We are moving to BC and I am getting orders through the api while using the usexml function as I have to output a file for each order. I have been successful getting orders, products in the orders, and shipping address from BC. I have had to add a number of function to the bigcommerce.php library to do this, as while they may be referenced in the online docs, they don't actually exist in the library. My last step is getting the coupons associated with an order. The functions which I implemented in the library are as follows:
// Function missing from library addded 030215 PH - Get products on an order
public static function getOrderProducts($id)
{
return self::getCollection('/orders/' . $id . '/products','Order');
}
// Function missing form library added 030215 - Get Shipping adds on order
public static function getOrderShippingAddresses($id)
{
return self::getCollection('/orders/' . $id .'/shipping_addresses','Order');
}
// Function missing form library added 030215 - Get Coupons on an order
public static function getOrderCoupons($id)
{
return self::getCollection('/orders/' . $id . '/coupons','Order');
}
While similar in syntax I can't get the getOrderCoupons function to return coupon info to substitute for the link provided in the normal getOrders return.
I am using the same logic for coupon as executed for getting shipping addresses as shown below. Any solutions are greatly appreciated.
N.B Bigcommerce::useXML(); is used so XML strings are being used
$shipping_xml = Bigcommerce::getOrderShippingAddresses($order->id);
$shippings = simplexml_load_string($shipping_xml);
// Should only have one shipping address per order
foreach($shippings as $shipping) {
$xmlship = $shipping->asXML();
$domship = new DOMDocument();
$domship = dom_import_simplexml($shipping);
$domordship = dom_import_simplexml($order->shipping_addresses);
$domship = $domordship->ownerDocument->importNode($domship, TRUE);
$domordship->appendChild($domship);
}
$coupon_xml = Bigcommerce::getOrderCoupons($order->id);
$coupons = simplexml_load_string($coupon_xml);
// Should only have one coupon per order
foreach($coupons as $coupon) {
$xmlcoup = $coupon->asXML();
$domcoup = new DOMDocument();
$domcoup = dom_import_simplexml($coupon);
$domordcoup = dom_import_simplexml($order->coupons);
$domcoup = $domordcoup->ownerDocument->importNode($domcoup, TRUE);
$domordcoup->appendChild($domcoup);
}