English 中文(简体)
Magento 清除所有产品图像的Magento 管理工具
原标题:Magento Admin Tool to remove ALL product images
  • 时间:2012-05-24 22:12:39
  •  标签:
  • magento

Magento 是否有一个管理工具, 能从所有产品中移除所有图像? 我知道你可以逐个逐个产品删除所有图像, 但我想知道是否有一个管理工具, 能同时完成所有产品?

提前感谢。

问题回答

我不知道你为什么想这样做,但这里是直接从数据库这样做的方法。

  1. 备份后删除这2个表格:

    catalog_product_entity_media_gallery catalog_product_entity_media_gallery_value

  2. 然后删除 /media/catalog/product

  3. 清除所有缓存 。

我还没有测试过它,但是它应该能完成它的工作。如果它不工作,那么恢复那两张桌子。

此方法已被测试并有效。 您可能想要这样做的原因之一是您重新测试产品的数据流导入。 如果您在上传中指定图像时, Magento 只指定 < em> adds 图像 - 它不会替换或删除它们 。

最终结果是,一些剖面图的运行将积累一些多余的图像。

mysql> **truncate catalog_product_entity_media_gallery;**
mysql> **truncate catalog_product_entity_media_gallery_value;**

然后,从您的 Magento 媒体/ Catalog 文件夹的命令提示 :

media/catalog$ **rm -rf ./product/**

通过 DB 这样做是不明智的, 但如果你必须这样做:

ALTER TABLE `catalog_product_entity_media_gallery_value` 
 DROP FOREIGN KEY `FK_CAT_PRD_ENTT_MDA_GLR_VAL_STORE_ID_CORE_STORE_STORE_ID`,
 DROP FOREIGN KEY `FK_CAT_PRD_ENTT_MDA_GLR_VAL_VAL_ID_CAT_PRD_ENTT_MDA_GLR_VAL_ID`;

TRUNCATE `catalog_product_entity_media_gallery_value`;
TRUNCATE `catalog_product_entity_media_gallery`;

ALTER TABLE `catalog_product_entity_media_gallery_value` 
 ADD CONSTRAINT `FK_CAT_PRD_ENTT_MDA_GLR_VAL_STORE_ID_CORE_STORE_STORE_ID` FOREIGN KEY (`store_id`) REFERENCES `core_store` (`store_id`) ON DELETE CASCADE ON UPDATE CASCADE,
 ADD CONSTRAINT `FK_CAT_PRD_ENTT_MDA_GLR_VAL_VAL_ID_CAT_PRD_ENTT_MDA_GLR_VAL_ID` FOREIGN KEY (`value_id`) REFERENCES `catalog_product_entity_media_gallery` (`value_id`) ON DELETE CASCADE ON UPDATE CASCADE;

然后您可以用下列方式删除产品文件夹 :

cd media/catalog/product
rm -rf *

这就是我如何修补它:

    public function __construct(
        MagentoCatalogModelProduct $product,
        MagentoFrameworkAppResourceConnection $resource,
        MagentoCatalogApiProductRepositoryInterface $productRepository,
        MagentoCatalogModelProductGalleryProcessor $processor
    ) {
        $this->productRepository = $productRepository;
        $this->product = $product;
        $this->resource = $resource;
        $this->processor = $processor;
    }

    protected function removeImageGallery($product)
    {
        try {
            $gallery = $this->resource->getTableName( catalog_product_entity_media_gallery );
            $galleryValue = $this->resource->getTableName( catalog_product_entity_media_gallery_value );

            $sql = <<<EOT
DELETE FROM {$gallery}
WHERE value_id IN (SELECT value_id FROM {$galleryValue} WHERE entity_id = {$product->getId()})
EOT;

            $response = $this->resource->getConnection()->query($sql);

            echo  (  . $product->getTypeId() .  ):   . $product->getSku() . " - No. Images: " . $response->rowCount() .  "
";


//            // Or if you want to try the Magento way
//
//            $images = $product->getMediaGalleryImages();
//            foreach($images as $child){
//                echo  (  . $product->getTypeId() .  ):   . $product->getSku() .   -   . $child->getFile() . "
";
//                $this->processor->removeImage($product, $child->getFile());
//            }
//
//            $this->productRepository->save($product);

        } catch (Exception $e) {
            echo $e->getMessage() . "
";
        }
    }




相关问题
Magento addFieldToFilter allow NULLs

When using the Magento collection method addFieldToFilter is it possible to allow filtering by NULL values? I want to select all the products in a collection that have a custom attribute even if no ...

Get product link from Magento API

I am new to Magento and using their API. I need to be able to get the product url from the API call. I see that I can access the url_key and url_path, but unfortunately that s not necessarily what ...

magento extension installation

I want to install a Magento extension in WAMP, but not from the Magento connect system. How can I do this? I have the module (extension) code and I already installed the sample data in the Magento ...

Link to a specific step in onepage checkout

Is it possible to redirect the browser to nth step in the onepage checkout? If so, how would one go about doing it? I m working on a payment module and have a sort of "cancel" action that i would ...

How do I filter a collection by a YesNo type attribute?

I have a ‘featured’ attribute, which has a Yes/No select-list as the admin input. I presume that the values for Yes and No are 1 and 0, as they are for every other Yes/No list. However, if I try and ...

热门标签