Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

How do I create this rule? 
 
thecurve
Jr. Member
 
Avatar
Total Posts:  9
Joined:  2008-05-13
New York, US
 

I have a cart-level promo that I’d like to setup as follows...For every TV wall mount in the cart, I’d like to give away 1 hdmi cable. There are 3 different lengths of HDMI cable, each with a different price. Can anyone think of how I can create a rule to do this?

For clarity’s sake, let’s assume the SKUs are as follows:

37WallMount
42WallMount
51WallMount

6FTHDMI - $20
10FTHDMI - $25
15FTHDMI - $30

Thanks!

 
Magento Community Magento Community
Magento Community
Magento Community
 
Moshe
Magento Team
 
Avatar
Total Posts:  1770
Joined:  2007-08-07
Los Angeles
 

With existing price rules logic components it is not possible to create this promotion.

However, it is possible to extend price rules to allow this functionality.

Basically that would boil down to counting quantity of matching “condition” wall mount items in cart, and then limiting discounted items to this quantity for matching “action” cable items.
I know it sounds obvious, but that previous sentence would directly translate to programming steps.
Overloaded files would be Mage/SalesRule/Model/Validator.php and Mage/Sales/Model/Quote/Address/Total/Discount.php

Alternatively you could bind to event “sales_quote_address_discount_item” (dispatched in Mage/Sales/Model/Quote/Address/Total/Discount.php) and using simple logic set for matching items (cables) these values if other items match to wall mount items, limiting by total quantity of wall mounts:
* discount_percent to 100
* discount_amount to row_total
* base_discount_amount to base_row_total

 
Magento Community Magento Community
Magento Community
Magento Community
 
thecurve
Jr. Member
 
Avatar
Total Posts:  9
Joined:  2008-05-13
New York, US
 

Thanks Moshe. Well I’m glad I didn’t spend hours trying to figure it out then smile

Is there a tutorial or screencast for modifying magento models?

 
Magento Community Magento Community
Magento Community
Magento Community
 
nicolas46
Sr. Member
 
Total Posts:  210
Joined:  2008-04-09
Toulouse
 

http://www.magentocommerce.com/boards/viewthread/4053/

Maybe that will help you

 
Magento Community Magento Community
Magento Community
Magento Community
 
thecurve
Jr. Member
 
Avatar
Total Posts:  9
Joined:  2008-05-13
New York, US
 

I’ve taken a look at the sales_quote_address_discount_item event, and see where I could potentially add logic. My confusion rests in where I can access the following data as variables: The item SKUs that are in the cart, and the prices for these items.

 
Magento Community Magento Community
Magento Community
Magento Community
 
thecurve
Jr. Member
 
Avatar
Total Posts:  9
Joined:  2008-05-13
New York, US
 

Getting closer...I see there is an array called items, which contains individual item.

And to access the methods of item, you can use the format: $item->methodName()

Is there a method name that exists (or that I can write) to access item sku and price? If so, I think I can just set $totalDiscountAmount to: # Cables in Cart * Total price of these cables.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top