Index: openacs-4/packages/ecommerce/ecommerce.info =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ecommerce/ecommerce.info,v diff -u -r1.40 -r1.41 --- openacs-4/packages/ecommerce/ecommerce.info 24 Feb 2005 13:33:12 -0000 1.40 +++ openacs-4/packages/ecommerce/ecommerce.info 27 Apr 2008 01:38:22 -0000 1.41 @@ -15,15 +15,17 @@ 2005-02-10 furfly.net, LLC This module implements all that IT needs for a standard business-to-consumer Web service. You can find a feature summary in the documentaion. + 0 - + - + + @@ -37,11 +39,16 @@ - + + + + + + @@ -54,6 +61,9 @@ + + + @@ -68,17 +78,12 @@ - + - - - - - Index: openacs-4/packages/ecommerce/sql/oracle/ecommerce-defaults.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ecommerce/sql/oracle/ecommerce-defaults.sql,v diff -u -r1.2 -r1.3 --- openacs-4/packages/ecommerce/sql/oracle/ecommerce-defaults.sql 26 May 2002 04:36:49 -0000 1.2 +++ openacs-4/packages/ecommerce/sql/oracle/ecommerce-defaults.sql 27 Apr 2008 01:38:23 -0000 1.3 @@ -33,7 +33,13 @@ || '' || CHR(10) || ' ' || CHR(10) || ' ' || CHR(10) - || ' ' || CHR(10) + || ' <%' || '\n' + || 'array set image_info [ecommerce::resource::image_info -type ProductImage -product_id $product_id -dirname $dirname]' || '\n' + || 'array set fullsize_info [ecommerce::resource::image_info -product_id $product_id -dirname $dirname]' || '\n' + || '%>' || '\n' + || '' || '\n' || '
<%= [ec_linked_thumbnail_if_it_exists $dirname] %>' || '\n' + || '' || '\n' + || '' || CHR(10) || ' <%= $one_line_description %>' || CHR(10) || '
' || CHR(10) Index: openacs-4/packages/ecommerce/sql/postgresql/ecommerce-defaults.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ecommerce/sql/postgresql/ecommerce-defaults.sql,v diff -u -r1.3 -r1.4 --- openacs-4/packages/ecommerce/sql/postgresql/ecommerce-defaults.sql 8 Mar 2004 19:46:10 -0000 1.3 +++ openacs-4/packages/ecommerce/sql/postgresql/ecommerce-defaults.sql 27 Apr 2008 01:38:23 -0000 1.4 @@ -33,7 +33,13 @@ || '
' || '\n' || ' ' || '\n' || ' ' || '\n' - || ' ' || '\n' + || ' <%' || '\n' + || 'array set image_info [ecommerce::resource::image_info -type ProductImage -product_id $product_id -dirname $dirname]' || '\n' + || 'array set fullsize_info [ecommerce::resource::image_info -product_id $product_id -dirname $dirname]' || '\n' + || '%>' || '\n' + || '' || '\n' || ' - + - " Index: openacs-4/packages/ecommerce/www/product.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ecommerce/www/product.adp,v diff -u -r1.5 -r1.6 --- openacs-4/packages/ecommerce/www/product.adp 13 Jan 2005 13:58:00 -0000 1.5 +++ openacs-4/packages/ecommerce/www/product.adp 27 Apr 2008 01:38:23 -0000 1.6 @@ -10,4 +10,4 @@ t - @formatted_product;noquote@ + <% eval $product_code %> Index: openacs-4/packages/ecommerce/www/product.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ecommerce/www/product.tcl,v diff -u -r1.10 -r1.11 --- openacs-4/packages/ecommerce/www/product.tcl 1 Mar 2005 00:01:31 -0000 1.10 +++ openacs-4/packages/ecommerce/www/product.tcl 27 Apr 2008 01:38:23 -0000 1.11 @@ -196,4 +196,5 @@ set context_bar [template::adp_parse [acs_root_dir]/packages/[ad_conn package_key]/www/contextbar [list context_addition [list $product_name]]] set ec_system_owner [ec_system_owner] -set formatted_product [ns_adp_parse -string $template] +# TODO should memoize this +set product_code [template::adp_compile -string $template] Index: openacs-4/packages/ecommerce/www/admin/products/add-2.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ecommerce/www/admin/products/add-2.tcl,v diff -u -r1.6 -r1.7 --- openacs-4/packages/ecommerce/www/admin/products/add-2.tcl 24 Feb 2005 13:33:15 -0000 1.6 +++ openacs-4/packages/ecommerce/www/admin/products/add-2.tcl 27 Apr 2008 01:38:24 -0000 1.7 @@ -132,97 +132,35 @@ # Things to generate: # 1. generate a product_id -# wtem@olywa.net, 2001-03-25 -# we are using ec_product.new pl/sql function now instead of old sequence/insert set product_id [db_nextval acs_object_id_seq] -# 2. generate a directory name (and create the directory) to store pictures -# and other supporting product info - -# let's have dirname 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"}] { - #maybe there aren't 4 letters in the product name - set dirname "$letters_in_product_name$product_id" -} - -# Get the directory where dirname is stored -set subdirectory "[ec_data_directory][ec_product_directory][ec_product_file_directory $product_id]" -# if you get errors here -# it may be because you have not completed your technical setup completely -# namely you need to set -# the EcommerceDataDirectory parameter and ProductDataDirectory parameter -# and create the corresponding directory in the file system -ec_assert_directory $subdirectory - -set full_dirname "$subdirectory/$dirname" -ec_assert_directory $full_dirname - # if an image file has been specified, upload it into the # directory that was just created and make a thumbnail (using # dimensions specified in parameters/whatever.ini) +set thumbnail "" + if { [info exists upload_file] && ![string compare $upload_file ""] == 0 } { - # this takes the upload_file and sticks its contents into a temporary - # file (will be deleted when the thread ends) + # tmp file will be deleted when the thread ends set tmp_filename ${upload_file.tmpfile} - - # so that we'll know if it's a gif or a jpg - set file_extension [file extension $upload_file] - - # copies this temp file into a permanent file - set perm_filename "$full_dirname/product[string tolower $file_extension]" - ns_cp $tmp_filename $perm_filename - - # create thumbnails + # copy image & create thumbnails # thumbnails are all jpg files - # set thumbnail dimensions - set use_both_param_dimensions [parameter::get -parameter ThumbnailSizeOuterlimits] - set thumbnail_width_is_blank [catch {set thumbnail_width [parameter::get -parameter ThumbnailWidth]} ] - set thumbnail_height_is_blank [catch {set thumbnail_height [parameter::get -parameter ThumbnailHeight]} ] - if { $use_both_param_dimensions } { - set convert_dimensions "${thumbnail_width}x${thumbnail_height}>" - } else { - if { $thumbnail_width_is_blank } { - if { $thumbnail_height_is_blank } { - set convert_dimensions "100x10000" - } else { - set convert_dimensions "10000x${thumbnail_height}" - } - } else { - set convert_dimensions "${thumbnail_width}x10000" - } - } + ecommerce::resource::make_product_images \ + -file_extension [file extension $upload_file] \ + -product_id $product_id \ + -product_name $product_name \ + -tmp_filename ${upload_file.tmpfile} - set system_url [parameter::get -package_id [ad_acs_kernel_id] -parameter SystemURL] - set system_name [parameter::get -package_id [ad_acs_kernel_id] -parameter SystemName] - set image_comment "from $system_url $system_name" - - set perm_thumbnail_filename "$full_dirname/product-thumbnail.jpg" - - set convert [ec_convert_path] - if {![string equal "" $convert] && [file exists $convert]} { - if [catch {exec $convert -geometry $convert_dimensions -comment \"$image_comment\" $perm_filename $perm_thumbnail_filename} errmsg ] { - ad_return_complaint 1 " - I am sorry, an error occurred converting the picture. $errmsg - " - } - } else { - ad_return_complaint 1 { - I am sorry, I could not find ImageMagick's convert utility for - image thumbnail creation. Please reconfigure this subsystem before - uploading pictures - } - } } -set linked_thumbnail [ec_linked_thumbnail_if_it_exists $dirname] +set dirname [ecommerce::resource::dirname -product_id $product_id -product_name $product_name] +# TODO: improve, along with admin add product pages +set linked_thumbnail [ecommerce::resource::image_tag -type Thumbnail -product_id $product_id -product_name $product_name] + # Need to let them select template based on category doc_body_append "[ad_admin_header "Add a Product, Continued"] @@ -233,7 +171,7 @@
-[export_form_vars product_name sku category_id_list subcategory_id_list subsubcategory_id_list one_line_description detailed_description color_list size_list style_list email_on_purchase_list search_keywords url price no_shipping_avail_p present_p shipping shipping_additional weight linked_thumbnail product_id dirname stock_status] +[export_form_vars product_name sku category_id_list subcategory_id_list subsubcategory_id_list one_line_description detailed_description color_list size_list style_list email_on_purchase_list search_keywords url price no_shipping_avail_p present_p shipping shipping_additional weight linked_thumbnail product_id stock_status dirname] " Index: openacs-4/packages/ecommerce/www/admin/products/edit-2.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ecommerce/www/admin/products/edit-2.tcl,v diff -u -r1.9 -r1.10 --- openacs-4/packages/ecommerce/www/admin/products/edit-2.tcl 21 Apr 2008 14:18:29 -0000 1.9 +++ openacs-4/packages/ecommerce/www/admin/products/edit-2.tcl 27 Apr 2008 01:38:24 -0000 1.10 @@ -135,61 +135,21 @@ # dimensions specified in parameters/whatever.ini) if { [exists_and_not_null upload_file] } { - - # this takes the upload_file and sticks its contents into a temporary - # file (will be deleted when the thread ends) + + # tmp file will be deleted when the thread ends set tmp_filename ${upload_file.tmpfile} - - # so that we'll know if it's a gif or a jpg - set file_extension [file extension $upload_file] - # copies this temp file into a permanent file - set perm_filename "$full_dirname/product$file_extension" - ns_cp $tmp_filename $perm_filename - - # create thumbnails + # copy image & create thumbnails # thumbnails are all jpg files - # set thumbnail dimensions - set use_both_param_dimensions [parameter::get -parameter ThumbnailSizeOuterlimits] - set thumbnail_width_is_blank [catch {set thumbnail_width [parameter::get -parameter ThumbnailWidth]} ] - set thumbnail_height_is_blank [catch {set thumbnail_height [parameter::get -parameter ThumbnailHeight]} ] - if { $use_both_param_dimensions } { - set convert_dimensions "${thumbnail_width}x${thumbnail_height}>" - } else { - if { $thumbnail_width_is_blank } { - if { $thumbnail_height_is_blank } { - set convert_dimensions "100x10000" - } else { - set convert_dimensions "10000x${thumbnail_height}" - } - } else { - set convert_dimensions "${thumbnail_width}x10000" - } - } + ecommerce::resource::make_product_images \ + -file_extension [file extension $upload_file] \ + -product_id $product_id \ + -tmp_filename ${upload_file.tmpfile} - set system_url [parameter::get -package_id [ad_acs_kernel_id] -parameter SystemURL] - set system_name [parameter::get -package_id [ad_acs_kernel_id] -parameter SystemName] - set image_comment "from $system_url $system_name" - - set perm_thumbnail_filename "$full_dirname/product-thumbnail.jpg" - - set convert [ec_convert_path] - if {![string equal "" $convert] && [file exists $convert]} { - if [catch {exec $convert -geometry $convert_dimensions -comment \"$image_comment\" $perm_filename $perm_thumbnail_filename} errmsg ] { - ad_return_complaint 1 " - I am sorry, an error occurred converting the picture. $errmsg - " - } - } else { - ad_return_complaint 1 { - I am sorry, I could not find ImageMagick's convert utility for - image thumbnail creation. Please reconfigure this subsystem before - uploading pictures - } - } } +set dirname [ecommerce::resource::dirname -product_id $product_id -product_name $product_name] set linked_thumbnail [ec_linked_thumbnail_if_it_exists $dirname] doc_body_append "[ad_admin_header "Confirm Product Changes"] Index: openacs-4/packages/ecommerce/www/admin/products/import-images-2.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ecommerce/www/admin/products/import-images-2.tcl,v diff -u -r1.2 -r1.3 --- openacs-4/packages/ecommerce/www/admin/products/import-images-2.tcl 24 Feb 2005 13:33:15 -0000 1.2 +++ openacs-4/packages/ecommerce/www/admin/products/import-images-2.tcl 27 Apr 2008 01:38:24 -0000 1.3 @@ -64,29 +64,6 @@ set errors 0 set success_count 0 -# Get the values that we use repeatedly in the main process loop(s) - -set products_root_path "[ec_data_directory][ec_product_directory]" -# prepare to use Imagemajicks convert tool -set convert [ec_convert_path] -if {[string equal "" $convert] || ![file exists $convert]} { - ad_return_complaint 1 { - I am sorry, I could not find ImageMagick's convert utility for - image thumbnail creation. Please reconfigure this subsystem before - uploading pictures - } -} - -# set thumbnail dimensions -set use_both_param_dimensions [parameter::get -parameter ThumbnailSizeOuterlimits] -set thumbnail_width_is_blank [catch {set thumbnail_width [parameter::get -parameter ThumbnailWidth]} ] -set thumbnail_height_is_blank [catch {set thumbnail_height [parameter::get -parameter ThumbnailHeight]} ] -# set internal comment for created thumbnail -set system_url [parameter::get -package_id [ad_acs_kernel_id] -parameter SystemURL] -set system_name [parameter::get -package_id [ad_acs_kernel_id] -parameter SystemName] -set image_comment "from $system_url $system_name" - - # Continue reading the file till the end but stop when an error # occured. @@ -129,7 +106,7 @@ # Assign the values in the datafile row to the required field names. foreach required_field_name $required_field_names { - set $required_field_name [lindex ${required_field_name}_column] + set $required_field_name [lindex $elements [lsearch -exact $field_names $required_field_name]] if { [empty_string_p $required_field_name] } { incr errors } @@ -142,44 +119,26 @@ # Check if there is a product with the give sku. # otherwise, there is no place to copy the product image to. - set product_id [db_string product_check {select product_id from ec_products where sku = :sku;} -default ""] + set product_id [db_string product_check {select product_id from ec_products where sku = :sku} -default ""] if { $product_id != ""} { # We found a product_id for the given sku # get the product directory - regsub - all {[a-zA-z]} $dirname "" product_id - set subdirectory [ec_product_file_directory $product_id] - set full_dir_path [file join ${products_root_path} ${subdirectory} ${dirname}] - set file_suffix [string range $image_fullpathname end-3 end] - set product_image_location [file join $full_dir_path "product${file_suffix}" ] - # update the product image - if { [catch {file copy $image_fullpathname $product_image_location} ] } { + + # copy image & create thumbnails + # thumbnails are all jpg files + + if { [catch {ecommerce::resource::make_product_images \ + -file_extension [file extension $image_fullpathname] \ + -product_id $product_id \ + -tmp_filename $image_fullpathname} errmsg ] } { + doc_body_append "

Error!Image update of $sku failed with error:<\p>

$errmsg

" } else { doc_body_append "

Imported images for product: $sku

" # A product row has been successfully processed, increase counter incr success_count } - # create a thumbnail - if { $use_both_param_dimensions } { - set convert_dimensions "${thumbnail_width}x${thumbnail_height}>" - } else { - if { $thumbnail_width_is_blank } { - if { $thumbnail_height_is_blank } { - set convert_dimensions "100x10000" - } else { - set convert_dimensions "10000x${thumbnail_height}" - } - } else { - set convert_dimensions "${thumbnail_width}x10000" - } - } - set perm_thumbnail_filename [file join $full_dir_path "product-thumbnail.jpg"] - - if [catch {exec $convert -geometry $convert_dimensions -comment \"$image_comment\" $product_image_location $perm_thumbnail_filename} errmsg ] { - doc_body_append "

Error! Could not create thumbnail for product: $sku Error is: $errmsg

" - } - } else { # Let them know this sku is not in the catalog Index: openacs-4/packages/ecommerce/www/admin/products/import-images.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ecommerce/www/admin/products/import-images.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/ecommerce/www/admin/products/import-images.adp 27 Apr 2008 01:38:24 -0000 1.1 @@ -0,0 +1,42 @@ + +@page_title@ +@context_bar;noquote@ + +t + +

@page_title@

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

Notes:

+ +

+ + This page uploads a data file containing product information to bulk import product images into the catalog. 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 and + the remaining lines contain the values for the specified fields, one line per product. +

+ +

+ sku and image_fullpathname are the only fields used. All other field names and values are ignored. sku should contain product sku values. image_fullpathname should contain absolute file references, one per sku. For example a value for image_fullpathname might look like: /var/tmp/boots/sidekick-3000.jpg +

Index: openacs-4/packages/ecommerce/www/admin/products/import-images.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ecommerce/www/admin/products/import-images.tcl,v diff -u -r1.2 -r1.3 --- openacs-4/packages/ecommerce/www/admin/products/import-images.tcl 24 Feb 2005 13:33:15 -0000 1.2 +++ openacs-4/packages/ecommerce/www/admin/products/import-images.tcl 27 Apr 2008 01:38:24 -0000 1.3 @@ -30,50 +30,6 @@ ad_require_permission [ad_conn package_id] admin -doc_body_append "[ad_admin_header "Bulk Import Product Images"] +set page_title "Bulk Import Product Images" +set context_bar [template::adp_parse [acs_root_dir]/packages/[ad_conn package_key]/www/contextbar [list context_addition "Bulk Import Product Images"]] -

Bulk Import Product Images

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

- -Notes: -

- -

- - This page uploads a data file containing product information to bulk import product images into the catalog. 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 and - the remaining lines contain the values for the specified fields, one line per product. -

-
-

- sku and image_fullpathname are the only fields used. All other field names and values are ignored. sku should contain product sku values. image_fullpathname should contain absolute file references, one per sku. For example a value for image_fullpathname might look like: /var/tmp/boots/sidekick-3000.jpg -

-

- -[ad_admin_footer] -" Index: openacs-4/packages/ecommerce/www/admin/products/upload-utilities.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ecommerce/www/admin/products/upload-utilities.tcl,v diff -u -r1.5 -r1.6 --- openacs-4/packages/ecommerce/www/admin/products/upload-utilities.tcl 24 Feb 2005 13:33:15 -0000 1.5 +++ openacs-4/packages/ecommerce/www/admin/products/upload-utilities.tcl 27 Apr 2008 01:38:24 -0000 1.6 @@ -55,7 +55,7 @@ products, and creates thumbnails for them. Place product images in a set of directories accessible by this server. Then use this utility to upload a file that maps product sku to the location of the product images - full_imagepathname. This option is untested and therefore buggy, but will be tested over the next day or so + full_imagepathname.

<%= [ec_linked_thumbnail_if_it_exists $dirname] %>' || '\n' + || '' || '\n' + || '' || '\n' || ' <%= $one_line_description %>' || '\n' || '
' || '\n' Index: openacs-4/packages/ecommerce/tcl/resource-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ecommerce/tcl/resource-procs.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/ecommerce/tcl/resource-procs.tcl 27 Apr 2008 01:38:23 -0000 1.1 @@ -0,0 +1,265 @@ +ad_library { + + Ecommerce resource (eg. image) related procs + + @author Mark Aufflick (mark@aufflick.com) + @creation-date 2008-04-26 + @cvs-id $Id: resource-procs.tcl,v 1.1 2008/04/27 01:38:23 marka Exp $ +} + +namespace eval ecommerce::resource {} + +ad_proc -private ecommerce::resource::make_product_images { + -file_extension + -product_id + {-product_name ""} + {-dirname ""} + -tmp_filename +} { + This proc creates the thumbnail and product image sized versions of an uploaded image, + and puts them in the relevant place. + + Caller is responsible for deleting the temporary file if required (uploaded files are usually deleted + when the thread ends). + + Extension is currently required. Could be made optional by using 'file' to interrogate + the image file binary. + + Product name should only be supplied for new products. For existing products to be updated, + supply either dirname (from ec_products) or simply leave both dirname and product_name blank/missing. + + The uplodade image is currently restricted to Jpegs - TODO: resolve this + + @param -file_extension the extension of the original image file type + @param -product_id + @param -product_name + @param -dirname + @param -tmp_filename the temporary filename from your image upload etc. + + @return nothing yet + +} { + + if { $file_extension ne ".jpg" } { + ad_return_error "Bad file format" "Sorry, currently only .jpg images are supported, you uploaded a $file_extension file" + } + + # get the directory name + set resource_path [ecommerce::resource::resource_path -product_id $product_id -product_name $product_name -dirname $dirname] + + # permanent full size filename + set perm_filename "$resource_path/product[string tolower $file_extension]" + + # copy temp file to permanent location + ns_cp $tmp_filename $perm_filename + + # thumbnails are all jpg files + set thumbnail [ecommerce::resource::resize_image -type Thumbnail -filename $perm_filename -dest_dir $resource_path] + ecommerce::resource::resize_image -type ProductImage -filename $perm_filename -dest_dir $resource_path + + return $thumbnail +} + +ad_proc -private ecommerce::resource::resize_image { + -type + -filename + -dest_dir +} { } { + + # get dimensions + set use_both_param_dimensions [parameter::get -parameter "${type}SizeOuterlimits"] + set width_is_blank [catch {set width [parameter::get -parameter "${type}Width"]} ] + set height_is_blank [catch {set height [parameter::get -parameter "${type}Height"]} ] + if { $use_both_param_dimensions } { + set convert_dimensions "${width}x${height}>" + } else { + if { $width_is_blank } { + if { $height_is_blank } { + set convert_dimensions "100x10000" + } else { + set convert_dimensions "10000x${height}" + } + } else { + set convert_dimensions "${width}x10000" + } + } + + set system_url [parameter::get -package_id [ad_acs_kernel_id] -parameter SystemURL] + set system_name [parameter::get -package_id [ad_acs_kernel_id] -parameter SystemName] + set image_comment "from $system_url $system_name" + + set new_filename "$dest_dir/product-[string tolower $type].jpg" + + set convert [ec_convert_path] + if {![string equal "" $convert] && [file exists $convert]} { + if [catch {exec $convert -geometry $convert_dimensions -comment \"$image_comment\" $filename $new_filename} errmsg ] { + ad_return_complaint 1 " + I am sorry, an error occurred converting the picture. $errmsg + " + } + } else { + ad_return_complaint 1 { + I am sorry, I could not find ImageMagick's convert utility for + image thumbnail creation. Please reconfigure this subsystem before + uploading pictures + } + } + + return $new_filename +} + +ad_proc -private ecommerce::resource::dirname { + -product_id + {-product_name ""} + {-dirname ""} +} { + Legacy ecommerce idea of dirname, lives under the product dir and based on original product name. + + should refactor away any dealing with this directly and combine with the subdirname... + + Product name should only be supplied for new products. For existing products to be updated, + supply either dirname (from ec_products) or simply leave both dirname and product_name blank/missing. + +} { + + # if the original calling proc passed in a dirname, use that + if {$dirname ne ""} { + return $dirname + } + + # If no product name, look up the dirname in the db TODO: move to xql + if {$product_name eq ""} { + return [db_string lookup_dirname "select dirname from ec_products where product_id = :product_id"] + } + + # we're creating an initial dirname + + # let's have dirname 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"}] { + #maybe there aren't 4 letters in the product name + set dirname "$letters_in_product_name$product_id" + } + return $dirname +} + +ad_proc -private ecommerce::resource::resource_path { + -product_id + {-dirname ""} + {-product_name ""} +} { + This proc returns the directory for images and other resources. + + Product name should only be supplied for new products. For existing products to be updated, + supply either dirname (from ec_products) or simply leave both dirname and product_name blank/missing. + + + The directory path is guaranteed to exist. + + @param -product_id + @param -product_name + @param -dirname + + @return disk path to product resource directory +} { + # find the ecommerce filesystem + set subdirectory "[ec_data_directory][ec_product_directory][ec_product_file_directory $product_id]" + ec_assert_directory $subdirectory + + set dirname [ecommerce::resource::dirname -product_id $product_id -product_name $product_name -dirname $dirname] + set full_dirname "$subdirectory/$dirname" + ec_assert_directory $full_dirname + + return $full_dirname +} + +ad_proc -private ecommerce::resource::resource_url { + -product_id + {-dirname ""} + {-product_name ""} +} { + This proc returns the directory for images and other resources. + + Product name should only be supplied for new products. For existing products to be updated, + supply either dirname (from ec_products) or simply leave both dirname and product_name blank/missing. + + + The directory path is guaranteed to exist. + + @param -product_id + @param -product_name + @param -dirname + + @return url path to product resource directory +} { + set dirname [ecommerce::resource::dirname -product_id $product_id -product_name $product_name -dirname $dirname] + return "[ec_url]product-file/[ec_product_file_directory $product_id]/$dirname" +} + + +# XXX TODO: provide memoized version + +ad_proc -private ecommerce::resource::image_info { + {-type ""} + -product_id + {-product_name ""} + {-dirname ""} +} { + Product name should only be supplied for new products. For existing products to be updated, + supply either dirname (from ec_products) or simply leave both dirname and product_name blank/missing. + + Type is currently one of Thumbail or ProductImage (sizes as per application params) or Full or blank + (for the original image). + + TODO: do something about alt etc. + + @param -type + @param -product_id + @param -product_name + @param -dirname + + + @return list (for array set) of: path, width, height or empty array if no such file +} { + set resource_path [ecommerce::resource::resource_path -product_id $product_id -product_name $product_name -dirname $dirname] + set resource_url [ecommerce::resource::resource_url -product_id $product_id -product_name $product_name -dirname $dirname] + + if {$type ne "" && $type ne "Full"} { + set type "-[string tolower $type]" + } + + set filename "product${type}.jpg" + + if { [file exists "$resource_path/$filename"] } { + # TODO: what if full size image not jpeg? + set thumbnail_size [ns_jpegsize "$resource_path/$filename"] + + return [list path "$resource_path/$filename" url "$resource_url/$filename" width [lindex $thumbnail_size 0] height [lindex $thumbnail_size 1]] + } + + ns_log Notice "unable find image info for: type: $type product_id: $product_id product_name: $product_name dirname: $dirname" + + return [list] +} + + +ad_proc -private ecommerce::resource::image_tag { + {-type ""} + -product_id + {-product_name ""} +} { + TODO: get product name from id if not supplied + TODO: do something about alt etc. +} { + set html "" + + array set info [ecommerce::resource::image_info -type $type -product_id $product_id -product_name $product_name] + + if {[lindex $info 0] ne ""} { + set html "\"Product" + } + + return $html +} Index: openacs-4/packages/ecommerce/www/category-browse-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ecommerce/www/category-browse-oracle.xql,v diff -u -r1.1 -r1.2 --- openacs-4/packages/ecommerce/www/category-browse-oracle.xql 19 Sep 2002 23:38:18 -0000 1.1 +++ openacs-4/packages/ecommerce/www/category-browse-oracle.xql 27 Apr 2008 01:38:23 -0000 1.2 @@ -25,7 +25,7 @@ - select p.product_id, p.product_name, p.one_line_description, o.offer_code + select p.product_id, p.product_name, p.one_line_description, o.offer_code, p.dirname from $product_map($sub) m, ec_products_searchable p, ec_user_session_offer_codes o where (p.product_id=o.product_id(+) and (user_session_id=:user_session_id or user_session_id is null)) and p.product_id = m.product_id Index: openacs-4/packages/ecommerce/www/category-browse-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ecommerce/www/category-browse-postgresql.xql,v diff -u -r1.1 -r1.2 --- openacs-4/packages/ecommerce/www/category-browse-postgresql.xql 19 Sep 2002 23:38:18 -0000 1.1 +++ openacs-4/packages/ecommerce/www/category-browse-postgresql.xql 27 Apr 2008 01:38:23 -0000 1.2 @@ -25,7 +25,7 @@ - select p.product_id, p.product_name, p.one_line_description, o.offer_code + select p.product_id, p.product_name, p.one_line_description, o.offer_code, p.dirname from $product_map($sub) m, ec_products_searchable p left outer join ec_user_session_offer_codes o on (p.product_id = o.product_id and user_session_id = :user_session_id) where p.product_id = m.product_id and m.${sub}category_id = :${sub}category_id Index: openacs-4/packages/ecommerce/www/category-browse.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ecommerce/www/category-browse.tcl,v diff -u -r1.10 -r1.11 --- openacs-4/packages/ecommerce/www/category-browse.tcl 1 Mar 2005 00:01:30 -0000 1.10 +++ openacs-4/packages/ecommerce/www/category-browse.tcl 27 Apr 2008 01:38:23 -0000 1.11 @@ -178,23 +178,21 @@ set have_how_many_more_p f set count 0 -db_foreach get_regular_product_list " - select p.product_id, p.product_name, p.one_line_description, o.offer_code - from $product_map($sub) m, ec_products_searchable p left outer join ec_user_session_offer_codes o on (p.product_id = o.product_id and user_session_id = :user_session_id) - where p.product_id = m.product_id - and m.${sub}category_id = :${sub}category_id - $exclude_subproducts - order by p.product_name" { +db_foreach get_regular_product_list "sql in db specific xql filessw" { if { $count >= $start && [expr $count - $start] < $how_many } { + array set thumbnail_info [ecommerce::resource::image_info -type Thumbnail -product_id $product_id -dirname $dirname] + set image_html "" + # assumes exists... + set image_html "" + append products "
[expr $count + 1]$image_html $product_name
$one_line_description [ec_price_line $product_id $user_id $offer_code]