🎉 Simple Commerce v3.0 is out! Includes new features & some big quality of life improvements.

Simple Commerce Logo

Content Drivers

Simple Commerce has a concept of 'content drivers'. They let you switch out how & where 'things' in Simple Commerce are stored.

A content driver consists of a 'repository' which implements a couple of methods to handle creating/finding/saving bits of content. They work in a very similar way to Repositories in Statamic itself.

The Database Orders feature is essentially two content drivers which deal with getting content from the database.

You can configure content drivers for the following 'things':

  • Products
  • Orders
  • Coupons
  • Customers

Configuration

1'content' => [
2 'coupons' => [
3 'repository' => \DoubleThreeDigital\SimpleCommerce\Coupons\EntryCouponRepository::class,
4 'collection' => 'coupons',
5 ],
6 
7 'customers' => [
8 'repository' => \DoubleThreeDigital\SimpleCommerce\Customers\EntryCustomerRepository::class,
9 'collection' => 'customers',
10 ],
11 
12 'orders' => [
13 'repository' => \DoubleThreeDigital\SimpleCommerce\Orders\EntryOrderRepository::class,
14 'collection' => 'orders',
15 ],
16 
17 'products' => [
18 'repository' => \DoubleThreeDigital\SimpleCommerce\Products\EntryProductRepository::class,
19 'collection' => 'products',
20 ],
21],

As you can see, each bit of 'content' has its own 'repository' attached, along with any configuration options that may be needed.

Example

Here's a bare-bones example of a content driver repository to get you started:

1<?php
2 
3namespace DoubleThreeDigital\SimpleCommerce\Products;
4 
5use DoubleThreeDigital\SimpleCommerce\Contracts\Product;
6use DoubleThreeDigital\SimpleCommerce\Contracts\ProductRepository as RepositoryContract;
7 
8class EntryProductRepository implements RepositoryContract
9{
10 public function all()
11 {
12 return [];
13 }
14 
15 public function find($id): ?Product
16 {
17 //
18 }
19 
20 public function make(): Product
21 {
22 return app(Product::class);
23 }
24 
25 public function save(Product $product): void
26 {
27 //
28 }
29 
30 public function delete(Product $product): void
31 {
32 //
33 }
34 
35 public static function bindings(): array
36 {
37 return [];
38 }
39}

You may find it helpful to review the built-in content driver repositories while building a custom one.

Code highlighting provided by Torchlight.

Edit this page