Skip to content

Commit

Permalink
v1.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
nghelo committed May 17, 2019
1 parent ba51346 commit f67d103
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 11 deletions.
32 changes: 24 additions & 8 deletions Block/Product/ProductList/Related.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@

namespace Tun2U\AutoRelated\Block\Product\ProductList;

use Magento\Framework\ObjectManagerInterface;
use Tun2U\AutoRelated\Model\Collection;

class Related extends \Magento\Catalog\Block\Product\ProductList\Related
{

Expand Down Expand Up @@ -45,9 +42,10 @@ public function __construct(
\Magento\Catalog\Model\Product\Visibility $catalogProductVisibility,
\Magento\Checkout\Model\Session $checkoutSession,
\Magento\Framework\Module\Manager $moduleManager,
array $data = [],
ObjectManagerInterface $helperFactory,
Collection $collection
\Magento\Framework\ObjectManagerInterface $helperFactory,
\Tun2U\AutoRelated\Model\Collection $collection,
\Tun2U\AutoRelated\Helper\Data $helper,
array $data = []
) {
$this->_helper = $helperFactory;
$this->_registry = $context->getRegistry();
Expand All @@ -63,8 +61,12 @@ public function __construct(
$data
);

$this->setBlockType('related');

$this->helper = $helper;

// Only cache if we have something thats keyable..
$_time = $this->_helper->get('Tun2U\AutoRelated\Helper\Data')->get_cache_lifetime();
$_time = $this->helper->get_cache_lifetime();

if ($_time > 0 && $cacheKey = $this->_cacheKey()) {
$this->addData(array(
Expand All @@ -75,6 +77,16 @@ public function __construct(
}
}

public function getHelper()
{
// Amasty Cart
if ($this->moduleManager->isOutputEnabled('Amasty_Cart')) {
return $this->_helper->get('Amasty\Cart\Helper\Data');
}

return $this->helper;
}

protected function _cacheKey()
{
$product = $this->_registry->registry('product');
Expand All @@ -90,7 +102,7 @@ protected function _prepareData()
{
parent::_prepareData();

$_enabled = $this->_helper->get('Tun2U\AutoRelated\Helper\Data')->get_enabled();
$_enabled = $this->helper->get_enabled();

if ($_enabled && count($this->getItems()) == 0) {
$_products = $this->_collection->getRelatedProducts();
Expand All @@ -99,6 +111,10 @@ protected function _prepareData()
}
}

foreach ($this->_itemCollection as $product) {
$product->setDoNotUseCategoryId(true);
}

return $this;
}

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "tun2u/module-auto-related",
"name": "tun2u/m2-autorelated",
"description": "Auto generate related products for Magento 2",
"keywords": ["magento2","autorelated","related","products"],
"homepage": "https://github.com/Tun2U/M2-AutoRelated",
"type": "magento2-module",
"version": "1.0.2",
"version": "1.0.3",
"minimum-stability": "stable",
"license": "GPL-3.0",
"authors": [
Expand Down
1 change: 1 addition & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
<preference for="Magento\Catalog\Block\Product\ProductList\Related" type="Tun2U\AutoRelated\Block\Product\ProductList\Related" />
<preference for="Amasty\Cart\Block\Product\Related" type="Tun2U\AutoRelated\Block\Product\ProductList\Related" />
</config>
5 changes: 4 additions & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Tun2U_AutoRelated" setup_version="1.0.2" />
<module name="Tun2U_AutoRelated" setup_version="1.0.3" />
<sequence>
<module name="Amasty_Cart" />
</sequence>
</config>

0 comments on commit f67d103

Please sign in to comment.