Release 0.265: ShopPromotion date_from and edit save fix

This commit is contained in:
2026-02-13 22:44:07 +01:00
parent d824ba3909
commit 88e5673569
24 changed files with 1334 additions and 436 deletions

View File

@@ -0,0 +1,19 @@
<?php
$label = trim((string)($this->label ?? 'Kategorie'));
$inputName = trim((string)($this->inputName ?? 'categories[]'));
$categories = is_array($this->categories ?? null) ? $this->categories : [];
$selectedIds = is_array($this->selectedIds ?? null) ? $this->selectedIds : [];
?>
<div class="form-group row js-promotion-row js-promotion-row-categories">
<label class="col-lg-4 control-label"><?= htmlspecialchars($label, ENT_QUOTES, 'UTF-8'); ?>:</label>
<div class="col-lg-8">
<div class="promotion-categories-box">
<?= \Tpl::view('shop-promotion/promotion-categories-tree', [
'categories' => $categories,
'selectedIds' => $selectedIds,
'inputName' => $inputName,
]); ?>
</div>
</div>
</div>

View File

@@ -0,0 +1,68 @@
<?php
$categories = is_array($this->categories ?? null) ? $this->categories : [];
$inputName = trim((string)($this->inputName ?? 'categories[]'));
$selectedRaw = is_array($this->selectedIds ?? null) ? $this->selectedIds : [];
$selected = [];
foreach ($selectedRaw as $value) {
$id = (int)$value;
if ($id > 0) {
$selected[$id] = true;
}
}
?>
<?php if (!empty($categories)): ?>
<ol class="promotion-categories-tree">
<?php foreach ($categories as $category): ?>
<?php
$categoryId = (int)($category['id'] ?? 0);
if ($categoryId <= 0) {
continue;
}
$title = trim((string)($category['title'] ?? ''));
if ($title === '') {
$title = 'Kategoria #' . $categoryId;
}
$isActive = (int)($category['status'] ?? 0) === 1;
$children = is_array($category['subcategories'] ?? null) ? $category['subcategories'] : [];
$hasChildren = !empty($children);
?>
<li class="promotion-category-item<?= $hasChildren ? ' has-children is-collapsed' : ''; ?>">
<div class="promotion-category-row">
<?php if ($hasChildren): ?>
<button type="button" class="promotion-tree-toggle" aria-expanded="false" title="Rozwin / zwin">
<i class="fa fa-caret-right"></i>
</button>
<?php else: ?>
<span class="promotion-tree-spacer"></span>
<?php endif; ?>
<?php if (!$isActive): ?>
<i class="fa fa-ban text-danger" title="Kategoria nieaktywna"></i>
<?php endif; ?>
<label class="promotion-category-label">
<input
type="checkbox"
class="g-checkbox"
name="<?= htmlspecialchars($inputName, ENT_QUOTES, 'UTF-8'); ?>"
value="<?= $categoryId; ?>"
<?= isset($selected[$categoryId]) ? 'checked="checked"' : ''; ?>
/>
<span><?= htmlspecialchars($title, ENT_QUOTES, 'UTF-8'); ?></span>
</label>
</div>
<?php if ($hasChildren): ?>
<?= \Tpl::view('shop-promotion/promotion-categories-tree', [
'categories' => $children,
'selectedIds' => array_keys($selected),
'inputName' => $inputName,
]); ?>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ol>
<?php endif; ?>

View File

