Index: openacs-4/packages/dotlrn-ecommerce/www/ecommerce/shopping-cart-add.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/ecommerce/shopping-cart-add.tcl,v diff -u -N -r1.23 -r1.24 --- openacs-4/packages/dotlrn-ecommerce/www/ecommerce/shopping-cart-add.tcl 19 Sep 2005 22:11:38 -0000 1.23 +++ openacs-4/packages/dotlrn-ecommerce/www/ecommerce/shopping-cart-add.tcl 20 Sep 2005 17:38:28 -0000 1.24 @@ -36,7 +36,8 @@ {participant_id:integer 0} {override_p 0} - + {override_course_application_p 0} + offer_code:optional return_url:notnull,optional } @@ -109,27 +110,36 @@ $member_state != "payment received" && ($override_p == 0 || $admin_p == 0) } { - + # Check application assessment - if { [db_0or1row get_assessment { - select c.assessment_id - - from dotlrn_ecommerce_section s, - dotlrn_catalogi c, - cr_items i - - where s.course_id = c.item_id - and c.item_id = i.item_id - and i.live_revision = c.course_id - and s.product_id = :product_id - - limit 1 - }] } { - if { ! [empty_string_p $assessment_id] && $assessment_id != -1 } { - set return_url [export_vars -base "[ad_conn package_url]application-confirm" { product_id {member_state "awaiting payment"} }] - ad_returnredirect [export_vars -base application-request { user_id participant_id community_id {next_url $return_url} { type payment } }] - ad_script_abort + if { ! $override_course_application_p } { + if { [db_0or1row get_assessment { + select c.assessment_id, c.auto_register_p + from dotlrn_ecommerce_section s, + dotlrn_catalogi c, + cr_items i + + where s.course_id = c.item_id + and c.item_id = i.item_id + and i.live_revision = c.course_id + and s.product_id = :product_id + + limit 1 + }] } { + if { ! [empty_string_p $assessment_id] && $assessment_id != -1 } { + if { $auto_register_p == "t" } { + set form [rp_getform] + ns_set delkey $form override_course_application_p + + set return_url [export_vars -base [ad_return_url] { {override_course_application_p 1} }] + ad_returnredirect [export_vars -base "[apm_package_url_from_id [parameter::get -parameter AssessmentPackage]]assessment" { assessment_id return_url }] + } else { + set return_url [export_vars -base "[ad_conn package_url]application-confirm" { product_id {member_state "awaiting payment"} }] + ad_returnredirect [export_vars -base application-request { user_id participant_id community_id {next_url $return_url} { type payment } }] + } + ad_script_abort + } } } @@ -218,46 +228,46 @@ if { $price < 0.01 } { dotlrn_community::add_user $community_id $participant_id - } - # Adding these for correctness, taken from the after-checkout - # callback + # Adding these for correctness, taken from the after-checkout + # callback - if { [lsearch [parameter::get -parameter WelcomeEmailRecipients] purchaser] != -1 } { - if {$user_id != $participant_id} { - # if they are the participant, then - # they will get the welcome email for the community - dotlrn_community::send_member_email -community_id $community_id -to_user $participant_id -type "on join" -email_send_to $user_id -override_enabled + if { [lsearch [parameter::get -parameter WelcomeEmailRecipients] purchaser] != -1 } { + if {$user_id != $participant_id} { + # if they are the participant, then + # they will get the welcome email for the community + dotlrn_community::send_member_email -community_id $community_id -to_user $participant_id -type "on join" -email_send_to $user_id -override_enabled + } } - } - - if { [db_0or1row member_rel { - select rel_id - from dotlrn_member_rels_full - where community_id = :community_id - and user_id = :participant_id - limit 1 - }] } { - set patron_rel_id [db_exec_plsql relate_patron { - select acs_rel__new (null, - 'membership_patron_rel', - :rel_id, - :user_id, - null, - null, - null) - }] - } + + if { [db_0or1row member_rel { + select rel_id + from dotlrn_member_rels_full + where community_id = :community_id + and user_id = :participant_id + limit 1 + }] } { + set patron_rel_id [db_exec_plsql relate_patron { + select acs_rel__new (null, + 'membership_patron_rel', + :rel_id, + :user_id, + null, + null, + null) + }] + } - # Flush cache - dotlrn_ecommerce::section::flush_cache $section_id + # Flush cache + dotlrn_ecommerce::section::flush_cache $section_id - if { [exists_and_not_null return_url] } { - ad_returnredirect $return_url - } else { - ad_returnredirect [ad_conn package_url] + if { [exists_and_not_null return_url] } { + ad_returnredirect $return_url + } else { + ad_returnredirect [ad_conn package_url] + } + ad_script_abort } - ad_script_abort } # added default values to above params so that this page works