title: Prestashop 1.7 Exporting orders to XML
body: <p>Can you please help me with below script? It imports a specific order and displays in XML format.
  The problem is that, a random records (product IDs) can be presented 2-times. As result I need to verify every time, whether the output includes the mistake or not. To sum up, how to improve this script in order to be sure that every output will be 100% correct?</p>
  
  <pre><code>&lt;?php 
      header('Content-type: text/xml');
      $xml="&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;";
      // import Prestashop settings
  ?&gt;
  &lt;ZAM&gt;
  &lt;?php
  $zamowienie = $_GET['zamowienie'];
  $context = Context::getContext();
  $id_lang = (int)Configuration::get('PS_LANG_DEFAULT', (int)$context-&gt;shop-&gt;id);
  $order_details = Db::getInstance()-&gt;ExecuteS('
  SELECT o.reference, o.date_add, o.id_order, message
  FROM '._DB_PREFIX_.'orders o
  LEFT JOIN '._DB_PREFIX_.'customer_message pl ON (pl.date_add = o.date_add)
  WHERE o.reference = "'.$zamowienie.'"');
  
  $order_details2 = Db::getInstance()-&gt;ExecuteS('
  SELECT o.id_order, od.product_reference, od.product_quantity
  FROM '._DB_PREFIX_.'orders o
  LEFT JOIN '._DB_PREFIX_.'order_detail od ON (od.id_order = o.id_order)
  LEFT JOIN '._DB_PREFIX_.'product_lang pl ON (pl.id_product = od.product_reference)
  WHERE o.reference = "'.$zamowienie.'"');
  
  foreach ($order_details as &amp;$od){
      echo "&lt;NAG&gt;";
          echo "&lt;numer&gt;".$od['id_order']."&lt;/numer&gt;";
          echo "&lt;data&gt;".$od['date_add']."&lt;/data&gt;";
          echo "&lt;numer_zam&gt;".$od['reference']."&lt;/numer_zam&gt;";
          echo "&lt;uwagi&gt;".$od['message']."&lt;/uwagi&gt;";
      echo "&lt;/NAG&gt;";
  }
  foreach ($order_details2 as &amp;$od){
      echo "&lt;POZ&gt;";
          echo "&lt;numer&gt;".$od['id_order']."&lt;/numer&gt;";
          echo "&lt;tw_id&gt;".$od['product_reference']."&lt;/tw_id&gt;";
          echo "&lt;zam_ilo&gt;".$od['product_quantity']."&lt;/zam_ilo&gt;";
      echo "&lt;/POZ&gt;";
  };
  
  ?&gt;
  &lt;/ZAM&gt;
  </code></pre>