63. Araxis Merge File Comparison Report

Produced by Araxis Merge on 2023-03-13 03:00:43 +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.

63.1 Files compared

#LocationFileLast Modified
1Porto v4.0.4/Porto Theme/app/code/Mageplaza/LayeredNavigation/Model/Layer/FilterPrice.php2022-04-22 07:34:10 +0000
2Porto v4.0.5/Porto Theme/app/code/Mageplaza/LayeredNavigation/Model/Layer/FilterPrice.php2022-12-08 01:34:28 +0000

63.2 Comparison summary

DescriptionBetween
Files 1 and 2
Text BlocksLines
Unchanged2524
Changed112
Inserted00
Removed00

63.3 Comparison options

WhitespaceConsecutive whitespace is treated as a single space
Character caseDifferences in character case are significant
Line endingsDifferences in line endings (CR and LF characters) are ignored
CR/LF charactersNot shown in the comparison detail
Active line-pairing rules

63.4 Active regular expressions

No regular expressions were active.

63.5 Comparison detail

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\DataProvider\PriceFactory; 25 use Magento\Catalog\Model\Layer\Filter\DataProvider\PriceFactory;
26 use Magento\Catalog\Model\Layer\Filter\Dynamic\AlgorithmFactory; 26 use Magento\Catalog\Model\Layer\Filter\Dynamic\AlgorithmFactory;
27 use Magento\Catalog\Model\Layer\Filter\Item\DataBuilder; 27 use Magento\Catalog\Model\Layer\Filter\Item\DataBuilder;
28 use Magento\Catalog\Model\Layer\Filter\ItemFactory; 28 use Magento\Catalog\Model\Layer\Filter\ItemFactory;
29 use Magento\Catalog\Model\ResourceModel\Layer\Filter\Price as CatalogPrice; 29 use Magento\Catalog\Model\ResourceModel\Layer\Filter\Price as CatalogPrice;
30 use Magento\CatalogSearch\Model\Layer\Filter\Price as AbstractFilter; 30 use Magento\CatalogSearch\Model\Layer\Filter\Price as AbstractFilter;
31 use Magento\Customer\Model\Session; 31 use Magento\Customer\Model\Session;
32 use Magento\Framework\App\RequestInterface; 32 use Magento\Framework\App\RequestInterface;
33 use Magento\Framework\Exception\LocalizedException; 33 use Magento\Framework\Exception\LocalizedException;
34 use Magento\Framework\Exception\StateException; 34 use Magento\Framework\Exception\StateException;
35 use Magento\Framework\Pricing\PriceCurrencyInterface; 35 use Magento\Framework\Pricing\PriceCurrencyInterface;
36 use Magento\Framework\Search\Dynamic\Algorithm; 36 use Magento\Framework\Search\Dynamic\Algorithm;
37 use Magento\Store\Model\StoreManagerInterface; 37 use Magento\Store\Model\StoreManagerInterface;
38 use Magento\Tax\Helper\Data as TaxHelper; 38 use Magento\Tax\Helper\Data as TaxHelper;
39 use Mageplaza\LayeredNavigation\Helper\Data as LayerHelper; 39 use Mageplaza\LayeredNavigation\Helper\Data as LayerHelper;
40 use Mageplaza\LayeredNavigation\Model\ResourceModel\Fulltext\Collection; 40 use Mageplaza\LayeredNavigation\Model\ResourceModel\Fulltext\Collection;
41  41 
42 /** 42 /**
43  * Class Price 43  * Class Price
44  * @package Mageplaza\LayeredNavigation\Model\Layer\Filter 44  * @package Mageplaza\LayeredNavigation\Model\Layer\Filter
45  */ 45  */
46 class Price extends AbstractFilter 46 class Price extends AbstractFilter
47 { 47 {
48     /** @var LayerHelper */ 48     /** @var LayerHelper */
49     protected $_moduleHelper; 49     protected $_moduleHelper;
50  50 
51     /** @var array|null Filter value */ 51     /** @var array|null Filter value */
52     protected $_filterVal = null; 52     protected $_filterVal = null;
53  53 
54     /** @var TaxHelper */ 54     /** @var TaxHelper */
55     protected $_taxHelper; 55     protected $_taxHelper;
56  56 
57     /** @var LayerCatalog\Filter\DataProvider\Price */ 57     /** @var LayerCatalog\Filter\DataProvider\Price */
58     private $dataProvider; 58     private $dataProvider;
59  59 
60     /** @var PriceCurrencyInterface */ 60     /** @var PriceCurrencyInterface */
61     private $priceCurrency; 61     private $priceCurrency;
62  62 
63     /** 63     /**
64      * @param ItemFactory $filterItemFactory 64      * @param ItemFactory $filterItemFactory
65      * @param StoreManagerInterface $storeManager 65      * @param StoreManagerInterface $storeManager
66      * @param LayerCatalog $layer 66      * @param LayerCatalog $layer
67      * @param DataBuilder $itemDataBuilder 67      * @param DataBuilder $itemDataBuilder
68      * @param CatalogPrice $resource 68      * @param CatalogPrice $resource
69      * @param Session $customerSession 69      * @param Session $customerSession
70      * @param Algorithm $priceAlgorithm 70      * @param Algorithm $priceAlgorithm
71      * @param PriceCurrencyInterface $priceCurrency 71      * @param PriceCurrencyInterface $priceCurrency
72      * @param AlgorithmFactory $algorithmFactory 72      * @param AlgorithmFactory $algorithmFactory
73      * @param PriceFactory $dataProviderFactory 73      * @param PriceFactory $dataProviderFactory
74      * @param TaxHelper $taxHelper 74      * @param TaxHelper $taxHelper
75      * @param LayerHelper $moduleHelper 75      * @param LayerHelper $moduleHelper
76      * @param array $data 76      * @param array $data
77      */ 77      */
78     public function __construct( 78     public function __construct(
79         ItemFactory $filterItemFactory, 79         ItemFactory $filterItemFactory,
80         StoreManagerInterface $storeManager, 80         StoreManagerInterface $storeManager,
81         LayerCatalog $layer, 81         LayerCatalog $layer,
82         DataBuilder $itemDataBuilder, 82         DataBuilder $itemDataBuilder,
83         CatalogPrice $resource, 83         CatalogPrice $resource,
84         Session $customerSession, 84         Session $customerSession,
85         Algorithm $priceAlgorithm, 85         Algorithm $priceAlgorithm,
86         PriceCurrencyInterface $priceCurrency, 86         PriceCurrencyInterface $priceCurrency,
87         AlgorithmFactory $algorithmFactory, 87         AlgorithmFactory $algorithmFactory,
88         PriceFactory $dataProviderFactory, 88         PriceFactory $dataProviderFactory,
89         TaxHelper $taxHelper, 89         TaxHelper $taxHelper,
90         LayerHelper $moduleHelper, 90         LayerHelper $moduleHelper,
91         array $data = [] 91         array $data = []
92     ) { 92     ) {
93         parent::__construct( 93         parent::__construct(
94             $filterItemFactory, 94             $filterItemFactory,
95             $storeManager, 95             $storeManager,
96             $layer, 96             $layer,
97             $itemDataBuilder, 97             $itemDataBuilder,
98             $resource, 98             $resource,
99             $customerSession, 99             $customerSession,
100             $priceAlgorithm, 100             $priceAlgorithm,
101             $priceCurrency, 101             $priceCurrency,
102             $algorithmFactory, 102             $algorithmFactory,
103             $dataProviderFactory, 103             $dataProviderFactory,
104             $data 104             $data
105         ); 105         );
106  106 
107         $this->priceCurrency = $priceCurrency; 107         $this->priceCurrency = $priceCurrency;
108         $this->dataProvider = $dataProviderFactory->create(['layer' => $this->getLayer()]); 108         $this->dataProvider = $dataProviderFactory->create(['layer' => $this->getLayer()]);
109         $this->_moduleHelper = $moduleHelper; 109         $this->_moduleHelper = $moduleHelper;
110         $this->_taxHelper = $taxHelper; 110         $this->_taxHelper = $taxHelper;
111     } 111     }
112  112 
113     /** 113     /**
114      * @inheritdoc 114      * @inheritdoc
115      */ 115      */
116     public function apply(RequestInterface $request) 116     public function apply(RequestInterface $request)
117     { 117     {
118         if (!$this->_moduleHelper->isEnabled()) { 118         if (!$this->_moduleHelper->isEnabled()) {
119             return parent::apply($request); 119             return parent::apply($request);
120         } 120         }
121  121 
122         /** Filter must be string: $fromPrice-$toPrice */ 122         /** Filter must be string: $fromPrice-$toPrice */
123         $filter = $request->getParam($this->getRequestVar()); 123         $filter = $request->getParam($this->getRequestVar());
124         if (!$filter || is_array($filter)) { 124         if (!$filter || is_array($filter)) {
125             return $this; 125             return $this;
126         } 126         }
127         $filterParams = explode(',', $filter); 127         $filterParams = explode(',', $filter);
128         $filter = $this->dataProvider->validateFilter($filterParams[0]); 128         $filter = $this->dataProvider->validateFilter($filterParams[0]);
129         if (!$filter) { 129         if (!$filter) {
130             return $this; 130             return $this;
131         } 131         }
132  132 
133         $this->dataProvider->setInterval($filter); 133         $this->dataProvider->setInterval($filter);
134         $priorFilters = $this->dataProvider->getPriorFilters($filterParams); 134         $priorFilters = $this->dataProvider->getPriorFilters($filterParams);
135         if ($priorFilters) { 135         if ($priorFilters) {
136             $this->dataProvider->setPriorIntervals($priorFilters); 136             $this->dataProvider->setPriorIntervals($priorFilters);
137         } 137         }
138  138 
139         [$from, $to] = $this->_filterVal = $filter; 139         [$from, $to] = $this->_filterVal = $filter;
140  140 
141         $this->getLayer()->getProductCollection()->addFieldToFilter('price', [ 141         $this->getLayer()->getProductCollection()->addFieldToFilter('price', [
142             'from' => $from / $this->getCurrencyRate(), 142             'from' => $from / $this->getCurrencyRate(),
143             'to' => $to / $this->getCurrencyRate() 143             'to' => $to / $this->getCurrencyRate()
144         ]); 144         ]);
145  145 
146         $this->getLayer()->getState()->addFilter( 146         $this->getLayer()->getState()->addFilter(
147             $this->_createItem($this->_renderRangeLayerLabel(empty($from) ? 0 : $from, $to), $filter) 147             $this->_createItem($this->_renderRangeLayerLabel(empty($from) ? 0 : $from, $to), $filter)
148         ); 148         );
149  149 
150         return $this; 150         return $this;
151     } 151     }
152  152 
153     /** 153     /**
154      * @inheritdoc 154      * @inheritdoc
155      */ 155      */
156     protected function _renderRangeLayerLabel($fromPrice, $toPrice) 156     protected function _renderRangeLayerLabel($fromPrice, $toPrice)
157     { 157     {
158         $formattedFromPrice = $this->priceCurrency->format($fromPrice); 158         $formattedFromPrice = $this->priceCurrency->format($fromPrice);
159         if ($toPrice === '') { 159         if ($toPrice === '') {
160             return __('%1 and above', $formattedFromPrice); 160             return __('%1 and above', $formattedFromPrice);
161         } 161         }
162  162 
163         if ($fromPrice === $toPrice && $this->dataProvider->getOnePriceIntervalValue()) { 163         if ($fromPrice === $toPrice && $this->dataProvider->getOnePriceIntervalValue()) {
164             return $formattedFromPrice; 164             return $formattedFromPrice;
165         } 165         }
166  166 
167         return __('%1 - %2', $formattedFromPrice, $this->priceCurrency->format($toPrice)); 167         return __('%1 - %2', $formattedFromPrice, $this->priceCurrency->format($toPrice));
168     } 168     }
169  169 
170     /** 170     /**
171      * Price Slider Configuration 171      * Price Slider Configuration
172      * 172      *
173      * @return array 173      * @return array
174      */ 174      */
175     public function getSliderConfig() 175     public function getSliderConfig()
176     { 176     {
177         /** @var Collection $productCollection */ 177         /** @var Collection $productCollection */
178         $productCollection = $this->getLayer()->getProductCollection(); 178         $productCollection = $this->getLayer()->getProductCollection()
179  179             ->getCollectionClone()
180         if ($this->_filterVal) { 180             ->setGetAllData(true)
181             /** @type Collection $productCollectionClone */ 181             ->removeAttributeSearch(['price.from', 'price.to'])
182             $productCollection = $productCollection->getCollectionClone() 182             ->setGetAllData(false);
183                 ->removeAttributeSearch(['price.from', 'price.to']);    
184         }    
185  183 
186         $min = $productCollection->getMinPrice(); 184         $min = $productCollection->getMinPrice();
187         $max = $productCollection->getMaxPrice(); 185         $max = $productCollection->getMaxPrice();
188  186 
189         [$from, $to] = $this->_filterVal ?: [$min, $max]; 187         [$from, $to] = $this->_filterVal ?: [$min, $max];
190         $from = max(min($from, $max), $min); 188         $from = max(min($from, $max), $min);
191         $to = min(max($to, $from), $max); 189         $to = min(max($to, $from), $max);
192  190 
193         $item = $this->getItems()[0]; 191         $item = $this->getItems()[0];
194  192 
195         return [ 193         return [
196             'selectedFrom' => $from, 194             'selectedFrom' => $from,
197             'selectedTo' => $to, 195             'selectedTo' => $to,
198             'minValue' => $min, 196             'minValue' => $min,
199             'maxValue' => $max, 197             'maxValue' => $max,
200             'priceFormat' => $this->_taxHelper->getPriceFormat(), 198             'priceFormat' => $this->_taxHelper->getPriceFormat(),
201             'ajaxUrl' => $item->getUrl() 199             'ajaxUrl' => $item->getUrl()
202         ]; 200         ];
203     } 201     }
204  202 
205     /** 203     /**
206      * Get data array for building attribute filter items 204      * Get data array for building attribute filter items
207      * 205      *
208      * @return array 206      * @return array
209      * @throws LocalizedException 207      * @throws LocalizedException
210      * @throws StateException 208      * @throws StateException
211      */ 209      */
212     protected function _getItemsData() 210     protected function _getItemsData()
213     { 211     {
214         if (!$this->_moduleHelper->isEnabled()) { 212         if (!$this->_moduleHelper->isEnabled()) {
215             return parent::_getItemsData(); 213             return parent::_getItemsData();
216         } 214         }
217  215 
218         $attribute = $this->getAttributeModel(); 216         $attribute = $this->getAttributeModel();
219         $this->_requestVar = $attribute->getAttributeCode(); 217         $this->_requestVar = $attribute->getAttributeCode();
220  218 
221         /** @var \Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection $productCollection */ 219         /** @var \Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection $productCollection */
222         $productCollection = $this->getLayer()->getProductCollection(); 220         $productCollection = $this->getLayer()->getProductCollection();
223  221 
224         if ($this->_filterVal) { 222         if ($this->_filterVal) {
225             /** @type Collection $productCollectionClone */ 223             /** @type Collection $productCollectionClone */
226             $productCollection = $productCollection->getCollectionClone() 224             $productCollection = $productCollection->getCollectionClone()
227                 ->removeAttributeSearch(['price.from', 'price.to']); 225                 ->removeAttributeSearch(['price.from', 'price.to']);
228         } 226         }
229  227 
230         $facets = $productCollection->getFacetedData($attribute->getAttributeCode()); 228         $facets = $productCollection->getFacetedData($attribute->getAttributeCode());
231  229 
232         $data = []; 230         $data = [];
233         if (count($facets) >= 1) { // fix range of price with elasticsearch 231         if (count($facets) >= 1) { // fix range of price with elasticsearch
234             foreach ($facets as $key => $aggregation) { 232             foreach ($facets as $key => $aggregation) {
235                 $count = $aggregation['count']; 233                 $count = $aggregation['count'];
236                 if (strpos($key, '_') === false) { 234                 if (strpos($key, '_') === false) {
237                     continue; 235                     continue;
238                 } 236                 }
239                 $data[] = $this->prepareData($key, $count); 237                 $data[] = $this->prepareData($key, $count);
240             } 238             }
241         } 239         }
242  240 
243         return $data; 241         return $data;
244     } 242     }
245  243 
246     /** 244     /**
247      * @param string $key 245      * @param string $key
248      * @param int $count 246      * @param int $count
249      * 247      *
250      * @return array 248      * @return array
251      */ 249      */
252     private function prepareData($key, $count) 250     private function prepareData($key, $count)
253     { 251     {
254         [$from, $to] = explode('_', $key); 252         [$from, $to] = explode('_', $key);
255         if ($from === '*') { 253         if ($from === '*') {
256             $from = $this->getFrom($to); 254             $from = $this->getFrom($to);
257         } 255         }
258         if ($to === '*') { 256         if ($to === '*') {
259             $to = $this->getTo($to); 257             $to = $this->getTo($to);
260         } 258         }
261         $label = $this->_renderRangeLayerLabel( 259         $label = $this->_renderRangeLayerLabel(
262             empty($from) ? 0 : $from * $this->getCurrencyRate(), 260             empty($from) ? 0 : $from * $this->getCurrencyRate(),
263             empty($to) ? $to : $to * $this->getCurrencyRate() 261             empty($to) ? $to : $to * $this->getCurrencyRate()
264         ); 262         );
265         $value = (float)$from * $this->getCurrencyRate() . '-' . (float)$to * $this->getCurrencyRate(); 263         $value = (float)$from * $this->getCurrencyRate() . '-' . (float)$to * $this->getCurrencyRate();
266  264 
267         return compact('label', 'value', 'count', 'from', 'to'); 265         return compact('label', 'value', 'count', 'from', 'to');
268     } 266     }
269 } 267 }