网络营销电子商务研究中心  
How to buy the best prescription safety glasses in Canada? Let's study!
Go Back   网络营销电子商务研究中心 > 网站建设 > ZenCart
User Name
Password
 
FAQ Members List Calendar Cheap Glasses

Reply
 
Thread Tools Display Modes
  #1   IP: 49.87.2.24
Old 2016-05-14, 09:36 PM
Jaycob Jaycob is offline
初级会员
 
Join Date: 2005-03-18
Posts: 1
Jaycob 现在声名狼藉
Default 解决Zen Cart目录链接为-c-.html的问题

在进行一些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 by 水木(http://www.0058.net) since 2010-11-2
*/
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 by 水木(http://www.0058.net) since 2010-11-2
*/
$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问题解决。
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Prescription-glasses.com offers prescription glasses online at discount prices.
All times are GMT +8. The time now is 11:07 AM.


Powered by vBulletin Version 3.8.7
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.