|
1 | 1 | <?php
|
2 |
| -ini_set('display_errors', 1); |
3 |
| -ini_set('display_startup_errors', 1); |
4 |
| -error_reporting(E_ALL); |
5 | 2 |
|
6 | 3 | require_once('fs_cleverreach_interface_rest_client.php');
|
7 | 4 | require("../includes/application_top_export.php");
|
|
34 | 31 | )
|
35 | 32 | );
|
36 | 33 |
|
| 34 | +if ($_GET['update_receivers']) { |
| 35 | + $update_receivers = $_GET['update_receivers']; |
| 36 | +} |
| 37 | + |
37 | 38 | $rest->setAuthMode("bearer", $token);
|
38 | 39 |
|
39 | 40 | $groups = $rest->get("/groups");
|
|
44 | 45 | die('No groups found! Please create one in the Cleverreach backend');
|
45 | 46 | }
|
46 | 47 |
|
47 |
| -$receivers = array(); |
| 48 | +if (MODULE_FS_CLEVERREACH_INTERFACE_IMPORT_SUBSCRIBERS == 'true') { |
48 | 49 |
|
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)) { |
| 50 | + $receivers = array(); |
61 | 51 |
|
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 |
| - } |
| 52 | + $manual_registered_customers = xtc_db_query("SELECT |
| 53 | + customers_id, |
| 54 | + customers_email_address as email, |
| 55 | + date_added as registered, |
| 56 | + customers_firstname as firstname, |
| 57 | + customers_lastname as lastname |
| 58 | + FROM " . TABLE_NEWSLETTER_RECIPIENTS . " WHERE mail_status = '1' "); |
72 | 59 |
|
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']); |
| 60 | + while ($customer = xtc_db_fetch_array($manual_registered_customers)) { |
| 61 | + $orders = array(); |
| 62 | + $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 "); |
| 63 | + while ($order_row = xtc_db_fetch_array($order_rows)) { |
76 | 64 |
|
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(); |
| 65 | + $orders[] = array( |
| 66 | + "order_id" => $order_row["orders_id"], //required |
| 67 | + "product_id" => $order_row["products_id"], //optional |
| 68 | + "product" => $order_row["products_name"], //required |
| 69 | + "price" => $order_row["products_price"], //optional |
| 70 | + "currency" => "EUR", //optional |
| 71 | + "amount" => $order_row["products_quantity"], //optional |
| 72 | + "source" => STORE_NAME //optional |
| 73 | + ); |
| 74 | + } |
| 75 | + |
| 76 | + $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, ab.entry_company as company 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"); |
| 77 | + $customers_data = xtc_db_fetch_array($gender_query); |
| 78 | + $country = xtc_get_country_name($customers_data['country']); |
| 79 | + |
| 80 | + $receivers[] = array( |
| 81 | + "email" => $customer["email"], |
| 82 | + "registered" => strtotime($customer["registered"]), |
| 83 | + "activated" => strtotime($customer["registered"]), |
| 84 | + "source" => STORE_NAME, |
| 85 | + "attributes" => array( |
| 86 | + "city" => $customer["city"], |
| 87 | + "street" => $customer["street"], |
| 88 | + "zip" => $customer["zip"], |
| 89 | + "country" => $country, |
| 90 | + "firstname" => $customer["firstname"], |
| 91 | + "lastname" => $customer["lastname"], |
| 92 | + "geschlecht" => $customers_data["gender"], |
| 93 | + "company" => $customers_data["company"] |
| 94 | + ), |
| 95 | + "orders" => $orders |
| 96 | + ); |
| 97 | + |
| 98 | + if ($update_receivers) { |
| 99 | + $deleted = $rest->delete("/groups.json/".$group_id."/receivers/".$customer["email"]); |
| 100 | + } |
| 101 | + |
| 102 | + if (count($receivers) > 1000) { |
| 103 | + $rest->post("/groups.json/".$group_id."/receivers", $receivers); |
| 104 | + $receivers = array(); |
| 105 | + } |
99 | 106 | }
|
100 | 107 | }
|
101 | 108 |
|
102 |
| - |
103 | 109 | if (MODULE_FS_CLEVERREACH_INTERFACE_IMPORT_BUYERS == 'true') {
|
104 | 110 | $where_clause = '';
|
105 | 111 | if (isset($_GET['export_filter_amazon']) && $_GET['export_filter_amazon'] == 1) {
|
|
131 | 137 | "activated" => strtotime($customer["registered"]),
|
132 | 138 | "registered" => strtotime($customer["registered"]),
|
133 | 139 | "source" => STORE_NAME,
|
134 |
| - "global_attributes" => array( |
| 140 | + "attributes" => array( |
135 | 141 | "nachname" => utf8_encode($order_row["firstname"]),
|
136 | 142 | "vorname" => utf8_encode($order_row["lastname"]),
|
137 | 143 | "m__nnlich_weiblich" => $customer["gender"],
|
|
143 | 149 | ),
|
144 | 150 | "orders" => $orders
|
145 | 151 | );
|
| 152 | + |
| 153 | + if ($update_receivers) { |
| 154 | + $rest->delete("/groups.json/".$group_id."/receivers/".$order_row["email"]); |
| 155 | + } |
146 | 156 |
|
147 | 157 | if (count($receivers) > 1000) {
|
148 | 158 | $rest->post("/groups.json/".$group_id."/receivers", $receivers);
|
|
155 | 165 | "activated" => strtotime($order_row["date_purchased"]),
|
156 | 166 | "registered" => strtotime($order_row["date_purchased"]),
|
157 | 167 | "source" => STORE_NAME,
|
158 |
| - "global_attributes" => array( |
| 168 | + "attributes" => array( |
159 | 169 | "nachname" => utf8_encode($order_row["firstname"]),
|
160 | 170 | "vorname" => utf8_encode($order_row["lastname"]),
|
161 | 171 | "m__nnlich_weiblich" => $customer["gender"],
|
|
168 | 178 | "orders" => $orders
|
169 | 179 | );
|
170 | 180 |
|
| 181 | + if ($update_receivers) { |
| 182 | + $rest->delete("/groups.json/".$group_id."/receivers/".$order_row["email"]); |
| 183 | + } |
| 184 | + |
171 | 185 | if (count($receivers) > 1000) {
|
172 | 186 | $rest->post("/groups.json/".$group_id."/receivers", $receivers);
|
173 | 187 | $receivers = array();
|
|
0 commit comments