Version Notes
Release v2.1.0.1
Download this release
Release Info
| Developer | MailPlus |
| Extension | Techtwo_Mailplus |
| Version | 2.1.0.0 |
| Comparing to | |
| See all releases | |
Version 2.1.0.0
- app/code/community/Techtwo/Mailplus/Block/Adminhtml/Bounces.php +47 -0
- app/code/community/Techtwo/Mailplus/Block/Adminhtml/Bounces/Grid.php +109 -0
- app/code/community/Techtwo/Mailplus/Block/Adminhtml/Mapping.php +37 -0
- app/code/community/Techtwo/Mailplus/Block/Adminhtml/Mapping/Edit/Form.php +155 -0
- app/code/community/Techtwo/Mailplus/Block/Adminhtml/Restqueue.php +29 -0
- app/code/community/Techtwo/Mailplus/Block/Adminhtml/Restqueue/Grid.php +104 -0
- app/code/community/Techtwo/Mailplus/Block/Adminhtml/Syncstatus.php +33 -0
- app/code/community/Techtwo/Mailplus/Block/Adminhtml/Syncstatus/Grid.php +107 -0
- app/code/community/Techtwo/Mailplus/Block/Adminhtml/Users.php +66 -0
- app/code/community/Techtwo/Mailplus/Block/Adminhtml/Users/Edit.php +46 -0
- app/code/community/Techtwo/Mailplus/Block/Adminhtml/Users/Edit/Form.php +35 -0
- app/code/community/Techtwo/Mailplus/Block/Adminhtml/Users/Edit/Tab/Form.php +119 -0
- app/code/community/Techtwo/Mailplus/Block/Adminhtml/Users/Edit/Tabs.php +38 -0
- app/code/community/Techtwo/Mailplus/Block/Adminhtml/Users/Grid.php +163 -0
- app/code/community/Techtwo/Mailplus/Client/Contact/Permission.php +74 -0
- app/code/community/Techtwo/Mailplus/Client/Contact/Property.php +76 -0
- app/code/community/Techtwo/Mailplus/Client/Error.php +64 -0
- app/code/community/Techtwo/Mailplus/Client/Exception.php +31 -0
- app/code/community/Techtwo/Mailplus/Client/Rest.php +108 -0
- app/code/community/Techtwo/Mailplus/Helper/Config.php +193 -0
- app/code/community/Techtwo/Mailplus/Helper/Cron.php +43 -0
- app/code/community/Techtwo/Mailplus/Helper/Data.php +376 -0
- app/code/community/Techtwo/Mailplus/Helper/Feed.php +65 -0
- app/code/community/Techtwo/Mailplus/Helper/Rest.php +1604 -0
- app/code/community/Techtwo/Mailplus/Model/Abandoned/Campaign.php +40 -0
- app/code/community/Techtwo/Mailplus/Model/Bounce.php +23 -0
- app/code/community/Techtwo/Mailplus/Model/Cron/Hourly.php +316 -0
- app/code/community/Techtwo/Mailplus/Model/Cron/Often.php +368 -0
- app/code/community/Techtwo/Mailplus/Model/Info.php +30 -0
- app/code/community/Techtwo/Mailplus/Model/Mailing.php +23 -0
- app/code/community/Techtwo/Mailplus/Model/Mysql4/Abandoned/Campaign.php +25 -0
- app/code/community/Techtwo/Mailplus/Model/Mysql4/Abandoned/Campaign/Collection.php +23 -0
- app/code/community/Techtwo/Mailplus/Model/Mysql4/Bounce.php +23 -0
- app/code/community/Techtwo/Mailplus/Model/Mysql4/Bounce/Collection.php +24 -0
- app/code/community/Techtwo/Mailplus/Model/Mysql4/Info.php +23 -0
- app/code/community/Techtwo/Mailplus/Model/Mysql4/Info/Collection.php +22 -0
- app/code/community/Techtwo/Mailplus/Model/Mysql4/Product.php +39 -0
- app/code/community/Techtwo/Mailplus/Model/Mysql4/Product/Collection.php +41 -0
- app/code/community/Techtwo/Mailplus/Model/Mysql4/Restqueue.php +23 -0
- app/code/community/Techtwo/Mailplus/Model/Mysql4/Restqueue/Collection.php +25 -0
- app/code/community/Techtwo/Mailplus/Model/Mysql4/Syncqueue.php +23 -0
- app/code/community/Techtwo/Mailplus/Model/Mysql4/Syncqueue/Collection.php +25 -0
- app/code/community/Techtwo/Mailplus/Model/Mysql4/User.php +60 -0
- app/code/community/Techtwo/Mailplus/Model/Mysql4/User/Collection.php +24 -0
- app/code/community/Techtwo/Mailplus/Model/Newsletter/Subscriber.php +36 -0
- app/code/community/Techtwo/Mailplus/Model/Product.php +59 -0
- app/code/community/Techtwo/Mailplus/Model/Restqueue.php +24 -0
- app/code/community/Techtwo/Mailplus/Model/Syncqueue.php +38 -0
- app/code/community/Techtwo/Mailplus/Model/System/Campaign.php +63 -0
- app/code/community/Techtwo/Mailplus/Model/System/Config/Source/Campaign.php +106 -0
- app/code/community/Techtwo/Mailplus/Model/System/Config/Source/Keepframe.php +33 -0
- app/code/community/Techtwo/Mailplus/Model/System/Config/Source/Product/Specs.php +37 -0
- app/code/community/Techtwo/Mailplus/Model/System/Config/Source/Synchronize.php +32 -0
- app/code/community/Techtwo/Mailplus/Model/System/Config/Source/Yesno/Default/No.php +38 -0
- app/code/community/Techtwo/Mailplus/Model/System/Config/Source/Yesno/Default/Yes.php +38 -0
- app/code/community/Techtwo/Mailplus/Model/User.php +495 -0
- app/code/community/Techtwo/Mailplus/Observer/Config.php +33 -0
- app/code/community/Techtwo/Mailplus/Observer/Customer.php +535 -0
- app/code/community/Techtwo/Mailplus/Observer/Product.php +64 -0
- app/code/community/Techtwo/Mailplus/controllers/Adminhtml/BouncesController.php +199 -0
- app/code/community/Techtwo/Mailplus/controllers/Adminhtml/FeedController.php +201 -0
- app/code/community/Techtwo/Mailplus/controllers/Adminhtml/FeedsController.php +61 -0
- app/code/community/Techtwo/Mailplus/controllers/Adminhtml/HelpController.php +27 -0
- app/code/community/Techtwo/Mailplus/controllers/Adminhtml/MailingsController.php +109 -0
- app/code/community/Techtwo/Mailplus/controllers/Adminhtml/MappingController.php +76 -0
- app/code/community/Techtwo/Mailplus/controllers/Adminhtml/RestqueueController.php +26 -0
- app/code/community/Techtwo/Mailplus/controllers/Adminhtml/StatusController.php +164 -0
- app/code/community/Techtwo/Mailplus/controllers/Adminhtml/SyncstatusController.php +23 -0
- app/code/community/Techtwo/Mailplus/controllers/Adminhtml/UsersController.php +522 -0
- app/code/community/Techtwo/Mailplus/controllers/CustomerController.php +31 -0
- app/code/community/Techtwo/Mailplus/controllers/ImageController.php +51 -0
- app/code/community/Techtwo/Mailplus/controllers/Mailplus/Entry.php +210 -0
- app/code/community/Techtwo/Mailplus/controllers/Mailplus/Renderer/Entry.php +282 -0
- app/code/community/Techtwo/Mailplus/controllers/UseController.php +85 -0
- app/code/community/Techtwo/Mailplus/etc/config.xml +397 -0
- app/code/community/Techtwo/Mailplus/etc/system.xml +210 -0
- app/code/community/Techtwo/Mailplus/sql/mailplus_setup/mysql4-install-2.1.0.php +130 -0
- app/code/community/Techtwo/Mailplus/sql/mailplus_setup/mysql4-upgrade-0.1.1-0.2.1.php +2 -0
- app/code/community/Techtwo/Mailplus/sql/mailplus_setup/mysql4-upgrade-0.2.1-0.3.1.php +2 -0
- app/code/community/Techtwo/Mailplus/sql/mailplus_setup/mysql4-upgrade-0.3.1-0.3.2.php +2 -0
- app/code/community/Techtwo/Mailplus/sql/mailplus_setup/mysql4-upgrade-0.3.2-0.3.3.php +5 -0
- app/code/community/Techtwo/Mailplus/sql/mailplus_setup/mysql4-upgrade-0.3.3-1.0.0.php +24 -0
- app/code/community/Techtwo/Mailplus/sql/mailplus_setup/mysql4-upgrade-1.0.0-2.0.0.php +29 -0
- app/code/community/Techtwo/Mailplus/sql/mailplus_setup/mysql4-upgrade-2.0.0-2.1.0.php +15 -0
- app/design/adminhtml/default/default/layout/mailplus.xml +95 -0
- app/design/adminhtml/default/default/template/mailplus/bounces.phtml +47 -0
- app/design/adminhtml/default/default/template/mailplus/cronstatus.phtml +71 -0
- app/design/adminhtml/default/default/template/mailplus/edit.phtml +117 -0
- app/design/adminhtml/default/default/template/mailplus/help.phtml +64 -0
- app/design/adminhtml/default/default/template/mailplus/notifications.phtml +55 -0
- app/design/adminhtml/default/default/template/mailplus/status.phtml +100 -0
- app/design/adminhtml/default/default/template/mailplus/users/grid.phtml +60 -0
- app/design/adminhtml/default/default/template/mailplus/users/import.phtml +27 -0
- app/design/adminhtml/default/default/template/mailplus/website_switcher.phtml +30 -0
- app/design/frontend/base/default/layout/mailplus.xml +4 -0
- lib/MailPlus/Oauth/Client.php +68 -0
- lib/MailPlus/Oauth/Token/Access.php +41 -0
- package.xml +18 -0
app/code/community/Techtwo/Mailplus/Block/Adminhtml/Bounces.php
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
class Techtwo_Mailplus_Block_Adminhtml_Bounces extends Mage_Adminhtml_Block_Widget_Grid_Container
|
| 18 |
+
{
|
| 19 |
+
public function __construct()
|
| 20 |
+
{
|
| 21 |
+
$this->_controller = 'adminhtml_bounces';
|
| 22 |
+
$this->_blockGroup = 'mailplus';
|
| 23 |
+
$this->_headerText = Mage::helper('mailplus')->__('MailPlus Bounces');
|
| 24 |
+
parent::__construct();
|
| 25 |
+
|
| 26 |
+
if ( false) // not yet supported
|
| 27 |
+
{
|
| 28 |
+
$this->_addButton('add', array(
|
| 29 |
+
'label' => 'Add Bounce',
|
| 30 |
+
//'onclick' => 'submitMyHooks(\'' . Mage::helper('adminhtml')->getUrl('mailplus/adminhtml_index/new') . '\')',
|
| 31 |
+
'class' => 'add'
|
| 32 |
+
));
|
| 33 |
+
}
|
| 34 |
+
else
|
| 35 |
+
$this->_removeButton('add');
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
/*
|
| 39 |
+
protected function _prepareLayout()
|
| 40 |
+
{
|
| 41 |
+
parent::_prepareLayout();
|
| 42 |
+
if(!$this->getRequest()->isXmlHttpRequest()){
|
| 43 |
+
$this->getLayout()->getBlock('head')->addItem('skin_js', 'mailplus/Mailplus.js');
|
| 44 |
+
}
|
| 45 |
+
}
|
| 46 |
+
*/
|
| 47 |
+
}
|
app/code/community/Techtwo/Mailplus/Block/Adminhtml/Bounces/Grid.php
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
|
| 18 |
+
class Techtwo_Mailplus_Block_Adminhtml_Bounces_Grid extends Mage_Adminhtml_Block_Widget_Grid
|
| 19 |
+
{
|
| 20 |
+
public function __construct()
|
| 21 |
+
{
|
| 22 |
+
parent::__construct();
|
| 23 |
+
$this->setId('bouncesGrid');
|
| 24 |
+
// This is the primary key of the database
|
| 25 |
+
$this->setDefaultSort('id');
|
| 26 |
+
$this->setDefaultDir('ASC');
|
| 27 |
+
$this->setSaveParametersInSession(true);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
protected function _prepareCollection()
|
| 31 |
+
{
|
| 32 |
+
$collection = Mage::getModel('mailplus/bounce')->getCollection();
|
| 33 |
+
//$collection = Mage::helper('mailplus')->joinEavTablesIntoCollection($collection, 'customer_id', 'customer');
|
| 34 |
+
$this->setCollection($collection);
|
| 35 |
+
|
| 36 |
+
return parent::_prepareCollection();
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
protected function _prepareMassaction()
|
| 40 |
+
{
|
| 41 |
+
$this->setMassactionIdField('queue_id');
|
| 42 |
+
$this->getMassactionBlock()->setFormFieldName('mailplus_bounce_mass');
|
| 43 |
+
|
| 44 |
+
$this->getMassactionBlock()->addItem('delete', array(
|
| 45 |
+
'label' => Mage::helper('mailplus')->__('Delete'),
|
| 46 |
+
'url' => $this->getUrl('*/*/massDelete'),
|
| 47 |
+
'confirm' => Mage::helper('mailplus')->__('Are you sure you want to delete these bounces?')
|
| 48 |
+
));
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
protected function _prepareColumns()
|
| 52 |
+
{
|
| 53 |
+
$this->addColumn('id', array(
|
| 54 |
+
'header' => Mage::helper('mailplus')->__('Id'),
|
| 55 |
+
'align' =>'right',
|
| 56 |
+
'width' => '50px',
|
| 57 |
+
'index' => 'id',
|
| 58 |
+
));
|
| 59 |
+
|
| 60 |
+
$this->addColumn('firstname', array(
|
| 61 |
+
'header' => Mage::helper('customer')->__('Firstname'),
|
| 62 |
+
'index' => 'firstname'
|
| 63 |
+
));
|
| 64 |
+
|
| 65 |
+
$this->addColumn('lastname', array(
|
| 66 |
+
'header' => Mage::helper('customer')->__('Lastname'),
|
| 67 |
+
'index' => 'lastname'
|
| 68 |
+
));
|
| 69 |
+
|
| 70 |
+
$this->addColumn('email', array(
|
| 71 |
+
'header' => Mage::helper('customer')->__('Email'),
|
| 72 |
+
'index' => 'email'
|
| 73 |
+
));
|
| 74 |
+
|
| 75 |
+
$this->addColumn('mailplus_id', array(
|
| 76 |
+
'header' => 'Mailplus id',
|
| 77 |
+
'index' => 'mailplus_id'
|
| 78 |
+
));
|
| 79 |
+
|
| 80 |
+
$this->addColumn('total_received', array(
|
| 81 |
+
'header' => Mage::helper('mailplus')->__('Total received'),
|
| 82 |
+
'align' =>'center',
|
| 83 |
+
//'type' => 'int',
|
| 84 |
+
'index' => 'total_received',
|
| 85 |
+
));
|
| 86 |
+
|
| 87 |
+
$this->addColumn('is_test', array(
|
| 88 |
+
'header' => Mage::helper('mailplus')->__('Is test'),
|
| 89 |
+
'align' =>'center',
|
| 90 |
+
'type' => 'bool',
|
| 91 |
+
'index' => 'is_test',
|
| 92 |
+
));
|
| 93 |
+
|
| 94 |
+
$this->addColumn('last_bounce_date', array(
|
| 95 |
+
'header' => Mage::helper('mailplus')->__('Date last bounced'),
|
| 96 |
+
'align' =>'center',
|
| 97 |
+
'type' => 'datetime',
|
| 98 |
+
'index' => 'last_bounce_date',
|
| 99 |
+
));
|
| 100 |
+
|
| 101 |
+
return parent::_prepareColumns();
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
public function getRowUrl($row)
|
| 105 |
+
{
|
| 106 |
+
return '#';
|
| 107 |
+
return $this->getUrl('*/*/edit', array('id' => $row->getId()));
|
| 108 |
+
}
|
| 109 |
+
}
|
app/code/community/Techtwo/Mailplus/Block/Adminhtml/Mapping.php
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
class Techtwo_Mailplus_Block_Adminhtml_Mapping extends Mage_Adminhtml_Block_Widget_Form_Container
|
| 18 |
+
{
|
| 19 |
+
public function __construct()
|
| 20 |
+
{
|
| 21 |
+
parent::__construct();
|
| 22 |
+
|
| 23 |
+
$this->_objectId = 'id';
|
| 24 |
+
$this->_blockGroup = 'mailplus';
|
| 25 |
+
$this->_controller = 'adminhtml_mapping';
|
| 26 |
+
|
| 27 |
+
$this->_updateButton('save', 'label', Mage::helper('mailplus')->__('Save'));
|
| 28 |
+
$this->_removeButton('reset');
|
| 29 |
+
$this->_removeButton('back');
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
public function getHeaderText()
|
| 33 |
+
{
|
| 34 |
+
return Mage::helper('mailplus')->__('Mapping');
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
}
|
app/code/community/Techtwo/Mailplus/Block/Adminhtml/Mapping/Edit/Form.php
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
class Techtwo_Mailplus_Block_Adminhtml_Mapping_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
|
| 18 |
+
{
|
| 19 |
+
protected function _prepareForm()
|
| 20 |
+
{
|
| 21 |
+
$form = new Varien_Data_Form(array(
|
| 22 |
+
'id' => 'edit_form',
|
| 23 |
+
'action' => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'))),
|
| 24 |
+
'method' => 'post',
|
| 25 |
+
'enctype' => 'multipart/form-data'
|
| 26 |
+
)
|
| 27 |
+
);
|
| 28 |
+
|
| 29 |
+
$website = Mage::app()->getFrontController()->getRequest()->getParam('website');
|
| 30 |
+
if (!$website) {
|
| 31 |
+
$sites = Mage::app()->getWebsites();
|
| 32 |
+
$website = reset($sites);
|
| 33 |
+
} else {
|
| 34 |
+
$website = Mage::app()->getWebsite($website);
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
$fieldSet = $form->addFieldset('Mapping', array('legend' => 'Mapping for site ' . $website->getName()));
|
| 38 |
+
|
| 39 |
+
$this->fillForm($website, $fieldSet);
|
| 40 |
+
|
| 41 |
+
$form->setUseContainer(true);
|
| 42 |
+
$this->setForm($form);
|
| 43 |
+
return parent::_prepareForm();
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
protected function addAttributeToFieldset($site, $fieldset, $attr, $mailplusProperties) {
|
| 47 |
+
if ($attr->getFrontendInput() === 'multiline') {
|
| 48 |
+
for ($i = 1; $i <= $attr->getMultilineCount(); $i++) {
|
| 49 |
+
$mappingId = $attr->getAttributeCode() . '-line-' . $i;
|
| 50 |
+
$label = $attr->getFrontendLabel() . ' ' . Mage::helper('mailplus')->__('line') . ' ' . $i;
|
| 51 |
+
$this->addAttributeCodeToFieldset($mappingId, $label, $site, $fieldset, $attr, $mailplusProperties);
|
| 52 |
+
}
|
| 53 |
+
} else {
|
| 54 |
+
$mappingId = $attr->getAttributeCode();
|
| 55 |
+
$label = $attr->getFrontendLabel();
|
| 56 |
+
$this->addAttributeCodeToFieldset($mappingId, $label, $site, $fieldset, $attr, $mailplusProperties);
|
| 57 |
+
}
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
protected function addAttributeCodeToFieldset($mappingId, $label, $site, $fieldset, $attr, $mailplusProperties) {
|
| 61 |
+
$currentMapping = Mage::registry('mailplus_currentmapping');
|
| 62 |
+
$doubleMappedProps = Mage::registry('mailplus_double_mapped');
|
| 63 |
+
|
| 64 |
+
$value = null;
|
| 65 |
+
if ($currentMapping) {
|
| 66 |
+
$value = $currentMapping[$mappingId];
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
if (!$value) {
|
| 70 |
+
$value = $site->getConfig(Techtwo_Mailplus_Helper_Config::$_MAPPING_CONFIGPATH . $mappingId);
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
if (!$value && !$site->getConfig(Techtwo_Mailplus_Helper_Config::$_MAPPING_CONFIGPATH . 'savedonce')) {
|
| 74 |
+
if (isset(Techtwo_Mailplus_Helper_Config::$_defaultMapping[$mappingId])) {
|
| 75 |
+
$value = Techtwo_Mailplus_Helper_Config::$_defaultMapping[$mappingId];
|
| 76 |
+
}
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
$fieldOptions = array(
|
| 80 |
+
'backend_model' => 'mailplus_mapping',
|
| 81 |
+
'label' => $label,
|
| 82 |
+
'title' => $label,
|
| 83 |
+
'name' => 'groups[mapping][fields][' . $mappingId . '][value]',
|
| 84 |
+
'options' => $mailplusProperties,
|
| 85 |
+
'value' => $value
|
| 86 |
+
);
|
| 87 |
+
|
| 88 |
+
if (isset($doubleMappedProps[$value])) {
|
| 89 |
+
$fieldOptions['after_element_html'] = '<div class="validation-advice">'.
|
| 90 |
+
Mage::helper('mailplus')->__('This property is mapped more than once') .
|
| 91 |
+
'</div>';
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
$fieldset->addField('mailplusmapping_mailplusmapping_' . $mappingId, 'select', $fieldOptions);
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
protected function fillForm($site, $fieldset) {
|
| 98 |
+
/* @var $rest Techtwo_Mailplus_Helper_Rest */
|
| 99 |
+
$rest = Mage::helper('mailplus/rest');
|
| 100 |
+
/* @var $mailplus Techtwo_Mailplus_Helper_Data */
|
| 101 |
+
$mailplus = Mage::helper('mailplus');
|
| 102 |
+
/* @var $config Techtwo_Mailplus_Helper_Config */
|
| 103 |
+
$config = Mage::helper('mailplus/config');
|
| 104 |
+
|
| 105 |
+
$websiteId = $site->getId();
|
| 106 |
+
|
| 107 |
+
$properties = null;
|
| 108 |
+
try {
|
| 109 |
+
$rest->clearContactPropertiesCache($websiteId);
|
| 110 |
+
$properties = $rest->getContactProperties($websiteId);
|
| 111 |
+
} catch (Exception $e) {
|
| 112 |
+
Mage::logException($e);
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
if (!$properties) {
|
| 116 |
+
$fieldset->addField("label", "label", array(
|
| 117 |
+
'label' => $mailplus->__('Error:'),
|
| 118 |
+
'value' => $mailplus->__('Could not get settings from MailPlus. '))
|
| 119 |
+
);
|
| 120 |
+
return;
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
$propoptions = array();
|
| 124 |
+
$propoptions[''] = $mailplus->__('Not mapped');
|
| 125 |
+
foreach($properties as $prop) {
|
| 126 |
+
if ($prop->getName() !== 'testGroup' &&
|
| 127 |
+
$prop->getName() !== 'externalId' &&
|
| 128 |
+
$prop->getName() !== 'permissions') {
|
| 129 |
+
$propoptions[$prop->getName()] = $prop->getDescription();
|
| 130 |
+
}
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
$fieldset->addField('custlabel', 'label', array('bold' => true, 'value' => $mailplus->__('Customer')));
|
| 134 |
+
$attributes = $config->getCustomerAttributes();
|
| 135 |
+
foreach ($attributes as $attr) {
|
| 136 |
+
if ($attr->getIsVisible() && $attr->getAttributeCode() !== 'disable_auto_group_change') {
|
| 137 |
+
$this->addAttributeToFieldset($site, $fieldset, $attr, $propoptions);
|
| 138 |
+
}
|
| 139 |
+
}
|
| 140 |
+
$fieldset->addField('addrlabel', 'label', array('bold' => true, 'value' => $mailplus->__('Address')));
|
| 141 |
+
$attributes = $config->getAddressAttributes();
|
| 142 |
+
foreach ($attributes as $attr) {
|
| 143 |
+
if ($attr->getIsVisible()) {
|
| 144 |
+
$this->addAttributeToFieldset($site, $fieldset, $attr, $propoptions);
|
| 145 |
+
}
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
$fieldset->addField('mailplusmapping_mapping_site', 'hidden',
|
| 149 |
+
array(
|
| 150 |
+
'name' => 'groups[mapping][fields][site][value]',
|
| 151 |
+
'value' => $site->getId()
|
| 152 |
+
)
|
| 153 |
+
);
|
| 154 |
+
}
|
| 155 |
+
}
|
app/code/community/Techtwo/Mailplus/Block/Adminhtml/Restqueue.php
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
class Techtwo_Mailplus_Block_Adminhtml_RestQueue extends Mage_Adminhtml_Block_Widget_Grid_Container
|
| 18 |
+
{
|
| 19 |
+
public function __construct()
|
| 20 |
+
{
|
| 21 |
+
$this->_controller = 'adminhtml_restqueue';
|
| 22 |
+
$this->_blockGroup = 'mailplus';
|
| 23 |
+
$this->_headerText = Mage::helper('mailplus')->__('MailPlus API Queue');
|
| 24 |
+
|
| 25 |
+
parent::__construct();
|
| 26 |
+
|
| 27 |
+
$this->_removeButton('add');
|
| 28 |
+
}
|
| 29 |
+
}
|
app/code/community/Techtwo/Mailplus/Block/Adminhtml/Restqueue/Grid.php
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/class Techtwo_Mailplus_Block_Adminhtml_Restqueue_Grid extends Mage_Adminhtml_Block_Widget_Grid
|
| 17 |
+
{
|
| 18 |
+
public function __construct()
|
| 19 |
+
{
|
| 20 |
+
parent::__construct();
|
| 21 |
+
$this->setId('RestqueueGrid');
|
| 22 |
+
$this->setDefaultSort('id');
|
| 23 |
+
$this->setDefaultDir('DESC');
|
| 24 |
+
$this->setSaveParametersInSession(true);
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
protected function _prepareCollection()
|
| 28 |
+
{
|
| 29 |
+
$collection = Mage::getModel('mailplus/restqueue')->getCollection();
|
| 30 |
+
$this->setCollection($collection);
|
| 31 |
+
return parent::_prepareCollection();
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
protected function _prepareColumns()
|
| 35 |
+
{
|
| 36 |
+
$this->addColumn('queue_id', array(
|
| 37 |
+
'header' => Mage::helper('mailplus')->__('queue_id'),
|
| 38 |
+
'align' =>'right',
|
| 39 |
+
'width' => '50px',
|
| 40 |
+
'index' => 'queue_id',
|
| 41 |
+
'type' => 'range'
|
| 42 |
+
));
|
| 43 |
+
|
| 44 |
+
$this->addColumn('created_at', array(
|
| 45 |
+
'header' => Mage::helper('mailplus')->__('Created'),
|
| 46 |
+
'align' => 'left',
|
| 47 |
+
'index' => 'created_at',
|
| 48 |
+
'type' => 'date'
|
| 49 |
+
));
|
| 50 |
+
|
| 51 |
+
$this->addColumn('last_run_at', array(
|
| 52 |
+
'header' => Mage::helper('mailplus')->__('Last run'),
|
| 53 |
+
'align' => 'left',
|
| 54 |
+
'index' => 'last_run_at',
|
| 55 |
+
'type' => 'date'
|
| 56 |
+
));
|
| 57 |
+
|
| 58 |
+
$this->addColumn('method', array(
|
| 59 |
+
'header' => Mage::helper('mailplus')->__('Method'),
|
| 60 |
+
'align' =>'left',
|
| 61 |
+
'index' => 'method',
|
| 62 |
+
'width' => '50px'
|
| 63 |
+
));
|
| 64 |
+
|
| 65 |
+
$this->addColumn('url', array(
|
| 66 |
+
'header' => Mage::helper('mailplus')->__('URL'),
|
| 67 |
+
'align' =>'left',
|
| 68 |
+
'index' => 'url'
|
| 69 |
+
));
|
| 70 |
+
|
| 71 |
+
$this->addColumn('tries', array(
|
| 72 |
+
'header' => Mage::helper('mailplus')->__('Tries'),
|
| 73 |
+
'align' =>'left',
|
| 74 |
+
'index' => 'tries',
|
| 75 |
+
'type=' => 'number',
|
| 76 |
+
'width' => '50px'
|
| 77 |
+
));
|
| 78 |
+
|
| 79 |
+
$this->addColumn('last_error', array(
|
| 80 |
+
'header' => Mage::helper('mailplus')->__('Last error'),
|
| 81 |
+
'align' =>'left',
|
| 82 |
+
'index' => 'last_error'
|
| 83 |
+
));
|
| 84 |
+
|
| 85 |
+
$this->addColumn('last_response', array(
|
| 86 |
+
'header' => Mage::helper('mailplus')->__('Last response'),
|
| 87 |
+
'align' =>'left',
|
| 88 |
+
'index' => 'last_response'
|
| 89 |
+
));
|
| 90 |
+
|
| 91 |
+
return parent::_prepareColumns();
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
public function getRowUrl($row)
|
| 95 |
+
{
|
| 96 |
+
return;
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
public function getGridUrl()
|
| 100 |
+
{
|
| 101 |
+
return $this->getUrl('*/*/grid', array('_current'=>true));
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
}
|
app/code/community/Techtwo/Mailplus/Block/Adminhtml/Syncstatus.php
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
class Techtwo_Mailplus_Block_Adminhtml_Syncstatus extends Mage_Adminhtml_Block_Widget_Grid_Container
|
| 18 |
+
{
|
| 19 |
+
public function __construct()
|
| 20 |
+
{
|
| 21 |
+
$this->_controller = 'adminhtml_syncstatus';
|
| 22 |
+
$this->_blockGroup = 'mailplus';
|
| 23 |
+
$this->_headerText = Mage::helper('mailplus')->__('MailPlus sync status');
|
| 24 |
+
|
| 25 |
+
parent::__construct();
|
| 26 |
+
|
| 27 |
+
$this->_removeButton('add');
|
| 28 |
+
$this->_addButton('reload', array(
|
| 29 |
+
'label' => Mage::helper('adminhtml')->__('Refresh'),
|
| 30 |
+
'onclick' => 'setLocation(window.location.href)',
|
| 31 |
+
), -1);
|
| 32 |
+
}
|
| 33 |
+
}
|
app/code/community/Techtwo/Mailplus/Block/Adminhtml/Syncstatus/Grid.php
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
class Techtwo_Mailplus_Block_Adminhtml_Syncstatus_Grid extends Mage_Adminhtml_Block_Widget_Grid
|
| 18 |
+
{
|
| 19 |
+
public function __construct() {
|
| 20 |
+
parent::__construct();
|
| 21 |
+
$this->setId('SyncstatusGrid');
|
| 22 |
+
$this->setFilterVisibility(false);
|
| 23 |
+
$this->setPagerVisibility(false);
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
protected function _prepareCollection()
|
| 27 |
+
{
|
| 28 |
+
/* @var $mailplus Techtwo_Mailplus_Helper_Data */
|
| 29 |
+
$mailplus = Mage::helper('mailplus');
|
| 30 |
+
$website = $mailplus->getWebsiteFromRequest();
|
| 31 |
+
|
| 32 |
+
$collection = new Varien_Data_Collection();
|
| 33 |
+
|
| 34 |
+
$data = new Varien_Object();
|
| 35 |
+
$data->setName($mailplus->__('Newsletter subscribers'));
|
| 36 |
+
$data->setCount($mailplus->getSyncCount($website->getId(), Techtwo_Mailplus_Model_Syncqueue::TYPE_SUBSCRIBER));
|
| 37 |
+
$data->setSynctype(Techtwo_Mailplus_Model_Syncqueue::TYPE_SUBSCRIBER);
|
| 38 |
+
$collection->addItem($data);
|
| 39 |
+
|
| 40 |
+
$data = new Varien_Object();
|
| 41 |
+
$data->setName($mailplus->__('Customers'));
|
| 42 |
+
$data->setCount($mailplus->getSyncCount($website->getId(), Techtwo_Mailplus_Model_Syncqueue::TYPE_CUSTOMER));
|
| 43 |
+
$data->setSynctype(Techtwo_Mailplus_Model_Syncqueue::TYPE_CUSTOMER);
|
| 44 |
+
$collection->addItem($data);
|
| 45 |
+
|
| 46 |
+
$data = new Varien_Object();
|
| 47 |
+
$data->setName($mailplus->__('Products'));
|
| 48 |
+
$data->setCount($mailplus->getSyncCount($website->getId(), Techtwo_Mailplus_Model_Syncqueue::TYPE_PRODUCT));
|
| 49 |
+
$data->setSynctype(Techtwo_Mailplus_Model_Syncqueue::TYPE_PRODUCT);
|
| 50 |
+
$collection->addItem($data);
|
| 51 |
+
|
| 52 |
+
$data = new Varien_Object();
|
| 53 |
+
$data->setName($mailplus->__('Orders'));
|
| 54 |
+
$data->setCount($mailplus->getSyncCount($website->getId(), Techtwo_Mailplus_Model_Syncqueue::TYPE_ORDER));
|
| 55 |
+
$data->setSynctype(Techtwo_Mailplus_Model_Syncqueue::TYPE_ORDER);
|
| 56 |
+
$collection->addItem($data);
|
| 57 |
+
|
| 58 |
+
$this->setCollection($collection);
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
protected function _prepareColumns()
|
| 62 |
+
{
|
| 63 |
+
/* @var $mailplus Techtwo_Mailplus_Helper_Data */
|
| 64 |
+
$mailplus = Mage::helper('mailplus');
|
| 65 |
+
$website = $mailplus->getWebsiteFromRequest();
|
| 66 |
+
|
| 67 |
+
$this->addColumn('name', array(
|
| 68 |
+
'header' => Mage::helper('mailplus')->__('Name'),
|
| 69 |
+
'align' =>'left',
|
| 70 |
+
'width' => '50px',
|
| 71 |
+
'index' => 'name'
|
| 72 |
+
));
|
| 73 |
+
|
| 74 |
+
$this->addColumn('count', array(
|
| 75 |
+
'header' => Mage::helper('mailplus')->__('Count'),
|
| 76 |
+
'align' =>'left',
|
| 77 |
+
'width' => '50px',
|
| 78 |
+
'index' => 'count'
|
| 79 |
+
));
|
| 80 |
+
|
| 81 |
+
$this->addColumn('action', array(
|
| 82 |
+
'header' => Mage::helper('mailplus')->__('Action'),
|
| 83 |
+
'width' => '50px',
|
| 84 |
+
'type' => 'action',
|
| 85 |
+
'getter' => 'getSynctype',
|
| 86 |
+
'actions' => array(
|
| 87 |
+
array(
|
| 88 |
+
'caption' => 'Sync',
|
| 89 |
+
'url' => array(
|
| 90 |
+
'base' => '*/*/sync',
|
| 91 |
+
'params' => array('website' => $website->getCode())
|
| 92 |
+
),
|
| 93 |
+
'field' => 'synctype'
|
| 94 |
+
)
|
| 95 |
+
)
|
| 96 |
+
));
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
return parent::_prepareColumns();
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
public function getGridUrl() {
|
| 104 |
+
return $this->getUrl('*/*/grid', array('_current'=>true));
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
}
|
app/code/community/Techtwo/Mailplus/Block/Adminhtml/Users.php
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
class Techtwo_Mailplus_Block_Adminhtml_Users extends Mage_Adminhtml_Block_Widget_Grid_Container
|
| 18 |
+
{
|
| 19 |
+
public function __construct()
|
| 20 |
+
{
|
| 21 |
+
$this->_controller = 'adminhtml_users';
|
| 22 |
+
$this->_blockGroup = 'mailplus';
|
| 23 |
+
$this->_headerText = Mage::helper('mailplus')->__('User manager');
|
| 24 |
+
parent::__construct();
|
| 25 |
+
|
| 26 |
+
if ( false) // not yet supported
|
| 27 |
+
{
|
| 28 |
+
$this->_addButton('add', array(
|
| 29 |
+
'label' => 'Add User',
|
| 30 |
+
//'onclick' => 'submitMyHooks(\'' . Mage::helper('adminhtml')->getUrl('mailplus/adminhtml_index/new') . '\')',
|
| 31 |
+
'class' => 'add'
|
| 32 |
+
));
|
| 33 |
+
}
|
| 34 |
+
else
|
| 35 |
+
$this->_removeButton('add');
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
$this->_addButton('import', array(
|
| 39 |
+
'label' => Mage::helper('mailplus')->__('Import users'),
|
| 40 |
+
'onclick' => "document.location.href='".Mage::getSingleton('adminhtml/url')->getUrl('*/*/import')."'",
|
| 41 |
+
'class' => 'add'
|
| 42 |
+
));
|
| 43 |
+
|
| 44 |
+
$this->_addButton('export', array(
|
| 45 |
+
'label' => Mage::helper('mailplus')->__('Export users'),
|
| 46 |
+
'onclick' => "document.location.href='".Mage::getSingleton('adminhtml/url')->getUrl('*/*/export')."'",
|
| 47 |
+
'class' => 'add'
|
| 48 |
+
));
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
/*
|
| 52 |
+
protected function _prepareLayout()
|
| 53 |
+
{
|
| 54 |
+
parent::_prepareLayout();
|
| 55 |
+
if(!$this->getRequest()->isXmlHttpRequest()){
|
| 56 |
+
$this->getLayout()->getBlock('head')->addItem('skin_js', 'mailplus/Mailplus.js');
|
| 57 |
+
}
|
| 58 |
+
}
|
| 59 |
+
*/
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
protected function getMaxImportFilesize()
|
| 63 |
+
{
|
| 64 |
+
return 7*1024*1024; // 7 mb
|
| 65 |
+
}
|
| 66 |
+
}
|
app/code/community/Techtwo/Mailplus/Block/Adminhtml/Users/Edit.php
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
class Techtwo_Mailplus_Block_Adminhtml_Users_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
|
| 18 |
+
{
|
| 19 |
+
|
| 20 |
+
public function __construct()
|
| 21 |
+
{
|
| 22 |
+
parent::__construct();
|
| 23 |
+
|
| 24 |
+
$this->_objectId = 'customer_id';
|
| 25 |
+
$this->_blockGroup = 'mailplus';
|
| 26 |
+
$this->_controller = 'adminhtml_users';
|
| 27 |
+
|
| 28 |
+
$this->_updateButton('save', 'label', Mage::helper('mailplus')->__('Save Item'));
|
| 29 |
+
$this->_updateButton('delete', 'label', Mage::helper('mailplus')->__('Delete Item'));
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
public function getHeaderText()
|
| 33 |
+
{
|
| 34 |
+
if (Mage::registry('mailplus_user_data') && Mage::registry('mailplus_user_data')->getId())
|
| 35 |
+
{
|
| 36 |
+
return $this->__('Edit user');
|
| 37 |
+
// return Mage::helper('mailplus')->__("Edit user '%s'", $this->htmlEscape(Mage::registry('mailplus_user_data')->getName()));
|
| 38 |
+
}
|
| 39 |
+
else
|
| 40 |
+
{
|
| 41 |
+
return Mage::helper('mailplus')->__('Add User');
|
| 42 |
+
}
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
}
|
| 46 |
+
?>
|
app/code/community/Techtwo/Mailplus/Block/Adminhtml/Users/Edit/Form.php
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
|
| 18 |
+
class Techtwo_Mailplus_Block_Adminhtml_Users_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
|
| 19 |
+
{
|
| 20 |
+
|
| 21 |
+
protected function _prepareForm()
|
| 22 |
+
{
|
| 23 |
+
$form = new Varien_Data_Form(array(
|
| 24 |
+
'id' => 'edit_form',
|
| 25 |
+
'action' => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'))),
|
| 26 |
+
'method' => 'post',
|
| 27 |
+
)
|
| 28 |
+
);
|
| 29 |
+
|
| 30 |
+
$form->setUseContainer(true);
|
| 31 |
+
$this->setForm($form);
|
| 32 |
+
return parent::_prepareForm();
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
}
|
app/code/community/Techtwo/Mailplus/Block/Adminhtml/Users/Edit/Tab/Form.php
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
class Techtwo_Mailplus_Block_Adminhtml_Users_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form
|
| 18 |
+
{
|
| 19 |
+
|
| 20 |
+
protected function _prepareForm()
|
| 21 |
+
{
|
| 22 |
+
$form = new Varien_Data_Form();
|
| 23 |
+
$this->setForm($form);
|
| 24 |
+
$fieldset = $form->addFieldset('mailplus_form', array('legend' => Mage::helper('mailplus')->__('Customer information')));
|
| 25 |
+
|
| 26 |
+
/*
|
| 27 |
+
$fieldset->addField('mailplus_id', 'label', array(
|
| 28 |
+
'label' => Mage::helper('mailplus')->__('Mailplus').' (<small>encrypted id</small>) : ',
|
| 29 |
+
'class' => 'entry',
|
| 30 |
+
'name' => 'mailplus_id',
|
| 31 |
+
));
|
| 32 |
+
*/
|
| 33 |
+
|
| 34 |
+
$fieldset->addField('customer_id', 'text', array(
|
| 35 |
+
'label' => Mage::helper('mailplus')->__('Customer'),
|
| 36 |
+
'class' => 'entry', // required-entry : blank is now used as anonymous
|
| 37 |
+
// 'required' => true,
|
| 38 |
+
'name' => 'customer_id',
|
| 39 |
+
));
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
/*
|
| 43 |
+
$fieldset->addField('enabled', 'select', array(
|
| 44 |
+
'label' => Mage::helper('mailplus')->__('Enabled'),
|
| 45 |
+
'class' => 'entry',
|
| 46 |
+
'required' => false,
|
| 47 |
+
'name' => 'enabled',
|
| 48 |
+
'values' => array(
|
| 49 |
+
array(
|
| 50 |
+
'value' => 0,
|
| 51 |
+
'label' => Mage::helper('mailplus')->__('No'),
|
| 52 |
+
),
|
| 53 |
+
array(
|
| 54 |
+
'value' => 1,
|
| 55 |
+
'label' => Mage::helper('mailplus')->__('Yes'),
|
| 56 |
+
),
|
| 57 |
+
),
|
| 58 |
+
));
|
| 59 |
+
*/
|
| 60 |
+
|
| 61 |
+
$fieldset->addField('is_test', 'select', array(
|
| 62 |
+
'label' => Mage::helper('mailplus')->__('Is test account'),
|
| 63 |
+
'class' => 'entry',
|
| 64 |
+
'required' => false,
|
| 65 |
+
'name' => 'is_test',
|
| 66 |
+
'values' => array(
|
| 67 |
+
array(
|
| 68 |
+
'value' => 0,
|
| 69 |
+
'label' => Mage::helper('mailplus')->__('No'),
|
| 70 |
+
),
|
| 71 |
+
array(
|
| 72 |
+
'value' => 1,
|
| 73 |
+
'label' => Mage::helper('mailplus')->__('Yes'),
|
| 74 |
+
),
|
| 75 |
+
),
|
| 76 |
+
));
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
/*
|
| 80 |
+
$fieldset->addField('status', 'select', array(
|
| 81 |
+
'label' => Mage::helper('mailplus')->__('Status'),
|
| 82 |
+
'name' => 'status',
|
| 83 |
+
'values' => array(
|
| 84 |
+
array(
|
| 85 |
+
'value' => 1,
|
| 86 |
+
'label' => Mage::helper('mailplus')->__('Active'),
|
| 87 |
+
),
|
| 88 |
+
array(
|
| 89 |
+
'value' => 0,
|
| 90 |
+
'label' => Mage::helper('mailplus')->__('Inactive'),
|
| 91 |
+
),
|
| 92 |
+
),
|
| 93 |
+
));
|
| 94 |
+
|
| 95 |
+
$fieldset->addField('content', 'editor', array(
|
| 96 |
+
'name' => 'content',
|
| 97 |
+
'label' => Mage::helper('mailplus')->__('Content'),
|
| 98 |
+
'title' => Mage::helper('mailplus')->__('Content'),
|
| 99 |
+
'style' => 'width:98%; height:400px;',
|
| 100 |
+
'wysiwyg' => false,
|
| 101 |
+
'required' => true,
|
| 102 |
+
));
|
| 103 |
+
*/
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
if (Mage::getSingleton('adminhtml/session')->getMailplusUserData())
|
| 107 |
+
{
|
| 108 |
+
$form->setValues(Mage::getSingleton('adminhtml/session')->getMailplusUserData());
|
| 109 |
+
Mage::getSingleton('adminhtml/session')->setMailplusUserData(null);
|
| 110 |
+
}
|
| 111 |
+
elseif (Mage::registry('mailplus_user_data'))
|
| 112 |
+
{
|
| 113 |
+
$form->setValues(Mage::registry('mailplus_user_data')->getData());
|
| 114 |
+
// print_r(Mage::registry('mailplus_user_data')->getData());
|
| 115 |
+
}
|
| 116 |
+
return parent::_prepareForm();
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
}
|
app/code/community/Techtwo/Mailplus/Block/Adminhtml/Users/Edit/Tabs.php
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
class Techtwo_Mailplus_Block_Adminhtml_Users_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
|
| 18 |
+
{
|
| 19 |
+
|
| 20 |
+
public function __construct()
|
| 21 |
+
{
|
| 22 |
+
parent::__construct();
|
| 23 |
+
$this->setId('mailplus_tabs');
|
| 24 |
+
$this->setDestElementId('edit_form');
|
| 25 |
+
$this->setTitle(Mage::helper('mailplus')->__('Customer Information'));
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
protected function _beforeToHtml()
|
| 29 |
+
{
|
| 30 |
+
$this->addTab('form_section', array(
|
| 31 |
+
'label' => Mage::helper('mailplus')->__('Customer Information'),
|
| 32 |
+
'title' => Mage::helper('mailplus')->__('Customer Information'),
|
| 33 |
+
'content' => $this->getLayout()->createBlock('mailplus/adminhtml_users_edit_tab_form')->toHtml(),
|
| 34 |
+
));
|
| 35 |
+
|
| 36 |
+
return parent::_beforeToHtml();
|
| 37 |
+
}
|
| 38 |
+
}
|
app/code/community/Techtwo/Mailplus/Block/Adminhtml/Users/Grid.php
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
class Techtwo_Mailplus_Block_Adminhtml_Users_Grid extends Mage_Adminhtml_Block_Widget_Grid
|
| 18 |
+
{
|
| 19 |
+
public function __construct()
|
| 20 |
+
{
|
| 21 |
+
parent::__construct();
|
| 22 |
+
$this->setId('usersGrid');
|
| 23 |
+
// This is the primary key of the database
|
| 24 |
+
$this->setDefaultSort('user_id');
|
| 25 |
+
$this->setDefaultDir('ASC');
|
| 26 |
+
$this->setSaveParametersInSession(true);
|
| 27 |
+
$this->setTemplate('mailplus/users/grid.phtml');
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
protected function _prepareCollection()
|
| 31 |
+
{
|
| 32 |
+
$collection = Mage::getModel('mailplus/user')->getCollection();
|
| 33 |
+
//$collection = Mage::helper('mailplus')->joinEavTablesIntoCollection($collection, 'customer_id', 'customer');
|
| 34 |
+
/* @var $collection Techtwo_Mailplus_Model_Mysql4_User_Collection */
|
| 35 |
+
$this->setCollection($collection);
|
| 36 |
+
|
| 37 |
+
return parent::_prepareCollection();
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
protected function _prepareMassaction()
|
| 41 |
+
{
|
| 42 |
+
$this->setMassactionIdField('user_id');
|
| 43 |
+
$this->getMassactionBlock()->setFormFieldName('mailplus_user_mass');
|
| 44 |
+
|
| 45 |
+
$this->getMassactionBlock()->addItem('delete', array(
|
| 46 |
+
'label' => Mage::helper('mailplus')->__('Delete'),
|
| 47 |
+
'url' => $this->getUrl('*/*/massDelete'),
|
| 48 |
+
'confirm' => Mage::helper('mailplus')->__('Are you sure you want to delete these contacts?')
|
| 49 |
+
));
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
protected function _prepareColumns()
|
| 53 |
+
{
|
| 54 |
+
$this->addColumn('user_id', array(
|
| 55 |
+
'header' => Mage::helper('mailplus')->__('External id'),
|
| 56 |
+
'align' =>'right',
|
| 57 |
+
'width' => '50px',
|
| 58 |
+
'index' => 'user_id',
|
| 59 |
+
'type' => 'range'
|
| 60 |
+
));
|
| 61 |
+
|
| 62 |
+
$this->addColumn('customer_id', array(
|
| 63 |
+
'header' => Mage::helper('mailplus')->__('Customer id'),
|
| 64 |
+
'align' =>'right',
|
| 65 |
+
'width' => '50px',
|
| 66 |
+
'index' => 'customer_id',
|
| 67 |
+
'type' => 'range'
|
| 68 |
+
));
|
| 69 |
+
|
| 70 |
+
$this->addColumn('firstname', array(
|
| 71 |
+
'header' => Mage::helper('customer')->__('Firstname'),
|
| 72 |
+
'index' => 'firstname'
|
| 73 |
+
));
|
| 74 |
+
|
| 75 |
+
$this->addColumn('lastname', array(
|
| 76 |
+
'header' => Mage::helper('customer')->__('Lastname'),
|
| 77 |
+
'index' => 'lastname'
|
| 78 |
+
));
|
| 79 |
+
|
| 80 |
+
$this->addColumn('email', array(
|
| 81 |
+
'header' => Mage::helper('customer')->__('Email'),
|
| 82 |
+
'index' => 'email'
|
| 83 |
+
));
|
| 84 |
+
/*
|
| 85 |
+
$this->addColumn('mailplus_id', array(
|
| 86 |
+
'header' => 'Mailplus id',
|
| 87 |
+
'index' => 'mailplus_id',
|
| 88 |
+
'width' => '160px'
|
| 89 |
+
));
|
| 90 |
+
*/
|
| 91 |
+
|
| 92 |
+
$this->addColumn('enabled', array(
|
| 93 |
+
'header' => Mage::helper('mailplus')->__('Enabled'),
|
| 94 |
+
'align' =>'center',
|
| 95 |
+
'type' => 'bool',
|
| 96 |
+
'index' => 'enabled',
|
| 97 |
+
'width' => '50px',
|
| 98 |
+
));
|
| 99 |
+
|
| 100 |
+
if (!Mage::app()->isSingleStoreMode()) {
|
| 101 |
+
|
| 102 |
+
/* @var $systemStore Mage_Adminhtml_Model_System_Store */
|
| 103 |
+
$systemStore = Mage::getSingleton('adminhtml/system_store');
|
| 104 |
+
|
| 105 |
+
$this->addColumn('store_id', array(
|
| 106 |
+
'header' => Mage::helper('customer')->__('Store'),
|
| 107 |
+
'align' => 'center',
|
| 108 |
+
'width' => '100px',
|
| 109 |
+
'type' => 'options',
|
| 110 |
+
'options' => $systemStore->getStoreOptionHash(TRUE), // getWebsiteOptionHash(TRUE),
|
| 111 |
+
'index' => 'store_id',
|
| 112 |
+
));
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
/*
|
| 116 |
+
$this->addColumn('content', array(
|
| 117 |
+
'header' => Mage::helper('<module>')->__('Item Content'),
|
| 118 |
+
'width' => '150px',
|
| 119 |
+
'index' => 'content',
|
| 120 |
+
));
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
$this->addColumn('created_time', array(
|
| 124 |
+
'header' => Mage::helper('<module>')->__('Creation Time'),
|
| 125 |
+
'align' => 'left',
|
| 126 |
+
'width' => '120px',
|
| 127 |
+
'type' => 'date',
|
| 128 |
+
'default' => '--',
|
| 129 |
+
'index' => 'created_time',
|
| 130 |
+
));
|
| 131 |
+
|
| 132 |
+
$this->addColumn('update_time', array(
|
| 133 |
+
'header' => Mage::helper('<module>')->__('Update Time'),
|
| 134 |
+
'align' => 'left',
|
| 135 |
+
'width' => '120px',
|
| 136 |
+
'type' => 'date',
|
| 137 |
+
'default' => '--',
|
| 138 |
+
'index' => 'update_time',
|
| 139 |
+
));
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
$this->addColumn('status', array(
|
| 143 |
+
|
| 144 |
+
'header' => Mage::helper('<module>')->__('Status'),
|
| 145 |
+
'align' => 'left',
|
| 146 |
+
'width' => '80px',
|
| 147 |
+
'index' => 'status',
|
| 148 |
+
'type' => 'options',
|
| 149 |
+
'options' => array(
|
| 150 |
+
1 => 'Active',
|
| 151 |
+
0 => 'Inactive',
|
| 152 |
+
),
|
| 153 |
+
));
|
| 154 |
+
*/
|
| 155 |
+
|
| 156 |
+
return parent::_prepareColumns();
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
public function getRowUrl($row)
|
| 160 |
+
{
|
| 161 |
+
return $this->getUrl('*/*/edit', array('id' => $row->getUserId()));
|
| 162 |
+
}
|
| 163 |
+
}
|
app/code/community/Techtwo/Mailplus/Client/Contact/Permission.php
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
class Techtwo_Mailplus_Client_Contact_Permission
|
| 18 |
+
{
|
| 19 |
+
protected $_bit;
|
| 20 |
+
protected $_enabled;
|
| 21 |
+
protected $_description;
|
| 22 |
+
|
| 23 |
+
public function getBit()
|
| 24 |
+
{
|
| 25 |
+
return $this->_bit;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
public function setBit($bit)
|
| 29 |
+
{
|
| 30 |
+
$this->_bit = (int)$bit;
|
| 31 |
+
return $this;
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
public function getEnabled()
|
| 35 |
+
{
|
| 36 |
+
return $this->_enabled;
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
public function setEnabled($enabled)
|
| 40 |
+
{
|
| 41 |
+
$this->_enabled = (bool)$enabled;
|
| 42 |
+
return $this;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
public function isEnabled()
|
| 46 |
+
{
|
| 47 |
+
return (bool) $this->_enabled;
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
public function getDescription()
|
| 51 |
+
{
|
| 52 |
+
return $this->_description;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
public function setDescription($description)
|
| 56 |
+
{
|
| 57 |
+
$this->_description = $description;
|
| 58 |
+
return $this;
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
public function toMailPlusData()
|
| 62 |
+
{
|
| 63 |
+
$aux = array(
|
| 64 |
+
'bit' => $this->getBit(),
|
| 65 |
+
'enabled' => $this->getEnabled(),
|
| 66 |
+
'description' => $this->getDescription()
|
| 67 |
+
);
|
| 68 |
+
|
| 69 |
+
if ( !$aux['description'] )
|
| 70 |
+
unset($aux['description']);
|
| 71 |
+
|
| 72 |
+
return $aux;
|
| 73 |
+
}
|
| 74 |
+
}
|
app/code/community/Techtwo/Mailplus/Client/Contact/Property.php
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
class Techtwo_Mailplus_Client_Contact_Property
|
| 18 |
+
{
|
| 19 |
+
protected $_name;
|
| 20 |
+
protected $_description;
|
| 21 |
+
protected $_type;
|
| 22 |
+
|
| 23 |
+
public function setData( array $data )
|
| 24 |
+
{
|
| 25 |
+
if ( array_key_exists('name', $data))
|
| 26 |
+
$this->_name = $data['name'];
|
| 27 |
+
if ( array_key_exists('description', $data))
|
| 28 |
+
$this->_description = $data['description'];
|
| 29 |
+
if ( array_key_exists('type', $data))
|
| 30 |
+
$this->_type = $data['type'];
|
| 31 |
+
|
| 32 |
+
return $this;
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
public function debug()
|
| 36 |
+
{
|
| 37 |
+
return array(
|
| 38 |
+
'name' => $this->_name,
|
| 39 |
+
'description' => $this->_description,
|
| 40 |
+
'type' => $this->_type,
|
| 41 |
+
);
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
public function getName()
|
| 45 |
+
{
|
| 46 |
+
return $this->_name;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
public function setName($name)
|
| 50 |
+
{
|
| 51 |
+
$this->_name = $name;
|
| 52 |
+
return $this;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
public function getDescription()
|
| 56 |
+
{
|
| 57 |
+
return $this->_description;
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
public function setDescription($description)
|
| 61 |
+
{
|
| 62 |
+
$this->_description = $description;
|
| 63 |
+
return $this;
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
public function getType()
|
| 67 |
+
{
|
| 68 |
+
return $this->_type;
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
public function setType($type)
|
| 72 |
+
{
|
| 73 |
+
$this->_type = $type;
|
| 74 |
+
return $this;
|
| 75 |
+
}
|
| 76 |
+
}
|
app/code/community/Techtwo/Mailplus/Client/Error.php
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
class Techtwo_Mailplus_Client_Error
|
| 18 |
+
{
|
| 19 |
+
protected $_message;
|
| 20 |
+
protected $_type;
|
| 21 |
+
protected $_code;
|
| 22 |
+
|
| 23 |
+
public function debug()
|
| 24 |
+
{
|
| 25 |
+
return array(
|
| 26 |
+
'message' => $this->_message,
|
| 27 |
+
'type' => $this->_type,
|
| 28 |
+
'code' => $this->_code,
|
| 29 |
+
);
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
public function setMessage( $value )
|
| 33 |
+
{
|
| 34 |
+
$this->_message = $value;
|
| 35 |
+
return $this;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
public function getMessage()
|
| 39 |
+
{
|
| 40 |
+
return $this->_message;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
public function setType( $value )
|
| 44 |
+
{
|
| 45 |
+
$this->_type = $value;
|
| 46 |
+
return $this;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
public function getType()
|
| 50 |
+
{
|
| 51 |
+
return $this->_type;
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
public function setCode( $value )
|
| 55 |
+
{
|
| 56 |
+
$this->_code = $value;
|
| 57 |
+
return $this;
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
public function getCode()
|
| 61 |
+
{
|
| 62 |
+
return $this->_code;
|
| 63 |
+
}
|
| 64 |
+
}
|
app/code/community/Techtwo/Mailplus/Client/Exception.php
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
class Techtwo_Mailplus_Client_Exception extends Exception
|
| 18 |
+
{
|
| 19 |
+
protected $_type;
|
| 20 |
+
|
| 21 |
+
public function getType()
|
| 22 |
+
{
|
| 23 |
+
return $this->_type;
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
public function setType($type)
|
| 27 |
+
{
|
| 28 |
+
$this->_type = $type;
|
| 29 |
+
return $this;
|
| 30 |
+
}
|
| 31 |
+
}
|
app/code/community/Techtwo/Mailplus/Client/Rest.php
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
class Techtwo_Mailplus_Client_Rest extends Zend_Rest_Client
|
| 18 |
+
{
|
| 19 |
+
const REST_LOG_FILE = 'mailplus_rest.log';
|
| 20 |
+
|
| 21 |
+
private $_siteId = null;
|
| 22 |
+
|
| 23 |
+
/**
|
| 24 |
+
* Create a log of the request and response call
|
| 25 |
+
*
|
| 26 |
+
* @param null $title
|
| 27 |
+
* @return Techtwo_Mailplus_Client_Rest
|
| 28 |
+
*/
|
| 29 |
+
public function log($title=NULL)
|
| 30 |
+
{
|
| 31 |
+
if ( Mage::getStoreConfigFlag('mailplus/debug/log_enabled') )
|
| 32 |
+
{
|
| 33 |
+
$log = '';
|
| 34 |
+
if ($title)
|
| 35 |
+
{
|
| 36 |
+
$log .= $title.PHP_EOL;
|
| 37 |
+
$log .= '--------------------------'.PHP_EOL;
|
| 38 |
+
}
|
| 39 |
+
$log .= 'REQUEST: '.PHP_EOL.PHP_EOL;
|
| 40 |
+
$log .= $this->getHttpClient()->getLastRequest();
|
| 41 |
+
$log .= PHP_EOL.'--------------------------'.PHP_EOL;
|
| 42 |
+
$log .= 'RESPONSE: '.PHP_EOL;
|
| 43 |
+
$log .= print_r($this->getHttpClient()->getLastResponse(), TRUE).PHP_EOL;
|
| 44 |
+
|
| 45 |
+
Mage::log($log, Zend_Log::DEBUG, self::REST_LOG_FILE);
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
return $this;
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
/**
|
| 52 |
+
* Assumes all status codes 200 are valid
|
| 53 |
+
*
|
| 54 |
+
* @return NULL|Techtwo_Mailplus_Client_Error
|
| 55 |
+
*/
|
| 56 |
+
public function getError()
|
| 57 |
+
{
|
| 58 |
+
$response = $this->getHttpClient()->getLastResponse();
|
| 59 |
+
if ($response == NULL) {
|
| 60 |
+
return NULL;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
$status = $response->getStatus();
|
| 65 |
+
if ( $response->isSuccessful() /*$status >= 200 && $status < 299*/ )
|
| 66 |
+
return NULL;
|
| 67 |
+
|
| 68 |
+
$content_type = $response->getHeader('content-type'); // zend always use lower case
|
| 69 |
+
|
| 70 |
+
$error = new Techtwo_Mailplus_Client_Error();
|
| 71 |
+
$error->setCode($status);
|
| 72 |
+
|
| 73 |
+
if ( 'application/xml' === $content_type )
|
| 74 |
+
{
|
| 75 |
+
$xml = simplexml_load_string($response->getBody());
|
| 76 |
+
$error
|
| 77 |
+
->setMessage( (string) $xml->message )
|
| 78 |
+
->setType( (string) $xml->errorType );
|
| 79 |
+
}
|
| 80 |
+
elseif ( 'application/json' === $content_type )
|
| 81 |
+
{
|
| 82 |
+
$json = json_decode($response->getBody());
|
| 83 |
+
$error
|
| 84 |
+
->setMessage( (string) $json->message )
|
| 85 |
+
->setType( (string) $json->errorType );
|
| 86 |
+
}
|
| 87 |
+
else
|
| 88 |
+
{
|
| 89 |
+
$error
|
| 90 |
+
->setMessage( 'Unknown error occurred' )
|
| 91 |
+
->setType( NULL );
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
if ( '' == $error->getMessage() )
|
| 95 |
+
$error->setMessage( 'Unknown error occurred' );
|
| 96 |
+
|
| 97 |
+
return $error;
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
public function setSiteId($siteId) {
|
| 101 |
+
$this->_siteId = $siteId;
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
public function getSiteId() {
|
| 105 |
+
return $this->_siteId;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
}
|
app/code/community/Techtwo/Mailplus/Helper/Config.php
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
class Techtwo_Mailplus_Helper_Config extends Mage_Core_Helper_Abstract {
|
| 18 |
+
public static $_MAPPING_CONFIGPATH = "mailplusmapping/mapping/";
|
| 19 |
+
public static $_MAPPING_CACHE_KEY = "magento-mailplus-mapping";
|
| 20 |
+
|
| 21 |
+
public function getMappingCacheKey($siteId) {
|
| 22 |
+
return Techtwo_Mailplus_Helper_Config::$_MAPPING_CACHE_KEY . '-' . $siteId;
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
public static $_defaultMapping = array(
|
| 26 |
+
'email' => 'email',
|
| 27 |
+
'firstname' => 'firstName',
|
| 28 |
+
'middlename'=> 'infix',
|
| 29 |
+
'lastname' => 'lastName',
|
| 30 |
+
'gender' => 'gender',
|
| 31 |
+
'dob' => 'birthday',
|
| 32 |
+
'group_id' => 'customerType',
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
'company' => 'organisation',
|
| 36 |
+
'city' => 'city',
|
| 37 |
+
'housenumber' => 'houseNumber',
|
| 38 |
+
'telephone' => 'phoneNumber',
|
| 39 |
+
'street' => 'street',
|
| 40 |
+
'street-line-1' => 'street',
|
| 41 |
+
'street-line-2' => 'houseNumber',
|
| 42 |
+
'postcode' => 'postalCode',
|
| 43 |
+
'country' => 'country',
|
| 44 |
+
|
| 45 |
+
'storedescription' => 'taal',
|
| 46 |
+
'firstpurchasedate' => 'firstPurchaseDate',
|
| 47 |
+
'lastpurchasedate' => 'lastPurchaseDate'
|
| 48 |
+
);
|
| 49 |
+
|
| 50 |
+
public function getCustomerAttributes() {
|
| 51 |
+
$attributes = Mage::getModel('customer/customer')->getAttributes();
|
| 52 |
+
$mapping = array();
|
| 53 |
+
foreach ($attributes as $attr) {
|
| 54 |
+
if ($attr->getIsVisible() && $attr->getFrontendInput() !== 'hidden') {
|
| 55 |
+
$mappingId = $attr->getAttributeCode();
|
| 56 |
+
$mapping[$mappingId] = $attr;
|
| 57 |
+
}
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
/* Dummy attribute for the storedescription (website-stroregroup-store) */
|
| 61 |
+
$storedescription = new Mage_Customer_Model_Attribute();
|
| 62 |
+
$storedescription->setAttributeCode('storedescription');
|
| 63 |
+
$storedescription->setFrontendLabel($this->__('Storeview description'));
|
| 64 |
+
$storedescription->setIsVisible(true);
|
| 65 |
+
$mapping[$storedescription->getAttributeCode()] = $storedescription;
|
| 66 |
+
|
| 67 |
+
/* Dummy attribute for the first purchase date */
|
| 68 |
+
$firstpurchasedate = new Mage_Customer_Model_Attribute();
|
| 69 |
+
$firstpurchasedate->setAttributeCode('firstpurchasedate');
|
| 70 |
+
$firstpurchasedate->setFrontendLabel($this->__('First purchase date'));
|
| 71 |
+
$firstpurchasedate->setIsVisible(true);
|
| 72 |
+
$mapping[$firstpurchasedate->getAttributeCode()] = $firstpurchasedate;
|
| 73 |
+
|
| 74 |
+
/* Dummy attribute for the last purchase date */
|
| 75 |
+
$lastpurchasedate = new Mage_Customer_Model_Attribute();
|
| 76 |
+
$lastpurchasedate->setAttributeCode('lastpurchasedate');
|
| 77 |
+
$lastpurchasedate->setFrontendLabel($this->__('Last purchase date'));
|
| 78 |
+
$lastpurchasedate->setIsVisible(true);
|
| 79 |
+
$mapping[$lastpurchasedate->getAttributeCode()] = $lastpurchasedate;
|
| 80 |
+
|
| 81 |
+
return $mapping;
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
public function getAddressAttributes() {
|
| 85 |
+
$customerAttrs = $this->getCustomerAttributes();
|
| 86 |
+
|
| 87 |
+
$attributes = Mage::getModel('customer/address')->getAttributes();
|
| 88 |
+
|
| 89 |
+
foreach ($attributes as $attr) {
|
| 90 |
+
if ($attr->getIsVisible() && $attr->getFrontendInput() !== 'hidden') {
|
| 91 |
+
$mappingId = $attr->getAttributeCode();
|
| 92 |
+
// Only add them if they do not exist for a customer
|
| 93 |
+
if (!array_key_exists($mappingId, $customerAttrs)) {
|
| 94 |
+
$mapping[$mappingId] = $attr;
|
| 95 |
+
}
|
| 96 |
+
}
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
return $mapping;
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
/**
|
| 103 |
+
* Retrieves mapping
|
| 104 |
+
*
|
| 105 |
+
* Note for some fields:
|
| 106 |
+
* housenumber is not an magento option. It's set as an street array. So the second you should use as housenumber
|
| 107 |
+
* country is not an magento option, note you must set it yourselves since country_id!
|
| 108 |
+
*
|
| 109 |
+
*/
|
| 110 |
+
public function getMapping($websiteId)
|
| 111 |
+
{
|
| 112 |
+
$cache = Mage::app()->getCache();
|
| 113 |
+
|
| 114 |
+
$mappingData = $cache->load($this->getMappingCacheKey($websiteId));
|
| 115 |
+
if ($mappingData) {
|
| 116 |
+
$mapping = unserialize($mappingData);
|
| 117 |
+
|
| 118 |
+
if ($mapping) {
|
| 119 |
+
return $mapping;
|
| 120 |
+
}
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
$site = Mage::app()->getWebsite($websiteId);
|
| 124 |
+
|
| 125 |
+
$fieldsToMap = $this->getAddressAttributes();
|
| 126 |
+
$fieldsToMap = array_merge($fieldsToMap, $this->getCustomerAttributes());
|
| 127 |
+
|
| 128 |
+
$mapping = array();
|
| 129 |
+
|
| 130 |
+
foreach($fieldsToMap as $attr) {
|
| 131 |
+
if ($attr->getFrontendInput() === 'multiline') {
|
| 132 |
+
for ($i = 1; $i <= $attr->getMultilineCount(); $i++) {
|
| 133 |
+
$attrCode = $attr->getAttributeCode() . '-line-' . $i;
|
| 134 |
+
$mailplusProperty = $this->getMappingForAttributeCode($site, $attrCode);
|
| 135 |
+
if ($mailplusProperty) {
|
| 136 |
+
$mapping[$attrCode] = $mailplusProperty;
|
| 137 |
+
};
|
| 138 |
+
}
|
| 139 |
+
} else {
|
| 140 |
+
$attrCode = $attr->getAttributeCode();
|
| 141 |
+
$mailplusProperty = $this->getMappingForAttributeCode($site, $attrCode);
|
| 142 |
+
if ($mailplusProperty) {
|
| 143 |
+
$mapping[$attrCode] = $mailplusProperty;
|
| 144 |
+
};
|
| 145 |
+
}
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
$cache->save(serialize($mapping), $this->getMappingCacheKey($websiteId), array("mailplus-cache"), NULL);
|
| 149 |
+
|
| 150 |
+
return $mapping;
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
/**
|
| 154 |
+
* Retrieves mapping for an attributeCode
|
| 155 |
+
*
|
| 156 |
+
* This will get the mapping from the saved configuration. If the mapping configuration
|
| 157 |
+
* has not been saved yet, default values will be used
|
| 158 |
+
*
|
| 159 |
+
*/
|
| 160 |
+
|
| 161 |
+
public function getMappingForAttributeCode($site, $mappingId) {
|
| 162 |
+
$value = $site->getConfig(Techtwo_Mailplus_Helper_Config::$_MAPPING_CONFIGPATH . $mappingId);
|
| 163 |
+
|
| 164 |
+
if (!$value && !$site->getConfig(Techtwo_Mailplus_Helper_Config::$_MAPPING_CONFIGPATH . 'savedonce')) {
|
| 165 |
+
if (isset(Techtwo_Mailplus_Helper_Config::$_defaultMapping[$mappingId])) {
|
| 166 |
+
$value = Techtwo_Mailplus_Helper_Config::$_defaultMapping[$mappingId];
|
| 167 |
+
}
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
return $value;
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
public function syncActiveForSite($siteId) {
|
| 174 |
+
return (Mage::app()->getWebsite($siteId)->getConfig('mailplus/general/active') == 1);
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
public function syncActiveForStore($storeId) {
|
| 178 |
+
return (Mage::getStoreConfig('mailplus/general/active', $storeId) == 1);
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
public function contactSyncAllowed($siteId) {
|
| 182 |
+
$site = Mage::app()->getWebsite($siteId);
|
| 183 |
+
return ($site->getConfig('mailplus/general/synchronize') == 'all');
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
public function getProductSpecGroup($siteId) {
|
| 187 |
+
$site = Mage::app()->getWebsite($siteId);
|
| 188 |
+
$groupName = $site->getConfig('mailplus/syncsettings/productspecs');
|
| 189 |
+
if ($groupName == '')
|
| 190 |
+
return NULL;
|
| 191 |
+
return $groupName;
|
| 192 |
+
}
|
| 193 |
+
}
|
app/code/community/Techtwo/Mailplus/Helper/Cron.php
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
class Techtwo_Mailplus_Helper_Cron extends Mage_Core_Helper_Abstract
|
| 18 |
+
{
|
| 19 |
+
const OFTEN_START = 'cron_often_start';
|
| 20 |
+
const OFTEN_END = 'cron_often_end';
|
| 21 |
+
const HOURLY_START = 'cron_hourly_start';
|
| 22 |
+
const HOURLY_END = 'cron_hourly_end';
|
| 23 |
+
|
| 24 |
+
protected $_logHdl;
|
| 25 |
+
protected $_log_prefix;
|
| 26 |
+
|
| 27 |
+
public function setLogHandle($logHdl)
|
| 28 |
+
{
|
| 29 |
+
$this->_logHdl = $logHdl;
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
public function setLogPrefix($prefix)
|
| 33 |
+
{
|
| 34 |
+
$this->_log_prefix = $prefix;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
public function eventLog( $str )
|
| 38 |
+
{
|
| 39 |
+
if ($this->_logHdl)
|
| 40 |
+
return fwrite( $this->_logHdl, $this->_log_prefix.$str.PHP_EOL );
|
| 41 |
+
return false;
|
| 42 |
+
}
|
| 43 |
+
}
|
app/code/community/Techtwo/Mailplus/Helper/Data.php
ADDED
|
@@ -0,0 +1,376 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
class Techtwo_Mailplus_Helper_Data extends Mage_Core_Helper_Abstract
|
| 18 |
+
{
|
| 19 |
+
const PRODUCT_TYPE_ECOM = 'ecomm';
|
| 20 |
+
const PRODUCT_TYPE_ECOM_PRO = 'ecomm_pro';
|
| 21 |
+
const PRODUCT_TYPE_ECOM_ENTERPRISE = 'ecomm_enterprise';
|
| 22 |
+
|
| 23 |
+
const MAPPING_ACCOUNT = 'account';
|
| 24 |
+
const MAPPING_ADDRESS = 'address';
|
| 25 |
+
|
| 26 |
+
const ORDERS_CACHE_SYNCHRONIZE_KEY = 'techtwo_mailplus_model_orders-synchronize';
|
| 27 |
+
const USERS_CACHE_SYNCHRONIZE_KEY = 'techtwo_mailplus_model_user-synchronize';
|
| 28 |
+
const PRODUCTS_CACHE_SYNCHRONIZE_KEY = 'techtwo_mailplus_model_product-synchronize';
|
| 29 |
+
|
| 30 |
+
const SMALL_IMAGE_MAX = 145;
|
| 31 |
+
const LARGE_IMAGE_MAX = 185;
|
| 32 |
+
|
| 33 |
+
const NL_ZIPCODE_REGEXP = '/^[1-9][0-9]{3}[\s]?[A-Za-z]{2}$/i';
|
| 34 |
+
const IS_MULTILINE_REGEXP = '/^(.+)-line-(\d+)$/i';
|
| 35 |
+
|
| 36 |
+
public function getCacheFile($cacheType) {
|
| 37 |
+
$file = Mage::getBaseDir('var').DIRECTORY_SEPARATOR.'cache'.DS.$cacheType.'.cache';
|
| 38 |
+
return $file;
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
/**
|
| 43 |
+
* Check if module is active
|
| 44 |
+
* @return bool
|
| 45 |
+
*/
|
| 46 |
+
public function isEnabled()
|
| 47 |
+
{
|
| 48 |
+
return TRUE === Mage::getConfig()->getModuleConfig('Techtwo_Mailplus')->is('active', 'true') && '1' === Mage::getStoreConfig('mailplus/general/active');
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
public function isSynchronizeContactsAllowed( $store_id=NULL )
|
| 52 |
+
{
|
| 53 |
+
return 'all' === Mage::getStoreConfig('mailplus/general/synchronize', $store_id);
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
public function isSynchronizeProductsAllowed( $store_id=NULL )
|
| 57 |
+
{
|
| 58 |
+
return TRUE; // you can't turn it off yet
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
/**
|
| 62 |
+
* This assumes that the foreign key is the entity id of the eav table.
|
| 63 |
+
* $collection is a collection object of a flat table.
|
| 64 |
+
* $mainTableForeignKey is the name of the foreign key to the eav table.
|
| 65 |
+
* $eavType is the type of entity (the entity_type_code in eav_entity_type)
|
| 66 |
+
*
|
| 67 |
+
* @url http://codemagento.com/2011/03/joining-an-eav-table-to-flat-table/
|
| 68 |
+
*/
|
| 69 |
+
public function joinEavTablesIntoCollection($collection, $mainTableForeignKey, $eavType)
|
| 70 |
+
{
|
| 71 |
+
$entityType = Mage::getModel('eav/entity_type')->loadByCode($eavType);
|
| 72 |
+
$attributes = $entityType->getAttributeCollection();
|
| 73 |
+
$entityTable = $collection->getTable($entityType->getEntityTable());
|
| 74 |
+
|
| 75 |
+
//Use an incremented index to make sure all of the aliases for the eav attribute tables are unique.
|
| 76 |
+
$index = 1;
|
| 77 |
+
foreach ($attributes->getItems() as $attribute)
|
| 78 |
+
{
|
| 79 |
+
$alias = 'table' . $index;
|
| 80 |
+
if ($attribute->getBackendType() != 'static')
|
| 81 |
+
{
|
| 82 |
+
$table = $entityTable . '_' . $attribute->getBackendType();
|
| 83 |
+
$field = $alias . '.value';
|
| 84 |
+
$collection->getSelect()
|
| 85 |
+
->joinLeft(
|
| 86 |
+
array($alias => $table),
|
| 87 |
+
'main_table.' . $mainTableForeignKey . ' = ' . $alias . '.entity_id and ' . $alias . '.attribute_id = ' . $attribute->getAttributeId(),
|
| 88 |
+
array($attribute->getAttributeCode() => $field)
|
| 89 |
+
);
|
| 90 |
+
}
|
| 91 |
+
$index++;
|
| 92 |
+
}
|
| 93 |
+
//Join in all of the static attributes by joining the base entity table.
|
| 94 |
+
$collection->getSelect()->joinLeft($entityTable, 'main_table.' . $mainTableForeignKey . ' = ' . $entityTable . '.entity_id');
|
| 95 |
+
|
| 96 |
+
return $collection;
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
protected $_genderOptions;
|
| 100 |
+
|
| 101 |
+
public function getMagentoGenderMaleId( )
|
| 102 |
+
{
|
| 103 |
+
$this->_genderHelper();
|
| 104 |
+
return $this->_genderOptions['male'];
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
public function getMagentoGenderFemaleId( )
|
| 108 |
+
{
|
| 109 |
+
$this->_genderHelper();
|
| 110 |
+
return $this->_genderOptions['female'];
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
protected function _genderHelper()
|
| 114 |
+
{
|
| 115 |
+
if ( NULL === $this->_genderOptions )
|
| 116 |
+
{
|
| 117 |
+
$entityType = Mage::getModel('eav/config')->getEntityType('customer');
|
| 118 |
+
$entityTypeId = $entityType->getEntityTypeId();
|
| 119 |
+
|
| 120 |
+
/* @var $attribute Mage_Eav_Model_Entity_Attribute */
|
| 121 |
+
$attribute = Mage::getResourceModel('eav/entity_attribute_collection')
|
| 122 |
+
->setCodeFilter('gender')
|
| 123 |
+
->setEntityTypeFilter($entityTypeId)
|
| 124 |
+
->getFirstItem();
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
//print_r($attribute->debug());
|
| 128 |
+
|
| 129 |
+
if ( $attribute->usesSource() )
|
| 130 |
+
{
|
| 131 |
+
$options = $attribute->getSource()->getAllOptions(false);
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
$option = array_shift($options);
|
| 135 |
+
$this->_genderOptions = array();
|
| 136 |
+
$this->_genderOptions['male'] = $option? $option['value']:NULL;
|
| 137 |
+
$option = array_shift($options);
|
| 138 |
+
$this->_genderOptions['female'] = $option? $option['value']:NULL;
|
| 139 |
+
}
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
public function getCustomerTotalOrders( $customer_id )
|
| 143 |
+
{
|
| 144 |
+
$collection = Mage::getModel('sales/order')->getCollection();
|
| 145 |
+
/* @var $collection Mage_Sales_Model_Entity_Order_Collection */
|
| 146 |
+
$collection->addFieldToFilter('customer_id', $customer_id);
|
| 147 |
+
|
| 148 |
+
return $collection->count();
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
public function getCustomerFirstPurchaseDate($customer_id)
|
| 152 |
+
{
|
| 153 |
+
$collection = Mage::getModel('sales/order')->getCollection();
|
| 154 |
+
/* @var $collection Mage_Sales_Model_Entity_Order_Collection */
|
| 155 |
+
$collection
|
| 156 |
+
->addFieldToFilter('customer_id', $customer_id)
|
| 157 |
+
//->addFieldToFilter('state', 'complete')
|
| 158 |
+
->setOrder('created_at', 'asc')
|
| 159 |
+
->setPageSize(1)
|
| 160 |
+
;
|
| 161 |
+
|
| 162 |
+
if ( $collection->count() > 0 )
|
| 163 |
+
{
|
| 164 |
+
/* @var $order Mage_Sales_Model_Order */
|
| 165 |
+
$order = $collection->getFirstItem();
|
| 166 |
+
return $order->getDataUsingMethod('created_at');
|
| 167 |
+
}
|
| 168 |
+
return NULL;
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
public function getCustomerLastPurchaseDate($customer_id)
|
| 172 |
+
{
|
| 173 |
+
$collection = Mage::getModel('sales/order')->getCollection();
|
| 174 |
+
/* @var $collection Mage_Sales_Model_Entity_Order_Collection */
|
| 175 |
+
$collection
|
| 176 |
+
->addFieldToFilter('customer_id', $customer_id)
|
| 177 |
+
//->addFieldToFilter('state', 'complete')
|
| 178 |
+
->setOrder('created_at', 'desc')
|
| 179 |
+
->setPageSize(1)
|
| 180 |
+
;
|
| 181 |
+
|
| 182 |
+
if ( $collection->count() > 0 )
|
| 183 |
+
{
|
| 184 |
+
/* @var $order Mage_Sales_Model_Order */
|
| 185 |
+
$order = $collection->getFirstItem();
|
| 186 |
+
return $order->getDataUsingMethod('created_at');
|
| 187 |
+
}
|
| 188 |
+
return NULL;
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
/*
|
| 192 |
+
* Returns the value which can be send to MailPlus. Returns NULL when nothing needs to be set.
|
| 193 |
+
*/
|
| 194 |
+
public function attributeToMailplusValue($elem, $attribute, $mapping) {
|
| 195 |
+
$attributeCode = $attribute->getAttributeCode();
|
| 196 |
+
switch ($attributeCode) {
|
| 197 |
+
case 'gender':
|
| 198 |
+
$gender = $elem->getDataUsingMethod( $attributeCode );
|
| 199 |
+
|
| 200 |
+
if ( $this->getMagentoGenderMaleId() == $gender )
|
| 201 |
+
return 'M';
|
| 202 |
+
elseif ( $this->getMagentoGenderFemaleId() == $gender )
|
| 203 |
+
return 'F';
|
| 204 |
+
break;
|
| 205 |
+
case 'dob':
|
| 206 |
+
$dob = $elem->getDataUsingMethod( $attributeCode );
|
| 207 |
+
if (!$dob ) {
|
| 208 |
+
return NULL;
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
return date('Y-m-d', strtotime($dob));
|
| 212 |
+
case 'postcode':
|
| 213 |
+
// Make sure to send only NL formatted postcodes when postcode is mapped to MailPlus postalcode.
|
| 214 |
+
if (isset($mapping['postcode']) && $mapping['postcode'] === 'postalCode') {
|
| 215 |
+
$value = (string) $elem->getDataUsingMethod( $attributeCode );
|
| 216 |
+
if (preg_match(Techtwo_Mailplus_Helper_Data::NL_ZIPCODE_REGEXP, $value)) {
|
| 217 |
+
return $value;
|
| 218 |
+
}
|
| 219 |
+
} else {
|
| 220 |
+
return (string) $elem->getDataUsingMethod( $attributeCode );
|
| 221 |
+
}
|
| 222 |
+
break;
|
| 223 |
+
case 'storedescription':
|
| 224 |
+
$store = null;
|
| 225 |
+
if ($elem->getStore){
|
| 226 |
+
$store = $elem->getStore();
|
| 227 |
+
} else {
|
| 228 |
+
$store = Mage::app()->getStore($elem->getStoreId());
|
| 229 |
+
}
|
| 230 |
+
return $store->getWebsite()->getName() . ' - ' . $store->getGroup()->getName() . ' - ' . $store->getName();
|
| 231 |
+
case 'firstpurchasedate':
|
| 232 |
+
$date = $this->getCustomerFirstPurchaseDate( $elem->getId() );
|
| 233 |
+
if ($date) {
|
| 234 |
+
return date(DateTime::ATOM, strtotime($date));
|
| 235 |
+
}
|
| 236 |
+
break;
|
| 237 |
+
case 'lastpurchasedate':
|
| 238 |
+
$date = $this->getCustomerLastPurchaseDate( $elem->getId() );
|
| 239 |
+
if ($date) {
|
| 240 |
+
return date(DateTime::ATOM, strtotime($date));
|
| 241 |
+
}
|
| 242 |
+
break;
|
| 243 |
+
case 'group_id': {
|
| 244 |
+
$groupId = $elem->getDataUsingMethod( $attributeCode );
|
| 245 |
+
return Mage::getModel('customer/group')->load($groupId)->getCode();
|
| 246 |
+
}
|
| 247 |
+
default:
|
| 248 |
+
return (string) $elem->getDataUsingMethod( $attributeCode );
|
| 249 |
+
};
|
| 250 |
+
|
| 251 |
+
return NULL;
|
| 252 |
+
}
|
| 253 |
+
|
| 254 |
+
public function addAttributeToProperties($properties, $attribute, $customer, $mapping) {
|
| 255 |
+
if ($attribute->getFrontendInput() === 'multiline') {
|
| 256 |
+
$data = $customer->getDataUsingMethod( $attribute->getAttributeCode() );
|
| 257 |
+
|
| 258 |
+
for ($i = 0; $i < $attribute->getMultilineCount(); $i++) {
|
| 259 |
+
$mappingId = $attribute->getAttributeCode() . '-line-' . ($i +1);
|
| 260 |
+
if (isset($mapping[$mappingId]) && isset($data[$i])) {
|
| 261 |
+
$properties[$mapping[$mappingId]] = $data[$i];
|
| 262 |
+
}
|
| 263 |
+
}
|
| 264 |
+
} else {
|
| 265 |
+
if (isset($mapping[$attribute->getAttributeCode()])) {
|
| 266 |
+
$mailplusProperty = $mapping[$attribute->getAttributeCode()];
|
| 267 |
+
$value = $this->attributeToMailplusValue($customer, $attribute, $mapping);
|
| 268 |
+
if ( $value != NULL ) {
|
| 269 |
+
|
| 270 |
+
$properties[$mailplusProperty] = $value;
|
| 271 |
+
}
|
| 272 |
+
}
|
| 273 |
+
}
|
| 274 |
+
|
| 275 |
+
return $properties;
|
| 276 |
+
}
|
| 277 |
+
|
| 278 |
+
|
| 279 |
+
public function getSyncCount($websiteId, $type = null) {
|
| 280 |
+
if (!$type)
|
| 281 |
+
return Mage::getModel('mailplus/syncqueue')->getCollection()->getSize();
|
| 282 |
+
|
| 283 |
+
return Mage::getModel('mailplus/syncqueue')->getCollection()
|
| 284 |
+
->addFieldToFilter('websiteid', Array('eq' => $websiteId))
|
| 285 |
+
->addFieldToFilter('synctype', Array('eq' => $type))
|
| 286 |
+
->getSize();
|
| 287 |
+
}
|
| 288 |
+
|
| 289 |
+
public function saveSyncItem($websiteId, $id, $type) {
|
| 290 |
+
$syncItem = Mage::getModel('mailplus/syncqueue');
|
| 291 |
+
$syncItem->setSynctype($type);
|
| 292 |
+
$syncItem->setWebsiteid($websiteId);
|
| 293 |
+
$syncItem->setSyncid($id);
|
| 294 |
+
$syncItem->setCreatedAt(date('Y-m-d H:i:s'));
|
| 295 |
+
$syncItem->save();
|
| 296 |
+
}
|
| 297 |
+
|
| 298 |
+
|
| 299 |
+
public function getRestqueueCount() {
|
| 300 |
+
return Mage::getModel('mailplus/restqueue')->getCollection()->getSize();
|
| 301 |
+
}
|
| 302 |
+
|
| 303 |
+
public function getAllAttributeGroupNames() {
|
| 304 |
+
$groups = Mage::getModel('eav/entity_attribute_group')
|
| 305 |
+
->getCollection()
|
| 306 |
+
->load();
|
| 307 |
+
|
| 308 |
+
$uniqGroups = Array();
|
| 309 |
+
$return = Array();
|
| 310 |
+
|
| 311 |
+
foreach($groups as $group) {
|
| 312 |
+
$uniqGroups[$group->getAttributeGroupName()] = true;
|
| 313 |
+
}
|
| 314 |
+
foreach($uniqGroups as $name => $blup) {
|
| 315 |
+
$return[] = $name;
|
| 316 |
+
}
|
| 317 |
+
|
| 318 |
+
return $return;
|
| 319 |
+
}
|
| 320 |
+
|
| 321 |
+
/**
|
| 322 |
+
* Create a mailplus/user from a customer. Only call this when the customer
|
| 323 |
+
* has no corresponding mailplus/user. This will also check the
|
| 324 |
+
* newsletter/subscriber if the customer has the newsletters permission
|
| 325 |
+
*
|
| 326 |
+
* @param Mage_Customer_Model_Customer $customer
|
| 327 |
+
* @return Techtwo_Mailplus_Model_User
|
| 328 |
+
*/
|
| 329 |
+
public function createUserFromCustomer($customer) {
|
| 330 |
+
/* @var $user Techtwo_Mailplus_Model_User */
|
| 331 |
+
$user = Mage::getModel('mailplus/user');
|
| 332 |
+
|
| 333 |
+
$existingUser = $user->findByEmail($customer->getEmail());
|
| 334 |
+
if (!$existingUser->getId()) {
|
| 335 |
+
// only check and set the permission when no existing user is found
|
| 336 |
+
$subscriber = Mage::getModel('newsletter/subscriber')->loadByCustomer($customer);
|
| 337 |
+
if ($subscriber && $subscriber->getStatus() == Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED) {
|
| 338 |
+
$user->setPermission( Techtwo_Mailplus_Helper_Rest::PERMISSION_BIT_NEWSLETTER, TRUE );
|
| 339 |
+
}
|
| 340 |
+
|
| 341 |
+
$user->setEmail( $customer->getEmail() );
|
| 342 |
+
$user->setCreatets( time() );
|
| 343 |
+
} else {
|
| 344 |
+
$user = $existingUser;
|
| 345 |
+
}
|
| 346 |
+
|
| 347 |
+
if ($customer->getFirstname() && trim($customer->getFirstname()) != '') {
|
| 348 |
+
$user->setFirstname( $customer->getFirstname());
|
| 349 |
+
}
|
| 350 |
+
if ($customer->getLastname() && trim($customer->getLastname()) != '') {
|
| 351 |
+
$user->setLastname( $customer->getLastname());
|
| 352 |
+
}
|
| 353 |
+
$user->setCustomerId( $customer->getId());
|
| 354 |
+
$user->setStoreId( $customer->getStore()->getId() );
|
| 355 |
+
$user->setEnabled(TRUE);
|
| 356 |
+
|
| 357 |
+
return $user;
|
| 358 |
+
}
|
| 359 |
+
|
| 360 |
+
/**
|
| 361 |
+
* Returns the website from the request, or the first website when there is no website parameter
|
| 362 |
+
*
|
| 363 |
+
* @return website
|
| 364 |
+
*/
|
| 365 |
+
public function getWebsiteFromRequest() {
|
| 366 |
+
$websiteCode = Mage::app()->getFrontController()->getRequest()->getParam('website');
|
| 367 |
+
$website = null;
|
| 368 |
+
if (!$websiteCode) {
|
| 369 |
+
$sites = Mage::app()->getWebsites();
|
| 370 |
+
$website = reset($sites);
|
| 371 |
+
} else {
|
| 372 |
+
$website = Mage::getModel('core/website')->load($websiteCode);
|
| 373 |
+
}
|
| 374 |
+
return $website;
|
| 375 |
+
}
|
| 376 |
+
}
|
app/code/community/Techtwo/Mailplus/Helper/Feed.php
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
class Techtwo_Mailplus_Helper_Feed extends Mage_Core_Helper_Abstract
|
| 18 |
+
{
|
| 19 |
+
public function getAllOptions( $store_id =NULL )
|
| 20 |
+
{
|
| 21 |
+
$attr_feed = Mage::getModel('catalog/product')->getResource()->getAttribute('mailplus_feed');
|
| 22 |
+
|
| 23 |
+
if ( NULL !== $store_id )
|
| 24 |
+
$attr_feed->setStoreId( $store_id );
|
| 25 |
+
|
| 26 |
+
/* @var $attr_feed Mage_Catalog_Model_Resource_Eav_Attribute */
|
| 27 |
+
$options = $attr_feed
|
| 28 |
+
->getSource()
|
| 29 |
+
->getAllOptions();
|
| 30 |
+
|
| 31 |
+
$valid_feeds = array();
|
| 32 |
+
foreach ( $options as $option )
|
| 33 |
+
if ('' != $option['value'])
|
| 34 |
+
$valid_feeds[$option['value']] = $option['label'];
|
| 35 |
+
return $valid_feeds;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
public function getProductIdsSql( $feed_id )
|
| 40 |
+
{
|
| 41 |
+
|
| 42 |
+
$db = Mage::getSingleton('core/resource')->getConnection('mailplus_read');
|
| 43 |
+
return '
|
| 44 |
+
SELECT `catalog_product_entity_id`
|
| 45 |
+
FROM `'.Mage::getModel('mailplus/feed')->getCollection()->getTable('mailplus/feed').'`
|
| 46 |
+
WHERE eav_attribute_option_id = '.$db->quote($feed_id).'
|
| 47 |
+
ORDER BY `order`';
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
public function getProductIds( $feed_id )
|
| 52 |
+
{
|
| 53 |
+
|
| 54 |
+
$db = Mage::getSingleton('core/resource')->getConnection('mailplus_read');
|
| 55 |
+
$productIds = $db->fetchPairs( '
|
| 56 |
+
SELECT `catalog_product_entity_id`, NULL as `foo`
|
| 57 |
+
FROM `'.Mage::getModel('mailplus/feed')->getCollection()->getTable('mailplus/feed').'`
|
| 58 |
+
WHERE eav_attribute_option_id = '.$db->quote($feed_id).'
|
| 59 |
+
ORDER BY `order`'
|
| 60 |
+
);
|
| 61 |
+
|
| 62 |
+
return is_bool($productIds)? $productIds:array_keys($productIds);
|
| 63 |
+
}
|
| 64 |
+
}
|
| 65 |
+
?>
|
app/code/community/Techtwo/Mailplus/Helper/Rest.php
ADDED
|
@@ -0,0 +1,1604 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
class Techtwo_Mailplus_Helper_Rest extends Mage_Core_Helper_Abstract
|
| 18 |
+
{
|
| 19 |
+
const PERMISSION_BIT_NEWSLETTER = 1;
|
| 20 |
+
|
| 21 |
+
/** The CAMPAIGN_ constants name are named after the configuration name */
|
| 22 |
+
|
| 23 |
+
/** */
|
| 24 |
+
const CAMPAIGN_NEWSLETTER = 21;
|
| 25 |
+
const CAMPAIGN_ABANDONED_CART = 22;
|
| 26 |
+
const CAMPAIGN_PRODUCT_REVIEW = 23;
|
| 27 |
+
|
| 28 |
+
/**
|
| 29 |
+
*
|
| 30 |
+
* Create $data:
|
| 31 |
+
* array products = product_ids involved at order
|
| 32 |
+
* float value = total order value
|
| 33 |
+
*/
|
| 34 |
+
const CONVERSION_SHOPPINGCART = 'SHOPPINGCART';
|
| 35 |
+
|
| 36 |
+
/**
|
| 37 |
+
* Cached clients stores based
|
| 38 |
+
* @var array(Zend_Rest_Client) */
|
| 39 |
+
protected $_client_stores = array();
|
| 40 |
+
|
| 41 |
+
/**
|
| 42 |
+
* Cached clients website based
|
| 43 |
+
* @var array(Zend_Rest_Client) */
|
| 44 |
+
protected $_client_websites = array();
|
| 45 |
+
|
| 46 |
+
protected $_restBaseUrl;
|
| 47 |
+
|
| 48 |
+
/**
|
| 49 |
+
* Checks if rest is enabled
|
| 50 |
+
*
|
| 51 |
+
* The store configuration rest must be filled in!
|
| 52 |
+
*
|
| 53 |
+
* @param int $store_id
|
| 54 |
+
* @param int $website_id
|
| 55 |
+
* @throws Exception
|
| 56 |
+
* @return bool
|
| 57 |
+
*/
|
| 58 |
+
protected function _isEnabled($store_id, $website_id)
|
| 59 |
+
{
|
| 60 |
+
if ($store_id && $website_id)
|
| 61 |
+
{
|
| 62 |
+
|
| 63 |
+
}
|
| 64 |
+
elseif ($store_id !== NULL)
|
| 65 |
+
{
|
| 66 |
+
return '1' === Mage::getStoreConfig('mailplus/general/active', $store_id) && '' != Mage::getStoreConfig('mailplus/general/rest_consumer_key', $store_id) && '' != Mage::getStoreConfig('mailplus/general/rest_secret', $store_id);
|
| 67 |
+
}
|
| 68 |
+
elseif ($website_id !== NULL)
|
| 69 |
+
{
|
| 70 |
+
return '1' === Mage::app()->getWebsite($website_id)->getConfig('mailplus/general/active') && '' != Mage::app()->getWebsite($website_id)->getConfig('mailplus/general/rest_consumer_key') && '' != Mage::app()->getWebsite($website_id)->getConfig('mailplus/general/rest_secret');
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
Mage::logException(new Exception('Use either store_id or website id'));
|
| 74 |
+
throw new Exception('Use either store_id or website id');
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
/**
|
| 78 |
+
* @param $store_id
|
| 79 |
+
* @return Techtwo_Mailplus_Client_Rest
|
| 80 |
+
*/
|
| 81 |
+
public function getClientByStore($store_id)
|
| 82 |
+
{
|
| 83 |
+
return $this->_getClient($store_id);
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
/**
|
| 87 |
+
* @param $website
|
| 88 |
+
* @return Techtwo_Mailplus_Client_Rest
|
| 89 |
+
*/
|
| 90 |
+
public function getClientByWebsite($website)
|
| 91 |
+
{
|
| 92 |
+
return $this->_getClient(NULL, $website);
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
protected function _restBaseUrl()
|
| 96 |
+
{
|
| 97 |
+
if ( NULL === $this->_restBaseUrl )
|
| 98 |
+
{
|
| 99 |
+
$in_test_mode = '1' === ((string) Mage::getConfig()->getNode('mailplus/in_test_mode'));
|
| 100 |
+
$this->_restBaseUrl = (string) $in_test_mode? Mage::getConfig()->getNode('mailplus/rest_base_test'):Mage::getConfig()->getNode('mailplus/rest_base');
|
| 101 |
+
}
|
| 102 |
+
return $this->_restBaseUrl;
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
/**
|
| 106 |
+
* Retrieves rest client connected with oAuth to MailPlus
|
| 107 |
+
* Initializes on first access.
|
| 108 |
+
*
|
| 109 |
+
* @param int $store_id
|
| 110 |
+
* @param int $website_id
|
| 111 |
+
* @throws Exception
|
| 112 |
+
* @return Techtwo_Mailplus_Client_Rest
|
| 113 |
+
*/
|
| 114 |
+
public function _getClient($store_id=NULL, $website_id=NULL)
|
| 115 |
+
{
|
| 116 |
+
if ($store_id === NULL && $website_id === NULL)
|
| 117 |
+
throw new Exception('Use either store_id or website id');
|
| 118 |
+
|
| 119 |
+
if ( !$this->_isEnabled($store_id, $website_id) )
|
| 120 |
+
{
|
| 121 |
+
return NULL;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
$this->_client_stores = array();
|
| 125 |
+
$this->_client_websites = array();
|
| 126 |
+
|
| 127 |
+
if (
|
| 128 |
+
($store_id && !array_key_exists($store_id,$this->_client_stores))
|
| 129 |
+
|| ($website_id && !array_key_exists($website_id,$this->_client_websites) )
|
| 130 |
+
)
|
| 131 |
+
{ // we don't use the two-way http://framework.zend.com/manual/1.12/en/zend.oauth.introduction.html
|
| 132 |
+
|
| 133 |
+
$in_test_mode = '1' === ((string) Mage::getConfig()->getNode('mailplus/in_test_mode'));
|
| 134 |
+
$restBaseDomain = $in_test_mode? Mage::getConfig()->getNode('mailplus/rest_test'):Mage::getConfig()->getNode('mailplus/rest');
|
| 135 |
+
|
| 136 |
+
if ($store_id)
|
| 137 |
+
{
|
| 138 |
+
$consumer_key = Mage::getStoreConfig('mailplus/general/rest_consumer_key',$store_id);
|
| 139 |
+
$secret = Mage::getStoreConfig('mailplus/general/rest_secret',$store_id);
|
| 140 |
+
}
|
| 141 |
+
else
|
| 142 |
+
{
|
| 143 |
+
$consumer_key = Mage::app()->getWebsite($website_id)->getConfig('mailplus/general/rest_consumer_key');
|
| 144 |
+
$secret = Mage::app()->getWebsite($website_id)->getConfig('mailplus/general/rest_secret');
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
$configOauth = array(
|
| 148 |
+
// 'callbackUrl' => Mage::getUrl('*/*/callback'),
|
| 149 |
+
// 'siteUrl' => $restBaseDomain, // no need for 2-way
|
| 150 |
+
'requestScheme' => Zend_Oauth::REQUEST_SCHEME_HEADER,
|
| 151 |
+
'consumerKey' => $consumer_key,
|
| 152 |
+
'consumerSecret' => $secret,
|
| 153 |
+
'version' => '1.0',
|
| 154 |
+
'signatureMethod' => 'HMAC-SHA1',
|
| 155 |
+
);
|
| 156 |
+
|
| 157 |
+
$config = array(
|
| 158 |
+
'useragent' => 'Magento-MailPlus v'.Mage::getConfig()->getNode('modules/Techtwo_Mailplus/version')
|
| 159 |
+
);
|
| 160 |
+
|
| 161 |
+
$token = new MailPlus_Oauth_Token_Access();
|
| 162 |
+
$httpClient = $token->getHttpClient($configOauth, NULL, $config);
|
| 163 |
+
$httpClient->setHeaders('Content-Type','application/json');
|
| 164 |
+
$httpClient->setHeaders('Accept','application/json');
|
| 165 |
+
$httpClient->setHeaders('Accept-encoding','');
|
| 166 |
+
$httpClient->setKeepContentType();
|
| 167 |
+
|
| 168 |
+
$client = new Techtwo_Mailplus_Client_Rest($restBaseDomain);
|
| 169 |
+
$client->setHttpClient($httpClient);
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
if ($store_id) {
|
| 173 |
+
$client->setSiteId( Mage::getModel('core/store')->load( $store_id)->getWebsiteId() );
|
| 174 |
+
} else {
|
| 175 |
+
$client->setSiteId($website_id);
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
if ($store_id) {
|
| 179 |
+
$this->_client_stores[$store_id] = $client;
|
| 180 |
+
}
|
| 181 |
+
else {
|
| 182 |
+
$this->_client_websites[$website_id] = $client;
|
| 183 |
+
}
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
if ($store_id)
|
| 187 |
+
return $this->_client_stores[$store_id];
|
| 188 |
+
|
| 189 |
+
return $this->_client_websites[$website_id];
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
protected $_trigger_campaign_state;
|
| 193 |
+
|
| 194 |
+
public function getTriggerCampaignLastSate()
|
| 195 |
+
{
|
| 196 |
+
return $this->_trigger_campaign_state;
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
/**
|
| 200 |
+
* Triggers a campaign
|
| 201 |
+
*
|
| 202 |
+
* @param int $campaign_constant A campaign constant defined in this class
|
| 203 |
+
* @param int $externalId The customer external id
|
| 204 |
+
* @return bool
|
| 205 |
+
*/
|
| 206 |
+
public function triggerCampaign( $campaign_constant, $externalId, array $extraData=array() )
|
| 207 |
+
{
|
| 208 |
+
$this->_trigger_campaign_state = NULL;
|
| 209 |
+
|
| 210 |
+
if ( !$this->_validateConstant('CAMPAIGN_', $campaign_constant, $constant_name) )
|
| 211 |
+
Mage::throwException('Incorrect permission, see CAMPAIGN_ constants');
|
| 212 |
+
|
| 213 |
+
/* @var $user Techtwo_Mailplus_Model_User */
|
| 214 |
+
$user = Mage::getModel('mailplus/user');
|
| 215 |
+
$user->load($externalId);
|
| 216 |
+
|
| 217 |
+
if ( !$user || $user->getId() < 1 ) {
|
| 218 |
+
$exception = new Exception("Campaign triggered '$constant_name', but user $externalId did not exist");
|
| 219 |
+
Mage::logException($exception);
|
| 220 |
+
return TRUE; // success but no user to send
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
+
$storeId = $user->getStoreId();
|
| 224 |
+
|
| 225 |
+
$config_path = 'mailplus/campaign/'.strtolower(substr($constant_name, strlen('CAMPAIGN_')));
|
| 226 |
+
$campaign_code = Mage::getStoreConfig($config_path, $storeId);
|
| 227 |
+
if (!$campaign_code)
|
| 228 |
+
{ // No campaign was setup
|
| 229 |
+
$this->_trigger_campaign_state = "MailPlus: Campaign $constant_name was not setup";
|
| 230 |
+
Mage::log("MailPlus: Campaign $constant_name was not setup", Zend_Log::DEBUG);
|
| 231 |
+
return TRUE;
|
| 232 |
+
}
|
| 233 |
+
|
| 234 |
+
$client = $this->getClientByStore($storeId);
|
| 235 |
+
if ($client == NULL) {
|
| 236 |
+
Mage::log("Plugin not active for storeview " . $storeId);
|
| 237 |
+
return TRUE;
|
| 238 |
+
}
|
| 239 |
+
|
| 240 |
+
$campaigns = $this->getTriggers($client);
|
| 241 |
+
|
| 242 |
+
// Incorrect campaign code, check configuration
|
| 243 |
+
if ( !array_key_exists($campaign_code, $campaigns) )
|
| 244 |
+
{
|
| 245 |
+
//echo "Mage::getConfig('$config_path'): ".$campaign_code; die();
|
| 246 |
+
Mage::log("MailPlus: Error campaign $campaign_code does not exists", Zend_Log::ERR);
|
| 247 |
+
$this->_trigger_campaign_state = "MailPlus: Error campaign $campaign_code does not exists";
|
| 248 |
+
return TRUE;
|
| 249 |
+
}
|
| 250 |
+
|
| 251 |
+
/* @var $campaign Techtwo_Mailplus_Model_System_Campaign */
|
| 252 |
+
$campaign = $campaigns[$campaign_code];
|
| 253 |
+
$campaignId = $campaign->getFirstTriggerEncryptedId();
|
| 254 |
+
|
| 255 |
+
$extraData['externalContactId'] = $externalId;
|
| 256 |
+
|
| 257 |
+
$response = $this->restPost($client, $this->_restBaseUrl().'/campaign/trigger/'.$campaignId, json_encode($extraData));
|
| 258 |
+
$client->log(__METHOD__."('$campaign_constant' [{$campaign->getName()}])");
|
| 259 |
+
|
| 260 |
+
if ($response == NULL) {
|
| 261 |
+
return FALSE; // call failed or queued
|
| 262 |
+
}
|
| 263 |
+
|
| 264 |
+
return $response->isSuccessful();
|
| 265 |
+
}
|
| 266 |
+
|
| 267 |
+
protected function _validateConversionType( $type )
|
| 268 |
+
{
|
| 269 |
+
if (! in_array($type, array(self::CONVERSION_SHOPPINGCART)) )
|
| 270 |
+
{
|
| 271 |
+
Mage::throwException("Invalid conversion type '$type'");
|
| 272 |
+
}
|
| 273 |
+
}
|
| 274 |
+
|
| 275 |
+
/**
|
| 276 |
+
* Create a conversion and remember it in the session
|
| 277 |
+
*
|
| 278 |
+
* @param $conversion_type
|
| 279 |
+
* @param $mailplus_id
|
| 280 |
+
* @return bool
|
| 281 |
+
*/
|
| 282 |
+
public function registerConversion( $conversion_type, $mailplus_id )
|
| 283 |
+
{
|
| 284 |
+
return $this->_conversion( $conversion_type, $mailplus_id );
|
| 285 |
+
}
|
| 286 |
+
|
| 287 |
+
/**
|
| 288 |
+
* Convert a conversion
|
| 289 |
+
*
|
| 290 |
+
* @param $conversion_type
|
| 291 |
+
* @param $mailplus_id
|
| 292 |
+
* @param array $conversion_data
|
| 293 |
+
* @return bool
|
| 294 |
+
*/
|
| 295 |
+
public function convertConversion( $conversion_type, $mailplus_id, array $conversion_data )
|
| 296 |
+
{
|
| 297 |
+
return $this->_conversion( $conversion_type, $mailplus_id, $conversion_data);
|
| 298 |
+
}
|
| 299 |
+
|
| 300 |
+
/**
|
| 301 |
+
* Registers or creates the conversion.
|
| 302 |
+
*
|
| 303 |
+
* @param $conversion_type
|
| 304 |
+
* @param $mailplus_id
|
| 305 |
+
* @param array $convert_data On array the conversion is created, on NULL it's only registered
|
| 306 |
+
* @return bool
|
| 307 |
+
*/
|
| 308 |
+
protected function _conversion( $conversion_type, $mailplus_id, array $convert_data=NULL )
|
| 309 |
+
{
|
| 310 |
+
$client = $this->getClientByStore( Mage::app()->getStore()->getId() );
|
| 311 |
+
if (!$client)
|
| 312 |
+
return TRUE;
|
| 313 |
+
|
| 314 |
+
$this->_validateConversionType( $conversion_type );
|
| 315 |
+
|
| 316 |
+
$action = NULL===$convert_data? 'CREATE':'CONVERT';
|
| 317 |
+
|
| 318 |
+
$data = array(
|
| 319 |
+
'mailplusId' => $mailplus_id,
|
| 320 |
+
'type' => $action.'_'.self::CONVERSION_SHOPPINGCART,
|
| 321 |
+
'interactionDate' => date(DateTime::ATOM)
|
| 322 |
+
);
|
| 323 |
+
|
| 324 |
+
if ( $convert_data )
|
| 325 |
+
{
|
| 326 |
+
$data = array_merge($convert_data, $data); // data last, you should not change the $data object
|
| 327 |
+
}
|
| 328 |
+
|
| 329 |
+
$response = $this->restPost($client, $this->_restBaseUrl().'/conversion', json_encode($data));
|
| 330 |
+
$client->log(__METHOD__.'('.$conversion_type.')');
|
| 331 |
+
|
| 332 |
+
if ($response == null) {
|
| 333 |
+
return false; // Call failed or call is queued
|
| 334 |
+
}
|
| 335 |
+
|
| 336 |
+
$success = 204 === $response->getStatus();
|
| 337 |
+
|
| 338 |
+
return $success;
|
| 339 |
+
}
|
| 340 |
+
|
| 341 |
+
|
| 342 |
+
/**
|
| 343 |
+
* Saves a product in MailPlus
|
| 344 |
+
*
|
| 345 |
+
* @throws Exception
|
| 346 |
+
* @param Mage_Catalog_Model_Product $product
|
| 347 |
+
* @return bool
|
| 348 |
+
*/
|
| 349 |
+
public function saveProduct( Mage_Catalog_Model_Product $product )
|
| 350 |
+
{
|
| 351 |
+
if ( Mage::app()->getStore()->isAdmin() )
|
| 352 |
+
{
|
| 353 |
+
/* @var $appEmulation Mage_Core_Model_App_Emulation */
|
| 354 |
+
$appEmulation = Mage::getSingleton('core/app_emulation');
|
| 355 |
+
|
| 356 |
+
$store_id = Mage::app()->getFrontController()->getRequest()->getParam('store');
|
| 357 |
+
$stores = array();
|
| 358 |
+
if ( $store_id )
|
| 359 |
+
{
|
| 360 |
+
$stores = array(Mage::app()->getStore($store_id));
|
| 361 |
+
}
|
| 362 |
+
else
|
| 363 |
+
{
|
| 364 |
+
$stores = Mage::app()->getStores();
|
| 365 |
+
}
|
| 366 |
+
|
| 367 |
+
|
| 368 |
+
foreach($stores as $store){
|
| 369 |
+
/* @var $store Mage_Core_Model_Store */
|
| 370 |
+
if (!$store->getIsActive())
|
| 371 |
+
continue;
|
| 372 |
+
|
| 373 |
+
$initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($store->getId());
|
| 374 |
+
|
| 375 |
+
/* @var $localProduct Mage_Catalog_Model_Product */
|
| 376 |
+
$localProduct = Mage::getModel('catalog/product')->load($product->getId());
|
| 377 |
+
|
| 378 |
+
try {
|
| 379 |
+
|
| 380 |
+
if ($localProduct->getId() && Mage_Catalog_Model_Product_Status::STATUS_ENABLED == $localProduct->getStatus() )
|
| 381 |
+
{
|
| 382 |
+
$this->_saveProduct($localProduct, $store->getId());
|
| 383 |
+
} else
|
| 384 |
+
{
|
| 385 |
+
$this->_deleteProduct($localProduct);
|
| 386 |
+
}
|
| 387 |
+
}
|
| 388 |
+
catch (Exception $ex)
|
| 389 |
+
{
|
| 390 |
+
Mage::logException($ex);
|
| 391 |
+
//Mage::getSingleton('core/session')->addError($ex->getMessage().' for store '.$store->getCode());
|
| 392 |
+
}
|
| 393 |
+
|
| 394 |
+
|
| 395 |
+
$appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
|
| 396 |
+
}
|
| 397 |
+
|
| 398 |
+
|
| 399 |
+
|
| 400 |
+
}
|
| 401 |
+
else
|
| 402 |
+
{
|
| 403 |
+
$this->_saveProduct($product, $product->getStore()->getId());
|
| 404 |
+
}
|
| 405 |
+
}
|
| 406 |
+
|
| 407 |
+
|
| 408 |
+
/**
|
| 409 |
+
* Saves a product in MailPlus
|
| 410 |
+
*
|
| 411 |
+
* @throws Exception
|
| 412 |
+
* @param Mage_Catalog_Model_Product $product
|
| 413 |
+
* @param int $store_id
|
| 414 |
+
* @return bool
|
| 415 |
+
*/
|
| 416 |
+
public function _saveProduct( Mage_Catalog_Model_Product $product, $store_id )
|
| 417 |
+
{
|
| 418 |
+
/* @var $productHelper Techtwo_Mailplus_Model_Product */
|
| 419 |
+
$productHelper = Mage::getModel('mailplus/product');
|
| 420 |
+
|
| 421 |
+
$client = $this->getClientByStore( $store_id );
|
| 422 |
+
if (!$client)
|
| 423 |
+
{ // No MailPlus client is setup or active. So we don't need to synchronize this
|
| 424 |
+
return TRUE;
|
| 425 |
+
}
|
| 426 |
+
|
| 427 |
+
/* @var $synchronize Techtwo_Mailplus_Model_Product */
|
| 428 |
+
$synchronize = $productHelper->findByProductId($product->getId(), $store_id);
|
| 429 |
+
|
| 430 |
+
if ( !$synchronize->getId() )
|
| 431 |
+
{
|
| 432 |
+
$synchronize->clearInstance();
|
| 433 |
+
/* @var $synchronize Techtwo_Mailplus_Model_Product */
|
| 434 |
+
$synchronize = Mage::getModel('mailplus/product');
|
| 435 |
+
|
| 436 |
+
$synchronize->setData(array(
|
| 437 |
+
'catalog_product_entity_id' => $product->getId(),
|
| 438 |
+
'store_id' => $store_id,
|
| 439 |
+
'price' => $product->getFinalPrice(),
|
| 440 |
+
'checksum' => ''
|
| 441 |
+
));
|
| 442 |
+
$synchronize->save();
|
| 443 |
+
}
|
| 444 |
+
|
| 445 |
+
$data = $this->_createMailPlusProductData( $synchronize, $product, $store_id );
|
| 446 |
+
$synchronize->setData('checksum', crc32(serialize($data)));
|
| 447 |
+
|
| 448 |
+
|
| 449 |
+
// we use the mailplus 'update=TRUE' option, so we don't care about insert or update
|
| 450 |
+
$response = $this->restPost($client, $this->_restBaseUrl().'/product', json_encode($data));
|
| 451 |
+
|
| 452 |
+
// ID_NOTUNIQUE
|
| 453 |
+
|
| 454 |
+
if ($response != null) {
|
| 455 |
+
$success = 204 === $response->getStatus();
|
| 456 |
+
$client->log(__METHOD__.'('.$product->getId().')');
|
| 457 |
+
|
| 458 |
+
if ( !$success )
|
| 459 |
+
{
|
| 460 |
+
$this->_processResponseError($response, $product);
|
| 461 |
+
}
|
| 462 |
+
}
|
| 463 |
+
|
| 464 |
+
/**
|
| 465 |
+
* New product is added/ updated at the MailPlus side, or request is queued
|
| 466 |
+
* Make a record of that so we don't try and add the same product again!
|
| 467 |
+
*/
|
| 468 |
+
try {
|
| 469 |
+
// ensure the update_at is saved on save
|
| 470 |
+
$synchronize->setDataChanges( TRUE );
|
| 471 |
+
$synchronize->save();
|
| 472 |
+
}
|
| 473 |
+
catch (Exception $ex)
|
| 474 |
+
{
|
| 475 |
+
Mage::logException($ex);
|
| 476 |
+
if ( Mage::getStoreConfigFlag('mailplus/debug/log_enabled') )
|
| 477 |
+
{
|
| 478 |
+
throw $ex;
|
| 479 |
+
}
|
| 480 |
+
}
|
| 481 |
+
|
| 482 |
+
return $success;
|
| 483 |
+
}
|
| 484 |
+
|
| 485 |
+
/**
|
| 486 |
+
* Throws exception for all status ( also 200, so only error responses here )
|
| 487 |
+
*
|
| 488 |
+
* Known error codes:
|
| 489 |
+
* ID_NOTUNIQUE - externalProductId must be unique , happens when you insert an product id which is already inserted
|
| 490 |
+
* PRODUCT_NOTFOUND - product not found with externalProductId: %s , happens when you update an not existent product
|
| 491 |
+
*
|
| 492 |
+
* @throws Exception
|
| 493 |
+
* @param Zend_Http_Response $response
|
| 494 |
+
* * @param Mage_Catalog_Model_Product $product_for_auto_recover
|
| 495 |
+
*/
|
| 496 |
+
protected function _processResponseError( Zend_Http_Response $response, Mage_Catalog_Model_Product $product_for_auto_recover=NULL )
|
| 497 |
+
{
|
| 498 |
+
if ( 400 === $response->getStatus() )
|
| 499 |
+
{
|
| 500 |
+
$content_type = $response->getHeader('content-type'); // zend always use lower case
|
| 501 |
+
|
| 502 |
+
if ( 'application/json' === $content_type )
|
| 503 |
+
{
|
| 504 |
+
$json = json_decode($response->getBody());
|
| 505 |
+
$error_type = (string) $json->errorType;
|
| 506 |
+
|
| 507 |
+
Mage::throwException('MailPlus product synchronize '.(string) $json->message .' [ ' . $error_type .' ]');
|
| 508 |
+
}
|
| 509 |
+
else
|
| 510 |
+
{
|
| 511 |
+
Mage::throwException('MailPlus product synchronize unknown error '.$response->getBody());
|
| 512 |
+
}
|
| 513 |
+
}
|
| 514 |
+
else
|
| 515 |
+
{
|
| 516 |
+
Mage::throwException('MailPlus product synchronize unknown error '.$response->getStatus());
|
| 517 |
+
}
|
| 518 |
+
}
|
| 519 |
+
|
| 520 |
+
public function deleteProduct( Mage_Catalog_Model_Product $product )
|
| 521 |
+
{
|
| 522 |
+
/* @var $collection Techtwo_Mailplus_Model_Mysql4_Product_Collection */
|
| 523 |
+
$collection = Mage::getModel('mailplus/product')->getCollection();
|
| 524 |
+
$stores = $collection->getAllStoreIdsByProductId( $product->getId() );
|
| 525 |
+
|
| 526 |
+
/* @var $appEmulation Mage_Core_Model_App_Emulation */
|
| 527 |
+
$appEmulation = Mage::getSingleton('core/app_emulation');
|
| 528 |
+
$initialEnvironmentInfo = NULL;
|
| 529 |
+
foreach ( $stores as $store_id )
|
| 530 |
+
{
|
| 531 |
+
$first = $appEmulation->startEnvironmentEmulation($store_id);
|
| 532 |
+
if ( NULL === $initialEnvironmentInfo )
|
| 533 |
+
{
|
| 534 |
+
$initialEnvironmentInfo = $first;
|
| 535 |
+
}
|
| 536 |
+
|
| 537 |
+
$this->_deleteProduct($product);
|
| 538 |
+
|
| 539 |
+
|
| 540 |
+
$appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
|
| 541 |
+
}
|
| 542 |
+
if ( $initialEnvironmentInfo )
|
| 543 |
+
$appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
|
| 544 |
+
}
|
| 545 |
+
|
| 546 |
+
/**
|
| 547 |
+
* Delete the product from MailPlus
|
| 548 |
+
*
|
| 549 |
+
* @param Mage_Catalog_Model_Product $product
|
| 550 |
+
* @return bool
|
| 551 |
+
*/
|
| 552 |
+
public function _deleteProduct( Mage_Catalog_Model_Product $product )
|
| 553 |
+
{
|
| 554 |
+
$client = $this->getClientByStore($product->getStoreId());
|
| 555 |
+
if (!$client)
|
| 556 |
+
return TRUE;
|
| 557 |
+
|
| 558 |
+
/* @var $synchronize Techtwo_Mailplus_Model_Product */
|
| 559 |
+
$synchronize = Mage::getModel('mailplus/product');
|
| 560 |
+
$synchronize = $synchronize->findByProductId( $product->getId(), $product->getStoreId() );
|
| 561 |
+
|
| 562 |
+
$external_id = $synchronize->getExternalId();
|
| 563 |
+
|
| 564 |
+
if ( $synchronize->getId() )
|
| 565 |
+
{
|
| 566 |
+
$response = $this->restDelete($client, $this->_restBaseUrl().'/product/'.$external_id, false);
|
| 567 |
+
|
| 568 |
+
// 204 ok deleted, 404 you deleted a non-existent product ... which is fine too
|
| 569 |
+
if ( 204 !== $response->getStatus() && 404 !== $response->getStatus() )
|
| 570 |
+
{
|
| 571 |
+
// silently log exceptions when they occur
|
| 572 |
+
try { $this->_processResponseError($response); }
|
| 573 |
+
catch ( Exception $ex ) { Mage::logException( $ex ); }
|
| 574 |
+
|
| 575 |
+
// eg. on 500 internal server error or if mailplus is gone ...
|
| 576 |
+
// .. don't remove it in the product synchronized table, because it's not deleted
|
| 577 |
+
|
| 578 |
+
return FALSE;
|
| 579 |
+
}
|
| 580 |
+
|
| 581 |
+
$client->log( __METHOD__.'('.$product->getId().')' );
|
| 582 |
+
|
| 583 |
+
// Now remove it from the synchronized table
|
| 584 |
+
$synchronize->delete();
|
| 585 |
+
}
|
| 586 |
+
|
| 587 |
+
return TRUE;
|
| 588 |
+
}
|
| 589 |
+
|
| 590 |
+
/**
|
| 591 |
+
* Creates the product data to send to MailPlus
|
| 592 |
+
* It still lacks the external ids, so you can batch check the externalIds
|
| 593 |
+
*
|
| 594 |
+
* @param Techtwo_Mailplus_Model_Product $mailplus_product
|
| 595 |
+
* @param Mage_Catalog_Model_Product $product
|
| 596 |
+
* @param $store_id
|
| 597 |
+
* @return array
|
| 598 |
+
*/
|
| 599 |
+
protected function _createMailPlusProductData( Techtwo_Mailplus_Model_Product $mailplus_product, Mage_Catalog_Model_Product $product, $store_id )
|
| 600 |
+
{
|
| 601 |
+
$external_id = $mailplus_product->getExternalId();
|
| 602 |
+
$categoryPaths = $this->_findDeepestCategories( $product );
|
| 603 |
+
|
| 604 |
+
$brand_attribute = $this->_getBrandAttributeCode();
|
| 605 |
+
|
| 606 |
+
$product_brand = NULL;
|
| 607 |
+
if ($product->offsetExists($brand_attribute)) {
|
| 608 |
+
$product_brand = $product->getAttributeText($brand_attribute);
|
| 609 |
+
if ( FALSE === $product_brand || NULL === $product_brand ) // not a multiselect ?
|
| 610 |
+
$product_brand = $product->getDataUsingMethod($brand_attribute); // you never know if someone created a getMethod
|
| 611 |
+
}
|
| 612 |
+
|
| 613 |
+
/* @var $image Mage_Catalog_Helper_Image */
|
| 614 |
+
$image = Mage::helper('catalog/image');
|
| 615 |
+
|
| 616 |
+
$imageUrl = Mage::getUrl('mailplus/image/get/id/' . $mailplus_product->getId() . '/f/n');
|
| 617 |
+
$imageLargeUrl = Mage::getUrl('mailplus/image/get/id/' . $mailplus_product->getId() . '/f/l');
|
| 618 |
+
|
| 619 |
+
$store = $product->getStore();
|
| 620 |
+
$mailplus_sku = $store->getId().'-'.$product->getSku();
|
| 621 |
+
$storeName = $store->getWebsite()->getName() . ' - ' . $store->getGroup()->getName() . ' - ' . $product->getStore()->getName();
|
| 622 |
+
|
| 623 |
+
$description = strip_tags($product->getShortDescription());
|
| 624 |
+
if ($description === NULL || $description === '') {
|
| 625 |
+
$description = $product->getName();
|
| 626 |
+
}
|
| 627 |
+
|
| 628 |
+
$specifications = $this->_getProductSpecifications($product, $store_id);
|
| 629 |
+
|
| 630 |
+
$data = array(
|
| 631 |
+
'update' => TRUE,
|
| 632 |
+
'product' => array(
|
| 633 |
+
'externalId' => $external_id,
|
| 634 |
+
'sku' => $mailplus_sku,
|
| 635 |
+
'gtin' => $product->getId(), //, $product->getSku(), || SKU is almost always bigger than the maximum allowed
|
| 636 |
+
'name' => $product->getName(),
|
| 637 |
+
'description' => $description,
|
| 638 |
+
'category' => $categoryPaths? reset($categoryPaths):'',
|
| 639 |
+
'price' => round($product->getFinalPrice()*100), // must be in cents
|
| 640 |
+
'oldPrice' => round($product->getPrice()*100), // must be in cents
|
| 641 |
+
'link' => $product->getProductUrl(),
|
| 642 |
+
'brand' => $product_brand? $product_brand:'',
|
| 643 |
+
'imageUrl' => $imageUrl,
|
| 644 |
+
'imageLargeUrl' => $imageLargeUrl,
|
| 645 |
+
//'ratingImageUrl' => '', // TODO: rating image for the product, probably no longer required as mailplus can generate the images
|
| 646 |
+
'addToCartLink' => '', // TODO: add to cart url here ( if possible, so simple product without custom options )
|
| 647 |
+
'language' => $storeName
|
| 648 |
+
)
|
| 649 |
+
);
|
| 650 |
+
|
| 651 |
+
$productData = &$data['product']; // make an easy short-cut to $data[product] using reference
|
| 652 |
+
|
| 653 |
+
if ($specifications) {
|
| 654 |
+
$productData['specifications'] = $specifications;
|
| 655 |
+
}
|
| 656 |
+
|
| 657 |
+
|
| 658 |
+
/* @var $review Mage_Review_Model_Review */
|
| 659 |
+
$review = Mage::getModel('review/review');
|
| 660 |
+
$review->getEntitySummary($product);
|
| 661 |
+
|
| 662 |
+
$ratingPercent = (int) $product->getRatingSummary()->getRatingSummary(); // this get you a percent 0 to 100
|
| 663 |
+
$reviewsCount = (int) $product->getRatingSummary()->getReviewsCount(); // this get you a percent 0 to 100
|
| 664 |
+
|
| 665 |
+
// this is a link to a single review
|
| 666 |
+
//$data['reviewLink'] = $review->getReviewUrl();
|
| 667 |
+
|
| 668 |
+
// this is the best way to get the reviews url, should someone use a different link, than they should be able to just rewrite the block
|
| 669 |
+
|
| 670 |
+
/* @var $block Mage_Review_Block_Helper */
|
| 671 |
+
$block = Mage::app()->getLayout()->createBlock('review/helper');
|
| 672 |
+
$block->setDataUsingMethod('product', $product);
|
| 673 |
+
$productData['reviewLink'] = $block->getReviewsUrl();
|
| 674 |
+
if ( FALSE !== ($pos = strpos($productData['reviewLink'], '?')) )
|
| 675 |
+
{
|
| 676 |
+
$productData['reviewLink'] = substr($productData['reviewLink'], 0, $pos);
|
| 677 |
+
}
|
| 678 |
+
|
| 679 |
+
if ( $reviewsCount > 0 )
|
| 680 |
+
{
|
| 681 |
+
$mailplusBase = 5;
|
| 682 |
+
$productData['ratingValue'] = $mailplusBase *( $ratingPercent/100 );
|
| 683 |
+
}
|
| 684 |
+
|
| 685 |
+
// MailPlus does not want the oldPrice is the price==oldPrice
|
| 686 |
+
if ($data['product']['price'] === $data['product']['oldPrice'])
|
| 687 |
+
{
|
| 688 |
+
unset($data['product']['oldPrice']);
|
| 689 |
+
}
|
| 690 |
+
|
| 691 |
+
return $data;
|
| 692 |
+
}
|
| 693 |
+
|
| 694 |
+
private function _getProductSpecifications($product, $store_id) {
|
| 695 |
+
$specsGroupName = Mage::getStoreConfig('mailplus/syncsettings/productspecs', $store_id);
|
| 696 |
+
if ($specsGroupName == NULL) {
|
| 697 |
+
return NULL;
|
| 698 |
+
}
|
| 699 |
+
|
| 700 |
+
$setId = $product->getAttributeSetId();
|
| 701 |
+
|
| 702 |
+
$groups = Mage::getModel('eav/entity_attribute_group')
|
| 703 |
+
->getCollection()
|
| 704 |
+
->addFieldToFilter('attribute_set_id', $setId)
|
| 705 |
+
->load();
|
| 706 |
+
|
| 707 |
+
$result = array();
|
| 708 |
+
|
| 709 |
+
foreach($groups as $group) {
|
| 710 |
+
if ($specsGroupName === $group->getAttributeGroupName()) {
|
| 711 |
+
$productAttrs = $product->getAttributes();
|
| 712 |
+
foreach($productAttrs as $attrName => $attr) {
|
| 713 |
+
$groupId = $attr->getAttributeGroupId();
|
| 714 |
+
if ($groupId == $group->getId()) {
|
| 715 |
+
$labels = $attr->getStoreLabels();
|
| 716 |
+
$label = NULL;
|
| 717 |
+
if (array_key_exists($product->getStoreId(), $labels)) {
|
| 718 |
+
$label = $labels[$product->getStoreId()];
|
| 719 |
+
}
|
| 720 |
+
if ($label == null || $label == '') {
|
| 721 |
+
$label = $attr->getStoreLabel();
|
| 722 |
+
}
|
| 723 |
+
|
| 724 |
+
if ($label != null && $label != '') {
|
| 725 |
+
$value = NULL;
|
| 726 |
+
if ($attr->usesSource()) {
|
| 727 |
+
$value = $product->getResource()->getAttribute($attrName)->getSource()->getOptionText($product->getData($attrName));
|
| 728 |
+
} else {
|
| 729 |
+
$value = $product->getResource()->getAttribute($attrName)->getFrontEnd()->getValue($product);
|
| 730 |
+
}
|
| 731 |
+
|
| 732 |
+
if ($value != NULL || $value != '') {
|
| 733 |
+
$specification = array(
|
| 734 |
+
'description' => $label,
|
| 735 |
+
'value' => strip_tags($value),
|
| 736 |
+
'rank' => $attr->getSortOrder()
|
| 737 |
+
);
|
| 738 |
+
$result[] = $specification;
|
| 739 |
+
}
|
| 740 |
+
}
|
| 741 |
+
}
|
| 742 |
+
}
|
| 743 |
+
}
|
| 744 |
+
}
|
| 745 |
+
|
| 746 |
+
$numItems = count($result);
|
| 747 |
+
if ($numItems == 0)
|
| 748 |
+
return NULL;
|
| 749 |
+
|
| 750 |
+
usort($result, array("Techtwo_Mailplus_Helper_Rest", "specCompare"));
|
| 751 |
+
|
| 752 |
+
if ($numItems <= 5) {
|
| 753 |
+
return $result;
|
| 754 |
+
}
|
| 755 |
+
|
| 756 |
+
return array_slice($result, 0, 5);
|
| 757 |
+
}
|
| 758 |
+
|
| 759 |
+
static function specCompare($a, $b) {
|
| 760 |
+
return ($a['rank'] > $b['rank'] ? +1 : -1);
|
| 761 |
+
}
|
| 762 |
+
|
| 763 |
+
|
| 764 |
+
public function getModifiedContacts( $websiteId, $fromDate, $toDate )
|
| 765 |
+
{
|
| 766 |
+
$client = $this->getClientByWebsite($websiteId);
|
| 767 |
+
if ( !$client )
|
| 768 |
+
return array();
|
| 769 |
+
|
| 770 |
+
$fromDate = date(DateTime::ATOM, $fromDate);
|
| 771 |
+
$toDate = date(DateTime::ATOM, $toDate);
|
| 772 |
+
|
| 773 |
+
$response = $client->restGet($this->_restBaseUrl().'/contact/updates/list', array('fromDate'=>$fromDate, 'toDate'=>$toDate));
|
| 774 |
+
$client->log(__METHOD__."( '$fromDate', '$toDate'' )");
|
| 775 |
+
|
| 776 |
+
if ( !$response->isSuccessful() )
|
| 777 |
+
return FALSE;
|
| 778 |
+
|
| 779 |
+
return json_decode( $response->getBody() );
|
| 780 |
+
}
|
| 781 |
+
|
| 782 |
+
public function getBounces( $websiteId, $fromDate, $toDate )
|
| 783 |
+
{
|
| 784 |
+
$client = $this->getClientByWebsite($websiteId);
|
| 785 |
+
|
| 786 |
+
$fromDate = date(DateTime::ATOM, $fromDate);
|
| 787 |
+
$toDate = date(DateTime::ATOM, $toDate);
|
| 788 |
+
|
| 789 |
+
|
| 790 |
+
$response = $client->restGet($this->_restBaseUrl().'/contact/bounces/list', array('fromDate'=>$fromDate, 'toDate'=>$toDate));
|
| 791 |
+
$client->log(__METHOD__."( '$fromDate', '$toDate' )");
|
| 792 |
+
|
| 793 |
+
if ( !$response->isSuccessful() )
|
| 794 |
+
return FALSE;
|
| 795 |
+
|
| 796 |
+
return json_decode( $response->getBody() );
|
| 797 |
+
}
|
| 798 |
+
|
| 799 |
+
public function getTriggers( $client )
|
| 800 |
+
{
|
| 801 |
+
$cache_id = 'techtwo_mailplus_campaign_triggers';
|
| 802 |
+
|
| 803 |
+
|
| 804 |
+
//Mage::app()->getWebsite($websiteId)->getConfig('web/unsecure/base_url')
|
| 805 |
+
$store = Mage::app()->getFrontController()->getRequest()->getParam('store');
|
| 806 |
+
$website = Mage::app()->getFrontController()->getRequest()->getParam('website');
|
| 807 |
+
|
| 808 |
+
if ($store)
|
| 809 |
+
$cache_id .= '-s-'.$store;
|
| 810 |
+
|
| 811 |
+
if ($website)
|
| 812 |
+
$cache_id .= '-w-'.$website;
|
| 813 |
+
|
| 814 |
+
|
| 815 |
+
/* @var $cache Varien_Cache_Core */
|
| 816 |
+
$cache = Mage::app()->getCache();
|
| 817 |
+
$cache_data = $cache->load($cache_id);
|
| 818 |
+
if ( $cache_data )
|
| 819 |
+
{
|
| 820 |
+
$cache_data = unserialize($cache_data);
|
| 821 |
+
if ( $cache_data ) // might be a unserialize problem
|
| 822 |
+
return $cache_data;
|
| 823 |
+
}
|
| 824 |
+
|
| 825 |
+
/* @var $helper Techtwo_Mailplus_Helper_Rest */
|
| 826 |
+
$helper = Mage::helper('mailplus/rest');
|
| 827 |
+
|
| 828 |
+
$aux = FALSE;
|
| 829 |
+
|
| 830 |
+
if ( $client )
|
| 831 |
+
{
|
| 832 |
+
$response = $client->restGet($this->_restBaseUrl().'/campaign/list');
|
| 833 |
+
if ( $response->isSuccessful() )
|
| 834 |
+
$aux = array();
|
| 835 |
+
|
| 836 |
+
$client->log(__METHOD__.'()');
|
| 837 |
+
|
| 838 |
+
$content_type = $response->getHeader('content-type'); // zend always use lower case
|
| 839 |
+
|
| 840 |
+
|
| 841 |
+
$json = json_decode($response->getBody());
|
| 842 |
+
|
| 843 |
+
|
| 844 |
+
if (!$response->isSuccessful())
|
| 845 |
+
{
|
| 846 |
+
$error_type = (string) $json->errorType;
|
| 847 |
+
Mage::logException(new Exception('MailPlus campaign list '.(string) $json->message .' [ ' . $error_type .' ]'));
|
| 848 |
+
return FALSE;
|
| 849 |
+
}
|
| 850 |
+
|
| 851 |
+
foreach ($json as $c)
|
| 852 |
+
{
|
| 853 |
+
if ( $c->active )
|
| 854 |
+
{
|
| 855 |
+
/* @var $campaign Techtwo_Mailplus_Model_System_Campaign */
|
| 856 |
+
$campaign = Mage::getModel('mailplus/system_campaign');
|
| 857 |
+
$campaign->setName( (string) $c->name );
|
| 858 |
+
$campaign->setEncryptedId( (string) $c->encryptedId );
|
| 859 |
+
if ( isset($c->triggers) )
|
| 860 |
+
{
|
| 861 |
+
foreach ($c->triggers as $trigger)
|
| 862 |
+
{
|
| 863 |
+
$campaign->addTrigger((string)$trigger->encryptedId, (string)$trigger->name);
|
| 864 |
+
}
|
| 865 |
+
}
|
| 866 |
+
|
| 867 |
+
$aux[$c->encryptedId] = $campaign;
|
| 868 |
+
}
|
| 869 |
+
}
|
| 870 |
+
}
|
| 871 |
+
else
|
| 872 |
+
{
|
| 873 |
+
$cache->remove($cache_id);
|
| 874 |
+
return FALSE;
|
| 875 |
+
}
|
| 876 |
+
|
| 877 |
+
Mage::app()->getCache()->save( serialize($aux), $cache_id, array(Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Attribute_Collection::CACHE_TAG), 900 );
|
| 878 |
+
|
| 879 |
+
return $aux;
|
| 880 |
+
}
|
| 881 |
+
|
| 882 |
+
/**
|
| 883 |
+
* Get the branch attribute
|
| 884 |
+
*
|
| 885 |
+
* By default the branch attribute is called 'manufacturer' in Magento.
|
| 886 |
+
*
|
| 887 |
+
* @todo create setting a somewhere
|
| 888 |
+
* @return string
|
| 889 |
+
*/
|
| 890 |
+
protected function _getBrandAttributeCode()
|
| 891 |
+
{
|
| 892 |
+
return 'manufacturer';
|
| 893 |
+
}
|
| 894 |
+
|
| 895 |
+
/**
|
| 896 |
+
* Finds the deepest paths for a given product
|
| 897 |
+
*
|
| 898 |
+
* a book in listed in eg. category book, book/fantasy and /featured
|
| 899 |
+
* will correctly result in: /book/fantasy and in /featured
|
| 900 |
+
* it checks for the deepest and unique category paths of the product
|
| 901 |
+
*
|
| 902 |
+
* @param Mage_Catalog_Model_Product $product
|
| 903 |
+
* @return array
|
| 904 |
+
*/
|
| 905 |
+
protected function _findDeepestCategories( Mage_Catalog_Model_Product $product )
|
| 906 |
+
{
|
| 907 |
+
// Set the categories, multiple categories are joined on '/' as delimeter
|
| 908 |
+
$categories = array();
|
| 909 |
+
$categoriesCollection = $product->getCategoryCollection();
|
| 910 |
+
|
| 911 |
+
$categoriesCollection
|
| 912 |
+
->addAttributeToSelect(array('name'))
|
| 913 |
+
->setOrder('level','DESC');
|
| 914 |
+
|
| 915 |
+
$deepestNest = array();
|
| 916 |
+
|
| 917 |
+
$categoryPaths = Array();
|
| 918 |
+
foreach ($categoriesCollection as $category )
|
| 919 |
+
{ /* @var $category Mage_Catalog_Model_Category */
|
| 920 |
+
$deepestNestFound = TRUE;
|
| 921 |
+
foreach ($deepestNest as $nest)
|
| 922 |
+
{
|
| 923 |
+
if ( 0 === strpos($nest, $category->getPath()) )
|
| 924 |
+
{
|
| 925 |
+
$deepestNestFound = FALSE;
|
| 926 |
+
}
|
| 927 |
+
}
|
| 928 |
+
|
| 929 |
+
if ($deepestNestFound)
|
| 930 |
+
{
|
| 931 |
+
$deepestNest []= $category->getPath();
|
| 932 |
+
}
|
| 933 |
+
|
| 934 |
+
$categories[$category->getId()] = $category->getName();
|
| 935 |
+
|
| 936 |
+
$parentCats = $category->getParentCategories();
|
| 937 |
+
$pathNames = Array();
|
| 938 |
+
foreach($parentCats as $pCat) {
|
| 939 |
+
$pathNames[] = $pCat->getName();
|
| 940 |
+
}
|
| 941 |
+
$categoryPaths[$category->getPath()] = implode("/", $pathNames);
|
| 942 |
+
}
|
| 943 |
+
|
| 944 |
+
$result = Array();
|
| 945 |
+
foreach($categoryPaths as $key => $value) {
|
| 946 |
+
if (in_array($key, $deepestNest)) {
|
| 947 |
+
$result[$key] = $value;
|
| 948 |
+
}
|
| 949 |
+
}
|
| 950 |
+
|
| 951 |
+
return $result;
|
| 952 |
+
}
|
| 953 |
+
|
| 954 |
+
/**
|
| 955 |
+
* @param string $externalId The externalId, this is {store_id}-{entity_id}
|
| 956 |
+
* @return array|NULL Array of mailplus data or NULL on not found
|
| 957 |
+
* @throws Techtwo_Mailplus_Client_Exception
|
| 958 |
+
*/
|
| 959 |
+
public function getContactByExternalId( $externalId, $storeId )
|
| 960 |
+
{
|
| 961 |
+
$client = $this->getClientByStore($storeId);
|
| 962 |
+
|
| 963 |
+
if ($client === NULL) {
|
| 964 |
+
return NULL;
|
| 965 |
+
}
|
| 966 |
+
|
| 967 |
+
$response = $client->restGet($this->_restBaseUrl().'/contact/'.$externalId);
|
| 968 |
+
$client->log(__METHOD__."( $externalId )");
|
| 969 |
+
$error = $client->getError();
|
| 970 |
+
|
| 971 |
+
if ( NULL !== $error )
|
| 972 |
+
{
|
| 973 |
+
$exception = new Techtwo_Mailplus_Client_Exception( $error->getMessage()."[{$error->getType()}]", $error->getCode() );
|
| 974 |
+
$exception->setType( $error->getType() );
|
| 975 |
+
|
| 976 |
+
if ('CONTACT_NOT_FOUND' === $error->getType())
|
| 977 |
+
return NULL;
|
| 978 |
+
throw $exception;
|
| 979 |
+
}
|
| 980 |
+
|
| 981 |
+
return json_decode( $response->getBody() );
|
| 982 |
+
}
|
| 983 |
+
|
| 984 |
+
/**
|
| 985 |
+
* * Options
|
| 986 |
+
* purge - Clears contact data on TRUE. On FALSE the new data is merged/added to the old data.
|
| 987 |
+
*
|
| 988 |
+
* @param $contact_data
|
| 989 |
+
* @param array $options
|
| 990 |
+
* @return bool
|
| 991 |
+
* @throws Techtwo_Mailplus_Client_Exception
|
| 992 |
+
*/
|
| 993 |
+
public function updateContact( $storeId, $contact_data, array $options=array() )
|
| 994 |
+
{
|
| 995 |
+
$options = array_merge( array(
|
| 996 |
+
'purge' => FALSE,
|
| 997 |
+
), $options);
|
| 998 |
+
|
| 999 |
+
$externalId = $contact_data['externalId'];
|
| 1000 |
+
|
| 1001 |
+
$data = array(
|
| 1002 |
+
'purge' => (bool) $options['purge'],
|
| 1003 |
+
'contact' => $contact_data
|
| 1004 |
+
);
|
| 1005 |
+
|
| 1006 |
+
$client = $this->getClientByStore( $storeId );
|
| 1007 |
+
$response = $this->restPut($client, $this->_restBaseUrl().'/contact/'.$externalId, json_encode($data) );
|
| 1008 |
+
$client->log(__METHOD__."( $externalId )");
|
| 1009 |
+
$error = $client->getError();
|
| 1010 |
+
if ( NULL !== $error )
|
| 1011 |
+
{
|
| 1012 |
+
$exception = new Techtwo_Mailplus_Client_Exception( $error->getMessage()."[{$error->getType()}]", $error->getCode() );
|
| 1013 |
+
$exception->setType($error->getType());
|
| 1014 |
+
throw $exception;
|
| 1015 |
+
}
|
| 1016 |
+
|
| 1017 |
+
return TRUE;
|
| 1018 |
+
}
|
| 1019 |
+
|
| 1020 |
+
/**
|
| 1021 |
+
* Either create or update an contact
|
| 1022 |
+
*
|
| 1023 |
+
* options:
|
| 1024 |
+
* - update : default TRUE
|
| 1025 |
+
* - purge : default FALSE
|
| 1026 |
+
*
|
| 1027 |
+
* @param $contact_data
|
| 1028 |
+
* @param array $options
|
| 1029 |
+
* @return bool
|
| 1030 |
+
* @throws Exception
|
| 1031 |
+
*/
|
| 1032 |
+
public function saveContact( $websiteId, $storeId, $contact_data, array $options=array() )
|
| 1033 |
+
{
|
| 1034 |
+
/* @var $dataHelper Techtwo_Mailplus_Helper_Data */
|
| 1035 |
+
$dataHelper = Mage::helper('mailplus');
|
| 1036 |
+
/* @var $configHelper Techtwo_Mailplus_Helper_Config */
|
| 1037 |
+
$configHelper = Mage::helper('mailplus/config');
|
| 1038 |
+
|
| 1039 |
+
if ($storeId != 0 && !$configHelper->syncActiveForStore($storeId)) {
|
| 1040 |
+
return $this;
|
| 1041 |
+
} else if (!$configHelper->syncActiveForSite($websiteId)) {
|
| 1042 |
+
return $this;
|
| 1043 |
+
}
|
| 1044 |
+
|
| 1045 |
+
$options = array_merge( array(
|
| 1046 |
+
'update' => TRUE,
|
| 1047 |
+
'purge' => FALSE,
|
| 1048 |
+
), $options);
|
| 1049 |
+
|
| 1050 |
+
$data = array(
|
| 1051 |
+
'purge' => (bool) $options['purge'],
|
| 1052 |
+
'update' => (bool) $options['update'],
|
| 1053 |
+
'contact' => $contact_data
|
| 1054 |
+
);
|
| 1055 |
+
|
| 1056 |
+
$client = $this->getClientByWebsite($websiteId);
|
| 1057 |
+
if ( $client )
|
| 1058 |
+
{
|
| 1059 |
+
$response = $this->restPost($client, $this->_restBaseUrl().'/contact/', json_encode($data) );
|
| 1060 |
+
$client->log(__METHOD__."( externalId : {$contact_data['externalId']} )");
|
| 1061 |
+
|
| 1062 |
+
$error = $client->getError();
|
| 1063 |
+
if ( NULL !== $error )
|
| 1064 |
+
throw new Exception( $error->getMessage()."[{$error->getType()}]", $error->getCode() );
|
| 1065 |
+
}
|
| 1066 |
+
|
| 1067 |
+
return TRUE;
|
| 1068 |
+
}
|
| 1069 |
+
|
| 1070 |
+
/**
|
| 1071 |
+
* Checks if $value_to_check is a valid constant value by constant name prefix
|
| 1072 |
+
*
|
| 1073 |
+
* @param $constant_prefix
|
| 1074 |
+
* @param $value_to_check
|
| 1075 |
+
* @param null $constant_name
|
| 1076 |
+
* @return bool
|
| 1077 |
+
*/
|
| 1078 |
+
protected function _validateConstant($constant_prefix, $value_to_check, &$constant_name=NULL)
|
| 1079 |
+
{
|
| 1080 |
+
$reflection = new ReflectionClass($this);
|
| 1081 |
+
$constants = $reflection->getConstants();
|
| 1082 |
+
foreach ( $constants as $constant_name => $value )
|
| 1083 |
+
{
|
| 1084 |
+
if ( 0 === strpos($constant_name, $constant_prefix) )
|
| 1085 |
+
{
|
| 1086 |
+
if ( $value === $value_to_check )
|
| 1087 |
+
{
|
| 1088 |
+
return TRUE;
|
| 1089 |
+
}
|
| 1090 |
+
}
|
| 1091 |
+
}
|
| 1092 |
+
$constant_name = NULL;
|
| 1093 |
+
return FALSE;
|
| 1094 |
+
}
|
| 1095 |
+
|
| 1096 |
+
public function getAllPermissionBits()
|
| 1097 |
+
{
|
| 1098 |
+
$aux = array();
|
| 1099 |
+
|
| 1100 |
+
$reflection = new ReflectionClass($this);
|
| 1101 |
+
$constants = $reflection->getConstants();
|
| 1102 |
+
foreach ( $constants as $constant_name => $value )
|
| 1103 |
+
{
|
| 1104 |
+
if ( 0 === strpos($constant_name, 'PERMISSION_BIT_') )
|
| 1105 |
+
{
|
| 1106 |
+
$aux[$constant_name] = $value;
|
| 1107 |
+
}
|
| 1108 |
+
}
|
| 1109 |
+
return $aux;
|
| 1110 |
+
}
|
| 1111 |
+
|
| 1112 |
+
/**
|
| 1113 |
+
* Update a permission
|
| 1114 |
+
*
|
| 1115 |
+
* @param string $externalId The external contact id
|
| 1116 |
+
* @param int $permission
|
| 1117 |
+
* @param bool $allowed
|
| 1118 |
+
* @return bool
|
| 1119 |
+
*/
|
| 1120 |
+
public function updateContactPermission($storeId, $externalId, $permission, $allowed )
|
| 1121 |
+
{
|
| 1122 |
+
if ( !$this->_validateConstant('PERMISSION_BIT_', $permission) )
|
| 1123 |
+
Mage::throwException('Incorrect permission, see PERMISSION_BIT_ constants');
|
| 1124 |
+
|
| 1125 |
+
// now create a small user data
|
| 1126 |
+
$data = array(
|
| 1127 |
+
'externalId' => $externalId,
|
| 1128 |
+
'properties' => array(
|
| 1129 |
+
'permissions' => array(
|
| 1130 |
+
array(
|
| 1131 |
+
'bit' => $permission,
|
| 1132 |
+
'enabled' => $allowed
|
| 1133 |
+
)
|
| 1134 |
+
)
|
| 1135 |
+
)
|
| 1136 |
+
);
|
| 1137 |
+
|
| 1138 |
+
// update the contact with the new data
|
| 1139 |
+
return $this->updateContact($storeId, $data);
|
| 1140 |
+
}
|
| 1141 |
+
|
| 1142 |
+
|
| 1143 |
+
/**
|
| 1144 |
+
* Disables all permissions of the contact in MailPlus
|
| 1145 |
+
*
|
| 1146 |
+
* @param $externalId
|
| 1147 |
+
* @return bool
|
| 1148 |
+
*/
|
| 1149 |
+
public function disableContact($storeId, $externalId )
|
| 1150 |
+
{
|
| 1151 |
+
$permissionsData = array();
|
| 1152 |
+
$permissionsData[] = array(
|
| 1153 |
+
'bit' => self::PERMISSION_BIT_NEWSLETTER,
|
| 1154 |
+
'enabled' => FALSE
|
| 1155 |
+
);
|
| 1156 |
+
|
| 1157 |
+
// now create a small user data
|
| 1158 |
+
$data = array(
|
| 1159 |
+
'externalId' => $externalId,
|
| 1160 |
+
'properties' => array(
|
| 1161 |
+
'permissions' => $permissionsData
|
| 1162 |
+
)
|
| 1163 |
+
);
|
| 1164 |
+
|
| 1165 |
+
// update the contact with the new data
|
| 1166 |
+
return $this->updateContact($storeId, $data);
|
| 1167 |
+
}
|
| 1168 |
+
|
| 1169 |
+
public function clearContactPropertiesCache($websiteId)
|
| 1170 |
+
{
|
| 1171 |
+
$cache_id = __CLASS__.'_getContactProperties_' . $websiteId;
|
| 1172 |
+
/* @var $cache Varien_Cache_Core */
|
| 1173 |
+
$cache = Mage::app()->getCache();
|
| 1174 |
+
if ( $cache->load($cache_id) )
|
| 1175 |
+
$cache->remove($cache_id);
|
| 1176 |
+
return $this;
|
| 1177 |
+
}
|
| 1178 |
+
|
| 1179 |
+
/**
|
| 1180 |
+
* Retrieve all contact properties
|
| 1181 |
+
*
|
| 1182 |
+
* Contact properties is cached, you can remove it with {@link clearContactPropertiesCache()}
|
| 1183 |
+
*
|
| 1184 |
+
* @return bool|mixed
|
| 1185 |
+
*/
|
| 1186 |
+
public function getContactProperties($websiteId)
|
| 1187 |
+
{
|
| 1188 |
+
$cache_id = __CLASS__.'_getContactProperties_' . $websiteId;
|
| 1189 |
+
/* @var $cache Varien_Cache_Core */
|
| 1190 |
+
$cache = Mage::app()->getCache();
|
| 1191 |
+
$cache_data = $cache->load($cache_id);
|
| 1192 |
+
if ( $cache_data ) {
|
| 1193 |
+
$cache_data = unserialize($cache_data);
|
| 1194 |
+
if ( $cache_data ) {// might be a unserialize problem
|
| 1195 |
+
return $cache_data;
|
| 1196 |
+
}
|
| 1197 |
+
}
|
| 1198 |
+
|
| 1199 |
+
$client = $this->getClientByWebsite($websiteId);
|
| 1200 |
+
if ( NULL === $client ) {
|
| 1201 |
+
//Mage::log('MailPlus was not activated, getContactProperties is off', Zend_Log::ERR);
|
| 1202 |
+
return FALSE;
|
| 1203 |
+
}
|
| 1204 |
+
|
| 1205 |
+
try {
|
| 1206 |
+
$response = $client->restGet($this->_restBaseUrl().'/contact/properties/list');
|
| 1207 |
+
} catch (Exception $e) {
|
| 1208 |
+
Mage::logException($e);
|
| 1209 |
+
return FALSE;
|
| 1210 |
+
}
|
| 1211 |
+
|
| 1212 |
+
$client->log(__METHOD__.'()');
|
| 1213 |
+
$error = $client->getError();
|
| 1214 |
+
|
| 1215 |
+
if ( $error ) {
|
| 1216 |
+
$exception = new Exception($error->getMessage()." [{$error->getType()}]", $error->getCode());
|
| 1217 |
+
Mage::logException( $exception );
|
| 1218 |
+
return FALSE;
|
| 1219 |
+
}
|
| 1220 |
+
|
| 1221 |
+
$rawProperties = json_decode($response->getBody());
|
| 1222 |
+
|
| 1223 |
+
$aux = array();
|
| 1224 |
+
foreach ( $rawProperties as $p ) {
|
| 1225 |
+
$property = new Techtwo_Mailplus_Client_Contact_Property;
|
| 1226 |
+
$property
|
| 1227 |
+
->setName( $p->name )
|
| 1228 |
+
->setDescription( $p->description )
|
| 1229 |
+
->setType( $p->type );
|
| 1230 |
+
|
| 1231 |
+
$aux[(string)$p->name] = $property;
|
| 1232 |
+
}
|
| 1233 |
+
|
| 1234 |
+
|
| 1235 |
+
Mage::app()->getCache()->save( serialize($aux), $cache_id, array(Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Attribute_Collection::CACHE_TAG), 900 );
|
| 1236 |
+
|
| 1237 |
+
return $aux;
|
| 1238 |
+
}
|
| 1239 |
+
|
| 1240 |
+
/**
|
| 1241 |
+
* Get or create a mailplus/user from the given order.
|
| 1242 |
+
*
|
| 1243 |
+
* @param Mage_Sales_Model_Entity_Order $order
|
| 1244 |
+
*/
|
| 1245 |
+
public function getUserFromOrder($order) {
|
| 1246 |
+
$dataHelper = Mage::helper('mailplus');
|
| 1247 |
+
$user = Mage::getModel('mailplus/user');
|
| 1248 |
+
|
| 1249 |
+
if ($order->getCustomerId()) {
|
| 1250 |
+
$user->loadByCustomerId($order->getCustomerId());
|
| 1251 |
+
if (!$user->getId()) {
|
| 1252 |
+
$customer = Mage::getModel('customer/customer')->load($order->getCustomerId());
|
| 1253 |
+
$user = $dataHelper->createUserFromCustomer($customer);
|
| 1254 |
+
try {
|
| 1255 |
+
$user->save();
|
| 1256 |
+
}
|
| 1257 |
+
catch( Exception $e ) {
|
| 1258 |
+
Mage::logException($e);
|
| 1259 |
+
return null;
|
| 1260 |
+
}
|
| 1261 |
+
}
|
| 1262 |
+
} else if ($order->getCustomerGroupId() == 0) {
|
| 1263 |
+
// Order done by guest account. Check if e-mail exists and if not, create user.
|
| 1264 |
+
$email = $order->getCustomerEmail();
|
| 1265 |
+
$firstname = $order->getCustomerFirstname();
|
| 1266 |
+
$lastname = $order->getCustomerLastname();
|
| 1267 |
+
|
| 1268 |
+
if ($email) {
|
| 1269 |
+
$existingUser = $user->findByEmail($email);
|
| 1270 |
+
|
| 1271 |
+
if ($email && $existingUser->getId()) {
|
| 1272 |
+
$user = $existingUser;
|
| 1273 |
+
} else {
|
| 1274 |
+
$subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($email);
|
| 1275 |
+
if ($subscriber && $subscriber->getStatus() == Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED) {
|
| 1276 |
+
$user->setPermission( Techtwo_Mailplus_Helper_Rest::PERMISSION_BIT_NEWSLETTER, TRUE );
|
| 1277 |
+
}
|
| 1278 |
+
$user->setEnabled(TRUE);
|
| 1279 |
+
$user->setCreatets( time() );
|
| 1280 |
+
}
|
| 1281 |
+
|
| 1282 |
+
// update the user.
|
| 1283 |
+
$user->setEmail($email);
|
| 1284 |
+
$user->setFirstname($firstname);
|
| 1285 |
+
$user->setLastname($lastname);
|
| 1286 |
+
$user->setStoreId( $order->getStoreId());
|
| 1287 |
+
|
| 1288 |
+
try {
|
| 1289 |
+
$user->save();
|
| 1290 |
+
}
|
| 1291 |
+
catch( Exception $e ) {
|
| 1292 |
+
Mage::logException($e);
|
| 1293 |
+
return null;
|
| 1294 |
+
}
|
| 1295 |
+
}
|
| 1296 |
+
}
|
| 1297 |
+
|
| 1298 |
+
return $user;
|
| 1299 |
+
}
|
| 1300 |
+
|
| 1301 |
+
|
| 1302 |
+
/**
|
| 1303 |
+
* Sync the order to MailPlus.
|
| 1304 |
+
* When $checkSyncqueue is FALSE, the order will always by synced to MailPlus.
|
| 1305 |
+
* When $checkSyncqueue is TRUE, the order will only by synced to MailPlus when
|
| 1306 |
+
* the Syncqueue is empty, else it will be saved to the Syncqueue instead
|
| 1307 |
+
*
|
| 1308 |
+
* @param Mage_Sales_Model_Entity_Order $order
|
| 1309 |
+
* @param boolean $checkSyncqueue
|
| 1310 |
+
*/
|
| 1311 |
+
public function saveOrder($order, $checkSyncqueue) {
|
| 1312 |
+
$dataHelper = Mage::helper('mailplus');
|
| 1313 |
+
|
| 1314 |
+
$client = $this->getClientByStore($order->getStoreId());
|
| 1315 |
+
if ($client == NULL) {
|
| 1316 |
+
return;
|
| 1317 |
+
}
|
| 1318 |
+
|
| 1319 |
+
if ($checkSyncqueue) {
|
| 1320 |
+
$websiteId = Mage::getModel('core/store')->load($order->getStoreId())->getWebsiteId();
|
| 1321 |
+
if ($dataHelper->getSyncCount($websiteId, Techtwo_Mailplus_Model_Syncqueue::TYPE_ORDER) > 0) {
|
| 1322 |
+
/*
|
| 1323 |
+
* Do not save an order when there are still items to be synced but
|
| 1324 |
+
* save it to the queue instead
|
| 1325 |
+
*/
|
| 1326 |
+
|
| 1327 |
+
$dataHelper->saveSyncItem($websiteId, $order->getId(), Techtwo_Mailplus_Model_Syncqueue::TYPE_ORDER);
|
| 1328 |
+
return;
|
| 1329 |
+
}
|
| 1330 |
+
}
|
| 1331 |
+
|
| 1332 |
+
$orderData = array();
|
| 1333 |
+
$orderData['externalId'] = $order->getId();
|
| 1334 |
+
$orderData['date'] = date(DateTime::ATOM, strtotime($order->getCreatedAt()));
|
| 1335 |
+
|
| 1336 |
+
$user = $this->getUserFromOrder($order);
|
| 1337 |
+
if ($user === NULL) {
|
| 1338 |
+
return;
|
| 1339 |
+
}
|
| 1340 |
+
|
| 1341 |
+
$orderData['externalContactId'] = $user->getId();
|
| 1342 |
+
|
| 1343 |
+
$product_ids = array();
|
| 1344 |
+
foreach ( $order->getAllVisibleItems() as $item ) {
|
| 1345 |
+
/* @var $mailplus_product Techtwo_Mailplus_Model_Product */
|
| 1346 |
+
$mailplusProduct = Mage::getModel('mailplus/product');
|
| 1347 |
+
|
| 1348 |
+
if ($item && $item->getProductId()) {
|
| 1349 |
+
// Do not add products that are cancelled or refunded
|
| 1350 |
+
if ($item->getQtyOrdered() != $item->getQtyRefunded() &&
|
| 1351 |
+
($item->getQtyOrdered() != $item->getQtyCanceled())) {
|
| 1352 |
+
$product = $mailplusProduct->findByProductId($item->getProductId(), $order->getStoreId());
|
| 1353 |
+
|
| 1354 |
+
if (!$product->getId() ) {
|
| 1355 |
+
$orderProduct = Mage::getModel('catalog/product')->load($item->getProductId());
|
| 1356 |
+
if ($orderProduct && $orderProduct->getId()) {
|
| 1357 |
+
$this->saveProduct($orderProduct);
|
| 1358 |
+
$product = $mailplusProduct->findByProductId($item->getProductId());
|
| 1359 |
+
}
|
| 1360 |
+
}
|
| 1361 |
+
|
| 1362 |
+
if ($product->getId()) {
|
| 1363 |
+
$product_ids[]= $product->getExternalId();
|
| 1364 |
+
}
|
| 1365 |
+
}
|
| 1366 |
+
}
|
| 1367 |
+
}
|
| 1368 |
+
|
| 1369 |
+
if (count($product_ids) > 0) {
|
| 1370 |
+
$orderData['externalProductIds'] = $product_ids;
|
| 1371 |
+
|
| 1372 |
+
$refunded = $order->getTotalRefunded();
|
| 1373 |
+
if (!$refunded) {
|
| 1374 |
+
$refunded = 0;
|
| 1375 |
+
}
|
| 1376 |
+
|
| 1377 |
+
$orderData['value'] = round(($order->getGrandTotal() - $refunded) * 100); // MailPlus wants cents
|
| 1378 |
+
|
| 1379 |
+
$data = array();
|
| 1380 |
+
$data['update'] = true;
|
| 1381 |
+
$data['order'] = $orderData;
|
| 1382 |
+
|
| 1383 |
+
$response = NULL;
|
| 1384 |
+
try {
|
| 1385 |
+
$response = $this->restPost($client, $this->_restBaseUrl().'/order/', json_encode($data) );
|
| 1386 |
+
}
|
| 1387 |
+
catch (Exception $exception) {
|
| 1388 |
+
Mage::logException($exception);
|
| 1389 |
+
}
|
| 1390 |
+
|
| 1391 |
+
if ($response !== NULL) {
|
| 1392 |
+
$error = $client->getError();
|
| 1393 |
+
if ( NULL !== $error )
|
| 1394 |
+
throw new Exception( $error->getMessage()."[{$error->getType()}]", $error->getCode());
|
| 1395 |
+
}
|
| 1396 |
+
}
|
| 1397 |
+
}
|
| 1398 |
+
|
| 1399 |
+
public function deleteOrder($order) {
|
| 1400 |
+
$dataHelper = Mage::helper('mailplus');
|
| 1401 |
+
$client = $this->getClientByStore($order->getStoreId());
|
| 1402 |
+
|
| 1403 |
+
if ($client == NULL) {
|
| 1404 |
+
return;
|
| 1405 |
+
}
|
| 1406 |
+
|
| 1407 |
+
$response = NULL;
|
| 1408 |
+
try {
|
| 1409 |
+
$response = $this->restDelete($client, $this->_restBaseUrl().'/order/' . $order->getId());
|
| 1410 |
+
}
|
| 1411 |
+
catch (Exception $exception) {
|
| 1412 |
+
Mage::logException($exception);
|
| 1413 |
+
}
|
| 1414 |
+
|
| 1415 |
+
if ($response !== NULL) {
|
| 1416 |
+
$error = $client->getError();
|
| 1417 |
+
if ( NULL !== $error )
|
| 1418 |
+
Mage::logException(new Exception( $error->getMessage()."[{$error->getType()}]", $error->getCode()));
|
| 1419 |
+
}
|
| 1420 |
+
}
|
| 1421 |
+
|
| 1422 |
+
|
| 1423 |
+
public function restDelete($client, $url, $queueOnError = true) {
|
| 1424 |
+
$response = NULL;
|
| 1425 |
+
try {
|
| 1426 |
+
$response = $client->restDelete($url);
|
| 1427 |
+
if (!$queueOnError) {
|
| 1428 |
+
return $response;
|
| 1429 |
+
}
|
| 1430 |
+
$this->_checkAndQueueCall("POST", $url, NULL, $response, $client->getSiteId());
|
| 1431 |
+
}
|
| 1432 |
+
catch (Exception $e) {
|
| 1433 |
+
// rethrow when not queueing
|
| 1434 |
+
if (!$queueOnError) {
|
| 1435 |
+
throw $e;
|
| 1436 |
+
}
|
| 1437 |
+
$this->queueCall("POST", $url, NULL, $response, $e, $client->getSiteId());
|
| 1438 |
+
}
|
| 1439 |
+
|
| 1440 |
+
return $response;
|
| 1441 |
+
}
|
| 1442 |
+
|
| 1443 |
+
public function restPost($client, $url, $data, $queueOnError = true) {
|
| 1444 |
+
$response = NULL;
|
| 1445 |
+
try {
|
| 1446 |
+
$response = $client->restPost($url, $data);
|
| 1447 |
+
if (!$queueOnError) {
|
| 1448 |
+
return $response;
|
| 1449 |
+
}
|
| 1450 |
+
|
| 1451 |
+
$this->_checkAndQueueCall("POST", $url, $data, $response, $client->getSiteId());
|
| 1452 |
+
}
|
| 1453 |
+
catch (Exception $e) {
|
| 1454 |
+
// rethrow when not queueing
|
| 1455 |
+
if (!$queueOnError) {
|
| 1456 |
+
throw $e;
|
| 1457 |
+
}
|
| 1458 |
+
|
| 1459 |
+
$this->_queueCall("POST", $url, $data, $response, $e, $client->getSiteId());
|
| 1460 |
+
}
|
| 1461 |
+
|
| 1462 |
+
return $response;
|
| 1463 |
+
}
|
| 1464 |
+
|
| 1465 |
+
public function restPut($client, $url, $data, $queueOnError = true) {
|
| 1466 |
+
$response = NULL;
|
| 1467 |
+
try {
|
| 1468 |
+
$response = $client->restPut($url, $data);
|
| 1469 |
+
if (!$queueOnError) {
|
| 1470 |
+
return $response;
|
| 1471 |
+
}
|
| 1472 |
+
|
| 1473 |
+
$this->_checkAndQueueCall("PUT", $url, $data, $response, $client->getSiteId());
|
| 1474 |
+
}
|
| 1475 |
+
catch (Exception $e) {
|
| 1476 |
+
// rethrow when not queueing
|
| 1477 |
+
if (!$queueOnError) {
|
| 1478 |
+
throw $e;
|
| 1479 |
+
}
|
| 1480 |
+
$this->_queueCall("PUT", $url, $data, $response, $e, $client->getSiteId());
|
| 1481 |
+
}
|
| 1482 |
+
|
| 1483 |
+
return $response;
|
| 1484 |
+
}
|
| 1485 |
+
|
| 1486 |
+
protected function _shouldRetry($response) {
|
| 1487 |
+
if ($response == null) {
|
| 1488 |
+
return TRUE;
|
| 1489 |
+
}
|
| 1490 |
+
|
| 1491 |
+
$status = $response->getStatus();
|
| 1492 |
+
// All 200 codes are OK.
|
| 1493 |
+
if ($status >= 200 && $status < 300) {
|
| 1494 |
+
return FALSE;
|
| 1495 |
+
}
|
| 1496 |
+
|
| 1497 |
+
/*
|
| 1498 |
+
* MailPlus gives the following status codes on error:
|
| 1499 |
+
* 400: Bad request. A given value was invalid (e.g. wrong e-mail adres for a contact)
|
| 1500 |
+
* 401: Unauthorized. Wrong credentials (key and secret) given
|
| 1501 |
+
* 404: Not found. The given resource does not exists (e.g. when doing an update on a contact which does not exists in MailPlus)
|
| 1502 |
+
*
|
| 1503 |
+
* These should not be retried
|
| 1504 |
+
*/
|
| 1505 |
+
|
| 1506 |
+
if ($status == 400 || $status == 401 || $status == 404) {
|
| 1507 |
+
return FALSE;
|
| 1508 |
+
}
|
| 1509 |
+
|
| 1510 |
+
return TRUE;
|
| 1511 |
+
}
|
| 1512 |
+
|
| 1513 |
+
protected function _checkAndQueueCall($method, $url, $data, $response, $websiteId) {
|
| 1514 |
+
if ($this->_shouldRetry($response)) {
|
| 1515 |
+
$this->_queueCall($method, $url, $data, $response, NULL, $websiteId);
|
| 1516 |
+
}
|
| 1517 |
+
}
|
| 1518 |
+
|
| 1519 |
+
protected function _queueCall($method, $origUrl, $data, $response, $exception, $websiteId) {
|
| 1520 |
+
$url = substr($origUrl, strlen($this->_restBaseUrl()));
|
| 1521 |
+
|
| 1522 |
+
$queueItem = Mage::getModel('mailplus/restqueue');
|
| 1523 |
+
$queueItem->setMethod($method);
|
| 1524 |
+
$queueItem->setUrl($url);
|
| 1525 |
+
$queueItem->setPayload($data);
|
| 1526 |
+
$queueItem->setTries(1);
|
| 1527 |
+
|
| 1528 |
+
if ($response != null) {
|
| 1529 |
+
$queueItem->setLastError($response->getStatus());
|
| 1530 |
+
$queueItem->setLastResponse($response->getBody());
|
| 1531 |
+
} else if ($exception != null) {
|
| 1532 |
+
$queueItem->setLastError($exception->getMessage());
|
| 1533 |
+
}
|
| 1534 |
+
|
| 1535 |
+
$date = time();
|
| 1536 |
+
$queueItem->setCreatedAt($date);
|
| 1537 |
+
$queueItem->setLastRunAt($date);
|
| 1538 |
+
$queueItem->setSite($websiteId);
|
| 1539 |
+
|
| 1540 |
+
$date = $date + 5 * 60; // Add 5 minutes
|
| 1541 |
+
$queueItem->setNextRunAt($date);
|
| 1542 |
+
|
| 1543 |
+
$queueItem->save();
|
| 1544 |
+
}
|
| 1545 |
+
|
| 1546 |
+
public function handleQueueItem($item) {
|
| 1547 |
+
$method = $item->getMethod();
|
| 1548 |
+
|
| 1549 |
+
$client = $this->getClientByWebsite($item->getSite());
|
| 1550 |
+
if ($client == null) {
|
| 1551 |
+
return;
|
| 1552 |
+
}
|
| 1553 |
+
$response = null;
|
| 1554 |
+
$exception = null;
|
| 1555 |
+
|
| 1556 |
+
try {
|
| 1557 |
+
switch ($method) {
|
| 1558 |
+
case 'POST':
|
| 1559 |
+
$response = $this->restPost($client, $this->_restBaseUrl() . $item->getUrl(), $item->getPayload(), false);
|
| 1560 |
+
break;
|
| 1561 |
+
case 'PUT':
|
| 1562 |
+
$response = $this->restPut($client, $this->_restBaseUrl() . $item->getUrl(), $item->getPayload(), false);
|
| 1563 |
+
break;
|
| 1564 |
+
case 'DELETE':
|
| 1565 |
+
$response = $this->restDelete($client, $this->_restBaseUrl() . $item->getUrl(), false);
|
| 1566 |
+
break;
|
| 1567 |
+
}
|
| 1568 |
+
}
|
| 1569 |
+
catch (Exception $e) {
|
| 1570 |
+
Mage::logException($e);
|
| 1571 |
+
$exception = $e;
|
| 1572 |
+
}
|
| 1573 |
+
|
| 1574 |
+
if ($this->_shouldRetry($response)) {
|
| 1575 |
+
$this->_reQueueItem($item, $response, $exception);
|
| 1576 |
+
} else {
|
| 1577 |
+
$item->delete();
|
| 1578 |
+
}
|
| 1579 |
+
}
|
| 1580 |
+
|
| 1581 |
+
public function _reQueueItem($item, $response, $exception) {
|
| 1582 |
+
$date = time();
|
| 1583 |
+
$tries = $item->getTries() + 1;
|
| 1584 |
+
|
| 1585 |
+
if ($tries > 6) {
|
| 1586 |
+
$item->delete();
|
| 1587 |
+
Mage::log('Removed restqueue item ' . $item->getId() . ' after 6 tries.');
|
| 1588 |
+
return;
|
| 1589 |
+
}
|
| 1590 |
+
|
| 1591 |
+
if ($response != null) {
|
| 1592 |
+
$item->setLastError($response->getStatus());
|
| 1593 |
+
$item->setLastResponse($response->getBody());
|
| 1594 |
+
} else if ($exception != null) {
|
| 1595 |
+
$item->setLastError($exception->getMessage());
|
| 1596 |
+
}
|
| 1597 |
+
|
| 1598 |
+
$item->setTries($tries);
|
| 1599 |
+
$item->setLastRunAt($date);
|
| 1600 |
+
$item->setNextRunAt($date + pow(2, $tries) * 5 * 60 ) ; // data = date + 2^tries x 5 minutes
|
| 1601 |
+
|
| 1602 |
+
$item->save();
|
| 1603 |
+
}
|
| 1604 |
+
}
|
app/code/community/Techtwo/Mailplus/Model/Abandoned/Campaign.php
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
/**
|
| 18 |
+
* @method Techtwo_Mailplus_Model_Abandoned_Campaign setCreatedAt($value)
|
| 19 |
+
* @method string getCreatedAt()
|
| 20 |
+
* @method Techtwo_Mailplus_Model_Mysql4_Abandoned_Campaign_Collection getCollection()
|
| 21 |
+
*/
|
| 22 |
+
class Techtwo_Mailplus_Model_Abandoned_Campaign extends Mage_Core_Model_Abstract
|
| 23 |
+
{
|
| 24 |
+
protected function _construct()
|
| 25 |
+
{
|
| 26 |
+
$this->_init('mailplus/abandoned_campaign');
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
protected function _beforeSave()
|
| 30 |
+
{
|
| 31 |
+
if ( !$this->getId() )
|
| 32 |
+
{
|
| 33 |
+
$this->setCreatedAt(date('Y-m-d H:i:s'));
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
return parent::_beforeSave();
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
}
|
app/code/community/Techtwo/Mailplus/Model/Bounce.php
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
class Techtwo_Mailplus_Model_Bounce extends Mage_Core_Model_Abstract
|
| 18 |
+
{
|
| 19 |
+
protected function _construct()
|
| 20 |
+
{
|
| 21 |
+
$this->_init('mailplus/bounce');
|
| 22 |
+
}
|
| 23 |
+
}
|
app/code/community/Techtwo/Mailplus/Model/Cron/Hourly.php
ADDED
|
@@ -0,0 +1,316 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
class Techtwo_Mailplus_Model_Cron_Hourly
|
| 18 |
+
{
|
| 19 |
+
// Always run once per run
|
| 20 |
+
protected static $_ran_daily_cron = FALSE;
|
| 21 |
+
|
| 22 |
+
public function run()
|
| 23 |
+
{
|
| 24 |
+
if ( self::$_ran_daily_cron ) {
|
| 25 |
+
Mage::log("MailPlus: Cron hourly already ran", Zend_Log::ERR);
|
| 26 |
+
return;
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
$currentTime = Mage::getModel('core/date')->timestamp(time());
|
| 30 |
+
Mage::getModel('mailplus/info')->loadByName(Techtwo_Mailplus_Helper_Cron::HOURLY_START)
|
| 31 |
+
->setName(Techtwo_Mailplus_Helper_Cron::HOURLY_START)
|
| 32 |
+
->setValue($currentTime)
|
| 33 |
+
->save();
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
self::$_ran_daily_cron = TRUE;
|
| 37 |
+
|
| 38 |
+
$toDate = time();
|
| 39 |
+
$fromDate = strtotime('-2 hours', $toDate);
|
| 40 |
+
|
| 41 |
+
Mage::log('Handling modified contacts + bounces from ' . date(DateTime::ATOM, $fromDate) . ' to ' . date(DateTime::ATOM, $toDate));
|
| 42 |
+
|
| 43 |
+
foreach (Mage::app()->getWebsites() as $website) {
|
| 44 |
+
$this->_modifiedContacts($website->getId(), $fromDate, $toDate);
|
| 45 |
+
$this->_processBounces($website->getId(), $fromDate, $toDate);
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
$currentTime = Mage::getModel('core/date')->timestamp(time());
|
| 49 |
+
Mage::getModel('mailplus/info')->loadByName(Techtwo_Mailplus_Helper_Cron::HOURLY_END)
|
| 50 |
+
->setName(Techtwo_Mailplus_Helper_Cron::HOURLY_END)
|
| 51 |
+
->setValue($currentTime)
|
| 52 |
+
->save();
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
/**
|
| 56 |
+
* Get mailplus bounces in magento
|
| 57 |
+
*
|
| 58 |
+
* @param $fromDate
|
| 59 |
+
* @param $toDate
|
| 60 |
+
* @return bool
|
| 61 |
+
*/
|
| 62 |
+
protected function _processBounces($websiteId, $fromDate, $toDate)
|
| 63 |
+
{
|
| 64 |
+
/* @var $rest Techtwo_Mailplus_Helper_Rest */
|
| 65 |
+
$rest = Mage::helper('mailplus/rest');
|
| 66 |
+
/* @var $config Techtwo_Mailplus_Helper_Config */
|
| 67 |
+
$config = Mage::helper('mailplus/config');
|
| 68 |
+
$response = $rest->getBounces($websiteId, $fromDate, $toDate);
|
| 69 |
+
if ( !$response )
|
| 70 |
+
return FALSE !== $response;
|
| 71 |
+
|
| 72 |
+
$mapping = $config->getMapping($websiteId);
|
| 73 |
+
|
| 74 |
+
foreach ($response as $mailplus)
|
| 75 |
+
{
|
| 76 |
+
$contact = $mailplus->contact;
|
| 77 |
+
$properties = $contact->properties;
|
| 78 |
+
|
| 79 |
+
$data = array(
|
| 80 |
+
'mailplus_id' => $contact->encryptedId,
|
| 81 |
+
'email' => $properties->email,
|
| 82 |
+
'total_received' => 0, //$contact->receivedCount, // no longer exists
|
| 83 |
+
'is_test' => $contact->testGroup? 1:0,
|
| 84 |
+
'is_customer_alerted' => '0', // ALWAYS RESET customer alert on new bounce
|
| 85 |
+
'last_bounce_date' => date('Y-m-d H:i:s', (int) $mailplus->date),
|
| 86 |
+
);
|
| 87 |
+
|
| 88 |
+
$attributeToSync = array("firstname", "lastname", "insertion");
|
| 89 |
+
|
| 90 |
+
foreach ($attributeToSync as $attribute) {
|
| 91 |
+
if (isset($mapping[$attribute])) {
|
| 92 |
+
$property = $mapping[$attribute];
|
| 93 |
+
if (isset($properties->{$property})) {
|
| 94 |
+
$data[$attribute] = $properties->{$property};
|
| 95 |
+
}
|
| 96 |
+
}
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
$model = Mage::getModel('mailplus/bounce')->load( $contact->encryptedId, 'mailplus_id' );
|
| 100 |
+
if ( $model->getId() )
|
| 101 |
+
unset($data['mailplus_id']);
|
| 102 |
+
else
|
| 103 |
+
$model->unsetData();
|
| 104 |
+
|
| 105 |
+
$model->addData($data);
|
| 106 |
+
|
| 107 |
+
try { $model->save(); }
|
| 108 |
+
catch (Exception $ex) { Mage::logException( $ex ); }
|
| 109 |
+
|
| 110 |
+
$model->clearInstance();
|
| 111 |
+
unset($model);
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
return TRUE;
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
/**
|
| 118 |
+
* Processes the modified contacts at mailplus
|
| 119 |
+
* Synchronize the changes in MailPlus back to Magento.
|
| 120 |
+
*
|
| 121 |
+
* @param $fromDate
|
| 122 |
+
* @param $toDate
|
| 123 |
+
* @return bool
|
| 124 |
+
*/
|
| 125 |
+
protected function _modifiedContacts($websiteId, $fromDate, $toDate)
|
| 126 |
+
{
|
| 127 |
+
/* @var $rest Techtwo_Mailplus_Helper_Rest */
|
| 128 |
+
$rest = Mage::helper('mailplus/rest');
|
| 129 |
+
/* @var $dataHelper Techtwo_Mailplus_Helper_Data */
|
| 130 |
+
$dataHelper = Mage::helper('mailplus');
|
| 131 |
+
/* @var $config Techtwo_Mailplus_Helper_Config */
|
| 132 |
+
$config = Mage::helper('mailplus/config');
|
| 133 |
+
|
| 134 |
+
$customerAttributes = $config->getCustomerAttributes();
|
| 135 |
+
$addressAttributes = $config->getAddressAttributes();
|
| 136 |
+
|
| 137 |
+
$response = $rest->getModifiedContacts($websiteId, $fromDate, $toDate);
|
| 138 |
+
if ( !$response )
|
| 139 |
+
return FALSE!==$response;
|
| 140 |
+
|
| 141 |
+
$attributes = $config->getMapping($websiteId);
|
| 142 |
+
|
| 143 |
+
foreach ( $response as $mailplusContact ) {
|
| 144 |
+
/* @var $user Techtwo_Mailplus_Model_User */
|
| 145 |
+
$user = Mage::getModel('mailplus/user')->load($mailplusContact->externalId);
|
| 146 |
+
|
| 147 |
+
if ( !$user->getId() )
|
| 148 |
+
continue;
|
| 149 |
+
|
| 150 |
+
$this->updateUserData($user, $mailplusContact, $attributes);
|
| 151 |
+
|
| 152 |
+
$customer = $user->getCustomer();
|
| 153 |
+
$address = $customer ? $customer->getPrimaryBillingAddress() : NULL;
|
| 154 |
+
|
| 155 |
+
if ($customer) {
|
| 156 |
+
foreach ( $attributes as $attributeCode => $mailplusProperty ) {
|
| 157 |
+
$updateItem = NULL;
|
| 158 |
+
|
| 159 |
+
$offset = NULL;
|
| 160 |
+
if (preg_match(Techtwo_Mailplus_Helper_Data::IS_MULTILINE_REGEXP, $attributeCode, $matches)) {
|
| 161 |
+
$attributeCode = $matches[1];
|
| 162 |
+
$offset = $matches[2];
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
if (isset($customerAttributes[$attributeCode])) {
|
| 166 |
+
$updateItem = $customer;
|
| 167 |
+
} if (isset($addressAttributes[$attributeCode])) {
|
| 168 |
+
$updateItem = $address;
|
| 169 |
+
};
|
| 170 |
+
|
| 171 |
+
if ($updateItem) {
|
| 172 |
+
$this->updateCustomerData($updateItem, $attributeCode, $offset, $mailplusProperty, $mailplusContact);
|
| 173 |
+
}
|
| 174 |
+
}
|
| 175 |
+
$this->updateNewsletterSubscriber($customer, null, $mailplusContact);
|
| 176 |
+
$this->saveCustomer($customer, $address);
|
| 177 |
+
} else {
|
| 178 |
+
$this->updateNewsletterSubscriber(null, $user->getEmail(), $mailplusContact);
|
| 179 |
+
}
|
| 180 |
+
};
|
| 181 |
+
|
| 182 |
+
return TRUE;
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
private function saveCustomer($customer, $address) {
|
| 186 |
+
if ( $customer ) {
|
| 187 |
+
if ( $address ) {
|
| 188 |
+
$address->setCustomer( $customer ); // required to set this, otherwise the address will not be saved properly
|
| 189 |
+
try { $address->save(); }
|
| 190 |
+
catch( Exception $ex) { Mage::logException( $ex ); }
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
try { $customer->save(); }
|
| 194 |
+
catch( Exception $ex) { Mage::logException( $ex ); }
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
// do mind saving an mailplus user will start a synchronisation operation
|
| 198 |
+
//$user->setStoreId( $customer->getStore()->getId() );
|
| 199 |
+
//try { $user->save(); }
|
| 200 |
+
//catch( Exception $ex) { Mage::logException( $ex ); }
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
private function updateNewsletterSubscriber($customer, $email, $mailplusContact) {
|
| 204 |
+
$prop = 'permissions';
|
| 205 |
+
if (isset($mailplusContact->properties->{$prop})) {
|
| 206 |
+
/* @var $subscriber Mage_Newsletter_Model_Subscriber */
|
| 207 |
+
$subscriber = Mage::getModel('newsletter/subscriber');
|
| 208 |
+
|
| 209 |
+
if ($customer) {
|
| 210 |
+
$subscriber->loadByCustomer($customer);
|
| 211 |
+
}
|
| 212 |
+
if (!$subscriber->getId()) {
|
| 213 |
+
if ($customer) {
|
| 214 |
+
$subscriber->loadByEmail($customer->getDataUsingMethod('email'));
|
| 215 |
+
} else {
|
| 216 |
+
$subscriber->loadByEmail($email);
|
| 217 |
+
}
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
$permissions = $mailplusContact->properties->{$prop};
|
| 221 |
+
$enableNewsletter = false;
|
| 222 |
+
foreach ($permissions as $permission) {
|
| 223 |
+
if ($permission->bit == Techtwo_Mailplus_Helper_Rest::PERMISSION_BIT_NEWSLETTER) {
|
| 224 |
+
$enableNewsletter = $permission->enabled;
|
| 225 |
+
break;
|
| 226 |
+
}
|
| 227 |
+
}
|
| 228 |
+
|
| 229 |
+
if ($enableNewsletter) {
|
| 230 |
+
if (!$subscriber->getId()) {
|
| 231 |
+
if ($customer) {
|
| 232 |
+
$subscriber->setStoreId($customer->getStoreId());
|
| 233 |
+
$subscriber->setCustomerId($customer->getId());
|
| 234 |
+
$subscriber->setEmail($customer->getDataUsingMethod('email'));
|
| 235 |
+
}
|
| 236 |
+
}
|
| 237 |
+
|
| 238 |
+
if ($customer) {
|
| 239 |
+
if ($subscriber->getStatus() != Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED) {
|
| 240 |
+
$subscriber->setStatus(Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED);
|
| 241 |
+
}
|
| 242 |
+
$subscriber->save();
|
| 243 |
+
} else {
|
| 244 |
+
$subscriber->subscribe($email);
|
| 245 |
+
}
|
| 246 |
+
} else {
|
| 247 |
+
if ($subscriber->getId() && $subscriber->getStatus() == Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED) {
|
| 248 |
+
$subscriber->unsubscribe();
|
| 249 |
+
}
|
| 250 |
+
}
|
| 251 |
+
}
|
| 252 |
+
}
|
| 253 |
+
|
| 254 |
+
private function updateCustomerData($updateItem, $attributeCode, $offset, $mailplusProperty, $mailplusContact) {
|
| 255 |
+
if ( isset($mailplusContact->properties->{$mailplusProperty}) ) {
|
| 256 |
+
$value = $mailplusContact->properties->{$mailplusProperty};
|
| 257 |
+
|
| 258 |
+
switch ($attributeCode) {
|
| 259 |
+
case 'gender':
|
| 260 |
+
/* @var $dataHelper Techtwo_Mailplus_Helper_Data */
|
| 261 |
+
$dataHelper = Mage::helper('mailplus');
|
| 262 |
+
if ( 'M' === $value )
|
| 263 |
+
$value = $dataHelper->getMagentoGenderMaleId();
|
| 264 |
+
elseif( 'F' === $value )
|
| 265 |
+
$value = $dataHelper->getMagentoGenderFemaleId();
|
| 266 |
+
else
|
| 267 |
+
$value = '';
|
| 268 |
+
$updateItem->setDataUsingMethod($attributeCode, $value);
|
| 269 |
+
break;
|
| 270 |
+
case 'dob':
|
| 271 |
+
// Magento assumes we set the value for DoB in the setup locale
|
| 272 |
+
$localFormat = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
|
| 273 |
+
$magentoDate = Mage::app()->getLocale()->date($value)->toString($localFormat);
|
| 274 |
+
$value = $magentoDate;
|
| 275 |
+
$updateItem->setDataUsingMethod($attributeCode, $value);
|
| 276 |
+
break;
|
| 277 |
+
// Do not update the next attributes
|
| 278 |
+
case 'email': break;
|
| 279 |
+
case 'storedescription': break;
|
| 280 |
+
case 'firstpurchasedate': break;
|
| 281 |
+
case 'lastpurchasedate': break;
|
| 282 |
+
case 'group_id': break;
|
| 283 |
+
default:
|
| 284 |
+
if ($offset !== NULL) {
|
| 285 |
+
// Multiline attribute. Set the correct line
|
| 286 |
+
$array = $updateItem->getDataUsingMethod($attributeCode);
|
| 287 |
+
$array[$offset - 1] = $value;
|
| 288 |
+
$updateItem->setDataUsingMethod($attributeCode, $array);
|
| 289 |
+
} else {
|
| 290 |
+
$updateItem->setDataUsingMethod($attributeCode, $value);
|
| 291 |
+
}
|
| 292 |
+
}
|
| 293 |
+
}
|
| 294 |
+
}
|
| 295 |
+
|
| 296 |
+
private function updateUserData($user, $mailplusContact, $attributes) {
|
| 297 |
+
if (isset($attributes['firstname'])) {
|
| 298 |
+
$firstnameProp = $attributes['firstname'];
|
| 299 |
+
if ($firstnameProp) {
|
| 300 |
+
if (isset($mailplusContact->properties->{$firstnameProp})) {
|
| 301 |
+
$user->setFirstname($mailplusContact->properties->{$firstnameProp});
|
| 302 |
+
}
|
| 303 |
+
}
|
| 304 |
+
}
|
| 305 |
+
|
| 306 |
+
if (isset($attributes['lastname'])) {
|
| 307 |
+
$lastnameProp = $attributes['lastname'];
|
| 308 |
+
if ($lastnameProp) {
|
| 309 |
+
if (isset($mailplusContact->properties->{$lastnameProp})) {
|
| 310 |
+
$user->setLastname($mailplusContact->properties->{$lastnameProp});
|
| 311 |
+
}
|
| 312 |
+
}
|
| 313 |
+
}
|
| 314 |
+
}
|
| 315 |
+
|
| 316 |
+
}
|
app/code/community/Techtwo/Mailplus/Model/Cron/Often.php
ADDED
|
@@ -0,0 +1,368 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
class Techtwo_Mailplus_Model_Cron_Often
|
| 18 |
+
{
|
| 19 |
+
protected static $_ran_cron;
|
| 20 |
+
|
| 21 |
+
public function run()
|
| 22 |
+
{
|
| 23 |
+
if ( self::$_ran_cron ) {
|
| 24 |
+
return;
|
| 25 |
+
}
|
| 26 |
+
self::$_ran_cron = TRUE;
|
| 27 |
+
|
| 28 |
+
$currentTime = Mage::getModel('core/date')->timestamp(time());
|
| 29 |
+
|
| 30 |
+
Mage::getModel('mailplus/info')->loadByName(Techtwo_Mailplus_Helper_Cron::OFTEN_START)
|
| 31 |
+
->setName(Techtwo_Mailplus_Helper_Cron::OFTEN_START)
|
| 32 |
+
->setValue($currentTime)
|
| 33 |
+
->save();
|
| 34 |
+
|
| 35 |
+
$this->_abandonedCartCampaign();
|
| 36 |
+
$continue = true;
|
| 37 |
+
|
| 38 |
+
if ($continue) {
|
| 39 |
+
$continue = $this->_processRestqueue();
|
| 40 |
+
}
|
| 41 |
+
if ($continue) {
|
| 42 |
+
$continue = $this->_processScheduledSynchronizeItems();
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
$currentTime = Mage::getModel('core/date')->timestamp(time());
|
| 46 |
+
Mage::getModel('mailplus/info')->loadByName(Techtwo_Mailplus_Helper_Cron::OFTEN_END)
|
| 47 |
+
->setName(Techtwo_Mailplus_Helper_Cron::OFTEN_END)
|
| 48 |
+
->setValue($currentTime)
|
| 49 |
+
->save();
|
| 50 |
+
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
/**
|
| 55 |
+
* Process the restqueue. Returns true when the queue is empty or false
|
| 56 |
+
* when there are more items to be processed
|
| 57 |
+
*
|
| 58 |
+
* @return boolean
|
| 59 |
+
*/
|
| 60 |
+
protected function _processRestqueue() {
|
| 61 |
+
$rest = Mage::helper('mailplus/rest');
|
| 62 |
+
|
| 63 |
+
$pageSize = 100;
|
| 64 |
+
$items = Mage::getModel('mailplus/restqueue')
|
| 65 |
+
->getCollection()
|
| 66 |
+
->setOrder('next_run_at', 'ASC')
|
| 67 |
+
->addFieldToFilter('next_run_at', array('lteq' => Mage::getModel('core/date')->gmtDate()))
|
| 68 |
+
->setPageSize($pageSize);
|
| 69 |
+
|
| 70 |
+
$size = $items->getSize();
|
| 71 |
+
|
| 72 |
+
$numPages = ceil($size / $pageSize);
|
| 73 |
+
|
| 74 |
+
if ($size > 0 ) {
|
| 75 |
+
for ($page = 1; $page <= $numPages; $page++) {
|
| 76 |
+
$items->setCurPage($page);
|
| 77 |
+
|
| 78 |
+
foreach ($items as $item) {
|
| 79 |
+
$rest->handleQueueItem($item);
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
$items->clear();
|
| 83 |
+
}
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
return ($size == 0);
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
public function testAbandonedCartCampaign()
|
| 91 |
+
{
|
| 92 |
+
$this->_abandonedCartCampaign();
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
public function testProcessScheduledSynchronizeProducts()
|
| 96 |
+
{
|
| 97 |
+
$this->_processScheduledSynchronizeProducts();
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
/**
|
| 101 |
+
* Finds lost carts of the previous days and sends a lost cart campaign whenever required
|
| 102 |
+
*
|
| 103 |
+
* TODO: Split this code up to make it more readable
|
| 104 |
+
*/
|
| 105 |
+
protected function _abandonedCartCampaign()
|
| 106 |
+
{
|
| 107 |
+
/* @var $quoteCollection Mage_Sales_Model_Mysql4_Quote_Collection */
|
| 108 |
+
$quoteCollection = Mage::getModel('sales/quote')->getCollection();
|
| 109 |
+
$sales_table = $quoteCollection->getTable('sales/order');
|
| 110 |
+
$abandoned_campaign_table = $quoteCollection->getTable('mailplus/abandoned_campaign');
|
| 111 |
+
|
| 112 |
+
$baseTime = strtotime('-4 hours', time());
|
| 113 |
+
$date = date('Y-m-d H:i:s', $baseTime);
|
| 114 |
+
$yesYesterday = date('Y-m-d 00:00:00', strtotime('-7 days', $baseTime));
|
| 115 |
+
|
| 116 |
+
// send quotes only if they were filled with products
|
| 117 |
+
$quoteCollection->addFieldToFilter('items_count', array('gt' => 0));
|
| 118 |
+
|
| 119 |
+
// we want to fetch lost quotes from yesterday and the $yesYesterday
|
| 120 |
+
$quoteCollection->addFieldToFilter('updated_at', array('gt' => $yesYesterday));
|
| 121 |
+
$quoteCollection->addFieldToFilter('updated_at', array('lt' => $date));
|
| 122 |
+
|
| 123 |
+
// We don't want converted quotes and we don't want quotes we already send
|
| 124 |
+
$quoteCollection->addFieldToFilter('entity_id', array( 'nin' => new Zend_Db_Expr("SELECT `quote_id` FROM `{$sales_table}`")));
|
| 125 |
+
$quoteCollection->addFieldToFilter('entity_id', array( 'nin' => new Zend_Db_Expr("SELECT `quote_id` FROM `{$abandoned_campaign_table}`")));
|
| 126 |
+
|
| 127 |
+
/* @var $rest Techtwo_Mailplus_Helper_Rest */
|
| 128 |
+
$rest = Mage::helper('mailplus/rest');
|
| 129 |
+
|
| 130 |
+
/* @var $dataHelper Techtwo_Mailplus_Helper_Data */
|
| 131 |
+
$dataHelper = Mage::helper('mailplus');
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
$debug = 'test' === Mage::app()->getFrontController()->getRequest()->getControllerName();
|
| 135 |
+
if ( $debug )
|
| 136 |
+
echo "Abandoned cart campaign started for possible {$quoteCollection->count()}<br />\r\n";
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
/* @var $appEmulation Mage_Core_Model_App_Emulation */
|
| 140 |
+
$appEmulation = Mage::getSingleton('core/app_emulation');
|
| 141 |
+
|
| 142 |
+
foreach ( $quoteCollection as $quote )
|
| 143 |
+
{
|
| 144 |
+
/* @var $quote Mage_Sales_Model_Quote */
|
| 145 |
+
$customerId = $quote->getCustomerId()? (int) $quote->getCustomerId():NULL;
|
| 146 |
+
if ( !$customerId )
|
| 147 |
+
continue;
|
| 148 |
+
|
| 149 |
+
$storeId = $quote->getStoreId();
|
| 150 |
+
|
| 151 |
+
/* @var $customer Mage_Customer_Model_Customer */
|
| 152 |
+
$customer = Mage::getModel('customer/customer');
|
| 153 |
+
$customer->load( $customerId );
|
| 154 |
+
|
| 155 |
+
$initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($storeId);
|
| 156 |
+
|
| 157 |
+
$items = $quote->getAllVisibleItems();
|
| 158 |
+
$productList = array();
|
| 159 |
+
foreach ($items as $item) {
|
| 160 |
+
/* @var $mailplus_product Techtwo_Mailplus_Model_Product */
|
| 161 |
+
$mailplus_product = Mage::getModel('mailplus/product');
|
| 162 |
+
$mailplus_product = $mailplus_product->findByProductId( $item->getProductId(), $item->getStoreId() );
|
| 163 |
+
|
| 164 |
+
if ( $mailplus_product->getId() ) {
|
| 165 |
+
$productList []= $mailplus_product->getExternalId();
|
| 166 |
+
}
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
$extraData = array();
|
| 170 |
+
|
| 171 |
+
$link = Mage::getUrl('mailplus/use/cart', array(
|
| 172 |
+
'id' => $quote->getId(),
|
| 173 |
+
'_store' => $storeId,
|
| 174 |
+
'_store_to_url' => true
|
| 175 |
+
));
|
| 176 |
+
|
| 177 |
+
if ($productList)
|
| 178 |
+
{
|
| 179 |
+
$extraData['campaignFields'] = array(
|
| 180 |
+
array(
|
| 181 |
+
'name' => 'linktocart',
|
| 182 |
+
'value' => $link
|
| 183 |
+
),
|
| 184 |
+
array(
|
| 185 |
+
'values' => $productList,
|
| 186 |
+
'name' => 'productlist',
|
| 187 |
+
'type' => 'PRODUCTLIST'
|
| 188 |
+
)
|
| 189 |
+
);
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
/* @var $user Techtwo_Mailplus_Model_User */
|
| 193 |
+
$user = Mage::getModel('mailplus/user');
|
| 194 |
+
$user->loadByCustomer( $customer );
|
| 195 |
+
|
| 196 |
+
// If we have no mailplus/user , we make one
|
| 197 |
+
if (!$user->getId() && $user->getId()<1 )
|
| 198 |
+
{
|
| 199 |
+
/* @var $user Techtwo_Mailplus_Model_User */
|
| 200 |
+
$user = $dataHelper->createUserFromCustomer($customer);
|
| 201 |
+
try {
|
| 202 |
+
$user->save();
|
| 203 |
+
}
|
| 204 |
+
catch( Exception $e ) {
|
| 205 |
+
Mage::logException($e);
|
| 206 |
+
}
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
// Okay, we should now have a mailplus user
|
| 210 |
+
if ($user->getId() && $user->getId()>0 )
|
| 211 |
+
{
|
| 212 |
+
$rest->triggerCampaign( Techtwo_Mailplus_Helper_Rest::CAMPAIGN_ABANDONED_CART, $user->getId(), $extraData );
|
| 213 |
+
// Now ensure we don't keep sending the campaign
|
| 214 |
+
// so we just create a record in the abandoned_campaign table
|
| 215 |
+
/* @var $campaign Techtwo_Mailplus_Model_Abandoned_Campaign */
|
| 216 |
+
$campaign = Mage::getModel('mailplus/abandoned_campaign');
|
| 217 |
+
$campaign->setId( $quote->getId() );
|
| 218 |
+
$campaign->setCreatedAt(date('Y-m-d H:i:s'));
|
| 219 |
+
try { $campaign->save(); }
|
| 220 |
+
catch( Exception $e ) { Mage::logException($e); }
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
+
$appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
|
| 224 |
+
}
|
| 225 |
+
}
|
| 226 |
+
|
| 227 |
+
/**
|
| 228 |
+
* Schedules all items to be synced to MailPlus
|
| 229 |
+
*/
|
| 230 |
+
protected function _processScheduledSynchronizeItems() {
|
| 231 |
+
$mailplusHelper = Mage::helper('mailplus');
|
| 232 |
+
|
| 233 |
+
$typeOrder = Techtwo_Mailplus_Model_Syncqueue::getTypesInOrder();
|
| 234 |
+
$type = reset($typeOrder);
|
| 235 |
+
|
| 236 |
+
$itemsToSync = 200;
|
| 237 |
+
$itemsSynced = 0;
|
| 238 |
+
|
| 239 |
+
while ($itemsSynced < 200 && $type !== false) {
|
| 240 |
+
$collection = Mage::getModel('mailplus/syncqueue')->getCollection()
|
| 241 |
+
->setPageSize($itemsToSync)
|
| 242 |
+
->addFieldToFilter('synctype', array("eq" => $type))
|
| 243 |
+
->setOrder('created_at', 'ASC');
|
| 244 |
+
|
| 245 |
+
$size = $collection->getSize();
|
| 246 |
+
|
| 247 |
+
if ($size > 0) {
|
| 248 |
+
$collection->setCurPage(1);
|
| 249 |
+
foreach($collection as $item) {
|
| 250 |
+
try {
|
| 251 |
+
$this->syncSyncItem($item);
|
| 252 |
+
}
|
| 253 |
+
catch( Exception $ex) {
|
| 254 |
+
Mage::logException($ex);
|
| 255 |
+
}
|
| 256 |
+
$item->delete();
|
| 257 |
+
$itemsSynced++;
|
| 258 |
+
}
|
| 259 |
+
$collection->clear();
|
| 260 |
+
} else {
|
| 261 |
+
$type = next($typeOrder);
|
| 262 |
+
}
|
| 263 |
+
}
|
| 264 |
+
}
|
| 265 |
+
|
| 266 |
+
/**
|
| 267 |
+
* Syncs the item (customer, order, product or subscriber) to MailPlus
|
| 268 |
+
*
|
| 269 |
+
* @param Techtwo_Mailplus_Model_Syncqueue $item
|
| 270 |
+
*/
|
| 271 |
+
public function syncSyncItem($item) {
|
| 272 |
+
$mailplusHelper = Mage::helper('mailplus');
|
| 273 |
+
$rest = Mage::helper('mailplus/rest');
|
| 274 |
+
|
| 275 |
+
switch ($item->getSynctype()) {
|
| 276 |
+
case Techtwo_Mailplus_Model_Syncqueue::TYPE_CUSTOMER:
|
| 277 |
+
/** @var $product Mage_Catalog_Model_Product */
|
| 278 |
+
$customer = Mage::getModel('customer/customer')->load($item->getSyncid());
|
| 279 |
+
|
| 280 |
+
if ($customer && $customer->getId() && $customer->getIsActive()) {
|
| 281 |
+
$userModel = Mage::getModel('mailplus/user');
|
| 282 |
+
$userModel->loadByCustomer($customer);
|
| 283 |
+
|
| 284 |
+
if (!$userModel->getId()) {
|
| 285 |
+
$userModel = $mailplusHelper->createUserFromCustomer($customer);
|
| 286 |
+
} else {
|
| 287 |
+
// Update the data
|
| 288 |
+
$userModel->setData('firstname', $customer->getData('firstname'));
|
| 289 |
+
$userModel->setData('lastname', $customer->getData('lastname'));
|
| 290 |
+
$userModel->setData('email', $customer->getData('email'));
|
| 291 |
+
}
|
| 292 |
+
$userModel->save(); // also triggers the rest call to save the customer to MailPlus
|
| 293 |
+
}
|
| 294 |
+
case Techtwo_Mailplus_Model_Syncqueue::TYPE_ORDER:
|
| 295 |
+
$order = Mage::getModel('sales/order')->load($item->getSyncid());
|
| 296 |
+
if ($order && $order->getId()) {
|
| 297 |
+
$rest->saveOrder($order, FALSE);
|
| 298 |
+
}
|
| 299 |
+
break;
|
| 300 |
+
case Techtwo_Mailplus_Model_Syncqueue::TYPE_PRODUCT:
|
| 301 |
+
$product = Mage::getModel('catalog/product')->load($item->getSyncid());
|
| 302 |
+
if ($product && $product->getId()) {
|
| 303 |
+
$rest->saveProduct($product);
|
| 304 |
+
}
|
| 305 |
+
break;
|
| 306 |
+
case Techtwo_Mailplus_Model_Syncqueue::TYPE_SUBSCRIBER:
|
| 307 |
+
/* @var $subscriberCollection Mage_Newsletter_Model_Mysql4_Subscriber_Collection */
|
| 308 |
+
$subscriber = Mage::getModel('newsletter/subscriber')->load($item->getSyncid());
|
| 309 |
+
/* @var $mailplus_user Techtwo_Mailplus_Model_User */
|
| 310 |
+
$mailplus_user = Mage::getModel('mailplus/user');
|
| 311 |
+
|
| 312 |
+
if ($subscriber->getCustomerId()) {
|
| 313 |
+
/* @var $customer Mage_Customer_Model_Customer */
|
| 314 |
+
$customer = Mage::getModel('customer/customer')->load($subscriber->getCustomerId());
|
| 315 |
+
if ( $customer && $customer->getId() ) {
|
| 316 |
+
$mailplus_user->loadByCustomer($customer);
|
| 317 |
+
if (!$mailplus_user || !$mailplus_user->getUserId()) {
|
| 318 |
+
/* Set the values from the customer. This will also set the newsletter permission
|
| 319 |
+
if needed */
|
| 320 |
+
$mailplus_user = $mailplusHelper->createUserFromCustomer($customer);
|
| 321 |
+
$mailplus_user->save();
|
| 322 |
+
return;
|
| 323 |
+
}
|
| 324 |
+
}
|
| 325 |
+
}
|
| 326 |
+
|
| 327 |
+
// Only set the values when no existing mailplus_user was found.
|
| 328 |
+
if (!$mailplus_user || !$mailplus_user->getUserId()) {
|
| 329 |
+
$mailplus_user = $mailplus_user->findByEmail($subscriber->getEmail());
|
| 330 |
+
}
|
| 331 |
+
|
| 332 |
+
// Only set the values when no existing mailplus_user was found.
|
| 333 |
+
if (!$mailplus_user || !$mailplus_user->getUserId()) {
|
| 334 |
+
$mailplus_user = Mage::getModel('mailplus/user');
|
| 335 |
+
$mailplus_user->setEmail( $subscriber->getEmail() );
|
| 336 |
+
$mailplus_user->setFirstname( '' );
|
| 337 |
+
$mailplus_user->setLastname( '' );
|
| 338 |
+
$mailplus_user->setCustomerId(NULL);
|
| 339 |
+
$mailplus_user->setStoreId( $subscriber->getStoreId() );
|
| 340 |
+
$mailplus_user->setIsTest(FALSE);
|
| 341 |
+
$mailplus_user->setCreatets(time());
|
| 342 |
+
|
| 343 |
+
if ($subscriber->getStatus() == Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED) {
|
| 344 |
+
$mailplus_user->setEnabled(true);
|
| 345 |
+
$mailplus_user->setPermission( Techtwo_Mailplus_Helper_Rest::PERMISSION_BIT_NEWSLETTER, TRUE );
|
| 346 |
+
} else {
|
| 347 |
+
$mailplus_user->setEnabled(false);
|
| 348 |
+
}
|
| 349 |
+
|
| 350 |
+
} else {
|
| 351 |
+
// user found in mailplus table. Check if the user is in MailPlus
|
| 352 |
+
$contact = $rest->getContactByExternalId($mailplus_user->getId(), $mailplus_user->getStoreId());
|
| 353 |
+
|
| 354 |
+
if (!$contact) {
|
| 355 |
+
// only update permissions when the user is not in MailPlus
|
| 356 |
+
if ($subscriber->getStatus() == Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED) {
|
| 357 |
+
$mailplus_user->setEnabled(true);
|
| 358 |
+
$mailplus_user->setPermission( Techtwo_Mailplus_Helper_Rest::PERMISSION_BIT_NEWSLETTER, TRUE );
|
| 359 |
+
} else {
|
| 360 |
+
$mailplus_user->setEnabled(false);
|
| 361 |
+
}
|
| 362 |
+
}
|
| 363 |
+
}
|
| 364 |
+
|
| 365 |
+
$mailplus_user->save();
|
| 366 |
+
}
|
| 367 |
+
}
|
| 368 |
+
}
|
app/code/community/Techtwo/Mailplus/Model/Info.php
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
class Techtwo_Mailplus_Model_Info extends Mage_Core_Model_Abstract
|
| 18 |
+
{
|
| 19 |
+
protected function _construct() {
|
| 20 |
+
$this->_init('mailplus/info');
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
public function loadByName($name) {
|
| 24 |
+
$collection = $this->getCollection()
|
| 25 |
+
->addFieldToFilter('name', $name);
|
| 26 |
+
|
| 27 |
+
$product = $collection->getFirstItem();
|
| 28 |
+
return $product;
|
| 29 |
+
}
|
| 30 |
+
}
|
app/code/community/Techtwo/Mailplus/Model/Mailing.php
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
class Techtwo_Mailplus_Model_Mailing extends Mage_Core_Model_Abstract
|
| 18 |
+
{
|
| 19 |
+
protected function _construct()
|
| 20 |
+
{
|
| 21 |
+
$this->_init('mailplus/mailing');
|
| 22 |
+
}
|
| 23 |
+
}
|
app/code/community/Techtwo/Mailplus/Model/Mysql4/Abandoned/Campaign.php
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
class Techtwo_Mailplus_Model_Mysql4_Abandoned_Campaign extends Mage_Core_Model_Mysql4_Abstract
|
| 18 |
+
{
|
| 19 |
+
protected $_isPkAutoIncrement = false;
|
| 20 |
+
|
| 21 |
+
public function _construct()
|
| 22 |
+
{
|
| 23 |
+
$this->_init('mailplus/abandoned_campaign', 'quote_id');
|
| 24 |
+
}
|
| 25 |
+
}
|
app/code/community/Techtwo/Mailplus/Model/Mysql4/Abandoned/Campaign/Collection.php
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
class Techtwo_Mailplus_Model_Mysql4_Abandoned_Campaign_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
|
| 18 |
+
{
|
| 19 |
+
public function _construct()
|
| 20 |
+
{
|
| 21 |
+
$this->_init('mailplus/abandoned_campaign');
|
| 22 |
+
}
|
| 23 |
+
}
|
app/code/community/Techtwo/Mailplus/Model/Mysql4/Bounce.php
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
class Techtwo_Mailplus_Model_Mysql4_Bounce extends Mage_Core_Model_Mysql4_Abstract
|
| 18 |
+
{
|
| 19 |
+
public function _construct()
|
| 20 |
+
{
|
| 21 |
+
$this->_init('mailplus/bounce', 'id');
|
| 22 |
+
}
|
| 23 |
+
}
|
app/code/community/Techtwo/Mailplus/Model/Mysql4/Bounce/Collection.php
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
class Techtwo_Mailplus_Model_Mysql4_Bounce_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
|
| 18 |
+
{
|
| 19 |
+
public function _construct()
|
| 20 |
+
{
|
| 21 |
+
//parent::__construct();
|
| 22 |
+
$this->_init('mailplus/bounce');
|
| 23 |
+
}
|
| 24 |
+
}
|
app/code/community/Techtwo/Mailplus/Model/Mysql4/Info.php
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
class Techtwo_Mailplus_Model_Mysql4_Info extends Mage_Core_Model_Mysql4_Abstract
|
| 18 |
+
{
|
| 19 |
+
public function _construct() {
|
| 20 |
+
$this->_init( 'mailplus/info', 'id' );
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
}
|
app/code/community/Techtwo/Mailplus/Model/Mysql4/Info/Collection.php
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
class Techtwo_Mailplus_Model_Mysql4_Info_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract {
|
| 18 |
+
|
| 19 |
+
public function _construct() {
|
| 20 |
+
$this->_init('mailplus/info');
|
| 21 |
+
}
|
| 22 |
+
}
|
app/code/community/Techtwo/Mailplus/Model/Mysql4/Product.php
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
class Techtwo_Mailplus_Model_Mysql4_Product extends Mage_Core_Model_Mysql4_Abstract
|
| 18 |
+
{
|
| 19 |
+
public function _construct()
|
| 20 |
+
{
|
| 21 |
+
$this->_init( 'mailplus/product', 'entity_id' );
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
/**
|
| 25 |
+
* @param Mage_Core_Model_Abstract $model
|
| 26 |
+
* @return Mage_Core_Model_Mysql4_Abstract
|
| 27 |
+
*/
|
| 28 |
+
protected function _beforeSave(Mage_Core_Model_Abstract $model)
|
| 29 |
+
{
|
| 30 |
+
$datetime = date('Y-m-d H:i:s');
|
| 31 |
+
if (!$model->getId())
|
| 32 |
+
{
|
| 33 |
+
$model->setCreatedAt( $datetime );
|
| 34 |
+
}
|
| 35 |
+
$model->setUpdatedAt( $datetime );
|
| 36 |
+
|
| 37 |
+
return parent::_beforeSave($model);
|
| 38 |
+
}
|
| 39 |
+
}
|
app/code/community/Techtwo/Mailplus/Model/Mysql4/Product/Collection.php
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
class Techtwo_Mailplus_Model_Mysql4_Product_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
|
| 18 |
+
{
|
| 19 |
+
public function _construct()
|
| 20 |
+
{
|
| 21 |
+
$this->_init('mailplus/product');
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
public function getAllStoreIdsByProductId( $product_id )
|
| 25 |
+
{
|
| 26 |
+
$db = $this->getConnection();
|
| 27 |
+
|
| 28 |
+
$select = new Varien_Db_Select( $db );
|
| 29 |
+
$select->from( $this->getMainTable(), array('store_id') )->where( 'catalog_product_entity_id = ?', $product_id );
|
| 30 |
+
//echo $select."<br />\r\n";
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
//$this->_fetchAll( $select ); // could be used for automatic cache
|
| 34 |
+
$result = $db->fetchCol( $select );
|
| 35 |
+
|
| 36 |
+
// echo "<pre>" . print_r($result, true) . "</pre>";
|
| 37 |
+
|
| 38 |
+
return $result;
|
| 39 |
+
|
| 40 |
+
}
|
| 41 |
+
}
|
app/code/community/Techtwo/Mailplus/Model/Mysql4/Restqueue.php
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
class Techtwo_Mailplus_Model_Mysql4_Restqueue extends Mage_Core_Model_Mysql4_Abstract
|
| 18 |
+
{
|
| 19 |
+
public function _construct()
|
| 20 |
+
{
|
| 21 |
+
$this->_init('mailplus/restqueue', 'restqueue_id');
|
| 22 |
+
}
|
| 23 |
+
}
|
app/code/community/Techtwo/Mailplus/Model/Mysql4/Restqueue/Collection.php
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
class Techtwo_Mailplus_Model_Mysql4_Restqueue_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
|
| 18 |
+
{
|
| 19 |
+
public function _construct()
|
| 20 |
+
{
|
| 21 |
+
//parent::__construct();
|
| 22 |
+
$this->_init('mailplus/restqueue');
|
| 23 |
+
}
|
| 24 |
+
}
|
| 25 |
+
?>
|
app/code/community/Techtwo/Mailplus/Model/Mysql4/Syncqueue.php
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
class Techtwo_Mailplus_Model_Mysql4_Syncqueue extends Mage_Core_Model_Mysql4_Abstract {
|
| 18 |
+
|
| 19 |
+
public function _construct() {
|
| 20 |
+
$this->_init('mailplus/syncqueue', 'syncqueue_id');
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
}
|
app/code/community/Techtwo/Mailplus/Model/Mysql4/Syncqueue/Collection.php
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
class Techtwo_Mailplus_Model_Mysql4_Syncqueue_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
|
| 18 |
+
{
|
| 19 |
+
public function _construct()
|
| 20 |
+
{
|
| 21 |
+
//parent::__construct();
|
| 22 |
+
$this->_init('mailplus/syncqueue');
|
| 23 |
+
}
|
| 24 |
+
}
|
| 25 |
+
?>
|
app/code/community/Techtwo/Mailplus/Model/Mysql4/User.php
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
class Techtwo_Mailplus_Model_Mysql4_User extends Mage_Core_Model_Mysql4_Abstract
|
| 18 |
+
{
|
| 19 |
+
//protected $_isPkAutoIncrement = false;
|
| 20 |
+
|
| 21 |
+
public function _construct()
|
| 22 |
+
{
|
| 23 |
+
$this->_init('mailplus/user', 'user_id');
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
/**
|
| 27 |
+
* Load an object by field and store id
|
| 28 |
+
*
|
| 29 |
+
* Actually the same as load, but with an additional check for where
|
| 30 |
+
*
|
| 31 |
+
* @param Mage_Core_Model_Abstract $object
|
| 32 |
+
* @param $value
|
| 33 |
+
* @param $field
|
| 34 |
+
* @param $store_id
|
| 35 |
+
* @return Techtwo_Mailplus_Model_Mysql4_User
|
| 36 |
+
*/
|
| 37 |
+
public function loadByFieldAndStore(Mage_Core_Model_Abstract $object, $value, $field, $store_id)
|
| 38 |
+
{
|
| 39 |
+
$read = $this->_getReadAdapter();
|
| 40 |
+
if ($read && !is_null($value)) {
|
| 41 |
+
|
| 42 |
+
$select = $this->_getReadAdapter()->select()
|
| 43 |
+
->from($this->getMainTable())
|
| 44 |
+
->where($this->getMainTable().'.'.$field.'=?', $value)
|
| 45 |
+
->where($this->getMainTable().'.'.'store_id'.'=?', $store_id)
|
| 46 |
+
;
|
| 47 |
+
|
| 48 |
+
$data = $read->fetchRow($select);
|
| 49 |
+
|
| 50 |
+
if ($data) {
|
| 51 |
+
$object->setData($data);
|
| 52 |
+
}
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
$this->unserializeFields($object);
|
| 56 |
+
$this->_afterLoad($object);
|
| 57 |
+
|
| 58 |
+
return $this;
|
| 59 |
+
}
|
| 60 |
+
}
|
app/code/community/Techtwo/Mailplus/Model/Mysql4/User/Collection.php
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
class Techtwo_Mailplus_Model_Mysql4_User_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
|
| 18 |
+
{
|
| 19 |
+
public function _construct()
|
| 20 |
+
{
|
| 21 |
+
//parent::__construct();
|
| 22 |
+
$this->_init('mailplus/user');
|
| 23 |
+
}
|
| 24 |
+
}
|
app/code/community/Techtwo/Mailplus/Model/Newsletter/Subscriber.php
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
/**
|
| 18 |
+
* Override the Subscriber class so no newsletter confirmation mails will be sent.
|
| 19 |
+
*/
|
| 20 |
+
class Techtwo_Mailplus_Model_Newsletter_Subscriber extends Mage_Newsletter_Model_Subscriber
|
| 21 |
+
{
|
| 22 |
+
public function sendConfirmationRequestEmail() {
|
| 23 |
+
// Dont send the request, just enable the subscriber
|
| 24 |
+
$this->setStatus(self::STATUS_SUBSCRIBED);
|
| 25 |
+
$this->save();
|
| 26 |
+
return $this;
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
public function sendConfirmationSuccessEmail() {
|
| 30 |
+
return $this;
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
public function sendUnsubscriptionEmail() {
|
| 34 |
+
return $this;
|
| 35 |
+
}
|
| 36 |
+
}
|
app/code/community/Techtwo/Mailplus/Model/Product.php
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
/**
|
| 18 |
+
* @method float getPrice()
|
| 19 |
+
* @method Techtwo_Mailplus_Model_Product setPrice( $value )
|
| 20 |
+
* @method string getCreatedAt()
|
| 21 |
+
* @method Techtwo_Mailplus_Model_Product setCreatedAt( $value )
|
| 22 |
+
* @method string getUpdatedAt()
|
| 23 |
+
* @method Techtwo_Mailplus_Model_Product setUpdatedAt( $value )
|
| 24 |
+
* @method string getStoreId()
|
| 25 |
+
* @method Techtwo_Mailplus_Model_Product setStoreId( $value )
|
| 26 |
+
* @method Techtwo_Mailplus_Model_Mysql4_Product_Collection getCollection()
|
| 27 |
+
*/
|
| 28 |
+
class Techtwo_Mailplus_Model_Product extends Mage_Core_Model_Abstract
|
| 29 |
+
{
|
| 30 |
+
public function _construct()
|
| 31 |
+
{
|
| 32 |
+
$this->_init('mailplus/product');
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
/**
|
| 36 |
+
* @param $product_id
|
| 37 |
+
* @param null $store_id
|
| 38 |
+
* @return Techtwo_Mailplus_Model_Product
|
| 39 |
+
*/
|
| 40 |
+
public function findByProductId( $product_id, $store_id=NULL )
|
| 41 |
+
{
|
| 42 |
+
if ( NULL == $store_id )
|
| 43 |
+
{
|
| 44 |
+
$store_id = Mage::app()->getStore()->getId();
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
$collection = $this->getCollection()
|
| 48 |
+
->addFieldToFilter('catalog_product_entity_id', $product_id)
|
| 49 |
+
->addFieldToFilter('store_id', $store_id);
|
| 50 |
+
|
| 51 |
+
$product = $collection->getFirstItem();
|
| 52 |
+
return $product;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
public function getExternalId()
|
| 56 |
+
{
|
| 57 |
+
return $this->getStoreId().'-'.$this->getId();
|
| 58 |
+
}
|
| 59 |
+
}
|
app/code/community/Techtwo/Mailplus/Model/Restqueue.php
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
class Techtwo_Mailplus_Model_Restqueue extends Mage_Core_Model_Abstract
|
| 18 |
+
{
|
| 19 |
+
protected function _construct()
|
| 20 |
+
{
|
| 21 |
+
parent::_construct();
|
| 22 |
+
$this->_init('mailplus/restqueue');
|
| 23 |
+
}
|
| 24 |
+
}
|
app/code/community/Techtwo/Mailplus/Model/Syncqueue.php
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
class Techtwo_Mailplus_Model_Syncqueue extends Mage_Core_Model_Abstract
|
| 18 |
+
{
|
| 19 |
+
const TYPE_CUSTOMER = "customer";
|
| 20 |
+
const TYPE_PRODUCT = "product";
|
| 21 |
+
const TYPE_ORDER = "order";
|
| 22 |
+
const TYPE_SUBSCRIBER = "subscriber";
|
| 23 |
+
|
| 24 |
+
protected function _construct() {
|
| 25 |
+
parent::_construct();
|
| 26 |
+
$this->_init('mailplus/syncqueue');
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
public static function getTypesInOrder() {
|
| 30 |
+
$result = array();
|
| 31 |
+
$result[] = Techtwo_Mailplus_Model_Syncqueue::TYPE_SUBSCRIBER;
|
| 32 |
+
$result[] = Techtwo_Mailplus_Model_Syncqueue::TYPE_CUSTOMER;
|
| 33 |
+
$result[] = Techtwo_Mailplus_Model_Syncqueue::TYPE_PRODUCT;
|
| 34 |
+
$result[] = Techtwo_Mailplus_Model_Syncqueue::TYPE_ORDER;
|
| 35 |
+
return $result;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
}
|
app/code/community/Techtwo/Mailplus/Model/System/Campaign.php
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
/**
|
| 18 |
+
* @method Techtwo_Mailplus_Model_System_Campaign setEncryptedId($value)
|
| 19 |
+
* @method string getEncryptedId()
|
| 20 |
+
* @method Techtwo_Mailplus_Model_System_Campaign setName($value)
|
| 21 |
+
* @method string getName()
|
| 22 |
+
*/
|
| 23 |
+
class Techtwo_Mailplus_Model_System_Campaign extends Varien_Object
|
| 24 |
+
{
|
| 25 |
+
protected $_triggers = array();
|
| 26 |
+
|
| 27 |
+
public function addTrigger( $encryptedId, $name )
|
| 28 |
+
{
|
| 29 |
+
$this->_triggers[$encryptedId] = $name;
|
| 30 |
+
return $this;
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
public function hasTriggers()
|
| 34 |
+
{
|
| 35 |
+
return count($this->_triggers) > 0;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
/**
|
| 39 |
+
* @return array
|
| 40 |
+
*/
|
| 41 |
+
public function getTriggers()
|
| 42 |
+
{
|
| 43 |
+
return $this->_triggers;
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
public function getFirstTriggerName()
|
| 47 |
+
{
|
| 48 |
+
if ( 0 === count($this->_triggers) )
|
| 49 |
+
return NULL;
|
| 50 |
+
|
| 51 |
+
$trigger = reset($this->_triggers);
|
| 52 |
+
return $trigger;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
public function getFirstTriggerEncryptedId()
|
| 56 |
+
{
|
| 57 |
+
if ( 0 === count($this->_triggers) )
|
| 58 |
+
return NULL;
|
| 59 |
+
|
| 60 |
+
$trigger = reset($this->_triggers);
|
| 61 |
+
return key($this->_triggers);
|
| 62 |
+
}
|
| 63 |
+
}
|
app/code/community/Techtwo/Mailplus/Model/System/Config/Source/Campaign.php
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
|
| 18 |
+
/**
|
| 19 |
+
* Used in creating options for Yes|No config value selection
|
| 20 |
+
*
|
| 21 |
+
*/
|
| 22 |
+
class Techtwo_Mailplus_Model_System_Config_Source_Campaign
|
| 23 |
+
{
|
| 24 |
+
|
| 25 |
+
/**
|
| 26 |
+
* Options getter
|
| 27 |
+
*
|
| 28 |
+
* @return array
|
| 29 |
+
*/
|
| 30 |
+
public function toOptionArray()
|
| 31 |
+
{
|
| 32 |
+
|
| 33 |
+
$aux = array();
|
| 34 |
+
|
| 35 |
+
$aux []= array(
|
| 36 |
+
'value' => '',
|
| 37 |
+
'label' => Mage::helper('adminhtml')->__('Disabled')
|
| 38 |
+
);
|
| 39 |
+
|
| 40 |
+
$triggers = $this->getTriggers();
|
| 41 |
+
if ( FALSE !== $triggers )
|
| 42 |
+
{
|
| 43 |
+
|
| 44 |
+
if ( 0 === count($triggers) )
|
| 45 |
+
{
|
| 46 |
+
$aux = array(array(
|
| 47 |
+
'value' => '',
|
| 48 |
+
'label' => Mage::helper('adminhtml')->__('No campaigns registered or cache')
|
| 49 |
+
));
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
foreach ( $triggers as $t )
|
| 53 |
+
{
|
| 54 |
+
/* @var $t Techtwo_Mailplus_Model_System_Campaign */
|
| 55 |
+
|
| 56 |
+
if (!$t->hasTriggers())
|
| 57 |
+
continue;
|
| 58 |
+
|
| 59 |
+
$aux []= array(
|
| 60 |
+
'value' => $t->getEncryptedId(),
|
| 61 |
+
'label' => "{$t->getName()}" // [{$t->getFirstTriggerName()}]
|
| 62 |
+
);
|
| 63 |
+
}
|
| 64 |
+
}
|
| 65 |
+
else
|
| 66 |
+
{
|
| 67 |
+
// this is the user current value, so if the cache cannot be used or retrieved
|
| 68 |
+
// you actually won't lose your settings upon save (and no change)
|
| 69 |
+
$aux []= array(
|
| 70 |
+
'value' => '', //Mage::getStoreConfig('mailplus/campaign/newsletter'), // keeps the current value
|
| 71 |
+
'label' => Mage::helper('mailplus')->__('Cache failed or authorize first')
|
| 72 |
+
);
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
return $aux;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
/**
|
| 80 |
+
* @return array|bool Return a array of Techtwo_Mailplus_Model_System_Campaign as triggers or FALSE on error
|
| 81 |
+
*/
|
| 82 |
+
public function getTriggers()
|
| 83 |
+
{
|
| 84 |
+
try {
|
| 85 |
+
$store = Mage::app()->getFrontController()->getRequest()->getParam('store');
|
| 86 |
+
$website = Mage::app()->getFrontController()->getRequest()->getParam('website');
|
| 87 |
+
|
| 88 |
+
/* @var $helper Techtwo_Mailplus_Helper_Rest */
|
| 89 |
+
$helper = Mage::helper('mailplus/rest');
|
| 90 |
+
$client = null;
|
| 91 |
+
if ($website)
|
| 92 |
+
$client = $helper->getClientByWebsite( $website );
|
| 93 |
+
elseif ($store)
|
| 94 |
+
$client = $helper->getClientByStore( $store );
|
| 95 |
+
|
| 96 |
+
if ( $client )
|
| 97 |
+
return $helper->getTriggers($client);
|
| 98 |
+
}
|
| 99 |
+
catch (Exception $e) {
|
| 100 |
+
Mage::logException($e);
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
return FALSE;
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
}
|
app/code/community/Techtwo/Mailplus/Model/System/Config/Source/Keepframe.php
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
class Techtwo_Mailplus_Model_System_Config_Source_Keepframe
|
| 18 |
+
{
|
| 19 |
+
/**
|
| 20 |
+
* Options getter
|
| 21 |
+
*
|
| 22 |
+
* @return array
|
| 23 |
+
*/
|
| 24 |
+
public function toOptionArray()
|
| 25 |
+
{
|
| 26 |
+
/* @var $h Techtwo_Mailplus_Helper_Data */
|
| 27 |
+
$h = Mage::helper('mailplus');
|
| 28 |
+
return array(
|
| 29 |
+
array('value' => 1, 'label' => $h->__('Fixed width and height')),
|
| 30 |
+
array('value' => 0, 'label' => $h->__('Variable width and height')),
|
| 31 |
+
);
|
| 32 |
+
}
|
| 33 |
+
}
|
app/code/community/Techtwo/Mailplus/Model/System/Config/Source/Product/Specs.php
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
class Techtwo_Mailplus_Model_System_Config_Source_Product_Specs
|
| 18 |
+
{
|
| 19 |
+
/**
|
| 20 |
+
* Options getter
|
| 21 |
+
*
|
| 22 |
+
* @return array
|
| 23 |
+
*/
|
| 24 |
+
public function toOptionArray()
|
| 25 |
+
{
|
| 26 |
+
$h = Mage::helper('mailplus');
|
| 27 |
+
$groupNames = $h->getAllAttributeGroupNames();
|
| 28 |
+
|
| 29 |
+
$options = array();
|
| 30 |
+
$options[] = array('value' => '', 'label' => 'Selecteer een groep');
|
| 31 |
+
foreach($groupNames as $name) {
|
| 32 |
+
$options[] = array('value' => $name, 'label' => $name);
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
return $options;
|
| 36 |
+
}
|
| 37 |
+
}
|
app/code/community/Techtwo/Mailplus/Model/System/Config/Source/Synchronize.php
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
class Techtwo_Mailplus_Model_System_Config_Source_Synchronize
|
| 18 |
+
{
|
| 19 |
+
/**
|
| 20 |
+
* Options getter
|
| 21 |
+
*
|
| 22 |
+
* @return array
|
| 23 |
+
*/
|
| 24 |
+
public function toOptionArray()
|
| 25 |
+
{
|
| 26 |
+
$h = Mage::helper('mailplus');
|
| 27 |
+
return array(
|
| 28 |
+
array('value' => 'all', 'label' => $h->__('Contacts and Products')),
|
| 29 |
+
array('value' => 'products', 'label' => $h->__('Only products')),
|
| 30 |
+
);
|
| 31 |
+
}
|
| 32 |
+
}
|
app/code/community/Techtwo/Mailplus/Model/System/Config/Source/Yesno/Default/No.php
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
|
| 18 |
+
/**
|
| 19 |
+
* Used in creating options for Yes|No config value selection
|
| 20 |
+
*
|
| 21 |
+
*/
|
| 22 |
+
class Techtwo_Mailplus_Model_System_Config_Source_Yesno_Default_No
|
| 23 |
+
{
|
| 24 |
+
|
| 25 |
+
/**
|
| 26 |
+
* Options getter
|
| 27 |
+
*
|
| 28 |
+
* @return array
|
| 29 |
+
*/
|
| 30 |
+
public function toOptionArray()
|
| 31 |
+
{
|
| 32 |
+
return array(
|
| 33 |
+
array('value' => 1, 'label'=>Mage::helper('adminhtml')->__('Yes')),
|
| 34 |
+
array('value' => 0, 'label'=>Mage::helper('adminhtml')->__('No').' ('.Mage::helper('adminhtml')->__('Recommended').')'),
|
| 35 |
+
);
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
}
|
app/code/community/Techtwo/Mailplus/Model/System/Config/Source/Yesno/Default/Yes.php
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
|
| 18 |
+
/**
|
| 19 |
+
* Used in creating options for Yes|No config value selection
|
| 20 |
+
*
|
| 21 |
+
*/
|
| 22 |
+
class Techtwo_Mailplus_Model_System_Config_Source_Yesno_Default_Yes
|
| 23 |
+
{
|
| 24 |
+
|
| 25 |
+
/**
|
| 26 |
+
* Options getter
|
| 27 |
+
*
|
| 28 |
+
* @return array
|
| 29 |
+
*/
|
| 30 |
+
public function toOptionArray()
|
| 31 |
+
{
|
| 32 |
+
return array(
|
| 33 |
+
array('value' => 1, 'label'=>Mage::helper('adminhtml')->__('Yes').' ('.Mage::helper('adminhtml')->__('Recommended').')'),
|
| 34 |
+
array('value' => 0, 'label'=>Mage::helper('adminhtml')->__('No')),
|
| 35 |
+
);
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
}
|
app/code/community/Techtwo/Mailplus/Model/User.php
ADDED
|
@@ -0,0 +1,495 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
/**
|
| 18 |
+
* @method string getFirstname()
|
| 19 |
+
* @method Techtwo_Mailplus_Model_User setFirstname( $value )
|
| 20 |
+
* @method string getLastname()
|
| 21 |
+
* @method Techtwo_Mailplus_Model_User setLastname( $value )
|
| 22 |
+
* @method string getEmail()
|
| 23 |
+
* @method Techtwo_Mailplus_Model_User setEmail( $value )
|
| 24 |
+
* @method string getCustomerId()
|
| 25 |
+
* @method Techtwo_Mailplus_Model_User setCustomerId( $value )
|
| 26 |
+
* @method string getEnabled()
|
| 27 |
+
* @method Techtwo_Mailplus_Model_User setEnabled( $value )
|
| 28 |
+
* @method string getStoreId()
|
| 29 |
+
* @method Techtwo_Mailplus_Model_User setCreatets($value)
|
| 30 |
+
* @method string getCreatets()
|
| 31 |
+
* @method Techtwo_Mailplus_Model_User setStoreId( $value )
|
| 32 |
+
* @method Techtwo_Mailplus_Model_Mysql4_User_Collection getCollection()
|
| 33 |
+
* @method Techtwo_Mailplus_Model_Mysql4_User _getResource()
|
| 34 |
+
*/
|
| 35 |
+
class Techtwo_Mailplus_Model_User extends Mage_Core_Model_Abstract
|
| 36 |
+
{
|
| 37 |
+
/**
|
| 38 |
+
* The cached customer instance
|
| 39 |
+
* @var Mage_Customer_Model_Customer
|
| 40 |
+
*/
|
| 41 |
+
protected $_customer;
|
| 42 |
+
|
| 43 |
+
/**
|
| 44 |
+
* A flag determines if the customer lookup was done.
|
| 45 |
+
* Helps to identify if the cache took place
|
| 46 |
+
*/
|
| 47 |
+
protected $_customer_searched;
|
| 48 |
+
|
| 49 |
+
protected $_permissions;
|
| 50 |
+
protected $_permissionsChanges = FALSE;
|
| 51 |
+
|
| 52 |
+
protected function _construct()
|
| 53 |
+
{
|
| 54 |
+
$this->_init('mailplus/user');
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
public function loadByCustomerId( $customer_id )
|
| 58 |
+
{
|
| 59 |
+
/* @var $customer Mage_Customer_Model_Customer */
|
| 60 |
+
$customer = Mage::getModel('customer/customer')->load($customer_id);
|
| 61 |
+
if ($customer && $customer->getId() && $customer->getId() >0 )
|
| 62 |
+
return $this->loadByCustomer( $customer );
|
| 63 |
+
|
| 64 |
+
if ($this->getId() && $this->getId()>0)
|
| 65 |
+
{
|
| 66 |
+
$this->clearInstance();
|
| 67 |
+
$this->unsetData();
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
return $this;
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
public function loadByCustomer( Mage_Customer_Model_Customer $customer )
|
| 74 |
+
{
|
| 75 |
+
$field = 'customer_id';
|
| 76 |
+
|
| 77 |
+
$customer_id = $customer->getId();
|
| 78 |
+
$store_id = $customer->getStore()->getId();
|
| 79 |
+
|
| 80 |
+
$this->_beforeLoad($customer_id, $field);
|
| 81 |
+
$this->_getResource()->loadByFieldAndStore($this, $customer_id, $field, $store_id);
|
| 82 |
+
$this->_afterLoad();
|
| 83 |
+
$this->setOrigData();
|
| 84 |
+
$this->_hasDataChanges = FALSE;
|
| 85 |
+
|
| 86 |
+
// after load immediately set the corresponding customer object
|
| 87 |
+
if ( $this->getId() && $this->getId() > 0 )
|
| 88 |
+
{
|
| 89 |
+
$this->setCustomer( $customer );
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
return $this;
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
/**
|
| 96 |
+
* Get the correct user by email
|
| 97 |
+
*
|
| 98 |
+
* @param $email
|
| 99 |
+
* @param null $store_id
|
| 100 |
+
* @return Techtwo_Mailplus_Model_User
|
| 101 |
+
*/
|
| 102 |
+
public function findByEmail($email)
|
| 103 |
+
{
|
| 104 |
+
$collection = $this->getCollection()
|
| 105 |
+
->addFieldToFilter('email', $email);
|
| 106 |
+
|
| 107 |
+
$user = $collection->getFirstItem();
|
| 108 |
+
return $user;
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
/**
|
| 113 |
+
* @param Mage_Customer_Model_Customer $customer
|
| 114 |
+
* @param null $store_id
|
| 115 |
+
* @return Techtwo_Mailplus_Model_User
|
| 116 |
+
*/
|
| 117 |
+
public function findByCustomer( Mage_Customer_Model_Customer $customer)
|
| 118 |
+
{
|
| 119 |
+
$collection = $this->getCollection()
|
| 120 |
+
->addFieldToFilter('customer_id', $customer->getId());
|
| 121 |
+
|
| 122 |
+
/* @var $user Techtwo_Mailplus_Model_User */
|
| 123 |
+
$user = $collection->getFirstItem();
|
| 124 |
+
if ( $user && $user->getId() && $user->getId()>0 )
|
| 125 |
+
$user->setCustomer($customer);
|
| 126 |
+
return $user;
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
/**
|
| 130 |
+
* Fetches the associated customer by the MailPlus user
|
| 131 |
+
* This customer is cached in the class.
|
| 132 |
+
*
|
| 133 |
+
* @return Mage_Customer_Model_Customer|NULL or NULL if no customer was set
|
| 134 |
+
*/
|
| 135 |
+
public function getCustomer()
|
| 136 |
+
{
|
| 137 |
+
if ( $this->_customer === NULL && $this->_customer_searched === NULL )
|
| 138 |
+
{
|
| 139 |
+
if ( $this->getCustomerId() )
|
| 140 |
+
{
|
| 141 |
+
$this->_customer = Mage::getModel('customer/customer')->load($this->getCustomerId());
|
| 142 |
+
$this->_customer_searched = TRUE;
|
| 143 |
+
if ( !$this->_customer || $this->_customer->getId() < 1 )
|
| 144 |
+
{
|
| 145 |
+
$this->_customer->clearInstance();
|
| 146 |
+
$this->_customer = NULL;
|
| 147 |
+
}
|
| 148 |
+
}
|
| 149 |
+
}
|
| 150 |
+
return $this->_customer;
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
/**
|
| 154 |
+
* Set the customer for the MailPlus (prefered over $this->getCustomerId() )
|
| 155 |
+
* @param Mage_Customer_Model_Customer $customer
|
| 156 |
+
*/
|
| 157 |
+
public function setCustomer( Mage_Customer_Model_Customer $customer )
|
| 158 |
+
{
|
| 159 |
+
// this is required for hasDataChanges to work correctly, as set will always set this on true
|
| 160 |
+
if ($this->getId()<1 || $this->getCustomerId() != $customer->getId())
|
| 161 |
+
{
|
| 162 |
+
$this->setCustomerId($customer->getId()); // could be zero too, that's ok
|
| 163 |
+
}
|
| 164 |
+
$this->_customer = $customer;
|
| 165 |
+
$this->_customer_searched = TRUE;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
/**
|
| 169 |
+
* Removes customer reference
|
| 170 |
+
* @return Mage_Core_Model_Abstract
|
| 171 |
+
*/
|
| 172 |
+
function _clearReferences()
|
| 173 |
+
{
|
| 174 |
+
if ( $this->_customer )
|
| 175 |
+
{
|
| 176 |
+
$this->_customer->clearInstance();
|
| 177 |
+
$this->_customer = NULL;
|
| 178 |
+
$this->_customer_searched = NULL;
|
| 179 |
+
}
|
| 180 |
+
return parent::_clearReferences();
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
/**
|
| 184 |
+
* Removes all permissions of the user in MailPlus.
|
| 185 |
+
*
|
| 186 |
+
* Note you should actually not delete users , but remove all permissions
|
| 187 |
+
* This won't give errors if there was no mailplus users to begin with
|
| 188 |
+
*/
|
| 189 |
+
public function delete()
|
| 190 |
+
{
|
| 191 |
+
// TODO: QUEUE on error
|
| 192 |
+
/* @var $rest Techtwo_Mailplus_Helper_Rest */
|
| 193 |
+
$rest = Mage::helper('mailplus/rest');
|
| 194 |
+
try { $rest->disableContact( $this->getStoreId(), $this->getId() ); }
|
| 195 |
+
catch( Techtwo_Mailplus_Client_Exception $ex ) {
|
| 196 |
+
if ( 'CONTACT_NOT_FOUND' !== $ex->getType() ) {
|
| 197 |
+
throw $ex;
|
| 198 |
+
}
|
| 199 |
+
}
|
| 200 |
+
catch( Exception $ex ) { throw $ex; }
|
| 201 |
+
|
| 202 |
+
return parent::delete();
|
| 203 |
+
}
|
| 204 |
+
|
| 205 |
+
/**
|
| 206 |
+
* Try to synchronize the user in mailplus
|
| 207 |
+
*
|
| 208 |
+
* @return Mage_Core_Model_Abstract
|
| 209 |
+
*/
|
| 210 |
+
public function _afterSave()
|
| 211 |
+
{
|
| 212 |
+
/* @var $rest Techtwo_Mailplus_Helper_Rest */
|
| 213 |
+
$rest = Mage::helper('mailplus/rest');
|
| 214 |
+
$customer = $this->getCustomer();
|
| 215 |
+
|
| 216 |
+
$siteId = $this->getWebsiteId();
|
| 217 |
+
|
| 218 |
+
try {
|
| 219 |
+
$rest->saveContact($siteId, $this->getStoreId(), $this->toMailplusData());
|
| 220 |
+
}
|
| 221 |
+
catch( Exception $e ) {
|
| 222 |
+
Mage::logException($e);
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
return parent::_afterSave();
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
private function addDataToAray($attributeCode, $value, $mapping, $data) {
|
| 229 |
+
if ($value && isset($mapping[$attributeCode])) {
|
| 230 |
+
$data[$mapping[$attributeCode]] = $value;
|
| 231 |
+
}
|
| 232 |
+
return $data;
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
private function userDataToMailplusData($mapping, $contact_properties) {
|
| 236 |
+
// Set this users' data
|
| 237 |
+
$contact_properties = $this->addDataToAray('email', $this->getEmail(), $mapping, $contact_properties);
|
| 238 |
+
$contact_properties = $this->addDataToAray('firstname', $this->getFirstname(), $mapping, $contact_properties);
|
| 239 |
+
$contact_properties = $this->addDataToAray('lastname', $this->getLastname(), $mapping, $contact_properties);
|
| 240 |
+
|
| 241 |
+
// Add store description dummy attribute
|
| 242 |
+
$storedescription = new Mage_Customer_Model_Attribute();
|
| 243 |
+
$storedescription->setAttributeCode('storedescription');
|
| 244 |
+
$storedescription->setFrontendLabel(Mage::helper('mailplus')->__('Storeview description'));
|
| 245 |
+
$storedescription->setIsVisible(true);
|
| 246 |
+
|
| 247 |
+
$value = Mage::helper('mailplus')->attributeToMailplusValue($this, $storedescription, null);
|
| 248 |
+
$contact_properties = $this->addDataToAray($storedescription->getAttributeCode() , $value, $mapping, $contact_properties);
|
| 249 |
+
|
| 250 |
+
return $contact_properties;
|
| 251 |
+
}
|
| 252 |
+
|
| 253 |
+
/**
|
| 254 |
+
* Convert the user to mailplus data. When there is a customer linked it will load
|
| 255 |
+
* the data from the customer.
|
| 256 |
+
*
|
| 257 |
+
* @return array
|
| 258 |
+
*/
|
| 259 |
+
public function toMailplusData()
|
| 260 |
+
{
|
| 261 |
+
/* @var $config Techtwo_Mailplus_Helper_Config */
|
| 262 |
+
$config = Mage::helper('mailplus/config');
|
| 263 |
+
/* @var $config Techtwo_Mailplus_Helper_Data */
|
| 264 |
+
$data = Mage::helper('mailplus');
|
| 265 |
+
$is_test = '1' == $this->getData('is_test');
|
| 266 |
+
|
| 267 |
+
// Make sure to load all the data first
|
| 268 |
+
if (! $this->hasData('email') )
|
| 269 |
+
$this->load($this->getId());
|
| 270 |
+
|
| 271 |
+
$contact_properties = array();
|
| 272 |
+
$aux = array(
|
| 273 |
+
'testGroup' => (bool) $is_test,
|
| 274 |
+
'externalId' => $this->getId()
|
| 275 |
+
);
|
| 276 |
+
|
| 277 |
+
$mapping = $config->getMapping($this->getWebsiteId());
|
| 278 |
+
|
| 279 |
+
$contact_properties = $this->userDataToMailplusData($mapping, $contact_properties);
|
| 280 |
+
|
| 281 |
+
// Set the data from the linked customer.
|
| 282 |
+
$customer = $this->getCustomer();
|
| 283 |
+
if ($customer) {
|
| 284 |
+
$address = $customer->getPrimaryBillingAddress();
|
| 285 |
+
|
| 286 |
+
if ( $address ) {
|
| 287 |
+
foreach ( $address->getAttributes() as $attr ) {
|
| 288 |
+
$contact_properties = $data->addAttributeToProperties($contact_properties, $attr, $address, $mapping);
|
| 289 |
+
};
|
| 290 |
+
}
|
| 291 |
+
|
| 292 |
+
$attributes = $customer->getAttributes();
|
| 293 |
+
|
| 294 |
+
/* Dummy attribute for the first purchase date */
|
| 295 |
+
$firstpurchasedate = new Mage_Customer_Model_Attribute();
|
| 296 |
+
$firstpurchasedate->setAttributeCode('firstpurchasedate');
|
| 297 |
+
$firstpurchasedate->setFrontendLabel(Mage::helper('mailplus')->__('First purchase date'));
|
| 298 |
+
$firstpurchasedate->setIsVisible(true);
|
| 299 |
+
$attributes[] = $firstpurchasedate;
|
| 300 |
+
|
| 301 |
+
/* Dummy attribute for the last purchase date */
|
| 302 |
+
$lastpurchasedate = new Mage_Customer_Model_Attribute();
|
| 303 |
+
$lastpurchasedate->setAttributeCode('lastpurchasedate');
|
| 304 |
+
$lastpurchasedate->setFrontendLabel(Mage::helper('mailplus')->__('Last purchase date'));
|
| 305 |
+
$lastpurchasedate->setIsVisible(true);
|
| 306 |
+
$attributes[] = $lastpurchasedate;
|
| 307 |
+
|
| 308 |
+
foreach ($attributes as $attr ) {
|
| 309 |
+
$contact_properties = $data->addAttributeToProperties($contact_properties, $attr, $customer, $mapping);
|
| 310 |
+
};
|
| 311 |
+
}
|
| 312 |
+
|
| 313 |
+
if ( $this->hasPermissionChanges() ) {
|
| 314 |
+
$contact_properties['permissions'] = $this->toMailplusDataPermission();
|
| 315 |
+
}
|
| 316 |
+
|
| 317 |
+
$aux['properties'] = $contact_properties;
|
| 318 |
+
return $aux;
|
| 319 |
+
}
|
| 320 |
+
|
| 321 |
+
/**
|
| 322 |
+
* Sets a permission
|
| 323 |
+
*
|
| 324 |
+
* Note: only sets the setDataChanges on an actual change.
|
| 325 |
+
*
|
| 326 |
+
* @param $permission
|
| 327 |
+
* @param $allowed
|
| 328 |
+
* @throws Exception
|
| 329 |
+
*/
|
| 330 |
+
public function setPermission( $permission, $allowed )
|
| 331 |
+
{
|
| 332 |
+
/* @var $rest Techtwo_Mailplus_Helper_Rest */
|
| 333 |
+
$rest = Mage::helper('mailplus/rest');
|
| 334 |
+
|
| 335 |
+
$permission = (int) $permission;
|
| 336 |
+
if (!in_array($permission, $rest->getAllPermissionBits()))
|
| 337 |
+
{
|
| 338 |
+
throw new Exception('Invalid permission');
|
| 339 |
+
}
|
| 340 |
+
|
| 341 |
+
$allowed = (bool) $allowed;
|
| 342 |
+
|
| 343 |
+
$this->getPermissions();
|
| 344 |
+
|
| 345 |
+
if ( FALSE !== $this->_permissions )
|
| 346 |
+
{
|
| 347 |
+
if ( array_key_exists($permission, $this->_permissions))
|
| 348 |
+
{
|
| 349 |
+
if ( $this->_permissions[$permission]->getEnabled() !== $allowed )
|
| 350 |
+
{
|
| 351 |
+
$this->setDataChanges(TRUE);
|
| 352 |
+
$this->_permissionsChanges = TRUE;
|
| 353 |
+
$this->_permissions[$permission]->setEnabled( $allowed );
|
| 354 |
+
}
|
| 355 |
+
}
|
| 356 |
+
else
|
| 357 |
+
{
|
| 358 |
+
throw new Exception("Invalid permission $permission, no such permission for contact found");
|
| 359 |
+
}
|
| 360 |
+
|
| 361 |
+
}
|
| 362 |
+
|
| 363 |
+
|
| 364 |
+
}
|
| 365 |
+
|
| 366 |
+
public function getPermissions()
|
| 367 |
+
{
|
| 368 |
+
if ( NULL === $this->_permissions )
|
| 369 |
+
{
|
| 370 |
+
/* @var $rest Techtwo_Mailplus_Helper_Rest */
|
| 371 |
+
$rest = Mage::helper('mailplus/rest');
|
| 372 |
+
|
| 373 |
+
$make_new_permission = FALSE;
|
| 374 |
+
|
| 375 |
+
if ( $this->getId() && $this->getId() > 0 )
|
| 376 |
+
{
|
| 377 |
+
$contactData = null;
|
| 378 |
+
|
| 379 |
+
try {
|
| 380 |
+
$contactData = $rest->getContactByExternalId( $this->getId(), $this->getStoreId() );
|
| 381 |
+
} catch (Exception $e) {
|
| 382 |
+
Mage::logException($e);
|
| 383 |
+
return null;
|
| 384 |
+
}
|
| 385 |
+
|
| 386 |
+
$permissions = NULL !== $contactData && isset( $contactData->properties ) && isset( $contactData->properties->permissions )? $contactData->properties->permissions:FALSE;
|
| 387 |
+
|
| 388 |
+
if ( $permissions )
|
| 389 |
+
{
|
| 390 |
+
$this->_permissions = array();
|
| 391 |
+
foreach ($permissions as $permission)
|
| 392 |
+
{
|
| 393 |
+
$p = new Techtwo_Mailplus_Client_Contact_Permission;
|
| 394 |
+
|
| 395 |
+
$bit = (int) $permission->bit;
|
| 396 |
+
|
| 397 |
+
$p->setBit($bit);
|
| 398 |
+
$p->setEnabled($permission->enabled);
|
| 399 |
+
$p->setDescription($permission->description);
|
| 400 |
+
|
| 401 |
+
$this->_permissions[$bit] = $p;
|
| 402 |
+
}
|
| 403 |
+
}
|
| 404 |
+
else
|
| 405 |
+
{
|
| 406 |
+
$make_new_permission = TRUE;
|
| 407 |
+
}
|
| 408 |
+
}
|
| 409 |
+
else
|
| 410 |
+
{
|
| 411 |
+
$make_new_permission = TRUE;
|
| 412 |
+
}
|
| 413 |
+
|
| 414 |
+
if ( $make_new_permission )
|
| 415 |
+
{
|
| 416 |
+
// User is new
|
| 417 |
+
$this->_permissions = array();
|
| 418 |
+
|
| 419 |
+
$allBits = $rest->getAllPermissionBits();
|
| 420 |
+
|
| 421 |
+
foreach ($allBits as $bit)
|
| 422 |
+
{
|
| 423 |
+
$p = new Techtwo_Mailplus_Client_Contact_Permission;
|
| 424 |
+
|
| 425 |
+
$p->setBit($bit);
|
| 426 |
+
$p->setEnabled( FALSE );
|
| 427 |
+
//$p->setDescription( '' );
|
| 428 |
+
|
| 429 |
+
$this->_permissions[$bit] = $p;
|
| 430 |
+
}
|
| 431 |
+
}
|
| 432 |
+
}
|
| 433 |
+
return $this->_permissions;
|
| 434 |
+
}
|
| 435 |
+
|
| 436 |
+
public function isPermissionAllowed($permission)
|
| 437 |
+
{
|
| 438 |
+
$this->getPermissions();
|
| 439 |
+
if ( array_key_exists($permission, $this->_permissions) )
|
| 440 |
+
{
|
| 441 |
+
/* @var $permission Techtwo_Mailplus_Client_Contact_Permission */
|
| 442 |
+
$permission = $this->_permissions[$permission];
|
| 443 |
+
return $permission->isEnabled();
|
| 444 |
+
}
|
| 445 |
+
return false;
|
| 446 |
+
}
|
| 447 |
+
|
| 448 |
+
public function hasPermissionChanges()
|
| 449 |
+
{
|
| 450 |
+
return NULL !== $this->_permissions && FALSE !== $this->_permissions && TRUE === $this->_permissionsChanges;
|
| 451 |
+
}
|
| 452 |
+
|
| 453 |
+
/**
|
| 454 |
+
* Is used in toMailPlusData() , do note, toMailPlusData won't call it of no changes were made
|
| 455 |
+
*
|
| 456 |
+
* @return array|bool
|
| 457 |
+
*/
|
| 458 |
+
public function toMailplusDataPermission()
|
| 459 |
+
{
|
| 460 |
+
$permissions = $this->getPermissions();
|
| 461 |
+
if ( !$permissions )
|
| 462 |
+
return FALSE;
|
| 463 |
+
|
| 464 |
+
$data = array();
|
| 465 |
+
foreach ($permissions as $permission)
|
| 466 |
+
{
|
| 467 |
+
/* @var $permission Techtwo_Mailplus_Client_Contact_Permission */
|
| 468 |
+
$data []= $permission->toMailPlusData();
|
| 469 |
+
}
|
| 470 |
+
|
| 471 |
+
return $data;
|
| 472 |
+
}
|
| 473 |
+
|
| 474 |
+
/**
|
| 475 |
+
* Returns the siteId where this users belongs to. When this user is linked to a customer
|
| 476 |
+
* the customer will be loaded first and the customers website will be used. When there
|
| 477 |
+
* is no customer the storeId will be used to load the store and get the siteId from the
|
| 478 |
+
* store.
|
| 479 |
+
*
|
| 480 |
+
* @return int
|
| 481 |
+
*/
|
| 482 |
+
|
| 483 |
+
public function getWebsiteId() {
|
| 484 |
+
$siteId = null;
|
| 485 |
+
$customer = $this->getCustomer();
|
| 486 |
+
|
| 487 |
+
if ($customer) {
|
| 488 |
+
$siteId = $customer->getWebsiteId();
|
| 489 |
+
} else {
|
| 490 |
+
$siteId = Mage::app()->getStore($this->getStoreId())->getWebsiteId();
|
| 491 |
+
}
|
| 492 |
+
|
| 493 |
+
return $siteId;
|
| 494 |
+
}
|
| 495 |
+
}
|
app/code/community/Techtwo/Mailplus/Observer/Config.php
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
|
| 18 |
+
class Techtwo_Mailplus_Observer_Config
|
| 19 |
+
{
|
| 20 |
+
|
| 21 |
+
public function newsletter_warning(Varien_Event_Observer $observer)
|
| 22 |
+
{
|
| 23 |
+
/* @var $controller Mage_Adminhtml_System_ConfigController */
|
| 24 |
+
$controller = $observer->getEvent()->getData('controller_action');
|
| 25 |
+
if ( 'newsletter' !== $controller->getRequest()->getParam('section') )
|
| 26 |
+
return;
|
| 27 |
+
|
| 28 |
+
Mage::getSingleton('adminhtml/session')->addNotice(
|
| 29 |
+
Mage::helper('mailplus')->__('Newsletter confirmation emails will not be sent out by Magento. Instead the MailPlus "Newsletter Campaign" will be used instead')
|
| 30 |
+
);
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
}
|
app/code/community/Techtwo/Mailplus/Observer/Customer.php
ADDED
|
@@ -0,0 +1,535 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
class Techtwo_Mailplus_Observer_Customer
|
| 18 |
+
{
|
| 19 |
+
const SESSION_CONVERSION_KEY = 'mailplus_registered_conversions';
|
| 20 |
+
|
| 21 |
+
/**
|
| 22 |
+
* Login customer
|
| 23 |
+
*
|
| 24 |
+
* Checks if MailPlus had send a bounce error. If an error was found, the bounce will be informed.
|
| 25 |
+
*
|
| 26 |
+
* @param Varien_Event_Observer $observer
|
| 27 |
+
*/
|
| 28 |
+
public function login_customer(Varien_Event_Observer $observer)
|
| 29 |
+
{
|
| 30 |
+
if ( ! Mage::getSingleton('customer/session')->isLoggedIn() )
|
| 31 |
+
return;
|
| 32 |
+
|
| 33 |
+
$customer = Mage::getSingleton('customer/session')->getCustomer();
|
| 34 |
+
/* @var $customer Mage_Customer_Model_Customer */
|
| 35 |
+
|
| 36 |
+
$bounces = Mage::getModel('mailplus/bounce')->getCollection();
|
| 37 |
+
/* @var $bounces Techtwo_Mailplus_Model_Mysql4_Bounce_Collection */
|
| 38 |
+
$bounces->getSelect()->where('email = ?', $customer->getData('email'))->limit(1)->order('last_bounce_date DESC');
|
| 39 |
+
if ( $bounces->load()->count() > 0 )
|
| 40 |
+
{
|
| 41 |
+
$bounce = $bounces->getFirstItem();
|
| 42 |
+
/* @var $bounce Techtwo_Mailplus_Model_Bounce */
|
| 43 |
+
|
| 44 |
+
// WARNING! DO NOT PUT THIS CHECK IN THE SELECT !
|
| 45 |
+
// WE HAVE USED THE SELECT SOLEY TO CHECK FOR A RECENT BOUNCE!
|
| 46 |
+
// When you would put this in the select, it will switch the following record in the list...
|
| 47 |
+
if ( '0' === $bounce->getData('is_customer_alerted') )
|
| 48 |
+
{
|
| 49 |
+
$bounce->setData('is_customer_alerted', '1');
|
| 50 |
+
$bounce->save();
|
| 51 |
+
|
| 52 |
+
$link = Mage::getUrl('customer/account/edit');
|
| 53 |
+
Mage::getSingleton('core/session')->addError(
|
| 54 |
+
sprintf(
|
| 55 |
+
Mage::helper('mailplus')->__('Your email was not reachable at %2$s, please <a href=%1$s" title="goto account settings to edit your email">correct your email</a>')
|
| 56 |
+
, $link, date('Y-m-d H:i', strtotime($bounce->getData('last_bounce_date')))
|
| 57 |
+
)
|
| 58 |
+
);
|
| 59 |
+
}
|
| 60 |
+
}
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
/**
|
| 65 |
+
* If someone was subscribed on the newsletter BEFORE he/ she became member
|
| 66 |
+
* and now registers himself/ herself without checking the newsletter
|
| 67 |
+
* Magento would still leave the subscription !
|
| 68 |
+
*
|
| 69 |
+
* This fixed the issue. When the checkbox is NOT set, you will be unsubscribed if subscribed.
|
| 70 |
+
* When that event occurs, an error will be showed to the user.
|
| 71 |
+
*/
|
| 72 |
+
public function register_customer( Varien_Event_Observer $observer )
|
| 73 |
+
{
|
| 74 |
+
/* @var $dataHelper Techtwo_Mailplus_Helper_Data */
|
| 75 |
+
$dataHelper = Mage::helper('mailplus');
|
| 76 |
+
|
| 77 |
+
if ( !$dataHelper->isSynchronizeContactsAllowed() )
|
| 78 |
+
{
|
| 79 |
+
return $this;
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
if ( ! Mage::getSingleton('customer/session')->isLoggedIn() )
|
| 83 |
+
return $this;
|
| 84 |
+
|
| 85 |
+
/* @var $customer Mage_Customer_Model_Customer */
|
| 86 |
+
$customer = Mage::getSingleton('customer/session')->getCustomer();
|
| 87 |
+
|
| 88 |
+
/* @var $rest Techtwo_Mailplus_Helper_Rest */
|
| 89 |
+
$rest = Mage::helper('mailplus/rest');
|
| 90 |
+
|
| 91 |
+
/* @var $userModel Techtwo_Mailplus_Model_User */
|
| 92 |
+
$userModel = Mage::getModel('mailplus/user');//->load( $customer->getEmail(), 'email' );
|
| 93 |
+
$userModel = $userModel->findByEmail($customer->getEmail());
|
| 94 |
+
|
| 95 |
+
if ($userModel->getId() < 1) {
|
| 96 |
+
$userModel = $dataHelper->createUserFromCustomer($customer);
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
$userModel->setCustomer($customer);
|
| 100 |
+
|
| 101 |
+
if ('1' == Mage::app()->getFrontController()->getRequest()->getPost('is_subscribed', '0') ) {
|
| 102 |
+
$userModel->setPermission( Techtwo_Mailplus_Helper_Rest::PERMISSION_BIT_NEWSLETTER, TRUE );
|
| 103 |
+
};
|
| 104 |
+
|
| 105 |
+
$userModel->save();
|
| 106 |
+
|
| 107 |
+
return $this;
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
/**
|
| 112 |
+
* Synchronizes the newsletter visitor ( if the subscriber is no customer )
|
| 113 |
+
* If the subscriber is a customer this method will just return 'true'.
|
| 114 |
+
*
|
| 115 |
+
* @param Varien_Event_Observer $observer
|
| 116 |
+
* @return bool|Techtwo_Mailplus_Observer_Customer
|
| 117 |
+
* @throws Exception
|
| 118 |
+
*/
|
| 119 |
+
public function synchronize_visitor(Varien_Event_Observer $observer)
|
| 120 |
+
{
|
| 121 |
+
/* @var $dataHelper Techtwo_Mailplus_Helper_Data */
|
| 122 |
+
$dataHelper = Mage::helper('mailplus');
|
| 123 |
+
|
| 124 |
+
if ( !$dataHelper->isSynchronizeContactsAllowed() )
|
| 125 |
+
{
|
| 126 |
+
return $this;
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
/* @var $subscriber Mage_Newsletter_Model_Subscriber */
|
| 130 |
+
$subscriber = $observer->getEvent()->getData('subscriber');
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
// Check if the subscriber is a customer, if so, the event for 'synchronize_customer' will deal with this
|
| 134 |
+
if ( '' !== $subscriber->getData('customer_id') && '0' !== $subscriber->getData('customer_id') && ((int) $subscriber->getData('customer_id')) > 0 )
|
| 135 |
+
return TRUE;
|
| 136 |
+
|
| 137 |
+
/* @var $userModel Techtwo_Mailplus_Model_User */
|
| 138 |
+
$userModel = Mage::getModel('mailplus/user')->findByEmail( $subscriber->getData('subscriber_email') );
|
| 139 |
+
$status = $subscriber->getSubscriberStatus();
|
| 140 |
+
|
| 141 |
+
$do_subscribe = $status == Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED;
|
| 142 |
+
|
| 143 |
+
/* @var $rest Techtwo_Mailplus_Helper_Rest */
|
| 144 |
+
$rest = Mage::helper('mailplus/rest');
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
// MailPlus is turned off
|
| 148 |
+
if ( !Mage::app()->getStore()->isAdmin() && !$rest->getClientByStore(Mage::app()->getStore()->getId()) )
|
| 149 |
+
return TRUE;
|
| 150 |
+
|
| 151 |
+
try
|
| 152 |
+
{
|
| 153 |
+
if ( !$userModel->getId() && $do_subscribe )
|
| 154 |
+
{
|
| 155 |
+
$userModel->setData('customer_id' , NULL);
|
| 156 |
+
$userModel->setData('mailplus_id' , NULL); // always be filled by feedback
|
| 157 |
+
$userModel->setData('enabled' , 1);
|
| 158 |
+
$userModel->setData('is_test' , 0);
|
| 159 |
+
$userModel->setData('email' , $subscriber->getData('subscriber_email'));
|
| 160 |
+
$userModel->setData('store_id' , Mage::app()->getStore()->getId());
|
| 161 |
+
$userModel->setData('createts' , time());
|
| 162 |
+
|
| 163 |
+
$userModel->save();
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
if ( $do_subscribe )
|
| 167 |
+
{
|
| 168 |
+
$rest->updateContactPermission($userModel->getStoreId(), $userModel->getId(), Techtwo_Mailplus_Helper_Rest::PERMISSION_BIT_NEWSLETTER, TRUE);
|
| 169 |
+
$rest->triggerCampaign( Techtwo_Mailplus_Helper_Rest::CAMPAIGN_NEWSLETTER, $userModel->getId() );
|
| 170 |
+
}
|
| 171 |
+
else
|
| 172 |
+
{
|
| 173 |
+
if ( $userModel->getId() )
|
| 174 |
+
$rest->disableContact($userModel->getStoreId(), $userModel->getId() );
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
}
|
| 178 |
+
catch (Exception $e)
|
| 179 |
+
{
|
| 180 |
+
throw $e;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
return $this;
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
/**
|
| 187 |
+
* Handles customer data by observing the save event
|
| 188 |
+
*
|
| 189 |
+
* @param Varien_Event_Observer $observer
|
| 190 |
+
* @return mixed
|
| 191 |
+
* @throws Exception
|
| 192 |
+
*/
|
| 193 |
+
public function synchronize_customer(Varien_Event_Observer $observer)
|
| 194 |
+
{
|
| 195 |
+
/* @var $dataHelper Techtwo_Mailplus_Helper_Data */
|
| 196 |
+
$dataHelper = Mage::helper('mailplus');
|
| 197 |
+
|
| 198 |
+
/* @var $customer Mage_Customer_Model_Customer */
|
| 199 |
+
$customer = $observer->getEvent()->getData('customer');
|
| 200 |
+
|
| 201 |
+
$store_id = $customer->getStore()->getId();
|
| 202 |
+
|
| 203 |
+
/* @var $subscriber Mage_Newsletter_Model_Subscriber */
|
| 204 |
+
$subscriber = Mage::getModel('newsletter/subscriber');
|
| 205 |
+
$subscriber->loadByCustomer($customer);
|
| 206 |
+
|
| 207 |
+
|
| 208 |
+
// Determine if this is a new account
|
| 209 |
+
if ( strtolower($customer->getData('created_in')) == 'admin' )
|
| 210 |
+
{
|
| 211 |
+
$is_new = $customer->getData('created_at') == $customer->getData('updated_at');
|
| 212 |
+
}
|
| 213 |
+
else
|
| 214 |
+
{
|
| 215 |
+
$is_new = 'account' == Mage::app()->getRequest()->getControllerName() && FALSE!==strpos(Mage::app()->getRequest()->getActionName(), 'create');
|
| 216 |
+
if ( $is_new )
|
| 217 |
+
{
|
| 218 |
+
|
| 219 |
+
/*
|
| 220 |
+
workaround register issue whereas customer->save event is invoked twice
|
| 221 |
+
When a new user creates an account, the createPostAction() is run when the form is submitted. This action invokes 'customer->save()'.
|
| 222 |
+
|
| 223 |
+
THEN, after the customer has been created, setCustomerAsLoggedIn() is called by createPostAction(). This in turn calls setCustomer(), which has this little bit of code:
|
| 224 |
+
http://stackoverflow.com/questions/5838346
|
| 225 |
+
|
| 226 |
+
this is resolved in magento 1.5+, but in Magento 1.5 we still have this compelling issue.
|
| 227 |
+
*/
|
| 228 |
+
|
| 229 |
+
|
| 230 |
+
if ( $customer->getId() === Mage::registry('Techtwo_Mailplus_Observer_Customer->synchronize_customer') )
|
| 231 |
+
return $this;
|
| 232 |
+
Mage::register('Techtwo_Mailplus_Observer_Customer->synchronize_customer', $customer->getId());
|
| 233 |
+
}
|
| 234 |
+
}
|
| 235 |
+
|
| 236 |
+
|
| 237 |
+
$current_is_subscribed = $subscriber->getStatus() == Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED;
|
| 238 |
+
$change_subscription = $customer->hasData('is_subscribed');
|
| 239 |
+
if ( $change_subscription )
|
| 240 |
+
{
|
| 241 |
+
if ( $current_is_subscribed && '1' == $customer->getData('is_subscribed') )
|
| 242 |
+
$change_subscription = FALSE;
|
| 243 |
+
elseif ( !$current_is_subscribed && '1' != $customer->getData('is_subscribed') )
|
| 244 |
+
$change_subscription = FALSE;
|
| 245 |
+
}
|
| 246 |
+
|
| 247 |
+
$wants_newsletter = $change_subscription && (TRUE === $customer->getData('is_subscribed') || '1' == $customer->getData('is_subscribed'));
|
| 248 |
+
|
| 249 |
+
// if this is a new use we do not want a newsletter ... we don't need to change anything
|
| 250 |
+
if ( $is_new && $change_subscription && !$wants_newsletter )
|
| 251 |
+
return $this;
|
| 252 |
+
|
| 253 |
+
/* Insert new MailPlus User if required */
|
| 254 |
+
/* @var $userModel Techtwo_Mailplus_Model_User */
|
| 255 |
+
$userModel = Mage::getModel('mailplus/user');
|
| 256 |
+
$userModel = $userModel->findByCustomer($customer);
|
| 257 |
+
|
| 258 |
+
// not found by customer ... maybe by email ( in that case , the user was subscribed before he/she became registered themselves)
|
| 259 |
+
if ( $userModel->getId() < 1 )
|
| 260 |
+
$userModel = $userModel->findByEmail( $customer->getEmail(), $store_id );
|
| 261 |
+
|
| 262 |
+
$is_new = $userModel->getId() < 1;
|
| 263 |
+
|
| 264 |
+
/* @var $rest Techtwo_Mailplus_Helper_Rest */
|
| 265 |
+
$rest = Mage::helper('mailplus/rest');
|
| 266 |
+
|
| 267 |
+
// ALSO send a mail to this contact after he/she has registered
|
| 268 |
+
// this also sends a welcome mail on reactivating the member
|
| 269 |
+
try
|
| 270 |
+
{
|
| 271 |
+
if ( $is_new )
|
| 272 |
+
{
|
| 273 |
+
if ( $change_subscription && $wants_newsletter )
|
| 274 |
+
{
|
| 275 |
+
$userModel = $dataHelper->createUserFromCustomer($customer);
|
| 276 |
+
$userModel->setPermission( Techtwo_Mailplus_Helper_Rest::PERMISSION_BIT_NEWSLETTER, TRUE );
|
| 277 |
+
|
| 278 |
+
$userModel->save();
|
| 279 |
+
$rest->triggerCampaign( Techtwo_Mailplus_Helper_Rest::CAMPAIGN_NEWSLETTER, $userModel->getId() );
|
| 280 |
+
}
|
| 281 |
+
else
|
| 282 |
+
$userModel = NULL;
|
| 283 |
+
}
|
| 284 |
+
else
|
| 285 |
+
{
|
| 286 |
+
$userModel->setData('customer_id', $customer->getId());
|
| 287 |
+
$userModel->setData('firstname', $customer->getData('firstname'));
|
| 288 |
+
$userModel->setData('lastname', $customer->getData('lastname'));
|
| 289 |
+
$userModel->setData('email', $customer->getData('email'));
|
| 290 |
+
|
| 291 |
+
if ( ! $change_subscription )
|
| 292 |
+
{ // subscription is not changed but user changed data
|
| 293 |
+
$userModel->save();
|
| 294 |
+
|
| 295 |
+
}
|
| 296 |
+
elseif ( $wants_newsletter )
|
| 297 |
+
{
|
| 298 |
+
$userModel->setPermission( Techtwo_Mailplus_Helper_Rest::PERMISSION_BIT_NEWSLETTER, TRUE );
|
| 299 |
+
$userModel->save();
|
| 300 |
+
$rest->triggerCampaign( Techtwo_Mailplus_Helper_Rest::CAMPAIGN_NEWSLETTER, $userModel->getId() );
|
| 301 |
+
}
|
| 302 |
+
else
|
| 303 |
+
{
|
| 304 |
+
$userModel->setPermission( Techtwo_Mailplus_Helper_Rest::PERMISSION_BIT_NEWSLETTER, FALSE );
|
| 305 |
+
$userModel->save();
|
| 306 |
+
}
|
| 307 |
+
|
| 308 |
+
}
|
| 309 |
+
}
|
| 310 |
+
catch (Exception $e)
|
| 311 |
+
{
|
| 312 |
+
Mage::logException($e);
|
| 313 |
+
throw $e;
|
| 314 |
+
}
|
| 315 |
+
|
| 316 |
+
return $this;
|
| 317 |
+
}
|
| 318 |
+
|
| 319 |
+
|
| 320 |
+
public function delete_customer(Varien_Event_Observer $observer)
|
| 321 |
+
{
|
| 322 |
+
/* @var $customer Mage_Customer_Model_Customer */
|
| 323 |
+
$customer = $observer->getEvent()->getData('customer');
|
| 324 |
+
/* @var $user Techtwo_Mailplus_Model_User */
|
| 325 |
+
$user = Mage::getModel('mailplus/user');
|
| 326 |
+
$user = $user->loadByCustomer($customer);
|
| 327 |
+
if ($user && $user->getId()) {
|
| 328 |
+
$this->deleteMailplusUser($user->getStoreId(), $user->getId());
|
| 329 |
+
}
|
| 330 |
+
return $this;
|
| 331 |
+
}
|
| 332 |
+
|
| 333 |
+
public function delete_visitor(Varien_Event_Observer $observer)
|
| 334 |
+
{
|
| 335 |
+
/* @var $customer Mage_Newsletter_Model_Subscriber */
|
| 336 |
+
$subscriber = $observer->getEvent()->getData('subscriber');
|
| 337 |
+
$userModel = Mage::getModel('mailplus/user')->load( $subscriber->getData('subscriber_email'), 'email' );
|
| 338 |
+
if ( $userModel && $userModel->getId() )
|
| 339 |
+
$this->deleteMailplusUser($userModel->getStoreId(), $userModel->getId());
|
| 340 |
+
return $this;
|
| 341 |
+
}
|
| 342 |
+
|
| 343 |
+
private function deleteMailplusUser($storeId, $externalId)
|
| 344 |
+
{
|
| 345 |
+
$rest = Mage::helper('mailplus/rest');
|
| 346 |
+
$rest->disableContact($storeId, $externalId);
|
| 347 |
+
}
|
| 348 |
+
|
| 349 |
+
/**
|
| 350 |
+
* Registers conversion on a parameter in the request url
|
| 351 |
+
*
|
| 352 |
+
* MailPlus newsletter example url
|
| 353 |
+
* http://magento.local/kitty-hats.html?utm_medium=email&utm_campaign=Nieuwsbrief&utm_content=1-8&utm_term=Kitty+hats&utm_source=Nieuwsbrief&utm_name=Kitty+hats&mpid=DBPgSjYfdL6maCi-Dcw7Fr6anKWdvvn-myMih3JhFztyVvk
|
| 354 |
+
*
|
| 355 |
+
* @param Varien_Event_Observer $observer
|
| 356 |
+
*/
|
| 357 |
+
public function register_conversion( Varien_Event_Observer $observer )
|
| 358 |
+
{
|
| 359 |
+
$front = $observer->getFront();
|
| 360 |
+
if ($front) {
|
| 361 |
+
$request = $front->getRequest();
|
| 362 |
+
$mailplus_click = $request->getParam('mpid');
|
| 363 |
+
} else {
|
| 364 |
+
/** @var $controller Mage_Core_Controller_Front_Action */
|
| 365 |
+
$controller = $observer->getControllerAction();
|
| 366 |
+
if ($controller) {
|
| 367 |
+
$mailplus_click = $controller->getRequest()->getQuery('mpid');
|
| 368 |
+
}
|
| 369 |
+
}
|
| 370 |
+
|
| 371 |
+
if ($mailplus_click) {
|
| 372 |
+
/* @var $session Mage_Core_Model_Session */
|
| 373 |
+
$session = Mage::getSingleton('core/session');
|
| 374 |
+
$data = array( Techtwo_Mailplus_Helper_Rest::CONVERSION_SHOPPINGCART => array('mpid'=>$mailplus_click, 'is_converted'=>FALSE) );
|
| 375 |
+
if ( $session->hasData(self::SESSION_CONVERSION_KEY) ) {
|
| 376 |
+
$data = array_unique(array_merge($session->getData(self::SESSION_CONVERSION_KEY), $data));
|
| 377 |
+
}
|
| 378 |
+
|
| 379 |
+
$session->setData(self::SESSION_CONVERSION_KEY, $data);
|
| 380 |
+
}
|
| 381 |
+
}
|
| 382 |
+
|
| 383 |
+
public function register_conversion_mailplus( Varien_Event_Observer $observer )
|
| 384 |
+
{
|
| 385 |
+
/* @var $session Mage_Core_Model_Session */
|
| 386 |
+
$session = Mage::getSingleton('core/session');
|
| 387 |
+
|
| 388 |
+
$ses = $session->hasData(self::SESSION_CONVERSION_KEY)? $session->getData(self::SESSION_CONVERSION_KEY):array();
|
| 389 |
+
|
| 390 |
+
if ( array_key_exists(Techtwo_Mailplus_Helper_Rest::CONVERSION_SHOPPINGCART, $ses ) )
|
| 391 |
+
{
|
| 392 |
+
$mailplus_click = $ses[Techtwo_Mailplus_Helper_Rest::CONVERSION_SHOPPINGCART]['mpid'];
|
| 393 |
+
|
| 394 |
+
if ( FALSE === $ses[Techtwo_Mailplus_Helper_Rest::CONVERSION_SHOPPINGCART]['is_converted'] )
|
| 395 |
+
{
|
| 396 |
+
if ( NULL !== $mailplus_click )
|
| 397 |
+
{
|
| 398 |
+
/* @var $rest Techtwo_Mailplus_Helper_Rest */
|
| 399 |
+
$rest = Mage::helper('mailplus/rest');
|
| 400 |
+
$rest->registerConversion(Techtwo_Mailplus_Helper_Rest::CONVERSION_SHOPPINGCART, $mailplus_click);
|
| 401 |
+
}
|
| 402 |
+
$ses[Techtwo_Mailplus_Helper_Rest::CONVERSION_SHOPPINGCART]['is_converted'] = TRUE;
|
| 403 |
+
|
| 404 |
+
$session->setData(self::SESSION_CONVERSION_KEY, $ses);
|
| 405 |
+
}
|
| 406 |
+
}
|
| 407 |
+
}
|
| 408 |
+
|
| 409 |
+
/**
|
| 410 |
+
* Create the actual conversion
|
| 411 |
+
* Triggers conversion if there is one in the session.
|
| 412 |
+
*
|
| 413 |
+
* @param Varien_Event_Observer $observer
|
| 414 |
+
* @return bool
|
| 415 |
+
*/
|
| 416 |
+
public function create_conversion( Varien_Event_Observer $observer )
|
| 417 |
+
{
|
| 418 |
+
/* @var $session Mage_Core_Model_Session */
|
| 419 |
+
$session = Mage::getSingleton('core/session');
|
| 420 |
+
$ses = $session->hasData(self::SESSION_CONVERSION_KEY)? $session->getData(self::SESSION_CONVERSION_KEY):array();
|
| 421 |
+
|
| 422 |
+
if ( ! array_key_exists(Techtwo_Mailplus_Helper_Rest::CONVERSION_SHOPPINGCART, $ses ) )
|
| 423 |
+
return TRUE;
|
| 424 |
+
|
| 425 |
+
$mailplus_click = $ses[Techtwo_Mailplus_Helper_Rest::CONVERSION_SHOPPINGCART]['mpid'];
|
| 426 |
+
|
| 427 |
+
if (NULL !== $mailplus_click) {
|
| 428 |
+
/* @var $mailplus_product Techtwo_Mailplus_Model_Product */
|
| 429 |
+
$mailplus_product = Mage::getModel('mailplus/product');
|
| 430 |
+
|
| 431 |
+
/** @var $order Mage_Sales_Model_Order */
|
| 432 |
+
$order = $observer->getOrder();
|
| 433 |
+
|
| 434 |
+
$product_ids = array();
|
| 435 |
+
foreach ( $order->getAllVisibleItems() as $item ) {
|
| 436 |
+
/* @var $item Mage_Sales_Model_Order_Item */
|
| 437 |
+
if ($item && $item->getProductId()) {
|
| 438 |
+
$product = $mailplus_product->findByProductId($item->getProductId());
|
| 439 |
+
if ( $product && $product->getId() )
|
| 440 |
+
$product_ids []= $product->getExternalId();
|
| 441 |
+
}
|
| 442 |
+
}
|
| 443 |
+
|
| 444 |
+
if (count($product_ids)) {
|
| 445 |
+
/* @var $rest Techtwo_Mailplus_Helper_Rest */
|
| 446 |
+
$rest = Mage::helper('mailplus/rest');
|
| 447 |
+
|
| 448 |
+
return $rest->convertConversion( Techtwo_Mailplus_Helper_Rest::CONVERSION_SHOPPINGCART, $mailplus_click, array(
|
| 449 |
+
'products' => $product_ids,
|
| 450 |
+
'value' => round($order->getGrandTotal()*100) // MailPlus wants cents
|
| 451 |
+
) );
|
| 452 |
+
}
|
| 453 |
+
}
|
| 454 |
+
}
|
| 455 |
+
|
| 456 |
+
private function orderToProductList($order) {
|
| 457 |
+
$productIds = array();
|
| 458 |
+
$items = $order->getAllVisibleItems();
|
| 459 |
+
|
| 460 |
+
foreach ($items as $item) {
|
| 461 |
+
$mailplus_product = Mage::getModel('mailplus/product');
|
| 462 |
+
$mailplus_product = $mailplus_product->findByProductId($item->getProductId(), $item->getStoreId());
|
| 463 |
+
|
| 464 |
+
$productIds[] = $mailplus_product->getExternalId();
|
| 465 |
+
}
|
| 466 |
+
|
| 467 |
+
return $productIds;
|
| 468 |
+
}
|
| 469 |
+
|
| 470 |
+
/**
|
| 471 |
+
* @param Varien_Event_Observer $observer
|
| 472 |
+
*/
|
| 473 |
+
public function apply_sales_order_campaign( Varien_Event_Observer $observer ) {
|
| 474 |
+
/* @var $dataHelper Techtwo_Mailplus_Helper_Data */
|
| 475 |
+
$dataHelper = Mage::helper('mailplus');
|
| 476 |
+
/* @var $rest Techtwo_Mailplus_Helper_Rest */
|
| 477 |
+
$rest = Mage::helper('mailplus/rest');
|
| 478 |
+
|
| 479 |
+
/* @var $order Mage_Sales_Model_Order */
|
| 480 |
+
$order = $observer->getOrder();
|
| 481 |
+
$originalState = $order->getOrigData('state');
|
| 482 |
+
|
| 483 |
+
if ( $order->getState() !== $originalState) {
|
| 484 |
+
// Delete the order from MailPlus when it is canceled
|
| 485 |
+
if ($order->getState() === Mage_Sales_Model_Order::STATE_CLOSED) {
|
| 486 |
+
$rest->deleteOrder($order);
|
| 487 |
+
|
| 488 |
+
} else if ($order->getState() === Mage_Sales_Model_Order::STATE_COMPLETE) {
|
| 489 |
+
// On order change to 'complete' which happens on button 'ship'
|
| 490 |
+
/* @var $user Techtwo_Mailplus_Model_User */
|
| 491 |
+
$user = $rest->getUserFromOrder($order);
|
| 492 |
+
|
| 493 |
+
if ($user && $user->getId()) {
|
| 494 |
+
try {
|
| 495 |
+
$rest->saveOrder($order, TRUE);
|
| 496 |
+
$this->triggerReviewCampaign($user, $order);
|
| 497 |
+
}
|
| 498 |
+
catch (Exception $e) {
|
| 499 |
+
Mage::logException($e);
|
| 500 |
+
}
|
| 501 |
+
}
|
| 502 |
+
}
|
| 503 |
+
} else if ($order->getState() === Mage_Sales_Model_Order::STATE_COMPLETE) {
|
| 504 |
+
try {
|
| 505 |
+
$rest->saveOrder($order, TRUE);
|
| 506 |
+
}
|
| 507 |
+
catch (Exception $e) {
|
| 508 |
+
Mage::logException($e);
|
| 509 |
+
}
|
| 510 |
+
}
|
| 511 |
+
}
|
| 512 |
+
|
| 513 |
+
private function triggerReviewCampaign($user, $order) {
|
| 514 |
+
$extraData = array();
|
| 515 |
+
$productList = $this->orderToProductList($order);
|
| 516 |
+
|
| 517 |
+
$extraData['campaignFields'] = array(
|
| 518 |
+
array(
|
| 519 |
+
'values' => $productList,
|
| 520 |
+
'name' => 'productlist',
|
| 521 |
+
'type' => 'PRODUCTLIST'
|
| 522 |
+
)
|
| 523 |
+
);
|
| 524 |
+
|
| 525 |
+
$rest = Mage::helper('mailplus/rest');
|
| 526 |
+
|
| 527 |
+
try {
|
| 528 |
+
$rest->triggerCampaign( Techtwo_Mailplus_Helper_Rest::CAMPAIGN_PRODUCT_REVIEW, $user->getId(), $extraData );
|
| 529 |
+
}
|
| 530 |
+
catch (Exception $e) {
|
| 531 |
+
Mage::logException($e);
|
| 532 |
+
}
|
| 533 |
+
}
|
| 534 |
+
|
| 535 |
+
}
|
app/code/community/Techtwo/Mailplus/Observer/Product.php
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
class Techtwo_Mailplus_Observer_Product
|
| 18 |
+
{
|
| 19 |
+
/**
|
| 20 |
+
* Synchronize product with MailPlus
|
| 21 |
+
*
|
| 22 |
+
* @param Varien_Event_Observer $observer
|
| 23 |
+
*/
|
| 24 |
+
public function synchronize_product(Varien_Event_Observer $observer)
|
| 25 |
+
{
|
| 26 |
+
/* @var $product Mage_Catalog_Model_Product */
|
| 27 |
+
$product = $observer->getProduct();
|
| 28 |
+
|
| 29 |
+
/* @var $rest Techtwo_Mailplus_Helper_Rest */
|
| 30 |
+
$rest = Mage::helper('mailplus/rest');
|
| 31 |
+
|
| 32 |
+
try { $rest->saveProduct( $observer->getProduct() ); }
|
| 33 |
+
catch (Exception $e ) { Mage::logException($e); }
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
public function delete_product(Varien_Event_Observer $observer)
|
| 37 |
+
{
|
| 38 |
+
/* @var $rest Techtwo_Mailplus_Helper_Rest */
|
| 39 |
+
$rest = Mage::helper('mailplus/rest');
|
| 40 |
+
$rest->deleteProduct( $observer->getProduct() );
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
public function apply_review_value(Varien_Event_Observer $observer)
|
| 44 |
+
{
|
| 45 |
+
/* @var $review Mage_Review_Model_Review */
|
| 46 |
+
$review = $observer->getEvent()->getObject();
|
| 47 |
+
|
| 48 |
+
if ( $review->getOrigData('status_id') != $review->getStatusId() )
|
| 49 |
+
{
|
| 50 |
+
/* @var $rest Techtwo_Mailplus_Helper_Rest */
|
| 51 |
+
$rest = Mage::helper('mailplus/rest');
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
/* @var $product Mage_Catalog_Model_Product */
|
| 55 |
+
$product = Mage::getModel('catalog/product')->load($review->getEntityPkValue());
|
| 56 |
+
|
| 57 |
+
//$productCollection = $review->getProductCollection();
|
| 58 |
+
//foreach ( $productCollection as $product )
|
| 59 |
+
|
| 60 |
+
//echo "ID:".$product->getId()."<br />\r\n";
|
| 61 |
+
$rest->saveProduct( $product );
|
| 62 |
+
}
|
| 63 |
+
}
|
| 64 |
+
}
|
app/code/community/Techtwo/Mailplus/controllers/Adminhtml/BouncesController.php
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
class Techtwo_Mailplus_Adminhtml_BouncesController extends Mage_Adminhtml_Controller_Action
|
| 18 |
+
{
|
| 19 |
+
|
| 20 |
+
public function indexAction()
|
| 21 |
+
{
|
| 22 |
+
$this->loadLayout()
|
| 23 |
+
->_setActiveMenu('mailplus')
|
| 24 |
+
//->_addContent($this->getLayout()->createBlock('mailplus/adminhtml_users')) // dynamic add content
|
| 25 |
+
->renderLayout();
|
| 26 |
+
return;
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
public function massDeleteAction()
|
| 30 |
+
{
|
| 31 |
+
$bounces_to_delete = $this->_request->getParam('mailplus_bounce_mass');
|
| 32 |
+
|
| 33 |
+
$bounceModel = Mage::getModel('mailplus/bounce');
|
| 34 |
+
foreach ( $bounces_to_delete as $id )
|
| 35 |
+
{
|
| 36 |
+
$id = (int) $id;
|
| 37 |
+
$bounceModel->load($id);
|
| 38 |
+
if ( $bounceModel->getId() )
|
| 39 |
+
$bounceModel->delete();
|
| 40 |
+
}
|
| 41 |
+
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('mailplus')->__('Bounce was successfully deleted'));
|
| 42 |
+
$this->_redirect('*/*/');
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
public function editAction()
|
| 46 |
+
{
|
| 47 |
+
/*
|
| 48 |
+
$this->loadLayout()->_setActiveMenu('newsletter')
|
| 49 |
+
//->_addContent($this->getLayout()->createBlock('mailplus/admin_mailplus_edit')) // dynamic add content
|
| 50 |
+
->renderLayout();
|
| 51 |
+
*/
|
| 52 |
+
|
| 53 |
+
$userId = $this->getRequest()->getParam('id');
|
| 54 |
+
$userModel = Mage::getModel('mailplus/user')->load($userId);
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
if ($userModel->getId() || $userId == 0)
|
| 58 |
+
{
|
| 59 |
+
|
| 60 |
+
Mage::register('mailplus_user_data', $userModel);
|
| 61 |
+
|
| 62 |
+
$this->loadLayout();
|
| 63 |
+
$this->_setActiveMenu('mailplus');
|
| 64 |
+
|
| 65 |
+
$this->_addBreadcrumb(Mage::helper('adminhtml')->__('Item Manager'), Mage::helper('adminhtml')->__('Item Manager'));
|
| 66 |
+
$this->_addBreadcrumb(Mage::helper('adminhtml')->__('Item News'), Mage::helper('adminhtml')->__('Item News'));
|
| 67 |
+
|
| 68 |
+
$this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
|
| 69 |
+
|
| 70 |
+
$this->_addContent($this->getLayout()->createBlock('mailplus/adminhtml_users_edit'))
|
| 71 |
+
->_addLeft($this->getLayout()->createBlock('mailplus/adminhtml_users_edit_tabs'));
|
| 72 |
+
|
| 73 |
+
$this->renderLayout();
|
| 74 |
+
}
|
| 75 |
+
else
|
| 76 |
+
{
|
| 77 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('mailplus')->__('Item does not exist'));
|
| 78 |
+
$this->_redirect('*/*/');
|
| 79 |
+
}
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
public function saveAction()
|
| 83 |
+
{
|
| 84 |
+
|
| 85 |
+
$data = $this->getRequest()->getPost();
|
| 86 |
+
if (!$data)
|
| 87 |
+
{
|
| 88 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('mailplus')->__('Unable to find mailplus user to save'));
|
| 89 |
+
$this->_redirect('*/*/');
|
| 90 |
+
return;
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
if (array_key_exists('mailplus_id', $data))
|
| 94 |
+
unset($data['mailplus_id']);
|
| 95 |
+
|
| 96 |
+
$customer = Mage::getModel('customer/customer');
|
| 97 |
+
if ( '0' != $data['customer_id'] && $customer->load($data['customer_id'], 'customer_id')->getId() < 1 )
|
| 98 |
+
{
|
| 99 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('mailplus')->__('Unable to find customer to save'));
|
| 100 |
+
Mage::getSingleton('adminhtml/session')->setFormData($data);
|
| 101 |
+
$this->_redirect('*/*/edit/', array( 'id' => $this->getRequest()->id ));
|
| 102 |
+
return;
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
$model = Mage::getModel('mailplus/user');
|
| 106 |
+
$model->setData($data)
|
| 107 |
+
->setId($this->getRequest()->getParam('id'));
|
| 108 |
+
|
| 109 |
+
try
|
| 110 |
+
{
|
| 111 |
+
$model->save();
|
| 112 |
+
|
| 113 |
+
$properties = array( );
|
| 114 |
+
if ( '1' == $data['is_test'] )
|
| 115 |
+
$properties['testGroup'] = 'Ja';
|
| 116 |
+
else
|
| 117 |
+
$properties['testGroup'] = 'Nee';
|
| 118 |
+
|
| 119 |
+
/* MailPlus_Queue::add( 'contacts/updateContact', array(
|
| 120 |
+
'externalContactId' => $model->getId(),
|
| 121 |
+
'keys' => array_keys($properties),
|
| 122 |
+
'values' => array_values($properties),
|
| 123 |
+
'visible' => '0' != $data['enabled'],
|
| 124 |
+
'merge' => true
|
| 125 |
+
),
|
| 126 |
+
$data['customer_id']
|
| 127 |
+
); */
|
| 128 |
+
|
| 129 |
+
// @TODO: Check what this should do, or if it should be removed
|
| 130 |
+
|
| 131 |
+
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('mailplus')->__('User was succesful saved'));
|
| 132 |
+
Mage::getSingleton('adminhtml/session')->setFormData(false);
|
| 133 |
+
|
| 134 |
+
if ($this->getRequest()->getParam('back')) {
|
| 135 |
+
$this->_redirect('*/*/edit', array('id' => $model->getCustomerId()));
|
| 136 |
+
return;
|
| 137 |
+
}
|
| 138 |
+
$this->_redirect('*/*/');
|
| 139 |
+
return;
|
| 140 |
+
} catch (Exception $e) {
|
| 141 |
+
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
|
| 142 |
+
Mage::getSingleton('adminhtml/session')->setFormData($data);
|
| 143 |
+
$this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
|
| 144 |
+
return;
|
| 145 |
+
}
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
/*
|
| 149 |
+
* @deprecated
|
| 150 |
+
*
|
| 151 |
+
*/
|
| 152 |
+
public function deleteAction()
|
| 153 |
+
{
|
| 154 |
+
$model = Mage::getModel('mailplus/user')->load($this->getRequest()->get('id'));
|
| 155 |
+
if ( $model->getId() < 1 )
|
| 156 |
+
{
|
| 157 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('mailplus')->__('Unable to find mailplus user to delete on id '.$this->getRequest()->get('id') ));
|
| 158 |
+
$this->_redirect('*/*/');
|
| 159 |
+
return;
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
if ( 0 != $model->getData('customer_id') )
|
| 163 |
+
{
|
| 164 |
+
$customer = Mage::getModel('customer/customer')->load($model->getData('customer_id'));
|
| 165 |
+
if ( $customer->getId() < 1 )
|
| 166 |
+
$customer = NULL;
|
| 167 |
+
}
|
| 168 |
+
else
|
| 169 |
+
$customer = NULL;
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
if ( $customer )
|
| 173 |
+
$status = sprintf(Mage::helper('mailplus')->__('User id %s ( customer %s ) ( mailplus %s ) was succesful deleted'), $model->getData('user_id'), $customer->getData('firstname').' '.$customer->getData('middlename').' '.$customer->getData('lastname'), $model->getData('mailplus_id'));
|
| 174 |
+
else
|
| 175 |
+
$status = sprintf(Mage::helper('mailplus')->__('User id %s ( mailplus %s ) was succesful deleted'), $model->getData('user_id'), $model->getData('mailplus_id'));
|
| 176 |
+
|
| 177 |
+
try {
|
| 178 |
+
$model->delete();
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
Mage::getSingleton('adminhtml/session')->addSuccess('Please be aware there is a certain delay in Mailplus');
|
| 182 |
+
}
|
| 183 |
+
catch (Exception $ex)
|
| 184 |
+
{
|
| 185 |
+
$status = 'Error occurred : '.$ex->getMessage();
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
Mage::getSingleton('adminhtml/session')->addSuccess($status);
|
| 190 |
+
$this->_redirect('*/*');
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
/*
|
| 194 |
+
protected function _addContent(Mage_Core_Block_Abstract $block)
|
| 195 |
+
{
|
| 196 |
+
$this->getLayout()->getBlock('content')->append($block);
|
| 197 |
+
return $this;
|
| 198 |
+
} */
|
| 199 |
+
}
|
app/code/community/Techtwo/Mailplus/controllers/Adminhtml/FeedController.php
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
class Techtwo_Mailplus_Adminhtml_FeedController extends Mage_Adminhtml_Controller_Action
|
| 18 |
+
{
|
| 19 |
+
public function indexAction()
|
| 20 |
+
{
|
| 21 |
+
$this->loadLayout()
|
| 22 |
+
->_setActiveMenu('mailplus')
|
| 23 |
+
->renderLayout();
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
public function newAction()
|
| 27 |
+
{
|
| 28 |
+
Mage::unregister('mailplus_feed_data');
|
| 29 |
+
|
| 30 |
+
$this->loadLayout();
|
| 31 |
+
$this->_setActiveMenu('mailplus');
|
| 32 |
+
|
| 33 |
+
$this->_addBreadcrumb(Mage::helper('adminhtml')->__('Item Manager'), Mage::helper('adminhtml')->__('Item Manager'));
|
| 34 |
+
$this->_addBreadcrumb(Mage::helper('adminhtml')->__('Item News'), Mage::helper('adminhtml')->__('Item News'));
|
| 35 |
+
|
| 36 |
+
$this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
|
| 37 |
+
|
| 38 |
+
$this->_addContent($this->getLayout()->createBlock('mailplus/adminhtml_feed_edit'))
|
| 39 |
+
->_addLeft($this->getLayout()->createBlock('mailplus/adminhtml_feed_edit_tabs'));
|
| 40 |
+
|
| 41 |
+
$this->renderLayout();
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
public function editAction()
|
| 45 |
+
{
|
| 46 |
+
$entityId = (int) $this->getRequest()->getParam('id');
|
| 47 |
+
$userModel = $entityId>0? Mage::getModel('mailplus/feed')->load($entityId):NULL;
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
if ( NULL !== $userModel && $userModel->getId())
|
| 51 |
+
{
|
| 52 |
+
|
| 53 |
+
Mage::register('mailplus_feed_data', $userModel);
|
| 54 |
+
|
| 55 |
+
$this->loadLayout();
|
| 56 |
+
$this->_setActiveMenu('mailplus');
|
| 57 |
+
|
| 58 |
+
$this->_addBreadcrumb(Mage::helper('adminhtml')->__('Item Manager'), Mage::helper('adminhtml')->__('Item Manager'));
|
| 59 |
+
$this->_addBreadcrumb(Mage::helper('adminhtml')->__('Item News'), Mage::helper('adminhtml')->__('Item News'));
|
| 60 |
+
|
| 61 |
+
$this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
|
| 62 |
+
|
| 63 |
+
$this->_addContent($this->getLayout()->createBlock('mailplus/adminhtml_feed_edit'))
|
| 64 |
+
->_addLeft($this->getLayout()->createBlock('mailplus/adminhtml_feed_edit_tabs'));
|
| 65 |
+
|
| 66 |
+
$this->renderLayout();
|
| 67 |
+
}
|
| 68 |
+
else
|
| 69 |
+
{
|
| 70 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('mailplus')->__('Product feed item does not exist'));
|
| 71 |
+
$this->_redirect('*/*/');
|
| 72 |
+
}
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
public function saveAction()
|
| 78 |
+
{
|
| 79 |
+
|
| 80 |
+
$data = $this->getRequest()->getPost();
|
| 81 |
+
if (!$data)
|
| 82 |
+
{
|
| 83 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('mailplus')->__('Unable to find mailplus product item'));
|
| 84 |
+
$this->_redirect('*/*/');
|
| 85 |
+
return;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
$model = Mage::getModel('mailplus/feed');
|
| 89 |
+
$model->setData($data);
|
| 90 |
+
|
| 91 |
+
if ( $this->getRequest()->has('id') )
|
| 92 |
+
$model->setId($this->getRequest()->getParam('id'));
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
try
|
| 96 |
+
{
|
| 97 |
+
$model->save();
|
| 98 |
+
|
| 99 |
+
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('mailplus')->__('Product feed item was successfully saved'));
|
| 100 |
+
Mage::getSingleton('adminhtml/session')->setFormData(false);
|
| 101 |
+
|
| 102 |
+
if ($this->getRequest()->getParam('back'))
|
| 103 |
+
{
|
| 104 |
+
$this->_redirect('*/*/edit', array('id' => $model->getId()));
|
| 105 |
+
return;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
$this->_redirect('*/*/');
|
| 109 |
+
return;
|
| 110 |
+
} catch (Exception $e) {
|
| 111 |
+
|
| 112 |
+
if ( $e instanceof Zend_Db_Exception && 23000 === $e->getCode() )
|
| 113 |
+
{
|
| 114 |
+
if ( stripos($e->getMessage(), 'foreign')!==false && strpos($e->getMessage(), 'catalog_product_entity_id')!==false )
|
| 115 |
+
Mage::getSingleton('adminhtml/session')->addError( Mage::helper('mailplus')->__('No product with id %u found', $data['catalog_product_entity_id']) );
|
| 116 |
+
else
|
| 117 |
+
Mage::getSingleton('adminhtml/session')->addError( Mage::helper('mailplus')->__('This product is already listed in the feed') );
|
| 118 |
+
}
|
| 119 |
+
else
|
| 120 |
+
{
|
| 121 |
+
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
Mage::getSingleton('adminhtml/session')->setMailplusFeedData($data);
|
| 125 |
+
if ($this->getRequest()->getParam('back'))
|
| 126 |
+
$this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
|
| 127 |
+
$this->_redirect('*/*/');
|
| 128 |
+
return;
|
| 129 |
+
}
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
public function massDeleteAction()
|
| 134 |
+
{
|
| 135 |
+
$delete_ids = $this->_request->getParam('mailplus_feed_mass');
|
| 136 |
+
$model = Mage::getModel('mailplus/feed');
|
| 137 |
+
|
| 138 |
+
try
|
| 139 |
+
{
|
| 140 |
+
foreach ( $delete_ids as $id )
|
| 141 |
+
{
|
| 142 |
+
$id = (int) $id;
|
| 143 |
+
if ( $id > 0)
|
| 144 |
+
{
|
| 145 |
+
$model->load($id);
|
| 146 |
+
if ( $model->getId() )
|
| 147 |
+
$model->delete();
|
| 148 |
+
}
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('mailplus')->__('Product feed item as successfully deleted'));
|
| 152 |
+
}
|
| 153 |
+
catch (Exception $ex)
|
| 154 |
+
{
|
| 155 |
+
Mage::getSingleton('adminhtml/session')->addError( $ex->getMessage() );
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
$this->_redirect('*/*/');
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
public function deleteAction()
|
| 163 |
+
{
|
| 164 |
+
$model = Mage::getModel('mailplus/feed');
|
| 165 |
+
$model->load( $this->getRequest()->getParam('id') );
|
| 166 |
+
if ( $model && $model->getId() )
|
| 167 |
+
{
|
| 168 |
+
try
|
| 169 |
+
{
|
| 170 |
+
$model->delete();
|
| 171 |
+
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('mailplus')->__('Product feed item as successfully deleted'));
|
| 172 |
+
}
|
| 173 |
+
catch (Exception $ex)
|
| 174 |
+
{
|
| 175 |
+
Mage::getSingleton('adminhtml/session')->addError( $ex->getMessage() );
|
| 176 |
+
}
|
| 177 |
+
}
|
| 178 |
+
else
|
| 179 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('mailplus')->__('Unable to find mailplus product item'));
|
| 180 |
+
|
| 181 |
+
$this->_redirect('*/*/');
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
public function productGridAction()
|
| 185 |
+
{
|
| 186 |
+
$this->getResponse()->setHeader('Content-Type','text/json');
|
| 187 |
+
echo json_encode(array(
|
| 188 |
+
'products' => array('product_2' => 'colman', 'product_3'=>'foo')
|
| 189 |
+
));
|
| 190 |
+
return;
|
| 191 |
+
$this->loadLayout();
|
| 192 |
+
$this->_addContent($this->getLayout()->createBlock('mailplus/adminhtml_users_grid'));
|
| 193 |
+
$this->renderLayout();
|
| 194 |
+
//$this->getLayout()->createBlock('mailplus/adminhtml_users_grid')->toHtml();
|
| 195 |
+
return;
|
| 196 |
+
$this->loadLayout();
|
| 197 |
+
$this->_addContent($this->getLayout()->createBlock('mailplus/adminhtml_users_grid'));
|
| 198 |
+
$this->renderLayout();
|
| 199 |
+
}
|
| 200 |
+
|
| 201 |
+
}
|
app/code/community/Techtwo/Mailplus/controllers/Adminhtml/FeedsController.php
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
class Techtwo_Mailplus_Adminhtml_FeedsController extends Mage_Adminhtml_Controller_Action
|
| 18 |
+
{
|
| 19 |
+
public function indexAction()
|
| 20 |
+
{
|
| 21 |
+
$this->loadLayout()
|
| 22 |
+
->_setActiveMenu('mailplus')
|
| 23 |
+
//->_addContent($this->getLayout()->createBlock('mailplus/adminhtml_feeds'))
|
| 24 |
+
->renderLayout();
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
public function viewAction()
|
| 29 |
+
{
|
| 30 |
+
$remove = $this->_request->getParam('remove');
|
| 31 |
+
$feed = $this->_request->getParam('feed');
|
| 32 |
+
|
| 33 |
+
if ( $remove && $feed )
|
| 34 |
+
{
|
| 35 |
+
$options = Mage::helper('mailplus/feed')->getAllOptions();
|
| 36 |
+
$feed = $this->getRequest()->getParam('feed', '');
|
| 37 |
+
|
| 38 |
+
$product = Mage::getModel('catalog/product');
|
| 39 |
+
if ( $feed && array_key_exists($feed, $options) && $product->load($remove)->getId() )
|
| 40 |
+
{
|
| 41 |
+
$mailplus_feeds = array_filter(explode(',', $product->getData('mailplus_feed')));
|
| 42 |
+
$key = array_search($feed, $mailplus_feeds);
|
| 43 |
+
if ( false !== $key )
|
| 44 |
+
unset($mailplus_feeds[$key]);
|
| 45 |
+
|
| 46 |
+
$product->setData('mailplus_feed', implode(',', $mailplus_feeds));
|
| 47 |
+
$product->save();
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
$this->_redirect('*/*/*', array('feed'=>$feed));
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
$this->loadLayout()
|
| 56 |
+
->_setActiveMenu('mailplus')
|
| 57 |
+
//->_addContent($this->getLayout()->createBlock('mailplus/adminhtml_feeds'))
|
| 58 |
+
->renderLayout();
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
}
|
app/code/community/Techtwo/Mailplus/controllers/Adminhtml/HelpController.php
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
class Techtwo_Mailplus_Adminhtml_HelpController extends Mage_Adminhtml_Controller_Action{
|
| 18 |
+
|
| 19 |
+
public function indexAction(){
|
| 20 |
+
|
| 21 |
+
$this->loadLayout()
|
| 22 |
+
->_setActiveMenu('mailplus')
|
| 23 |
+
//->_addContent($this->getLayout()->createBlock('mailplus/adminhtml_help'))
|
| 24 |
+
->renderLayout();
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
}
|
app/code/community/Techtwo/Mailplus/controllers/Adminhtml/MailingsController.php
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
class Techtwo_Mailplus_Adminhtml_MailingsController extends Mage_Adminhtml_Controller_Action
|
| 18 |
+
{
|
| 19 |
+
|
| 20 |
+
public function indexAction()
|
| 21 |
+
{
|
| 22 |
+
$this->loadLayout()
|
| 23 |
+
->_setActiveMenu('mailplus')
|
| 24 |
+
//->_addContent($this->getLayout()->createBlock('mailplus/adminhtml_mailings')) // dynamic add content
|
| 25 |
+
->renderLayout();
|
| 26 |
+
|
| 27 |
+
//$model = Mage::getModel("mailplus/mailing")->load(1);
|
| 28 |
+
//print_r($model->debug());
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
public function editAction()
|
| 32 |
+
{
|
| 33 |
+
$mailingId = $this->getRequest()->getParam('id');
|
| 34 |
+
$mailingModel = Mage::getModel('mailplus/mailing')->load($mailingId);
|
| 35 |
+
|
| 36 |
+
if ($mailingModel->getId() || $mailingId == 0)
|
| 37 |
+
{
|
| 38 |
+
|
| 39 |
+
Mage::register('mailplus_mailing_data', $mailingModel);
|
| 40 |
+
|
| 41 |
+
$this->loadLayout();
|
| 42 |
+
$this->_setActiveMenu('mailplus');
|
| 43 |
+
|
| 44 |
+
$this->_addBreadcrumb(Mage::helper('adminhtml')->__('Mailplus'), Mage::helper('adminhtml')->__('Mailing Manager'));
|
| 45 |
+
$this->_addBreadcrumb(Mage::helper('adminhtml')->__('Mailplus'), Mage::helper('adminhtml')->__('Mailing News'));
|
| 46 |
+
|
| 47 |
+
$this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
|
| 48 |
+
|
| 49 |
+
$this->_addContent($this->getLayout()->createBlock('mailplus/adminhtml_mailings_edit'))
|
| 50 |
+
->_addLeft($this->getLayout()->createBlock('mailplus/adminhtml_mailings_edit_tabs'));
|
| 51 |
+
|
| 52 |
+
$this->renderLayout();
|
| 53 |
+
}
|
| 54 |
+
else
|
| 55 |
+
{
|
| 56 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('mailplus')->__('Mailing does not exist'));
|
| 57 |
+
$this->_redirect('*/*/');
|
| 58 |
+
}
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
public function saveAction()
|
| 62 |
+
{
|
| 63 |
+
$data = $this->getRequest()->getPost();
|
| 64 |
+
if ( empty( $data ) )
|
| 65 |
+
{
|
| 66 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('mailplus')->__('Unable to find mailing to save'));
|
| 67 |
+
$this->_redirect('*/*/');
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
$data['startdate'] = date('Y-m-d H:i:s', strtotime($data['startdate']));
|
| 71 |
+
$data['enddate'] = date('Y-m-d H:i:s', strtotime($data['enddate']));
|
| 72 |
+
|
| 73 |
+
$model = Mage::getModel('mailplus/mailing');
|
| 74 |
+
$model->setData($data)
|
| 75 |
+
->setId($this->getRequest()->getParam('id'));
|
| 76 |
+
|
| 77 |
+
try {
|
| 78 |
+
$model->save();
|
| 79 |
+
|
| 80 |
+
// feedback
|
| 81 |
+
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('mailplus')->__('Mailing was successfully saved'));
|
| 82 |
+
Mage::getSingleton('adminhtml/session')->setFormData(false); // clear data
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
// Redirect
|
| 86 |
+
|
| 87 |
+
if ($this->getRequest()->getParam('back')) {
|
| 88 |
+
$this->_redirect('*/*/edit', array('id' => $model->getId()));
|
| 89 |
+
return;
|
| 90 |
+
}
|
| 91 |
+
$this->_redirect('*/*/');
|
| 92 |
+
return;
|
| 93 |
+
|
| 94 |
+
} catch (Exception $e) {
|
| 95 |
+
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
|
| 96 |
+
Mage::getSingleton('adminhtml/session')->setFormData($data);
|
| 97 |
+
$this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
|
| 98 |
+
return;
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
/*
|
| 104 |
+
protected function _addContent(Mage_Core_Block_Abstract $block)
|
| 105 |
+
{
|
| 106 |
+
$this->getLayout()->getBlock('content')->append($block);
|
| 107 |
+
return $this;
|
| 108 |
+
} */
|
| 109 |
+
}
|
app/code/community/Techtwo/Mailplus/controllers/Adminhtml/MappingController.php
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
class Techtwo_Mailplus_Adminhtml_MappingController extends Mage_Adminhtml_Controller_Action {
|
| 18 |
+
|
| 19 |
+
public function indexAction(){
|
| 20 |
+
$this->loadLayout()->_setActiveMenu('mailplus');
|
| 21 |
+
$this->renderLayout();
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
public function saveAction() {
|
| 25 |
+
$data = $this->getRequest()->getPost();
|
| 26 |
+
if (!$data) {
|
| 27 |
+
$this->_redirect('*/*/index/', array( 'id' => $this->getRequest()->id ));
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
/* @var $config Techtwo_Mailplus_Helper_Config */
|
| 31 |
+
$config = Mage::helper('mailplus/config');
|
| 32 |
+
|
| 33 |
+
$mapping = $data['groups']['mapping']['fields'];
|
| 34 |
+
$siteId = $mapping['site']['value'];
|
| 35 |
+
$site = Mage::app()->getWebsite($siteId);
|
| 36 |
+
$usedProps = array();
|
| 37 |
+
$usedAttrs = array();
|
| 38 |
+
$doubleMapped = array();
|
| 39 |
+
|
| 40 |
+
foreach($mapping as $attributeName => $mailplusProp) {
|
| 41 |
+
if ($mailplusProp['value'] && $mailplusProp['value'] != '') {
|
| 42 |
+
if (isset($usedProps[$mailplusProp['value']])) {
|
| 43 |
+
$doubleMapped[$mailplusProp['value']] = true;
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
$usedProps[$mailplusProp['value']] = $attributeName;
|
| 47 |
+
}
|
| 48 |
+
$usedAttrs[$attributeName] = $mailplusProp['value'];
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
if (count($doubleMapped) > 0) {
|
| 52 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('mailplus')->__('Mapping not saved. One or more mailplus fields have been mapped more then once'));
|
| 53 |
+
Mage::register('mailplus_double_mapped', $doubleMapped);
|
| 54 |
+
Mage::register('mailplus_currentmapping', $usedAttrs);
|
| 55 |
+
$this->indexAction();
|
| 56 |
+
return;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
$coreConfig = new Mage_Core_Model_Config();
|
| 60 |
+
|
| 61 |
+
foreach($mapping as $attributeName => $mailplusProp) {
|
| 62 |
+
if ($mailplusProp['value']) {
|
| 63 |
+
$coreConfig->saveConfig(Techtwo_Mailplus_Helper_Config::$_MAPPING_CONFIGPATH . $attributeName, $mailplusProp['value'], 'websites', $siteId);
|
| 64 |
+
} else {
|
| 65 |
+
$coreConfig->saveConfig(Techtwo_Mailplus_Helper_Config::$_MAPPING_CONFIGPATH . $attributeName, null, 'websites', $siteId);
|
| 66 |
+
}
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
Mage::app()->getCache()->remove($config->getMappingCacheKey($siteId));
|
| 70 |
+
// Mark as saved once so the default value for an attributeName will not be used when there is no config found. (e.g. not mapped)
|
| 71 |
+
$coreConfig->saveConfig(Techtwo_Mailplus_Helper_Config::$_MAPPING_CONFIGPATH . 'savedonce', 1, 'websites', $siteId);
|
| 72 |
+
$coreConfig->cleanCache();
|
| 73 |
+
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('mailplus')->__('Mapping saved'));
|
| 74 |
+
$this->_redirect('*/*/index');
|
| 75 |
+
}
|
| 76 |
+
}
|
app/code/community/Techtwo/Mailplus/controllers/Adminhtml/RestqueueController.php
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
class Techtwo_Mailplus_Adminhtml_RestqueueController extends Mage_Adminhtml_Controller_Action
|
| 18 |
+
{
|
| 19 |
+
public function indexAction()
|
| 20 |
+
{
|
| 21 |
+
$this->loadLayout()
|
| 22 |
+
->_setActiveMenu('mailplus')
|
| 23 |
+
->renderLayout();
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
}
|
app/code/community/Techtwo/Mailplus/controllers/Adminhtml/StatusController.php
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
class Techtwo_Mailplus_Adminhtml_StatusController extends Mage_Adminhtml_Controller_Action{
|
| 18 |
+
|
| 19 |
+
public function indexAction()
|
| 20 |
+
{
|
| 21 |
+
$this->loadLayout()
|
| 22 |
+
->_setActiveMenu('mailplus')
|
| 23 |
+
->renderLayout();
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
public function syncAction() {
|
| 27 |
+
$synctype = Mage::app()->getFrontController()->getRequest()->getParam('synctype');
|
| 28 |
+
$mailplusHelper = Mage::helper('mailplus');
|
| 29 |
+
$website = $mailplusHelper->getWebsiteFromRequest();
|
| 30 |
+
|
| 31 |
+
$websiteId = $website->getId();
|
| 32 |
+
|
| 33 |
+
$mailplus = Mage::helper('mailplus');
|
| 34 |
+
|
| 35 |
+
switch ($synctype) {
|
| 36 |
+
case Techtwo_Mailplus_Model_Syncqueue::TYPE_CUSTOMER:
|
| 37 |
+
$this->_fillCustomerSyncCache($websiteId);
|
| 38 |
+
break;
|
| 39 |
+
case Techtwo_Mailplus_Model_Syncqueue::TYPE_ORDER:
|
| 40 |
+
$this->_fillOrderSyncCache($websiteId);
|
| 41 |
+
break;
|
| 42 |
+
case Techtwo_Mailplus_Model_Syncqueue::TYPE_PRODUCT:
|
| 43 |
+
$this->_fillProductSyncCache($websiteId);
|
| 44 |
+
break;
|
| 45 |
+
case Techtwo_Mailplus_Model_Syncqueue::TYPE_SUBSCRIBER:
|
| 46 |
+
$this->_fillSubscriberSyncCache($websiteId);
|
| 47 |
+
break;
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
$session = Mage::getSingleton('core/session');
|
| 51 |
+
$session->addSuccess($mailplus->__('Sync for ' . $mailplus->__($synctype) . $mailplus->__(' started')));
|
| 52 |
+
$this->_redirect('*/*', array('website' => $website->getCode()));
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
private function _fillOrderSyncCache($websiteId) {
|
| 56 |
+
$configHelper = Mage::helper('mailplus/config');
|
| 57 |
+
$mailplusHelper = Mage::helper('mailplus');
|
| 58 |
+
$storeViewsToSync = array();
|
| 59 |
+
|
| 60 |
+
$website = Mage::app()->getWebsite($websiteId);
|
| 61 |
+
if ($configHelper->contactSyncAllowed($websiteId)) {
|
| 62 |
+
foreach($website->getGroups() as $group) {
|
| 63 |
+
$stores = $group->getStores();
|
| 64 |
+
|
| 65 |
+
foreach($stores as $store) {
|
| 66 |
+
if ($configHelper->syncActiveForStore($store->getId())) {
|
| 67 |
+
$storeViewsToSync[] = $store->getId();
|
| 68 |
+
}
|
| 69 |
+
}
|
| 70 |
+
}
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
foreach ($storeViewsToSync as $storeId) {
|
| 74 |
+
$orders = Mage::getModel('sales/order')->getCollection()
|
| 75 |
+
->addAttributeToFilter('store_id', $storeId)
|
| 76 |
+
->addAttributeToFilter('state', Mage_Sales_Model_Order::STATE_COMPLETE);
|
| 77 |
+
|
| 78 |
+
$this->fillSyncCache($orders, $websiteId, Techtwo_Mailplus_Model_Syncqueue::TYPE_ORDER);
|
| 79 |
+
}
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
private function fillSyncCache($collection, $websiteId, $type) {
|
| 83 |
+
$dataHelper = Mage::helper('mailplus');
|
| 84 |
+
$allIds = $collection->getAllIds();
|
| 85 |
+
foreach($allIds as $id) {
|
| 86 |
+
$dataHelper->saveSyncItem($websiteId, $id, $type);
|
| 87 |
+
}
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
private function _fillCustomerSyncCache($websiteId) {
|
| 91 |
+
$configHelper = Mage::helper('mailplus/config');
|
| 92 |
+
|
| 93 |
+
if (!$configHelper->syncActiveForSite($websiteId) ||
|
| 94 |
+
!$configHelper->contactSyncAllowed($websiteId) ) {
|
| 95 |
+
return;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
$customers = Mage::getModel('customer/customer')->getCollection()
|
| 99 |
+
->addAttributeToFilter('website_id', $websiteId);
|
| 100 |
+
|
| 101 |
+
$this->fillSyncCache($customers, $websiteId, Techtwo_Mailplus_Model_Syncqueue::TYPE_CUSTOMER);
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
private function _fillProductSyncCache($websiteId) {
|
| 105 |
+
$configHelper = Mage::helper('mailplus/config');
|
| 106 |
+
|
| 107 |
+
if (!$configHelper->syncActiveForSite($websiteId)) {
|
| 108 |
+
return;
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
$products = Mage::getModel('catalog/product')->getCollection()
|
| 112 |
+
->addWebsiteFilter($websiteId);
|
| 113 |
+
|
| 114 |
+
$this->fillSyncCache($products, $websiteId, Techtwo_Mailplus_Model_Syncqueue::TYPE_PRODUCT);
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
public function synchronizeAction() {
|
| 118 |
+
ignore_user_abort( true );
|
| 119 |
+
/* @var $session Mage_Core_Model_Session */
|
| 120 |
+
$session = Mage::getSingleton('core/session');
|
| 121 |
+
/* @var $dataHelper Techtwo_Mailplus_Helper_Data */
|
| 122 |
+
$dataHelper = Mage::helper('mailplus');
|
| 123 |
+
/* @var $rest Techtwo_Mailplus_Helper_Rest */
|
| 124 |
+
$rest = Mage::helper('mailplus/rest');
|
| 125 |
+
|
| 126 |
+
$website = $dataHelper->getWebsiteFromRequest();
|
| 127 |
+
|
| 128 |
+
$synchronize = FALSE;
|
| 129 |
+
|
| 130 |
+
$this->_fillSubscriberSyncCache($website->getId());
|
| 131 |
+
$this->_fillCustomerSyncCache($website->getId());
|
| 132 |
+
$this->_fillProductSyncCache($website->getId());
|
| 133 |
+
$this->_fillOrderSyncCache($website->getId());
|
| 134 |
+
|
| 135 |
+
$session->addSuccess('MailPlus synchronizing is now scheduled');
|
| 136 |
+
$this->_redirect('*/*', array('website' => $website->getCode()));
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
protected function _fillSubscriberSyncCache($websiteId ) {
|
| 140 |
+
/* @var $configHelper Techtwo_Mailplus_Helper_Config */
|
| 141 |
+
$configHelper = Mage::helper('mailplus/config');
|
| 142 |
+
if (!$configHelper->contactSyncAllowed($websiteId) ) {
|
| 143 |
+
return;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
$website = Mage::app()->getWebsite($websiteId);
|
| 147 |
+
$storeIds = array();
|
| 148 |
+
foreach($website->getGroups() as $group) {
|
| 149 |
+
$stores = $group->getStores();
|
| 150 |
+
foreach($stores as $store) {
|
| 151 |
+
if ($configHelper->syncActiveForStore($store->getId())) {
|
| 152 |
+
$storeIds[] = $store->getId();
|
| 153 |
+
}
|
| 154 |
+
}
|
| 155 |
+
}
|
| 156 |
+
$this->_redirect('*/website/' . $website->getCode());
|
| 157 |
+
if (count($storeIds) > 0) {
|
| 158 |
+
$subscriberCollection = Mage::getModel('newsletter/subscriber')->getCollection()
|
| 159 |
+
->addFieldToFilter('store_id', array('in' => $storeIds));
|
| 160 |
+
|
| 161 |
+
$this->fillSyncCache($subscriberCollection, $websiteId, Techtwo_Mailplus_Model_Syncqueue::TYPE_SUBSCRIBER);
|
| 162 |
+
}
|
| 163 |
+
}
|
| 164 |
+
}
|
app/code/community/Techtwo/Mailplus/controllers/Adminhtml/SyncstatusController.php
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
class Techtwo_Mailplus_Adminhtml_SyncstatusController extends Mage_Adminhtml_Controller_Action {
|
| 18 |
+
public function indexAction() {
|
| 19 |
+
$this->loadLayout()
|
| 20 |
+
->_setActiveMenu('mailplus')
|
| 21 |
+
->renderLayout();
|
| 22 |
+
}
|
| 23 |
+
}
|
app/code/community/Techtwo/Mailplus/controllers/Adminhtml/UsersController.php
ADDED
|
@@ -0,0 +1,522 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
class Techtwo_Mailplus_Adminhtml_UsersController extends Mage_Adminhtml_Controller_Action
|
| 18 |
+
{
|
| 19 |
+
|
| 20 |
+
private $_csv_mapping_mailplus_magento = array(
|
| 21 |
+
'Voornaam' => 'firstname',
|
| 22 |
+
'Achternaam' => 'lastname',
|
| 23 |
+
'E-mailadres' => 'email',
|
| 24 |
+
'Test groep_Ja' => 'is_test',
|
| 25 |
+
'Geslacht' => 'gender',
|
| 26 |
+
'Geboortedag' => 'dob',
|
| 27 |
+
|
| 28 |
+
// FROM BILLING ADRES
|
| 29 |
+
'Straat' => 'street',
|
| 30 |
+
'Huisnummer' => 'number',
|
| 31 |
+
'Postcode' => 'zipcode',
|
| 32 |
+
'Woonplaats' => 'city',
|
| 33 |
+
'Bedrijfsnaam' => 'company',
|
| 34 |
+
'Telefoon nr.' => 'phone',
|
| 35 |
+
// 'Mobiel nr.' => '' MAGENTO HAS NO MOBIEL
|
| 36 |
+
);
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
public function indexAction()
|
| 40 |
+
{
|
| 41 |
+
$this->loadLayout()
|
| 42 |
+
->_setActiveMenu('mailplus')
|
| 43 |
+
//->_addContent($this->getLayout()->createBlock('mailplus/adminhtml_users')) // dynamic add content
|
| 44 |
+
->renderLayout();
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
public function editAction()
|
| 48 |
+
{
|
| 49 |
+
$userId = $this->getRequest()->getParam('id');
|
| 50 |
+
$userModel = Mage::getModel('mailplus/user')->load($userId);
|
| 51 |
+
|
| 52 |
+
if ($userModel->getId() || $userId == 0)
|
| 53 |
+
{
|
| 54 |
+
Mage::register('mailplus_user_data', $userModel);
|
| 55 |
+
|
| 56 |
+
$this->loadLayout();
|
| 57 |
+
$this->_setActiveMenu('mailplus');
|
| 58 |
+
|
| 59 |
+
$this->_addBreadcrumb(Mage::helper('adminhtml')->__('Item Manager'), Mage::helper('adminhtml')->__('Item Manager'));
|
| 60 |
+
$this->_addBreadcrumb(Mage::helper('adminhtml')->__('Item News'), Mage::helper('adminhtml')->__('Item News'));
|
| 61 |
+
|
| 62 |
+
$this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
|
| 63 |
+
|
| 64 |
+
$this->_addContent($this->getLayout()->createBlock('mailplus/adminhtml_users_edit'))
|
| 65 |
+
->_addLeft($this->getLayout()->createBlock('mailplus/adminhtml_users_edit_tabs'));
|
| 66 |
+
|
| 67 |
+
$this->renderLayout();
|
| 68 |
+
}
|
| 69 |
+
else
|
| 70 |
+
{
|
| 71 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('mailplus')->__('Item does not exist'));
|
| 72 |
+
$this->_redirect('*/*/');
|
| 73 |
+
}
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
public function saveAction()
|
| 77 |
+
{
|
| 78 |
+
|
| 79 |
+
$data = $this->getRequest()->getPost();
|
| 80 |
+
if (!$data)
|
| 81 |
+
{
|
| 82 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('mailplus')->__('Unable to find mailplus user to save'));
|
| 83 |
+
$this->_redirect('*/*/');
|
| 84 |
+
return;
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
if (array_key_exists('mailplus_id', $data))
|
| 88 |
+
unset($data['mailplus_id']);
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
$customer_id = trim($data['customer_id']);
|
| 92 |
+
if ( '' === $customer_id || '0' === $customer_id )
|
| 93 |
+
{
|
| 94 |
+
$customer = NULL;
|
| 95 |
+
}
|
| 96 |
+
else
|
| 97 |
+
{
|
| 98 |
+
$customer = Mage::getModel('customer/customer');
|
| 99 |
+
if ( $customer->load($data['customer_id'])->getId() < 1 )
|
| 100 |
+
{
|
| 101 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('mailplus')->__('Unable to find customer to save'));
|
| 102 |
+
Mage::getSingleton('adminhtml/session')->setFormData($data);
|
| 103 |
+
$this->_redirect('*/*/edit/', array( 'id' => $this->getRequest()->id ));
|
| 104 |
+
return;
|
| 105 |
+
}
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
if ( NULL !== $customer )
|
| 112 |
+
{
|
| 113 |
+
$data['firstname'] = $customer->getData('firstname');
|
| 114 |
+
$data['lastname'] = $customer->getData('lastname');
|
| 115 |
+
$data['email'] = $customer->getData('email');
|
| 116 |
+
}
|
| 117 |
+
else
|
| 118 |
+
{
|
| 119 |
+
$data['customer_id'] = NULL;
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
/* @var $model Techtwo_Mailplus_Model_User */
|
| 123 |
+
$model = Mage::getModel('mailplus/user');
|
| 124 |
+
$model->setData($data)
|
| 125 |
+
->setId($this->getRequest()->getParam('id'));
|
| 126 |
+
|
| 127 |
+
try
|
| 128 |
+
{
|
| 129 |
+
/* @var $rest Techtwo_Mailplus_Helper_Rest */
|
| 130 |
+
$rest = Mage::helper('mailplus/rest');
|
| 131 |
+
|
| 132 |
+
$stores = Mage::app()->getStores();
|
| 133 |
+
$model->save();
|
| 134 |
+
|
| 135 |
+
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('mailplus')->__('User was successful saved'));
|
| 136 |
+
Mage::getSingleton('adminhtml/session')->setFormData(false);
|
| 137 |
+
|
| 138 |
+
if ($this->getRequest()->getParam('back')) {
|
| 139 |
+
$this->_redirect('*/*/edit', array('id' => $model->getCustomerId()));
|
| 140 |
+
return;
|
| 141 |
+
}
|
| 142 |
+
$this->_redirect('*/*/');
|
| 143 |
+
return;
|
| 144 |
+
} catch (Exception $e) {
|
| 145 |
+
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
|
| 146 |
+
Mage::getSingleton('adminhtml/session')->setFormData($data);
|
| 147 |
+
$this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
|
| 148 |
+
return;
|
| 149 |
+
}
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
public function massDeleteAction()
|
| 153 |
+
{
|
| 154 |
+
/* @var $rest Techtwo_Mailplus_Helper_Rest */
|
| 155 |
+
$rest = Mage::helper('mailplus/rest');
|
| 156 |
+
|
| 157 |
+
$users_to_delete = $this->_request->getParam('mailplus_user_mass');
|
| 158 |
+
|
| 159 |
+
/* @var $userModel Techtwo_Mailplus_Model_User */
|
| 160 |
+
$userModel = Mage::getModel('mailplus/user');
|
| 161 |
+
try
|
| 162 |
+
{
|
| 163 |
+
foreach ( $users_to_delete as $id )
|
| 164 |
+
{
|
| 165 |
+
$id = (int) $id;
|
| 166 |
+
$userModel->load($id);
|
| 167 |
+
if ( $userModel->getId() )
|
| 168 |
+
{
|
| 169 |
+
//$userModel->delete();
|
| 170 |
+
}
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('mailplus')->__('Users were successfully deleted'));
|
| 174 |
+
}
|
| 175 |
+
catch (Exception $ex)
|
| 176 |
+
{
|
| 177 |
+
$status = 'Error occurred : '.$ex->getMessage();
|
| 178 |
+
Mage::getSingleton('adminhtml/session')->addError($status);
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
$this->_redirect('*/*/');
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
public function deleteAction()
|
| 185 |
+
{
|
| 186 |
+
/* @var $model Techtwo_Mailplus_Model_User */
|
| 187 |
+
$model = Mage::getModel('mailplus/user')->load($this->getRequest()->get('id'));
|
| 188 |
+
if ( $model->getId() < 1 )
|
| 189 |
+
{
|
| 190 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('mailplus')->__('Unable to find mailplus user to delete on id '.$this->getRequest()->get('id') ));
|
| 191 |
+
$this->_redirect('*/*/');
|
| 192 |
+
return;
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
if ( 0 != $model->getData('customer_id') )
|
| 196 |
+
{
|
| 197 |
+
$customer = Mage::getModel('customer/customer')->load($model->getData('customer_id'));
|
| 198 |
+
if ( $customer->getId() < 1 )
|
| 199 |
+
$customer = NULL;
|
| 200 |
+
}
|
| 201 |
+
else
|
| 202 |
+
$customer = NULL;
|
| 203 |
+
|
| 204 |
+
try {
|
| 205 |
+
//$model->delete();
|
| 206 |
+
/* @var $rest Techtwo_Mailplus_Helper_Rest */
|
| 207 |
+
$rest = Mage::helper('mailplus/rest');
|
| 208 |
+
if ( $model->getEnabled() )
|
| 209 |
+
{
|
| 210 |
+
$model->setEnabled(FALSE);
|
| 211 |
+
$model->save();
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
if ( $customer )
|
| 215 |
+
$status = sprintf(Mage::helper('mailplus')->__('User id %s, customer %s (%s) is successful deleted.'), $model->getData('user_id'), $customer->getData('firstname').' '.$customer->getData('middlename').' '.$customer->getData('lastname'), $model->getData('email'));
|
| 216 |
+
else
|
| 217 |
+
$status = sprintf(Mage::helper('mailplus')->__('User id %s (%s) is successful deleted.'), $model->getData('user_id'), $model->getData('email'));
|
| 218 |
+
|
| 219 |
+
Mage::getSingleton('adminhtml/session')->addSuccess($status);
|
| 220 |
+
}
|
| 221 |
+
catch (Techtwo_Mailplus_Client_Exception $ex)
|
| 222 |
+
{
|
| 223 |
+
if ( 'CONTACT_NOT_FOUND' === $ex->getType() ) // ok best to remove it here too
|
| 224 |
+
{
|
| 225 |
+
if ( $customer )
|
| 226 |
+
$status = sprintf(Mage::helper('mailplus')->__('User id %s, customer %s (%s) is successful deleted.'), $model->getData('user_id'), $customer->getData('firstname').' '.$customer->getData('middlename').' '.$customer->getData('lastname'), $model->getData('email'));
|
| 227 |
+
else
|
| 228 |
+
$status = sprintf(Mage::helper('mailplus')->__('User id %s (%s) is successful deleted.'), $model->getData('user_id'), $model->getData('email'));
|
| 229 |
+
Mage::getSingleton('adminhtml/session')->addSuccess($status);
|
| 230 |
+
|
| 231 |
+
try { $model->delete(); } catch( Exception $e ) { Mage::logException($e); echo $e; die('s'); }
|
| 232 |
+
}
|
| 233 |
+
else
|
| 234 |
+
{
|
| 235 |
+
$status = 'Error occurred : '.$ex->getMessage();
|
| 236 |
+
Mage::getSingleton('adminhtml/session')->addError($status);
|
| 237 |
+
}
|
| 238 |
+
}
|
| 239 |
+
catch (Exception $ex)
|
| 240 |
+
{
|
| 241 |
+
$status = 'Error occurred : '.$ex->getMessage();
|
| 242 |
+
Mage::getSingleton('adminhtml/session')->addError($status);
|
| 243 |
+
}
|
| 244 |
+
|
| 245 |
+
|
| 246 |
+
|
| 247 |
+
$this->_redirect('*/*');
|
| 248 |
+
}
|
| 249 |
+
|
| 250 |
+
public function importAction()
|
| 251 |
+
{
|
| 252 |
+
if ( $this->_request->isPost() )
|
| 253 |
+
{
|
| 254 |
+
$file = &$_FILES['ufile'];
|
| 255 |
+
|
| 256 |
+
if ($file && $file['error'] === UPLOAD_ERR_OK)
|
| 257 |
+
{
|
| 258 |
+
$name = $file['name'];
|
| 259 |
+
$users_imported = 0;
|
| 260 |
+
|
| 261 |
+
$CSV_DELIMITER = ';';
|
| 262 |
+
$CSV_ENCLOSURE = '"';
|
| 263 |
+
$CSV_LENGTH = 0;
|
| 264 |
+
|
| 265 |
+
$handle = fopen($file['tmp_name'], 'r');
|
| 266 |
+
$cols = array_flip(fgetcsv($handle, $CSV_LENGTH, $CSV_DELIMITER, $CSV_ENCLOSURE));
|
| 267 |
+
if ( !$cols )
|
| 268 |
+
{
|
| 269 |
+
Mage::getSingleton('adminhtml/session')->addError( Mage::helper('mailplus')->__('The users were not imported due an error') );
|
| 270 |
+
Mage::getSingleton('adminhtml/session')->addError( 'Invalid columns' );
|
| 271 |
+
}
|
| 272 |
+
else
|
| 273 |
+
{
|
| 274 |
+
// if already have externalContactId, ignore this
|
| 275 |
+
$cols_length = count($cols);
|
| 276 |
+
|
| 277 |
+
|
| 278 |
+
$website_id = $this->_request->getPost('website_id',1);/////////////////////////// it's admin so we don't validate
|
| 279 |
+
$customer = Mage::getModel('customer/customer');
|
| 280 |
+
|
| 281 |
+
|
| 282 |
+
$mapping = array_flip($this->_csv_mapping_mailplus_magento);
|
| 283 |
+
|
| 284 |
+
while (($data = fgetcsv($handle, $CSV_LENGTH, $CSV_DELIMITER, $CSV_ENCLOSURE)) !== FALSE)
|
| 285 |
+
{
|
| 286 |
+
if ( count($data) != $cols_length )
|
| 287 |
+
{
|
| 288 |
+
//echo "Skip invalid line $line\n";
|
| 289 |
+
continue;
|
| 290 |
+
}
|
| 291 |
+
|
| 292 |
+
if ( !array_key_exists($cols[$mapping['email']], $data) || '' === $data[$cols[$mapping['email']]] )
|
| 293 |
+
{
|
| 294 |
+
//echo "Skip invalid line $line\n";
|
| 295 |
+
continue;
|
| 296 |
+
}
|
| 297 |
+
$email = $data[$cols[$mapping['email']]];
|
| 298 |
+
|
| 299 |
+
$model = Mage::getModel('mailplus/user');
|
| 300 |
+
/* @var $model Techtwo_Mailplus_Model_User */
|
| 301 |
+
|
| 302 |
+
if ( $model->load($email, 'email')->getId() )
|
| 303 |
+
{
|
| 304 |
+
//echo "Already imported $line\n";
|
| 305 |
+
continue;
|
| 306 |
+
}
|
| 307 |
+
|
| 308 |
+
$customer_id = NULL;
|
| 309 |
+
$customer->setData('website_id', $website_id);
|
| 310 |
+
if ( $customer->loadByEmail($email, 'email')->getId() )
|
| 311 |
+
{
|
| 312 |
+
$customer_id = $customer->getId();
|
| 313 |
+
|
| 314 |
+
$data[$cols[$mapping['firstname']]] = $customer->getFirstname();
|
| 315 |
+
$data[$cols[$mapping['lastname']]] = $customer->getLastname();
|
| 316 |
+
}
|
| 317 |
+
|
| 318 |
+
$model->addData(array(
|
| 319 |
+
'customer_id' => $customer_id,
|
| 320 |
+
'firstname' => $data[$cols[$mapping['firstname']]],
|
| 321 |
+
'lastname' => $data[$cols[$mapping['lastname']]],
|
| 322 |
+
'email' => $email,
|
| 323 |
+
'is_test' => 'J' === $data[$cols[$mapping['is_test']]],
|
| 324 |
+
'createts' => time(),
|
| 325 |
+
'enabled' => 1
|
| 326 |
+
));
|
| 327 |
+
|
| 328 |
+
if ( $model->save() )
|
| 329 |
+
$users_imported++;
|
| 330 |
+
unset($model);
|
| 331 |
+
|
| 332 |
+
|
| 333 |
+
//print_r($data); echo '<br />';
|
| 334 |
+
}
|
| 335 |
+
|
| 336 |
+
Mage::getSingleton('adminhtml/session')->addSuccess( sprintf(Mage::helper('mailplus')->__('%d users were imported'), $users_imported) );
|
| 337 |
+
}
|
| 338 |
+
fclose($handle);
|
| 339 |
+
|
| 340 |
+
|
| 341 |
+
|
| 342 |
+
|
| 343 |
+
}
|
| 344 |
+
else
|
| 345 |
+
{
|
| 346 |
+
Mage::getSingleton('adminhtml/session')->addError( Mage::helper('mailplus')->__('The users were not imported due an error') );
|
| 347 |
+
}
|
| 348 |
+
|
| 349 |
+
|
| 350 |
+
|
| 351 |
+
|
| 352 |
+
$this->_redirect('*/*/*');
|
| 353 |
+
return;
|
| 354 |
+
}
|
| 355 |
+
|
| 356 |
+
$this->loadLayout()
|
| 357 |
+
->_setActiveMenu('mailplus')
|
| 358 |
+
->renderLayout();
|
| 359 |
+
}
|
| 360 |
+
|
| 361 |
+
public function exportAction()
|
| 362 |
+
{
|
| 363 |
+
$page_size = 50;
|
| 364 |
+
$page = 1;
|
| 365 |
+
|
| 366 |
+
$CSV_DELIMITER = ';';
|
| 367 |
+
$CSV_ENCLOSURE = '"';
|
| 368 |
+
|
| 369 |
+
if ( true ) { // debug purpose
|
| 370 |
+
header('Pragma: public'); // required
|
| 371 |
+
header('Expires: 0');
|
| 372 |
+
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
|
| 373 |
+
header('Cache-Control: private',false); // required for certain browsers
|
| 374 |
+
header('Content-Type: text/csv');
|
| 375 |
+
header('Content-Disposition: attachment; filename="mailplus_users_export.csv";' );
|
| 376 |
+
header('Content-Transfer-Encoding: binary');
|
| 377 |
+
flush();
|
| 378 |
+
}
|
| 379 |
+
|
| 380 |
+
|
| 381 |
+
|
| 382 |
+
|
| 383 |
+
//Mage::getModel('mailplus/user')->getResourceCollection();
|
| 384 |
+
$res = Mage::getResourceModel('mailplus/user_collection');
|
| 385 |
+
|
| 386 |
+
|
| 387 |
+
$mapping = array_flip( $this->_csv_mapping_mailplus_magento );
|
| 388 |
+
|
| 389 |
+
$csv_cols = array(
|
| 390 |
+
$mapping['firstname'],
|
| 391 |
+
$mapping['lastname'],
|
| 392 |
+
$mapping['email'],
|
| 393 |
+
str_replace('_',':', $mapping['is_test']), // :S mailplus import and export columns differs
|
| 394 |
+
'externalContactId',
|
| 395 |
+
|
| 396 |
+
'Tussenvoegsel',
|
| 397 |
+
'Geslacht',
|
| 398 |
+
'Straat',
|
| 399 |
+
'Huisnummer',
|
| 400 |
+
'Postcode',
|
| 401 |
+
'Woonplaats',
|
| 402 |
+
'Bedrijfsnaam',
|
| 403 |
+
'Telefoon nr.',
|
| 404 |
+
'Geboortedag',
|
| 405 |
+
'Land'
|
| 406 |
+
);
|
| 407 |
+
|
| 408 |
+
$handle = fopen('php://temp', 'rw');
|
| 409 |
+
fputcsv($handle, $csv_cols, $CSV_DELIMITER, $CSV_ENCLOSURE);
|
| 410 |
+
|
| 411 |
+
/* @var $dataHelper Techtwo_Mailplus_Helper_Data */
|
| 412 |
+
$dataHelper = Mage::helper('mailplus');
|
| 413 |
+
|
| 414 |
+
/* @var $res Techtwo_Mailplus_Model_Mysql4_User_Collection */
|
| 415 |
+
$total_items = $res->getSize();
|
| 416 |
+
if ( $total_items )
|
| 417 |
+
{
|
| 418 |
+
$total_pages = ceil( $total_items / $page_size );
|
| 419 |
+
$customer = Mage::getModel('customer/customer');
|
| 420 |
+
/* @var $customer Mage_Customer_Model_Customer */
|
| 421 |
+
|
| 422 |
+
while ( $total_pages-- )
|
| 423 |
+
{
|
| 424 |
+
$res->getSelect()->limitPage($page, $page_size);
|
| 425 |
+
$items = $res->load();
|
| 426 |
+
|
| 427 |
+
$items = $items->toArray();
|
| 428 |
+
$items = $items['items'];
|
| 429 |
+
foreach ( $items as $item )
|
| 430 |
+
{
|
| 431 |
+
$is_test = 'Nee';
|
| 432 |
+
if ( '1' == $item['is_test'] )
|
| 433 |
+
$is_test = 'Ja';
|
| 434 |
+
|
| 435 |
+
$csv_data = array(
|
| 436 |
+
$item['firstname'],
|
| 437 |
+
$item['lastname'],
|
| 438 |
+
$item['email'],
|
| 439 |
+
$is_test,
|
| 440 |
+
$item['user_id'],
|
| 441 |
+
|
| 442 |
+
'Tussenvoegsel' => '',
|
| 443 |
+
'Geslacht' => '',
|
| 444 |
+
'Straat' => '',
|
| 445 |
+
'Huisnummer' => '',
|
| 446 |
+
'Postcode' => '',
|
| 447 |
+
'Woonplaats' => '',
|
| 448 |
+
'Bedrijfsnaam' => '',
|
| 449 |
+
'Telefoon nr.' => '',
|
| 450 |
+
'Geboortedag' => '',
|
| 451 |
+
'Land' => ''
|
| 452 |
+
);
|
| 453 |
+
|
| 454 |
+
|
| 455 |
+
if ( (int) $item['customer_id'] > 0 && $customer->load($item['customer_id'])->getId() )
|
| 456 |
+
{
|
| 457 |
+
$adrress = $customer->getAddresses();
|
| 458 |
+
|
| 459 |
+
if ( array_key_exists($customer->getData('default_billing'), $adrress) )
|
| 460 |
+
{
|
| 461 |
+
$adrress = $adrress[$customer->getData('default_billing')]->toArray(); // Mage_Customer_Model_Address Object
|
| 462 |
+
|
| 463 |
+
$gender = $customer->getGender();
|
| 464 |
+
if ( $dataHelper->getMagentoGenderMaleId() == $gender )
|
| 465 |
+
$gender = 'M';
|
| 466 |
+
elseif ( $dataHelper->getMagentoGenderFemaleId() == $gender )
|
| 467 |
+
$gender = 'F';
|
| 468 |
+
else
|
| 469 |
+
$gender = '';
|
| 470 |
+
|
| 471 |
+
|
| 472 |
+
//$csv_data['Tussenvoegsel'] = $customer->getData('street'); ???? its not here :S
|
| 473 |
+
list($street, $housenumber) = explode("\n", $adrress['street'], 2);
|
| 474 |
+
$csv_data['Geslacht'] = $gender;
|
| 475 |
+
$csv_data['Geboortedag'] = $customer->getDob();
|
| 476 |
+
$csv_data['Straat'] = trim($street);
|
| 477 |
+
$csv_data['Huisnummer'] = $housenumber? trim($housenumber):'';
|
| 478 |
+
$csv_data['Woonplaats'] = $adrress['city'];
|
| 479 |
+
$csv_data['Postcode'] = $adrress['postcode'];
|
| 480 |
+
$csv_data['Telefoon nr.'] = $adrress['telephone'];
|
| 481 |
+
$csv_data['Land'] = $adrress['country_id'];
|
| 482 |
+
}
|
| 483 |
+
}
|
| 484 |
+
|
| 485 |
+
|
| 486 |
+
fputcsv($handle, $csv_data, $CSV_DELIMITER, $CSV_ENCLOSURE);
|
| 487 |
+
}
|
| 488 |
+
|
| 489 |
+
$res->clear(); // clear loaded data, so we can re-use the object
|
| 490 |
+
$page++;
|
| 491 |
+
}
|
| 492 |
+
//echo ;
|
| 493 |
+
|
| 494 |
+
|
| 495 |
+
/*
|
| 496 |
+
$res = Mage::getResourceModel('mailplus/user');
|
| 497 |
+
/ * @var $res Techtwo_Mailplus_Model_Mysql4_User * /
|
| 498 |
+
echo $res->getMainTable();
|
| 499 |
+
*/
|
| 500 |
+
}
|
| 501 |
+
|
| 502 |
+
|
| 503 |
+
rewind($handle);
|
| 504 |
+
fpassthru($handle);
|
| 505 |
+
fclose($handle);
|
| 506 |
+
|
| 507 |
+
|
| 508 |
+
|
| 509 |
+
return;
|
| 510 |
+
|
| 511 |
+
$this->loadLayout()
|
| 512 |
+
->_setActiveMenu('mailplus')
|
| 513 |
+
->renderLayout();
|
| 514 |
+
}
|
| 515 |
+
|
| 516 |
+
/*
|
| 517 |
+
protected function _addContent(Mage_Core_Block_Abstract $block)
|
| 518 |
+
{
|
| 519 |
+
$this->getLayout()->getBlock('content')->append($block);
|
| 520 |
+
return $this;
|
| 521 |
+
} */
|
| 522 |
+
}
|
app/code/community/Techtwo/Mailplus/controllers/CustomerController.php
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
require 'Mage/Newsletter/controllers/ManageController.php';
|
| 18 |
+
|
| 19 |
+
/**
|
| 20 |
+
* Customers newsletter subscription controller
|
| 21 |
+
*
|
| 22 |
+
* This checks the mailplus user.
|
| 23 |
+
* Magento subscriber is really weird, if you are registered on webshop 1, then subscribe on webshop 2 and refresh the account in webshop1, the customer_id is added int he store webshop 2 entry and the subscriber is set to on.
|
| 24 |
+
* This could be a magento bug or it is not multi store.
|
| 25 |
+
*
|
| 26 |
+
* This at least fixes it to use the actual user permissions.
|
| 27 |
+
*/
|
| 28 |
+
class Techtwo_Mailplus_CustomerController extends Mage_Newsletter_ManageController
|
| 29 |
+
{
|
| 30 |
+
|
| 31 |
+
}
|
app/code/community/Techtwo/Mailplus/controllers/ImageController.php
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
class Techtwo_Mailplus_ImageController extends Mage_Core_Controller_Front_Action
|
| 18 |
+
{
|
| 19 |
+
public function getAction() {
|
| 20 |
+
$params = $this->getRequest()->getParams();
|
| 21 |
+
|
| 22 |
+
$productId = $params['id'];
|
| 23 |
+
$formatParam = $params['f'];
|
| 24 |
+
|
| 25 |
+
if ($productId && $formatParam) {
|
| 26 |
+
$image = Mage::helper('catalog/image');
|
| 27 |
+
$mailplus = Mage::helper('mailplus');
|
| 28 |
+
$mpProduct = Mage::getModel('mailplus/product')->load($productId);
|
| 29 |
+
|
| 30 |
+
if ($mpProduct && $mpProduct->getId()) {
|
| 31 |
+
$product = Mage::getModel('catalog/product')->load($mpProduct->getCatalogProductEntityId());
|
| 32 |
+
|
| 33 |
+
$format = Techtwo_Mailplus_Helper_Data::SMALL_IMAGE_MAX;
|
| 34 |
+
if ($formatParam == 'l') {
|
| 35 |
+
$format = Techtwo_Mailplus_Helper_Data::LARGE_IMAGE_MAX;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
$image = $image->init($product, 'small_image');
|
| 39 |
+
$url = $image
|
| 40 |
+
->keepFrame( '1' === Mage::getStoreConfig('mailplus/advanced/image_keep_frame') )
|
| 41 |
+
->resize($format);
|
| 42 |
+
|
| 43 |
+
$this->getResponse()->setRedirect($url);
|
| 44 |
+
return;
|
| 45 |
+
}
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
$this->getResponse()->setHeader('HTTP/1.1','404 Not Found');
|
| 49 |
+
$this->getResponse()->setHeader('Status','404 File not found');
|
| 50 |
+
}
|
| 51 |
+
}
|
app/code/community/Techtwo/Mailplus/controllers/Mailplus/Entry.php
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
class Mailplus_Mailplus_Entry
|
| 18 |
+
{
|
| 19 |
+
/**
|
| 20 |
+
* Array of Feed data for rendering by Extension's renderers
|
| 21 |
+
*
|
| 22 |
+
* @var array
|
| 23 |
+
*/
|
| 24 |
+
protected $_data = array();
|
| 25 |
+
|
| 26 |
+
/**
|
| 27 |
+
* Encoding of all text values
|
| 28 |
+
*
|
| 29 |
+
* @var string
|
| 30 |
+
*/
|
| 31 |
+
protected $_encoding = 'UTF-8';
|
| 32 |
+
|
| 33 |
+
/**
|
| 34 |
+
* Set feed encoding
|
| 35 |
+
*
|
| 36 |
+
* @param string $enc
|
| 37 |
+
* @return Mailplus_Mailplus_Renderer_Entry
|
| 38 |
+
*/
|
| 39 |
+
public function setEncoding($enc)
|
| 40 |
+
{
|
| 41 |
+
$this->_encoding = $enc;
|
| 42 |
+
return $this;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
/**
|
| 46 |
+
* Get feed encoding
|
| 47 |
+
*
|
| 48 |
+
* @return string
|
| 49 |
+
*/
|
| 50 |
+
public function getEncoding()
|
| 51 |
+
{
|
| 52 |
+
return $this->_encoding;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
/**
|
| 56 |
+
* Set price
|
| 57 |
+
*
|
| 58 |
+
* @param string $value
|
| 59 |
+
* @return Mailplus_Mailplus_Renderer_Entry
|
| 60 |
+
*/
|
| 61 |
+
public function setMailplusPrice( Mage_Catalog_Model_Product $product )
|
| 62 |
+
{
|
| 63 |
+
// GET prijs exclusive BTW
|
| 64 |
+
$taxHelper = Mage::helper('tax');
|
| 65 |
+
/* @var $taxHelper Mage_Tax_Helper_Data */
|
| 66 |
+
|
| 67 |
+
$price = $taxHelper->getPrice( $product, $product->getFinalPrice(), true );
|
| 68 |
+
$price_no_btw = $taxHelper->getPrice( $product, $product->getFinalPrice() );
|
| 69 |
+
|
| 70 |
+
$this->_data['price'] = array(
|
| 71 |
+
'product_price' => $taxHelper->getPrice( $product, $product->getPrice(), true ),
|
| 72 |
+
'product_without_taxes' => $taxHelper->getPrice( $product, $product->getPrice() ),
|
| 73 |
+
'final' => $price,
|
| 74 |
+
'without_taxes' => $price_no_btw
|
| 75 |
+
);
|
| 76 |
+
return $this;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
/**
|
| 80 |
+
* Set special price
|
| 81 |
+
*
|
| 82 |
+
* @param string $value
|
| 83 |
+
* @return Mailplus_Mailplus_Renderer_Entry
|
| 84 |
+
*/
|
| 85 |
+
public function setMailplusSpecialPrice( Mage_Catalog_Model_Product $product )
|
| 86 |
+
{
|
| 87 |
+
// GET prijs exclusive BTW
|
| 88 |
+
$taxHelper = Mage::helper('tax');
|
| 89 |
+
/* @var $taxHelper Mage_Tax_Helper_Data */
|
| 90 |
+
//var_dump($product); die();
|
| 91 |
+
|
| 92 |
+
$price = $taxHelper->getPrice( $product, $product->getSpecialPrice(), true );
|
| 93 |
+
$price_no_btw = $taxHelper->getPrice( $product, $product->getSpecialPrice(), false );
|
| 94 |
+
|
| 95 |
+
$this->_data['specialprice'] = array(
|
| 96 |
+
'final' => $price,
|
| 97 |
+
'without_taxes' => $price_no_btw
|
| 98 |
+
);
|
| 99 |
+
return $this;
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
public function setMailplusWeight($value)
|
| 103 |
+
{
|
| 104 |
+
if (is_numeric($value))
|
| 105 |
+
$this->_data['weight'] = (float) $value; // casting to float ensures 0 values will not be printed
|
| 106 |
+
return $this;
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
/**
|
| 110 |
+
* @param type $base_image
|
| 111 |
+
* @param type $small_image This is mailplus default 'image'
|
| 112 |
+
* @param type $thumbnail
|
| 113 |
+
* @return \Mailplus_Mailplus_Entry
|
| 114 |
+
*/
|
| 115 |
+
public function setMailplusImage($base_image, $small_image, $thumbnail)
|
| 116 |
+
{
|
| 117 |
+
$this->_data['image'] = array(
|
| 118 |
+
'base' => $base_image,
|
| 119 |
+
'small' => $small_image,
|
| 120 |
+
'thumbnail' => $thumbnail
|
| 121 |
+
);
|
| 122 |
+
return $this;
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
public function setMailplusSku($value)
|
| 126 |
+
{
|
| 127 |
+
$this->_data['sku'] = $value;
|
| 128 |
+
return $this;
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
public function setMailplusLogo($value)
|
| 132 |
+
{
|
| 133 |
+
$this->_data['logo'] = $value;
|
| 134 |
+
return $this;
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
public function setMailplusQty($value)
|
| 138 |
+
{
|
| 139 |
+
$this->_data['qty'] = $value;
|
| 140 |
+
return $this;
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
public function setMailplusBackorders($value)
|
| 144 |
+
{
|
| 145 |
+
$this->_data['backorders'] = $value;
|
| 146 |
+
return $this;
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
public function setMailplusIsInStock($value)
|
| 150 |
+
{
|
| 151 |
+
if ( is_bool($value) )
|
| 152 |
+
; // bool is ok
|
| 153 |
+
elseif ( is_string($value) && ( '1' === $value || '0' === $value ) )
|
| 154 |
+
$value = '1' === $value; // a string either "1" or "0" is good, but we replace it boolean
|
| 155 |
+
else
|
| 156 |
+
throw new Zend_Feed_Exception('invalid parameter: MailPlus "IsInStock" must be an boolean or a string "1" or "0"');
|
| 157 |
+
|
| 158 |
+
$this->_data['isInStock'] = $value;
|
| 159 |
+
return $this;
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
public function setMailPlusShortDescription($value)
|
| 163 |
+
{
|
| 164 |
+
$this->_data['shortDescription'] = $value;
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
/*
|
| 168 |
+
public function setMailplusSummary($value)
|
| 169 |
+
{
|
| 170 |
+
if (iconv_strlen($value, $this->getEncoding()) > 4000) {
|
| 171 |
+
#require_once 'Zend/Feed/Exception.php';
|
| 172 |
+
throw new Zend_Feed_Exception('invalid parameter: "summary" may only'
|
| 173 |
+
. ' contain a maximum of 4000 characters');
|
| 174 |
+
}
|
| 175 |
+
$this->_data['summary'] = $value;
|
| 176 |
+
return $this;
|
| 177 |
+
}
|
| 178 |
+
*/
|
| 179 |
+
|
| 180 |
+
/**
|
| 181 |
+
* Overloading to mailplus specific setters
|
| 182 |
+
*
|
| 183 |
+
* @param string $method
|
| 184 |
+
* @param array $params
|
| 185 |
+
* @return mixed
|
| 186 |
+
*/
|
| 187 |
+
public function __call($method, array $params)
|
| 188 |
+
{
|
| 189 |
+
if (strlen($method) < 9)
|
| 190 |
+
return;
|
| 191 |
+
|
| 192 |
+
$point = Zend_Feed_Writer::lcfirst(substr($method, 11));
|
| 193 |
+
|
| 194 |
+
if ( !method_exists($this, 'setMailplus' . ucfirst($point)) && !method_exists($this, 'addMailplus' . ucfirst($point)) )
|
| 195 |
+
{
|
| 196 |
+
#require_once 'Zend/Feed/Writer/Exception/InvalidMethodException.php';
|
| 197 |
+
throw new Zend_Feed_Writer_Exception_InvalidMethodException(
|
| 198 |
+
'invalid method: ' . $method
|
| 199 |
+
);
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
if (!array_key_exists($point, $this->_data) || empty($this->_data[$point]) )
|
| 203 |
+
{
|
| 204 |
+
return null;
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
return $this->_data[$point];
|
| 208 |
+
}
|
| 209 |
+
}
|
| 210 |
+
|
app/code/community/Techtwo/Mailplus/controllers/Mailplus/Renderer/Entry.php
ADDED
|
@@ -0,0 +1,282 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
class Mailplus_Mailplus_Renderer_Entry extends Zend_Feed_Writer_Extension_RendererAbstract
|
| 18 |
+
{
|
| 19 |
+
/**
|
| 20 |
+
* Set to TRUE if a rendering method actually renders something. This
|
| 21 |
+
* is used to prevent premature appending of a XML namespace declaration
|
| 22 |
+
* until an element which requires it is actually appended.
|
| 23 |
+
*
|
| 24 |
+
* @var bool
|
| 25 |
+
*/
|
| 26 |
+
protected $_called = false;
|
| 27 |
+
|
| 28 |
+
protected $_dataContainer;
|
| 29 |
+
|
| 30 |
+
/**
|
| 31 |
+
* Render entry
|
| 32 |
+
*
|
| 33 |
+
* @return void
|
| 34 |
+
*/
|
| 35 |
+
public function render()
|
| 36 |
+
{
|
| 37 |
+
$this->_dataContainer = $this->getDataContainer();
|
| 38 |
+
|
| 39 |
+
$this->_setPrice($this->_dom, $this->_base);
|
| 40 |
+
$this->_setSpecialPrice($this->_dom, $this->_base);
|
| 41 |
+
$this->_setImage($this->_dom, $this->_base);
|
| 42 |
+
$this->_setSku($this->_dom, $this->_base);
|
| 43 |
+
$this->_setQty($this->_dom, $this->_base);
|
| 44 |
+
$this->_setBackorders($this->_dom, $this->_base);
|
| 45 |
+
$this->_setIsInStock($this->_dom, $this->_base);
|
| 46 |
+
$this->_setShortDescription($this->_dom, $this->_base);
|
| 47 |
+
$this->_setWeight($this->_dom, $this->_base);
|
| 48 |
+
$this->_setLogo($this->_dom, $this->_base);
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
if ($this->_called)
|
| 52 |
+
$this->_appendNamespaces();
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
/**
|
| 56 |
+
* Append namespaces to entry root
|
| 57 |
+
*
|
| 58 |
+
* @return void
|
| 59 |
+
*/
|
| 60 |
+
protected function _appendNamespaces()
|
| 61 |
+
{
|
| 62 |
+
$this->getRootElement()->setAttribute('xmlns:mailplus', 'http://api.mailplus.nl/rss/mailplus/');
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
private function _priceElementHelper(DOMDocument $dom, DOMElement $root, $price, $isOldPrice, $isExlTaxes)
|
| 66 |
+
{
|
| 67 |
+
$prefix = $isOldPrice? 'oude':'';
|
| 68 |
+
$prefix .= 'prijs';
|
| 69 |
+
$prefix .= $isExlTaxes? 'exbtw':'';
|
| 70 |
+
|
| 71 |
+
list( $integer, $decimals ) = strpos((string) $price, '.')? explode('.', ''.$price):array($price, '00');
|
| 72 |
+
|
| 73 |
+
if ( strlen($decimals) > 2)
|
| 74 |
+
$decimals = substr($decimals, 0,2);
|
| 75 |
+
else
|
| 76 |
+
{
|
| 77 |
+
while ( strlen($decimals) < 2 )
|
| 78 |
+
$decimals .= '0';
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
$el = $dom->createElement("mailplus:{$prefix}");
|
| 82 |
+
$text = $dom->createTextNode( "{$integer}.{$decimals}" );
|
| 83 |
+
$el->appendChild( $text );
|
| 84 |
+
$root->appendChild( $el );
|
| 85 |
+
|
| 86 |
+
$el = $dom->createElement("mailplus:{$prefix}voorkomma");
|
| 87 |
+
$text = $dom->createTextNode( $integer );
|
| 88 |
+
$el->appendChild( $text );
|
| 89 |
+
$root->appendChild( $el );
|
| 90 |
+
|
| 91 |
+
$el = $dom->createElement("mailplus:{$prefix}nakomma");
|
| 92 |
+
$text = $dom->createTextNode( $decimals );
|
| 93 |
+
$el->appendChild( $text );
|
| 94 |
+
$root->appendChild( $el );
|
| 95 |
+
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
/**
|
| 100 |
+
* If special price is set, then mailplus 'special price' is set to 'prijs' instead. The value 'price' itself is moved to 'oudeprijs'.
|
| 101 |
+
* @param DOMDocument $dom
|
| 102 |
+
* @param DOMElement $root
|
| 103 |
+
* @return type
|
| 104 |
+
*/
|
| 105 |
+
protected function _setPrice(DOMDocument $dom, DOMElement $root)
|
| 106 |
+
{
|
| 107 |
+
$priceSet = $this->_dataContainer->getMailplusPrice();
|
| 108 |
+
if (!$priceSet)
|
| 109 |
+
return;
|
| 110 |
+
|
| 111 |
+
$oldPriceSet = NULL;
|
| 112 |
+
$specialPriceSet = $this->_dataContainer->getMailplusSpecialprice();
|
| 113 |
+
if ( $specialPriceSet )
|
| 114 |
+
{
|
| 115 |
+
// Special price becomes price
|
| 116 |
+
// Price becomes old
|
| 117 |
+
$oldPriceSet = array(
|
| 118 |
+
'final' => $priceSet['product_price'],
|
| 119 |
+
'without_taxes' => $priceSet['product_without_taxes'],
|
| 120 |
+
);
|
| 121 |
+
$priceSet = $specialPriceSet;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
$this->_priceElementHelper($dom, $root, $priceSet['final'], false, false);
|
| 125 |
+
$this->_priceElementHelper($dom, $root, $priceSet['without_taxes'], false, true);
|
| 126 |
+
|
| 127 |
+
if ( $specialPriceSet )
|
| 128 |
+
{
|
| 129 |
+
$this->_priceElementHelper($dom, $root, $oldPriceSet['final'], true, false);
|
| 130 |
+
$this->_priceElementHelper($dom, $root, $oldPriceSet['without_taxes'], true, true);
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
$this->_called = true;
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
protected function _setSpecialPrice(DOMDocument $dom, DOMElement $root)
|
| 139 |
+
{
|
| 140 |
+
return; // Done in _setPrice() - see comments there
|
| 141 |
+
|
| 142 |
+
$priceSet = $this->_dataContainer->getMailplusSpecialprice();
|
| 143 |
+
if (!$priceSet)
|
| 144 |
+
return;
|
| 145 |
+
|
| 146 |
+
$price = $priceSet['final'];
|
| 147 |
+
|
| 148 |
+
$el = $dom->createElement('mailplus:aanbieding');
|
| 149 |
+
$text = $dom->createTextNode($price);
|
| 150 |
+
$el->appendChild($text);
|
| 151 |
+
$root->appendChild($el);
|
| 152 |
+
$this->_called = true;
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
protected function _setImage(DOMDocument $dom, DOMElement $root)
|
| 156 |
+
{
|
| 157 |
+
$imageSet = $this->_dataContainer->getMailplusImage();
|
| 158 |
+
if ( !$imageSet || !is_array($imageSet) )
|
| 159 |
+
return;
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
if ( array_key_exists('base', $imageSet) && $imageSet['base'])
|
| 163 |
+
{
|
| 164 |
+
$el = $dom->createElement('mailplus:afbeeldinggroot');
|
| 165 |
+
$text = $dom->createTextNode($imageSet['base']);
|
| 166 |
+
$el->appendChild($text);
|
| 167 |
+
$root->appendChild($el);
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
if ( array_key_exists('small', $imageSet) && $imageSet['small'])
|
| 171 |
+
{
|
| 172 |
+
$el = $dom->createElement('mailplus:afbeelding');
|
| 173 |
+
$text = $dom->createTextNode($imageSet['small']);
|
| 174 |
+
$el->appendChild($text);
|
| 175 |
+
$root->appendChild($el);
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
if ( array_key_exists('thumbnail', $imageSet) && $imageSet['thumbnail'])
|
| 179 |
+
{
|
| 180 |
+
$el = $dom->createElement('mailplus:afbeeldingklein');
|
| 181 |
+
$text = $dom->createTextNode($imageSet['thumbnail']);
|
| 182 |
+
$el->appendChild($text);
|
| 183 |
+
$root->appendChild($el);
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
$this->_called = true;
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
protected function _setSku(DOMDocument $dom, DOMElement $root)
|
| 190 |
+
{
|
| 191 |
+
$value = $this->_dataContainer->getMailplusSku();
|
| 192 |
+
if (!$value)
|
| 193 |
+
return;
|
| 194 |
+
|
| 195 |
+
$el = $dom->createElement('mailplus:artikelnummer');
|
| 196 |
+
$text = $dom->createTextNode($value);
|
| 197 |
+
$el->appendChild($text);
|
| 198 |
+
$root->appendChild($el);
|
| 199 |
+
$this->_called = true;
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
protected function _setQty(DOMDocument $dom, DOMElement $root)
|
| 203 |
+
{
|
| 204 |
+
$value = $this->_dataContainer->getMailplusQty();
|
| 205 |
+
if (!$value)
|
| 206 |
+
return;
|
| 207 |
+
|
| 208 |
+
$el = $dom->createElement('mailplus:voorraad');
|
| 209 |
+
$text = $dom->createTextNode($value);
|
| 210 |
+
$el->appendChild($text);
|
| 211 |
+
$root->appendChild($el);
|
| 212 |
+
$this->_called = true;
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
+
protected function _setBackorders(DOMDocument $dom, DOMElement $root)
|
| 216 |
+
{
|
| 217 |
+
$value = $this->_dataContainer->getMailplusBackorders();
|
| 218 |
+
if (!$value)
|
| 219 |
+
return;
|
| 220 |
+
|
| 221 |
+
$el = $dom->createElement('mailplus:backorders');
|
| 222 |
+
$text = $dom->createTextNode($value);
|
| 223 |
+
$el->appendChild($text);
|
| 224 |
+
$root->appendChild($el);
|
| 225 |
+
$this->_called = true;
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
protected function _setWeight(DOMDocument $dom, DOMElement $root)
|
| 229 |
+
{
|
| 230 |
+
$value = $this->_dataContainer->getMailplusWeight();
|
| 231 |
+
if (!$value)
|
| 232 |
+
return;
|
| 233 |
+
|
| 234 |
+
$el = $dom->createElement('mailplus:gewicht');
|
| 235 |
+
$text = $dom->createTextNode($value);
|
| 236 |
+
$el->appendChild($text);
|
| 237 |
+
$root->appendChild($el);
|
| 238 |
+
$this->_called = true;
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
protected function _setLogo(DOMDocument $dom, DOMElement $root)
|
| 242 |
+
{
|
| 243 |
+
$value = $this->_dataContainer->getMailplusLogo();
|
| 244 |
+
if (!$value)
|
| 245 |
+
return;
|
| 246 |
+
|
| 247 |
+
$el = $dom->createElement('mailplus:logo');
|
| 248 |
+
$text = $dom->createTextNode($value);
|
| 249 |
+
$el->appendChild($text);
|
| 250 |
+
$root->appendChild($el);
|
| 251 |
+
$this->_called = true;
|
| 252 |
+
}
|
| 253 |
+
|
| 254 |
+
protected function _setIsInStock(DOMDocument $dom, DOMElement $root)
|
| 255 |
+
{
|
| 256 |
+
//print_r($this->_dataContainer->getExtension('Mailplus') );
|
| 257 |
+
$value = $this->_dataContainer->getMailplusIsInStock();
|
| 258 |
+
if (NULL === $value)
|
| 259 |
+
return;
|
| 260 |
+
|
| 261 |
+
$el = $dom->createElement('mailplus:op_voorraad');
|
| 262 |
+
$text = $dom->createTextNode( true === $value? '1':'0' );
|
| 263 |
+
$el->appendChild($text);
|
| 264 |
+
$root->appendChild($el);
|
| 265 |
+
$this->_called = true;
|
| 266 |
+
}
|
| 267 |
+
|
| 268 |
+
protected function _setShortDescription(DOMDocument $dom, DOMElement $root)
|
| 269 |
+
{
|
| 270 |
+
//print_r($this->_dataContainer->getExtension('Mailplus') );
|
| 271 |
+
$value = $this->_dataContainer->getMailplusShortDescription();
|
| 272 |
+
if (!$value)
|
| 273 |
+
return;
|
| 274 |
+
|
| 275 |
+
$el = $dom->createElement('mailplus:kortebeschrijving');
|
| 276 |
+
$text = $dom->createTextNode($value);
|
| 277 |
+
$el->appendChild($text);
|
| 278 |
+
$root->appendChild($el);
|
| 279 |
+
$this->_called = true;
|
| 280 |
+
}
|
| 281 |
+
|
| 282 |
+
}
|
app/code/community/Techtwo/Mailplus/controllers/UseController.php
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
class Techtwo_Mailplus_UseController extends Mage_Core_Controller_Front_Action
|
| 18 |
+
{
|
| 19 |
+
public function cartAction()
|
| 20 |
+
{
|
| 21 |
+
/* @var $dataHelper Techtwo_Mailplus_Helper_Data */
|
| 22 |
+
$dataHelper = Mage::helper('mailplus');
|
| 23 |
+
$quote_id = $this->_request->getParam('id');
|
| 24 |
+
/* @var $quote Mage_Sales_Model_Quote */
|
| 25 |
+
$quote = Mage::getModel('sales/quote')->load($quote_id);
|
| 26 |
+
if ($quote->getId())
|
| 27 |
+
{
|
| 28 |
+
/* @var $customerSession Mage_Customer_Model_Session */
|
| 29 |
+
$customerSession = Mage::getSingleton('customer/session');
|
| 30 |
+
$current_customer_id = NULL;
|
| 31 |
+
if ( $customerSession->isLoggedIn() )
|
| 32 |
+
{
|
| 33 |
+
$current_customer_id = $customerSession->getCustomerId();
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
/**
|
| 37 |
+
* You are trying to resume a quote of a customer .. is but you are not logged in
|
| 38 |
+
* You have to authorize yourself if you want to resume from another customer quote
|
| 39 |
+
*/
|
| 40 |
+
if ( $quote->getCustomerId() && NULL === $current_customer_id )
|
| 41 |
+
{
|
| 42 |
+
/* @var $urlHelper Mage_Core_Helper_Url */
|
| 43 |
+
$urlHelper = Mage::helper('core/url');
|
| 44 |
+
|
| 45 |
+
$customerSession->setAfterAuthUrl( $urlHelper->getCurrentUrl() );
|
| 46 |
+
Mage::getSingleton('core/session')->addError(
|
| 47 |
+
$dataHelper->__('Please login to resume continue shopping with your last cart')
|
| 48 |
+
);
|
| 49 |
+
|
| 50 |
+
$this->_redirect('customer/account/login');
|
| 51 |
+
return;
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
/**
|
| 55 |
+
* You are logged in, but you resume a quote from somebody else. That's a nono!
|
| 56 |
+
*/
|
| 57 |
+
if ( $quote->getCustomerId() && $quote->getCustomerId() !== $current_customer_id )
|
| 58 |
+
{
|
| 59 |
+
Mage::getSingleton('core/session')->addError(
|
| 60 |
+
$dataHelper->__('Invalid cart quote')
|
| 61 |
+
);
|
| 62 |
+
$this->_redirect('/');
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
/* @var $checkoutSession Mage_Checkout_Model_Session */
|
| 68 |
+
$checkoutSession = Mage::getSingleton('checkout/session');
|
| 69 |
+
$checkoutSession->replaceQuote( $quote );
|
| 70 |
+
|
| 71 |
+
if ( TRUE !== $quote->getIsActive() || 1 !== (int) $quote->getIsActive() )
|
| 72 |
+
{
|
| 73 |
+
$quote->setIsActive(TRUE);
|
| 74 |
+
$quote->save();
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
Mage::getSingleton('core/session')->addSuccess(
|
| 78 |
+
$dataHelper->__('Your cart is restored')
|
| 79 |
+
);
|
| 80 |
+
$this->_redirect('checkout/cart');
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
}
|
| 85 |
+
}
|
app/code/community/Techtwo/Mailplus/etc/config.xml
ADDED
|
@@ -0,0 +1,397 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<config>
|
| 3 |
+
<modules>
|
| 4 |
+
<Techtwo_Mailplus>
|
| 5 |
+
<version>2.1.0</version>
|
| 6 |
+
<subv>.0</subv>
|
| 7 |
+
</Techtwo_Mailplus>
|
| 8 |
+
</modules>
|
| 9 |
+
<adminhtml>
|
| 10 |
+
<layout>
|
| 11 |
+
<updates>
|
| 12 |
+
<mailplus>
|
| 13 |
+
<file>mailplus.xml</file>
|
| 14 |
+
</mailplus>
|
| 15 |
+
</updates>
|
| 16 |
+
</layout>
|
| 17 |
+
<menu>
|
| 18 |
+
<mailplus translate="title" module="mailplus">
|
| 19 |
+
<title>MailPlus</title>
|
| 20 |
+
<sort_order>50</sort_order>
|
| 21 |
+
<!--<depends><module>Techtwo_Mailplus</module></depends>-->
|
| 22 |
+
<children>
|
| 23 |
+
<status translate="title" module="mailplus">
|
| 24 |
+
<title>Status connector</title>
|
| 25 |
+
<action>mailplus/adminhtml_status</action>
|
| 26 |
+
</status>
|
| 27 |
+
<bounces translate="title" module="mailplus">
|
| 28 |
+
<title>Bounces</title>
|
| 29 |
+
<action>mailplus/adminhtml_bounces</action>
|
| 30 |
+
</bounces>
|
| 31 |
+
<restqueue translate="title" module="mailplus">
|
| 32 |
+
<title>API Queue</title>
|
| 33 |
+
<action>mailplus/adminhtml_restqueue</action>
|
| 34 |
+
</restqueue>
|
| 35 |
+
<mapping translate="title" module="mailplus">
|
| 36 |
+
<title>Mapping</title>
|
| 37 |
+
<action>mailplus/adminhtml_mapping</action>
|
| 38 |
+
</mapping>
|
| 39 |
+
<help translate="title" module="mailplus">
|
| 40 |
+
<title>Help</title>
|
| 41 |
+
<action>mailplus/adminhtml_help</action>
|
| 42 |
+
</help>
|
| 43 |
+
</children>
|
| 44 |
+
</mailplus>
|
| 45 |
+
</menu>
|
| 46 |
+
<acl>
|
| 47 |
+
<resources>
|
| 48 |
+
<all>
|
| 49 |
+
<title>Allow everything</title>
|
| 50 |
+
</all>
|
| 51 |
+
<admin>
|
| 52 |
+
<children>
|
| 53 |
+
<system>
|
| 54 |
+
<children>
|
| 55 |
+
<config>
|
| 56 |
+
<children>
|
| 57 |
+
<mailplus translate="title" module="mailplus">
|
| 58 |
+
<title>MailPlus Configuration</title>
|
| 59 |
+
</mailplus>
|
| 60 |
+
</children>
|
| 61 |
+
</config>
|
| 62 |
+
</children>
|
| 63 |
+
</system>
|
| 64 |
+
|
| 65 |
+
<mailplus translate="title" module="mailplus">
|
| 66 |
+
<title>MailPlus</title>
|
| 67 |
+
<sort_order>50</sort_order>
|
| 68 |
+
<children>
|
| 69 |
+
<status translate="title">
|
| 70 |
+
<title>Status connector</title>
|
| 71 |
+
</status>
|
| 72 |
+
<users translate="title">
|
| 73 |
+
<title>Contacts</title>
|
| 74 |
+
</users>
|
| 75 |
+
<bounces translate="title">
|
| 76 |
+
<title>Bounces</title>
|
| 77 |
+
</bounces>
|
| 78 |
+
<restqueue translate="title">
|
| 79 |
+
<title>API Queue</title>
|
| 80 |
+
</restqueue>
|
| 81 |
+
<mapping translate="title">
|
| 82 |
+
<title>Mapping</title>
|
| 83 |
+
</mapping>
|
| 84 |
+
<help translate="title">
|
| 85 |
+
<title>Help</title>
|
| 86 |
+
</help>
|
| 87 |
+
</children>
|
| 88 |
+
</mailplus>
|
| 89 |
+
|
| 90 |
+
</children>
|
| 91 |
+
</admin>
|
| 92 |
+
</resources>
|
| 93 |
+
</acl>
|
| 94 |
+
<translate>
|
| 95 |
+
<modules>
|
| 96 |
+
<Techtwo_Mailplus>
|
| 97 |
+
<files>
|
| 98 |
+
<default>Techtwo_Mailplus.csv</default>
|
| 99 |
+
</files>
|
| 100 |
+
</Techtwo_Mailplus>
|
| 101 |
+
</modules>
|
| 102 |
+
</translate>
|
| 103 |
+
</adminhtml>
|
| 104 |
+
|
| 105 |
+
<admin>
|
| 106 |
+
<routers>
|
| 107 |
+
<mailplus>
|
| 108 |
+
<use>admin</use>
|
| 109 |
+
<args>
|
| 110 |
+
<module>Techtwo_Mailplus</module>
|
| 111 |
+
<frontName>mailplus</frontName>
|
| 112 |
+
</args>
|
| 113 |
+
</mailplus>
|
| 114 |
+
</routers>
|
| 115 |
+
</admin>
|
| 116 |
+
|
| 117 |
+
<frontend>
|
| 118 |
+
<routers>
|
| 119 |
+
<mailplus>
|
| 120 |
+
<use>standard</use>
|
| 121 |
+
<args>
|
| 122 |
+
<module>Techtwo_Mailplus</module>
|
| 123 |
+
<frontName>mailplus</frontName>
|
| 124 |
+
</args>
|
| 125 |
+
</mailplus>
|
| 126 |
+
</routers>
|
| 127 |
+
<layout>
|
| 128 |
+
<updates>
|
| 129 |
+
<mailplus>
|
| 130 |
+
<file>mailplus.xml</file>
|
| 131 |
+
</mailplus>
|
| 132 |
+
</updates>
|
| 133 |
+
</layout>
|
| 134 |
+
<events>
|
| 135 |
+
<controller_front_send_response_before>
|
| 136 |
+
<observers>
|
| 137 |
+
<techtwo_mailplus_observer_customer>
|
| 138 |
+
<class>Techtwo_Mailplus_Observer_Customer</class>
|
| 139 |
+
<method>register_conversion</method>
|
| 140 |
+
</techtwo_mailplus_observer_customer>
|
| 141 |
+
</observers>
|
| 142 |
+
</controller_front_send_response_before>
|
| 143 |
+
</events>
|
| 144 |
+
</frontend>
|
| 145 |
+
|
| 146 |
+
<default>
|
| 147 |
+
<!-- Set active on 0 by default since we have no id and password -->
|
| 148 |
+
<mailplus>
|
| 149 |
+
<general>
|
| 150 |
+
<active>0</active>
|
| 151 |
+
</general>
|
| 152 |
+
<automailer>
|
| 153 |
+
<enabled>0</enabled>
|
| 154 |
+
</automailer>
|
| 155 |
+
<advanced>
|
| 156 |
+
<image_keep_frame>1</image_keep_frame>
|
| 157 |
+
</advanced>
|
| 158 |
+
<system>
|
| 159 |
+
<last_synchronized>0</last_synchronized>
|
| 160 |
+
</system>
|
| 161 |
+
<debug>
|
| 162 |
+
<log_enabled>0</log_enabled>
|
| 163 |
+
</debug>
|
| 164 |
+
</mailplus>
|
| 165 |
+
</default>
|
| 166 |
+
<global>
|
| 167 |
+
<models>
|
| 168 |
+
<newsletter>
|
| 169 |
+
<rewrite>
|
| 170 |
+
<subscriber>Techtwo_Mailplus_Model_Newsletter_Subscriber</subscriber>
|
| 171 |
+
</rewrite>
|
| 172 |
+
</newsletter>
|
| 173 |
+
|
| 174 |
+
<mailplus>
|
| 175 |
+
<class>Techtwo_Mailplus_Model</class>
|
| 176 |
+
<resourceModel>mailplus_mysql4</resourceModel>
|
| 177 |
+
</mailplus>
|
| 178 |
+
<mailplus_mysql4>
|
| 179 |
+
<class>Techtwo_Mailplus_Model_Mysql4</class>
|
| 180 |
+
<entities>
|
| 181 |
+
<info>
|
| 182 |
+
<table>mailplus_info</table>
|
| 183 |
+
</info>
|
| 184 |
+
<user>
|
| 185 |
+
<table>mailplus_user</table>
|
| 186 |
+
</user>
|
| 187 |
+
<restqueue>
|
| 188 |
+
<table>mailplus_restqueue</table>
|
| 189 |
+
</restqueue>
|
| 190 |
+
<syncqueue>
|
| 191 |
+
<table>mailplus_syncqueue</table>
|
| 192 |
+
</syncqueue>
|
| 193 |
+
<bounce>
|
| 194 |
+
<table>mailplus_bounce</table>
|
| 195 |
+
</bounce>
|
| 196 |
+
<product>
|
| 197 |
+
<table>mailplus_product</table>
|
| 198 |
+
</product>
|
| 199 |
+
<abandoned_campaign>
|
| 200 |
+
<table>mailplus_abandoned_campaign</table>
|
| 201 |
+
</abandoned_campaign>
|
| 202 |
+
</entities>
|
| 203 |
+
</mailplus_mysql4>
|
| 204 |
+
</models>
|
| 205 |
+
<resources>
|
| 206 |
+
<mailplus_setup>
|
| 207 |
+
<setup>
|
| 208 |
+
<module>Techtwo_Mailplus</module>
|
| 209 |
+
</setup>
|
| 210 |
+
<connection>
|
| 211 |
+
<use>core_setup</use>
|
| 212 |
+
</connection>
|
| 213 |
+
</mailplus_setup>
|
| 214 |
+
<mailplus_write>
|
| 215 |
+
<connection>
|
| 216 |
+
<use>core_write</use>
|
| 217 |
+
</connection>
|
| 218 |
+
</mailplus_write>
|
| 219 |
+
<mailplus_read>
|
| 220 |
+
<connection>
|
| 221 |
+
<use>core_read</use>
|
| 222 |
+
</connection>
|
| 223 |
+
</mailplus_read>
|
| 224 |
+
</resources>
|
| 225 |
+
<blocks>
|
| 226 |
+
<mailplus>
|
| 227 |
+
<class>Techtwo_Mailplus_Block</class>
|
| 228 |
+
</mailplus>
|
| 229 |
+
</blocks>
|
| 230 |
+
<helpers>
|
| 231 |
+
<mailplus>
|
| 232 |
+
<class>Techtwo_Mailplus_Helper</class>
|
| 233 |
+
</mailplus>
|
| 234 |
+
</helpers>
|
| 235 |
+
<events>
|
| 236 |
+
<newsletter_subscriber_save_after>
|
| 237 |
+
<observers>
|
| 238 |
+
<techtwo_mailplus_observer_customer>
|
| 239 |
+
<type>singleton</type>
|
| 240 |
+
<class>Techtwo_Mailplus_Observer_Customer</class>
|
| 241 |
+
<method>synchronize_visitor</method>
|
| 242 |
+
</techtwo_mailplus_observer_customer>
|
| 243 |
+
</observers>
|
| 244 |
+
</newsletter_subscriber_save_after>
|
| 245 |
+
<newsletter_subscriber_delete_after>
|
| 246 |
+
<observers>
|
| 247 |
+
<techtwo_mailplus_observer_customer>
|
| 248 |
+
<type>singleton</type>
|
| 249 |
+
<class>Techtwo_Mailplus_Observer_Customer</class>
|
| 250 |
+
<method>delete_visitor</method>
|
| 251 |
+
</techtwo_mailplus_observer_customer>
|
| 252 |
+
</observers>
|
| 253 |
+
</newsletter_subscriber_delete_after>
|
| 254 |
+
<customer_save_after>
|
| 255 |
+
<observers>
|
| 256 |
+
<techtwo_mailplus_observer_customer>
|
| 257 |
+
<type>singleton</type>
|
| 258 |
+
<class>Techtwo_Mailplus_Observer_Customer</class>
|
| 259 |
+
<method>synchronize_customer</method>
|
| 260 |
+
</techtwo_mailplus_observer_customer>
|
| 261 |
+
</observers>
|
| 262 |
+
</customer_save_after>
|
| 263 |
+
<customer_delete_before>
|
| 264 |
+
<observers>
|
| 265 |
+
<techtwo_mailplus_observer_customer>
|
| 266 |
+
<type>singleton</type>
|
| 267 |
+
<class>Techtwo_Mailplus_Observer_Customer</class>
|
| 268 |
+
<method>delete_customer</method>
|
| 269 |
+
</techtwo_mailplus_observer_customer>
|
| 270 |
+
</observers>
|
| 271 |
+
</customer_delete_before>
|
| 272 |
+
<controller_action_postdispatch_customer_account_loginPost>
|
| 273 |
+
<observers>
|
| 274 |
+
<techtwo_mailplus_observer_customer>
|
| 275 |
+
<type>singleton</type>
|
| 276 |
+
<class>Techtwo_Mailplus_Observer_Customer</class>
|
| 277 |
+
<method>login_customer</method>
|
| 278 |
+
</techtwo_mailplus_observer_customer>
|
| 279 |
+
</observers>
|
| 280 |
+
</controller_action_postdispatch_customer_account_loginPost>
|
| 281 |
+
<!--customer_customer_authenticated-->
|
| 282 |
+
<controller_action_postdispatch_customer_account_createpost>
|
| 283 |
+
<observers>
|
| 284 |
+
<techtwo_mailplus_observer_customer>
|
| 285 |
+
<type>singleton</type>
|
| 286 |
+
<class>Techtwo_Mailplus_Observer_Customer</class>
|
| 287 |
+
<method>register_customer</method>
|
| 288 |
+
</techtwo_mailplus_observer_customer>
|
| 289 |
+
</observers>
|
| 290 |
+
</controller_action_postdispatch_customer_account_createpost>
|
| 291 |
+
<controller_action_predispatch_adminhtml_system_config_edit>
|
| 292 |
+
<observers>
|
| 293 |
+
<techtwo_mailplus_observer_config>
|
| 294 |
+
<type>singleton</type>
|
| 295 |
+
<class>Techtwo_Mailplus_Observer_Config</class>
|
| 296 |
+
<method>newsletter_warning</method>
|
| 297 |
+
</techtwo_mailplus_observer_config>
|
| 298 |
+
</observers>
|
| 299 |
+
</controller_action_predispatch_adminhtml_system_config_edit>
|
| 300 |
+
<catalog_product_save_after>
|
| 301 |
+
<observers>
|
| 302 |
+
<techtwo_mailplus_observer_product>
|
| 303 |
+
<type>singleton</type>
|
| 304 |
+
<class>Techtwo_Mailplus_Observer_Product</class>
|
| 305 |
+
<method>synchronize_product</method>
|
| 306 |
+
</techtwo_mailplus_observer_product>
|
| 307 |
+
</observers>
|
| 308 |
+
</catalog_product_save_after>
|
| 309 |
+
<catalog_product_delete_before>
|
| 310 |
+
<observers>
|
| 311 |
+
<techtwo_mailplus_observer_product>
|
| 312 |
+
<type>singleton</type>
|
| 313 |
+
<class>Techtwo_Mailplus_Observer_Product</class>
|
| 314 |
+
<method>delete_product</method>
|
| 315 |
+
</techtwo_mailplus_observer_product>
|
| 316 |
+
</observers>
|
| 317 |
+
</catalog_product_delete_before>
|
| 318 |
+
<checkout_cart_add_product_complete>
|
| 319 |
+
<observers>
|
| 320 |
+
<techtwo_mailplus_observer_customer_conversion>
|
| 321 |
+
<type>singleton</type>
|
| 322 |
+
<class>Techtwo_Mailplus_Observer_Customer</class>
|
| 323 |
+
<method>register_conversion_mailplus</method>
|
| 324 |
+
</techtwo_mailplus_observer_customer_conversion>
|
| 325 |
+
</observers>
|
| 326 |
+
</checkout_cart_add_product_complete>
|
| 327 |
+
<!-- on error controller_action_postdispatch_cms_index_noRoute -->
|
| 328 |
+
<sales_order_place_after>
|
| 329 |
+
<observers>
|
| 330 |
+
<techtwo_mailplus_observer_customer>
|
| 331 |
+
<type>singleton</type>
|
| 332 |
+
<class>Techtwo_Mailplus_Observer_Customer</class>
|
| 333 |
+
<method>create_conversion</method>
|
| 334 |
+
</techtwo_mailplus_observer_customer>
|
| 335 |
+
</observers>
|
| 336 |
+
</sales_order_place_after>
|
| 337 |
+
<sales_order_save_after>
|
| 338 |
+
<observers>
|
| 339 |
+
<techtwo_mailplus_observer_sales_order_save_after>
|
| 340 |
+
<type>singleton</type>
|
| 341 |
+
<class>Techtwo_Mailplus_Observer_Customer</class>
|
| 342 |
+
<method>apply_sales_order_campaign</method>
|
| 343 |
+
</techtwo_mailplus_observer_sales_order_save_after>
|
| 344 |
+
</observers>
|
| 345 |
+
</sales_order_save_after>
|
| 346 |
+
<review_save_before>
|
| 347 |
+
<observers>
|
| 348 |
+
<techtwo_mailplus_review_review_after_save>
|
| 349 |
+
<type>singleton</type>
|
| 350 |
+
<class>Techtwo_Mailplus_Observer_Product</class>
|
| 351 |
+
<method>apply_review_value</method>
|
| 352 |
+
</techtwo_mailplus_review_review_after_save>
|
| 353 |
+
</observers>
|
| 354 |
+
</review_save_before>
|
| 355 |
+
</events>
|
| 356 |
+
</global>
|
| 357 |
+
<crontab>
|
| 358 |
+
<jobs>
|
| 359 |
+
<mailplus_daily_queue>
|
| 360 |
+
<schedule><cron_expr>0 * * * *</cron_expr></schedule>
|
| 361 |
+
<run><model>mailplus/cron_hourly::run</model></run>
|
| 362 |
+
</mailplus_daily_queue>
|
| 363 |
+
|
| 364 |
+
<mailplus_often_cron>
|
| 365 |
+
<schedule><cron_expr>*/5 * * * *</cron_expr></schedule>
|
| 366 |
+
<run><model>mailplus/cron_often::run</model></run>
|
| 367 |
+
</mailplus_often_cron>
|
| 368 |
+
</jobs>
|
| 369 |
+
</crontab>
|
| 370 |
+
<mailplus>
|
| 371 |
+
<in_test_mode>0</in_test_mode>
|
| 372 |
+
|
| 373 |
+
<!-- used in test mode -->
|
| 374 |
+
<wsdl_test>https://test.mailplus.nl/ApiService/soap/{TYPE}?wsdl</wsdl_test>
|
| 375 |
+
<rest_test>https://test.mailplus.nl</rest_test>
|
| 376 |
+
<rest_base_test>/integrationservice</rest_base_test>
|
| 377 |
+
|
| 378 |
+
<!-- used not in test mode -->
|
| 379 |
+
<rest>https://restapi.mailplus.nl</rest>
|
| 380 |
+
<rest_base>/integrationservice-1.1.0</rest_base>
|
| 381 |
+
<!-- END -->
|
| 382 |
+
|
| 383 |
+
|
| 384 |
+
<server_timezone>Europe/Amsterdam</server_timezone>
|
| 385 |
+
<id_prefix>LIVE_</id_prefix>
|
| 386 |
+
|
| 387 |
+
<!--
|
| 388 |
+
rest
|
| 389 |
+
test url | https://test.mailplus.nl
|
| 390 |
+
live url | https://restapi.mailplus.nl
|
| 391 |
+
|
| 392 |
+
wsdl
|
| 393 |
+
test url | https://test.mailplus.nl/ApiService/soap/Contacts_v2?wsdl
|
| 394 |
+
live url | http://api.mailplus.nl/ApiService/soap/{TYPE}?wsdl
|
| 395 |
+
-->
|
| 396 |
+
</mailplus>
|
| 397 |
+
</config>
|
app/code/community/Techtwo/Mailplus/etc/system.xml
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<config>
|
| 3 |
+
<tabs>
|
| 4 |
+
<mailplus translate="label" module="mailplus">
|
| 5 |
+
<label>MailPlus</label>
|
| 6 |
+
<sort_order>100</sort_order>
|
| 7 |
+
</mailplus>
|
| 8 |
+
</tabs>
|
| 9 |
+
<sections>
|
| 10 |
+
<mailplus translate="label">
|
| 11 |
+
<label>MailPlus Configuration</label>
|
| 12 |
+
<!--
|
| 13 |
+
<class>mailplus-section</class>
|
| 14 |
+
<header_css>mailplus-header</header_css>
|
| 15 |
+
-->
|
| 16 |
+
<tab>mailplus</tab>
|
| 17 |
+
<sort_order>200</sort_order>
|
| 18 |
+
<show_in_default>1</show_in_default>
|
| 19 |
+
<show_in_website>1</show_in_website>
|
| 20 |
+
<show_in_store>1</show_in_store>
|
| 21 |
+
<groups>
|
| 22 |
+
<general translate="label comment" module="mailplus">
|
| 23 |
+
<comment><![CDATA[<p>Druk op opslaan na het wijzigen van de <a href="http://www.mailplus.nl/" target="_blank">MailPlus</a>-instellingen.</p>]]></comment>
|
| 24 |
+
<label>General</label>
|
| 25 |
+
<frontend_type>text</frontend_type>
|
| 26 |
+
<sort_order>20</sort_order>
|
| 27 |
+
<expanded>1</expanded><!-- This must be set, so expand by default -->
|
| 28 |
+
<show_in_default>1</show_in_default>
|
| 29 |
+
<show_in_website>1</show_in_website>
|
| 30 |
+
<show_in_store>1</show_in_store>
|
| 31 |
+
<fields>
|
| 32 |
+
<active translate="label">
|
| 33 |
+
<label>Enabled</label>
|
| 34 |
+
<frontend_type>select</frontend_type>
|
| 35 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 36 |
+
<sort_order>1</sort_order>
|
| 37 |
+
<show_in_default>1</show_in_default>
|
| 38 |
+
<show_in_website>1</show_in_website>
|
| 39 |
+
<show_in_store>1</show_in_store>
|
| 40 |
+
</active>
|
| 41 |
+
<rest_consumer_key>
|
| 42 |
+
<label>Consumer key</label>
|
| 43 |
+
<frontend_type>text</frontend_type>
|
| 44 |
+
<sort_order>40</sort_order>
|
| 45 |
+
<show_in_default>0</show_in_default>
|
| 46 |
+
<show_in_website>1</show_in_website>
|
| 47 |
+
<show_in_store>0</show_in_store>
|
| 48 |
+
<comment>You will find the key in your MailPlus-account at MailPlus Settings</comment>
|
| 49 |
+
</rest_consumer_key>
|
| 50 |
+
<rest_secret>
|
| 51 |
+
<label>Consumer secret</label>
|
| 52 |
+
<frontend_type>text</frontend_type>
|
| 53 |
+
<sort_order>50</sort_order>
|
| 54 |
+
<show_in_default>0</show_in_default>
|
| 55 |
+
<show_in_website>1</show_in_website>
|
| 56 |
+
<show_in_store>0</show_in_store>
|
| 57 |
+
<comment>You will find the secret in your MailPlus-account at MailPlus Settings</comment>
|
| 58 |
+
</rest_secret>
|
| 59 |
+
<synchronize>
|
| 60 |
+
<label>Synchroniseren van</label>
|
| 61 |
+
<frontend_type>select</frontend_type>
|
| 62 |
+
<source_model>mailplus/system_config_source_synchronize</source_model>
|
| 63 |
+
<sort_order>70</sort_order>
|
| 64 |
+
<show_in_default>0</show_in_default>
|
| 65 |
+
<show_in_website>1</show_in_website>
|
| 66 |
+
<show_in_store>0</show_in_store>
|
| 67 |
+
</synchronize>
|
| 68 |
+
</fields>
|
| 69 |
+
</general>
|
| 70 |
+
<syncsettings translate="label">
|
| 71 |
+
<label>Sync settings</label>
|
| 72 |
+
<frontend_type>text</frontend_type>
|
| 73 |
+
<sort_order>30</sort_order>
|
| 74 |
+
<expanded>1</expanded>
|
| 75 |
+
<show_in_default>0</show_in_default>
|
| 76 |
+
<show_in_website>1</show_in_website>
|
| 77 |
+
<show_in_store>1</show_in_store>
|
| 78 |
+
|
| 79 |
+
<fields>
|
| 80 |
+
<productspecs>
|
| 81 |
+
<label>Product specificaties</label>
|
| 82 |
+
<frontend_type>select</frontend_type>
|
| 83 |
+
<source_model>mailplus/system_config_source_product_specs</source_model>
|
| 84 |
+
<sort_order>75</sort_order>
|
| 85 |
+
<show_in_default>0</show_in_default>
|
| 86 |
+
<show_in_website>1</show_in_website>
|
| 87 |
+
<show_in_store>0</show_in_store>
|
| 88 |
+
</productspecs>
|
| 89 |
+
</fields>
|
| 90 |
+
</syncsettings>
|
| 91 |
+
<campaign translate="label comment" module="mailplus">
|
| 92 |
+
<!-- <comment><![CDATA[<p>You can start a campaign on any newsletter subscription automatically. This allows you to confirm the subscriber by email.</p>]]></comment> -->
|
| 93 |
+
<!-- translate comment isn't working -->
|
| 94 |
+
<comment><![CDATA[<p>Hieronder kunt u de automatische campagnes van MailPlus instellen.</p>]]></comment>
|
| 95 |
+
<label>MailPlus Campaigns</label>
|
| 96 |
+
<frontend_type>text</frontend_type>
|
| 97 |
+
<sort_order>40</sort_order>
|
| 98 |
+
<expanded>1</expanded><!-- This must be set, so expand by default -->
|
| 99 |
+
<show_in_default>0</show_in_default>
|
| 100 |
+
<show_in_website>1</show_in_website>
|
| 101 |
+
<show_in_store>0</show_in_store>
|
| 102 |
+
<fields>
|
| 103 |
+
<newsletter translate="label comment">
|
| 104 |
+
<label>Newsletter campaign</label>
|
| 105 |
+
<!--<comment><![CDATA[<p>Automatically start a campaign on newsletter subscribe. You may use this to confirm the email.</p>]]></comment>-->
|
| 106 |
+
<frontend_type>select</frontend_type>
|
| 107 |
+
<source_model>mailplus/system_config_source_campaign</source_model>
|
| 108 |
+
<sort_order>10</sort_order>
|
| 109 |
+
<show_in_default>0</show_in_default>
|
| 110 |
+
<show_in_website>1</show_in_website>
|
| 111 |
+
<show_in_store>0</show_in_store>
|
| 112 |
+
</newsletter>
|
| 113 |
+
<abandoned_cart>
|
| 114 |
+
<label>Abandoned cart campaign</label>
|
| 115 |
+
<!--<comment><![CDATA[<p>Automatically start a campaign on newsletter subscribe. You may use this to confirm the email.</p>]]></comment>-->
|
| 116 |
+
<frontend_type>select</frontend_type>
|
| 117 |
+
<source_model>mailplus/system_config_source_campaign</source_model>
|
| 118 |
+
<sort_order>20</sort_order>
|
| 119 |
+
<show_in_default>0</show_in_default>
|
| 120 |
+
<show_in_website>1</show_in_website>
|
| 121 |
+
<show_in_store>0</show_in_store>
|
| 122 |
+
</abandoned_cart>
|
| 123 |
+
<product_review>
|
| 124 |
+
<label>Product review campaign</label>
|
| 125 |
+
<!--<comment><![CDATA[<p>Automatically start a campaign on newsletter subscribe. You may use this to confirm the email.</p>]]></comment>-->
|
| 126 |
+
<frontend_type>select</frontend_type>
|
| 127 |
+
<source_model>mailplus/system_config_source_campaign</source_model>
|
| 128 |
+
<sort_order>30</sort_order>
|
| 129 |
+
<show_in_default>0</show_in_default>
|
| 130 |
+
<show_in_website>1</show_in_website>
|
| 131 |
+
<show_in_store>0</show_in_store>
|
| 132 |
+
</product_review>
|
| 133 |
+
</fields>
|
| 134 |
+
</campaign>
|
| 135 |
+
<!-- automailer is temp off -->
|
| 136 |
+
<automailer translate="label comment">
|
| 137 |
+
<comment><![CDATA[<p>U heeft de mogelijkheid om de periodieke nieuwsbrief vanuit Magento te versturen. Dat betekent dat u niet hoeft in te loggen in <a href="http://www.mailplus.nl/" target="_blank">MailPlus</a>. De geselecteerde producten worden automatisch in de nieuwsbrief ingeladen. Uw nieuwsbrief-template in MailPlus moet hierop ingesteld zijn. Neem hiervoor contact op met uw MailPlus-partner.</p>]]></comment>
|
| 138 |
+
<label>Send MailPlus newsletter from Magento</label>
|
| 139 |
+
<frontend_type>text</frontend_type>
|
| 140 |
+
<sort_order>50</sort_order>
|
| 141 |
+
<expanded>1</expanded><!-- This must be set, so expand by default -->
|
| 142 |
+
<show_in_default>0</show_in_default>
|
| 143 |
+
<show_in_website>0</show_in_website>
|
| 144 |
+
<show_in_store>0</show_in_store>
|
| 145 |
+
<fields>
|
| 146 |
+
<enabled translate="label">
|
| 147 |
+
<label>Enabled</label>
|
| 148 |
+
<frontend_type>select</frontend_type>
|
| 149 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 150 |
+
<sort_order>1</sort_order>
|
| 151 |
+
<show_in_default>0</show_in_default>
|
| 152 |
+
<show_in_website>1</show_in_website>
|
| 153 |
+
<show_in_store>1</show_in_store>
|
| 154 |
+
</enabled>
|
| 155 |
+
<id translate="label comment">
|
| 156 |
+
<label>MailPlus Automailer ID</label>
|
| 157 |
+
<frontend_type>text</frontend_type>
|
| 158 |
+
<sort_order>2</sort_order>
|
| 159 |
+
<show_in_default>0</show_in_default>
|
| 160 |
+
<show_in_website>1</show_in_website>
|
| 161 |
+
<show_in_store>1</show_in_store>
|
| 162 |
+
<comment>Your MailPlus Automailer Id for a periodic newsletter</comment>
|
| 163 |
+
</id>
|
| 164 |
+
</fields>
|
| 165 |
+
</automailer>
|
| 166 |
+
<advanced translate="label">
|
| 167 |
+
<label>Advanced configuration</label>
|
| 168 |
+
<sort_order>60</sort_order>
|
| 169 |
+
<expanded>0</expanded>
|
| 170 |
+
<show_in_default>1</show_in_default>
|
| 171 |
+
<show_in_website>1</show_in_website>
|
| 172 |
+
<show_in_store>1</show_in_store>
|
| 173 |
+
<fields>
|
| 174 |
+
<image_keep_frame>
|
| 175 |
+
<label>Format images</label>
|
| 176 |
+
<frontend_type>select</frontend_type>
|
| 177 |
+
<source_model>mailplus/system_config_source_keepframe</source_model>
|
| 178 |
+
<sort_order>1</sort_order>
|
| 179 |
+
<show_in_default>1</show_in_default>
|
| 180 |
+
<show_in_website>1</show_in_website>
|
| 181 |
+
<show_in_store>1</show_in_store>
|
| 182 |
+
</image_keep_frame>
|
| 183 |
+
</fields>
|
| 184 |
+
</advanced>
|
| 185 |
+
<debug translate="label comment">
|
| 186 |
+
<label>Debug options</label>
|
| 187 |
+
<!--<comment><![CDATA[<p>Debug options</p>]]></comment>-->
|
| 188 |
+
<frontend_type>text</frontend_type>
|
| 189 |
+
<sort_order>900</sort_order>
|
| 190 |
+
<expanded>0</expanded>
|
| 191 |
+
<show_in_default>1</show_in_default>
|
| 192 |
+
<show_in_website>1</show_in_website>
|
| 193 |
+
<show_in_store>1</show_in_store>
|
| 194 |
+
<fields>
|
| 195 |
+
<log_enabled translate="label">
|
| 196 |
+
<label>Log</label>
|
| 197 |
+
<frontend_type>select</frontend_type>
|
| 198 |
+
<!--<source_model>adminhtml/system_config_source_yesno</source_model>-->
|
| 199 |
+
<source_model>mailplus/system_config_source_yesno_default_no</source_model>
|
| 200 |
+
<sort_order>1</sort_order>
|
| 201 |
+
<show_in_default>1</show_in_default>
|
| 202 |
+
<show_in_website>1</show_in_website>
|
| 203 |
+
<show_in_store>1</show_in_store>
|
| 204 |
+
</log_enabled>
|
| 205 |
+
</fields>
|
| 206 |
+
</debug>
|
| 207 |
+
</groups>
|
| 208 |
+
</mailplus>
|
| 209 |
+
</sections>
|
| 210 |
+
</config>
|
app/code/community/Techtwo/Mailplus/sql/mailplus_setup/mysql4-install-2.1.0.php
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
// Since Magento 1.4+ is supported, plain SQL queries instead of DDL are used
|
| 18 |
+
|
| 19 |
+
/* @var $this Mage_Core_Model_Resource_Setup */
|
| 20 |
+
$this->startSetup();
|
| 21 |
+
|
| 22 |
+
$this->run("
|
| 23 |
+
CREATE TABLE IF NOT EXISTS `{$this->getTable('mailplus/bounce')}` (
|
| 24 |
+
`id` int(11) NOT NULL AUTO_INCREMENT,
|
| 25 |
+
`mailplus_id` varchar(255) NOT NULL,
|
| 26 |
+
`firstname` varchar(255) NOT NULL,
|
| 27 |
+
`insertion` varchar(255) NOT NULL,
|
| 28 |
+
`lastname` varchar(255) NOT NULL,
|
| 29 |
+
`email` varchar(255) NOT NULL,
|
| 30 |
+
`total_received` int(10) unsigned NOT NULL,
|
| 31 |
+
`is_test` tinyint(1) NOT NULL,
|
| 32 |
+
`is_customer_alerted` int(11) NOT NULL DEFAULT '0',
|
| 33 |
+
`last_bounce_date` datetime NOT NULL,
|
| 34 |
+
PRIMARY KEY (`id`),
|
| 35 |
+
UNIQUE KEY `mailplus_id` (`mailplus_id`)
|
| 36 |
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ;
|
| 37 |
+
");
|
| 38 |
+
|
| 39 |
+
$this->run("
|
| 40 |
+
CREATE TABLE IF NOT EXISTS `{$this->getTable('mailplus/product')}` (
|
| 41 |
+
`entity_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
| 42 |
+
`catalog_product_entity_id` int(10) unsigned NOT NULL,
|
| 43 |
+
`store_id` smallint(5) unsigned NOT NULL,
|
| 44 |
+
`price` decimal(12,4) NOT NULL COMMENT 'The synchronized price',
|
| 45 |
+
`checksum` bigint(20) NOT NULL,
|
| 46 |
+
`created_at` datetime NOT NULL,
|
| 47 |
+
`updated_at` datetime NOT NULL,
|
| 48 |
+
PRIMARY KEY (`entity_id`),
|
| 49 |
+
UNIQUE KEY `catalog_product_entity_id_2` (`catalog_product_entity_id`,`store_id`),
|
| 50 |
+
KEY `store_id` (`store_id`),
|
| 51 |
+
KEY `catalog_product_entity_id` (`catalog_product_entity_id`)
|
| 52 |
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
| 53 |
+
");
|
| 54 |
+
|
| 55 |
+
$this->run("
|
| 56 |
+
CREATE TABLE IF NOT EXISTS `{$this->getTable('mailplus/restqueue')}` (
|
| 57 |
+
`restqueue_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
| 58 |
+
`method` varchar(255) NOT NULL,
|
| 59 |
+
`url` varchar(255) NOT NULL,
|
| 60 |
+
`payload` text NULL,
|
| 61 |
+
`tries` int(10) unsigned NOT NULL DEFAULT '0',
|
| 62 |
+
`last_error` text NULL,
|
| 63 |
+
`last_response` text NULL,
|
| 64 |
+
`created_at` datetime NOT NULL,
|
| 65 |
+
`last_run_at` datetime NOT NULL,
|
| 66 |
+
`next_run_at` datetime NOT NULL,
|
| 67 |
+
`site` int(10) unsigned NOT NULL,
|
| 68 |
+
PRIMARY KEY (`restqueue_id`)
|
| 69 |
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8
|
| 70 |
+
");
|
| 71 |
+
|
| 72 |
+
$this->run("
|
| 73 |
+
CREATE TABLE `{$this->getTable('mailplus/syncqueue')}` (
|
| 74 |
+
`syncqueue_id` int(11) NOT NULL AUTO_INCREMENT,
|
| 75 |
+
`synctype` varchar(10) NOT NULL,
|
| 76 |
+
`websiteid` int(11) NOT NULL,
|
| 77 |
+
`syncid` int(11) NOT NULL,
|
| 78 |
+
`created_at` datetime NOT NULL,
|
| 79 |
+
PRIMARY KEY (`syncqueue_id`),
|
| 80 |
+
KEY `synctype` (`synctype`,`created_at`),
|
| 81 |
+
KEY `websiteid` (`websiteid`)
|
| 82 |
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8
|
| 83 |
+
");
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
$this->run("
|
| 87 |
+
CREATE TABLE IF NOT EXISTS `{$this->getTable('mailplus/user')}` (
|
| 88 |
+
`user_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
|
| 89 |
+
`customer_id` int(11) unsigned DEFAULT NULL,
|
| 90 |
+
`mailplus_id` char(50) DEFAULT NULL,
|
| 91 |
+
`store_id` smallint(5) unsigned NOT NULL,
|
| 92 |
+
`enabled` tinyint(1) NOT NULL DEFAULT '0',
|
| 93 |
+
`is_test` tinyint(1) NOT NULL DEFAULT '0',
|
| 94 |
+
`firstname` varchar(255) NOT NULL DEFAULT '',
|
| 95 |
+
`lastname` varchar(255) NOT NULL DEFAULT '',
|
| 96 |
+
`email` varchar(255) DEFAULT NULL,
|
| 97 |
+
`createts` int(11) unsigned NOT NULL DEFAULT '0',
|
| 98 |
+
PRIMARY KEY (`user_id`),
|
| 99 |
+
UNIQUE KEY `mailplus_id` (`mailplus_id`),
|
| 100 |
+
KEY `store_id` (`store_id`),
|
| 101 |
+
KEY `store_customer` (`customer_id`)
|
| 102 |
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8
|
| 103 |
+
");
|
| 104 |
+
|
| 105 |
+
$this->run("
|
| 106 |
+
CREATE TABLE `{$this->getTable('mailplus/abandoned_campaign')}` (
|
| 107 |
+
`quote_id` INT( 10 ) UNSIGNED NOT NULL ,
|
| 108 |
+
`created_at` DATETIME NOT NULL ,
|
| 109 |
+
PRIMARY KEY ( `quote_id` )
|
| 110 |
+
) ENGINE = InnoDB;
|
| 111 |
+
");
|
| 112 |
+
|
| 113 |
+
$this->run("
|
| 114 |
+
CREATE TABLE `{$this->getTable('mailplus/info')}` (
|
| 115 |
+
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
|
| 116 |
+
`name` varchar(255) NOT NULL DEFAULT '' ,
|
| 117 |
+
`value` varchar(255) NOT NULL DEFAULT '' ,
|
| 118 |
+
PRIMARY KEY ( `id` ),
|
| 119 |
+
KEY `name` (`name`)
|
| 120 |
+
) ENGINE = InnoDB;
|
| 121 |
+
");
|
| 122 |
+
|
| 123 |
+
$this->run("
|
| 124 |
+
ALTER TABLE `{$this->getTable('mailplus/user')}`
|
| 125 |
+
ADD CONSTRAINT `mailplus_user_ibfk_2` FOREIGN KEY (`customer_id`) REFERENCES `{$this->getTable('customer/entity')}` (`entity_id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
| 126 |
+
ADD CONSTRAINT `mailplus_user_ibfk_3` FOREIGN KEY (`store_id`) REFERENCES `{$this->getTable('core/store')}` (`store_id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
| 127 |
+
");
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
$this->endSetup();
|
app/code/community/Techtwo/Mailplus/sql/mailplus_setup/mysql4-upgrade-0.1.1-0.2.1.php
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
die("The Techtwo COWW connector cannot be upgraded to the MailPlus Connector. Please de-install the COWW connector, remove all mailplus tables from the database and do a clean install of the MailPlus Connector");
|
app/code/community/Techtwo/Mailplus/sql/mailplus_setup/mysql4-upgrade-0.2.1-0.3.1.php
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
die("The Techtwo COWW connector cannot be upgraded to the MailPlus Connector. Please de-install the COWW connector, remove all mailplus tables from the database and do a clean install of the MailPlus Connector");
|
app/code/community/Techtwo/Mailplus/sql/mailplus_setup/mysql4-upgrade-0.3.1-0.3.2.php
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
die("The current MailPlus Connector version cannot be upgraded. Please de-install the MailPlus Connector, remove all mailplus tables from the database and do a clean install of the current MailPlus Connector");
|
app/code/community/Techtwo/Mailplus/sql/mailplus_setup/mysql4-upgrade-0.3.2-0.3.3.php
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/* @var $this Mage_Core_Model_Resource_Setup */
|
| 3 |
+
$this->startSetup();
|
| 4 |
+
|
| 5 |
+
$this->endSetup();
|
app/code/community/Techtwo/Mailplus/sql/mailplus_setup/mysql4-upgrade-0.3.3-1.0.0.php
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/* @var $this Mage_Core_Model_Resource_Setup */
|
| 3 |
+
$this->startSetup();
|
| 4 |
+
|
| 5 |
+
$this->run("DROP TABLE IF EXISTS `{$this->getTable('mailplus/restqueue')}`");
|
| 6 |
+
|
| 7 |
+
$this->run("
|
| 8 |
+
CREATE TABLE `{$this->getTable('mailplus/restqueue')}` (
|
| 9 |
+
`restqueue_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
| 10 |
+
`method` varchar(255) NOT NULL,
|
| 11 |
+
`url` varchar(255) NOT NULL,
|
| 12 |
+
`payload` text NULL,
|
| 13 |
+
`tries` int(10) unsigned NOT NULL DEFAULT '0',
|
| 14 |
+
`last_error` text NULL,
|
| 15 |
+
`last_response` text NULL,
|
| 16 |
+
`created_at` datetime NOT NULL,
|
| 17 |
+
`last_run_at` datetime NOT NULL,
|
| 18 |
+
`next_run_at` datetime NOT NULL,
|
| 19 |
+
`site` int(10) unsigned NOT NULL,
|
| 20 |
+
PRIMARY KEY (`restqueue_id`)
|
| 21 |
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8
|
| 22 |
+
");
|
| 23 |
+
|
| 24 |
+
$this->endSetup();
|
app/code/community/Techtwo/Mailplus/sql/mailplus_setup/mysql4-upgrade-1.0.0-2.0.0.php
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/* @var $this Mage_Core_Model_Resource_Setup */
|
| 3 |
+
$this->startSetup();
|
| 4 |
+
|
| 5 |
+
$this->run("DROP TABLE IF EXISTS `{$this->getTable('mailplus/syncqueue')}`");
|
| 6 |
+
|
| 7 |
+
$this->run("
|
| 8 |
+
CREATE TABLE `{$this->getTable('mailplus/syncqueue')}` (
|
| 9 |
+
`syncqueue_id` int(11) NOT NULL AUTO_INCREMENT,
|
| 10 |
+
`synctype` varchar(10) NOT NULL,
|
| 11 |
+
`websiteid` int(11) NOT NULL,
|
| 12 |
+
`syncid` int(11) NOT NULL,
|
| 13 |
+
`created_at` datetime NOT NULL,
|
| 14 |
+
PRIMARY KEY (`syncqueue_id`),
|
| 15 |
+
KEY `synctype` (`synctype`,`created_at`),
|
| 16 |
+
KEY `websiteid` (`websiteid`)
|
| 17 |
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8
|
| 18 |
+
");
|
| 19 |
+
|
| 20 |
+
$db = $this->getConnection();
|
| 21 |
+
$db->dropForeignKey($this->getTable('mailplus/product'), 'mailplus_product_ibfk_1');
|
| 22 |
+
$db->dropForeignKey($this->getTable('mailplus/product'), 'mailplus_product_ibfk_2');
|
| 23 |
+
$db->dropForeignKey($this->getTable('mailplus/product'), 'mailplus_product_ibfk_3');
|
| 24 |
+
|
| 25 |
+
// This foreign key was added without a name. So make sure to delete it with the correct name
|
| 26 |
+
$db->dropForeignKey($this->getTable('mailplus/abandoned_campaign'), $this->getTable('mailplus/abandoned_campaign') . '_ibfk_1');
|
| 27 |
+
$db->dropForeignKey($this->getTable('mailplus/abandoned_campaign'), $this->getTable('mailplus/abandoned_campaign') . '_ibfk_2');
|
| 28 |
+
|
| 29 |
+
$this->endSetup();
|
app/code/community/Techtwo/Mailplus/sql/mailplus_setup/mysql4-upgrade-2.0.0-2.1.0.php
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/* @var $this Mage_Core_Model_Resource_Setup */
|
| 3 |
+
$this->startSetup();
|
| 4 |
+
|
| 5 |
+
$this->run("
|
| 6 |
+
CREATE TABLE `{$this->getTable('mailplus/info')}` (
|
| 7 |
+
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
|
| 8 |
+
`name` varchar(255) NOT NULL DEFAULT '' ,
|
| 9 |
+
`value` varchar(255) NOT NULL DEFAULT '' ,
|
| 10 |
+
PRIMARY KEY ( `id` ),
|
| 11 |
+
KEY `name` (`name`)
|
| 12 |
+
) ENGINE = InnoDB;
|
| 13 |
+
");
|
| 14 |
+
|
| 15 |
+
$this->endSetup();
|
app/design/adminhtml/default/default/layout/mailplus.xml
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<layout version="0.1.0">
|
| 3 |
+
<default>
|
| 4 |
+
<reference name="notifications">
|
| 5 |
+
<block type="index/adminhtml_notifications" name="mailplus_admin_notifications" template="mailplus/notifications.phtml" />
|
| 6 |
+
</reference>
|
| 7 |
+
</default>
|
| 8 |
+
|
| 9 |
+
<!--
|
| 10 |
+
<mailplus_adminhtml_index_index>
|
| 11 |
+
<reference name="root">
|
| 12 |
+
<block type="page/html" name="content" output="toHtml" template="mailplus/index.phtml" />
|
| 13 |
+
</reference>
|
| 14 |
+
</mailplus_adminhtml_index_index>
|
| 15 |
+
-->
|
| 16 |
+
<mailplus_adminhtml_users_index>
|
| 17 |
+
<reference name="content">
|
| 18 |
+
<block type="mailplus/adminhtml_users" name="mailplus_admin_users" />
|
| 19 |
+
</reference>
|
| 20 |
+
</mailplus_adminhtml_users_index>
|
| 21 |
+
|
| 22 |
+
<mailplus_adminhtml_users_import>
|
| 23 |
+
<reference name="content">
|
| 24 |
+
<block type="mailplus/adminhtml_users" name="mailplus_admin_users_import" template="mailplus/users/import.phtml" />
|
| 25 |
+
</reference>
|
| 26 |
+
</mailplus_adminhtml_users_import>
|
| 27 |
+
|
| 28 |
+
<mailplus_adminhtml_users_export>
|
| 29 |
+
<reference name="content">
|
| 30 |
+
<block type="mailplus/adminhtml_users" name="mailplus_admin_users_export" template="mailplus/users/export.phtml" />
|
| 31 |
+
</reference>
|
| 32 |
+
</mailplus_adminhtml_users_export>
|
| 33 |
+
|
| 34 |
+
<mailplus_adminhtml_bounces_index>
|
| 35 |
+
<reference name="content">
|
| 36 |
+
<block type="mailplus/adminhtml_bounces" name="mailplus_admin_bounces" />
|
| 37 |
+
</reference>
|
| 38 |
+
</mailplus_adminhtml_bounces_index>
|
| 39 |
+
|
| 40 |
+
<mailplus_adminhtml_restqueue_index>
|
| 41 |
+
<reference name="content">
|
| 42 |
+
<block type="mailplus/adminhtml_restqueue" name="mailplus_admin_restqueue" />
|
| 43 |
+
</reference>
|
| 44 |
+
</mailplus_adminhtml_restqueue_index>
|
| 45 |
+
|
| 46 |
+
<mailplus_adminhtml_status_index>
|
| 47 |
+
<reference name="left">
|
| 48 |
+
<block type="adminhtml/template" name="mailplus_website_switcher" template="mailplus/website_switcher.phtml" />
|
| 49 |
+
</reference>
|
| 50 |
+
<reference name="content">
|
| 51 |
+
<block type="adminhtml/template" name="mailplus_admin_help" template="mailplus/status.phtml" />
|
| 52 |
+
<block type="adminhtml/template" name="mailplus_admin_cron_status" template="mailplus/cronstatus.phtml" />
|
| 53 |
+
<block type="mailplus/adminhtml_syncstatus" name="mailplus_admin_syncstatus" />
|
| 54 |
+
</reference>
|
| 55 |
+
</mailplus_adminhtml_status_index>
|
| 56 |
+
|
| 57 |
+
<mailplus_adminhtml_mapping_index>
|
| 58 |
+
<reference name="left">
|
| 59 |
+
<block type="adminhtml/template" name="mailplus_website_switcher" template="mailplus/website_switcher.phtml" />
|
| 60 |
+
</reference>
|
| 61 |
+
<reference name="content">
|
| 62 |
+
<block type="mailplus/adminhtml_mapping" name="mailplus_admin_mapping" />
|
| 63 |
+
</reference>
|
| 64 |
+
</mailplus_adminhtml_mapping_index>
|
| 65 |
+
|
| 66 |
+
<mailplus_adminhtml_mapping_save>
|
| 67 |
+
<reference name="left">
|
| 68 |
+
<block type="adminhtml/template" name="mailplus_website_switcher" template="mailplus/website_switcher.phtml" />
|
| 69 |
+
</reference>
|
| 70 |
+
<reference name="content">
|
| 71 |
+
<block type="mailplus/adminhtml_mapping" name="mailplus_admin_mapping" />
|
| 72 |
+
</reference>
|
| 73 |
+
</mailplus_adminhtml_mapping_save>
|
| 74 |
+
|
| 75 |
+
<mailplus_adminhtml_help_index>
|
| 76 |
+
<reference name="content">
|
| 77 |
+
<block type="adminhtml/template" name="mailplus_admin_help" template="mailplus/help.phtml" />
|
| 78 |
+
</reference>
|
| 79 |
+
</mailplus_adminhtml_help_index>
|
| 80 |
+
|
| 81 |
+
<!--
|
| 82 |
+
<mailplus_adminhtml_bounces_index>
|
| 83 |
+
<reference name="root">
|
| 84 |
+
<block type="page/html" name="content" output="toHtml" template="mailplus/bounces.phtml" />
|
| 85 |
+
</reference>
|
| 86 |
+
</mailplus_adminhtml_bounces_index>-->
|
| 87 |
+
|
| 88 |
+
<!--
|
| 89 |
+
<mailplus_adminhtml_bounces_index>
|
| 90 |
+
<reference name="content">
|
| 91 |
+
<block type="adminhtml/template" name="mycontent" template="mailplus/bounces.phtml" />
|
| 92 |
+
</reference>
|
| 93 |
+
</mailplus_adminhtml_bounces_index>
|
| 94 |
+
-->
|
| 95 |
+
</layout>
|
app/design/adminhtml/default/default/template/mailplus/bounces.phtml
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
$readDb = Mage::getSingleton('core/resource')->getConnection('core_write');
|
| 18 |
+
/* @var $readDb Varien_Db_Adapter_Pdo_Mysql */
|
| 19 |
+
|
| 20 |
+
//echo get_class($readDb);
|
| 21 |
+
//mailplus_bounces
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
$bounces = $readDb->fetchAll("SELECT * FROM mailplus_bounces");
|
| 25 |
+
$cols = array_keys(reset($bounces));
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
echo '<h1>Bounces</h1>';
|
| 29 |
+
echo '<p>No design yet</p>';
|
| 30 |
+
|
| 31 |
+
echo '<table width="100%">';
|
| 32 |
+
echo '<tr>';
|
| 33 |
+
foreach ( $cols as $col )
|
| 34 |
+
echo "<th>$col</th>";
|
| 35 |
+
echo '</tr>';
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
foreach ( $bounces as $bounce )
|
| 39 |
+
{
|
| 40 |
+
echo '<tr>';
|
| 41 |
+
foreach ($bounce as $value)
|
| 42 |
+
echo "<td>$value</td>";
|
| 43 |
+
echo '</tr>';
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
echo '</table>';
|
| 47 |
+
?>
|
app/design/adminhtml/default/default/template/mailplus/cronstatus.phtml
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
$mailplus = Mage::helper('mailplus');
|
| 18 |
+
|
| 19 |
+
$cronOftenStart = Mage::getModel('mailplus/info')->loadByName('cron_often_start');
|
| 20 |
+
$cronOftenEnd = Mage::getModel('mailplus/info')->loadByName('cron_often_end');
|
| 21 |
+
$cronHourlyStart = Mage::getModel('mailplus/info')->loadByName('cron_hourly_start');
|
| 22 |
+
$cronHourlyEnd = Mage::getModel('mailplus/info')->loadByName('cron_hourly_end');
|
| 23 |
+
|
| 24 |
+
function returnDateString($date) {
|
| 25 |
+
$mailplus = Mage::helper('mailplus');
|
| 26 |
+
$dateString = $mailplus->__("never");
|
| 27 |
+
if ($date && $date->getValue()) {
|
| 28 |
+
$dateString = date('Y-m-d H:i', $date->getValue());
|
| 29 |
+
}
|
| 30 |
+
return $dateString;
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
$startStatus = returnDateString($cronOftenStart);
|
| 35 |
+
$endStatus = returnDateString($cronOftenEnd);
|
| 36 |
+
$hourlyStartStatus = returnDateString($cronHourlyStart);
|
| 37 |
+
$hourlyEndStatus = returnDateString($cronHourlyEnd);
|
| 38 |
+
|
| 39 |
+
?>
|
| 40 |
+
<div class="content-header"><h3 class="icon-head"><?php echo $mailplus->__('MailPlus Cron status') ?></h3></div>
|
| 41 |
+
|
| 42 |
+
<table>
|
| 43 |
+
<tr>
|
| 44 |
+
<th colspan="2">Cron often</th>
|
| 45 |
+
</tr>
|
| 46 |
+
|
| 47 |
+
<tr>
|
| 48 |
+
<td><?php echo $mailplus->__('Last started at') ?>:</td>
|
| 49 |
+
<td><?php echo $startStatus ?></td>
|
| 50 |
+
</tr>
|
| 51 |
+
<tr>
|
| 52 |
+
<td><?php echo $mailplus->__('Finished at') ?>:</td>
|
| 53 |
+
<td><?php echo $endStatus ?></td>
|
| 54 |
+
</tr>
|
| 55 |
+
<tr>
|
| 56 |
+
<th colspan="2">Cron hourly</th>
|
| 57 |
+
</tr>
|
| 58 |
+
|
| 59 |
+
<tr>
|
| 60 |
+
<td><?php echo $mailplus->__('Last started at') ?>:</td>
|
| 61 |
+
<td><?php echo $hourlyStartStatus ?></td>
|
| 62 |
+
</tr>
|
| 63 |
+
<tr>
|
| 64 |
+
<td><?php echo $mailplus->__('Finished at') ?>:</td>
|
| 65 |
+
<td><?php echo $hourlyEndStatus ?></td>
|
| 66 |
+
</tr>
|
| 67 |
+
|
| 68 |
+
</table>
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
|
app/design/adminhtml/default/default/template/mailplus/edit.phtml
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
if (!Mage::helper('mailplus')->isEnabled())
|
| 18 |
+
{
|
| 19 |
+
?>
|
| 20 |
+
<div class="error"><h2>Module is not enabled</h2></div>
|
| 21 |
+
<p>
|
| 22 |
+
MailPlus is installed but not enabled. You must enable it to correctly syncronize and use MailPlus services.<br />
|
| 23 |
+
The module must be activated and enabled.
|
| 24 |
+
</p>
|
| 25 |
+
<?php
|
| 26 |
+
return;
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
// echo Mage::getStoreConfig('MailPlus/general/mailplus_id');
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
echo 'empty';
|
| 37 |
+
return;
|
| 38 |
+
?>
|
| 39 |
+
<div id="page:main-container">
|
| 40 |
+
<div id="messages"></div>
|
| 41 |
+
<div class="content-header">
|
| 42 |
+
<table cellspacing="0">
|
| 43 |
+
<tbody><tr>
|
| 44 |
+
<td style="width:50%;"><h3 class="icon-head head-adminhtml-mobile">Edit user</h3></td>
|
| 45 |
+
<td class="form-buttons"><button style="" onclick="setLocation('http://magento.local/index.php/admin/mobile/new/key/53dcbae5fa5a32b19f77601b9ac30bbe/')" class="scalable add" type="button" id="id_fc34dcaa44833e9c687985f298822182"><span>Add App</span></button></td>
|
| 46 |
+
</tr>
|
| 47 |
+
</tbody></table>
|
| 48 |
+
</div>
|
| 49 |
+
<div>
|
| 50 |
+
|
| 51 |
+
<div id="mobile_apps_grid">
|
| 52 |
+
<table cellspacing="0" class="actions">
|
| 53 |
+
<tbody><tr>
|
| 54 |
+
<td class="pager">
|
| 55 |
+
Page
|
| 56 |
+
<img class="arrow" alt="Go to Previous page" src="http://magento.local/skin/adminhtml/default/default/images/pager_arrow_left_off.gif">
|
| 57 |
+
|
| 58 |
+
<input type="text" onkeypress="mobile_apps_gridJsObject.inputPage(event, '1')" class="input-text page" value="1" name="page">
|
| 59 |
+
|
| 60 |
+
<img class="arrow" alt="Go to Previous page" src="http://magento.local/skin/adminhtml/default/default/images/pager_arrow_right_off.gif">
|
| 61 |
+
|
| 62 |
+
of 1 pages <span class="separator">|</span>
|
| 63 |
+
View <select onchange="mobile_apps_gridJsObject.loadByElement(this)" name="limit">
|
| 64 |
+
<option selected="selected" value="20">20</option>
|
| 65 |
+
<option value="30">30</option>
|
| 66 |
+
<option value="50">50</option>
|
| 67 |
+
<option value="100">100</option>
|
| 68 |
+
<option value="200">200</option>
|
| 69 |
+
</select>
|
| 70 |
+
per page<span class="separator">|</span>
|
| 71 |
+
Total 0 records found <span class="no-display" id="mobile_apps_grid-total-count">0</span>
|
| 72 |
+
</td>
|
| 73 |
+
<td class="filter-actions a-right">
|
| 74 |
+
<button style="" onclick="mobile_apps_gridJsObject.resetFilter()" class="scalable " type="button" id="id_42b86e575de572cdbc965e3de5301646"><span>Reset Filter</span></button><button style="" onclick="mobile_apps_gridJsObject.doFilter()" class="scalable task" type="button" id="id_961935cee023689cbeb9f54014d04c79"><span>Search</span></button> </td>
|
| 75 |
+
</tr>
|
| 76 |
+
</tbody></table>
|
| 77 |
+
<div class="grid">
|
| 78 |
+
<div class="hor-scroll">
|
| 79 |
+
<table cellspacing="0" id="mobile_apps_grid_table" class="data">
|
| 80 |
+
<colgroup><col>
|
| 81 |
+
<col width="200">
|
| 82 |
+
<col>
|
| 83 |
+
<col>
|
| 84 |
+
</colgroup><thead>
|
| 85 |
+
<tr class="headings">
|
| 86 |
+
<th><span class="nobr"><a class="not-sort" title="asc" name="name" href="#"><span class="sort-title">App Name</span></a></span></th>
|
| 87 |
+
<th><span class="nobr"><a class="not-sort" title="asc" name="code" href="#"><span class="sort-title">App Code</span></a></span></th>
|
| 88 |
+
<th><span class="nobr"><a class="not-sort" title="asc" name="type" href="#"><span class="sort-title">Device</span></a></span></th>
|
| 89 |
+
<th class=" last"><span class="nobr"><a class="not-sort" title="asc" name="status" href="#"><span class="sort-title">Status</span></a></span></th>
|
| 90 |
+
</tr>
|
| 91 |
+
<tr class="filter">
|
| 92 |
+
<th><div class="field-100"><input type="text" class="input-text no-changes" value="" id="filter_name" name="name"></div></th>
|
| 93 |
+
<th><div class="field-100"><input type="text" class="input-text no-changes" value="" id="filter_code" name="code"></div></th>
|
| 94 |
+
<th><select class="no-changes" id="filter_type" name="type"><option value=""></option><option value="ipad">iPad</option><option value="iphone">iPhone</option><option value="android">Android</option></select></th>
|
| 95 |
+
<th class=" last"><select class="no-changes" id="filter_status" name="status"><option value=""></option><option value="1">Submitted</option><option value="0">Not Submitted</option></select></th>
|
| 96 |
+
</tr>
|
| 97 |
+
</thead>
|
| 98 |
+
|
| 99 |
+
<tbody id="">
|
| 100 |
+
<tr class="even">
|
| 101 |
+
<td colspan="4" class="empty-text a-center">No records found.</td>
|
| 102 |
+
</tr>
|
| 103 |
+
</tbody>
|
| 104 |
+
|
| 105 |
+
</table>
|
| 106 |
+
</div>
|
| 107 |
+
</div>
|
| 108 |
+
</div>
|
| 109 |
+
<script type="text/javascript">
|
| 110 |
+
//<![CDATA[
|
| 111 |
+
mobile_apps_gridJsObject = new varienGrid('mobile_apps_grid', 'http://magento.local/index.php/admin/mobile/index/key/966a6d38122a600c6981a377d23f2872/', 'page', 'sort', 'dir', 'filter');
|
| 112 |
+
mobile_apps_gridJsObject.useAjax = '';
|
| 113 |
+
mobile_apps_gridJsObject.rowClickCallback = openGridRow;
|
| 114 |
+
//]]>
|
| 115 |
+
</script>
|
| 116 |
+
</div>
|
| 117 |
+
</div>
|
app/design/adminhtml/default/default/template/mailplus/help.phtml
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
$locale = Mage::app()->getLocale()->getLocaleCode();
|
| 18 |
+
|
| 19 |
+
// @var $resource Mage_Core_Model_Resource*/
|
| 20 |
+
$prefix = (string) Mage::app()->getConfig()->getResourceConfig('db')->table_prefix;
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
$readDb = Mage::getSingleton('core/resource')->getConnection('core_write');
|
| 24 |
+
/* @var $readDb Varien_Db_Adapter_Pdo_Mysql */
|
| 25 |
+
$resource = $readDb->fetchRow("SELECT * FROM {$prefix}core_resource WHERE `code` LIKE {$readDb->quote('mailplus_setup')}", array(), Zend_Db::FETCH_OBJ );
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
switch ( $locale )
|
| 29 |
+
{
|
| 30 |
+
case 'nl_NL':
|
| 31 |
+
?>
|
| 32 |
+
|
| 33 |
+
<h1>MailPlus - Help</h1>
|
| 34 |
+
<p>
|
| 35 |
+
U bevind zich op de hulp pagina voor de koppeling van <a href="http://www.mailplus.nl/" target="_blank">MailPlus</a> en Magento.<br />
|
| 36 |
+
U gebruikt versie <?php echo Mage::getConfig()->getModuleConfig('Techtwo_Mailplus')->version . Mage::getConfig()->getModuleConfig('Techtwo_Mailplus')->subv; ?>.
|
| 37 |
+
<?php if ( $resource ) : ?>
|
| 38 |
+
U heeft deze module geinstalleerd met de versie: <?php echo $resource->version; ?> en uw data versie is <?php echo $resource->data_version; ?>
|
| 39 |
+
<?php else: ?>
|
| 40 |
+
Deze module is niet correct geinstalleerd.
|
| 41 |
+
<?php endif; ?>
|
| 42 |
+
</p>
|
| 43 |
+
|
| 44 |
+
<?php
|
| 45 |
+
break;
|
| 46 |
+
|
| 47 |
+
default:
|
| 48 |
+
?>
|
| 49 |
+
|
| 50 |
+
<h1>MailPlus - Help</h1>
|
| 51 |
+
<p>
|
| 52 |
+
You are now viewing the help page for <a href="http://www.mailplus.nl/" target="_blank">MailPlus</a> Magento Connection<br />
|
| 53 |
+
The version of this module is <?php echo Mage::getConfig()->getModuleConfig('Techtwo_Mailplus')->version . Mage::getConfig()->getModuleConfig('Techtwo_Mailplus')->subv;; ?>
|
| 54 |
+
<?php if ( $resource ) : ?>
|
| 55 |
+
The version module installed is: : <?php echo $resource->version; ?> and your data version is <?php echo $resource->data_version; ?>.
|
| 56 |
+
<?php else: ?>
|
| 57 |
+
You have not installed this module correctly.
|
| 58 |
+
<?php endif; ?>
|
| 59 |
+
</p>
|
| 60 |
+
|
| 61 |
+
<?php
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
?>
|
app/design/adminhtml/default/default/template/mailplus/notifications.phtml
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
// --- Utilize the cache whenever available ---
|
| 18 |
+
$cache = Mage::getSingleton('core/cache');
|
| 19 |
+
/* @var $cache Mage_Core_Model_Cache */
|
| 20 |
+
|
| 21 |
+
$bounce_errors = $cache->load('mailplus.notifications.bounce_errors');
|
| 22 |
+
if ( false === $bounce_errors )
|
| 23 |
+
{
|
| 24 |
+
$readDb = Mage::getSingleton('core/resource')->getConnection('core_read');
|
| 25 |
+
/* @var $readDb Zend_Db_Adapter_Abstract */
|
| 26 |
+
|
| 27 |
+
$bounce = Mage::getModel('mailplus/bounce');
|
| 28 |
+
$bounce_errors = $readDb->fetchOne($sql = '
|
| 29 |
+
SELECT COUNT('. $readDb->quoteIdentifier($bounce->getResource()->getIdFieldName()) .')
|
| 30 |
+
FROM ' . $readDb->quoteIdentifier( $bounce->getResource()->getMainTable() ).'
|
| 31 |
+
WHERE '. $readDb->quoteIdentifier('last_bounce_date') .' > '.$readDb->quote(date('Y-m-d H:i:s', strtotime('-2 weeks'))).' ;'
|
| 32 |
+
);
|
| 33 |
+
|
| 34 |
+
if ( false !== $bounce_errors )
|
| 35 |
+
$bounce_errors = (int) $bounce_errors;
|
| 36 |
+
|
| 37 |
+
$cache->save($bounce_errors, 'mailplus.notifications.bounce_errors', /*$tags*/array(), /*$lifeTime*/10);
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
////////////////////////////////////////////////
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
if ( !$bounce_errors )
|
| 44 |
+
return;
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
?>
|
| 49 |
+
|
| 50 |
+
<?php if ( $bounce_errors ) : ?>
|
| 51 |
+
<div class="notification-global">
|
| 52 |
+
<strong class="label"><?php echo Mage::helper('mailplus')->__('MailPlus Bounce reports') ?></strong>
|
| 53 |
+
<?php echo Mage::helper('mailplus')->__('Found %u <a href="%s">MailPlus bounces</a> in the last 2 weeks', $bounce_errors, $this->getUrl('mailplus/adminhtml_bounces/') );?>
|
| 54 |
+
</div>
|
| 55 |
+
<?php endif; ?>
|
app/design/adminhtml/default/default/template/mailplus/status.phtml
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
|
| 18 |
+
$website = Mage::app()->getFrontController()->getRequest()->getParam('website');
|
| 19 |
+
if (!$website) {
|
| 20 |
+
$sites = Mage::app()->getWebsites();
|
| 21 |
+
$website = reset($sites);
|
| 22 |
+
} else {
|
| 23 |
+
$website = Mage::app()->getWebsite($website);
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
/* @var $rest Techtwo_Mailplus_Helper_Rest */
|
| 27 |
+
$rest = Mage::helper('mailplus/rest');
|
| 28 |
+
$mailplus = Mage::helper('mailplus');
|
| 29 |
+
|
| 30 |
+
$hasMailPlusConnection = false;
|
| 31 |
+
|
| 32 |
+
$hasMailPlusConnection = (FALSE !== $rest->clearContactPropertiesCache($website->getId())->getContactProperties($website->getId()) );
|
| 33 |
+
?>
|
| 34 |
+
<script type="text/javascript">
|
| 35 |
+
function mailplus_start_synchronize() {
|
| 36 |
+
document.location.href='<?php echo Mage::helper('adminhtml')->getUrl('mailplus/adminhtml_status/synchronize') . 'website/' . $website->getCode(); ?>';
|
| 37 |
+
}
|
| 38 |
+
</script>
|
| 39 |
+
<div class="content-header">
|
| 40 |
+
<table cellspacing="0">
|
| 41 |
+
<tbody><tr>
|
| 42 |
+
<td style="width:50%;">
|
| 43 |
+
<h3 class="icon-head head-adminhtml-users">
|
| 44 |
+
<?php echo $mailplus->__('Connector state') ?>
|
| 45 |
+
(<?php echo $mailplus->__('version') ?>
|
| 46 |
+
<?php echo Mage::getConfig()->getModuleConfig("Techtwo_Mailplus")->version .
|
| 47 |
+
Mage::getConfig()->getModuleConfig("Techtwo_Mailplus")->subv;
|
| 48 |
+
?>)
|
| 49 |
+
<?php echo $mailplus->__('for website') . " "" . $website->getName() . """?></h3>
|
| 50 |
+
</td>
|
| 51 |
+
<td class="form-buttons">
|
| 52 |
+
<button style="" onclick="mailplus_start_synchronize();" class="scalable add" type="button"><span>Volledig synchroniseren</span></button>
|
| 53 |
+
</td>
|
| 54 |
+
</tr>
|
| 55 |
+
</tbody>
|
| 56 |
+
</table>
|
| 57 |
+
</div>
|
| 58 |
+
<div class="content-body">
|
| 59 |
+
<ul class="messages">
|
| 60 |
+
<?php if ( $hasMailPlusConnection ) { ?>
|
| 61 |
+
<li class="success-msg">
|
| 62 |
+
<ul>
|
| 63 |
+
<li>
|
| 64 |
+
<span>The connection between Magento and MailPlus is OK</span>
|
| 65 |
+
</li>
|
| 66 |
+
</ul>
|
| 67 |
+
</li>
|
| 68 |
+
<?php
|
| 69 |
+
} else {
|
| 70 |
+
?>
|
| 71 |
+
<li class="error-msg">
|
| 72 |
+
<ul>
|
| 73 |
+
<li>
|
| 74 |
+
<strong>The connection between Magento and Mailplus <u>is not OK</u></strong><br />
|
| 75 |
+
<span>If the connection is not OK in the next hour, please contact the MailPlus helpdesk.</span>
|
| 76 |
+
</li>
|
| 77 |
+
</ul>
|
| 78 |
+
</li>
|
| 79 |
+
<?php }
|
| 80 |
+
$queueCount = $mailplus->getRestqueueCount();
|
| 81 |
+
if ($queueCount) {
|
| 82 |
+
?>
|
| 83 |
+
<li class="error-msg">
|
| 84 |
+
<ul>
|
| 85 |
+
<li>
|
| 86 |
+
<p>
|
| 87 |
+
<?php echo $this->__( 'There are still %u MailPlus API calls queued', $queueCount); ?>
|
| 88 |
+
</p>
|
| 89 |
+
<p>
|
| 90 |
+
<?php echo $this->__( 'If this queue cannot be emptied, the connection between Magento and MailPlus is not OK.'); ?>
|
| 91 |
+
</p>
|
| 92 |
+
</li>
|
| 93 |
+
</ul>
|
| 94 |
+
</li>
|
| 95 |
+
<?php
|
| 96 |
+
}
|
| 97 |
+
?>
|
| 98 |
+
</ul>
|
| 99 |
+
</div>
|
| 100 |
+
|
app/design/adminhtml/default/default/template/mailplus/users/grid.phtml
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
// Finds the base Mage_Adminhtml_Block_Widget_Grid
|
| 3 |
+
// For maximum upgradability.. does not overwrite the grid table.
|
| 4 |
+
|
| 5 |
+
$file = Mage::getDesign()->getTemplateFilename('widget/grid.phtml');
|
| 6 |
+
$helper = Mage::helper('mailplus');
|
| 7 |
+
/* @var $helper Techtwo_Model_Helper_Data */
|
| 8 |
+
?>
|
| 9 |
+
|
| 10 |
+
<div id="last_synchronized" style="margin: -1em 0 2em 0"><b><?php echo $helper->__('Last synchronized')?></b>:
|
| 11 |
+
|
| 12 |
+
<?php
|
| 13 |
+
$last_cron_file = Mage::getBaseDir('var').DS.'mailplus-last-cron.php';
|
| 14 |
+
$time = file_exists($last_cron_file)? include $last_cron_file:0;
|
| 15 |
+
if ( !$time )
|
| 16 |
+
{
|
| 17 |
+
echo 'never';
|
| 18 |
+
}
|
| 19 |
+
else
|
| 20 |
+
{
|
| 21 |
+
$diff = time() - $time;
|
| 22 |
+
if ( $diff > 86400 )
|
| 23 |
+
{
|
| 24 |
+
echo date('j F Y, H:i', $time);
|
| 25 |
+
}
|
| 26 |
+
else
|
| 27 |
+
{
|
| 28 |
+
$diff_r = 0;
|
| 29 |
+
|
| 30 |
+
if ($diff > 3600 )
|
| 31 |
+
{
|
| 32 |
+
$diff_r = floor($diff / 3600);
|
| 33 |
+
echo $diff_r.' '.$helper->__('hours');
|
| 34 |
+
$diff -= $diff_r * 3600;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
if ( $diff > 60 )
|
| 38 |
+
{
|
| 39 |
+
if ( $diff_r )
|
| 40 |
+
echo ' '.$helper->__('and').' ';
|
| 41 |
+
$diff_r = floor($diff / 60);
|
| 42 |
+
echo $diff_r.' '.$helper->__('minutes');
|
| 43 |
+
$diff -= $diff_r * 60;
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
if ( $diff )
|
| 47 |
+
{
|
| 48 |
+
if ( $diff_r )
|
| 49 |
+
echo ' '.$helper->__('and').' ';
|
| 50 |
+
echo $diff.' '.$helper->__('seconds');
|
| 51 |
+
}
|
| 52 |
+
echo ' '.$helper->__('ago');
|
| 53 |
+
}
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
?>
|
| 58 |
+
</div>
|
| 59 |
+
|
| 60 |
+
<?php if ( $file ) require $file; ?>
|
app/design/adminhtml/default/default/template/mailplus/users/import.phtml
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php Mage::app()->getLayout()->getMessagesBlock()->getGroupedHtml(); ?>
|
| 2 |
+
<h1><?php echo Mage::helper('mailplus')->__('Import users') ?></h1>
|
| 3 |
+
<form enctype="multipart/form-data" action="<?php echo $this->getUrl('*/*/import')?>" method="post" />
|
| 4 |
+
<input type="hidden" name="form_key" value="<?php echo $this->getFormKey(); ?>" />
|
| 5 |
+
|
| 6 |
+
<?php echo Mage::helper('mailplus')->__('Website') ?>
|
| 7 |
+
<select name="website_id">
|
| 8 |
+
<?php
|
| 9 |
+
$websites = Mage::app()->getWebsites();
|
| 10 |
+
foreach ( $websites as $website )
|
| 11 |
+
echo '<option value="'.$website->getId().'">'.$website->getName().'</option>';
|
| 12 |
+
?>
|
| 13 |
+
</select><br />
|
| 14 |
+
|
| 15 |
+
<em><?php echo Mage::helper('mailplus')->__('Import csv file') ?></em>
|
| 16 |
+
<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $this->getMaxImportFilesize() ?>" />
|
| 17 |
+
<input type="file" name="ufile" /><br />
|
| 18 |
+
<br />
|
| 19 |
+
<input type="submit" class="form-button" value="<?php echo Mage::helper('mailplus')->__('Import')?>" />
|
| 20 |
+
</form>
|
| 21 |
+
|
| 22 |
+
<?php
|
| 23 |
+
|
| 24 |
+
//$websites = Mage::app()->getWebsites();
|
| 25 |
+
//print_r(reset($websites)->toArray());
|
| 26 |
+
|
| 27 |
+
?>
|
app/design/adminhtml/default/default/template/mailplus/website_switcher.phtml
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
|
| 18 |
+
$websites=Mage::app()->getWebsites();
|
| 19 |
+
$baseUrl = $this->getUrl('*/*/*', array('_current' => true, $this->_storeVarName => null, 'website'=> null));
|
| 20 |
+
$current_website_code = Mage::app()->getFrontController()->getRequest()->getParam('website');
|
| 21 |
+
?>
|
| 22 |
+
<p class="switcher">
|
| 23 |
+
<label for="website_switcher"><?php echo $this->__('Select website') ?>:</label>
|
| 24 |
+
<select id="website_switcher" onchange="location.href=this.value">
|
| 25 |
+
<?php foreach ($websites as $website): ?>
|
| 26 |
+
<?php $_selected = $website->getCode() == $current_website_code? ' selected="selected"' : '' ?>
|
| 27 |
+
<option value="<?php echo $baseUrl . 'website/' . $website->getCode(); ?>"<?php echo $_selected ?>><?php echo $this->htmlEscape($website->getName()) ?></option>
|
| 28 |
+
<?php endforeach; ?>
|
| 29 |
+
</select>
|
| 30 |
+
</p>
|
app/design/frontend/base/default/layout/mailplus.xml
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
|
| 3 |
+
<layout version="0.1.0">
|
| 4 |
+
</layout>
|
lib/MailPlus/Oauth/Client.php
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
|
| 18 |
+
/**
|
| 19 |
+
* Fixes http://framework.zend.com/issues/browse/ZF-9840
|
| 20 |
+
* Issue: Zend_Rest_Client::restPost forces Content-Type to be 'application/x-www-form-urlencoded'
|
| 21 |
+
*/
|
| 22 |
+
class MailPlus_Oauth_Client extends Zend_Oauth_Client
|
| 23 |
+
{
|
| 24 |
+
|
| 25 |
+
protected $_keepContentType = false;
|
| 26 |
+
public function setKeepContentType( $keep=true )
|
| 27 |
+
{
|
| 28 |
+
$this->_keepContentType = (bool) $keep;
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
/**
|
| 32 |
+
* Clear all GET and POST parameters
|
| 33 |
+
*
|
| 34 |
+
* Should be used to reset the request parameters if the client is
|
| 35 |
+
* used for several concurrent requests.
|
| 36 |
+
*
|
| 37 |
+
* clearAll parameter controls if we clean just parameters or also
|
| 38 |
+
* headers and last_*
|
| 39 |
+
*
|
| 40 |
+
* @param bool $clearAll Should all data be cleared?
|
| 41 |
+
* @return Zend_Http_Client
|
| 42 |
+
*/
|
| 43 |
+
public function resetParameters($clearAll = false)
|
| 44 |
+
{
|
| 45 |
+
// Reset parameter data
|
| 46 |
+
$this->paramsGet = array();
|
| 47 |
+
$this->paramsPost = array();
|
| 48 |
+
$this->files = array();
|
| 49 |
+
$this->raw_post_data = null;
|
| 50 |
+
|
| 51 |
+
if($clearAll) {
|
| 52 |
+
$this->headers = array();
|
| 53 |
+
$this->last_request = null;
|
| 54 |
+
$this->last_response = null;
|
| 55 |
+
} else {
|
| 56 |
+
// Clear outdated headers
|
| 57 |
+
if (false === $this->_keepContentType && isset($this->headers[strtolower(self::CONTENT_TYPE)])) {
|
| 58 |
+
unset($this->headers[strtolower(self::CONTENT_TYPE)]);
|
| 59 |
+
}
|
| 60 |
+
if (isset($this->headers[strtolower(self::CONTENT_LENGTH)])) {
|
| 61 |
+
unset($this->headers[strtolower(self::CONTENT_LENGTH)]);
|
| 62 |
+
}
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
return $this;
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
}
|
lib/MailPlus/Oauth/Token/Access.php
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2014 MailPlus
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
| 6 |
+
* use this file except in compliance with the License. You may obtain a copy
|
| 7 |
+
* of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 13 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 14 |
+
* License for the specific language governing permissions and limitations
|
| 15 |
+
* under the License.
|
| 16 |
+
*/
|
| 17 |
+
|
| 18 |
+
/**
|
| 19 |
+
* MailPlus customization:
|
| 20 |
+
* - Use the Zend_Oauth_Client in getHttpClient
|
| 21 |
+
*/
|
| 22 |
+
class MailPlus_Oauth_Token_Access extends Zend_Oauth_Token_Access
|
| 23 |
+
{
|
| 24 |
+
/**
|
| 25 |
+
* Get OAuth client
|
| 26 |
+
*
|
| 27 |
+
* Use the Zend_Oauth_Client in getHttpClient
|
| 28 |
+
*
|
| 29 |
+
* @param array $oauthOptions
|
| 30 |
+
* @param null|string $uri
|
| 31 |
+
* @param null|array|Zend_Config $config
|
| 32 |
+
* @param bool $excludeCustomParamsFromHeader
|
| 33 |
+
* @return Mailplus_Oauth_Client
|
| 34 |
+
*/
|
| 35 |
+
public function getHttpClient(array $oauthOptions, $uri = NULL, $config = NULL, $excludeCustomParamsFromHeader = TRUE)
|
| 36 |
+
{
|
| 37 |
+
$client = new MailPlus_Oauth_Client($oauthOptions, $uri, $config, $excludeCustomParamsFromHeader);
|
| 38 |
+
$client->setToken($this);
|
| 39 |
+
return $client;
|
| 40 |
+
}
|
| 41 |
+
}
|
package.xml
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<package>
|
| 3 |
+
<name>Techtwo_Mailplus</name>
|
| 4 |
+
<version>2.1.0.0</version>
|
| 5 |
+
<stability>stable</stability>
|
| 6 |
+
<license uri="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</license>
|
| 7 |
+
<channel>community</channel>
|
| 8 |
+
<extends/>
|
| 9 |
+
<summary>MailPlus Connector for Magento</summary>
|
| 10 |
+
<description>Synchronizes contact, product and order information between Magento and MailPlus eCom and triggers campaigns.</description>
|
| 11 |
+
<notes>Release v2.1.0.1</notes>
|
| 12 |
+
<authors><author><name>Paul Bosselaar</name><user>PaulBos</user><email>paul@mailplus.nl</email></author></authors>
|
| 13 |
+
<date>2014-01-17</date>
|
| 14 |
+
<time>10:32:26</time>
|
| 15 |
+
<contents><target name="magecommunity"><dir name="Techtwo"><dir name="Mailplus"><dir name="Block"><dir name="Adminhtml"><dir name="Bounces"><file name="Grid.php" hash="f8a718505b7ddc76b7c41cabd725385a"/></dir><file name="Bounces.php" hash="9e948d87a42affafe387ae22b76b0329"/><dir name="Mapping"><dir name="Edit"><file name="Form.php" hash="d1c2810efc8e47c57524e3e80e2b41c1"/></dir></dir><file name="Mapping.php" hash="5263da49b84234e9f25063c1fe6109be"/><dir name="Restqueue"><file name="Grid.php" hash="4aa89c69ed281f91d8c13528d79f6702"/></dir><file name="Restqueue.php" hash="9eb67a7691b733fdff5a28cb8c148aa3"/><dir name="Syncstatus"><file name="Grid.php" hash="e12d16fcfbd0b5415af2005c1769abdd"/></dir><file name="Syncstatus.php" hash="f1286b0f99f427678280d0faf7aa0459"/><dir name="Users"><dir name="Edit"><file name="Form.php" hash="dd8a34b1ef517fa6cfd86df923883874"/><dir name="Tab"><file name="Form.php" hash="6902ea8145aaf3de04aa0ae3a5a749b6"/></dir><file name="Tabs.php" hash="649f4504ef6b1b677e0af718b4fb1bf2"/></dir><file name="Edit.php" hash="d49c6d3e6d841101177063353c38c520"/><file name="Grid.php" hash="e5606c984441b99a89b66473ea9b1635"/></dir><file name="Users.php" hash="c28da0f1b0a7d7924bd0779e2c8c4072"/></dir></dir><dir name="Client"><dir name="Contact"><file name="Permission.php" hash="c7cb785041a3685eed8b5dec3573f773"/><file name="Property.php" hash="637bdb0ef575e0f2cb1ee6c2e48e0566"/></dir><file name="Error.php" hash="d6104ae10196b5e7941dfc866236b015"/><file name="Exception.php" hash="7c8fd063c8f6e4e42db2ba2003db5538"/><file name="Rest.php" hash="9ac7ebb23b1dd6f3521df89677d722d9"/></dir><dir name="Helper"><file name="Config.php" hash="5267bdaaf7c605d604327dc59bbf7b8c"/><file name="Cron.php" hash="7790b6e1d0b740228e273cabb2892324"/><file name="Data.php" hash="80690fe1484d3f5fc242d0c8774aea74"/><file name="Feed.php" hash="ae866adfed51d488fed615fd828257fe"/><file name="Rest.php" hash="b0bc0e865a2fed4b2a6168682ad8d941"/></dir><dir name="Model"><dir name="Abandoned"><file name="Campaign.php" hash="745bc978a8cf2ea88c0e31d59823de8b"/></dir><file name="Bounce.php" hash="a2ab980e67ca1783180265b54ee0ea74"/><dir name="Cron"><file name="Hourly.php" hash="8366c9858757f1d32f45527a23bad6b8"/><file name="Often.php" hash="f17145e6f9ce059a8ec03d369202c3c8"/></dir><file name="Info.php" hash="4aade98df5fc5fba93831c4c367ce14b"/><file name="Mailing.php" hash="ad152a095677a8559b5ca3a4f35408fc"/><dir name="Mysql4"><dir name="Abandoned"><dir name="Campaign"><file name="Collection.php" hash="4fe912177ce6c734f2f5bda923a8149a"/></dir><file name="Campaign.php" hash="7cceca83ac44242374318041bf29216b"/></dir><dir name="Bounce"><file name="Collection.php" hash="4660a53fff332a3d6cc9707a82f6e936"/></dir><file name="Bounce.php" hash="471b5432251ad6d311d4b42c233493aa"/><dir name="Info"><file name="Collection.php" hash="1c1c60197096c4c197ab9532f877d564"/></dir><file name="Info.php" hash="9179c5665d912ae7bb88ee96b7742346"/><dir name="Product"><file name="Collection.php" hash="a68a8da87fea9c4295511e2116d72e81"/></dir><file name="Product.php" hash="f63464aa767938d52e15e068c683e7ce"/><dir name="Restqueue"><file name="Collection.php" hash="b6c8a6c80915ca8fb48d5ece6fdec059"/></dir><file name="Restqueue.php" hash="80da968d9d75e780cbcc3c32a53e39d2"/><dir name="Syncqueue"><file name="Collection.php" hash="1f7ebe9212d2f38c02751644f82f3df7"/></dir><file name="Syncqueue.php" hash="4661379f990d0e2c026c2fc1c3c6e2d7"/><dir name="User"><file name="Collection.php" hash="67d7babb94883c223f850b56f1486bf7"/></dir><file name="User.php" hash="5cd0ab76b7f25bbcb23ecad412b75648"/></dir><dir name="Newsletter"><file name="Subscriber.php" hash="98275f4d9a38491a5eab1bb217b067cc"/></dir><file name="Product.php" hash="8d3cb4f534c157bb12f71ee78cc8afe5"/><file name="Restqueue.php" hash="0a33c0caea964ed076ee003c08677974"/><file name="Syncqueue.php" hash="4a3864eb463f290bc0a329b7692293ea"/><dir name="System"><file name="Campaign.php" hash="69b0b838a7644e1d59ba3bc601ec172a"/><dir name="Config"><dir name="Source"><file name="Campaign.php" hash="e8f5324473a3aa56e111204cba6a08bf"/><file name="Keepframe.php" hash="f538cca9d9e8bf3d6d852c02b023096f"/><dir name="Product"><file name="Specs.php" hash="ddde4111fb3c4e015e4ad54f4ddb3150"/></dir><file name="Synchronize.php" hash="74ffa47771b8d58cd3610ee37bcdcc22"/><dir name="Yesno"><dir name="Default"><file name="No.php" hash="15fdcf3048bf48b65e07096dae603238"/><file name="Yes.php" hash="44449a8b1ca6967c171bdd9b5119f6dd"/></dir></dir></dir></dir></dir><file name="User.php" hash="06c6640185c7ceed5954a3763b86346c"/></dir><dir name="Observer"><file name="Config.php" hash="040600ac7accc712e1243fe4f4c097c8"/><file name="Customer.php" hash="74662ba2777bf23425eb88dacd4fd79d"/><file name="Product.php" hash="cfc5b5f7bc7c9293c8963d4155ca6437"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="BouncesController.php" hash="8735f990874d66f40aaf8dbc7f8b95ab"/><file name="FeedController.php" hash="f98e072358410bb7ca0f23ef1531d9b9"/><file name="FeedsController.php" hash="ec29193a39d76d04020a1b8ad65f4e19"/><file name="HelpController.php" hash="9d391566874f5a2e9cd4fe1a8488af08"/><file name="MailingsController.php" hash="e025450c4e57aa8eeb71dc9b3c31a556"/><file name="MappingController.php" hash="ad7890191c2e2d7b4304e55630b3feda"/><file name="RestqueueController.php" hash="eb502c9ae148c629ed98b272f828186f"/><file name="StatusController.php" hash="2517245af96efffd357fa7842ae630ae"/><file name="SyncstatusController.php" hash="637fa60c8d35e09c307feb61af22a923"/><file name="UsersController.php" hash="a95069af4c2f186fd68f97dcdc3680e8"/></dir><file name="CustomerController.php" hash="c968354013c4d746609ede5224b18949"/><file name="ImageController.php" hash="3c8343c14e6d38caf4db6d095ede6922"/><dir name="Mailplus"><file name="Entry.php" hash="9c5703bcdf2b27b4403f35946e9308e3"/><dir name="Renderer"><file name="Entry.php" hash="21549a8d17704314b99918ddd9e66904"/></dir></dir><file name="UseController.php" hash="c45954c725de56304a0a0ab3fb923698"/></dir><dir name="etc"><file name="config.xml" hash="12a381f270aced70f07b7e38c453b402"/><file name="system.xml" hash="706808af2c74c1666563c1aefb841fca"/></dir><dir name="sql"><dir name="mailplus_setup"><file name="mysql4-install-2.1.0.php" hash="f17cd9e7bcdc86d7666dd6e0b44d9d8e"/><file name="mysql4-upgrade-0.1.1-0.2.1.php" hash="d0f17ed7531e43ed541be989c30b9d57"/><file name="mysql4-upgrade-0.2.1-0.3.1.php" hash="d0f17ed7531e43ed541be989c30b9d57"/><file name="mysql4-upgrade-0.3.1-0.3.2.php" hash="567018f30306b80e8f912f346b0b5d3d"/><file name="mysql4-upgrade-0.3.2-0.3.3.php" hash="e8cc865c196516155304418ff871d6fe"/><file name="mysql4-upgrade-0.3.3-1.0.0.php" hash="9d47cbd0f0a6052973e29f1b1dc55775"/><file name="mysql4-upgrade-1.0.0-2.0.0.php" hash="e677470234bd75a9f11aa01cb71777c2"/><file name="mysql4-upgrade-2.0.0-2.1.0.php" hash="b865191bd73dd5633d04636435f9a793"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="mailplus.xml" hash="1b0dd29f2dbc1f0a9b614f26694a825c"/></dir><dir name="template"><dir name="mailplus"><file name="bounces.phtml" hash="c98b3f2e7e44b52c7d54d68b02d0bd05"/><file name="cronstatus.phtml" hash="5a5e75a1d8d0ac3701211f1e3e8d2d66"/><file name="edit.phtml" hash="872f074814af467ae4ed5b9b2f853557"/><file name="help.phtml" hash="8e83222357b6b64dea99633a5cfcf2a0"/><file name="notifications.phtml" hash="b3107cc2ad722d6e04e3bfa6e6f23ce0"/><file name="status.phtml" hash="6c66bf6273905682ada59683205993db"/><dir name="users"><file name="grid.phtml" hash="59be26393c7ba9f3d2fec90c4fe172f6"/><file name="import.phtml" hash="95e7f2ae0a5ae8159be57bdf22b1b7cb"/></dir><file name="website_switcher.phtml" hash="b17e3fab749ff638e181a19f8c6fa087"/></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="mailplus.xml" hash="d484d7a3878a276c47697f62f33597c6"/></dir></dir></dir></dir></target><target name="magelocale"><dir name="nl_NL"><file name="Techwto_Mailplus.csv" hash=""/></dir></target><target name="mageetc"><dir name="."><file name="Techtwo_Mailplus.xml" hash=""/></dir></target><target name="magelib"><dir name="MailPlus"><dir name="Oauth"><file name="Client.php" hash="3f09bcf9bdcef2698b172af3e63b2c24"/><dir name="Token"><file name="Access.php" hash="5ea167ab32e05cbc95a6e1a4dc30fe06"/></dir></dir></dir></target></contents>
|
| 16 |
+
<compatible/>
|
| 17 |
+
<dependencies><required><php><min>5.1.0</min><max>5.5.7</max></php><package><name>Mage_Newsletter</name><channel>core</channel><min>1.5.0</min><max>1.8.1</max></package></required></dependencies>
|
| 18 |
+
</package>
|
