Index: openacs-4/packages/ecommerce/ecommerce.info =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ecommerce/ecommerce.info,v diff -u -r1.28 -r1.29 --- openacs-4/packages/ecommerce/ecommerce.info 19 Sep 2002 23:38:19 -0000 1.28 +++ openacs-4/packages/ecommerce/ecommerce.info 27 Sep 2002 04:46:46 -0000 1.29 @@ -599,6 +599,7 @@ + @@ -744,8 +745,6 @@ - - @@ -970,53 +969,53 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Index: openacs-4/packages/ecommerce/tcl/ecommerce-scheduled-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ecommerce/tcl/ecommerce-scheduled-procs.tcl,v diff -u -r1.8 -r1.9 --- openacs-4/packages/ecommerce/tcl/ecommerce-scheduled-procs.tcl 26 May 2002 04:36:49 -0000 1.8 +++ openacs-4/packages/ecommerce/tcl/ecommerce-scheduled-procs.tcl 27 Sep 2002 04:46:45 -0000 1.9 @@ -54,18 +54,26 @@ } { - # For each product find other products that are items of orders - # with the same user_id. + # First prune expired combinations. A combination is deemed + # expired when one of the products is inactive. - db_foreach products_select "select product_id from ec_products" { + ec_prune_product_purchase_combinations + + # For each active product find other active products that are + # items of orders with the same user_id. + + db_foreach products_select "select product_id from ec_products where active_p = 't'" { + + # Then find current product combinations. + set correlated_product_counter 0 set insert_cols [list] set insert_vals [list] set update_items [list] db_foreach correlated_products_select " select i2.product_id as correlated_product_id, count(*) as n_product_occurrences - from ec_items i2 + from ec_items i2, ec_products p where i2.order_id in (select o2.order_id from ec_orders o2 where o2.user_id in (select user_id @@ -74,6 +82,8 @@ from ec_items i where product_id = :product_id))) and i2.product_id <> :product_id + and i2.product_id = p.product_id + and p.active_p = 't' group by i2.product_id order by n_product_occurrences desc" { if { $correlated_product_counter >= 5 } { Index: openacs-4/packages/ecommerce/tcl/ecommerce-scheduled-procs.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ecommerce/tcl/ecommerce-scheduled-procs.xql,v diff -u -r1.5 -r1.6 --- openacs-4/packages/ecommerce/tcl/ecommerce-scheduled-procs.xql 26 May 2002 04:36:50 -0000 1.5 +++ openacs-4/packages/ecommerce/tcl/ecommerce-scheduled-procs.xql 27 Sep 2002 04:46:45 -0000 1.6 @@ -4,23 +4,25 @@ - select product_id from ec_products + select product_id from ec_products where active_p = 't' select i2.product_id as correlated_product_id, count(*) as n_product_occurrences - from ec_items i2 + from ec_items i2, ec_products p where i2.order_id in (select o2.order_id from ec_orders o2 where o2.user_id in (select user_id from ec_orders o where o.order_id in (select i.order_id from ec_items i where product_id = :product_id))) - and i2.product_id <> :product_id + and i2.product_id = p.product_id + and p.active_p = 't' + and i2.product_id <> :product_id group by i2.product_id order by n_product_occurrences desc Index: openacs-4/packages/ecommerce/tcl/ecommerce-utilities-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ecommerce/tcl/ecommerce-utilities-procs.tcl,v diff -u -r1.10 -r1.11 --- openacs-4/packages/ecommerce/tcl/ecommerce-utilities-procs.tcl 12 Sep 2002 02:41:56 -0000 1.10 +++ openacs-4/packages/ecommerce/tcl/ecommerce-utilities-procs.tcl 27 Sep 2002 04:46:45 -0000 1.11 @@ -1027,3 +1027,19 @@ set userag [ns_set iget $header "USER-AGENT"] return $userag } + +ad_proc ec_prune_product_purchase_combinations { +} { + Prune expired product purchase combinations. A combination is + deemed expired when one of the products is inactive. + +} { + db_dml prune_expired_combinations { + delete from ec_product_purchase_comb + where exists (select product_id + from ec_products p + where p.active_p = 'f' + and p.product_id in (ec_product_purchase_comb.product_id, ec_product_purchase_comb.product_0, + ec_product_purchase_comb.product_1, ec_product_purchase_comb.product_2, + ec_product_purchase_comb.product_3, ec_product_purchase_comb.product_4))} +} Index: openacs-4/packages/ecommerce/tcl/ecommerce-utilities-procs.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ecommerce/tcl/ecommerce-utilities-procs.xql,v diff -u -r1.4 -r1.5 --- openacs-4/packages/ecommerce/tcl/ecommerce-utilities-procs.xql 26 May 2002 04:36:50 -0000 1.4 +++ openacs-4/packages/ecommerce/tcl/ecommerce-utilities-procs.xql 27 Sep 2002 04:46:45 -0000 1.5 @@ -83,4 +83,16 @@ + + + delete from ec_product_purchase_comb + where exists (select product_id + from ec_products p + where p.active_p = 'f' + and p.product_id in (ec_product_purchase_comb.product_id, ec_product_purchase_comb.product_0, + ec_product_purchase_comb.product_1, ec_product_purchase_comb.product_2, + ec_product_purchase_comb.product_3, ec_product_purchase_comb.product_4)) + + + Index: openacs-4/packages/ecommerce/www/admin/products/toggle-active-p.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ecommerce/www/admin/products/toggle-active-p.tcl,v diff -u -r1.2 -r1.3 --- openacs-4/packages/ecommerce/www/admin/products/toggle-active-p.tcl 10 Sep 2002 22:22:45 -0000 1.2 +++ openacs-4/packages/ecommerce/www/admin/products/toggle-active-p.tcl 27 Sep 2002 04:46:42 -0000 1.3 @@ -6,7 +6,7 @@ @cvs-id $Id$ @author ported by Jerry Asher (jerry@theashergroup.com) } { - product_id:integer,notnull + product_id:integer,notnull } ad_require_permission [ad_conn package_id] admin @@ -17,12 +17,15 @@ set peeraddr [ns_conn peeraddr] db_dml toggle_active_p_update " -update ec_products -set active_p = logical_negation(active_p), - last_modified = sysdate, - last_modifying_user = :user_id, - modified_ip_address = :peeraddr -where product_id = :product_id -" + update ec_products + set active_p = logical_negation(active_p), last_modified = sysdate, last_modifying_user = :user_id, + modified_ip_address = :peeraddr + where product_id = :product_id" +# Recalculate product purchase combinations to remove combinations +# involving the discontinued product. + +if {![template::util::is_true [db_string is_product_active_p "select active_p from ec_products where product_id = :product_id"]]} { + ec_prune_product_purchase_combinations +} ad_returnredirect "one.tcl?[export_url_vars product_id]" Index: openacs-4/packages/ecommerce/www/admin/products/toggle-active-p.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ecommerce/www/admin/products/toggle-active-p.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/ecommerce/www/admin/products/toggle-active-p.xql 27 Sep 2002 04:46:42 -0000 1.1 @@ -0,0 +1,13 @@ + + + + + + + select active_p + from ec_products + where product_id = :product_id + + + +