2

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

2

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'); 
3
  • Its not working for me $avid is null for me Even there's value for that attribute. Can you update code regarding this ? That will be great. Thanks.
    – TBS Mage
    Jul 18 '18 at 10:58
  • 1
    @TBSMage you can try $product->getAttribute('brand'); Jul 18 '18 at 11:09
  • 1
    @TBSMage you are always welcome :) Jul 18 '18 at 11:23
0

Load all products from store then get brand attribute value and assign it to manufaturer

(Manufaturer assumed to be created by admin already)

$product=Mage::getModel('catalog/product')->load($id);

$brandValue=$prod->getData('brand');

$product->setData('manufacturer', $brandValue);
$product->save();

Run below script in root folder

Create an script at magento root update.php and put the below code :

<?php
require_once  "app/Mage.php";
Mage::app("admin");
umask();


$collection = Mage::getResourceModel('catalog/product_collection')->addAttributeToSelect('brand');

foreach($collection as $product){
$val=$product->getBrand();

$product->setManufacturer($val);
$product->getResource()->saveAttribute($product, 'manufacturer');
$product->save();

}

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.