| 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 |
|