|
1 | 1 | <?php
|
2 |
| - |
3 |
| - |
4 | 2 | ini_set('display_errors', 1);
|
5 | 3 | ini_set('display_startup_errors', 1);
|
6 | 4 | error_reporting(E_ALL);
|
|
10 | 8 | require("../inc/xtc_not_null.inc.php");
|
11 | 9 | require("../inc/xtc_get_country_name.inc.php");
|
12 | 10 |
|
13 |
| - |
14 |
| - |
15 |
| - |
16 | 11 | if(!defined('MODULE_FS_CLEVERREACH_INTERFACE_STATUS') || MODULE_FS_CLEVERREACH_INTERFACE_STATUS != 'true')
|
17 | 12 | {
|
18 | 13 | header('Location: ' . preg_replace("/[\r\n]+(.*)$/i", "", html_entity_decode($_SERVER['HTTP_REFERER'])));
|
19 | 14 | exit();
|
20 | 15 | }
|
21 | 16 |
|
22 |
| - |
23 |
| - |
24 | 17 | if(!defined('MODULE_FS_CLEVERREACH_INTERFACE_CLIENT_ID') || !defined('MODULE_FS_CLEVERREACH_INTERFACE_USERNAME') || !defined('MODULE_FS_CLEVERREACH_INTERFACE_PASSWORD'))
|
25 | 18 | {
|
26 |
| - |
27 | 19 | header('Location: ' . preg_replace("/[\r\n]+(.*)$/i", "", html_entity_decode($_SERVER['HTTP_REFERER'])));
|
28 | 20 | exit();
|
29 | 21 | }
|
30 | 22 |
|
31 | 23 | $rest = new \CR\tools\rest("https://rest.cleverreach.com/v2");
|
32 | 24 |
|
33 |
| - |
34 | 25 | if (trim(MODULE_FS_CLEVERREACH_INTERFACE_CLIENT_ID) == '' || trim(MODULE_FS_CLEVERREACH_INTERFACE_USERNAME) == '' || trim(MODULE_FS_CLEVERREACH_INTERFACE_PASSWORD) == '') {
|
35 | 26 | die('Please enter all login credentials for Cleverreach!');
|
36 | 27 | }
|
|
55 | 46 |
|
56 | 47 | $receivers = array();
|
57 | 48 |
|
| 49 | +$manual_registered_customers = xtc_db_query("SELECT |
| 50 | + customers_id, |
| 51 | + customers_email_address as email, |
| 52 | + date_added as registered, |
| 53 | + customers_firstname as firstname, |
| 54 | + customers_lastname as lastname |
| 55 | + FROM " . TABLE_NEWSLETTER_RECIPIENTS . " WHERE mail_status = '1' "); |
| 56 | + |
| 57 | +while ($customer = xtc_db_fetch_array($manual_registered_customers)) { |
| 58 | + $orders = array(); |
| 59 | + $order_rows = xtc_db_query("SELECT o.orders_id, op.products_id, op.products_name, op.products_price, op.products_quantity from " . TABLE_ORDERS . " o JOIN " . TABLE_ORDERS_PRODUCTS . " op ON o.orders_id = op.orders_id WHERE customers_id = '" . $customer['customers_id'] . "' ORDER BY date_purchased "); |
| 60 | + while ($order_row = xtc_db_fetch_array($order_rows)) { |
58 | 61 |
|
59 |
| - $manual_registered_customers = xtc_db_query("SELECT |
60 |
| - customers_id, |
61 |
| - customers_email_address as email, |
62 |
| - date_added as registered, |
63 |
| - customers_firstname as firstname, |
64 |
| - customers_lastname as lastname |
65 |
| - FROM " . TABLE_NEWSLETTER_RECIPIENTS . " WHERE mail_status = '1' "); |
66 |
| - |
67 |
| - while ($customer = xtc_db_fetch_array($manual_registered_customers)) { |
68 |
| - $orders = array(); |
69 |
| - $order_rows = xtc_db_query("SELECT o.orders_id, op.products_id, op.products_name, op.products_price, op.products_quantity from " . TABLE_ORDERS . " o JOIN " . TABLE_ORDERS_PRODUCTS . " op ON o.orders_id = op.orders_id WHERE customers_id = '" . $customer['customers_id'] . "' ORDER BY date_purchased "); |
70 |
| - while ($order_row = xtc_db_fetch_array($order_rows)) { |
71 |
| - |
72 |
| - $orders[] = array( |
73 |
| - "order_id" => $order_row["orders_id"], //required |
74 |
| - "product_id" => $order_row["products_id"], //optional |
75 |
| - "product" => $order_row["products_name"], //required |
76 |
| - "price" => $order_row["products_price"], //optional |
77 |
| - "currency" => "EUR", //optional |
78 |
| - "amount" => $order_row["products_quantity"], //optional |
79 |
| - "source" => STORE_NAME //optional |
80 |
| - ); |
81 |
| - } |
| 62 | + $orders[] = array( |
| 63 | + "order_id" => $order_row["orders_id"], //required |
| 64 | + "product_id" => $order_row["products_id"], //optional |
| 65 | + "product" => $order_row["products_name"], //required |
| 66 | + "price" => $order_row["products_price"], //optional |
| 67 | + "currency" => "EUR", //optional |
| 68 | + "amount" => $order_row["products_quantity"], //optional |
| 69 | + "source" => STORE_NAME //optional |
| 70 | + ); |
| 71 | + } |
82 | 72 |
|
83 |
| - $gender_query = xtc_db_query("SELECT c.customers_gender as gender, ab.entry_country_id as country, ab.entry_city as city, ab.entry_postcode as zip, ab.entry_street_address as street FROM " . TABLE_CUSTOMERS . " c JOIN ".TABLE_ADDRESS_BOOK." ab ON c.customers_id = ab.customers_id WHERE customers_id = '" . $customer['customers_id'] . "' AND c.customers_default_address_id = ab.address_book_id"); |
84 |
| - $customers_data = xtc_db_fetch_array($gender_query); |
85 |
| - $country = xtc_get_country_name($customers_data['country']); |
| 73 | + $gender_query = xtc_db_query("SELECT c.customers_gender as gender, ab.entry_country_id as country, ab.entry_city as city, ab.entry_postcode as zip, ab.entry_street_address as street FROM " . TABLE_CUSTOMERS . " c JOIN ".TABLE_ADDRESS_BOOK." ab ON c.customers_id = ab.customers_id WHERE customers_id = '" . $customer['customers_id'] . "' AND c.customers_default_address_id = ab.address_book_id"); |
| 74 | + $customers_data = xtc_db_fetch_array($gender_query); |
| 75 | + $country = xtc_get_country_name($customers_data['country']); |
86 | 76 |
|
87 |
| - $receivers[] = array( |
88 |
| - "email" => $customer["email"], |
89 |
| - "registered" => strtotime($customer["registered"]), |
90 |
| - "activated" => strtotime($customer["registered"]), |
91 |
| - "source" => STORE_NAME, |
92 |
| - "attributes" => array( |
93 |
| - "city" => $customer["city"], |
94 |
| - "street" => $customer["street"], |
95 |
| - "zip" => $customer["zip"], |
96 |
| - "country" => $country |
97 |
| - ), |
98 |
| - "global_attributes" => array( |
99 |
| - "firstname" => $customer["firstname"], |
100 |
| - "lastname" => $customer["lastname"], |
101 |
| - "geschlecht" => $customers_data["gender"] |
102 |
| - ), |
103 |
| - "orders" => $orders |
104 |
| - ); |
105 |
| - |
106 |
| - if (count($receivers) > 1000) { |
107 |
| - $rest->post("/groups.json/".$group_id."/receivers", $receivers); |
108 |
| - $receivers = array(); |
109 |
| - } |
| 77 | + $receivers[] = array( |
| 78 | + "email" => $customer["email"], |
| 79 | + "registered" => strtotime($customer["registered"]), |
| 80 | + "activated" => strtotime($customer["registered"]), |
| 81 | + "source" => STORE_NAME, |
| 82 | + "attributes" => array( |
| 83 | + "city" => $customer["city"], |
| 84 | + "street" => $customer["street"], |
| 85 | + "zip" => $customer["zip"], |
| 86 | + "country" => $country |
| 87 | + ), |
| 88 | + "global_attributes" => array( |
| 89 | + "firstname" => $customer["firstname"], |
| 90 | + "lastname" => $customer["lastname"], |
| 91 | + "geschlecht" => $customers_data["gender"] |
| 92 | + ), |
| 93 | + "orders" => $orders |
| 94 | + ); |
| 95 | + |
| 96 | + if (count($receivers) > 1000) { |
| 97 | + $rest->post("/groups.json/".$group_id."/receivers", $receivers); |
| 98 | + $receivers = array(); |
110 | 99 | }
|
| 100 | +} |
111 | 101 |
|
112 | 102 |
|
113 | 103 | if (MODULE_FS_CLEVERREACH_INTERFACE_IMPORT_BUYERS == 'true') {
|
| 104 | + $where_clause = ''; |
| 105 | + if (isset($_GET['export_filter_amazon']) && $_GET['export_filter_amazon'] == 1) { |
| 106 | + $where_clause .= " AND customers_email_address NOT LIKE '%@marketplace.amazon.de%'"; |
| 107 | + } |
114 | 108 | $order_rows = xtc_db_query("SELECT DISTINCT o.orders_id, o.customers_id, o.customers_email_address as email, o.customers_firstname as firstname, o.customers_lastname as lastname, o.customers_gender as gender, o.customers_street_address as street, o.customers_city as city, o.customers_postcode as zip, o.customers_country as country, o.date_purchased, op.products_id, op.products_name, op.products_price, op.products_quantity from " . TABLE_ORDERS . " o JOIN " . TABLE_ORDERS_PRODUCTS . " op ON o.orders_id = op.orders_id GROUP BY o.customers_id ORDER BY o.date_purchased ");
|
115 | 109 | while ($order_row = xtc_db_fetch_array($order_rows)) {
|
116 | 110 |
|
|
126 | 120 | "source" => STORE_NAME //optional
|
127 | 121 | );
|
128 | 122 |
|
129 |
| - $flagged_customers = xtc_db_query(" SELECT c.customers_date_added as registered, c.customers_gender as gender, c.customers_dob as dob FROM " . TABLE_CUSTOMERS . " c WHERE c.customers_id = '" . $order_row["customers_id"] . "'"); |
| 123 | + $flagged_customers = xtc_db_query(" SELECT c.customers_date_added as registered, c.customers_gender as gender, c.customers_dob as dob FROM " . TABLE_CUSTOMERS . " c WHERE c.customers_id = '" . $order_row["customers_id"] . "' " . $where_clause); |
130 | 124 | $receivers = array('postdata' => array());
|
131 | 125 |
|
132 | 126 | if (xtc_db_num_rows($flagged_customers) > 0) {
|
|
0 commit comments