Produced by Araxis Merge on 2021-05-13 09:08:39 +0000. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
| # | Location | File | Last Modified |
|---|---|---|---|
| 1 | /Applications/Ampps/www/Porto 3.2.2/Theme Files/Magento 2.x/Porto Theme/app/code/Mageplaza/LayeredNavigation/Model/Layer/Filter | Attribute.php | 2020-06-26 11:11:14 +0000 |
| 2 | /Applications/Ampps/www/Porto v4.0.0/Theme Files/Magento 2.x/Porto Theme/app/code/Mageplaza/LayeredNavigation/Model/Layer/Filter | Attribute.php | 2020-06-26 11:11:14 +0000 |
| Description | Between Files 1 and 2 | |
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 1 | 376 |
| Changed | 0 | 0 |
| Inserted | 0 | 0 |
| Removed | 0 | 0 |
| Whitespace | Consecutive whitespace is treated as a single space |
|---|---|
| Character case | Differences in character case are significant |
| Line endings | Differences in line endings (CR and LF characters) are ignored |
| CR/LF characters | Not shown in the comparison detail |
| Active line-pairing rules |
No regular expressions were active.
| 1 | <?php | 1 | <?php | |||
| 2 | /** | 2 | /** | |||
| 3 | * Mageplaza | 3 | * Mageplaza | |||
| 4 | * | 4 | * | |||
| 5 | * NOTICE OF LICENSE | 5 | * NOTICE OF LICENSE | |||
| 6 | * | 6 | * | |||
| 7 | * This source file is subject to the Mageplaza.com license that is | 7 | * This source file is subject to the Mageplaza.com license that is | |||
| 8 | * available through the world-wide-web at this URL: | 8 | * available through the world-wide-web at this URL: | |||
| 9 | * https://www.mageplaza.com/LICENSE.txt | 9 | * https://www.mageplaza.com/LICENSE.txt | |||
| 10 | * | 10 | * | |||
| 11 | * DISCLAIMER | 11 | * DISCLAIMER | |||
| 12 | * | 12 | * | |||
| 13 | * Do not edit or add to this file if you wish to upgrade this extension to newer | 13 | * Do not edit or add to this file if you wish to upgrade this extension to newer | |||
| 14 | * version in the future. | 14 | * version in the future. | |||
| 15 | * | 15 | * | |||
| 16 | * @category Mageplaza | 16 | * @category Mageplaza | |||
| 17 | * @package Mageplaza_LayeredNavigation | 17 | * @package Mageplaza_LayeredNavigation | |||
| 18 | * @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/) | 18 | * @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/) | |||
| 19 | * @license https://www.mageplaza.com/LICENSE.txt | 19 | * @license https://www.mageplaza.com/LICENSE.txt | |||
| 20 | */ | 20 | */ | |||
| 21 | 21 | |||||
| 22 | namespace Mageplaza\LayeredNavigation\Model\Layer\Filter; | 22 | namespace Mageplaza\LayeredNavigation\Model\Layer\Filter; | |||
| 23 | 23 | |||||
| 24 | use Magento\Catalog\Model\Layer as LayerCatalog; | 24 | use Magento\Catalog\Model\Layer as LayerCatalog; | |||
| 25 | use Magento\Catalog\Model\Layer\Filter\Item\DataBuilder; | 25 | use Magento\Catalog\Model\Layer\Filter\Item\DataBuilder; | |||
| 26 | use Magento\Catalog\Model\Layer\Filter\ItemFactory; | 26 | use Magento\Catalog\Model\Layer\Filter\ItemFactory; | |||
| 27 | use Magento\CatalogSearch\Model\Layer\Filter\Attribute as AbstractFilter; | 27 | use Magento\CatalogSearch\Model\Layer\Filter\Attribute as AbstractFilter; | |||
| 28 | use Magento\Framework\App\RequestInterface; | 28 | use Magento\Framework\App\RequestInterface; | |||
| 29 | use Magento\Framework\Filter\StripTags; | 29 | use Magento\Framework\Filter\StripTags; | |||
| 30 | use Magento\Store\Model\StoreManagerInterface; | 30 | use Magento\Store\Model\StoreManagerInterface; | |||
| 31 | use Mageplaza\LayeredNavigation\Helper\Data as LayerHelper; | 31 | use Mageplaza\LayeredNavigation\Helper\Data as LayerHelper; | |||
| 32 | use Mageplaza\LayeredNavigation\Model\ResourceModel\Fulltext\Collection; | 32 | use Mageplaza\LayeredNavigation\Model\ResourceModel\Fulltext\Collection; | |||
| 33 | 33 | |||||
| 34 | /** | 34 | /** | |||
| 35 | * Class Attribute | 35 | * Class Attribute | |||
| 36 | * @package Mageplaza\LayeredNavigation\Model\Layer\Filter | 36 | * @package Mageplaza\LayeredNavigation\Model\Layer\Filter | |||
| 37 | */ | 37 | */ | |||
| 38 | class Attribute extends AbstractFilter | 38 | class Attribute extends AbstractFilter | |||
| 39 | { | 39 | { | |||
| 40 | /** @var LayerHelper */ | 40 | /** @var LayerHelper */ | |||
| 41 | protected $_moduleHelper; | 41 | protected $_moduleHelper; | |||
| 42 | 42 | |||||
| 43 | /** @var bool Is Filterable Flag */ | 43 | /** @var bool Is Filterable Flag */ | |||
| 44 | protected $_isFilter = true; | 44 | protected $_isFilter = true; | |||
| 45 | 45 | |||||
| 46 | /** @var StripTags */ | 46 | /** @var StripTags */ | |||
| 47 | private $tagFilter; | 47 | private $tagFilter; | |||
| 48 | 48 | |||||
| 49 | /** | 49 | /** | |||
| 50 | * Attribute constructor. | 50 | * Attribute constructor. | |||
| 51 | * | 51 | * | |||
| 52 | * @param ItemFactory $filterItemFactory | 52 | * @param ItemFactory $filterItemFactory | |||
| 53 | * @param StoreManagerInterface $storeManager | 53 | * @param StoreManagerInterface $storeManager | |||
| 54 | * @param LayerCatalog $layer | 54 | * @param LayerCatalog $layer | |||
| 55 | * @param DataBuilder $itemDataBuilder | 55 | * @param DataBuilder $itemDataBuilder | |||
| 56 | * @param StripTags $tagFilter | 56 | * @param StripTags $tagFilter | |||
| 57 | * @param LayerHelper $moduleHelper | 57 | * @param LayerHelper $moduleHelper | |||
| 58 | * @param array $data | 58 | * @param array $data | |||
| 59 | */ | 59 | */ | |||
| 60 | public function __construct( | 60 | public function __construct( | |||
| 61 | ItemFactory $filterItemFactory, | 61 | ItemFactory $filterItemFactory, | |||
| 62 | StoreManagerInterface $storeManager, | 62 | StoreManagerInterface $storeManager, | |||
| 63 | LayerCatalog $layer, | 63 | LayerCatalog $layer, | |||
| 64 | DataBuilder $itemDataBuilder, | 64 | DataBuilder $itemDataBuilder, | |||
| 65 | StripTags $tagFilter, | 65 | StripTags $tagFilter, | |||
| 66 | LayerHelper $moduleHelper, | 66 | LayerHelper $moduleHelper, | |||
| 67 | array $data = [] | 67 | array $data = [] | |||
| 68 | ) { | 68 | ) { | |||
| 69 | $this->tagFilter = $tagFilter; | 69 | $this->tagFilter = $tagFilter; | |||
| 70 | $this->_moduleHelper = $moduleHelper; | 70 | $this->_moduleHelper = $moduleHelper; | |||
| 71 | 71 | |||||
| 72 | parent::__construct( | 72 | parent::__construct( | |||
| 73 | $filterItemFactory, | 73 | $filterItemFactory, | |||
| 74 | $storeManager, | 74 | $storeManager, | |||
| 75 | $layer, | 75 | $layer, | |||
| 76 | $itemDataBuilder, | 76 | $itemDataBuilder, | |||
| 77 | $tagFilter, | 77 | $tagFilter, | |||
| 78 | $data | 78 | $data | |||
| 79 | ); | 79 | ); | |||
| 80 | } | 80 | } | |||
| 81 | 81 | |||||
| 82 | /** | 82 | /** | |||
| 83 | * @inheritdoc | 83 | * @inheritdoc | |||
| 84 | */ | 84 | */ | |||
| 85 | public function apply(RequestInterface $request) | 85 | public function apply(RequestInterface $request) | |||
| 86 | { | 86 | { | |||
| 87 | if (!$this->_moduleHelper->isEnabled()) { | 87 | if (!$this->_moduleHelper->isEnabled()) { | |||
| 88 | return parent::apply($request); | 88 | return parent::apply($request); | |||
| 89 | } | 89 | } | |||
| 90 | 90 | |||||
| 91 | $attributeValue = $request->getParam($this->_requestVar); | 91 | $attributeValue = $request->getParam($this->_requestVar); | |||
| 92 | if (empty($attributeValue)) { | 92 | if (empty($attributeValue)) { | |||
| 93 | $this->_isFilter = false; | 93 | $this->_isFilter = false; | |||
| 94 | 94 | |||||
| 95 | return $this; | 95 | return $this; | |||
| 96 | } | 96 | } | |||
| 97 | 97 | |||||
| 98 | $attributeValue = explode(',', $attributeValue); | 98 | $attributeValue = explode(',', $attributeValue); | |||
| 99 | 99 | |||||
| 100 | $attribute = $this->getAttributeModel(); | 100 | $attribute = $this->getAttributeModel(); | |||
| 101 | /** @var \Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection $productCollection */ | 101 | /** @var \Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection $productCollection */ | |||
| 102 | $productCollection = $this->getLayer() | 102 | $productCollection = $this->getLayer() | |||
| 103 | ->getProductCollection(); | 103 | ->getProductCollection(); | |||
| 104 | if (count($attributeValue) > 1) { | 104 | if (count($attributeValue) > 1) { | |||
| 105 | $productCollection->addFieldToFilter($attribute->getAttributeCode(), ['in' => $attributeValue]); | 105 | $productCollection->addFieldToFilter($attribute->getAttributeCode(), ['in' => $attributeValue]); | |||
| 106 | } else { | 106 | } else { | |||
| 107 | $productCollection->addFieldToFilter($attribute->getAttributeCode(), $attributeValue[0]); | 107 | $productCollection->addFieldToFilter($attribute->getAttributeCode(), $attributeValue[0]); | |||
| 108 | } | 108 | } | |||
| 109 | 109 | |||||
| 110 | $state = $this->getLayer()->getState(); | 110 | $state = $this->getLayer()->getState(); | |||
| 111 | foreach ($attributeValue as $value) { | 111 | foreach ($attributeValue as $value) { | |||
| 112 | $label = $this->getOptionText($value); | 112 | $label = $this->getOptionText($value); | |||
| 113 | $state->addFilter($this->_createItem($label, $value)); | 113 | $state->addFilter($this->_createItem($label, $value)); | |||
| 114 | } | 114 | } | |||
| 115 | 115 | |||||
| 116 | return $this; | 116 | return $this; | |||
| 117 | } | 117 | } | |||
| 118 | 118 | |||||
| 119 | /** | 119 | /** | |||
| 120 | * @inheritdoc | 120 | * @inheritdoc | |||
| 121 | */ | 121 | */ | |||
| 122 | protected function _getItemsData() | 122 | protected function _getItemsData() | |||
| 123 | { | 123 | { | |||
| 124 | if (!$this->_moduleHelper->isEnabled()) { | 124 | if (!$this->_moduleHelper->isEnabled()) { | |||
| 125 | return parent::_getItemsData(); | 125 | return parent::_getItemsData(); | |||
| 126 | } | 126 | } | |||
| 127 | 127 | |||||
| 128 | $attribute = $this->getAttributeModel(); | 128 | $attribute = $this->getAttributeModel(); | |||
| 129 | 129 | |||||
| 130 | /** @var Collection $productCollection */ | 130 | /** @var Collection $productCollection */ | |||
| 131 | $productCollection = $this->getLayer()->getProductCollection(); | 131 | $productCollection = $this->getLayer()->getProductCollection(); | |||
| 132 | 132 | |||||
| 133 | if ($this->_isFilter) { | 133 | if ($this->_isFilter) { | |||
| 134 | $productCollection = $productCollection->getCollectionClone() | 134 | $productCollection = $productCollection->getCollectionClone() | |||
| 135 | ->removeAttributeSearch($attribute->getAttributeCode()); | 135 | ->removeAttributeSearch($attribute->getAttributeCode()); | |||
| 136 | } | 136 | } | |||
| 137 | 137 | |||||
| 138 | $optionsFacetedData = $productCollection->getFacetedData($attribute->getAttributeCode()); | 138 | $optionsFacetedData = $productCollection->getFacetedData($attribute->getAttributeCode()); | |||
| 139 | 139 | |||||
| 140 | if (count($optionsFacetedData) === 0 | 140 | if (count($optionsFacetedData) === 0 | |||
| 141 | && $this->getAttributeIsFilterable($attribute) !== static::ATTRIBUTE_OPTIONS_ONLY_WITH_RESULTS | 141 | && $this->getAttributeIsFilterable($attribute) !== static::ATTRIBUTE_OPTIONS_ONLY_WITH_RESULTS | |||
| 142 | ) { | 142 | ) { | |||
| 143 | return $this->itemDataBuilder->build(); | 143 | return $this->itemDataBuilder->build(); | |||
| 144 | } | 144 | } | |||
| 145 | 145 | |||||
| 146 | $productSize = $productCollection->getSize(); | 146 | $productSize = $productCollection->getSize(); | |||
| 147 | $itemData = []; | 147 | $itemData = []; | |||
| 148 | $checkCount = false; | 148 | $checkCount = false; | |||
| 149 | 149 | |||||
| 150 | $options = $attribute->getFrontend()->getSelectOptions(); | 150 | $options = $attribute->getFrontend()->getSelectOptions(); | |||
| 151 | foreach ($options as $option) { | 151 | foreach ($options as $option) { | |||
| 152 | if (empty($option['value'])) { | 152 | if (empty($option['value'])) { | |||
| 153 | continue; | 153 | continue; | |||
| 154 | } | 154 | } | |||
| 155 | 155 | |||||
| 156 | $value = $option['value']; | 156 | $value = $option['value']; | |||
| 157 | 157 | |||||
| 158 | $count = isset($optionsFacetedData[$value]['count']) | 158 | $count = isset($optionsFacetedData[$value]['count']) | |||
| 159 | ? (int) $optionsFacetedData[$value]['count'] | 159 | ? (int) $optionsFacetedData[$value]['count'] | |||
| 160 | : 0; | 160 | : 0; | |||
| 161 | 161 | |||||
| 162 | // Check filter type | 162 | // Check filter type | |||
| 163 | if ($this->getAttributeIsFilterable($attribute) === static::ATTRIBUTE_OPTIONS_ONLY_WITH_RESULTS | 163 | if ($this->getAttributeIsFilterable($attribute) === static::ATTRIBUTE_OPTIONS_ONLY_WITH_RESULTS | |||
| 164 | && (!$this->_moduleHelper->getFilterModel()->isOptionReducesResults($this, $count, $productSize)) | 164 | && (!$this->_moduleHelper->getFilterModel()->isOptionReducesResults($this, $count, $productSize)) | |||
| 165 | ) { | 165 | ) { | |||
| 166 | continue; | 166 | continue; | |||
| 167 | } | 167 | } | |||
| 168 | 168 | |||||
| 169 | if ($count > 0) { | 169 | if ($count > 0) { | |||
| 170 | $checkCount = true; | 170 | $checkCount = true; | |||
| 171 | } | 171 | } | |||
| 172 | 172 | |||||
| 173 | $itemData[] = [ | 173 | $itemData[] = [ | |||
| 174 | 'label' => $this->tagFilter->filter($option['label']), | 174 | 'label' => $this->tagFilter->filter($option['label']), | |||
| 175 | 'value' => $value, | 175 | 'value' => $value, | |||
| 176 | 'count' => $count | 176 | 'count' => $count | |||
| 177 | ]; | 177 | ]; | |||
| 178 | } | 178 | } | |||
| 179 | 179 | |||||
| 180 | if ($checkCount) { | 180 | if ($checkCount) { | |||
| 181 | foreach ($itemData as $item) { | 181 | foreach ($itemData as $item) { | |||
| 182 | $this->itemDataBuilder->addItemData($item['label'], $item['value'], $item['count']); | 182 | $this->itemDataBuilder->addItemData($item['label'], $item['value'], $item['count']); | |||
| 183 | } | 183 | } | |||
| 184 | } | 184 | } | |||
| 185 | 185 | |||||
| 186 | return $this->itemDataBuilder->build(); | 186 | return $this->itemDataBuilder->build(); | |||
| 187 | } | 187 | } | |||
| 188 | } | 188 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993–2019 Araxis Ltd (www.araxis.com). All rights reserved.