Version Notes
First release
Download this release
Release Info
Developer | ActiveCampaign, Inc. |
Extension | ActiveCampaign_Subscriptions |
Version | 1.0.0 |
Comparing to | |
See all releases |
Version 1.0.0
- app/code/local/ActiveCampaign/Subscriptions/Block/Adminhtml/Subscriptions.php +12 -0
- app/code/local/ActiveCampaign/Subscriptions/Block/Adminhtml/Subscriptions/Edit.php +45 -0
- app/code/local/ActiveCampaign/Subscriptions/Block/Adminhtml/Subscriptions/Edit/Form.php +19 -0
- app/code/local/ActiveCampaign/Subscriptions/Block/Adminhtml/Subscriptions/Edit/Tab/Connection.php +76 -0
- app/code/local/ActiveCampaign/Subscriptions/Block/Adminhtml/Subscriptions/Edit/Tab/Export.php +84 -0
- app/code/local/ActiveCampaign/Subscriptions/Block/Adminhtml/Subscriptions/Edit/Tab/List.php +102 -0
- app/code/local/ActiveCampaign/Subscriptions/Block/Adminhtml/Subscriptions/Edit/Tabs.php +36 -0
- app/code/local/ActiveCampaign/Subscriptions/Block/Adminhtml/Subscriptions/Grid.php +162 -0
- app/code/local/ActiveCampaign/Subscriptions/Block/Subscriptions.php +22 -0
- app/code/local/ActiveCampaign/Subscriptions/Helper/Data.php +6 -0
- app/code/local/ActiveCampaign/Subscriptions/Model/Mysql4/Subscriptions.php +10 -0
- app/code/local/ActiveCampaign/Subscriptions/Model/Mysql4/Subscriptions/Collection.php +10 -0
- app/code/local/ActiveCampaign/Subscriptions/Model/Observer.php +178 -0
- app/code/local/ActiveCampaign/Subscriptions/Model/Status.php +15 -0
- app/code/local/ActiveCampaign/Subscriptions/Model/Subscriptions.php +10 -0
- app/code/local/ActiveCampaign/Subscriptions/controllers/Adminhtml/SubscriptionsController.php +333 -0
- app/code/local/ActiveCampaign/Subscriptions/controllers/IndexController.php +47 -0
- app/code/local/ActiveCampaign/Subscriptions/etc/config.xml +156 -0
- app/code/local/ActiveCampaign/Subscriptions/sql/subscriptions_setup/mysql4-install-1.0.0.php +36 -0
- app/design/adminhtml/default/default/layout/subscriptions.xml +10 -0
- app/design/adminhtml/default/default/template/subscriptions/grid.phtml +5 -0
- app/design/adminhtml/default/default/template/subscriptions/list.phtml +51 -0
- app/design/frontend/default/default/layout/subscriptions.xml +10 -0
- app/design/frontend/default/default/template/subscriptions/subscriptions.phtml +65 -0
- package.xml +24 -0
app/code/local/ActiveCampaign/Subscriptions/Block/Adminhtml/Subscriptions.php
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class ActiveCampaign_Subscriptions_Block_Adminhtml_Subscriptions extends Mage_Adminhtml_Block_Widget_Grid_Container
|
3 |
+
{
|
4 |
+
public function __construct()
|
5 |
+
{
|
6 |
+
$this->_controller = 'adminhtml_subscriptions';
|
7 |
+
$this->_blockGroup = 'subscriptions';
|
8 |
+
$this->_headerText = Mage::helper('subscriptions')->__('ActiveCampaign Settings');
|
9 |
+
$this->_addButtonLabel = Mage::helper('subscriptions')->__('Add Connection');
|
10 |
+
parent::__construct();
|
11 |
+
}
|
12 |
+
}
|
app/code/local/ActiveCampaign/Subscriptions/Block/Adminhtml/Subscriptions/Edit.php
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class ActiveCampaign_Subscriptions_Block_Adminhtml_Subscriptions_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
|
4 |
+
{
|
5 |
+
public function __construct()
|
6 |
+
{
|
7 |
+
parent::__construct();
|
8 |
+
|
9 |
+
$this->_objectId = 'id';
|
10 |
+
$this->_blockGroup = 'subscriptions';
|
11 |
+
$this->_controller = 'adminhtml_subscriptions';
|
12 |
+
|
13 |
+
$this->_updateButton('save', 'label', Mage::helper('subscriptions')->__('Save Connection'));
|
14 |
+
$this->_updateButton('delete', 'label', Mage::helper('subscriptions')->__('Delete Connection'));
|
15 |
+
|
16 |
+
$this->_addButton('saveandcontinue', array(
|
17 |
+
'label' => Mage::helper('adminhtml')->__('Save And Continue Edit'),
|
18 |
+
'onclick' => 'saveAndContinueEdit()',
|
19 |
+
'class' => 'save',
|
20 |
+
), -100);
|
21 |
+
|
22 |
+
$this->_formScripts[] = "
|
23 |
+
function toggleEditor() {
|
24 |
+
if (tinyMCE.getInstanceById('subscriptions_content') == null) {
|
25 |
+
tinyMCE.execCommand('mceAddControl', false, 'subscriptions_content');
|
26 |
+
} else {
|
27 |
+
tinyMCE.execCommand('mceRemoveControl', false, 'subscriptions_content');
|
28 |
+
}
|
29 |
+
}
|
30 |
+
|
31 |
+
function saveAndContinueEdit(){
|
32 |
+
editForm.submit($('edit_form').action+'back/edit/');
|
33 |
+
}
|
34 |
+
";
|
35 |
+
}
|
36 |
+
|
37 |
+
public function getHeaderText()
|
38 |
+
{
|
39 |
+
if( Mage::registry('subscriptions_data') && Mage::registry('subscriptions_data')->getId() ) {
|
40 |
+
return Mage::helper('subscriptions')->__("Edit Connection '%s'", $this->htmlEscape(Mage::registry('subscriptions_data')->getTitle()));
|
41 |
+
} else {
|
42 |
+
return Mage::helper('subscriptions')->__('Add Connection');
|
43 |
+
}
|
44 |
+
}
|
45 |
+
}
|
app/code/local/ActiveCampaign/Subscriptions/Block/Adminhtml/Subscriptions/Edit/Form.php
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class ActiveCampaign_Subscriptions_Block_Adminhtml_Subscriptions_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
|
4 |
+
{
|
5 |
+
protected function _prepareForm()
|
6 |
+
{
|
7 |
+
$form = new Varien_Data_Form(array(
|
8 |
+
'id' => 'edit_form',
|
9 |
+
'action' => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'))),
|
10 |
+
'method' => 'post',
|
11 |
+
'enctype' => 'multipart/form-data'
|
12 |
+
)
|
13 |
+
);
|
14 |
+
|
15 |
+
$form->setUseContainer(true);
|
16 |
+
$this->setForm($form);
|
17 |
+
return parent::_prepareForm();
|
18 |
+
}
|
19 |
+
}
|
app/code/local/ActiveCampaign/Subscriptions/Block/Adminhtml/Subscriptions/Edit/Tab/Connection.php
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class ActiveCampaign_Subscriptions_Block_Adminhtml_Subscriptions_Edit_Tab_Connection extends Mage_Adminhtml_Block_Widget_Form
|
4 |
+
{
|
5 |
+
protected function _prepareForm()
|
6 |
+
{
|
7 |
+
$form = new Varien_Data_Form();
|
8 |
+
$this->setForm($form);
|
9 |
+
$fieldset = $form->addFieldset('subscriptions_form', array('legend'=>Mage::helper('subscriptions')->__('Add Connection Details')));
|
10 |
+
|
11 |
+
$fieldset->addField('title', 'text', array(
|
12 |
+
'label' => Mage::helper('subscriptions')->__('Title'),
|
13 |
+
'class' => 'required-entry',
|
14 |
+
'required' => true,
|
15 |
+
'name' => 'title',
|
16 |
+
));
|
17 |
+
|
18 |
+
/*
|
19 |
+
$fieldset->addField('filename', 'file', array(
|
20 |
+
'label' => Mage::helper('subscriptions')->__('File'),
|
21 |
+
'required' => false,
|
22 |
+
'name' => 'filename',
|
23 |
+
));
|
24 |
+
*/
|
25 |
+
|
26 |
+
$fieldset->addField('status', 'select', array(
|
27 |
+
'label' => Mage::helper('subscriptions')->__('Status'),
|
28 |
+
'name' => 'status',
|
29 |
+
'values' => array(
|
30 |
+
array(
|
31 |
+
'value' => 1,
|
32 |
+
'label' => Mage::helper('subscriptions')->__('Enabled'),
|
33 |
+
),
|
34 |
+
|
35 |
+
array(
|
36 |
+
'value' => 2,
|
37 |
+
'label' => Mage::helper('subscriptions')->__('Disabled'),
|
38 |
+
),
|
39 |
+
),
|
40 |
+
));
|
41 |
+
|
42 |
+
$fieldset->addField('api_url', 'text', array(
|
43 |
+
'label' => Mage::helper('subscriptions')->__('API URL'),
|
44 |
+
'class' => 'required-entry',
|
45 |
+
'required' => true,
|
46 |
+
'name' => 'api_url',
|
47 |
+
));
|
48 |
+
|
49 |
+
$fieldset->addField('api_key', 'text', array(
|
50 |
+
'label' => Mage::helper('subscriptions')->__('API Key'),
|
51 |
+
'class' => 'required-entry',
|
52 |
+
'required' => true,
|
53 |
+
'name' => 'api_key',
|
54 |
+
));
|
55 |
+
|
56 |
+
/*
|
57 |
+
$fieldset->addField('content', 'editor', array(
|
58 |
+
'name' => 'content',
|
59 |
+
'label' => Mage::helper('subscriptions')->__('Content'),
|
60 |
+
'title' => Mage::helper('subscriptions')->__('Content'),
|
61 |
+
'style' => 'width:700px; height:500px;',
|
62 |
+
'wysiwyg' => false,
|
63 |
+
'required' => true,
|
64 |
+
));
|
65 |
+
*/
|
66 |
+
|
67 |
+
if ( Mage::getSingleton('adminhtml/session')->getSubscriptionsData() )
|
68 |
+
{
|
69 |
+
$form->setValues(Mage::getSingleton('adminhtml/session')->getSubscriptionsData());
|
70 |
+
Mage::getSingleton('adminhtml/session')->setSubscriptionsData(null);
|
71 |
+
} elseif ( Mage::registry('subscriptions_data') ) {
|
72 |
+
$form->setValues(Mage::registry('subscriptions_data')->getData());
|
73 |
+
}
|
74 |
+
return parent::_prepareForm();
|
75 |
+
}
|
76 |
+
}
|
app/code/local/ActiveCampaign/Subscriptions/Block/Adminhtml/Subscriptions/Edit/Tab/Export.php
ADDED
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class ActiveCampaign_Subscriptions_Block_Adminhtml_Subscriptions_Edit_Tab_Export extends Mage_Adminhtml_Block_Widget_Form
|
4 |
+
{
|
5 |
+
protected function dbg($var, $continue = 0, $element = "pre")
|
6 |
+
{
|
7 |
+
echo "<" . $element . ">";
|
8 |
+
echo "Vartype: " . gettype($var) . "\n";
|
9 |
+
if ( is_array($var) )
|
10 |
+
{
|
11 |
+
echo "Elements: " . count($var) . "\n\n";
|
12 |
+
}
|
13 |
+
elseif ( is_string($var) )
|
14 |
+
{
|
15 |
+
echo "Length: " . strlen($var) . "\n\n";
|
16 |
+
}
|
17 |
+
print_r($var);
|
18 |
+
echo "</" . $element . ">";
|
19 |
+
if (!$continue) exit();
|
20 |
+
}
|
21 |
+
|
22 |
+
protected function _prepareForm()
|
23 |
+
{
|
24 |
+
$form = new Varien_Data_Form();
|
25 |
+
$this->setForm($form);
|
26 |
+
$fieldset = $form->addFieldset('subscriptions_form', array('legend'=>Mage::helper('subscriptions')->__('Export Newsletter Subscribers To ActiveCampaign')));
|
27 |
+
|
28 |
+
// gets all customers
|
29 |
+
/*
|
30 |
+
$customer_collection = Mage::getModel('customer/customer')->getCollection()->addAttributeToSelect('*');
|
31 |
+
$customers = array();
|
32 |
+
foreach ($customer_collection as $customer) {
|
33 |
+
$customers[] = $customer->toArray();
|
34 |
+
}
|
35 |
+
*/
|
36 |
+
//$this->dbg($customers);
|
37 |
+
|
38 |
+
// gets all customers that are subscribed to the newsletter
|
39 |
+
$subscribers = Mage::getResourceModel('newsletter/subscriber_collection')->showStoreInfo()->showCustomerInfo()->getData();
|
40 |
+
//$this->dbg($subscribers);
|
41 |
+
|
42 |
+
$connection = Mage::registry('subscriptions_data')->getData();
|
43 |
+
//$this->dbg($connection);
|
44 |
+
|
45 |
+
if ($connection) {
|
46 |
+
$api_url = $connection["api_url"];
|
47 |
+
$api_key = $connection["api_key"];
|
48 |
+
|
49 |
+
$ac = new ActiveCampaign($api_url, $api_key);
|
50 |
+
|
51 |
+
|
52 |
+
}
|
53 |
+
|
54 |
+
$fieldset->addField('export_note', 'note', array(
|
55 |
+
'text' => Mage::helper('subscriptions')->__('Check the box below, then click the Save Connection button to export ' . count($subscribers) . ' subscribers to ActiveCampaign.'),
|
56 |
+
));
|
57 |
+
|
58 |
+
$fieldset->addField('export_confirm', 'checkbox', array(
|
59 |
+
'label' => Mage::helper('subscriptions')->__('Confirm?'),
|
60 |
+
'name' => 'export_confirm',
|
61 |
+
));
|
62 |
+
|
63 |
+
/*
|
64 |
+
$fieldset->addField('list_value', 'multiselect', array(
|
65 |
+
'label' => Mage::helper('subscriptions')->__('Lists'),
|
66 |
+
'name' => 'list_value',
|
67 |
+
'values' => $lists_,
|
68 |
+
));
|
69 |
+
*/
|
70 |
+
|
71 |
+
if ( Mage::getSingleton('adminhtml/session')->getSubscriptionsData() ) {
|
72 |
+
$data = Mage::getSingleton('adminhtml/session')->getSubscriptionsData();
|
73 |
+
$data["export_confirm"] = 1;
|
74 |
+
$form->setValues($data);
|
75 |
+
Mage::getSingleton('adminhtml/session')->setSubscriptionsData(null);
|
76 |
+
}
|
77 |
+
elseif ( Mage::registry('subscriptions_data') ) {
|
78 |
+
$data = Mage::registry('subscriptions_data')->getData();
|
79 |
+
$data["export_confirm"] = 1;
|
80 |
+
$form->setValues($data);
|
81 |
+
}
|
82 |
+
return parent::_prepareForm();
|
83 |
+
}
|
84 |
+
}
|
app/code/local/ActiveCampaign/Subscriptions/Block/Adminhtml/Subscriptions/Edit/Tab/List.php
ADDED
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class ActiveCampaign_Subscriptions_Block_Adminhtml_Subscriptions_Edit_Tab_List extends Mage_Adminhtml_Block_Widget_Form
|
4 |
+
{
|
5 |
+
protected function dbg($var, $continue = 0, $element = "pre")
|
6 |
+
{
|
7 |
+
echo "<" . $element . ">";
|
8 |
+
echo "Vartype: " . gettype($var) . "\n";
|
9 |
+
if ( is_array($var) )
|
10 |
+
{
|
11 |
+
echo "Elements: " . count($var) . "\n\n";
|
12 |
+
}
|
13 |
+
elseif ( is_string($var) )
|
14 |
+
{
|
15 |
+
echo "Length: " . strlen($var) . "\n\n";
|
16 |
+
}
|
17 |
+
print_r($var);
|
18 |
+
echo "</" . $element . ">";
|
19 |
+
if (!$continue) exit();
|
20 |
+
}
|
21 |
+
|
22 |
+
protected function _prepareForm()
|
23 |
+
{
|
24 |
+
$form = new Varien_Data_Form();
|
25 |
+
$this->setForm($form);
|
26 |
+
$fieldset = $form->addFieldset('subscriptions_form', array('legend'=>Mage::helper('subscriptions')->__('Choose Lists')));
|
27 |
+
|
28 |
+
$connection = Mage::registry('subscriptions_data')->getData();
|
29 |
+
//$this->dbg($connection,1);
|
30 |
+
|
31 |
+
$lists_ = array();
|
32 |
+
|
33 |
+
$lists_[] = array(
|
34 |
+
"value" => $connection["account_url"] . "-" . "0",
|
35 |
+
"label" => Mage::helper('subscriptions')->__("Please select one or more lists..."),
|
36 |
+
);
|
37 |
+
|
38 |
+
if ($connection) {
|
39 |
+
$api_url = $connection["api_url"];
|
40 |
+
$api_key = $connection["api_key"];
|
41 |
+
|
42 |
+
$ac = new ActiveCampaign($api_url, $api_key);
|
43 |
+
|
44 |
+
// get lists from AC
|
45 |
+
|
46 |
+
$lists = $ac->api("list/list?ids=all&full=0");
|
47 |
+
//$this->dbg($lists);
|
48 |
+
$lists = get_object_vars($lists);
|
49 |
+
|
50 |
+
foreach ($lists as $k => $list) {
|
51 |
+
if (is_int($k)) {
|
52 |
+
// avoid "result_code", "result_message", etc items
|
53 |
+
$list = get_object_vars($list);
|
54 |
+
$list__ = array(
|
55 |
+
"value" => $connection["account_url"] . "-" . $list["id"],
|
56 |
+
"label" => $list["name"],
|
57 |
+
);
|
58 |
+
$lists_[] = $list__;
|
59 |
+
}
|
60 |
+
}
|
61 |
+
//$this->dbg($lists_);
|
62 |
+
}
|
63 |
+
|
64 |
+
// hidden field that stores all of the lists from the install (so we can reference data from them later, based on what they choose).
|
65 |
+
$fieldset->addField('lists', 'hidden', array(
|
66 |
+
'label' => Mage::helper('subscriptions')->__('Lists'),
|
67 |
+
'name' => 'lists',
|
68 |
+
));
|
69 |
+
|
70 |
+
$fieldset->addField('list_value', 'multiselect', array(
|
71 |
+
'label' => Mage::helper('subscriptions')->__('Lists'),
|
72 |
+
'name' => 'list_value',
|
73 |
+
'values' => $lists_,
|
74 |
+
/*'values' => array(
|
75 |
+
array(
|
76 |
+
'value' => 1,
|
77 |
+
'label' => Mage::helper('subscriptions')->__('Enabled'),
|
78 |
+
),
|
79 |
+
|
80 |
+
array(
|
81 |
+
'value' => 2,
|
82 |
+
'label' => Mage::helper('subscriptions')->__('Disabled'),
|
83 |
+
),
|
84 |
+
),*/
|
85 |
+
));
|
86 |
+
|
87 |
+
if ( Mage::getSingleton('adminhtml/session')->getSubscriptionsData() ) {
|
88 |
+
$data = Mage::getSingleton('adminhtml/session')->getSubscriptionsData();
|
89 |
+
$data["lists"] = json_encode($lists_);
|
90 |
+
$data["list_value"] = json_decode($data["list_value"]);
|
91 |
+
$form->setValues($data);
|
92 |
+
Mage::getSingleton('adminhtml/session')->setSubscriptionsData(null);
|
93 |
+
}
|
94 |
+
elseif ( Mage::registry('subscriptions_data') ) {
|
95 |
+
$data = Mage::registry('subscriptions_data')->getData();
|
96 |
+
$data["lists"] = json_encode($lists_);
|
97 |
+
$data["list_value"] = json_decode($data["list_value"]);
|
98 |
+
$form->setValues($data);
|
99 |
+
}
|
100 |
+
return parent::_prepareForm();
|
101 |
+
}
|
102 |
+
}
|
app/code/local/ActiveCampaign/Subscriptions/Block/Adminhtml/Subscriptions/Edit/Tabs.php
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class ActiveCampaign_Subscriptions_Block_Adminhtml_Subscriptions_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
|
4 |
+
{
|
5 |
+
|
6 |
+
public function __construct()
|
7 |
+
{
|
8 |
+
parent::__construct();
|
9 |
+
$this->setId('subscriptions_tabs');
|
10 |
+
$this->setDestElementId('edit_form');
|
11 |
+
$this->setTitle(Mage::helper('subscriptions')->__('ActiveCampaign Settings'));
|
12 |
+
}
|
13 |
+
|
14 |
+
protected function _beforeToHtml()
|
15 |
+
{
|
16 |
+
$this->addTab('form_section_connection', array(
|
17 |
+
'label' => Mage::helper('subscriptions')->__('API Information'),
|
18 |
+
'title' => Mage::helper('subscriptions')->__('API Information'),
|
19 |
+
'content' => $this->getLayout()->createBlock('subscriptions/adminhtml_subscriptions_edit_tab_connection')->toHtml(),
|
20 |
+
));
|
21 |
+
|
22 |
+
$this->addTab('form_section_lists', array(
|
23 |
+
'label' => Mage::helper('subscriptions')->__('Lists'),
|
24 |
+
'title' => Mage::helper('subscriptions')->__('Lists'),
|
25 |
+
'content' => $this->getLayout()->createBlock('subscriptions/adminhtml_subscriptions_edit_tab_list')->toHtml(),
|
26 |
+
));
|
27 |
+
|
28 |
+
$this->addTab('form_section_export', array(
|
29 |
+
'label' => Mage::helper('subscriptions')->__('Export Magento Subscribers'),
|
30 |
+
'title' => Mage::helper('subscriptions')->__('Export Magento Subscribers'),
|
31 |
+
'content' => $this->getLayout()->createBlock('subscriptions/adminhtml_subscriptions_edit_tab_export')->toHtml(),
|
32 |
+
));
|
33 |
+
|
34 |
+
return parent::_beforeToHtml();
|
35 |
+
}
|
36 |
+
}
|
app/code/local/ActiveCampaign/Subscriptions/Block/Adminhtml/Subscriptions/Grid.php
ADDED
@@ -0,0 +1,162 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class ActiveCampaign_Subscriptions_Block_Adminhtml_Subscriptions_Grid extends Mage_Adminhtml_Block_Widget_Grid
|
4 |
+
{
|
5 |
+
public function __construct()
|
6 |
+
{
|
7 |
+
parent::__construct();
|
8 |
+
$this->setId('subscriptionsGrid');
|
9 |
+
//$this->setDefaultSort('status');
|
10 |
+
//$this->setDefaultDir('ASC');
|
11 |
+
//$this->setSaveParametersInSession(true);
|
12 |
+
}
|
13 |
+
|
14 |
+
protected function dbg($var, $continue = 0, $element = "pre")
|
15 |
+
{
|
16 |
+
echo "<" . $element . ">";
|
17 |
+
echo "Vartype: " . gettype($var) . "\n";
|
18 |
+
if ( is_array($var) )
|
19 |
+
{
|
20 |
+
echo "Elements: " . count($var) . "\n\n";
|
21 |
+
}
|
22 |
+
elseif ( is_string($var) )
|
23 |
+
{
|
24 |
+
echo "Length: " . strlen($var) . "\n\n";
|
25 |
+
}
|
26 |
+
print_r($var);
|
27 |
+
echo "</" . $element . ">";
|
28 |
+
if (!$continue) exit();
|
29 |
+
}
|
30 |
+
|
31 |
+
protected function _prepareCollection()
|
32 |
+
{
|
33 |
+
$collection = Mage::getModel('subscriptions/subscriptions')->getCollection();
|
34 |
+
$this->setCollection($collection);
|
35 |
+
return parent::_prepareCollection();
|
36 |
+
}
|
37 |
+
|
38 |
+
protected function _prepareColumns()
|
39 |
+
{
|
40 |
+
/*
|
41 |
+
$this->addColumn('subscriptions_id', array(
|
42 |
+
'header' => Mage::helper('subscriptions')->__('ID'),
|
43 |
+
'align' =>'right',
|
44 |
+
'width' => '50px',
|
45 |
+
'index' => 'subscriptions_id',
|
46 |
+
));
|
47 |
+
*/
|
48 |
+
|
49 |
+
$this->addColumn('title', array(
|
50 |
+
'header' => Mage::helper('subscriptions')->__('Title'),
|
51 |
+
'align' =>'left',
|
52 |
+
'width' => '250px',
|
53 |
+
'index' => 'title',
|
54 |
+
));
|
55 |
+
|
56 |
+
/*
|
57 |
+
$this->addColumn('content', array(
|
58 |
+
'header' => Mage::helper('subscriptions')->__('Item Content'),
|
59 |
+
'width' => '150px',
|
60 |
+
'index' => 'content',
|
61 |
+
));
|
62 |
+
*/
|
63 |
+
|
64 |
+
$collection_data = Mage::getModel('subscriptions/subscriptions')->getCollection()->getData();
|
65 |
+
|
66 |
+
$lists_ = array();
|
67 |
+
foreach ($collection_data as $connection) {
|
68 |
+
$lists = json_decode($connection["lists"]);
|
69 |
+
//$this->dbg($lists);
|
70 |
+
if ($lists) {
|
71 |
+
foreach ($lists as $list) {
|
72 |
+
$list = get_object_vars($list);
|
73 |
+
if (!preg_match("/0$/", $list["value"])) {
|
74 |
+
$lists_[ $list["value"] ] = $list["label"];
|
75 |
+
}
|
76 |
+
}
|
77 |
+
}
|
78 |
+
}
|
79 |
+
//$this->dbg($lists_);
|
80 |
+
|
81 |
+
$this->addColumn('list_value', array(
|
82 |
+
'header' => Mage::helper('subscriptions')->__('Lists'),
|
83 |
+
'align' => 'left',
|
84 |
+
'width' => '300px',
|
85 |
+
'index' => 'list_value',
|
86 |
+
'type' => 'options',
|
87 |
+
'options' => $lists_,
|
88 |
+
));
|
89 |
+
|
90 |
+
$this->addColumn('status', array(
|
91 |
+
'header' => Mage::helper('subscriptions')->__('Status'),
|
92 |
+
'align' => 'left',
|
93 |
+
'width' => '80px',
|
94 |
+
'index' => 'status',
|
95 |
+
'type' => 'options',
|
96 |
+
'options' => array(
|
97 |
+
1 => 'Enabled',
|
98 |
+
2 => 'Disabled',
|
99 |
+
),
|
100 |
+
));
|
101 |
+
|
102 |
+
$this->addColumn('action',
|
103 |
+
array(
|
104 |
+
'header' => Mage::helper('subscriptions')->__('Action'),
|
105 |
+
'width' => '100',
|
106 |
+
'type' => 'action',
|
107 |
+
'getter' => 'getId',
|
108 |
+
'actions' => array(
|
109 |
+
array(
|
110 |
+
'caption' => Mage::helper('subscriptions')->__('Edit'),
|
111 |
+
'url' => array('base'=> '*/*/edit'),
|
112 |
+
'field' => 'id'
|
113 |
+
)
|
114 |
+
),
|
115 |
+
'filter' => false,
|
116 |
+
'sortable' => false,
|
117 |
+
'index' => 'stores',
|
118 |
+
'is_system' => true,
|
119 |
+
));
|
120 |
+
|
121 |
+
$this->addExportType('*/*/exportCsv', Mage::helper('subscriptions')->__('CSV'));
|
122 |
+
$this->addExportType('*/*/exportXml', Mage::helper('subscriptions')->__('XML'));
|
123 |
+
|
124 |
+
return parent::_prepareColumns();
|
125 |
+
}
|
126 |
+
|
127 |
+
protected function _prepareMassaction()
|
128 |
+
{
|
129 |
+
$this->setMassactionIdField('subscriptions_id');
|
130 |
+
$this->getMassactionBlock()->setFormFieldName('subscriptions');
|
131 |
+
|
132 |
+
$this->getMassactionBlock()->addItem('delete', array(
|
133 |
+
'label' => Mage::helper('subscriptions')->__('Delete'),
|
134 |
+
'url' => $this->getUrl('*/*/massDelete'),
|
135 |
+
'confirm' => Mage::helper('subscriptions')->__('Are you sure?')
|
136 |
+
));
|
137 |
+
|
138 |
+
$statuses = Mage::getSingleton('subscriptions/status')->getOptionArray();
|
139 |
+
|
140 |
+
array_unshift($statuses, array('label'=>'', 'value'=>''));
|
141 |
+
$this->getMassactionBlock()->addItem('status', array(
|
142 |
+
'label'=> Mage::helper('subscriptions')->__('Change status'),
|
143 |
+
'url' => $this->getUrl('*/*/massStatus', array('_current'=>true)),
|
144 |
+
'additional' => array(
|
145 |
+
'visibility' => array(
|
146 |
+
'name' => 'status',
|
147 |
+
'type' => 'select',
|
148 |
+
'class' => 'required-entry',
|
149 |
+
'label' => Mage::helper('subscriptions')->__('Status'),
|
150 |
+
'values' => $statuses
|
151 |
+
)
|
152 |
+
)
|
153 |
+
));
|
154 |
+
return $this;
|
155 |
+
}
|
156 |
+
|
157 |
+
public function getRowUrl($row)
|
158 |
+
{
|
159 |
+
return $this->getUrl('*/*/edit', array('id' => $row->getId()));
|
160 |
+
}
|
161 |
+
|
162 |
+
}
|
app/code/local/ActiveCampaign/Subscriptions/Block/Subscriptions.php
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
define("ACTIVECAMPAIGN_URL", "");
|
4 |
+
define("ACTIVECAMPAIGN_API_KEY", "");
|
5 |
+
require_once(Mage::getBaseDir() . "/app/code/local/ActiveCampaign/Subscriptions/activecampaign-api-php/ActiveCampaign.class.php");
|
6 |
+
|
7 |
+
class ActiveCampaign_Subscriptions_Block_Subscriptions extends Mage_Core_Block_Template
|
8 |
+
{
|
9 |
+
public function _prepareLayout()
|
10 |
+
{
|
11 |
+
return parent::_prepareLayout();
|
12 |
+
}
|
13 |
+
|
14 |
+
public function getSubscriptions()
|
15 |
+
{
|
16 |
+
if (!$this->hasData('subscriptions')) {
|
17 |
+
$this->setData('subscriptions', Mage::registry('subscriptions'));
|
18 |
+
}
|
19 |
+
return $this->getData('subscriptions');
|
20 |
+
|
21 |
+
}
|
22 |
+
}
|
app/code/local/ActiveCampaign/Subscriptions/Helper/Data.php
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class ActiveCampaign_Subscriptions_Helper_Data extends Mage_Core_Helper_Abstract
|
4 |
+
{
|
5 |
+
|
6 |
+
}
|
app/code/local/ActiveCampaign/Subscriptions/Model/Mysql4/Subscriptions.php
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class ActiveCampaign_Subscriptions_Model_Mysql4_Subscriptions extends Mage_Core_Model_Mysql4_Abstract
|
4 |
+
{
|
5 |
+
public function _construct()
|
6 |
+
{
|
7 |
+
// Note that the subscriptions_id refers to the key field in your database table.
|
8 |
+
$this->_init('subscriptions/subscriptions', 'subscriptions_id');
|
9 |
+
}
|
10 |
+
}
|
app/code/local/ActiveCampaign/Subscriptions/Model/Mysql4/Subscriptions/Collection.php
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class ActiveCampaign_Subscriptions_Model_Mysql4_Subscriptions_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
|
4 |
+
{
|
5 |
+
public function _construct()
|
6 |
+
{
|
7 |
+
parent::_construct();
|
8 |
+
$this->_init('subscriptions/subscriptions');
|
9 |
+
}
|
10 |
+
}
|
app/code/local/ActiveCampaign/Subscriptions/Model/Observer.php
ADDED
@@ -0,0 +1,178 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
// public side stuff - happens when registering or modifying account
|
4 |
+
|
5 |
+
define("ACTIVECAMPAIGN_URL", "");
|
6 |
+
define("ACTIVECAMPAIGN_API_KEY", "");
|
7 |
+
require_once(Mage::getBaseDir() . "/app/code/local/ActiveCampaign/Subscriptions/activecampaign-api-php/ActiveCampaign.class.php");
|
8 |
+
|
9 |
+
class ActiveCampaign_Subscriptions_Model_Observer {
|
10 |
+
|
11 |
+
protected function dbg($var, $continue = 0, $element = "pre")
|
12 |
+
{
|
13 |
+
echo "<" . $element . ">";
|
14 |
+
echo "Vartype: " . gettype($var) . "\n";
|
15 |
+
if ( is_array($var) )
|
16 |
+
{
|
17 |
+
echo "Elements: " . count($var) . "\n\n";
|
18 |
+
}
|
19 |
+
elseif ( is_string($var) )
|
20 |
+
{
|
21 |
+
echo "Length: " . strlen($var) . "\n\n";
|
22 |
+
}
|
23 |
+
print_r($var);
|
24 |
+
echo "</" . $element . ">";
|
25 |
+
if (!$continue) exit();
|
26 |
+
}
|
27 |
+
|
28 |
+
public function connection_data() {
|
29 |
+
// get saved API connections
|
30 |
+
$collection = Mage::getModel("subscriptions/subscriptions")->getCollection();
|
31 |
+
$connection_data = $collection->getData();
|
32 |
+
//$this->dbg($collection_data);
|
33 |
+
|
34 |
+
$api_url = $api_key = $list_value = "";
|
35 |
+
$list_ids = array();
|
36 |
+
|
37 |
+
foreach ($connection_data as $connection) {
|
38 |
+
if ((int)$connection["status"] == 1) {
|
39 |
+
// find first one that is enabled
|
40 |
+
$api_url = $connection["api_url"];
|
41 |
+
$api_key = $connection["api_key"];
|
42 |
+
$list_value = $connection["list_value"];
|
43 |
+
if ($list_value) {
|
44 |
+
// example for single list saved: ["mthommes6.activehosted.com-13"]
|
45 |
+
// example for multiple lists saved: ["mthommes6.activehosted.com-5","mthommes6.activehosted.com-13"]
|
46 |
+
$list_values = json_decode($list_value);
|
47 |
+
foreach ($list_values as $acct_listid) {
|
48 |
+
// IE: mthommes6.activehosted.com-13
|
49 |
+
$acct_listid = explode("-", $acct_listid);
|
50 |
+
$list_ids[] = (int)$acct_listid[1];
|
51 |
+
}
|
52 |
+
}
|
53 |
+
break;
|
54 |
+
}
|
55 |
+
}
|
56 |
+
|
57 |
+
return array(
|
58 |
+
"data" => $connection_data,
|
59 |
+
"api_url" => $api_url,
|
60 |
+
"api_key" => $api_key,
|
61 |
+
"list_ids" => $list_ids,
|
62 |
+
);
|
63 |
+
}
|
64 |
+
|
65 |
+
public function register_subscribe(Varien_Event_Observer $observer) {
|
66 |
+
|
67 |
+
// called when they initially register as a new customer
|
68 |
+
|
69 |
+
$customer = $observer->getCustomer();
|
70 |
+
$customer_data = $customer->getData();
|
71 |
+
//$this->dbg($customer_data);
|
72 |
+
|
73 |
+
if (isset($customer_data["is_subscribed"]) && (int)$customer_data["is_subscribed"]) {
|
74 |
+
|
75 |
+
$connection = $this->connection_data();
|
76 |
+
|
77 |
+
$customer_first_name = $customer_data["firstname"];
|
78 |
+
$customer_last_name = $customer_data["lastname"];
|
79 |
+
$customer_email = $customer_data["email"];
|
80 |
+
$group_id = $customer_data["group_id"];
|
81 |
+
$store_id = $customer_data["store_id"];
|
82 |
+
|
83 |
+
if ($connection["api_url"] && $connection["api_key"] && $connection["list_ids"]) {
|
84 |
+
|
85 |
+
$ac = new ActiveCampaign($connection["api_url"], $connection["api_key"]);
|
86 |
+
$test_connection = $ac->credentials_test();
|
87 |
+
|
88 |
+
if ($test_connection) {
|
89 |
+
|
90 |
+
$subscriber = array(
|
91 |
+
"email" => $customer_email,
|
92 |
+
"first_name" => $customer_first_name,
|
93 |
+
"last_name" => $customer_last_name,
|
94 |
+
);
|
95 |
+
|
96 |
+
// add lists
|
97 |
+
foreach ($connection["list_ids"] as $list_id) {
|
98 |
+
$subscriber["p[{$list_id}]"] = $list_id;
|
99 |
+
$subscriber["status[{$list_id}]"] = 1;
|
100 |
+
}
|
101 |
+
|
102 |
+
$subscriber_request = $ac->api("subscriber/sync?service=magento", $subscriber);
|
103 |
+
|
104 |
+
if ((int)$subscriber_request->success) {
|
105 |
+
// successful request
|
106 |
+
//$subscriber_id = (int)$subscriber_request->subscriber_id;
|
107 |
+
}
|
108 |
+
else {
|
109 |
+
// request failed
|
110 |
+
//print_r($subscriber_request->error);
|
111 |
+
//exit();
|
112 |
+
}
|
113 |
+
}
|
114 |
+
}
|
115 |
+
|
116 |
+
}
|
117 |
+
|
118 |
+
}
|
119 |
+
|
120 |
+
public function edit_subscribe(Varien_Event_Observer $observer) {
|
121 |
+
|
122 |
+
// called when they update their profile (already registered as a customer)
|
123 |
+
|
124 |
+
$customer = $observer->getCustomer();
|
125 |
+
$customer_data = $customer->getData();
|
126 |
+
//$this->dbg($customer_data);
|
127 |
+
|
128 |
+
$is_subscribed = (int)$customer_data["is_subscribed"];
|
129 |
+
$list_status = ($is_subscribed) ? 1 : 2;
|
130 |
+
|
131 |
+
$connection = $this->connection_data();
|
132 |
+
|
133 |
+
$customer_first_name = $customer_data["firstname"];
|
134 |
+
$customer_last_name = $customer_data["lastname"];
|
135 |
+
$customer_email = $customer_data["email"];
|
136 |
+
$group_id = $customer_data["group_id"];
|
137 |
+
$store_id = $customer_data["store_id"];
|
138 |
+
|
139 |
+
if ($connection["api_url"] && $connection["api_key"] && $connection["list_ids"]) {
|
140 |
+
|
141 |
+
$ac = new ActiveCampaign($connection["api_url"], $connection["api_key"]);
|
142 |
+
$test_connection = $ac->credentials_test();
|
143 |
+
|
144 |
+
if ($test_connection) {
|
145 |
+
|
146 |
+
$subscriber = array(
|
147 |
+
"email" => $customer_email,
|
148 |
+
"first_name" => $customer_first_name,
|
149 |
+
"last_name" => $customer_last_name,
|
150 |
+
);
|
151 |
+
|
152 |
+
// add lists
|
153 |
+
foreach ($connection["list_ids"] as $list_id) {
|
154 |
+
$subscriber["p[{$list_id}]"] = $list_id;
|
155 |
+
$subscriber["status[{$list_id}]"] = $list_status;
|
156 |
+
}
|
157 |
+
|
158 |
+
$subscriber_request = $ac->api("subscriber/sync?service=magento", $subscriber);
|
159 |
+
|
160 |
+
if ((int)$subscriber_request->success) {
|
161 |
+
// successful request
|
162 |
+
//$subscriber_id = (int)$subscriber_request->subscriber_id;
|
163 |
+
}
|
164 |
+
else {
|
165 |
+
// request failed
|
166 |
+
//print_r($subscriber_request->error);
|
167 |
+
//exit();
|
168 |
+
}
|
169 |
+
|
170 |
+
}
|
171 |
+
|
172 |
+
}
|
173 |
+
|
174 |
+
}
|
175 |
+
|
176 |
+
}
|
177 |
+
|
178 |
+
?>
|
app/code/local/ActiveCampaign/Subscriptions/Model/Status.php
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class ActiveCampaign_Subscriptions_Model_Status extends Varien_Object
|
4 |
+
{
|
5 |
+
const STATUS_ENABLED = 1;
|
6 |
+
const STATUS_DISABLED = 2;
|
7 |
+
|
8 |
+
static public function getOptionArray()
|
9 |
+
{
|
10 |
+
return array(
|
11 |
+
self::STATUS_ENABLED => Mage::helper('subscriptions')->__('Enabled'),
|
12 |
+
self::STATUS_DISABLED => Mage::helper('subscriptions')->__('Disabled')
|
13 |
+
);
|
14 |
+
}
|
15 |
+
}
|
app/code/local/ActiveCampaign/Subscriptions/Model/Subscriptions.php
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class ActiveCampaign_Subscriptions_Model_Subscriptions extends Mage_Core_Model_Abstract
|
4 |
+
{
|
5 |
+
public function _construct()
|
6 |
+
{
|
7 |
+
parent::_construct();
|
8 |
+
$this->_init('subscriptions/subscriptions');
|
9 |
+
}
|
10 |
+
}
|
app/code/local/ActiveCampaign/Subscriptions/controllers/Adminhtml/SubscriptionsController.php
ADDED
@@ -0,0 +1,333 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
define("ACTIVECAMPAIGN_URL", "");
|
4 |
+
define("ACTIVECAMPAIGN_API_KEY", "");
|
5 |
+
require_once(Mage::getBaseDir() . "/app/code/local/ActiveCampaign/Subscriptions/activecampaign-api-php/ActiveCampaign.class.php");
|
6 |
+
|
7 |
+
class ActiveCampaign_Subscriptions_Adminhtml_SubscriptionsController extends Mage_Adminhtml_Controller_action
|
8 |
+
{
|
9 |
+
|
10 |
+
protected function _initAction() {
|
11 |
+
$this->loadLayout()
|
12 |
+
->_setActiveMenu('subscriptions/items')
|
13 |
+
->_addBreadcrumb(Mage::helper('adminhtml')->__('Connections Manager'), Mage::helper('adminhtml')->__('Connection Manager'));
|
14 |
+
|
15 |
+
return $this;
|
16 |
+
}
|
17 |
+
|
18 |
+
protected function dbg($var, $continue = 0, $element = "pre")
|
19 |
+
{
|
20 |
+
echo "<" . $element . ">";
|
21 |
+
echo "Vartype: " . gettype($var) . "\n";
|
22 |
+
if ( is_array($var) )
|
23 |
+
{
|
24 |
+
echo "Elements: " . count($var) . "\n\n";
|
25 |
+
}
|
26 |
+
elseif ( is_string($var) )
|
27 |
+
{
|
28 |
+
echo "Length: " . strlen($var) . "\n\n";
|
29 |
+
}
|
30 |
+
print_r($var);
|
31 |
+
echo "</" . $element . ">";
|
32 |
+
if (!$continue) exit();
|
33 |
+
}
|
34 |
+
|
35 |
+
public function indexAction() {
|
36 |
+
$this->_initAction()
|
37 |
+
->renderLayout();
|
38 |
+
}
|
39 |
+
|
40 |
+
public function editAction() {
|
41 |
+
$id = $this->getRequest()->getParam('id');
|
42 |
+
$model = Mage::getModel('subscriptions/subscriptions')->load($id);
|
43 |
+
|
44 |
+
if ($model->getId() || $id == 0) {
|
45 |
+
$data = Mage::getSingleton('adminhtml/session')->getFormData(true);
|
46 |
+
|
47 |
+
if (!empty($data)) {
|
48 |
+
$model->setData($data);
|
49 |
+
}
|
50 |
+
|
51 |
+
Mage::register('subscriptions_data', $model);
|
52 |
+
|
53 |
+
$this->loadLayout();
|
54 |
+
$this->_setActiveMenu('subscriptions/items');
|
55 |
+
|
56 |
+
//$this->_addBreadcrumb(Mage::helper('adminhtml')->__('Connection Manager'), Mage::helper('adminhtml')->__('Connection Manager'));
|
57 |
+
//$this->_addBreadcrumb(Mage::helper('adminhtml')->__('Item News'), Mage::helper('adminhtml')->__('Item News'));
|
58 |
+
|
59 |
+
$this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
|
60 |
+
|
61 |
+
$this->_addContent($this->getLayout()->createBlock('subscriptions/adminhtml_subscriptions_edit'))
|
62 |
+
->_addLeft($this->getLayout()->createBlock('subscriptions/adminhtml_subscriptions_edit_tabs'));
|
63 |
+
|
64 |
+
$this->renderLayout();
|
65 |
+
} else {
|
66 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('subscriptions')->__('Item does not exist'));
|
67 |
+
$this->_redirect('*/*/');
|
68 |
+
}
|
69 |
+
}
|
70 |
+
|
71 |
+
public function newAction() {
|
72 |
+
$this->_forward('edit');
|
73 |
+
}
|
74 |
+
|
75 |
+
public function saveAction() {
|
76 |
+
|
77 |
+
if ($data = $this->getRequest()->getPost()) {
|
78 |
+
|
79 |
+
//$this->dbg($data);
|
80 |
+
|
81 |
+
/*
|
82 |
+
if (isset($_FILES['filename']['name']) && $_FILES['filename']['name'] != '') {
|
83 |
+
try {
|
84 |
+
// Starting upload
|
85 |
+
$uploader = new Varien_File_Uploader('filename');
|
86 |
+
|
87 |
+
// Any extention would work
|
88 |
+
$uploader->setAllowedExtensions(array('jpg','jpeg','gif','png'));
|
89 |
+
$uploader->setAllowRenameFiles(false);
|
90 |
+
|
91 |
+
// Set the file upload mode
|
92 |
+
// false -> get the file directly in the specified folder
|
93 |
+
// true -> get the file in the product like folders
|
94 |
+
// (file.jpg will go in something like /media/f/i/file.jpg)
|
95 |
+
$uploader->setFilesDispersion(false);
|
96 |
+
|
97 |
+
// We set media as the upload dir
|
98 |
+
$path = Mage::getBaseDir('media') . DS ;
|
99 |
+
$uploader->save($path, $_FILES['filename']['name'] );
|
100 |
+
|
101 |
+
} catch (Exception $e) {
|
102 |
+
|
103 |
+
}
|
104 |
+
|
105 |
+
//this way the name is saved in DB
|
106 |
+
$data['filename'] = $_FILES['filename']['name'];
|
107 |
+
}
|
108 |
+
*/
|
109 |
+
|
110 |
+
$model = Mage::getModel('subscriptions/subscriptions');
|
111 |
+
|
112 |
+
$api_url = $data["api_url"];
|
113 |
+
$api_key = $data["api_key"];
|
114 |
+
|
115 |
+
$ac = new ActiveCampaign($api_url, $api_key);
|
116 |
+
|
117 |
+
$test_connection = $ac->credentials_test();
|
118 |
+
|
119 |
+
if (!$test_connection) {
|
120 |
+
Mage::getSingleton("adminhtml/session")->addError("Invalid API URL or Key. Please check to make sure both values are correct.");
|
121 |
+
Mage::getSingleton('adminhtml/session')->setFormData($data);
|
122 |
+
$this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
|
123 |
+
return;
|
124 |
+
}
|
125 |
+
else {
|
126 |
+
// get AC account details
|
127 |
+
$account = $ac->api("account/view");
|
128 |
+
$data["account_url"] = $account->account;
|
129 |
+
|
130 |
+
//$data["cdate"] = "NOW()";
|
131 |
+
|
132 |
+
$list_values = $data["list_value"];
|
133 |
+
$list_ids = array();
|
134 |
+
|
135 |
+
// example (converts to): ["mthommes6.activehosted.com-5","mthommes6.activehosted.com-13"]
|
136 |
+
$data["list_value"] = json_encode($data["list_value"]);
|
137 |
+
|
138 |
+
//$this->dbg($data);
|
139 |
+
|
140 |
+
$model->setData($data)->setId($this->getRequest()->getParam('id'));
|
141 |
+
|
142 |
+
if (isset($data["export_confirm"]) && (int)$data["export_confirm"]) {
|
143 |
+
|
144 |
+
// exporting Newsletter subscribers to ActiveCampaign
|
145 |
+
|
146 |
+
$subscribers_magento = Mage::getResourceModel('newsletter/subscriber_collection')->showStoreInfo()->showCustomerInfo()->getData();
|
147 |
+
//$this->dbg($subscribers_magento);
|
148 |
+
|
149 |
+
$subscribers_ac = array();
|
150 |
+
|
151 |
+
foreach ($list_values as $acct_listid) {
|
152 |
+
// IE: mthommes6.activehosted.com-13
|
153 |
+
$acct_listid = explode("-", $acct_listid);
|
154 |
+
$list_ids[] = (int)$acct_listid[1];
|
155 |
+
}
|
156 |
+
|
157 |
+
foreach ($subscribers_magento as $subscriber) {
|
158 |
+
|
159 |
+
$subscribers_ac_ = array(
|
160 |
+
"email" => $subscriber["subscriber_email"],
|
161 |
+
"first_name" => $subscriber["customer_firstname"],
|
162 |
+
"last_name" => $subscriber["customer_lastname"],
|
163 |
+
);
|
164 |
+
|
165 |
+
// add lists
|
166 |
+
$p = array();
|
167 |
+
$status = array();
|
168 |
+
foreach ($list_ids as $list_id) {
|
169 |
+
$p[$list_id] = $list_id;
|
170 |
+
$status[$list_id] = 1;
|
171 |
+
}
|
172 |
+
|
173 |
+
$subscribers_ac_["p"] = $p;
|
174 |
+
$subscribers_ac_["status"] = $status;
|
175 |
+
|
176 |
+
//$this->dbg($subscribers_ac_);
|
177 |
+
|
178 |
+
$subscribers_ac[] = $subscribers_ac_;
|
179 |
+
|
180 |
+
}
|
181 |
+
|
182 |
+
//$this->dbg($subscribers_ac);
|
183 |
+
|
184 |
+
$subscribers_ac_serialized = serialize($subscribers_ac);
|
185 |
+
//$this->dbg($subscribers_ac_serialized);
|
186 |
+
|
187 |
+
$subscriber_request = $ac->api("subscriber/sync?service=magento", $subscribers_ac_serialized);
|
188 |
+
//$this->dbg($subscriber_request);
|
189 |
+
|
190 |
+
if ((int)$subscriber_request->success) {
|
191 |
+
// successful request
|
192 |
+
//$subscriber_id = (int)$subscriber_request->subscriber_id;
|
193 |
+
}
|
194 |
+
else {
|
195 |
+
// request failed
|
196 |
+
//print_r($subscriber_request->error);
|
197 |
+
//exit();
|
198 |
+
}
|
199 |
+
|
200 |
+
}
|
201 |
+
|
202 |
+
try {
|
203 |
+
if ($model->getCreatedTime == NULL || $model->getUpdateTime() == NULL) {
|
204 |
+
$model->setCreatedTime(now())
|
205 |
+
->setUpdateTime(now());
|
206 |
+
} else {
|
207 |
+
$model->setUpdateTime(now());
|
208 |
+
}
|
209 |
+
|
210 |
+
$model->save();
|
211 |
+
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('subscriptions')->__('Settings were successfully saved'));
|
212 |
+
Mage::getSingleton('adminhtml/session')->setFormData(false);
|
213 |
+
|
214 |
+
if ($this->getRequest()->getParam('back')) {
|
215 |
+
$this->_redirect('*/*/edit', array('id' => $model->getId()));
|
216 |
+
return;
|
217 |
+
}
|
218 |
+
$this->_redirect('*/*/');
|
219 |
+
return;
|
220 |
+
}
|
221 |
+
catch (Exception $e) {
|
222 |
+
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
|
223 |
+
Mage::getSingleton('adminhtml/session')->setFormData($data);
|
224 |
+
$this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
|
225 |
+
return;
|
226 |
+
}
|
227 |
+
|
228 |
+
}
|
229 |
+
|
230 |
+
}
|
231 |
+
|
232 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('subscriptions')->__('Unable to find item to save'));
|
233 |
+
$this->_redirect('*/*/');
|
234 |
+
}
|
235 |
+
|
236 |
+
public function deleteAction() {
|
237 |
+
if( $this->getRequest()->getParam('id') > 0 ) {
|
238 |
+
try {
|
239 |
+
$model = Mage::getModel('subscriptions/subscriptions');
|
240 |
+
|
241 |
+
$model->setId($this->getRequest()->getParam('id'))
|
242 |
+
->delete();
|
243 |
+
|
244 |
+
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Item was successfully deleted'));
|
245 |
+
$this->_redirect('*/*/');
|
246 |
+
} catch (Exception $e) {
|
247 |
+
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
|
248 |
+
$this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
|
249 |
+
}
|
250 |
+
}
|
251 |
+
$this->_redirect('*/*/');
|
252 |
+
}
|
253 |
+
|
254 |
+
public function massDeleteAction() {
|
255 |
+
$subscriptionsIds = $this->getRequest()->getParam('subscriptions');
|
256 |
+
if(!is_array($subscriptionsIds)) {
|
257 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Please select item(s)'));
|
258 |
+
} else {
|
259 |
+
try {
|
260 |
+
foreach ($subscriptionsIds as $subscriptionsId) {
|
261 |
+
$subscriptions = Mage::getModel('subscriptions/subscriptions')->load($subscriptionsId);
|
262 |
+
$subscriptions->delete();
|
263 |
+
}
|
264 |
+
Mage::getSingleton('adminhtml/session')->addSuccess(
|
265 |
+
Mage::helper('adminhtml')->__(
|
266 |
+
'Total of %d record(s) were successfully deleted', count($subscriptionsIds)
|
267 |
+
)
|
268 |
+
);
|
269 |
+
} catch (Exception $e) {
|
270 |
+
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
|
271 |
+
}
|
272 |
+
}
|
273 |
+
$this->_redirect('*/*/index');
|
274 |
+
}
|
275 |
+
|
276 |
+
public function massStatusAction()
|
277 |
+
{
|
278 |
+
$subscriptionsIds = $this->getRequest()->getParam('subscriptions');
|
279 |
+
if(!is_array($subscriptionsIds)) {
|
280 |
+
Mage::getSingleton('adminhtml/session')->addError($this->__('Please select item(s)'));
|
281 |
+
} else {
|
282 |
+
try {
|
283 |
+
foreach ($subscriptionsIds as $subscriptionsId) {
|
284 |
+
$subscriptions = Mage::getSingleton('subscriptions/subscriptions')
|
285 |
+
->load($subscriptionsId)
|
286 |
+
->setStatus($this->getRequest()->getParam('status'))
|
287 |
+
->setIsMassupdate(true)
|
288 |
+
->save();
|
289 |
+
}
|
290 |
+
$this->_getSession()->addSuccess(
|
291 |
+
$this->__('Total of %d record(s) were successfully updated', count($subscriptionsIds))
|
292 |
+
);
|
293 |
+
} catch (Exception $e) {
|
294 |
+
$this->_getSession()->addError($e->getMessage());
|
295 |
+
}
|
296 |
+
}
|
297 |
+
$this->_redirect('*/*/index');
|
298 |
+
}
|
299 |
+
|
300 |
+
public function exportCsvAction()
|
301 |
+
{
|
302 |
+
$fileName = 'subscriptions.csv';
|
303 |
+
$content = $this->getLayout()->createBlock('subscriptions/adminhtml_subscriptions_grid')
|
304 |
+
->getCsv();
|
305 |
+
|
306 |
+
$this->_sendUploadResponse($fileName, $content);
|
307 |
+
}
|
308 |
+
|
309 |
+
public function exportXmlAction()
|
310 |
+
{
|
311 |
+
$fileName = 'subscriptions.xml';
|
312 |
+
$content = $this->getLayout()->createBlock('subscriptions/adminhtml_subscriptions_grid')
|
313 |
+
->getXml();
|
314 |
+
|
315 |
+
$this->_sendUploadResponse($fileName, $content);
|
316 |
+
}
|
317 |
+
|
318 |
+
protected function _sendUploadResponse($fileName, $content, $contentType='application/octet-stream')
|
319 |
+
{
|
320 |
+
$response = $this->getResponse();
|
321 |
+
$response->setHeader('HTTP/1.1 200 OK','');
|
322 |
+
$response->setHeader('Pragma', 'public', true);
|
323 |
+
$response->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true);
|
324 |
+
$response->setHeader('Content-Disposition', 'attachment; filename='.$fileName);
|
325 |
+
$response->setHeader('Last-Modified', date('r'));
|
326 |
+
$response->setHeader('Accept-Ranges', 'bytes');
|
327 |
+
$response->setHeader('Content-Length', strlen($content));
|
328 |
+
$response->setHeader('Content-type', $contentType);
|
329 |
+
$response->setBody($content);
|
330 |
+
$response->sendResponse();
|
331 |
+
die;
|
332 |
+
}
|
333 |
+
}
|
app/code/local/ActiveCampaign/Subscriptions/controllers/IndexController.php
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class ActiveCampaign_Subscriptions_IndexController extends Mage_Core_Controller_Front_Action
|
3 |
+
{
|
4 |
+
public function indexAction()
|
5 |
+
{
|
6 |
+
|
7 |
+
/*
|
8 |
+
* Load an object by id
|
9 |
+
* Request looking like:
|
10 |
+
* http://site.com/subscriptions?id=15
|
11 |
+
* or
|
12 |
+
* http://site.com/subscriptions/id/15
|
13 |
+
*/
|
14 |
+
/*
|
15 |
+
$subscriptions_id = $this->getRequest()->getParam('id');
|
16 |
+
|
17 |
+
if($subscriptions_id != null && $subscriptions_id != '') {
|
18 |
+
$subscriptions = Mage::getModel('subscriptions/subscriptions')->load($subscriptions_id)->getData();
|
19 |
+
} else {
|
20 |
+
$subscriptions = null;
|
21 |
+
}
|
22 |
+
*/
|
23 |
+
|
24 |
+
/*
|
25 |
+
* If no param we load a the last created item
|
26 |
+
*/
|
27 |
+
/*
|
28 |
+
if($subscriptions == null) {
|
29 |
+
$resource = Mage::getSingleton('core/resource');
|
30 |
+
$read= $resource->getConnection('core_read');
|
31 |
+
$subscriptionsTable = $resource->getTableName('subscriptions');
|
32 |
+
|
33 |
+
$select = $read->select()
|
34 |
+
->from($subscriptionsTable,array('subscriptions_id','title','content','status'))
|
35 |
+
->where('status',1)
|
36 |
+
->order('created_time DESC') ;
|
37 |
+
|
38 |
+
$subscriptions = $read->fetchRow($select);
|
39 |
+
}
|
40 |
+
Mage::register('subscriptions', $subscriptions);
|
41 |
+
*/
|
42 |
+
|
43 |
+
|
44 |
+
$this->loadLayout();
|
45 |
+
$this->renderLayout();
|
46 |
+
}
|
47 |
+
}
|
app/code/local/ActiveCampaign/Subscriptions/etc/config.xml
ADDED
@@ -0,0 +1,156 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<!--
|
3 |
+
/**
|
4 |
+
* @category ActiveCampaign
|
5 |
+
* @package ActiveCampaign_Subscriptions
|
6 |
+
* @author ActiveCampaign
|
7 |
+
* @license https://www.activecampaign.com/hosted/terms.php
|
8 |
+
*/
|
9 |
+
-->
|
10 |
+
<config>
|
11 |
+
<modules>
|
12 |
+
<ActiveCampaign_Subscriptions>
|
13 |
+
<version>1.0.0</version>
|
14 |
+
</ActiveCampaign_Subscriptions>
|
15 |
+
</modules>
|
16 |
+
<frontend>
|
17 |
+
<routers>
|
18 |
+
<subscriptions>
|
19 |
+
<use>standard</use>
|
20 |
+
<args>
|
21 |
+
<module>ActiveCampaign_Subscriptions</module>
|
22 |
+
<frontName>subscriptions</frontName>
|
23 |
+
</args>
|
24 |
+
</subscriptions>
|
25 |
+
</routers>
|
26 |
+
<layout>
|
27 |
+
<updates>
|
28 |
+
<subscriptions>
|
29 |
+
<file>subscriptions.xml</file>
|
30 |
+
</subscriptions>
|
31 |
+
</updates>
|
32 |
+
</layout>
|
33 |
+
</frontend>
|
34 |
+
<admin>
|
35 |
+
<routers>
|
36 |
+
<subscriptions>
|
37 |
+
<use>admin</use>
|
38 |
+
<args>
|
39 |
+
<module>ActiveCampaign_Subscriptions</module>
|
40 |
+
<frontName>subscriptions</frontName>
|
41 |
+
</args>
|
42 |
+
</subscriptions>
|
43 |
+
</routers>
|
44 |
+
</admin>
|
45 |
+
<adminhtml>
|
46 |
+
<menu>
|
47 |
+
<subscriptions module="subscriptions">
|
48 |
+
<title>ActiveCampaign</title>
|
49 |
+
<sort_order>71</sort_order>
|
50 |
+
<children>
|
51 |
+
<items module="subscriptions">
|
52 |
+
<title>Settings</title>
|
53 |
+
<sort_order>0</sort_order>
|
54 |
+
<action>subscriptions/adminhtml_subscriptions</action>
|
55 |
+
</items>
|
56 |
+
</children>
|
57 |
+
</subscriptions>
|
58 |
+
<newsletter>
|
59 |
+
<children>
|
60 |
+
<subscriptions_adminform translate="title" module="subscriptions">
|
61 |
+
<title>ActiveCampaign Settings</title>
|
62 |
+
<action>subscriptions/adminhtml_subscriptions</action>
|
63 |
+
</subscriptions_adminform>
|
64 |
+
</children>
|
65 |
+
</newsletter>
|
66 |
+
</menu>
|
67 |
+
<acl>
|
68 |
+
<resources>
|
69 |
+
<all>
|
70 |
+
<title>Allow Everything</title>
|
71 |
+
</all>
|
72 |
+
<admin>
|
73 |
+
<children>
|
74 |
+
<ActiveCampaign_Subscriptions>
|
75 |
+
<title>Subscriptions Module</title>
|
76 |
+
<sort_order>10</sort_order>
|
77 |
+
</ActiveCampaign_Subscriptions>
|
78 |
+
</children>
|
79 |
+
</admin>
|
80 |
+
</resources>
|
81 |
+
</acl>
|
82 |
+
<layout>
|
83 |
+
<updates>
|
84 |
+
<subscriptions>
|
85 |
+
<file>subscriptions.xml</file>
|
86 |
+
</subscriptions>
|
87 |
+
</updates>
|
88 |
+
</layout>
|
89 |
+
</adminhtml>
|
90 |
+
<global>
|
91 |
+
<models>
|
92 |
+
<subscriptions>
|
93 |
+
<class>ActiveCampaign_Subscriptions_Model</class>
|
94 |
+
<resourceModel>subscriptions_mysql4</resourceModel>
|
95 |
+
</subscriptions>
|
96 |
+
<subscriptions_mysql4>
|
97 |
+
<class>ActiveCampaign_Subscriptions_Model_Mysql4</class>
|
98 |
+
<entities>
|
99 |
+
<subscriptions>
|
100 |
+
<table>subscriptions</table>
|
101 |
+
</subscriptions>
|
102 |
+
</entities>
|
103 |
+
</subscriptions_mysql4>
|
104 |
+
</models>
|
105 |
+
<events>
|
106 |
+
<customer_register_success>
|
107 |
+
<observers>
|
108 |
+
<subscriptions>
|
109 |
+
<class>subscriptions/observer</class>
|
110 |
+
<method>register_subscribe</method>
|
111 |
+
<type>singleton</type>
|
112 |
+
</subscriptions>
|
113 |
+
</observers>
|
114 |
+
</customer_register_success>
|
115 |
+
<customer_save_after>
|
116 |
+
<observers>
|
117 |
+
<subscriptions>
|
118 |
+
<class>subscriptions/observer</class>
|
119 |
+
<method>edit_subscribe</method>
|
120 |
+
<type>singleton</type>
|
121 |
+
</subscriptions>
|
122 |
+
</observers>
|
123 |
+
</customer_save_after>
|
124 |
+
</events>
|
125 |
+
<resources>
|
126 |
+
<subscriptions_setup>
|
127 |
+
<setup>
|
128 |
+
<module>ActiveCampaign_Subscriptions</module>
|
129 |
+
</setup>
|
130 |
+
<connection>
|
131 |
+
<use>core_setup</use>
|
132 |
+
</connection>
|
133 |
+
</subscriptions_setup>
|
134 |
+
<subscriptions_write>
|
135 |
+
<connection>
|
136 |
+
<use>core_write</use>
|
137 |
+
</connection>
|
138 |
+
</subscriptions_write>
|
139 |
+
<subscriptions_read>
|
140 |
+
<connection>
|
141 |
+
<use>core_read</use>
|
142 |
+
</connection>
|
143 |
+
</subscriptions_read>
|
144 |
+
</resources>
|
145 |
+
<blocks>
|
146 |
+
<subscriptions>
|
147 |
+
<class>ActiveCampaign_Subscriptions_Block</class>
|
148 |
+
</subscriptions>
|
149 |
+
</blocks>
|
150 |
+
<helpers>
|
151 |
+
<subscriptions>
|
152 |
+
<class>ActiveCampaign_Subscriptions_Helper</class>
|
153 |
+
</subscriptions>
|
154 |
+
</helpers>
|
155 |
+
</global>
|
156 |
+
</config>
|
app/code/local/ActiveCampaign/Subscriptions/sql/subscriptions_setup/mysql4-install-1.0.0.php
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
$installer = $this;
|
4 |
+
|
5 |
+
$installer->startSetup();
|
6 |
+
|
7 |
+
/*
|
8 |
+
`subscriptions_id` int(11) unsigned NOT NULL auto_increment,
|
9 |
+
`title` varchar(255) NOT NULL default '',
|
10 |
+
`filename` varchar(255) NOT NULL default '',
|
11 |
+
`content` text NOT NULL default '',
|
12 |
+
`status` smallint(6) NOT NULL default '0',
|
13 |
+
`created_time` datetime NULL,
|
14 |
+
`update_time` datetime NULL,
|
15 |
+
*/
|
16 |
+
|
17 |
+
$installer->run("
|
18 |
+
|
19 |
+
-- DROP TABLE IF EXISTS {$this->getTable('subscriptions')};
|
20 |
+
CREATE TABLE {$this->getTable('subscriptions')} (
|
21 |
+
`subscriptions_id` int(11) unsigned NOT NULL auto_increment,
|
22 |
+
`title` varchar(255) NOT NULL default '',
|
23 |
+
`api_url` varchar(50) NOT NULL default '',
|
24 |
+
`api_key` varchar(75) NOT NULL default '',
|
25 |
+
`account_url` varchar(50) NOT NULL default '',
|
26 |
+
`list_value` varchar(100) NULL,
|
27 |
+
`lists` text NULL,
|
28 |
+
`status` smallint(6) NOT NULL default '0',
|
29 |
+
`cdate` datetime NULL,
|
30 |
+
PRIMARY KEY (`subscriptions_id`)
|
31 |
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
32 |
+
|
33 |
+
INSERT INTO {$this->getTable('subscriptions')} (title, status, cdate) VALUES ('Default', 2, NOW());
|
34 |
+
");
|
35 |
+
|
36 |
+
$installer->endSetup();
|
app/design/adminhtml/default/default/layout/subscriptions.xml
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<layout version="0.1.0">
|
3 |
+
<subscriptions_adminhtml_subscriptions_index>
|
4 |
+
<reference name="content">
|
5 |
+
<block type="subscriptions/adminhtml_subscriptions" name="subscriptions" template="subscriptions/list.phtml">
|
6 |
+
<block type="subscriptions/adminhtml_subscriptions" name="grid" template="subscriptions/grid.phtml" />
|
7 |
+
</block>
|
8 |
+
</reference>
|
9 |
+
</subscriptions_adminhtml_subscriptions_index>
|
10 |
+
</layout>
|
app/design/adminhtml/default/default/template/subscriptions/grid.phtml
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<div>
|
2 |
+
<?php
|
3 |
+
echo $this->getGridHtml();
|
4 |
+
?>
|
5 |
+
</div>
|
app/design/adminhtml/default/default/template/subscriptions/list.phtml
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
|
2 |
+
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js"></script>
|
3 |
+
<script type="text/javascript">
|
4 |
+
var $ac = jQuery.noConflict();
|
5 |
+
|
6 |
+
function hide_stuff() {
|
7 |
+
// the paginator stuff (also Export, Search, etc)
|
8 |
+
$ac("#subscriptionsGrid .actions").hide();
|
9 |
+
$ac("#subscriptionsGrid .massaction").hide();
|
10 |
+
|
11 |
+
// the headings row
|
12 |
+
//$ac("#subscriptionsGrid_table tr.headings").hide();
|
13 |
+
|
14 |
+
// the filter row (right beneath the column headers)
|
15 |
+
$ac("#subscriptionsGrid_table tr.filter").hide();
|
16 |
+
|
17 |
+
// the first column of the table (the checkboxes)
|
18 |
+
$ac("#subscriptionsGrid_table td:nth-child(1),th:nth-child(1)").hide();
|
19 |
+
|
20 |
+
// the Lists column (we could not get the list output anyway)
|
21 |
+
$ac("#subscriptionsGrid_table td:nth-child(3),th:nth-child(3)").hide();
|
22 |
+
|
23 |
+
// hide the Action column (where the Edit button showed) - you can just click on the row
|
24 |
+
$ac("#subscriptionsGrid_table td:nth-child(5),th:nth-child(5)").hide();
|
25 |
+
}
|
26 |
+
</script>
|
27 |
+
<div class="content-header">
|
28 |
+
<table cellspacing="0">
|
29 |
+
<tr>
|
30 |
+
<td style="width:50%;">
|
31 |
+
<h3 class="icon-head" style="background-image: url(http://d226aj4ao1t61q.cloudfront.net/iiqh94zq_activecampaign.png); color: #2559A2;">
|
32 |
+
<?php echo Mage::helper('subscriptions')->__('ActiveCampaign Subscription Settings') ?>
|
33 |
+
</h3>
|
34 |
+
</td>
|
35 |
+
<td class="form-buttons"></td>
|
36 |
+
</tr>
|
37 |
+
</table>
|
38 |
+
</div>
|
39 |
+
<div>
|
40 |
+
<?php
|
41 |
+
//echo $this->getChildHtml('grid');
|
42 |
+
$grid_html = $this->getGridHtml();
|
43 |
+
echo $grid_html;
|
44 |
+
?>
|
45 |
+
</div>
|
46 |
+
<script type="text/javascript">
|
47 |
+
$ac(document).ready(function() {
|
48 |
+
hide_stuff();
|
49 |
+
$ac("#subscriptionsGrid_table").attr("style", "width: 600px;");
|
50 |
+
});
|
51 |
+
</script>
|
app/design/frontend/default/default/layout/subscriptions.xml
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<layout version="0.1.0">
|
3 |
+
<default>
|
4 |
+
</default>
|
5 |
+
<subscriptions_index_index>
|
6 |
+
<reference name="content">
|
7 |
+
<block type="subscriptions/subscriptions" name="subscriptions" template="subscriptions/subscriptions.phtml" />
|
8 |
+
</reference>
|
9 |
+
</subscriptions_index_index>
|
10 |
+
</layout>
|
app/design/frontend/default/default/template/subscriptions/subscriptions.phtml
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<h4><?php echo $this->__('Module List') ?></h4>
|
2 |
+
<?php
|
3 |
+
|
4 |
+
/*
|
5 |
+
This shows how to load specific fields from a record in the database.
|
6 |
+
1) Note the load(15), this corresponds to saying "select * from table where table_id = 15"
|
7 |
+
2) You can then just use the get(fieldname) to pull specific data from the table.
|
8 |
+
3) If you have a field named news_id, then it becomes getNewsId, etc.
|
9 |
+
*/
|
10 |
+
/*
|
11 |
+
$news = Mage::getModel('subscriptions/subscriptions')->load(15);
|
12 |
+
echo $news->getNewsId();
|
13 |
+
echo $news->getTitle();
|
14 |
+
echo $news->getContent();
|
15 |
+
echo $news->getStatus();
|
16 |
+
*/
|
17 |
+
|
18 |
+
/*
|
19 |
+
This shows an alternate way of loading datas from a record using the database the "Magento Way" (using blocks and controller).
|
20 |
+
Uncomment blocks in /app/code/local/Namespace/Module/controllers/IndexController.php if you want to use it.
|
21 |
+
|
22 |
+
*/
|
23 |
+
/*
|
24 |
+
$object = $this->getSubscriptions();
|
25 |
+
echo 'id: '.$object['test_id'].'<br/>';
|
26 |
+
echo 'title: '.$object['title'].'<br/>';
|
27 |
+
echo 'content: '.$object['content'].'<br/>';
|
28 |
+
echo 'status: '.$object['status'].'<br/>';
|
29 |
+
*/
|
30 |
+
|
31 |
+
|
32 |
+
/*
|
33 |
+
This shows how to load multiple rows in a collection and save a change to them.
|
34 |
+
1) The setPageSize function will load only 5 records per page and you can set the current Page with the setCurPage function.
|
35 |
+
2) The $collection->walk('save') allows you to save everything in the collection after all changes have been made.
|
36 |
+
*/
|
37 |
+
/*
|
38 |
+
$i = 0;
|
39 |
+
|
40 |
+
$collection = Mage::getModel('subscriptions/subscriptions')->getCollection();
|
41 |
+
$collection->setPageSize(5);
|
42 |
+
$collection->setCurPage(2);
|
43 |
+
$size = $collection->getSize();
|
44 |
+
$cnt = count($collection);
|
45 |
+
foreach ($collection as $item) {
|
46 |
+
$i = $i+1;
|
47 |
+
$item->setTitle($i);
|
48 |
+
echo $item->getTitle();
|
49 |
+
}
|
50 |
+
|
51 |
+
$collection->walk('save');
|
52 |
+
*/
|
53 |
+
|
54 |
+
/*
|
55 |
+
This shows how to load a single record and save a change.
|
56 |
+
1) Note the setTitle, this corresponds to the table field name, title, and then you pass it the text to change.
|
57 |
+
2) Call the save() function only on a single record.
|
58 |
+
*/
|
59 |
+
/*
|
60 |
+
$object = Mage::getModel('subscriptions/subscriptions')->load(1);
|
61 |
+
$object->setTitle('This is a changed title');
|
62 |
+
$object->save();
|
63 |
+
*/
|
64 |
+
|
65 |
+
?>
|
package.xml
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<package>
|
3 |
+
<name>ActiveCampaign_Subscriptions</name>
|
4 |
+
<version>1.0.0</version>
|
5 |
+
<stability>stable</stability>
|
6 |
+
<license uri="https://www.activecampaign.com/hosted/terms.php">Commercial/Free</license>
|
7 |
+
<channel>community</channel>
|
8 |
+
<extends/>
|
9 |
+
<summary>Add Magento customers as ActiveCampaign subscribers with various sync options.</summary>
|
10 |
+
<description>1. Connect any ActiveCampaign hosted account (using your API URL and Key).
|
11 |
+

|
12 |
+
2. Have new customer account registrations added to ActiveCampaign (if they opt-in to the Newsletter).
|
13 |
+

|
14 |
+
3. Have existing customer account newsletter modifications updated in ActiveCampaign.
|
15 |
+

|
16 |
+
4. Bulk export/sync all current newsletter subscribers to ActiveCampaign in just two clicks!</description>
|
17 |
+
<notes>First release</notes>
|
18 |
+
<authors><author><name>ActiveCampaign, Inc.</name><user>activecampaign</user><email>matt@activecampaign.com</email></author></authors>
|
19 |
+
<date>2012-11-12</date>
|
20 |
+
<time>17:17:17</time>
|
21 |
+
<contents><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="subscriptions.xml" hash="18bfe6676477fc84b488277025d42568"/></dir><dir name="template"><dir name="subscriptions"><file name="grid.phtml" hash="5479475e2a96a006da97e35b31efeb02"/><file name="list.phtml" hash="d90e444079a30e2337df2cbcf10aa35f"/></dir></dir></dir></dir></dir><dir name="frontend"><dir name="default"><dir name="default"><dir name="layout"><file name="subscriptions.xml" hash="d0a96f68db976ce1919a664228184e9c"/></dir><dir name="template"><dir name="subscriptions"><file name="subscriptions.phtml" hash="2025758bce03d7b9cfe99029050c7be4"/></dir></dir></dir></dir></dir></target><target name="magelocal"><dir name="ActiveCampaign"><dir name="Subscriptions"><dir name="Block"><file name="Subscriptions.php" hash="ec632af3d623af970ba460de16eaa841"/><dir name="Adminhtml"><file name="Subscriptions.php" hash="c26f6255fa14a3a5b81828425041ec2c"/><dir name="Subscriptions"><file name="Edit.php" hash="3dba9bad67c86cea8d6bb9e40898d5fb"/><file name="Grid.php" hash="b51fc9698c21224488c41826489a8177"/><dir name="Edit"><file name="Form.php" hash="b1eda088b2adf03d69bc1aa3cfb2a00a"/><file name="Tabs.php" hash="19d7771dca320416c7c27e0d8f6c9f36"/><dir name="Tab"><file name="Connection.php" hash="230d5a8f70b5de930864b25821290efb"/><file name="Export.php" hash="f65aa906629d6a1b4a17f16014488017"/><file name="List.php" hash="bcde9bfb9254caa3774e9b5d4aa85e14"/></dir></dir></dir></dir></dir><dir name="controllers"><file name="IndexController.php" hash="f6e27a764745bdb55f17fdca49a7fa81"/><dir name="Adminhtml"><file name="SubscriptionsController.php" hash="ee5fb27c34ca707a35b8766455dc0283"/></dir></dir><dir name="etc"><file name="config.xml" hash="a3bacb007c725735eee61c9a2bae5475"/></dir><dir name="Helper"><file name="Data.php" hash="4b35d91431328ee595132df575a60a2a"/></dir><dir name="Model"><file name="Observer.php" hash="fce592221a9113aa5ae356da79b31a6e"/><file name="Status.php" hash="c35feda8164009341d289074be5612c0"/><file name="Subscriptions.php" hash="76818326ecfd635e574f704003184300"/><dir name="Mysql4"><file name="Subscriptions.php" hash="d112b3f1194a8bb7f329dacb34161941"/><dir name="Subscriptions"><file name="Collection.php" hash="457890390bd29e72dda81d3088ef5a50"/></dir></dir></dir><dir name="sql"><dir name="subscriptions_setup"><file name="mysql4-install-1.0.0.php" hash="11028fce8cd9cbf9cff09dd7575453dd"/></dir></dir></dir></dir></target></contents>
|
22 |
+
<compatible/>
|
23 |
+
<dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php><extension><name>curl</name><min>7.19.7</min><max>7.28.0</max></extension></required></dependencies>
|
24 |
+
</package>
|