Version Notes
Just enter your RuleMailer API key and you are good to go!
You can read more here: http://www.rulemailer.se/support/manual/#e-handel-nyhetsbrev-magento
Download this release
Release Info
Developer | RuleCom |
Extension | Newsletter_RuleMailer |
Version | 1.0.0 |
Comparing to | |
See all releases |
Version 1.0.0
- app/code/community/KL/Rulemailer/Helper/Data.php +30 -0
- app/code/community/KL/Rulemailer/Model/Abstract.php +8 -0
- app/code/community/KL/Rulemailer/Model/Api.php +61 -0
- app/code/community/KL/Rulemailer/Model/Api/List/Custom/Fields.php +41 -0
- app/code/community/KL/Rulemailer/Model/Api/Lists.php +8 -0
- app/code/community/KL/Rulemailer/Model/Api/Response.php +55 -0
- app/code/community/KL/Rulemailer/Model/Api/Subscriber.php +77 -0
- app/code/community/KL/Rulemailer/Model/Array.php +33 -0
- app/code/community/KL/Rulemailer/Model/Config.php +32 -0
- app/code/community/KL/Rulemailer/Model/Observer.php +204 -0
- app/code/community/KL/Rulemailer/Model/Source/List.php +34 -0
- app/code/community/KL/Rulemailer/Test/Case.php +26 -0
- app/code/community/KL/Rulemailer/Test/Model/Api.php +21 -0
- app/code/community/KL/Rulemailer/Test/Model/Api/Lists.php +40 -0
- app/code/community/KL/Rulemailer/Test/Model/Api/Response.php +52 -0
- app/code/community/KL/Rulemailer/Test/Model/Api/Subscriber.php +125 -0
- app/code/community/KL/Rulemailer/Test/Model/Array.php +35 -0
- app/code/community/KL/Rulemailer/Test/Model/Config.php +19 -0
- app/code/community/KL/Rulemailer/Test/Model/Source/List.php +51 -0
- app/code/community/KL/Rulemailer/Test/fixtures/default.yaml +3 -0
- app/code/community/KL/Rulemailer/etc/adminhtml.xml +23 -0
- app/code/community/KL/Rulemailer/etc/config.xml +49 -0
- app/code/community/KL/Rulemailer/etc/system.xml +59 -0
- package.xml +28 -0
app/code/community/KL/Rulemailer/Helper/Data.php
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class KL_Rulemailer_Helper_Data extends Mage_Core_Helper_Abstract
|
3 |
+
{
|
4 |
+
public function isOldPhpVersion()
|
5 |
+
{
|
6 |
+
/**
|
7 |
+
* Explode the version
|
8 |
+
*/
|
9 |
+
$version = explode('.', phpversion());
|
10 |
+
|
11 |
+
/**
|
12 |
+
* If it's not PHP5
|
13 |
+
* Not sure how it will work, but let's give it a try
|
14 |
+
*/
|
15 |
+
if ($version[0] <= 4) {
|
16 |
+
return true;
|
17 |
+
}
|
18 |
+
|
19 |
+
/**
|
20 |
+
* If it's less than 5.2
|
21 |
+
* Some functions has changed in PHP Version 5.3
|
22 |
+
*/
|
23 |
+
if ($version[1] <= 2) {
|
24 |
+
return true;
|
25 |
+
} else {
|
26 |
+
return false;
|
27 |
+
}
|
28 |
+
}
|
29 |
+
|
30 |
+
}
|
app/code/community/KL/Rulemailer/Model/Abstract.php
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
ADDED
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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/List/Custom/Fields.php
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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/Subscriber.php
ADDED
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
}
|
app/code/community/KL/Rulemailer/Model/Array.php
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class KL_Rulemailer_Model_Config extends KL_Rulemailer_Model_Abstract
|
3 |
+
{
|
4 |
+
/**
|
5 |
+
* Configuration section.
|
6 |
+
*
|
7 |
+
* @var string
|
8 |
+
*/
|
9 |
+
const SECTION = 'kl_rulemailer_settings';
|
10 |
+
|
11 |
+
/**
|
12 |
+
* Get a module specific configuration option.
|
13 |
+
*
|
14 |
+
* @param string $key The option name.
|
15 |
+
* @param string $group The option group.
|
16 |
+
* @throws InvalidArgumentException if the given option does not exists.
|
17 |
+
* @return string
|
18 |
+
*/
|
19 |
+
public function get($key, $group = 'general')
|
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(
|
27 |
+
'invalid config key: ' . $configKey
|
28 |
+
);
|
29 |
+
}
|
30 |
+
|
31 |
+
}
|
32 |
+
}
|
app/code/community/KL/Rulemailer/Model/Observer.php
ADDED
@@ -0,0 +1,204 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
15 |
+
{
|
16 |
+
if (Mage::getSingleton('rulemailer/config')->get('logging') == '1') {
|
17 |
+
// Fetch backtrace
|
18 |
+
$callers = debug_backtrace();
|
19 |
+
|
20 |
+
// Setup caller
|
21 |
+
$caller = $callers[1]['class'] . '::' . $callers[1]['function'];
|
22 |
+
|
23 |
+
// Convert to string of not a string
|
24 |
+
if (!is_string($data)) {
|
25 |
+
$data = var_export($data, TRUE);
|
26 |
+
}
|
27 |
+
|
28 |
+
// Log the entry
|
29 |
+
Mage::log('(' . $caller . ') ' . $data, NULL, 'KL_Rulemailer.log', TRUE);
|
30 |
+
}
|
31 |
+
}
|
32 |
+
|
33 |
+
/**
|
34 |
+
* Manage subscription
|
35 |
+
*
|
36 |
+
* @param Varien_Event_Observer $observer
|
37 |
+
*
|
38 |
+
* @return Varien_Event_Observer
|
39 |
+
*/
|
40 |
+
public function manageSubscription(Varien_Event_Observer $observer)
|
41 |
+
{
|
42 |
+
try {
|
43 |
+
$event = $observer->getEvent();
|
44 |
+
$subscriber = $event->getDataObject();
|
45 |
+
$data = $subscriber->getData();
|
46 |
+
|
47 |
+
/**
|
48 |
+
* Check for customer number
|
49 |
+
*/
|
50 |
+
if (!isset($data['customer_id']) || $data['customer_id'] == '0' || !$data['customer_id']) {
|
51 |
+
/**
|
52 |
+
* Make sure a e-mail address was given
|
53 |
+
*/
|
54 |
+
if (isset($data['subscriber_email']) && $data['subscriber_email']) {
|
55 |
+
/**
|
56 |
+
* No customer was found, create a dummy customer object
|
57 |
+
*/
|
58 |
+
$dummyCustomer = Mage::getModel('customer/customer');
|
59 |
+
|
60 |
+
/**
|
61 |
+
* Populate the object
|
62 |
+
*/
|
63 |
+
$dummyCustomer->setEmail($data['subscriber_email']);
|
64 |
+
|
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
|
77 |
+
*/
|
78 |
+
$customer = Mage::getModel('customer/customer')->load($data['customer_id']);
|
79 |
+
|
80 |
+
if ($subscriber->isSubscribed()) {
|
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) {
|
100 |
+
$this->logData('Exception: ' . $e->getMessage());
|
101 |
+
}
|
102 |
+
|
103 |
+
/**
|
104 |
+
* Nothing more to do
|
105 |
+
*/
|
106 |
+
return $observer;
|
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
|
119 |
+
$data = $observer
|
120 |
+
->getEvent()
|
121 |
+
->getDataObject()
|
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 |
+
|
130 |
+
// Check subscription status
|
131 |
+
$newsletter = Mage::getModel('newsletter/subscriber')->loadByCustomer($customer);
|
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) {
|
148 |
+
$this->logData('Exception: ' . $e->getMessage());
|
149 |
+
}
|
150 |
+
|
151 |
+
return $observer;
|
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 |
+
}
|
app/code/community/KL/Rulemailer/Model/Source/List.php
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
ADDED
@@ -0,0 +1,125 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
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/adminhtml.xml
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<acl>
|
4 |
+
<resources>
|
5 |
+
<admin>
|
6 |
+
<children>
|
7 |
+
<system>
|
8 |
+
<children>
|
9 |
+
<config>
|
10 |
+
<children>
|
11 |
+
<kl_rulemailer_settings translate="title" module="rulemailer">
|
12 |
+
<title>RuleMailer Section</title>
|
13 |
+
<sort_order>0</sort_order>
|
14 |
+
</kl_rulemailer_settings>
|
15 |
+
</children>
|
16 |
+
</config>
|
17 |
+
</children>
|
18 |
+
</system>
|
19 |
+
</children>
|
20 |
+
</admin>
|
21 |
+
</resources>
|
22 |
+
</acl>
|
23 |
+
</config>
|
app/code/community/KL/Rulemailer/etc/config.xml
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<KL_Rulemailer>
|
5 |
+
<version>0.0.2</version>
|
6 |
+
</KL_Rulemailer>
|
7 |
+
</modules>
|
8 |
+
<global>
|
9 |
+
<helpers>
|
10 |
+
<rulemailer>
|
11 |
+
<class>KL_Rulemailer_Helper</class>
|
12 |
+
</rulemailer>
|
13 |
+
</helpers>
|
14 |
+
<models>
|
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>
|
app/code/community/KL/Rulemailer/etc/system.xml
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<sections>
|
4 |
+
<kl_rulemailer_settings translate="label" module="rulemailer">
|
5 |
+
<label>RuleMailer</label>
|
6 |
+
<tab>customer</tab>
|
7 |
+
<frontend_type>text</frontend_type>
|
8 |
+
<sort_order>404</sort_order>
|
9 |
+
<show_in_default>1</show_in_default>
|
10 |
+
<show_in_website>1</show_in_website>
|
11 |
+
<show_in_store>1</show_in_store>
|
12 |
+
<groups>
|
13 |
+
<general translate="label">
|
14 |
+
<label>General</label>
|
15 |
+
<frontend_type>text</frontend_type>
|
16 |
+
<show_in_default>1</show_in_default>
|
17 |
+
<show_in_website>1</show_in_website>
|
18 |
+
<show_in_store>1</show_in_store>
|
19 |
+
<sort_order>1</sort_order>
|
20 |
+
<fields>
|
21 |
+
<key translate="label comment">
|
22 |
+
<label>API Key</label>
|
23 |
+
<frontend_type>text</frontend_type>
|
24 |
+
<sort_order>10</sort_order>
|
25 |
+
<show_in_default>1</show_in_default>
|
26 |
+
<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 |
+
<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>
|
49 |
+
<show_in_store>1</show_in_store>
|
50 |
+
<comment>
|
51 |
+
<![CDATA[When enabled all requests will be logged to KL_Rulemailer.log]]>
|
52 |
+
</comment>
|
53 |
+
</logging>
|
54 |
+
</fields>
|
55 |
+
</general>
|
56 |
+
</groups>
|
57 |
+
</kl_rulemailer_settings>
|
58 |
+
</sections>
|
59 |
+
</config>
|
package.xml
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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. 
|
11 |
+

|
12 |
+
It' super easy to setup up, all you need is your RuleMailer API key. 
|
13 |
+

|
14 |
+
Once the plugin is setup your visitors will be able to signup for your newsletter everywhere on your site. 
|
15 |
+

|
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. 
|
17 |
+

|
18 |
+
You can read more about the <a href="http://www.rulemailer.se">RuleMailer newsletter here.</a></description>
|
19 |
+
<notes>Just enter your RuleMailer API key and you are good to go! 
|
20 |
+

|
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>
|