Product images programatically

Can anyone tell me with an example how to create a product image and create a path for a product image. I mean like how cscart creates a numbered sub folder under the profit images folder. I need to know the logic so I can duplicate it, or an example call to the function that does it.



Right now I am putting all images in /0 folders and uploading using fileput commands. If I knew how I would reuse the cscart function to create an image. Anyone have any examples to help me along my way.

I can't really help you with the logic, but there are a couple of options for you.



First off, you don't have to let the cart split up your images. In config.local.php, you have:


// Maximum number of files, stored in directory. You may change this parameter straight after a store was installed. And you must not change it when the store has been populated with products already.
define('MAX_FILES_IN_DIR', 1000);




Just change the 1000 to 1000000 or something. This will prevent all of those numbered folders.



I'm not sure what it is that you are trying to do, but you can also put all of your images in a folder and then tell CS-Cart what folder it is when you import in your products/images and it will automatically put the images into all the numbered folders.



As for the other logic, hopefully someone else will chime in.



Thanks,



Brandon

Brandon,



Thanks for your reply. Yes I was aware of the setting option I would just prefer to be able to make the numerical directories.



As for what I'm trying to do I'm importing products from our companies erp system. I wrote a massive script that imports automatically by reading our db and creates categories products filters and features. It's great I just want to use functions built into Csc where possible and if not at least have the same functional logic programmed into my importing script. This has been a four month project lol.

I am also highly interested in this subject. I am creating some alternative websites where certain categories of products are shown and where the customer may see product detailed information and all extracted from my CS_Cart Database. This way if a product description, name code, etc is updated on my main site all other sites are populated with this new information. I have the complete idea of how to do it but i am having problems figuring out how to pull the actual physical path of the product images…





Any help on how this path is generated in cs-cart or how to obtain it directly from the DB would be highly appreciated???

I have been reviewing the database and there is no relation, at least that i can see, between the folder names /0/ /1/ /2/ etc and the product image. without this information it is impossible to reconstruct the link.

got it…





cart_directory/images/objsect_type/image_id / MAX_FILES_IN_DIR/image_path



correct me i am wrong!!

Correction:



cart_directory/images/object_type/floor(image_id / MAX_FILES_IN_DIR)/image_path

So if it uses image I'd does that mean it's not consistent number for each type. Say I allow 100 per folder.



I mean I could have an image I'd of 800 but only have 30 variant images but since my id is 800 it would treat it as if I have 800 variant images to account for to decide what folder to put the image in, right?

Each variant image would have its own ID and it divide each by the MAX_FILES_IN_DIR value to find the container folder… At least this is what i understand from the image functions



$path .= floor($image_id / MAX_FILES_IN_DIR) . "/";

[quote name='alebargut' timestamp='1337560644' post='136872']Each variant image would have its own ID and it divide each by the MAX_FILES_IN_DIR value to find the container folder… At least this is what i understand from the image functions



$path .= floor($image_id / MAX_FILES_IN_DIR) . "/";
[/quote]



Ok… I understand that part but what I don't get is how does it know how many files are in the said directory? I don't see any function that checks that, do you?



And what does floor do? I never understood that.

[quote]Ok… I understand that part but what I don't get is how does it know how many files are in the said directory? I don't see any function that checks that, do you?[/quote]



It's in the database level.



Each product ID will have it's corresponding object_id in the images_links table. Will also have object_type and detailed_id fields. The detailed_id field in the images_link table will has its corresponding associated value “image_id” in the images table.



If you make this query:


SELECT * FROM cscart_images AS i LEFT JOIN cscart_images_links AS il ON i.image_id = il.detailed_id WHERE il.object_id = 250 AND il.type = 'M'




it will return all the data of the main image for that product_id = 250. If instead you make that query with the 'A' instead of 'M', you'll get all the alternative images saved for that product.



The way to know where that product image is saved is to devide its image_id by MAX_FILES_IN_DIR and round it down to the nearest integer value (That's what floor command does).





There is something i clearly do not understand yet, and it is that thumnails are saved in other folder extructure, named by their width and Heigh values.

I guess we can get that info from the database too. Not sure! But I won't need this since i am going to work just with the detailed image only.

[quote name='alebargut' timestamp='1337565570' post='136874']

It's in the database level.



Each product ID will have it's corresponding object_id in the images_links table. Will also have object_type and detailed_id fields. The detailed_id field in the images_link table will has its corresponding associated value “image_id” in the images table.



If you make this query:


SELECT * FROM cscart_images AS i LEFT JOIN cscart_images_links AS il ON i.image_id = il.detailed_id WHERE il.object_id = 250 AND il.type = 'M'




it will return all the data of the main image for that product_id = 250. If instead you make that query with the 'A' instead of 'M', you'll get all the alternative images saved for that product.



The way to know where that product image is saved is to devide its image_id by MAX_FILES_IN_DIR and round it down to the nearest integer value (That's what floor command does).



[/quote]



Yes but I don't see how that works if you have different types of images that are stored in different folders.

That would work fine if all you had to worry about was the detailed images but we have other image

types to be concerned with.



For example: Variant images are stored in images/variant_images, and feature variant in images/feature_variant

and category images in images/category.



But all image types share the same IMAGE_ID auto increment field in the cscart_images table.



Your Thoughts or anyone else have any thoughts on this?

Anyone from CS-Cart can assist with this answer?

[quote name='alebargut' timestamp='1337556932' post='136869']

Correction:



cart_directory/images/object_type/floor(image_id / MAX_FILES_IN_DIR)/image_path

[/quote]



Thank you very much for the answer. Thanks again.