函数hook_cart_display()位于uc_cart.module模块中:
<?php
hook_cart_display($item)
?>
描述:
产品类型模块决定了哪些节点可以被添加到购物车中。而购物车通过使用这个钩子来决定如何显示这个钩子。对于产品包来说,这一点就非常重要了,因为,即便是它代表了多个项目,它在购物车中可能也就显示为一个单元。
参数:
· $item - 购物车中要显示的项目。
返回值:
一个表单数组,包含了以下元素:
键 |
#type |
#value |
nid |
value |
$item的节点id |
module |
value |
实现了这个钩子,并且与$item所代表的节点对应的模块 |
remove |
checkbox |
如果选中的话,那么该项$item将被从购物车中删除。 |
options |
markup |
显示额外信息的主体化了的标识文本markup(通常为一个无须列表) |
title |
markup |
$item所要显示的标题 |
#total |
float |
$item的价格。注意,这里'#' 意味着这不是一个表单元素,而仅仅是一个保存在表单数组中的值。 |
data |
hidden |
序列化了的d $item->data |
qty |
textfield |
购物车中该项的数量。当点击了“更新购物车”时,客户输入的数量将被保存到购物车中。 |
Example:
<?php
function uc_product_cart_display($item){
$node = node_load($item->nid);
$element = array();
$element['nid'] = array('#type' => 'value', '#value' => $node->nid);
$element['module'] = array('#type' => 'value', '#value' => 'uc_product');
$element['remove'] = array('#type' => 'checkbox');
$op_names = '';
if (module_exists('uc_attribute')){
$op_names = "<ul class=\"cart-options\">\n";
foreach ($item->options as $option){
$op_names .= '<li>'. $option['attribute'] .': '. $option['name'] ."</li>\n";
}
$op_names .= "</ul>\n";
}
$element['options'] = array('#value' => $op_names);
$element['title'] = array(
'#value' => l($node->title, 'node/'. $node->nid),
);
$element['#total'] = $item->price * $item->qty;
$element['data'] = array('#type' => 'hidden', '#value' => serialize($item->data));
$element['qty'] = array(
'#type' => 'textfield',
'#default_value' => $item->qty,
'#size' => 3,
'#maxlength' => 3
);
return $element;
}
?>