Jump to content

Prevent CubeCart from Recreating Thumbnail upon Edit Product


Guest lauriex

Recommended Posts

Guest lauriex

Is there a way to prevent CubeCart from recreating a product thumbnail every time a product is updated in the Admin Edit Product? I have generated my own thumbs that I do not want to be overwritten by CubeCart - they are a different proportion and scale than the product photos used in the product pages.

Link to comment
Share on other sites

I don't think CC will re-create a thumb if the thumb exists. Of course, the thumb must have the exact same name and image type as the main product, with the "thumb_" prefix. If, when you edit the prod, you are changinng the image, then of course it will create a new thumbnail.

This is not to say that you cannot have a totally different thumbnail image, though, than main prod image. Here's how.

1. Add or edit your prod and be sure you add the image you want to use for prod.

2. Create your differing thumb on your PC, and give it the same name as prod image, addint the thumb_ prefix.

example - for a prod image of widget.jpg, create a thumb_widget.jpg

3. Once you have all your differing thumbnails prepared, upload them via ftp to images/uploads/thumbs overwriting the onnes CC reated.

Link to comment
Share on other sites

Guest lauriex

I don't think CC will re-create a thumb if the thumb exists. Of course, the thumb must have the exact same name and image type as the main product, with the "thumb_" prefix. If, when you edit the prod, you are changinng the image, then of course it will create a new thumbnail.

This is not to say that you cannot have a totally different thumbnail image, though, than main prod image. Here's how.

1. Add or edit your prod and be sure you add the image you want to use for prod.

2. Create your differing thumb on your PC, and give it the same name as prod image, addint the thumb_ prefix.

example - for a prod image of widget.jpg, create a thumb_widget.jpg

3. Once you have all your differing thumbnails prepared, upload them via ftp to images/uploads/thumbs overwriting the onnes CC reated.

Thanks! I have done steps 1- 3, and when I edit a product, even if no actual change is made and I click on Admin "edit product", CC auto-recreates and replaces (changes it back) the thumb I have created locally and uploaded. I can tell that it has been replaced by different width & height, throwing off my display, in addition to new thumb file creation date. You can see the result. Then I have to go in and reupload/replace my local copy of the thumb I want each time an edit is made.

I have attached a screenshot where prod in row 2 column 2 has been replaced by CC.

Link to comment
Share on other sites

Laurie;

Can you not protect the thumbnail folder (CHMOD it) once you upload it with your custom images? That way, when CC tries to update with a new thumbnail, it cant.

Also, did you manage to get the image slined up? I wasn't able to get an answer to you over the weekend.

Link to comment
Share on other sites

Guest lauriex

Laurie;

Can you not protect the thumbnail folder (CHMOD it) once you upload it with your custom images? That way, when CC tries to update with a new thumbnail, it cant.

Also, did you manage to get the image slined up? I wasn't able to get an answer to you over the weekend.

Hmm change folder permissions, didn't think of that. I remember changing specific folder/file permissions to writable (777) during install but what is the number I should change the thumbs folder back to? I will have to test whether this causes an error in CubeCart when it can't write to it's destination.

As you have seen from my other post, my sales page alignment is still an issue.

Thanks!

Link to comment
Share on other sites

  • 3 weeks later...

Well, I've never fooled with this, but it looks like you need to change admin/products/index.php

Around line 487, I found:

	// if image is a JPG check thumbnail doesn't exist and if not make one



	$imageFormat = strtoupper(ereg_replace(".*\.(.*)$","\\1",$_POST['imageName']));



	if($imageFormat == "JPG" || $imageFormat == "JPEG" || $imageFormat == "PNG" || ($imageFormat == "GIF" && $config['gdGifSupport']==1)){



		



		if(file_exists($GLOBALS['rootDir']."/images/uploads/thumbs/thumb_".$_POST['imageName'])){



			@chmod($GLOBALS['rootDir']."/images/uploads/thumbs/thumb_".$_POST['imageName'], 0775);



			unlink($GLOBALS['rootDir']."/images/uploads/thumbs/thumb_".$_POST['imageName']);



		}



		



		$thumb=new thumbnail($GLOBALS['rootDir']."/images/uploads/".$_POST['imageName']);



		$thumb->size_auto($config['gdthumbSize']);



		$thumb->jpeg_quality($config['gdquality']);



		$thumb->save($GLOBALS['rootDir']."/images/uploads/thumbs/thumb_".$_POST['imageName']);



	}

You might try commenting out part of this - the middle section

