Index: openacs-4/packages/ecommerce/www/admin/products/upload-2.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ecommerce/www/admin/products/upload-2.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/ecommerce/www/admin/products/upload-2.adp 16 Aug 2008 05:12:52 -0000 1.1 @@ -0,0 +1,13 @@ + + @title;noquote@ + @context;noquote@ +

@title@

+ + +@error_message@ + + +@doc_body;noquote@ +

Successfully loaded @success_count@ @product_string@ out of @total_lines@.

+ +
Index: openacs-4/packages/ecommerce/www/admin/products/upload-2.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ecommerce/www/admin/products/upload-2.tcl,v diff -u -r1.9 -r1.10 --- openacs-4/packages/ecommerce/www/admin/products/upload-2.tcl 30 Apr 2008 11:38:11 -0000 1.9 +++ openacs-4/packages/ecommerce/www/admin/products/upload-2.tcl 16 Aug 2008 05:12:52 -0000 1.10 @@ -19,34 +19,25 @@ set peeraddr [ns_conn peeraddr] # Grab package_id as context_id - set context_id [ad_conn package_id] -doc_body_append "[ad_admin_header "Uploading Products"] +set serious_errors 0 -

Uploading Products

+set title "Uploading Products" +set context [list [list index Products] $title] -[ad_context_bar [list "../" "Ecommerce([ec_system_name])"] [list "index.tcl" "Products"] "Uploading Products"] - -
- -
-" - # Get the name of the transfered data file - 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 error_message "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 error_message "Delimiter is not one character long." + set serious_errors 1 } # Accept only field names that exist in the ec_product table and are @@ -59,27 +50,22 @@ # Check each entry in the datafile for the following required fields. # These fields are required so that we can check if a product already # in the products table and should be update rather than created. - set required_field_names {sku product_name} # Initialize each legal field name as the datafile might not mention # each and every one of them. - foreach legal_field_name $legal_field_names { set $legal_field_name "" } # Start reading. # use file_type to determine which proc to delimit data - set datafilefp [open $unix_file_name] set count 0 -set errors 0 +set errors $serious_errors set success_count 0 +set doc_body "" -# 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] @@ -92,21 +78,20 @@ set line_status -1 } +# Continue reading the file till the end but stop when an error occured. while { $line_status != -1 && !$errors} { incr count if { $count == 1 } { # First row, grab the field names and their number. - set field_names $elements set number_of_fields [llength $elements] # Check the field names against the list of legal names - foreach field_name $field_names { if {[lsearch -exact $legal_field_names $field_name] == -1} { incr errors - doc_body_append "

FAILURE! $field_name is not an allowed field name.

" + append doc_body "

FAILURE! $field_name is not an allowed field name.

" } } } else { @@ -162,7 +147,6 @@ # We found a product_id for the given sku, let's # update the product. - if { [catch {db_dml product_update " update ec_products set user_id = :user_id, @@ -187,20 +171,18 @@ template_id = :template_id where product_id = :product_id; "} errmsg] } { - doc_body_append "

FAILURE! Product update of $product_name failed with error:<\p>

$errmsg

" + append doc_body "

FAILURE! Product update of $product_name failed with error:<\p>

$errmsg

" } else { - doc_body_append "

Updated $product_name

" + append doc_body "

Updated $product_name

