fixed checkout

This commit is contained in:
Edward Yang 2022-07-04 16:43:56 +08:00
parent c3ba1cc895
commit dfc22f4702
4 changed files with 16 additions and 9 deletions

View File

@ -10,10 +10,7 @@ class Cart extends Model
{
use HasFactory;
protected $fillable = ['customer_id', 'selected', 'product_id', 'product_sku_id', 'quantity'];
public function sku(): BelongsTo
{
return $this->belongsTo(ProductSku::class, 'product_sku_id', 'id');
}
protected $fillable = [
'customer_id', 'shipping_address_id', 'shipping_method_code', 'payment_address_id', 'payment_method_code'
];
}

View File

@ -11,9 +11,18 @@
namespace Beike\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class CartProduct extends Model
{
use HasFactory;
protected $fillable = ['customer_id', 'selected', 'product_id', 'product_sku_id', 'quantity'];
public function sku(): BelongsTo
{
return $this->belongsTo(ProductSku::class, 'product_sku_id', 'id');
}
}

View File

@ -11,6 +11,7 @@
namespace Beike\Shop\Services;
use Beike\Models\CartProduct;
use Exception;
use Beike\Models\Cart;
use Beike\Shop\Http\Resources\CartList;
@ -29,7 +30,7 @@ class CartService
if (empty($customer)) {
return [];
}
$cartBuilder = Cart::query()
$cartBuilder = CartProduct::query()
->with(['sku.product.description'])
->where('customer_id', $customer->id)
->orderByDesc('id');

View File

@ -18,9 +18,9 @@ class AddCartItemOrders extends Migration
Schema::create('carts', function (Blueprint $table) {
$table->id();
$table->integer('customer_id');
$table->integer('ship_address_id');
$table->integer('pay_address_id');
$table->integer('shipping_address_id');
$table->integer('shipping_method_code');
$table->integer('payment_address_id');
$table->integer('payment_method_code');
$table->timestamps();
});