让所有商店图像成为 Magento 中的基本图像、小图像和缩略图?

发布于 2024-10-06 02:54:02 字数 686 浏览 3 评论 0原文

我有一家 Magento 商店,约有 3,000 种产品。几乎所有这些产品都附有一张图片。

由于某种原因,即使我将小图像和缩略图设置为与导入 CSV 文件中的基本图像相同,但每个产品仅设置了基本图像。这意味着当您搜索产品时,您会得到一个占位符 - 但一旦您进入产品页面,您就会得到正确的图像。通过进入产品管理页面并选择小图像和缩略图框可以轻松解决此问题。

问题是,对于 3,000 张图像,手动完成这将需要相当长的时间。我发现一个 SQL 命令应该使所有基本图像、小图像和缩略图映射到每个产品的第一个图像。由于每种产品我只有一张图片,这应该是完美的。然而,它没有做任何事情。它说 0 行已更改。

UPDATE catalog_product_entity_media_gallery AS mg,
catalog_product_entity_media_gallery_value AS mgv,
catalog_product_entity_varchar AS ev
SET ev.value = mg.value
WHERE  mg.value_id = mgv.value_id
AND mg.entity_id = ev.entity_id
AND ev.attribute_id IN (70, 71, 72)
AND mgv.position = 1

有谁知道为什么这不起作用?

谢谢,

丹尼

I have a Magento store that has around 3,000 products. Almost all of these products have a single image attached to it.

For some reason, even though I set the small image and thumbnail image as the same as the base image in the import CSV file, only the base image is set for each product. This means that when you search for a product you get a placeholder - but once you go into the product page you get the correct image. This can be easily remedied by going into the product admin page and selecting the boxes for small image and thumbnail.

The problem is, with 3,000 images this would take quite a long time to do manually. I have found a SQL command that should make all base, small and thumbnail images map the the first image for each product. As I only have one image for each product this should be perfect. However, it doesn't do anything. It says 0 rows changed.

UPDATE catalog_product_entity_media_gallery AS mg,
catalog_product_entity_media_gallery_value AS mgv,
catalog_product_entity_varchar AS ev
SET ev.value = mg.value
WHERE  mg.value_id = mgv.value_id
AND mg.entity_id = ev.entity_id
AND ev.attribute_id IN (70, 71, 72)
AND mgv.position = 1

Does anyone know why this isn't working?

Thanks,

Danny

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

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

发布评论

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

