首页 文章

在Magento 1.9 SOAP V2中获取具有属性的产品

提问于
浏览
0

我正在构建一个通过他们的Soap v1 api与Magento集成的第三方服务,但我遇到了一些问题 .

我想从网上商店获得所有产品 . 这包括产品的 Headers ,描述,价格,库存状态,主要图像,sku,产品类型,品牌,可用性,销售状态等 . 到目前为止,我的代码如下所示:

$domain    = 'https://domain/';
$apiUser = 'xxxx';
$apiKey  = 'xxxx';

$client = new SoapClient("{$domain}/api/v2_soap/?wsdl");
$session = $client->login($apiUser, $apiKey);

$filters = ['complex_filter' => [[
    'key' => 'type',
    'value' => ['key' => 'in', 'value' => 'simple,configurable']
]]];

$products = [];
$items = $client->catalogProductList($session, $filters);

foreach ($items as $product) {
    $products[] = $client->catalogProductInfo($session, $product['product_id']);
}

产品数组中每个元素的响应和内容:

{
    "product_id": "x",
    "sku": "x",
    "set": "x",
    "type": "x",
    "categories": ["1","2","3", ...],
    "websites": ["1"],
    "created_at": "x",
    "updated_at": "x",
    "type_id": "simple",
    "name": "x",
    "description": "x",
    "short_description": "x",
    "weight": "x",
    "status": "x",
    "url_key": "x",
    "url_path": "x",
    "visibility": "x",
    "category_ids": ['1', '2', '3', ...],
    "has_options": "0",
    "price": "x",
    "tax_class_id": "x",
    "tier_price": [],
    "custom_design": "x",
    "options_container": "x"
}

正如您所看到的,我缺少库存状态,主要图像,产品类别/类型,品牌,可用性,销售状态等 . 我将如何在请求中急切加载它们 . 我可以再次为每个产品发出新请求,但我不希望重复出现请求循环 . 这让我想到了下一个问题 .

如何使用Soap api在一个或两个请求中获取所有具有属性和所有内容的产品? foreach循环现在为每个产品创建一个新请求,但我不希望...

我真的无法弄清楚这一点 . 我们高度赞赏的例子是:D

1 回答

  • 1

    为了记录,Magento的API太可怕了!您认为他们的API将支持检索具有库存属性的产品而无需任何额外的努力 . 好消息是有更好的方法 . 坏消息是它需要在服务器上进行额外配置 . 在主机上,将所需的任何字段插入文件app / code / core / Mage / Catalog / etc / wsdl.xml,如下所示:

    ...
    <complexType name="catalogProductEntity">
    <all>
        <element name="product_id" type="xsd:string"/>
        <element name="sku" type="xsd:string"/>
        <element name="name" type="xsd:string"/>
        <element name="set" type="xsd:string"/>
        <element name="type" type="xsd:string"/>
        <element name="category_ids" type="typens:ArrayOfString"/>
        <element name="website_ids" type="typens:ArrayOfString"/>
        <element name="price" type="xsd:string"/>
        <element name="description" type="xsd:string"/>
    </all>
    </complexType>
    ...
    

    当然不是最好的解决方案,但有效并且不需要多个要求 .

相关问题