Skip to content

Commit 3fd1a30

Browse files
author
php-schubser
committed
first commit
0 parents  commit 3fd1a30

File tree

12 files changed

+627
-0
lines changed

12 files changed

+627
-0
lines changed

changelog.md

Whitespace-only changes.

docs/install.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
### EINE SICHERUNG DER DATENBANK ERSTELLEN
2+
###### Änderungen werden in der Konfigurationstabelle vorgenommen.
3+
4+
---
5+
6+
# Installation
7+
1. Loggen Sie sich in den Admin-Bereich ein
8+
2. Öffnen Sie die **Menüoption Module > Systemmodule**.
9+
3. Wählen Sie das Cleverreach Interface und klicken Sie auf Installieren.
10+
11+
---
12+
13+
#### Für dieses Modul müssen keine Änderungen vorgenommen werden.

docs/usage.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Dieses Modul fügt eine Schnittstelle zum Newsletteranbieter <strong>Cleverreach</strong> hinzu. Im Admin können Sie dann unter \"Zusatzmodule\" Ihre Daten eintragen. Es ist der Export in EINE Kundengruppe möglich.

icon.png

61 KB
Loading

images/cleverreach_interface.jpg

129 KB
Loading

moduleinfo.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "Cleverreach Schnittstelle",
3+
"archiveName": "fishnetservices/cleverreach-interface",
4+
"sourceDir": "new_files",
5+
"version": "auto",
6+
"productNumber": "20027",
7+
"shortDescription": "Newsletter Anbindung",
8+
"description": "Dieses Modul fügt eine Schnittstelle zum Newsletteranbieter <a href=\"http://www.cleverreach.de/?rk=xcetomni\" target=\"_blank\"><strong>Cleverreach</strong></a> hinzu. Im Admin können Sie dann unter \"Zusatzmodule\" Ihre Daten eintragen. Es ist der Export in EINE Kundengruppe möglich.",
9+
"developer": "fishnetservices",
10+
"developerWebsite": "https://www.shopbetreuung.com/",
11+
"website": "https://www.shopbetreuung.com/",
12+
"category": "promotion/marketing",
13+
"price": "free",
14+
"require": {
15+
"composer/autoload": "^1.1.0",
16+
"robinthehood/modified-std-module": "^0.1.0"
17+
},
18+
"modifiedCompatibility": [
19+
"2.0.5.1"
20+
]
21+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
defined('_VALID_XTC') or die('Direct Access to this location is not allowed.');
3+
4+
use RobinTheHood\ModifiedStdModule\Classes\StdModule;
5+
require_once DIR_FS_DOCUMENT_ROOT . '/vendor-no-composer/fishnetservices/CleverreachInterface/autoload.php';
6+
7+
class fs_cleverreach_interface extends StdModule
8+
{
9+
public function __construct()
10+
{
11+
$this->init('MODULE_FS_CLEVERREACH_INTERFACE');
12+
$this->addKey('CLIENT_ID');
13+
$this->addKey('USERNAME');
14+
$this->addKey('PASSWORD');
15+
$this->addKey('IMPORT_SUBSCRIBERS');
16+
$this->addKey('IMPORT_BUYERS');
17+
$this->addKey('GROUP_ID');
18+
}
19+
20+
public function display()
21+
{
22+
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>"
24+
];
25+
}
26+
27+
public function install()
28+
{
29+
30+
$this->addConfiguration('CLIENT_ID', '', 6, 16);
31+
$this->addConfiguration('USERNAME', '', 6, 17);
32+
$this->addConfiguration('PASSWORD', '', 6, 18);
33+
$this->addConfiguration('IMPORT_SUBSCRIBERS', 'true', 6, 19, 'xtc_cfg_select_option(array(\'true\', \'false\'),');
34+
$this->addConfiguration('IMPORT_BUYERS', 'false', 6, 20, 'xtc_cfg_select_option(array(\'true\', \'false\'),');
35+
$this->addConfiguration('GROUP_ID', '', 6, 21);
36+
parent::install();
37+
}
38+
39+
public function remove()
40+
{
41+
parent::remove();
42+
$this->deleteConfiguration('CLIENT_ID');
43+
$this->deleteConfiguration('USERNAME');
44+
$this->deleteConfiguration('PASSWORD');
45+
$this->deleteConfiguration('IMPORT_SUBSCRIBERS');
46+
$this->deleteConfiguration('IMPORT_BUYERS');
47+
$this->deleteConfiguration('GROUP_ID');
48+
}
49+
}
Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
<?php
2+
3+
4+
ini_set('display_errors', 1);
5+
ini_set('display_startup_errors', 1);
6+
error_reporting(E_ALL);
7+
8+
require_once('fs_cleverreach_interface_rest_client.php');
9+
require("../includes/application_top_export.php");
10+
require("../inc/xtc_not_null.inc.php");
11+
require("../inc/xtc_get_country_name.inc.php");
12+
13+
14+
15+
16+
if(!defined('MODULE_FS_CLEVERREACH_INTERFACE_STATUS') || MODULE_FS_CLEVERREACH_INTERFACE_STATUS != 'true')
17+
{
18+
header('Location: ' . preg_replace("/[\r\n]+(.*)$/i", "", html_entity_decode($_SERVER['HTTP_REFERER'])));
19+
exit();
20+
}
21+
22+
23+
24+
if(!defined('MODULE_FS_CLEVERREACH_INTERFACE_CLIENT_ID') || !defined('MODULE_FS_CLEVERREACH_INTERFACE_USERNAME') || !defined('MODULE_FS_CLEVERREACH_INTERFACE_PASSWORD'))
25+
{
26+
27+
header('Location: ' . preg_replace("/[\r\n]+(.*)$/i", "", html_entity_decode($_SERVER['HTTP_REFERER'])));
28+
exit();
29+
}
30+
31+
$rest = new \CR\tools\rest("https://rest.cleverreach.com/v2");
32+
33+
34+
if (trim(MODULE_FS_CLEVERREACH_INTERFACE_CLIENT_ID) == '' || trim(MODULE_FS_CLEVERREACH_INTERFACE_USERNAME) == '' || trim(MODULE_FS_CLEVERREACH_INTERFACE_PASSWORD) == '') {
35+
die('Please enter all login credentials for Cleverreach!');
36+
}
37+
38+
$token = $rest->post('/login',
39+
array(
40+
"client_id"=> MODULE_FS_CLEVERREACH_INTERFACE_CLIENT_ID,
41+
"login"=> MODULE_FS_CLEVERREACH_INTERFACE_USERNAME,
42+
"password"=> MODULE_FS_CLEVERREACH_INTERFACE_PASSWORD
43+
)
44+
);
45+
46+
$rest->setAuthMode("bearer", $token);
47+
48+
$groups = $rest->get("/groups");
49+
50+
$group_id = MODULE_FS_CLEVERREACH_INTERFACE_GROUP_ID;
51+
52+
if (!isset($group_id)) {
53+
die('No groups found! Please create one in the Cleverreach backend');
54+
}
55+
56+
$receivers = array();
57+
58+
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+
}
82+
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']);
86+
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+
}
110+
}
111+
112+
113+
if (MODULE_FS_CLEVERREACH_INTERFACE_IMPORT_BUYERS == 'true') {
114+
$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+
while ($order_row = xtc_db_fetch_array($order_rows)) {
116+
117+
$orders = array();
118+
119+
$orders[] = array(
120+
"order_id" => $order_row["orders_id"], //required
121+
"product_id" => $order_row["products_id"], //optional
122+
"product" => utf8_encode($order_row["products_name"]), //required
123+
"price" => $order_row["products_price"], //optional
124+
"currency" => "EUR", //optional
125+
"amount" => $order_row["products_quantity"], //optional
126+
"source" => STORE_NAME //optional
127+
);
128+
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"] . "'");
130+
$receivers = array('postdata' => array());
131+
132+
if (xtc_db_num_rows($flagged_customers) > 0) {
133+
while ($customer = xtc_db_fetch_array($flagged_customers)) {
134+
135+
$receivers["postdata"][] = array(
136+
"email" => $order_row["email"],
137+
"activated" => strtotime($customer["registered"]),
138+
"registered" => strtotime($customer["registered"]),
139+
"source" => STORE_NAME,
140+
"global_attributes" => array(
141+
"nachname" => utf8_encode($order_row["firstname"]),
142+
"vorname" => utf8_encode($order_row["lastname"]),
143+
"m__nnlich_weiblich" => $customer["gender"],
144+
"geburtsdatum" => $customer['dob'],
145+
"ort" => utf8_encode($order_row["city"]),
146+
"street" => utf8_encode($order_row["street"]),
147+
"zip" => $order_row["zip"],
148+
"country" => utf8_encode($order_row["country"])
149+
),
150+
"orders" => $orders
151+
);
152+
153+
if (count($receivers) > 1000) {
154+
$rest->post("/groups.json/".$group_id."/receivers", $receivers);
155+
$receivers = array();
156+
}
157+
}
158+
} else {
159+
$receivers["postdata"][] = array(
160+
"email" => $order_row["email"],
161+
"activated" => strtotime($order_row["date_purchased"]),
162+
"registered" => strtotime($order_row["date_purchased"]),
163+
"source" => STORE_NAME,
164+
"global_attributes" => array(
165+
"nachname" => utf8_encode($order_row["firstname"]),
166+
"vorname" => utf8_encode($order_row["lastname"]),
167+
"m__nnlich_weiblich" => $customer["gender"],
168+
"geburtsdatum" => $customer['dob'],
169+
"ort" => utf8_encode($order_row["city"]),
170+
"street" => utf8_encode($order_row["street"]),
171+
"zip" => $order_row["zip"],
172+
"country" => utf8_encode($order_row["country"])
173+
),
174+
"orders" => $orders
175+
);
176+
177+
if (count($receivers) > 1000) {
178+
$rest->post("/groups.json/".$group_id."/receivers", $receivers);
179+
$receivers = array();
180+
}
181+
}
182+
}
183+
}
184+
185+
if (count($receivers) > 0) {
186+
$rest->post("/groups.json/".$group_id."/receivers", $receivers);
187+
} else {
188+
die('No new receivers found');
189+
}
190+
$receivers = array();
191+
192+
header('Location: ' . preg_replace("/[\r\n]+(.*)$/i", "", html_entity_decode($_SERVER['HTTP_REFERER'])));
193+
exit();

0 commit comments

Comments
 (0)