O
O
Oleg Batishchev2014-08-19 03:09:53
Magento
Oleg Batishchev, 2014-08-19 03:09:53

By what criteria can Magento set the Disabled status for simple products that make up a custom one?

And also how to quickly find this piece of code?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Fedyuk, 2014-08-19
@dfediuk

The only reason for the Magento core to automatically transfer a simple product (including a simple variant of a custom product) to the “ not for sale ” state (after which the product is removed from the online storefront) is the presence of this product in the online store’s warehouse in a quantity less than the amount specified by the administrative option
"System" → "Settings" → " Catalogue " → " Availability " → " Standard values ​​of other product availability parameters " → " The minimum number of units of a particular product in stock, upon reaching which the product is considered out of stock ".
The default value of this option is " 0 ".”, that is, by default, Magento removes goods that are out of stock from sale.
Please note that the above reason for automatic withdrawal from the sale of goods is necessary, but not sufficient .
The final decision (whether or not to withdraw a product) is made by Magento, taking into account the value of the options.
The names of the options are given in accordance with the Russification of the Russian assembly of Magento.
In the English version of Magento, they are called like this:
Sections of the program code responsible for the automatic removal of goods from sale can be found by the keywords is_salable , isSalable , IsSalable , isAvailable .
In particular, for simple products (custom product variations of a custom product are considered simple products), the Mage_CatalogInventory_Model_Stock_Status class automatically removes the product from sale : in two places: the assignProduct and addStockStatusToProducts methods .

public function assignProduct(Mage_Catalog_Model_Product $product, $stockId = 1, $stockStatus = null)
{
    if (is_null($stockStatus)) {
        $websiteId = $product->getStore()->getWebsiteId();
        $status = $this->getProductStatus($product->getId(), $websiteId, $stockId);
        $stockStatus = isset($status[$product->getId()]) ? $status[$product->getId()] : null;
    }

    $product->setIsSalable($stockStatus);

    return $this;
}

public function addStockStatusToProducts($productCollection, $websiteId = null, $stockId = null)
{
    <...>
  
  $stockStatuses = $this->_getResource()->getProductStatus($productIds, $websiteId, $stockId);
  foreach ($stockStatuses as $productId => $status) {
    if ($product = $productCollection->getItemById($productId)) {
      $product->setIsSalable($status);
    }
  }

  <...>

    return $this;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question