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

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

75 lines 2.1 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\Framework\Support\Arr;
8 use FluentCart\Framework\Support\Collection;
9 use FluentCart\App\Services\Renderer\SearchBarRenderer;
10
11 class SearchBarShortCode extends ShortCode
12 {
13 protected static string $shortCodeName = 'fluent_products_search_bar';
14
15 public function getScripts(): array
16 {
17 return [
18 [
19 'source' => 'public/search-bar-app/SearchBarApp.js',
20 'dependencies' => ['jquery']
21 ]
22 ];
23 }
24
25 public function getStyles(): array
26 {
27 return [
28 'public/search-bar-app/style/style.scss'
29 ];
30 }
31
32 public function localizeData(): array
33 {
34 return [
35 'fluentcart_search_bar_vars' => [
36 'rest' => Helper::getRestInfo(),
37 ]
38 ];
39 }
40
41 public function viewData(): ?array
42 {
43 return [
44 'url_mode' => Arr::get($this->shortCodeAttributes, 'url_mode'),
45 'category_mode' => Arr::get($this->shortCodeAttributes, 'category_mode'),
46 'termData' => $this->getTermsData('categories'),
47 'link_with_shop_app' => Arr::get($this->shortCodeAttributes, 'link_with_shop_app'),
48 'show_thumbnail' => filter_var(Arr::get($this->shortCodeAttributes, 'show_thumbnail', true), FILTER_VALIDATE_BOOLEAN),
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