Magento以编程方式删除产品图像 [英] Magento programmatically remove product images

查看:162
本文介绍了Magento以编程方式删除产品图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这必须是一个如此简单的编程任务,我绝对无法在网上找到任何有关它的信息。基本上,我正在尝试删除产品图像。我想删除产品媒体库中的所有图片。我可以在不花费一百万行代码的情况下完成这么简单的任务吗?

This must be a such a simple programming task that I absolutely cannot find any information about it on the net. Basically, I'm trying to DELETE product images. I want to delete all images from a product's media gallery. Can I do this without wading through a million lines of code for such a simple task?

请注意我已经尝试过这个:

Please note that I've already tried this:

$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']);
        }
    }
}

这绝对不行。我正在尝试在导入过程中删除图像,这样我就不会产生重复。任何帮助将不胜感激。

This absolutely does not work. I'm trying to delete images during an import so that I do not keep accruing duplicates. Any help would be greatly appreciated.

推荐答案

好的,这就是我最终解决问题的方法。

Okay, this is how I finally fixed my problem.

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

This is the link that finally set my head straight: http://www.magentocommerce.com/wiki/doc/webservices-api/api/catalog_product_attribute_media

太糟糕了,它不像$ product-> getImages()那么简单,是吗?

Too bad it's not as simple as $product->getImages(), eh?

这篇关于Magento以编程方式删除产品图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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