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',
];
protected $appends = ['image'];
public function product()
{
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,
'sku_id' => $this->product_sku_id,
'name' => $description->name,
'image' => image_resize($sku->image),
'image' => $sku->image,
'image_url' => image_resize($sku->image),
'quantity' => $this->quantity,
'selected' => $this->selected,
'price' => $price,

View File

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

View File

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