Skip to content

Commit 8b76ec7

Browse files
committedSep 29, 2022
Update for storefront controller related to issue #18
Allow to generate tab for any product (event not visible on storefront).
1 parent 24222a7 commit 8b76ec7

File tree

2 files changed

+54
-3
lines changed

2 files changed

+54
-3
lines changed
 

‎Controller/Index/Index.php

+30-3
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,34 @@
66
use Magento\Framework\UrlInterface;
77
use Magento\Framework\App\Action\Context;
88
use Magento\Framework\Url\DecoderInterface;
9+
use Magento\Catalog\Controller\Product\View\ViewInterface;
10+
use Magento\Catalog\Model\Product as ModelProduct;
11+
use Swissup\Easytabs\Helper\Product as HelperProduct;
912

10-
class Index extends \Magento\Catalog\Controller\Product
13+
class Index extends \Magento\Framework\App\Action\Action implements ViewInterface
1114
{
1215
/**
1316
* @var DecoderInterface
1417
*/
1518
private $decoder;
1619

1720
/**
18-
* @param DecoderInterface $decode
19-
* @param Context $context
21+
* @var HelperProduct
22+
*/
23+
private $helper;
24+
25+
/**
26+
* @param DecoderInterface $decoder
27+
* @param HelperProduct $helper
28+
* @param Context $context
2029
*/
2130
public function __construct(
2231
DecoderInterface $decoder,
32+
HelperProduct $helper,
2333
Context $context
2434
) {
2535
$this->decoder = $decoder;
36+
$this->helper = $helper;
2637
parent::__construct($context);
2738
}
2839

@@ -39,4 +50,20 @@ public function execute()
3950

4051
return $this->resultFactory->create(ResultFactory::TYPE_LAYOUT);
4152
}
53+
54+
/**
55+
* Initialize requested product object
56+
*
57+
* @return ModelProduct
58+
*/
59+
protected function _initProduct()
60+
{
61+
$categoryId = (int)$this->getRequest()->getParam('category', false);
62+
$productId = (int)$this->getRequest()->getParam('id');
63+
64+
$params = new \Magento\Framework\DataObject();
65+
$params->setCategoryId($categoryId);
66+
67+
return $this->helper->initProduct($productId, $this, $params);
68+
}
4269
}

‎Helper/Product.php

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace Swissup\Easytabs\Helper;
4+
5+
class Product extends \Magento\Catalog\Helper\Product
6+
{
7+
/**
8+
* {@inheritdoc}
9+
*/
10+
public function canShow($product, $where = 'catalog')
11+
{
12+
$canShow = parent::canShow($product, $where);
13+
14+
if (!$canShow) {
15+
$parentId = (int)$this->_request->getParam('parent_id');
16+
17+
if ($parentId) {
18+
$canShow = parent::canShow($parentId, $where);
19+
}
20+
}
21+
22+
return $canShow;
23+
}
24+
}

0 commit comments

Comments
 (0)
Please sign in to comment.