1

I want to create a custom field called Price1. I tried this code.

$fieldset->addField('Price1','text', array(
                'name'=>'Price1',
                'class'=>$attribute->getIsRequired()?'required-entry':'',
                'lable'=>Mage::helper('catalog')->_('Price1'),
                'title'=>Mage::helper('catalog')->_('Price1'),
                ));

And I got this error.

Fatal error: Call to a member function getIsRequired() on a non-object in C:\wamp\www\multiplecurrencies\app\code\core\Mage\Adminhtml\Block\Catalog\Product\Edit\Tab\Attributes.php on line 71

What am I missing?

6
  • What is $attribute variable?
    – Marius
    Commented Jul 8, 2014 at 12:56
  • Umm... I am trying to figure that out. Commented Jul 8, 2014 at 12:57
  • The problem originates from there. I think the variable is not defined.
    – Marius
    Commented Jul 8, 2014 at 13:08
  • I changed 'class' value to 'price-box' and got this error. Fatal error: Call to a member function getIsRequired() on a non-object in C:\wamp\www\multiplecurrencies\app\code\core\Mage\Adminhtml\Block\Catalog\Product\Edit\Tab\Attributes.php on line 71 Commented Jul 8, 2014 at 13:16
  • Where did you add this code? Post the full file.
    – Marius
    Commented Jul 8, 2014 at 13:23

1 Answer 1

1

If you want to add an attribute to the product add/edit page you shouldn't add it by code.
Create the attribute in Catalog->Attributes->Manage attributes, then go to Catalog->Attributes->Manage attribute sets edit each attribute set and add the attribute by drag and drop in the group called 'Prices'.

3
  • I know that method. I tried programatically for learning purposes. Pity, it didn't work. Commented Jul 8, 2014 at 13:30
  • @AjayKulkarni. Nope. it does not work like that.
    – Marius
    Commented Jul 8, 2014 at 13:31
  • Okay, I've one more question. Will post it very soon. Commented Jul 8, 2014 at 13:31

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.