简体   繁体   English

在venuemart joomla 2.5上显示购物车中的物品数量?

[英]display the number of items in the cart on virtuemart joomla 2.5?

I'm using the code below to display a number based on the number of items in the cart. 我正在使用以下代码根据购物车中的物品数量显示数字。 If there's 1 item, then the number 1 is generated, 2 items and 2 is displayed etc etc. 如果有1个项目,则生成数字1,显示2个项目,并显示2,依此类推。

the problem is that it displays the quantity for the product with an id of [1]. 问题是它显示ID为[1]的产品数量。 how can change this to make it work for all product ids? 如何更改此设置以使其适用于所有产品ID?

<?php $array = unserialize($_SESSION['__vm']['vmcart']); 
$amount = $array->products[1]->amount;
if ($amount != 0){ echo $amount; } else { echo 0; } ?>

the [1] is the product id. [1]是产品ID。 how do i change it to accept all product ids? 我如何更改它以接受所有产品ID?

Are you wanting to loop through all products? 您是否要遍历所有产品? Something like ... 就像是 ...

<?php 
    $array = unserialize($_SESSION['__vm']['vmcart']); 
    foreach($array->products as $product){
        $amount = $product->amount;
        if ($amount != 0){ echo $amount; } else { echo 0; } 
    }
?>

Adding all products ... 添加所有产品...

<?php 
    $array = unserialize($_SESSION['__vm']['vmcart']); 
    $total = 0;
    foreach($array->products as $product){
        $total += $product->amount;
    }
    echo "Total Products: " . $total;
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM