Skip to content

Commit

Permalink
ability for unlimited product slugs
Browse files Browse the repository at this point in the history
Signed-off-by: fenn-cs <[email protected]>
  • Loading branch information
nfebe committed Feb 8, 2022
1 parent 1f885a6 commit 1593439
Show file tree
Hide file tree
Showing 23 changed files with 491 additions and 92 deletions.
15 changes: 11 additions & 4 deletions components/ProductPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

use Lovata\Shopaholic\Models\Product;
use Lovata\Shopaholic\Classes\Item\ProductItem;
use Lovata\Shopaholic\Models\ProductSlug;

/**
* Class ProductPage
Expand Down Expand Up @@ -61,14 +62,20 @@ protected function getElementObject($sElementSlug)

if ($this->isSlugTranslatable()) {
$obElement = Product::active()->transWhere('slug', $sElementSlug)->first();
if (!$obElement) {
$obElement = Product::active()->transWhere('slug_alias', $sElementSlug)->first();
}
if (!$this->checkTransSlug($obElement, $sElementSlug)) {
$obElement = null;
}
if (!$obElement) {
$prodSlug = ProductSlug::transWhere('slug', $sElementSlug)->first();
if($prodSlug) $obElement = Product::active()->where('id', $prodSlug->product_id)->first();
}
} else {
$obElement = Product::active()->where('slug', $sElementSlug)->orWhere('slug_alias', $sElementSlug)->first();
$obElement = Product::active()->where('slug', $sElementSlug)->first();

if (!$obElement) {
$prodSlug = ProductSlug::where('slug', $sElementSlug)->first();
if($prodSlug) $obElement = Product::active()->where('id', $prodSlug->product_id)->first();
}
}
if (!empty($obElement)) {
Event::fire('shopaholic.product.open', [$obElement]);
Expand Down
32 changes: 32 additions & 0 deletions controllers/ProductSlugs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php namespace Lovata\Shopaholic\Controllers;

use BackendMenu;
use Backend\Classes\Controller;

/**
* Product Slugs Back-end Controller
*/
class ProductSlugs extends Controller
{
/**
* @var array Behaviors that are implemented by this controller.
*/
public $implement = [
'Backend.Behaviors.FormController',
'Backend.Behaviors.ListController',
'Backend.Behaviors.RelationController',
];

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

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

//BackendMenu::setContext('Lovata.Shopaholic', 'shopaholic', 'productslugs');
BackendMenu::setContext('Lovata.Shopaholic', 'shopaholic-menu-main', 'shopaholic-menu-products');

}
}
1 change: 1 addition & 0 deletions controllers/products/_product_slug.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?= $this->relationRender('product_slug') ?>
15 changes: 15 additions & 0 deletions controllers/products/config_relation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,19 @@ offer:
toolbarButtons: 'create|delete'
showSearch: true
showSorting: true
recordsPerPage: 10
product_slug:
label: 'lovata.shopaholic::lang.product_slug.name'
manage:
list: $/lovata/shopaholic/models/productslug/columns.yaml
form: $/lovata/shopaholic/models/productslug/fields.yaml
showSearch: true
showSorting: true
recordsPerPage: 10
view:
list: $/lovata/shopaholic/models/productslug/columns.yaml
recordUrl: lovata/shopaholic/productslug/update/:id
toolbarButtons: 'create|delete'
showSearch: true
showSorting: true
recordsPerPage: 10
21 changes: 21 additions & 0 deletions controllers/productslugs/_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('lovata/shopaholic/productslugs/create') ?>"
class="btn btn-primary oc-icon-plus">
New Product Slug
</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 Product Slugs?"
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/productslugs/config_form.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# ===================================
# Form Behavior Config
# ===================================

# Record name
name: Product Slug

# Model Form Field configuration
form: $/lovata/shopaholic/models/productslug/fields.yaml

# Model Class name
modelClass: Lovata\Shopaholic\Models\ProductSlug

