Question

I'm trying to use salesOrderInfo, but I can't see the coupon code returned anywhere. Is there any way of finding the coupon code for an order?

I'm using the SOAPv2 API with WS-I compliance enabled. My code is just a mock up in VB.NET to test so far, but is very simple...

Dim mc As New BMCore.Magento.Mage_Api_Model_Server_Wsi_HandlerPortTypeClient()
Dim token = mc.login("TheUserName", "TheAPIKey")
Dim response = mc.salesOrderInfo(token, 100000024)

I know that sales order 100000024 definitely has a coupon code and I am retrieving all the other order details ok, just can't see the coupon code anywhere - I've searched the response for both "coupon" and the actual code. I've also checked the response using Fiddler to ensure that there is nothing relevant that is being returned from the server that isn't making it into the object.

Response from Fiddler (anonymised)...

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:Magento">
<SOAP-ENV:Body>
<ns1:salesOrderInfoResponseParam>
<result>
<increment_id>100000024</increment_id>
<store_id>1</store_id>
<created_at>2015-05-28 12:21:50</created_at>
<updated_at>2015-06-04 11:59:30</updated_at>
<customer_id>2</customer_id>
<tax_amount>0.0000</tax_amount>
<shipping_amount>4.9900</shipping_amount>
<discount_amount>-17.1900</discount_amount>
<subtotal>171.9100</subtotal>
<grand_total>159.7100</grand_total>
<total_paid>159.7100</total_paid>
<total_refunded>154.7200</total_refunded>
<total_qty_ordered>9.0000</total_qty_ordered>
<total_invoiced>159.7100</total_invoiced>
<total_offline_refunded>154.7200</total_offline_refunded>
<base_tax_amount>0.0000</base_tax_amount>
<base_shipping_amount>4.9900</base_shipping_amount>
<base_discount_amount>-17.1900</base_discount_amount>
<base_subtotal>171.9100</base_subtotal>
<base_grand_total>159.7100</base_grand_total>
<base_total_paid>159.7100</base_total_paid>
<base_total_refunded>154.7200</base_total_refunded>
<base_total_invoiced>159.7100</base_total_invoiced>
<base_total_offline_refunded>154.7200</base_total_offline_refunded>
<billing_address_id>67</billing_address_id>
<shipping_address_id>68</shipping_address_id>
<store_to_base_rate>1.0000</store_to_base_rate>
<store_to_order_rate>1.0000</store_to_order_rate>
<base_to_global_rate>1.0000</base_to_global_rate>
<base_to_order_rate>1.0000</base_to_order_rate>
<weight>0.0000</weight>
<store_name>Main Website
Main Website Store
Default Store View</store_name>
<remote_ip>xxx.xxx.xxx.xxx</remote_ip>
<status>complete</status>
<state>complete</state>
<applied_rule_ids>2</applied_rule_ids>
<global_currency_code>GBP</global_currency_code>
<base_currency_code>GBP</base_currency_code>
<store_currency_code>GBP</store_currency_code>
<order_currency_code>GBP</order_currency_code>
<shipping_method>matrixrate_matrixrate_20</shipping_method>
<shipping_description>Select Shipping Method - Speedy Delivery ( 1 - 2 Working Days)</shipping_description>
<customer_email>********@gmail.com</customer_email>
<customer_firstname>****</customer_firstname>
<customer_lastname>***********</customer_lastname>
<quote_id>76</quote_id>
<is_virtual>0</is_virtual>
<customer_group_id>1</customer_group_id>
<customer_note_notify>0</customer_note_notify>
<customer_is_guest>0</customer_is_guest>
<email_sent>1</email_sent>
<order_id>34</order_id>
<shipping_address>
<parent_id>34</parent_id>
<address_type>shipping</address_type>
<firstname>****</firstname>
<lastname>*******</lastname>
<street>************</street>
<city>*******</city>
<postcode>*******</postcode>
<country_id>GB</country_id>
<telephone>+********</telephone>
<address_id>68</address_id>
</shipping_address>
<billing_address>
<parent_id>34</parent_id>
<address_type>billing</address_type>
<firstname>****</firstname>
<lastname>*********</lastname>
<street>*********</street>
<city>********</city>
<region>-</region>
<postcode>*********</postcode>
<country_id>GB</country_id>
<telephone>+*********</telephone>
<address_id>67</address_id>
</billing_address>
<items>
<complexObjectArray>
<item_id>41</item_id>
<order_id>34</order_id>
<quote_item_id>82</quote_item_id>
<created_at>2015-05-28 12:21:50</created_at>
<updated_at>2015-06-04 11:59:30</updated_at>
<product_id>1</product_id>
<product_type>simple</product_type>
<product_options>a:1:{s:15:"info_buyRequest";a:5:{s:4:"uenc";s:172:"aHR0cDovL3N0YWdpbmcuYmFyZ2Fpbm1heC5jby51ay90eXBlLW9mLXRveS9kb2xscy1wbGF5c2V0cy9vbmUtZGlyZWN0aW9uLWRhcmUtdG8tZHJlYW0tbGlmZS1hcy1vbmUtZGlyZWN0aW9uLWJvb2suaHRtbD9fX19TSUQ9VQ,,";s:7:"product";s:1:"1";s:8:"form_key";s:16:"3tDrSuCZRFCguJAc";s:15:"related_product";s:0:"";s:3:"qty";s:1:"1";}}</product_options>
<weight>0.0000</weight>
<is_virtual>0</is_virtual>
<sku>**********</sku>
<name>*****************k</name>
<applied_rule_ids>2</applied_rule_ids>
<free_shipping>0</free_shipping>
<is_qty_decimal>0</is_qty_decimal>
<no_discount>0</no_discount>
<qty_canceled>0.0000</qty_canceled>
<qty_invoiced>6.0000</qty_invoiced>
<qty_ordered>6.0000</qty_ordered>
<qty_refunded>6.0000</qty_refunded>
<qty_shipped>0.0000</qty_shipped>
<price>19.9900</price>
<base_price>19.9900</base_price>
<original_price>19.9900</original_price>
<base_original_price>19.9900</base_original_price>
<tax_percent>0.0000</tax_percent>
<tax_amount>0.0000</tax_amount>
<base_tax_amount>0.0000</base_tax_amount>
<tax_invoiced>0.0000</tax_invoiced>
<base_tax_invoiced>0.0000</base_tax_invoiced>
<discount_percent>10.0000</discount_percent>
<discount_amount>11.9900</discount_amount>
<base_discount_amount>11.9900</base_discount_amount>
<discount_invoiced>11.9900</discount_invoiced>
<base_discount_invoiced>11.9900</base_discount_invoiced>
<amount_refunded>119.9400</amount_refunded>
<base_amount_refunded>119.9400</base_amount_refunded>
<row_total>119.9400</row_total>
<base_row_total>119.9400</base_row_total>
<row_invoiced>119.9400</row_invoiced>
<base_row_invoiced>119.9400</base_row_invoiced>
<row_weight>0.0000</row_weight>
<weee_tax_applied>a:0:{}</weee_tax_applied>
<weee_tax_applied_amount>0.0000</weee_tax_applied_amount>
<weee_tax_applied_row_amount>0.0000</weee_tax_applied_row_amount>
<base_weee_tax_applied_amount>0.0000</base_weee_tax_applied_amount>
<base_weee_tax_applied_row_amount>0.0000</base_weee_tax_applied_row_amount>
<weee_tax_disposition>0.0000</weee_tax_disposition>
<weee_tax_row_disposition>0.0000</weee_tax_row_disposition>
<base_weee_tax_disposition>0.0000</base_weee_tax_disposition>
<base_weee_tax_row_disposition>0.0000</base_weee_tax_row_disposition>
</complexObjectArray>
<complexObjectArray>
<item_id>42</item_id>
<order_id>34</order_id>
<quote_item_id>97</quote_item_id>
<created_at>2015-05-28 12:21:50</created_at>
<updated_at>2015-06-04 11:59:30</updated_at>
<product_id>7</product_id>
<product_type>simple</product_type>
<product_options>a:1:{s:15:"info_buyRequest";a:5:{s:4:"uenc";s:84:"aHR0cDovL3N0YWdpbmcuYmFyZ2Fpbm1heC5jby51ay90eXBlLW9mLXRveS9kb2xscy1wbGF5c2V0cy5odG1s";s:7:"product";s:1:"7";s:8:"form_key";s:16:"oWVwEWvPQ4F7TCHK";s:9:"productId";s:1:"7";s:3:"qty";s:1:"1";}}</product_options>
<weight>0.0000</weight>
<is_virtual>0</is_virtual>
<sku>*****</sku>
<name>**********</name>
<applied_rule_ids>2</applied_rule_ids>
<free_shipping>0</free_shipping>
<is_qty_decimal>0</is_qty_decimal>
<no_discount>0</no_discount>
<qty_canceled>0.0000</qty_canceled>
<qty_invoiced>2.0000</qty_invoiced>
<qty_ordered>2.0000</qty_ordered>
<qty_refunded>2.0000</qty_refunded>
<qty_shipped>0.0000</qty_shipped>
<price>5.9900</price>
<base_price>5.9900</base_price>
<original_price>5.9900</original_price>
<base_original_price>5.9900</base_original_price>
<tax_percent>0.0000</tax_percent>
<tax_amount>0.0000</tax_amount>
<base_tax_amount>0.0000</base_tax_amount>
<tax_invoiced>0.0000</tax_invoiced>
<base_tax_invoiced>0.0000</base_tax_invoiced>
<discount_percent>10.0000</discount_percent>
<discount_amount>1.2000</discount_amount>
<base_discount_amount>1.2000</base_discount_amount>
<discount_invoiced>1.2000</discount_invoiced>
<base_discount_invoiced>1.2000</base_discount_invoiced>
<amount_refunded>11.9800</amount_refunded>
<base_amount_refunded>11.9800</base_amount_refunded>
<row_total>11.9800</row_total>
<base_row_total>11.9800</base_row_total>
<row_invoiced>11.9800</row_invoiced>
<base_row_invoiced>11.9800</base_row_invoiced>
<row_weight>0.0000</row_weight>
<weee_tax_applied>a:0:{}</weee_tax_applied>
<weee_tax_applied_amount>0.0000</weee_tax_applied_amount>
<weee_tax_applied_row_amount>0.0000</weee_tax_applied_row_amount>
<base_weee_tax_applied_amount>0.0000</base_weee_tax_applied_amount>
<base_weee_tax_applied_row_amount>0.0000</base_weee_tax_applied_row_amount>
<weee_tax_disposition>0.0000</weee_tax_disposition>
<weee_tax_row_disposition>0.0000</weee_tax_row_disposition>
<base_weee_tax_disposition>0.0000</base_weee_tax_disposition>
<base_weee_tax_row_disposition>0.0000</base_weee_tax_row_disposition>
</complexObjectArray>
<complexObjectArray>
<item_id>43</item_id>
<order_id>34</order_id>
<quote_item_id>99</quote_item_id>
<created_at>2015-05-28 12:21:50</created_at>
<updated_at>2015-06-04 11:59:30</updated_at>
<product_id>9</product_id>
<product_type>simple</product_type>
<product_options>a:1:{s:15:"info_buyRequest";a:5:{s:4:"uenc";s:140:"aHR0cDovL3N0YWdpbmcuYmFyZ2Fpbm1heC5jby51ay90eXBlLW9mLXRveS9kb2xscy1wbGF5c2V0cy9tb25zdGVyLWhpZ2gtY2xlby12YW5pdHktZHJlc3NpbmctdGFibGUuaHRtbA,,";s:7:"product";s:1:"9";s:8:"form_key";s:16:"wRoD321eMVPMS5Kp";s:15:"related_product";s:0:"";s:3:"qty";s:1:"1";}}</product_options>
<weight>0.0000</weight>
<is_virtual>0</is_virtual>
<sku>********</sku>
<name>********************</name>
<applied_rule_ids>2</applied_rule_ids>
<free_shipping>0</free_shipping>
<is_qty_decimal>0</is_qty_decimal>
<no_discount>0</no_discount>
<qty_canceled>0.0000</qty_canceled>
<qty_invoiced>1.0000</qty_invoiced>
<qty_ordered>1.0000</qty_ordered>
<qty_refunded>1.0000</qty_refunded>
<qty_shipped>0.0000</qty_shipped>
<price>39.9900</price>
<base_price>39.9900</base_price>
<original_price>39.9900</original_price>
<base_original_price>39.9900</base_original_price>
<tax_percent>0.0000</tax_percent>
<tax_amount>0.0000</tax_amount>
<base_tax_amount>0.0000</base_tax_amount>
<tax_invoiced>0.0000</tax_invoiced>
<base_tax_invoiced>0.0000</base_tax_invoiced>
<discount_percent>10.0000</discount_percent>
<discount_amount>4.0000</discount_amount>
<base_discount_amount>4.0000</base_discount_amount>
<discount_invoiced>4.0000</discount_invoiced>
<base_discount_invoiced>4.0000</base_discount_invoiced>
<amount_refunded>39.9900</amount_refunded>
<base_amount_refunded>39.9900</base_amount_refunded>
<row_total>39.9900</row_total>
<base_row_total>39.9900</base_row_total>
<row_invoiced>39.9900</row_invoiced>
<base_row_invoiced>39.9900</base_row_invoiced>
<row_weight>0.0000</row_weight>
<weee_tax_applied>a:0:{}</weee_tax_applied>
<weee_tax_applied_amount>0.0000</weee_tax_applied_amount>
<weee_tax_applied_row_amount>0.0000</weee_tax_applied_row_amount>
<base_weee_tax_applied_amount>0.0000</base_weee_tax_applied_amount>
<base_weee_tax_applied_row_amount>0.0000</base_weee_tax_applied_row_amount>
<weee_tax_disposition>0.0000</weee_tax_disposition>
<weee_tax_row_disposition>0.0000</weee_tax_row_disposition>
<base_weee_tax_disposition>0.0000</base_weee_tax_disposition>
<base_weee_tax_row_disposition>0.0000</base_weee_tax_row_disposition>
</complexObjectArray>
</items>
<payment>
<parent_id>34</parent_id>
<amount_ordered>159.7100</amount_ordered>
<shipping_amount>4.9900</shipping_amount>
<base_amount_ordered>159.7100</base_amount_ordered>
<base_shipping_amount>4.9900</base_shipping_amount>
<method>sagepaydirectpro</method>
<cc_type>*****</cc_type>
<cc_last4>****</cc_last4>
<cc_owner>**** ****</cc_owner>
<cc_exp_month>**</cc_exp_month>
<cc_exp_year>****</cc_exp_year>
<cc_ss_start_month>0</cc_ss_start_month>
<cc_ss_start_year>0</cc_ss_start_year>
<payment_id>34</payment_id>
</payment>
<status_history>
<complexObjectArray>
<parent_id>34</parent_id>
<created_at>2015-06-04 11:59:30</created_at>
<is_customer_notified>0</is_customer_notified>
<status>complete</status>
</complexObjectArray>
<complexObjectArray>
<parent_id>34</parent_id>
<created_at>2015-06-04 11:59:30</created_at>
<is_customer_notified>2</is_customer_notified>
<status>processing</status>
<comment>Refunded amount of £154.72 offline.</comment>
</complexObjectArray>
<complexObjectArray>
<parent_id>34</parent_id>
<created_at>2015-05-28 12:21:50</created_at>
<is_customer_notified>1</is_customer_notified>
<status>processing</status>
</complexObjectArray>
</status_history>
</result>
</ns1:salesOrderInfoResponseParam>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Was it helpful?

