Skip to content

Commit

Permalink
Productwise Delivery Charge on ManualOrder + OrderEdit
Browse files Browse the repository at this point in the history
  • Loading branch information
bdsumon4u committed Sep 6, 2024
1 parent d24d8b0 commit d53a41e
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion app/Http/Livewire/EditOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,12 @@ public function addProduct(Product $product)
'price' => $selling = $product->getPrice($quantity),
'quantity' => $quantity,
'total' => $quantity * $selling,
'shipping_inside' => $product->shipping_inside,
'shipping_outside' => $product->shipping_outside,
];

$this->updatedOrderDataShippingArea('');

$this->search = '';
$this->dispatchBrowserEvent('notify', ['message' => 'Product added successfully.']);
}
Expand All @@ -116,6 +120,8 @@ public function increaseQuantity($id)
{
$this->selectedProducts[$id]['quantity']++;
$this->selectedProducts[$id]['total'] = $this->selectedProducts[$id]['quantity'] * $this->selectedProducts[$id]['price'];

$this->updatedOrderDataShippingArea('');
}

public function decreaseQuantity($id)
Expand All @@ -126,12 +132,27 @@ public function decreaseQuantity($id)
} else {
unset($this->selectedProducts[$id]);
}

$this->updatedOrderDataShippingArea('');
}

public function updatedOrderDataShippingArea($value)
{
$shipping_cost = 0;
if (! setting('show_option')->productwise_delivery_charge) {
$shipping_cost = setting('delivery_charge')->{$this->order->data['shipping_area'] == 'Inside Dhaka' ? 'inside_dhaka' : 'outside_dhaka'} ?? config('services.shipping.' . $this->order->data['shipping_area'], 0);
} else {
$shipping_cost = collect($this->selectedProducts)->sum(function ($item) {
if ($this->order->data['shipping_area'] == 'Inside Dhaka') {
return $item['shipping_inside'] * (setting('show_option')->quantitywise_delivery_charge ? $item['quantity'] : 1);
} else {
return $item['shipping_outside'] * (setting('show_option')->quantitywise_delivery_charge ? $item['quantity'] : 1);
}
});
}

$this->order->fill(['data' => [
'shipping_cost' => setting('delivery_charge')->{$this->order->data['shipping_area'] == 'Inside Dhaka' ? 'inside_dhaka' : 'outside_dhaka'} ?? config('services.shipping.' . $this->order->data['shipping_area'], 0),
'shipping_cost' => $shipping_cost,
]]);
}

Expand Down

0 comments on commit d53a41e

Please sign in to comment.