ltsecurityinc安防产品在线商城代码
This commit is contained in:
+14
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Olegnax
|
||||
* @package Olegnax_LayeredNavigation
|
||||
* @copyright Copyright (c) 2019 Olegnax (http://olegnax.com/). All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Olegnax\LayeredNavigation\Block\Adminhtml\System\Config\Form;
|
||||
|
||||
class Info extends \Olegnax\Core\Block\Adminhtml\System\Config\Form\Info
|
||||
{
|
||||
}
|
||||
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Olegnax
|
||||
* @package Olegnax_LayeredNavigation
|
||||
* @copyright Copyright (c) 2019 Olegnax (http://olegnax.com/). All rights reserved.
|
||||
* @license Proprietary License https://olegnax.com/license/
|
||||
*/
|
||||
|
||||
namespace Olegnax\LayeredNavigation\Block\LayeredNavigation;
|
||||
|
||||
use Magento\Catalog\Model\Layer\Filter\Item as FilterItem;
|
||||
use Magento\Catalog\Model\ResourceModel\Layer\Filter\AttributeFactory;
|
||||
use Magento\Eav\Model\Entity\Attribute;
|
||||
use Magento\Eav\Model\Entity\Attribute\Option;
|
||||
use Magento\Framework\UrlInterface;
|
||||
use Magento\Framework\View\Element\Template\Context;
|
||||
use Magento\Swatches\Helper\Data;
|
||||
use Magento\Swatches\Helper\Media;
|
||||
use Olegnax\LayeredNavigation\Helper\Helper;
|
||||
use Olegnax\LayeredNavigation\Model\Layer\Filter;
|
||||
use Magento\Theme\Block\Html\Pager;
|
||||
|
||||
class RenderLayered extends \Magento\Swatches\Block\LayeredNavigation\RenderLayered
|
||||
{
|
||||
|
||||
protected $_url;
|
||||
protected $_helper;
|
||||
protected $_filter;
|
||||
protected $_template = 'Olegnax_LayeredNavigation::product/layered/renderer.phtml';
|
||||
|
||||
/**
|
||||
* RenderLayered constructor.
|
||||
* @param Context $context
|
||||
* @param Attribute $eavAttribute
|
||||
* @param AttributeFactory $layerAttribute
|
||||
* @param Data $swatchHelper
|
||||
* @param Media $mediaHelper
|
||||
* @param UrlInterface $url
|
||||
* @param Helper $helper
|
||||
* @param Filter $filter
|
||||
* @param array $data
|
||||
* @param Pager|null $htmlPagerBlock
|
||||
*/
|
||||
public function __construct(
|
||||
Context $context,
|
||||
Attribute $eavAttribute,
|
||||
AttributeFactory $layerAttribute,
|
||||
Data $swatchHelper,
|
||||
Media $mediaHelper,
|
||||
UrlInterface $url,
|
||||
Helper $helper,
|
||||
Filter $filter,
|
||||
array $data = [],
|
||||
?Pager $htmlPagerBlock = null
|
||||
) {
|
||||
$this->_url = $url;
|
||||
$this->_helper = $helper;
|
||||
$this->_filter = $filter;
|
||||
parent::__construct($context, $eavAttribute, $layerAttribute, $swatchHelper, $mediaHelper, $data, $htmlPagerBlock);
|
||||
}
|
||||
|
||||
protected function getOptionViewData(FilterItem $item, Option $swatchOption)
|
||||
{
|
||||
$result = parent::getOptionViewData($item, $swatchOption);
|
||||
|
||||
if (!$this->_helper->isEnabled() || $this->isOptionDisabled($item)) {
|
||||
return $result;
|
||||
}
|
||||
$filter = $item->getFilter();
|
||||
$itemValue = $item->getValue();
|
||||
$value = [is_array($itemValue) ? implode('-', $itemValue) : $itemValue];
|
||||
if ($this->_filter->isMultiselect($filter)) {
|
||||
$value = array_merge($this->_filter->getFilterValue($filter), $value);
|
||||
$value = array_unique($value);
|
||||
}
|
||||
|
||||
$query = [
|
||||
$filter->getRequestVar() => implode(',', $value),
|
||||
];
|
||||
|
||||
$result['link'] = $this->_url->getUrl(
|
||||
'*/*/*',
|
||||
[
|
||||
'_current' => true,
|
||||
'_use_rewrite' => true,
|
||||
'_query' => $query
|
||||
]
|
||||
);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
+134
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Olegnax
|
||||
* @package Olegnax_LayeredNavigation
|
||||
* @copyright Copyright (c) 2019 Olegnax (http://olegnax.com/). All rights reserved.
|
||||
* @license Proprietary License https://olegnax.com/license/
|
||||
*/
|
||||
|
||||
namespace Olegnax\LayeredNavigation\Block;
|
||||
|
||||
use Magento\Catalog\Helper\Product\ProductList;
|
||||
use Magento\Catalog\Model\Layer\AvailabilityFlagInterface;
|
||||
use Magento\Catalog\Model\Layer\FilterList;
|
||||
use Magento\Catalog\Model\Layer\Resolver;
|
||||
use Magento\Catalog\Model\Product\ProductList\Toolbar;
|
||||
use Magento\Framework\View\Element\Template\Context;
|
||||
use Olegnax\LayeredNavigation\Helper\Helper;
|
||||
|
||||
class Navigation extends \Magento\LayeredNavigation\Block\Navigation
|
||||
{
|
||||
|
||||
protected $_catalogLayer;
|
||||
protected $filterList;
|
||||
protected $visibilityFlag;
|
||||
protected $_productListHelper;
|
||||
protected $_orderField = null;
|
||||
protected $_direction = ProductList::DEFAULT_SORT_DIRECTION;
|
||||
/**
|
||||
* @var Helper
|
||||
*/
|
||||
protected $_helper;
|
||||
|
||||
public function __construct(
|
||||
Context $context,
|
||||
Resolver $layerResolver,
|
||||
FilterList $filterList,
|
||||
AvailabilityFlagInterface $visibilityFlag,
|
||||
ProductList $productListHelper,
|
||||
Helper $helper,
|
||||
array $data = []
|
||||
) {
|
||||
$this->_catalogLayer = $layerResolver->get();
|
||||
$this->filterList = $filterList;
|
||||
$this->visibilityFlag = $visibilityFlag;
|
||||
$this->_productListHelper = $productListHelper;
|
||||
$this->_helper = $helper;
|
||||
parent::__construct($context, $layerResolver, $filterList, $visibilityFlag, $data);
|
||||
}
|
||||
|
||||
public function AjaxEnabled()
|
||||
{
|
||||
return $this->_helper->AjaxEnabled();
|
||||
}
|
||||
|
||||
public function isCategoryFilter($filter)
|
||||
{
|
||||
return ($filter->getRequestVar() == 'cat') ? true : false;
|
||||
}
|
||||
|
||||
public function getFilterButtonHtml()
|
||||
{
|
||||
return $this->_helper->getFilterButtonStyle();
|
||||
}
|
||||
|
||||
public function getActiveFilters()
|
||||
{
|
||||
$filters = $this->getFilters();
|
||||
$activeFilters = [];
|
||||
$ctr = 0;
|
||||
foreach ($filters as $k => $filter) {
|
||||
if ($filter->getRequestVar() == 'cat') {
|
||||
if ($filter->getItemsCount()) {
|
||||
$ctr++;
|
||||
}
|
||||
continue;
|
||||
} else {
|
||||
if ($filter->getItemsCount()) {
|
||||
$attributeId = $filter->getAttributeModel()->getAttributeId();
|
||||
if ($attributeId) {
|
||||
//$activeFilters[] = $ctr;
|
||||
}
|
||||
$ctr++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$activeFiltersStr = implode(' ', $activeFilters);
|
||||
|
||||
return $activeFiltersStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve widget options in json format
|
||||
*
|
||||
* @param array $customOptions Optional parameter for passing custom selectors from template
|
||||
* @return string
|
||||
*/
|
||||
public function getWidgetOptionsJson(array $customOptions = [])
|
||||
{
|
||||
$defaultMode = $this->_productListHelper->getDefaultViewMode($this->getModes());
|
||||
$options = [
|
||||
'mode' => Toolbar::MODE_PARAM_NAME,
|
||||
'direction' => Toolbar::DIRECTION_PARAM_NAME,
|
||||
'order' => Toolbar::ORDER_PARAM_NAME,
|
||||
'limit' => Toolbar::LIMIT_PARAM_NAME,
|
||||
'modeDefault' => $defaultMode,
|
||||
'directionDefault' => $this->_direction ?: ProductList::DEFAULT_SORT_DIRECTION,
|
||||
'orderDefault' => $this->getOrderField(),
|
||||
'limitDefault' => $this->_productListHelper->getDefaultLimitPerPageValue($defaultMode),
|
||||
'url' => $this->getPagerUrl(),
|
||||
];
|
||||
$options = array_replace_recursive($options, $customOptions);
|
||||
return json_encode(['productListToolbarForm' => $options]);
|
||||
}
|
||||
|
||||
protected function getOrderField()
|
||||
{
|
||||
if ($this->_orderField === null) {
|
||||
$this->_orderField = $this->_productListHelper->getDefaultSortField();
|
||||
}
|
||||
return $this->_orderField;
|
||||
}
|
||||
|
||||
public function getPagerUrl($params = [])
|
||||
{
|
||||
$urlParams = [];
|
||||
$urlParams['_current'] = true;
|
||||
$urlParams['_escape'] = false;
|
||||
$urlParams['_use_rewrite'] = true;
|
||||
$urlParams['_query'] = $params;
|
||||
return $this->getUrl('*/*/*', $urlParams);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Olegnax
|
||||
* @package Olegnax_LayeredNavigation
|
||||
* @copyright Copyright (c) 2019 Olegnax (http://olegnax.com/). All rights reserved.
|
||||
* @license Proprietary License https://olegnax.com/license/
|
||||
*/
|
||||
|
||||
namespace Olegnax\LayeredNavigation\Block\Navigation;
|
||||
|
||||
use Magento\Catalog\Model\Layer\Resolver;
|
||||
use Magento\Framework\View\Element\Template\Context;
|
||||
|
||||
class State extends \Magento\LayeredNavigation\Block\Navigation\State
|
||||
{
|
||||
|
||||
protected $_template = 'Olegnax_LayeredNavigation::layer/state.phtml';
|
||||
protected $_catalogLayer;
|
||||
|
||||
public function __construct(
|
||||
Context $context,
|
||||
Resolver $layerResolver,
|
||||
array $data = []
|
||||
) {
|
||||
$this->_catalogLayer = $layerResolver->get();
|
||||
parent::__construct($context, $layerResolver, $data);
|
||||
}
|
||||
|
||||
}
|
||||
+137
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* A Magento 2 module named Olegnax/LayeredNavigation
|
||||
* Copyright (C) 2019
|
||||
*
|
||||
* This file is part of Olegnax/LayeredNavigation.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Olegnax.com license that is
|
||||
* available through the world-wide-web at this URL:
|
||||
* https://www.olegnax.com/license
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade this extension to newer
|
||||
* version in the future.
|
||||
*
|
||||
* @category Block
|
||||
* @package Olegnax_LayeredNavigation
|
||||
* @copyright Copyright (c) 2010-2019 Olegnax (http://www.olegnax.com/)
|
||||
* @license https://www.olegnax.com/license
|
||||
*/
|
||||
|
||||
namespace Olegnax\LayeredNavigation\Block;
|
||||
|
||||
use Magento\Catalog\Model\Layer;
|
||||
use Magento\Catalog\Model\Layer\Resolver;
|
||||
use Magento\Framework\App\ObjectManager;
|
||||
use Magento\Framework\Serialize\Serializer\Json;
|
||||
use Magento\Framework\View\Element\Template\Context;
|
||||
use Olegnax\Core\Block\Template as coreTemplate;
|
||||
use Olegnax\LayeredNavigation\Helper\Helper;
|
||||
|
||||
class Template extends coreTemplate
|
||||
{
|
||||
protected $helper;
|
||||
/**
|
||||
* @var Json|mixed|null
|
||||
*/
|
||||
protected $json;
|
||||
|
||||
public function __construct(
|
||||
Context $context,
|
||||
Helper $helper,
|
||||
Json $json = null,
|
||||
array $data = []
|
||||
) {
|
||||
$this->helper = $helper;
|
||||
$this->json = $json ?: ObjectManager::getInstance()->get(Json::class);
|
||||
parent::__construct($context, $data);
|
||||
}
|
||||
|
||||
public function getNavConfig()
|
||||
{
|
||||
$config = [
|
||||
'clearUrl' => $this->getClearUrl(),
|
||||
'scrollToTop' => 1,
|
||||
'loaderFilter' => (bool)$this->getModuleLoadersConfig('loader_type_filters'),
|
||||
'loaderContent' => (bool)$this->getModuleLoadersConfig('loader_type_content'),
|
||||
'loaderPage' => (bool)$this->getModuleLoadersConfig('loader_type_page'),
|
||||
'abortPrev' => (bool)$this->helper->getModuleConfig('general/abort_prev_request'),
|
||||
];
|
||||
if ($config['loaderContent']) {
|
||||
$config['loaderContentSelector'] = $this->getSelectorProducts();
|
||||
}
|
||||
|
||||
return $this->json->serialize($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve Clear Filters URL
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getClearUrl()
|
||||
{
|
||||
$filterState = [];
|
||||
foreach ($this->getActiveFilters() as $item) {
|
||||
$filterState[$item->getFilter()->getRequestVar()] = $item->getFilter()->getCleanValue();
|
||||
}
|
||||
$params['_current'] = true;
|
||||
$params['_use_rewrite'] = true;
|
||||
$params['_query'] = $filterState;
|
||||
$params['_escape'] = true;
|
||||
return $this->_urlBuilder->getUrl('*/*/*', $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve active filters
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getActiveFilters()
|
||||
{
|
||||
$filters = $this->getLayer()->getState()->getFilters();
|
||||
if (!is_array($filters)) {
|
||||
$filters = [];
|
||||
}
|
||||
return $filters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve Layer object
|
||||
*
|
||||
* @return Layer
|
||||
*/
|
||||
public function getLayer()
|
||||
{
|
||||
if (!$this->hasData('layer')) {
|
||||
$_catalogLayer = $this->_loadObject(Resolver::class)->get();
|
||||
$this->setLayer($_catalogLayer);
|
||||
}
|
||||
return $this->_getData('layer');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
* @param null $storeCode
|
||||
* @return mixed
|
||||
*/
|
||||
public function getModuleLoadersConfig($path = '', $storeCode = null)
|
||||
{
|
||||
return $this->helper->getModuleConfig('loaders/' . $path, $storeCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getSelectorProducts()
|
||||
{
|
||||
$products_container = $this->getModuleLoadersConfig('loader_content_selector') ?: '.column.main .products.products-grid, .column.main .products.products-list, .column.main .products-grid.grid';
|
||||
return $products_container;
|
||||
}
|
||||
|
||||
}
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Olegnax
|
||||
* @package Olegnax_LayeredNavigation
|
||||
* @copyright Copyright (c) 2019 Olegnax (http://olegnax.com/). All rights reserved.
|
||||
* @license Proprietary License https://olegnax.com/license/
|
||||
*/
|
||||
|
||||
namespace Olegnax\LayeredNavigation\Helper;
|
||||
|
||||
use Magento\Framework\App\RequestInterface;
|
||||
use Olegnax\Core\Helper\Helper as CoreHelperHelper;
|
||||
|
||||
class Filter extends CoreHelperHelper
|
||||
{
|
||||
const CONFIG_MODULE = 'olegnax_layered_navigation';
|
||||
|
||||
public function isPriceSlider()
|
||||
{
|
||||
return $this->getModuleConfig('price_slider/price_slider');
|
||||
}
|
||||
|
||||
public function checkedFilter($item, $echoselected = ' checked')
|
||||
{
|
||||
$filter = $item->getFilter();
|
||||
$itemValue = $item->getValue();
|
||||
$itemValue = is_array($itemValue) ? implode('-', $itemValue) : $itemValue;
|
||||
$valueRequest = $this->getFilterValue($filter);
|
||||
if (is_array($valueRequest)) {
|
||||
$result = in_array($itemValue, $valueRequest);
|
||||
} else {
|
||||
$result = false;
|
||||
}
|
||||
if (!empty($echoselected)) {
|
||||
$result = $result ? $echoselected : '';
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getFilterValue($filter, $explode = true)
|
||||
{
|
||||
$filterValue = $this->getRequest()->getParam($filter->getRequestVar());
|
||||
if (empty($filterValue)) {
|
||||
return [];
|
||||
}
|
||||
if ($explode) {
|
||||
$filterValue = explode(',', $filterValue);
|
||||
}
|
||||
|
||||
return $filterValue;
|
||||
}
|
||||
|
||||
public function getRequest()
|
||||
{
|
||||
return $this->_loadObject(RequestInterface::class);
|
||||
}
|
||||
|
||||
public function getSelectedSlider($filter)
|
||||
{
|
||||
$filterValue = $this->getRequest()->getParam($filter->getRequestVar());
|
||||
if (empty($filterValue)) {
|
||||
return '';
|
||||
}
|
||||
return $filterValue;
|
||||
}
|
||||
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Olegnax LayeredNavigation
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Olegnax.com license that is
|
||||
* available through the world-wide-web at this URL:
|
||||
* https://www.olegnax.com/license
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade this extension to newer
|
||||
* version in the future.
|
||||
*
|
||||
* @category Olegnax
|
||||
* @package Olegnax_LayeredNavigation
|
||||
* @copyright Copyright (c) 2019 Olegnax (http://www.olegnax.com/)
|
||||
* @license https://www.olegnax.com/license
|
||||
*/
|
||||
|
||||
namespace Olegnax\LayeredNavigation\Helper;
|
||||
|
||||
use Magento\CatalogSearch\Model\ResourceModel\EngineInterface;
|
||||
use Olegnax\Core\Helper\Helper as CoreHelperHelper;
|
||||
|
||||
class Helper extends CoreHelperHelper
|
||||
{
|
||||
|
||||
const CONFIG_MODULE = 'olegnax_layered_navigation';
|
||||
|
||||
protected $_currentEngine = '';
|
||||
|
||||
public function isEnabled()
|
||||
{
|
||||
return $this->getModuleConfig('general/enable');
|
||||
|
||||
}
|
||||
|
||||
public function isPriceSlider()
|
||||
{
|
||||
return $this->getModuleConfig('price_slider/price_slider');
|
||||
|
||||
}
|
||||
|
||||
public function isElasticSearchEngine()
|
||||
{
|
||||
if (!$this->_currentEngine) {
|
||||
$this->_currentEngine = $this->getSystemValue(EngineInterface::CONFIG_ENGINE_PATH);
|
||||
}
|
||||
if ($this->_currentEngine == 'elasticsearch' || $this->_currentEngine == 'elasticsearch5') {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function AjaxEnabled()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Olegnax
|
||||
* @package Olegnax_LayeredNavigation
|
||||
* @copyright Copyright (c) 2019 Olegnax (http://olegnax.com/). All rights reserved.
|
||||
* @license Proprietary License https://olegnax.com/license/
|
||||
*/
|
||||
|
||||
namespace Olegnax\LayeredNavigation\Model\Category;
|
||||
|
||||
/**
|
||||
* Class DataProvider
|
||||
*
|
||||
* @api
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
* @since 101.0.0
|
||||
*/
|
||||
class DataProvider extends \Magento\Catalog\Model\Category\DataProvider
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @since 101.0.0
|
||||
*/
|
||||
protected function getFieldsMap()
|
||||
{
|
||||
$fields = parent::getFieldsMap();
|
||||
$fields['display_settings'][] = 'ox_nav_disable_ajax';
|
||||
return $fields;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Olegnax\LayeredNavigation\Model\Config\Source;
|
||||
|
||||
|
||||
use Magento\Framework\Option\ArrayInterface;
|
||||
|
||||
class CategoryDepth implements ArrayInterface
|
||||
{
|
||||
public function toOptionArray()
|
||||
{
|
||||
return [
|
||||
['value' => 0, 'label' => __('Don\'t show nested categories')],
|
||||
['value' => 1, 'label' => __('1 level sub categories')],
|
||||
['value' => 2, 'label' => __('2 level sub categories')],
|
||||
['value' => 3, 'label' => __('3 level sub categories')],
|
||||
['value' => 4, 'label' => __('4 level sub categories')],
|
||||
['value' => 5, 'label' => __('5 level sub categories')],
|
||||
];
|
||||
}
|
||||
|
||||
public function toArray()
|
||||
{
|
||||
$array = [];
|
||||
foreach ($this->toOptionArray() as $item) {
|
||||
$array[$item['value']] = $item['label'];
|
||||
}
|
||||
return $array;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Olegnax
|
||||
* @package Olegnax_LayeredNavigation
|
||||
* @copyright Copyright (c) 2019 Olegnax (http://olegnax.com/). All rights reserved.
|
||||
* @license Proprietary License https://olegnax.com/license/
|
||||
*/
|
||||
|
||||
namespace Olegnax\LayeredNavigation\Model\Config\Source;
|
||||
|
||||
use Magento\Framework\Option\ArrayInterface;
|
||||
|
||||
class FiltersType implements ArrayInterface
|
||||
{
|
||||
const TYPE_CHECKBOX = 'checkbox';
|
||||
|
||||
public function toOptionArray()
|
||||
{
|
||||
return [
|
||||
['value' => '', 'label' => __('Simple Links')],
|
||||
['value' => static::TYPE_CHECKBOX, 'label' => __('Checkboxes')],
|
||||
];
|
||||
}
|
||||
|
||||
public function toArray()
|
||||
{
|
||||
$array = [];
|
||||
foreach ($this->toOptionArray() as $item) {
|
||||
$array[$item['value']] = $item['label'];
|
||||
}
|
||||
return $array;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Olegnax
|
||||
* @package Olegnax_LayeredNavigation
|
||||
* @copyright Copyright (c) 2019 Olegnax (http://olegnax.com/). All rights reserved.
|
||||
* @license Proprietary License https://olegnax.com/license/
|
||||
*/
|
||||
|
||||
namespace Olegnax\LayeredNavigation\Model\Config\Source;
|
||||
|
||||
use Magento\Framework\Option\ArrayInterface;
|
||||
|
||||
class LoaderType implements ArrayInterface
|
||||
{
|
||||
const TYPE_THEME = 'theme';
|
||||
const TYPE_MAGENTO = 'magento';
|
||||
const TYPE_BLOCK = 'css';
|
||||
const TYPE_IMAGE = 'image';
|
||||
|
||||
public function toOptionArray()
|
||||
{
|
||||
return [
|
||||
['value' => '', 'label' => __('Disabled')],
|
||||
['value' => static::TYPE_MAGENTO, 'label' => __('Magento Default')],
|
||||
['value' => static::TYPE_BLOCK, 'label' => __('CSS Preloader')],
|
||||
['value' => static::TYPE_THEME, 'label' => __('Theme Preloader')],
|
||||
['value' => static::TYPE_IMAGE, 'label' => __('Custom Image')]
|
||||
];
|
||||
}
|
||||
|
||||
public function toArray()
|
||||
{
|
||||
return [
|
||||
'' => __('Disabled'),
|
||||
static::TYPE_MAGENTO => __('Magento Default'),
|
||||
static::TYPE_IMAGE => __('CSS Preloader'),
|
||||
static::TYPE_THEME => __('Theme Preloader'),
|
||||
static::TYPE_IMAGE => __('Custom Image')
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Olegnax
|
||||
* @package Olegnax_LayeredNavigation
|
||||
* @copyright Copyright (c) 2019 Olegnax (http://olegnax.com/). All rights reserved.
|
||||
* @license Proprietary License https://olegnax.com/license/
|
||||
*/
|
||||
|
||||
namespace Olegnax\LayeredNavigation\Model\Config\Source;
|
||||
|
||||
use Magento\Config\Block\System\Config\Form\Field;
|
||||
use Magento\Framework\Data\Form\Element\AbstractElement;
|
||||
|
||||
class Spacer extends Field
|
||||
{
|
||||
protected function _decorateRowHtml(AbstractElement $element, $html)
|
||||
{
|
||||
return '<tr id="row_' . $element->getHtmlId() . '"><td></td><td colspan="2"><hr class="ox-settings-spacer"></td></tr>';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Olegnax
|
||||
* @package Olegnax_LayeredNavigation
|
||||
* @copyright Copyright (c) 2019 Olegnax (http://olegnax.com/). All rights reserved.
|
||||
* @license Proprietary License https://olegnax.com/license/
|
||||
*/
|
||||
|
||||
namespace Olegnax\LayeredNavigation\Model\Layer;
|
||||
|
||||
use Magento\Framework\App\RequestInterface;
|
||||
|
||||
class Filter
|
||||
{
|
||||
|
||||
protected $request;
|
||||
protected $_ids = [];
|
||||
|
||||
public function __construct(
|
||||
RequestInterface $request
|
||||
) {
|
||||
$this->request = $request;
|
||||
}
|
||||
|
||||
public function getItemUrl($item)
|
||||
{
|
||||
if ($this->isSelected($item)) {
|
||||
return $item->getRemoveUrl();
|
||||
}
|
||||
|
||||
return $item->getUrl();
|
||||
}
|
||||
|
||||
public function getFilterValue($filter, $explode = true)
|
||||
{
|
||||
$filterValue = $this->request->getParam($filter->getRequestVar());
|
||||
if (empty($filterValue)) {
|
||||
return [];
|
||||
}
|
||||
if ($explode) {
|
||||
if (is_string($filterValue)) {
|
||||
$filterValue = explode(',', $filterValue);
|
||||
}
|
||||
}
|
||||
|
||||
return $filterValue;
|
||||
}
|
||||
|
||||
public function isOptionReducesResults($filter, $optionCount, $totalSize)
|
||||
{
|
||||
$result = $optionCount <= $totalSize;
|
||||
|
||||
if ($this->isShowZero($filter)) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
return $optionCount && $result;
|
||||
}
|
||||
|
||||
public function isShowZero($filter)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function isMainFilter($filter)
|
||||
{
|
||||
if (empty($this->_ids)) {
|
||||
$this->_ids = $this->getStateAttributesIds($filter);
|
||||
}
|
||||
$isMulti = false;
|
||||
if (count($this->_ids) <= 1) {
|
||||
$isMulti = true;
|
||||
if (!empty($this->_ids)) {
|
||||
$isMulti = $this->isMultiselect($this->_ids[0]);
|
||||
}
|
||||
}
|
||||
|
||||
return $isMulti;
|
||||
}
|
||||
|
||||
protected function getStateAttributesIds($filter)
|
||||
{
|
||||
$layer = $filter->getLayer();
|
||||
foreach ($layer->getState()->getFilters() as $filter) {
|
||||
if ($model = $filter->getFilter()->getData('attribute_model')) {
|
||||
$this->_ids[] = $model->getId();
|
||||
}
|
||||
}
|
||||
return array_unique($this->_ids);
|
||||
}
|
||||
|
||||
public function isMultiselect($attrId)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,490 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Olegnax
|
||||
* @package Olegnax_LayeredNavigation
|
||||
* @copyright Copyright (c) 2019 Olegnax (http://olegnax.com/). All rights reserved.
|
||||
* @license Proprietary License https://olegnax.com/license/
|
||||
*/
|
||||
|
||||
namespace Olegnax\LayeredNavigation\Model\Layer\Filter;
|
||||
|
||||
use Amasty\ShopbyBase\Helper\FilterSetting;
|
||||
use Exception;
|
||||
use Magento\Catalog\Model\Layer;
|
||||
use Magento\Catalog\Model\Layer\Filter\Item;
|
||||
use Magento\Catalog\Model\Layer\Filter\Item\DataBuilder;
|
||||
use Magento\Catalog\Model\Layer\Filter\ItemFactory;
|
||||
use Magento\Framework\App\ObjectManager;
|
||||
use Magento\Framework\App\RequestInterface;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Magento\Framework\Exception\StateException;
|
||||
use Magento\Framework\Filter\StripTags;
|
||||
use Magento\Framework\Message\ManagerInterface;
|
||||
use Magento\Framework\Search\Response\QueryResponse;
|
||||
use Magento\Framework\Search\ResponseInterface;
|
||||
use Magento\Search\Model\SearchEngine;
|
||||
use Magento\Store\Model\StoreManagerInterface;
|
||||
use Olegnax\LayeredNavigation\Helper\Helper;
|
||||
use Olegnax\LayeredNavigation\Model\Request\Builder;
|
||||
use Olegnax\LayeredNavigation\Model\ResourceModel\Fulltext\Collection;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class Attribute extends \Magento\CatalogSearch\Model\Layer\Filter\Attribute
|
||||
{
|
||||
|
||||
/**
|
||||
* @var Helper
|
||||
*/
|
||||
protected $_helper;
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $_isFilter = false;
|
||||
/**
|
||||
* @var SearchEngine
|
||||
*/
|
||||
protected $searchEngine;
|
||||
/**
|
||||
* @var ManagerInterface
|
||||
*/
|
||||
protected $messageManager;
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $attributeValues = [];
|
||||
/**
|
||||
* @var StripTags
|
||||
*/
|
||||
private $tagFilter;
|
||||
|
||||
public function __construct(
|
||||
ItemFactory $filterItemFactory,
|
||||
StoreManagerInterface $storeManager,
|
||||
Layer $layer,
|
||||
DataBuilder $itemDataBuilder,
|
||||
StripTags $tagFilter,
|
||||
Helper $helper,
|
||||
SearchEngine $searchEngine,
|
||||
ManagerInterface $messageManager,
|
||||
array $data = []
|
||||
) {
|
||||
parent::__construct(
|
||||
$filterItemFactory,
|
||||
$storeManager,
|
||||
$layer,
|
||||
$itemDataBuilder,
|
||||
$tagFilter,
|
||||
$data
|
||||
);
|
||||
$this->_helper = $helper;
|
||||
$this->searchEngine = $searchEngine;
|
||||
$this->messageManager = $messageManager;
|
||||
$this->tagFilter = $tagFilter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply filter to collection
|
||||
*
|
||||
* @param RequestInterface $request
|
||||
* @return $this
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
public function apply(RequestInterface $request)
|
||||
{
|
||||
if (!$this->pluginEnable()) {
|
||||
return parent::apply($request);
|
||||
}
|
||||
|
||||
$attributeValue = $request->getParam($this->getRequestVar());
|
||||
if (empty($attributeValue)) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$attributeValue = explode(',', $attributeValue);
|
||||
$this->setCurrentValue($attributeValue);
|
||||
|
||||
/** @var \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute */
|
||||
$attribute = $this->getAttributeModel();
|
||||
$id = $attribute->getAttributeId();
|
||||
|
||||
if (!$this->isMultiselect($id) && count($attributeValue) > 1) {
|
||||
$attributeValue = array_slice($attributeValue, 0, 1);
|
||||
}
|
||||
/** @var Collection $productCollection */
|
||||
$productCollection = $this->getProductCollection();
|
||||
|
||||
$productCollection->addFieldToFilter($attribute->getAttributeCode(), $attributeValue);
|
||||
|
||||
if ($this->shouldAddState($id)) {
|
||||
$this->addState($attributeValue);
|
||||
}
|
||||
if (!$this->isVisibleWhenSelected($id)) {
|
||||
$this->setItems([]); // set items to disable show filtering
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function pluginEnable()
|
||||
{
|
||||
return (bool)$this->_helper->isEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $attributeValues
|
||||
*/
|
||||
protected function setCurrentValue(array $attributeValues)
|
||||
{
|
||||
$this->attributeValues = $attributeValues;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @return bool
|
||||
* @noinspection PhpUnusedParameterInspection
|
||||
*/
|
||||
protected function isMultiselect($id)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Magento\Catalog\Model\ResourceModel\Product\Collection
|
||||
*/
|
||||
protected function getProductCollection()
|
||||
{
|
||||
return $this->getLayer()->getProductCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @return bool
|
||||
* @noinspection PhpUnusedParameterInspection
|
||||
*/
|
||||
public function shouldAddState($id)
|
||||
{
|
||||
return !$this->isBrandingBrand();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function isBrandingBrand()
|
||||
{
|
||||
if (
|
||||
class_exists('Amasty\ShopbyBrand\Helper\Content')
|
||||
&& $contentHelper = ObjectManager::getInstance()->get('Amasty\ShopbyBrand\Helper\Content')
|
||||
) {
|
||||
$brand = $contentHelper->getCurrentBranding();
|
||||
return $brand &&
|
||||
(FilterSetting::ATTR_PREFIX . $this->getRequestVar() ==
|
||||
$brand->getFilterCode());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $values
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
protected function addState($values)
|
||||
{
|
||||
$labels = [];
|
||||
foreach ((array)$values as $value) {
|
||||
$label = $this->getOptionText($value);
|
||||
$labels[$value] = $label;
|
||||
}
|
||||
foreach ($labels as $id => $label) {
|
||||
$item = $this->_createItem($label, $id);
|
||||
$this->getLayer()->getState()
|
||||
->addFilter(
|
||||
$item
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @return bool
|
||||
* @noinspection PhpUnusedParameterInspection
|
||||
*/
|
||||
public function isVisibleWhenSelected($id)
|
||||
{
|
||||
return !$this->isBrandingBrand();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $a
|
||||
* @param $b
|
||||
* @return int|mixed
|
||||
*/
|
||||
public function sortOption($a, $b)
|
||||
{
|
||||
$pattern = '@^(\d+)@';
|
||||
if (preg_match($pattern, $a['label'], $ma) && preg_match($pattern, $b['label'], $mb)) {
|
||||
$r = $ma[1] - $mb[1];
|
||||
if ($r != 0) {
|
||||
return $r;
|
||||
}
|
||||
}
|
||||
|
||||
return strcasecmp($a['label'], $b['label']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data array for building filter items
|
||||
*
|
||||
* Result array should have next structure:
|
||||
* array(
|
||||
* $index => array(
|
||||
* 'label' => $label,
|
||||
* 'value' => $value,
|
||||
* 'count' => $count
|
||||
* )
|
||||
* )
|
||||
*
|
||||
* @return array
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
protected function _getItemsData()
|
||||
{
|
||||
if (!$this->pluginEnable()) {
|
||||
return parent::_getItemsData();
|
||||
}
|
||||
$attribute = $this->getAttributeModel();
|
||||
if ($this->hasCurrentValue() && !$this->isVisibleWhenSelected($attribute->getAttributeId())) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$options = $this->getOptions();
|
||||
$optionsFacetedData = $this->getOptionsFacetedData();
|
||||
if (!$optionsFacetedData) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$this->addItemsToDataBuilder($options, $optionsFacetedData);
|
||||
$itemsData = $this->getItemsFromDataBuilder();
|
||||
|
||||
return $itemsData;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function hasCurrentValue()
|
||||
{
|
||||
return !empty($this->attributeValues);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
$attribute = $this->getAttributeModel();
|
||||
$options = $attribute->getFrontend()->getSelectOptions();
|
||||
|
||||
usort($options, [$this, 'sortOption']);
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
protected function getOptionsFacetedData()
|
||||
{
|
||||
$optionsFacetedData = $this->generateOptionsFacetedData();
|
||||
|
||||
if (count($optionsFacetedData)) {
|
||||
$optionsFacetedData = $this->convertOptionsFacetedData($optionsFacetedData);
|
||||
}
|
||||
|
||||
return $optionsFacetedData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @throws LocalizedException
|
||||
* @noinspection PhpRedundantCatchClauseInspection
|
||||
*/
|
||||
protected function generateOptionsFacetedData()
|
||||
{
|
||||
$productCollection = $this->getProductCollection();
|
||||
$attribute = $this->getAttributeModel();
|
||||
$attributeCode = $attribute->getAttributeCode();
|
||||
try {
|
||||
$optionsFacetedData = $productCollection->getFacetedData(
|
||||
$attributeCode,
|
||||
$this->getAlteredQueryResponse()
|
||||
);
|
||||
} catch (StateException $e) {
|
||||
if (!$this->messageManager->hasMessages()) {
|
||||
$this->messageManager->addErrorMessage(
|
||||
__('Make sure that "%1" attribute can be used in layered navigation', $attributeCode)
|
||||
);
|
||||
}
|
||||
$optionsFacetedData = [];
|
||||
}
|
||||
|
||||
return $optionsFacetedData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return QueryResponse|ResponseInterface|null
|
||||
*/
|
||||
protected function getAlteredQueryResponse()
|
||||
{
|
||||
$alteredQueryResponse = null;
|
||||
if ($this->hasCurrentValue()) {
|
||||
try {
|
||||
$requestBuilder = $this->getRequestBuilder();
|
||||
if (!$requestBuilder) {
|
||||
return $alteredQueryResponse;
|
||||
}
|
||||
$queryRequest = $requestBuilder->create();
|
||||
$alteredQueryResponse = $this->searchEngine->search($queryRequest);
|
||||
} catch (Exception $e) {
|
||||
$alteredQueryResponse = null;
|
||||
}
|
||||
}
|
||||
return $alteredQueryResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Builder|null
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
protected function getRequestBuilder()
|
||||
{
|
||||
$requestBuilder = $this->getMemRequestBuilder();
|
||||
if (!$requestBuilder) {
|
||||
return null;
|
||||
}
|
||||
$attributeCode = $this->getAttributeModel()->getAttributeCode();
|
||||
$requestBuilder->removePlaceholder($attributeCode);
|
||||
$requestBuilder->setAggregationsOnly($attributeCode);
|
||||
|
||||
return $requestBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Builder|null
|
||||
*/
|
||||
private function getMemRequestBuilder()
|
||||
{
|
||||
$productCollection = $this->getProductCollection();
|
||||
if (method_exists($productCollection, 'getMemRequestBuilder')) {
|
||||
return clone $productCollection->getMemRequestBuilder();
|
||||
}
|
||||
$this->_helper->_loadObject(LoggerInterface::class)
|
||||
->error(__('Invalid class for product collection: ') . get_class($productCollection));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $optionsFacetedData
|
||||
* @return array
|
||||
*/
|
||||
protected function convertOptionsFacetedData(array $optionsFacetedData)
|
||||
{
|
||||
$values = $this->getCurrentValue();
|
||||
foreach ($values as $value) {
|
||||
if (!empty($value) && !array_key_exists($value, $optionsFacetedData)) {
|
||||
$optionsFacetedData[$value] = [
|
||||
'value' => $value,
|
||||
'count' => 0,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $optionsFacetedData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function getCurrentValue()
|
||||
{
|
||||
return $this->attributeValues;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $options
|
||||
* @param array $optionsFacetedData
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
protected function addItemsToDataBuilder(array $options, array $optionsFacetedData)
|
||||
{
|
||||
if (!$options) {
|
||||
return;
|
||||
}
|
||||
foreach ($options as $option) {
|
||||
if (empty($option['value'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$isFilterableAttribute = $this->getAttributeIsFilterable($this->getAttributeModel());
|
||||
if (isset($optionsFacetedData[$option['value']])
|
||||
|| $isFilterableAttribute != static::ATTRIBUTE_OPTIONS_ONLY_WITH_RESULTS
|
||||
) {
|
||||
$count = 0;
|
||||
if (isset($optionsFacetedData[$option['value']]['count'])) {
|
||||
$count = $optionsFacetedData[$option['value']]['count'];
|
||||
}
|
||||
$this->itemDataBuilder->addItemData(
|
||||
$this->tagFilter->filter($option['label']),
|
||||
$option['value'],
|
||||
$count
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
private function getItemsFromDataBuilder()
|
||||
{
|
||||
$itemsData = $this->itemDataBuilder->build();
|
||||
if (count($itemsData) == 1
|
||||
&& !$this->isOptionReducesResults(
|
||||
$itemsData[0]['count'],
|
||||
$this->getLayer()->getProductCollection()->getSize()
|
||||
)
|
||||
) {
|
||||
$itemsData = $this->getReducedItemsData($itemsData);
|
||||
}
|
||||
|
||||
return $itemsData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $itemsData
|
||||
* @return array
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
protected function getReducedItemsData(array $itemsData)
|
||||
{
|
||||
$isFilterActive = false;
|
||||
/** @var Item $filter */
|
||||
foreach ($this->getLayer()->getState()->getFilters() as $filter) {
|
||||
|
||||
if ($filter->getFilter()->getRequestVar() == $this->getRequestVar()) {
|
||||
$isFilterActive = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $isFilterActive ? $itemsData : [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,521 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Olegnax
|
||||
* @package Olegnax_LayeredNavigation
|
||||
* @copyright Copyright (c) 2019 Olegnax (http://olegnax.com/). All rights reserved.
|
||||
* @license Proprietary License https://olegnax.com/license/
|
||||
*/
|
||||
|
||||
namespace Olegnax\LayeredNavigation\Model\Layer\Filter;
|
||||
|
||||
|
||||
use Exception;
|
||||
use Magento\Catalog\Api\CategoryRepositoryInterface;
|
||||
use Magento\Catalog\Model\Category as CategoryModel;
|
||||
use Magento\Catalog\Model\Layer;
|
||||
use Magento\Catalog\Model\Layer\Filter\DataProvider\CategoryFactory;
|
||||
use Magento\Catalog\Model\Layer\Filter\Item\DataBuilder;
|
||||
use Magento\Catalog\Model\Layer\Filter\ItemFactory;
|
||||
use Magento\Framework\App\RequestInterface;
|
||||
use Magento\Framework\Escaper;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\Exception\StateException;
|
||||
use Magento\Framework\Message\ManagerInterface;
|
||||
use Magento\Framework\Search\Response\QueryResponse;
|
||||
use Magento\Framework\Search\ResponseInterface;
|
||||
use Magento\Search\Model\SearchEngine;
|
||||
use Magento\Store\Api\Data\StoreInterface;
|
||||
use Magento\Store\Model\StoreManagerInterface;
|
||||
use Olegnax\LayeredNavigation\Helper\Helper;
|
||||
use Olegnax\LayeredNavigation\Model\Layer\Filter;
|
||||
use Olegnax\LayeredNavigation\Model\Request\Builder;
|
||||
use Olegnax\LayeredNavigation\Model\ResourceModel\Fulltext\Collection;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class Category extends \Magento\CatalogSearch\Model\Layer\Filter\Category
|
||||
{
|
||||
const FILTER_CODE = 'category';
|
||||
const ATTRIBUTE_CODE = 'category_ids';
|
||||
/**
|
||||
* @var Helper
|
||||
*/
|
||||
protected $_helper;
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $attributeValues;
|
||||
/**
|
||||
* @var mixed
|
||||
*/
|
||||
protected $currentId;
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $isSearch;
|
||||
/**
|
||||
* @var ManagerInterface
|
||||
*/
|
||||
protected $messageManager;
|
||||
/**
|
||||
* @var CategoryRepositoryInterface
|
||||
*/
|
||||
protected $categoryRepository;
|
||||
/**
|
||||
* @var SearchEngine
|
||||
*/
|
||||
protected $searchEngine;
|
||||
/**
|
||||
* @var Filter
|
||||
*/
|
||||
protected $layerFilter;
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $categorys = [];
|
||||
/**
|
||||
* @var CategoryModel
|
||||
*/
|
||||
protected $category;
|
||||
/**
|
||||
* @var StoreManagerInterface
|
||||
*/
|
||||
protected $storeManager;
|
||||
/**
|
||||
* @var Layer\Filter\DataProvider\Category
|
||||
*/
|
||||
private $dataProvider;
|
||||
/**
|
||||
* @var Escaper
|
||||
*/
|
||||
private $escaper;
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $maxDepth;
|
||||
|
||||
/**
|
||||
* Category constructor.
|
||||
* @param ItemFactory $filterItemFactory
|
||||
* @param StoreManagerInterface $storeManager
|
||||
* @param Layer $layer
|
||||
* @param DataBuilder $itemDataBuilder
|
||||
* @param Escaper $escaper
|
||||
* @param CategoryFactory $categoryDataProviderFactory
|
||||
* @param Helper $helper
|
||||
* @param SearchEngine $searchEngine
|
||||
* @param ManagerInterface $messageManager
|
||||
* @param Filter $layerFilter
|
||||
* @param CategoryModel $category
|
||||
* @param array $data
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
public function __construct(
|
||||
ItemFactory $filterItemFactory,
|
||||
StoreManagerInterface $storeManager,
|
||||
Layer $layer,
|
||||
DataBuilder $itemDataBuilder,
|
||||
Escaper $escaper,
|
||||
CategoryFactory $categoryDataProviderFactory,
|
||||
Helper $helper,
|
||||
SearchEngine $searchEngine,
|
||||
ManagerInterface $messageManager,
|
||||
Filter $layerFilter,
|
||||
CategoryModel $category,
|
||||
array $data = []
|
||||
) {
|
||||
parent::__construct(
|
||||
$filterItemFactory,
|
||||
$storeManager,
|
||||
$layer,
|
||||
$itemDataBuilder,
|
||||
$escaper,
|
||||
$categoryDataProviderFactory,
|
||||
$data
|
||||
);
|
||||
$this->storeManager = $storeManager;
|
||||
$this->_helper = $helper;
|
||||
$this->dataProvider = $categoryDataProviderFactory->create(['layer' => $this->getLayer()]);
|
||||
$this->searchEngine = $searchEngine;
|
||||
$this->messageManager = $messageManager;
|
||||
$this->escaper = $escaper;
|
||||
$this->layerFilter = $layerFilter;
|
||||
$this->category = $category;
|
||||
}
|
||||
|
||||
public function getMaxDepth()
|
||||
{
|
||||
if (null == $this->maxDepth) {
|
||||
$this->maxDepth = abs((int)$this->_helper->getModuleConfig('category/depth'));
|
||||
}
|
||||
return $this->maxDepth;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RequestInterface $request
|
||||
* @return $this|Category
|
||||
* @noinspection PhpDeprecationInspection
|
||||
*/
|
||||
public function apply(RequestInterface $request)
|
||||
{
|
||||
if (!$this->pluginEnable()) {
|
||||
return parent::apply($request);
|
||||
}
|
||||
$this->currentId = $request->getParam('id');
|
||||
$this->isSearch = (bool)$request->getParam('q');
|
||||
$categoryId = $request->getParam($this->_requestVar) ?: $this->currentId;
|
||||
if (empty($categoryId)) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$categoryIds = explode(',', $categoryId);
|
||||
$categoryIds = array_unique($categoryIds);
|
||||
$this->setCurrentValue($categoryIds);
|
||||
|
||||
/** @var Collection $productCollection */
|
||||
$productCollection = $this->getProductCollection();
|
||||
if ($this->isMultiselect() && count($categoryIds) > 1) {
|
||||
$productCollection->addIndexCategoriesFilter(['in' => $categoryIds]);
|
||||
$category = $this->getLayer()->getCurrentCategory();
|
||||
$child = $category->getCollection()
|
||||
->addFieldToFilter($category->getIdFieldName(), ['in' => $categoryIds])
|
||||
->addAttributeToSelect('name');
|
||||
if ($this->shouldAddState()) {
|
||||
$this->addState($categoryIds, $child);
|
||||
}
|
||||
} else {
|
||||
$this->dataProvider->setCategoryId($categoryId);
|
||||
$productCollection->addCategoryFilter($this->dataProvider->getCategory());
|
||||
if ($this->shouldAddState()) {
|
||||
$this->addState();
|
||||
}
|
||||
}
|
||||
|
||||
if (!$this->shouldVisible()) {
|
||||
$this->setItems([]); // set items to disable show filtering
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function pluginEnable()
|
||||
{
|
||||
return (bool)$this->_helper->isEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $attributeValues
|
||||
*/
|
||||
protected function setCurrentValue(array $attributeValues)
|
||||
{
|
||||
$this->attributeValues = $attributeValues;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Magento\Catalog\Model\ResourceModel\Product\Collection
|
||||
*/
|
||||
protected function getProductCollection()
|
||||
{
|
||||
return $this->getLayer()->getProductCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function isMultiselect()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function shouldAddState()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $values
|
||||
* @param null $child
|
||||
*/
|
||||
protected function addState($values = [], $child = null)
|
||||
{
|
||||
if ($child) {
|
||||
$labels = [];
|
||||
foreach ((array)$values as $value) {
|
||||
if ($currentCategory = $child->getItemById($value)) {
|
||||
$labels[$currentCategory->getId()] = $currentCategory->getName();
|
||||
}
|
||||
}
|
||||
foreach ($labels as $id => $categoryName) {
|
||||
$state = $this->_createItem($categoryName, $id);
|
||||
$this->getLayer()->getState()->addFilter($state);
|
||||
}
|
||||
} else {
|
||||
$category = $this->dataProvider->getCategory();
|
||||
if ($this->getCurrentCategoryId() != $category->getId() && $this->dataProvider->isValid()) {
|
||||
$state = $this->_createItem($category->getName(), $category->getId());
|
||||
$this->getLayer()->getState()->addFilter($state);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function getCurrentCategoryId()
|
||||
{
|
||||
return $this->currentId ?: $this->getStore()->getRootCategoryId(); //$this->getRootCategory()->getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return StoreInterface
|
||||
* @throws NoSuchEntityException
|
||||
*/
|
||||
private function getStore()
|
||||
{
|
||||
return $this->storeManager->getStore();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function shouldVisible()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function _getItemsData()
|
||||
{
|
||||
if (!$this->pluginEnable()) {
|
||||
return parent::_getItemsData();
|
||||
}
|
||||
|
||||
$optionsFacetedData = $this->getOptionsFacetedData();
|
||||
$this->dataProvider->setCategoryId($this->getCurrentCategoryId());
|
||||
$categories = $this->getCategoryTree($this->dataProvider->getCategory());
|
||||
foreach ($categories as $key => $category) {
|
||||
if (isset($optionsFacetedData[$key])) {
|
||||
$categories[$key]['count'] = $optionsFacetedData[$key]['count'];
|
||||
$path = explode('/', $category['path']);
|
||||
foreach ($path as $id) {
|
||||
if (array_key_exists($id, $categories)) {
|
||||
$categories[$id]['use'] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$categories = array_filter($categories, [$this, 'filterCategory']);
|
||||
|
||||
return $categories;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize filter items
|
||||
*
|
||||
* @return \Magento\Catalog\Model\Layer\Filter\AbstractFilter
|
||||
*/
|
||||
protected function _initItems()
|
||||
{
|
||||
$data = $this->_getItemsData();
|
||||
$items = [];
|
||||
foreach ($data as $itemData) {
|
||||
$items[] = $this->_createItem(
|
||||
$itemData['label'],
|
||||
$itemData['value'],
|
||||
$itemData['count']
|
||||
)
|
||||
->setData('item_level', isset($itemData['item_level']) ? $itemData['item_level'] : 0)
|
||||
->setData('path', isset($itemData['path']) ? $itemData['path'] : '');
|
||||
}
|
||||
$this->_items = $items;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function getOptionsFacetedData()
|
||||
{
|
||||
return $this->generateOptionsFacetedData();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @noinspection PhpRedundantCatchClauseInspection
|
||||
*/
|
||||
protected function generateOptionsFacetedData()
|
||||
{
|
||||
$productCollection = $this->getProductCollection();
|
||||
$attributeCode = static::FILTER_CODE;
|
||||
try {
|
||||
$optionsFacetedData = $productCollection->getFacetedData(
|
||||
$attributeCode,
|
||||
$this->getAlteredQueryResponse()
|
||||
);
|
||||
} catch (StateException $e) {
|
||||
if (!$this->messageManager->hasMessages()) {
|
||||
$this->messageManager->addErrorMessage(
|
||||
__('Make sure that "%1" attribute can be used in layered navigation', $attributeCode)
|
||||
);
|
||||
}
|
||||
$optionsFacetedData = [];
|
||||
}
|
||||
|
||||
return $optionsFacetedData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return QueryResponse|ResponseInterface|null
|
||||
*/
|
||||
protected function getAlteredQueryResponse()
|
||||
{
|
||||
$alteredQueryResponse = null;
|
||||
$categoryIds = $this->getCurrentValue();
|
||||
$categoryId = !empty($categoryIds) ? $categoryIds[0] : null;
|
||||
if ($this->hasCurrentValue() && $categoryId != $this->getCurrentCategoryId()) {
|
||||
try {
|
||||
$requestBuilder = $this->getRequestBuilder();
|
||||
if (!$requestBuilder) {
|
||||
return $alteredQueryResponse;
|
||||
}
|
||||
$queryRequest = $requestBuilder->create();
|
||||
$alteredQueryResponse = $this->searchEngine->search($queryRequest);
|
||||
} catch (Exception $e) {
|
||||
$alteredQueryResponse = null;
|
||||
}
|
||||
}
|
||||
return $alteredQueryResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function getCurrentValue()
|
||||
{
|
||||
return $this->attributeValues;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function hasCurrentValue()
|
||||
{
|
||||
return !empty($this->attributeValues);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Builder|null
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
protected function getRequestBuilder()
|
||||
{
|
||||
$requestBuilder = $this->getMemRequestBuilder();
|
||||
if (!$requestBuilder) {
|
||||
return null;
|
||||
}
|
||||
$attributeCode = static::ATTRIBUTE_CODE;
|
||||
$requestBuilder->removePlaceholder($attributeCode);
|
||||
$requestBuilder->bind($attributeCode, $this->getCurrentCategoryId());
|
||||
$requestBuilder->setAggregationsOnly($attributeCode);
|
||||
|
||||
return $requestBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Builder|null
|
||||
*/
|
||||
private function getMemRequestBuilder()
|
||||
{
|
||||
$productCollection = $this->getProductCollection();
|
||||
if (method_exists($productCollection, 'getMemRequestBuilder')) {
|
||||
return clone $productCollection->getMemRequestBuilder();
|
||||
}
|
||||
$this->_helper->_loadObject(LoggerInterface::class)
|
||||
->error(__('Invalid class for product collection: ') . get_class($productCollection));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CategoryModel $category
|
||||
* @param int $level
|
||||
* @return array
|
||||
*/
|
||||
private function getCategoryTree($category, $level = 0)
|
||||
{
|
||||
$result = [];
|
||||
if ($category->getIsActive()) {
|
||||
$categories = $category->getChildrenCategories();
|
||||
foreach ($categories as $category) {
|
||||
if ($category->getIsActive()) {
|
||||
$id = $category->getId();
|
||||
$result[$id] = [
|
||||
'label' => $this->escaper->escapeHtml($category->getName()),
|
||||
'value' => $id,
|
||||
'item_level' => $level,
|
||||
'path' => $category->getPath(),
|
||||
'count' => 0,
|
||||
];
|
||||
if ($this->getMaxDepth() > $level) {
|
||||
$subItem = $this->getCategoryTree($category, $level + 1);
|
||||
foreach ($subItem as $key => $item) {
|
||||
$result[$key] = $item;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $item
|
||||
* @return bool
|
||||
*/
|
||||
public function filterCategory($item)
|
||||
{
|
||||
return is_array($item) && array_key_exists('use', $item);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $filterItem
|
||||
* @return bool
|
||||
*/
|
||||
public function getIsDisableAjax($filterItem)
|
||||
{
|
||||
$categoryItem = $this->getCategoryItem($filterItem);
|
||||
return $categoryItem->getData('ox_nav_disable_ajax') || !$categoryItem->getIsAnchor();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $filterItem
|
||||
* @return mixed
|
||||
*/
|
||||
private function getCategoryItem($filterItem)
|
||||
{
|
||||
$value = $filterItem->getValue();
|
||||
if (!array_key_exists($value, $this->categorys)) {
|
||||
$category = clone $this->category;
|
||||
$this->categorys[$value] = $category->load($value);
|
||||
}
|
||||
|
||||
return $this->categorys[$value];
|
||||
}
|
||||
|
||||
/** @noinspection PhpDeprecationInspection */
|
||||
|
||||
/**
|
||||
* @param $filterItem
|
||||
* @return mixed
|
||||
*/
|
||||
public function getUrlItem($filterItem)
|
||||
{
|
||||
return $this->getCategoryItem($filterItem)->getUrl();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,488 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Olegnax
|
||||
* @package Olegnax_LayeredNavigation
|
||||
* @copyright Copyright (c) 2019 Olegnax (http://olegnax.com/). All rights reserved.
|
||||
* @license Proprietary License https://olegnax.com/license/
|
||||
*/
|
||||
|
||||
namespace Olegnax\LayeredNavigation\Model\Layer\Filter;
|
||||
|
||||
use Exception;
|
||||
use Magento\Catalog\Model\Layer;
|
||||
use Magento\Catalog\Model\Layer\Filter\DataProvider\PriceFactory;
|
||||
use Magento\Catalog\Model\Layer\Filter\Dynamic\AlgorithmFactory;
|
||||
use Magento\Catalog\Model\Layer\Filter\Item\DataBuilder;
|
||||
use Magento\Catalog\Model\Layer\Filter\ItemFactory;
|
||||
use Magento\Catalog\Model\ResourceModel\Product\Collection;
|
||||
use Magento\Customer\Model\Session;
|
||||
use Magento\Directory\Model\Currency;
|
||||
use Magento\Framework\App\Config\ScopeConfigInterface;
|
||||
use Magento\Framework\App\RequestInterface;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\Exception\StateException;
|
||||
use Magento\Framework\Message\ManagerInterface;
|
||||
use Magento\Framework\Pricing\PriceCurrencyInterface;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\Framework\Search\Dynamic\Algorithm;
|
||||
use Magento\Framework\Search\Response\QueryResponse;
|
||||
use Magento\Framework\Search\ResponseInterface;
|
||||
use Magento\Framework\Serialize\Serializer\Json;
|
||||
use Magento\Search\Model\SearchEngine;
|
||||
use Magento\Store\Model\Store;
|
||||
use Magento\Store\Model\StoreManagerInterface;
|
||||
use Olegnax\LayeredNavigation\Helper\Helper;
|
||||
use Olegnax\LayeredNavigation\Model\Request\Builder;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class Price extends \Magento\CatalogSearch\Model\Layer\Filter\Price
|
||||
{
|
||||
|
||||
/**
|
||||
* @var Helper
|
||||
*/
|
||||
protected $_helper;
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $attributeValues = [];
|
||||
/**
|
||||
* @var Registry
|
||||
*/
|
||||
protected $coreRegistry;
|
||||
/**
|
||||
* @var ManagerInterface
|
||||
*/
|
||||
protected $messageManager;
|
||||
/**
|
||||
* @var SearchEngine
|
||||
*/
|
||||
protected $searchEngine;
|
||||
/**
|
||||
* @var ScopeConfigInterface
|
||||
*/
|
||||
protected $scopeConfig;
|
||||
/**
|
||||
* @var Json
|
||||
*/
|
||||
protected $json;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $currencySymbol;
|
||||
/**
|
||||
* @var Layer\Filter\DataProvider\Price
|
||||
*/
|
||||
private $dataProvider;
|
||||
|
||||
/**
|
||||
* Price constructor.
|
||||
* @param ItemFactory $filterItemFactory
|
||||
* @param StoreManagerInterface $storeManager
|
||||
* @param Layer $layer
|
||||
* @param DataBuilder $itemDataBuilder
|
||||
* @param \Magento\Catalog\Model\ResourceModel\Layer\Filter\Price $resource
|
||||
* @param Session $customerSession
|
||||
* @param Algorithm $priceAlgorithm
|
||||
* @param PriceCurrencyInterface $priceCurrency
|
||||
* @param AlgorithmFactory $algorithmFactory
|
||||
* @param PriceFactory $dataProviderFactory
|
||||
* @param Helper $helper
|
||||
* @param Registry $coreRegistry
|
||||
* @param SearchEngine $searchEngine
|
||||
* @param ManagerInterface $messageManager
|
||||
* @param ScopeConfigInterface $scopeConfig
|
||||
* @param Json $json
|
||||
* @param array $data
|
||||
* @noinspection PhpDeprecationInspection
|
||||
*/
|
||||
public function __construct(
|
||||
ItemFactory $filterItemFactory,
|
||||
StoreManagerInterface $storeManager,
|
||||
Layer $layer,
|
||||
DataBuilder $itemDataBuilder,
|
||||
\Magento\Catalog\Model\ResourceModel\Layer\Filter\Price $resource,
|
||||
Session $customerSession,
|
||||
Algorithm $priceAlgorithm,
|
||||
PriceCurrencyInterface $priceCurrency,
|
||||
AlgorithmFactory $algorithmFactory,
|
||||
PriceFactory $dataProviderFactory,
|
||||
Helper $helper,
|
||||
Registry $coreRegistry,
|
||||
SearchEngine $searchEngine,
|
||||
ManagerInterface $messageManager,
|
||||
ScopeConfigInterface $scopeConfig,
|
||||
Json $json,
|
||||
array $data = []
|
||||
) {
|
||||
parent::__construct(
|
||||
$filterItemFactory,
|
||||
$storeManager,
|
||||
$layer,
|
||||
$itemDataBuilder,
|
||||
$resource,
|
||||
$customerSession,
|
||||
$priceAlgorithm,
|
||||
$priceCurrency,
|
||||
$algorithmFactory,
|
||||
$dataProviderFactory,
|
||||
$data
|
||||
);
|
||||
$this->_helper = $helper;
|
||||
$this->dataProvider = $dataProviderFactory->create(['layer' => $layer]);
|
||||
$this->coreRegistry = $coreRegistry;
|
||||
$this->searchEngine = $searchEngine;
|
||||
$this->messageManager = $messageManager;
|
||||
$this->scopeConfig = $scopeConfig;
|
||||
$this->json = $json;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RequestInterface $request
|
||||
* @return $this|Price
|
||||
*/
|
||||
public function apply(RequestInterface $request)
|
||||
{
|
||||
if (!$this->pluginEnable()) {
|
||||
return parent::apply($request);
|
||||
}
|
||||
|
||||
$filter = $request->getParam($this->getRequestVar());
|
||||
if (empty($filter)) {
|
||||
return $this;
|
||||
}
|
||||
if (is_string($filter)) {
|
||||
$filter = explode(',', $filter);
|
||||
}
|
||||
$filterParams = $filter;
|
||||
|
||||
$filter = $this->dataProvider->validateFilter($filterParams[0]);
|
||||
if (!$filter) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$this->setCurrentValue($filter);
|
||||
$this->dataProvider->setInterval($filter);
|
||||
$priorFilters = $this->dataProvider->getPriorFilters($filterParams);
|
||||
if ($priorFilters) {
|
||||
$this->dataProvider->setPriorIntervals($priorFilters);
|
||||
}
|
||||
|
||||
[$from, $to] = $filter;
|
||||
|
||||
$this->getProductCollection()->addFieldToFilter(
|
||||
'price',
|
||||
[
|
||||
'from' => $from,
|
||||
'to' => $to,
|
||||
]
|
||||
);
|
||||
if ($this->shouldAddState()) {
|
||||
$this->addState($filter);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function pluginEnable()
|
||||
{
|
||||
return (bool)$this->_helper->isEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $attributeValues
|
||||
*/
|
||||
protected function setCurrentValue(array $attributeValues)
|
||||
{
|
||||
$this->attributeValues = $attributeValues;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
protected function getProductCollection()
|
||||
{
|
||||
return $this->getLayer()->getProductCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function shouldAddState()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $values
|
||||
*/
|
||||
protected function addState($values)
|
||||
{
|
||||
[$from, $to] = $values;
|
||||
$label = $this->_renderRangeLabel(empty($from) ? 0 : $from, $to);
|
||||
$item = $this->_createItem($label, $values);
|
||||
$this->getLayer()->getState()
|
||||
->addFilter(
|
||||
$item
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function getIsSlider()
|
||||
{
|
||||
return $this->pluginEnable() && $this->_helper->isPriceSlider();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool|false|string
|
||||
* @throws LocalizedException
|
||||
* @throws NoSuchEntityException
|
||||
*/
|
||||
public function getSliderConfig()
|
||||
{
|
||||
/** @var Collection $productCollection */
|
||||
$productCollection = $this->getProductCollection();
|
||||
$format = explode('%s', $this->getOutputFormat());
|
||||
if (2 != count($format)) {
|
||||
$format = [
|
||||
$this->getCurrencySymbol(),
|
||||
''
|
||||
];
|
||||
}
|
||||
$config = [
|
||||
"min" => $productCollection->getMinPrice(),
|
||||
"max" => $productCollection->getMaxPrice(),
|
||||
"step" => 1,
|
||||
"formatMoney" => [
|
||||
"prefix" => $format[0] ?: '',
|
||||
"suffix" => $format[1] ?: '',
|
||||
],
|
||||
];
|
||||
|
||||
return $this->json->serialize($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @throws LocalizedException
|
||||
* @throws NoSuchEntityException
|
||||
*/
|
||||
public function getCurrencySymbol()
|
||||
{
|
||||
if (empty($this->currencySymbol)) {
|
||||
$this->currencySymbol = $this->getCurrentCurrency()->getCurrencySymbol();
|
||||
}
|
||||
|
||||
return $this->currencySymbol;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Currency
|
||||
* @throws LocalizedException
|
||||
* @throws NoSuchEntityException
|
||||
*/
|
||||
public function getCurrentCurrency()
|
||||
{
|
||||
/** @var Store $store */
|
||||
$store = $this->_storeManager->getStore();
|
||||
/** @var Currency $currentCurrency */
|
||||
$currentCurrency = $store->getCurrentCurrency();
|
||||
return $currentCurrency;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @throws LocalizedException
|
||||
* @throws NoSuchEntityException
|
||||
*/
|
||||
public function getOutputFormat()
|
||||
{
|
||||
return $this->getCurrentCurrency()->getOutputFormat();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function getCurrentValue()
|
||||
{
|
||||
return $this->attributeValues;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
protected function _getItemsData()
|
||||
{
|
||||
if (!$this->_helper->isEnabled()) {
|
||||
return parent::_getItemsData();
|
||||
}
|
||||
|
||||
if ($this->hasCurrentValue() && !$this->shouldVisible()) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$facets = $this->getFacetedData();
|
||||
|
||||
$data = [];
|
||||
if (count($facets) > 1) { // two range minimum
|
||||
$lastFacet = array_key_last($facets);
|
||||
foreach ($facets as $key => $aggregation) {
|
||||
$count = $aggregation['count'];
|
||||
if (strpos($key, '_') === false) {
|
||||
continue;
|
||||
}
|
||||
$isLast = $lastFacet === $key;
|
||||
$data[] = $this->prepareData($key, $count, $isLast);
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function hasCurrentValue()
|
||||
{
|
||||
return !empty($this->attributeValues);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function shouldVisible()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @throws LocalizedException
|
||||
* @noinspection PhpDeprecationInspection
|
||||
*/
|
||||
protected function getFacetedData()
|
||||
{
|
||||
$key = 'facet_price_' . $this->getRequestVar();
|
||||
if ($this->coreRegistry->registry($key) === null) {
|
||||
$this->coreRegistry->register($key, $this->generateFacetedData());
|
||||
}
|
||||
|
||||
return $this->coreRegistry->registry($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @throws LocalizedException
|
||||
* @noinspection PhpRedundantCatchClauseInspection
|
||||
*/
|
||||
protected function generateFacetedData()
|
||||
{
|
||||
$productCollection = $this->getProductCollection();
|
||||
$attribute = $this->getAttributeModel();
|
||||
$attributeCode = $attribute->getAttributeCode();
|
||||
try {
|
||||
$facetedData = $productCollection->getFacetedData(
|
||||
$attributeCode,
|
||||
$this->getAlteredQueryResponse()
|
||||
);
|
||||
} catch (StateException $e) {
|
||||
if (!$this->messageManager->hasMessages()) {
|
||||
$this->messageManager->addErrorMessage(
|
||||
__('Make sure that "%1" attribute can be used in layered navigation', $attributeCode)
|
||||
);
|
||||
}
|
||||
$facetedData = [];
|
||||
}
|
||||
|
||||
return $facetedData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return QueryResponse|ResponseInterface|null
|
||||
*/
|
||||
protected function getAlteredQueryResponse()
|
||||
{
|
||||
$alteredQueryResponse = null;
|
||||
if ($this->hasCurrentValue() &&
|
||||
$this->scopeConfig->getValue(AlgorithmFactory::XML_PATH_RANGE_CALCULATION) !=
|
||||
AlgorithmFactory::RANGE_CALCULATION_IMPROVED) {
|
||||
try {
|
||||
$requestBuilder = $this->getRequestBuilder();
|
||||
if (!$requestBuilder) {
|
||||
return $alteredQueryResponse;
|
||||
}
|
||||
$queryRequest = $requestBuilder->create();
|
||||
$alteredQueryResponse = $this->searchEngine->search($queryRequest);
|
||||
} catch (Exception $e) {
|
||||
$alteredQueryResponse = null;
|
||||
}
|
||||
}
|
||||
return $alteredQueryResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Builder|null
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
protected function getRequestBuilder()
|
||||
{
|
||||
$requestBuilder = $this->getMemRequestBuilder();
|
||||
if (!$requestBuilder) {
|
||||
return null;
|
||||
}
|
||||
$attributeCode = $this->getAttributeModel()->getAttributeCode();
|
||||
$requestBuilder->removePlaceholder($attributeCode . '.from');
|
||||
$requestBuilder->removePlaceholder($attributeCode . '.to');
|
||||
$requestBuilder->setAggregationsOnly($attributeCode);
|
||||
|
||||
return $requestBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Builder|null
|
||||
*/
|
||||
private function getMemRequestBuilder()
|
||||
{
|
||||
$productCollection = $this->getProductCollection();
|
||||
if (method_exists($productCollection, 'getMemRequestBuilder')) {
|
||||
return clone $productCollection->getMemRequestBuilder();
|
||||
}
|
||||
$this->_helper->_loadObject(LoggerInterface::class)
|
||||
->error(__('Invalid class for product collection: ') . get_class($productCollection));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @param int $count
|
||||
* @return array
|
||||
*/
|
||||
private function prepareData($key, $count, $isLast = false)
|
||||
{
|
||||
[$from, $to] = explode('_', $key);
|
||||
$label = $this->_renderRangeLabel(
|
||||
empty($from) ? 0 : $from * $this->getCurrencyRate(), // @todo may need to be removed * $this->getCurrencyRate()
|
||||
$to * $this->getCurrencyRate(), // @todo may need to be removed * $this->getCurrencyRate()
|
||||
$isLast
|
||||
);
|
||||
$value = $from . '-' . $to . $this->dataProvider->getAdditionalRequestData();
|
||||
|
||||
$data = [
|
||||
'label' => $label,
|
||||
'value' => $value,
|
||||
'count' => $count,
|
||||
'from' => $from,
|
||||
'to' => $to,
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,184 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Olegnax
|
||||
* @package Olegnax_LayeredNavigation
|
||||
* @copyright Copyright (c) 2019 Olegnax (http://olegnax.com/). All rights reserved.
|
||||
* @license Proprietary License https://olegnax.com/license/
|
||||
*/
|
||||
|
||||
namespace Olegnax\LayeredNavigation\Model\Request;
|
||||
|
||||
|
||||
use Magento\Framework\App\Request\Http;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Framework\Search\Request\Binder;
|
||||
use Magento\Framework\Search\Request\Cleaner;
|
||||
use Magento\Framework\Search\Request\Config;
|
||||
use Magento\Framework\Search\RequestInterface;
|
||||
use ReflectionClass;
|
||||
|
||||
class Builder extends \Magento\Framework\Search\Request\Builder
|
||||
{
|
||||
/**
|
||||
* @var Http
|
||||
*/
|
||||
protected $requestHttp;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $dataPlaceholders = [];
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $baseCategory;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $aggregationsOnly = [];
|
||||
|
||||
public function __construct(
|
||||
ObjectManagerInterface $objectManager,
|
||||
Config $config,
|
||||
Binder $binder,
|
||||
Cleaner $cleaner,
|
||||
Http $requestHttp
|
||||
) {
|
||||
$this->requestHttp = $requestHttp;
|
||||
parent::__construct($objectManager, $config, $binder, $cleaner);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $placeholder
|
||||
* @param mixed $value
|
||||
* @return Builder
|
||||
*/
|
||||
public function bind($placeholder, $value)
|
||||
{
|
||||
$this->dataPlaceholders[$placeholder] = $placeholder == 'category_ids'
|
||||
? $this->getPlaceholderCategory($placeholder, $value)
|
||||
: $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $placeholder
|
||||
* @param $value
|
||||
* @return array
|
||||
*/
|
||||
public function getPlaceholderCategory($placeholder, $value)
|
||||
{
|
||||
if (!$this->baseCategory) {
|
||||
$this->baseCategory = $this->requestHttp->getParam('id') ?: $value;
|
||||
}
|
||||
|
||||
if (isset($this->dataPlaceholders[$placeholder])
|
||||
&& $this->dataPlaceholders[$placeholder] !== $value) {
|
||||
$value = $this->getPlaceholderCategoryList($this->dataPlaceholders[$placeholder], $value);
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $placeholders
|
||||
* @param $value
|
||||
* @return array
|
||||
*/
|
||||
public function getPlaceholderCategoryList($placeholders, $value)
|
||||
{
|
||||
$placeholders = array_merge((array)$placeholders, (array)$value);
|
||||
$placeholders = array_unique($placeholders);
|
||||
$placeholders = array_diff($placeholders, (array)$this->baseCategory);
|
||||
$placeholders = array_values($placeholders);
|
||||
|
||||
return $placeholders;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return RequestInterface
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$this->applyPlaceholders();
|
||||
$request = parent::create();
|
||||
$this->removeAggregations($request);
|
||||
return $request;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
protected function applyPlaceholders()
|
||||
{
|
||||
foreach ($this->dataPlaceholders as $key => $value) {
|
||||
parent::bind($key, $value);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $request
|
||||
* @return $this
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
private function removeAggregations($request)
|
||||
{
|
||||
if (!empty($this->aggregationsOnly)) {
|
||||
$buckets = $request->getAggregation();
|
||||
foreach ($buckets as $key => $bucket) {
|
||||
if (!in_array($bucket->getField(), $this->aggregationsOnly)) {
|
||||
unset($buckets[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
$reflection = new ReflectionClass($request);
|
||||
$bucketProperty = $reflection->getProperty('buckets');
|
||||
$bucketProperty->setAccessible(true);
|
||||
$bucketProperty->setValue($request, $buckets);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $code
|
||||
* @return $this
|
||||
*/
|
||||
public function setAggregationsOnly($code)
|
||||
{
|
||||
if (!is_array($code)) {
|
||||
$code = [$code];
|
||||
}
|
||||
$this->aggregationsOnly = $code;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $placeholder
|
||||
* @return $this
|
||||
*/
|
||||
public function removePlaceholder($placeholder)
|
||||
{
|
||||
if (array_key_exists($placeholder, $this->dataPlaceholders)) {
|
||||
unset($this->dataPlaceholders[$placeholder]);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $placeholder
|
||||
* @return bool
|
||||
*/
|
||||
public function hasPlaceholder($placeholder)
|
||||
{
|
||||
return array_key_exists($placeholder, $this->dataPlaceholders);
|
||||
}
|
||||
|
||||
}
|
||||
+478
@@ -0,0 +1,478 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Olegnax
|
||||
* @package Olegnax_LayeredNavigation
|
||||
* @copyright Copyright (c) 2019 Olegnax (http://olegnax.com/). All rights reserved.
|
||||
* @license Proprietary License https://olegnax.com/license/
|
||||
*/
|
||||
|
||||
namespace Olegnax\LayeredNavigation\Model\ResourceModel\Fulltext;
|
||||
|
||||
use Magento\Catalog\Model\Category;
|
||||
use Magento\Catalog\Model\Indexer\Product\Flat\State;
|
||||
use Magento\Catalog\Model\Layer\Filter\Dynamic\AlgorithmFactory;
|
||||
use Magento\Catalog\Model\Product\OptionFactory;
|
||||
use Magento\Catalog\Model\ResourceModel\Helper;
|
||||
use Magento\Catalog\Model\ResourceModel\Url;
|
||||
use Magento\CatalogInventory\Helper\Stock;
|
||||
use Magento\Customer\Api\GroupManagementInterface;
|
||||
use Magento\Customer\Model\Session;
|
||||
use Magento\Eav\Model\Config;
|
||||
use Magento\Eav\Model\EntityFactory;
|
||||
use Magento\Framework\App\Config\ScopeConfigInterface;
|
||||
use Magento\Framework\App\ProductMetadataInterface;
|
||||
use Magento\Framework\App\ResourceConnection;
|
||||
use Magento\Framework\Data\Collection\Db\FetchStrategyInterface;
|
||||
use Magento\Framework\DB\Select;
|
||||
use Magento\Framework\Event\ManagerInterface;
|
||||
use Magento\Framework\Exception\StateException;
|
||||
use Magento\Framework\Module\Manager;
|
||||
use Magento\Framework\Phrase;
|
||||
use Magento\Framework\Search\Adapter\Mysql\TemporaryStorage;
|
||||
use Magento\Framework\Search\Adapter\Mysql\TemporaryStorageFactory;
|
||||
use Magento\Framework\Search\Response\QueryResponse;
|
||||
use Magento\Framework\Stdlib\DateTime;
|
||||
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
|
||||
use Magento\Framework\Validator\UniversalFactory;
|
||||
use Magento\Search\Model\QueryFactory;
|
||||
use Magento\Search\Model\SearchEngine;
|
||||
use Magento\Store\Model\ScopeInterface;
|
||||
use Magento\Store\Model\StoreManagerInterface;
|
||||
use Olegnax\LayeredNavigation\Model\Request\Builder;
|
||||
use Olegnax\LayeredNavigation\Model\Request\BuilderFactory;
|
||||
//use Magento\Framework\Search\Request\Builder;
|
||||
//use Magento\Framework\Search\Request\BuilderFactory;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* Fulltext Collection
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class Collection extends \Magento\Catalog\Model\ResourceModel\Product\Collection
|
||||
{
|
||||
/**
|
||||
* @var QueryResponse
|
||||
*/
|
||||
private $queryResponse;
|
||||
|
||||
/**
|
||||
* Catalog search data
|
||||
*
|
||||
* @var QueryFactory
|
||||
*/
|
||||
private $queryFactory = null;
|
||||
|
||||
/**
|
||||
* @var Builder
|
||||
*/
|
||||
private $requestBuilder;
|
||||
|
||||
/**
|
||||
* @var SearchEngine
|
||||
*/
|
||||
private $searchEngine;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $queryText;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $relevanceOrderDirection;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $searchRequestName;
|
||||
|
||||
/**
|
||||
* @var TemporaryStorageFactory
|
||||
*/
|
||||
private $temporaryStorageFactory;
|
||||
|
||||
/**
|
||||
* @var Stock
|
||||
*/
|
||||
private $stockHelper;
|
||||
|
||||
/**
|
||||
* @var Builder
|
||||
*/
|
||||
private $memRequestBuilder;
|
||||
|
||||
/**
|
||||
* @var ProductMetadataInterface
|
||||
*/
|
||||
private $productMetadata;
|
||||
|
||||
/**
|
||||
* Collection constructor.
|
||||
* @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory
|
||||
* @param LoggerInterface $logger
|
||||
* @param FetchStrategyInterface $fetchStrategy
|
||||
* @param ManagerInterface $eventManager
|
||||
* @param Config $eavConfig
|
||||
* @param ResourceConnection $resource
|
||||
* @param EntityFactory $eavEntityFactory
|
||||
* @param Helper $resourceHelper
|
||||
* @param UniversalFactory $universalFactory
|
||||
* @param StoreManagerInterface $storeManager
|
||||
* @param Manager $moduleManager
|
||||
* @param State $catalogProductFlatState
|
||||
* @param ScopeConfigInterface $scopeConfig
|
||||
* @param OptionFactory $productOptionFactory
|
||||
* @param Url $catalogUrl
|
||||
* @param TimezoneInterface $localeDate
|
||||
* @param Session $customerSession
|
||||
* @param DateTime $dateTime
|
||||
* @param GroupManagementInterface $groupManagement
|
||||
* @param QueryFactory $queryFactory
|
||||
* @param BuilderFactory $requestBuilderFactory
|
||||
* @param SearchEngine $searchEngine
|
||||
* @param TemporaryStorageFactory $temporaryStorageFactory
|
||||
* @param ProductMetadataInterface $productMetadata
|
||||
* @param Stock $stockHelper
|
||||
* @param null $connection
|
||||
* @param string $searchRequestName
|
||||
*/
|
||||
public function __construct(
|
||||
\Magento\Framework\Data\Collection\EntityFactory $entityFactory,
|
||||
LoggerInterface $logger,
|
||||
FetchStrategyInterface $fetchStrategy,
|
||||
ManagerInterface $eventManager,
|
||||
Config $eavConfig,
|
||||
ResourceConnection $resource,
|
||||
EntityFactory $eavEntityFactory,
|
||||
Helper $resourceHelper,
|
||||
UniversalFactory $universalFactory,
|
||||
StoreManagerInterface $storeManager,
|
||||
Manager $moduleManager,
|
||||
State $catalogProductFlatState,
|
||||
ScopeConfigInterface $scopeConfig,
|
||||
OptionFactory $productOptionFactory,
|
||||
Url $catalogUrl,
|
||||
TimezoneInterface $localeDate,
|
||||
Session $customerSession,
|
||||
DateTime $dateTime,
|
||||
GroupManagementInterface $groupManagement,
|
||||
QueryFactory $queryFactory,
|
||||
BuilderFactory $requestBuilderFactory,
|
||||
SearchEngine $searchEngine,
|
||||
TemporaryStorageFactory $temporaryStorageFactory,
|
||||
ProductMetadataInterface $productMetadata,
|
||||
Stock $stockHelper,
|
||||
$connection = null,
|
||||
$searchRequestName = 'catalog_view_container'
|
||||
) {
|
||||
$this->queryFactory = $queryFactory;
|
||||
$this->searchRequestName = $searchRequestName;
|
||||
parent::__construct(
|
||||
$entityFactory,
|
||||
$logger,
|
||||
$fetchStrategy,
|
||||
$eventManager,
|
||||
$eavConfig,
|
||||
$resource,
|
||||
$eavEntityFactory,
|
||||
$resourceHelper,
|
||||
$universalFactory,
|
||||
$storeManager,
|
||||
$moduleManager,
|
||||
$catalogProductFlatState,
|
||||
$scopeConfig,
|
||||
$productOptionFactory,
|
||||
$catalogUrl,
|
||||
$localeDate,
|
||||
$customerSession,
|
||||
$dateTime,
|
||||
$groupManagement,
|
||||
$connection
|
||||
);
|
||||
|
||||
$this->requestBuilder = $requestBuilderFactory->create();
|
||||
$this->searchEngine = $searchEngine;
|
||||
$this->temporaryStorageFactory = $temporaryStorageFactory;
|
||||
$this->stockHelper = $stockHelper;
|
||||
$this->productMetadata = $productMetadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add search query filter
|
||||
*
|
||||
* @param string $query
|
||||
* @return $this
|
||||
*/
|
||||
public function addSearchFilter($query)
|
||||
{
|
||||
$this->queryText = trim($this->queryText . ' ' . $query);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function setRequestData($builder)
|
||||
{
|
||||
$this->_select->reset();
|
||||
$this->requestBuilder = $builder;
|
||||
$this->queryResponse = null;
|
||||
$this->_isFiltersRendered = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Builder
|
||||
*/
|
||||
public function getMemRequestBuilder()
|
||||
{
|
||||
if ($this->memRequestBuilder === null) {
|
||||
$this->memRequestBuilder = clone $this->requestBuilder;
|
||||
$this->memRequestBuilder->bindDimension('scope', $this->getStoreId());
|
||||
if ($this->queryText) {
|
||||
$this->memRequestBuilder->bind('search_term', $this->queryText);
|
||||
}
|
||||
|
||||
$priceRangeCalculation = $this->_scopeConfig->getValue(
|
||||
AlgorithmFactory::XML_PATH_RANGE_CALCULATION,
|
||||
ScopeInterface::SCOPE_STORE
|
||||
);
|
||||
if (is_null($priceRangeCalculation)) {
|
||||
$priceRangeCalculation = '';
|
||||
}
|
||||
if ($priceRangeCalculation) {
|
||||
$this->memRequestBuilder->bind('price_dynamic_algorithm', $priceRangeCalculation);
|
||||
}
|
||||
|
||||
$this->memRequestBuilder->setRequestName($this->searchRequestName);
|
||||
}
|
||||
return $this->memRequestBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stub method for compatibility with other search engines
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setGeneralDefaultQuery()
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $field
|
||||
* @param QueryResponse|null $response
|
||||
* @return array
|
||||
*/
|
||||
public function getFacetedData($field, QueryResponse $response = null)
|
||||
{
|
||||
if (!$response) {
|
||||
$this->_renderFilters();
|
||||
$response = $this->queryResponse;
|
||||
}
|
||||
|
||||
$aggregations = $response->getAggregations();
|
||||
$bucket = $aggregations->getBucket($field . '_bucket');
|
||||
$result = [];
|
||||
if (!$bucket) {
|
||||
throw new StateException(__('Bucket does not exist'));
|
||||
}
|
||||
|
||||
foreach ($bucket->getValues() as $value) {
|
||||
$metrics = $value->getMetrics();
|
||||
$result[$metrics['value']] = $metrics;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
protected function _renderFilters()
|
||||
{
|
||||
$this->_filters = [];
|
||||
return parent::_renderFilters();
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify category filter for product collection
|
||||
*
|
||||
* @param Category $category
|
||||
* @return $this
|
||||
*/
|
||||
public function addCategoryFilter(Category $category)
|
||||
{
|
||||
$this->addFieldToFilter('category_ids', $category->getId());
|
||||
return parent::addCategoryFilter($category);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply attribute filter to facet collection
|
||||
*
|
||||
* @param string $field
|
||||
* @param null $condition
|
||||
* @return $this
|
||||
*/
|
||||
public function addFieldToFilter($field, $condition = null)
|
||||
{
|
||||
if ($this->queryResponse !== null) {
|
||||
throw new RuntimeException('Illegal state');
|
||||
}
|
||||
|
||||
if (!is_array($condition) || !in_array(key($condition), ['from', 'to'], true)) {
|
||||
// See app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/Eav/AbstractEav::_getIndexableAttributesCondition()
|
||||
// Visibility filter wasn't in index before 2.2
|
||||
if ($field != 'visibility'
|
||||
|| version_compare($this->productMetadata->getVersion(), '2.2.0', '>=')) {
|
||||
$this->requestBuilder->bind($field, $condition);
|
||||
}
|
||||
} else {
|
||||
if (!empty($condition['from'])) {
|
||||
$this->requestBuilder->bind("{$field}.from", $condition['from']);
|
||||
}
|
||||
if (!empty($condition['to'])) {
|
||||
$this->requestBuilder->bind("{$field}.to", $condition['to']);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set product visibility filter for enabled products
|
||||
*
|
||||
* @param array $visibility
|
||||
* @return $this
|
||||
*/
|
||||
public function setVisibility($visibility)
|
||||
{
|
||||
$this->addFieldToFilter('visibility', $visibility);
|
||||
return parent::setVisibility($visibility);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter Product by Categories using index table
|
||||
*
|
||||
* @param array $categoriesFilter
|
||||
* @return $this
|
||||
*/
|
||||
public function addIndexCategoriesFilter(array $categoriesFilter)
|
||||
{
|
||||
foreach ($categoriesFilter as $conditionType => $values) {
|
||||
$categorySelect = $this->getConnection()->select()->from(
|
||||
['cat' => $this->getTable('catalog_category_product_index')],
|
||||
'cat.product_id'
|
||||
)->where($this->getConnection()->prepareSqlCondition('cat.category_id', ['in' => $values]));
|
||||
$selectCondition = [
|
||||
$this->mapConditionType($conditionType) => $categorySelect,
|
||||
];
|
||||
$whereCondition = $this->getConnection()->prepareSqlCondition('e.entity_id', $selectCondition);
|
||||
$this->getSelect()->where($whereCondition);
|
||||
$this->requestBuilder->bind('category_ids', $values);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Map equal and not equal conditions to in and not in
|
||||
*
|
||||
* @param string $conditionType
|
||||
* @return mixed
|
||||
*/
|
||||
private function mapConditionType($conditionType)
|
||||
{
|
||||
$conditionsMap = [
|
||||
'eq' => 'in',
|
||||
'neq' => 'nin',
|
||||
];
|
||||
return isset($conditionsMap[$conditionType]) ? $conditionsMap[$conditionType] : $conditionType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load product collection before filters rendering
|
||||
*/
|
||||
protected function _renderFiltersBefore()
|
||||
{
|
||||
$this->requestBuilder->bindDimension('scope', $this->getStoreId());
|
||||
if ($this->queryText) {
|
||||
$this->requestBuilder->bind('search_term', $this->queryText);
|
||||
}
|
||||
|
||||
$priceRangeCalculation = $this->_scopeConfig->getValue(
|
||||
AlgorithmFactory::XML_PATH_RANGE_CALCULATION,
|
||||
ScopeInterface::SCOPE_STORE
|
||||
);
|
||||
if ($priceRangeCalculation) {
|
||||
$this->requestBuilder->bind('price_dynamic_algorithm', $priceRangeCalculation);
|
||||
}
|
||||
|
||||
$this->requestBuilder->setRequestName($this->searchRequestName);
|
||||
$this->memRequestBuilder = clone $this->requestBuilder;
|
||||
$queryRequest = $this->requestBuilder->create();
|
||||
$this->queryResponse = $this->searchEngine->search($queryRequest);
|
||||
|
||||
$temporaryStorage = $this->temporaryStorageFactory->create();
|
||||
$table = $temporaryStorage->storeApiDocuments($this->queryResponse->getIterator());
|
||||
|
||||
$this->getSelect()->joinInner(
|
||||
[
|
||||
'search_result' => $table->getName(),
|
||||
],
|
||||
'e.entity_id = search_result.' . TemporaryStorage::FIELD_ENTITY_ID,
|
||||
[]
|
||||
);
|
||||
|
||||
return parent::_renderFiltersBefore();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
protected function _beforeLoad()
|
||||
{
|
||||
$this->setOrder('entity_id');
|
||||
$this->stockHelper->addIsInStockFilterToCollection($this);
|
||||
|
||||
return parent::_beforeLoad();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Order field
|
||||
*
|
||||
* @param string $attribute
|
||||
* @param string $dir
|
||||
* @return $this
|
||||
*/
|
||||
public function setOrder($attribute, $dir = Select::SQL_DESC)
|
||||
{
|
||||
if ($attribute === 'relevance') {
|
||||
$this->relevanceOrderDirection = $dir;
|
||||
} else {
|
||||
parent::setOrder($attribute, $dir);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add order by entity_id
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
protected function _renderOrders()
|
||||
{
|
||||
if (!$this->_isOrdersRendered) {
|
||||
if ($this->relevanceOrderDirection) {
|
||||
$this->getSelect()->order(
|
||||
'search_result.' . TemporaryStorage::FIELD_SCORE . ' ' . $this->relevanceOrderDirection
|
||||
);
|
||||
}
|
||||
|
||||
parent::_renderOrders();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Olegnax
|
||||
* @package Olegnax_LayeredNavigation
|
||||
* @copyright Copyright (c) 2019 Olegnax (http://olegnax.com/). All rights reserved.
|
||||
* @license Proprietary License https://olegnax.com/license/
|
||||
*/
|
||||
|
||||
namespace Olegnax\LayeredNavigation\Model\ResourceModel\Layer\Filter;
|
||||
|
||||
use Magento\Catalog\Model\Layer\Filter\FilterInterface;
|
||||
use Magento\Catalog\Model\Layer\Search;
|
||||
use Magento\Framework\DB\Select;
|
||||
use Zend_Db_Expr;
|
||||
|
||||
class Attribute extends \Magento\Catalog\Model\ResourceModel\Layer\Filter\Attribute
|
||||
{
|
||||
|
||||
public function getCount(FilterInterface $filter)
|
||||
{
|
||||
$layer = $filter->getLayer();
|
||||
if ($layer instanceof Search) {
|
||||
$collectionSelect = $layer->getProductCollection()->getSelect();
|
||||
} else {
|
||||
$collectionSelect = $layer->getCurrentCategory()->getProductCollection()->getSelect();
|
||||
}
|
||||
|
||||
$select = clone $collectionSelect;
|
||||
$select->reset(Select::COLUMNS);
|
||||
$select->reset(Select::ORDER);
|
||||
$select->reset(Select::LIMIT_COUNT);
|
||||
$select->reset(Select::LIMIT_OFFSET);
|
||||
|
||||
$connection = $this->getConnection();
|
||||
$attribute = $filter->getAttributeModel();
|
||||
$tableAlias = sprintf('%s_idx', $attribute->getAttributeCode());
|
||||
$conditions = [
|
||||
"{$tableAlias}.entity_id = e.entity_id",
|
||||
$connection->quoteInto("{$tableAlias}.attribute_id = ?", $attribute->getAttributeId()),
|
||||
$connection->quoteInto("{$tableAlias}.store_id = ?", $filter->getStoreId()),
|
||||
];
|
||||
|
||||
$select->join(
|
||||
[$tableAlias => $this->getMainTable()], join(' AND ', $conditions),
|
||||
['value', 'count' => new Zend_Db_Expr("COUNT({$tableAlias}.entity_id)")]
|
||||
)->group(
|
||||
"{$tableAlias}.value"
|
||||
);
|
||||
|
||||
return $connection->fetchPairs($select);
|
||||
}
|
||||
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Olegnax
|
||||
* @package Olegnax_LayeredNavigation
|
||||
* @copyright Copyright (c) 2019 Olegnax (http://olegnax.com/). All rights reserved.
|
||||
* @license Proprietary License https://olegnax.com/license/
|
||||
*/
|
||||
|
||||
namespace Olegnax\LayeredNavigation\Model\ResourceModel\Search;
|
||||
|
||||
use Magento\Framework\Api\FilterBuilder;
|
||||
use Magento\Framework\Api\ObjectFactory;
|
||||
use Magento\Framework\Api\Search\FilterGroup as SourceFilterGroup;
|
||||
use Magento\Framework\Api\Search\FilterGroupBuilder as SourceFilterGroupBuilder;
|
||||
use Magento\Framework\App\RequestInterface;
|
||||
|
||||
class FilterGroupBuilder extends SourceFilterGroupBuilder
|
||||
{
|
||||
|
||||
protected $_request;
|
||||
|
||||
public function __construct(
|
||||
ObjectFactory $objectFactory,
|
||||
FilterBuilder $filterBuilder,
|
||||
RequestInterface $request
|
||||
) {
|
||||
parent::__construct($objectFactory, $filterBuilder);
|
||||
|
||||
$this->_request = $request;
|
||||
}
|
||||
|
||||
public function cloneObject()
|
||||
{
|
||||
$cloneObject = clone $this;
|
||||
$cloneObject->setFilterBuilder(clone $this->_filterBuilder);
|
||||
|
||||
return $cloneObject;
|
||||
}
|
||||
|
||||
public function setFilterBuilder($filterBuilder)
|
||||
{
|
||||
$this->_filterBuilder = $filterBuilder;
|
||||
}
|
||||
|
||||
public function removeFilter($attributeCode)
|
||||
{
|
||||
if (isset($this->data[SourceFilterGroup::FILTERS])) {
|
||||
foreach ($this->data[SourceFilterGroup::FILTERS] as $key => $filter) {
|
||||
if ($filter->getField() == $attributeCode) {
|
||||
if (($attributeCode == 'category_ids') && ($filter->getValue() == $this->_request->getParam('id'))) {
|
||||
continue;
|
||||
}
|
||||
unset($this->data[SourceFilterGroup::FILTERS][$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _getDataObjectType()
|
||||
{
|
||||
return 'Magento\Framework\Api\Search\FilterGroup';
|
||||
}
|
||||
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Olegnax
|
||||
* @package Olegnax_LayeredNavigation
|
||||
* @copyright Copyright (c) 2019 Olegnax (http://olegnax.com/). All rights reserved.
|
||||
* @license Proprietary License https://olegnax.com/license/
|
||||
*/
|
||||
|
||||
namespace Olegnax\LayeredNavigation\Model\ResourceModel\Search;
|
||||
|
||||
use Magento\Framework\Api\ObjectFactory;
|
||||
use Magento\Framework\Api\Search\SearchCriteriaBuilder as SourceSearchCriteriaBuilder;
|
||||
use Magento\Framework\Api\SortOrderBuilder;
|
||||
|
||||
class SearchCriteriaBuilder extends SourceSearchCriteriaBuilder
|
||||
{
|
||||
|
||||
public function __construct(
|
||||
ObjectFactory $objectFactory,
|
||||
FilterGroupBuilder $filterGroupBuilder,
|
||||
SortOrderBuilder $sortOrderBuilder
|
||||
) {
|
||||
parent::__construct($objectFactory, $filterGroupBuilder, $sortOrderBuilder);
|
||||
}
|
||||
|
||||
public function removeFilter($attributeCode)
|
||||
{
|
||||
$this->filterGroupBuilder->removeFilter($attributeCode);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function cloneObject()
|
||||
{
|
||||
$cloneObject = clone $this;
|
||||
$cloneObject->setFilterGroupBuilder($this->filterGroupBuilder->cloneObject());
|
||||
|
||||
return $cloneObject;
|
||||
}
|
||||
|
||||
public function setFilterGroupBuilder($filterGroupBuilder)
|
||||
{
|
||||
$this->filterGroupBuilder = $filterGroupBuilder;
|
||||
}
|
||||
|
||||
protected function _getDataObjectType()
|
||||
{
|
||||
return 'Magento\Framework\Api\Search\SearchCriteria';
|
||||
}
|
||||
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Olegnax\LayeredNavigation\Observer\Frontend\View;
|
||||
|
||||
use Magento\Catalog\Block\Product\ListProduct;
|
||||
use Magento\Catalog\Block\Product\ListProduct\Interceptor;
|
||||
use Magento\Framework\DataObject;
|
||||
use Magento\Framework\Event\Observer;
|
||||
use Magento\Framework\Event\ObserverInterface;
|
||||
use Magento\Framework\View\Element\AbstractBlock;
|
||||
|
||||
class BlockAbstractToHtmlAfter implements ObserverInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* Execute observer
|
||||
*
|
||||
* @param Observer $observer
|
||||
* @return void
|
||||
*/
|
||||
public function execute(
|
||||
Observer $observer
|
||||
) {
|
||||
/** @var AbstractBlock $block */
|
||||
$block = $observer->getData('block');
|
||||
if (in_array($block->getNameInLayout(), [
|
||||
'category.products.list',
|
||||
'search_result_list',
|
||||
])) {
|
||||
/** @var DataObject $transport */
|
||||
$transport = $observer->getData('transport');
|
||||
$html = $transport->getData('html');
|
||||
$html = '<div class="ox-layerednavigation-product-list-wrapper">' . $html . '</div>';
|
||||
$transport->setData('html', $html);
|
||||
$observer->setData('transport', $transport);
|
||||
}
|
||||
}
|
||||
}
|
||||
+258
@@ -0,0 +1,258 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Olegnax
|
||||
* @package Olegnax_LayeredNavigation
|
||||
* @copyright Copyright (c) 2019 Olegnax (http://olegnax.com/). All rights reserved.
|
||||
* @license Proprietary License https://olegnax.com/license/
|
||||
*/
|
||||
|
||||
namespace Olegnax\LayeredNavigation\Plugin;
|
||||
|
||||
use Magento\Catalog\Block\Product\ListProduct;
|
||||
use Magento\Framework\App\ObjectManager;
|
||||
use Magento\Framework\App\Request\Http;
|
||||
use Magento\Framework\Controller\Result\RawFactory;
|
||||
use Magento\Framework\DataObject\IdentityInterface;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\Framework\Serialize\Serializer\Json;
|
||||
use Magento\Framework\Url\DecoderInterface;
|
||||
use Magento\Framework\Url\Helper\Data as UrlHelper;
|
||||
use Magento\Framework\View\LayoutInterface;
|
||||
use Magento\Framework\View\Result\Page;
|
||||
use Magento\PageCache\Model\Cache\Type;
|
||||
use Olegnax\LayeredNavigation\Helper\Helper;
|
||||
|
||||
class Ajax
|
||||
{
|
||||
const AJAX_ATTR = 'navAjax';
|
||||
|
||||
const BLOCK_PRODUCTS = 'category.products.list';
|
||||
const BLOCK_PRODUCTS_SEARCH = 'search_result_list';
|
||||
const BLOCK_TITLE = 'page.main.title';
|
||||
const BLOCK_NAVIGATION = 'catalog.leftnav';
|
||||
const BLOCK_NAVIGATION_SEARCH = 'catalogsearch.leftnav';
|
||||
const BLOCK_BREADCRUMBS = 'breadcrumbs';
|
||||
const REGEX_URLS = '@aHR0c(Dov|HM6)[A-Za-z0-9_-]+@u';
|
||||
|
||||
/**
|
||||
* @var Helper
|
||||
*/
|
||||
protected $helper;
|
||||
/**
|
||||
* @var RawFactory
|
||||
*/
|
||||
protected $resultRaw;
|
||||
/**
|
||||
* @var Http
|
||||
*/
|
||||
protected $request;
|
||||
/**
|
||||
* @var Json
|
||||
*/
|
||||
protected $json;
|
||||
/**
|
||||
* @var DecoderInterface
|
||||
*/
|
||||
protected $urlDecoder;
|
||||
/**
|
||||
* @var UrlHelper
|
||||
*/
|
||||
private $urlHelper;
|
||||
/**
|
||||
* @var Registry
|
||||
*/
|
||||
protected $registry;
|
||||
|
||||
public function __construct(
|
||||
Helper $helper,
|
||||
RawFactory $resultRaw,
|
||||
Http $request,
|
||||
UrlHelper $urlHelper,
|
||||
DecoderInterface $urlDecoder,
|
||||
Registry $registry,
|
||||
Json $json
|
||||
) {
|
||||
$this->helper = $helper;
|
||||
$this->resultRaw = $resultRaw;
|
||||
$this->request = $request;
|
||||
$this->urlHelper = $urlHelper;
|
||||
$this->urlDecoder = $urlDecoder;
|
||||
$this->registry = $registry;
|
||||
$this->json = $json;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $html
|
||||
* @return string
|
||||
*/
|
||||
public function removeArgs($html)
|
||||
{
|
||||
$html = str_replace(['?' . static::AJAX_ATTR . '=1&', '?' . static::AJAX_ATTR . '=1&'], '?', $html);
|
||||
$html = str_replace([
|
||||
'?' . static::AJAX_ATTR . '=1',
|
||||
'&' . static::AJAX_ATTR . '=1',
|
||||
'&' . static::AJAX_ATTR . '=1'
|
||||
], '', $html);
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function removeEncodedArgsItem($match)
|
||||
{
|
||||
$code_string = $match[0];
|
||||
$url = $this->urlDecoder->decode($code_string);
|
||||
if (false !== $url) {
|
||||
$newUrl = $this->urlHelper->removeRequestParam($url, static::AJAX_ATTR);
|
||||
$newUrl = $this->removeEncodedArgs($newUrl);
|
||||
|
||||
if ($url != $newUrl) {
|
||||
$code_string = $this->urlHelper->getEncodedUrl($newUrl);
|
||||
}
|
||||
}
|
||||
return $code_string;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $html
|
||||
* @return string
|
||||
*/
|
||||
public function removeEncodedArgs($html)
|
||||
{
|
||||
$_html = preg_replace_callback(static::REGEX_URLS, [$this, 'removeEncodedArgsItem'], $html);
|
||||
if ($_html) {
|
||||
$html = $_html;
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function isAjax()
|
||||
{
|
||||
return $this->helper->isEnabled() &&
|
||||
$this->request->isXmlHttpRequest() &&
|
||||
$this->request->isAjax() &&
|
||||
$this->request->getParam(static::AJAX_ATTR, '');
|
||||
}
|
||||
|
||||
protected function getAjaxContent(Page $page)
|
||||
{
|
||||
/** @var LayoutInterface $layout */
|
||||
$layout = $page->getLayout();
|
||||
$layout->getOutput(); // @todo temporary fix: magenta ignoring the product limit parameter per page, per page with ajax request
|
||||
$title = $page->getConfig()->getTitle()->get();
|
||||
|
||||
$blocks = $this->getLayoutBlock($layout);
|
||||
|
||||
$productsCount = 0;
|
||||
$currentCategory = 0;
|
||||
if ($blocks['products']) {
|
||||
$productsCount = $this->getProductCount($blocks['products']);
|
||||
if ($blocks['products']->getLayer()) {
|
||||
$currentCategory = $blocks['products']->getLayer()->getCurrentCategory();
|
||||
$currentCategory = $currentCategory ? $currentCategory->getId() : 0;
|
||||
}
|
||||
}
|
||||
|
||||
$html = [];
|
||||
$cache_tags = [];
|
||||
foreach ($blocks as $key => $block) {
|
||||
$cache_tags = $this->addIdentities($block, $cache_tags);
|
||||
|
||||
$html[$key] = $block ? $block->toHtml() : '';
|
||||
}
|
||||
|
||||
$response = compact('productsCount', 'currentCategory', 'title', 'html');
|
||||
$response['html']['_before'] = '';
|
||||
$response['html']['_after'] = '';
|
||||
try {
|
||||
$response = $this->prepareForPlugins($response, $blocks);
|
||||
} catch (\Exception $exception){
|
||||
// @todo do nothing or log
|
||||
}
|
||||
$response = $this->changeResponse($response, $cache_tags, $page);
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param LayoutInterface $layout
|
||||
* @return array
|
||||
*/
|
||||
protected function getLayoutBlock($layout)
|
||||
{
|
||||
return [
|
||||
'products' => $layout->getBlock(self::BLOCK_PRODUCTS) ?: $layout->getBlock(self::BLOCK_PRODUCTS_SEARCH),
|
||||
'leftnav' => $layout->getBlock(self::BLOCK_NAVIGATION) ?: $layout->getBlock(self::BLOCK_NAVIGATION_SEARCH),
|
||||
'title' => $layout->getBlock(self::BLOCK_TITLE),
|
||||
'breadcrumbs' => $layout->getBlock(self::BLOCK_BREADCRUMBS),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ListProduct $block
|
||||
* @return int
|
||||
*/
|
||||
protected function getProductCount($block)
|
||||
{
|
||||
return (int)$block->getLoadedProductCollection()->getSize();
|
||||
}
|
||||
|
||||
protected function addIdentities($block, array $data = [])
|
||||
{
|
||||
if ($block instanceof IdentityInterface) {
|
||||
$data = array_merge($data, $block->getIdentities());
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function changeResponse($response, $cache_tags)
|
||||
{
|
||||
$cache_tags[] = Type::CACHE_TAG;
|
||||
$cache_tags = array_unique($cache_tags);
|
||||
$cache_tags = implode(',', $cache_tags);
|
||||
|
||||
$response['cache_tags'] = $cache_tags;
|
||||
$response['html'] = array_map([$this, 'removeArgs'], $response['html']);
|
||||
$response['html'] = array_map([$this, 'removeEncodedArgs'], $response['html']);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
protected function json(array $data)
|
||||
{
|
||||
$response = $this->resultRaw->create();
|
||||
$response->setHeader('Content-type', 'application/json');
|
||||
if (array_key_exists('cache_tags', $data)) {
|
||||
if (!empty($data['cache_tags'])) {
|
||||
$response->setHeader('X-Magento-Tags', $data['cache_tags']);
|
||||
}
|
||||
unset($data['cache_tags']);
|
||||
}
|
||||
$data = $this->json->serialize($data);
|
||||
$response->setContents($data);
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $response
|
||||
* @param array $blocks
|
||||
* @return array
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
protected function prepareForPlugins(array $response, array $blocks)
|
||||
{
|
||||
if (array_key_exists('products', $blocks) && class_exists('\Amasty\Label\Plugin\Catalog\Product\ListProduct')) {
|
||||
/** @var \Amasty\Label\Plugin\Catalog\Product\ListProduct $amastyLabelListProduct */
|
||||
$amastyLabelListProduct = ObjectManager::getInstance()->get('\Amasty\Label\Plugin\Catalog\Product\ListProduct');
|
||||
$this->registry->register('amlabel_category_observer', false);
|
||||
$blocks['products']->setIsAmLabelObserved(false);
|
||||
$response['html']['_after'] .= $amastyLabelListProduct->afterToHtml($blocks['products'], '');
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Olegnax
|
||||
* @package Olegnax_LayeredNavigation
|
||||
* @copyright Copyright (c) 2019 Olegnax (http://olegnax.com/). All rights reserved.
|
||||
* @license Proprietary License https://olegnax.com/license/
|
||||
*/
|
||||
|
||||
namespace Olegnax\LayeredNavigation\Plugin\Catalog\Model\Layer\Filter;
|
||||
|
||||
use Magento\Framework\UrlInterface;
|
||||
use Magento\Theme\Block\Html\Pager;
|
||||
use Olegnax\LayeredNavigation\Helper\Helper;
|
||||
use Olegnax\LayeredNavigation\Model\Layer\Filter;
|
||||
|
||||
class Item
|
||||
{
|
||||
|
||||
protected $_url;
|
||||
protected $_htmlPagerBlock;
|
||||
protected $_helper;
|
||||
protected $_filter;
|
||||
|
||||
public function __construct(
|
||||
UrlInterface $url,
|
||||
Pager $htmlPagerBlock,
|
||||
Helper $helper,
|
||||
Filter $filter
|
||||
) {
|
||||
$this->_url = $url;
|
||||
$this->_htmlPagerBlock = $htmlPagerBlock;
|
||||
$this->_helper = $helper;
|
||||
$this->_filter = $filter;
|
||||
}
|
||||
|
||||
public function aroundGetUrl(\Magento\Catalog\Model\Layer\Filter\Item $item, $proceed)
|
||||
{
|
||||
if ($this->_helper->isEnabled()) {
|
||||
$filter = $item->getFilter();
|
||||
$itemValue = $item->getValue();
|
||||
$value = [is_array($itemValue) ? implode('-', $itemValue) : $itemValue];
|
||||
if ($this->_filter->isMultiselect($filter)) {
|
||||
$value = array_merge($this->_filter->getFilterValue($filter), $value);
|
||||
$value = array_unique($value);
|
||||
}
|
||||
|
||||
$query = [
|
||||
$filter->getRequestVar() => implode(',', $value),
|
||||
// exclude current page from urls
|
||||
$this->_htmlPagerBlock->getPageVarName() => null,
|
||||
];
|
||||
return $this->_url->getUrl('*/*/*', ['_current' => true, '_use_rewrite' => true, '_query' => $query]);
|
||||
}
|
||||
|
||||
return $proceed();
|
||||
}
|
||||
|
||||
public function aroundGetRemoveUrl(\Magento\Catalog\Model\Layer\Filter\Item $item, $proceed)
|
||||
{
|
||||
if ($this->_helper->isEnabled()) {
|
||||
$filter = $item->getFilter();
|
||||
$itemValue = $item->getValue();
|
||||
$value = [is_array($itemValue) ? implode('-', $itemValue) : $itemValue];
|
||||
$valueRequest = $this->_filter->getFilterValue($filter);
|
||||
if (in_array($value[0], $valueRequest)) {
|
||||
$valueRequest = array_diff($valueRequest, $value);
|
||||
}
|
||||
|
||||
$query = [
|
||||
$filter->getRequestVar() => count($valueRequest) ? implode(',', $valueRequest) :
|
||||
$filter->getResetValue()
|
||||
];
|
||||
$params['_current'] = true;
|
||||
$params['_use_rewrite'] = true;
|
||||
$params['_query'] = $query;
|
||||
$params['_escape'] = true;
|
||||
return $this->_url->getUrl('*/*/*', $params);
|
||||
}
|
||||
|
||||
return $proceed();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Olegnax\LayeredNavigation\Plugin\Framework\App;
|
||||
|
||||
|
||||
use Closure;
|
||||
use Magento\Framework\App\Request\Http;
|
||||
use Magento\Framework\App\Response\Http as ResponseHttp;
|
||||
use Magento\Framework\Controller\Result\RawFactory;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\Framework\Serialize\Serializer\Json;
|
||||
use Magento\Framework\Url\DecoderInterface;
|
||||
use Magento\Framework\Url\Helper\Data as UrlHelper;
|
||||
use Magento\Framework\View\Result\Page;
|
||||
use Olegnax\LayeredNavigation\Helper\Helper;
|
||||
use Olegnax\LayeredNavigation\Plugin\Ajax;
|
||||
|
||||
class View extends Ajax
|
||||
{
|
||||
/**
|
||||
* @var ResponseHttp
|
||||
*/
|
||||
private $response;
|
||||
public function __construct(
|
||||
Helper $helper,
|
||||
RawFactory $resultRaw,
|
||||
Http $request,
|
||||
UrlHelper $urlHelper,
|
||||
DecoderInterface $urlDecoder,
|
||||
ResponseHttp $response,
|
||||
Registry $registry,
|
||||
Json $json
|
||||
) {
|
||||
$this->response = $response;
|
||||
parent::__construct($helper, $resultRaw, $request, $urlHelper, $urlDecoder, $registry, $json);
|
||||
}
|
||||
|
||||
public function aroundRenderLayout(
|
||||
\Magento\Framework\App\View $subject,
|
||||
Closure $proceed,
|
||||
$output = ''
|
||||
) {
|
||||
$page = $subject->getPage();
|
||||
|
||||
if ($this->isAjax() && $page instanceof Page && $this->request->getRouteName() === 'catalogsearch') {
|
||||
$content = $this->getAjaxContent($page);
|
||||
$content = $this->json->serialize($content);
|
||||
$this->response->setBody($content);
|
||||
} else {
|
||||
return $proceed($output);
|
||||
}
|
||||
}
|
||||
}
|
||||
Executable
+25
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Olegnax
|
||||
* @package Olegnax_LayeredNavigation
|
||||
* @copyright Copyright (c) 2019 Olegnax (http://olegnax.com/). All rights reserved.
|
||||
* @license Proprietary License https://olegnax.com/license/
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Olegnax\LayeredNavigation\Plugin\Frontend\Magento\Catalog\Model;
|
||||
|
||||
class CategoryRepository
|
||||
{
|
||||
|
||||
public function beforeGet(
|
||||
\Magento\Catalog\Model\CategoryRepository $subject,
|
||||
$categoryId,
|
||||
$storeId = null
|
||||
) {
|
||||
if (is_array($categoryId)) {
|
||||
$categoryId = array_shift($categoryId);
|
||||
}
|
||||
return [$categoryId, $storeId];
|
||||
}
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Olegnax\LayeredNavigation\Plugin\Frontend\Magento\Eav\Model\Entity\Collection;
|
||||
|
||||
use Closure;
|
||||
use Exception;
|
||||
use Magento\Framework\DataObject;
|
||||
|
||||
class AbstractCollection
|
||||
{
|
||||
|
||||
/**
|
||||
* @param \Magento\Eav\Model\Entity\Collection\AbstractCollection $subject
|
||||
* @param Closure $process
|
||||
* @param DataObject $dataObject
|
||||
* @return $this
|
||||
*/
|
||||
public function aroundAddItem(
|
||||
\Magento\Eav\Model\Entity\Collection\AbstractCollection $subject,
|
||||
Closure $process,
|
||||
DataObject $dataObject
|
||||
) {
|
||||
try {
|
||||
return $process($dataObject);
|
||||
} catch (Exception $e) {
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
}
|
||||
Executable
+39
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Olegnax
|
||||
* @package Olegnax_LayeredNavigation
|
||||
* @copyright Copyright (c) 2019 Olegnax (http://olegnax.com/). All rights reserved.
|
||||
* @license Proprietary License https://olegnax.com/license/
|
||||
*/
|
||||
|
||||
namespace Olegnax\LayeredNavigation\Plugin\LayeredNavigation\Block\Navigation;
|
||||
|
||||
use Magento\Catalog\Model\Layer\Filter\FilterInterface;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
|
||||
class FilterRenderer
|
||||
{
|
||||
|
||||
protected $filterPrice;
|
||||
protected $currencySymbol;
|
||||
protected $storeManager;
|
||||
|
||||
/**
|
||||
* @param \Magento\LayeredNavigation\Block\Navigation\FilterRenderer $subject
|
||||
* @param FilterInterface $filter
|
||||
* @return array
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
public function beforeRender($subject, $filter)
|
||||
{
|
||||
$attribute_id = 0;
|
||||
if ('cat' != $filter->getRequestVar()) {
|
||||
$attribute_id = $filter->getAttributeModel()->getAttributeId();
|
||||
}
|
||||
$subject->setData('attribute_id', $attribute_id);
|
||||
$subject->assign('filter', $filter);
|
||||
|
||||
return [$filter];
|
||||
}
|
||||
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Olegnax
|
||||
* @package Olegnax_LayeredNavigation
|
||||
* @copyright Copyright (c) 2020 Olegnax (http://olegnax.com/). All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Olegnax\LayeredNavigation\Plugin;
|
||||
|
||||
use Magento\Framework\App\Action\Action;
|
||||
use Magento\Framework\Controller\Result\Raw;
|
||||
use Magento\Framework\View\Result\Page;
|
||||
|
||||
class ListAjax extends Ajax
|
||||
{
|
||||
/**
|
||||
* @param Action $controller
|
||||
* @param Page $page
|
||||
* @return Raw
|
||||
*/
|
||||
public function afterExecute(Action $controller, $page)
|
||||
{
|
||||
if ($this->isAjax() && $page instanceof Page) {
|
||||
$page = $this->json($this->getAjaxContent($page));
|
||||
}
|
||||
|
||||
return $page;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Olegnax
|
||||
* @package Olegnax_LayeredNavigation
|
||||
* @copyright Copyright (c) 2019 Olegnax (http://olegnax.com/). All rights reserved.
|
||||
* @license Proprietary License https://olegnax.com/license/
|
||||
*/
|
||||
|
||||
namespace Olegnax\LayeredNavigation\Setup;
|
||||
|
||||
use Magento\Catalog\Model\Category;
|
||||
use Magento\Catalog\Setup\CategorySetupFactory;
|
||||
use Magento\Eav\Model\Entity\Attribute\Source\Boolean;
|
||||
use Magento\Eav\Setup\EavSetupFactory;
|
||||
use Magento\Framework\Setup\InstallDataInterface;
|
||||
use Magento\Framework\Setup\ModuleContextInterface;
|
||||
use Magento\Framework\Setup\ModuleDataSetupInterface;
|
||||
|
||||
class InstallData implements InstallDataInterface
|
||||
{
|
||||
|
||||
private $eavSetupFactory;
|
||||
private $categorySetupFactory;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param EavSetupFactory $eavSetupFactory
|
||||
* @param CategorySetupFactory $categorySetupFactory
|
||||
*/
|
||||
public function __construct(EavSetupFactory $eavSetupFactory, CategorySetupFactory $categorySetupFactory)
|
||||
{
|
||||
$this->eavSetupFactory = $eavSetupFactory;
|
||||
$this->categorySetupFactory = $categorySetupFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function install(
|
||||
ModuleDataSetupInterface $setup,
|
||||
ModuleContextInterface $context
|
||||
) {
|
||||
$setup->startSetup();
|
||||
$this->_install($setup);
|
||||
$setup->endSetup();
|
||||
}
|
||||
|
||||
private function _install(ModuleDataSetupInterface $setup)
|
||||
{
|
||||
$tablefields = $this->fields();
|
||||
if (!empty($tablefields)) {
|
||||
$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
|
||||
$categorySetup = $this->categorySetupFactory->create(['setup' => $setup]);
|
||||
$entityTypeId = $categorySetup->getEntityTypeId(Category::ENTITY);
|
||||
$attributeSetId = $categorySetup->getDefaultAttributeSetId($entityTypeId);
|
||||
foreach ($tablefields as $entity => $fields) {
|
||||
foreach ($fields as $key => $value) {
|
||||
if (Category::ENTITY == $entity) {
|
||||
$categorySetup->addAttribute($entity, $key, $value);
|
||||
$group = $value['group'];
|
||||
$idg = $categorySetup->getAttributeGroupId($entityTypeId, $attributeSetId,
|
||||
$group);
|
||||
$categorySetup->addAttributeToGroup(
|
||||
$entityTypeId, $attributeSetId, $idg, $key, $value['sort_order']
|
||||
);
|
||||
} else {
|
||||
$eavSetup->addAttribute($entity, $key, $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function fields()
|
||||
{
|
||||
return [
|
||||
Category::ENTITY => [
|
||||
'ox_nav_disable_ajax' => [
|
||||
'type' => 'int',
|
||||
'label' => 'Disable AJAX in Layered Navigation',
|
||||
'input' => 'select',
|
||||
'source' => Boolean::class,
|
||||
'required' => false,
|
||||
'sort_order' => 10,
|
||||
'group' => 'Display Settings',
|
||||
'default' => 0,
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"name": "olegnax/layered-navigation",
|
||||
"description": "Olegnax Layered Navigastion allows to filter products with multiple filters and withour reloading the page.",
|
||||
"version": "0.2.1.2",
|
||||
"type": "magento2-module",
|
||||
"license": "proprietary",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Olegnax",
|
||||
"email": "mail@olegnax.com",
|
||||
"homepage": "https://olegnax.com",
|
||||
"role": "Technical Support"
|
||||
}
|
||||
],
|
||||
"minimum-stability": "dev",
|
||||
"require": {
|
||||
"olegnax/module-core": ">=1.1.0"
|
||||
},
|
||||
"autoload": {
|
||||
"files": [
|
||||
"registration.php"
|
||||
],
|
||||
"psr-4": {
|
||||
"Olegnax\\LayeredNavigation\\": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" ?>
|
||||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="urn:magento:framework:Acl/etc/acl.xsd">
|
||||
<acl>
|
||||
<resources>
|
||||
<resource id="Magento_Backend::admin">
|
||||
<resource id="Olegnax_Core::Olegnax_Core">
|
||||
<resource id="Olegnax_LayeredNavigation::layered_navigation" sortOrder="10" title="Layered Navigation"/>
|
||||
</resource>
|
||||
</resource>
|
||||
</resources>
|
||||
</acl>
|
||||
</config>
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0"?>
|
||||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Backend:etc/menu.xsd">
|
||||
<menu>
|
||||
<add id="Olegnax_LayeredNavigation::layered_navigation" title="Layered Navigation" translate="title"
|
||||
module="Olegnax_LayeredNavigation" sortOrder="999" parent="Olegnax_Core::Olegnax_Core"
|
||||
resource="Olegnax_LayeredNavigation::layered_navigation"/>
|
||||
<add id="Olegnax_LayeredNavigation::config" title="Configuration" translate="title"
|
||||
module="Olegnax_LayeredNavigation" sortOrder="10"
|
||||
action="adminhtml/system_config/edit/section/olegnax_layered_navigation"
|
||||
parent="Olegnax_LayeredNavigation::layered_navigation" resource="Olegnax_LayeredNavigation::layered_navigation"/>
|
||||
</menu>
|
||||
</config>
|
||||
+122
@@ -0,0 +1,122 @@
|
||||
<?xml version="1.0" ?>
|
||||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
|
||||
<system>
|
||||
<tab id="olegnax" sortOrder="999" translate="label">
|
||||
<label>Olegnax</label>
|
||||
</tab>
|
||||
<section id="olegnax_layered_navigation" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="10"
|
||||
translate="label">
|
||||
<label>Layered Navigation</label>
|
||||
<tab>olegnax</tab>
|
||||
<resource>Olegnax_LayeredNavigation::layered_navigation</resource>
|
||||
<group id="info" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="0" translate="label">
|
||||
<frontend_model>Olegnax\LayeredNavigation\Block\Adminhtml\System\Config\Form\Info</frontend_model>
|
||||
</group>
|
||||
<group id="general" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="10" translate="label">
|
||||
<label>General</label>
|
||||
<field id="enable" translate="label comment" type="select" sortOrder="10" showInDefault="1"
|
||||
showInWebsite="1" showInStore="1">
|
||||
<label>Enable</label>
|
||||
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
|
||||
<frontend_class>on-off-trigger</frontend_class>
|
||||
</field>
|
||||
<field id="filters_type" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="22"
|
||||
translate="label" type="select">
|
||||
<label>Filters Type</label>
|
||||
<source_model>Olegnax\LayeredNavigation\Model\Config\Source\FiltersType</source_model>
|
||||
</field>
|
||||
<field id="abort_prev_request" translate="label" type="select" sortOrder="25" showInDefault="1"
|
||||
showInWebsite="1" showInStore="1">
|
||||
<label>Abort Previous Requests</label>
|
||||
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
|
||||
<frontend_class>on-off-trigger</frontend_class>
|
||||
<depends>
|
||||
<field id="ajax">1</field>
|
||||
</depends>
|
||||
</field>
|
||||
</group>
|
||||
<group id="category" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="20"
|
||||
translate="label">
|
||||
<label>Category</label>
|
||||
<field id="depth" translate="label comment" type="select" sortOrder="10" showInDefault="1"
|
||||
showInWebsite="1" showInStore="1">
|
||||
<label>Depth of nested categories</label>
|
||||
<source_model>Olegnax\LayeredNavigation\Model\Config\Source\CategoryDepth</source_model>
|
||||
</field>
|
||||
</group>
|
||||
<group id="price_slider" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="30"
|
||||
translate="label">
|
||||
<label>Price Slider</label>
|
||||
<field id="price_slider" translate="label comment" type="select" sortOrder="25" showInDefault="1"
|
||||
showInWebsite="1" showInStore="1">
|
||||
<label>Enable Price Slider</label>
|
||||
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
|
||||
<frontend_class>on-off-trigger</frontend_class>
|
||||
</field>
|
||||
</group>
|
||||
<group id="loaders" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="40" translate="label">
|
||||
<label>Loaders</label>
|
||||
<field id="loader_type_filters" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="10"
|
||||
translate="label" type="select">
|
||||
<label>AJAX Progress Loader For Filters Block</label>
|
||||
<source_model>Olegnax\LayeredNavigation\Model\Config\Source\LoaderType</source_model>
|
||||
</field>
|
||||
<field id="loader_filters" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="11"
|
||||
translate="label" type="text">
|
||||
<label>Filters Loader Image</label>
|
||||
<comment>Set url to preloader image. E.g.: "images/preloader.svg" will link to images folder in your
|
||||
current theme. E.g.: app\design\frontend\Olegnax\athlete2\web\images.
|
||||
</comment>
|
||||
<depends>
|
||||
<field id="loader_type_filters">image</field>
|
||||
</depends>
|
||||
</field>
|
||||
<field id="spacer_1" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
|
||||
<frontend_model>Olegnax\LayeredNavigation\Model\Config\Source\Spacer</frontend_model>
|
||||
</field>
|
||||
<field id="loader_type_content" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="21"
|
||||
translate="label" type="select">
|
||||
<label>AJAX Progress Loader For Content</label>
|
||||
<source_model>Olegnax\LayeredNavigation\Model\Config\Source\LoaderType</source_model>
|
||||
</field>
|
||||
<field id="loader_content" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="22"
|
||||
translate="label" type="text">
|
||||
<label>Content Loader Image</label>
|
||||
<comment>Set url to preloader image. E.g.: "images/preloader.svg" will link to images folder in your
|
||||
current theme. E.g.: app\design\frontend\Olegnax\athlete2\web\images.
|
||||
</comment>
|
||||
<depends>
|
||||
<field id="loader_type_content">image</field>
|
||||
</depends>
|
||||
</field>
|
||||
<field id="loader_content_selector" translate="label comment" type="text" sortOrder="23"
|
||||
showInDefault="1"
|
||||
showInWebsite="1" showInStore="1">
|
||||
<label>Custom DOM Selectors for Products Container</label>
|
||||
<comment>Default selectors: ".column.main .products.products-grid, .column.main
|
||||
.products.products-list, .column.main .products-grid.grid"
|
||||
</comment>
|
||||
</field>
|
||||
<field id="spacer_2" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
|
||||
<frontend_model>Olegnax\LayeredNavigation\Model\Config\Source\Spacer</frontend_model>
|
||||
</field>
|
||||
<field id="loader_type_page" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="31"
|
||||
translate="label" type="select">
|
||||
<label>AJAX Progress Loader For the Whole Page</label>
|
||||
<source_model>Olegnax\LayeredNavigation\Model\Config\Source\LoaderType</source_model>
|
||||
</field>
|
||||
<field id="loader_page" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="32"
|
||||
translate="label" type="text">
|
||||
<label>Page Loader Image</label>
|
||||
<comment>Set url to preloader image. E.g.: "images/preloader.svg" will link to images folder in your
|
||||
current theme. E.g.: app\design\frontend\Olegnax\athlete2\web\images.
|
||||
</comment>
|
||||
<depends>
|
||||
<field id="loader_type_page">image</field>
|
||||
</depends>
|
||||
</field>
|
||||
</group>
|
||||
</section>
|
||||
</system>
|
||||
</config>
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
<?xml version="1.0" ?>
|
||||
<!--
|
||||
/**
|
||||
* @author Olegnax
|
||||
* @package Olegnax_LayeredNavigation
|
||||
* @copyright Copyright (c) 2019 Olegnax (http://olegnax.com/). All rights reserved.
|
||||
* @license Proprietary License https://olegnax.com/license/
|
||||
*/
|
||||
-->
|
||||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
|
||||
<default>
|
||||
<olegnax_layered_navigation>
|
||||
<general>
|
||||
<enable>1</enable>
|
||||
<filters_type/>
|
||||
<abort_prev_request>1</abort_prev_request>
|
||||
</general>
|
||||
<category>
|
||||
<depth>0</depth>
|
||||
</category>
|
||||
<price_slider>
|
||||
<price_slider>1</price_slider>
|
||||
</price_slider>
|
||||
<loaders>
|
||||
<loader_type_filters>theme</loader_type_filters>
|
||||
<loader_filters/>
|
||||
<loader_type_content>theme</loader_type_content>
|
||||
<loader_content/>
|
||||
<loader_content_selector/>
|
||||
<loader_type_page/>
|
||||
<loader_page/>
|
||||
</loaders>
|
||||
</olegnax_layered_navigation>
|
||||
</default>
|
||||
</config>
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* @author Olegnax
|
||||
* @package Olegnax_LayeredNavigation
|
||||
* @copyright Copyright (c) 2019 Olegnax (http://olegnax.com/). All rights reserved.
|
||||
* @license Proprietary License https://olegnax.com/license/
|
||||
*/
|
||||
-->
|
||||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
|
||||
<preference for="Magento\Catalog\Model\Category\DataProvider" type="Olegnax\LayeredNavigation\Model\Category\DataProvider"/>
|
||||
|
||||
|
||||
|
||||
<virtualType name="categoryFilterList" type="Magento\Catalog\Model\Layer\FilterList">
|
||||
<arguments>
|
||||
<argument name="filters" xsi:type="array">
|
||||
<item name="attribute" xsi:type="string">Olegnax\LayeredNavigation\Model\Layer\Filter\Attribute</item>
|
||||
<item name="price" xsi:type="string">Olegnax\LayeredNavigation\Model\Layer\Filter\Price</item>
|
||||
<item name="category" xsi:type="string">Olegnax\LayeredNavigation\Model\Layer\Filter\Category</item>
|
||||
</argument>
|
||||
</arguments>
|
||||
</virtualType>
|
||||
<virtualType name="searchFilterList" type="Magento\Catalog\Model\Layer\FilterList">
|
||||
<arguments>
|
||||
<argument name="filters" xsi:type="array">
|
||||
<item name="attribute" xsi:type="string">Olegnax\LayeredNavigation\Model\Layer\Filter\Attribute</item>
|
||||
<item name="price" xsi:type="string">Olegnax\LayeredNavigation\Model\Layer\Filter\Price</item>
|
||||
<item name="category" xsi:type="string">Olegnax\LayeredNavigation\Model\Layer\Filter\Category</item>
|
||||
</argument>
|
||||
</arguments>
|
||||
</virtualType>
|
||||
<virtualType name="Olegnax\LayeredNavigation\Model\ResourceModel\Fulltext\SearchCollection"
|
||||
type="Olegnax\LayeredNavigation\Model\ResourceModel\Fulltext\Collection">
|
||||
<arguments>
|
||||
<argument name="searchRequestName" xsi:type="string">quick_search_container</argument>
|
||||
</arguments>
|
||||
</virtualType>
|
||||
<virtualType name="elasticsearchFulltextSearchCollectionFactory" type="Magento\CatalogSearch\Model\ResourceModel\Fulltext\SearchCollectionFactory">
|
||||
<arguments>
|
||||
<argument name="instanceName" xsi:type="string">Olegnax\LayeredNavigation\Model\ResourceModel\Fulltext\SearchCollection</argument>
|
||||
</arguments>
|
||||
</virtualType>
|
||||
<virtualType name="Magento\CatalogSearch\Model\ResourceModel\Fulltext\CollectionFactory"
|
||||
type="Magento\Catalog\Model\ResourceModel\Product\CollectionFactory">
|
||||
<arguments>
|
||||
<argument name="instanceName" xsi:type="string">
|
||||
Olegnax\LayeredNavigation\Model\ResourceModel\Fulltext\Collection
|
||||
</argument>
|
||||
</arguments>
|
||||
</virtualType>
|
||||
<virtualType name="elasticsearchCategoryCollectionFactory"
|
||||
type="Magento\CatalogSearch\Model\ResourceModel\Fulltext\SearchCollectionFactory">
|
||||
<arguments>
|
||||
<argument name="instanceName" xsi:type="string">
|
||||
Olegnax\LayeredNavigation\Model\ResourceModel\Fulltext\Collection
|
||||
</argument>
|
||||
</arguments>
|
||||
</virtualType>
|
||||
<virtualType name="Magento\CatalogSearch\Model\ResourceModel\Fulltext\SearchCollection"
|
||||
type="Olegnax\LayeredNavigation\Model\ResourceModel\Fulltext\Collection">
|
||||
<arguments>
|
||||
<argument name="searchRequestName" xsi:type="string">quick_search_container</argument>
|
||||
</arguments>
|
||||
</virtualType>
|
||||
<virtualType name="Olegnax\LayeredNavigation\Block\Navigation\Category"
|
||||
type="Olegnax\LayeredNavigation\Block\Navigation">
|
||||
<arguments>
|
||||
<argument name="filterList" xsi:type="object">categoryFilterList</argument>
|
||||
</arguments>
|
||||
</virtualType>
|
||||
<virtualType name="Olegnax\LayeredNavigation\Block\Navigation\Search"
|
||||
type="Olegnax\LayeredNavigation\Block\Navigation">
|
||||
<arguments>
|
||||
<argument name="filterList" xsi:type="object">searchFilterList</argument>
|
||||
</arguments>
|
||||
</virtualType>
|
||||
<virtualType name="Magento\LayeredNavigationStaging\Block\Navigation\Category"
|
||||
type="Olegnax\LayeredNavigation\Block\Navigation">
|
||||
<arguments>
|
||||
<argument name="filterList" xsi:type="object">categoryFilterList</argument>
|
||||
</arguments>
|
||||
</virtualType>
|
||||
<virtualType name="Magento\LayeredNavigationStaging\Block\Navigation\Search"
|
||||
type="Olegnax\LayeredNavigation\Block\Navigation">
|
||||
<arguments>
|
||||
<argument name="filterList" xsi:type="object">searchFilterList</argument>
|
||||
</arguments>
|
||||
</virtualType>
|
||||
|
||||
</config>
|
||||
+108
@@ -0,0 +1,108 @@
|
||||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
|
||||
<type name="Magento\Catalog\Controller\Category\View">
|
||||
<plugin name="ox_navigation_Catalog_View"
|
||||
type="Olegnax\LayeredNavigation\Plugin\ListAjax"/>
|
||||
</type>
|
||||
<type name="Magento\CatalogSearch\Controller\Result\Index">
|
||||
<plugin name="ox_navigation_CatalogSearch_Index"
|
||||
type="Olegnax\LayeredNavigation\Plugin\ListAjax"/>
|
||||
</type>
|
||||
<type name="Smartwave\Porto\Controller\CatalogSearch\Result">
|
||||
<plugin name="ox_navigation_SmartwavePorto_Result"
|
||||
type="Olegnax\LayeredNavigation\Plugin\ListAjax"/>
|
||||
</type>
|
||||
<type name="Amasty\ShopbyBrand\Controller\Index\Index">
|
||||
<plugin name="ox_navigation_ShopbyBrand_Index"
|
||||
type="Olegnax\LayeredNavigation\Plugin\ListAjax"/>
|
||||
</type>
|
||||
<type name="Magento\LayeredNavigation\Block\Navigation\FilterRenderer">
|
||||
<plugin name="ox_navigation_filter_render"
|
||||
type="Olegnax\LayeredNavigation\Plugin\LayeredNavigation\Block\Navigation\FilterRenderer"/>
|
||||
</type>
|
||||
<type name="Magento\Catalog\Model\Layer\Filter\Item">
|
||||
<plugin name="ox_navigation_filter_item_urls"
|
||||
type="Olegnax\LayeredNavigation\Plugin\Catalog\Model\Layer\Filter\Item" sortOrder="1"/>
|
||||
</type>
|
||||
<type name="Magento\Framework\App\View">
|
||||
<plugin name="ox_navigation_filter_search" type="Olegnax\LayeredNavigation\Plugin\Framework\App\View"/>
|
||||
</type>
|
||||
<type name="Magento\Catalog\Model\CategoryRepository">
|
||||
<plugin disabled="false" name="Olegnax_LayeredNavigation_Plugin_Frontend_Magento_Catalog_Model_CategoryRepository" sortOrder="10" type="Olegnax\LayeredNavigation\Plugin\Frontend\Magento\Catalog\Model\CategoryRepository"/>
|
||||
</type>
|
||||
<type name="Magento\Eav\Model\Entity\Collection\AbstractCollection">
|
||||
<plugin disabled="false" name="Olegnax_LayeredNavigation_Plugin_Frontend_Magento_Eav_Model_Entity_Collection_AbstractCollection" sortOrder="10" type="Olegnax\LayeredNavigation\Plugin\Frontend\Magento\Eav\Model\Entity\Collection\AbstractCollection"/>
|
||||
</type>
|
||||
<virtualType name="categoryFilterList" type="Magento\Catalog\Model\Layer\FilterList">
|
||||
<arguments>
|
||||
<argument name="filters" xsi:type="array">
|
||||
<item name="attribute" xsi:type="string">Olegnax\LayeredNavigation\Model\Layer\Filter\Attribute</item>
|
||||
<item name="price" xsi:type="string">Olegnax\LayeredNavigation\Model\Layer\Filter\Price</item>
|
||||
<item name="category" xsi:type="string">Olegnax\LayeredNavigation\Model\Layer\Filter\Category</item>
|
||||
</argument>
|
||||
</arguments>
|
||||
</virtualType>
|
||||
<virtualType name="searchFilterList" type="Magento\Catalog\Model\Layer\FilterList">
|
||||
<arguments>
|
||||
<argument name="filters" xsi:type="array">
|
||||
<item name="attribute" xsi:type="string">Olegnax\LayeredNavigation\Model\Layer\Filter\Attribute</item>
|
||||
<item name="price" xsi:type="string">Olegnax\LayeredNavigation\Model\Layer\Filter\Price</item>
|
||||
<item name="category" xsi:type="string">Olegnax\LayeredNavigation\Model\Layer\Filter\Category</item>
|
||||
</argument>
|
||||
</arguments>
|
||||
</virtualType>
|
||||
<virtualType name="Magento\CatalogSearch\Model\ResourceModel\Fulltext\CollectionFactory"
|
||||
type="Magento\Catalog\Model\ResourceModel\Product\CollectionFactory">
|
||||
<arguments>
|
||||
<argument name="instanceName" xsi:type="string">
|
||||
Olegnax\LayeredNavigation\Model\ResourceModel\Fulltext\Collection
|
||||
</argument>
|
||||
</arguments>
|
||||
</virtualType>
|
||||
<virtualType name="elasticsearchCategoryCollectionFactory"
|
||||
type="Magento\CatalogSearch\Model\ResourceModel\Fulltext\SearchCollectionFactory">
|
||||
<arguments>
|
||||
<argument name="instanceName" xsi:type="string">
|
||||
Olegnax\LayeredNavigation\Model\ResourceModel\Fulltext\Collection
|
||||
</argument>
|
||||
</arguments>
|
||||
</virtualType>
|
||||
<virtualType name="Magento\CatalogSearch\Model\ResourceModel\Fulltext\SearchCollection"
|
||||
type="Olegnax\LayeredNavigation\Model\ResourceModel\Fulltext\Collection">
|
||||
<arguments>
|
||||
<argument name="searchRequestName" xsi:type="string">quick_search_container</argument>
|
||||
</arguments>
|
||||
</virtualType>
|
||||
<virtualType name="Olegnax\LayeredNavigation\Block\Navigation\Category"
|
||||
type="Olegnax\LayeredNavigation\Block\Navigation">
|
||||
<arguments>
|
||||
<argument name="filterList" xsi:type="object">categoryFilterList</argument>
|
||||
</arguments>
|
||||
</virtualType>
|
||||
<virtualType name="Olegnax\LayeredNavigation\Block\Navigation\Search"
|
||||
type="Olegnax\LayeredNavigation\Block\Navigation">
|
||||
<arguments>
|
||||
<argument name="filterList" xsi:type="object">searchFilterList</argument>
|
||||
</arguments>
|
||||
</virtualType>
|
||||
<virtualType name="Magento\LayeredNavigationStaging\Block\Navigation\Category"
|
||||
type="Olegnax\LayeredNavigation\Block\Navigation">
|
||||
<arguments>
|
||||
<argument name="filterList" xsi:type="object">categoryFilterList</argument>
|
||||
</arguments>
|
||||
</virtualType>
|
||||
<virtualType name="Magento\LayeredNavigationStaging\Block\Navigation\Search"
|
||||
type="Olegnax\LayeredNavigation\Block\Navigation">
|
||||
<arguments>
|
||||
<argument name="filterList" xsi:type="object">searchFilterList</argument>
|
||||
</arguments>
|
||||
</virtualType>
|
||||
|
||||
|
||||
<preference for="Magento\LayeredNavigation\Block\Navigation\State"
|
||||
type="Olegnax\LayeredNavigation\Block\Navigation\State"/>
|
||||
<preference for="Magento\Catalog\Model\ResourceModel\Layer\Filter\Attribute"
|
||||
type="Olegnax\LayeredNavigation\Model\ResourceModel\Layer\Filter\Attribute"/>
|
||||
<preference for="Magento\Swatches\Block\LayeredNavigation\RenderLayered"
|
||||
type="Olegnax\LayeredNavigation\Block\LayeredNavigation\RenderLayered"/>
|
||||
</config>
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" ?>
|
||||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
|
||||
<event name="view_block_abstract_to_html_after">
|
||||
<observer instance="Olegnax\LayeredNavigation\Observer\Frontend\View\BlockAbstractToHtmlAfter" name="olegnax_layerednavigation_observer_frontend_view_blockabstracttohtmlafter_view_block_abstract_to_html_after"/>
|
||||
</event>
|
||||
</config>
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
|
||||
<module name="Olegnax_LayeredNavigation" setup_version="0.2.1.2">
|
||||
<sequence>
|
||||
<module name="Olegnax_Core"/>
|
||||
<module name="Magento_Catalog"/>
|
||||
</sequence>
|
||||
</module>
|
||||
</config>
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Olegnax
|
||||
* @package Olegnax_LayeredNavigation
|
||||
* @copyright Copyright (c) 2019 Olegnax (http://olegnax.com/). All rights reserved.
|
||||
* @license Proprietary License https://olegnax.com/license/
|
||||
*/
|
||||
|
||||
use Magento\Framework\Component\ComponentRegistrar;
|
||||
|
||||
ComponentRegistrar::register(
|
||||
ComponentRegistrar::MODULE, 'Olegnax_LayeredNavigation', __DIR__
|
||||
);
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
/**
|
||||
* @author Olegnax
|
||||
* @package Olegnax_LayeredNavigation
|
||||
* @copyright Copyright (c) 2019 Olegnax (http://olegnax.com/). All rights reserved.
|
||||
* @license Proprietary License https://olegnax.com/license/
|
||||
*/
|
||||
-->
|
||||
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
|
||||
<fieldset name="display_settings" sortOrder="20">
|
||||
<settings>
|
||||
<collapsible>true</collapsible>
|
||||
<label translate="true">Display Settings</label>
|
||||
</settings>
|
||||
<field name="ox_nav_disable_ajax" sortOrder="60" formElement="checkbox">
|
||||
<argument name="data" xsi:type="array">
|
||||
<item name="config" xsi:type="array">
|
||||
<item name="default" xsi:type="number">0</item>
|
||||
</item>
|
||||
</argument>
|
||||
<settings>
|
||||
<dataType>boolean</dataType>
|
||||
<label translate="true">Disable AJAX in Layered Navigation</label>
|
||||
</settings>
|
||||
<formElements>
|
||||
<checkbox>
|
||||
<settings>
|
||||
<valueMap>
|
||||
<map name="false" xsi:type="string">0</map>
|
||||
<map name="true" xsi:type="string">1</map>
|
||||
</valueMap>
|
||||
<prefer>toggle</prefer>
|
||||
</settings>
|
||||
</checkbox>
|
||||
</formElements>
|
||||
</field>
|
||||
</fieldset>
|
||||
</form>
|
||||
Executable
+6
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
|
||||
<update handle="layered_navigation_handle" />
|
||||
<update handle="layered_navigation_templates" />
|
||||
</page>
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0"?>
|
||||
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
|
||||
<update handle="layered_navigation_handle" />
|
||||
<body>
|
||||
<referenceBlock name="catalogsearch.leftnav">
|
||||
<action method="setTemplate" ifconfig="olegnax_layered_navigation/general/enable">
|
||||
<argument name="template" xsi:type="string">Olegnax_LayeredNavigation::layer/view.phtml</argument>
|
||||
</action>
|
||||
</referenceBlock>
|
||||
<referenceBlock name="catalogsearch.navigation.renderer">
|
||||
<action method="setTemplate" ifconfig="olegnax_layered_navigation/general/enable">
|
||||
<argument name="template" xsi:type="string">Olegnax_LayeredNavigation::layer/filter.phtml</argument>
|
||||
</action>
|
||||
</referenceBlock>
|
||||
</body>
|
||||
</page>
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0"?>
|
||||
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
|
||||
<body>
|
||||
<referenceContainer name="before.body.end">
|
||||
<block class="Magento\Framework\View\Element\Template" name="ox_layerednavigation_loader" template="Olegnax_LayeredNavigation::loader.phtml"
|
||||
ifconfig="olegnax_layered_navigation/general/enable"/>
|
||||
<block class="Olegnax\LayeredNavigation\Block\Template" name="ox_layerednavigation_initialize" template="Olegnax_LayeredNavigation::initialize.phtml"
|
||||
ifconfig="olegnax_layered_navigation/general/enable"/>
|
||||
</referenceContainer>
|
||||
</body>
|
||||
</page>
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0"?>
|
||||
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
|
||||
<body>
|
||||
<referenceBlock name="catalog.leftnav">
|
||||
<action method="setTemplate" ifconfig="olegnax_layered_navigation/general/enable">
|
||||
<argument name="template" xsi:type="string">Olegnax_LayeredNavigation::layer/view.phtml</argument>
|
||||
</action>
|
||||
</referenceBlock>
|
||||
<referenceBlock name="catalog.navigation.renderer">
|
||||
<action method="setTemplate" ifconfig="olegnax_layered_navigation/general/enable">
|
||||
<argument name="template" xsi:type="string">Olegnax_LayeredNavigation::layer/filter.phtml</argument>
|
||||
</action>
|
||||
</referenceBlock>
|
||||
</body>
|
||||
</page>
|
||||
@@ -0,0 +1,18 @@
|
||||
var config = {
|
||||
map: {
|
||||
'*': {
|
||||
'OXPriceSlider': 'Olegnax_LayeredNavigation/js/price-slider',
|
||||
'wNumb': 'Olegnax_LayeredNavigation/js/wNumb.min',
|
||||
'OXAjaxNav': 'Olegnax_LayeredNavigation/js/ajax-nav',
|
||||
'oxFormValues': 'Olegnax_LayeredNavigation/js/form-values',
|
||||
'noUiSlider': 'Olegnax_LayeredNavigation/js/nouislider.min',
|
||||
}
|
||||
},
|
||||
config: {
|
||||
mixins: {
|
||||
'Magento_Swatches/js/swatch-renderer': {
|
||||
'Olegnax_LayeredNavigation/js/swatch-renderer': true
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Olegnax
|
||||
* @package Olegnax_LayeredNavigation
|
||||
* @copyright Copyright (c) 2019 Olegnax (http://olegnax.com/). All rights reserved.
|
||||
* @license Proprietary License https://olegnax.com/license/
|
||||
*/
|
||||
|
||||
use Olegnax\LayeredNavigation\Block\Template;
|
||||
|
||||
/** @var Template $block */
|
||||
?>
|
||||
|
||||
<script>
|
||||
requirejs(['jquery', 'OXAjaxNav'],
|
||||
function ($) {
|
||||
"use strict";
|
||||
|
||||
$(function () {
|
||||
$('body').OXAjaxNav(<?= $block->getNavConfig(); ?>);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Olegnax
|
||||
* @package Olegnax_LayeredNavigation
|
||||
* @copyright Copyright (c) 2019 Olegnax (http://olegnax.com/). All rights reserved.
|
||||
* @license Proprietary License https://olegnax.com/license/
|
||||
*/
|
||||
|
||||
use Magento\Catalog\Model\Layer\Filter\AbstractFilter;
|
||||
use Magento\CatalogSearch\Model\Layer\Filter\Category;
|
||||
use Magento\CatalogSearch\Model\Layer\Filter\Price;
|
||||
use Magento\LayeredNavigation\Block\Navigation\FilterRenderer;
|
||||
use Olegnax\LayeredNavigation\Helper\Filter;
|
||||
use Olegnax\LayeredNavigation\Helper\Helper;
|
||||
use Olegnax\LayeredNavigation\Model\Config\Source\FiltersType;
|
||||
|
||||
/**
|
||||
* Template for filter items block
|
||||
*
|
||||
* @var $block FilterRenderer
|
||||
* @var $filter AbstractFilter
|
||||
*/
|
||||
|
||||
/** @var Filter $helperFilter */
|
||||
$helperFilter = $this->helper(Filter::class);
|
||||
$showCheckbox = $this->helper(Helper::class)->getModuleConfig('general/filters_type');
|
||||
$isCategorie = $filter instanceof Category;
|
||||
$requestVar = $filter->getRequestVar();
|
||||
|
||||
if ($filter instanceof Price && $filter->getIsSlider()): ?>
|
||||
<div class="item item-price-slider" data-mage-init='{"OXPriceSlider":<?php echo $filter->getSliderConfig(); ?>}'>
|
||||
<div class="ox-price-slider" style="display:none;"></div>
|
||||
<div class="ox-price-filter__values">
|
||||
<span class="ox-slider-min"></span>
|
||||
<span class="ox-slider-max"></span>
|
||||
<input<?= $showCheckbox !== FiltersType::TYPE_CHECKBOX ? ' class="ox-nav-use-url"' : '' ?> type="text" name="filter[<?= $requestVar ?>]"
|
||||
value="<?= $helperFilter->getSelectedSlider($filter); ?>" placeholder="<?= $filter->getLabel() ?>"/>
|
||||
<span class="ox-price-filter__selected" style="display:none;">
|
||||
<?= $filter->getLabel() ? $filter->getLabel() . ': ' : '' ?>
|
||||
<span class="ox-slider-from"></span> <span class="separator">–</span>
|
||||
<span class="ox-slider-to"></span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<ol class="items <?php if ($showCheckbox == FiltersType::TYPE_CHECKBOX) {
|
||||
echo 'ox-layered__items--checkbox';
|
||||
} ?> ">
|
||||
<?php foreach ($filterItems as $filterItem): ?>
|
||||
<li class="item<?= $helperFilter->checkedFilter($filterItem, ' ox-seleted-item') . $filterItem->getData('item_level')? ' ox-item-level-'.$filterItem->getData('item_level'):''; ?>">
|
||||
<?php if ($filterItem->getCount() > 0): ?>
|
||||
<?php if ($filter->getIsDisableAjax($filterItem) && ($filter instanceof Category)): ?>
|
||||
<?php if ($showCheckbox == FiltersType::TYPE_CHECKBOX): ?>
|
||||
<label for="filter_item_<?= $requestVar . '_' . $filterItem->getValue(); ?>">
|
||||
<span class="ox-checkbox"></span>
|
||||
<a class="label ox-disable-ajax" rel="nofollow"
|
||||
href="<?= $filter->getUrlItem($filterItem) ?>">
|
||||
<?= /* @noEscape */
|
||||
$filterItem->getLabel() ?>
|
||||
</a>
|
||||
</label>
|
||||
<?php else: ?>
|
||||
<a class="ox-disable-ajax" rel="nofollow" href="<?= $filter->getUrlItem($filterItem) ?>">
|
||||
<?= /* @noEscape */
|
||||
$filterItem->getLabel() ?>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
<?php elseif ($showCheckbox == FiltersType::TYPE_CHECKBOX): ?>
|
||||
<input id="filter_item_<?= $requestVar . '_' . $filterItem->getValue(); ?>"
|
||||
type="checkbox" name="filter[<?= $requestVar ?>][]"
|
||||
value="<?= $filterItem->getValue(); ?>" <?= !$filterItem->getCount() ? 'disabled' : ''; ?><?= $helperFilter->checkedFilter($filterItem); ?> />
|
||||
<label for="filter_item_<?= $requestVar . '_' . $filterItem->getValue(); ?>">
|
||||
<span class="ox-checkbox"></span>
|
||||
<span class="label"><?= /* @noEscape */
|
||||
$filterItem->getLabel() ?></span>
|
||||
</label>
|
||||
<?php else: ?>
|
||||
<a href="<?= $block->escapeUrl($filterItem->getUrl()) ?>" rel="nofollow">
|
||||
<?= /* @noEscape */
|
||||
$filterItem->getLabel() ?>
|
||||
</a>
|
||||
|
||||
<?php endif; ?>
|
||||
<?php else : ?>
|
||||
<strong><?= /* @noEscape */
|
||||
$filterItem->getLabel() ?></strong>
|
||||
<?php endif; ?>
|
||||
<?php /* show counter */ ?>
|
||||
<?php if ($this->helper(\Magento\Catalog\Helper\Data::class)->shouldDisplayProductCountOnLayer()) : ?>
|
||||
<span class="count"><?= /* @noEscape */
|
||||
(int)$filterItem->getCount()?:'' ?><span class="filter-count-label">
|
||||
<?php if ($filterItem->getCount() == 1) :
|
||||
?> <?= $block->escapeHtml(__('item')) ?><?php
|
||||
elseif ($filterItem->getCount() > 0) :
|
||||
?> <?= $block->escapeHtml(__('items')) ?><?php
|
||||
endif; ?></span></span>
|
||||
<?php endif; ?>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ol>
|
||||
<?php endif; ?>
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Olegnax
|
||||
* @package Olegnax_LayeredNavigation
|
||||
* @copyright Copyright (c) 2019 Olegnax (http://olegnax.com/). All rights reserved.
|
||||
* @license Proprietary License https://olegnax.com/license/
|
||||
*/
|
||||
|
||||
use Magento\LayeredNavigation\Block\Navigation\State;
|
||||
|
||||
// @codingStandardsIgnoreFile
|
||||
?>
|
||||
<?php
|
||||
/**
|
||||
* Category layered navigation state
|
||||
*
|
||||
* @var $block State
|
||||
*/
|
||||
?>
|
||||
<?php $_filters = $block->getActiveFilters() ?>
|
||||
<?php if (!empty($_filters)): ?>
|
||||
<div class="filter-current">
|
||||
<strong class="block-subtitle filter-current-subtitle"
|
||||
role="heading"
|
||||
aria-level="2"
|
||||
data-count="<?= count($_filters) ?>"><?= /* @escapeNotVerified */
|
||||
__('Now Shopping by') ?></strong>
|
||||
<ol class="items">
|
||||
<?php
|
||||
foreach ($_filters as $_filter):
|
||||
$requestVar = $_filter->getFilter()->getRequestVar();
|
||||
$filterItemVal = (is_array($_filter->getValue())) ? implode('-',
|
||||
$_filter->getValue()) : $_filter->getValue();
|
||||
?>
|
||||
<li class="item">
|
||||
<span class="filter-label"><?= $block->escapeHtml(__($_filter->getName())) ?></span>
|
||||
<span class="filter-value"><?= /* @escapeNotVerified */
|
||||
$block->stripTags($_filter->getLabel()) ?></span>
|
||||
<?php
|
||||
$clearLinkUrl = $_filter->getClearLinkUrl();
|
||||
$currentFilterName = $block->escapeHtml(__($_filter->getName())) . " " . $block->stripTags($_filter->getLabel());
|
||||
if ($clearLinkUrl):
|
||||
?>
|
||||
<a class="action previous" href="<?= /* @escapeNotVerified */
|
||||
$_filter->getRemoveUrl() ?>"
|
||||
title="<?= /* @escapeNotVerified */
|
||||
__('Previous') ?>" data-current-var="<?= /* @escapeNotVerified */
|
||||
$requestVar ?>" data-current-val="<?= /* @escapeNotVerified */
|
||||
$filterItemVal ?>">
|
||||
<span><?= /* @escapeNotVerified */
|
||||
__('Previous') ?></span>
|
||||
</a>
|
||||
<a class="action remove"
|
||||
title="<?= $block->escapeHtml($_filter->getFilter()->getClearLinkText()) ?>"
|
||||
href="<?= /* @escapeNotVerified */
|
||||
$clearLinkUrl ?>" data-current-var="<?= /* @escapeNotVerified */
|
||||
$requestVar ?>" data-current-val="<?= /* @escapeNotVerified */
|
||||
$filterItemVal ?>">
|
||||
<span><?= $block->escapeHtml($_filter->getFilter()->getClearLinkText()) ?></span>
|
||||
</a>
|
||||
<?php else: ?>
|
||||
<a class="action remove" href="<?= /* @escapeNotVerified */
|
||||
$_filter->getRemoveUrl() ?>" data-current-var="<?= /* @escapeNotVerified */
|
||||
$requestVar ?>" data-current-val="<?= /* @escapeNotVerified */
|
||||
$filterItemVal ?>"
|
||||
title="<?= /* @escapeNotVerified */
|
||||
$block->escapeHtml(__('Remove')) . " " . $currentFilterName ?>">
|
||||
<span><?= /* @escapeNotVerified */
|
||||
__('Remove This Item') ?></span>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ol>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Olegnax
|
||||
* @package Olegnax_LayeredNavigation
|
||||
* @copyright Copyright (c) 2019 Olegnax (http://olegnax.com/). All rights reserved.
|
||||
* @license Proprietary License https://olegnax.com/license/
|
||||
*/
|
||||
?>
|
||||
<?php if ($block->canShowBlock()): ?>
|
||||
<div class="block filter">
|
||||
<div class="block-title filter-title">
|
||||
<strong><?= /* @escapeNotVerified */
|
||||
__('Shop By') ?></strong>
|
||||
</div>
|
||||
|
||||
<div class="block-content filter-content">
|
||||
<?= $block->getChildHtml('state') ?>
|
||||
|
||||
<?php if ($block->getLayer()->getState()->getFilters()): ?>
|
||||
<div class="block-actions filter-actions">
|
||||
<a href="<?= /* @escapeNotVerified */
|
||||
$block->getClearUrl() ?>" class="action clear filter-clear"><span><?= /* @escapeNotVerified */
|
||||
__('Clear All') ?></span></a>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php $wrapOptions = false; ?>
|
||||
<?php foreach ($block->getFilters() as $filter): ?>
|
||||
<?php if (!$wrapOptions): ?>
|
||||
<strong role="heading" aria-level="2" class="block-subtitle filter-subtitle"><?= /* @escapeNotVerified */
|
||||
__('Shopping Options') ?></strong>
|
||||
<dl class="filter-options" id="narrow-by-list">
|
||||
<?php $wrapOptions = true;
|
||||
endif; ?>
|
||||
<?php if ($filter->getItemsCount()): ?>
|
||||
<dt role="heading" aria-level="3"
|
||||
class="filter-options-title"><?= $block->escapeHtml(__($filter->getName())) ?></dt>
|
||||
<dd class="filter-options-content"><?= /* @escapeNotVerified */
|
||||
$block->getChildBlock('renderer')->render($filter) ?></dd>
|
||||
<?php endif; ?>
|
||||
<?php endforeach; ?>
|
||||
<?php if ($wrapOptions): ?>
|
||||
</dl>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Olegnax
|
||||
* @package Olegnax_LayeredNavigation
|
||||
* @copyright Copyright (c) 2019 Olegnax (http://olegnax.com/). All rights reserved.
|
||||
* @license Proprietary License https://olegnax.com/license/
|
||||
*/
|
||||
|
||||
use Olegnax\LayeredNavigation\Helper\Helper;
|
||||
use Olegnax\LayeredNavigation\Model\Config\Source\LoaderType;
|
||||
|
||||
/** @var Helper $_helper */
|
||||
$config = $this->helper(Helper::class)->getModuleConfig('general');
|
||||
$configLoaders = $this->helper(Helper::class)->getModuleConfig('loaders');
|
||||
|
||||
if ('' !== $configLoaders['loader_type_filters'] && $config['enable']): ?>
|
||||
<script data-role="ox-nav-loader-filter" type="text/x-magento-template">
|
||||
<div class="ox-product-nav ox-product-nav-filter ox-product-nav__loader--<?= $configLoaders['loader_type_filters']; ?>">
|
||||
<div class="ox-product-nav__loader">
|
||||
<?php if (LoaderType::TYPE_IMAGE == $configLoaders['loader_type_filters']): ?>
|
||||
<img src="<?= $this->getViewFileUrl($configLoaders['loader_filters']) ?>"
|
||||
class="ox-product-nav__loader-image"/>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</script>
|
||||
<?php endif;
|
||||
if ('' !== $configLoaders['loader_type_content'] && $config['enable']): ?>
|
||||
<script data-role="ox-nav-loader-content" type="text/x-magento-template">
|
||||
<div class="ox-product-nav ox-product-nav-content ox-product-nav__loader--<?= $configLoaders['loader_type_content']; ?>">
|
||||
<div class="ox-product-nav__loader">
|
||||
<?php if (LoaderType::TYPE_IMAGE == $configLoaders['loader_type_content']): ?>
|
||||
<img src="<?= $this->getViewFileUrl($configLoaders['loader_content']) ?>"
|
||||
class="ox-product-nav__loader-image"/>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</script>
|
||||
<?php endif;
|
||||
if ('' !== $configLoaders['loader_type_page'] && $config['enable']): ?>
|
||||
<script data-role="ox-nav-loader-page" type="text/x-magento-template">
|
||||
<div class="ox-product-nav ox-product-nav-page ox-product-nav__loader--<?= $configLoaders['loader_type_page']; ?>">
|
||||
<div class="ox-product-nav__loader">
|
||||
<?php if (LoaderType::TYPE_IMAGE == $configLoaders['loader_type_page']): ?>
|
||||
<img src="<?= $this->getViewFileUrl($configLoaders['loader_page']) ?>"
|
||||
class="ox-product-nav__loader-image"/>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</script>
|
||||
<?php endif;
|
||||
Executable
+109
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Olegnax
|
||||
* @package Olegnax_LayeredNavigation
|
||||
* @copyright Copyright (c) 2019 Olegnax (http://olegnax.com/). All rights reserved.
|
||||
* @license Proprietary License https://olegnax.com/license/
|
||||
*/
|
||||
|
||||
// @codingStandardsIgnoreFile
|
||||
|
||||
/** @var $block RenderLayered */
|
||||
|
||||
use Magento\Swatches\Block\LayeredNavigation\RenderLayered; ?>
|
||||
<?php $swatchData = $block->getSwatchData(); ?>
|
||||
<div class="swatch-attribute swatch-layered <?= /* @escapeNotVerified */
|
||||
$swatchData['attribute_code'] ?>"
|
||||
attribute-code="<?= /* @escapeNotVerified */
|
||||
$swatchData['attribute_code'] ?>"
|
||||
attribute-id="<?= /* @escapeNotVerified */
|
||||
$swatchData['attribute_id'] ?>">
|
||||
<div class="swatch-attribute-options clearfix">
|
||||
<?php foreach ($swatchData['options'] as $option => $label): ?>
|
||||
<a href="<?= /* @escapeNotVerified */
|
||||
$label['link'] ?>"
|
||||
aria-label="<?= /* @escapeNotVerified */
|
||||
$label['label'] ?>"
|
||||
class="swatch-option-link-layered">
|
||||
<?php if (isset($swatchData['swatches'][$option]['type'])) { ?>
|
||||
<?php switch ($swatchData['swatches'][$option]['type']) {
|
||||
case '3':
|
||||
?>
|
||||
<div class="swatch-option <?= /* @escapeNotVerified */
|
||||
$label['custom_style'] ?>"
|
||||
tabindex="-1"
|
||||
data-option-type="3"
|
||||
data-option-id="<?= /* @escapeNotVerified */
|
||||
$option ?>"
|
||||
data-option-label="<?= /* @escapeNotVerified */
|
||||
$label['label'] ?>"
|
||||
data-option-tooltip-thumb=""
|
||||
data-option-tooltip-value=""
|
||||
></div>
|
||||
<?php break;
|
||||
case '2':
|
||||
?>
|
||||
<?php $swatchThumbPath = $block->getSwatchPath('swatch_thumb',
|
||||
$swatchData['swatches'][$option]['value']); ?>
|
||||
<?php $swatchImagePath = $block->getSwatchPath('swatch_image',
|
||||
$swatchData['swatches'][$option]['value']); ?>
|
||||
<div class="swatch-option image <?= /* @escapeNotVerified */
|
||||
$label['custom_style'] ?>"
|
||||
tabindex="-1"
|
||||
data-option-type="2"
|
||||
data-option-id="<?= /* @escapeNotVerified */
|
||||
$option ?>"
|
||||
data-option-label="<?= /* @escapeNotVerified */
|
||||
$label['label'] ?>"
|
||||
data-option-tooltip-thumb="<?= /* @escapeNotVerified */
|
||||
$swatchThumbPath ?>"
|
||||
data-option-tooltip-value=""
|
||||
style="background: url(<?= /* @escapeNotVerified */
|
||||
$swatchImagePath ?>) no-repeat center; background-size: initial;"></div>
|
||||
<?php break;
|
||||
case '1':
|
||||
?>
|
||||
<div class="swatch-option color <?= /* @escapeNotVerified */
|
||||
$label['custom_style'] ?>"
|
||||
tabindex="-1"
|
||||
data-option-type="1"
|
||||
data-option-id="<?= /* @escapeNotVerified */
|
||||
$option ?>"
|
||||
data-option-label="<?= /* @escapeNotVerified */
|
||||
$label['label'] ?>"
|
||||
data-option-tooltip-thumb=""
|
||||
data-option-tooltip-value="<?= /* @escapeNotVerified */
|
||||
$swatchData['swatches'][$option]['value'] ?>"
|
||||
style="background: <?= /* @escapeNotVerified */
|
||||
$swatchData['swatches'][$option]['value'] ?> no-repeat center; background-size: initial;"></div>
|
||||
<?php break;
|
||||
case '0':
|
||||
default:
|
||||
?>
|
||||
<div class="swatch-option text <?= /* @escapeNotVerified */
|
||||
$label['custom_style'] ?>"
|
||||
tabindex="-1"
|
||||
data-option-type="0"
|
||||
data-option-id="<?= /* @escapeNotVerified */
|
||||
$option ?>"
|
||||
data-option-label="<?= /* @escapeNotVerified */
|
||||
$label['label'] ?>"
|
||||
data-option-tooltip-thumb=""
|
||||
data-option-tooltip-value=""
|
||||
><?= /* @escapeNotVerified */
|
||||
$swatchData['swatches'][$option]['value'] ?></div>
|
||||
<?php break;
|
||||
} ?>
|
||||
<?php } ?>
|
||||
</a>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
require(["jquery", "jquery-ui-modules/widget", "Magento_Swatches/js/swatch-renderer"], function ($) {
|
||||
$('.swatch-layered.<?= /* @escapeNotVerified */ $swatchData['attribute_code'] ?>')
|
||||
.find('[data-option-type="1"], [data-option-type="2"], [data-option-type="0"], [data-option-type="3"]')
|
||||
.SwatchRendererTooltip();
|
||||
});
|
||||
</script>
|
||||
+135
@@ -0,0 +1,135 @@
|
||||
// /**
|
||||
// * Olegnax Layeren Navigation
|
||||
// * Copyright (c) Olegnax. All rights reserved.
|
||||
// */
|
||||
|
||||
@import '_noui-slider.less';
|
||||
|
||||
//
|
||||
// Variables
|
||||
// _____________________________________________
|
||||
|
||||
@css-preloader-color: #000000;
|
||||
@css-preloader-size: 35px;
|
||||
@css-preloader-border-size: 4px;
|
||||
|
||||
//
|
||||
// Common
|
||||
// _____________________________________________
|
||||
|
||||
& when (@media-common = true) {
|
||||
|
||||
.column.main .products.products-grid,
|
||||
.column.main .products.products-list,
|
||||
.column.main .products-grid.grid,
|
||||
.sidebar.sidebar-main .block.filter {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.ox-product-nav {
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
z-index: 100;
|
||||
background: rgba(255, 255, 255, 0.5);
|
||||
top:0;
|
||||
left:0;
|
||||
|
||||
&.ox-product-nav-page {
|
||||
position: fixed;
|
||||
z-index: 99999;
|
||||
}
|
||||
|
||||
.ox-product-nav__loader {
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
top: 50%;
|
||||
transform: translate3d(-50%, -50%, 0);
|
||||
}
|
||||
|
||||
&.ox-product-nav__loader--magento {
|
||||
.ox-product-nav__loader {
|
||||
.lib-loading();
|
||||
width: @loader-icon__width;
|
||||
height: @loader-icon__height;
|
||||
margin-top: 0;
|
||||
}
|
||||
}
|
||||
|
||||
&.ox-product-nav__loader--css {
|
||||
.ox-product-nav__loader {
|
||||
display: block;
|
||||
width: @css-preloader-size;
|
||||
height: @css-preloader-size;
|
||||
border: @css-preloader-border-size solid rgba(0, 0, 0, 0);
|
||||
border-radius: @css-preloader-size;
|
||||
border-left: @css-preloader-border-size solid @css-preloader-color;
|
||||
border-right: @css-preloader-border-size solid @css-preloader-color;
|
||||
border-top: @css-preloader-border-size solid @css-preloader-color;
|
||||
animation: spin .65s infinite linear;
|
||||
transition: all 600ms ease-in-out;
|
||||
margin-left: -17px;
|
||||
margin-top: -17px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.filter-options-content{
|
||||
.item {
|
||||
&.item-price-slider {
|
||||
display: block;
|
||||
padding-right: 3px;
|
||||
}
|
||||
&[class*='ox-item-level-']{
|
||||
padding-left: 30px;
|
||||
}
|
||||
&.ox-item-level-,
|
||||
&.ox-item-level-0{
|
||||
padding-left: 0;
|
||||
}
|
||||
&.ox-item-level-1{
|
||||
padding-left: 12px;
|
||||
}
|
||||
&.ox-item-level-2{
|
||||
padding-left: 24px;
|
||||
}
|
||||
}
|
||||
.ox-layered__items--checkbox{
|
||||
.item{
|
||||
input{
|
||||
position: absolute;
|
||||
opacity: 0;
|
||||
cursor: pointer;
|
||||
height: 0;
|
||||
width: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.ox-price-filter__values {
|
||||
text-align: left;
|
||||
overflow: hidden;
|
||||
|
||||
.ox-slider-min {
|
||||
float: left;
|
||||
}
|
||||
|
||||
.ox-slider-max {
|
||||
float: right;
|
||||
}
|
||||
|
||||
.ox-slider-max,
|
||||
.ox-slider-min {
|
||||
opacity: 0.6;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
from {
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
}
|
||||
+425
@@ -0,0 +1,425 @@
|
||||
// /**
|
||||
// * Olegnax Layeren Navigation - noUiSlider
|
||||
// * Copyright (c) Olegnax. All rights reserved.
|
||||
// */
|
||||
|
||||
@main_color: #ffe51e;
|
||||
|
||||
//
|
||||
// Common
|
||||
// _____________________________________________
|
||||
|
||||
& when (@media-common = true) {
|
||||
/* Offset direction
|
||||
*/
|
||||
|
||||
html:not([dir="rtl"]) .filter-options-content .noUi-horizontal .noUi-origin {
|
||||
left: auto;
|
||||
right: 0;
|
||||
}
|
||||
html:not([dir="rtl"]) .filter-options-content .noUi-horizontal .noUi-handle {
|
||||
right: -6px;
|
||||
left: auto;
|
||||
}
|
||||
.filter-options-content{
|
||||
.noUi-target,
|
||||
.noUi-target * {
|
||||
-webkit-touch-callout: none;
|
||||
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
|
||||
-webkit-user-select: none;
|
||||
-ms-touch-action: none;
|
||||
touch-action: none;
|
||||
-ms-user-select: none;
|
||||
-moz-user-select: none;
|
||||
user-select: none;
|
||||
-moz-box-sizing: border-box;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.noUi-target {
|
||||
position: relative;
|
||||
direction: ltr;
|
||||
&.noUi-horizontal{
|
||||
margin: 10px 6px 45px;
|
||||
}
|
||||
}
|
||||
.noUi-base,
|
||||
.noUi-connects {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
/* Wrapper for all connect elements.
|
||||
*/
|
||||
|
||||
.noUi-connects {
|
||||
overflow: hidden;
|
||||
z-index: 0;
|
||||
}
|
||||
|
||||
.noUi-connect,
|
||||
.noUi-origin {
|
||||
will-change: transform;
|
||||
position: absolute;
|
||||
z-index: 1;
|
||||
top: 0;
|
||||
left: 0;
|
||||
-ms-transform-origin: 0 0;
|
||||
-webkit-transform-origin: 0 0;
|
||||
-webkit-transform-style: preserve-3d;
|
||||
transform-origin: 0 0;
|
||||
transform-style: flat;
|
||||
}
|
||||
|
||||
.noUi-connect {
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.noUi-origin {
|
||||
height: 10%;
|
||||
width: 10%;
|
||||
}
|
||||
|
||||
/* Give origins 0 height/width so they don't interfere with clicking the
|
||||
* connect elements.
|
||||
*/
|
||||
|
||||
.noUi-vertical .noUi-origin {
|
||||
width: 0;
|
||||
}
|
||||
|
||||
.noUi-horizontal .noUi-origin {
|
||||
height: 0;
|
||||
}
|
||||
|
||||
.noUi-handle {
|
||||
-webkit-backface-visibility: hidden;
|
||||
backface-visibility: hidden;
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
.noUi-touch-area {
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.noUi-state-tap .noUi-connect,
|
||||
.noUi-state-tap .noUi-origin {
|
||||
-webkit-transition: transform 0.3s;
|
||||
transition: transform 0.3s;
|
||||
}
|
||||
|
||||
.noUi-state-drag * {
|
||||
cursor: inherit !important;
|
||||
}
|
||||
|
||||
/* Slider size and handle placement;
|
||||
*/
|
||||
|
||||
.noUi-horizontal {
|
||||
height: 18px;
|
||||
}
|
||||
|
||||
.noUi-horizontal .noUi-handle {
|
||||
width: 12px;
|
||||
height: 18px;
|
||||
left: -6px;
|
||||
top: -6px;
|
||||
cursor: w-resize;
|
||||
}
|
||||
|
||||
.noUi-vertical {
|
||||
width: 18px;
|
||||
}
|
||||
|
||||
.noUi-vertical .noUi-handle {
|
||||
width: 28px;
|
||||
height: 34px;
|
||||
left: -6px;
|
||||
top: -17px;
|
||||
}
|
||||
|
||||
/* Styling;
|
||||
* Giving the connect element a border radius causes issues with using transform: scale
|
||||
*/
|
||||
|
||||
.noUi-target {
|
||||
background: #e4e4e4;
|
||||
border-radius: 0;
|
||||
border: none;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
.noUi-connects {
|
||||
border-radius: 0;
|
||||
}
|
||||
|
||||
.noUi-connect {
|
||||
background: @main_color;
|
||||
}
|
||||
|
||||
/* Handles and cursors;
|
||||
*/
|
||||
|
||||
.noUi-draggable {
|
||||
cursor: ew-resize;
|
||||
}
|
||||
.ox-price-filter__values{
|
||||
display: none;
|
||||
}
|
||||
|
||||
.noUi-vertical .noUi-draggable {
|
||||
cursor: ns-resize;
|
||||
}
|
||||
|
||||
.noUi-handle {
|
||||
border: none;
|
||||
border-radius: 0;
|
||||
background: #000000;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
.noUi-handle{
|
||||
.noUi-tooltip{
|
||||
opacity:0;
|
||||
transition:opacity 200ms ease;
|
||||
}
|
||||
&.noUi-active,
|
||||
&:hover{
|
||||
.noUi-tooltip{
|
||||
opacity:1;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
.noUi-active {
|
||||
background: @main_color;
|
||||
}*/
|
||||
|
||||
/* Handle stripes;
|
||||
*/
|
||||
|
||||
/*
|
||||
.noUi-handle:before,
|
||||
.noUi-handle:after {
|
||||
content: "";
|
||||
display: block;
|
||||
position: absolute;
|
||||
height: 14px;
|
||||
width: 1px;
|
||||
background: #E8E7E6;
|
||||
left: 14px;
|
||||
top: 6px;
|
||||
}*/
|
||||
|
||||
.noUi-handle:after {
|
||||
left: 17px;
|
||||
}
|
||||
|
||||
.noUi-vertical .noUi-handle:before,
|
||||
.noUi-vertical .noUi-handle:after {
|
||||
width: 14px;
|
||||
height: 1px;
|
||||
left: 6px;
|
||||
top: 14px;
|
||||
}
|
||||
|
||||
.noUi-vertical .noUi-handle:after {
|
||||
top: 17px;
|
||||
}
|
||||
|
||||
/* Disabled state;
|
||||
*/
|
||||
|
||||
[disabled] .noUi-connect {
|
||||
background: #B8B8B8;
|
||||
}
|
||||
|
||||
[disabled].noUi-target,
|
||||
[disabled].noUi-handle,
|
||||
[disabled] .noUi-handle {
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
/* Base;
|
||||
*
|
||||
*/
|
||||
.noUi-pips,
|
||||
.noUi-pips * {
|
||||
-moz-box-sizing: border-box;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.noUi-pips {
|
||||
position: absolute;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
/* Values;
|
||||
*
|
||||
*/
|
||||
|
||||
.noUi-value {
|
||||
position: absolute;
|
||||
white-space: nowrap;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.noUi-value-sub {
|
||||
color: #ccc;
|
||||
font-size: 10px;
|
||||
}
|
||||
|
||||
/* Markings;
|
||||
*
|
||||
*/
|
||||
|
||||
.noUi-marker {
|
||||
position: absolute;
|
||||
background: #e4e4e4;
|
||||
}
|
||||
|
||||
.noUi-marker-sub {
|
||||
background: #AAA;
|
||||
}
|
||||
|
||||
.noUi-marker-large {
|
||||
background: #e4e4e4;
|
||||
}
|
||||
|
||||
/* Horizontal layout;
|
||||
*
|
||||
*/
|
||||
|
||||
.noUi-pips-horizontal {
|
||||
padding: 10px 0;
|
||||
height: 35px;
|
||||
top: 100%;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.noUi-value-horizontal {
|
||||
-webkit-transform: translate(0, 17px);
|
||||
transform: translate(0, 17px);
|
||||
margin-left: -3px;
|
||||
}
|
||||
.noUi-pips-horizontal{
|
||||
.noUi-value-horizontal:last-child {
|
||||
-webkit-transform: translate(-100%, 17px);
|
||||
transform: translate(-100%, 17px);
|
||||
margin-left: 3px;
|
||||
}
|
||||
}
|
||||
.noUi-rtl .noUi-value-horizontal {
|
||||
-webkit-transform: translate(50%, 50%);
|
||||
transform: translate(50%, 50%);
|
||||
}
|
||||
|
||||
.noUi-marker-horizontal.noUi-marker {
|
||||
margin-left: -1px;
|
||||
width: 2px;
|
||||
height: 5px;
|
||||
}
|
||||
|
||||
.noUi-marker-horizontal.noUi-marker-sub {
|
||||
height: 10px;
|
||||
}
|
||||
|
||||
.noUi-marker-horizontal.noUi-marker-large {
|
||||
height: 12px;
|
||||
}
|
||||
|
||||
/* Vertical layout;
|
||||
*
|
||||
*/
|
||||
|
||||
.noUi-pips-vertical {
|
||||
padding: 0 10px;
|
||||
height: 100%;
|
||||
top: 0;
|
||||
left: 100%;
|
||||
}
|
||||
|
||||
.noUi-value-vertical {
|
||||
-webkit-transform: translate(0, -50%);
|
||||
transform: translate(0, -50%);
|
||||
padding-left: 25px;
|
||||
}
|
||||
|
||||
.noUi-rtl .noUi-value-vertical {
|
||||
-webkit-transform: translate(0, 50%);
|
||||
transform: translate(0, 50%);
|
||||
}
|
||||
|
||||
.noUi-marker-vertical.noUi-marker {
|
||||
width: 5px;
|
||||
height: 2px;
|
||||
margin-top: -1px;
|
||||
}
|
||||
|
||||
.noUi-marker-vertical.noUi-marker-sub {
|
||||
width: 10px;
|
||||
}
|
||||
|
||||
.noUi-marker-vertical.noUi-marker-large {
|
||||
width: 15px;
|
||||
}
|
||||
|
||||
.noUi-tooltip {
|
||||
display: block;
|
||||
position: absolute;
|
||||
border: none;
|
||||
border-radius: 0;
|
||||
background: #000;
|
||||
color: #fff;
|
||||
padding: 5px 6px;
|
||||
line-height: 1;
|
||||
text-align: center;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.noUi-horizontal .noUi-tooltip {
|
||||
-webkit-transform: translate(-50%, 0);
|
||||
transform: translate(-50%, 0);
|
||||
left: 50%;
|
||||
bottom: 110%;
|
||||
}
|
||||
|
||||
.noUi-vertical .noUi-tooltip {
|
||||
-webkit-transform: translate(0, -50%);
|
||||
transform: translate(0, -50%);
|
||||
top: 50%;
|
||||
right: 120%;
|
||||
}
|
||||
/* hide pips options */
|
||||
.hide-pips{
|
||||
.noUi-pips{
|
||||
&.noUi-pips-horizontal{
|
||||
padding: 15px 0 0 0;
|
||||
}
|
||||
.noUi-value-horizontal{
|
||||
-webkit-transform: none;
|
||||
transform: none;
|
||||
}
|
||||
.noUi-marker{
|
||||
display:none;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* always show tooltips */
|
||||
.tooltip-always-show{
|
||||
.noUi-handle{
|
||||
.noUi-tooltip{
|
||||
opacity:1;
|
||||
}
|
||||
}
|
||||
noUi-target.noUi-horizontal{
|
||||
margin-top:20px;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,352 @@
|
||||
/**
|
||||
* Olegnax Layered Navigation
|
||||
* Copyright (c) 2019 Olegnax (http://olegnax.com/). All rights reserved.
|
||||
*/
|
||||
define([
|
||||
'jquery',
|
||||
'Magento_Theme/js/view/messages',
|
||||
'ko',
|
||||
'jquery-ui-modules/widget',
|
||||
'jquery-ui-modules/core',
|
||||
'oxFormValues'
|
||||
], function ($, messenger, ko) {
|
||||
'use strict';
|
||||
|
||||
$.widget('mage.OXAjaxNav', {
|
||||
options: {
|
||||
filterNavInputClass: '.block.filter .filter-options-content .item input[name^=filter]',
|
||||
filterClearAllClass: '.block.filter .filter-actions a.action.filter-clear',
|
||||
filterCurrentClass: '.block.filter .filter-current .item a.action',
|
||||
filters: [
|
||||
'.block.filter .filter-options-content .item a',
|
||||
'.block.filter .swatch-attribute a'
|
||||
],
|
||||
replaceSelectors: {
|
||||
leftnav: '.sidebar.sidebar-main .block.filter, [data-move-mobile="filtersslideout"] .block.filter.filters-slideout-content.ox-move-item',
|
||||
title: '.column.main .page-title-wrapper',
|
||||
breadcrumbs: '.column.main .breadcrumbs'
|
||||
},
|
||||
replaceContentSelectors: {
|
||||
products: '.column.main .search.results, .column.main'
|
||||
},
|
||||
clearUrl: null,
|
||||
timeout: 300,
|
||||
scrollToTop: true,
|
||||
loaderFilter: false,
|
||||
loaderContent: false,
|
||||
loaderPage: false,
|
||||
abortPrev: true,
|
||||
loaderContentSelector: '',
|
||||
selectedItemClass: 'ox-seleted-item'
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
_create: function () {
|
||||
this._loader_template_filter = '[data-role="ox-nav-loader-filter"]';
|
||||
this._loader_template_content = '[data-role="ox-nav-loader-content"]';
|
||||
this._loader_template_page = '[data-role="ox-nav-loader-page"]';
|
||||
this._loader_class_filter = '.ox-product-nav-filter';
|
||||
this._loader_class_content = '.ox-product-nav-content';
|
||||
this._loader_class_page = '.ox-product-nav-page';
|
||||
this._disable_class = 'ox-disable-ajax';
|
||||
this._current_count = '.filter-current-count';
|
||||
this._current_item = '.filter-current .item';
|
||||
this._use_url_class = 'ox-nav-use-url';
|
||||
this.timeoutID = null;
|
||||
|
||||
if (!this.options.clearUrl) {
|
||||
this.options.clearUrl = window.location.href;
|
||||
}
|
||||
this.afterUpdate();
|
||||
this._event();
|
||||
},
|
||||
/**
|
||||
* Set events
|
||||
* @private
|
||||
*/
|
||||
_event: function () {
|
||||
var _self = this;
|
||||
this.element.off('filter_apply.OXAjaxNav').on('filter_apply.OXAjaxNav', $.proxy(function (event, values, url) {
|
||||
var _url = url || this.options.clearUrl;
|
||||
this.getDebounceContent(_url, values);
|
||||
}, this));
|
||||
this.element.off('change.OXAjaxNav', this.options.filterNavInputClass).on('change.OXAjaxNav', this.options.filterNavInputClass, $.proxy(function (event) {
|
||||
var $this = $(event.currentTarget),
|
||||
values = _self.getAllFilter(),
|
||||
url;
|
||||
if ($this.hasClass(this._use_url_class)) {
|
||||
url = window.location.href;
|
||||
}
|
||||
$this.closest('li').eq(0).toggleClass(this.options.selectedItemClass, $this.prop('checked'));
|
||||
_self.element.trigger('filter_apply.OXAjaxNav', [values, url]);
|
||||
}, this));
|
||||
this.element.off('click.OXAjaxNav', this.options.filters.join(', ')).on('click.OXAjaxNav', this.options.filters.join(', '), $.proxy(function (event) {
|
||||
var $this = $(event.currentTarget).addClass(this.options.selectedItemClass),
|
||||
url = $this.attr('href');
|
||||
|
||||
if (url && !$this.hasClass(this._disable_class)) {
|
||||
event.preventDefault();
|
||||
var values = this._parseQueryString(url);
|
||||
_self.element.trigger('filter_apply.OXAjaxNav', values);
|
||||
}
|
||||
}, this));
|
||||
this.element.off('click.OXAjaxNav', this.options.filterCurrentClass).on('click.OXAjaxNav', this.options.filterCurrentClass, $.proxy(function (event) {
|
||||
var $this = $(event.currentTarget),
|
||||
url = $this.attr('href');
|
||||
|
||||
if (url && !$this.hasClass(this._disable_class)) {
|
||||
event.preventDefault();
|
||||
var values = this._parseQueryString(url);
|
||||
this.element.trigger('filter_apply.OXAjaxNav', values, url);
|
||||
}
|
||||
}, this));
|
||||
this.element.off('click.OXAjaxNav', this.options.filterClearAllClass).on('click.OXAjaxNav', this.options.filterClearAllClass, $.proxy(function (event) {
|
||||
var $this = $(event.currentTarget),
|
||||
url = $this.attr('href');
|
||||
|
||||
if (url && !$this.hasClass(this._disable_class)) {
|
||||
event.preventDefault();
|
||||
this.element.trigger('filter_apply.OXAjaxNav', null, url);
|
||||
}
|
||||
}, this));
|
||||
},
|
||||
/**
|
||||
* Update url current page
|
||||
* @param string url
|
||||
* @param object data
|
||||
*/
|
||||
updateUrl: function (url, data) {
|
||||
var _url = url || this.options.clearUrl,
|
||||
_data = data || {};
|
||||
|
||||
if (data.hasOwnProperty('navAjax')) {
|
||||
delete data.navAjax;
|
||||
}
|
||||
var new_url = new URL(_url);
|
||||
$.each(_data, function (i, v) {
|
||||
if (Array.isArray(v)) {
|
||||
new_url.searchParams.set(i, v.join(','));
|
||||
} else {
|
||||
new_url.searchParams.set(i, v);
|
||||
}
|
||||
});
|
||||
|
||||
if (typeof history.replaceState === 'function') {
|
||||
history.replaceState(null, null, new_url.toString());
|
||||
}
|
||||
return new_url.toString();
|
||||
},
|
||||
/**
|
||||
* Get url attributes
|
||||
* @param string url
|
||||
* @return string
|
||||
* @private
|
||||
*/
|
||||
_parseQueryString: function (url) {
|
||||
return $.getURLValues(url);
|
||||
},
|
||||
getAllFilter: function () {
|
||||
var values = this.element.find(this.options.filterNavInputClass).getFormValues();
|
||||
if (values.hasOwnProperty('filter')) {
|
||||
values = values.filter;
|
||||
$.each(values, function (i, v) {
|
||||
if ('object' === typeof v) {
|
||||
var _v = [];
|
||||
$.each(v, function (i, v) {
|
||||
_v.push(v);
|
||||
});
|
||||
values[i] = _v.join(',');
|
||||
} else if (!values[i]) {
|
||||
delete values[i];
|
||||
}
|
||||
});
|
||||
|
||||
return values;
|
||||
}
|
||||
|
||||
return {};
|
||||
},
|
||||
getDebounceContent: function (url, data, timeout) {
|
||||
var _url = url || this.options.clearUrl,
|
||||
_data = data || {},
|
||||
_timeout = timeout || this.options.timeout,
|
||||
_self = this;
|
||||
|
||||
clearTimeout(this.timeoutID);
|
||||
this.timeoutID = setTimeout(function () {
|
||||
_self.getContent.call(_self, _url, _data);
|
||||
}, _timeout);
|
||||
|
||||
},
|
||||
getContent: function (url, data) {
|
||||
this.startLoading();
|
||||
if (this.options.scrollToTop) {
|
||||
$(document).scrollTop(0);
|
||||
}
|
||||
var _url = url || this.options.clearUrl,
|
||||
_data = data || {},
|
||||
_self = this;
|
||||
this.current_filters = _data;
|
||||
_data['navAjax'] = 1;
|
||||
|
||||
var timestamp = new Date().getTime();
|
||||
this.lastTimestamp = timestamp;
|
||||
if (this.options.abortPrev && this.xhr)
|
||||
this.xhr.abort();
|
||||
this.xhr = $.ajax({
|
||||
url: _url,
|
||||
data: _data,
|
||||
cache: true,
|
||||
dataType: 'json',
|
||||
success: function (response) {
|
||||
if (_self.lastUpdate && _self.lastUpdate > timestamp)
|
||||
return;
|
||||
_self.lastUpdate = timestamp;
|
||||
if (response.hasOwnProperty('html')) {
|
||||
_self.replaceHTML(response.html);
|
||||
} else {
|
||||
if (response.hasOwnProperty('msg')) {
|
||||
_self.setMessage({
|
||||
type: 'error',
|
||||
text: response.msg
|
||||
});
|
||||
}
|
||||
}
|
||||
if (this.lastTimestamp > timestamp)
|
||||
return;
|
||||
_self.updateUrl(_url, data);
|
||||
_self.afterUpdate();
|
||||
_self.element.trigger('filter_applied.OXAjaxNav', response);
|
||||
$('body').trigger('contentUpdated').trigger('OxInfiniteScroll');
|
||||
_self.stopLoading();
|
||||
},
|
||||
error: function (response) {
|
||||
_self.element.trigger('filter_error.OXAjaxNav', response);
|
||||
_self.setMessage({
|
||||
type: 'error',
|
||||
text: 'Sorry, something went wrong. Please try again later.'
|
||||
});
|
||||
window.location = _self.updateUrl(_url, data);
|
||||
}
|
||||
});
|
||||
},
|
||||
setMessage: function (obj) {
|
||||
messenger().messages({
|
||||
messages: ko.observableArray([obj])
|
||||
});
|
||||
},
|
||||
_createLoader: function (loader, parent) {
|
||||
if (!this.hasOwnProperty('_loader_class_' + loader)) {
|
||||
return;
|
||||
}
|
||||
var parent = parent || 'body',
|
||||
$parent = $(parent),
|
||||
$loader = $parent.children(this['_loader_class_' + loader]);
|
||||
if (!$loader.length) {
|
||||
var content = $(this['_loader_template_' + loader]).html();
|
||||
$(content).prependTo($parent);
|
||||
$loader = $parent.children(this['_loader_class_' + loader]);
|
||||
}
|
||||
return $loader;
|
||||
},
|
||||
|
||||
startLoading: function () {
|
||||
if (this.options.loaderFilter) {
|
||||
this._createLoader('filter', this.options.replaceSelectors.leftnav).show();
|
||||
}
|
||||
if (this.options.loaderContent && this.options.loaderContentSelector) {
|
||||
this._createLoader('content', this.options.loaderContentSelector).show();
|
||||
}
|
||||
if (this.options.loaderPage) {
|
||||
this._createLoader('page').show();
|
||||
}
|
||||
},
|
||||
stopLoading: function () {
|
||||
if (this.options.loaderFilter) {
|
||||
this._createLoader('filter', this.options.replaceSelectors.leftnav).hide();
|
||||
}
|
||||
if (this.options.loaderContent && this.options.loaderContentSelector) {
|
||||
this._createLoader('content', this.options.loaderContentSelector).hide();
|
||||
}
|
||||
if (this.options.loaderPage) {
|
||||
this._createLoader('page').hide();
|
||||
}
|
||||
},
|
||||
replaceHTML: function (data) {
|
||||
$.each(data, $.proxy(function (key, html) {
|
||||
if (this.options.replaceSelectors.hasOwnProperty(key)) {
|
||||
var $element = $(this.options.replaceSelectors[key]);
|
||||
|
||||
if ($element.length) {
|
||||
$element.replaceWith(html);
|
||||
$element.trigger('contentUpdated');
|
||||
}
|
||||
} else if ('_before' === key || '_after' === key) {
|
||||
if ('_before' === key && html) {
|
||||
$(this.options.replaceContentSelectors.products).before(html);
|
||||
} else if (html) {
|
||||
$(this.options.replaceContentSelectors.products).after(html);
|
||||
}
|
||||
} else if (html) {
|
||||
var $elementParent;
|
||||
if (this.options.replaceContentSelectors.hasOwnProperty(key)) {
|
||||
$elementParent = $(this.options.replaceContentSelectors[key]).last();
|
||||
}
|
||||
var createSelector = function (a) {
|
||||
if (!a.prop('tagName'))
|
||||
return;
|
||||
var _id = a.attr('id') || '',
|
||||
_class = (a.attr('class') || '').replace(/\s+/g, ' ').replace(/ /g, '.'),
|
||||
_selector = a.prop('tagName') + (_id ? '#' + _id : '') + (_class ? '.' + _class : '');
|
||||
return _selector;
|
||||
};
|
||||
var items = {},
|
||||
parent,
|
||||
first = true,
|
||||
prevElement;
|
||||
$(html).each(function () {
|
||||
var $html = $(this),
|
||||
selector = createSelector($html);
|
||||
if (!selector)
|
||||
return;
|
||||
if (/^script/i.test(selector)) {
|
||||
$elementParent.append($html);
|
||||
return;
|
||||
}
|
||||
var $element = $(selector);
|
||||
if ($elementParent.length) {
|
||||
$element = $elementParent.find(selector);
|
||||
}
|
||||
if (0 < $element.length) {
|
||||
if (1 == $element.length) {
|
||||
$element.replaceWith($html);
|
||||
prevElement = selector;
|
||||
} else {
|
||||
var $element = $(prevElement);
|
||||
if ($elementParent.length) {
|
||||
$element = $elementParent.find(prevElement);
|
||||
}
|
||||
$element = $element.next(selector);
|
||||
if (0 < $element.length) {
|
||||
$element.replaceWith($html);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$elementParent.append($html);
|
||||
}
|
||||
});
|
||||
}
|
||||
}, this));
|
||||
},
|
||||
afterUpdate: function () {
|
||||
var count = $(this._current_item).length;
|
||||
$(this._current_count).html(count ? count : "");
|
||||
$(this.options.replaceSelectors.leftnav).data('moveDesktopParent', $('.sidebar.sidebar-main').eq(0));
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
return $.mage.OXAjaxNav;
|
||||
});
|
||||
@@ -0,0 +1,61 @@
|
||||
define([
|
||||
'jquery',
|
||||
], function ($) {
|
||||
'use strict';
|
||||
$.getValues = function (query) {
|
||||
var query = query || '',
|
||||
vars = query.split('&'),
|
||||
result = {},
|
||||
getName = function (name) {
|
||||
var regex;
|
||||
|
||||
if ((regex = /^(.+?)\[(.*?)$/).test(name)) {
|
||||
name = name.match(regex);
|
||||
name[2] = name[2].replace(/\]/g, '').split('[');
|
||||
name[2].unshift(name[1]);
|
||||
name = name[2].map(function (v) {
|
||||
return '' === v ? 0 : v;
|
||||
});
|
||||
} else {
|
||||
name = [name];
|
||||
}
|
||||
|
||||
return name;
|
||||
},
|
||||
setValue = function (form, names, value) {
|
||||
var name = names.shift();
|
||||
|
||||
if (names.length) {
|
||||
var _form = form.hasOwnProperty(name) ? form[name] : {};
|
||||
form[name] = setValue(_form, names, value);
|
||||
} else {
|
||||
if (0 === name) {
|
||||
for (; form.hasOwnProperty(name); name++) {
|
||||
}
|
||||
}
|
||||
form[name] = value;
|
||||
}
|
||||
|
||||
return form
|
||||
};
|
||||
for (var i = 0; i < vars.length; i++)
|
||||
if (vars[i].length) {
|
||||
var pair = vars[i].split('=').map(decodeURIComponent);
|
||||
result = setValue(result, getName(pair[0]), pair[1]);
|
||||
}
|
||||
|
||||
return $.extend(true, {}, result);
|
||||
|
||||
};
|
||||
$.getURLValues = function (href) {
|
||||
var href = href || window.location.href,
|
||||
url = new URL(href);
|
||||
return $.getValues(url.search.replace(/^\?/, ''));
|
||||
};
|
||||
|
||||
$.fn.getFormValues = function () {
|
||||
return $.getValues($(this).serialize());
|
||||
};
|
||||
|
||||
return $.fn.getFormValues;
|
||||
});
|
||||
+2
File diff suppressed because one or more lines are too long
@@ -0,0 +1,111 @@
|
||||
/**
|
||||
* Olegnax Layered Navigation - Price Slider
|
||||
* Copyright (c) 2019 Olegnax (http://olegnax.com/). All rights reserved.
|
||||
*/
|
||||
define([
|
||||
'jquery',
|
||||
'noUiSlider',
|
||||
'wNumb',
|
||||
'jquery-ui-modules/core',
|
||||
'jquery-ui-modules/widget',
|
||||
], function ($, noUiSlider, wNumb) {
|
||||
'use strict';
|
||||
|
||||
$.widget('mage.OXPriceSlider', {
|
||||
options: {
|
||||
//slider
|
||||
animate: true,
|
||||
min: 0,
|
||||
max: 100,
|
||||
current: null,
|
||||
step: 1,
|
||||
//format
|
||||
formatMoney: {
|
||||
decimals: 2
|
||||
},
|
||||
//html
|
||||
class_slider: ".ox-price-slider",
|
||||
class_value: "input[name='filter[price]']",
|
||||
class_label_scale: ".ox-price-filter__values",
|
||||
class_label: ".ox-price-filter__selected",
|
||||
class_from_label: ".ox-slider-from",
|
||||
class_to_label: ".ox-slider-to",
|
||||
|
||||
},
|
||||
_create: function () {
|
||||
this.slider_element = this.element.find(this.options.class_slider);
|
||||
this.value_element = this.element.find(this.options.class_value);
|
||||
this.label_element = this.element.find(this.options.class_label);
|
||||
this.min_label_element = this.label_element.find(this.options.class_from_label);
|
||||
this.max_label_element = this.label_element.find(this.options.class_to_label);
|
||||
|
||||
var values = this.value_element.val();
|
||||
values = values ? values.split('-').map(parseFloat) : null;
|
||||
|
||||
this.options.min = parseFloat(this.options.min);
|
||||
this.options.max = parseFloat(this.options.max);
|
||||
this.options.step = parseFloat(this.options.step);
|
||||
this.options.current = this.options.current || values || [this.options.min, this.options.max];
|
||||
|
||||
this.element.find('input').hide();
|
||||
|
||||
this.slider_element.show();
|
||||
this.wNumb = wNumb(this.options.formatMoney);
|
||||
var slider = this.slider_element[0];
|
||||
|
||||
|
||||
noUiSlider.create(slider, {
|
||||
start: this.options.current,
|
||||
step: 1,
|
||||
connect: true,
|
||||
range: {
|
||||
'min': this.options.min,
|
||||
'max': this.options.max
|
||||
},
|
||||
tooltips: [true, this.wNumb],
|
||||
pips: {
|
||||
mode: 'positions',
|
||||
values: [0, 100],
|
||||
density: 4,
|
||||
format: this.wNumb
|
||||
}
|
||||
});
|
||||
this.sliderCreate();
|
||||
slider.noUiSlider.on('change.OXPriceSlider', $.proxy(this.sliderChange, this));
|
||||
},
|
||||
sliderCreate: function () {
|
||||
this.change_label(this.options.current);
|
||||
this.element.trigger('price_slider_create', this.options.current);
|
||||
},
|
||||
sliderSlide: function (values) {
|
||||
this.change(values, 'price_slider_slide');
|
||||
},
|
||||
sliderChange: function (values) {
|
||||
this.change(values, 'price_slider_change');
|
||||
},
|
||||
change: function (values, event) {
|
||||
this.change_value(values, 'price_slider_change' === event);
|
||||
this.change_label(values);
|
||||
if ('string' == typeof event && event) {
|
||||
this.element.trigger(event, values);
|
||||
}
|
||||
},
|
||||
change_value: function (values, run) {
|
||||
values = values.join('-');
|
||||
this.value_element.val(values);
|
||||
if (run) {
|
||||
this.value_element.trigger('change');
|
||||
}
|
||||
},
|
||||
|
||||
change_label: function (values) {
|
||||
this.min_label_element.html(this.wNumb.to(values[0]));
|
||||
this.max_label_element.html(this.wNumb.to(values[1]));
|
||||
this.label_element.show();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
return $.mage.OXPriceSlider;
|
||||
|
||||
});
|
||||
@@ -0,0 +1,20 @@
|
||||
define([
|
||||
'jquery'
|
||||
], function ($) {
|
||||
'use strict';
|
||||
|
||||
return function (widget) {
|
||||
$.widget('mage.SwatchRenderer', widget, {
|
||||
_RenderControls: function () {
|
||||
var container = this.element,
|
||||
classes = this.options.classes;
|
||||
if (container.find('.' + classes.attributeClass).length) {
|
||||
return;
|
||||
}
|
||||
return this._super();
|
||||
}
|
||||
});
|
||||
|
||||
return $.mage.SwatchRenderer;
|
||||
}
|
||||
});
|
||||
+1
@@ -0,0 +1 @@
|
||||
!function(e){"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?module.exports=e():window.wNumb=e()}(function(){"use strict";var o=["decimals","thousand","mark","prefix","suffix","encoder","decoder","negativeBefore","negative","edit","undo"];function w(e){return e.split("").reverse().join("")}function h(e,t){return e.substring(0,t.length)===t}function f(e,t,n){if((e[t]||e[n])&&e[t]===e[n])throw new Error(t)}function x(e){return"number"==typeof e&&isFinite(e)}function n(e,t,n,r,i,o,f,u,s,c,a,p){var d,l,h,g=p,v="",m="";return o&&(p=o(p)),!!x(p)&&(!1!==e&&0===parseFloat(p.toFixed(e))&&(p=0),p<0&&(d=!0,p=Math.abs(p)),!1!==e&&(p=function(e,t){return e=e.toString().split("e"),(+((e=(e=Math.round(+(e[0]+"e"+(e[1]?+e[1]+t:t)))).toString().split("e"))[0]+"e"+(e[1]?e[1]-t:-t))).toFixed(t)}(p,e)),-1!==(p=p.toString()).indexOf(".")?(h=(l=p.split("."))[0],n&&(v=n+l[1])):h=p,t&&(h=w((h=w(h).match(/.{1,3}/g)).join(w(t)))),d&&u&&(m+=u),r&&(m+=r),d&&s&&(m+=s),m+=h,m+=v,i&&(m+=i),c&&(m=c(m,g)),m)}function r(e,t,n,r,i,o,f,u,s,c,a,p){var d,l="";return a&&(p=a(p)),!(!p||"string"!=typeof p)&&(u&&h(p,u)&&(p=p.replace(u,""),d=!0),r&&h(p,r)&&(p=p.replace(r,"")),s&&h(p,s)&&(p=p.replace(s,""),d=!0),i&&function(e,t){return e.slice(-1*t.length)===t}(p,i)&&(p=p.slice(0,-1*i.length)),t&&(p=p.split(t).join("")),n&&(p=p.replace(n,".")),d&&(l+="-"),""!==(l=(l+=p).replace(/[^0-9\.\-.]/g,""))&&(l=Number(l),f&&(l=f(l)),!!x(l)&&l))}function i(e,t,n){var r,i=[];for(r=0;r<o.length;r+=1)i.push(e[o[r]]);return i.push(n),t.apply("",i)}return function e(t){if(!(this instanceof e))return new e(t);"object"==typeof t&&(t=function(e){var t,n,r,i={};for(void 0===e.suffix&&(e.suffix=e.postfix),t=0;t<o.length;t+=1)if(void 0===(r=e[n=o[t]]))"negative"!==n||i.negativeBefore?"mark"===n&&"."!==i.thousand?i[n]=".":i[n]=!1:i[n]="-";else if("decimals"===n){if(!(0<=r&&r<8))throw new Error(n);i[n]=r}else if("encoder"===n||"decoder"===n||"edit"===n||"undo"===n){if("function"!=typeof r)throw new Error(n);i[n]=r}else{if("string"!=typeof r)throw new Error(n);i[n]=r}return f(i,"mark","thousand"),f(i,"prefix","negative"),f(i,"prefix","negativeBefore"),i}(t),this.to=function(e){return i(t,n,e)},this.from=function(e){return i(t,r,e)})}});
|
||||
Reference in New Issue
Block a user