0

I created a bundle product and when I try to get that Bundle product id on product detail page I am getting simple product id of that bundle product instead of Bundle product id. I used this function to get bundle id but its giving all the parent bundle products id instead of current bundle product id :

    $model = \Magento\Framework\App\ObjectManager::getInstance()->get('\Magento\Bundle\Model\Product\Type');
    $product = $this->product;
    $parentIds = $model->getParentIdsByChild($product->getId());
1

in your block

protected $_registry;

    public function __construct(
        \Magento\Backend\Block\Template\Context $context,
        \Magento\Framework\Registry $registry,
        array $data = []
    ) {
        $this->_registry = $registry;
        parent::__construct($context, $data);
    }


    public function getCurrentProduct()
    {        
        return $this->_registry->registry('current_product');
    }

in your template

  $currentProduct = $block->getCurrentProduct();   $id = $currentProduct->getId();
  • Thanks its working – MagentoDev Oct 1 '19 at 13:30
  • please accept the answer to helps others. – MichaelHa Oct 1 '19 at 13:32
  • but its not working in API – MagentoDev Oct 1 '19 at 13:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.