PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.5.3
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.5.3
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 / Modules / Templating / Bricks / Elements / PriceRange.php

PriceRange.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.5.3, at app/Modules/Templating/Bricks/Elements/PriceRange.php

132 lines 4.5 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\Modules\Templating\Bricks\Elements;
4
5 use Bricks\Element;
6 use FluentCart\App\Modules\Data\ProductDataSetup;
7 use FluentCart\App\Services\Renderer\ProductRenderer;
8 use FluentCart\Framework\Support\Arr;
9 use FluentCart\App\Modules\Templating\Bricks\BricksLoader;
10
11 if (!defined('ABSPATH')) exit; // Exit if accessed directly
12
13 class PriceRange extends Element
14 {
15
16 public $category = 'fluent-cart';
17 public $name = 'fct-price-range';
18 public $icon = 'ti-money fluent-cart-element-icon';
19
20 public function get_label()
21 {
22 return esc_html__('Price Range', 'fluent-cart');
23 }
24
25 public function set_controls()
26 {
27 $this->controls['queryType'] = [
28 'tab' => 'content',
29 'type' => 'select',
30 'label' => esc_html__('Query Type', 'fluent-cart-bricks-blocks'),
31 'options' => [
32 'default' => esc_html__('Default', 'fluent-cart-bricks-blocks'),
33 'custom' => esc_html__('Custom', 'fluent-cart-bricks-blocks'),
34 ],
35 'default' => 'default',
36 'inline' => true,
37 ];
38
39 $this->controls['productId'] = [
40 'tab' => 'content',
41 'type' => 'select',
42 'label' => esc_html__('Product', 'fluent-cart-bricks-blocks'),
43 'options' => BricksLoader::getProductOptions(),
44 'placeholder' => esc_html__('Select a product', 'fluent-cart-bricks-blocks'),
45 'searchable' => true,
46 'rerender' => true,
47 'required' => ['queryType', '=', 'custom'],
48 ];
49
50 $this->controls['manualProductId'] = [
51 'tab' => 'content',
52 'type' => 'text',
53 'label' => esc_html__('Manual Product ID', 'fluent-cart-bricks-blocks'),
54 'description' => esc_html__('Use this if the product is not available in dropdown.', 'fluent-cart-bricks-blocks'),
55 'required' => [['queryType', '=', 'custom'], ['productId', '=', '']],
56 ];
57
58 $this->controls['hideNoRange'] = [
59 'tab' => 'content',
60 'label' => esc_html__('Hide when max and min is same', 'fluent-cart'),
61 'type' => 'checkbox'
62 ];
63 $this->controls['priceRangeTypography'] = [
64 'tab' => 'content',
65 'label' => esc_html__('Price Range typography', 'fluent-cart'),
66 'type' => 'typography',
67 'css' => [
68 [
69 'selector' => '.fct-price-range.fct-product-prices',
70 'property' => 'font',
71 ],
72 ],
73 ];
74 }
75
76 public function render()
77 {
78 $settings = $this->settings;
79 $queryType = $settings['queryType'] ?? 'default';
80
81 if ($queryType === 'default') {
82 $productId = $this->post_id;
83 } else {
84 $productId = !empty($settings['productId']) ? \intval($settings['productId']) : 0;
85 $manualProductId = !empty($settings['manualProductId']) ? \intval($settings['manualProductId']) : 0;
86
87 if (!$productId && $manualProductId) {
88 $productId = $manualProductId;
89 }
90 }
91
92 $product = ProductDataSetup::getProductModel($productId);
93
94 if (!$product) {
95 return $this->render_element_placeholder([
96 'title' => esc_html__(
97 'Select a product',
98 'fluent-cart-bricks-blocks'
99 ),
100 ]);
101 }
102
103 if(Arr::get($settings, 'hideNoRange')) {
104 $hasPriceRange = $product->detail->variation_type !== 'simple';
105 if(!$hasPriceRange) {
106 $min_price = $product->detail->min_price;
107 $max_price = $product->detail->max_price;
108 $hasPriceRange = $max_price && $max_price > $min_price;
109 }
110 if(!$hasPriceRange) {
111 return $this->render_element_placeholder(
112 [
113 'description' => esc_html__('Product does not have min-max range', 'fluent-cart'),
114 ]
115 );
116 }
117 }
118
119 ?>
120 <div
121 <?php
122 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- render_attributes() handles escaping internally
123 echo $this->render_attributes( '_root' );
124 ?>
125 >
126 <?php (new ProductRenderer($product))->renderPrices(); ?>
127 </div>
128
129 <?php
130 }
131 }
132