Exemple #1
0
 /**
  * @return void
  */
 public function executeInternal()
 {
     try {
         $this->_catalogSearchAdvanced->addFilters($this->getRequest()->getQueryValue());
         $this->_view->loadLayout();
         $this->_view->renderLayout();
     } catch (\Magento\Framework\Exception\LocalizedException $e) {
         $this->messageManager->addError($e->getMessage());
         $defaultUrl = $this->_urlFactory->create()->addQueryParams($this->getRequest()->getQueryValue())->getUrl('*/*/');
         $this->getResponse()->setRedirect($this->_redirect->error($defaultUrl));
     }
 }
Exemple #2
0
 /**
  * {@inheritdoc}
  */
 public function getItems()
 {
     $items = [];
     /** @var \Magento\Search\Model\Query $query */
     foreach ($this->collection as $query) {
         $url = $this->urlFactory->create();
         $url->setQueryParam('q', $query->getQueryText());
         $url = $url->getUrl('catalogsearch/result');
         $key = strtolower(trim($query->getQueryText()));
         $items[$key] = ['query_text' => $query->getQueryText(), 'num_results' => $query->getNumResults(), 'popularity' => $query->getPopularity(), 'url' => $url];
     }
     return array_values($items);
 }
 /**
  * @param \Ced\DevTool\Block\Context $context
  * @param \Magento\Framework\UrlFactory $urlFactory
  */
 public function __construct(\Ced\DevTool\Block\Context $context, UrlFactory $urlFactory)
 {
     $this->_devToolHelper = $context->getDevToolHelper();
     $this->_config = $context->getConfig();
     $this->_urlApp = $urlFactory->create();
     parent::__construct($context);
 }
Exemple #4
0
 /**
  * @param Context $context
  * @param Session $customerSession
  * @param PageFactory $resultPageFactory
  * @param ScopeConfigInterface $scopeConfig
  * @param StoreManagerInterface $storeManager
  * @param AccountManagementInterface $customerAccountManagement
  * @param CustomerRepositoryInterface $customerRepository
  * @param Address $addressHelper
  * @param UrlFactory $urlFactory
  *
  * @SuppressWarnings(PHPMD.ExcessiveParameterList)
  */
 public function __construct(Context $context, Session $customerSession, PageFactory $resultPageFactory, ScopeConfigInterface $scopeConfig, StoreManagerInterface $storeManager, AccountManagementInterface $customerAccountManagement, CustomerRepositoryInterface $customerRepository, Address $addressHelper, UrlFactory $urlFactory)
 {
     $this->scopeConfig = $scopeConfig;
     $this->storeManager = $storeManager;
     $this->customerAccountManagement = $customerAccountManagement;
     $this->customerRepository = $customerRepository;
     $this->addressHelper = $addressHelper;
     $this->urlModel = $urlFactory->create();
     parent::__construct($context, $customerSession, $resultPageFactory);
 }
Exemple #5
0
 /**
  * @param \Magento\Framework\DataObject $obj
  * @return string
  */
 public function getSearchUrl($obj)
 {
     /** @var $url UrlInterface */
     $url = $this->_urlFactory->create();
     /*
      * url encoding will be done in Url.php http_build_query
      * so no need to explicitly called urlencode for the text
      */
     $url->setQueryParam('q', $obj->getName());
     return $url->getUrl('catalogsearch/result');
 }
