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

i found this codes, but i don't know what to do with this codes? or where to copy them?



assign the values to another attribute of that product with this code



i will thankful if you experts help me and explain by details.

** i want weight attribute value to be copied into general_weight always on product save.

  • why you need this program?
    – Amit Bera
    Feb 4, 2015 at 8:24

3 Answers 3


Moh3n,i suggest that export an product from Admin in csv format. with sku,weight and then import that csv with change columns name to general_weight from weight.

pragmatically if want then follow below process:






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 $product){
/*$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.

  • where should i copy this code?
    – Moh3n
    Feb 4, 2015 at 9:30
  • can you please tell me how many product on your system >
    – Amit Bera
    Feb 4, 2015 at 9:32
  • 1
    i want weight attribute to be always copied to general_weight on product save. does this code do that?
    – Moh3n
    Feb 4, 2015 at 9:33
  • about 600 products
    – Moh3n
    Feb 4, 2015 at 9:33
  • when i run 'update.php' with your code i face this error: 'Fatal error: Call to a member function getWeight() on a non-object in /home/dokanche/public_html/update_weight.php on line 12'
    – Moh3n
    Apr 27, 2015 at 9:00

You can do this with a sql query.
But First you need to identify the attribute ids for your attributes and their types.

    attribute_id, attribute_code, backend_type
    attribute_code IN ('weight', 'general_weight') AND
    entity_type_id = (SELECT 
                          entity_type_code = 'catalog_product'

Let's say it turns out like this:

101         |weight        |decimal
502         |general_weight|decimal

To determine the table for each attribute type you just append catalog_product_entity_ to the backend_type.
So in this case catalog_product_entity_decimal is for both of them (and they should be since the attributes should be the same type).

Now run this (backup your database before trying it).Replace 502 and 101 with the ids you got from the query above.:

    `catalog_product_entity_decimal` -- the table for `general_weight` attribute
    (entity_type_id, attribute_id, store_id, entity_id, value)
SELECT entity_type_id, 502 as attribute_id, store_id, entity_id, value
    `catalog_product_entity_decimal` -- the table for `weight` attribute
    attribute_id = 101 -- the id of the weight attribute
    value = VALUES(value)

Now rebuild your indexes.

  • Good and faster way
    – Amit Bera
    Feb 4, 2015 at 9:02
  • @AmitBera. And risky :)
    – Marius
    Feb 4, 2015 at 9:05
  • Yes.it is also risky
    – Amit Bera
    Feb 4, 2015 at 9:05

i have a Weight attribute :

Attribute Code: weight
Scope: general
Catalog Input Type for Store Owner: Text Field
Values Required: yes
Apply To: Simple Product, Bundle Product
Allow HTML Tags on Frontend: yes

and i have a General Weight attribute :

Attribute Code: general_weight
Scope: general
Catalog Input Type for Store Owner: Text Field
Values Required: no
Apply To: All Product Types
Use in Advanced Search: yes
Comparable on Front-end: yse
Allow HTML Tags on Frontend: yes
Visible on Product View Page on Front-end: yes

i want to assign Weight attribute to General Weight without four decimals. i mean i want the value of Weight attribute( for example 2000.0000 to copy into General Weight value on product save (but without for last decimals like 2000).

i made an small extension for that in this way:

i created Moh3n_Attvaluecopier.xml file in app/etc/modules with this content:

<?xml version="1.0"?>

and config.xml file in app/code/local/Moh3n/Attvaluecopier/etc with this content:

<?xml version="1.0"?>

and Observer.php file in app/code/local/Moh3n/Attvaluecopier/model with this content:


class Moh3n_Attvaluecopier_Model_Observer

public function  copyAttribute($observer){


        $_product = $observer->getProduct();
        $_productid = $_product->getId();
        $productModel = Mage::getModel('catalog/product');
        $loadCurrentProduct = $productModel->load($_productid);
  • This code is so imperformant... Take a look at Amit his code to save the attribute, it's 10 times as fast, Marius his answer is even faster but is risky if you don't know what you are doing :). This is not the correct answer. Apr 26, 2015 at 13:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.