Skip to content

Commit 33481cb

Browse files
committed
Simplify
1 parent ee2b601 commit 33481cb

File tree

2 files changed

+33
-33
lines changed

2 files changed

+33
-33
lines changed

resources/js/cp.js

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/ServiceProvider.php

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,55 @@
33
namespace Thoughtco\SimpleCommerceNav;
44

55
use Statamic;
6+
use Statamic\Facades\Collection;
67
use Statamic\Facades\CP\Nav;
78
use Statamic\Providers\AddonServiceProvider;
89

910
class ServiceProvider extends AddonServiceProvider
1011
{
11-
protected $scripts = [
12-
__DIR__.'/../resources/js/cp.js'
13-
];
14-
1512
public function boot()
1613
{
17-
Statamic::script('app', 'cp');
18-
1914
Statamic::booted(function () {
2015
Nav::extend(function ($nav) {
16+
2117
$productsCollection = Collection::find('products');
2218
$couponsCollection = Collection::find('coupons');
2319
$ordersCollection = Collection::find('orders');
2420
$customersCollection = Collection::find('customers');
2521

26-
$nav->create('Products')
27-
->section('Ecommerce')
22+
// add new ecommerce block
23+
$nav->content('Ecommerce')
2824
->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; });
4054

41-
$nav->create('Customers')
42-
->section('Ecommerce')
43-
->url($customersCollection->showUrl())
44-
->can('view', $customersCollection);
4555
});
4656
});
4757
}

0 commit comments

Comments
 (0)