ver. 0.274 - ShopProduct mass_edit + tree UI cleanup
This commit is contained in:
@@ -52,6 +52,49 @@ if (!empty($_COOKIE['cookie_menus'])) {
|
|||||||
<script type="text/javascript" src="/libraries/jquery/lozad.js"></script>
|
<script type="text/javascript" src="/libraries/jquery/lozad.js"></script>
|
||||||
|
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
|
#fg-article-edit .layout-tree-toggle {
|
||||||
|
width: 18px;
|
||||||
|
height: 18px;
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
border: 0;
|
||||||
|
background: transparent;
|
||||||
|
padding: 0;
|
||||||
|
margin-right: 4px;
|
||||||
|
color: #666;
|
||||||
|
cursor: pointer;
|
||||||
|
text-indent: 0;
|
||||||
|
background-image: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
#fg-article-edit .layout-tree-toggle:focus,
|
||||||
|
#fg-article-edit .layout-tree-toggle:active,
|
||||||
|
#fg-article-edit .layout-tree-toggle:focus-visible {
|
||||||
|
outline: none;
|
||||||
|
box-shadow: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
#fg-article-edit li.sort-expanded > div .layout-tree-toggle i {
|
||||||
|
transform: rotate(90deg);
|
||||||
|
}
|
||||||
|
|
||||||
|
#fg-article-edit .sortable li.sort-branch > div > .layout-tree-toggle {
|
||||||
|
display: inline-flex;
|
||||||
|
float: none;
|
||||||
|
margin-right: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#fg-article-edit .menu_sortable .icheckbox_minimal-blue {
|
||||||
|
margin-top: 0;
|
||||||
|
margin-right: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#fg-article-edit .menu_sortable .g-checkbox {
|
||||||
|
position: relative;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
.jconfirm.table-list-confirm-dialog .jconfirm-row {
|
.jconfirm.table-list-confirm-dialog .jconfirm-row {
|
||||||
min-height: 100vh;
|
min-height: 100vh;
|
||||||
display: flex;
|
display: flex;
|
||||||
@@ -371,9 +414,39 @@ if (!empty($_COOKIE['cookie_menus'])) {
|
|||||||
flash_swf_url: '/../libraries/plupload/plupload.flash.swf'
|
flash_swf_url: '/../libraries/plupload/plupload.flash.swf'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function refreshTreeDisclosureState() {
|
||||||
|
$('ol.sortable li').each(function() {
|
||||||
|
var $li = $(this);
|
||||||
|
var hasChildren = $li.children('ol').children('li').length > 0;
|
||||||
|
var $disclose = $li.children('div').children('.disclose');
|
||||||
|
|
||||||
|
if (hasChildren) {
|
||||||
|
$li.removeClass('sort-leaf');
|
||||||
|
if (!$li.hasClass('sort-collapsed') && !$li.hasClass('sort-expanded')) {
|
||||||
|
$li.addClass('sort-collapsed');
|
||||||
|
}
|
||||||
|
$li.addClass('sort-branch');
|
||||||
|
$disclose.attr('aria-expanded', $li.hasClass('sort-expanded') ? 'true' : 'false');
|
||||||
|
$disclose.show();
|
||||||
|
} else {
|
||||||
|
$li.removeClass('sort-branch sort-collapsed sort-expanded').addClass('sort-leaf');
|
||||||
|
$disclose.attr('aria-expanded', 'false');
|
||||||
|
$disclose.hide();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($.fn && typeof $.fn.iCheck === 'function') {
|
||||||
|
$('#fg-article-edit .menu_sortable .g-checkbox').iCheck({
|
||||||
|
checkboxClass: 'icheckbox_minimal-blue',
|
||||||
|
radioClass: 'iradio_minimal-blue'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
$('ol.sortable').nestedSortable({
|
$('ol.sortable').nestedSortable({
|
||||||
forcePlaceholderSize: true,
|
forcePlaceholderSize: true,
|
||||||
handle: 'div',
|
handle: 'div',
|
||||||
|
cancel: 'input,textarea,button,select,option,.icheckbox_minimal-blue,.iradio_minimal-blue,ins.iCheck-helper',
|
||||||
helper: 'clone',
|
helper: 'clone',
|
||||||
items: 'li',
|
items: 'li',
|
||||||
opacity: .6,
|
opacity: .6,
|
||||||
@@ -390,8 +463,17 @@ if (!empty($_COOKIE['cookie_menus'])) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
refreshTreeDisclosureState();
|
||||||
|
|
||||||
$('.disclose').on('click', function() {
|
$('.disclose').on('click', function() {
|
||||||
$(this).closest('li').toggleClass('sort-collapsed').toggleClass('sort-expanded');
|
var $li = $(this).closest('li');
|
||||||
|
if (!$li.hasClass('sort-branch')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$li.toggleClass('sort-collapsed').toggleClass('sort-expanded');
|
||||||
|
$(this).attr('aria-expanded', $li.hasClass('sort-expanded') ? 'true' : 'false');
|
||||||
|
this.blur();
|
||||||
});
|
});
|
||||||
|
|
||||||
$('.disclose').mousedown(function(e) {
|
$('.disclose').mousedown(function(e) {
|
||||||
@@ -423,10 +505,10 @@ if (!empty($_COOKIE['cookie_menus'])) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
<?php foreach ($cookiePages as $key => $val): ?>
|
<?php foreach ($cookiePages as $key => $val): ?>
|
||||||
<?php if ($val): ?>$('.<?= htmlspecialchars((string)$key, ENT_QUOTES, 'UTF-8') ?>').children('div').children('span.disclose').click();<?php endif; ?>
|
<?php if ($val): ?>$('.list_<?= (int)$key ?>').children('div').children('.disclose').click();<?php endif; ?>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
<?php foreach ($cookieMenus as $key => $val): ?>
|
<?php foreach ($cookieMenus as $key => $val): ?>
|
||||||
<?php if ($val): ?>$('.menu_<?= (int)$key ?>').children('div').children('span.disclose').click();<?php endif; ?>
|
<?php if ($val): ?>$('.menu_<?= (int)$key ?>').children('div').children('.disclose').click();<?php endif; ?>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
|
|
||||||
$('body').on('change', '.image-alt', function() {
|
$('body').on('change', '.image-alt', function() {
|
||||||
|
|||||||
@@ -3,8 +3,11 @@
|
|||||||
<? foreach ( $this -> pages as $page ):?>
|
<? foreach ( $this -> pages as $page ):?>
|
||||||
<li id="list_<?= $page['id'];?>" idk="<?= $page['id'];?>" class="sort-nonesting list_<?= $page['id'];?>" menu="<?= $page['menu_id'];?>">
|
<li id="list_<?= $page['id'];?>" idk="<?= $page['id'];?>" class="sort-nonesting list_<?= $page['id'];?>" menu="<?= $page['menu_id'];?>">
|
||||||
<div class="content <?= $this -> step < 2 ? $tmp = 'content_page' : $tmp = 'content_page_last_level';?>" <? if ( !$page['status'] ) echo 'style="color: #cc0000;"';?>>
|
<div class="content <?= $this -> step < 2 ? $tmp = 'content_page' : $tmp = 'content_page_last_level';?>" <? if ( !$page['status'] ) echo 'style="color: #cc0000;"';?>>
|
||||||
<span class="disclose"><span></span></span>
|
<button type="button" class="disclose layout-tree-toggle" aria-expanded="false" title="Rozwin / zwin">
|
||||||
<input type="checkbox" class="g-checkbox" name="pages[]" value="<?= $page['id'];?>" <? if ( is_array( $this -> article_pages ) and in_array( $page['id'], $this -> article_pages ) ):?>checked="checked"<? endif;?> /><?= $page['title'];?>
|
<i class="fa fa-caret-right"></i>
|
||||||
|
</button>
|
||||||
|
<input type="checkbox" class="g-checkbox" name="pages[]" id="article_page_<?= $page['id'];?>" value="<?= $page['id'];?>" <? if ( is_array( $this -> article_pages ) and in_array( $page['id'], $this -> article_pages ) ):?>checked="checked"<? endif;?> />
|
||||||
|
<label for="article_page_<?= $page['id'];?>" class="mb0"><?= $page['title'];?></label>
|
||||||
</div>
|
</div>
|
||||||
<?= \Tpl::view( 'articles/subpages-list', [
|
<?= \Tpl::view( 'articles/subpages-list', [
|
||||||
'pages' => $page['subpages'],
|
'pages' => $page['subpages'],
|
||||||
|
|||||||
@@ -15,7 +15,9 @@ foreach ($menus as $menu):
|
|||||||
<ol class="sortable" id="sortable_<?= $menuId; ?>" menu-id="<?= $menuId; ?>">
|
<ol class="sortable" id="sortable_<?= $menuId; ?>" menu-id="<?= $menuId; ?>">
|
||||||
<li id="list_<?= $menuId; ?>" class="menu_<?= $menuId; ?>" menu="<?= $menuId; ?>">
|
<li id="list_<?= $menuId; ?>" class="menu_<?= $menuId; ?>" menu="<?= $menuId; ?>">
|
||||||
<div class="context_0 content content_menu">
|
<div class="context_0 content content_menu">
|
||||||
<span class="disclose"><span></span></span>
|
<button type="button" class="disclose layout-tree-toggle" aria-expanded="false" title="Rozwin / zwin">
|
||||||
|
<i class="fa fa-caret-right"></i>
|
||||||
|
</button>
|
||||||
<?php if ($menuStatus !== 1): ?><i class="fa fa-ban fa-lg text-danger" title="Menu nieaktywne"></i><?php endif; ?>
|
<?php if ($menuStatus !== 1): ?><i class="fa fa-ban fa-lg text-danger" title="Menu nieaktywne"></i><?php endif; ?>
|
||||||
<b>Menu: <?= htmlspecialchars($menuName, ENT_QUOTES, 'UTF-8'); ?></b>
|
<b>Menu: <?= htmlspecialchars($menuName, ENT_QUOTES, 'UTF-8'); ?></b>
|
||||||
<div class="btn-group ml20 pull-right">
|
<div class="btn-group ml20 pull-right">
|
||||||
@@ -61,6 +63,31 @@ echo $grid->draw();
|
|||||||
?>
|
?>
|
||||||
<script type="text/javascript" src="/libraries/jquery-nested-sortable/jquery.mjs.nestedSortable.js"></script>
|
<script type="text/javascript" src="/libraries/jquery-nested-sortable/jquery.mjs.nestedSortable.js"></script>
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
|
.layout-tree-toggle {
|
||||||
|
width: 18px;
|
||||||
|
height: 18px;
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
border: 0;
|
||||||
|
background: transparent;
|
||||||
|
padding: 0;
|
||||||
|
margin-right: 4px;
|
||||||
|
color: #666;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.layout-tree-toggle:focus,
|
||||||
|
.layout-tree-toggle:active,
|
||||||
|
.layout-tree-toggle:focus-visible {
|
||||||
|
outline: none;
|
||||||
|
box-shadow: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
li.sort-expanded > div .layout-tree-toggle i {
|
||||||
|
transform: rotate(90deg);
|
||||||
|
}
|
||||||
|
|
||||||
.jconfirm.table-list-confirm-dialog .jconfirm-row {
|
.jconfirm.table-list-confirm-dialog .jconfirm-row {
|
||||||
min-height: 100vh;
|
min-height: 100vh;
|
||||||
display: flex;
|
display: flex;
|
||||||
@@ -86,6 +113,28 @@ echo $grid->draw();
|
|||||||
var cookieMenus = <?= json_encode($cookieMenus, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); ?>;
|
var cookieMenus = <?= json_encode($cookieMenus, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); ?>;
|
||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
|
function refreshTreeDisclosureState() {
|
||||||
|
$('ol.sortable li').each(function() {
|
||||||
|
var $li = $(this);
|
||||||
|
var hasChildren = $li.children('ol').children('li').length > 0;
|
||||||
|
var $disclose = $li.children('div').children('.disclose');
|
||||||
|
|
||||||
|
if (hasChildren) {
|
||||||
|
$li.removeClass('sort-leaf');
|
||||||
|
if (!$li.hasClass('sort-collapsed') && !$li.hasClass('sort-expanded')) {
|
||||||
|
$li.addClass('sort-collapsed');
|
||||||
|
}
|
||||||
|
$li.addClass('sort-branch');
|
||||||
|
$disclose.attr('aria-expanded', $li.hasClass('sort-expanded') ? 'true' : 'false');
|
||||||
|
$disclose.show();
|
||||||
|
} else {
|
||||||
|
$li.removeClass('sort-branch sort-collapsed sort-expanded').addClass('sort-leaf');
|
||||||
|
$disclose.attr('aria-expanded', 'false');
|
||||||
|
$disclose.hide();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function confirmDialog(message, onConfirm) {
|
function confirmDialog(message, onConfirm) {
|
||||||
if (typeof $.confirm === 'function') {
|
if (typeof $.confirm === 'function') {
|
||||||
$.confirm({
|
$.confirm({
|
||||||
@@ -167,12 +216,22 @@ echo $grid->draw();
|
|||||||
isTree: true,
|
isTree: true,
|
||||||
expandOnHover: 700,
|
expandOnHover: 700,
|
||||||
stop: function() {
|
stop: function() {
|
||||||
|
refreshTreeDisclosureState();
|
||||||
save_pages_order();
|
save_pages_order();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
refreshTreeDisclosureState();
|
||||||
|
|
||||||
$('.disclose').on('click', function() {
|
$('.disclose').on('click', function() {
|
||||||
$(this).closest('li').toggleClass('sort-collapsed').toggleClass('sort-expanded');
|
var $li = $(this).closest('li');
|
||||||
|
if (!$li.hasClass('sort-branch')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$li.toggleClass('sort-collapsed').toggleClass('sort-expanded');
|
||||||
|
$(this).attr('aria-expanded', $li.hasClass('sort-expanded') ? 'true' : 'false');
|
||||||
|
this.blur();
|
||||||
});
|
});
|
||||||
|
|
||||||
$('.sortable *').mousedown(function() {
|
$('.sortable *').mousedown(function() {
|
||||||
@@ -205,13 +264,13 @@ echo $grid->draw();
|
|||||||
|
|
||||||
Object.keys(cookiePages || {}).forEach(function(key) {
|
Object.keys(cookiePages || {}).forEach(function(key) {
|
||||||
if (String(cookiePages[key]) === '1') {
|
if (String(cookiePages[key]) === '1') {
|
||||||
$('.list_' + key).children('div').children('span.disclose').click();
|
$('.list_' + key).children('div').children('.disclose').click();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Object.keys(cookieMenus || {}).forEach(function(key) {
|
Object.keys(cookieMenus || {}).forEach(function(key) {
|
||||||
if (String(cookieMenus[key]) === '1') {
|
if (String(cookieMenus[key]) === '1') {
|
||||||
$('.menu_' + key).children('div').children('span.disclose').click();
|
$('.menu_' + key).children('div').children('.disclose').click();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -19,7 +19,9 @@ if (empty($pages)) {
|
|||||||
<li id="list_<?= $pageId; ?>" class="list_<?= $pageId; ?>" menu="<?= $menuId; ?>">
|
<li id="list_<?= $pageId; ?>" class="list_<?= $pageId; ?>" menu="<?= $menuId; ?>">
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<div class="menu-box-title">
|
<div class="menu-box-title">
|
||||||
<span class="disclose"><span></span></span>
|
<button type="button" class="disclose layout-tree-toggle" aria-expanded="false" title="Rozwin / zwin">
|
||||||
|
<i class="fa fa-caret-right"></i>
|
||||||
|
</button>
|
||||||
<?php if ($status !== 1): ?><i class="fa fa-ban fa-lg text-danger" title="Strona nieaktywna"></i><?php endif; ?>
|
<?php if ($status !== 1): ?><i class="fa fa-ban fa-lg text-danger" title="Strona nieaktywna"></i><?php endif; ?>
|
||||||
<?php if ($start === 1): ?><i class="fa fa-star fa-lg text-system" title="Strona startowa"></i><?php endif; ?>
|
<?php if ($start === 1): ?><i class="fa fa-star fa-lg text-system" title="Strona startowa"></i><?php endif; ?>
|
||||||
<?= htmlspecialchars($title, ENT_QUOTES, 'UTF-8'); ?>
|
<?= htmlspecialchars($title, ENT_QUOTES, 'UTF-8'); ?>
|
||||||
|
|||||||
158
admin/templates/shop-product/mass-edit-custom-script.php
Normal file
158
admin/templates/shop-product/mass-edit-custom-script.php
Normal file
@@ -0,0 +1,158 @@
|
|||||||
|
<script type="text/javascript" src="/libraries/jquery-nested-sortable/jquery.mjs.nestedSortable.js"></script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
$(document).ready(function() {
|
||||||
|
$('ol.sortable').nestedSortable({
|
||||||
|
forcePlaceholderSize: true,
|
||||||
|
handle: 'div.content',
|
||||||
|
cancel: 'input,textarea,button,select,option,.icheckbox_minimal-blue,.iradio_minimal-blue,ins.iCheck-helper',
|
||||||
|
helper: 'original',
|
||||||
|
items: 'li',
|
||||||
|
opacity: .6,
|
||||||
|
placeholder: 'placeholder',
|
||||||
|
revert: 250,
|
||||||
|
tabSize: 25,
|
||||||
|
tolerance: 'pointer',
|
||||||
|
toleranceElement: '> div.content',
|
||||||
|
maxLevels: 4,
|
||||||
|
isTree: true,
|
||||||
|
expandOnHover: 700,
|
||||||
|
isAllowed: function() { return false; }
|
||||||
|
});
|
||||||
|
|
||||||
|
function refreshTreeDisclosureState() {
|
||||||
|
$('ol.sortable li').each(function() {
|
||||||
|
var $li = $(this);
|
||||||
|
var hasChildren = $li.children('ol').children('li').length > 0;
|
||||||
|
var $disclose = $li.children('div').children('.disclose');
|
||||||
|
|
||||||
|
if (hasChildren) {
|
||||||
|
$li.removeClass('sort-leaf');
|
||||||
|
if (!$li.hasClass('sort-collapsed') && !$li.hasClass('sort-expanded'))
|
||||||
|
$li.addClass('sort-collapsed');
|
||||||
|
$li.addClass('sort-branch');
|
||||||
|
$disclose.attr('aria-expanded', $li.hasClass('sort-expanded') ? 'true' : 'false');
|
||||||
|
$disclose.show();
|
||||||
|
} else {
|
||||||
|
$li.removeClass('sort-branch sort-collapsed sort-expanded').addClass('sort-leaf');
|
||||||
|
$disclose.attr('aria-expanded', 'false');
|
||||||
|
$disclose.hide();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
refreshTreeDisclosureState();
|
||||||
|
|
||||||
|
// Inicjalizacja iCheck — osobno dla produktów i kategorii
|
||||||
|
if ($.fn && typeof $.fn.iCheck === 'function') {
|
||||||
|
$('.product-item .g-checkbox').iCheck({
|
||||||
|
checkboxClass: 'icheckbox_minimal-blue',
|
||||||
|
radioClass: 'iradio_minimal-blue'
|
||||||
|
});
|
||||||
|
$('#sortable input.g-checkbox').iCheck({
|
||||||
|
checkboxClass: 'icheckbox_minimal-blue',
|
||||||
|
radioClass: 'iradio_minimal-blue'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
$('body').on('click', '.disclose', function() {
|
||||||
|
var $li = $(this).closest('li');
|
||||||
|
if (!$li.hasClass('sort-branch')) return;
|
||||||
|
$li.toggleClass('sort-collapsed').toggleClass('sort-expanded');
|
||||||
|
$(this).attr('aria-expanded', $li.hasClass('sort-expanded') ? 'true' : 'false');
|
||||||
|
this.blur();
|
||||||
|
});
|
||||||
|
|
||||||
|
$('.disclose').mousedown(function(e) {
|
||||||
|
if (e.which === 1) {
|
||||||
|
var category_id = $(this).parent('div').parent('li').attr('id');
|
||||||
|
$.ajax({
|
||||||
|
type: 'POST',
|
||||||
|
cache: false,
|
||||||
|
url: '/admin/ajax.php',
|
||||||
|
data: { a: 'cookie_categories', category_id: category_id }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
<?php
|
||||||
|
$array = isset($_COOKIE['cookie_categories']) ? @unserialize($_COOKIE['cookie_categories']) : [];
|
||||||
|
if (is_array($array)):
|
||||||
|
foreach ($array as $key => $val):
|
||||||
|
if ($val):
|
||||||
|
?>
|
||||||
|
$('#<?= $key; ?>').children('div').children('button.disclose').click();
|
||||||
|
<?php
|
||||||
|
endif;
|
||||||
|
endforeach;
|
||||||
|
endif;
|
||||||
|
?>
|
||||||
|
|
||||||
|
$('.select-all').click(function() {
|
||||||
|
$('.product-item .g-checkbox').iCheck('check');
|
||||||
|
});
|
||||||
|
|
||||||
|
$('.deselect-all').click(function() {
|
||||||
|
$('.product-item .g-checkbox').iCheck('uncheck');
|
||||||
|
});
|
||||||
|
|
||||||
|
$('body').on('click', 'span[field-id="discount_percent"]', function() {
|
||||||
|
$('.ajax-msg').remove();
|
||||||
|
var discount_percent = $('#discount_percent').val();
|
||||||
|
var products = [];
|
||||||
|
$('input[name="products[]"]:checked').each(function() {
|
||||||
|
products.push($(this).val());
|
||||||
|
});
|
||||||
|
|
||||||
|
function saveProduct(index) {
|
||||||
|
if (index < products.length) {
|
||||||
|
$.ajax({
|
||||||
|
url: '/admin/shop_product/mass_edit_save/',
|
||||||
|
type: 'post',
|
||||||
|
data: { discount_percent: discount_percent, products: [products[index]] },
|
||||||
|
success: function(data) {
|
||||||
|
data = JSON.parse(data);
|
||||||
|
if (data.status == 'ok') {
|
||||||
|
if (data.price_brutto_promo)
|
||||||
|
$('label[for="product' + products[index] + '"]').append(' <span class="ajax-msg text-success">cena promocyjna: ' + data.price_brutto_promo + ' zł, cena zwykła: ' + data.price_brutto + '</span>');
|
||||||
|
else
|
||||||
|
$('label[for="product' + products[index] + '"]').append(' <span class="ajax-msg text-success">cena zwykła: ' + data.price_brutto + '</span>');
|
||||||
|
} else {
|
||||||
|
alert('Błąd przy zapisie produktu: ' + products[index]);
|
||||||
|
}
|
||||||
|
saveProduct(index + 1);
|
||||||
|
},
|
||||||
|
error: function() {
|
||||||
|
alert('Błąd przy zapisie produktu: ' + products[index]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
$.alert({
|
||||||
|
title: 'Informacja',
|
||||||
|
content: 'Zakończono zapisywanie produktów',
|
||||||
|
type: 'orange',
|
||||||
|
closeIcon: true,
|
||||||
|
closeIconClass: 'fa fa-close',
|
||||||
|
typeAnimated: true,
|
||||||
|
animation: 'opacity',
|
||||||
|
useBootstrap: false,
|
||||||
|
theme: 'modern',
|
||||||
|
autoClose: 'cancel|10000',
|
||||||
|
icon: 'fa fa-exclamation',
|
||||||
|
buttons: {
|
||||||
|
confirm: {
|
||||||
|
text: 'Zamknij',
|
||||||
|
btnClass: 'btn-blue',
|
||||||
|
keys: ['enter'],
|
||||||
|
action: function() {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (products.length > 0) {
|
||||||
|
saveProduct(0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
@@ -1,4 +1,56 @@
|
|||||||
<div class="panel mb50 panel-primary">
|
<style type="text/css">
|
||||||
|
.layout-tree-toggle {
|
||||||
|
width: 18px;
|
||||||
|
height: 18px;
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
border: 0;
|
||||||
|
background: transparent;
|
||||||
|
padding: 0;
|
||||||
|
margin-right: 4px;
|
||||||
|
color: #666;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.layout-tree-toggle:focus,
|
||||||
|
.layout-tree-toggle:active,
|
||||||
|
.layout-tree-toggle:focus-visible {
|
||||||
|
outline: none;
|
||||||
|
box-shadow: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
li.sort-expanded > div .layout-tree-toggle i {
|
||||||
|
transform: rotate(90deg);
|
||||||
|
}
|
||||||
|
|
||||||
|
#mass-edit-panel .product-item {
|
||||||
|
margin-bottom: 4px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#mass-edit-panel .product-item label {
|
||||||
|
cursor: pointer;
|
||||||
|
font-weight: normal;
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#mass-edit-panel .content_menu .icheckbox_minimal-blue {
|
||||||
|
margin-top: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#mass-edit-panel .icheckbox_minimal-blue {
|
||||||
|
position: relative;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<link rel="stylesheet" type="text/css" href="/libraries/grid/plugins/icheck/skins/minimal/minimal.css">
|
||||||
|
<link rel="stylesheet" type="text/css" href="/libraries/grid/plugins/icheck/skins/minimal/blue.css">
|
||||||
|
|
||||||
|
<div class="panel mb50 panel-primary" id="mass-edit-panel">
|
||||||
<div class="panel-heading">
|
<div class="panel-heading">
|
||||||
<span class="panel-title">Masowa edycja produktów</span>
|
<span class="panel-title">Masowa edycja produktów</span>
|
||||||
</div>
|
</div>
|
||||||
@@ -8,7 +60,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
<div class="form-group mb10">
|
<div class="form-group mb10">
|
||||||
<label class="col-lg-3 control-label" for="inputDefault">Ustaw cenę promocyjną (minus X procent)</label>
|
<label class="col-lg-3 control-label" for="discount_percent">Ustaw cenę promocyjną (minus X procent)</label>
|
||||||
<div class="col-lg-9">
|
<div class="col-lg-9">
|
||||||
<div class="bs-component">
|
<div class="bs-component">
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
@@ -24,200 +76,39 @@
|
|||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-6">
|
<div class="col-lg-6">
|
||||||
<? foreach ( $this -> products as $key => $product ):?>
|
<?php if ( is_array( $this->products ) ): foreach ( $this->products as $key => $product ): ?>
|
||||||
<div class="checkbox-custom fill mb5">
|
<div class="product-item">
|
||||||
<input type="checkbox" name="products[]" id="product<?= $key;?>" value="<?= $key;?>">
|
<input type="checkbox" class="g-checkbox" name="products[]" id="product<?= $key; ?>" value="<?= $key; ?>">
|
||||||
<label for="product<?= $key;?>"><?= $product;?></label>
|
<label for="product<?= $key; ?>"><?= htmlspecialchars( $product ); ?></label>
|
||||||
</div>
|
</div>
|
||||||
<? endforeach;?>
|
<?php endforeach; endif; ?>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-lg-6">
|
<div class="col-lg-6">
|
||||||
<div class="menu_sortable">
|
<div class="menu_sortable">
|
||||||
<ol class="sortable" id="sortable">
|
<ol class="sortable" id="sortable">
|
||||||
<? if ( is_array( $this -> categories ) ): foreach ( $this -> categories as $category ):?>
|
<?php if ( is_array( $this->categories ) ): foreach ( $this->categories as $category ): ?>
|
||||||
<li id="list_<?= $category['id'];?>" class="category_<?= $category['id'];?>" category="<?= $category['id'];?>">
|
<li id="list_<?= $category['id']; ?>" class="category_<?= $category['id']; ?>" category="<?= $category['id']; ?>">
|
||||||
<div class="context_0 content content_menu">
|
<div class="context_0 content content_menu">
|
||||||
<span class="disclose"><span></span></span>
|
<button type="button" class="disclose layout-tree-toggle" aria-expanded="false" title="Rozwin / zwin">
|
||||||
<? if ( !$category['status'] ) echo '<i class="fa fa-ban fa-lg text-danger" title="Kategoria nieaktywna"></i>';?>
|
<i class="fa fa-caret-right"></i>
|
||||||
<b><?= $category['languages'][$this -> dlang]['title'];?></b>
|
</button>
|
||||||
|
<?php if ( !$category['status'] ) echo '<i class="fa fa-ban fa-lg text-danger" title="Kategoria nieaktywna"></i>'; ?>
|
||||||
|
<input type="checkbox" class="g-checkbox" name="mass_categories[]" value="<?= $category['id']; ?>" />
|
||||||
|
<b><?= $category['languages'][$this->dlang]['title']; ?></b>
|
||||||
</div>
|
</div>
|
||||||
<?= \Tpl::view( 'shop-product/subcategories-list', [
|
<?= \Tpl::view( 'shop-product/subcategories-list', [
|
||||||
'categories' => \admin\factory\ShopCategory::subcategories( $category['id'] ),
|
'categories' => \admin\factory\ShopCategory::subcategories( $category['id'] ),
|
||||||
'level' => $this -> level + 1,
|
'level' => ($this->level ?? 0) + 1,
|
||||||
'dlang' => $this -> dlang
|
'dlang' => $this->dlang,
|
||||||
] );?>
|
'name' => 'mass_categories[]'
|
||||||
|
] ); ?>
|
||||||
</li>
|
</li>
|
||||||
<? endforeach; endif;?>
|
<?php endforeach; endif; ?>
|
||||||
</ol>
|
</ol>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<script type="text/javascript" src="/libraries/jquery-nested-sortable/jquery.mjs.nestedSortable.js"></script>
|
|
||||||
<script type="text/javascript">
|
|
||||||
$( document ).ready( function()
|
|
||||||
{
|
|
||||||
$( 'ol.sortable' ).nestedSortable(
|
|
||||||
{
|
|
||||||
forcePlaceholderSize: true,
|
|
||||||
handle: 'div',
|
|
||||||
helper: 'clone',
|
|
||||||
items: 'li',
|
|
||||||
opacity: .9,
|
|
||||||
placeholder: 'placeholder',
|
|
||||||
revert: 250,
|
|
||||||
tabSize: 45,
|
|
||||||
tolerance: 'pointer',
|
|
||||||
toleranceElement: '> div',
|
|
||||||
maxLevels: 4,
|
|
||||||
isTree: true,
|
|
||||||
expandOnHover: 700,
|
|
||||||
protectRoot: false
|
|
||||||
});
|
|
||||||
|
|
||||||
$( '.disclose' ).on( 'click', function()
|
<?= \Tpl::view( 'shop-product/mass-edit-custom-script' ); ?>
|
||||||
{
|
|
||||||
$( this ).closest( 'li' ).toggleClass( 'sort-collapsed' ).toggleClass( 'sort-expanded' );
|
|
||||||
});
|
|
||||||
|
|
||||||
$( '.disclose' ).mousedown( function(e) {
|
|
||||||
if ( e.which === 1 ) {
|
|
||||||
var category_id = $( this ).parent( 'div' ).parent( 'li' ).attr( 'id' );
|
|
||||||
|
|
||||||
$.ajax({
|
|
||||||
type: 'POST',
|
|
||||||
cache: false,
|
|
||||||
url: '/admin/ajax.php',
|
|
||||||
data: {
|
|
||||||
a: 'cookie_categories',
|
|
||||||
category_id: category_id
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
<?php
|
|
||||||
$array = unserialize( $_COOKIE[ 'cookie_categories' ] );
|
|
||||||
if ( is_array( $array ) ): foreach ( $array as $key => $val ):
|
|
||||||
if ( $val ):
|
|
||||||
?>$( '#<?= $key;?>' ).children( 'div' ).children( 'span.disclose' ).click();<?
|
|
||||||
endif;
|
|
||||||
endforeach; endif;
|
|
||||||
?>
|
|
||||||
|
|
||||||
$( '.select-all' ).click( function()
|
|
||||||
{
|
|
||||||
$( '.checkbox-custom input' ).prop( 'checked', true );
|
|
||||||
});
|
|
||||||
|
|
||||||
$( '.deselect-all' ).click( function()
|
|
||||||
{
|
|
||||||
$( '.checkbox-custom input' ).prop( 'checked', false );
|
|
||||||
});
|
|
||||||
|
|
||||||
$( 'body' ).on( 'click', '#sortable input[type="checkbox"]', function(){
|
|
||||||
if ( $( this ).is( ':checked' ) ) {
|
|
||||||
$.ajax({
|
|
||||||
url: '/admin/shop_product/get_products_by_category/',
|
|
||||||
type: 'post',
|
|
||||||
data: {
|
|
||||||
category_id: $( this ).val()
|
|
||||||
},
|
|
||||||
success: function(data) {
|
|
||||||
data = JSON.parse(data);
|
|
||||||
if ( data.status == 'ok' ) {
|
|
||||||
$.each( data.products, function( key, value ) {
|
|
||||||
$( '#product' + value ).prop( 'checked', true );
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
$.ajax({
|
|
||||||
url: '/admin/shop_product/get_products_by_category/',
|
|
||||||
type: 'post',
|
|
||||||
data: {
|
|
||||||
category_id: $( this ).val()
|
|
||||||
},
|
|
||||||
success: function(data) {
|
|
||||||
data = JSON.parse(data);
|
|
||||||
if ( data.status == 'ok' ) {
|
|
||||||
$.each( data.products, function( key, value ) {
|
|
||||||
$( '#product' + value ).prop( 'checked', false );
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$( 'body' ).on( 'click', 'span[field-id="discount_percent"]', function()
|
|
||||||
{
|
|
||||||
$( '.ajax-msg' ).remove();
|
|
||||||
var discount_percent = $( '#discount_percent' ).val();
|
|
||||||
var products = [];
|
|
||||||
$( 'input[name="products[]"]:checked' ).each( function(){
|
|
||||||
products.push( $( this ).val() );
|
|
||||||
});
|
|
||||||
|
|
||||||
function saveProduct(index) {
|
|
||||||
if (index < products.length) {
|
|
||||||
$.ajax({
|
|
||||||
url: '/admin/shop_product/mass_edit_save/',
|
|
||||||
type: 'post',
|
|
||||||
data: {
|
|
||||||
discount_percent: discount_percent,
|
|
||||||
products: [products[index]]
|
|
||||||
},
|
|
||||||
success: function(data) {
|
|
||||||
data = JSON.parse(data);
|
|
||||||
if ( data.status == 'ok') {
|
|
||||||
if ( data.price_brutto_promo )
|
|
||||||
$( 'label[for="product' + products[index] + '"]' ).append( ' <span class="ajax-msg text-success">cena promocyjna: ' + data.price_brutto_promo + ' zł, cena zwykła: ' + data.price_brutto + '</span>' );
|
|
||||||
else
|
|
||||||
$( 'label[for="product' + products[index] + '"]' ).append( ' <span class="ajax-msg text-success">cena zwykła: ' + data.price_brutto + '</span>' );
|
|
||||||
} else {
|
|
||||||
alert('Błąd przy zapisie produktu: ', products[index]);
|
|
||||||
}
|
|
||||||
// Wywołanie dla następnego produktu
|
|
||||||
saveProduct(index + 1);
|
|
||||||
},
|
|
||||||
error: function(err) {
|
|
||||||
alert('Błąd przy zapisie produktu: ', err);
|
|
||||||
// Można dodać obsługę błędu lub przerwać proces
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
$.alert({
|
|
||||||
title: 'Informacja',
|
|
||||||
content: 'Zakończono zapisywanie produktów',
|
|
||||||
type: 'orange',
|
|
||||||
closeIcon: true,
|
|
||||||
closeIconClass: 'fa fa-close',
|
|
||||||
typeAnimated: true,
|
|
||||||
animation: 'opacity',
|
|
||||||
autoClose: 'confirm|10000',
|
|
||||||
useBootstrap: false,
|
|
||||||
theme: 'modern',
|
|
||||||
autoClose: 'cancel|10000',
|
|
||||||
icon: 'fa fa-exclamation',
|
|
||||||
buttons:
|
|
||||||
{
|
|
||||||
confirm:
|
|
||||||
{
|
|
||||||
text: 'Zamknij',
|
|
||||||
btnClass: 'btn-blue',
|
|
||||||
keys: ['enter'],
|
|
||||||
action: function() {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (products.length > 0) {
|
|
||||||
saveProduct(0); // Rozpoczęcie od pierwszego produktu
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
|
|||||||
@@ -3,7 +3,9 @@
|
|||||||
<? foreach ( $this -> categories as $category ):?>
|
<? foreach ( $this -> categories as $category ):?>
|
||||||
<li id="list_<?= $category[ 'id' ];?>" class="list_<?= $category[ 'id' ];?>" category="<?= $category[ 'id' ];?>">
|
<li id="list_<?= $category[ 'id' ];?>" class="list_<?= $category[ 'id' ];?>" category="<?= $category[ 'id' ];?>">
|
||||||
<div class="context_0 content content_menu">
|
<div class="context_0 content content_menu">
|
||||||
<span class="disclose"><span></span></span>
|
<button type="button" class="disclose layout-tree-toggle" aria-expanded="false" title="Rozwin / zwin">
|
||||||
|
<i class="fa fa-caret-right"></i>
|
||||||
|
</button>
|
||||||
<? if ( !$category[ 'status' ] ) echo '<i class="fa fa-ban fa-lg text-danger" title="Kategoria nieaktywna"></i>';?>
|
<? if ( !$category[ 'status' ] ) echo '<i class="fa fa-ban fa-lg text-danger" title="Kategoria nieaktywna"></i>';?>
|
||||||
<input type="checkbox" class="g-checkbox" name="<?= $this -> name ? $this -> name : 'categories[]';?>" value="<?= $category[ 'id' ];?>" <? if ( is_array( $this -> product_categories ) and in_array( $category[ 'id' ], $this -> product_categories ) ):?>checked="checked"<? endif;?> />
|
<input type="checkbox" class="g-checkbox" name="<?= $this -> name ? $this -> name : 'categories[]';?>" value="<?= $category[ 'id' ];?>" <? if ( is_array( $this -> product_categories ) and in_array( $category[ 'id' ], $this -> product_categories ) ):?>checked="checked"<? endif;?> />
|
||||||
<b><?= $category[ 'languages' ][ $this -> dlang ][ 'title' ];?></b>
|
<b><?= $category[ 'languages' ][ $this -> dlang ][ 'title' ];?></b>
|
||||||
|
|||||||
@@ -244,4 +244,157 @@ class ProductRepository
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pobiera listę wszystkich produktów głównych (id => name) do masowej edycji.
|
||||||
|
* Zwraca tylko produkty bez parent_id (bez kombinacji).
|
||||||
|
*
|
||||||
|
* @return array<int, string> Mapa id => nazwa produktu
|
||||||
|
*/
|
||||||
|
public function allProductsForMassEdit(): array
|
||||||
|
{
|
||||||
|
$defaultLang = $this->db->get( 'pp_langs', 'id', [ 'start' => 1 ] );
|
||||||
|
if ( !$defaultLang ) {
|
||||||
|
$defaultLang = 'pl';
|
||||||
|
}
|
||||||
|
|
||||||
|
$results = $this->db->select( 'pp_shop_products', 'id', [ 'parent_id' => null ] );
|
||||||
|
$products = [];
|
||||||
|
|
||||||
|
if ( is_array( $results ) ) {
|
||||||
|
foreach ( $results as $id ) {
|
||||||
|
$name = $this->db->get( 'pp_shop_products_langs', 'name', [
|
||||||
|
'AND' => [ 'product_id' => $id, 'lang_id' => $defaultLang ]
|
||||||
|
] );
|
||||||
|
$products[ (int) $id ] = $name ?: '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $products;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pobiera listę ID produktów przypisanych do danej kategorii.
|
||||||
|
*
|
||||||
|
* @param int $categoryId ID kategorii
|
||||||
|
* @return int[] Lista ID produktów
|
||||||
|
*/
|
||||||
|
public function getProductsByCategory(int $categoryId): array
|
||||||
|
{
|
||||||
|
$results = $this->db->select(
|
||||||
|
'pp_shop_products_categories',
|
||||||
|
'product_id',
|
||||||
|
[ 'category_id' => $categoryId ]
|
||||||
|
);
|
||||||
|
|
||||||
|
return is_array( $results ) ? $results : [];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Aplikuje rabat procentowy na produkt (cena promocyjna = cena - X%).
|
||||||
|
* Aktualizuje również ceny kombinacji produktu.
|
||||||
|
*
|
||||||
|
* @param int $productId ID produktu
|
||||||
|
* @param float $discountPercent Procent rabatu
|
||||||
|
* @return array|null Tablica z price_brutto i price_brutto_promo lub null przy błędzie
|
||||||
|
*/
|
||||||
|
public function applyDiscountPercent(int $productId, float $discountPercent): ?array
|
||||||
|
{
|
||||||
|
$product = $this->db->get( 'pp_shop_products', [
|
||||||
|
'vat', 'price_brutto', 'price_netto'
|
||||||
|
], [ 'id' => $productId ] );
|
||||||
|
|
||||||
|
if ( !$product ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$vat = $product['vat'];
|
||||||
|
$priceBrutto = (float) $product['price_brutto'];
|
||||||
|
$priceNetto = (float) $product['price_netto'];
|
||||||
|
|
||||||
|
$priceBruttoPromo = $priceBrutto - ( $priceBrutto * ( $discountPercent / 100 ) );
|
||||||
|
$priceNettoPromo = $priceNetto - ( $priceNetto * ( $discountPercent / 100 ) );
|
||||||
|
|
||||||
|
if ( $priceBrutto == $priceBruttoPromo ) {
|
||||||
|
$priceBruttoPromo = null;
|
||||||
|
}
|
||||||
|
if ( $priceNetto == $priceNettoPromo ) {
|
||||||
|
$priceNettoPromo = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->db->update( 'pp_shop_products', [
|
||||||
|
'price_brutto_promo' => $priceBruttoPromo,
|
||||||
|
'price_netto_promo' => $priceNettoPromo
|
||||||
|
], [ 'id' => $productId ] );
|
||||||
|
|
||||||
|
$this->updateCombinationPrices( $productId, $priceNetto, $vat, $priceNettoPromo );
|
||||||
|
|
||||||
|
return [
|
||||||
|
'price_brutto' => $priceBrutto,
|
||||||
|
'price_brutto_promo' => $priceBruttoPromo
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Aktualizuje ceny kombinacji produktu uwzględniając wpływ na cenę (impact_on_the_price).
|
||||||
|
*
|
||||||
|
* @param int $productId ID produktu nadrzędnego
|
||||||
|
* @param float $priceNetto Cena netto bazowa
|
||||||
|
* @param float $vat Stawka VAT
|
||||||
|
* @param float|null $priceNettoPromo Cena promo netto bazowa (null = brak)
|
||||||
|
*/
|
||||||
|
private function updateCombinationPrices(int $productId, float $priceNetto, float $vat, ?float $priceNettoPromo): void
|
||||||
|
{
|
||||||
|
$priceBrutto = \S::normalize_decimal( $priceNetto * ( 100 + $vat ) / 100, 2 );
|
||||||
|
$priceBruttoPromo = $priceNettoPromo !== null
|
||||||
|
? \S::normalize_decimal( $priceNettoPromo * ( 100 + $vat ) / 100, 2 )
|
||||||
|
: null;
|
||||||
|
|
||||||
|
$combinations = $this->db->query(
|
||||||
|
'SELECT psp.id '
|
||||||
|
. 'FROM pp_shop_products AS psp '
|
||||||
|
. 'INNER JOIN pp_shop_products_attributes AS pspa ON psp.id = pspa.product_id '
|
||||||
|
. 'INNER JOIN pp_shop_attributes_values AS psav ON pspa.value_id = psav.id '
|
||||||
|
. 'WHERE psav.impact_on_the_price > 0 AND psp.parent_id = :product_id',
|
||||||
|
[ ':product_id' => $productId ]
|
||||||
|
);
|
||||||
|
|
||||||
|
if ( !$combinations ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$rows = $combinations->fetchAll( \PDO::FETCH_ASSOC );
|
||||||
|
foreach ( $rows as $row ) {
|
||||||
|
$combBrutto = $priceBrutto;
|
||||||
|
$combBruttoPromo = $priceBruttoPromo;
|
||||||
|
|
||||||
|
$values = $this->db->query(
|
||||||
|
'SELECT impact_on_the_price FROM pp_shop_attributes_values AS psav '
|
||||||
|
. 'INNER JOIN pp_shop_products_attributes AS pspa ON pspa.value_id = psav.id '
|
||||||
|
. 'WHERE impact_on_the_price IS NOT NULL AND product_id = :product_id',
|
||||||
|
[ ':product_id' => $row['id'] ]
|
||||||
|
);
|
||||||
|
|
||||||
|
if ( $values ) {
|
||||||
|
foreach ( $values->fetchAll( \PDO::FETCH_ASSOC ) as $value ) {
|
||||||
|
$combBrutto += $value['impact_on_the_price'];
|
||||||
|
if ( $combBruttoPromo !== null ) {
|
||||||
|
$combBruttoPromo += $value['impact_on_the_price'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$combNetto = \S::normalize_decimal( $combBrutto / ( 100 + $vat ) * 100, 2 );
|
||||||
|
$combNettoPromo = $combBruttoPromo !== null
|
||||||
|
? \S::normalize_decimal( $combBruttoPromo / ( 100 + $vat ) * 100, 2 )
|
||||||
|
: null;
|
||||||
|
|
||||||
|
$this->db->update( 'pp_shop_products', [
|
||||||
|
'price_netto' => $combNetto,
|
||||||
|
'price_brutto' => $combBrutto,
|
||||||
|
'price_netto_promo' => $combNettoPromo,
|
||||||
|
'price_brutto_promo' => $combBruttoPromo
|
||||||
|
], [ 'id' => $row['id'] ] );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -440,7 +440,9 @@ class ArticlesController
|
|||||||
$html .= '<ol class="sortable" id="sortable_' . $menuId . '">';
|
$html .= '<ol class="sortable" id="sortable_' . $menuId . '">';
|
||||||
$html .= '<li id="list_' . $menuId . '" class="menu_' . $menuId . '" menu="' . $menuId . '">';
|
$html .= '<li id="list_' . $menuId . '" class="menu_' . $menuId . '" menu="' . $menuId . '">';
|
||||||
$html .= '<div class="context_0 content content_menu"' . ($menuStatus ? '' : ' style="color: #cc0000;"') . '>';
|
$html .= '<div class="context_0 content content_menu"' . ($menuStatus ? '' : ' style="color: #cc0000;"') . '>';
|
||||||
$html .= '<span class="disclose"><span></span></span>Menu: <b>' . $menuName . '</b>';
|
$html .= '<button type="button" class="disclose layout-tree-toggle" aria-expanded="false" title="Rozwin / zwin">'
|
||||||
|
. '<i class="fa fa-caret-right"></i>'
|
||||||
|
. '</button>Menu: <b>' . $menuName . '</b>';
|
||||||
$html .= '</div>';
|
$html .= '</div>';
|
||||||
$html .= \Tpl::view('articles/subpages-list', [
|
$html .= \Tpl::view('articles/subpages-list', [
|
||||||
'pages' => $menuPages,
|
'pages' => $menuPages,
|
||||||
|
|||||||
70
autoload/admin/Controllers/ShopProductController.php
Normal file
70
autoload/admin/Controllers/ShopProductController.php
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
<?php
|
||||||
|
namespace admin\Controllers;
|
||||||
|
|
||||||
|
use Domain\Product\ProductRepository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Kontroler masowej edycji produktów.
|
||||||
|
* Obsługuje akcje: mass_edit (widok), mass_edit_save (AJAX), get_products_by_category (AJAX).
|
||||||
|
* Pozostałe akcje shop_product (view_list, product_edit, save itd.) nadal działają
|
||||||
|
* przez fallback na \admin\controls\ShopProduct.
|
||||||
|
*/
|
||||||
|
class ShopProductController
|
||||||
|
{
|
||||||
|
private ProductRepository $repository;
|
||||||
|
|
||||||
|
public function __construct(ProductRepository $repository)
|
||||||
|
{
|
||||||
|
$this->repository = $repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Widok masowej edycji produktów.
|
||||||
|
*/
|
||||||
|
public function mass_edit(): string
|
||||||
|
{
|
||||||
|
return \Tpl::view( 'shop-product/mass-edit', [
|
||||||
|
'products' => $this->repository->allProductsForMassEdit(),
|
||||||
|
'categories' => \admin\factory\ShopCategory::subcategories( null ),
|
||||||
|
'dlang' => \front\factory\Languages::default_language()
|
||||||
|
] );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AJAX: zastosowanie rabatu procentowego na zaznaczonych produktach.
|
||||||
|
*/
|
||||||
|
public function mass_edit_save(): void
|
||||||
|
{
|
||||||
|
$discountPercent = \S::get( 'discount_percent' );
|
||||||
|
$products = \S::get( 'products' );
|
||||||
|
|
||||||
|
if ( $discountPercent != '' && $products && is_array( $products ) && count( $products ) > 0 ) {
|
||||||
|
$productId = (int) $products[0];
|
||||||
|
$result = $this->repository->applyDiscountPercent( $productId, (float) $discountPercent );
|
||||||
|
|
||||||
|
if ( $result !== null ) {
|
||||||
|
echo json_encode( [
|
||||||
|
'status' => 'ok',
|
||||||
|
'price_brutto_promo' => $result['price_brutto_promo'],
|
||||||
|
'price_brutto' => $result['price_brutto']
|
||||||
|
] );
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
echo json_encode( [ 'status' => 'error' ] );
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AJAX: pobranie ID produktów z danej kategorii.
|
||||||
|
*/
|
||||||
|
public function get_products_by_category(): void
|
||||||
|
{
|
||||||
|
$categoryId = (int) \S::get( 'category_id' );
|
||||||
|
$products = $this->repository->getProductsByCategory( $categoryId );
|
||||||
|
|
||||||
|
echo json_encode( [ 'status' => 'ok', 'products' => $products ] );
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -377,6 +377,13 @@ class Site
|
|||||||
new \Domain\Languages\LanguagesRepository( $mdb )
|
new \Domain\Languages\LanguagesRepository( $mdb )
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
'ShopProduct' => function() {
|
||||||
|
global $mdb;
|
||||||
|
|
||||||
|
return new \admin\Controllers\ShopProductController(
|
||||||
|
new \Domain\Product\ProductRepository( $mdb )
|
||||||
|
);
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
return self::$newControllers;
|
return self::$newControllers;
|
||||||
|
|||||||
@@ -2,56 +2,6 @@
|
|||||||
namespace admin\controls;
|
namespace admin\controls;
|
||||||
class ShopProduct
|
class ShopProduct
|
||||||
{
|
{
|
||||||
static public function mass_edit_save()
|
|
||||||
{
|
|
||||||
global $mdb;
|
|
||||||
|
|
||||||
if ( \S::get( 'discount_percent' ) != '' and \S::get( 'products' ) )
|
|
||||||
{
|
|
||||||
$product_details = \admin\factory\ShopProduct::product_details( \S::get( 'products' )[0] );
|
|
||||||
|
|
||||||
$vat = $product_details['vat'];
|
|
||||||
$price_brutto = $product_details['price_brutto'];
|
|
||||||
$price_brutto_promo = $price_brutto - ( $price_brutto * ( \S::get( 'discount_percent' ) / 100 ) );
|
|
||||||
$price_netto = $product_details['price_netto'];
|
|
||||||
$price_netto_promo = $price_netto - ( $price_netto * ( \S::get( 'discount_percent' ) / 100 ) );
|
|
||||||
|
|
||||||
if ( $price_brutto == $price_brutto_promo)
|
|
||||||
$price_brutto_promo = null;
|
|
||||||
|
|
||||||
if ( $price_netto == $price_netto_promo )
|
|
||||||
$price_netto_promo = null;
|
|
||||||
|
|
||||||
$mdb -> update( 'pp_shop_products', [ 'price_brutto_promo' => $price_brutto_promo, 'price_netto_promo' => $price_netto_promo ], [ 'id' => \S::get( 'products' )[0] ] );
|
|
||||||
|
|
||||||
\admin\factory\ShopProduct::update_product_combinations_prices( \S::get( 'products' )[0], $price_netto, $vat, $price_netto_promo );
|
|
||||||
|
|
||||||
echo json_encode( [ 'status' => 'ok', 'price_brutto_promo' => $price_brutto_promo, 'price_brutto' => $price_brutto ] );
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
echo json_encode( [ 'status' => 'error' ] );
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
// get_products_by_category
|
|
||||||
static public function get_products_by_category() {
|
|
||||||
global $mdb;
|
|
||||||
|
|
||||||
$products = $mdb -> select( 'pp_shop_products_categories', 'product_id', [ 'category_id' => \S::get( 'category_id' ) ] );
|
|
||||||
|
|
||||||
echo json_encode( [ 'status' => 'ok', 'products' => $products ] );
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
static public function mass_edit()
|
|
||||||
{
|
|
||||||
return \Tpl::view( 'shop-product/mass-edit', [
|
|
||||||
'products' => \admin\factory\ShopProduct::products_list(),
|
|
||||||
'categories' => \admin\factory\ShopCategory::subcategories( null ),
|
|
||||||
'dlang' => \front\factory\Languages::default_language()
|
|
||||||
] );
|
|
||||||
}
|
|
||||||
|
|
||||||
static public function generate_combination()
|
static public function generate_combination()
|
||||||
{
|
{
|
||||||
foreach ( $_POST as $key => $val )
|
foreach ( $_POST as $key => $val )
|
||||||
|
|||||||
@@ -4,6 +4,29 @@ Logi zmian z migracji na Domain-Driven Architecture. Najnowsze na gorze.
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## ver. 0.274 (2026-02-15) - ShopProduct mass_edit + UI trees
|
||||||
|
|
||||||
|
- **ShopProduct (mass_edit)** - migracja akcji masowej edycji na Domain + DI
|
||||||
|
- NOWE: `admin\Controllers\ShopProductController` (DI) z akcjami `mass_edit`, `mass_edit_save`, `get_products_by_category`
|
||||||
|
- UPDATE: routing DI (`admin\Site`) rozszerzony o modul `ShopProduct`
|
||||||
|
- UPDATE: `Domain\Product\ProductRepository` rozszerzone o metody `allProductsForMassEdit`, `getProductsByCategory`, `applyDiscountPercent` (+ aktualizacja cen kombinacji)
|
||||||
|
- CLEANUP: usuniete legacy akcje `mass_edit`, `mass_edit_save`, `get_products_by_category` z `admin\controls\ShopProduct`
|
||||||
|
- **ShopProduct mass_edit UI** - przebudowa widoku i skryptu
|
||||||
|
- UPDATE: `admin/templates/shop-product/mass-edit.php` przepiety na nowy partial JS `mass-edit-custom-script`
|
||||||
|
- NOWE: `admin/templates/shop-product/mass-edit-custom-script.php` (nestedSortable + iCheck + stabilizacja drzewka)
|
||||||
|
- UPDATE: `admin/templates/shop-product/subcategories-list.php` ujednolicone strzalki (button + caret)
|
||||||
|
- FIX: zaznaczenie kategorii w drzewku nie zaznacza automatycznie produktow na liscie
|
||||||
|
- **Pages / Articles UI** - ujednolicenie drzewek
|
||||||
|
- UPDATE: `/admin/pages/list/` - nowe strzalki drzewa + `aria-expanded` + odswiezanie stanu branch/leaf
|
||||||
|
- UPDATE: `/admin/articles/edit/*` (zakladka wyswietlania) - nowe strzalki i checkboxy (iCheck) dla drzewka stron
|
||||||
|
- TEST:
|
||||||
|
- NOWE: `tests/Unit/admin/Controllers/ShopProductControllerTest.php`
|
||||||
|
- UPDATE: `tests/Unit/Domain/Product/ProductRepositoryTest.php` (nowe przypadki dla mass_edit)
|
||||||
|
- UPDATE: `tests/bootstrap.php` (stub `S::normalize_decimal()`)
|
||||||
|
- Testy: **OK (351 tests, 1091 assertions)**
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## ver. 0.273 (2026-02-15) - ShopProducer
|
## ver. 0.273 (2026-02-15) - ShopProducer
|
||||||
|
|
||||||
- **ShopProducer** - migracja `/admin/shop_producer` na Domain + DI + nowe widoki
|
- **ShopProducer** - migracja `/admin/shop_producer` na Domain + DI + nowe widoki
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ Główna tabela produktów.
|
|||||||
| apilo_product_id | ID produktu w Apilo |
|
| apilo_product_id | ID produktu w Apilo |
|
||||||
| apilo_product_name | Nazwa produktu w Apilo |
|
| apilo_product_name | Nazwa produktu w Apilo |
|
||||||
|
|
||||||
**Używane w:** `Domain\Product\ProductRepository`, `admin\factory\ShopProduct`
|
**Używane w:** `Domain\Product\ProductRepository`, `admin\factory\ShopProduct`, `admin\Controllers\ShopProductController`
|
||||||
|
|
||||||
## pp_shop_products_langs
|
## pp_shop_products_langs
|
||||||
Tłumaczenia produktów (per język).
|
Tłumaczenia produktów (per język).
|
||||||
@@ -53,7 +53,9 @@ Przypisanie produktów do kategorii.
|
|||||||
|---------|------|
|
|---------|------|
|
||||||
| product_id | FK do pp_shop_products |
|
| product_id | FK do pp_shop_products |
|
||||||
|
|
||||||
**Używane w:** `admin\factory\ShopProduct::product_delete()`
|
**Używane w:** `admin\factory\ShopProduct::product_delete()`, `Domain\Product\ProductRepository::getProductsByCategory()`
|
||||||
|
|
||||||
|
**Aktualizacja 2026-02-15 (ver. 0.274):** akcje `/admin/shop_product/mass_edit/*` korzystają z `Domain\Product\ProductRepository` przez `admin\Controllers\ShopProductController`.
|
||||||
|
|
||||||
## pp_banners
|
## pp_banners
|
||||||
Banery.
|
Banery.
|
||||||
|
|||||||
@@ -307,5 +307,15 @@ Pelna dokumentacja testow: `TESTING.md`
|
|||||||
- Przepieto 2 wywolania `admin\factory\ShopTransport` w `admin\factory\ShopProduct` na `Domain\Transport\TransportRepository`.
|
- Przepieto 2 wywolania `admin\factory\ShopTransport` w `admin\factory\ShopProduct` na `Domain\Transport\TransportRepository`.
|
||||||
- Usuniety fallback do `admin\factory\Layouts` w `admin\controls\ShopProduct`.
|
- Usuniety fallback do `admin\factory\Layouts` w `admin\controls\ShopProduct`.
|
||||||
|
|
||||||
|
## Dodatkowa aktualizacja 2026-02-15 (ver. 0.274)
|
||||||
|
- Dodano kontroler DI `admin/Controllers/ShopProductController.php` (akcje `mass_edit`, `mass_edit_save`, `get_products_by_category`).
|
||||||
|
- Routing `admin\Site` rozszerzono o mapowanie `ShopProduct` do nowego kontrolera.
|
||||||
|
- `Domain/Product/ProductRepository.php` rozszerzono o metody dla mass-edit: `allProductsForMassEdit`, `getProductsByCategory`, `applyDiscountPercent`.
|
||||||
|
- Usunieto legacy akcje mass-edit z `autoload/admin/controls/class.ShopProduct.php`.
|
||||||
|
- Widok `/admin/shop_product/mass_edit/` przepiety na nowy partial `admin/templates/shop-product/mass-edit-custom-script.php`.
|
||||||
|
- Ujednolicono UI drzewek (strzalki/expand) w:
|
||||||
|
- `admin/templates/pages/pages-list.php` + `admin/templates/pages/subpages-list.php`
|
||||||
|
- `admin/templates/articles/subpages-list.php` + `admin/templates/articles/article-edit-custom-script.php`
|
||||||
|
|
||||||
---
|
---
|
||||||
*Dokument aktualizowany: 2026-02-15*
|
*Dokument aktualizowany: 2026-02-15*
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ grep -r "Product::getQuantity" .
|
|||||||
| # | Modul | Wersja | Zakres |
|
| # | Modul | Wersja | Zakres |
|
||||||
|---|-------|--------|--------|
|
|---|-------|--------|--------|
|
||||||
| 1 | Cache | 0.237 | CacheHandler, RedisConnection, clear_product_cache |
|
| 1 | Cache | 0.237 | CacheHandler, RedisConnection, clear_product_cache |
|
||||||
| 2 | Product | 0.238-0.252 | getQuantity, getPrice, getName, archive/unarchive |
|
| 2 | Product | 0.238-0.252, 0.274 | getQuantity, getPrice, getName, archive/unarchive, allProductsForMassEdit, getProductsByCategory, applyDiscountPercent |
|
||||||
| 3 | Banner | 0.239 | find, delete, save, kontroler DI |
|
| 3 | Banner | 0.239 | find, delete, save, kontroler DI |
|
||||||
| 4 | Settings | 0.240/0.250 | saveSettings, getSettings, kontroler DI |
|
| 4 | Settings | 0.240/0.250 | saveSettings, getSettings, kontroler DI |
|
||||||
| 5 | Dictionaries | 0.251 | listForAdmin, find, save, delete, kontroler DI |
|
| 5 | Dictionaries | 0.251 | listForAdmin, find, save, delete, kontroler DI |
|
||||||
@@ -153,12 +153,16 @@ grep -r "Product::getQuantity" .
|
|||||||
| 22 | ShopAttribute | 0.271 | list/edit/save/delete/values, nowy edytor wartosci, cleanup legacy, przepiecie zaleznosci kombinacji |
|
| 22 | ShopAttribute | 0.271 | list/edit/save/delete/values, nowy edytor wartosci, cleanup legacy, przepiecie zaleznosci kombinacji |
|
||||||
| 23 | ShopProductSets | 0.272 | listForAdmin, find, save, delete, allSets, allProductsMap, multi-select Selectize, DI kontroler |
|
| 23 | ShopProductSets | 0.272 | listForAdmin, find, save, delete, allSets, allProductsMap, multi-select Selectize, DI kontroler |
|
||||||
| 24 | ShopProducer | 0.273 | listForAdmin, find, save, delete, allProducers, producerProducts, fasada shop\Producer, DI kontroler |
|
| 24 | ShopProducer | 0.273 | listForAdmin, find, save, delete, allProducers, producerProducts, fasada shop\Producer, DI kontroler |
|
||||||
|
| 25 | ShopProduct (mass_edit) | 0.274 | DI kontroler + routing dla `mass_edit`, `mass_edit_save`, `get_products_by_category`, cleanup legacy akcji |
|
||||||
|
|
||||||
### Product - szczegolowy status
|
### Product - szczegolowy status
|
||||||
- ✅ getQuantity (ver. 0.238)
|
- ✅ getQuantity (ver. 0.238)
|
||||||
- ✅ getPrice (ver. 0.239)
|
- ✅ getPrice (ver. 0.239)
|
||||||
- ✅ getName (ver. 0.239)
|
- ✅ getName (ver. 0.239)
|
||||||
- ✅ archive / unarchive (ver. 0.241/0.252)
|
- ✅ archive / unarchive (ver. 0.241/0.252)
|
||||||
|
- ✅ allProductsForMassEdit (ver. 0.274)
|
||||||
|
- ✅ getProductsByCategory (ver. 0.274)
|
||||||
|
- ✅ applyDiscountPercent (ver. 0.274)
|
||||||
- [ ] is_product_on_promotion
|
- [ ] is_product_on_promotion
|
||||||
- [ ] getFromCache
|
- [ ] getFromCache
|
||||||
- [ ] getProductImg
|
- [ ] getProductImg
|
||||||
@@ -170,11 +174,11 @@ grep -r "Product::getQuantity" .
|
|||||||
|
|
||||||
## Kolejność refaktoryzacji (priorytet)
|
## Kolejność refaktoryzacji (priorytet)
|
||||||
|
|
||||||
1-24: ✅ Cache, Product, Banner, Settings, Dictionaries, ProductArchive, Filemanager, Users, Pages, Integrations, ShopPromotion, ShopCoupon, ShopStatuses, ShopPaymentMethod, ShopTransport, ShopAttribute, ShopProductSets, ShopProducer
|
1-25: ✅ Cache, Product, Banner, Settings, Dictionaries, ProductArchive, Filemanager, Users, Pages, Integrations, ShopPromotion, ShopCoupon, ShopStatuses, ShopPaymentMethod, ShopTransport, ShopAttribute, ShopProductSets, ShopProducer, ShopProduct (mass_edit)
|
||||||
|
|
||||||
Nastepne:
|
Nastepne:
|
||||||
25. **Order**
|
26. **Order**
|
||||||
26. **Category**
|
27. **Category**
|
||||||
|
|
||||||
## Form Edit System
|
## Form Edit System
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ Alternatywnie (Git Bash):
|
|||||||
Ostatnio zweryfikowano: 2026-02-15
|
Ostatnio zweryfikowano: 2026-02-15
|
||||||
|
|
||||||
```text
|
```text
|
||||||
OK (338 tests, 1063 assertions)
|
OK (351 tests, 1091 assertions)
|
||||||
```
|
```
|
||||||
|
|
||||||
## Struktura testow
|
## Struktura testow
|
||||||
@@ -73,6 +73,7 @@ tests/
|
|||||||
| |-- ShopCouponControllerTest.php
|
| |-- ShopCouponControllerTest.php
|
||||||
| |-- ShopPaymentMethodControllerTest.php
|
| |-- ShopPaymentMethodControllerTest.php
|
||||||
| |-- ShopProducerControllerTest.php
|
| |-- ShopProducerControllerTest.php
|
||||||
|
| |-- ShopProductControllerTest.php
|
||||||
| |-- ShopProductSetsControllerTest.php
|
| |-- ShopProductSetsControllerTest.php
|
||||||
| |-- ShopPromotionControllerTest.php
|
| |-- ShopPromotionControllerTest.php
|
||||||
| |-- ShopStatusesControllerTest.php
|
| |-- ShopStatusesControllerTest.php
|
||||||
@@ -424,3 +425,14 @@ OK (338 tests, 1063 assertions)
|
|||||||
Nowe testy dodane 2026-02-15:
|
Nowe testy dodane 2026-02-15:
|
||||||
- `tests/Unit/Domain/Producer/ProducerRepositoryTest.php` (9 testow: find default/normalize, save insert/update, delete invalid/success, whitelist sortowania/paginacji, allProducers, producerProducts)
|
- `tests/Unit/Domain/Producer/ProducerRepositoryTest.php` (9 testow: find default/normalize, save insert/update, delete invalid/success, whitelist sortowania/paginacji, allProducers, producerProducts)
|
||||||
- `tests/Unit/admin/Controllers/ShopProducerControllerTest.php` (5 testow: kontrakty metod, aliasy legacy, return types, DI konstruktora)
|
- `tests/Unit/admin/Controllers/ShopProducerControllerTest.php` (5 testow: kontrakty metod, aliasy legacy, return types, DI konstruktora)
|
||||||
|
|
||||||
|
## Aktualizacja suite (ShopProduct mass_edit, ver. 0.274)
|
||||||
|
Ostatnio zweryfikowano: 2026-02-15
|
||||||
|
|
||||||
|
```text
|
||||||
|
OK (351 tests, 1091 assertions)
|
||||||
|
```
|
||||||
|
|
||||||
|
Nowe testy dodane 2026-02-15:
|
||||||
|
- `tests/Unit/Domain/Product/ProductRepositoryTest.php` (rozszerzenie: `allProductsForMassEdit`, `getProductsByCategory`, `applyDiscountPercent`)
|
||||||
|
- `tests/Unit/admin/Controllers/ShopProductControllerTest.php` (7 testow: kontrakty metod, return types, DI konstruktora)
|
||||||
|
|||||||
1
temp/update_build/delete_files_0.274.txt
Normal file
1
temp/update_build/delete_files_0.274.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
# brak plikow do usuniecia w ver. 0.274
|
||||||
BIN
temp/update_build/update_0.274.zip
Normal file
BIN
temp/update_build/update_0.274.zip
Normal file
Binary file not shown.
@@ -347,4 +347,167 @@ class ProductRepositoryTest extends TestCase
|
|||||||
$result = $repository->archive(1);
|
$result = $repository->archive(1);
|
||||||
$this->assertIsBool($result);
|
$this->assertIsBool($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test allProductsForMassEdit - zwraca mapę id => name
|
||||||
|
*/
|
||||||
|
public function testAllProductsForMassEditReturnsMap()
|
||||||
|
{
|
||||||
|
$mockDb = $this->createMock(\medoo::class);
|
||||||
|
|
||||||
|
$callIndex = 0;
|
||||||
|
$mockDb->method('get')
|
||||||
|
->willReturnCallback(function($table, $column, $where) use (&$callIndex) {
|
||||||
|
$callIndex++;
|
||||||
|
// 1. domyślny język
|
||||||
|
if ($table === 'pp_langs') return 'pl';
|
||||||
|
// 2. nazwa produktu 1
|
||||||
|
if ($table === 'pp_shop_products_langs' && $where['AND']['product_id'] === 1) return 'Produkt A';
|
||||||
|
// 3. nazwa produktu 2
|
||||||
|
if ($table === 'pp_shop_products_langs' && $where['AND']['product_id'] === 2) return 'Produkt B';
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
$mockDb->method('select')
|
||||||
|
->with('pp_shop_products', 'id', ['parent_id' => null])
|
||||||
|
->willReturn([1, 2]);
|
||||||
|
|
||||||
|
$repository = new ProductRepository($mockDb);
|
||||||
|
|
||||||
|
$result = $repository->allProductsForMassEdit();
|
||||||
|
|
||||||
|
$this->assertIsArray($result);
|
||||||
|
$this->assertCount(2, $result);
|
||||||
|
$this->assertEquals('Produkt A', $result[1]);
|
||||||
|
$this->assertEquals('Produkt B', $result[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test allProductsForMassEdit - pusta lista gdy brak produktów
|
||||||
|
*/
|
||||||
|
public function testAllProductsForMassEditEmptyWhenNoProducts()
|
||||||
|
{
|
||||||
|
$mockDb = $this->createMock(\medoo::class);
|
||||||
|
$mockDb->method('get')->willReturn('pl');
|
||||||
|
$mockDb->method('select')->willReturn([]);
|
||||||
|
|
||||||
|
$repository = new ProductRepository($mockDb);
|
||||||
|
|
||||||
|
$result = $repository->allProductsForMassEdit();
|
||||||
|
|
||||||
|
$this->assertIsArray($result);
|
||||||
|
$this->assertEmpty($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test getProductsByCategory - zwraca listę ID
|
||||||
|
*/
|
||||||
|
public function testGetProductsByCategoryReturnsList()
|
||||||
|
{
|
||||||
|
$mockDb = $this->createMock(\medoo::class);
|
||||||
|
$mockDb->method('select')
|
||||||
|
->with('pp_shop_products_categories', 'product_id', ['category_id' => 5])
|
||||||
|
->willReturn([10, 20, 30]);
|
||||||
|
|
||||||
|
$repository = new ProductRepository($mockDb);
|
||||||
|
|
||||||
|
$result = $repository->getProductsByCategory(5);
|
||||||
|
|
||||||
|
$this->assertIsArray($result);
|
||||||
|
$this->assertCount(3, $result);
|
||||||
|
$this->assertEquals([10, 20, 30], $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test getProductsByCategory - pusta lista gdy brak produktów w kategorii
|
||||||
|
*/
|
||||||
|
public function testGetProductsByCategoryReturnsEmptyArray()
|
||||||
|
{
|
||||||
|
$mockDb = $this->createMock(\medoo::class);
|
||||||
|
$mockDb->method('select')->willReturn([]);
|
||||||
|
|
||||||
|
$repository = new ProductRepository($mockDb);
|
||||||
|
|
||||||
|
$result = $repository->getProductsByCategory(999);
|
||||||
|
|
||||||
|
$this->assertIsArray($result);
|
||||||
|
$this->assertEmpty($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test applyDiscountPercent - zwraca null gdy produkt nie istnieje
|
||||||
|
*/
|
||||||
|
public function testApplyDiscountPercentReturnsNullForInvalidProduct()
|
||||||
|
{
|
||||||
|
$mockDb = $this->createMock(\medoo::class);
|
||||||
|
$mockDb->method('get')->willReturn(false);
|
||||||
|
|
||||||
|
$repository = new ProductRepository($mockDb);
|
||||||
|
|
||||||
|
$result = $repository->applyDiscountPercent(999, 10.0);
|
||||||
|
|
||||||
|
$this->assertNull($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test applyDiscountPercent - poprawny wynik z rabatem
|
||||||
|
*/
|
||||||
|
public function testApplyDiscountPercentReturnsCorrectPrices()
|
||||||
|
{
|
||||||
|
$mockDb = $this->createMock(\medoo::class);
|
||||||
|
|
||||||
|
$mockDb->method('get')
|
||||||
|
->willReturn([
|
||||||
|
'vat' => 23,
|
||||||
|
'price_brutto' => '100.00',
|
||||||
|
'price_netto' => '81.30',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$mockDb->method('update')
|
||||||
|
->willReturn($this->createMock(\PDOStatement::class));
|
||||||
|
|
||||||
|
// query zwracający puste kombinacje
|
||||||
|
$mockStmt = $this->createMock(\PDOStatement::class);
|
||||||
|
$mockStmt->method('fetchAll')->willReturn([]);
|
||||||
|
$mockDb->method('query')->willReturn($mockStmt);
|
||||||
|
|
||||||
|
$repository = new ProductRepository($mockDb);
|
||||||
|
|
||||||
|
$result = $repository->applyDiscountPercent(1, 10.0);
|
||||||
|
|
||||||
|
$this->assertIsArray($result);
|
||||||
|
$this->assertArrayHasKey('price_brutto', $result);
|
||||||
|
$this->assertArrayHasKey('price_brutto_promo', $result);
|
||||||
|
$this->assertEquals(100.00, $result['price_brutto']);
|
||||||
|
$this->assertEquals(90.00, $result['price_brutto_promo']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test applyDiscountPercent - rabat 0% nie tworzy ceny promocyjnej
|
||||||
|
*/
|
||||||
|
public function testApplyDiscountPercentZeroPercentNullsPromo()
|
||||||
|
{
|
||||||
|
$mockDb = $this->createMock(\medoo::class);
|
||||||
|
|
||||||
|
$mockDb->method('get')
|
||||||
|
->willReturn([
|
||||||
|
'vat' => 23,
|
||||||
|
'price_brutto' => '100.00',
|
||||||
|
'price_netto' => '81.30',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$mockDb->method('update')
|
||||||
|
->willReturn($this->createMock(\PDOStatement::class));
|
||||||
|
|
||||||
|
$mockStmt = $this->createMock(\PDOStatement::class);
|
||||||
|
$mockStmt->method('fetchAll')->willReturn([]);
|
||||||
|
$mockDb->method('query')->willReturn($mockStmt);
|
||||||
|
|
||||||
|
$repository = new ProductRepository($mockDb);
|
||||||
|
|
||||||
|
$result = $repository->applyDiscountPercent(1, 0.0);
|
||||||
|
|
||||||
|
$this->assertIsArray($result);
|
||||||
|
$this->assertNull($result['price_brutto_promo']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
59
tests/Unit/admin/Controllers/ShopProductControllerTest.php
Normal file
59
tests/Unit/admin/Controllers/ShopProductControllerTest.php
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
<?php
|
||||||
|
namespace Tests\Unit\admin\Controllers;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use admin\Controllers\ShopProductController;
|
||||||
|
use Domain\Product\ProductRepository;
|
||||||
|
|
||||||
|
class ShopProductControllerTest extends TestCase
|
||||||
|
{
|
||||||
|
private $repository;
|
||||||
|
private $controller;
|
||||||
|
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
$this->repository = $this->createMock(ProductRepository::class);
|
||||||
|
$this->controller = new ShopProductController($this->repository);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testConstructorAcceptsRepository(): void
|
||||||
|
{
|
||||||
|
$controller = new ShopProductController($this->repository);
|
||||||
|
$this->assertInstanceOf(ShopProductController::class, $controller);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testHasMassEditActionMethods(): void
|
||||||
|
{
|
||||||
|
$this->assertTrue(method_exists($this->controller, 'mass_edit'));
|
||||||
|
$this->assertTrue(method_exists($this->controller, 'mass_edit_save'));
|
||||||
|
$this->assertTrue(method_exists($this->controller, 'get_products_by_category'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testMassEditReturnsString(): void
|
||||||
|
{
|
||||||
|
$reflection = new \ReflectionClass($this->controller);
|
||||||
|
$this->assertEquals('string', (string)$reflection->getMethod('mass_edit')->getReturnType());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testMassEditSaveReturnsVoid(): void
|
||||||
|
{
|
||||||
|
$reflection = new \ReflectionClass($this->controller);
|
||||||
|
$this->assertEquals('void', (string)$reflection->getMethod('mass_edit_save')->getReturnType());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetProductsByCategoryReturnsVoid(): void
|
||||||
|
{
|
||||||
|
$reflection = new \ReflectionClass($this->controller);
|
||||||
|
$this->assertEquals('void', (string)$reflection->getMethod('get_products_by_category')->getReturnType());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testConstructorRequiresProductRepository(): void
|
||||||
|
{
|
||||||
|
$reflection = new \ReflectionClass(ShopProductController::class);
|
||||||
|
$constructor = $reflection->getConstructor();
|
||||||
|
$params = $constructor->getParameters();
|
||||||
|
|
||||||
|
$this->assertCount(1, $params);
|
||||||
|
$this->assertEquals('Domain\Product\ProductRepository', $params[0]->getType()->getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -51,6 +51,7 @@ if (!class_exists('S')) {
|
|||||||
public static function clear_product_cache($id) {}
|
public static function clear_product_cache($id) {}
|
||||||
public static function send_email($to, $subject, $body) { return true; }
|
public static function send_email($to, $subject, $body) { return true; }
|
||||||
public static function remove_special_chars($str) { return str_ireplace(['\'', '"', ',', ';', '<', '>'], ' ', $str); }
|
public static function remove_special_chars($str) { return str_ireplace(['\'', '"', ',', ';', '<', '>'], ' ', $str); }
|
||||||
|
public static function normalize_decimal($val, $precision = 2) { return round((float)$val, $precision); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user