I have a requirement to create a scheduled task that will send orders (since the last time the task ran) to an external web service. The data needs to be sent in cXML format and one xml per order. It needs to be the cXML formatted data rather than actual file.
I'm looking for some advice really on how best to accomplish this. I have created a base module with a cronjob that will run every 5 minutes.
I have a Model/Export.php as follows that is pretty basic at the moment to just get orders with specific statuses;
class OrderSync_Model_Export
{
public function ExportSales()
{
//A collection of orders
$order = Mage::getModel('sales/order')->getCollection();
$order->addAttributeToFilter('status', array('in' => array('pending','complete')));
$orders = $order->getItems();
}
}
I obviously then need to get the specific data from each order but the part i'm not sure is how to get/send each individual order as cXML ( http://cxml.org/) to the web service. I assume I would probably need to cURL this to the web service but it's the part about sending each individual order when the cronjob runs that i'm not so sure of and wondered if someone might be able to help?
Also, the web service returns a response for each order cXML that it receives like so and I'd like to be able to update an order attribute with the status detail (code and text) if anyone has any pointers for this too?
The example response is as follows;
<?xml version="1.0" encoding="utf-16"?>
<cXML payloadID="int.coupahost.com" xml:lang="en" timestamp="2017-04-06T11:43:25.2681984+01:00">
<Response>
<Status code="500" text="Price does not match current pricelist- 653244 Possibly out of date Pricelist, Please contact supplier for updated pricelist " />
</Response>
</cXML>