在商店视图级别以编程方式更改产品属性 [英] Programmatically change product attribute at store view level

查看:66
本文介绍了在商店视图级别以编程方式更改产品属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很抱歉,如果这个问题很琐碎,但我一直在努力寻找我在这里做错的地方.我正在尝试在商店视图级别上更改属性的值,但默认值也已更改,但不应更改.当然,此属性被设置为商店视图范围".为简单起见,我尝试使用产品名称.没有成功.

I'm sorry if this question is trivial but I've been struggling to find what I am doing wrong here. I am trying to change the value of an attribute on a store view level but the default is also changed whereas it shouldn't be. Of course, this attribute is set up to be "store-view-scoped". To keep it simple, I've tried with the product name. No success.

以下是我尝试过的失败测试...

Below are unsuccessful tests I've tried...

您在这里看到我在做什么错吗?

Do you see what I am doing wrong here?

非常感谢.

我的尝试:

$product = Mage::getModel('catalog/product')->load(PRODUCT_ID);
$product->setStoreId(STORE_ID)->setName('new_name')->save();

$product = Mage::getModel('catalog/product')->load(PRODUCT_ID);
$product->setStoreId(STORE_ID)->setStore(STORE_CODE)->setName('new_name')->save();

$product = Mage::getModel('catalog/product')->load(PRODUCT_ID);
$product->setStoreId(STORE_CODE)->setName('new_name')->save();

$product = Mage::getModel('catalog/product')->setStoreId(STORE_ID)->load(PRODUCT_ID);
$product->setName('new_name')->save();

$product = Mage::getModel('catalog/product')->setStoreId(STORE_ID)->load(PRODUCT_ID);
$product->setStoreId(STORE_ID)->setName('new_name')->save();

我什至尝试在产品模型加载之前在下面添加以下行...

I even tried by adding the line below before the product model load...

Mage::app()->setCurrentStore(STORE_ID);

推荐答案

因此,以下是用于更改特定商店视图上特定产品属性的属性值的完整代码段.产品名称示例:

So here is the complete snippet to change attribute value for a specific product attribute on a specific store view. Example with the product name :

Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
$product = Mage::getModel('catalog/product')->load(PRODUCT_ID);
$product->setStoreId(STORE_ID)->setName('my_new_product_name')->save();

还有一个额外的答案,可能是有兴趣将属性值更改为默认值.在这种情况下,必须将参数'false'传递给setAttribute:

And as an additional answer, one could be interested in changing the attribute value to the default one. In this case, the argument 'false' must be passed to the setAttribute :

Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
$product = Mage::getModel('catalog/product')->load(PRODUCT_ID);
$product->setStoreId(STORE_ID)->setName(false)->save();

这篇关于在商店视图级别以编程方式更改产品属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