isSaleable () When working with Magento templates, you definitely came across the isSalable () method applied to the product object. This method physically exists, but it checks to see if the product has allowed status, and a sale check should not be skipped. Then the is_salable property of the product object is returned.
The obvious question is when this property is set. After loading the product, it is already installed on the model, but it is not an attribute and is not a column in the product’s flat table.
As usual, all bizarre things in Magento are done by observers. Mage_Cataloginventory observes the catalog_product_load_after event, and there it comes down to Mage_CatalogInventory_Model_Resource_Stock_Status :: getProductStatus and the following query:
SELECT `cataloginventory_stock_status`.`product_id`, `cataloginventory_stock_status`.`stock_status` FROM `cataloginventory_stock_status` WHERE (product_id IN('241319')) AND (stock_id=1) AND (website_id=3);
It is clearly seen that the decision, if the product is sold or not, is made during reindexing. And ignore share_id, which is some kind of incomplete functionality that will also come out later.
So, we find ourselves in a place where no sane Magento developer would willingly go ... a pointer. Catalog inventory indexer in our case. After a quick passage through the labyrinth Mage_CatalogInventory_Model_Indexer_Stock :: _ processEvent, Mage_Index_Model_Indexer_Abstract :: reindexAll and Mage_CatalogInventory_Model_Resource_Indexer_Stock :: reindex we have our own index / model, we have our own index / Model, reindex, which we find Indexer / Photo.
Each type has a _getStockStatusSelect method, where the SQL query finally decides whether the product is sold or not. Although the query may seem massive, the logic is not complicated.
Most of the code here is again rudimentary material. It seems that the main developers made an excellent attempt to allow different levels of inventory for different sites, but for some reason this functionality never ended.
So, for example, checking the availability of simple products is available only to verify that the product is included, and the quantity is positively flavored with inventory control flags. Requests for custom and grouped products are slightly different due to the nature of the product type.