Jump to content

image upload


Recommended Posts

Hi, I have some experience php and I have a good amount with MySQL. I have imported all of the data in the shop, its a little over 3000 items. Can someone tell me what functions are used in the code to do the image manipulation and upload? I looked at it, and I'm not really sure how the images get resized and uploaded. I'd like to be able to upload all of the images and update the db. I can get the names of the images from the database as they are part of the manufacturer's part number and I have shell access. Any help would be appreciated.

Thanks,

Rob

Link to comment
Share on other sites

I created a text file with the items seperated by @'s. Then I created the categories that I was going to use, and added the category id's into a new column in the file (the category id's have to be seperated by commas.) So a line out of my import file would be something like

00001@3D Dragon Cue@A great cue stick for any level of [email protected]@200.00@4,6,9

the fields for this are as follows:
wholesaler id
name
description
wholesale price
retial price
categories (their id's)

I had to break the file into smaller files consisting of 300 records each, and I imported them under tools | import. After the import I choose the columns. Since I didn't have a wholesale price column I just choose another column to put the data in. One note, you have to escape single and double quotes, registerd and copyright symbols and angle's <>. I used the html equivilents (I replaced all of the "" with "). Hope that helps.

Thanks,

Rob

http://www.cheapcharliesbilliards.com

Link to comment
Share on other sites

I figured out how to upload the images at once, but I need to say that this isn't a task for someone who isn't a programmer. Please read all of the steps before starting to make sure you can complete this.

1) Backup the database -- don't continue, if you do not have a means to do this.

2) insert an image record into the ps_image table for all products that do not have images, I am only concerned about english, which is why I have id_lang = 1. To do this run this against the database:
insert into ps_image (id_product, position, cover)
SELECT id_product, 1 as position, 1 as cover
FROM ps_product_lang
WHERE id_product NOT IN (
SELECT id_product
FROM ps_image
)
AND id_lang =1

3) insert a description in the correct language in the ps_image_lang table, once again, I only use english on my site, Here's the query:
insert into ps_image_lang (id_image, id_lang, legend)
SELECT ps_image.id_image, 1 as id_lang, SUBSTRING(ps_product_lang.name,1, 63) as legend
FROM ps_product_lang
JOIN ps_image on ps_image.id_product = ps_product_lang.id_product
WHERE ps_image.id_image NOT
IN (
SELECT id_image
FROM ps_image_lang
)
AND id_lang =1

4) At this point the image records have been created and you need to copy all of the images to the p directory under the img directory of the shop root directory. So, if you installed prestashop under /usr/local/apache2/presta, the directory would be /usr/local/apache2/presta/img/p/. They also have to be named id_product-id_image.jpg. I'm not sure if they have to jpg's or not, mine were so and it worked. My wholesalers name the images their part number, which I have as the supplier reference number in prestashop. To get all the id_product, id_image, and supplier_reference data I ran:
select ps_image.id_product, ps_image.id_image, ps_product.supplier_reference
from ps_image
join ps_product on ps_product.id_product = ps_image.id_product
and stored the results in a semi-colon delimited test file named images.txt
Then I copied all of the images, renaming them to the correct name for presta. I did this with a python script, which I modified to make it clearer here:

import sys
import os, os.path
import shutil

o = open('images.txt')
r = o.readlines()
o.close()

current_image_dir = '/usr/local/images/'
presta_image_dir = '/usr/local/apache2/presta/img/p/'
for x in r:
xs = x.split(';')
current_image = xs[2].strip() + '.jpg'
presta_image = xs[0].strip() + '-' + xs[1].strip() + '.jpg'
if os.path.exists(current_image_dir + current_image):
shutil.copyfile(current_image_dir + current_image, presta_image_dir + presta_image)

