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 / Services / Renderer / ProductListRenderer.php

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

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