_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; } }