" } } else { # Generate a product_id - set product_id [db_nextval acs_object_id_seq] # Dirname will be the first four letters (lowercase) # of the product_name followed by the product_id (for # uniqueness) - regsub -all {[^a-zA-Z]} $product_name "" letters_in_product_name set letters_in_product_name [string tolower $letters_in_product_name] if [catch {set dirname "[string range $letters_in_product_name 0 3]$product_id"}] { @@ -238,16 +220,14 @@ :size_list, :peeraddr )"} errmsg] } { - doc_body_append "FAILURE! Product creation of $product_name failed with error:<\p>

$errmsg

" + append doc_body "FAILURE! Product creation of $product_name failed with error:<\p>

$errmsg

" } else { - doc_body_append "

Created $product_name

" + append doc_body "

Created $product_name

" # we have to also write a row into ec_custom_product_field_values # for consistency with add*.tcl (added 1999-08-08, inadvertently removed 20020504) - - if { [catch {db_dml custom_product_field_insert "insert into ec_custom_product_field_values (product_id, last_modified, last_modifying_user, modified_ip_address) values (:product_id, now(), :user_id, :peeraddr)" } errmsg] } { - doc_body_append "FAILURE! Insert into ec_custom_product_field_values failed for product_id=$product_id with error: $errmsg
\n" + append doc_body "FAILURE! Insert into ec_custom_product_field_values failed for product_id=$product_id with error: $errmsg
\n" } } } @@ -265,13 +245,10 @@ template_id = :template_id where product_id = :product_id; "} errmsg] } { - doc_body_append "FAILURE! Product update of new product $product_name failed with error:<\p>

$errmsg

" + append doc_body "FAILURE! Product update of new product $product_name failed with error:<\p>

$errmsg

" } - } - # Product line is completed, increase counter - incr success_count } @@ -289,7 +266,6 @@ set line_status -1 } - } if { $success_count == 1 } { @@ -298,9 +274,7 @@ set product_string "products" } -doc_body_append "
+set total_lines "[ec_decode $count "0" "0" [expr $count -1]]" -

Successfully loaded $success_count $product_string out of [ec_decode $count "0" "0" [expr $count -1]]. -[ad_admin_footer] -" + Index: openacs-4/packages/ecommerce/www/admin/products/upload.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ecommerce/www/admin/products/upload.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/ecommerce/www/admin/products/upload.adp 16 Aug 2008 05:12:52 -0000 1.1 @@ -0,0 +1,49 @@ + + @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 information into the database. The file format should be: +

+

+field_name_1, field_name_2, ... field_name_n
+value_1, value_2, ... value_n
+
+

+where the first line contains the actual names of the columns in ec_products and the remaining lines contain +the values for the specified fields, one line per product. +

+Legal values for field names are the columns in ec_products: +

+

+
+@doc_body;noquote@
+
+
+

+Note: @undesirable_cols_html;noquote@ are set +automatically and should not appear in the data file. + +

+ +

About search_keywords: Data from product_name, one_line_description, and detailed_description +are automatically included in product searches. No need to repeat that information in search_keywords.

Index: openacs-4/packages/ecommerce/www/admin/products/upload.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ecommerce/www/admin/products/upload.tcl,v diff -u -r1.9 -r1.10 --- openacs-4/packages/ecommerce/www/admin/products/upload.tcl 13 Jan 2005 13:58:02 -0000 1.9 +++ openacs-4/packages/ecommerce/www/admin/products/upload.tcl 16 Aug 2008 05:12:52 -0000 1.10 @@ -45,78 +45,26 @@ ad_require_permission [ad_conn package_id] admin -doc_body_append "[ad_admin_header "Upload Products"] +set title "Upload Products" +set context [list [list index Products] $title] -

Upload Products

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

- -Notes: - -

-

- -This page uploads a data file containing product information into the database. The file format should be: -

-

-field_name_1, field_name_2, ... field_name_n
-value_1, value_2, ... value_n
-
-

-where the first line contains the actual names of the columns in ec_products and the remaining lines contain -the values for the specified fields, one line per product. -

-Legal values for field names are the columns in ec_products: -

-

-
-"
-
 set undesirable_cols [list "product_id" "dirname" "creation_date" "available_date" "last_modified" "last_modifying_user" "modified_ip_address"]
+
 set required_cols [list "sku" "product_name"]
 
-
 db_with_handle db {
   for {set i 0} {$i < [ns_column count $db ec_products]} {incr i} {
     set col_to_print [ns_column name $db ec_products $i]
     if { [lsearch -exact $undesirable_cols $col_to_print] == -1 } {
-      doc_body_append "$col_to_print"
+      append doc_body "$col_to_print"
       if { [lsearch -exact $required_cols $col_to_print] != -1 } {
-	doc_body_append " (required)"
+          append doc_body " (required)"
       }
-      doc_body_append "\n"
+      append doc_body "\n"
     }
   }
 }
 
-doc_body_append "
-
-

-Note: [join $undesirable_cols ", "] are set -automatically and should not appear in the data file. +set undesirable_cols_html [join $undesirable_cols ", "] -

-
-

About search_keywords: Data from product_name, one_line_description, and detailed_description -are automatically included in product searches. No need to repeat that information in search_keywords.

-[ad_admin_footer] -"