将所有商店图像设为 Magento 中的基本图像、小图像和缩略图图像? [英] Make all store images the base, small and thumbnail images in Magento?

查看:27
本文介绍了将所有商店图像设为 Magento 中的基本图像、小图像和缩略图图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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.

问题是,对于 3,000 张图像,手动操作需要很长时间.我发现了一个 SQL 命令,应该将所有基本图像、小图像和缩略图图像映射到每个产品的第一个图像.因为我每个产品只有一张图片,所以这应该是完美的.但是,它没有任何作用.它说 0 行已更改.

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?

谢谢,

丹尼

推荐答案

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

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!

将其保存在您的 Magento 目录中,然后通过在浏览器的地址栏中键入 URL 来访问它.我还没有测试过这个脚本.

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.

这篇关于将所有商店图像设为 Magento 中的基本图像、小图像和缩略图图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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