fixed checkout
This commit is contained in:
parent
00ede7adcd
commit
e086401619
|
|
@ -0,0 +1,32 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* CartRepo.php
|
||||||
|
*
|
||||||
|
* @copyright 2022 opencart.cn - All Rights Reserved
|
||||||
|
* @link http://www.guangdawangluo.com
|
||||||
|
* @author Edward Yang <yangjin@opencart.cn>
|
||||||
|
* @created 2022-07-04 17:14:14
|
||||||
|
* @modified 2022-07-04 17:14:14
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Beike\Repositories;
|
||||||
|
|
||||||
|
use Beike\Models\Cart;
|
||||||
|
|
||||||
|
class CartRepo
|
||||||
|
{
|
||||||
|
public static function createCart(int $customerId)
|
||||||
|
{
|
||||||
|
$cart = Cart::query()->where('customer_id', $customerId)->first();
|
||||||
|
if (empty($cart)) {
|
||||||
|
$cart = Cart::query()->create([
|
||||||
|
'customer_id' => $customerId,
|
||||||
|
'shipping_address_id' => 0,
|
||||||
|
'shipping_method_code' => '',
|
||||||
|
'payment_address_id' => 0,
|
||||||
|
'payment_method_code' => ''
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
return $cart;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -13,6 +13,7 @@ namespace Beike\Shop\Services;
|
||||||
|
|
||||||
use Beike\Models\Cart;
|
use Beike\Models\Cart;
|
||||||
use Beike\Models\Customer;
|
use Beike\Models\Customer;
|
||||||
|
use Beike\Repositories\CartRepo;
|
||||||
use Beike\Repositories\PluginRepo;
|
use Beike\Repositories\PluginRepo;
|
||||||
use Beike\Repositories\AddressRepo;
|
use Beike\Repositories\AddressRepo;
|
||||||
use Beike\Repositories\CountryRepo;
|
use Beike\Repositories\CountryRepo;
|
||||||
|
|
@ -29,12 +30,10 @@ class CheckoutService
|
||||||
if (is_int($customer) || empty($customer)) {
|
if (is_int($customer) || empty($customer)) {
|
||||||
$this->customer = current_customer();
|
$this->customer = current_customer();
|
||||||
}
|
}
|
||||||
if (empty($this->customer) && !($this->customer instanceof Customer)) {
|
if (empty($this->customer) || !($this->customer instanceof Customer)) {
|
||||||
throw new \Exception("购物车客户无效");
|
throw new \Exception("购物车客户无效");
|
||||||
}
|
}
|
||||||
$this->cart = Cart::query()
|
$this->cart = CartRepo::createCart($this->customer->id);
|
||||||
->where('customer_id', $customer->id)
|
|
||||||
->firstOrCreate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -19,9 +19,9 @@ class AddCartItemOrders extends Migration
|
||||||
$table->id();
|
$table->id();
|
||||||
$table->integer('customer_id');
|
$table->integer('customer_id');
|
||||||
$table->integer('shipping_address_id');
|
$table->integer('shipping_address_id');
|
||||||
$table->integer('shipping_method_code');
|
$table->string('shipping_method_code');
|
||||||
$table->integer('payment_address_id');
|
$table->integer('payment_address_id');
|
||||||
$table->integer('payment_method_code');
|
$table->string('payment_method_code');
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue