Kryptronic Software Support Forum

You are viewing this forum as a guest. Login to an existing account, or create a new account, to reply to topics and to create new topics.

#1 09-28-2015 09:14:01

nigel
Member
From: Peterborough, UK
Registered: 04-27-2008
Posts: 418
Website

Royal Mail DMO csv file

Hi,

is anyone using Royal Mail DMO, if so can you point me in the right direction for creating the csv file that needs to be imported into DMO.

Offline

 

#2 09-29-2015 06:35:27

webmaster
Administrator
From: York, PA
Registered: 04-20-2001
Posts: 19861
Website

Re: Royal Mail DMO csv file

I'm not familiar with it.  Do you have a link to info you can share?  You can likely get an export file function written for it if you contact our Custom Shop for a quote.


Nick Hendler

Offline

 

#3 09-29-2015 08:25:58

nigel
Member
From: Peterborough, UK
Registered: 04-27-2008
Posts: 418
Website

Re: Royal Mail DMO csv file

Hi Nick,

the below link relates to Ebay documentation but as it says "the same principles apply to any customer who can extract bulk address and postal service particulars into a .csv spreadsheet"

http://www.oybcycles.com/DMO

I think basically what I need is the easiest/quickest way to populate a spreadsheet with all my orders which are marked as "Processing" (on the standard install this would have been "Pending Shipment"). Once I know how to do this I can then see what columns need adding or changing.

I can export the ecom_order table using a where clause to select only the orders marked as "Processing", but I ship to addresses other than the billing address so I need to figure out a way of having the shipping address instead of the billing address on the spreadsheet.

Last edited by nigel (09-29-2015 09:30:01)

Offline

 

#4 09-29-2015 10:52:20

zanart
Member
From: bedford
Registered: 04-02-2008
Posts: 1716

Re: Royal Mail DMO csv file

If you are familiar with PHP you could have a look at the Sage or Peachtree Export files to get an idea of how to get CCP to create the CSV file.

core-private\apps\ecom\ECOM_Export\ext

This would get you started.

If you are not familiar, get a quote from NIck


Rob

Offline

 

#5 09-30-2015 08:01:35

nigel
Member
From: Peterborough, UK
Registered: 04-27-2008
Posts: 418
Website

Re: Royal Mail DMO csv file

thanks for the reply Zanart

The Peachtree Export file looks promising, it's just a case of figuring out how to get all the information into one spreadsheet: shipping name, shipping address, order items, shipping method etc. etc.

peachtree-orders.csv looks like the nearest thing, any idea how I get the SName SAddress SCity SZipCode columns to populate?

Offline

 

#6 09-30-2015 08:43:15

webmaster
Administrator
From: York, PA
Registered: 04-20-2001
Posts: 19861
Website

Re: Royal Mail DMO csv file

I haven't looked at that export in ages.  Are SName, SAddress, SCity and SZipCode in that file now, but not populating for your orders?


Nick Hendler

Offline

 

#7 09-30-2015 08:57:25

nigel
Member
From: Peterborough, UK
Registered: 04-27-2008
Posts: 418
Website

Re: Royal Mail DMO csv file

yes, they are in the file but not populating

Offline

 

#8 09-30-2015 10:09:13

zanart
Member
From: bedford
Registered: 04-02-2008
Posts: 1716

Re: Royal Mail DMO csv file

You need to get a list of order numbers with the correct status into an array.

Then you need to run through this array to create an array of all the orderitems.

Then you need to run through this array to create the csv file, something like this

Code:

    $export_file1 .= $item['orderid']  . ',';
      $export_file1 .= $item['fname']. ' ' . $item['lname'] . ',' ;
     $export_file1 .= $item['company']. ',' ;
     $export_file1 .= $item['addone']. ',' ;
     $export_file1 .= $item['addtwo']. ',' ;

Rob

Offline

 

#9 10-01-2015 07:36:30

webmaster
Administrator
From: York, PA
Registered: 04-20-2001
Posts: 19861
Website

Re: Royal Mail DMO csv file

Correct.  The items with their shipping addresses are each listed in the $order['items'] array.


Nick Hendler

Offline

 

#10 10-14-2015 04:45:18

nigel
Member
From: Peterborough, UK
Registered: 04-27-2008
Posts: 418
Website

Re: Royal Mail DMO csv file

thank Nick and Zanart,

I have adapted the Peachtree export and it works fine. Is it possible to get the order weight into the csv file? I have tried various things but can't get it to work. Below are the 2 parts of the peachtree.php file I have edited, can you tell me the code needed to get the weight into the bottom block of code (I need the total order weight). As you can see below, I have tried {$order['shipweight']} but it does not input the weight into the csv file.

Code:

$export_file1  = "\"CustID\",";
$export_file1 .= "\"Name\",\"Company\",\"Address 1\",\"Address 2\",\"Address 3\",\"Town/City\",\"Postcode\",";
$export_file1 .= "\"Country\",\"Phone\",\"Email\",\"Service Reference\",\"Service\",";
$export_file1 .= "\"Service Enhancement\",\"Service Enhancement 2\",\"Service Format\",\"Items\",\"Weight\"" . $eol;

Code:

$export_file1 .= "\"{$order['id']}\",";
     $export_file1 .= "\"{$item['fname']} {$item['lname']}\",\"{$item['company']}\",\"{$item['addone']}\",\"{$item['addtwo']}\",\"\",\"{$item['city']}\",";
     $export_file1 .= "\"{$item['postalcode']}\",\"{$item['country']}\",\"\",\"{$order['email']}\",";
     $export_file1 .= "\"SR1\",\"CRL1\",\"\",\"\",\"\",\"1\",\"{$order['shipweight']}\",\"\"" . $eol;

Last edited by nigel (10-14-2015 05:38:33)

Offline

 

#11 10-14-2015 07:30:16

webmaster
Administrator
From: York, PA
Registered: 04-20-2001
Posts: 19861
Website

Re: Royal Mail DMO csv file

The shipweight for each item can be found in it's cartdata field, which is a serialized PHP array.  If you create a zero value $weight variable at the beginning of your script, and as you loop through the items, unserialize($item['cartdata']) and look add $item['cartdata']['shipweight'] to your $weight variable.  By the time you need to print the weight, you'll have it.


Nick Hendler

Offline

 

#12 10-19-2015 10:34:32

nigel
Member
From: Peterborough, UK
Registered: 04-27-2008
Posts: 418
Website

Re: Royal Mail DMO csv file

Hi Nick,

I have tried lots of different variations but still can't get the shipweight to show in the output. any chance you can tell me where I am going wrong? Here is the latest variation:

Code:

$item['shipweight'] = $cartdata['shipweight'];
      
      

     // +--
     // | Do the customer information export.
     // +--

     $export_file1 .= "\"{$order['id']}\",";
     $export_file1 .= "\"{$item['fname']} {$item['lname']}\",\"{$item['company']}\",\"{$item['addone']}\",\"{$item['addtwo']}\",\"\",\"{$item['city']}\",";
     $export_file1 .= "\"{$item['postalcode']}\",\"{$item['country']}\",\"\",\"{$order['email']}\",";
     $export_file1 .= "\"SR1\",\"CRL1\",\"\",\"\",\"LL\",\"1\",\"{$item['shipweight']}\",\"{$order['datestamp']}\",\"\"" . $eol;

Offline

 

#13 10-19-2015 14:34:03

zanart
Member
From: bedford
Registered: 04-02-2008
Posts: 1716

Re: Royal Mail DMO csv file

you will probably need to unserialize the cart data first

Code:

$cartdata = unserialize($data['cartdata']);

Rob

Offline

 

#14 10-20-2015 04:28:13

nigel
Member
From: Peterborough, UK
Registered: 04-27-2008
Posts: 418
Website

Re: Royal Mail DMO csv file

Hi Zanart,

thanks for your help, but I am still struggling to get this working. I have tried the following code but it puts all the cart data into the csv file:

Code:

$cartdata = unserialize($data['cartdata']);
      $item['shipweight'] = $item['cartdata'].['shipweight'];
     

     // +--
     // | Do the customer information export.
     // +--

     $export_file1 .= "\"{$order['id']}\",";
     $export_file1 .= "\"{$item['fname']} {$item['lname']}\",\"{$item['company']}\",\"{$item['addone']}\",\"{$item['addtwo']}\",\"\",\"{$item['city']}\",";
     $export_file1 .= "\"{$item['postalcode']}\",\"{$item['country']}\",\"\",\"{$order['email']}\",";
     $export_file1 .= "\"SR1\",\"CRL1\",\"\",\"\",\"LL\",\"1\",\"{$item['shipweight']}\",\"{$order['datestamp']}\",\"\"" . $eol;

Offline

 

#15 10-20-2015 06:05:54

zanart
Member
From: bedford
Registered: 04-02-2008
Posts: 1716

Re: Royal Mail DMO csv file

try

Code:

$cartdata = unserialize($item['cartdata']);

$shipweight = $cartdata['shipweight'];

Rob

Offline

 

#16 10-20-2015 06:37:47

nigel
Member
From: Peterborough, UK
Registered: 04-27-2008
Posts: 418
Website

Re: Royal Mail DMO csv file

Hi Zanart,

I tried that but still no data appearing in the csv file. I also tried a few other variations without any success.

Code:

$cartdata = unserialize($item['cartdata']);
      $shipweight = $cartdata['shipweight'];
      //$shipweight = $item['shipweight'];
      //$item['shipweight'] = $item['shipweight'];
      //$item['shipweight'] = $cartdata['shipweight'];

Offline

 

#17 10-21-2015 06:49:46

webmaster
Administrator
From: York, PA
Registered: 04-20-2001
Posts: 19861
Website

Re: Royal Mail DMO csv file

The following should work:

Code:

$cartdata = unserialize($item['cartdata']);
$shipweight = $cartdata['shipweight'];

Nick Hendler

Offline

 

#18 10-21-2015 07:40:14

zanart
Member
From: bedford
Registered: 04-02-2008
Posts: 1716

Re: Royal Mail DMO csv file

Post the complete code you are using as that should work as long as it is within the foreach statement.


Rob

Offline

 

#19 10-21-2015 07:53:38

nigel
Member
From: Peterborough, UK
Registered: 04-27-2008
Posts: 418
Website

Re: Royal Mail DMO csv file

