PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.4
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.4
1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 trunk 1.2.0 All 47 releases
fluent-cart / app / Services / Filter / AttrTermFilter.php

AttrTermFilter.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.6.4, at app/Services/Filter/AttrTermFilter.php

98 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCart\App\Services\Filter;
4
5 use FluentCart\App\Models\AttributeTerm;
6 use FluentCart\App\Services\Filter\BaseFilter;
7 use FluentCart\App\Services\Filter\Concerns\HasIdTitleSlugSearch;
8
9 class AttrTermFilter extends BaseFilter
10 {
11 use HasIdTitleSlugSearch;
12 public string $defaultSortBy = 'serial';
13 public string $defaultSortType = 'asc';
14
15 protected function parseSortBy(): string
16 {
17 return 'serial';
18 }
19
20 protected function parseSortType(): string
21 {
22 return 'asc';
23 }
24
25 protected ?int $groupId = null;
26
27 public function setGroupId(int $groupId): self
28 {
29 $this->groupId = $groupId;
30 return $this;
31 }
32
33 public function applySelect(): void
34 {
35 $this->query->select(['id', 'title', 'settings', 'serial', 'created_at']);
36 }
37
38 protected function buildCommonQuery()
39 {
40 if ($this->groupId) {
41 $this->query->where('group_id', $this->groupId);
42 }
43
44 parent::buildCommonQuery();
45
46 // Default sort is serial ASC, but two terms can share the same serial
47 // (the swap-on-reorder logic guarantees uniqueness within a group at
48 // the moment of reorder, but bulk imports or partial states can leave
49 // ties). Append id ASC as a deterministic tie-breaker so paginated
50 // listings stay stable across requests.
51 $this->query->orderBy('id', 'ASC');
52 }
53
54 public function tabsMap(): array
55 {
56 return [];
57 }
58
59 public function getModel(): string
60 {
61 return AttributeTerm::class;
62 }
63
64 public static function getFilterName(): string
65 {
66 return 'attr_terms';
67 }
68
69 /**
70 * @return array<string, array<string, mixed>>
71 */
72 protected static function sortableColumns(): array
73 {
74 return [
75 'serial' => ['label' => __('Serial', 'fluent-cart'), 'column' => 'serial'],
76 'title' => ['label' => __('Title', 'fluent-cart'), 'column' => 'title'],
77 'created_at' => ['label' => __('Created at', 'fluent-cart'), 'column' => 'created_at'],
78 ];
79 }
80
81 /**
82 * Intentionally empty, and verified so: AttrTermsTable.js sends no `with`
83 * at all, so there is nothing to allow. Add an entry only when a caller
84 * actually needs it — do not pre-open relations.
85 *
86 * @return array<string, callable>
87 */
88 protected function allowedWiths(): array
89 {
90 return [];
91 }
92
93 public function applyActiveViewFilter(?string $activeView = null): void
94 {
95 // Terms have no tab views; this hook is intentionally a no-op.
96 }
97 }
98