示例#1
0
 /**
  * @param Attribute\Save $subject
  * @param RequestInterface $request
  * @return array
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function beforeExecute(Attribute\Save $subject, RequestInterface $request)
 {
     $data = $request->getPostValue();
     if (isset($data['frontend_input'])) {
         switch ($data['frontend_input']) {
             case 'swatch_visual':
                 $data[Swatch::SWATCH_INPUT_TYPE_KEY] = Swatch::SWATCH_INPUT_TYPE_VISUAL;
                 $data['frontend_input'] = 'select';
                 $request->setPostValue($data);
                 break;
             case 'swatch_text':
                 $data[Swatch::SWATCH_INPUT_TYPE_KEY] = Swatch::SWATCH_INPUT_TYPE_TEXT;
                 $data['use_product_image_for_swatch'] = 0;
                 $data['frontend_input'] = 'select';
                 $request->setPostValue($data);
                 break;
             case 'select':
                 $data[Swatch::SWATCH_INPUT_TYPE_KEY] = Swatch::SWATCH_INPUT_TYPE_DROPDOWN;
                 $data['frontend_input'] = 'select';
                 $request->setPostValue($data);
                 break;
         }
     }
     return [$request];
 }
示例#2
0
 /**
  * Check if module is enabled
  * If allow only for customer - redirect to login page
  *
  * @param RequestInterface $request
  * @return \Magento\Framework\App\ResponseInterface
  * @throws \Magento\Framework\Exception\NotFoundException
  */
 public function dispatch(RequestInterface $request)
 {
     /* @var $helper \Magento\Sendfriend\Helper\Data */
     $helper = $this->_objectManager->get('Magento\\Sendfriend\\Helper\\Data');
     /* @var $session \Magento\Customer\Model\Session */
     $session = $this->_objectManager->get('Magento\\Customer\\Model\\Session');
     if (!$helper->isEnabled()) {
         throw new NotFoundException(__('Page not found.'));
     }
     if (!$helper->isAllowForGuest() && !$session->authenticate($this)) {
         $this->_actionFlag->set('', self::FLAG_NO_DISPATCH, true);
         if ($this->getRequest()->getActionName() == 'sendemail') {
             $session->setBeforeAuthUrl($this->_url->getUrl('sendfriend/product/send', ['_current' => true]));
             $this->_objectManager->get('Magento\\Catalog\\Model\\Session')->setSendfriendFormData($request->getPostValue());
         }
     }
     return parent::dispatch($request);
 }
示例#3
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');
 }
示例#4
0
 /**
  * Check that request uses https protocol if it should.
  * Function redirects user to correct URL if needed.
  *
  * @param \Magento\Framework\App\RequestInterface $request
  * @param string $path
  * @return void
  * @SuppressWarnings(PHPMD.ExitExpression)
  */
 protected function _checkShouldBeSecure(\Magento\Framework\App\RequestInterface $request, $path = '')
 {
     if ($request->getPostValue()) {
         return;
     }
     if ($this->pathConfig->shouldBeSecure($path) && !$request->isSecure()) {
         $url = $this->pathConfig->getCurrentSecureUrl($request);
         if ($this->_shouldRedirectToSecure()) {
             $url = $this->_url->getRedirectUrl($url);
         }
         $this->_responseFactory->create()->setRedirect($url)->sendResponse();
         exit;
     }
 }