rss
twitter
    Find out what I'm doing, Follow Me :)

Monday, February 15, 2010

Pin It

Widgets

2 SQL Tricks to Auto-Organize your Images In Magento

If you imported a lot of data into your Magento installation, and your images got disorganized in the process, here are a couple SQL scripts that may help you!

Trick 1 - 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!

Careful if you run this!  Getting your image order set back to how it was won’t be so easy!

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;

Trick 2 - 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/

2 comments: