以编程方式为Store View(Magento)设置默认媒体库图像

Fre*_*red 8 php magento

我有一个脚本,可以将图像添加到我的产品中.它用于设置图像,small_image和缩略图.该代码适用于默认视图,但当我切换到商店视图时,媒体库设置为"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(); 
Run Code Online (Sandbox Code Playgroud)

如何修改特定的商店属性,并将其重置为使用父属性?

谢谢.

clo*_*eek 4

您的“简单解决方案”可以更简单;

foreach($product->getStoreIds() as $storeId) {
    $product->setStoreId($storeId)
        ->setImage(false)
        ->setSmallImage(false)
        ->setThumbnail(false)
        ->save();
}
Run Code Online (Sandbox Code Playgroud)