fixed payment address id

This commit is contained in:
Edward Yang 2022-07-29 18:40:41 +08:00
parent 8a36d5ea3d
commit 0be99e30fb
1 changed files with 13 additions and 3 deletions

View File

@ -24,17 +24,27 @@ class CartRepo
}
$customerId = $customer->id;
$cart = Cart::query()->where('customer_id', $customerId)->first();
$defaultAddress = AddressRepo::listByCustomer($customer)->first();
$defaultAddressId = $defaultAddress->id ?? 0;
if (empty($cart)) {
$shippingMethod = PluginRepo::getShippingMethods()->first();
$paymentMethod = PluginRepo::getPaymentMethods()->first();
$defaultAddress = AddressRepo::listByCustomer($customer)->first();
$cart = Cart::query()->create([
'customer_id' => $customerId,
'shipping_address_id' => $defaultAddress->id ?? 0,
'shipping_address_id' => $defaultAddressId,
'shipping_method_code' => $shippingMethod->code,
'payment_address_id' => $defaultAddress->id ?? 0,
'payment_address_id' => $defaultAddressId,
'payment_method_code' => $paymentMethod->code
]);
} else {
if ($cart->shipping_address_id == 0) {
$cart->shipping_address_id = $defaultAddressId;
}
if ($cart->payment_address_id == 0) {
$cart->payment_address_id = $defaultAddressId;
}
$cart->save();
}
return $cart;
}