| 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 |
|
| 10 |
if (!defined('ABSPATH')) exit; // Exit if accessed directly |
| 11 |
|
| 12 |
class PriceRange extends Element |
| 13 |
{ |
| 14 |
|
| 15 |
public $category = 'fluent_cart_product'; |
| 16 |
public $name = 'fct-price-range'; |
| 17 |
public $icon = 'ti-money'; |
| 18 |
|
| 19 |
public function get_label() |
| 20 |
{ |
| 21 |
return esc_html__('Price range', 'fluent-cart'); |
| 22 |
} |
| 23 |
|
| 24 |
public function set_controls() |
| 25 |
{ |
| 26 |
$this->controls['hideNoRange'] = [ |
| 27 |
'tab' => 'content', |
| 28 |
'label' => esc_html__('Hide when max and mix is same', 'fluent-cart'), |
| 29 |
'type' => 'checkbox' |
| 30 |
]; |
| 31 |
$this->controls['priceRangeTypography'] = [ |
| 32 |
'tab' => 'content', |
| 33 |
'label' => esc_html__('Price Range typography', 'fluent-cart'), |
| 34 |
'type' => 'typography', |
| 35 |
'css' => [ |
| 36 |
[ |
| 37 |
'selector' => '.fct-price-range.fct-product-prices', |
| 38 |
'property' => 'font', |
| 39 |
], |
| 40 |
], |
| 41 |
]; |
| 42 |
} |
| 43 |
|
| 44 |
public function render() |
| 45 |
{ |
| 46 |
$settings = $this->settings; |
| 47 |
|
| 48 |
$product = ProductDataSetup::getProductModel($this->post_id); |
| 49 |
|
| 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 |
); |
| 57 |
} |
| 58 |
|
| 59 |
if(Arr::get($settings, 'hideNoRange')) { |
| 60 |
$hasPriceRange = $product->detail->variation_type !== 'simple'; |
| 61 |
if(!$hasPriceRange) { |
| 62 |
$min_price = $product->detail->min_price; |
| 63 |
$max_price = $product->detail->max_price; |
| 64 |
$hasPriceRange = $max_price && $max_price > $min_price; |
| 65 |
} |
| 66 |
if(!$hasPriceRange) { |
| 67 |
return $this->render_element_placeholder( |
| 68 |
[ |
| 69 |
'description' => esc_html__('Product does not have min-max range', 'fluent-cart'), |
| 70 |
] |
| 71 |
); |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 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>'; |
| 79 |
} |
| 80 |
} |
| 81 |
|