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.
I've done something similar but not quite. Maybe it helps.
my task was to have a checkbox on each product page called gift wrap
. If checked then, the sales team would know to wrap the product (they only had a single wrapping option).
So I did this in order to be able to port the wrap
checkbox value from product to quote to order. (I could have used a custom option but it's ugly to add one option to a few thousand products).
I had an observer for the event sales_convert_quote_item_to_order_item
.
public function checkGiftWrap($observer)
{
$orderItem = $observer->getEvent()->getOrderItem();
$item = $observer->getEvent()->getItem();
$wrap = $item->getOptionByCode('wrap');
if ($wrap){
$options = $orderItem->getProductOptions();
$options['wrap'] = unserialize($wrap->getValue());
$orderItem->setProductOptions($options);
}
return $this;
}
I've rewritten the Mage_Catalog_Helper_Product_Configuration::getCustomOptions
helper in order to tell Magento that my option is important and should treat it separately
<?php
class [Namespace]_[Module]_Helper_Product_Configuration extends Mage_Catalog_Helper_Product_Configuration
{
public function getCustomOptions(Mage_Catalog_Model_Product_Configuration_Item_Interface $item){
$options = parent::getCustomOptions($item);
$wrap = $item->getOptionByCode('wrap');
if ($wrap){
$options = array_merge($options, array(unserialize($wrap->getValue())));
}
return $options;
}
}
For the same reason I've rewritten Mage_Sales_Block_Order_Item_Renderer_Default::getItemOptions
so my option will be displayed in the cart
<?php
class [Namespace]_[Module]_Block_Sales_Order_Item_Renderer_Default extends Mage_Sales_Block_Order_Item_Renderer_Default
{
public function getItemOptions(){
$result = parent::getItemOptions();
$options = $this->getOrderItem()->getProductOptions();
if (isset($options['wrap'])){
$result = array_merge($result, array($options['wrap']));
}
return $result;
}
}
and the admin name column for the order items grid:
<?php
class [Namespace]_[Module]_Block_Adminhtml_Sales_Items_Column_Name extends Mage_Adminhtml_Block_Sales_Items_Column_Name
{
public function getOrderOptions(){
$result = parent::getOrderOptions();
if ($options = $this->getItem()->getProductOptions()) {
if (isset($options['wrap'])) {
$result = array_merge($result, array($options['wrap']));
}
}
return $result;
}
}
[EDIT]
It seams I missed something. I only implemented the option to add a giftwrap once the product is in the cart.
But I think you can use the same code in an event prior or after adding the item to the cart.
$data = array();
$data['label'] = Mage::helper('helper_alias')->__('Giftwrapping');
$data['value'] = Mage::helper('helper_alias')->__('Yes');
$product->addCustomOption('wrap', serialize($data));
$item->addOption($product->getCustomOption('wrap'));
$item->save(); //this line should be called only if it's not called by default after your event is dispatched.
That's it. I hope you can get something useful out of it.
Best Answer
You should implement the sim card as related product instead of custom option.