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 / Modules / Templating / Bricks / Elements / ProductContent.php

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

114 lines 3.7 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 Bricks\Helpers;
7 use FluentCart\App\CPT\FluentProducts;
8 use FluentCart\App\Modules\Templating\Bricks\BricksLoader;
9 use FluentCart\App\Modules\Templating\Bricks\BricksHelper;
10 use FluentCart\App\Modules\Data\ProductDataSetup;
11 use FluentCart\App\Services\Renderer\ProductRenderer;
12
13 class ProductContent extends Element
14 {
15 public $category = 'fluent-cart';
16 public $name = 'fct-product-content';
17 public $icon = 'ion-md-list-box fluent-cart-element-icon';
18
19 public function get_label()
20 {
21 return esc_html__('Product Content', 'fluent-cart');
22 }
23
24 public function set_controls()
25 {
26 $this->controls['queryType'] = [
27 'tab' => 'content',
28 'type' => 'select',
29 'label' => esc_html__('Query Type', 'fluent-cart'),
30 'options' => [
31 'default' => esc_html__('Default', 'fluent-cart'),
32 'custom' => esc_html__('Custom', 'fluent-cart'),
33 ],
34 'default' => 'default',
35 'inline' => true,
36 ];
37
38 $this->controls['productId'] = [
39 'tab' => 'content',
40 'type' => 'select',
41 'label' => esc_html__('Product', 'fluent-cart'),
42 'options' => BricksLoader::getProductOptions(),
43 'placeholder' => esc_html__('Select a product', 'fluent-cart'),
44 'searchable' => true,
45 'rerender' => true,
46 'required' => ['queryType', '=', 'custom'],
47 ];
48
49 $this->controls['manualProductId'] = [
50 'tab' => 'content',
51 'type' => 'text',
52 'label' => esc_html__('Manual Product ID', 'fluent-cart'),
53 'description' => esc_html__('Use this if the product is not available in dropdown.', 'fluent-cart'),
54 'required' => [['queryType', '=', 'custom'], ['productId', '=', '']],
55 ];
56
57 $this->controls['info'] = [
58 'tab' => 'content',
59 'type' => 'info',
60 'content' => esc_html__('Edit product content in FluentCart.', 'fluent-cart'),
61 ];
62 }
63
64 public function render()
65 {
66 $settings = $this->settings;
67 $queryType = $settings['queryType'] ?? 'default';
68
69 if ($queryType === 'default') {
70 $productId = $this->post_id;
71 } else {
72 $productId = !empty($settings['productId']) ? \intval($settings['productId']) : 0;
73 $manualProductId = !empty($settings['manualProductId']) ? \intval($settings['manualProductId']) : 0;
74
75 if (!$productId && $manualProductId) {
76 $productId = $manualProductId;
77 }
78 }
79
80 $product = ProductDataSetup::getProductModel($productId);
81
82 if (!$product) {
83 return $this->render_element_placeholder([
84 'title' => esc_html__('Select a product', 'fluent-cart'),
85 ]);
86 }
87
88 $content = $product->post_content;
89
90
91 if (!$content) {
92 return $this->render_element_placeholder([
93 'title' => esc_html__('Product content is empty.', 'fluent-cart'),
94 ]);
95 }
96
97 $content = $this->render_dynamic_data($content);
98 $content = Helpers::parse_editor_content($content);
99 $content = str_replace(']]>', ']]&gt;', $content);
100
101 ?>
102 <div
103 <?php
104 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- render_attributes() handles escaping
105 echo $this->render_attributes( '_root' );
106 ?>
107 >
108 <?php echo wp_kses($content, BricksHelper::getAllowedHtmlForContent()); ?>
109 </div>
110
111 <?php
112 }
113 }
114