2071 Posts in 814 Topics by 448 members
|Go to End|
5 April 2013 at 8:38am
The client has small ecommerce site (SS 2.4.? (5-6-7..? I think) and ecommerce 0.8.1), and is recieving around 30 orders per month. But in database, hundreds of empty orders are being created every day, and since last time I tested one month ago, it has been created more than ten thousand of these. They are completely empty, and all have status "Cart"
What is happening? Is there a way to block this?
Thanks in advance
13 April 2013 at 1:32pm
A new cart (i.e., Order object) is created for every new visitor, and that includes any bots that visit. Yes, those empty entries are annoying.
I happen to have solved this problem for one of my sites recently (link). Basically, order creation is delayed until a visitor actually adds an item to a cart (or visits the cart or checkout pages).
If you want more details on the fix, let me know.
13 April 2013 at 6:49pm
It would be great if order creation was delayed until visitor adds an item to a cart
Thanks in advance!
15 April 2013 at 9:37pm
Attached are the changes to the PHP files (relative to version 0.9). This patch doesn't solve the problem by itself, but it does provide the needed functionality. Basically, it adds $allowCreate as a parameter to methods such as ShoppingCart::current_order() and EcommerceSiteTreeExtension::Cart()), but the default behaviour is still to create the cart.
You will still have to manually update all of your ecommerce templates. For example, my dropdown cart looks like this:
<% if Cart(0) %>
<% control Cart %>
<% include CartDropDownInner %>
<% end_control %>
<% else %>
Note the "Cart(0)" at the top. Passing 0 ensures that the cart won't be created if it doesn't exist.
I recommend temporarily inserting a user_error() call in ShoppingCart::current_order() just before the code that creates a cart. That way you can visit various pages on your website, and it will spit out an error if it tries to create a cart. Even better, the stack trace will tell you what you need to change. **
I hope that this helps.
** IMPORTANT: Clear the cache first, or open an incognito window before trying this. You won't get an error if a cart already exists for the current session.
18 April 2013 at 8:34pm
Thanks a lot for the code.
Oh, it's a shame I do not know how to use this fix for earlier version, ecommerce version on that site is 0.8.1
|Go to Top|