Downloadable product on Magento 2.3.1 out of stock issue
-
12-03-2021 - |
Pergunta
I'm issuing a problem with newly created downloadable products on Magento 2.3.1
This store contains about 10k products (phisical and digital) imported from M1
- Phisical in stock/out of stock is working both for imported and native products
- Digital in stock/out of stock is working only for M1 imported products.
I compared the records of 2 digital products (1 imported and 1 native) in all %stock% database tables and the only strange things I noticed is that:
- M2 native downloadable product has several records on cataloginventory_stock_cl table
- M2 imported downloadable product has no records on cataloginventory_stock_cl table
What is the use of cataloginventory_stock_cl table?
There are other places where I can find to debug this problem?
Solução
In our case the issue was related to a migration from Magento 1 to Magento 2 via migration data tool. The problem is that default value for the attribute 'links_exist' is 0
in Magento 1. However in Magento 2 default value for 'links_exist' is null
.
Because of that following validation fails
File: vendor/magento/module-catalog/view/frontend/templates/product/view/addtocart.phtml
Line 13: <?php if ($_product->isSaleable()): ?>
which leads to
File: vendor/magento/module-catalog/Model/Product.php
Line 1805: return $this->isSalable();
Line 1748: $salable = $this->isAvailable();
Line 1766: return $this->_catalogProduct->getSkipSaleableCheck() || $this->getTypeInstance()->isSalable($this);
Last part is important: $this->getTypeInstance()->isSalable($this);
. In case of a downloadable product following validation happens:
File: vendor/magento/module-downloadable/Model/Product/Type.php
Line 334: return $this->hasLinks($product) && parent::isSalable($product);
This validation will return false
for new created downloadables because of mentioned default value 0
for links_exist
.
File: vendor/magento/module-downloadable/Model/Product/Type.php
Line 169-176:
public function hasLinks($product)
{
$hasLinks = $product->getData('links_exist');
if (null === $hasLinks) {
$hasLinks = (count($this->getLinks($product)) > 0);
}
return $hasLinks;
}
Here your can see that Magento 2 expects null
before even considering counting links.
That all said the issue is only related to newly created downloadables. Imported ones will most likely have a different value for links_exist
which will pass mentioned validation.
Our solution was to manually change the default value for links exist in eav_attributes
table. This should solve the issue for new downloadables.
Hope I could help.
Edit: This bug is already reported on GitHub see: GitHub Issue.
Edit 2:
For downloadables that were created with a wrong default value for links_exist
it is necessary to change the attribute value in catalog_product_entity_int
.
Following query will help (substitute attribute_id
and entity_id
appropriately):
UPDATE catalog_product_entity_int SET value=null WHERE attribute_id="attribute id of links_exist" AND entity_id="insert product id here";
You can find attribute_id
of links_exist
in eav_attribute
table.
Outras dicas
cl
ending on the table means "chanage log".
Run:
php bin/magento indexer:reindex
And you should be able to see changes in those tables. The above command should hopefully fix the problem with the OOS products.
Have a look at this: Magento 2 Tables Being Created Ending in "_cl"