Jump to content

How get $product->quantity for products with attributes


FluffyCat

Recommended Posts

Hi

 

I am making a minor change in product.tpl for my theme. I simply want to show a specific image when the product is in stock and another image when it is not.

 

This works almost perfectly simply using $product->quantity.

 

However, if the product is out of stock in a certain color but is in stock in another color, then $product->quantity still says there is products in stock when I am looking at the color that is out of stock.

 

So I guess $product->quantity is the quantity for all items in stock of this product regardless of color. 

 

How can I get the number of products in stock with the color that is currently being shown to the user. Prestashop seems to handle this correctly but I do not understand how they do it.

 

Thanks in advice for any hints.

  • Like 1
Link to comment
Share on other sites

Hi

 

Sorry I forgot to add that, it is 1.5.4.1. I have seen that the combinations are managed from the js file in the theme so it is working ok now. However it would be really interesting to know if this can be managed from the tpl file to simplify things but maybe that is not an option?

Link to comment
Share on other sites

  • 4 weeks later...

The problem is that PrestaShop sets $product->quantity to the sum of all quantities for all combinations for the product. I have a problem with this at the moment. I have code to change the colour/class of #availability_value when the combination has a quantity of zero or less. Unfortunately, since I have another combination, which does have stock, $product->quantity is being set to 6 (because one combination, the one for pre-ordering, has 0 in stock, while the other has 6 in stock). Is there an easy way to fix this bug?

EDIT: Nevermind. I achieved what I needed to by modifying product.js.

Edited by typ3z3r0 (see edit history)
  • Confused 1
Link to comment
Share on other sites

  • 1 year later...
  • 1 year later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...