PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.1
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.1
1.6.6 1.6.5 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 All 49 releases
fluent-cart / app / Services / Filter / OrderBumpFilter.php

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

203 lines 7.2 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\Helpers\Status;
6 use FluentCart\App\Services\DateTime\DateTime;
7 use FluentCartPro\App\Modules\Licensing\Models\License;
8 use FluentCartPro\App\Modules\Promotional\Models\OrderPromotion;
9
10
11 class OrderBumpFilter extends BaseFilter
12 {
13
14 public function applySimpleFilter(?string $search = null): void
15 {
16 $isApplied = $this->applySimpleOperatorFilter($search);
17 if ($isApplied) {
18 return;
19 }
20
21 $this->query->when($search ?? $this->search, function ($query, $search) {
22 // If search is an array, implode it
23 $search = is_array($search) ? implode(' ', $search) : $search;
24
25 // If search is empty or null, return the query
26 if (empty($search)) {
27 return $query;
28 }
29
30 $query->where(function ($query) use ($search) {
31 $query->where('title', 'like', '%' . $search . '%')
32 ->orWhere('id', 'like', '%' . $search . '%');
33 });
34
35 return $query;
36 });
37 }
38
39 public function tabsMap(): array
40 {
41 return [
42 'active' => __('Active', 'fluent-cart'),
43 'inactive' => __('Inactive', 'fluent-cart'),
44 ];
45 }
46
47 public function getModel(): string
48 {
49 return OrderPromotion::class;
50 }
51
52 public static function getFilterName(): string
53 {
54 return 'order_bump';
55 }
56
57 /**
58 * Intentionally empty. Nothing instantiates this filter: the order-bump
59 * list endpoint is Pro's OrderBumpController::index(), which builds its own
60 * OrderPromotion query and hardcodes `->with(['product_variant.product'])`.
61 * OrderBumpTable.js's `product_variant` therefore never reaches this map.
62 *
63 * If the Pro controller is ever moved onto this filter, declare
64 * `product_variant` (and its `.product` child) here — do not widen the map
65 * speculatively before that happens.
66 *
67 * @return array<string, callable>
68 */
69 protected function allowedWiths(): array
70 {
71 return [];
72 }
73
74
75 public function applyActiveViewFilter(?string $activeView = null): void
76 {
77 $activeView = $activeView ?? $this->activeView;
78 $this->query->when($activeView, function ($query, $activeView) {
79 $validStatuses = [
80 'active',
81 'draft'
82 ];
83
84 if (in_array($activeView, $validStatuses)) {
85 if ($activeView == 'expired') {
86 $query->where('expiration_date', '<', DateTime::gmtNow());
87 } else if ($activeView == 'active') {
88 $query->where(function ($query) {
89 $query->where('expiration_date', '>', DateTime::gmtNow())
90 ->orWhereNull('expiration_date');
91 })
92 ->where('status', 'active');
93 } else {
94 $query->where('status', $activeView);
95 }
96 } else if ($activeView == 'inactive') {
97 $query->where('status', 'active')
98 ->whereDoesntHave('activations');
99 }
100
101 return $query;
102 });
103 }
104
105 public static function getSearchableFields(): array
106 {
107 return [
108 'key' => [
109 'column' => 'title',
110 'description' => 'title',
111 'type' => 'string'
112 ]
113 ];
114 }
115
116 public static function advanceFilterOptions(): array
117 {
118 $filters = [
119 'product' => [
120 'label' => __('Products', 'fluent-cart'),
121 'value' => 'product',
122 'children' => [
123 [
124 'label' => __('By Products', 'fluent-cart'),
125 'value' => 'product',
126 'column' => 'variation_id',
127 'filter_type' => 'relation',
128 'relation' => 'productVariant',
129 'remote_data_key' => 'product_variations',
130 'type' => 'remote_tree_select',
131 'limit' => 10,
132 ],
133 ],
134 ],
135 'customer' => [
136 'label' => __('Customer Property', 'fluent-cart'),
137 'value' => 'customer',
138 'children' => [
139 [
140 'label' => __('Customer first name', 'fluent-cart'),
141 'value' => 'customer_first_name',
142 'type' => 'text',
143 'filter_type' => 'relation',
144 'column' => 'first_name',
145 'relation' => 'customer',
146 ],
147 [
148 'label' => __('Customer last name', 'fluent-cart'),
149 'value' => 'customer_last_name',
150 'type' => 'text',
151 'filter_type' => 'relation',
152 'column' => 'last_name',
153 'relation' => 'customer',
154 ]
155 ],
156 ],
157 'license' => [
158 'label' => __('License Property', 'fluent-cart'),
159 'value' => 'license',
160 'children' => [
161 [
162 'label' => __('License key', 'fluent-cart'),
163 'value' => 'license_key',
164 'type' => 'text',
165 'filter_type' => 'column',
166 'column' => 'license_key',
167 ],
168 [
169 'label' => __('Status', 'fluent-cart'),
170 'value' => 'status',
171 'type' => 'selections',
172 'filter_type' => 'column',
173 'column' => 'status',
174 'options' => [
175 Status::LICENSE_ACTIVE => __('Active', 'fluent-cart'),
176 Status::LICENSE_DISABLED => __('Disabled', 'fluent-cart'),
177 Status::LICENSE_EXPIRED => __('Expired', 'fluent-cart'),
178 ],
179 'is_multiple' => true,
180 'is_only_in' => true
181 ],
182 [
183 'label' => __('Activation Count', 'fluent-cart'),
184 'value' => 'activation_count',
185 'type' => 'numeric',
186 'filter_type' => 'column',
187 'column' => 'activation_count',
188 ],
189 [
190 'label' => __('Expiration Date', 'fluent-cart'),
191 'value' => 'expiration_date',
192 'type' => 'dates',
193 'filter_type' => 'date',
194 'column' => 'expiration_date',
195 ]
196 ],
197 ],
198 ];
199 return LabelFilter::advanceFilterOptionsForOther($filters);
200 }
201
202 }
203