C# 如何检索与可配置产品关联的简单产品
嗨,我正在使用带有c#的magento soap api v2。你知道我一直在打电话吗C# 如何检索与可配置产品关联的简单产品,c#,api,magento,C#,Api,Magento,嗨,我正在使用带有c#的magento soap api v2。你知道我一直在打电话吗 var groupedProducts = magentoService.catalogProductLinkList(sessionId, "grouped", id, "productId"); 这会返回分组产品,但我想检索简单的产品,例如与可配置t恤关联的绿色大t恤 这是如何实现的?不幸的是,这在magento SOAP api中是不可能实现的。您无法通过api检索父产品的子产品。相信我,我早就解决
var groupedProducts = magentoService.catalogProductLinkList(sessionId, "grouped", id, "productId");
这会返回分组产品,但我想检索简单的产品,例如与可配置t恤关联的绿色大t恤
这是如何实现的?不幸的是,这在magento SOAP api中是不可能实现的。您无法通过api检索父产品的子产品。相信我,我早就解决了这个问题。我可以建议2个修复和1个解决方法 解决方法-尝试按sku或名称检索子产品。如果您的所有子产品都使用父产品的名称或sku作为前缀,则可以使用此功能。这就是我在开始时解决问题的方法,只要客户没有引入与父产品名称不匹配的子产品名称,它就工作得很好。下面是一些示例代码:
//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
}
修复#1免费-编写自己的api扩展。要检索子产品,您可以使用:
$childProducts = Mage::getModel('catalog/product_type_configurable')->getUsedProducts(null, $product);
然后将结果发送给api调用方,一切都应该正常。不过,我自己也没有试过,所以我不确定是否还有其他问题
修复#2付费-从NetzCollektiv获得(非常好,但价格昂贵)。这就是我在解决方案不再适用于我时所做的,我从来没有后悔过这个决定。我认为默认的magento SOAP api不可能实现您想要做的事情 您可以做的是创建一个自定义api 例如 然后创建逻辑以检索与该可配置产品关联的所有简单产品
$_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);
}
我在Github上发现了一个Magento扩展,其中包括这个功能 在同一响应中获取可配置的子产品信息
请注意
... new associativeEntity() { key="like", ...
而不是
... new associativeEntity() { key="LIKE", ....
大写字母LIKE不起作用。虽然这在理论上可以回答这个问题,但在这里包括答案的基本部分,并提供链接供参考。但这是本主题中唯一准确的答案。我看没有理由贬低这个答案。对于阅读本主题的每个人来说,这个答案都是相关的。->添加了一段引语。我没有对答案投反对票。必须有人将其标记为原始答案仅为链接,因此当您编辑文章时,它会自动获得DV。如果您对文章发表评论,请发表评论而不是答案