|
3 | 3 | namespace Thoughtco\SimpleCommerceNav; |
4 | 4 |
|
5 | 5 | use Statamic; |
| 6 | +use Statamic\Facades\Collection; |
6 | 7 | use Statamic\Facades\CP\Nav; |
7 | 8 | use Statamic\Providers\AddonServiceProvider; |
8 | 9 |
|
9 | 10 | class ServiceProvider extends AddonServiceProvider |
10 | 11 | { |
11 | | - protected $scripts = [ |
12 | | - __DIR__.'/../resources/js/cp.js' |
13 | | - ]; |
14 | | - |
15 | 12 | public function boot() |
16 | 13 | { |
17 | | - Statamic::script('app', 'cp'); |
18 | | - |
19 | 14 | Statamic::booted(function () { |
20 | 15 | Nav::extend(function ($nav) { |
| 16 | + |
21 | 17 | $productsCollection = Collection::find('products'); |
22 | 18 | $couponsCollection = Collection::find('coupons'); |
23 | 19 | $ordersCollection = Collection::find('orders'); |
24 | 20 | $customersCollection = Collection::find('customers'); |
25 | 21 |
|
26 | | - $nav->create('Products') |
27 | | - ->section('Ecommerce') |
| 22 | + // add new ecommerce block |
| 23 | + $nav->content('Ecommerce') |
28 | 24 | ->url($productsCollection->showUrl()) |
29 | | - ->can('view', $productsCollection); |
30 | | - |
31 | | - $nav->create('Coupons') |
32 | | - ->section('Ecommerce') |
33 | | - ->url($couponsCollection->showUrl()) |
34 | | - ->can('view', $couponsCollection); |
35 | | - |
36 | | - $nav->create('Orders') |
37 | | - ->section('Ecommerce') |
38 | | - ->url($ordersCollection->showUrl()) |
39 | | - ->can('view', $ordersCollection); |
| 25 | + ->icon('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48"> <g transform="matrix(3.4285714285714284,0,0,3.4285714285714284,0,0)"><g> <line x1="7" y1="4.5" x2="7" y2="3" style="fill: none;stroke: #000000;stroke-linecap: round;stroke-linejoin: round"></line> <g> <path d="M5.5,8.5c0,.75.67,1,1.5,1s1.5,0,1.5-1c0-1.5-3-1.5-3-3,0-1,.67-1,1.5-1s1.5.38,1.5,1" style="fill: none;stroke: #000000;stroke-linecap: round;stroke-linejoin: round"></path> <line x1="7" y1="9.5" x2="7" y2="11" style="fill: none;stroke: #000000;stroke-linecap: round;stroke-linejoin: round"></line> </g> <circle cx="7" cy="7" r="6.5" style="fill: none;stroke: #000000;stroke-linecap: round;stroke-linejoin: round"></circle> </g></g></svg>') |
| 26 | + ->children([ |
| 27 | + |
| 28 | + 'Products' => $nav->item('Products') |
| 29 | + ->url($productsCollection->showUrl()) |
| 30 | + ->can('view', $productsCollection), |
| 31 | + |
| 32 | + 'Coupons' => $nav->item('Coupons') |
| 33 | + ->url($couponsCollection->showUrl()) |
| 34 | + ->can('view', $couponsCollection), |
| 35 | + |
| 36 | + 'Orders' => $nav->item('Orders') |
| 37 | + ->url($ordersCollection->showUrl()) |
| 38 | + ->can('view', $ordersCollection), |
| 39 | + |
| 40 | + 'Customers' => $nav->item('Customers') |
| 41 | + ->url($customersCollection->showUrl()) |
| 42 | + ->can('view', $customersCollection), |
| 43 | + |
| 44 | + ]) |
| 45 | + ->active('|products|coupons|orders|customers'); |
| 46 | + |
| 47 | + // remove from 'collections' |
| 48 | + $collections = $nav->content('Collections'); |
| 49 | + $children = $collections->children()() |
| 50 | + ->filter(function ($child) { |
| 51 | + return !in_array($child->name(), ['Products', 'Coupons', 'Orders', 'Customers']); |
| 52 | + }); |
| 53 | + $collections->children(function() use ($children) { return $children; }); |
40 | 54 |
|
41 | | - $nav->create('Customers') |
42 | | - ->section('Ecommerce') |
43 | | - ->url($customersCollection->showUrl()) |
44 | | - ->can('view', $customersCollection); |
45 | 55 | }); |
46 | 56 | }); |
47 | 57 | } |
|
0 commit comments