# Default redirect location
defaultRedirect: lovata/shopaholic/productslugs

# Create page
create:
title: backend::lang.form.create_title
redirect: lovata/shopaholic/productslugs/update/:id
redirectClose: lovata/shopaholic/productslugs

# Update page
update:
title: backend::lang.form.update_title
redirect: lovata/shopaholic/productslugs
redirectClose: lovata/shopaholic/productslugs

# Preview page
preview:
title: backend::lang.form.preview_title
50 changes: 50 additions & 0 deletions controllers/productslugs/config_list.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# ===================================
# List Behavior Config
# ===================================

# Model List Column configuration
list: $/lovata/shopaholic/models/productslug/columns.yaml

# Model Class name
modelClass: Lovata\Shopaholic\Models\ProductSlug

# List Title
title: Manage Product Slugs

# Link URL for each record
recordUrl: lovata/shopaholic/productslugs/update/:id

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

# Records to display per page
recordsPerPage: 20

# Options to provide the user when selecting how many records to display per page
perPageOptions: [20, 40, 80, 100, 120]

# 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
Empty file.
48 changes: 48 additions & 0 deletions controllers/productslugs/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('lovata/shopaholic/productslugs') ?>">Product Slugs</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 ProductSlug..."
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 ProductSlug..."
class="btn btn-default">
Create and Close
</button>
<span class="btn-text">
or <a href="<?= Backend::url('lovata/shopaholic/productslugs') ?>">Cancel</a>
</span>
</div>
</div>

<?= Form::close() ?>

<?php else: ?>

<p class="flash-message static error"><?= e($this->fatalError) ?></p>
<p><a href="<?= Backend::url('lovata/shopaholic/productslugs') ?>" class="btn btn-default">Return to product slugs list</a></p>

<?php endif ?>
2 changes: 2 additions & 0 deletions controllers/productslugs/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/productslugs/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('lovata/shopaholic/productslugs') ?>">Product Slugs</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('lovata/shopaholic/productslugs') ?>" class="btn btn-default">Return to product slugs list</a></p>

<?php endif ?>
56 changes: 56 additions & 0 deletions controllers/productslugs/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('lovata/shopaholic/productslugs') ?>">Product Slugs</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 ProductSlug..."
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 ProductSlug..."
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 ProductSlug..."
data-request-confirm="Delete this productslug?">
</button>
<span class="btn-text">
or <a href="<?= Backend::url('lovata/shopaholic/productslugs') ?>">Cancel</a>
</span>
</div>
</div>

<?= Form::close() ?>

<?php else: ?>

<p class="flash-message static error"><?= e($this->fatalError) ?></p>
<p><a href="<?= Backend::url('lovata/shopaholic/productslugs') ?>" class="btn btn-default">Return to product slugs list</a></p>

<?php endif ?>
8 changes: 7 additions & 1 deletion lang/en/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
'promo_block_type' => 'Promo block with product list',
'promo_block' => 'Promo block',
'product_id' => 'Product ID',
'product_slug' => 'Slug Alias',
'product_slug_source' => 'Source String',
'rate' => 'Rate',
'tax_is_global' => 'Tax will apply to all products',
'tax_percent' => 'Tax percent',
Expand Down Expand Up @@ -87,7 +89,8 @@
'taxes' => 'Taxes',
'import_setting' => 'Import',
'dimensions' => 'Dimensions and weight',
'page_settings' => 'Page settings'
'page_settings' => 'Page settings',
'product_slug' => 'Slug Aliases'
],
'category' => [
'name' => 'category',
Expand Down Expand Up @@ -223,4 +226,7 @@
'import_from_xml_files' => 'Import from XML',
'import_from_csv_files' => 'Import from CSV',
],
'product_slug' => [
'name' => 'Slug Alias'
]
];
Loading

0 comments on commit 1593439

Please sign in to comment.