简体   繁体   English

当我以编程方式更新属性时,它不会反映在admin上。 为什么?

[英]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.

相关问题 如何为管理员显示每个用户的特定项目? - How do I show specific projects of each user for the admin.? 我有两种类型的用户 - 用户和管理员。 我想包括一个会话检查,以检查该人是以用户身份登录还是以管理员身份登录。 - I have two types of users - User and Admin. I would like to include a session check, to check if the person is logging on as a user or as an admin. 为什么我不能从管理员视图更新帖子元? - Why can't I update post meta from the admin view? 在Sonata Admin中设置表演动作时出现问题。 当我尝试使用标签选项自定义显示字段的显示标签时出错 - Problems when setting up a show action in Sonata Admin. Error when I was trying customize the displayed label of a show field using the label option 当我使用Ajax更新实体时,为什么从Controller的Request对象不包含数据信息? - Why Request object from Controller doesn't contain data information when i used Ajax to update entity? 我不确定为什么我的代码不更新数据库 - I'm not sure why my code doesn't update the database 当我尝试更新时,unlink() 函数不会删除图像 - unlink() function doesn't delete the image when I try to update 当我从公共区域发布帖子时,wp_insert_post挂钩不起作用。 但是从管理区域可以正常工作。 为什么? - wp_insert_post hook doesn't work when I publish a post from public area. But works fine from admin area. Why? 为什么当我包含 php 脚本时它不执行 - Why doesn't the php script execute when I include it 嗨,我在访问我的网站和 prestashop 管理员时在 prestashop 1.6 中遇到以下错误。 请提出修复建议 - Hi i am getting the below error in prestashop 1.6 while accessing my website and prestashop admin. Please suggest with the fix
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM