1

I found this article to add new options for a attribute using program perfectly:
http://www.danneh.org/2011/01/getting-value-of-attribute-option-and-adding-a-new-attribute-option-in-magento/

But every attributes will always create with position '0' and I want to sort them because their values are numbers.
Can I set attribute options' position when I create them or update the position after I create them?

2
  • this is pretty simple (in magento admin), while you go to Manage Label/ Option tab, there is a box to type 0,1,2 or whatever you need .. if that u are referring to
    – echoashu
    Commented Sep 4, 2014 at 7:27
  • @echoashu-I know I can change it using admin panel but currently I want the program can set the option's position in auto when the option is created.
    – Bruce Chen
    Commented Sep 4, 2014 at 7:39

1 Answer 1

0

Try:

public function addAttributeOption($attributeCode, $optionValue, $sortPosition) {
    $attribute = Mage::getModel('eav/entity_attribute')->loadByCode('catalog_product', $attributeCode);      
    $option = array('value' => array($optionValue, $optionValue), // set default value, store value
                    'order' => array($sortPosition)); // set sort posiiton
    $attribute->setOption($option);
    $attribute->save();

    return $this->getAttributeOptionValue($attributeCode, $optionValue);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.