/** * @param $customerRepository * @return int */ public static function getDefaultCountry(CustomerRepository $customerRepository = null) { // if country ID is in the GET then obviously, that if (isset($_GET['countryId']) && is_numeric($_GET['countryId'])) { return (int) $_GET['countryId']; } if ($customerRepository) { try { $customer = $customerRepository->find(); // get top address /* @var $customer Customer */ $addresses = $customer->getAddresses(); if (count($addresses) > 0) { return $addresses[0]->getCountryId(); } } catch (CustomerNotFoundException $e) { // get company default country $clientInfo = Config::get('clientInfo'); if ($clientInfo->country_id) { return $clientInfo->country_id; } } } // use UK as super-default if company default not set return 79; }
/** * @param OrderRepository $orderRepository * @param CustomerRepository $customerRepository * @param $orderId * @return \Illuminate\Contracts\View\View */ public function view(OrderRepository $orderRepository, CustomerRepository $customerRepository, $orderId) { $data['customer'] = $customerRepository->find(); $data['order'] = $orderRepository->find($orderId); $data['defaultAddress'] = $data['order']->getBillingAddress(); $data['pageTitle'] = trans('vendirun::product.viewOrder'); return View::make('vendirun::customer.orders.view', $data); }
/** * @param CustomerRepository $customerRepository * @return \Illuminate\Http\RedirectResponse */ public function save(CustomerRepository $customerRepository) { $customer = $customerRepository->find(); $data = Request::all(); $data['id'] = $data['addressId']; $customer->addAddress(new Address($data)); $customerRepository->save($customer); return Redirect::route('vendirun.customer.account'); }
/** * @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 ProductRepository $productRepository * @param CustomerRepository $customerRepository * @param $productId * @return \Illuminate\Contracts\View\View */ public function index(ProductRepository $productRepository, CustomerRepository $customerRepository, $productId) { $data = []; try { $data['product'] = $productRepository->find($productId); } catch (FailResponseException $e) { if (App::environment() == 'production') { abort(404); } } try { $data['customer'] = $customerRepository->find(); } catch (CustomerNotFoundException $e) { // this exception means we're not logged in. No problem } $data['recommend'] = true; $data['pageTitle'] = trans('vendirun::product.sendProductToFriend'); return View::make('vendirun::product.recommend', $data); }
/** * @param CustomerRepository $customerRepository * @return \Illuminate\Contracts\View\View */ public function index(CustomerRepository $customerRepository) { $data['pageTitle'] = trans('vendirun::customer.account'); $data['customer'] = $customerRepository->find(); return View::make('vendirun::customer.account.index', $data); }
/** * Process Contact form * @param IlRequest $request * @param CustomerRepository $customerRepository * @return mixed */ public function processContactForm(IlRequest $request, CustomerRepository $customerRepository) { $this->validate($request, ['email' => 'required']); // we will always make a new customer on contact forms, in case the form values are wildly different from the logged in user's details $customerFactory = new CustomerFactory(); $customer = $customerFactory->make(null, Request::get('fullname', null), Request::get('email')); $customer->setPrimaryTelephone(Request::get('telephone', null)); $customerRepository->save($customer); if (Request::has('propertyId')) { VendirunApi::makeRequest('property/addToFavourite', ['customer_id' => $customer->getId(), 'property_id' => Request::get('propertyId')]); Cache::forget('favourites-' . Session::get('token')); } $note = ''; if (Request::has('property')) { $note .= "<strong>Property Name: " . Request::get('property') . '</strong><br>'; } if (Request::has('product')) { $note .= "<strong>Product Name: " . Request::get('product') . '</strong><br>'; } if (Request::has('message')) { $note .= nl2br(Request::get('message', '')); } if ($note) { VendirunApi::makeRequest('customer/addNote', ['customer_id' => $customer->getId(), 'note' => $note]); } $formId = Request::get('formId', 'Website Form'); VendirunApi::makeRequest('customer/registerFormCompletion', ['customer_id' => $customer->getId(), 'new_customer' => 1, 'data' => json_encode(Request::all()), 'form_id' => $formId]); switch ($formId) { case 'Newsletter Signup': Session::flash('vendirun-alert-success', trans('vendirun::forms.newsletterThanks')); break; default: Session::flash('vendirun-alert-success', trans('vendirun::forms.contactThanks')); } return Redirect::back(); }