E-Commerce边学边用,持续更新中......

下面是功能介绍的一个翻译,水平有限,翻译不对的,希望给指正。

• Shopping cart and product 'look and feel' are themeable (购物车和商品是要主题化的)
• Create taxes, charges and discounts (可以创建税、费用和折扣)
• Subscriptions and recurring payments (订购和定期付款)
• Receive donations(接受捐赠)
• Sell file downloads, shippable items, bundles or even customizable products (可以出售供下载的文件、可运输的货物、包裹、甚至定制的商品)
• Inventory management (库存管理)
• Payment and shipping plugins: The system can use PayPal, Authorize.net, eWAY, C.O.D. or you can roll your own. (支付和运输的插件:系统可以用PayPal, Authorize.net, eWAY, C.O.D.或者你可以定义自己的接口)
• Invoice generation and email notifications (发票的生成和email通知)
• Transaction and payment workflows (交易和付款的流程)
• Reports and sales summaries (报告和出售记录)
• Customers can review their order history (顾客可以查看他们的订单历史)
• Run an auction site (可以做成一个拍卖网站)
• Charts and Statistics! (Soon...) (图表和统计)

随着经验的增加会不断更新中

==============a scratch of pen of jason==================
www.5iphp.com,我的drupal站点

ecommerce

ecommerce 貌似挺复杂的,期待。。。

关于ecommerce的cart表现形式的修改

用ecommerce模块的时候,我想自己修改cart的显示方式,开始找了半天也没有找到在哪里修改那个cart的view,后来我灵机一动,先搜索“Subtotal”这个显示在cart下面的总价格的单词,在cart.module里找到了theme_cart_view_form函数,后来一看,就是修改这个函数了,最后得到自己比较满意的显示效果。

==============a scratch of pen of jason==================
www.5iphp.com,我的drupal站点

www.5iphp.com 关于drupal学习、drupal经验、drupal教程的网站

关于ecommerce中添加市场价格

多商品都有市场价格跟会员价格。ecommerce没有分的那么仔细,它只有一个价格。所以需要建立一个市场价格的字段。这个字段可以用cck添加。
产品的访问路径是http://127.0.0.1/product
首先要确认已经安装好了cck了。
然后到 管理--内容管理--内容类型--product--编辑
这个目录下有个添加字段的标签,你可以添加marketPrice字段了。
添加完这个字段以后,你再去创建内容--product--Shippable Product里添加产品的时候就会多出一个marketPrice的选项,你就可以添加市场价格了。

市场价格添加完以后,会跟原来的价格不现在在一起,这就需要修改ecommerce--product--product.module了

主要修改这个模块里的这个函数function product_nodeapi下的

