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?

  • What is $attribute variable? – Marius Jul 8 '14 at 12:56
  • Umm... I am trying to figure that out. – brainReader Jul 8 '14 at 12:57
  • The problem originates from there. I think the variable is not defined. – Marius Jul 8 '14 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 – brainReader Jul 8 '14 at 13:16
  • Where did you add this code? Post the full file. – Marius Jul 8 '14 at 13:23
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'.

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

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.