Page 1 of 1

Change Product Image Directory Name=no images

Posted: Mon Jan 18, 2016 3:01 am
by varnco
I'm wanting to change the name of directory where I have my images.

the current folder name is "product images" (yes, with a space) so the image link looks like this:
http://www.example.com/image/cache/data/product images/taco.jpg

I want to change it to "product-image" (with no space)
http://www.example.com/image/cache/data/product-images/taco.jpg

When I renamed the folder to include the dash, using the built-in tool to upload or select images, the name of the older changes, but the links to my product images do not.

Any thoughts on how I can fix it without having to re-establish all my product image links so they include the "-" now?

I tried clearing out the cache under system/cache but that didn't work.

Thank you.

Re: Change Product Image Directory Name=no images

Posted: Mon Jan 18, 2016 3:08 am
by victorj
renaming to product images would render the url to looklike this:

product%20images due to the way your server and browser do handle a spave in a url.

you can try it with renaming the seo url of one off your products, replace your hypens with a space and check the url to that product.

Re: Change Product Image Directory Name=no images

Posted: Mon Jan 18, 2016 3:17 am
by varnco
I was hoping that there's a fast way I can change the folder name (I never should have made a folder name with a space), so it doesn't have a space any longer, but without me having to "reset" the URL's for the product images.

I assume this is handled somehow in the database

Re: Change Product Image Directory Name=no images

Posted: Mon Jan 18, 2016 3:40 am
by victorj
No that would be far to easy >:D

Image folders are defined bij absulute path in config.php files and the actual file to the images on your server.

at this moment the path to the images for your products is set in the database, so opencart knows whre to find them.

if you would relocate the image path, youre product would end up without any images, as path in databse is different to actual path on server.

Re: Change Product Image Directory Name=no images

Posted: Mon Jan 18, 2016 4:02 am
by varnco
So, my option is to change the folder name, and then go and reselect each product image, so I updates the URL pointing to the product image and corresponding thumbnails?

Thanks.

Re: Change Product Image Directory Name=no images

Posted: Mon Jan 18, 2016 4:06 am
by victorj
indeed change the folder name.

edit config.php in root and admin folder so it will point to your renamed image folder.

iether edit each product and reasign the corresponding picture to it, or much faster, edit your database and alter all image path in one go

Re: Change Product Image Directory Name=no images

Posted: Mon Jan 18, 2016 9:41 am
by varnco
Here's what I did:

Created new folder
Went into db and changed the path
Only the thumbnail is using the new path. The main image is using the old path

Are these image paths in d different areas of the database?

Re: Change Product Image Directory Name=no images

Posted: Tue Jan 19, 2016 12:51 am
by varnco
The thumbnail updates but the product images do not.. any thoughts on why changing the path in the database itself to the image does not fix it?

Does "assigning" it withing opencart do something different? If it did, wouldn't it be listed in the database?

Thanks.

Re: Change Product Image Directory Name=no images

Posted: Tue Jan 19, 2016 3:56 am
by victorj
did you adapt the path to image in both your config files as well ?

Re: Change Product Image Directory Name=no images

Posted: Tue Jan 19, 2016 4:47 am
by varnco
Thanks for the help!

More information:

I found that the image URL's are located in 2 different tables in the database.
gtk_product
gtk_product_image

A question, I'm sure there's a way I can replace
data/product images/imagenamesthatvary.jpg

So it reads (with the dash):
data/product-images/imagenamesthatvary.jpg

Using some sort of command, like this in PHPAdmin?:

Code: Select all

update gtk_product set image = replace(image, 'data/product images/', 'data/product-images/');
I stole the code from a post on updating wordpress, and figure it's probably similar or the same as updating a database for opencart?

Thoughts?

Re: Change Product Image Directory Name=no images

Posted: Tue Jan 19, 2016 5:22 am
by victorj
indeed you found them.

its possible to update a database field with a sql comand as described, it will update all field at once, saving loads off time.

Re: Change Product Image Directory Name=no images

Posted: Tue Jan 19, 2016 5:54 am
by varnco
Well, I made a backup of the 2 tables from my database, and then pulled the trigger.

Worked well, and the image URL's have changed from "data/product images/" to "data/product-images/" using the above referenced coding

Just in case someone needs this in the future... I went to the tables

gtk_product
gtk_product images

And changed the variables in red to match the table, fields that needed to be updated and what needed to be found and replaced with:

update gtk_product set image = replace(image, 'data/product images/', 'data/product-images/');

Thanks victorj for the help!