Prestashop get product quantity of one combination

Viewed 107

Hello I'm trying to override my CartController file. The problem is how to get quantity of single product, not all combinations. My code is:

if ('update' !== $mode && $this->shouldAvailabilityErrorBeRaised($product, $qty_to_check)) {
   $this->{$ErrorKey}[] = $this->trans(
      'The item %product% in your cart is no longer available in this quantity. You cannot proceed with your order until the quantity is adjusted %productQuantity% - %productCheck%.',
            array('%product%' => $product->name, '%productQuantity%' => $product->quantity, '%productCheck%' => $qty_to_check),
            'Shop.Notifications.Error'
   );
}

but %productQuantity% shows quantity sum of all combinations. How to get quantity of current combination.

1 Answers

The quantity for a single combination can be retrieved with the static method :

StockAvailable::getQuantityAvailableByProduct()

So, when in cart controller you can do something like :

StockAvailable::getQuantityAvailableByProduct($this->id_product, $this->id_product_attribute, $this->context->shop->id)
Related