2

How can I change the label associated with an attribute in the catalog_entity_attribute_save_before event?

When I say label, I mean the value set here:

Catalog -> Attributes -> Manage Attributes -> Click on an attribute -> Manage Labels / Options -> Manage Titles -> Admin

I have tried this in my observer, but $attribute->getLabel() returns NULL.

class NS1_ProductAttributeSpacesAndProperty_Model_Observer
{
    public function catalog_entity_attribute_save_before($observer)
    {
        $attribute = $observer->getEvent()->getAttribute();

        $entityTypeId = $attribute->getEntityTypeId();
        if($entityTypeId == 4)
        {
            // the attribute is a product attribute
            $label = $attribute->getLabel();
            echo gettype($label);exit; // prints NULL
            //$attribute->setLabel("Test");
        }
    }
}

Edit:

I have managed to retrieve the label with $attribute->getFrontendLabel(), but I am still unable to update the attribute label before it saves.

2

I have solved this now by using:

$labels = $attribute->getFrontendLabel();

$labels[0] = 'blah';

$attribute->setFrontendLabel($labels);
  • 1
    Just for future reference, frontend_label should be an array. The key will be the store ID, and the value the label for that store ID. In your case, "0" is the Admin Store. – Mayers Feb 16 '15 at 21:47
  • Fantastic thanks, I see that it's 1 array element per column in the GUI. – Mex Feb 16 '15 at 22:25

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.