Thrown cart exception.
This commit is contained in:
parent
6a16540d1b
commit
65f8023891
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
/**
|
||||
* CartException.php
|
||||
*
|
||||
* @copyright 2023 beikeshop.com - All Rights Reserved
|
||||
* @link https://beikeshop.com
|
||||
* @author Edward Yang <yangjin@guangda.work>
|
||||
* @created 2023-06-02 17:08:18
|
||||
* @modified 2023-06-02 17:08:18
|
||||
*/
|
||||
|
||||
namespace Beike\Exceptions;
|
||||
|
||||
class CartException extends \Exception
|
||||
{
|
||||
}
|
||||
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
namespace Beike\Shop\Http\Controllers;
|
||||
|
||||
use Beike\Exceptions\CartException;
|
||||
use Beike\Repositories\OrderRepo;
|
||||
use Beike\Shop\Services\CheckoutService;
|
||||
use Illuminate\Http\Request;
|
||||
|
|
@ -24,8 +25,10 @@ class CheckoutController extends Controller
|
|||
$data = hook_filter('checkout.index.data', $data);
|
||||
|
||||
return view('checkout', $data);
|
||||
} catch (\Exception $e) {
|
||||
} catch (CartException $e) {
|
||||
return redirect(shop_route('carts.index'))->withErrors(['error' => $e->getMessage()]);
|
||||
} catch (\Exception $e) {
|
||||
return redirect(shop_route('checkout.index'))->withErrors(['error' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,10 +11,10 @@
|
|||
|
||||
namespace Beike\Shop\Services;
|
||||
|
||||
use Beike\Exceptions\CartException;
|
||||
use Beike\Libraries\Weight;
|
||||
use Beike\Models\Address;
|
||||
use Beike\Models\Country;
|
||||
use Beike\Models\Customer;
|
||||
use Beike\Models\Order;
|
||||
use Beike\Models\Zone;
|
||||
use Beike\Repositories\AddressRepo;
|
||||
|
|
@ -46,13 +46,11 @@ class CheckoutService
|
|||
if (is_int($customer) || empty($customer)) {
|
||||
$this->customer = current_customer();
|
||||
}
|
||||
// if (empty($this->customer) || !($this->customer instanceof Customer)) {
|
||||
// // throw new \Exception(trans('shop/carts.invalid_customer'));
|
||||
// }
|
||||
|
||||
$this->cart = CartRepo::createCart($this->customer);
|
||||
$this->selectedProducts = CartRepo::selectedCartProducts($this->customer->id ?? 0);
|
||||
if ($this->selectedProducts->count() == 0) {
|
||||
throw new \Exception(trans('shop/carts.empty_selected_products'));
|
||||
throw new CartException(trans('shop/carts.empty_selected_products'));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue