示例#1
0
 public function store(OrderCreationRequest $request, Address $address, $seller, StockValidator $stockValidator)
 {
     $cartItems = $this->cartManager->getItemsForOrderCreation($this->user(), $seller);
     if ($cartItems->isEmpty()) {
         $this->error(trans('cart::messages.no_items_by_seller'));
     }
     // check stock
     foreach ($cartItems as $cartItem) {
         $stockValidator->validate($cartItem->getProduct(), $cartItem->getVariant(), $cartItem->quantity);
     }
     // optional route paramter 'address' will be injected regardless
     // need to check if it's route model binding or dependency injection
     $address = $address->exists ? $address : null;
     $paymentMethod = $request->input('payment');
     // validate shipping options
     $shippingOptions = $this->validateShippingOptions($request, $address, $seller, $cartItems);
     $order = DB::transaction(function () use($seller, $cartItems, $address, $paymentMethod, $shippingOptions) {
         return app(OrderManager::class)->createOrder($this->user(), $seller, $cartItems, $address, $paymentMethod, $shippingOptions);
     });
     if ($order) {
         event(new OrderCreated($order));
     }
     $this->flashSuccessOverlay('订单已提交给卖家');
     return redirect()->route('account::purchases.show', $order->id);
 }
 public function destroy(CartItem $cartItem)
 {
     $this->cartManager->getCartItemRepository()->delete($cartItem);
     return $this->success('delete');
 }