商品總重量用于計算郵費,讓買家容易下判斷。默認的購物車環節有兩個:查看購物車的商品、結算,默認兩個環節都不顯示商品總重量。
默認有個現成的函數的cart_weight_price($type),是把購物車中的單價、重量、數量調出來匯總,模板變量也寫好 了:$formated_weight,只需要定義一下模式,在模板上添加代碼就可以了。不過這種方法只能顯示購物車的總重量,不能顯示單個商品的重量。
$smarty->assign("cart_weight_price",$cart_weight_price);
{$cart_weight_price.formated_weight}
不過這種方法只能顯示購物車的總重量,不能顯示單個商品的重量。如果要顯示單重,沒有現成的函數或代碼,得自己寫一個。
調出單重
$row['goods_weight'] = $GLOBALS['db']-> getOne("select goods_weight from".$GLOBALS['ecs']->table('goods')." where goods_id = ".$row['goods_id']);
計算總重
$total['all_weight'] += $row['goods_weight'] * $row ['goods_number'];
默認都是按克顯示的,可以分成公斤和克分別顯示,大于1公斤的,顯示公斤,小于1公斤的,顯示克,格式化一下重量
$row['goods_weight'] = formated_weight($row['goods_weight']);
$total['all_weight'] = formated_weight($total['all_weight']);
模板代碼:
{$all_weight}
ecshop 購物流程頁面顯示商品總重量
1、打開flow.php
找到
$smarty->assign('shipping_list', $shipping_list);
$smarty->assign('insure_disabled', $insure_disabled);
$smarty->assign('cod_disabled', $cod_disabled);
后面添加代碼:
$smarty->assign('zhongliang', sprintf($_LANG['zhongliang'], $cart_weight_price['formated_weight']));
2、打開 /languages/zh_cn/shopping_flow.php 加上如下代碼
$_LANG['zhongliang'] = '訂單總重量: %s';
3、然后在flow.dwt中調用{$zhongliang}
flow.dwt中的代碼:
<tr>
<td bgcolor="#ffffff" colspan="7" class="f1 f14b">
<!-- {if $discount gt 0} -->{$your_discount}<br /><!-- {/if} -->
{$shopping_money}<!-- {if $show_marketprice} -->,{$market_price_desc} <!--{/if}--> {$zhongliang}</td>
</tr>
<!-- {/if} -->
新聞熱點
疑難解答