PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.5.3
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.5.3
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 trunk All 48 releases
fluent-cart / app / Services / Filter / CustomerFilter.php

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

158 lines 5.4 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\AddressHelper;
6 use FluentCart\App\Models\Activity;
7 use FluentCart\App\Models\Customer;
8 use FluentCart\Framework\Support\Arr;
9 use FluentCart\Framework\Support\Str;
10
11 class CustomerFilter 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 $this->query->when($search ?? $this->search, function ($query, $search) {
21
22 return $query
23 ->where(function ($query) use ($search) {
24 $search = trim($search);
25 $searchLike = addcslashes($search, '\\%_');
26 $query
27 ->whereRaw("CONCAT(first_name, ' ', last_name) LIKE ?", ["%{$searchLike}%"])
28 ->when(is_numeric($search), function ($query) use ($search) {
29 $query->orWhere('id', 'LIKE', "%{$search}%");
30 })
31 ->when(!str_contains($search, ' '), function ($query) use ($search) {
32 $query->orWhere('email', 'LIKE', "%{$search}%");
33 });
34 });
35 });
36 }
37
38
39 public function tabsMap(): array
40 {
41 return [
42
43 ];
44 }
45
46 public function getModel(): string
47 {
48 return Customer::class;
49 }
50
51 public static function getFilterName(): string
52 {
53 return 'customers';
54 }
55
56
57 public function applyActiveViewFilter(?string $activeView = null): void
58 {
59
60 }
61
62 public static function getSearchableFields(): array
63 {
64 return [
65 'id' => [
66 'column' => 'ID',
67 'description' => 'Customer ID',
68 'type' => 'numeric'
69 ]
70 ];
71 }
72
73 public static function advanceFilterOptions(): array
74 {
75 $filters = [
76 'order' => [
77 'label' => __('Order Property', 'fluent-cart'),
78 'value' => 'order',
79 'children' => [
80 [
81 'label' => __('By Order Items', 'fluent-cart'),
82 'value' => 'order_items',
83 'column' => 'object_id',
84 'filter_type' => 'relation',
85 'relation' => 'orders.order_items',
86 'remote_data_key' => 'product_variations',
87 'type' => 'remote_tree_select',
88 'limit' => 10,
89 ],
90 [
91 'label' => __('Purchases', 'fluent-cart'),
92 'value' => 'purchase_count',
93 'type' => 'numeric',
94 ],
95 [
96 'label' => __('First Purchase Date', 'fluent-cart'),
97 'value' => 'first_purchase_date',
98 'type' => 'dates',
99 'filter_type' => 'date',
100 ],
101 [
102 'label' => __('Last Purchase Date', 'fluent-cart'),
103 'value' => 'last_purchase_date',
104 'type' => 'dates',
105 'filter_type' => 'date',
106 ]
107 ],
108 ],
109 'customer' => [
110 'label' => __('Customer Property', 'fluent-cart'),
111 'value' => 'customer',
112 'children' => [
113 [
114 'label' => __('Customer Name', 'fluent-cart'),
115 'value' => 'customer_full_name',
116 'type' => 'text',
117 'filter_type' => 'custom',
118 'operators' => [
119 'like_all' => __('Contains', 'fluent-cart'),
120 'starts_with' => __('Starts With', 'fluent-cart'),
121 'ends_with' => __('Ends With', 'fluent-cart'),
122 'not_like' => __('Not Contains', 'fluent-cart'),
123 ],
124 'callback' => function ($query, $data) {
125 $query->searchByFullName($data);
126 }
127 ],
128 [
129 'label' => __('Customer Email', 'fluent-cart'),
130 'value' => 'email',
131 'type' => 'text',
132 'filter_type' => 'column',
133 'column' => 'email',
134 ],
135 [
136 'label' => __('Customer LTV', 'fluent-cart'),
137 'value' => 'ltv',
138 'type' => 'numeric',
139 'filter_type' => 'column',
140 'column' => 'ltv'
141 ]
142 ],
143 ]
144 ];
145 return LabelFilter::advanceFilterOptionsForOther($filters);
146 }
147
148 public function dateColumns(): array
149 {
150 return array_merge(parent::dateColumns(), ['first_purchase_date', 'last_purchase_date']);
151 }
152
153 public function centColumns(): array
154 {
155 return ['ltv'];
156 }
157 }
158