Index: openacs-4/packages/ecommerce/www/admin/products/categories-upload-by-id-2.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ecommerce/www/admin/products/categories-upload-by-id-2.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/ecommerce/www/admin/products/categories-upload-by-id-2.adp 14 Aug 2008 21:09:18 -0000 1.1 @@ -0,0 +1,8 @@ + + @title;noquote@ + @context;noquote@ +

@title@

+ +
+@doc_body;noquote@ + Index: openacs-4/packages/ecommerce/www/admin/products/categories-upload-by-id-2.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ecommerce/www/admin/products/categories-upload-by-id-2.tcl,v diff -u -r1.2 -r1.3 --- openacs-4/packages/ecommerce/www/admin/products/categories-upload-by-id-2.tcl 24 Feb 2005 13:33:15 -0000 1.2 +++ openacs-4/packages/ecommerce/www/admin/products/categories-upload-by-id-2.tcl 14 Aug 2008 21:09:18 -0000 1.3 @@ -27,150 +27,35 @@ set user_id [ad_get_user_id] set ip [ns_conn peeraddr] -doc_body_append "[ad_admin_header "Uploading Category Mappings"] +set title "Uploading Category Mappings" +set context [list [list index Products] $title] -[ad_context_bar [list "../" "Ecommerce([ec_system_name])"] [list "index.tcl" "Products"] "Uploading Categories"] +set doc_body "" -
- -

Uploading Category Mappings

