init
This commit is contained in:
Executable
+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();
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace WeltPixel\LayeredNavigation\Block\Adminhtml\System\Config;
|
||||
|
||||
/**
|
||||
* Implement
|
||||
* @category WeltPixel_OwlCarouselSlider
|
||||
* @package WeltPixel_OwlCarouselSlider
|
||||
* @module OwlCarouselSlider
|
||||
* @author WeltPixel_OwlCarouselSlider Developer
|
||||
*/
|
||||
class InfoMessage extends \Magento\Config\Block\System\Config\Form\Field
|
||||
{
|
||||
protected function _getElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element)
|
||||
{
|
||||
$number = (int)substr($element->getId(), -1);
|
||||
|
||||
|
||||
$html = '
|
||||
<div class="message" style="text-align: center; margin-top: 20px;">
|
||||
<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>
|
||||
</div>
|
||||
';
|
||||
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
+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,56 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
+387
@@ -0,0 +1,387 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* 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 \Magento\Framework\Registry
|
||||
*/
|
||||
protected $_registry;
|
||||
|
||||
/**
|
||||
* @var \WeltPixel\LayeredNavigation\Model\AttributeOptions
|
||||
*/
|
||||
protected $_attributeOptions;
|
||||
|
||||
/**
|
||||
* @var \Magento\Swatches\Helper\Data
|
||||
*/
|
||||
private $swatchHelper;
|
||||
|
||||
/**
|
||||
* 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 \Magento\Framework\Registry $registry
|
||||
* @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,
|
||||
\Magento\Framework\Registry $registry,
|
||||
\Magento\Swatches\Helper\Data $swatchHelper,
|
||||
array $data = []
|
||||
)
|
||||
{
|
||||
$this->_catalogLayer = $layerResolver->get();
|
||||
$this->filterList = $filterList;
|
||||
$this->visibilityFlag = $visibilityFlag;
|
||||
$this->_productListHelper = $productListHelper;
|
||||
$this->_wpHelper = $wpHelper;
|
||||
$this->_attributeOptions = $attributeOptions;
|
||||
$this->_registry = $registry;
|
||||
$this->swatchHelper = $swatchHelper;
|
||||
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();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function isAjaxScrollToTop()
|
||||
{
|
||||
return $this->_wpHelper->isAjaxScrollToTopEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function isAutoClose()
|
||||
{
|
||||
return $this->_wpHelper->isAutoClose();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function noOfColumns() {
|
||||
return $this->_wpHelper->getNoColumns();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function boxHeight() {
|
||||
return $this->_wpHelper->getSlideDownHeight();
|
||||
}
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function filterColumnHeight() {
|
||||
return $this->_wpHelper->getFilterColumnHeight();
|
||||
}
|
||||
|
||||
/**
|
||||
* check if current filter is a category filter
|
||||
*
|
||||
* @param $filter
|
||||
* @return bool
|
||||
*/
|
||||
public function isCategoryFilter($filter)
|
||||
{
|
||||
return ($filter->getRequestVar() == $this->_wpHelper->getCategoryParamLabel()) ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* check if current filter is a rating filter
|
||||
*
|
||||
* @param $filter
|
||||
* @return bool
|
||||
*/
|
||||
public function isRatingFilter($filter)
|
||||
{
|
||||
return ($filter->getRequestVar() == $this->_wpHelper->getRatingParamLabel()) ? 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* set filter tab status
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getActiveFilters() {
|
||||
$stateFilters = $this->_catalogLayer->getState()->getFilters();
|
||||
$stateFilterIds = [];
|
||||
foreach ($stateFilters as $_filter) {
|
||||
if (in_array($_filter->getFilter()->getRequestVar(), [$this->_wpHelper->getCategoryParamLabel(), $this->_wpHelper->getRatingParamLabel()])) {
|
||||
continue;
|
||||
}
|
||||
$dataAttrId = $_filter->getFilter()->getAttributeModel()->getAttributeId();
|
||||
$stateFilterIds[] = $dataAttrId;
|
||||
}
|
||||
$filters = $this->getFilters();
|
||||
$activeFilters = [];
|
||||
$ctr = 0;
|
||||
$isSlideDownMode = ($this->_wpHelper->getSidebarStyle() == 2 ) ? true : false;
|
||||
foreach($filters as $k => $filter) {
|
||||
|
||||
if($filter->getRequestVar() == $this->_wpHelper->getCategoryParamLabel() && !$isSlideDownMode) {
|
||||
if(($filter->getItemsCount() > 0) && $this->_wpHelper->showCategoryFilterAs()) {
|
||||
|
||||
$activeFilters[] = $ctr; $ctr++;
|
||||
}
|
||||
continue;
|
||||
} else {
|
||||
|
||||
if($filter->getItemsCount() > 0) {
|
||||
|
||||
if($isSlideDownMode) {
|
||||
$activeFilters[] = $ctr;
|
||||
$ctr++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if($filter->getRequestVar() == $this->_wpHelper->getRatingParamLabel()) {
|
||||
if($this->_wpHelper->getRatingFilterDisplay() == '1') $activeFilters[] = $ctr;
|
||||
if($filter->getItemsCount()) $ctr++;
|
||||
continue;
|
||||
}
|
||||
$attributeId = $filter->getAttributeModel()->getAttributeId();
|
||||
$categoryVisibility = $this->getCategoryVisibility($attributeId);
|
||||
if(!$categoryVisibility) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if($attributeId) {
|
||||
$wpOptions = $this->getWpAttributeOptions($attributeId);
|
||||
if($wpOptions->getData()) {
|
||||
|
||||
if($wpOptions->getDisplayOption() == '1' || $wpOptions->getDisplayOption() == '2') {
|
||||
$activeFilters[] = $ctr;
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->swatchHelper->isSwatchAttribute($filter->getAttributeModel())) {
|
||||
if($wpOptions->getDisplayOption() == '1') {
|
||||
$activeFilters[] = $ctr;
|
||||
}
|
||||
}
|
||||
|
||||
if (in_array($attributeId, $stateFilterIds) && $wpOptions->getKeepOpenAfterFilter()) {
|
||||
$activeFilters[] = $ctr;
|
||||
}
|
||||
}
|
||||
$ctr++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$activeFilters = array_unique($activeFilters);
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function getCategoryVisibility($attributeId = false)
|
||||
{
|
||||
if(!$attributeId) {
|
||||
return true;
|
||||
}
|
||||
$visibility = true;
|
||||
$category = $this->_registry->registry('current_category');
|
||||
if ($attributeId > 0 && $category) {
|
||||
$currentCatId = $category->getId();
|
||||
$categoryVisibility = $this->getWpAttributeOptions($attributeId)->getCategoryVisibility();
|
||||
$categoriesIds = $this->getWpAttributeOptions($attributeId)->getCategoryIds() ?? '';
|
||||
$categoriesArr = explode(',', $categoriesIds);
|
||||
|
||||
if ($categoryVisibility == 1) {
|
||||
if (in_array($currentCatId, $categoriesArr)) {
|
||||
$visibility = true;
|
||||
} else {
|
||||
$visibility = false;
|
||||
}
|
||||
}
|
||||
|
||||
if ($categoryVisibility == 2) {
|
||||
if (in_array($currentCatId, $categoriesArr)) {
|
||||
$visibility = false;
|
||||
} else {
|
||||
$visibility = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $visibility;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,370 @@
|
||||
<?php
|
||||
/**
|
||||
* @category WeltPixel
|
||||
* @package WeltPixel_LayeredNavigation
|
||||
* @copyright Copyright (c) 2018 Weltpixel
|
||||
* @author Weltpixel TEAM
|
||||
*/
|
||||
|
||||
namespace WeltPixel\LayeredNavigation\Block\Navigation;
|
||||
|
||||
use Magento\Framework\App\ProductMetadataInterface;
|
||||
use Magento\Framework\View\Element\Template;
|
||||
use Magento\Catalog\Model\Layer\Filter\FilterInterface;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $maxPrice;
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $minPrice;
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $maxPriceX;
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $minPriceX;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Registry
|
||||
*/
|
||||
protected $_registry;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Pricing\PriceCurrencyInterface
|
||||
*/
|
||||
protected $_currency;
|
||||
|
||||
/**
|
||||
* @var \Magento\Theme\Block\Html\Pager
|
||||
*/
|
||||
private $htmlPagerBlock;
|
||||
|
||||
/**
|
||||
* @var ProductMetadataInterface
|
||||
*/
|
||||
protected $productMetadata;
|
||||
|
||||
/**
|
||||
* FilterRenderer constructor.
|
||||
* @param ProductMetadataInterface $productMetadata
|
||||
* @param \WeltPixel\LayeredNavigation\Helper\Data $wpHelper
|
||||
* @param \WeltPixel\LayeredNavigation\Model\AttributeOptions $attributeOptions
|
||||
* @param \Magento\Framework\Registry $registry
|
||||
* @param \Magento\Framework\Pricing\PriceCurrencyInterface $currency
|
||||
* @param \Magento\Theme\Block\Html\Pager $htmlPagerBlock
|
||||
* @param Template\Context $context
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(
|
||||
ProductMetadataInterface $productMetadata,
|
||||
\WeltPixel\LayeredNavigation\Helper\Data $wpHelper,
|
||||
\WeltPixel\LayeredNavigation\Model\AttributeOptions $attributeOptions,
|
||||
\Magento\Framework\Registry $registry,
|
||||
\Magento\Framework\Pricing\PriceCurrencyInterface $currency,
|
||||
\Magento\Theme\Block\Html\Pager $htmlPagerBlock,
|
||||
Template\Context $context,
|
||||
array $data = []
|
||||
)
|
||||
{
|
||||
$this->productMetadata = $productMetadata;
|
||||
$this->_wpHelper = $wpHelper;
|
||||
$this->_attributeOptions = $attributeOptions;
|
||||
$this->_registry = $registry;
|
||||
$this->_currency = $currency;
|
||||
$this->htmlPagerBlock = $htmlPagerBlock;
|
||||
parent::__construct($context, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FilterInterface $filter
|
||||
* @return string
|
||||
*/
|
||||
public function render(FilterInterface $filter)
|
||||
{
|
||||
$this->filter = $filter;
|
||||
|
||||
if ($this->_wpHelper->isEnabled()) {
|
||||
if ($filter->getRequestVar() == 'price' && $this->_wpHelper->getPriceIsSliderMode()) {
|
||||
$collection = $this->filter->getLayer()->getProductCollection();
|
||||
$currentCatId = ($this->_registry->registry('current_category')) ? $this->_registry->registry('current_category')->getId() : "";
|
||||
$basePriceData = $this->_registry->registry('price_filter');
|
||||
|
||||
if (is_array($basePriceData) && $currentCatId && array_key_exists($currentCatId, $basePriceData)) {
|
||||
$this->minPriceX = $basePriceData[$currentCatId]['min'];
|
||||
$this->maxPriceX = $basePriceData[$currentCatId]['max'];
|
||||
} else {
|
||||
$this->minPriceX = ($this->minPriceX == null) ? $collection->getMinPrice() : $this->minPriceX;
|
||||
$this->maxPriceX = ($this->maxPriceX == null) ? $collection->getMaxPrice() : $this->maxPriceX;
|
||||
}
|
||||
$this->minPrice = ($this->minPrice == null) ? $collection->getMinPrice() : $this->minPrice;
|
||||
$this->maxPrice = ($this->maxPrice == null) ? $collection->getMaxPrice() : $this->maxPrice;
|
||||
$this->setTemplate('layer/slider.phtml');
|
||||
} else {
|
||||
$this->setTemplate('layer/filter.phtml');
|
||||
}
|
||||
}
|
||||
|
||||
$html = parent::render($filter);
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getPriceConfigData()
|
||||
{
|
||||
|
||||
$range = [
|
||||
'minX' => floor($this->minPriceX),
|
||||
'maxX' => ceil($this->maxPriceX),
|
||||
'min' => floor($this->minPrice),
|
||||
'max' => ceil($this->maxPrice),
|
||||
'step' => 1,
|
||||
'currency' => $this->_currency->getCurrencySymbol()
|
||||
];
|
||||
|
||||
return $range;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function priceIsInputType()
|
||||
{
|
||||
return $this->_wpHelper->canShowPriceInput();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getSliderApplyUrl()
|
||||
{
|
||||
$params = [
|
||||
'price' => $this->minPrice . '-' . $this->maxPrice,
|
||||
$this->htmlPagerBlock->getPageVarName() => null
|
||||
];
|
||||
$urlParams = [];
|
||||
$urlParams['_current'] = true;
|
||||
$urlParams['_escape'] = false;
|
||||
$urlParams['_use_rewrite'] = true;
|
||||
$urlParams['_query'] = $params;
|
||||
return $this->getUrl('*/*/*', $urlParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getPriceStep()
|
||||
{
|
||||
$step = $this->_wpHelper->getPriceRangeStep();
|
||||
return ($step > $this->maxPrice) ? $this->maxPrice : $step;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $filter
|
||||
*/
|
||||
public function setAttributeId($filter)
|
||||
{
|
||||
if ($filter->getRequestVar() == $this->_wpHelper->getCategoryParamLabel()) {
|
||||
$this->_attributeId = $this->_wpHelper->getCategoryParamLabel();
|
||||
} elseif ($filter->getRequestVar() == $this->_wpHelper->getRatingParamLabel()) {
|
||||
$this->_attributeId = $this->_wpHelper->getRatingParamLabel();
|
||||
} else {
|
||||
$this->_attributeId = $filter->getAttributeModel()->getAttributeId();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 == $this->_wpHelper->getRatingParamLabel()) {
|
||||
return $this->_wpHelper->getRatingFilterCounter();
|
||||
} elseif ($this->_attributeId == $this->_wpHelper->getCategoryParamLabel()) {
|
||||
return '';
|
||||
} else {
|
||||
$attributeOptions = $this->getWpAttributeOptions();
|
||||
if ($attributeOptions) {
|
||||
return $attributeOptions->getShowQuantity();
|
||||
}
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* return the 'Is Multiselect' attribute configuration value
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getIsMultiSelect()
|
||||
{
|
||||
if ($this->_attributeId == $this->_wpHelper->getRatingParamLabel()) {
|
||||
return $this->_wpHelper->isRatingFilterMultiselect();
|
||||
} elseif ($this->_attributeId == $this->_wpHelper->getCategoryParamLabel()) {
|
||||
return '';
|
||||
} else {
|
||||
$attributeOptions = $this->getWpAttributeOptions();
|
||||
if ($attributeOptions) {
|
||||
return $attributeOptions->getIsMultiselect();
|
||||
}
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* return the 'Instant Search' attribute configuration value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function canShowInstantSearch()
|
||||
{
|
||||
if ($this->_attributeId > 0) {
|
||||
$attributeOptions = $this->getWpAttributeOptions();
|
||||
if ($attributeOptions) {
|
||||
return $attributeOptions->getInstantSearch();
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* return the 'Instant Search Mobile' attribute configuration value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function canShowInstantSearchMobile()
|
||||
{
|
||||
if ($this->_attributeId > 0) {
|
||||
$attributeOptions = $this->getWpAttributeOptions();
|
||||
if ($attributeOptions) {
|
||||
return $attributeOptions->getInstantSearchMobile();
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getCategoryParamLabel()
|
||||
{
|
||||
return $this->_wpHelper->getCategoryParamLabel();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getRatingParamLabel()
|
||||
{
|
||||
return $this->_wpHelper->getRatingParamLabel();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getSliderJsWidget()
|
||||
{
|
||||
$jsSliderWidget = 'jquery/ui-modules/widgets/slider';
|
||||
$magentoVersion = $this->productMetadata->getVersion();
|
||||
if (version_compare($magentoVersion, '2.4.4', '<')) {
|
||||
$jsSliderWidget = 'jquery-ui-modules/slider';
|
||||
}
|
||||
|
||||
return $jsSliderWidget;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
<?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 array
|
||||
*/
|
||||
protected $ratesStep = [
|
||||
'0-20' => 1,
|
||||
'21-40' => 2,
|
||||
'41-60' => 3,
|
||||
'61-80' => 4,
|
||||
'81-100' => 5,
|
||||
];
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
if($this->_wpHelper->isEnabled()) {
|
||||
$this->_template = 'WeltPixel_LayeredNavigation::layer/state.phtml';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $filter
|
||||
* @return string
|
||||
*/
|
||||
public function getRateFilterLabel($filter) {
|
||||
$selectedValue = $filter->getValue();
|
||||
$countStars = 1;
|
||||
if(is_array($selectedValue)) {
|
||||
$val = $selectedValue[0].'-'.$selectedValue[1];
|
||||
$countStars = $this->ratesStep[$val];
|
||||
} else {
|
||||
$valArr = explode('-', $selectedValue);
|
||||
$val = $valArr[0].'-'.$valArr[1];
|
||||
$countStars = $this->ratesStep[$val];
|
||||
}
|
||||
$label = '<div class="rating-summary" style="display: inline-block;margin-top: -5px;">
|
||||
<div class="rating-result" title="up to '.$countStars*20 .'%"">
|
||||
<span style="width:'.$countStars*20 .'%"></span>
|
||||
</div>
|
||||
</div>';
|
||||
|
||||
return $label;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getCategoryParamLabel() {
|
||||
return $this->_wpHelper->getCategoryParamLabel();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getRatingParamLabel() {
|
||||
return $this->_wpHelper->getRatingParamLabel();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user