Hi Zanart,

here is the full code. I tried putting the additional code in a few different places without success. I have now moved them just above export file 1, which is the file I am exporting.

Code:

<?php 

// +------------------------------------------------------------------+
// |                                                                  |
// | Copyright 1999-Present Kryptronic, Inc. All rights reserved.     |
// |                                                                  |
// | This software is copyrighted, trademarked, developed and         |
// | licensed by Kryptronic, Inc. This software is distributed        |
// | under license.                                                   |
// |                                                                  |
// | View the license agreement for more information.  Installation   |
// | of this software package indicates acceptance of the license     |
// | agreement.                                                       |
// |                                                                  |
// +------------------------------------------------------------------+

// +------------------------------------------------------------------+
// | Class Definition                                                 |
// +------------------------------------------------------------------+

class ECOM_Export_peachtree extends ECOM_Export {

var $class   = 'ECOM_Export_peachtree';
var $version = '8.0.0';
var $cerror;

var $CORE_DB;
var $CORE_File;
var $CORE_Display;
var $CORE_Form;

// +------------------------------------------------------------------+
// | Constructor Function                                             |
// +------------------------------------------------------------------+

function ECOM_Export_peachtree () {

// +--
// | This is the class constructor function.
// +--

if ($this->debug) {$this->debugger("constructor: Accessed.");}

// +--
// | Quick object load: CORE_DB
// +--

$this->CORE_DB =& $this->quick_object('CORE_DB','core','CORE_DB_1');

if ($this->IsError($this->CORE_DB)) {$this->cerror = $this->CORE_DB; return;}

// +--
// | Quick object load: CORE_Display
// +--

$this->CORE_Display =& $this->quick_object('CORE_Display','core');

if ($this->IsError($this->CORE_Display)) {$this->cerror = $this->CORE_Display; return;}

// +--
// | Quick object load: CORE_File
// +--

$this->CORE_File =& $this->quick_object('CORE_File','core');

if ($this->IsError($this->CORE_File)) {$this->cerror = $this->CORE_File; return;}

// +--
// | Quick object load: CORE_Form
// +--

$this->CORE_Form =& $this->quick_object('CORE_Form','core');

if ($this->IsError($this->CORE_Form)) {$this->cerror = $this->CORE_Form; return;}

// +--
// | Return $this.
// +--

return;

} // End of function.

// +------------------------------------------------------------------+
// | Function: showform                                               |
// +------------------------------------------------------------------+

function showform () {

// +--
// | This function displays the export setup form.
// +--

$result = $this->CORE_Form->exec_form(array('app'  => 'ecom',
                                            'form' => 'ecom.exppeachtree'));

if ($this->IsError($result)) {return $result;}

// +--
// | Log that we were here.
// +--

if ($this->debug) {$this->debugger("showform: Displayed export form.");}

// +--
// | Return true.
// +--

return 1;

} // End of function.

// +------------------------------------------------------------------+
// | Function: doform                                                 |
// +------------------------------------------------------------------+

function doform () {

// +--
// | This function runs the export and redirects back to the original
// | namespace (if the export was not done for some reason), or to
// | the downloads page with a confirmation message.
// +--

$file1 = $this->globals('core_cgi.ecom--exppeachtree--file1');
$file2 = $this->globals('core_cgi.ecom--exppeachtree--file2');
$file3 = $this->globals('core_cgi.ecom--exppeachtree--file3');

// +--
// | Handle incomplete form data.
// +--

if ((empty($file1)) || (empty($file2)) || (empty($file3))) {

     if ($this->debug) {$this->debugger("doform: Form data incomplete.  Printing message and form again.");}

     return $this->return_wmessage('reqnotcomp');

} // End of if statement.

// +--
// | Set up our data needed for the export based on settings.
// +--

$expsett = array('ptacctrec'           => 1,
                 'ptincitem'           => 1,
                 'ptincship'           => 1,
                 'ptinctaxs'           => 1,
                 'ptinctaxc'           => 1,
                 'ptexpsale'           => 1,
                 'ptexpdisc'           => 1,
                 'ptpayment'           => 1,
                 'ptexployaltypoints'  => 1,
                 'ptincitemt'          => 1,
                 'ptincshipt'          => 1,
                 'ptinctaxst'          => 1,
                 'ptinctaxct'          => 1,
                 'ptexpsalet'          => 1,
                 'ptexpdisct'          => 1,
                 'ptpaymentt'          => 1,
                 'ptexployaltypointst' => 1,
                 'ptincshipd'          => 1,
                 'ptinctaxsd'          => 1,
                 'ptinctaxcd'          => 1,
                 'ptexpsaled'          => 1,
                 'ptexpdiscd'          => 1,
                 'ptpaymentd'          => 1,
                 'ptexployaltypointsd' => 1);

foreach ($expsett as $key => $data) {

     $expsett[$key] = $this->globals('core_settings.ecom.' . $key);

} // End of foreach statement.

// +--
// | Figure out if we have any order that have not been exported which
// | need to be exported.
// +--

$table  = 'ecom_orders';

$where  = "status=" . $this->CORE_DB->quote('PRI') . " AND postordpt<>";
$where .= $this->CORE_DB->quote(1);

$count  = $this->CORE_DB->sql_count(array('table' => $table,
                                          'where' => $where));

if (($this->IsError($count)) || (empty($count))) {$count = 0;}

// +--
// | Return if we have no orders to export.
// +--

if (empty($count)) {

     if ($this->debug) {$this->debugger("doform: No information to export.  Returning.");}

     return $this->return_wmessage('expnodata');

} // End of if statement.

// +--
// | If we're still here, let's grab the order information.
// +--

$table    = 'ecom_orders';

$columns  = $this->CORE_DB->table_column_string($table);

if ($this->IsError($columns)) {return $this->return_wmessage('experror');}

$sql    = "SELECT {$columns} FROM {$table} WHERE ";
$sql   .= "status=" . $this->CORE_DB->quote('PRI') . " AND postordpt<>";
$sql   .= $this->CORE_DB->quote(1);

$orders = $this->CORE_DB->sql_do(array('sql'   => $sql,
                                       'table' => $table,
                                       'order' => array('id' => 'ASC')));

if ($this->IsError($orders)) {return $this->return_wmessage('experror');}
if (empty($orders))          {return $this->return_wmessage('experror');}

// +--
// | Now make a list of order ids we need to use to pull items from the
// | orderitems table.
// +--

$orders_string = '';

foreach ($orders as $num => $order) {

     $orders_string .= 'orderid=' . $this->CORE_DB->quote($order['id']) . ' OR ';

} // End of foreach statement.

if (preg_match('/ OR $/',$orders_string)) {$orders_string = rtrim($orders_string,' OR ');}

if ($this->IsError($orders_string)) {return $this->return_wmessage('experror');}

// +--
// | Pull data from the order items table for each order.
// +--

$table    = 'ecom_orderitems';

$columns  = $this->CORE_DB->table_column_string($table);

if ($this->IsError($columns)) {return $this->return_wmessage('experror');}

$sql    = "SELECT {$columns} FROM {$table} WHERE " . $orders_string;

$orderitems = $this->CORE_DB->sql_do(array('sql'   => $sql,
                                           'table' => $table,
                                           'order' => array('id' => 'ASC')));

if ($this->IsError($orderitems)) {return $this->return_wmessage('experror');}
if (empty($orderitems))          {return $this->return_wmessage('experror');}

// +--
// | Now combine the arrays.
// +--

$ordcomb = array();

foreach ($orders as $num => $order) {

     $ordcomb[$order['id']]['order'] = $order;

} // End of foreach statement.

foreach ($orderitems as $num => $orderitems) {

     $ordcomb[$orderitems['orderid']]['items'][] = $orderitems;
      
      
      

} // End of foreach statement.

// +--
// | Define our end of line character.
// +--

$eol = $this->globals('core.eol');

// +--
// | Begin creating the export files.
// +--

$export_file1  = "\"CustID\",";
$export_file1 .= "\"Name\",\"Company\",\"Address 1\",\"Address 2\",\"Address 3\",\"Town/City\",\"Postcode\",";
$export_file1 .= "\"Country\",\"Phone\",\"Email\",\"Service Ref\",\"Service\",";
$export_file1 .= "\"Enhance\",\"Enhance 2\",\"Format\",\"Items\",\"Weight\",\"Date\"" . $eol;

$export_file2  = "\"Item ID\",\"Item Description\",\"Item Class\",\"Inactive\",\"Item Type\",\"G/L Sales Account\",";
$export_file2 .= "\"Item Tax Type\"" . $eol;

$export_file3  = "\"CustID\",\"CustName\",\"SalesOrderNo\",\"Date\",\"DropShip\",\"SName\",\"SAddress1\",\"SAddress2\",";
$export_file3 .= "\"SCity\",\"SState\",\"SZipcode\",\"SCountry\",\"PONumber\",\"ShipVia\",\"DiscAmt\",\"Terms\",\"Rep\",";
$export_file3 .= "\"ARAccount\",\"ARAmount\",\"SalesCode\",\"InvoiceNote\",\"PrintAfter\",\"DistLines\",\"Quantity\",";
$export_file3 .= "\"Item\",\"Description\",\"ItemAccount\",\"Price\",\"TaxType\",\"LineAmount\",\"TaxAuthority\"" . $eol;

// +--
// | Loop through the data and create the file.
// +--

foreach ($ordcomb as $id => $xorder) {

     // +--
     // | Create quick references.
     // +--

     $order = $xorder['order'];
     $items = $xorder['items'];

     // +--
     // | Quote everything for insertion.
     // +--

     $keys = array_keys($order);

     foreach ($keys as $num => $key) {$order[$key] = $this->ptquote($order[$key]);}

     // +--
     // | Quote everything for insertion.
     // +--

     foreach ($items as $num => $item)  {

          $keys = array_keys($item);

          foreach ($keys as $xnum => $xkey) {$items[$num][$xkey] = $this->ptquote($item[$xkey]);}
            
            

     } // End of foreach statement.

     // +--
     // | Set our Dist lines count.  We set to 1 initially because the order total
     // | counts as a line.
     // +--

     $dist_lines = 1;

     // +--
     // | Some formatted info we need.
     // +--

     $order['datestamp'] = $order['dateday'] . '/' . $order['datemonth'] . '/' . $order['dateyear'];
      
       $cartdata = unserialize($item['cartdata']);
     $shipweight = $cartdata['shipweight']; 
      

     // +--
     // | Do the customer information export.
     // +--

     $export_file1 .= "\"{$order['id']}\",";
     $export_file1 .= "\"{$item['fname']} {$item['lname']}\",\"{$item['company']}\",\"{$item['addone']}\",\"{$item['addtwo']}\",\"\",\"{$item['city']}\",";
     $export_file1 .= "\"{$item['postalcode']}\",\"{$item['country']}\",\"\",\"{$order['email']}\",";
     $export_file1 .= "\"SR1\",\"CRL1\",\"\",\"\",\"LL\",\"1\",\"{$item['shipweight']}\",\"{$order['datestamp']}\",\"\"" . $eol;

     // +--
     // | Increment our $dist_lines variable for a number of things...
     // +--

     foreach ($items as $num => $item)      {$dist_lines++;}

     if ($order['shiptotal'] > 0)           {$dist_lines++;}
     if ($order['taxsptotal'] > 0)          {$dist_lines++;}
     if ($order['taxctotal'] > 0)           {$dist_lines++;}
     if ($order['taxcreftotal'] > 0)        {$dist_lines++;}
     if ($order['custsaletotal'] > 0)       {$dist_lines++;}
     if ($order['loyaltypointstotal'] > 0)  {$dist_lines++;}
     if ($order['custsurchargetotal'] > 0)  {$dist_lines++;}
     if ($order['disctotal'] > 0)           {$dist_lines++;}

     // +--
     // | Now handle the order information export.
     // +--

     $order['shipmethod'] = '';

     foreach ($items as $num => $item) {

          $item_string  = 'Item: ' . $item['itemnum'] . ' -  ' . $item['itemname'] . '; Quantity: ' . $item['itemquan'];
          if (!(empty($item['itemopts']))) {$item_string .= '; ' . $item['itemopts'];}

          $priceper = $item['ordertotal'] / $item['itemquan'];
          $priceper = $this->price_round($priceper);

          $export_file3 .= "\"{$order['id']}\",\"{$order['fname']} {$order['lname']}\",\"{$order['id']}\",\"{$order['datestamp']}\",";
          $export_file3 .= "\"FALSE\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"{$order['id']}\",\"{$item['shipmethod']}\",\"0\",";
          $export_file3 .= "\"Prepaid\",\"\",\"{$expsett['ptacctrec']}\",\"{$order['ordertotal']}\",\"\",\"\",\"FALSE\",";
          $export_file3 .= "\"$dist_lines\",\"{$item['itemquan']}\",\"{$item['itemnum']}\",\"{$item_string}\",\"{$expsett['ptincitem']}\",";
          $export_file3 .= "\"{$priceper}\",\"{$expsett['ptincitemt']}\",\"-{$item['ordertotal']}\",\"\"" . $eol;

          if (empty($order['shipmethod'])) {$order['shipmethod'] = $item['shipmethod'];}

     } // End of foreach statement.

     // +--
     // | Handle the state/province tax total.
     // +--

     if ($order['taxsptotal'] > 0) {

          $export_file3 .= "\"{$order['id']}\",\"{$order['fname']} {$order['lname']}\",\"{$order['id']}\",\"{$order['datestamp']}\",";
          $export_file3 .= "\"FALSE\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"{$order['id']}\",\"{$order['shipmethod']}\",\"0\",";
          $export_file3 .= "\"Prepaid\",\"\",\"{$expsett['ptacctrec']}\",\"{$order['ordertotal']}\",\"\",\"\",\"FALSE\",";
          $export_file3 .= "\"{$dist_lines}\",\"0\",\"\",\"{$expsett['ptinctaxsd']}\",\"{$expsett['ptinctaxs']}\",\"0.00\",";
          $export_file3 .= "\"{$expsett['ptinctaxst']}\",\"-{$order['taxsptotal']}\",\"\"" . $eol;

     } // End of if statement.

     // +--
     // | Handle the country tax total.
     // +--

     if ($order['taxctotal'] > 0) {

          $export_file3 .= "\"{$order['id']}\",\"{$order['fname']} {$order['lname']}\",\"{$order['id']}\",\"{$order['datestamp']}\",";
          $export_file3 .= "\"FALSE\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"{$order['id']}\",\"{$order['shipmethod']}\",\"0\",";
          $export_file3 .= "\"Prepaid\",\"\",\"{$expsett['ptacctrec']}\",\"{$order['ordertotal']}\",\"\",\"\",\"FALSE\",";
          $export_file3 .= "\"{$dist_lines}\",\"0\",\"\",\"{$expsett['ptinctaxcd']}\",\"{$expsett['ptinctaxc']}\",\"0.00\",";
          $export_file3 .= "\"{$expsett['ptinctaxct']}\",\"-{$order['taxctotal']}\",\"\"" . $eol;

     } // End of if statement.

     // +--
     // | Handle the country tax refund total.
     // +--

     if ($order['taxcreftotal'] > 0) {

          $export_file3 .= "\"{$order['id']}\",\"{$order['fname']} {$order['lname']}\",\"{$order['id']}\",\"{$order['datestamp']}\",";
          $export_file3 .= "\"FALSE\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"{$order['id']}\",\"{$order['shipmethod']}\",\"0\",";
          $export_file3 .= "\"Prepaid\",\"\",\"{$expsett['ptacctrec']}\",\"{$order['ordertotal']}\",\"\",\"\",\"FALSE\",";
          $export_file3 .= "\"{$dist_lines}\",\"0\",\"\",\"{$expsett['ptexptaxcrefd']}\",\"{$expsett['ptexptaxcref']}\",\"0.00\",";
          $export_file3 .= "\"{$expsett['ptexptaxcreft']}\",\"{$order['taxcreftotal']}\",\"\"" . $eol;

     } // End of if statement.

     // +--
     // | Handle the custom sale total.
     // +--

     if ($order['custsaletotal'] > 0) {

          $export_file3 .= "\"{$order['id']}\",\"{$order['fname']} {$order['lname']}\",\"{$order['id']}\",\"{$order['datestamp']}\",";
          $export_file3 .= "\"FALSE\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"{$order['id']}\",\"{$order['shipmethod']}\",\"0\",";
          $export_file3 .= "\"Prepaid\",\"\",\"{$expsett['ptacctrec']}\",\"{$order['ordertotal']}\",\"\",\"\",\"FALSE\",";
          $export_file3 .= "\"{$dist_lines}\",\"0\",\"\",\"{$expsett['ptexpsaled']}\",\"{$expsett['ptexpsale']}\",\"0.00\",";
          $export_file3 .= "\"{$expsett['ptexpsalet']}\",\"{$order['custsaletotal']}\",\"\"" . $eol;

     } // End of if statement.

     // +--
     // | Handle the loyalty points total.
     // +--

     if ($order['loyaltypointstotal'] > 0) {

          $export_file3 .= "\"{$order['id']}\",\"{$order['fname']} {$order['lname']}\",\"{$order['id']}\",\"{$order['datestamp']}\",";
          $export_file3 .= "\"FALSE\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"{$order['id']}\",\"{$order['shipmethod']}\",\"0\",";
          $export_file3 .= "\"Prepaid\",\"\",\"{$expsett['ptacctrec']}\",\"{$order['ordertotal']}\",\"\",\"\",\"FALSE\",";
          $export_file3 .= "\"{$dist_lines}\",\"0\",\"\",\"{$expsett['ptexployaltypointsd']}\",\"{$expsett['ptexployaltypoints']}\",\"0.00\",";
          $export_file3 .= "\"{$expsett['ptexployaltypointst']}\",\"{$order['loyaltypointstotal']}\",\"\"" . $eol;

     } // End of if statement.

     // +--
     // | Handle the custom surcharge total.
     // +--

     if ($order['custsurchargetotal'] > 0) {

          $export_file3 .= "\"{$order['id']}\",\"{$order['fname']} {$order['lname']}\",\"{$order['id']}\",\"{$order['datestamp']}\",";
          $export_file3 .= "\"FALSE\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"{$order['id']}\",\"{$order['shipmethod']}\",\"0\",";
          $export_file3 .= "\"Prepaid\",\"\",\"{$expsett['ptacctrec']}\",\"{$order['ordertotal']}\",\"\",\"\",\"FALSE\",";
          $export_file3 .= "\"{$dist_lines}\",\"0\",\"\",\"{$expsett['ptincsurcd']}\",\"{$expsett['ptincsurc']}\",\"0.00\",";
          $export_file3 .= "\"{$expsett['ptincsurct']}\",\"-{$order['cutsurchargetotal']}\",\"\"" . $eol;

     } // End of if statement.

     // +--
     // | Handle the discount total.
     // +--

     if ($order['disctotal'] > 0) {

          $export_file3 .= "\"{$order['id']}\",\"{$order['fname']} {$order['lname']}\",\"{$order['id']}\",\"{$order['datestamp']}\",";
          $export_file3 .= "\"FALSE\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"{$order['id']}\",\"{$order['shipmethod']}\",\"0\",";
          $export_file3 .= "\"Prepaid\",\"\",\"{$expsett['ptacctrec']}\",\"{$order['ordertotal']}\",\"\",\"\",\"FALSE\",";
          $export_file3 .= "\"{$dist_lines}\",\"0\",\"\",\"{$expsett['ptexpdiscd']}\",\"{$expsett['ptexpdisc']}\",\"0.00\",";
          $export_file3 .= "\"{$expsett['ptexpdisct']}\",\"{$order['disctotal']}\",\"\"" . $eol;

     } // End of if statement.

     // +--
     // | Handle the order total.
     // +--

     $export_file3 .= "\"{$order['id']}\",\"{$order['fname']} {$order['lname']}\",\"{$order['id']}\",\"{$order['datestamp']}\",";
     $export_file3 .= "\"FALSE\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"{$order['id']}\",\"{$order['shipmethod']}\",\"0\",";
     $export_file3 .= "\"Prepaid\",\"\",\"{$expsett['ptacctrec']}\",\"{$order['ordertotal']}\",\"\",\"\",\"FALSE\",";
     $export_file3 .= "\"{$dist_lines}\",\"0\",\"\",\"{$expsett['ptpaymentd']}\",\"{$expsett['ptpayment']}\",\"0.00\",";
     $export_file3 .= "\"{$expsett['ptpaymentt']}\",\"{$order['ordertotal']}\",\"\"" . $eol;

     // +--
     // | Handle the shipping total.
     // +--

     if ($order['shiptotal'] > 0) {

          $export_file3 .= "\"{$order['id']}\",\"{$order['fname']} {$order['lname']}\",\"{$order['id']}\",\"{$order['datestamp']}\",";
          $export_file3 .= "\"FALSE\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"{$order['id']}\",\"{$order['shipmethod']}\",\"0\",";
          $export_file3 .= "\"Prepaid\",\"\",\"{$expsett['ptacctrec']}\",\"{$order['ordertotal']}\",\"\",\"\",\"FALSE\",";
          $export_file3 .= "\"{$dist_lines}\",\"0\",\"\",\"{$expsett['ptincshipd']}\",\"{$expsett['ptincship']}\",\"0.00\",";
          $export_file3 .= "\"{$expsett['ptincshipt']}\",\"-{$order['shiptotal']}\",\"\"" . $eol;

     } // End of if statement.

} // End of foreach statement.

// +--
// | Lastly, handle the product information export.
// +--

$table    = 'ecom_prod';

$sql      = "SELECT name, prodnum, xcat FROM {$table}";

$products = $this->CORE_DB->sql_do(array('sql'   => $sql,
                                         'table' => $table,
                                         'order' => array('id' => 'ASC')));

if ((!($this->IsError($products))) && (!(empty($products)))) {

     foreach ($products as $num => $row) {

          $row['name']    = $this->ptquote($row['name']);
          $row['prodnum'] = $this->ptquote($row['prodnum']);
          $row['xcat']    = $this->ptquote($row['xcat']);

          $xcat = $this->make_list($row['xcat']);
          if (empty($xcat[0])) {$xcat[0] = 'Not Available';}

          $export_file2 .= "\"{$row['prodnum']}\",\"{$row['name']}\",\"0\",\"FALSE\",\"{$xcat[0]}\",\"{$expsett['ptincitem']}\",\"{$expsett['ptincitemt']}\"" . $eol;

     } // End of foreach statement.

} // End of if statement.

// +--
// | Write out export file 1 and handle errors.
// +--

$filename = $this->globals('core.path_public') . '/downloads/' . $file1;

$result = $this->CORE_File->write(array('name' => $filename,
                                        'data' => $export_file1));

if ($this->IsError($result)) {

     if ($this->debug) {$this->debugger("doform: Unable to write export information to file.  Returning.");}

     return $this->return_wmessage('expnodata');

} // End of if statement.

// +--
// | Write out export file 2 and handle errors.
// +--

$filename = $this->globals('core.path_public') . '/downloads/' . $file2;

$result = $this->CORE_File->write(array('name' => $filename,
                                        'data' => $export_file2));

if ($this->IsError($result)) {

     if ($this->debug) {$this->debugger("doform: Unable to write export information to file.  Returning.");}

     return $this->return_wmessage('expnodata');

} // End of if statement.

// +--
// | Write out export file 3 and handle errors.
// +--

$filename = $this->globals('core.path_public') . '/downloads/' . $file3;

$result = $this->CORE_File->write(array('name' => $filename,
                                        'data' => $export_file3));

if ($this->IsError($result)) {

     if ($this->debug) {$this->debugger("doform: Unable to write export information to file.  Returning.");}

     return $this->return_wmessage('expnodata');

} // End of if statement.

// +--
// | Update all of our orders that we process so they're marked and
// | we don't export them again.
// +--

$table  = 'ecom_orders';

$data   = array('postordpt' => 1);

$where  = "status=" . $this->CORE_DB->quote('PRI');

$update_clause = $this->CORE_DB->clause_update(array('table' => $table,
                                                     'data'  => $data));

if (!($this->IsError($update_clause))) {

     $sql = $update_clause . ' WHERE ' . $where;

     $this->CORE_DB->sql_do(array('sql'   => $sql,
                                  'table' => $table));

} // End of if statement.

// +--
// | Print the confirm and return true.
// +--

$this->print_message('ecom','expconf');

// +--
// | Log that we were here.
// +--

if ($this->debug) {$this->debugger("showform: Displayed export form.");}

// +--
// | Run the download ready include.
// +--

$this->CORE_Display->include_file('core','downloadready.php');

// +--
// | Return true.
// +--

return 1;

} // End of function.

// +------------------------------------------------------------------+
// | Function: return_wmessage                                        |
// +------------------------------------------------------------------+

function return_wmessage ($message = '') {

// +--
// | This function prints a generic error message and returns to 
// | the doform() method.
// +--

if (!(empty($message))) {

     $this->print_message('ecom',$message);

} // End of if statement.

return $this->showform();

} // End of function.

// +------------------------------------------------------------------+
// | Function: ptquote                                                |
// +------------------------------------------------------------------+

function ptquote ($string = '') {

// +--
// | This function quotes a string for insertion into a Peachtree
// | export file.
// +--

return preg_replace('/\"/','',$string);

} // End of function.

// +------------------------------------------------------------------+
// | End of Class                                                     |
// +------------------------------------------------------------------+

} // End of class.

