Is there a way in Magento where I can assign Attribute X's value to Attribute Y programmatically ?
So far I have tried this. I created the Y attribute with following settings:
$setup->addAttribute('catalog_product','myAttribute',array(
'group'=>'General',
'input'=>'label',
'type'=>'varchar',
'label'=>'Value of Attribute X',
'visible'=>1,
'backend'=>'beta/entity_attribute_backend_myattribute',
'global'=>Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE
));
In my backend model, I have done this:
class Namespace_Module_Model_Entity_Attribute_Backend_Myattribute extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract
{
public function beforeSave($object){
$attrCode = $this->getAttribute()->getAttributeCode();
$object->setData($attrCode,'HAHAHA');
parent::beforeSave($object);
return $this;
}
}
I am able to see "HAHAHA" as the attribute value in the Product Edit page. I want to change this to value of another attribute. How do I do it ? How do I access another attribute's value of the same product from this class ?
PS: What I am actually trying to achieve is this. The attribute X is of type multi select with 100s of options. So the attribute Y must keep track of the options selected of X, and Y shows the value in product page in read-only format.
Best Answer
It's Simple
now assign the values to another attribute of that product
Don't forgot to save product.