Skip to content

Instantly share code, notes, and snippets.

@janbru
Last active August 29, 2015 14:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janbru/aaeb70ff2aa292501cfb to your computer and use it in GitHub Desktop.
Save janbru/aaeb70ff2aa292501cfb to your computer and use it in GitHub Desktop.
PrestaShop export naar PostNL Zendinggegevens
<?php
if (!defined('_PS_ADMIN_DIR_'))
define('_PS_ADMIN_DIR_', getcwd());
include(_PS_ADMIN_DIR_.'/../config/config.inc.php');
/* Getting cookie or logout */
require_once(_PS_ADMIN_DIR_.'/init.php');
$file_name = "verzenden.csv";
header("Content-Type: text/plain");
header("Pragma: public");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Disposition: attachment; filename=\"$file_name\"");
$re = "/^(\\d*[\\wÀÈÌÒÙàèìòùÁÉÍÓÚÝáéíóúýÂÊÎÔÛâêîôûÃÕãõÄËÏÖÜŸäëïöüÿßÑñİıÇçĞğŞşåÅæÆøØ\\d '\\-\\.]+)[,\\s]+(\\d+)\\s*([\\ÀÈÌÒÙàèìòùÁÉÍÓÚÝáéíóúýÂÊÎÔÛâêîôûÃÕãõÄËÏÖÜŸäëïöüÿßÑñİıÇçĞğŞşåÅæÆøØ \\d\\-\\/]*)$/i";
$result = Db::getInstance()->ExecuteS("
SELECT orders.reference, orders.id_order, address.*, order_carrier.tracking_number, country.iso_code, customer.email, shop.name AS shop_name
FROM `orders`
INNER JOIN `address` ON address.id_address = orders.id_address_delivery
INNER JOIN `order_carrier` ON order_carrier.id_order = orders.id_order
INNER JOIN `country` ON country.id_country = address.id_country
INNER JOIN `customer` ON customer.id_customer = orders.id_customer
INNER JOIN `shop` ON shop.id_shop = orders.id_shop
;
");
//var_dump($result);
echo "partnerid;brief;gewicht;optie;kenmerk;naam;bedrijfsnaam;postcode;huisnummer;huisnummertoevoeging;straat;woonplaats;land;email;mobielnummer;pakjegemak\n";
foreach ($result as $row) {
$state = Db::getInstance()->getValue("
select id_order_state from `order_history`
where id_order = ".$row["id_order"]."
order by date_add desc", false);
if($state == 4)
{
echo $row["shop_name"].";";
echo "ja".";";
$weight = Db::getInstance()->getValue("
select sum(product_weight * product_quantity)
from `order_detail`
where id_order = ".$row["id_order"].";", false);
$weight = (Int)(((Double)$weight)*1000);
echo $weight.";";
echo "VOLGBAAR".";";
echo $row["reference"].";";
echo $row["firstname"]." ".$row["lastname"].";";
echo $row["company"].";";
echo $row["postcode"].";";
$address = $row["address1"];
preg_match($re, $address, $matches);
echo $matches[2].";";
echo $matches[3].";";
echo $matches[1].";";
echo $row["city"].";";
echo $row["iso_code"].";";
echo $row["email"].";";
$phone = $row["phone_mobile"];
preg_match("/\\d+/", $phone, $matches);
$phone = $matches[0];
$phone = str_replace('+31', '0', $phone);
$phone = str_replace('06', '06-', $phone);
echo $phone.";";
echo "nee".";";
echo "\n";
}
}
?>
@snelweg
Copy link

snelweg commented Mar 25, 2015

als ik zo kijk hoe doe je het dan met de huisnummers?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment