Kiddo
Kiddo

Reputation: 5082

How do I retrieve simple products associated with configurable products

Hi i'm using magento soap api v2 with c#. Do far I have been calling

 var groupedProducts = magentoService.catalogProductLinkList(sessionId, "grouped", id, "productId");

that does return grouped Products, but instead I would like to retrieve simple products such as green large t-shirt which is associated with configurable t-shirt.

How can this be achieved?

Upvotes: 3

Views: 3246

Answers (4)

waltavista
waltavista

Reputation: 157

Please be aware that it should be

... new associativeEntity() { key="like", ...

and not

... new associativeEntity() { key="LIKE", ....

Upper case LIKE does not work.

Upvotes: 0

Andreas Gyr
Andreas Gyr

Reputation: 519

I found a Magento Extension on Github, which includes this functionallity.

Get configurable's subproducts informations in the same response.

https://github.com/Yameveo/Yameveo_ProductInfo

Upvotes: -1

MagePal Extensions
MagePal Extensions

Reputation: 17656

I dont think what you are trying to do is possible with default magento SOAP api.

What you could do is create a custom api

eg.

How to setup custom api for Magento with SOAP V2?

http://www.magentocommerce.com/api/soap/create_your_own_api.html

Then create the logic to retrieve all the simple products associated with that configurable product.

$_product  = Mage::getModel('catalog/product')->load($id);
// check if it's a configurable product
if($_product->isConfigurable()){
   //load simple product ids
   $ids = $_product->getTypeInstance()->getUsedProductIds(); 
   OR
  $ids = Mage::getResourceModel('catalog/product_type_configurable')->load($_product);
}

Upvotes: 3

silvo
silvo

Reputation: 4009

Unfortunatelly that's not possible with the magento SOAP api. You are not able to retrieve child products of a parent product via the api. Believe me, I have tackled this myself some time ago. I can suggest 2 fixes and 1 workaround.

Workaround - Try to retrieve child products by sku or name. This can work provided that all your child products use the parent's name or sku as the prefix. That's how I resolved it in the beginning and it worked well as long as the client did not introduce child product names that did not match the parent name. Here's some sample code:

//fetch configurable products
filters filter = new filters();
filter.filter = new associativeEntity[1];
filter.filter[0] = new associativeEntity();
filter.filter[0].key = "type_id";
filter.filter[0].value = "configurable";

//get all configurable products
var configurableProducts = service.catalogProductList(sessionID, filter, storeView);

foreach (var parent in configurableProducts)
{
    filters filter = new filters();
    filter.filter = new associativeEntity[1];
    filter.filter[0] = new associativeEntity();
    filter.filter[0].key = "type_id";
    filter.filter[0].value = "configurable";
    filter.complex_filter = new complexFilter[1];
    filter.complex_filter[0] = new complexFilter();
    filter.complex_filter[0].key = "sku";
    filter.complex_filter[0].value = new associativeEntity() { key="LIKE", value=parent.sku + "%" };

    var simpleProducts = service.catalogProductList(sessionID, filter, storeView);

    //do whatever you need with the simple products

}

Fix #1 - Free - Write your own api extension. To retrieve child products you could use:

$childProducts = Mage::getModel('catalog/product_type_configurable')->getUsedProducts(null, $product);

You then send the results to the api caller and all should be well. I have not tried that myself, though, so I'm not sure if there are any other problems on the way.

Fix #2 - Paid - Get the (excellent, but pricey) CoreAPI extension from netzkollektiv. That's what I did when the workaround stopped working out for me and never regretted this decision.

Upvotes: 3

Related Questions