Skip to content

Commit 0cd54c0

Browse files
committed
Init
0 parents  commit 0cd54c0

3 files changed

Lines changed: 72 additions & 0 deletions

File tree

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Simple Commerce Nav
2+
3+
> This is a Statamic addon that groups all your Simple Commerce collections into one sidebar group.
4+
5+
## How to Install
6+
7+
You can search for this addon in the `Tools > Addons` section of the Statamic control panel and click **install**, or run the following command from your project root:
8+
9+
``` bash
10+
composer require thoughtco/simple-commerce-nav
11+
```
12+
13+
## How to Use
14+
15+
Once installed, all your simple commerce collections will be grouped under an Ecommerce sidebar link.

resources/js/cp.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
if (window.location.pathname.includes('/collections')) {
2+
Array.from(document.querySelectorAll('.nav-main-inner ul:nth-child(2) li a')).filter((el) => {
3+
return el.href.includes('/cp/collections/products')
4+
|| el.href.includes('/cp/collections/coupons')
5+
|| el.href.includes('/cp/collections/orders')
6+
|| el.href.includes('/cp/collections/customers')
7+
}).forEach((el) => {
8+
el.parentElement.outerHTML = ''
9+
})
10+
}

src/ServiceProvider.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
namespace Thoughtco\SimpleCommerceNav;
4+
5+
use Statamic\Facades\CP\Nav;
6+
use Statamic\Providers\AddonServiceProvider;
7+
8+
class ServiceProvider extends AddonServiceProvider
9+
{
10+
protected $scripts = [
11+
__DIR__.'/../resources/js/cp.js'
12+
];
13+
14+
public function boot()
15+
{
16+
Statamic::script('app', 'cp');
17+
18+
Statamic::booted(function () {
19+
Nav::extend(function ($nav) {
20+
$productsCollection = Collection::find('products');
21+
$couponsCollection = Collection::find('coupons');
22+
$ordersCollection = Collection::find('orders');
23+
$customersCollection = Collection::find('customers');
24+
25+
$nav->create('Products')
26+
->section('Ecommerce')
27+
->url($productsCollection->showUrl())
28+
->can('view', $productsCollection);
29+
30+
$nav->create('Coupons')
31+
->section('Ecommerce')
32+
->url($couponsCollection->showUrl())
33+
->can('view', $couponsCollection);
34+
35+
$nav->create('Orders')
36+
->section('Ecommerce')
37+
->url($ordersCollection->showUrl())
38+
->can('view', $ordersCollection);
39+
40+
$nav->create('Customers')
41+
->section('Ecommerce')
42+
->url($customersCollection->showUrl())
43+
->can('view', $customersCollection);
44+
});
45+
});
46+
}
47+
}

0 commit comments

Comments
 (0)