【发布时间】:2011-08-01 02:48:58
【问题描述】:
我有一个脚本,可以将图像添加到我的产品中。用于设置图片、small_image 和 thumbnail。该代码适用于默认视图,但是当我切换到存储视图时,媒体库设置为“no_image”。导致我的产品在前端完全没有图像。
我尝试重置商店视图属性但没有成功。
$product->addImageToMediaGallery($fileName, array('image', 'small_image', 'thumbnail'), false, false);
$attributes = $product->setStoreId(1)->getTypeInstance(true)->getSetAttributes($product);
if (isset($attributes['media_gallery'])) {
$attributes['media_gallery']->getBackend()->clearMediaAttribute($product, array('image', 'small_image', 'thumbnail'));
}
$product->save();
如何修改特定的商店属性,并将它们重置为使用父属性?
谢谢。
【问题讨论】:
-
我找到了解决方案。比我想象的要简单:
foreach($product->getStoreIds() as $storeId) {$product->load(null);$product->setStoreId($storeId)->setImage(false);$product->setStoreId($storeId)->setSmallImage(false);$product->setStoreId($storeId)->setThumbnail(false);$product->save();} -
这个“解决方案”对我不起作用!!!我有 magento 1.6.1