cancel
Showing results for 
Search instead for 
Did you mean: 

Update item options on cart page - error on save

Update item options on cart page - error on save

Edit:  Ok I went back to the other implementation I was working with.

The Error I am getting upon UPDATE is:

 

Please specify the product required option(s).


I am trying to update my Custom Option (Warranty) from my cart view.
I have followed the advice from another post, but it did not work.

Using the Module override technique of using an Observer to listen for the

checkout_cart_update_items_after

event, I fire a custom method that is supposed to update the option as the cart is updating

 

 

    public function updateItemsSpecificOption(Varien_Event_Observer $observer) {
        
        $aPost  = Mage::app()->getFrontController()->getRequest()->getPost();;
        #print_r($aPost);
        $quoteItems = $observer->getCart()->getQuote()->getAllVisibleItems();
        foreach ($quoteItems as $item) {
            
            $cart_arr   =   $aPost['cart'];
            
            $itemId = $item->getId();
            $productId = $item->getProductId();
            $productQty = $item->getQty();
            $option_arr     =   $cart_arr[$itemId]['option'];
            foreach($option_arr as $key=>$val_option) {
                $superAttributeId = $key;
                $childId = $val_option;
            }
            
            
            #$refresh = $this->getRequest()->getParam('refresh');

            $params = array(
                'id' => $itemId,
                'qty' => $productQty,
                'product' => $productId,
                'super_attribute' => array($superAttributeId => $childId)
            );

            //var_dump($params); die();
            $cart = Mage::getSingleton('checkout/cart');
            $quoteItem = $cart->getQuote()->getItemById($itemId);
            if (!$quoteItem) {
                Mage::throwException($this->__('Quote item is not found.'));
            }

            $item = $cart->updateItem($itemId, new Varien_Object($params));
            if (is_string($item)) {
                Mage::throwException($item);
            }
            $cart->save();

            Mage::getSingleton('checkout/session')->setCartWasUpdated(true);
            
        }
    }

 

Form HTML

<select name="cart[75549][option][145]" id="select_145" class="required-entry product-custom-option" style="margin: 2px 0px; padding: .4em .8em;" onchange="form.submit();">
<option value="548" price="0.0000"> No Extra Warranty +$0.00 CAD + 0.0000</option>
<option value="549" price="89.0000"> Gold + 89.0000</option>
<option value="550" price="169.0000"> Diamond + 169.0000</option>
<option value="551" price="289.0000"> Platinum + 289.0000</option>
</select>

 

 

The $params object gets updated as it should I think

array(4) { ["id"]=> string(5) "75549" ["qty"]=> int(1) ["product"]=> string(3) "308" ["super_attribute"]=> array(1) { [0]=> string(3) "549" } }

 

but after the update routine is finished and the page refreshes, my Cart Item custom option is not updated.

Any insight?