case 'view'://单个产品的显示页面
/* If we have a pseudo product, add some product specific theming to it. */
if ($node->type == 'product' && $a4) {
$breadcrumb[] = l(t('Home'), '');
$breadcrumb[] = l(t('Product'), 'product');
drupal_set_breadcrumb($breadcrumb);
}
if ($node->ptype) {
$node->content['price'] = array(
'#value' => theme('product_price', $node),
'#weight' => 2,
);
$node->content['field_marketprice'] = array(//市场价格的表现形式
'#value' => theme('product_marketPrice', $node),
'#weight' => 1,
);

然后单独的在这个页面写一个theme函数
/**
* Theme function to render product node-市场价格的表现形式.
*/
function theme_product_marketPrice($node) {
//print_r($node);
return ''. t('marketPrice') .': ' . module_invoke('payment', 'format', $node->field_marketprice[0]['value']) . '';
}

至此市场价格的添加和显示都正常了

==============a scratch of pen of jason==================
www.5iphp.com,我的drupal站点

www.5iphp.com 关于drupal学习、drupal经验、drupal教程的网站

一直期待支付宝模块

一直期待支付宝模块的诞生

--------------------------------
购物者|快乐购购购

--------------------------------
摄影博客

支付宝模块我已经写

支付宝模块我已经写好了,不过支付宝网关真是垃圾。。。而且不支持firefox。。。
详见www.socialedge.cn

关于ecommerce中的Shopping cart的显示

ecommerce中的Shopping cart是一个block,可以直接添加block在右侧边栏显示,这个会显示出你购物车的购物情况。

如何让匿名用户也能看到自己的Shopping cart呢,这就需要对它进行设置了。

进入 管理--站点创建--区块 找到Shopping Cart,后面有一个“配置”设置,在“角色制定的可见性设置”里面,几个复选框都不选,就可以对所有用户都显示了,当然包括匿名用户了。

如果不想让购物车为空的时候显示,可以在“区块特定的设置”里面,勾选“Hide block if cart is empty ”就可以了。

==============a scratch of pen of jason==================
www.5iphp.com,我的drupal站点

www.5iphp.com 关于drupal学习、drupal经验、drupal教程的网站

关于ecommerce中产品展示页面里添加产品数量的功能


具体效果如上图所示,具体的代码如下

在product.module模块里的product_nodeapi钩子函数里添加
case 'view'://单个产品的显示页面
/* If we have a pseudo product, add some product specific theming to it. */
if ($node->type == 'product' && $a4) {
$breadcrumb[] = l(t('Home'), '');
$breadcrumb[] = l(t('Product'), 'product');
$node->content['products_add'] = array(
'#value' => drupal_get_form('products_add_form',$node->nid).''.$_SESSION['message'].'',
'#weight' => 2,
);
$_SESSION['message']=NULL;
drupal_set_breadcrumb($breadcrumb);
}

然后在这个模块的最后面添加products_add_form等两个函数

function products_add_form($nid){
$form['products'] = array(
'#type' => 'textfield',
'#size' => 5,
'#default_value' => 1,
'#required' => TRUE,
'#prefix' => '',
);
$form['nid'] = array(
'#type' => 'hidden',
'#value' => $nid,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'add to cart',
'#prefix' => '',
'#suffix' => '',
);
return $form;
}
function products_add_form_submit($form_id, $form_values){
$_SESSION['message'] = NULL;
$sql = "SELECT * FROM {ec_cart} WHERE cookie_id=".cart_get_id()." AND nid=".$form_values['nid'].";";
$res = db_query($sql);
if($arra = db_fetch_array($res)){
$qty = $arra['qty']+$form_values['products'];
db_query("UPDATE {ec_cart} SET qty=".$qty.",changed=".time()." WHERE cookie_id=".cart_get_id()." AND nid=".$form_values['nid'].";");
$_SESSION['message'] = "continue shopping";
}
else{
$qty = $form_values['products'];
db_query("INSERT INTO {ec_cart}(cookie_id, nid, qty, changed, data) VALUES ('%s', %d, %d, %d, '%s')",cart_get_id(), $form_values['nid'], $qty, time(), '');
$_SESSION['message'] = "continue shopping";
}
}

==============a scratch of pen of jason==================
www.5iphp.com,我的drupal站点

www.5iphp.com 关于drupal学习、drupal经验、drupal教程的网站

持续关注中......

写的很好,一直对这个模块感兴趣; 现在还没研究到,先留着以后参考..
E-Commerce可以说是drupal模块里最庞大的一个了,比drupal整个核心都大;装上后有点小驴拉大车的感觉:)
另外想询问一下这个模块组织的内容是独立的吗? 还是靠drupal的node 来组织成节点类型?

是靠drupal的node

是靠drupal的node 来组织成节点类型的

www.5iphp.com 关于drupal学习、drupal经验、drupal教程的网站

ecommerce核心钩子的位置

ecommerce-》docs-》developer-》hooks-》core.php

其他的ecommerce模块里,很多用了这些核心的钩子函数

www.5iphp.com 关于drupal学习、drupal经验、drupal教程的网站

谢谢! 那么利用这个模

谢谢!
那么利用这个模块发布的产品信息也都是储存在node和node_revisions表里吗?

是的

你说的没错!

www.5iphp.com 关于drupal学习、drupal经验、drupal教程的网站

本来我还对这个模块

本来我还对这个模块期望很大,想把它改成多用户商城,现在看来是没法指望它了..我看了drupal几个电子商务模块ubercart,zencart,order也都是基于node的;如果做单用户商城我建议用后面两个,比较简单点...

如何修改ecommerce选择的信用卡的名字


