1

I am looking for a way to transfer a product attribute to quote item whenever a product is added. I came across a method in which I could write an observer to hook onto th event:sales_quote_item_set_product and set the quote item attribute based on the product attribute.

But, I don't like this approach since sales_quote_item_set_product is dispatched every time a quote item is loaded from the DB. I'd like a one time thing wherein I fetch a product attribute at the time of add to cart and add it's value in a column in quote item. Is there an event I could hook onto?

I think checkout_cart_product_add_after should be a good prospect to explore...any thoughts?

  • I've decided to use checkout_cart_product_add_after. This is dispatched right after a product is added to cart from:Mage_Checkout_Model_Cart::addProduct($productInfo, $requestInfo=null) – Paras Sood Aug 26 '14 at 17:07
2

You can try to use sales_quote_product_add_after.
That one is dispatched after you add a product to the cart.
the downside is that you get as parameter a list of all the items in the cart and you have to look for your latest item and set the attribute you need.
But you can easily identify it. It has the highest id.

1

Set this attribute as "Used for Promo Rules" = "Yes" at the attribute edit page admin > attributes > manage attributes and it will be available in the quote.

1

To get a product attribute as Amasty already mentioned you can also add it to this list:

app/code/core/Mage/Sales/etc/config.xml:1251
XPATH: /config/global/sales/quote/item/product_attributes

Of course not in the Mage_Sales config.xml but in your own :-)

1

I have decided to use checkout_cart_product_add_after. This is dispatched right after a product is added to cart from:

Mage_Checkout_Model_Cart::addProduct($productInfo, $requestInfo=null)

I didn't want to use Amasty's or Fabian's approach because it would have an additional attribute load from the DB into the quote item's product whenever a quote item is loaded from the DB. I am rather looking to store the value in sales_flat_quote_item table after I've made that entry on add to cart.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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