/**
  * Print Shipment Action
  *
  * @return \Magento\Framework\Controller\Result\Redirect|\Magento\Framework\View\Result\Page
  */
 public function execute()
 {
     $shipmentId = (int) $this->getRequest()->getParam('shipment_id');
     if ($shipmentId) {
         $shipment = $this->_objectManager->create('Magento\\Sales\\Model\\Order\\Shipment')->load($shipmentId);
         $order = $shipment->getOrder();
     } else {
         $orderId = (int) $this->getRequest()->getParam('order_id');
         $order = $this->_objectManager->create('Magento\\Sales\\Model\\Order')->load($orderId);
     }
     if ($this->orderAuthorization->canView($order)) {
         $this->_coreRegistry->register('current_order', $order);
         if (isset($shipment)) {
             $this->_coreRegistry->register('current_shipment', $shipment);
         }
         /** @var \Magento\Framework\View\Result\Page $resultPage */
         $resultPage = $this->resultPageFactory->create();
         $resultPage->addHandle('print');
         return $resultPage;
     } else {
         /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
         $resultRedirect = $this->resultRedirectFactory->create();
         if ($this->_objectManager->get('Magento\\Customer\\Model\\Session')->isLoggedIn()) {
             $resultRedirect->setPath('*/*/history');
         } else {
             $resultRedirect->setPath('sales/guest/form');
         }
         return $resultRedirect;
     }
 }
Beispiel #2
0
 /**
  * Action for reorder
  *
  * @return \Magento\Framework\Controller\ResultInterface
  */
 public function execute()
 {
     $result = $this->orderLoader->load($this->_request);
     if ($result instanceof \Magento\Framework\Controller\ResultInterface) {
         return $result;
     }
     $order = $this->_coreRegistry->registry('current_order');
     /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
     $resultRedirect = $this->resultRedirectFactory->create();
     /* @var $cart \Magento\Checkout\Model\Cart */
     $cart = $this->_objectManager->get('Magento\\Checkout\\Model\\Cart');
     $items = $order->getItemsCollection();
     foreach ($items as $item) {
         try {
             $cart->addOrderItem($item);
         } catch (\Magento\Framework\Exception\LocalizedException $e) {
             if ($this->_objectManager->get('Magento\\Checkout\\Model\\Session')->getUseNotice(true)) {
                 $this->messageManager->addNotice($e->getMessage());
             } else {
                 $this->messageManager->addError($e->getMessage());
             }
             return $resultRedirect->setPath('*/*/history');
         } catch (\Exception $e) {
             $this->messageManager->addException($e, __('We cannot add this item to your shopping cart.'));
             return $resultRedirect->setPath('checkout/cart');
         }
     }
     $cart->save();
     return $resultRedirect->setPath('checkout/cart');
 }
Beispiel #3
0
 /**
  * Set back redirect url to response
  *
  * @param null|string $backUrl
  *
  * @return \Magento\Framework\Controller\Result\Redirect
  */
 protected function _goBack($backUrl = null)
 {
     $resultRedirect = $this->resultRedirectFactory->create();
     if ($backUrl || ($backUrl = $this->getBackUrl($this->_redirect->getRefererUrl()))) {
         $resultRedirect->setUrl($backUrl);
     }
     return $resultRedirect;
 }
 /**
  * Retrieve redirect
  *
  * @return ResultRedirect
  */
 public function getRedirect()
 {
     $this->updateLastCustomerId();
     $this->prepareRedirectUrl();
     /** @var ResultRedirect $resultRedirect */
     $resultRedirect = $this->resultRedirectFactory->create();
     $resultRedirect->setUrl($this->session->getBeforeAuthUrl(true));
     return $resultRedirect;
 }