- -
-" - set unix_file_name ${csv_file.tmpfile} # Check that the file is readable. if { ![file readable $unix_file_name] } { - doc_body_append "Cannot read file $unix_file_name" - return + append doc_body "Cannot read file $unix_file_name" + set serious_errors 1 } # Check that delimiter is one character, if used if { [string length $delimiter] != 1 && [string eq $file_type "delim"]} { - doc_body_append "Delimiter is not one character long." - return + append doc_body "Delimiter is not one character long." + set serious_errors 1 } -set datafilefp [open $unix_file_name] -set count 0 -set success_count 0 +if { !serious_errors } { -# Continue reading the file till the end but stop when an error -# occured. - -# read line, depending on file type -if {[string eq $file_type "csv"]} { - set line_status [ns_getcsv $datafilefp elements] -} elseif {[string eq $file_type "tab"]} { - set line_status [ec_gets_char_delimited_line $datafilefp elements] -} elseif {[string eq $file_type "delim"]} { - set line_status [ec_gets_char_delimited_line $datafilefp elements $delimiter] -} else { -# no valid filetype chosen - set line_status -1 -} - -while { $line_status != -1 } { - - incr count - # this line is a product - set sku [lindex $elements 0] -# upload category id from file - set category [lindex $elements 1] -# upload subcategory id from file - set subcategory [lindex $elements 2] -# upload subsubcategory id from file - set subsubcategory [lindex $elements 3] - - - # 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 ""] - - # Modified by RH on 05/05/03 - # Match the product with the given (sub)(sub)category. - if { $product_id != "" } { - - # see if this matches any subsubcategories - set subsubmatch_p 0 - db_foreach subsubcategories_select " - select c.category_id, c.category_name, s.subcategory_id, s.subcategory_name, ss.subsubcategory_id, ss.subsubcategory_name from ec_subsubcategories ss, ec_subcategories s, ec_categories c - where c.category_id = s.category_id - and s.subcategory_id = ss.subcategory_id - and :subsubcategory = ss.subsubcategory_id" { -# previous line changed to directly match category id -# so that there is no mistake in placement of product to categories - set subsubmatch_p 1 - - # add this product to the matched subsubcategory - set sql "insert into ec_subsubcategory_product_map (product_id, subsubcategory_id, publisher_favorite_p, last_modified, last_modifying_user, modified_ip_address) values (:product_id, :subsubcategory_id, 'f', sysdate, :user_id, :ip)" - if { [catch {db_dml subsubcategory_insert $sql} errmsg] } { - #error, probably already loaded this one - } else { - doc_body_append "Matched $category to subsubcategory $subsubcategory_name in subcategory $subcategory_name, category $category_name.
\n" - } - - # now add it to the subcategory that owns this subsubcategory - 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 - } - - # 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 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 :subcategory = subcategory_id" { - # previous line changed to directly match category id - # so that there is no mistake in placement of product to categories - 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 - } - } - - # see if this matches any categories - set match_p 0 - db_foreach category_match_select "select category_id, category_name from ec_categories where :category = category_id" { - # previous line changed to directly match category id - # so that there is no mistake in placement of product to categories - 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 || $subsubmatch_p) } { - doc_body_append "Datafile row $count : Could not find matching category reference for item (sku: $sku) with category ref: $category : $subcategory : $subsubcategory
\n" - } else { - incr success_count - } - } - - # read next line of data file, depending on file type, or end read loop if error. + set datafilefp [open $unix_file_name] + set count 0 + set success_count 0 + + # Continue reading the file till the end but stop when an error + # occured. + + # read line, depending on file type if {[string eq $file_type "csv"]} { set line_status [ns_getcsv $datafilefp elements] } elseif {[string eq $file_type "tab"]} { @@ -179,20 +64,128 @@ set line_status [ec_gets_char_delimited_line $datafilefp elements $delimiter] } else { # no valid filetype chosen - set line_status -1 + set line_status -1 } - + + while { $line_status != -1 } { + + incr count + # this line is a product + set sku [lindex $elements 0] + # upload category id from file + set category [lindex $elements 1] + # upload subcategory id from file + set subcategory [lindex $elements 2] + # upload subsubcategory id from file + set subsubcategory [lindex $elements 3] + + + # 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 ""] + + # Modified by RH on 05/05/03 + # Match the product with the given (sub)(sub)category. + if { $product_id != "" } { + + # see if this matches any subsubcategories + set subsubmatch_p 0 + db_foreach subsubcategories_select " + select c.category_id, c.category_name, s.subcategory_id, s.subcategory_name, ss.subsubcategory_id, ss.subsubcategory_name from ec_subsubcategories ss, ec_subcategories s, ec_categories c + where c.category_id = s.category_id + and s.subcategory_id = ss.subcategory_id + and :subsubcategory = ss.subsubcategory_id" { + # previous line changed to directly match category id + # so that there is no mistake in placement of product to categories + set subsubmatch_p 1 + + # add this product to the matched subsubcategory + set sql "insert into ec_subsubcategory_product_map (product_id, subsubcategory_id, publisher_favorite_p, last_modified, last_modifying_user, modified_ip_address) values (:product_id, :subsubcategory_id, 'f', sysdate, :user_id, :ip)" + if { [catch {db_dml subsubcategory_insert $sql} errmsg] } { + #error, probably already loaded this one + } else { + append doc_body "Matched $category to subsubcategory $subsubcategory_name in subcategory $subcategory_name, category $category_name.
\n" + } + + # now add it to the subcategory that owns this subsubcategory + 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 + } + + # 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 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 :subcategory = subcategory_id" { + # previous line changed to directly match category id + # so that there is no mistake in placement of product to categories + 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 { + append doc_body "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 + } + } + + # see if this matches any categories + set match_p 0 + db_foreach category_match_select "select category_id, category_name from ec_categories where :category = category_id" { + # previous line changed to directly match category id + # so that there is no mistake in placement of product to categories + 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 { + append doc_body "Matched $category to category $category_name
\n" + } + } + if { ! ($match_p || $submatch_p || $subsubmatch_p) } { + append doc_body "Datafile row $count : Could not find matching category reference for item (sku: $sku) with category ref: $category : $subcategory : $subsubcategory
\n" + } else { + incr success_count + } + } + + # read next line of data file, depending on file type, or end read loop if error. + if {[string eq $file_type "csv"]} { + set line_status [ns_getcsv $datafilefp elements] + } elseif {[string eq $file_type "tab"]} { + set line_status [ec_gets_char_delimited_line $datafilefp elements] + } elseif {[string eq $file_type "delim"]} { + set line_status [ec_gets_char_delimited_line $datafilefp elements $delimiter] + } else { + # no valid filetype chosen + set line_status -1 + } + + } + + if { $success_count == 1 } { + set category_string "category mapping" + } else { + set category_string "category mappings" + } + + append doc_body "

Done loading $success_count $category_string out of [expr $count - 1]. + } - -if { $success_count == 1 } { - set category_string "category mapping" -} else { - set category_string "category mappings" -} - -doc_body_append "

Done loading $success_count $category_string out of [expr $count - 1]. - -

- -[ad_admin_footer] -" Index: openacs-4/packages/ecommerce/www/admin/products/categories-upload-by-id.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ecommerce/www/admin/products/categories-upload-by-id.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/ecommerce/www/admin/products/categories-upload-by-id.adp 14 Aug 2008 21:09:18 -0000 1.1 @@ -0,0 +1,47 @@ + + @title;noquote@ + @context;noquote@ +

@title@

+ +
+ +
+Data Filename +
+CSV format
+Tab Delimited format
+Delimited by: (single character).
+

+

+ +
+
+ +

+Notes: +

+
+

+ + This page uploads a data file containing product category mappings using (sub)(sub)category_id + values from ec_categories, ec_subcategories, and ec_subsubcategories tables. +

+ The file format should be: +

+

+sku_1, category_id_1, subcategory_id_1, subsubcategory_id_1
+sku_2, category_id_2, subcategory_id_2, subsubcategory_id_2
+...
+sku_n, category_id_n, subcategory_id_n, subsubcategory_id_n
+
+

+ Where each line contains a sku and category id set. There may be multiple lines for a single sku + which will cause the product to get placed in multiple categories (or subcategories etc.) +

+ If a subcategory match is found, the product is placed into the matching parent category + of the matching subcategory as well as the subcategory. If no match is found for + a product, no mapping entry is made. +

+
+ +
Index: openacs-4/packages/ecommerce/www/admin/products/categories-upload-by-id.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ecommerce/www/admin/products/categories-upload-by-id.tcl,v diff -u -r1.2 -r1.3 --- openacs-4/packages/ecommerce/www/admin/products/categories-upload-by-id.tcl 24 Feb 2005 13:33:15 -0000 1.2 +++ openacs-4/packages/ecommerce/www/admin/products/categories-upload-by-id.tcl 14 Aug 2008 21:09:18 -0000 1.3 @@ -36,56 +36,5 @@ ad_require_permission [ad_conn package_id] admin -doc_body_append "[ad_admin_header "Upload Category Mapping Data"] - -

Upload Category Mapping Data by category id indexes

- -[ad_context_bar [list "../" "Ecommerce([ec_system_name])"] [list "index.tcl" "Products"] "Upload Category Mapping Data"] - -
- -
- -
-Data Filename -
-CSV format
-Tab Delimited format
-Delimited by: (single character).
-

-

- -
-
- -

- -Notes: -

-
-

- - This page uploads a data file containing product category mappings using (sub)(sub)category_id - values from ec_categories, ec_subcategories, and ec_subsubcategories tables. -

- The file format should be: -

-

-sku_1, category_id_1, subcategory_id_1, subsubcategory_id_1
-sku_2, category_id_2, subcategory_id_2, subsubcategory_id_2
-...
-sku_n, category_id_n, subcategory_id_n, subsubcategory_id_n
-
-

- Where each line contains a sku and category id set. There may be multiple lines for a single sku - which will cause the product to get placed in multiple categories (or subcategories etc.) -

- If a subcategory match is found, the product is placed into the matching parent category - of the matching subcategory as well as the subcategory. If no match is found for - a product, no mapping entry is made. -

-
-
- -[ad_admin_footer] -" +set title "Uploading Category Mapping Data by category id indexes" +set context [list [list index Products] $title]