これは、Magento Adminhtmlフォームの既知の(迷惑な)動作です。
問題は、複数選択に値が選択されていない場合、フォームの送信時にその属性の値が送信されないことです。
サーバー側で、Magentoはモデルをロードし、モデルに投稿されたすべての属性値を設定して保存します。
値が投稿されていないため、モデルにロードされた元の値は更新されませんでした。
カスタムソースモデルを使用した属性の解決策として、特別なオプション値を持つ空のオプションを提供する傾向があります(例-1)。0その値は、または空の文字列であってはなりません。
次に、メソッド内のその特別な値をチェックするその属性のバックエンドモデルを指定します_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);
}
}
より良い回避策を見つけたら、私に知らせてください。