Skip to content

Commit 817750a

Browse files
committed
Enhance wholesale price handling in ProductController to prevent zero values from being saved
This commit updates the store method in ProductController to include a check that prevents wholesale prices with a value of "0" from being saved. This change ensures that only valid wholesale prices are recorded, improving data integrity. Additionally, the Product model is modified to include price information in the variations, enhancing the detail available for each product variation.
1 parent e545073 commit 817750a

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

app/Http/Controllers/Seller/ProductController.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,14 @@ public function store(Request $request)
106106
if ($wholesalePricesData) {
107107
foreach ($wholesalePricesData as $wpData) {
108108
// Lie les prix de gros au produit directement via la relation polymorphique
109-
$product->wholesalePrices()->create([
110-
'min_quantity' => $wpData['min_quantity'],
111-
'wholesale_price' => $wpData['wholesale_price'],
112-
]);
109+
110+
if($wpData['wholesale_price'] != "0"){
111+
$product->wholesalePrices()->create([
112+
'min_quantity' => $wpData['min_quantity'],
113+
'wholesale_price' => $wpData['wholesale_price'],
114+
]);
115+
}
116+
113117
Log::info('Product global wholesale price saved', ['product_id' => $product->id, 'min_quantity' => $wpData['min_quantity']]);
114118
}
115119
}

app/Models/Product.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
use App\Models\AttributeValue;
1212
use App\Models\WholeSalePrice;
1313
use App\Models\ProductVariation;
14+
use App\Models\VariationAttribute;
1415
use Illuminate\Support\Facades\URL;
1516
use Illuminate\Database\Eloquent\Model;
17+
use App\Http\Resources\WholeSalePriceResource;
1618
use Illuminate\Database\Eloquent\Relations\HasMany;
1719
use Illuminate\Database\Eloquent\Relations\BelongsTo;
1820
use Illuminate\Database\Eloquent\Factories\HasFactory;
@@ -114,6 +116,7 @@ public function getVariations()
114116
"group"=>$attr->attributeValue->attributeValueGroup->label ?? null,
115117
"label"=>$attr->attributeValue->label ?? null,
116118
"quantity" => $attr->quantity ?? null,
119+
117120
"price" => $attr->price ?? null,
118121
];
119122
});

0 commit comments

Comments
 (0)