@@ -0,0 +1,115 @@
<style type="text/css">
.promotion-categories-box {
max-height: 420px;
overflow: auto;
border: 1px solid #d6d6d6;
border-radius: 4px;
padding: 8px 10px;
background: #fff;
}
.promotion-categories-tree {
margin: 0;
padding: 0 0 0 16px;
list-style: none;
}
.promotion-category-item {
margin: 2px 0;
}
.promotion-category-item.is-collapsed > ol {
display: none;
}
.promotion-category-row {
display: flex;
align-items: center;
gap: 6px;
min-height: 28px;
}
.promotion-tree-toggle,
.promotion-tree-spacer {
width: 18px;
height: 18px;
display: inline-flex;
align-items: center;
justify-content: center;
border: 0;
background: transparent;
padding: 0;
}
.promotion-tree-toggle {
cursor: pointer;
color: #666;
}
.promotion-category-item:not(.is-collapsed) > .promotion-category-row .promotion-tree-toggle i {
transform: rotate(90deg);
}
.promotion-category-label {
margin: 0;
font-weight: 600;
cursor: pointer;
display: inline-flex;
align-items: center;
gap: 6px;
}
.js-promotion-row-hide {
display: none;
}
</style>
<script type="text/javascript">
(function($) {
if (!$) {
return;
}
function updatePromotionConditionRows() {
var conditionType = parseInt($('#condition_type').val(), 10) || 0;
var $discountTypeRow = $('#discount_type').closest('.form-group, .row');
var $amountRow = $('#amount').closest('.form-group, .row');
var $group2Row = $('input[name="condition_categories[]"]').first().closest('.js-promotion-row');
var $minCountRow = $('#min_product_count').closest('.form-group, .row');
var $cheapestPriceRow = $('#price_cheapest_product').closest('.form-group, .row');
if (conditionType === 3) {
$discountTypeRow.addClass('js-promotion-row-hide');
$amountRow.addClass('js-promotion-row-hide');
$group2Row.addClass('js-promotion-row-hide');
$minCountRow.removeClass('js-promotion-row-hide');
$cheapestPriceRow.removeClass('js-promotion-row-hide');
return;
}
$discountTypeRow.removeClass('js-promotion-row-hide');
$amountRow.removeClass('js-promotion-row-hide');
$group2Row.removeClass('js-promotion-row-hide');
$minCountRow.addClass('js-promotion-row-hide');
$cheapestPriceRow.addClass('js-promotion-row-hide');
}
$(document).off('change.shopPromotionCondition', '#condition_type');
$(document).on('change.shopPromotionCondition', '#condition_type', function() {
updatePromotionConditionRows();
});
$(document).off('click.shopPromotionTree', '.promotion-tree-toggle');
$(document).on('click.shopPromotionTree', '.promotion-tree-toggle', function(e) {
e.preventDefault();
var $item = $(this).closest('.promotion-category-item');
$item.toggleClass('is-collapsed');
$(this).attr('aria-expanded', $item.hasClass('is-collapsed') ? 'false' : 'true');
});
$(function() {
updatePromotionConditionRows();
});
})(window.jQuery);
</script>

View File

@@ -1,257 +1,3 @@
<script type="text/javascript" src="/libraries/jquery/sortable/sortable.js"></script>
<?
global $db;
ob_start();
?>
<div id="settings-tabs">
<ul class="resp-tabs-list settings-tabs">
<li><i class="fa fa-wrench"></i>Ustawienia</li>
</ul>
<div class="resp-tabs-container settings-tabs">
<div>
<?=
\Html::input( [
'label' => 'Nazwa',
'name' => 'name',
'id' => 'name',
'value' => $this -> promotion['name']
] );
?>
<?=
\Html::input_switch( [
'label' => 'Aktywna',
'name' => 'status',
'checked' => $this -> promotion['status'] == 1 ? true : false
] );
?>
<?=
\Html::input_switch( [
'label' => 'Łącz z kuponami rabatowymi',
'name' => 'include_coupon',
'checked' => $this -> promotion['include_coupon'] == 1 ? true : false
] );
?>
<?=
\Html::input_switch( [
'label' => 'Uwzględnij produkty przecenione',
'name' => 'include_product_promo',
'checked' => $this -> promotion['include_product_promo'] == 1 ? true : false
] );
?>
<?=
\Html::select( [
'label' => 'Warunki promocji',
'id' => 'condition_type',
'name' => 'condition_type',
'values' => \shop\Promotion::$condition_type,
'value' => $this -> promotion['condition_type'],
] );
?>
<?=
\Html::select( [
'label' => 'Typ rabatu',
'id' => 'discount_type',
'name' => 'discount_type',
'values' => \shop\Promotion::$discount_type,
'value' => $this -> promotion['discount_type'],
] );
?>
<?= \Html::input( [
'label' => 'Min. ilość produktów z danej kategorii',
'class' => 'int-format',
'name' => 'min_product_count',
'id' => 'min_product_count',
'value' => $this -> promotion['min_product_count']
] );?>
<?= \Html::input( [
'label' => 'Cena najtańszego produktu',
'class' => 'number-format',
'name' => 'price_cheapest_product',
'id' => 'price_cheapest_product',
'value' => $this -> promotion['price_cheapest_product']
] );
?>
<?=
\Html::input( [
'label' => 'Wartość',
'class' => 'number-format',
'name' => 'amount',
'id' => 'amount',
'value' => $this -> promotion['amount']
] );
?>
<?=
\Html::input( [
'label' => 'Data do',
'class' => 'date',
'name' => 'date_to',
'id' => 'date_to',
'value' => $this -> promotion['date_to']
] );
?>
<div class="form-group row">
<label class="col-lg-4 control-label">Kategorie grupa I:</label>
<div class="col-lg-8">
<div class="menu_sortable">
<ol class="sortable" id="sortable">
<?
if ( is_array( $this -> categories ) )
{
foreach ( $this -> categories as $category )
{
?>
<li id="list_<?= $category[ 'id' ];?>" class="category_<?= $category[ 'id' ];?>" category="<?= $category[ 'id' ];?>">
<div class="context_0 content content_menu">
<span class="disclose"><span></span></span>
<? if ( !$category[ 'status' ] ) echo '<i class="fa fa-ban fa-lg text-danger" title="Kategoria nieaktywna"></i>';?>
<input type="checkbox" class="g-checkbox" name="categories[]" value="<?= $category[ 'id' ];?>" <? if ( is_array( json_decode( $this -> promotion['categories'] ) ) and in_array( $category[ 'id' ], json_decode( $this -> promotion['categories'] ) ) ):?>checked="checked"<? endif;?> />
<b><?= $category[ 'languages' ][ $this -> dlang ][ 'title' ];?></b>
</div>
<?=
\Tpl::view( 'shop-product/subcategories-list', [
'categories' => \admin\factory\ShopCategory::subcategories( $category[ 'id' ] ),
'product_categories' => json_decode( $this -> promotion['categories'] ),
'dlang' => $this -> dlang
] );
?>
</li>
<?
}
}
?>
</ol>
</div>
</div>
<div class="clear"></div>
</div>
<div class="form-group row">
<label class="col-lg-4 control-label">Kategoria grupa II:</label>
<div class="col-lg-8">
<div class="menu_sortable">
<ol class="sortable" id="sortable2">
<?
if ( is_array( $this -> categories ) )
{
foreach ( $this -> categories as $category )
{
?>
<li id="list_<?= $category[ 'id' ];?>" class="category_<?= $category[ 'id' ];?>" category="<?= $category[ 'id' ];?>">
<div class="context_0 content content_menu">
<span class="disclose"><span></span></span>
<? if ( !$category[ 'status' ] ) echo '<i class="fa fa-ban fa-lg text-danger" title="Kategoria nieaktywna"></i>';?>
<input type="checkbox" class="g-checkbox" name="condition_categories[]" value="<?= $category[ 'id' ];?>" <? if ( is_array( json_decode( $this -> promotion['condition_categories'] ) ) and in_array( $category[ 'id' ], json_decode( $this -> promotion['condition_categories'] ) ) ):?>checked="checked"<? endif;?> />
<b><?= $category[ 'languages' ][ $this -> dlang ][ 'title' ];?></b>
</div>
<?=
\Tpl::view( 'shop-product/subcategories-list', [
'categories' => \admin\factory\ShopCategory::subcategories( $category[ 'id' ] ),
'product_categories' => json_decode( $this -> promotion['condition_categories'] ),
'dlang' => $this -> dlang,
'name' => 'condition_categories[]'
] );
?>
</li>
<?
}
}
?>
</ol>
</div>
</div>
</div>
</div>
</div>
</div>
<?
$out = ob_get_clean();
<?= \Tpl::view('components/form-edit', ['form' => $this->form]); ?>
<?= \Tpl::view('shop-promotion/promotion-edit-custom-script'); ?>
$grid = new \gridEdit;
$grid -> id = 'promotion-edit';
$grid -> gdb_opt = $gdb;
$grid -> include_plugins = true;
$grid -> title = $this -> promotion['id'] ? 'Edycja promocji: <u>' . $this -> promotion['name'] . '</u>' : 'Nowa promocja';
$grid -> fields = [
[
'db' => 'id',
'type' => 'hidden',
'value' => $this -> promotion['id']
]
];
$grid -> actions = [
'save' => [ 'url' => '/admin/shop_promotion/save/', 'back_url' => '/admin/shop_promotion/view_list/' ],
'cancel' => [ 'url' => '/admin/shop_promotion/view_list/' ]
];
$grid -> external_code = $out;
$grid -> persist_edit = true;
$grid -> id_param = 'id';
echo $grid -> draw();
?>
<link type="text/css" rel="stylesheet" href="/libraries/selectize/css/selectize.css">
<link type="text/css" rel="stylesheet" href="/libraries/selectize/css/selectize.default.css">
<script type="text/javascript" src="/libraries/plupload/jquery.plupload.queue/jquery.plupload.queue.js"></script>
<script type="text/javascript" src="/libraries/jquery-nested-sortable/jquery.mjs.nestedSortable.js"></script>
<script type="text/javascript" src="/libraries/selectize/js/standalone/selectize.js"></script>
<script type="text/javascript">
function condition_type_change()
{
if ( $( '#condition_type' ).val() == 1 || $( '#condition_type' ).val() == 2 )
{
$( '#discount_type' ).closest( '.row' ).show();
$( '#amount' ).closest( '.row' ).show();
$( '#sortable2' ).closest( '.row' ).show();
$( '#min_product_count' ).closest( '.row' ).hide();
$( '#price_cheapest_product' ).closest( '.row' ).hide();
}
if ( $( '#condition_type' ).val() == 3 )
{
$( '#discount_type' ).closest( '.row' ).hide();
$( '#amount' ).closest( '.row' ).hide();
$( '#sortable2' ).closest( '.row' ).hide();
$( '#min_product_count' ).closest( '.row' ).show();
$( '#price_cheapest_product' ).closest( '.row' ).show();
}
}
$(function ()
{
condition_type_change();
$( 'body' ).on( 'change', '#condition_type', function()
{
condition_type_change();
});
disable_menu();
$('#settings-tabs').easyResponsiveTabs({
width: 'auto',
fit: true,
tabidentify: 'settings-tabs',
type: 'vertical'
});
$('ol.sortable').nestedSortable({
forcePlaceholderSize: true,
handle: 'div',
helper: 'clone',
items: 'li',
opacity: .9,
placeholder: 'placeholder',
revert: 250,
tabSize: 45,
tolerance: 'pointer',
toleranceElement: '> div',
maxLevels: 2,
isTree: true,
expandOnHover: 700,
protectRoot: false
});
$('.disclose').on('click', function ()
{
$(this).closest('li').toggleClass('sort-collapsed').toggleClass('sort-expanded');
});
});
</script>

