diff --git a/app/Http/Controllers/Shop/CustomerController.php b/app/Http/Controllers/Shop/CustomerController.php index 52e4ffe8..18d01adc 100644 --- a/app/Http/Controllers/Shop/CustomerController.php +++ b/app/Http/Controllers/Shop/CustomerController.php @@ -245,6 +245,7 @@ class CustomerController extends Controller $html = view('Shop.Customers.partials.address_item', [ 'address' => $address->toArray(), 'prefix' => $prefix, + 'inputName' => $request->input('input_name'), 'with_name' => true, 'selected' => $address->id, ])->render(); diff --git a/app/Http/Controllers/Shop/OrderController.php b/app/Http/Controllers/Shop/OrderController.php index b4a38d4a..95db3c31 100644 --- a/app/Http/Controllers/Shop/OrderController.php +++ b/app/Http/Controllers/Shop/OrderController.php @@ -9,6 +9,7 @@ use App\Repositories\Core\User\ShopCart; use App\Repositories\Shop\Baskets; use App\Repositories\Shop\Contents; use App\Repositories\Shop\Customers; +use App\Repositories\Shop\CustomerAddresses; use App\Repositories\Shop\Deliveries; use App\Repositories\Shop\DeliveryTypes; use App\Repositories\Shop\OrderMails; @@ -57,8 +58,21 @@ class OrderController extends Controller $deliveries = $deliveries ? $deliveries->values() : collect(); $customerData = $customer ? $customer->toArray() : false; - if ($customerData && $defaultSaleChannelId) { - $customerData['default_sale_channel_id'] = $defaultSaleChannelId; + if ($customerData) { + $customerData['delivery_address_id'] = optional(CustomerAddresses::getDeliveryAddress($customerId))->id; + $customerData['invoice_address_id'] = optional(CustomerAddresses::getInvoiceAddress($customerId))->id; + + if (! $customerData['delivery_address_id'] && ! empty($customerData['delivery_addresses'])) { + $customerData['delivery_address_id'] = $customerData['delivery_addresses'][0]['id'] ?? null; + } + + if (! $customerData['invoice_address_id'] && ! empty($customerData['invoice_addresses'])) { + $customerData['invoice_address_id'] = $customerData['invoice_addresses'][0]['id'] ?? null; + } + + if ($defaultSaleChannelId) { + $customerData['default_sale_channel_id'] = $defaultSaleChannelId; + } } $data = [ diff --git a/resources/views/Shop/Customers/partials/address_item.blade.php b/resources/views/Shop/Customers/partials/address_item.blade.php index dab8d52c..6afa56e3 100644 --- a/resources/views/Shop/Customers/partials/address_item.blade.php +++ b/resources/views/Shop/Customers/partials/address_item.blade.php @@ -1,7 +1,7 @@
@php - $inputName = isset($prefix) && $prefix ? $prefix.'[address_id]' : 'address_id'; + $inputName = $inputName ?? (isset($prefix) && $prefix ? $prefix.'[address_id]' : 'address_id'); $currentValue = $selected ?? null; @endphp $address, 'prefix' => $prefix ?? null, + 'inputName' => $inputName ?? null, 'with_name' => $with_name ?? false, 'selected' => $selected ?? null, ]) @@ -44,6 +45,7 @@