| @@ -7,8 +7,9 @@ | ||
| 7 | 7 | use FluentCart\App\Helpers\Helper; |
| 8 | 8 | use FluentCart\App\Http\Routes\WebRoutes; |
| 9 | 9 | use FluentCart\App\Modules\Templating\AssetLoader; |
| 10 | 10 | use FluentCart\Framework\Pagination\CursorPaginator; |
| 11 | +use FluentCart\Framework\Pagination\LengthAwarePaginator; | |
| 11 | 12 | use FluentCart\Framework\Support\Arr; |
| 12 | 13 | |
| 13 | 14 | class ShopAppRenderer |
| 14 | 15 | { |
| @@ -90,8 +91,15 @@ | ||
| 90 | 91 | if($this->products instanceof CursorPaginator){ |
| 91 | 92 | $this->total = 0; |
| 92 | 93 | }else{ |
| 93 | 94 | $this->total = Arr::get($products, 'total', 0); |
| 95 | + if (!$this->total && $this->products instanceof LengthAwarePaginator) { | |
| 96 | + // A raw LengthAwarePaginator's ArrayAccess proxies to its item | |
| 97 | + // collection, not its own properties, so Arr::get($products, 'total') | |
| 98 | + // above always misses when the caller passes the paginator directly | |
| 99 | + // instead of the normalized ['products' => ..., 'total' => ...] shape. | |
| 100 | + $this->total = $this->products->total(); | |
| 101 | + } | |
| 94 | 102 | } |
| 95 | 103 | //$this->total = $products['total']; |
| 96 | 104 | |
| 97 | 105 | |
| @@ -120,8 +128,17 @@ | ||
| 120 | 128 | |
| 121 | 129 | // Merge allow_out_of_stock from config into defaultFilters |
| 122 | 130 | if (Arr::get($config, 'allow_out_of_stock')) { |
| 123 | 131 | $this->defaultFilters['allow_out_of_stock'] = true; |
| 132 | + } | |
| 133 | + | |
| 134 | + // Merge wildcard search preset into defaultFilters so it persists in AJAX re-fetches | |
| 135 | + $wildcard = Arr::get($defaultFilters, 'wildcard', ''); | |
| 136 | + if ($wildcard !== '') { | |
| 137 | + $this->defaultFilters['wildcard'] = $wildcard; | |
| 138 | + if (empty($this->defaultFilters['enabled'])) { | |
| 139 | + $this->defaultFilters['enabled'] = true; | |
| 140 | + } | |
| 124 | 141 | } |
| 125 | 142 | |
| 126 | 143 | // Merge sort_by from config filters into defaultFilters for AJAX persistence |
| 127 | 144 | $configFilters = Arr::get($config, 'filters', []); |