【问题标题】:Get product category IDs from Magento v2.0 SOAP API从 Magento v2.0 SOAP API 获取产品类别 ID
【发布时间】:2016-09-17 17:16:33
【问题描述】:

如何使用 Magento v2.0 SOAP Web 服务获取产品所属的类别列表?

http://devdocs.magento.com/guides/v2.0/soap/bk-soap.html 我找到了一个服务列表。

使用catalogProductRepositoryV1,我可以请求列表或单个产品,但它不包含类别。例如:

请求:

POST http://domain/soap/default?services=catalogProductRepositoryV1 HTTP/1.1
Content-Type: application/soap+xml; charset=utf-8; action="catalogProductRepositoryV1Get"
Host: domain
Content-Length: 382
Expect: 100-continue
Accept-Encoding: gzip, deflate

<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope">
    <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <catalogProductRepositoryV1GetRequest xmlns="http://domain/soap/default?services=catalogProductRepositoryV1">
            <sku xmlns="">24-MB01</sku>
        </catalogProductRepositoryV1GetRequest>
    </s:Body>
</s:Envelope>

回复:

HTTP/1.1 200 OK
Date: Fri, 20 May 2016 12:21:46 GMT
Server: Apache/2.4.18 (Unix) OpenSSL/1.0.1e-fips mod_bwlimited/1.4 PHP/5.6.21
X-Powered-By: PHP/5.6.21
Set-Cookie: PHPSESSID=89fdd89a6caeb8be424b9531c69d6c69; expires=Fri, 20-May-2016 13:21:47 GMT; Max-Age=3600; path=/; domain=domain; HttpOnly
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Content-Length: 5547
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Connection: close
Content-Type: application/soap+xml; charset=utf-8

<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns1="http://domain/soap/default?services=catalogProductRepositoryV1">
    <env:Body>
        <ns1:catalogProductRepositoryV1GetResponse>
            <result>
                <id>1</id>
                <sku>24-MB01</sku>
                <name>Joust Duffle Bag</name>
                <attributeSetId>15</attributeSetId>
                <price>34</price>
                <status>1</status>
                <visibility>4</visibility>
                <typeId>simple</typeId>
                <createdAt>2016-01-22 16:28:25</createdAt>
                <updatedAt>2016-04-20 09:51:54</updatedAt>
                <extensionAttributes/>
                <productLinks>
                    <item>
                        <sku>24-MB01</sku>
                        <linkType>upsell</linkType>
                        <linkedProductSku>24-MB03</linkedProductSku>
                        <linkedProductType>simple</linkedProductType>
                        <position/>
                        <extensionAttributes/>
                    </item>
                    <item>
                        <sku>24-MB01</sku>
                        <linkType>upsell</linkType>
                        <linkedProductSku>24-MB05</linkedProductSku>
                        <linkedProductType>simple</linkedProductType>
                        <position/>
                        <extensionAttributes/>
                    </item>
                    <item>
                        <sku>24-MB01</sku>
                        <linkType>upsell</linkType>
                        <linkedProductSku>24-MB06</linkedProductSku>
                        <linkedProductType>simple</linkedProductType>
                        <position/>
                        <extensionAttributes/>
                    </item>
                    <item>
                        <sku>24-MB01</sku>
                        <linkType>upsell</linkType>
                        <linkedProductSku>24-MB02</linkedProductSku>
                        <linkedProductType>simple</linkedProductType>
                        <position/>
                        <extensionAttributes/>
                    </item>
                    <item>
                        <sku>24-MB01</sku>
                        <linkType>upsell</linkType>
                        <linkedProductSku>24-UB02</linkedProductSku>
                        <linkedProductType>simple</linkedProductType>
                        <position/>
                        <extensionAttributes/>
                    </item>
                    <item>
                        <sku>24-MB01</sku>
                        <linkType>upsell</linkType>
                        <linkedProductSku>24-WB03</linkedProductSku>
                        <linkedProductType>simple</linkedProductType>
                        <position/>
                        <extensionAttributes/>
                    </item>
                    <item>
                        <sku>24-MB01</sku>
                        <linkType>upsell</linkType>
                        <linkedProductSku>24-WB07</linkedProductSku>
                        <linkedProductType>simple</linkedProductType>
                        <position/>
                        <extensionAttributes/>
                    </item>
                    <item>
                        <sku>24-MB01</sku>
                        <linkType>upsell</linkType>
                        <linkedProductSku>24-WB04</linkedProductSku>
                        <linkedProductType>simple</linkedProductType>
                        <position/>
                        <extensionAttributes/>
                    </item>
                </productLinks>
                <options/>
                <mediaGalleryEntries>
                    <item>
                        <id>1</id>
                        <mediaType>image</mediaType>
                        <label>Image</label>
                        <position>1</position>
                        <disabled>false</disabled>
                        <types>
                            <item>image</item>
                            <item>small_image</item>
                            <item>thumbnail</item>
                        </types>
                        <file>/m/b/mb01-blue-0.jpg</file>
                    </item>
                </mediaGalleryEntries>
                <tierPrices/>
                <customAttributes>
                    <item>
                        <attributeCode>description</attributeCode>
                        <value>&lt;p&gt;The sporty Joust Duffle Bag can't be beat - not in the gym, not on the luggage carousel, not anywhere. Big enough to haul a basketball or soccer ball and some sneakers with plenty of room to spare, it's ideal for athletes with places to go.&lt;/p&gt;&#13;
