1

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 :

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

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

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

$product->getResource()->getAttribute('weight')->getFrontend()->getValue($product-)

*/
$product->setGeneralWeight($val);
$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

2

Replace

foreach($collection as $eachproduct){

with:

foreach($collection as $product){
2

Your foreach loop looks like this:

foreach($collection as $eachproduct){

but then you get the weight like this:

$val=$product->getWeight();

the variable names don't match.

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

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.