Skip to content

Commit 30fe35d

Browse files
author
php-schubser
committed
added button for filter amazon customers
1 parent 3fd1a30 commit 30fe35d

File tree

4 files changed

+63
-62
lines changed

4 files changed

+63
-62
lines changed

new_files/admin/includes/modules/system/fs_cleverreach_interface.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ public function __construct()
2020
public function display()
2121
{
2222
return [
23-
'text' => '<br /><div align="center">' . xtc_button(BUTTON_SAVE). xtc_button_link(BUTTON_EXPORT, xtc_href_link("../interface/fs_cleverreach_interface.php")) . xtc_button_link(BUTTON_CANCEL, xtc_href_link(FILENAME_MODULE_EXPORT, 'set=' . $_GET['set'] . '&module=fw_free_products')) . "</div>"
23+
'text' => '<br /><div align="center">' . xtc_button(BUTTON_SAVE).
24+
xtc_button_link(BUTTON_EXPORT, xtc_href_link("../interface/fs_cleverreach_interface.php")) .
25+
xtc_button_link(BUTTON_EXPORT_FILTER_AMAZON, xtc_href_link("../interface/fs_cleverreach_interface.php", 'export_filter_amazon=1'), 'name="export_filter_amazon"') .
26+
xtc_button_link(BUTTON_CANCEL, xtc_href_link(FILENAME_MODULE_EXPORT, 'set=' . $_GET['set'] . '&module=fw_free_products')) . "</div>"
2427
];
2528
}
2629

new_files/interface/fs_cleverreach_interface.php

Lines changed: 53 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
<?php
2-
3-
42
ini_set('display_errors', 1);
53
ini_set('display_startup_errors', 1);
64
error_reporting(E_ALL);
@@ -10,27 +8,20 @@
108
require("../inc/xtc_not_null.inc.php");
119
require("../inc/xtc_get_country_name.inc.php");
1210

13-
14-
15-
1611
if(!defined('MODULE_FS_CLEVERREACH_INTERFACE_STATUS') || MODULE_FS_CLEVERREACH_INTERFACE_STATUS != 'true')
1712
{
1813
header('Location: ' . preg_replace("/[\r\n]+(.*)$/i", "", html_entity_decode($_SERVER['HTTP_REFERER'])));
1914
exit();
2015
}
2116

22-
23-
2417
if(!defined('MODULE_FS_CLEVERREACH_INTERFACE_CLIENT_ID') || !defined('MODULE_FS_CLEVERREACH_INTERFACE_USERNAME') || !defined('MODULE_FS_CLEVERREACH_INTERFACE_PASSWORD'))
2518
{
26-
2719
header('Location: ' . preg_replace("/[\r\n]+(.*)$/i", "", html_entity_decode($_SERVER['HTTP_REFERER'])));
2820
exit();
2921
}
3022

3123
$rest = new \CR\tools\rest("https://rest.cleverreach.com/v2");
3224

33-
3425
if (trim(MODULE_FS_CLEVERREACH_INTERFACE_CLIENT_ID) == '' || trim(MODULE_FS_CLEVERREACH_INTERFACE_USERNAME) == '' || trim(MODULE_FS_CLEVERREACH_INTERFACE_PASSWORD) == '') {
3526
die('Please enter all login credentials for Cleverreach!');
3627
}
@@ -55,62 +46,65 @@
5546

5647
$receivers = array();
5748

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)) {
5861

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+
}
8272

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']);
8676

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();
11099
}
100+
}
111101

112102

113103
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+
}
114108
$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 ");
115109
while ($order_row = xtc_db_fetch_array($order_rows)) {
116110

@@ -126,7 +120,7 @@
126120
"source" => STORE_NAME //optional
127121
);
128122

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);
130124
$receivers = array('postdata' => array());
131125

132126
if (xtc_db_num_rows($flagged_customers) > 0) {

new_files/lang/english/modules/system/fs_cleverreach_interface.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@
1515
define('MODULE_FS_CLEVERREACH_INTERFACE_IMPORT_BUYERS_TITLE', 'Cleverreach Import buyers');
1616
define('MODULE_FS_CLEVERREACH_INTERFACE_IMPORT_BUYERS_DESC', '');
1717
define('MODULE_FS_CLEVERREACH_INTERFACE_GROUP_ID_TITLE', 'Cleverreach Group ID');
18-
define('MODULE_FS_CLEVERREACH_INTERFACE_GROUP_ID_DESC', '');
18+
define('MODULE_FS_CLEVERREACH_INTERFACE_GROUP_ID_DESC', '');
19+
20+
define('BUTTON_EXPORT_FILTER_AMAZON', 'Filter Amazon customers');

new_files/lang/german/modules/system/fs_cleverreach_interface.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@
1717
define('MODULE_FS_CLEVERREACH_INTERFACE_IMPORT_BUYERS_TITLE', 'Cleverreach Importiere K&auml;ufer');
1818
define('MODULE_FS_CLEVERREACH_INTERFACE_IMPORT_BUYERS_DESC', '');
1919
define('MODULE_FS_CLEVERREACH_INTERFACE_GROUP_ID_TITLE', 'Cleverreach Gruppen-ID');
20-
define('MODULE_FS_CLEVERREACH_INTERFACE_GROUP_ID_DESC', '');
20+
define('MODULE_FS_CLEVERREACH_INTERFACE_GROUP_ID_DESC', '');
21+
22+
define('BUTTON_EXPORT_FILTER_AMAZON', 'Amazon Kunden ausfiltern');

0 commit comments

Comments
 (0)