Magento - cannot delete mulitple selection value in admin file

I created a new attribute (multiple selection) with some values, everything works fine, but when I want to delete all the selected values ​​for the product, I get the message "The product attribute has been saved." but the values ​​are still selected.

Notes:

  • I click Ctrl + Clickto undo the last value before saving.
  • I set the value to Required My attribute No
  • If I save the product without any selected value, then the values ​​will not be selected.
  • My indexes are updated correctly.
  • Below are two screens, on the left are the parameters of my attribute, and on the right are several.

enter image description here

I'm running out of ideas, so thanks for your help.

+5
source share
5 answers

This is the well-known (annoying) behavior of Magento Adminhtml forms.
The problem is that if a value is not selected for the multi selector, the value for this attribute will not be sent when the form is submitted.

On the server side, Magento downloads the model, sets all published attribute values ​​to the model, and saves it.
Since no value was published, the original value loaded into the model was not updated.

As a solution for attributes with a custom source model, I want to provide an empty option with a special parameter value (for example, -1). This value should not be 0or an empty string.

- , _beforeSave(). , .

:

:

class Your_Module_Model_Entity_Attribute_Source_Example
    extends Mage_Eav_Model_Entity_Attribute_Source_Abstract
{
    const EMPTY = '-1';

    public function getAllOptions()
        $options = array(
            array('value' => 1, 'label' => 'One'),
            array('value' => 2, 'label' => 'Two'),
            array('value' => 3, 'label' => 'Three')
        );
        if ($this->getAttribute()->getFrontendInput() === 'multiselect')
        {
            array_unshift($options, array('value' => self::EMPTY, 'label' => ''));
        }
        return $options;
    }
}

:

class Your_Module_Model_Entity_Attribute_Backend_Example
    extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract
{
    public function beforeSave($object)
    {
        $code = $this->getAttribute()->getAttributeCode();
        $value = $object->getData($code);
        if ($value == Your_Module_Model_Entity_Attribute_Source_Example::EMPTY)
        {
            $object->unsetData($code);
        }
        return parent::beforeSave($object);
    }
}

, .

+11

, , , , - , .

, , drop down:

  • " "
  • ,

.

+1

, <can_be_empty>, system.xml :

<can_be_empty>1</can_be_empty>

= "selected" "", - .

+1

html chrome/firefox, . .

<option value="99999999">Click this to unselect option</option>
+1

Magento 1.7.0.2, :

  • Firefox Firebug

  • , " ", - Firebug: XLarge

  • Double-click on the selected, right-click, cut, do not select the selected attribute and just save the page.

0
source

All Articles