Skip to content

Commit 3ec5f88

Browse files
committed
Enhance allProducts method in ProductListController to support bulk price range filtering
This commit adds functionality to the allProducts method, allowing products to be filtered based on a specified bulk price range. It introduces a new query condition that processes the 'bulk_price_range' input, enabling users to view wholesale products within a defined price range, including checks for simple products and their variations.
1 parent 4944496 commit 3ec5f88

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

app/Http/Controllers/Product/ProductListController.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,36 @@ public function allProducts(Request $request){
110110

111111
if ($request->has('seller_mode') && $request->input('seller_mode')==true) {
112112
$query->where('is_wholesale',1);
113+
114+
if ($request->has('bulk_price_range')) {
115+
list($minBulkPrice, $maxBulkPrice) = explode('-', $request->input('bulk_price_range'));
116+
117+
$minBulkPrice = floatval($minBulkPrice);
118+
$maxBulkPrice = floatval($maxBulkPrice);
119+
120+
// On regroupe toutes les conditions de prix de gros
121+
$query->where(function(Builder $bulkPriceQuery) use ($minBulkPrice, $maxBulkPrice) {
122+
123+
// Cas 1: Prix de gros pour les produits simples (sans variations)
124+
$bulkPriceQuery->whereHas('wholesalePrices', function (Builder $wholesaleQuery) use ($minBulkPrice, $maxBulkPrice) {
125+
$wholesaleQuery->whereBetween('wholesale_price', [$minBulkPrice, $maxBulkPrice]);
126+
});
127+
128+
// Cas 2: Prix de gros pour les produits variés (couleur uniquement)
129+
$bulkPriceQuery->orWhereHas('variations', function (Builder $variationQuery) use ($minBulkPrice, $maxBulkPrice) {
130+
$variationQuery->whereHas('wholesalePrices', function (Builder $wholesaleQuery) use ($minBulkPrice, $maxBulkPrice) {
131+
$wholesaleQuery->whereBetween('wholesale_price', [$minBulkPrice, $maxBulkPrice]);
132+
});
133+
});
134+
135+
// Cas 3: Prix de gros pour les produits variés (couleur + attribut)
136+
$bulkPriceQuery->orWhereHas('variations.attributesVariation', function (Builder $attributeQuery) use ($minBulkPrice, $maxBulkPrice) {
137+
$attributeQuery->whereHas('wholesalePrices', function (Builder $wholesaleQuery) use ($minBulkPrice, $maxBulkPrice) {
138+
$wholesaleQuery->whereBetween('wholesale_price', [$minBulkPrice, $maxBulkPrice]);
139+
});
140+
});
141+
});
142+
}
113143

114144
}
115145

0 commit comments

Comments
 (0)