This repository has been archived by the owner on Oct 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Freek Gruntjes
committed
Oct 6, 2017
1 parent
07eaea3
commit 9b503d6
Showing
5 changed files
with
148 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
src/Model/Observer/AbstractProductNavigationRequestObserver.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<?php | ||
/** | ||
* Tweakwise & Emico (https://www.tweakwise.com/ & https://www.emico.nl/) - All Rights Reserved | ||
* | ||
* @copyright Copyright (c) 2017-2017 Tweakwise.com B.V. (https://www.tweakwise.com) | ||
* @license Proprietary and confidential, Unauthorized copying of this file, via any medium is strictly prohibited | ||
*/ | ||
|
||
namespace Emico\Tweakwise\Model\Observer; | ||
|
||
use Emico\Tweakwise\Model\Catalog\Layer\NavigationContext\CurrentContext; | ||
use Emico\Tweakwise\Model\Config; | ||
use Magento\Framework\App\Action\Action; | ||
use Magento\Framework\Event\Observer; | ||
use Magento\Framework\Event\ObserverInterface; | ||
use Magento\Framework\HTTP\PhpEnvironment\Response; | ||
use Magento\Framework\UrlInterface; | ||
|
||
abstract class AbstractProductNavigationRequestObserver implements ObserverInterface | ||
{ | ||
/** | ||
* @var Config | ||
*/ | ||
protected $config; | ||
|
||
/** | ||
* @var CurrentContext | ||
*/ | ||
protected $context; | ||
|
||
/** | ||
* @var UrlInterface | ||
*/ | ||
protected $urlBuilder; | ||
|
||
/** | ||
* @var Action | ||
*/ | ||
protected $controller; | ||
|
||
/** | ||
* CatalogLastPageRedirect constructor. | ||
* | ||
* @param Config $config | ||
* @param CurrentContext $context | ||
* @param UrlInterface $urlBuilder | ||
* @param Action $action | ||
*/ | ||
public function __construct(Config $config, CurrentContext $context, UrlInterface $urlBuilder, Action $action) | ||
{ | ||
$this->config = $config; | ||
$this->context = $context; | ||
$this->urlBuilder = $urlBuilder; | ||
$this->controller = $action; | ||
} | ||
|
||
/** | ||
* @return Response|null | ||
*/ | ||
protected function getHttpResponse() | ||
{ | ||
$response = $this->controller->getResponse(); | ||
if (!$response instanceof Response) { | ||
return null; | ||
} | ||
|
||
return $response; | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
protected function hasTweakwiseResponse() | ||
{ | ||
if (!$this->config->isLayeredEnabled()) { | ||
return false; | ||
} | ||
|
||
if (!$this->context->getContext()->hasResponse()) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function execute(Observer $observer) | ||
{ | ||
$response = $this->getHttpResponse(); | ||
if (!$response) { | ||
return; | ||
} | ||
|
||
if (!$this->hasTweakwiseResponse()) { | ||
return; | ||
} | ||
|
||
$this->_execute($observer); | ||
} | ||
|
||
/** | ||
* @param Observer $observer | ||
*/ | ||
abstract protected function _execute(Observer $observer); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
/** | ||
* Tweakwise & Emico (https://www.tweakwise.com/ & https://www.emico.nl/) - All Rights Reserved | ||
* | ||
* @copyright Copyright (c) 2017-2017 Tweakwise.com B.V. (https://www.tweakwise.com) | ||
* @license Proprietary and confidential, Unauthorized copying of this file, via any medium is strictly prohibited | ||
*/ | ||
|
||
namespace Emico\Tweakwise\Model\Observer; | ||
|
||
use Magento\Framework\Event\Observer; | ||
|
||
class CatalogSearchRedirect extends AbstractProductNavigationRequestObserver | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function _execute(Observer $observer) | ||
{ | ||
$redirects = $this->context->getResponse()->getRedirects(); | ||
if (!$redirects) { | ||
return; | ||
} | ||
|
||
|
||
$redirect = current($redirects); | ||
$url = $redirect->getUrl(); | ||
if (strpos($url, 'http') !== 0) { | ||
$url = $this->urlBuilder->getUrl($url); | ||
} | ||
|
||
$this->getHttpResponse()->setRedirect($url); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters