Newsletter_RuleMailer - Version 1.2.0

Version Notes

Improved integration.
Using v2 api of the rule mailer
Added "cart in progress" functionality

For more info about dependencies please refer extension git reposiotry https://github.com/rulecom/rulemailer

Download this release

Release Info

Developer Stanislav
Extension Newsletter_RuleMailer
Version 1.2.0
Comparing to
See all releases


Code changes from version 1.0.0 to 1.2.0

Files changed (39) hide show
  1. app/code/community/KL/Rulemailer/Helper/Data.php +12 -0
  2. app/code/community/KL/Rulemailer/Model/Abstract.php +0 -8
  3. app/code/community/KL/Rulemailer/Model/Api.php +0 -61
  4. app/code/community/KL/Rulemailer/Model/Api/Customizations.php +29 -0
  5. app/code/community/KL/Rulemailer/Model/Api/List/Custom/Fields.php +0 -41
  6. app/code/community/KL/Rulemailer/Model/Api/Lists.php +0 -8
  7. app/code/community/KL/Rulemailer/Model/Api/Response.php +0 -55
  8. app/code/community/KL/Rulemailer/Model/Api/Rest.php +23 -0
  9. app/code/community/KL/Rulemailer/Model/Api/Rest/Client.php +36 -0
  10. app/code/community/KL/Rulemailer/Model/Api/Rest/Exception.php +4 -0
  11. app/code/community/KL/Rulemailer/Model/Api/Rest/GuzzleClient.php +122 -0
  12. app/code/community/KL/Rulemailer/Model/Api/Rest/Response.php +101 -0
  13. app/code/community/KL/Rulemailer/Model/Api/Subscriber.php +199 -46
  14. app/code/community/KL/Rulemailer/Model/Api/Suppression.php +43 -0
  15. app/code/community/KL/Rulemailer/Model/Api/Tag.php +28 -0
  16. app/code/community/KL/Rulemailer/Model/Api/Transactional.php +143 -0
  17. app/code/community/KL/Rulemailer/Model/Array.php +0 -33
  18. app/code/community/KL/Rulemailer/Model/Config.php +3 -2
  19. app/code/community/KL/Rulemailer/Model/Email.php +5 -0
  20. app/code/community/KL/Rulemailer/Model/Email/Template.php +95 -0
  21. app/code/community/KL/Rulemailer/Model/Export/Attributes.php +12 -0
  22. app/code/community/KL/Rulemailer/Model/Export/Clerk.php +74 -0
  23. app/code/community/KL/Rulemailer/Model/Export/FieldsBuilder.php +275 -0
  24. app/code/community/KL/Rulemailer/Model/Export/Manager.php +95 -0
  25. app/code/community/KL/Rulemailer/Model/Observer.php +80 -56
  26. app/code/community/KL/Rulemailer/Model/Source/List.php +0 -34
  27. app/code/community/KL/Rulemailer/Test/Case.php +0 -26
  28. app/code/community/KL/Rulemailer/Test/Model/Api.php +0 -21
  29. app/code/community/KL/Rulemailer/Test/Model/Api/Lists.php +0 -40
  30. app/code/community/KL/Rulemailer/Test/Model/Api/Response.php +0 -52
  31. app/code/community/KL/Rulemailer/Test/Model/Api/Subscriber.php +0 -125
  32. app/code/community/KL/Rulemailer/Test/Model/Array.php +0 -35
  33. app/code/community/KL/Rulemailer/Test/Model/Config.php +0 -19
  34. app/code/community/KL/Rulemailer/Test/Model/Source/List.php +0 -51
  35. app/code/community/KL/Rulemailer/Test/fixtures/default.yaml +0 -3
  36. app/code/community/KL/Rulemailer/etc/config.xml +38 -11
  37. app/code/community/KL/Rulemailer/etc/system.xml +7 -7
  38. app/etc/modules/KL_Rulemailer.xml +9 -0
  39. package.xml +14 -19
app/code/community/KL/Rulemailer/Helper/Data.php CHANGED
@@ -1,6 +1,18 @@
1
  <?php
 
 
 
 
 
 
 
2
  class KL_Rulemailer_Helper_Data extends Mage_Core_Helper_Abstract
3
  {
 
 
 
 
 
4
  public function isOldPhpVersion()
5
  {
6
  /**
1
  <?php
2
+ /**
3
+ * RuleMailer
4
+ */
5
+
6
+ /**
7
+ * Data helper
8
+ */
9
  class KL_Rulemailer_Helper_Data extends Mage_Core_Helper_Abstract
10
  {
11
+ /**
12
+ * Check if the system is running on an old PHP version
13
+ *
14
+ * @return bool
15
+ */
16
  public function isOldPhpVersion()
17
  {
18
  /**
app/code/community/KL/Rulemailer/Model/Abstract.php DELETED
@@ -1,8 +0,0 @@
1
- <?php
2
- class KL_Rulemailer_Model_Abstract extends Mage_Core_Model_Abstract
3
- {
4
- protected function getConfig($key)
5
- {
6
- return Mage::getSingleton('rulemailer/config')->get($key);
7
- }
8
- }
 
 
 
 
 
 
 
 
app/code/community/KL/Rulemailer/Model/Api.php DELETED
@@ -1,61 +0,0 @@
1
- <?php
2
- class KL_Rulemailer_Model_Api
3
- {
4
- /**
5
- * API WSDL URL.
6
- *
7
- * @var string
8
- */
9
- const WSDL = 'http://one.rulemailer.com/api3.6.php?wsdl';
10
-
11
- /**
12
- * The SOAP adapter.
13
- *
14
- * @var SoapClient
15
- */
16
- private $soapClient;
17
-
18
- /**
19
- * Class constructor.
20
- */
21
- public function __construct()
22
- {
23
- $this->soapClient = new SoapClient(self::WSDL);
24
- }
25
-
26
- public function getHelper()
27
- {
28
- return Mage::helper('rulemailer');
29
- }
30
-
31
- public function getSoapClient()
32
- {
33
- return $this->soapClient;
34
- }
35
-
36
- public function setSoapClient($soapClient)
37
- {
38
- $this->soapClient = $soapClient;
39
-
40
- return $this;
41
- }
42
-
43
- protected function getConfig($key)
44
- {
45
- return Mage::getSingleton('rulemailer/config')->get($key);
46
- }
47
-
48
- protected function request()
49
- {
50
- $args = func_get_args(); // Function call arguments.
51
- $func = array_shift($args); // Function to request.
52
-
53
- array_unshift($args, $this->getConfig('key')); // Prepend API key.
54
-
55
- $response = call_user_func_array(
56
- array($this->soapClient, $func), $args
57
- );
58
-
59
- return Mage::getModel('rulemailer/api_response', $response);
60
- }
61
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/KL/Rulemailer/Model/Api/Customizations.php ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class KL_Rulemailer_Model_Api_Customizations extends KL_Rulemailer_Model_Api_Rest
4
+ {
5
+ /**
6
+ * Endpoint
7
+ */
8
+ const CUSTOMIZATIONS_ENDPOINT = 'customizations';
9
+
10
+ /**
11
+ * Find all customizations
12
+ *
13
+ * This call is limited to 100 customizations. Fetch all by changing the
14
+ * page parameter.
15
+ *
16
+ * @param int $page What page to fetch
17
+ *
18
+ * @return KL_Rulemailer_Model_Api_Rest_Response
19
+ */
20
+ public function findAll($page = 0)
21
+ {
22
+ $data = array();
23
+ $data['page'] = $page;
24
+
25
+ $response = $this->client->get(static::CUSTOMIZATIONS_ENDPOINT, $data);
26
+ return new KL_Rulemailer_Model_Api_Rest_Response($response);
27
+ }
28
+
29
+ }
app/code/community/KL/Rulemailer/Model/Api/List/Custom/Fields.php DELETED
@@ -1,41 +0,0 @@
1
- <?php
2
- class KL_Rulemailer_Model_Api_List_Custom_Fields extends KL_Rulemailer_Model_Api
3
- {
4
- /**
5
- * Get all custom fields for the predefined list.
6
- *
7
- * @see KL_Rulemailer_Model_Api::request()
8
- * @return mixed
9
- */
10
- public function get()
11
- {
12
- return $this->request('listCustomFieldsGet');
13
- }
14
-
15
- /**
16
- * Create a new custom field for the predefined list.
17
- *
18
- * @see KL_Rulemailer_Model_Api::request()
19
- * @param string $name The name of the custom field.
20
- * @param string $type Optional type of the custom field.
21
- * @param array $presets Presets values for the custom field.
22
- * @return mixed
23
- */
24
- public function create($name, $type = 'Single line', $presets = array())
25
- {
26
- return $this->request('listCustomFieldCreate', func_get_args());
27
- }
28
-
29
- protected function request()
30
- {
31
- $args = Mage::getModel('rulemailer/array', func_get_args());
32
-
33
- $args->insert($this->getConfig('list_id'), 1);
34
-
35
- if ($this->getHelper()->isOldPhpVersion()) {
36
- return call_user_func_array(array($this, 'parent::request'), $args->toArray());
37
- } else {
38
- return call_user_func_array('parent::request', $args->toArray());
39
- }
40
- }
41
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/KL/Rulemailer/Model/Api/Lists.php DELETED
@@ -1,8 +0,0 @@
1
- <?php
2
- class KL_Rulemailer_Model_Api_Lists extends KL_Rulemailer_Model_Api
3
- {
4
- public function get()
5
- {
6
- return $this->request('listsGet');
7
- }
8
- }
 
 
 
 
 
 
 
 
app/code/community/KL/Rulemailer/Model/Api/Response.php DELETED
@@ -1,55 +0,0 @@
1
- <?php
2
- class KL_Rulemailer_Model_Api_Response extends Varien_Object
3
- {
4
- /**
5
- * Class constructor.
6
- *
7
- * @param stdClass $obj The SOAP response object.
8
- */
9
- public function __construct($obj)
10
- {
11
- foreach (get_object_vars($obj) as $key => $val) {
12
- $this->setData($key, $val);
13
- }
14
- }
15
-
16
- /**
17
- * Get a arbitrary response object value.
18
- *
19
- * @return string
20
- */
21
- public function get($key)
22
- {
23
- return $this->getData($key);
24
- }
25
-
26
- /**
27
- * Get the response status.
28
- *
29
- * @return string
30
- */
31
- public function getStatus()
32
- {
33
- return $this->getData('status');
34
- }
35
-
36
- /**
37
- * Returns true if the request failed.
38
- *
39
- * @return bool
40
- */
41
- public function isError()
42
- {
43
- return !$this->isSuccess();
44
- }
45
-
46
- /**
47
- * Returns true if the request was successful.
48
- *
49
- * @return bool
50
- */
51
- public function isSuccess()
52
- {
53
- return $this->getData('error_code') == 0;
54
- }
55
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/KL/Rulemailer/Model/Api/Rest.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class KL_Rulemailer_Model_Api_Rest
5
+ * @package KL_Rulemailer
6
+ * @author David Wickström <david@karlssonlord.com>
7
+ */
8
+ abstract class KL_Rulemailer_Model_Api_Rest
9
+ {
10
+ /**
11
+ * @var KL_Rulemailer_Model_Api_Rest_Client
12
+ */
13
+ protected $client;
14
+
15
+ /**
16
+ * @param $client
17
+ */
18
+ public function __construct($client = null)
19
+ {
20
+ $this->client = $client ? : new KL_Rulemailer_Model_Api_Rest_GuzzleClient;
21
+ }
22
+
23
+ }
app/code/community/KL/Rulemailer/Model/Api/Rest/Client.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Interface KL_Rulemailer_Model_Api_Rest_Client
5
+ */
6
+ interface KL_Rulemailer_Model_Api_Rest_Client
7
+ {
8
+ /**
9
+ * @param $path
10
+ * @param array $data
11
+ * @return mixed
12
+ */
13
+ public function get($path, array $data = []);
14
+
15
+ /**
16
+ * @param $path
17
+ * @param array $data
18
+ * @return mixed
19
+ */
20
+ public function post($path, array $data = []);
21
+
22
+ /**
23
+ * @param $path
24
+ * @param array $data
25
+ * @return mixed
26
+ */
27
+ public function put($path, array $data = []);
28
+
29
+ /**
30
+ * @param $path
31
+ * @param array $data
32
+ * @return mixed
33
+ */
34
+ public function delete($path, array $data = []);
35
+
36
+ }
app/code/community/KL/Rulemailer/Model/Api/Rest/Exception.php ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ <?php
2
+ class KL_Rulemailer_Model_Api_Rest_Exception extends Zend_Service_Exception
3
+ {
4
+ }
app/code/community/KL/Rulemailer/Model/Api/Rest/GuzzleClient.php ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ use GuzzleHttp\Client;
4
+
5
+ /**
6
+ * Class KL_Rulemailer_Model_Api_Rest_GuzzleClient
7
+ * @author David Wickström <david@karlssonlord.com>
8
+ */
9
+ class KL_Rulemailer_Model_Api_Rest_GuzzleClient implements KL_Rulemailer_Model_Api_Rest_Client
10
+ {
11
+ /**
12
+ * Base url
13
+ */
14
+ const BASE_URL = 'http://app.rule.io/api/v2/';
15
+ /**
16
+ * @var null
17
+ */
18
+ private $httpClient = null;
19
+
20
+ /**
21
+ * @var string
22
+ */
23
+ private $apiKey = null;
24
+
25
+ /**
26
+ * @param $client
27
+ */
28
+ public function __construct($client = null)
29
+ {
30
+ $client = $client ? : new Client([
31
+ 'base_uri' => self::BASE_URL,
32
+ 'query' => [],
33
+ 'headers' => ['Accept-Charset' => 'ISO-8859-1,utf-8'],
34
+ ]);
35
+
36
+ $this->setHttpClient($client);
37
+ $defaultApiKey = Mage::getStoreConfig('kl_rulemailer_settings/general/key');
38
+ $this->setApiKey($defaultApiKey ? $defaultApiKey : getenv('RULEMAILER_APIKEY'));
39
+ }
40
+
41
+ /**
42
+ * Get the API key from the config
43
+ *
44
+ * @return mixed
45
+ */
46
+ private function getApiKey()
47
+ {
48
+ return $this->apiKey;
49
+ }
50
+
51
+ /**
52
+ * Set api custom api key for client
53
+ *
54
+ * @param string $apiKey Api key for Rule
55
+ */
56
+ public function setApiKey($apiKey)
57
+ {
58
+ $this->apiKey = $apiKey;
59
+ }
60
+
61
+ /**
62
+ * @param $client
63
+ */
64
+ private function setHttpClient($client)
65
+ {
66
+ $this->httpClient = $client;
67
+ }
68
+
69
+ /**
70
+ * Return a new instance of this client
71
+ *
72
+ * @return mixed
73
+ */
74
+ public function httpClient()
75
+ {
76
+ return $this->httpClient;
77
+ }
78
+
79
+ /**
80
+ * @param $path
81
+ * @param array $data
82
+ * @return mixed
83
+ */
84
+ public function get($path, array $data = array())
85
+ {
86
+ $data['apikey'] = $this->getApiKey();
87
+ return $this->httpClient()->get($path, array('query' => $data));
88
+ }
89
+
90
+ /**
91
+ * @param $path
92
+ * @param array $data
93
+ * @return mixed
94
+ */
95
+ public function post($path, array $data = array())
96
+ {
97
+ return $this->httpClient()
98
+ ->post($path, array('json' => $data, 'query' => array('apikey' => $this->getApiKey())));
99
+ }
100
+
101
+ /**
102
+ * @param $path
103
+ * @param $data
104
+ * @return mixed
105
+ */
106
+ public function put($path, array $data = array())
107
+ {
108
+ return $this->httpClient()
109
+ ->put($path, array('json' => $data, 'query' => ['apikey' => $this->getApiKey()]));
110
+ }
111
+
112
+ /**
113
+ * @param $path
114
+ * @param array $data
115
+ * @return mixed
116
+ */
117
+ public function delete($path, array $data = array())
118
+ {
119
+ return $this->httpClient()
120
+ ->delete($path, array('json' => $data, 'query' => ['apikey' => $this->getApiKey()]));
121
+ }
122
+ }
app/code/community/KL/Rulemailer/Model/Api/Rest/Response.php ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ use GuzzleHttp\Psr7\Response;
4
+
5
+ class KL_Rulemailer_Model_Api_Rest_Response
6
+ {
7
+ /**
8
+ * @var ResponseInterface
9
+ */
10
+ protected $httpResponse;
11
+
12
+ /**
13
+ * @var array|stdClass
14
+ */
15
+ protected $jsonBody;
16
+
17
+ /**
18
+ * @var string
19
+ */
20
+ protected $rawBody;
21
+
22
+ /**
23
+ * Constructor
24
+ *
25
+ * Assigns the HTTP response to a property, as well as the body
26
+ * representation. It then attempts to decode the body as JSON.
27
+ */
28
+ public function __construct(Response $response)
29
+ {
30
+ $this->httpResponse = $response;
31
+ $this->jsonBody = json_decode($response->getBody());
32
+ }
33
+
34
+ /**
35
+ * Was the request successful?
36
+ *
37
+ * @return bool
38
+ */
39
+ public function isSuccess()
40
+ {
41
+ return $this->httpResponse->getStatusCode() == 200;
42
+ }
43
+
44
+ /**
45
+ * Did an error occur in the request?
46
+ *
47
+ * @return bool
48
+ */
49
+ public function isError()
50
+ {
51
+ return $this->httpResponse->getStatusCode() != 200;
52
+ }
53
+
54
+ /**
55
+ * Fetch error code (if any)
56
+ *
57
+ * @return null|string
58
+ */
59
+ public function getError()
60
+ {
61
+ if ($this->isError()) {
62
+ return $this->httpResponse->getStatusCode() . ': ' . $this->httpResponse->getReasonPhrase();
63
+ }
64
+
65
+ return null;
66
+ }
67
+
68
+ /**
69
+ * Property overloading to JSON elements
70
+ *
71
+ * If a named property exists within the JSON response returned,
72
+ * proxies to it. Otherwise, returns null.
73
+ *
74
+ * @param string $name
75
+ *
76
+ * @return mixed
77
+ */
78
+ public function __get($name)
79
+ {
80
+ if (null === $this->jsonBody) {
81
+ return null;
82
+ }
83
+
84
+ if (!isset($this->jsonBody->{$name})) {
85
+ return null;
86
+ }
87
+
88
+ return $this->jsonBody->{$name};
89
+ }
90
+
91
+ /**
92
+ * Return the decoded response body
93
+ *
94
+ * @return array|stdClass
95
+ */
96
+ public function toValue()
97
+ {
98
+ return $this->jsonBody;
99
+ }
100
+
101
+ }
app/code/community/KL/Rulemailer/Model/Api/Subscriber.php CHANGED
@@ -1,77 +1,230 @@
1
  <?php
2
 
3
- class KL_Rulemailer_Model_Api_Subscriber extends KL_Rulemailer_Model_Api
 
 
 
 
 
 
4
  {
5
- private function prepareCustomFields($fields = array())
6
- {
7
- // Don't bother the API if the field list is empty
8
- if (count($fields) <= 0) {
9
- return $fields;
10
- }
11
 
12
- // Fetch Custom Fields API
13
- $apiFields = Mage::getSingleton('rulemailer/api_list_custom_fields')->get()->getData();
 
 
 
 
 
 
 
14
 
15
- if (isset($apiFields['custom_fields'])) {
16
- $apiFields = $apiFields['custom_fields'];
17
- } else {
18
- $apiFields = array();
19
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
- // Setup return data
22
- $return = array();
 
 
23
 
24
- // Check what data we can add
25
- foreach ($apiFields as $field) {
26
- if (isset($fields[$field->name])) {
27
- $return[] = array(
28
- 'id' => $field->id,
29
- 'value' => $fields[$field->name]
30
- );
31
- }
32
- }
33
 
34
- return $return;
 
35
  }
36
 
37
- public function delete($email)
 
 
 
 
 
 
 
 
 
 
38
  {
39
- return $this->request('subscriberDelete', $email);
40
- }
41
 
42
- public function get($email)
43
- {
44
- return $this->request('subscriberGet', $email);
45
  }
46
 
47
- public function subscribe($email, $customFields = array())
 
 
 
 
 
 
 
 
 
 
 
48
  {
49
- return $this->request('subscriberSubscribe', $email, $this->prepareCustomFields($customFields));
 
 
 
 
 
 
 
 
 
 
50
  }
51
 
52
- public function unsubscribe($email)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
  {
54
- return $this->request('subscriberUnsubscribe', $email);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  }
56
 
57
- public function update($email, $fields)
 
 
 
 
 
 
 
 
 
58
  {
59
- return $this->request('subscriberUpdate', $email, $this->prepareCustomFields($fields));
 
 
 
 
 
 
 
 
60
  }
61
 
62
- protected function request()
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  {
64
- $func_args = func_get_args();
65
 
66
- $args = Mage::getModel('rulemailer/array', $func_args);
 
67
 
68
- $args->insert($this->getConfig('list_id'), 1);
 
 
69
 
70
- if ($this->getHelper()->isOldPhpVersion()) {
71
- $parent_class = get_parent_class($this);
72
- return call_user_func_array(array($parent_class, 'request'), $args->toArray());
 
 
 
 
 
 
 
 
 
 
 
 
 
73
  } else {
74
- return call_user_func_array('parent::request', $args->toArray());
 
 
75
  }
 
76
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
  }
1
  <?php
2
 
3
+ /**
4
+ * Class KL_Rulemailer_Model_Api_Subscriber
5
+ * @package KL_Rulemailer
6
+ * @author Andreas Karlsson <andreas@karlssonlord.com>
7
+ * @author David Wickström <david@karlssonlord.com>
8
+ */
9
+ class KL_Rulemailer_Model_Api_Subscriber extends KL_Rulemailer_Model_Api_Rest
10
  {
11
+ /**
12
+ * Endpoint
13
+ */
14
+ const SUBSCRIBERS_PATH = 'subscribers';
 
 
15
 
16
+ /**
17
+ * Set api custom api key for client
18
+ *
19
+ * @param string $apiKey Api key for Rule
20
+ */
21
+ public function setApiKey($apiKey)
22
+ {
23
+ $this->client->setApiKey($apiKey);
24
+ }
25
 
26
+ /**
27
+ * Create subscriber
28
+ *
29
+ * @param string $email Email address
30
+ * @param array $tags Tag subscriber with these tags, use
31
+ * numerical ID or a string name
32
+ * @param array $fields Customization fields, optional
33
+ * @param bool $updateOnDuplicate Update the subscriber if it already
34
+ * exists, defaults to false
35
+ * @param bool $autoCreateTags Create tags if they don't exist,
36
+ * defaults to false
37
+ * @param bool $autoCreateFields Create group and or field if they don't
38
+ * exist, defaults to false
39
+ *
40
+ * @return KL_Rulemailer_Model_Api_Rest_Response
41
+ */
42
+ public function create($email, array $tags = array(), array $fields = array(), $updateOnDuplicate = true, $autoCreateTags = true, $autoCreateFields = true)
43
+ {
44
+ // Validate if identifier is used
45
+ $this->validateEmailAddress($email, 'email');
46
 
47
+ $subscriber = [
48
+ 'email' => $email,
49
+ 'fields' => $fields
50
+ ];
51
 
52
+ $data = array();
53
+ $data['tags'] = $tags;
54
+ $data['update_on_duplicate'] = $updateOnDuplicate;
55
+ $data['auto_create_tags'] = $autoCreateTags;
56
+ $data['auto_create_fields'] = $autoCreateFields;
57
+ $data['subscribers'] = [$subscriber];
 
 
 
58
 
59
+ $response = $this->client->post(static::SUBSCRIBERS_PATH, $data);
60
+ return new KL_Rulemailer_Model_Api_Rest_Response($response);
61
  }
62
 
63
+ /**
64
+ * Find all subscribers
65
+ *
66
+ * This call is limited to 1000 subscribers. Fetch all by changing the page
67
+ * parameter.
68
+ *
69
+ * @param int $page What page to fetch
70
+ *
71
+ * @return KL_Rulemailer_Model_Api_Rest_Response
72
+ */
73
+ public function findAll($page = 0)
74
  {
75
+ $data = array();
76
+ $data['page'] = $page;
77
 
78
+ $response = $this->client->get(static::SUBSCRIBERS_PATH, $data);
79
+ return new KL_Rulemailer_Model_Api_Rest_Response($response);
 
80
  }
81
 
82
+ /**
83
+ * Find one subscriber
84
+ *
85
+ * Get a subscriber via email or ID.
86
+ *
87
+ * @param int|string $identifier The subscriber identifier
88
+ * @param string $identifiedBy Specify your identifier, id or email;
89
+ * defaults to email
90
+ *
91
+ * @return KL_Rulemailer_Model_Api_Rest_Response
92
+ */
93
+ public function findOne($identifier, $identifiedBy = 'email')
94
  {
95
+ // Validate if identifier is used
96
+ $this->validateEmailAddress($identifier, $identifiedBy);
97
+
98
+ // Compose request path
99
+ $path = sprintf('%s/%s', static::SUBSCRIBERS_PATH, $identifier);
100
+
101
+ $data = array();
102
+ $data['identified_by'] = $identifiedBy;
103
+
104
+ $response = $this->client->get($path, $data);
105
+ return new KL_Rulemailer_Model_Api_Rest_Response($response);
106
  }
107
 
108
+ /**
109
+ * Add tag
110
+ *
111
+ * Add tag/tags to a subscriber.
112
+ *
113
+ * @param array $tags Tag subscriber with these tags, use
114
+ * numerical ID or a string name
115
+ * @param int|string $identifier The subscriber identifier
116
+ * @param string $identifiedBy Specify your identifier, id or email;
117
+ * defaults to email
118
+ *
119
+ * @throws InvalidArgumentException
120
+ * @return KL_Rulemailer_Model_Api_Rest_Response
121
+ */
122
+ public function addTag($tags, $identifier, $identifiedBy = 'email')
123
  {
124
+ // Filter invalid email addresses
125
+ $this->validateEmailAddress($identifier, $identifiedBy);
126
+
127
+ // Filter invalid tags
128
+ $tags = $this->filterTags($tags);
129
+
130
+ // Build request path
131
+ $path = sprintf('%s/%s/tags', static::SUBSCRIBERS_PATH, $identifier);
132
+
133
+ // Compose request parameters array
134
+ $data = array();
135
+ $data['identifier'] = $identifier;
136
+ $data['identified_by'] = $identifiedBy;
137
+ $data['tags'] = $tags;
138
+
139
+ // Make request
140
+ $response = $this->client->post($path, $data);
141
+ return new KL_Rulemailer_Model_Api_Rest_Response($response);
142
  }
143
 
144
+ /**
145
+ * List tags
146
+ *
147
+ * @param int|string $identifier The subscriber identifier
148
+ * @param string $identifiedBy Specify your identifier, id or email;
149
+ * defaults to email
150
+ *
151
+ * @return KL_Rulemailer_Model_Api_Rest_Response
152
+ */
153
+ public function listTags($identifier, $identifiedBy = 'email')
154
  {
155
+ $this->validateEmailAddress($identifier, $identifiedBy);
156
+
157
+ $path = sprintf('%s/%s/tags', static::SUBSCRIBERS_PATH, $identifier);
158
+
159
+ $data = array();
160
+ $data['identified_by'] = $identifiedBy;
161
+
162
+ $response = $this->client->get($path, $data);
163
+ return new KL_Rulemailer_Model_Api_Rest_Response($response);
164
  }
165
 
166
+ /**
167
+ * Remove tag
168
+ *
169
+ * Delete a tag from a subscriber.
170
+ *
171
+ * @param int|string $tagIdentifier The tag identifier, can be the tag name
172
+ * or the tag id
173
+ * @param int|string $identifier The subscriber identifier
174
+ * @param string $identifiedBy Specify your identifier, id or email;
175
+ * defaults to email
176
+ *
177
+ * @return KL_Rulemailer_Model_Api_Rest_Response
178
+ */
179
+ public function removeTag($tagIdentifier, $identifier, $identifiedBy = 'email')
180
  {
181
+ $path = sprintf('%s/%s/tags/%s', static::SUBSCRIBERS_PATH, $identifier, $tagIdentifier);
182
 
183
+ $data = array();
184
+ $data['identified_by'] = $identifiedBy;
185
 
186
+ $response = $this->client->delete($path, $data);
187
+ return new KL_Rulemailer_Model_Api_Rest_Response($response);
188
+ }
189
 
190
+ /**
191
+ * Check for incorrect types and make sure we return an array
192
+ *
193
+ * @param $tags
194
+ * @return array
195
+ * @throws InvalidArgumentException
196
+ */
197
+ private function filterTags($tags)
198
+ {
199
+ if (is_array($tags)) {
200
+ foreach ($tags as $tag) {
201
+ if (!is_scalar($tag)) {
202
+ throw new InvalidArgumentException('Tags must have scalar type.');
203
+ }
204
+ }
205
+ return $tags;
206
  } else {
207
+ if (!is_scalar($tags)) {
208
+ throw new InvalidArgumentException('Tags must have scalar type.');
209
+ }
210
  }
211
+ return array($tags);
212
  }
213
+
214
+ /**
215
+ * Validate email identifiers
216
+ *
217
+ * @param $identifier
218
+ * @param $identifiedBy
219
+ * @throws InvalidArgumentException
220
+ */
221
+ private function validateEmailAddress($identifier, $identifiedBy)
222
+ {
223
+ if ($identifiedBy == 'email') {
224
+ if (!filter_var($identifier, FILTER_VALIDATE_EMAIL)) {
225
+ throw new InvalidArgumentException("The supplied customer email was not valid: {$identifier}");
226
+ }
227
+ }
228
+ }
229
+
230
  }
app/code/community/KL/Rulemailer/Model/Api/Suppression.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class KL_Rulemailer_Model_Api_Suppression extends KL_Rulemailer_Model_Api_Rest
3
+ {
4
+ const SUPPRESSIONS_PATH = 'suppressions';
5
+
6
+ /**
7
+ * Add subscribers
8
+ *
9
+ * Suppress one or multiple subscribers by email and/or ID.
10
+ *
11
+ * @param array $subscribers Subscribers
12
+ *
13
+ * @return KL_Rulemailer_Model_Api_Rest_Response
14
+ */
15
+ public function addSubscribers(array $subscribers)
16
+ {
17
+ $data = array();
18
+ $data['subscribers'] = $subscribers;
19
+
20
+ $response = $this->client->post(static::SUPPRESSIONS_PATH, $data);
21
+ return new KL_Rulemailer_Model_Api_Rest_Response($response);
22
+ }
23
+
24
+ /**
25
+ * Find all
26
+ *
27
+ * This call is limited to 1000 suppressions. Fetch all by changing the page
28
+ * parameter.
29
+ *
30
+ * @param int $page What page to fetch
31
+ *
32
+ * @return KL_Rulemailer_Model_Api_Rest_Response
33
+ */
34
+ public function findAll($page = 0)
35
+ {
36
+ $data = array();
37
+ $data['page'] = $page;
38
+
39
+ $response = $this->client->get(static::SUPPRESSIONS_PATH, $data);
40
+ return new KL_Rulemailer_Model_Api_Rest_Response($response);
41
+ }
42
+
43
+ }
app/code/community/KL/Rulemailer/Model/Api/Tag.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class KL_Rulemailer_Model_Api_Tag extends KL_Rulemailer_Model_Api_Rest
3
+ {
4
+ /**
5
+ * Endpoint
6
+ */
7
+ const PATH = 'tags';
8
+
9
+ /**
10
+ * Find all
11
+ *
12
+ * This call is limited to 1000 tags. Fetch all by changing the page
13
+ * parameter.
14
+ *
15
+ * @param int $page What page to fetch
16
+ *
17
+ * @return KL_Rulemailer_Model_Api_Rest_Response
18
+ */
19
+ public function findAll($page = 0)
20
+ {
21
+ $data = array();
22
+ $data['page'] = $page;
23
+
24
+ $response = $this->client->get(static::PATH, $data);
25
+ return new KL_Rulemailer_Model_Api_Rest_Response($response);
26
+ }
27
+
28
+ }
app/code/community/KL/Rulemailer/Model/Api/Transactional.php ADDED
@@ -0,0 +1,143 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class KL_Rulemailer_Model_Api_Transactional
5
+ * @package KL_Rulemailer
6
+ * @author Andreas Karlsson <andreas@karlssonlord.com>
7
+ * @author David Wickström <david@karlssonlord.com>
8
+ */
9
+ class KL_Rulemailer_Model_Api_Transactional extends KL_Rulemailer_Model_Api_Rest
10
+ {
11
+ /**
12
+ * Endpoint
13
+ */
14
+ const TRANSACTIONALS_ENDPOINT = 'transactionals';
15
+ /**
16
+ * Email
17
+ */
18
+ const EMAIL = 'email';
19
+ /**
20
+ * Text message
21
+ */
22
+ const TEXT_MESSAGE = 'text_message';
23
+
24
+ /**
25
+ * Post a transactional email
26
+ *
27
+ * @param string $subject
28
+ * @param array $from
29
+ * @param array $to
30
+ * @param array $content
31
+ * @param string $transactionName
32
+ * @param boolean $async
33
+ *
34
+ * @throws KL_Rulemailer_Model_Api_Rest_Exception
35
+ * @return \KL_Rulemailer_Model_Api_Rest_Response
36
+ */
37
+ public function sendEmail($subject, array $from, array $to, array $content, $transactionName = '', $async = false)
38
+ {
39
+ $this->validateEmailParams($from, $to, $content);
40
+
41
+ $data = array();
42
+ $data['subject'] = $subject;
43
+ $data['from'] = $from;
44
+ $data['to'] = $to;
45
+ $data['content'] = $content;
46
+ $data['transaction_type'] = self::EMAIL;
47
+
48
+ if ($transactionName !== '') {
49
+ $data['transaction_name'] = $transactionName;
50
+ }
51
+
52
+ $response = $this->client->post(static::TRANSACTIONALS_ENDPOINT, $data);
53
+ return new KL_Rulemailer_Model_Api_Rest_Response($response);
54
+ }
55
+
56
+ /**
57
+ * Post a transactional text message
58
+ *
59
+ * @param array $to
60
+ * @param array $content
61
+ * @param string $transactionName
62
+ * @param boolean $async
63
+ *
64
+ * @throws KL_Rulemailer_Model_Api_Rest_Exception
65
+ * @return \KL_Rulemailer_Model_Api_Rest_Response
66
+ */
67
+ public function sendTextMessage(array $to, array $content, $transactionName = '', $async = false)
68
+ {
69
+ $this->validateTextMessageParams($to, $content);
70
+
71
+ $data = array();
72
+ $data['to'] = $to;
73
+ $data['content'] = $content;
74
+ $data['transaction_type'] = self::TEXT_MESSAGE;
75
+
76
+ if ($transactionName !== '') {
77
+ $data['transaction_name'] = $transactionName;
78
+ }
79
+
80
+ $response = $this->client->post(self::TRANSACTIONALS_ENDPOINT, $data);
81
+ return new KL_Rulemailer_Model_Api_Rest_Response($response);
82
+ }
83
+
84
+ /**
85
+ * @param array $from
86
+ * @param array $to
87
+ * @param array $content
88
+ * @throws KL_Rulemailer_Model_Api_Rest_Exception
89
+ */
90
+ private function validateEmailParams(array $from, array $to, array $content)
91
+ {
92
+ if (!array_key_exists('name', $from)) {
93
+ throw new KL_Rulemailer_Model_Api_Rest_Exception(
94
+ 'Required value "name" is missing for the sender'
95
+ );
96
+ }
97
+
98
+ if (!array_key_exists('email', $from)) {
99
+ throw new KL_Rulemailer_Model_Api_Rest_Exception(
100
+ 'Required value "email" is missing for the sender'
101
+ );
102
+ }
103
+
104
+ if (!array_key_exists('email', $to)) {
105
+ throw new KL_Rulemailer_Model_Api_Rest_Exception(
106
+ 'Required value "email" is missing for the recipient'
107
+ );
108
+ }
109
+
110
+ if (!array_key_exists('html', $content)) {
111
+ throw new KL_Rulemailer_Model_Api_Rest_Exception(
112
+ 'Required content in HTML format is missing'
113
+ );
114
+ }
115
+
116
+ if (!array_key_exists('plain', $content)) {
117
+ throw new KL_Rulemailer_Model_Api_Rest_Exception(
118
+ 'Required content in plain text format is missing'
119
+ );
120
+ }
121
+ }
122
+
123
+ /**
124
+ * @param array $to
125
+ * @param array $content
126
+ * @throws KL_Rulemailer_Model_Api_Rest_Exception
127
+ */
128
+ private function validateTextMessageParams(array $to, array $content)
129
+ {
130
+ if (!array_key_exists('phone_number', $to)) {
131
+ throw new KL_Rulemailer_Model_Api_Rest_Exception(
132
+ 'Required "phone_number" is missing for the recipient'
133
+ );
134
+ }
135
+
136
+ if (!array_key_exists('text_message', $content)) {
137
+ throw new KL_Rulemailer_Model_Api_Rest_Exception(
138
+ 'Required "text_message" is missing'
139
+ );
140
+ }
141
+ }
142
+
143
+ }
app/code/community/KL/Rulemailer/Model/Array.php DELETED
@@ -1,33 +0,0 @@
1
- <?php
2
- class KL_Rulemailer_Model_Array extends ArrayObject
3
- {
4
- private $arr;
5
-
6
- public function __construct($arr)
7
- {
8
- $this->arr = $arr;
9
- }
10
-
11
- public function insert($element, $position = 0)
12
- {
13
- if ($position < 0 || $position >= $this->size()) {
14
- throw new OutOfBoundsException();
15
- }
16
-
17
- $this->arr = array_merge(
18
- array_slice($this->arr, 0, $position),
19
- array($element),
20
- array_slice($this->arr, $position)
21
- );
22
- }
23
-
24
- public function size()
25
- {
26
- return count($this->arr);
27
- }
28
-
29
- public function toArray()
30
- {
31
- return $this->arr;
32
- }
33
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/KL/Rulemailer/Model/Config.php CHANGED
@@ -1,5 +1,6 @@
1
  <?php
2
- class KL_Rulemailer_Model_Config extends KL_Rulemailer_Model_Abstract
 
3
  {
4
  /**
5
  * Configuration section.
@@ -20,7 +21,7 @@ class KL_Rulemailer_Model_Config extends KL_Rulemailer_Model_Abstract
20
  {
21
  $configKey = join(array(self::SECTION, $group, $key), '/');
22
 
23
- if (Mage::getStoreConfigFlag($configKey)) {
24
  return Mage::getStoreConfig($configKey);
25
  } else {
26
  throw new InvalidArgumentException(
1
  <?php
2
+
3
+ class KL_Rulemailer_Model_Config
4
  {
5
  /**
6
  * Configuration section.
21
  {
22
  $configKey = join(array(self::SECTION, $group, $key), '/');
23
 
24
+ if (!is_null(Mage::getStoreConfig($configKey))) {
25
  return Mage::getStoreConfig($configKey);
26
  } else {
27
  throw new InvalidArgumentException(
app/code/community/KL/Rulemailer/Model/Email.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+ class KL_Rulemailer_Model_Email
3
+ extends Mage_Core_Model_Email
4
+ {
5
+ }
app/code/community/KL/Rulemailer/Model/Email/Template.php ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Email template model
5
+ *
6
+ * @category KL
7
+ * @package KL_Rulemailer
8
+ */
9
+ class KL_Rulemailer_Model_Email_Template
10
+ extends Mage_Core_Model_Email_Template
11
+ {
12
+ protected $_mail;
13
+
14
+ public function encode($data)
15
+ {
16
+ return base64_encode($data);
17
+ }
18
+
19
+ /**
20
+ * Send one or multiple emails
21
+ *
22
+ * Returns true if sent successfully, otherwise it returns false.
23
+ *
24
+ * @param array|string $email Receiver email(s)
25
+ * @param array|string $name Receiver name(s)
26
+ * @param array $variables Template variables
27
+ *
28
+ * @return bool
29
+ *
30
+ * @access public
31
+ */
32
+ public function send($email, $name = null, array $variables = array())
33
+ {
34
+ if (!Mage::getSingleton('rulemailer/config')->get('transactional')) {
35
+ Mage::log('Transactionals not enabled.', null, 'api.log', true);
36
+ return parent::send($email, $name, $variables);
37
+ }
38
+
39
+ if (!$this->isValidForSend()) {
40
+ Mage::logException(new Exception('This letter cannot be sent.'));
41
+ return false;
42
+ }
43
+
44
+ $emails = array_values((array)$email);
45
+ $names = is_array($name) ? $name : (array)$name;
46
+ $names = array_values($names);
47
+
48
+ foreach ($emails as $key => $email) {
49
+ if (!isset($names[$key])) {
50
+ $names[$key] = substr($email, 0, strpos($email, '@'));
51
+ }
52
+ }
53
+
54
+ $this->setUseAbsoluteLinks(true);
55
+ $text = $this->getProcessedTemplate($variables);
56
+
57
+ foreach ($emails as $key => $email) {
58
+ try {
59
+ $result = Mage::getModel('rulemailer/api_transactional', null)->sendEmail(
60
+ $this->getProcessedTemplateSubject($variables),
61
+ array('name' => $this->getSenderName(), 'email' => $this->getSenderEmail()),
62
+ array('name' => $names[$key], "email" => $email),
63
+ array('html' => base64_encode($text), 'plain' => base64_encode($text)),
64
+ '',
65
+ false
66
+ );
67
+ } catch(Exception $e) {
68
+ Mage::log($e->getMessage(), null, 'result.log', true);
69
+ }
70
+ }
71
+
72
+ return true;
73
+ }
74
+
75
+ /**
76
+ * Retrieve mail object instance
77
+ *
78
+ * @return KL_Rulemailer_Model_Email|Zend_Mail
79
+ *
80
+ * @access public
81
+ */
82
+ public function getMail()
83
+ {
84
+ if (is_null($this->_mail)) {
85
+ if (Mage::getSingleton('rulemailer/config')->get('transactional')) {
86
+ $this->_mail = Mage::getModel('rulemailer/email');
87
+ } else {
88
+ $this->_mail = parent::getMail();
89
+ }
90
+ }
91
+
92
+ return $this->_mail;
93
+ }
94
+
95
+ }
app/code/community/KL/Rulemailer/Model/Export/Attributes.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class KL_Rulemailer_Model_Export_Attributes
4
+ {
5
+ public static function defaultSet()
6
+ {
7
+ return [
8
+ 'color',
9
+ 'size'
10
+ ];
11
+ }
12
+ }
app/code/community/KL/Rulemailer/Model/Export/Clerk.php ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class KL_Rulemailer_Model_Export_Clerk
5
+ * @author David Wickström <david@karlssonlord.com>
6
+ */
7
+ class KL_Rulemailer_Model_Export_Clerk
8
+ {
9
+ /**
10
+ * @var KL_Rulemailer_Model_Api_Subscriber
11
+ */
12
+ private $remoteSubscriber;
13
+ /**
14
+ * @var KL_Rulemailer_Model_Export_FieldsBuilder
15
+ */
16
+ private $fieldsBuilder;
17
+
18
+ /**
19
+ * @param KL_Rulemailer_Model_Api_Subscriber $api
20
+ * @param KL_Rulemailer_Model_Export_FieldsBuilder $fieldsBuilder
21
+ */
22
+ public function __construct(KL_Rulemailer_Model_Api_Subscriber $api = null, KL_Rulemailer_Model_Export_FieldsBuilder $fieldsBuilder = null)
23
+ {
24
+ $this->remoteSubscriber = $api ? : Mage::getModel('rulemailer/api_subscriber', null);
25
+ $this->fieldsBuilder = $fieldsBuilder ? : new KL_Rulemailer_Model_Export_FieldsBuilder;
26
+ }
27
+
28
+ /**
29
+ * Accepts the order and performs the data export via the RuleMailer API
30
+ *
31
+ * @param Mage_Sales_Model_Order $order
32
+ */
33
+ public function conductExport(Mage_Sales_Model_Order $order)
34
+ {
35
+ $this->remoteSubscriber->setApiKey(Mage::getStoreConfig('kl_rulemailer_settings/general/key', $order->getStoreId()));
36
+ $this->updateOrderFields($this->fieldsBuilder->extractOrderFields($order), $order->getCustomerEmail());
37
+ }
38
+
39
+ /**
40
+ * The method that communicates to update the fields via the RuleMailer API
41
+ *
42
+ * @param array $fields
43
+ * @param $customerEmail
44
+ * @throws InvalidArgumentException
45
+ * @throws KL_Rulemailer_Model_Api_Rest_Exception
46
+ */
47
+ protected function updateOrderFields(array $fields, $customerEmail)
48
+ {
49
+ //Mage::log("update fields:" . json_encode($fields), null, 'KL_Rulemailer.log', true);
50
+ // Filter valid email addresses
51
+ if (!filter_var($customerEmail, FILTER_VALIDATE_EMAIL)) {
52
+ throw new InvalidArgumentException("The supplied customer email was not valid: {$customerEmail}");
53
+ }
54
+
55
+ // Workaround, as specified by sam@rule.io - to allow for them to trigger different actions
56
+ // when customer has ordered a new item
57
+ try {
58
+ $this->remoteSubscriber->removeTag(KL_Rulemailer_Model_Observer::COMPLETE_ORDER_TAG, $customerEmail);
59
+ $this->remoteSubscriber->removeTag(KL_Rulemailer_Model_Observer::CART_IN_PROGRESS_TAG, $customerEmail);
60
+ } catch (Exception $e) {
61
+ Mage::log('Could not remove order tag: '.$e->getMessage(), null, 'KL_Rulemailer.log', true);
62
+ }
63
+
64
+ // Create JSON object & make API call
65
+ $response = $this->remoteSubscriber
66
+ ->create($customerEmail, array(KL_Rulemailer_Model_Observer::COMPLETE_ORDER_TAG), $fields);
67
+
68
+ // Alert if all is not well
69
+ if ($response->isError()) {
70
+ throw new KL_Rulemailer_Model_Api_Rest_Exception($response->getError());
71
+ }
72
+ }
73
+
74
+ }
app/code/community/KL/Rulemailer/Model/Export/FieldsBuilder.php ADDED
@@ -0,0 +1,275 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class KL_Rulemailer_Model_Export_FieldsBuilder
4
+ {
5
+ const ORDER_GROUP = "Order";
6
+ const SUBSCRIBER_GROUP = "User";
7
+ const CART_GROUP = "Cart";
8
+ /**
9
+ * @var Mage_Catalog_Model_Category
10
+ */
11
+ private $category;
12
+ /**
13
+ * @var Mage_Catalog_Model_Product
14
+ */
15
+ private $product;
16
+
17
+ public function __construct(
18
+ Mage_Catalog_Model_Category $category = null,
19
+ Mage_Catalog_Model_Product $product = null,
20
+ Mage_Customer_Model_Customer $customer = null
21
+ ) {
22
+ $this->category = $category ? : Mage::getModel('catalog/category');
23
+ $this->product = $product ? : Mage::getModel('catalog/product');
24
+ $this->customer = $customer ? : Mage::getModel('customer/customer');
25
+ }
26
+
27
+ public function extractCustomerFields(Mage_Customer_Model_Customer $customer)
28
+ {
29
+ $fields = [
30
+ ['key' => self::SUBSCRIBER_GROUP . '.Firstname', 'value' => $customer->getFirstname()],
31
+ ['key' => self::SUBSCRIBER_GROUP . '.Lastname', 'value' => $customer->getLastname()]
32
+ ];
33
+
34
+ if ($customer->getDob()) {
35
+ $fields[] = ['key' => self::SUBSCRIBER_GROUP . '.BirthDate', 'value' => $customer->getDob()];
36
+ }
37
+
38
+ if ($customer->getGender()) {
39
+ $fields[] = ['key' => self::SUBSCRIBER_GROUP . '.Gender', 'value' => $customer->getGender()];
40
+ }
41
+
42
+ return $fields;
43
+ }
44
+
45
+ public function extractCartFields(Mage_Sales_Model_Quote $quote)
46
+ {
47
+ $fields = [
48
+ ['key' => self::CART_GROUP . '.GrandTotal', 'value' => $quote->getGrandTotal()],
49
+ ['key' => self::CART_GROUP . '.Currency', 'value' => $quote->getQuoteCurrencyCode()],
50
+ ['key' => self::CART_GROUP . '.ItemsCount', 'value' => $quote->getItemsCount()],
51
+ ['key' => self::CART_GROUP . '.TotalCost', 'value' => $quote->getGrandTotal()],
52
+ ['key' => self::CART_GROUP . '.Products', 'value' => $this->getProductsJson($quote), 'type' => 'json']
53
+ ];
54
+
55
+ return $fields;
56
+ }
57
+
58
+ protected function getProductsJson($quote)
59
+ {
60
+ $products = [];
61
+
62
+ foreach ($quote->getAllVisibleItems() as $item) {
63
+ $product = $this->product->load($item->getProductId());
64
+ $products[] = ['name' => $product->getName(), 'quantity' => $item->getQty(),
65
+ 'url' => $product->getProductUrl(), 'price' => $product->getPrice()];
66
+ }
67
+
68
+ return json_encode($products);
69
+ }
70
+
71
+ /**
72
+ * Returns an array structure of useful fields
73
+ *
74
+ * @param Mage_Sales_Model_Order $order
75
+ * @return array
76
+ */
77
+ public function extractOrderFields(Mage_Sales_Model_Order $order)
78
+ {
79
+ $fieldSet = [
80
+ ['key' => self::ORDER_GROUP . '.IncrementId', 'value' => (string)$order->getIncrementId()],
81
+ ['key' => self::ORDER_GROUP . '.Date', 'value' => (string)$order->getCreatedAt(), 'type' => 'date'],
82
+ ['key' => self::ORDER_GROUP . '.Firstname', 'value' => (string)$order->getCustomerFirstname()],
83
+ ['key' => self::ORDER_GROUP . '.Lastname', 'value' => (string)$order->getCustomerLastname()],
84
+ ['key' => self::ORDER_GROUP . '.Street', 'value' => (string)$order->getShippingAddress()->getStreet1()],
85
+ ['key' => self::ORDER_GROUP . '.City', 'value' => (string)$order->getShippingAddress()->getCity()],
86
+ ['key' => self::ORDER_GROUP . '.Postcode', 'value' => (string)$order->getShippingAddress()->getPostcode()],
87
+ ['key' => self::ORDER_GROUP . '.Country', 'value' => (string)$order->getShippingAddress()->getCountry()],
88
+ ['key' => self::ORDER_GROUP . '.Phone', 'value' => (string)$order->getShippingAddress()->getTelephone()],
89
+ ['key' => self::ORDER_GROUP . '.TaxAmount', 'value' => (float)$this->getTaxAmount($order)],
90
+ ['key' => self::ORDER_GROUP . '.Sku', 'value' => (array)$this->getOrderSkus($order), 'type' => 'multiple'],
91
+ ['key' => self::ORDER_GROUP . '.StoreId', 'value' => (integer)$order->getStoreId()],
92
+ ['key' => self::ORDER_GROUP . '.Categories', 'value' => (array)$this->getCategoryNames($order), 'type' => 'multiple'],
93
+ ['key' => self::ORDER_GROUP . '.Weight', 'value' => (float)$order->getWeight()],
94
+ ['key' => self::ORDER_GROUP . '.Subtotal', 'value' => (float)$order->getSubtotal()],
95
+ ['key' => self::ORDER_GROUP . '.GrandTotal', 'value' => (float)$order->getGrandTotal()],
96
+ ['key' => self::ORDER_GROUP . '.StoreCurrencyCode', 'value' => (string)$order->getStoreCurrencyCode()],
97
+ ['key' => self::ORDER_GROUP . '.ShippingMethod', 'value' => (string)$order->getShippingMethod()],
98
+ ['key' => self::ORDER_GROUP . '.Coupon', 'value' => (string)$order->getCouponCode()],
99
+ ['key' => self::ORDER_GROUP . '.DiscountAmount', 'value' => (float)$order->getDiscountAmount()],
100
+ ['key' => self::ORDER_GROUP . '.DiscountPercent', 'value' => (float)$this->getDiscountPercent($order)],
101
+ ['key' => self::ORDER_GROUP . '.ShippingAmount', 'value' => (float)$order->getShippingAmount()],
102
+ ['key' => self::ORDER_GROUP . '.Brands', 'value' => (array)$this->getBrands($order), 'type' => 'multiple'],
103
+ ['key' => self::ORDER_GROUP . '.Products', 'value' => $this->getProductsJson($order), 'type' => 'json']
104
+ ];
105
+
106
+ return $this->addArbitraryFields($fieldSet, $order);
107
+ }
108
+
109
+ /**
110
+ * Returns all categories from all products in the order
111
+ *
112
+ * @param $order
113
+ * @return array
114
+ */
115
+ private function getCategoryNames($order)
116
+ {
117
+ $categoryIds = array();
118
+ foreach ($order->getAllVisibleItems() as $item) {
119
+ $product = $this->product->load($item->getProductId());
120
+
121
+ foreach ($product->getCategoryIds() as $categoryId) {
122
+ if (!in_array($categoryId, $categoryIds)) {
123
+ $categoryIds[] = $categoryId;
124
+ }
125
+ }
126
+ }
127
+
128
+ $categories = array();
129
+ foreach ($categoryIds as $categoryId) {
130
+ $category = $this->category->load($categoryId);
131
+ $categories[] = $category->getName();
132
+ }
133
+
134
+ return $categories;
135
+ }
136
+
137
+ /**
138
+ * @param Mage_Sales_Model_Order $order
139
+ * @return string
140
+ */
141
+ private function getOrderSkus(Mage_Sales_Model_Order $order)
142
+ {
143
+ $skus = array();
144
+ foreach ($order->getAllItems() as $item) {
145
+ if ($this->hasSimpleTypeAndIsUnique($item, $skus)) {
146
+ $skus[] = $item->getSku();
147
+ }
148
+ }
149
+ return $skus;
150
+ }
151
+
152
+ /**
153
+ * @param Mage_Sales_Model_Order $order
154
+ * @return array
155
+ */
156
+ private function getBrands(Mage_Sales_Model_Order $order)
157
+ {
158
+ $brands = array();
159
+ foreach ($order->getAllItems() as $item) {
160
+ $product = $this->loadProduct($item);
161
+ $brands[] = $product->getAttributeText('manufacturer');
162
+ }
163
+ return $brands;
164
+ }
165
+
166
+ /**
167
+ * @param Mage_Sales_Model_Order $order
168
+ * @return float
169
+ */
170
+ private function getDiscountPercent(Mage_Sales_Model_Order $order)
171
+ {
172
+ return (float)$order->getDiscountAmount() / (float)$order->getGrandTotal();
173
+ }
174
+
175
+ /**
176
+ * @param $item
177
+ * @param $skus
178
+ * @return bool
179
+ */
180
+ private function hasSimpleTypeAndIsUnique($item, $skus)
181
+ {
182
+ return !in_array($item->getSku(), $skus) && $this->isSimple($item);
183
+ }
184
+
185
+ private function addArbitraryFields(array $fieldSet, Mage_Sales_Model_Order $order)
186
+ {
187
+ $attributes = [];
188
+ foreach (KL_Rulemailer_Model_Export_Attributes::defaultSet() as $attribute) {
189
+ foreach ($order->getAllItems() as $item) {
190
+ if ($this->isSimple($item) && $attributeValue = $this->getAttributeValue($attribute, $item)) {
191
+ $attributes[$attribute][] = $attributeValue;
192
+ }
193
+ }
194
+ }
195
+
196
+ // I got into this mess of throwing booleans around. Haven't got time to redo this.
197
+ // Suck...
198
+ $additionalAttributes = $this->buildFields($attributes);
199
+ if ($additionalAttributes) {
200
+ return array_merge($additionalAttributes, $fieldSet);
201
+ }
202
+
203
+ return $fieldSet;
204
+ }
205
+
206
+
207
+ /**
208
+ * @param Mage_Sales_Model_Order_Item $item
209
+ * @return bool
210
+ */
211
+ private function isSimple(Mage_Sales_Model_Order_Item $item)
212
+ {
213
+ return $item->getProduct()->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_SIMPLE;
214
+ }
215
+
216
+ /**
217
+ * @param Mage_Sales_Model_Order $order
218
+ * @return mixed
219
+ */
220
+ private function getTaxAmount(Mage_Sales_Model_Order $order)
221
+ {
222
+ return $order->getTaxAmount();
223
+ }
224
+
225
+ private function buildFields(array $attributes)
226
+ {
227
+ $fields = [];
228
+ foreach ($attributes as $attributeKey => $attributeValue) {
229
+ $keyValue = $this->buildKeyValue($attributeKey, $attributeValue);
230
+ if ($keyValue) {
231
+ $fields[] = $keyValue;
232
+ }
233
+ }
234
+
235
+ return $fields;
236
+ }
237
+
238
+ private function buildKeyValue($attributeKey, $attributeValue)
239
+ {
240
+ if (count($attributeValue) == 1 && is_null(reset($attributeValue))) return false;
241
+ return ['key' => 'Order.'.ucfirst($attributeKey), 'value' => $attributeValue, 'type' => 'multiple'];
242
+ }
243
+
244
+ private function getValue($attributeValue)
245
+ {
246
+ if (is_array($attributeValue)) {
247
+ if (count($attributeValue) <= 1) {
248
+ return false;
249
+ }
250
+ }
251
+ return $attributeValue;
252
+ }
253
+
254
+ private function getAttributeValue($attributeCode, Mage_Sales_Model_Order_Item $item)
255
+ {
256
+ $product = $this->loadProduct($item);
257
+ $versionInfo = Mage::getVersionInfo();
258
+ if ($versionInfo['minor'] < 9) {
259
+ return $product->getAttributeText($attributeCode);
260
+ }
261
+ $method = 'get'.ucfirst($attributeCode);
262
+ return $product->$method() ? : '';
263
+ }
264
+
265
+ /**
266
+ * @param Mage_Sales_Model_Order_Item $item
267
+ * @return Mage_Core_Model_Abstract
268
+ */
269
+ private function loadProduct(Mage_Sales_Model_Order_Item $item)
270
+ {
271
+ return $item->getProduct()->load($item->getProduct()->getId());
272
+ }
273
+
274
+
275
+ }
app/code/community/KL/Rulemailer/Model/Export/Manager.php ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class KL_Rulemailer_Model_Export_Manager
5
+ */
6
+ class KL_Rulemailer_Model_Export_Manager
7
+ {
8
+ /**
9
+ * @var false|Mage_Core_Model_Abstract
10
+ */
11
+ private $newsletterSubscriber;
12
+ /**
13
+ * @var Mage_Core_Model_Abstract
14
+ */
15
+ private $lastOrderId;
16
+
17
+ /**
18
+ * @var false|Mage_Core_Model_Abstract
19
+ */
20
+ private $exportClerk;
21
+
22
+ /**
23
+ * @var false|Mage_Core_Model_Abstract
24
+ */
25
+ private $order;
26
+
27
+ /**
28
+ * @var null
29
+ */
30
+ private $lastExported = null;
31
+
32
+ /**
33
+ * @param null $newsletterSubscriber
34
+ * @param null $lastOrderId
35
+ * @param null $exportClerk
36
+ * @param null $order
37
+ */
38
+ public function __construct($newsletterSubscriber = null, $lastOrderId = null, $exportClerk = null, $order = null)
39
+ {
40
+ $this->newsletterSubscriber = $newsletterSubscriber ? : Mage::getModel('newsletter/subscriber');
41
+ $this->lastOrderId = $lastOrderId ? : Mage::getStoreConfig('kl_rulemailer/last_exported/order_id');
42
+ $this->exportClerk = $exportClerk ? : Mage::getModel('rulemailer/export_clerk', null);
43
+ $this->order = $order ? : Mage::getModel('sales/order');
44
+ }
45
+
46
+ /**
47
+ * For every order not previously exported
48
+ */
49
+ public function exportData()
50
+ {
51
+ $orders = $this->getOrdersCollection();
52
+ if (count($orders) === 0) return;
53
+ foreach ($orders as $order) {
54
+ try {
55
+ $this->exportClerk->conductExport($order);
56
+ } catch (Exception $e) {
57
+ Mage::log($e->getMessage(), null, 'KL_Rulemailer.log', true);
58
+ }
59
+
60
+ $this->lastExported = $order->getId();
61
+ }
62
+ // Remember which order was the last one to have been exported
63
+ Mage::getModel('core/config')->saveConfig('kl_rulemailer/last_exported/order_id', $this->lastExported);
64
+ }
65
+
66
+ /**
67
+ * @param $email
68
+ * @return bool
69
+ */
70
+ private function isOrderedBySubscriber($email)
71
+ {
72
+ $emailExist = $this->newsletterSubscriber->load($email, 'subscriber_email');
73
+
74
+ if ($emailExist->getId()) {
75
+ return true;
76
+ }
77
+ return false;
78
+ }
79
+
80
+ /**
81
+ * @return mixed
82
+ */
83
+ private function getOrdersCollection()
84
+ {
85
+ $lastExported = Mage::getStoreConfig('kl_rulemailer/last_exported/order_id') ? : 0;
86
+
87
+ return $this->order
88
+ ->getCollection()
89
+ ->addAttributeToFilter('entity_id', array('gt' => $lastExported))
90
+ ->addAttributeToSelect('*')
91
+ ->setOrder('entity_id', 'ASC')
92
+ ;
93
+ }
94
+
95
+ }
app/code/community/KL/Rulemailer/Model/Observer.php CHANGED
@@ -1,14 +1,30 @@
1
  <?php
2
 
3
- /**
4
- * Class KL_Rulemailer_Model_Observer
5
- */
6
- class KL_Rulemailer_Model_Observer extends KL_Rulemailer_Model_Abstract
7
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  /**
9
  * Function for handling observer logging
10
  *
11
  * @param mixed $data
 
12
  * @return void
13
  */
14
  private function logData($data)
@@ -30,6 +46,21 @@ class KL_Rulemailer_Model_Observer extends KL_Rulemailer_Model_Abstract
30
  }
31
  }
32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  /**
34
  * Manage subscription
35
  *
@@ -37,7 +68,7 @@ class KL_Rulemailer_Model_Observer extends KL_Rulemailer_Model_Abstract
37
  *
38
  * @return Varien_Event_Observer
39
  */
40
- public function manageSubscription(Varien_Event_Observer $observer)
41
  {
42
  try {
43
  $event = $observer->getEvent();
@@ -65,12 +96,9 @@ class KL_Rulemailer_Model_Observer extends KL_Rulemailer_Model_Abstract
65
  /**
66
  * Add new subscriber
67
  */
68
- $this->addSubscriber($dummyCustomer, array());
69
  }
70
  } else {
71
- /**
72
- * Customer was found
73
- */
74
 
75
  /**
76
  * Load customer object
@@ -81,19 +109,14 @@ class KL_Rulemailer_Model_Observer extends KL_Rulemailer_Model_Abstract
81
  // Fetch address
82
  $addressId = $customer->getDefaultBillingAddress();
83
 
84
- if (is_object($addressId)) {
85
- $addressId = $addressId->getId();
86
- $fields = Mage::getModel('customer/address')->load($addressId)->getData();
87
- } else {
88
- $fields = array();
89
- }
90
  // Add or update
91
- $this->addSubscriber($customer, $fields);
92
 
93
  } else {
94
  // Remove
95
  $this->logData("Removing subscriber " . $customer->getData('email'));
96
- $this->getApiSubscriber()->delete($customer->getData('email'));
97
  }
98
  }
99
  } catch (Exception $e) {
@@ -107,12 +130,12 @@ class KL_Rulemailer_Model_Observer extends KL_Rulemailer_Model_Abstract
107
  }
108
 
109
  /**
110
- * Address update
111
  *
112
  * @param Varien_Event_Observer $observer
113
  * @return Varien_Event_Observer
114
  */
115
- public function addressUpdate(Varien_Event_Observer $observer)
116
  {
117
  try {
118
  // Fetch observer data
@@ -122,8 +145,7 @@ class KL_Rulemailer_Model_Observer extends KL_Rulemailer_Model_Abstract
122
  ->getData();
123
 
124
  // Load customer object
125
- $customer = Mage::getModel('customer/customer')->load($data['parent_id']);
126
-
127
  // Update if it's an object
128
  if (is_object($customer)) {
129
 
@@ -132,16 +154,15 @@ class KL_Rulemailer_Model_Observer extends KL_Rulemailer_Model_Abstract
132
 
133
  // Make sure we'd like to receive newsletters
134
  if ($newsletter->getData('subscriber_status') == '1') {
135
-
136
  // Set the data fields of the address
137
  $fields = Mage::getModel('customer/address')->load($data['entity_id'])->getData();
138
 
 
139
  // Add or update the subscriber
140
- $this->addSubscriber($customer, $fields);
141
-
142
  } else {
143
  $this->logData("Removing subscriber " . $customer->getData('email'));
144
- $this->getApiSubscriber()->delete($customer->getData('email'));
145
  }
146
  }
147
  } catch (Exception $e) {
@@ -152,53 +173,56 @@ class KL_Rulemailer_Model_Observer extends KL_Rulemailer_Model_Abstract
152
  }
153
 
154
  /**
155
- * Get API subscriber model.
156
  *
157
  * @return KL_Rulemailer_Model_Api_Subscriber
158
  */
159
  private function getApiSubscriber()
160
  {
161
- return Mage::getSingleton('rulemailer/api_subscriber');
162
  }
163
 
164
  /**
165
  * Function for adding or updating subscriber
166
  *
167
- * @param $customer
168
- * @param $fields
169
- * @return bool
 
 
170
  */
171
- public function addSubscriber($customer, $fields = array())
172
  {
173
-
174
- // Add the user
175
- $response = $this->getApiSubscriber()->subscribe($customer->getData('email'), $fields);
176
-
177
- if (!$response) {
178
- return FALSE;
 
 
 
179
  }
180
 
181
- // Try to update if something went wrong
182
- if (intval($response->getData('error_code')) > 0) {
183
- // Log the error message
184
- $this->logData("When adding subscriber, get code error code #" . $response->getData('error_code'));
185
 
186
- // Try to update
187
- $response = $this->getApiSubscriber()->update($customer->getData('email'), $fields);
188
 
189
- // Check if we succeeded this time
190
- if (intval($response->getData('error_code')) > 0) {
191
- // Log the error message
192
- $this->logData("When updating subscriber, get code error code #" . $response->getData('error_code'));
193
- return FALSE;
194
- } else {
195
- $this->logData("Updated subscriber " . $customer->getData('email'));
196
- return TRUE;
197
- }
198
- } else {
199
- $this->logData("Added new subscriber " . $customer->getData('email'));
200
- return TRUE;
 
201
  }
202
- }
203
 
 
 
204
  }
1
  <?php
2
 
3
+ class KL_Rulemailer_Model_Observer
 
 
 
4
  {
5
+ const CART_IN_PROGRESS_TAG = "CartInProgress";
6
+ const NEWSLETTER_TAG = "Newsletter";
7
+ const COMPLETE_ORDER_TAG = "Order";
8
+
9
+ /**
10
+ * @var null
11
+ */
12
+ private $apiSubscriber;
13
+
14
+ /**
15
+ * @param null $apiSubscriber
16
+ */
17
+ public function __construct($apiSubscriber = null)
18
+ {
19
+ $this->apiSubscriber = $apiSubscriber;
20
+ $this->fieldsBuilder = new KL_Rulemailer_Model_Export_FieldsBuilder;
21
+ }
22
+
23
  /**
24
  * Function for handling observer logging
25
  *
26
  * @param mixed $data
27
+ *
28
  * @return void
29
  */
30
  private function logData($data)
46
  }
47
  }
48
 
49
+ public function processCart(Varien_Event_Observer $observer)
50
+ {
51
+ if (Mage::getSingleton('customer/session')->isLoggedIn()) {
52
+ $customer = Mage::getSingleton('customer/session')->getCustomer();
53
+ $quote = $observer->getEvent()->getCart()->getQuote();
54
+
55
+ $fields = array_merge(
56
+ $this->fieldsBuilder->extractCustomerFields($customer),
57
+ $this->fieldsBuilder->extractCartFields($quote)
58
+ );
59
+
60
+ $this->addSubscriber($customer->getEmail(), array(self::CART_IN_PROGRESS_TAG), $fields, true, true, true);
61
+ }
62
+ }
63
+
64
  /**
65
  * Manage subscription
66
  *
68
  *
69
  * @return Varien_Event_Observer
70
  */
71
+ public function processSubscriber(Varien_Event_Observer $observer)
72
  {
73
  try {
74
  $event = $observer->getEvent();
96
  /**
97
  * Add new subscriber
98
  */
99
+ $this->addSubscriber($dummyCustomer, array('newsletter'), array());
100
  }
101
  } else {
 
 
 
102
 
103
  /**
104
  * Load customer object
109
  // Fetch address
110
  $addressId = $customer->getDefaultBillingAddress();
111
 
112
+ $fields = $this->fieldsBuilder->extractCustomerFields($customer);
 
 
 
 
 
113
  // Add or update
114
+ $this->addSubscriber($customer, array("newsletter"), $fields);
115
 
116
  } else {
117
  // Remove
118
  $this->logData("Removing subscriber " . $customer->getData('email'));
119
+ $this->removeSubscriber($customer);
120
  }
121
  }
122
  } catch (Exception $e) {
130
  }
131
 
132
  /**
133
+ * Create RULE subscriber or update existing on customer save
134
  *
135
  * @param Varien_Event_Observer $observer
136
  * @return Varien_Event_Observer
137
  */
138
+ public function processCustomer(Varien_Event_Observer $observer)
139
  {
140
  try {
141
  // Fetch observer data
145
  ->getData();
146
 
147
  // Load customer object
148
+ $customer = $observer->getCustomer();
 
149
  // Update if it's an object
150
  if (is_object($customer)) {
151
 
154
 
155
  // Make sure we'd like to receive newsletters
156
  if ($newsletter->getData('subscriber_status') == '1') {
 
157
  // Set the data fields of the address
158
  $fields = Mage::getModel('customer/address')->load($data['entity_id'])->getData();
159
 
160
+ $this->logData(json_encode($fields));
161
  // Add or update the subscriber
162
+ $this->addSubscriber($customer, array(), $fields);
 
163
  } else {
164
  $this->logData("Removing subscriber " . $customer->getData('email'));
165
+ $this->removeSubscriber($customer);
166
  }
167
  }
168
  } catch (Exception $e) {
173
  }
174
 
175
  /**
176
+ * Get API subscriber model
177
  *
178
  * @return KL_Rulemailer_Model_Api_Subscriber
179
  */
180
  private function getApiSubscriber()
181
  {
182
+ return $this->apiSubscriber ? : Mage::getModel('rulemailer/api_subscriber', null);
183
  }
184
 
185
  /**
186
  * Function for adding or updating subscriber
187
  *
188
+ * @param Mage_Customer_Model_Customer $customer
189
+ * @param array $tags
190
+ * @param array $fields
191
+ *
192
+ * @return void
193
  */
194
+ public function addSubscriber($customer, array $tags, $fields = null)
195
  {
196
+ $response = $this->getApiSubscriber()->create($customer->getData('email'), $tags, $fields, true, true, true);
197
+
198
+ if ($response->isError()) {
199
+ $this->logData("When adding subscriber (" . $customer->getData('email') . "), get code error: " . $response->getError());
200
+ $this->logData('Trying to add tag...');
201
+ $response = $this->getApiSubscriber()->addTag($tags, $customer->getData('email'), 'email');
202
+ if ($response->isError()) {
203
+ $this->logData("When adding tag to subscriber (" . $customer->getData('email') . "), get code error: " . $response->getError());
204
+ }
205
  }
206
 
207
+ $this->logData("Added new subscriber " . $customer->getData('email'));
208
+ }
 
 
209
 
 
 
210
 
211
+ /**
212
+ * Function for adding or updating subscriber
213
+ *
214
+ * @param Mage_Customer_Model_Customer $customer
215
+ *
216
+ * @return void
217
+ */
218
+ public function removeSubscriber($customer)
219
+ {
220
+ $response = $this->getApiSubscriber()->removeTag('newsletter', $customer->getData('email'));
221
+
222
+ if ($response->isError()) {
223
+ return $this->logData("When removing subscriber tag (" . $customer->getData('email') . "), got code error: " . $response->getError());
224
  }
 
225
 
226
+ $this->logData("Removed tag newsletter from subscriber " . $customer->getData('email'));
227
+ }
228
  }
app/code/community/KL/Rulemailer/Model/Source/List.php DELETED
@@ -1,34 +0,0 @@
1
- <?php
2
- class KL_Rulemailer_Model_Source_List extends KL_Rulemailer_Model_Abstract
3
- {
4
- /**
5
- * Get an option array representation of all lists.
6
- *
7
- * @return array
8
- */
9
- public function toOptionArray()
10
- {
11
- $lists = array();
12
-
13
- try {
14
- foreach ($this->getLists() as $list) {
15
- array_push(
16
- $lists,
17
- array('value' => $list->id, 'label' => $list->name)
18
- );
19
- }
20
- } catch (InvalidArgumentException $e) {}
21
-
22
- return $lists;
23
- }
24
-
25
- /**
26
- * Get all lists.
27
- *
28
- * @return KL_Rulemailer_Model_Api_Response
29
- */
30
- private function getLists()
31
- {
32
- return Mage::getSingleton('rulemailer/api_lists')->get()->get('lists');
33
- }
34
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/KL/Rulemailer/Test/Case.php DELETED
@@ -1,26 +0,0 @@
1
- <?php
2
- class KL_Rulemailer_Test_Case extends EcomDev_PHPUnit_Test_Case
3
- {
4
- protected function getResponseObject($vars)
5
- {
6
- $obj = new stdClass();
7
-
8
- foreach ($vars as $key => $val) {
9
- $obj->$key = $val;
10
- }
11
-
12
- return $obj;
13
- }
14
-
15
- protected function getSoapClientStub($vars)
16
- {
17
- $soapClientStub = $this->getMockBuilder('SoapClient')
18
- ->disableOriginalConstructor()
19
- ->getMock();
20
- $soapClientStub->expects($this->any())
21
- ->method('__call')
22
- ->will($this->returnValue($this->getResponseObject($vars)));
23
-
24
- return $soapClientStub;
25
- }
26
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/KL/Rulemailer/Test/Model/Api.php DELETED
@@ -1,21 +0,0 @@
1
- <?php
2
- class KL_Rulemailer_Test_Model_Api extends KL_Rulemailer_Test_Case
3
- {
4
- protected $api;
5
-
6
- protected function setUp()
7
- {
8
- $this->api = Mage::getModel('rulemailer/api');
9
- }
10
-
11
- public function testSetSoapClient()
12
- {
13
- $soapClient = $this->getMockBuilder('SoapClient')
14
- ->disableOriginalConstructor()
15
- ->getMock();
16
-
17
- $this->api->setSoapClient($soapClient);
18
-
19
- $this->assertEquals($soapClient, $this->api->getSoapClient());
20
- }
21
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/KL/Rulemailer/Test/Model/Api/Lists.php DELETED
@@ -1,40 +0,0 @@
1
- <?php
2
- class KL_Rulemailer_Test_Model_Api_Lists extends KL_Rulemailer_Test_Case
3
- {
4
- protected $lists;
5
-
6
- protected function setUp()
7
- {
8
- $this->lists = Mage::getSingleton('rulemailer/api_lists');
9
- }
10
-
11
- /**
12
- * @loadFixture default
13
- */
14
- public function testListsWithSuccess()
15
- {
16
- $list = new stdclass();
17
- $list->id = 4914;
18
- $list->name = 'Karlsson & Lord AB medlemmar';
19
- $this->lists->setSoapClient($this->getSoapClientStub(array(
20
- 'lists' => array($list)
21
- )));
22
-
23
- $lists = $this->lists->get()->get('lists');
24
-
25
- $this->assertEquals(1, count($lists));
26
- $this->assertEquals(4914, $lists[0]->id);
27
- $this->assertEquals('Karlsson & Lord AB medlemmar', $lists[0]->name);
28
- }
29
-
30
- public function testListsWithError()
31
- {
32
- $this->lists->setSoapClient($this->getSoapClientStub(array(
33
- 'error_code' => 1
34
- )));
35
-
36
- $response = $this->lists->get();
37
-
38
- $this->assertTrue($response->isError());
39
- }
40
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/KL/Rulemailer/Test/Model/Api/Response.php DELETED
@@ -1,52 +0,0 @@
1
- <?php
2
- class KL_Rulemailer_Test_Model_Api_Response extends KL_Rulemailer_Test_Case
3
- {
4
- public function testGet()
5
- {
6
- $response = $this->getModel(array('foo' => 'bar'));
7
-
8
- $this->assertEquals('bar', $response->get('foo'));
9
- }
10
-
11
- public function testGetStatus()
12
- {
13
- $response = $this->getModel(array('status' => 'Success'));
14
-
15
- $this->assertEquals('Success', $response->getStatus());
16
- }
17
-
18
- public function testIsErrorWithSuccess()
19
- {
20
- $response = $this->getModel(array('error_code' => 0));
21
-
22
- $this->assertFalse($response->isError());
23
- }
24
-
25
- public function testIsErrorWithError()
26
- {
27
- $response = $this->getModel(array('error_code' => 1));
28
-
29
- $this->assertTrue($response->isError());
30
- }
31
-
32
- public function testIsSuccessWithSuccess()
33
- {
34
- $response = $this->getModel(array('error_code' => 0));
35
-
36
- $this->assertTrue($response->isSuccess());
37
- }
38
-
39
- public function testIsSuccessWithError()
40
- {
41
- $response = $this->getModel(array('error_code' => 1));
42
-
43
- $this->assertFalse($response->isSuccess());
44
- }
45
-
46
- private function getModel($vars)
47
- {
48
- return Mage::getModel(
49
- 'rulemailer/api_response', $this->getResponseObject($vars)
50
- );
51
- }
52
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/KL/Rulemailer/Test/Model/Api/Subscriber.php DELETED
@@ -1,125 +0,0 @@
1
- <?php
2
- class KL_Rulemailer_Test_Model_Api_Subscriber extends KL_Rulemailer_Test_Case
3
- {
4
- protected $subscriber;
5
-
6
- protected function setUp()
7
- {
8
- $this->subscriber = Mage::getSingleton('rulemailer/api_subscriber');
9
- }
10
-
11
- /**
12
- * @loadFixture default
13
- */
14
- public function testDeleteWithSuccess()
15
- {
16
- $this->subscriber->setSoapClient($this->getSoapClientStub(array(
17
- 'error_code' => 0
18
- )));
19
-
20
- $response = $this->subscriber->delete('hello@karlssonlord.com');
21
-
22
- $this->assertTrue($response->isSuccess());
23
- }
24
-
25
- /**
26
- * @loadFixture default
27
- */
28
- public function testDeleteWithError()
29
- {
30
- $this->subscriber->setSoapClient($this->getSoapClientStub(array(
31
- 'error_code' => 3
32
- )));
33
-
34
- $response = $this->subscriber->delete('hello@karlssonlord.com');
35
-
36
- $this->assertTrue($response->isError());
37
- }
38
-
39
- /**
40
- * @loadFixture default
41
- */
42
- public function testGetWithSuccess()
43
- {
44
- $this->subscriber->setSoapClient($this->getSoapClientStub(array(
45
- 'email' => 'hello@karlssonlord.com',
46
- 'subscriber_id' => '2'
47
- )));
48
-
49
- $response = $this->subscriber->get('hello@karlssonlord.com');
50
-
51
- $this->assertEquals('hello@karlssonlord.com', $response->get('email'));
52
- $this->assertEquals('2', $response->get('subscriber_id'));
53
- }
54
-
55
- /**
56
- * @loadFixture default
57
- */
58
- public function testGetWithError()
59
- {
60
- $this->subscriber->setSoapClient($this->getSoapClientStub(array(
61
- 'error_code' => 3
62
- )));
63
-
64
- $response = $this->subscriber->get('hello1@karlssonlord.com');
65
-
66
- $this->assertTrue($response->isError());
67
- }
68
-
69
- /**
70
- * @loadFixture default
71
- */
72
- public function testSubscribeWithSuccess()
73
- {
74
- $this->subscriber->setSoapClient($this->getSoapClientStub(array(
75
- 'error_code' => 0
76
- )));
77
-
78
- $response = $this->subscriber->subscribe('hello' . time() . '@karlssonlord.com');
79
-
80
- $this->assertTrue($response->isSuccess());
81
- }
82
-
83
- /**
84
- * @loadFixture default
85
- */
86
- public function testSubscribeWithError()
87
- {
88
- $this->subscriber->setSoapClient($this->getSoapClientStub(array(
89
- 'error_code' => 9
90
- )));
91
-
92
- $response = $this->subscriber->subscribe('hello' . time() . '@karlssonlord.com');
93
-
94
- $this->assertTrue($response->isError());
95
- }
96
-
97
- /**
98
- * @loadFixture default
99
- */
100
- public function testUnsubscribeWithSuccess()
101
- {
102
- $this->subscriber->setSoapClient($this->getSoapClientStub(array(
103
- 'error_code' => 0
104
- )));
105
-
106
- $response = $this->subscriber->unsubscribe('hello' . time() . '@karlssonlord.com');
107
-
108
- $this->assertTrue($response->isSuccess());
109
- }
110
-
111
- /**
112
- * @loadFixture default
113
- */
114
- public function testUnsubscribeWithError()
115
- {
116
- $this->subscriber->setSoapClient($this->getSoapClientStub(array(
117
- 'error_code' => 3
118
- )));
119
-
120
- $response = $this->subscriber->unsubscribe('hello-unittest@karlssonlord.com');
121
-
122
- $this->assertTrue($response->isError());
123
- }
124
-
125
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/KL/Rulemailer/Test/Model/Array.php DELETED
@@ -1,35 +0,0 @@
1
- <?php
2
- class KL_Rulemailer_Test_Model_Array extends KL_Rulemailer_Test_Case
3
- {
4
- protected $arr;
5
-
6
- protected function setUp()
7
- {
8
- $this->arr = Mage::getModel('rulemailer/array', array(1, 2, 3, 4, 5));
9
- }
10
-
11
- public function testInsert()
12
- {
13
- $this->arr->insert(0, 2);
14
-
15
- $this->assertEquals(array(1, 2, 0, 3, 4, 5), $this->arr->toArray());
16
- }
17
-
18
- /**
19
- * @expectedException OutOfBoundsException
20
- */
21
- public function testInsertWithInvalidPosition()
22
- {
23
- $this->arr->insert(0, -1);
24
- }
25
-
26
- public function testSize()
27
- {
28
- $this->assertEquals(5, $this->arr->size());
29
- }
30
-
31
- public function testToArray()
32
- {
33
- $this->assertEquals(array(1, 2, 3, 4, 5), $this->arr->toArray());
34
- }
35
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/KL/Rulemailer/Test/Model/Config.php DELETED
@@ -1,19 +0,0 @@
1
- <?php
2
- class KL_Rulemailer_Test_Model_Config extends KL_Rulemailer_Test_Case
3
- {
4
- protected $config;
5
-
6
- protected function setUp()
7
- {
8
- $this->config = Mage::getModel('rulemailer/config');
9
- }
10
-
11
- /**
12
- * @expectedException InvalidArgumentException
13
- * @loadFixture default
14
- */
15
- public function testGetWithInvalidKey()
16
- {
17
- $this->config->get('foo');
18
- }
19
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/KL/Rulemailer/Test/Model/Source/List.php DELETED
@@ -1,51 +0,0 @@
1
- <?php
2
- class KL_Rulemailer_Test_Model_Source_list extends KL_Rulemailer_Test_Case
3
- {
4
- protected $list;
5
-
6
- protected function setUp()
7
- {
8
- $this->list = Mage::getModel('rulemailer/source_list');
9
- }
10
-
11
- public function testToOptionArrayWithSuccess()
12
- {
13
- $list = new stdclass();
14
- $list->id = 4914;
15
- $list->name = 'Karlsson & Lord AB';
16
- $response = $this->getModelMock(
17
- 'rulemailer/api_response',
18
- array('get'),
19
- false,
20
- array(new stdclass())
21
- );
22
- $response->expects($this->any())
23
- ->method('get')
24
- ->will($this->returnValue(array($list)));
25
- $apiLists = $this->getModelMock('rulemailer/api_lists', array('get'));
26
- $apiLists->expects($this->any())
27
- ->method('get')
28
- ->will($this->returnValue($response));
29
- $this->replaceByMock('singleton', 'rulemailer/api_lists', $apiLists);
30
-
31
- $lists = $this->list->toOptionArray();
32
-
33
- $this->assertEquals(
34
- array(array('value' => 4914, 'label' => 'Karlsson & Lord AB')),
35
- $lists
36
- );
37
- }
38
-
39
- public function testToOptionArrayWithError()
40
- {
41
- $apiLists = $this->getModelMock('rulemailer/api_lists', array('get'));
42
- $apiLists->expects($this->any())
43
- ->method('get')
44
- ->will($this->throwException(new InvalidArgumentException()));
45
- $this->replaceByMock('singleton', 'rulemailer/api_lists', $apiLists);
46
-
47
- $lists = $this->list->toOptionArray();
48
-
49
- $this->assertEquals(0, count($lists));
50
- }
51
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/KL/Rulemailer/Test/fixtures/default.yaml DELETED
@@ -1,3 +0,0 @@
1
- config:
2
- default/kl_rulemailer_settings/general/key: 0NPn2Njc3eLU1NrToeDG2aja2Zmc
3
- default/kl_rulemailer_settings/general/list_id: 4995
 
 
 
app/code/community/KL/Rulemailer/etc/config.xml CHANGED
@@ -15,35 +15,62 @@
15
  <rulemailer>
16
  <class>KL_Rulemailer_Model</class>
17
  </rulemailer>
 
 
 
 
 
18
  </models>
19
  <events>
20
- <customer_address_save_after>
 
 
 
 
 
 
 
 
 
 
21
  <observers>
22
  <customer_save_after_handler>
23
  <type>model</type>
24
  <class>rulemailer/observer</class>
25
- <method>addressUpdate</method>
26
  <args></args>
27
  </customer_save_after_handler>
28
  </observers>
29
- </customer_address_save_after>
30
  <newsletter_subscriber_save_commit_after>
31
  <observers>
32
  <newsletter_subscriber_save_before_handler>
33
  <type>model</type>
34
  <class>rulemailer/observer</class>
35
- <method>manageSubscription</method>
36
  <args></args>
37
  </newsletter_subscriber_save_before_handler>
38
  </observers>
39
  </newsletter_subscriber_save_commit_after>
40
  </events>
41
  </global>
42
- <phpunit>
43
- <suite>
44
- <modules>
45
- <KL_Rulemailer/>
46
- </modules>
47
- </suite>
48
- </phpunit>
 
 
 
 
 
 
 
 
 
 
 
 
49
  </config>
15
  <rulemailer>
16
  <class>KL_Rulemailer_Model</class>
17
  </rulemailer>
18
+ <core>
19
+ <rewrite>
20
+ <email_template>KL_Rulemailer_Model_Email_Template</email_template>
21
+ </rewrite>
22
+ </core>
23
  </models>
24
  <events>
25
+ <checkout_cart_save_after>
26
+ <observers>
27
+ <cart_save_after_handler>
28
+ <type>model</type>
29
+ <class>rulemailer/observer</class>
30
+ <method>processCart</method>
31
+ <args></args>
32
+ </cart_save_after_handler>
33
+ </observers>
34
+ </checkout_cart_save_after>
35
+ <customer_save_after>
36
  <observers>
37
  <customer_save_after_handler>
38
  <type>model</type>
39
  <class>rulemailer/observer</class>
40
+ <method>processCustomer</method>
41
  <args></args>
42
  </customer_save_after_handler>
43
  </observers>
44
+ </customer_save_after>
45
  <newsletter_subscriber_save_commit_after>
46
  <observers>
47
  <newsletter_subscriber_save_before_handler>
48
  <type>model</type>
49
  <class>rulemailer/observer</class>
50
+ <method>processSubscriber</method>
51
  <args></args>
52
  </newsletter_subscriber_save_before_handler>
53
  </observers>
54
  </newsletter_subscriber_save_commit_after>
55
  </events>
56
  </global>
57
+ <crontab>
58
+ <jobs>
59
+ <export_data_to_rule_mailer>
60
+ <schedule>
61
+ <cron_expr>*/5 * * * *</cron_expr>
62
+ </schedule>
63
+ <run><model>rulemailer/export_manager::exportData</model></run>
64
+ </export_data_to_rule_mailer>
65
+ </jobs>
66
+ </crontab>
67
+ <default>
68
+ <kl_rulemailer_settings>
69
+ <general>
70
+ <module_enabled>1</module_enabled>
71
+ <logging>1</logging>
72
+ <transactional>0</transactional>
73
+ </general>
74
+ </kl_rulemailer_settings>
75
+ </default>
76
  </config>
app/code/community/KL/Rulemailer/etc/system.xml CHANGED
@@ -27,22 +27,22 @@
27
  <show_in_store>1</show_in_store>
28
  <comment><![CDATA[Your secret API key.]]></comment>
29
  </key>
30
- <list_id translate="label comment">
31
- <label>List</label>
32
  <frontend_type>select</frontend_type>
33
- <sort_order>20</sort_order>
34
- <source_model>rulemailer/source_list</source_model>
35
  <show_in_default>1</show_in_default>
36
  <show_in_website>1</show_in_website>
37
  <show_in_store>1</show_in_store>
38
  <comment>
39
- <![CDATA[A valid API key must be present before being able to choose a list.]]>
40
  </comment>
41
- </list_id>
42
  <logging translate="label comment">
43
  <label>Enable logging</label>
44
  <frontend_type>select</frontend_type>
45
- <sort_order>30</sort_order>
46
  <source_model>adminhtml/system_config_source_yesno</source_model>
47
  <show_in_default>1</show_in_default>
48
  <show_in_website>1</show_in_website>
27
  <show_in_store>1</show_in_store>
28
  <comment><![CDATA[Your secret API key.]]></comment>
29
  </key>
30
+ <transactional translate="label comment">
31
+ <label>Enable transactional</label>
32
  <frontend_type>select</frontend_type>
33
+ <sort_order>30</sort_order>
34
+ <source_model>adminhtml/system_config_source_yesno</source_model>
35
  <show_in_default>1</show_in_default>
36
  <show_in_website>1</show_in_website>
37
  <show_in_store>1</show_in_store>
38
  <comment>
39
+ <![CDATA[Send transactional emails with RuleMailer.]]>
40
  </comment>
41
+ </transactional>
42
  <logging translate="label comment">
43
  <label>Enable logging</label>
44
  <frontend_type>select</frontend_type>
45
+ <sort_order>40</sort_order>
46
  <source_model>adminhtml/system_config_source_yesno</source_model>
47
  <show_in_default>1</show_in_default>
48
  <show_in_website>1</show_in_website>
app/etc/modules/KL_Rulemailer.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <KL_Rulemailer>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ </KL_Rulemailer>
8
+ </modules>
9
+ </config>
package.xml CHANGED
@@ -1,28 +1,23 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Newsletter_RuleMailer</name>
4
- <version>1.0.0</version>
5
  <stability>stable</stability>
6
- <license uri="http://opensource.org/licenses/osl-3.0.php">Open Software License (OSL)</license>
7
  <channel>community</channel>
8
  <extends/>
9
- <summary>Let your customers subscribe to your newsletter automatically with full integration to RuleMailer.</summary>
10
- <description>This plugin enables signup for your customers to your RuleMailer newsletter service. &#xD;
 
 
 
11
  &#xD;
12
- It' super easy to setup up, all you need is your RuleMailer API key. &#xD;
13
- &#xD;
14
- Once the plugin is setup your visitors will be able to signup for your newsletter everywhere on your site. &#xD;
15
- &#xD;
16
- In the checkout, your customers will have the choice to subscribe to your newsletter. And the extension will automatically collect all information and send it to RuleMailer. &#xD;
17
- &#xD;
18
- You can read more about the &lt;a href="http://www.rulemailer.se"&gt;RuleMailer newsletter here.&lt;/a&gt;</description>
19
- <notes>Just enter your RuleMailer API key and you are good to go! &#xD;
20
- &#xD;
21
- You can read more here: http://www.rulemailer.se/support/manual/#e-handel-nyhetsbrev-magento</notes>
22
- <authors><author><name>RuleCom</name><user>rulecom</user><email>sam.jahanfar@rule.se</email></author></authors>
23
- <date>2013-11-01</date>
24
- <time>09:28:26</time>
25
- <contents><target name="magecommunity"><dir name="KL"><dir name="Rulemailer"><dir name="Helper"><file name="Data.php" hash="045299110074915c748aa60e32420326"/></dir><dir name="Model"><file name="Abstract.php" hash="af0e33b5bdeb511ba9bf187bc82074db"/><dir name="Api"><dir name="List"><dir name="Custom"><file name="Fields.php" hash="de8fd49655ef5eb1f30ef0c7d91aa457"/></dir></dir><file name="Lists.php" hash="0c3b8e64a20777da3ca30ede2bd15a8a"/><file name="Response.php" hash="22db556bac26052434731a805bf46799"/><file name="Subscriber.php" hash="0d44b8b5787bbb6bdac5e7dd7966fa42"/></dir><file name="Api.php" hash="1518115b3bd9e14fc7246716e541739a"/><file name="Array.php" hash="9c3ba8e6529b08c1aa51ea77afbcf036"/><file name="Config.php" hash="ccbaea025794c91be15dec707b5490ba"/><file name="Observer.php" hash="d3500f32345f521ddd5bdb7720662e00"/><dir name="Source"><file name="List.php" hash="07291171cc6379d9bc0098131befb03e"/></dir></dir><dir name="Test"><file name="Case.php" hash="6d247d0386f931fe4cff8913d1aff29a"/><dir name="Model"><dir name="Api"><file name="Lists.php" hash="356c2d3a5eb9c98f56f646156963b66a"/><file name="Response.php" hash="3a6f91bb1f62dba231efd4ec0d0d2a1c"/><file name="Subscriber.php" hash="c3dfbed1b1ff5486b8a47c2632f63890"/></dir><file name="Api.php" hash="609c1b37250f7360930cce06e5156d54"/><file name="Array.php" hash="73ddb5591c2524484bc59b939b1669cc"/><file name="Config.php" hash="567075089b74c4cb74eacc09daee475f"/><dir name="Source"><file name="List.php" hash="83b2050b46015a2d6837a3fea0ee2111"/></dir></dir><dir name="fixtures"><file name="default.yaml" hash="2fa19abeaa4f915e17c767fbf7eec64f"/></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="83203c043d23f2dc6314aced70189994"/><file name="config.xml" hash="7a5a3f9b4049ee6c9353261947aa2fda"/><file name="system.xml" hash="6f2819bb727fb1602b893b6ecc95585f"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="KL_RuleMailer.xml" hash=""/></dir></target></contents>
26
  <compatible/>
27
- <dependencies><required><php><min>5.4.0</min><max>6.0.0</max></php></required></dependencies>
28
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Newsletter_RuleMailer</name>
4
+ <version>1.2.0</version>
5
  <stability>stable</stability>
6
+ <license>osl</license>
7
  <channel>community</channel>
8
  <extends/>
9
+ <summary>Rule Mailer integration</summary>
10
+ <description>This plugin enables signup for your customers to your RuleMailer newsletter service. It' super easy to setup up, all you need is your RuleMailer API key. Once the plugin is setup your visitors will be able to signup for your newsletter everywhere on your site. In the checkout, your customers will have the choice to subscribe to your newsletter. And the extension will automatically collect all information and send it to RuleMailer. You can read more about the RuleMailer newsletter here.</description>
11
+ <notes>Improved integration. &#xD;
12
+ Using v2 api of the rule mailer&#xD;
13
+ Added "cart in progress" functionality&#xD;
14
  &#xD;
15
+ For more info about dependencies please refer extension git reposiotry https://github.com/rulecom/rulemailer&#xD;
16
+ </notes>
17
+ <authors><author><name>Stanislav</name><user>stask</user><email>stanislav.kalashnik@rule.se</email></author></authors>
18
+ <date>2016-08-31</date>
19
+ <time>14:27:09</time>
20
+ <contents><target name="magecommunity"><dir name="KL"><dir name="Rulemailer"><dir name="Helper"><file name="Data.php" hash="65c31b984485222ff53c91d99041b970"/></dir><dir name="Model"><dir name="Api"><file name="Customizations.php" hash="20f0180c277b01ec0035762222ac7c07"/><dir name="Rest"><file name="Client.php" hash="701b2fe3f4e41a3918c88d177ebd68a7"/><file name="Exception.php" hash="44526b737bd905c546b6edd5ef68b03b"/><file name="GuzzleClient.php" hash="3ea450b4f6964b82df4ec742b07f439c"/><file name="Response.php" hash="9a1c0194de2b8bede290b00e9fd79b55"/></dir><file name="Rest.php" hash="6687d92135e5e4982a3ee378cd1dd352"/><file name="Subscriber.php" hash="367577e037dedf76dadac857efbbad8c"/><file name="Suppression.php" hash="4587710474791feacd7529cb757a557c"/><file name="Tag.php" hash="633542156951140390c43b66444dd426"/><file name="Transactional.php" hash="b1707ec95febc7d57a11287e17466cb6"/></dir><file name="Config.php" hash="682256625adc66e7b72f14455af049cc"/><dir name="Email"><file name="Template.php" hash="7613a85ddf28a86c5c08d1c050139420"/></dir><file name="Email.php" hash="308c5c0f8d845d081cc61226fccc7109"/><dir name="Export"><file name="Attributes.php" hash="bfb625c3ece06eb0cf9f454ce26e0e3a"/><file name="Clerk.php" hash="0abd074a0f27095a1257633f607c84a3"/><file name="FieldsBuilder.php" hash="2995b5565e835f03c2e1222885fe91fd"/><file name="Manager.php" hash="3f8181fda68b266f0636cdb6cf344ed1"/></dir><file name="Observer.php" hash="07309f180fafc879685a14d359094ea9"/></dir><dir name="etc"><file name="adminhtml.xml" hash="83203c043d23f2dc6314aced70189994"/><file name="config.xml" hash="af9db908ab6ad402ba167e3620089991"/><file name="system.xml" hash="61099beef4176dc02ba2694326fffe88"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="KL_Rulemailer.xml" hash="c440f9593d5df961c0b0d9fddab9baab"/></dir></target></contents>
 
 
 
 
 
 
 
 
21
  <compatible/>
22
+ <dependencies><required><php><min>5.3.0</min><max>5.6.0</max></php></required></dependencies>
23
  </package>