View File

@@ -0,0 +1,2 @@
<?= \Tpl::view('components/table-list', ['list' => $this->viewModel]); ?>

View File

@@ -1,59 +0,0 @@
<?php
global $gdb;
$grid = new \grid( 'pp_shop_promotion' );
$grid -> gdb_opt = $gdb;
$grid -> debug = true;
$grid -> order = [ 'column' => 'id', 'type' => 'DESC' ];
$grid -> search = [
[ 'name' => 'Nazwa', 'db' => 'name', 'type' => 'text' ],
[ 'name' => 'Aktywny', 'db' => 'status', 'type' => 'select', 'replace' => [ 'array' => [ 0 => 'nie', 1 => 'tak' ] ] ]
];
$grid -> columns_view = [
[
'name' => 'Lp.',
'th' => [ 'class' => 'g-lp' ],
'td' => [ 'class' => 'g-center' ],
'autoincrement' => true
], [
'name' => 'Aktywny',
'db' => 'status',
'replace' => [ 'array' => [ 0 => '<span style="color: #FF0000;">nie</span>', 1 => 'tak' ] ],
'td' => [ 'class' => 'g-center' ],
'th' => [ 'class' => 'g-center', 'style' => 'width: 150px;' ],
'sort' => true
], [
'name' => 'Nazwa',
'db' => 'name',
'sort' => true,
'php' => 'echo "<a href=\'/admin/shop_promotion/edit/id=[id]\'>[name]</a>";'
], [
'name' => 'Typ kuponu',
'db' => 'condition_type',
'replace' => [ 'array' => \shop\Promotion::$condition_type ]
], [
'name' => 'Data do',
'db' => 'date_to',
'td' => [ 'class' => 'g-center' ],
'th' => [ 'class' => 'g-center', 'style' => 'width: 150px;' ]
], [
'name' => 'Edytuj',
'action' => [ 'type' => 'edit', 'url' => '/admin/shop_promotion/edit/id=[id]' ],
'th' => [ 'class' => 'g-center', 'style' => 'width: 70px;' ],
'td' => [ 'class' => 'g-center' ]
], [
'name' => 'Usuń',
'action' => [ 'type' => 'delete', 'url' => '/admin/shop_promotion/promotion_delete/id=[id]' ],
'th' => [ 'class' => 'g-center', 'style' => 'width: 70px;' ],
'td' => [ 'class' => 'g-center' ]
]
];
$grid -> buttons = [
[
'label' => 'Dodaj promocję',
'url' => '/admin/shop_promotion/edit/',
'icon' => 'fa-plus-circle',
'class' => 'btn-success'
]
];
echo $grid -> draw();

View File

@@ -76,7 +76,7 @@
<a href="/admin/shop_statuses/view_list/"><i class="fa fa-bars"></i>Statusy zam&#243;wie&#324;</a>
</li>
<li><a href="/admin/shop_coupon/view_list/"><img src="/admin/layout/icon/icon-menu/piggy-bank-coins.svg">Kody rabatowe</a></li>
<li><a href="/admin/shop_promotion/view_list/"><img src="/admin/layout/icon/icon-menu/burst-sale.svg">Promocje</a></li>
<li><a href="/admin/shop_promotion/list/"><img src="/admin/layout/icon/icon-menu/burst-sale.svg">Promocje</a></li>
</ul>
<div class="title">Zawarto&#347;&#263;</div>
<ul>