Index: openacs-4/packages/ecommerce/www/shopping-cart-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ecommerce/www/shopping-cart-oracle.xql,v diff -u -r1.3.8.1 -r1.3.8.2 --- openacs-4/packages/ecommerce/www/shopping-cart-oracle.xql 8 Mar 2005 06:40:20 -0000 1.3.8.1 +++ openacs-4/packages/ecommerce/www/shopping-cart-oracle.xql 9 Mar 2005 06:02:26 -0000 1.3.8.2 @@ -31,4 +31,16 @@ + + + select i.product_id, i.color_choice, i.size_choice, i.style_choice, count(*) as item_count, u.offer_code + from ec_products p, ec_items i, ec_user_session_offer_codes u + where u.product_id(+)=i.product_id and (u.user_session_id is null or u.user_session_id=:user_session_id) + and i.product_id = p.product_id + and p.no_shipping_avail_p = 'f' + and i.order_id = :order_id + group by i.product_id, i.color_choice, i.size_choice, i.style_choice, u.offer_code + + + Index: openacs-4/packages/ecommerce/www/shopping-cart-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ecommerce/www/shopping-cart-postgresql.xql,v diff -u -r1.3.8.3 -r1.3.8.4 --- openacs-4/packages/ecommerce/www/shopping-cart-postgresql.xql 8 Mar 2005 06:40:20 -0000 1.3.8.3 +++ openacs-4/packages/ecommerce/www/shopping-cart-postgresql.xql 9 Mar 2005 06:02:26 -0000 1.3.8.4 @@ -33,4 +33,16 @@ + + + select i.product_id, i.color_choice, i.size_choice, i.style_choice, count(*) as item_count, u.offer_code + from ec_products p, ec_items i + left join ec_user_session_offer_codes u on (u.product_id = i.product_id and u.user_session_id = :user_session_id) + where i.product_id = p.product_id + and p.no_shipping_avail_p = 'f' + and i.order_id = :order_id + group by i.product_id, i.color_choice, i.size_choice, i.style_choice, u.offer_code + + + 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.9.2.6 -r1.9.2.7 --- openacs-4/packages/ecommerce/www/shopping-cart.adp 8 Mar 2005 06:40:20 -0000 1.9.2.6 +++ openacs-4/packages/ecommerce/www/shopping-cart.adp 9 Mar 2005 06:02:26 -0000 1.9.2.7 @@ -64,47 +64,49 @@ @pretty_total_price@ - + - + - + @shipping_options@ - Standard@total_reg_shipping_price@ + @total_reg_shipping_price@standard - + - +   - Express@total_exp_shipping_price@ + @total_exp_shipping_price@express - + - + - +   - Pickup@shipping_method_pickup@ + @shipping_method_pickup@pickup + + @@ -114,6 +116,9 @@ + + @shipping_options;noquote@ +
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.12.2.5 -r1.12.2.6 --- openacs-4/packages/ecommerce/www/shopping-cart.tcl 8 Mar 2005 06:40:20 -0000 1.12.2.5 +++ openacs-4/packages/ecommerce/www/shopping-cart.tcl 9 Mar 2005 06:02:26 -0000 1.12.2.6 @@ -80,11 +80,56 @@ 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 -# adding some fields to handl calculating shipping prices +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 will be able to review your order and shipping charge before confirming the 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 -# for calculating shipping, we need to know if the order requires shipping -# basically collect shipping information for any items where ec_products.no_shipping_avail_p = 't' +# 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.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 @@ -136,7 +181,7 @@ 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"] } { + 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" @@ -153,55 +198,90 @@ 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} { + 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 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]" } # Add adjust quantities line if there are products in the cart. set pretty_total_price [ec_pretty_price $total_price $currency] -# 3. Determine base shipping costs that are separate from items +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 -set order_shipping_cost $base_shipping_cost -set shipping_method_standard $order_shipping_cost + # set base shipping charges + set order_shipping_cost $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] + # 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_price [expr $total_reg_shipping_price + $shipping_method_standard] $currency "t"] -set total_exp_shipping_price [ec_pretty_price [expr $total_exp_shipping_price + $shipping_method_express] $currency "t"] -set shipping_method_pickup [ec_pretty_price 0 $currency "t"] -set shipping_method_no_shipping 0 + # 4. set total costs for each shipping option + set total_shipping_price_default $total_reg_shipping_price + set total_reg_shipping_price [ec_pretty_price [expr $total_reg_shipping_price + $shipping_method_standard] $currency "t"] + set total_exp_shipping_price [ec_pretty_price [expr $total_exp_shipping_price + $shipping_method_express] $currency "t"] + set shipping_method_pickup [ec_pretty_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" ] } { + # 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:" + # 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." } - 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 Index: openacs-4/packages/ecommerce/www/shopping-cart.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ecommerce/www/shopping-cart.xql,v diff -u -r1.5 -r1.5.8.1 --- openacs-4/packages/ecommerce/www/shopping-cart.xql 19 Sep 2002 03:24:55 -0000 1.5 +++ openacs-4/packages/ecommerce/www/shopping-cart.xql 9 Mar 2005 06:02:26 -0000 1.5.8.1 @@ -11,6 +11,24 @@ + + + + select address_id + from ec_addresses + where user_id=:user_id + and address_type = 'shipping' + + + + + + select country_code, zip_code + from ec_addresses + where address_id = :shipping_address_id + + + select tax_rate, initcap(state_name) as state