Convert secondary images to default
Posted: 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!
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!
