ZENCART晚点出现 -c-.html 网址的 解决办法

来源:互联网 发布:英国留学哪种gpa算法 编辑:程序博客网 时间:2024/05/01 09:55
在进行一些zen cart设置时发现产品页面(product_info)的category icon显示有两个问题,一是category name不显示,二是链接错误,形如:http://example.com/-c-.html (开启了SEO URLS后)。检查后台设置 admin -> configuration -> product info 是没有问题的,默认就已经打开,因此错误来源于代码问题。检查 includes/modules/category_icon_display.php 可以看到如下代码:

$category_icon_display_name = zen_get_categories_name((int)$current_category_id); 
$category_icon_display_image = zen_get_categories_image((int)$current_category_id);

然而die($category_icon_display_name)出来的结果是空的。检查 zen_get_categories_name 函数没有问题,因此问题出在 $current_category_id 变量,果然,打印结果显示它是空的!经过搜索 $current_category_id 变量初始化于 includes/init_includes/init_category_path.php,检查代码可以看到:

$cPath = zen_get_product_path($_GET['products_id']);

检查函数 zen_get_product_path 代码可以看到zen cart使用 master_categories_id 来查看产品的分类的,而数据库中 master_categories_id 全是 0 !这时想到我们上产品基本都是使用 easy populate 插件来完成,master_categories_id 为空的情况只可能是由于 easy populate 的不完整,代码有点小失误(暂未细查)。OK,问题找到了,临时的解决办法是首先完善 zen_get_products_category_id 函数(因为它也是只根据 master_categories_id 查看分类,而未查看 products_to_categories 表),在 return 之前加入代码:

/** 
* Add since 2010-12-8, by $d {http://www.ddmin.com} 
*/ 
if (! $the_products_category->fields['master_categories_id']) { 
$d_p2c_cid = $db->Execute('SELECT categories_id FROM `' . TABLE_PRODUCTS_TO_CATEGORIES . '` WHERE products_id="' . $products_id . '"')->fields['categories_id']; 
$the_products_category->fields['master_categories_id'] = $d_p2c_cid; 

/** 
* Add end 
*/

然后打开 includes/modules/category_icon_display.php,在 $category_icon_display_name = zen_get_categories_name((int)$current_category_id); 前加入代码:

/** 
* Add since 2010-12-8, by $d {http://www.ddmin.com} 
*/ 
$current_category_id = zen_get_products_category_id((int)$_GET['products_id']); 
/** 
* Add end 
*/

category id 获取不到的问题解决,接着打开 template_default/templates/tpl_modules_category_icon_display.php,将 $_GET['cPath'] 改为 $current_category_id 即可,category icon问题解决。



修改tpl_best_sellers.php(/includes/templates/template_default/sideboxes)文件里的for ($i=1; $i<=sizeof($bestsellers_list); $i++) { 以下面的代码替换 } 

$content .= ‘<li><a href=”‘ . zen_href_link(zen_get_info_page($bestsellers_list[$i]['id']), ‘products_id=’ . $bestsellers_list[$i]['id']) . ‘”>’ . zen_get_products_image($bestsellers_list[$i]['id']) . zen_trunc_string($bestsellers_list[$i]['name'], BEST_SELLERS_TRUNCATE, BEST_SELLERS_TRUNCATE_MORE) . ‘</a></li>’ . “\n”;

最后进网站后台-Configuration-images- small image width/small image height 修改图片的大小即可 !



直接修改includes/templates/YOUR_TEMPLATES/templates/tpl_modules_category_icon_display.php
找到文件中的以下内容
<div align="<?php echo $align; ?>" id="categoryIcon" class="categoryIcon"><?php echo '<a href="' . zen_href_link(FILENAME_DEFAULT, 'cPath=' . $_GET['cPath'], 'NONSSL') . '">' . $category_icon_display_image . $category_icon_display_name . '</a>'; ?></div>
替换为
<div align="<?php echo $align; ?>" id="categoryIcon" class="categoryIcon"><?php echo '<a href="' . zen_href_link(FILENAME_DEFAULT, 'cPath=' .$cPath, 'NONSSL') . '">' . $category_icon_display_image . $category_icon_display_name . '</a>'; ?></div>
即可。
注:如果自定义的模版里没有以上文件,请从默认模版中复制。