Forum OpenACS Q&A: wanna show subtotal price of items in shopping cart

I'm developing ecommerce module of OpenACS 3.x Then I'm trying to
show subtotal price of items in shopping cart as wineaccsess.com
does. Please let me know if somebody have any advice or solitions.
thanks for any help.
There is a pl/pgsql function called ec_total_price(integer) which gives you the subtotal of the order (ie sum of all items before tax and shipping).  You will have to do a query using this function on the order_id.

select ec_total_price($order_id) as subtotal

Hope that helps.

Collapse
3: Mumm... (response to 1)
Posted by k masuo on
Thank you very much for your suggestion. I followed the suggestion in your comment but i cannot fiugre it out yet. if you give me some more details to show "subtotal" at shopping-cart.tcl, i'll very appreciate becaus i'm stucking for how to set up the query at shopping-cart.tcl. here is the same document what i'm working on http://cvs.arsdigita.com/cgi-bin/cvsweb.pl/acs3x/www/ecommerce/ shopping-cart.tcl?rev=3.6&content-type=text/x-cvsweb-markup thanks.

Oops. I misread your post. I didn't see the shopping cart part of your message. The easiest way is to add this code in the while loop:

set subtotal [expr [lindex [ec_lowest_price_and_price_name_for_an_item $product_id $user_id] 0]*$quantity + $subtotal]

you also have to add some code just before the while loop:

set subtotal 0
set product_counter 0
while { ... } {

Anyway, you can use the $subtotal variable and use that in your HTML code.

Now, please note that you would be calling this function twice in shopping-cart.tcl. Once in ec_price_line and once as stated above. It's not the most efficient way to do it, but it is the easiest :) One more thing, you might have to play around with the precision in tcl. Right now, my test cases only show the first decimal point if they hundredths digit is a 0.

Collapse
5: I made it. (response to 1)
Posted by k masuo on

Again thank you very much for your suggestion. Finally, I could figure it out with some improvement from your code in the while loop.

set subtotal [expr [lindex 
[ec_lowest_price_and_price_name_for_an_item $product_id $user_id] 0]*
$quantity + $subtotal]

I replaced this part,[ec_lowest_price_and_price_name_for_an_item $product_id $user_id], like this.

set subtotal [expr [lindex [ec_price_line $db_sub $product_id 
$user_id $offer_code] 0]*$quantity + $subtotal]

Then it worked. Thanks a lot!