0

I am trying to get a Grouped product ID (and then the grouped product URL, but I can do this) from a Simple product which is part of this grouped product.

I tried the following:

$parents = $product->getTypeInstance()->getParentIdsByChild($productId);

Without success. Thanks!

0

You can get this way:

    public function __construct(
        \Magento\Framework\View\Element\Template\Context $context,
        \Magento\GroupedProduct\Model\Product\Type\Grouped $groupedProduct,
        array $data = []
    ) {
        $this->groupedProduct = $groupedProduct;
        parent::__construct($context, $data);
    }
    /**
      * $childId Child Item id
      */
    public function getGroupedProductId($childId) {
     return $this->groupedProduct->getParentIdsByChild($childId);
    }

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.