Skip to content

Commit

Permalink
Basic Category and Product
Browse files Browse the repository at this point in the history
  • Loading branch information
ljb0904 committed Dec 30, 2019
1 parent 2a8de70 commit 077ce58
Show file tree
Hide file tree
Showing 28 changed files with 953 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*~
108 changes: 108 additions & 0 deletions Plugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?php namespace Lbaig\Catalog;

use Backend;
use System\Classes\PluginBase;

/**
* Catalog Plugin Information File
*/
class Plugin extends PluginBase
{
/**
* Returns information about this plugin.
*
* @return array
*/
public function pluginDetails()
{
return [
'name' => 'Catalog',
'description' => 'No description provided yet...',
'author' => 'Lbaig',
'icon' => 'icon-leaf'
];
}

/**
* Register method, called when the plugin is first registered.
*
* @return void
*/
public function register()
{

}

/**
* Boot method, called right before the request route.
*
* @return array
*/
public function boot()
{

}

/**
* Registers any front-end components implemented in this plugin.
*
* @return array
*/
public function registerComponents()
{
return []; // Remove this line to activate

return [
'Lbaig\Catalog\Components\MyComponent' => 'myComponent',
];
}

/**
* Registers any back-end permissions used by this plugin.
*
* @return array
*/
public function registerPermissions()
{
return []; // Remove this line to activate

return [
'lbaig.catalog.some_permission' => [
'tab' => 'Catalog',
'label' => 'Some permission'
],
];
}

/**
* Registers back-end navigation items for this plugin.
*
* @return array
*/
public function registerNavigation()
{
return [
'catalog' => [
'label' => 'Catalog',
'url' => Backend::url('lbaig/catalog/products'),
'icon' => 'icon-leaf',
'permissions' => ['lbaig.catalog.*'],
'order' => 500,
'sideMenu' => [
'categories' => [
'label' => 'Categories',
'icon' => 'icon-sitemap',
'url' => Backend::url('lbaig/catalog/categories'),
'permissions' => ['lbaig.lshop.some_permission']
],
'products' => [
'label' => 'Products',
'icon' => 'icon-book',
'url' => Backend::url('lbaig/catalog/products'),
'permissions' => ['lbaig.lshop.some_permission']
],
]
],
];
}
}
25 changes: 25 additions & 0 deletions controllers/Categories.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php namespace Lbaig\Catalog\Controllers;

use BackendMenu;
use Backend\Classes\Controller;

/**
* Categories Back-end Controller
*/
class Categories extends Controller
{
public $implement = [
'Backend.Behaviors.FormController',
'Backend.Behaviors.ListController'
];

public $formConfig = 'config_form.yaml';
public $listConfig = 'config_list.yaml';

public function __construct()
{
parent::__construct();

BackendMenu::setContext('Lbaig.Catalog', 'catalog', 'categories');
}
}
25 changes: 25 additions & 0 deletions controllers/Products.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php namespace Lbaig\Catalog\Controllers;

use BackendMenu;
use Backend\Classes\Controller;

/**
* Products Back-end Controller
*/
class Products extends Controller
{
public $implement = [
'Backend.Behaviors.FormController',
'Backend.Behaviors.ListController'
];

public $formConfig = 'config_form.yaml';
public $listConfig = 'config_list.yaml';

public function __construct()
{
parent::__construct();

BackendMenu::setContext('Lbaig.Catalog', 'catalog', 'products');
}
}
21 changes: 21 additions & 0 deletions controllers/categories/_list_toolbar.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<div data-control="toolbar">
<a
href="<?= Backend::url('lbaig/catalog/categories/create') ?>"
class="btn btn-primary oc-icon-plus">
New Category
</a>

<button
class="btn btn-danger oc-icon-trash-o"
disabled="disabled"
onclick="$(this).data('request-data', { checked: $('.control-list').listWidget('getChecked') })"
data-request="onDelete"
data-request-confirm="Are you sure you want to delete the selected Categories?"
data-trigger-action="enable"
data-trigger=".control-list input[type=checkbox]"
data-trigger-condition="checked"
data-request-success="$(this).prop('disabled', 'disabled')"
data-stripe-load-indicator>
Delete selected
</button>
</div>
31 changes: 31 additions & 0 deletions controllers/categories/config_form.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# ===================================
# Form Behavior Config
# ===================================

# Record name
name: Category

# Model Form Field configuration
form: $/lbaig/catalog/models/category/fields.yaml

# Model Class name
modelClass: Lbaig\Catalog\Models\Category

# Default redirect location
defaultRedirect: lbaig/catalog/categories

# Create page
create:
title: Create Category
redirect: lbaig/catalog/categories/update/:id
redirectClose: lbaig/catalog/categories

# Update page
update:
title: Edit Category
redirect: lbaig/catalog/categories
redirectClose: lbaig/catalog/categories

