我试图在 Magento 1.8 中以编程方式创建一个产品,然后为其设置一些属性值。到目前为止,一切正常,属性与产品一起正确保存在“默认”范围内。
问题是我的商店有两种不同的“商店 View ”,一种是英语,一种是法语。我不知道如何为特定属性的数据设置“范围”或“存储 View ”。
如何告诉 Magento 保存特定范围的属性值?
下面是使用“简短描述”属性的代码示例:
$product = new Mage_Catalog_Model_Product();
$product->setSku($sku);
$product->setAttributeSetId($attributeSetId);
$product->setTypeId($typeId);
$product->setName($sku);
$product->setWebsiteIDs(array($websiteId));
$product->setShortDescription('Short description in english');
$product->setShortDescription('Short description in french'); // Scope change here?
最佳答案
创建产品后,它应该有一个 ID。
这是一种快速更新特定商店 View 的产品名称和简短描述的方法,无需调用资源消耗的 save
方法。
假设产品 id 为 10,商店 View id 为 2。
运行这个:
$productId = 10;
$storeId = 2;
$newName = 'Nom de produit';
$newShortDescription = 'description de produit';
Mage::getSingleton('catalog/product_action')->updateAttributes(
array($productId),
array('name'=>$newName, 'short_description' => $newShortDescription),
$storeId
);
关于magento - 如何保存特定商店 View 的属性值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23353555/