Reputation: 298
I'm building a 3nd party service that integrates with Magento through their Soap v1 api, but I run into some issues.
I want to get all products from the webshop. This includes the product's title, description, price, stock status, main image, sku, product type, brand, availability, sale status, etc. So far my code looks like this:
$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']);
}
Response and content of each element in the products array:
{
"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"
}
As you can see, I'm missing the stock status, main image, product category/type, brand, availability, sale status, etc. How would I go about eager loading them as part of the request. I could make a new request for each product again, but I don't want the recurring loop of requests. This brings me to my next question.
How can I get all of the products with their attributes and everything in one or maybe two requests using the Soap api? The foreach loop creates a new request for each product right now, but I don't want that...
I really can't figure this on out. Examples are we highly appreciated :D
Upvotes: 0
Views: 1642
Reputation: 9591
For the record, Magento's API is horrible! You'd think their API would support retrieving products with stock attributes without any additional effort. The good news is there's a better way. The bad news is that it requires additional configuration on the server. On the host, insert any fields you need into the file app/code/core/Mage/Catalog/etc/wsdl.xml like this:
...
<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>
...
Certainly not the best solution, but works and doesn't require multiple requires.
Upvotes: 1