Sure, I'm using version 2.2.0.
In controller/checkout/success.php I've added the following code to get info about the orders:
Code: Select all
//GET ORDER DETAILS
//LOAD MODEL
$this->load->model('checkout/order');
//GET ORDER DETAILS
$order_info = $this->model_checkout_order->getOrder($order_id);
//NEW MODEL TO COLLECT TAX
$get_order_tax = $this->model_checkout_order->getOrderTax($order_id);
if($get_order_tax){
//ASSIGN TAX TO NEW VARIABLE
$order_tax = $get_order_tax['value'];
} else {
//THERE WAS NO TAX COLLECTED
$order_tax = '';
}
//NEW MODEL TO COLLECT SHIPPING
$get_order_shipping = $this->model_checkout_order->getOrderShipping($order_id);
if($get_order_shipping){
//ASSIGN SHIPPING TO NEW VARIABLE
$order_shipping = $get_order_shipping['value'];
} else {
//THERE WAS NO SHIPPING COLLECTED
$order_shipping = '';
}
//NEW MODEL TO COLLECT ALL PRODUCTS ASSOCIATED WITH ORDER
$get_order_products = $this->model_checkout_order->getOrderProducts($order_id);
//CREATE ARRAY TO HOLD PRODUCTS
$order_products = array();
foreach($get_order_products as $prod){
$order_products[] = array(
'order_id' => $order_id,
'model' => $prod['model'],
'name' => $prod['name'],
'sku' => $prod['sku'],
'category' => '',
'price' => number_format($prod['price'], 2, '.', ','),
'quantity' => $prod['quantity'],
'value' => $prod['value']
);
}
//NEW ORDER ARRAY
$order_tracker = array(
'order_id' => $order_id,
'store_name' => $order_info['store_name'],
'total' => $order_info['total'],
'tax' => $order_tax,
'shipping' => $order_shipping,
'city' => $order_info['payment_city'],
'state' => $order_info['payment_zone'],
'country' => $order_info['payment_country'],
'currency' => $order_info['currency_code'],
'products' => $order_products
);
$this->session->data['order_tracker'] = $order_tracker;
$order_info['shipping'] = $order_shipping;
$order_info['products'] = $order_products;
$this->model_checkout_order->exportToMyFunction($order_id);
//END MODIFICATION
The data is then passed to an export function in /model/checkout/order.php. The code for that is:
Code: Select all
private function exportToMyDB($order) {
$hash = $this->toHashMap($order);
$db = $this->getMyDB();
$sql = "INSERT INTO orders VALUES (" . implode(array_keys($hash), ',') . ")";
try {
$db->prepare($sql)->execute($hash);
}
catch (Exception $e) {
error_log($e->getMessage());
error_log("Export failed: {$sql}; with values: " . implode($hash, ","));
}
}
private function toHashMap($order) {
return [
":id" => NULL,
":fname" => $order['firstname'],
":lname" => $order['lastname'],
":address1" => $order['shipping_address_1'],
":address2" => $order['shipping_address_2'],
":city" => $order['shipping_city'],
":county" => $order['shipping_zone'],
":postcode" => $order['shipping_postcode'],
":country" => $order['shipping_iso_code_2'],
":tel" => $order['telephone'],
":email" => $order['email'],
":comments" => $order['comment'],
":postage" => number_format($order['shipping'], 2, '.', ','),
":subTotal" => number_format($order['total'] - $order['shipping'], 2, '.', ','),
":total" => number_format($order['total'], 2, '.', ','),
":products" => implode(array_map([$this, 'getProductString'], $order['products']), ":"),
":productsNice" => "Unavailable",
":domain" => $order['store_name'],
":time" => $order['date_modified'],
":currency" => $order['currency_code'],
":paymentMethod" => "card",
":new" => "1",
":orderRef" => $order['order_id'],
":complete" => "1",
":txnid" => $order['order_id'],
":dispatched" => "0"
];
}
private function getProductString($product) {
return implode([
$product['sku'],
$product['name'],
$product['price'],
$product['quantity'],
"0.00"
], ";");
}
Though reading back through the comments on the
WorldPay Business Gateway extension page it seems like this is a problem people have encountered with previous versions of the extension.