0

I would like to update the quote item additional option with my custom input value

I am trying below

event checkout_cart_update_item_complete

        public function customPriceUpdate(Varien_Event_Observer $observer) 
    {
        $id = (int) Mage::app()->getRequest()->getParam('id');
        $cart=Mage::getSingleton('checkout/cart');
        $item = $cart->getQuote()->getItemById($id);
        //$item= Mage::getModel('sales/quote_item')->load($id);           
        $single_price = 100;
        $item->setStoreId(Mage::app()->getStore()->getStoreId());

        $width= array(
            'label'                    => 'Width',
            'option_value'             => $width,
            'value'                    => $width,
            'print_value'              => $width,
        );
        $length= array(
            'label'                    => 'Length',
            'option_value'             => $length,
            'value'                    => $length,
            'print_value'              => $length,
        );
        $value = array('width'=> $width, 'length' => $length);
        $value = serialize($value);
        $item->addOption(array('code'=> 'additional_options', 'product_id'=> $item->getProductId(), 'value'=> $value));     


        $item->setCustomPrice($single_price);
        $item->setOriginalCustomPrice($single_price);    
        $item->getProduct()->setIsSuperMode(true); 
        $item->save(); 
        //for updating the totals
        $quote = Mage::getModel('checkout/session')->getQuote(); 
        $quote->collectTotals()->save();    

}

When first time edit cart item its gives error Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails sales_flat_quote_item_option

Second time same code working without error.

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.