如何在每个credit card 后面填上必要的信息呢?
只举一个例子说明:
比如第一个Credit Card(authorize_net)
首先找到\ecommerce\contrib\authorize_net文件夹下的authorize_net.module模块
修改为
/**
* Implementation of hook_paymentapi().
*/
function authorize_net_paymentapi(&$txn, $op) {
switch ($op) {
case 'display name':
return t('Credit Card(authorize_net)');
case 'payment page':
return authorize_net_goto($txn);
}
}
这样就可以了,其他的信用卡名字修改类似。

为什么要修改这个模块呢?是因为查看到了\ecommerce\docs\developer\hooks文件夹下的core.php这个核心模块中
function hook_checkoutapi(&$txn, $op, $arg3 = NULL, $arg4 = NULL) {
$output = '';
switch ($op) {
case 'form':
if ($form = payment_view_methods()) {
drupal_set_title(t('Please select a payment method'));
$form[] = array(
'#type' => 'submit',
'#value' => t('Continue'),
);
return $form;
}
else {
foreach (payment_get_methods() as $module) {
if (module_invoke($module, 'paymentapi', $txn, 'display name')) {
$txn->payment_method = $module;
break;
}
}
return false;
}
钩子函数hook_checkoutapi在form操作的时候调用module_invoke($module, 'paymentapi', $txn, 'display name'),也就是调用paymentapi的钩子。

==============a scratch of pen of jason==================
www.5iphp.com,我的drupal站点

www.5iphp.com 关于drupal学习、drupal经验、drupal教程的网站

ecommerce的产品展示页面是product_nodeapi钩子函数显示的

function product_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {

case 'view'://单个产品的显示页面xww
//正准备将节点展示给用户。将在钩子hook_view()之后调用该动作,所以模块可以假定节点已被过滤并且现在包含的为HTML。
//当展示一个节点并且$op为view时,$a3 将为$teaser,而 $a4将为$page
// If we have a pseudo product, add some product specific theming to it.
if ($node->type == 'product' && $a4) {
$breadcrumb[] = l(t('Home'), '');
$breadcrumb[] = l(t('Product'), 'product');
$node->content['products_add'] = array(
'#value' => drupal_get_form('products_add_form',$node->nid).''.$_SESSION['message'].'',
'#weight' => 2,
);
$_SESSION['message']=NULL;
drupal_set_breadcrumb($breadcrumb);
}
if ($node->ptype) {
$node->content['price'] = array(
'#value' => theme('product_price', $node),
'#weight' => 1,
);
$node->content['field_marketprice'] = array(//市场价格的表现形式xww
'#value' => theme('product_marketPrice', $node),
'#weight' => 1,
);
if ($a4 && !variable_get('product_cart_addition_by_link', 1)) {
$node->content['cart'] = array(
'#value' => drupal_get_form('product_cart_form', $node),
'#weight' => 10,
);
}
}
//print_r($node);
break;

}

以上的函数决定了product展示的页面,这个函数在product.module模块里

==============a scratch of pen of jason==================
www.5iphp.com,我的drupal站点

www.5iphp.com 关于drupal学习、drupal经验、drupal教程的网站

ecommerce中如何添加产品到购物车里

添加产品到购物车里只需要知道node的id就可以了

下面这个实例是添加产品到一个购物车里,购物车图片是自己做的图片

$cartImage_dir = 图片的路径;//得到图片路径
$output = l($cartImage_dir,"cart/add/{$node->nid}",null,variable_get('product_cart_is_destination', 0) ? NULL : drupal_get_destination(), NULL, null,true).'';//得到购物车对应的nid,并且可以点击购物车图片,添加产品到购物车里

以上修改的代码参考了参考了product.module的product_link里面的$links['add_to_cart']的代码
$links['add_to_cart'] = array(
'title' => t('Add to cart'),
'href' => "cart/add/{$node->nid}",
'attributes' => array('class' => 'cart_link', 'title' => t('Add this item to your shopping cart.')),
'query' => variable_get('product_cart_is_destination', 0) ? NULL : drupal_get_destination()
);//query是指点击完购物车以后,返回的页面

www.5iphp.com 关于drupal学习、drupal经验、drupal教程的网站

ecommerce里常用的theme_box

/**
* Return a themed box.
*
* @param $title
* The subject of the box.
* @param $content
* The content of the box.
* @param $region
* The region in which the box is displayed.
* @return
* A string containing the box output.
*/
function theme_box($title, $content, $region = 'main') {
$output = ''. $title .''. $content .'';
return $output;
}

例如:

function theme_ec_anon_review_form(&$form) {
global $user;
$screens = checkout_get_screens();
$screen = array_search('ec_anon', $screens);
if (!$user->uid) {
$changeurl = ($screen !== FALSE ? ' '. l(t('(change)'), 'cart/checkout', array(), "op={$screen}&". drupal_get_destination()) : '');
}
else {
$changeurl = ' '. l(t('(change)'), 'user/'. $user->uid .'/edit', array(), drupal_get_destination());
}
return theme('box', t('Email address'), drupal_render($form['mail']) . $changeurl);
}

最后的返回是theme_box

又例如:

function theme_coupon_review_form($form) {
if ($form['coupons']) {
$header = array(
array('data' => t('Coupon No.')),
array('data' => t('Discount')),
'',
);
foreach (element_children($form['coupons']) as $key) {
$rows[] = array(
array('data' => drupal_render($form['coupons'][$key]['coupon_no'])),
array('data' => drupal_render($form['coupons'][$key]['discount']), 'align' => 'right'),
array('data' => drupal_render($form['coupons'][$key]['options'])),
);
}
$output.= theme('table', $header, $rows);
}
$output.= '';
$output.= drupal_render($form);
$output.= '';
return theme('box', t('Redeem Coupon/Gift Certificates'), $output);
}

www.5iphp.com 关于drupal学习、drupal经验、drupal教程的网站

再谈ecommerce的图片提交按钮

关于怎么样制作一个图片的提交按钮,前面的文章已经介绍,不做过多解释了。

下面要谈一下关于图片提交按钮不起作用的问题。

问题描述:

做了个图片提交按钮以后,点击提交,总是不起作用,在name_form_submit($form_id, $form_values),也不能输出$form_values的值。

问题解决:

后来发现是我的theme里面集成的图片提交按钮,代码如下:
$content .= drupal_render($form['submit']);
这样虽然把图片按钮显示出来了,但是查看输出页面的源码会发现,在form里,没有输出

这样的话,导致form不能提交。

修改方式如下:
$content .= drupal_render($form['submit']);
$content .= drupal_render($form['form_token']);
$content .= drupal_render($form['form_id']);
加上这两个输出,提交按钮就正常了。

==============a scratch of pen of jason==================
www.5iphp.com,我的drupal站点

www.5iphp.com 关于drupal学习、drupal经验、drupal教程的网站

ecommerce中如何修改默认的快递时间

在ecommerce/tangible/tangible.module中修改
function tangible_productapi(&$node, $op, $a3 = null, $a4 = null)函数中的

$form['availability'] = array(
'#type' => 'select',
'#title' => t("Availability estimate"),
'#default_value' => variable_get($node->availability,3),
'#options' => availability_build_messages(),
'#description' => t("How long it will take this item to leave the fulfillment center once the order has been placed?"),
);

这样的话,默认的值是Usually ships in 2-3 days,这个默认值从下面的函数中得到

function availability_build_messages() {
return array(
1 => t('--none--'),
2 => t('Usually ships in 24 hours.'),
3 => t('Usually ships in 2-3 days.'),
4 => t('Usually ships in 1-2 weeks.'),
5 => t('Usually ships in 4-6 weeks.'),
);
}

==============a scratch of pen of jason==================
www.5iphp.com,我的drupal站点

www.5iphp.com 关于drupal学习、drupal经验、drupal教程的网站

问个问题

Invoice generation and email notifications (发票的生成和email通知) 具体是怎么设置的

发票的生成这块,我

发票的生成这块,我们没做,email的通知,你只要在那个邮箱设置里写上你自己的email邮箱就可以了
==============a scratch of pen of jason==================
www.5iphp.com,我的drupal站点

www.5iphp.com 关于drupal学习、drupal经验、drupal教程的网站