Remarkety_Mgconnector - Version 1.4.3.0

Version Notes

No comments

Download this release

Release Info

Developer Remarkety
Extension Remarkety_Mgconnector
Version 1.4.3.0
Comparing to
See all releases


Version 1.4.3.0

Files changed (69) hide show
  1. CHANGELOG.txt +79 -0
  2. app/code/community/Remarkety/Mgconnector/Block/Adminhtml/Configuration.php +24 -0
  3. app/code/community/Remarkety/Mgconnector/Block/Adminhtml/Configuration/Complete.php +35 -0
  4. app/code/community/Remarkety/Mgconnector/Block/Adminhtml/Configuration/Complete/Form.php +62 -0
  5. app/code/community/Remarkety/Mgconnector/Block/Adminhtml/Configuration/Configuration.php +41 -0
  6. app/code/community/Remarkety/Mgconnector/Block/Adminhtml/Configuration/Configuration/Form.php +64 -0
  7. app/code/community/Remarkety/Mgconnector/Block/Adminhtml/Configuration/Install.php +35 -0
  8. app/code/community/Remarkety/Mgconnector/Block/Adminhtml/Configuration/Install/Form.php +90 -0
  9. app/code/community/Remarkety/Mgconnector/Block/Adminhtml/Configuration/Upgrade.php +35 -0
  10. app/code/community/Remarkety/Mgconnector/Block/Adminhtml/Configuration/Upgrade/Form.php +71 -0
  11. app/code/community/Remarkety/Mgconnector/Block/Adminhtml/Install/Complete.php +37 -0
  12. app/code/community/Remarkety/Mgconnector/Block/Adminhtml/Install/Complete/Form.php +63 -0
  13. app/code/community/Remarkety/Mgconnector/Block/Adminhtml/Install/Install/Create.php +33 -0
  14. app/code/community/Remarkety/Mgconnector/Block/Adminhtml/Install/Install/Create/Form.php +140 -0
  15. app/code/community/Remarkety/Mgconnector/Block/Adminhtml/Install/Install/Login.php +33 -0
  16. app/code/community/Remarkety/Mgconnector/Block/Adminhtml/Install/Install/Login/Form.php +130 -0
  17. app/code/community/Remarkety/Mgconnector/Block/Adminhtml/Install/Upgrade.php +37 -0
  18. app/code/community/Remarkety/Mgconnector/Block/Adminhtml/Install/Upgrade/Form.php +62 -0
  19. app/code/community/Remarkety/Mgconnector/Block/Adminhtml/Install/Welcome.php +39 -0
  20. app/code/community/Remarkety/Mgconnector/Block/Adminhtml/Install/Welcome/Form.php +56 -0
  21. app/code/community/Remarkety/Mgconnector/Block/Adminhtml/Install/Welcome/Store.php +60 -0
  22. app/code/community/Remarkety/Mgconnector/Block/Adminhtml/Queue.php +24 -0
  23. app/code/community/Remarkety/Mgconnector/Block/Adminhtml/Queue/Configure.php +38 -0
  24. app/code/community/Remarkety/Mgconnector/Block/Adminhtml/Queue/Configure/Form.php +104 -0
  25. app/code/community/Remarkety/Mgconnector/Block/Adminhtml/Queue/Grid.php +116 -0
  26. app/code/community/Remarkety/Mgconnector/Block/Adminhtml/Queue/Grid/Column/Renderer/EventType.php +29 -0
  27. app/code/community/Remarkety/Mgconnector/Block/Adminhtml/Queue/Grid/Column/Renderer/Status.php +25 -0
  28. app/code/community/Remarkety/Mgconnector/Block/Tracking/Base.php +35 -0
  29. app/code/community/Remarkety/Mgconnector/Block/Tracking/General.php +5 -0
  30. app/code/community/Remarkety/Mgconnector/Block/Tracking/Product.php +57 -0
  31. app/code/community/Remarkety/Mgconnector/Helper/Data.php +74 -0
  32. app/code/community/Remarkety/Mgconnector/Helper/Links.php +64 -0
  33. app/code/community/Remarkety/Mgconnector/Helper/Urls.php +46 -0
  34. app/code/community/Remarkety/Mgconnector/Model/Core.php +1399 -0
  35. app/code/community/Remarkety/Mgconnector/Model/Core/Api.php +211 -0
  36. app/code/community/Remarkety/Mgconnector/Model/Install.php +484 -0
  37. app/code/community/Remarkety/Mgconnector/Model/Observer.php +499 -0
  38. app/code/community/Remarkety/Mgconnector/Model/Queue.php +16 -0
  39. app/code/community/Remarkety/Mgconnector/Model/Recovery.php +92 -0
  40. app/code/community/Remarkety/Mgconnector/Model/Request.php +131 -0
  41. app/code/community/Remarkety/Mgconnector/Model/Resource/Coupon.php +77 -0
  42. app/code/community/Remarkety/Mgconnector/Model/Resource/Queue.php +30 -0
  43. app/code/community/Remarkety/Mgconnector/Model/Resource/Queue/Collection.php +30 -0
  44. app/code/community/Remarkety/Mgconnector/Model/Resource/Rule/Collection.php +138 -0
  45. app/code/community/Remarkety/Mgconnector/Model/Resource/Setup.php +13 -0
  46. app/code/community/Remarkety/Mgconnector/Model/Webtracking.php +40 -0
  47. app/code/community/Remarkety/Mgconnector/controllers/Adminhtml/ConfigureController.php +55 -0
  48. app/code/community/Remarkety/Mgconnector/controllers/Adminhtml/InstallController.php +186 -0
  49. app/code/community/Remarkety/Mgconnector/controllers/Adminhtml/MgconnectorController.php +192 -0
  50. app/code/community/Remarkety/Mgconnector/controllers/Adminhtml/QueueController.php +129 -0
  51. app/code/community/Remarkety/Mgconnector/controllers/RecoveryController.php +53 -0
  52. app/code/community/Remarkety/Mgconnector/controllers/WebtrackingController.php +31 -0
  53. app/code/community/Remarkety/Mgconnector/etc/adminhtml.xml +55 -0
  54. app/code/community/Remarkety/Mgconnector/etc/api.xml +68 -0
  55. app/code/community/Remarkety/Mgconnector/etc/config.xml +163 -0
  56. app/code/community/Remarkety/Mgconnector/sql/mgconnector_setup/mysql4-install-1.0.0.13.php +26 -0
  57. app/code/community/Remarkety/Mgconnector/sql/mgconnector_setup/mysql4-upgrade-1.0.0.13-1.0.0.14.php +26 -0
  58. app/code/community/Remarkety/Mgconnector/sql/mgconnector_setup/mysql4-upgrade-1.0.0.14-1.0.0.15.php +13 -0
  59. app/code/community/Remarkety/Mgconnector/sql/mgconnector_setup/mysql4-upgrade-1.0.0.14-1.1.0.0.php +13 -0
  60. app/code/community/Remarkety/Mgconnector/sql/mgconnector_setup/mysql4-upgrade-1.1.0.5-1.1.0.6.php +15 -0
  61. app/code/community/Remarkety/Mgconnector/sql/mgconnector_setup/mysql4-upgrade-1.1.2.8-1.3.0.0.php +21 -0
  62. app/design/adminhtml/default/default/template/mgconnector/element.phtml +26 -0
  63. app/design/adminhtml/default/default/template/mgconnector/install/welcome/store.phtml +70 -0
  64. app/design/adminhtml/default/default/template/mgconnector/widget/form/renderer/fieldset/element.phtml +26 -0
  65. app/design/frontend/base/default/layout/mgconnector.xml +13 -0
  66. app/design/frontend/base/default/template/mgconnector/tracking/general.phtml +23 -0
  67. app/design/frontend/base/default/template/mgconnector/tracking/product_view.phtml +10 -0
  68. app/etc/modules/Remarkety_Mgconnector.xml +12 -0
  69. package.xml +31 -0
