This repository has been archived by the owner on Jan 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ajax page update, seo urls, price slider
- Loading branch information
Nikita Zhavoronkov
authored and
Nikita Zhavoronkov
committed
Oct 24, 2017
1 parent
ed7f29f
commit 370a056
Showing
31 changed files
with
1,477 additions
and
191 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
namespace Niks\LayeredNavigation\Block; | ||
|
||
use Magento\Framework\View\Element\Template; | ||
|
||
/** | ||
* Class AjaxScript | ||
* @package Niks_LayeredNavigation | ||
*/ | ||
class AjaxScript extends Template | ||
{ | ||
|
||
/** | ||
* Get JSON config | ||
* | ||
* @return string | ||
*/ | ||
public function getAjaxConfig() | ||
{ | ||
$config = [ | ||
'disabled' => !$this->getIsAjax(), | ||
'filtersContainer' => '#layered-filter-block', | ||
'productsContainer' => '.' . \Niks\LayeredNavigation\Plugin\CategoryViewBlock::PRODUCT_LIST_WRAPPER | ||
]; | ||
return json_encode($config); | ||
} | ||
|
||
/** | ||
* Get ajax option | ||
* | ||
* @return string | ||
*/ | ||
protected function getIsAjax() | ||
{ | ||
return $this->_scopeConfig->getValue( | ||
'niks_layered_navigation/general/ajax', | ||
\Magento\Store\Model\ScopeInterface::SCOPE_STORE, | ||
$this->_storeManager->getStore()->getId() | ||
); | ||
} | ||
} |
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,53 @@ | ||
<?php | ||
|
||
namespace Niks\LayeredNavigation\Block\LayeredNavigation; | ||
|
||
use Magento\Framework\View\Element\Template; | ||
|
||
/** | ||
* Class RenderLayered Render Swatches at Layered Navigation | ||
* | ||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects) | ||
*/ | ||
class SliderRenderer extends Template | ||
{ | ||
/** | ||
* Path to template file. | ||
* | ||
* @var string | ||
*/ | ||
protected $_template = 'Niks_LayeredNavigation::slider.phtml'; | ||
|
||
public function getFrom() | ||
{ | ||
$currentValues = $this->getFilter()->getCurrentValue(); | ||
if (isset($currentValues[0])) { | ||
return $currentValues[0]; | ||
} | ||
return $this->getFilter()->getMin(); | ||
} | ||
|
||
public function getTo() | ||
{ | ||
$currentValues = $this->getFilter()->getCurrentValue(); | ||
if (isset($currentValues[1])) { | ||
return $currentValues[1]; | ||
} | ||
return $this->getFilter()->getMax(); | ||
} | ||
|
||
public function getPriceRangeUrlTemplate() | ||
{ | ||
return $this->_urlBuilder->getFilterUrl( | ||
$this->getFilter()->getRequestVar(), | ||
'{{from}}-{{to}}', | ||
[], | ||
true | ||
); | ||
} | ||
|
||
public function getCurrencySymbol() | ||
{ | ||
return $this->_storeManager->getStore()->getCurrentCurrency()->getCurrencySymbol(); | ||
} | ||
} |
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,84 @@ | ||
<?php | ||
namespace Niks\LayeredNavigation\Controller; | ||
|
||
use Magento\Framework\UrlInterface; | ||
use Magento\UrlRewrite\Model\UrlFinderInterface; | ||
use Niks\LayeredNavigation\Model\Url\Builder; | ||
use Niks\LayeredNavigation\Model\Url\Hydrator; | ||
|
||
/** | ||
* Class Router | ||
* @package Niks_LayeredNavigation | ||
*/ | ||
class Router extends \Magento\UrlRewrite\Controller\Router implements \Magento\Framework\App\RouterInterface | ||
{ | ||
/** @var \Niks\LayeredNavigation\Model\Url\Hydrator */ | ||
protected $urlHydrator; | ||
|
||
/** @var \Magento\Framework\Registry */ | ||
protected $registry; | ||
|
||
/** | ||
* @param \Magento\Framework\App\ActionFactory $actionFactory | ||
* @param \Magento\Framework\UrlInterface $url | ||
* @param \Magento\Store\Model\StoreManagerInterface $storeManager | ||
* @param \Magento\Framework\App\ResponseInterface $response | ||
* @param UrlFinderInterface $urlFinder | ||
* @param Hydrator $urlHydrator | ||
* @param \Magento\Framework\Registry $registry | ||
*/ | ||
public function __construct( | ||
\Magento\Framework\App\ActionFactory $actionFactory, | ||
\Magento\Framework\UrlInterface $url, | ||
\Magento\Store\Model\StoreManagerInterface $storeManager, | ||
\Magento\Framework\App\ResponseInterface $response, | ||
UrlFinderInterface $urlFinder, | ||
Hydrator $urlHydrator, | ||
\Magento\Framework\Registry $registry | ||
) | ||
{ | ||
$this->urlHydrator = $urlHydrator; | ||
$this->registry = $registry; | ||
parent::__construct($actionFactory, $url, $storeManager, $response, $urlFinder); | ||
} | ||
|
||
/** | ||
* Match corresponding navigation URL and modify request | ||
* | ||
* @param \Magento\Framework\App\RequestInterface $request | ||
* @return \Magento\Framework\App\ActionInterface|null | ||
*/ | ||
public function match(\Magento\Framework\App\RequestInterface $request) | ||
{ | ||
$parentMatch = parent::match($request); | ||
if ($parentMatch !== null) { | ||
$request->setAlias( | ||
Builder::REWRITE_NAVIGATION_PATH_ALIAS, | ||
ltrim($request->getOriginalPathInfo(), '/') | ||
); | ||
return $parentMatch; | ||
} | ||
|
||
$filterString = '/' . $this->urlHydrator->getFilterString($request->getPathInfo()); | ||
$originalPath = preg_replace('%' . $filterString . '(?!.*' . $filterString . '.*)%', '', $request->getPathInfo()); | ||
|
||
$rewrite = $this->getRewrite($originalPath, $this->storeManager->getStore()->getId()); | ||
if ($rewrite === null) { | ||
return null; | ||
} | ||
if ($rewrite->getRedirectType()) { | ||
return $this->processRedirect($request, $rewrite); | ||
} | ||
|
||
$this->registry->register('current_category_id', $rewrite->getEntityId()); | ||
$filterParams = $this->urlHydrator->extract($request->getPathInfo()); | ||
if (empty($filterParams)) { | ||
return null; | ||
} | ||
$request->setParam('navigation_filters', $filterParams); | ||
$request->setAlias(UrlInterface::REWRITE_REQUEST_PATH_ALIAS, ltrim($request->getPathInfo(), '/')); | ||
$request->setAlias(Builder::REWRITE_NAVIGATION_PATH_ALIAS, $rewrite->getRequestPath()); | ||
$request->setPathInfo('/' . $rewrite->getTargetPath()); | ||
return $this->actionFactory->create(\Magento\Framework\App\Action\Forward::class); | ||
} | ||
} |
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
Oops, something went wrong.