Beispiel #5
0
 /**
  * Order view form page
  *
  * @return \Magento\Framework\Controller\Result\Redirect|\Magento\Framework\View\Result\Page
  */
 public function execute()
 {
     if ($this->_objectManager->get('Magento\\Customer\\Model\\Session')->isLoggedIn()) {
         return $this->resultRedirectFactory->create()->setPath('customer/account/');
     }
     $resultPage = $this->resultPageFactory->create();
     $resultPage->getConfig()->getTitle()->set(__('Orders and Returns'));
     $this->_objectManager->get('Magento\\Sales\\Helper\\Guest')->getBreadcrumbs($resultPage);
     return $resultPage;
 }
 /**
  * @param \Magento\Backend\App\AbstractAction $subject
  * @param callable $proceed
  * @param \Magento\Framework\App\RequestInterface $request
  *
  * @return mixed
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function aroundDispatch(\Magento\Backend\App\AbstractAction $subject, \Closure $proceed, \Magento\Framework\App\RequestInterface $request)
 {
     $requestedActionName = $request->getActionName();
     if (in_array($requestedActionName, $this->_openActions)) {
         $request->setDispatched(true);
     } else {
         if ($this->_auth->getUser()) {
             $this->_auth->getUser()->reload();
         }
         if (!$this->_auth->isLoggedIn()) {
             $this->_processNotLoggedInUser($request);
         } else {
             $this->_auth->getAuthStorage()->prolong();
             $backendApp = null;
             if ($request->getParam('app')) {
                 $backendApp = $this->backendAppList->getCurrentApp();
             }
             if ($backendApp) {
                 $resultRedirect = $this->resultRedirectFactory->create();
                 $baseUrl = \Magento\Framework\App\Request\Http::getUrlNoScript($this->backendUrl->getBaseUrl());
                 $baseUrl = $baseUrl . $backendApp->getStartupPage();
                 return $resultRedirect->setUrl($baseUrl);
             }
         }
     }
     $this->_auth->getAuthStorage()->refreshAcl();
     return $proceed($request);
 }
 /**
  * @param RequestInterface $request
  * @return bool|\Magento\Framework\Controller\Result\Forward|\Magento\Framework\Controller\Result\Redirect
  */
 public function load(RequestInterface $request)
 {
     $orderId = (int) $request->getParam('order_id');
     if (!$orderId) {
         /** @var \Magento\Framework\Controller\Result\Forward $resultForward */
         $resultForward = $this->resultForwardFactory->create();
         return $resultForward->forward('noroute');
     }
     $order = $this->orderFactory->create()->load($orderId);
     if ($this->orderAuthorization->canView($order)) {
         $this->registry->register('current_order', $order);
         return true;
     }
     /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
     $resultRedirect = $this->redirectFactory->create();
     return $resultRedirect->setUrl($this->url->getUrl('*/*/history'));
 }
Beispiel #8
0
 /**
  * Try to load valid order by $_POST or $_COOKIE
  *
  * @param App\RequestInterface $request
  * @return \Magento\Framework\Controller\Result\Redirect|bool
  *
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function loadValidOrder(App\RequestInterface $request)
 {
     if ($this->customerSession->isLoggedIn()) {
         return $this->resultRedirectFactory->create()->setPath('sales/order/history');
     }
     $post = $request->getPostValue();
     $errors = false;
     /** @var $order \Magento\Sales\Model\Order */
     $order = $this->orderFactory->create();
     $fromCookie = $this->cookieManager->getCookie(self::COOKIE_NAME);
     if (empty($post) && !$fromCookie) {
         return $this->resultRedirectFactory->create()->setPath('sales/guest/form');
     } elseif (!empty($post) && isset($post['oar_order_id']) && isset($post['oar_type'])) {
         $type = $post['oar_type'];
         $incrementId = $post['oar_order_id'];
         $lastName = $post['oar_billing_lastname'];
         $email = $post['oar_email'];
         $zip = $post['oar_zip'];
         $storeId = $this->_storeManager->getStore()->getId();
         if (empty($incrementId) || empty($lastName) || empty($type) || empty($storeId) || !in_array($type, ['email', 'zip']) || $type == 'email' && empty($email) || $type == 'zip' && empty($zip)) {
             $errors = true;
         }
         if (!$errors) {
             $order = $order->loadByIncrementIdAndStoreId($incrementId, $storeId);
         }
         $errors = true;
         if ($order->getId()) {
             $billingAddress = $order->getBillingAddress();
             if (strtolower($lastName) == strtolower($billingAddress->getLastname()) && ($type == 'email' && strtolower($email) == strtolower($billingAddress->getEmail()) || $type == 'zip' && strtolower($zip) == strtolower($billingAddress->getPostcode()))) {
                 $errors = false;
             }
         }
         if (!$errors) {
             $toCookie = base64_encode($order->getProtectCode() . ':' . $incrementId);
             $this->setGuestViewCookie($toCookie);
         }
     } elseif ($fromCookie) {
         $cookieData = explode(':', base64_decode($fromCookie));
         $protectCode = isset($cookieData[0]) ? $cookieData[0] : null;
         $incrementId = isset($cookieData[1]) ? $cookieData[1] : null;
         $errors = true;
         if (!empty($protectCode) && !empty($incrementId)) {
             $order->loadByIncrementId($incrementId);
             if ($order->getProtectCode() === $protectCode) {
                 // renew cookie
                 $this->setGuestViewCookie($fromCookie);
                 $errors = false;
             }
         }
     }
     if (!$errors && $order->getId()) {
         $this->coreRegistry->register('current_order', $order);
         return true;
     }
     $this->messageManager->addError(__('You entered incorrect data. Please try again.'));
     return $this->resultRedirectFactory->create()->setPath('sales/guest/form');
 }
Beispiel #9
0
 /**
  * Make sure customer is valid, if logged in
  *
  * By default will add error messages and redirect to customer edit form
  *
  * @param bool $redirect - stop dispatch and redirect?
  * @param bool $addErrors - add error messages?
  * @return bool|\Magento\Framework\Controller\Result\Redirect
  */
 protected function _preDispatchValidateCustomer($redirect = true, $addErrors = true)
 {
     try {
         $customer = $this->customerRepository->getById($this->_customerSession->getCustomerId());
     } catch (NoSuchEntityException $e) {
         return true;
     }
     if (isset($customer)) {
         $validationResult = $this->accountManagement->validate($customer);
         if (!$validationResult->isValid()) {
             if ($addErrors) {
                 foreach ($validationResult->getMessages() as $error) {
                     $this->messageManager->addError($error);
                 }
             }
             if ($redirect) {
                 $this->_actionFlag->set('', self::FLAG_NO_DISPATCH, true);
                 return $this->resultRedirectFactory->create()->setPath('customer/account/edit');
             }
             return false;
         }
     }
     return true;
 }
