I want to copy a product's attribute (weight) to another atribute (general_weight).

I found this:

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

require_once  "app/Mage.php";

 Step2: get Product Collection filter by Saleable
$collection = Mage::getResourceModel('catalog/product_collection')->addAttributeToSelect('weight');

foreach($collection as $eachproduct){
/*$product->getWeight() is not given the value then used 


$product->getResource()->saveAttribute($product, 'general_weight');


then run the script by browser or shell php program.

but this faces to an error:

Fatal error: Call to a member function getWeight() on a non-object in update.php on line 12



foreach($collection as $eachproduct){


foreach($collection as $product){

Your foreach loop looks like this:

foreach($collection as $eachproduct){

but then you get the weight like this:


the variable names don't match.

  • welcome back @marius..... happy to see again – Amit Bera Apr 27 '15 at 13:10

There issue with product object name.you should change $eachproduct to $productt as product object variably name is not match that why this create error

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.