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 Answer 1

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();
3
  • Thanks its working
    – MagentoDev
    Commented Oct 1, 2019 at 13:30
  • please accept the answer to helps others.
    – MichaelHa
    Commented Oct 1, 2019 at 13:32
  • but its not working in API
    – MagentoDev
    Commented Oct 1, 2019 at 13:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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