fixed checkout service

This commit is contained in:
Edward Yang 2022-08-12 14:50:56 +08:00
parent 622901eaf5
commit 95ad14093a
4 changed files with 21 additions and 9 deletions

View File

@ -15,8 +15,16 @@ class ProductSku extends Base
'images' => 'array', 'images' => 'array',
]; ];
protected $appends = ['image'];
public function product() public function product()
{ {
return $this->belongsTo(Product::class); return $this->belongsTo(Product::class);
} }
public function getImageAttribute()
{
$images = $this->images ?? [];
return $images[0] ?? '';
}
} }

View File

@ -27,7 +27,8 @@ class CartDetail extends JsonResource
'product_id' => $this->product_id, 'product_id' => $this->product_id,
'sku_id' => $this->product_sku_id, 'sku_id' => $this->product_sku_id,
'name' => $description->name, 'name' => $description->name,
'image' => image_resize($sku->image), 'image' => $sku->image,
'image_url' => image_resize($sku->image),
'quantity' => $this->quantity, 'quantity' => $this->quantity,
'selected' => $this->selected, 'selected' => $this->selected,
'price' => $price, 'price' => $price,

View File

@ -47,8 +47,7 @@ class CartService
return $description && $product; return $description && $product;
}); });
$cartList = CartDetail::collection($cartItems)->jsonSerialize(); return CartDetail::collection($cartItems)->jsonSerialize();
return $cartList;
} }

View File

@ -11,12 +11,10 @@
namespace Beike\Shop\Services; namespace Beike\Shop\Services;
use Beike\Models\Cart;
use Beike\Models\CartProduct;
use Beike\Models\Customer; use Beike\Models\Customer;
use Beike\Models\Order;
use Beike\Repositories\CartRepo; use Beike\Repositories\CartRepo;
use Beike\Repositories\OrderRepo; use Beike\Repositories\OrderRepo;
use Illuminate\Support\Facades\DB;
use Beike\Repositories\PluginRepo; use Beike\Repositories\PluginRepo;
use Beike\Repositories\AddressRepo; use Beike\Repositories\AddressRepo;
use Beike\Repositories\CountryRepo; use Beike\Repositories\CountryRepo;
@ -81,9 +79,15 @@ class CheckoutService
$checkoutData = self::checkoutData(); $checkoutData = self::checkoutData();
$checkoutData['customer'] = $customer; $checkoutData['customer'] = $customer;
try {
DB::beginTransaction();
$order = OrderRepo::create($checkoutData); $order = OrderRepo::create($checkoutData);
CartRepo::clearSelectedCartProducts($customer); CartRepo::clearSelectedCartProducts($customer);
DB::commit();
} catch (\Exception $e) {
DB::rollBack();
dd($e);
}
// Notification::endmail(); // Notification::endmail();
// Notification::sendsms(); // Notification::sendsms();