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