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

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

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