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 -N -r1.20 -r1.21 --- openacs-4/packages/ecommerce/www/shopping-cart.tcl 25 Sep 2010 19:50:12 -0000 1.20 +++ openacs-4/packages/ecommerce/www/shopping-cart.tcl 13 Oct 2010 09:59:24 -0000 1.21 @@ -11,8 +11,7 @@ usca_p:optional product_id:optional } - - set logout_url "/register/logout?return_url=[ns_urlencode "[ec_url]"]" +set logout_url "/register/logout?return_url=[ns_urlencode "[ec_url]"]" # bottom links: # 1) continue shopping (always) @@ -56,6 +55,12 @@ # where o.order_id=i.order_id # and o.user_session_id=:user_session_id and o.order_state='in_basket'"] +set order_id [db_string get_order_id " + select order_id + from ec_orders + where user_session_id = :user_session_id + and order_state = 'in_basket'" -default ""] + # calculate shipping charge options when not using shipping-gateway, # and then include the value with each option (for an informed choice) @@ -78,9 +83,16 @@ 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 paypal_business [parameter::get -parameter PayPalBusiness] +set paypal_standard_mode [parameter::get -parameter PayPalStandardMode] +set store_name [parameter::get -parameter SystemName] set total_reg_shipping_price 0 set total_exp_shipping_price 0 +set total_weight 0 set no_shipping_options "t" +set paypal_shipping_mode 1 +# papal_shipping_mode should mirror no_shipping_options + # 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] @@ -141,7 +153,7 @@ # 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 + select p.product_name, p.one_line_description, p.no_shipping_avail_p, p.shipping, p.shipping_additonal, p.weight, p.product_id, p.sku, 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) @@ -153,12 +165,23 @@ 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" } +# not used? +set paypal_checkout_button "
+ + + + + +" +set line_items_count 0 + for {set i 1} {$i <= [template::multirow size in_cart]} {incr i} { 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 sku [template::multirow get in_cart $i sku] 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] @@ -169,6 +192,7 @@ 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 @@ -195,7 +219,7 @@ 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" - + set paypal_shipping_mode 2 # 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] @@ -218,18 +242,35 @@ set total_price [expr $total_price + ($quantity * $lowest_price)] incr product_counter $quantity + # Add weight to order + set total_weight [expr { $quantity * $weight + $total_weight } ] + 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]" + set line_items_count $i + + # calculate paypal line item + set item_name [string range "${sku} ${product_name}, ${one_line_description}" 0 126] + append paypal_checkout_button " + + + +" + + } +set weight_unit_of_measure [parameter::get -parameter WeightUnits] + + # Add adjust quantities line if there are products in the cart. set pretty_total_price [ec_pretty_pure_price $total_price $currency] +# require shipping address + if { $shipping_gateway_in_use && $shipping_address_id > 0} { - - set weight_unit_of_measure [parameter::get -parameter WeightUnits] - + set shipping_options "" @@ -274,15 +315,15 @@ # 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 total_reg_ship_price [format "%0.2f" [expr $total_reg_shipping_price + $shipping_method_standard]] + set total_reg_shipping_price [ec_pretty_pure_price $total_reg_ship_price $currency "t"] + set total_exp_ship_price [format "%0.2f" [expr $total_exp_shipping_price + $shipping_method_express]] + set total_exp_shipping_price [ec_pretty_pure_price $total_exp_ship_price $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 } { @@ -295,6 +336,7 @@ } } else { set shipping_options "No shipping options available." + } } @@ -308,6 +350,53 @@ set pretty_tax "[format %0.2f [expr $tax_rate * 100]]%" } +# calculate paypal cart totals, finish button html +if { $paypal_standard_mode == 1 } { +# +append paypal_checkout_button " + +" +} + +append paypal_checkout_button " + + + + + + + +" + + +if { $paypal_shipping_mode == 2 && $paypal_standard_mode == 3 } { + set ii [expr { $line_items_count + 1 } ] + set paypal_checkout_button_stand "${paypal_checkout_button} + + + + +Standard shipping  checkout +" + set paypal_checkout_button_expr "${paypal_checkout_button} + + + + +Express shipping  checkout +" +} else { + append paypal_checkout_button " +Checkout with . A safe, easy way to pay. +" + +} +if { $paypal_standard_mode > 0 && $paypal_standard_mode < 3} { + set no_shipping_options "t" +} + +# src="http://www.paypal.com/en_US/i/btn/btn_xpressCheckout.gif" alt="Check out with PayPal. The safer, easier way to pay." + # bottom links: # 1) continue shopping (always and already created) # 2) log in (if they're not logged in) @@ -332,6 +421,7 @@ and saved_p='t')" -default ""] } + set title "Shopping Cart" set context [list $title] set ec_system_owner [ec_system_owner]
Shipping method: