2

We have a store setup using ExpressionEngine and Expresso Store, it's all working great however we now need to integrate with another system. This system imports information on orders, it's basically a CRM system, it required an XML file to be produced each time an order is processed, we've managed to produce an XML feed for these orders but unfortunatently it requires a seperate file for EACH order. This is the XML we produced:

<?xml version="1.0" encoding="UTF-8"?>
<Clarity xmlns="http://www.touchsystems.co.uk/schemas" Type="Order" DateTime="2011-04-04T17:58:41.000000" Source="Customer Website">

  {exp:store:orders}
  <Contact>
    <Name>{billing_name}</Name>
    <Company></Company>
    <Telephone>{billing_phone}</Telephone>
    <Email>{order_email}</Email>
    <Address>
      <Address1>{billing_address1} {billing_address2}</Address1>
      <City>{billing_address3}</City>
      <County>{billing_region_name}</County>
      <Postcode>{billing_postcode}</Postcode>
      <Country>United Kingdom</Country>
    </Address>
    <Detail>
      <Title></Title>
      <Extension></Extension>
      <Fax></Fax>
      <Website></Website>
    </Detail>
    <Comment></Comment>
    <Document>
      <Title>Online Order REF {order_id}</Title>
      <Notes>Here are some example order notes</Notes>
      <Detail>
        <Terms>Delivery within 30 days of payment</Terms>
        <CustOrderNo>{order_id}</CustOrderNo>
        <RequiredDate>{order_date}</RequiredDate>
      </Detail>
      {items}
      <Item>
        <Partcode>{sku}</Partcode>
        <Description>{title} {modifiers}{modifier_name} {modifier_value} {if price_mod_val}({price_mod}){/if}{/modifiers}</Description>
        <Quantity>{item_qty}</Quantity>
        <UnitPrice>{price} - {item_subtotal}</UnitPrice>
      </Item>
      {/items}
      <Totals>
      </Totals>
      <DeliveryAddress>
        <Contact>{shipping_name}</Contact>
        <Address1>{shipping_address1}</Address1>
        <Address2>{shipping_address2}</Address2>
        <City>{shipping_address3}</City>
        <County>{shipping_region_name}</County>
        <Postcode>{shipping_postcode}</Postcode>
        <Telephone>{shipping_phone}</Telephone>
      </DeliveryAddress>
    </Document>
  </Contact>
  {/exp:store:orders}
</Clarity> 

But we're not really sure how to go about generating a single XML file per order, will we need to do this with PHP or can ExpressionEngine handle this? Any ideas would be really appreciated!

3

Looks like you have working code to generate XML for multiple orders, and generating XML for a single order is easy by just including the order_hash or order_id parameter.

The only problem then is how to move these files into an FTP directory for your CRM. To do this you could either set up a nightly script to check for new orders and save their XML to a particular folder, or as Derek mentioned in the comments, you could use the store_order_complete_end hook to do this immediately after the order is saved.

4
  • Thanks Adrian, do you think we could potentially add a script to the order complete template that generates an XML file when the page is visited? Guessing this would need to be PHP? This page should only be accessed once an order is processed. Or would this method generally be frowned upon?
    – Nick
    Dec 17 '13 at 12:42
  • You could. But it's a little unreliable (if the page is visited again it will keep generating new files). It's probably going to be about the same amount of work to keep the XML URL secret, and set up a simple extension which downloads that URL to a file on the server (or generate the XML straight from the extension, which would be better still but requires a little bit more experience with PHP). Dec 17 '13 at 19:33
  • Thanks, we ended up building a custom extension for this
    – Nick
    Feb 24 '14 at 10:58
  • Hi Nick, did your custom extension simply fetch the XML template and save the output to disk, or did it generate the XML itself as well? I'm looking for a solution that will do the former, but for CSV: expressionengine.stackexchange.com/questions/30358/…
    – Sandwich
    Mar 4 '15 at 14:15
3

You could have an admin-only page where you list orders using store:orders, and have each link to the order detail via its order_hash.

{exp:store:orders}
{if count  == "1"}<ul>{/if}
    <li><a href="{path="orders/view/{order_hash}">Order #{order_id}</a></li>
{if count  == total_results}</ul>{/if}
{/exp:store:orders}

Then orders/view looks like:

{exp:store:orders order_hash="{segment_3}"}
    // your XML template here
{/exp:store:orders}

You'd want to add something like {if logged_in_member_group != "1"}{redirect="404"}{/if} to each page to make sure prying eyes could not see.

2
  • Thanks Derek, looks like a great solution. The issue we have is that the system we're syncing with requires physical XML files in an FTP directory so the site has to automatically generate one of these when an order is placed, would this be possible?
    – Nick
    Dec 16 '13 at 14:30
  • 1
    Ah - trickier then. Have a look at the store_order_complete_end hook - you could write an extension which uses that hook, loads your template programatically, then saves the result on the server. Lots of steps to work out there though. Dec 16 '13 at 17:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.