From 6cbd4d80de2497f9c0f5aabfa9d30209427048e5 Mon Sep 17 00:00:00 2001 From: Edward Yang Date: Mon, 4 Jul 2022 17:58:05 +0800 Subject: [PATCH] fixed checkout --- beike/Repositories/CartRepo.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/beike/Repositories/CartRepo.php b/beike/Repositories/CartRepo.php index 966d2139..0514963a 100644 --- a/beike/Repositories/CartRepo.php +++ b/beike/Repositories/CartRepo.php @@ -17,14 +17,18 @@ class CartRepo { public static function createCart(int $customerId) { + $customer = CustomerRepo::find($customerId); $cart = Cart::query()->where('customer_id', $customerId)->first(); 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' => 0, - 'shipping_method_code' => '', - 'payment_address_id' => 0, - 'payment_method_code' => '' + 'shipping_address_id' => $defaultAddress->id, + 'shipping_method_code' => $shippingMethod->code, + 'payment_address_id' => $defaultAddress->id, + 'payment_method_code' => $paymentMethod->code ]); } return $cart;