1

i have this code in an observer.php :

<?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()));
        $loadCurrentProduct->save();
        endif;}
    }

it copies the weight attribute value into general_weight attribute without decimals.

i want to add a value like (KG) to general_weight right after copied value. i want general_weight to show this way: 1000 KG

how to do that?

1

Assuming you are saving it as a string, just do this:

$weight = intval($loadCurrentProduct->getWeight());
$gw = (string)$weight. " KG";
$loadCurrentProduct->setGeneralWeight($gw);

If you need to save it as an integer for comparison or something, you could add the KG when outputting the value in the template, or write a custom getter for general_weight in your model that gives you

return $value . " KG";

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.