3

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();
4

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();

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.