Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

Image Path MOD for 4.1.x
 
Reply
   X-Cart forums > X-Cart 4 > Changing and adding new features
 
Thread Tools Search this Thread
  #1  
Old 04-26-2008, 12:30 PM
 
robertswww robertswww is offline
 

X-Adept
  
Join Date: Jul 2003
Posts: 586
 

Default Image Path MOD for 4.1.x

Many people on the X-Cart Forums have complained about the way the X-Cart 4.1.x branch handles images.

The Problem:
Many users have their own Image Folder Structure for grouping images by Category, Manufacturer, Provider, etc. Unfortunately, the 4.1.x branch tries to move all Thumbnails to the T folder, all Product images to the P folder, all Detailed images to the D folder, etc. If your store has thousands of images, these folders become a bloated mess with no organizational structure that makes it difficult for site Administrators to locate and add images.

The MODs below will fix this in 2 simple steps...
Step 1 will modify the image file path location (for example, to point to the old /files/images directory previously used in 4.0.x carts).
Step 2 will modify the code to keep your image name and location and not move it to the lettered sub-folders (on your server) when adding a New Product Thumbnail, Detailed Image, etc.

Thanks to my programmer brother for figuring this out for our store site. He said it was really easy to accomplish and the code could easily be made to check for which type of Image handling your prefer... the 4.0.x-style or the 4.1.x-style, so maybe the X-Cart Qualiteam programmers will implement this in a future release.

First, if you would like to try this MOD, as always, it's a good idea to first make a backup of your store files and DB. Also work on copies of the 2 files that are being modified, so you can change back quickly, if need be.

Next, make sure your Images Location is set to use the File System (FS).

MOD 01
File: include/func/func.backoffice.php (about line 49)

NOTE: The proper image file path (the part before the /files/ directory) can be found on the Summary page of your X-Cart back-end. Look under the Component column for your X-Cart directory, and enter the value you see in the Status column.

Part of: function func_get_files_location () {
# This function determine the files location for current user

CODE Was:
Code:
if ($single_mode || $user_account["usertype"] == "A") return $files_dir_name; return $files_dir_name.DIRECTORY_SEPARATOR.$login; }

CODE Now:
Code:
### Custom MOD - Image directory file path - Comment out 2 lines below and hard-code image path to your files folder... if ($single_mode || $user_account["usertype"] == "A") ## return $files_dir_name; return "/home/yoursite/public_html/files/"; ## return $files_dir_name.DIRECTORY_SEPARATOR.$login; return "/home/yoursite/public_html/files/"; }


MOD 02:
File: include/func/func.image.php (about line 502)

