Index: openacs-4/packages/ecommerce/www/shopping-cart.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ecommerce/www/shopping-cart.adp,v diff -u -r1.11 -r1.12 --- openacs-4/packages/ecommerce/www/shopping-cart.adp 24 Feb 2005 13:33:14 -0000 1.11 +++ openacs-4/packages/ecommerce/www/shopping-cart.adp 10 Aug 2008 11:34:05 -0000 1.12 @@ -8,7 +8,7 @@ for @first_names@ @last_name@ (if you're not @first_names@ @last_name@, - click here). + click here).
@@ -28,7 +28,7 @@ - @in_cart.product_name@ + @in_cart.product_name;noquote@ @@ -57,22 +57,79 @@ - Total: + +Total: @product_counter@   - @pretty_total_price@ + + +** + +@pretty_total_price@ + + + + + + + + + + @shipping_options@ + @total_reg_shipping_price@standard + + + + + + + + + + +   + @total_exp_shipping_price@express + + + + + + + + + + + +   + + $0.00 pickup + + + + + + + +

** - Special message for items marked as @display_price_of_zero_as@

+ +
+ - Residents of @tax_entries.state@, please add @tax_entries.pretty_tax@ tax. +

Residents of @tax_entries.state@, @tax_entries.pretty_tax@ sales tax will be added to your order on checkout.*

+ + + @shipping_options;noquote@ +
@@ -106,3 +163,5 @@
+ + Index: openacs-4/packages/ecommerce/www/shopping-cart.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ecommerce/www/shopping-cart.tcl,v diff -u -r1.16 -r1.17 --- openacs-4/packages/ecommerce/www/shopping-cart.tcl 9 Aug 2008 10:31:04 -0000 1.16 +++ openacs-4/packages/ecommerce/www/shopping-cart.tcl 10 Aug 2008 11:34:05 -0000 1.17 @@ -6,7 +6,7 @@ @author ported by Jerry Asher (jerry@theashergroup.com) @author revised by Bart Teeuwisse (bart.teeuwisse@thecodemill.biz) @revision-date April 2002 - + } { usca_p:optional product_id:optional @@ -55,14 +55,92 @@ # where o.order_id=i.order_id # and o.user_session_id=:user_session_id and o.order_state='in_basket'"] +# calculate shipping charge options when not using shipping-gateway, +# and then include the value with each option (for an informed choice) + +# mainly from process-order-quantity-shipping.tcl + +# set initial values for itemization loop +db_1row get_ec_admin_settings " + select nvl(base_shipping_cost,0) as base_shipping_cost, + nvl(default_shipping_per_item,0) as default_shipping_per_item, + nvl(weight_shipping_cost,0) as weight_shipping_cost, + nvl(add_exp_base_shipping_cost,0) as add_exp_base_shipping_cost, + nvl(add_exp_amount_per_item,0) as add_exp_amount_per_item, + nvl(add_exp_amount_by_weight,0) as add_exp_amount_by_weight + from ec_admin_settings" + +set last_product_id 0 set product_counter 0 set total_price 0 set currency [parameter::get -parameter Currency] -set max_quantity_length [string length [parameter::get -parameter CartMaxToAdd]] +set max_add_quantity_length [string length [parameter::get -parameter CartMaxToAdd]] +set offer_express_shipping_p [parameter::get -parameter ExpressShippingP] +set offer_pickup_option_p [parameter::get -parameter PickupP] +set total_reg_shipping_price 0 +set total_exp_shipping_price 0 +set no_shipping_options "t" +# Check if a shipping gateway has been selected. +set shipping_gateway [parameter::get -parameter ShippingGateway] +set shipping_gateway_in_use [acs_sc_binding_exists_p ShippingGateway $shipping_gateway] +set shipping_address_id 0 +set display_price_of_zero_as [parameter::get -parameter DisplayPriceOfZeroAs] +if { [string equal $display_price_of_zero_as "0.00"] } { + set display_zero_as_special 0 +} else { + set display_zero_as_special 1 +} +set includes_display_zero_as_items 0 +if { $shipping_gateway_in_use} { + #this section mainly from select-shipping.tcl + + # Replace the default ecommerce shipping calculations with the + # charges from the shipping gateway, which contains + # both the shipping service level and the associated total + # charges. Requries zipcode and country, so + # user needs to be logged in too. + + if { $user_id != 0 } { + set shipping_address_ids [db_list get_shipping_address_ids " + select address_id + from ec_addresses + where user_id=:user_id + and address_type = 'shipping'" ] + + if { [llength $shipping_address_ids] > 1 } { + # the max valued id is most likely the newest id (no last used date field available) + set shipping_address_id [ec_max_of_list $shipping_address_ids] + } elseif { $shipping_address_ids > 0 } { + set shipping_address_id $shipping_address_ids + } else { + set shipping_address_id 0 + set shipping_options "

We need your shipping address before we can quote a shipping price. You are able to review your order and any shipping charges before confirming an order.

" + } + if { $shipping_address_id > 0 } { + # we have a zipcode and country + db_1row select_shipping_area " + select country_code, zip_code + from ec_addresses + where address_id = :shipping_address_id" + + # Calculate the total value of the shipment. + set shipment_value 0 + } + } else { + # user_id == 0 + set shipping_options "

If you were logged in, we could show you any associated shipping charges

" + } +} + + +# adding some fields to handle calculating shipping prices +# p.no_shipping_avail_p, p.shipping, p.shipping_additional, p.weight +# basically collect shipping information for any items where ec_products.no_shipping_avail_p = 't' + db_multirow -extend { line_subtotal } in_cart get_products_in_cart " - select p.product_name, p.one_line_description, p.product_id, count(*) as quantity, u.offer_code, i.color_choice, i.size_choice, i.style_choice, '' as price + select p.product_name, p.one_line_description, p.no_shipping_avail_p, p.shipping, p.shipping_additonal, p.weight, p.product_id, count(*) as quantity, u.offer_code, i.color_choice, i.size_choice, i.style_choice, '' as price from ec_orders o join ec_items i on (o.order_id=i.order_id) join ec_products p on (i.product_id=p.product_id) @@ -71,21 +149,26 @@ where usoc.user_session_id=:user_session_id) u on (p.product_id=u.product_id) where o.user_session_id=:user_session_id and o.order_state='in_basket' - group by p.product_name, p.one_line_description, p.product_id, u.offer_code, i.color_choice, i.size_choice, i.style_choice" { + group by p.product_name, p.one_line_description, p.no_shipping_avail_p, p.shipping, p.shipping_additional, p.weight, p.product_id, u.offer_code, i.color_choice, i.size_choice, i.style_choice" { set line_subtotal "$quantity" } -for {set i 1} {$i <= [multirow size in_cart]} {incr i} { +for {set i 1} {$i <= [template::multirow size in_cart]} {incr i} { - set product_name [multirow get in_cart $i product_name] - set one_line_description [multirow get in_cart $i one_line_description] - set product_id [multirow get in_cart $i product_id] - set quantity [multirow get in_cart $i quantity] - set offer_code [multirow get in_cart $i offer_code] - set color_choice [multirow get in_cart $i color_choice] - set size_choice [multirow get in_cart $i size_choice] - set style_choice [multirow get in_cart $i style_choice] + set product_name [template::multirow get in_cart $i product_name] + set one_line_description [template::multirow get in_cart $i one_line_description] + set product_id [template::multirow get in_cart $i product_id] + set no_shipping_avail_p [template::multirow get in_cart $i no_shipping_avail_p] + set shipping [template::multirow get in_cart $i shipping] + set shipping_additional [template::multirow get in_cart $i shipping_additional] + set weight [template::multirow get in_cart $i weight] + set quantity [template::multirow get in_cart $i quantity] + set offer_code [template::multirow get in_cart $i offer_code] + set color_choice [template::multirow get in_cart $i color_choice] + set size_choice [template::multirow get in_cart $i size_choice] + set style_choice [template::multirow get in_cart $i style_choice] + set max_quantity_length [max $max_add_quantity_length [string length $quantity]] # Deletions are done by product_id, color_choice, size_choice, # style_choice, not by item_id because we want to delete the # entire quantity of that product. Also print the price for a @@ -100,28 +183,120 @@ set lowest_price_and_price_name [ec_lowest_price_and_price_name_for_an_item $product_id $user_id $offer_code] set lowest_price [lindex $lowest_price_and_price_name 0] + if { $lowest_price == 0 && $display_zero_as_special } { + set includes_display_zero_as_items 1 + } - # Calculate line subtotal for end users - set line_subtotal [ec_pretty_pure_price [expr $quantity * $lowest_price] $currency] - multirow set in_cart $i line_subtotal $line_subtotal + set line_subtotal [ec_pretty_price [expr $quantity * $lowest_price] $currency] + template::multirow set in_cart $i line_subtotal $line_subtotal + if { [string equal $no_shipping_avail_p "f"] && !$shipping_gateway_in_use} { + # at least one thing is shippable, begin calculating ship value(s) + set no_shipping_options "f" + + # Calculate shipping for line item + set first_instance 1 + set shipping_prices_for_first_line_item [ec_shipping_prices_for_one_item_by_rate $product_id $shipping $shipping_additional $default_shipping_per_item $weight $weight_shipping_cost $first_instance $add_exp_amount_per_item $add_exp_amount_by_weight] + set total_reg_shipping_price [expr $total_reg_shipping_price + [lindex $shipping_prices_for_first_line_item 0]] + set total_exp_shipping_price [expr $total_exp_shipping_price + [lindex $shipping_prices_for_first_line_item 1]] + + if { $quantity > 1 } { + set first_instance 0 + set shipping_prices_for_more_line_items [ec_shipping_prices_for_one_item_by_rate $product_id $shipping $shipping_additional $default_shipping_per_item $weight $weight_shipping_cost $first_instance $add_exp_amount_per_item $add_exp_amount_by_weight] + set total_reg_shipping_price [expr $total_reg_shipping_price + ( [lindex $shipping_prices_for_more_line_items 0] * ( $quantity - 1 ) ) ] + set total_exp_shipping_price [expr $total_exp_shipping_price + ( [lindex $shipping_prices_for_more_line_items 1] * ( $quantity - 1 ) ) ] + + } + } elseif { $shipping_gateway_in_use && $shipping_address_id > 0 && [string equal $no_shipping_avail_p "f"] } { + set shipment_value [expr $shipment_value + [lindex [ec_lowest_price_and_price_name_for_an_item $product_id $user_id $offer_code] 0]] + } + # Add the price of the item to the total price set total_price [expr $total_price + ($quantity * $lowest_price)] incr product_counter $quantity - # following line added according to bug 643 at openacs.org - # http://openacs.org/bugtracker/openacs/com/ecommerce/bug?bug%5fnumber=643 - multirow set in_cart $i delete_export_vars $delete_export_vars + template::multirow set in_cart $i delete_export_vars $delete_export_vars + template::multirow set in_cart $i price "[lindex $lowest_price_and_price_name 1]:  [ec_pretty_price [lindex $lowest_price_and_price_name 0] $currency]" - multirow set in_cart $i price "[lindex $lowest_price_and_price_name 1]:  [ec_pretty_pure_price [lindex $lowest_price_and_price_name 0] $currency]" - } # Add adjust quantities line if there are products in the cart. set pretty_total_price [ec_pretty_pure_price $total_price $currency] +if { $shipping_gateway_in_use && $shipping_address_id > 0} { + + set weight_unit_of_measure [parameter::get -parameter WeightUnits] + + set shipping_options "" + + # Get the list of services and their charges + + set rates_and_services [lsort -index 1 -real \ + [acs_sc_call "ShippingGateway" "RatesAndServicesSelection" \ + [list "" "" "$country_code" "$zip_code" "$shipment_value" "$currency" "" "$weight_unit_of_measure"] "$shipping_gateway"]] + + # Present the available shipping services to the user + + foreach service $rates_and_services { + array set rate_and_service $service + set total_charges $rate_and_service(total_charges) + set service_code $rate_and_service(service_code) + set service_description [acs_sc_call "ShippingGateway" "ServiceDescription" "$service_code" "$shipping_gateway"] + set gateway_shipping_default_price $total_charges + append shipping_options " + " + } + append shipping_options "
Shipping method:

+ $service_description + + [string map {USD $} $currency] + + $total_charges +
" +} + +if { !$shipping_gateway_in_use } { + # Rate based shipping calculations + # 3. Determine base shipping costs that are separate from items + + # set base shipping charges + # reset standard to special shipping rate based on price + set order_shipping_cost [expr { [ecds_base_shipping_price_from_order_value $total_price ] + $base_shipping_cost } ] + + set shipping_method_standard $order_shipping_cost + + # Add on the extra base cost for express shipping + set shipping_method_express [expr $order_shipping_cost + $add_exp_base_shipping_cost] + + # 4. set total costs for each shipping option + set total_shipping_price_default $total_reg_shipping_price + set total_reg_shipping_price [ec_pretty_pure_price [expr $total_reg_shipping_price + $shipping_method_standard] $currency "t"] + + set total_exp_shipping_price [ec_pretty_pure_price [expr $total_exp_shipping_price + $shipping_method_express] $currency "t"] + set shipping_method_pickup [ec_pretty_pure_price 0 $currency "t"] + set shipping_method_no_shipping 0 + + # 5 prepare shipping options to present to user + if { [string equal $no_shipping_options "f" ] } { + + # standard shipping is total_reg_shipping_price + set shipping_options "Shipping is addtional:" + if { $offer_express_shipping_p } { + # express shipping is total_exp_shipping_price + set shipping_options "Shipping is additional, choices are:" + } + if { $offer_pickup_option_p } { + # pickup instead of shipping is shipping_method_pickup + set shipping_options "Shipping is additional, choices are:" + } + } else { + set shipping_options "No shipping options available." + } +} + # List the states that get charged tax. Although not 100% accurate # as shipping might be taxed too this is better than nothing.