Index: openacs-4/packages/ecommerce/www/admin/products/categories-upload-2-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ecommerce/www/admin/products/categories-upload-2-postgresql.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/ecommerce/www/admin/products/categories-upload-2-postgresql.xql 24 Nov 2001 03:44:26 -0000 1.1 @@ -0,0 +1,73 @@ + + + + + + select product_id from ec_products + where sku = :sku; + + + + + + insert into ec_subcategory_product_map ( + product_id, + subcategory_id, + publisher_favorite_p, + last_modified, + last_modifying_user, + modified_ip_address) + values ( + :product_id, + :subcategory_id, + 'f', + now(), + :user_id, + :ip) + + + + + + insert into ec_category_product_map ( + product_id, + category_id, + publisher_favorite_p, + last_modified, + last_modifying_user, + modified_ip_address) + values ( + :product_id, + :category_id, + 'f', + now(), + :user_id, + :ip) + + + + + + insert into ec_category_product_map ( + product_id, + category_id, + publisher_favorite_p, + last_modified, + last_modifying_user, + modified_ip_address) + values ( + :product_id, + :category_id, + 'f', + now(), + :user_id, + :ip) + + + + + + + + + Index: openacs-4/packages/ecommerce/www/admin/products/categories-upload-2.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ecommerce/www/admin/products/categories-upload-2.tcl,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/ecommerce/www/admin/products/categories-upload-2.tcl 20 Apr 2001 20:51:14 -0000 1.1 +++ openacs-4/packages/ecommerce/www/admin/products/categories-upload-2.tcl 24 Nov 2001 03:34:36 -0000 1.2 @@ -7,8 +7,8 @@ @cvs-id categories-upload-2.tcl,v 3.1.2.2 2000/07/22 07:57:37 ron Exp @author ported by Jerry Asher (jerry@theashergroup.com) } { - cvs_file - cvs_file.tmpfile:tmpfile + csv_file + csv_file.tmpfile:tmpfile } ad_require_permission [ad_conn package_id] admin @@ -41,47 +41,57 @@ while { [ns_getcsv $csvfp elements] != -1 } { incr count # this line is a product - set product_id [lindex $elements 0] + set sku [lindex $elements 0] set category [lindex $elements 1] - # see if this matches any subcategories - set submatch_p 0 - db_foreach subcategories_select " - select c.category_id, c.category_name, s.subcategory_id, - s.subcategory_name from ec_subcategories s, ec_categories c - where c.category_id = s.category_id - and upper(:category) like upper(subcategory_name) || '%'" { - set submatch_p 1 - # add this product to the matched subcategory - set sql "insert into ec_subcategory_product_map (product_id, subcategory_id, publisher_favorite_p, last_modified, last_modifying_user, modified_ip_address) values (:product_id, :subcategory_id, 'f', sysdate, :user_id, :ip)" - if { [catch {db_dml subcategory_insert $sql} errmsg] } { - #error, probably already loaded this one - } else { - doc_body_append "Matched $category to subcategory $subcategory_name in category $category_name
\n" + # Check if there is a product with the give sku. + # Set product_id to NULL if there is no + # product with the given sku. + set product_id [db_string product_check {select product_id from ec_products where sku = :sku;} -default ""] + + # Match the product with the given (sub)category. + if { $product_id != "" } { + + # see if this matches any subcategories + set submatch_p 0 + db_foreach subcategories_select " + select c.category_id, c.category_name, s.subcategory_id, + s.subcategory_name from ec_subcategories s, ec_categories c + where c.category_id = s.category_id + and upper(:category) like upper(subcategory_name) || '%'" { + set submatch_p 1 + + # add this product to the matched subcategory + set sql "insert into ec_subcategory_product_map (product_id, subcategory_id, publisher_favorite_p, last_modified, last_modifying_user, modified_ip_address) values (:product_id, :subcategory_id, 'f', sysdate, :user_id, :ip)" + if { [catch {db_dml subcategory_insert $sql} errmsg] } { + #error, probably already loaded this one + } else { + doc_body_append "Matched $category to subcategory $subcategory_name in category $category_name
\n" + } + # now add it to the category that owns this subcategory + set sql "insert into ec_category_product_map (product_id, category_id, publisher_favorite_p, last_modified, last_modifying_user, modified_ip_address) values (:product_id, :category_id, 'f', sysdate, :user_id, :ip)" + if { [catch {db_dml unused_sub $sql} errmsg] } { + #error, probably already loaded this one + } } - # now add it to the category that owns this subcategory - set sql "insert into ec_category_product_map (product_id, category_id, publisher_favorite_p, last_modified, last_modifying_user, modified_ip_address) values (:product_id, :category_id, 'f', sysdate, :user_id, :ip)" - if { [catch {db_dml unused_sub $sql} errmsg] } { - #error, probably already loaded this one - } - } - # see if this matches any categories - set match_p 0 - db_foreach category_match_select "select category_id, category_name from ec_categories where upper(:category) like upper(category_name) || '%'" { - set match_p 1 - set sql "insert into ec_category_product_map (product_id, category_id, publisher_favorite_p, last_modified, last_modifying_user, modified_ip_address) values (:product_id, :category_id, 'f', sysdate, :user_id, :ip)" - if { [catch {db_dml cateogry_insert $sql} errmsg] } { - #error, probably already loaded this one + # see if this matches any categories + set match_p 0 + db_foreach category_match_select "select category_id, category_name from ec_categories where upper(:category) like upper(category_name) || '%'" { + set match_p 1 + set sql "insert into ec_category_product_map (product_id, category_id, publisher_favorite_p, last_modified, last_modifying_user, modified_ip_address) values (:product_id, :category_id, 'f', sysdate, :user_id, :ip)" + if { [catch {db_dml category_insert $sql} errmsg] } { + #error, probably already loaded this one + } else { + doc_body_append "Matched $category to category $category_name
\n" + } + } + if { ! ($match_p || $submatch_p) } { + doc_body_append "Could not find matching category or subcategory for $category
\n" } else { - doc_body_append "Matched $category to category $category_name
\n" + incr success_count } } - if { ! ($match_p || $submatch_p) } { - doc_body_append "Could not find matching category or subcategory for $category
\n" - } else { - incr success_count - } } if { $success_count == 1 } { Index: openacs-4/packages/ecommerce/www/admin/products/categories-upload.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ecommerce/www/admin/products/categories-upload.tcl,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/ecommerce/www/admin/products/categories-upload.tcl 20 Apr 2001 20:51:14 -0000 1.1 +++ openacs-4/packages/ecommerce/www/admin/products/categories-upload.tcl 24 Nov 2001 03:41:06 -0000 1.2 @@ -6,10 +6,10 @@ The file format should be: - product_id_1, category_description_1 - product_id_2, category_description_2 + sku_1, category_description_1 + sku_2, category_description_2 ... - product_id_n, category_description_n + sku_n, category_description_n Where each line contains a product id, category name pair. There may be multiple lines for a single product id which will cause the @@ -66,10 +66,10 @@ The file format should be:

-product_id_1, category_description_1
-product_id_2, category_description_2
+sku_1, category_description_1
+sku_2, category_description_2
...
-product_id_n, category_description_n
+sku_n, category_description_n

Where each line contains a product id, category name pair. There may be multiple lines for a single product id