|
7 | 7 | use App\Models\Product; |
8 | 8 | use Illuminate\Http\Request; |
9 | 9 | use Illuminate\Database\Eloquent\Builder; |
| 10 | +use Illuminate\Support\Facades\Log; |
10 | 11 |
|
11 | 12 | class ProductListController extends Controller |
12 | 13 | { |
@@ -116,26 +117,29 @@ public function allProducts(Request $request){ |
116 | 117 |
|
117 | 118 | $minBulkPrice = floatval($minBulkPrice); |
118 | 119 | $maxBulkPrice = floatval($maxBulkPrice); |
119 | | - |
| 120 | + Log::info('Bulk price range', ['minBulkPrice' => gettype($minBulkPrice), 'maxBulkPrice' => $maxBulkPrice]); |
120 | 121 | // On regroupe toutes les conditions de prix de gros |
121 | 122 | $query->where(function(Builder $bulkPriceQuery) use ($minBulkPrice, $maxBulkPrice) { |
122 | 123 |
|
123 | 124 | // Cas 1: Prix de gros pour les produits simples (sans variations) |
124 | 125 | $bulkPriceQuery->whereHas('wholesalePrices', function (Builder $wholesaleQuery) use ($minBulkPrice, $maxBulkPrice) { |
125 | | - $wholesaleQuery->whereBetween('wholesale_price', [$minBulkPrice, $maxBulkPrice]); |
| 126 | + $wholesaleQuery->whereRaw('CAST(wholesale_price AS DECIMAL(10, 2)) >= ?', [$minBulkPrice]); |
| 127 | + $wholesaleQuery->whereRaw('CAST(wholesale_price AS DECIMAL(10, 2)) <= ?', [$maxBulkPrice]); |
126 | 128 | }); |
127 | 129 |
|
128 | 130 | // Cas 2: Prix de gros pour les produits variés (couleur uniquement) |
129 | 131 | $bulkPriceQuery->orWhereHas('variations', function (Builder $variationQuery) use ($minBulkPrice, $maxBulkPrice) { |
130 | 132 | $variationQuery->whereHas('wholesalePrices', function (Builder $wholesaleQuery) use ($minBulkPrice, $maxBulkPrice) { |
131 | | - $wholesaleQuery->whereBetween('wholesale_price', [$minBulkPrice, $maxBulkPrice]); |
| 133 | + $wholesaleQuery->whereRaw('CAST(wholesale_price AS DECIMAL(10, 2)) >= ?', [$minBulkPrice]); |
| 134 | + $wholesaleQuery->whereRaw('CAST(wholesale_price AS DECIMAL(10, 2)) <= ?', [$maxBulkPrice]); |
132 | 135 | }); |
133 | 136 | }); |
134 | 137 |
|
135 | 138 | // Cas 3: Prix de gros pour les produits variés (couleur + attribut) |
136 | 139 | $bulkPriceQuery->orWhereHas('variations.attributesVariation', function (Builder $attributeQuery) use ($minBulkPrice, $maxBulkPrice) { |
137 | 140 | $attributeQuery->whereHas('wholesalePrices', function (Builder $wholesaleQuery) use ($minBulkPrice, $maxBulkPrice) { |
138 | | - $wholesaleQuery->whereBetween('wholesale_price', [$minBulkPrice, $maxBulkPrice]); |
| 141 | + $wholesaleQuery->whereRaw('CAST(wholesale_price AS DECIMAL(10, 2)) >= ?', [$minBulkPrice]); |
| 142 | + $wholesaleQuery->whereRaw('CAST(wholesale_price AS DECIMAL(10, 2)) <= ?', [$maxBulkPrice]); |
139 | 143 | }); |
140 | 144 | }); |
141 | 145 | }); |
|
0 commit comments