Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected function _initItems()
- {
- parent::_initItems();
- foreach ($this->_items as $item) {
- $applyValue = $item->getLabel();
- if (($valuePos = array_search($applyValue, $this->currentFilterValue)) !== false) {
- $item->setIsSelected(true);
- $applyValue = $this->currentFilterValue;
- unset($applyValue[$valuePos]);
- } else {
- $applyValue = array_merge($this->currentFilterValue, [$applyValue]);
- }
- $item->setApplyFilterValue(array_values($applyValue));
- }
- return $this;
- }
- protected function _getItemsData()
- {
- $attribute = $this->getAttributeModel();
- /** @var MagentoCatalogSearchModelResourceModelFulltextCollection $productCollection */
- $productCollection = $this->getLayer()->getProductCollection();
- $optionsFacetedData = $productCollection->getFacetedData($this->getFilterField());
- $items = [];
- $attributeCode = $attribute->getAttributeCode();
- if ($attribute->getFrontendInput() == 'multiselect') {
- //echo '1<br/>';
- if($this->_coreRegistry->registry('current_category')) {
- // echo '2<br/>';
- $catId = $this->_coreRegistry->registry('current_category')->getId();
- $facetSession = $this->_catalogSession->getData('multiselect_facets');
- if(isset($facetSession[$catId][$attributeCode]) && isset($_GET[$attributeCode])) {;
- $optionsFacetedData = $facetSession[$catId][$attributeCode];
- } else {
- // echo '4<br/>';
- $optionsFacetedData = $productCollection->getFacetedData($this->getFilterField());
- // $optionsFacetedData returning all attributes after filter
- $facetArray = $facetSession;
- $facetArray[$catId][$attributeCode] = $optionsFacetedData;
- $this->_catalogSession->setData('multiselect_facets', $facetArray);
- }
- } else {
- $catId = 'search';
- $facetSession = $this->_catalogSession->getData('multiselect_facets');
- if(isset($facetSession[$catId][$attributeCode]) && isset($_GET[$attributeCode])) {
- $optionsFacetedData = $facetSession[$catId][$attributeCode];
- } else {
- $optionsFacetedData = $productCollection->getFacetedData($this->getFilterField());
- $facetArray = $facetSession;
- $facetArray[$catId][$attributeCode] = $optionsFacetedData;
- $this->_catalogSession->setData('multiselect_facets', $facetArray);
- }
- }
- }
- if (isset($optionsFacetedData['__other_docs'])) {
- $this->hasMoreItems = $optionsFacetedData['__other_docs']['count'] > 0;
- unset($optionsFacetedData['__other_docs']);
- }
- foreach ($optionsFacetedData as $value => $data) {
- $items[$value] = [
- 'label' => $this->tagFilter->filter($value),
- 'value' => $value,
- 'count' => $data['count'],
- ];
- }
- $items = $this->addOptionsData($items);
- return $items;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement