PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.3.25
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.3.25
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 / VariationFilter.php

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

72 lines 2.0 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\Product;
6 use FluentCart\Framework\Database\Orm\Builder;
7
8 class VariationFilter extends BaseFilter
9 {
10
11 public function applySimpleFilter(?string $search = null): void
12 {
13
14 $this->query = $this->query->when($search ?? $this->search, function ($query, $search) {
15 return $query->where('post_title', 'LIKE', "%{$search}%")
16 ->orWhereHas('variants', function (Builder $query) use ($search) {
17 $query->where('variation_title', 'LIKE', "%{$search}%");
18 });
19 });
20 }
21
22 protected function applyMustLoadIds()
23 {
24 $this->query = $this->query->orWhereIn('ID', $this->includeIds)
25 ->orWhereHas('variants', function (Builder $query) {
26 $query->orWhereIn('id', $this->includeIds);
27 });
28 }
29
30 public function tabsMap(): array
31 {
32 return [
33 'publish' => 'post_status',
34 'simple' => 'variation_type',
35 'simple_variations' => 'variation_type',
36 'physical' => 'fulfillment_type',
37 'digital' => 'fulfillment_type',
38 ];
39 }
40
41 public function getModel(): string
42 {
43 return Product::class;
44 }
45
46 public static function getFilterName(): string
47 {
48 return 'product_variation';
49 }
50
51 public function applyActiveViewFilter(?string $activeView = null): void
52 {
53
54 }
55
56 public static function getTreeFilterOptions(array $args): array
57 {
58
59 return static::make($args)->get()->map(function ($product) {
60 return [
61 'value' => $product->ID,
62 'label' => $product->post_title,
63 'children' => $product->variants->map(function ($variation) {
64 return [
65 'value' => $variation->id,
66 'label' => $variation->variation_title,
67 ];
68 })->toArray()
69 ];
70 })->toArray();
71 }
72 }