简体   繁体   中英

Magento -> Add custom option to product when adding product to cart

Need to add some custom option to product after adding this product to cart. I use this observer:

  <checkout_cart_add_product_complete>
   <observers>
   <test_chooser_observer>
    <type>singleton</type>
    <class>test_chooser_model_observer</class>
    <method>addAttributes</method>
   </test_chooser_observer>
    </observers>
  </checkout_cart_add_product_complete>

And this code:

public function addAttributes($observer)
            {
               $event = $observer->getEvent();
                    $quoteItem = $event->getQuoteItem();
             $additionalOptions[] = array(
                                'label' => 'Test',
                                'value' => 'Test',
                            );
            $quoteItem->getProduct()->addCustomOption('additional_options', serialize($additionalOptions));
                    return $this;

            }

But i see blank page. I use answers for earliest version of magento, but it seems they don't work in 1.8.1

尝试将您的类更改为: Test_Chooser_Model_Observer如下所示:

<class>Test_Chooser_Model_Observer</class>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM