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?

  • 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 Sep 4 '14 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 Sep 4 '14 at 7:39
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, privacy policy and cookie policy

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