PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.5
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.5
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
← All changes | app/Modules/Templating/Bricks/Elements/ProductGallery.php +75 -25 1.3.21 → 1.6.5 View file →
@@ -1,25 +1,23 @@
1 1 <?php
2 2
3 3 namespace FluentCart\App\Modules\Templating\Bricks\Elements;
4 4
5 -use Bricks\Database;
5 +
6 6 use Bricks\Element;
7 7 use Bricks\Setup;
8 -//use FluentCart\App\Hooks\Handlers\ShortCodes\Buttons\AddToCartShortcode;
9 -use FluentCart\App\Hooks\Handlers\ShortCodes\SingleProductShortCode;
10 8 use FluentCart\App\Modules\Data\ProductDataSetup;
11 9 use FluentCart\App\Modules\Templating\AssetLoader;
12 10 use FluentCart\App\Services\Renderer\ProductRenderer;
13 -use FluentCart\App\Vite;
11 +use FluentCart\App\Modules\Templating\Bricks\BricksLoader;
14 12
15 13 if (!defined('ABSPATH')) exit; // Exit if accessed directly
16 14
17 15 class ProductGallery extends Element
18 16 {
19 - public $category = 'fluent_cart_product';
17 + public $category = 'fluent-cart';
20 18 public $name = 'fct-product-gallery';
21 - public $icon = 'ti-gallery';
19 + public $icon = 'ti-gallery fluent-cart-element-icon';
22 20
23 21 public function enqueue_scripts()
24 22 {
25 23 AssetLoader::loadSingleProductAssets();
@@ -26,9 +24,9 @@
26 24 }
27 25
28 26 public function get_label()
29 27 {
30 - return esc_html__('Product gallery', 'fluent-cart');
28 + return esc_html__('Product Gallery', 'fluent-cart');
31 29 }
32 30
33 31 public function set_controls()
34 32 {
@@ -35,8 +33,39 @@
35 33 $this->controls['_width']['rerender'] = true;
36 34 $this->controls['_widthMin']['rerender'] = true;
37 35 $this->controls['_widthMax']['rerender'] = true;
38 36
37 + $this->controls['queryType'] = [
38 + 'tab' => 'content',
39 + 'type' => 'select',
40 + 'label' => esc_html__('Query Type', 'fluent-cart'),
41 + 'options' => [
42 + 'default' => esc_html__('Default', 'fluent-cart'),
43 + 'custom' => esc_html__('Custom', 'fluent-cart'),
44 + ],
45 + 'default' => 'default',
46 + 'inline' => true,
47 + ];
48 +
49 + $this->controls['productId'] = [
50 + 'tab' => 'content',
51 + 'type' => 'select',
52 + 'label' => esc_html__('Product', 'fluent-cart'),
53 + 'options' => BricksLoader::getProductOptions(),
54 + 'placeholder' => esc_html__('Select a product', 'fluent-cart'),
55 + 'searchable' => true,
56 + 'rerender' => true,
57 + 'required' => ['queryType', '=', 'custom'],
58 + ];
59 +
60 + $this->controls['manualProductId'] = [
61 + 'tab' => 'content',
62 + 'type' => 'text',
63 + 'label' => esc_html__('Manual Product ID', 'fluent-cart'),
64 + 'description' => esc_html__('Use this if the product is not available in dropdown.', 'fluent-cart'),
65 + 'required' => [['queryType', '=', 'custom'], ['productId', '=', '']],
66 + ];
67 +
39 68 $this->controls['productImageSize'] = [
40 69 'tab' => 'content',
41 70 'label' => esc_html__('Product', 'fluent-cart') . ': ' . esc_html__('Image size', 'fluent-cart'),
42 71 'type' => 'select',
@@ -198,21 +227,33 @@
198 227 }
199 228
200 229 public function render()
201 230 {
202 - $product = ProductDataSetup::getProductModel($this->post_id);
231 + $settings = $this->settings;
232 + $queryType = $settings['queryType'] ?? 'default';
203 233
204 - if (empty($product)) {
205 - return $this->render_element_placeholder(
206 - [
207 - 'title' => esc_html__('For better preview select content to show.', 'fluent-cart'),
208 - 'description' => esc_html__('Go to: Settings > Template Settings > Populate Content', 'fluent-cart'),
209 - ]
210 - );
234 + if ($queryType === 'default') {
235 + $productId = $this->post_id;
236 + } else {
237 + $productId = !empty($settings['productId']) ? \intval($settings['productId']) : 0;
238 + $manualProductId = !empty($settings['manualProductId']) ? \intval($settings['manualProductId']) : 0;
239 +
240 + if (!$productId && $manualProductId) {
241 + $productId = $manualProductId;
242 + }
211 243 }
212 244
213 - $settings = $this->settings;
245 + $product = ProductDataSetup::getProductModel($productId);
214 246
247 + if (!$product) {
248 + return $this->render_element_placeholder([
249 + 'title' => esc_html__(
250 + 'Select a product',
251 + 'fluent-cart'
252 + ),
253 + ]);
254 + }
255 +
215 256 // Thumbnail position
216 257 $thumbnail_position = !empty($settings['thumbnailPosition']) ? $settings['thumbnailPosition'] : 'bottom';
217 258 if (!in_array($thumbnail_position, ['bottom', 'top', 'left', 'right'], true)) {
218 259 $thumbnail_position = 'bottom';
@@ -225,18 +266,27 @@
225 266 if ($max_thumbnails !== null && $max_thumbnails <= 0) {
226 267 $max_thumbnails = null;
227 268 }
228 269
229 - // STEP: Render
230 - // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- render_attributes() handles escaping
231 - echo "<div {$this->render_attributes( '_root' )}>";
270 + ?>
232 271
233 - (new ProductRenderer($product))->renderGallery([
234 - 'thumb_position' => $thumbnail_position,
235 - 'scrollable_thumbs' => $scrollable_thumbs,
236 - 'max_thumbnails' => $max_thumbnails,
237 - ]);
272 + <div
273 + <?php
274 + // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- render_attributes() handles escaping
275 + echo $this->render_attributes( '_root' );
276 + ?>
277 + >
278 +
279 + <?php
280 + (new ProductRenderer($product))->renderGallery([
281 + 'thumb_position' => $thumbnail_position,
282 + 'scrollable_thumbs' => $scrollable_thumbs,
283 + 'max_thumbnails' => $max_thumbnails,
284 + ]);
285 + ?>
286 +
287 + </div>
238 288
239 - echo '</div>';
289 + <?php
240 290 }
241 291
242 292 }