Skip to content

Commit 7098af7

Browse files
committed
fix(manager): show draft orders toggle and grid filter params (#302)
Vue orders grid lacked a way to include draft rows despite ms3_order_show_drafts, and column filters were sent without the filter_ prefix expected by the API.
1 parent c29b4d6 commit 7098af7

5 files changed

Lines changed: 83 additions & 7 deletions

File tree

core/components/minishop3/controllers/mgr/orders.class.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public function loadCustomCssJs()
3838
$this->addJavascript($this->ms3->config['jsUrl'] . 'mgr/orders/orders.wrapper.js');
3939

4040
$config = $this->ms3->config;
41+
$config['order_show_drafts'] = (bool) $this->modx->getOption('ms3_order_show_drafts', null, false);
4142
$this->addHtml('<script>Object.assign(ms3.config, ' . json_encode($config) . ');</script>');
4243

4344
$this->addCss($this->ms3->config['assetsUrl'] . 'css/mgr/vue-dist/primeicons.min.css');

core/components/minishop3/lexicon/en/vue.inc.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,7 @@
489489
$_lang['orders_title'] = 'Orders';
490490
$_lang['orders_month'] = 'Orders';
491491
$_lang['orders_month_sum'] = 'Total sum';
492+
$_lang['ms3_orders_show_drafts'] = 'Show drafts';
492493
$_lang['order_num'] = 'Number';
493494
$_lang['order_customer'] = 'Customer';
494495
$_lang['order_status'] = 'Status';

core/components/minishop3/lexicon/ru/vue.inc.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,7 @@
489489
$_lang['orders_title'] = 'Заказы';
490490
$_lang['orders_month'] = 'Заказов';
491491
$_lang['orders_month_sum'] = 'На сумму';
492+
$_lang['ms3_orders_show_drafts'] = 'Показывать черновики';
492493
$_lang['order_num'] = 'Номер';
493494
$_lang['order_customer'] = 'Клиент';
494495
$_lang['order_status'] = 'Статус';

core/components/minishop3/src/Controllers/Api/Manager/OrdersController.php

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,7 @@ public function getList(array $params = []): array
155155
}
156156
}
157157

158-
$showDrafts = $this->modx->getOption('ms3_order_show_drafts', null, false);
159-
if (!$showDrafts) {
160-
$statusDrafts = (int) $this->modx->getOption('ms3_status_draft', null, 1) ?: 1;
161-
$c->where(['status_id:!=' => $statusDrafts]);
162-
}
158+
$this->applyDraftVisibilityFilter($c, $params);
163159

164160
if (!empty($query)) {
165161
if (is_numeric($query)) {
@@ -1552,6 +1548,38 @@ protected function getOrdersStats(array $params = []): array
15521548
];
15531549
}
15541550

