April 15, 201016 yr Hi Guys, I'm implementing a promotion on a site - Buy 2 get 1 free on everything. Magento has a similar promotion by default which only applies on an individual product and not on all products in the cart! So, here's the default code: case 'buy_x_get_y': $x = $rule->getDiscountStep(); $y = $rule->getDiscountAmount(); if (!$x || $y>=$x) { break; } $buy = 0; $free = 0; while ($buy+$free<$qty) { $buy += $x; if ($buy+$free>=$qty) { break; } $free += min($y, $qty-$buy-$free); if ($buy+$free>=$qty) { break; } } $discountAmount = $free*$itemPrice; $baseDiscountAmount= $free*$baseItemPrice; break; someone came up with this solution but only works on the first three products: case 'buy_x_get_y': $cartRules = $address->getCartFixedRules(); $x = $rule->getDiscountStep(); //2 $y = $rule->getDiscountAmount(); //1 if ($quote->getItemsSummaryQty()>=($x+$y)){ if (!isset($cartRules[$rule->getId()])) { $cartRules[$rule->getId()] = $item->getPrice(); }elseif($cartRules[$rule->getId()]>$item->getPrice()){ $cartRules[$rule->getId()] = $item->getPrice(); } if ($cartRules[$rule->getId()] > 0) { $quoteAmount = $quote->getStore()->convertPrice($cartRules[$rule->getId()]); $discountAmount = min($item->getRowTotal(), $quoteAmount); $baseDiscountAmount = min($item->getBaseRowTotal(), $cartRules[$rule->getId()]); $cartRules[$rule->getId()] -= $baseDiscountAmount; } $address->setCartFixedRules($cartRules); } break; I would appreciate your thoughts on this! WkdFX
Create an account or sign in to comment