init
This commit is contained in:
+91
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
namespace WeltPixel\LayeredNavigation\Block\Adminhtml\Product\Attribute\Edit\Tab;
|
||||
|
||||
use Magento\Backend\Block\Template\Context;
|
||||
use Magento\Backend\Block\Widget\Form\Generic;
|
||||
use Magento\Catalog\Model\Entity\Attribute;
|
||||
use Magento\Framework\Data\FormFactory;
|
||||
use Magento\Framework\Registry;
|
||||
|
||||
/**
|
||||
* @api
|
||||
* @since 100.0.2
|
||||
*/
|
||||
class Options extends Generic implements \Magento\Backend\Block\Widget\Tab\TabInterface
|
||||
{
|
||||
/**
|
||||
* @param Context $context
|
||||
* @param Registry $registry
|
||||
* @param FormFactory $formFactory
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(
|
||||
Context $context,
|
||||
Registry $registry,
|
||||
FormFactory $formFactory,
|
||||
array $data = []
|
||||
) {
|
||||
parent::__construct($context, $registry, $formFactory, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return Tab label
|
||||
*
|
||||
* @return string
|
||||
* @api
|
||||
*/
|
||||
public function getTabLabel() {
|
||||
return __('WeltPixel Layered Navigation Properties');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return Tab title
|
||||
*
|
||||
* @return string
|
||||
* @api
|
||||
*/
|
||||
public function getTabTitle() {
|
||||
return __('WeltPixel Layered Navigation Properties');
|
||||
}
|
||||
|
||||
/**
|
||||
* Can show tab in tabs
|
||||
*
|
||||
* @return boolean
|
||||
* @api
|
||||
*/
|
||||
public function canShowTab() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tab is hidden
|
||||
*
|
||||
* @return boolean
|
||||
* @api
|
||||
*/
|
||||
public function isHidden() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* @return $this
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
*/
|
||||
protected function _prepareForm()
|
||||
{
|
||||
/** @var Attribute $attributeObject */
|
||||
$attributeObject = $this->_coreRegistry->registry('entity_attribute');
|
||||
|
||||
/** @var \Magento\Framework\Data\Form $form */
|
||||
$form = $this->_formFactory->create(
|
||||
['data' => ['id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post']]
|
||||
);
|
||||
$this->_eventManager->dispatch('product_attribute_form_build_weltpixel_layerednavigation_tab', ['form' => $form]);
|
||||
|
||||
$this->setForm($form);
|
||||
$form->setValues($attributeObject->getData());
|
||||
return parent::_prepareForm();
|
||||
}
|
||||
}
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
/**
|
||||
* @category WeltPixel
|
||||
* @package WeltPixel_LayeredNavigation
|
||||
* @copyright Copyright (c) 2018 Weltpixel
|
||||
* @author Weltpixel TEAM
|
||||
*/
|
||||
namespace WeltPixel\LayeredNavigation\Block\LayeredNavigation;
|
||||
|
||||
use Magento\Eav\Model\Entity\Attribute;
|
||||
use Magento\Catalog\Model\ResourceModel\Layer\Filter\AttributeFactory;
|
||||
use Magento\Framework\View\Element\Template;
|
||||
|
||||
/**
|
||||
* Class RenderLayered
|
||||
* @package WeltPixel\LayeredNavigation\Block\LayeredNavigation
|
||||
*/
|
||||
class RenderLayered extends \Magento\Swatches\Block\LayeredNavigation\RenderLayered
|
||||
{
|
||||
|
||||
/**
|
||||
* Path to template file.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_template = 'WeltPixel_LayeredNavigation::product/layered/renderer.phtml';
|
||||
|
||||
/**
|
||||
* @var \WeltPixel\LayeredNavigation\Model\AttributeOptions
|
||||
*/
|
||||
protected $_attributeOptions;
|
||||
|
||||
/**
|
||||
* RenderLayered constructor.
|
||||
* @param Template\Context $context
|
||||
* @param Attribute $eavAttribute
|
||||
* @param AttributeFactory $layerAttribute
|
||||
* @param \Magento\Swatches\Helper\Data $swatchHelper
|
||||
* @param \Magento\Swatches\Helper\Media $mediaHelper
|
||||
* @param \WeltPixel\LayeredNavigation\Model\AttributeOptions $attributeOptions
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(
|
||||
\Magento\Framework\View\Element\Template\Context $context,
|
||||
Attribute $eavAttribute,
|
||||
AttributeFactory $layerAttribute,
|
||||
\Magento\Swatches\Helper\Data $swatchHelper,
|
||||
\Magento\Swatches\Helper\Media $mediaHelper,
|
||||
\WeltPixel\LayeredNavigation\Model\AttributeOptions $attributeOptions,
|
||||
array $data = []
|
||||
) {
|
||||
$this->eavAttribute = $eavAttribute;
|
||||
$this->layerAttribute = $layerAttribute;
|
||||
$this->swatchHelper = $swatchHelper;
|
||||
$this->mediaHelper = $mediaHelper;
|
||||
$this->_attributeOptions = $attributeOptions;
|
||||
|
||||
parent::__construct($context,$eavAttribute,$layerAttribute,$swatchHelper,$mediaHelper, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* return the 'Is Multiselect' attribute configuration value
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getIsMultiSelect($attrId)
|
||||
{
|
||||
return ($attrId > 0) ? $this->getWpAttributeOptions($attrId)->getIsMultiselect() : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return wp attribute options
|
||||
*
|
||||
* @param $attributeId
|
||||
* @return mixed
|
||||
*/
|
||||
public function getWpAttributeOptions($attrId)
|
||||
{
|
||||
$this->_attributeOptionsObj = ($attrId > 0) ? $this->_attributeOptions->getDisplayOptionsByAttribute($attrId) : '';
|
||||
|
||||
return $this->_attributeOptionsObj;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
/**
|
||||
* @category WeltPixel
|
||||
* @package WeltPixel_LayeredNavigation
|
||||
* @copyright Copyright (c) 2018 Weltpixel
|
||||
* @author Weltpixel TEAM
|
||||
*/
|
||||
namespace WeltPixel\LayeredNavigation\Block;
|
||||
use Magento\Framework\View\Element\Template\Context;
|
||||
use WeltPixel\LayeredNavigation\Helper\Data;
|
||||
class LayeredNavigationAdd extends \Magento\Framework\View\Element\Template
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\App\Config\ScopeConfigInterface
|
||||
*/
|
||||
protected $_scopeConfig;
|
||||
/**
|
||||
* @var Data
|
||||
*/
|
||||
protected $_wpHelper;
|
||||
/**
|
||||
* AjaxInfiniteScroll constructor.
|
||||
* @param Context $context
|
||||
* @param Data $helper
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(
|
||||
Context $context,
|
||||
Data $helper,
|
||||
array $data = []
|
||||
) {
|
||||
$this->_scopeConfig = $context->getScopeConfig();
|
||||
$this->_wpHelper = $helper;
|
||||
parent::__construct($context, $data);
|
||||
}
|
||||
/**
|
||||
* check if module enabled and ajax mode is enabled
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isLnEnabled() {
|
||||
$is = false;
|
||||
if($this->_wpHelper->isEnabled()) {
|
||||
$is = ($this->_wpHelper->isAjaxEnabled()) ? true : false;
|
||||
}
|
||||
return $is;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,240 @@
|
||||
<?php
|
||||
/**
|
||||
* @category WeltPixel
|
||||
* @package WeltPixel_LayeredNavigation
|
||||
* @copyright Copyright (c) 2018 Weltpixel
|
||||
* @author Weltpixel TEAM
|
||||
*/
|
||||
|
||||
namespace WeltPixel\LayeredNavigation\Block;
|
||||
|
||||
use Magento\Catalog\Model\Product\ProductList\Toolbar as ToolbarModel;
|
||||
use Magento\Catalog\Helper\Product\ProductList;
|
||||
use Magento\Customer\Model\Session;
|
||||
use WeltPixel\LayeredNavigation\Block\Navigation\FilterRenderer;
|
||||
|
||||
/**
|
||||
* Class Navigation
|
||||
* @package WeltPixel\LayeredNavigation\Block
|
||||
*/
|
||||
class Navigation extends \Magento\LayeredNavigation\Block\Navigation
|
||||
{
|
||||
/**
|
||||
* Catalog layer
|
||||
*
|
||||
* @var \Magento\Catalog\Model\Layer
|
||||
*/
|
||||
protected $_catalogLayer;
|
||||
|
||||
/**
|
||||
* @var \Magento\Catalog\Model\Layer\FilterList
|
||||
*/
|
||||
protected $filterList;
|
||||
|
||||
/**
|
||||
* @var \Magento\Catalog\Model\Layer\AvailabilityFlagInterface
|
||||
*/
|
||||
protected $visibilityFlag;
|
||||
|
||||
/**
|
||||
* @var ProductList
|
||||
*/
|
||||
protected $_productListHelper;
|
||||
|
||||
/**
|
||||
* Default Order field
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_orderField = null;
|
||||
|
||||
/**
|
||||
* Default direction
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_direction = ProductList::DEFAULT_SORT_DIRECTION;
|
||||
|
||||
/**
|
||||
* @var \WeltPixel\LayeredNavigation\Helper\Data
|
||||
*/
|
||||
protected $_wpHelper;
|
||||
|
||||
/**
|
||||
* @var \WeltPixel\LayeredNavigation\Model\AttributeOptions
|
||||
*/
|
||||
protected $_attributeOptions;
|
||||
|
||||
/**
|
||||
* Navigation constructor.
|
||||
* @param \Magento\Framework\View\Element\Template\Context $context
|
||||
* @param \Magento\Catalog\Model\Layer\Resolver $layerResolver
|
||||
* @param \Magento\Catalog\Model\Layer\FilterList $filterList
|
||||
* @param \Magento\Catalog\Model\Layer\AvailabilityFlagInterface $visibilityFlag
|
||||
* @param ProductList $productListHelper
|
||||
* @param \WeltPixel\LayeredNavigation\Helper\Data $wpHelper
|
||||
* @param \WeltPixel\LayeredNavigation\Model\AttributeOptions $attributeOptions
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(
|
||||
\Magento\Framework\View\Element\Template\Context $context,
|
||||
\Magento\Catalog\Model\Layer\Resolver $layerResolver,
|
||||
\Magento\Catalog\Model\Layer\FilterList $filterList,
|
||||
\Magento\Catalog\Model\Layer\AvailabilityFlagInterface $visibilityFlag,
|
||||
ProductList $productListHelper,
|
||||
\WeltPixel\LayeredNavigation\Helper\Data $wpHelper,
|
||||
\WeltPixel\LayeredNavigation\Model\AttributeOptions $attributeOptions,
|
||||
protected Session $customerSession,
|
||||
array $data = []
|
||||
)
|
||||
{
|
||||
$this->_catalogLayer = $layerResolver->get();
|
||||
$this->filterList = $filterList;
|
||||
$this->visibilityFlag = $visibilityFlag;
|
||||
$this->_productListHelper = $productListHelper;
|
||||
$this->_wpHelper = $wpHelper;
|
||||
$this->_attributeOptions = $attributeOptions;
|
||||
parent::__construct($context, $layerResolver, $filterList, $visibilityFlag, $data);
|
||||
}
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function isCategoryFilterVisible()
|
||||
{
|
||||
return $this->_wpHelper->showCategoriesBlock();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function isAjaxMode()
|
||||
{
|
||||
return $this->_wpHelper->isAjaxEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* check if current filter is a category filter
|
||||
*
|
||||
* @param $filter
|
||||
* @return bool
|
||||
*/
|
||||
public function isCategoryFilter($filter)
|
||||
{
|
||||
return ($filter->getRequestVar() == 'cat') ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Magento\Framework\Phrase|string
|
||||
*/
|
||||
public function getFilterButtonHtml()
|
||||
{
|
||||
return $this->_wpHelper->getFilterButtonStyle();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return wp attribute options
|
||||
*
|
||||
* @param $attributeId
|
||||
* @return mixed
|
||||
*/
|
||||
public function getWpAttributeOptions($attributeId)
|
||||
{
|
||||
return $this->_attributeOptions->getDisplayOptionsByAttribute($attributeId);
|
||||
}
|
||||
|
||||
/**
|
||||
* set filter tab status
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
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) {
|
||||
$wpOptions = $this->getWpAttributeOptions($attributeId);
|
||||
if($wpOptions->getData()) {
|
||||
|
||||
if($wpOptions->getDisplayOption() == '1' || $wpOptions->getDisplayOption() == '2') {
|
||||
$activeFilters[] = $ctr;
|
||||
}
|
||||
}
|
||||
}
|
||||
$ctr++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$activeFiltersStr = implode(' ', $activeFilters);
|
||||
|
||||
return $activeFiltersStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return current URL with rewrites and additional parameters
|
||||
*
|
||||
* @param array $params Query parameters
|
||||
* @return string
|
||||
*/
|
||||
public function getPagerUrl($params = [])
|
||||
{
|
||||
$urlParams = [];
|
||||
$urlParams['_current'] = true;
|
||||
$urlParams['_escape'] = false;
|
||||
$urlParams['_use_rewrite'] = true;
|
||||
$urlParams['_query'] = $params;
|
||||
return $this->getUrl('*/*/*', $urlParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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' => ToolbarModel::MODE_PARAM_NAME,
|
||||
'direction' => ToolbarModel::DIRECTION_PARAM_NAME,
|
||||
'order' => ToolbarModel::ORDER_PARAM_NAME,
|
||||
'limit' => ToolbarModel::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]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get order field
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
protected function getOrderField()
|
||||
{
|
||||
if ($this->_orderField === null) {
|
||||
$this->_orderField = $this->_productListHelper->getDefaultSortField();
|
||||
}
|
||||
return $this->_orderField;
|
||||
}
|
||||
|
||||
public function getRedirectUrl()
|
||||
{
|
||||
$redirectUrl = $this->customerSession->getData(FilterRenderer::CATEGORY_OPTION_REDIRECT_URL_KEY);
|
||||
$this->customerSession->getData(FilterRenderer::CATEGORY_OPTION_REDIRECT_URL_KEY, true);
|
||||
return $redirectUrl;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
<?php
|
||||
/**
|
||||
* @category WeltPixel
|
||||
* @package WeltPixel_LayeredNavigation
|
||||
* @copyright Copyright (c) 2018 Weltpixel
|
||||
* @author Weltpixel TEAM
|
||||
*/
|
||||
|
||||
namespace WeltPixel\LayeredNavigation\Block\Navigation;
|
||||
|
||||
use Magento\Customer\Model\Session;
|
||||
use Magento\Eav\Model\Config;
|
||||
use Magento\Framework\View\Element\Template;
|
||||
|
||||
/**
|
||||
* Class FilterRenderer
|
||||
* @package WeltPixel\LayeredNavigation\Block\Navigation
|
||||
*/
|
||||
class FilterRenderer extends \Magento\LayeredNavigation\Block\Navigation\FilterRenderer
|
||||
{
|
||||
/**
|
||||
* @var \WeltPixel\LayeredNavigation\Helper\Data
|
||||
*/
|
||||
protected $_wpHelper;
|
||||
|
||||
/**
|
||||
* @var \WeltPixel\LayeredNavigation\Model\AttributeOptions
|
||||
*/
|
||||
protected $_attributeOptions;
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
protected $_attributeId;
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
protected $_attributeOptionsObj;
|
||||
|
||||
const CATEGORY_OPTION_REDIRECT_URL_KEY = 'category_option_redirect_url';
|
||||
|
||||
/**
|
||||
* FilterRenderer constructor.
|
||||
* @param \WeltPixel\LayeredNavigation\Helper\Data $wpHelper
|
||||
* @param \WeltPixel\LayeredNavigation\Model\AttributeOptions $attributeOptions
|
||||
* @param Template\Context $context
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(
|
||||
\WeltPixel\LayeredNavigation\Helper\Data $wpHelper,
|
||||
\WeltPixel\LayeredNavigation\Model\AttributeOptions $attributeOptions,
|
||||
Template\Context $context,
|
||||
protected Config $eavConfig,
|
||||
protected Session $customerSession,
|
||||
array $data = []
|
||||
)
|
||||
{
|
||||
$this->_wpHelper = $wpHelper;
|
||||
$this->_attributeOptions = $attributeOptions;
|
||||
|
||||
parent::__construct($context, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $filter
|
||||
*/
|
||||
public function setAttributeId($filter)
|
||||
{
|
||||
$this->_attributeId = ($filter->getRequestVar() != 'cat') ? $filter->getAttributeModel()->getAttributeId() : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return wp attribute options
|
||||
*
|
||||
* @param $attributeId
|
||||
* @return mixed
|
||||
*/
|
||||
public function getWpAttributeOptions()
|
||||
{
|
||||
$this->_attributeOptionsObj = ($this->_attributeId > 0) ? $this->_attributeOptions->getDisplayOptionsByAttribute($this->_attributeId) : '';
|
||||
|
||||
return $this->_attributeOptionsObj;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getAttributeId()
|
||||
{
|
||||
return $this->_attributeId;
|
||||
}
|
||||
|
||||
/**
|
||||
* return the 'Visible Options' attribute configuration value
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getVisibleItems()
|
||||
{
|
||||
if ($this->_attributeId > 0) {
|
||||
$attributeOptions = $this->getWpAttributeOptions();
|
||||
if ($attributeOptions) {
|
||||
return $attributeOptions->getVisibleOptions();
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* return the 'Visible Options Step' attribute configuration value
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getVisibleItemsStep()
|
||||
{
|
||||
if ($this->_attributeId > 0) {
|
||||
$attributeOptions = $this->getWpAttributeOptions();
|
||||
if ($attributeOptions) {
|
||||
return $attributeOptions->getVisibleOptionsStep();
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* return the 'Show Qty' attribute configuration value
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getShowQty()
|
||||
{
|
||||
if ($this->_attributeId > 0) {
|
||||
$attributeOptions = $this->getWpAttributeOptions();
|
||||
if ($attributeOptions) {
|
||||
return $attributeOptions->getShowQuantity();
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* return the 'Is Multiselect' attribute configuration value
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getIsMultiSelect()
|
||||
{
|
||||
if ($this->_attributeId > 0) {
|
||||
$attributeOptions = $this->getWpAttributeOptions();
|
||||
if ($attributeOptions) {
|
||||
return $attributeOptions->getIsMultiselect();
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
public function getAttribute()
|
||||
{
|
||||
return $this->eavConfig->getAttribute(\Magento\Catalog\Model\Product::ENTITY, $this->_attributeId);
|
||||
}
|
||||
|
||||
public function setRedirectUrl(string $url)
|
||||
{
|
||||
$this->customerSession->setData(self::CATEGORY_OPTION_REDIRECT_URL_KEY, $url);
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/**
|
||||
* @category WeltPixel
|
||||
* @package WeltPixel_LayeredNavigation
|
||||
* @copyright Copyright (c) 2018 Weltpixel
|
||||
* @author Weltpixel TEAM
|
||||
*/
|
||||
namespace WeltPixel\LayeredNavigation\Block\Navigation;
|
||||
|
||||
/**
|
||||
* Layered navigation state
|
||||
*
|
||||
* @api
|
||||
* @since 100.0.2
|
||||
*/
|
||||
class State extends \Magento\LayeredNavigation\Block\Navigation\State
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_template = 'WeltPixel_LayeredNavigation::layer/state.phtml';
|
||||
|
||||
/**
|
||||
* Catalog layer
|
||||
*
|
||||
* @var \Magento\Catalog\Model\Layer
|
||||
*/
|
||||
protected $_catalogLayer;
|
||||
|
||||
/**
|
||||
* @var \WeltPixel\LayeredNavigation\Helper\Data
|
||||
*/
|
||||
protected $_wpHelper;
|
||||
|
||||
/**
|
||||
* @param \Magento\Framework\View\Element\Template\Context $context
|
||||
* @param \Magento\Catalog\Model\Layer\Resolver $layerResolver
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(
|
||||
\Magento\Framework\View\Element\Template\Context $context,
|
||||
\Magento\Catalog\Model\Layer\Resolver $layerResolver,
|
||||
\WeltPixel\LayeredNavigation\Helper\Data $wpHelper,
|
||||
array $data = []
|
||||
) {
|
||||
$this->_catalogLayer = $layerResolver->get();
|
||||
$this->_wpHelper = $wpHelper;
|
||||
parent::__construct($context,$layerResolver, $data);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
/**
|
||||
* @category WeltPixel
|
||||
* @package WeltPixel_LayeredNavigation
|
||||
* @copyright Copyright (c) 2018 Weltpixel
|
||||
* @author Weltpixel TEAM
|
||||
*/
|
||||
|
||||
namespace WeltPixel\LayeredNavigation\Block\System\Config\Form\Field;
|
||||
|
||||
use Magento\Framework\Data\Form\Element\AbstractElement;
|
||||
|
||||
/**
|
||||
* Class Disable
|
||||
* @package WeltPixel\LayerdNavigation\Block\System\Config\Form\Field
|
||||
*/
|
||||
class Disable extends \Magento\Config\Block\System\Config\Form\Field
|
||||
{
|
||||
protected function _getElementHtml(AbstractElement $element)
|
||||
{
|
||||
$element->setDisabled('disabled');
|
||||
return $element->getElementHtml();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
Important notes:
|
||||
- Extension files for Magento versions 2.4 or higher.
|
||||
- Files NOT compatible with Magento version 2.0 - 2.3.x.
|
||||
- Using different set of files for each Magento version for best performance.
|
||||
@@ -0,0 +1,200 @@
|
||||
<?php
|
||||
/**
|
||||
* @category WeltPixel
|
||||
* @package WeltPixel_LayeredNavigation
|
||||
* @copyright Copyright (c) 2018 Weltpixel
|
||||
* @author Weltpixel TEAM
|
||||
*/
|
||||
|
||||
namespace WeltPixel\LayeredNavigation\Helper;
|
||||
|
||||
use Magento\Store\Model\ScopeInterface;
|
||||
use \Magento\CatalogSearch\Model\ResourceModel\EngineInterface;
|
||||
|
||||
/**
|
||||
* Class Data
|
||||
* @package WeltPixel\LayeredNavigation\Helper
|
||||
*/
|
||||
class Data extends \Magento\Framework\App\Helper\AbstractHelper
|
||||
{
|
||||
const FILTER_TYPE_SLIDER = 'slider';
|
||||
const FILTER_TYPE_LIST = 'list';
|
||||
const SLIDE_IN_STYLE = 1;
|
||||
const FILTER_BUTTON_LABEL = 'Filter';
|
||||
|
||||
protected $_currentEngine = '';
|
||||
|
||||
/**
|
||||
* @var \Magento\Store\Model\StoreManagerInterface
|
||||
*/
|
||||
protected $_storeManager;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $_storeId;
|
||||
|
||||
/**
|
||||
* @var Config
|
||||
*/
|
||||
private $pageConfig;
|
||||
|
||||
|
||||
/**
|
||||
* Data constructor.
|
||||
* @param \Magento\Framework\App\Helper\Context $context
|
||||
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
|
||||
*/
|
||||
public function __construct(
|
||||
\Magento\Framework\App\Helper\Context $context,
|
||||
\Magento\Store\Model\StoreManagerInterface $storeManager,
|
||||
\Magento\Framework\View\Page\Config $pageConfig
|
||||
)
|
||||
{
|
||||
$this->_storeManager = $storeManager;
|
||||
$this->pageConfig = $pageConfig;
|
||||
parent::__construct($context);
|
||||
|
||||
$this->_storeId = $this->getCurrentStoreId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return current store_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getCurrentStoreId()
|
||||
{
|
||||
return $this->_storeManager->getStore()->getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $storeId
|
||||
* @return mixed
|
||||
*/
|
||||
public function isEnabled($storeId = null)
|
||||
{
|
||||
return $this->scopeConfig->getValue('weltpixel_layerednavigation/general/enable', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $storeId
|
||||
* @return mixed
|
||||
*/
|
||||
public function isAjaxEnabled($storeId = null)
|
||||
{
|
||||
return $this->scopeConfig->getValue('weltpixel_layerednavigation/general/ajax', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $storeId
|
||||
* @return mixed
|
||||
*/
|
||||
public function showCategoriesBlock($storeId = null)
|
||||
{
|
||||
return $this->scopeConfig->getValue('weltpixel_layerednavigation/sidebar/category_block', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $storeId
|
||||
* @return mixed
|
||||
*/
|
||||
public function showCompareBlock($storeId = null)
|
||||
{
|
||||
return $this->scopeConfig->getValue('weltpixel_layerednavigation/sidebar/compare_block', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $storeId
|
||||
* @return mixed
|
||||
*/
|
||||
public function showWishlistBlock($storeId = null)
|
||||
{
|
||||
return $this->scopeConfig->getValue('weltpixel_layerednavigation/sidebar/wishlist_block', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $storeId
|
||||
* @return mixed
|
||||
*/
|
||||
public function showRecentlyOrderedBlock($storeId = null)
|
||||
{
|
||||
return $this->scopeConfig->getValue('weltpixel_layerednavigation/sidebar/recentlyordered_block', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $storeId
|
||||
* @return mixed
|
||||
*/
|
||||
public function getFilterButton($storeId = null)
|
||||
{
|
||||
return $this->scopeConfig->getValue('weltpixel_layerednavigation/sidebar/filter_button', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter Button option
|
||||
* 0-icon only
|
||||
* 1-icon & label
|
||||
* 2-label only
|
||||
*
|
||||
* @return \Magento\Framework\Phrase|string
|
||||
*/
|
||||
public function getFilterButtonStyle()
|
||||
{
|
||||
switch ($this->getFilterButton()) {
|
||||
case 0:
|
||||
$filterButtonHtml = "<b class='wp-slide-in'></b>";
|
||||
break;
|
||||
case 1:
|
||||
$filterButtonHtml = "<b class='wp-slide-in'></b><b class='wp-filters-text'>" . /* @escapeNotVerified */
|
||||
__(self::FILTER_BUTTON_LABEL) . "</b>";
|
||||
break;
|
||||
case 2:
|
||||
$filterButtonHtml = __(self::FILTER_BUTTON_LABEL);
|
||||
break;
|
||||
default:
|
||||
$filterButtonHtml = '';
|
||||
}
|
||||
|
||||
return $filterButtonHtml;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the engine provider is 'elasticsearch'
|
||||
* @deprecated
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isElasticSearchEngine()
|
||||
{
|
||||
if (!$this->_currentEngine) {
|
||||
$this->_currentEngine = $this->scopeConfig->getValue(EngineInterface::CONFIG_ENGINE_PATH, ScopeInterface::SCOPE_STORE);
|
||||
}
|
||||
if($this->_currentEngine == 'elasticsearch' || $this->_currentEngine == 'elasticsearch5'
|
||||
|| $this->_currentEngine == 'elasticsearch6' || $this->_currentEngine == 'elasticsearch7' ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the engine provider is 'elasticsearch' or 'opensearch'
|
||||
* @deprecated
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isElasticOrOpenSearchEngine()
|
||||
{
|
||||
if (!$this->_currentEngine) {
|
||||
$this->_currentEngine = $this->scopeConfig->getValue(EngineInterface::CONFIG_ENGINE_PATH, ScopeInterface::SCOPE_STORE);
|
||||
}
|
||||
if($this->_currentEngine == 'elasticsearch' || $this->_currentEngine == 'elasticsearch5'
|
||||
|| $this->_currentEngine == 'elasticsearch6' || $this->_currentEngine == 'elasticsearch7' || $this->_currentEngine == 'opensearch' ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/**
|
||||
* @category WeltPixel
|
||||
* @package WeltPixel_LayeredNavigation
|
||||
* @copyright Copyright (c) 2018 Weltpixel
|
||||
* @author Weltpixel TEAM
|
||||
*/
|
||||
|
||||
namespace WeltPixel\LayeredNavigation\Model;
|
||||
|
||||
class AttributeOptions extends \Magento\Framework\Model\AbstractModel implements \Magento\Framework\DataObject\IdentityInterface
|
||||
{
|
||||
const CACHE_TAG = 'weltpixel_ln_attribute_options';
|
||||
const DISPLAY_OPTION_DEF_VAL = 0;
|
||||
const DISPLAY_OPTION_OPEN_VAL = 1;
|
||||
const VISIBLE_OPTIONS_DEF_VAL = 99;
|
||||
const VISIBLE_OPTIONS_STEP_DEF_VAL = 99;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_cacheTag = 'weltpixel_ln_attribute_options';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_eventPrefix = 'weltpixel_ln_attribute_options';
|
||||
|
||||
protected function _construct()
|
||||
{
|
||||
$this->_init('WeltPixel\LayeredNavigation\Model\ResourceModel\AttributeOptions');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|string[]
|
||||
*/
|
||||
public function getIdentities()
|
||||
{
|
||||
return [self::CACHE_TAG . '_' . $this->getId()];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $attributeId
|
||||
* @return $this
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
*/
|
||||
public function getDisplayOptionsByAttribute($attributeId) {
|
||||
$this->_getResource()->loadDisplayOptionsByAttribute($this, $attributeId);
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* @category WeltPixel
|
||||
* @package WeltPixel_LayeredNavigation
|
||||
* @copyright Copyright (c) 2018 Weltpixel
|
||||
* @author Weltpixel TEAM
|
||||
*/
|
||||
|
||||
namespace WeltPixel\LayeredNavigation\Model\Config\Source;
|
||||
|
||||
use Magento\Framework\Option\ArrayInterface;
|
||||
|
||||
/**
|
||||
* Class FilterButton
|
||||
* @package WeltPixel\LayeredNavigation\Model\Config\Source
|
||||
*/
|
||||
class FilterButton implements ArrayInterface
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $_styles = array(
|
||||
0 => 'Icon Only',
|
||||
1 => 'Icon + Label',
|
||||
2 => 'Label Only',
|
||||
);
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toOptionArray()
|
||||
{
|
||||
$options = array();
|
||||
foreach ($this->_styles as $id => $style) :
|
||||
$options[] = array(
|
||||
'value' => $id,
|
||||
'label' => $style
|
||||
);
|
||||
endforeach;
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* @category WeltPixel
|
||||
* @package WeltPixel_LayeredNavigation
|
||||
* @copyright Copyright (c) 2018 Weltpixel
|
||||
* @author Weltpixel TEAM
|
||||
*/
|
||||
|
||||
namespace WeltPixel\LayeredNavigation\Model\Config\Source;
|
||||
|
||||
use Magento\Framework\Option\ArrayInterface;
|
||||
|
||||
/**
|
||||
* Class FilterDisplay
|
||||
* @package WeltPixel\LayeredNavigation\Model\Config\Source
|
||||
*/
|
||||
class FilterDisplay implements ArrayInterface
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $_styles = array(
|
||||
0 => 'Close',
|
||||
1 => 'Open',
|
||||
2 => 'Expand',
|
||||
);
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toOptionArray()
|
||||
{
|
||||
$options = array();
|
||||
foreach ($this->_styles as $id => $style) :
|
||||
$options[] = array(
|
||||
'value' => $id,
|
||||
'label' => $style
|
||||
);
|
||||
endforeach;
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
* @category WeltPixel
|
||||
* @package WeltPixel_LayeredNavigation
|
||||
* @copyright Copyright (c) 2018 Weltpixel
|
||||
* @author Weltpixel TEAM
|
||||
*/
|
||||
|
||||
namespace WeltPixel\LayeredNavigation\Model\Config\Source;
|
||||
|
||||
use Magento\Framework\Option\ArrayInterface;
|
||||
|
||||
/**
|
||||
* Class SidebarStyle
|
||||
* @package WeltPixel\LayeredNavigation\Model\Config\Source
|
||||
*/
|
||||
class SidebarStyle implements ArrayInterface
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $_styles = array(
|
||||
'0' => 'Default',
|
||||
'1' => 'Slide In',
|
||||
);
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toOptionArray()
|
||||
{
|
||||
$options = array();
|
||||
foreach ($this->_styles as $id => $style) :
|
||||
$options[] = array(
|
||||
'value' => $id,
|
||||
'label' => $style
|
||||
);
|
||||
endforeach;
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
* @category WeltPixel
|
||||
* @package WeltPixel_LayeredNavigation
|
||||
* @copyright Copyright (c) 2018 Weltpixel
|
||||
* @author Weltpixel TEAM
|
||||
*/
|
||||
|
||||
namespace WeltPixel\LayeredNavigation\Model\Config\Source;
|
||||
|
||||
use Magento\Framework\Option\ArrayInterface;
|
||||
|
||||
/**
|
||||
* Class SortBy
|
||||
* @package WeltPixel\LayeredNavigation\Model\Config\Source
|
||||
*/
|
||||
class SortBy implements ArrayInterface
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $_styles = array(
|
||||
'position' => 'Position',
|
||||
'name' => 'Name'
|
||||
);
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toOptionArray()
|
||||
{
|
||||
$options = array();
|
||||
foreach ($this->_styles as $id => $style) :
|
||||
$options[] = array(
|
||||
'value' => $id,
|
||||
'label' => $style
|
||||
);
|
||||
endforeach;
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
+152
@@ -0,0 +1,152 @@
|
||||
<?php
|
||||
/**
|
||||
* @category WeltPixel
|
||||
* @package WeltPixel_LayeredNavigation
|
||||
* @copyright Copyright (c) 2018 Weltpixel
|
||||
* @author Weltpixel TEAM
|
||||
*/
|
||||
|
||||
namespace WeltPixel\LayeredNavigation\Model\Layer;
|
||||
|
||||
use Magento\Framework\App\RequestInterface;
|
||||
use WeltPixel\LayeredNavigation\Model\AttributeOptions;
|
||||
|
||||
/**
|
||||
* Class Filter
|
||||
* @package WeltPixel\LayeredNavigation\Model\Layer
|
||||
*/
|
||||
class Filter
|
||||
{
|
||||
/** @var \Magento\Framework\App\RequestInterface */
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* @var AttributeOptions
|
||||
*/
|
||||
protected $_wpAttributeOptions;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $_ids = [];
|
||||
|
||||
/**
|
||||
* Filter constructor.
|
||||
* @param RequestInterface $request
|
||||
* @param AttributeOptions $attributeOptions
|
||||
*/
|
||||
public function __construct(
|
||||
RequestInterface $request,
|
||||
AttributeOptions $attributeOptions
|
||||
)
|
||||
{
|
||||
$this->request = $request;
|
||||
$this->_wpAttributeOptions = $attributeOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get option url. If it has been filtered, return removed url. Else return filter url
|
||||
*
|
||||
* @param \Magento\Catalog\Model\Layer\Filter\Item $item
|
||||
* @return mixed
|
||||
*/
|
||||
public function getItemUrl($item)
|
||||
{
|
||||
if ($this->isSelected($item)) {
|
||||
return $item->getRemoveUrl();
|
||||
}
|
||||
|
||||
return $item->getUrl();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Magento\Catalog\Model\Layer\Filter\AbstractFilter $filter
|
||||
* @param bool|true $explode
|
||||
* @return array|mixed
|
||||
*/
|
||||
public function getFilterValue($filter, $explode = true)
|
||||
{
|
||||
$filterValue = $this->request->getParam($filter->getRequestVar());
|
||||
if (empty($filterValue)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return $explode ? explode(',', $filterValue) : $filterValue;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks whether the option reduces the number of results
|
||||
*
|
||||
* @param \Magento\Catalog\Model\Layer\Filter\AbstractFilter $filter
|
||||
* @param int $optionCount Count of search results with this option
|
||||
* @param int $totalSize Current search results count
|
||||
* @return bool
|
||||
*/
|
||||
public function isOptionReducesResults($filter, $optionCount, $totalSize)
|
||||
{
|
||||
$result = $optionCount <= $totalSize;
|
||||
|
||||
if ($this->isShowZero($filter)) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
return $optionCount && $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Magento\Catalog\Model\Layer\Filter\AbstractFilter $filter
|
||||
* @return bool
|
||||
*/
|
||||
public function isShowZero($filter)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $filter
|
||||
* @return bool
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $attrId
|
||||
*/
|
||||
public function isMultiselect($attrId) {
|
||||
$wpLnAttributeOptions = ($attrId) ? $this->_wpAttributeOptions->getDisplayOptionsByAttribute($attrId) : false;
|
||||
$isMultiselect = ($wpLnAttributeOptions) ? $wpLnAttributeOptions->getIsMultiselect() : false;
|
||||
|
||||
return $isMultiselect;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Layer $layer
|
||||
* @return array
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,271 @@
|
||||
<?php
|
||||
/**
|
||||
* @category WeltPixel
|
||||
* @package WeltPixel_LayeredNavigation
|
||||
* @copyright Copyright (c) 2018 Weltpixel
|
||||
* @author Weltpixel TEAM
|
||||
*/
|
||||
|
||||
namespace WeltPixel\LayeredNavigation\Model\Layer\Filter;
|
||||
|
||||
use Magento\Catalog\Model\Layer\Filter\AbstractFilter;
|
||||
use WeltPixel\LayeredNavigation\Helper\Data as LayerHelper;
|
||||
use WeltPixel\LayeredNavigation\Model\Layer\Filter as LayerFilter;
|
||||
use WeltPixel\LayeredNavigation\Model\AttributeOptions;
|
||||
|
||||
/**
|
||||
* Class Attribute
|
||||
* @package WeltPixel\LayeredNavigation\Model\Layer\Filter
|
||||
*/
|
||||
class Attribute extends AbstractFilter
|
||||
{
|
||||
/**
|
||||
* @var LayerHelper
|
||||
*/
|
||||
protected $_moduleHelper;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $_isFilter = true;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Filter\StripTags
|
||||
*/
|
||||
protected $tagFilter;
|
||||
|
||||
/**
|
||||
* @var LayerFilter
|
||||
*/
|
||||
protected $_layerFilter;
|
||||
|
||||
/**
|
||||
* @var AttributeOptions
|
||||
*/
|
||||
protected $_wpAttributeOptions;
|
||||
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
protected $_requestParamVal;
|
||||
|
||||
/**
|
||||
* Resource instance
|
||||
*
|
||||
* @var \Magento\Catalog\Model\ResourceModel\Layer\Filter\Attribute
|
||||
*/
|
||||
protected $_resource;
|
||||
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
protected $_originalCollection;
|
||||
|
||||
/**
|
||||
* Attribute constructor.
|
||||
* @param \Magento\Catalog\Model\Layer\Filter\ItemFactory $filterItemFactory
|
||||
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
|
||||
* @param \Magento\Catalog\Model\Layer $layer
|
||||
* @param \Magento\Catalog\Model\Layer\Filter\Item\DataBuilder $itemDataBuilder
|
||||
* @param \Magento\Framework\Filter\StripTags $tagFilter
|
||||
* @param \Magento\Catalog\Model\ResourceModel\Layer\Filter\AttributeFactory $filterAttributeFactory
|
||||
* @param LayerHelper $moduleHelper
|
||||
* @param LayerFilter $layerFilter
|
||||
* @param AttributeOptions $attributeOptions
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(
|
||||
\Magento\Catalog\Model\Layer\Filter\ItemFactory $filterItemFactory,
|
||||
\Magento\Store\Model\StoreManagerInterface $storeManager,
|
||||
\Magento\Catalog\Model\Layer $layer,
|
||||
\Magento\Catalog\Model\Layer\Filter\Item\DataBuilder $itemDataBuilder,
|
||||
\Magento\Framework\Filter\StripTags $tagFilter,
|
||||
\Magento\Catalog\Model\ResourceModel\Layer\Filter\AttributeFactory $filterAttributeFactory,
|
||||
LayerHelper $moduleHelper,
|
||||
LayerFilter $layerFilter,
|
||||
AttributeOptions $attributeOptions,
|
||||
array $data = []
|
||||
)
|
||||
{
|
||||
parent::__construct(
|
||||
$filterItemFactory,
|
||||
$storeManager,
|
||||
$layer,
|
||||
$itemDataBuilder,
|
||||
$data
|
||||
);
|
||||
$this->_resource = $filterAttributeFactory->create();
|
||||
$this->tagFilter = $tagFilter;
|
||||
$this->_moduleHelper = $moduleHelper;
|
||||
$this->_layerFilter = $layerFilter;
|
||||
$this->_wpAttributeOptions = $attributeOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function apply(\Magento\Framework\App\RequestInterface $request)
|
||||
{
|
||||
if (!$this->_moduleHelper->isEnabled()) {
|
||||
return parent::apply($request);
|
||||
}
|
||||
$attribute = $this->getAttributeModel();
|
||||
$attributeValue = $request->getParam($this->_requestVar);
|
||||
|
||||
if (empty($attributeValue)) {
|
||||
$this->_isFilter = false;
|
||||
|
||||
return $this;
|
||||
}
|
||||
$this->_requestParamVal = $this->_requestVar;
|
||||
$attributeValue = explode(',', $attributeValue);
|
||||
$state = $this->getLayer()->getState();
|
||||
foreach ($attributeValue as $value) {
|
||||
$label = $this->getOptionText($value);
|
||||
$state->addFilter($this->_createItem($label, $value));
|
||||
}
|
||||
|
||||
|
||||
if (!$this->isMultiselect($attribute->getId()) && count($attributeValue) > 1) {
|
||||
$attributeValue = array_slice($attributeValue, 0, 1);
|
||||
}
|
||||
|
||||
/** @var \Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection $productCollection */
|
||||
$productCollection = $this->getLayer()->getProductCollection();
|
||||
if(!$this->_originalCollection) {
|
||||
$this->_originalCollection = $productCollection->getCollectionClone();
|
||||
}
|
||||
if (count($attributeValue) > 1) {
|
||||
if ($this->_moduleHelper->isElasticOrOpenSearchEngine()) {
|
||||
$productCollection->addFieldToFilter($attribute->getAttributeCode(), $attributeValue);
|
||||
} else {
|
||||
$productCollection->addFieldToFilter($attribute->getAttributeCode(), ['in' => $attributeValue]);
|
||||
}
|
||||
} else {
|
||||
$productCollection->addFieldToFilter($attribute->getAttributeCode(), $attributeValue[0]);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve resource instance
|
||||
*
|
||||
* @return \Magento\Catalog\Model\ResourceModel\Layer\Filter\Attribute
|
||||
*/
|
||||
protected function _getResource()
|
||||
{
|
||||
return $this->_resource;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function _getItemsData()
|
||||
{
|
||||
if (!$this->_moduleHelper->isEnabled()) {
|
||||
return parent::_getItemsData();
|
||||
}
|
||||
$logger = \Magento\Framework\App\ObjectManager::getInstance()->get(\Psr\Log\LoggerInterface::class);
|
||||
$attribute = $this->getAttributeModel();
|
||||
$wpLnAttributeOptions = ($attribute->getId()) ? $this->_wpAttributeOptions->getDisplayOptionsByAttribute($attribute->getId()) : false;
|
||||
|
||||
if(!$wpLnAttributeOptions->getIsMultiselect() && $this->_isFilter && $attribute->getAttributeCode() != 'category_option') {
|
||||
return [];
|
||||
}
|
||||
|
||||
/** @var \WeltPixel\LayeredNavigation\Model\ResourceModel\Fulltext\Collection $productCollection */
|
||||
$productCollection = $this->getLayer()->getProductCollection();
|
||||
|
||||
if ($this->_isFilter && ( $this->_layerFilter->isMainFilter($this) || $wpLnAttributeOptions->getIsMultiselect())) {
|
||||
$productCollection = $productCollection->getCollectionClone()
|
||||
->removeAttributeSearch($attribute->getAttributeCode());
|
||||
}
|
||||
|
||||
$optionsFacetedData = $productCollection->getFacetedData($attribute->getAttributeCode());
|
||||
|
||||
if (count($optionsFacetedData) === 0
|
||||
&& $this->getAttributeIsFilterable($attribute) !== static::ATTRIBUTE_OPTIONS_ONLY_WITH_RESULTS
|
||||
) {
|
||||
return $this->itemDataBuilder->build();
|
||||
}
|
||||
|
||||
$productSize = $productCollection->getSize();
|
||||
|
||||
$itemData = [];
|
||||
$checkCount = false;
|
||||
$options = $attribute->getFrontend()->getSelectOptions();
|
||||
$counter = false;
|
||||
|
||||
foreach ($options as $option) {
|
||||
$sorted = false;
|
||||
if (empty($option['value'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$value = $option['value'];
|
||||
|
||||
if($counter) {
|
||||
$count = isset($counter[$value]) ? (int)$counter[$value] : 0;
|
||||
} else {
|
||||
$count = isset($optionsFacetedData[$value]['count']) ? (int)$optionsFacetedData[$value]['count'] : 0;
|
||||
}
|
||||
|
||||
// Check filter type
|
||||
if ($this->getAttributeIsFilterable($attribute) == static::ATTRIBUTE_OPTIONS_ONLY_WITH_RESULTS && (!$this->_layerFilter->isOptionReducesResults($this, $count, $productSize)) && $count == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($count > 0) {
|
||||
$checkCount = true;
|
||||
}
|
||||
|
||||
$itemData[] = [
|
||||
'label' => $this->tagFilter->filter($option['label']),
|
||||
'value' => $value,
|
||||
'count' => $count
|
||||
];
|
||||
}
|
||||
|
||||
if ($checkCount) {
|
||||
if ($wpLnAttributeOptions->getSortBy() == 2) {
|
||||
usort($itemData, [$this, '_compareAz']);
|
||||
$sorted = true;
|
||||
}
|
||||
foreach ($itemData as $item) {
|
||||
$this->itemDataBuilder->addItemData($item['label'], $item['value'], $item['count']);
|
||||
}
|
||||
}
|
||||
|
||||
if ($wpLnAttributeOptions->getSortBy() == 2 && !$sorted) {
|
||||
usort($options, [$this, '_compareAz']);
|
||||
}
|
||||
return $this->itemDataBuilder->build();
|
||||
}
|
||||
|
||||
/**
|
||||
* return attribute custom 'is_multiselect' option
|
||||
*
|
||||
* @param $attrId
|
||||
* @return bool
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
*/
|
||||
protected function isMultiselect($attrId)
|
||||
{
|
||||
$wpLnAttributeOptions = ($attrId) ? $this->_wpAttributeOptions->getDisplayOptionsByAttribute($attrId) : false;
|
||||
$isMultiselect = ($wpLnAttributeOptions) ? $wpLnAttributeOptions->getIsMultiselect() : false;
|
||||
|
||||
return $isMultiselect;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $a
|
||||
* @param $b
|
||||
* @return int
|
||||
*/
|
||||
protected function _compareAz($a, $b)
|
||||
{
|
||||
return strcmp($a["label"], $b["label"]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
<?php
|
||||
/**
|
||||
* @category WeltPixel
|
||||
* @package WeltPixel_LayeredNavigation
|
||||
* @copyright Copyright (c) 2018 Weltpixel
|
||||
* @author Weltpixel TEAM
|
||||
*/
|
||||
|
||||
namespace WeltPixel\LayeredNavigation\Model\Layer\Filter;
|
||||
|
||||
use Magento\CatalogSearch\Model\Layer\Filter\Category as AbstractFilter;
|
||||
use WeltPixel\LayeredNavigation\Helper\Data as LayerHelper;
|
||||
use WeltPixel\LayeredNavigation\Model\Layer\Filter as LayerFilter;
|
||||
|
||||
/**
|
||||
* Class Category
|
||||
* @package WeltPixel\LayeredNavigation\Model\Layer\Filter
|
||||
*/
|
||||
class Category extends AbstractFilter
|
||||
{
|
||||
/** @var \WeltPixel\LayeredNavigation\Helper\Data */
|
||||
protected $_moduleHelper;
|
||||
|
||||
/** @var bool Is Filterable Flag */
|
||||
protected $_isFilter = false;
|
||||
|
||||
/** @var \Magento\Framework\Escaper */
|
||||
private $escaper;
|
||||
|
||||
/** @var \Magento\Catalog\Model\Layer\Filter\DataProvider\Category */
|
||||
private $dataProvider;
|
||||
|
||||
/**
|
||||
* Category constructor.
|
||||
* @param \Magento\Catalog\Model\Layer\Filter\ItemFactory $filterItemFactory
|
||||
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
|
||||
* @param \Magento\Catalog\Model\Layer $layer
|
||||
* @param \Magento\Catalog\Model\Layer\Filter\Item\DataBuilder $itemDataBuilder
|
||||
* @param \Magento\Framework\Escaper $escaper
|
||||
* @param \Magento\Catalog\Model\Layer\Filter\DataProvider\CategoryFactory $categoryDataProviderFactory
|
||||
* @param LayerHelper $moduleHelper
|
||||
* @param LayerFilter $layerFilter
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(
|
||||
\Magento\Catalog\Model\Layer\Filter\ItemFactory $filterItemFactory,
|
||||
\Magento\Store\Model\StoreManagerInterface $storeManager,
|
||||
\Magento\Catalog\Model\Layer $layer,
|
||||
\Magento\Catalog\Model\Layer\Filter\Item\DataBuilder $itemDataBuilder,
|
||||
\Magento\Framework\Escaper $escaper,
|
||||
\Magento\Catalog\Model\Layer\Filter\DataProvider\CategoryFactory $categoryDataProviderFactory,
|
||||
LayerHelper $moduleHelper,
|
||||
LayerFilter $layerFilter,
|
||||
array $data = []
|
||||
)
|
||||
{
|
||||
parent::__construct(
|
||||
$filterItemFactory,
|
||||
$storeManager,
|
||||
$layer,
|
||||
$itemDataBuilder,
|
||||
$escaper,
|
||||
$categoryDataProviderFactory,
|
||||
$data
|
||||
);
|
||||
|
||||
$this->escaper = $escaper;
|
||||
$this->_moduleHelper = $moduleHelper;
|
||||
$this->_layerFilter = $layerFilter;
|
||||
$this->dataProvider = $categoryDataProviderFactory->create(['layer' => $this->getLayer()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function apply(\Magento\Framework\App\RequestInterface $request)
|
||||
{
|
||||
if (!$this->_moduleHelper->isEnabled()) {
|
||||
return parent::apply($request);
|
||||
}
|
||||
|
||||
$categoryId = $request->getParam($this->_requestVar);
|
||||
if (empty($categoryId)) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$categoryIds = [];
|
||||
foreach (explode(',', $categoryId) as $key => $id) {
|
||||
$this->dataProvider->setCategoryId($id);
|
||||
if ($this->dataProvider->isValid()) {
|
||||
$category = $this->dataProvider->getCategory();
|
||||
if ($request->getParam('id') != $id) {
|
||||
$categoryIds[] = $id;
|
||||
$this->getLayer()->getState()->addFilter($this->_createItem($category->getName(), $id));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (sizeof($categoryIds)) {
|
||||
$this->_isFilter = true;
|
||||
$this->getLayer()->getProductCollection()->addLayerCategoryFilter($categoryIds);
|
||||
}
|
||||
|
||||
if ($parentCategoryId = $request->getParam('id')) {
|
||||
$this->dataProvider->setCategoryId($parentCategoryId);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @throws \Magento\Framework\Exception\StateException
|
||||
*/
|
||||
protected function _getItemsData()
|
||||
{
|
||||
if (!$this->_moduleHelper->isEnabled()) {
|
||||
return parent::_getItemsData();
|
||||
}
|
||||
|
||||
/** @var \Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection $productCollection */
|
||||
$productCollection = $this->getLayer()->getProductCollection();
|
||||
|
||||
if ($this->_isFilter) {
|
||||
$productCollection = $productCollection->getCollectionClone()
|
||||
->removeAttributeSearch('category_ids');
|
||||
}
|
||||
|
||||
$optionsFacetedData = $productCollection->getFacetedData('category');
|
||||
$category = $this->dataProvider->getCategory();
|
||||
$categories = $category->getChildrenCategories();
|
||||
|
||||
$collectionSize = $productCollection->getSize();
|
||||
|
||||
if ($category->getIsActive()) {
|
||||
foreach ($categories as $category) {
|
||||
$count = isset($optionsFacetedData[$category->getId()]) ? $optionsFacetedData[$category->getId()]['count'] : 0;
|
||||
if ($category->getIsActive()
|
||||
&& $this->_layerFilter->isOptionReducesResults($this, $count, $collectionSize)
|
||||
) {
|
||||
$this->itemDataBuilder->addItemData(
|
||||
$this->escaper->escapeHtml($category->getName()),
|
||||
$category->getId(),
|
||||
$count
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->itemDataBuilder->build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
<?php
|
||||
/**
|
||||
* @category WeltPixel
|
||||
* @package WeltPixel_LayeredNavigation
|
||||
* @copyright Copyright (c) 2018 Weltpixel
|
||||
* @author Weltpixel TEAM
|
||||
*/
|
||||
|
||||
namespace WeltPixel\LayerdNavigation\Model\Layer\Filter;
|
||||
|
||||
use Magento\Catalog\Model\Layer\Filter\AbstractFilter;
|
||||
|
||||
/**
|
||||
* Class Decimal
|
||||
* @package WeltPixel\LayerdNavigation\Model\Layer\Filter
|
||||
*/
|
||||
class Decimal extends AbstractFilter
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\Pricing\PriceCurrencyInterface
|
||||
*/
|
||||
private $priceCurrency;
|
||||
|
||||
/**
|
||||
* @var \Magento\Catalog\Model\ResourceModel\Layer\Filter\Decimal
|
||||
*/
|
||||
private $resource;
|
||||
|
||||
/**
|
||||
* @param \Magento\Catalog\Model\Layer\Filter\ItemFactory $filterItemFactory
|
||||
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
|
||||
* @param \Magento\Catalog\Model\Layer $layer
|
||||
* @param \Magento\Catalog\Model\Layer\Filter\Item\DataBuilder $itemDataBuilder
|
||||
* @param \Magento\Catalog\Model\ResourceModel\Layer\Filter\DecimalFactory $filterDecimalFactory
|
||||
* @param \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(
|
||||
\Magento\Catalog\Model\Layer\Filter\ItemFactory $filterItemFactory,
|
||||
\Magento\Store\Model\StoreManagerInterface $storeManager,
|
||||
\Magento\Catalog\Model\Layer $layer,
|
||||
\Magento\Catalog\Model\Layer\Filter\Item\DataBuilder $itemDataBuilder,
|
||||
\Magento\Catalog\Model\ResourceModel\Layer\Filter\DecimalFactory $filterDecimalFactory,
|
||||
\Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency,
|
||||
array $data = []
|
||||
) {
|
||||
parent::__construct(
|
||||
$filterItemFactory,
|
||||
$storeManager,
|
||||
$layer,
|
||||
$itemDataBuilder,
|
||||
$data
|
||||
);
|
||||
$this->resource = $filterDecimalFactory->create();
|
||||
$this->priceCurrency = $priceCurrency;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply price range filter
|
||||
*
|
||||
* @param \Magento\Framework\App\RequestInterface $request
|
||||
* @return $this
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
*/
|
||||
public function apply(\Magento\Framework\App\RequestInterface $request)
|
||||
{
|
||||
/**
|
||||
* Filter must be string: $fromPrice-$toPrice
|
||||
*/
|
||||
$filter = $request->getParam($this->getRequestVar());
|
||||
if (!$filter || is_array($filter)) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
list($from, $to) = explode('-', $filter);
|
||||
|
||||
$this->getLayer()
|
||||
->getProductCollection()
|
||||
->addFieldToFilter(
|
||||
$this->getAttributeModel()->getAttributeCode(),
|
||||
['from' => $from, 'to' => $to]
|
||||
);
|
||||
|
||||
$this->getLayer()->getState()->addFilter(
|
||||
$this->_createItem($this->renderRangeLabel(empty($from) ? 0 : $from, $to), $filter)
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data array for building attribute filter items
|
||||
*
|
||||
* @return array
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
* @SuppressWarnings(PHPMD.NPathComplexity)
|
||||
*/
|
||||
protected function _getItemsData()
|
||||
{
|
||||
$attribute = $this->getAttributeModel();
|
||||
|
||||
/** @var \Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection $productCollection */
|
||||
$productCollection = $this->getLayer()->getProductCollection();
|
||||
$productSize = $productCollection->getSize();
|
||||
$facets = $productCollection->getFacetedData($attribute->getAttributeCode());
|
||||
|
||||
$data = [];
|
||||
foreach ($facets as $key => $aggregation) {
|
||||
$count = $aggregation['count'];
|
||||
if (!$this->isOptionReducesResults($count, $productSize)) {
|
||||
continue;
|
||||
}
|
||||
list($from, $to) = explode('_', $key);
|
||||
if ($from == '*') {
|
||||
$from = '';
|
||||
}
|
||||
if ($to == '*') {
|
||||
$to = '';
|
||||
}
|
||||
$label = $this->renderRangeLabel(
|
||||
empty($from) ? 0 : $from,
|
||||
empty($to) ? $to : $to
|
||||
);
|
||||
$value = $from . '-' . $to;
|
||||
|
||||
$data[] = [
|
||||
'label' => $label,
|
||||
'value' => $value,
|
||||
'count' => $count,
|
||||
'from' => $from,
|
||||
'to' => $to
|
||||
];
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare text of range label
|
||||
*
|
||||
* @param float|string $fromPrice
|
||||
* @param float|string $toPrice
|
||||
* @return \Magento\Framework\Phrase
|
||||
*/
|
||||
protected function renderRangeLabel($fromPrice, $toPrice)
|
||||
{
|
||||
$formattedFromPrice = $this->priceCurrency->format($fromPrice);
|
||||
if ($toPrice === '') {
|
||||
return __('%1 and above', $formattedFromPrice);
|
||||
} else {
|
||||
if ($fromPrice != $toPrice) {
|
||||
$toPrice -= .01;
|
||||
}
|
||||
return __('%1 - %2', $formattedFromPrice, $this->priceCurrency->format($toPrice));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,255 @@
|
||||
<?php
|
||||
/**
|
||||
* @category WeltPixel
|
||||
* @package WeltPixel_LayeredNavigation
|
||||
* @copyright Copyright (c) 2018 Weltpixel
|
||||
* @author Weltpixel TEAM
|
||||
*/
|
||||
|
||||
namespace WeltPixel\LayeredNavigation\Model\Layer\Filter;
|
||||
|
||||
use Magento\CatalogSearch\Model\Layer\Filter\Price as AbstractFilter;
|
||||
use WeltPixel\LayeredNavigation\Helper\Data as LayerHelper;
|
||||
|
||||
/**
|
||||
* Class Price
|
||||
* @package WeltPixel\LayeredNavigation\Model\Layer\Filter
|
||||
*/
|
||||
class Price extends AbstractFilter
|
||||
{
|
||||
/** @var \WeltPixel\LayeredNavigation\Helper\Data */
|
||||
protected $_moduleHelper;
|
||||
|
||||
/** @var array|null Filter value */
|
||||
protected $_filterVal = null;
|
||||
|
||||
/** @var \Magento\Tax\Helper\Data */
|
||||
protected $_taxHelper;
|
||||
|
||||
/** @var \Magento\Catalog\Model\Layer\Filter\DataProvider\Price */
|
||||
private $dataProvider;
|
||||
|
||||
/** @var \Magento\Framework\Pricing\PriceCurrencyInterface */
|
||||
private $priceCurrency;
|
||||
|
||||
/**
|
||||
* @param \Magento\Catalog\Model\Layer\Filter\ItemFactory $filterItemFactory
|
||||
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
|
||||
* @param \Magento\Catalog\Model\Layer $layer
|
||||
* @param \Magento\Catalog\Model\Layer\Filter\Item\DataBuilder $itemDataBuilder
|
||||
* @param \Magento\Catalog\Model\ResourceModel\Layer\Filter\Price $resource
|
||||
* @param \Magento\Customer\Model\Session $customerSession
|
||||
* @param \Magento\Framework\Search\Dynamic\Algorithm $priceAlgorithm
|
||||
* @param \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency
|
||||
* @param \Magento\Catalog\Model\Layer\Filter\Dynamic\AlgorithmFactory $algorithmFactory
|
||||
* @param \Magento\Catalog\Model\Layer\Filter\DataProvider\PriceFactory $dataProviderFactory
|
||||
* @param \Magento\Tax\Helper\Data $taxHelper
|
||||
* @param \WeltPixel\LayeredNavigation\Helper\Data $moduleHelper
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(
|
||||
\Magento\Catalog\Model\Layer\Filter\ItemFactory $filterItemFactory,
|
||||
\Magento\Store\Model\StoreManagerInterface $storeManager,
|
||||
\Magento\Catalog\Model\Layer $layer,
|
||||
\Magento\Catalog\Model\Layer\Filter\Item\DataBuilder $itemDataBuilder,
|
||||
\Magento\Catalog\Model\ResourceModel\Layer\Filter\Price $resource,
|
||||
\Magento\Customer\Model\Session $customerSession,
|
||||
\Magento\Framework\Search\Dynamic\Algorithm $priceAlgorithm,
|
||||
\Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency,
|
||||
\Magento\Catalog\Model\Layer\Filter\Dynamic\AlgorithmFactory $algorithmFactory,
|
||||
\Magento\Catalog\Model\Layer\Filter\DataProvider\PriceFactory $dataProviderFactory,
|
||||
\Magento\Tax\Helper\Data $taxHelper,
|
||||
LayerHelper $moduleHelper,
|
||||
array $data = []
|
||||
)
|
||||
{
|
||||
parent::__construct(
|
||||
$filterItemFactory,
|
||||
$storeManager,
|
||||
$layer,
|
||||
$itemDataBuilder,
|
||||
$resource,
|
||||
$customerSession,
|
||||
$priceAlgorithm,
|
||||
$priceCurrency,
|
||||
$algorithmFactory,
|
||||
$dataProviderFactory,
|
||||
$data
|
||||
);
|
||||
|
||||
$this->priceCurrency = $priceCurrency;
|
||||
$this->dataProvider = $dataProviderFactory->create(['layer' => $this->getLayer()]);
|
||||
$this->_moduleHelper = $moduleHelper;
|
||||
$this->_taxHelper = $taxHelper;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function apply(\Magento\Framework\App\RequestInterface $request)
|
||||
{
|
||||
if (!$this->_moduleHelper->isEnabled()) {
|
||||
return parent::apply($request);
|
||||
}
|
||||
/**
|
||||
* Filter must be string: $fromPrice-$toPrice
|
||||
*/
|
||||
$filter = $request->getParam($this->getRequestVar());
|
||||
if (!$filter || is_array($filter)) {
|
||||
return $this;
|
||||
}
|
||||
$filterParams = explode(',', $filter);
|
||||
$filter = $this->dataProvider->validateFilter($filterParams[0]);
|
||||
if (!$filter) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$this->dataProvider->setInterval($filter);
|
||||
$priorFilters = $this->dataProvider->getPriorFilters($filterParams);
|
||||
if ($priorFilters) {
|
||||
$this->dataProvider->setPriorIntervals($priorFilters);
|
||||
}
|
||||
|
||||
list($from, $to) = $this->_filterVal = $filter;
|
||||
|
||||
$this->getLayer()->getProductCollection()->addFieldToFilter(
|
||||
'price',
|
||||
['from' => $from, 'to' => $to]
|
||||
);
|
||||
|
||||
$this->getLayer()->getState()->addFilter(
|
||||
$this->_createItem($this->_renderRangeLabel(empty($from) ? 0 : $from, $to), $filter)
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function _renderRangeLabel($fromPrice, $toPrice, $isLast = false)
|
||||
{
|
||||
if (!$this->_moduleHelper->isEnabled()) {
|
||||
return parent::_renderRangeLabel($fromPrice, $toPrice, $isLast = false);
|
||||
}
|
||||
$formattedFromPrice = $this->priceCurrency->format($fromPrice);
|
||||
if ($toPrice === '' || $isLast) {
|
||||
return __('%1 and above', $formattedFromPrice);
|
||||
} elseif ($fromPrice == $toPrice && $this->dataProvider->getOnePriceIntervalValue()) {
|
||||
return $formattedFromPrice;
|
||||
} else {
|
||||
return __('%1 - %2', $formattedFromPrice, $this->priceCurrency->format($toPrice));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Price Slider Configuration
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSliderConfig()
|
||||
{
|
||||
/** @var \WeltPixel\LayeredNavigation\Model\ResourceModel\Fulltext\Collection $productCollection */
|
||||
$productCollection = $this->getLayer()->getProductCollection();
|
||||
|
||||
if ($this->_filterVal) {
|
||||
/** @type \WeltPixel\LayeredNavigation\Model\ResourceModel\Fulltext\Collection $productCollectionClone */
|
||||
$productCollection = $productCollection->getCollectionClone()
|
||||
->removeAttributeSearch(['price.from', 'price.to']);
|
||||
}
|
||||
|
||||
$min = $productCollection->getMinPrice();
|
||||
$max = $productCollection->getMaxPrice();
|
||||
|
||||
list($from, $to) = $this->_filterVal ?: [$min, $max];
|
||||
$from = ($from < $min) ? $min : $from;
|
||||
$to = ($to > $max) ? $max : $to;
|
||||
|
||||
$item = $this->getItems()[0];
|
||||
|
||||
return [
|
||||
"selectedFrom" => $from,
|
||||
"selectedTo" => $to,
|
||||
"minValue" => $min,
|
||||
"maxValue" => $max,
|
||||
"priceFormat" => $this->_taxHelper->getPriceFormat(),
|
||||
"ajaxUrl" => $item->getUrl()
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data array for building attribute filter items
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.NPathComplexity)
|
||||
*/
|
||||
protected function _getItemsData()
|
||||
{
|
||||
if (!$this->_moduleHelper->isEnabled()) {
|
||||
return parent::_getItemsData();
|
||||
}
|
||||
|
||||
$attribute = $this->getAttributeModel();
|
||||
$this->_requestVar = $attribute->getAttributeCode();
|
||||
|
||||
/** @var \Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection $productCollection */
|
||||
$productCollection = $this->getLayer()->getProductCollection();
|
||||
|
||||
if ($this->_filterVal) {
|
||||
/** @type \WeltPixel\LayeredNavigation\Model\ResourceModel\Fulltext\Collection $productCollectionClone */
|
||||
$productCollection = $productCollection->getCollectionClone()
|
||||
->removeAttributeSearch(['price.from', 'price.to']);
|
||||
}
|
||||
|
||||
$facets = $productCollection->getFacetedData($attribute->getAttributeCode());
|
||||
|
||||
$data = [];
|
||||
if (count($facets) > 1) {
|
||||
$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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @param int $count
|
||||
* @param boolean $isLast
|
||||
* @return array
|
||||
*/
|
||||
private function prepareData($key, $count, $isLast = false)
|
||||
{
|
||||
list($from, $to) = explode('_', $key);
|
||||
if ($from == '*') {
|
||||
$from = $this->getFrom($to);
|
||||
}
|
||||
if ($to == '*') {
|
||||
$to = $this->getTo($to);
|
||||
}
|
||||
$label = $this->_renderRangeLabel(
|
||||
empty($from) ? 0 : $from * $this->getCurrencyRate(),
|
||||
empty($to) ? $to : $to * $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,75 @@
|
||||
<?php
|
||||
/**
|
||||
* @category WeltPixel
|
||||
* @package WeltPixel_LayeredNavigation
|
||||
* @copyright Copyright (c) 2018 Weltpixel
|
||||
* @author Weltpixel TEAM
|
||||
*/
|
||||
|
||||
namespace WeltPixel\LayeredNavigation\Model\ResourceModel;
|
||||
|
||||
/**
|
||||
* Class AttributeOptions
|
||||
* @package WeltPixel\LayeredNavigation\Model\ResourceModel
|
||||
*/
|
||||
class AttributeOptions extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $loadedAttributes = [];
|
||||
|
||||
/**
|
||||
* AttributeOptions constructor.
|
||||
* @param \Magento\Framework\Model\ResourceModel\Db\Context $context
|
||||
*/
|
||||
public function __construct(
|
||||
\Magento\Framework\Model\ResourceModel\Db\Context $context
|
||||
)
|
||||
{
|
||||
parent::__construct($context);
|
||||
}
|
||||
|
||||
protected function _construct()
|
||||
{
|
||||
$this->_init('weltpixel_ln_attribute_options', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Load Attribute display option by attribute_id & store_id
|
||||
*
|
||||
* @param \WeltPixel\LayeredNavigation\Model\AttributeOptions $attributeOptions
|
||||
* @param $attributeId
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
*/
|
||||
public function loadDisplayOptionsByAttribute(
|
||||
\WeltPixel\LayeredNavigation\Model\AttributeOptions $attributeOptions,
|
||||
$attributeId
|
||||
) {
|
||||
if (isset($this->loadedAttributes[$attributeId])) {
|
||||
$attributeOptions->setData($this->loadedAttributes[$attributeId]->getData());
|
||||
return $this;
|
||||
}
|
||||
$connection = $this->getConnection();
|
||||
$bind = [
|
||||
'attribute_id' => $attributeId
|
||||
];
|
||||
|
||||
$select = $connection->select()->from(
|
||||
$this->getMainTable(),
|
||||
[$this->getIdFieldName()]
|
||||
)->where(
|
||||
'attribute_id = :attribute_id'
|
||||
);
|
||||
|
||||
$lineId = $connection->fetchOne($select, $bind);
|
||||
if ($lineId) {
|
||||
$this->load($attributeOptions, $lineId);
|
||||
} else {
|
||||
$attributeOptions->setData([]);
|
||||
}
|
||||
|
||||
$this->loadedAttributes[$attributeId] = clone $attributeOptions;
|
||||
}
|
||||
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* @category WeltPixel
|
||||
* @package WeltPixel_LayeredNavigation
|
||||
* @copyright Copyright (c) 2018 Weltpixel
|
||||
* @author Weltpixel TEAM
|
||||
*/
|
||||
|
||||
namespace WeltPixel\LayeredNavigation\Model\ResourceModel\AttributeOptions;
|
||||
|
||||
/**
|
||||
* Class Collection
|
||||
* @package WeltPixel\LayeredNavigation\Model\ResourceModel\AttributeOptions
|
||||
*/
|
||||
class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
|
||||
{
|
||||
protected $_idFieldName = 'id';
|
||||
protected $_eventPrefix = 'weltpixel_ln_atribute_options_collection';
|
||||
protected $_eventObject = 'attribute_options_collection';
|
||||
|
||||
/**
|
||||
* Define resource model
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _construct()
|
||||
{
|
||||
$this->_init('WeltPixel\LayeredNavigation\Model\AttributeOptions', 'WeltPixel\LayeredNavigation\Model\ResourceModel\AttributeOptions');
|
||||
}
|
||||
|
||||
}
|
||||
+588
@@ -0,0 +1,588 @@
|
||||
<?php
|
||||
/**
|
||||
* @category WeltPixel
|
||||
* @package WeltPixel_LayeredNavigation
|
||||
* @copyright Copyright (c) 2018 Weltpixel
|
||||
* @author Weltpixel TEAM
|
||||
*/
|
||||
|
||||
namespace WeltPixel\LayeredNavigation\Model\ResourceModel\Fulltext;
|
||||
|
||||
use Magento\CatalogSearch\Model\Search\RequestGenerator;
|
||||
use Magento\Framework\Api\Search\FilterGroup as SourceFilterGroup;
|
||||
use Magento\Framework\Api\Search\SearchCriteria;
|
||||
use Magento\Framework\Api\Search\SearchResultFactory;
|
||||
use Magento\Framework\App\ObjectManager;
|
||||
use Magento\Framework\DB\Select;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Magento\Framework\Exception\StateException;
|
||||
use Magento\Framework\Search\Adapter\Mysql\TemporaryStorage;
|
||||
use Magento\Framework\Search\Request\EmptyRequestDataException;
|
||||
use Magento\Store\Model\ScopeInterface;
|
||||
use Magento\CatalogSearch\Model\ResourceModel\EngineInterface;
|
||||
|
||||
/**
|
||||
* Class Collection
|
||||
* @package WeltPixel\LayeredNavigation\Model\ResourceModel\Fulltext
|
||||
*/
|
||||
class Collection extends \Magento\Catalog\Model\ResourceModel\Product\Collection
|
||||
{
|
||||
/** @var \WeltPixel\LayeredNavigation\Model\ResourceModel\Fulltext\Collection|null Clone collection */
|
||||
public $collectionClone = null;
|
||||
|
||||
/** @var string */
|
||||
private $queryText;
|
||||
|
||||
/** @var string|null */
|
||||
private $order = null;
|
||||
|
||||
/** @var string */
|
||||
private $searchRequestName;
|
||||
|
||||
/** @var \Magento\Framework\Search\Adapter\Mysql\TemporaryStorageFactory */
|
||||
private $temporaryStorageFactory;
|
||||
|
||||
/** @var \Magento\Search\Api\SearchInterface */
|
||||
private $search;
|
||||
|
||||
/** @var \WeltPixel\LayeredNavigation\Model\ResourceModel\Search\SearchCriteriaBuilder */
|
||||
private $searchCriteriaBuilder;
|
||||
|
||||
/** @var \Magento\Framework\Api\Search\SearchResultInterface */
|
||||
private $searchResult;
|
||||
|
||||
/** @var \Magento\Framework\Api\FilterBuilder */
|
||||
private $filterBuilder;
|
||||
|
||||
/* @var \Magento\Framework\App\Config\ScopeConfigInterface */
|
||||
protected $_scopeConfig;
|
||||
|
||||
/** @var \Magento\Framework\App\ProductMetadataInterface */
|
||||
protected $_productMetadata;
|
||||
|
||||
/** @var */
|
||||
protected $_categoryId;
|
||||
|
||||
/** @var */
|
||||
protected $_isTwoOne;
|
||||
|
||||
/**
|
||||
* @var SearchResultFactory
|
||||
*/
|
||||
protected $searchResultFactory;
|
||||
|
||||
/**
|
||||
* Collection constructor.
|
||||
* @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory
|
||||
* @param \Psr\Log\LoggerInterface $logger
|
||||
* @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy
|
||||
* @param \Magento\Framework\Event\ManagerInterface $eventManager
|
||||
* @param \Magento\Eav\Model\Config $eavConfig
|
||||
* @param \Magento\Framework\App\ResourceConnection $resource
|
||||
* @param \Magento\Eav\Model\EntityFactory $eavEntityFactory
|
||||
* @param \Magento\Catalog\Model\ResourceModel\Helper $resourceHelper
|
||||
* @param \Magento\Framework\Validator\UniversalFactory $universalFactory
|
||||
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
|
||||
* @param \Magento\Framework\Module\Manager $moduleManager
|
||||
* @param \Magento\Catalog\Model\Indexer\Product\Flat\State $catalogProductFlatState
|
||||
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
|
||||
* @param \Magento\Catalog\Model\Product\OptionFactory $productOptionFactory
|
||||
* @param \Magento\Catalog\Model\ResourceModel\Url $catalogUrl
|
||||
* @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
|
||||
* @param \Magento\Customer\Model\Session $customerSession
|
||||
* @param \Magento\Framework\Stdlib\DateTime $dateTime
|
||||
* @param \Magento\Customer\Api\GroupManagementInterface $groupManagement
|
||||
* @param \Magento\Framework\Search\Adapter\Mysql\TemporaryStorageFactory $temporaryStorageFactory
|
||||
* @param \Magento\Framework\App\ProductMetadataInterface $productMetadata
|
||||
* @param \Magento\Framework\DB\Adapter\AdapterInterface|null $connection
|
||||
* @param string $searchRequestName
|
||||
* @param SearchResultFactory|null $searchResultFactory
|
||||
*/
|
||||
public function __construct(
|
||||
\Magento\Framework\Data\Collection\EntityFactory $entityFactory,
|
||||
\Psr\Log\LoggerInterface $logger,
|
||||
\Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy,
|
||||
\Magento\Framework\Event\ManagerInterface $eventManager,
|
||||
\Magento\Eav\Model\Config $eavConfig,
|
||||
\Magento\Framework\App\ResourceConnection $resource,
|
||||
\Magento\Eav\Model\EntityFactory $eavEntityFactory,
|
||||
\Magento\Catalog\Model\ResourceModel\Helper $resourceHelper,
|
||||
\Magento\Framework\Validator\UniversalFactory $universalFactory,
|
||||
\Magento\Store\Model\StoreManagerInterface $storeManager,
|
||||
\Magento\Framework\Module\Manager $moduleManager,
|
||||
\Magento\Catalog\Model\Indexer\Product\Flat\State $catalogProductFlatState,
|
||||
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
|
||||
\Magento\Catalog\Model\Product\OptionFactory $productOptionFactory,
|
||||
\Magento\Catalog\Model\ResourceModel\Url $catalogUrl,
|
||||
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate,
|
||||
\Magento\Customer\Model\Session $customerSession,
|
||||
\Magento\Framework\Stdlib\DateTime $dateTime,
|
||||
\Magento\Customer\Api\GroupManagementInterface $groupManagement,
|
||||
\Magento\Framework\Search\Adapter\Mysql\TemporaryStorageFactory $temporaryStorageFactory,
|
||||
\Magento\Framework\App\ProductMetadataInterface $productMetadata,
|
||||
\Magento\Framework\DB\Adapter\AdapterInterface $connection = null,
|
||||
$searchRequestName = 'catalog_view_container',
|
||||
SearchResultFactory $searchResultFactory = null
|
||||
)
|
||||
{
|
||||
$this->searchResultFactory = $searchResultFactory ?? ObjectManager::getInstance()->get(SearchResultFactory::class);
|
||||
parent::__construct(
|
||||
$entityFactory,
|
||||
$logger,
|
||||
$fetchStrategy,
|
||||
$eventManager,
|
||||
$eavConfig,
|
||||
$resource,
|
||||
$eavEntityFactory,
|
||||
$resourceHelper,
|
||||
$universalFactory,
|
||||
$storeManager,
|
||||
$moduleManager,
|
||||
$catalogProductFlatState,
|
||||
$scopeConfig,
|
||||
$productOptionFactory,
|
||||
$catalogUrl,
|
||||
$localeDate,
|
||||
$customerSession,
|
||||
$dateTime,
|
||||
$groupManagement,
|
||||
$connection
|
||||
);
|
||||
$this->temporaryStorageFactory = $temporaryStorageFactory;
|
||||
$this->searchRequestName = $searchRequestName;
|
||||
$this->_scopeConfig = $scopeConfig;
|
||||
$this->_productMetadata = $productMetadata;
|
||||
$this->_isMTwoOneVersion();
|
||||
}
|
||||
|
||||
/**
|
||||
* WeltPixel LayeredNavigation Clone collection
|
||||
*
|
||||
* @return \WeltPixel\LayeredNavigation\Model\ResourceModel\Fulltext\Collection|null
|
||||
*/
|
||||
public function getCollectionClone()
|
||||
{
|
||||
if ($this->collectionClone === null) {
|
||||
$this->collectionClone = clone $this;
|
||||
$this->collectionClone->setSearchCriteriaBuilder($this->searchCriteriaBuilder->cloneObject());
|
||||
}
|
||||
|
||||
$searchCriterialBuilder = $this->collectionClone->getSearchCriteriaBuilder()->cloneObject();
|
||||
|
||||
/** @var \WeltPixel\LayeredNavigation\Model\ResourceModel\Fulltext\Collection $collectionClone */
|
||||
$collectionClone = clone $this->collectionClone;
|
||||
$collectionClone->setSearchCriteriaBuilder($searchCriterialBuilder);
|
||||
|
||||
return $collectionClone;
|
||||
}
|
||||
|
||||
/**
|
||||
* WeltPixel LayeredNavigation Add multi-filter categories
|
||||
*
|
||||
* @param $categories
|
||||
* @return $this
|
||||
*/
|
||||
public function addLayerCategoryFilter($categories)
|
||||
{
|
||||
$this->addFieldToFilter('category_ids', implode(',', $categories));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* WeltPixel LayeredNavigation remove filter to load option item data
|
||||
*
|
||||
* @param $attributeCode
|
||||
* @return $this
|
||||
*/
|
||||
public function removeAttributeSearch($attributeCode)
|
||||
{
|
||||
if (is_array($attributeCode)) {
|
||||
foreach ($attributeCode as $attCode) {
|
||||
$this->searchCriteriaBuilder->removeFilter($attCode);
|
||||
}
|
||||
} else {
|
||||
$this->searchCriteriaBuilder->removeFilter($attributeCode);
|
||||
}
|
||||
|
||||
$this->_isFiltersRendered = false;
|
||||
|
||||
return $this->loadWithFilter();
|
||||
}
|
||||
|
||||
/**
|
||||
* WeltPixel LayeredNavigation Get attribute condition sql
|
||||
*
|
||||
* @param $attribute
|
||||
* @param $condition
|
||||
* @param string $joinType
|
||||
* @return string
|
||||
*/
|
||||
public function getAttributeConditionSql($attribute, $condition, $joinType = 'inner')
|
||||
{
|
||||
return $this->_getAttributeConditionSql($attribute, $condition, $joinType);
|
||||
}
|
||||
|
||||
/**
|
||||
* WeltPixel LayeredNavigation Reset Total records
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function resetTotalRecords($collectionCount = null)
|
||||
{
|
||||
$this->_totalRecords = $collectionCount;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|void
|
||||
*/
|
||||
public function getSize() {
|
||||
return sizeof($this->getAllIds());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Magento\Search\Api\SearchInterface|mixed
|
||||
*/
|
||||
private function getSearch()
|
||||
{
|
||||
if ($this->search === null) {
|
||||
$this->search = ObjectManager::getInstance()->get('\Magento\Search\Api\SearchInterface');
|
||||
}
|
||||
|
||||
return $this->search;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Magento\Search\Api\SearchInterface $object
|
||||
*/
|
||||
public function setSearch(\Magento\Search\Api\SearchInterface $object)
|
||||
{
|
||||
$this->search = $object;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed|\WeltPixel\LayeredNavigation\Model\ResourceModel\Search\SearchCriteriaBuilder
|
||||
*/
|
||||
public function getSearchCriteriaBuilder()
|
||||
{
|
||||
if ($this->searchCriteriaBuilder === null) {
|
||||
$this->searchCriteriaBuilder = ObjectManager::getInstance()
|
||||
->get('\WeltPixel\LayeredNavigation\Model\ResourceModel\Search\SearchCriteriaBuilder');
|
||||
}
|
||||
|
||||
return $this->searchCriteriaBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \WeltPixel\LayeredNavigation\Model\ResourceModel\Search\SearchCriteriaBuilder $object
|
||||
*/
|
||||
public function setSearchCriteriaBuilder(\WeltPixel\LayeredNavigation\Model\ResourceModel\Search\SearchCriteriaBuilder $object)
|
||||
{
|
||||
$this->searchCriteriaBuilder = $object;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Magento\Framework\Api\FilterBuilder|mixed
|
||||
*/
|
||||
private function getFilterBuilder()
|
||||
{
|
||||
if ($this->filterBuilder === null) {
|
||||
$this->filterBuilder = ObjectManager::getInstance()->get('\Magento\Framework\Api\FilterBuilder');
|
||||
}
|
||||
|
||||
return $this->filterBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Magento\Framework\Api\FilterBuilder $object
|
||||
*/
|
||||
public function setFilterBuilder(\Magento\Framework\Api\FilterBuilder $object)
|
||||
{
|
||||
$this->filterBuilder = $object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply attribute filter to facet collection
|
||||
*
|
||||
* @param string $field
|
||||
* @param null $condition
|
||||
* @return $this
|
||||
*/
|
||||
public function addFieldToFilter($field, $condition = null)
|
||||
{
|
||||
if ($this->searchResult !== null) {
|
||||
throw new \RuntimeException('Illegal state');
|
||||
}
|
||||
|
||||
$this->getSearchCriteriaBuilder();
|
||||
$this->getFilterBuilder();
|
||||
|
||||
|
||||
if (is_array($condition) && $this->_isElasticOrOpenSearchEngine()) {
|
||||
$this->filterBuilder->setField($field);
|
||||
$this->filterBuilder->setValue($condition);
|
||||
$this->searchCriteriaBuilder->addFilter($this->filterBuilder->create());
|
||||
} elseif (!is_array($condition) || !in_array(key($condition), ['from', 'to'])) {
|
||||
$this->filterBuilder->setField($field);
|
||||
$this->filterBuilder->setValue($condition);
|
||||
$this->searchCriteriaBuilder->addFilter($this->filterBuilder->create());
|
||||
} else {
|
||||
if (!empty($condition['from'])) {
|
||||
$this->filterBuilder->setField("{$field}.from");
|
||||
$this->filterBuilder->setValue($condition['from']);
|
||||
$this->searchCriteriaBuilder->addFilter($this->filterBuilder->create());
|
||||
}
|
||||
if (!empty($condition['to'])) {
|
||||
$this->filterBuilder->setField("{$field}.to");
|
||||
$this->filterBuilder->setValue($condition['to']);
|
||||
$this->searchCriteriaBuilder->addFilter($this->filterBuilder->create());
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add search query filter
|
||||
*
|
||||
* @param string $query
|
||||
* @return $this
|
||||
*/
|
||||
public function addSearchFilter($query)
|
||||
{
|
||||
$this->queryText = trim($this->queryText . ' ' . $query);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function _renderFiltersBefore()
|
||||
{
|
||||
$this->getCollectionClone();
|
||||
|
||||
$this->getSearchCriteriaBuilder();
|
||||
$this->getFilterBuilder();
|
||||
$this->getSearch();
|
||||
|
||||
if ($this->queryText) {
|
||||
$this->filterBuilder->setField('search_term');
|
||||
$this->filterBuilder->setValue($this->queryText);
|
||||
$this->searchCriteriaBuilder->addFilter($this->filterBuilder->create());
|
||||
}
|
||||
|
||||
$priceRangeCalculation = $this->_scopeConfig->getValue(
|
||||
\Magento\Catalog\Model\Layer\Filter\Dynamic\AlgorithmFactory::XML_PATH_RANGE_CALCULATION,
|
||||
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
|
||||
);
|
||||
if ($priceRangeCalculation) {
|
||||
$this->filterBuilder->setField('price_dynamic_algorithm');
|
||||
$this->filterBuilder->setValue($priceRangeCalculation);
|
||||
$this->searchCriteriaBuilder->addFilter($this->filterBuilder->create());
|
||||
}
|
||||
|
||||
if ($this->_isTwoOne) {
|
||||
$this->filterBuilder->setField('category_ids');
|
||||
$this->filterBuilder->setValue($this->_categoryId);
|
||||
$this->searchCriteriaBuilder->addFilter($this->filterBuilder->create());
|
||||
}
|
||||
|
||||
$searchCriteria = $this->searchCriteriaBuilder->create();
|
||||
$searchCriteria->setRequestName($this->searchRequestName);
|
||||
|
||||
if ($this->_isElasticOrOpenSearchEngine()) {
|
||||
if ($this->order && isset($this->order['field'])) {
|
||||
$fieldValue = explode("~", $this->order['field']);
|
||||
} else {
|
||||
$fieldValue = [];
|
||||
$fieldValue[0]=null;
|
||||
}
|
||||
if (!$fieldValue[0]) {
|
||||
$searchCriteria->setSortOrders([
|
||||
'entity_id' => 'DESC'
|
||||
]);
|
||||
} else {
|
||||
$searchCriteria->setSortOrders([
|
||||
$fieldValue[0] => $this->order['dir']
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
$this->searchResult = $this->getSearch()->search($searchCriteria);
|
||||
} catch (EmptyRequestDataException $e) {
|
||||
/** @var \Magento\Framework\Api\Search\SearchResultInterface $searchResult */
|
||||
$this->searchResult = $this->searchResultFactory->create()->setItems([]);
|
||||
} catch (\Exception $e) {
|
||||
throw new LocalizedException(__('Something went wrong, check and test your Search Engine configurations, reindex catalog and clear cache. Thrown error: %1', $e->getMessage()));
|
||||
}
|
||||
|
||||
try {
|
||||
$temporaryStorage = $this->temporaryStorageFactory->create();
|
||||
$table = $temporaryStorage->storeDocuments($this->searchResult->getItems());
|
||||
|
||||
$this->getSelect()->joinInner(
|
||||
[
|
||||
'search_result' => $table->getName(),
|
||||
],
|
||||
'e.entity_id = search_result.' . TemporaryStorage::FIELD_ENTITY_ID,
|
||||
[]
|
||||
);
|
||||
|
||||
if ($this->order && 'relevance' === $this->order['field']) {
|
||||
$this->getSelect()->order('search_result.' . TemporaryStorage::FIELD_SCORE . ' ' . $this->order['dir']);
|
||||
}
|
||||
} catch (\Exception $ex) {
|
||||
$this->_logger->error($ex->getMessage());
|
||||
}
|
||||
|
||||
parent::_renderFiltersBefore();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
protected function _renderFilters()
|
||||
{
|
||||
$this->_filters = [];
|
||||
|
||||
return parent::_renderFilters();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Order field
|
||||
*
|
||||
* @param string $attribute
|
||||
* @param string $dir
|
||||
* @return $this
|
||||
*/
|
||||
public function setOrder($attribute, $dir = Select::SQL_DESC)
|
||||
{
|
||||
$this->order = ['field' => $attribute, 'dir' => $dir];
|
||||
if ($attribute != 'relevance') {
|
||||
parent::setOrder($attribute, $dir);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stub method for compatibility with other search engines
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setGeneralDefaultQuery()
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return field faceted data from faceted search result
|
||||
*
|
||||
* @param string $field
|
||||
* @return array
|
||||
* @throws StateException
|
||||
*/
|
||||
public function getFacetedData($field)
|
||||
{
|
||||
$this->_renderFilters();
|
||||
$result = [];
|
||||
|
||||
$aggregations = $this->searchResult->getAggregations();
|
||||
if (null !== $aggregations) {
|
||||
$bucketName = $field . RequestGenerator::BUCKET_SUFFIX;
|
||||
$bucket = $aggregations->getBucket($bucketName);
|
||||
if ($bucket) {
|
||||
foreach ($bucket->getValues() as $value) {
|
||||
$metrics = $value->getMetrics();
|
||||
$result[$metrics['value']] = $metrics;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify category filter for product collection
|
||||
*
|
||||
* @param \Magento\Catalog\Model\Category $category
|
||||
* @return $this
|
||||
*/
|
||||
public function addCategoryFilter(\Magento\Catalog\Model\Category $category)
|
||||
{
|
||||
$this->_categoryId = $category->getId();
|
||||
$this->addFieldToFilter('category_ids', $category->getId());
|
||||
|
||||
return parent::addCategoryFilter($category);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set product visibility filter for enabled products
|
||||
*
|
||||
* @param array $visibility
|
||||
* @return $this
|
||||
*/
|
||||
public function setVisibility($visibility)
|
||||
{
|
||||
$this->addFieldToFilter('visibility', $visibility);
|
||||
|
||||
return parent::setVisibility($visibility);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the engine provider is 'elasticsearch'
|
||||
* @deprecated
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _isElasticSearchEngine()
|
||||
{
|
||||
$currentEngine = $this->_scopeConfig->getValue(EngineInterface::CONFIG_ENGINE_PATH, ScopeInterface::SCOPE_STORE);
|
||||
if ($currentEngine == 'elasticsearch' || $currentEngine == 'elasticsearch5'
|
||||
|| $currentEngine == 'elasticsearch6' || $currentEngine == 'elasticsearch7' ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the engine provider is 'elasticsearch' or 'opensearch'
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _isElasticOrOpenSearchEngine()
|
||||
{
|
||||
$currentEngine = $this->_scopeConfig->getValue(EngineInterface::CONFIG_ENGINE_PATH, ScopeInterface::SCOPE_STORE);
|
||||
if ($currentEngine == 'elasticsearch' || $currentEngine == 'elasticsearch5'
|
||||
|| $currentEngine == 'elasticsearch6' || $currentEngine == 'elasticsearch7' || $currentEngine == 'opensearch' ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* check magento version
|
||||
* @return bool
|
||||
*/
|
||||
protected function _isMTwoOneVersion()
|
||||
{
|
||||
$version = $this->_productMetadata->getVersion();
|
||||
$pos = strpos($version, '2.1');
|
||||
|
||||
if ($pos === false) {
|
||||
$this->_isTwoOne = false;
|
||||
} else {
|
||||
$this->_isTwoOne = true;
|
||||
}
|
||||
|
||||
return $this->_isTwoOne;
|
||||
}
|
||||
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
/**
|
||||
* @category WeltPixel
|
||||
* @package WeltPixel_LayeredNavigation
|
||||
* @copyright Copyright (c) 2018 Weltpixel
|
||||
* @author Weltpixel TEAM
|
||||
*/
|
||||
|
||||
namespace WeltPixel\LayeredNavigation\Model\ResourceModel\Layer\Filter;
|
||||
|
||||
/**
|
||||
* Class Attribute
|
||||
* @package WeltPixel\LayeredNavigation\Model\ResourceModel\Layer\Filter
|
||||
*/
|
||||
class Attribute extends \Magento\Catalog\Model\ResourceModel\Layer\Filter\Attribute
|
||||
{
|
||||
|
||||
/**
|
||||
* Retrieve array with products counts per attribute option
|
||||
*
|
||||
* @param \Magento\Catalog\Model\Layer\Filter\FilterInterface $filter
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
* @return array
|
||||
*/
|
||||
public function getCount(\Magento\Catalog\Model\Layer\Filter\FilterInterface $filter)
|
||||
{
|
||||
// clone select from collection with filters
|
||||
$layer = $filter->getLayer();
|
||||
if($layer instanceof \Magento\Catalog\Model\Layer\Search) {
|
||||
$collectionSelect = $layer->getProductCollection()->getSelect();
|
||||
} else {
|
||||
$collectionSelect = $layer->getCurrentCategory()->getProductCollection()->getSelect();
|
||||
}
|
||||
|
||||
$select = clone $collectionSelect;
|
||||
// reset columns, order and limitation conditions
|
||||
$select->reset(\Magento\Framework\DB\Select::COLUMNS);
|
||||
$select->reset(\Magento\Framework\DB\Select::ORDER);
|
||||
$select->reset(\Magento\Framework\DB\Select::LIMIT_COUNT);
|
||||
$select->reset(\Magento\Framework\DB\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);
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
* @category WeltPixel
|
||||
* @package WeltPixel_LayeredNavigation
|
||||
* @copyright Copyright (c) 2018 Weltpixel
|
||||
* @author Weltpixel TEAM
|
||||
*/
|
||||
|
||||
namespace WeltPixel\LayeredNavigation\Model\ResourceModel\Search;
|
||||
|
||||
use Magento\Framework\Api\Search\FilterGroup as SourceFilterGroup;
|
||||
|
||||
/**
|
||||
* Class FilterGroup
|
||||
* @package WeltPixel\LayeredNavigation\Model\ResourceModel\Search
|
||||
*/
|
||||
class FilterGroup extends SourceFilterGroup
|
||||
{
|
||||
}
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
/**
|
||||
* @category WeltPixel
|
||||
* @package WeltPixel_LayeredNavigation
|
||||
* @copyright Copyright (c) 2018 Weltpixel
|
||||
* @author Weltpixel TEAM
|
||||
*/
|
||||
|
||||
namespace WeltPixel\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
|
||||
* @package WeltPixel\LayeredNavigation\Model\ResourceModel\Search
|
||||
*/
|
||||
class FilterGroupBuilder extends SourceFilterGroupBuilder
|
||||
{
|
||||
/** @var \Magento\Framework\App\RequestInterface */
|
||||
protected $_request;
|
||||
|
||||
/**
|
||||
* FilterGroupBuilder constructor.
|
||||
* @param \Magento\Framework\Api\ObjectFactory $objectFactory
|
||||
* @param \Magento\Framework\Api\FilterBuilder $filterBuilder
|
||||
* @param \Magento\Framework\App\RequestInterface $request
|
||||
*/
|
||||
public function __construct(
|
||||
ObjectFactory $objectFactory,
|
||||
FilterBuilder $filterBuilder,
|
||||
RequestInterface $request
|
||||
)
|
||||
{
|
||||
parent::__construct($objectFactory, $filterBuilder);
|
||||
|
||||
$this->_request = $request;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return FilterGroupBuilder
|
||||
*/
|
||||
public function cloneObject()
|
||||
{
|
||||
$cloneObject = clone $this;
|
||||
$cloneObject->setFilterBuilder(clone $this->_filterBuilder);
|
||||
|
||||
return $cloneObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $filterBuilder
|
||||
*/
|
||||
public function setFilterBuilder($filterBuilder)
|
||||
{
|
||||
$this->_filterBuilder = $filterBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $attributeCode
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the Data type class name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _getDataObjectType()
|
||||
{
|
||||
return 'Magento\Framework\Api\Search\FilterGroup';
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
* @category WeltPixel
|
||||
* @package WeltPixel_LayeredNavigation
|
||||
* @copyright Copyright (c) 2018 Weltpixel
|
||||
* @author Weltpixel TEAM
|
||||
*/
|
||||
|
||||
namespace WeltPixel\LayeredNavigation\Model\ResourceModel\Search;
|
||||
|
||||
use Magento\Framework\Api\Search\SearchCriteria as SourceSearchCriteria;
|
||||
|
||||
/**
|
||||
* Class SearchCriteria
|
||||
* @package WeltPixel\LayeredNavigation\Model\ResourceModel\Search
|
||||
*/
|
||||
class SearchCriteria extends SourceSearchCriteria
|
||||
{
|
||||
}
|
||||
Executable
+73
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
/**
|
||||
* @category WeltPixel
|
||||
* @package WeltPixel_LayeredNavigation
|
||||
* @copyright Copyright (c) 2018 Weltpixel
|
||||
* @author Weltpixel TEAM
|
||||
*/
|
||||
|
||||
namespace WeltPixel\LayeredNavigation\Model\ResourceModel\Search;
|
||||
|
||||
use Magento\Framework\Api\ObjectFactory;
|
||||
use Magento\Framework\Api\Search\SearchCriteriaBuilder as SourceSearchCriteriaBuilder;
|
||||
use Magento\Framework\Api\SortOrderBuilder;
|
||||
|
||||
/**
|
||||
* Class SearchCriteriaBuilder
|
||||
* @package WeltPixel\LayeredNavigation\Model\ResourceModel\Search
|
||||
*/
|
||||
class SearchCriteriaBuilder extends SourceSearchCriteriaBuilder
|
||||
{
|
||||
/**
|
||||
* @param ObjectFactory $objectFactory
|
||||
* @param FilterGroupBuilder $filterGroupBuilder
|
||||
* @param SortOrderBuilder $sortOrderBuilder
|
||||
*/
|
||||
public function __construct(
|
||||
ObjectFactory $objectFactory,
|
||||
FilterGroupBuilder $filterGroupBuilder,
|
||||
SortOrderBuilder $sortOrderBuilder
|
||||
)
|
||||
{
|
||||
parent::__construct($objectFactory, $filterGroupBuilder, $sortOrderBuilder);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $attributeCode
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function removeFilter($attributeCode)
|
||||
{
|
||||
$this->filterGroupBuilder->removeFilter($attributeCode);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return SearchCriteriaBuilder
|
||||
*/
|
||||
public function cloneObject()
|
||||
{
|
||||
$cloneObject = clone $this;
|
||||
$cloneObject->setFilterGroupBuilder($this->filterGroupBuilder->cloneObject());
|
||||
|
||||
return $cloneObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $filterGroupBuilder
|
||||
*/
|
||||
public function setFilterGroupBuilder($filterGroupBuilder)
|
||||
{
|
||||
$this->filterGroupBuilder = $filterGroupBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function _getDataObjectType()
|
||||
{
|
||||
return 'Magento\Framework\Api\Search\SearchCriteria';
|
||||
}
|
||||
}
|
||||
+496
@@ -0,0 +1,496 @@
|
||||
<?php
|
||||
/**
|
||||
* @category WeltPixel
|
||||
* @package WeltPixel_LayeredNavigation
|
||||
* @copyright Copyright (c) 2018 Weltpixel
|
||||
* @author Weltpixel TEAM
|
||||
*/
|
||||
|
||||
namespace WeltPixel\LayeredNavigation\Observer\Edit\Tab\Front;
|
||||
|
||||
use Magento\Config\Model\Config\Source;
|
||||
use Magento\Framework\Module\Manager;
|
||||
use Magento\Framework\Event\ObserverInterface;
|
||||
use Magento\Framework\App\Request\Http;
|
||||
use WeltPixel\LayeredNavigation\Model\AttributeOptions;
|
||||
use Magento\Catalog\Model\ResourceModel\Eav\Attribute;
|
||||
|
||||
/**
|
||||
* Class WpProductAttributeFormBuildFrontTabObserver
|
||||
* @package WeltPixel\LayeredNavigation\Observer\Edit\Tab\Front
|
||||
*/
|
||||
class WpProductAttributeFormBuildFrontTabObserver implements ObserverInterface
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Config\Model\Config\Source\Yesno
|
||||
*/
|
||||
protected $optionList;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Module\Manager
|
||||
*/
|
||||
protected $moduleManager;
|
||||
|
||||
/**
|
||||
* @var Http
|
||||
*/
|
||||
protected $_request;
|
||||
|
||||
/**
|
||||
* @var AttributeOptions
|
||||
*/
|
||||
protected $_wpModel;
|
||||
|
||||
protected $_wpAttributeObj = false;
|
||||
|
||||
/**
|
||||
* @var Attribute
|
||||
*/
|
||||
protected $_attributeModel;
|
||||
|
||||
/**
|
||||
* WpProductAttributeFormBuildFrontTabObserver constructor.
|
||||
* @param Manager $moduleManager
|
||||
* @param Source\Yesno $optionList
|
||||
* @param Http $request
|
||||
* @param AttributeOptions $wpModel
|
||||
* @param Attribute $attributeModel
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
*/
|
||||
public function __construct(
|
||||
Manager $moduleManager,
|
||||
Source\Yesno $optionList,
|
||||
Http $request,
|
||||
AttributeOptions $wpModel,
|
||||
Attribute $attributeModel
|
||||
)
|
||||
{
|
||||
$this->optionList = $optionList;
|
||||
$this->moduleManager = $moduleManager;
|
||||
$this->_request = $request;
|
||||
$this->_wpModel = $wpModel;
|
||||
$this->_attributeModel = $attributeModel;
|
||||
|
||||
$this->_getWpAttributeOptionValues();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Magento\Framework\Event\Observer $observer
|
||||
* @return void
|
||||
*/
|
||||
public function execute(\Magento\Framework\Event\Observer $observer)
|
||||
{
|
||||
if (!$this->moduleManager->isOutputEnabled('WeltPixel_LayeredNavigation')) {
|
||||
return;
|
||||
}
|
||||
$isSwatchAttr = $this->_isSwatchAttr();
|
||||
$swatchComment = $isSwatchAttr ? '<br/>This setting can not be used with swatch attribute types.' : '';
|
||||
|
||||
/** @var \Magento\Framework\Data\Form\AbstractForm $form */
|
||||
$form = $observer->getForm();
|
||||
|
||||
$fieldset = $form->addFieldset(
|
||||
'wp_front_fieldset',
|
||||
['legend' => __('WeltPixel Layered Navigation Properties'), 'collapsable' => false]
|
||||
);
|
||||
$field = '';
|
||||
|
||||
$fieldset->addField(
|
||||
'wp_display_options',
|
||||
'select',
|
||||
[
|
||||
'name' => 'wp_display_options',
|
||||
'label' => __("Filter Display Options"),
|
||||
'title' => __('Can be used only with catalog input type Dropdown, Multiple Select and Price'),
|
||||
'note' => __('Can be used only with catalog input type Dropdown, Multiple Select and Price. %1', $swatchComment),
|
||||
'values' => [
|
||||
['value' => 0, 'label' => __('Closed')],
|
||||
['value' => 1, 'label' => __('Fully Opened')],
|
||||
['value' => 2, 'label' => __('Expandable')],
|
||||
],
|
||||
'value' => $this->_getDisplayOption(),
|
||||
]
|
||||
);
|
||||
|
||||
$field = $fieldset->addField(
|
||||
'wp_visible_options',
|
||||
'text',
|
||||
[
|
||||
'name' => 'wp_visible_options',
|
||||
'label' => __("Initial Number of Visible Options"),
|
||||
'value' => $this->_getVisibleOptions(),
|
||||
'title' => __('The number of attribute option(s) that will be initially visible. Can be used only with Filter Display Options - Expandable.'),
|
||||
'note' => __('The number of attribute option(s) that will be initially visible. Can be used only with Filter Display Options - Expandable. %1', $swatchComment)
|
||||
|
||||
]
|
||||
);
|
||||
|
||||
$field = $fieldset->addField(
|
||||
'wp_visible_options_step',
|
||||
'select',
|
||||
[
|
||||
'name' => 'wp_visible_options_step',
|
||||
'label' => __("Expandable items behaviour"),
|
||||
'values' => [
|
||||
['value' => 99, 'label' => __('All')],
|
||||
['value' => 5, 'label' => __('Show 5 more')],
|
||||
['value' => 10, 'label' => __('Show 10 more')],
|
||||
['value' => 15, 'label' => __('Show 15 more')],
|
||||
],
|
||||
'value' => $this->_getVisibleOptions(),
|
||||
'title' => __('Select the number of attribute option(s) to show/hide when using Expand feature. Can be used only with Filter Display Options - Expandable.'),
|
||||
'note' => __('Select the number of attribute option(s) to show/hide when using Expand feature. Can be used only with Filter Display Options - Expandable. %1', $swatchComment)
|
||||
|
||||
]
|
||||
);
|
||||
|
||||
$fieldset->addField(
|
||||
'wp_is_multiselect',
|
||||
'select',
|
||||
[
|
||||
'name' => 'wp_is_multiselect',
|
||||
'label' => __("Enable Multiselect"),
|
||||
'value' => $this->_getIsMultiselect(),
|
||||
'values' => [
|
||||
['value' => 0, 'label' => __('No')],
|
||||
['value' => 1, 'label' => __('Yes')],
|
||||
],
|
||||
'title' => __('Allow to filter multiple options from the same attribute.'),
|
||||
'note' => __('Allow to filter multiple options from the same attribute.')
|
||||
|
||||
]
|
||||
);
|
||||
|
||||
$fieldset->addField(
|
||||
'wp_keep_open_after_filter',
|
||||
'select',
|
||||
[
|
||||
'name' => 'wp_keep_open_after_filter',
|
||||
'label' => __("Keep attribute opened after filterings"),
|
||||
'value' => 0,
|
||||
'values' => [
|
||||
['value' => 0, 'label' => __('No')],
|
||||
['value' => 1, 'label' => __('Yes')],
|
||||
],
|
||||
'title' => __('Allow to keep attribute open after filtering. Only available in PRO version of this extension. <br>
|
||||
<a style="font-size: 14px" target="_blank" href="https://www.weltpixel.com/magento2-layered-navigation.html">Upgrade to Pro version</a> to enable this functionality.'),
|
||||
'note' => __('Allow to keep attribute open after filtering. Only available in PRO version of this extension. <br>
|
||||
<a style="font-size: 14px" target="_blank" href="https://www.weltpixel.com/magento2-layered-navigation.html">Upgrade to Pro version</a> to enable this functionality.')
|
||||
]
|
||||
);
|
||||
|
||||
$fieldset->addField(
|
||||
'wp_show_quantity',
|
||||
'select',
|
||||
[
|
||||
'name' => 'wp_show_quantity',
|
||||
'label' => __("Show Item Counter"),
|
||||
'value' => $this->_getShowQuantity(),
|
||||
'values' => [
|
||||
['value' => 0, 'label' => __('No')],
|
||||
['value' => 1, 'label' => __('Yes')],
|
||||
],
|
||||
'title' => __('Show item counter next to the current attribute options.'),
|
||||
'note' => __('Show item counter next to the current attribute options. %1', $swatchComment)
|
||||
|
||||
]
|
||||
);
|
||||
|
||||
$fieldset->addField(
|
||||
'wp_sort_by',
|
||||
'select',
|
||||
[
|
||||
'name' => 'wp_sort_by',
|
||||
'label' => __("Sort By"),
|
||||
'value' => $this->_getSortBy(),
|
||||
'values' => [
|
||||
['value' => 1, 'label' => __('Position')],
|
||||
['value' => 2, 'label' => __('Name')],
|
||||
],
|
||||
'title' => __('Select the sorting of the current attribute options.'),
|
||||
'note' => __('Select the sorting of the current attribute options. %1', $swatchComment)
|
||||
|
||||
]
|
||||
);
|
||||
|
||||
|
||||
$field->setAfterElementHtml(
|
||||
"<script>
|
||||
//<![CDATA[
|
||||
require(['jquery', 'jquery/ui'], function($){
|
||||
var acceptedTypeArray = ['select','multiselect','price','swatch_visual','swatch_text'],
|
||||
wpDisplayOptionEl = $('#wp_display_options'),
|
||||
wpVisibleOptionsEl = $('#wp_visible_options'),
|
||||
wpVisibleOptionsStepEl = $('#wp_visible_options_step'),
|
||||
wpIsMultiselectEl = $('#wp_is_multiselect'),
|
||||
wpKeepAttributeOpenEl = $('#wp_keep_open_after_filter'),
|
||||
wpKeepAttributeOpenRow = $('.field-wp_keep_open_after_filter'),
|
||||
wpShowQuantityEl = $('#wp_show_quantity'),
|
||||
wpSortByEl = $('#wp_sort_by'),
|
||||
mageFrontendInpEl = $('#frontend_input'),
|
||||
|
||||
displayOpt = '" . $this->_getDisplayOption() . "',
|
||||
visibleOpt = '" . $this->_getVisibleOptions() . "',
|
||||
visibleOptStep = '" . $this->_getVisibleOptionsStep() . "',
|
||||
isMultiselect = '" . $this->_getIsMultiselect() . "',
|
||||
isAttributeOpen = '0',
|
||||
showQuantity = '" . $this->_getShowQuantity() . "',
|
||||
sortBy = '" . $this->_getSortBy() . "',
|
||||
isSwatch = '".$isSwatchAttr."';
|
||||
wpDisplayOptionEl.val(displayOpt);
|
||||
wpVisibleOptionsEl.val(visibleOpt);
|
||||
wpVisibleOptionsStepEl.val(visibleOptStep);
|
||||
wpIsMultiselectEl.val(isMultiselect);
|
||||
wpKeepAttributeOpenEl.val(isAttributeOpen);
|
||||
wpShowQuantityEl.val(showQuantity);
|
||||
wpSortByEl.val(sortBy);
|
||||
|
||||
setWpVisibility();
|
||||
|
||||
wpIsMultiselectEl.change(function() {
|
||||
if(wpIsMultiselectEl.val() != 0) {
|
||||
wpKeepAttributeOpenRow.show();
|
||||
} else {
|
||||
wpKeepAttributeOpenRow.hide();
|
||||
}
|
||||
});
|
||||
|
||||
wpDisplayOptionEl.change(function(){
|
||||
|
||||
if($(this).val() == 2) {
|
||||
enableElement(wpVisibleOptionsEl);
|
||||
enableElement(wpVisibleOptionsStepEl);
|
||||
wpVisibleOptionsEl.val(visibleOpt);
|
||||
wpVisibleOptionsStepEl.val(visibleOptStep);
|
||||
} else {
|
||||
wpVisibleOptionsEl.val(99);
|
||||
wpVisibleOptionsStepEl.val(99);
|
||||
disableElement(wpVisibleOptionsEl);
|
||||
disableElement(wpVisibleOptionsStepEl);
|
||||
}
|
||||
});
|
||||
|
||||
mageFrontendInpEl.change(function(){
|
||||
var selVal = $(this).val();
|
||||
if($.inArray(selVal, acceptedTypeArray) !== -1) {
|
||||
enableElement(wpDisplayOptionEl);
|
||||
enableElement(wpIsMultiselectEl);
|
||||
enableElement(wpShowQuantityEl);
|
||||
enableElement(wpSortByEl);
|
||||
if(wpDisplayOptionEl.val() == 2){
|
||||
enableElement(wpVisibleOptionsEl);
|
||||
enableElement(wpVisibleOptionsStepEl);
|
||||
} else {
|
||||
disableElement(wpVisibleOptionsEl);
|
||||
disableElement(wpVisibleOptionsStepEl);
|
||||
}
|
||||
} else {
|
||||
disableElement(wpVisibleOptionsEl);
|
||||
disableElement(wpVisibleOptionsStepEl);
|
||||
disableElement(wpDisplayOptionEl);
|
||||
disableElement(wpIsMultiselectEl);
|
||||
disableElement(wpShowQuantityEl);
|
||||
disableElement(wpSortByEl);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* set wp fields property(disabled)
|
||||
*/
|
||||
function setWpVisibility(){
|
||||
|
||||
disableElement(wpKeepAttributeOpenEl);
|
||||
var elVal = mageFrontendInpEl.val();
|
||||
|
||||
if(wpIsMultiselectEl.val() != 0) {
|
||||
wpKeepAttributeOpenRow.show();
|
||||
} else {
|
||||
wpKeepAttributeOpenRow.hide();
|
||||
}
|
||||
|
||||
if($.inArray(elVal, acceptedTypeArray) !== -1) {
|
||||
enableElement(wpDisplayOptionEl);
|
||||
enableElement(wpIsMultiselectEl);
|
||||
enableElement(wpShowQuantityEl);
|
||||
enableElement(wpSortByEl);
|
||||
|
||||
} else {
|
||||
disableElement(wpVisibleOptionsEl);
|
||||
disableElement(wpVisibleOptionsStepEl);
|
||||
disableElement(wpDisplayOptionEl);
|
||||
disableElement(wpIsMultiselectEl);
|
||||
disableElement(wpShowQuantityEl);
|
||||
disableElement(wpSortByEl);
|
||||
}
|
||||
|
||||
if(wpDisplayOptionEl.val() != 2){
|
||||
disableElement(wpVisibleOptionsEl);
|
||||
disableElement(wpVisibleOptionsStepEl);
|
||||
}
|
||||
|
||||
if(isSwatch) {
|
||||
disableElement(wpDisplayOptionEl);
|
||||
disableElement(wpVisibleOptionsEl);
|
||||
disableElement(wpVisibleOptionsStepEl);
|
||||
disableElement(wpShowQuantityEl);
|
||||
disableElement(wpSortByEl);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* set element as disabled
|
||||
* @param element
|
||||
*/
|
||||
function disableElement(element) {
|
||||
element.prop('disabled', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* remove 'disabled' attribute from element
|
||||
* @param element
|
||||
*/
|
||||
function enableElement(element) {
|
||||
element.removeAttr('disabled');
|
||||
}
|
||||
});
|
||||
//]]>
|
||||
</script>"
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this|bool
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
*/
|
||||
protected function _getWpAttributeOptionValues()
|
||||
{
|
||||
$attributeId = $this->_request->getParam('attribute_id');
|
||||
|
||||
if ($attributeId) {
|
||||
$this->_wpAttributeObj = $this->_wpModel->getDisplayOptionsByAttribute($attributeId);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get attribute 'display_option' value
|
||||
* @return int
|
||||
*/
|
||||
protected function _getDisplayOption()
|
||||
{
|
||||
$val = AttributeOptions::DISPLAY_OPTION_DEF_VAL;
|
||||
if($this->_wpAttributeObj) {
|
||||
if(!empty($this->_wpAttributeObj->getData())) {
|
||||
$val = $this->_wpAttributeObj->getDisplayOption();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $val;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get attribute 'visible_options' value
|
||||
* @return int
|
||||
*/
|
||||
protected function _getVisibleOptions()
|
||||
{
|
||||
$val = '';
|
||||
if($this->_wpAttributeObj) {
|
||||
if(!empty($this->_wpAttributeObj->getData())) {
|
||||
$val = $this->_wpAttributeObj->getVisibleOptions();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $val;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get attribute 'visible_options' value
|
||||
* @return int
|
||||
*/
|
||||
protected function _getVisibleOptionsStep()
|
||||
{
|
||||
$val = '';
|
||||
if($this->_wpAttributeObj) {
|
||||
if(!empty($this->_wpAttributeObj->getData())) {
|
||||
$val = $this->_wpAttributeObj->getVisibleOptionsStep();
|
||||
}
|
||||
}
|
||||
|
||||
return $val;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get attribute 'is_multiselect' value
|
||||
* @return int
|
||||
*/
|
||||
protected function _getIsMultiselect()
|
||||
{
|
||||
$val = 0;
|
||||
if($this->_wpAttributeObj) {
|
||||
if(!empty($this->_wpAttributeObj->getData())) {
|
||||
$val = $this->_wpAttributeObj->getIsMultiselect();
|
||||
}
|
||||
}
|
||||
|
||||
return $val;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get attribute 'show_quantity' value
|
||||
* @return int
|
||||
*/
|
||||
protected function _getShowQuantity()
|
||||
{
|
||||
$val = 0;
|
||||
if($this->_wpAttributeObj) {
|
||||
if(!empty($this->_wpAttributeObj->getData())) {
|
||||
$val = $this->_wpAttributeObj->getShowQuantity();
|
||||
}
|
||||
}
|
||||
|
||||
return $val;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get attribute 'sort_by' value
|
||||
* @return int
|
||||
*/
|
||||
protected function _getSortBy()
|
||||
{
|
||||
$val = 1;
|
||||
if($this->_wpAttributeObj) {
|
||||
if(!empty($this->_wpAttributeObj->getData())) {
|
||||
$val = $this->_wpAttributeObj->getSortBy();
|
||||
}
|
||||
}
|
||||
|
||||
return $val;
|
||||
}
|
||||
|
||||
protected function _isSwatchAttr() {
|
||||
$attributeId = $this->_request->getParam('attribute_id');
|
||||
|
||||
if ($attributeId) {
|
||||
$attr = $this->_attributeModel->load($attributeId);
|
||||
if(!$attr->getAdditionalData()) {
|
||||
return false;
|
||||
}
|
||||
$addititonalData = $attr->getAdditionalData();
|
||||
$attrData = json_decode($addititonalData, true);
|
||||
if(isset($attrData['swatch_input_type'])) {
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
/**
|
||||
* @category WeltPixel
|
||||
* @package WeltPixel_LayeredNavigation
|
||||
* @copyright Copyright (c) 2018 Weltpixel
|
||||
* @author Weltpixel TEAM
|
||||
*/
|
||||
|
||||
namespace WeltPixel\LayeredNavigation\Observer;
|
||||
|
||||
use Magento\Framework\Event\Observer;
|
||||
use Magento\Framework\Event\ObserverInterface;
|
||||
|
||||
/**
|
||||
* Class RemoveBlocks
|
||||
* @package WeltPixel\LayeredNavigation\Observer
|
||||
*/
|
||||
class RemoveBlocks implements ObserverInterface
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\App\Config\ScopeConfigInterface
|
||||
*/
|
||||
protected $_scopeConfig;
|
||||
/**
|
||||
* @var \WeltPixel\LayeredNavigation\Helper\Data
|
||||
*/
|
||||
protected $_wpHelper;
|
||||
/**
|
||||
* @var \Magento\Framework\App\Request\Http
|
||||
*/
|
||||
protected $_request;
|
||||
|
||||
/**
|
||||
* RemoveBlocks constructor.
|
||||
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
|
||||
* @param \WeltPixel\LayeredNavigation\Helper\Data $wpHelper
|
||||
* @param \Magento\Framework\App\Request\Http $request
|
||||
*/
|
||||
public function __construct(
|
||||
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
|
||||
\WeltPixel\LayeredNavigation\Helper\Data $wpHelper,
|
||||
\Magento\Framework\App\Request\Http $request
|
||||
) {
|
||||
$this->_scopeConfig = $scopeConfig;
|
||||
$this->_wpHelper = $wpHelper;
|
||||
$this->_request = $request;
|
||||
}
|
||||
|
||||
public function execute(Observer $observer)
|
||||
{
|
||||
if($this->_isAdvancedSearchResultPage()) {
|
||||
return;
|
||||
}
|
||||
/** @var \Magento\Framework\View\Layout $layout */
|
||||
$layout = $observer->getLayout();
|
||||
$wishlistBlock = $layout->getBlock('wishlist_sidebar');
|
||||
$compareBlock = $layout->getBlock('catalog.compare.sidebar');
|
||||
$reorderBlock = $layout->getBlock('sale.reorder.sidebar');
|
||||
|
||||
|
||||
if($wishlistBlock) {
|
||||
$showWishlistBlock = $this->_wpHelper->showWishlistBlock();
|
||||
if (!$showWishlistBlock) {
|
||||
$layout->unsetElement('wishlist_sidebar');
|
||||
}
|
||||
}
|
||||
|
||||
if($compareBlock) {
|
||||
$showCompareBlock = $this->_wpHelper->showCompareBlock();
|
||||
if (!$showCompareBlock ) {
|
||||
$layout->unsetElement('catalog.compare.sidebar');
|
||||
}
|
||||
}
|
||||
|
||||
if ($reorderBlock) {
|
||||
$showRecentlyOrderedBlock = $this->_wpHelper->showRecentlyOrderedBlock();
|
||||
if (!$showRecentlyOrderedBlock) {
|
||||
$layout->unsetElement('sale.reorder.sidebar');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function _isAdvancedSearchResultPage() {
|
||||
$is = false;
|
||||
$controller = $this->_request->getControllerName();
|
||||
$action = $this->_request->getActionName();
|
||||
$route = $this->_request->getRouteName();
|
||||
|
||||
if($route == 'catalogsearch' && $controller == 'advanced' && $action == 'result') {
|
||||
$is = true;
|
||||
}
|
||||
|
||||
return $is;
|
||||
}
|
||||
}
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
/**
|
||||
* @category WeltPixel
|
||||
* @package WeltPixel_LayeredNavigation
|
||||
* @copyright Copyright (c) 2018 Weltpixel
|
||||
* @author Weltpixel TEAM
|
||||
*/
|
||||
|
||||
namespace WeltPixel\LayeredNavigation\Observer;
|
||||
|
||||
use Magento\Framework\Event\Observer as EventObserver;
|
||||
use Magento\Framework\Event\ObserverInterface;
|
||||
|
||||
/**
|
||||
* Class WpCatalogAttributeSaveAfterObserver
|
||||
* @package WeltPixel\LayeredNavigation\Model\Observer
|
||||
*/
|
||||
class WpCatalogAttributeSaveAfterObserver implements ObserverInterface
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $_lnInputTypes = [
|
||||
'select',
|
||||
'multiselect',
|
||||
'price'
|
||||
];
|
||||
|
||||
/**
|
||||
* @var \WeltPixel\LayeredNavigation\Model\AttributeOptions
|
||||
*/
|
||||
protected $_attributeOptions;
|
||||
|
||||
/**
|
||||
* @param CheckSalesRulesAvailability $checkSalesRulesAvailability
|
||||
*/
|
||||
public function __construct(
|
||||
\WeltPixel\LayeredNavigation\Model\AttributeOptions $attributeOptions
|
||||
)
|
||||
{
|
||||
$this->_attributeOptions = $attributeOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* After save attribute
|
||||
*
|
||||
* @param EventObserver $observer
|
||||
* @return $this
|
||||
*/
|
||||
public function execute(EventObserver $observer)
|
||||
{
|
||||
$attribute = $observer->getEvent()->getAttribute();
|
||||
$wpAttributeOptions = $this->_attributeOptions->getDisplayOptionsByAttribute($attribute->getAttributeId());
|
||||
|
||||
if (in_array($attribute->getFrontendInput(), $this->_lnInputTypes)) {
|
||||
// insert
|
||||
if (!$wpAttributeOptions->getId()) {
|
||||
$this->_attributeOptions->setAttributeId($attribute->getAttributeId())
|
||||
->setDisplayOption($attribute->getWpDisplayOptions())
|
||||
->setVisibleOptions($attribute->getWpVisibleOptions())
|
||||
->setVisibleOptionsStep($attribute->getWpVisibleOptionsStep())
|
||||
->setIsMultiselect($attribute->getWpIsMultiselect())
|
||||
->setShowQuantity($attribute->getWpShowQuantity())
|
||||
->setSortBy($attribute->getWpSortBy())
|
||||
->save();
|
||||
} // update
|
||||
else {
|
||||
$visibleItems = ($attribute->getWpDisplayOptions() == \WeltPixel\LayeredNavigation\Model\AttributeOptions::DISPLAY_OPTION_OPEN_VAL || $attribute->getWpDisplayOptions() == \WeltPixel\LayeredNavigation\Model\AttributeOptions::DISPLAY_OPTION_DEF_VAL) ? \WeltPixel\LayeredNavigation\Model\AttributeOptions::VISIBLE_OPTIONS_DEF_VAL : $attribute->getWpVisibleOptions();
|
||||
$visibleItemsStep = (!$attribute->getWpDisplayOptions() == \WeltPixel\LayeredNavigation\Model\AttributeOptions::DISPLAY_OPTION_OPEN_VAL || $attribute->getWpDisplayOptions() == \WeltPixel\LayeredNavigation\Model\AttributeOptions::DISPLAY_OPTION_DEF_VAL) ? \WeltPixel\LayeredNavigation\Model\AttributeOptions::VISIBLE_OPTIONS_STEP_DEF_VAL : $attribute->getWpVisibleOptionsStep();
|
||||
$this->_attributeOptions->setId($wpAttributeOptions->getId())
|
||||
->setDisplayOption($attribute->getWpDisplayOptions())
|
||||
->setVisibleOptions($visibleItems)
|
||||
->setVisibleOptionsStep($visibleItemsStep)
|
||||
->setIsMultiselect($attribute->getWpIsMultiselect())
|
||||
->setShowQuantity($attribute->getWpShowQuantity())
|
||||
->setSortBy($attribute->getWpSortBy())
|
||||
->save();
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
<?php
|
||||
/**
|
||||
* @category WeltPixel
|
||||
* @package WeltPixel_LayeredNavigation
|
||||
* @copyright Copyright (c) 2018 Weltpixel
|
||||
* @author Weltpixel TEAM
|
||||
*/
|
||||
|
||||
namespace WeltPixel\LayeredNavigation\Plugin\CatalogSearch;
|
||||
|
||||
use Magento\Catalog\Model\Layer\Resolver;
|
||||
use Magento\Framework\Controller\Result\JsonFactory;
|
||||
use Magento\Framework\View\Result\PageFactory;
|
||||
use Magento\Search\Model\QueryFactory;
|
||||
use Magento\Store\Model\StoreManagerInterface;
|
||||
use Magento\CatalogSearch\Helper\Data as CatalogSearchHelper;
|
||||
use WeltPixel\LayeredNavigation\Helper\Data as WpHelper;
|
||||
|
||||
/**
|
||||
* Class View
|
||||
* @package WeltPixel\LayeredNavigation\Plugin\Category
|
||||
*/
|
||||
class ResultView
|
||||
{
|
||||
/**
|
||||
* Catalog session
|
||||
*
|
||||
* @var Session
|
||||
*/
|
||||
protected $_catalogSession;
|
||||
|
||||
/**
|
||||
* @var StoreManagerInterface
|
||||
*/
|
||||
protected $_storeManager;
|
||||
|
||||
/**
|
||||
* @var QueryFactory
|
||||
*/
|
||||
private $_queryFactory;
|
||||
|
||||
/**
|
||||
* Catalog Layer Resolver
|
||||
*
|
||||
* @var Resolver
|
||||
*/
|
||||
protected $layerResolver;
|
||||
|
||||
/**
|
||||
* @var JsonFactory
|
||||
*/
|
||||
protected $_resultJsonFactory;
|
||||
|
||||
/**
|
||||
* @var PageFactory
|
||||
*/
|
||||
protected $_resultPageFactory;
|
||||
|
||||
/**
|
||||
* @var CatalogSearchHelper
|
||||
*/
|
||||
protected $_catalogSearchHelper;
|
||||
|
||||
/**
|
||||
* @var WpHelper
|
||||
*/
|
||||
protected $_wpHelper;
|
||||
|
||||
/**
|
||||
* ResultView constructor.
|
||||
* @param StoreManagerInterface $storeManager
|
||||
* @param QueryFactory $queryFactory
|
||||
* @param Resolver $layerResolver
|
||||
* @param JsonFactory $resultJsonFactory
|
||||
* @param PageFactory $resultPageFactory
|
||||
* @param CatalogSearchHelper $catalogSearchHelper
|
||||
* @param WpHelper $wpHelper
|
||||
*/
|
||||
public function __construct(
|
||||
StoreManagerInterface $storeManager,
|
||||
QueryFactory $queryFactory,
|
||||
Resolver $layerResolver,
|
||||
JsonFactory $resultJsonFactory,
|
||||
PageFactory $resultPageFactory,
|
||||
CatalogSearchHelper $catalogSearchHelper,
|
||||
WpHelper $wpHelper
|
||||
) {
|
||||
$this->_storeManager = $storeManager;
|
||||
$this->_queryFactory = $queryFactory;
|
||||
$this->layerResolver = $layerResolver;
|
||||
$this->_resultJsonFactory = $resultJsonFactory;
|
||||
$this->_resultPageFactory = $resultPageFactory;
|
||||
$this->_catalogSearchHelper = $catalogSearchHelper;
|
||||
$this->_wpHelper = $wpHelper;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Magento\CatalogSearch\Controller\Result\Index $subject
|
||||
* @param \Closure $method
|
||||
* @return $this|array|mixed
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
*/
|
||||
public function aroundExecute(
|
||||
\Magento\CatalogSearch\Controller\Result\Index $subject,
|
||||
\Closure $method
|
||||
){
|
||||
if($subject->getRequest()->getParam('ajax') == 1){
|
||||
$requestUri = $subject->getRequest()->getRequestUri();
|
||||
$requestUri = preg_replace('/(\?|&)ajax=1/', '', $requestUri);
|
||||
$subject->getRequest()->setRequestUri($requestUri);
|
||||
try {
|
||||
$this->layerResolver->create(Resolver::CATALOG_LAYER_SEARCH);
|
||||
} catch (\Exception $ex) {
|
||||
}
|
||||
/* @var $query \Magento\Search\Model\Query */
|
||||
$query = $this->_queryFactory->get();
|
||||
|
||||
$query->setStoreId($this->_storeManager->getStore()->getId());
|
||||
|
||||
$resultJson = $this->_resultJsonFactory->create();
|
||||
|
||||
if ($query->getQueryText() != '') {
|
||||
|
||||
if ($this->_catalogSearchHelper->isMinQueryLength()) {
|
||||
$query->setId(0)->setIsActive(1)->setIsProcessed(1);
|
||||
} else {
|
||||
$query->saveIncrementalPopularity();
|
||||
|
||||
if ($query->getRedirect()) {
|
||||
$data = [
|
||||
'success' => true,
|
||||
'redirect_url' => $query->getRedirect()
|
||||
];
|
||||
return $resultJson->setData($data);
|
||||
}
|
||||
}
|
||||
|
||||
$this->_catalogSearchHelper->checkNotes();
|
||||
$pageFactory = $this->_resultPageFactory->create();
|
||||
$resultsBlockHtml = $pageFactory->getLayout()->getBlock('search.result')->toHtml();
|
||||
$leftNavBlockHtml = $pageFactory->getLayout()->getBlock('catalogsearch.leftnav')->toHtml();
|
||||
|
||||
$dataLayerContent = '';
|
||||
$dataLayerContentGa4 = '';
|
||||
$dataLayerBlock = $pageFactory->getLayout()->getBlock('head.additional');
|
||||
if ($dataLayerBlock) {
|
||||
$dLBlockHtml = $dataLayerBlock->toHtml();
|
||||
|
||||
preg_match('/var dlObjects ?= ?(.*?)];/', $dLBlockHtml, $matches);
|
||||
if (count($matches) == 2) {
|
||||
$dataLayerContent = $matches[1] . ']';
|
||||
}
|
||||
preg_match('/var dl4Objects ?= ?(.*?)];/', $dLBlockHtml, $matchesGa4);
|
||||
if (count($matchesGa4) == 2) {
|
||||
$dataLayerContentGa4 = $matchesGa4[1] . ']';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$ga4ServerSideViewItemListContent = '';
|
||||
$ga4ServerSideViewItemListBlock = $pageFactory->getLayout()->getBlock('weltpixel-ga4-server-view-item-list');
|
||||
if ($ga4ServerSideViewItemListBlock) {
|
||||
$ga4ServerSideViewItemListBlockHtml = $ga4ServerSideViewItemListBlock->toHtml();
|
||||
preg_match('/<input.*id="wp_ga4_server_side_view_item_list".*value="(.*?)"/', $ga4ServerSideViewItemListBlockHtml, $matchesGa4ServerSide);
|
||||
if (count($matchesGa4ServerSide) == 2) {
|
||||
$ga4ServerSideViewItemListContent = $matchesGa4ServerSide[1];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return $this->_resultJsonFactory->create()->setData(
|
||||
[
|
||||
'success' => true,
|
||||
'html' => [
|
||||
'products_list' => $resultsBlockHtml,
|
||||
'filters' => $leftNavBlockHtml,
|
||||
'dataLayer' => $dataLayerContent,
|
||||
'dataLayerGA4' => $dataLayerContentGa4,
|
||||
'ga4ServerSideItemListHash' => $ga4ServerSideViewItemListContent
|
||||
]
|
||||
]
|
||||
);
|
||||
return $data;
|
||||
} else {
|
||||
$data = [
|
||||
'success' => true,
|
||||
'redirect_url' => $this->_redirect->getRedirectUrl()
|
||||
];
|
||||
return $resultJson->setData($data);
|
||||
}
|
||||
} else {
|
||||
return $method();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
/**
|
||||
* @category WeltPixel
|
||||
* @package WeltPixel_LayeredNavigation
|
||||
* @copyright Copyright (c) 2018 Weltpixel
|
||||
* @author Weltpixel TEAM
|
||||
*/
|
||||
|
||||
namespace WeltPixel\LayeredNavigation\Plugin\Category;
|
||||
|
||||
use Magento\Framework\Controller\Result\JsonFactory;
|
||||
use Magento\Framework\View\Result\Page;
|
||||
use Magento\Framework\UrlInterface;
|
||||
use WeltPixel\LayeredNavigation\Helper\Data;
|
||||
use Magento\Framework\View\Result\PageFactory;
|
||||
use Magento\Framework\App\Action\Action;
|
||||
|
||||
/**
|
||||
* Class View
|
||||
* @package WeltPixel\LayeredNavigation\Plugin\Category
|
||||
*/
|
||||
class View
|
||||
{
|
||||
/**
|
||||
* @var JsonFactory
|
||||
*/
|
||||
protected $_resultJsonFactory;
|
||||
/**
|
||||
* @var UrlInterface
|
||||
*/
|
||||
protected $_storeManager;
|
||||
/**
|
||||
* @var \WeltPixel\LayeredNavigation\Helper\Data
|
||||
*/
|
||||
protected $_wpHelper;
|
||||
|
||||
/**
|
||||
* @var PageFactory
|
||||
*/
|
||||
protected $pageFactory;
|
||||
|
||||
/**
|
||||
* View constructor.
|
||||
* @param JsonFactory $resultJsonFactory
|
||||
* @param UrlInterface $_storeManager
|
||||
* @param Data $wpHelper
|
||||
* @param PageFactory $pageFactory
|
||||
*/
|
||||
public function __construct(
|
||||
JsonFactory $resultJsonFactory,
|
||||
UrlInterface $_storeManager,
|
||||
Data $wpHelper,
|
||||
PageFactory $pageFactory
|
||||
)
|
||||
{
|
||||
$this->_resultJsonFactory = $resultJsonFactory;
|
||||
$this->_storeManager = $_storeManager;
|
||||
$this->_wpHelper = $wpHelper;
|
||||
$this->pageFactory = $pageFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Action $subject
|
||||
* @param $page
|
||||
* @return $this|void
|
||||
*/
|
||||
public function afterExecute(Action $subject, $page)
|
||||
{
|
||||
if(!$this->_wpHelper->isAjaxEnabled()) {
|
||||
return $page;
|
||||
}
|
||||
|
||||
$response = $page;
|
||||
if ($response instanceof Page) {
|
||||
if ($subject->getRequest()->getParam('ajax') == 1) {
|
||||
$subject->getRequest()->getQuery()->set('ajax', null);
|
||||
$requestUri = $subject->getRequest()->getRequestUri();
|
||||
$requestUri = preg_replace('/(\?|&)ajax=1/', '', $requestUri);
|
||||
$subject->getRequest()->setRequestUri($requestUri);
|
||||
|
||||
$productsList = $response->getLayout()->getBlock('category.products.list');
|
||||
$listMode = $subject->getRequest()->getParam('product_list_mode');
|
||||
if($listMode) {
|
||||
$productsList->getChildBlock('product_list_toolbar')->setData('_current_grid_mode', $listMode);
|
||||
}
|
||||
$productsListBlockHtml = $productsList->toHtml();
|
||||
$leftNavBlockHtml = $response->getLayout()->getBlock('catalog.leftnav')->toHtml();
|
||||
|
||||
$dataLayerContent = '';
|
||||
$dataLayerContentGa4 = '';
|
||||
$dataLayerBlock = $response->getLayout()->getBlock('head.additional');
|
||||
if ($dataLayerBlock) {
|
||||
$dLBlockHtml = $dataLayerBlock->toHtml();
|
||||
preg_match('/var dlObjects ?= ?(.*?)];/', $dLBlockHtml, $matches);
|
||||
if (count($matches) == 2) {
|
||||
$dataLayerContent = $matches[1] . ']';
|
||||
}
|
||||
preg_match('/var dl4Objects ?= ?(.*?)];/', $dLBlockHtml, $matchesGa4);
|
||||
if (count($matchesGa4) == 2) {
|
||||
$dataLayerContentGa4 = $matchesGa4[1] . ']';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$ga4ServerSideViewItemListContent = '';
|
||||
$ga4ServerSideViewItemListBlock = $response->getLayout()->getBlock('weltpixel-ga4-server-view-item-list');
|
||||
if ($ga4ServerSideViewItemListBlock) {
|
||||
$ga4ServerSideViewItemListBlockHtml = $ga4ServerSideViewItemListBlock->toHtml();
|
||||
preg_match('/<input.*id="wp_ga4_server_side_view_item_list".*value="(.*?)"/', $ga4ServerSideViewItemListBlockHtml, $matchesGa4ServerSide);
|
||||
if (count($matchesGa4ServerSide) == 2) {
|
||||
$ga4ServerSideViewItemListContent = $matchesGa4ServerSide[1];
|
||||
}
|
||||
}
|
||||
|
||||
$tags = [];
|
||||
$blocksList = [$productsList,$leftNavBlockHtml];
|
||||
foreach ($blocksList as $block) {
|
||||
if ($block instanceof \Magento\Framework\DataObject\IdentityInterface) {
|
||||
$tags = array_merge($tags, $block->getIdentities());
|
||||
}
|
||||
}
|
||||
$tags = array_unique($tags);
|
||||
|
||||
return $this->_resultJsonFactory->create()->setData(
|
||||
[
|
||||
'success' => true,
|
||||
'html' => [
|
||||
'products_list' => $productsListBlockHtml,
|
||||
'filters' => $leftNavBlockHtml,
|
||||
'dataLayer' => $dataLayerContent,
|
||||
'dataLayerGA4' => $dataLayerContentGa4,
|
||||
'ga4ServerSideItemListHash' => $ga4ServerSideViewItemListContent
|
||||
]
|
||||
]
|
||||
)->setHeader('X-Magento-Tags', implode(',', $tags));
|
||||
}
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
/**
|
||||
* @category WeltPixel
|
||||
* @package WeltPixel_LayeredNavigation
|
||||
* @copyright Copyright (c) 2018 Weltpixel
|
||||
* @author Weltpixel TEAM
|
||||
*/
|
||||
|
||||
namespace WeltPixel\LayeredNavigation\Plugin\Layer;
|
||||
|
||||
use WeltPixel\LayeredNavigation\Helper\Data;
|
||||
|
||||
/**
|
||||
* Class FilterList
|
||||
* @package WeltPixel\LayeredNavigation\Plugin\Layer
|
||||
*/
|
||||
class FilterList
|
||||
{
|
||||
/**
|
||||
* @var \WeltPixel\LayeredNavigation\Helper\Data
|
||||
*/
|
||||
protected $_wpHelper;
|
||||
|
||||
/**
|
||||
* FilterList constructor.
|
||||
* @param Data $wpHelper
|
||||
*/
|
||||
public function __construct(
|
||||
Data $wpHelper
|
||||
)
|
||||
{
|
||||
$this->_wpHelper = $wpHelper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove category filter if disabled in configuration
|
||||
*
|
||||
* @param \Magento\Catalog\Model\Layer\FilterList $subject
|
||||
* @param $result
|
||||
* @return array
|
||||
*/
|
||||
public function afterGetFilters(\Magento\Catalog\Model\Layer\FilterList $subject, $result)
|
||||
{
|
||||
if(!$this->_wpHelper->isEnabled()){
|
||||
return $result;
|
||||
}
|
||||
$filteredResult = [];
|
||||
if(!$this->_wpHelper->showCategoriesBlock()) {
|
||||
foreach($result as $r) {
|
||||
if($r->getRequestVar() != 'cat') {
|
||||
$filteredResult[] = $r;
|
||||
}
|
||||
}
|
||||
return $filteredResult;
|
||||
|
||||
} else {
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
<?php
|
||||
/**
|
||||
* @category WeltPixel
|
||||
* @package WeltPixel_LayeredNavigation
|
||||
* @copyright Copyright (c) 2018 Weltpixel
|
||||
* @author Weltpixel TEAM
|
||||
*/
|
||||
|
||||
namespace WeltPixel\LayeredNavigation\Plugin\Model\Layer\Filter;
|
||||
|
||||
use WeltPixel\LayeredNavigation\Helper\Data as LayerHelper;
|
||||
use WeltPixel\LayeredNavigation\Model\Layer\Filter as FilterModel;
|
||||
|
||||
/**
|
||||
* Class Item
|
||||
* @package WeltPixel\LayeredNavigation\Model\Plugin\Layer\Filter
|
||||
*/
|
||||
class Item
|
||||
{
|
||||
/** @var \Magento\Framework\UrlInterface */
|
||||
protected $_url;
|
||||
|
||||
/** @var \Magento\Theme\Block\Html\Pager */
|
||||
protected $_htmlPagerBlock;
|
||||
|
||||
/** @var \Magento\Framework\App\RequestInterface */
|
||||
protected $_request;
|
||||
|
||||
/** @var \WeltPixel\LayeredNavigation\Helper\Data */
|
||||
protected $_wpHelper;
|
||||
/**
|
||||
* @var FilterModel
|
||||
*/
|
||||
protected $_filterModel;
|
||||
|
||||
/**
|
||||
* Item constructor.
|
||||
* @param \Magento\Framework\UrlInterface $url
|
||||
* @param \Magento\Theme\Block\Html\Pager $htmlPagerBlock
|
||||
* @param \Magento\Framework\App\RequestInterface $request
|
||||
* @param LayerHelper $_wpHelper
|
||||
* @param FilterModel $filterModel
|
||||
*/
|
||||
public function __construct(
|
||||
\Magento\Framework\UrlInterface $url,
|
||||
\Magento\Theme\Block\Html\Pager $htmlPagerBlock,
|
||||
\Magento\Framework\App\RequestInterface $request,
|
||||
LayerHelper $wpHelper,
|
||||
FilterModel $filterModel
|
||||
)
|
||||
{
|
||||
$this->_url = $url;
|
||||
$this->_htmlPagerBlock = $htmlPagerBlock;
|
||||
$this->_request = $request;
|
||||
$this->_wpHelper = $wpHelper;
|
||||
$this->_filterModel = $filterModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Magento\Catalog\Model\Layer\Filter\Item $item
|
||||
* @param $proceed
|
||||
* @return string
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
*/
|
||||
public function __aroundGetUrl(\Magento\Catalog\Model\Layer\Filter\Item $item, $proceed)
|
||||
{
|
||||
if (!$this->_wpHelper->isEnabled()) {
|
||||
return $proceed();
|
||||
}
|
||||
|
||||
$value = [];
|
||||
$filter = $item->getFilter();
|
||||
if ($this->_filterModel->isMultiple($filter)) {
|
||||
$requestVar = $filter->getRequestVar();
|
||||
if ($requestValue = $this->_request->getParam($requestVar)) {
|
||||
$value = explode(',', $requestValue);
|
||||
}
|
||||
if (!in_array($item->getValue(), $value)) {
|
||||
$value[] = $item->getValue();
|
||||
}
|
||||
}
|
||||
|
||||
if (sizeof($value)) {
|
||||
$query = [
|
||||
$filter->getRequestVar() => implode(',', $value),
|
||||
$this->_htmlPagerBlock->getPageVarName() => null,
|
||||
];
|
||||
|
||||
return $this->_url->getUrl('*/*/*', ['_current' => true, '_use_rewrite' => true, '_query' => $query]);
|
||||
}
|
||||
|
||||
return $proceed();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Magento\Catalog\Model\Layer\Filter\Item $item
|
||||
* @param $proceed
|
||||
* @return string
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
*/
|
||||
public function aroundGetRemoveUrl(\Magento\Catalog\Model\Layer\Filter\Item $item, $proceed)
|
||||
{
|
||||
if (!$this->_wpHelper->isEnabled()) {
|
||||
return $proceed();
|
||||
}
|
||||
|
||||
$value = [];
|
||||
$filter = $item->getFilter();
|
||||
|
||||
$value = $this->_filterModel->getFilterValue($filter);
|
||||
$itemValue = $item->getValue();
|
||||
if (is_array($item->getValue())) {
|
||||
$itemValue = implode('-', $item->getValue());
|
||||
}
|
||||
if (in_array($itemValue, $value)) {
|
||||
$value = array_diff($value, [$itemValue]);
|
||||
}
|
||||
|
||||
$params['_query'] = [$filter->getRequestVar() => count($value) ? implode(',', $value) : $filter->getResetValue()];
|
||||
$params['_current'] = true;
|
||||
$params['_use_rewrite'] = true;
|
||||
$params['_escape'] = true;
|
||||
|
||||
return $this->_url->getUrl('*/*/*', $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Magento\Catalog\Model\Layer\Filter\Item $item
|
||||
* @param $proceed
|
||||
* @return string
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
*/
|
||||
public function aroundGetUrl(\Magento\Catalog\Model\Layer\Filter\Item $item, $proceed)
|
||||
{
|
||||
if (!$this->_wpHelper->isEnabled() || $this->_wpHelper->isAjaxEnabled()) {
|
||||
return $proceed();
|
||||
}
|
||||
|
||||
$filter = $item->getFilter();
|
||||
if ($filter instanceof \WeltPixel\LayeredNavigation\Model\Layer\Filter\Category) {
|
||||
$isMultiSelect = false;
|
||||
} else {
|
||||
$isMultiSelect = $this->_filterModel->isMultiselect($filter->getAttributeModel()->getAttributeId());
|
||||
}
|
||||
|
||||
if (!$isMultiSelect) {
|
||||
return $proceed();
|
||||
}
|
||||
|
||||
$requestVarValue = $this->_filterModel->getFilterValue($filter);
|
||||
|
||||
if (in_array($item->getValue(), $requestVarValue)) {
|
||||
$requestVarValue = array_diff($requestVarValue, [$item->getValue()]);
|
||||
} else {
|
||||
array_push($requestVarValue, $item->getValue());
|
||||
}
|
||||
|
||||
$requestVarValue = implode(",", $requestVarValue);
|
||||
|
||||
$query = [
|
||||
$filter->getRequestVar() => $requestVarValue,
|
||||
$this->_htmlPagerBlock->getPageVarName() => null,
|
||||
];
|
||||
return $this->_url->getUrl('*/*/*', ['_current' => true, '_use_rewrite' => true, '_query' => $query]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
/**
|
||||
* @category WeltPixel
|
||||
* @package WeltPixel_LayeredNavigation
|
||||
* @copyright Copyright (c) 2018 Weltpixel
|
||||
* @author Weltpixel TEAM
|
||||
*/
|
||||
|
||||
namespace WeltPixel\LayeredNavigation\Plugin\Swatches;
|
||||
|
||||
use WeltPixel\LayeredNavigation\Helper\Data as LayerHelper;
|
||||
use WeltPixel\LayeredNavigation\Model\Layer\Filter as FilterModel;
|
||||
|
||||
/**
|
||||
* Class RenderLayered
|
||||
* @package WeltPixel\LayeredNavigation\Plugin\Swatches
|
||||
*/
|
||||
class RenderLayered
|
||||
{
|
||||
/** @var \Magento\Framework\UrlInterface */
|
||||
protected $_url;
|
||||
|
||||
/** @var \Magento\Theme\Block\Html\Pager */
|
||||
protected $_htmlPagerBlock;
|
||||
|
||||
/** @var \Magento\Framework\App\RequestInterface */
|
||||
protected $_request;
|
||||
|
||||
/** @var \WeltPixel\LayeredNavigation\Helper\Data */
|
||||
protected $_wpHelper;
|
||||
/**
|
||||
* @var FilterModel
|
||||
*/
|
||||
protected $_filterModel;
|
||||
|
||||
/**
|
||||
* @var \Magento\Eav\Model\ResourceModel\Entity\Attribute
|
||||
*/
|
||||
protected $eavAttribute;
|
||||
|
||||
/**
|
||||
* Item constructor.
|
||||
* @param \Magento\Framework\UrlInterface $url
|
||||
* @param \Magento\Theme\Block\Html\Pager $htmlPagerBlock
|
||||
* @param \Magento\Framework\App\RequestInterface $request
|
||||
* @param LayerHelper $_wpHelper
|
||||
* @param FilterModel $filterModel
|
||||
* @param \Magento\Eav\Model\ResourceModel\Entity\Attribute $eavAttribute
|
||||
*/
|
||||
public function __construct(
|
||||
\Magento\Framework\UrlInterface $url,
|
||||
\Magento\Theme\Block\Html\Pager $htmlPagerBlock,
|
||||
\Magento\Framework\App\RequestInterface $request,
|
||||
LayerHelper $wpHelper,
|
||||
FilterModel $filterModel,
|
||||
\Magento\Eav\Model\ResourceModel\Entity\Attribute $eavAttribute
|
||||
) {
|
||||
$this->_url = $url;
|
||||
$this->_htmlPagerBlock = $htmlPagerBlock;
|
||||
$this->_request = $request;
|
||||
$this->_wpHelper = $wpHelper;
|
||||
$this->_filterModel = $filterModel;
|
||||
$this->eavAttribute = $eavAttribute;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Magento\Swatches\Block\LayeredNavigation\RenderLayered $renderLayered
|
||||
* @param $proceed
|
||||
* @param string $attributeCode
|
||||
* @param int $optionId
|
||||
* @return string
|
||||
*/
|
||||
public function aroundBuildUrl(
|
||||
\Magento\Swatches\Block\LayeredNavigation\RenderLayered $renderLayered,
|
||||
$proceed,
|
||||
$attributeCode,
|
||||
$optionId
|
||||
) {
|
||||
if (!$this->_wpHelper->isEnabled() || $this->_wpHelper->isAjaxEnabled()) {
|
||||
return $proceed($attributeCode, $optionId);
|
||||
}
|
||||
|
||||
$attributeId = $this->eavAttribute->getIdByCode('catalog_product', $attributeCode);
|
||||
$isMultiSelect = $this->_filterModel->isMultiselect($attributeId);
|
||||
|
||||
if (!$isMultiSelect) {
|
||||
return $proceed($attributeCode, $optionId);
|
||||
}
|
||||
|
||||
$filterValue = $this->_request->getParam($attributeCode);
|
||||
$requestVarValue = [];
|
||||
if (!empty($filterValue)) {
|
||||
$requestVarValue = explode(',', $filterValue);
|
||||
}
|
||||
|
||||
if (in_array($optionId, $requestVarValue)) {
|
||||
$requestVarValue = array_diff($requestVarValue, [$optionId]);
|
||||
} else {
|
||||
array_push($requestVarValue, $optionId);
|
||||
}
|
||||
|
||||
$requestVarValue = implode(",", $requestVarValue);
|
||||
|
||||
$query = [
|
||||
$attributeCode => $requestVarValue,
|
||||
$this->_htmlPagerBlock->getPageVarName() => null
|
||||
];
|
||||
|
||||
return $this->_url->getUrl('*/*/*', ['_current' => true, '_use_rewrite' => true, '_query' => $query]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* @category WeltPixel
|
||||
* @package WeltPixel_LayeredNavigation
|
||||
* @copyright Copyright (c) 2018 Weltpixel
|
||||
* @author Weltpixel TEAM
|
||||
*/
|
||||
namespace WeltPixel\LayeredNavigation\Plugin;
|
||||
|
||||
class Utility extends \WeltPixel\Backend\Plugin\Utility
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getModuleName()
|
||||
{
|
||||
return $this->convertToString(
|
||||
[
|
||||
'87', '101', '108', '116', '80', '105', '120', '101', '108', '95', '76', '97', '121', '101', '114',
|
||||
'101', '100', '78', '97', '118', '105', '103', '97', '116', '105', '111', '110', '95', '70', '114',
|
||||
'101', '101'
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function _getAdminPaths()
|
||||
{
|
||||
return [
|
||||
$this->convertToString(
|
||||
[
|
||||
'115', '121', '115', '116', '101', '109', '95', '99', '111', '110', '102', '105', '103', '47',
|
||||
'101', '100', '105', '116', '47', '115', '101', '99', '116', '105', '111', '110', '47', '119',
|
||||
'101', '108', '116', '112', '105', '120', '101', '108', '95', '108', '97', '121', '101', '114',
|
||||
'101', '100', '110', '97', '118', '105', '103', '97', '116', '105', '111', '110'
|
||||
]
|
||||
)
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
# m2-weltpixel-layered-navigation
|
||||
|
||||
### Installation
|
||||
|
||||
Dependencies:
|
||||
- m2-weltpixel-backend
|
||||
|
||||
With composer:
|
||||
|
||||
```sh
|
||||
$ composer config repositories.welpixel-m2-weltpixel-layered-navigation git git@github.com:Weltpixel/m2-weltpixel-layered-navigation.git
|
||||
$ composer require weltpixel/m2-weltpixel-layered-navigation:dev-master-free
|
||||
```
|
||||
Note: Composer installation only available for WeltPixel internal use for the moment as the repositos are not public. However, there is a work around that will allow you to install the product via composer, described in the article below: https://support.weltpixel.com/hc/en-us/articles/115000216654-How-to-use-composer-and-install-Pearl-Theme-or-other-WeltPixel-extensions
|
||||
|
||||
Manually:
|
||||
|
||||
Copy the zip into app/code/WeltPixel/LayeredNavigation directory
|
||||
|
||||
|
||||
#### After installation by either means, enable the extension by running following commands:
|
||||
|
||||
```sh
|
||||
$ php bin/magento module:enable WeltPixel_LayeredNavigation --clear-static-content
|
||||
$ php bin/magento setup:upgrade
|
||||
```
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
namespace WeltPixel\LayeredNavigation\Setup\Patch\Schema;
|
||||
|
||||
use Magento\Framework\Setup\SchemaSetupInterface;
|
||||
use Magento\Framework\Setup\Patch\SchemaPatchInterface;
|
||||
use Magento\Framework\Setup\Patch\PatchVersionInterface;
|
||||
|
||||
class AddAttributeOptionsTable implements SchemaPatchInterface, PatchVersionInterface
|
||||
{
|
||||
/**
|
||||
* @var SchemaSetupInterface $schemaSetup
|
||||
*/
|
||||
private $schemaSetup;
|
||||
|
||||
/**
|
||||
* @param SchemaSetupInterface $schemaSetup
|
||||
*/
|
||||
public function __construct(SchemaSetupInterface $schemaSetup)
|
||||
{
|
||||
$this->schemaSetup = $schemaSetup;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function apply()
|
||||
{
|
||||
$setup = $this->schemaSetup;
|
||||
$this->schemaSetup->startSetup();
|
||||
|
||||
/**
|
||||
* Create table 'weltpixel_ln_attribute_options'
|
||||
*/
|
||||
$table = $setup->getConnection()->newTable(
|
||||
$setup->getTable('weltpixel_ln_attribute_options')
|
||||
)->addColumn(
|
||||
'id',
|
||||
\Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
|
||||
null,
|
||||
['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true],
|
||||
'Id'
|
||||
)->addColumn(
|
||||
'attribute_id',
|
||||
\Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
|
||||
null,
|
||||
['unsigned' => true, 'nullable' => false, 'default' => '0'],
|
||||
'Attribute Id'
|
||||
)->addColumn(
|
||||
'display_option',
|
||||
\Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
|
||||
null,
|
||||
['unsigned' => true, 'nullable' => false, 'default' => '0'],
|
||||
'Filter Display Option'
|
||||
)->addColumn(
|
||||
'visible_options',
|
||||
\Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
|
||||
null,
|
||||
['unsigned' => true, 'nullable' => false, 'default' => '99'],
|
||||
'Initial number of options'
|
||||
)->addColumn(
|
||||
'visible_options_step',
|
||||
\Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
|
||||
null,
|
||||
['unsigned' => true, 'nullable' => false, 'default' => '99'],
|
||||
'Expandable items behaviour'
|
||||
)->addColumn(
|
||||
'is_multiselect',
|
||||
\Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
|
||||
null,
|
||||
['unsigned' => true, 'nullable' => false, 'default' => '0'],
|
||||
'Enable Multiselect'
|
||||
)->addColumn(
|
||||
'show_quantity',
|
||||
\Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
|
||||
null,
|
||||
['unsigned' => true, 'nullable' => false, 'default' => '0'],
|
||||
'Show Quantity'
|
||||
)->addColumn(
|
||||
'sort_by',
|
||||
\Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
|
||||
null,
|
||||
['unsigned' => true, 'nullable' => false, 'default' => '1'],
|
||||
'Sort By'
|
||||
)->addIndex(
|
||||
$setup->getIdxName($setup->getTable('weltpixel_ln_attribute_options'),['id']),
|
||||
['id']
|
||||
)->addForeignKey(
|
||||
$setup->getFkName('weltpixel_ln_attribute_options', 'attribute_id', 'eav_attribute', 'attribute_id'),
|
||||
'attribute_id',
|
||||
$setup->getTable('eav_attribute'),
|
||||
'attribute_id',
|
||||
\Magento\Framework\DB\Ddl\Table::ACTION_CASCADE
|
||||
)->setComment(
|
||||
'WeltPixel Layered Navigation Attribute Options'
|
||||
);
|
||||
|
||||
$setup->getConnection()->createTable($table);
|
||||
|
||||
$this->schemaSetup->endSetup();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getVersion()
|
||||
{
|
||||
return '1.0.0';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getAliases()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public static function getDependencies()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "weltpixel/m2-weltpixel-layered-navigation",
|
||||
"description": "WeltPixel LayeredNavigation Module",
|
||||
"require": {
|
||||
"weltpixel/m2-weltpixel-backend": "*"
|
||||
},
|
||||
"type": "magento2-module",
|
||||
"version": "1.11.19",
|
||||
"license": [
|
||||
"OSL-3.0",
|
||||
"AFL-3.0"
|
||||
],
|
||||
"autoload": {
|
||||
"files": [
|
||||
"registration.php"
|
||||
],
|
||||
"psr-4": {
|
||||
"WeltPixel\\LayeredNavigation\\": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* @category WeltPixel
|
||||
* @package WeltPixel_LayeredNavigation
|
||||
* @copyright Copyright (c) 2018 Weltpixel
|
||||
* @author Weltpixel TEAM
|
||||
*/
|
||||
-->
|
||||
<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="WeltPixel_Backend::WeltPixel">
|
||||
<resource id="WeltPixel_LayeredNavigation::LayeredNavigation_Label" sortOrder="90"
|
||||
title="LayeredNavigation">
|
||||
<resource id="WeltPixel_LayeredNavigation::LayeredNavigation_General" sortOrder="10"
|
||||
title="LayeredNavigation Settings"/>
|
||||
</resource>
|
||||
</resource>
|
||||
<resource id="Magento_Backend::stores">
|
||||
<resource id="Magento_Backend::stores_settings">
|
||||
<resource id="Magento_Config::config">
|
||||
<resource id="WeltPixel_LayeredNavigation::LayeredNavigation"
|
||||
title="WeltPixel LayeredNavigation" sortOrder="283"/>
|
||||
</resource>
|
||||
</resource>
|
||||
</resource>
|
||||
</resource>
|
||||
</resources>
|
||||
</acl>
|
||||
</config>
|
||||
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* @category WeltPixel
|
||||
* @package WeltPixel_LayeredNavigation
|
||||
* @copyright Copyright (c) 2018 Weltpixel
|
||||
* @author Weltpixel TEAM
|
||||
*/
|
||||
-->
|
||||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
|
||||
<type name="Magento\Backend\App\AbstractAction">
|
||||
<plugin name="weltpixel-layerenavigation-utility" type="WeltPixel\LayeredNavigation\Plugin\Utility" sortOrder="1000" />
|
||||
</type>
|
||||
</config>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* @category WeltPixel
|
||||
* @package WeltPixel_LayeredNavigation
|
||||
* @copyright Copyright (c) 2018 Weltpixel
|
||||
* @author Weltpixel TEAM
|
||||
*/
|
||||
-->
|
||||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
|
||||
<event name="product_attribute_form_build_weltpixel_layerednavigation_tab">
|
||||
<observer name="wp_layeredNavigation" instance="WeltPixel\LayeredNavigation\Observer\Edit\Tab\Front\WpProductAttributeFormBuildFrontTabObserver" />
|
||||
</event>
|
||||
<event name="catalog_entity_attribute_save_after">
|
||||
<observer name="wp_layeredNavigation_attribute_options" instance="WeltPixel\LayeredNavigation\Observer\WpCatalogAttributeSaveAfterObserver" />
|
||||
</event>
|
||||
</config>
|
||||
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* @category WeltPixel
|
||||
* @package WeltPixel_LayeredNavigation
|
||||
* @copyright Copyright (c) 2018 Weltpixel
|
||||
* @author Weltpixel TEAM
|
||||
*/
|
||||
-->
|
||||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Backend:etc/menu.xsd">
|
||||
<menu>
|
||||
<add
|
||||
id="WeltPixel_LayeredNavigation::LayeredNavigation_Label"
|
||||
title="Layered Navigation"
|
||||
module="WeltPixel_LayeredNavigation"
|
||||
sortOrder="390"
|
||||
parent="WeltPixel_Backend::WeltPixel"
|
||||
resource="WeltPixel_LayeredNavigation::LayeredNavigation_Label"
|
||||
/>
|
||||
<add
|
||||
id="WeltPixel_LayeredNavigation::LayeredNavigation_General"
|
||||
title="Layered Navigation Settings"
|
||||
module="WeltPixel_LayeredNavigation"
|
||||
action="adminhtml/system_config/edit/section/weltpixel_layerednavigation/"
|
||||
sortOrder="10"
|
||||
parent="WeltPixel_LayeredNavigation::LayeredNavigation_Label"
|
||||
resource="WeltPixel_LayeredNavigation::LayeredNavigation_General"
|
||||
/>
|
||||
</menu>
|
||||
</config>
|
||||
@@ -0,0 +1,226 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* @category WeltPixel
|
||||
* @package WeltPixel_LayeredNavigation
|
||||
* @copyright Copyright (c) 2018 Weltpixel
|
||||
* @author Weltpixel TEAM
|
||||
*/
|
||||
-->
|
||||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
|
||||
<system>
|
||||
<section id="weltpixel_layerednavigation" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="210"
|
||||
translate="label">
|
||||
<label>Layered Navigation</label>
|
||||
<tab>weltpixel</tab>
|
||||
<resource>WeltPixel_LayeredNavigation::LayeredNavigation</resource>
|
||||
|
||||
<group id="general" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="10" translate="label">
|
||||
<label>General Settings</label>
|
||||
<field id="enable" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="10" translate="label"
|
||||
type="select">
|
||||
<label>Enable Layered Navigation</label>
|
||||
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
|
||||
<comment>Enable/Disable WeltPixel Layered Navigation.</comment>
|
||||
</field>
|
||||
|
||||
<field id="ajax" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="30"
|
||||
translate="label" type="select">
|
||||
<label>Enable Ajax</label>
|
||||
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
|
||||
<comment>Enable/Disable Ajax Layered Navigation.</comment>
|
||||
<depends>
|
||||
<field id="enable">1</field>
|
||||
</depends>
|
||||
</field>
|
||||
<field id="ajax_scroll_top" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="32"
|
||||
translate="label" type="select">
|
||||
<label>Scroll to top after Ajax load</label>
|
||||
<frontend_model>WeltPixel\LayeredNavigation\Block\System\Config\Form\Field\Disable</frontend_model>
|
||||
<comment><![CDATA[Only available in PRO version of this extension. <br>
|
||||
<a style="font-size: 14px" target="_blank" href="https://www.weltpixel.com/magento2-layered-navigation.html">Upgrade to Pro version</a> to enable this functionality.
|
||||
]]>
|
||||
</comment>
|
||||
</field>
|
||||
</group>
|
||||
|
||||
<group id="sidebar" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="20" translate="label">
|
||||
<label>Sidebar Settings</label>
|
||||
<field id="style" translate="label" type="select" sortOrder="10" showInDefault="1"
|
||||
showInWebsite="1" showInStore="1">
|
||||
<label>Sidebar Style</label>
|
||||
<frontend_model>WeltPixel\LayeredNavigation\Block\System\Config\Form\Field\Disable</frontend_model>
|
||||
<comment><![CDATA[Default magento navigation enabled. <br/>
|
||||
<strong>“Slide-In Navigation & Slide-Down Navigation”</strong> only available in PRO version of this extension. <br>
|
||||
<a style="font-size: 14px" target="_blank" href="https://www.weltpixel.com/magento2-layered-navigation.html">Upgrade to Pro version</a> to enable this functionality.
|
||||
]]>
|
||||
</comment>
|
||||
|
||||
</field>
|
||||
|
||||
<field id="display_multiselect_selected_options" translate="label comment" type="select" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
|
||||
<label>Display Multiselect Attributes Selected Options Counter</label>
|
||||
<frontend_model>WeltPixel\LayeredNavigation\Block\System\Config\Form\Field\Disable</frontend_model>
|
||||
<comment><![CDATA[Only available in PRO version of this extension. <br>
|
||||
<a style="font-size: 14px" target="_blank" href="https://www.weltpixel.com/magento2-layered-navigation.html">Upgrade to Pro version</a> to enable this functionality.
|
||||
]]>
|
||||
</comment>
|
||||
</field>
|
||||
|
||||
<field id="compare_block" translate="label comment" type="select" sortOrder="20" showInDefault="1"
|
||||
showInWebsite="1" showInStore="1">
|
||||
<label>Show Compare Products block</label>
|
||||
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
|
||||
<comment>Show/Hide Compare Products block from sidebar.</comment>
|
||||
<depends>
|
||||
<field id="sb_style">0</field>
|
||||
</depends>
|
||||
</field>
|
||||
|
||||
<field id="wishlist_block" translate="label comment" type="select" sortOrder="30" showInDefault="1"
|
||||
showInWebsite="1" showInStore="1">
|
||||
<label>Show Wish List block</label>
|
||||
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
|
||||
<comment>Show/Hide Wish List block from sidebar.</comment>
|
||||
</field>
|
||||
|
||||
<field id="recentlyordered_block" translate="label comment" type="select" sortOrder="35" showInDefault="1"
|
||||
showInWebsite="1" showInStore="1">
|
||||
<label>Show Recently Ordered block</label>
|
||||
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
|
||||
<comment>Show/Hide Recently Ordered block from sidebar.</comment>
|
||||
</field>
|
||||
|
||||
<field id="category_block" translate="label comment" type="select" sortOrder="40" showInDefault="1"
|
||||
showInWebsite="1" showInStore="1">
|
||||
<label>Show Category Filter</label>
|
||||
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
|
||||
<comment>
|
||||
<![CDATA[Show/Hide Category Filter section from Layered Navigation sidebar.<br/>
|
||||
Applicable to Anchor categories. <br/>
|
||||
Also, if exists, make sure to set Stores > Configuration > Catalog > Catalog > Layered Navigation > Display Category Filter to Yes.
|
||||
]]>
|
||||
</comment>
|
||||
<depends>
|
||||
<field id="enable">1</field>
|
||||
</depends>
|
||||
</field>
|
||||
|
||||
<field id="filter_button" translate="label" type="select" sortOrder="50" showInDefault="1"
|
||||
showInWebsite="1" showInStore="1">
|
||||
<label>Filter Button</label>
|
||||
<source_model>WeltPixel\LayeredNavigation\Model\Config\Source\FilterButton</source_model>
|
||||
<comment>Select the preferred style for the Layered Navigation filter button.</comment>
|
||||
</field>
|
||||
|
||||
<field id="price_filter" translate="label" type="select" sortOrder="60" showInDefault="1"
|
||||
showInWebsite="1" showInStore="1">
|
||||
<label>Price Filter</label>
|
||||
<frontend_model>WeltPixel\LayeredNavigation\Block\System\Config\Form\Field\Disable</frontend_model>
|
||||
<comment><![CDATA[Default magento navigation enabled. <br/>
|
||||
<strong>“Price Filter”</strong> only available in PRO version of this extension. <br>
|
||||
<a style="font-size: 14px" target="_blank" href="https://www.weltpixel.com/magento2-layered-navigation.html">Upgrade to Pro version</a> to enable this functionality.
|
||||
]]>
|
||||
</comment>
|
||||
|
||||
</field>
|
||||
|
||||
<field id="price_filter_input" translate="label" type="select" sortOrder="70" showInDefault="1"
|
||||
showInWebsite="1" showInStore="1">
|
||||
<label>Show Price Filter With Input</label>
|
||||
<frontend_model>WeltPixel\LayeredNavigation\Block\System\Config\Form\Field\Disable</frontend_model>
|
||||
<comment><![CDATA[Default magento navigation enabled. <br/>
|
||||
<strong>“Show Price Filter With Input”</strong> only available in PRO version of this extension. <br>
|
||||
<a style="font-size: 14px" target="_blank" href="https://www.weltpixel.com/magento2-layered-navigation.html">Upgrade to Pro version</a> to enable this functionality.
|
||||
]]>
|
||||
</comment>
|
||||
|
||||
</field>
|
||||
|
||||
<field id="auto_close" translate="label" type="select" sortOrder="80" showInDefault="1"
|
||||
showInWebsite="1" showInStore="1">
|
||||
<label>Auto Close Sidebar</label>
|
||||
<frontend_model>WeltPixel\LayeredNavigation\Block\System\Config\Form\Field\Disable</frontend_model>
|
||||
<comment><![CDATA[Default magento navigation enabled. <br/>
|
||||
<strong>“Auto Close Sidebar”</strong> only available in PRO version of this extension. <br>
|
||||
<a style="font-size: 14px" target="_blank" href="https://www.weltpixel.com/magento2-layered-navigation.html">Upgrade to Pro version</a> to enable this functionality.
|
||||
]]>
|
||||
</comment>
|
||||
|
||||
</field>
|
||||
|
||||
<field id="rating_filter" translate="label" type="select" sortOrder="90" showInDefault="1"
|
||||
showInWebsite="1" showInStore="1">
|
||||
<label>Enable Rating Filter</label>
|
||||
<frontend_model>WeltPixel\LayeredNavigation\Block\System\Config\Form\Field\Disable</frontend_model>
|
||||
<comment><![CDATA[Default magento navigation enabled. <br/>
|
||||
<strong>“Rating Filter”</strong> only available in PRO version of this extension. <br>
|
||||
<a style="font-size: 14px" target="_blank" href="https://www.weltpixel.com/magento2-layered-navigation.html">Upgrade to Pro version</a> to enable this functionality.
|
||||
]]>
|
||||
</comment>
|
||||
|
||||
</field>
|
||||
|
||||
<field id="rating_filter_option" translate="label" type="select" sortOrder="100" showInDefault="1"
|
||||
showInWebsite="1" showInStore="1">
|
||||
<label>Rating Filter Display Options</label>
|
||||
<frontend_model>WeltPixel\LayeredNavigation\Block\System\Config\Form\Field\Disable</frontend_model>
|
||||
<comment><![CDATA[Default magento navigation enabled. <br/>
|
||||
<strong>“Rating Filter Display Options”</strong> only available in PRO version of this extension. <br>
|
||||
<a style="font-size: 14px" target="_blank" href="https://www.weltpixel.com/magento2-layered-navigation.html">Upgrade to Pro version</a> to enable this functionality.
|
||||
]]>
|
||||
</comment>
|
||||
|
||||
</field>
|
||||
|
||||
<field id="rating_filter_position" translate="label" type="select" sortOrder="110" showInDefault="1"
|
||||
showInWebsite="1" showInStore="1">
|
||||
<label>Rating Filter Position</label>
|
||||
<frontend_model>WeltPixel\LayeredNavigation\Block\System\Config\Form\Field\Disable</frontend_model>
|
||||
<comment><![CDATA[Default magento navigation enabled. <br/>
|
||||
<strong>“Rating Filter Position”</strong> only available in PRO version of this extension. <br>
|
||||
<a style="font-size: 14px" target="_blank" href="https://www.weltpixel.com/magento2-layered-navigation.html">Upgrade to Pro version</a> to enable this functionality.
|
||||
]]>
|
||||
</comment>
|
||||
|
||||
</field>
|
||||
|
||||
<field id="rating_filter_ms" translate="label" type="select" sortOrder="120" showInDefault="1"
|
||||
showInWebsite="1" showInStore="1">
|
||||
<label>Rating Filter Multiselect</label>
|
||||
<frontend_model>WeltPixel\LayeredNavigation\Block\System\Config\Form\Field\Disable</frontend_model>
|
||||
<comment><![CDATA[Default magento navigation enabled. <br/>
|
||||
<strong>“Rating Filter Multiselect”</strong> only available in PRO version of this extension. <br>
|
||||
<a style="font-size: 14px" target="_blank" href="https://www.weltpixel.com/magento2-layered-navigation.html">Upgrade to Pro version</a> to enable this functionality.
|
||||
]]>
|
||||
</comment>
|
||||
|
||||
</field>
|
||||
|
||||
<field id="rating_filter_counter" translate="label" type="select" sortOrder="130" showInDefault="1"
|
||||
showInWebsite="1" showInStore="1">
|
||||
<label>Show Rating Filter Counter</label>
|
||||
<frontend_model>WeltPixel\LayeredNavigation\Block\System\Config\Form\Field\Disable</frontend_model>
|
||||
<comment><![CDATA[Default magento navigation enabled. <br/>
|
||||
<strong>“Show Rating Filter Counter”</strong> only available in PRO version of this extension. <br>
|
||||
<a style="font-size: 14px" target="_blank" href="https://www.weltpixel.com/magento2-layered-navigation.html">Upgrade to Pro version</a> to enable this functionality.
|
||||
]]>
|
||||
</comment>
|
||||
|
||||
</field>
|
||||
|
||||
<comment>
|
||||
<![CDATA[<p>For more settings on attribute level, go to
|
||||
<strong>Stores -> Attributes -> Product -> [select desired attribute from grid] ->
|
||||
Storefront Properties -> WeltPixel Layered Navigation Properties</strong>
|
||||
section.
|
||||
</p>
|
||||
]]>
|
||||
</comment>
|
||||
|
||||
</group>
|
||||
|
||||
</section>
|
||||
</system>
|
||||
</config>
|
||||
@@ -0,0 +1,34 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* @category WeltPixel
|
||||
* @package WeltPixel_LayeredNavigation
|
||||
* @copyright Copyright (c) 2018 Weltpixel
|
||||
* @author Weltpixel TEAM
|
||||
*/
|
||||
-->
|
||||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
|
||||
<default>
|
||||
<weltpixel_layerednavigation>
|
||||
<general>
|
||||
<enable>1</enable>
|
||||
<ajax>1</ajax>
|
||||
</general>
|
||||
<sidebar>
|
||||
<sb_style>0</sb_style>
|
||||
<category_block>1</category_block>
|
||||
<compare_block>1</compare_block>
|
||||
<wishlist_block>1</wishlist_block>
|
||||
<filter_button>1</filter_button>
|
||||
<recentlyordered_block>1</recentlyordered_block>
|
||||
</sidebar>
|
||||
<attribute_display>
|
||||
<filter>0</filter>
|
||||
<multiselect>1</multiselect>
|
||||
<qty>1</qty>
|
||||
<sort>position</sort>
|
||||
</attribute_display>
|
||||
</weltpixel_layerednavigation>
|
||||
</default>
|
||||
</config>
|
||||
@@ -0,0 +1,57 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* @category WeltPixel
|
||||
* @package WeltPixel_LayeredNavigation
|
||||
* @copyright Copyright (c) 2018 Weltpixel
|
||||
* @author Weltpixel TEAM
|
||||
*/
|
||||
-->
|
||||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
|
||||
<virtualType name="categoryFilterList" type="Magento\Catalog\Model\Layer\FilterList">
|
||||
<arguments>
|
||||
<argument name="filters" xsi:type="array">
|
||||
<item name="attribute" xsi:type="string">WeltPixel\LayeredNavigation\Model\Layer\Filter\Attribute</item>
|
||||
<item name="price" xsi:type="string">WeltPixel\LayeredNavigation\Model\Layer\Filter\Price</item>
|
||||
<item name="category" xsi:type="string">WeltPixel\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">WeltPixel\LayeredNavigation\Model\Layer\Filter\Attribute</item>
|
||||
<item name="price" xsi:type="string">WeltPixel\LayeredNavigation\Model\Layer\Filter\Price</item>
|
||||
<item name="category" xsi:type="string">WeltPixel\LayeredNavigation\Model\Layer\Filter\Category</item>
|
||||
</argument>
|
||||
</arguments>
|
||||
</virtualType>
|
||||
<preference for="Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection"
|
||||
type="WeltPixel\LayeredNavigation\Model\ResourceModel\Fulltext\Collection" />
|
||||
<virtualType name="Magento\CatalogSearch\Model\ResourceModel\Fulltext\CollectionFactory"
|
||||
type="Magento\Catalog\Model\ResourceModel\Product\CollectionFactory">
|
||||
<arguments>
|
||||
<argument name="instanceName" xsi:type="string">WeltPixel\LayeredNavigation\Model\ResourceModel\Fulltext\Collection</argument>
|
||||
</arguments>
|
||||
</virtualType>
|
||||
<virtualType name="Magento\CatalogSearch\Model\ResourceModel\Fulltext\SearchCollection"
|
||||
type="WeltPixel\LayeredNavigation\Model\ResourceModel\Fulltext\Collection">
|
||||
<arguments>
|
||||
<argument name="searchRequestName" xsi:type="string">quick_search_container</argument>
|
||||
</arguments>
|
||||
</virtualType>
|
||||
|
||||
<!-- Since M-2.3.2 -->
|
||||
<type name="Magento\Catalog\Model\Layer\Search">
|
||||
<arguments>
|
||||
<argument name="context" xsi:type="object">Magento\CatalogSearch\Model\Layer\Search\Context</argument>
|
||||
</arguments>
|
||||
</type>
|
||||
<type name="Magento\Catalog\Model\Layer\Category">
|
||||
<arguments>
|
||||
<argument name="context" xsi:type="object">Magento\CatalogSearch\Model\Layer\Category\Context</argument>
|
||||
</arguments>
|
||||
</type>
|
||||
<!-- End since -->
|
||||
</config>
|
||||
@@ -0,0 +1,87 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* @category WeltPixel
|
||||
* @package WeltPixel_LayeredNavigation
|
||||
* @copyright Copyright (c) 2018 Weltpixel
|
||||
* @author Weltpixel TEAM
|
||||
*/
|
||||
-->
|
||||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
|
||||
|
||||
<virtualType name="WeltPixel\LayeredNavigation\Block\Navigation\Category"
|
||||
type="WeltPixel\LayeredNavigation\Block\Navigation">
|
||||
<arguments>
|
||||
<argument name="filterList" xsi:type="object">categoryFilterList</argument>
|
||||
</arguments>
|
||||
</virtualType>
|
||||
|
||||
<virtualType name="WeltPixel\LayeredNavigation\Block\Navigation\Search"
|
||||
type="WeltPixel\LayeredNavigation\Block\Navigation">
|
||||
<arguments>
|
||||
<argument name="filterList" xsi:type="object">searchFilterList</argument>
|
||||
</arguments>
|
||||
</virtualType>
|
||||
|
||||
<!-- @api -->
|
||||
<virtualType name="Magento\LayeredNavigationStaging\Block\Navigation\Category"
|
||||
type="WeltPixel\LayeredNavigation\Block\Navigation">
|
||||
<arguments>
|
||||
<argument name="filterList" xsi:type="object">categoryFilterList</argument>
|
||||
</arguments>
|
||||
</virtualType>
|
||||
<!-- @api -->
|
||||
<virtualType name="Magento\LayeredNavigationStaging\Block\Navigation\Search"
|
||||
type="WeltPixel\LayeredNavigation\Block\Navigation">
|
||||
<arguments>
|
||||
<argument name="filterList" xsi:type="object">searchFilterList</argument>
|
||||
</arguments>
|
||||
</virtualType>
|
||||
|
||||
<preference for="Magento\LayeredNavigation\Block\Navigation\Category"
|
||||
type="WeltPixel\LayeredNavigation\Block\Navigation\Category"/>
|
||||
|
||||
<preference for="Magento\LayeredNavigation\Block\Navigation\FilterRenderer"
|
||||
type="WeltPixel\LayeredNavigation\Block\Navigation\FilterRenderer"/>
|
||||
|
||||
<preference for="Magento\LayeredNavigation\Block\Navigation\State"
|
||||
type="WeltPixel\LayeredNavigation\Block\Navigation\State"/>
|
||||
|
||||
<preference for="Magento\Swatches\Block\LayeredNavigation\RenderLayered"
|
||||
type="WeltPixel\LayeredNavigation\Block\LayeredNavigation\RenderLayered"/>
|
||||
|
||||
<preference for="Magento\Catalog\Model\ResourceModel\Layer\Filter\Attribute"
|
||||
type="WeltPixel\LayeredNavigation\Model\ResourceModel\Layer\Filter\Attribute"/>
|
||||
|
||||
<type name="Amasty\ShopbyBrand\Controller\Index\Index">
|
||||
<plugin name="WeltPixel_LayeredNavigation_Ajax_Amasty_ShopBy"
|
||||
type="WeltPixel\LayeredNavigation\Plugin\Category\View"></plugin>
|
||||
</type>
|
||||
|
||||
<type name="Magento\Catalog\Controller\Category\View">
|
||||
<plugin name="WeltPixel_LayeredNavigation_Ajax_Category_View"
|
||||
type="WeltPixel\LayeredNavigation\Plugin\Category\View"></plugin>
|
||||
</type>
|
||||
|
||||
<type name="Magento\CatalogSearch\Controller\Result\Index">
|
||||
<plugin name="WeltPixel_LayeredNavigation_Ajax_CategorSearch_Result"
|
||||
type="WeltPixel\LayeredNavigation\Plugin\CatalogSearch\ResultView"></plugin>
|
||||
</type>
|
||||
|
||||
<type name="Magento\Catalog\Model\Layer\FilterList">
|
||||
<plugin name="WeltPixel_LayeredNavigation_Filter_List"
|
||||
type="WeltPixel\LayeredNavigation\Plugin\Layer\FilterList"></plugin>
|
||||
</type>
|
||||
|
||||
<type name="Magento\Catalog\Model\Layer\Filter\Item">
|
||||
<plugin name="WeltPixel_LayeredNavigation_Item_Url"
|
||||
type="WeltPixel\LayeredNavigation\Plugin\Model\Layer\Filter\Item" sortOrder="1"/>
|
||||
</type>
|
||||
|
||||
<type name="Magento\Swatches\Block\LayeredNavigation\RenderLayered">
|
||||
<plugin name="WeltPixel_LayeredNavigation_Swatches_RenderLayered"
|
||||
type="WeltPixel\LayeredNavigation\Plugin\Swatches\RenderLayered" sortOrder="1"/>
|
||||
</type>
|
||||
|
||||
</config>
|
||||
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* @category WeltPixel
|
||||
* @package WeltPixel_LayeredNavigation
|
||||
* @copyright Copyright (c) 2018 Weltpixel
|
||||
* @author Weltpixel TEAM
|
||||
*/
|
||||
-->
|
||||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
|
||||
<event name="layout_generate_blocks_after">
|
||||
<observer name="remove_block" instance="WeltPixel\LayeredNavigation\Observer\RemoveBlocks"/>
|
||||
</event>
|
||||
</config>
|
||||
@@ -0,0 +1 @@
|
||||
aULixHiC2+4o5CHvwRTwSYVM4snpseXqr2zV3R7dSfxMxsDjERk9Fyxy/F2V/+61M94keXaQjkLwZGQHImK8RQ07SE9iLufSpsFwuvLL8GFPzFrTMhinO0oR6n9CN7lkWFw8925JzpTsg+NvnTjVuKeJr/kPA/V06Vp+TtWSu2/P7pYclhS22wn4eBBYambiACOEHb+gN2WQJH+X5VWvcQ==
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* @category WeltPixel
|
||||
* @package WeltPixel_LayeredNavigation
|
||||
* @copyright Copyright (c) 2018 Weltpixel
|
||||
* @author Weltpixel TEAM
|
||||
*/
|
||||
-->
|
||||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
|
||||
<module name="WeltPixel_LayeredNavigation">
|
||||
<sequence>
|
||||
<module name="WeltPixel_Backend"/>
|
||||
</sequence>
|
||||
</module>
|
||||
</config>
|
||||
@@ -0,0 +1,69 @@
|
||||
"%1 and above","%1 and above"
|
||||
"%1 - %2","%1 - %2"
|
||||
"Something went wrong, check and test your Search Engine configurations, reindex catalog and clear cache. Thrown error: %1","Something went wrong, check and test your Search Engine configurations, reindex catalog and clear cache. Thrown error: %1"
|
||||
"Bucket does not exist","Bucket does not exist"
|
||||
"WeltPixel Layered Navigation Properties","WeltPixel Layered Navigation Properties"
|
||||
"Filter Display Options","Filter Display Options"
|
||||
"Can be used only with catalog input type Dropdown, Multiple Select and Price","Can be used only with catalog input type Dropdown, Multiple Select and Price"
|
||||
"Can be used only with catalog input type Dropdown, Multiple Select and Price. %1","Can be used only with catalog input type Dropdown, Multiple Select and Price. %1"
|
||||
Closed,Closed
|
||||
"Fully Opened","Fully Opened"
|
||||
Expandable,Expandable
|
||||
"Initial Number of Visible Options","Initial Number of Visible Options"
|
||||
"The number of attribute option(s) that will be initially visible. Can be used only with Filter Display Options - Expandable.","The number of attribute option(s) that will be initially visible. Can be used only with Filter Display Options - Expandable."
|
||||
"The number of attribute option(s) that will be initially visible. Can be used only with Filter Display Options - Expandable. %1","The number of attribute option(s) that will be initially visible. Can be used only with Filter Display Options - Expandable. %1"
|
||||
"Expandable items behaviour","Expandable items behaviour"
|
||||
All,All
|
||||
"Show 5 more","Show 5 more"
|
||||
"Show 10 more","Show 10 more"
|
||||
"Show 15 more","Show 15 more"
|
||||
"Select the number of attribute option(s) to show/hide when using Expand feature. Can be used only with Filter Display Options - Expandable.","Select the number of attribute option(s) to show/hide when using Expand feature. Can be used only with Filter Display Options - Expandable."
|
||||
"Select the number of attribute option(s) to show/hide when using Expand feature. Can be used only with Filter Display Options - Expandable. %1","Select the number of attribute option(s) to show/hide when using Expand feature. Can be used only with Filter Display Options - Expandable. %1"
|
||||
"Enable Multiselect","Enable Multiselect"
|
||||
No,No
|
||||
Yes,Yes
|
||||
"Allow to filter multiple options from the same attribute.","Allow to filter multiple options from the same attribute."
|
||||
"Show Item Counter","Show Item Counter"
|
||||
"Show item counter next to the current attribute options.","Show item counter next to the current attribute options."
|
||||
"Show item counter next to the current attribute options. %1","Show item counter next to the current attribute options. %1"
|
||||
"Sort By","Sort By"
|
||||
Position,Position
|
||||
Name,Name
|
||||
"Select the sorting of the current attribute options.","Select the sorting of the current attribute options."
|
||||
"Select the sorting of the current attribute options. %1","Select the sorting of the current attribute options. %1"
|
||||
item,item
|
||||
items,items
|
||||
"Now Shopping by","Now Shopping by"
|
||||
Previous,Previous
|
||||
Remove,Remove
|
||||
"Remove This Item","Remove This Item"
|
||||
"Shop By","Shop By"
|
||||
"Clear All","Clear All"
|
||||
"Shopping Options","Shopping Options"
|
||||
"Layered Navigation","Layered Navigation"
|
||||
"General Settings","General Settings"
|
||||
"Enable Layered Navigation","Enable Layered Navigation"
|
||||
"Enable Ajax","Enable Ajax"
|
||||
"Sidebar Settings","Sidebar Settings"
|
||||
"Sidebar Style","Sidebar Style"
|
||||
"Show Compare Products block","Show Compare Products block"
|
||||
"Show/Hide Compare Products block from sidebar.","Show/Hide Compare Products block from sidebar."
|
||||
"Show Wish List block","Show Wish List block"
|
||||
"Show/Hide Wish List block from sidebar.","Show/Hide Wish List block from sidebar."
|
||||
"Show Recently Ordered block","Show Recently Ordered block"
|
||||
"Show/Hide Recently Ordered block from sidebar.","Show/Hide Recently Ordered block from sidebar."
|
||||
"Show Category Filter","Show Category Filter"
|
||||
"Show/Hide Category Filter section from Layered Navigation sidebar.<br/>
|
||||
Applicable to Anchor categories. <br/>
|
||||
Also, if exists, make sure to set Stores > Configuration > Catalog > Catalog > Layered Navigation > Display Category Filter to Yes.","Show/Hide Category Filter section from Layered Navigation sidebar.<br/>
|
||||
Applicable to Anchor categories. <br/>
|
||||
Also, if exists, make sure to set Stores > Configuration > Catalog > Catalog > Layered Navigation > Display Category Filter to Yes."
|
||||
"Filter Button","Filter Button"
|
||||
"Price Filter","Price Filter"
|
||||
"Show Price Filter With Input","Show Price Filter With Input"
|
||||
"Auto Close Sidebar","Auto Close Sidebar"
|
||||
"Enable Rating Filter","Enable Rating Filter"
|
||||
"Rating Filter Display Options","Rating Filter Display Options"
|
||||
"Rating Filter Position","Rating Filter Position"
|
||||
"Rating Filter Multiselect","Rating Filter Multiselect"
|
||||
"Show Rating Filter Counter","Show Rating Filter Counter"
|
||||
|
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
\Magento\Framework\Component\ComponentRegistrar::register(
|
||||
\Magento\Framework\Component\ComponentRegistrar::MODULE,
|
||||
'WeltPixel_LayeredNavigation',
|
||||
__DIR__
|
||||
);
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
<?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">
|
||||
<body>
|
||||
<referenceBlock name="attribute_edit_tabs">
|
||||
<action method="addTabAfter">
|
||||
<argument name="name" xsi:type="string">weltpixellayerednavigation</argument>
|
||||
<argument name="block" xsi:type="string">WeltPixel\LayeredNavigation\Block\Adminhtml\Product\Attribute\Edit\Tab\Options</argument>
|
||||
<argument name="after" xsi:type="string">front</argument>
|
||||
</action>
|
||||
</referenceBlock>
|
||||
</body>
|
||||
</page>
|
||||
@@ -0,0 +1,13 @@
|
||||
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
|
||||
<body>
|
||||
<referenceContainer name="before.body.end">
|
||||
<block
|
||||
ifconfig="weltpixel_layerednavigation/general/enable"
|
||||
class="WeltPixel\LayeredNavigation\Block\LayeredNavigationAdd"
|
||||
name="layerednavigationadd"
|
||||
template="WeltPixel_LayeredNavigation::layerednavigationadd.phtml"
|
||||
/>
|
||||
</referenceContainer>
|
||||
</body>
|
||||
</page>
|
||||
Executable
+40
@@ -0,0 +1,40 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* @category WeltPixel
|
||||
* @package WeltPixel_LayeredNavigation
|
||||
* @copyright Copyright (c) 2018 Weltpixel
|
||||
* @author Weltpixel TEAM
|
||||
*/
|
||||
-->
|
||||
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
|
||||
<body>
|
||||
<attribute name="class" value="wp-ln-filter-page"/>
|
||||
<referenceBlock name="catalog.leftnav">
|
||||
<action method="setTemplate" ifconfig="weltpixel_layerednavigation/general/enable">
|
||||
<argument name="template" xsi:type="string">WeltPixel_LayeredNavigation::layer/view.phtml</argument>
|
||||
</action>
|
||||
<container name="layer.additional.info" as="layer_additional_info"/>
|
||||
<container name="layer.content.before" as="layer_content_before"/>
|
||||
</referenceBlock>
|
||||
<referenceBlock name="catalog.navigation.renderer">
|
||||
<action method="setTemplate" ifconfig="weltpixel_layerednavigation/general/enable">
|
||||
<argument name="template" xsi:type="string">WeltPixel_LayeredNavigation::layer/filter.phtml</argument>
|
||||
</action>
|
||||
</referenceBlock>
|
||||
|
||||
<referenceContainer name="content">
|
||||
<block class="Magento\Framework\View\Element\Template" name="layer.category.products" template="WeltPixel_LayeredNavigation::products.phtml" />
|
||||
</referenceContainer>
|
||||
|
||||
<move element="category.products" destination="layer.category.products"/>
|
||||
<referenceContainer name="before.body.end">
|
||||
<block
|
||||
ifconfig="weltpixel_layerednavigation/general/enable"
|
||||
class="WeltPixel\LayeredNavigation\Block\LayeredNavigationAdd"
|
||||
name="layerednavigationadd"
|
||||
template="WeltPixel_LayeredNavigation::layerednavigationadd.phtml"
|
||||
/>
|
||||
</referenceContainer>
|
||||
</body>
|
||||
</page>
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* @category WeltPixel
|
||||
* @package WeltPixel_LayeredNavigation
|
||||
* @copyright Copyright (c) 2018 Weltpixel
|
||||
* @author Weltpixel TEAM
|
||||
*/
|
||||
-->
|
||||
<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>
|
||||
<attribute name="class" value="page-products"/>
|
||||
|
||||
<referenceContainer name="sidebar.main">
|
||||
<block class="WeltPixel\LayeredNavigation\Block\Navigation\Search" name="catalogsearch.leftnav" before="-" template="WeltPixel_LayeredNavigation::layer/view.phtml">
|
||||
<block class="WeltPixel\LayeredNavigation\Block\Navigation\State" name="catalogsearch.navigation.state" as="state" />
|
||||
<block class="WeltPixel\LayeredNavigation\Block\Navigation\FilterRenderer" name="catalogsearch.navigation.renderer" as="renderer" template="WeltPixel_LayeredNavigation::layer/filter.phtml"/>
|
||||
</block>
|
||||
</referenceContainer>
|
||||
|
||||
<referenceContainer name="content">
|
||||
<block class="Magento\Framework\View\Element\Template" name="wp.layer.search.result" template="WeltPixel_LayeredNavigation::search_products.phtml" />
|
||||
</referenceContainer>
|
||||
<move element="search.result" destination="wp.layer.search.result"/>
|
||||
|
||||
<referenceContainer name="before.body.end">
|
||||
<block
|
||||
ifconfig="weltpixel_layerednavigation/general/enable"
|
||||
class="WeltPixel\LayeredNavigation\Block\LayeredNavigationAdd"
|
||||
name="layerednavigationadd"
|
||||
template="WeltPixel_LayeredNavigation::layerednavigationadd.phtml"
|
||||
/>
|
||||
</referenceContainer>
|
||||
|
||||
</body>
|
||||
</page>
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
var config = {
|
||||
map: {
|
||||
'*': {
|
||||
wpFilterSelect: 'WeltPixel_LayeredNavigation/js/wpFilterSelect'
|
||||
}
|
||||
}
|
||||
};
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
// @codingStandardsIgnoreFile
|
||||
|
||||
/* @var $block WeltPixel\LayeredNavigation\Block\Navigation\FilterRenderer */
|
||||
$attributeCode = $this->getAttribute()->getAttributeCode();
|
||||
|
||||
$url = '';
|
||||
?>
|
||||
|
||||
<?php $attributeId = $block->getAttributeId()?>
|
||||
<?php $isMulti = $block->getIsMultiselect()?>
|
||||
<?php $canShowQty = (is_null($block->getShowQty())) ? $this->helper('\Magento\Catalog\Helper\Data')->shouldDisplayProductCountOnLayer() : $block->getShowQty();?>
|
||||
<ol class="items" id="<?= $attributeId ?>_items" >
|
||||
<?php foreach ($filterItems as $index => $filterItem): ?>
|
||||
<?php /* @var $filterItem \Magento\Catalog\Model\Layer\Filter\Item */ ?>
|
||||
|
||||
<?php $filterUrl = $filterItem->getUrl(); ?>
|
||||
<?php $requestVar = $filterItem->getFilter()->getRequestVar();?>
|
||||
<?php $filterItemVal = is_array($filterItem->getValue()) ? implode('-', $filterItem->getValue()) : $filterItem->getValue()?>
|
||||
|
||||
<?php if (!$url && $filterItem->getCount() && $attributeCode=='category_option') { $url=$filterUrl; } ?>
|
||||
<?php $dataOptPath = ($requestVar != 'cat') ? $filterItem->getFilter()->getAttributeModel()->getAttributeCode() . '='. $filterItemVal : 'cat='.$filterItemVal;?>
|
||||
<li class="item" style="display: none" id="wp_ln_attr_<?= $attributeId ?>_<?= /* @escapeNotVerified */ is_array($filterItem->getValue()) ? implode('-', $filterItem->getValue()) : $filterItem->getValue() ?>">
|
||||
<a href="<?= $block->escapeUrl($filterUrl) ?>"
|
||||
data-opt-path="<?= /* @escapeNotVerified */ $block->escapeHtmlAttr($dataOptPath) ?>"
|
||||
data-is-multi="<?= $isMulti?>">
|
||||
<?= /* @escapeNotVerified */ $filterItem->getLabel() ?>
|
||||
<?php if ($canShowQty): ?>
|
||||
<span class="count"><?= /* @escapeNotVerified */ $filterItem->getCount() ?></span>
|
||||
<?php endif; ?>
|
||||
</a>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
<div class="wp-ln-actions">
|
||||
<b id="loadMore_<?=$attributeId?>" class="wp-ln-action wp-ln-load-more icon-line-arrow-down">Show More</b>
|
||||
<b id="showLess_<?=$attributeId?>" class="wp-ln-action wp-ln-show-less icon-line-arrow-up">Show Less</b>
|
||||
</div>
|
||||
</ol>
|
||||
<?php
|
||||
if ($url && $attributeCode=='category_option' && !$this->getRequest()->getParam('category_option')) {
|
||||
$block->setRedirectUrl($url);
|
||||
}
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
require(['jquery'], function($){
|
||||
$(document).ready(function(){
|
||||
var visibleItems = "<?= $block->getVisibleItems()?>",
|
||||
visibleItemsStep = "<?= $block->getVisibleItemsStep()?>",
|
||||
attrId = "<?= $attributeId?>",
|
||||
elId = attrId + '_items',
|
||||
ulSize = $('#' + elId + ' li').length,
|
||||
loadMoreId = '#loadMore_' + attrId,
|
||||
showLessId = '#showLess_' + attrId,
|
||||
x = parseInt(visibleItems),
|
||||
initialX = x,
|
||||
xStep = parseInt(visibleItemsStep);
|
||||
if(visibleItems > 0 && visibleItems.length > 0 && visibleItems < 99 && ulSize > visibleItems) {
|
||||
$(loadMoreId).show();
|
||||
$("#"+ elId + " li:lt(" + visibleItems + ")").show();
|
||||
$(showLessId).hide();
|
||||
} else {
|
||||
$("#"+ elId + " li").show();
|
||||
$(loadMoreId).hide();
|
||||
$(showLessId).hide();
|
||||
}
|
||||
|
||||
$(loadMoreId).click(function () {
|
||||
if(xStep == 99) {
|
||||
$('#' + elId + ' li:lt(' + ulSize + ')').show();
|
||||
$(this).hide();
|
||||
$(showLessId).show();
|
||||
} else {
|
||||
x = ( x + xStep <= ulSize) ? x + xStep : ulSize;
|
||||
$('#' + elId + ' li:lt(' + x + ')').show();
|
||||
if(ulSize == x){
|
||||
$(this).hide();
|
||||
$(showLessId).show();
|
||||
}else{
|
||||
$(showLessId).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$(showLessId).click(function () {
|
||||
if(xStep == 99) {
|
||||
$('#' + elId + ' li').not(':lt(' + xStep + ')').hide();
|
||||
$(this).hide();
|
||||
$(loadMoreId).show();
|
||||
} else {
|
||||
x = ( x - xStep < 0 || x == ulSize) ? initialX : x - xStep;
|
||||
$('#' + elId + ' li').not(':lt(' + x + ')').hide();
|
||||
if(x <= visibleItems){
|
||||
$(this).hide();
|
||||
$(loadMoreId).show();
|
||||
}else{
|
||||
$(loadMoreId).show();
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
})
|
||||
|
||||
});
|
||||
|
||||
</script>
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
// @codingStandardsIgnoreFile
|
||||
?>
|
||||
<?php
|
||||
/**
|
||||
* Category layered navigation state
|
||||
*
|
||||
* @var $block \WeltPixel\LayeredNavigation\Block\Navigation\State
|
||||
*/
|
||||
?>
|
||||
<?php $_filters = $block->getActiveFilters() ?>
|
||||
<?php if (!empty($_filters)): ?>
|
||||
<div class="filter-current" id="wp_ln_shopby">
|
||||
|
||||
<ol class="items" id="wp_ln_shopby_items" data-role="content">
|
||||
<?php foreach ($_filters as $_filter): ?>
|
||||
<?php
|
||||
$requestVar = $_filter->getFilter()->getRequestVar();
|
||||
$filterItemVal = (is_array($_filter->getValue())) ? implode('-', $_filter->getValue()) : $_filter->getValue();
|
||||
$dataAttrId = ($requestVar != 'cat') ? $_filter->getFilter()->getAttributeModel()->getAttributeId() . '_' . $filterItemVal : '0_'.$filterItemVal;
|
||||
?>
|
||||
<li class="item" data-attr-id="<?= /* @escapeNotVerified */ $block->escapeHtml($dataAttrId) ?>">
|
||||
<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') ?>">
|
||||
<span><?= /* @escapeNotVerified */ __('Previous') ?></span>
|
||||
</a>
|
||||
<a class="action remove"
|
||||
title="<?= $block->escapeHtml($_filter->getFilter()->getClearLinkText()) ?>"
|
||||
href="<?= /* @escapeNotVerified */ $clearLinkUrl ?>">
|
||||
<span><?= $block->escapeHtml($_filter->getFilter()->getClearLinkText()) ?></span>
|
||||
</a>
|
||||
<?php else: ?>
|
||||
<a class="action remove" href="<?= /* @escapeNotVerified */ $_filter->getRemoveUrl() ?>"
|
||||
title="<?= /* @escapeNotVerified */ $block->escapeHtml(__('Remove')) . " " . $currentFilterName ?>">
|
||||
<span><?= /* @escapeNotVerified */ __('Remove This Item') ?></span>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ol>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
+105
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
// @codingStandardsIgnoreFile
|
||||
?>
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Category layered navigation
|
||||
*
|
||||
* @var $block WeltPixel\LayeredNavigation\Block\Navigation
|
||||
*/
|
||||
|
||||
$isAjaxMode = $block->isAjaxMode();
|
||||
$jsClass = ($isAjaxMode) ? 'WeltPixel_LayeredNavigation/js/product/list/toolbar' : false;
|
||||
?>
|
||||
<?php if ($block->canShowBlock()): ?>
|
||||
<div class="wp-filters <?php if ($isAjaxMode) echo 'wp-filters-ajax' ?>">
|
||||
<?= /* @escapeNotVerified */
|
||||
$block->getFilterButtonHtml() ?>
|
||||
</div>
|
||||
<div class="block filter" id="layered-filter-block"
|
||||
data-mage-init='{"collapsible":{"openedState": "active", "collapsible": true, "active": false, "collateral": { "openedState": "filter-active", "element": "body" } }}'>
|
||||
<?php $filtered = count($block->getLayer()->getState()->getFilters()) ?>
|
||||
<div class="block-title filter-title" data-count="<?= /* @escapeNotVerified */
|
||||
$filtered ?>">
|
||||
<strong data-role="title"><?= /* @escapeNotVerified */
|
||||
__('筛选结果') ?></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 $activeFilters = $block->getActiveFilters() ?>
|
||||
<?php $wrapOptions = false; ?>
|
||||
<?php foreach ($block->getFilters() as $k => $filter): ?>
|
||||
|
||||
<?php $filterAttributeId = $filter->getData('attribute_model') ? $filter->getData('attribute_model')->getAttributeId() : 0; ?>
|
||||
<?php $attributeId = (!$block->isCategoryFilter($filter)) ? $filterAttributeId : 0; ?>
|
||||
<?php if ($filter->getItemsCount()): ?>
|
||||
<?php if (!$wrapOptions): ?>
|
||||
|
||||
<div class="filter-options" id="narrow-by-list" data-role="content"
|
||||
data-mage-init='{"accordion":{"openedState": "active", "collapsible": true, "active": "<?php echo $activeFilters; ?>", "multipleCollapsible": true}}'>
|
||||
<?php $wrapOptions = true; ?>
|
||||
<?php endif; ?>
|
||||
<div data-role="collapsible" class="filter-options-item">
|
||||
<?php $block->getChildBlock('renderer')->setAttributeId($filter) ?>
|
||||
<div data-role="title" class="filter-options-title">
|
||||
<?= /* @escapeNotVerified */ __($filter->getName()) ?></div>
|
||||
<div id="attr_<?php echo $attributeId ?>" data-role="content"
|
||||
class="filter-options-content"><?= /* @escapeNotVerified */
|
||||
$block->getChildBlock('renderer')->render($filter) ?></div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php endforeach; ?>
|
||||
<?php if ($wrapOptions): ?>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<script>
|
||||
require([
|
||||
'jquery'
|
||||
], function ($) {
|
||||
$('#layered-filter-block').addClass('filter-no-options');
|
||||
|
||||
});
|
||||
</script>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<div class="wp-ln-overlay"></div>
|
||||
<div class="wp-ln-slider-js" data-mage-init='<?= /* @escapeNotVerified */ $block->getWidgetOptionsJson() ?>'>
|
||||
<script>
|
||||
<?php if ($jsClass): ?>
|
||||
require.config({
|
||||
map: {
|
||||
'*': {
|
||||
"productListToolbarForm": "<?= $jsClass?>"
|
||||
}
|
||||
}
|
||||
});
|
||||
<?php endif; ?>
|
||||
|
||||
require(['wpFilterSelect'], function(){
|
||||
wpFilterSelect.markSelected();
|
||||
});
|
||||
</script>
|
||||
|
||||
</div>
|
||||
<?php $redirectUrl = $block->getRedirectUrl(); ?>
|
||||
<?php if ($redirectUrl): ?>
|
||||
<script>
|
||||
window.location.href = '<?= $redirectUrl ?>';
|
||||
</script>
|
||||
<?php endif; ?>
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
<script>
|
||||
window.isLayeredNavigationEnabled = '<?= $this->isLnEnabled()?>';
|
||||
</script>
|
||||
Executable
+92
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
// @codingStandardsIgnoreFile
|
||||
|
||||
/** @var $block \WeltPixel\LayeredNavigation\Block\LayeredNavigation\RenderLayered */
|
||||
?>
|
||||
<?php $swatchData = $block->getSwatchData(); ?>
|
||||
<?php $isMulti = $block->getIsMultiSelect($swatchData['attribute_id']) ?>
|
||||
<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" data-is-multi="<?= $block->getIsMultiSelect($swatchData['attribute_id'])?>">
|
||||
<?php foreach ($swatchData['options'] as $option => $label): ?>
|
||||
<a href="<?= /* @escapeNotVerified */ $label['link'] ?>"
|
||||
aria-label="<?= /* @escapeNotVerified */ $label['label'] ?>"
|
||||
class="swatch-option-link-layered"
|
||||
data-is-multi="<?= $isMulti ?>"
|
||||
data-opt-path="<?=/* @escapeNotVerified */ $swatchData['attribute_code']?>=<?= /* @escapeNotVerified */ $option?>"
|
||||
id="wp_ln_swatch_attr_<?= /* @escapeNotVerified */ $swatchData['attribute_id']?>_<?= /* @escapeNotVerified */ $option?>">
|
||||
<?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", "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>
|
||||
|
||||
<div class="wp-ln-selected-js">
|
||||
<script>
|
||||
require(['wpFilterSelect'], function(){
|
||||
wpFilterSelect.markSelected();
|
||||
});
|
||||
</script>
|
||||
|
||||
</div>
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
|
||||
<?php
|
||||
/* @var $block \Magento\Framework\View\Element\Template */
|
||||
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
|
||||
$currentCategory = $objectManager->get(\Magento\Framework\Registry::class)->registry('current_category');
|
||||
|
||||
$scopeConfig = $objectManager->get(\Magento\Framework\App\Config\ScopeConfigInterface::class);
|
||||
|
||||
$samplePackCategoryId = $scopeConfig->getValue(
|
||||
'catalog/product_settings/sample_pack_category_id',
|
||||
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
|
||||
);
|
||||
$productSheetIds = [154,247];
|
||||
if ($samplePackCategoryId){
|
||||
$productSheetIds[] = $samplePackCategoryId;
|
||||
}
|
||||
|
||||
if($currentCategory && in_array($currentCategory->getId(), $productSheetIds)):
|
||||
// 获取当前完整URL
|
||||
$currentUrl = $block->getUrl('*/*/*', ['_current' => true, '_use_rewrite' => true]);
|
||||
$keyword = $block->getRequest()->getParam('keyword');
|
||||
?>
|
||||
<div class="search-technical-resources">
|
||||
<div class="search-technical-resources-form-wrapper">
|
||||
<label>输入产品号或产品名称搜索</label>
|
||||
<form action="<?= $currentUrl ?>" method="get">
|
||||
<input type="text" name="keyword" value="<?= $keyword ?>" placeholder="例如: 17858或EasySep™人CD14正选试剂盒II" class="input-text" maxlength="128" autocomplete="off">
|
||||
|
||||
<input type="hidden" name="product_list_mode" value="list" autocomplete="off">
|
||||
<button type="submit" class="sc-button orange">搜索</button>
|
||||
</form>
|
||||
<div class="clear"></div>
|
||||
</div>
|
||||
<div class="clear"></div>
|
||||
</div>
|
||||
<?php endif;?>
|
||||
<div id="layer-product-list">
|
||||
<?php echo $block->getChildHtml() ?>
|
||||
</div>
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
<div id="layer-product-list">
|
||||
<?php echo $block->getChildHtml() ?>
|
||||
</div>
|
||||
@@ -0,0 +1,291 @@
|
||||
.media-width(@extremum, @break) when (@extremum = 'min') and (@break = @screen__m) {
|
||||
|
||||
#wp_ln_shopby {
|
||||
&.filter-current {
|
||||
#wp_ln_shopby_items {
|
||||
display: block !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.wp-ln-actions {
|
||||
color: #ef8200;
|
||||
font-size: 12px;
|
||||
line-height: 16px;
|
||||
font-weight: normal;
|
||||
margin-top: 20px;
|
||||
}
|
||||
.wp-ln-action {
|
||||
cursor: pointer;
|
||||
display: inline-block;
|
||||
font-weight: normal;
|
||||
padding-right: 20px;
|
||||
}
|
||||
|
||||
.wp-ln-show-less {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.sidebar.sidebar-main {
|
||||
.wp-filters {
|
||||
display: none
|
||||
}
|
||||
}
|
||||
|
||||
body.slider-layer {
|
||||
.column.main {
|
||||
width: 100%;
|
||||
}
|
||||
.block.filter {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.toolbar-products {
|
||||
margin-left: 90px
|
||||
}
|
||||
|
||||
.sidebar.sidebar-main {
|
||||
.wp-filters {
|
||||
display: block;
|
||||
position: absolute;
|
||||
top: 5px;
|
||||
height: 20px;
|
||||
cursor: pointer;
|
||||
font-weight: bold;
|
||||
.wp-filters-text {
|
||||
vertical-align: top;
|
||||
font-weight: bold;
|
||||
}
|
||||
}
|
||||
}
|
||||
.wp-ln-overlay {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: none;
|
||||
z-index: 99;
|
||||
background: rgba(0, 0, 0, .3);
|
||||
overflow: hidden;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
.sidebar.sidebar-main {
|
||||
|
||||
b.wp-slide-in {
|
||||
display: inline-block;
|
||||
background: url('../WeltPixel_LayeredNavigation/images/slide_icon.png') no-repeat;
|
||||
width: 20px;
|
||||
height: 23px;
|
||||
transition: scale 100ms ease;
|
||||
margin: 2px 8px 0 0;
|
||||
|
||||
}
|
||||
}
|
||||
.slide-in-filter {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 12%;
|
||||
min-width: 250px;
|
||||
background: #fff;
|
||||
height: 95%;
|
||||
padding: 25px;
|
||||
overflow: scroll;
|
||||
margin-bottom: 10px;
|
||||
z-index: 100;
|
||||
|
||||
.block-subtitle {
|
||||
font-size: 15px;
|
||||
text-align: center;
|
||||
padding: 10px 10px 30px
|
||||
}
|
||||
|
||||
.filter-options-item {
|
||||
padding: 15px 0;
|
||||
border-bottom: 1px solid #ecece7
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
b.wp-ln-load-more {
|
||||
&:before {
|
||||
font-family: FontAwesome;
|
||||
padding-right: 6px;
|
||||
margin-left: 2px;
|
||||
content: '\f055';
|
||||
}
|
||||
}
|
||||
|
||||
b.wp-ln-show-less {
|
||||
&:before {
|
||||
font-family: FontAwesome;
|
||||
padding-right: 6px;
|
||||
margin-left: 2px;
|
||||
content: '\f056';
|
||||
}
|
||||
}
|
||||
|
||||
#layered-filter-block {
|
||||
.wp-ln-selected {
|
||||
a{
|
||||
border-left: 5px solid red;
|
||||
padding-left: 11px;
|
||||
font-style: italic;
|
||||
color: #908f8f;
|
||||
}
|
||||
}
|
||||
.filter-options-item {
|
||||
.filter-options-content {
|
||||
display: none;
|
||||
}
|
||||
&.active {
|
||||
.filter-options-content {
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#layered-filter-block {
|
||||
.wp-ln-selected {
|
||||
.swatch-option {
|
||||
position: relative;
|
||||
overflow: visible;
|
||||
outline: 2px solid #ee0000;
|
||||
border: 1px solid #fff;
|
||||
&:before {
|
||||
visibility: visible;
|
||||
border: 3px solid white !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#layer-product-list {
|
||||
.message.info.empty{
|
||||
margin-left: 90px !important;
|
||||
}
|
||||
}
|
||||
|
||||
body.theme-pearl{
|
||||
.slide-in-filter {
|
||||
height: 100% !important;
|
||||
}
|
||||
|
||||
b.wp-ln-load-more {
|
||||
&:before {
|
||||
font-family: FontAwesome;
|
||||
padding-right: 6px;
|
||||
margin-left: 2px;
|
||||
content: '\f055';
|
||||
}
|
||||
}
|
||||
|
||||
b.wp-ln-show-less {
|
||||
&:before {
|
||||
font-family: FontAwesome;
|
||||
padding-right: 6px;
|
||||
margin-left: 2px;
|
||||
content: '\f056';
|
||||
}
|
||||
}
|
||||
|
||||
.sidebar.sidebar-main {
|
||||
.wp-filters {
|
||||
top: 16px !important;
|
||||
.wp-filters-text {
|
||||
text-transform: uppercase;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#layered-filter-block {
|
||||
.wp-ln-selected {
|
||||
a{
|
||||
text-decoration: none;
|
||||
font-weight: 900;
|
||||
border-left: 0 none;
|
||||
font-style:normal;
|
||||
color: inherit;
|
||||
&:before {
|
||||
background: #303030;
|
||||
border: 1px solid #303030 !important;
|
||||
}
|
||||
}
|
||||
|
||||
.swatch-option {
|
||||
outline: 2px solid #ee0000;
|
||||
border: 1px solid #fff;
|
||||
}
|
||||
|
||||
.swatch-option.text {
|
||||
position: relative;
|
||||
overflow: visible;
|
||||
border: 2px solid #999999 !important;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
#layer-product-list {
|
||||
.message.info.empty{
|
||||
margin-left: 90px !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.media-width(@extremum, @break) when (@extremum = 'max') and (@break = @screen__m) {
|
||||
#layered-filter-block {
|
||||
.wp-ln-selected {
|
||||
.swatch-option {
|
||||
position: relative;
|
||||
overflow: visible;
|
||||
outline: 2px solid #ee0000;
|
||||
border: 1px solid #fff;
|
||||
&:before {
|
||||
visibility: visible;
|
||||
border: 3px solid white !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.wp-ln-actions {
|
||||
color: #ef8200;
|
||||
font-size: 12px;
|
||||
line-height: 16px;
|
||||
font-weight: normal;
|
||||
margin-top: 20px;
|
||||
}
|
||||
.wp-ln-action {
|
||||
cursor: pointer;
|
||||
display: inline-block;
|
||||
font-weight: normal;
|
||||
padding-right: 20px;
|
||||
}
|
||||
|
||||
.wp-ln-show-less {
|
||||
display: none;
|
||||
}
|
||||
b.wp-ln-load-more {
|
||||
&:before {
|
||||
font-family: FontAwesome;
|
||||
padding-right: 6px;
|
||||
margin-left: 2px;
|
||||
content: '\f055';
|
||||
}
|
||||
}
|
||||
|
||||
b.wp-ln-show-less {
|
||||
&:before {
|
||||
font-family: FontAwesome;
|
||||
padding-right: 6px;
|
||||
margin-left: 2px;
|
||||
content: '\f056';
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 177 B |
@@ -0,0 +1,696 @@
|
||||
define([
|
||||
"jquery",
|
||||
"loader",
|
||||
"jquery-ui-modules/widget",
|
||||
"jquery-ui-modules/effect-slide",
|
||||
"Magento_Catalog/js/product/list/toolbar",
|
||||
], function ($) {
|
||||
/**
|
||||
* ProductListToolbarForm Widget - this widget is setting cookie and submitting form according to toolbar controls
|
||||
*/
|
||||
$.widget('mage.productListToolbarForm', $.mage.productListToolbarForm, {
|
||||
|
||||
options:
|
||||
{
|
||||
modeControl: '[data-role="mode-switcher"]',
|
||||
directionControl: '[data-role="direction-switcher"]',
|
||||
orderControl: '[data-role="sorter"]',
|
||||
limitControl: '[data-role="limiter"]',
|
||||
pagerControl: '[data-role="pager"], .pages-items a',
|
||||
mode: 'product_list_mode',
|
||||
direction: 'product_list_dir',
|
||||
order: 'product_list_order',
|
||||
limit: 'product_list_limit',
|
||||
pager: 'p',
|
||||
modeDefault: 'grid',
|
||||
directionDefault: 'asc',
|
||||
orderDefault: 'position',
|
||||
limitDefault: '9',
|
||||
pagerDefault: '1',
|
||||
productsToolbarControl: '.toolbar.toolbar-products',
|
||||
productsListBlock: '#layer-product-list',
|
||||
layeredNavigationFilterBlock: '.block.filter',
|
||||
filterItemControl: '.block.filter .item a, .block.filter .filter-clear,.block.filter .swatch-option-link-layered, .wp-price-slider-a',
|
||||
url: ''
|
||||
},
|
||||
|
||||
_create: function () {
|
||||
this._super();
|
||||
this._bind($(this.options.pagerControl), this.options.pager, this.options.pagerDefault);
|
||||
$(this.options.filterItemControl)
|
||||
.off('click.' + this.namespace + 'productListToolbarForm')
|
||||
.on('click.' + this.namespace + 'productListToolbarForm', {}, $.proxy(this.applyFilterToProductsList, this))
|
||||
;
|
||||
|
||||
var that = this;
|
||||
|
||||
window.onpopstate = function(event) {
|
||||
var ignoredHashes = ['#search-mod'];
|
||||
if (event && !ignoredHashes.includes(window.location.hash) && window.location.href.slice(-1) != '#') {
|
||||
var backUrl = event.target.location.origin + event.target.location.pathname;
|
||||
var paramData = event.target.location.search.replace(/^\?/, '')
|
||||
that.makeAjaxCall(backUrl, paramData, false);
|
||||
}
|
||||
}
|
||||
|
||||
$('.item a.wp-filter-disabled').off('click');
|
||||
if (window.wp_ajax_useCustomPlaceholder == '1') {
|
||||
$('.page-wrapper').loader({
|
||||
icon: window.loadingImage,
|
||||
template: '<div class="loading-mask" data-role="loader">\n' +
|
||||
' <div class="loader">\n' +
|
||||
' <img alt="<%- data.texts.imgAlt %>" style="max-width: ' + window.wp_ajax_placeholderCustomWidth + '" src="<%- data.icon %>">\n' +
|
||||
' <p><%- data.texts.loaderText %></p>\n' +
|
||||
' </div>\n' +
|
||||
'</div>'
|
||||
});
|
||||
}
|
||||
},
|
||||
/**
|
||||
* @param {jQuery.Event} event
|
||||
* @private
|
||||
*/
|
||||
_processPagination: function (event) {
|
||||
event.preventDefault();
|
||||
var paginationUrl = event.currentTarget.href;
|
||||
var urlParams = this.getUrlParams(paginationUrl);
|
||||
this.changeUrl(
|
||||
event.data.paramName,
|
||||
urlParams[event.data.paramName],
|
||||
event.data.default
|
||||
);
|
||||
},
|
||||
_bind: function (element, paramName, defaultValue) {
|
||||
/**
|
||||
* Prevent double binding of these events because this component is being applied twice in the UIX
|
||||
*/
|
||||
if (paramName == this.options.pager) {
|
||||
element
|
||||
.off('click.' + this.namespace + 'productListToolbarForm')
|
||||
.on('click.' + this.namespace + 'productListToolbarForm', {
|
||||
paramName: paramName,
|
||||
default: defaultValue
|
||||
}, $.proxy(this._processPagination, this));
|
||||
} else if (element.is("select")) {
|
||||
element
|
||||
.off('change.' + this.namespace + 'productListToolbarForm')
|
||||
.on('change.' + this.namespace + 'productListToolbarForm', {
|
||||
paramName: paramName,
|
||||
default: defaultValue
|
||||
}, $.proxy(this._processSelect, this));
|
||||
} else {
|
||||
element
|
||||
.off('click.' + this.namespace + 'productListToolbarForm')
|
||||
.on('click.' + this.namespace + 'productListToolbarForm', {
|
||||
paramName: paramName,
|
||||
default: defaultValue
|
||||
}, $.proxy(this._processLink, this));
|
||||
}
|
||||
|
||||
},
|
||||
applyFilterToProductsList: function (evt) {
|
||||
var link = $(evt.currentTarget),
|
||||
linkA = link.attr('href'),
|
||||
urlParts = (typeof linkA !== 'undefined') ? linkA.split('?') : '',
|
||||
currentUrl = window.location.href,
|
||||
isMulti = (link.attr('data-is-multi')) ? link.data('is-multi') : 0,
|
||||
parentElem = link.parent(),
|
||||
clickOpt = (parentElem.attr('data-path-opt')) ? parentElem.data('opt-path') : link.data('opt-path'),
|
||||
c = currentUrl.split('?');
|
||||
window.isSorting = false;
|
||||
var reqeustParams = (typeof urlParts[1] === 'undefined') ? '' : urlParts[1];
|
||||
|
||||
var mergedPath = reqeustParams;
|
||||
|
||||
if (reqeustParams.length > 0 && typeof c[1] !== 'undefined') {
|
||||
mergedPath = this.compareMergeParams(c[1], reqeustParams, clickOpt, isMulti);
|
||||
}
|
||||
|
||||
self.elem = link;
|
||||
|
||||
this.makeAjaxCall(urlParts[0], mergedPath, true);
|
||||
evt.preventDefault();
|
||||
|
||||
},
|
||||
compareMergeParams: function (currentParamsStr, newParamsStr, clickOpt, isMulti) {
|
||||
var a = currentParamsStr.split('&');
|
||||
var b = newParamsStr.split('&');
|
||||
var c = (typeof clickOpt !== 'undefined') ? clickOpt.split('=') : '';
|
||||
var res = '';
|
||||
a.sort();
|
||||
b.sort();
|
||||
for (var i = 0; i < b.length; i++) {
|
||||
var paramStr = b[i].split('=')[0],
|
||||
paramVal = decodeURIComponent(b[i].split('=')[1]),
|
||||
paramArr = paramVal.split(',');
|
||||
for (var j = 0; j < a.length; j++) {
|
||||
|
||||
if (typeof a[j] === 'undefined') {
|
||||
continue;
|
||||
}
|
||||
|
||||
var existParamStr = a[j].split('=')[0],
|
||||
existParamVal = decodeURIComponent(a[j].split('=')[1]),
|
||||
existParamArr = existParamVal.split(','),
|
||||
matchParams = '';
|
||||
|
||||
if(paramStr == 'p' || paramStr == 'q' || paramStr == 'ajax') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (paramStr !== existParamStr) {
|
||||
//res += paramStr + '=' + paramVal + '&';
|
||||
continue;
|
||||
}
|
||||
for (var z = 0; z < existParamArr.length; z++) {
|
||||
if (paramArr.indexOf(existParamArr[z]) !== -1) {
|
||||
matchParams = (matchParams.length === 0) ? existParamArr[z] : matchParams + ',' + existParamArr[z];
|
||||
}
|
||||
}
|
||||
|
||||
if (paramStr === existParamStr && paramVal !== existParamVal && matchParams.length === 0 && isMulti != 0) {
|
||||
paramVal = existParamVal + ',' + paramVal;
|
||||
}
|
||||
else if( c[0] == paramStr && c[1] == matchParams ){
|
||||
var filteredArray = existParamArr.filter(function(e) { return e !== matchParams })
|
||||
paramVal = (filteredArray.length > 0) ? filteredArray.join(',') : '';
|
||||
}
|
||||
else {
|
||||
//paramVal = matchParams;
|
||||
}
|
||||
}
|
||||
|
||||
if(paramVal) {
|
||||
res += paramStr + '=' + paramVal + '&';
|
||||
}
|
||||
|
||||
}
|
||||
res = res.slice(0, -1);
|
||||
|
||||
return res;
|
||||
},
|
||||
updateUrl: function (url, paramData, pushState) {
|
||||
if (!url) {
|
||||
return;
|
||||
}
|
||||
if (paramData && paramData.length > 0) {
|
||||
url += '?' + paramData;
|
||||
}
|
||||
url = this.removeQueryStringParameter('ajax', url);
|
||||
url = this.removeQueryStringParameter('_', url);
|
||||
if (pushState && (typeof history.pushState === 'function')) {
|
||||
history.pushState({}, null, url);
|
||||
}
|
||||
},
|
||||
|
||||
getParams: function (urlParams, paramName, paramValue, defaultValue) {
|
||||
var decode = window.decodeURIComponent,
|
||||
paramData = {},
|
||||
parameters, i;
|
||||
|
||||
for (i = 0; i < urlParams.length; i++) {
|
||||
parameters = urlParams[i].split('=');
|
||||
paramData[decode(parameters[0])] = parameters[1] !== undefined ?
|
||||
decode(parameters[1].replace(/\+/g, '%20')) :
|
||||
'';
|
||||
}
|
||||
|
||||
/** get the real attr name from param */
|
||||
var paramValueArr = paramValue.split('~'),
|
||||
paramValueNew = paramValueArr[0];
|
||||
|
||||
paramData[paramName] = paramValueNew;
|
||||
|
||||
/** get the given direction from param */
|
||||
var directionName = this.options.direction;
|
||||
if (paramValueArr.length == 2 && paramName != directionName) {
|
||||
paramData[directionName] = paramValueArr[1];
|
||||
}
|
||||
|
||||
return $.param(paramData);
|
||||
},
|
||||
_updateContent: function (content) {
|
||||
window.shouldOpenMinicart = false;
|
||||
$(this.options.productsToolbarControl).remove();
|
||||
if (content.products_list) {
|
||||
$(this.options.productsListBlock).html(content.products_list);
|
||||
$(this.options.productsListBlock).trigger('contentUpdated');
|
||||
}
|
||||
|
||||
if (content.filters) {
|
||||
var isSlideIn = $('body').hasClass('slider-layer');
|
||||
var isSlideDown = $('body').hasClass('slider-down-layer');
|
||||
var isAutoClose = $('#layered-filter-block').hasClass('auto-close');
|
||||
var isViewL = $('body').hasClass('wp-device-l');
|
||||
var isViewXl = $('body').hasClass('wp-device-xl');
|
||||
$(this.options.layeredNavigationFilterBlock).replaceWith(content.filters);
|
||||
$(this.options.layeredNavigationFilterBlock).trigger('contentUpdated');
|
||||
|
||||
if(!isAutoClose && isSlideIn && !window.isSorting && (isViewL || isViewXl)) {
|
||||
$('body').addClass('wp-ln-open').css({'height': '100%', 'overflow': 'hidden'});
|
||||
$('.block-search, a.logo').css({'z-index': '1'});
|
||||
$('.wp-ln-overlay').fadeIn(100, 'swing', function () {
|
||||
$('#layered-filter-block').delay(150).show("slide", {direction: "left"});
|
||||
});
|
||||
}
|
||||
|
||||
if(!isAutoClose && isSlideDown && !window.isSorting) {
|
||||
var productWrapperMarginTop = $('body').attr('data-pwmt');
|
||||
$('.products.wrapper').animate({marginTop: productWrapperMarginTop},
|
||||
{
|
||||
duration:500,
|
||||
complete: function() {
|
||||
$('.wp-filters span.wp-slide-down-add').addClass('active');
|
||||
}
|
||||
|
||||
});
|
||||
$('.wp-slide-down-add:not(active)').off('click');
|
||||
$('.slide-down-filter').slideDown(500);
|
||||
$('body.slider-down-layer #layered-filter-block').show();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (content.ga4ServerSideItemListHash) {
|
||||
window.wpGA4ServerSide.pushViewItemList(content.ga4ServerSideItemListHash);
|
||||
}
|
||||
|
||||
if (content.dataLayer) {
|
||||
var dlObjects = JSON.parse(content.dataLayer);
|
||||
window.dataLayer = window.dataLayer || [];
|
||||
for (var i in dlObjects) {
|
||||
window.dataLayer.push({ecommerce: null});
|
||||
window.dataLayer.push(dlObjects[i]);
|
||||
}
|
||||
}
|
||||
if (content.dataLayerGA4) {
|
||||
var dl4Objects = JSON.parse(content.dataLayerGA4);
|
||||
window.dataLayer = window.dataLayer || [];
|
||||
for (var i in dl4Objects) {
|
||||
window.dataLayer.push({ecommerce: null});
|
||||
window.dataLayer.push(dl4Objects[i]);
|
||||
}
|
||||
}
|
||||
$(document).trigger("wpproductlabels:init");
|
||||
$('li.product-item').trigger('contentUpdated');
|
||||
if (window.isSlCustomPopupUsed && parseInt(window.isSlCustomPopupUsed)) {
|
||||
$('li.product-item').find('.towishlist').each(function() {
|
||||
$(this).removeAttr('data-post');
|
||||
})
|
||||
}
|
||||
$('body').trigger('contentUpdated');
|
||||
|
||||
},
|
||||
lnSlideDown: function() {
|
||||
var productWrapperMarginTop = $('body').attr('data-pwmt');
|
||||
|
||||
$('.products.wrapper').animate({marginTop: productWrapperMarginTop},
|
||||
{
|
||||
duration:500,
|
||||
complete: function() {
|
||||
$('.wp-filters span.wp-slide-down-add').addClass('active');
|
||||
}
|
||||
|
||||
});
|
||||
$('.wp-slide-down-add:not(active)').off('click');
|
||||
$('.slide-down-filter').slideDown(500);
|
||||
$('.wp-filters').on('click', this.lnSlideUp);
|
||||
},
|
||||
lnSlideUp: function() {
|
||||
$('.wp-filters').off('click');
|
||||
$('.slide-down-filter').slideUp(
|
||||
{
|
||||
duration: 500,
|
||||
start: function(){
|
||||
$('.products.wrapper').animate(
|
||||
{
|
||||
marginTop: '0px'
|
||||
},
|
||||
{
|
||||
duration:500,
|
||||
complete: function() {
|
||||
$('.wp-filters span.wp-slide-down-add').removeClass('active');
|
||||
$('.wp-filters').on('click', this.lnSlideDown);
|
||||
},
|
||||
queue: false
|
||||
}
|
||||
);
|
||||
|
||||
},
|
||||
queue: false
|
||||
});
|
||||
},
|
||||
reinitializeIas: function() {
|
||||
if(require.defined('ias') && window.ajaxCatalog == 'infiniteScroll') {
|
||||
jQuery.ias().destroy();
|
||||
jQuery(function($) {
|
||||
var config = {
|
||||
container: '.products.wrapper .product-items',
|
||||
item: '.product-item',
|
||||
pagination: '.toolbar .pages, .toolbar .limiter',
|
||||
next: '.pages .action.next',
|
||||
negativeMargin: window.negativeMargin
|
||||
};
|
||||
|
||||
var pagertext = jQuery(".toolbar-amount");
|
||||
pagertext.show();
|
||||
|
||||
/** added to prevent jquery to add extra "_" parameter to link */
|
||||
$.ajaxSetup({ cache: true });
|
||||
|
||||
/** add infinite-scroll class */
|
||||
$(config.container).closest('.column.main').addClass('infinite-scroll');
|
||||
/** load ias */
|
||||
var ias = $.ias(config);
|
||||
|
||||
ias.getNextUrl = function(container) {
|
||||
if (!container) {
|
||||
container = ias.$container;
|
||||
}
|
||||
/** always take the last matching item + fix to be protocol relative */
|
||||
var nexturl = $(ias.nextSelector, container).last().attr('href');
|
||||
if(typeof nexturl !== "undefined") {
|
||||
if (window.location.protocol == 'https:') {
|
||||
nexturl = nexturl.replace('http:', window.location.protocol);
|
||||
} else {
|
||||
nexturl = nexturl.replace('https:', window.location.protocol);
|
||||
}
|
||||
nexturl = window.ajaxInfiniteScroll.removeQueryStringParameter('_', nexturl);
|
||||
nexturl = window.ajaxInfiniteScroll.removeQueryStringParameter('ajax', nexturl);
|
||||
}
|
||||
|
||||
return nexturl;
|
||||
};
|
||||
|
||||
/** adds extra functionality to Infinite AJAX Scroll */
|
||||
ias.extension(new IASPagingExtension());
|
||||
ias.on('pageChange', function(pageNum, scrollOffset, url) {
|
||||
window.page = pageNum;
|
||||
});
|
||||
|
||||
/** added to prevent jquery to add extra "_" parameter to link */
|
||||
ias.on('load', function(event) {
|
||||
var url = event.url;
|
||||
event.ajaxOptions.cache = true;
|
||||
event.url = window.ajaxInfiniteScroll.removeQueryStringParameter('_', event.url);
|
||||
});
|
||||
|
||||
ias.on('loaded', function(data, items) {
|
||||
/** fix lazy load images */
|
||||
window.ajaxInfiniteScroll.reloadImages(items);
|
||||
window.ajaxInfiniteScroll.dataLayerUpdate(data);
|
||||
});
|
||||
/** fix ajax add to cart */
|
||||
ias.on('rendered', function(items) {
|
||||
window.ajaxInfiniteScroll.fixAddToCart();
|
||||
/** re-init Pearl related elements */
|
||||
window.ajaxInfiniteScroll.reloadQuickView();
|
||||
window.ajaxInfiniteScroll.reloadCategoryPage();
|
||||
/** update next/prev head links */
|
||||
if (window.showCanonical == 1) {
|
||||
window.ajaxInfiniteScroll.reloadCanonicalPrevNext();
|
||||
}
|
||||
$('.product-item-info a').each(function() {
|
||||
if( typeof $(this).attr('data-item-page') === 'undefined') {
|
||||
$(this).attr('data-item-page', window.page);
|
||||
}
|
||||
});
|
||||
$(document).trigger("wpproductlabels:init");
|
||||
$('li.product-item').trigger('contentUpdated');
|
||||
if (window.isSlCustomPopupUsed && parseInt(window.isSlCustomPopupUsed)) {
|
||||
$('li.product-item').find('.towishlist').each(function() {
|
||||
$(this).removeAttr('data-post');
|
||||
})
|
||||
}
|
||||
$.mage.formKey();
|
||||
});
|
||||
|
||||
|
||||
/** adds a text when there are no more pages to load */
|
||||
ias.extension(new IASNoneLeftExtension({
|
||||
html: '<span class="ias-no-more">' + window.textNoMore + '</span>'
|
||||
|
||||
}));
|
||||
/** displays a customizable loader image when loading a new page */
|
||||
var loadingHtml = '<div class="ias-spinner">';
|
||||
loadingHtml += '<img src="{src}"';
|
||||
if (window.wp_ajax_useCustomPlaceholder == '1') {
|
||||
loadingHtml += "style='max-width:" + window.wp_ajax_placeholderCustomWidth +"'";
|
||||
}
|
||||
loadingHtml += '/>';
|
||||
loadingHtml += '<span>' + window.textLoadingMore + '</span>';
|
||||
loadingHtml += '</div>';
|
||||
ias.extension(new IASSpinnerExtension({
|
||||
src: window.loadingImage,
|
||||
html: loadingHtml
|
||||
}));
|
||||
|
||||
/** adds "Load More" and "Load Previous" button */
|
||||
if (window.LoadMore > 0) {
|
||||
ias.extension(new IASTriggerExtension({
|
||||
text: window.textNext,
|
||||
html: '<button class="button action ias-load-more" type="button"><span>{text}</span></button>',
|
||||
textPrev: 'Load previous items',
|
||||
htmlPrev: '<button class="button action ias-load-prev" type="button"><span>{text}</span></button>',
|
||||
offset: window.LoadMore
|
||||
}));
|
||||
} else {
|
||||
ias.extension(new IASTriggerExtension({
|
||||
textPrev: 'Load previous items',
|
||||
htmlPrev: '<button class="button action ias-load-prev" type="button"><span>{text}</span></button>',
|
||||
offset: 1000
|
||||
}));
|
||||
}
|
||||
/** adds history support */
|
||||
ias.extension(new IASHistoryExtension({prev: '.previous'}));
|
||||
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
updateContent: function (content) {
|
||||
this._updateContent(content)
|
||||
},
|
||||
|
||||
|
||||
changeUrl: function (paramName, paramValue, defaultValue) {
|
||||
var urlPaths = this.options.url.split('?'),
|
||||
baseUrl = urlPaths[0],
|
||||
urlParams = urlPaths[1] ? urlPaths[1].split('&') : [],
|
||||
paramData = this.getParams(urlParams, paramName, paramValue, defaultValue);
|
||||
window.isSorting = (paramName == 'product_list_order' || paramName == 'product_list_limit' || paramName == 'p') ? true : false;
|
||||
if( paramName == 'product_list_mode') {// paramName == 'product_list_order' - to remove adavancedsorting by ajax
|
||||
var ajaxParam = false;
|
||||
for (var i = urlParams.length; i--;) {
|
||||
if (urlParams[i] === 'ajax=1') {
|
||||
urlParams.splice(i, 1);
|
||||
ajaxParam = true;
|
||||
}
|
||||
}
|
||||
if (ajaxParam) {
|
||||
paramData = this.getParams(urlParams, paramName, paramValue, defaultValue);
|
||||
}
|
||||
location.href = baseUrl + (paramData.length ? '?' + paramData : '');
|
||||
} else {
|
||||
this.makeAjaxCall(baseUrl, paramData, true);
|
||||
}
|
||||
},
|
||||
|
||||
backToTop: function()
|
||||
{
|
||||
var stickyHeader = $('.sticky-header, .sticky-header-mobile, .page-header.sticky'),
|
||||
stickyHeaderHeight = 0;
|
||||
if (stickyHeader.length) {
|
||||
stickyHeaderHeight = parseInt(stickyHeader.outerHeight());
|
||||
}
|
||||
|
||||
$('html, body').animate({
|
||||
scrollTop: ($('.column.main').offset().top - stickyHeaderHeight)
|
||||
}, 'slow');
|
||||
},
|
||||
|
||||
makeAjaxCall: function (baseUrl, paramData, pushState) {
|
||||
var self = this;
|
||||
var isSlideIn = $('body').hasClass('slider-layer');
|
||||
if (!isSlideIn) {
|
||||
self.backToTop();
|
||||
}
|
||||
var showLoader = true;
|
||||
if (window.wp_ajax_useCustomPlaceholder == '1' && window.isSorting) {
|
||||
$('.page-wrapper').loader("show");
|
||||
showLoader = false;
|
||||
}
|
||||
var jqxhr = $.ajax({
|
||||
url: baseUrl,
|
||||
data: (paramData && paramData.length > 0) ? paramData + '&ajax=1' : 'ajax=1',
|
||||
type: 'get',
|
||||
global: false,
|
||||
dataType: 'json',
|
||||
cache: true,
|
||||
showLoader: showLoader,
|
||||
beforeSend: function (xhr){
|
||||
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
|
||||
if(typeof window.page === 'undefined') {
|
||||
window.page = $('.product-item-info a').last().attr('data-item-page');
|
||||
}
|
||||
}
|
||||
}).done(function (response) {
|
||||
if (response.success) {
|
||||
$('.swatch-option-tooltip').hide();
|
||||
self.updateUrl(baseUrl, paramData, pushState);
|
||||
self.updateContent(response.html);
|
||||
self.slidersUpdate();
|
||||
}
|
||||
});
|
||||
|
||||
jqxhr.always(function() {
|
||||
if (window.wp_ajax_useCustomPlaceholder == '1') {
|
||||
$('.page-wrapper').loader("hide");
|
||||
}
|
||||
/** fix lazy load image width */
|
||||
$("img.lazy").each(function() {
|
||||
$(this).css({'max-width':'100%'});
|
||||
});
|
||||
|
||||
self.reinitializeIas();
|
||||
$('.product.photo.product-item-photo').on('click', function(e) {
|
||||
e.preventDefault();
|
||||
var page = $(this).attr('data-item-page');
|
||||
var url = window.location.href;
|
||||
self.resetIasPagination(page, url);
|
||||
var href = $(this).attr('href');
|
||||
window.location.href = href;
|
||||
});
|
||||
$('.product-item-info a').each(function() {
|
||||
if( typeof $(this).attr('data-item-page') === 'undefined') {
|
||||
$(this).attr('data-item-page', window.page);
|
||||
}
|
||||
});
|
||||
if(require.defined('ias') && window.ajaxCatalog == 'nextPage') {
|
||||
window.ajaxInfiniteScroll.addPageSelector('.pages li.item a.page');
|
||||
}
|
||||
|
||||
if ($('body').hasClass('slider-layer')) self.resetPage();
|
||||
if ($('body').hasClass('slider-down-layer')) self.slideUpReset();
|
||||
|
||||
self.reloadQuickView();
|
||||
window.shouldOpenMinicart = '1';
|
||||
$.mage.formKey();
|
||||
});
|
||||
},
|
||||
resetIasPagination: function(page, url) {
|
||||
if(require.defined('ias') && window.ajaxCatalog == 'infiniteScroll') {
|
||||
jQuery.ias().destroy();
|
||||
var newUrl = url.replace(/(&p=|\?p=).*?(&|$)/,'$1' + page + '$2');
|
||||
window.history.replaceState("", "", newUrl);
|
||||
|
||||
|
||||
}
|
||||
},
|
||||
reloadQuickView: function() {
|
||||
var quickView = $('.weltpixel-quickview');
|
||||
if (quickView.length) {
|
||||
$('.weltpixel-quickview').bind('click', function() {
|
||||
var prodUrl = $(this).attr('data-quickview-url');
|
||||
if (prodUrl.length) {
|
||||
window.quickview.displayContent(prodUrl);
|
||||
}
|
||||
});
|
||||
if (window.wpQwListMode == 'list') {
|
||||
quickView.each(function (key, item) {
|
||||
if (!$(item).hasClass('wp-qw-adjusted')) {
|
||||
var imageWrapper = $(item).closest('.product-item').find('.product-item-info').get(0);
|
||||
var imagePhotoLink = $(item).closest('.product-item-info').find('.product-item-photo').get(0);
|
||||
|
||||
$(imageWrapper).prepend('<div class="product photo product-item-photo product-image-list"></div>');
|
||||
var imageCustomDiv = $(item).closest('.product-item-info').find('.product-image-list').get(0);
|
||||
|
||||
$(imagePhotoLink).appendTo(imageCustomDiv)
|
||||
var imagePhoto = $(item).closest('.product-item-info').find('.product-image-list').get(0);
|
||||
$(item).show().appendTo(imagePhoto);
|
||||
$(item).addClass('wp-qw-adjusted');
|
||||
$(item).css('display', '');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
slidersUpdate: function () {
|
||||
$('.wp-slide-in').not(':first').remove();
|
||||
$('.wp-slide-out').not(':first').remove();
|
||||
$('.wp-filters').not(':first').remove();
|
||||
$('.wp-ln-overlay').not(':first').remove();
|
||||
$('.wp-ln-slider-js').not(':first').remove();
|
||||
$('.wp-ln-selected-js').not(':first').remove();
|
||||
},
|
||||
resetPage: function () {
|
||||
var slideInBlock = $('#layered-filter-block');
|
||||
if(slideInBlock.hasClass('auto-close')) {
|
||||
//$('.slide-in-filter').hide('slide', {direction: "left"}, 500, function () {
|
||||
$('body').removeClass('wp-ln-open').css({'height': 'auto', 'overflow': 'auto'});
|
||||
$('.wp-ln-overlay').hide();
|
||||
$('.block-search, a.logo').css({'z-index': '10'});
|
||||
//});
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
slideUpReset: function () {
|
||||
var slideDownBlock = $('#layered-filter-block');
|
||||
if(slideDownBlock.hasClass('auto-close')) {
|
||||
//$('.wp-slide-down-add.active').off('click');
|
||||
//$('.wp-slide-down-add:not(active)').on('click', self.lnSlideDown());
|
||||
$('.wp-filters span.wp-slide-down-add').removeClass('active');
|
||||
$('.products.wrapper').animate({marginTop: '0px'}, 1000);
|
||||
$('.slide-down-filter').slideUp(1000);
|
||||
$('.wp-filters').off('click');
|
||||
} else {
|
||||
$('.wp-filters span.wp-slide-down-add').removeClass('active');
|
||||
$('.wp-filters').off('click');
|
||||
}
|
||||
},
|
||||
|
||||
markSelected: function () {
|
||||
var elem = self.elem.parent();
|
||||
if(elem.hasClass('wp-ln-selected')) {
|
||||
elem.removeClass('wp-ln-selected');
|
||||
|
||||
} else {
|
||||
elem.addClass('wp-ln-selected');
|
||||
}
|
||||
|
||||
},
|
||||
removeQueryStringParameter: function (key, url)
|
||||
{
|
||||
if (!url) url = window.location.href;
|
||||
var hashParts = url.split('#'),
|
||||
regex = new RegExp("([?&])" + key + "=.*?(&|#|$)", "i");
|
||||
|
||||
if (hashParts[0].match(regex)) {
|
||||
url = hashParts[0].replace(regex, '$1');
|
||||
url = url.replace(/([?&])$/, '');
|
||||
if (typeof hashParts[1] !== 'undefined' && hashParts[1] !== null)
|
||||
url += '#' + hashParts[1];
|
||||
}
|
||||
|
||||
return url;
|
||||
},
|
||||
getUrlParams: function (url) {
|
||||
var params = {
|
||||
p: "1"
|
||||
};
|
||||
var parser = document.createElement('a');
|
||||
parser.href = url;
|
||||
var query = parser.search.substring(1);
|
||||
var vars = query.split('&');
|
||||
for (var i = 0; i < vars.length; i++) {
|
||||
var pair = vars[i].split('=');
|
||||
params[pair[0]] = decodeURIComponent(pair[1]);
|
||||
}
|
||||
return params;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
return $.mage.productListToolbarForm;
|
||||
});
|
||||
@@ -0,0 +1,25 @@
|
||||
define([
|
||||
"jquery"
|
||||
], function ($) {
|
||||
"use strict";
|
||||
|
||||
window.wpFilterSelect = {
|
||||
markSelected: function() {
|
||||
$.each($('#wp_ln_shopby_items li'), function() {
|
||||
var id = $(this).data('attr-id');
|
||||
if(id) {
|
||||
var filterElem = $('#wp_ln_attr_' + id);
|
||||
var filterSwatchElem = $('#wp_ln_swatch_attr_' + id);
|
||||
|
||||
if(filterElem.length) {
|
||||
filterElem.addClass('wp-ln-selected');
|
||||
}
|
||||
|
||||
if(filterSwatchElem.length) {
|
||||
filterSwatchElem.addClass('wp-ln-selected');
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user