Skip to content

Instantly share code, notes, and snippets.

@nhp
Created July 17, 2014 11:13
Show Gist options
  • Save nhp/9166abfee3b7ba2ef6f2 to your computer and use it in GitHub Desktop.
Save nhp/9166abfee3b7ba2ef6f2 to your computer and use it in GitHub Desktop.
Attribute option update model based
public function quickNDirtyUpdateAttributeOptions($row)
{
foreach ($row as $data) {
$this->isAttributeCodeValid($data['attribute_code']);
$id = Mage::getModel('eav/entity_attribute')->getIdByCode('catalog_product', $data['attribute_code']);
$attr = Mage::getModel('eav/entity_attribute')->load($id);
//set adminid to have a general and always present identifier for the attribute options
$allOptions = $attr->setStoreId(0)->getSource()->getAllOptions(false);
foreach (Mage::app()->getStores() as $store) {
$stores[$store->getName()] = $store->getId();
}
foreach ($allOptions as $option) {
$values = array();
if ($option['label'] == $data['admin']) {
if (isset($data['admin_new'])) {
$values[] = $data['admin_new'];
} else {
$values[] = $data['admin'];
}
if (isset($data['view']) && is_array($data['view'])) {
foreach ($data['view'] as $viewKey => $view) {
$values[$stores[$viewKey]] = $view;
}
}
$updated = array(self::COL_ORDER => array($option['value'] => $data['order']),
self::COL_VALUE => array($option['value'] => $values),
);
}
}
// var_dump($data);
// var_dump($updated);
if (isset($data['label'])) {
$labels = array();
foreach ($data['label'] as $labelKey => $viewLabel) {
$labels[$stores[$labelKey]] = $viewLabel;
}
$attr->setData('store_labels', $labels);
}
$attr->setOption($updated);
$result = $attr->save();
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment