Skip to content

Instantly share code, notes, and snippets.

@Amakata
Created August 28, 2017 06:02
Show Gist options
  • Save Amakata/80377f00a8832528b5430f162960147e to your computer and use it in GitHub Desktop.
Save Amakata/80377f00a8832528b5430f162960147e to your computer and use it in GitHub Desktop.
属性のオプション値がなければオプション値を追加をセットアップスクリプトじゃないところでしたい場合
$attribute_code = '';
$value = '';
$attribute = Mage::getSingleton('eav/config')->getAttribute(Mage_Catalog_Model_Product::ENTITY, $attribute_code);
if (in_array($attribute->getFrontendInput(), array('select')) && strlen($value) > 0) {
$values = Mage::getResourceModel('eav/entity_attribute_option_collection')->setAttributeFilter(
$attribute->getId())
->setStoreFilter()
->addFieldToFilter('tdv.value', array('in' => $value))
->load();
if (count($values) == 0) {
$data = array(
'option' => array(
'value' => array(
'optionnone' => array(
0 => $value, // Admin
),
),
),
);
$attribute->addData($data)->save();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment