3

I am changing shipping price on the fly but it doesn't update cart total as it should.

Here is my code.

Observer event i m using sales_quote_address_collect_totals_after

code from observer.

public function checkshipping(Varien_Event_Observer $observer){
    //echo Mage::helper('shippingoptions')->getSaturday_delivery(); exit;
    if(/* Mage::helper('shippingoptions')->getSaturday_delivery() */Mage::getSingleton('checkout/session')->getSaturdayDelivery()){
        $event = $observer->getEvent();
        $data = Mage::app()->getRequest()->getParams();
        $price = 20;
        $address = $observer->getQuoteAddress();
        $quote = $address->getQuote();
        $address->setCollectShippingRates(false);
        $rates = $address->collectShippingRates()
        ->getGroupedAllShippingRates();
        foreach ($rates as $carrier) {
            foreach ($carrier as $rate) {                   
                if($rate->getCode()=='fedex_PRIORITY_OVERNIGHT'){
                    $finalPrice = $rate->getPrice()+$price;
                    /* $rate->setPrice($finalPrice);
                    $rate->save(); */
                }
            }
        }
        $title = $address->getShippingDescription();
        $address->setShippingDescription($title.' - Saturday Delivery');
        $address->setShippingAmount($finalPrice);
        $address->setBaseShippingAmount($finalPrice);
        //$quote->setTotalsCollectedFlag(false)->collectTotals();

        $address->save();
    }

}

when i enable $quote->setTotalsCollectedFlag(false)->collectTotals() it goes to infinite loop. Have also tried before event but no luck.

Please guide.

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.