Part of: function func_prepare_image($file_upload_data, $type = 'T', $id = 0) {
# Prepare posted image for saving

CODE Was:
Code:
if ($config_data["location"] == "FS") { $prepared['image_path'] = ""; if (!is_url($file_path) || $config_data['save_url'] == 'Y') { $dest_file = func_image_dir($type); if (!zerolen($prepared['filename'])) { $dest_file .= "/".$prepared['filename']; } $prepared['image_path'] = func_store_image_fs($image_data, $type); if (zerolen($prepared['image_path'])) return false; $prepared['filename'] = basename($prepared['image_path']); $path = func_relative_path($prepared['image_path'], $xcart_dir); if ($path !== false) { $prepared['image_path'] = $path; } } else { $prepared['image_path'] = $file_path; } }

NOTE: All the code in MOD 2 below is comment out except for the final closing bracket, and this line: $prepared['image_path'] = $file_path;

CODE Now:
Code:
### Custom MOD - Comment out section below to prevent X-Cart from changing file name and saving to a lettered image subfolder /* if (!is_url($file_path) || $config_data['save_url'] == 'Y') { $dest_file = func_image_dir($type); if (!zerolen($prepared['filename'])) { $dest_file .= "/".$prepared['filename']; } $prepared['image_path'] = func_store_image_fs($image_data, $type); if (zerolen($prepared['image_path'])) return false; $prepared['filename'] = basename($prepared['image_path']); $path = func_relative_path($prepared['image_path'], $xcart_dir); if ($path !== false) { $prepared['image_path'] = $path; } } else { */ $prepared['image_path'] = $file_path; ### } }

I hope others get some good use out of this mod!

Update May 27, 2008:
NOTE 1: We 1st upload our product images (thumbs, detailed, etc.) to the files/images folder via FTP. When we Add a New Product, or change an existing one, we then Browse to this file on the Server (not from our local drive). This will give the product the correct image path to the exact location on your server. Otherwise you will have issues with a Temp image being created with the wrong image path.

NOTE 2: In the Database, your newly added images will then have the correct image_path in the xcart_images_D, xcart_images_T, etc. tables. Your images/D, images/T, etc. folders on your server will remain empty.

NOTE 3: If you are upgrading from X-Cart 4.0.x to X-Cart 4.1.x, the Database updater will assign your existing product images to one of the lettered sub-folders. Our web programmer then wrote a PHP script to go in and change all the existing image paths to point to their location in the /files/images folder(s). For new stores, without products, this will not be an issue, but if you have an existing store, you will need to go into the Database and export the xcart_images_D, xcart_images_T, etc. tables, and use a utility to find and replace the image_path. If your store only has a few existing products, you can manually Modify the Product via the Admin interface and select the new image via the FTP method mentioned in NOTE 1 above.

NOTE 4:This MOD has also been tested on stock installs of X-Cart 4.1.9 and X-Cart 4.1.10
A Security Fix was released by X-Cart on July 2, 2008 and it affects the include/func/func.backoffice.php file... see Post # 26 on Page 3 for X-Cart ver. 4.1.10 with Security Fix and the updated MOD code.

Robert
__________________
X-cart 4.1.10
Reply With Quote
  #2  
Old 05-15-2008, 08:09 AM
 
parekh81 parekh81 is offline
 

Senior Member
  
Join Date: Nov 2007
Posts: 191
 

Default Re: Image Path MOD for 4.1.x

hmm this is interesting. Haven't tried it out, but definately going to ... will let you know. Thanks for the effort.
__________________
Gold 4.4.2 with 'some' customisation
Site review: http://forum.x-cart.com/showthread.php?t=63075
Reply With Quote
  #3  
Old 05-15-2008, 10:10 AM
 
robertswww robertswww is offline
 

X-Adept
  
Join Date: Jul 2003
Posts: 586
 

Default Re: Image Path MOD for 4.1.x

Quote:
Originally Posted by parekh81
hmm this is interesting. Haven't tried it out, but definately going to ... will let you know. Thanks for the effort.
Let me know how it works out for you, as it worked out perfectly for our live site.

Also, it's an easy fix to change back, so when X-Cart 4.1.11 comes out, you can revert the files and use their image path fix, if you so desire.

In case you missed it, Alex Mulin, said that the image path issue would be addressed in the next major upgrade of X-Cart. Read his post #31 on page 4 of this forum topic:

http://forum.x-cart.com/showthread.php?t=39255

Robert
__________________
X-cart 4.1.10
Reply With Quote
  #4  
Old 05-22-2008, 03:23 PM
  JWait's Avatar 
JWait JWait is offline
 

X-Man
  
Join Date: Nov 2005
Location: California
Posts: 2,440
 

Default Re: Image Path MOD for 4.1.x

I am having a hard time figuring these parts out...
Code:
## return $files_dir_name; return "/home/yoursite/public_html/files/"; ## return $files_dir_name.DIRECTORY_SEPARATOR.$login; return "/home/yoursite/public_html/files/";

I understand I need to put the path to where my images are, but how does x-cart know I want to save a thumbnail to the "thumbs" folder and a product image to the "products" folder? It seems to find the images that are already there, but when I add one it puts in it the "var/tmp" folder with some strage abstraction of the original file name. For instance, "test-1.jpg" will be "test-1jpgFgfGt" or something similar. At any rate, it shows as a broken image, and is not stored anywhere near "/home/mysite/public_html/files/".

I could live with the P, T, D, C , and M folders if it didn't change the filename, and didn't append -01, -02, -03 etc. if the file was already there. Is there some reason it will not overwrite an existing file with the same name?
__________________
Two Separate X-Cart Stores
Version 4.4.4 Gold - X-AOM - Vivid Dreams Aquamarine (modified) - Linux
Mods - Newest Products - View All -, and a few others. Numerous upgrades from 4.0.x series.
Integrated with Stone Edge Order Manager + POS

Version 4.1.12 Gold (fresh install) - X-AOM - Linux
Mods - XCSEO free
Reply With Quote
  #5  
Old 05-24-2008, 03:42 PM
 
robertswww robertswww is offline
 

X-Adept
  
Join Date: Jul 2003
Posts: 586
 

Default Re: Image Path MOD for 4.1.x

As the original X-Cart codes shows in the func.backoffice.php, you need to specify your "$files_dir_name" (i.e. files directory name).

This is the name of your main files directory. For us, we just upgraded from a 4.0.x cart, so it was the main /files/ folder. Then in that folder we have sub-folders with our product images in them. This link is only concerned with the main folder that holds your image sub-folders.

To get the rest of the link (the part before the /files/ directory), go to the Administration --> Summary page of your X-Cart back-end. Look under the Component column for your X-Cart directory, and enter the value you see in the Status column.

NOTE: If you only do this Step 1, it will have the correct image path for existing images, but if you want it to have the correct image path to that same folder for new products (and not the standard X-Cart lettered sub-folders), then you have to complete Step 2 (in post #1 above).

When you complete Step 2 in the func.image.php file, be sure to keep these 2 lines of code:
Code:
$prepared['image_path'] = $file_path; }
That will set the image path to the file path you specify. When you add a new product (or clone a product) and add a thumbnail (or detailed image), it will first generate a tmp image link until you Save the New Product, and then the actual File Path and File Name you specified will be written into the Database and stored as the product's image path.

Our T, P, D, etc. image folders all remain empty at this point, and images for our newly added products are all existing in our files/imageABC folders.

Note: This has only been tested on X-Cart 4.1.9 on an Apache server (we're using a Dedicated IP).

Robert
__________________
X-cart 4.1.10
Reply With Quote
  #6  
Old 05-25-2008, 08:18 AM
  JWait's Avatar 
JWait JWait is offline
 

X-Man
  
Join Date: Nov 2005
Location: California
Posts: 2,440
 

Default Re: Image Path MOD for 4.1.x

"That will set the image path to the file path you specify. When you add a new product (or clone a product) and add a thumbnail (or detailed image), it will first generate a tmp image link until you Save the New Product, and then the actual File Path and File Name you specified will be written into the Database and stored as the product's image path."

I think that is the problem.

I have specified "/home/removed account name/public_html/test1/files/" as $prepared['image_path'] = $file_path; in func.backoffice.php

so in func.image.php when it see "$prepared['image_path'] = $file_path;" it is looking for
"/home/removed account name/public_html/test1/files/", correct? How does it know that a thumbnail needs to go to "/home/removed account name/public_html/test1/files/thumbs/" and a product image needs to go to "/home/removed account name/public_html/test1/files/products/" when it is not specified anywhere (that I can see anyway)?

Part of the upgrade process involves moving the images from the file system to the database. When I try to move them it does not move them where I want but uses the images/T, P, D etc. folders renaming them in the process.

Lets pretend for a moment that I have no images. If I add a new product with a thumbnail, how do I get it to save to "/home/removed account name/public_html/test1/files/products/" using the original filename I specify? Also, if I decide later I want a different thumbnail, how do I get it to overwrite the original thumbnail instead of appending "-01" to it?
__________________
Two Separate X-Cart Stores
Version 4.4.4 Gold - X-AOM - Vivid Dreams Aquamarine (modified) - Linux
Mods - Newest Products - View All -, and a few others. Numerous upgrades from 4.0.x series.
Integrated with Stone Edge Order Manager + POS

Version 4.1.12 Gold (fresh install) - X-AOM - Linux
Mods - XCSEO free
Reply With Quote
  #7  
Old 05-25-2008, 08:37 AM
  JWait's Avatar 
JWait JWait is offline
 

X-Man
  
Join Date: Nov 2005
Location: California
Posts: 2,440
 

Default Re: Image Path MOD for 4.1.x

As a side note: You might notice in my signature that we are using a Dynamic Image mod in version 4.0.19 but have decided not to use this after upgrading because of the ensuing problems it has caused. What it does is "read" the original full size image (stored in /files/products/) and creates a thumbnail that it stores as a MD5 hash of the filenname in files/cache (regardless of where you stipulate in the "images location" of x-cart). After upgrading, the full size product image shows as the thumbnail in xcart and there is no product image shown. As you can see, I am kind of starting from scratch, but I do have the images, just need to know where x-cart will put them (and hopefully store them using the original filenames).
__________________
Two Separate X-Cart Stores
Version 4.4.4 Gold - X-AOM - Vivid Dreams Aquamarine (modified) - Linux
Mods - Newest Products - View All -, and a few others. Numerous upgrades from 4.0.x series.
Integrated with Stone Edge Order Manager + POS

Version 4.1.12 Gold (fresh install) - X-AOM - Linux
Mods - XCSEO free
Reply With Quote
  #8  
Old 05-25-2008, 07:22 PM
  JWait's Avatar 
JWait JWait is offline
 

X-Man
  
Join Date: Nov 2005
Location: California
Posts: 2,440
 

Default Re: Image Path MOD for 4.1.x

OK.... I got x-cart to "see" the images that exist. There is still the problem that when adding a new image it isn't saved because it doesn't know where to save it (at least that is what I think). It "saves" it in the var/tmp folder (where it really isn't saved). If I comment out the code like this...

Have you tried saving a new image? Were you successful?
__________________
Two Separate X-Cart Stores
Version 4.4.4 Gold - X-AOM - Vivid Dreams Aquamarine (modified) - Linux
Mods - Newest Products - View All -, and a few others. Numerous upgrades from 4.0.x series.
Integrated with Stone Edge Order Manager + POS

Version 4.1.12 Gold (fresh install) - X-AOM - Linux
Mods - XCSEO free
Reply With Quote
  #9  
Old 05-27-2008, 12:28 PM
 
sparker2 sparker2 is offline
 

eXpert
  
Join Date: Feb 2007
Posts: 290
 

Default Re: Image Path MOD for 4.1.x

I have done the mod here and now I am getting this error below.

Parse error: syntax error, unexpected $end in /home/stitches/public_html/include/func/func.backoffice.php on line 619
__________________
Shareen
sparker2@cox.net
http://www.stitches4u.com
X-Cart Version 4.5.0 with Smart Template vs 4.4.x
Reply With Quote
  #10  
Old 05-27-2008, 12:28 PM
 
robertswww robertswww is offline
 

X-Adept
  
Join Date: Jul 2003
Posts: 586
 

Default Re: Image Path MOD for 4.1.x

Quote:
Originally Posted by JWait
Have you tried saving a new image? Were you successful?
Yes, we add new images all the time (with this Mod in place).

I think I might know what the problem is. We FTP our images up to our site first (into the files/images/sub-folders).

Then when we Add or Modify a product, we browse to this location on the server. So the exact file location is placed into the image_path.

If you are browsing images on your local hard drive, then it will not have the correct image file path and will create a Temp image.

Please look back at my 1st Post above, as I updated it with 3 new NOTES at the bottom.

Robert
__________________
X-cart 4.1.10
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Changing and adding new features


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 04:44 AM.

   

 
X-Cart forums © 2001-2018