// +------------------------------------------------------------------+
// | End Of File                                                      |
// +------------------------------------------------------------------+

?>

Offline

 

#20 10-21-2015 09:42:12

zanart
Member
From: bedford
Registered: 04-02-2008
Posts: 1716

Re: Royal Mail DMO csv file

You need to go through each Item in the order to get the shipping weight.
Therefore you need to include the code provided within a foreach statement that checks each item in the order

Code:

     foreach ($items as $num => $item)  {

     $cartdata = unserialize($item['cartdata']);
     $shipweight = $cartdata['shipweight'];  

     } // End of foreach statement.

Rob

Offline

 

#21 10-21-2015 10:02:32

nigel
Member
From: Peterborough, UK
Registered: 04-27-2008
Posts: 418
Website

Re: Royal Mail DMO csv file

Thanks again. Still no joy. This is how my code looks now but it is still not outputting the weight to the csv file.

Code:

foreach ($items as $num => $item)  {

     $cartdata = unserialize($item['cartdata']);
     $shipweight = $cartdata['shipweight']; 
      
     } // End of foreach statement.
        
      

     // +--
     // | Do the customer information export.
     // +--

     $export_file1 .= "\"{$order['id']}\",";
     $export_file1 .= "\"{$item['fname']} {$item['lname']}\",\"{$item['company']}\",\"{$item['addone']}\",\"{$item['addtwo']}\",\"\",\"{$item['city']}\",";
     $export_file1 .= "\"{$item['postalcode']}\",\"{$item['country']}\",\"\",\"{$order['email']}\",";
     $export_file1 .= "\"SR1\",\"CRL1\",\"\",\"\",\"LL\",\"1\",\"{$item['shipweight']}\",\"{$order['datestamp']}\",\"\"" . $eol;

