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

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

84 lines 2.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;
4
5 use Bricks\Elements;
6 use Bricks\Query;
7 use FluentCart\Framework\Support\Arr;
8
9 class BricksLoader
10 {
11 public function register()
12 {
13 if (!defined('BRICKS_VERSION')) {
14 return;
15 }
16
17 add_action('init', [$this, 'loadElements'], 20);
18
19 (new DynamicData())->register();
20
21 add_filter('fluent_cart/template/disable_taxonomy_fallback', function ($result) {
22 $bricks_data = \Bricks\Database::get_template_data('archive');
23
24 if ($bricks_data) {
25 return true;
26 }
27
28 return $result;
29 });
30
31 add_filter('fluent_cart/products_views/preload_collection_bricks', [$this, 'preloadProductCollectionsAjax'], 10, 2);
32
33 }
34
35 public function loadElements()
36 {
37 $elements = [
38 'ProductTitle' => 'fct-product-title',
39 'ProductShortDescription' => 'fct-product-short-description',
40 'ProductContent' => 'fct-product-content',
41 'ProductStock' => 'fct-product-stock',
42 'PriceRange' => 'fct-price-range',
43 'ProductAddToCart' => 'fct-product-buy-section',
44 'ProductGallery' => 'fct-product-gallery',
45 'ProductsCollection' => 'fct-products',
46 ];
47
48 foreach ($elements as $elementKey => $elementName) {
49 $elementFile = FLUENTCART_PLUGIN_PATH . "app/Modules/Templating/Bricks/Elements/$elementKey.php";
50 $className = "\\FluentCart\\App\\Modules\\Templating\\Bricks\\Elements\\$elementKey";
51 Elements::register_element($elementFile, $elementName, $className);
52 }
53
54 }
55
56 public function preloadProductCollectionsAjax($view, $args)
57 {
58 $products = $args['products'];
59 $clientId = Arr::get($args, 'client_id', '');
60
61 $settings = get_transient('fc_bx_collection_' . $clientId);
62 if (!$settings) {
63 return $view;
64 }
65
66 do_action('fluent_cart/bricks/rendering_ajax_collection');
67
68 ob_start();
69 $post_index = 1;
70
71 foreach ($products as $product) {
72 $post = get_post($product->ID);
73 setup_postdata($post);
74 BricksHelper::setFormCurrentPost($post);
75 BricksHelper::renderCollectionCard($settings, $product, $post_index, $clientId);
76
77 $post_index++;
78 }
79 wp_reset_postdata();
80
81 return ob_get_clean();
82 }
83 }
84