嗨,我正在使用magento soap api v2和c# . 我一直在打电话
var groupedProducts = magentoService.catalogProductLinkList(sessionId, "grouped", id, "productId");
确实会返回分组产品,但我想要检索简单的产品,例如与可配置T恤相关的绿色大T恤 .
怎么能实现这一目标?
不幸的是 that's not possible with the magento SOAP api . 您无法通过api检索父产品的子产品 . 相信我,我不久前已经解决了这个问题 . 我可以建议2个修复和1个解决方法 .
Workaround - 尝试通过sku或名称检索子产品 . 这可以工作,只要您的所有子产品使用父's name or sku as the prefix. That'我在开始时如何解决它并且只要客户端没有引入与父名称不匹配的子产品名称,它就能正常工作 . 这是一些示例代码:
//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 - 免费 - 编写自己的api扩展程序 . 要检索子产品,您可以使用:
$childProducts = Mage::getModel('catalog/product_type_configurable')->getUsedProducts(null, $product);
然后,您将结果发送给api调用者,一切都应该很好 . 不过,我自己也没试过,所以我不确定路上是否还有其他问题 .
Fix #2 - 付费 - 从netzkollektiv获取(优秀,但价格昂贵)CoreAPI extension . 这就是我在解决方案停止为我工作时所做的事情,并且从未后悔过这个决定 .
我不认为你可以使用默认的magento SOAP api做什么 .
你可以做的是创建一个自定义API
例如 .
How to setup custom api for Magento with SOAP V2?
http://www.magentocommerce.com/api/soap/create_your_own_api.html
然后创建逻辑以检索与该可配置产品关联的所有简单产品 .
$_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); }
请注意它应该是
... new associativeEntity() { key="like", ...
并不是
... new associativeEntity() { key="LIKE", ....
大写LIKE不起作用 .
我在Github上找到了一个Magento扩展,其中包含了这个功能 .
在同一响应中获取可配置的子产品信息 .
https://github.com/Yameveo/Yameveo_ProductInfo
4 回答
不幸的是 that's not possible with the magento SOAP api . 您无法通过api检索父产品的子产品 . 相信我,我不久前已经解决了这个问题 . 我可以建议2个修复和1个解决方法 .
Workaround - 尝试通过sku或名称检索子产品 . 这可以工作,只要您的所有子产品使用父's name or sku as the prefix. That'我在开始时如何解决它并且只要客户端没有引入与父名称不匹配的子产品名称,它就能正常工作 . 这是一些示例代码:
Fix #1 - 免费 - 编写自己的api扩展程序 . 要检索子产品,您可以使用:
然后,您将结果发送给api调用者,一切都应该很好 . 不过,我自己也没试过,所以我不确定路上是否还有其他问题 .
Fix #2 - 付费 - 从netzkollektiv获取(优秀,但价格昂贵)CoreAPI extension . 这就是我在解决方案停止为我工作时所做的事情,并且从未后悔过这个决定 .
我不认为你可以使用默认的magento SOAP api做什么 .
你可以做的是创建一个自定义API
例如 .
How to setup custom api for Magento with SOAP V2?
http://www.magentocommerce.com/api/soap/create_your_own_api.html
然后创建逻辑以检索与该可配置产品关联的所有简单产品 .
请注意它应该是
并不是
大写LIKE不起作用 .
我在Github上找到了一个Magento扩展,其中包含了这个功能 .
https://github.com/Yameveo/Yameveo_ProductInfo