【问题标题】:How do I retrieve simple products associated with configurable products如何检索与可配置产品关联的简单产品
【发布时间】:2012-10-19 17:02:51
【问题描述】:

您好,我正在使用带有 c# 的 magento soap api v2。走远了,我一直在打电话

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

确实返回分组产品,但我想检索简单的产品,例如与可配置 T 恤相关联的绿色大 T 恤。

如何做到这一点?

【问题讨论】:

    标签: c# api magento


    【解决方案1】:

    不幸的是ma​​gento 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
    
    }
    

    Fix #1 - 免费 - 编写您自己的 api 扩展。要检索您可以使用的子产品:

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

    然后您将结果发送给 api 调用者,一切都会好起来的。不过,我自己没有尝试过,所以我不确定是否还有其他问题。

    修复 #2 - 付费 - 从 netzkollektiv 获取(优秀但昂贵的)CoreAPI extension。当解决方法对我不起作用并且从不后悔这个决定时,我就是这样做的。

    【讨论】:

      【解决方案2】:

      我认为您尝试使用默认的 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);
      }
      

      【讨论】:

        【解决方案3】:

        请注意,它应该是

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

        而不是

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

        大写 LIKE 不起作用。

        【讨论】:

        • 如果您正在评论silvo's answer,请发表评论而不是答案
        【解决方案4】:

        我在 Github 上找到了一个 Magento 扩展,其中包含此功能。

        在同一响应中获取可配置的子产品信息。

        https://github.com/Yameveo/Yameveo_ProductInfo

        【讨论】:

        • 虽然这在理论上可以回答这个问题,it would be preferable 在此处包含答案的基本部分,并提供链接以供参考。
        • 但这是本主题中唯一具体且正确的答案。我认为没有理由低估这个答案。对于阅读此主题的每个人来说,这个答案都是相关的。 -> 添加了报价。
        • 我没有对答案投反对票。一定有人将其标记为原始答案是仅链接,因此当您编辑帖子时它会自动获得 DV。
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-05-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-03-29
        相关资源
        最近更新 更多