Skip to content

Commit 29b520c

Browse files
authored
feat: deactivate customer if the last order is canceled
1 parent bbfe3f3 commit 29b520c

File tree

5 files changed

+72
-49
lines changed

5 files changed

+72
-49
lines changed

moduleinfo.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616
"robinthehood/modified-std-module": "^0.1.0"
1717
},
1818
"modifiedCompatibility": [
19-
"2.0.4.2", "2.0.5.1"
19+
"2.0.4.2", "2.0.5.1", "2.0.7.2"
2020
]
2121
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public function __construct()
1515
$this->addKey('IMPORT_SUBSCRIBERS');
1616
$this->addKey('IMPORT_BUYERS');
1717
$this->addKey('GROUP_ID');
18+
$this->addKey('CANCELED_ORDER_STATUS_ID');
1819
}
1920

2021
public function display()
@@ -35,6 +36,8 @@ public function install()
3536
$this->addConfiguration('IMPORT_SUBSCRIBERS', 'true', 6, 19, 'xtc_cfg_select_option(array(\'true\', \'false\'),');
3637
$this->addConfiguration('IMPORT_BUYERS', 'false', 6, 20, 'xtc_cfg_select_option(array(\'true\', \'false\'),');
3738
$this->addConfiguration('GROUP_ID', '', 6, 21);
39+
$this->addConfiguration('CANCELED_ORDER_STATUS_ID', '', 6, 22);
40+
3841
parent::install();
3942
}
4043

@@ -47,5 +50,6 @@ public function remove()
4750
$this->deleteConfiguration('IMPORT_SUBSCRIBERS');
4851
$this->deleteConfiguration('IMPORT_BUYERS');
4952
$this->deleteConfiguration('GROUP_ID');
53+
$this->deleteConfiguration('CANCELED_ORDER_STATUS_ID');
5054
}
5155
}

new_files/interface/fs_cleverreach_interface.php

Lines changed: 63 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,55 @@
6262
}
6363
}
6464

65+
if (MODULE_FS_CLEVERREACH_INTERFACE_IMPORT_BUYERS == 'true') {
66+
$where_clause = '';
67+
if (isset($_GET['export_filter_amazon']) && $_GET['export_filter_amazon'] == 1) {
68+
$where_clause .= " AND customers_email_address NOT LIKE '%@marketplace.amazon.de%'";
69+
}
70+
$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 " . $where_limit . $where_offset);
71+
while ($order_row = xtc_db_fetch_array($order_rows)) {
72+
73+
$orders = array();
74+
75+
$orders[] = array(
76+
"order_id" => $order_row["orders_id"], //required
77+
"product_id" => $order_row["products_id"], //optional
78+
"product" => utf8_encode($order_row["products_name"]), //required
79+
"price" => $order_row["products_price"], //optional
80+
"currency" => "EUR", //optional
81+
"amount" => $order_row["products_quantity"], //optional
82+
"source" => STORE_NAME //optional
83+
);
84+
85+
$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"] . "' AND customers_email_address NOT LIKE '%@marketplace.amazon.de%'");
86+
87+
if (xtc_db_num_rows($flagged_customers) > 0) {
88+
while ($customer = xtc_db_fetch_array($flagged_customers)) {
89+
90+
$receivers[] = array(
91+
"email" => $order_row["email"],
92+
"activated" => getOrdersCount($order_row["customers_id"]) > 0 ? time() : 0,
93+
"registered" => strtotime($customer["registered"]),
94+
"deactivated" => getOrdersCount($order_row["customers_id"]) > 0 ? 0 : time(),
95+
"source" => STORE_NAME,
96+
"active" => getOrdersCount($order_row["customers_id"]) > 0,
97+
"attributes" => array(
98+
"nachname" => utf8_encode($order_row["firstname"]),
99+
"vorname" => utf8_encode($order_row["lastname"]),
100+
"m__nnlich_weiblich" => $customer["gender"],
101+
"geburtsdatum" => $customer['dob'],
102+
"ort" => utf8_encode($order_row["city"]),
103+
"street" => utf8_encode($order_row["street"]),
104+
"zip" => $order_row["zip"],
105+
"country" => utf8_encode($order_row["country"])
106+
),
107+
"orders" => $orders
108+
);
109+
}
110+
}
111+
}
112+
}
113+
65114
if (MODULE_FS_CLEVERREACH_INTERFACE_IMPORT_SUBSCRIBERS == 'true') {
66115

67116

@@ -113,59 +162,12 @@
113162
}
114163
}
115164

