[英]Drupal Ubercart how to get cart total?
I used Ubercart module for my shopping cart site. 我在购物车网站上使用了Ubercart模块。 I want to get the cart total on the checkout page? 我想在结帐页面上获得购物车总额吗? I research on google but I can't able to find any proper help for getting the cart total. 我在Google上进行了研究,但找不到任何适当的帮助来获取购物车总额。
I used below code but it returns empty. 我用下面的代码,但它返回空。
http://api.ubercart.me/api/drupal/ubercart%21uc_cart%21uc_cart.module/function/uc_cart_block_view/7 http://api.ubercart.me/api/drupal/ubercart%21uc_cart%21uc_cart.module/function/uc_cart_block_view/7
$data = uc_cart_block_view();
print_r($data);
Please help me how can I get the cart total on check out page. 请帮助我如何在结帐页面上获得购物车总额。
I don't think there is a native ubercart function. 我认为没有本地ubercart函数。 However you can peek inside the uc_cart_checkout() function to see how the total is displayed on the checkout page. 但是,您可以在uc_cart_checkout()函数中进行查看,以查看总计在结帐页面上的显示方式。
I created my own function to do this based on the method used in uc_cart_checkout: 我基于uc_cart_checkout中使用的方法创建了自己的函数来执行此操作:
function mycustommodule_uc_cart_total($oid = NULL){
$items = uc_cart_get_contents($oid);
$subtotal = 0;
if (is_array($items) && count($items) > 0) {
foreach ($items as $item) {
$data = module_invoke($item->module, 'uc_cart_display', $item);
if (!empty($data)) {
$subtotal += $data['#total'];
}
}
}
return $subtotal;
}//end function
Note, this only tallies the cart item totals and does not include things like shipping or other additional line items. 请注意,这只会计算购物车中的商品总计,不包括运输或其他其他订单项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.