Index: openacs-4/packages/ecommerce/ecommerce.info
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/ecommerce/ecommerce.info,v
diff -u -r1.44 -r1.45
--- openacs-4/packages/ecommerce/ecommerce.info 4 Sep 2008 12:24:05 -0000 1.44
+++ openacs-4/packages/ecommerce/ecommerce.info 15 Nov 2008 12:06:59 -0000 1.45
@@ -7,7 +7,7 @@
f
t
-
+
Janine Sisk
Bart Teeuwisse
Alfred Werner
@@ -17,7 +17,7 @@
This module implements a standard business-to-consumer Web store service. A feature summary is included with the documentaion.
0
-
+
@@ -31,6 +31,9 @@
+
+
+
Index: openacs-4/packages/ecommerce/tcl/ecds-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/ecommerce/tcl/ecds-procs.tcl,v
diff -u -r1.5 -r1.6
--- openacs-4/packages/ecommerce/tcl/ecds-procs.tcl 27 Sep 2008 12:27:03 -0000 1.5
+++ openacs-4/packages/ecommerce/tcl/ecds-procs.tcl 15 Nov 2008 12:07:04 -0000 1.6
@@ -62,6 +62,7 @@
set brandname_width 16
set brandname_len_limit 14
regsub -all -- { } $brand_name {} brandname_new
+ regsub -all -- {&} $brandname_new {} brandname_new
if { [string length $brandname_new] > $brandname_width } {
set brandname_end [expr { [string last " " [string range $brandname_new 0 $brandname_width] ] - 1 } ]
if { $brandname_end < 0 } {
@@ -71,8 +72,8 @@
regsub {[^a-zA-Z0-9]+\.\.} $brandname_new {} brandname_new
}
regsub -all -- { } $brandname_new {-} brandname_new
- set brandname_new [string trim [string tolower $brandname_new]]
+ set brandname_new [string trim [string tolower $brandname_new]]
set sku "${brandname_new}-${product_sku}"
}
return $sku
@@ -81,8 +82,10 @@
ad_proc -private ecds_base_shipping_price_from_order_value {
total_price
+ base_ship_price
} {
returns the value based shipping price, based on the value of the total price of items in the cart
+ and perhaps the value of any existing shipping price
this value based shipping price gets added to the base_shipping_price
this is ignored when using a shipping gateway
} {
@@ -99,7 +102,10 @@
# set value_based_shipping 0
# }
- set value_based_shipping 0
+ # example 3 using 1/x multiplier
+ set multiplier [f::max [expr { ( 15. / ( $total_price + 4 ) ) - 0.05 } ] 0]
+
+ set value_based_shipping [expr { $total_price * $multiplier } ]
return $value_based_shipping
}
@@ -1164,6 +1170,7 @@
ecommerce::resource::make_product_images -product_id $product_id -tmp_filename $image_import_location
}
}
+ ecds_file_cache_product $product_id
}
return $import_conditions_met
}
@@ -1826,3 +1833,119 @@
set email [parameter::get -parameter CustomerServiceEmailAddress -default [ad_system_owner]]
return $email
}
+
+
+ad_proc -private ecds_file_cache_product {
+ product_id
+} {
+ creates or updates a static page of product?product_id for web crawlers
+} {
+ set cache_product_as_file [parameter::get -parameter CacheProductAsFile -default 0]
+ # Should we be creating or updating a static page for this product_id?
+
+ # the static page for each product is $sku.html
+ # using ${product_id}.html may not work if some products have an integer sku
+ db_0or1row check_product_history {select sku,last_modified from ec_products where product_id = :product_id }
+
+ if { $cache_product_as_file && [info exists sku] } {
+ set reserved_filename_list [list account address-2 address-international-2 address-international address billing browse-categories card-security category-browse-subcategory category-browse-subsubcategory category-browse checkout-2 checkout-3 checkout-one-form-2 checkout-one-form checkout credit-card-correction-2 credit-card-correction delete-address finalize-order gift-certificate-billing gift-certificate-claim-2 gift-certificate-claim gift-certificate-finalize-order gift-certificate-order-2 gift-certificate-order-3 gift-certificate-order-4 gift-certificate-order gift-certificate-thank-you gift-certificate index mailing-list-add-2 mailing-list-add mailing-list-remove order payment policy-privacy policy-sales-terms policy-shipping process-order-quantity-shipping process-payment product-search product product2 review-submit-2 review-submit-3 review-submit select-shipping shopping-cart-add shopping-cart-delete-from shopping-cart-quantities-change shopping-cart-retrieve-2 shopping-cart-retrieve-3 shopping-cart-retrieve shopping-cart-save-2 shopping-cart-save shopping-cart sitemap.xml thank-you track update-user-classes-2 update-user-classes]
+ # verify that the sku is not a root openacs page
+ if { [lsearch -exact $reserved_filename_list $sku] < 0 } {
+ # the cached files go into the www/ec_url dir so we do not have to worry about overwriting
+ # ecommerce files, but the www/ec_url dir takes presidence in url resolving, so still must check
+
+ set cache_dir "[file join [acs_root_dir] www [string trim [ec_url] /]]"
+ ec_assert_directory $cache_dir
+ set filepathname [file join $cache_dir ${sku}.html]
+ set url "[ec_insecure_location][ec_url]product?usca_p=t&product_id=${product_id}"
+ set product_file_exists [file exists $filepathname]
+ if { ( $product_file_exists eq 0 ) || ( $product_file_exists && [clock scan [string range $last_modified 0 18]] > [file mtime $filepathname] ) } {
+ # product file either does not exist or has been updated after the current file modification time
+ # updating file
+ ns_log Notice "ecds_file_cache_product: product_id = $product_id waiting 15 seconds before trying, in case we recently ns_http ed"
+ # ec_create_new_session_if_necessary needs to NOT automatically redirect the following ns_http get
+ # to the static html file, since we want to update that file with a fresh http request
+ # so, we need to remove this file before requesting it.
+ if { [file exists $filepathname ] } {
+ file delete $filepathname
+ }
+ after 15000
+ if { [catch {set get_id [ns_http queue -timeout 65 $url]} err ]} {
+ set page $err
+ ns_log Error "ecds_file_cache_product: url=$url error: $err"
+ } else {
+ ns_log Notice "ecds_file_cache_product: ns_httping $url"
+ # removed -timeout "30" from next statment, because it is unrecognized for this instance..
+ if { [catch { ns_http wait -result page -status status $get_id } err2 ]} {
+ ns_log Error "ecds_file_cache_product: ns_http wait $err2"
+ }
+
+ if { ![info exists status] || $status ne "200" } {
+ # no page info returned, just return error
+ if { ![info exists status] } {
+ set status "not exists"
+ }
+ set page "ecds_file_cache_product Error: url timed out with status $status"
+ ns_log Notice $page
+ } else {
+ #if { [file exists $filepathname ] } {
+ # \[file delete $filepathname\]
+ #}
+ #put page into acs_root_dir/www not packages/ecommerce/www
+ if { [catch {open $filepathname w} fileId]} {
+ ns_log Error "ecds_file_cache_product: unable to write to file $filepathname"
+ ad_script_abort
+ } else {
+ # strip extra lines and funny characters
+ regsub -all -- {[\f\e\r\v\n\t]} $page { } oneliner
+ # strip extra spaces
+ regsub -all -- {[ ][ ]*} $oneliner { } oneliner2
+ set page $oneliner2
+ puts $fileId $page
+ ns_log Notice "ecds_file_cache_product: writing $filepathname"
+ close $fileId
+ }
+ }
+ }
+ }
+ } else {
+ ns_log Warning "ecds_file_cache_product: sku is same as a reserved ecommerce filename for product_id $product_id"
+ }
+ }
+}
+
+
+ad_proc -private ecds_create_cache_product_files {
+} {
+ creates or updates the static pages referenced in the ecommerce sitemap.xml
+} {
+
+ set cache_product_as_file [parameter::get -parameter CacheProductAsFile -default 0]
+ ns_log Notice "ecds_create_cache_product_files: starting.."
+ if { $cache_product_as_file } {
+ set sitemap_list [db_list_of_lists get_catalog_product_ids "
+ select product_id from ec_products
+ where active_p='t' and present_p = 't' and sku is not null
+ order by last_modified desc"]
+
+ foreach product_id $sitemap_list {
+ ecds_file_cache_product $product_id
+ }
+ }
+ ns_log Notice "ecds_create_cache_product_files: ended"
+}
+
+ad_proc -private ecds_refresh_import_products_from_vendor {
+ vendor_abbrev
+} {
+ creates or updates product info for imported products of a specific vendor
+} {
+
+ set vendor_product_ids_list [db_list_of_lists get_vendor_product_ids "
+ select product_id from ec_custom_product_field_values
+ where vendorabbrev = :vendor_abbrev"]
+ set product_count [llength $vendor_product_ids_list]
+ foreach product_id $vendor_product_ids_list {
+ ecds_import_product_from_vendor_site $vendor_abbrev product_id $product_id
+ }
+}
Index: openacs-4/packages/ecommerce/tcl/ecommerce-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/ecommerce/tcl/ecommerce-procs.tcl,v
diff -u -r1.30 -r1.31
--- openacs-4/packages/ecommerce/tcl/ecommerce-procs.tcl 11 Oct 2008 10:51:38 -0000 1.30
+++ openacs-4/packages/ecommerce/tcl/ecommerce-procs.tcl 15 Nov 2008 12:07:03 -0000 1.31
@@ -1459,6 +1459,17 @@
# For this page continue
ns_log Notice "ec_create_new_session_if_necessary: ec_create_session cookies are off but that's okay, they aren't required."
+
+ set current_url [ns_conn url]
+ if { [parameter::get -parameter CacheProductAsFile -default 0] && [string match "*[ec_url]product*" $current_url ] } {
+ regexp {product_id=([1-9][0-9]*)} $current_url scratch product_id
+ db_0or1row get_sku_from_product_id "select sku from ec_products where product_id = :product_id"
+ if { [info exists sku] && [file exists "[file join [acs_root_dir] www [string trim [ec_url] /] ${sku}.html]"] } {
+ # this is a valid product url, redirect to the existing static version
+ ad_returnredirect "[ec_url]${sku}.html"
+ ad_script_abort
+ }
+ }
} elseif {[string compare $_ec_cookie_requirement "shopping_cart_required"] == 0} {
Index: openacs-4/packages/ecommerce/www/index.vuh
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/ecommerce/www/index.vuh,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/ecommerce/www/index.vuh 15 Nov 2008 12:07:05 -0000 1.1
@@ -0,0 +1,36 @@
+# ecommmerce/www/product-file.vuh
+ad_page_contract {
+
+ Return a product image
+ @author jerry@hollyjerry.org
+ @creation-date winter 2001
+ @cvs-id
+} {
+}
+
+# set is_url [ad_conn url]
+# set e_url [ad_conn extra_url]
+# set f [ad_conn file]
+set path_info [ad_conn path_info]
+
+# if path_info contains no /, lookup f(path_info) as sku
+if { [string match "*.html" $path_info] } {
+ set sku [string range $path_info 0 end-5]
+ db_0or1row get_product_id_from_sku_if_exists "select product_id from ec_products where sku =:sku"
+}
+
+# no need to verify that the sku is not a root openacs page, since root openacs pages are chosen over index.vuh redirects
+# set reserved_filename_list [list account address-2 address-international-2 address-international address billing browse-categories card-security category-browse-subcategory category-browse-subsubcategory category-browse checkout-2 checkout-3 checkout-one-form-2 checkout-one-form checkout credit-card-correction-2 credit-card-correction delete-address finalize-order gift-certificate-billing gift-certificate-claim-2 gift-certificate-claim gift-certificate-finalize-order gift-certificate-order-2 gift-certificate-order-3 gift-certificate-order-4 gift-certificate-order gift-certificate-thank-you gift-certificate index mailing-list-add-2 mailing-list-add mailing-list-remove order payment policy-privacy policy-sales-terms policy-shipping process-order-quantity-shipping process-payment product-search product product2 review-submit-2 review-submit-3 review-submit select-shipping shopping-cart-add shopping-cart-delete-from shopping-cart-quantities-change shopping-cart-retrieve-2 shopping-cart-retrieve-3 shopping-cart-retrieve shopping-cart-save-2 shopping-cart-save shopping-cart sitemap.xml thank-you track update-user-classes-2 update-user-classes]
+# \[lsearch -exact $reserved_filename_list $path_info\] < 0
+
+if { [info exists product_id] } {
+# set redirect_url "\[file join \[ec_url\] product\]"
+ rp_form_put usca_p t
+ rp_form_put product_id $product_id
+# ns_log Notice "ecommerce/www/index.vuh redirecting to $path_info"
+ rp_internal_redirect product
+} else {
+ ns_log Notice "packages/www/ecommerce/index.vuh: path requested and not found: $path_info"
+ rp_form_put product_id -1
+ rp_internal_redirect product
+}
\ No newline at end of file
Index: openacs-4/packages/ecommerce/www/sitemap.xml.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/ecommerce/www/sitemap.xml.tcl,v
diff -u -r1.4 -r1.5
--- openacs-4/packages/ecommerce/www/sitemap.xml.tcl 19 Oct 2008 20:50:44 -0000 1.4
+++ openacs-4/packages/ecommerce/www/sitemap.xml.tcl 15 Nov 2008 12:07:06 -0000 1.5
@@ -1,20 +1,43 @@
#sitemap.xml.tcl
+set cache_product_as_file [parameter::get -parameter CacheProductAsFile -default 0]
set sitemap_xml "
\n"
-set sitemap_list [db_list_of_lists get_catalog_products "
- select product_id, last_modified from ec_products
+
+if { $cache_product_as_file } {
+
+ set sitemap_list [db_list_of_lists get_catalog_sku_products "
+ select sku, last_modified from ec_products
+ where active_p='t' and present_p = 't' and sku is not null
+ order by last_modified desc"]
+
+ foreach url_pair $sitemap_list {
+ set sku [lindex $url_pair 0]
+ set last_modified [lindex $url_pair 1]
+ set url "[ec_insecure_location][ec_url]${sku}.html"
+ set last_mod ""
+ regsub -- { } $last_modified {T} last_mod
+ append last_mod ":00"
+ append sitemap_xml "$url${last_mod}\n"
+ }
+
+} else {
+
+ set sitemap_list [db_list_of_lists get_catalog_products "
+ select product_id, last_modified from ec_products
where active_p='t' and present_p = 't'
order by last_modified desc"]
-foreach url_pair $sitemap_list {
- set product_id [lindex $url_pair 0]
- set last_modified [lindex $url_pair 1]
- set url "[ec_insecure_location][ec_url]product?usca_p=t&product_id=${product_id}"
- set last_mod ""
- regsub -- { } $last_modified {T} last_mod
- append last_mod ":00"
- append sitemap_xml "$url${last_mod}\n"
+ foreach url_pair $sitemap_list {
+ set product_id [lindex $url_pair 0]
+ set last_modified [lindex $url_pair 1]
+ set url "[ec_insecure_location][ec_url]product?usca_p=t&product_id=${product_id}"
+ set last_mod ""
+ regsub -- { } $last_modified {T} last_mod
+ append last_mod ":00"
+ append sitemap_xml "$url${last_mod}\n"
+ }
}
+
append sitemap_xml "\n"
ns_return 200 text/xml $sitemap_xml