Beispiel #10
0
 /**
  * Category view action
  *
  * @return \Magento\Framework\Controller\ResultInterface
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function execute()
 {
     if ($this->_request->getParam(\Magento\Framework\App\Action\Action::PARAM_NAME_URL_ENCODED)) {
         return $this->resultRedirectFactory->create()->setUrl($this->_redirect->getRedirectUrl());
     }
     $category = $this->_initCategory();
     if ($category) {
         $this->layerResolver->create(Resolver::CATALOG_LAYER_CATEGORY);
         $settings = $this->_catalogDesign->getDesignSettings($category);
         // apply custom design
         if ($settings->getCustomDesign()) {
             $this->_catalogDesign->applyCustomDesign($settings->getCustomDesign());
         }
         $this->_catalogSession->setLastViewedCategoryId($category->getId());
         $page = $this->resultPageFactory->create();
         // apply custom layout (page) template once the blocks are generated
         if ($settings->getPageLayout()) {
             $page->getConfig()->setPageLayout($settings->getPageLayout());
         }
         if ($category->getIsAnchor()) {
             $type = $category->hasChildren() ? 'layered' : 'layered_without_children';
         } else {
             $type = $category->hasChildren() ? 'default' : 'default_without_children';
         }
         if (!$category->hasChildren()) {
             // Two levels removed from parent.  Need to add default page type.
             $parentType = strtok($type, '_');
             $page->addPageLayoutHandles(['type' => $parentType]);
         }
         $page->addPageLayoutHandles(['type' => $type, 'id' => $category->getId()]);
         // apply custom layout update once layout is loaded
         $layoutUpdates = $settings->getLayoutUpdates();
         if ($layoutUpdates && is_array($layoutUpdates)) {
             foreach ($layoutUpdates as $layoutUpdate) {
                 $page->addUpdate($layoutUpdate);
             }
         }
         $page->getConfig()->addBodyClass('page-products')->addBodyClass('categorypath-' . $this->categoryUrlPathGenerator->getUrlPath($category))->addBodyClass('category-' . $category->getUrlKey());
         $page->getLayout()->initMessages();
         return $page;
     } elseif (!$this->getResponse()->isRedirect()) {
         return $this->resultForwardFactory->create()->forward('noroute');
     }
 }
Beispiel #11
0
 /**
  * Product view action
  *
  * @return \Magento\Framework\Controller\Result\Forward|\Magento\Framework\Controller\Result\Redirect
  */
 public function execute()
 {
     // Get initial data from request
     $categoryId = (int) $this->getRequest()->getParam('category', false);
     $productId = (int) $this->getRequest()->getParam('id');
     $specifyOptions = $this->getRequest()->getParam('options');
     if ($this->getRequest()->isPost() && $this->getRequest()->getParam(self::PARAM_NAME_URL_ENCODED)) {
         $product = $this->_initProduct();
         if (!$product) {
             return $this->noProductRedirect();
         }
         if ($specifyOptions) {
             $notice = $product->getTypeInstance()->getSpecifyOptionMessage();
             $this->messageManager->addNotice($notice);
         }
         if ($this->getRequest()->isAjax()) {
             $this->getResponse()->representJson($this->_objectManager->get('Magento\\Framework\\Json\\Helper\\Data')->jsonEncode(['backUrl' => $this->_redirect->getRedirectUrl()]));
             return;
         }
         $resultRedirect = $this->resultRedirectFactory->create();
         $resultRedirect->setRefererOrBaseUrl();
         return $resultRedirect;
     }
     // Prepare helper and params
     $params = new \Magento\Framework\Object();
     $params->setCategoryId($categoryId);
     $params->setSpecifyOptions($specifyOptions);
     // Render page
     try {
         $page = $this->resultPageFactory->create(false, ['isIsolated' => true]);
         $this->viewHelper->prepareAndRender($page, $productId, $this, $params);
         return $page;
     } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
         return $this->noProductRedirect();
     } catch (\Exception $e) {
         $this->_objectManager->get('Psr\\Log\\LoggerInterface')->critical($e);
         $resultForward = $this->resultForwardFactory->create();
         $resultForward->forward('noroute');
         return $resultForward;
     }
 }
Beispiel #12
0
 /**
  * Create redirect object, which can be used to redirect user to previous or main page
  *
  * @return \Magento\Framework\Controller\ResultInterface
  */
 public function getDefaultResult()
 {
     $resultRedirect = $this->resultRedirectFactory->create();
     return $resultRedirect->setRefererOrBaseUrl();
 }
Beispiel #13
0
 /**
  * @return \Magento\Framework\Controller\Result\Redirect
  */
 public function execute()
 {
     return $this->resultRedirectFactory->create()->setPath('checkout/onepage', ['_secure' => true]);
 }