Hi Guys,

I'm currently working on developing a shipping add on to share with the community.

I've managed to get a list of orders available for despatch based upon the orders.order_status field. I have written a simple class to deal with the CSV generation, changing of order.order_status value and insert to order_status_history. However, I get the below error when the method is called to update the orders.order_status field.

PHP Fatal error: Call to a member function on a non-object in /var/www/vhost/somedomain.com/www/admin/includes/classes/DPDExport.php on line 39
Here's the class:

PHP Code:
<?php

class DPDExport {

    var 
$OrderInfo;
    var 
$OrderNumber;
    
    function 
DPDExport(){
        
    }
    
    function 
getDPDCode$method ){
    if(
$method == 'flat')
        return 
36;
    else
        return 
32;
    }
    
    function 
setOrderInfo$OrderInfo ){
        
$this->OrderInfo $OrderInfo;
        
$this->OrderNumber $OrderInfo['orders_id'];
    }
    
    function 
getCSVRow(){
        
$code $this->getDPDCode($this->OrderInfo['shipping_module_code']);
        
$CustomerComments $this->getCustomersComments();
        
$csvRow =        "\"" $this->OrderNumber "\"" DPD_DELIMITER "\"1\""  DPD_DELIMITER "\"" $code "\"" DPD_DELIMITER 
                            
"\"1\"" DPD_DELIMITER "\"" $this->OrderInfo['customers_name'] . "\"" DPD_DELIMITER "\"" $this->OrderInfo['delivery_street_address'] . "\"" DPD_DELIMITER 
                            
"\"" $this->OrderInfo['delivery_suburb'] . "\"" DPD_DELIMITER "\"" $this->OrderInfo['delivery_city'] . "\"" DPD_DELIMITER 
                            
"\"" $this->OrderInfo['delivery_state'] . "\"" DPD_DELIMITER "\"" $this->OrderInfo['delivery_postcode'] . "\"" DPD_DELIMITER 
                            
"\"" $this->OrderInfo['customers_email_address'] . "\"" DPD_DELIMITER "\"1\"" DPD_DELIMITER "\"" $comments "\"" "\n";
        
$this->setOrderStatus();
        return 
$csvRow;
    }
    
    function 
getCustomersComments(){
        
$sql "SELECT `comments` FROM `orders_status_history` WHERE orders_id = '" .$this->OrderNumber"' AND `orders_status_id` = '1'";
        
$CustomerComments $dbObj->Execute$sql );
        return 
$CustomerComments->fields['comments'];
    }    
    
    function 
setOrderStatus(){
        
$sql "UPDATE " .TABLE_ORDERS" SET `orders_status` = '3' WHERE orders_id = '" .$this->OrderNumber"'";
        
$dbObj->Execute$sql );
        
$this->setOrderHistory();
    }
    
    function 
setOrderHistory(){
        
$date date("Y-m-d H:i:s");
        
$sql "INSERT INTO `orders_status_history` (`orders_id`, `orders_status_id`, `date_added`, `customer_notified`, `comments`)
                        VALUES ( '" 
.$this->OrderNumber"', '3', '" .$date"', '0', '" .TEXT_DPD_COMMENTS"')";
        
$dbObj->Execute$sql );    
    }
    
}

?>
The issue is that the call to this class is nested within a while loop which is evaluated by the EOF property.

Here's the tpl file:

PHP Code:
require('includes/application_top.php');

include(
DIR_WS_CLASSES 'DPDExport.php');

$today date("Ymda"); 

$sql 'SELECT orders_id, customers_name, delivery_street_address, delivery_suburb, delivery_city, delivery_postcode, delivery_state, 
                 delivery_country, customers_email_address, shipping_module_code
                 FROM orders
                 WHERE orders_status = ' 
.DPD_ORDER_STATUS_DESPATCH;
$DespatchOrders $db->Execute($sql);

//set the columns in the csv file
$csv TEXT_DPD_JOB_REF DPD_DELIMITER TEXT_DPD_LABELS DPD_DELIMITER TEXT_DPD_SERVICE DPD_DELIMITER .
                
TEXT_DPD_WEIGHT DPD_DELIMITER TEXT_DPD_NAME DPD_DELIMITER TEXT_DPD_ADDRESS1 DPD_DELIMITER 
                
TEXT_DPD_ADDRESS2 DPD_DELIMITER TEXT_DPD_TOWN DPD_DELIMITER TEXT_DPD_COUNTY DPD_DELIMITER 
                
TEXT_DPD_POSTCODE DPD_DELIMITER TEXT_DPD_EMAIL DPD_DELIMITER TEXT_DPD_JOB_TYPE DPD_DELIMITER 
                
TEXT_DPD_CUST_COMMENTS ."\n";

        
$dpd = new DPDExport();        
//loop through the result set populating the CSV
while (!$DespatchOrders->EOF) {
    if(
$DespatchOrders->fields['delivery_country'] == 'United Kingdom' ){
        
        
$dpd->setOrderInfo$DespatchOrders->fields );
        
$csv .= $dpd->getCSVRow();
    }
        
$DespatchOrders->MoveNext();
}
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"DPDExport"  .$today".csv\"");
echo 
$csv
I know this isn't that tidy but this is literally for testing atm :)

Any help would be greatly appreciated as I'd like to get this out to the community as soon as I'm done

Thanks