| @@ -13,13 +13,23 @@ | ||
| 13 | 13 | protected $wrapperClass = null; |
| 14 | 14 | |
| 15 | 15 | protected $cursor = null; |
| 16 | 16 | |
| 17 | - public function __construct($products, $listTitle = null, $wrapperClass = null) | |
| 17 | + protected $columns = 4; | |
| 18 | + | |
| 19 | + protected $hideExcerpt = false; | |
| 20 | + | |
| 21 | + protected $ratingContext = ''; | |
| 22 | + | |
| 23 | + public function __construct($products, $listTitle = null, $wrapperClass = null, $config = []) | |
| 18 | 24 | { |
| 19 | 25 | $this->products = $products; |
| 20 | 26 | $this->listTitle = $listTitle; |
| 21 | 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', ''); | |
| 22 | 32 | |
| 23 | 33 | if($products instanceof \FluentCart\Framework\Pagination\CursorPaginator){ |
| 24 | 34 | $this->cursor = wp_parse_args(wp_parse_url($products->nextPageUrl(), PHP_URL_QUERY)); |
| 25 | 35 | $this->cursor = Arr::get($this->cursor, 'cursor', ''); |
| @@ -34,8 +44,13 @@ | ||
| 34 | 44 | ($this->products instanceof \FluentCart\Framework\Pagination\CursorPaginator && $this->products->count() === 0) |
| 35 | 45 | ) { |
| 36 | 46 | return ''; |
| 37 | 47 | } |
| 48 | + | |
| 49 | + $columns = $this->columns | |
| 50 | + ? 'style="--fct-product-list-columns: ' . $this->columns . ';"' | |
| 51 | + : ''; | |
| 52 | + | |
| 38 | 53 | ?> |
| 39 | 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')); ?>"> |
| 40 | 55 | <?php $this->renderTitle(); ?> |
| 41 | 56 | <div |
| @@ -42,8 +57,9 @@ | ||
| 42 | 57 | class="fct-product-list" |
| 43 | 58 | role="list" |
| 44 | 59 | aria-live="polite" |
| 45 | 60 | aria-busy="false" |
| 61 | + <?php echo $columns; ?> | |
| 46 | 62 | > |
| 47 | 63 | <?php $this->renderProductList(); ?> |
| 48 | 64 | </div> |
| 49 | 65 | </section> |
| @@ -53,9 +69,12 @@ | ||
| 53 | 69 | public function renderProductList() |
| 54 | 70 | { |
| 55 | 71 | |
| 56 | 72 | foreach ($this->products as $index => $product) { |
| 57 | - $config = []; | |
| 73 | + $config = ['hide_excerpt' => $this->hideExcerpt]; | |
| 74 | + if ($this->ratingContext) { | |
| 75 | + $config['rating_context'] = $this->ratingContext; | |
| 76 | + } | |
| 58 | 77 | if($index == 0 && $this->cursor){ |
| 59 | 78 | $config['cursor'] = $this->cursor; |
| 60 | 79 | } |
| 61 | 80 | ?> |