/**
  * @param $view
  */
 public function posts($view)
 {
     $viewData = $view->getData();
     if (!isset($view['posts'])) {
         $params = [];
         if (isset($viewData['element']->element_options)) {
             $options = json_decode($viewData['element']->element_options);
             if (isset($options->show)) {
                 $params['limit'] = $options->show;
             }
             if (isset($options->show_images) && !$options->show_images) {
                 $view->with('hideImages', true);
             }
             if (isset($options->category)) {
                 $params['category'] = $options->category;
             }
         }
         try {
             $params['token'] = CustomerHelper::checkLoggedinCustomer();
             $request = VendirunApi::makeRequest('blog/search', $params);
             $posts = $request->getData();
         } catch (FailResponseException $e) {
             $posts = [];
         }
         $view->with('posts', $posts);
     }
 }
 /**
  * @return \Illuminate\View\View
  */
 public function recovery()
 {
     // log out if logged in
     if (CustomerHelper::checkLoggedinCustomer()) {
         Session::flush();
     }
     $data['pageTitle'] = trans('vendirun::customer.recoverPassword');
     return View::make('vendirun::customer.password.recovery', $data);
 }
 public function __construct()
 {
     parent::__construct();
     if (!CustomerHelper::checkLoggedinCustomer()) {
         $path = Request::getPathInfo() . (Request::getQueryString() ? '?' . Request::getQueryString() : '');
         Session::put('attemptedAction', $path);
         Session::save();
         Redirect::route(LocaleHelper::localePrefix() . 'vendirun.register')->send();
     }
 }
 /**
  * @param CartRepository $cartRepository
  * @param CustomerRepository $customerRepository
  * @param CartValuesTransformer $transformer
  * @return mixed
  */
 public function index(CartRepository $cartRepository, CustomerRepository $customerRepository, CartValuesTransformer $transformer)
 {
     $this->setPrimaryPath();
     $countryId = Request::get('countryId', null);
     if (!$countryId) {
         $countryId = CustomerHelper::getDefaultCountry($customerRepository);
     }
     $data['cart'] = $cartRepository->find($countryId);
     $data['cartValues'] = $data['cart']->getValues($transformer);
     return View::make('vendirun::product.cart', $data);
 }
 /**
  * @param OrderRepository $orderRepository
  * @return \Illuminate\Contracts\View\View
  */
 public function index(OrderRepository $orderRepository)
 {
     $page = Request::get('page', 1);
     $limit = Request::get('limit', 5);
     $offset = ($page - 1) * $limit;
     $orderSearchResult = $orderRepository->search(CustomerHelper::checkLoggedinCustomer(), Request::get('search', ''), $limit, $offset);
     $pagination = $orderSearchResult->getTotalRows() > 0 ? $pagination = new LengthAwarePaginator($orderSearchResult->getOrders(), $orderSearchResult->getTotalRows(), $orderSearchResult->getLimit(), Request::get('page'), ['path' => Request::url(), 'query' => Request::query()]) : false;
     $data['pageTitle'] = trans('vendirun::product.orderHistory');
     $data['orders'] = $orderSearchResult->getOrders();
     $data['pagination'] = $pagination;
     return View::make('vendirun::customer.orders.index', $data);
 }
 /**
  * @param      $id
  * @param null $oneTimeToken
  * @param bool $removeOneTimeToken
  * @return Order
  */
 public function find($id = null, $oneTimeToken = null, $removeOneTimeToken = true)
 {
     $params = ['id' => $id, 'token' => CustomerHelper::checkLoggedinCustomer(), 'remove_one_time_token' => $removeOneTimeToken];
     try {
         $orderFactory = new OrderFactory();
         $apiResult = VendirunApi::makeRequest('order/find', $params)->getData();
         $order = $orderFactory->fromApi($apiResult);
         $order->setOneTimeToken($oneTimeToken);
         return $order;
     } catch (FailResponseException $e) {
         return null;
     }
 }
 /**
  * @param View $view
  */
 public function customerDetails($view)
 {
     // check if token exists and confirm login
     if ($token = CustomerHelper::checkLoggedinCustomer()) {
         $loggedIn = VendirunApi::makeRequest('customer/tokenAuth', ['token' => $token]);
         if ($loggedIn->getSuccess()) {
             $data = $loggedIn->getData();
             $view->with('loggedInName', $data->name);
             $view->with('loggedInEmail', $data->name);
         } else {
             Session::remove('token');
         }
     }
 }
 /**
  * @return \Illuminate\View\View
  */
 public function search()
 {
     $data = [];
     try {
         $searchVars = $_GET;
         $searchVars['language'] = App::getLocale();
         $searchVars['token'] = CustomerHelper::checkLoggedinCustomer();
         $posts = VendirunApi::makeRequest('blog/search', $searchVars);
         $data['posts'] = $posts->getData();
     } catch (FailResponseException $e) {
         abort('404');
     }
     return View::make('vendirun::blog.search', $data);
 }
 /**
  * @param CustomerRepository $customerRepository
  * @return \Illuminate\Http\RedirectResponse
  */
 public function recalculateShipping(CustomerRepository $customerRepository)
 {
     $customer = $customerRepository->find();
     $countryId = NULL;
     $countryId = CustomerHelper::getDefaultCountry($customerRepository);
     if (Request::has('countryId')) {
         $countryId = Request::get('countryId');
     }
     if (Request::has('shippingaddressId')) {
         $customerCountryId = $customer->getAddressFromAddressId(Request::get('shippingaddressId'));
         if ($customerCountryId) {
             $countryId = $customerCountryId->getCountryId();
         }
     }
     return Redirect::route('vendirun.checkout', ['countryId' => $countryId, 'shippingTypeId' => Request::get('shippingTypeId', NULL)])->withInput();
 }
 /**
  * @param $slug
  * @return \Illuminate\View\View
  */
 public function page($slug = '')
 {
     $data = [];
     try {
         $page = VendirunApi::makeRequest('cms/page', ['slug' => $slug, 'locale' => App::getLocale(), 'token' => CustomerHelper::checkLoggedinCustomer()]);
         $data['page'] = $page->getData();
     } catch (FailResponseException $e) {
         $errors = json_decode($e->getMessage());
         if (isset($errors->try_with_login)) {
             if (CustomerHelper::checkLoggedinCustomer()) {
                 return Redirect::route(LocaleHelper::localePrefix() . 'vendirun.noPermissions');
             }
             return Redirect::route(LocaleHelper::localePrefix() . 'vendirun.register')->withErrors('Please login to view this content');
         }
         abort('404');
     }
     return View::make('vendirun::cms.page', $data);
 }
 /**
  * @param null $countryId
  * @param string $shippingType
  * @return Cart
  */
 public function find($countryId = null, $shippingType = '')
 {
     $cartFactory = new CartFactory($this, $this->cartValuesTransformer);
     if (Session::has('shoppingCart')) {
         return $cartFactory->makeFromIds(Session::get('shoppingCart'), $countryId, $shippingType);
     }
     if (!CustomerHelper::checkLoggedinCustomer()) {
         return $cartFactory->makeFromIds([], $countryId, $shippingType);
     }
     try {
         $data = ['token' => Session::get('token')];
         $result = VendirunApi::makeRequest('cart/fetch', $data)->getData();
         $items = $this->getItemListFromApiReturn($result->items);
     } catch (FailResponseException $e) {
         // if token is invalid
         $items = [];
     }
     return $cartFactory->makeFromIds($items, $countryId, $shippingType);
 }
Example #12
0
 /**
  * Update shipping prices
  */
 private function setShippingPrice()
 {
     if (!$this->countryId) {
         $this->countryId = CustomerHelper::getDefaultCountry();
     }
     $this->availableShippingTypes = ShippingCalculator::availableShippingTypes($this);
     if (!$this->shippingType && count($this->availableShippingTypes) > 0) {
         $this->shippingType = $this->availableShippingTypes[0];
     }
     $this->orderShippingPrice = ShippingCalculator::orderShippingCharge($this);
     foreach ($this->items as $item) {
         $item->setCountryId($this->countryId);
         $item->setShippingType($this->shippingType);
     }
 }