1

i have this Observer.php file in app/code/local/Moh3n/Attvaluecopier/model to copy a product attribute value into another product attribute on product save:

<?php

class Moh3n_Attvaluecopier_Model_Observer
{

public function  copyAttribute($observer){

    if(!$this->_processFlag):

        $this->_processFlag=true;
        $_product = $observer->getProduct();
        $_productid = $_product->getId();
        $productModel = Mage::getModel('catalog/product');
        $loadCurrentProduct = $productModel->load($_productid);
        $loadCurrentProduct->setGeneralWeight(intval($loadCurrentProduct->getWeight()));
        $weight = intval($loadCurrentProduct->getWeight());
        $gw = (string)$weight. " KG";
        $loadCurrentProduct->setGeneralWeight($gw);
        $loadCurrentProduct->save();
        endif;}
    }

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

<?xml version="1.0"?>
<config>
    <modules>
        <Moh3n_Attvaluecopier>
            <active>true</active>
            <codePool>local</codePool>
        </Moh3n_Attvaluecopier>
    </modules>
</config>

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

<?xml version="1.0"?>
<config>
    <modules>
        <Moh3n_Attvaluecopier>
            <version>0.0.1</version>
        </Moh3n_Attvaluecopier>
    </modules>
    <global>
        <models>
            <moh3nattvaluecopier>
                <class>Attvaluecopier_Model</class>
            </moh3nattvaluecopier>
        </models>
        <events>
            <catalog_product_save_after>
                <observers>
                    <moh3n_attvaluecopier_model_observer>
                        <type>singleton</type>
                        <class>Moh3n_Attvaluecopier_Model_Observer</class>
                        <method>copyAttribute</method>
                    </moh3n_attvaluecopier_model_observer>
                </observers>
            </catalog_product_save_after>
        </events>
    </global>
</config>

full extension link: How to copy a product's attributes value to another attribute?

it was working fine on localserver but after i migrated magento from local to online server it wont work. no error, no log. it wont copy the value.

  • Please share the part of config.xml which registers this event observer, and/or the code that calls it. – Tyler V. Mar 17 '15 at 23:15
  • @TylerV. check my question again please. its updated – Moh3n Mar 18 '15 at 5:02
  • Sounds like an uncleared cache on the online server. – Tyler V. Mar 18 '15 at 5:14
  • @TylerV. you mean every thing is alright with this extension, yah? – Moh3n Mar 18 '15 at 6:42
  • It looks fine, though I haven't run it. But the hunch that I have if it worked in one environment but not another is that either 1) The new attribute doesn't exist on the new environment, or 2) The cache wasn't cleared, so Magento isn't aware of the new observer. – Tyler V. Mar 18 '15 at 20:06
1

Could you try updating your config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Moh3n_Attvaluecopier>
            <version>0.0.1</version>
        </Moh3n_Attvaluecopier>
    </modules>
    <global>
        <models>
            <attvaluecopier>
                <class>Moh3n_Attvaluecopier_Model</class>
            </attvaluecopier>
        </models>
        <events>
            <catalog_product_save_after>
                <observers>
                    <moh3n_attvaluecopier_model_observer>
                        <type>singleton</type>
                        <class>attvaluecopier/observer</class>
                        <method>copyAttribute</method>
                    </moh3n_attvaluecopier_model_observer>
                </observers>
            </catalog_product_save_after>
        </events>
    </global>
</config>

Check if your directories are spelled correctly Mohen/Attvaluecopier/Model/Observer.php

Check if compilation is disabled before installing the module System / Tools / Compilation

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.