评论(6

镜花水月 2024-10-13 02:54:02

就像对任何想要尝试这个脚本的人(比如我自己!)的警告。我不假思索地运行了这个,它改变了所有的产品名称!

  1. 进入属性面板,找到图像/小图像/缩略图属性。
  2. 记下 id(在本例中我的是 85,86 和 87)
  3. 更改查询以反映这些 id。

所以我的查询如下所示:

UPDATE catalog_product_entity_media_gallery AS mg,
       catalog_product_entity_media_gallery_value AS mgv,
       catalog_product_entity_varchar AS ev
SET ev.value = mg.value
WHERE  mg.value_id = mgv.value_id
AND mg.entity_id = ev.entity_id
AND ev.attribute_id IN (85,86,87)
AND mgv.position = 1;

Just as a warning to anyone (like myself!) who wants to try out this script. I ran this without thinking and it changed all the product names!

  1. Go into your attributes panel, find the image/small image/thumbnail attributes.
  2. Note down the ids (mine in this case were 85,86 and 87)
  3. Change the query to reflect those id's.

So my query looks like:

UPDATE catalog_product_entity_media_gallery AS mg,
       catalog_product_entity_media_gallery_value AS mgv,
       catalog_product_entity_varchar AS ev
SET ev.value = mg.value
WHERE  mg.value_id = mgv.value_id
AND mg.entity_id = ev.entity_id
AND ev.attribute_id IN (85,86,87)
AND mgv.position = 1;
浅紫色的梦幻 2024-10-13 02:54:02

对数据库进行类似的更改后,即使成功,您也需要在缓存管理中重建图像缓存。

您也许可以使用这样的脚本来完成此操作,而不必担心缓存或索引。

<?php

require 'app/Mage.php';
Mage::app();

$products = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*');
foreach ($products as $product) {
    if (!$product->hasImage()) continue;
    if (!$product->hasSmallImage()) $product->setSmallImage($product->getImage());
    if (!$product->hasThumbnail()) $product->setThumbnail($product->getImage());
    $product->save();
}

?>Done!

将其保存在 Magento 目录中,并通过在浏览器地址栏中输入 URL 来访问它。我还没有测试过这个脚本。

After making a change like that to the database, even if successful, you would need to rebuild the images cache in Cache Management.

You might be able to do it with a script like this and not worry about caching or indexing.

<?php

require 'app/Mage.php';
Mage::app();

$products = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*');
foreach ($products as $product) {
    if (!$product->hasImage()) continue;
    if (!$product->hasSmallImage()) $product->setSmallImage($product->getImage());
    if (!$product->hasThumbnail()) $product->setThumbnail($product->getImage());
    $product->save();
}

?>Done!

Save this in your Magento directory and access it by typing the URL into your browser's address bar. I haven't tested this script yet.

流星番茄 2024-10-13 02:54:02

我知道这是一篇旧帖子,但是如果有人遇到同样的问题,那么问题出在 ev.attribute_id 上。下面更新了代码:

UPDATE 
    catalog_product_entity_media_gallery AS mg,
    catalog_product_entity_media_gallery_value AS mgv,
    catalog_product_entity_varchar AS ev
SET 
    ev.value = mg.value
WHERE  
    mg.value_id = mgv.value_id
      AND mg.entity_id = ev.entity_id
      AND ev.attribute_id IN (74, 75, 76)
      AND mgv.position = 1

谢谢。

i know this is an old post, however in case anyone has the same issue then the problem was with the ev.attribute_id. Updated code below:

UPDATE 
    catalog_product_entity_media_gallery AS mg,
    catalog_product_entity_media_gallery_value AS mgv,
    catalog_product_entity_varchar AS ev
SET 
    ev.value = mg.value
WHERE  
    mg.value_id = mgv.value_id
      AND mg.entity_id = ev.entity_id
      AND ev.attribute_id IN (74, 75, 76)
      AND mgv.position = 1

Thanks.

櫻之舞 2024-10-13 02:54:02

我在 magento 1.7.0.2 上使用stereo_world的方法,效果很好。 (我不能赞成他的答案,因为我是 stackoverflow 的新手)

我不知道他在属性面板中的哪里看到属性 id,因为我根本没有在那里看到数字 id。
我通过打开 phpMyAdmin 并查看 eav_attribute 表找到了 ids (85,86,87)。

正如 Clockworkgeek 指出的那样 - 重新索引/缓存刷新是必要的。

I used stereo_world's method on magento 1.7.0.2 and it worked great. (I can't upvote his answer because I'm new to stackoverflow)

I don't know where he is seeing the attribute id in the attribute panel, because I don't see a numerical id there at all.
I found the ids (85,86,87) by opening up phpMyAdmin and looking in eav_attribute table.

As clockworkgeek pointed out - reindex/cache flush are necessary.

泪是无色的血 2024-10-13 02:54:02

@user2321249 要在CE 1.9.1中查找属性id,请转到属性信息页面并查看URL。例如,从管理后端,选择目录 -> 管理属性。找到缩略图属性并选择它。在我的系统中,URL 是:

www.example.com/magento/index.php/admin/catalog_product_attribute/edit/attribute_id/87/key/f759b57c21a7c75f33095a243f44b2a5/

您可以轻松看出我系统中的缩略图 attribute_id 是 87。对基本镜像和小镜像。

@user2321249 To find the attribute id in CE 1.9.1, go to the attribute information page and look at the URL. For example, from the Admin backend, select Catalog->Manage Attributes. Find the thumbnail attribute and select it. With my system the URL is:

www.example.com/magento/index.php/admin/catalog_product_attribute/edit/attribute_id/87/key/f759b57c21a7c75f33095a243f44b2a5/

You can easily tell the thumbnail attribute_id in my system is 87. Do the same for the Base Image and Small Image.

鹿! 2024-10-13 02:54:02

我使用 Magento 1.9.2.2 版本的以下技巧让它工作:

INSERT INTO catalog_product_entity_varchar
      (entity_type_id, attribute_id, store_id, entity_id, value)
SELECT
      entity_type_id, 75, store_id, entity_id, value
FROM
      catalog_product_entity_varchar
WHERE 
      attribute_id = 74

然后用 76 替换值 75 并再次导入查询。
请务必将属性 id 值替换为您自己的值

I got it working using the following trick for Magento 1.9.2.2 version:

INSERT INTO catalog_product_entity_varchar
      (entity_type_id, attribute_id, store_id, entity_id, value)
SELECT
      entity_type_id, 75, store_id, entity_id, value
FROM
      catalog_product_entity_varchar
WHERE 
      attribute_id = 74

Then replace value 75 with 76 and import the query again.
Be sure to replace the attribute id values to your own

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