/**
  * @param $items
  * @param null $countryId
  * @param string $shippingType
  * @return Cart
  */
 public function makeFromIds($items, $countryId = null, $shippingType = '')
 {
     $clientInfo = Config::get('clientInfo');
     $priceIncludesTax = $clientInfo->business_settings->tax->price_includes_tax;
     $taxes = ProductTaxOptionFactory::makeFromApi($clientInfo->business_settings->tax->country_tax_rates);
     $defaultTaxRate = TaxCalculator::calculateProductTaxRate($taxes, $countryId, $clientInfo->business_settings->tax->default_tax_rate);
     $params = ['ids' => $items, 'priceIncludesTax' => $priceIncludesTax, 'chargeTaxOnShipping' => $clientInfo->business_settings->tax->charge_tax_on_shipping, 'defaultTaxRate' => $defaultTaxRate, 'countryId' => $countryId, 'shippingType' => $shippingType ? $shippingType : null];
     $cart = new Cart($params);
     $cartItemFactory = new CartItemFactory($this->cartRepository, $cart);
     foreach ($cartItemFactory->makeFromIds($items, $priceIncludesTax, $cart->getDefaultTaxRate()) as $item) {
         $cart->add($item);
     }
     $cart->checkIdList();
     // check for free shipping
     if (isset($clientInfo->business_settings->free_shipping) && $clientInfo->business_settings->free_shipping->free_shipping_enabled) {
         $cart->updateForFreeShipping($this->cartValuesTransformer, $clientInfo->business_settings->free_shipping->free_shipping_minimum_order, $clientInfo->business_settings->free_shipping->free_shipping_countries);
     }
     return $cart;
 }
 /**
  * @param CartRepository $cartRepository
  * @param ProductRepository $productRepository
  * @param CartValuesTransformer $cartValuesTransformer
  * @return array
  */
 public function add(CartRepository $cartRepository, ProductRepository $productRepository, CartValuesTransformer $cartValuesTransformer)
 {
     $productVariationId = Request::get('productVariationId', 0);
     $quantity = Request::get('quantity', 1);
     try {
         $cart = $cartRepository->find();
         $product = $productRepository->findByVariationId($productVariationId);
         $clientInfo = Config::get('clientInfo');
         $priceIncludesTax = $clientInfo->business_settings->tax->price_includes_tax;
         $cartItemFactory = new CartItemFactory($cartRepository, $cart);
         $cartItem = $cartItemFactory->make($product, $priceIncludesTax, $quantity);
         $cart->add($cartItem);
         $cart = $cartRepository->save($cart);
         $final = $cart->toArray($cartValuesTransformer);
         $final['itemAdded'] = $product->getDisplayArray();
         $final['itemAdded']['quantity'] = $quantity;
         return $this->respond(true, $final);
     } catch (\Exception $e) {
         return $this->respond(false, [], $e->getMessage());
     }
 }
 /**
  * @param CartRepository    $cartRepository
  * @param ProductRepository $productRepository
  * @param int               $productVariationId
  * @return \Illuminate\Http\RedirectResponse
  */
 public function add(CartRepository $cartRepository, ProductRepository $productRepository, $productVariationId = NULL)
 {
     try {
         $productVariationId = Request::get('productVariationId', $productVariationId);
         $cart = $cartRepository->find();
         $product = $productRepository->findByVariationId($productVariationId);
         $clientInfo = Config::get('clientInfo');
         $priceIncludesTax = $clientInfo->business_settings->tax->price_includes_tax;
         $cartItemFactory = new CartItemFactory($cartRepository, $cart);
         $cartItem = $cartItemFactory->make($product, $priceIncludesTax, Request::input('quantity', 1));
         $cart->add($cartItem);
         $cartRepository->save($cart);
     } catch (Exception $e) {
         Session::flash('vendirun-alert-error', 'Unable to add your item to the cart. ' . $e->getMessage());
         return Redirect::back();
     }
     Session::flash('vendirun-alert-success', 'Item Added to Cart');
     if (Session::has('primaryPagePath')) {
         return Redirect::to(Session::get('primaryPagePath'));
     }
     return Redirect::back();
 }