Magento – Set attribute value from other attribute

attribute-setattributesmodelshell

I have custom attribute 'brand'. I should set its value in attribute 'manufacturer'. How can i do this? For now, all that i cat do ->
shell file

require_once dirname(__FILE__) . '/../app/Mage.php';
Mage::app('admin');

$product = Mage::getModel('catalog/product')->getCollection()->addAttributeToFilter('manufacturer', Null);
$avid = $product->getResource()->getAttribute('brand');
$product->setData('manufacturer', $avid)->save();

There the mistake or maybe it is fundamentally wrong?
And it must be replaced in all products

Best Answer

For me saving Product object for single data is not good idea, its take to much time. you can try below code which will help you to reduce time as well ,

and if you are saving data from shell then set store as admin.

Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); //set admin store for current opration

$product = Mage::getModel('catalog/product')->getCollection()->addAttributeToFilter('manufacturer', Null);

$avid = $product->getResource()->getAttribute('brand');
$product->setData('manufacturer', $avid);
$product->getResource()->saveAttribute($product, 'manufacturer');