Offline

 

#22 10-21-2015 11:05:55

zanart
Member
From: bedford
Registered: 04-02-2008
Posts: 1716

Re: Royal Mail DMO csv file

your shipweight is $shipweight but you have $item['shipweight'] in your $export_file1......


Rob

Offline

 

#23 10-22-2015 08:26:47

nigel
Member
From: Peterborough, UK
Registered: 04-27-2008
Posts: 418
Website

Re: Royal Mail DMO csv file

Hi,

sorry to be a pain, but I still can't get this working. Can you tell me exactly what goes in $export_file1 to replace XXXXXXXXXX

and where does the foreach statement need to be, just above the export file?

Thank you!!

Code:

$export_file1 .= "\"{$order['id']}\",";
     $export_file1 .= "\"{$item['fname']} {$item['lname']}\",\"{$item['company']}\",\"{$item['addone']}\",\"{$item['addtwo']}\",\"\",\"{$item['city']}\",";
     $export_file1 .= "\"{$item['postalcode']}\",\"{$item['country']}\",\"\",\"{$order['email']}\",";
     $export_file1 .= "\"SR1\",\"CRL1\",\"\",\"\",\"LL\",\"1\",\"XXXXXXXXXX\",\"{$order['datestamp']}\",\"\"" . $eol;

