Magento - 设置“排除”的 SQL 命令在产品图片上

发布于 2024-10-19 14:48:14 字数 863 浏览 1 评论 0原文

我想知道是否有一些我可以运行的 SQL 命令将任何只有 1 个图像的产品设置为从图像库中“排除”该图像。添加以下内容会将所有排除设置为 1(或勾选“排除”图像框,换句话说):

UPDATE catalog_product_entity_media_gallery_value
SET disabled = 1

但我只需要对具有 1 个图像的产品执行此操作,并将任何具有超过 1 个图像的产品“未排除” (或“禁用= 0”)。

Magento 版本是 1.4.2.0。

欢呼

更新:我发现以下内容正在做类似的事情,尽管我只想排除只有 1 张图像的产品:

-- 将所有图像设置为启用(取消选择“排除”)

update catalog_product_entity_media_gallery_value set disabled = 0;

-- 将所有主图像设置为禁用(选择“排除”),这样它们就不会出现在“更多视图”中

update catalog_product_entity_media_gallery_value set disabled=1 where value_id in (select value_id from catalog_product_entity_media_gallery where value in (select value
from catalog_product_entity_varchar where attribute_id=(select attribute_id from eav_attribute where attribute_code=’image’ and entity_type_id=4)))

I'm wondering if there's some SQL command I can run that will set any product with only 1 image to "exclude" that image from the image gallery. Adding the following will set all excludes to 1 (or tick the "exclude" image box in other words):

UPDATE catalog_product_entity_media_gallery_value
SET disabled = 1

But I need to only do that for products with 1 image, and leave any products with more than 1 image "un-excluded" (or "disabled = 0").

Magento version is 1.4.2.0.

Cheers

UPDATE: I found the following which is doing something similar, although I would want just products with only 1 image to be excluded:

-- Set all images as enabled ("exclude" deselected)

update catalog_product_entity_media_gallery_value set disabled = 0;

-- Set all the main images as disabled ("exclude" selected) so that they do not show up in “More Views”

update catalog_product_entity_media_gallery_value set disabled=1 where value_id in (select value_id from catalog_product_entity_media_gallery where value in (select value
from catalog_product_entity_varchar where attribute_id=(select attribute_id from eav_attribute where attribute_code=’image’ and entity_type_id=4)))

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

箜明 2024-10-26 14:48:14

好的,这似乎可以解决问题:

UPDATE catalog_product_entity_media_gallery_value SET disabled = 0; 
UPDATE catalog_product_entity_media_gallery_value AS mgv,
(SELECT entity_id, COUNT(*) as image_count, MAX(value_id) AS value_id
FROM catalog_product_entity_media_gallery AS mg
GROUP BY entity_id
HAVING image_count = 1) AS mg
SET mgv.disabled = 1
WHERE mgv.value_id = mg.value_id 

OK, this seems to do the trick:

UPDATE catalog_product_entity_media_gallery_value SET disabled = 0; 
UPDATE catalog_product_entity_media_gallery_value AS mgv,
(SELECT entity_id, COUNT(*) as image_count, MAX(value_id) AS value_id
FROM catalog_product_entity_media_gallery AS mg
GROUP BY entity_id
HAVING image_count = 1) AS mg
SET mgv.disabled = 1
WHERE mgv.value_id = mg.value_id 
池予 2024-10-26 14:48:14

我建议您不要将其作为 SQL 运行,而是更改主题的 template/catalog/product/view/media.phtml 文件,以便仅在存在多个图像时才显示图库(我假设这就是您想要实现的目标??)。将下面的行从 0 更改为 1

<?php if (count($this->getGalleryImages()) > 0): ?>

这样做的好处是,您无需在每次添加新产品时重新运行 SQL 。

HTH,
京东

Rather than running this as SQL, I would recommend that you change your theme's template/catalog/product/view/media.phtml file so that it only shows the gallery if there is more than one image (I assume that's what you are trying to achieve??). Change the line below from 0 to 1

<?php if (count($this->getGalleryImages()) > 0): ?>

The advantage in doing it this way is that you won't need to re-run the SQL every time that you add a new product.

HTH,
JD

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文