[ic] Totally items in cart

Ed LaFrance interchange-users@interchange.redhat.com
Thu Sep 6 12:00:01 2001


At 08:54 AM 09/06/2001 -0500, you wrote:
>I have added a 'shipping' field to the standard demo products table. I am
>attempting to total the shipping values of all the items in the cart when a
>person views their shopping cart. This is my code:
>
><snip>
>                         [perl arg="carts"]
>                            $ship_total = 0;
>
>                            # Loop over all items in the main cart
>                            foreach my $item ( @{$Safe{'carts'}->{'main'}} )
>{
>                               # Total up all the shipping costs
>                               $ship_total = $ship_total +
>$item->{'shipping'};
>                            }
>                            return ("Shipping: $ship_total");
>                         [/perl]
></snip>
>
>This returns 'Shipping: 0'. Am I doing something wrong with my calculation?
>
>Any help is greatly appreciated.
>Chad

The shipping value wouldn't be stored in the cart unless you had setup your 
catalog to treat it as a modifier and modified order functions to insert 
it.  To do what you want you could try something like:

[set total_shipping]0[/set]
[item-list]
         [seti total_shipping][calc]
                 [scratch total_shipping] + ([item-field shipping] * 
[item-quantity])
         [/calc][/seti]
[/item-list]
...
Shipping: [currency][scratch total_shipping][/currency]

- Ed L.




===============================================================
New Media E.M.S.               Software Solutions for Business
463 Main St., Suite D          eCommerce | Consulting | Hosting
Placerville, CA  95667         edl@newmediaems.com
(530) 622-9421                 http://www.newmediaems.com
(866) 519-4680 Toll-Free       (530) 622-9426 Fax
===============================================================