75. Araxis Merge File Comparison Report

Produced by Araxis Merge on 2020-08-14 00:01:32 +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.

75.1 Files compared

#LocationFileLast Modified
1Porto v3.2.3/Magento 2.x/Porto Theme/app/code/Mageplaza/LayeredNavigation/Model/Layer/FilterPrice.php2018-10-10 20:33:20 +0000
2Porto v3.2.4/Magento 2.x/Porto Theme/app/code/Mageplaza/LayeredNavigation/Model/Layer/FilterPrice.php2020-06-26 11:11:14 +0000

75.2 Comparison summary

DescriptionBetween
Files 1 and 2
Text BlocksLines
Unchanged27436
Changed21102
Inserted47
Removed12

75.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

75.4 Active regular expressions

No regular expressions were active.

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