Magento2: Unable to change product stock status when it has related configurable product with different attribute set

Created on 1 Mar 2017  路  5Comments  路  Source: magento/magento2

Preconditions

  1. Magento 2.1.4
  2. (seems not important) PHP 7.0.13, 5.6.30

Steps to reproduce

  1. On clean magento, create new Attibute Set.
  2. Create a configurable product with attribute set from prev step with a couple configuration options.
  3. Create simple product with Default attribute set. Save it.
  4. Add configurable product to a list of related products for the simple one. Save it.
  5. Try to change value of "Stock Status" of simple product. Save it.

Expected result

  1. After step 5 you should see "Stock Status" value changed.

Actual result

  1. The value of "Stock Status" remains the same after you try to save a product. Works fine if you remove configurable product from related products.
Catalog Clear Description Format is valid Ready for Work bug report

Most helpful comment

Done a hacky fix for now which seems to work.
Find the function addAttribute() in file module-eav/Model/Entity/AbstractEntity.php

And change the line:
$this->_attributesByCode[$attributeCode] = $attribute;

To:
if (!array_key_exists($attributeCode, $this->_attributesByCode)) {
$this->_attributesByCode[$attributeCode] = $attribute;
}

All 5 comments

After couple hours together with XDebug I've found that attributes returned by \Magento\Eav\Model\Entity\AbstractEntity::getAttributesByCode depend on previous calls of \Magento\Catalog\Model\Product\Type\AbstractType::getSetAttributes . If the first product passed to it was having different attribute set than saved one then the result of \Magento\Eav\Model\Entity\AbstractEntity::_isApplicableAttribute was false negative inside of walkAttributes loop, form values are not applied to the stock model.

Having this issue as well

Done a hacky fix for now which seems to work.
Find the function addAttribute() in file module-eav/Model/Entity/AbstractEntity.php

And change the line:
$this->_attributesByCode[$attributeCode] = $attribute;

To:
if (!array_key_exists($attributeCode, $this->_attributesByCode)) {
$this->_attributesByCode[$attributeCode] = $attribute;
}

@Fel1xx Hi, thanks for reporting this issue. Internal ticket was created MAGETWO-70387.

@Fel1xx, thank you for your report.
The issue is already fixed in 2.2.0

Was this page helpful?
0 / 5 - 0 ratings