Post by townend » Mon Feb 21, 2011 1:27 am

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! :)

Web Design Barnsley by Townend


Newbie

Posts

Joined
Mon Feb 21, 2011 1:24 am
Location - Barnsley

Post by Chones » Mon Feb 21, 2011 1:47 am

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/

http://scarletandjones.com/
http://sharpdressedman.co.uk/
http://coffincompany.co.uk/
http://horsesculptures.co.uk/
If I've helped you out, why not buy me a beer? http://craigmurray.me.uk


User avatar
Active Member

Posts

Joined
Wed Mar 24, 2010 9:07 pm
Location - London

Post by townend » Mon Feb 21, 2011 6:58 pm

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. :)

Web Design Barnsley by Townend


Newbie

Posts

Joined
Mon Feb 21, 2011 1:24 am
Location - Barnsley

Post by symond93 » Wed Apr 06, 2011 3:38 pm

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.

Canadian Pharmacy


Newbie

Posts

Joined
Wed Apr 06, 2011 3:21 pm

Post by oliviargi » Sun Apr 17, 2011 2:06 pm

i love this forum and opencart

Newbie

Posts

Joined
Thu Mar 31, 2011 8:58 am
Who is online

Users browsing this forum: No registered users and 66 guests