PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.4
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.4
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 1.2.0 All 47 releases
fluent-cart / app / Services / Renderer / SearchBarRenderer.php

SearchBarRenderer.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.6.4, at app/Services/Renderer/SearchBarRenderer.php

200 lines 8.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\Renderer;
4 use FluentCart\Framework\Support\Arr;
5
6 class SearchBarRenderer
7 {
8
9 protected $config;
10
11 public function __construct(array $config = [])
12 {
13 $this->config = $config;
14
15 }
16
17 public function render(){
18 $wrapperAttributes = [
19 'class' => 'fluent-cart-search-bar-app-wrapper',
20 'data-link-with-shop-app' => esc_attr(Arr::get($this->config, 'link_with_shop_app', false)),
21 'data-fluent-cart-search-bar-app-wrapper' => '',
22 'data-url-mode' => esc_attr(Arr::get($this->config, 'url_mode', '')),
23 'data-show-thumbnail' => esc_attr(Arr::get($this->config, 'show_thumbnail', true) ? 'true' : 'false'),
24 ];
25
26 ?>
27
28 <div <?php RenderHelper::renderAtts($wrapperAttributes); ?> role="search">
29 <div class="fluent-cart-search-bar-app-wrapper-header-wrap">
30 <?php
31 if (Arr::get($this->config, 'category_mode', '')){
32 $this->renderCategory();
33 }
34 ?>
35
36 <?php $this->renderInput(); ?>
37 </div>
38
39 <?php $this->renderSearchResult(); ?>
40 </div>
41
42
43 <?php
44 }
45
46 public function renderCategory(){
47 ?>
48
49 <div class="fluent-cart-search-bar-app-wrapper-select-container" style="display: inline;">
50 <label for="fluent-cart-search-category" class="sr-only">
51 <?php esc_html_e('Select Category', 'fluent-cart'); ?>
52 </label>
53
54 <select
55 id="fluent-cart-search-category"
56 data-fluent-cart-search-bar-app-taxonomy
57 name="termId"
58 aria-describedby="category-help"
59 >
60 <option selected value="">
61 <?php echo esc_html__('Select Category', 'fluent-cart'); ?>
62 </option>
63
64 <?php if (Arr::get($this->config, 'termData', [])): ?>
65 <?php foreach (Arr::get($this->config, 'termData', []) as $term): ?>
66 <option value="<?php echo esc_attr(Arr::get($term, 'termId', '')); ?>">
67 <?php echo esc_html(Arr::get($term, 'termName', '')); ?>
68 </option>
69 <?php endforeach; ?>
70 <?php endif; ?>
71
72 </select>
73
74 <small id="category-help" class="sr-only">
75 <?php esc_html_e('Filter search results by category', 'fluent-cart'); ?>
76 </small>
77 </div>
78
79 <?php
80 }
81
82 public function renderInput(){
83 ?>
84
85 <div class="fluent-cart-search-bar-app-input-wrap">
86 <label for="fluent-cart-search-input" class="sr-only">
87 <?php esc_html_e('Search Products', 'fluent-cart'); ?>
88 </label>
89
90 <div class="fluent-cart-search-bar-app-input-search">
91 <svg aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 18 18" fill="none">
92 <path d="M13.583 13.583L17.333 17.333" stroke="currentColor" stroke-width="1.2" stroke-linecap="round" stroke-linejoin="round"/>
93 <path d="M15.666 8.1665C15.666 4.02437 12.3082 0.666504 8.16601 0.666504C4.02388 0.666504 0.666016 4.02437 0.666016 8.1665C0.666016 12.3086 4.02388 15.6665 8.16601 15.6665C12.3082 15.6665 15.666 12.3086 15.666 8.1665Z" stroke="currentColor" stroke-width="1.2" stroke-linejoin="round"/>
94 </svg>
95 </div>
96
97 <input
98 id="fluent-cart-search-input"
99 class="fluent-cart-search-bar-app-input"
100 data-fluent-cart-search-bar
101 type="text"
102 placeholder="<?php echo esc_attr(__('Search Products...', 'fluent-cart')) ?>"
103 aria-describedby="search-help"
104 />
105
106 <button
107 class="fluent-cart-search-bar-app-input-clear"
108 data-fluent-cart-search-clear
109 title="<?php echo esc_attr(__('Clear search', 'fluent-cart')); ?>"
110 type="button"
111 aria-label="<?php esc_attr_e('Clear search', 'fluent-cart'); ?>"
112 aria-controls="fluent-cart-search-input"
113 >
114 <svg aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 18 18" fill="none">
115 <path d="M11.4995 11.5L6.5 6.5M6.50053 11.5L11.5 6.5" stroke="currentColor" stroke-width="1.2" stroke-linecap="round" stroke-linejoin="round"/>
116 <path d="M17.3337 8.99967C17.3337 4.3973 13.6027 0.66634 9.00033 0.66634C4.39795 0.66634 0.666992 4.3973 0.666992 8.99967C0.666992 13.602 4.39795 17.333 9.00033 17.333C13.6027 17.333 17.3337 13.602 17.3337 8.99967Z" stroke="currentColor" stroke-width="1.2"/>
117 </svg>
118 </button>
119
120 <small id="search-help" class="sr-only">
121 <?php esc_html_e('Type to search products', 'fluent-cart'); ?>
122 </small>
123 </div>
124
125 <?php
126 }
127
128 public function renderSearchResult() {
129 ?>
130
131 <div class="fluent-cart-search-bar-app-wrapper-result-wrap" style="display: none;">
132 <h5 id="search-suggestions-heading"><?php esc_html_e('Suggestions', 'fluent-cart'); ?></h5>
133
134 <ul
135 id="search-suggestions-list"
136 class="fluent-cart-search-bar-app-list-wrapper"
137 data-fluent-cart-search-bar-lists-wrapper
138 role="list"
139 aria-labelledby="search-suggestions-heading"
140 >
141 <?php $this->renderResultItems(); ?>
142 </ul>
143 </div>
144
145 <?php
146 }
147
148 public function renderResultItems($products = [])
149 {
150 $pageTarget = (Arr::get($this->config, 'url_mode', '') == 'new-tab') ? 'target="_blank"' : '';
151 $showThumbnail = Arr::get($this->config, 'show_thumbnail', true);
152
153 foreach ($products as $product) {
154 $productTitle = Arr::get($product, 'post_title', '');
155 $productUrl = Arr::get($product, 'guid', '');
156 $thumbnail = $showThumbnail ? Arr::get($product, 'thumbnail', '') : '';
157 $minPrice = Arr::get($product, 'detail.formatted_min_price', '');
158 $maxPrice = Arr::get($product, 'detail.formatted_max_price', '');
159
160 $aria_label = sprintf(
161 /* translators: 1: Product title */
162 esc_attr__('View product: %1$s', 'fluent-cart'),
163 esc_html($productTitle)
164 );
165 ?>
166 <li data-fluent-cart-search-bar-lists-list-item style="z-index: 9999;" role="listitem">
167 <a
168 href="<?php echo esc_url($productUrl) ?>"
169 <?php echo esc_html($pageTarget); ?>
170 aria-label="<?php echo esc_attr($aria_label); ?>"
171 >
172 <div class="fct-search-result-info">
173 <?php if ($thumbnail) : ?>
174 <img
175 src="<?php echo esc_url($thumbnail); ?>"
176 alt="<?php echo esc_attr($productTitle); ?>"
177 />
178 <?php endif; ?>
179
180 <span class="fct-search-result-title">
181 <?php echo esc_html($productTitle); ?>
182 </span>
183 </div>
184
185 <?php if ($minPrice) : ?>
186 <span class="fct-search-result-price">
187 <?php echo wp_kses_post($minPrice); ?>
188 <?php if ($maxPrice && $maxPrice !== $minPrice) : ?>
189 - <?php echo wp_kses_post($maxPrice); ?>
190 <?php endif; ?>
191 </span>
192 <?php endif; ?>
193 </a>
194 </li>
195 <?php
196 }
197 }
198
199 }
200