if(file_exists($GLOBALS['rootDir']."/images/uploads/thumbs/thumb_".$_POST['imageName'])){

@chmod($GLOBALS['rootDir']."/images/uploads/thumbs/thumb_".$_POST['imageName'], 0775);

unlink($GLOBALS['rootDir']."/images/uploads/thumbs/thumb_".$_POST['imageName']);

would be my first best guess. You might need to readjust the { } to avoid syntax errors, but this would be my best suggestion. Perhaps a better coder can give you more details.

Link to comment
Share on other sites

Guest oldboy

This code is on line 184 in my index.php

Im not sure how to comment out the code u suggest, see code below what i did.

  // if image is a JPG check thumbnail doesn't exist and if not make one

		$imageFormat = strtoupper(ereg_replace(".*\.(.*)$","\\1",$_POST['imageName']));

		if($imageFormat == "JPG" || $imageFormat == "JPEG" || $imageFormat == "PNG" || ($imageFormat == "GIF" && $config['gdGifSupport']==1)) 



comment start -- > //[/color] {



//				if(file_exists($GLOBALS['rootDir']."/images/uploads/thumbs/thumb_".$_POST['imageName'])){

//						@chmod($GLOBALS['rootDir']."/images/uploads/thumbs/thumb_".$_POST['imageName'], 0775);

//						unlink($GLOBALS['rootDir']."/images/uploads/thumbs/thumb_".$_POST['imageName']);

comment end -- > //[/color]				 }



				$thumb=new thumbnail($GLOBALS['rootDir']."/images/uploads/".$_POST['imageName']);

				$thumb->size_auto($config['gdthumbSize']);

				$thumb->jpeg_quality($config['gdquality']);

				$thumb->save($GLOBALS['rootDir']."/images/uploads/thumbs/thumb_".$_POST['imageName']);

		}

This gave me a syntax error:

Parse error: syntax error, unexpected '}' in /home/teclaste/public_html/dap/admin/products/index.php on line 269

Link to comment
Share on other sites

Guest Brivtech

That's because there's a logic condition that you commented out, but the parser came across a terminator that shouldn't be there (Because you didn't comment the } at the end!).

In php, when you have a logic arguement, the resulting condition allows for a block of code to be executed. This is wapped between { and }, before the condition finishes, or changes. Always count them to make sure the opening and closing curly brackets always match up.

An easier way to comment out a whole section is to use /* and */ - It'll even cover the existing comment lines.

In the code Mysty gave, use

/*

	// if image is a JPG check thumbnail doesn't exist and if not make one



	$imageFormat = strtoupper(ereg_replace(".*\.(.*)$","\\1",$_POST['imageName']));



	if($imageFormat == "JPG" || $imageFormat == "JPEG" || $imageFormat == "PNG" || ($imageFormat == "GIF" && $config['gdGifSupport']==1)){



		



		if(file_exists($GLOBALS['rootDir']."/images/uploads/thumbs/thumb_".$_POST['imageName'])){



			@chmod($GLOBALS['rootDir']."/images/uploads/thumbs/thumb_".$_POST['imageName'], 0775);



			unlink($GLOBALS['rootDir']."/images/uploads/thumbs/thumb_".$_POST['imageName']);



		}



		



		$thumb=new thumbnail($GLOBALS['rootDir']."/images/uploads/".$_POST['imageName']);



		$thumb->size_auto($config['gdthumbSize']);



		$thumb->jpeg_quality($config['gdquality']);



		$thumb->save($GLOBALS['rootDir']."/images/uploads/thumbs/thumb_".$_POST['imageName']);



	}

*/

You could of course include a form option in admin/products/index.php, creating a variable say $doThumbRegen (set at default of 0 - NO), and then add in a condition at the beginning of the above block of code to see if it's set to 1 (yes), where it will execute the code, otherwise, skip over it.

In practice, that there would be a radio button that says "Regenerate thumbnail on update", always set to NO, and if you want to generate it on any occasion (like when creating a product), you will need to manually set it to yes.

Link to comment
Share on other sites

Guest oldboy

Mysty and Brivtech you are my heroes....

This tweak saves me alot time. Before i had to upload the thumbs after any change on a product.

Brivtech, no more syntax error when commenting the whole block of code...

also /* and */ workes much better.

Maybe time for a sticky here ..

Link to comment
Share on other sites

Guest lauriex

MYSTY and BRIVTECH,

I can't thank you both enough for your contributions to this fix - it works beautifully and will save me tons of future headaches !!!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...