Once they were all copied over, I recreated all of the thumbnails for presta by going to admin | preferences | images and clicking on the recreate thumbnails buttons. This took a while for 3000 images. I don't remember the exact time, but it was in excess of thirty minutes, and during that time the webpage timed out, but the process continued to work. You need to watch the img/p directory and wait until the new thumbnails are no longer being created. On my machine a new thumbnail was created every second and I waited until a new thumbnail wasn't created in a minutes time.

So this worked for me, if you have any questions please feel free to ask.

Thanks,

Rob

  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...

Images won't upload using CSV import if you don't specify product ID.
Just add a diffrent numeric ID to each line of the CSV file and images will be added. If you don't add this ID, pictures will be uploaded and created anyway, but you will see them only by looking into the ftp folder.
Also make sure that you have set right folder permissions (if not, you should see an error)

Dragos

Link to comment
Share on other sites

  • 2 months later...
I figured out how to upload the images at once, but I need to say that this isn't a task for someone who isn't a programmer. Please read all of the steps before starting to make sure you can complete this.

1) Backup the database -- don't continue, if you do not have a means to do this.

2) insert an image record into the ps_image table for all products that do not have images, I am only concerned about english, which is why I have id_lang = 1. To do this run this against the database:
insert into ps_image (id_product, position, cover)
SELECT id_product, 1 as position, 1 as cover
FROM ps_product_lang
WHERE id_product NOT IN (
SELECT id_product
FROM ps_image
)
AND id_lang =1

3) insert a description in the correct language in the ps_image_lang table, once again, I only use english on my site, Here's the query:
insert into ps_image_lang (id_image, id_lang, legend)
SELECT ps_image.id_image, 1 as id_lang, SUBSTRING(ps_product_lang.name,1, 63) as legend
FROM ps_product_lang
JOIN ps_image on ps_image.id_product = ps_product_lang.id_product
WHERE ps_image.id_image NOT
IN (
SELECT id_image
FROM ps_image_lang
)
AND id_lang =1

4) At this point the image records have been created and you need to copy all of the images to the p directory under the img directory of the shop root directory. So, if you installed prestashop under /usr/local/apache2/presta, the directory would be /usr/local/apache2/presta/img/p/. They also have to be named id_product-id_image.jpg. I'm not sure if they have to jpg's or not, mine were so and it worked. My wholesalers name the images their part number, which I have as the supplier reference number in prestashop. To get all the id_product, id_image, and supplier_reference data I ran:
select ps_image.id_product, ps_image.id_image, ps_product.supplier_reference
from ps_image
join ps_product on ps_product.id_product = ps_image.id_product
and stored the results in a semi-colon delimited test file named images.txt
Then I copied all of the images, renaming them to the correct name for presta. I did this with a python script, which I modified to make it clearer here:

import sys
import os, os.path
import shutil

o = open('images.txt')
r = o.readlines()
o.close()

current_image_dir = '/usr/local/images/'
presta_image_dir = '/usr/local/apache2/presta/img/p/'
for x in r:
xs = x.split(';')
current_image = xs[2].strip() + '.jpg'
presta_image = xs[0].strip() + '-' + xs[1].strip() + '.jpg'
if os.path.exists(current_image_dir + current_image):
shutil.copyfile(current_image_dir + current_image, presta_image_dir + presta_image)

Once they were all copied over, I recreated all of the thumbnails for presta by going to admin | preferences | images and clicking on the recreate thumbnails buttons. This took a while for 3000 images. I don't remember the exact time, but it was in excess of thirty minutes, and during that time the webpage timed out, but the process continued to work. You need to watch the img/p directory and wait until the new thumbnails are no longer being created. On my machine a new thumbnail was created every second and I waited until a new thumbnail wasn't created in a minutes time.

So this worked for me, if you have any questions please feel free to ask.

Thanks,

Rob




I am getting error in second step.

This was the error :

#1054 - Unknown column 'legend' in 'field list'


Please help me.Is there any other method ?
Link to comment
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
×
×
  • Create New...