1551+
/**
1552+
* Whether draft orders should be included in manager list/stats queries.
1553+
*
1554+
* Request param `show_drafts` overrides the system setting `ms3_order_show_drafts`.
1555+
*/
1556+
protected function shouldShowDrafts(array $params): bool
1557+
{
1558+
if (array_key_exists('show_drafts', $params)) {
1559+
$value = $params['show_drafts'];
1560+
if ($value === '' || $value === null) {
1561+
return (bool) $this->modx->getOption('ms3_order_show_drafts', null, false);
1562+
}
1563+
1564+
return filter_var($value, FILTER_VALIDATE_BOOLEAN);
1565+
}
1566+
1567+
return (bool) $this->modx->getOption('ms3_order_show_drafts', null, false);
1568+
}
1569+
1570+
/**
1571+
* Exclude draft status from query unless drafts are explicitly shown.
1572+
*/
1573+
protected function applyDraftVisibilityFilter($c, array $params): void
1574+
{
1575+
if ($this->shouldShowDrafts($params)) {
1576+
return;
1577+
}
1578+
1579+
$statusDrafts = (int) $this->modx->getOption('ms3_status_draft', null, 1) ?: 1;
1580+
$c->where(['status_id:!=' => $statusDrafts]);
1581+
}
1582+
15551583
/**
15561584
* Apply filter to query
15571585
*

vueManager/src/components/OrdersGrid.vue

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { useLexicon } from '@vuetools/useLexicon'
33
import Button from 'primevue/button'
44
import Card from 'primevue/card'
5+
import Checkbox from 'primevue/checkbox'
56
import Column from 'primevue/column'
67
import ConfirmDialog from 'primevue/confirmdialog'
78
import DataTable from 'primevue/datatable'
@@ -20,6 +21,20 @@ import ActionsColumn from './ActionsColumn.vue'
2021
const toast = useToast()
2122
const { _ } = useLexicon()
2223
24+
const ms3Config = typeof ms3 !== 'undefined' ? ms3.config : null
25+
const showDrafts = ref(Boolean(ms3Config?.order_show_drafts))
26+
27+
/** Filter keys sent as direct API params (not filter_ prefix). */
28+
const DIRECT_FILTER_KEYS = new Set([
29+
'query',
30+
'status_id',
31+
'delivery_id',
32+
'payment_id',
33+
'context_key',
34+
'createdon_from',
35+
'createdon_to',
36+
])
37+
2338
// Bulk selection
2439
const {
2540
selectedItems,
@@ -73,13 +88,13 @@ async function loadOrders() {
7388
limit: rows.value,
7489
sort: sortField.value,
7590
dir: sortOrder.value === 1 ? 'ASC' : 'DESC',
91+
show_drafts: showDrafts.value ? 1 : 0,
7692
}
7793
7894
// Apply filter values
7995
Object.keys(filterValues.value).forEach(key => {
8096
const value = filterValues.value[key]
8197
if (value !== null && value !== undefined && value !== '') {
82-
// Handle daterange type
8398
const filterConfig = filters.value[key]
8499
if (filterConfig?.type === 'daterange' && Array.isArray(value)) {
85100
if (value[0]) {
@@ -90,8 +105,10 @@ async function loadOrders() {
90105
}
91106
} else if (filterConfig?.type === 'datepicker' && value) {
92107
params[key] = formatDateForApi(value)
93-
} else {
108+
} else if (DIRECT_FILTER_KEYS.has(key)) {
94109
params[key] = value
110+
} else {
111+
params[`filter_${key}`] = value
95112
}
96113
}
97114
})
@@ -373,6 +390,11 @@ const hasActiveFilters = computed(() => {
373390
return Object.values(filterValues.value).some(v => v !== null && v !== '' && v !== undefined)
374391
})
375392
393+
function toggleShowDrafts() {
394+
first.value = 0
395+
loadOrders()
396+
}
397+
376398
/**
377399
* Load grid configuration
378400
*/
@@ -648,6 +670,15 @@ onMounted(async () => {
648670
649671
<!-- Filter buttons -->
650672
<div class="filter-buttons">
673+
<div class="show-drafts-toggle">
674+
<Checkbox
675+
v-model="showDrafts"
676+
input-id="orders-show-drafts"
677+
binary
678+
@change="toggleShowDrafts"
679+
/>
680+
<label for="orders-show-drafts">{{ _('ms3_orders_show_drafts') }}</label>
681+
</div>
651682
<Button
652683
:label="_('apply_filters')"
653684
icon="pi pi-filter"
@@ -876,7 +907,21 @@ onMounted(async () => {
876907
877908
.filter-buttons {
878909
display: flex;
910+
flex-wrap: wrap;
911+
align-items: center;
912+
gap: 0.5rem;
913+
}
914+
915+
.show-drafts-toggle {
916+
display: flex;
917+
align-items: center;
879918
gap: 0.5rem;
919+
margin-right: auto;
920+
}
921+
922+
.show-drafts-toggle label {
923+
cursor: pointer;
924+
user-select: none;
880925
}
881926
882927
/* Bulk actions toolbar */

0 commit comments

Comments
 (0)