Cart & Orders

Under the hood, Carts and Orders are really the same thing. They live under the same collection, use the same blueprint.

Often, when a cart is being mentioned, it's just referring to an unpaid order (defined by the is_paid boolean). If is_paid is true, it'll be refered to as an order.


Cart Abandonment (Cleanup)

It can sometimes be a little frustrating to have entries for abandoned carts lying around in your Orders collection. However, if you'd prefer, Simple Commerce can be configured to automatically delete orders older than 14 days from your collection.

Simple Commerce provides a command out-of-the-box, which can be run either manually, or on demand, which will delete orders older than 14 days.

1php please sc:cart-cleanup

If you wish to run this command on a regular basis, maybe every night or every week, you can configure that in your app/Console/Kernel.php method, inside the schedule method.

2 ->daily();

For more documentation on command scheduling, please review the Laravel documentation.

Cart Drivers

Simple Commerce provides a concept of 'Cart Drivers'. A cart driver essentially is the method on which you store the customer's current Cart ID.

Two cart drivers are provided as standard: the cookie driver & the session driver. I'd generally recommend using the cookie driver, as it has a longer lifetime compared to a session, meaning the customer can come back later without losing their cart.


2 |--------------------------------------------------------------------------
3 | Cart
4 |--------------------------------------------------------------------------
5 |
6 | Configure the Cart Driver in use on your site. It's what stores/gets the
7 | Cart ID from the user's browser on every request.
8 |
9 */
11'cart' => [
12 'repository' => \DoubleThreeDigital\SimpleCommerce\Orders\Cart\Drivers\CookieDriver::class,
13 'key' => 'simple-commerce-cart',

In your config/simple-commerce.php file, you can configure the cart driver class being used and the 'key' used by the driver.

Building your own cart driver

If you need to, you can create your own cart driver. It's a relativly simple thing to do: create your class, implement a couple of methods and hey presto!

Below is a boilerplate driver class to get you started:

3namespace App\CartDrivers;
5use DoubleThreeDigital\SimpleCommerce\Contracts\CartDriver;
6use DoubleThreeDigital\SimpleCommerce\Contracts\Order;
8class YourDriver implements CartDriver
10 public function getCartKey(): string
11 {
12 //
13 }
15 public function getCart(): Order
16 {
17 //
18 }
20 public function hasCart(): bool
21 {
22 //
23 }
25 public function makeCart(): Order
26 {
27 //
28 }
30 public function getOrMakeCart(): Order
31 {
32 //
33 }
35 public function forgetCart()
36 {
37 //
38 }


Order Numbers


This only applies when storing orders as entries. If you're storing orders in a database, the order number will be automaticaly generated from the order's ID in the database.

When an order is created, a unique order number will be assigned. It'll often be formatted like so: #1234.

By default, order numbers will start at #2000 and will continue endlessly. If you wish for order numbers to start at say, #5000, you can configure that in your config/simple-commerce.php config file.

3return [
4 ...
6 /*
7 |--------------------------------------------------------------------------
8 | Order Number
9 |--------------------------------------------------------------------------
10 |
11 | If you want to, you can change the minimum order number for your store. This won't
12 | affect past orders, just ones in the future.
13 |
14 */
16 'minimum_order_number' => 2000,