Jump to content

[1.7][sql]How to set all first images as coverphoto


yairobe
 Share

Recommended Posts

hI! 1.7.6.9
I  try regeneration, no luck with that. Script will be  nice  :)  I try this  but no  luck:
 

UPDATE `ps_image` SET `cover` = NULL
UPDATE `ps_image` SET `cover` = 1 WHERE `position` = 1;

 

Share this post


Link to post
Share on other sites

Hi,

You had SQL well, you just didn't put a semicolon at the end of the first line.

UPDATE `ps_image` SET `cover` = NULL;
UPDATE `ps_image` SET `cover` = 1 WHERE `position` = 1;

 

Share this post


Link to post
Share on other sites

  • 11 months later...

This may not work in case `position` 1 is not set for images

in my case i have 4 images for a product which only have position  4,5,6 and 7

the best solution to quickly fix all missing cover value is to run

UPDATE IGNORE ps_image f
	set	f.cover  =	1  
where f.id_image = 
	(SELECT t1.id_image FROM ps_image t1
	 JOIN (
	  SELECT MIN(id_image) AS min_value, id_product
	  FROM ps_image 
	  GROUP BY id_product
	) AS t2 ON t1.id_product = t2.id_product AND t1.id_image = t2.min_value
	  where t1.id_product = f.id_product
	limit 1);

UPDATE IGNORE ps_image_shop f
	set	f.cover  =	1  
where f.id_image = 
	(SELECT t1.id_image FROM ps_image_shop t1
	 JOIN (
	  SELECT MIN(id_image) AS min_value, id_product
	  FROM ps_image_shop 
	  GROUP BY id_product
	) AS t2 ON t1.id_product = t2.id_product AND t1.id_image = t2.min_value
	  where t1.id_product = f.id_product
	limit 1);

 

in case you will set the cover image according to the image with lowest position number,  just change  MIN(id_image) with MIN(position) ,  but the query i provided will just set the cover image for the first uploaded image which ahve the lowest image id

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More