Mass assigning images to products in Open Cart

Whilst working on an e-commerce project for a client we found that we had to add the same 3 images to over 200 products.

Now, compared the Zen Cart, the Open Cart admin dashboard is relatively easy on the eyes and intuitive, but it would still take a fair amount of time to manually assign the same 3 images to each product.

I wrote some SQL statements to take care of the job in less than 5 minutes (although I did spend a long time trying to do the job in one statement, but was unable).

So if you want to assign for example image1.jpg, image2.jpg and image3.jpg to all of your products in Open Cart as addition images here’s what you have to do.

1. Upload the pictures to your server

2. Open PHPmyadmin (via cPanel)

3. Open your MySQL table and select the SQL tab at the top of the screen

4. Run the following commands:

a) Copy all the product ids to the product_image table.

INSERT INTO product_image (product_id)
SELECT product_id FROM product

b) Now replace the null image value with the image and sort code of your choice:

UPDATE product_image
SET image='data/image1.jpg', sort_order=0

c) Now we need to add all the product IDs to the product image table again

INSERT INTO product_image (product_id)
SELECT product_id FROM product

d) Now use the same code from step b, but replace the values e.g.

UPDATE product_image
SET image='data/image2.jpg', sort_order=1

e) Repeat steps c and d until you’re done.

I’m sure this isn’t the most elegant solution, so if you have a better method please do leave a comment below!

Sign up for our regular newsletter with tips on Growing your online business, WordPress, content marketing and VoIP telephony

, , , , ,

Comments are closed.