Magento2: Multiselect EAV Product Attribute not working in Mass Action

Created on 5 Jul 2016  路  14Comments  路  Source: magento/magento2

Steps to reproduce

  1. Install Magento 2.1
  2. Create a product attribute with frontend input "multiselect" (and assign it to the necessary attribute sets).

    Expected result

  3. You can set values via mass action.

    Actual result

  4. If you want to use it via mass action from the grid, it does not set the selected values on the product(s).

Catalog Fixed in 2.1.x Fixed in 2.2.x Fixed in 2.3.x Clear Description Confirmed Format is not valid Ready for Work bug report

Most helpful comment

This issue was indeed not resolved with release 2.1 (as stated in your previous tickets). Seems like it is caused by some changes made to the admin frontend without taking the consequences to the bulk attribute update feature into account.

The following changes should address the problem:

diff --git a/app/code/Magento/Catalog/Block/Adminhtml/Product/Edit/Action/Attribute/Tab/Attributes.php b/app/code/Magento/Catalog/Block/Adminhtml/Product/Edit/Action/Attribute/Tab/Attributes.php
index 9c5d72f..0b857b5 100644
--- a/app/code/Magento/Catalog/Block/Adminhtml/Product/Edit/Action/Attribute/Tab/Attributes.php
+++ b/app/code/Magento/Catalog/Block/Adminhtml/Product/Edit/Action/Attribute/Tab/Attributes.php
@@ -128,15 +128,13 @@ class Attributes extends \Magento\Catalog\Block\Adminhtml\Form implements
      */
     protected function _getAdditionalElementHtml($element)
     {
-        // Add name attribute to checkboxes that correspond to multiselect elements
-        $nameAttributeHtml = $element->getExtType() === 'multiple' ? 'name="' . $element->getId() . '_checkbox"' : '';
         $elementId = $element->getId();
         $dataAttribute = "data-disable='{$elementId}'";
         $dataCheckboxName = "toggle_" . "{$elementId}";
         $checkboxLabel = __('Change');
         $html = <<<HTML
 <span class="attribute-change-checkbox">
-    <input type="checkbox" id="$dataCheckboxName" name="$dataCheckboxName" class="checkbox" $nameAttributeHtml onclick="toogleFieldEditMode(this, '{$elementId}')" $dataAttribute />
+    <input type="checkbox" id="$dataCheckboxName" name="$dataCheckboxName" class="checkbox" onclick="toogleFieldEditMode(this, '{$elementId}')" $dataAttribute />
     <label class="label" for="$dataCheckboxName">
         {$checkboxLabel}
     </label>
diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Action/Attribute/Save.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Action/Attribute/Save.php
index abe72e1..f878b89 100644
--- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Action/Attribute/Save.php
+++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Action/Attribute/Save.php
@@ -132,7 +132,7 @@ class Save extends \Magento\Catalog\Controller\Adminhtml\Product\Action\Attribut
                         $attributesData[$attributeCode] = $value;
                     } elseif ($attribute->getFrontendInput() == 'multiselect') {
                         // Check if 'Change' checkbox has been checked by admin for this attribute
-                        $isChanged = (bool)$this->getRequest()->getPost($attributeCode . '_checkbox');
+                        $isChanged = (bool)$this->getRequest()->getPost('toggle_' . $attributeCode);
                         if (!$isChanged) {
                             unset($attributesData[$attributeCode]);
                             continue;

Download / patch: 5459_multiselect_bulk_update_patch.txt

All 14 comments

This issue was indeed not resolved with release 2.1 (as stated in your previous tickets). Seems like it is caused by some changes made to the admin frontend without taking the consequences to the bulk attribute update feature into account.

The following changes should address the problem:

diff --git a/app/code/Magento/Catalog/Block/Adminhtml/Product/Edit/Action/Attribute/Tab/Attributes.php b/app/code/Magento/Catalog/Block/Adminhtml/Product/Edit/Action/Attribute/Tab/Attributes.php
index 9c5d72f..0b857b5 100644
--- a/app/code/Magento/Catalog/Block/Adminhtml/Product/Edit/Action/Attribute/Tab/Attributes.php
+++ b/app/code/Magento/Catalog/Block/Adminhtml/Product/Edit/Action/Attribute/Tab/Attributes.php
@@ -128,15 +128,13 @@ class Attributes extends \Magento\Catalog\Block\Adminhtml\Form implements
      */
     protected function _getAdditionalElementHtml($element)
     {
-        // Add name attribute to checkboxes that correspond to multiselect elements
-        $nameAttributeHtml = $element->getExtType() === 'multiple' ? 'name="' . $element->getId() . '_checkbox"' : '';
         $elementId = $element->getId();
         $dataAttribute = "data-disable='{$elementId}'";
         $dataCheckboxName = "toggle_" . "{$elementId}";
         $checkboxLabel = __('Change');
         $html = <<<HTML
 <span class="attribute-change-checkbox">
-    <input type="checkbox" id="$dataCheckboxName" name="$dataCheckboxName" class="checkbox" $nameAttributeHtml onclick="toogleFieldEditMode(this, '{$elementId}')" $dataAttribute />
+    <input type="checkbox" id="$dataCheckboxName" name="$dataCheckboxName" class="checkbox" onclick="toogleFieldEditMode(this, '{$elementId}')" $dataAttribute />
     <label class="label" for="$dataCheckboxName">
         {$checkboxLabel}
     </label>
diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Action/Attribute/Save.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Action/Attribute/Save.php
index abe72e1..f878b89 100644
--- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Action/Attribute/Save.php
+++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Action/Attribute/Save.php
@@ -132,7 +132,7 @@ class Save extends \Magento\Catalog\Controller\Adminhtml\Product\Action\Attribut
                         $attributesData[$attributeCode] = $value;
                     } elseif ($attribute->getFrontendInput() == 'multiselect') {
                         // Check if 'Change' checkbox has been checked by admin for this attribute
-                        $isChanged = (bool)$this->getRequest()->getPost($attributeCode . '_checkbox');
+                        $isChanged = (bool)$this->getRequest()->getPost('toggle_' . $attributeCode);
                         if (!$isChanged) {
                             unset($attributesData[$attributeCode]);
                             continue;

Download / patch: 5459_multiselect_bulk_update_patch.txt

@wardcapp thank you for the patch!

I can confirm this issue exists when trying to save a single product with a multiselect element using 2.1 EE, the patch from @wardcapp resolved the issue for me, thank you.

How can I apply this patch on 2.0.7 ? I am having the same problem with multiselect attibutes not changing when bulk editing in the catalog.

Edit - the paths for 2.0.7 are different:
vendor/magento/module-catalog/Block/Adminhtml/Product/Edit/Action/Attribute/Tab/Attributes.php
vendor/magento/module-catalog/Controller/Adminhtml/Product/Action/Attribute/Save.php

Manually editing these two files fixed the issue for me on 2.0.7 :) thanks!

@bh-ref thank you for your report.
We already have internal ticket MAGETWO-55054 for this issue.
I have linked it to this one.

Thank you so much for this patch.

worked for me but to clarify in the attributes.php I removed the old line and in the save.php I added the new one underneath the old one.
Also in 2.1 the file paths are as jvreeken said:
vendor/magento/module-catalog/Block/Adminhtml/Product/Edit/Action/Attribute/Tab/Attributes.php
vendor/magento/module-catalog/Controller/Adminhtml/Product/Action/Attribute/Save.php

Just upgraded to 2.1.1
Issue does still exist!

@wardcapp's solution has resolved defenetely the issue.
As per @rosandrest and @jvreeken the paths to the files are:
vendor/magento/module-catalog/Block/Adminhtml/Product/Edit/Action/Attribute/Tab/Attributes.php
vendor/magento/module-catalog/Controller/Adminhtml/Product/Action/Attribute/Save.php

@okorshenko can please take a look to this issue and get this done for the next release.
From past and current release notes this issue was meant to be already resolved but it is still present in 2.1.1

Thanks

Just upgraded to 2.1.2 and the issue still exists.
The patch at:
https://github.com/magento/magento2/commit/62783141641544080d83d604b86596c178a26854
fixed the issue for me :)

This patch worked for me on 2.1.2. Thanks @jvreeken.

Yep, this patch works fine on 2.1.2! Thanks @jvreeken

If field is required you must skip unchecked fields from validation. My fix -> https://github.com/webcodebg/magento2/commit/c2a5e579dbbc57025cad88910610214f6f1d059c

ver. 2.1.3

It looks like they've included the patch 6278314 in v2.1.3 as I finally didn't have to fix this after upgrading... however the Attributes.php file was still the same....

@bh-ref, thank you for your report.
The issue is already fixed in develop branch, 2.2.0, 2.1.9

Was this page helpful?
0 / 5 - 0 ratings