Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

E-Commerce Modules /

Discuss about the various e-commerce modules available:
Ecommerce, SS Shop, SilverCart and SwipeStripe
Alternatively, have a look the shared mailinglist.

Moderators: martimiz, Nicolaas, Sean, frankmullenger, biapar, Willr, Ingo, Jedateach, swaiba, simon_w

thousands of empty orders


Reply


5 Posts   782 Views

Avatar
janulka

Community Member, 80 Posts

5 April 2013 at 8:38am

Hello,

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

Avatar
HansR

Community Member, 140 Posts

13 April 2013 at 1:32pm

@janulka

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 ([url=https://groups.google.com/d/msg/silverstripe-ecommerce/Lf4nD9YqIPI/OlV8nz51k1MJ]link[/url]). 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.

Hans

Avatar
janulka

Community Member, 80 Posts

13 April 2013 at 6:49pm

Yes please!

It would be great if order creation was delayed until visitor adds an item to a cart :D

Thanks in advance!

Avatar
HansR

Community Member, 140 Posts

15 April 2013 at 9:37pm

@janulka

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 %>
      <span id="$SideBarCartID">
         <% include CartDropDownInner %>
      </span>
   <% 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.

Hans

** 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.

Avatar
janulka

Community Member, 80 Posts

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 :(