Remarkety_Mgconnector - Version 1.5.1.2

Version Notes

No comments

Download this release

Release Info

Developer Remarkety
Extension Remarkety_Mgconnector
Version 1.5.1.2
Comparing to
See all releases


Code changes from version 1.4.10.3 to 1.5.1.2

Files changed (22) hide show
  1. CHANGELOG.txt +25 -0
  2. app/code/community/Remarkety/Mgconnector/Block/Adminhtml/Install/Welcome/Store.php +12 -1
  3. app/code/community/Remarkety/Mgconnector/Block/Adminhtml/Queue/Configure/Form.php +53 -27
  4. app/code/community/Remarkety/Mgconnector/Block/Adminhtml/Queue/Grid.php +29 -21
  5. app/code/community/Remarkety/Mgconnector/Block/Tracking/Base.php +6 -1
  6. app/code/community/Remarkety/Mgconnector/Helper/Configuration.php +87 -1
  7. app/code/community/Remarkety/Mgconnector/Model/Core.php +244 -16
  8. app/code/community/Remarkety/Mgconnector/Model/Core/Api.php +49 -0
  9. app/code/community/Remarkety/Mgconnector/Model/Extension/RewardPoints/Observer/AbstractObserver.php +2 -3
  10. app/code/community/Remarkety/Mgconnector/Model/Extension/RewardPoints/Observer/MagestoreRewardPoints.php +9 -0
  11. app/code/community/Remarkety/Mgconnector/Model/Install.php +17 -0
  12. app/code/community/Remarkety/Mgconnector/Model/Observer.php +755 -164
  13. app/code/community/Remarkety/Mgconnector/Model/Webtracking.php +32 -4
  14. app/code/community/Remarkety/Mgconnector/controllers/Adminhtml/InstallController.php +62 -6
  15. app/code/community/Remarkety/Mgconnector/controllers/Adminhtml/QueueController.php +21 -9
  16. app/code/community/Remarkety/Mgconnector/etc/api.xml +18 -0
  17. app/code/community/Remarkety/Mgconnector/etc/config.xml +105 -4
  18. app/code/community/Remarkety/Mgconnector/sql/mgconnector_setup/mysql4-upgrade-1.4.10.4-1.5.0.0.php +24 -0
  19. app/code/community/Remarkety/Mgconnector/sql/mgconnector_setup/mysql4-upgrade-1.5.0.0-1.5.0.1.php +24 -0
  20. app/design/adminhtml/default/default/template/mgconnector/install/welcome/store.phtml +10 -2
  21. app/design/frontend/base/default/template/mgconnector/tracking/general.phtml +1 -1
  22. package.xml +5 -5
