Hi can you help me for this query Please
hi here is my code I want to show the product data on product page
<?php
namespace Meter\Calculation\Controller\Index;
use Magento\Framework\App\Action\Action;
use Magento\Framework\App\Action\Context;
class Index extends Action
{
protected $_productRepository;
public function __construct(
Context $context,
\Magento\Catalog\Api\ProductRepositoryInterface $productRepository
)
{
$this->_productRepository = $productRepository;
parent::__construct($context);
}
public function execute()
{
$id = $this->getRequest()->getParam('id');
echo $this->_productRepository->getById($id)->getSku();
}
}
when i click on swatches then I get both product id but I want to get single product id from swatches when I will be click on swatches please help me
<?php $_product = $block->getProduct(); ?>
<?php
$productTypeInstance = $_product->getTypeInstance();
if ($_product->getTypeId() == "configurable" ):
$usedProducts = $productTypeInstance->getUsedProducts($_product);
?>
<?php foreach ($usedProducts as $childProduct) { ?>
<div class="pro_conf" style="display: none;">
<h1>Get the configurable Product Ids <?php echo $childProduct->getId(); ?></h1>
</div>
<?php } ?>
<?php endif; ?>