Page 1 of 1

Convert secondary images to default

Posted: Mon Feb 21, 2011 1:27 am
by townend
Hi, I'm working on an Opencart shop for a client. The problem is, all of the product images have been added under the image tab instead of the data tab image field. This means there is no default image set for each product. There's way too many products to set this manually, so I'm trying to figure out a MySQL query that will take the image property and assign it to the product.

I've figured out what exactly needs to happen, I just need help writing the SQL query to achieve it. The database structure is as follows:

The table 'opproduct' holds product info, with the primary key 'product_id'. The default image URL for each product is held in the field 'image'.

The table 'opproduct_image' holds product image URLs in the field 'image' and the assigned product for each image in 'product_id'. This allows any one product to have multiple images. In order to have a default image, a product must have an image assigned in the table 'opproduct_image' and also the URL set in the table 'opproduct'.

So, the MySQL query needs to:
Find records that match the 'product_id' field in both the tables 'opproduct' and 'opproduct_image'
Now copy the value of the field 'image' in the table 'opproduct_image' to the field 'image' in the table 'opproduct'

I'm using Version 1.4.9.3. Thanks! :)

Re: Convert secondary images to default

Posted: Mon Feb 21, 2011 1:47 am
by Chones
I use the Export/Import tool for doing that sort of thing.
http://www.opencart.com/index.php?route ... sion_id=17

You can basically export the main data from your database, change it, then import it again. If you have a list of the images, you can just copy and paste into the image URL field - just make sure you have them all start with data/

Re: Convert secondary images to default

Posted: Mon Feb 21, 2011 6:58 pm
by townend
This was the solution:

Code: Select all

update `product` set image=(select image from product_image where product_image.image != '' AND product.product_id=product_image.product_id order by product_image.image ASC limit 0,1) WHERE `image` = ''
Thought it might help someone else. :)

Re: Convert secondary images to default

Posted: Wed Apr 06, 2011 3:38 pm
by symond93
Go to your start menu and open the control panel.Look for an icon called Folder Options and open it. Select the third tab, labeled File Types.Scroll down to JPG, the most common photo file type (you may want to change GIF as well), and highlight,Click on Change, and you will be presented with a list of options to choose from. Repeat steps 4 and 5 with extensions JPEG and JPE, two alternate designations for the same type of photo.Select OK to close the window.

Re: Convert secondary images to default

Posted: Sun Apr 17, 2011 2:06 pm
by oliviargi
i love this forum and opencart