View Single Post
  #7  
Old 03-13-2005, 08:14 PM
 
dsparks dsparks is offline
 

Advanced Member
  
Join Date: Nov 2002
Posts: 34
 

Default

I finally got the code straight for the product default image. I ran into a few issues wih variable scoping.

Anyway...

As I re-did the product code, I also re-did an option for the category code.

The following code changes will allow you to show or not show the default icon image for categories or products. This includes the featured item list, bestsellers etc. I also coded this change to only affect the customer areas, as I usually want to see what is going on into the admin area.


1) Add the following 2 records in the xcart_config table:

Code:
insert into xcart_config (name,`comment`,value,category,orderby,`type`,defvalue) VALUES ('show_default_product_image','Show default product image ','Y','Appearance','5100','checkbox','Y') insert into xcart_config (name,`comment`,value,category,orderby,`type`,defvalue) VALUES ('show_default_category_image','Show default category image ','Y','Appearance','5101','checkbox','Y')


2) Change the file skin1/product_thumbnail.tpl:

from:

Code:
{if $config.Appearance.show_thumbnails eq "Y"}[img]{if $tmbn_url}{$tmbn_url}{else}{if $full_url}{$http_location}{else}{$xcart_web_dir}{/if}/image.php?productid={$productid}{if $file_upload_data.file_path}&tmp=y{/if}{/if}[/img]{/if}

to:


Code:
{insert name="is_product_image_avail" assign="image_avail" productid=$productid variantid=""} {if $image_avail} {if $config.Appearance.show_thumbnails eq "Y"}[img]{if $tmbn_url}{$tmbn_url}{else}{if $full_url}{$http_location}{else}{$xcart_web_dir}{/if}/image.php?productid={$productid}{if $file_upload_data.file_path}&tmp=y{/if}{/if}[/img]{/if} {/if}


3) Change the file skin1/customer/main/subcategories.tpl around line 17:

from:

Code:
{if $tmp} [img]{if $current_category.icon_url}{$current_category.icon_url}{else}{$xcart_web_dir}/icon.php?categoryid={$cat}{/if}[/img] {/if}

to:

Code:
{insert name="is_category_image_avail" assign="image_avail" categoryid=$cat} {if $tmp and $image_avail} [img]{if $current_category.icon_url}{$current_category.icon_url}{else}{$xcart_web_dir}/icon.php?categoryid={$cat}{/if}[/img] {/if}


4) Then add the following code to the end of the file include/func.php:


Code:
# # Check to see if an image is available for a product and wether to use default image or not # function insert_is_product_image_avail($params, &$smarty) { global $config, $sql_tbl, $usertype, $current_area; $use_image = false; if ($current_area == "C" || $usertype == "C") { $productid = $params['productid']; $variantid = $params['variantid']; if (empty($productid)) $productid = ""; if (empty($variantid)) $variantid = ""; $continue_checks = true; if(!empty($variantid)) $dbresult = db_query("SELECT image, image_path FROM $sql_tbl[thumbnails] WHERE productid='$productid' AND variantid = '$variantid'"); if(empty($dbresult)) $dbresult = db_query("SELECT image, image_path FROM $sql_tbl[thumbnails] WHERE productid='$productid' AND variantid = ''"); if (db_num_rows($dbresult)) list($image, $image_path) = db_fetch_row($dbresult); else { if ($config["Appearance"]["show_default_product_image"] == "Y") $use_image = true; $continue_checks = false; } db_free_result($dbresult); if ( $continue_checks == true ) { if ($config["Images"]["thumbnails_location"] == "DB") { if (!empty($image)) $use_image = true; else $no_image_db = true; } if ($config["Images"]["thumbnails_location"] == "FS" || !empty($no_image_db) ) { if (!empty($image_path)) { $use_image = true; $continue_checks = false; } } } if ( $continue_checks == true ) { if (!empty($image_out)) $use_image = true; else { if ($config["Appearance"]["show_default_product_image"] == "Y") $use_image = true; } } } else $use_image = true; return $use_image; }

and

Code:
# # Check to see if an image is available for a category and wether to use default image or not # function insert_is_category_image_avail($params, &$smarty) { global $config, $sql_tbl, $usertype, $current_area; $use_image = false; if ($current_area == "C" || $usertype == "C") { $categoryid = $params['categoryid']; if (empty($categoryid)) $categoryid = 0; $image_out = ""; $image_type = ""; $image_path = ""; $image = ""; $continue_checks = true; if ($config["Images"]["icons_location"] == "FS") $image_field = "image_path"; else $image_field = "image"; $categoryid_path = func_query_first_cell("SELECT categoryid_path FROM $sql_tbl[categories] WHERE categoryid='$categoryid'"); $_cat_sequense = array_reverse(explode("/", $categoryid_path)); foreach ($_cat_sequense as $k=>$v) { $category_icon = func_query_first("SELECT $image_field, image_type FROM $sql_tbl[icons] WHERE categoryid='$v'"); if (!empty($category_icon[$image_field])) { $image_type = $category_icon["image_type"]; $$image_field = $category_icon[$image_field]; break; } } if (empty($image) and empty($image_path)) { if ($config["Appearance"]["show_default_category_image"] == "Y") $use_image = true; $continue_checks = false; } if ($continue_checks == true) { if ($config["Images"]["icons_location"] == "DB") { if (!empty($image)) $image_out = $image; else $no_image_db = true; } if ($config["Images"]["icons_location"] == "FS" || !empty($no_image_db)) { if (!empty($image_path)) { $use_image = true; $continue_checks = false; } } if ($continue_checks == true ) { if (!empty($image_out)) $use_image = true; else { if ($config["Appearance"]["show_default_category_image"] == "Y") $use_image = true; } } } } else $use_image = true; return $use_image; }


That's all...


If you want to change the way the product/category images are displayed just go to the Administration area and select the General settings / Appearance options and select or deselect the options to Show default category image and Show default product image (they should be at the bottom of the page).

This modification will not remove the added space taken up by the image if it were displayed.

If you want to do this, then you will need to change about 15 other files.

Typically, you just need to look for references to the text product_thumbnail.tpl in all of the files and put the following code around where the display table is built to display the image and remove the modification to the file skin1/product_thumbnail.tpl


Code:
{insert name="is_product_image_avail" assign="image_avail" productid=$productid variantid=""} {if $image_avail} *** DO CODE TO DEFINE TABLE AND DISPLAY IMAGE *** {/if}



Let me know if this works for you....
__________________
X-Cart Gold: v4.0.17
Reply With Quote