Forum OpenACS Q&A: Ecommerce Shopping Cart Change Quantities

I am having multiple problems with the shopping-cart-change-quantities.tcl page. I can increase quantities from the shopping cart, but decreasing causes this error:


[17/Feb/2001:13:21:37][16947.965637][-conn23-] Error: Ns_PgExec: result status:
 7 message: ERROR:  parser: parse error at or near ")"

[17/Feb/2001:13:21:37][16947.965637][-conn23-] Error: dbinit: error(localhost::
nh,ERROR:  parser: parse error at or near ")"
): 'select max(item_id) from ec_items where product_id=1 and color_choice is nu
ll and size_choice is null and style_choice is null and order_id=27 and item_id
 not in ()'
[17/Feb/2001:13:21:37][16947.965637][-conn23-] Error: Database operation "1row"
 failed (exception NSDB, "Query was not a statement returning rows.")
Database operation "1row" failed (exception NSDB, "Query was not a statement re
turning rows.")
    while executing
"ns_db 1row $db [db_sql_prep $sql"
    (procedure "database_to_tcl_string" line 6)
    invoked from within
"database_to_tcl_string $db "select max(item_id) from ec_items where product_id
=$product_id and color_choice [ec_decode $color_choice "" "is null" "= '..."
    ("foreach" body line 62)
    invoked from within
"foreach product_color_size_style $product_color_size_style_list {
    # quantity_to_add might be negative
    # also there are two special cases that ..."
    (file "/web/nh/www/ecommerce/shopping-cart-quantities-change.tcl" line 76)
    invoked from within
"source $script"
    (procedure "ns_sourceproc" line 6)
    invoked from within
"ns_sourceproc cns92 {}"
When setting a quantity to zero I get this error:
[17/Feb/2001:13:25:24][16947.968709][-conn26-] Error: Ns_PgExec: result status:
 7 message: ERROR:  parser: parse error at or near ")"

[17/Feb/2001:13:25:24][16947.968709][-conn26-] Error: dbinit: error(localhost::
nh,ERROR:  parser: parse error at or near ")"
): 'select max(item_id) from ec_items where product_id=1 and color_choice is nu
ll and size_choice is null and style_choice is null and order_id=27 and item_id
 not in ()'
[17/Feb/2001:13:25:24][16947.968709][-conn26-] Error: Database operation "1row"
 failed (exception NSDB, "Query was not a statement returning rows.")
Database operation "1row" failed (exception NSDB, "Query was not a statement returning rows.")
    while executing
"ns_db 1row $db [db_sql_prep $sql"
    (procedure "database_to_tcl_string" line 6)
    invoked from within
"database_to_tcl_string $db "select max(item_id) from ec_items where product_id
=$product_id and color_choice [ec_decode $color_choice "" "is null" "= '..."
    ("foreach" body line 62)
    invoked from within
"foreach product_color_size_style $product_color_size_style_list {
    # quantity_to_add might be negative
    # also there are two special cases that ..."
    (file "/web/nh/www/ecommerce/shopping-cart-quantities-change.tcl" line 76)
    invoked from within
"source $script"
    (procedure "ns_sourceproc" line 6)
    invoked from within
"ns_sourceproc cns95 {}"
Has anyone got this to work? It looks like the form variables are not getting passed to this page from the shopping cart.
Collapse
Posted by Dan Wickstrom on
The problem is probably due to the fact that ec_items has empty strings in style_choice, color_choice, and size_choice. This is probably a porting bug caused by oracle's non-standard method of converting empty strings to nulls whereas postgresql correctly inserts an empty string in the db. Try this from psql:

	acspg=# update ec_items set style_choice = null, color_choice = null, size_choice = null;
	UPDATE 3

Now try reloading the page and playing around with decreasing the quantities. It should now work. The true bug is probably at the point of insert for ec_items. I'll look around for it later when I have more time, unless you want to try and track it down.

Collapse
Posted by Dave Bauer on
Thanks. I thought the error was the "not in ()" part of this:
[17/Feb/2001:13:25:24][16947.968709][-conn26-] Error: dbinit: error(localhost::
nh,ERROR:  parser: parse error at or near ")"
): 'select max(item_id) from ec_items where product_id=1 and color_choice is nu
ll and size_choice is null and style_choice is null and order_id=27 and item_id
 not in ()'
[17/Feb/2001
I'll check the add to shopping cart routines to see if its inserting nulls or empty strings for non-existing attributes.
Collapse
Posted by Dave Bauer on
I changed the "is null"s to "=''"

instead of changing the insert code. Seems to work now. I can lower a quantity of change to 0.

Collapse
Posted by Dan Wickstrom on
You can do that, but you're fixing the symptom rather than the problem.  The data-model was designed with the assumption that the empty fields would have nulls, so there might be other points in the code that fail due to the incorrect insertion of empty strings.  Fixing the insertion points would allow the data model to function as intended and it would probably be less work in the long run.  In any event I'll take a look at it later and see if I can track it down.
Collapse
Posted by Dave Bauer on
Dan,

Places I changes from $QQcolor_list etc... or [DoubleApos $color_choice : to [db_postgres_null_sql ...]

www/admin/ecommerce/products/ add-4.tcl and edit-3.tcl

These insert the products into ec_products. If color_list, size_list, and style_list are empty it inserts nulls

www/ecommerce/shopping-cart-add.tcl

$color_choice, etc... to [db_postgres_null_sql $color_choice]

www/ecommerce/shopping-cart-quantities-change.tcl

the insert to add more items has
[DoubleApos $color_choice]

changed to [db_postgres_null_sql [DoubleApos $color_choice]]

If I find anything else I'll let you know.

If anyone wants to learn how OpenACS works, just try customizing the ecommerce module!

Collapse
Posted by Dan Wickstrom on
Excellent!  Thanks for tracking these down.  I would appreciate it if you could send me a diff when your done, so I can apply the changes to cvs.
Collapse
Posted by Don Baccus on
Gotta love this thread, open source in action!