1

I am trying to delete a cart after the user has made a reorder. I'll explain: I have a module that adds a free product with a shopping cart price rule (whether a product is part of a specific category, add a free product). The problem comes when the customer makes a Reorder: Magento adds to cart the free product 2 times in addition to products to be reordered.

You know tell me the event to use the type: "retrive the quote cart after a reorder is made"?

I have created a custom module and I used these events in observers:

checkout_cart_product_add_after
controller_action_predispatch_sales_order_reorder

Thi is my test code:

public function checkFreeProducts(Varien_Event_Observer $observer)
            {

            $order_id =Mage::app()->getRequest()->getParam('order_id');

                $promoSKU ='';
                $items = Mage::getModel('sales/order_item')
                    ->getCollection()
                    ->addFilter('order_id',array('eq'=>$order_id));
                    foreach($items as $item){
                        //if the item has not had a rule applied to it skip it
                        if($item->getAppliedRuleIds() == '')continue;

                        foreach(explode(",",$item->getAppliedRuleIds()) as $ruleID){        
                            $salesRule = Mage::getModel('salesrule/rule')->load($ruleID);
                            $promoSKU = $salesRule->getPromoSku();
                        }

                    }
                if($promoSKU){
                    $order = Mage::getModel('sales/order')->load($order_id);
                    $items = $order->getAllItems();
                    foreach($items as $i):
                        $prd_id =  $i->getProductId();
                        $product = Mage::getModel('catalog/product')->load($prd_id); 
                        $productSku = $product->getSku();

                        if($promoSKU==$productSku){ // there is a promo product 
                            Mage::getSingleton('core/session')->addError('promo product');                      }
                    endforeach;
                }
                $cart = Mage::getModel('checkout/cart')->getQuote();
                foreach ($cart->getAllItems() as $item) {
                    echo $productName = $item->getProduct()->getName();
                    $productPrice = $item->getProduct()->getPrice();
                }

but I could not see if is applied some cart rules. Someone can help me?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.