10. Araxis Merge File Comparison Report

Produced by Araxis Merge on 2024-03-04 14:38:22 +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.

10.1 Files compared

#LocationFileLast Modified
1/Users/coca/Documents/www/Porto v4.0.2/Theme Files/Magento 2.x/Porto Theme v4.0.7/app/code/Smartwave/Filterproducts/Block/WidgetProducts.php2023-11-22 08:10:32 +0000
2/Users/coca/Documents/www/Porto v4.0.2/Theme Files/Magento 2.x/Porto Theme v4.0.8/app/code/Smartwave/Filterproducts/Block/WidgetProducts.php2024-01-15 04:10:03 +0000

10.2 Comparison summary

DescriptionBetween
Files 1 and 2
Text BlocksLines
Unchanged2562
Changed00
Inserted115
Removed00

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

10.4 Active regular expressions

No regular expressions were active.

10.5 Comparison detail

1 <?php 1 <?php
2  2 
3 namespace Smartwave\Filterproducts\Block\Widget; 3 namespace Smartwave\Filterproducts\Block\Widget;
4  4 
5 use Magento\Catalog\Api\CategoryRepositoryInterface; 5 use Magento\Catalog\Api\CategoryRepositoryInterface;
6  6 
7  7 
8 class Products extends \Magento\Catalog\Block\Product\ListProduct implements \Magento\Widget\Block\BlockInterface { 8 class Products extends \Magento\Catalog\Block\Product\ListProduct implements \Magento\Widget\Block\BlockInterface {
9  9 
10     protected $_collection; 10     protected $_collection;
11  11 
12     protected $categoryRepository; 12     protected $categoryRepository;
13  13 
14     protected $_resource; 14     protected $_resource;
15  15 
16     protected $_pager; 16     protected $_pager;
17  17 
18     private $serializer; 18     private $serializer;
19  19 
20     const DISPLAY_TYPE_PRODUCTS = 'latest_products'; 20     const DISPLAY_TYPE_PRODUCTS = 'latest_products';
21  21 
22     const DEFAULT_SHOW_PAGER = false; 22     const DEFAULT_SHOW_PAGER = false;
23  23 
24     const DEFAULT_PRODUCTS_PER_PAGE = 5; 24     const DEFAULT_PRODUCTS_PER_PAGE = 5;
25  25 
26     const PAGE_VAR_NAME = 'np'; 26     const PAGE_VAR_NAME = 'np';
27  27 
28     public function __construct( 28     public function __construct(
29         \Magento\Catalog\Block\Product\Context $context, 29         \Magento\Catalog\Block\Product\Context $context,
30         \Magento\Framework\Data\Helper\PostHelper $postDataHelper, 30         \Magento\Framework\Data\Helper\PostHelper $postDataHelper,
31         \Magento\Catalog\Model\Layer\Resolver $layerResolver, 31         \Magento\Catalog\Model\Layer\Resolver $layerResolver,
32         CategoryRepositoryInterface $categoryRepository, 32         CategoryRepositoryInterface $categoryRepository,
33         \Magento\Framework\Url\Helper\Data $urlHelper, 33         \Magento\Framework\Url\Helper\Data $urlHelper,
34         \Magento\Catalog\Model\ResourceModel\Product\Collection $collection, 34         \Magento\Catalog\Model\ResourceModel\Product\Collection $collection,
35         \Magento\Framework\App\ResourceConnection $resource, 35         \Magento\Framework\App\ResourceConnection $resource,
36         array $data = [], 36         array $data = [],
37         \Magento\Framework\Serialize\Serializer\Json $serializer = null 37         \Magento\Framework\Serialize\Serializer\Json $serializer = null
38     ) { 38     ) {
39         $this->categoryRepository = $categoryRepository; 39         $this->categoryRepository = $categoryRepository;
40         $this->_collection = $collection; 40         $this->_collection = $collection;
41         $this->_resource = $resource; 41         $this->_resource = $resource;
42  42 
43         parent::__construct($context, $postDataHelper, $layerResolver, $categoryRepository, $urlHelper, $data); 43         parent::__construct($context, $postDataHelper, $layerResolver, $categoryRepository, $urlHelper, $data);
44  44 
45         $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance() 45         $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
46             ->get(\Magento\Framework\Serialize\Serializer\Json::class); 46             ->get(\Magento\Framework\Serialize\Serializer\Json::class);
47     } 47     }
48  48 
    49     /**
    50      * Set template
    51      *
    52      * @return string
    53      */
    54     public function _toHtml()
    55     {
    56         $this->setTemplate(
    57             $this->getData('layout_type') ? 'Smartwave_Filterproducts::widget/'.$this->getData('layout_type').'.phtml' : 'Smartwave_Filterproducts::widget/grid.phtml'
    58         );
    59 
    60         $html = parent::_toHtml();
    61         return $html;
    62     }
    63 
49     protected function _beforeToHtml() 64     protected function _beforeToHtml()
50     { 65     {
51         $this->setProductCollection($this->createCollection()); 66         $this->setProductCollection($this->createCollection());
52         return parent::_beforeToHtml(); 67         return parent::_beforeToHtml();
53     } 68     }
54  69 
55     public function createCollection() 70     public function createCollection()
56     { 71     {
57       $category_id = ''; 72       $category_id = '';
58       if($this->getData('category_ids')!=''){ 73       if($this->getData('category_ids')!=''){
59         if(explode('/', $this->getData('category_ids'))[0] == 'category'){ 74         if(explode('/', $this->getData('category_ids'))[0] == 'category'){
60           $category_id = explode('/', $this->getData('category_ids'))[1]; 75           $category_id = explode('/', $this->getData('category_ids'))[1];
61         }else{ 76         }else{
62           $category_id = $this->getData('category_ids'); 77           $category_id = $this->getData('category_ids');
63         } 78         }
64       } 79       }
65       $collection = clone $this->_collection; 80       $collection = clone $this->_collection;
66       $collection->clear()->getSelect()->reset(\Magento\Framework\DB\Select::WHERE)->reset(\Magento\Framework\DB\Select::ORDER)->reset(\Magento\Framework\DB\Select::LIMIT_COUNT)->reset(\Magento\Framework\DB\Select::LIMIT_OFFSET)->reset(\Magento\Framework\DB\Select::GROUP); 81       $collection->clear()->getSelect()->reset(\Magento\Framework\DB\Select::WHERE)->reset(\Magento\Framework\DB\Select::ORDER)->reset(\Magento\Framework\DB\Select::LIMIT_COUNT)->reset(\Magento\Framework\DB\Select::LIMIT_OFFSET)->reset(\Magento\Framework\DB\Select::GROUP);
67  82 
68       if(!$category_id) { 83       if(!$category_id) {
69           $category_id = $this->_storeManager->getStore()->getRootCategoryId(); 84           $category_id = $this->_storeManager->getStore()->getRootCategoryId();
70       } 85       }
71       $category = $this->categoryRepository->get($category_id); 86       $category = $this->categoryRepository->get($category_id);
72  87 
73       if ($this->getData('store_id') !== null) { 88       if ($this->getData('store_id') !== null) {
74           $collection->setStoreId($this->getData('store_id')); 89           $collection->setStoreId($this->getData('store_id'));
75       } 90       }
76  91 
77       $collection->addMinimalPrice() 92       $collection->addMinimalPrice()
78           ->addFinalPrice() 93           ->addFinalPrice()
79           ->addTaxPercents() 94           ->addTaxPercents()
80           ->addAttributeToSelect('name') 95           ->addAttributeToSelect('name')
81           ->addAttributeToSelect('image') 96           ->addAttributeToSelect('image')
82           ->addAttributeToSelect('small_image') 97           ->addAttributeToSelect('small_image')
83           ->addAttributeToSelect('thumbnail') 98           ->addAttributeToSelect('thumbnail')
84           ->addAttributeToSelect('special_from_date') 99           ->addAttributeToSelect('special_from_date')
85           ->addAttributeToSelect('special_to_date') 100           ->addAttributeToSelect('special_to_date')
86           ->addAttributeToSelect($this->_catalogConfig->getProductAttributes()) 101           ->addAttributeToSelect($this->_catalogConfig->getProductAttributes())
87           ->addUrlRewrite() 102           ->addUrlRewrite()
88           ->addStoreFilter(); 103           ->addStoreFilter();
89  104 
90       if(isset($category) && $category) 105       if(isset($category) && $category)
91       { 106       {
92         $collection->addCategoryFilter($category); 107         $collection->addCategoryFilter($category);
93       } 108       }
94       switch ($this->getDisplayType()) 109       switch ($this->getDisplayType())
95       { 110       {
96           case 'new_products': 111           case 'new_products':
97               $collection->addAttributeToFilter( 112               $collection->addAttributeToFilter(
98                     'news_from_date', 113                     'news_from_date',
99                     ['date' => true, 'to' => $this->getEndOfDayDate()], 114                     ['date' => true, 'to' => $this->getEndOfDayDate()],
100                     'left') 115                     'left')
101                 ->addAttributeToFilter( 116                 ->addAttributeToFilter(
102                     'news_to_date', 117                     'news_to_date',
103                     [ 118                     [
104                         'or' => [ 119                         'or' => [
105                             0 => ['date' => true, 'from' => $this->getStartOfDayDate()], 120                             0 => ['date' => true, 'from' => $this->getStartOfDayDate()],
106                             1 => ['is' => new \Zend_Db_Expr('null')], 121                             1 => ['is' => new \Zend_Db_Expr('null')],
107                         ] 122                         ]
108                     ], 123                     ],
109                     'left') 124                     'left')
110                 ->addAttributeToSort( 125                 ->addAttributeToSort(
111                     'news_from_date', 126                     'news_from_date',
112                     'desc'); 127                     'desc');
113               break; 128               break;
114           case 'featured_products': 129           case 'featured_products':
115               $collection->addAttributeToFilter('sw_featured', 1, 'left'); 130               $collection->addAttributeToFilter('sw_featured', 1, 'left');
116               break; 131               break;
117           case 'bestseller_products': 132           case 'bestseller_products':
118               $collection->getSelect() 133               $collection->getSelect()
119                   ->joinLeft(['soi' => $collection->getTable('sales_order_item')], 'soi.product_id = e.entity_id', ['SUM(soi.qty_ordered) AS ordered_qty']) 134                   ->joinLeft(['soi' => $collection->getTable('sales_order_item')], 'soi.product_id = e.entity_id', ['SUM(soi.qty_ordered) AS ordered_qty'])
120                   ->join(['order' => $collection->getTable('sales_order')], "order.entity_id = soi.order_id",['order.state']) 135                   ->join(['order' => $collection->getTable('sales_order')], "order.entity_id = soi.order_id",['order.state'])
121                   ->where("order.state <> 'canceled' and soi.parent_item_id IS NULL AND soi.product_id IS NOT NULL") 136                   ->where("order.state <> 'canceled' and soi.parent_item_id IS NULL AND soi.product_id IS NOT NULL")
122                   ->group('soi.product_id') 137                   ->group('soi.product_id')
123                   ->order('ordered_qty DESC'); 138                   ->order('ordered_qty DESC');
124               /*$collection->getSelect() 139               /*$collection->getSelect()
125                 ->join(['bestsellers' => $collection->getTable('sales_bestsellers_aggregated_yearly')], 140                 ->join(['bestsellers' => $collection->getTable('sales_bestsellers_aggregated_yearly')],
126                     'e.entity_id = bestsellers.product_id AND bestsellers.store_id = '.$this->getData('store_id'), 141                     'e.entity_id = bestsellers.product_id AND bestsellers.store_id = '.$this->getData('store_id'),
127                     ['qty_ordered','rating_pos']) 142                     ['qty_ordered','rating_pos'])
128                 ->order('rating_pos');*/ 143                 ->order('rating_pos');*/
129               break; 144               break;
130           case 'sale_products': 145           case 'sale_products':
131               $collection->addAttributeToFilter('special_price', ['neq' => '']) 146               $collection->addAttributeToFilter('special_price', ['neq' => ''])
132               ->addAttributeToFilter( 147               ->addAttributeToFilter(
133                     'special_from_date', 148                     'special_from_date',
134                     ['date' => true, 'to' => $this->getEndOfDayDate()], 149                     ['date' => true, 'to' => $this->getEndOfDayDate()],
135                     'left') 150                     'left')
136                 ->addAttributeToFilter( 151                 ->addAttributeToFilter(
137                     'special_to_date', 152                     'special_to_date',
138                     [ 153                     [
139                         'or' => [ 154                         'or' => [
140                             0 => ['date' => true, 'from' => $this->getStartOfDayDate()], 155                             0 => ['date' => true, 'from' => $this->getStartOfDayDate()],
141                             1 => ['is' => new \Zend_Db_Expr('null')], 156                             1 => ['is' => new \Zend_Db_Expr('null')],
142                         ] 157                         ]
143                     ], 158                     ],
144                     'left') 159                     'left')
145                 ->addAttributeToSort( 160                 ->addAttributeToSort(
146                     'news_from_date', 161                     'news_from_date',
147                     'desc'); 162                     'desc');
148               break; 163               break;
149           case 'deal_products': 164           case 'deal_products':
150               $collection->getSelect() 165               $collection->getSelect()
151                   ->joinLeft(['dai' => $collection->getTable('sw_dailydeals_dailydeal')], 'dai.sw_product_sku = e.sku') 166                   ->joinLeft(['dai' => $collection->getTable('sw_dailydeals_dailydeal')], 'dai.sw_product_sku = e.sku')
152                   ->where('dai.sw_deal_enable=1') 167                   ->where('dai.sw_deal_enable=1')
153                   ->where( 168                   ->where(
154                       'dai.sw_date_from <= "'.$this->getDayDate().'" or dai.sw_date_from IS NULL' 169                       'dai.sw_date_from <= "'.$this->getDayDate().'" or dai.sw_date_from IS NULL'
155                   )->where( 170                   )->where(
156                       'dai.sw_date_to >= "'.$this->getDayDate().'" or dai.sw_date_to IS NULL' 171                       'dai.sw_date_to >= "'.$this->getDayDate().'" or dai.sw_date_to IS NULL'
157                   ); 172                   );
158               break; 173               break;
159           default: 174           default:
160               $collection->addAttributeToSort('created_at','desc'); 175               $collection->addAttributeToSort('created_at','desc');
161               break; 176               break;
162       } 177       }
163  178 
164       $collection->setPageSize($this->getPageSize()) 179       $collection->setPageSize($this->getPageSize())
165                  ->setCurPage($this->getCurrentPage()); 180                  ->setCurPage($this->getCurrentPage());
166  181 
167       if($this->getDisplayType() == 'featured_products') { 182       if($this->getDisplayType() == 'featured_products') {
168         $collection->getSelect()->order('rand()'); 183         $collection->getSelect()->order('rand()');
169       } 184       }
170  185 
171       return $collection; 186       return $collection;
172     } 187     }
173  188 
174     public function getCurrentPage() 189     public function getCurrentPage()
175     { 190     {
176         return abs((int)$this->getRequest()->getParam($this->getData('page_var_name'))); 191         return abs((int)$this->getRequest()->getParam($this->getData('page_var_name')));
177     } 192     }
178  193 
179     public function getCacheKeyInfo() 194     public function getCacheKeyInfo()
180     { 195     {
181         return array_merge( 196         return array_merge(
182             parent::getCacheKeyInfo(), 197             parent::getCacheKeyInfo(),
183             [ 198             [
184                 $this->getDisplayType(), 199                 $this->getDisplayType(),
185                 $this->_storeManager->getStore()->getId(), 200                 $this->_storeManager->getStore()->getId(),
186                 $this->getProductsPerPage(), 201                 $this->getProductsPerPage(),
187                 (int) $this->getRequest()->getParam($this->getData('page_var_name'), 1), 202                 (int) $this->getRequest()->getParam($this->getData('page_var_name'), 1),
188                 $this->serializer->serialize($this->getRequest()->getParams()) 203                 $this->serializer->serialize($this->getRequest()->getParams())
189             ] 204             ]
190         ); 205         );
191     } 206     }
192  207 
193     public function getDisplayType() 208     public function getDisplayType()
194     { 209     {
195         if (!$this->hasData('display_type')) { 210         if (!$this->hasData('display_type')) {
196             $this->setData('display_type', self::DISPLAY_TYPE_PRODUCTS); 211             $this->setData('display_type', self::DISPLAY_TYPE_PRODUCTS);
197         } 212         }
198         return $this->getData('display_type'); 213         return $this->getData('display_type');
199     } 214     }
200  215 
201     public function getProductsCount() 216     public function getProductsCount()
202     { 217     {
203         if (!$this->hasData('product_count')) { 218         if (!$this->hasData('product_count')) {
204             return parent::getProductsCount(); 219             return parent::getProductsCount();
205         } 220         }
206         return $this->getData('product_count'); 221         return $this->getData('product_count');
207     } 222     }
208  223 
209     public function getProductsPerPage() 224     public function getProductsPerPage()
210     { 225     {
211         if (!$this->hasData('products_per_page')) { 226         if (!$this->hasData('products_per_page')) {
212             $this->setData('products_per_page', self::DEFAULT_PRODUCTS_PER_PAGE); 227             $this->setData('products_per_page', self::DEFAULT_PRODUCTS_PER_PAGE);
213         } 228         }
214         return $this->getData('products_per_page'); 229         return $this->getData('products_per_page');
215     } 230     }
216  231 
217     public function showPager() 232     public function showPager()
218     { 233     {
219         if (!$this->hasData('show_pager')) 234         if (!$this->hasData('show_pager'))
220         { 235         {
221             $this->setData('show_pager', self::DEFAULT_SHOW_PAGER); 236             $this->setData('show_pager', self::DEFAULT_SHOW_PAGER);
222         } 237         }
223         return (bool)$this->getData('show_pager'); 238         return (bool)$this->getData('show_pager');
224     } 239     }
225  240 
226     protected function getPageSize() 241     protected function getPageSize()
227     { 242     {
228         return $this->showPager() ? $this->getProductsPerPage() : $this->getProductsCount(); 243         return $this->showPager() ? $this->getProductsPerPage() : $this->getProductsCount();
229     } 244     }
230  245 
231     public function getPagerHtml() 246     public function getPagerHtml()
232     { 247     {
233         if ($this->showPager()) { 248         if ($this->showPager()) {
234             if (!$this->_pager) { 249             if (!$this->_pager) {
235                 $this->_pager = $this->getLayout()->createBlock( 250                 $this->_pager = $this->getLayout()->createBlock(
236                     \Magento\Catalog\Block\Product\Widget\Html\Pager::class, 251                     \Magento\Catalog\Block\Product\Widget\Html\Pager::class,
237                     $this->getWidgetPagerBlockName() 252                     $this->getWidgetPagerBlockName()
238                 ); 253                 );
239  254 
240                 $this->_pager->setUseContainer(true) 255                 $this->_pager->setUseContainer(true)
241                     ->setShowAmounts(true) 256                     ->setShowAmounts(true)
242                     ->setShowPerPage(false) 257                     ->setShowPerPage(false)
243                     ->setPageVarName($this->getData('page_var_name')) 258                     ->setPageVarName($this->getData('page_var_name'))
244                     ->setLimit($this->getProductsPerPage()) 259                     ->setLimit($this->getProductsPerPage())
245                     ->setTotalLimit($this->getProductsCount()) 260                     ->setTotalLimit($this->getProductsCount())
246                     ->setCollection($this->getProductCollection()); 261                     ->setCollection($this->getProductCollection());
247             } 262             }
248             if ($this->_pager instanceof \Magento\Framework\View\Element\AbstractBlock) { 263             if ($this->_pager instanceof \Magento\Framework\View\Element\AbstractBlock) {
249                 return $this->_pager->toHtml(); 264                 return $this->_pager->toHtml();
250             } 265             }
251         } 266         }
252         return ''; 267         return '';
253     } 268     }
254  269 
255     private function getWidgetPagerBlockName() 270     private function getWidgetPagerBlockName()
256     { 271     {
257         $pageName = $this->getData('page_var_name'); 272         $pageName = $this->getData('page_var_name');
258         $pagerBlockName = 'widget.porto.filter.products.pager'; 273         $pagerBlockName = 'widget.porto.filter.products.pager';
259  274 
260         if (!$pageName) { 275         if (!$pageName) {
261             return $pagerBlockName; 276             return $pagerBlockName;
262         } 277         }
263  278 
264         return $pagerBlockName . '.' . $pageName; 279         return $pagerBlockName . '.' . $pageName;
265     } 280     }
266  281 
267     public function getDayDate() 282     public function getDayDate()
268     { 283     {
269         return $this->_localeDate->date()->format('Y-m-d H:i:s'); 284         return $this->_localeDate->date()->format('Y-m-d H:i:s');
270     } 285     }
271  286 
272     public function getStartOfDayDate() 287     public function getStartOfDayDate()
273     { 288     {
274         return $this->_localeDate->date()->setTime(0, 0, 0)->format('Y-m-d H:i:s'); 289         return $this->_localeDate->date()->setTime(0, 0, 0)->format('Y-m-d H:i:s');
275     } 290     }
276  291 
277     public function getEndOfDayDate() 292     public function getEndOfDayDate()
278     { 293     {
279         return $this->_localeDate->date()->setTime(23, 59, 59)->format('Y-m-d H:i:s'); 294         return $this->_localeDate->date()->setTime(23, 59, 59)->format('Y-m-d H:i:s');
280     } 295     }
281 } 296 }