Zen Cart Logo
Forums / Templates, Stylesheets, Page Layout / What function/code do I need to use to get medium image displayed on a custom page?

What function/code do I need to use to get medium image displayed on a custom page?

Locked

Views: 1,416

Results 1 to 7 of 7
This thread is locked. New replies are disabled.
3 Mar 2008, 4:32 AM
#1
tj1 avatar

tj1

Totally Zenned

Join Date:
Mar 2005
Location:
California
Posts:
628
Plugin Contributions:
0

What function/code do I need to use to get medium image displayed on a custom page?

I've a built simple page that displays only the product's info, basically the center column minus navigation, price, add to cart buttons and other links.

I made this so I can put a link on my third-party site listings (such as eBay, amazon, etc) and when people click on it, it will open a new page showing only the product info, since putting a link to the regular ZC product page would be against the rules.

I put this script in my store's root directory and will put links in my third-party site listings using the products model or id something like this:
myzcstore/display_product_info?products_id=id_here or
myzcstore/diplay_product_info?model=model_here

Everything works perfectly, except I'm having trouble getting the product image. I'd like to use the medium image.

My php knowledge is really limited so this might be something simple, but it's been really hard for me.

Does anyone know what function/code is needed to get the medium image?

Using the **zen_get_products_image($products_id) **only retrieves the small image.

I've tried using this other line I found in tpl_modules_main_product_image.php

echo '<a href="' . zen_href_link(FILENAME_POPUP_IMAGE, 'pID=' . $_GET['products_id']) . '" target="_blank">' . zen_image($products_image_medium, $products_name, MEDIUM_IMAGE_WIDTH, MEDIUM_IMAGE_HEIGHT) . '<br />' . TEXT_CLICK_TO_ENLARGE . '</a>';

This hasn't worked either.
Could someone please help me figure this out?

Thanks.

3 Mar 2008, 7:13 AM
#2
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: What function/code do I need to use to get medium image displayed on a custom page?

This is the image code from tpl_product_info_display.php file which displays the medium image

<?php
/**
 * display the main product image
 */
   require($template->get_template_dir('/tpl_modules_main_product_image.php',DIR_WS_TEMPLATE, $current_page_base,'templates'). '/tpl_modules_main_product_image.php'); ?>
3 Mar 2008, 8:12 AM
#3
tj1 avatar

tj1

Totally Zenned

Join Date:
Mar 2005
Location:
California
Posts:
628
Plugin Contributions:
0

Re: What function/code do I need to use to get medium image displayed on a custom page?

Thanks for the suggestion, unfortunately, that doesn't seem to work. I'm not sure if it's because of the location of this script, which is located in the store's root directory.

Actually that was the first thing I tried before moving on the line I mentioned, but I always got the default 'no picture available' with either one.

Do you think that's the cause for it not being working (location of the script)?

3 Mar 2008, 8:16 AM
#4
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: What function/code do I need to use to get medium image displayed on a custom page?

Do you think that's the cause for it not being working (location of the script)?
From where are you trying to invoke this from?

Zen Cart uses sessions for security so if from outside of zencart this could be the issue

3 Mar 2008, 8:19 AM
#5
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: What function/code do I need to use to get medium image displayed on a custom page?

To get the image, you'll need to run this (from the /includes/modules/main_product_image.php):```
$products_image_extension = substr($products_image, strrpos($products_image, '.'));
$products_image_base = str_replace($products_image_extension, '', $products_image);
$products_image_medium = $products_image_base . IMAGE_SUFFIX_MEDIUM . $products_image_extension;

// check for a medium image else use small
if (!file_exists(DIR_WS_IMAGES . 'medium/' . $products_image_medium)) {
$products_image_medium = DIR_WS_IMAGES . $products_image;
} else {
$products_image_medium = DIR_WS_IMAGES . 'medium/' . $products_image_medium;
}
and then call your image similar to how the tpl_modules_main_product_image.php does it:
echo zen_image($products_image_medium, $products_name, MEDIUM_IMAGE_WIDTH, MEDIUM_IMAGE_HEIGHT);

3 Mar 2008, 8:24 AM
#6
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: What function/code do I need to use to get medium image displayed on a custom page?

tj1:

I've a built simple page that displays only the product's info, basically the center column minus navigation, price, add to cart buttons and other links.

I made this so I can put a link on my third-party site listings (such as eBay, amazon, etc) and when people click on it, it will open a new page showing only the product info, since putting a link to the regular ZC product page would be against the rules.

I put this script in my store's root directory and will put links in my third-party site listings using the products model or id something like this:
myzcstore/display_product_info?products_id=id_here or
myzcstore/diplay_product_info?model=model_here

Or you could just use the regular site, and add &source=ebay to your URLs, and then in your custom tpl_main_page.php AFTER this section:```
// the following IF statement can be duplicated/modified as needed to set additional flags
if (in_array($current_page_base,explode(",",'list_pages_to_skip_all_right_sideboxes_on_here,separated_by_commas,and_no_spaces')) ) {
$flag_disable_right = true;
}

if (isset($_GET['source']) && $_GET['source']=='ebay') {
$flag_disable_left = true;
$flag_disable_right = true;
}


So, you'd use http://www.my_site.com/index.php?main_page=product_info&products_id=333&source=ebay
 ... and when people visit that page, the left and right columns will be gone.

In fact, you could do this in addition to your other approach, and they can run at the same time, and you can choose whichever you desire whenever you wish ... etc.
And of course you could customize it further as needed ...
4 Mar 2008, 6:52 PM
#7
tj1 avatar

tj1

Totally Zenned

Join Date:
Mar 2005
Location:
California
Posts:
628
Plugin Contributions:
0

Re: What function/code do I need to use to get medium image displayed on a custom page?

DrByte, thanks so much for that great info on customizing using the tpl_main_page.php, I wasn't aware of this and it's so easy. :) It works great.

I still would like to know how to get the medium image to display if I were to use it in another script. I'm using the following simple script for testing using the info you provided. This is called show_image.php and is located in the store's root directory, accessed like myzcstore/show_image.php?products_id=123

<?PHP
require('includes/application_top.php');
?>

<?php 
$products_image_extension = substr($products_image, strrpos($products_image, '.'));
$products_image_base = str_replace($products_image_extension, '', $products_image);
$products_image_medium = $products_image_base . IMAGE_SUFFIX_MEDIUM . $products_image_extension;

// check for a medium image else use small
if (!file_exists(DIR_WS_IMAGES . 'medium/' . $products_image_medium)) {
  $products_image_medium = DIR_WS_IMAGES . $products_image;
} else {
  $products_image_medium = DIR_WS_IMAGES . 'medium/' . $products_image_medium;
}
 ?>
<?php
  echo '<a href="' . zen_href_link(FILENAME_POPUP_IMAGE, 'pID=' . $_GET['products_id']) . '" target="_blank">' . zen_image($products_image_medium, $products_name, MEDIUM_IMAGE_WIDTH, MEDIUM_IMAGE_HEIGHT) . '<br /><span class="imgLink">' . TEXT_CLICK_TO_ENLARGE . '</span></a>';
?>

<?php
require('includes/application_bottom.php');
?>

This doesn't work and I think the reason is that this code doesn't know what image to look for, correct? If so, how do I make it look for the image corresponding to the products_id?