116-
if (MODULE_FS_CLEVERREACH_INTERFACE_IMPORT_BUYERS == 'true') {
117-
$where_clause = '';
118-
if (isset($_GET['export_filter_amazon']) && $_GET['export_filter_amazon'] == 1) {
119-
$where_clause .= " AND customers_email_address NOT LIKE '%@marketplace.amazon.de%'";
120-
}
121-
$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 " . $where_limit . $where_offset);
122-
while ($order_row = xtc_db_fetch_array($order_rows)) {
123-
124-
$orders = array();
125-
126-
$orders[] = array(
127-
"order_id" => $order_row["orders_id"], //required
128-
"product_id" => $order_row["products_id"], //optional
129-
"product" => utf8_encode($order_row["products_name"]), //required
130-
"price" => $order_row["products_price"], //optional
131-
"currency" => "EUR", //optional
132-
"amount" => $order_row["products_quantity"], //optional
133-
"source" => STORE_NAME //optional
134-
);
135-
136-
$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"] . "' AND customers_email_address NOT LIKE '%@marketplace.amazon.de%'");
137-
138-
if (xtc_db_num_rows($flagged_customers) > 0) {
139-
while ($customer = xtc_db_fetch_array($flagged_customers)) {
140-
141-
$receivers[] = array(
142-
"email" => $order_row["email"],
143-
"activated" => strtotime($customer["registered"]),
144-
"registered" => strtotime($customer["registered"]),
145-
"source" => STORE_NAME,
146-
"attributes" => array(
147-
"nachname" => utf8_encode($order_row["firstname"]),
148-
"vorname" => utf8_encode($order_row["lastname"]),
149-
"m__nnlich_weiblich" => $customer["gender"],
150-
"geburtsdatum" => $customer['dob'],
151-
"ort" => utf8_encode($order_row["city"]),
152-
"street" => utf8_encode($order_row["street"]),
153-
"zip" => $order_row["zip"],
154-
"country" => utf8_encode($order_row["country"])
155-
),
156-
"orders" => $orders
157-
);
158-
}
159-
}
160-
}
161-
}
162-
163165
if (count($receivers) > 0) {
164166
foreach ($receivers as $receiver) {
165167
try {
166168
$response = $rest->get("/groups.json/".$group_id."/receivers/", $receiver["email"]);
167169
if(!$response) {
168-
$rest->post("/groups.json/".$group_id."/receivers", $receiver);
170+
$rest->post("/groups.json/".$group_id."/receivers", json_encode($receiver));
169171
} else {
170172
$rest->put("/groups.json/".$group_id."/receivers/".$receiver["email"], json_encode($receiver));
171173
}
@@ -200,3 +202,16 @@
200202

201203
unset($_SESSION['cleacerreach_interface_error']);
202204
exit();
205+
206+
207+
function getOrdersCount($customers_id) {
208+
209+
$canceled_orders_status_id = 8;
210+
if (defined('MODULE_FS_CLEVERREACH_INTERFACE_CANCELED_ORDER_STATUS_ID') && MODULE_FS_CLEVERREACH_INTERFACE_CANCELED_ORDER_STATUS_ID != '') {
211+
$canceled_orders_status_id = MODULE_FS_CLEVERREACH_INTERFACE_CANCELED_ORDER_STATUS_ID;
212+
}
213+
$q = xtc_db_query("SELECT COUNT(orders_id) as total FROM " . TABLE_ORDERS . " WHERE customers_id = " . $customers_id . " AND orders_status != " . $canceled_orders_status_id);
214+
$r = xtc_db_fetch_array($q);
215+
216+
return $r['total'];
217+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,5 @@
1616
define('MODULE_FS_CLEVERREACH_INTERFACE_IMPORT_BUYERS_DESC', '');
1717
define('MODULE_FS_CLEVERREACH_INTERFACE_GROUP_ID_TITLE', 'CleverReach Group ID');
1818
define('MODULE_FS_CLEVERREACH_INTERFACE_GROUP_ID_DESC', '');
19+
define('MODULE_FS_CLEVERREACH_INTERFACE_CANCELED_ORDER_STATUS_ID_TITLE', 'Canceled order status ID');
20+
define('MODULE_FS_CLEVERREACH_INTERFACE_CANCELED_ORDER_STATUS_ID_DESC', '');

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,5 @@
1616
define('MODULE_FS_CLEVERREACH_INTERFACE_IMPORT_BUYERS_DESC', '');
1717
define('MODULE_FS_CLEVERREACH_INTERFACE_GROUP_ID_TITLE', 'CleverReach Gruppen-ID');
1818
define('MODULE_FS_CLEVERREACH_INTERFACE_GROUP_ID_DESC', '');
19+
define('MODULE_FS_CLEVERREACH_INTERFACE_CANCELED_ORDER_STATUS_ID_TITLE', 'Status der stornierten Bestellung ID');
20+
define('MODULE_FS_CLEVERREACH_INTERFACE_CANCELED_ORDER_STATUS_ID_DESC', '');

0 commit comments

Comments
 (0)