Content Repositories

Content Repositories let you switch out how & where 'thing' in Simple Commerce are stored - they're pretty similar to Statamic's Repositories concept.

The Database Orders functionality is essentially two repositories which deal with getting/saving content from the database.

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

  • Products
  • Orders
  • Customers

Configuration

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

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

Example

Here's a bare-bones example of a content 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 repositories when building a custom one.