VirtueMart Forum

VirtueMart 2 + 3 + 4 => Plugins: Payment, Shipment and others => Topic started by: GJC Web Design on December 01, 2012, 12:11:33 PM

Title: How to access array node on $cart_prices
Post by: GJC Web Design on December 01, 2012, 12:11:33 PM
Hi,

Hope someone can help me with this..

The array $cart_prices is as follows:

Debug Line 1248 $cart_prices

Array
(
    [basePrice] => 48.7
    [basePriceWithTax] => 50.6
    [discountedPriceWithoutTax] => 0
    [salesPrice] => 50.6
    [taxAmount] => 1.9
    [salesPriceWithDiscount] => 0
    [discountAmount] => 0
    [priceWithoutTax] => 48.7
    [subTotalProducts] => 0
    [4Diff] => 0.194649
    [6] => Array
        (
            [costPrice] => 4.99000
            [basePrice] => 4.866232
            [basePriceVariant] => 4.866232
            [basePriceWithTax] => 5.06
            [discountedPriceWithoutTax] => 0
            [priceBeforeTax] => 4.866232
            [salesPrice] => 5.06
            [taxAmount] => 0.193768
            [salesPriceWithDiscount] => 0
            [salesPriceTemp] => 5.06
            [unitPrice] => 0
            [discountAmount] => 0
            [priceWithoutTax] => 4.866232
            [variantModification] => 0
            [DBTax] => Array
                (
                )

            [Tax] => Array
                (
                    [0] => Array
                        (
                            [0] => Alabama
                            [1] => 4.0000
                            [2] => +%
                            [3] => 1
                            [4] => 47
                            [5] =>
                            [6] => 1
                        )

                )

            [VatTax] => Array
                (
                )

            [DATax] => Array
                (
                )

            [subtotal_with_tax] => 50.6
            [subtotal_tax_amount] => 1.9
            [subtotal_discount] => 0
            [subtotal] => 48.7
        )

    [discountBeforeTaxBill] => 0
    [withTax] => 50.6
    [discountAfterTax] => 50.6
    [shipmentValue] => 11
    [shipmentTax] => 0
    [shipmentTotal] => 0
    [salesPriceShipment] => 0
    [shipment_calc_id] => 0
    [cost] => 0
)


How can I access the node  [6] => Array  as this index is always different in each checkout?
(trying to get the tax rate)

Can't even find where this array is formed - appears in cart.php and vmpsplugin.php

Thanks in advance
Title: Re: How to access array node on $cart_prices
Post by: Piero! on February 08, 2013, 17:31:57 PM
As an option:


foreach($cart->products as $productkey => $productvalue) {
        # $cart_prices[$productkey] - this is the node [6] in your example
}


Basically you could get array keys for $cart_prices array from $cart->products array.
Hope this helps.

P.S. Virtuemart management really needs to document their software better  >:(
Title: Re: How to access array node on $cart_prices
Post by: PRO on February 08, 2013, 18:59:09 PM
what are you trying to do?



$cart_prices['salesPrice']

Title: Re: How to access array node on $cart_prices
Post by: GJC Web Design on February 08, 2013, 22:33:58 PM
perfect! Thanks Piero!

@Pro - get the taxation percent applied - had been doing by back calculating but with the small amounts rounding errors can be a problem..
Title: Re: How to access array node on $cart_prices
Post by: Piero! on February 13, 2013, 21:38:10 PM
No problem GJC Web Design, happy to be helpful  ;)