PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.5.4
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.5.4
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 / Services / Renderer / ProductListRenderer.php

ProductListRenderer.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.5.4, at app/Services/Renderer/ProductListRenderer.php

94 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\Services\Renderer;
4
5 use FluentCart\Framework\Support\Arr;
6
7 class ProductListRenderer
8 {
9 protected $products = [];
10
11 protected $listTitle = null;
12
13 protected $wrapperClass = null;
14
15 protected $cursor = null;
16
17 protected $columns = 4;
18
19 public function __construct($products, $listTitle = null, $wrapperClass = null, $config = [])
20 {
21 $this->products = $products;
22 $this->listTitle = $listTitle;
23 $this->wrapperClass = $wrapperClass;
24 $columns = Arr::get($config, 'columns', 4);
25 $this->columns = max(1, min(6, intval($columns)));
26
27 if($products instanceof \FluentCart\Framework\Pagination\CursorPaginator){
28 $this->cursor = wp_parse_args(wp_parse_url($products->nextPageUrl(), PHP_URL_QUERY));
29 $this->cursor = Arr::get($this->cursor, 'cursor', '');
30 }
31
32 }
33
34 public function render()
35 {
36 if (
37 (is_array($this->products) && empty($this->products)) ||
38 ($this->products instanceof \FluentCart\Framework\Pagination\CursorPaginator && $this->products->count() === 0)
39 ) {
40 return '';
41 }
42
43 $columns = $this->columns
44 ? 'style="--fct-product-list-columns: ' . $this->columns . ';"'
45 : '';
46
47 ?>
48 <section class="fct-product-list-container <?php echo esc_attr($this->wrapperClass); ?>" aria-label="<?php echo esc_attr($this->listTitle ?: __('Product List', 'fluent-cart')); ?>">
49 <?php $this->renderTitle(); ?>
50 <div
51 class="fct-product-list"
52 role="list"
53 aria-live="polite"
54 aria-busy="false"
55 <?php echo $columns; ?>
56 >
57 <?php $this->renderProductList(); ?>
58 </div>
59 </section>
60 <?php
61 }
62
63 public function renderProductList()
64 {
65
66 foreach ($this->products as $index => $product) {
67 $config = [];
68 if($index == 0 && $this->cursor){
69 $config['cursor'] = $this->cursor;
70 }
71 ?>
72 <div
73 class="fct-product-list-item"
74 role="listitem"
75 >
76 <?php (new ProductCardRender($product, $config))->render(); ?>
77 </div>
78
79 <?php
80 }
81 }
82
83 public function renderTitle() {
84
85 if(!empty($this->listTitle)) : ?>
86 <h4 class="fct-product-list-heading">
87 <?php echo esc_html($this->listTitle); ?>
88 </h4>
89 <?php endif;
90
91 }
92
93 }
94