| @@ -30,8 +30,9 @@ | ||
| 30 | 30 | 'page' => 1, |
| 31 | 31 | 'cursor' => null, |
| 32 | 32 | 'product_type' => '', // physical|digital|subscription|onetime|simple|variations |
| 33 | 33 | 'stock_status' => '', // in_stock|out_of_stock // check only if global stock management is enabled |
| 34 | + 'allow_out_of_stock' => false, // when false, show only in-stock products | |
| 34 | 35 | 'min_price' => 0, |
| 35 | 36 | 'max_price' => 0, |
| 36 | 37 | 'on_sale' => false, |
| 37 | 38 | 'is_main_query' => false, |
| @@ -124,12 +125,11 @@ | ||
| 124 | 125 | }) |
| 125 | 126 | ->when($this->queryArgs['exclude_ids'], function ($query, $excludeIds) { |
| 126 | 127 | $query->whereNotIn('ID', $excludeIds); |
| 127 | 128 | }) |
| 128 | - //TODO: check if stock management module is on | |
| 129 | - ->when($this->queryArgs['stock_status'], function ($query, $stockStatus) { | |
| 130 | - $query->whereHas('detail', function ($query) use ($stockStatus) { | |
| 131 | - $query->where('stock_availability', $stockStatus); | |
| 129 | + ->when(!$this->queryArgs['allow_out_of_stock'], function ($query) { | |
| 130 | + $query->whereHas('detail', function ($query) { | |
| 131 | + $query->where('stock_availability', 'in-stock'); | |
| 132 | 132 | }); |
| 133 | 133 | }) |
| 134 | 134 | ->when($this->queryArgs['on_sale'], function ($query) { |
| 135 | 135 | $query->whereHas('variants', function ($query) { |