Solution 2

Looks like salesOrderInfo doesn't return the coupon_code, but salesOrderList does - I had to dig around inside the WSDL to discover that. Doesn't seem very logical, but looks like Tim Hallman's answer actually refers to salesOrderList and not salesOrderInfo. The following code in VB.NET returns it...

Dim mc As New Magento.Mage_Api_Model_Server_Wsi_HandlerPortTypeClient()
Dim token = mc.login("TheUserName", "TheAPIKey")
Dim f As New Magento.filters()
f.filter = New Magento.associativeEntity() {
    New Magento.associativeEntity With {.key = "increment_id", .value = 100000024}}

Dim sol = mc.salesOrderList(token, f)

The result is then in sol(0).coupon_code

OTHER TIPS

Depending on which version (1 or 2) and which type (SOAP or RESTful) api you're using will depend on the correct method to retrieve the data, but either way using method salesOrderInfo will return an array with coupon code like

array
  'state' => string 'new' (length=3)
  'status' => string 'pending' (length=7)
  'coupon_code' => null
  'protect_code' => string 'defe18' (length=6)
  'shipping_description' => string 'Flat Rate - Fixed' (length=17)
...

I am not sure how to write the code in VB.net, but in php V2 would look like this:

$client = new SoapClient('http:/magentoinstall.local/api/v2_soap?wsdl=1');

$session = $client->login('user', 'pass');    
$filter = new StdClass();
$filter->filter = array(array("key" => "sales_order", "value" => "100000024"));
$list = $client->salesOrderInfo($session, $filter);

So I'm wondering if/how you are passing filters through your VB script.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top