Produced by Araxis Merge on 2021-05-13 09:08:40 +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 | 2021-05-13 09:08:40 +0000 | ||
| 2 | /Applications/Ampps/www/Porto v4.0.0/Theme Files/Magento 2.x/Porto Theme/app/code/Smartwave/Filterproducts | FeaturedList.php | 2020-03-13 09:43:56 +0000 |
| Description | Between Files 1 and 2 | |
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 0 | 0 |
| Changed | 0 | 0 |
| Inserted | 1 | 98 |
| 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; | |||||
| 4 | ||||||
| 5 | class FeaturedList extends \Magento\Catalog\Block\Product\AbstractProduct { | |||||
| 6 | ||||||
| 7 | protected $_catalogProductVisibility; | |||||
| 8 | ||||||
| 9 | protected $_productCollectionFactory; | |||||
| 10 | ||||||
| 11 | protected $_categoryFactory; | |||||
| 12 | ||||||
| 13 | protected $urlHelper; | |||||
| 14 | ||||||
| 15 | public function __construct( | |||||
| 16 | \Magento\Catalog\Block\Product\Context $context, | |||||
| 17 | \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory, | |||||
| 18 | \Magento\Catalog\Model\Product\Visibility $catalogProductVisibility, | |||||
| 19 | \Magento\Catalog\Model\CategoryFactory $categoryFactory, | |||||
| 20 | \Magento\Framework\Url\Helper\Data $urlHelper, | |||||
| 21 | array $data = [] | |||||
| 22 | ) { | |||||
| 23 | $this->_categoryFactory = $categoryFactory; | |||||
| 24 | $this->_productCollectionFactory = $productCollectionFactory; | |||||
| 25 | $this->_catalogProductVisibility = $catalogProductVisibility; | |||||
| 26 | $this->urlHelper = $urlHelper; | |||||
| 27 | ||||||
| 28 | parent::__construct($context, $data); | |||||
| 29 | } | |||||
| 30 | ||||||
| 31 | public function getProducts() { | |||||
| 32 | $count = $this->getProductCount(); | |||||
| 33 | $category_id = $this->getData("category_id"); | |||||
| 34 | $collection = $this->_productCollectionFactory->create(); | |||||
| 35 | $collection->setVisibility($this->_catalogProductVisibility->getVisibleInCatalogIds()); | |||||
| 36 | ||||||
| 37 | $collection = $this->_addProductAttributesAndPrices($collection)->addStoreFilter(); | |||||
| 38 | ||||||
| 39 | if(!$category_id) { | |||||
| 40 | $category_id = $this->_storeManager->getStore()->getRootCategoryId(); | |||||
| 41 | } | |||||
| 42 | $category = $this->_categoryFactory->create()->load($category_id); | |||||
| 43 | if(isset($category) && $category) { | |||||
| 44 | $collection->addMinimalPrice() | |||||
| 45 | ->addFinalPrice() | |||||
| 46 | ->addTaxPercents() | |||||
| 47 | ->addAttributeToSelect('name') | |||||
| 48 | ->addAttributeToSelect('image') | |||||
| 49 | ->addAttributeToSelect('small_image') | |||||
| 50 | ->addAttributeToSelect('thumbnail') | |||||
| 51 | ->addAttributeToSelect($this->_catalogConfig->getProductAttributes()) | |||||
| 52 | ->addUrlRewrite() | |||||
| 53 | ->addAttributeToFilter('sw_featured', 1, 'left') | |||||
| 54 | ->addCategoryFilter($category); | |||||
| 55 | } else { | |||||
| 56 | $collection->addMinimalPrice() | |||||
| 57 | ->addFinalPrice() | |||||
| 58 | ->addTaxPercents() | |||||
| 59 | ->addAttributeToSelect('name') | |||||
| 60 | ->addAttributeToSelect('image') | |||||
| 61 | ->addAttributeToSelect('small_image') | |||||
| 62 | ->addAttributeToSelect('thumbnail') | |||||
| 63 | ->addAttributeToSelect($this->_catalogConfig->getProductAttributes()) | |||||
| 64 | ->addUrlRewrite() | |||||
| 65 | ->addAttributeToFilter('sw_featured', 1, 'left'); | |||||
| 66 | } | |||||
| 67 | ||||||
| 68 | $collection->getSelect() | |||||
| 69 | ->order('rand()') | |||||
| 70 | ->limit($count); | |||||
| 71 | ||||||
| 72 | return $collection; | |||||
| 73 | } | |||||
| 74 | ||||||
| 75 | public function getAddToCartPostParams(\Magento\Catalog\Model\Product $product) | |||||
| 76 | { | |||||
| 77 | $url = $this->getAddToCartUrl($product); | |||||
| 78 | return [ | |||||
| 79 | 'action' => $url, | |||||
| 80 | 'data' => [ | |||||
| 81 | 'product' => $product->getEntityId(), | |||||
| 82 | \Magento\Framework\App\Action\Action::PARAM_NAME_URL_ENCODED => | |||||
| 83 | $this->urlHelper->getEncodedUrl($url), | |||||
| 84 | ] | |||||
| 85 | ]; | |||||
| 86 | } | |||||
| 87 | ||||||
| 88 | public function getLoadedProductCollection() { | |||||
| 89 | return $this->getProducts(); | |||||
| 90 | } | |||||
| 91 | ||||||
| 92 | public function getProductCount() { | |||||
| 93 | $limit = $this->getData("product_count"); | |||||
| 94 | if(!$limit) | |||||
| 95 | $limit = 10; | |||||
| 96 | return $limit; | |||||
| 97 | } | |||||
| 98 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993–2019 Araxis Ltd (www.araxis.com). All rights reserved.