CHANGELOG.txt ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 1.4.3.0
2
+ -------
3
+ - Bypass store cache for website tracking
4
+ - Changed menu titles
5
+
6
+ 1.4.2.0
7
+ -------
8
+ - Clear cache after enable/disable website tracking
9
+ - Bugfix: Array declaration error on old PHP versions
10
+
11
+ 1.4.1.0
12
+ -------
13
+ Allow admin to change Remarkety's api key
14
+
15
+ 1.4.0.2
16
+ -------
17
+ Bug fix subscribers view id
18
+
19
+ 1.4.0.1
20
+ -------
21
+ Newsletter subscription saves the email address to the cart
22
+
23
+ 1.4.0.0
24
+ -------
25
+ Enable website tracking from the Remarkety installation menu
26
+
27
+ 1.3.0.1
28
+ -------
29
+ Automatic tagging for newsletter subscribers
30
+
31
+ 1.3.0.0
32
+ -------
33
+ - Add support for per-coupon expiration dates
34
+
35
+ 1.2.0.0
36
+ -------
37
+ - Automatic tagging for newsletter subscribers
38
+ - Add cart recovery link
39
+ - Payment method field added for segmentation
40
+
41
+ 1.1.2.7
42
+ -------
43
+ - Don't sync products which are not visible
44
+ - Deal with no tags collection
45
+ - Fix table prefix issue
46
+
47
+ 1.1.2.6
48
+ -------
49
+ - Backward compatibility for PHP 5.3
50
+
51
+ 1.1.0.10
52
+ --------
53
+ - Support installation of multiple views through the plugin
54
+ - Error logging improvements
55
+
56
+ 1.1.0.9
57
+ -------
58
+ - API can return log for analysis
59
+ - Return more information: Discount prices, stock levels, parent product
60
+ - Performance improvements when fetching products
61
+
62
+ 1.1.0.4
63
+ -------
64
+ - Fix bug in creating a Magento Web Service user, when another WS user already has the same email
65
+
66
+ 1.1.0.3
67
+ -------
68
+ - Fix bug in comparing what's changed in customer observer
69
+
70
+ 1.1.0.1
71
+ -------
72
+ - Resend / delete queue events
73
+
74
+ 1.1.0.0
75
+ -------
76
+ - Implement one-click install for Magento
77
+ - Send customer update events (signup / subscribe / unsubscribe) immediately (push)
78
+ - Fix problem with multiple views
79
+ - Resend / delete queue events
app/code/community/Remarkety/Mgconnector/Block/Adminhtml/Configuration.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Adminhtml configuration block
5
+ *
6
+ * @category Remarkety
7
+ * @package Remarkety_Mgconnector
8
+ * @author Piotr Pierzak <piotrek.pierzak@gmail.com>
9
+ */
10
+ class Remarkety_Mgconnector_Block_Adminhtml_Configuration extends Mage_Adminhtml_Block_Widget_Grid_Container
11
+ {
12
+ /**
13
+ * Prepare block
14
+ */
15
+ public function __construct()
16
+ {
17
+ $this->_blockGroup = 'mgconnector';
18
+ $this->_controller = 'adminhtml_configuration';
19
+ $this->_headerText = Mage::helper('mgconnector')->__('Remarkety Configuration');
20
+ $this->_removeButton('add');
21
+
22
+ parent::__construct();
23
+ }
24
+ }
app/code/community/Remarkety/Mgconnector/Block/Adminhtml/Configuration/Complete.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Adminhtml configuration complete block
5
+ *
6
+ * @category Remarkety
7
+ * @package Remarkety_Mgconnector
8
+ * @author Piotr Pierzak <piotrek.pierzak@gmail.com>
9
+ */
10
+ class Remarkety_Mgconnector_Block_Adminhtml_Configuration_Complete extends Mage_Adminhtml_Block_Widget_Form_Container
11
+ {
12
+ /**
13
+ * Prepare block
14
+ */
15
+ public function __construct()
16
+ {
17
+ parent::__construct();
18
+
19
+ $this->_objectId = 'complete_id';
20
+ $this->_blockGroup = 'mgconnector';
21
+ $this->_controller = 'adminhtml_configuration';
22
+ $this->_mode = 'complete';
23
+
24
+ $ver = Mage::getConfig()->getModuleConfig("Remarkety_Mgconnector")->version;
25
+ $this->_headerText = $this->__('Install Complete (version: %s)', $ver);
26
+
27
+ $this->_removeButton('back');
28
+ $this->_removeButton('reset');
29
+ $this->_addButton('save', array(
30
+ 'label' => Mage::helper('adminhtml')->__('Done'),
31
+ 'onclick' => 'editForm.submit();',
32
+ 'class' => 'save',
33
+ ), 1);
34
+ }
35
+ }
app/code/community/Remarkety/Mgconnector/Block/Adminhtml/Configuration/Complete/Form.php ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Adminhtml configuration complete form block
5
+ *
6
+ * @category Remarkety
7
+ * @package Remarkety_Mgconnector
8
+ * @author Piotr Pierzak <piotrek.pierzak@gmail.com>
9
+ */
10
+ class Remarkety_Mgconnector_Block_Adminhtml_Configuration_Complete_Form extends Mage_Adminhtml_Block_Widget_Form
11
+ {
12
+ /**
13
+ * Prepare form
14
+ *
15
+ * @return Mage_Adminhtml_Block_Widget_Form
16
+ */
17
+ protected function _prepareForm()
18
+ {
19
+ $form = new Varien_Data_Form(array(
20
+ 'id' => 'edit_form',
21
+ 'action' => $this->getUrl('*/*/complete'),
22
+ 'method' => 'post',
23
+ ));
24
+ $form->setFieldContainerIdPrefix('data');
25
+ $form->setUseContainer(true);
26
+ $this->setForm($form);
27
+
28
+ $fieldset = $form->addFieldset(
29
+ 'general',
30
+ array(
31
+ 'legend' => $this->__('Installation Complete')
32
+ )
33
+ );
34
+
35
+ $fieldset->addField('mode', 'hidden', array(
36
+ 'name' => 'data[mode]',
37
+ 'value' => 'complete',
38
+ ));
39
+
40
+ $instruction = $fieldset->addField('instruction', 'note', array(
41
+ 'text' => '',
42
+ 'label' => false,
43
+ 'after_element_html' => '<p style="font-weight:bold;">' . $this->__('Installation complete!') . '</p>'
44
+ ));
45
+ $instruction->getRenderer()->setTemplate('mgconnector/widget/form/renderer/fieldset/element.phtml');
46
+
47
+ $response = unserialize(Mage::getStoreConfig('remarkety/mgconnector/last_response'),true);
48
+ $fieldset->addField('response', 'note', array(
49
+ 'label' => false,
50
+ 'after_element_html' => !empty($response['info']) ? $response['info'] : $this->__('There is no response to display')
51
+ ));
52
+
53
+ $fieldset->addField('button', 'note', array(
54
+ 'label' => false,
55
+ 'name' => 'button',
56
+ 'after_element_html' => '<button type="button" class="save" onclick="editForm.submit();"><span><span>'
57
+ . $this->__('Done') . '</span></span></button>'
58
+ ));
59
+
60
+ return parent::_prepareForm();
61
+ }
62
+ }
app/code/community/Remarkety/Mgconnector/Block/Adminhtml/Configuration/Configuration.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Adminhtml configuration configuration block
5
+ *
6
+ * @category Remarkety
7
+ * @package Remarkety_Mgconnector
8
+ * @author Piotr Pierzak <piotrek.pierzak@gmail.com>
9
+ */
10
+ class Remarkety_Mgconnector_Block_Adminhtml_Configuration_Configuration extends Mage_Adminhtml_Block_Widget_Form_Container
11
+ {
12
+ /**
13
+ * Prepare block
14
+ */
15
+ public function __construct()
16
+ {
17
+ parent::__construct();
18
+
19
+ $this->_objectId = 'configuration_id';
20
+ $this->_blockGroup = 'mgconnector';
21
+ $this->_controller = 'adminhtml_configuration';
22
+ $this->_mode = 'configuration';
23
+
24
+ $ver = Mage::getConfig()->getModuleConfig("Remarkety_Mgconnector")->version;
25
+ $this->_headerText = $this->__('Remarkety configuration (version: %s)', $ver);
26
+
27
+ $this->_removeButton('back');
28
+ $this->_removeButton('reset');
29
+ $this->_addButton('save', array(
30
+ 'label' => Mage::helper('adminhtml')->__('Save'),
31
+ 'onclick' => 'editForm.submit();',
32
+ 'class' => 'save',
33
+ ), 1);
34
+
35
+ $this->_addButton('reinstall', array(
36
+ 'label' => Mage::helper('adminhtml')->__('Reinstall'),
37
+ 'onclick' => "return confirm('Are you sure?') ? window.location = '" . $this->getUrl('*/*/reinstall')."' : false;",
38
+ 'class' => 'delete',
39
+ ), 0);
40
+ }
41
+ }
app/code/community/Remarkety/Mgconnector/Block/Adminhtml/Configuration/Configuration/Form.php ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Adminhtml configuration configuration form block
5
+ *
6
+ * @category Remarkety
7
+ * @package Remarkety_Mgconnector
8
+ * @author Piotr Pierzak <piotrek.pierzak@gmail.com>
9
+ */
10
+ class Remarkety_Mgconnector_Block_Adminhtml_Configuration_Configuration_Form extends Mage_Adminhtml_Block_Widget_Form
11
+ {
12
+ /**
13
+ * Prepare form
14
+ *
15
+ * @return Mage_Adminhtml_Block_Widget_Form
16
+ */
17
+ protected function _prepareForm()
18
+ {
19
+ $form = new Varien_Data_Form(array(
20
+ 'id' => 'edit_form',
21
+ 'action' => $this->getUrl('*/*/configuration'),
22
+ 'method' => 'post',
23
+ ));
24
+ $form->setFieldContainerIdPrefix('data');
25
+ $form->setUseContainer(true);
26
+ $this->setForm($form);
27
+
28
+ $fieldset = $form->addFieldset(
29
+ 'general',
30
+ array(
31
+ 'legend' => $this->__('Remarkety configuration')
32
+ )
33
+ );
34
+
35
+ $fieldset->addField('mode', 'hidden', array(
36
+ 'name' => 'data[mode]',
37
+ 'value' => 'configuration',
38
+ ));
39
+
40
+ $fieldset->addField('intervals', 'text', array(
41
+ 'label' => $this->__('Intervals:'),
42
+ 'name' => 'data[intervals]',
43
+ 'required' => true,
44
+ 'after_element_html' => '<small style="float:left;width:100%;">' . $this->__(
45
+ 'Here you have to type amount of minutes separated by commas.For example "1,3,10" -
46
+ it means that second attempt will be after 1 minute, third after 3 minutes,
47
+ and fourth after 10 minutes.If last attempt will not be successful,
48
+ status will be changed to "failed" and it will not be processed anymore.'
49
+ ) . '</small>',
50
+ 'value' => Mage::getStoreConfig('remarkety/mgconnector/intervals'),
51
+ 'style' => 'float:left',
52
+ ));
53
+
54
+ $button = $fieldset->addField('button', 'note', array(
55
+ 'label' => false,
56
+ 'name' => 'button',
57
+ 'after_element_html' => '<button type="button" class="save" onclick="editForm.submit();"><span><span>'
58
+ . $this->__('Save') . '</span></span></button>',
59
+ ));
60
+ $button->getRenderer()->setTemplate('mgconnector/widget/form/renderer/fieldset/element.phtml');
61
+
62
+ return parent::_prepareForm();
63
+ }
64
+ }
app/code/community/Remarkety/Mgconnector/Block/Adminhtml/Configuration/Install.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Adminhtml configuration install block
5
+ *
6
+ * @category Remarkety
7
+ * @package Remarkety_Mgconnector
8
+ * @author Piotr Pierzak <piotrek.pierzak@gmail.com>
9
+ */
10
+ class Remarkety_Mgconnector_Block_Adminhtml_Configuration_Install extends Mage_Adminhtml_Block_Widget_Form_Container
11
+ {
12
+ /**
13
+ * Prepare block
14
+ */
15
+ public function __construct()
16
+ {
17
+ parent::__construct();
18
+
19
+ $this->_objectId = 'install_id';
20
+ $this->_blockGroup = 'mgconnector';
21
+ $this->_controller = 'adminhtml_configuration';
22
+ $this->_mode = 'install';
23
+
24
+ $ver = Mage::getConfig()->getModuleConfig("Remarkety_Mgconnector")->version;
25
+ $this->_headerText = $this->__('Install Remarkety extension (version: %s)', $ver);
26
+
27
+ $this->_removeButton('back');
28
+ $this->_removeButton('reset');
29
+ $this->_addButton('save', array(
30
+ 'label' => Mage::helper('adminhtml')->__('Complete Installation'),
31
+ 'onclick' => 'editForm.submit();',
32
+ 'class' => 'save',
33
+ ), 1);
34
+ }
35
+ }
app/code/community/Remarkety/Mgconnector/Block/Adminhtml/Configuration/Install/Form.php ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Adminhtml configuration install form block
5
+ *
6
+ * @category Remarkety
7
+ * @package Remarkety_Mgconnector
8
+ * @author Piotr Pierzak <piotrek.pierzak@gmail.com>
9
+ */
10
+ class Remarkety_Mgconnector_Block_Adminhtml_Configuration_Install_Form extends Mage_Adminhtml_Block_Widget_Form
11
+ {
12
+ /**
13
+ * Prepare form
14
+ *
15
+ * @return Mage_Adminhtml_Block_Widget_Form
16
+ */
17
+ protected function _prepareForm()
18
+ {
19
+ $form = new Varien_Data_Form(array(
20
+ 'id' => 'edit_form',
21
+ 'action' => $this->getUrl('*/*/complete'),
22
+ 'method' => 'post',
23
+ ));
24
+ $form->setFieldContainerIdPrefix('data');
25
+ $form->setUseContainer(true);
26
+ $this->setForm($form);
27
+
28
+ $fieldset = $form->addFieldset(
29
+ 'general',
30
+ array(
31
+ 'legend' => $this->__('Install Remarkety extension')
32
+ )
33
+ );
34
+
35
+ $fieldset->addField('mode', 'hidden', array(
36
+ 'name' => 'data[mode]',
37
+ 'value' => 'install',
38
+ ));
39
+
40
+ $instruction = $fieldset->addField('instruction', 'note', array(
41
+ 'text' => '',
42
+ 'label' => false,
43
+ 'after_element_html' =>
44
+ '<p style="font-weight:bold;">' . $this->__('Thank you for installing the Remarkety Magento plugin.
45
+ You are one click away from finishing setting up Remarkety on your store and sending effective, targeted emails!')
46
+ . '<br><br>'
47
+ . $this->__('The plugin will automatically create a Magento WebService API user so that
48
+ Remarkety can synchronize with your store.') . '</p>',
49
+ ));
50
+ $instruction->getRenderer()->setTemplate('mgconnector/widget/form/renderer/fieldset/element.phtml');
51
+
52
+ $fieldset->addField('email', 'text', array(
53
+ 'label' => $this->__('Email address for the Remarkety account:'),
54
+ 'name' => 'data[email]',
55
+ 'required' => true,
56
+ 'class' => 'validate-email',
57
+ 'after_element_html' => '<small style="float:left;width:100%;">' . $this->__(
58
+ 'If you’ve already registered to Remarkety, please use the email you used to open your account.
59
+ If you haven’t, an email will be sent to this address with the login information. You will then be able
60
+ to choose your password.'
61
+ ) . '</small>',
62
+ 'style' => 'float:left',
63
+ ));
64
+
65
+ $fieldset->addField('store_id', 'select', array(
66
+ 'name' => 'data[store_id]',
67
+ 'label' => $this->__('Sync Remarkety with this view:'),
68
+ 'required' => true,
69
+ 'values' => Mage::getSingleton('adminhtml/system_store')->getStoreValuesForForm(false, false),
70
+ ));
71
+
72
+ $fieldset->addField('terms', 'checkbox', array(
73
+ 'label' => false,
74
+ 'name' => 'data[terms]',
75
+ 'checked' => false,
76
+ 'value' => '1',
77
+ 'class' => 'required-entry',
78
+ 'after_element_html' => $this->__('I agree to Remarkety’s <a href="%s">terms of use</a>.', '#'),
79
+ ));
80
+
81
+ $fieldset->addField('button', 'note', array(
82
+ 'label' => false,
83
+ 'name' => 'button',
84
+ 'after_element_html' => '<button type="button" class="save" onclick="editForm.submit();"><span><span>'
85
+ . $this->__('Complete Installation') . '</span></span></button>'
86
+ ));
87
+
88
+ return parent::_prepareForm();
89
+ }
90
+ }
app/code/community/Remarkety/Mgconnector/Block/Adminhtml/Configuration/Upgrade.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Adminhtml configuration upgrade block
5
+ *
6
+ * @category Remarkety
7
+ * @package Remarkety_Mgconnector
8
+ * @author Piotr Pierzak <piotrek.pierzak@gmail.com>
9
+ */
10
+ class Remarkety_Mgconnector_Block_Adminhtml_Configuration_Upgrade extends Mage_Adminhtml_Block_Widget_Form_Container
11
+ {
12
+ /**
13
+ * Prepare block
14
+ */
15
+ public function __construct()
16
+ {
17
+ parent::__construct();
18
+
19
+ $this->_objectId = 'upgrade_id';
20
+ $this->_blockGroup = 'mgconnector';
21
+ $this->_controller = 'adminhtml_configuration';
22
+ $this->_mode = 'upgrade';
23
+
24
+ $ver = Mage::getConfig()->getModuleConfig("Remarkety_Mgconnector")->version;
25
+ $this->_headerText = $this->__('Upgrade Remarkety extension (version: %s)', $ver);
26
+
27
+ $this->_removeButton('back');
28
+ $this->_removeButton('reset');
29
+ $this->_addButton('save', array(
30
+ 'label' => Mage::helper('adminhtml')->__('Complete Installation'),
31
+ 'onclick' => 'editForm.submit();',
32
+ 'class' => 'save',
33
+ ), 1);
34
+ }
35
+ }
app/code/community/Remarkety/Mgconnector/Block/Adminhtml/Configuration/Upgrade/Form.php ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Adminhtml configuration upgrade form block
5
+ *
6
+ * @category Remarkety
7
+ * @package Remarkety_Mgconnector
8
+ * @author Piotr Pierzak <piotrek.pierzak@gmail.com>
9
+ */
10
+ class Remarkety_Mgconnector_Block_Adminhtml_Configuration_Upgrade_Form extends Mage_Adminhtml_Block_Widget_Form
11
+ {
12
+ /**
13
+ * Prepare form
14
+ *
15
+ * @return Mage_Adminhtml_Block_Widget_Form
16
+ */
17
+ protected function _prepareForm()
18
+ {
19
+ $form = new Varien_Data_Form(array(
20
+ 'id' => 'edit_form',
21
+ 'action' => $this->getUrl('*/*/complete'),
22
+ 'method' => 'post',
23
+ ));
24
+ $form->setFieldContainerIdPrefix('data');
25
+ $form->setUseContainer(true);
26
+ $this->setForm($form);
27
+
28
+ $fieldset = $form->addFieldset(
29
+ 'general',
30
+ array(
31
+ 'legend' => $this->__('Upgrade Remarkety extension')
32
+ )
33
+ );
34
+
35
+ $fieldset->addField('mode', 'hidden', array(
36
+ 'name' => 'data[mode]',
37
+ 'value' => 'upgrade',
38
+ ));
39
+
40
+ $instruction = $fieldset->addField('instruction', 'note', array(
41
+ 'text' => '',
42
+ 'label' => false,
43
+ 'after_element_html' =>
44
+ '<p style="font-weight:bold;">' . $this->__('Thank you for installing the Remarkety Magento plugin.
45
+ You are one click away from finishing setting up Remarkety on your store and sending effective, targeted emails!')
46
+ . '<br><br>'
47
+ . $this->__('It seems that you have already installed Remarkety on this website before. This
48
+ version of the plugin will create a new API key, and automatically inform
49
+ Remarkety. If this is a mistake, please <a href="%s">click here</a>.</p>', $this->getUrl('*/*/installation', array('mode' => 'install')))
50
+ ));
51
+ $instruction->getRenderer()->setTemplate('mgconnector/widget/form/renderer/fieldset/element.phtml');
52
+
53
+ $fieldset->addField('terms', 'checkbox', array(
54
+ 'label' => false,
55
+ 'name' => 'data[terms]',
56
+ 'checked' => false,
57
+ 'value' => '1',
58
+ 'class' => 'required-entry',
59
+ 'after_element_html' => $this->__('I agree to Remarkety’s <a href="%s">terms of use</a>.', '#'),
60
+ ));
61
+
62
+ $fieldset->addField('button', 'note', array(
63
+ 'label' => false,
64
+ 'name' => 'button',
65
+ 'after_element_html' => '<button type="button" class="save" onclick="editForm.submit();"><span><span>'
66
+ . $this->__('Complete Installation') . '</span></span></button>'
67
+ ));
68
+
69
+ return parent::_prepareForm();
70
+ }
71
+ }
app/code/community/Remarkety/Mgconnector/Block/Adminhtml/Install/Complete.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Adminhtml configuration complete block
5
+ *
6
+ * @category Remarkety
7
+ * @package Remarkety_Mgconnector
8
+ * @author Piotr Pierzak <piotrek.pierzak@gmail.com>
9
+ */
10
+ class Remarkety_Mgconnector_Block_Adminhtml_Install_Complete extends Mage_Adminhtml_Block_Widget_Form_Container
11
+ {
12
+ /**
13
+ * Prepare block
14
+ */
15
+ public function __construct()
16
+ {
17
+ parent::__construct();
18
+
19
+ $this->_objectId = 'complete_id';
20
+ $this->_blockGroup = 'mgconnector';
21
+ $this->_controller = 'adminhtml_install';
22
+ $this->_mode = 'complete';
23
+
24
+ $this->_headerText = $this->__(
25
+ 'Install Complete (version: %s)',
26
+ Mage::helper('mgconnector')->getInstalledVersion()
27
+ );
28
+
29
+ $this->_removeButton('back');
30
+ $this->_removeButton('reset');
31
+ $this->_addButton('save', array(
32
+ 'label' => Mage::helper('adminhtml')->__('Done'),
33
+ 'onclick' => 'editForm.submit();',
34
+ 'class' => 'save',
35
+ ), 1);
36
+ }
37
+ }
app/code/community/Remarkety/Mgconnector/Block/Adminhtml/Install/Complete/Form.php ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Adminhtml configuration complete form block
5
+ *
6
+ * @category Remarkety
7
+ * @package Remarkety_Mgconnector
8
+ * @author Piotr Pierzak <piotrek.pierzak@gmail.com>
9
+ */
10
+ class Remarkety_Mgconnector_Block_Adminhtml_Install_Complete_Form extends Mage_Adminhtml_Block_Widget_Form
11
+ {
12
+ /**
13
+ * Prepare form
14
+ *
15
+ * @return Mage_Adminhtml_Block_Widget_Form
16
+ */
17
+ protected function _prepareForm()
18
+ {
19
+ $form = new Varien_Data_Form(array(
20
+ 'id' => 'edit_form',
21
+ 'action' => $this->getUrl('*/*/complete'),
22
+ 'method' => 'post',
23
+ ));
24
+ $form->setFieldContainerIdPrefix('data');
25
+ $form->setUseContainer(true);
26
+ $this->setForm($form);
27
+
28
+ $fieldset = $form->addFieldset(
29
+ 'general',
30
+ array(
31
+ 'legend' => $this->__('Installation Complete')
32
+ )
33
+ );
34
+
35
+ $fieldset->addField('mode', 'hidden', array(
36
+ 'name' => 'data[mode]',
37
+ 'value' => 'complete',
38
+ ));
39
+
40
+ $instruction = $fieldset->addField('instruction', 'note', array(
41
+ 'text' => '',
42
+ 'label' => false,
43
+ 'after_element_html' => '<p style="font-weight:bold;">' . $this->__('Installation complete!') . '</p>'
44
+ ));
45
+ $instruction->getRenderer()->setTemplate('mgconnector/element.phtml');
46
+
47
+ $response = Mage::getSingleton('core/session')->getRemarketyLastResponseMessage();
48
+ $response = !empty($response) ? unserialize($response) : array();
49
+ $fieldset->addField('response', 'note', array(
50
+ 'label' => false,
51
+ 'after_element_html' => !empty($response['info']) ? $response['info'] : $this->__('There is no response to display')
52
+ ));
53
+
54
+ $fieldset->addField('button', 'note', array(
55
+ 'label' => false,
56
+ 'name' => 'button',
57
+ 'after_element_html' => '<button type="button" class="save" onclick="editForm.submit();"><span><span>'
58
+ . $this->__('Done') . '</span></span></button>'
59
+ ));
60
+
61
+ return parent::_prepareForm();
62
+ }
63
+ }
app/code/community/Remarkety/Mgconnector/Block/Adminhtml/Install/Install/Create.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Adminhtml install install block
5
+ *
6
+ * @category Remarkety
7
+ * @package Remarkety_Mgconnector
8
+ * @author Piotr Pierzak <piotrek.pierzak@gmail.com>
9
+ */
10
+ class Remarkety_Mgconnector_Block_Adminhtml_Install_Install_Create extends Mage_Adminhtml_Block_Widget_Form_Container
11
+ {
12
+ /**
13
+ * Prepare block
14
+ */
15
+ public function __construct()
16
+ {
17
+ parent::__construct();
18
+
19
+ $this->_objectId = 'install_id';
20
+ $this->_blockGroup = 'mgconnector';
21
+ $this->_controller = 'adminhtml_install_install';
22
+ $this->_mode = 'create';
23
+
24
+ $this->_headerText = $this->__(
25
+ 'Install Remarkety extension (version: %s)',
26
+ Mage::helper('mgconnector')->getInstalledVersion()
27
+ );
28
+
29
+ $this->_removeButton('back');
30
+ $this->_removeButton('reset');
31
+ $this->_removeButton('save');
32
+ }
33
+ }
app/code/community/Remarkety/Mgconnector/Block/Adminhtml/Install/Install/Create/Form.php ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Adminhtml install install form block
5
+ *
6
+ * @category Remarkety
7
+ * @package Remarkety_Mgconnector
8
+ * @author Piotr Pierzak <piotrek.pierzak@gmail.com>
9
+ */
10
+ class Remarkety_Mgconnector_Block_Adminhtml_Install_Install_Create_Form extends Mage_Adminhtml_Block_Widget_Form
11
+ {
12
+ /**
13
+ * Prepare form
14
+ *
15
+ * @return Mage_Adminhtml_Block_Widget_Form
16
+ */
17
+ protected function _prepareForm()
18
+ {
19
+ $form = new Varien_Data_Form(array(
20
+ 'id' => 'edit_form',
21
+ 'action' => $this->getUrl('*/install/complete'),
22
+ 'method' => 'post',
23
+ ));
24
+ $form->setFieldContainerIdPrefix('data');
25
+ $form->setUseContainer(true);
26
+ $this->setForm($form);
27
+
28
+ $multipleStores = Remarkety_Mgconnector_Model_Install::isMultipleStores();
29
+ $accountWithLoginUrl = $this->getUrl('*/install/install', array('mode' => Remarkety_Mgconnector_Model_Install::MODE_INSTALL_LOGIN));
30
+
31
+ $fieldset = $form->addFieldset(
32
+ 'general',
33
+ array(
34
+ 'legend' => $this->__('Install Remarkety extension')
35
+ )
36
+ );
37
+
38
+ $fieldset->addField('mode', 'hidden', array(
39
+ 'name' => 'data[mode]',
40
+ 'value' => 'install_create',
41
+ ));
42
+
43
+ $headingHtml =
44
+ '<p><b>' . $this->__('Thank you for installing the Remarkety Magento plugin.
45
+ You are one click away from finishing setting up Remarkety on your store and sending effective, targeted emails!')
46
+ . '</b><br><br>'
47
+ . $this->__('The plugin will automatically create a Magento WebService API user so that
48
+ Remarkety can synchronize with your store.') . '</p><hr/>'
49
+ . '<h2>'.$this->__('Create a new Remarkety account') . '</h2>'
50
+ . '<p>'.
51
+ sprintf($this->__(
52
+ 'Already registered to Remarkety? <a href="%s">Click here</a>'
53
+ ), $accountWithLoginUrl)
54
+ . '</p>';
55
+
56
+ $instruction = $fieldset->addField('instruction', 'note', array(
57
+ 'text' => '',
58
+ 'label' => false,
59
+ 'after_element_html' => $headingHtml,
60
+
61
+ ));
62
+ $instruction->getRenderer()->setTemplate('mgconnector/element.phtml');
63
+
64
+ $html = '<small style="float:left;width:100%;">' . sprintf($this->__(
65
+ 'Already registered to Remarkety? <a href="%s">Click here</a>'
66
+ ), $accountWithLoginUrl) . '</small>';
67
+
68
+ $fieldset->addField('email', 'text', array(
69
+ 'label' => $this->__('Email address for the Remarkety account:'),
70
+ 'name' => 'data[email]',
71
+ 'required' => true,
72
+ 'class' => 'validate-email',
73
+ //'after_element_html' => $html,
74
+ 'style' => 'float:left',
75
+ ));
76
+
77
+ $fieldset->addField('first_name', 'text', array(
78
+ 'label' => $this->__('First Name:'),
79
+ 'name' => 'data[first_name]',
80
+ 'required' => true,
81
+ 'class' => 'required-entry'
82
+ ));
83
+
84
+ $fieldset->addField('last_name', 'text', array(
85
+ 'label' => $this->__('Last Name:'),
86
+ 'name' => 'data[last_name]',
87
+ 'required' => true,
88
+ 'class' => 'required-entry'
89
+ ));
90
+
91
+ $fieldset->addField('phone', 'text', array(
92
+ 'label' => $this->__('Phone:'),
93
+ 'name' => 'data[phone]',
94
+ 'required' => true,
95
+ 'class' => 'required-entry'
96
+ ));
97
+
98
+ $fieldset->addField('password', 'password', array(
99
+ 'label' => $this->__('Password:'),
100
+ 'name' => 'data[password]',
101
+ 'required' => true,
102
+ 'class' => 'required-entry'
103
+ ));
104
+
105
+
106
+ $fieldset->addField('store_id', $multipleStores ? 'multiselect' : 'select', array(
107
+ 'name' => 'data[store_id]',
108
+ 'label' => $this->__('Sync Remarkety with this view:'),
109
+ 'required' => true,
110
+ 'values' => Mage::getSingleton('adminhtml/system_store')->getStoreValuesForForm(false, false),
111
+ ));
112
+
113
+ $fieldset->addField('terms', 'checkbox', array(
114
+ 'label' => false,
115
+ 'name' => 'data[terms]',
116
+ 'checked' => false,
117
+ 'value' => '1',
118
+ 'class' => 'required-entry',
119
+ 'after_element_html' => $this->__('I agree to Remarkety’s <a href="%s">terms of use</a>.', '#'),
120
+ ));
121
+
122
+ $fieldset->addField('create', 'note', array(
123
+ 'label' => false,
124
+ 'name' => 'button',
125
+ 'after_element_html' => '<button type="button" class="save" onclick="editForm.submit();"><span><span>'
126
+ . $this->__('Create New Account And Connect') . '</span></span></button>',
127
+ ));
128
+
129
+ // $fieldset->addField('login', 'note', array(
130
+ // 'label' => false,
131
+ // 'name' => 'button',
132
+ // 'after_element_html' => '<button type="button" class="save"
133
+ // onclick="window.location = \'' . $this->getUrl('*/install/install', array('mode' => Remarkety_Mgconnector_Model_Install::MODE_INSTALL_LOGIN)) . '\'"
134
+ // ><span><span>'
135
+ // . $this->__('I Already Have An Account') . '</span></span></button>',
136
+ // ));
137
+
138
+ return parent::_prepareForm();
139
+ }
140
+ }
app/code/community/Remarkety/Mgconnector/Block/Adminhtml/Install/Install/Login.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Adminhtml install install block
5
+ *
6
+ * @category Remarkety
7
+ * @package Remarkety_Mgconnector
8
+ * @author Piotr Pierzak <piotrek.pierzak@gmail.com>
9
+ */
10
+ class Remarkety_Mgconnector_Block_Adminhtml_Install_Install_Login extends Mage_Adminhtml_Block_Widget_Form_Container
11
+ {
12
+ /**
13
+ * Prepare block
14
+ */
15
+ public function __construct()
16
+ {
17
+ parent::__construct();
18
+
19
+ $this->_objectId = 'install_id';
20
+ $this->_blockGroup = 'mgconnector';
21
+ $this->_controller = 'adminhtml_install_install';
22
+ $this->_mode = 'login';
23
+
24
+ $this->_headerText = $this->__(
25
+ 'Install Remarkety extension (version: %s)',
26
+ Mage::helper('mgconnector')->getInstalledVersion()
27
+ );
28
+
29
+ $this->_removeButton('back');
30
+ $this->_removeButton('reset');
31
+ $this->_removeButton('save');
32
+ }
33
+ }
app/code/community/Remarkety/Mgconnector/Block/Adminhtml/Install/Install/Login/Form.php ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Adminhtml install install form block
5
+ *
6
+ * @category Remarkety
7
+ * @package Remarkety_Mgconnector
8
+ * @author Piotr Pierzak <piotrek.pierzak@gmail.com>
9
+ */
10
+ class Remarkety_Mgconnector_Block_Adminhtml_Install_Install_Login_Form extends Mage_Adminhtml_Block_Widget_Form
11
+ {
12
+ /**
13
+ * Prepare form
14
+ *
15
+ * @return Mage_Adminhtml_Block_Widget_Form
16
+ */
17
+ protected function _prepareForm()
18
+ {
19
+ $form = new Varien_Data_Form(array(
20
+ 'id' => 'edit_form',
21
+ 'action' => $this->getUrl('*/install/complete'),
22
+ 'method' => 'post',
23
+ ));
24
+ $form->setFieldContainerIdPrefix('data');
25
+ $form->setUseContainer(true);
26
+ $this->setForm($form);
27
+
28
+ $fieldset = $form->addFieldset(
29
+ 'general',
30
+ array(
31
+ 'legend' => $this->__('Install Remarkety extension')
32
+ )
33
+ );
34
+
35
+ $fieldset->addField('mode', 'hidden', array(
36
+ 'name' => 'data[mode]',
37
+ 'value' => 'install_login',
38
+ ));
39
+ $noAccountUrl = $this->getUrl('*/install/install', array('mode' => Remarkety_Mgconnector_Model_Install::MODE_INSTALL_CREATE));
40
+
41
+ /*$headingHtml =
42
+ '<p><b>' . $this->__('Thank you for installing the Remarkety Magento plugin.
43
+ You are one click away from finishing setting up Remarkety on your store and sending effective, targeted emails!')
44
+ . '</b><br><br>'
45
+ . $this->__('The plugin will automatically create a Magento WebService API user so that
46
+ Remarkety can synchronize with your store.') . '</p><hr/>'
47
+ . '<h2>'.$this->__('Login to Remarkety') . '</h2>'
48
+ . '<p>'.
49
+ sprintf($this->__(
50
+ 'Don\'t have a Remarkety account yet? <a href="%s">Click here</a>'
51
+ ), $noAccountUrl)
52
+ . '</p>';
53
+
54
+ /$instruction = $fieldset->addField('instruction', 'note', array(
55
+ 'text' => '',
56
+ 'label' => false,
57
+ 'after_element_html' => $headingHtml,
58
+ // '<p style="font-weight:bold;">' . $this->__('Thank you for installing the Remarkety Magento plugin.
59
+ // You are one click away from finishing setting up Remarkety on your store and sending effective, targeted emails!')
60
+ // . '<br><br>'
61
+ // . $this->__('The plugin will automatically create a Magento WebService API user so that
62
+ // Remarkety can synchronize with your store.') . '</p>',
63
+ ));
64
+ $instruction->getRenderer()->setTemplate('mgconnector/element.phtml');*/
65
+
66
+ $noAccountUrl = $this->getUrl('*/install/install', array('mode' => Remarkety_Mgconnector_Model_Install::MODE_INSTALL_CREATE));
67
+
68
+ $html = '<small style="float:left;width:100%;">' . sprintf($this->__(
69
+ 'Don\'t have a Remarkety account yet? <a href="%s">Click here</a>'
70
+ ), $noAccountUrl) . '</small>';
71
+
72
+ $fieldset->addField('email', 'text', array(
73
+ 'label' => $this->__('Email address for the Remarkety account:'),
74
+ 'name' => 'data[email]',
75
+ 'required' => true,
76
+ 'class' => 'validate-email',
77
+ /*
78
+ 'after_element_html' => $html,
79
+ '<small style="float:left;width:100%;">' . $this->__(
80
+ 'If you’ve already registered to Remarkety, please use the email you used to open your account.
81
+ If you haven’t, please click on the button "Create New Account And Install" below.'
82
+ ) . '</small>',
83
+ */
84
+ 'style' => 'float:left',
85
+ ));
86
+
87
+ $fieldset->addField('password', 'password', array(
88
+ 'label' => $this->__('Password:'),
89
+ 'name' => 'data[password]',
90
+ 'required' => true,
91
+ 'class' => 'required-entry'
92
+ ));
93
+
94
+ $fieldset->addField('store_id', 'select', array(
95
+ 'name' => 'data[store_id]',
96
+ 'label' => $this->__('Connect this view:'),
97
+ 'required' => true,
98
+ 'values' => Mage::getSingleton('adminhtml/system_store')->getStoreValuesForForm(false, false),
99
+ //'value' => $this->getRequest()->getParam('store'),
100
+ ));
101
+
102
+ // $fieldset->addField('terms', 'checkbox', array(
103
+ // 'label' => false,
104
+ // 'name' => 'data[terms]',
105
+ // 'checked' => false,
106
+ // 'value' => '1',
107
+ // 'class' => 'required-entry',
108
+ // 'after_element_html' => $this->__('I agree to Remarkety’s <a href="%s">terms of use</a>.', '#'),
109
+ // ));
110
+
111
+ $fieldset->addField('login', 'note', array(
112
+ 'label' => false,
113
+ 'name' => 'button',
114
+ 'after_element_html' => '<button type="button" class="save" onclick="editForm.submit();"><span>'
115
+ . $this->__('Login And Connect') . '
116
+ </span></button>',
117
+ ));
118
+
119
+ // $fieldset->addField('create', 'note', array(
120
+ // 'label' => false,
121
+ // 'name' => 'button',
122
+ // 'after_element_html' => '<button type="button" class="save"
123
+ // onclick="window.location = \'' . $this->getUrl('*/install/install', array('mode' => Remarkety_Mgconnector_Model_Install::MODE_INSTALL_CREATE)) . '\'"
124
+ // ><span><span>'
125
+ // . $this->__('Create New Account And Install') . '</span></span></button>',
126
+ // ));
127
+
128
+ return parent::_prepareForm();
129
+ }
130
+ }
app/code/community/Remarkety/Mgconnector/Block/Adminhtml/Install/Upgrade.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Adminhtml configuration upgrade block
5
+ *
6
+ * @category Remarkety
7
+ * @package Remarkety_Mgconnector
8
+ * @author Piotr Pierzak <piotrek.pierzak@gmail.com>
9
+ */
10
+ class Remarkety_Mgconnector_Block_Adminhtml_Install_Upgrade extends Mage_Adminhtml_Block_Widget_Form_Container
11
+ {
12
+ /**
13
+ * Prepare block
14
+ */
15
+ public function __construct()
16
+ {
17
+ parent::__construct();
18
+
19
+ $this->_objectId = 'upgrade_id';
20
+ $this->_blockGroup = 'mgconnector';
21
+ $this->_controller = 'adminhtml_install';
22
+ $this->_mode = 'upgrade';
23
+
24
+ $this->_headerText = $this->__(
25
+ 'Upgrade Remarkety extension (version: %s)',
26
+ Mage::helper('mgconnector')->getInstalledVersion()
27
+ );
28
+
29
+ $this->_removeButton('back');
30
+ $this->_removeButton('reset');
31
+ $this->_addButton('save', array(
32
+ 'label' => Mage::helper('adminhtml')->__('Complete Installation'),
33
+ 'onclick' => 'editForm.submit();',
34
+ 'class' => 'save',
35
+ ), 1);
36
+ }
37
+ }
app/code/community/Remarkety/Mgconnector/Block/Adminhtml/Install/Upgrade/Form.php ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Adminhtml configuration upgrade form block
5
+ *
6
+ * @category Remarkety
7
+ * @package Remarkety_Mgconnector
8
+ * @author Piotr Pierzak <piotrek.pierzak@gmail.com>
9
+ */
10
+ class Remarkety_Mgconnector_Block_Adminhtml_Install_Upgrade_Form extends Mage_Adminhtml_Block_Widget_Form
11
+ {
12
+ /**
13
+ * Prepare form
14
+ *
15
+ * @return Mage_Adminhtml_Block_Widget_Form
16
+ */
17
+ protected function _prepareForm()
18
+ {
19
+ $form = new Varien_Data_Form(array(
20
+ 'id' => 'edit_form',
21
+ 'action' => $this->getUrl('*/install/complete'),
22
+ 'method' => 'post',
23
+ ));
24
+ $form->setFieldContainerIdPrefix('data');
25
+ $form->setUseContainer(true);
26
+ $this->setForm($form);
27
+
28
+ $fieldset = $form->addFieldset(
29
+ 'general',
30
+ array(
31
+ 'legend' => $this->__('Upgrade Remarkety extension')
32
+ )
33
+ );
34
+
35
+ $fieldset->addField('mode', 'hidden', array(
36
+ 'name' => 'data[mode]',
37
+ 'value' => 'upgrade',
38
+ ));
39
+
40
+ $instruction = $fieldset->addField('instruction', 'note', array(
41
+ 'text' => '',
42
+ 'label' => false,
43
+ 'after_element_html' =>
44
+ '<p style="font-weight:bold;">' . $this->__('Thank you for installing the Remarkety Magento plugin.
45
+ You are one click away from finishing setting up Remarkety on your store and sending effective, targeted emails!')
46
+ . '<br><br>'
47
+ . $this->__('It seems that you have already installed Remarkety on this website before. This
48
+ version of the plugin will create a new API key, and automatically inform
49
+ Remarkety. If this is a mistake, please <a href="%s">click here</a>.</p>', $this->getUrl('*/install/install', array('mode' => 'install_create')))
50
+ ));
51
+ $instruction->getRenderer()->setTemplate('mgconnector/element.phtml');
52
+
53
+ $fieldset->addField('button', 'note', array(
54
+ 'label' => false,
55
+ 'name' => 'button',
56
+ 'after_element_html' => '<button type="button" class="save" onclick="editForm.submit();"><span><span>'
57
+ . $this->__('Complete Installation') . '</span></span></button>'
58
+ ));
59
+
60
+ return parent::_prepareForm();
61
+ }
62
+ }
app/code/community/Remarkety/Mgconnector/Block/Adminhtml/Install/Welcome.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Adminhtml welcome complete block
5
+ *
6
+ * @category Remarkety
7
+ * @package Remarkety_Mgconnector
8
+ * @author Piotr Pierzak <piotrek.pierzak@gmail.com>
9
+ */
10
+ class Remarkety_Mgconnector_Block_Adminhtml_Install_Welcome extends Mage_Adminhtml_Block_Widget_Form_Container
11
+ {
12
+ /**
13
+ * Prepare block
14
+ */
15
+ public function __construct()
16
+ {
17
+ parent::__construct();
18
+
19
+ $this->_objectId = 'welcome_id';
20
+ $this->_blockGroup = 'mgconnector';
21
+ $this->_controller = 'adminhtml_install';
22
+ $this->_mode = 'welcome';
23
+
24
+ $this->_headerText = $this->__(
25
+ 'Remarkety (version: %s)',
26
+ Mage::helper('mgconnector')->getInstalledVersion()
27
+ );
28
+
29
+ $this->_removeButton('back');
30
+ $this->_removeButton('reset');
31
+ $this->_removeButton('save');
32
+
33
+ $this->_addButton('reinstall', array(
34
+ 'label' => Mage::helper('adminhtml')->__('Reinstall'),
35
+ 'onclick' => "return confirm('Are you sure?') ? window.location = '" . $this->getUrl('*/install/reinstall')."' : false;",
36
+ 'class' => 'delete',
37
+ ), 0);
38
+ }
39
+ }
app/code/community/Remarkety/Mgconnector/Block/Adminhtml/Install/Welcome/Form.php ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Adminhtml welcome complete form block
5
+ *
6
+ * @category Remarkety
7
+ * @package Remarkety_Mgconnector
8
+ * @author Piotr Pierzak <piotrek.pierzak@gmail.com>
9
+ */
10
+ class Remarkety_Mgconnector_Block_Adminhtml_Install_Welcome_Form extends Mage_Adminhtml_Block_Widget_Form
11
+ {
12
+ /**
13
+ * Prepare form
14
+ *
15
+ * @return Mage_Adminhtml_Block_Widget_Form
16
+ */
17
+ protected function _prepareForm()
18
+ {
19
+ $form = new Varien_Data_Form(array(
20
+ 'id' => 'edit_form',
21
+ 'action' => $this->getUrl('*/*/install'),
22
+ 'method' => 'post',
23
+ ));
24
+ $form->setFieldContainerIdPrefix('data');
25
+ $form->setUseContainer(true);
26
+ $this->setForm($form);
27
+
28
+ $fieldset = $form->addFieldset(
29
+ 'general',
30
+ array(
31
+ 'legend' => $this->__('Remarkety')
32
+ )
33
+ );
34
+
35
+ $fieldset->addField('mode', 'hidden', array(
36
+ 'name' => 'data[mode]',
37
+ 'value' => 'complete',
38
+ ));
39
+
40
+ $instruction = $fieldset->addField('instruction', 'note', array(
41
+ 'text' => '',
42
+ 'label' => false,
43
+ 'after_element_html' => '<p style="font-weight:bold;font-size:25px;">' . $this->__('Welcome to Remarkety - What\'s next?') . '</p>
44
+ <ol style="list-style-type:decimal;margin-left:20px;font-weight:bold;font-size:12px;">
45
+ <li>Sign in to your account <a href="https://app.remarkety.com/?utm_source=plugin&utm_medium=link&utm_campaign=magento-plugin" target="_blank">here</a></li>
46
+ <li>Create campaigns, send emails and monitor results.</li>
47
+ <li>Increase sales and customer\'s Life Time Value</li>
48
+ <li>Need help? We are here for you: <a href="mailto:support@remarkety.com">support@remarkety.com</a> <a href="tel:%28%2B1%20800%20570-7564">(+1 800 570-7564)</a></li>
49
+ </ol>
50
+ '
51
+ ));
52
+ $instruction->getRenderer()->setTemplate('mgconnector/element.phtml');
53
+
54
+ return parent::_prepareForm();
55
+ }
56
+ }
app/code/community/Remarkety/Mgconnector/Block/Adminhtml/Install/Welcome/Store.php ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Remarkety_Mgconnector_Block_Adminhtml_Install_Welcome_Store extends Mage_Adminhtml_Block_Template
4
+ {
5
+ /**
6
+ * Prepare block
7
+ */
8
+ public function __construct()
9
+ {
10
+ $this->setTemplate('mgconnector/install/welcome/store.phtml');
11
+ parent::__construct();
12
+ }
13
+
14
+ public function getStoresStatus()
15
+ {
16
+ /**
17
+ * @var $wtModel Remarkety_Mgconnector_Model_Webtracking
18
+ */
19
+ $wtModel = Mage::getModel('mgconnector/webtracking');
20
+
21
+ $stores = array();
22
+
23
+ foreach (Mage::app()->getWebsites() as $_website) {
24
+ $stores[$_website->getCode()] = array(
25
+ 'name' => $_website->getName(),
26
+ 'id' => $_website->getWebsiteId(),
27
+ );
28
+
29
+ foreach ($_website->getGroups() as $_group) {
30
+ $stores[$_website->getCode()]['store_groups'][$_group->getCode()] = array(
31
+ 'name' => $_group->getName(),
32
+ 'id' => $_group->getGroupId(),
33
+ );
34
+
35
+ foreach ($_group->getStores() as $_store) {
36
+ $isInstalled = $_store->getConfig(Remarkety_Mgconnector_Model_Install::XPATH_INSTALLED);
37
+ $webtracking = $wtModel->getRemarketyPublicId($_store->getStoreId());
38
+ $stores[$_website->getCode()]['store_groups'][$_group->getCode()]['store_views'][$_store->getCode()] = array(
39
+ 'name' => $_store->getName(),
40
+ 'id' => $_store->getStoreId(),
41
+ 'isInstalled' => $isInstalled,
42
+ 'webTracking' => $webtracking
43
+ );
44
+ }
45
+ }
46
+ }
47
+
48
+ return $stores;
49
+ }
50
+
51
+ public function checkAPIKey(){
52
+ try {
53
+ $uModel = Mage::getModel('api/user');
54
+ $apiKey = Mage::getStoreConfig('remarkety/mgconnector/api_key');
55
+ return $uModel->authenticate(\Remarkety_Mgconnector_Model_Install::WEB_SERVICE_USERNAME, $apiKey);
56
+ } catch (Exception $ex){
57
+ return false;
58
+ }
59
+ }
60
+ }
app/code/community/Remarkety/Mgconnector/Block/Adminhtml/Queue.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Adminhtml queue block
5
+ *
6
+ * @category Remarkety
7
+ * @package Remarkety_Mgconnector
8
+ * @author Piotr Pierzak <piotrek.pierzak@gmail.com>
9
+ */
10
+ class Remarkety_Mgconnector_Block_Adminhtml_Queue extends Mage_Adminhtml_Block_Widget_Grid_Container
11
+ {
12
+ /**
13
+ * Prepare block
14
+ */
15
+ public function __construct()
16
+ {
17
+ parent::__construct();
18
+
19
+ $this->_blockGroup = 'mgconnector';
20
+ $this->_controller = 'adminhtml_queue';
21
+ $this->_headerText = Mage::helper('mgconnector')->__('Queue Contents');
22
+ $this->_removeButton('add');
23
+ }
24
+ }
app/code/community/Remarkety/Mgconnector/Block/Adminhtml/Queue/Configure.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Adminhtml configure block
5
+ *
6
+ * @category Remarkety
7
+ * @package Remarkety_Mgconnector
8
+ * @author Piotr Pierzak <piotrek.pierzak@gmail.com>
9
+ */
10
+ class Remarkety_Mgconnector_Block_Adminhtml_Queue_Configure extends Mage_Adminhtml_Block_Widget_Form_Container
11
+ {
12
+ /**
13
+ * Prepare block
14
+ */
15
+ public function __construct()
16
+ {
17
+ parent::__construct();
18
+
19
+ $this->_objectId = 'configure_id';
20
+ $this->_blockGroup = 'mgconnector';
21
+ $this->_controller = 'adminhtml_queue';
22
+ $this->_mode = 'configure';
23
+
24
+ $this->_headerText = $this->__(
25
+ 'Configuration'
26
+ // Mage::helper('mgconnector')->getInstalledVersion()
27
+ );
28
+
29
+ $this->_removeButton('back');
30
+ $this->_removeButton('reset');
31
+
32
+ // $this->_addButton('save', array(
33
+ // 'label' => Mage::helper('adminhtml')->__('Save'),
34
+ // 'onclick' => 'editForm.submit();',
35
+ // 'class' => 'save',
36
+ // ), 0);
37
+ }
38
+ }
app/code/community/Remarkety/Mgconnector/Block/Adminhtml/Queue/Configure/Form.php ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Adminhtml configure form block
5
+ *
6
+ * @category Remarkety
7
+ * @package Remarkety_Mgconnector
8
+ * @author Piotr Pierzak <piotrek.pierzak@gmail.com>
9
+ */
10
+ class Remarkety_Mgconnector_Block_Adminhtml_Queue_Configure_Form extends Mage_Adminhtml_Block_Widget_Form
11
+ {
12
+ /**
13
+ * Prepare form
14
+ *
15
+ * @return Mage_Adminhtml_Block_Widget_Form
16
+ */
17
+ protected function _prepareForm()
18
+ {
19
+ $form = new Varien_Data_Form(array(
20
+ 'id' => 'edit_form',
21
+ 'action' => $this->getUrl('*/queue/save'),
22
+ 'method' => 'post',
23
+ ));
24
+ $form->setFieldContainerIdPrefix('data');
25
+ $form->setUseContainer(true);
26
+ $this->setForm($form);
27
+
28
+ $fieldset = $form->addFieldset(
29
+ 'general',
30
+ array(
31
+ 'legend' => $this->__('Remarkety Configuration')
32
+ )
33
+ );
34
+
35
+ $fieldset->addField('mode', 'hidden', array(
36
+ 'name' => 'data[mode]',
37
+ 'value' => 'configuration',
38
+ ));
39
+
40
+ if(!$this->checkAPIKey()) {
41
+ $fieldset->addField('api_warning', 'note', array(
42
+ 'text' => '<span style="color: red;">' . $this->__('Attention! Remarkety\'s API key is not the same as the Magento API key. Please set it below.') . '</span>'.
43
+ ' <a target="_blank" href="https://support.remarkety.com/hc/en-us/articles/209184646-Synchronizing-the-API-key">More Info</a>.',
44
+ ));
45
+ }
46
+
47
+ $fieldset->addField('api_key', 'text', array(
48
+ 'label' => $this->__('API Key:'),
49
+ 'name' => 'data[api_key]',
50
+ 'required' => true,
51
+ 'after_element_html' => '<small style="float:left;width:100%;">' . $this->__(
52
+ 'This API key will be used for Remarkety\'s sync and queue.'
53
+ ) . '</small>',
54
+ 'value' => Mage::getStoreConfig('remarkety/mgconnector/api_key'),
55
+ 'style' => 'float:left',
56
+ ));
57
+
58
+ $fieldset->addField('intervals', 'text', array(
59
+ 'label' => $this->__('Intervals:'),
60
+ 'name' => 'data[intervals]',
61
+ 'required' => true,
62
+ 'after_element_html' => '<small style="float:left;width:100%;">' . $this->__(
63
+ 'This defines the queue retry interval.<br/>
64
+ Type the amount of minutes between retries, separated by commas. For example "1,3,10" -
65
+ the second attempt will be after 1 minute, third after 3 minutes,<br/>
66
+ and fourth after 10 minutes. If the last attempt is unsuccessful,
67
+ the status will be changed to "failed" and will not be retried anymore.'
68
+ ) . '</small>',
69
+ 'value' => Mage::getStoreConfig('remarkety/mgconnector/intervals'),
70
+ 'style' => 'float:left',
71
+ ));
72
+
73
+ $fieldset->addField('bypasscache', 'checkbox', array(
74
+ 'label' => $this->__('Bypass page cache for website tracking:'),
75
+ 'name' => 'data[bypasscache]',
76
+ 'after_element_html' => '<small style="float:left;width:100%;">' . $this->__(
77
+ 'Enable this checkbox if you use caching on your store pages.'
78
+ ) . '</small>',
79
+ 'value' => 1,
80
+ 'checked' => \Remarkety_Mgconnector_Model_Webtracking::getBypassCache() ? 'checked' : '',
81
+ 'style' => 'float:left',
82
+ ));
83
+
84
+ $button = $fieldset->addField('button', 'note', array(
85
+ 'label' => false,
86
+ 'name' => 'button',
87
+ 'after_element_html' => '<button type="button" class="save" onclick="editForm.submit();"><span><span>'
88
+ . $this->__('Save') . '</span></span></button>',
89
+ ));
90
+ $button->getRenderer()->setTemplate('mgconnector/element.phtml');
91
+
92
+ return parent::_prepareForm();
93
+ }
94
+
95
+ private function checkAPIKey(){
96
+ try {
97
+ $uModel = Mage::getModel('api/user');
98
+ $apiKey = Mage::getStoreConfig('remarkety/mgconnector/api_key');
99
+ return $uModel->authenticate(\Remarkety_Mgconnector_Model_Install::WEB_SERVICE_USERNAME, $apiKey);
100
+ } catch (Exception $ex){
101
+ return false;
102
+ }
103
+ }
104
+ }
app/code/community/Remarkety/Mgconnector/Block/Adminhtml/Queue/Grid.php ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Adminhtml queue grid block
5
+ *
6
+ * @category Remarkety
7
+ * @package Remarkety_Mgconnector
8
+ * @author Piotr Pierzak <piotrek.pierzak@gmail.com>
9
+ */
10
+ class Remarkety_Mgconnector_Block_Adminhtml_Queue_Grid extends Mage_Adminhtml_Block_Widget_Grid
11
+ {
12
+ /**
13
+ * Prepare block
14
+ */
15
+ public function __construct()
16
+ {
17
+ parent::__construct();
18
+
19
+ $this
20
+ ->setId('queue_grid')
21
+ ->setDefaultSort('next_attempt')
22
+ ->setDefaultDir('ASC')
23
+ ->setSaveParametersInSession(true)
24
+ ->setUseAjax(true);
25
+ }
26
+
27
+ /**
28
+ * Prepare collection
29
+ *
30
+ * @return Remarkety_Mgconnector_Block_Adminhtml_Queue_Grid
31
+ */
32
+ protected function _prepareCollection()
33
+ {
34
+ $collection = Mage::getResourceModel('mgconnector/queue_collection');
35
+ $this->setCollection($collection);
36
+
37
+ return parent::_prepareCollection();
38
+ }
39
+
40
+ /**
41
+ * Prepare columns
42
+ *
43
+ * @return Remarkety_Mgconnector_Block_Adminhtml_Queue_Grid
44
+ * @throws Exception
45
+ */
46
+ protected function _prepareColumns()
47
+ {
48
+ $helper = Mage::helper('mgconnector');
49
+
50
+ $this->addColumn('queue_id', array(
51
+ 'header' => $helper->__('Queue #'),
52
+ 'width' => '50px',
53
+ 'type' => 'number',
54
+ 'index' => 'queue_id'
55
+ ));
56
+ $this->addColumn('event_type', array(
57
+ 'header' => $helper->__('Event Type'),
58
+ 'index' => 'event_type',
59
+ 'renderer' => 'Remarkety_Mgconnector_Block_Adminhtml_Queue_Grid_Column_Renderer_EventType',
60
+ ));
61
+ $this->addColumn('status', array(
62
+ 'header' => $helper->__('Status'),
63
+ 'width' => '200px',
64
+ 'renderer' => 'Remarkety_Mgconnector_Block_Adminhtml_Queue_Grid_Column_Renderer_Status',
65
+ 'index' => 'status'
66
+ ));
67
+ $this->addColumn('attempts', array(
68
+ 'header' => $helper->__('Attempts'),
69
+ 'index' => 'attempts'
70
+ ));
71
+ $this->addColumn('last_attempt', array(
72
+ 'header' => $helper->__('Last Attempt'),
73
+ 'width' => '200px',
74
+ 'type' => 'datetime',
75
+ 'index' => 'last_attempt'
76
+ ));
77
+ $this->addColumn('next_attempt', array(
78
+ 'header' => $helper->__('Next Attempt'),
79
+ 'width' => '200px',
80
+ 'type' => 'datetime',
81
+ 'index' => 'next_attempt'
82
+ ));
83
+
84
+ return parent::_prepareColumns();
85
+ }
86
+
87
+ /**
88
+ * Return grid url
89
+ *
90
+ * @return string
91
+ */
92
+ public function getGridUrl()
93
+ {
94
+ return $this->getUrl('*/*/grid', array('_current' => true));
95
+ }
96
+
97
+
98
+ protected function _prepareMassaction()
99
+ {
100
+ $this->setMassactionIdField('queue_id');
101
+ $this->getMassactionBlock()->setFormFieldName('queue');
102
+
103
+ $this->getMassactionBlock()->addItem('resend', array(
104
+ 'label' => $this->__('Resend'),
105
+ 'url' => $this->getUrl('*/*/massResend')
106
+ ));
107
+
108
+ $this->getMassactionBlock()->addItem('delete', array(
109
+ 'label' => $this->__('Delete'),
110
+ 'url' => $this->getUrl('*/*/massDelete'),
111
+ 'confirm' => $this->__('Really delete all these events?')
112
+ ));
113
+
114
+ return $this;
115
+ }
116
+ }
app/code/community/Remarkety/Mgconnector/Block/Adminhtml/Queue/Grid/Column/Renderer/EventType.php ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Adminhtml queue grid status column renderer block
5
+ *
6
+ * @category Remarkety
7
+ * @package Remarkety_Mgconnector
8
+ * @author Piotr Pierzak <piotrek.pierzak@gmail.com>
9
+ */
10
+ class Remarkety_Mgconnector_Block_Adminhtml_Queue_Grid_Column_Renderer_EventType
11
+ extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
12
+ {
13
+ /**
14
+ * Column renderer
15
+ *
16
+ * @param Varien_Object $row
17
+ * @return string
18
+ */
19
+ public function render(Varien_Object $row)
20
+ {
21
+ $value = $row->getData($this->getColumn()->getIndex());
22
+ try {
23
+ $payload = json_encode(unserialize($row->getData('payload')));
24
+ } catch (\Exception $e) {
25
+ $payload = "?";
26
+ }
27
+ return '<span title="'.htmlentities($payload).'">'.$value.'</span>';
28
+ }
29
+ }
app/code/community/Remarkety/Mgconnector/Block/Adminhtml/Queue/Grid/Column/Renderer/Status.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Adminhtml queue grid status column renderer block
5
+ *
6
+ * @category Remarkety
7
+ * @package Remarkety_Mgconnector
8
+ * @author Piotr Pierzak <piotrek.pierzak@gmail.com>
9
+ */
10
+ class Remarkety_Mgconnector_Block_Adminhtml_Queue_Grid_Column_Renderer_Status
11
+ extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
12
+ {
13
+ /**
14
+ * Column renderer
15
+ *
16
+ * @param Varien_Object $row
17
+ * @return string
18
+ */
19
+ public function render(Varien_Object $row)
20
+ {
21
+ $value = $row->getData($this->getColumn()->getIndex());
22
+
23
+ return Mage::helper('mgconnector')->__($value ? 'Queued' : 'Failed');
24
+ }
25
+ }
app/code/community/Remarkety/Mgconnector/Block/Tracking/Base.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Remarkety_Mgconnector_Block_Tracking_Base extends Mage_Core_Block_Template
3
+ {
4
+ public function isWebtrackingActivated()
5
+ {
6
+ return ($this->getRemarketyPublicId() !== false);
7
+ }
8
+
9
+ public function getRemarketyPublicId()
10
+ {
11
+ $store = Mage::app()->getStore();
12
+ /**
13
+ * @var $m Remarkety_Mgconnector_Model_Webtracking
14
+ */
15
+ $m = Mage::getModel('mgconnector/webtracking');
16
+ return $m->getRemarketyPublicId($store);
17
+ }
18
+
19
+ public function shouldBypassCache(){
20
+ return \Remarkety_Mgconnector_Model_Webtracking::getBypassCache();
21
+ }
22
+
23
+ public function getCustomer()
24
+ {
25
+ return Mage::getSingleton('customer/session')->getCustomer();
26
+ }
27
+
28
+ public function getEmail(){
29
+ if(Mage::getSingleton('customer/session')->isLoggedIn()){
30
+ return $this->getCustomer()->getEmail();
31
+ }
32
+ $email = Mage::getSingleton('customer/session')->getSubscriberEmail();
33
+ return empty($email) ? false : $email;
34
+ }
35
+ }
app/code/community/Remarkety/Mgconnector/Block/Tracking/General.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+ class Remarkety_Mgconnector_Block_Tracking_General extends Remarkety_Mgconnector_Block_Tracking_Base
3
+ {
4
+
5
+ }
app/code/community/Remarkety/Mgconnector/Block/Tracking/Product.php ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Remarkety_Mgconnector_Block_Tracking_Product extends Remarkety_Mgconnector_Block_Tracking_Base
3
+ {
4
+ private $_CategoryNames = array();
5
+ private $_CategoryIds = array();
6
+ /**
7
+ * Get the active product object
8
+ *
9
+ * @return Mage_Catalog_Model_Product
10
+ */
11
+ public function getActiveProduct()
12
+ {
13
+ if($this->getProduct()){
14
+ return $this->getProduct();
15
+ }
16
+ return Mage::registry('product');
17
+ }
18
+
19
+ /**
20
+ * Get arrays of Category ids and names
21
+ * @return array
22
+ */
23
+ public function getCategories(){
24
+ if(empty($this->_CategoryNames) || empty($this->_CategoryIds)) {
25
+ $cats = $this->getActiveProduct()->getCategoryIds();
26
+ $productCategoryNames = Array();
27
+ foreach ($cats as $category_id) {
28
+ $_cat = Mage::getModel('catalog/category')->load($category_id);
29
+ $productCategoryNames[] = $_cat->getName();
30
+ }
31
+ $this->_CategoryNames = $productCategoryNames;
32
+ $this->_CategoryIds = $cats;
33
+ }
34
+ return Array(
35
+ "ids" => $this->_CategoryIds,
36
+ "names" => $this->_CategoryNames
37
+ );
38
+ }
39
+
40
+ /**
41
+ * Return array of Category names
42
+ * @return array
43
+ */
44
+ public function getCategoryNames(){
45
+ $info = $this->getCategories();
46
+ return $info['names'];
47
+ }
48
+
49
+ /**
50
+ * Return array of Category ids
51
+ * @return array
52
+ */
53
+ public function getCategoryIds(){
54
+ $info = $this->getCategories();
55
+ return $info['ids'];
56
+ }
57
+ }
app/code/community/Remarkety/Mgconnector/Helper/Data.php ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Mgconnector helper
5
+ *
6
+ * @category Remarkety
7
+ * @package Remarkety_Mgconnector
8
+ * @author Piotr Pierzak <piotrek.pierzak@gmail.com>
9
+ */
10
+ class Remarkety_Mgconnector_Helper_Data extends Mage_Core_Helper_Abstract
11
+ {
12
+ /**
13
+ * Return installed extension version
14
+ *
15
+ * @return string
16
+ */
17
+ public function getInstalledVersion()
18
+ {
19
+ return Mage::getConfig()->getModuleConfig("Remarkety_Mgconnector")->version;
20
+ }
21
+
22
+ /**
23
+ * Return mode
24
+ *
25
+ * @return string
26
+ * @throws Mage_Core_Exception
27
+ */
28
+ public function getMode()
29
+ {
30
+ $mode = Remarkety_Mgconnector_Model_Install::MODE_INSTALL_CREATE;
31
+
32
+ /**
33
+ * If remarkety extension was installed in version lower than 1.0.0.15
34
+ * and remarkety web service user already exists
35
+ */
36
+ $webServiceUser = Mage::getModel('api/user')
37
+ ->setUsername(Remarkety_Mgconnector_Model_Install::WEB_SERVICE_USERNAME)
38
+ ->userExists();
39
+
40
+ if($webServiceUser === true) {
41
+ $mode = Remarkety_Mgconnector_Model_Install::MODE_UPGRADE;
42
+ }
43
+
44
+ $response = Mage::getSingleton('core/session')->getRemarketyLastResponseStatus();
45
+ //$response = Mage::getModel('core/config')->getConfig('remarkety/mgconnector/last_response_status');
46
+ if($response == 1) {
47
+ $mode = Remarkety_Mgconnector_Model_Install::MODE_COMPLETE;
48
+ } elseif($response == 0) {
49
+ $mode = Remarkety_Mgconnector_Model_Install::MODE_INSTALL_CREATE;
50
+ }
51
+
52
+ $configuredStores = Mage::getModel('mgconnector/install')->getConfiguredStores();
53
+ if($configuredStores->getSize()) {
54
+ $mode = Remarkety_Mgconnector_Model_Install::MODE_WELCOME;
55
+ }
56
+
57
+ $forceMode = Mage::app()->getRequest()->getParam('mode', false);
58
+ if(!empty($forceMode)) {
59
+ $mode = $forceMode;
60
+ }
61
+
62
+ if(!in_array($mode, array(
63
+ Remarkety_Mgconnector_Model_Install::MODE_INSTALL_CREATE,
64
+ Remarkety_Mgconnector_Model_Install::MODE_INSTALL_LOGIN,
65
+ Remarkety_Mgconnector_Model_Install::MODE_UPGRADE,
66
+ Remarkety_Mgconnector_Model_Install::MODE_COMPLETE,
67
+ Remarkety_Mgconnector_Model_Install::MODE_WELCOME,
68
+ ))) {
69
+ throw new Mage_Core_Exception('Installation mode can not be handled.');
70
+ }
71
+
72
+ return $mode;
73
+ }
74
+ }
app/code/community/Remarkety/Mgconnector/Helper/Links.php ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Remarkety_Mgconnector_Helper_Links extends Mage_Core_Helper_Abstract
4
+ {
5
+ private $parentId = null;
6
+ private $simpleIds = null;
7
+
8
+
9
+ private function loadProductLinks()
10
+ {
11
+
12
+ if ($this->parentId && $this->simpleIds) {
13
+ return;
14
+ }
15
+
16
+ $connection = Mage::getSingleton('core/resource')->getConnection('core_read');
17
+ $tableName = Mage::getSingleton('core/resource')->getTableName('catalog_product_super_link');
18
+
19
+ $query = 'select product_id,parent_id from ' . $tableName;
20
+ $this->simpleIds = array();
21
+ $this->parentId = array();
22
+
23
+ foreach ($connection->fetchAll($query) as $row) {
24
+ $productId = $row['product_id'];
25
+ $parentId = $row['parent_id'];
26
+
27
+ if (!isset($this->simpleIds[$parentId])) {
28
+ $this->simpleIds[$parentId] = array();
29
+ }
30
+ $this->simpleIds[$parentId][] = $productId;
31
+ $this->parentId[$productId] = $parentId;
32
+ }
33
+ }
34
+
35
+ public function getParentId($productId = null)
36
+ {
37
+ $this->loadProductLinks();
38
+
39
+ if (!$productId) {
40
+ return false;
41
+ }
42
+
43
+ if (isset($this->parentId[$productId])) {
44
+ return $this->parentId[$productId];
45
+ }
46
+
47
+ return null;
48
+ }
49
+
50
+ public function getSimpleIds($productId = null)
51
+ {
52
+
53
+ $this->loadProductLinks();
54
+
55
+ if (!isset($productId)) {
56
+ return $this->simpleIds;
57
+ }
58
+
59
+ if (isset($this->simpleIds[$productId])) {
60
+ return $this->simpleIds[$productId];
61
+ }
62
+ return null;
63
+ }
64
+ }
app/code/community/Remarkety/Mgconnector/Helper/Urls.php ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Remarkety_Mgconnector_Helper_Urls extends Mage_Core_Helper_Abstract
4
+ {
5
+ private $_attributeId = false;
6
+ private $_urlKey = false;
7
+
8
+ public function getValue($productId, $store_id)
9
+ {
10
+ if(isset($this->_urlKey[$store_id]) && isset($this->_urlKey[$store_id][$productId])) {
11
+ return $this->_urlKey[$store_id][$productId];
12
+ }
13
+
14
+ $connection = Mage::getSingleton('core/resource')->getConnection('core_read');
15
+ $tableName = Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar');
16
+ $attrbuteId = $this->_getAttributeId();
17
+ $query = 'SELECT `value`, `store_id` FROM ' . $tableName . ' WHERE (store_id = "'.$store_id.'" OR store_id = 0) AND attribute_id = "' . $attrbuteId . '" AND entity_id = "'. $productId .'"';
18
+
19
+ $value = $connection->fetchAll($query);
20
+
21
+ if(count($value) > 0) {
22
+ if(count($value) == 1) {
23
+ $this->_urlKey[$store_id][$productId] = $value[0]['value'];
24
+ } else {
25
+ foreach($value AS $sValue) {
26
+ if($sValue['store_id'] != 0) {
27
+ $this->_urlKey[$store_id][$productId] = $sValue['value'];
28
+ }
29
+ }
30
+ }
31
+
32
+ return $this->_urlKey[$store_id][$productId];
33
+
34
+ }
35
+ return false;
36
+ }
37
+
38
+ private function _getAttributeId() {
39
+ if(!$this->_attributeId) {
40
+ $this->_attributeId = Mage::getResourceModel('eav/entity_attribute')->getIdByCode('catalog_product', 'url_key');
41
+ }
42
+ return $this->_attributeId;
43
+ }
44
+
45
+
46
+ }
app/code/community/Remarkety/Mgconnector/Model/Core.php ADDED
@@ -0,0 +1,1399 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @copyright Copyright (C) 2016 InteraMind Ltd (Remarkety). All rights reserved.
4
+ * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
5
+ * @package This file is part of Magento Connector Plugin for Remarkety
6
+ **/
7
+
8
+ define('REMARKETY_MGCONNECTOR_STATUS', 'STATUS');
9
+ define('REMARKETY_MGCONNECTOR_CALLED_STATUS', 'CALLED');
10
+ define('REMARKETY_MGCONNECTOR_SUCCESS_STATUS', 'SUCCESS');
11
+ define('REMARKETY_MGCONNECTOR_FAILED_STATUS', 'FAILED');
12
+ define('REMARKETY_MGCONNECTOR_ERROR', 'ERROR');
13
+ define('REMARKETY_MGCONNECTOR_DATA', 'DATA');
14
+ define('REMARKETY_MGCONNECTOR_MAGE_VERSION', 'MAGENTO_VERSION');
15
+ define('REMARKETY_MGCONNECTOR_EXT_VERSION', 'PLUGIN_VERSION');
16
+ define('REMARKETY_EXECUTION_TIME', 'EXECUTION_TIME_MS');
17
+ define('REMARKETY_LOG', 'remarkety_mgconnector.log');
18
+ define('REMARKETY_LOG_SEPARATOR', '|');
19
+
20
+ class Remarkety_Mgconnector_Model_Core extends Mage_Core_Model_Abstract {
21
+
22
+ const XPATH_CATEGORIES_TO_IGNORE = 'remarkety/mgconnector/categories-to-ignore';
23
+ private $_categoriesToIgnore = array();
24
+
25
+ private $configurable_product_model = null;
26
+
27
+ private $_productCache = array();
28
+ private $_categoryCache = array();
29
+
30
+ private $_sendLogInResponse = false;
31
+ private $_log = array();
32
+
33
+ private $_startTime = 0;
34
+
35
+ private $response_mask = array(
36
+ 'customer' => array(
37
+ 'entity_id',
38
+ 'firstname',
39
+ 'lastname',
40
+ 'email',
41
+ 'created_at',
42
+ 'updated_at',
43
+ 'is_active',
44
+ 'default_billing',
45
+ 'default_shipping',
46
+ 'registered_to_newsletter',
47
+ 'group_id',
48
+ 'group_name',
49
+ 'gender',
50
+ 'prefix',
51
+ 'rewards_points',
52
+ 'store_credits',
53
+ 'address' => array(
54
+ 'created_at',
55
+ 'updated_at',
56
+ 'is_active',
57
+ 'firstname',
58
+ 'lastname',
59
+ 'city',
60
+ 'country_id',
61
+ 'region',
62
+ 'postcode',
63
+ 'region_id',
64
+ 'street',
65
+ 'company',
66
+ 'telephone'
67
+ )
68
+ ),
69
+ 'subscriber' => array(
70
+ 'subscriber_id',
71
+ 'change_status_at',
72
+ 'customer_id',
73
+ 'subscriber_email',
74
+ 'subscriber_status'
75
+ ),
76
+ 'quote' => array(
77
+ 'entity_id',
78
+ 'created_at',
79
+ 'updated_at',
80
+ 'converted_at',
81
+ 'customer_id',
82
+ 'customer_is_guest',
83
+ 'customer_email',
84
+ 'customer_firstname',
85
+ 'customer_lastname',
86
+ 'is_active',
87
+ 'grand_total',
88
+ 'discount_amount',
89
+ 'base_subtotal',
90
+ 'base_subtotal_with_discount',
91
+ 'coupon_code',
92
+ 'quote_currency_code',
93
+ 'customer_registered_to_newsletter',
94
+ 'currency',
95
+ 'checkout_url',
96
+ 'items' => array(
97
+ '*' => array(
98
+ 'item_id',
99
+ 'parent_item_id',
100
+ 'categories',
101
+ 'qty',
102
+ 'base_price',
103
+ 'base_price_incl_tax',
104
+ 'name',
105
+ 'sku',
106
+ 'created_at',
107
+ 'updated_at',
108
+ 'product_id',
109
+ 'type_id',
110
+ 'url_path'
111
+ )
112
+ )
113
+ ),
114
+ 'order' => array(
115
+ 'rem_main_increment_id',
116
+ 'increment_id',
117
+ 'entity_id',
118
+ 'grand_total',
119
+ 'shipping_amount',
120
+ 'coupon_code',
121
+ 'created_at',
122
+ 'updated_at',
123
+ 'order_currency_code',
124
+ 'customer_id',
125
+ 'customer_is_guest',
126
+ 'customer_email',
127
+ 'customer_firstname',
128
+ 'customer_lastname',
129
+ 'customer_group_id',
130
+ 'customer_group',
131
+ 'state',
132
+ 'status',
133
+ 'address',
134
+ 'currency',
135
+ 'discount_amount',
136
+ 'customer_registered_to_newsletter',
137
+ 'payment_method',
138
+ 'items' => array(
139
+ '*' => array(
140
+ 'parent_item_id',
141
+ 'product_id',
142
+ 'qty_ordered',
143
+ 'base_price',
144
+ 'base_price_incl_tax',
145
+ 'sku',
146
+ 'name',
147
+ 'created_at',
148
+ 'updated_at',
149
+ 'thumbnail',
150
+ 'small_image',
151
+ 'categories',
152
+ 'type_id',
153
+ 'url_path'
154
+ )
155
+ )
156
+ ),
157
+ 'product' => array(
158
+ 'entity_id',
159
+ 'sku',
160
+ 'name',
161
+ 'created_at',
162
+ 'updated_at',
163
+ 'type_id',
164
+ 'thumbnail',
165
+ 'is_salable',
166
+ 'visibility',
167
+ 'categories',
168
+ 'small_image',
169
+ 'price',
170
+ 'special_price',
171
+ 'cost',
172
+ 'url_path',
173
+ 'is_in_stock',
174
+ 'parent_id'
175
+ )
176
+ );
177
+
178
+ private function _log($function, $status, $message, $data, $logLevel = null)
179
+ {
180
+ $logMsg = implode(REMARKETY_LOG_SEPARATOR, array($function, $status, $message, json_encode($data)));
181
+ // $force = ($status != REMARKETY_MGCONNECTOR_CALLED_STATUS);
182
+ if ($this->_sendLogInResponse)
183
+ $this->_log[] = $logLevel.": ".$logMsg;
184
+ Mage::log($logMsg, $logLevel, REMARKETY_LOG);
185
+ }
186
+
187
+ private function _debug($function, $status, $message, $data)
188
+ {
189
+ $logMsg = implode(REMARKETY_LOG_SEPARATOR, array($function, $status, $message, json_encode($data)));
190
+ // $force = ($status != REMARKETY_MGCONNECTOR_CALLED_STATUS);
191
+ if ($this->_sendLogInResponse)
192
+ $this->_log[] = Zend_Log::DEBUG.": ".$logMsg;
193
+ Mage::log($logMsg, Zend_Log::DEBUG, REMARKETY_LOG);
194
+ }
195
+
196
+ private function _wrapResponse($data, $status, $statusStr = null)
197
+ {
198
+ $ret = array();
199
+
200
+ $ret[REMARKETY_MGCONNECTOR_DATA] = $data;
201
+ $ret[REMARKETY_MGCONNECTOR_STATUS] = $status;
202
+ $ret[REMARKETY_MGCONNECTOR_ERROR] = $statusStr;
203
+ $ret[REMARKETY_MGCONNECTOR_EXT_VERSION] = (string)Mage::getConfig()->getNode()->modules->Remarkety_Mgconnector->version;
204
+ $ret[REMARKETY_MGCONNECTOR_MAGE_VERSION] = Mage::getVersion();
205
+ $ret[REMARKETY_EXECUTION_TIME] = (microtime(true) - $this->_startTime) * 1000;
206
+ if ($this->_sendLogInResponse)
207
+ $ret["log"] = $this->_log;
208
+ return $ret;
209
+ }
210
+
211
+ private function _store_views_in_group($group_id)
212
+ {
213
+ if (empty($group_id)) {
214
+ return array(-1);
215
+ } else {
216
+ $group = Mage::getModel('core/store_group')->load($group_id);
217
+ if (empty($group)) return array(-1);
218
+
219
+ $codes = array_keys($group->getStoreCodes());
220
+ return $codes;
221
+ }
222
+ }
223
+
224
+ private function _filter_output_data($data, $field_set = array())
225
+ {
226
+ if (empty($field_set)) return $data;
227
+
228
+ foreach (array_keys($data) as $key) {
229
+ if (isset($field_set[$key]) && is_array($field_set[$key])) {
230
+ $data[$key] = $this->_filter_output_data($data[$key], $field_set[$key]);
231
+ } else if (isset($field_set['*']) && is_array($field_set['*'])) {
232
+ $data[$key] = $this->_filter_output_data($data[$key], $field_set['*']);
233
+ } else {
234
+ if (!in_array($key, $field_set)) unset ($data[$key]);
235
+ }
236
+ }
237
+ return $data;
238
+ }
239
+
240
+ private function _productCategories(Mage_Catalog_Model_Product $product)
241
+ {
242
+ $categoryCollection = $product->getCategoryCollection()
243
+ ->addAttributeToSelect('name');
244
+
245
+ $categories = array();
246
+
247
+ foreach ($categoryCollection as $category) {
248
+ $categoryId = $category->getId();
249
+ if (!in_array($categoryId, $this->_categoriesToIgnore)) {
250
+ if (!array_key_exists($categoryId, $this->_categoryCache)) {
251
+ $pathInStore = array_reverse(explode(",", $category->getPathInStore()));
252
+ $parentCategories = $category->getParentCategories(); // Uses a single DB query
253
+ $categoryTree = array();
254
+ foreach ($pathInStore as $parentCategoryId) {
255
+ foreach ($parentCategories as $parentCategory) {
256
+ if (!in_array($parentCategoryId, $this->_categoriesToIgnore)) {
257
+ if ($parentCategory->getId() == $parentCategoryId) {
258
+ $parentCategoryName = $parentCategory->getName();
259
+ if (!empty($parentCategoryName) && !in_array($parentCategoryName, $categoryTree)) {
260
+ $categoryTree[] = $parentCategoryName;
261
+ }
262
+ }
263
+ }
264
+ }
265
+ }
266
+ $this->_categoryCache[$categoryId] = implode(" / ", $categoryTree);
267
+ }
268
+ $categories[] = $this->_categoryCache[$categoryId];
269
+ }
270
+ }
271
+
272
+ return $categories;
273
+ }
274
+
275
+ private function _currencyInfo($currencyCode)
276
+ {
277
+ $currencyInfo = array(
278
+ 'code' => Mage::app()->getLocale()->currency($currencyCode)->getShortName(),
279
+ 'name' => Mage::app()->getLocale()->currency($currencyCode)->getName(),
280
+ 'symbol' => Mage::app()->getLocale()->currency($currencyCode)->getSymbol()
281
+ );
282
+
283
+ return $currencyInfo;
284
+ }
285
+
286
+ public function __construct() {
287
+ $this->_startTime = microtime(true);
288
+ $collection = Mage::getModel('core/config_data')->getCollection();
289
+ $collection
290
+ ->getSelect()
291
+ ->where('path = ?', self::XPATH_CATEGORIES_TO_IGNORE);
292
+ foreach ($collection as $config) {
293
+ $this->_categoriesToIgnore = array_merge($this->_categoriesToIgnore, explode(",",$config->getValue()));
294
+ }
295
+ }
296
+
297
+ public function getSubscribers($mage_store_view_id = null, $limit = null, $page = null, $sinceId = null) {
298
+ register_shutdown_function('handleShutdown');
299
+ $ret = array();
300
+ $pageNumber = null;
301
+ $pageSize = null;
302
+ $myArgs = func_get_args();
303
+ try {
304
+ $this->_debug(__FUNCTION__, REMARKETY_MGCONNECTOR_CALLED_STATUS, null, $myArgs);
305
+ $ret = array();
306
+ $subscriberCollection = Mage::getModel('newsletter/subscriber')
307
+ ->getCollection()
308
+ ->addOrder('subscriber_id', 'ASC');
309
+
310
+ // Get only subscribers who are not shoppers
311
+ $subscriberCollection->addFieldToFilter('customer_id', array('eq' => 0));
312
+
313
+ $store_views = $this->_store_views_in_group($mage_store_view_id);
314
+ $subscriberCollection->addFieldToFilter('store_id', array('in' => $store_views));
315
+ if ($limit != null) {
316
+ $pageNumber = 1; // Note that page numbers begin at 1 in Magento
317
+ $pageSize = $limit;
318
+ }
319
+
320
+ if ($page != null) {
321
+ if (!is_null($pageSize)) {
322
+ $pageNumber = $page + 1; // Note that page numbers begin at 1 in Magento
323
+ }
324
+ }
325
+
326
+ if (!is_null($pageSize)) {
327
+ $subscriberCollection->setPageSize($pageSize)
328
+ ->setCurPage($pageNumber);
329
+ }
330
+
331
+ if (!empty($sinceId)) {
332
+ $subscriberCollection->addFieldToFilter('subscriber_id', array('gt' => (int)$sinceId));
333
+ }
334
+
335
+ foreach ($subscriberCollection as $subscriber) {
336
+ $subscriberData = $subscriber->toArray();
337
+
338
+ $subscriberData = $this->_filter_output_data($subscriberData, $this->response_mask['subscriber']);
339
+ $ret[] = $subscriberData;
340
+ }
341
+
342
+
343
+ $this->_debug(__FUNCTION__, REMARKETY_MGCONNECTOR_SUCCESS_STATUS, null, '');
344
+ return $this->_wrapResponse($ret, REMARKETY_MGCONNECTOR_SUCCESS_STATUS);
345
+ } catch (Mage_Core_Exception $e) {
346
+ $this->_log(__FUNCTION__, REMARKETY_MGCONNECTOR_FAILED_STATUS, $e->getMessage(), $myArgs);
347
+ return $this->_wrapResponse(null, REMARKETY_MGCONNECTOR_FAILED_STATUS, $e->getMessage());
348
+ } catch (Exception $e) {
349
+ $this->_log(__FUNCTION__, REMARKETY_MGCONNECTOR_FAILED_STATUS, $e->getMessage(), $myArgs);
350
+ return $this->_wrapResponse(null, REMARKETY_MGCONNECTOR_FAILED_STATUS, $e->getMessage());
351
+ }
352
+ }
353
+
354
+ public function getSubscriberCount($mage_store_view_id)
355
+ {
356
+ register_shutdown_function('handleShutdown');
357
+ $myArgs = func_get_args();
358
+
359
+ try {
360
+ $this->_debug(__FUNCTION__, REMARKETY_MGCONNECTOR_CALLED_STATUS, null, $myArgs);
361
+ $store_views = $this->_store_views_in_group($mage_store_view_id);
362
+
363
+ $subscriberCollection = Mage::getModel('newsletter/subscriber')
364
+ ->getCollection();
365
+
366
+ // Get only subscribers who are not shoppers
367
+ $subscriberCollection->addFieldToFilter('customer_id', array('eq' => 0));
368
+
369
+ $store_views = $this->_store_views_in_group($mage_store_view_id);
370
+ $subscriberCollection->addFieldToFilter('store_id', array('in' => $store_views));
371
+
372
+ $count = $subscriberCollection->getSize();
373
+ $ret = array('count' => $count);
374
+
375
+ $this->_debug(__FUNCTION__, REMARKETY_MGCONNECTOR_SUCCESS_STATUS, null, '');
376
+ return $this->_wrapResponse($ret, REMARKETY_MGCONNECTOR_SUCCESS_STATUS);
377
+ } catch (Mage_Core_Exception $e) {
378
+ $this->_log(__FUNCTION__, REMARKETY_MGCONNECTOR_FAILED_STATUS, $e->getMessage(), $myArgs);
379
+ return $this->_wrapResponse(null, REMARKETY_MGCONNECTOR_FAILED_STATUS, $e->getMessage());
380
+ } catch (Exception $e) {
381
+ $this->_log(__FUNCTION__, REMARKETY_MGCONNECTOR_FAILED_STATUS, $e->getMessage(), $myArgs);
382
+ return $this->_wrapResponse(null, REMARKETY_MGCONNECTOR_FAILED_STATUS, $e->getMessage());
383
+ }
384
+ }
385
+
386
+
387
+ public function getCustomers(
388
+ $mage_store_view_id,
389
+ $updated_at_min = null,
390
+ $updated_at_max = null,
391
+ $limit = null,
392
+ $page = null,
393
+ $since_id = null)
394
+ {
395
+ register_shutdown_function('handleShutdown');
396
+ $ret = array();
397
+ $pageNumber = null;
398
+ $pageSize = null;
399
+ $myArgs = func_get_args();
400
+
401
+ try {
402
+ $this->_debug(__FUNCTION__, REMARKETY_MGCONNECTOR_CALLED_STATUS, null, $myArgs);
403
+ $customersCollection = Mage::getModel("customer/customer")
404
+ ->getCollection()
405
+ ->addOrder('updated_at', 'ASC')
406
+ ->addAttributeToSelect('*');
407
+
408
+
409
+ // $customersCollection->addFieldToFilter('store_id', array('eq' => $mage_store_view_id));
410
+
411
+ $store = Mage::getModel('core/store')->load($mage_store_view_id);
412
+ $name= $store->getName();
413
+ // $viewName = Mage::getModel(""); XXX
414
+ $customersCollection->addFieldToFilter('store_id', array('eq' => $mage_store_view_id)); //$mage_store_id));
415
+ if ($updated_at_min != null) {
416
+ $customersCollection->addAttributeToFilter('updated_at', array('gt' => $updated_at_min));
417
+ }
418
+
419
+ if ($updated_at_max != null) {
420
+ $customersCollection->addAttributeToFilter('updated_at', array('lt' => $updated_at_max));
421
+ }
422
+
423
+ if ($since_id != null) {
424
+ $customersCollection->addAttributeToFilter('entity_id', array('gt' => $since_id));
425
+ }
426
+
427
+ if ($limit != null) {
428
+ $pageNumber = 1; // Note that page numbers begin at 1 in Magento
429
+ $pageSize = $limit;
430
+ }
431
+
432
+ if ($page != null) {
433
+ if (!is_null($pageSize)) {
434
+ $pageNumber = $page + 1; // Note that page numbers begin at 1 in Magento
435
+ }
436
+ }
437
+
438
+ if (!is_null($pageSize)) {
439
+ $customersCollection->setPage($pageNumber, $pageSize);
440
+ }
441
+
442
+ $subscriberModel = Mage::getModel("newsletter/subscriber");
443
+ $groupModel = Mage::getModel("customer/group");
444
+
445
+ /**
446
+ *
447
+ * Special code to exclude Amazon's group shoppers
448
+ * You can un-comment this code and change the group name ("amazon") to fit your needs
449
+ */
450
+ /*
451
+ $ignoredGroupIds = $this->getIgnoredGroupIds("amazon");
452
+ if (!empty($ignoredGroupIds))
453
+ $customersCollection->addAttributeToFilter("group_id", array("nin"=>$ignoredGroupIds));
454
+ */
455
+
456
+ foreach ($customersCollection as $customer) {
457
+ $customerData = $customer->toArray();
458
+
459
+ $subscriberModel->loadByCustomer($customer);
460
+ $customerData['registered_to_newsletter'] = $subscriberModel->isSubscribed();
461
+
462
+ $groupModel->load($customer->getGroupId());
463
+ $groupName = $groupModel->getCustomerGroupCode();
464
+ $customerData ['group_name'] = $groupName;
465
+ $customerData ['group_id'] = $customer->getGroupId();
466
+
467
+ $addresses_coll = $customer->getAddressesCollection();
468
+ $addresses_array = $addresses_coll->toArray();
469
+
470
+ if (is_array($addresses_array) && !empty($addresses_array)) {
471
+ if (in_array('default_billing', $customerData) && array_key_exists($customerData['default_billing'], $addresses_array)) {
472
+ $customerData['address_origin'] = 'billing';
473
+ $customerData['address'] = $addresses_array[$customerData['default_billing']];
474
+ } else if (in_array('default_shipping', $customerData) && array_key_exists($customerData['default_shipping'], $addresses_array)) {
475
+ $customerData['address_origin'] = 'shipping';
476
+ $customerData['address'] = $addresses_array[$customerData['default_shipping']];
477
+ } else {
478
+ $customerData['address_origin'] = 'first';
479
+ $customerData['address'] = array_shift($addresses_array);
480
+ }
481
+ }
482
+
483
+ $customerData = $this->_filter_output_data($customerData, $this->response_mask['customer']);
484
+ $ret[] = $customerData;
485
+ }
486
+
487
+ $this->_debug(__FUNCTION__, REMARKETY_MGCONNECTOR_SUCCESS_STATUS, null, '');
488
+ return $this->_wrapResponse($ret, REMARKETY_MGCONNECTOR_SUCCESS_STATUS);
489
+ } catch (Mage_Core_Exception $e) {
490
+ $this->_log(__FUNCTION__, REMARKETY_MGCONNECTOR_FAILED_STATUS, $e->getMessage(), $myArgs);
491
+ return $this->_wrapResponse(null, REMARKETY_MGCONNECTOR_FAILED_STATUS, $e->getMessage());
492
+ } catch (Exception $e) {
493
+ $this->_log(__FUNCTION__, REMARKETY_MGCONNECTOR_FAILED_STATUS, $e->getMessage(), $myArgs);
494
+ return $this->_wrapResponse(null, REMARKETY_MGCONNECTOR_FAILED_STATUS, $e->getMessage());
495
+ }
496
+ }
497
+
498
+ public function getOrders(
499
+ $mage_store_view_id,
500
+ $updated_at_min = null,
501
+ $updated_at_max = null,
502
+ $limit = null,
503
+ $page = null,
504
+ $since_id = null,
505
+ $created_at_min = null,
506
+ $created_at_max = null,
507
+ $order_status = null, // not implemented
508
+ $order_id = null
509
+ )
510
+ {
511
+
512
+ register_shutdown_function('handleShutdown');
513
+ $orders = array();
514
+ $pageNumber = null;
515
+ $pageSize = null;
516
+ $myArgs = func_get_args();
517
+
518
+ try {
519
+ $this->_debug(__FUNCTION__, REMARKETY_MGCONNECTOR_CALLED_STATUS, null, $myArgs);
520
+ $ordersCollection = Mage::getModel("sales/order")
521
+ ->getCollection()
522
+ ->addOrder('updated_at', 'ASC')
523
+ ->addAttributeToSelect('*');
524
+
525
+ // $store_views = $this->_store_views_in_group($mage_store_view_id);
526
+ // $ordersCollection->addFieldToFilter('store_id', array('in' => $store_views));
527
+ $ordersCollection->addFieldToFilter('main_table.store_id', array('eq' => $mage_store_view_id));
528
+ if ($updated_at_min != null) {
529
+ $ordersCollection->addAttributeToFilter('main_table.updated_at', array('gt' => $updated_at_min));
530
+ }
531
+
532
+ if ($updated_at_max != null) {
533
+ $ordersCollection->addAttributeToFilter('main_table.updated_at', array('lt' => $updated_at_max));
534
+ }
535
+
536
+ if ($since_id != null) {
537
+ $ordersCollection->addAttributeToFilter('main_table.entity_id', array('gt' => $since_id));
538
+ }
539
+
540
+ if ($created_at_min != null) {
541
+ $ordersCollection->addAttributeToFilter('main_table.created_at', array('gt' => $created_at_min));
542
+ }
543
+
544
+ if ($created_at_max != null) {
545
+ $ordersCollection->addAttributeToFilter('main_table.created_at', array('lt' => $created_at_max));
546
+ }
547
+
548
+ if ($order_id != null) {
549
+ $ordersCollection->addAttributeToFilter('main_table.entity_id', $order_id);
550
+ }
551
+
552
+ if ($limit != null) {
553
+ $pageNumber = 1; // Note that page numbers begin at 1
554
+ $pageSize = $limit;
555
+ }
556
+
557
+ if ($page != null) {
558
+ if (!is_null($pageSize)) {
559
+ $pageNumber = $page + 1; // Note that page numbers begin at 1
560
+ }
561
+ }
562
+
563
+ if (!is_null($pageSize)) {
564
+ $ordersCollection->setPage($pageNumber, $pageSize);
565
+ }
566
+
567
+ $subscriberModel = Mage::getModel("newsletter/subscriber");
568
+ $groupModel = Mage::getModel("customer/group");
569
+
570
+ /**
571
+ * Special code to exclude Amazon's group shoppers
572
+ * You can un-comment this code and change the group name ("amazon") to fit your needs
573
+ */
574
+ /*
575
+ $ignoredGroupIds = $this->getIgnoredGroupIds("amazon");
576
+ if (!empty($ignoredGroupIds))
577
+ $ordersCollection->addAttributeToFilter("customer_group_id", array("nin"=>$ignoredGroupIds));
578
+ */
579
+
580
+ $productIdsToLoad = array();
581
+ $orderIds = array();
582
+
583
+ foreach ($ordersCollection as $order) {
584
+ $orderData = $order->toArray();
585
+ if (!empty($orderData['relation_child_id'])) {
586
+ continue;
587
+ }
588
+ $orderIds[] = $orderData['entity_id'];
589
+ $orderData['rem_main_increment_id'] = (empty($orderData['original_increment_id'])) ? $orderData['increment_id'] : $orderData['original_increment_id'];
590
+ $orderData['currency'] = $this->_currencyInfo($orderData['order_currency_code']);
591
+
592
+ $subscriberModel->loadByEmail($orderData['customer_email']);
593
+ $orderData['customer_registered_to_newsletter'] = $subscriberModel->isSubscribed();
594
+
595
+ $addressID = null;
596
+
597
+ if (isset($orderData['billing_address_id']) && $orderData['billing_address_id']) {
598
+ $addressID = $orderData['billing_address_id'];
599
+ } elseif (isset($orderData['shipping_address_id']) && $orderData['shipping_address_id']) {
600
+ $addressID = $orderData['shipping_address_id'];
601
+ }
602
+
603
+ if (!empty($addressID)) {
604
+ $address = Mage::getModel('sales/order_address')->load($addressID)->toArray();
605
+ $orderData['address'] = $address;
606
+ }
607
+
608
+ $storeUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
609
+
610
+ $itemsCollection = $order->getItemsCollection();
611
+ // $itemsCollection->join(
612
+ //
613
+ // );
614
+ // $itemsCollection = $order->getAllVisibleItems();
615
+
616
+ foreach ($itemsCollection as $item) {
617
+ $product = null;
618
+
619
+ try {
620
+ $itemData = $item->toArray();
621
+ $productIdsToLoad[] = $itemData['product_id'];
622
+ /* The item data is loaded later and populated for performance reasons - get all the products at once instead of one-by-one in a loop */
623
+ $orderData['items'][$itemData['item_id']] = $itemData;
624
+
625
+ } catch (Exception $e) {
626
+ $this->_log(__FUNCTION__, 'Error in handling order items for order ID '.$orderData['entity_id'], $e->getMessage(), $myArgs);
627
+ }
628
+ }
629
+
630
+ $groupModel->load($orderData['customer_group_id']);
631
+ $groupName = $groupModel->getCustomerGroupCode();
632
+ $orderData['customer_group'] = $groupName;
633
+
634
+
635
+ $orders[] = $orderData;
636
+ }
637
+
638
+ //load all payment methods at once
639
+ $paymentMethods = $this->loadPaymentMethods($orderIds);
640
+
641
+ // Load the products all at once and populate the items
642
+ $this->loadProducts($mage_store_view_id, $productIdsToLoad);
643
+
644
+ $ret = array();
645
+ foreach ($orders as &$orderData) {
646
+ if (array_key_exists('items', $orderData)) {
647
+ foreach ($orderData['items'] as &$itemData) {
648
+ $product = $this->loadProduct($itemData['product_id']);
649
+ if (empty($product)) {
650
+ $this->debug("Could not load product, productID: ".$itemData['product_id']);
651
+ continue;
652
+ }
653
+
654
+ // $product->setStoreId($mage_store_view_id)->load($product->getId());
655
+ $itemData['thumbnail'] = $this->getImageUrl($product, 'image', $mage_store_view_id);
656
+ //$itemData['small_image'] = $this->getImageUrl($product, 'thumbnail', $mage_store_view_id);
657
+ $itemData['name'] = $this->getProductName($product, $mage_store_view_id);
658
+
659
+ $itemData['type_id'] = $product->getData('type_id');
660
+ //$itemData['categories'] = $this->_productCategories($product);
661
+ $prodUrl = $this->getProdUrl($product, $storeUrl, $mage_store_view_id);
662
+ $itemData['url_path'] = $prodUrl;
663
+ }
664
+ }
665
+ //set payment method
666
+ if(!empty($orderData['entity_id'])){
667
+ if(isset($paymentMethods[$orderData['entity_id']])){
668
+ $orderData['payment_method'] = $paymentMethods[$orderData['entity_id']];
669
+ }
670
+ }
671
+ $ret[] = $this->_filter_output_data($orderData, $this->response_mask['order']);
672
+ }
673
+
674
+ $this->_debug(__FUNCTION__, REMARKETY_MGCONNECTOR_SUCCESS_STATUS, null, '');
675
+ return $this->_wrapResponse($ret, REMARKETY_MGCONNECTOR_SUCCESS_STATUS);
676
+ } catch (Mage_Core_Exception $e) {
677
+ $this->_log(__FUNCTION__, REMARKETY_MGCONNECTOR_FAILED_STATUS, $e->getMessage(), $myArgs);
678
+ return $this->_wrapResponse(null, REMARKETY_MGCONNECTOR_FAILED_STATUS, $e->getMessage());
679
+ } catch (Exception $e) {
680
+ $this->_log(__FUNCTION__, REMARKETY_MGCONNECTOR_FAILED_STATUS, $e->getMessage(), $myArgs);
681
+ return $this->_wrapResponse(null, REMARKETY_MGCONNECTOR_FAILED_STATUS, $e->getMessage());
682
+ }
683
+ }
684
+
685
+ public function getQuotes(
686
+ $mage_store_view_id,
687
+ $updated_at_min = null,
688
+ $updated_at_max = null,
689
+ $limit = null,
690
+ $page = null,
691
+ $since_id = null)
692
+ {
693
+ register_shutdown_function('handleShutdown');
694
+ $pageNumber = null;
695
+ $pageSize = null;
696
+ $ret = array();
697
+ $myArgs = func_get_args();
698
+
699
+ try {
700
+ $quotesCollection = Mage::getResourceModel('reports/quote_collection');
701
+
702
+ // $quotesCollection->prepareForAbandonedReport($this->_storeIds);
703
+ $quotesCollection->addFieldToFilter('items_count', array('neq' => '0'))
704
+ ->addFieldToFilter('main_table.is_active', '1')
705
+ ->addSubtotal($this->_storeIds, null)
706
+ //->addCustomerData($filter)
707
+ ->setOrder('updated_at');
708
+ if (is_array($this->_storeIds)) {
709
+ $this->addFieldToFilter('store_id', array('in' => $this->_storeIds));
710
+ }
711
+
712
+ if ($updated_at_min != null) {
713
+ $quotesCollection->addFieldToFilter('main_table.updated_at', array('gt' => $updated_at_min));
714
+ }
715
+
716
+ if ($updated_at_max != null) {
717
+ $quotesCollection->addFieldToFilter('main_table.updated_at', array('lt' => $updated_at_max));
718
+ }
719
+
720
+ if ($since_id != null) {
721
+ $quotesCollection->addFieldToFilter('main_table.entity_id', array('gt' => $since_id));
722
+ }
723
+
724
+ if ($limit != null) {
725
+ $pageNumber = 1; // Note that page numbers begin at 1
726
+ $pageSize = $limit;
727
+ }
728
+
729
+ if ($page != null) {
730
+ if (!is_null($pageSize)) {
731
+ $pageNumber = $page + 1; // Note that page numbers begin at 1
732
+ }
733
+ }
734
+
735
+ if (!is_null($pageSize)){
736
+ $quotesCollection->setPageSize($pageSize)->setCurPage($pageNumber);
737
+ }
738
+
739
+ //$storeUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
740
+ $this->_debug(__FUNCTION__, " collection SQL: ".$quotesCollection->getSelect()->__toString(), null, null);
741
+
742
+ foreach ($quotesCollection as $quote) {
743
+ $this->_debug(__FUNCTION__, REMARKETY_MGCONNECTOR_CALLED_STATUS, "inside carts loop", null);
744
+ $quoteData = $quote->toArray();
745
+
746
+ if (empty($quoteData['customer_email']))
747
+ continue;
748
+
749
+ $currency = $quoteData['quote_currency_code'];
750
+ $quoteData['currency'] = $this->_currencyInfo($currency);
751
+
752
+ $quoteData['checkout_url'] = $this->getCartRecoveryURL($quoteData['entity_id']);
753
+
754
+ foreach ($quote->getItemsCollection() as $item) {
755
+ $quoteItem = array();
756
+
757
+ foreach ($this->response_mask['quote']['items']['*'] as $field) {
758
+ $quoteItem[$field] = $item->getData($field);
759
+ }
760
+ $_product = $this->loadProduct($quoteItem['product_id']);
761
+ //$_product->setStoreId($mage_store_view_id);
762
+ if (!empty($_product)) {
763
+ $quoteItem['type_id'] = $_product->getData('type_id');
764
+ }
765
+
766
+ //$quoteItem['categories'] = $this->_productCategories($_product);
767
+ //$prodUrl = $this->getProdUrl($_product, $storeUrl, $mage_store_view_id);
768
+ //$quoteItem['url_path'] = $prodUrl;
769
+
770
+ $quoteData['items'][$quoteItem['item_id']] = $quoteItem;
771
+ }
772
+
773
+ $quoteData = $this->_filter_output_data($quoteData, $this->response_mask['quote']);
774
+ if (!empty($quoteData['items'])) {
775
+ $ret[] = $quoteData;
776
+ }
777
+ }
778
+
779
+ $this->_debug(__FUNCTION__, REMARKETY_MGCONNECTOR_SUCCESS_STATUS, null, '');
780
+ return $this->_wrapResponse($ret, REMARKETY_MGCONNECTOR_SUCCESS_STATUS);
781
+ } catch (Mage_Core_Exception $e) {
782
+ $this->_log(__FUNCTION__, REMARKETY_MGCONNECTOR_FAILED_STATUS, $e->getMessage(), $myArgs);
783
+ return $this->_wrapResponse(null, REMARKETY_MGCONNECTOR_FAILED_STATUS, $e->getMessage());
784
+ } catch (Exception $e) {
785
+ $this->_log(__FUNCTION__, REMARKETY_MGCONNECTOR_FAILED_STATUS, $e->getMessage(), $myArgs);
786
+ return $this->_wrapResponse(null, REMARKETY_MGCONNECTOR_FAILED_STATUS, $e->getMessage());
787
+ }
788
+ }
789
+
790
+ public function getProducts(
791
+ $mage_store_id,
792
+ $updated_at_min = null,
793
+ $updated_at_max = null,
794
+ $limit = null,
795
+ $page = null,
796
+ $handle = null, // Not implemented
797
+ $vendor = null, // Not implemented
798
+ $product_type = null, // Not implemented
799
+ $collection_id = null, // Not implemented
800
+ $since_id = null,
801
+ $created_at_min = null,
802
+ $created_at_max = null,
803
+ $published_status = null, // Not implemented
804
+ $product_id = null)
805
+ {
806
+
807
+ register_shutdown_function('handleShutdown');
808
+ $pageNumber = null;
809
+ $pageSize = null;
810
+ $ret = array();
811
+ $myArgs = func_get_args();
812
+
813
+ try {
814
+ $this->_debug(__FUNCTION__, REMARKETY_MGCONNECTOR_CALLED_STATUS, null, $myArgs);
815
+ $productsCollection = Mage::getModel("catalog/product")
816
+ ->getCollection()
817
+ ->setStoreId($mage_store_id)
818
+ ->applyFrontendPriceLimitations()
819
+ ->addOrder('updated_at', 'ASC')
820
+ ->addFinalPrice()
821
+ ->addCategoryIds()
822
+ // ->addUrlRewrite()
823
+ ->addAttributeToSelect('*');
824
+
825
+ if ($updated_at_min != null) {
826
+ $productsCollection->addAttributeToFilter('updated_at', array('gt' => $updated_at_min));
827
+ }
828
+
829
+ if ($updated_at_max != null) {
830
+ $productsCollection->addAttributeToFilter('updated_at', array('lt' => $updated_at_max));
831
+ }
832
+
833
+ if ($since_id != null) {
834
+ $productsCollection->addAttributeToFilter('entity_id', array('gt' => $since_id));
835
+ }
836
+
837
+ if ($created_at_min != null) {
838
+ $productsCollection->addAttributeToFilter('created_at', array('gt' => $created_at_min));
839
+ }
840
+
841
+ if ($created_at_max != null) {
842
+ $productsCollection->addAttributeToFilter('created_at', array('lt' => $created_at_max));
843
+ }
844
+
845
+ if ($product_id != null) {
846
+ $productsCollection->addAttributeToFilter('entity_id', $product_id);
847
+ }
848
+
849
+ if ($limit != null) {
850
+ $pageNumber = 1; // Note that page numbers begin at 1
851
+ $pageSize = $limit;
852
+ }
853
+
854
+ if ($page != null) {
855
+ if (!is_null($pageSize)) {
856
+ $pageNumber = $page + 1; // Note that page numbers begin at 1
857
+ }
858
+ }
859
+
860
+ if (!is_null($pageSize)) $productsCollection->setPage($pageNumber, $pageSize);
861
+
862
+ $storeUrl = Mage::app()->getStore($mage_store_id)->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB, true);
863
+
864
+ $productIds = array();
865
+ foreach ($productsCollection as $product) {
866
+ $productIds[] = $product->getId();
867
+ }
868
+ $this->loadProducts($mage_store_id, $productIds);
869
+
870
+ foreach ($productsCollection as $product) {
871
+ // $product->setStoreId($mage_store_view_id)->load($product->getId());
872
+ $productData = $product->toArray();
873
+ $productData['thumbnail'] = $this->getImageUrl($product, 'image', $mage_store_id);
874
+
875
+ $productData['categories'] = $this->_productCategories($product);
876
+ $productData['price'] = $product->getFinalPrice();
877
+
878
+ $prodUrl = $this->getProdUrl($product, $storeUrl, $mage_store_id);
879
+ $productData['url_path'] = $prodUrl;
880
+ $productData['name'] = $this->getProductName($product, $mage_store_id);
881
+ $productData['is_salable'] = $product->isSalable();
882
+ $productData['visibility'] = $product->getVisibility();
883
+
884
+ /*
885
+ VISIBILITY_BOTH = 4
886
+ VISIBILITY_IN_CATALOG = 2
887
+ VISIBILITY_IN_SEARCH = 3
888
+ VISIBILITY_NOT_VISIBLE = 1
889
+ */
890
+
891
+ $parent_id = $this->getProductParentId($product);
892
+ if($parent_id !== false){
893
+ $productData['parent_id'] = $parent_id;
894
+ }
895
+
896
+ $productData = $this->_filter_output_data($productData, $this->response_mask['product']);
897
+ $ret[] = $productData;
898
+ }
899
+ $this->_debug(__FUNCTION__, REMARKETY_MGCONNECTOR_SUCCESS_STATUS, null, '');
900
+ return $this->_wrapResponse($ret, REMARKETY_MGCONNECTOR_SUCCESS_STATUS);
901
+ } catch (Mage_Core_Exception $e) {
902
+ $this->_log(__FUNCTION__, REMARKETY_MGCONNECTOR_FAILED_STATUS, $e->getMessage(), $myArgs);
903
+ return $this->_wrapResponse(null, REMARKETY_MGCONNECTOR_FAILED_STATUS, $e->getMessage());
904
+ } catch (Exception $e) {
905
+ $this->_log(__FUNCTION__, REMARKETY_MGCONNECTOR_FAILED_STATUS, $e->getMessage(), $myArgs);
906
+ return $this->_wrapResponse(null, REMARKETY_MGCONNECTOR_FAILED_STATUS, $e->getMessage());
907
+ }
908
+ }
909
+
910
+ private function getCategories($product) {
911
+ $categories = array();
912
+ $categoryCollection = $product->getCategoryCollection()->addAttributeToSelect('name');
913
+ foreach ($categoryCollection as $category) {
914
+ $categories[] = $category->getPath(); //getData('name');
915
+ }
916
+ return $categories;
917
+ }
918
+
919
+ public function getStoreSettings($mage_store_view_id = null)
920
+ {
921
+ register_shutdown_function('handleShutdown');
922
+ $myArgs = func_get_args();
923
+
924
+ try {
925
+ $this->_debug(__FUNCTION__, REMARKETY_MGCONNECTOR_CALLED_STATUS, null, $myArgs);
926
+
927
+ $currency = Mage::getStoreConfig('currency/options/default', $mage_store_view_id);
928
+ $currencySymbol = Mage::app()->getLocale()->currency($currency)->getSymbol();
929
+ $currencyFormat = Mage::getModel("directory/currency")->load($currency)->getOutputFormat();
930
+ $storeName = Mage::getStoreConfig('general/store_information/name', $mage_store_view_id);
931
+
932
+ $storeView = Mage::getModel('core/store');
933
+ $storeView->load($mage_store_view_id);
934
+ $storeGroup = $storeView->getGroup();
935
+ $storeViewName = $storeView->name;
936
+ $storeGroupName = $storeGroup->name;
937
+
938
+ if (empty($storeName)) {
939
+ $storeName = $storeGroupName;
940
+ }
941
+ $baseUrl = Mage::getStoreConfig('web/unsecure/base_url', $mage_store_view_id);
942
+ $storeUrl = $storeView->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);
943
+ $ret = array(
944
+ 'domain' => $baseUrl,
945
+ 'storeFrontUrl' => $storeUrl,
946
+ 'name' => $storeName,
947
+ 'viewName' => $storeViewName,
948
+ 'phone' => Mage::getStoreConfig('general/store_information/phone', $mage_store_view_id),
949
+ 'contactEmail' => Mage::getStoreConfig('contacts/email/recipient_email', $mage_store_view_id),
950
+ 'timezone' => Mage::getStoreConfig('general/locale/timezone', $mage_store_view_id),
951
+ 'locale' => Mage::getStoreConfig('general/locale/code', $mage_store_view_id),
952
+ 'address' => Mage::getStoreConfig('general/store_information/address', $mage_store_view_id),
953
+ 'country' => Mage::getStoreConfig('general/store_information/merchant_country', $mage_store_view_id),
954
+ 'currency' => $currency,
955
+ 'money_format' => $currencySymbol,
956
+ 'money_with_currency_format' => $currencyFormat
957
+ );
958
+
959
+ $wsCollection = Mage::getModel("core/website")->getCollection();
960
+ foreach ($wsCollection as $ws) {
961
+ $websiteArr = $ws->toArray();
962
+ $groups = $ws->getGroupCollection();
963
+ foreach ($groups as $group) {
964
+ $groupArr = $group->toArray();
965
+ $stores = $group->getStoreCollection();
966
+ foreach ($stores as $store) {
967
+ $groupArr['views'][] = $store->toArray();
968
+ }
969
+ $websiteArr['groups'][] = $groupArr;
970
+ }
971
+ $ret['websites'][] = $websiteArr;
972
+ }
973
+ $this->_debug(__FUNCTION__, REMARKETY_MGCONNECTOR_SUCCESS_STATUS, null, '');
974
+ return $this->_wrapResponse($ret, REMARKETY_MGCONNECTOR_SUCCESS_STATUS);
975
+ } catch (Mage_Core_Exception $e) {
976
+ $this->_log(__FUNCTION__, REMARKETY_MGCONNECTOR_FAILED_STATUS, $e->getMessage(), $myArgs);
977
+ return $this->_wrapResponse(null, REMARKETY_MGCONNECTOR_FAILED_STATUS, $e->getMessage());
978
+ } catch (Exception $e) {
979
+ $this->_log(__FUNCTION__, REMARKETY_MGCONNECTOR_FAILED_STATUS, $e->getMessage(), $myArgs);
980
+ return $this->_wrapResponse(null, REMARKETY_MGCONNECTOR_FAILED_STATUS, $e->getMessage());
981
+ }
982
+ }
983
+
984
+ public function getStoreOrderStatuses($mage_store_view_id)
985
+ {
986
+ register_shutdown_function('handleShutdown');
987
+ $myArgs = func_get_args();
988
+
989
+ try {
990
+ $this->_debug(__FUNCTION__, REMARKETY_MGCONNECTOR_CALLED_STATUS, null, $myArgs);
991
+ $statusesCollection = Mage::getModel('sales/order_status')->getCollection();
992
+ $ret = array();
993
+ foreach ($statusesCollection as $status) {
994
+ $newStat = array();
995
+ $newStat['status'] = $status->getData('status');
996
+ $newStat['label'] = $status->getStoreLabel($mage_store_view_id);
997
+ $ret[] = $newStat;
998
+ }
999
+ $this->_debug(__FUNCTION__, REMARKETY_MGCONNECTOR_SUCCESS_STATUS, null, '');
1000
+ return $this->_wrapResponse($ret, REMARKETY_MGCONNECTOR_SUCCESS_STATUS);
1001
+ } catch (Mage_Core_Exception $e) {
1002
+ $this->_log(__FUNCTION__, REMARKETY_MGCONNECTOR_FAILED_STATUS, $e->getMessage(), $myArgs);
1003
+ return $this->_wrapResponse(null, REMARKETY_MGCONNECTOR_FAILED_STATUS, $e->getMessage());
1004
+ } catch (Exception $e) {
1005
+ $this->_log(__FUNCTION__, REMARKETY_MGCONNECTOR_FAILED_STATUS, $e->getMessage(), $myArgs);
1006
+ return $this->_wrapResponse(null, REMARKETY_MGCONNECTOR_FAILED_STATUS, $e->getMessage());
1007
+ }
1008
+ }
1009
+
1010
+
1011
+ public function createCoupon($rule_id, $coupon_code, $expiration_date = null)
1012
+ {
1013
+ register_shutdown_function('handleShutdown');
1014
+ $myArgs = func_get_args();
1015
+
1016
+ try {
1017
+ $this->_debug(__FUNCTION__, REMARKETY_MGCONNECTOR_CALLED_STATUS, null, $myArgs);
1018
+ $rule = Mage::getModel('salesrule/rule')->load($rule_id);
1019
+
1020
+ if (empty($rule)) {
1021
+ $msg = 'Given promotion ID does not exist';
1022
+ $this->_debug(__FUNCTION__, REMARKETY_MGCONNECTOR_FAILED_STATUS, $msg, $myArgs);
1023
+ return $this->_wrapResponse(null, REMARKETY_MGCONNECTOR_FAILED_STATUS, $msg);
1024
+ }
1025
+
1026
+ if (!($rule->getUseAutoGeneration())) {
1027
+ $msg = 'Promotion not configured for multiple coupons generation';
1028
+ $this->_debug(__FUNCTION__, REMARKETY_MGCONNECTOR_FAILED_STATUS, $msg, $myArgs);
1029
+ return $this->_wrapResponse(null, REMARKETY_MGCONNECTOR_FAILED_STATUS, $msg);
1030
+ }
1031
+
1032
+ $coupon = Mage::getModel('salesrule/coupon')
1033
+ ->setRule($rule)
1034
+ ->setIsPrimary(false)
1035
+ ->setCode($coupon_code)
1036
+ ->setAddedByRemarkety(1)
1037
+ ->setUsageLimit($rule->getUsesPerCoupon())
1038
+ ->setUsagePerCustomer($rule->getUsesPerCustomer())
1039
+ ->setType(Mage_SalesRule_Helper_Coupon::COUPON_TYPE_SPECIFIC_AUTOGENERATED);
1040
+
1041
+ if ($expiration_date != null) {
1042
+ $coupon->setExpirationDate($expiration_date);
1043
+ } else {
1044
+ $coupon->setExpirationDate($rule->getToDate());
1045
+ }
1046
+
1047
+ $coupon->save();
1048
+
1049
+ $msg = "Successfuly created coupon code: " . $coupon_code . " for rule id: " . $rule_id;
1050
+ $this->_log(__FUNCTION__, REMARKETY_MGCONNECTOR_SUCCESS_STATUS, $msg, $myArgs);
1051
+ return $this->_wrapResponse(null, REMARKETY_MGCONNECTOR_SUCCESS_STATUS);
1052
+ } catch (Mage_Core_Exception $e) {
1053
+ $this->_log(__FUNCTION__, REMARKETY_MGCONNECTOR_FAILED_STATUS, $e->getMessage(), $myArgs);
1054
+ return $this->_wrapResponse(null, REMARKETY_MGCONNECTOR_FAILED_STATUS, $e->getMessage());
1055
+ } catch (Exception $e) {
1056
+ $this->_log(__FUNCTION__, REMARKETY_MGCONNECTOR_FAILED_STATUS, $e->getMessage(), $myArgs);
1057
+ return $this->_wrapResponse(null, REMARKETY_MGCONNECTOR_FAILED_STATUS, $e->getMessage());
1058
+ }
1059
+ }
1060
+
1061
+ public function getCustomersCount($mage_store_view_id)
1062
+ {
1063
+ register_shutdown_function('handleShutdown');
1064
+ $myArgs = func_get_args();
1065
+
1066
+ try {
1067
+ $this->_debug(__FUNCTION__, REMARKETY_MGCONNECTOR_CALLED_STATUS, null, $myArgs);
1068
+ $store_views = $this->_store_views_in_group($mage_store_view_id);
1069
+ $customers = Mage::getModel("customer/customer")->getCollection();
1070
+ $customers->addFieldToFilter('store_id', array('in' => $store_views));
1071
+ $count = $customers->getSize();
1072
+ $ret = array('count' => $count);
1073
+
1074
+ $this->_debug(__FUNCTION__, REMARKETY_MGCONNECTOR_SUCCESS_STATUS, null, '');
1075
+ return $this->_wrapResponse($ret, REMARKETY_MGCONNECTOR_SUCCESS_STATUS);
1076
+ } catch (Mage_Core_Exception $e) {
1077
+ $this->_log(__FUNCTION__, REMARKETY_MGCONNECTOR_FAILED_STATUS, $e->getMessage(), $myArgs);
1078
+ return $this->_wrapResponse(null, REMARKETY_MGCONNECTOR_FAILED_STATUS, $e->getMessage());
1079
+ } catch (Exception $e) {
1080
+ $this->_log(__FUNCTION__, REMARKETY_MGCONNECTOR_FAILED_STATUS, $e->getMessage(), $myArgs);
1081
+ return $this->_wrapResponse(null, REMARKETY_MGCONNECTOR_FAILED_STATUS, $e->getMessage());
1082
+ }
1083
+ }
1084
+
1085
+ public function getOrdersCount($mage_store_view_id)
1086
+ {
1087
+ register_shutdown_function('handleShutdown');
1088
+ $myArgs = func_get_args();
1089
+
1090
+ try {
1091
+ $this->_debug(__FUNCTION__, REMARKETY_MGCONNECTOR_CALLED_STATUS, null, $myArgs);
1092
+ // $store_views = $this->_store_views_in_group($mage_store_view_id);
1093
+ $orders = Mage::getModel("sales/order")->getCollection();
1094
+ $orders->addFieldToFilter('store_id', array('eq' => $mage_store_view_id));
1095
+ $count = $orders->getSize();
1096
+ $ret = array('count' => $count);
1097
+
1098
+ $this->_debug(__FUNCTION__, REMARKETY_MGCONNECTOR_SUCCESS_STATUS, null, '');
1099
+ return $this->_wrapResponse($ret, REMARKETY_MGCONNECTOR_SUCCESS_STATUS);
1100
+ } catch (Mage_Core_Exception $e) {
1101
+ $this->_log(__FUNCTION__, REMARKETY_MGCONNECTOR_FAILED_STATUS, $e->getMessage(), $myArgs);
1102
+ return $this->_wrapResponse(null, REMARKETY_MGCONNECTOR_FAILED_STATUS, $e->getMessage());
1103
+ } catch (Exception $e) {
1104
+ $this->_log(__FUNCTION__, REMARKETY_MGCONNECTOR_FAILED_STATUS, $e->getMessage(), $myArgs);
1105
+ return $this->_wrapResponse(null, REMARKETY_MGCONNECTOR_FAILED_STATUS, $e->getMessage());
1106
+ }
1107
+ }
1108
+
1109
+ public function getProductsCount($mage_view_id)
1110
+ {
1111
+ register_shutdown_function('handleShutdown');
1112
+ $myArgs = func_get_args();
1113
+
1114
+ try {
1115
+ $this->_debug(__FUNCTION__, REMARKETY_MGCONNECTOR_CALLED_STATUS, null, $myArgs);
1116
+ $products = Mage::getModel("catalog/product")->getCollection();
1117
+ $products->addStoreFilter($mage_view_id);
1118
+ $count = $products->getSize();
1119
+ $ret = array('count' => $count);
1120
+
1121
+ $this->_debug(__FUNCTION__, REMARKETY_MGCONNECTOR_SUCCESS_STATUS, null, '');
1122
+ return $this->_wrapResponse($ret, REMARKETY_MGCONNECTOR_SUCCESS_STATUS);
1123
+ } catch (Mage_Core_Exception $e) {
1124
+ $this->_log(__FUNCTION__, REMARKETY_MGCONNECTOR_FAILED_STATUS, $e->getMessage(), $myArgs);
1125
+ return $this->_wrapResponse(null, REMARKETY_MGCONNECTOR_FAILED_STATUS, $e->getMessage());
1126
+ }
1127
+ }
1128
+
1129
+ public function getProductParentId($product){
1130
+ if ($product->type_id != 'configurable') {
1131
+ $arrayOfParentIds = Mage::helper('mgconnector/links')->getParentId($product->getId());
1132
+ $parentId = null;
1133
+
1134
+ if($arrayOfParentIds && count($arrayOfParentIds)) {
1135
+ if(is_array($arrayOfParentIds)) {
1136
+ $parentId = $arrayOfParentIds[0];
1137
+ } else {
1138
+ $parentId = $arrayOfParentIds;
1139
+ }
1140
+ }
1141
+
1142
+ if (!is_null($parentId)) {
1143
+ return $parentId;
1144
+ }
1145
+ }
1146
+ return false;
1147
+ }
1148
+
1149
+ public function getProdUrl($product, $storeUrl, $mage_store_view_id)
1150
+ {
1151
+ $this->_debug(__FUNCTION__, "Start - prod id ".$product->getId(), null, '');
1152
+ $url = '';
1153
+ $visibility = $product->getVisibility();
1154
+ if ($product->type_id != 'configurable' || $visibility == 1) {
1155
+ $arrayOfParentIds = Mage::helper('mgconnector/links')->getParentId($product->getId());
1156
+ $parentId = null;
1157
+
1158
+ if($arrayOfParentIds && count($arrayOfParentIds)) {
1159
+ if(is_array($arrayOfParentIds)) {
1160
+ $parentId = $arrayOfParentIds[0];
1161
+ } else {
1162
+ $parentId = $arrayOfParentIds;
1163
+ }
1164
+ }
1165
+
1166
+ if (!is_null($parentId)) {
1167
+ $this->_debug(__FUNCTION__, "parent id ".$parentId, null, '');
1168
+ $product_id = $parentId;
1169
+ } else {
1170
+ $product_id = $product->getId();
1171
+ }
1172
+ } else {
1173
+ $product_id = $product->getId();
1174
+ }
1175
+
1176
+ try{
1177
+ $url = Mage::helper('mgconnector/urls')->getValue($product_id, $mage_store_view_id);
1178
+ if(!empty($url)) {
1179
+ $url = $storeUrl . $url;
1180
+ if(Mage::getStoreConfig('catalog/seo/product_url_suffix', $mage_store_view_id)) {
1181
+ $url .= Mage::getStoreConfig('catalog/seo/product_url_suffix', $mage_store_view_id);
1182
+ }
1183
+ }
1184
+ $this->_debug(__FUNCTION__, "after setStoreId getProductUrl: ".$url, null, '');
1185
+ }catch(Exception $e){
1186
+ $this->_log(__FUNCTION__, "failed after setStoreId: ", $e->getMessage(), '');
1187
+ }
1188
+
1189
+ if(!empty($url)) {
1190
+ return $url;
1191
+ } else {
1192
+ $getProductUrl = $product->getProductUrl();
1193
+ $this->_debug(__FUNCTION__, "getProductUrl: ".$getProductUrl, null, '');
1194
+ return $getProductUrl;
1195
+ }
1196
+
1197
+ }
1198
+
1199
+ public function getImageUrl($product, $type = 'image', $mage_store_view_id)
1200
+ {
1201
+ $url = '';
1202
+ if ($product->type_id != 'configurable') {
1203
+ $this->_debug(__FUNCTION__, null, "not config prod id" . $product->getId(), '');
1204
+ $arrayOfParentIds = Mage::helper('mgconnector/links')->getParentId($product->getId());
1205
+ $parentId = null;
1206
+
1207
+ if($arrayOfParentIds && count($arrayOfParentIds)) {
1208
+ if(is_array($arrayOfParentIds)) {
1209
+ $parentId = $arrayOfParentIds[0];
1210
+ } else {
1211
+ $parentId = $arrayOfParentIds;
1212
+ }
1213
+ }
1214
+
1215
+ if (!is_null($parentId)) {
1216
+ $this->_debug(__FUNCTION__, null, "parent id: ".$parentId, '');
1217
+ $product = $this->loadProduct($parentId, $mage_store_view_id);
1218
+ }
1219
+ } else {
1220
+ $this->_debug(__FUNCTION__, null, "configurable prod id" . $product->getId(), '');
1221
+ }
1222
+ $this->_debug(__FUNCTION__, null, "Getting image url for product: " . $product->getId(), '');
1223
+ $url = (string)Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'catalog/product' . $product->getImage();
1224
+ // $url = (string)Mage::helper('catalog/image')->init($product, $type);
1225
+ $this->_debug(__FUNCTION__, null, $type . " url: " . $url, '');
1226
+ return $url;
1227
+
1228
+ }
1229
+
1230
+ public function getCartRecoveryURL($cart_id){
1231
+ $recovery = Mage::getModel('mgconnector/recovery');
1232
+ $id = $recovery->encodeQuoteId($cart_id);
1233
+ $url = (string)Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK) . 'remarkety/recovery/cart/quote_id/' . $id;
1234
+ return $url;
1235
+ }
1236
+
1237
+ private function getProductName($product, $mage_store_view_id){
1238
+ $name = '';
1239
+ if($product->type_id != 'configurable') {
1240
+ $this->_debug(__FUNCTION__, null, "not config prod id ".$product->getId(), '');
1241
+ $arrayOfParentIds = Mage::helper('mgconnector/links')->getParentId($product->getId());
1242
+ $parentId = null;
1243
+
1244
+ if($arrayOfParentIds && count($arrayOfParentIds)) {
1245
+ if(is_array($arrayOfParentIds)) {
1246
+ $parentId = $arrayOfParentIds[0];
1247
+ } else {
1248
+ $parentId = $arrayOfParentIds;
1249
+ }
1250
+ }
1251
+
1252
+ if(!is_null($parentId)){
1253
+ $this->_debug(__FUNCTION__, null, "parent id: ".$parentId, '');
1254
+ $product = $this->loadProduct($parentId);
1255
+ // $product->setStoreId($mage_store_view_id)->load($parentId);
1256
+ //$product->setStoreId($mage_store_view_id);
1257
+ }
1258
+ }else{
1259
+ $this->_debug(__FUNCTION__, null, "configurable prod id ".$product->getId(), '');
1260
+ }
1261
+
1262
+ $name = $product->getName();
1263
+ $this->_debug(__FUNCTION__, null, "Prod name: ".$name, '');
1264
+ return $name;
1265
+ }
1266
+
1267
+ public function unsubscribe($email)
1268
+ {
1269
+ register_shutdown_function('handleShutdown');
1270
+ $myArgs = func_get_args();
1271
+
1272
+ try {
1273
+ if (empty($email)) {
1274
+ $msg = 'No email sent passed to unsubsribe';
1275
+ $this->_debug(__FUNCTION__, REMARKETY_MGCONNECTOR_FAILED_STATUS, $msg, $myArgs);
1276
+ return $this->_wrapResponse(null, REMARKETY_MGCONNECTOR_FAILED_STATUS, $msg);
1277
+ }
1278
+
1279
+ $this->_debug(__FUNCTION__, REMARKETY_MGCONNECTOR_CALLED_STATUS, null, $myArgs);
1280
+ $subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($email);
1281
+
1282
+ if (empty($subscriber)) {
1283
+ $msg = 'Given subscriber does not exist';
1284
+ $this->_debug(__FUNCTION__, REMARKETY_MGCONNECTOR_FAILED_STATUS, $msg, $myArgs);
1285
+ return $this->_wrapResponse(null, REMARKETY_MGCONNECTOR_FAILED_STATUS, $msg);
1286
+ }
1287
+ Mage::register('remarkety_subscriber_deleted',true, true);
1288
+ $subscriber->unsubscribe();
1289
+
1290
+ $msg = "Successfuly unsubscribed customer using email: " . $email;
1291
+ $this->_debug(__FUNCTION__, REMARKETY_MGCONNECTOR_SUCCESS_STATUS, $msg, $myArgs);
1292
+ return $this->_wrapResponse(null, REMARKETY_MGCONNECTOR_SUCCESS_STATUS);
1293
+ } catch (Mage_Core_Exception $e) {
1294
+ $this->_log(__FUNCTION__, REMARKETY_MGCONNECTOR_FAILED_STATUS, $e->getMessage(), $myArgs);
1295
+ return $this->_wrapResponse(null, REMARKETY_MGCONNECTOR_FAILED_STATUS, $e->getMessage());
1296
+ } catch (Exception $e) {
1297
+ $this->_log(__FUNCTION__, REMARKETY_MGCONNECTOR_FAILED_STATUS, $e->getMessage(), $myArgs);
1298
+ return $this->_wrapResponse(null, REMARKETY_MGCONNECTOR_FAILED_STATUS, $e->getMessage());
1299
+ }
1300
+ }
1301
+
1302
+ private function getConfigProdModel()
1303
+ {
1304
+ if ($this->configurable_product_model == null) {
1305
+ $this->configurable_product_model = Mage::getModel('catalog/product_type_configurable');
1306
+ }
1307
+ return $this->configurable_product_model;
1308
+ }
1309
+
1310
+ private function loadProduct($productId) {
1311
+ if (!isset($this->_productCache[$productId])) {
1312
+ $this->_productCache[$productId] = Mage::getModel("catalog/product")->load($productId);
1313
+ }
1314
+ return $this->_productCache[$productId];
1315
+ }
1316
+
1317
+ /**
1318
+ * Returns a list of payment methods used in each order
1319
+ * @param $orderIds
1320
+ * @return array
1321
+ */
1322
+ private function loadPaymentMethods($orderIds){
1323
+
1324
+ $orderIds = array_unique($orderIds);
1325
+ $paymentsCollection = Mage::getModel("sales/order_payment")
1326
+ ->getCollection()
1327
+ ->addOrder('main_table.entity_id', 'DESC')
1328
+ ->addAttributeToFilter('main_table.parent_id', array('in' => $orderIds))
1329
+ ->addAttributeToSelect('parent_id')
1330
+ ->addAttributeToSelect('method');
1331
+
1332
+ $payments = array();
1333
+ $paymentMethodsNames = array();
1334
+
1335
+ foreach($paymentsCollection as $payment){
1336
+ $row = $payment->toArray();
1337
+ if(!isset($payments[$row['parent_id']])){
1338
+ $method = $row['method'];
1339
+ //convert method code to name
1340
+ if(!isset($paymentMethodsNames[$method])){
1341
+ $methodName = Mage::getStoreConfig('payment/'.$method.'/title');
1342
+ if(!empty($methodName)){
1343
+ $paymentMethodsNames[$method] = $methodName;
1344
+ } else {
1345
+ $paymentMethodsNames[$method] = $method;
1346
+ }
1347
+ }
1348
+ //save to list with order id as key
1349
+ $payments[$row['parent_id']] = $paymentMethodsNames[$method];
1350
+ }
1351
+ }
1352
+
1353
+ return $payments;
1354
+ }
1355
+
1356
+ private function loadProducts($storeId, $productIds, $loadParents = true) {
1357
+ if (empty($productIds))
1358
+ return;
1359
+ $productIds = array_unique($productIds);
1360
+ $productsCollection = Mage::getModel("catalog/product")
1361
+ ->getCollection()
1362
+ ->setStoreId($storeId)
1363
+ ->addFieldToFilter('entity_id', array($productIds))
1364
+ ->applyFrontendPriceLimitations()
1365
+ ->addOrder('updated_at', 'ASC')
1366
+ ->addFinalPrice()
1367
+ ->addCategoryIds()
1368
+ // ->addUrlRewrite()
1369
+ ->addAttributeToSelect('*');
1370
+ $productsCollection->load(false,true);
1371
+ $parentIds = array();
1372
+ foreach ($productsCollection as $product) {
1373
+ $productId = $product->getId();
1374
+ if (!array_key_exists($productId, $this->_productCache)) {
1375
+ $this->_productCache[$productId] = $product; //Mage::getModel("catalog/product")->load($productId);
1376
+ if ($loadParents)
1377
+ $parentIds[] = $this->getProductParentId($product);
1378
+ }
1379
+ }
1380
+ if ($loadParents)
1381
+ $this->loadProducts($storeId, $parentIds, false);
1382
+ }
1383
+
1384
+ public function sendLogInResponse() {
1385
+ $this->_sendLogInResponse = true;
1386
+ }
1387
+ }
1388
+
1389
+
1390
+ function handleShutdown()
1391
+ {
1392
+ $error = error_get_last();
1393
+ if ($error !== NULL) {
1394
+ $error_info = "[SHUTDOWN] file:" . $error['file'] . " | ln:" . $error['line'] . " | msg:" . $error['message'] . PHP_EOL;
1395
+ Mage::log($error_info, null, REMARKETY_LOG, true);
1396
+ } else {
1397
+ Mage::log("SHUTDOWN", null, REMARKETY_LOG);
1398
+ }
1399
+ }
app/code/community/Remarkety/Mgconnector/Model/Core/Api.php ADDED
@@ -0,0 +1,211 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @copyright Copyright (C) 2014 InteraMind Ltd (Remarkety). All rights reserved.
5
+ * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
6
+ * @package This file is part of Magento Connector Plugin for Remarkety
7
+ **/
8
+ class Remarkety_Mgconnector_Model_Core_Api
9
+ {
10
+ public function getCustomers(
11
+ $mage_store_group_id,
12
+ $updated_at_min = null,
13
+ $updated_at_max = null,
14
+ $limit = null,
15
+ $page = null,
16
+ $since_id = null,
17
+ $returnLog = 0)
18
+ {
19
+
20
+ $myModel = Mage::getModel("mgconnector/core");
21
+ if ($returnLog)
22
+ $myModel->sendLogInResponse();
23
+
24
+ return $myModel->getCustomers(
25
+ $mage_store_group_id,
26
+ $updated_at_min,
27
+ $updated_at_max,
28
+ $limit,
29
+ $page,
30
+ $since_id);
31
+ }
32
+
33
+ public function getOrders(
34
+ $mage_store_group_id,
35
+ $updated_at_min = null,
36
+ $updated_at_max = null,
37
+ $limit = null,
38
+ $page = null,
39
+ $since_id = null,
40
+ $created_at_min = null,
41
+ $created_at_max = null,
42
+ $order_status = null, // Not implemented
43
+ $order_id = null,
44
+ $returnLog = 0)
45
+ {
46
+
47
+ $myModel = Mage::getModel("mgconnector/core");
48
+ if ($returnLog)
49
+ $myModel->sendLogInResponse();
50
+
51
+ return $myModel->getOrders(
52
+ $mage_store_group_id,
53
+ $updated_at_min,
54
+ $updated_at_max,
55
+ $limit,
56
+ $page,
57
+ $since_id,
58
+ $created_at_min,
59
+ $created_at_max,
60
+ $order_status, // Not implemented
61
+ $order_id);
62
+ }
63
+
64
+ public function getQuotes(
65
+ $mage_store_group_id,
66
+ $updated_at_min = null,
67
+ $updated_at_max = null,
68
+ $limit = null,
69
+ $page = null,
70
+ $since_id = null,
71
+ $returnLog = 0)
72
+ {
73
+
74
+ $myModel = Mage::getModel("mgconnector/core");
75
+ if ($returnLog)
76
+ $myModel->sendLogInResponse();
77
+
78
+ return $myModel->getQuotes(
79
+ $mage_store_group_id,
80
+ $updated_at_min,
81
+ $updated_at_max,
82
+ $limit,
83
+ $page,
84
+ $since_id);
85
+ }
86
+
87
+ public function getProducts(
88
+ $mage_store_view_id,
89
+ $updated_at_min = null,
90
+ $updated_at_max = null,
91
+ $limit = null,
92
+ $page = null,
93
+ $handle = null, // Not implemented
94
+ $vendor = null, // Not implemented
95
+ $product_type = null, // Not implemented
96
+ $collection_id = null, // Not implemented
97
+ $since_id = null,
98
+ $created_at_min = null,
99
+ $created_at_max = null,
100
+ $published_status = null, // Not implemented
101
+ $product_id = null,
102
+ $returnLog = 0)
103
+ {
104
+
105
+ $myModel = Mage::getModel("mgconnector/core");
106
+ if ($returnLog)
107
+ $myModel->sendLogInResponse();
108
+ return $myModel->getProducts(
109
+ $mage_store_view_id,
110
+ $updated_at_min,
111
+ $updated_at_max,
112
+ $limit,
113
+ $page,
114
+ $handle,
115
+ $vendor,
116
+ $product_type,
117
+ $collection_id,
118
+ $since_id,
119
+ $created_at_min,
120
+ $created_at_max,
121
+ $published_status,
122
+ $product_id,
123
+ $returnLog);
124
+ }
125
+
126
+ public function getSubscribers($mage_store_view_id = null,
127
+ $limit = null,
128
+ $page = null,
129
+ $sinceId = null,
130
+ $returnLog = 0)
131
+ {
132
+ $myModel = Mage::getModel("mgconnector/core");
133
+ if ($returnLog)
134
+ $myModel->sendLogInResponse();
135
+
136
+ return $myModel->getSubscribers(
137
+ $mage_store_view_id,
138
+ $limit,
139
+ $page,
140
+ $sinceId);
141
+ }
142
+
143
+ public function getSubscriberCount($mage_store_view_id = null, $returnLog = 0)
144
+ {
145
+
146
+ $myModel = Mage::getModel("mgconnector/core");
147
+ if ($returnLog)
148
+ $myModel->sendLogInResponse();
149
+
150
+ return $myModel->getSubscriberCount($mage_store_view_id);
151
+ }
152
+
153
+ public function getStoreSettings($mage_store_view_id = null, $returnLog = 0)
154
+ {
155
+ $myModel = Mage::getModel("mgconnector/core");
156
+ if ($returnLog)
157
+ $myModel->sendLogInResponse();
158
+ return $myModel->getStoreSettings($mage_store_view_id);
159
+ }
160
+
161
+ public function getStoreOrderStatuses($mage_store_view_id, $returnLog = 0)
162
+ {
163
+ $myModel = Mage::getModel("mgconnector/core");
164
+ if ($returnLog)
165
+ $myModel->sendLogInResponse();
166
+ return $myModel->getStoreOrderStatuses($mage_store_view_id);
167
+ }
168
+
169
+ public function createCoupon($rule_id, $coupon_code, $expiration, $returnLog = 0)
170
+ {
171
+ $myModel = Mage::getModel("mgconnector/core");
172
+ if ($returnLog)
173
+ $myModel->sendLogInResponse();
174
+ $ret = $myModel->createCoupon($rule_id, $coupon_code, $expiration);
175
+ return $ret;
176
+ }
177
+
178
+ public function unsubscribe($email, $returnLog = 0)
179
+ {
180
+ $myModel = Mage::getModel('mgconnector/core');
181
+ if ($returnLog)
182
+ $myModel->sendLogInResponse();
183
+ $ret = $myModel->unsubscribe($email);
184
+ return $ret;
185
+ }
186
+
187
+ public function getCustomersCount($mage_store_group_id, $returnLog = 0)
188
+ {
189
+ $myModel = Mage::getModel("mgconnector/core");
190
+ if ($returnLog)
191
+ $myModel->sendLogInResponse();
192
+ return $myModel->getCustomersCount($mage_store_group_id);
193
+ }
194
+
195
+ public function getOrdersCount($mage_store_group_id, $returnLog = 0)
196
+ {
197
+ $myModel = Mage::getModel("mgconnector/core");
198
+ if ($returnLog)
199
+ $myModel->sendLogInResponse();
200
+ return $myModel->getOrdersCount($mage_store_group_id);
201
+ }
202
+
203
+ public function getProductsCount($mage_view_id, $returnLog = 0)
204
+ {
205
+ $myModel = Mage::getModel("mgconnector/core");
206
+ if ($returnLog)
207
+ $myModel->sendLogInResponse();
208
+ $ret = $myModel->getProductsCount($mage_view_id);
209
+ return $ret;
210
+ }
211
+ }
app/code/community/Remarkety/Mgconnector/Model/Install.php ADDED
@@ -0,0 +1,484 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Install model
5
+ *
6
+ * @category Remarkety
7
+ * @package Remarkety_Mgconnector
8
+ * @author Piotr Pierzak <piotrek.pierzak@gmail.com>
9
+ */
10
+ class Remarkety_Mgconnector_Model_Install
11
+ {
12
+ /**
13
+ * Upgrade mode code
14
+ */
15
+ const MODE_UPGRADE = 'upgrade';
16
+
17
+ /**
18
+ * Install create mode code
19
+ */
20
+ const MODE_INSTALL_CREATE = 'install_create';
21
+
22
+ /**
23
+ * Install login mode code
24
+ */
25
+ const MODE_INSTALL_LOGIN = 'install_login';
26
+
27
+ /**
28
+ * Completed mode code
29
+ */
30
+ const MODE_COMPLETE = 'complete';
31
+
32
+ /**
33
+ * Welcome mode code
34
+ */
35
+ const MODE_WELCOME = 'welcome';
36
+
37
+ /**
38
+ * Web service remarkety username
39
+ */
40
+ const WEB_SERVICE_USERNAME = 'remarkety';
41
+
42
+ /**
43
+ * Web service role name
44
+ */
45
+ const WEB_SERVICE_ROLE = 'remarkety';
46
+
47
+ /**
48
+ * Store code scope
49
+ */
50
+ const STORE_SCOPE = 'stores';
51
+
52
+ /**
53
+ * Key in config for installed flag
54
+ */
55
+ const XPATH_INSTALLED = 'remarkety/mgconnector/installed';
56
+
57
+ /**
58
+ * Install data
59
+ *
60
+ * @var array
61
+ */
62
+ protected $_data = null;
63
+
64
+ /**
65
+ * Set data
66
+ *
67
+ * @param array $data
68
+ * @return Remarkety_Mgconnector_Model_Install
69
+ */
70
+ public function setData(array $data)
71
+ {
72
+ $this->_data['mode'] = $data['mode'];
73
+ $this->_data['email']= array_key_exists('email', $data) ? $data['email'] : null;
74
+ $this->_data['first_name']= array_key_exists('first_name', $data) ? $data['first_name'] : null;
75
+ $this->_data['last_name']= array_key_exists('last_name', $data) ? $data['last_name'] : null;
76
+ $this->_data['phone']= array_key_exists('phone', $data) ? $data['phone'] : null;
77
+ $this->_data['password']= array_key_exists('password', $data) ? $data['password'] : null;
78
+ $this->_data['terms'] = array_key_exists('terms', $data) ? ($data['terms']== '1' ? 'true' : 'false') : null;
79
+ $this->_data['store_id'] = array_key_exists('store_id', $data) ? $data['store_id'] : null;
80
+ $this->_data['key'] = array_key_exists('key', $data) ? $data['key'] : null;
81
+
82
+ return $this;
83
+ }
84
+
85
+ /**
86
+ * Get data
87
+ *
88
+ * @return array
89
+ */
90
+ public function getData()
91
+ {
92
+ return $this->_data;
93
+ }
94
+
95
+ /**
96
+ * Create web service role and user
97
+ *
98
+ * @throws Exception
99
+ * @throws Mage_Core_Exception
100
+ * @return Remarkety_Mgconnector_Model_Install
101
+ */
102
+ protected function _webServiceConfiguration()
103
+ {
104
+ $this->_data['key'] = $this->_generateApiKey();
105
+ Mage::getModel('core/config')->saveConfig('remarkety/mgconnector/api_key', $this->_data['key']);
106
+
107
+ $wsFirstName = array_key_exists('first_name', $this->data) && !empty($this->_data['first_name']) ? $this->_data['first_name'] : "Remarkety";
108
+ $wsLastName = array_key_exists('last_name', $this->data) && !empty($this->_data['last_name']) ? $this->_data['last_name'] : "API";
109
+
110
+ if(!$this->_getWebServiceUser()->getId()) {
111
+ $email = $this->_data['email'];
112
+
113
+ $role = Mage::getModel('api/roles')
114
+ ->setName(self::WEB_SERVICE_ROLE)
115
+ ->setPid(false)
116
+ ->setRoleType('G')
117
+ ->save();
118
+
119
+ Mage::getModel("api/rules")
120
+ ->setRoleId($role->getId())
121
+ ->setResources(array('all'))
122
+ ->saveRel();
123
+
124
+ $user = Mage::getModel('api/user')
125
+ ->setData(array(
126
+ 'username' => self::WEB_SERVICE_ROLE,
127
+ 'firstname' => $wsFirstName,
128
+ 'lastname' => $wsLastName,
129
+ 'email' => $email,
130
+ 'api_key' => $this->_data['key'],
131
+ 'api_key_confirmation' => $this->_data['key'],
132
+ 'is_active' => 1,
133
+ 'user_roles' => '',
134
+ 'assigned_user_role' => '',
135
+ 'role_name' => '',
136
+ 'roles' => array($role->getId())
137
+ ));
138
+
139
+ $retries = 0;
140
+ $maxRetries = 5;
141
+ while ($user->userExists() && $retries++ < $maxRetries) {
142
+ $email = "_$email";
143
+ $user->setData("email", $email);
144
+ }
145
+ if ($retries == $maxRetries) {
146
+ throw new Exception("Could not create WebService user - all emails are taken");
147
+ }
148
+ $user->save();
149
+
150
+ $user
151
+ ->setRoleIds(array($role->getId()))
152
+ ->setRoleUserId($user->getUserId())
153
+ ->saveRelations();
154
+ } else {
155
+ $this
156
+ ->_getWebServiceUser()
157
+ //->setEmail($this->_data['email'])
158
+ ->setFirstname($wsFirstName)
159
+ ->setLastname($wsLastName)
160
+ ->setNewApiKey($this->_data['key'])
161
+ ->save();
162
+ }
163
+
164
+ return $this;
165
+ }
166
+
167
+ /**
168
+ * Send request
169
+ *
170
+ * @param $payload
171
+ * @return Remarkety_Mgconnector_Model_Install
172
+ */
173
+ protected function _sendRequest($payload)
174
+ {
175
+ Mage::getModel('mgconnector/request')->makeRequest($payload);
176
+
177
+ return $this;
178
+ }
179
+
180
+ /**
181
+ * Install extension creating new remarkety account
182
+ *
183
+ * @return Remarkety_Mgconnector_Model_Install
184
+ * @throws Mage_Core_Exception
185
+ */
186
+ public function installByCreateExtension()
187
+ {
188
+ $connection = Mage::getSingleton('core/resource')->getConnection('core_write');
189
+
190
+ try {
191
+ $connection->beginTransaction();
192
+
193
+ $this->_webServiceConfiguration();
194
+
195
+ $connection->commit();
196
+ } catch(Mage_Core_Exception $e) {
197
+ $connection->rollback();
198
+ throw new Mage_Core_Exception($e->getMessage());
199
+ }
200
+
201
+ // Make sure that store_id entry is an array
202
+ if(!empty($this->_data['store_id']) && !is_array($this->_data['store_id'])) {
203
+ $this->_data['store_id'] = (array)$this->_data['store_id'];
204
+ }
205
+
206
+ // Create request for each store view separately
207
+ foreach($this->_data['store_id'] as $_storeId) {
208
+ $store = Mage::getModel('core/store')->load($_storeId);
209
+ $this->_sendRequest(array(
210
+ 'key' => $this->_data['key'],
211
+ 'email' => $this->_data['email'],
212
+ 'password' => $this->_data['password'],
213
+ 'acceptTerms' => $this->_data['terms'],
214
+ 'selectedView' => json_encode(array(
215
+ 'website_id' => $store->getWebsiteId(),
216
+ 'store_id' => $store->getGroupId(),
217
+ 'view_id' => $_storeId,
218
+ )),
219
+ 'isNewUser' => true,
220
+ 'firstName' => $this->_data['first_name'],
221
+ 'lastName' => $this->_data['last_name'],
222
+ 'phone' => $this->_data['phone'],
223
+ 'storeFrontUrl' => $store->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK),
224
+ 'viewName' => $store->name,
225
+ 'ip' => Mage::helper('core/http')->getRemoteAddr()
226
+ ));
227
+
228
+ $this->_markInstalled($_storeId);
229
+ }
230
+
231
+ // Reinitialize configuration
232
+ Mage::app()->getCacheInstance()->cleanType('config');
233
+
234
+ return $this;
235
+ }
236
+
237
+ /**
238
+ * Install extension using existing remarkety account
239
+ *
240
+ * @return Remarkety_Mgconnector_Model_Install
241
+ * @throws Mage_Core_Exception
242
+ */
243
+ public function installByLoginExtension()
244
+ {
245
+ $connection = Mage::getSingleton('core/resource')->getConnection('core_write');
246
+
247
+ try {
248
+ $connection->beginTransaction();
249
+
250
+ $this->_webServiceConfiguration();
251
+
252
+ $connection->commit();
253
+ } catch(Mage_Core_Exception $e) {
254
+ $connection->rollback();
255
+ throw new Mage_Core_Exception($e->getMessage());
256
+ }
257
+
258
+ // Make sure that store_id entry is an array
259
+ if(!empty($this->_data['store_id']) && !is_array($this->_data['store_id'])) {
260
+ $this->_data['store_id'] = (array)$this->_data['store_id'];
261
+ }
262
+
263
+ // Create request for each store view separately
264
+ foreach($this->_data['store_id'] as $_storeId) {
265
+ $store = Mage::getModel('core/store')->load($_storeId);
266
+
267
+ $this->_sendRequest(array(
268
+ 'key' => $this->_data['key'],
269
+ 'email' => $this->_data['email'],
270
+ 'password' => $this->_data['password'],
271
+ 'acceptTerms' => $this->_data['terms'],
272
+ 'selectedView' => json_encode(array(
273
+ 'website_id' => $store->getWebsiteId(),
274
+ 'store_id' => $store->getGroupId(),
275
+ 'view_id' => $_storeId,
276
+ )),
277
+ 'isNewUser' => false,
278
+ 'storeFrontUrl' => $store->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK),
279
+ 'viewName' => $store->name,
280
+ 'ip' => Mage::helper('core/http')->getRemoteAddr()
281
+ ));
282
+
283
+ $this->_markInstalled($_storeId);
284
+ }
285
+
286
+ // Reinitialize configuration
287
+ Mage::app()->getCacheInstance()->cleanType('config');
288
+
289
+ return $this;
290
+ }
291
+
292
+ /**
293
+ * Upgrade extension
294
+ *
295
+ * @return Remarkety_Mgconnector_Model_Install
296
+ * @throws Mage_Core_Exception
297
+ */
298
+ public function upgradeExtension()
299
+ {
300
+ $connection = Mage::getSingleton('core/resource')->getConnection('core_write');
301
+
302
+ try {
303
+ $connection->beginTransaction();
304
+
305
+ $webServiceUser = $this->_getWebServiceUser();
306
+
307
+ $this->_data['email'] = $webServiceUser->getEmail();
308
+ $this->_data['key'] = $this->_generateApiKey();
309
+
310
+ $this
311
+ ->_getWebServiceUser()
312
+ ->setNewApiKey($this->_data['key'])
313
+ ->save();
314
+
315
+ Mage::getModel('core/config')->saveConfig('remarkety/mgconnector/api_key', $this->_data['key']);
316
+
317
+ $connection->commit();
318
+ } catch(Mage_Core_Exception $e) {
319
+ $connection->rollback();
320
+ throw new Mage_Core_Exception($e->getMessage());
321
+ }
322
+
323
+ $this->_sendRequest(array());
324
+
325
+ return $this;
326
+ }
327
+
328
+ /**
329
+ * Complete extension installation
330
+ *
331
+ * @return Remarkety_Mgconnector_Model_Install
332
+ * @throws Mage_Core_Exception
333
+ */
334
+ public function completeExtensionInstallation()
335
+ {
336
+ $connection = Mage::getSingleton('core/resource')->getConnection('core_write');
337
+
338
+ try {
339
+ $connection->beginTransaction();
340
+
341
+ $ver = Mage::getConfig()->getModuleConfig("Remarkety_Mgconnector")->version;
342
+ Mage::getModel('core/config')->saveConfig(self::XPATH_INSTALLED, $ver);
343
+
344
+ $intervals = Mage::getStoreConfig('mgconnector_options/mgconnector_options_group/intervals');
345
+ if(!empty($intervals)) {
346
+ Mage::getModel('core/config')->saveConfig('remarkety/mgconnector/intervals', $intervals);
347
+ } else {
348
+ Mage::getModel('core/config')->saveConfig('remarkety/mgconnector/intervals', "1,3,10");
349
+ }
350
+
351
+ // remove old config entries if exist
352
+ Mage::getModel('core/config')
353
+ ->deleteConfig('mgconnector_options/mgconnector_options_group/api_key')
354
+ ->deleteConfig('mgconnector_options/mgconnector_options_group/intervals');
355
+
356
+ // remove old files
357
+ $blockDir = Mage::getModuleDir('Block', 'Remarkety_Mgconnector') . DS . 'Block';
358
+ $etcDir = Mage::getModuleDir('etc', 'Remarkety_Mgconnector');
359
+
360
+ if(file_exists($file = $etcDir . DS . 'system.xml')) {
361
+ unlink($file);
362
+ }
363
+ if(file_exists($file = $blockDir . DS . 'Adminhtml' . DS . 'Mgconnector.php')) {
364
+ unlink($file);
365
+ }
366
+ if(file_exists($file = $blockDir . DS . 'Adminhtml' . DS . 'Mgconnector' . DS . 'Grid.php')) {
367
+ unlink($file);
368
+ }
369
+ if(file_exists($file = $blockDir . DS . 'Adminhtml' . DS . 'Mgconnector' . DS . 'Grid' . DS . 'Column' . DS . 'Renderer' . DS . 'Status.php')) {
370
+ unlink($file);
371
+ }
372
+
373
+ $connection->commit();
374
+ } catch(Mage_Core_Exception $e) {
375
+ $connection->rollback();
376
+ throw new Mage_Core_Exception($e->getMessage());
377
+ }
378
+
379
+ return $this;
380
+ }
381
+
382
+ /**
383
+ * Generate new api key
384
+ *
385
+ * @return string
386
+ * @throws Mage_Core_Exception
387
+ */
388
+ protected function _generateApiKey()
389
+ {
390
+ $apiKey = Mage::getStoreConfig('remarkety/mgconnector/api_key');
391
+ if (!empty($apiKey))
392
+ return $apiKey;
393
+ if(!empty($this->_data['email'])) {
394
+ return md5($this->_data['email'] . time());
395
+ }
396
+ throw new Mage_Core_Exception('Can not generate api key');
397
+ }
398
+
399
+ /**
400
+ * Return remarkety webservice user
401
+ *
402
+ * @return Mage_Api_Model_User
403
+ */
404
+ protected function _getWebServiceUser()
405
+ {
406
+ $webServiceUser = Mage::getModel('api/user')
407
+ ->loadByUsername(self::WEB_SERVICE_USERNAME);
408
+
409
+ return $webServiceUser;
410
+ }
411
+
412
+ /**
413
+ * Return remarkety webservice user by email
414
+ *
415
+ * @param string $email
416
+ * @return Mage_Api_Model_User
417
+ */
418
+ protected function _getWebServiceUserByEmail($email) {
419
+ $webServiceUser = Mage::getModel('api/user')
420
+ ->loadByEmail($email);
421
+
422
+ return $webServiceUser;
423
+ }
424
+
425
+ /**
426
+ * Mark extension as installed for provided store id
427
+ *
428
+ * @param int $storeId
429
+ * @throws Mage_Core_Exception
430
+ * @return Remarkety_Mgconnector_Model_Install
431
+ */
432
+ protected function _markInstalled($storeId) {
433
+ $connection = Mage::getSingleton('core/resource')->getConnection('core_write');
434
+
435
+ try {
436
+ $connection->beginTransaction();
437
+
438
+ $ver = Mage::getConfig()->getModuleConfig("Remarkety_Mgconnector")->version;
439
+ Mage::getModel('core/config')->saveConfig(
440
+ self::XPATH_INSTALLED,
441
+ $ver,
442
+ self::STORE_SCOPE,
443
+ $storeId
444
+ );
445
+
446
+ $response = Mage::getSingleton('core/session')->getRemarketyLastResponseMessage();
447
+ $response = !empty($response) ? unserialize($response) : array();
448
+ if(!empty($response['storePublicId'])){
449
+ /**
450
+ * @var $m Remarkety_Mgconnector_Model_Webtracking
451
+ */
452
+ $m = Mage::getModel('mgconnector/webtracking');
453
+ $m->setRemarketyPublicId($storeId, $response['storePublicId']);
454
+ }
455
+
456
+ $connection->commit();
457
+ } catch(Mage_Core_Exception $e) {
458
+ $connection->rollback();
459
+ throw new Mage_Core_Exception($e->getMessage());
460
+ }
461
+
462
+ return $this;
463
+ }
464
+
465
+ /**
466
+ * Return core_config_data entries for stores where extension is installed
467
+ *
468
+ * @return object
469
+ */
470
+ public function getConfiguredStores()
471
+ {
472
+ $collection = Mage::getModel('core/config_data')->getCollection();
473
+ $collection
474
+ ->getSelect()
475
+ ->where('scope = ?', self::STORE_SCOPE)
476
+ ->where('path = ?', self::XPATH_INSTALLED);
477
+
478
+ return $collection;
479
+ }
480
+
481
+ public static function isMultipleStores() {
482
+ return 'true' === 'true';
483
+ }
484
+ }
app/code/community/Remarkety/Mgconnector/Model/Observer.php ADDED
@@ -0,0 +1,499 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Observer model, which handle few events and send post request
5
+ *
6
+ * @category Remarkety
7
+ * @package Remarkety_Mgconnector
8
+ * @author Piotr Pierzak <piotrek.pierzak@gmail.com>
9
+ */
10
+
11
+ if (!defined("REMARKETY_LOG"))
12
+ define('REMARKETY_LOG', 'remarkety_mgconnector.log');
13
+
14
+ class Remarkety_Mgconnector_Model_Observer
15
+ {
16
+ const REMARKETY_EVENTS_ENDPOINT = 'https://api-events.remarkety.com/v1';
17
+ const REMARKETY_METHOD = 'POST';
18
+ const REMARKETY_TIMEOUT = 2;
19
+ const REMARKETY_VERSION = 0.9;
20
+ const REMARKETY_PLATFORM = 'MAGENTO';
21
+
22
+ protected $_token = null;
23
+ protected $_intervals = null;
24
+ protected $_customer = null;
25
+ protected $_hasDataChanged = false;
26
+
27
+ protected $_subscriber = null;
28
+ protected $_origSubsciberData = null;
29
+
30
+ protected $_address = null;
31
+ protected $_origAddressData = null;
32
+
33
+ public function __construct()
34
+ {
35
+ $this->_token = Mage::getStoreConfig('remarkety/mgconnector/api_key');
36
+ $intervals = Mage::getStoreConfig('remarkety/mgconnector/intervals');
37
+ $this->_intervals = explode(',', $intervals);
38
+ }
39
+
40
+
41
+
42
+ public function triggerCustomerAddressBeforeUpdate($observer)
43
+ {
44
+ $address = Mage::getSingleton('customer/session')->getCustomer()->getDefaultBillingAddress();
45
+ if(!empty($address)) {
46
+ $this->_origAddressData = $address->getData();
47
+ }
48
+ return $this;
49
+ }
50
+
51
+ public function beforeBlockToHtml(Varien_Event_Observer $observer) {
52
+
53
+ $grid = $observer->getBlock();
54
+
55
+ /**
56
+ * Mage_Adminhtml_Block_Customer_Grid
57
+ */
58
+ if ($grid instanceof Mage_Adminhtml_Block_Promo_Quote_Edit_Tab_Coupons_Grid) {
59
+ $grid->addColumnAfter(
60
+ 'expiration_date',
61
+ array(
62
+ 'header' => Mage::helper('salesrule')->__('Expiration date'),
63
+ 'index' => 'expiration_date',
64
+ 'type' => 'datetime',
65
+ 'default' => '-',
66
+ 'align' => 'center',
67
+ 'width' => '160'
68
+ ),
69
+ 'created_at'
70
+ );
71
+
72
+ $yesnoOptions = array(null => 'No','1' => 'Yes','' => 'No');
73
+
74
+ $grid->addColumnAfter('added_by_remarkety', array(
75
+ 'header' => Mage::helper('salesrule')->__('Created By Remarkety'),
76
+ 'index' => 'added_by_remarkety',
77
+ 'type' => 'options',
78
+ 'options' => $yesnoOptions,
79
+ 'width' => '30',
80
+ 'align' => 'center',
81
+ ),'expiration_date');
82
+
83
+ }
84
+
85
+ }
86
+
87
+ public function triggerCustomerAddressUpdate($observer)
88
+ {
89
+ $this->_address = $observer->getEvent()->getCustomerAddress();
90
+ $this->_customer = $this->_address->getCustomer();
91
+
92
+ if(Mage::registry('remarkety_customer_save_observer_executed_'.$this->_customer->getId())) {
93
+ return $this;
94
+ }
95
+
96
+ $isDefaultBilling =
97
+ ($this->_customer == null || $this->_customer->getDefaultBillingAddress() == null)
98
+ ? false
99
+ : ($this->_address->getId() == $this->_customer->getDefaultBillingAddress()->getId());
100
+ if (!$isDefaultBilling || !$this->_customer->getId()) {
101
+ return $this;
102
+ }
103
+
104
+ $this->_customerUpdate();
105
+
106
+ Mage::register('remarkety_customer_save_observer_executed_'.$this->_customer->getId(),true);
107
+ return $this;
108
+ }
109
+
110
+ public function triggerCustomerUpdate($observer)
111
+ {
112
+ $this->_customer = $observer->getEvent()->getCustomer();
113
+
114
+ if(Mage::registry('remarkety_customer_save_observer_executed_'.$this->_customer->getId()) || !$this->_customer->getId()) {
115
+ return $this;
116
+ }
117
+
118
+ if($this->_customer->getOrigData() === null) {
119
+ $this->_customerRegistration();
120
+ } else {
121
+ $this->_customerUpdate();
122
+ }
123
+
124
+ Mage::register('remarkety_customer_save_observer_executed_'.$this->_customer->getId(),true);
125
+ return $this;
126
+ }
127
+
128
+ public function triggerSubscribeUpdate($observer)
129
+ {
130
+ $this->_subscriber = $observer->getEvent()->getSubscriber();
131
+
132
+ $loggedIn = Mage::getSingleton('customer/session')->isLoggedIn();
133
+
134
+ if($this->_subscriber->getId() && !$loggedIn) {
135
+ if($this->_subscriber->getCustomerId() && Mage::registry('remarkety_customer_save_observer_executed_'.$this->_subscriber->getCustomerId())) {
136
+ return $this;
137
+ }
138
+ // Avoid loops - If this unsubsribe was triggered by remarkety, no need to update us
139
+ if (Mage::registry('remarkety_subscriber_deleted'))
140
+ return $this;
141
+ $this->makeRequest('customers/create', $this->_prepareCustomerSubscribtionUpdateData(true));
142
+ $email = $this->_subscriber->getSubscriberEmail();
143
+ if(!empty($email)){
144
+
145
+ //save email to cart if needed
146
+ $cart = Mage::getSingleton('checkout/session')->getQuote();
147
+ if($cart && !is_null($cart->getId()) && is_null($cart->getCustomerEmail())){
148
+ $cart->setCustomerEmail($email)->save();
149
+ }
150
+
151
+ Mage::getSingleton('customer/session')->setSubscriberEmail($email);
152
+ }
153
+ }
154
+
155
+ return $this;
156
+ }
157
+
158
+ public function triggerSubscribeDelete($observer)
159
+ {
160
+ $this->_subscriber = $observer->getEvent()->getSubscriber();
161
+ if(!Mage::registry('remarkety_subscriber_deleted_'.$this->_subscriber->getEmail()) && $this->_subscriber->getId()) {
162
+ $this->makeRequest('customers/update', $this->_prepareCustomerSubscribtionDeleteData());
163
+ }
164
+
165
+ return $this;
166
+ }
167
+
168
+ public function triggerCustomerDelete($observer)
169
+ {
170
+ $this->_customer = $observer->getEvent()->getCustomer();
171
+ if (!$this->_customer->getId()) {
172
+ return $this;
173
+ }
174
+
175
+ $this->makeRequest('customers/delete', array(
176
+ 'id' => (int)$this->_customer->getId(),
177
+ 'email' => $this->_customer->getEmail(),
178
+ ));
179
+ return $this;
180
+ }
181
+
182
+ public function triggerProductSave($observer) {
183
+ // TODO - Need to implement
184
+ return $this;
185
+ }
186
+
187
+ protected function _customerRegistration()
188
+ {
189
+ $this->makeRequest('customers/create', $this->_prepareCustomerUpdateData());
190
+ return $this;
191
+ }
192
+
193
+ protected function _customerUpdate()
194
+ {
195
+ if($this->_hasDataChanged()) {
196
+ $this->makeRequest('customers/update', $this->_prepareCustomerUpdateData());
197
+ }
198
+ return $this;
199
+ }
200
+
201
+ protected function _hasDataChanged()
202
+ {
203
+ if(!$this->_hasDataChanged && $this->_customer) {
204
+ $validate = array(
205
+ 'firstname',
206
+ 'lastname',
207
+ 'title',
208
+ 'birthday',
209
+ 'gender',
210
+ 'email',
211
+ 'group_id',
212
+ 'default_billing',
213
+ 'is_subscribed',
214
+ );
215
+ $originalData = $this->_customer->getOrigData();
216
+ $currentData = $this->_customer->getData();
217
+ foreach ($validate as $field) {
218
+ if (isset($originalData[$field])) {
219
+ if (!isset($currentData[$field]) || $currentData[$field] != $originalData[$field]) {
220
+ $this->_hasDataChanged = true;
221
+ break;
222
+ }
223
+ }
224
+ }
225
+ // This part has been replaced by the loop above to avoid comparing objects in array_diff
226
+ // $customerDiffKeys = array_keys( array_diff($this->_customer->getData(), $this->_customer->getOrigData()) );
227
+ //
228
+ // if(array_intersect($customerDiffKeys, $validate)) {
229
+ // $this->_hasDataChanged = true;
230
+ // }
231
+ $customerData = $this->_customer->getData();
232
+ if(!$this->_hasDataChanged && isset($customerData['is_subscribed'])) {
233
+ $subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($this->_customer->getEmail());
234
+ $isSubscribed = $subscriber->getId() ? $subscriber->getData('subscriber_status') == Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED : false;
235
+
236
+ if($customerData['is_subscribed'] !== $isSubscribed) {
237
+ $this->_hasDataChanged = true;
238
+ }
239
+ }
240
+ }
241
+ if(!$this->_hasDataChanged && $this->_address && $this->_origAddressData) {
242
+ $validate = array(
243
+ 'street',
244
+ 'city',
245
+ 'region',
246
+ 'postcode',
247
+ 'country_id',
248
+ 'telephone',
249
+ );
250
+ $addressDiffKeys = array_keys( array_diff($this->_address->getData(), $this->_origAddressData) );
251
+
252
+ if(array_intersect($addressDiffKeys, $validate)) {
253
+ $this->_hasDataChanged = true;
254
+ }
255
+ }
256
+
257
+ return $this->_hasDataChanged;
258
+ }
259
+
260
+ protected function _getRequestConfig($eventType)
261
+ {
262
+ return array(
263
+ 'adapter' => 'Zend_Http_Client_Adapter_Curl',
264
+ 'curloptions' => array(
265
+ // CURLOPT_FOLLOWLOCATION => true,
266
+ CURLOPT_HEADER => true,
267
+ CURLOPT_CONNECTTIMEOUT => self::REMARKETY_TIMEOUT
268
+ // CURLOPT_SSL_CIPHER_LIST => "RC4-SHA"
269
+ ),
270
+ );
271
+ }
272
+
273
+ protected function _getHeaders($eventType,$payload)
274
+ {
275
+ $domain = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
276
+ $domain = substr($domain, 7, -1);
277
+
278
+ $headers = array(
279
+ 'X-Domain: ' . $domain,
280
+ 'X-Token: ' . $this->_token,
281
+ 'X-Event-Type: ' . $eventType,
282
+ 'X-Platform: ' . self::REMARKETY_PLATFORM,
283
+ 'X-Version: ' . self::REMARKETY_VERSION,
284
+ );
285
+ if (isset($payload['storeId']))
286
+ $headers[] = 'X-Magento-Store-Id: ' . $payload['storeId'];
287
+ return $headers;
288
+ }
289
+
290
+ public function makeRequest($eventType, $payload, $attempt = 1, $queueId = null)
291
+ {
292
+ try {
293
+ $client = new Zend_Http_Client(self::REMARKETY_EVENTS_ENDPOINT, $this->_getRequestConfig($eventType));
294
+ $payload = array_merge($payload, $this->_getPayloadBase($eventType));
295
+ $headers = $this->_getHeaders($eventType, $payload);
296
+ unset($payload['storeId']);
297
+ $json = json_encode($payload);
298
+
299
+ $response = $client
300
+ ->setHeaders($headers)
301
+ ->setRawData($json, 'application/json')
302
+ ->request(self::REMARKETY_METHOD);
303
+
304
+ Mage::log("Sent event to endpoint: ".$json."; Response (".$response->getStatus()."): ".$response->getBody(), \Zend_Log::DEBUG, REMARKETY_LOG);
305
+ switch ($response->getStatus()) {
306
+ case '200':
307
+ return true;
308
+ case '400':
309
+ throw new Exception('Request has been malformed.');
310
+ case '401':
311
+ throw new Exception('Request failed, probably wrong API key or inactive account.');
312
+ default:
313
+ $this->_queueRequest($eventType, $payload, $attempt, $queueId);
314
+ }
315
+ } catch(Exception $e) {
316
+ $this->_queueRequest($eventType, $payload, $attempt, $queueId);
317
+ }
318
+
319
+ return false;
320
+ }
321
+
322
+ protected function _queueRequest($eventType, $payload, $attempt, $queueId)
323
+ {
324
+ $queueModel = Mage::getModel('mgconnector/queue');
325
+
326
+ if(!empty($this->_intervals[$attempt-1])) {
327
+ $now = time();
328
+ $nextAttempt = $now + (int)$this->_intervals[$attempt-1] * 60;
329
+ if($queueId) {
330
+ $queueModel->load($queueId);
331
+ $queueModel->setAttempts($attempt);
332
+ $queueModel->setLastAttempt( date("Y-m-d H:i:s", $now) );
333
+ $queueModel->setNextAttempt( date("Y-m-d H:i:s", $nextAttempt) );
334
+ } else {
335
+ $queueModel->setData(array(
336
+ 'event_type' => $eventType,
337
+ 'payload' => serialize($payload),
338
+ 'attempts' => $attempt,
339
+ 'last_attempt' => date("Y-m-d H:i:s", $now),
340
+ 'next_attempt' => date("Y-m-d H:i:s", $nextAttempt),
341
+ ));
342
+ }
343
+ return $queueModel->save();
344
+ } elseif($queueId) {
345
+ $queueModel->load($queueId);
346
+ $queueModel->setStatus(0);
347
+ return $queueModel->save();
348
+ }
349
+ return false;
350
+ }
351
+
352
+ protected function _getPayloadBase($eventType)
353
+ {
354
+ date_default_timezone_set('UTC');
355
+ $arr = array(
356
+ 'timestamp' => (string)time(),
357
+ 'event_id' => $eventType,
358
+ );
359
+ return $arr;
360
+ }
361
+
362
+ protected function _prepareCustomerUpdateData()
363
+ {
364
+ $arr = array(
365
+ 'id' => (int)$this->_customer->getId(),
366
+ 'email' => $this->_customer->getEmail(),
367
+ 'created_at' => date('c', strtotime($this->_customer->getCreatedAt())),
368
+ 'first_name' => $this->_customer->getFirstname(),
369
+ 'last_name' => $this->_customer->getLastname(),
370
+ 'store_id' => $this->_customer->getStoreId(),
371
+ //'extra_info' => array(),
372
+ );
373
+
374
+ $isSubscribed = $this->_customer->getIsSubscribed();
375
+ if($isSubscribed === null) {
376
+ $subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($this->_customer->getEmail());
377
+ if($subscriber->getId()) {
378
+ $isSubscribed = $subscriber->getData('subscriber_status') == Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED;
379
+ } else {
380
+ $isSubscribed = false;
381
+ }
382
+ }
383
+ $arr = array_merge($arr, array('accepts_marketing' => (bool)$isSubscribed));
384
+
385
+ if($title = $this->_customer->getPrefix()) {
386
+ $arr = array_merge($arr, array('title' => $title));
387
+ }
388
+
389
+ if($dob = $this->_customer->getDob()) {
390
+ $arr = array_merge($arr, array('birthdate' => $dob));
391
+ }
392
+
393
+ if($gender = $this->_customer->getGender()) {
394
+ $arr = array_merge($arr, array('gender' => $gender));
395
+ }
396
+
397
+ if($address = $this->_customer->getDefaultBillingAddress()) {
398
+ $street = $address->getStreet();
399
+ $arr = array_merge($arr, array('default_address' => array(
400
+ 'address1' => isset($street[0]) ? $street[0] : '',
401
+ 'address2' => isset($street[1]) ? $street[1] : '',
402
+ 'city' => $address->getCity(),
403
+ 'province' => $address->getRegion(),
404
+ 'phone' => $address->getTelephone(),
405
+ 'country_code' => $address->getCountryId(),
406
+ 'zip' => $address->getPostcode(),
407
+ )));
408
+ }
409
+
410
+ $tags = $this->_getCustomerProductTags();
411
+ if(!empty($tags) && $tags->getSize()) {
412
+ $tagsArr = array();
413
+ foreach ($tags as $_tag) {
414
+ $tagsArr[] = $_tag->getName();
415
+ }
416
+ $arr = array_merge($arr, array('tags' => $tagsArr));
417
+ }
418
+
419
+ if($group = Mage::getModel('customer/group')->load($this->_customer->getGroupId())) {
420
+ $arr = array_merge($arr, array('groups' => array(
421
+ array(
422
+ 'id' => (int)$this->_customer->getGroupId(),
423
+ 'name' => $group->getCustomerGroupCode(),
424
+ )
425
+ )));
426
+ }
427
+
428
+ return $arr;
429
+ }
430
+
431
+ protected function _getCustomerProductTags()
432
+ {
433
+ $tags = Mage::getModel('tag/tag')->getResourceCollection();
434
+ if (!empty($tags)) {
435
+ $tags = $tags
436
+ ->joinRel()
437
+ ->addCustomerFilter($this->_customer->getId());
438
+ }
439
+ return $tags;
440
+ }
441
+
442
+ protected function _prepareCustomerSubscribtionUpdateData($newsletter = false)
443
+ {
444
+ $quote = Mage::getSingleton('checkout/session')->getQuote();
445
+ $store = Mage::app()->getStore();
446
+
447
+ $arr = array(
448
+ 'email' => $this->_subscriber->getSubscriberEmail(),
449
+ 'accepts_marketing' => $this->_subscriber->getData('subscriber_status') == Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED,
450
+ 'storeId' => $store->getStoreId()
451
+ );
452
+
453
+ if($newsletter && (!is_object($quote) || $quote->getCheckoutMethod() !== Mage_Sales_Model_Quote::CHECKOUT_METHOD_GUEST) ){
454
+ $arr['is_newsletter_subscriber'] = true;
455
+ }
456
+
457
+ return $arr;
458
+ }
459
+
460
+ protected function _prepareCustomerSubscribtionDeleteData()
461
+ {
462
+ $store = Mage::app()->getStore();
463
+
464
+ $arr = array(
465
+ 'email' => $this->_subscriber->getSubscriberEmail(),
466
+ 'accepts_marketing' => false,
467
+ 'storeId' => $store->getStoreId()
468
+ );
469
+
470
+ return $arr;
471
+ }
472
+
473
+ public function resend($queueItems,$resetAttempts = false) {
474
+ $sent=0;
475
+ foreach($queueItems as $_queue) {
476
+ $result = $this->makeRequest($_queue->getEventType(), unserialize($_queue->getPayload()), $resetAttempts ? 1 : ($_queue->getAttempts()+1), $_queue->getId());
477
+ if($result) {
478
+ Mage::getModel('mgconnector/queue')
479
+ ->load($_queue->getId())
480
+ ->delete();
481
+ $sent++;
482
+ }
483
+ }
484
+ return $sent;
485
+ }
486
+
487
+ public function run()
488
+ {
489
+ $collection = Mage::getModel('mgconnector/queue')->getCollection();
490
+ $nextAttempt = date("Y-m-d H:i:s");
491
+ $collection
492
+ ->getSelect()
493
+ ->where('next_attempt <= ?', $nextAttempt)
494
+ ->where('status = 1')
495
+ ->order('main_table.next_attempt asc');
496
+ $this->resend($collection);
497
+ return $this;
498
+ }
499
+ }
app/code/community/Remarkety/Mgconnector/Model/Queue.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Queue model
5
+ *
6
+ * @category Remarkety
7
+ * @package Remarkety_Mgconnector
8
+ * @author Piotr Pierzak <piotrek.pierzak@gmail.com>
9
+ */
10
+ class Remarkety_Mgconnector_Model_Queue extends Mage_Core_Model_Abstract
11
+ {
12
+ protected function _construct()
13
+ {
14
+ $this->_init('mgconnector/queue');
15
+ }
16
+ }
app/code/community/Remarkety/Mgconnector/Model/Recovery.php ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Remarkety Mgconnector recovery controller.
5
+ *
6
+ * @category Remarkety
7
+ * @package Remarkety_Mgconnector
8
+ * @author Piotr Pierzak <piotrek.pierzak@gmail.com>
9
+ */
10
+ class Remarkety_Mgconnector_Model_Recovery
11
+ {
12
+ private $_apikey;
13
+
14
+ /**
15
+ * Remarkety_Mgconnector_Model_Recovery constructor.
16
+ */
17
+ public function __construct()
18
+ {
19
+ $this->_apikey = Mage::getStoreConfig('remarkety/mgconnector/api_key');
20
+ }
21
+
22
+ /**
23
+ * Restore quote.
24
+ *
25
+ * @param int $quoteId
26
+ * @return Remarkety_Mgconnector_Model_Recovery
27
+ * @throws Mage_Core_Exception
28
+ */
29
+ public function quoteRestore($quoteId)
30
+ {
31
+ /** @var Mage_Checkout_Model_Session $checkoutSession */
32
+ $checkoutSession = Mage::getSingleton('checkout/session');
33
+
34
+ $checkoutSession->setQuoteId($quoteId);
35
+
36
+ /** @var Mage_Sales_Model_Quote $quoteModel */
37
+ $quote = $checkoutSession->getQuote();
38
+
39
+ $quote->getAddressesCollection();
40
+ $quote->getItemsCollection();
41
+ $quote->getPaymentsCollection();
42
+
43
+ $quote->getPaymentsCollection()->walk('delete');
44
+ $quote->getAddressesCollection()->walk('delete');
45
+
46
+ $quote
47
+ ->setIsActive(true)
48
+ ->setCustomerId(null)
49
+ ->setCustomerEmail(null)
50
+ ->setCustomerFirstname(null)
51
+ ->setCustomerMiddlename(null)
52
+ ->setCustomerLastname(null)
53
+ ->setCustomerGroupId(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID)
54
+ ->save();
55
+
56
+ return $this;
57
+ }
58
+
59
+ /**
60
+ * Generates signed cart id for urls
61
+ * @param $id
62
+ * @return string
63
+ */
64
+ public function encodeQuoteId($id){
65
+ $sign = md5($id . '.' . $this->_apikey);
66
+ return base64_encode($id . ':' . $sign);
67
+ }
68
+
69
+ /**
70
+ * Decodes signed cart ids from urls
71
+ * @param $hashed_id
72
+ * @return bool|int
73
+ */
74
+ public function decodeQuoteId($hashed_id){
75
+ $id = null;
76
+ $parts = base64_decode($hashed_id);
77
+ if(!empty($parts)){
78
+ $split = explode(':', $parts);
79
+ if(count($split) == 2){
80
+ $cart_id = $split[0];
81
+ if(is_numeric($cart_id)){
82
+ $sign = md5($cart_id . '.' . $this->_apikey);
83
+ $sign_from_request = $split[1];
84
+ if($sign === $sign_from_request){
85
+ return (int)$cart_id;
86
+ }
87
+ }
88
+ }
89
+ }
90
+ return false;
91
+ }
92
+ }
app/code/community/Remarkety/Mgconnector/Model/Request.php ADDED
@@ -0,0 +1,131 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Request model
5
+ *
6
+ * @category Remarkety
7
+ * @package Remarkety_Mgconnector
8
+ * @author Piotr Pierzak <piotrek.pierzak@gmail.com>
9
+ */
10
+ class Remarkety_Mgconnector_Model_Request
11
+ {
12
+ const REMARKETY_URI = 'https://app.remarkety.com/public/install/notify';
13
+ const REMARKETY_STOREID_URI = 'https://app.remarkety.com/public/install/get-store-id';
14
+ const REMARKETY_METHOD = 'POST';
15
+ const REMARKETY_TIMEOUT = 10;
16
+ const REMARKETY_VERSION = 0.9;
17
+ const REMARKETY_PLATFORM = 'MAGENTO';
18
+ const REMARKETY_OEM = 'remarkety';
19
+
20
+ protected function _getRequestConfig()
21
+ {
22
+ return array(
23
+ 'adapter' => 'Zend_Http_Client_Adapter_Curl',
24
+ 'curloptions' => array(
25
+ // CURLOPT_FOLLOWLOCATION => true,
26
+ CURLOPT_HEADER => true,
27
+ CURLOPT_CONNECTTIMEOUT => self::REMARKETY_TIMEOUT,
28
+ // CURLOPT_SSL_CIPHER_LIST => "RC4-SHA"
29
+ // CURLOPT_SSL_VERIFYPEER => false,
30
+ ),
31
+ );
32
+ }
33
+
34
+ protected function _getPayloadBase()
35
+ {
36
+ $domain = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
37
+ $domain = substr($domain, 7, -1);
38
+
39
+ $version = Mage::getVersion();
40
+ $version .= ' ' . (Mage::helper('core')->isModuleEnabled('Enterprise_Enterprise') ? 'EE' : 'CE');
41
+
42
+ $arr = array(
43
+ 'domain' => $domain,
44
+ 'platform' => Remarkety_Mgconnector_Model_Request::REMARKETY_PLATFORM,
45
+ 'version' => $version,
46
+ 'oem' => Remarkety_Mgconnector_Model_Request::REMARKETY_OEM,
47
+ );
48
+ return $arr;
49
+ }
50
+
51
+ public function getStoreID($magento_store_id){
52
+ try {
53
+ $store = Mage::getModel('core/store')->load($magento_store_id);
54
+ $payload = $this->_getPayloadBase();
55
+
56
+ $payload['selectedView'] = json_encode(array(
57
+ 'website_id' => $store->getWebsiteId(),
58
+ 'store_id' => $store->getGroupId(),
59
+ 'view_id' => $magento_store_id,
60
+ ));
61
+ $payload['key'] = Mage::getStoreConfig('remarkety/mgconnector/api_key');
62
+
63
+ $client = new Zend_Http_Client(
64
+ self::REMARKETY_STOREID_URI,
65
+ $this->_getRequestConfig()
66
+ );
67
+ $client->setParameterPost($payload);
68
+ $response = $client->request(self::REMARKETY_METHOD);
69
+
70
+ Mage::log(var_export($payload, true), null, 'remarkety-ext.log');
71
+ Mage::log($response->getStatus(), null, 'remarkety-ext.log');
72
+ Mage::log($response->getBody(), null, 'remarkety-ext.log');
73
+
74
+ $body = (array)json_decode($response->getBody());
75
+
76
+ Mage::getSingleton('core/session')->setRemarketyLastResponseStatus($response->getStatus() === 200 ? 1 : 0);
77
+ Mage::getSingleton('core/session')->setRemarketyLastResponseMessage(serialize($body));
78
+ if($response->getStatus() == "200"){
79
+ if(!empty($body['storePublicId'])){
80
+ return $body['storePublicId'];
81
+ }
82
+ //if no store id
83
+ throw new Exception('Response from Remarkety without storeId');
84
+ }
85
+ switch ($response->getStatus()) {
86
+ case '200':
87
+ return $body;
88
+ case '400':
89
+ throw new Exception('Request failed. ' . $body['message']);
90
+ default:
91
+ throw new Exception('Request to remarkety servers failed ('.$response->getStatus().')');
92
+ }
93
+ } catch(Exception $e) {
94
+ Mage::log($e->getMessage(), null, 'remarkety-ext.log');
95
+ throw new Mage_Core_Exception($e->getMessage());
96
+ }
97
+ }
98
+ public function makeRequest($payload)
99
+ {
100
+ try {
101
+ $payload = array_merge($payload, $this->_getPayloadBase());
102
+ $client = new Zend_Http_Client(
103
+ self::REMARKETY_URI,
104
+ $this->_getRequestConfig()
105
+ );
106
+ $client->setParameterPost($payload);
107
+ $response = $client->request(self::REMARKETY_METHOD);
108
+
109
+ Mage::log(var_export($payload, true), null, 'remarkety-ext.log');
110
+ Mage::log($response->getStatus(), null, 'remarkety-ext.log');
111
+ Mage::log($response->getBody(), null, 'remarkety-ext.log');
112
+
113
+ $body = (array)json_decode($response->getBody());
114
+
115
+ Mage::getSingleton('core/session')->setRemarketyLastResponseStatus($response->getStatus() === 200 ? 1 : 0);
116
+ Mage::getSingleton('core/session')->setRemarketyLastResponseMessage(serialize($body));
117
+
118
+ switch ($response->getStatus()) {
119
+ case '200':
120
+ return $body;
121
+ case '400':
122
+ throw new Exception('Request failed. ' . $body['message']);
123
+ default:
124
+ throw new Exception('Request to remarkety servers failed ('.$response->getStatus().')');
125
+ }
126
+ } catch(Exception $e) {
127
+ Mage::log($e->getMessage(), null, 'remarkety-ext.log');
128
+ throw new Mage_Core_Exception($e->getMessage());
129
+ }
130
+ }
131
+ }
app/code/community/Remarkety/Mgconnector/Model/Resource/Coupon.php ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magento.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magento.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_SalesRule
23
+ * @copyright Copyright (c) 2006-2016 X.commerce, Inc. and affiliates (http://www.magento.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+
28
+ /**
29
+ * SalesRule Resource Coupon
30
+ *
31
+ * @category Remarkety
32
+ * @package Remarkety_Mgconnector
33
+ * @author Rafal Andryanczyk <rafal.andryanczyk@gmail.com>
34
+ */
35
+ class Remarkety_Mgconnector_Model_Resource_Coupon extends Mage_SalesRule_Model_Resource_Coupon
36
+ {
37
+
38
+ /**
39
+ * Update auto generated Specific Coupon if it's rule changed
40
+ *
41
+ * @param Mage_SalesRule_Model_Rule $rule
42
+ * @return Mage_SalesRule_Model_Resource_Coupon
43
+ */
44
+ public function updateSpecificCoupons(Mage_SalesRule_Model_Rule $rule)
45
+ {
46
+
47
+ if (!$rule || !$rule->getId() || !$rule->hasDataChanges()) {
48
+ return $this;
49
+ }
50
+
51
+ $updateArray = array();
52
+ if ($rule->dataHasChangedFor('uses_per_coupon')) {
53
+ $updateArray['usage_limit'] = $rule->getUsesPerCoupon();
54
+ }
55
+
56
+ if ($rule->dataHasChangedFor('uses_per_customer')) {
57
+ $updateArray['usage_per_customer'] = $rule->getUsesPerCustomer();
58
+ }
59
+
60
+ $ruleNewDate = new Zend_Date($rule->getToDate());
61
+ $ruleOldDate = new Zend_Date($rule->getOrigData('to_date'));
62
+
63
+ if ($ruleNewDate->compare($ruleOldDate)) {
64
+ $updateArray['expiration_date'] = $rule->getToDate();
65
+ }
66
+
67
+ if (!empty($updateArray)) {
68
+ $this->_getWriteAdapter()->update(
69
+ $this->getTable('salesrule/coupon'),
70
+ $updateArray,
71
+ array('rule_id = ?' => $rule->getId(),'added_by_remarkety is null')
72
+ );
73
+ }
74
+
75
+ return $this;
76
+ }
77
+ }
app/code/community/Remarkety/Mgconnector/Model/Resource/Queue.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Queue resource model
5
+ *
6
+ * @category Remarkety
7
+ * @package Remarkety_Mgconnector
8
+ * @author Piotr Pierzak <piotrek.pierzak@gmail.com>
9
+ */
10
+ if (version_compare(Mage::getVersion(), '1.6', '>=')) {
11
+
12
+ class Remarkety_Mgconnector_Model_Resource_Queue extends Mage_Core_Model_Resource_Db_Abstract
13
+ {
14
+ protected function _construct()
15
+ {
16
+ $this->_init('mgconnector/queue', 'queue_id');
17
+ }
18
+ }
19
+
20
+ } else {
21
+
22
+ class Remarkety_Mgconnector_Model_Resource_Queue extends Mage_Core_Model_Mysql4_Abstract
23
+ {
24
+ protected function _construct()
25
+ {
26
+ $this->_init('mgconnector/queue', 'queue_id');
27
+ }
28
+ }
29
+
30
+ }
app/code/community/Remarkety/Mgconnector/Model/Resource/Queue/Collection.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Mgconnector collection resource model
5
+ *
6
+ * @category Remarkety
7
+ * @package Remarkety_Mgconnector
8
+ * @author Piotr Pierzak <piotrek.pierzak@gmail.com>
9
+ */
10
+ if (version_compare(Mage::getVersion(), '1.6', '>=')) {
11
+
12
+ class Remarkety_Mgconnector_Model_Resource_Queue_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
13
+ {
14
+ protected function _construct()
15
+ {
16
+ $this->_init('mgconnector/queue');
17
+ }
18
+ }
19
+
20
+ } else {
21
+
22
+ class Remarkety_Mgconnector_Model_Resource_Queue_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
23
+ {
24
+ protected function _construct()
25
+ {
26
+ $this->_init('mgconnector/queue');
27
+ }
28
+ }
29
+
30
+ }
app/code/community/Remarkety/Mgconnector/Model/Resource/Rule/Collection.php ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Mgconnector Sales Rules resource collection model
5
+ *
6
+ * @category Remarkety
7
+ * @package Remarkety_Mgconnector
8
+ * @author Rafał Andryanczyk <rafal.andryanczyk@gmail.com>
9
+ */
10
+ class Remarkety_Mgconnector_Model_Resource_Rule_Collection extends Mage_SalesRule_Model_Resource_Rule_Collection
11
+ {
12
+
13
+ /**
14
+ * Filter collection by specified website, customer group, coupon code, date.
15
+ * Filter collection to use only active rules.
16
+ * Involved sorting by sort_order column.
17
+ *
18
+ * @param int $websiteId
19
+ * @param int $customerGroupId
20
+ * @param string $couponCode
21
+ * @param string|null $now
22
+ * @use $this->addWebsiteGroupDateFilter()
23
+ *
24
+ * @return Mage_SalesRule_Model_Resource_Rule_Collection
25
+ */
26
+ public function setValidationFilter($websiteId, $customerGroupId, $couponCode = '', $now = null)
27
+ {
28
+ if (!$this->getFlag('validation_filter')) {
29
+
30
+ if (is_null($now)) {
31
+ $now = Mage::getModel('core/date')->date('Y-m-d');
32
+ }
33
+
34
+
35
+ /* We need to overwrite joinLeft if coupon is applied */
36
+ $this->getSelect()->reset();
37
+ Mage_Rule_Model_Resource_Rule_Collection_Abstract::_initSelect();
38
+
39
+ $this->addWebsiteGroupDateFilter($websiteId, $customerGroupId, $now);
40
+ $select = $this->getSelect();
41
+
42
+ $connection = $this->getConnection();
43
+ if (strlen($couponCode)) {
44
+ $select->joinLeft(
45
+ array('rule_coupons' => $this->getTable('salesrule/coupon')),
46
+ $connection->quoteInto(
47
+ 'main_table.rule_id = rule_coupons.rule_id AND main_table.coupon_type != ?',
48
+ Mage_SalesRule_Model_Rule::COUPON_TYPE_NO_COUPON
49
+ ),
50
+ array('code')
51
+ );
52
+
53
+ $noCouponCondition = $connection->quoteInto(
54
+ 'main_table.coupon_type = ? ',
55
+ Mage_SalesRule_Model_Rule::COUPON_TYPE_NO_COUPON
56
+ );
57
+
58
+ $orWhereConditions = array(
59
+ $connection->quoteInto(
60
+ '(main_table.coupon_type = ? AND rule_coupons.type = 0)',
61
+ Mage_SalesRule_Model_Rule::COUPON_TYPE_AUTO
62
+ ),
63
+ $connection->quoteInto(
64
+ '(main_table.coupon_type = ? AND main_table.use_auto_generation = 1 AND rule_coupons.type = 1)',
65
+ Mage_SalesRule_Model_Rule::COUPON_TYPE_SPECIFIC
66
+ ),
67
+ $connection->quoteInto(
68
+ '(main_table.coupon_type = ? AND main_table.use_auto_generation = 0 AND rule_coupons.type = 0)',
69
+ Mage_SalesRule_Model_Rule::COUPON_TYPE_SPECIFIC
70
+ ),
71
+ );
72
+ $orWhereCondition = implode(' OR ', $orWhereConditions);
73
+ $select->where(
74
+ $noCouponCondition . ' OR ((' . $orWhereCondition . ') AND rule_coupons.code = ?)', $couponCode
75
+ );
76
+
77
+ $select->where('(rule_coupons.expiration_date IS NULL) AND
78
+ (to_date is null or to_date >= ?)
79
+ OR
80
+ (rule_coupons.expiration_date IS NOT NULL) AND
81
+ (rule_coupons.expiration_date >= ?) ', $now);
82
+ } else {
83
+ $this->addFieldToFilter('main_table.coupon_type', Mage_SalesRule_Model_Rule::COUPON_TYPE_NO_COUPON);
84
+ }
85
+ $this->setOrder('sort_order', self::SORT_ORDER_ASC);
86
+ $this->setFlag('validation_filter', true);
87
+ }
88
+
89
+ return $this;
90
+ }
91
+
92
+ /**
93
+ * Filter collection by website(s), customer group(s) and date.
94
+ * Filter collection to only active rules.
95
+ * Sorting is not involved
96
+ *
97
+ * @param int $websiteId
98
+ * @param int $customerGroupId
99
+ * @param string|null $now
100
+ * @use $this->addWebsiteFilter()
101
+ *
102
+ * @return Mage_SalesRule_Model_Mysql4_Rule_Collection
103
+ */
104
+ public function addWebsiteGroupDateFilter($websiteId, $customerGroupId, $now = null)
105
+ {
106
+
107
+ if (!$this->getFlag('website_group_date_filter')) {
108
+ if (is_null($now)) {
109
+ $now = Mage::getModel('core/date')->date('Y-m-d');
110
+ }
111
+
112
+ $this->addWebsiteFilter($websiteId);
113
+
114
+ $entityInfo = $this->_getAssociatedEntityInfo('customer_group');
115
+ $connection = $this->getConnection();
116
+ $this->getSelect()
117
+ ->joinInner(
118
+ array('customer_group_ids' => $this->getTable($entityInfo['associations_table'])),
119
+ $connection->quoteInto(
120
+ 'main_table.' . $entityInfo['rule_id_field']
121
+ . ' = customer_group_ids.' . $entityInfo['rule_id_field']
122
+ . ' AND customer_group_ids.' . $entityInfo['entity_id_field'] . ' = ?',
123
+ (int)$customerGroupId
124
+ ),
125
+ array()
126
+ )
127
+ ->where('from_date is null or from_date <= ?', $now);
128
+
129
+
130
+ $this->addIsActiveFilter();
131
+
132
+ $this->setFlag('website_group_date_filter', true);
133
+ }
134
+
135
+ return $this;
136
+ }
137
+
138
+ }
app/code/community/Remarkety/Mgconnector/Model/Resource/Setup.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Mgconnector resource setup model
5
+ *
6
+ * @category Remarkety
7
+ * @package Remarkety_Mgconnector
8
+ * @author Piotr Pierzak <piotrek.pierzak@gmail.com>
9
+ */
10
+ class Remarkety_Mgconnector_Model_Resource_Setup extends Mage_Core_Model_Resource_Setup
11
+ {
12
+
13
+ }
app/code/community/Remarkety/Mgconnector/Model/Webtracking.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ Class Remarkety_Mgconnector_Model_Webtracking extends Mage_Core_Model_Abstract
4
+ {
5
+ const RM_STORE_ID = 'remarkety/mgconnector/public_storeId';
6
+ const RM_BYPASS_CACHE = 'remarkety/mgconnector/bypass_cache';
7
+ const STORE_SCOPE = 'stores';
8
+ public function getRemarketyPublicId($store = null)
9
+ {
10
+ $store = is_null($store) ? Mage::app()->getStore() : $store;
11
+ $store_id = is_numeric($store) ? $store : $store->getStoreId();
12
+ $id = Mage::getStoreConfig(self::RM_STORE_ID, $store_id);
13
+ return (empty($id) || is_null($id)) ? false : $id;
14
+ }
15
+
16
+ public function setRemarketyPublicId($store, $newId)
17
+ {
18
+ $store_id = is_numeric($store) ? $store : $store->getStoreId();
19
+ Mage::getModel('core/config')->saveConfig(
20
+ self::RM_STORE_ID,
21
+ $newId,
22
+ self::STORE_SCOPE,
23
+ $store_id
24
+ );
25
+ Mage::app()->getCacheInstance()->cleanType('config');
26
+ }
27
+
28
+ public static function getBypassCache()
29
+ {
30
+ return $apiKey = Mage::getStoreConfig(self::RM_BYPASS_CACHE);
31
+ }
32
+
33
+ /**
34
+ * @param bool $bool_val
35
+ */
36
+ public function setBypassCache($bool_val)
37
+ {
38
+ Mage::getModel('core/config')->saveConfig(self::RM_BYPASS_CACHE, $bool_val);
39
+ }
40
+ }
app/code/community/Remarkety/Mgconnector/controllers/Adminhtml/ConfigureController.php ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Adminhtml Configure controller
5
+ *
6
+ * @category Remarkety
7
+ * @package Remarkety_Mgconnector
8
+ * @author Piotr Pierzak <piotrek.pierzak@gmail.com>
9
+ */
10
+ class Remarkety_Mgconnector_Adminhtml_ConfigureController extends Mage_Adminhtml_Controller_Action
11
+ {
12
+ /**
13
+ * Init action
14
+ *
15
+ * @return Remarkety_Mgconnector_Adminhtml_ConfigureController
16
+ */
17
+ protected function _initAction()
18
+ {
19
+ $this
20
+ ->loadLayout()
21
+ ->_title($this->__('Remarkety'))
22
+ ->_setActiveMenu('mgconnector');
23
+
24
+ return $this;
25
+ }
26
+
27
+ /**
28
+ * Configuration action
29
+ */
30
+ public function indexAction()
31
+ {
32
+ $mode = Mage::helper('mgconnector')->getMode();
33
+ if($mode === Remarkety_Mgconnector_Model_Install::MODE_WELCOME) {
34
+ $this
35
+ ->_initAction()
36
+ ->_title($this->__('Configuration'))
37
+ ->_addContent($this->getLayout()->createBlock('mgconnector/adminhtml_configure'))
38
+ ->renderLayout();
39
+ } else {
40
+ $this->_redirect('*/install/install');
41
+ }
42
+ }
43
+
44
+ public function saveAction()
45
+ {
46
+ if($this->getRequest()->isPost()) {
47
+ $params = $this->getRequest()->getParams();
48
+
49
+ Mage::getModel('core/config')->saveConfig('remarkety/mgconnector/intervals', $params['data']['intervals']);
50
+ $this->_getSession()->addSuccess($this->__('Configuration has been saved.'));
51
+ }
52
+
53
+ $this->_redirect('*/queue/index');
54
+ }
55
+ }
app/code/community/Remarkety/Mgconnector/controllers/Adminhtml/InstallController.php ADDED
@@ -0,0 +1,186 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Adminhtml Install controller
5
+ *
6
+ * @category Remarkety
7
+ * @package Remarkety_Mgconnector
8
+ * @author Piotr Pierzak <piotrek.pierzak@gmail.com>
9
+ */
10
+ class Remarkety_Mgconnector_Adminhtml_InstallController extends Mage_Adminhtml_Controller_Action
11
+ {
12
+ /**
13
+ * Init action
14
+ *
15
+ * @return Remarkety_Mgconnector_Adminhtml_InstallController
16
+ */
17
+ protected function _initAction()
18
+ {
19
+ $this
20
+ ->loadLayout()
21
+ ->_title($this->__('Remarkety'))
22
+ ->_setActiveMenu('mgconnector');
23
+
24
+ return $this;
25
+ }
26
+
27
+ /**
28
+ * Reinstall action
29
+ */
30
+ public function reinstallAction()
31
+ {
32
+ $config = Mage::getModel('core/config');
33
+ $config
34
+ ->deleteConfig(Remarkety_Mgconnector_Model_Install::XPATH_INSTALLED)
35
+ ->deleteConfig('remarkety/mgconnector/api_key')
36
+ ->deleteConfig('remarkety/mgconnector/public_storeId')
37
+ ->deleteConfig('remarkety/mgconnector/intervals')
38
+ ->deleteConfig('remarkety/mgconnector/last_response_status')
39
+ ->deleteConfig('remarkety/mgconnector/last_response_message');
40
+
41
+ foreach (Mage::app()->getWebsites() as $_website) {
42
+ foreach ($_website->getGroups() as $_group) {
43
+ foreach ($_group->getStores() as $_store) {
44
+ $scope = $_store->getStoreId();
45
+ $config->deleteConfig(Remarkety_Mgconnector_Model_Install::XPATH_INSTALLED, 'stores', $scope);
46
+ $config->deleteConfig('remarkety/mgconnector/public_storeId', 'stores', $scope);
47
+ }
48
+ }
49
+ }
50
+
51
+ Mage::app()->getCacheInstance()->cleanType('config');
52
+
53
+ Mage::getSingleton('core/session')->unsRemarketyLastResponseMessage();
54
+ Mage::getSingleton('core/session')->unsRemarketyLastResponseStatus();
55
+
56
+ $this->_redirect('*/*/install');
57
+ }
58
+
59
+ /**
60
+ * Installation action
61
+ */
62
+ public function installAction()
63
+ {
64
+ $mode = Mage::helper('mgconnector')->getMode();
65
+ $this
66
+ ->_initAction()
67
+ ->_title($this->__($this->_getTitle($mode)));
68
+
69
+ $this
70
+ ->_addContent($this->getLayout()->createBlock(sprintf('mgconnector/adminhtml_install_%s', $mode)))
71
+ ->_addAdditionalContent()
72
+ ->renderLayout();
73
+ }
74
+
75
+ /**
76
+ * Enable webtracking action
77
+ */
78
+ public function installWebtrackingAction()
79
+ {
80
+ $store_id = $this->getRequest()->getParam('store');
81
+ if(!is_numeric($store_id) || is_null($store_id)){
82
+ throw new Exception("Missing store id");
83
+ }
84
+ /**
85
+ * @var $m Remarkety_Mgconnector_Model_Webtracking
86
+ */
87
+ $m = Mage::getModel('mgconnector/webtracking');
88
+
89
+ /**
90
+ * @var $req Remarkety_Mgconnector_Model_Request
91
+ */
92
+ $req = Mage::getModel('mgconnector/request');
93
+ $rmStoreId = $req->getStoreID($store_id);
94
+ if($rmStoreId){
95
+ $m->setRemarketyPublicId($store_id, $rmStoreId);
96
+ Mage::app()->getCacheInstance()->cleanType('config');
97
+ }
98
+ $this->_redirect('*/install/install', array('mode' => 'welcome'));
99
+ }
100
+
101
+ /**
102
+ * Disable webtracking action
103
+ */
104
+ public function disableWebtrackingAction()
105
+ {
106
+ $store_id = $this->getRequest()->getParam('store');
107
+ if(!is_numeric($store_id) || is_null($store_id)){
108
+ throw new Exception("Missing store id");
109
+ }
110
+ /**
111
+ * @var $m Remarkety_Mgconnector_Model_Webtracking
112
+ */
113
+ $m = Mage::getModel('mgconnector/webtracking');
114
+ $m->setRemarketyPublicId($store_id, null);
115
+ Mage::app()->getCacheInstance()->cleanType('config');
116
+ $this->_redirect('*/install/install', array('mode' => 'welcome'));
117
+ }
118
+
119
+ protected function _addAdditionalContent()
120
+ {
121
+ $mode = Mage::helper('mgconnector')->getMode();
122
+
123
+ switch($mode) {
124
+ case Remarkety_Mgconnector_Model_Install::MODE_WELCOME:
125
+ $this->_addContent($this->getLayout()->createBlock('mgconnector/adminhtml_install_welcome_store'));
126
+ break;
127
+ }
128
+
129
+ return $this;
130
+ }
131
+
132
+ /**
133
+ * Return title
134
+ *
135
+ * @param string $mode
136
+ * @return string
137
+ */
138
+ protected function _getTitle($mode) {
139
+ return ucwords(str_replace('_', ' - ', $mode));
140
+ }
141
+
142
+ /**
143
+ * Complete action
144
+ */
145
+ public function completeAction()
146
+ {
147
+ $redirectBack = true;
148
+
149
+ if($this->getRequest()->isPost()) {
150
+ $params = $this->getRequest()->getParams();
151
+
152
+ try {
153
+ $install = Mage::getModel('mgconnector/install')
154
+ ->setData($params['data']);
155
+
156
+ switch($params['data']['mode']) {
157
+ case Remarkety_Mgconnector_Model_Install::MODE_INSTALL_CREATE:
158
+ $install->installByCreateExtension();
159
+ break;
160
+ case Remarkety_Mgconnector_Model_Install::MODE_INSTALL_LOGIN:
161
+ $install->installByLoginExtension();
162
+ break;
163
+ case Remarkety_Mgconnector_Model_Install::MODE_UPGRADE:
164
+ $install->upgradeExtension();
165
+ break;
166
+ case Remarkety_Mgconnector_Model_Install::MODE_COMPLETE:
167
+ $install->completeExtensionInstallation();
168
+ break;
169
+ default:
170
+ throw new Mage_Core_Exception('Selected mode can not be handled.');
171
+ }
172
+
173
+ $redirectBack = false;
174
+ } catch(Mage_Core_Exception $e) {
175
+ $this->_getSession()->addError($e->getMessage());
176
+ }
177
+ }
178
+
179
+ if($redirectBack) {
180
+ $mode = isset($params['data']['mode']) ? $params['data']['mode'] : null;
181
+ $this->_redirect('*/install/install', array('mode' => $mode));
182
+ } else {
183
+ $this->_redirect('*/install/install', array('mode' => 'welcome'));
184
+ }
185
+ }
186
+ }
app/code/community/Remarkety/Mgconnector/controllers/Adminhtml/MgconnectorController.php ADDED
@@ -0,0 +1,192 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Adminhtml Mgconnector controller
5
+ *
6
+ * @category Remarkety
7
+ * @package Remarkety_Mgconnector
8
+ * @author Piotr Pierzak <piotrek.pierzak@gmail.com>
9
+ */
10
+ class Remarkety_Mgconnector_Adminhtml_MgconnectorController extends Mage_Adminhtml_Controller_Action
11
+ {
12
+ /**
13
+ * Init action
14
+ *
15
+ * @return Remarkety_Mgconnector_Adminhtml_MgconnectorController
16
+ */
17
+ protected function _initAction()
18
+ {
19
+ $this
20
+ ->loadLayout()
21
+ ->_title($this->__('Remarkety'))
22
+ ->_setActiveMenu('mgconnector');
23
+
24
+ return $this;
25
+ }
26
+
27
+ /**
28
+ * Index action
29
+ */
30
+ public function indexAction()
31
+ {
32
+ $this
33
+ ->_initAction()
34
+ ->_title($this->__('Queue'));
35
+
36
+ $this->_addContent($this->getLayout()->createBlock('mgconnector/adminhtml_queue'));
37
+ $this->renderLayout();
38
+ }
39
+
40
+ /**
41
+ * Reinstall action
42
+ */
43
+ public function reinstallAction()
44
+ {
45
+ Mage::getModel('core/config')
46
+ ->deleteConfig('remarkety/mgconnector/apikey')
47
+ ->deleteConfig('remarkety/mgconnector/last_response')
48
+ ->deleteConfig(Remarkety_Mgconnector_Model_Install::XPATH_INSTALLED)
49
+ ->deleteConfig('remarkety/mgconnector/intervals');
50
+
51
+ $this->_redirect('*/*/installation');
52
+ }
53
+
54
+ /**
55
+ * Configuration action
56
+ */
57
+ public function configurationAction()
58
+ {
59
+ $mode = $this->_initMode();
60
+
61
+ if($mode === Remarkety_Mgconnector_Model_Install::MODE_CONFIGURATION) {
62
+ if($this->getRequest()->isPost()) {
63
+ $params = $this->getRequest()->getParams();
64
+
65
+ Mage::getModel('core/config')->saveConfig('remarkety/mgconnector/intervals', $params['data']['intervals']);
66
+ $this->_getSession()->addSuccess($this->__('Configuration has been saved.'));
67
+
68
+ $this->_redirect('*/*/*');
69
+ } else {
70
+ $this
71
+ ->_initAction()
72
+ ->_title($this->__(ucfirst($mode)));
73
+
74
+ $this->_addContent($this->getLayout()->createBlock(sprintf('mgconnector/adminhtml_configuration_%s', $mode)));
75
+ $this->renderLayout();
76
+ }
77
+ } else {
78
+ $this->_redirect('*/*/installation', array('_current' => true));
79
+ }
80
+ }
81
+
82
+ /**
83
+ * Installation action
84
+ */
85
+ public function installationAction()
86
+ {
87
+ $mode = $this->_initMode();
88
+
89
+ $this
90
+ ->_initAction()
91
+ ->_title($this->__(ucfirst($mode)));
92
+
93
+ $this->_addContent($this->getLayout()->createBlock(sprintf('mgconnector/adminhtml_configuration_%s', $mode)));
94
+ $this->renderLayout();
95
+ }
96
+
97
+ /**
98
+ * Complete action
99
+ */
100
+ public function completeAction()
101
+ {
102
+ $redirectBack = true;
103
+
104
+ if($this->getRequest()->isPost()) {
105
+ $params = $this->getRequest()->getParams();
106
+
107
+ try {
108
+ $install = Mage::getModel('mgconnector/install')
109
+ ->setData($params['data']);
110
+
111
+ switch($params['data']['mode']) {
112
+ case Remarkety_Mgconnector_Model_Install::MODE_INSTALL:
113
+ $install->installExtension();
114
+ break;
115
+ case Remarkety_Mgconnector_Model_Install::MODE_UPGRADE:
116
+ $install->upgradeExtension();
117
+ break;
118
+ case Remarkety_Mgconnector_Model_Install::MODE_COMPLETE:
119
+ $install->completeExtensionInstallation();
120
+ break;
121
+ default:
122
+ throw new Mage_Core_Exception('Selected mode can not be handled.');
123
+ }
124
+
125
+ $redirectBack = false;
126
+ } catch(Mage_Core_Exception $e) {
127
+ $this->_getSession()->addError($e->getMessage());
128
+ }
129
+ }
130
+
131
+ $this->_redirect(sprintf('*/*/%s', $redirectBack ? 'installation' : 'configuration'));
132
+ }
133
+
134
+ /**
135
+ * Grid action
136
+ */
137
+ public function gridAction()
138
+ {
139
+ $this->loadLayout();
140
+ $this->getResponse()->setBody(
141
+ $this->getLayout()->createBlock('mgconnector/adminhtml_mgconnector_grid')->toHtml()
142
+ );
143
+ }
144
+
145
+ /**
146
+ * Return mode
147
+ * @return string
148
+ * @throws Mage_Core_Exception
149
+ */
150
+ protected function _initMode()
151
+ {
152
+ $mode = Remarkety_Mgconnector_Model_Install::MODE_INSTALL;
153
+
154
+ /**
155
+ * If remarkety extension was installed in version lower than 1.0.0.15
156
+ * and remarkety web service user already exists
157
+ */
158
+ $webServiceUser = Mage::getModel('api/user')
159
+ ->setUsername(Remarkety_Mgconnector_Model_Install::WEB_SERVICE_USERNAME)
160
+ ->userExists();
161
+
162
+ if($webServiceUser === true) {
163
+ $mode = Remarkety_Mgconnector_Model_Install::MODE_UPGRADE;
164
+ }
165
+
166
+ $response = Mage::getStoreConfig('remarkety/mgconnector/last_response');
167
+ if(!empty($response)) {
168
+ $mode = Remarkety_Mgconnector_Model_Install::MODE_COMPLETE;
169
+ }
170
+
171
+ $installed = Mage::getStoreConfig(Remarkety_Mgconnector_Model_Install::XPATH_INSTALLED);
172
+ if(!empty($installed)) {
173
+ $mode = Remarkety_Mgconnector_Model_Install::MODE_CONFIGURATION;
174
+ }
175
+
176
+ $forceMode = $this->getRequest()->getParam('mode', false);
177
+ if(!empty($forceMode)) {
178
+ $mode = $forceMode;
179
+ }
180
+
181
+ if(!in_array($mode, array(
182
+ Remarkety_Mgconnector_Model_Install::MODE_INSTALL,
183
+ Remarkety_Mgconnector_Model_Install::MODE_UPGRADE,
184
+ Remarkety_Mgconnector_Model_Install::MODE_COMPLETE,
185
+ Remarkety_Mgconnector_Model_Install::MODE_CONFIGURATION
186
+ ))) {
187
+ throw new Mage_Core_Exception('Installation mode can not be handled.');
188
+ }
189
+
190
+ return $mode;
191
+ }
192
+ }
app/code/community/Remarkety/Mgconnector/controllers/Adminhtml/QueueController.php ADDED
@@ -0,0 +1,129 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Adminhtml Queue controller
5
+ *
6
+ * @category Remarkety
7
+ * @package Remarkety_Mgconnector
8
+ * @author Piotr Pierzak <piotrek.pierzak@gmail.com>
9
+ */
10
+ class Remarkety_Mgconnector_Adminhtml_QueueController extends Mage_Adminhtml_Controller_Action
11
+ {
12
+ /**
13
+ * Init action
14
+ *
15
+ * @return Remarkety_Mgconnector_Adminhtml_QueueController
16
+ */
17
+ protected function _initAction()
18
+ {
19
+ $this
20
+ ->loadLayout()
21
+ ->_title($this->__('Remarkety'))
22
+ ->_setActiveMenu('mgconnector');
23
+
24
+ return $this;
25
+ }
26
+
27
+ /**
28
+ * Index action
29
+ */
30
+ public function indexAction()
31
+ {
32
+ $this
33
+ ->_initAction()
34
+ ->_title($this->__('Queue'))
35
+ ->_addContent($this->getLayout()->createBlock('mgconnector/adminhtml_queue_configure'))
36
+ ->_addContent($this->getLayout()->createBlock('mgconnector/adminhtml_queue'))
37
+ ->renderLayout();
38
+ }
39
+
40
+ public function saveAction()
41
+ {
42
+ if($this->getRequest()->isPost()) {
43
+ $params = $this->getRequest()->getParams();
44
+
45
+ Mage::getModel('core/config')->saveConfig('remarkety/mgconnector/intervals', $params['data']['intervals']);
46
+
47
+ if(isset($params['data']['api_key'])){
48
+ $key = $params['data']['api_key'];
49
+ Mage::getModel('core/config')->saveConfig('remarkety/mgconnector/api_key', $key);
50
+ $apiUser = Mage::getModel('api/user')->loadByUsername(\Remarkety_Mgconnector_Model_Install::WEB_SERVICE_USERNAME);
51
+ $apiUser
52
+ ->setNewApiKey($key)
53
+ ->save();
54
+ }
55
+ if(isset($params['data']['bypasscache'])){
56
+ Mage::getModel('core/config')->saveConfig(\Remarkety_Mgconnector_Model_Webtracking::RM_BYPASS_CACHE, true);
57
+ } else {
58
+ Mage::getModel('core/config')->saveConfig(\Remarkety_Mgconnector_Model_Webtracking::RM_BYPASS_CACHE, false);
59
+ }
60
+
61
+ Mage::app()->getCacheInstance()->cleanType('config');
62
+ $this->_getSession()->addSuccess($this->__('Configuration has been saved.'));
63
+ }
64
+
65
+ $this->_redirect('*/queue/index');
66
+ }
67
+
68
+ /**
69
+ * Grid action
70
+ */
71
+ public function gridAction()
72
+ {
73
+ $this->loadLayout();
74
+ $this->getResponse()->setBody(
75
+ $this->getLayout()->createBlock('mgconnector/adminhtml_queue_grid')->toHtml()
76
+ );
77
+ }
78
+
79
+ public function massResendAction() {
80
+
81
+ $queueIds = $this->getRequest()->getParam('queue');
82
+ if (!is_array($queueIds)) {
83
+ Mage::getSingleton('adminhtml/session')->addError($this->__('Please select queue item(s)'));
84
+ }
85
+ else {
86
+ try {
87
+ $collection = Mage::getModel('mgconnector/queue')->getCollection();
88
+ $collection
89
+ ->addFieldToFilter('queue_id',$queueIds)
90
+ ->getSelect();
91
+ $observer = Mage::getModel('mgconnector/observer');
92
+ $itemsSent = $observer->resend($collection);
93
+ Mage::getSingleton('adminhtml/session')->addSuccess(
94
+ Mage::helper('adminhtml')->__('Total of %d events(s) were resent', $itemsSent)
95
+ );
96
+ } catch (Exception $e) {
97
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
98
+ }
99
+ }
100
+
101
+ $this->_redirect('*/queue/index');
102
+ }
103
+
104
+ public function massDeleteAction() {
105
+
106
+ $queueIds = $this->getRequest()->getParam('queue');
107
+ if (!is_array($queueIds)) {
108
+ Mage::getSingleton('adminhtml/session')->addError($this->__('Please select queue item(s)'));
109
+ }
110
+ else {
111
+ try {
112
+ $collection = Mage::getModel('mgconnector/queue')->getCollection();
113
+ $collection
114
+ ->addFieldToFilter('queue_id',$queueIds)
115
+ ->getSelect();
116
+ foreach ($collection as $item) {
117
+ $item->delete();
118
+ }
119
+ Mage::getSingleton('adminhtml/session')->addSuccess(
120
+ Mage::helper('adminhtml')->__('Total of %d events(s) were deleted', count($queueIds))
121
+ );
122
+ } catch (Exception $e) {
123
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
124
+ }
125
+ }
126
+
127
+ $this->_redirect('*/queue/index');
128
+ }
129
+ }
app/code/community/Remarkety/Mgconnector/controllers/RecoveryController.php ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Remarkety Mgconnector recovery controller.
5
+ *
6
+ * @category Remarkety
7
+ * @package Remarkety_Mgconnector
8
+ * @author Piotr Pierzak <piotrek.pierzak@gmail.com>
9
+ */
10
+ class Remarkety_Mgconnector_RecoveryController extends Mage_Core_Controller_Front_Action
11
+ {
12
+ const MESSAGE_ERROR_WRONG_QUOTE_ID = 'Quote identifier has been not passed or it does not exists.';
13
+ const MESSAGE_ERROR_DURING_PROCESSING = 'During quote recovery error has occurred.';
14
+
15
+ /**
16
+ * Cart recovery controller action.
17
+ */
18
+ public function cartAction()
19
+ {
20
+ /** @var Mage_Core_Controller_Request_Http $requestModel */
21
+ $requestModel = $this->getRequest();
22
+
23
+ /** @var string|bool $hashedQuoteId */
24
+ $hashedQuoteId = $requestModel->getParam('quote_id', false);
25
+
26
+ if (!$hashedQuoteId) {
27
+ Mage::throwException(self::MESSAGE_ERROR_WRONG_QUOTE_ID);
28
+ }
29
+
30
+ /** @var Remarkety_Mgconnector_Model_Recovery $recovery */
31
+ $recovery = Mage::getModel('mgconnector/recovery');
32
+
33
+ $quoteId = $recovery->decodeQuoteId($hashedQuoteId);
34
+ if (!is_int($quoteId)) {
35
+ Mage::throwException(self::MESSAGE_ERROR_WRONG_QUOTE_ID);
36
+ }
37
+
38
+ /** @var Mage_Sales_Model_Quote $quoteModel */
39
+ $quote = Mage::getModel('sales/quote')->load($quoteId);
40
+ if (!$quote->getId()) {
41
+ Mage::throwException(self::MESSAGE_ERROR_WRONG_QUOTE_ID);
42
+ }
43
+
44
+ try {
45
+
46
+ $recovery->quoteRestore($quoteId);
47
+ } catch (Mage_Core_Exception $e) {
48
+ Mage::throwException(self::MESSAGE_ERROR_DURING_PROCESSING);
49
+ }
50
+
51
+ $this->_redirect('checkout/cart');
52
+ }
53
+ }
app/code/community/Remarkety/Mgconnector/controllers/WebtrackingController.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Remarkety Mgconnector recovery controller.
5
+ *
6
+ * @category Remarkety
7
+ * @package Remarkety_Mgconnector
8
+ * @author Piotr Pierzak <piotrek.pierzak@gmail.com>
9
+ */
10
+ class Remarkety_Mgconnector_WebtrackingController extends Mage_Core_Controller_Front_Action
11
+ {
12
+ public function identifyAction()
13
+ {
14
+ $this->getResponse()->clearHeaders()->setHeader('Content-type','application/x-javascript',true);
15
+ $email = $this->getEmail();
16
+ if($email){
17
+ $this->getResponse()->setBody('_rmData.push(["setCustomer", "'.$email.'"]);');
18
+ } else {
19
+ $this->getResponse()->setBody('');
20
+ }
21
+
22
+ }
23
+
24
+ private function getEmail(){
25
+ if(Mage::getSingleton('customer/session')->isLoggedIn()){
26
+ return $this->getCustomer()->getEmail();
27
+ }
28
+ $email = Mage::getSingleton('customer/session')->getSubscriberEmail();
29
+ return empty($email) ? false : $email;
30
+ }
31
+ }
app/code/community/Remarkety/Mgconnector/etc/adminhtml.xml ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <menu>
4
+ <mgconnector translate="title" module="mgconnector">
5
+ <title>Remarkety</title>
6
+ <sort_order>90</sort_order>
7
+ <children>
8
+ <mgconnector_configuration translate="title" module="mgconnector">
9
+ <title>Remarkety Installation</title>
10
+ <sort_order>10</sort_order>
11
+ <action>adminhtml/install/complete</action>
12
+ </mgconnector_configuration>
13
+ <mgconnector_queue>
14
+ <title>Configuration</title>
15
+ <sort_order>20</sort_order>
16
+ <action>adminhtml/queue/index</action>
17
+ </mgconnector_queue>
18
+ </children>
19
+ </mgconnector>
20
+ </menu>
21
+ <acl>
22
+ <resources>
23
+ <admin>
24
+ <children>
25
+ <children>
26
+ <mgconnector translate="title" module="mgconnector">
27
+ <title>Remarkety</title>
28
+ <children>
29
+ <mgconnector_configuration translate="title" module="mgconnector">
30
+ <title>Remarkety Configuration</title>
31
+ <sort_order>10</sort_order>
32
+ </mgconnector_configuration>
33
+ <mgconnector_queue>
34
+ <title>Remarkety Queue</title>
35
+ <sort_order>20</sort_order>
36
+ </mgconnector_queue>
37
+ </children>
38
+ </mgconnector>
39
+ </children>
40
+ </children>
41
+ </admin>
42
+ </resources>
43
+ </acl>
44
+ <events>
45
+ <core_block_abstract_to_html_before>
46
+ <observers>
47
+ <multiuseraccounts_add_column_parent_customer>
48
+ <type>singleton</type>
49
+ <class>Cminds_MultiUserAccounts_Model_Observer</class>
50
+ <method>beforeBlockToHtml</method>
51
+ </multiuseraccounts_add_column_parent_customer>
52
+ </observers>
53
+ </core_block_abstract_to_html_before>
54
+ </events>
55
+ </config>
app/code/community/Remarkety/Mgconnector/etc/api.xml ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <config>
2
+ <api>
3
+ <resources>
4
+ <mgconnector_core translate="title" module="mgconnector">
5
+ <title>Remarkety Magento Connector Core API calls</title>
6
+ <model>mgconnector/core_api</model>
7
+ <acl>remarkety/mgconnector</acl>
8
+ <methods>
9
+ <getCustomers translate="title" module="mgconnector">
10
+ <title>Returns Customer details</title>
11
+ </getCustomers>
12
+ <getOrders translate="title" module="mgconnector">
13
+ <title>Returns Order Details</title>
14
+ </getOrders>
15
+ <getQuotes translate="title" module="mgconnector">
16
+ <title>Returns Quote Details</title>
17
+ </getQuotes>
18
+ <getProducts translate="title" module="mgconnector">
19
+ <title>Returns Product Details</title>
20
+ </getProducts>
21
+ <getStoreSettings translate="title" module="mgconnector">
22
+ <title>Returns General Store Settings</title>
23
+ </getStoreSettings>
24
+ <getStoreOrderStatuses translate="title" module="mgconnector">
25
+ <title>Returns Optional Order Statuses</title>
26
+ </getStoreOrderStatuses>
27
+ <getCustomersCount translate="title" module="mgconnector">
28
+ <title>Returns Customers Count</title>
29
+ </getCustomersCount>
30
+ <getOrdersCount translate="title" module="mgconnector">
31
+ <title>Returns Orders Count</title>
32
+ </getOrdersCount>
33
+ <getProductsCount translate="title" module="mgconnector">
34
+ <title>Products Count</title>
35
+ </getProductsCount>
36
+ <createCoupon translate="title" module="mgconnector">
37
+ <title>Coupon Creation</title>
38
+ </createCoupon>
39
+ <unsubscribe translate="title" module="mgconnector">
40
+ <title>Unsubscribe</title>
41
+ </unsubscribe>
42
+ <getSubscribers translate="title" module="mgconnector">
43
+ <title>Get newsletter subscribers</title>
44
+ </getSubscribers>
45
+ <getSubscriberCount translate="title" module="mgconnector">
46
+ <title>Get newsletter subscriber count</title>
47
+ </getSubscriberCount>
48
+ </methods>
49
+ </mgconnector_core>
50
+ </resources>
51
+ <resources_alias>
52
+ <dashboard>mgconnector_dashboard</dashboard>
53
+ <core>mgconnector_core</core>
54
+ </resources_alias>
55
+ <acl>
56
+ <resources>
57
+ <remarkety translate="title" module="mgconnector">
58
+ <title>Remarkety</title>
59
+ <sort_order>100</sort_order>
60
+ <mgconnector translate="title" module="mgconnector">
61
+ <title>Store Connector APIs</title>
62
+ <sort_order>100</sort_order>
63
+ </mgconnector>
64
+ </remarkety>
65
+ </resources>
66
+ </acl>
67
+ </api>
68
+ </config>
app/code/community/Remarkety/Mgconnector/etc/config.xml ADDED
@@ -0,0 +1,163 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <config>
2
+ <modules>
3
+ <Remarkety_Mgconnector>
4
+ <version>1.4.3.0</version>
5
+ </Remarkety_Mgconnector>
6
+ </modules>
7
+ <global>
8
+ <models>
9
+ <mgconnector>
10
+ <class>Remarkety_Mgconnector_Model</class>
11
+ <resourceModel>mgconnector_resource</resourceModel>
12
+ </mgconnector>
13
+ <mgconnector_resource>
14
+ <class>Remarkety_Mgconnector_Model_Resource</class>
15
+ <entities>
16
+ <queue>
17
+ <table>remarkety_queue</table>
18
+ </queue>
19
+ </entities>
20
+ </mgconnector_resource>
21
+ <salesrule_resource>
22
+ <rewrite>
23
+ <!-- Model -->
24
+ <rule_collection>Remarkety_Mgconnector_Model_Resource_Rule_Collection</rule_collection>
25
+ <!-- Model -->
26
+ <coupon>Remarkety_Mgconnector_Model_Resource_Coupon</coupon>
27
+ </rewrite>
28
+
29
+ </salesrule_resource>
30
+
31
+ </models>
32
+ <resources>
33
+ <mgconnector_setup>
34
+ <setup>
35
+ <module>Remarkety_Mgconnector</module>
36
+ <class>Remarkety_Mgconnector_Model_Resource_Setup</class>
37
+ </setup>
38
+ </mgconnector_setup>
39
+ </resources>
40
+ <helpers>
41
+ <mgconnector>
42
+ <class>Remarkety_Mgconnector_Helper</class>
43
+ </mgconnector>
44
+ </helpers>
45
+ <blocks>
46
+ <mgconnector>
47
+ <class>Remarkety_Mgconnector_Block</class>
48
+ </mgconnector>
49
+ </blocks>
50
+ <events>
51
+ <catalog_product_save_after>
52
+ <observers>
53
+ <remarkety_catalog_product_save_after>
54
+ <type>singleton</type>
55
+ <class>mgconnector/observer</class>
56
+ <method>triggerProductSave</method>
57
+ </remarkety_catalog_product_save_after>
58
+ </observers>
59
+ </catalog_product_save_after>
60
+ <customer_save_after>
61
+ <observers>
62
+ <remarkety_customer_save_after_observer>
63
+ <type>singleton</type>
64
+ <class>mgconnector/observer</class>
65
+ <method>triggerCustomerUpdate</method>
66
+ </remarkety_customer_save_after_observer>
67
+ </observers>
68
+ </customer_save_after>
69
+ <customer_address_save_after>
70
+ <observers>
71
+ <remarkety_customer_address_save_after_observer>
72
+ <type>singleton</type>
73
+ <class>mgconnector/observer</class>
74
+ <method>triggerCustomerAddressUpdate</method>
75
+ </remarkety_customer_address_save_after_observer>
76
+ </observers>
77
+ </customer_address_save_after>
78
+ <customer_address_save_before>
79
+ <observers>
80
+ <remarkety_customer_address_save_before_observer>
81
+ <type>singleton</type>
82
+ <class>mgconnector/observer</class>
83
+ <method>triggerCustomerAddressBeforeUpdate</method>
84
+ </remarkety_customer_address_save_before_observer>
85
+ </observers>
86
+ </customer_address_save_before>
87
+ <newsletter_subscriber_save_after>
88
+ <observers>
89
+ <remarkety_newsletter_subscriber_save_after_observer>
90
+ <type>singleton</type>
91
+ <class>mgconnector/observer</class>
92
+ <method>triggerSubscribeUpdate</method>
93
+ </remarkety_newsletter_subscriber_save_after_observer>
94
+ </observers>
95
+ </newsletter_subscriber_save_after>
96
+ <newsletter_subscriber_delete_after>
97
+ <observers>
98
+ <remarkety_newsletter_subscriber_delete_after_observer>
99
+ <type>singleton</type>
100
+ <class>mgconnector/observer</class>
101
+ <method>triggerSubscribeDelete</method>
102
+ </remarkety_newsletter_subscriber_delete_after_observer>
103
+ </observers>
104
+ </newsletter_subscriber_delete_after>
105
+ <customer_delete_commit_after>
106
+ <observers>
107
+ <remarkety_customer_delete_commit_after_observer>
108
+ <type>singleton</type>
109
+ <class>mgconnector/observer</class>
110
+ <method>triggerCustomerDelete</method>
111
+ </remarkety_customer_delete_commit_after_observer>
112
+ </observers>
113
+ </customer_delete_commit_after>
114
+ <core_block_abstract_to_html_before>
115
+ <observers>
116
+ <remarkety_add_column_expiration_date>
117
+ <type>singleton</type>
118
+ <class>mgconnector/observer</class>
119
+ <method>beforeBlockToHtml</method>
120
+ </remarkety_add_column_expiration_date>
121
+ </observers>
122
+ </core_block_abstract_to_html_before>
123
+ </events>
124
+ </global>
125
+ <admin>
126
+ <routers>
127
+ <adminhtml>
128
+ <args>
129
+ <modules>
130
+ <Remarkety_Mgconnector before="Mage_Adminhtml">Remarkety_Mgconnector_Adminhtml</Remarkety_Mgconnector>
131
+ </modules>
132
+ </args>
133
+ </adminhtml>
134
+ </routers>
135
+ </admin>
136
+ <frontend>
137
+ <routers>
138
+ <mgconnector>
139
+ <use>standard</use>
140
+ <args>
141
+ <module>Remarkety_Mgconnector</module>
142
+ <frontName>remarkety</frontName>
143
+ </args>
144
+ </mgconnector>
145
+ </routers>
146
+ <layout>
147
+ <updates>
148
+ <mgconnector>
149
+ <file>mgconnector.xml</file>
150
+ </mgconnector>
151
+ </updates>
152
+ </layout>
153
+ </frontend>
154
+ <crontab>
155
+ <jobs>
156
+ <mgconnector_cron>
157
+ <schedule><cron_expr>*/1 * * * *</cron_expr></schedule>
158
+ <run><model>mgconnector/observer::run</model></run>
159
+ </mgconnector_cron>
160
+ </jobs>
161
+ </crontab>
162
+ </config>
163
+
app/code/community/Remarkety/Mgconnector/sql/mgconnector_setup/mysql4-install-1.0.0.13.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Install script to version 1.0.0.13
5
+ *
6
+ * @category Remarkety
7
+ * @package Remarkety_Mgconnector
8
+ * @author Piotr Pierzak <piotrek.pierzak@gmail.com>
9
+ */
10
+ $installer = $this;
11
+ $installer->startSetup();
12
+
13
+ $installer->run("
14
+ CREATE TABLE IF NOT EXISTS `{$installer->getTable('mgconnector/queue')}` (
15
+ `queue_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Remarkety queue ID',
16
+ `event_type` varchar(20) NOT NULL COMMENT 'Event_type',
17
+ `payload` text NOT NULL COMMENT 'Payload',
18
+ `attempts` smallint(5) unsigned NOT NULL DEFAULT '1' COMMENT 'Attempts',
19
+ `last_attempt` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'Last_attempt',
20
+ `next_attempt` timestamp NULL DEFAULT NULL COMMENT 'Next_attempt',
21
+ `status` smallint(6) NOT NULL DEFAULT '1' COMMENT 'Status',
22
+ PRIMARY KEY (`queue_id`)
23
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Remarkety queue table';
24
+ ");
25
+
26
+ $installer->endSetup();
app/code/community/Remarkety/Mgconnector/sql/mgconnector_setup/mysql4-upgrade-1.0.0.13-1.0.0.14.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Upgrade script from version 1.0.0.13 to 1.0.0.14
5
+ *
6
+ * @category Remarkety
7
+ * @package Remarkety_Mgconnector
8
+ * @author Piotr Pierzak <piotrek.pierzak@gmail.com>
9
+ */
10
+ $installer = $this;
11
+ $installer->startSetup();
12
+
13
+ $installer->run("
14
+ CREATE TABLE IF NOT EXISTS `{$installer->getTable('mgconnector/queue')}` (
15
+ `queue_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Remarkety queue ID',
16
+ `event_type` varchar(20) NOT NULL COMMENT 'Event_type',
17
+ `payload` text NOT NULL COMMENT 'Payload',
18
+ `attempts` smallint(5) unsigned NOT NULL DEFAULT '1' COMMENT 'Attempts',
19
+ `last_attempt` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'Last_attempt',
20
+ `next_attempt` timestamp NULL DEFAULT NULL COMMENT 'Next_attempt',
21
+ `status` smallint(6) NOT NULL DEFAULT '1' COMMENT 'Status',
22
+ PRIMARY KEY (`queue_id`)
23
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Remarkety queue table';
24
+ ");
25
+
26
+ $installer->endSetup();
app/code/community/Remarkety/Mgconnector/sql/mgconnector_setup/mysql4-upgrade-1.0.0.14-1.0.0.15.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Upgrade script from version 1.0.0.14 to 1.0.0.15
5
+ *
6
+ * @category Remarkety
7
+ * @package Remarkety_Mgconnector
8
+ * @author Piotr Pierzak <piotrek.pierzak@gmail.com>
9
+ */
10
+ $installer = $this;
11
+ $installer->startSetup();
12
+
13
+ $installer->endSetup();
app/code/community/Remarkety/Mgconnector/sql/mgconnector_setup/mysql4-upgrade-1.0.0.14-1.1.0.0.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Upgrade script from version 1.0.0.14 to 1.1.0.0
5
+ *
6
+ * @category Remarkety
7
+ * @package Remarkety_Mgconnector
8
+ * @author Piotr Pierzak <piotrek.pierzak@gmail.com>
9
+ */
10
+ $installer = $this;
11
+ $installer->startSetup();
12
+
13
+ $installer->endSetup();
app/code/community/Remarkety/Mgconnector/sql/mgconnector_setup/mysql4-upgrade-1.1.0.5-1.1.0.6.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Upgrade script from version 1.1.0.5 to 1.1.0.6
5
+ *
6
+ * @category Remarkety
7
+ * @package Remarkety_Mgconnector
8
+ * @author Piotr Pierzak <piotrek.pierzak@gmail.com>
9
+ */
10
+ $installer = $this;
11
+ $installer->startSetup();
12
+
13
+ //@TODO remove installed entry for 0 scope with api key
14
+
15
+ $installer->endSetup();
app/code/community/Remarkety/Mgconnector/sql/mgconnector_setup/mysql4-upgrade-1.1.2.8-1.3.0.0.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Upgrade script from version 1.1.2.8 to 1.3.0.0
5
+ *
6
+ * @category Remarkety
7
+ * @package Remarkety_Mgconnector
8
+ * @author Rafał Andryanczyk <rafal.andryanczyk@gmail.com>
9
+ */
10
+ $installer = $this;
11
+ $installer->startSetup();
12
+
13
+ $installer->getConnection()
14
+ ->addColumn($installer->getTable('salesrule/coupon'),'added_by_remarkety', array(
15
+ 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT,
16
+ 'nullable' => true,
17
+ 'default' => null,
18
+ 'comment' => '1 = added by remarkety api',
19
+ ));
20
+
21
+ $installer->endSetup();
app/design/adminhtml/default/default/template/mgconnector/element.phtml ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $_element = $this->getElement();
3
+ $_note = $_element->getNote();
4
+ $_trId = $_element->getHtmlContainerId();
5
+ $_class = $_element->getFieldsetHtmlClass();
6
+ ?>
7
+ <?php if (!$_element->getNoDisplay()): ?>
8
+ <tr<?php if($_trId): ?> id="<?php echo $_trId ?>"<?php endif; ?>>
9
+ <?php if ($_element->getType()=='hidden'): ?>
10
+ <td colspan="2" class="hidden"><?php echo trim($_element->getElementHtml()) ?></td>
11
+ <?php else: ?>
12
+ <?php $label = $_element->getLabel() ? trim($_element->getLabelHtml()) : false ?>
13
+ <?php if(!empty($label)): ?>
14
+ <td class="label<?php echo $_class ? " {$_class}-label" : ''?>"><?php echo $label ?></td>
15
+ <?php endif; ?>
16
+ <td <?php echo empty($label) ? 'colspan="2"' : '' ?>
17
+ class="<?php echo $_element->hasValueClass() ? $_element->getValueClass() : 'value' ?><?php echo $_class ? " {$_class}-value" : ''?>"
18
+ style="padding: 5px 0;">
19
+ <?php echo trim($_element->getElementHtml()) ?>
20
+ <?php if ($_note): ?>
21
+ <p class="note<?php echo $_class ? " {$_class}-note" : ''?>" id="note_<?php echo $_element->getId()?>"><span><?php echo $_note ?></span></p>
22
+ <?php endif ?>
23
+ </td>
24
+ <?php endif; ?>
25
+ </tr>
26
+ <?php endif; ?>
app/design/adminhtml/default/default/template/mgconnector/install/welcome/store.phtml ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $stores = $this->getStoresStatus();
3
+ $apiValid = $this->checkAPIKey();
4
+
5
+ if (!$apiValid || \Remarkety_Mgconnector_Model_Install::isMultipleStores()) {
6
+ ?>
7
+
8
+ <div class="entry-edit">
9
+ <div class="entry-edit-head">
10
+ <h4 class="icon-head head-edit-form fieldset-legend"><?php echo $this->__('Stores Configuration') ?></h4>
11
+ <div class="form-buttons"></div>
12
+ </div>
13
+ <div class="fieldset " id="general">
14
+ <div class="hor-scroll">
15
+ <?php if(!$apiValid): ?>
16
+ <strong style="color: red;">Attention! Remarkety's API key is not the same as the Magento API key. Please set it <a href="<?php echo $this->getUrl('*/queue/index'); ?>">here</a></strong>
17
+ (<a target="_blank" href="https://support.remarkety.com/hc/en-us/articles/209184646-Synchronizing-the-API-key">More Info</a>).
18
+ <?php endif; ?>
19
+ <?php if (\Remarkety_Mgconnector_Model_Install::isMultipleStores()): ?>
20
+ <table cellspacing="0" class="form-list">
21
+ <tbody>
22
+ <tr>
23
+ <td colspan="2" class="value" style="padding: 5px 0;">
24
+ <ul style="list-style-type:none;margin-left:20px;font-weight:bold;font-size:16px;">
25
+ <?php foreach($stores as $_website): ?>
26
+ <li style="margin-bottom:20px;">
27
+ <?php echo $_website['name']; ?>
28
+ <ul>
29
+ <?php foreach($_website['store_groups'] as $_group): ?>
30
+ <li style="list-style-type:none;margin-left:20px;font-weight:bold;font-size:14px;">
31
+ <?php echo $_group['name']; ?>
32
+ <ul>
33
+ <?php foreach($_group['store_views'] as $_store): ?>
34
+ <li style="list-style-type:none;margin-left:20px;font-weight:bold;font-size:12px;">
35
+ <?php echo $_store['name']; ?>
36
+
37
+ <?php if($_store['isInstalled']): ?>
38
+ <span style="color:green">(<?php echo $this->__('Installed') ?>)</span>
39
+ -
40
+ <?php if($_store['webTracking']): ?>
41
+ <span style="color:green"><?php echo $this->__('Website Tracking Enabled') ?></span>
42
+ - <a href="<?php echo $this->getUrl('*/install/disableWebtracking', array('store' => $_store['id'])) ?>"><?php echo $this->__('Disable Website Tracking'); ?></a>
43
+ <?php else: ?>
44
+ <button id="install_webtracking_button_<?php echo $_store['id'] ?>" title="Webtracking" type="button" class="scalable save" onclick="window.location = '<?php echo $this->getUrl('*/install/installWebtracking', array('store' => $_store['id'])) ?>'" style="">
45
+ <span><span><span>Enable Website Tracking</span></span></span>
46
+ </button>
47
+ <?php endif; ?>
48
+ <?php else: ?>
49
+ <button id="install_button_<?php echo $_store['id'] ?>" title="Save Category" type="button" class="scalable save" onclick="window.location = '<?php echo $this->getUrl('*/install/install', array('mode' => Remarkety_Mgconnector_Model_Install::MODE_INSTALL_LOGIN, 'store' => $_store['id'])) ?>'" style="">
50
+ <span><span><span>Install</span></span></span>
51
+ </button>
52
+ <?php endif; ?>
53
+ </li>
54
+ <?php endforeach; ?>
55
+ </ul>
56
+ </li>
57
+ <?php endforeach; ?>
58
+ </ul>
59
+ </li>
60
+ <?php endforeach; ?>
61
+ </ul>
62
+ </td>
63
+ </tr>
64
+ </tbody>
65
+ </table>
66
+ <?php endif; ?>
67
+ </div>
68
+ </div>
69
+ </div>
70
+ <?php } ?>
app/design/adminhtml/default/default/template/mgconnector/widget/form/renderer/fieldset/element.phtml ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $_element = $this->getElement();
3
+ $_note = $_element->getNote();
4
+ $_trId = $_element->getHtmlContainerId();
5
+ $_class = $_element->getFieldsetHtmlClass();
6
+ ?>
7
+ <?php if (!$_element->getNoDisplay()): ?>
8
+ <tr<?php if($_trId): ?> id="<?php echo $_trId ?>"<?php endif; ?>>
9
+ <?php if ($_element->getType()=='hidden'): ?>
10
+ <td colspan="2" class="hidden"><?php echo trim($_element->getElementHtml()) ?></td>
11
+ <?php else: ?>
12
+ <?php $label = $_element->getLabel() ? trim($_element->getLabelHtml()) : false ?>
13
+ <?php if(!empty($label)): ?>
14
+ <td class="label<?php echo $_class ? " {$_class}-label" : ''?>"><?php echo $label ?></td>
15
+ <?php endif; ?>
16
+ <td <?php echo empty($label) ? 'colspan="2"' : '' ?>
17
+ class="<?php echo $_element->hasValueClass() ? $_element->getValueClass() : 'value' ?><?php echo $_class ? " {$_class}-value" : ''?>"
18
+ style="padding: 5px 0;">
19
+ <?php echo trim($_element->getElementHtml()) ?>
20
+ <?php if ($_note): ?>
21
+ <p class="note<?php echo $_class ? " {$_class}-note" : ''?>" id="note_<?php echo $_element->getId()?>"><span><?php echo $_note ?></span></p>
22
+ <?php endif ?>
23
+ </td>
24
+ <?php endif; ?>
25
+ </tr>
26
+ <?php endif; ?>
app/design/frontend/base/default/layout/mgconnector.xml ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout version="0.1.0">
3
+ <default>
4
+ <reference name="before_body_end">
5
+ <block type="mgconnector/tracking_general" name="mgconnector.tracking_general" template="mgconnector/tracking/general.phtml" />
6
+ </reference>
7
+ </default>
8
+ <catalog_product_view>
9
+ <reference name="before_body_end">
10
+ <block type="mgconnector/tracking_product" name="mgconnector.tracking_product" template="mgconnector/tracking/product_view.phtml" />
11
+ </reference>
12
+ </catalog_product_view>
13
+ </layout>
app/design/frontend/base/default/template/mgconnector/tracking/general.phtml ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php if ($this->isWebtrackingActivated()): ?>
2
+ <script>
3
+ var _rmData = _rmData || [];
4
+ _rmData.push(['setStoreKey', '<?php echo $this->getRemarketyPublicId(); ?>']);
5
+ <?php if(!$this->shouldBypassCache()): ?>
6
+ <?php $_rmEmail = $this->getEmail(); if ($_rmEmail): ?>_rmData.push(["setCustomer", "<?php echo $_rmEmail; ?>"]);<?php endif; ?>
7
+ <?php else: ?>
8
+ (function(d, t) {
9
+ var g = d.createElement(t),
10
+ s = d.getElementsByTagName(t)[0];
11
+ g.src = '<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK) . 'remarkety/webtracking/identify?noMagentoBoosterCache'; ?>&t='+(new Date().getTime())+'&r='+Math.random();
12
+ s.parentNode.insertBefore(g, s);
13
+ }(document, 'script'));
14
+ <?php endif; ?>
15
+ </script>
16
+
17
+ <script>(function(d, t) {
18
+ var g = d.createElement(t),
19
+ s = d.getElementsByTagName(t)[0];
20
+ g.src = 'https://s3.amazonaws.com/downloads.remarkety.com/webtracking/remarkety.js';
21
+ s.parentNode.insertBefore(g, s);
22
+ }(document, 'script'));</script>
23
+ <?php endif; ?>
app/design/frontend/base/default/template/mgconnector/tracking/product_view.phtml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php if ($this->isWebtrackingActivated()): ?>
2
+ <script>
3
+ var _rmData = _rmData || [];
4
+ _rmData.push(['productView', {
5
+ productId: <?php echo json_encode($this->getActiveProduct()->getId()); ?>,
6
+ productCategories: <?php echo json_encode($this->getCategoryNames()); ?>,
7
+ productCategoriesIds: <?php echo json_encode($this->getCategoryIds()); ?>,
8
+ }]);
9
+ </script>
10
+ <?php endif; ?>
app/etc/modules/Remarkety_Mgconnector.xml ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <config>
2
+ <modules>
3
+ <Remarkety_Mgconnector>
4
+ <active>true</active>
5
+ <codePool>community</codePool>
6
+ <depends>
7
+ <Mage_Api />
8
+ </depends>
9
+ </Remarkety_Mgconnector>
10
+ </modules>
11
+ </config>
12
+
package.xml ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Remarkety_Mgconnector</name>
4
+ <version>1.4.3.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://www.gnu.org/licenses/gpl-3.0.html">GPL v3</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Remarkety Magento Connector</summary>
10
+ <description>Remarkety Magento Connector</description>
11
+ <notes>No comments</notes>
12
+ <date>2016-06-07</date>
13
+ <time>8-35-48</time>
14
+ <contents>
15
+ <target name="magecommunity">
16
+ <dir name="Remarkety"><dir name="Mgconnector"><dir name="Block"><dir name="Adminhtml"><dir name="Configuration"><dir name="Complete"><file name="Form.php" hash="dc799532128513364fc3afd17eabb78b"/></dir><file name="Complete.php" hash="b9f7b4ecbd2be587c0efbd16523b167e"/><dir name="Configuration"><file name="Form.php" hash="89b286409ad9d64ae8e51e314198f427"/></dir><file name="Configuration.php" hash="67b3b564c2c3123301f5f97b2b258a7a"/><dir name="Install"><file name="Form.php" hash="59541fe2ad9a49b9fb56a41f00e6a591"/></dir><file name="Install.php" hash="f631fcdfd86d2bc416eb1ad4422fc20c"/><dir name="Upgrade"><file name="Form.php" hash="598f83eca99d0153537e22f9ee6b1934"/></dir><file name="Upgrade.php" hash="c672741b0407f108d2266dd939590846"/></dir><file name="Configuration.php" hash="bf0c9aabe92f669694e0699c009b2a9c"/><dir name="Install"><dir name="Complete"><file name="Form.php" hash="5992149b9ff2d2a7c2b008d98098362d"/></dir><file name="Complete.php" hash="452944c613b88ede358ee4dacd562d05"/><dir name="Install"><dir name="Create"><file name="Form.php" hash="65d98f1449ce6af413a3185692e07533"/></dir><file name="Create.php" hash="0d3182923fd5542e3d0a757625a85ae4"/><dir name="Login"><file name="Form.php" hash="a58c19056e47c7851eb6a5f40517f757"/></dir><file name="Login.php" hash="3ee61a883f843c55b1b32a328af84322"/></dir><dir name="Upgrade"><file name="Form.php" hash="6f4e2ac19d30115de4e275fdb8dca5b6"/></dir><file name="Upgrade.php" hash="f16ba61a8c86007bbc0a980e8faeade1"/><dir name="Welcome"><file name="Form.php" hash="58cb26cc7555498bd0367c77a99c8d60"/><file name="Store.php" hash="9f3b5c7bbd9f4d7201189598e5a64cc4"/></dir><file name="Welcome.php" hash="86589c79b5c38ea5f25d58ac932f33cb"/></dir><dir name="Queue"><dir name="Configure"><file name="Form.php" hash="69619798add1783da4b74b521264d987"/></dir><file name="Configure.php" hash="03d5ebf7644462904c439d172cde3afc"/><dir name="Grid"><dir name="Column"><dir name="Renderer"><file name="EventType.php" hash="4ac5971c368b70efa96b4c8297c85c3c"/><file name="Status.php" hash="ec57ddafc2515b952958e6ace6de22ec"/></dir></dir></dir><file name="Grid.php" hash="74d5f3b18d76cdf8219e2d39a83a2f7c"/></dir><file name="Queue.php" hash="2c905cc54a6c08d4d73a392d5b95a25c"/></dir><dir name="Tracking"><file name="Base.php" hash="5e0f245ac5ee59d2f6c6f35087059b56"/><file name="General.php" hash="9ca2796c6f2bf9233553e6b782f3722b"/><file name="Product.php" hash="3a0c1b1a5fcbd23d1dcd04714742ebe9"/></dir></dir><dir name="Helper"><file name="Data.php" hash="b27f970b943e6e989e9061275cc25c7b"/><file name="Links.php" hash="3eb52ad30d952c8b3c697323a5bdc0eb"/><file name="Urls.php" hash="ce396940c96bf8139da8ec59bb498acf"/></dir><dir name="Model"><dir name="Core"><file name="Api.php" hash="948c7965f7fe9d044b532314aaa8e0f9"/></dir><file name="Core.php" hash="74c15a36f270fbb3b799034780b0ed5a"/><file name="Install.php" hash="a932ce10c0387b00147e40e9f42e20d9"/><file name="Observer.php" hash="8975e5b8d9802b616d9b177cd1e58599"/><file name="Queue.php" hash="3a0fda4b18ec947c20e6e81cc1e995de"/><file name="Recovery.php" hash="bd856fdd5788e00bcf29a67446ad8ef1"/><file name="Request.php" hash="47e81216d7bca3f0aba93bf816298221"/><dir name="Resource"><file name="Coupon.php" hash="6079c05e422e9c1ad5327fc881cee7e3"/><dir name="Queue"><file name="Collection.php" hash="ce59b04c8a8146f5094d6622134885d3"/></dir><file name="Queue.php" hash="971a539849d0cde2e413b0642403a6ca"/><dir name="Rule"><file name="Collection.php" hash="d57fff76c25dab67dbdbbd57b3afdfdf"/></dir><file name="Setup.php" hash="13253a5b7a2749f4a3bc84e32e31e27c"/></dir><file name="Webtracking.php" hash="4b2d9d73dcc8d68b40f375f6c55c4999"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="ConfigureController.php" hash="b4e51acf22ea798e2d2144a4672bc30f"/><file name="InstallController.php" hash="cebbe5f80c59d6fbc18eecff20e7d432"/><file name="MgconnectorController.php" hash="a8e55464624c5fa9e9641cf97f963b3b"/><file name="QueueController.php" hash="70d05e61daf651dad840b04f21e3022e"/></dir><file name="RecoveryController.php" hash="0a53efaef9019c6b661fe494067473e3"/><file name="WebtrackingController.php" hash="2e1b75f58ada4a091a8d02a04d508f89"/></dir><dir name="etc"><file name="adminhtml.xml" hash="c555aaf95943f74e1c29032e3ed385a1"/><file name="api.xml" hash="9f6d5fd3330bb0640f97efc3f819e684"/><file name="config.xml" hash="c0ac4e7d6b0f6598ded6128d65cb61f4"/></dir><dir name="sql"><dir name="mgconnector_setup"><file name="mysql4-install-1.0.0.13.php" hash="d1033ffd3d6b13af28ad4082d5744c25"/><file name="mysql4-upgrade-1.0.0.13-1.0.0.14.php" hash="db871ba73f3dcc7abfb806991edc12f1"/><file name="mysql4-upgrade-1.0.0.14-1.0.0.15.php" hash="c9ced7a4a2e85c9d594e9f97320cab58"/><file name="mysql4-upgrade-1.0.0.14-1.1.0.0.php" hash="fd445e8c179cdb2718a85adec05c5343"/><file name="mysql4-upgrade-1.1.0.5-1.1.0.6.php" hash="e24831cfd077827ba545f7ea71669729"/><file name="mysql4-upgrade-1.1.2.8-1.3.0.0.php" hash="97bbb9e411bcd45f875f29fcc8c8b420"/></dir></dir></dir></dir></target>
17
+ <target name="mageetc">
18
+ <dir name="modules"><file name="Remarkety_Mgconnector.xml" hash="d584b234f653fbf34376e7dcb8caf117"/></dir></target>
19
+ <target name="magedesign">
20
+ <dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="mgconnector"><file name="element.phtml" hash="b956df05d4eeb30f5199a75deab74fbc"/><dir name="install"><dir name="welcome"><file name="store.phtml" hash="3839928b62115329e0f3af442f44774d"/></dir></dir><dir name="widget"><dir name="form"><dir name="renderer"><dir name="fieldset"><file name="element.phtml" hash="abd5b9848b714779ddecb4536c846395"/></dir></dir></dir></dir></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="mgconnector.xml" hash="81584e822ae52179c8fb1dfc48cb8a9f"/></dir><dir name="template"><dir name="mgconnector"><dir name="tracking"><file name="general.phtml" hash="9da11c45059c094753ea65b2067be9a7"/><file name="product_view.phtml" hash="cf48e30b61979eaed3813b422959937f"/></dir></dir></dir></dir></dir></dir></target>
21
+ </contents>
22
+ <compatible/>
23
+ <dependencies>
24
+ <required>
25
+ <php>
26
+ <min>5.1.0</min>
27
+ <max>6.0.0</max>
28
+ </php>
29
+ </required>
30
+ </dependencies>
31
+ <authors><author><email>support@remarkety.com</email><name>Remarkety</name><user>remarkety</user></author></authors></package>