/**
  * @param Address $address
  * @return \Illuminate\Http\RedirectResponse
  */
 public function primarize(Address $address)
 {
     if (!$address->isPrimary()) {
         DB::transaction(function () use($address) {
             $this->addressManager->primarizeAddress($address, $this->user());
         });
     }
     return $this->success('edit');
 }
 public function update(Request $request)
 {
     $this->validate($request, ['city_id' => 'required|exists:locations,id,depth,' . Location::getCityDepth()], ['city_id' => '请至少输入城市']);
     if ($address = $this->addressManager->getAddressRepository()->whereOwner($this->shop())->first()) {
         $this->addressManager->update($address, $request->all());
     } else {
         $this->addressManager->createAddress($this->shop(), $request->all());
     }
     return $this->success('update');
 }
 public function create(OrderCreationRequest $request, Address $address, Seller $seller, AddressManager $addressManager, StockValidator $stockValidator)
 {
     $cartItems = $this->cartManager->getItemsForOrderCreation($this->user(), $seller);
     if ($cartItems->isEmpty()) {
         return $this->error(trans('cart::messages.no_items_by_seller'));
     }
     // check stock
     foreach ($cartItems as $cartItem) {
         $stockValidator->validate($cartItem->getProduct(), $cartItem->getVariant(), $cartItem->quantity);
         if (!$cartItem->getProduct()->isActive()) {
             throw new InvalidDataException(bracketed($cartItem->getProduct()->name) . '已下架');
         }
     }
     // 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;
     if ($address) {
         $address->setFeeType($seller);
     }
     $addresses = $addressManager->getAddressRepository()->whereOwner($this->user())->findAll();
     $paymentMethods = $this->paymentManager->getPaymentMethodRepository()->whereSeller($seller)->findAll();
     return view('order::__front.orders.create', compact('seller', 'cartItems', 'addresses', 'paymentMethods'), ['selectedAddress' => $address]);
 }
 public function index(AddressManager $addressManager)
 {
     $address = $addressManager->getAddressRepository()->whereOwner(shop())->first();
     $cities = $addressManager->getCities();
     return view('shop::__shop.settings', compact('address', 'cities'));
 }