Exemple #6
0
 public function __construct(Context $context, PageFactory $resultPageFactory, Registration $registration, Session $customerSession, StoreManagerInterface $storeManager, AccountManagementInterface $accountManagement, CustomerUrl $customerUrl, CustomerExtractor $customerExtractor, AccountRedirect $accountRedirect, UrlFactory $urlFactory, Logger $logger)
 {
     $this->resultPageFactory = $resultPageFactory;
     parent::__construct($context);
     $this->registration = $registration;
     $this->session = $customerSession;
     $this->storeManager = $storeManager;
     $this->accountManagement = $accountManagement;
     $this->customerUrl = $customerUrl;
     $this->customerExtractor = $customerExtractor;
     $this->accountRedirect = $accountRedirect;
     $this->urlModel = $urlFactory->create();
     $this->logger = $logger;
 }
 /**
  * {@inheritdoc}
  * @param Observer $observer
  * @return bool
  */
 public function execute(Observer $observer)
 {
     if ($this->config->isNorouteToSearchEnabled()) {
         /** @var \Magento\Framework\App\Request\Http $request */
         $request = $observer->getEvent()->getData('request');
         /** @var \Magento\Framework\App\Response\Http\Interceptor $response */
         $response = $observer->getEvent()->getData('response');
         $extension = pathinfo($request->getRequestString(), PATHINFO_EXTENSION);
         if ($response->getStatusCode() != 404 || !$request->isGet() || in_array($extension, $this->mediaTypes)) {
             return false;
         } else {
             $searchQuery = $this->getSearchQuery($request);
             if (!$searchQuery) {
                 return false;
             }
             $message = __('The page you requested was not found, but we have searched for relevant content.');
             $this->messageManager->addNotice($message);
             $url = $this->urlFactory->create()->addQueryParams(['q' => $searchQuery])->getUrl('catalogsearch/result');
             $response->setRedirect($url)->setStatusCode(301)->sendResponse();
         }
     }
     return true;
 }
 /**
  * @param Context $context
  * @param Session $customerSession
  * @param ScopeConfigInterface $scopeConfig
  * @param StoreManagerInterface $storeManager
  * @param AccountManagementInterface $accountManagement
  * @param Address $addressHelper
  * @param UrlFactory $urlFactory
  * @param FormFactory $formFactory
  * @param SubscriberFactory $subscriberFactory
  * @param RegionInterfaceFactory $regionDataFactory
  * @param AddressInterfaceFactory $addressDataFactory
  * @param CustomerInterfaceFactory $customerDataFactory
  * @param CustomerUrl $customerUrl
  * @param Registration $registration
  * @param Escaper $escaper
  * @param CustomerExtractor $customerExtractor
  * @param DataObjectHelper $dataObjectHelper
  * @param AccountRedirect $accountRedirect
  *
  * @SuppressWarnings(PHPMD.ExcessiveParameterList)
  */
 public function __construct(Context $context, Session $customerSession, ScopeConfigInterface $scopeConfig, StoreManagerInterface $storeManager, AccountManagementInterface $accountManagement, Address $addressHelper, UrlFactory $urlFactory, FormFactory $formFactory, SubscriberFactory $subscriberFactory, RegionInterfaceFactory $regionDataFactory, AddressInterfaceFactory $addressDataFactory, CustomerInterfaceFactory $customerDataFactory, CustomerUrl $customerUrl, Registration $registration, Escaper $escaper, CustomerExtractor $customerExtractor, DataObjectHelper $dataObjectHelper, AccountRedirect $accountRedirect)
 {
     $this->session = $customerSession;
     $this->scopeConfig = $scopeConfig;
     $this->storeManager = $storeManager;
     $this->accountManagement = $accountManagement;
     $this->addressHelper = $addressHelper;
     $this->formFactory = $formFactory;
     $this->subscriberFactory = $subscriberFactory;
     $this->regionDataFactory = $regionDataFactory;
     $this->addressDataFactory = $addressDataFactory;
     $this->customerDataFactory = $customerDataFactory;
     $this->customerUrl = $customerUrl;
     $this->registration = $registration;
     $this->escaper = $escaper;
     $this->customerExtractor = $customerExtractor;
     $this->urlModel = $urlFactory->create();
     $this->dataObjectHelper = $dataObjectHelper;
     $this->accountRedirect = $accountRedirect;
     parent::__construct($context);
 }
Exemple #9
0
 /**
  * @return \Magento\Framework\UrlInterface
  */
 protected function _createUrl()
 {
     return $this->_urlFactory->create();
 }
Exemple #10
0
 /**
  * Return search url for query
  *
  * @param string $query
  * @return string
  */
 public function getQueryUrl($query)
 {
     return $this->urlFactory->create()->addQueryParams(['q' => $query])->getUrl('catalogsearch/result');
 }
Exemple #11
0
 /**
  * Retrieve URL Instance
  *
  * @return \Magento\Framework\UrlInterface
  */
 private function getUrlInstance()
 {
     return $this->urlFactory->create();
 }
Exemple #12
0
 /**
  * Fallback Url
  *
  * @param string $from
  * @param string $to
  * @return string
  */
 public function getFallbackUrl($from, $to)
 {
     return $this->urlFactory->create()->addQueryParams(['q' => $to, 'f' => $from])->getUrl('catalogsearch/result');
 }
Exemple #13
0
 /**
  * @return string
  */
 public function getFormUrl()
 {
     return $this->_urlFactory->create()->addQueryParams($this->getRequest()->getQueryValue())->getUrl('*/*/', ['_escape' => true]);
 }