3

I am trying to get the product quantity in observer event catalog_product_type_prepare_full_options but even if i try to add more than one, the observer returns 1 as quantity

    $product = $observer->getEvent()->getProduct();

    $productqtty = $product->getQty();

$productqtty always returns 1

What could be wrong?

1 Answer 1

2

At this point the product object does not yet contain data for the cart item (qty, options).

But in the event you have access to the quantity through the buy request object:

$buyRequest = $observer->getEvent()->getBuyRequest();
$qty = $buyRequest->getQty();

Reference:

3
  • Thank you so much it is working in simple products but in grouped products I still get 1 for quantity do you know what could be? Feb 5, 2017 at 21:20
  • For grouped products each has its own qty. If you inspect the content of the buy request object you will find the individual qtys there Feb 5, 2017 at 21:24
  • how could i check for each one the quantity in the observer? (as if they would be different products?) I need to limit the quantity of each product in a group product per customer) Feb 5, 2017 at 21:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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