Magento设置新的属性值 [英] Magento set the new attribute value
问题描述
我为所有产品创建了一个类型为textarea的新IMEI属性,请参见图片.任何人都可以指出一个函数来更新其值.我有类似以下的代码.
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登录到Mage_Sales_Model_Order.
$this belogns to Mage_Sales_Model_Order.
foreach ($this->getAllItems() as $item) {
$item->setImei('123');
$item->save();
echo $item->getImei();
}
从上一条语句中我得到123,但是从admin查看时.它在那里没有改变.同样,属性和值将存储在哪个表中,因此我可以从那里进行调试.
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.
推荐答案
$ this-> getAllItems()
是什么类? Mage_Catalog_Model_Product
?
如果不是 Mage_Catalog_Model_Product
,则按ID加载产品并保存产品
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();
}
这篇关于Magento设置新的属性值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!