3

When I edit a configurable product in the Configuration section, it shows the list of all the configurations.

I want to disable one of the products listed there so when I choose Disable Product the status does change to "Disabled".

But after saving the product, status changes back to Enabled.

I have the error logs enabled but no error message appears there even when I have cleared the cache and reindexed.

enter image description here

5
+50

Problem solved. After I've tried to change simple products statuses, from the configurable product grid, I've encountered the same problem. Seems to be a magento bug.

The story

Before saving the informations about configurable product, there are initialised the informations about simple products belonging to it. This is happening in module-configurable-product/Controller/Adminhtml/Product/Initialization/Helper/Plugin/UpdateConfigurations.php file, following function:

private function getConfigurationsFromProduct(\Magento\Catalog\Model\Product $configurableProduct)
    {
        $result = [];

        $configurableMatrix = $configurableProduct->hasData('configurable-matrix') ?
            $configurableProduct->getData('configurable-matrix') : [];
        foreach ($configurableMatrix as $item) {
            if (empty($item['was_changed'])) {
                continue;
            } else {
                unset($item['was_changed']);
            }

            if (!$item['newProduct']) {
                $result[$item['id']] = $this->mapData($item);

                if (isset($item['qty'])) {
                    $result[$item['id']]['quantity_and_stock_status']['qty'] = $item['qty'];
                }
            }
        }

        return $result;
    }

Here, the simple products are iterated and if a product contains was_changed, in the array informations, it is added in the $result array to be saved in the database.

The problem: Even if I change the status for a simple product, the was_changed attribute is not set for it, in the informations which will be received by the "save" controller. So, when the simple items are iterated in getConfigurationsFromProduct function, the continue statement will be hit every time, $result array being null.

The solution:

I've found a way to set was_changed attribute, in the toggleStatusProduct function from module-configurable-product/view/adminhtml/web/js/components/dynamic-rows-configurable.js, which is dispatched every time the simple product status is changed. The cleanest way is to rewrite that file and replace the function with:

toggleStatusProduct: function (rowIndex) {
            var tmpArray = this.getUnionInsertData(),
                status = parseInt(tmpArray[rowIndex].status, 10);

            if (status === 1) {
                tmpArray[rowIndex].status = 2;
            } else {
                tmpArray[rowIndex].status = 1;
            }
            tmpArray[rowIndex]['was_changed'] = true;
            this.unionInsertData(tmpArray);
        }

Clear the cache, run a deploy and it should work.

Good luck !

  • Perfect, that fixes it! How do I overwrite that? When I add the file app/design/frontend/Meigee/blacknwhite/Magento_ConfigurableProduct/view/adminhtml/web/js/components it doesn't overwrite. – Howli Aug 1 '17 at 11:30
  • try to run a php bin/magento setup:static-content:deploy followed by php bin/magento cache:clean. Also clear the browser cache – Alex Constantinescu Aug 1 '17 at 11:35
  • If it's working, please be a fair player and mark the answer accordingly !! :D – Alex Constantinescu Aug 1 '17 at 13:59
  • Sorry about that, I thought I had. Would clicking Clean Cache in the backend do the same as running the php bin/magento cache:clean command? – Howli Aug 2 '17 at 16:37
  • No problem :D ...yes, it's the same thing – Alex Constantinescu Aug 2 '17 at 17:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.