dannymcc

a genius in training.

1 note

Handy database tricks for Magento

Simple bulk image settings with Magento

From time to time we need to bulk import products and images into Magento. As you can imaging when you import more than around 2,000 products, each with at least one image, things get a little bit awkward to change. Not just because importing and exporting takes more and more time but because if you wan’t to make changes to the images for each product it would take an age.

We came across the following SQL commands whilst tidying up a catalog with around 4,000 products. They helped us cut down time editing products one by one hugely.

Auto-set default base, thumb, small image to first image.
If you have multiple images per product from your import, Magento might have set the LAST one as the default base, small, and thumb image for all of your products!  This can be an issue if you want the FIRST image to be the default!

This script updates your images and makes the FIRST image (image order 1) your default BASE, SMALL, and THUMB image for ALL products in your database.  Can save you lots of hours if you were planning on doing this task manually!

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;

Auto-enable thumbs for multi-image and auto-disable for single-image products

Ok, so you imported 5,000 new products into your Magento store, and some have 1 product image, and the rest have 2+ images.  If you’re like me, you want the multi-image products to have thumbnails enabled on the product page, and if you only have 1 image, you want no thumbnails (kind of silly to switch between an image and itself LOL).

So this script runs 2 updates.  The first enables all images for thumbnails, then the second disables any thumbnails for images associated to products having only a total count of 1image.

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

Source: http://www.magentocommerce.com/boards/viewthread/59440/

  1. dannymcc posted this