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