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)
- || ' <%= [ec_linked_thumbnail_if_it_exists $dirname] %> | ' || 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'
+ || '' || '\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'
- || ' <%= [ec_linked_thumbnail_if_it_exists $dirname] %> | ' || '\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'
+ || '' || '\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 ""
+ }
+
+ 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] |
"
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 @@
| | |