<p>You could write a custom <a href="http://craftcms.com/docs/plugins" rel="nofollow noreferrer">Craft plugin</a> (generate the boilerplate for it at <a href="https://pluginfactory.io" rel="nofollow noreferrer">https://pluginfactory.io</a>) that listened to one of Craft Commerce's order events.  Likely <a href="https://craftcommerce.com/docs/events-reference#commerce_orders.onsaveorder" rel="nofollow noreferrer">onSaveOrder</a> or <a href="https://craftcommerce.com/docs/events-reference#commerce_orders.onordercomplete" rel="nofollow noreferrer">onOrderComplete</a> depending on your specific requirements.</p>

<p>From there, your plugin could build the CSV the old fashioned way in PHP, or use something like the <a href="https://github.com/thephpleague/csv" rel="nofollow noreferrer">CSV library</a> to do the heavy lifting for you.</p>

<p>Once you've built the CSV, you can use Craft's <a href="https://craftcms.com/classreference/services/EmailService#sendEmail-detail" rel="nofollow noreferrer">EmailService->sendEmail()</a> (accessible through <code>craft()-&gt;email-&gt;sendEmail()</code> to add the attachment and shoot the email off.</p>

CC BY-SA 4.0
2018-10-12T13:39:31.560Z
I was really taken back to see that there is no built-in way to get orders out of craft commerce. It seems like a fairly big oversight. This platform seems unfinished to me.
David A McInnis
CC BY-SA 3.0
2017-05-16T21:51:59.273Z
2017-05-16T21:51:59.273Z
Brad Bell
<p>Although I don't like this for some reasons, my client wants Craft Commerce to directly send specific formatted CSV file to their CRM system for each order.</p>

<p>Is it possible to write a Craft Commerce plugin to allow such a feature ?</p>

<plugin-development><plugin-craftcommerce>
Craft Commerce: Export each order to a specific CSV file and send it throught email
# Craft Commerce: Export each order to a specific CSV file and send it throught email

(Asked by: username_0 on 2017-05-16)

Although I don't like this for some reasons, my client wants Craft Commerce to directly send specific formatted CSV file to their CRM system for each order.

Is it possible to write a Craft Commerce plugin to allow such a feature ?

**Tags:** plugin-development, plugin-craftcommerce


---

## 1 answers

### Answer by username_1 on 2017-05-16. Score: 1 | Accepted answer

You could write a custom [Craft plugin](http://craftcms.com/docs/plugins) (generate the boilerplate for it at <https://pluginfactory.io>) that listened to one of Craft Commerce's order events. Likely [onSaveOrder](https://craftcommerce.com/docs/events-reference#commerce_orders.onsaveorder) or [onOrderComplete](https://craftcommerce.com/docs/events-reference#commerce_orders.onordercomplete) depending on your specific requirements.

From there, your plugin could build the CSV the old fashioned way in PHP, or use something like the [CSV library](https://github.com/thephpleague/csv) to do the heavy lifting for you.

Once you've built the CSV, you can use Craft's [EmailService->sendEmail()](https://craftcms.com/classreference/services/EmailService#sendEmail-detail) (accessible through `craft()->email->sendEmail()` to add the attachment and shoot the email off.

> **Comments:**
> **username_2**: I was really taken back to see that there is no built-in way to get orders out of craft commerce. It seems like a fairly big oversight. This platform seems unfinished to me.  

---

