I need to set a new value to a custom product attribute.

I want this to happen when a new product is created. The default value of the attribute is 0, I need to set it to 1.

I have an event observer for catalog_product_load_after.

<?xml version="1.0"?>

Here is my observer

class Schott_ShowQuoteAtZero_Model_Observer
        public function showQuoteButtonAtZeroPrice(Varien_Event_Observer $observer)
            $product = $observer->getEvent()->getProduct();

It does not change the attribute value. Can anyone help?


You can set the default value for your attribute in:

Admin -> Catalog -> Attribute -> Manage attributes

If you want to set the value when you create a product from backend, you can use catalog_product_new_action event.

When you use catalog_product_save_before event, please remove $product->save(); otherwise it will create an infinite loop.

Btw ... is it possible that your config.xml isn't complete? I miss the <models> node:

  • In admin it is not possible to edit the attribute (default value) – Self Diagnostics Mar 23 '18 at 14:49
  • catalog_product_new_action does not change a thing – Self Diagnostics Mar 23 '18 at 14:50
  • config is good, this structure works for other modules too. – Self Diagnostics Mar 23 '18 at 14:51
  • @SelfDiagnostics You're right, admin default value only works for text attributes. Without declared <models> it can not work ... Can you please add a Mage::log to you observer to ensure it is called? – sv3n Mar 23 '18 at 15:11
  • sorry, I did not read your text carefully enough. You are right, it works, thank you! – Self Diagnostics Mar 23 '18 at 15:18

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.