0

I am trying to remove Product by applying zero price coupon code its working fine but Grand total is not updating on apply the coupon code . its working if I click on update items button.

I have added 2 products test1 => price : $100 & test2 => price => $10 On apply coupon code, test2 is removed from order item from admin but grand total is showing $110 its should show $100 only . if i click on update button its showing correct one.

what I want on apply coupon code it should show the $100

<adminhtml>
        <events>
            <sales_quote_item_set_product>
                <observers>
                    <namespace_additionalproduct_order_observer>
                        <type>singleton</type>
                        <class>additionalproduct/observer</class>
                        <method>addProduct</method>
                    </namespace_additionalproduct_order_observer>
                </observers>
            </sales_quote_item_set_product>

            <salesrule_validator_process>
                <observers>
                    <namespace_removeproduct_order_observer>
                        <type>singleton</type>
                        <class>additionalproduct/observer</class>
                        <method>removeProduct</method>
                    </namespace_removeproduct_order_observer>
                </observers>
            </salesrule_validator_process>

        </events>
    </adminhtml>

Observer.php

        public function addProduct($observer)
        {

            $hessSkuTwentySeventeen = '2017MiniCollection';
            $hessSkuServiceFee = 'ServiceFee';
            $added = false;
            $quote = $observer->getQuoteItem();
            $product = $observer->getProduct();

            if ($product->getSku() == $hessSkuTwentySeventeen) {
                $addProduct = Mage::getModel('catalog/product');
                $addProduct->load($addProduct->getIdBySku($hessSkuServiceFee));

                foreach ($quote->getQuote()->getAllVisibleItems() as $item) {
                    if ($item->getProduct()->getSku() == $hessSkuTwentySeventeen) {
                        $added = true;
                        break;
                    }
                }

                if (!$added) {
                    $quote->getQuote()->addProduct($addProduct);
                }
            }
        }

        public function removeProduct($observer){
            $hessSkuServiceFee = 'ServiceFee';

            if ($observer->getRule()->getCouponCode() == 'removeproduct') {
                $quote = $observer->getQuote();
                foreach ($quote->getAllVisibleItems() as $item) {
                    if ($item->getProduct()->getSku() == $hessSkuServiceFee) {
                        $quote->deleteItem($item);


                    }
                }
            }



        }
0

I believe you are missing function called collectTotals().

try this: $quote->collectTotals()->save();

This should update total.

For more info you can visit function collectTotals() in Mage_Sales_Model_Quote class. Which goes to each items and updates the total and other stuff. It's very important to call collectTotals() after each quote update.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.