gaiterjones / magento-buy-x-get-y-free

Magento Buy X Get Y Free Module
43 stars 21 forks source link

On first Visit of Cart free gift is not added. #9

Open Ruko2010 opened 8 years ago

Ruko2010 commented 8 years ago

We set up a rule "Spend 60€ and get a free product" on Magento 1.9.2.1. But if someone puts products in the cart for more than 60€, and visit the cart (he is not rediected automatically, but he has to visit the cart before checking out), the product is not added. If we simply reload the page, everything is fine and the product is added. Also, after that, if we delete all products from the cart, and put something back in it, the free product is added on the first visit of the cart.

If we delete all browser data, the game begins again, on first visit of the cart, the free product is not added.

Ruko2010 commented 8 years ago

I found something. On the first call of the CartController (your controller, not the one from Magento), it seams that the totals are not generated, because $subtotal = $totals['subtotal']->getValue(); returns a 0. (Function spendXgetYfreeCartUpdate)

Ruko2010 commented 8 years ago

Ok, 2 minutes later I found the solution :). Just add right before this line:

Mage::getSingleton('checkout/cart')->getQuote()->collectTotals()->save();

then it works.