如何在Joomla 2.5 virtuemart上显示购物车中的商品数量?

时间:2012-10-29 15:29:08

标签: php mysql arrays session joomla

我发现这个php的peice从vm会话打印出一个数组:

<?php print_r(unserialize($_SESSION['__vm']['vmcart'])); ?>

这是打印出来的数组:

stdClass Object
(
[products] =&gt; Array
    (
        [1] =&gt; stdClass Object
            (
                [virtuemart_manufacturer_id] =&gt; Array
                    (
                    )

                [slug] =&gt; basic
                [published] =&gt; 1
                [virtuemart_product_price_id] =&gt; 1
                [virtuemart_product_id] =&gt; 1
                [virtuemart_shoppergroup_id] =&gt; 
                [product_price] =&gt; 10.00000
                [override] =&gt; 
                [product_override_price] =&gt; 0.00000
                [product_tax_id] =&gt; 0
                [product_discount_id] =&gt; 0
                [product_currency] =&gt; 52
                [virtuemart_vendor_id] =&gt; 1
                [product_parent_id] =&gt; 0
                [product_sku] =&gt; 001
                [product_name] =&gt; Basic
                [product_s_desc] = d
                [product_weight] =&gt; 0.0000
                [product_weight_uom] =&gt; KG
                [product_length] =&gt; 0.0000
                [product_width] =&gt; 0.0000
                [product_height] =&gt; 0.0000
                [product_lwh_uom] =&gt; M
                [product_in_stock] =&gt; 0
                [product_ordered] =&gt; 2
                [product_sales] =&gt; 0
                [product_unit] =&gt; KG
                [product_packaging] =&gt; 0.0000
                [min_order_level] =&gt; 
                [max_order_level] =&gt; 
                [virtuemart_media_id] =&gt; Array
                    (
                    )

                [categories] =&gt; Array
                    (
                        [0] =&gt; 1
                    )

                [virtuemart_category_id] =&gt; 1
                [category_name] =&gt; Policies
                [link] =&gt; /locksure-upgrade/index.php/our-policies/policies/basic-detail
                [packaging] =&gt; 0
                [quantity] =&gt; 2
                [amount] =&gt; 2
                [url] =&gt; /locksure-upgrade/index.php/our-policies/policies/basic-detail
                [customfields] =&gt; 
                [cart_item_id] =&gt; 1
            )

    )

[vendorId] =&gt; 1
[lastVisitedCategoryId] =&gt; 0
[virtuemart_shipmentmethod_id] =&gt; 1
[virtuemart_paymentmethod_id] =&gt; 1
[automaticSelectedShipment] =&gt; 1
[automaticSelectedPayment] =&gt; 1
[order_number] =&gt; 
[BT] =&gt; Array
    (
        [company] =&gt; 
        [email] =&gt; sean@rmspr.co.uk
        [title] =&gt; 
        [first_name] =&gt; lock
        [middle_name] =&gt; 
        [last_name] =&gt; sure
        [address_1] =&gt; 20 market street
        [address_2] =&gt; 
        [zip] =&gt; wa141pf
        [city] =&gt; altrincham
        [virtuemart_country_id] =&gt; 222
        [virtuemart_state_id] =&gt; 65
        [phone_1] =&gt; 01619273131
        [phone_2] =&gt; 
        [fax] =&gt; 
    )

[ST] =&gt; 0
[tosAccepted] =&gt; 
[customer_comment] =&gt; 
[couponCode] =&gt; 
[cartData] =&gt; Array
    (
        [duty] =&gt; 1
        [payment] =&gt; 0
        [paymentName] =&gt; <span class="vmpayment_name">payment</span>
        [totalProduct] =&gt; 1
        [DBTaxRulesBill] =&gt; Array
            (
            )

        [taxRulesBill] =&gt; Array
            (
            )

        [DATaxRulesBill] =&gt; Array
            (
            )

        [shipmentName] =&gt; <span class="vmshipment_name">shipment</span>
    )

[lists] =&gt; Array
    (
        [shipTo] =&gt; 
<input name="shipto" id="shipto1" value="1" checked="checked" type="radio">
<label for="shipto1" id="shipto1-lbl" class="radiobtn"><a href="/locksure-upgrade/index.php/our-policies/user/editaddresscartBT?virtuemart_userinfo_id=1">- Default (Same as Billing)</a><br></label>

        [billTo] =&gt; 1
    )

[pricesUnformatted] =&gt; Array
    (
        [basePrice] =&gt; 20
        [basePriceWithTax] =&gt; 0
        [discountedPriceWithoutTax] =&gt; 0
        [salesPrice] =&gt; 20
        [taxAmount] =&gt; 0
        [salesPriceWithDiscount] =&gt; 0
        [discountAmount] =&gt; 0
        [priceWithoutTax] =&gt; 20
        [subTotalProducts] =&gt; 0
        [1] =&gt; Array
            (
                [costPrice] =&gt; 10.00000
                [basePrice] =&gt; 10
                [basePriceVariant] =&gt; 10
                [basePriceWithTax] =&gt; 0
                [discountedPriceWithoutTax] =&gt; 0
                [priceBeforeTax] =&gt; 10
                [salesPrice] =&gt; 10
                [taxAmount] =&gt; 0
                [salesPriceWithDiscount] =&gt; 0
                [salesPriceTemp] =&gt; 10
                [unitPrice] =&gt; 0
                [discountAmount] =&gt; 0
                [priceWithoutTax] =&gt; 10
                [variantModification] =&gt; 0
                [DBTax] =&gt; Array
                    (
                    )

                [Tax] =&gt; Array
                    (
                    )

                [VatTax] =&gt; Array
                    (
                    )

                [DATax] =&gt; Array
                    (
                    )

                [subtotal_with_tax] =&gt; 20
                [subtotal_tax_amount] =&gt; 0
                [subtotal_discount] =&gt; 0
                [subtotal] =&gt; 20
            )

        [discountBeforeTaxBill] =&gt; 0
        [withTax] =&gt; 20
        [discountAfterTax] =&gt; 20
        [shipmentValue] =&gt; 0
        [shipmentTax] =&gt; 0
        [shipmentTotal] =&gt; 0
        [salesPriceShipment] =&gt; 0
        [shipment_calc_id] =&gt; 0
        [cost] =&gt; 0
        [paymentValue] =&gt; 0
        [paymentTax] =&gt; 0
        [paymentTotal] =&gt; 0
        [salesPricePayment] =&gt; 0
        [payment_calc_id] =&gt; 0
        [billSub] =&gt; 20
        [billDiscountAmount] =&gt; 0
        [billTaxAmount] =&gt; 0
        [billTotal] =&gt; 20
    )

[pricesCurrency] =&gt; 52
[paymentCurrency] =&gt; 52
[_inCheckOut] =&gt; 1
[_dataValidated] =&gt; 
[_confirmDone] =&gt; 
[STsameAsBT] =&gt; 0
)

从该数组中我将如何提取购物车中的商品数量?如果它可能吗?

1 个答案:

答案 0 :(得分:1)

使用以下代码为任何需要它的人解决:

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