&lt;ul&gt;&#13;
&lt;li&gt;Dual top handles.&lt;/li&gt;&#13;
&lt;li&gt;Adjustable shoulder strap.&lt;/li&gt;&#13;
&lt;li&gt;Full-length zipper.&lt;/li&gt;&#13;
&lt;li&gt;L 29" x W 13" x H 11".&lt;/li&gt;&#13;
&lt;/ul&gt;</value>
                    </item>
                    <item>
                        <attributeCode>meta_title</attributeCode>
                        <value>Joust Duffle Bag</value>
                    </item>
                    <item>
                        <attributeCode>meta_keyword</attributeCode>
                        <value>Joust Duffle Bag</value>
                    </item>
                    <item>
                        <attributeCode>meta_description</attributeCode>
                        <value>Joust Duffle Bag &lt;p&gt;The sporty Joust Duffle Bag can't be beat - not in the gym, not on the luggage carousel, not anywhere. Big enough to haul a basketball or soccer ball and some sneakers with plenty of room to spare, it's ideal for athletes with places t</value>
                    </item>
                    <item>
                        <attributeCode>image</attributeCode>
                        <value>/m/b/mb01-blue-0.jpg</value>
                    </item>
                    <item>
                        <attributeCode>small_image</attributeCode>
                        <value>/m/b/mb01-blue-0.jpg</value>
                    </item>
                    <item>
                        <attributeCode>thumbnail</attributeCode>
                        <value>/m/b/mb01-blue-0.jpg</value>
                    </item>
                    <item>
                        <attributeCode>category_ids</attributeCode>
                        <value>
                            <xsd:string>3</xsd:string>
                            <xsd:string>4</xsd:string>
                        </value>
                    </item>
                    <item>
                        <attributeCode>options_container</attributeCode>
                        <value>container2</value>
                    </item>
                    <item>
                        <attributeCode>required_options</attributeCode>
                        <value>0</value>
                    </item>
                    <item>
                        <attributeCode>has_options</attributeCode>
                        <value>0</value>
                    </item>
                    <item>
                        <attributeCode>image_label</attributeCode>
                        <value>Image</value>
                    </item>
                    <item>
                        <attributeCode>small_image_label</attributeCode>
                        <value>Image</value>
                    </item>
                    <item>
                        <attributeCode>thumbnail_label</attributeCode>
                        <value>Image</value>
                    </item>
                    <item>
                        <attributeCode>msrp_display_actual_price_type</attributeCode>
                        <value>0</value>
                    </item>
                    <item>
                        <attributeCode>url_key</attributeCode>
                        <value>joust-duffle-bag</value>
                    </item>
                    <item>
                        <attributeCode>tax_class_id</attributeCode>
                        <value>0</value>
                    </item>
                    <item>
                        <attributeCode>activity</attributeCode>
                        <value>11,19,21,22</value>
                    </item>
                    <item>
                        <attributeCode>style_bags</attributeCode>
                        <value>25,26,29</value>
                    </item>
                    <item>
                        <attributeCode>material</attributeCode>
                        <value>37,38</value>
                    </item>
                    <item>
                        <attributeCode>strap_bags</attributeCode>
                        <value>61,62,63,64,65,66</value>
                    </item>
                    <item>
                        <attributeCode>features_bags</attributeCode>
                        <value>74,76,79</value>
                    </item>
                    <item>
                        <attributeCode>eco_collection</attributeCode>
                        <value>0</value>
                    </item>
                    <item>
                        <attributeCode>performance_fabric</attributeCode>
                        <value>0</value>
                    </item>
                    <item>
                        <attributeCode>erin_recommends</attributeCode>
                        <value>0</value>
                    </item>
                    <item>
                        <attributeCode>new</attributeCode>
                        <value>0</value>
                    </item>
                    <item>
                        <attributeCode>sale</attributeCode>
                        <value>0</value>
                    </item>
                    <item>
                        <attributeCode>eboekhouden_grootboekrekening</attributeCode>
                        <value>8000</value>
                    </item>
                    <item>
                        <attributeCode>eboekhouden_costcenter</attributeCode>
                        <value>0</value>
                    </item>
                </customAttributes>
            </result>
        </ns1:catalogProductRepositoryV1GetResponse>
    </env:Body>
</env:Envelope>

【问题讨论】:

    标签: magento magento2 magento-2.0


    【解决方案1】:

    在产品详细信息 SOAP 调用中,即 catalogProductRepositoryV1 您会在 customAttributes 标签中找到 category_ids 作为一个项目

    <customAttributes>
    ...
    <item>
        <attributeCode>category_ids</attributeCode>
        <value>
            <xsd:string>3</xsd:string>
            <xsd:string>4</xsd:string>
        </value>
    </item>
    ...
    </customAttributes>
    

    如果您想从 catalogCategoryRepositoryV1

    获取任何信息,则需要加载类别

    【讨论】:

    • 所以,它一直在响应中......叹息。我现在明白为什么我以前没有看到它。如果你使用catalogProductRepositoryV1GetListRequest,你不会得到customAttribute category_ids..
    • 在List Api中只有默认值,category_ids在Product detail API中
    猜你喜欢
    • 2011-05-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-06
    • 2019-08-09
    • 2012-07-27
    相关资源
    最近更新 更多