这肯定是一个非常简单的编程任务,我绝对无法在网上找到任何有关它的信息。基本上,我正在尝试删除产品图像。我想删除产品媒体库中的所有图像。我可以在不为如此简单的任务编写一百万行代码的情况下完成此操作吗?
请注意,我已经尝试过:
$attributes = $product->getTypeInstance()->getSetAttributes();
if (isset($attributes['media_gallery'])) {
$gallery = $attributes['media_gallery'];
$galleryData = $product->getMediaGallery();//this returns NULL
foreach($galleryData['images'] as $image){
if ($gallery->getBackend()->getImage($product, $image['file'])) {
$gallery->getBackend()->removeImage($product, $image['file']);
}
}
}
这绝对不行。我试图在导入过程中删除图像,这样我就不会不断累积重复项。任何帮助将不胜感激。
好吧,这就是我最终解决问题的方法。
if ($product->getId()){
$mediaApi = Mage::getModel("catalog/product_attribute_media_api");
$items = $mediaApi->items($product->getId());
foreach($items as $item)
$mediaApi->remove($product->getId(), $item['file']);
}
这是最终让我头脑清醒的链接:http://www.magentocommerce.com/wiki/doc/webservices-api/api/catalog_product_attribute_media http://www.magentocommerce.com/wiki/doc/webservices-api/api/catalog_product_attribute_media
太糟糕了,它不像 $product->getImages() 那么简单,是吗?
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)