diff --git a/Block/Product/ProductList/Related.php b/Block/Product/ProductList/Related.php index 431b4c0..664200f 100644 --- a/Block/Product/ProductList/Related.php +++ b/Block/Product/ProductList/Related.php @@ -1,4 +1,5 @@ _helper = $helperFactory; - $this->_registry = $context->getRegistry(); - $this->_storeManager = $context->getStoreManager(); - ; - $this->_collection = $collection; - parent::__construct( - $context, - $checkoutCart, - $catalogProductVisibility, - $checkoutSession, - $moduleManager, - $data - ); - - // Only cache if we have something thats keyable.. - $_time = $this->_helper->get('Tun2U\AutoRelated\Helper\Data')->get_cache_lifetime(); - - if ($_time > 0 && $cacheKey = $this->_cacheKey()) { - $this->addData(array( - 'cache_lifetime' => $_time, - 'cache_tags' => array(\Magento\Store\Model\Store::CACHE_TAG), - 'cache_key' => $cacheKey, - )); - } - } - - protected function _cacheKey() - { - $product = $this->_registry->registry('product'); - - if ($product) { - return get_class() . '::' . $this->_storeManager->getStore()->getCode() . '::' . $product->getId(); - } - - return false; - } - - protected function _prepareData() - { - parent::_prepareData(); - - $_enabled = $this->_helper->get('Tun2U\AutoRelated\Helper\Data')->get_enabled(); - - if ($_enabled && count($this->getItems()) == 0) { - $_products = $this->_collection->getRelatedProducts(); - if ($_products) { - $this->_itemCollection = $_products; - } - } - - return $this; - } - - public function getIdentities() - { - $identities = []; - //Bugfix: Warning: Invalid argument supplied for foreach() - if (is_array($this->getItems()) || is_object($this->getItems())) { - foreach ($this->getItems() as $item) { - $identities = array_merge($identities, $item->getIdentities()); - } - } - return $identities; - } -} + /** + * @var \Magento\Core\Model\Factory\Helper + */ + protected $_helper; + + + /** + * @var \Magento\Store\Model\StoreManagerInterface + */ + protected $_storeManager; + + + /** + * @var \Magento\Framework\Registry + */ + protected $_registry; + + + /** + * @var \Tun2U\AutoRelated\Model\Collection + */ + protected $_collection; + + + public function __construct( + \Magento\Catalog\Block\Product\Context $context, + \Magento\Checkout\Model\ResourceModel\Cart $checkoutCart, + \Magento\Catalog\Model\Product\Visibility $catalogProductVisibility, + \Magento\Checkout\Model\Session $checkoutSession, + \Magento\Framework\Module\Manager $moduleManager, + ObjectManagerInterface $helperFactory, + Collection $collection, + array $data = [] + ) { + $this->_helper = $helperFactory; + $this->_registry = $context->getRegistry(); + $this->_storeManager = $context->getStoreManager();; + $this->_collection = $collection; + parent::__construct( + $context, + $checkoutCart, + $catalogProductVisibility, + $checkoutSession, + $moduleManager, + $data + ); + + // Only cache if we have something thats keyable.. + $_time = $this->_helper->get('Tun2U\AutoRelated\Helper\Data')->get_cache_lifetime(); + + if ($_time > 0 && $cacheKey = $this->_cacheKey()) { + $this->addData(array( + 'cache_lifetime' => $_time, + 'cache_tags' => array(\Magento\Store\Model\Store::CACHE_TAG), + 'cache_key' => $cacheKey, + )); + } + } + + protected function _cacheKey() + { + $product = $this->_registry->registry('product'); + + if ($product) { + return get_class() . '::' . $this->_storeManager->getStore()->getCode() . '::' . $product->getId(); + } + + return false; + } + + protected function _prepareData() + { + parent::_prepareData(); + + $_enabled = $this->_helper->get('Tun2U\AutoRelated\Helper\Data')->get_enabled(); + + if ($_enabled && count($this->getItems()) == 0) { + $_products = $this->_collection->getRelatedProducts(); + if ($_products) { + $this->_itemCollection = $_products; + } + } + + return $this; + } + + public function getIdentities() + { + $identities = []; + //Bugfix: Warning: Invalid argument supplied for foreach() + if (is_array($this->getItems()) || is_object($this->getItems())) { + foreach ($this->getItems() as $item) { + $identities = array_merge($identities, $item->getIdentities()); + } + } + return $identities; + } +} \ No newline at end of file diff --git a/composer.json b/composer.json index 106d521..b02b01c 100644 --- a/composer.json +++ b/composer.json @@ -1,19 +1,22 @@ { "name": "tun2u/m2-autorelated", "description": "Auto generate related products for Magento 2", - "keywords": ["magento2","autorelated","related","products"], + "keywords": [ + "magento2", + "autorelated", + "related", + "products" + ], "homepage": "https://github.com/Tun2U/M2-AutoRelated", "type": "magento2-module", - "version": "1.0.4", + "version": "1.0.5", "minimum-stability": "stable", "license": "GPL-3.0", - "authors": [ - { - "name": "Tun2U S.r.l.", - "email": "info@tun2u.it", - "homepage": "https://www.tun2u.com" - } - ], + "authors": [{ + "name": "Tun2U S.r.l.", + "email": "info@tun2u.it", + "homepage": "https://www.tun2u.com" + }], "support": { "email": "info@tun2u.com" }, @@ -28,4 +31,4 @@ "Tun2U\\AutoRelated\\": "" } } -} +} \ No newline at end of file