1

I am doing a search via the REST API, looking for products with a certain color and a certain name:

http://127.0.0.1/index.php/rest/V1/products/?searchCriteria[filter_groups][0][filters][0][field]=color&searchCriteria[filter_groups][0][filters][0][value]=49&searchCriteria[filter_groups][0][filters][0][condition_type]=eq&searchCriteria[filter_groups][1][filters][0][field]=name&searchCriteria[filter_groups][1][filters][0][value]=hero%25&searchCriteria[filter_groups][1][filters][0][condition_type]=like

This returns the products I am expecting. It is returning all the variant that match the search to. For example (using the magento sample data), I get:

  • Hero Hoodie-XS-Black
  • Hero Hoodie-S-Black
  • Hero Hoodie-MS-Black

These are all "simple" products, but how do I know they are related? There doesn't appear to be any information in the JSON response to indicate that the products are related, or what their associated configurable product is.

1

You can call this API for each products :

http://domain.com/index.php/rest/V1/products/:sku 

to get more details, but this will cause more requests and reduce performance for the app.

As an advice, you can make a custome module for that and get the parent for every product by ID as EX :

$productId = 1; //this is child product id
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->create('Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable')->getParentIdsByChild($productId);
if(isset($product[0])){
  $product = $objectManager->create('Magento\Catalog\Model\Product')->load($product[0]);
    echo $product->getName();
}

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.