I just start in Magento 2 and I came across problem. When I select a simple product, that belong to a configurable product, my code returns the product id from the configurable product. I can print the childs of this configurable product but I need to have exactly the product id of the product page that I am visiting.
<?php
$product = $block->getProduct();
$productId = $block->getProduct()->getId();
$ProductName = $block->getProduct()->getName();
?>
<?php if ($product->getTypeId() === 'simple'):?>
<div class="product-count">
<?= $productId ?>
</div>
<?php else:?>
<div class="product-count">
<?= $productId ?>
</div>
<?php endif?>
The second is the configurable product and I need the product selected.
Thanks.