Jump to content

Difference between product.out_of_stock vs stock_available.out_of_stock?


HarmonicApps

Recommended Posts

Hello,
Does anyone know the difference between product.out_of_stock vs stock_available.out_of_stock?
 

My research so far:

In PrestaShop 1.6.1.1 product.out_of_stock is defined as int(10) and stock_available.out_of_stock as tinyint(1).  It is still defined that way in PrestaShop 1.6.1.15.

out_of_stock is referenced in the following files (usually from the stock_available table):

  • classes\Cart.php
  • classes\Category.php
  • classes\Manufacturer.php
  • classes\Pack.php
  • classes\Product.php
  • classes\ProductSale.php
  • classes\Search.php
  • classes\Supplier.php
  • order\OrderDetail.php - pulled from product table instead of stock_available in getCrossSells()
  • classes\stock\StockAvailable.php

File classes\stock\StockAvailable.php has the following comment:

/** @var bool determine if a product is out of stock - it was previously in Product class */
public $out_of_stock = false;

Let's assume product.out_of_stock is no longer used.  The rest of the comment cannot be accurate because when I run the following SQL I have 0, 1, or 2 as a value.  2 is not a boolean value.

select out_of_stock from ps_stock_available group by 1;

When I go to back office > Catalog > Products > Edit (for a product) > Quantities > Available quantities for sale > When out of stock: drop-down has the following options.

  • Deny orders (0)
  • Allow orders (1)
  • Default (2)

I was thinking maybe this setting only applies to the stock_available record where id_product_attribute=0 (the parent record).  However, this is not true because I found records where id_product_attribute > 0 and out_of_stock=2.

 

classes\stock\StockAvailable::outOfStock() uses the following query:

select out_of_stock from stock_available where id_product=<id_product> and id_product_attrubute=0;

In classes\Product::isAvailableWhenOutOfStock(), true is returned if PS_STOCK_MANAGEMENT=false (back office > Preferences > Products > Products stock > Enable stock management=No).  If stock_available.out_of_stock=2, then PS_ORDER_OUT_OF_STOCK (back office > Preferences > Products > Products stock > Allow ordering of out-of-stock products) is returned.  Otherwise stock_available.out_of_stock is returned.

 

So I'm thinking stock_available.out_of_stock is populated with the value from back office > Catalog > Products > Edit (for a product) > Quantities > Available quantities for sale > When out of stock for the parent product and all combinations (product attributes).  This would mean this field is not a boolean as in true if out of stock and false if in stock.

 

Would love if someone else could review this and let me know if I'm right (since I'm new to PrestaShop)...

Thanks for your help!

Edited by HarmonicApps (see edit history)
Link to comment
Share on other sites

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...