Question

I need to get quantity of product being added NOT quantity of that product in cart.

E.g. I am on product view page and set quantity to 5 and click on "Add to Cart". I need to get that quantity in observer.

How can I do that?

Currently I have this, but it gets quantity of that product in cart. E.g. if I already had 3 of same products in cart and I added 5 more of same product then $qty will be 8 not 5. That is not what I need.

$product = $observer->getEvent()->getQuoteItem();
$qty = $product->getQty();
Was it helpful?

Solution

If you do var_dump($product->getData() you will see that there is a field with name qty_to_add in the data. This field contains the quantity which was requested to be add.
So to get what you want use below code.

$product->getQtyToAdd();
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top