0

I'm looking for get the simple products associated to a configurable one. I'm currently using this : $product->getTypeInstance->getUsedProducts($product); Where $product is a configurable.

But it return me simple products that have quantity > 0. Is there a method to also get the 'out of stock' products from a configurable ?

Thanks!

1

Following class is configurable product type class:

vendor/magento/module-configurable-product/Model/Product/Type/Configurable.php

Check the following method for child product collection:


public function getUsedProductCollection($product)
2
0

What I have done :

$product->getTypeInstance()->getUsedProductCollection($product)->getData()

Thank you Sohel Rana !

0

actually the getUsedProducts method only returns the in-stock products. To solve this problem I did the following:

use Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable;

private Configurable $configurable;

public function __construct(Configurable $configurable) 
{
    $this->configurable = $configurable
}

public function getAllChildren($productId)
{
   $this->configurable->getChildrenIds($productId);
}

This will return all product ids, including those without stock.

The downside is that just seeing the ID it will be necessary to consult the Repository to get the product data,

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.