Im trying to get a list of items from an order to display correctly on my webpage using the SOAP API. I have managed to display shipping, billing and general info, and i have also managed to display the list of items... BUT for some reason i am getting duplicate results with a price and row_total equaling zero, the picture below shows what i mean:
items_display
So as you can see there are 2 records for ink_med and 2 for coal_sm, but only 1 record for the last entry.
My question to you guys is, how do i stop the duplicate records?
Here is the call im using to retrieve the order items:
$sales_order_info = $this->client->salesOrderInfo($this->sessionID,$o->increment_id);
And i access the items array by using this:
foreach($sales_order_info->items as $i)
Any help will be appreciated thank you
5 Answers 5
This is because the items are configurables, and you will get both the configurable and the corresponding simple product in your collection. The simple items that belong to a confirable will have the parent_id (where this is the item_id of the configurable). This way you can filter out the duplicate items and only show the items you want.
-
Ok thanks for the info, so will it be better to show the configurable or the simple product? ThanksTom Burman– Tom Burman2013年11月03日 11:01:22 +00:00Commented Nov 3, 2013 at 11:01
-
I have just looked on the back end of magento, and the products are simple...not configurable? Im using magentos sample data by the wayTom Burman– Tom Burman2013年11月03日 11:08:36 +00:00Commented Nov 3, 2013 at 11:08
-
The ink_med shirt is a simple product that is a child product of the sku 'ink' and that is a configurable product. Looking at the sales_order/view template Magento displays only the parent items (it skips the rows where the item has a parent item, this is also the records where the price is available.Vladimir Kerkhoff– Vladimir Kerkhoff2013年11月03日 12:09:32 +00:00Commented Nov 3, 2013 at 12:09
-
Oh i see now. Ok so what is the best way to filter out the simple from the configurable? I also dont understand what you mean with your last sentence? Do you mean i should therefore just list the simple products? ThanksTom Burman– Tom Burman2013年11月03日 14:32:24 +00:00Commented Nov 3, 2013 at 14:32
-
You should just list the configurable items, if you check the array you can skip all the records that have the parent_id setupVladimir Kerkhoff– Vladimir Kerkhoff2013年11月03日 15:51:08 +00:00Commented Nov 3, 2013 at 15:51
What Vladimir Kerkhoff has written is right. You get both the configurable product and also the corresponding simple product.
But i want to add, in Magento 1.9.2, maybe earlier, there is no parent_id in the soap api available. So his solution did not work for me.
I had to extend the api. Fortunately this is quite easy. Create a barebones extension and add a file wsdl.xml to the etc-folder of this extension.
Paste the following into this File:
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns:typens="urn:{{var wsdl.name}}" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/"
name="{{var wsdl.name}}" targetNamespace="urn:{{var wsdl.name}}">
<types>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:Magento">
<import namespace="http://schemas.xmlsoap.org/soap/encoding/" schemaLocation="http://schemas.xmlsoap.org/soap/encoding/" />
<complexType name="salesOrderItemEntity">
<all>
<element name="parent_item_id" type="xsd:string" minOccurs="0" />
</all>
</complexType>
</schema>
</types>
</definitions>
parent_item_id is your key for the soap api then.
-
Had to clear magento cache (var/cache folder) for extra field to appearFrEaKmAn– FrEaKmAn2017年05月28日 21:02:08 +00:00Commented May 28, 2017 at 21:02
Using the SOAP api, in the salesOrderItemEntity array, there should be a 'parent_item_id' attribute. Probably you want the configurable item only(that's where the price is) and want to filter out the child products while still allowing 'normal' simple products through.
if ($i['product_type'] == 'configurable' || ($i['product_type'] == 'simple' && $i['parent_item_id'] == null)){
// insert info into your ERP or do something with the product
}
for mage 1.9.x
Do what @Upperface wrote but with the correct complex type name salesOrderItemEntity
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns:typens="urn:{{var wsdl.name}}" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns="http://schemas.xmlsoap.org/wsdl/"
name="{{var wsdl.name}}" targetNamespace="urn:{{var wsdl.name}}">
<types>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:Magento">
<import namespace="http://schemas.xmlsoap.org/soap/encoding/"
schemaLocation="http://schemas.xmlsoap.org/soap/encoding/"/>
<complexType name="salesOrderItemEntity">
<all>
<element name="parent_item_id" type="xsd:string" minOccurs="0"/>
</all>
</complexType>
</schema>
</types>
</definitions>
make sure You use correct URL otherwise you can't see parent_item_id.