new: display the default address checkbox on profile load

This commit is contained in:
Valentin Lab
2025-10-04 11:44:04 +02:00
parent 7217d945a3
commit ccc477f291
5 changed files with 18 additions and 1 deletions

View File

@@ -6,6 +6,7 @@ use App\Datatables\Shop\CustomerInvoicesDataTable;
use App\Datatables\Shop\CustomerOrdersDataTable;
use App\Models\Shop\Customer;
use App\Traits\Model\Basic;
use App\Repositories\Shop\CustomerAddresses;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Str;
@@ -95,6 +96,16 @@ class Customers
$data = $customer->toArray();
$data['sale_channels'] = $customer->sale_channels->pluck('id')->toArray();
$data['deliveries'] = Deliveries::getBySaleChannels($data['sale_channels'])->toArray();
$data['delivery_address_id'] = optional(CustomerAddresses::getDeliveryAddress($id))->id;
$data['invoice_address_id'] = optional(CustomerAddresses::getInvoiceAddress($id))->id;
if (! $data['delivery_address_id'] && ! empty($data['delivery_addresses'])) {
$data['delivery_address_id'] = $data['delivery_addresses'][0]['id'] ?? null;
}
if (! $data['invoice_address_id'] && ! empty($data['invoice_addresses'])) {
$data['invoice_address_id'] = $data['invoice_addresses'][0]['id'] ?? null;
}
return $data;
}