1

I want to get parent product data for configurable products.

I have parent id

How do I get it?

2
  • As a parent configurable product you can get the children simple products. Likewise as a child simple product you can get the parent. Do you want to do either of these? Jun 11, 2019 at 0:44
  • then load the product data based on id use ProductRepositoryInterface and call getById function
    – mohith
    Jun 11, 2019 at 4:54

1 Answer 1

2

I Got the solution

 use \Magento\Catalog\Model\ProductRepository;
 use \Magento\ConfigurableProduct\Model\Product\Type\Configurable;

Then in construct function use

public function __construct(ProductRepository $_productloader,Configurable $configurable) {
$this->configurable=$configurable;
$this->_productloader=$_productloader;
}

get parent product id by product id

 $productId='get your product id'

 $parentId=$this->configurable->getParentIdsByChild($productId);

$parentId gives an array

then get parent product data by

$parentProductData=$this->_productloader->getById($parentId[0]);

This worked for me.

1
  • I had comment the same thing above
    – mohith
    Jun 11, 2019 at 10:13

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.