PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.3.21
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.3.21
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 / Hooks / Handlers / ShortCodes / SearchBarShortCode.php

SearchBarShortCode.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.3.21, at app/Hooks/Handlers/ShortCodes/SearchBarShortCode.php

75 lines 1.9 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\Hooks\Handlers\ShortCodes;
4
5 use FluentCart\App\CPT\FluentProducts;
6 use FluentCart\App\Helpers\Helper;
7 use FluentCart\App\Vite;
8 use FluentCart\Framework\Support\Arr;
9 use FluentCart\Framework\Support\Collection;
10 use FluentCart\App\Services\Renderer\SearchBarRenderer;
11
12 class SearchBarShortCode extends ShortCode
13 {
14 protected static string $shortCodeName = 'fluent_products_search_bar';
15
16 public function getScripts(): array
17 {
18 return [
19 [
20 'source' => 'public/search-bar-app/SearchBarApp.js',
21 'dependencies' => ['jquery']
22 ]
23 ];
24 }
25
26 public function getStyles(): array
27 {
28 return [
29 'public/search-bar-app/style/style.scss'
30 ];
31 }
32
33 public function localizeData(): array
34 {
35 return [
36 'fluentcart_search_bar_vars' => [
37 'rest' => Helper::getRestInfo(),
38 ]
39 ];
40 }
41
42 public function viewData(): ?array
43 {
44 return [
45 'url_mode' => Arr::get($this->shortCodeAttributes, 'url_mode'),
46 'category_mode' => Arr::get($this->shortCodeAttributes, 'category_mode'),
47 'termData' => $this->getTermsData('categories'),
48 'link_with_shop_app' => Arr::get($this->shortCodeAttributes, 'link_with_shop_app'),
49 ];
50 }
51
52 public function render(?array $viewData = null)
53 {
54 (new SearchBarRenderer($viewData))->render();
55 }
56
57 private function getTermsData($key): array
58 {
59 if (!$key) {
60 return [];
61 }
62 $options = get_categories([
63 'taxonomy' => 'product-' . $key,
64 'post_type' => FluentProducts::CPT_NAME
65 ]);
66
67 return Collection::make($options)->map(function ($meta) {
68 return [
69 'termId' => $meta->term_id,
70 'termName' => $meta->name,
71 ];
72 })->toArray();
73 }
74 }
75