/**
  * @param CartRepository $cartRepository
  * @param CartValuesTransformer $cartValuesTransformer
  * @return array
  */
 public function remove(CartRepository $cartRepository, CartValuesTransformer $cartValuesTransformer)
 {
     $productVariationId = Request::get('productVariationId', 0);
     $quantity = Request::get('quantity', 1);
     try {
         $cart = $cartRepository->find();
         $cart->remove($productVariationId, $quantity);
         $cart = $cartRepository->save($cart);
         $final = $cart->toArray($cartValuesTransformer);
         return $this->respond(true, $final);
     } catch (\Exception $e) {
         return $this->respond(false, [], $e->getMessage());
     }
 }
 /**
  * @param      $items
  * @param bool $priceIncludesTax
  * @param int $shippingTaxRate
  * @return array
  */
 public function makeFromIds($items, $priceIncludesTax, $shippingTaxRate = 0)
 {
     $products = $this->cartRepository->getProducts($items);
     $productFactory = new ProductFactory();
     $final = [];
     foreach ($this->getUniqueList($items) as $productVariationId => $quantity) {
         /** @noinspection PhpUndefinedFieldInspection */
         foreach ($products->result as $product) {
             $vrProduct = $productFactory->fromApi($product);
             if ($product->variations[0]->id == $productVariationId) {
                 $final[] = $this->make($vrProduct, $priceIncludesTax, $quantity, $shippingTaxRate);
             }
         }
     }
     return $final;
 }
 /**
  * @param CartRepository $cartRepository
  * @return \Illuminate\Http\RedirectResponse
  */
 public function clear(CartRepository $cartRepository)
 {
     $cart = $cartRepository->find();
     $cart->clear();
     $cartRepository->save($cart);
     Session::flash('vendirun-alert-success', 'Cart Emptied');
     if (Session::has('primaryPagePath')) {
         return Redirect::to(Session::get('primaryPagePath'));
     }
     return Redirect::back();
 }
 /**
  * @param OrderRepository $orderRepository
  * @param CartRepository $cartRepository
  * @param int $orderId
  * @return \Illuminate\Contracts\View\View
  */
 public function failure(OrderRepository $orderRepository, CartRepository $cartRepository, $orderId)
 {
     // clear the cart because the order already exists
     $cartRepository->save($cartRepository->find()->clear());
     // if NULL, we'll get the most recent order from session
     try {
         $data['order'] = $orderRepository->find($orderId, Session::get('orderOneTimeToken', NULL));
         Session::remove('orderOneTimeToken');
     } catch (FailResponseException $e) {
         // if we can't find a valid order, might just be that the session has expired,
         //    in which case we just won't show the order details
         $data['order'] = NULL;
     }
     $data['pageTitle'] = trans('vendirun::checkout.orderFailedTitle');
     return View::make('vendirun::checkout.failure', $data);
 }