init
This commit is contained in:
@@ -0,0 +1,198 @@
|
||||
<?php
|
||||
/**
|
||||
* @category WeltPixel
|
||||
* @package WeltPixel_LayeredNavigation
|
||||
* @copyright Copyright (c) 2018 Weltpixel
|
||||
* @author Weltpixel TEAM
|
||||
*/
|
||||
|
||||
namespace WeltPixel\LayeredNavigation\Plugin\CatalogSearch;
|
||||
|
||||
use Magento\Catalog\Model\Layer\Resolver;
|
||||
use Magento\Framework\Controller\Result\JsonFactory;
|
||||
use Magento\Framework\View\Result\PageFactory;
|
||||
use Magento\Search\Model\QueryFactory;
|
||||
use Magento\Store\Model\StoreManagerInterface;
|
||||
use Magento\CatalogSearch\Helper\Data as CatalogSearchHelper;
|
||||
use WeltPixel\LayeredNavigation\Helper\Data as WpHelper;
|
||||
|
||||
/**
|
||||
* Class View
|
||||
* @package WeltPixel\LayeredNavigation\Plugin\Category
|
||||
*/
|
||||
class ResultView
|
||||
{
|
||||
/**
|
||||
* Catalog session
|
||||
*
|
||||
* @var Session
|
||||
*/
|
||||
protected $_catalogSession;
|
||||
|
||||
/**
|
||||
* @var StoreManagerInterface
|
||||
*/
|
||||
protected $_storeManager;
|
||||
|
||||
/**
|
||||
* @var QueryFactory
|
||||
*/
|
||||
private $_queryFactory;
|
||||
|
||||
/**
|
||||
* Catalog Layer Resolver
|
||||
*
|
||||
* @var Resolver
|
||||
*/
|
||||
protected $layerResolver;
|
||||
|
||||
/**
|
||||
* @var JsonFactory
|
||||
*/
|
||||
protected $_resultJsonFactory;
|
||||
|
||||
/**
|
||||
* @var PageFactory
|
||||
*/
|
||||
protected $_resultPageFactory;
|
||||
|
||||
/**
|
||||
* @var CatalogSearchHelper
|
||||
*/
|
||||
protected $_catalogSearchHelper;
|
||||
|
||||
/**
|
||||
* @var WpHelper
|
||||
*/
|
||||
protected $_wpHelper;
|
||||
|
||||
/**
|
||||
* ResultView constructor.
|
||||
* @param StoreManagerInterface $storeManager
|
||||
* @param QueryFactory $queryFactory
|
||||
* @param Resolver $layerResolver
|
||||
* @param JsonFactory $resultJsonFactory
|
||||
* @param PageFactory $resultPageFactory
|
||||
* @param CatalogSearchHelper $catalogSearchHelper
|
||||
* @param WpHelper $wpHelper
|
||||
*/
|
||||
public function __construct(
|
||||
StoreManagerInterface $storeManager,
|
||||
QueryFactory $queryFactory,
|
||||
Resolver $layerResolver,
|
||||
JsonFactory $resultJsonFactory,
|
||||
PageFactory $resultPageFactory,
|
||||
CatalogSearchHelper $catalogSearchHelper,
|
||||
WpHelper $wpHelper
|
||||
) {
|
||||
$this->_storeManager = $storeManager;
|
||||
$this->_queryFactory = $queryFactory;
|
||||
$this->layerResolver = $layerResolver;
|
||||
$this->_resultJsonFactory = $resultJsonFactory;
|
||||
$this->_resultPageFactory = $resultPageFactory;
|
||||
$this->_catalogSearchHelper = $catalogSearchHelper;
|
||||
$this->_wpHelper = $wpHelper;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Magento\CatalogSearch\Controller\Result\Index $subject
|
||||
* @param \Closure $method
|
||||
* @return $this|array|mixed
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
*/
|
||||
public function aroundExecute(
|
||||
\Magento\CatalogSearch\Controller\Result\Index $subject,
|
||||
\Closure $method
|
||||
){
|
||||
if($subject->getRequest()->getParam('ajax') == 1){
|
||||
$requestUri = $subject->getRequest()->getRequestUri();
|
||||
$requestUri = preg_replace('/(\?|&)ajax=1/', '', $requestUri);
|
||||
$subject->getRequest()->setRequestUri($requestUri);
|
||||
try {
|
||||
$this->layerResolver->create(Resolver::CATALOG_LAYER_SEARCH);
|
||||
} catch (\Exception $ex) {
|
||||
}
|
||||
/* @var $query \Magento\Search\Model\Query */
|
||||
$query = $this->_queryFactory->get();
|
||||
|
||||
$query->setStoreId($this->_storeManager->getStore()->getId());
|
||||
|
||||
$resultJson = $this->_resultJsonFactory->create();
|
||||
|
||||
if ($query->getQueryText() != '') {
|
||||
|
||||
if ($this->_catalogSearchHelper->isMinQueryLength()) {
|
||||
$query->setId(0)->setIsActive(1)->setIsProcessed(1);
|
||||
} else {
|
||||
$query->saveIncrementalPopularity();
|
||||
|
||||
if ($query->getRedirect()) {
|
||||
$data = [
|
||||
'success' => true,
|
||||
'redirect_url' => $query->getRedirect()
|
||||
];
|
||||
return $resultJson->setData($data);
|
||||
}
|
||||
}
|
||||
|
||||
$this->_catalogSearchHelper->checkNotes();
|
||||
$pageFactory = $this->_resultPageFactory->create();
|
||||
$resultsBlockHtml = $pageFactory->getLayout()->getBlock('search.result')->toHtml();
|
||||
$leftNavBlockHtml = $pageFactory->getLayout()->getBlock('catalogsearch.leftnav')->toHtml();
|
||||
|
||||
$dataLayerContent = '';
|
||||
$dataLayerContentGa4 = '';
|
||||
$dataLayerBlock = $pageFactory->getLayout()->getBlock('head.additional');
|
||||
if ($dataLayerBlock) {
|
||||
$dLBlockHtml = $dataLayerBlock->toHtml();
|
||||
|
||||
preg_match('/var dlObjects ?= ?(.*?)];/', $dLBlockHtml, $matches);
|
||||
if (count($matches) == 2) {
|
||||
$dataLayerContent = $matches[1] . ']';
|
||||
}
|
||||
preg_match('/var dl4Objects ?= ?(.*?)];/', $dLBlockHtml, $matchesGa4);
|
||||
if (count($matchesGa4) == 2) {
|
||||
$dataLayerContentGa4 = $matchesGa4[1] . ']';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$ga4ServerSideViewItemListContent = '';
|
||||
$ga4ServerSideViewItemListBlock = $pageFactory->getLayout()->getBlock('weltpixel-ga4-server-view-item-list');
|
||||
if ($ga4ServerSideViewItemListBlock) {
|
||||
$ga4ServerSideViewItemListBlockHtml = $ga4ServerSideViewItemListBlock->toHtml();
|
||||
preg_match('/<input.*id="wp_ga4_server_side_view_item_list".*value="(.*?)"/', $ga4ServerSideViewItemListBlockHtml, $matchesGa4ServerSide);
|
||||
if (count($matchesGa4ServerSide) == 2) {
|
||||
$ga4ServerSideViewItemListContent = $matchesGa4ServerSide[1];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return $this->_resultJsonFactory->create()->setData(
|
||||
[
|
||||
'success' => true,
|
||||
'html' => [
|
||||
'products_list' => $resultsBlockHtml,
|
||||
'filters' => $leftNavBlockHtml,
|
||||
'dataLayer' => $dataLayerContent,
|
||||
'dataLayerGA4' => $dataLayerContentGa4,
|
||||
'ga4ServerSideItemListHash' => $ga4ServerSideViewItemListContent
|
||||
]
|
||||
]
|
||||
);
|
||||
return $data;
|
||||
} else {
|
||||
$data = [
|
||||
'success' => true,
|
||||
'redirect_url' => $this->_redirect->getRedirectUrl()
|
||||
];
|
||||
return $resultJson->setData($data);
|
||||
}
|
||||
} else {
|
||||
return $method();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
/**
|
||||
* @category WeltPixel
|
||||
* @package WeltPixel_LayeredNavigation
|
||||
* @copyright Copyright (c) 2018 Weltpixel
|
||||
* @author Weltpixel TEAM
|
||||
*/
|
||||
|
||||
namespace WeltPixel\LayeredNavigation\Plugin\Category;
|
||||
|
||||
use Magento\Framework\Controller\Result\JsonFactory;
|
||||
use Magento\Framework\View\Result\Page;
|
||||
use Magento\Framework\UrlInterface;
|
||||
use WeltPixel\LayeredNavigation\Helper\Data;
|
||||
use Magento\Framework\View\Result\PageFactory;
|
||||
use Magento\Framework\App\Action\Action;
|
||||
|
||||
/**
|
||||
* Class View
|
||||
* @package WeltPixel\LayeredNavigation\Plugin\Category
|
||||
*/
|
||||
class View
|
||||
{
|
||||
/**
|
||||
* @var JsonFactory
|
||||
*/
|
||||
protected $_resultJsonFactory;
|
||||
/**
|
||||
* @var UrlInterface
|
||||
*/
|
||||
protected $_storeManager;
|
||||
/**
|
||||
* @var \WeltPixel\LayeredNavigation\Helper\Data
|
||||
*/
|
||||
protected $_wpHelper;
|
||||
|
||||
/**
|
||||
* @var PageFactory
|
||||
*/
|
||||
protected $pageFactory;
|
||||
|
||||
/**
|
||||
* View constructor.
|
||||
* @param JsonFactory $resultJsonFactory
|
||||
* @param UrlInterface $_storeManager
|
||||
* @param Data $wpHelper
|
||||
* @param PageFactory $pageFactory
|
||||
*/
|
||||
public function __construct(
|
||||
JsonFactory $resultJsonFactory,
|
||||
UrlInterface $_storeManager,
|
||||
Data $wpHelper,
|
||||
PageFactory $pageFactory
|
||||
)
|
||||
{
|
||||
$this->_resultJsonFactory = $resultJsonFactory;
|
||||
$this->_storeManager = $_storeManager;
|
||||
$this->_wpHelper = $wpHelper;
|
||||
$this->pageFactory = $pageFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Action $subject
|
||||
* @param $page
|
||||
* @return $this|void
|
||||
*/
|
||||
public function afterExecute(Action $subject, $page)
|
||||
{
|
||||
if(!$this->_wpHelper->isAjaxEnabled()) {
|
||||
return $page;
|
||||
}
|
||||
|
||||
$response = $page;
|
||||
if ($response instanceof Page) {
|
||||
if ($subject->getRequest()->getParam('ajax') == 1) {
|
||||
$subject->getRequest()->getQuery()->set('ajax', null);
|
||||
$requestUri = $subject->getRequest()->getRequestUri();
|
||||
$requestUri = preg_replace('/(\?|&)ajax=1/', '', $requestUri);
|
||||
$subject->getRequest()->setRequestUri($requestUri);
|
||||
|
||||
$productsList = $response->getLayout()->getBlock('category.products.list');
|
||||
$listMode = $subject->getRequest()->getParam('product_list_mode');
|
||||
if($listMode) {
|
||||
$productsList->getChildBlock('product_list_toolbar')->setData('_current_grid_mode', $listMode);
|
||||
}
|
||||
$productsListBlockHtml = $productsList->toHtml();
|
||||
$leftNavBlockHtml = $response->getLayout()->getBlock('catalog.leftnav')->toHtml();
|
||||
|
||||
$dataLayerContent = '';
|
||||
$dataLayerContentGa4 = '';
|
||||
$dataLayerBlock = $response->getLayout()->getBlock('head.additional');
|
||||
if ($dataLayerBlock) {
|
||||
$dLBlockHtml = $dataLayerBlock->toHtml();
|
||||
preg_match('/var dlObjects ?= ?(.*?)];/', $dLBlockHtml, $matches);
|
||||
if (count($matches) == 2) {
|
||||
$dataLayerContent = $matches[1] . ']';
|
||||
}
|
||||
preg_match('/var dl4Objects ?= ?(.*?)];/', $dLBlockHtml, $matchesGa4);
|
||||
if (count($matchesGa4) == 2) {
|
||||
$dataLayerContentGa4 = $matchesGa4[1] . ']';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$ga4ServerSideViewItemListContent = '';
|
||||
$ga4ServerSideViewItemListBlock = $response->getLayout()->getBlock('weltpixel-ga4-server-view-item-list');
|
||||
if ($ga4ServerSideViewItemListBlock) {
|
||||
$ga4ServerSideViewItemListBlockHtml = $ga4ServerSideViewItemListBlock->toHtml();
|
||||
preg_match('/<input.*id="wp_ga4_server_side_view_item_list".*value="(.*?)"/', $ga4ServerSideViewItemListBlockHtml, $matchesGa4ServerSide);
|
||||
if (count($matchesGa4ServerSide) == 2) {
|
||||
$ga4ServerSideViewItemListContent = $matchesGa4ServerSide[1];
|
||||
}
|
||||
}
|
||||
|
||||
$tags = [];
|
||||
$blocksList = [$productsList,$leftNavBlockHtml];
|
||||
foreach ($blocksList as $block) {
|
||||
if ($block instanceof \Magento\Framework\DataObject\IdentityInterface) {
|
||||
$tags = array_merge($tags, $block->getIdentities());
|
||||
}
|
||||
}
|
||||
$tags = array_unique($tags);
|
||||
|
||||
return $this->_resultJsonFactory->create()->setData(
|
||||
[
|
||||
'success' => true,
|
||||
'html' => [
|
||||
'products_list' => $productsListBlockHtml,
|
||||
'filters' => $leftNavBlockHtml,
|
||||
'dataLayer' => $dataLayerContent,
|
||||
'dataLayerGA4' => $dataLayerContentGa4,
|
||||
'ga4ServerSideItemListHash' => $ga4ServerSideViewItemListContent
|
||||
]
|
||||
]
|
||||
)->setHeader('X-Magento-Tags', implode(',', $tags));
|
||||
}
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
/**
|
||||
* @category WeltPixel
|
||||
* @package WeltPixel_LayeredNavigation
|
||||
* @copyright Copyright (c) 2018 Weltpixel
|
||||
* @author Weltpixel TEAM
|
||||
*/
|
||||
|
||||
namespace WeltPixel\LayeredNavigation\Plugin\Layer;
|
||||
|
||||
use WeltPixel\LayeredNavigation\Helper\Data;
|
||||
|
||||
/**
|
||||
* Class FilterList
|
||||
* @package WeltPixel\LayeredNavigation\Plugin\Layer
|
||||
*/
|
||||
class FilterList
|
||||
{
|
||||
/**
|
||||
* @var \WeltPixel\LayeredNavigation\Helper\Data
|
||||
*/
|
||||
protected $_wpHelper;
|
||||
|
||||
/**
|
||||
* FilterList constructor.
|
||||
* @param Data $wpHelper
|
||||
*/
|
||||
public function __construct(
|
||||
Data $wpHelper
|
||||
)
|
||||
{
|
||||
$this->_wpHelper = $wpHelper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove category filter if disabled in configuration
|
||||
*
|
||||
* @param \Magento\Catalog\Model\Layer\FilterList $subject
|
||||
* @param $result
|
||||
* @return array
|
||||
*/
|
||||
public function afterGetFilters(\Magento\Catalog\Model\Layer\FilterList $subject, $result)
|
||||
{
|
||||
if(!$this->_wpHelper->isEnabled()){
|
||||
return $result;
|
||||
}
|
||||
$filteredResult = [];
|
||||
if(!$this->_wpHelper->showCategoriesBlock()) {
|
||||
foreach($result as $r) {
|
||||
if($r->getRequestVar() != 'cat') {
|
||||
$filteredResult[] = $r;
|
||||
}
|
||||
}
|
||||
return $filteredResult;
|
||||
|
||||
} else {
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
<?php
|
||||
/**
|
||||
* @category WeltPixel
|
||||
* @package WeltPixel_LayeredNavigation
|
||||
* @copyright Copyright (c) 2018 Weltpixel
|
||||
* @author Weltpixel TEAM
|
||||
*/
|
||||
|
||||
namespace WeltPixel\LayeredNavigation\Plugin\Model\Layer\Filter;
|
||||
|
||||
use WeltPixel\LayeredNavigation\Helper\Data as LayerHelper;
|
||||
use WeltPixel\LayeredNavigation\Model\Layer\Filter as FilterModel;
|
||||
|
||||
/**
|
||||
* Class Item
|
||||
* @package WeltPixel\LayeredNavigation\Model\Plugin\Layer\Filter
|
||||
*/
|
||||
class Item
|
||||
{
|
||||
/** @var \Magento\Framework\UrlInterface */
|
||||
protected $_url;
|
||||
|
||||
/** @var \Magento\Theme\Block\Html\Pager */
|
||||
protected $_htmlPagerBlock;
|
||||
|
||||
/** @var \Magento\Framework\App\RequestInterface */
|
||||
protected $_request;
|
||||
|
||||
/** @var \WeltPixel\LayeredNavigation\Helper\Data */
|
||||
protected $_wpHelper;
|
||||
/**
|
||||
* @var FilterModel
|
||||
*/
|
||||
protected $_filterModel;
|
||||
|
||||
/**
|
||||
* Item constructor.
|
||||
* @param \Magento\Framework\UrlInterface $url
|
||||
* @param \Magento\Theme\Block\Html\Pager $htmlPagerBlock
|
||||
* @param \Magento\Framework\App\RequestInterface $request
|
||||
* @param LayerHelper $_wpHelper
|
||||
* @param FilterModel $filterModel
|
||||
*/
|
||||
public function __construct(
|
||||
\Magento\Framework\UrlInterface $url,
|
||||
\Magento\Theme\Block\Html\Pager $htmlPagerBlock,
|
||||
\Magento\Framework\App\RequestInterface $request,
|
||||
LayerHelper $wpHelper,
|
||||
FilterModel $filterModel
|
||||
)
|
||||
{
|
||||
$this->_url = $url;
|
||||
$this->_htmlPagerBlock = $htmlPagerBlock;
|
||||
$this->_request = $request;
|
||||
$this->_wpHelper = $wpHelper;
|
||||
$this->_filterModel = $filterModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Magento\Catalog\Model\Layer\Filter\Item $item
|
||||
* @param $proceed
|
||||
* @return string
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
*/
|
||||
public function __aroundGetUrl(\Magento\Catalog\Model\Layer\Filter\Item $item, $proceed)
|
||||
{
|
||||
if (!$this->_wpHelper->isEnabled()) {
|
||||
return $proceed();
|
||||
}
|
||||
|
||||
$value = [];
|
||||
$filter = $item->getFilter();
|
||||
if ($this->_filterModel->isMultiple($filter)) {
|
||||
$requestVar = $filter->getRequestVar();
|
||||
if ($requestValue = $this->_request->getParam($requestVar)) {
|
||||
$value = explode(',', $requestValue);
|
||||
}
|
||||
if (!in_array($item->getValue(), $value)) {
|
||||
$value[] = $item->getValue();
|
||||
}
|
||||
}
|
||||
|
||||
if (sizeof($value)) {
|
||||
$query = [
|
||||
$filter->getRequestVar() => implode(',', $value),
|
||||
$this->_htmlPagerBlock->getPageVarName() => null,
|
||||
];
|
||||
|
||||
return $this->_url->getUrl('*/*/*', ['_current' => true, '_use_rewrite' => true, '_query' => $query]);
|
||||
}
|
||||
|
||||
return $proceed();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Magento\Catalog\Model\Layer\Filter\Item $item
|
||||
* @param $proceed
|
||||
* @return string
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
*/
|
||||
public function aroundGetRemoveUrl(\Magento\Catalog\Model\Layer\Filter\Item $item, $proceed)
|
||||
{
|
||||
if (!$this->_wpHelper->isEnabled()) {
|
||||
return $proceed();
|
||||
}
|
||||
|
||||
$value = [];
|
||||
$filter = $item->getFilter();
|
||||
|
||||
$value = $this->_filterModel->getFilterValue($filter);
|
||||
$itemValue = $item->getValue();
|
||||
if (is_array($item->getValue())) {
|
||||
$itemValue = implode('-', $item->getValue());
|
||||
}
|
||||
if (in_array($itemValue, $value)) {
|
||||
$value = array_diff($value, [$itemValue]);
|
||||
}
|
||||
|
||||
$params['_query'] = [$filter->getRequestVar() => count($value) ? implode(',', $value) : $filter->getResetValue()];
|
||||
$params['_current'] = true;
|
||||
$params['_use_rewrite'] = true;
|
||||
$params['_escape'] = true;
|
||||
|
||||
return $this->_url->getUrl('*/*/*', $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Magento\Catalog\Model\Layer\Filter\Item $item
|
||||
* @param $proceed
|
||||
* @return string
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
*/
|
||||
public function aroundGetUrl(\Magento\Catalog\Model\Layer\Filter\Item $item, $proceed)
|
||||
{
|
||||
if (!$this->_wpHelper->isEnabled() || $this->_wpHelper->isAjaxEnabled()) {
|
||||
return $proceed();
|
||||
}
|
||||
|
||||
$filter = $item->getFilter();
|
||||
if ($filter instanceof \WeltPixel\LayeredNavigation\Model\Layer\Filter\Category) {
|
||||
$isMultiSelect = false;
|
||||
} else {
|
||||
$isMultiSelect = $this->_filterModel->isMultiselect($filter->getAttributeModel()->getAttributeId());
|
||||
}
|
||||
|
||||
if (!$isMultiSelect) {
|
||||
return $proceed();
|
||||
}
|
||||
|
||||
$requestVarValue = $this->_filterModel->getFilterValue($filter);
|
||||
|
||||
if (in_array($item->getValue(), $requestVarValue)) {
|
||||
$requestVarValue = array_diff($requestVarValue, [$item->getValue()]);
|
||||
} else {
|
||||
array_push($requestVarValue, $item->getValue());
|
||||
}
|
||||
|
||||
$requestVarValue = implode(",", $requestVarValue);
|
||||
|
||||
$query = [
|
||||
$filter->getRequestVar() => $requestVarValue,
|
||||
$this->_htmlPagerBlock->getPageVarName() => null,
|
||||
];
|
||||
return $this->_url->getUrl('*/*/*', ['_current' => true, '_use_rewrite' => true, '_query' => $query]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
/**
|
||||
* @category WeltPixel
|
||||
* @package WeltPixel_LayeredNavigation
|
||||
* @copyright Copyright (c) 2018 Weltpixel
|
||||
* @author Weltpixel TEAM
|
||||
*/
|
||||
|
||||
namespace WeltPixel\LayeredNavigation\Plugin\Swatches;
|
||||
|
||||
use WeltPixel\LayeredNavigation\Helper\Data as LayerHelper;
|
||||
use WeltPixel\LayeredNavigation\Model\Layer\Filter as FilterModel;
|
||||
|
||||
/**
|
||||
* Class RenderLayered
|
||||
* @package WeltPixel\LayeredNavigation\Plugin\Swatches
|
||||
*/
|
||||
class RenderLayered
|
||||
{
|
||||
/** @var \Magento\Framework\UrlInterface */
|
||||
protected $_url;
|
||||
|
||||
/** @var \Magento\Theme\Block\Html\Pager */
|
||||
protected $_htmlPagerBlock;
|
||||
|
||||
/** @var \Magento\Framework\App\RequestInterface */
|
||||
protected $_request;
|
||||
|
||||
/** @var \WeltPixel\LayeredNavigation\Helper\Data */
|
||||
protected $_wpHelper;
|
||||
/**
|
||||
* @var FilterModel
|
||||
*/
|
||||
protected $_filterModel;
|
||||
|
||||
/**
|
||||
* @var \Magento\Eav\Model\ResourceModel\Entity\Attribute
|
||||
*/
|
||||
protected $eavAttribute;
|
||||
|
||||
/**
|
||||
* Item constructor.
|
||||
* @param \Magento\Framework\UrlInterface $url
|
||||
* @param \Magento\Theme\Block\Html\Pager $htmlPagerBlock
|
||||
* @param \Magento\Framework\App\RequestInterface $request
|
||||
* @param LayerHelper $_wpHelper
|
||||
* @param FilterModel $filterModel
|
||||
* @param \Magento\Eav\Model\ResourceModel\Entity\Attribute $eavAttribute
|
||||
*/
|
||||
public function __construct(
|
||||
\Magento\Framework\UrlInterface $url,
|
||||
\Magento\Theme\Block\Html\Pager $htmlPagerBlock,
|
||||
\Magento\Framework\App\RequestInterface $request,
|
||||
LayerHelper $wpHelper,
|
||||
FilterModel $filterModel,
|
||||
\Magento\Eav\Model\ResourceModel\Entity\Attribute $eavAttribute
|
||||
) {
|
||||
$this->_url = $url;
|
||||
$this->_htmlPagerBlock = $htmlPagerBlock;
|
||||
$this->_request = $request;
|
||||
$this->_wpHelper = $wpHelper;
|
||||
$this->_filterModel = $filterModel;
|
||||
$this->eavAttribute = $eavAttribute;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Magento\Swatches\Block\LayeredNavigation\RenderLayered $renderLayered
|
||||
* @param $proceed
|
||||
* @param string $attributeCode
|
||||
* @param int $optionId
|
||||
* @return string
|
||||
*/
|
||||
public function aroundBuildUrl(
|
||||
\Magento\Swatches\Block\LayeredNavigation\RenderLayered $renderLayered,
|
||||
$proceed,
|
||||
$attributeCode,
|
||||
$optionId
|
||||
) {
|
||||
if (!$this->_wpHelper->isEnabled() || $this->_wpHelper->isAjaxEnabled()) {
|
||||
return $proceed($attributeCode, $optionId);
|
||||
}
|
||||
|
||||
$attributeId = $this->eavAttribute->getIdByCode('catalog_product', $attributeCode);
|
||||
$isMultiSelect = $this->_filterModel->isMultiselect($attributeId);
|
||||
|
||||
if (!$isMultiSelect) {
|
||||
return $proceed($attributeCode, $optionId);
|
||||
}
|
||||
|
||||
$filterValue = $this->_request->getParam($attributeCode);
|
||||
$requestVarValue = [];
|
||||
if (!empty($filterValue)) {
|
||||
$requestVarValue = explode(',', $filterValue);
|
||||
}
|
||||
|
||||
if (in_array($optionId, $requestVarValue)) {
|
||||
$requestVarValue = array_diff($requestVarValue, [$optionId]);
|
||||
} else {
|
||||
array_push($requestVarValue, $optionId);
|
||||
}
|
||||
|
||||
$requestVarValue = implode(",", $requestVarValue);
|
||||
|
||||
$query = [
|
||||
$attributeCode => $requestVarValue,
|
||||
$this->_htmlPagerBlock->getPageVarName() => null
|
||||
];
|
||||
|
||||
return $this->_url->getUrl('*/*/*', ['_current' => true, '_use_rewrite' => true, '_query' => $query]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* @category WeltPixel
|
||||
* @package WeltPixel_LayeredNavigation
|
||||
* @copyright Copyright (c) 2018 Weltpixel
|
||||
* @author Weltpixel TEAM
|
||||
*/
|
||||
namespace WeltPixel\LayeredNavigation\Plugin;
|
||||
|
||||
class Utility extends \WeltPixel\Backend\Plugin\Utility
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getModuleName()
|
||||
{
|
||||
return $this->convertToString(
|
||||
[
|
||||
'87', '101', '108', '116', '80', '105', '120', '101', '108', '95', '76', '97', '121', '101', '114',
|
||||
'101', '100', '78', '97', '118', '105', '103', '97', '116', '105', '111', '110', '95', '70', '114',
|
||||
'101', '101'
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function _getAdminPaths()
|
||||
{
|
||||
return [
|
||||
$this->convertToString(
|
||||
[
|
||||
'115', '121', '115', '116', '101', '109', '95', '99', '111', '110', '102', '105', '103', '47',
|
||||
'101', '100', '105', '116', '47', '115', '101', '99', '116', '105', '111', '110', '47', '119',
|
||||
'101', '108', '116', '112', '105', '120', '101', '108', '95', '108', '97', '121', '101', '114',
|
||||
'101', '100', '110', '97', '118', '105', '103', '97', '116', '105', '111', '110'
|
||||
]
|
||||
)
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user