PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.7.0
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.7.0
1.7.0 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 All 50 releases
fluent-cart / app / Services / Renderer / ProductListRenderer.php

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

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