Php – Magento set the new attribute value

magentoPHP

I have created a new IMEI attribute of type textarea for all products, see from the image. Can anyone point out a function to update the its value. I have the code like the following.

$this belogns to Mage_Sales_Model_Order.

    foreach ($this->getAllItems() as $item) {

                 $item->setImei('123');

             $item->save();
             echo $item->getImei();
    }

I am getting 123 from the last statement but when I am viewing from admin. Its not changing there. Also in which table the attribute and value will be stored, So I can debug from there.

enter image description here

Best Answer

What class is $this->getAllItems() is it Mage_Catalog_Model_Product?

If it not Mage_Catalog_Model_Product then load the product by id and save the product

foreach ($this->getAllItems() as $item) {
     $product = Mage::getModel('catalog/product')->load($item->getId() or $item->getProductId())
     $product->setImei($product->getImei() . '123');

     $product->save();   
}
Related Topic