kafaya
kafaya

Reputation: 101

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

Upvotes: 0

Views: 1077

Answers (1)

seanbreeden
seanbreeden

Reputation: 6097

Try changing your class to: Test_Chooser_Model_Observer like this:

<class>Test_Chooser_Model_Observer</class>

Upvotes: 1

Related Questions