Offline

 

#24 10-22-2015 11:27:50

webmaster
Administrator
From: York, PA
Registered: 04-20-2001
Posts: 19861
Website

Re: Royal Mail DMO csv file

If you're defining $shipweight like:

Code:

     $cartdata   = unserialize($item['cartdata']);
     $shipweight = $cartdata['shipweight'];

Do:

Code:

     $export_file1 .= "\"{$order['id']}\",";
     $export_file1 .= "\"{$item['fname']} {$item['lname']}\",\"{$item['company']}\",\"{$item['addone']}\",\"{$item['addtwo']}\",\"\",\"{$item['city']}\",";
     $export_file1 .= "\"{$item['postalcode']}\",\"{$item['country']}\",\"\",\"{$order['email']}\",";
     $export_file1 .= "\"SR1\",\"CRL1\",\"\",\"\",\"LL\",\"1\",\"{$shipweight}\",\"{$order['datestamp']}\",\"\"" . $eol;

Nick Hendler

Offline

 

#25 10-22-2015 11:46:26

nigel
Member
From: Peterborough, UK
Registered: 04-27-2008
Posts: 418
Website

Re: Royal Mail DMO csv file

I tried that code but it does not populate the cell in the spreadsheet. I tried the following code and it puts the total content of the cartdata in the cell, does that mean the "unserialize" is not working?

Code:

foreach ($items as $num => $item) {
      $cartdata = unserialize($item['cartdata']);
      $item['shipweight'] = $item['cartdata']; 
      
     $export_file1 .= "\"{$order['id']}\",";
     $export_file1 .= "\"{$item['fname']} {$item['lname']}\",\"{$item['company']}\",\"{$item['addone']}\",\"{$item['addtwo']}\",\"\",\"{$item['city']}\",";
     $export_file1 .= "\"{$item['postalcode']}\",\"{$item['country']}\",\"\",\"{$order['email']}\",";
     $export_file1 .= "\"SR1\",\"CRL1\",\"\",\"\",\"LL\",\"1\",\"{$item['shipweight']}\",\"{$order['datestamp']}\",\"\"" . $eol;
     
      } // End of foreach statement.

Offline

 

Board footer