$7.49 .com domain with free InstantPage Website Builder$1.99 Web Hosting   捷飞网络官方淘宝店   Godaddy 优惠码
返回列表 发帖
分享到:




[开发经验技巧分享] 设置Zen Cart 商品页显示一定数量的同类商品(相关商品)

在商品详细页,随机显示一定数量的同类产品& N+ t  X6 L6 f
1、创建一个新文件 随意命名 没重复就行 例如:tpl_product_info_similar.php
6 ]( H. ~% N2 ~; g% \复制该文件到includes\templates\你的模板\templates\目录下. x& U/ _- j$ m& n5 U# F
打开该文件,把以下代码复制进去并保存
# ?$ D5 C1 J! s) \& L

  1. <div class="centerBoxWrapper" id="similar_product">
  2. <h2 class="centerBoxHeading">Related Products</h2>
  3. <ul>
  4. <?php
  5. $products_id = (int)$_GET['products_id'];
  6.     $flash_page_id_con = array();
  7.     $flash_page_images_con = array();
  8.     $flash_page_price_con = array();
  9.     $flash_page_name_con = array();
  10.     $flash_page_query = "select p.products_id,p.products_image,pd.products_name from " . TABLE_PRODUCTS ." p, ". TABLE_PRODUCTS_DESCRIPTION . " pd where p.`products_id`=pd.`products_id` AND p.`products_status`='1'  AND pd.`language_id` = '" . (int)$_SESSION['languages_id'] . "' AND p.`master_categories_id` = " . zen_get_products_category_id($products_id) . " ORDER BY rand() limit 12";
  11.     $flash_page = $db->Execute($flash_page_query);
  12.     while(!$flash_page->EOF){
  13.         $flash_page_items[] = $flash_page->fields;
  14.         $flash_page_id_con[]    = $flash_page->fields['products_id'];
  15.         $flash_page_images_src = is_int(strpos($flash_page->fields['products_image'],','))? substr($flash_page->fields['products_image'],0,strpos($flash_page->fields['products_image'],',')):$flash_page->fields['products_image'];
  16.         $flash_page_images_con[]    = '"'.(zen_not_null($flash_page->fields['products_image']) ? $flash_page_images_src : PRODUCTS_IMAGE_NO_IMAGE ).'"';
  17.         $flash_page_price_con[]    = '"'.$currencies->display_price(zen_get_products_base_price($flash_page->fields['products_id']),zen_get_tax_rate($product_check->fields['products_tax_class_id'])).'"';
  18.         $flash_page_name_con[]    = '"'.zen_output_string(zen_get_products_name($flash_page->fields['products_id'])).'"';
  19.         $flash_page->MoveNext();
  20.     }
  21.    
  22.     $flash_page_id = implode(",", $flash_page_id_con);
  23.     $flash_page_images = implode(",", $flash_page_images_con);
  24.     $flash_page_price = implode(",", $flash_page_price_con);
  25.     $flash_page_name = implode(",", $flash_page_name_con);
  26.     $flash_page_display_num    = $flash_page->RecordCount();
  27. ?>
  28. <?php for($i = 0; $i< $flash_page_display_num ; $i++){?>
  29. <li id="li<?php echo $i;?>" style="display:block;float:left;padding-left:10px;width:22%;">
  30. <a href="<?php echo zen_href_link(zen_get_info_page($flash_page_items[$i]['products_id']), 'products_id=' . $flash_page_items[$i]['products_id']);?>"><?php echo zen_image(DIR_WS_IMAGES . $flash_page_items[$i]['products_image'], $flash_page_items[$i]['products_name'], IMAGE_FEATURED_PRODUCTS_LISTING_WIDTH, IMAGE_FEATURED_PRODUCTS_LISTING_HEIGHT); ?></a><p style="text-align:center;"><a href="<?php echo zen_href_link(zen_get_info_page($flash_page_items[$i]['products_id']), 'products_id=' . $flash_page_items[$i]['products_id']);?>"><?php echo $flash_page_items[$i]['products_name']; ?></a><br /><strong id="cell_price<?php echo $i?>" class="red"><?php echo $currencies->display_price((zen_get_products_base_price($flash_page_items[$i]['products_id']) == 0 ? zen_get_products_sample_price($flash_page_items[$i]['products_id']): zen_get_products_base_price($flash_page_items[$i]['products_id'])),zen_get_tax_rate($product_check->fields['products_tax_class_id'])); ?></strong></p>
  31. </li>
  32. <?php
  33. //print_r($flash_page_items[$i]);
  34. }
  35. ?>
  36. </ul>
  37. </div>
复制代码
2 o! }% C+ }/ j% i4 P6 ^9 S( r$ s

" _6 i& H/ d! @( B! v- w) a  m2、找到includes\templates\你的模板\templates\tpl_product_info_display.php文件% \% E& q" }- u9 {3 i5 f
在相应的位置加上以下代码:
# i( @( i) D* e. J! d; F! }
  1. <?php require($template->get_template_dir('你创建的文件tpl_product_info_similar.php',DIR_WS_TEMPLATE, $current_page_base,'templates'). '/你创建的文件tpl_product_info_similar.php'); ?>
复制代码
6 W* J, o2 Y6 b( h  P6 ]1 {$ j
% \/ T# b' a; u. T
PS,标题显示字数限制:
3 m  P+ o& {6 w

  1. <?php echo substr($flash_page_items[$i]['products_name'],0,34); ?>
复制代码

返回列表
Namecheap
Namecheap.com - Cheap domain name registration, renewal and transfers - Free SSL Certificates - Web Hosting
互联网安全