feat: Implement distinct order item entries for perfumes and add 'ml' suffix to custom quantity display.
This commit is contained in:
parent
c74b03fde0
commit
07e0c4ce90
@ -15,7 +15,24 @@ trait WithManageItem
|
||||
*/
|
||||
protected function addOrUpdateOrderItem($model, int $quantity, ?string $quality = null): void
|
||||
{
|
||||
$existing = $this->items->firstWhere(fn ($i) => $i->orderable_type === get_class($model) && $i->orderable_id === $model->id && $i->quality === $quality);
|
||||
// If the item is a Perfume, we generally want separate entries (especially for custom sizes or distinct refills)
|
||||
// Adjust logic: Only search for existing if it's NOT a Perfume.
|
||||
// Or if user specifically wants Bottles/Products to merge but Perfumes to split:
|
||||
|
||||
$existing = null;
|
||||
|
||||
// Check instance type to decide whether to merge
|
||||
// "if item is perfume, then do not increment quantity"
|
||||
// "if item is bottle or product, then increment quantity"
|
||||
$isPerfume = $model instanceof \App\Models\Perfume;
|
||||
|
||||
if (! $isPerfume) {
|
||||
$existing = $this->items->firstWhere(
|
||||
fn ($i) => $i->orderable_type === get_class($model) &&
|
||||
$i->orderable_id === $model->id &&
|
||||
$i->quality === $quality
|
||||
);
|
||||
}
|
||||
|
||||
if ($existing) {
|
||||
$existing->increment('quantity', $quantity);
|
||||
|
||||
@ -246,7 +246,7 @@
|
||||
@if ($item->quality && $item->quality !== 'Custom')
|
||||
{{ $item->quality }}
|
||||
@else
|
||||
{{ $item->quality === 'Custom' ? $item->quantity : formatCurrencyNumber($item->quantity, '') }}
|
||||
{{ $item->quality === 'Custom' ? formatCurrencyNumber($item->quantity, '') . ' ml' : formatCurrencyNumber($item->quantity, '') }}
|
||||
x
|
||||
{{ formatCurrencyNumber($item->unit_price, 'Rp') }}
|
||||
@endif
|
||||
|
||||
@ -191,11 +191,13 @@
|
||||
'quantity' => 30,
|
||||
]);
|
||||
|
||||
// Bottle should have aggregated to 2 (since bottle has no quality separation)
|
||||
// Bottle SHOULD aggregated to 2 (since bottle isn't a perfume and logic allows increment)
|
||||
$this->assertDatabaseHas('order_items', [
|
||||
'orderable_id' => $bottle->id,
|
||||
'quantity' => 2,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseCount('order_items', 3); // 2 perfumes (diff quality) + 1 bottle (aggregated)
|
||||
});
|
||||
|
||||
it('can update item quantity in the cart', function () {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user