PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.5.2
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.5.2
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 / ProductContent.php

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

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