PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.3.19
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.3.19
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.3.19, at app/Services/Filter/OrderBumpFilter.php

186 lines 6.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\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 public function applyActiveViewFilter(?string $activeView = null): void
59 {
60 $activeView = $activeView ?? $this->activeView;
61 $this->query->when($activeView, function ($query, $activeView) {
62 $validStatuses = [
63 'active',
64 'draft'
65 ];
66
67 if (in_array($activeView, $validStatuses)) {
68 if ($activeView == 'expired') {
69 $query->where('expiration_date', '<', DateTime::gmtNow());
70 } else if ($activeView == 'active') {
71 $query->where(function ($query) {
72 $query->where('expiration_date', '>', DateTime::gmtNow())
73 ->orWhereNull('expiration_date');
74 })
75 ->where('status', 'active');
76 } else {
77 $query->where('status', $activeView);
78 }
79 } else if ($activeView == 'inactive') {
80 $query->where('status', 'active')
81 ->whereDoesntHave('activations');
82 }
83
84 return $query;
85 });
86 }
87
88 public static function getSearchableFields(): array
89 {
90 return [
91 'key' => [
92 'column' => 'title',
93 'description' => 'title',
94 'type' => 'string'
95 ]
96 ];
97 }
98
99 public static function advanceFilterOptions(): array
100 {
101 $filters = [
102 'product' => [
103 'label' => __('Products', 'fluent-cart'),
104 'value' => 'product',
105 'children' => [
106 [
107 'label' => __('By Products', 'fluent-cart'),
108 'value' => 'product',
109 'column' => 'variation_id',
110 'filter_type' => 'relation',
111 'relation' => 'productVariant',
112 'remote_data_key' => 'product_variations',
113 'type' => 'remote_tree_select',
114 'limit' => 10,
115 ],
116 ],
117 ],
118 'customer' => [
119 'label' => __('Customer Property', 'fluent-cart'),
120 'value' => 'customer',
121 'children' => [
122 [
123 'label' => __('Customer first name', 'fluent-cart'),
124 'value' => 'customer_first_name',
125 'type' => 'text',
126 'filter_type' => 'relation',
127 'column' => 'first_name',
128 'relation' => 'customer',
129 ],
130 [
131 'label' => __('Customer last name', 'fluent-cart'),
132 'value' => 'customer_last_name',
133 'type' => 'text',
134 'filter_type' => 'relation',
135 'column' => 'last_name',
136 'relation' => 'customer',
137 ]
138 ],
139 ],
140 'license' => [
141 'label' => __('License Property', 'fluent-cart'),
142 'value' => 'license',
143 'children' => [
144 [
145 'label' => __('License key', 'fluent-cart'),
146 'value' => 'license_key',
147 'type' => 'text',
148 'filter_type' => 'column',
149 'column' => 'license_key',
150 ],
151 [
152 'label' => __('Status', 'fluent-cart'),
153 'value' => 'status',
154 'type' => 'selections',
155 'filter_type' => 'column',
156 'column' => 'status',
157 'options' => [
158 Status::LICENSE_ACTIVE => __('Active', 'fluent-cart'),
159 Status::LICENSE_DISABLED => __('Disabled', 'fluent-cart'),
160 Status::LICENSE_EXPIRED => __('Expired', 'fluent-cart'),
161 ],
162 'is_multiple' => true,
163 'is_only_in' => true
164 ],
165 [
166 'label' => __('Activation Count', 'fluent-cart'),
167 'value' => 'activation_count',
168 'type' => 'numeric',
169 'filter_type' => 'column',
170 'column' => 'activation_count',
171 ],
172 [
173 'label' => __('Expiration Date', 'fluent-cart'),
174 'value' => 'expiration_date',
175 'type' => 'dates',
176 'filter_type' => 'date',
177 'column' => 'expiration_date',
178 ]
179 ],
180 ],
181 ];
182 return LabelFilter::advanceFilterOptionsForOther($filters);
183 }
184
185 }
186