To set an attribute val I would use:
$product->setNameofmyattribute('somestuff');
Now I have the name of my attribute in a string.
So how can I merge:
$attribute = 'Nameofmyattribute';
$product->set[here comes my string]('somestuff');
You can use setDataUsingMethod()
defined in Varien_Object
.
For example, if your attribute is called some_attribute
the following are identical:
$product->setSomeAttribute('some_value');
$product->setDataUsingMethod('some_attribute', 'some_value');
[Edit: and a bit off topic]
It works the same way for getters:
$product->getSomeAttribute();
is the same as
$product->getDataUsingMethod('some_attribute');
PHP can interpret this automatically, but you'll have to prepend the set
keyword:
$attribute = 'Nameofmyattribute';
$setter = 'set' . $attribute;
$product->$setter('somestuff');