CHANGELOG.txt CHANGED
@@ -1,3 +1,28 @@
1
1.4.10.2
2
-------
3
Products should not be taken from flat catalog table if enabled
1
+ 1.5.1.2
2
+ --------
3
+ Detect cart email from session if visitor subscribed before creating the cart
4
+
5
+ 1.5.1.1
6
+ --------
7
+ Configurable using Magento's internal methods to get product url
8
+
9
+ 1.5.1.0
10
+ --------
11
+ Support push events (for transactional emails and more)
12
+
13
+ 1.4.10.5
14
+ --------
15
+ Change webtracking source script to be from CloudFront CDN
16
+
17
+ 1.4.10.4
18
+ --------
19
+ Get customer birthday
20
+
21
+ 1.4.10.3
22
+ --------
23
+ Bugfix - Properly unsubscribe users. Before, would create an empty unsubscribe record if the email did not exist
24
+ (Thanks to John Carlson @ www.surethingweb.com)
25
+
26
1.4.10.2
27
-------
28
Products should not be taken from flat catalog table if enabled
app/code/community/Remarkety/Mgconnector/Block/Adminhtml/Install/Welcome/Store.php CHANGED
@@ -18,6 +18,8 @@ class Remarkety_Mgconnector_Block_Adminhtml_Install_Welcome_Store extends Mage_A
18
*/
19
$wtModel = Mage::getModel('mgconnector/webtracking');
20
21
$stores = array();
22
23
foreach (Mage::app()->getWebsites() as $_website) {
@@ -34,7 +36,7 @@ class Remarkety_Mgconnector_Block_Adminhtml_Install_Welcome_Store extends Mage_A
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->getGroupId()]['store_views'][$_store->getCode()] = array(
39
'name' => $_store->getName(),
40
'id' => $_store->getStoreId(),
@@ -58,4 +60,13 @@ class Remarkety_Mgconnector_Block_Adminhtml_Install_Welcome_Store extends Mage_A
58
return false;
59
}
60
}
61
}
18
*/
19
$wtModel = Mage::getModel('mgconnector/webtracking');
20
21
+
22
+
23
$stores = array();
24
25
foreach (Mage::app()->getWebsites() as $_website) {
36
37
foreach ($_group->getStores() as $_store) {
38
$isInstalled = $_store->getConfig(Remarkety_Mgconnector_Model_Install::XPATH_INSTALLED);
39
+ $webtracking = $wtModel->isEnabled($_store->getStoreId());
40
$stores[$_website->getCode()]['store_groups'][$_group->getGroupId()]['store_views'][$_store->getCode()] = array(
41
'name' => $_store->getName(),
42
'id' => $_store->getStoreId(),
60
return false;
61
}
62
}
63
+
64
+ public function isWebhooksEnabled(){
65
+ /**
66
+ * @var $configHelper Remarkety_Mgconnector_Helper_Configuration
67
+ */
68
+ $configHelper = Mage::helper('mgconnector/configuration');
69
+
70
+ return $configHelper->isWebhooksEnabled();
71
+ }
72
}
app/code/community/Remarkety/Mgconnector/Block/Adminhtml/Queue/Configure/Form.php CHANGED
@@ -16,12 +16,12 @@ class Remarkety_Mgconnector_Block_Adminhtml_Queue_Configure_Form extends Mage_Ad
16
*/
17
protected function _prepareForm()
18
{
19
- $form = new Varien_Data_Form(
20
array(
21
'id' => 'edit_form',
22
'action' => $this->getUrl('*/queue/save'),
23
'method' => 'post',
24
- )
25
);
26
$form->setFieldContainerIdPrefix('data');
27
$form->setUseContainer(true);
@@ -34,23 +34,23 @@ class Remarkety_Mgconnector_Block_Adminhtml_Queue_Configure_Form extends Mage_Ad
34
)
35
);
36
37
- $fieldset->addField(
38
'mode', 'hidden', array(
39
'name' => 'data[mode]',
40
'value' => 'configuration',
41
- )
42
);
43
44
if(!$this->checkAPIKey()) {
45
- $fieldset->addField(
46
'api_warning', 'note', array(
47
'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>'.
48
' <a target="_blank" href="https://support.remarkety.com/hc/en-us/articles/209184646-Synchronizing-the-API-key">More Info</a>.',
49
- )
50
);
51
}
52
53
- $fieldset->addField(
54
'api_key', 'text', array(
55
'label' => $this->__('API Key:'),
56
'name' => 'data[api_key]',
@@ -60,10 +60,10 @@ class Remarkety_Mgconnector_Block_Adminhtml_Queue_Configure_Form extends Mage_Ad
60
) . '</small>',
61
'value' => Mage::getStoreConfig('remarkety/mgconnector/api_key'),
62
'style' => 'float:left',
63
- )
64
);
65
66
- $fieldset->addField(
67
'intervals', 'text', array(
68
'label' => $this->__('Intervals:'),
69
'name' => 'data[intervals]',
@@ -77,10 +77,10 @@ class Remarkety_Mgconnector_Block_Adminhtml_Queue_Configure_Form extends Mage_Ad
77
) . '</small>',
78
'value' => Mage::getStoreConfig('remarkety/mgconnector/intervals'),
79
'style' => 'float:left',
80
- )
81
);
82
83
- $fieldset->addField(
84
'bypasscache', 'checkbox', array(
85
'label' => $this->__('Bypass page cache for website tracking:'),
86
'name' => 'data[bypasscache]',
@@ -90,10 +90,10 @@ class Remarkety_Mgconnector_Block_Adminhtml_Queue_Configure_Form extends Mage_Ad
90
'value' => 1,
91
'checked' => \Remarkety_Mgconnector_Model_Webtracking::getBypassCache() ? 'checked' : '',
92
'style' => 'float:left',
93
- )
94
);
95
96
- $fieldset->addField(
97
'markgroupparent', 'checkbox', array(
98
'label' => $this->__('Mark grouped product as parent of associated products'),
99
'name' => 'data[markgroupparent]',
@@ -103,36 +103,62 @@ class Remarkety_Mgconnector_Block_Adminhtml_Queue_Configure_Form extends Mage_Ad
103
'value' => 1,
104
'checked' => Mage::getStoreConfig('remarkety/mgconnector/mark_group_parent') ? 'checked' : '',
105
'style' => 'float:left',
106
- )
107
);
108
109
- $fieldset->addField(
110
'simpleproductstandalone', 'checkbox', array(
111
- 'label' => $this->__('Get images and urls independently for simple products'),
112
- 'name' => 'data[simpleproductstandalone]',
113
- 'after_element_html' => '<small style="float:left;width:100%;">' . $this->__(
114
- 'Enable this checkbox if simple products that are related to configurable products have their own images and urls'
115
- ) . '</small>',
116
- 'value' => 1,
117
- 'checked' => Mage::getStoreConfig('remarkety/mgconnector/configurable_standalone') ? 'checked' : '',
118
- 'style' => 'float:left',
119
- )
120
);
121
122
- $button = $fieldset->addField(
123
'button', 'note', array(
124
'label' => false,
125
'name' => 'button',
126
'after_element_html' => '<button type="button" class="save" onclick="editForm.submit();"><span><span>'
127
. $this->__('Save') . '</span></span></button>',
128
- )
129
);
130
$button->getRenderer()->setTemplate('mgconnector/element.phtml');
131
132
return parent::_prepareForm();
133
}
134
135
- private function checkAPIKey()
136
{
137
try {
138
$uModel = Mage::getModel('api/user');
16
*/
17
protected function _prepareForm()
18
{
19
+ $form = new Varien_Data_Form(
20
array(
21
'id' => 'edit_form',
22
'action' => $this->getUrl('*/queue/save'),
23
'method' => 'post',
24
+ )
25
);
26
$form->setFieldContainerIdPrefix('data');
27
$form->setUseContainer(true);
34
)
35
);
36
37
+ $fieldset->addField(
38
'mode', 'hidden', array(
39
'name' => 'data[mode]',
40
'value' => 'configuration',
41
+ )
42
);
43
44
if(!$this->checkAPIKey()) {
45
+ $fieldset->addField(
46
'api_warning', 'note', array(
47
'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>'.
48
' <a target="_blank" href="https://support.remarkety.com/hc/en-us/articles/209184646-Synchronizing-the-API-key">More Info</a>.',
49
+ )
50
);
51
}
52
53
+ $fieldset->addField(
54
'api_key', 'text', array(
55
'label' => $this->__('API Key:'),
56
'name' => 'data[api_key]',
60
) . '</small>',
61
'value' => Mage::getStoreConfig('remarkety/mgconnector/api_key'),
62
'style' => 'float:left',
63
+ )
64
);
65
66
+ $fieldset->addField(
67
'intervals', 'text', array(
68
'label' => $this->__('Intervals:'),
69
'name' => 'data[intervals]',
77
) . '</small>',
78
'value' => Mage::getStoreConfig('remarkety/mgconnector/intervals'),
79
'style' => 'float:left',
80
+ )
81
);
82
83
+ $fieldset->addField(
84
'bypasscache', 'checkbox', array(
85
'label' => $this->__('Bypass page cache for website tracking:'),
86
'name' => 'data[bypasscache]',
90
'value' => 1,
91
'checked' => \Remarkety_Mgconnector_Model_Webtracking::getBypassCache() ? 'checked' : '',
92
'style' => 'float:left',
93
+ )
94
);
95
96
+ $fieldset->addField(
97
'markgroupparent', 'checkbox', array(
98
'label' => $this->__('Mark grouped product as parent of associated products'),
99
'name' => 'data[markgroupparent]',
103
'value' => 1,
104
'checked' => Mage::getStoreConfig('remarkety/mgconnector/mark_group_parent') ? 'checked' : '',
105
'style' => 'float:left',
106
+ )
107
);
108
109
+ $fieldset->addField(
110
'simpleproductstandalone', 'checkbox', array(
111
+ 'label' => $this->__('Get images and urls independently for simple products'),
112
+ 'name' => 'data[simpleproductstandalone]',
113
+ 'after_element_html' => '<small style="float:left;width:100%;">' . $this->__(
114
+ 'Enable this checkbox if simple products that are related to configurable products have their own images and urls'
115
+ ) . '</small>',
116
+ 'value' => 1,
117
+ 'checked' => Mage::getStoreConfig('remarkety/mgconnector/configurable_standalone') ? 'checked' : '',
118
+ 'style' => 'float:left',
119
+ )
120
+ );
121
+
122
+ $fieldset->addField(
123
+ 'product_url_internal', 'checkbox', array(
124
+ 'label' => $this->__('Use Magento\'s internal methods to get product urls'),
125
+ 'name' => 'data[product_url_internal]',
126
+ 'after_element_html' => '<small style="float:left;width:100%;">' . $this->__(
127
+ 'Enabling this feature may cause performance issues.'
128
+ ) . '</small>',
129
+ 'value' => 1,
130
+ 'checked' => Mage::getStoreConfig(Remarkety_Mgconnector_Helper_Configuration::XPATH_INTERNAL_PRODUCT_URL) ? 'checked' : '',
131
+ 'style' => 'float:left',
132
+ )
133
);
134
135
+ $fieldset->addField(
136
+ 'forceasyncwebhooks', 'checkbox', array(
137
+ 'label' => $this->__('Force webhooks to make requests asynchronous using queue'),
138
+ 'name' => 'data[forceasyncwebhooks]',
139
+ 'after_element_html' => '<small style="float:left;width:100%;">' . $this->__(
140
+ 'Enabling this checkbox will cause a delay sending Remarkety transactional events'
141
+ ) . '</small>',
142
+ 'value' => 1,
143
+ 'checked' => Mage::getStoreConfig('remarkety/mgconnector/forceasyncwebhooks') ? 'checked' : '',
144
+ 'style' => 'float:left',
145
+ )
146
+ );
147
+
148
+ $button = $fieldset->addField(
149
'button', 'note', array(
150
'label' => false,
151
'name' => 'button',
152
'after_element_html' => '<button type="button" class="save" onclick="editForm.submit();"><span><span>'
153
. $this->__('Save') . '</span></span></button>',
154
+ )
155
);
156
$button->getRenderer()->setTemplate('mgconnector/element.phtml');
157
158
return parent::_prepareForm();
159
}
160
161
+ private function checkAPIKey()
162
{
163
try {
164
$uModel = Mage::getModel('api/user');
app/code/community/Remarkety/Mgconnector/Block/Adminhtml/Queue/Grid.php CHANGED
@@ -47,50 +47,58 @@ class Remarkety_Mgconnector_Block_Adminhtml_Queue_Grid extends Mage_Adminhtml_Bl
47
{
48
$helper = Mage::helper('mgconnector');
49
50
- $this->addColumn(
51
'queue_id', array(
52
'header' => $helper->__('Queue #'),
53
'width' => '50px',
54
'type' => 'number',
55
'index' => 'queue_id'
56
- )
57
);
58
- $this->addColumn(
59
'event_type', array(
60
'header' => $helper->__('Event Type'),
61
'index' => 'event_type',
62
'renderer' => 'Remarkety_Mgconnector_Block_Adminhtml_Queue_Grid_Column_Renderer_EventType',
63
- )
64
);
65
- $this->addColumn(
66
'status', array(
67
'header' => $helper->__('Status'),
68
'width' => '200px',
69
'renderer' => 'Remarkety_Mgconnector_Block_Adminhtml_Queue_Grid_Column_Renderer_Status',
70
'index' => 'status'
71
- )
72
);
73
- $this->addColumn(
74
'attempts', array(
75
'header' => $helper->__('Attempts'),
76
- 'index' => 'attempts'
77
- )
78
);
79
- $this->addColumn(
80
'last_attempt', array(
81
'header' => $helper->__('Last Attempt'),
82
'width' => '200px',
83
'type' => 'datetime',
84
'index' => 'last_attempt'
85
- )
86
);
87
- $this->addColumn(
88
'next_attempt', array(
89
- 'header' => $helper->__('Next Attempt'),
90
- 'width' => '200px',
91
- 'type' => 'datetime',
92
- 'index' => 'next_attempt'
93
- )
94
);
95
96
return parent::_prepareColumns();
@@ -112,19 +120,19 @@ class Remarkety_Mgconnector_Block_Adminhtml_Queue_Grid extends Mage_Adminhtml_Bl
112
$this->setMassactionIdField('queue_id');
113
$this->getMassactionBlock()->setFormFieldName('queue');
114
115
- $this->getMassactionBlock()->addItem(
116
'resend', array(
117
'label' => $this->__('Resend'),
118
'url' => $this->getUrl('*/*/massResend')
119
- )
120
);
121
122
- $this->getMassactionBlock()->addItem(
123
'delete', array(
124
'label' => $this->__('Delete'),
125
'url' => $this->getUrl('*/*/massDelete'),
126
'confirm' => $this->__('Really delete all these events?')
127
- )
128
);
129
130
return $this;
47
{
48
$helper = Mage::helper('mgconnector');
49
50
+ $this->addColumn(
51
'queue_id', array(
52
'header' => $helper->__('Queue #'),
53
'width' => '50px',
54
'type' => 'number',
55
'index' => 'queue_id'
56
+ )
57
);
58
+ $this->addColumn(
59
'event_type', array(
60
'header' => $helper->__('Event Type'),
61
'index' => 'event_type',
62
'renderer' => 'Remarkety_Mgconnector_Block_Adminhtml_Queue_Grid_Column_Renderer_EventType',
63
+ )
64
);
65
+ $this->addColumn(
66
'status', array(
67
'header' => $helper->__('Status'),
68
'width' => '200px',
69
'renderer' => 'Remarkety_Mgconnector_Block_Adminhtml_Queue_Grid_Column_Renderer_Status',
70
'index' => 'status'
71
+ )
72
);
73
+ $this->addColumn(
74
'attempts', array(
75
'header' => $helper->__('Attempts'),
76
+ 'index' => 'attempts',
77
+ 'width' => '200px'
78
+ )
79
);
80
+ $this->addColumn(
81
'last_attempt', array(
82
'header' => $helper->__('Last Attempt'),
83
'width' => '200px',
84
'type' => 'datetime',
85
'index' => 'last_attempt'
86
+ )
87
);
88
+ $this->addColumn(
89
'next_attempt', array(
90
+ 'header' => $helper->__('Next Attempt'),
91
+ 'width' => '200px',
92
+ 'type' => 'datetime',
93
+ 'index' => 'next_attempt'
94
+ )
95
+ );
96
+
97
+ $this->addColumn(
98
+ 'last_error', array(
99
+ 'header' => $helper->__('Last Error Message'),
100
+ 'index' => 'last_error_message'
101
+ )
102
);
103
104
return parent::_prepareColumns();
120
$this->setMassactionIdField('queue_id');
121
$this->getMassactionBlock()->setFormFieldName('queue');
122
123
+ $this->getMassactionBlock()->addItem(
124
'resend', array(
125
'label' => $this->__('Resend'),
126
'url' => $this->getUrl('*/*/massResend')
127
+ )
128
);
129
130
+ $this->getMassactionBlock()->addItem(
131
'delete', array(
132
'label' => $this->__('Delete'),
133
'url' => $this->getUrl('*/*/massDelete'),
134
'confirm' => $this->__('Really delete all these events?')
135
+ )
136
);
137
138
return $this;
app/code/community/Remarkety/Mgconnector/Block/Tracking/Base.php CHANGED
@@ -3,7 +3,12 @@ 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()
3
{
4
public function isWebtrackingActivated()
5
{
6
+ $store = Mage::app()->getStore();
7
+ /**
8
+ * @var $m Remarkety_Mgconnector_Model_Webtracking
9
+ */
10
+ $m = Mage::getModel('mgconnector/webtracking');
11
+ return ($m->isEnabled($store));
12
}
13
14
public function getRemarketyPublicId()
app/code/community/Remarkety/Mgconnector/Helper/Configuration.php CHANGED
@@ -3,8 +3,11 @@
3
class Remarkety_Mgconnector_Helper_Configuration extends Mage_Core_Helper_Abstract
4
{
5
private $_cache = array();
6
7
- public function getValue($key, $default = null)
8
{
9
// Check if the key is in our cache
10
if (key_exists($key, $this->_cache))
@@ -27,4 +30,87 @@ class Remarkety_Mgconnector_Helper_Configuration extends Mage_Core_Helper_Abstra
27
return $default;
28
29
}
30
}
3
class Remarkety_Mgconnector_Helper_Configuration extends Mage_Core_Helper_Abstract
4
{
5
private $_cache = array();
6
+ private $_installedStores = false;
7
8
+ const XPATH_INTERNAL_PRODUCT_URL = 'remarkety/mgconnector/product_url_internal';
9
+
10
+ public function getValue($key, $default = null)
11
{
12
// Check if the key is in our cache
13
if (key_exists($key, $this->_cache))
30
return $default;
31
32
}
33
+
34
+ /**
35
+ * Get a list of stores that has Remarkety installed
36
+ * @return array
37
+ */
38
+ public function getInstalledStores(){
39
+ if($this->_installedStores === false) {
40
+ $this->_installedStores = array();
41
+ $stores = Mage::app()->getStores(false);
42
+ /**
43
+ * @var $store Mage_Core_Model_Store
44
+ */
45
+ foreach ($stores as $storeId => $store) {
46
+ $isInstalled = $store->getConfig(Remarkety_Mgconnector_Model_Install::XPATH_INSTALLED);
47
+ if(!empty($isInstalled)){
48
+ $this->_installedStores[] = $storeId;
49
+ }
50
+ }
51
+ }
52
+ return $this->_installedStores;
53
+ }
54
+
55
+ /**
56
+ * Check if a specific store id has Remarkety installed
57
+ * @param $storeId
58
+ * @return bool
59
+ */
60
+ public function isStoreInstalled($storeId){
61
+ if(!$this->_installedStores) {
62
+ /**
63
+ * @var $store Mage_Core_Model_Store
64
+ */
65
+ $store = Mage::app()->getStore($storeId);
66
+ $isInstalled = $store->getConfig(Remarkety_Mgconnector_Model_Install::XPATH_INSTALLED);
67
+ return !empty($isInstalled);
68
+ }
69
+ return in_array($storeId, $this->getInstalledStores());
70
+ }
71
+
72
+ /**
73
+ * Check if a specific store id has Remarkety installed
74
+ * @param $storeId
75
+ * @return bool
76
+ */
77
+ public function isWebhooksEnabled($storeId = null){
78
+ /**
79
+ * @var $store Mage_Core_Model_Store
80
+ */
81
+ $isInstalled = Mage::getStoreConfig(Remarkety_Mgconnector_Model_Install::XPATH_WEBHOOKS_ENABLED);
82
+
83
+ if(!empty($isInstalled)){
84
+ if(empty($storeId)){
85
+ return true;
86
+ }
87
+
88
+ $store = Mage::app()->getStore($storeId);
89
+ $storeId = $this->getRemarketyPublicId($store);
90
+ return !empty($storeId);
91
+ }
92
+ return false;
93
+ }
94
+
95
+ public function isProductWebhooksEnabled(){
96
+ $isDisabled = Mage::getStoreConfig(Remarkety_Mgconnector_Model_Install::XPATH_PRODUCT_WEBHOOKS_DISABLED);
97
+ return empty($isDisabled);
98
+ }
99
+
100
+ /**
101
+ * @param null $store
102
+ * @return bool
103
+ */
104
+ public function getRemarketyPublicId($store = null)
105
+ {
106
+ $store = is_null($store) ? Mage::app()->getStore() : $store;
107
+ $store_id = is_numeric($store) ? $store : $store->getStoreId();
108
+ $id = Mage::getStoreConfig(Remarkety_Mgconnector_Model_Webtracking::RM_STORE_ID, $store_id);
109
+ return (empty($id) || is_null($id)) ? false : $id;
110
+ }
111
+
112
+ public static function getProductUrlFromMagento(){
113
+ $val = Mage::getStoreConfig(self::XPATH_INTERNAL_PRODUCT_URL);
114
+ return !empty($val);
115
+ }
116
}
app/code/community/Remarkety/Mgconnector/Model/Core.php CHANGED
@@ -39,6 +39,7 @@ class Remarkety_Mgconnector_Model_Core extends Mage_Core_Model_Abstract
39
private $response_mask = array(
40
'customer' => array(
41
'entity_id',
42
'firstname',
43
'lastname',
44
'email',
@@ -1251,6 +1252,7 @@ class Remarkety_Mgconnector_Model_Core extends Mage_Core_Model_Abstract
1251
$this->_debug(__FUNCTION__, "Start - prod id " . $product->getId(), null, '');
1252
$url = '';
1253
$visibility = $product->getVisibility();
1254
if ($visibility == 1 || !in_array($product->type_id, $this->_groupedTypes)) {
1255
$parentId = null;
1256
if (!$this->simpleProductsStandalone) {
@@ -1266,6 +1268,7 @@ class Remarkety_Mgconnector_Model_Core extends Mage_Core_Model_Abstract
1266
if (!is_null($parentId)) {
1267
$this->_debug(__FUNCTION__, "parent id " . $parentId, null, '');
1268
$product_id = $parentId;
1269
} else {
1270
$product_id = $product->getId();
1271
}
@@ -1273,30 +1276,38 @@ class Remarkety_Mgconnector_Model_Core extends Mage_Core_Model_Abstract
1273
$product_id = $product->getId();
1274
}
1275
1276
try {
1277
- $url = Mage::helper('mgconnector/urls')->getValue($product_id, $mage_store_view_id);
1278
- if (!empty($url)) {
1279
- $url = $storeUrl . $url;
1280
- if (Mage::getStoreConfig('catalog/seo/product_url_suffix', $mage_store_view_id)) {
1281
- $url .= Mage::getStoreConfig('catalog/seo/product_url_suffix', $mage_store_view_id);
1282
}
1283
}
1284
- $this->_debug(__FUNCTION__, "after setStoreId getProductUrl: " . $url, null, '');
1285
} catch (Exception $e) {
1286
$this->_log(__FUNCTION__, "failed after setStoreId: ", $e->getMessage(), '');
1287
}
1288
1289
- if (!empty($url)) {
1290
- return $url;
1291
- } else {
1292
- $getProductUrl = $product->getProductUrl();
1293
- $this->_debug(__FUNCTION__, "getProductUrl: " . $getProductUrl, null, '');
1294
- return $getProductUrl;
1295
}
1296
1297
}
1298
1299
- public function getImageUrl($product, $type = 'image', $mage_store_view_id)
1300
{
1301
1302
$url = '';
@@ -1315,7 +1326,7 @@ class Remarkety_Mgconnector_Model_Core extends Mage_Core_Model_Abstract
1315
1316
if (!is_null($parentId)) {
1317
$this->_debug(__FUNCTION__, null, "parent id: " . $parentId, '');
1318
- $product = $this->loadProduct($parentId, $mage_store_view_id);
1319
}
1320
} else {
1321
$this->_debug(__FUNCTION__, null, "configurable prod id" . $product->getId(), '');
@@ -1398,7 +1409,8 @@ class Remarkety_Mgconnector_Model_Core extends Mage_Core_Model_Abstract
1398
$this->_debug(__FUNCTION__, REMARKETY_MGCONNECTOR_CALLED_STATUS, null, $myArgs);
1399
$subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($email);
1400
1401
- if (empty($subscriber)) {
1402
$msg = 'Given subscriber does not exist';
1403
$this->_debug(__FUNCTION__, REMARKETY_MGCONNECTOR_FAILED_STATUS, $msg, $myArgs);
1404
return $this->_wrapResponse(null, REMARKETY_MGCONNECTOR_FAILED_STATUS, $msg);
@@ -1426,7 +1438,7 @@ class Remarkety_Mgconnector_Model_Core extends Mage_Core_Model_Abstract
1426
return $this->configurable_product_model;
1427
}
1428
1429
- private function loadProduct($productId)
1430
{
1431
if (!isset($this->_productCache[$productId])) {
1432
$this->_productCache[$productId] = Mage::getModel("catalog/product")->load($productId);
@@ -1514,6 +1526,222 @@ class Remarkety_Mgconnector_Model_Core extends Mage_Core_Model_Abstract
1514
1515
$this->simpleProductsStandalone = Mage::getStoreConfig('remarkety/mgconnector/configurable_standalone');
1516
}
1517
}
1518
1519
39
private $response_mask = array(
40
'customer' => array(
41
'entity_id',
42
+ 'dob',
43
'firstname',
44
'lastname',
45
'email',
1252
$this->_debug(__FUNCTION__, "Start - prod id " . $product->getId(), null, '');
1253
$url = '';
1254
$visibility = $product->getVisibility();
1255
+ $parentProduct = null;
1256
if ($visibility == 1 || !in_array($product->type_id, $this->_groupedTypes)) {
1257
$parentId = null;
1258
if (!$this->simpleProductsStandalone) {
1268
if (!is_null($parentId)) {
1269
$this->_debug(__FUNCTION__, "parent id " . $parentId, null, '');
1270
$product_id = $parentId;
1271
+ $parentProduct = $this->loadProduct($parentId);
1272
} else {
1273
$product_id = $product->getId();
1274
}
1276
$product_id = $product->getId();
1277
}
1278
1279
+
1280
try {
1281
+ $useInternalMethods = Mage::helper('mgconnector/configuration')->getProductUrlFromMagento();
1282
+ if(!$useInternalMethods){
1283
+ $url = Mage::helper('mgconnector/urls')->getValue($product_id, $mage_store_view_id);
1284
+ if (!empty($url)) {
1285
+ $url = $storeUrl . $url;
1286
+ if (Mage::getStoreConfig('catalog/seo/product_url_suffix', $mage_store_view_id)) {
1287
+ $url .= Mage::getStoreConfig('catalog/seo/product_url_suffix', $mage_store_view_id);
1288
+ }
1289
}
1290
+ $this->_debug(__FUNCTION__, "after setStoreId getProductUrl: " . $url, null, '');
1291
}
1292
} catch (Exception $e) {
1293
$this->_log(__FUNCTION__, "failed after setStoreId: ", $e->getMessage(), '');
1294
}
1295
1296
+ if(empty($url) && !empty($parentProduct)){
1297
+ $url = $parentProduct->getProductUrl();
1298
+ }
1299
+
1300
+ if(empty($url) && !empty($product)){
1301
+ $url = $product->getProductUrl();
1302
}
1303
1304
+ $this->_debug(__FUNCTION__, "getProductUrl: " . $url, null, '');
1305
+
1306
+ return $url;
1307
+
1308
}
1309
1310
+ public function getImageUrl($product, $type = 'image', $mage_store_view_id = null)
1311
{
1312
1313
$url = '';
1326
1327
if (!is_null($parentId)) {
1328
$this->_debug(__FUNCTION__, null, "parent id: " . $parentId, '');
1329
+ $product = $this->loadProduct($parentId);
1330
}
1331
} else {
1332
$this->_debug(__FUNCTION__, null, "configurable prod id" . $product->getId(), '');
1409
$this->_debug(__FUNCTION__, REMARKETY_MGCONNECTOR_CALLED_STATUS, null, $myArgs);
1410
$subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($email);
1411
1412
+ $data = $subscriber->getData();
1413
+ if (empty($data)) {
1414
$msg = 'Given subscriber does not exist';
1415
$this->_debug(__FUNCTION__, REMARKETY_MGCONNECTOR_FAILED_STATUS, $msg, $myArgs);
1416
return $this->_wrapResponse(null, REMARKETY_MGCONNECTOR_FAILED_STATUS, $msg);
1438
return $this->configurable_product_model;
1439
}
1440
1441
+ public function loadProduct($productId)
1442
{
1443
if (!isset($this->_productCache[$productId])) {
1444
$this->_productCache[$productId] = Mage::getModel("catalog/product")->load($productId);
1526
1527
$this->simpleProductsStandalone = Mage::getStoreConfig('remarkety/mgconnector/configurable_standalone');
1528
}
1529
+
1530
+ public function getQueueSize($mage_store_view_id)
1531
+ {
1532
+ register_shutdown_function('handleShutdown');
1533
+ $myArgs = func_get_args();
1534
+
1535
+ try {
1536
+ $this->_debug(__FUNCTION__, REMARKETY_MGCONNECTOR_CALLED_STATUS, null, $myArgs);
1537
+ // $store_views = $this->_store_views_in_group($mage_store_view_id);
1538
+ $queue = Mage::getModel('mgconnector/queue')->getCollection();
1539
+ $queue->addFieldToFilter('store_id', array('eq' => $mage_store_view_id));
1540
+ $count = $queue->getSize();
1541
+ $ret = array('count' => $count);
1542
+
1543
+ $this->_debug(__FUNCTION__, REMARKETY_MGCONNECTOR_SUCCESS_STATUS, null, '');
1544
+ return $this->_wrapResponse($ret, REMARKETY_MGCONNECTOR_SUCCESS_STATUS);
1545
+ } catch (Exception $e) {
1546
+ $this->_log(__FUNCTION__, REMARKETY_MGCONNECTOR_FAILED_STATUS, $e->getMessage(), $myArgs);
1547
+ return $this->_wrapResponse(null, REMARKETY_MGCONNECTOR_FAILED_STATUS, $e->getMessage());
1548
+ }
1549
+ }
1550
+
1551
+ public function getQueueItems($mage_store_view_id, $limit = null, $page = null, $minId = null, $maxId = null)
1552
+ {
1553
+ try {
1554
+ $myArgs = func_get_args();
1555
+
1556
+ $this->_debug(__FUNCTION__, REMARKETY_MGCONNECTOR_CALLED_STATUS, null, $myArgs);
1557
+
1558
+ $collection = Mage::getModel('mgconnector/queue')->getCollection();
1559
+ $collection->addFieldToFilter('store_id', array('eq' => $mage_store_view_id));
1560
+
1561
+ if(!empty($minId)){
1562
+ $collection->addFieldToFilter('queue_id', array('gteq' => $minId));
1563
+ }
1564
+
1565
+ if(!empty($maxId)){
1566
+ $collection->addFieldToFilter('queue_id', array('lteq' => $maxId));
1567
+ }
1568
+
1569
+ $pageSize = null;
1570
+ $pageNumber = 1; // Note that page numbers begin at 1 and remarkety starts at 0
1571
+ if ($limit != null) {
1572
+ $pageSize = $limit;
1573
+ }
1574
+
1575
+ if ($page != null) {
1576
+ if (!is_null($pageSize)) {
1577
+ $pageNumber = $page + 1; // Note that page numbers begin at 1 and remarkety starts at 0
1578
+ }
1579
+ }
1580
+
1581
+ if (!is_null($pageSize)) {
1582
+ $collection->getSelect()->limit($pageSize, ($pageNumber-1)*$pageSize);
1583
+ }
1584
+ $data = array();
1585
+ foreach ($collection as $queueEvent) {
1586
+ $event = $queueEvent->toArray();
1587
+ $event['payload'] = json_encode(unserialize($event['payload']));
1588
+ $data[] = $event;
1589
+ }
1590
+ $this->_debug(__FUNCTION__, REMARKETY_MGCONNECTOR_SUCCESS_STATUS, null, $myArgs);
1591
+ return $this->_wrapResponse($data, REMARKETY_MGCONNECTOR_SUCCESS_STATUS);
1592
+ } catch (Exception $e) {
1593
+ $this->_log(__FUNCTION__, REMARKETY_MGCONNECTOR_FAILED_STATUS, $e->getMessage(), $myArgs);
1594
+ return $this->_wrapResponse(null, REMARKETY_MGCONNECTOR_FAILED_STATUS, $e->getMessage());
1595
+ }
1596
+ }
1597
+
1598
+ public function deleteQueueItems($mage_store_view_id, $minId = null, $maxId = null){
1599
+ try {
1600
+ $myArgs = func_get_args();
1601
+
1602
+ $this->_debug(__FUNCTION__, REMARKETY_MGCONNECTOR_CALLED_STATUS, null, $myArgs);
1603
+
1604
+ $collection = Mage::getModel('mgconnector/queue')->getCollection();
1605
+ $collection->addFieldToFilter('store_id', array('eq' => $mage_store_view_id));
1606
+
1607
+ if(!empty($minId)){
1608
+ $collection->addFieldToFilter('queue_id', array('gteq' => $minId));
1609
+ }
1610
+
1611
+ if(!empty($maxId)){
1612
+ $collection->addFieldToFilter('queue_id', array('lteq' => $maxId));
1613
+ }
1614
+
1615
+ $toDelete = $collection->count();
1616
+ $itemsDeleted = 0;
1617
+
1618
+ foreach ($collection as $item) {
1619
+ $this->_debug(__FUNCTION__, REMARKETY_MGCONNECTOR_CALLED_STATUS, "inside delete events loop", array('id' => $item->getId()));
1620
+ $item->delete();
1621
+ $itemsDeleted++;
1622
+ }
1623
+
1624
+ $this->_debug(__FUNCTION__, REMARKETY_MGCONNECTOR_SUCCESS_STATUS, null, $myArgs);
1625
+
1626
+ return $this->_wrapResponse(array(
1627
+ 'totalMatching' => $toDelete,
1628
+ 'totalDeleted' => $itemsDeleted
1629
+ ), REMARKETY_MGCONNECTOR_SUCCESS_STATUS);
1630
+
1631
+ } catch (Exception $e) {
1632
+ $this->_log(__FUNCTION__, REMARKETY_MGCONNECTOR_FAILED_STATUS, $e->getMessage(), $myArgs);
1633
+ return $this->_wrapResponse(null, REMARKETY_MGCONNECTOR_FAILED_STATUS, $e->getMessage());
1634
+ }
1635
+ }
1636
+
1637
+ public function retryQueueItems($mage_store_view_id, $limit = null, $page = null, $minId = null, $maxId = null)
1638
+ {
1639
+ try {
1640
+ $myArgs = func_get_args();
1641
+
1642
+ $this->_debug(__FUNCTION__, REMARKETY_MGCONNECTOR_CALLED_STATUS, null, $myArgs);
1643
+
1644
+ $collection = Mage::getModel('mgconnector/queue')->getCollection();
1645
+ $collection->addFieldToFilter('store_id', array('eq' => $mage_store_view_id));
1646
+
1647
+ if(!empty($minId)){
1648
+ $collection->addFieldToFilter('queue_id', array('gteq' => $minId));
1649
+ }
1650
+
1651
+ if(!empty($maxId)){
1652
+ $collection->addFieldToFilter('queue_id', array('lteq' => $maxId));
1653
+ }
1654
+
1655
+ $pageSize = null;
1656
+ $pageNumber = 1; // Note that page numbers begin at 1 and remarkety starts at 0
1657
+ if ($limit != null) {
1658
+ $pageSize = $limit;
1659
+ }
1660
+
1661
+ if ($page != null) {
1662
+ if (!is_null($pageSize)) {
1663
+ $pageNumber = $page + 1; // Note that page numbers begin at 1 and remarkety starts at 0
1664
+ }
1665
+ }
1666
+
1667
+ if (!is_null($pageSize)) {
1668
+ $collection->getSelect()->limit($pageSize, ($pageNumber-1)*$pageSize);
1669
+ }
1670
+
1671
+ $observer = Mage::getModel('mgconnector/observer');
1672
+ $itemsSent = $observer->resend($collection);
1673
+
1674
+ $this->_debug(__FUNCTION__, REMARKETY_MGCONNECTOR_SUCCESS_STATUS, null, $myArgs);
1675
+ return $this->_wrapResponse(array(
1676
+ 'totalMatching' => $collection->count(),
1677
+ 'sentSuccessfully' => $itemsSent
1678
+ ), REMARKETY_MGCONNECTOR_SUCCESS_STATUS);
1679
+ } catch (Exception $e) {
1680
+ $this->_log(__FUNCTION__, REMARKETY_MGCONNECTOR_FAILED_STATUS, $e->getMessage(), $myArgs);
1681
+ return $this->_wrapResponse(null, REMARKETY_MGCONNECTOR_FAILED_STATUS, $e->getMessage());
1682
+ }
1683
+ }
1684
+
1685
+ public function getConfig($mage_store_id, $configName, $scope)
1686
+ {
1687
+ register_shutdown_function('handleShutdown');
1688
+ $myArgs = func_get_args();
1689
+
1690
+ try {
1691
+ $this->_debug(__FUNCTION__, REMARKETY_MGCONNECTOR_CALLED_STATUS, null, $myArgs);
1692
+ $configPath = 'remarkety/mgconnector/' . $configName;
1693
+ $value = null;
1694
+ switch($scope){
1695
+ case 'stores':
1696
+ $store = Mage::app()->getStore($mage_store_id);
1697
+ if($store) {
1698
+ $value = $store->getConfig($configPath);
1699
+ }
1700
+ break;
1701
+ default:
1702
+ $value = Mage::getStoreConfig($configPath);
1703
+ }
1704
+
1705
+ $this->_debug(__FUNCTION__, REMARKETY_MGCONNECTOR_SUCCESS_STATUS, null, '');
1706
+ return $this->_wrapResponse(Array(
1707
+ 'value' => $value
1708
+ ), REMARKETY_MGCONNECTOR_SUCCESS_STATUS);
1709
+ } catch (Exception $e) {
1710
+ $this->_log(__FUNCTION__, REMARKETY_MGCONNECTOR_FAILED_STATUS, $e->getMessage(), $myArgs);
1711
+ return $this->_wrapResponse(null, REMARKETY_MGCONNECTOR_FAILED_STATUS, $e->getMessage());
1712
+ }
1713
+ }
1714
+
1715
+ public function setConfig($mage_store_id, $configName, $scope, $newValue)
1716
+ {
1717
+ register_shutdown_function('handleShutdown');
1718
+ $myArgs = func_get_args();
1719
+
1720
+ try {
1721
+ $this->_debug(__FUNCTION__, REMARKETY_MGCONNECTOR_CALLED_STATUS, null, $myArgs);
1722
+ $configPath = 'remarkety/mgconnector/' . $configName;
1723
+ $value = null;
1724
+ if($scope !== 'stores'){
1725
+ $scope = 'default';
1726
+ $mage_store_id = 0;
1727
+ }
1728
+ Mage::getModel('core/config')->saveConfig(
1729
+ $configPath,
1730
+ $newValue,
1731
+ $scope,
1732
+ $mage_store_id
1733
+ );
1734
+
1735
+ Mage::app()->getCacheInstance()->cleanType('config');
1736
+ Mage::dispatchEvent('adminhtml_cache_refresh_type', array('type' => 'config'));
1737
+
1738
+ $this->_debug(__FUNCTION__, REMARKETY_MGCONNECTOR_SUCCESS_STATUS, null, '');
1739
+ return $this->_wrapResponse(true, REMARKETY_MGCONNECTOR_SUCCESS_STATUS);
1740
+ } catch (Exception $e) {
1741
+ $this->_log(__FUNCTION__, REMARKETY_MGCONNECTOR_FAILED_STATUS, $e->getMessage(), $myArgs);
1742
+ return $this->_wrapResponse(null, REMARKETY_MGCONNECTOR_FAILED_STATUS, $e->getMessage());
1743
+ }
1744
+ }
1745
}
1746
1747
app/code/community/Remarkety/Mgconnector/Model/Core/Api.php CHANGED
@@ -275,4 +275,53 @@ class Remarkety_Mgconnector_Model_Core_Api
275
$ret = $myModel->getProductsCount($mage_view_id);
276
return $ret;
277
}
278
}
275
$ret = $myModel->getProductsCount($mage_view_id);
276
return $ret;
277
}
278
+
279
+ public function getQueueSize($mage_store_view_id, $returnLog = 0)
280
+ {
281
+ $myModel = Mage::getModel("mgconnector/core");
282
+ if ($returnLog)
283
+ $myModel->sendLogInResponse();
284
+ return $myModel->getQueueSize($mage_store_view_id);
285
+ }
286
+
287
+ public function getQueueItems($mage_store_view_id,
288
+ $limit = null,
289
+ $page = null,
290
+ $minId = null,
291
+ $maxId = null,
292
+ $returnLog = 0)
293
+ {
294
+ $myModel = Mage::getModel("mgconnector/core");
295
+ if ($returnLog)
296
+ $myModel->sendLogInResponse();
297
+ return $myModel->getQueueItems($mage_store_view_id, $limit, $page, $minId, $maxId);
298
+ }
299
+
300
+ public function retryQueueItems($mage_store_view_id, $limit = null, $page = null, $minId = null, $maxId = null, $returnLog = 0){
301
+ $myModel = Mage::getModel("mgconnector/core");
302
+ if ($returnLog)
303
+ $myModel->sendLogInResponse();
304
+ return $myModel->retryQueueItems($mage_store_view_id, $limit, $page, $minId, $maxId);
305
+ }
306
+
307
+ public function deleteQueueItems($mage_store_view_id, $minId = null, $maxId = null, $returnLog = 0){
308
+ $myModel = Mage::getModel("mgconnector/core");
309
+ if ($returnLog)
310
+ $myModel->sendLogInResponse();
311
+ return $myModel->deleteQueueItems($mage_store_view_id, $minId, $maxId);
312
+ }
313
+
314
+ public function getConfig($mage_store_id, $configName, $scope, $returnLog = 0){
315
+ $myModel = Mage::getModel("mgconnector/core");
316
+ if ($returnLog)
317
+ $myModel->sendLogInResponse();
318
+ return $myModel->getConfig($mage_store_id, $configName, $scope);
319
+ }
320
+
321
+ public function setConfig($mage_store_id, $configName, $scope, $newValue, $returnLog = 0){
322
+ $myModel = Mage::getModel("mgconnector/core");
323
+ if ($returnLog)
324
+ $myModel->sendLogInResponse();
325
+ return $myModel->setConfig($mage_store_id, $configName, $scope, $newValue);
326
+ }
327
}
app/code/community/Remarkety/Mgconnector/Model/Extension/RewardPoints/Observer/AbstractObserver.php CHANGED
@@ -34,11 +34,10 @@ abstract class Remarkety_Mgconnector_Model_Extension_RewardPoints_Observer_Abstr
34
$customerData['rewards'] = $rewardPointsData;
35
36
//queue customer update event
37
- $this->_queueRequest(
38
'customers/update',
39
$customerData,
40
- 1,
41
- null
42
);
43
44
return $this;
34
$customerData['rewards'] = $rewardPointsData;
35
36
//queue customer update event
37
+ $this->makeRequest(
38
'customers/update',
39
$customerData,
40
+ $this->_customer->getStore()->getId()
41
);
42
43
return $this;
app/code/community/Remarkety/Mgconnector/Model/Extension/RewardPoints/Observer/MagestoreRewardPoints.php CHANGED
@@ -35,6 +35,10 @@ class Remarkety_Mgconnector_Model_Extension_RewardPoints_Observer_MagestoreRewar
35
return $this;
36
}
37
38
$rewardPointsCustomerModel = Mage::getModel('rewardpoints/customer')
39
->load($transactionModel->getCustomerId(), 'customer_id');
40
@@ -55,6 +59,11 @@ class Remarkety_Mgconnector_Model_Extension_RewardPoints_Observer_MagestoreRewar
55
->load($transactionModel->getCustomerId());
56
$this->sendCustomerUpdateRequest($rewardPointsData);
57
58
return $this;
59
}
60
}
35
return $this;
36
}
37
38
+ if (Mage::registry('remarkety_customer_save_observer_executed_' . $transactionModel->getCustomerId()) || !$transactionModel->getCustomerId()) {
39
+ return $this;
40
+ }
41
+
42
$rewardPointsCustomerModel = Mage::getModel('rewardpoints/customer')
43
->load($transactionModel->getCustomerId(), 'customer_id');
44
59
->load($transactionModel->getCustomerId());
60
$this->sendCustomerUpdateRequest($rewardPointsData);
61
62
+ Mage::register(
63
+ 'remarkety_customer_save_observer_executed_' . $transactionModel->getCustomerId(),
64
+ true
65
+ );
66
+
67
return $this;
68
}
69
}
app/code/community/Remarkety/Mgconnector/Model/Install.php CHANGED
@@ -54,6 +54,15 @@ class Remarkety_Mgconnector_Model_Install
54
*/
55
const XPATH_INSTALLED = 'remarkety/mgconnector/installed';
56
57
/**
58
* Install data
59
*
@@ -471,6 +480,14 @@ class Remarkety_Mgconnector_Model_Install
471
*/
472
$m = Mage::getModel('mgconnector/webtracking');
473
$m->setRemarketyPublicId($storeId, $response['storePublicId']);
474
}
475
476
$connection->commit();
54
*/
55
const XPATH_INSTALLED = 'remarkety/mgconnector/installed';
56
57
+ /**
58
+ *
59
+ */
60
+ const XPATH_WEBHOOKS_ENABLED = 'remarkety/mgconnector/webhooks';
61
+
62
+ const XPATH_WEBTRACKING_ENABLED = 'remarkety/mgconnector/webtracking';
63
+
64
+ const XPATH_PRODUCT_WEBHOOKS_DISABLED = 'remarkety/mgconnector/product_webhooks_disable';
65
+
66
/**
67
* Install data
68
*
480
*/
481
$m = Mage::getModel('mgconnector/webtracking');
482
$m->setRemarketyPublicId($storeId, $response['storePublicId']);
483
+
484
+ $m->setEnabled($storeId, true);
485
+
486
+ Mage::getModel('core/config')->saveConfig(
487
+ self::XPATH_WEBHOOKS_ENABLED,
488
+ true,
489
+ 'default'
490
+ );
491
}
492
493
$connection->commit();
app/code/community/Remarkety/Mgconnector/Model/Observer.php CHANGED
@@ -13,12 +13,22 @@ if (!defined("REMARKETY_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;
@@ -30,6 +40,9 @@ class Remarkety_Mgconnector_Model_Observer
30
protected $_address = null;
31
protected $_origAddressData = null;
32
33
private $response_mask = array(
34
'product' => array(
35
'id',
@@ -53,6 +66,18 @@ class Remarkety_Mgconnector_Model_Observer
53
)
54
);
55
56
public function __construct()
57
{
58
$this->_token = Mage::getStoreConfig('remarkety/mgconnector/api_key');
@@ -61,9 +86,402 @@ class Remarkety_Mgconnector_Model_Observer
61
$intervals = "1,3,10";
62
}
63
$this->_intervals = explode(',', $intervals);
64
}
65
66
67
68
public function triggerCustomerAddressBeforeUpdate($observer)
69
{
@@ -122,6 +540,10 @@ class Remarkety_Mgconnector_Model_Observer
122
$this->_address = $observer->getEvent()->getCustomerAddress();
123
$this->_customer = $this->_address->getCustomer();
124
125
if (Mage::registry('remarkety_customer_save_observer_executed_' . $this->_customer->getId())) {
126
return $this;
127
}
@@ -134,17 +556,21 @@ class Remarkety_Mgconnector_Model_Observer
134
return $this;
135
}
136
137
- $this->_customerUpdate();
138
139
- Mage::register(
140
- 'remarkety_customer_save_observer_executed_' . $this->_customer->getId(),
141
- true
142
- );
143
144
return $this;
145
}
146
147
private function shouldUpdateRule($rule){
148
$now = new DateTime();
149
$currentFromDate = new DateTime($rule->getFromDate());
150
$currentToDate = new DateTime($rule->getToDate());
@@ -202,27 +628,57 @@ class Remarkety_Mgconnector_Model_Observer
202
{
203
$this->_customer = $observer->getEvent()->getCustomer();
204
205
if (Mage::registry('remarkety_customer_save_observer_executed_' . $this->_customer->getId()) || !$this->_customer->getId()) {
206
return $this;
207
}
208
209
if ($this->_customer->getOrigData() === null) {
210
$this->_customerRegistration();
211
} else {
212
- $this->_customerUpdate();
213
}
214
215
- Mage::register(
216
- 'remarkety_customer_save_observer_executed_' . $this->_customer->getId(),
217
- true
218
- );
219
220
return $this;
221
}
222
223
public function triggerSubscribeUpdate($observer)
224
{
225
- $this->_subscriber = $observer->getEvent()->getSubscriber();
226
227
$loggedIn = Mage::getSingleton('customer/session')->isLoggedIn();
228
@@ -235,9 +691,24 @@ class Remarkety_Mgconnector_Model_Observer
235
return $this;
236
}
237
238
$this->makeRequest(
239
- 'customers/create',
240
- $this->_prepareCustomerSubscribtionUpdateData(true)
241
);
242
243
$email = $this->_subscriber->getSubscriberEmail();
@@ -259,10 +730,16 @@ class Remarkety_Mgconnector_Model_Observer
259
public function triggerSubscribeDelete($observer)
260
{
261
$this->_subscriber = $observer->getEvent()->getSubscriber();
262
if (!Mage::registry('remarkety_subscriber_deleted_' . $this->_subscriber->getEmail()) && $this->_subscriber->getId()) {
263
$this->makeRequest(
264
- 'customers/update',
265
- $this->_prepareCustomerSubscribtionDeleteData()
266
);
267
}
268
@@ -276,28 +753,128 @@ class Remarkety_Mgconnector_Model_Observer
276
return $this;
277
}
278
279
$this->makeRequest(
280
- 'customers/delete',
281
array(
282
'id' => (int)$this->_customer->getId(),
283
- 'email' => $this->_customer->getEmail(),
284
- )
285
);
286
287
return $this;
288
}
289
290
- public function triggerProductSave($observer)
291
- {
292
- // TODO - Need to implement
293
return $this;
294
}
295
296
protected function _customerRegistration()
297
{
298
$this->makeRequest(
299
- 'customers/create',
300
- $this->_prepareCustomerUpdateData()
301
);
302
303
return $this;
@@ -307,12 +884,14 @@ class Remarkety_Mgconnector_Model_Observer
307
{
308
if ($this->_hasDataChanged()) {
309
$this->makeRequest(
310
- 'customers/update',
311
- $this->_prepareCustomerUpdateData()
312
);
313
}
314
315
- return $this;
316
}
317
318
protected function _hasDataChanged()
@@ -355,6 +934,10 @@ class Remarkety_Mgconnector_Model_Observer
355
}
356
}
357
}
358
if (!$this->_hasDataChanged && $this->_address && $this->_origAddressData) {
359
$validate = array(
360
'street',
@@ -363,6 +946,8 @@ class Remarkety_Mgconnector_Model_Observer
363
'postcode',
364
'country_id',
365
'telephone',
366
);
367
$addressDiffKeys = array_keys(
368
array_diff(
@@ -393,7 +978,7 @@ class Remarkety_Mgconnector_Model_Observer
393
);
394
}
395
396
- protected function _getHeaders($eventType, $payload)
397
{
398
$domain = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
399
$url = parse_url($domain);
@@ -410,27 +995,63 @@ class Remarkety_Mgconnector_Model_Observer
410
$headers[] = 'X-Magento-Store-Id: ' . $payload['storeId'];
411
} elseif (isset($payload['store_id'])) {
412
$headers[] = 'X-Magento-Store-Id: ' . $payload['store_id'];
413
}
414
415
return $headers;
416
}
417
418
public function makeRequest(
419
$eventType,
420
$payload,
421
$attempt = 1,
422
$queueId = null
423
) {
424
try {
425
$client = new Zend_Http_Client(
426
- self::REMARKETY_EVENTS_ENDPOINT,
427
$this->_getRequestConfig($eventType)
428
);
429
$payload = array_merge(
430
$payload,
431
$this->_getPayloadBase($eventType)
432
);
433
- $headers = $this->_getHeaders($eventType, $payload);
434
unset($payload['storeId']);
435
$json = json_encode($payload);
436
@@ -452,32 +1073,40 @@ class Remarkety_Mgconnector_Model_Observer
452
case '401':
453
throw new Exception('Request failed, probably wrong API key or inactive account.');
454
default:
455
$this->_queueRequest(
456
$eventType,
457
$payload,
458
$attempt,
459
- $queueId
460
);
461
}
462
} catch (Exception $e) {
463
- $this->_queueRequest($eventType, $payload, $attempt, $queueId);
464
}
465
466
return false;
467
}
468
469
- protected function _queueRequest($eventType, $payload, $attempt, $queueId)
470
{
471
$queueModel = Mage::getModel('mgconnector/queue');
472
473
- if(!empty($this->_intervals[$attempt-1])) {
474
$now = time();
475
- $nextAttempt = $now + (int)$this->_intervals[$attempt - 1] * 60;
476
if ($queueId) {
477
$queueModel->load($queueId);
478
$queueModel->setAttempts($attempt);
479
$queueModel->setLastAttempt(date("Y-m-d H:i:s", $now));
480
$queueModel->setNextAttempt(date("Y-m-d H:i:s", $nextAttempt));
481
} else {
482
$queueModel->setData(
483
array(
@@ -486,6 +1115,8 @@ class Remarkety_Mgconnector_Model_Observer
486
'attempts' => $attempt,
487
'last_attempt' => date("Y-m-d H:i:s", $now),
488
'next_attempt' => date("Y-m-d H:i:s", $nextAttempt),
489
)
490
);
491
}
@@ -510,102 +1141,21 @@ class Remarkety_Mgconnector_Model_Observer
510
511
protected function _prepareCustomerUpdateData()
512
{
513
- $arr = array(
514
- 'id' => (int)$this->_customer->getId(),
515
- 'email' => $this->_customer->getEmail(),
516
- 'created_at' => date(
517
- 'c',
518
- strtotime($this->_customer->getCreatedAt())
519
- ),
520
- 'first_name' => $this->_customer->getFirstname(),
521
- 'last_name' => $this->_customer->getLastname(),
522
- 'store_id' => $this->_customer->getStoreId(),
523
- //'extra_info' => array(),
524
- );
525
-
526
- $isSubscribed = $this->_customer->getIsSubscribed();
527
- if ($isSubscribed === null) {
528
- $subscriber = Mage::getModel('newsletter/subscriber')
529
- ->loadByEmail($this->_customer->getEmail());
530
- if ($subscriber->getId()) {
531
- $isSubscribed = $subscriber->getData('subscriber_status') == Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED;
532
- } else {
533
- $isSubscribed = false;
534
- }
535
- }
536
- $arr = array_merge(
537
- $arr,
538
- array('accepts_marketing' => (bool)$isSubscribed)
539
- );
540
-
541
- if ($title = $this->_customer->getPrefix()) {
542
- $arr = array_merge($arr, array('title' => $title));
543
- }
544
-
545
- if ($dob = $this->_customer->getDob()) {
546
- $arr = array_merge($arr, array('birthdate' => $dob));
547
- }
548
-
549
- if ($gender = $this->_customer->getGender()) {
550
- $arr = array_merge($arr, array('gender' => $gender));
551
- }
552
-
553
- if ($address = $this->_customer->getDefaultBillingAddress()) {
554
- $street = $address->getStreet();
555
- $arr = array_merge(
556
- $arr,
557
- array(
558
- 'default_address' => array(
559
- 'address1' => isset($street[0]) ? $street[0] : '',
560
- 'address2' => isset($street[1]) ? $street[1] : '',
561
- 'city' => $address->getCity(),
562
- 'province' => $address->getRegion(),
563
- 'phone' => $address->getTelephone(),
564
- 'country_code' => $address->getCountryId(),
565
- 'zip' => $address->getPostcode(),
566
- ),
567
- )
568
- );
569
- }
570
-
571
- $tags = $this->_getCustomerProductTags();
572
- if (!empty($tags) && $tags->getSize()) {
573
- $tagsArr = array();
574
- foreach ($tags as $_tag) {
575
- $tagsArr[] = $_tag->getName();
576
- }
577
- $arr = array_merge($arr, array('tags' => $tagsArr));
578
- }
579
-
580
- if ($group = Mage::getModel('customer/group')->load($this->_customer->getGroupId())) {
581
- $arr = array_merge($arr, array(
582
- 'groups' => array(
583
- array(
584
- 'id' => (int)$this->_customer->getGroupId(),
585
- 'name' => $group->getCustomerGroupCode(),
586
- ),
587
- ),
588
- ));
589
- }
590
-
591
- $extensionHelper = Mage::helper('mgconnector/extension');
592
- $rewardPointsInstance = $extensionHelper
593
- ->getRewardPointsIntegrationInstance();
594
- if ($rewardPointsInstance !== false) {
595
- $arr['rewards'] = $rewardPointsInstance
596
- ->getCustomerUpdateData($this->_customer->getId());
597
- }
598
-
599
- return $arr;
600
}
601
602
- protected function _getCustomerProductTags()
603
{
604
$tags = Mage::getModel('tag/tag')->getResourceCollection();
605
if (!empty($tags)) {
606
$tags = $tags
607
->joinRel()
608
- ->addCustomerFilter($this->_customer->getId());
609
}
610
611
return $tags;
@@ -643,6 +1193,12 @@ class Remarkety_Mgconnector_Model_Observer
643
return $arr;
644
}
645
646
public function resend($queueItems, $resetAttempts = false)
647
{
648
$sent = 0;
@@ -651,23 +1207,31 @@ class Remarkety_Mgconnector_Model_Observer
651
if($_queue->getEventType() == "catalogruleupdated"){
652
//create queue for price rule update
653
$ruleData = unserialize($_queue->getPayload());
654
$ruleId = isset($ruleData['ruleId']) ? $ruleData['ruleId'] : false;
655
if($ruleId){
656
$result = $this->sendProductPrices($ruleId);
657
}
658
} else {
659
//send event to remarkety
660
- $result = $this->makeRequest($_queue->getEventType(),
661
unserialize($_queue->getPayload()),
662
$resetAttempts ? 1 : ($_queue->getAttempts() + 1),
663
- $_queue->getId());
664
- }
665
- if ($result) {
666
- Mage::getModel('mgconnector/queue')
667
- ->load($_queue->getId())
668
- ->delete();
669
- $sent++;
670
}
671
}
672
673
return $sent;
@@ -706,17 +1270,19 @@ class Remarkety_Mgconnector_Model_Observer
706
protected function _productsUpdate($storeId, $data, $toQueue = false)
707
{
708
if($toQueue){
709
- $this->_queueRequest('products/update', array('storeId' => $storeId, 'products' => $data), 1, null);
710
} else {
711
- $this->makeRequest('products/update', array('storeId' => $storeId, 'products' => $data));
712
}
713
-
714
return $this;
715
}
716
717
718
public function sendProductPrices($ruleId = null)
719
{
720
// Fix for scenario when method is called directly as cron.
721
if (is_object($ruleId)) {
722
$ruleId = null;
@@ -785,7 +1351,7 @@ class Remarkety_Mgconnector_Model_Observer
785
$product = Mage::getModel('catalog/product')->load($productId);
786
$pWebsites = $product->getWebsiteIds();
787
if(in_array($websiteId, $pWebsites)) {
788
- $rows[] = $this->_prepareProductData($product, $store->getStoreId(), $storeUrls[$store->getStoreId()]);
789
$i++;
790
}
791
}
@@ -800,42 +1366,67 @@ class Remarkety_Mgconnector_Model_Observer
800
return true;
801
}
802
803
- private function _prepareProductData($product,$mage_store_id,$storeUrl)
804
{
805
- $product->setStoreId($mage_store_id)->setCustomerGroupId(0);
806
-
807
- $productData = $product->toArray();
808
- $productData['base_image'] = array('src' => Mage::getModel('mgconnector/core')->getImageUrl($product, 'image', $mage_store_id));
809
- $productData['small_image'] = array('src' => Mage::getModel('mgconnector/core')->getImageUrl($product, 'small', $mage_store_id));
810
- $productData['thumbnail_image'] = array('src' => Mage::getModel('mgconnector/core')->getImageUrl($product, 'thumbnail', $mage_store_id));
811
812
- $cats = Mage::getModel('mgconnector/core')->_productCategories($product);
813
- $categoriesNames = array();
814
- foreach($cats as $catName){
815
- $categoriesNames[] = array('name' => $catName);
816
}
817
- $productData['categories'] = $categoriesNames;
818
-
819
- $price = Mage::getModel('catalogrule/rule')->calcProductPriceRule($product,$product->getPrice());
820
- $productData['price'] = empty($price) ? $product->getFinalPrice() : $price;
821
- $productData['special_price'] = $product->getSpecialPrice();
822
-
823
- $prodUrl = Mage::getModel('mgconnector/core')->getProdUrl($product, $storeUrl, $mage_store_id);
824
- $productData['id'] = $productData['entity_id'];
825
- $productData['url'] = $prodUrl;
826
- $productData['title'] = Mage::getModel('mgconnector/core')->getProductName($product, $mage_store_id);
827
- $productData['enabled'] = $product->isSalable() && $product->isVisibleInSiteVisibility();
828
- $productData['visibility'] = $product->getVisibility();
829
830
831
- $parent_id = Mage::getModel('mgconnector/core')->getProductParentId($product);
832
- if($parent_id !== false){
833
- $productData['parent_id'] = $parent_id;
834
}
835
836
- $productData = $this->_filter_output_data($productData, $this->response_mask['product']);
837
838
- return $productData;
839
}
840
841
}
13
14
class Remarkety_Mgconnector_Model_Observer
15
{
16
+ const REMARKETY_EVENTS_ENDPOINT = 'https://webhooks.remarkety.com/webhooks';
17
const REMARKETY_METHOD = 'POST';
18
const REMARKETY_TIMEOUT = 2;
19
const REMARKETY_VERSION = 0.9;
20
const REMARKETY_PLATFORM = 'MAGENTO';
21
22
+ const EVENT_ORDERS_CREATED = 'orders/create';
23
+ const EVENT_ORDERS_UPDATED = 'orders/updated';
24
+ const EVENT_ORDERS_DELETE = 'orders/delete';
25
+ const EVENT_CUSTOMERS_CREATED = 'customers/create';
26
+ const EVENT_CUSTOMERS_UPDATED = 'customers/update';
27
+ const EVENT_CUSTOMERS_DELETE = 'customers/delete';
28
+ const EVENT_PRODUCTS_CREATED = 'products/create';
29
+ const EVENT_PRODUCTS_UPDATED = 'products/update';
30
+ const EVENT_PRODUCTS_DELETED = 'products/delete';
31
+
32
protected $_token = null;
33
protected $_intervals = null;
34
protected $_customer = null;
40
protected $_address = null;
41
protected $_origAddressData = null;
42
43
+ protected $_sentEventsHash = array();
44
+ protected $_productStoreIds;
45
+
46
private $response_mask = array(
47
'product' => array(
48
'id',
66
)
67
);
68
69
+ /**
70
+ * @var $_configHelp Remarkety_Mgconnector_Helper_Configuration
71
+ */
72
+ private $_configHelp;
73
+
74
+ /**
75
+ * @var $rmCore Remarkety_Mgconnector_Model_Core
76
+ */
77
+ private $_rmCore;
78
+
79
+ private $_forceAsync = false;
80
+
81
public function __construct()
82
{
83
$this->_token = Mage::getStoreConfig('remarkety/mgconnector/api_key');
86
$intervals = "1,3,10";
87
}
88
$this->_intervals = explode(',', $intervals);
89
+ $this->_configHelp = Mage::helper('mgconnector/configuration');
90
+ $this->_rmCore = Mage::getModel("mgconnector/core");
91
+
92
+ $this->_forceAsync = Mage::helper('mgconnector/configuration')->getValue('forceasyncwebhooks', false);
93
+ }
94
+
95
+ private function _log($function, $status, $message, $data, $logLevel = Zend_Log::DEBUG)
96
+ {
97
+ $logMsg = implode(REMARKETY_LOG_SEPARATOR, array($function, $status, $message, json_encode($data)));
98
+ // $force = ($status != REMARKETY_MGCONNECTOR_CALLED_STATUS);
99
+ Mage::log($logMsg, $logLevel, REMARKETY_LOG);
100
+ }
101
+
102
+ public function triggerOrderUpdate($observer){
103
+ $order = $observer->getOrder();
104
+ if(!$this->_configHelp->isWebhooksEnabled($order->getStore()->getId())){
105
+ return $this;
106
+ }
107
+
108
+ $eventType = self::EVENT_ORDERS_UPDATED;
109
+ if ($order->getOrigData() === null) {
110
+ $eventType = self::EVENT_ORDERS_CREATED;
111
+ }
112
+
113
+ $data = $this->serializeOrder($order);
114
+ $this->makeRequest($eventType, $data, $order->getStore()->getId());
115
+ }
116
+
117
+ /**
118
+ * @param array $address
119
+ * @return array
120
+ */
121
+ private function serializeAddress($address){
122
+ $country = Mage::getModel('directory/country')->loadByCode($address['country_id']);
123
+ return array(
124
+ 'first_name' => $address['firstname'],
125
+ 'last_name' => $address['lastname'],
126
+ 'city' => $address['city'],
127
+ 'street' => $address['street'],
128
+ 'country_code' => $address['country_id'],
129
+ 'country' => $country->getName(),
130
+ 'zip' => $address['postcode'],
131
+ 'phone' => $address['telephone'],
132
+ 'region' => $address['region']
133
+ );
134
+ }
135
+
136
+ /**
137
+ * @param Mage_Customer_Model_Customer $customer
138
+ * @return array
139
+ */
140
+ public function serializeCustomer($customer){
141
+
142
+ $groupModel = Mage::getModel("customer/group");
143
+ $groups = array();
144
+ $group_id = $customer->getGroupId();
145
+ if(!empty($group_id)) {
146
+ $groupModel->load($customer->getGroupId());
147
+ $groupName = $groupModel->getCustomerGroupCode();
148
+ $groups[] = array(
149
+ 'id' => $customer->getGroupId(),
150
+ 'name' => $groupName
151
+ );
152
+ }
153
+
154
+ $subscriberModel = Mage::getModel("newsletter/subscriber");
155
+ $subscriberModel->loadByEmail($customer->getEmail());
156
+
157
+ $billingAddress = $customer->getDefaultBillingAddress();
158
+ $customerAddress = $billingAddress ? $billingAddress : $customer->getDefaultShippingAddress();
159
+
160
+ $tags = $this->_getCustomerProductTags($customer);
161
+ $tagsArr = array();
162
+ if (!empty($tags) && $tags->getSize()) {
163
+ foreach ($tags as $_tag) {
164
+ $tagsArr[] = $_tag->getName();
165
+ }
166
+ }
167
+
168
+ if($customer->getIsSubscribed()){
169
+ $allowed = true;
170
+ } else {
171
+ $allowed = $subscriberModel->isSubscribed();
172
+ }
173
+
174
+ $gender = $customer->getResource()->getAttribute("gender");
175
+ $genderVal = null;
176
+ if ($gender->usesSource()) {
177
+ $genderVal = $gender->getSource()->getOptionText($customer->getGender());
178
+ }
179
+
180
+ $info = array(
181
+ 'id' => $customer->getId(),
182
+ 'storeId' => $customer->getStore()->getId(),
183
+ 'accepts_marketing' => $allowed,
184
+ 'birthdate' => $customer->getDob(),
185
+ 'email' => $customer->getEmail(),
186
+ 'title' => $customer->getPrefix(),
187
+ 'first_name' => $customer->getFirstname(),
188
+ 'last_name' => $customer->getLastname(),
189
+ 'groups' => $groups,
190
+ 'created_at' => $customer->getCreatedAt(),
191
+ 'updated_at' => $customer->getUpdatedAt(),
192
+ 'guest' => false,
193
+ 'default_address' => $customerAddress ? $this->serializeAddress($customerAddress->getData()) : null,
194
+ 'tags' => $tagsArr,
195
+ 'gender' => !empty($genderVal) ? $genderVal : null
196
+ );
197
+ $extensionHelper = Mage::helper('mgconnector/extension');
198
+ $rewardPointsInstance = $extensionHelper
199
+ ->getRewardPointsIntegrationInstance();
200
+ if ($rewardPointsInstance !== false) {
201
+ $info['rewards'] = $rewardPointsInstance
202
+ ->getCustomerUpdateData($customer->getId());
203
+ }
204
+
205
+ return $info;
206
+ }
207
+
208
+ /**
209
+ * @param $orderId
210
+ * @return string|null
211
+ */
212
+ private function loadPaymentMethod($orderId)
213
+ {
214
+
215
+ $paymentsCollection = Mage::getModel("sales/order_payment")
216
+ ->getCollection()
217
+ ->addOrder('main_table.entity_id', 'DESC')
218
+ ->addAttributeToFilter('main_table.parent_id', array('eq' => $orderId))
219
+ ->addAttributeToSelect('parent_id')
220
+ ->addAttributeToSelect('method');
221
+
222
+
223
+ foreach ($paymentsCollection as $payment) {
224
+ $row = $payment->toArray();
225
+ $method = $row['method'];
226
+ $methodName = Mage::getStoreConfig('payment/' . $method . '/title');
227
+ if (!empty($methodName)) {
228
+ return $methodName;
229
+ } else {
230
+ return $method;
231
+ }
232
+ }
233
+
234
+ return null;
235
+ }
236
+
237
+ /**
238
+ * @param Mage_Sales_Model_Order $order
239
+ * @return bool|array
240
+ */
241
+ public function serializeOrder($order){
242
+
243
+ $orderData = $order->toArray();
244
+ if (!empty($orderData['relation_child_id'])) {
245
+ return false;
246
+ }
247
+
248
+
249
+ $shippingAddress = null;
250
+ if (isset($orderData['shipping_address_id']) && $orderData['shipping_address_id']) {
251
+ $shippingAddress = Mage::getModel('sales/order_address')->load($orderData['shipping_address_id'])->toArray();
252
+ }
253
+ $billingAddress = null;
254
+ if (isset($orderData['billing_address_id']) && $orderData['billing_address_id']) {
255
+ $billingAddress = Mage::getModel('sales/order_address')->load($orderData['billing_address_id'])->toArray();
256
+ }
257
+
258
+ /**
259
+ * @var $rmCore Remarkety_Mgconnector_Model_Core
260
+ */
261
+ $rmCore = Mage::getModel("mgconnector/core");
262
+
263
+ $customerAddress = null;
264
+ if($orderData['customer_is_guest']) {
265
+ $subscriberModel = Mage::getModel("newsletter/subscriber");
266
+ $subscriberModel->loadByEmail($orderData['customer_email']);
267
+
268
+ $customerAddress = !empty($billingAddress) ? $billingAddress : $shippingAddress;
269
+ $customerInfo = array(
270
+ 'id' => $orderData['customer_id'],
271
+ 'accepts_marketing' => $subscriberModel->isSubscribed(),
272
+ 'birthdate' => $orderData['customer_dob'],
273
+ 'email' => $orderData['customer_email'],
274
+ 'title' => $orderData['customer_prefix'],
275
+ 'first_name' => $orderData['customer_firstname'],
276
+ 'last_name' => $orderData['customer_lastname'],
277
+ 'groups' => array(),
278
+ 'created_at' => $orderData['created_at'],
279
+ 'updated_at' => $orderData['updated_at'],
280
+ 'guest' => true,
281
+ 'default_address' => $this->serializeAddress($customerAddress)
282
+ );
283
+ } else {
284
+ //get address for customer
285
+ $customer_id = $order->getCustomerId();
286
+ $customer = Mage::getModel('customer/customer')->load($customer_id);
287
+ $customerInfo = $this->serializeCustomer($customer);
288
+ }
289
+
290
+ $discounts = array();
291
+ if(!empty($orderData['coupon_code'])){
292
+ $discounts[] = array(
293
+ 'code' => $orderData['coupon_code'],
294
+ 'amount' => (float)$orderData['discount_amount']
295
+ );
296
+ }
297
+
298
+ $line_items = array();
299
+ $itemsCollection = $order->getAllVisibleItems();
300
+ $store = $order->getStore();
301
+ $storeUrl = $store->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB, true);
302
+ $store_id = $store->getId();
303
+
304
+ /**
305
+ * @var $item Mage_Sales_Model_Order_Item
306
+ */
307
+ foreach ($itemsCollection as $item) {
308
+ try {
309
+ $enabled = $item->getProduct()->getIsSalable();
310
+ if($enabled){
311
+ $enabled = $item->getProduct()->isVisibleInCatalog() || $item->getProduct()->isVisibleInSiteVisibility();
312
+ }
313
+
314
+ $images = $this->getProductImages($item->getProduct());
315
+
316
+ $itemArr = array(
317
+ 'product_parent_id' => $rmCore->getProductParentId($item->getProduct()),
318
+ 'product_id' => $item->getProductId(),
319
+ 'quantity' => (float)$item->getQtyOrdered(),
320
+ 'sku' => $item->getSku(),
321
+ 'name' => $item->getName(),
322
+ 'title' => $rmCore->getProductName($item->getProduct(), $store_id),
323
+ 'price' => (float)$item->getBasePrice(),
324
+ 'product_exists' => $enabled,
325
+ 'url' => $rmCore->getProdUrl($item->getProduct(), $storeUrl, $store_id),
326
+ 'images' => $images
327
+ );
328
+
329
+ $line_items[] = $itemArr;
330
+ } catch (Exception $e) {
331
+ $this->_log(__FUNCTION__, 'Error in handling order items for order ID ' . $orderData['entity_id'], $e->getMessage(), $orderData, Zend_Log::ERR);
332
+ }
333
+ }
334
+
335
+ $shipping_lines = array();
336
+ $shipmentCollection = Mage::getResourceModel('sales/order_shipment_collection')
337
+ ->setOrderFilter($order)
338
+ ->load();
339
+ /**
340
+ * @var $shipment Mage_Sales_Model_Order_Shipment
341
+ */
342
+ foreach ($shipmentCollection as $shipment){
343
+ /**
344
+ * @var $tracknum Mage_Sales_Model_Order_Shipment_Track
345
+ */
346
+ foreach($shipment->getAllTracks() as $tracknum)
347
+ {
348
+ $shipping_lines[] = array(
349
+ 'title' => $tracknum->getTitle(),
350
+ 'tracking_number' => $tracknum->getNumber()
351
+ );
352
+ }
353
+
354
+ }
355
+
356
+ $data = array(
357
+ 'storeId' => $store->getId(),
358
+ 'id' => (empty($orderData['original_increment_id'])) ? $orderData['increment_id'] : $orderData['original_increment_id'],
359
+ 'name' => $orderData['increment_id'],
360
+ 'created_at' => $orderData['created_at'],
361
+ 'updated_at' => $orderData['updated_at'],
362
+ 'currency' => $orderData['order_currency_code'],
363
+ 'discount_codes' => $discounts,
364
+ 'email' => $orderData['customer_email'],
365
+ 'payment_method' => $this->loadPaymentMethod($order->getId()),
366
+ 'fulfillment_status' => '',
367
+ 'line_items' => $line_items,
368
+ 'note' => $orderData['customer_note'],
369
+ 'status' => array(
370
+ 'code' => $order->getStatus(),
371
+ 'name' => $order->getStatusLabel(),
372
+ ),
373
+ 'subtotal_price' => $orderData['subtotal'],
374
+ 'taxes_included' => true,
375
+ 'total_discounts' => $orderData['discount_amount'],
376
+ 'total_price' => $orderData['grand_total'],
377
+ 'total_shipping' => $orderData['shipping_amount'],
378
+ 'total_tax' => $orderData['tax_amount'],
379
+ 'customer' => $customerInfo,
380
+ 'shipping_address' => $this->serializeAddress($shippingAddress),
381
+ 'billing_address' => $this->serializeAddress($billingAddress),
382
+ 'shipping_lines' => $shipping_lines
383
+ );
384
+ return $data;
385
+ }
386
+
387
+ private function getProductImages($product){
388
+ /**
389
+ * @var $rmCore Remarkety_Mgconnector_Model_Core
390
+ */
391
+ $rmCore = Mage::getModel("mgconnector/core");
392
+
393
+ $images = array();
394
+ $baseImage = $rmCore->getImageUrl($product, 'image');
395
+ if(!empty($baseImage)){
396
+ $images[] = array(
397
+ 'src' => $baseImage,
398
+ 'type' => 'base_image'
399
+ );
400
+ }
401
+ $smallImage = $rmCore->getImageUrl($product, 'small');
402
+ if(!empty($smallImage)){
403
+ $images[] = array(
404
+ 'src' => $smallImage,
405
+ 'type' => 'small_image'
406
+ );
407
+ }
408
+ $thumbnailImage = $rmCore->getImageUrl($product, 'thumbnail');
409
+ if(!empty($thumbnailImage)){
410
+ $images[] = array(
411
+ 'src' => $thumbnailImage,
412
+ 'type' => 'thumbnail_image'
413
+ );
414
+ }
415
+ return $images;
416
}
417
418
+ /**
419
+ * @param Mage_Catalog_Model_Product $product
420
+ * @param $storeId
421
+ * @return array
422
+ */
423
+ public function serializeProduct($product, $storeId){
424
425
+ /**
426
+ * @var $rmCore Remarkety_Mgconnector_Model_Core
427
+ */
428
+ $rmCore = Mage::getModel("mgconnector/core");
429
+
430
+ $store = Mage::App()->getStore($storeId);
431
+ $storeUrl = $store->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB, true);
432
+
433
+ $categories = $rmCore->_productCategories($product);
434
+ $categories = array_map(function ($val) {
435
+ return array(
436
+ 'name' => $val
437
+ );
438
+ }, $categories);
439
+
440
+ $now = Mage::getSingleton('core/date')->timestamp(time());
441
+ $rules = Mage::getResourceModel('catalogrule/rule');
442
+ $price = $rules->getRulePrice($now, $store->getWebsiteId(), 0, $product->getId());
443
+ $price = empty($price) ? $product->getFinalPrice() : (float)$price;
444
+ $special_price = $product->getSpecialPrice();
445
+
446
+ $stocklevel = (int)Mage::getModel('cataloginventory/stock_item')
447
+ ->loadByProduct($product)->getQty();
448
+
449
+ $originalStore = Mage::app()->getStore();
450
+ Mage::app()->setCurrentStore($storeId);
451
+ $product = $rmCore->loadProduct($product->getId());
452
+ $stores = $product->getStoreIds();
453
+ if(!in_array($storeId, $stores)){
454
+ $enabled = false;
455
+ } else {
456
+ $enabled = $product->isAvailable() && ($product->isVisibleInCatalog() || $product->isVisibleInSiteVisibility());
457
+ }
458
+ $url = $rmCore->getProdUrl($product, $storeUrl, $storeId);
459
+ Mage::app()->setCurrentStore($originalStore->getId());
460
+
461
+ $data = array(
462
+ 'id' => $product->getId(),
463
+ 'sku' => $product->getSku(),
464
+ 'title' => $rmCore->getProductName($product, $storeId),
465
+ 'body_html' => '',
466
+ 'categories' => $categories,
467
+ 'created_at' => $product->getCreatedAt(),
468
+ 'updated_at' => $product->getUpdatedAt(),
469
+ 'images' => $this->getProductImages($product),
470
+ 'enabled' => $enabled,
471
+ 'price' => $price,
472
+ 'special_price' => $special_price,
473
+ 'url' => $url,
474
+ 'parent_id' => $rmCore->getProductParentId($product),
475
+ 'variants' => array(
476
+ array(
477
+ 'inventory_quantity' => $stocklevel,
478
+ 'price' => $price
479
+ )
480
+ )
481
+ );
482
+
483
+ return $data;
484
+ }
485
486
public function triggerCustomerAddressBeforeUpdate($observer)
487
{
540
$this->_address = $observer->getEvent()->getCustomerAddress();
541
$this->_customer = $this->_address->getCustomer();
542
543
+ if(!$this->_configHelp->isStoreInstalled($this->_customer->getStore()->getId())){
544
+ return $this;
545
+ }
546
+
547
if (Mage::registry('remarkety_customer_save_observer_executed_' . $this->_customer->getId())) {
548
return $this;
549
}
556
return $this;
557
}
558
559
+ if($this->_customerUpdate()){
560
+ Mage::register(
561
+ 'remarkety_customer_save_observer_executed_' . $this->_customer->getId(),
562
+ true
563
+ );
564
+ }
565
566
567
return $this;
568
}
569
570
private function shouldUpdateRule($rule){
571
+ if(!$this->shouldSendProductUpdates()){
572
+ return false;
573
+ }
574
$now = new DateTime();
575
$currentFromDate = new DateTime($rule->getFromDate());
576
$currentToDate = new DateTime($rule->getToDate());
628
{
629
$this->_customer = $observer->getEvent()->getCustomer();
630
631
+ if(!$this->_configHelp->isStoreInstalled($this->_customer->getStore()->getId())){
632
+ return $this;
633
+ }
634
+
635
if (Mage::registry('remarkety_customer_save_observer_executed_' . $this->_customer->getId()) || !$this->_customer->getId()) {
636
return $this;
637
}
638
639
if ($this->_customer->getOrigData() === null) {
640
$this->_customerRegistration();
641
+ $done = true;
642
} else {
643
+ $done = $this->_customerUpdate();
644
}
645
646
+ if($done) {
647
+ Mage::register(
648
+ 'remarkety_customer_save_observer_executed_' . $this->_customer->getId(),
649
+ true
650
+ );
651
+ }
652
653
return $this;
654
}
655
656
+ public function triggerCartUpdated($observer){
657
+ try {
658
+ $cart = $observer->getCart();
659
+ if($cart){
660
+ $quote = $cart->getQuote();
661
+ $email = Mage::getSingleton('customer/session')->getSubscriberEmail();
662
+ if ($email && $quote && !is_null($quote->getId()) && is_null($quote->getCustomerEmail())) {
663
+ $quote->setCustomerEmail($email)->save();
664
+ }
665
+ }
666
+ } catch (Exception $ex){
667
+ $this->_log('triggerCartUpdated', '', $ex->getMessage(), null, Zend_Log::ERR);
668
+ }
669
+ }
670
+
671
public function triggerSubscribeUpdate($observer)
672
{
673
+ /**
674
+ * @var $subscriber Mage_Newsletter_Model_Subscriber
675
+ */
676
+ $subscriber = $observer->getEvent()->getSubscriber();
677
+ $this->_subscriber = $subscriber;
678
+
679
+ if(!$this->_configHelp->isStoreInstalled($this->_subscriber->getStoreId())){
680
+ return $this;
681
+ }
682
683
$loggedIn = Mage::getSingleton('customer/session')->isLoggedIn();
684
691
return $this;
692
}
693
694
+ $new = $subscriber->isObjectNew();
695
+
696
+
697
+ if($this->_subscriber->getCustomerId()){
698
+ $customer = Mage::getModel('customer/customer')->load($this->_subscriber->getCustomerId());
699
+ $data = $this->serializeCustomer($customer);
700
+ Mage::register(
701
+ 'remarkety_customer_save_observer_executed_' . $customer->getId(),
702
+ true
703
+ );
704
+
705
+ } else {
706
+ $data = $this->_prepareCustomerSubscribtionUpdateData(true);
707
+ }
708
$this->makeRequest(
709
+ $new ? self::EVENT_CUSTOMERS_CREATED : self::EVENT_CUSTOMERS_UPDATED,
710
+ $data,
711
+ $this->_subscriber->getStoreId()
712
);
713
714
$email = $this->_subscriber->getSubscriberEmail();
730
public function triggerSubscribeDelete($observer)
731
{
732
$this->_subscriber = $observer->getEvent()->getSubscriber();
733
+ if(!$this->_configHelp->isStoreInstalled($this->_subscriber->getStoreId())){
734
+ return $this;
735
+ }
736
+
737
if (!Mage::registry('remarkety_subscriber_deleted_' . $this->_subscriber->getEmail()) && $this->_subscriber->getId()) {
738
+
739
$this->makeRequest(
740
+ self::EVENT_CUSTOMERS_UPDATED,
741
+ $this->_prepareCustomerSubscribtionDeleteData(),
742
+ $this->_subscriber->getStoreId()
743
);
744
}
745
753
return $this;
754
}
755
756
+ if(!$this->_configHelp->isStoreInstalled($this->_customer->getStore()->getId())){
757
+ return $this;
758
+ }
759
+
760
$this->makeRequest(
761
+ self::EVENT_CUSTOMERS_DELETE,
762
array(
763
'id' => (int)$this->_customer->getId(),
764
+ 'email' => $this->_customer->getEmail()
765
+ ), $this->_customer->getStore()->getId()
766
);
767
768
return $this;
769
}
770
771
+ public function triggerProductDeleteBefore($observer){
772
+ /**
773
+ * @var $product Mage_Catalog_Model_Product
774
+ */
775
+ $product = $observer->getProduct();
776
+ $this->_productStoreIds = $product->getStoreIds();
777
+ }
778
+ public function triggerProductDelete($observer){
779
+
780
+
781
+ /**
782
+ * @var $product Mage_Catalog_Model_Product
783
+ */
784
+ $product = $observer->getProduct();
785
+ //should send this event to all relevant stores
786
+ foreach($this->_productStoreIds as $storeId) {
787
+ if($this->_configHelp->isWebhooksEnabled($storeId)) {
788
+ $this->makeRequest(self::EVENT_PRODUCTS_DELETED, array(
789
+ 'id' => $product->getId()
790
+ ), $storeId);
791
+ }
792
+ }
793
return $this;
794
}
795
+ public function triggerCategoryChangeProducts($observer){
796
+ if(!$this->shouldSendProductUpdates()){
797
+ return $this;
798
+ }
799
+
800
+ $ids = $observer->getProductIds();
801
+ if(!empty($ids)){
802
+ foreach ($ids as $productId){
803
+ $product = $this->_rmCore->loadProduct($productId);
804
+ $this->productUpdate($product, $product->getStoreIds(), self::EVENT_PRODUCTS_UPDATED);
805
+ }
806
+ }
807
+ }
808
+
809
+ public function triggerProductSaveBefore($observer){
810
+ /**
811
+ * We need to store the original store ids to make sure to update removed store
812
+ * Also in commit_after we cant get the store ids for some reason
813
+ */
814
+ if(!$this->shouldSendProductUpdates()){
815
+ return $this;
816
+ }
817
+ $product = $observer->getProduct();
818
+
819
+ $dbStores = array();
820
+ if ($product->getOrigData() !== null) {
821
+ $productDb = Mage::getModel("catalog/product")->load($product->getId());
822
+ $dbStores = $productDb->getStoreIds();
823
+ }
824
+ $ids = array_merge($dbStores, $product->getStoreIds());
825
+ $this->_productStoreIds = array_unique($ids);
826
+ }
827
+ public function triggerProductSaveCommit($observer){
828
+ if(!$this->shouldSendProductUpdates()){
829
+ return $this;
830
+ }
831
+ $product = $observer->getProduct();
832
+ $storeIds = $this->_productStoreIds;
833
+ if ($product->getOrigData() === null) {
834
+ $eventType = self::EVENT_PRODUCTS_CREATED;
835
+ } else {
836
+ $eventType = self::EVENT_PRODUCTS_UPDATED;
837
+ }
838
+ $this->productUpdate($product, $storeIds, $eventType);
839
+
840
+ return $this;
841
+ }
842
+
843
+ private function productUpdate($product, $storeIds, $eventType){
844
+ $childProducts = array();
845
+ $grouped = array(
846
+ Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE,
847
+ Mage_Catalog_Model_Product_Type::TYPE_GROUPED
848
+ );
849
+ if(in_array($product->getTypeId(), $grouped)){
850
+ $childProductsIds = Mage::helper('mgconnector/links')->getSimpleIds($product->getId());
851
+ if(!empty($childProductsIds)) {
852
+ foreach ($childProductsIds as $childProductsId) {
853
+ $childProducts[] = $this->_rmCore->loadProduct($childProductsId);
854
+ }
855
+ }
856
+ }
857
+
858
+ foreach($storeIds as $storeId) {
859
+ if ($this->_configHelp->isWebhooksEnabled($storeId)) {
860
+ $data = $this->serializeProduct($product, $storeId);
861
+ $this->makeRequest($eventType, $data, $storeId);
862
+ if(!empty($childProducts)){
863
+ foreach ($childProducts as $childProduct) {
864
+ $data = $this->serializeProduct($childProduct, $storeId);
865
+ $this->makeRequest($eventType, $data, $storeId);
866
+ }
867
+ }
868
+ }
869
+ }
870
+ }
871
872
protected function _customerRegistration()
873
{
874
$this->makeRequest(
875
+ self::EVENT_CUSTOMERS_CREATED,
876
+ $this->_prepareCustomerUpdateData(),
877
+ $this->_customer->getStore()->getId()
878
);
879
880
return $this;
884
{
885
if ($this->_hasDataChanged()) {
886
$this->makeRequest(
887
+ self::EVENT_CUSTOMERS_UPDATED,
888
+ $this->_prepareCustomerUpdateData(),
889
+ $this->_customer->getStore()->getId()
890
);
891
+ return true;
892
}
893
894
+ return false;
895
}
896
897
protected function _hasDataChanged()
934
}
935
}
936
}
937
+ if (!$this->_hasDataChanged && $this->_address && empty($this->_origAddressData)) {
938
+ //new address
939
+ $this->_hasDataChanged = true;
940
+ }
941
if (!$this->_hasDataChanged && $this->_address && $this->_origAddressData) {
942
$validate = array(
943
'street',
946
'postcode',
947
'country_id',
948
'telephone',
949
+ 'firstname',
950
+ 'lastname'
951
);
952
$addressDiffKeys = array_keys(
953
array_diff(
978
);
979
}
980
981
+ protected function _getHeaders($eventType, $payload, $storeId = null)
982
{
983
$domain = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
984
$url = parse_url($domain);
995
$headers[] = 'X-Magento-Store-Id: ' . $payload['storeId'];
996
} elseif (isset($payload['store_id'])) {
997
$headers[] = 'X-Magento-Store-Id: ' . $payload['store_id'];
998
+ } elseif (!empty($storeId)){
999
+ $headers[] = 'X-Magento-Store-Id: ' . $storeId;
1000
+ } else {
1001
+ $store = Mage::app()->getStore();
1002
+ $headers[] = 'X-Magento-Store-Id: ' . $store->getId();
1003
}
1004
1005
return $headers;
1006
}
1007
1008
+ protected function shouldSendEvent($eventType, $payload, $storeId = null){
1009
+ $data = array(
1010
+ 'eventType' => $eventType,
1011
+ 'payload' => $payload,
1012
+ 'storeId' => $storeId
1013
+ );
1014
+ $hash = md5(serialize($data));
1015
+ if(array_key_exists($hash, $this->_sentEventsHash)){
1016
+ return false;
1017
+ }
1018
+ $this->_sentEventsHash[$hash] = true;
1019
+ return true;
1020
+ }
1021
public function makeRequest(
1022
$eventType,
1023
$payload,
1024
+ $storeId,
1025
$attempt = 1,
1026
$queueId = null
1027
) {
1028
try {
1029
+ if(!$this->shouldSendEvent($eventType, $payload, $storeId)){
1030
+ //safety for not sending the same event on same event
1031
+ $this->_log(__FUNCTION__, '', 'Event already sent', $payload);
1032
+ return true;
1033
+ }
1034
+
1035
+ if($this->_forceAsync && $attempt == 1 && empty($queueId)){
1036
+ $this->_queueRequest($eventType, $payload, 0, $queueId, $storeId);
1037
+ return true;
1038
+ }
1039
+
1040
+ $url = self::REMARKETY_EVENTS_ENDPOINT;
1041
+ $storeAppId = $this->_configHelp->getRemarketyPublicId($storeId);
1042
+ if($storeAppId){
1043
+ $url .= '?storeId=' . $storeAppId;
1044
+ }
1045
+
1046
$client = new Zend_Http_Client(
1047
+ $url,
1048
$this->_getRequestConfig($eventType)
1049
);
1050