Magento change Custom Option value before adding it to cart

前端 未结 3 666
眼角桃花
眼角桃花 2020-12-13 22:44

I have setup a custom option for my product in Magento as dropdown i.e.

Size : Small, Medium, Large

On product page I show additional information for each op

3条回答
  •  無奈伤痛
    2020-12-13 22:56

    Just to add a small fix to Vinai's great solution. The solution breaks the logic of getting a quote item by product.

    The function getItemByProduct in Mage_Sales_Model_Quote_Item calls the function representProduct which compares between the quote and product options. If both objects have identical list of options it returns the quote object otherwise false.

    Because both objects have different options now that we added our custom option the function will return false.

    One way to solve this issue is to rewrite Mage_Sales_Model_Quote_Item class and add your custom option code to the local variable $_notRepresentOptions in the constructor.

    class Custom_Options_Model_Sales_Quote_Item extends Mage_Sales_Model_Quote_Item {
    
            /**
             * Initialize resource model
             *
             */
            protected function _construct()
            {        
                $this->_notRepresentOptions = array_merge($this->_notRepresentOptions, array('additional_options'));
    
               parent::_construct();
            }
    }
    

提交回复
热议问题