# Preview page
preview:
title: Preview Category
47 changes: 47 additions & 0 deletions controllers/categories/config_list.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# ===================================
# List Behavior Config
# ===================================

# Model List Column configuration
list: $/lbaig/catalog/models/category/columns.yaml

# Model Class name
modelClass: Lbaig\Catalog\Models\Category

# List Title
title: Manage Categories

# Link URL for each record
recordUrl: lbaig/catalog/categories/update/:id

# Message to display if the list is empty
noRecordsMessage: backend::lang.list.no_records

# Records to display per page
recordsPerPage: 20

# Display page numbers with pagination, disable to improve performance
showPageNumbers: true

# Displays the list column set up button
showSetup: true

# Displays the sorting link on each column
showSorting: true

# Default sorting column
# defaultSort:
# column: created_at
# direction: desc

# Display checkboxes next to each record
showCheckboxes: true

# Toolbar widget configuration
toolbar:
# Partial for toolbar buttons
buttons: list_toolbar

# Search widget configuration
search:
prompt: backend::lang.list.search_prompt
48 changes: 48 additions & 0 deletions controllers/categories/create.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php Block::put('breadcrumb') ?>
<ul>
<li><a href="<?= Backend::url('lbaig/catalog/categories') ?>">Categories</a></li>
<li><?= e($this->pageTitle) ?></li>
</ul>
<?php Block::endPut() ?>

<?php if (!$this->fatalError): ?>

<?= Form::open(['class' => 'layout']) ?>

<div class="layout-row">
<?= $this->formRender() ?>
</div>

<div class="form-buttons">
<div class="loading-indicator-container">
<button
type="submit"
data-request="onSave"
data-hotkey="ctrl+s, cmd+s"
data-load-indicator="Creating Category..."
class="btn btn-primary">
Create
</button>
<button
type="button"
data-request="onSave"
data-request-data="close:1"
data-hotkey="ctrl+enter, cmd+enter"
data-load-indicator="Creating Category..."
class="btn btn-default">
Create and Close
</button>
<span class="btn-text">
or <a href="<?= Backend::url('lbaig/catalog/categories') ?>">Cancel</a>
</span>
</div>
</div>

<?= Form::close() ?>

<?php else: ?>

<p class="flash-message static error"><?= e($this->fatalError) ?></p>
<p><a href="<?= Backend::url('lbaig/catalog/categories') ?>" class="btn btn-default">Return to categories list</a></p>

<?php endif ?>
2 changes: 2 additions & 0 deletions controllers/categories/index.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

<?= $this->listRender() ?>
19 changes: 19 additions & 0 deletions controllers/categories/preview.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php Block::put('breadcrumb') ?>
<ul>
<li><a href="<?= Backend::url('lbaig/catalog/categories') ?>">Categories</a></li>
<li><?= e($this->pageTitle) ?></li>
</ul>
<?php Block::endPut() ?>

<?php if (!$this->fatalError): ?>

<div class="form-preview">
<?= $this->formRenderPreview() ?>
</div>

<?php else: ?>

<p class="flash-message static error"><?= e($this->fatalError) ?></p>
<p><a href="<?= Backend::url('lbaig/catalog/categories') ?>" class="btn btn-default">Return to categories list</a></p>

<?php endif ?>
56 changes: 56 additions & 0 deletions controllers/categories/update.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php Block::put('breadcrumb') ?>
<ul>
<li><a href="<?= Backend::url('lbaig/catalog/categories') ?>">Categories</a></li>
<li><?= e($this->pageTitle) ?></li>
</ul>
<?php Block::endPut() ?>

<?php if (!$this->fatalError): ?>

<?= Form::open(['class' => 'layout']) ?>

<div class="layout-row">
<?= $this->formRender() ?>
</div>

<div class="form-buttons">
<div class="loading-indicator-container">
<button
type="submit"
data-request="onSave"
data-request-data="redirect:0"
data-hotkey="ctrl+s, cmd+s"
data-load-indicator="Saving Category..."
class="btn btn-primary">
<u>S</u>ave
</button>
<button
type="button"
data-request="onSave"
data-request-data="close:1"
data-hotkey="ctrl+enter, cmd+enter"
data-load-indicator="Saving Category..."
class="btn btn-default">
Save and Close
</button>
<button
type="button"
class="oc-icon-trash-o btn-icon danger pull-right"
data-request="onDelete"
data-load-indicator="Deleting Category..."
data-request-confirm="Delete this category?">
</button>
<span class="btn-text">
or <a href="<?= Backend::url('lbaig/catalog/categories') ?>">Cancel</a>
</span>
</div>
</div>

<?= Form::close() ?>

<?php else: ?>

<p class="flash-message static error"><?= e($this->fatalError) ?></p>
<p><a href="<?= Backend::url('lbaig/catalog/categories') ?>" class="btn btn-default">Return to categories list</a></p>

<?php endif ?>
Loading

0 comments on commit 077ce58

Please sign in to comment.