Skip to content

Instantly share code, notes, and snippets.

@setola
Created March 23, 2017 11:37
Show Gist options
  • Save setola/330ac4f6c5f483d2a5ec1c92559da68a to your computer and use it in GitHub Desktop.
Save setola/330ac4f6c5f483d2a5ec1c92559da68a to your computer and use it in GitHub Desktop.
import customers prestohop -> woocommerce
<?php
/**
* Created by PhpStorm.
* User: setola
* Date: 22/02/17
* Time: 10.09
*/
$sql = <<<SQL
SELECT
*
FROM
ps_customer AS A
LEFT JOIN
ps_address AS B ON (B.id_customer = A.id_customer)
JOIN
ps_lang AS C ON (A.id_lang = C.id_lang)
JOIN
ps_state AS D ON (B.id_state = D.id_state)
JOIN
ps_country AS E ON (B.id_country = E.id_country)
;
SQL;
$db = new PDO('mysql:dbname=gajardo_db;host=127.0.0.1', 'root', 'texrulez');
$orders = $db->query('SELECT * FROM ps_orders;');
$langs = $db->query('SELECT * FROM ps_lang');
$customers = $db->query('SELECT * FROM ps_customer;');
$queryAddress = 'SELECT * FROM ps_address where id_address = :idAddress;';
$toret = [];
$lastOrderStmt = $db->prepare('SELECT * FROM ps_orders WHERE id_customer = :idCustomer ORDER BY id_order DESC LIMIT 1;');
$addressStmt = $db->prepare('
SELECT *, D.iso_code as diso_code, E.iso_code as eiso_code FROM ps_address AS B
JOIN ps_state AS D ON (B.id_state = D.id_state)
JOIN ps_country AS E ON (B.id_country = E.id_country)
WHERE id_address = :idAddress;
');
foreach ($customers as $customer) {
$lastOrderStmt->bindValue('idCustomer', $customer['id_customer'], PDO::PARAM_INT);
$lastOrderStmt->execute();
$lastOrder = $lastOrderStmt->fetch();
$addressStmt->bindValue('idAddress', $lastOrder['id_address_delivery'], PDO::PARAM_INT);
$addressStmt->execute();
$deliver = $addressStmt->fetch();
$addressStmt->bindValue('idAddress', $lastOrder['id_address_invoice'], PDO::PARAM_INT);
$addressStmt->execute();
$invoice = $addressStmt->fetch();
var_dump($customer['id_customer'], $deliver);
/*
$toret[] = [
'user' => $customer,
'delivery' => $db->query($queryAddress, ['idAddress' => $lastOrder['id_address_delivery']]),
'invoice' => $db->query($queryAddress, ['idAddress' => $lastOrder['id_address_invoice']]),
];/**/
$tmp = [
'User Login' => '',
'User Email' => $customer['email'],
'First Name' => $customer['firstname'],
'Last Name' => $customer['lastname'],
'User Registered' => '',
'User Nicename' => $customer['firstname'] . ' ' . $customer['lastname'],
'User URL' => '',
'Display Name' => $customer['firstname'] . ' ' . $customer['lastname'],
'Nickname' => '',
'Description' => '',
'Customer User ID' => '',
];
if ($invoice) {
$tmp = array_merge($tmp, array(
'Billing First Name' => $invoice['firstname'],
'Billing Last Name' => $invoice['lastname'],
'Billing Company' => $invoice[''],
'Billing Address 1' => $invoice['address1'],
'Billing Address 2' => $invoice['address2'],
'Billing City' => $invoice['city'],
'Billing Postcode' => $invoice['postcode'],
'Billing Country' => $invoice['eiso_code'],
'Billing State' => $invoice['diso_code'],
'Billing Email' => $invoice[''],
'Billing Phone' => $invoice[''],
));
}
if ($deliver) {
$tmp = array_merge($tmp, array(
'Shipping First Name' => $deliver['firstname'],
'Shipping Last Name' => $deliver['lastname'],
'Shipping Company' => $deliver[''],
'Shipping Address 1' => $deliver['address1'],
'Shipping Address 2' => $deliver['address2'],
'Shipping City' => $deliver['city'],
'Shipping Postcode' => $deliver['postcode'],
'Shipping Country' => $deliver['eiso_code'],
'Shipping State' => $deliver['diso_code'],
));
}
$toret[] = $tmp;
};
//var_dump($toret);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment