0

I'm trying to perform an action after i add a product to my cart.

I tried the observer checkout_cart_product_add_after but this does not enter a new line in the quote until after, thus my quote item is empty.

I need to have the line item created for the quote.

So i thought i would use "checkout_cart_add_product_complete" and this does create a line item in the quote, but i don't know what the new line item entity_id is from the "checkout_cart_add_product_complete", i tried looking at the object but it is way to big for me to find it....

Anyway so all i want after adding a product to the cart, is get the new line item id, this DOES NOT have to be from my observer object if not possible...

Fabian Schmengler
  • 65,791
  • 25
  • 187
  • 421
Tobias Hagenbeek
  • 183
  • 2
  • 11

1 Answers1

2

I tested some code here, and I am finding that checkout_cart_product_add_after does include the quote item, after it has been added:

$item = $observer->getQuoteItem();
$quote = $item->getQuote();

echo $item->getId();
Joseph at SwiftOtter
  • 1,171
  • 1
  • 17
  • 31
  • Well i had tried that, and again, i don't get a line item id, unless the item already existed in the cart and i added another one... – Tobias Hagenbeek Feb 18 '14 at 13:31
  • You could try doing $item->save();, to see if that will then set the item id. – Joseph at SwiftOtter Feb 18 '14 at 13:52
  • that could work, that is just not what i want or need to do, and it would create lots of non needed items in the ccart – Tobias Hagenbeek Feb 18 '14 at 16:10
  • I may be missing something, but I believe that this item will be saved anyway, and this is just making it happen sooner. Maybe, would you revisit your question to add some more details and clarify? That would help. – Joseph at SwiftOtter Feb 18 '14 at 19:14
  • See http://magento.stackexchange.com/questions/10662/watching-add-to-cart-event-quote-item-id-is-empty on how to get the quote item ID after the item has been saved. – Matthias Zeis May 19 '14 at 08:35