[英]When I update an attribute programatically, it doesn't reflect on admin. Why?
I have an attribute post_to_amazon that can be set to Yes or No on the product. 我的属性post_to_amazon可以在产品上设置为Yes或No。
This is my code: 这是我的代码:
require_once('../app/Mage.php');
Mage::app();
$_product = Mage::getModel('catalog/product')->load("83061");
echo $_product->getPostToAmazon();
$_product->setData("post_to_amazon", "11063");
$_product->save();
The echo prints 11063 which is the value for Yes but i'm not seeing Yes selected for the dropdown on admin. 回显打印11063,这是“是”的值,但我在admin的下拉菜单中没有看到“是”。
Why isn't the dropdown showing Yes when the echo is showing 11063? 当回显显示11063时,为什么下拉列表不显示“是”?
Here are the settings for my attibute. 这是我衣服的设置。 I'm using Magento 1.9.
我正在使用Magento 1.9。
Try with this code hope this might useful to you. 尝试使用此代码,希望它可能对您有用。
require_once('../app/Mage.php');
Mage::app();
$_product = Mage::getModel('catalog/product')->load("83061");
echo $_product->getPostToAmazon();
$attrCode = 'post_to_amazon';
$valueText = ('Yes');
$valueId = Mage::getModel('catalog/product')->getResource()->getAttribute($attrCode)->getSource()->getOptionId($valueText);
$_product->setData($attrCode, $valueId);
$_product->save();
我发现在Mage :: app()之后我错过了这个
Mage :: app ()->setCurrentStore(Mage_Core_Model_App :: ADMIN_STORE_ID);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.