网络营销电子商务研究中心  
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, 08:03 PM
Izayah Izayah is offline
初级会员
 
Join Date: 2013-04-12
Posts: 2
Izayah 现在声名狼藉
Default Zen-cart里创建module的方法

虽然Zen-cart左右栏都有相关的module放在sideboxes里,但是,有的时候,需要在页面上某个地方单独显示这些box的内容。比如说,我想把Shopping Cart和Currencies的内容显示在页面的头部。这个时候,并不能直接用Zen-cart提供的module;唯有对现有的module进行相关的改造,才能自如的显示内容。

Zen-cart 1.3.8 采用的模板技术比较特殊,/includes/modules里存放的是相关的module文件,负责页面数据的生成;而模板文件则是放在各个模板目录,处理相关页面内容的生成。整个过程更像是对zen-cart的hack,而不是module的制作。

下面就以创建一个页面头部的currencies,来简单说明一下页面module的制作方法,制作完成后的效果如下图所示:



可以参考、对比


/includes/templates/template_default/sideboxes/tpl_search_header.php
/includes/templates/template_default/sideboxes/tpl_search.php




/includes/modules/sideboxes/search_header.php
/includes/modules/sideboxes/search.php

来获得灵感。

按以下三个步骤来制作这个module:

1)
在/includes/modules/sideboxes目录下,新建一个名叫currencies_header.php的文件。

如果需要,在这个文件里可以依照/includes/modules/sideboxes/search_header.php提供的方法来直接操作数据库。

在这里,我们根据/includes/modules/sideboxes/currencies.php来创建文件,主要是把currencies.php里用于sidebox显示的句子删掉:


$title = '<label>' . BOX_HEADING_CURRENCIES . '</label>';
$title_link = false;
require($template->get_template_dir($column_box_default, DIR_WS_TEMPLATE, $current_page_base,'common') . '/' . $column_box_default);

这样,我们就不会在调用这个module的时候,调用到用于sidebox里显示的相关语句。

同样,在这个文件里,我们可以根据自己的需要,加入一个module生成数据所需要的所有元素。

2)
新建一个名叫tpl_currencies_header.php的文件到/includes/templates/YourTemplate/sideboxes,为这个module创建单独的显示风格。这里根据你需要放置的地方,对其中的CSS/XHTML代码进行修改即可。用于显示的数据,是从第一步的module里传进来的全局变量。

注意:Zen-cart 1.3.8 里,按习惯用$content来存储生成的页面显示代码。

3) 在/includes/templates/YourTemplate/common文件夹里,到指定的页面模板里,加入相关的显示生成语句。

在这个例子中,因为是要在页首显示这个currencies显示框,则要在tpl_header.php里加入这么一段话就可以调用module生成数据了:


<?php
require(DIR_WS_MODULES . 'sideboxes/currencies_header.php');
echo $content;
?>

用上面的方法,就不单单可以修改现有的module,还能根据自己的需要,创作更多的module出来。
Attached Images
File Type: jpg zen-cart-module-make.jpg (57 KB, 3 views)
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 05:37 AM.


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