Hi i am trying to create a page which will search a product and show the product there. Everything is working fine but i can't show the product additional information tab in the product.
Here is my block code:
<?php
namespace Custom\Module\Block\Product;
use Magento\Catalog\Model\Product;
use Magento\Catalog\Model\Category;
class Create extends \Magento\Framework\View\Element\Template
{
/**
* @var \Magento\Catalog\Model\Product
*/
protected $_product;
/**
* @var \Magento\Catalog\Model\Category
*/
protected $_category;
/**
* @var \Magento\Cms\Model\Wysiwyg\Config
*/
protected $_wysiwygConfig;
/**
* @param \Magento\Catalog\Block\Product\Context $context
* @param \Magento\Cms\Model\Wysiwyg\Config $wysiwygConfig
* @param Product $product
* @param Category $category
* @param array $data
*/
public function __construct(
\Magento\Catalog\Block\Product\Context $context,
\Magento\Cms\Model\Wysiwyg\Config $wysiwygConfig,
Product $product,
Category $category,
array $data = []
)
{
$this->_wysiwygConfig = $wysiwygConfig;
$this->_product = $product;
$this->_category = $category;
parent::__construct($context, $data);
}
public function getWysiwygConfig()
{
$config = $this->_wysiwygConfig->getConfig();
$config = json_encode($config->getData());
}
public function getProduct($id)
{
return $this->_product->load($id);
}
public function getCategory()
{
return $this->_category;
}
public function _prepareLayout()
{
return parent::_prepareLayout();
}
}
Here is template code:
<?php
$helper = $this->helper('Webkul\Marketplace\Helper\Data');
/** @var $this \Magento\Framework\View\Element\Template */
/** @var $helper \Magento\Search\Helper\Data */
$helper_search = $this->helper('Magento\Search\Helper\Data');
$product_id=$this->getRequest()->getParam('pid');
$product_coll = $block->getProduct($product_id);
$pname = $product_coll->getname();
$desc = $product_coll->getDescription();
$pSku = $product_coll->getsku();
$attributes = $product_coll->getAttributes();
foreach ($attributes as $attribute) {
echo $attribute->getAttributeCode(); echo '<br />';
echo $attribute->getStoreLabel(); echo '<br />';
echo $attribute->getFrontendLabel(); echo '<br />';
echo $attribute->getFrontend()->getLabel(); echo '<br />';
echo $attribute->getFrontend()->getValue($product); echo '<br />';
}
?>
Above code shows the product name, description and sku but it's now showing product additional data.