Question

I have a following problem:

There is a 3rd party extension which automatically adds products to cart as gifts when user adds some specific product. It also applies coupon. For example it adds free WiFi receiver when user wants to buy a TV. It adds products good enough, but there must be a shopping cart rule to make a 100% discount for these products.

What I need to do is to make this extension to add these products as free without shopping cart rule. The only event i found connected with discounts is sales_quote_address_discount_item, but any operations with it gave no results.

So I would be really grateful if someone points me in the right direction: where exactly in code is this discount applied and how can I make the same from this extension?

Was it helpful?

Solution

The discount from a coupon is applied in Mage_SalesRule_Model_Validator in the process() method. This method is called every time collectTotals() is called on the quote. You would need to override this class (and possible a few others) to override coupon behavior. There is an event inside that method salesrule_validator_process that you might be able to use instead of overriding the whole method, but it will depend on what logic you need to change as to whether it occurs at the right place for you.

OTHER TIPS

You could also add your own logic after the add_to_cart_after event is fired. (Eg create your own event apply_discount_after_add_to_cart ;)

Take a look at this module; it can add products to the shopping cart as a gift and set their price to 0$ during adding them: http://www.code4business.de/make-a-gift-magento-warenkorbpreisregeln-um-geschenke-erweitern/.

To do so it catches the two events salesrule_validator_process and sales_quote_collect_totals_before. It does not rewrite anything. The code is also described in detail at http://www.webguys.de/magento/turchen-21-kostenlose-produkte-uber-warenkorb-preisregeln/.

It needs a price rule – but just to identify the product (or the condition) that you get your gift for. The gift is always free of charge; no additional rule needed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top