Zen Cart Logo
Forums / General Questions / A PHP question: appending $random_featured_product->fields['products_image']

A PHP question: appending $random_featured_product->fields['products_image']

Views: 658

Results 1 to 5 of 5
13 Jan 2011, 11:35 PM
#1
donn avatar

donn

Zen Follower

Join Date:
Oct 2007
Posts:
241
Plugin Contributions:
0

A PHP question: appending $random_featured_product->fields['products_image']

First, I'd like to thank anyone who responds to my question, as I'm trying to find the answer, but still have not. The code snippet below is what I am concerned with:

. zen_image(DIR_WS_IMAGES . $random_featured_product->fields['products_image'],

Specifically, I'd like to append a suffix to the

$random_featured_product->fields['products_image']

part of the generated HTML, and so essentially I need to know how to have the $random_featured_product->fields['products_image'] with the same suffix on every one.

This is probably already in the ZC code somewhere else, as it would be the same as how the cart generates the appended _MED and _LRG image names.

Thanks....!

14 Jan 2011, 12:04 AM
#2
donn avatar

donn

Zen Follower

Join Date:
Oct 2007
Posts:
241
Plugin Contributions:
0

Re: A PHP question: appending $random_featured_product->fields['products_image']

$products_image_large = $products_image_base . IMAGE_SUFFIX_LARGE . $products_image_extension;

I found this code in another cart file.
(includes/modules/main_product_image.php)

Can't I just use this code, and replace the IMAGE_SUFFIX_LARGE with a new constant defined with the new suffix that I am using??

Would this work?

14 Jan 2011, 1:38 AM
#3
donn avatar

donn

Zen Follower

Join Date:
Oct 2007
Posts:
241
Plugin Contributions:
0

Re: A PHP question: appending $random_featured_product->fields['products_image']

OK; I see that the example is dealing with a different string.

so, would this then work:

.....zen_image(DIR_WS_IMAGES . 'tiny/' . str_replace($random_featured_product->fields['products_name'], '', $file) . IMAGE_SUFFIX_TINY . $products_image_extension, TINY_IMAGE_WIDTH, TINY_IMAGE_HEIGHT) . '</a><br />.....

14 Jan 2011, 8:28 PM
#4
donn avatar

donn

Zen Follower

Join Date:
Oct 2007
Posts:
241
Plugin Contributions:
0

Re: A PHP question: appending $random_featured_product->fields['products_image']

define("LEFTCOLUMN_IMAGE_WIDTH", "180");
define("IMAGE_SUFFIX_TINY", "_TNY");
define("DIR_WS_IMAGES_TINY", "images/tiny/");

...

$randomfeaturednu = $random_featured_product->fields['products_image']. IMAGE_SUFFIX_TINY . '.jpg';

...

. zen_image (DIR_WS_IMAGES_TINY . $randomfeaturednu, $random_featured_product->fields['products_name'], LEFTCOLUMN_IMAGE_WIDTH, LEFTCOLUMN_IMAGE_HEIGHT) . '</a>


These code changes/additions produces an HTML output with
filename.jpg_TNY.jpg - not exactly what I was intending.

. zen_image (DIR_WS_IMAGES_TINY . $random_featured_product->fields['products_image'], $random_featured_product->fields['products_name'], LEFTCOLUMN_IMAGE_WIDTH, LEFTCOLUMN_IMAGE_HEIGHT) . '</a>

This works, but the TINY file has the same name as the SMALL size, only a different directory.

I would rather have ALL the TNY files in one directory, even though that defies the convention of how SMALL MED and LRG image files are arranged in their dirs. How would I remove the path from the product image result? Also how do I truncate the file extension, so I can add the _TNY.jpg and not have it as jpg._TNY.jpg??

14 Jan 2011, 9:07 PM
#5
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: A PHP question: appending $random_featured_product->fields['products_image']

main_product_image.php does all the steps of creating the filepaths, so if you examine it thoroughly you should see how you can make your desired filepaths.
Its first step is recording and removing the extension.