8

I have a simple product with custom options. When someone select any option and click on add to cart the product with the option goes to the cart where the product and selected option is shown.

Now here comes the situation where I need to alter the flow of Magento. I want to update that option value on cart page. Being more specific I want to make customer able to select or change option on cart page.

What i have done so far is that I have traced that items are shown from template/checkoput/cart/item/default.phtml.

I have placed my custom option dropdown there in a row of product and placed a save button near the dropdown. But again how do I get it updated?

4 Answers 4

6

Interesting question. I suggest doing it not by adding "Update" button to each items but using generic Magento "Update Cart" routine.

In this case we can assume that values of your drop-downs will be submitted with the form. Then you can observe checkout_cart_update_items_after event, get updated options with Mage::app()->getFrontController()->getRequest()->getParam(...) and change the selected option of each item.

This is just my theoretical assumptions but I'm sure you were not expecting complete code. Otherwise there's a commercial extension out there which is doing exactly what you need.

3
  • Thanks Tim for your help, i have managed to do this. for this i have made a custom module.
    – Sarvagya
    Commented May 29, 2013 at 12:29
  • Tim, is it possible to get the posted value in sales_quote_collect_totals_before , i have created the custom option in it need to set value with that posted data ?? Commented Nov 21, 2013 at 12:50
  • I'm not quite sure if I understand you right but you can fetch it from the quote item object and the quote item object can be fetched from the quote and observer respectively. Commented Nov 21, 2013 at 15:27
4

I got my work done, here is how i have done that:

I just use jquery and ajax and created a custom module in which i made an action with the code :

  $options = $item->getOptions();

  foreach ($options as $option) 
{ 

switch (true) 
    {

        case (strtolower($option->getCode()) == 'info_buyrequest') :
            $unserialized = unserialize($option->getValue());
            $unserialized['options'][2] = $info_option_value;
            $option->setValue(serialize($unserialized));
            break;

            case ($option->getCode() == "option_2") :
            $option->setValue($info_option_value);
            break;
    }

}
$item->setOptions($options)->save(); 
Mage::getSingleton('checkout/cart')->save();

When any one press button this action is called through ajax and its Done !!!!

If anyone needs more detailed solution ask it here.

3
  • 1
    How do you know that option_2 is the one to change? Commented Nov 4, 2013 at 16:29
  • 1
    good job! i stood 2 days figuring it out until i found your solution. thanks! Commented Mar 4, 2015 at 11:27
  • @Sarvagya, i have to do the same in magento2. can you please help
    – surbhi agr
    Commented Dec 11, 2019 at 6:48
2

Let’s say we have configurable Magento product in shopping cart and we want to update its options without deleting product from cart and adding it again.

That’s quite easy to achieve with following steps, however I can’t write complete tutorial here so you should be a little more familiar with Magento in order to make it work.

For further details you can refer following link : http://inchoo.net/ecommerce/magento/updating-options-of-configurable-product-that-is-already-in-the-cart/

I hope this will help you :)

1
  • How can we do this in magento2
    – surbhi agr
    Commented Dec 11, 2019 at 6:59
1

Try to this code is used to add product to cart with custome options.

$cart   = Mage::getModel("checkout/cart");

$params = $this->getRequest()->getParams();
$product =Mage::getModel('catalog/product')->load($product_id);

try{
$cart->addProduct($product,$params);
$cart->save();
}catch (Exception $ex) {
echo $ex->getMessage();
}

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