Copernica_MarketingSoftware - Version 3.2.4

Version Notes

Copernica - Version 3.2.4

Download this release

Release Info

Developer Cream
Extension Copernica_MarketingSoftware
Version 3.2.4
Comparing to
See all releases


Code changes from version 3.2.3 to 3.2.4

Files changed (117) hide show
  1. app/code/community/Copernica/MarketingSoftware/Block/Adminhtml/Marketingsoftware/Sync.php +3 -3
  2. app/code/community/Copernica/MarketingSoftware/Controller/Action.php +15 -15
  3. app/code/community/Copernica/MarketingSoftware/Helper/Api.php +45 -43
  4. app/code/community/Copernica/MarketingSoftware/Helper/Api/Abstract.php +38 -38
  5. app/code/community/Copernica/MarketingSoftware/Helper/Api/Builder.php +46 -40
  6. app/code/community/Copernica/MarketingSoftware/Helper/Api/Validator.php +61 -61
  7. app/code/community/Copernica/MarketingSoftware/Helper/Config.php +170 -168
  8. app/code/community/Copernica/MarketingSoftware/Helper/Data.php +240 -234
  9. app/code/community/Copernica/MarketingSoftware/Helper/DataWriter.php +13 -16
  10. app/code/community/Copernica/MarketingSoftware/Helper/Profile.php +22 -21
  11. app/code/community/Copernica/MarketingSoftware/Helper/Rest/Request.php +59 -45
  12. app/code/community/Copernica/MarketingSoftware/Model/Abandoned/Cart.php +2 -2
  13. app/code/community/Copernica/MarketingSoftware/Model/Abandoned/Carts/Processor.php +5 -5
  14. app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Address.php +24 -22
  15. app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Attributes.php +15 -13
  16. app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Customer.php +33 -33
  17. app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Name.php +13 -11
  18. app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Order.php +31 -29
  19. app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Order/Item.php +17 -15
  20. app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Order/Item/Options.php +15 -13
  21. app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Price.php +18 -16
  22. app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Product.php +31 -31
  23. app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Product/Viewed.php +26 -26
  24. app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Quote.php +36 -32
  25. app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Quote/Item.php +29 -27
  26. app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Quote/Item/Options.php +17 -15
  27. app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Storeview.php +22 -18
  28. app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Subscription.php +14 -12
  29. app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Wishlist.php +40 -34
  30. app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Wishlist/Item.php +29 -27
  31. app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Wishlist/Item/Options.php +17 -15
  32. app/code/community/Copernica/MarketingSoftware/Model/Config.php +3 -3
  33. app/code/community/Copernica/MarketingSoftware/Model/Copernica/Abstract.php +11 -11
  34. app/code/community/Copernica/MarketingSoftware/Model/Copernica/Address/Subprofile.php +1 -1
  35. app/code/community/Copernica/MarketingSoftware/Model/Copernica/Entity.php +16 -16
  36. app/code/community/Copernica/MarketingSoftware/Model/Copernica/Entity/Address.php +36 -38
  37. app/code/community/Copernica/MarketingSoftware/Model/Copernica/Entity/Customer.php +63 -61
  38. app/code/community/Copernica/MarketingSoftware/Model/Copernica/Entity/Order.php +65 -31
  39. app/code/community/Copernica/MarketingSoftware/Model/Copernica/Entity/Order/Item.php +37 -33
  40. app/code/community/Copernica/MarketingSoftware/Model/Copernica/Entity/Product.php +40 -38
  41. app/code/community/Copernica/MarketingSoftware/Model/Copernica/Entity/Quote.php +14 -14
  42. app/code/community/Copernica/MarketingSoftware/Model/Copernica/Entity/Quote/Item.php +11 -10
  43. app/code/community/Copernica/MarketingSoftware/Model/Copernica/Entity/Subscription.php +18 -18
  44. app/code/community/Copernica/MarketingSoftware/Model/Copernica/Entity/Wishlist.php +16 -16
  45. app/code/community/Copernica/MarketingSoftware/Model/Copernica/Entity/Wishlist/Item.php +110 -109
  46. app/code/community/Copernica/MarketingSoftware/Model/Copernica/Order/Subprofile.php +11 -11
  47. app/code/community/Copernica/MarketingSoftware/Model/Copernica/Orderitem/Subprofile.php +10 -6
  48. app/code/community/Copernica/MarketingSoftware/Model/Copernica/Product/Viewed/Subprofile.php +4 -4
  49. app/code/community/Copernica/MarketingSoftware/Model/Copernica/Profile/Customer.php +3 -3
  50. app/code/community/Copernica/MarketingSoftware/Model/Copernica/Profile/Order.php +12 -12
  51. app/code/community/Copernica/MarketingSoftware/Model/Copernica/Profile/Quote.php +14 -14
  52. app/code/community/Copernica/MarketingSoftware/Model/Copernica/Profile/Subscription.php +4 -4
  53. app/code/community/Copernica/MarketingSoftware/Model/Copernica/Quote/Item/Subprofile.php +12 -8
  54. app/code/community/Copernica/MarketingSoftware/Model/Copernica/Wishlist/Item/Subprofile.php +11 -7
  55. app/code/community/Copernica/MarketingSoftware/Model/Error/Queue.php +6 -6
  56. app/code/community/Copernica/MarketingSoftware/Model/Mysql4/Queue/Item.php +1 -1
  57. app/code/community/Copernica/MarketingSoftware/Model/Observer.php +101 -101
  58. app/code/community/Copernica/MarketingSoftware/Model/Profile/Cache.php +3 -3
  59. app/code/community/Copernica/MarketingSoftware/Model/Queue/Event/Abstract.php +9 -9
  60. app/code/community/Copernica/MarketingSoftware/Model/Queue/Event/Checkout.php +39 -37
  61. app/code/community/Copernica/MarketingSoftware/Model/Queue/Event/Customer.php +13 -12
  62. app/code/community/Copernica/MarketingSoftware/Model/Queue/Event/Factory.php +2 -2
  63. app/code/community/Copernica/MarketingSoftware/Model/Queue/Event/Item.php +37 -33
  64. app/code/community/Copernica/MarketingSoftware/Model/Queue/Event/Order.php +45 -43
  65. app/code/community/Copernica/MarketingSoftware/Model/Queue/Event/Quote.php +14 -10
  66. app/code/community/Copernica/MarketingSoftware/Model/Queue/Event/Startsync.php +27 -18
  67. app/code/community/Copernica/MarketingSoftware/Model/Queue/Event/Subscription.php +11 -8
  68. app/code/community/Copernica/MarketingSoftware/Model/Queue/Event/View.php +9 -9
  69. app/code/community/Copernica/MarketingSoftware/Model/Queue/Event/Wishlist/Item.php +30 -26
  70. app/code/community/Copernica/MarketingSoftware/Model/Queue/Item.php +11 -11
  71. app/code/community/Copernica/MarketingSoftware/Model/Queue/Processor.php +19 -19
  72. app/code/community/Copernica/MarketingSoftware/Model/Rest.php +22 -18
  73. app/code/community/Copernica/MarketingSoftware/Model/Rest/Address.php +32 -28
  74. app/code/community/Copernica/MarketingSoftware/Model/Rest/Customer.php +6 -5
  75. app/code/community/Copernica/MarketingSoftware/Model/Rest/Order.php +34 -28
  76. app/code/community/Copernica/MarketingSoftware/Model/Rest/Order/Item.php +29 -25
  77. app/code/community/Copernica/MarketingSoftware/Model/Rest/Product.php +24 -19
  78. app/code/community/Copernica/MarketingSoftware/Model/Rest/Quote.php +9 -8
  79. app/code/community/Copernica/MarketingSoftware/Model/Rest/Quote/Item.php +35 -30
  80. app/code/community/Copernica/MarketingSoftware/Model/Rest/Subscription.php +11 -9
  81. app/code/community/Copernica/MarketingSoftware/Model/Rest/Wishlist.php +9 -8
  82. app/code/community/Copernica/MarketingSoftware/Model/Rest/Wishlist/Item.php +36 -31
  83. app/code/community/Copernica/MarketingSoftware/Model/Sync/Profile.php +11 -11
  84. app/code/community/Copernica/MarketingSoftware/Model/Sync/Status.php +24 -22
  85. app/code/community/Copernica/MarketingSoftware/controllers/Adminhtml/Marketingsoftware/AccessTokenController.php +2 -2
  86. app/code/community/Copernica/MarketingSoftware/controllers/Adminhtml/Marketingsoftware/AjaxcollectionController.php +57 -38
  87. app/code/community/Copernica/MarketingSoftware/controllers/Adminhtml/Marketingsoftware/ExportController.php +14 -14
  88. app/code/community/Copernica/MarketingSoftware/controllers/Adminhtml/Marketingsoftware/LinkController.php +35 -31
  89. app/code/community/Copernica/MarketingSoftware/controllers/Adminhtml/Marketingsoftware/SettingsController.php +29 -29
  90. app/code/community/Copernica/MarketingSoftware/controllers/Adminhtml/Marketingsoftware/SyncController.php +24 -22
  91. app/code/community/Copernica/MarketingSoftware/controllers/CartController.php +29 -27
  92. app/code/community/Copernica/MarketingSoftware/controllers/ProductController.php +43 -38
  93. app/code/community/Copernica/MarketingSoftware/controllers/UnsubscribeController.php +21 -11
  94. app/code/community/Copernica/MarketingSoftware/cron/clearCopernicaDatabase.php +3 -3
  95. app/code/community/Copernica/MarketingSoftware/cron/detectAbandonedCarts.php +2 -2
  96. app/code/community/Copernica/MarketingSoftware/cron/fullSync.php +3 -3
  97. app/code/community/Copernica/MarketingSoftware/cron/processQueue.php +8 -8
  98. app/code/community/Copernica/MarketingSoftware/data/marketingsoftware_setup/data-upgrade-3.4.0-3.4.1.php +4 -7
  99. app/code/community/Copernica/MarketingSoftware/etc/config.xml +1 -1
  100. app/code/community/Copernica/MarketingSoftware/sql/marketingsoftware_setup/mysql4-install-1.2.0.php +4 -2
  101. app/code/community/Copernica/MarketingSoftware/sql/marketingsoftware_setup/mysql4-upgrade-1.1.5-1.1.6.php +4 -2
  102. app/code/community/Copernica/MarketingSoftware/sql/marketingsoftware_setup/mysql4-upgrade-1.1.6-1.1.7.php +4 -2
  103. app/code/community/Copernica/MarketingSoftware/sql/marketingsoftware_setup/mysql4-upgrade-1.1.7-1.1.8.php +4 -2
  104. app/code/community/Copernica/MarketingSoftware/sql/marketingsoftware_setup/mysql4-upgrade-1.1.8-1.2.0.php +4 -2
  105. app/code/community/Copernica/MarketingSoftware/sql/marketingsoftware_setup/mysql4-upgrade-2.0.1-2.0.2.php +7 -3
  106. app/code/community/Copernica/MarketingSoftware/sql/marketingsoftware_setup/mysql4-upgrade-2.1.0.1-2.2.0.php +8 -4
  107. app/code/community/Copernica/MarketingSoftware/sql/marketingsoftware_setup/mysql4-upgrade-2.2.0.1-2.3.0.php +8 -4
  108. app/code/community/Copernica/MarketingSoftware/sql/marketingsoftware_setup/mysql4-upgrade-2.3.0-2.3.1.php +4 -2
  109. app/code/community/Copernica/MarketingSoftware/sql/marketingsoftware_setup/mysql4-upgrade-2.3.1-2.3.2.php +4 -2
  110. app/code/community/Copernica/MarketingSoftware/sql/marketingsoftware_setup/mysql4-upgrade-2.3.2-2.3.3.php +24 -12
  111. app/code/community/Copernica/MarketingSoftware/sql/marketingsoftware_setup/mysql4-upgrade-2.3.8-2.4.0.php +10 -7
  112. app/code/community/Copernica/MarketingSoftware/sql/marketingsoftware_setup/mysql4-upgrade-2.4.0-2.4.1.php +3 -6
  113. app/code/community/Copernica/MarketingSoftware/sql/marketingsoftware_setup/mysql4-upgrade-2.4.1-2.4.2.php +20 -10
  114. app/code/community/Copernica/MarketingSoftware/sql/marketingsoftware_setup/mysql4-upgrade-2.4.2-2.4.3.php +12 -6
  115. app/code/community/Copernica/MarketingSoftware/sql/marketingsoftware_setup/mysql4-upgrade-2.4.3-2.4.4.php +25 -13
  116. app/design/adminhtml/default/default/template/marketingsoftware/settings.phtml +2 -2
  117. package.xml +6 -6
app/code/community/Copernica/MarketingSoftware/Block/Adminhtml/Marketingsoftware/Sync.php CHANGED
@@ -81,7 +81,7 @@ class Copernica_MarketingSoftware_Block_Adminhtml_MarketingSoftware_Sync extends
81
  /**
82
  * Get url that will point to state action in controller
83
  *
84
- * @todo Two returns????
85
  * @return string
86
  */
87
  public function getStateUrl()
@@ -110,9 +110,9 @@ class Copernica_MarketingSoftware_Block_Adminhtml_MarketingSoftware_Sync extends
110
  $parts = array();
111
 
112
  foreach ($query as $key => $value) {
113
- $parts[] = implode('=', array($key, urlencode($value)));
114
  }
115
 
116
  return $authUrl.'?'.implode('&', $parts);
117
  }
118
- }
81
  /**
82
  * Get url that will point to state action in controller
83
  *
84
+ * @todo Two returns????
85
  * @return string
86
  */
87
  public function getStateUrl()
110
  $parts = array();
111
 
112
  foreach ($query as $key => $value) {
113
+ $parts[] = implode('=', array($key, urlencode($value)));
114
  }
115
 
116
  return $authUrl.'?'.implode('&', $parts);
117
  }
118
+ }
app/code/community/Copernica/MarketingSoftware/Controller/Action.php CHANGED
@@ -65,21 +65,21 @@ class Copernica_MarketingSoftware_Controller_Action extends Mage_Adminhtml_Contr
65
  */
66
  protected function _isAllowed()
67
  {
68
- return Mage::getSingleton('admin/session')->isAllowed('copernica');
69
  }
70
 
71
  /**
72
  * Check if queue have too many items. This method will output messages on
73
  * admin session to inform him about current state.
74
  *
75
- * @param Copernica_MarketingSoftware_Model_Mysql4_Queue_Item_Collection $queue
76
  */
77
  protected function _checkQueueSize(Copernica_MarketingSoftware_Model_Mysql4_Queue_Item_Collection $queue)
78
  {
79
  $queueSize = $queue->getSize();
80
 
81
  if ($queueSize < 100) {
82
- return;
83
  }
84
 
85
  $this->_addWarning(Mage::helper('marketingsoftware')->__("There is queue of %d local modification waiting to be processed", $queueSize));
@@ -88,18 +88,18 @@ class Copernica_MarketingSoftware_Controller_Action extends Mage_Adminhtml_Contr
88
  /**
89
  * Check if queue have too old items.
90
  *
91
- * @param Copernica_MarketingSoftware_Model_Mysql4_Queue_Item_Collection $queue
92
  */
93
  protected function _checkQueueTime(Copernica_MarketingSoftware_Model_Mysql4_Queue_Item_Collection $queue)
94
  {
95
  $oldestItemTimestamp = $queue->getQueueStartTime();
96
 
97
  if (is_null($oldestItemTimestamp)) {
98
- return;
99
  }
100
 
101
  if (time() - strtotime($oldestItemTimestamp) < 60*60*24) {
102
- return;
103
  }
104
 
105
  $printableTime = Mage::helper('core')->formatDate($oldestItemTimestamp, 'short', true);
@@ -115,7 +115,7 @@ class Copernica_MarketingSoftware_Controller_Action extends Mage_Adminhtml_Contr
115
  $accessToken = Mage::helper('marketingsoftware/config')->getAccessToken();
116
 
117
  if ($accessToken) {
118
- return;
119
  }
120
 
121
  $this->_addWarning(Mage::helper('marketingsoftware')->__('There is no access token for API communication.'));
@@ -124,7 +124,7 @@ class Copernica_MarketingSoftware_Controller_Action extends Mage_Adminhtml_Contr
124
  /**
125
  * Add warning message to controller.
126
  *
127
- * @param string $text
128
  * @return self
129
  */
130
  protected function _addWarning($text)
@@ -137,8 +137,8 @@ class Copernica_MarketingSoftware_Controller_Action extends Mage_Adminhtml_Contr
137
  /**
138
  * Add error message to controller.
139
  *
140
- * @todo Not used???
141
- * @param string $text
142
  * @return self
143
  */
144
  protected function _addError($text)
@@ -171,21 +171,21 @@ class Copernica_MarketingSoftware_Controller_Action extends Mage_Adminhtml_Contr
171
  /**
172
  * Get notifications of given type
173
  *
174
- * @param string $type
175
  * @return array
176
  */
177
  protected function _getNotifications($type)
178
  {
179
  if (!array_key_exists($type, $this->_notes)) {
180
- return array();
181
  }
182
 
183
  $output = $this->_notes[$type];
184
 
185
- if(is_array($output)) {
186
- return $output;
187
  }
188
 
189
  return array();
190
  }
191
- }
65
  */
66
  protected function _isAllowed()
67
  {
68
+ return Mage::getSingleton('admin/session')->isAllowed('copernica');
69
  }
70
 
71
  /**
72
  * Check if queue have too many items. This method will output messages on
73
  * admin session to inform him about current state.
74
  *
75
+ * @param Copernica_MarketingSoftware_Model_Mysql4_Queue_Item_Collection $queue
76
  */
77
  protected function _checkQueueSize(Copernica_MarketingSoftware_Model_Mysql4_Queue_Item_Collection $queue)
78
  {
79
  $queueSize = $queue->getSize();
80
 
81
  if ($queueSize < 100) {
82
+ return;
83
  }
84
 
85
  $this->_addWarning(Mage::helper('marketingsoftware')->__("There is queue of %d local modification waiting to be processed", $queueSize));
88
  /**
89
  * Check if queue have too old items.
90
  *
91
+ * @param Copernica_MarketingSoftware_Model_Mysql4_Queue_Item_Collection $queue
92
  */
93
  protected function _checkQueueTime(Copernica_MarketingSoftware_Model_Mysql4_Queue_Item_Collection $queue)
94
  {
95
  $oldestItemTimestamp = $queue->getQueueStartTime();
96
 
97
  if (is_null($oldestItemTimestamp)) {
98
+ return;
99
  }
100
 
101
  if (time() - strtotime($oldestItemTimestamp) < 60*60*24) {
102
+ return;
103
  }
104
 
105
  $printableTime = Mage::helper('core')->formatDate($oldestItemTimestamp, 'short', true);
115
  $accessToken = Mage::helper('marketingsoftware/config')->getAccessToken();
116
 
117
  if ($accessToken) {
118
+ return;
119
  }
120
 
121
  $this->_addWarning(Mage::helper('marketingsoftware')->__('There is no access token for API communication.'));
124
  /**
125
  * Add warning message to controller.
126
  *
127
+ * @param string $text
128
  * @return self
129
  */
130
  protected function _addWarning($text)
137
  /**
138
  * Add error message to controller.
139
  *
140
+ * @todo Not used???
141
+ * @param string $text
142
  * @return self
143
  */
144
  protected function _addError($text)
171
  /**
172
  * Get notifications of given type
173
  *
174
+ * @param string $type
175
  * @return array
176
  */
177
  protected function _getNotifications($type)
178
  {
179
  if (!array_key_exists($type, $this->_notes)) {
180
+ return array();
181
  }
182
 
183
  $output = $this->_notes[$type];
184
 
185
+ if (is_array($output)) {
186
+ return $output;
187
  }
188
 
189
  return array();
190
  }
191
+ }
app/code/community/Copernica/MarketingSoftware/Helper/Api.php CHANGED
@@ -42,15 +42,17 @@ class Copernica_MarketingSoftware_Helper_Api extends Copernica_MarketingSoftware
42
  */
43
  public function upgradeRequest($clientId, $clientSecret, $redirectUri, $code)
44
  {
45
- $output = $this->_restRequest()->get('token', array(
 
46
  'client_id' => $clientId,
47
  'client_secret' => $clientSecret,
48
  'redirect_uri' => $redirectUri,
49
- 'code' => $code
50
- ));
 
51
 
52
  if (isset($output['access_token'])) {
53
- return $output['access_token'];
54
  }
55
 
56
  return false;
@@ -59,7 +61,7 @@ class Copernica_MarketingSoftware_Helper_Api extends Copernica_MarketingSoftware
59
  /**
60
  * Search for profiles that match certain identifier
61
  *
62
- * @param string $identifier
63
  * @return array
64
  */
65
  public function searchProfiles($identifier)
@@ -77,7 +79,7 @@ class Copernica_MarketingSoftware_Helper_Api extends Copernica_MarketingSoftware
77
  /**
78
  * Update the profiles given a customer.
79
  *
80
- * @param Copernica_MarketingSoftware_Model_Copernica_Profile_Customer $customer
81
  */
82
  public function updateProfiles(Copernica_MarketingSoftware_Model_Copernica_Profile_Customer $customer)
83
  {
@@ -87,7 +89,7 @@ class Copernica_MarketingSoftware_Helper_Api extends Copernica_MarketingSoftware
87
  Mage::log('Data: '.print_r($data->toArray(), true));
88
 
89
  foreach (debug_backtrace() as $tr) {
90
- Mage::log(' '.$tr['file'].''.$tr['line']);
91
  }
92
 
93
  return;
@@ -115,12 +117,12 @@ class Copernica_MarketingSoftware_Helper_Api extends Copernica_MarketingSoftware
115
  /**
116
  * Remove the profile by customer instance
117
  *
118
- * @param Copernica_MarketingSoftware_Model_Copernica_Profile_Customer $customer
119
  */
120
  public function removeProfiles(Copernica_MarketingSoftware_Model_Copernica_Profile_Customer $customer)
121
  {
122
  if ($customer->getId() === false) {
123
- return false;
124
  }
125
 
126
  $output = $this->_restRequest()->get(
@@ -131,11 +133,11 @@ class Copernica_MarketingSoftware_Helper_Api extends Copernica_MarketingSoftware
131
  );
132
 
133
  if (!isset($output['data'])) {
134
- return;
135
  }
136
 
137
  foreach ($output['data'] as $profile) {
138
- $this->_restRequest()->delete('profile/'.$profile['ID']);
139
  }
140
  }
141
 
@@ -143,14 +145,14 @@ class Copernica_MarketingSoftware_Helper_Api extends Copernica_MarketingSoftware
143
  * Update or create quote item sub profile.
144
  *
145
  * @param string $profileID
146
- * @param Copernica_MarketingSoftware_Model_Copernica_Subprofile $data
147
  */
148
  public function updateQuoteItemSubProfiles($profileID, Copernica_MarketingSoftware_Model_Copernica_Subprofile $data)
149
  {
150
  $collectionId = Mage::helper('marketingsoftware/config')->getQuoteItemCollectionId();
151
 
152
  if (empty($collectionId)) {
153
- return false;
154
  }
155
 
156
  $this->_restRequest()->put(
@@ -171,25 +173,25 @@ class Copernica_MarketingSoftware_Helper_Api extends Copernica_MarketingSoftware
171
  $collectionId = Mage::helper('marketingsoftware/config')->getQuoteItemCollectionId();
172
 
173
  if (empty($collectionId)) {
174
- return false;
175
  }
176
 
177
  $output = $this->_restRequest()->get(
178
  'profile/'.$profileID.'/subprofiles/'.$collectionId,
179
  array (
180
- 'fields[]' => 'quote_id=='.$quote_id
181
  )
182
  );
183
 
184
  if (!isset($output['total'])) {
185
- return false;
186
  }
187
 
188
  if ($output['total'] == 0) {
189
- return true;
190
  }
191
 
192
- foreach($output['data'] as $subprofile) {
193
  $this->_restRequest()->delete('subprofile/'.$subprofile['ID']);
194
  }
195
  }
@@ -198,14 +200,14 @@ class Copernica_MarketingSoftware_Helper_Api extends Copernica_MarketingSoftware
198
  * Update order subprofile
199
  *
200
  * @param string $profileID
201
- * @param Copernica_MarketingSoftware_Model_Copernica_Subprofile $data
202
  */
203
  public function updateOrderSubProfile($profileID, Copernica_MarketingSoftware_Model_Copernica_Subprofile $data)
204
  {
205
  $collectionId = Mage::helper('marketingsoftware/config')->getOrdersCollectionId();
206
 
207
  if (empty($collectionId)) {
208
- return false;
209
  }
210
 
211
  $this->_restRequest()->put(
@@ -218,15 +220,15 @@ class Copernica_MarketingSoftware_Helper_Api extends Copernica_MarketingSoftware
218
  /**
219
  * Update the order item subprofiles in a profile.
220
  *
221
- * @param string customer identifier $profileID
222
- * @param Copernica_MarketingSoftware_Model_Copernica_Orderitem_Subprofile $data
223
  */
224
  public function updateOrderItemSubProfiles($profileID, Copernica_MarketingSoftware_Model_Copernica_Orderitem_Subprofile $data)
225
  {
226
  $collectionId = Mage::helper('marketingsoftware/config')->getOrderItemCollectionId();
227
 
228
  if (empty($collectionId)) {
229
- return false;
230
  }
231
 
232
  $this->_restRequest()->put(
@@ -239,36 +241,36 @@ class Copernica_MarketingSoftware_Helper_Api extends Copernica_MarketingSoftware
239
  /**
240
  * Update the wishlist item subprofiles in a profile.
241
  *
242
- * @param string customer identifier $profileID
243
- * @param Copernica_MarketingSoftware_Model_Copernica_Wishlist_Item_Subprofile $data
244
  */
245
  public function updateWishlistItemSubProfiles($profileID, Copernica_MarketingSoftware_Model_Copernica_Wishlist_Item_Subprofile $data)
246
  {
247
- $collectionId = Mage::helper('marketingsoftware/config')->getWishlistItemCollectionId();
248
 
249
- if (empty($collectionId)) {
250
- return false;
251
- }
252
 
253
- $this->_restRequest()->put(
254
- 'profile/'.$profileID.'/subprofiles/'.$collectionId,
255
- $data->toArray(),
256
- array('fields[]' => 'item_id=='.$data->id(), 'create' => 'true')
257
- );
258
  }
259
 
260
  /**
261
  * Update address subprofile in a profile
262
  *
263
  * @param string $profileID
264
- * @param Copernica_MarketingSoftware_Model_Copernica_Subprofile $data
265
  */
266
  public function updateAddressSubProfiles($profileID, Copernica_MarketingSoftware_Model_Copernica_Subprofile $data)
267
  {
268
  $collectionId = Mage::helper('marketingsoftware/config')->getAddressesCollectionId();
269
 
270
  if (empty($collectionId)) {
271
- return false;
272
  }
273
 
274
  $this->_restRequest()->put(
@@ -282,20 +284,20 @@ class Copernica_MarketingSoftware_Helper_Api extends Copernica_MarketingSoftware
282
  * Update product views subprofile in a certain profile.
283
  *
284
  * @param string $profileID
285
- * @param Copernica_MarketingSoftware_Model_Copernica_Product_Viewed_Subprofile $data
286
  */
287
  public function updateViewedProductSubProfiles($profileID, Copernica_MarketingSoftware_Model_Copernica_Product_Viewed_Subprofile $data)
288
  {
289
  $collectionId = Mage::helper('marketingsoftware/config')->getViewedProductCollectionId();
290
 
291
  if (empty($collectionId)) {
292
- return false;
293
  }
294
 
295
  $this->_restRequest()->put(
296
  'profile/'.$profileID.'/subprofiles/'.$collectionId, $data->toArray(), array(
297
- 'fields[]' => 'id=='.$data->id(),
298
- 'create' => 'true'
299
  )
300
  );
301
  }
@@ -312,7 +314,7 @@ class Copernica_MarketingSoftware_Helper_Api extends Copernica_MarketingSoftware
312
  $collectionId = Mage::helper('marketingsoftware/config')->getQuoteItemCollectionId();
313
 
314
  if (empty($collectionId)) {
315
- return false;
316
  }
317
 
318
  // Get all subprofiles that we want to remove as old quote items
@@ -327,7 +329,7 @@ class Copernica_MarketingSoftware_Helper_Api extends Copernica_MarketingSoftware
327
  );
328
 
329
  if (isset($output['error'])) {
330
- return false;
331
  }
332
 
333
  $request = $this->_restRequest();
@@ -347,7 +349,7 @@ class Copernica_MarketingSoftware_Helper_Api extends Copernica_MarketingSoftware
347
  /**
348
  * Check if database exists
349
  *
350
- * @param string $databaseName
351
  * @return boolean
352
  */
353
  public function databaseExists($databaseName)
42
  */
43
  public function upgradeRequest($clientId, $clientSecret, $redirectUri, $code)
44
  {
45
+ $output = $this->_restRequest()->get(
46
+ 'token', array(
47
  'client_id' => $clientId,
48
  'client_secret' => $clientSecret,
49
  'redirect_uri' => $redirectUri,
50
+ 'code' => $code
51
+ )
52
+ );
53
 
54
  if (isset($output['access_token'])) {
55
+ return $output['access_token'];
56
  }
57
 
58
  return false;
61
  /**
62
  * Search for profiles that match certain identifier
63
  *
64
+ * @param string $identifier
65
  * @return array
66
  */
67
  public function searchProfiles($identifier)
79
  /**
80
  * Update the profiles given a customer.
81
  *
82
+ * @param Copernica_MarketingSoftware_Model_Copernica_Profile_Customer $customer
83
  */
84
  public function updateProfiles(Copernica_MarketingSoftware_Model_Copernica_Profile_Customer $customer)
85
  {
89
  Mage::log('Data: '.print_r($data->toArray(), true));
90
 
91
  foreach (debug_backtrace() as $tr) {
92
+ Mage::log(' '.$tr['file'].''.$tr['line']);
93
  }
94
 
95
  return;
117
  /**
118
  * Remove the profile by customer instance
119
  *
120
+ * @param Copernica_MarketingSoftware_Model_Copernica_Profile_Customer $customer
121
  */
122
  public function removeProfiles(Copernica_MarketingSoftware_Model_Copernica_Profile_Customer $customer)
123
  {
124
  if ($customer->getId() === false) {
125
+ return false;
126
  }
127
 
128
  $output = $this->_restRequest()->get(
133
  );
134
 
135
  if (!isset($output['data'])) {
136
+ return;
137
  }
138
 
139
  foreach ($output['data'] as $profile) {
140
+ $this->_restRequest()->delete('profile/'.$profile['ID']);
141
  }
142
  }
143
 
145
  * Update or create quote item sub profile.
146
  *
147
  * @param string $profileID
148
+ * @param Copernica_MarketingSoftware_Model_Copernica_Subprofile $data
149
  */
150
  public function updateQuoteItemSubProfiles($profileID, Copernica_MarketingSoftware_Model_Copernica_Subprofile $data)
151
  {
152
  $collectionId = Mage::helper('marketingsoftware/config')->getQuoteItemCollectionId();
153
 
154
  if (empty($collectionId)) {
155
+ return false;
156
  }
157
 
158
  $this->_restRequest()->put(
173
  $collectionId = Mage::helper('marketingsoftware/config')->getQuoteItemCollectionId();
174
 
175
  if (empty($collectionId)) {
176
+ return false;
177
  }
178
 
179
  $output = $this->_restRequest()->get(
180
  'profile/'.$profileID.'/subprofiles/'.$collectionId,
181
  array (
182
+ 'fields[]' => 'quote_id=='.$quoteID
183
  )
184
  );
185
 
186
  if (!isset($output['total'])) {
187
+ return false;
188
  }
189
 
190
  if ($output['total'] == 0) {
191
+ return true;
192
  }
193
 
194
+ foreach ($output['data'] as $subprofile) {
195
  $this->_restRequest()->delete('subprofile/'.$subprofile['ID']);
196
  }
197
  }
200
  * Update order subprofile
201
  *
202
  * @param string $profileID
203
+ * @param Copernica_MarketingSoftware_Model_Copernica_Subprofile $data
204
  */
205
  public function updateOrderSubProfile($profileID, Copernica_MarketingSoftware_Model_Copernica_Subprofile $data)
206
  {
207
  $collectionId = Mage::helper('marketingsoftware/config')->getOrdersCollectionId();
208
 
209
  if (empty($collectionId)) {
210
+ return false;
211
  }
212
 
213
  $this->_restRequest()->put(
220
  /**
221
  * Update the order item subprofiles in a profile.
222
  *
223
+ * @param string customer identifier $profileID
224
+ * @param Copernica_MarketingSoftware_Model_Copernica_Orderitem_Subprofile $data
225
  */
226
  public function updateOrderItemSubProfiles($profileID, Copernica_MarketingSoftware_Model_Copernica_Orderitem_Subprofile $data)
227
  {
228
  $collectionId = Mage::helper('marketingsoftware/config')->getOrderItemCollectionId();
229
 
230
  if (empty($collectionId)) {
231
+ return false;
232
  }
233
 
234
  $this->_restRequest()->put(
241
  /**
242
  * Update the wishlist item subprofiles in a profile.
243
  *
244
+ * @param string customer identifier $profileID
245
+ * @param Copernica_MarketingSoftware_Model_Copernica_Wishlist_Item_Subprofile $data
246
  */
247
  public function updateWishlistItemSubProfiles($profileID, Copernica_MarketingSoftware_Model_Copernica_Wishlist_Item_Subprofile $data)
248
  {
249
+ $collectionId = Mage::helper('marketingsoftware/config')->getWishlistItemCollectionId();
250
 
251
+ if (empty($collectionId)) {
252
+ return false;
253
+ }
254
 
255
+ $this->_restRequest()->put(
256
+ 'profile/'.$profileID.'/subprofiles/'.$collectionId,
257
+ $data->toArray(),
258
+ array('fields[]' => 'item_id=='.$data->id(), 'create' => 'true')
259
+ );
260
  }
261
 
262
  /**
263
  * Update address subprofile in a profile
264
  *
265
  * @param string $profileID
266
+ * @param Copernica_MarketingSoftware_Model_Copernica_Subprofile $data
267
  */
268
  public function updateAddressSubProfiles($profileID, Copernica_MarketingSoftware_Model_Copernica_Subprofile $data)
269
  {
270
  $collectionId = Mage::helper('marketingsoftware/config')->getAddressesCollectionId();
271
 
272
  if (empty($collectionId)) {
273
+ return false;
274
  }
275
 
276
  $this->_restRequest()->put(
284
  * Update product views subprofile in a certain profile.
285
  *
286
  * @param string $profileID
287
+ * @param Copernica_MarketingSoftware_Model_Copernica_Product_Viewed_Subprofile $data
288
  */
289
  public function updateViewedProductSubProfiles($profileID, Copernica_MarketingSoftware_Model_Copernica_Product_Viewed_Subprofile $data)
290
  {
291
  $collectionId = Mage::helper('marketingsoftware/config')->getViewedProductCollectionId();
292
 
293
  if (empty($collectionId)) {
294
+ return false;
295
  }
296
 
297
  $this->_restRequest()->put(
298
  'profile/'.$profileID.'/subprofiles/'.$collectionId, $data->toArray(), array(
299
+ 'fields[]' => 'id=='.$data->id(),
300
+ 'create' => 'true'
301
  )
302
  );
303
  }
314
  $collectionId = Mage::helper('marketingsoftware/config')->getQuoteItemCollectionId();
315
 
316
  if (empty($collectionId)) {
317
+ return false;
318
  }
319
 
320
  // Get all subprofiles that we want to remove as old quote items
329
  );
330
 
331
  if (isset($output['error'])) {
332
+ return false;
333
  }
334
 
335
  $request = $this->_restRequest();
349
  /**
350
  * Check if database exists
351
  *
352
+ * @param string $databaseName
353
  * @return boolean
354
  */
355
  public function databaseExists($databaseName)
app/code/community/Copernica/MarketingSoftware/Helper/Api/Abstract.php CHANGED
@@ -34,14 +34,14 @@ class Copernica_MarketingSoftware_Helper_Api_Abstract extends Mage_Core_Helper_A
34
  * Since Magento is cheating with theirs singleton implementation, we want
35
  * to use static fields for storing request instance.
36
  *
37
- * @var Copernica_MarketingSoftware_Helper_Rest_Request
38
  */
39
  static protected $_restRequest = null;
40
 
41
  /**
42
  * Database id that is on Copernica platform.
43
  *
44
- * @var int
45
  */
46
  static protected $_databaseId = false;
47
 
@@ -71,7 +71,7 @@ class Copernica_MarketingSoftware_Helper_Api_Abstract extends Mage_Core_Helper_A
71
  /**
72
  * Initialize helper.
73
  *
74
- * @return Copernica_MarketingSoftware_Helper_Api_Abstract
75
  */
76
  public function init()
77
  {
@@ -88,12 +88,12 @@ class Copernica_MarketingSoftware_Helper_Api_Abstract extends Mage_Core_Helper_A
88
  * API and circumstances. That is why we don't want to rely on magento
89
  * helpers as a final solution for reqeust instance.
90
  *
91
- * @return Copernica_MarketingSoftware_Helper_Rest_Request
92
  */
93
  protected function _restRequest()
94
  {
95
  if (!is_null(self::$_restRequest)) {
96
- return self::$_restRequest;
97
  }
98
 
99
  return self::$_restRequest = Mage::helper('marketingsoftware/rest_request');
@@ -102,7 +102,7 @@ class Copernica_MarketingSoftware_Helper_Api_Abstract extends Mage_Core_Helper_A
102
  /**
103
  * Set database Id
104
  *
105
- * @param int $id
106
  */
107
  protected function _setDatabaseId($id)
108
  {
@@ -112,7 +112,7 @@ class Copernica_MarketingSoftware_Helper_Api_Abstract extends Mage_Core_Helper_A
112
  /**
113
  * Check if this API instance is valid.
114
  *
115
- * @param boolean $extensive
116
  * @return boolean
117
  */
118
  public function check($extensive = false)
@@ -131,7 +131,7 @@ class Copernica_MarketingSoftware_Helper_Api_Abstract extends Mage_Core_Helper_A
131
  $databaseId = Mage::helper('marketingsoftware/config')->getDatabaseId();
132
 
133
  if ($databaseId) {
134
- return $databaseId;
135
  }
136
 
137
  $databaseName = Mage::helper('marketingsoftware/config')->getDatabaseName();
@@ -153,7 +153,7 @@ class Copernica_MarketingSoftware_Helper_Api_Abstract extends Mage_Core_Helper_A
153
  * Get database Id by its name. This method will return false when we can
154
  * not fetch database.
155
  *
156
- * @param string $databaseName
157
  * @return int|false
158
  */
159
  protected function _getDatabaseIdByName($databaseName)
@@ -172,15 +172,15 @@ class Copernica_MarketingSoftware_Helper_Api_Abstract extends Mage_Core_Helper_A
172
  /**
173
  * Get database id that will be used inside Copernica platform
174
  *
175
- * @param string|false $databaseName
176
  * @return int
177
  */
178
  public function getDatabaseId($databaseName = false)
179
  {
180
  if ($databaseName === false) {
181
- $databaseId = $this->_getStoredDatabaseID();
182
  } else {
183
- $databaseId = $this->_getDatabaseIdByName($databaseName);
184
  }
185
 
186
  return $databaseId;
@@ -189,13 +189,13 @@ class Copernica_MarketingSoftware_Helper_Api_Abstract extends Mage_Core_Helper_A
189
  /**
190
  * Translate collection name into an ID.
191
  *
192
- * @param string $name
193
  * @return int
194
  */
195
  public function getCollectionId($name)
196
  {
197
  if (!is_null(self::$_collectionIdCache) && array_key_exists($name, self::$_collectionIdCache)) {
198
- return self::$_collectionIdCache[$name];
199
  }
200
 
201
  $output = $this->_restRequest()->get(
@@ -203,7 +203,7 @@ class Copernica_MarketingSoftware_Helper_Api_Abstract extends Mage_Core_Helper_A
203
  );
204
 
205
  if ($output['total'] == 0) {
206
- return false;
207
  }
208
 
209
  self::$_collectionIdCache = array();
@@ -213,7 +213,7 @@ class Copernica_MarketingSoftware_Helper_Api_Abstract extends Mage_Core_Helper_A
213
  }
214
 
215
  if (array_key_exists($name, self::$_collectionIdCache)) {
216
- return self::$_collectionIdCache[$name];
217
  }
218
 
219
  return false;
@@ -224,7 +224,7 @@ class Copernica_MarketingSoftware_Helper_Api_Abstract extends Mage_Core_Helper_A
224
  * This method is little bit more flexible. It's possible to supply customer
225
  * data by copernica model or by array with 'id', 'storeView', 'email' fields.
226
  *
227
- * @param Copernica_MarketingSoftware_Model_Copernica_Entity_Customer|array $customer
228
  * @return int the copernica profile Id
229
  */
230
  public function getProfileId($customer)
@@ -242,14 +242,14 @@ class Copernica_MarketingSoftware_Helper_Api_Abstract extends Mage_Core_Helper_A
242
  $profileId = false;
243
 
244
  if ($customerId === false) {
245
- return false;
246
  }
247
 
248
  $profileCacheCollection = Mage::getModel('marketingsoftware/profile_cache')
249
  ->getCollection()
250
  ->setPageSize(1)
251
  ->addFieldToFilter('copernica_id', $customerId)
252
- ->addFieldToFilter('store_view', $storeView);
253
 
254
  $profileCache = $profileCacheCollection->getFirstItem();
255
 
@@ -257,9 +257,9 @@ class Copernica_MarketingSoftware_Helper_Api_Abstract extends Mage_Core_Helper_A
257
  $profileId = $profileCache->getProfileId();
258
 
259
  if ($profileId > 0 && $profileId !== false && !is_null($profileId)) {
260
- return $profileId;
261
  } else {
262
- $profileCache->delete();
263
  }
264
  }
265
 
@@ -290,7 +290,7 @@ class Copernica_MarketingSoftware_Helper_Api_Abstract extends Mage_Core_Helper_A
290
  $profileId = $profileCache->getProfileId();
291
 
292
  if ($profileId > 0 && $profileId !== false && !is_null($profileId)) {
293
- return $profileId;
294
  }
295
  }
296
 
@@ -300,21 +300,21 @@ class Copernica_MarketingSoftware_Helper_Api_Abstract extends Mage_Core_Helper_A
300
  * a customer Id.
301
  */
302
  if (!is_null($customerId) && strlen($customerId)) {
303
- $profileId = $this->_getProfileIdByCustomerId($customerId);
304
  }
305
 
306
  if ($profileId !== false) {
307
  if ($profileId > 0 && $profileId !== false && !is_null($profileId)) {
308
  if (strlen($email)) {
309
- $profileCache->setEmail($email);
310
  }
311
 
312
  if (strlen($storeView)) {
313
- $profileCache->setStoreView($storeView);
314
  }
315
 
316
  if (!is_null($customerId)) {
317
- $profileCache->setCopernicaId($customerId);
318
  }
319
 
320
  $profileCache->setProfileId($profileId);
@@ -325,14 +325,14 @@ class Copernica_MarketingSoftware_Helper_Api_Abstract extends Mage_Core_Helper_A
325
  }
326
 
327
  if (strlen($email) == 0) {
328
- return false;
329
  }
330
 
331
  $profileId = $this->_getProfileIdByEmail($email, $storeView);
332
 
333
  if ($profileId !== false) {
334
  if (!is_null($customerId)) {
335
- $profileCache->setCopernicaId($customerId);
336
  }
337
 
338
  $profileCache->setStoreView($storeView);
@@ -350,7 +350,7 @@ class Copernica_MarketingSoftware_Helper_Api_Abstract extends Mage_Core_Helper_A
350
  * Get profile Id by customer Id. When profile can not be found FALSE will
351
  * be returned.
352
  *
353
- * @param string $customerId
354
  * @return int|false
355
  */
356
  protected function _getProfileIdByCustomerId($customerId)
@@ -363,11 +363,11 @@ class Copernica_MarketingSoftware_Helper_Api_Abstract extends Mage_Core_Helper_A
363
  );
364
 
365
  if (!isset($profiles['data'][0])) {
366
- return false;
367
  }
368
 
369
  if (is_null($profiles['data'][0]['ID']) || (int)$profiles['data'][0]['ID'] == 0) {
370
- return false;
371
  }
372
 
373
  return $profiles['data'][0]['ID'];
@@ -377,8 +377,8 @@ class Copernica_MarketingSoftware_Helper_Api_Abstract extends Mage_Core_Helper_A
377
  * Get profile Id by email address. FALSE will be returned if profile was not
378
  * found.
379
  *
380
- * @param string $email
381
- * @param string $storeView
382
  * @return int
383
  */
384
  protected function _getProfileIdByEmail($email, $storeView)
@@ -386,7 +386,7 @@ class Copernica_MarketingSoftware_Helper_Api_Abstract extends Mage_Core_Helper_A
386
  $customerLinkedFields = Mage::helper('marketingsoftware/config')->getLinkedCustomerFields();
387
 
388
  if (!isset($customerLinkedFields['email']) || !isset($customerLinkedFields['storeView'])) {
389
- return false;
390
  }
391
 
392
  $requestParams = array(
@@ -397,11 +397,11 @@ class Copernica_MarketingSoftware_Helper_Api_Abstract extends Mage_Core_Helper_A
397
  $profiles = $this->_restRequest()->get('database/'.$this->getDatabaseId().'/profiles', array ( 'fields' => $requestParams ));
398
 
399
  if (!isset($profiles['data'][0])) {
400
- return false;
401
  }
402
 
403
  if (is_null($profiles['data'][0]['ID']) || (int)$profiles['data'][0]['ID'] == 0) {
404
- return false;
405
  }
406
 
407
  return $profiles['data'][0]['ID'];
@@ -411,7 +411,7 @@ class Copernica_MarketingSoftware_Helper_Api_Abstract extends Mage_Core_Helper_A
411
  * Get profile Id from cache
412
  *
413
  * @todo not used, why??
414
- * @param string $customerId
415
  * @return int
416
  */
417
  protected function _getProfileIdFromCache($customerId)
@@ -425,7 +425,7 @@ class Copernica_MarketingSoftware_Helper_Api_Abstract extends Mage_Core_Helper_A
425
  $profileId = $profileCache->getProfileId();
426
 
427
  if (!is_null($profileId)) {
428
- return $profileId;
429
  }
430
  }
431
  }
34
  * Since Magento is cheating with theirs singleton implementation, we want
35
  * to use static fields for storing request instance.
36
  *
37
+ * @var Copernica_MarketingSoftware_Helper_Rest_Request
38
  */
39
  static protected $_restRequest = null;
40
 
41
  /**
42
  * Database id that is on Copernica platform.
43
  *
44
+ * @var int
45
  */
46
  static protected $_databaseId = false;
47
 
71
  /**
72
  * Initialize helper.
73
  *
74
+ * @return Copernica_MarketingSoftware_Helper_Api_Abstract
75
  */
76
  public function init()
77
  {
88
  * API and circumstances. That is why we don't want to rely on magento
89
  * helpers as a final solution for reqeust instance.
90
  *
91
+ * @return Copernica_MarketingSoftware_Helper_Rest_Request
92
  */
93
  protected function _restRequest()
94
  {
95
  if (!is_null(self::$_restRequest)) {
96
+ return self::$_restRequest;
97
  }
98
 
99
  return self::$_restRequest = Mage::helper('marketingsoftware/rest_request');
102
  /**
103
  * Set database Id
104
  *
105
+ * @param int $id
106
  */
107
  protected function _setDatabaseId($id)
108
  {
112
  /**
113
  * Check if this API instance is valid.
114
  *
115
+ * @param boolean $extensive
116
  * @return boolean
117
  */
118
  public function check($extensive = false)
131
  $databaseId = Mage::helper('marketingsoftware/config')->getDatabaseId();
132
 
133
  if ($databaseId) {
134
+ return $databaseId;
135
  }
136
 
137
  $databaseName = Mage::helper('marketingsoftware/config')->getDatabaseName();
153
  * Get database Id by its name. This method will return false when we can
154
  * not fetch database.
155
  *
156
+ * @param string $databaseName
157
  * @return int|false
158
  */
159
  protected function _getDatabaseIdByName($databaseName)
172
  /**
173
  * Get database id that will be used inside Copernica platform
174
  *
175
+ * @param string|false $databaseName
176
  * @return int
177
  */
178
  public function getDatabaseId($databaseName = false)
179
  {
180
  if ($databaseName === false) {
181
+ $databaseId = $this->_getStoredDatabaseID();
182
  } else {
183
+ $databaseId = $this->_getDatabaseIdByName($databaseName);
184
  }
185
 
186
  return $databaseId;
189
  /**
190
  * Translate collection name into an ID.
191
  *
192
+ * @param string $name
193
  * @return int
194
  */
195
  public function getCollectionId($name)
196
  {
197
  if (!is_null(self::$_collectionIdCache) && array_key_exists($name, self::$_collectionIdCache)) {
198
+ return self::$_collectionIdCache[$name];
199
  }
200
 
201
  $output = $this->_restRequest()->get(
203
  );
204
 
205
  if ($output['total'] == 0) {
206
+ return false;
207
  }
208
 
209
  self::$_collectionIdCache = array();
213
  }
214
 
215
  if (array_key_exists($name, self::$_collectionIdCache)) {
216
+ return self::$_collectionIdCache[$name];
217
  }
218
 
219
  return false;
224
  * This method is little bit more flexible. It's possible to supply customer
225
  * data by copernica model or by array with 'id', 'storeView', 'email' fields.
226
  *
227
+ * @param Copernica_MarketingSoftware_Model_Copernica_Entity_Customer|array $customer
228
  * @return int the copernica profile Id
229
  */
230
  public function getProfileId($customer)
242
  $profileId = false;
243
 
244
  if ($customerId === false) {
245
+ return false;
246
  }
247
 
248
  $profileCacheCollection = Mage::getModel('marketingsoftware/profile_cache')
249
  ->getCollection()
250
  ->setPageSize(1)
251
  ->addFieldToFilter('copernica_id', $customerId)
252
+ ->addFieldToFilter('store_view', $storeView);
253
 
254
  $profileCache = $profileCacheCollection->getFirstItem();
255
 
257
  $profileId = $profileCache->getProfileId();
258
 
259
  if ($profileId > 0 && $profileId !== false && !is_null($profileId)) {
260
+ return $profileId;
261
  } else {
262
+ $profileCache->delete();
263
  }
264
  }
265
 
290
  $profileId = $profileCache->getProfileId();
291
 
292
  if ($profileId > 0 && $profileId !== false && !is_null($profileId)) {
293
+ return $profileId;
294
  }
295
  }
296
 
300
  * a customer Id.
301
  */
302
  if (!is_null($customerId) && strlen($customerId)) {
303
+ $profileId = $this->_getProfileIdByCustomerId($customerId);
304
  }
305
 
306
  if ($profileId !== false) {
307
  if ($profileId > 0 && $profileId !== false && !is_null($profileId)) {
308
  if (strlen($email)) {
309
+ $profileCache->setEmail($email);
310
  }
311
 
312
  if (strlen($storeView)) {
313
+ $profileCache->setStoreView($storeView);
314
  }
315
 
316
  if (!is_null($customerId)) {
317
+ $profileCache->setCopernicaId($customerId);
318
  }
319
 
320
  $profileCache->setProfileId($profileId);
325
  }
326
 
327
  if (strlen($email) == 0) {
328
+ return false;
329
  }
330
 
331
  $profileId = $this->_getProfileIdByEmail($email, $storeView);
332
 
333
  if ($profileId !== false) {
334
  if (!is_null($customerId)) {
335
+ $profileCache->setCopernicaId($customerId);
336
  }
337
 
338
  $profileCache->setStoreView($storeView);
350
  * Get profile Id by customer Id. When profile can not be found FALSE will
351
  * be returned.
352
  *
353
+ * @param string $customerId
354
  * @return int|false
355
  */
356
  protected function _getProfileIdByCustomerId($customerId)
363
  );
364
 
365
  if (!isset($profiles['data'][0])) {
366
+ return false;
367
  }
368
 
369
  if (is_null($profiles['data'][0]['ID']) || (int)$profiles['data'][0]['ID'] == 0) {
370
+ return false;
371
  }
372
 
373
  return $profiles['data'][0]['ID'];
377
  * Get profile Id by email address. FALSE will be returned if profile was not
378
  * found.
379
  *
380
+ * @param string $email
381
+ * @param string $storeView
382
  * @return int
383
  */
384
  protected function _getProfileIdByEmail($email, $storeView)
386
  $customerLinkedFields = Mage::helper('marketingsoftware/config')->getLinkedCustomerFields();
387
 
388
  if (!isset($customerLinkedFields['email']) || !isset($customerLinkedFields['storeView'])) {
389
+ return false;
390
  }
391
 
392
  $requestParams = array(
397
  $profiles = $this->_restRequest()->get('database/'.$this->getDatabaseId().'/profiles', array ( 'fields' => $requestParams ));
398
 
399
  if (!isset($profiles['data'][0])) {
400
+ return false;
401
  }
402
 
403
  if (is_null($profiles['data'][0]['ID']) || (int)$profiles['data'][0]['ID'] == 0) {
404
+ return false;
405
  }
406
 
407
  return $profiles['data'][0]['ID'];
411
  * Get profile Id from cache
412
  *
413
  * @todo not used, why??
414
+ * @param string $customerId
415
  * @return int
416
  */
417
  protected function _getProfileIdFromCache($customerId)
425
  $profileId = $profileCache->getProfileId();
426
 
427
  if (!is_null($profileId)) {
428
+ return $profileId;
429
  }
430
  }
431
  }
app/code/community/Copernica/MarketingSoftware/Helper/Api/Builder.php CHANGED
@@ -32,7 +32,7 @@ class Copernica_MarketingSoftware_Helper_Api_Builder extends Copernica_Marketing
32
  /**
33
  * Will create proper database in Copernica platform
34
  *
35
- * @param string $databaseName
36
  */
37
  public function createDatabase($databaseName)
38
  {
@@ -41,10 +41,12 @@ class Copernica_MarketingSoftware_Helper_Api_Builder extends Copernica_Marketing
41
 
42
  $this->_restRequest()->post('databases', $data);
43
 
44
- $this->createDatabaseField($databaseName, 'customer_id', array(
 
45
  'type' => 'text',
46
  'length' => 64
47
- ));
 
48
  }
49
 
50
  /**
@@ -52,22 +54,22 @@ class Copernica_MarketingSoftware_Helper_Api_Builder extends Copernica_Marketing
52
  * For more info about what can be supplied in $options argument go:
53
  * @see https://www.copernica.com/en/support/rest/database-fields
54
  *
55
- * @param string $databaseName
56
- * @param string $fieldName
57
- * @param array $options
58
  */
59
  public function createDatabaseField($databaseName, $fieldName, $options = array())
60
  {
61
- $options = array_merge( array ('name' => $fieldName), array('displayed' => true), $options);
62
 
63
- $this->_restRequest()->post( 'database/'.urlencode($databaseName).'/fields', $options );
64
  }
65
 
66
  /**
67
  * Helper method to create date fields.
68
  *
69
- * @param string $databaseName
70
- * @param string $fieldName
71
  */
72
  public function createDatabaseDateField($databaseName, $fieldName)
73
  {
@@ -79,8 +81,8 @@ class Copernica_MarketingSoftware_Helper_Api_Builder extends Copernica_Marketing
79
  /**
80
  * Helper method to create datetime fields.
81
  *
82
- * @param string $databaseName
83
- * @param string $fieldName
84
  */
85
  public function createDatabaseDatetimeField($databaseName, $fieldName)
86
  {
@@ -92,8 +94,8 @@ class Copernica_MarketingSoftware_Helper_Api_Builder extends Copernica_Marketing
92
  /**
93
  * Helper method to create email fields.
94
  *
95
- * @param string $databaseName
96
- * @param string $fieldName
97
  */
98
  public function createDatabaseEmailField($databaseName, $fieldName)
99
  {
@@ -106,8 +108,8 @@ class Copernica_MarketingSoftware_Helper_Api_Builder extends Copernica_Marketing
106
  /**
107
  * Helper method to create newsletter fields.
108
  *
109
- * @param string $databaseName
110
- * @param string $fieldName
111
  */
112
  public function createDatabaseNewsletterField($databaseName, $fieldName)
113
  {
@@ -136,14 +138,14 @@ class Copernica_MarketingSoftware_Helper_Api_Builder extends Copernica_Marketing
136
  /**
137
  * Create collection inside given database.
138
  *
139
- * @param string $databaseName
140
- * @param string $collectionName
141
  * @param string $collectionType
142
- * @throws Copernica_MarketingSoftware_Exception
143
  */
144
  public function createCollection($databaseName, $collectionName, $collectionType)
145
  {
146
- $this->_restRequest()->post( 'database/'.urlencode($databaseName).'/collections', array ( 'name' => $collectionName ) );
147
 
148
  $requiredFields = $this->_requiredCollectionFields($collectionType);
149
 
@@ -155,7 +157,7 @@ class Copernica_MarketingSoftware_Helper_Api_Builder extends Copernica_Marketing
155
  /**
156
  * This method created collection field.
157
  *
158
- * @param string $databaseName
159
  * @param string $collectionName
160
  * @param string $collectionType
161
  * @param string $copernicaName
@@ -170,9 +172,13 @@ class Copernica_MarketingSoftware_Helper_Api_Builder extends Copernica_Marketing
170
 
171
  $collectionId = $this->_getCollectionIdFromDatabase($databaseName, $collectionName);
172
 
173
- $this->_restRequest()->post( 'collection/'.$collectionId.'/fields', array_merge($fieldDefinition, array(
174
- 'name' => $copernicaName
175
- )));
 
 
 
 
176
  }
177
 
178
  /**
@@ -189,24 +195,24 @@ class Copernica_MarketingSoftware_Helper_Api_Builder extends Copernica_Marketing
189
 
190
  if (isset($output['error'])) {
191
  if (strpos($output['error']['message'], 'No database') !== false) {
192
- throw Mage::exception('Copernica_MarketingSoftware', 'No database', Copernica_MarketingSoftware_Exception::DATABASE_NOT_EXISTS);
193
  } else {
194
- throw Mage::exception('Copernica_MarketingSoftware', $output['message'], Copernica_MarketingSoftware_Exception::API_REQUEST_ERROR);
195
  }
196
  } else if (!is_array($output['data'])) {
197
- throw Mage::exception('Copernica_MarketingSoftware', 'Unknown error' ,Copernica_MarketingSoftware_Exception::API_REQUEST_ERROR);
198
  }
199
 
200
  $collectionId = false;
201
 
202
  foreach ($output['data'] as $collection) {
203
  if ($collection['name'] == $collectionName) {
204
- $collectionId = $collection['ID'];
205
  }
206
  }
207
 
208
  if ($collectionId === false) {
209
- throw Mage::exception('Copernica_MarketingSoftware', 'Collection does not exists', Copernica_MarketingSoftware_Exception::COLLECTION_NOT_EXISTS);
210
  }
211
 
212
  return $collectionId;
@@ -222,22 +228,22 @@ class Copernica_MarketingSoftware_Helper_Api_Builder extends Copernica_Marketing
222
  {
223
  switch ($collectionType) {
224
  case 'cartproducts':
225
- return Mage::helper('marketingsoftware')->requiredQuoteItemFields();
226
-
227
  case 'orders' :
228
- return Mage::helper('marketingsoftware')->requiredOrderFields();
229
-
230
  case 'orderproducts':
231
- return Mage::helper('marketingsoftware')->requiredOrderItemFields();
232
-
233
  case 'addresses':
234
- return Mage::helper('marketingsoftware')->requiredAddressFields();
235
-
236
  case 'viewedproducts':
237
- return Mage::helper('marketingsoftware')->requiredViewedProductFields();
238
-
239
  case 'wishlistproducts':
240
- return Mage::helper('marketingsoftware')->requiredWishlistItemFields();
241
  }
242
  }
243
  }
32
  /**
33
  * Will create proper database in Copernica platform
34
  *
35
+ * @param string $databaseName
36
  */
37
  public function createDatabase($databaseName)
38
  {
41
 
42
  $this->_restRequest()->post('databases', $data);
43
 
44
+ $this->createDatabaseField(
45
+ $databaseName, 'customer_id', array(
46
  'type' => 'text',
47
  'length' => 64
48
+ )
49
+ );
50
  }
51
 
52
  /**
54
  * For more info about what can be supplied in $options argument go:
55
  * @see https://www.copernica.com/en/support/rest/database-fields
56
  *
57
+ * @param string $databaseName
58
+ * @param string $fieldName
59
+ * @param array $options
60
  */
61
  public function createDatabaseField($databaseName, $fieldName, $options = array())
62
  {
63
+ $options = array_merge(array ('name' => $fieldName), array('displayed' => true), $options);
64
 
65
+ $this->_restRequest()->post('database/'.urlencode($databaseName).'/fields', $options);
66
  }
67
 
68
  /**
69
  * Helper method to create date fields.
70
  *
71
+ * @param string $databaseName
72
+ * @param string $fieldName
73
  */
74
  public function createDatabaseDateField($databaseName, $fieldName)
75
  {
81
  /**
82
  * Helper method to create datetime fields.
83
  *
84
+ * @param string $databaseName
85
+ * @param string $fieldName
86
  */
87
  public function createDatabaseDatetimeField($databaseName, $fieldName)
88
  {
94
  /**
95
  * Helper method to create email fields.
96
  *
97
+ * @param string $databaseName
98
+ * @param string $fieldName
99
  */
100
  public function createDatabaseEmailField($databaseName, $fieldName)
101
  {
108
  /**
109
  * Helper method to create newsletter fields.
110
  *
111
+ * @param string $databaseName
112
+ * @param string $fieldName
113
  */
114
  public function createDatabaseNewsletterField($databaseName, $fieldName)
115
  {
138
  /**
139
  * Create collection inside given database.
140
  *
141
+ * @param string $databaseName
142
+ * @param string $collectionName
143
  * @param string $collectionType
144
+ * @throws Copernica_MarketingSoftware_Exception
145
  */
146
  public function createCollection($databaseName, $collectionName, $collectionType)
147
  {
148
+ $this->_restRequest()->post('database/'.urlencode($databaseName).'/collections', array ( 'name' => $collectionName ));
149
 
150
  $requiredFields = $this->_requiredCollectionFields($collectionType);
151
 
157
  /**
158
  * This method created collection field.
159
  *
160
+ * @param string $databaseName
161
  * @param string $collectionName
162
  * @param string $collectionType
163
  * @param string $copernicaName
172
 
173
  $collectionId = $this->_getCollectionIdFromDatabase($databaseName, $collectionName);
174
 
175
+ $this->_restRequest()->post(
176
+ 'collection/'.$collectionId.'/fields', array_merge(
177
+ $fieldDefinition, array(
178
+ 'name' => $copernicaName
179
+ )
180
+ )
181
+ );
182
  }
183
 
184
  /**
195
 
196
  if (isset($output['error'])) {
197
  if (strpos($output['error']['message'], 'No database') !== false) {
198
+ throw Mage::exception('Copernica_MarketingSoftware', 'No database', Copernica_MarketingSoftware_Exception::DATABASE_NOT_EXISTS);
199
  } else {
200
+ throw Mage::exception('Copernica_MarketingSoftware', $output['message'], Copernica_MarketingSoftware_Exception::API_REQUEST_ERROR);
201
  }
202
  } else if (!is_array($output['data'])) {
203
+ throw Mage::exception('Copernica_MarketingSoftware', 'Unknown error', Copernica_MarketingSoftware_Exception::API_REQUEST_ERROR);
204
  }
205
 
206
  $collectionId = false;
207
 
208
  foreach ($output['data'] as $collection) {
209
  if ($collection['name'] == $collectionName) {
210
+ $collectionId = $collection['ID'];
211
  }
212
  }
213
 
214
  if ($collectionId === false) {
215
+ throw Mage::exception('Copernica_MarketingSoftware', 'Collection does not exists', Copernica_MarketingSoftware_Exception::COLLECTION_NOT_EXISTS);
216
  }
217
 
218
  return $collectionId;
228
  {
229
  switch ($collectionType) {
230
  case 'cartproducts':
231
+ return Mage::helper('marketingsoftware')->requiredQuoteItemFields();
232
+
233
  case 'orders' :
234
+ return Mage::helper('marketingsoftware')->requiredOrderFields();
235
+
236
  case 'orderproducts':
237
+ return Mage::helper('marketingsoftware')->requiredOrderItemFields();
238
+
239
  case 'addresses':
240
+ return Mage::helper('marketingsoftware')->requiredAddressFields();
241
+
242
  case 'viewedproducts':
243
+ return Mage::helper('marketingsoftware')->requiredViewedProductFields();
244
+
245
  case 'wishlistproducts':
246
+ return Mage::helper('marketingsoftware')->requiredWishlistItemFields();
247
  }
248
  }
249
  }
app/code/community/Copernica/MarketingSoftware/Helper/Api/Validator.php CHANGED
@@ -34,25 +34,25 @@ class Copernica_MarketingSoftware_Helper_Api_Validator extends Copernica_Marketi
34
  * Validate database. When something is wrong this method will throw
35
  * custom exception to report that.
36
  *
37
- * @param string $databaseName
38
  * @throws Copernica_MarketingSoftware_Exception
39
  */
40
  public function validateDatabase($databaseName)
41
  {
42
- $output = $this->_restRequest()->get( 'database/'.urlencode($databaseName) );
43
 
44
  if (isset($output['error']) || !isset($output['name'])) {
45
  if (strpos($output['error']['message'], 'No database') !== false) {
46
  throw Mage::exception('Copernica_MarketingSoftware', 'Database does not exists', Copernica_MarketingSoftware_Exception::DATABASE_NOT_EXISTS);
47
  } else {
48
- throw Mage::exception('Copernica_MarketingSoftware', 'Database could not be checked', Copernica_MarketingSoftware_Exception::API_REQUEST_ERROR);
49
  }
50
  }
51
 
52
  foreach ($output['fields']['data'] as $field) {
53
- if ($field['name'] == 'customer_id') {
54
- return;
55
- }
56
  }
57
 
58
  throw Mage::exception('Copernica_MarketingSoftware', 'Database does not have required customer_id field', Copernica_MarketingSoftware_Exception::DATABASE_STRUCT_INVALID);
@@ -61,15 +61,15 @@ class Copernica_MarketingSoftware_Helper_Api_Validator extends Copernica_Marketi
61
  /**
62
  * Validate database field.
63
  *
64
- * @param string $databaseName
65
- * @param string $fieldName
66
- * @param string $magentoField
67
  * @throws Copernica_MarketingSoftware_Exception
68
  */
69
  public function validateDatabaseField($databaseName, $fieldName, $magentoField)
70
  {
71
  if (trim($fieldName) == '') {
72
- throw Mage::exception('Copernica_MarketingSoftware', 'Field not linked', Copernica_MarketingSoftware_Exception::FIELD_NOT_LINKED);
73
  }
74
 
75
  $output = $this->_restRequest()->get('database/'.urlencode($databaseName).'/fields');
@@ -84,11 +84,11 @@ class Copernica_MarketingSoftware_Helper_Api_Validator extends Copernica_Marketi
84
 
85
  foreach ($output['data'] as $field) {
86
  if ($field['name'] != $fieldName) {
87
- continue;
88
  }
89
 
90
  if (!$this->_checkDatabaseFieldType($magentoField, $field, $databaseName)) {
91
- throw Mage::exception('Copernica_MarketingSoftware', 'Field is invalid', Copernica_MarketingSoftware_Exception::FIELD_STRUCT_INVALID);
92
  }
93
 
94
  return;
@@ -100,7 +100,7 @@ class Copernica_MarketingSoftware_Helper_Api_Validator extends Copernica_Marketi
100
  /**
101
  * Validate collection.
102
  *
103
- * @param string $databaseName
104
  * @param string $collectionName
105
  * @param string $collectionType
106
  * @throws Copenica_MarketingSoftware_Exception
@@ -118,16 +118,16 @@ class Copernica_MarketingSoftware_Helper_Api_Validator extends Copernica_Marketi
118
  }
119
 
120
  if ($output['total'] == 0) {
121
- throw Mage::exception('Copernica_MarketingSoftware', 'Collection does not exists', Copernica_MarketingSoftware_Exception::COLLECTION_NOT_EXISTS);
122
  }
123
 
124
  foreach ($output['data'] as $collection) {
125
  if ($collection['name'] != $collectionName) {
126
- continue;
127
  }
128
 
129
  if ($this->_isCollectionFieldsValid($collection['fields'], $collectionType)) {
130
- return;
131
  }
132
 
133
  throw Mage::exception('Copernica_MarketingSoftware', 'Collection structure is invalid.', Copernica_MarketingSoftware_Exception::COLLECTION_STRUCT_INVALID);
@@ -139,8 +139,8 @@ class Copernica_MarketingSoftware_Helper_Api_Validator extends Copernica_Marketi
139
  /**
140
  * Check collection field structure.
141
  *
142
- * @param assoc $collectionFieldStruct
143
- * @param string $collectionType
144
  * @return bool
145
  */
146
  protected function _isCollectionFieldsValid($collectionFieldStruct, $collectionType)
@@ -154,7 +154,7 @@ class Copernica_MarketingSoftware_Helper_Api_Validator extends Copernica_Marketi
154
  }
155
 
156
  if (count(array_intersect($collectionFields, $requiredFields)) == count($requiredFields)) {
157
- return true;
158
  }
159
 
160
  return false;
@@ -163,7 +163,7 @@ class Copernica_MarketingSoftware_Helper_Api_Validator extends Copernica_Marketi
163
  /**
164
  * Validate collection field.
165
  *
166
- * @param string $databaseName
167
  * @param string $collectionName
168
  * @param string $collectionType
169
  * @param string $magentoFieldName
@@ -178,29 +178,29 @@ class Copernica_MarketingSoftware_Helper_Api_Validator extends Copernica_Marketi
178
 
179
  if (isset($output['error'])) {
180
  if (strpos($output['error']['message'], 'No database') !== false) {
181
- throw Mage::exception('Copernica_MarketingSoftware', 'Database does not exists', Copernica_MarketingSoftware_Exception::DATABASE_NOT_EXISTS);
182
  } else {
183
- throw Mage::exception('Copernica_MarketingSoftware', 'API error', Copernica_MarketingSoftware_Exception::API_REQUEST_ERROR);
184
  }
185
  }
186
 
187
  if ($output['total'] == 0) {
188
- throw Mage::exception('Copernica_MarketingSoftware', 'Collection does not exists', Copernica_MarketingSoftware_Exception::COLLECTION_NOT_EXISTS);
189
  }
190
 
191
  $collectionId = false;
192
 
193
  foreach ($output['data'] as $collection) {
194
  if ($collection['name'] == $collectionName) {
195
- $collectionId = $collection['ID'];
196
  }
197
  }
198
 
199
  if ($collectionId === false) {
200
- throw Mage::exception('Copernica_MarketingSoftware', 'Collection does not exits', Copernica_MarketingSoftware_Exception::COLLECTION_NOT_EXISTS);
201
  }
202
 
203
- $output = $this->_restRequest()->get( 'collection/'.$collectionId.'/fields' );
204
 
205
  if (isset($output['error']) || !isset($output['data'])) {
206
  throw Mage::exception('Copernica_MarketingSoftware', 'API error', Copernica_MarketingSoftware_Exception::API_REQUEST_ERROR);
@@ -212,7 +212,7 @@ class Copernica_MarketingSoftware_Helper_Api_Validator extends Copernica_Marketi
212
 
213
  foreach ($output['data'] as $field) {
214
  if ($field['name'] != $copernicaFieldName) {
215
- continue;
216
  }
217
 
218
  $fieldDefinition = Mage::helper('marketingsoftware/data')->getCollectionFieldDefinition($collectionType, $magentoFieldName);
@@ -230,7 +230,7 @@ class Copernica_MarketingSoftware_Helper_Api_Validator extends Copernica_Marketi
230
  /**
231
  * Get required fields for a collection of given type.
232
  *
233
- * @param string $collectionType
234
  * @return array
235
  */
236
  protected function _requiredCollectionFields($collectionType)
@@ -238,32 +238,32 @@ class Copernica_MarketingSoftware_Helper_Api_Validator extends Copernica_Marketi
238
  switch ($collectionType)
239
  {
240
  case 'cartproducts':
241
- return Mage::helper('marketingsoftware')->requiredQuoteItemFields();
242
-
243
  case 'orders' :
244
- return Mage::helper('marketingsoftware')->requiredOrderFields();
245
-
246
  case 'orderproducts':
247
- return Mage::helper('marketingsoftware')->requiredOrderItemFields();
248
-
249
  case 'addresses':
250
- return Mage::helper('marketingsoftware')->requiredAddressFields();
251
-
252
  case 'viewedproduct':
253
- return Mage::helper('marketingsoftware')->requiredViewedProductFields();
254
 
255
  case 'wishlistproducts':
256
- return Mage::helper('marketingsoftware')->requiredWishlistItemFields();
257
-
258
  default:
259
- return array();
260
  }
261
  }
262
 
263
  /**
264
  * Check database field if copernica type match magento type.
265
  *
266
- * @param string $magentoField
267
  * @param assoc $copernicaStructure
268
  * @param string $databaseName
269
  * @return boolean
@@ -272,19 +272,19 @@ class Copernica_MarketingSoftware_Helper_Api_Validator extends Copernica_Marketi
272
  {
273
  switch ($magentoField) {
274
  case 'email' :
275
- return $this->_checkEmailField($copernicaStructure);
276
-
277
  case 'newsletter':
278
- return $this->_checkNewsletterField($copernicaStructure, $databaseName);
279
-
280
  case 'birthdate':
281
- return $this->_checkDateField($copernicaStructure);
282
-
283
  case 'registrationDate':
284
- return $this->_checkDatetimeField($copernicaStructure);
285
-
286
  default:
287
- return $this->_checkDefaultField($copernicaStructure);
288
  }
289
  }
290
 
@@ -298,38 +298,38 @@ class Copernica_MarketingSoftware_Helper_Api_Validator extends Copernica_Marketi
298
  $databaseUnsubscribe = $this->_restRequest()->get('database/'.urlencode($databaseName).'/unsubscribe');
299
 
300
  if (isset($databaseUnsubscribe['error'])) {
301
- throw Mage::exception('Copernica_MarketingSoftware', 'Field could not be checked', Copernica_MarketingSoftware_Exception::API_REQUEST_ERROR);
302
  }
303
 
304
  if ($databaseUnsubscribe['behavior'] != 'update') {
305
- return false;
306
  }
307
 
308
  $fieldName = $copernicaStructure['name'];
309
 
310
  if (!array_key_exists($fieldName, $databaseUnsubscribe['fields'])) {
311
- return false;
312
  }
313
 
314
  if ($databaseUnsubscribe['fields'][$fieldName] != 'unsubscribed_copernica') {
315
- return false;
316
  }
317
 
318
  $databaseCallbacks = $this->_restRequest()->get('database/'.urlencode($databaseName).'/callbacks');
319
 
320
  if (isset($databaseCallbacks['error'])) {
321
- throw Mage::exception('Copernica_MarketingSoftware', 'Field could not be checked', Copernica_MarketingSoftware_Exception::API_REQUEST_ERROR);
322
  }
323
 
324
  $callbackUrl = Mage::helper('marketingsoftware')->unsubscribeCallbackUrl();
325
 
326
  if ($databaseCallbacks['total'] == 0) {
327
- return false;
328
  }
329
 
330
  foreach ($databaseCallbacks['data'] as $callback) {
331
  if ($callback['url'] == $callbackUrl && $callback['method'] == 'json' && $callback['expression'] == "profile.$fieldName == 'unsubscribed_copernica';") {
332
- return true;
333
  }
334
  }
335
 
@@ -339,7 +339,7 @@ class Copernica_MarketingSoftware_Helper_Api_Validator extends Copernica_Marketi
339
  /**
340
  * Check field if it's a email field.
341
  *
342
- * @param assoc $copernicaStructure
343
  * @return boolean
344
  */
345
  protected function _checkEmailField($copernicaStructure)
@@ -350,7 +350,7 @@ class Copernica_MarketingSoftware_Helper_Api_Validator extends Copernica_Marketi
350
  /**
351
  * Check field if it's a date field.
352
  *
353
- * @param assoc $copernicaStructure
354
  * @return boolean
355
  */
356
  protected function _checkDateField($copernicaStructure)
@@ -361,7 +361,7 @@ class Copernica_MarketingSoftware_Helper_Api_Validator extends Copernica_Marketi
361
  /**
362
  * Check field if it's a datetime field
363
  *
364
- * @param assoc $copernicaStructure
365
  * @return boolean
366
  */
367
  protected function _checkDatetimeField($copernicaStructure)
@@ -372,7 +372,7 @@ class Copernica_MarketingSoftware_Helper_Api_Validator extends Copernica_Marketi
372
  /**
373
  * Check field if it's a default field.
374
  *
375
- * @param assoc $copernicaStructure
376
  * @return boolean
377
  */
378
  protected function _checkDefaultField($copernicaStructure)
34
  * Validate database. When something is wrong this method will throw
35
  * custom exception to report that.
36
  *
37
+ * @param string $databaseName
38
  * @throws Copernica_MarketingSoftware_Exception
39
  */
40
  public function validateDatabase($databaseName)
41
  {
42
+ $output = $this->_restRequest()->get('database/'.urlencode($databaseName));
43
 
44
  if (isset($output['error']) || !isset($output['name'])) {
45
  if (strpos($output['error']['message'], 'No database') !== false) {
46
  throw Mage::exception('Copernica_MarketingSoftware', 'Database does not exists', Copernica_MarketingSoftware_Exception::DATABASE_NOT_EXISTS);
47
  } else {
48
+ throw Mage::exception('Copernica_MarketingSoftware', 'Database could not be checked', Copernica_MarketingSoftware_Exception::API_REQUEST_ERROR);
49
  }
50
  }
51
 
52
  foreach ($output['fields']['data'] as $field) {
53
+ if ($field['name'] == 'customer_id') {
54
+ return;
55
+ }
56
  }
57
 
58
  throw Mage::exception('Copernica_MarketingSoftware', 'Database does not have required customer_id field', Copernica_MarketingSoftware_Exception::DATABASE_STRUCT_INVALID);
61
  /**
62
  * Validate database field.
63
  *
64
+ * @param string $databaseName
65
+ * @param string $fieldName
66
+ * @param string $magentoField
67
  * @throws Copernica_MarketingSoftware_Exception
68
  */
69
  public function validateDatabaseField($databaseName, $fieldName, $magentoField)
70
  {
71
  if (trim($fieldName) == '') {
72
+ throw Mage::exception('Copernica_MarketingSoftware', 'Field not linked', Copernica_MarketingSoftware_Exception::FIELD_NOT_LINKED);
73
  }
74
 
75
  $output = $this->_restRequest()->get('database/'.urlencode($databaseName).'/fields');
84
 
85
  foreach ($output['data'] as $field) {
86
  if ($field['name'] != $fieldName) {
87
+ continue;
88
  }
89
 
90
  if (!$this->_checkDatabaseFieldType($magentoField, $field, $databaseName)) {
91
+ throw Mage::exception('Copernica_MarketingSoftware', 'Field is invalid', Copernica_MarketingSoftware_Exception::FIELD_STRUCT_INVALID);
92
  }
93
 
94
  return;
100
  /**
101
  * Validate collection.
102
  *
103
+ * @param string $databaseName
104
  * @param string $collectionName
105
  * @param string $collectionType
106
  * @throws Copenica_MarketingSoftware_Exception
118
  }
119
 
120
  if ($output['total'] == 0) {
121
+ throw Mage::exception('Copernica_MarketingSoftware', 'Collection does not exists', Copernica_MarketingSoftware_Exception::COLLECTION_NOT_EXISTS);
122
  }
123
 
124
  foreach ($output['data'] as $collection) {
125
  if ($collection['name'] != $collectionName) {
126
+ continue;
127
  }
128
 
129
  if ($this->_isCollectionFieldsValid($collection['fields'], $collectionType)) {
130
+ return;
131
  }
132
 
133
  throw Mage::exception('Copernica_MarketingSoftware', 'Collection structure is invalid.', Copernica_MarketingSoftware_Exception::COLLECTION_STRUCT_INVALID);
139
  /**
140
  * Check collection field structure.
141
  *
142
+ * @param assoc $collectionFieldStruct
143
+ * @param string $collectionType
144
  * @return bool
145
  */
146
  protected function _isCollectionFieldsValid($collectionFieldStruct, $collectionType)
154
  }
155
 
156
  if (count(array_intersect($collectionFields, $requiredFields)) == count($requiredFields)) {
157
+ return true;
158
  }
159
 
160
  return false;
163
  /**
164
  * Validate collection field.
165
  *
166
+ * @param string $databaseName
167
  * @param string $collectionName
168
  * @param string $collectionType
169
  * @param string $magentoFieldName
178
 
179
  if (isset($output['error'])) {
180
  if (strpos($output['error']['message'], 'No database') !== false) {
181
+ throw Mage::exception('Copernica_MarketingSoftware', 'Database does not exists', Copernica_MarketingSoftware_Exception::DATABASE_NOT_EXISTS);
182
  } else {
183
+ throw Mage::exception('Copernica_MarketingSoftware', 'API error', Copernica_MarketingSoftware_Exception::API_REQUEST_ERROR);
184
  }
185
  }
186
 
187
  if ($output['total'] == 0) {
188
+ throw Mage::exception('Copernica_MarketingSoftware', 'Collection does not exists', Copernica_MarketingSoftware_Exception::COLLECTION_NOT_EXISTS);
189
  }
190
 
191
  $collectionId = false;
192
 
193
  foreach ($output['data'] as $collection) {
194
  if ($collection['name'] == $collectionName) {
195
+ $collectionId = $collection['ID'];
196
  }
197
  }
198
 
199
  if ($collectionId === false) {
200
+ throw Mage::exception('Copernica_MarketingSoftware', 'Collection does not exits', Copernica_MarketingSoftware_Exception::COLLECTION_NOT_EXISTS);
201
  }
202
 
203
+ $output = $this->_restRequest()->get('collection/'.$collectionId.'/fields');
204
 
205
  if (isset($output['error']) || !isset($output['data'])) {
206
  throw Mage::exception('Copernica_MarketingSoftware', 'API error', Copernica_MarketingSoftware_Exception::API_REQUEST_ERROR);
212
 
213
  foreach ($output['data'] as $field) {
214
  if ($field['name'] != $copernicaFieldName) {
215
+ continue;
216
  }
217
 
218
  $fieldDefinition = Mage::helper('marketingsoftware/data')->getCollectionFieldDefinition($collectionType, $magentoFieldName);
230
  /**
231
  * Get required fields for a collection of given type.
232
  *
233
+ * @param string $collectionType
234
  * @return array
235
  */
236
  protected function _requiredCollectionFields($collectionType)
238
  switch ($collectionType)
239
  {
240
  case 'cartproducts':
241
+ return Mage::helper('marketingsoftware')->requiredQuoteItemFields();
242
+
243
  case 'orders' :
244
+ return Mage::helper('marketingsoftware')->requiredOrderFields();
245
+
246
  case 'orderproducts':
247
+ return Mage::helper('marketingsoftware')->requiredOrderItemFields();
248
+
249
  case 'addresses':
250
+ return Mage::helper('marketingsoftware')->requiredAddressFields();
251
+
252
  case 'viewedproduct':
253
+ return Mage::helper('marketingsoftware')->requiredViewedProductFields();
254
 
255
  case 'wishlistproducts':
256
+ return Mage::helper('marketingsoftware')->requiredWishlistItemFields();
257
+
258
  default:
259
+ return array();
260
  }
261
  }
262
 
263
  /**
264
  * Check database field if copernica type match magento type.
265
  *
266
+ * @param string $magentoField
267
  * @param assoc $copernicaStructure
268
  * @param string $databaseName
269
  * @return boolean
272
  {
273
  switch ($magentoField) {
274
  case 'email' :
275
+ return $this->_checkEmailField($copernicaStructure);
276
+
277
  case 'newsletter':
278
+ return $this->_checkNewsletterField($copernicaStructure, $databaseName);
279
+
280
  case 'birthdate':
281
+ return $this->_checkDateField($copernicaStructure);
282
+
283
  case 'registrationDate':
284
+ return $this->_checkDatetimeField($copernicaStructure);
285
+
286
  default:
287
+ return $this->_checkDefaultField($copernicaStructure);
288
  }
289
  }
290
 
298
  $databaseUnsubscribe = $this->_restRequest()->get('database/'.urlencode($databaseName).'/unsubscribe');
299
 
300
  if (isset($databaseUnsubscribe['error'])) {
301
+ throw Mage::exception('Copernica_MarketingSoftware', 'Field could not be checked', Copernica_MarketingSoftware_Exception::API_REQUEST_ERROR);
302
  }
303
 
304
  if ($databaseUnsubscribe['behavior'] != 'update') {
305
+ return false;
306
  }
307
 
308
  $fieldName = $copernicaStructure['name'];
309
 
310
  if (!array_key_exists($fieldName, $databaseUnsubscribe['fields'])) {
311
+ return false;
312
  }
313
 
314
  if ($databaseUnsubscribe['fields'][$fieldName] != 'unsubscribed_copernica') {
315
+ return false;
316
  }
317
 
318
  $databaseCallbacks = $this->_restRequest()->get('database/'.urlencode($databaseName).'/callbacks');
319
 
320
  if (isset($databaseCallbacks['error'])) {
321
+ throw Mage::exception('Copernica_MarketingSoftware', 'Field could not be checked', Copernica_MarketingSoftware_Exception::API_REQUEST_ERROR);
322
  }
323
 
324
  $callbackUrl = Mage::helper('marketingsoftware')->unsubscribeCallbackUrl();
325
 
326
  if ($databaseCallbacks['total'] == 0) {
327
+ return false;
328
  }
329
 
330
  foreach ($databaseCallbacks['data'] as $callback) {
331
  if ($callback['url'] == $callbackUrl && $callback['method'] == 'json' && $callback['expression'] == "profile.$fieldName == 'unsubscribed_copernica';") {
332
+ return true;
333
  }
334
  }
335
 
339
  /**
340
  * Check field if it's a email field.
341
  *
342
+ * @param assoc $copernicaStructure
343
  * @return boolean
344
  */
345
  protected function _checkEmailField($copernicaStructure)
350
  /**
351
  * Check field if it's a date field.
352
  *
353
+ * @param assoc $copernicaStructure
354
  * @return boolean
355
  */
356
  protected function _checkDateField($copernicaStructure)
361
  /**
362
  * Check field if it's a datetime field
363
  *
364
+ * @param assoc $copernicaStructure
365
  * @return boolean
366
  */
367
  protected function _checkDatetimeField($copernicaStructure)
372
  /**
373
  * Check field if it's a default field.
374
  *
375
+ * @param assoc $copernicaStructure
376
  * @return boolean
377
  */
378
  protected function _checkDefaultField($copernicaStructure)
app/code/community/Copernica/MarketingSoftware/Helper/Config.php CHANGED
@@ -34,30 +34,30 @@ class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstrac
34
  /**
35
  * Define a prefix used for the config
36
  *
37
- * @name CONFIG_BASE
38
  */
39
  const CONFIG_BASE = 'marketingsoftware/';
40
 
41
  /**
42
  * Holds a list of previously requested key names
43
  *
44
- * @var array
45
  */
46
  protected static $_keyNameCache = array();
47
 
48
  /**
49
  * List of already requested or used config entries
50
  *
51
- * @var array
52
  */
53
  protected static $_configEntryCache = array();
54
 
55
  /**
56
  * Magic method to get configurations from the database
57
  *
58
- * @param string $method
59
- * @param array $params
60
- * @return string
61
  */
62
  public function __call($method, $params)
63
  {
@@ -70,7 +70,7 @@ class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstrac
70
 
71
  case 'set':
72
  if (!isset($params) || !isset($params[0])) {
73
- return false;
74
  }
75
 
76
  $key = $this->_toKeyName(substr($method, 3));
@@ -109,8 +109,8 @@ class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstrac
109
  /**
110
  * Tries to get config value from custom config table
111
  *
112
- * @param string $key
113
- * @return string
114
  */
115
  protected function _getCustomConfig($key)
116
  {
@@ -130,8 +130,8 @@ class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstrac
130
  /**
131
  * Sets a config entry in the custom config tab
132
  *
133
- * @param string $key
134
- * @param string $value
135
  */
136
  protected function _setCustomConfig($key, $value)
137
  {
@@ -157,8 +157,8 @@ class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstrac
157
  /**
158
  * Checks if an entry exists in the custom config table
159
  *
160
- * @param string $key
161
- * @return boolean
162
  */
163
  protected function _hasCustomConfig($key)
164
  {
@@ -168,8 +168,8 @@ class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstrac
168
  /**
169
  * Loads the requested model config object if possible
170
  *
171
- * @param string $key
172
- * @return Copernica_MarketingSoftware_Model_Config
173
  */
174
  protected function _getModel($key)
175
  {
@@ -188,8 +188,8 @@ class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstrac
188
  * Prepends uppercase characters with underscores and lowers
189
  * the whole string
190
  *
191
- * @param string $name
192
- * @return string
193
  */
194
  protected function _toKeyName($name)
195
  {
@@ -207,7 +207,7 @@ class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstrac
207
  * Get the config item from the custom config table, otherwise from
208
  * the basic magento component.
209
  *
210
- * @param string $name
211
  */
212
  protected function _getConfig($name)
213
  {
@@ -223,26 +223,28 @@ class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstrac
223
  /**
224
  * Set the config item from the basic magento component
225
  *
226
- * @param string $name
227
  * @param string $value
228
  */
229
  protected function _setConfig($name, $value)
230
  {
231
  if ($value === $this->_getConfig($name)) {
232
- return;
233
  }
234
 
235
  $this->_setCustomConfig($name, $value);
236
 
237
  // Some config items are not needed
238
- if (in_array($name, array(
 
239
  'customer_progress_status',
240
  'order_progress_status',
241
  'subscription_progress_status',
242
  'cronjob_starttime',
243
  'cronjob_endtime',
244
  'cronjob_processedtasks',
245
- ))) return;
 
246
 
247
  $this->setCustomerProgressStatus('0');
248
 
@@ -254,15 +256,15 @@ class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstrac
254
  /**
255
  * Check if store is enabled.
256
  *
257
- * @param int
258
- * @return bool
259
  */
260
  public function isEnabledStore($storeId)
261
  {
262
  $stores = @unserialize($this->_getConfig('enabled_stores'));
263
 
264
  if (!is_array($stores)) {
265
- return true;
266
  }
267
 
268
  return in_array($storeId, $stores);
@@ -271,8 +273,8 @@ class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstrac
271
  /**
272
  * Set stores. Pass null to disable store filtering.
273
  *
274
- * @param array|null
275
- * @return Copernica_MarketingSoftware_Helper_Config
276
  */
277
  public function setEnabledStores($collectionOfStoresId)
278
  {
@@ -284,7 +286,7 @@ class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstrac
284
  /**
285
  * Get list of enabled stores
286
  *
287
- * @return array|null
288
  */
289
  public function getEnabledStores()
290
  {
@@ -294,7 +296,7 @@ class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstrac
294
  /**
295
  * Get the hostname from the config
296
  *
297
- * @return string
298
  */
299
  public function getHostname()
300
  {
@@ -304,7 +306,7 @@ class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstrac
304
  /**
305
  * Set the hostname from the config
306
  *
307
- * @return Copernica_MarketingSoftware_Helper_Config
308
  */
309
  public function setHostname($value)
310
  {
@@ -316,7 +318,7 @@ class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstrac
316
  /**
317
  * Get the name of the database
318
  *
319
- * @return string
320
  */
321
  public function getDatabaseName()
322
  {
@@ -326,8 +328,8 @@ class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstrac
326
  /**
327
  * Set the name of the database
328
  *
329
- * @param string $value
330
- * @return Copernica_MarketingSoftware_Helper_Config
331
  */
332
  public function setDatabaseName($value)
333
  {
@@ -339,7 +341,7 @@ class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstrac
339
  /**
340
  * Get the linked customer fields
341
  *
342
- * @return array
343
  */
344
  public function getLinkedCustomerFields()
345
  {
@@ -347,7 +349,7 @@ class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstrac
347
  $value = empty($value) ? array() : json_decode($value, true);
348
 
349
  if (!isset($value['customer_email'])) {
350
- return $value;
351
  }
352
 
353
  $oldValues = $value;
@@ -368,8 +370,8 @@ class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstrac
368
  /**
369
  * Set the linked customer fields
370
  *
371
- * @param array $value
372
- * @return Copernica_MarketingSoftware_Helper_Config
373
  */
374
  public function setLinkedCustomerFields($value)
375
  {
@@ -381,37 +383,37 @@ class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstrac
381
  /**
382
  * Get the id of the quote item collection
383
  *
384
- * @return int
385
  */
386
  public function getQuoteItemCollectionId()
387
  {
388
- $id = $this->_getConfig('quote_item_collection_id');
389
 
390
- if ($id) {
391
- return $id;
392
- }
393
 
394
- $name = $this->getQuoteItemCollectionName();
395
 
396
- if (!$name) {
397
- return null;
398
- }
399
 
400
- $id = Mage::helper('marketingsoftware/api_abstract')->getCollectionId($name);
401
 
402
- if (!$id) {
403
- return null;
404
- }
405
 
406
- $this->_setConfig('quote_item_collection_id', $id);
407
 
408
- return $id;
409
  }
410
 
411
  /**
412
  * Get the name of the quote item collection
413
  *
414
- * @return string
415
  */
416
  public function getQuoteItemCollectionName()
417
  {
@@ -421,8 +423,8 @@ class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstrac
421
  /**
422
  * Set the name of the quote item collection
423
  *
424
- * @param string $value
425
- * @return Copernica_MarketingSoftware_Helper_Config
426
  */
427
  public function setQuoteItemCollectionName($value)
428
  {
@@ -434,24 +436,24 @@ class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstrac
434
  /**
435
  * Get the linked quote item fields
436
  *
437
- * @return array
438
  */
439
  public function getLinkedQuoteItemFields()
440
  {
441
  $value = $this->_getConfig('linked_quote_item_fields');
442
 
443
  if (empty($value)) {
444
- return array();
445
  } else {
446
- return json_decode($value, true);
447
  }
448
  }
449
 
450
  /**
451
  * Get the linked quote item fields
452
  *
453
- * @param array $value
454
- * @return Copernica_MarketingSoftware_Helper_Config
455
  */
456
  public function setLinkedQuoteItemFields($value)
457
  {
@@ -463,7 +465,7 @@ class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstrac
463
  /**
464
  * Get the name of the orders collection
465
  *
466
- * @return string
467
  */
468
  public function getOrdersCollectionName()
469
  {
@@ -473,26 +475,26 @@ class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstrac
473
  /**
474
  * Get the id of the orders collection
475
  *
476
- * @return int
477
  */
478
  public function getOrdersCollectionId()
479
  {
480
  $id = $this->_getConfig('orders_collection_id');
481
 
482
  if ($id) {
483
- return $id;
484
  }
485
 
486
  $name = $this->getOrdersCollectionName();
487
 
488
  if (!$name) {
489
- return null;
490
  }
491
 
492
  $id = Mage::helper('marketingsoftware/api_abstract')->getCollectionId($name);
493
 
494
  if (!$id) {
495
- return null;
496
  }
497
 
498
  $this->_setConfig('orders_collection_id', $id);
@@ -503,8 +505,8 @@ class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstrac
503
  /**
504
  * Set the name of the orders collection
505
  *
506
- * @param string $value
507
- * @return Copernica_MarketingSoftware_Helper_Config
508
  */
509
  public function setOrdersCollectionName($value)
510
  {
@@ -516,15 +518,15 @@ class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstrac
516
  /**
517
  * Get the linked order fields
518
  *
519
- * @return array
520
  */
521
  public function getLinkedOrderFields()
522
  {
523
  $value = $this->_getConfig('linked_order_fields');
524
  $value = empty($value) ? array() : json_decode($value, true);
525
 
526
- if (!isset($value['order_timestamp'])) {
527
- return $value;
528
  }
529
 
530
  $oldValues = $value;
@@ -545,8 +547,8 @@ class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstrac
545
  /**
546
  * Set the linked order fields
547
  *
548
- * @param array $value
549
- * @return Copernica_MarketingSoftware_Helper_Config
550
  */
551
  public function setLinkedOrderFields($value)
552
  {
@@ -558,7 +560,7 @@ class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstrac
558
  /**
559
  * Get the name of the collection were all the orders are stored
560
  *
561
- * @return string
562
  */
563
  public function getOrderItemCollectionName()
564
  {
@@ -568,26 +570,26 @@ class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstrac
568
  /**
569
  * Get the id of the order item collection
570
  *
571
- * @return int
572
  */
573
  public function getOrderItemCollectionId()
574
  {
575
  $id = $this->_getConfig('order_item_collection_id');
576
 
577
  if ($id) {
578
- return $id;
579
  }
580
 
581
  $name = $this->getOrderItemCollectionName();
582
 
583
  if (!$name) {
584
- return null;
585
  }
586
 
587
  $id = Mage::helper('marketingsoftware/api_abstract')->getCollectionId($name);
588
 
589
  if (!$id) {
590
- return null;
591
  }
592
 
593
  $this->_setConfig('order_item_collection_id', $id);
@@ -598,7 +600,7 @@ class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstrac
598
  /**
599
  * Get the name of the collection were all the orders are stored
600
  *
601
- * @param string
602
  */
603
  public function setOrderItemCollectionName($value)
604
  {
@@ -610,7 +612,7 @@ class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstrac
610
  /**
611
  * Get the linked order item fields
612
  *
613
- * @return array
614
  */
615
  public function getLinkedOrderItemFields()
616
  {
@@ -618,7 +620,7 @@ class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstrac
618
  $value = empty($value) ? array() : json_decode($value, true);
619
 
620
  if (!isset($value['product_internal_id'])) {
621
- return $value;
622
  }
623
 
624
  $oldValues = $value;
@@ -626,19 +628,19 @@ class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstrac
626
  $newValues = array();
627
 
628
  foreach ($oldValues as $key => $value) {
629
- switch($key) {
630
- case 'product_qty':
631
- $key = 'quantity';
632
- break;
633
-
634
- case 'product_base_row_total':
635
- $key = 'total_price';
636
- break;
637
-
638
- default:
639
- $key = str_replace('product_', '', $key);
640
- break;
641
- }
642
 
643
  $newValues[$key] = $value;
644
  }
@@ -651,8 +653,8 @@ class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstrac
651
  /**
652
  * Set the linked order item fields
653
  *
654
- * @param array $value
655
- * @return Copernica_MarketingSoftware_Helper_Config
656
  */
657
  public function setLinkedOrderItemFields($value)
658
  {
@@ -680,19 +682,19 @@ class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstrac
680
  $id = $this->_getConfig('address_collection_id');
681
 
682
  if ($id) {
683
- return $id;
684
  }
685
 
686
  $name = $this->getAddressesCollectionName();
687
 
688
  if (!$name) {
689
- return null;
690
  }
691
 
692
  $id = Mage::helper('marketingsoftware/api_abstract')->getCollectionId($name);
693
 
694
  if (!$id) {
695
- return null;
696
  }
697
 
698
  $this->_setConfig('address_collection_id', $id);
@@ -713,7 +715,7 @@ class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstrac
713
  /**
714
  * Get the linked address fields
715
  *
716
- * @return array
717
  */
718
  public function getLinkedAddressFields()
719
  {
@@ -721,7 +723,7 @@ class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstrac
721
  $value = empty($value) ? array() : json_decode($value, true);
722
 
723
  if (!isset($value['address_firstname'])) {
724
- return $value;
725
  }
726
 
727
  $oldValues = $value;
@@ -742,8 +744,8 @@ class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstrac
742
  /**
743
  * set the linked address fields
744
  *
745
- * @param array $value
746
- * @return Copernica_MarketingSoftware_Helper_Config
747
  */
748
  public function setLinkedAddressFields($value)
749
  {
@@ -755,7 +757,7 @@ class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstrac
755
  /**
756
  * Get the name of the viewed products collection
757
  *
758
- * @return string
759
  */
760
  public function getViewedProductCollectionName()
761
  {
@@ -765,26 +767,26 @@ class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstrac
765
  /**
766
  * Get the id of the address collection
767
  *
768
- * @return int
769
  */
770
  public function getViewedProductCollectionId()
771
  {
772
  $id = $this->_getConfig('viewed_product_collection_id');
773
 
774
  if ($id) {
775
- return $id;
776
  }
777
 
778
  $name = $this->getViewedProductCollectionName();
779
 
780
  if (!$name) {
781
- return null;
782
  }
783
 
784
  $id = Mage::helper('marketingsoftware/api_abstract')->getCollectionId($name);
785
 
786
  if (!$id) {
787
- return null;
788
  }
789
 
790
  $this->_setConfig('viewed_product_collection_id', $id);
@@ -795,7 +797,7 @@ class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstrac
795
  /**
796
  * Set the name of the viewed products collection
797
  *
798
- * @param string $value
799
  * @return Copernica_MarketingSoftware_Helper_Config
800
  */
801
  public function setViewedProductCollectionName($value)
@@ -815,17 +817,17 @@ class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstrac
815
  $value = $this->_getConfig('linked_viewed_product_fields');
816
 
817
  if (empty($value)) {
818
- return array();
819
  } else {
820
- return json_decode($value, true);
821
  }
822
  }
823
 
824
  /**
825
  * Get the linked customer fields
826
  *
827
- * @param array $value
828
- * @return Copernica_MarketingSoftware_Helper_Config
829
  */
830
  public function setLinkedViewedProductFields($value)
831
  {
@@ -837,54 +839,54 @@ class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstrac
837
  /**
838
  * Get the name of the wishlist item collection
839
  *
840
- * @return string
841
  */
842
  public function getWishlistItemCollectionName()
843
  {
844
- return $this->_getConfig('wishlist_item_collection_name');
845
  }
846
 
847
  /**
848
  * Get the id of the wishlist item collection
849
  *
850
- * @return int
851
  */
852
  public function getWishlistItemCollectionId()
853
  {
854
- $id = $this->_getConfig('wishlist_item_collection_id');
855
 
856
- if ($id) {
857
- return $id;
858
- }
859
 
860
- $name = $this->getWishlistItemCollectionName();
861
 
862
- if (!$name) {
863
- return null;
864
- }
865
 
866
- $id = Mage::helper('marketingsoftware/api_abstract')->getCollectionId($name);
867
 
868
- if (!$id) {
869
- return null;
870
- }
871
 
872
- $this->_setConfig('wishlist_item_collection_id', $id);
873
 
874
- return $id;
875
  }
876
 
877
  /**
878
  * Set the name of the wishlist item collection
879
  *
880
- * @param string $value
881
  * @return Copernica_MarketingSoftware_Helper_Config
882
  */
883
  public function setWishlistItemCollectionName($value)
884
  {
885
- $this->_setConfig('wishlist_item_collection_name', $value);
886
 
887
- return $this;
888
  }
889
 
890
  /**
@@ -894,26 +896,26 @@ class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstrac
894
  */
895
  public function getLinkedWishlistItemFields()
896
  {
897
- $value = $this->_getConfig('linked_wishlist_item_fields');
898
 
899
- if (empty($value)) {
900
- return array();
901
- } else {
902
- return json_decode($value, true);
903
- }
904
  }
905
 
906
  /**
907
  * Set the linked wishlist item fields
908
  *
909
- * @param array $value
910
- * @return Copernica_MarketingSoftware_Helper_Config
911
  */
912
  public function setLinkedWishlistItemFields($value)
913
  {
914
- $this->_setConfig('linked_wishlist_item_fields', json_encode($value), true);
915
 
916
- return $this;
917
  }
918
 
919
  /**
@@ -921,7 +923,7 @@ class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstrac
921
  * This is the created timestamp of the most recent customer which has
922
  * been queued for synchronisation
923
  *
924
- * @return datetime
925
  */
926
  public function getCustomerProgressStatus()
927
  {
@@ -933,8 +935,8 @@ class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstrac
933
  * This is the created timestamp of the most recent customer which has
934
  * been queued for synchronisation
935
  *
936
- * @param datetime $value
937
- * @return Copernica_MarketingSoftware_Helper_Config
938
  */
939
  public function setCustomerProgressStatus($value)
940
  {
@@ -960,8 +962,8 @@ class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstrac
960
  * This is the created timestamp of the most recent order which has
961
  * been queued for synchronisation
962
  *
963
- * @param datetime $value
964
- * @return Copernica_MarketingSoftware_Helper_Config
965
  */
966
  public function setOrderProgressStatus($value)
967
  {
@@ -987,8 +989,8 @@ class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstrac
987
  * This is the created timestamp of the most recent subscription which has
988
  * been queued for synchronisation
989
  *
990
- * @param datetime $value
991
- * @return Copernica_MarketingSoftware_Helper_Config
992
  */
993
  public function setSubscriptionProgressStatus($value)
994
  {
@@ -1000,7 +1002,7 @@ class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstrac
1000
  /**
1001
  * Get the last start time of the cronjob.
1002
  *
1003
- * @return datetime
1004
  */
1005
  public function getLastStartTimeCronjob()
1006
  {
@@ -1010,8 +1012,8 @@ class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstrac
1010
  /**
1011
  * Set the last start time of the cronjob.
1012
  *
1013
- * @param datetime $value
1014
- * @return Copernica_MarketingSoftware_Helper_Config
1015
  */
1016
  public function setLastStartTimeCronjob($value)
1017
  {
@@ -1023,7 +1025,7 @@ class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstrac
1023
  /**
1024
  * Get the last end time of the cronjob.
1025
  *
1026
- * @return datetime
1027
  */
1028
  public function getLastEndTimeCronjob()
1029
  {
@@ -1033,8 +1035,8 @@ class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstrac
1033
  /**
1034
  * Set the last end time of the cronjob.
1035
  *
1036
- * @param datetime $value
1037
- * @return Copernica_MarketingSoftware_Helper_Config
1038
  */
1039
  public function setLastEndTimeCronjob($value)
1040
  {
@@ -1056,8 +1058,8 @@ class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstrac
1056
  /**
1057
  * Set the last end time of the cronjob.
1058
  *
1059
- * @param integer $value
1060
- * @return Copernica_MarketingSoftware_Helper_Config
1061
  */
1062
  public function setLastCronjobProcessedTasks($value)
1063
  {
@@ -1070,8 +1072,8 @@ class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstrac
1070
  * Should our extension use vanilla magento cron schedulers to execute
1071
  * queue? Or should we sync all data by processQueue.php file?
1072
  *
1073
- * @param boolean $vanilla
1074
- * @return Copernica_MarketingSoftware_Helper_Config
1075
  */
1076
  public function setVanillaCrons($vanilla)
1077
  {
@@ -1083,7 +1085,7 @@ class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstrac
1083
  /**
1084
  * Get stored config about vanilla crons schedulers.
1085
  *
1086
- * @return boolean
1087
  */
1088
  public function getVanillaCrons()
1089
  {
@@ -1105,8 +1107,8 @@ class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstrac
1105
  /**
1106
  * Set timestamp when we did check forgotten carts list
1107
  *
1108
- * @param string $time
1109
- * @return Copernica_MarketingSoftware_Helper_Config
1110
  */
1111
  public function setAbandonedLastCheck($time = null)
1112
  {
@@ -1119,7 +1121,7 @@ class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstrac
1119
  * Set number of minutes that have to pass from last quote item update to consider
1120
  * cart abandonded.
1121
  *
1122
- * @param int $timeout
1123
  * @return Copernica_MarketingSoftware_Helper_Config
1124
  */
1125
  public function setAbandonedTimeout($timeout)
@@ -1146,8 +1148,8 @@ class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstrac
1146
  * Carts older than supplied number of minutes will not be synchronized
1147
  * with Copernica.
1148
  *
1149
- * @param int $timeout
1150
- * @return Copernica_MarketingSoftware_Helper_Config
1151
  */
1152
  public function setAbandonedPeriod($timeout)
1153
  {
@@ -1172,8 +1174,8 @@ class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstrac
1172
  /**
1173
  * Should finished (removed or ordered) quote item be removed from profile?
1174
  *
1175
- * @param boolean $remove
1176
- * @return Copernica_MarketingSoftware_Helper_Config
1177
  */
1178
  public function setRemoveFinishedQuoteItem($remove)
1179
  {
@@ -1221,4 +1223,4 @@ class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstrac
1221
  $this->unsWishlistItemCollectionId();
1222
  $this->unsLinkedWishlistItemFields();
1223
  }
1224
- }
34
  /**
35
  * Define a prefix used for the config
36
  *
37
+ * @name CONFIG_BASE
38
  */
39
  const CONFIG_BASE = 'marketingsoftware/';
40
 
41
  /**
42
  * Holds a list of previously requested key names
43
  *
44
+ * @var array
45
  */
46
  protected static $_keyNameCache = array();
47
 
48
  /**
49
  * List of already requested or used config entries
50
  *
51
+ * @var array
52
  */
53
  protected static $_configEntryCache = array();
54
 
55
  /**
56
  * Magic method to get configurations from the database
57
  *
58
+ * @param string $method
59
+ * @param array $params
60
+ * @return string
61
  */
62
  public function __call($method, $params)
63
  {
70
 
71
  case 'set':
72
  if (!isset($params) || !isset($params[0])) {
73
+ return false;
74
  }
75
 
76
  $key = $this->_toKeyName(substr($method, 3));
109
  /**
110
  * Tries to get config value from custom config table
111
  *
112
+ * @param string $key
113
+ * @return string
114
  */
115
  protected function _getCustomConfig($key)
116
  {
130
  /**
131
  * Sets a config entry in the custom config tab
132
  *
133
+ * @param string $key
134
+ * @param string $value
135
  */
136
  protected function _setCustomConfig($key, $value)
137
  {
157
  /**
158
  * Checks if an entry exists in the custom config table
159
  *
160
+ * @param string $key
161
+ * @return boolean
162
  */
163
  protected function _hasCustomConfig($key)
164
  {
168
  /**
169
  * Loads the requested model config object if possible
170
  *
171
+ * @param string $key
172
+ * @return Copernica_MarketingSoftware_Model_Config
173
  */
174
  protected function _getModel($key)
175
  {
188
  * Prepends uppercase characters with underscores and lowers
189
  * the whole string
190
  *
191
+ * @param string $name
192
+ * @return string
193
  */
194
  protected function _toKeyName($name)
195
  {
207
  * Get the config item from the custom config table, otherwise from
208
  * the basic magento component.
209
  *
210
+ * @param string $name
211
  */
212
  protected function _getConfig($name)
213
  {
223
  /**
224
  * Set the config item from the basic magento component
225
  *
226
+ * @param string $name
227
  * @param string $value
228
  */
229
  protected function _setConfig($name, $value)
230
  {
231
  if ($value === $this->_getConfig($name)) {
232
+ return;
233
  }
234
 
235
  $this->_setCustomConfig($name, $value);
236
 
237
  // Some config items are not needed
238
+ if (in_array(
239
+ $name, array(
240
  'customer_progress_status',
241
  'order_progress_status',
242
  'subscription_progress_status',
243
  'cronjob_starttime',
244
  'cronjob_endtime',
245
  'cronjob_processedtasks',
246
+ )
247
+ )) return;
248
 
249
  $this->setCustomerProgressStatus('0');
250
 
256
  /**
257
  * Check if store is enabled.
258
  *
259
+ * @param int
260
+ * @return bool
261
  */
262
  public function isEnabledStore($storeId)
263
  {
264
  $stores = @unserialize($this->_getConfig('enabled_stores'));
265
 
266
  if (!is_array($stores)) {
267
+ return true;
268
  }
269
 
270
  return in_array($storeId, $stores);
273
  /**
274
  * Set stores. Pass null to disable store filtering.
275
  *
276
+ * @param array|null
277
+ * @return Copernica_MarketingSoftware_Helper_Config
278
  */
279
  public function setEnabledStores($collectionOfStoresId)
280
  {
286
  /**
287
  * Get list of enabled stores
288
  *
289
+ * @return array|null
290
  */
291
  public function getEnabledStores()
292
  {
296
  /**
297
  * Get the hostname from the config
298
  *
299
+ * @return string
300
  */
301
  public function getHostname()
302
  {
306
  /**
307
  * Set the hostname from the config
308
  *
309
+ * @return Copernica_MarketingSoftware_Helper_Config
310
  */
311
  public function setHostname($value)
312
  {
318
  /**
319
  * Get the name of the database
320
  *
321
+ * @return string
322
  */
323
  public function getDatabaseName()
324
  {
328
  /**
329
  * Set the name of the database
330
  *
331
+ * @param string $value
332
+ * @return Copernica_MarketingSoftware_Helper_Config
333
  */
334
  public function setDatabaseName($value)
335
  {
341
  /**
342
  * Get the linked customer fields
343
  *
344
+ * @return array
345
  */
346
  public function getLinkedCustomerFields()
347
  {
349
  $value = empty($value) ? array() : json_decode($value, true);
350
 
351
  if (!isset($value['customer_email'])) {
352
+ return $value;
353
  }
354
 
355
  $oldValues = $value;
370
  /**
371
  * Set the linked customer fields
372
  *
373
+ * @param array $value
374
+ * @return Copernica_MarketingSoftware_Helper_Config
375
  */
376
  public function setLinkedCustomerFields($value)
377
  {
383
  /**
384
  * Get the id of the quote item collection
385
  *
386
+ * @return int
387
  */
388
  public function getQuoteItemCollectionId()
389
  {
390
+ $id = $this->_getConfig('quote_item_collection_id');
391
 
392
+ if ($id) {
393
+ return $id;
394
+ }
395
 
396
+ $name = $this->getQuoteItemCollectionName();
397
 
398
+ if (!$name) {
399
+ return null;
400
+ }
401
 
402
+ $id = Mage::helper('marketingsoftware/api_abstract')->getCollectionId($name);
403
 
404
+ if (!$id) {
405
+ return null;
406
+ }
407
 
408
+ $this->_setConfig('quote_item_collection_id', $id);
409
 
410
+ return $id;
411
  }
412
 
413
  /**
414
  * Get the name of the quote item collection
415
  *
416
+ * @return string
417
  */
418
  public function getQuoteItemCollectionName()
419
  {
423
  /**
424
  * Set the name of the quote item collection
425
  *
426
+ * @param string $value
427
+ * @return Copernica_MarketingSoftware_Helper_Config
428
  */
429
  public function setQuoteItemCollectionName($value)
430
  {
436
  /**
437
  * Get the linked quote item fields
438
  *
439
+ * @return array
440
  */
441
  public function getLinkedQuoteItemFields()
442
  {
443
  $value = $this->_getConfig('linked_quote_item_fields');
444
 
445
  if (empty($value)) {
446
+ return array();
447
  } else {
448
+ return json_decode($value, true);
449
  }
450
  }
451
 
452
  /**
453
  * Get the linked quote item fields
454
  *
455
+ * @param array $value
456
+ * @return Copernica_MarketingSoftware_Helper_Config
457
  */
458
  public function setLinkedQuoteItemFields($value)
459
  {
465
  /**
466
  * Get the name of the orders collection
467
  *
468
+ * @return string
469
  */
470
  public function getOrdersCollectionName()
471
  {
475
  /**
476
  * Get the id of the orders collection
477
  *
478
+ * @return int
479
  */
480
  public function getOrdersCollectionId()
481
  {
482
  $id = $this->_getConfig('orders_collection_id');
483
 
484
  if ($id) {
485
+ return $id;
486
  }
487
 
488
  $name = $this->getOrdersCollectionName();
489
 
490
  if (!$name) {
491
+ return null;
492
  }
493
 
494
  $id = Mage::helper('marketingsoftware/api_abstract')->getCollectionId($name);
495
 
496
  if (!$id) {
497
+ return null;
498
  }
499
 
500
  $this->_setConfig('orders_collection_id', $id);
505
  /**
506
  * Set the name of the orders collection
507
  *
508
+ * @param string $value
509
+ * @return Copernica_MarketingSoftware_Helper_Config
510
  */
511
  public function setOrdersCollectionName($value)
512
  {
518
  /**
519
  * Get the linked order fields
520
  *
521
+ * @return array
522
  */
523
  public function getLinkedOrderFields()
524
  {
525
  $value = $this->_getConfig('linked_order_fields');
526
  $value = empty($value) ? array() : json_decode($value, true);
527
 
528
+ if (!isset($value['order_timestamp'])) {
529
+ return $value;
530
  }
531
 
532
  $oldValues = $value;
547
  /**
548
  * Set the linked order fields
549
  *
550
+ * @param array $value
551
+ * @return Copernica_MarketingSoftware_Helper_Config
552
  */
553
  public function setLinkedOrderFields($value)
554
  {
560
  /**
561
  * Get the name of the collection were all the orders are stored
562
  *
563
+ * @return string
564
  */
565
  public function getOrderItemCollectionName()
566
  {
570
  /**
571
  * Get the id of the order item collection
572
  *
573
+ * @return int
574
  */
575
  public function getOrderItemCollectionId()
576
  {
577
  $id = $this->_getConfig('order_item_collection_id');
578
 
579
  if ($id) {
580
+ return $id;
581
  }
582
 
583
  $name = $this->getOrderItemCollectionName();
584
 
585
  if (!$name) {
586
+ return null;
587
  }
588
 
589
  $id = Mage::helper('marketingsoftware/api_abstract')->getCollectionId($name);
590
 
591
  if (!$id) {
592
+ return null;
593
  }
594
 
595
  $this->_setConfig('order_item_collection_id', $id);
600
  /**
601
  * Get the name of the collection were all the orders are stored
602
  *
603
+ * @param string
604
  */
605
  public function setOrderItemCollectionName($value)
606
  {
612
  /**
613
  * Get the linked order item fields
614
  *
615
+ * @return array
616
  */
617
  public function getLinkedOrderItemFields()
618
  {
620
  $value = empty($value) ? array() : json_decode($value, true);
621
 
622
  if (!isset($value['product_internal_id'])) {
623
+ return $value;
624
  }
625
 
626
  $oldValues = $value;
628
  $newValues = array();
629
 
630
  foreach ($oldValues as $key => $value) {
631
+ switch($key) {
632
+ case 'product_qty':
633
+ $key = 'quantity';
634
+ break;
635
+
636
+ case 'product_base_row_total':
637
+ $key = 'total_price';
638
+ break;
639
+
640
+ default:
641
+ $key = str_replace('product_', '', $key);
642
+ break;
643
+ }
644
 
645
  $newValues[$key] = $value;
646
  }
653
  /**
654
  * Set the linked order item fields
655
  *
656
+ * @param array $value
657
+ * @return Copernica_MarketingSoftware_Helper_Config
658
  */
659
  public function setLinkedOrderItemFields($value)
660
  {
682
  $id = $this->_getConfig('address_collection_id');
683
 
684
  if ($id) {
685
+ return $id;
686
  }
687
 
688
  $name = $this->getAddressesCollectionName();
689
 
690
  if (!$name) {
691
+ return null;
692
  }
693
 
694
  $id = Mage::helper('marketingsoftware/api_abstract')->getCollectionId($name);
695
 
696
  if (!$id) {
697
+ return null;
698
  }
699
 
700
  $this->_setConfig('address_collection_id', $id);
715
  /**
716
  * Get the linked address fields
717
  *
718
+ * @return array
719
  */
720
  public function getLinkedAddressFields()
721
  {
723
  $value = empty($value) ? array() : json_decode($value, true);
724
 
725
  if (!isset($value['address_firstname'])) {
726
+ return $value;
727
  }
728
 
729
  $oldValues = $value;
744
  /**
745
  * set the linked address fields
746
  *
747
+ * @param array $value
748
+ * @return Copernica_MarketingSoftware_Helper_Config
749
  */
750
  public function setLinkedAddressFields($value)
751
  {
757
  /**
758
  * Get the name of the viewed products collection
759
  *
760
+ * @return string
761
  */
762
  public function getViewedProductCollectionName()
763
  {
767
  /**
768
  * Get the id of the address collection
769
  *
770
+ * @return int
771
  */
772
  public function getViewedProductCollectionId()
773
  {
774
  $id = $this->_getConfig('viewed_product_collection_id');
775
 
776
  if ($id) {
777
+ return $id;
778
  }
779
 
780
  $name = $this->getViewedProductCollectionName();
781
 
782
  if (!$name) {
783
+ return null;
784
  }
785
 
786
  $id = Mage::helper('marketingsoftware/api_abstract')->getCollectionId($name);
787
 
788
  if (!$id) {
789
+ return null;
790
  }
791
 
792
  $this->_setConfig('viewed_product_collection_id', $id);
797
  /**
798
  * Set the name of the viewed products collection
799
  *
800
+ * @param string $value
801
  * @return Copernica_MarketingSoftware_Helper_Config
802
  */
803
  public function setViewedProductCollectionName($value)
817
  $value = $this->_getConfig('linked_viewed_product_fields');
818
 
819
  if (empty($value)) {
820
+ return array();
821
  } else {
822
+ return json_decode($value, true);
823
  }
824
  }
825
 
826
  /**
827
  * Get the linked customer fields
828
  *
829
+ * @param array $value
830
+ * @return Copernica_MarketingSoftware_Helper_Config
831
  */
832
  public function setLinkedViewedProductFields($value)
833
  {
839
  /**
840
  * Get the name of the wishlist item collection
841
  *
842
+ * @return string
843
  */
844
  public function getWishlistItemCollectionName()
845
  {
846
+ return $this->_getConfig('wishlist_item_collection_name');
847
  }
848
 
849
  /**
850
  * Get the id of the wishlist item collection
851
  *
852
+ * @return int
853
  */
854
  public function getWishlistItemCollectionId()
855
  {
856
+ $id = $this->_getConfig('wishlist_item_collection_id');
857
 
858
+ if ($id) {
859
+ return $id;
860
+ }
861
 
862
+ $name = $this->getWishlistItemCollectionName();
863
 
864
+ if (!$name) {
865
+ return null;
866
+ }
867
 
868
+ $id = Mage::helper('marketingsoftware/api_abstract')->getCollectionId($name);
869
 
870
+ if (!$id) {
871
+ return null;
872
+ }
873
 
874
+ $this->_setConfig('wishlist_item_collection_id', $id);
875
 
876
+ return $id;
877
  }
878
 
879
  /**
880
  * Set the name of the wishlist item collection
881
  *
882
+ * @param string $value
883
  * @return Copernica_MarketingSoftware_Helper_Config
884
  */
885
  public function setWishlistItemCollectionName($value)
886
  {
887
+ $this->_setConfig('wishlist_item_collection_name', $value);
888
 
889
+ return $this;
890
  }
891
 
892
  /**
896
  */
897
  public function getLinkedWishlistItemFields()
898
  {
899
+ $value = $this->_getConfig('linked_wishlist_item_fields');
900
 
901
+ if (empty($value)) {
902
+ return array();
903
+ } else {
904
+ return json_decode($value, true);
905
+ }
906
  }
907
 
908
  /**
909
  * Set the linked wishlist item fields
910
  *
911
+ * @param array $value
912
+ * @return Copernica_MarketingSoftware_Helper_Config
913
  */
914
  public function setLinkedWishlistItemFields($value)
915
  {
916
+ $this->_setConfig('linked_wishlist_item_fields', json_encode($value), true);
917
 
918
+ return $this;
919
  }
920
 
921
  /**
923
  * This is the created timestamp of the most recent customer which has
924
  * been queued for synchronisation
925
  *
926
+ * @return datetime
927
  */
928
  public function getCustomerProgressStatus()
929
  {
935
  * This is the created timestamp of the most recent customer which has
936
  * been queued for synchronisation
937
  *
938
+ * @param datetime $value
939
+ * @return Copernica_MarketingSoftware_Helper_Config
940
  */
941
  public function setCustomerProgressStatus($value)
942
  {
962
  * This is the created timestamp of the most recent order which has
963
  * been queued for synchronisation
964
  *
965
+ * @param datetime $value
966
+ * @return Copernica_MarketingSoftware_Helper_Config
967
  */
968
  public function setOrderProgressStatus($value)
969
  {
989
  * This is the created timestamp of the most recent subscription which has
990
  * been queued for synchronisation
991
  *
992
+ * @param datetime $value
993
+ * @return Copernica_MarketingSoftware_Helper_Config
994
  */
995
  public function setSubscriptionProgressStatus($value)
996
  {
1002
  /**
1003
  * Get the last start time of the cronjob.
1004
  *
1005
+ * @return datetime
1006
  */
1007
  public function getLastStartTimeCronjob()
1008
  {
1012
  /**
1013
  * Set the last start time of the cronjob.
1014
  *
1015
+ * @param datetime $value
1016
+ * @return Copernica_MarketingSoftware_Helper_Config
1017
  */
1018
  public function setLastStartTimeCronjob($value)
1019
  {
1025
  /**
1026
  * Get the last end time of the cronjob.
1027
  *
1028
+ * @return datetime
1029
  */
1030
  public function getLastEndTimeCronjob()
1031
  {
1035
  /**
1036
  * Set the last end time of the cronjob.
1037
  *
1038
+ * @param datetime $value
1039
+ * @return Copernica_MarketingSoftware_Helper_Config
1040
  */
1041
  public function setLastEndTimeCronjob($value)
1042
  {
1058
  /**
1059
  * Set the last end time of the cronjob.
1060
  *
1061
+ * @param integer $value
1062
+ * @return Copernica_MarketingSoftware_Helper_Config
1063
  */
1064
  public function setLastCronjobProcessedTasks($value)
1065
  {
1072
  * Should our extension use vanilla magento cron schedulers to execute
1073
  * queue? Or should we sync all data by processQueue.php file?
1074
  *
1075
+ * @param boolean $vanilla
1076
+ * @return Copernica_MarketingSoftware_Helper_Config
1077
  */
1078
  public function setVanillaCrons($vanilla)
1079
  {
1085
  /**
1086
  * Get stored config about vanilla crons schedulers.
1087
  *
1088
+ * @return boolean
1089
  */
1090
  public function getVanillaCrons()
1091
  {
1107
  /**
1108
  * Set timestamp when we did check forgotten carts list
1109
  *
1110
+ * @param string $time
1111
+ * @return Copernica_MarketingSoftware_Helper_Config
1112
  */
1113
  public function setAbandonedLastCheck($time = null)
1114
  {
1121
  * Set number of minutes that have to pass from last quote item update to consider
1122
  * cart abandonded.
1123
  *
1124
+ * @param int $timeout
1125
  * @return Copernica_MarketingSoftware_Helper_Config
1126
  */
1127
  public function setAbandonedTimeout($timeout)
1148
  * Carts older than supplied number of minutes will not be synchronized
1149
  * with Copernica.
1150
  *
1151
+ * @param int $timeout
1152
+ * @return Copernica_MarketingSoftware_Helper_Config
1153
  */
1154
  public function setAbandonedPeriod($timeout)
1155
  {
1174
  /**
1175
  * Should finished (removed or ordered) quote item be removed from profile?
1176
  *
1177
+ * @param boolean $remove
1178
+ * @return Copernica_MarketingSoftware_Helper_Config
1179
  */
1180
  public function setRemoveFinishedQuoteItem($remove)
1181
  {
1223
  $this->unsWishlistItemCollectionId();
1224
  $this->unsLinkedWishlistItemFields();
1225
  }
1226
+ }
app/code/community/Copernica/MarketingSoftware/Helper/Data.php CHANGED
@@ -1,21 +1,21 @@
1
  <?php
2
  /**
3
- * Copernica Marketing Software
4
  *
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the Open Software License (OSL 3.0).
8
  * It is available through the world-wide-web at this URL:
9
  * http://opensource.org/licenses/osl-3.0.php
10
- * If you are unable to obtain a copy of the license through the
11
- * world-wide-web, please send an email to copernica@support.cream.nl
12
  * so we can send you a copy immediately.
13
  *
14
  * DISCLAIMER
15
  *
16
- * Do not edit or add to this file if you wish to upgrade this software
17
- * to newer versions in the future. If you wish to customize this module
18
- * for your needs please refer to http://www.magento.com/ for more
19
  * information.
20
  *
21
  * @category Copernica
@@ -31,196 +31,197 @@ class Copernica_MarketingSoftware_Helper_Data extends Mage_Core_Helper_Abstract
31
  {
32
  /**
33
  * Helper method returns all supported customer fields
34
- *
35
- * @return array
36
  */
37
  public function supportedCustomerFields()
38
  {
39
  return array(
40
- 'gender' => 'Gender',
41
- 'firstname' => 'Firstname',
42
- 'middlename' => 'Middlename',
43
- 'lastname' => 'Lastname',
44
- 'email' => 'E-mail',
45
- 'birthdate' => 'Birth date',
46
- 'group' => 'Customer group',
47
- 'newsletter' => 'Newsletter',
48
- 'storeView' => 'Store view',
49
- 'registrationDate' => 'Registration date',
50
  );
51
  }
52
-
53
  /**
54
- * Helper method returns all supported fields for
55
  * the quote item collection
56
- *
57
- * @return array
58
  */
59
  public function supportedQuoteItemFields()
60
  {
61
  return array(
62
- 'productId' => 'Product id',
63
- 'name' => 'Product name',
64
- 'sku' => 'SKU',
65
- 'attributeSet' => 'Attribute set',
66
- 'weight' => 'Weight',
67
- 'quantity' => 'Quantity',
68
- 'price' => 'Price',
69
- 'totalPrice' => 'Total price',
70
- 'storeView' => 'Store view',
71
- 'url' => 'Details URL',
72
- 'image' => 'Image URL',
73
- 'categories' => 'Categories',
74
- 'options' => 'Product options',
75
- 'attributes' => 'Product Attributes',
76
- 'createdAt' => 'Created',
77
- 'updatedAt' => 'Modified'
78
  );
79
  }
80
-
81
  /**
82
- * Helper method returns all supported fields for
83
  * the order collection
84
- *
85
- * @return array
86
  */
87
  public function supportedOrderFields()
88
  {
89
  return array(
90
- 'incrementId' => 'Increment id',
91
- 'quantity' => 'Quantity',
92
  //'subtotal' => 'Subtotal',
93
- 'shipping' => 'Shipping costs',
94
- 'total' => 'Order total',
95
- 'weight' => 'Total weight',
96
- 'currency' => 'Currency',
97
- 'status' => 'Order status',
98
- 'storeView' => 'Store view',
99
- 'remoteIp' => 'Order ip address',
100
- 'shippingDescription' => 'Shipping description',
101
- 'paymentDescription' => 'Payment description',
102
- 'shippingAddressId' => 'Shipping Address id',
103
- 'billingAddressId' => 'Billing Address id',
104
- 'couponCode' => 'Coupon code',
105
- 'createdAt' => 'Created',
106
- 'updatedAt' => 'Modified'
 
107
  );
108
  }
109
 
110
  /**
111
- * Helper method returns all supported fields for
112
  * the order item collection
113
- *
114
- * @return array
115
  */
116
  public function supportedOrderItemFields()
117
  {
118
  return array(
119
- 'productId' => 'Product id',
120
- 'incrementId' => 'Increment id',
121
- 'name' => 'Product name',
122
- 'sku' => 'SKU',
123
- 'attributeSet' => 'Attribute set',
124
- 'weight' => 'Weight',
125
- 'quantity' => 'Quantity',
126
- 'price' => 'Price',
127
- 'totalPrice' => 'Total price',
128
- 'status' => 'Order item status',
129
- 'storeView' => 'Store view',
130
- 'url' => 'Details URL',
131
- 'image' => 'Image URL',
132
- 'categories' => 'Categories',
133
- 'options' => 'Product options',
134
- 'attributes' => 'Product Attributes',
135
- 'salesRules' => 'Sales rules',
136
- 'createdAt' => 'Created',
137
- 'updatedAt' => 'Modified',
138
-
139
  );
140
  }
141
-
142
  /**
143
- * Helper method returns all supported fields for
144
  * the address collection
145
- *
146
- * @return array
147
  */
148
  public function supportedAddressFields()
149
  {
150
  return array(
151
- 'firstname' => 'Firstname',
152
- 'middlename' => 'Middlename',
153
- 'prefix' => 'Prefix',
154
- 'lastname' => 'Lastname',
155
- 'email' => 'E-mail',
156
- 'company' => 'Company',
157
- 'street' => 'Street',
158
- 'city' => 'City',
159
- 'state' => 'State',
160
- 'zipcode' => 'Zip code',
161
- 'countryId' => 'Country',
162
- 'telephone' => 'Telephone number',
163
- 'fax' => 'Fax number',
164
  );
165
  }
166
 
167
  /**
168
- * Helper method returns all supported fields for
169
  * the viewed product collection
170
- *
171
- * @return array
172
  */
173
  public function supportedViewedProductFields()
174
  {
175
  return array(
176
- 'productId' => 'Product id',
177
- 'name' => 'Product name',
178
- 'sku' => 'SKU',
179
- 'attributeSet' => 'Attribute set',
180
- 'weight' => 'Weight',
181
- 'price' => 'Price',
182
- 'storeView' => 'Store view',
183
- 'url' => 'Details URL',
184
- 'image' => 'Image URL',
185
- 'categories' => 'Categories',
186
- 'options' => 'Product options',
187
- 'attributes' => 'Product Attributes',
188
- 'createdAt' => 'Created'
189
  );
190
  }
191
-
192
  /**
193
  * Helper method returns all supported fields for
194
  * the wishlist item collection
195
  *
196
- * @return array
197
  */
198
  public function supportedWishlistItemFields()
199
  {
200
- return array(
201
- 'productId' => 'Product id',
202
- 'name' => 'Product name',
203
- 'sku' => 'SKU',
204
- 'attributeSet' => 'Attribute set',
205
- 'weight' => 'Weight',
206
- 'quantity' => 'Quantity',
207
- 'price' => 'Price',
208
- 'totalPrice' => 'Total price',
209
- 'description' => 'Description',
210
- 'storeView' => 'Store view',
211
- 'url' => 'Details URL',
212
- 'image' => 'Image URL',
213
- 'categories' => 'Categories',
214
- 'options' => 'Product options',
215
- 'attributes' => 'Product Attributes',
216
- 'createdAt' => 'Created'
217
- );
218
  }
219
 
220
  /**
221
  * Required fields for copernica customer profile.
222
- *
223
- * @return array
224
  */
225
  public function requiredCustomerFields()
226
  {
@@ -229,8 +230,8 @@ class Copernica_MarketingSoftware_Helper_Data extends Mage_Core_Helper_Abstract
229
 
230
  /**
231
  * Required fields for copernica quote item collection.
232
- *
233
- * @return array
234
  */
235
  public function requiredQuoteItemFields()
236
  {
@@ -239,8 +240,8 @@ class Copernica_MarketingSoftware_Helper_Data extends Mage_Core_Helper_Abstract
239
 
240
  /**
241
  * Required fields for copernica orders collection
242
- *
243
- * @return array
244
  */
245
  public function requiredOrderFields()
246
  {
@@ -249,8 +250,8 @@ class Copernica_MarketingSoftware_Helper_Data extends Mage_Core_Helper_Abstract
249
 
250
  /**
251
  * Required fields for copernica order item collection
252
- *
253
- * @return array
254
  */
255
  public function requiredOrderItemFields()
256
  {
@@ -259,8 +260,8 @@ class Copernica_MarketingSoftware_Helper_Data extends Mage_Core_Helper_Abstract
259
 
260
  /**
261
  * Required fields for copernica address collection
262
- *
263
- * @return array
264
  */
265
  public function requiredAddressFields()
266
  {
@@ -269,8 +270,8 @@ class Copernica_MarketingSoftware_Helper_Data extends Mage_Core_Helper_Abstract
269
 
270
  /**
271
  * Required fields for copernica viewed products collection
272
- *
273
- * @return array
274
  */
275
  public function requiredViewedProductFields()
276
  {
@@ -280,218 +281,223 @@ class Copernica_MarketingSoftware_Helper_Data extends Mage_Core_Helper_Abstract
280
  /**
281
  * Required fields for copernica wislist collection
282
  *
283
- * @return array
284
  */
285
  public function requiredWishlistItemFields()
286
  {
287
- return array('item_id', 'wishlist_id');
288
  }
289
-
290
  /**
291
  * Get field definition by collection type and magento field name.
292
  *
293
- * Some of collections fields should have special definitions. That is mostly
294
- * caused by meaning of data. Fox emaple when there is an email field we
295
  * want to be able to recognize data from that field as email. So, in copernica
296
  * platform we should also have a field of type email. Same goes for phones,
297
  * dates, etc.
298
  *
299
- * @param string $collectionType
300
- * @param string $magentoName
301
- * @return array
302
  */
303
  public function getCollectionFieldDefinition($collectionType, $magentoName)
304
  {
305
  $definitions = array(
306
- 'cartproducts' => array (
307
- 'createdAt' => array (
308
- 'type' => 'datetime'
309
- ),
310
- 'updatedAt' => array (
311
- 'type' => 'datetime'
312
- ),
313
- 'url' => array (
314
  'type' => 'text',
315
  'length' => 255
316
  ),
317
- 'image' => array (
318
  'type' => 'text',
319
  'length' => 255
320
  ),
321
- 'categories' => array (
322
  'type' => 'text',
323
  'length' => 255,
324
  'textlines' => 4,
325
  'lines' => 4
326
  ),
327
- 'storeView' => array (
328
  'type' => 'text',
329
  'length' => 250
330
  ),
331
- 'options' => array (
332
- 'type' => 'big',
333
  'textlines' => 4,
334
  'lines' => 4
335
- ),
336
- 'attributes' => array (
337
- 'type' => 'big',
338
  'textlines' => 4,
339
  'lines' => 4
340
- ),
341
  ),
342
- 'orderproducts' => array (
343
- 'createdAt' => array (
344
  'type' => 'datetime'
345
  ),
346
- 'updatedAt' => array (
347
- 'type' => 'datetime'
348
- ),
349
- 'url' => array (
350
  'type' => 'text',
351
  'length' => 255
352
  ),
353
- 'image' => array (
354
  'type' => 'text',
355
  'length' => 255
356
  ),
357
- 'categories' => array (
358
  'type' => 'text',
359
  'length' => 255,
360
  'textlines' => 4,
361
  'lines' => 4
362
  ),
363
- 'storeView' => array (
364
  'type' => 'text',
365
  'length' => 250
366
  ),
367
- 'options' => array (
368
  'type' => 'big',
369
  'textlines' => 4,
370
  'lines' => 4
371
  ),
372
- 'attributes' => array (
373
  'type' => 'big',
374
  'textlines' => 4,
375
  'lines' => 4
376
  ),
377
- 'salesRules' => array (
378
  'type' => 'big',
379
  'textlines' => 4,
380
  'lines' => 4
381
  ),
382
  ),
383
- 'viewedproducts' => array (
384
- 'createdAt' => array (
385
  'type' => 'datetime'
386
  ),
387
- 'url' => array (
388
  'type' => 'text',
389
  'length' => 255
390
  ),
391
- 'image' => array (
392
  'type' => 'text',
393
  'length' => 255
394
  ),
395
- 'categories' => array (
396
  'type' => 'text',
397
  'length' => 255,
398
  'textlines' => 4,
399
  'lines' => 4
400
  ),
401
- 'storeView' => array (
402
  'type' => 'text',
403
  'length' => 250
404
  ),
405
- 'options' => array (
406
  'type' => 'big',
407
  'textlines' => 4,
408
  'lines' => 4
409
  ),
410
- 'attributes' => array (
411
  'type' => 'big',
412
  'textlines' => 4,
413
  'lines' => 4
414
- )
415
  ),
416
- 'orders' => array (
417
- 'createdAt' => array (
418
  'type' => 'datetime'
419
  ),
420
- 'updatedAt' => array (
421
- 'type' => 'datetime'
422
- ),
423
- 'storeView' => array (
424
  'type' => 'text',
425
  'length' => 250
426
  ),
427
- 'shippingDescription' => array (
428
  'type' => 'big',
429
  'textlines' => 4,
430
  'lines' => 4
431
  ),
432
- 'paymentDescription' => array (
433
  'type' => 'big',
434
  'textlines' => 4,
435
  'lines' => 4
436
  ),
437
- 'couponCode' => array (
438
  'type' => 'text',
439
  'length' => 255
 
 
 
 
 
440
  )
441
  ),
442
- 'addresses' => array (
443
- 'email' => array (
444
  'type' => 'email',
445
  ),
446
- 'telephone' => array (
447
  'type' => 'phone_gsm'
448
  ),
449
- 'fax' => array (
450
  'type' => 'phone_fax'
451
  )
452
  ),
453
- 'wishlistproducts' => array (
454
- 'createdAt' => array (
455
  'type' => 'datetime'
456
  ),
457
- 'description' => array (
458
  'type' => 'big',
459
  'textlines' => 4,
460
  'lines' => 4
461
- ),
462
- 'url' => array (
463
  'type' => 'text',
464
  'length' => 255
465
  ),
466
- 'image' => array (
467
  'type' => 'text',
468
  'length' => 255
469
  ),
470
- 'categories' => array (
471
  'type' => 'text',
472
  'length' => 255,
473
  'textlines' => 4,
474
  'lines' => 4
475
  ),
476
- 'storeView' => array (
477
  'type' => 'text',
478
  'length' => 250
479
  ),
480
- 'options' => array (
481
- 'type' => 'big',
482
  'textlines' => 4,
483
  'lines' => 4
484
- ),
485
- 'attributes' => array (
486
- 'type' => 'big',
487
  'textlines' => 4,
488
  'lines' => 4
489
- ),
490
- )
491
  );
492
 
493
  if (!isset($definitions[$collectionType]) || !isset($definitions[$collectionType][$magentoName])) {
494
- return array ('type' => 'text');
495
  }
496
 
497
  return $definitions[$collectionType][$magentoName];
@@ -499,45 +505,45 @@ class Copernica_MarketingSoftware_Helper_Data extends Mage_Core_Helper_Abstract
499
 
500
  /**
501
  * Get the version of this extension.
502
- *
503
  * @return string
504
  */
505
  public function getExtensionVersion()
506
  {
507
  $config = Mage::getConfig()->getModuleConfig('Copernica_MarketingSoftware')->asArray();
508
-
509
  return $config['version'];
510
  }
511
 
512
  /**
513
  * Get the url for the unsubscribe callback
514
- *
515
- * @return string
516
  */
517
  public function unsubscribeCallbackUrl()
518
  {
519
  return Mage::getModel('core/url')->getUrl('copernica/unsubscribe/process', array());
520
  }
521
-
522
- /**
523
  * Does the queue contain the magic token, which indicates that the synchronisation
524
  * should be started?
525
- *
526
- * @return boolean
527
  */
528
  public function isSynchronisationStartScheduled()
529
  {
530
  $count = Mage::getResourceModel('marketingsoftware/queue_item_collection')
531
  ->addFieldToFilter('action', 'start_sync')
532
  ->getSize();
533
-
534
- return ($count > 0);
535
  }
536
-
537
  /**
538
  * Is the Copernica module enabled?
539
- *
540
- * @return boolean
541
  */
542
  public function enabled()
543
  {
1
  <?php
2
  /**
3
+ * Copernica Marketing Software
4
  *
5
  * NOTICE OF LICENSE
6
  *
7
  * This source file is subject to the Open Software License (OSL 3.0).
8
  * It is available through the world-wide-web at this URL:
9
  * http://opensource.org/licenses/osl-3.0.php
10
+ * If you are unable to obtain a copy of the license through the
11
+ * world-wide-web, please send an email to copernica@support.cream.nl
12
  * so we can send you a copy immediately.
13
  *
14
  * DISCLAIMER
15
  *
16
+ * Do not edit or add to this file if you wish to upgrade this software
17
+ * to newer versions in the future. If you wish to customize this module
18
+ * for your needs please refer to http://www.magento.com/ for more
19
  * information.
20
  *
21
  * @category Copernica
31
  {
32
  /**
33
  * Helper method returns all supported customer fields
34
+ *
35
+ * @return array
36
  */
37
  public function supportedCustomerFields()
38
  {
39
  return array(
40
+ 'gender' => 'Gender',
41
+ 'firstname' => 'Firstname',
42
+ 'middlename' => 'Middlename',
43
+ 'lastname' => 'Lastname',
44
+ 'email' => 'E-mail',
45
+ 'birthdate' => 'Birth date',
46
+ 'group' => 'Customer group',
47
+ 'newsletter' => 'Newsletter',
48
+ 'storeView' => 'Store view',
49
+ 'registrationDate' => 'Registration date'
50
  );
51
  }
52
+
53
  /**
54
+ * Helper method returns all supported fields for
55
  * the quote item collection
56
+ *
57
+ * @return array
58
  */
59
  public function supportedQuoteItemFields()
60
  {
61
  return array(
62
+ 'productId' => 'Product id',
63
+ 'name' => 'Product name',
64
+ 'sku' => 'SKU',
65
+ 'attributeSet' => 'Attribute set',
66
+ 'weight' => 'Weight',
67
+ 'quantity' => 'Quantity',
68
+ 'price' => 'Price',
69
+ 'totalPrice' => 'Total price',
70
+ 'storeView' => 'Store view',
71
+ 'url' => 'Details URL',
72
+ 'image' => 'Image URL',
73
+ 'categories' => 'Categories',
74
+ 'options' => 'Product options',
75
+ 'attributes' => 'Product Attributes',
76
+ 'createdAt' => 'Created',
77
+ 'updatedAt' => 'Modified'
78
  );
79
  }
80
+
81
  /**
82
+ * Helper method returns all supported fields for
83
  * the order collection
84
+ *
85
+ * @return array
86
  */
87
  public function supportedOrderFields()
88
  {
89
  return array(
90
+ 'incrementId' => 'Increment id',
91
+ 'quantity' => 'Quantity',
92
  //'subtotal' => 'Subtotal',
93
+ 'shipping' => 'Shipping costs',
94
+ 'total' => 'Order total',
95
+ 'weight' => 'Total weight',
96
+ 'currency' => 'Currency',
97
+ 'status' => 'Order status',
98
+ 'storeView' => 'Store view',
99
+ 'remoteIp' => 'Order ip address',
100
+ 'shippingDescription' => 'Shipping description',
101
+ 'paymentDescription' => 'Payment description',
102
+ 'shippingAddressId' => 'Shipping Address id',
103
+ 'billingAddressId' => 'Billing Address id',
104
+ 'couponCode' => 'Coupon code',
105
+ 'trackAndTrace' => 'Track & trace',
106
+ 'createdAt' => 'Created',
107
+ 'updatedAt' => 'Modified'
108
  );
109
  }
110
 
111
  /**
112
+ * Helper method returns all supported fields for
113
  * the order item collection
114
+ *
115
+ * @return array
116
  */
117
  public function supportedOrderItemFields()
118
  {
119
  return array(
120
+ 'productId' => 'Product id',
121
+ 'incrementId' => 'Increment id',
122
+ 'name' => 'Product name',
123
+ 'sku' => 'SKU',
124
+ 'attributeSet' => 'Attribute set',
125
+ 'weight' => 'Weight',
126
+ 'quantity' => 'Quantity',
127
+ 'price' => 'Price',
128
+ 'totalPrice' => 'Total price',
129
+ 'status' => 'Order item status',
130
+ 'storeView' => 'Store view',
131
+ 'url' => 'Details URL',
132
+ 'image' => 'Image URL',
133
+ 'categories' => 'Categories',
134
+ 'options' => 'Product options',
135
+ 'attributes' => 'Product Attributes',
136
+ 'salesRules' => 'Sales rules',
137
+ 'createdAt' => 'Created',
138
+ 'updatedAt' => 'Modified',
139
+
140
  );
141
  }
142
+
143
  /**
144
+ * Helper method returns all supported fields for
145
  * the address collection
146
+ *
147
+ * @return array
148
  */
149
  public function supportedAddressFields()
150
  {
151
  return array(
152
+ 'firstname' => 'Firstname',
153
+ 'middlename' => 'Middlename',
154
+ 'prefix' => 'Prefix',
155
+ 'lastname' => 'Lastname',
156
+ 'email' => 'E-mail',
157
+ 'company' => 'Company',
158
+ 'street' => 'Street',
159
+ 'city' => 'City',
160
+ 'state' => 'State',
161
+ 'zipcode' => 'Zip code',
162
+ 'countryId' => 'Country',
163
+ 'telephone' => 'Telephone number',
164
+ 'fax' => 'Fax number',
165
  );
166
  }
167
 
168
  /**
169
+ * Helper method returns all supported fields for
170
  * the viewed product collection
171
+ *
172
+ * @return array
173
  */
174
  public function supportedViewedProductFields()
175
  {
176
  return array(
177
+ 'productId' => 'Product id',
178
+ 'name' => 'Product name',
179
+ 'sku' => 'SKU',
180
+ 'attributeSet' => 'Attribute set',
181
+ 'weight' => 'Weight',
182
+ 'price' => 'Price',
183
+ 'storeView' => 'Store view',
184
+ 'url' => 'Details URL',
185
+ 'image' => 'Image URL',
186
+ 'categories' => 'Categories',
187
+ 'options' => 'Product options',
188
+ 'attributes' => 'Product Attributes',
189
+ 'createdAt' => 'Created'
190
  );
191
  }
192
+
193
  /**
194
  * Helper method returns all supported fields for
195
  * the wishlist item collection
196
  *
197
+ * @return array
198
  */
199
  public function supportedWishlistItemFields()
200
  {
201
+ return array(
202
+ 'productId' => 'Product id',
203
+ 'name' => 'Product name',
204
+ 'sku' => 'SKU',
205
+ 'attributeSet' => 'Attribute set',
206
+ 'weight' => 'Weight',
207
+ 'quantity' => 'Quantity',
208
+ 'price' => 'Price',
209
+ 'totalPrice' => 'Total price',
210
+ 'description' => 'Description',
211
+ 'storeView' => 'Store view',
212
+ 'url' => 'Details URL',
213
+ 'image' => 'Image URL',
214
+ 'categories' => 'Categories',
215
+ 'options' => 'Product options',
216
+ 'attributes' => 'Product Attributes',
217
+ 'createdAt' => 'Created'
218
+ );
219
  }
220
 
221
  /**
222
  * Required fields for copernica customer profile.
223
+ *
224
+ * @return array
225
  */
226
  public function requiredCustomerFields()
227
  {
230
 
231
  /**
232
  * Required fields for copernica quote item collection.
233
+ *
234
+ * @return array
235
  */
236
  public function requiredQuoteItemFields()
237
  {
240
 
241
  /**
242
  * Required fields for copernica orders collection
243
+ *
244
+ * @return array
245
  */
246
  public function requiredOrderFields()
247
  {
250
 
251
  /**
252
  * Required fields for copernica order item collection
253
+ *
254
+ * @return array
255
  */
256
  public function requiredOrderItemFields()
257
  {
260
 
261
  /**
262
  * Required fields for copernica address collection
263
+ *
264
+ * @return array
265
  */
266
  public function requiredAddressFields()
267
  {
270
 
271
  /**
272
  * Required fields for copernica viewed products collection
273
+ *
274
+ * @return array
275
  */
276
  public function requiredViewedProductFields()
277
  {
281
  /**
282
  * Required fields for copernica wislist collection
283
  *
284
+ * @return array
285
  */
286
  public function requiredWishlistItemFields()
287
  {
288
+ return array('item_id', 'wishlist_id');
289
  }
290
+
291
  /**
292
  * Get field definition by collection type and magento field name.
293
  *
294
+ * Some of collections fields should have special definitions. That is mostly
295
+ * caused by meaning of data. Fox emaple when there is an email field we
296
  * want to be able to recognize data from that field as email. So, in copernica
297
  * platform we should also have a field of type email. Same goes for phones,
298
  * dates, etc.
299
  *
300
+ * @param string $collectionType
301
+ * @param string $magentoName
302
+ * @return array
303
  */
304
  public function getCollectionFieldDefinition($collectionType, $magentoName)
305
  {
306
  $definitions = array(
307
+ 'cartproducts' => array(
308
+ 'createdAt' => array(
309
+ 'type' => 'datetime'
310
+ ),
311
+ 'updatedAt' => array(
312
+ 'type' => 'datetime'
313
+ ),
314
+ 'url' => array(
315
  'type' => 'text',
316
  'length' => 255
317
  ),
318
+ 'image' => array(
319
  'type' => 'text',
320
  'length' => 255
321
  ),
322
+ 'categories' => array(
323
  'type' => 'text',
324
  'length' => 255,
325
  'textlines' => 4,
326
  'lines' => 4
327
  ),
328
+ 'storeView' => array(
329
  'type' => 'text',
330
  'length' => 250
331
  ),
332
+ 'options' => array(
333
+ 'type' => 'big',
334
  'textlines' => 4,
335
  'lines' => 4
336
+ ),
337
+ 'attributes' => array(
338
+ 'type' => 'big',
339
  'textlines' => 4,
340
  'lines' => 4
341
+ ),
342
  ),
343
+ 'orderproducts' => array(
344
+ 'createdAt' => array(
345
  'type' => 'datetime'
346
  ),
347
+ 'updatedAt' => array(
348
+ 'type' => 'datetime'
349
+ ),
350
+ 'url' => array(
351
  'type' => 'text',
352
  'length' => 255
353
  ),
354
+ 'image' => array(
355
  'type' => 'text',
356
  'length' => 255
357
  ),
358
+ 'categories' => array(
359
  'type' => 'text',
360
  'length' => 255,
361
  'textlines' => 4,
362
  'lines' => 4
363
  ),
364
+ 'storeView' => array(
365
  'type' => 'text',
366
  'length' => 250
367
  ),
368
+ 'options' => array(
369
  'type' => 'big',
370
  'textlines' => 4,
371
  'lines' => 4
372
  ),
373
+ 'attributes' => array(
374
  'type' => 'big',
375
  'textlines' => 4,
376
  'lines' => 4
377
  ),
378
+ 'salesRules' => array(
379
  'type' => 'big',
380
  'textlines' => 4,
381
  'lines' => 4
382
  ),
383
  ),
384
+ 'viewedproducts' => array(
385
+ 'createdAt' => array(
386
  'type' => 'datetime'
387
  ),
388
+ 'url' => array(
389
  'type' => 'text',
390
  'length' => 255
391
  ),
392
+ 'image' => array(
393
  'type' => 'text',
394
  'length' => 255
395
  ),
396
+ 'categories' => array(
397
  'type' => 'text',
398
  'length' => 255,
399
  'textlines' => 4,
400
  'lines' => 4
401
  ),
402
+ 'storeView' => array(
403
  'type' => 'text',
404
  'length' => 250
405
  ),
406
+ 'options' => array(
407
  'type' => 'big',
408
  'textlines' => 4,
409
  'lines' => 4
410
  ),
411
+ 'attributes' => array(
412
  'type' => 'big',
413
  'textlines' => 4,
414
  'lines' => 4
415
+ )
416
  ),
417
+ 'orders' => array(
418
+ 'createdAt' => array(
419
  'type' => 'datetime'
420
  ),
421
+ 'updatedAt' => array(
422
+ 'type' => 'datetime'
423
+ ),
424
+ 'storeView' => array(
425
  'type' => 'text',
426
  'length' => 250
427
  ),
428
+ 'shippingDescription' => array(
429
  'type' => 'big',
430
  'textlines' => 4,
431
  'lines' => 4
432
  ),
433
+ 'paymentDescription' => array(
434
  'type' => 'big',
435
  'textlines' => 4,
436
  'lines' => 4
437
  ),
438
+ 'couponCode' => array(
439
  'type' => 'text',
440
  'length' => 255
441
+ ),
442
+ 'trackAndTrace' => array(
443
+ 'type' => 'big',
444
+ 'textlines' => 4,
445
+ 'lines' => 4
446
  )
447
  ),
448
+ 'addresses' => array(
449
+ 'email' => array(
450
  'type' => 'email',
451
  ),
452
+ 'telephone' => array(
453
  'type' => 'phone_gsm'
454
  ),
455
+ 'fax' => array(
456
  'type' => 'phone_fax'
457
  )
458
  ),
459
+ 'wishlistproducts' => array(
460
+ 'createdAt' => array(
461
  'type' => 'datetime'
462
  ),
463
+ 'description' => array(
464
  'type' => 'big',
465
  'textlines' => 4,
466
  'lines' => 4
467
+ ),
468
+ 'url' => array(
469
  'type' => 'text',
470
  'length' => 255
471
  ),
472
+ 'image' => array(
473
  'type' => 'text',
474
  'length' => 255
475
  ),
476
+ 'categories' => array(
477
  'type' => 'text',
478
  'length' => 255,
479
  'textlines' => 4,
480
  'lines' => 4
481
  ),
482
+ 'storeView' => array(
483
  'type' => 'text',
484
  'length' => 250
485
  ),
486
+ 'options' => array(
487
+ 'type' => 'big',
488
  'textlines' => 4,
489
  'lines' => 4
490
+ ),
491
+ 'attributes' => array(
492
+ 'type' => 'big',
493
  'textlines' => 4,
494
  'lines' => 4
495
+ ),
496
+ )
497
  );
498
 
499
  if (!isset($definitions[$collectionType]) || !isset($definitions[$collectionType][$magentoName])) {
500
+ return array('type' => 'text');
501
  }
502
 
503
  return $definitions[$collectionType][$magentoName];
505
 
506
  /**
507
  * Get the version of this extension.
508
+ *
509
  * @return string
510
  */
511
  public function getExtensionVersion()
512
  {
513
  $config = Mage::getConfig()->getModuleConfig('Copernica_MarketingSoftware')->asArray();
514
+
515
  return $config['version'];
516
  }
517
 
518
  /**
519
  * Get the url for the unsubscribe callback
520
+ *
521
+ * @return string
522
  */
523
  public function unsubscribeCallbackUrl()
524
  {
525
  return Mage::getModel('core/url')->getUrl('copernica/unsubscribe/process', array());
526
  }
527
+
528
+ /**
529
  * Does the queue contain the magic token, which indicates that the synchronisation
530
  * should be started?
531
+ *
532
+ * @return boolean
533
  */
534
  public function isSynchronisationStartScheduled()
535
  {
536
  $count = Mage::getResourceModel('marketingsoftware/queue_item_collection')
537
  ->addFieldToFilter('action', 'start_sync')
538
  ->getSize();
539
+
540
+ return ($count > 0);
541
  }
542
+
543
  /**
544
  * Is the Copernica module enabled?
545
+ *
546
+ * @return boolean
547
  */
548
  public function enabled()
549
  {
app/code/community/Copernica/MarketingSoftware/Helper/DataWriter.php CHANGED
@@ -71,7 +71,7 @@ class Copernica_MarketingSoftware_Helper_Datawriter
71
  public function __destruct()
72
  {
73
  if (!is_null($this->_fileHandle)) {
74
- fclose($this->_fileHandle);
75
  }
76
  }
77
 
@@ -86,7 +86,7 @@ class Copernica_MarketingSoftware_Helper_Datawriter
86
 
87
  while (false !== ($entry = readdir($directoryHandle))) {
88
  if (strpos($entry, '.') === 0) {
89
- continue;
90
  }
91
 
92
  $fileNameParts = explode('.', $entry);
@@ -108,7 +108,7 @@ class Copernica_MarketingSoftware_Helper_Datawriter
108
  $dir = Mage::getBaseDir('var');
109
 
110
  if (!is_dir($dir.'/copernica_data')) {
111
- mkdir ($dir.'/copernica_data');
112
  }
113
 
114
  $this->_workingDir = $dir.'/copernica_data';
@@ -124,7 +124,7 @@ class Copernica_MarketingSoftware_Helper_Datawriter
124
  $mbInBytes = 104857600;
125
 
126
  if (!is_file($this->_getFilePath())) {
127
- $this->_createDataFile($this->_getFilePath());
128
  }
129
 
130
  if (filesize($this->_getFilePath()) > $mbInBytes) {
@@ -139,14 +139,11 @@ class Copernica_MarketingSoftware_Helper_Datawriter
139
  /**
140
  * Create new data file at given path.
141
  *
142
- * @param string $path
143
  */
144
  protected function _createDataFile($path)
145
  {
146
- if (is_file($path)) {
147
- // we have a file. Most likely we should handle such situation.
148
- // we will see what we can do with it
149
- } else {
150
  touch($path);
151
  }
152
  }
@@ -155,8 +152,8 @@ class Copernica_MarketingSoftware_Helper_Datawriter
155
  * Get file path to data file. Supplying null value as a parameter will
156
  * output current data file.
157
  *
158
- * @param int $inc
159
- * @return string
160
  */
161
  protected function _getFilePath($inc = null)
162
  {
@@ -168,7 +165,7 @@ class Copernica_MarketingSoftware_Helper_Datawriter
168
 
169
  $fileName = implode('.', $fileNameParts);
170
  } else {
171
- $fileName = $this->_fileName;
172
  }
173
 
174
  return $this->_workingDir.'/'.$fileName;
@@ -177,7 +174,7 @@ class Copernica_MarketingSoftware_Helper_Datawriter
177
  /**
178
  * Write
179
  *
180
- * @param assoc $data
181
  */
182
  protected function _write($data)
183
  {
@@ -197,7 +194,7 @@ class Copernica_MarketingSoftware_Helper_Datawriter
197
 
198
  while (false !== ($entry = readdir($directoryHandle))) {
199
  if (strpos($entry, '.') === 0) {
200
- continue;
201
  }
202
 
203
  unlink($this->_workingDir.'/'.$entry);
@@ -211,10 +208,10 @@ class Copernica_MarketingSoftware_Helper_Datawriter
211
  /**
212
  * Store customer profile.
213
  *
214
- * @param assoc $profile
215
  */
216
  public function storeProfile($profile)
217
  {
218
  $this->_write($profile);
219
  }
220
- }
71
  public function __destruct()
72
  {
73
  if (!is_null($this->_fileHandle)) {
74
+ fclose($this->_fileHandle);
75
  }
76
  }
77
 
86
 
87
  while (false !== ($entry = readdir($directoryHandle))) {
88
  if (strpos($entry, '.') === 0) {
89
+ continue;
90
  }
91
 
92
  $fileNameParts = explode('.', $entry);
108
  $dir = Mage::getBaseDir('var');
109
 
110
  if (!is_dir($dir.'/copernica_data')) {
111
+ mkdir($dir.'/copernica_data');
112
  }
113
 
114
  $this->_workingDir = $dir.'/copernica_data';
124
  $mbInBytes = 104857600;
125
 
126
  if (!is_file($this->_getFilePath())) {
127
+ $this->_createDataFile($this->_getFilePath());
128
  }
129
 
130
  if (filesize($this->_getFilePath()) > $mbInBytes) {
139
  /**
140
  * Create new data file at given path.
141
  *
142
+ * @param string $path
143
  */
144
  protected function _createDataFile($path)
145
  {
146
+ if (!is_file($path)) {
 
 
 
147
  touch($path);
148
  }
149
  }
152
  * Get file path to data file. Supplying null value as a parameter will
153
  * output current data file.
154
  *
155
+ * @param int $inc
156
+ * @return string
157
  */
158
  protected function _getFilePath($inc = null)
159
  {
165
 
166
  $fileName = implode('.', $fileNameParts);
167
  } else {
168
+ $fileName = $this->_fileName;
169
  }
170
 
171
  return $this->_workingDir.'/'.$fileName;
174
  /**
175
  * Write
176
  *
177
+ * @param assoc $data
178
  */
179
  protected function _write($data)
180
  {
194
 
195
  while (false !== ($entry = readdir($directoryHandle))) {
196
  if (strpos($entry, '.') === 0) {
197
+ continue;
198
  }
199
 
200
  unlink($this->_workingDir.'/'.$entry);
208
  /**
209
  * Store customer profile.
210
  *
211
+ * @param assoc $profile
212
  */
213
  public function storeProfile($profile)
214
  {
215
  $this->_write($profile);
216
  }
217
+ }
app/code/community/Copernica/MarketingSoftware/Helper/Profile.php CHANGED
@@ -32,13 +32,13 @@
32
  * than one profile for one customer. It's cause one customer can be in more
33
  * than one store view. Same applies to email addresses cause of same reasons.
34
  */
35
- class Copernica_MarketingSoftware_Helper_Profile
36
  {
37
  /**
38
  * Get copernica Id based on something and store view.
39
  *
40
- * @param mixed $something
41
- * @param Copernica_MarketingSoftware_Model_Abstraction_Storeview $storeview
42
  */
43
  public function getCopernicaId($something, Copernica_MarketingSoftware_Model_Abstraction_Storeview $storeview)
44
  {
@@ -56,8 +56,8 @@ class Copernica_MarketingSoftware_Helper_Profile
56
  /**
57
  * Get copernica Id by customer instance
58
  *
59
- * @param Copernica_MarketingSoftware_Model_Abstraction_Customer $customer
60
- * @param Copernica_MarketingSoftware_Model_Abstraction_Storeview $storeview
61
  * @return string
62
  */
63
  public function getCustomerCopernicaId(Copernica_MarketingSoftware_Model_Abstraction_Customer $customer, Copernica_MarketingSoftware_Model_Abstraction_Storeview $storeview)
@@ -71,7 +71,7 @@ class Copernica_MarketingSoftware_Helper_Profile
71
  ->setPageSize(1);
72
 
73
  if ($profileCache->count()) {
74
- return $profileCache->getFirstItem()->getCopernicaId();
75
  }
76
 
77
  $profileCache = Mage::getModel('marketingsoftware/profile_cache')
@@ -112,7 +112,7 @@ class Copernica_MarketingSoftware_Helper_Profile
112
  /**
113
  * This method will upgrade profile cache data.
114
  *
115
- * @param Copernica_MarketingSoftware_Model_Profile_Cache $profileCache
116
  */
117
  protected function _upgradeSubscriberCopernicaId(Copernica_MarketingSoftware_Model_Profile_Cache $profileCache)
118
  {
@@ -127,8 +127,8 @@ class Copernica_MarketingSoftware_Helper_Profile
127
  /**
128
  * Generate Copernica Id from our customer instance and store view
129
  *
130
- * @param Copernica_MarketingSoftware_Model_Abstraction_Customer $customer
131
- * @param Copernica_MarketingSoftware_Model_Abstraction_Storeview $storeview
132
  * @return string
133
  */
134
  public function generateCustomerCopernicaId(Copernica_MarketingSoftware_Model_Abstraction_Customer $customer, Copernica_MarketingSoftware_Model_Abstraction_Storeview $storeview)
@@ -139,8 +139,8 @@ class Copernica_MarketingSoftware_Helper_Profile
139
  /**
140
  * Generate copernica Id from an email address and store View.
141
  *
142
- * @param string $email
143
- * @param Copernica_MarketingSoftware_Model_Abstraction_Storeview $storeview
144
  * @return string
145
  */
146
  public function getEmailCopernicaId($email, Copernica_MarketingSoftware_Model_Abstraction_Storeview $storeview)
@@ -152,7 +152,7 @@ class Copernica_MarketingSoftware_Helper_Profile
152
  ->setPageSize(1);
153
 
154
  if ($profileCache->count()) {
155
- return $profileCache->getFirstItem()->getCopernicaId();
156
  }
157
 
158
  $profileCache = $profileCache->getFirstItem();
@@ -175,9 +175,9 @@ class Copernica_MarketingSoftware_Helper_Profile
175
  /**
176
  * Generate Copernica Id from our email and store view
177
  *
178
- * @param string $email
179
- * @param Copernica_MarketingSoftware_Model_Abstraction_Storeview $storeview
180
- * @return string
181
  */
182
  public function generateEmailCopernicaId($email, Copernica_MarketingSoftware_Model_Abstraction_Storeview $storeview)
183
  {
@@ -188,8 +188,8 @@ class Copernica_MarketingSoftware_Helper_Profile
188
  * Basically it's a helper method that will convert old customer Id in
189
  * Copernica platform into normal Magento customer Id.
190
  *
191
- * @param string $oldCopernicaId
192
- * @param string $newCustomerId
193
  */
194
  protected function _convertCustomerId($oldCopernicaId, $newCustomerId)
195
  {
@@ -197,7 +197,8 @@ class Copernica_MarketingSoftware_Helper_Profile
197
 
198
  $databaseId = Mage::helper('marketingsoftware/api')->getDatabaseId();
199
 
200
- $request->put('database/'.$databaseId.'/profiles',
 
201
  array( 'customer_id' => $newCustomerId),
202
  array( 'fields[]' => 'customer_id=='.$oldCopernicaId )
203
  );
@@ -206,12 +207,12 @@ class Copernica_MarketingSoftware_Helper_Profile
206
  /**
207
  * Generates a unique customer ID based on the e-mail address and the storeview.
208
  *
209
- * @param string $email
210
- * @param Copernica_MarketingSoftware_Model_Abstraction_Storeview $storeview
211
  * @return string
212
  */
213
  protected function _generateOldCopernicaId($email, Copernica_MarketingSoftware_Model_Abstraction_Storeview $storeview)
214
  {
215
  return md5(strtolower($email) . $storeview);
216
  }
217
- }
32
  * than one profile for one customer. It's cause one customer can be in more
33
  * than one store view. Same applies to email addresses cause of same reasons.
34
  */
35
+ class Copernica_MarketingSoftware_Helper_Profile
36
  {
37
  /**
38
  * Get copernica Id based on something and store view.
39
  *
40
+ * @param mixed $something
41
+ * @param Copernica_MarketingSoftware_Model_Abstraction_Storeview $storeview
42
  */
43
  public function getCopernicaId($something, Copernica_MarketingSoftware_Model_Abstraction_Storeview $storeview)
44
  {
56
  /**
57
  * Get copernica Id by customer instance
58
  *
59
+ * @param Copernica_MarketingSoftware_Model_Abstraction_Customer $customer
60
+ * @param Copernica_MarketingSoftware_Model_Abstraction_Storeview $storeview
61
  * @return string
62
  */
63
  public function getCustomerCopernicaId(Copernica_MarketingSoftware_Model_Abstraction_Customer $customer, Copernica_MarketingSoftware_Model_Abstraction_Storeview $storeview)
71
  ->setPageSize(1);
72
 
73
  if ($profileCache->count()) {
74
+ return $profileCache->getFirstItem()->getCopernicaId();
75
  }
76
 
77
  $profileCache = Mage::getModel('marketingsoftware/profile_cache')
112
  /**
113
  * This method will upgrade profile cache data.
114
  *
115
+ * @param Copernica_MarketingSoftware_Model_Profile_Cache $profileCache
116
  */
117
  protected function _upgradeSubscriberCopernicaId(Copernica_MarketingSoftware_Model_Profile_Cache $profileCache)
118
  {
127
  /**
128
  * Generate Copernica Id from our customer instance and store view
129
  *
130
+ * @param Copernica_MarketingSoftware_Model_Abstraction_Customer $customer
131
+ * @param Copernica_MarketingSoftware_Model_Abstraction_Storeview $storeview
132
  * @return string
133
  */
134
  public function generateCustomerCopernicaId(Copernica_MarketingSoftware_Model_Abstraction_Customer $customer, Copernica_MarketingSoftware_Model_Abstraction_Storeview $storeview)
139
  /**
140
  * Generate copernica Id from an email address and store View.
141
  *
142
+ * @param string $email
143
+ * @param Copernica_MarketingSoftware_Model_Abstraction_Storeview $storeview
144
  * @return string
145
  */
146
  public function getEmailCopernicaId($email, Copernica_MarketingSoftware_Model_Abstraction_Storeview $storeview)
152
  ->setPageSize(1);
153
 
154
  if ($profileCache->count()) {
155
+ return $profileCache->getFirstItem()->getCopernicaId();
156
  }
157
 
158
  $profileCache = $profileCache->getFirstItem();
175
  /**
176
  * Generate Copernica Id from our email and store view
177
  *
178
+ * @param string $email
179
+ * @param Copernica_MarketingSoftware_Model_Abstraction_Storeview $storeview
180
+ * @return string
181
  */
182
  public function generateEmailCopernicaId($email, Copernica_MarketingSoftware_Model_Abstraction_Storeview $storeview)
183
  {
188
  * Basically it's a helper method that will convert old customer Id in
189
  * Copernica platform into normal Magento customer Id.
190
  *
191
+ * @param string $oldCopernicaId
192
+ * @param string $newCustomerId
193
  */
194
  protected function _convertCustomerId($oldCopernicaId, $newCustomerId)
195
  {
197
 
198
  $databaseId = Mage::helper('marketingsoftware/api')->getDatabaseId();
199
 
200
+ $request->put(
201
+ 'database/'.$databaseId.'/profiles',
202
  array( 'customer_id' => $newCustomerId),
203
  array( 'fields[]' => 'customer_id=='.$oldCopernicaId )
204
  );
207
  /**
208
  * Generates a unique customer ID based on the e-mail address and the storeview.
209
  *
210
+ * @param string $email
211
+ * @param Copernica_MarketingSoftware_Model_Abstraction_Storeview $storeview
212
  * @return string
213
  */
214
  protected function _generateOldCopernicaId($email, Copernica_MarketingSoftware_Model_Abstraction_Storeview $storeview)
215
  {
216
  return md5(strtolower($email) . $storeview);
217
  }
218
+ }
app/code/community/Copernica/MarketingSoftware/Helper/Rest/Request.php CHANGED
@@ -67,7 +67,7 @@ class Copernica_MarketingSoftware_Helper_Rest_Request
67
  $config = Mage::helper('marketingsoftware/config');
68
 
69
  if ($hostname = $config->getApiHostname()) {
70
- $this->_hostname = $hostname;
71
  } else {
72
  $this->_hostname = 'https://api.copernica.com';
73
 
@@ -77,7 +77,7 @@ class Copernica_MarketingSoftware_Helper_Rest_Request
77
  $accessToken = $config->getAccessToken();
78
 
79
  if ($accessToken) {
80
- $this->_accessToken = $accessToken;
81
  }
82
  }
83
 
@@ -87,7 +87,7 @@ class Copernica_MarketingSoftware_Helper_Rest_Request
87
  public function __destruct()
88
  {
89
  if (!is_null($this->_multi)) {
90
- $this->commit();
91
  }
92
  }
93
 
@@ -100,11 +100,11 @@ class Copernica_MarketingSoftware_Helper_Rest_Request
100
  public function check ()
101
  {
102
  if (empty($this->_accessToken)) {
103
- return false;
104
  }
105
 
106
  if (empty($this->_hostname)) {
107
- return false;
108
  }
109
 
110
  return true;
@@ -113,7 +113,7 @@ class Copernica_MarketingSoftware_Helper_Rest_Request
113
  /**
114
  * Helper method to build up a query string
115
  *
116
- * @param assoc $data
117
  * @return string
118
  */
119
  protected function _buildQueryString($data)
@@ -126,7 +126,7 @@ class Copernica_MarketingSoftware_Helper_Rest_Request
126
  $parts[] = $key.'[]='.urlencode(strval($valueItem));
127
  }
128
  } else {
129
- $parts[] = $key.'='.urlencode(strval($value));
130
  }
131
  }
132
 
@@ -152,7 +152,7 @@ class Copernica_MarketingSoftware_Helper_Rest_Request
152
  * Make a GET requst
153
  *
154
  * @param string $request
155
- * @param assoc $data
156
  * @return assoc
157
  */
158
  public function get($request, $data = null)
@@ -160,12 +160,15 @@ class Copernica_MarketingSoftware_Helper_Rest_Request
160
  $curl = $this->_prepareCurl();
161
 
162
  if ($this->_accessToken) {
163
- $request.=$this->_buildQueryString(array_merge(array(
164
- 'access_token' => $this->_accessToken),
165
- is_null($data) ? array() : $data
166
- ));
 
 
 
167
  } else {
168
- $request.=$this->_buildQueryString(is_null($data) ? array() : $data);
169
  }
170
 
171
  // Check to remove unnecessary slashes from the request
@@ -184,16 +187,16 @@ class Copernica_MarketingSoftware_Helper_Rest_Request
184
  /**
185
  * Make a POST request
186
  *
187
- * @param string $request
188
- * @param assoc $data
189
- * @param assoc $query
190
  */
191
  public function post($request, $data = null, $query = null)
192
  {
193
  if (is_array($query)) {
194
- $request.= $this->_buildQueryString(array_merge( $query, array('access_token' => $this->_accessToken) ));
195
  } else {
196
- $request.='?access_token='.$this->_accessToken;
197
  }
198
 
199
  $curl = $this->_prepareCurl();
@@ -204,14 +207,16 @@ class Copernica_MarketingSoftware_Helper_Rest_Request
204
  curl_setopt($curl, CURLOPT_URL, $this->_hostname.'/'.$request);
205
  curl_setopt($curl, CURLOPT_POST, true);
206
  curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
207
- curl_setopt($curl, CURLOPT_HTTPHEADER, array(
 
208
  'content-type: application/json',
209
  'accept: application/json'
210
- ));
 
211
  curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
212
 
213
  if ($this->_appendMulti($curl)) {
214
- return true;
215
  }
216
 
217
  curl_exec($curl);
@@ -224,16 +229,16 @@ class Copernica_MarketingSoftware_Helper_Rest_Request
224
  /**
225
  * Make a PUT request
226
  *
227
- * @param string $request
228
- * @param assoc $data
229
- * @param assoc $query
230
  */
231
  public function put($request, $data = null, $query = null)
232
  {
233
  if (is_array($query)) {
234
- $request.= $this->_buildQueryString(array_merge( $query, array('access_token' => $this->_accessToken) ));
235
  } else {
236
- $request.='?access_token='.$this->_accessToken;
237
  }
238
 
239
  $curl = $this->_prepareCurl();
@@ -244,15 +249,17 @@ class Copernica_MarketingSoftware_Helper_Rest_Request
244
  curl_setopt($curl, CURLOPT_URL, $this->_hostname.'/'.$request);
245
  curl_setopt($curl, CURLOPT_POST, true);
246
  curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
247
- curl_setopt($curl, CURLOPT_HTTPHEADER, array(
 
248
  'content-type: application/json',
249
  'accept: application/json'
250
- ));
 
251
  curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
252
  // curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
253
 
254
  if ($this->_appendMulti($curl)) {
255
- return true;
256
  }
257
 
258
  curl_exec($curl);
@@ -279,13 +286,15 @@ class Copernica_MarketingSoftware_Helper_Rest_Request
279
 
280
  curl_setopt($curl, CURLOPT_URL, $this->_hostname.'/'.$request);
281
  curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");
282
- curl_setopt($curl, CURLOPT_HTTPHEADER, array(
 
283
  'content-type: application/json',
284
  'accept: application/json'
285
- ));
 
286
 
287
  if ($this->_appendMulti($curl)) {
288
- return true;
289
  }
290
 
291
  curl_exec($curl);
@@ -314,24 +323,29 @@ class Copernica_MarketingSoftware_Helper_Rest_Request
314
  $active = true;
315
 
316
  if (is_null($this->_multi)) {
317
- return $this;
318
  }
319
 
320
  do {
321
- while (CURLM_CALL_MULTI_PERFORM === curl_multi_exec($this->_multi, $running));
322
- if (!$running) {
323
- break;
324
- }
325
-
326
- while (($res = curl_multi_select($this->_multi)) === 0){};
327
-
328
- if ($res === false) {
329
- break;
 
 
 
 
 
330
  }
331
- } while(true);
332
 
333
  foreach ($this->_children as $child) {
334
- curl_multi_remove_handle($this->_multi, $child);
335
  }
336
 
337
  curl_multi_close($this->_multi);
@@ -347,7 +361,7 @@ class Copernica_MarketingSoftware_Helper_Rest_Request
347
  protected function _appendMulti($curl)
348
  {
349
  if (!is_resource($this->_multi)) {
350
- return false;
351
  }
352
 
353
  $code = curl_multi_add_handle($this->_multi, $curl);
67
  $config = Mage::helper('marketingsoftware/config');
68
 
69
  if ($hostname = $config->getApiHostname()) {
70
+ $this->_hostname = $hostname;
71
  } else {
72
  $this->_hostname = 'https://api.copernica.com';
73
 
77
  $accessToken = $config->getAccessToken();
78
 
79
  if ($accessToken) {
80
+ $this->_accessToken = $accessToken;
81
  }
82
  }
83
 
87
  public function __destruct()
88
  {
89
  if (!is_null($this->_multi)) {
90
+ $this->commit();
91
  }
92
  }
93
 
100
  public function check ()
101
  {
102
  if (empty($this->_accessToken)) {
103
+ return false;
104
  }
105
 
106
  if (empty($this->_hostname)) {
107
+ return false;
108
  }
109
 
110
  return true;
113
  /**
114
  * Helper method to build up a query string
115
  *
116
+ * @param assoc $data
117
  * @return string
118
  */
119
  protected function _buildQueryString($data)
126
  $parts[] = $key.'[]='.urlencode(strval($valueItem));
127
  }
128
  } else {
129
+ $parts[] = $key.'='.urlencode(strval($value));
130
  }
131
  }
132
 
152
  * Make a GET requst
153
  *
154
  * @param string $request
155
+ * @param assoc $data
156
  * @return assoc
157
  */
158
  public function get($request, $data = null)
160
  $curl = $this->_prepareCurl();
161
 
162
  if ($this->_accessToken) {
163
+ $request.=$this->_buildQueryString(
164
+ array_merge(
165
+ array(
166
+ 'access_token' => $this->_accessToken),
167
+ is_null($data) ? array() : $data
168
+ )
169
+ );
170
  } else {
171
+ $request.=$this->_buildQueryString(is_null($data) ? array() : $data);
172
  }
173
 
174
  // Check to remove unnecessary slashes from the request
187
  /**
188
  * Make a POST request
189
  *
190
+ * @param string $request
191
+ * @param assoc $data
192
+ * @param assoc $query
193
  */
194
  public function post($request, $data = null, $query = null)
195
  {
196
  if (is_array($query)) {
197
+ $request.= $this->_buildQueryString(array_merge($query, array('access_token' => $this->_accessToken)));
198
  } else {
199
+ $request.='?access_token='.$this->_accessToken;
200
  }
201
 
202
  $curl = $this->_prepareCurl();
207
  curl_setopt($curl, CURLOPT_URL, $this->_hostname.'/'.$request);
208
  curl_setopt($curl, CURLOPT_POST, true);
209
  curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
210
+ curl_setopt(
211
+ $curl, CURLOPT_HTTPHEADER, array(
212
  'content-type: application/json',
213
  'accept: application/json'
214
+ )
215
+ );
216
  curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
217
 
218
  if ($this->_appendMulti($curl)) {
219
+ return true;
220
  }
221
 
222
  curl_exec($curl);
229
  /**
230
  * Make a PUT request
231
  *
232
+ * @param string $request
233
+ * @param assoc $data
234
+ * @param assoc $query
235
  */
236
  public function put($request, $data = null, $query = null)
237
  {
238
  if (is_array($query)) {
239
+ $request.= $this->_buildQueryString(array_merge($query, array('access_token' => $this->_accessToken)));
240
  } else {
241
+ $request.='?access_token='.$this->_accessToken;
242
  }
243
 
244
  $curl = $this->_prepareCurl();
249
  curl_setopt($curl, CURLOPT_URL, $this->_hostname.'/'.$request);
250
  curl_setopt($curl, CURLOPT_POST, true);
251
  curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
252
+ curl_setopt(
253
+ $curl, CURLOPT_HTTPHEADER, array(
254
  'content-type: application/json',
255
  'accept: application/json'
256
+ )
257
+ );
258
  curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
259
  // curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
260
 
261
  if ($this->_appendMulti($curl)) {
262
+ return true;
263
  }
264
 
265
  curl_exec($curl);
286
 
287
  curl_setopt($curl, CURLOPT_URL, $this->_hostname.'/'.$request);
288
  curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");
289
+ curl_setopt(
290
+ $curl, CURLOPT_HTTPHEADER, array(
291
  'content-type: application/json',
292
  'accept: application/json'
293
+ )
294
+ );
295
 
296
  if ($this->_appendMulti($curl)) {
297
+ return true;
298
  }
299
 
300
  curl_exec($curl);
323
  $active = true;
324
 
325
  if (is_null($this->_multi)) {
326
+ return $this;
327
  }
328
 
329
  do {
330
+ do {
331
+ $res = curl_multi_exec($this->_multi, $running);
332
+ } while ($res === CURLM_CALL_MULTI_PERFORM);
333
+
334
+ if (!$running) {
335
+ break;
336
+ }
337
+
338
+ do {
339
+ $res = curl_multi_select($this->_multi);
340
+ } while ($res === 0);
341
+
342
+ if ($res === false) {
343
+ break;
344
  }
345
+ } while (true);
346
 
347
  foreach ($this->_children as $child) {
348
+ curl_multi_remove_handle($this->_multi, $child);
349
  }
350
 
351
  curl_multi_close($this->_multi);
361
  protected function _appendMulti($curl)
362
  {
363
  if (!is_resource($this->_multi)) {
364
+ return false;
365
  }
366
 
367
  $code = curl_multi_add_handle($this->_multi, $curl);
app/code/community/Copernica/MarketingSoftware/Model/Abandoned/Cart.php CHANGED
@@ -40,7 +40,7 @@ class Copernica_MarketingSoftware_Model_Abandoned_Cart extends Mage_Core_Model_A
40
  /**
41
  * Set quote Id
42
  *
43
- * @param int $quoteID
44
  */
45
  public function setQuoteId($quoteID)
46
  {
@@ -62,4 +62,4 @@ class Copernica_MarketingSoftware_Model_Abandoned_Cart extends Mage_Core_Model_A
62
  {
63
  return parent::getData('quote_id');
64
  }
65
- }
40
  /**
41
  * Set quote Id
42
  *
43
+ * @param int $quoteID
44
  */
45
  public function setQuoteId($quoteID)
46
  {
62
  {
63
  return parent::getData('quote_id');
64
  }
65
+ }
app/code/community/Copernica/MarketingSoftware/Model/Abandoned/Carts/Processor.php CHANGED
@@ -34,7 +34,7 @@ class Copernica_MarketingSoftware_Model_Abandoned_Carts_Processor
34
  /**
35
  * Check if we did already marked
36
  *
37
- * @param array $quoteCollection
38
  * @return boolean
39
  */
40
  protected function _filterNotMarked($quoteCollection)
@@ -42,7 +42,7 @@ class Copernica_MarketingSoftware_Model_Abandoned_Carts_Processor
42
  $quotesIds = array();
43
 
44
  foreach ($quoteCollection as $quote) {
45
- $quotesIds[] = $quote->getId();
46
  }
47
 
48
  $markedQuotesIds = Mage::getModel('marketingsoftware/abandoned_cart')->getCollection()->addFieldToFilter('quote_id', array('in' => $quotesIds));
@@ -50,14 +50,14 @@ class Copernica_MarketingSoftware_Model_Abandoned_Carts_Processor
50
  $markedArray = array();
51
 
52
  foreach ($markedQuotesIds as $abandonedCart) {
53
- $markedArray[] = $abandonedCart->getQuoteId();
54
  }
55
 
56
  $notMarkedQuotes = array();
57
 
58
  foreach ($quoteCollection as $quote) {
59
  if (in_array($quote->getId(), $markedArray)) {
60
- continue;
61
  }
62
 
63
  $notMarkedQuotes[] = $quote;
@@ -78,7 +78,7 @@ class Copernica_MarketingSoftware_Model_Abandoned_Carts_Processor
78
  $storeIds = $config->getEnabledStores();
79
 
80
  if (!is_array($storeIds)) {
81
- $storeIds = array();
82
  }
83
 
84
  $timeoutLimit = new DateTime();
34
  /**
35
  * Check if we did already marked
36
  *
37
+ * @param array $quoteCollection
38
  * @return boolean
39
  */
40
  protected function _filterNotMarked($quoteCollection)
42
  $quotesIds = array();
43
 
44
  foreach ($quoteCollection as $quote) {
45
+ $quotesIds[] = $quote->getId();
46
  }
47
 
48
  $markedQuotesIds = Mage::getModel('marketingsoftware/abandoned_cart')->getCollection()->addFieldToFilter('quote_id', array('in' => $quotesIds));
50
  $markedArray = array();
51
 
52
  foreach ($markedQuotesIds as $abandonedCart) {
53
+ $markedArray[] = $abandonedCart->getQuoteId();
54
  }
55
 
56
  $notMarkedQuotes = array();
57
 
58
  foreach ($quoteCollection as $quote) {
59
  if (in_array($quote->getId(), $markedArray)) {
60
+ continue;
61
  }
62
 
63
  $notMarkedQuotes[] = $quote;
78
  $storeIds = $config->getEnabledStores();
79
 
80
  if (!is_array($storeIds)) {
81
+ $storeIds = array();
82
  }
83
 
84
  $timeoutLimit = new DateTime();
app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Address.php CHANGED
@@ -32,8 +32,8 @@ class Copernica_MarketingSoftware_Model_Abstraction_Address implements Serializa
32
  /**
33
  * The original object
34
  *
35
- * @todo Not used???
36
- * @var Mage_Sales_Model_Order_Address|Mage_Sales_Model_Quote_Address|Mage_Customer_Model_Address
37
  */
38
  protected $_original;
39
 
@@ -57,8 +57,8 @@ class Copernica_MarketingSoftware_Model_Abstraction_Address implements Serializa
57
  /**
58
  * Sets the original model
59
  *
60
- * @param Mage_Sales_Model_Order_Address|Mage_Sales_Model_Quote_Address|Mage_Customer_Model_Address $original
61
- * @return Copernica_MarketingSoftware_Model_Abstraction_Address
62
  */
63
  public function setOriginal($original)
64
  {
@@ -135,7 +135,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Address implements Serializa
135
  /**
136
  * Return the type of this address
137
  *
138
- * @return array
139
  */
140
  public function type()
141
  {
@@ -145,7 +145,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Address implements Serializa
145
  /**
146
  * The customer may return null
147
  *
148
- * @return Copernica_MarketingSoftware_Model_Abstraction_Customer|null
149
  */
150
  public function customer()
151
  {
@@ -170,7 +170,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Address implements Serializa
170
  /**
171
  * Return the name belonging to this address
172
  *
173
- * @return Copernica_MarketingSoftware_Model_Abstraction_Name
174
  */
175
  public function name()
176
  {
@@ -180,7 +180,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Address implements Serializa
180
  /**
181
  * Return the e-mail address of this address
182
  *
183
- * @return string
184
  */
185
  public function email()
186
  {
@@ -190,7 +190,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Address implements Serializa
190
  /**
191
  * Return the street of this addresses
192
  *
193
- * @return string
194
  */
195
  public function street()
196
  {
@@ -200,7 +200,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Address implements Serializa
200
  /**
201
  * Get the city of this addresses
202
  *
203
- * @return string
204
  */
205
  public function city()
206
  {
@@ -210,7 +210,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Address implements Serializa
210
  /**
211
  * Get the zipcode of this addresses
212
  *
213
- * @return string
214
  */
215
  public function zipcode()
216
  {
@@ -220,7 +220,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Address implements Serializa
220
  /**
221
  * Get the state of this addresses
222
  *
223
- * @return string
224
  */
225
  public function state()
226
  {
@@ -230,7 +230,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Address implements Serializa
230
  /**
231
  * Get the country id of this addresses
232
  *
233
- * @return string
234
  */
235
  public function countryId()
236
  {
@@ -240,7 +240,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Address implements Serializa
240
  /**
241
  * Get the telephone number of this addresses
242
  *
243
- * @return string
244
  */
245
  public function telephone()
246
  {
@@ -250,7 +250,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Address implements Serializa
250
  /**
251
  * Get the fax number of this addresses
252
  *
253
- * @return string
254
  */
255
  public function fax()
256
  {
@@ -260,7 +260,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Address implements Serializa
260
  /**
261
  * Get the company of this address
262
  *
263
- * @return string
264
  */
265
  public function company()
266
  {
@@ -270,11 +270,12 @@ class Copernica_MarketingSoftware_Model_Abstraction_Address implements Serializa
270
  /**
271
  * Serialize the object
272
  *
273
- * @return string
274
  */
275
  public function serialize()
276
  {
277
- return serialize(array(
 
278
  $this->id(),
279
  $this->type(),
280
  $this->name(),
@@ -288,14 +289,15 @@ class Copernica_MarketingSoftware_Model_Abstraction_Address implements Serializa
288
  $this->fax(),
289
  $this->company(),
290
  is_object($customer = $this->customer()) ? $customer->id() : null,
291
- ));
 
292
  }
293
 
294
  /**
295
  * Unserialize the object
296
  *
297
- * @param string $string
298
- * @return Copernica_MarketingSoftware_Model_Abstraction_Address
299
  */
300
  public function unserialize($string)
301
  {
@@ -317,4 +319,4 @@ class Copernica_MarketingSoftware_Model_Abstraction_Address implements Serializa
317
 
318
  return $this;
319
  }
320
- }
32
  /**
33
  * The original object
34
  *
35
+ * @todo Not used???
36
+ * @var Mage_Sales_Model_Order_Address|Mage_Sales_Model_Quote_Address|Mage_Customer_Model_Address
37
  */
38
  protected $_original;
39
 
57
  /**
58
  * Sets the original model
59
  *
60
+ * @param Mage_Sales_Model_Order_Address|Mage_Sales_Model_Quote_Address|Mage_Customer_Model_Address $original
61
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Address
62
  */
63
  public function setOriginal($original)
64
  {
135
  /**
136
  * Return the type of this address
137
  *
138
+ * @return array
139
  */
140
  public function type()
141
  {
145
  /**
146
  * The customer may return null
147
  *
148
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Customer|null
149
  */
150
  public function customer()
151
  {
170
  /**
171
  * Return the name belonging to this address
172
  *
173
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Name
174
  */
175
  public function name()
176
  {
180
  /**
181
  * Return the e-mail address of this address
182
  *
183
+ * @return string
184
  */
185
  public function email()
186
  {
190
  /**
191
  * Return the street of this addresses
192
  *
193
+ * @return string
194
  */
195
  public function street()
196
  {
200
  /**
201
  * Get the city of this addresses
202
  *
203
+ * @return string
204
  */
205
  public function city()
206
  {
210
  /**
211
  * Get the zipcode of this addresses
212
  *
213
+ * @return string
214
  */
215
  public function zipcode()
216
  {
220
  /**
221
  * Get the state of this addresses
222
  *
223
+ * @return string
224
  */
225
  public function state()
226
  {
230
  /**
231
  * Get the country id of this addresses
232
  *
233
+ * @return string
234
  */
235
  public function countryId()
236
  {
240
  /**
241
  * Get the telephone number of this addresses
242
  *
243
+ * @return string
244
  */
245
  public function telephone()
246
  {
250
  /**
251
  * Get the fax number of this addresses
252
  *
253
+ * @return string
254
  */
255
  public function fax()
256
  {
260
  /**
261
  * Get the company of this address
262
  *
263
+ * @return string
264
  */
265
  public function company()
266
  {
270
  /**
271
  * Serialize the object
272
  *
273
+ * @return string
274
  */
275
  public function serialize()
276
  {
277
+ return serialize(
278
+ array(
279
  $this->id(),
280
  $this->type(),
281
  $this->name(),
289
  $this->fax(),
290
  $this->company(),
291
  is_object($customer = $this->customer()) ? $customer->id() : null,
292
+ )
293
+ );
294
  }
295
 
296
  /**
297
  * Unserialize the object
298
  *
299
+ * @param string $string
300
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Address
301
  */
302
  public function unserialize($string)
303
  {
319
 
320
  return $this;
321
  }
322
+ }
app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Attributes.php CHANGED
@@ -38,8 +38,8 @@ class Copernica_MarketingSoftware_Model_Abstraction_Attributes implements Serial
38
  /**
39
  * Sets the original model
40
  *
41
- * @param Mage_Catalog_Model_Product $original
42
- * @return Copernica_MarketingSoftware_Model_Abstraction_Attributes
43
  */
44
  public function setOriginal(Mage_Catalog_Model_Product $original)
45
  {
@@ -53,7 +53,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Attributes implements Serial
53
 
54
  foreach ($attributes as $attribute) {
55
  if (
56
- $attribute->getIsUserDefined() &&
57
  in_array($attribute->getFrontendInput(), array('text', 'select', 'multiline', 'textarea', 'price', 'date', 'multiselect')) &&
58
  ($label = $attribute->getAttributeCode()) &&
59
  ($value = $attribute->getFrontend()->getValue($original))
@@ -70,7 +70,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Attributes implements Serial
70
  /**
71
  * The name of this product
72
  *
73
- * @return integer
74
  */
75
  public function name()
76
  {
@@ -80,8 +80,8 @@ class Copernica_MarketingSoftware_Model_Abstraction_Attributes implements Serial
80
  /**
81
  * Return an assoc array with attributes.
82
  *
83
- * @param Bool $useAttribcode
84
- * @return array
85
  */
86
  public function attributes($useAttribCode = false)
87
  {
@@ -91,14 +91,14 @@ class Copernica_MarketingSoftware_Model_Abstraction_Attributes implements Serial
91
  /**
92
  * Return a string representation
93
  *
94
- * @return string
95
  */
96
  public function __toString()
97
  {
98
  $options = "";
99
 
100
  foreach ($this->attributes() as $key => $value) {
101
- $options .= "$key: $value\n";
102
  }
103
 
104
  return $options;
@@ -107,21 +107,23 @@ class Copernica_MarketingSoftware_Model_Abstraction_Attributes implements Serial
107
  /**
108
  * Serialize the object
109
  *
110
- * @return string
111
  */
112
  public function serialize()
113
  {
114
- return serialize(array(
 
115
  $this->name(),
116
  $this->attributes(),
117
- ));
 
118
  }
119
 
120
  /**
121
  * Unserialize the object
122
  *
123
- * @param string $string
124
- * @return Copernica_MarketingSoftware_Model_Abstraction_Attributes
125
  */
126
  public function unserialize($string)
127
  {
38
  /**
39
  * Sets the original model
40
  *
41
+ * @param Mage_Catalog_Model_Product $original
42
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Attributes
43
  */
44
  public function setOriginal(Mage_Catalog_Model_Product $original)
45
  {
53
 
54
  foreach ($attributes as $attribute) {
55
  if (
56
+ $attribute->getIsUserDefined() &&
57
  in_array($attribute->getFrontendInput(), array('text', 'select', 'multiline', 'textarea', 'price', 'date', 'multiselect')) &&
58
  ($label = $attribute->getAttributeCode()) &&
59
  ($value = $attribute->getFrontend()->getValue($original))
70
  /**
71
  * The name of this product
72
  *
73
+ * @return integer
74
  */
75
  public function name()
76
  {
80
  /**
81
  * Return an assoc array with attributes.
82
  *
83
+ * @param Bool $useAttribcode
84
+ * @return array
85
  */
86
  public function attributes($useAttribCode = false)
87
  {
91
  /**
92
  * Return a string representation
93
  *
94
+ * @return string
95
  */
96
  public function __toString()
97
  {
98
  $options = "";
99
 
100
  foreach ($this->attributes() as $key => $value) {
101
+ $options .= "$key: $value\n";
102
  }
103
 
104
  return $options;
107
  /**
108
  * Serialize the object
109
  *
110
+ * @return string
111
  */
112
  public function serialize()
113
  {
114
+ return serialize(
115
+ array(
116
  $this->name(),
117
  $this->attributes(),
118
+ )
119
+ );
120
  }
121
 
122
  /**
123
  * Unserialize the object
124
  *
125
+ * @param string $string
126
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Attributes
127
  */
128
  public function unserialize($string)
129
  {
app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Customer.php CHANGED
@@ -33,22 +33,22 @@ class Copernica_MarketingSoftware_Model_Abstraction_Customer implements Serializ
33
  /**
34
  * The id
35
  *
36
- * @var int
37
  */
38
  protected $_id;
39
 
40
  /**
41
  * The original object
42
  *
43
- * @var Mage_Customer_Model_Customer
44
  */
45
  protected $_original;
46
 
47
  /**
48
  * Sets the original model
49
  *
50
- * @param Mage_Customer_Model_Customer $original
51
- * @return Copernica_MarketingSoftware_Model_Abstraction_Customer
52
  */
53
  public function setOriginal(Mage_Customer_Model_Customer $original)
54
  {
@@ -61,7 +61,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Customer implements Serializ
61
  /**
62
  * Returns the original model
63
  *
64
- * @return Mage_Customer_Model_Customer
65
  */
66
  protected function _original()
67
  {
@@ -71,7 +71,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Customer implements Serializ
71
  /**
72
  * Loads a customer model
73
  *
74
- * @param int $customerId
75
  * @return Copernica_MarketingSoftware_Model_Abstraction_Customer
76
  */
77
  public function loadCustomer($customerId)
@@ -79,7 +79,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Customer implements Serializ
79
  $customer = Mage::getModel('customer/customer')->load($customerId);
80
 
81
  if ($customer->getId()) {
82
- $this->setOriginal($customer);
83
  }
84
 
85
  return $this;
@@ -88,12 +88,12 @@ class Copernica_MarketingSoftware_Model_Abstraction_Customer implements Serializ
88
  /**
89
  * Return the id of the customer
90
  *
91
- * @return string
92
  */
93
  public function id()
94
  {
95
  if (!$this->_original()) {
96
- return null;
97
  }
98
 
99
  return $this->_original()->getId();
@@ -103,7 +103,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Customer implements Serializ
103
  * Return the name of this customer
104
  * Note that null may also be returned to indicate that the name is not known
105
  *
106
- * @return Copernica_MarketingSoftware_Model_Abstraction_Name
107
  */
108
  public function name()
109
  {
@@ -113,7 +113,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Customer implements Serializ
113
  /**
114
  * Return the e-mail address of the customer
115
  *
116
- * @return string
117
  */
118
  public function email()
119
  {
@@ -123,7 +123,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Customer implements Serializ
123
  /**
124
  * Return a customer's date of birth
125
  *
126
- * @return string
127
  */
128
  public function birthDate()
129
  {
@@ -134,14 +134,14 @@ class Copernica_MarketingSoftware_Model_Abstraction_Customer implements Serializ
134
  * Method to retrieve the previous email if possible
135
  * Falls back on self::email()
136
  *
137
- * @return string
138
  */
139
  public function oldEmail()
140
  {
141
  $oldEmail = $this->_original()->getOrigData('email');
142
 
143
  if (isset($oldEmail)) {
144
- return $oldEmail;
145
  }
146
 
147
  return $this->email();
@@ -150,7 +150,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Customer implements Serializ
150
  /**
151
  * Returns the gender
152
  *
153
- * @return string
154
  */
155
  public function gender()
156
  {
@@ -170,18 +170,18 @@ class Copernica_MarketingSoftware_Model_Abstraction_Customer implements Serializ
170
  /**
171
  * Return the subscription of the customer
172
  *
173
- * @return Copernica_MarketingSoftware_Model_Abstraction_Subscription
174
  */
175
  public function subscription()
176
  {
177
  $subscriber = Mage::getModel('newsletter/subscriber');
178
 
179
  if (!$subscriber->loadByCustomer($this->_original())->getId()) {
180
- return null;
181
  }
182
 
183
  if ($subscriber->getStoreId() !== $this->_original()->getStoreId()) {
184
- return null;
185
  }
186
 
187
  return Mage::getModel('marketingsoftware/abstraction_subscription')->setOriginal($subscriber);
@@ -190,7 +190,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Customer implements Serializ
190
  /**
191
  * Return the group to which this customer belongs
192
  *
193
- * @return string
194
  */
195
  public function group()
196
  {
@@ -200,7 +200,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Customer implements Serializ
200
  /**
201
  * Get the quotes for this customer
202
  *
203
- * @return array
204
  */
205
  public function quotes()
206
  {
@@ -210,7 +210,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Customer implements Serializ
210
  ->addFieldToFilter('customer_id', $this->id())->getAllIds();
211
 
212
  foreach ($quoteIds as $id) {
213
- $data[] = Mage::getModel('marketingsoftware/abstraction_quote')->loadQuote($id);
214
  }
215
 
216
  return $data;
@@ -229,7 +229,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Customer implements Serializ
229
  ->addAttributeToFilter('customer_id', $this->id())->getAllIds();
230
 
231
  foreach ($orderIds as $id) {
232
- $data[] = Mage::getModel('marketingsoftware/abstraction_order')->loadOrder($id);
233
  }
234
 
235
  return $data;
@@ -242,16 +242,16 @@ class Copernica_MarketingSoftware_Model_Abstraction_Customer implements Serializ
242
  */
243
  public function wishlist()
244
  {
245
- $data = array();
246
 
247
- $wishlistIds = Mage::getResourceModel('wishlist/wishlist_collection')
248
- ->addAttributeToFilter('customer_id', $this->id())->getAllIds();
249
 
250
- foreach ($wishlistIds as $id) {
251
- $data[] = Mage::getModel('marketingsoftware/abstraction_wishlist')->loadWishlist($id);
252
- }
253
 
254
- return $data;
255
  }
256
 
257
  /**
@@ -275,7 +275,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Customer implements Serializ
275
  /**
276
  * To what storeview does this order belong
277
  *
278
- * @return Copernica_MarketingSoftware_Model_Abstraction_Storeview
279
  */
280
  public function storeview()
281
  {
@@ -285,7 +285,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Customer implements Serializ
285
  /**
286
  * Serialize the object
287
  *
288
- * @return string
289
  */
290
  public function serialize()
291
  {
@@ -295,8 +295,8 @@ class Copernica_MarketingSoftware_Model_Abstraction_Customer implements Serializ
295
  /**
296
  * Unserialize the object
297
  *
298
- * @param string $string
299
- * @return Copernica_MarketingSoftware_Model_Abstraction_Customer
300
  */
301
  public function unserialize($string)
302
  {
33
  /**
34
  * The id
35
  *
36
+ * @var int
37
  */
38
  protected $_id;
39
 
40
  /**
41
  * The original object
42
  *
43
+ * @var Mage_Customer_Model_Customer
44
  */
45
  protected $_original;
46
 
47
  /**
48
  * Sets the original model
49
  *
50
+ * @param Mage_Customer_Model_Customer $original
51
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Customer
52
  */
53
  public function setOriginal(Mage_Customer_Model_Customer $original)
54
  {
61
  /**
62
  * Returns the original model
63
  *
64
+ * @return Mage_Customer_Model_Customer
65
  */
66
  protected function _original()
67
  {
71
  /**
72
  * Loads a customer model
73
  *
74
+ * @param int $customerId
75
  * @return Copernica_MarketingSoftware_Model_Abstraction_Customer
76
  */
77
  public function loadCustomer($customerId)
79
  $customer = Mage::getModel('customer/customer')->load($customerId);
80
 
81
  if ($customer->getId()) {
82
+ $this->setOriginal($customer);
83
  }
84
 
85
  return $this;
88
  /**
89
  * Return the id of the customer
90
  *
91
+ * @return string
92
  */
93
  public function id()
94
  {
95
  if (!$this->_original()) {
96
+ return null;
97
  }
98
 
99
  return $this->_original()->getId();
103
  * Return the name of this customer
104
  * Note that null may also be returned to indicate that the name is not known
105
  *
106
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Name
107
  */
108
  public function name()
109
  {
113
  /**
114
  * Return the e-mail address of the customer
115
  *
116
+ * @return string
117
  */
118
  public function email()
119
  {
123
  /**
124
  * Return a customer's date of birth
125
  *
126
+ * @return string
127
  */
128
  public function birthDate()
129
  {
134
  * Method to retrieve the previous email if possible
135
  * Falls back on self::email()
136
  *
137
+ * @return string
138
  */
139
  public function oldEmail()
140
  {
141
  $oldEmail = $this->_original()->getOrigData('email');
142
 
143
  if (isset($oldEmail)) {
144
+ return $oldEmail;
145
  }
146
 
147
  return $this->email();
150
  /**
151
  * Returns the gender
152
  *
153
+ * @return string
154
  */
155
  public function gender()
156
  {
170
  /**
171
  * Return the subscription of the customer
172
  *
173
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Subscription
174
  */
175
  public function subscription()
176
  {
177
  $subscriber = Mage::getModel('newsletter/subscriber');
178
 
179
  if (!$subscriber->loadByCustomer($this->_original())->getId()) {
180
+ return null;
181
  }
182
 
183
  if ($subscriber->getStoreId() !== $this->_original()->getStoreId()) {
184
+ return null;
185
  }
186
 
187
  return Mage::getModel('marketingsoftware/abstraction_subscription')->setOriginal($subscriber);
190
  /**
191
  * Return the group to which this customer belongs
192
  *
193
+ * @return string
194
  */
195
  public function group()
196
  {
200
  /**
201
  * Get the quotes for this customer
202
  *
203
+ * @return array
204
  */
205
  public function quotes()
206
  {
210
  ->addFieldToFilter('customer_id', $this->id())->getAllIds();
211
 
212
  foreach ($quoteIds as $id) {
213
+ $data[] = Mage::getModel('marketingsoftware/abstraction_quote')->loadQuote($id);
214
  }
215
 
216
  return $data;
229
  ->addAttributeToFilter('customer_id', $this->id())->getAllIds();
230
 
231
  foreach ($orderIds as $id) {
232
+ $data[] = Mage::getModel('marketingsoftware/abstraction_order')->loadOrder($id);
233
  }
234
 
235
  return $data;
242
  */
243
  public function wishlist()
244
  {
245
+ $data = array();
246
 
247
+ $wishlistIds = Mage::getResourceModel('wishlist/wishlist_collection')
248
+ ->addAttributeToFilter('customer_id', $this->id())->getAllIds();
249
 
250
+ foreach ($wishlistIds as $id) {
251
+ $data[] = Mage::getModel('marketingsoftware/abstraction_wishlist')->loadWishlist($id);
252
+ }
253
 
254
+ return $data;
255
  }
256
 
257
  /**
275
  /**
276
  * To what storeview does this order belong
277
  *
278
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Storeview
279
  */
280
  public function storeview()
281
  {
285
  /**
286
  * Serialize the object
287
  *
288
+ * @return string
289
  */
290
  public function serialize()
291
  {
295
  /**
296
  * Unserialize the object
297
  *
298
+ * @param string $string
299
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Customer
300
  */
301
  public function unserialize($string)
302
  {
app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Name.php CHANGED
@@ -40,8 +40,8 @@ class Copernica_MarketingSoftware_Model_Abstraction_Name implements Serializable
40
  /**
41
  * Sets the original model
42
  *
43
- * @param Mage_Customer_Model_Customer|Mage_Customer_Model_Customer_Address|Mage_Sales_Model_Order_Address|Mage_Sales_Model_Quote_Address|Mage_Customer_Model_Address
44
- * @return Copernica_MarketingSoftware_Model_Abstraction_Name
45
  */
46
  public function setOriginal($original)
47
  {
@@ -56,7 +56,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Name implements Serializable
56
  /**
57
  * Return the firstname of the customer
58
  *
59
- * @return string
60
  */
61
  public function firstname()
62
  {
@@ -67,7 +67,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Name implements Serializable
67
  * Return the prefix of the customer
68
  * NOTE: the prefix field is not displayed by default
69
  *
70
- * @return string
71
  */
72
  public function prefix()
73
  {
@@ -78,7 +78,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Name implements Serializable
78
  * Return the middlename of the customer
79
  * NOTE: the middlename field is not displayed by default
80
  *
81
- * @return string
82
  */
83
  public function middlename()
84
  {
@@ -88,7 +88,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Name implements Serializable
88
  /**
89
  * Return the lastname of the customer
90
  *
91
- * @return string
92
  */
93
  public function lastname()
94
  {
@@ -98,23 +98,25 @@ class Copernica_MarketingSoftware_Model_Abstraction_Name implements Serializable
98
  /**
99
  * Serialize the object
100
  *
101
- * @return string
102
  */
103
  public function serialize()
104
  {
105
- return serialize(array(
 
106
  $this->firstname(),
107
  $this->prefix(),
108
  $this->middlename(),
109
  $this->lastname(),
110
- ));
 
111
  }
112
 
113
  /**
114
  * Unserialize the object
115
  *
116
- * @param string $string
117
- * @return Copernica_MarketingSoftware_Model_Abstraction_Name
118
  */
119
  public function unserialize($string)
120
  {
40
  /**
41
  * Sets the original model
42
  *
43
+ * @param Mage_Customer_Model_Customer|Mage_Customer_Model_Customer_Address|Mage_Sales_Model_Order_Address|Mage_Sales_Model_Quote_Address|Mage_Customer_Model_Address
44
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Name
45
  */
46
  public function setOriginal($original)
47
  {
56
  /**
57
  * Return the firstname of the customer
58
  *
59
+ * @return string
60
  */
61
  public function firstname()
62
  {
67
  * Return the prefix of the customer
68
  * NOTE: the prefix field is not displayed by default
69
  *
70
+ * @return string
71
  */
72
  public function prefix()
73
  {
78
  * Return the middlename of the customer
79
  * NOTE: the middlename field is not displayed by default
80
  *
81
+ * @return string
82
  */
83
  public function middlename()
84
  {
88
  /**
89
  * Return the lastname of the customer
90
  *
91
+ * @return string
92
  */
93
  public function lastname()
94
  {
98
  /**
99
  * Serialize the object
100
  *
101
+ * @return string
102
  */
103
  public function serialize()
104
  {
105
+ return serialize(
106
+ array(
107
  $this->firstname(),
108
  $this->prefix(),
109
  $this->middlename(),
110
  $this->lastname(),
111
+ )
112
+ );
113
  }
114
 
115
  /**
116
  * Unserialize the object
117
  *
118
+ * @param string $string
119
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Name
120
  */
121
  public function unserialize($string)
122
  {
app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Order.php CHANGED
@@ -34,7 +34,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order implements Serializabl
34
  * payment name from a quote shipping address. Since this is an order
35
  * a quote is no longer available.
36
  *
37
- * @var string
38
  */
39
  const PAYMENT_METHOD_KLARNA = 'klarna_partpayment';
40
 
@@ -53,7 +53,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order implements Serializabl
53
  /**
54
  * The storeview object
55
  *
56
- * @var Copernica_MarketingSoftware_Model_Abstraction_Storeview
57
  */
58
  protected $_storeview;
59
 
@@ -69,8 +69,8 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order implements Serializabl
69
  /**
70
  * Sets the original model
71
  *
72
- * @param Mage_Sales_Model_Order $original
73
- * @return Copernica_MarketingSoftware_Model_Abstraction_Order
74
  */
75
  public function setOriginal(Mage_Sales_Model_Order $original)
76
  {
@@ -83,8 +83,8 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order implements Serializabl
83
  /**
84
  * This method will set the state of this order from original magento order
85
  *
86
- * @param Mage_Sales_Model_Order $original
87
- * @return Copernica_MarketingSoftware_Model_Abstraction_Order
88
  */
89
  public function importFromOriginal(Mage_Sales_Model_Order $original)
90
  {
@@ -133,7 +133,9 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order implements Serializabl
133
  } else {
134
  $this->_paymentDescription = $payment->getMethodInstance()->getTitle();
135
  }
136
- } catch (Mage_Core_Exception $exception) { }
 
 
137
  }
138
 
139
  return $this;
@@ -142,8 +144,8 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order implements Serializabl
142
  /**
143
  * Loads an order model
144
  *
145
- * @param integer $orderId
146
- * @return Copernica_MarketingSoftware_Model_Abstraction_Order
147
  */
148
  public function loadOrder($orderId)
149
  {
@@ -159,7 +161,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order implements Serializabl
159
  /**
160
  * The id of this order object
161
  *
162
- * @return integer
163
  */
164
  public function id()
165
  {
@@ -169,7 +171,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order implements Serializabl
169
  /**
170
  * The increment (longer) id of this order object
171
  *
172
- * @return integer
173
  */
174
  public function incrementId()
175
  {
@@ -179,7 +181,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order implements Serializabl
179
  /**
180
  * The quote id of this order object
181
  *
182
- * @return integer
183
  */
184
  public function quoteId()
185
  {
@@ -189,7 +191,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order implements Serializabl
189
  /**
190
  * The state of this order
191
  *
192
- * @return string
193
  */
194
  public function state()
195
  {
@@ -199,7 +201,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order implements Serializabl
199
  /**
200
  * The status of this order
201
  *
202
- * @return string
203
  */
204
  public function status()
205
  {
@@ -209,7 +211,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order implements Serializabl
209
  /**
210
  * The number of items present in this order
211
  *
212
- * @return integer
213
  */
214
  public function quantity()
215
  {
@@ -219,7 +221,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order implements Serializabl
219
  /**
220
  * The number of items present in this order
221
  *
222
- * @return integer
223
  */
224
  public function currency()
225
  {
@@ -230,7 +232,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order implements Serializabl
230
  * The price
231
  * Note that an object is returned, which may consist of multiple components
232
  *
233
- * @return Copernica_MarketingSoftware_Model_Abstraction_Price
234
  */
235
  public function price()
236
  {
@@ -240,7 +242,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order implements Serializabl
240
  /**
241
  * The weight
242
  *
243
- * @return float
244
  */
245
  public function weight()
246
  {
@@ -250,7 +252,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order implements Serializabl
250
  /**
251
  * To what storeview does this order belong
252
  *
253
- * @return Copernica_MarketingSoftware_Model_Abstraction_Storeview
254
  */
255
  public function storeview()
256
  {
@@ -260,7 +262,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order implements Serializabl
260
  /**
261
  * Get the items from the order
262
  *
263
- * @return array
264
  */
265
  public function items()
266
  {
@@ -270,7 +272,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order implements Serializabl
270
  /**
271
  * The timestamp at which this order was modified
272
  *
273
- * @return string
274
  */
275
  public function timestamp()
276
  {
@@ -280,7 +282,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order implements Serializabl
280
  /**
281
  * The customer may return null
282
  *
283
- * @return Copernica_MarketingSoftware_Model_Abstraction_Customer|null
284
  */
285
  public function customer()
286
  {
@@ -294,7 +296,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order implements Serializabl
294
  /**
295
  * The addresses of the order
296
  *
297
- * @return array of Copernica_MarketingSoftware_Model_Abstraction_Address
298
  */
299
  public function addresses()
300
  {
@@ -304,7 +306,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order implements Serializabl
304
  /**
305
  * The shipping method of the order
306
  *
307
- * @return string
308
  */
309
  public function shippingDescription()
310
  {
@@ -314,7 +316,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order implements Serializabl
314
  /**
315
  * The payment method of the order
316
  *
317
- * @return string
318
  */
319
  public function paymentDescription()
320
  {
@@ -324,7 +326,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order implements Serializabl
324
  /**
325
  * The IP from which this order was constructed
326
  *
327
- * @return string
328
  */
329
  public function customerIP()
330
  {
@@ -334,7 +336,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order implements Serializabl
334
  /**
335
  * Serialize the object
336
  *
337
- * @return string
338
  */
339
  public function serialize()
340
  {
@@ -344,8 +346,8 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order implements Serializabl
344
  /**
345
  * Unserialize the object
346
  *
347
- * @param string $string
348
- * @return Copernica_MarketingSoftware_Model_Abstraction_Order
349
  */
350
  public function unserialize($string)
351
  {
34
  * payment name from a quote shipping address. Since this is an order
35
  * a quote is no longer available.
36
  *
37
+ * @var string
38
  */
39
  const PAYMENT_METHOD_KLARNA = 'klarna_partpayment';
40
 
53
  /**
54
  * The storeview object
55
  *
56
+ * @var Copernica_MarketingSoftware_Model_Abstraction_Storeview
57
  */
58
  protected $_storeview;
59
 
69
  /**
70
  * Sets the original model
71
  *
72
+ * @param Mage_Sales_Model_Order $original
73
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Order
74
  */
75
  public function setOriginal(Mage_Sales_Model_Order $original)
76
  {
83
  /**
84
  * This method will set the state of this order from original magento order
85
  *
86
+ * @param Mage_Sales_Model_Order $original
87
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Order
88
  */
89
  public function importFromOriginal(Mage_Sales_Model_Order $original)
90
  {
133
  } else {
134
  $this->_paymentDescription = $payment->getMethodInstance()->getTitle();
135
  }
136
+ } catch (Mage_Core_Exception $exception) {
137
+ Mage::logException($exception);
138
+ }
139
  }
140
 
141
  return $this;
144
  /**
145
  * Loads an order model
146
  *
147
+ * @param integer $orderId
148
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Order
149
  */
150
  public function loadOrder($orderId)
151
  {
161
  /**
162
  * The id of this order object
163
  *
164
+ * @return integer
165
  */
166
  public function id()
167
  {
171
  /**
172
  * The increment (longer) id of this order object
173
  *
174
+ * @return integer
175
  */
176
  public function incrementId()
177
  {
181
  /**
182
  * The quote id of this order object
183
  *
184
+ * @return integer
185
  */
186
  public function quoteId()
187
  {
191
  /**
192
  * The state of this order
193
  *
194
+ * @return string
195
  */
196
  public function state()
197
  {
201
  /**
202
  * The status of this order
203
  *
204
+ * @return string
205
  */
206
  public function status()
207
  {
211
  /**
212
  * The number of items present in this order
213
  *
214
+ * @return integer
215
  */
216
  public function quantity()
217
  {
221
  /**
222
  * The number of items present in this order
223
  *
224
+ * @return integer
225
  */
226
  public function currency()
227
  {
232
  * The price
233
  * Note that an object is returned, which may consist of multiple components
234
  *
235
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Price
236
  */
237
  public function price()
238
  {
242
  /**
243
  * The weight
244
  *
245
+ * @return float
246
  */
247
  public function weight()
248
  {
252
  /**
253
  * To what storeview does this order belong
254
  *
255
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Storeview
256
  */
257
  public function storeview()
258
  {
262
  /**
263
  * Get the items from the order
264
  *
265
+ * @return array
266
  */
267
  public function items()
268
  {
272
  /**
273
  * The timestamp at which this order was modified
274
  *
275
+ * @return string
276
  */
277
  public function timestamp()
278
  {
282
  /**
283
  * The customer may return null
284
  *
285
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Customer|null
286
  */
287
  public function customer()
288
  {
296
  /**
297
  * The addresses of the order
298
  *
299
+ * @return array of Copernica_MarketingSoftware_Model_Abstraction_Address
300
  */
301
  public function addresses()
302
  {
306
  /**
307
  * The shipping method of the order
308
  *
309
+ * @return string
310
  */
311
  public function shippingDescription()
312
  {
316
  /**
317
  * The payment method of the order
318
  *
319
+ * @return string
320
  */
321
  public function paymentDescription()
322
  {
326
  /**
327
  * The IP from which this order was constructed
328
  *
329
+ * @return string
330
  */
331
  public function customerIP()
332
  {
336
  /**
337
  * Serialize the object
338
  *
339
+ * @return string
340
  */
341
  public function serialize()
342
  {
346
  /**
347
  * Unserialize the object
348
  *
349
+ * @param string $string
350
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Order
351
  */
352
  public function unserialize($string)
353
  {
app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Order/Item.php CHANGED
@@ -44,8 +44,8 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order_Item implements Serial
44
  /**
45
  * Sets the original model
46
  *
47
- * @param Mage_Sales_Model_Order_Item $original
48
- * @return Copernica_MarketingSoftware_Model_Abstraction_Order_Item
49
  */
50
  public function setOriginal(Mage_Sales_Model_Order_Item $original)
51
  {
@@ -69,7 +69,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order_Item implements Serial
69
  /**
70
  * The id of this order item object
71
  *
72
- * @return integer
73
  */
74
  public function id()
75
  {
@@ -79,7 +79,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order_Item implements Serial
79
  /**
80
  * Get the order to which this item belongs
81
  *
82
- * @return Copernica_MarketingSoftware_Model_Abstraction_Order
83
  */
84
  public function order()
85
  {
@@ -89,7 +89,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order_Item implements Serial
89
  /**
90
  * The amount of this order item
91
  *
92
- * @return integer
93
  */
94
  public function quantity()
95
  {
@@ -100,7 +100,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order_Item implements Serial
100
  * The price
101
  * Note that an object is returned, which may consist of multiple components
102
  *
103
- * @return Copernica_MarketingSoftware_Model_Abstraction_Price
104
  */
105
  public function price()
106
  {
@@ -110,7 +110,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order_Item implements Serial
110
  /**
111
  * The weight
112
  *
113
- * @return float
114
  */
115
  public function weight()
116
  {
@@ -120,7 +120,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order_Item implements Serial
120
  /**
121
  * The timestamp at which this order was modified
122
  *
123
- * @return string
124
  */
125
  public function timestamp()
126
  {
@@ -130,7 +130,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order_Item implements Serial
130
  /**
131
  * Get the options of this order item
132
  *
133
- * @return Copernica_MarketingSoftware_Model_Abstraction_Order_Item_Options
134
  */
135
  public function options()
136
  {
@@ -140,7 +140,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order_Item implements Serial
140
  /**
141
  * Get the product which belongs to this item
142
  *
143
- * @return Copernica_MarketingSoftware_Model_Abstraction_Product
144
  */
145
  public function product()
146
  {
@@ -150,11 +150,12 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order_Item implements Serial
150
  /**
151
  * Serialize the object
152
  *
153
- * @return string
154
  */
155
  public function serialize()
156
  {
157
- return serialize(array(
 
158
  $this->_id(),
159
  is_object($order = $this->order()) ? $order->id() : null,
160
  $this->_quantity(),
@@ -163,14 +164,15 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order_Item implements Serial
163
  $this->_timestamp(),
164
  $this->_options(),
165
  $this->_product(),
166
- ));
 
167
  }
168
 
169
  /**
170
  * Unserialize the object
171
  *
172
- * @param string $string
173
- * @return Copernica_MarketingSoftware_Model_Abstraction_Order_Item
174
  */
175
  public function unserialize($string)
176
  {
44
  /**
45
  * Sets the original model
46
  *
47
+ * @param Mage_Sales_Model_Order_Item $original
48
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Order_Item
49
  */
50
  public function setOriginal(Mage_Sales_Model_Order_Item $original)
51
  {
69
  /**
70
  * The id of this order item object
71
  *
72
+ * @return integer
73
  */
74
  public function id()
75
  {
79
  /**
80
  * Get the order to which this item belongs
81
  *
82
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Order
83
  */
84
  public function order()
85
  {
89
  /**
90
  * The amount of this order item
91
  *
92
+ * @return integer
93
  */
94
  public function quantity()
95
  {
100
  * The price
101
  * Note that an object is returned, which may consist of multiple components
102
  *
103
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Price
104
  */
105
  public function price()
106
  {
110
  /**
111
  * The weight
112
  *
113
+ * @return float
114
  */
115
  public function weight()
116
  {
120
  /**
121
  * The timestamp at which this order was modified
122
  *
123
+ * @return string
124
  */
125
  public function timestamp()
126
  {
130
  /**
131
  * Get the options of this order item
132
  *
133
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Order_Item_Options
134
  */
135
  public function options()
136
  {
140
  /**
141
  * Get the product which belongs to this item
142
  *
143
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Product
144
  */
145
  public function product()
146
  {
150
  /**
151
  * Serialize the object
152
  *
153
+ * @return string
154
  */
155
  public function serialize()
156
  {
157
+ return serialize(
158
+ array(
159
  $this->_id(),
160
  is_object($order = $this->order()) ? $order->id() : null,
161
  $this->_quantity(),
164
  $this->_timestamp(),
165
  $this->_options(),
166
  $this->_product(),
167
+ )
168
+ );
169
  }
170
 
171
  /**
172
  * Unserialize the object
173
  *
174
+ * @param string $string
175
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Order_Item
176
  */
177
  public function unserialize($string)
178
  {
app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Order/Item/Options.php CHANGED
@@ -39,8 +39,8 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order_Item_Options implement
39
  /**
40
  * Sets the original model
41
  *
42
- * @param Mage_Sales_Model_Order_Item $original
43
- * @return Copernica_MarketingSoftware_Model_Abstraction_Order_Item_Options
44
  */
45
  public function setOriginal(Mage_Sales_Model_Order_Item $original)
46
  {
@@ -72,7 +72,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order_Item_Options implement
72
  /**
73
  * The name of this order item
74
  *
75
- * @return integer
76
  */
77
  public function name()
78
  {
@@ -82,7 +82,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order_Item_Options implement
82
  /**
83
  * Return an assoc array with attributes
84
  *
85
- * @return array
86
  */
87
  public function attributes()
88
  {
@@ -102,8 +102,8 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order_Item_Options implement
102
  /**
103
  * Return a string representation of an array
104
  *
105
- * @param array $value
106
- * @param string $prefix
107
  * @return string
108
  */
109
  protected function _arrayToString($value, $prefix = '')
@@ -113,12 +113,12 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order_Item_Options implement
113
  foreach ($value as $key => $value) {
114
  if (is_array($value)) {
115
  if (isset($value[0]) && count($value) == 1) {
116
- $value = $value[0];
117
  }
118
 
119
  $string .= $prefix.$key.":\n".$this->_arrayToString($value, $prefix.' ');
120
  } else {
121
- $string.= $prefix.$key.": $value\n";
122
  }
123
  }
124
 
@@ -128,21 +128,23 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order_Item_Options implement
128
  /**
129
  * Serialize the object
130
  *
131
- * @return string
132
  */
133
  public function serialize()
134
  {
135
- return serialize(array(
 
136
  $this->_name(),
137
  $this->_attributes(),
138
- ));
 
139
  }
140
 
141
  /**
142
  * Unserialize the object
143
  *
144
- * @param string $string
145
- * @return Copernica_MarketingSoftware_Model_Abstraction_Order_Item_Options
146
  */
147
  public function unserialize($string)
148
  {
39
  /**
40
  * Sets the original model
41
  *
42
+ * @param Mage_Sales_Model_Order_Item $original
43
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Order_Item_Options
44
  */
45
  public function setOriginal(Mage_Sales_Model_Order_Item $original)
46
  {
72
  /**
73
  * The name of this order item
74
  *
75
+ * @return integer
76
  */
77
  public function name()
78
  {
82
  /**
83
  * Return an assoc array with attributes
84
  *
85
+ * @return array
86
  */
87
  public function attributes()
88
  {
102
  /**
103
  * Return a string representation of an array
104
  *
105
+ * @param array $value
106
+ * @param string $prefix
107
  * @return string
108
  */
109
  protected function _arrayToString($value, $prefix = '')
113
  foreach ($value as $key => $value) {
114
  if (is_array($value)) {
115
  if (isset($value[0]) && count($value) == 1) {
116
+ $value = $value[0];
117
  }
118
 
119
  $string .= $prefix.$key.":\n".$this->_arrayToString($value, $prefix.' ');
120
  } else {
121
+ $string.= $prefix.$key.": $value\n";
122
  }
123
  }
124
 
128
  /**
129
  * Serialize the object
130
  *
131
+ * @return string
132
  */
133
  public function serialize()
134
  {
135
+ return serialize(
136
+ array(
137
  $this->_name(),
138
  $this->_attributes(),
139
+ )
140
+ );
141
  }
142
 
143
  /**
144
  * Unserialize the object
145
  *
146
+ * @param string $string
147
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Order_Item_Options
148
  */
149
  public function unserialize($string)
150
  {
app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Price.php CHANGED
@@ -52,8 +52,8 @@ class Copernica_MarketingSoftware_Model_Abstraction_Price implements Serializabl
52
  /**
53
  * Sets the original model
54
  *
55
- * @param Mage_Sales_Model_Quote|Mage_Sales_Model_Order|Mage_Sales_Model_Quote_Item|Mage_Sales_Model_Order_Item $original
56
- * @return Copernica_MarketingSoftware_Model_Abstraction_Price
57
  */
58
  public function setOriginal($original)
59
  {
@@ -106,7 +106,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Price implements Serializabl
106
  $this->_shipping = 0;
107
  }
108
  } else {
109
- $this->_shipping = 0;
110
  }
111
 
112
  if ($currency = $original->getOrderCurrencyCode()) {
@@ -127,7 +127,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Price implements Serializabl
127
  /**
128
  * Return the total price
129
  *
130
- * @return float
131
  */
132
  public function total()
133
  {
@@ -137,7 +137,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Price implements Serializabl
137
  /**
138
  * Return the price for the individual item
139
  *
140
- * @return float
141
  */
142
  public function costs()
143
  {
@@ -147,7 +147,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Price implements Serializabl
147
  /**
148
  * Return the price for the individual item
149
  *
150
- * @return float
151
  */
152
  public function itemPrice()
153
  {
@@ -157,7 +157,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Price implements Serializabl
157
  /**
158
  * Return the original price for the individual item
159
  *
160
- * @return float
161
  */
162
  public function originalPrice()
163
  {
@@ -167,7 +167,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Price implements Serializabl
167
  /**
168
  * Return the discount which was given
169
  *
170
- * @return float
171
  */
172
  public function discount()
173
  {
@@ -177,7 +177,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Price implements Serializabl
177
  /**
178
  * Return the tax which was paid
179
  *
180
- * @return float
181
  */
182
  public function tax()
183
  {
@@ -187,7 +187,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Price implements Serializabl
187
  /**
188
  * Return the shipping costs
189
  *
190
- * @return float
191
  */
192
  public function shipping()
193
  {
@@ -197,7 +197,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Price implements Serializabl
197
  /**
198
  * Return the currency code
199
  *
200
- * @return float
201
  */
202
  public function currency()
203
  {
@@ -207,11 +207,12 @@ class Copernica_MarketingSoftware_Model_Abstraction_Price implements Serializabl
207
  /**
208
  * Serialize the object
209
  *
210
- * @return string
211
  */
212
  public function serialize()
213
  {
214
- return serialize(array(
 
215
  $this->total(),
216
  $this->costs(),
217
  $this->itemPrice(),
@@ -220,14 +221,15 @@ class Copernica_MarketingSoftware_Model_Abstraction_Price implements Serializabl
220
  $this->tax(),
221
  $this->shipping(),
222
  $this->currency(),
223
- ));
 
224
  }
225
 
226
  /**
227
  * Unserialize the object
228
  *
229
- * @param string $string
230
- * @return Copernica_MarketingSoftware_Model_Abstraction_Price
231
  */
232
  public function unserialize($string)
233
  {
52
  /**
53
  * Sets the original model
54
  *
55
+ * @param Mage_Sales_Model_Quote|Mage_Sales_Model_Order|Mage_Sales_Model_Quote_Item|Mage_Sales_Model_Order_Item $original
56
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Price
57
  */
58
  public function setOriginal($original)
59
  {
106
  $this->_shipping = 0;
107
  }
108
  } else {
109
+ $this->_shipping = 0;
110
  }
111
 
112
  if ($currency = $original->getOrderCurrencyCode()) {
127
  /**
128
  * Return the total price
129
  *
130
+ * @return float
131
  */
132
  public function total()
133
  {
137
  /**
138
  * Return the price for the individual item
139
  *
140
+ * @return float
141
  */
142
  public function costs()
143
  {
147
  /**
148
  * Return the price for the individual item
149
  *
150
+ * @return float
151
  */
152
  public function itemPrice()
153
  {
157
  /**
158
  * Return the original price for the individual item
159
  *
160
+ * @return float
161
  */
162
  public function originalPrice()
163
  {
167
  /**
168
  * Return the discount which was given
169
  *
170
+ * @return float
171
  */
172
  public function discount()
173
  {
177
  /**
178
  * Return the tax which was paid
179
  *
180
+ * @return float
181
  */
182
  public function tax()
183
  {
187
  /**
188
  * Return the shipping costs
189
  *
190
+ * @return float
191
  */
192
  public function shipping()
193
  {
197
  /**
198
  * Return the currency code
199
  *
200
+ * @return float
201
  */
202
  public function currency()
203
  {
207
  /**
208
  * Serialize the object
209
  *
210
+ * @return string
211
  */
212
  public function serialize()
213
  {
214
+ return serialize(
215
+ array(
216
  $this->total(),
217
  $this->costs(),
218
  $this->itemPrice(),
221
  $this->tax(),
222
  $this->shipping(),
223
  $this->currency(),
224
+ )
225
+ );
226
  }
227
 
228
  /**
229
  * Unserialize the object
230
  *
231
+ * @param string $string
232
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Price
233
  */
234
  public function unserialize($string)
235
  {
app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Product.php CHANGED
@@ -32,8 +32,8 @@ class Copernica_MarketingSoftware_Model_Abstraction_Product implements Serializa
32
  /**
33
  * The original object
34
  *
35
- * @todo Not used???
36
- * @var Mage_Catalog_Model_Product|Mage_Sales_Model_Quote_Item|Mage_Sales_Model_Order_Item
37
  */
38
  protected $_original;
39
 
@@ -57,18 +57,18 @@ class Copernica_MarketingSoftware_Model_Abstraction_Product implements Serializa
57
  /**
58
  * Sets the original model
59
  *
60
- * @param Mage_Catalog_Model_Product|Mage_Sales_Model_Quote_Item|Mage_Sales_Model_Order_Item $original
61
- * @return Copernica_MarketingSoftware_Model_Abstraction_Product
62
  */
63
  public function setOriginal($original)
64
  {
65
  if ($original instanceof Mage_Catalog_Model_Product) {
66
- $this->_createFromProductModel($original);
67
  } else {
68
  $product = Mage::getModel('catalog/product')->load($original->getProductId());
69
 
70
  if ($product->getID()) {
71
- $this->_createFromProductModel($product);
72
  } else {
73
  $this->_id = $original->getProductId();
74
  $this->_sku = $original->getSKU();
@@ -85,7 +85,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Product implements Serializa
85
  /**
86
  * Create product from model.
87
  *
88
- * @param Mage_Catalog_Model_Product $model
89
  */
90
  protected function _createFromProductModel(Mage_Catalog_Model_Product $model)
91
  {
@@ -125,8 +125,8 @@ class Copernica_MarketingSoftware_Model_Abstraction_Product implements Serializa
125
  /**
126
  * Loads a product model
127
  *
128
- * @param integer $productId
129
- * @return Copernica_MarketingSoftware_Model_Abstraction_Product
130
  */
131
  public function loadProduct($productId)
132
  {
@@ -144,7 +144,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Product implements Serializa
144
  /**
145
  * Return the identifier for this object
146
  *
147
- * @return integer
148
  */
149
  public function id()
150
  {
@@ -155,7 +155,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Product implements Serializa
155
  * Return the sku (stock keeping unit), which is an unique identifier
156
  * for a magento product
157
  *
158
- * @return string
159
  */
160
  public function sku()
161
  {
@@ -165,7 +165,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Product implements Serializa
165
  /**
166
  * Return the name of this magento product
167
  *
168
- * @return string
169
  */
170
  public function name()
171
  {
@@ -175,7 +175,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Product implements Serializa
175
  /**
176
  * Return the description of this magento product
177
  *
178
- * @return string
179
  */
180
  public function description()
181
  {
@@ -185,7 +185,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Product implements Serializa
185
  /**
186
  * Return the price of this magento product
187
  *
188
- * @return string
189
  */
190
  public function price()
191
  {
@@ -195,7 +195,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Product implements Serializa
195
  /**
196
  * Return the creation date of this magento product
197
  *
198
- * @return string
199
  */
200
  public function created()
201
  {
@@ -205,7 +205,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Product implements Serializa
205
  /**
206
  * Return the modification date of this magento product
207
  *
208
- * @return string
209
  */
210
  public function modified()
211
  {
@@ -215,8 +215,8 @@ class Copernica_MarketingSoftware_Model_Abstraction_Product implements Serializa
215
  /**
216
  * Return the product url of this magento product
217
  *
218
- * @param integer $storeId
219
- * @return string
220
  */
221
  public function productUrl($storeId = null)
222
  {
@@ -226,8 +226,8 @@ class Copernica_MarketingSoftware_Model_Abstraction_Product implements Serializa
226
  /**
227
  * Return the image url of this magento product
228
  *
229
- * @param integer $storeId
230
- * @return string
231
  */
232
  public function imageUrl($storeId = null)
233
  {
@@ -237,7 +237,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Product implements Serializa
237
  /**
238
  * Return the weight of this magento product
239
  *
240
- * @return float
241
  */
242
  public function weight()
243
  {
@@ -247,7 +247,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Product implements Serializa
247
  /**
248
  * Return the categories of this product
249
  *
250
- * @return array
251
  */
252
  public function categories()
253
  {
@@ -257,8 +257,8 @@ class Copernica_MarketingSoftware_Model_Abstraction_Product implements Serializa
257
  /**
258
  * Return the flattened tree of the given category
259
  *
260
- * @param Mage_Catalog_Model_Category $category
261
- * @return array
262
  */
263
  protected function _getFullCategoryName(Mage_Catalog_Model_Category $category)
264
  {
@@ -278,7 +278,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Product implements Serializa
278
  /**
279
  * Return the attributes for this product
280
  *
281
- * @return Copernica_MarketingSoftware_Model_Abstraction_Attributes
282
  */
283
  public function attributes()
284
  {
@@ -293,8 +293,8 @@ class Copernica_MarketingSoftware_Model_Abstraction_Product implements Serializa
293
  /**
294
  * Serialize the object
295
  *
296
- * @todo This method, is it even used?
297
- * @return string
298
  */
299
  public function serialize()
300
  {
@@ -304,9 +304,9 @@ class Copernica_MarketingSoftware_Model_Abstraction_Product implements Serializa
304
  /**
305
  * Unserialize the object
306
  *
307
- * @todo This method, is it even used? And $isNew???
308
- * @param string $string
309
- * @return Copernica_MarketingSoftware_Model_Abstraction_Product
310
  */
311
  public function unserialize($string)
312
  {
@@ -330,4 +330,4 @@ class Copernica_MarketingSoftware_Model_Abstraction_Product implements Serializa
330
 
331
  return $this;
332
  }
333
- }
32
  /**
33
  * The original object
34
  *
35
+ * @todo Not used???
36
+ * @var Mage_Catalog_Model_Product|Mage_Sales_Model_Quote_Item|Mage_Sales_Model_Order_Item
37
  */
38
  protected $_original;
39
 
57
  /**
58
  * Sets the original model
59
  *
60
+ * @param Mage_Catalog_Model_Product|Mage_Sales_Model_Quote_Item|Mage_Sales_Model_Order_Item $original
61
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Product
62
  */
63
  public function setOriginal($original)
64
  {
65
  if ($original instanceof Mage_Catalog_Model_Product) {
66
+ $this->_createFromProductModel($original);
67
  } else {
68
  $product = Mage::getModel('catalog/product')->load($original->getProductId());
69
 
70
  if ($product->getID()) {
71
+ $this->_createFromProductModel($product);
72
  } else {
73
  $this->_id = $original->getProductId();
74
  $this->_sku = $original->getSKU();
85
  /**
86
  * Create product from model.
87
  *
88
+ * @param Mage_Catalog_Model_Product $model
89
  */
90
  protected function _createFromProductModel(Mage_Catalog_Model_Product $model)
91
  {
125
  /**
126
  * Loads a product model
127
  *
128
+ * @param integer $productId
129
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Product
130
  */
131
  public function loadProduct($productId)
132
  {
144
  /**
145
  * Return the identifier for this object
146
  *
147
+ * @return integer
148
  */
149
  public function id()
150
  {
155
  * Return the sku (stock keeping unit), which is an unique identifier
156
  * for a magento product
157
  *
158
+ * @return string
159
  */
160
  public function sku()
161
  {
165
  /**
166
  * Return the name of this magento product
167
  *
168
+ * @return string
169
  */
170
  public function name()
171
  {
175
  /**
176
  * Return the description of this magento product
177
  *
178
+ * @return string
179
  */
180
  public function description()
181
  {
185
  /**
186
  * Return the price of this magento product
187
  *
188
+ * @return string
189
  */
190
  public function price()
191
  {
195
  /**
196
  * Return the creation date of this magento product
197
  *
198
+ * @return string
199
  */
200
  public function created()
201
  {
205
  /**
206
  * Return the modification date of this magento product
207
  *
208
+ * @return string
209
  */
210
  public function modified()
211
  {
215
  /**
216
  * Return the product url of this magento product
217
  *
218
+ * @param integer $storeId
219
+ * @return string
220
  */
221
  public function productUrl($storeId = null)
222
  {
226
  /**
227
  * Return the image url of this magento product
228
  *
229
+ * @param integer $storeId
230
+ * @return string
231
  */
232
  public function imageUrl($storeId = null)
233
  {
237
  /**
238
  * Return the weight of this magento product
239
  *
240
+ * @return float
241
  */
242
  public function weight()
243
  {
247
  /**
248
  * Return the categories of this product
249
  *
250
+ * @return array
251
  */
252
  public function categories()
253
  {
257
  /**
258
  * Return the flattened tree of the given category
259
  *
260
+ * @param Mage_Catalog_Model_Category $category
261
+ * @return array
262
  */
263
  protected function _getFullCategoryName(Mage_Catalog_Model_Category $category)
264
  {
278
  /**
279
  * Return the attributes for this product
280
  *
281
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Attributes
282
  */
283
  public function attributes()
284
  {
293
  /**
294
  * Serialize the object
295
  *
296
+ * @todo This method, is it even used?
297
+ * @return string
298
  */
299
  public function serialize()
300
  {
304
  /**
305
  * Unserialize the object
306
  *
307
+ * @todo This method, is it even used? And $isNew???
308
+ * @param string $string
309
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Product
310
  */
311
  public function unserialize($string)
312
  {
330
 
331
  return $this;
332
  }
333
+ }
app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Product/Viewed.php CHANGED
@@ -53,8 +53,8 @@ class Copernica_MarketingSoftware_Model_Abstraction_Product_Viewed implements Se
53
  /**
54
  * Sets the original model
55
  *
56
- * @param Mage_Catalog_Model_Product|Mage_Sales_Model_Quote_Item|Mage_Sales_Model_Order_Item $original
57
- * @return Copernica_MarketingSoftware_Model_Abstraction_Product
58
  */
59
  public function setOriginal($original, $id)
60
  {
@@ -201,8 +201,8 @@ class Copernica_MarketingSoftware_Model_Abstraction_Product_Viewed implements Se
201
  /**
202
  * Loads a product model
203
  *
204
- * @param integer $productId
205
- * @return Copernica_MarketingSoftware_Model_Abstraction_Product
206
  */
207
  public function loadProduct($productId)
208
  {
@@ -220,7 +220,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Product_Viewed implements Se
220
  /**
221
  * Return the identifier for this object
222
  *
223
- * @return integer
224
  */
225
  public function id()
226
  {
@@ -231,7 +231,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Product_Viewed implements Se
231
  * Return the sku (stock keeping unit), which is an unique identifier
232
  * for a magento product
233
  *
234
- * @return string
235
  */
236
  public function sku()
237
  {
@@ -241,7 +241,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Product_Viewed implements Se
241
  /**
242
  * Return the name of this magento product
243
  *
244
- * @return string
245
  */
246
  public function name()
247
  {
@@ -251,7 +251,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Product_Viewed implements Se
251
  /**
252
  * Return the description of this magento product
253
  *
254
- * @return string
255
  */
256
  public function description()
257
  {
@@ -261,7 +261,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Product_Viewed implements Se
261
  /**
262
  * Return the price of this magento product
263
  *
264
- * @return string
265
  */
266
  public function price()
267
  {
@@ -271,7 +271,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Product_Viewed implements Se
271
  /**
272
  * Return the price of this magento product
273
  *
274
- * @return string
275
  */
276
  public function specialPrice()
277
  {
@@ -282,7 +282,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Product_Viewed implements Se
282
  /**
283
  * Return the creation date of this magento product
284
  *
285
- * @return string
286
  */
287
  public function created()
288
  {
@@ -292,7 +292,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Product_Viewed implements Se
292
  /**
293
  * Return the modification date of this magento product
294
  *
295
- * @return string
296
  */
297
  public function modified()
298
  {
@@ -302,8 +302,8 @@ class Copernica_MarketingSoftware_Model_Abstraction_Product_Viewed implements Se
302
  /**
303
  * Return the product url of this magento product
304
  *
305
- * @param integer $storeId
306
- * @return string
307
  */
308
  public function productUrl($storeId = null)
309
  {
@@ -313,8 +313,8 @@ class Copernica_MarketingSoftware_Model_Abstraction_Product_Viewed implements Se
313
  /**
314
  * Return the image url of this magento product
315
  *
316
- * @param integer $storeId
317
- * @return string
318
  */
319
  public function imageUrl($storeId = null)
320
  {
@@ -324,7 +324,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Product_Viewed implements Se
324
  /**
325
  * Return the weight of this magento product
326
  *
327
- * @return float
328
  */
329
  public function weight()
330
  {
@@ -334,7 +334,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Product_Viewed implements Se
334
  /**
335
  * Return the categories of this product
336
  *
337
- * @return array
338
  */
339
  public function categories()
340
  {
@@ -344,8 +344,8 @@ class Copernica_MarketingSoftware_Model_Abstraction_Product_Viewed implements Se
344
  /**
345
  * Return the flattened tree of the given category
346
  *
347
- * @param Mage_Catalog_Model_Category $category
348
- * @return array
349
  */
350
  protected function _getFullCategoryName(Mage_Catalog_Model_Category $category)
351
  {
@@ -365,7 +365,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Product_Viewed implements Se
365
  /**
366
  * Return whether this product is new
367
  *
368
- * @return boolean
369
  */
370
  public function isNew()
371
  {
@@ -375,7 +375,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Product_Viewed implements Se
375
  /**
376
  * Return the attributes for this product
377
  *
378
- * @return Copernica_MarketingSoftware_Model_Abstraction_Attributes
379
  */
380
  public function attributes()
381
  {
@@ -396,7 +396,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Product_Viewed implements Se
396
  /**
397
  * Serialize the object
398
  *
399
- * @return string
400
  */
401
  public function serialize()
402
  {
@@ -406,8 +406,8 @@ class Copernica_MarketingSoftware_Model_Abstraction_Product_Viewed implements Se
406
  /**
407
  * Unserialize the object
408
  *
409
- * @param string $string
410
- * @return Copernica_MarketingSoftware_Model_Abstraction_Product
411
  */
412
  public function unserialize($string)
413
  {
@@ -415,4 +415,4 @@ class Copernica_MarketingSoftware_Model_Abstraction_Product_Viewed implements Se
415
 
416
  return $this;
417
  }
418
- }
53
  /**
54
  * Sets the original model
55
  *
56
+ * @param Mage_Catalog_Model_Product|Mage_Sales_Model_Quote_Item|Mage_Sales_Model_Order_Item $original
57
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Product
58
  */
59
  public function setOriginal($original, $id)
60
  {
201
  /**
202
  * Loads a product model
203
  *
204
+ * @param integer $productId
205
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Product
206
  */
207
  public function loadProduct($productId)
208
  {
220
  /**
221
  * Return the identifier for this object
222
  *
223
+ * @return integer
224
  */
225
  public function id()
226
  {
231
  * Return the sku (stock keeping unit), which is an unique identifier
232
  * for a magento product
233
  *
234
+ * @return string
235
  */
236
  public function sku()
237
  {
241
  /**
242
  * Return the name of this magento product
243
  *
244
+ * @return string
245
  */
246
  public function name()
247
  {
251
  /**
252
  * Return the description of this magento product
253
  *
254
+ * @return string
255
  */
256
  public function description()
257
  {
261
  /**
262
  * Return the price of this magento product
263
  *
264
+ * @return string
265
  */
266
  public function price()
267
  {
271
  /**
272
  * Return the price of this magento product
273
  *
274
+ * @return string
275
  */
276
  public function specialPrice()
277
  {
282
  /**
283
  * Return the creation date of this magento product
284
  *
285
+ * @return string
286
  */
287
  public function created()
288
  {
292
  /**
293
  * Return the modification date of this magento product
294
  *
295
+ * @return string
296
  */
297
  public function modified()
298
  {
302
  /**
303
  * Return the product url of this magento product
304
  *
305
+ * @param integer $storeId
306
+ * @return string
307
  */
308
  public function productUrl($storeId = null)
309
  {
313
  /**
314
  * Return the image url of this magento product
315
  *
316
+ * @param integer $storeId
317
+ * @return string
318
  */
319
  public function imageUrl($storeId = null)
320
  {
324
  /**
325
  * Return the weight of this magento product
326
  *
327
+ * @return float
328
  */
329
  public function weight()
330
  {
334
  /**
335
  * Return the categories of this product
336
  *
337
+ * @return array
338
  */
339
  public function categories()
340
  {
344
  /**
345
  * Return the flattened tree of the given category
346
  *
347
+ * @param Mage_Catalog_Model_Category $category
348
+ * @return array
349
  */
350
  protected function _getFullCategoryName(Mage_Catalog_Model_Category $category)
351
  {
365
  /**
366
  * Return whether this product is new
367
  *
368
+ * @return boolean
369
  */
370
  public function isNew()
371
  {
375
  /**
376
  * Return the attributes for this product
377
  *
378
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Attributes
379
  */
380
  public function attributes()
381
  {
396
  /**
397
  * Serialize the object
398
  *
399
+ * @return string
400
  */
401
  public function serialize()
402
  {
406
  /**
407
  * Unserialize the object
408
  *
409
+ * @param string $string
410
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Product
411
  */
412
  public function unserialize($string)
413
  {
415
 
416
  return $this;
417
  }
418
+ }
app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Quote.php CHANGED
@@ -57,8 +57,8 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote implements Serializabl
57
  /**
58
  * Sets the original model
59
  *
60
- * @param Mage_Sales_Model_Quote $original
61
- * @return Copernica_MarketingSoftware_Model_Abstraction_Quote
62
  */
63
  public function setOriginal(Mage_Sales_Model_Quote $original)
64
  {
@@ -70,8 +70,8 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote implements Serializabl
70
  /**
71
  * Loads a quote model
72
  *
73
- * @param integer $quoteId
74
- * @return Copernica_MarketingSoftware_Model_Abstraction_Quote
75
  */
76
  public function loadQuote($quoteId)
77
  {
@@ -80,14 +80,14 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote implements Serializabl
80
  if (!is_callable($quote, 'loadByIdWithoutStore')) {
81
  $storeIDs = array();
82
 
83
- foreach (Mage::app()->getStores() as $id => $store) {
84
- $storeIDs[] = $id;
85
  }
86
 
87
  $quote->setSharedStoreIds($storeIDs);
88
  $quote->load($quoteId);
89
  } else {
90
- $quote->loadByIdWithoutStore($quoteId);
91
  }
92
 
93
  if ($quote->getId()) {
@@ -102,8 +102,8 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote implements Serializabl
102
  /**
103
  * Import this abstract from a real magento one
104
  *
105
- * @param Mage_Sales_Model_Quote $original
106
- * @return Copernica_MarketingSoftware_Model_Abstraction_Quote
107
  */
108
  protected function _importFromObject(Mage_Sales_Model_Quote $original)
109
  {
@@ -151,14 +151,16 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote implements Serializabl
151
  if ($payment = $original->getPayment()) {
152
  try {
153
  $this->_paymentDescription = $payment->getMethodInstance()->getTitle();
154
- } catch (Mage_Core_Exception $exception) { }
 
 
155
  }
156
  }
157
 
158
  /**
159
  * The quote id of this quote object
160
  *
161
- * @return integer
162
  */
163
  public function id()
164
  {
@@ -168,7 +170,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote implements Serializabl
168
  /**
169
  * Is this quote still active
170
  *
171
- * @return boolean
172
  */
173
  public function active()
174
  {
@@ -178,7 +180,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote implements Serializabl
178
  /**
179
  * The number of items present in this quote
180
  *
181
- * @return integer
182
  */
183
  public function quantity()
184
  {
@@ -188,7 +190,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote implements Serializabl
188
  /**
189
  * The payment currency of this quote
190
  *
191
- * @return string
192
  */
193
  public function currency()
194
  {
@@ -199,7 +201,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote implements Serializabl
199
  * The price
200
  * Note that an object is returned, which may consist of multiple components
201
  *
202
- * @return Copernica_MarketingSoftware_Model_Abstraction_Price
203
  */
204
  public function price()
205
  {
@@ -209,7 +211,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote implements Serializabl
209
  /**
210
  * The weight
211
  *
212
- * @return float
213
  */
214
  public function weight()
215
  {
@@ -219,7 +221,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote implements Serializabl
219
  /**
220
  * To what storeview does this quote belong
221
  *
222
- * @return Copernica_MarketingSoftware_Model_Abstraction_Storeview
223
  */
224
  public function storeview()
225
  {
@@ -229,7 +231,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote implements Serializabl
229
  /**
230
  * Get the items from the quote
231
  *
232
- * @return array
233
  */
234
  public function items()
235
  {
@@ -239,7 +241,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote implements Serializabl
239
  /**
240
  * The timestamp at which this quote was modified
241
  *
242
- * @return string
243
  */
244
  public function timestamp()
245
  {
@@ -249,7 +251,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote implements Serializabl
249
  /**
250
  * The customer may return null
251
  *
252
- * @return Copernica_MarketingSoftware_Model_Abstraction_Customer|null
253
  */
254
  public function customer()
255
  {
@@ -263,7 +265,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote implements Serializabl
263
  /**
264
  * The addresses of this quote
265
  *
266
- * @return array
267
  */
268
  public function addresses()
269
  {
@@ -273,7 +275,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote implements Serializabl
273
  /**
274
  * The IP from which this quote was constructed
275
  *
276
- * @return string
277
  */
278
  public function customerIP()
279
  {
@@ -283,7 +285,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote implements Serializabl
283
  /**
284
  * The shipping method of this quote
285
  *
286
- * @return string
287
  */
288
  public function shippingDescription()
289
  {
@@ -293,7 +295,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote implements Serializabl
293
  /**
294
  * The payment method of this quote
295
  *
296
- * @return string
297
  */
298
  public function paymentDescription()
299
  {
@@ -303,22 +305,24 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote implements Serializabl
303
  /**
304
  * Serialize the object
305
  *
306
- * @todo Two returns??
307
- * @return string
308
  */
309
  public function serialize()
310
  {
311
- return serialize(array(
 
312
  $this->id()
313
- ));
 
314
  }
315
 
316
  /**
317
  * Unserialize the object
318
  *
319
- * @todo Two returns??
320
- * @param string $string
321
- * @return Copernica_MarketingSoftware_Model_Abstraction_Quote
322
  */
323
  public function unserialize($string)
324
  {
@@ -330,4 +334,4 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote implements Serializabl
330
 
331
  return $this;
332
  }
333
- }
57
  /**
58
  * Sets the original model
59
  *
60
+ * @param Mage_Sales_Model_Quote $original
61
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Quote
62
  */
63
  public function setOriginal(Mage_Sales_Model_Quote $original)
64
  {
70
  /**
71
  * Loads a quote model
72
  *
73
+ * @param integer $quoteId
74
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Quote
75
  */
76
  public function loadQuote($quoteId)
77
  {
80
  if (!is_callable($quote, 'loadByIdWithoutStore')) {
81
  $storeIDs = array();
82
 
83
+ foreach (Mage::app()->getStores() as $id => $store) {
84
+ $storeIDs[] = $id;
85
  }
86
 
87
  $quote->setSharedStoreIds($storeIDs);
88
  $quote->load($quoteId);
89
  } else {
90
+ $quote->loadByIdWithoutStore($quoteId);
91
  }
92
 
93
  if ($quote->getId()) {
102
  /**
103
  * Import this abstract from a real magento one
104
  *
105
+ * @param Mage_Sales_Model_Quote $original
106
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Quote
107
  */
108
  protected function _importFromObject(Mage_Sales_Model_Quote $original)
109
  {
151
  if ($payment = $original->getPayment()) {
152
  try {
153
  $this->_paymentDescription = $payment->getMethodInstance()->getTitle();
154
+ } catch (Mage_Core_Exception $exception) {
155
+ Mage::logException($exception);
156
+ }
157
  }
158
  }
159
 
160
  /**
161
  * The quote id of this quote object
162
  *
163
+ * @return integer
164
  */
165
  public function id()
166
  {
170
  /**
171
  * Is this quote still active
172
  *
173
+ * @return boolean
174
  */
175
  public function active()
176
  {
180
  /**
181
  * The number of items present in this quote
182
  *
183
+ * @return integer
184
  */
185
  public function quantity()
186
  {
190
  /**
191
  * The payment currency of this quote
192
  *
193
+ * @return string
194
  */
195
  public function currency()
196
  {
201
  * The price
202
  * Note that an object is returned, which may consist of multiple components
203
  *
204
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Price
205
  */
206
  public function price()
207
  {
211
  /**
212
  * The weight
213
  *
214
+ * @return float
215
  */
216
  public function weight()
217
  {
221
  /**
222
  * To what storeview does this quote belong
223
  *
224
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Storeview
225
  */
226
  public function storeview()
227
  {
231
  /**
232
  * Get the items from the quote
233
  *
234
+ * @return array
235
  */
236
  public function items()
237
  {
241
  /**
242
  * The timestamp at which this quote was modified
243
  *
244
+ * @return string
245
  */
246
  public function timestamp()
247
  {
251
  /**
252
  * The customer may return null
253
  *
254
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Customer|null
255
  */
256
  public function customer()
257
  {
265
  /**
266
  * The addresses of this quote
267
  *
268
+ * @return array
269
  */
270
  public function addresses()
271
  {
275
  /**
276
  * The IP from which this quote was constructed
277
  *
278
+ * @return string
279
  */
280
  public function customerIP()
281
  {
285
  /**
286
  * The shipping method of this quote
287
  *
288
+ * @return string
289
  */
290
  public function shippingDescription()
291
  {
295
  /**
296
  * The payment method of this quote
297
  *
298
+ * @return string
299
  */
300
  public function paymentDescription()
301
  {
305
  /**
306
  * Serialize the object
307
  *
308
+ * @todo Two returns??
309
+ * @return string
310
  */
311
  public function serialize()
312
  {
313
+ return serialize(
314
+ array(
315
  $this->id()
316
+ )
317
+ );
318
  }
319
 
320
  /**
321
  * Unserialize the object
322
  *
323
+ * @todo Two returns??
324
+ * @param string $string
325
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Quote
326
  */
327
  public function unserialize($string)
328
  {
334
 
335
  return $this;
336
  }
337
+ }
app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Quote/Item.php CHANGED
@@ -44,8 +44,8 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote_Item implements Serial
44
  /**
45
  * Sets the original model
46
  *
47
- * @param Mage_Sales_Model_Quote_Item $original
48
- * @return Copernica_MarketingSoftware_Model_Abstraction_Quote_Item
49
  */
50
  public function setOriginal(Mage_Sales_Model_Quote_Item $original)
51
  {
@@ -72,7 +72,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote_Item implements Serial
72
  /**
73
  * The id of this quote item object
74
  *
75
- * @return integer
76
  */
77
  public function id()
78
  {
@@ -82,7 +82,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote_Item implements Serial
82
  /**
83
  * Get the quote to which this item belongs
84
  *
85
- * @return Copernica_MarketingSoftware_Model_Abstraction_Quote
86
  */
87
  public function quote()
88
  {
@@ -92,7 +92,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote_Item implements Serial
92
  /**
93
  * The amount of this quote item
94
  *
95
- * @return integer
96
  */
97
  public function quantity()
98
  {
@@ -103,7 +103,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote_Item implements Serial
103
  * The price
104
  * Note that an object is returned, which may consist of multiple components
105
  *
106
- * @return Copernica_MarketingSoftware_Model_Abstraction_Price
107
  */
108
  public function price()
109
  {
@@ -113,7 +113,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote_Item implements Serial
113
  /**
114
  * The weight
115
  *
116
- * @return float
117
  */
118
  public function weight()
119
  {
@@ -123,7 +123,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote_Item implements Serial
123
  /**
124
  * The timestamp at which this quote item was modified
125
  *
126
- * @return string
127
  */
128
  public function timestamp()
129
  {
@@ -133,7 +133,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote_Item implements Serial
133
  /**
134
  * Get the options of this quote item
135
  *
136
- * @return Copernica_MarketingSoftware_Model_Abstraction_Quote_Item_Options
137
  */
138
  public function options()
139
  {
@@ -143,7 +143,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote_Item implements Serial
143
  /**
144
  * Get the product which belongs to this item
145
  *
146
- * @return Copernica_MarketingSoftware_Model_Abstraction_Product
147
  */
148
  public function product()
149
  {
@@ -153,30 +153,31 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote_Item implements Serial
153
  /**
154
  * Loads a product model
155
  *
156
- * @param integer $productId
157
- * @return Copernica_MarketingSoftware_Model_Abstraction_Product
158
  */
159
  public function loadQuoteItem($quoteId)
160
  {
161
- $quoteItem = Mage::getModel('sales/quote_item')->load($quoteId);
162
-
163
- if ($quoteItem->getId()) {
164
- $this->setOriginal($quoteItem);
165
- } else {
166
- $this->id = $quoteId;
167
- }
168
-
169
- return $this;
170
  }
171
 
172
  /**
173
  * Serialize the object
174
  *
175
- * @return string
176
  */
177
  public function serialize()
178
  {
179
- return serialize(array(
 
180
  $this->id(),
181
  is_object($quote = $this->quote()) ? $quote->id() : null,
182
  $this->quantity(),
@@ -185,14 +186,15 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote_Item implements Serial
185
  $this->timestamp(),
186
  $this->options(),
187
  $this->product(),
188
- ));
 
189
  }
190
 
191
  /**
192
  * Unserialize the object
193
  *
194
- * @param string $string
195
- * @return Copernica_MarketingSoftware_Model_Abstraction_Quote_Item
196
  */
197
  public function unserialize($string)
198
  {
@@ -209,4 +211,4 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote_Item implements Serial
209
 
210
  return $this;
211
  }
212
- }
44
  /**
45
  * Sets the original model
46
  *
47
+ * @param Mage_Sales_Model_Quote_Item $original
48
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Quote_Item
49
  */
50
  public function setOriginal(Mage_Sales_Model_Quote_Item $original)
51
  {
72
  /**
73
  * The id of this quote item object
74
  *
75
+ * @return integer
76
  */
77
  public function id()
78
  {
82
  /**
83
  * Get the quote to which this item belongs
84
  *
85
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Quote
86
  */
87
  public function quote()
88
  {
92
  /**
93
  * The amount of this quote item
94
  *
95
+ * @return integer
96
  */
97
  public function quantity()
98
  {
103
  * The price
104
  * Note that an object is returned, which may consist of multiple components
105
  *
106
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Price
107
  */
108
  public function price()
109
  {
113
  /**
114
  * The weight
115
  *
116
+ * @return float
117
  */
118
  public function weight()
119
  {
123
  /**
124
  * The timestamp at which this quote item was modified
125
  *
126
+ * @return string
127
  */
128
  public function timestamp()
129
  {
133
  /**
134
  * Get the options of this quote item
135
  *
136
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Quote_Item_Options
137
  */
138
  public function options()
139
  {
143
  /**
144
  * Get the product which belongs to this item
145
  *
146
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Product
147
  */
148
  public function product()
149
  {
153
  /**
154
  * Loads a product model
155
  *
156
+ * @param integer $productId
157
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Product
158
  */
159
  public function loadQuoteItem($quoteId)
160
  {
161
+ $quoteItem = Mage::getModel('sales/quote_item')->load($quoteId);
162
+
163
+ if ($quoteItem->getId()) {
164
+ $this->setOriginal($quoteItem);
165
+ } else {
166
+ $this->id = $quoteId;
167
+ }
168
+
169
+ return $this;
170
  }
171
 
172
  /**
173
  * Serialize the object
174
  *
175
+ * @return string
176
  */
177
  public function serialize()
178
  {
179
+ return serialize(
180
+ array(
181
  $this->id(),
182
  is_object($quote = $this->quote()) ? $quote->id() : null,
183
  $this->quantity(),
186
  $this->timestamp(),
187
  $this->options(),
188
  $this->product(),
189
+ )
190
+ );
191
  }
192
 
193
  /**
194
  * Unserialize the object
195
  *
196
+ * @param string $string
197
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Quote_Item
198
  */
199
  public function unserialize($string)
200
  {
211
 
212
  return $this;
213
  }
214
+ }
app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Quote/Item/Options.php CHANGED
@@ -39,8 +39,8 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote_Item_Options implement
39
  /**
40
  * Sets the original model
41
  *
42
- * @param Mage_Sales_Model_Quote_Item $original
43
- * @return Copernica_MarketingSoftware_Model_Abstraction_Quote_Item_Options
44
  */
45
  public function setOriginal(Mage_Sales_Model_Quote_Item $original)
46
  {
@@ -78,7 +78,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote_Item_Options implement
78
  /**
79
  * The name of this set of options
80
  *
81
- * @return integer
82
  */
83
  public function name()
84
  {
@@ -88,7 +88,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote_Item_Options implement
88
  /**
89
  * Return an assoc array with attributes
90
  *
91
- * @return array
92
  */
93
  public function attributes()
94
  {
@@ -98,7 +98,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote_Item_Options implement
98
  /**
99
  * Return a string representation
100
  *
101
- * @return string
102
  */
103
  public function __toString()
104
  {
@@ -108,9 +108,9 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote_Item_Options implement
108
  /**
109
  * Return a string representation of an array
110
  *
111
- * @param array $value
112
- * @param string $prefix
113
- * @return string
114
  */
115
  protected function _arrayToString($value, $prefix = '')
116
  {
@@ -119,12 +119,12 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote_Item_Options implement
119
  foreach ($value as $key => $value) {
120
  if (is_array($value)) {
121
  if (isset($value[0]) && count($value) == 1) {
122
- $value = $value[0];
123
  }
124
 
125
  $string .= $prefix.$key.":\n".$this->_arrayToString($value, $prefix.' ');
126
  } else {
127
- $string.= $prefix.$key.": $value\n";
128
  }
129
  }
130
 
@@ -134,21 +134,23 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote_Item_Options implement
134
  /**
135
  * Serialize the object
136
  *
137
- * @return string
138
  */
139
  public function serialize()
140
  {
141
- return serialize(array(
 
142
  $this->name(),
143
  $this->attributes(),
144
- ));
 
145
  }
146
 
147
  /**
148
  * Unserialize the object
149
  *
150
- * @param string $string
151
- * @return Copernica_MarketingSoftware_Model_Abstraction_Quote_Item_Options
152
  */
153
  public function unserialize($string)
154
  {
39
  /**
40
  * Sets the original model
41
  *
42
+ * @param Mage_Sales_Model_Quote_Item $original
43
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Quote_Item_Options
44
  */
45
  public function setOriginal(Mage_Sales_Model_Quote_Item $original)
46
  {
78
  /**
79
  * The name of this set of options
80
  *
81
+ * @return integer
82
  */
83
  public function name()
84
  {
88
  /**
89
  * Return an assoc array with attributes
90
  *
91
+ * @return array
92
  */
93
  public function attributes()
94
  {
98
  /**
99
  * Return a string representation
100
  *
101
+ * @return string
102
  */
103
  public function __toString()
104
  {
108
  /**
109
  * Return a string representation of an array
110
  *
111
+ * @param array $value
112
+ * @param string $prefix
113
+ * @return string
114
  */
115
  protected function _arrayToString($value, $prefix = '')
116
  {
119
  foreach ($value as $key => $value) {
120
  if (is_array($value)) {
121
  if (isset($value[0]) && count($value) == 1) {
122
+ $value = $value[0];
123
  }
124
 
125
  $string .= $prefix.$key.":\n".$this->_arrayToString($value, $prefix.' ');
126
  } else {
127
+ $string.= $prefix.$key.": $value\n";
128
  }
129
  }
130
 
134
  /**
135
  * Serialize the object
136
  *
137
+ * @return string
138
  */
139
  public function serialize()
140
  {
141
+ return serialize(
142
+ array(
143
  $this->name(),
144
  $this->attributes(),
145
+ )
146
+ );
147
  }
148
 
149
  /**
150
  * Unserialize the object
151
  *
152
+ * @param string $string
153
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Quote_Item_Options
154
  */
155
  public function unserialize($string)
156
  {
app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Storeview.php CHANGED
@@ -43,8 +43,8 @@ class Copernica_MarketingSoftware_Model_Abstraction_Storeview implements Seriali
43
  /**
44
  * Sets the original model
45
  *
46
- * @param Mage_Core_Model_Store $original
47
- * @return Copernica_MarketingSoftware_Model_Abstraction_Storeview
48
  */
49
  public function setOriginal(Mage_Core_Model_Store $original)
50
  {
@@ -64,7 +64,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Storeview implements Seriali
64
  /**
65
  * Return the id for the storeview
66
  *
67
- * @return int
68
  */
69
  public function id()
70
  {
@@ -74,7 +74,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Storeview implements Seriali
74
  /**
75
  * Return the code for the website
76
  *
77
- * @return string
78
  */
79
  public function websiteCode()
80
  {
@@ -84,7 +84,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Storeview implements Seriali
84
  /**
85
  * Return the label for the website
86
  *
87
- * @return string
88
  */
89
  public function websiteLabel()
90
  {
@@ -94,7 +94,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Storeview implements Seriali
94
  /**
95
  * Return the code for the store
96
  *
97
- * @return string
98
  */
99
  public function storeCode()
100
  {
@@ -104,7 +104,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Storeview implements Seriali
104
  /**
105
  * Return the label for the store
106
  *
107
- * @return string
108
  */
109
  public function storeLabel()
110
  {
@@ -114,7 +114,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Storeview implements Seriali
114
  /**
115
  * Return the code for the store
116
  *
117
- * @return string
118
  */
119
  public function viewCode()
120
  {
@@ -124,7 +124,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Storeview implements Seriali
124
  /**
125
  * Return the label for the store
126
  *
127
- * @return string
128
  */
129
  public function viewLabel()
130
  {
@@ -134,25 +134,28 @@ class Copernica_MarketingSoftware_Model_Abstraction_Storeview implements Seriali
134
  /**
135
  * Convert this value to a string
136
  *
137
- * @return String
138
  */
139
  public function __toString()
140
  {
141
- return implode(' > ', array(
 
142
  $this->websiteLabel(),
143
  $this->storeLabel(),
144
  $this->viewLabel(),
145
- ));
 
146
  }
147
 
148
  /**
149
  * Serialize the object
150
  *
151
- * @return string
152
  */
153
  public function serialize()
154
  {
155
- return serialize(array(
 
156
  $this->id(),
157
  $this->websiteCode(),
158
  $this->websiteLabel(),
@@ -160,14 +163,15 @@ class Copernica_MarketingSoftware_Model_Abstraction_Storeview implements Seriali
160
  $this->storeLabel(),
161
  $this->viewCode(),
162
  $this->viewLabel(),
163
- ));
 
164
  }
165
 
166
  /**
167
  * Unserialize the object
168
  *
169
- * @param string $string
170
- * @return Copernica_MarketingSoftware_Model_Abstraction_Storeview
171
  */
172
  public function unserialize($string)
173
  {
@@ -183,4 +187,4 @@ class Copernica_MarketingSoftware_Model_Abstraction_Storeview implements Seriali
183
 
184
  return $this;
185
  }
186
- }
43
  /**
44
  * Sets the original model
45
  *
46
+ * @param Mage_Core_Model_Store $original
47
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Storeview
48
  */
49
  public function setOriginal(Mage_Core_Model_Store $original)
50
  {
64
  /**
65
  * Return the id for the storeview
66
  *
67
+ * @return int
68
  */
69
  public function id()
70
  {
74
  /**
75
  * Return the code for the website
76
  *
77
+ * @return string
78
  */
79
  public function websiteCode()
80
  {
84
  /**
85
  * Return the label for the website
86
  *
87
+ * @return string
88
  */
89
  public function websiteLabel()
90
  {
94
  /**
95
  * Return the code for the store
96
  *
97
+ * @return string
98
  */
99
  public function storeCode()
100
  {
104
  /**
105
  * Return the label for the store
106
  *
107
+ * @return string
108
  */
109
  public function storeLabel()
110
  {
114
  /**
115
  * Return the code for the store
116
  *
117
+ * @return string
118
  */
119
  public function viewCode()
120
  {
124
  /**
125
  * Return the label for the store
126
  *
127
+ * @return string
128
  */
129
  public function viewLabel()
130
  {
134
  /**
135
  * Convert this value to a string
136
  *
137
+ * @return String
138
  */
139
  public function __toString()
140
  {
141
+ return implode(
142
+ ' > ', array(
143
  $this->websiteLabel(),
144
  $this->storeLabel(),
145
  $this->viewLabel(),
146
+ )
147
+ );
148
  }
149
 
150
  /**
151
  * Serialize the object
152
  *
153
+ * @return string
154
  */
155
  public function serialize()
156
  {
157
+ return serialize(
158
+ array(
159
  $this->id(),
160
  $this->websiteCode(),
161
  $this->websiteLabel(),
163
  $this->storeLabel(),
164
  $this->viewCode(),
165
  $this->viewLabel(),
166
+ )
167
+ );
168
  }
169
 
170
  /**
171
  * Unserialize the object
172
  *
173
+ * @param string $string
174
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Storeview
175
  */
176
  public function unserialize($string)
177
  {
187
 
188
  return $this;
189
  }
190
+ }
app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Subscription.php CHANGED
@@ -48,8 +48,8 @@ class Copernica_MarketingSoftware_Model_Abstraction_Subscription implements Seri
48
  /**
49
  * Sets the original model
50
  *
51
- * @param Mage_Newsletter_Model_Subscriber $original
52
- * @return Copernica_MarketingSoftware_Model_Abstraction_Subscription
53
  */
54
  public function setOriginal(Mage_Newsletter_Model_Subscriber $original)
55
  {
@@ -89,7 +89,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Subscription implements Seri
89
  /**
90
  * Return the identifier for this object
91
  *
92
- * @return integer
93
  */
94
  public function id()
95
  {
@@ -99,7 +99,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Subscription implements Seri
99
  /**
100
  * Return the e-mail address with which the user is subscribed
101
  *
102
- * @return string
103
  */
104
  public function email()
105
  {
@@ -110,7 +110,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Subscription implements Seri
110
  * Return the status of this subscription
111
  * Note that subscribed might be returned but the record is currently removed
112
  *
113
- * @return string
114
  */
115
  public function status()
116
  {
@@ -120,7 +120,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Subscription implements Seri
120
  /**
121
  * The customer may return null
122
  *
123
- * @return Copernica_MarketingSoftware_Model_Abstraction_Customer
124
  */
125
  public function customer()
126
  {
@@ -134,7 +134,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Subscription implements Seri
134
  /**
135
  * Return the storeview for this subscription
136
  *
137
- * @return Copernica_MarketingSoftware_Model_Abstraction_Storeview
138
  */
139
  public function storeView()
140
  {
@@ -144,24 +144,26 @@ class Copernica_MarketingSoftware_Model_Abstraction_Subscription implements Seri
144
  /**
145
  * Serialize the object
146
  *
147
- * @return string
148
  */
149
  public function serialize()
150
  {
151
- return serialize(array(
 
152
  $this->id(),
153
  $this->email(),
154
  $this->status(),
155
  $this->storeview(),
156
  is_object($customer = $this->customer()) ? $customer->id() : null,
157
- ));
 
158
  }
159
 
160
  /**
161
  * Unserialize the object
162
  *
163
- * @param string $string
164
- * @return Copernica_MarketingSoftware_Model_Abstraction_Subscription
165
  */
166
  public function unserialize($string)
167
  {
48
  /**
49
  * Sets the original model
50
  *
51
+ * @param Mage_Newsletter_Model_Subscriber $original
52
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Subscription
53
  */
54
  public function setOriginal(Mage_Newsletter_Model_Subscriber $original)
55
  {
89
  /**
90
  * Return the identifier for this object
91
  *
92
+ * @return integer
93
  */
94
  public function id()
95
  {
99
  /**
100
  * Return the e-mail address with which the user is subscribed
101
  *
102
+ * @return string
103
  */
104
  public function email()
105
  {
110
  * Return the status of this subscription
111
  * Note that subscribed might be returned but the record is currently removed
112
  *
113
+ * @return string
114
  */
115
  public function status()
116
  {
120
  /**
121
  * The customer may return null
122
  *
123
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Customer
124
  */
125
  public function customer()
126
  {
134
  /**
135
  * Return the storeview for this subscription
136
  *
137
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Storeview
138
  */
139
  public function storeView()
140
  {
144
  /**
145
  * Serialize the object
146
  *
147
+ * @return string
148
  */
149
  public function serialize()
150
  {
151
+ return serialize(
152
+ array(
153
  $this->id(),
154
  $this->email(),
155
  $this->status(),
156
  $this->storeview(),
157
  is_object($customer = $this->customer()) ? $customer->id() : null,
158
+ )
159
+ );
160
  }
161
 
162
  /**
163
  * Unserialize the object
164
  *
165
+ * @param string $string
166
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Subscription
167
  */
168
  public function unserialize($string)
169
  {
app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Wishlist.php CHANGED
@@ -57,8 +57,8 @@ class Copernica_MarketingSoftware_Model_Abstraction_Wishlist implements Serializ
57
  /**
58
  * Sets the original model
59
  *
60
- * @param Mage_Wishlist_Model_Wishlist $original
61
- * @return Copernica_MarketingSoftware_Model_Abstraction_Wishlist
62
  */
63
  public function setOriginal(Mage_Wishlist_Model_Wishlist $original)
64
  {
@@ -70,8 +70,8 @@ class Copernica_MarketingSoftware_Model_Abstraction_Wishlist implements Serializ
70
  /**
71
  * Loads a wishlist model
72
  *
73
- * @param integer $wishlistId
74
- * @return Copernica_MarketingSoftware_Model_Abstraction_Wishlist
75
  */
76
  public function loadWishlist($wishlistId)
77
  {
@@ -80,14 +80,14 @@ class Copernica_MarketingSoftware_Model_Abstraction_Wishlist implements Serializ
80
  if (!is_callable($wishlist, 'loadByIdWithoutStore')) {
81
  $storeIDs = array();
82
 
83
- foreach (Mage::app()->getStores() as $id => $store) {
84
- $storeIDs[] = $id;
85
  }
86
 
87
  $wishlist->setSharedStoreIds($storeIDs);
88
  $wishlist->load($wishlistId);
89
  } else {
90
- $wishlist->loadByIdWithoutStore($wishlistId);
91
  }
92
 
93
  if ($wishlist->getId()) {
@@ -102,8 +102,8 @@ class Copernica_MarketingSoftware_Model_Abstraction_Wishlist implements Serializ
102
  /**
103
  * Import this abstract from a real magento one
104
  *
105
- * @param Mage_Wishlist_Model_Wishlist $original
106
- * @return Copernica_MarketingSoftware_Model_Abstraction_Wishlist
107
  */
108
  protected function _importFromObject(Mage_Wishlist_Model_Wishlist $original)
109
  {
@@ -151,14 +151,16 @@ class Copernica_MarketingSoftware_Model_Abstraction_Wishlist implements Serializ
151
  if ($payment = $original->getPayment()) {
152
  try {
153
  $this->_paymentDescription = $payment->getMethodInstance()->getTitle();
154
- } catch (Mage_Core_Exception $exception) { }
 
 
155
  }
156
  }
157
 
158
  /**
159
  * The wishlist id of this wishlist object
160
  *
161
- * @return integer
162
  */
163
  public function id()
164
  {
@@ -168,7 +170,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Wishlist implements Serializ
168
  /**
169
  * Is this wishlist still active
170
  *
171
- * @return boolean
172
  */
173
  public function active()
174
  {
@@ -178,7 +180,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Wishlist implements Serializ
178
  /**
179
  * The number of items present in this wishlist
180
  *
181
- * @return integer
182
  */
183
  public function quantity()
184
  {
@@ -188,7 +190,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Wishlist implements Serializ
188
  /**
189
  * The payment currency of this wishlist
190
  *
191
- * @return string
192
  */
193
  public function currency()
194
  {
@@ -199,7 +201,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Wishlist implements Serializ
199
  * The price
200
  * Note that an object is returned, which may consist of multiple components
201
  *
202
- * @return Copernica_MarketingSoftware_Model_Abstraction_Price
203
  */
204
  public function price()
205
  {
@@ -209,7 +211,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Wishlist implements Serializ
209
  /**
210
  * The weight
211
  *
212
- * @return float
213
  */
214
  public function weight()
215
  {
@@ -219,7 +221,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Wishlist implements Serializ
219
  /**
220
  * To what storeview does this wishlist belong
221
  *
222
- * @return Copernica_MarketingSoftware_Model_Abstraction_Storeview
223
  */
224
  public function storeview()
225
  {
@@ -229,7 +231,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Wishlist implements Serializ
229
  /**
230
  * Get the items from the wishlist
231
  *
232
- * @return array
233
  */
234
  public function items()
235
  {
@@ -239,7 +241,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Wishlist implements Serializ
239
  /**
240
  * The timestamp at which this wishlist was modified
241
  *
242
- * @return string
243
  */
244
  public function timestamp()
245
  {
@@ -249,7 +251,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Wishlist implements Serializ
249
  /**
250
  * The customer may return null
251
  *
252
- * @return Copernica_MarketingSoftware_Model_Abstraction_Customer|null
253
  */
254
  public function customer()
255
  {
@@ -263,7 +265,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Wishlist implements Serializ
263
  /**
264
  * The addresses of this wishlist
265
  *
266
- * @return array
267
  */
268
  public function addresses()
269
  {
@@ -273,7 +275,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Wishlist implements Serializ
273
  /**
274
  * The IP from which this wishlist was constructed
275
  *
276
- * @return string
277
  */
278
  public function customerIP()
279
  {
@@ -283,7 +285,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Wishlist implements Serializ
283
  /**
284
  * The shipping method of this wishlist
285
  *
286
- * @return string
287
  */
288
  public function shippingDescription()
289
  {
@@ -293,7 +295,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Wishlist implements Serializ
293
  /**
294
  * The payment method of this wishlist
295
  *
296
- * @return string
297
  */
298
  public function paymentDescription()
299
  {
@@ -303,16 +305,19 @@ class Copernica_MarketingSoftware_Model_Abstraction_Wishlist implements Serializ
303
  /**
304
  * Serialize the object
305
  *
306
- * @todo Two returns??
307
- * @return string
308
  */
309
  public function serialize()
310
  {
311
- return serialize(array(
 
312
  $this->id()
313
- ));
 
314
 
315
- return serialize(array(
 
316
  $this->id(),
317
  $this->quantity(),
318
  $this->currency(),
@@ -327,15 +332,16 @@ class Copernica_MarketingSoftware_Model_Abstraction_Wishlist implements Serializ
327
  $this->active(),
328
  $this->shippingDescription(),
329
  $this->paymentDescription()
330
- ));
 
331
  }
332
 
333
  /**
334
  * Unserialize the object
335
  *
336
- * @todo Two returns??
337
- * @param string $string
338
- * @return Copernica_MarketingSoftware_Model_Abstraction_Wishlist
339
  */
340
  public function unserialize($string)
341
  {
@@ -366,4 +372,4 @@ class Copernica_MarketingSoftware_Model_Abstraction_Wishlist implements Serializ
366
 
367
  return $this;
368
  }
369
- }
57
  /**
58
  * Sets the original model
59
  *
60
+ * @param Mage_Wishlist_Model_Wishlist $original
61
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Wishlist
62
  */
63
  public function setOriginal(Mage_Wishlist_Model_Wishlist $original)
64
  {
70
  /**
71
  * Loads a wishlist model
72
  *
73
+ * @param integer $wishlistId
74
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Wishlist
75
  */
76
  public function loadWishlist($wishlistId)
77
  {
80
  if (!is_callable($wishlist, 'loadByIdWithoutStore')) {
81
  $storeIDs = array();
82
 
83
+ foreach (Mage::app()->getStores() as $id => $store) {
84
+ $storeIDs[] = $id;
85
  }
86
 
87
  $wishlist->setSharedStoreIds($storeIDs);
88
  $wishlist->load($wishlistId);
89
  } else {
90
+ $wishlist->loadByIdWithoutStore($wishlistId);
91
  }
92
 
93
  if ($wishlist->getId()) {
102
  /**
103
  * Import this abstract from a real magento one
104
  *
105
+ * @param Mage_Wishlist_Model_Wishlist $original
106
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Wishlist
107
  */
108
  protected function _importFromObject(Mage_Wishlist_Model_Wishlist $original)
109
  {
151
  if ($payment = $original->getPayment()) {
152
  try {
153
  $this->_paymentDescription = $payment->getMethodInstance()->getTitle();
154
+ } catch (Mage_Core_Exception $exception) {
155
+ Mage::logException($exception);
156
+ }
157
  }
158
  }
159
 
160
  /**
161
  * The wishlist id of this wishlist object
162
  *
163
+ * @return integer
164
  */
165
  public function id()
166
  {
170
  /**
171
  * Is this wishlist still active
172
  *
173
+ * @return boolean
174
  */
175
  public function active()
176
  {
180
  /**
181
  * The number of items present in this wishlist
182
  *
183
+ * @return integer
184
  */
185
  public function quantity()
186
  {
190
  /**
191
  * The payment currency of this wishlist
192
  *
193
+ * @return string
194
  */
195
  public function currency()
196
  {
201
  * The price
202
  * Note that an object is returned, which may consist of multiple components
203
  *
204
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Price
205
  */
206
  public function price()
207
  {
211
  /**
212
  * The weight
213
  *
214
+ * @return float
215
  */
216
  public function weight()
217
  {
221
  /**
222
  * To what storeview does this wishlist belong
223
  *
224
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Storeview
225
  */
226
  public function storeview()
227
  {
231
  /**
232
  * Get the items from the wishlist
233
  *
234
+ * @return array
235
  */
236
  public function items()
237
  {
241
  /**
242
  * The timestamp at which this wishlist was modified
243
  *
244
+ * @return string
245
  */
246
  public function timestamp()
247
  {
251
  /**
252
  * The customer may return null
253
  *
254
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Customer|null
255
  */
256
  public function customer()
257
  {
265
  /**
266
  * The addresses of this wishlist
267
  *
268
+ * @return array
269
  */
270
  public function addresses()
271
  {
275
  /**
276
  * The IP from which this wishlist was constructed
277
  *
278
+ * @return string
279
  */
280
  public function customerIP()
281
  {
285
  /**
286
  * The shipping method of this wishlist
287
  *
288
+ * @return string
289
  */
290
  public function shippingDescription()
291
  {
295
  /**
296
  * The payment method of this wishlist
297
  *
298
+ * @return string
299
  */
300
  public function paymentDescription()
301
  {
305
  /**
306
  * Serialize the object
307
  *
308
+ * @todo Two returns??
309
+ * @return string
310
  */
311
  public function serialize()
312
  {
313
+ return serialize(
314
+ array(
315
  $this->id()
316
+ )
317
+ );
318
 
319
+ return serialize(
320
+ array(
321
  $this->id(),
322
  $this->quantity(),
323
  $this->currency(),
332
  $this->active(),
333
  $this->shippingDescription(),
334
  $this->paymentDescription()
335
+ )
336
+ );
337
  }
338
 
339
  /**
340
  * Unserialize the object
341
  *
342
+ * @todo Two returns??
343
+ * @param string $string
344
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Wishlist
345
  */
346
  public function unserialize($string)
347
  {
372
 
373
  return $this;
374
  }
375
+ }
app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Wishlist/Item.php CHANGED
@@ -44,8 +44,8 @@ class Copernica_MarketingSoftware_Model_Abstraction_Wishlist_Item implements Ser
44
  /**
45
  * Sets the original model
46
  *
47
- * @param Mage_Wishlist_Model_Item $original
48
- * @return Copernica_MarketingSoftware_Model_Abstraction_Wishlist_Item
49
  */
50
  public function setOriginal(Mage_Wishlist_Model_Item $original)
51
  {
@@ -69,7 +69,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Wishlist_Item implements Ser
69
  /**
70
  * The id of this wishlist item object
71
  *
72
- * @return integer
73
  */
74
  public function id()
75
  {
@@ -79,7 +79,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Wishlist_Item implements Ser
79
  /**
80
  * Get the wishlist to which this item belongs
81
  *
82
- * @return Copernica_MarketingSoftware_Model_Abstraction_Wishlist
83
  */
84
  public function wishlist()
85
  {
@@ -89,7 +89,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Wishlist_Item implements Ser
89
  /**
90
  * The amount of this wishlist item
91
  *
92
- * @return integer
93
  */
94
  public function quantity()
95
  {
@@ -100,7 +100,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Wishlist_Item implements Ser
100
  * The price
101
  * Note that an object is returned, which may consist of multiple components
102
  *
103
- * @return Copernica_MarketingSoftware_Model_Abstraction_Price
104
  */
105
  public function price()
106
  {
@@ -110,7 +110,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Wishlist_Item implements Ser
110
  /**
111
  * The weight
112
  *
113
- * @return float
114
  */
115
  public function weight()
116
  {
@@ -120,7 +120,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Wishlist_Item implements Ser
120
  /**
121
  * The timestamp at which this wishlist item was modified
122
  *
123
- * @return string
124
  */
125
  public function timestamp()
126
  {
@@ -130,7 +130,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Wishlist_Item implements Ser
130
  /**
131
  * Get the options of this wishlist item
132
  *
133
- * @return Copernica_MarketingSoftware_Model_Abstraction_Wishlist_Item_Options
134
  */
135
  public function options()
136
  {
@@ -140,7 +140,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Wishlist_Item implements Ser
140
  /**
141
  * Get the product which belongs to this item
142
  *
143
- * @return Copernica_MarketingSoftware_Model_Abstraction_Product
144
  */
145
  public function product()
146
  {
@@ -150,30 +150,31 @@ class Copernica_MarketingSoftware_Model_Abstraction_Wishlist_Item implements Ser
150
  /**
151
  * Loads a wishlist model
152
  *
153
- * @param integer $wishlistId
154
- * @return Copernica_MarketingSoftware_Model_Abstraction_Wishlist_Item
155
  */
156
  public function loadWishlistItem($wishlistItemId)
157
  {
158
- $wishlistItem = Mage::getModel('wishlist/item')->load($wishlistItemId);
159
-
160
- if ($wishlistItem->getId()) {
161
- $this->setOriginal($wishlistItem);
162
- } else {
163
- $this->id = $wishlistItemId;
164
- }
165
-
166
- return $this;
167
  }
168
 
169
  /**
170
  * Serialize the object
171
  *
172
- * @return string
173
  */
174
  public function serialize()
175
  {
176
- return serialize(array(
 
177
  $this->id(),
178
  is_object($wishlist = $this->wishlist()) ? $wishlist->id() : null,
179
  $this->quantity(),
@@ -182,14 +183,15 @@ class Copernica_MarketingSoftware_Model_Abstraction_Wishlist_Item implements Ser
182
  $this->timestamp(),
183
  $this->options(),
184
  $this->product(),
185
- ));
 
186
  }
187
 
188
  /**
189
  * Unserialize the object
190
  *
191
- * @param string $string
192
- * @return Copernica_MarketingSoftware_Model_Abstraction_Wishlist_Item
193
  */
194
  public function unserialize($string)
195
  {
@@ -206,4 +208,4 @@ class Copernica_MarketingSoftware_Model_Abstraction_Wishlist_Item implements Ser
206
 
207
  return $this;
208
  }
209
- }
44
  /**
45
  * Sets the original model
46
  *
47
+ * @param Mage_Wishlist_Model_Item $original
48
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Wishlist_Item
49
  */
50
  public function setOriginal(Mage_Wishlist_Model_Item $original)
51
  {
69
  /**
70
  * The id of this wishlist item object
71
  *
72
+ * @return integer
73
  */
74
  public function id()
75
  {
79
  /**
80
  * Get the wishlist to which this item belongs
81
  *
82
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Wishlist
83
  */
84
  public function wishlist()
85
  {
89
  /**
90
  * The amount of this wishlist item
91
  *
92
+ * @return integer
93
  */
94
  public function quantity()
95
  {
100
  * The price
101
  * Note that an object is returned, which may consist of multiple components
102
  *
103
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Price
104
  */
105
  public function price()
106
  {
110
  /**
111
  * The weight
112
  *
113
+ * @return float
114
  */
115
  public function weight()
116
  {
120
  /**
121
  * The timestamp at which this wishlist item was modified
122
  *
123
+ * @return string
124
  */
125
  public function timestamp()
126
  {
130
  /**
131
  * Get the options of this wishlist item
132
  *
133
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Wishlist_Item_Options
134
  */
135
  public function options()
136
  {
140
  /**
141
  * Get the product which belongs to this item
142
  *
143
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Product
144
  */
145
  public function product()
146
  {
150
  /**
151
  * Loads a wishlist model
152
  *
153
+ * @param integer $wishlistId
154
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Wishlist_Item
155
  */
156
  public function loadWishlistItem($wishlistItemId)
157
  {
158
+ $wishlistItem = Mage::getModel('wishlist/item')->load($wishlistItemId);
159
+
160
+ if ($wishlistItem->getId()) {
161
+ $this->setOriginal($wishlistItem);
162
+ } else {
163
+ $this->id = $wishlistItemId;
164
+ }
165
+
166
+ return $this;
167
  }
168
 
169
  /**
170
  * Serialize the object
171
  *
172
+ * @return string
173
  */
174
  public function serialize()
175
  {
176
+ return serialize(
177
+ array(
178
  $this->id(),
179
  is_object($wishlist = $this->wishlist()) ? $wishlist->id() : null,
180
  $this->quantity(),
183
  $this->timestamp(),
184
  $this->options(),
185
  $this->product(),
186
+ )
187
+ );
188
  }
189
 
190
  /**
191
  * Unserialize the object
192
  *
193
+ * @param string $string
194
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Wishlist_Item
195
  */
196
  public function unserialize($string)
197
  {
208
 
209
  return $this;
210
  }
211
+ }
app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Wishlist/Item/Options.php CHANGED
@@ -39,8 +39,8 @@ class Copernica_MarketingSoftware_Model_Abstraction_Wishlist_Item_Options implem
39
  /**
40
  * Sets the original model
41
  *
42
- * @param Mage_Wishlist_Model_Item $original
43
- * @return Copernica_MarketingSoftware_Model_Abstraction_Wishlist_Item_Options
44
  */
45
  public function setOriginal(Mage_Wishlist_Model_Item $original)
46
  {
@@ -78,7 +78,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Wishlist_Item_Options implem
78
  /**
79
  * The name of this set of options
80
  *
81
- * @return integer
82
  */
83
  public function name()
84
  {
@@ -88,7 +88,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Wishlist_Item_Options implem
88
  /**
89
  * Return an assoc array with attributes
90
  *
91
- * @return array
92
  */
93
  public function attributes()
94
  {
@@ -98,7 +98,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Wishlist_Item_Options implem
98
  /**
99
  * Return a string representation
100
  *
101
- * @return string
102
  */
103
  public function __toString()
104
  {
@@ -108,9 +108,9 @@ class Copernica_MarketingSoftware_Model_Abstraction_Wishlist_Item_Options implem
108
  /**
109
  * Return a string representation of an array
110
  *
111
- * @param array $value
112
- * @param string $prefix
113
- * @return string
114
  */
115
  protected function _arrayToString($value, $prefix = '')
116
  {
@@ -119,12 +119,12 @@ class Copernica_MarketingSoftware_Model_Abstraction_Wishlist_Item_Options implem
119
  foreach ($value as $key => $value) {
120
  if (is_array($value)) {
121
  if (isset($value[0]) && count($value) == 1) {
122
- $value = $value[0];
123
  }
124
 
125
  $string .= $prefix.$key.":\n".$this->_arrayToString($value, $prefix.' ');
126
  } else {
127
- $string.= $prefix.$key.": $value\n";
128
  }
129
  }
130
 
@@ -134,21 +134,23 @@ class Copernica_MarketingSoftware_Model_Abstraction_Wishlist_Item_Options implem
134
  /**
135
  * Serialize the object
136
  *
137
- * @return string
138
  */
139
  public function serialize()
140
  {
141
- return serialize(array(
 
142
  $this->name(),
143
  $this->attributes(),
144
- ));
 
145
  }
146
 
147
  /**
148
  * Unserialize the object
149
  *
150
- * @param string $string
151
- * @return Copernica_MarketingSoftware_Model_Abstraction_Wishlist_Item_Options
152
  */
153
  public function unserialize($string)
154
  {
39
  /**
40
  * Sets the original model
41
  *
42
+ * @param Mage_Wishlist_Model_Item $original
43
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Wishlist_Item_Options
44
  */
45
  public function setOriginal(Mage_Wishlist_Model_Item $original)
46
  {
78
  /**
79
  * The name of this set of options
80
  *
81
+ * @return integer
82
  */
83
  public function name()
84
  {
88
  /**
89
  * Return an assoc array with attributes
90
  *
91
+ * @return array
92
  */
93
  public function attributes()
94
  {
98
  /**
99
  * Return a string representation
100
  *
101
+ * @return string
102
  */
103
  public function __toString()
104
  {
108
  /**
109
  * Return a string representation of an array
110
  *
111
+ * @param array $value
112
+ * @param string $prefix
113
+ * @return string
114
  */
115
  protected function _arrayToString($value, $prefix = '')
116
  {
119
  foreach ($value as $key => $value) {
120
  if (is_array($value)) {
121
  if (isset($value[0]) && count($value) == 1) {
122
+ $value = $value[0];
123
  }
124
 
125
  $string .= $prefix.$key.":\n".$this->_arrayToString($value, $prefix.' ');
126
  } else {
127
+ $string.= $prefix.$key.": $value\n";
128
  }
129
  }
130
 
134
  /**
135
  * Serialize the object
136
  *
137
+ * @return string
138
  */
139
  public function serialize()
140
  {
141
+ return serialize(
142
+ array(
143
  $this->name(),
144
  $this->attributes(),
145
+ )
146
+ );
147
  }
148
 
149
  /**
150
  * Unserialize the object
151
  *
152
+ * @param string $string
153
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Wishlist_Item_Options
154
  */
155
  public function unserialize($string)
156
  {
app/code/community/Copernica/MarketingSoftware/Model/Config.php CHANGED
@@ -38,7 +38,7 @@ class Copernica_MarketingSoftware_Model_Config extends Mage_Core_Model_Abstract
38
  /**
39
  * Constructor
40
  *
41
- * @see Varien_Object::_construct()
42
  */
43
  protected function _construct()
44
  {
@@ -48,7 +48,7 @@ class Copernica_MarketingSoftware_Model_Config extends Mage_Core_Model_Abstract
48
  /**
49
  * Load configuration row by it's key.
50
  *
51
- * @param string $key
52
  * @return Copernica_MarketingSoftware_Model_Config
53
  */
54
  public function loadByKey($key)
@@ -61,4 +61,4 @@ class Copernica_MarketingSoftware_Model_Config extends Mage_Core_Model_Abstract
61
 
62
  return $this;
63
  }
64
- }
38
  /**
39
  * Constructor
40
  *
41
+ * @see Varien_Object::_construct()
42
  */
43
  protected function _construct()
44
  {
48
  /**
49
  * Load configuration row by it's key.
50
  *
51
+ * @param string $key
52
  * @return Copernica_MarketingSoftware_Model_Config
53
  */
54
  public function loadByKey($key)
61
 
62
  return $this;
63
  }
64
+ }
app/code/community/Copernica/MarketingSoftware/Model/Copernica/Abstract.php CHANGED
@@ -32,15 +32,15 @@ abstract class Copernica_MarketingSoftware_Model_Copernica_Abstract implements A
32
  /**
33
  * To where data will be saved? Posible values are 'copernica' and 'magento'
34
  *
35
- * @var String
36
  */
37
  protected $_direction = 'copernica';
38
 
39
  /**
40
  * Set the direction for this synchronisation
41
  *
42
- * @param string $direction
43
- * @return Copernica_MarketingSoftware_Model_Copernica_Orderitem_Subprofile
44
  */
45
  public function setDirection($direction)
46
  {
@@ -80,7 +80,7 @@ abstract class Copernica_MarketingSoftware_Model_Copernica_Abstract implements A
80
  /**
81
  * Check if offset exists in array
82
  *
83
- * @param mixed $offset
84
  * @return boolean
85
  */
86
  public function offsetExists($offset)
@@ -93,7 +93,7 @@ abstract class Copernica_MarketingSoftware_Model_Copernica_Abstract implements A
93
  /**
94
  * Get offset in array
95
  *
96
- * @param mixed $offset
97
  * @return mixed
98
  */
99
  public function offsetGet($offset)
@@ -113,18 +113,18 @@ abstract class Copernica_MarketingSoftware_Model_Copernica_Abstract implements A
113
  $data = $this->_data();
114
 
115
  if ($this->_direction == 'magento') {
116
- return $data;
117
  }
118
 
119
  $returndata = array();
120
 
121
  foreach ($this->requiredFields() as $field) {
122
- $returndata[$field] = $data[$field];
123
  }
124
 
125
  foreach ($this->linkedFields() as $magentoField => $copernicaField) {
126
  if (empty($copernicaField) || !isset($data[$magentoField])) {
127
- continue;
128
  }
129
 
130
  $returndata[$copernicaField] = $data[$magentoField];
@@ -137,8 +137,8 @@ abstract class Copernica_MarketingSoftware_Model_Copernica_Abstract implements A
137
  * Set entry in offset of array
138
  *
139
  * @deprecated
140
- * @param mixed $offset
141
- * @param mixed $value
142
  */
143
  public function offsetSet($offset, $value)
144
  {
@@ -149,7 +149,7 @@ abstract class Copernica_MarketingSoftware_Model_Copernica_Abstract implements A
149
  * Remove entry by offset in array
150
  *
151
  * @deprecated
152
- * @param mixed $offset
153
  */
154
  public function offsetUnset($offset)
155
  {
32
  /**
33
  * To where data will be saved? Posible values are 'copernica' and 'magento'
34
  *
35
+ * @var String
36
  */
37
  protected $_direction = 'copernica';
38
 
39
  /**
40
  * Set the direction for this synchronisation
41
  *
42
+ * @param string $direction
43
+ * @return Copernica_MarketingSoftware_Model_Copernica_Orderitem_Subprofile
44
  */
45
  public function setDirection($direction)
46
  {
80
  /**
81
  * Check if offset exists in array
82
  *
83
+ * @param mixed $offset
84
  * @return boolean
85
  */
86
  public function offsetExists($offset)
93
  /**
94
  * Get offset in array
95
  *
96
+ * @param mixed $offset
97
  * @return mixed
98
  */
99
  public function offsetGet($offset)
113
  $data = $this->_data();
114
 
115
  if ($this->_direction == 'magento') {
116
+ return $data;
117
  }
118
 
119
  $returndata = array();
120
 
121
  foreach ($this->requiredFields() as $field) {
122
+ $returndata[$field] = $data[$field];
123
  }
124
 
125
  foreach ($this->linkedFields() as $magentoField => $copernicaField) {
126
  if (empty($copernicaField) || !isset($data[$magentoField])) {
127
+ continue;
128
  }
129
 
130
  $returndata[$copernicaField] = $data[$magentoField];
137
  * Set entry in offset of array
138
  *
139
  * @deprecated
140
+ * @param mixed $offset
141
+ * @param mixed $value
142
  */
143
  public function offsetSet($offset, $value)
144
  {
149
  * Remove entry by offset in array
150
  *
151
  * @deprecated
152
+ * @param mixed $offset
153
  */
154
  public function offsetUnset($offset)
155
  {
app/code/community/Copernica/MarketingSoftware/Model/Copernica/Address/Subprofile.php CHANGED
@@ -42,7 +42,7 @@ class Copernica_MarketingSoftware_Model_Copernica_Address_Subprofile extends Cop
42
  /**
43
  * Try to store a quote item
44
  *
45
- * @param Copernica_MarketingSoftware_Model_Abstraction_Address $address
46
  */
47
  public function setAddress($address)
48
  {
42
  /**
43
  * Try to store a quote item
44
  *
45
+ * @param Copernica_MarketingSoftware_Model_Abstraction_Address $address
46
  */
47
  public function setAddress($address)
48
  {
app/code/community/Copernica/MarketingSoftware/Model/Copernica/Entity.php CHANGED
@@ -32,51 +32,51 @@ abstract class Copernica_MarketingSoftware_Model_Copernica_Entity
32
  /**
33
  * Cached data.
34
  *
35
- * @var array
36
  */
37
  protected $_data = array();
38
 
39
  /**
40
  * This is a factory method that will produce proper entities.
41
  *
42
- * @todo Verify whether it is actually needed
43
- * @param string $itemName
44
  * @return Copernica_MarketingSoftware_Model_Copernica_Entity
45
  */
46
  public function create($itemName)
47
  {
48
- $modelName = 'marketingsoftware/copernica_entity_'. $itemName;
49
-
50
- if (!class_exists(Mage::getConfig()->getModelClassName($modelName))) {
51
- return null;
52
- }
53
-
54
- return Mage::getModel($modelName);
55
  }
56
 
57
  /**
58
- * @todo param arguments
59
- * @param string $methodName
60
  */
61
  public function __call($methodName, $arguments)
62
  {
63
  if (substr($methodName, 0, 3) != 'get') {
64
- return null;
65
  }
66
 
67
  $property = substr($methodName, 3);
68
  $property{0} = strtolower($property{0});
69
 
70
  if (array_key_exists($property, $this->_data)) {
71
- return $this->_data[$property];
72
  }
73
 
74
  $fetchMethod = 'fetch'.ucfirst($property);
75
 
76
  if (method_exists($this, $fetchMethod) && !is_null($value = $this->$fetchMethod())) {
77
- return $this->_data[$property] = $value;
78
  }
79
 
80
  return null;
81
  }
82
- }
32
  /**
33
  * Cached data.
34
  *
35
+ * @var array
36
  */
37
  protected $_data = array();
38
 
39
  /**
40
  * This is a factory method that will produce proper entities.
41
  *
42
+ * @todo Verify whether it is actually needed
43
+ * @param string $itemName
44
  * @return Copernica_MarketingSoftware_Model_Copernica_Entity
45
  */
46
  public function create($itemName)
47
  {
48
+ $modelName = 'marketingsoftware/copernica_entity_'. $itemName;
49
+
50
+ if (!class_exists(Mage::getConfig()->getModelClassName($modelName))) {
51
+ return null;
52
+ }
53
+
54
+ return Mage::getModel($modelName);
55
  }
56
 
57
  /**
58
+ * @todo param arguments
59
+ * @param string $methodName
60
  */
61
  public function __call($methodName, $arguments)
62
  {
63
  if (substr($methodName, 0, 3) != 'get') {
64
+ return null;
65
  }
66
 
67
  $property = substr($methodName, 3);
68
  $property{0} = strtolower($property{0});
69
 
70
  if (array_key_exists($property, $this->_data)) {
71
+ return $this->_data[$property];
72
  }
73
 
74
  $fetchMethod = 'fetch'.ucfirst($property);
75
 
76
  if (method_exists($this, $fetchMethod) && !is_null($value = $this->$fetchMethod())) {
77
+ return $this->_data[$property] = $value;
78
  }
79
 
80
  return null;
81
  }
82
+ }
app/code/community/Copernica/MarketingSoftware/Model/Copernica/Entity/Address.php CHANGED
@@ -29,7 +29,7 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Address extends Coperni
29
  /**
30
  * Magento address model
31
  *
32
- * @var Mage_Customer_Model_Address
33
  */
34
  protected $_address = null;
35
 
@@ -42,50 +42,48 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Address extends Coperni
42
  {
43
  switch (get_class($this->_address)) {
44
  case 'Mage_Customer_Model_Address':
45
- return 'ca_'.$this->_address->getId();
46
-
47
  case 'Mage_Sales_Model_Order_Address':
48
  if ($customerAddressId = $this->_address->getCustomerAddressId()) {
49
- return 'ca_'.$customerAddressId;
50
- }
51
- else {
52
- return 'oa_'.$this->_address->getId();
53
  }
54
 
55
  case 'Mage_Sales_Model_Quote_Address':
56
  if ($customerAddressId = $this->_address->getCustomerAddressId()) {
57
- return 'ca_'.$customerAddressId;
58
- }
59
- else {
60
- return 'ca_'.$customerAddressId;
61
  }
62
 
63
  default:
64
- return $this->_address->getId();
65
  }
66
  }
67
 
68
  /**
69
  * Fetch email
70
  *
71
- * @return string
72
  */
73
  public function fetchEmail()
74
  {
75
  if ($email = $this->_address->getEmail()) {
76
- return $email;
77
  }
78
 
79
  if (is_object($order = $this->_address->getOrder()) && $email = $order->getCustomerEmail()) {
80
- return $email;
81
  }
82
 
83
  if (is_object($quote = $this->_address->getQuote()) && $email = $quote->getCustomerEmail()) {
84
- return $email;
85
  }
86
 
87
  if (is_object($customer = $this->_address->getCustomer()) && $email = $customer->getEmail()) {
88
- return $email;
89
  }
90
 
91
  return '';
@@ -94,7 +92,7 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Address extends Coperni
94
  /**
95
  * Fetch name object for this address
96
  *
97
- * @return Copernica_MarketingSoftware_Model_Abstraction_Name
98
  */
99
  public function fetchName()
100
  {
@@ -104,7 +102,7 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Address extends Coperni
104
  /**
105
  * Fetch firstname
106
  *
107
- * @return string
108
  */
109
  public function fetchFirstname()
110
  {
@@ -114,7 +112,7 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Address extends Coperni
114
  /**
115
  * Fetch middlename
116
  *
117
- * @return string
118
  */
119
  public function fetchMiddlename()
120
  {
@@ -124,7 +122,7 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Address extends Coperni
124
  /**
125
  * Fetch lastname
126
  *
127
- * @return string
128
  */
129
  public function fetchLastname()
130
  {
@@ -134,7 +132,7 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Address extends Coperni
134
  /**
135
  * Fetch prefix
136
  *
137
- * @return string
138
  */
139
  public function fetchPrefix()
140
  {
@@ -144,7 +142,7 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Address extends Coperni
144
  /**
145
  * Fetch street
146
  *
147
- * @return string
148
  */
149
  public function fetchStreet()
150
  {
@@ -154,7 +152,7 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Address extends Coperni
154
  /**
155
  * Fetch city
156
  *
157
- * @return string
158
  */
159
  public function fetchCity()
160
  {
@@ -164,7 +162,7 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Address extends Coperni
164
  /**
165
  * Fetch postal code
166
  *
167
- * @return string
168
  */
169
  public function fetchZipcode()
170
  {
@@ -174,7 +172,7 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Address extends Coperni
174
  /**
175
  * Fetch state
176
  *
177
- * @return string
178
  */
179
  public function fetchState()
180
  {
@@ -184,7 +182,7 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Address extends Coperni
184
  /**
185
  * Fetch country
186
  *
187
- * @return string
188
  */
189
  public function fetchCountryId()
190
  {
@@ -194,7 +192,7 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Address extends Coperni
194
  /**
195
  * Fetch company
196
  *
197
- * @return string
198
  */
199
  public function fetchCompany()
200
  {
@@ -204,7 +202,7 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Address extends Coperni
204
  /**
205
  * Fetch telephone
206
  *
207
- * @return string
208
  */
209
  public function fetchTelephone()
210
  {
@@ -214,7 +212,7 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Address extends Coperni
214
  /**
215
  * Fetch fax
216
  *
217
- * @return string
218
  */
219
  public function fetchFax()
220
  {
@@ -224,14 +222,14 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Address extends Coperni
224
  /**
225
  * Get REST address entity
226
  *
227
- * @return Copernica_MarketingSoftware_Model_Rest_Address
228
  */
229
  public function getRestAddress()
230
  {
231
- $restAddress = Mage::getModel('marketingsoftware/rest_address');
232
- $restAddress->setAddressEntity($this);
233
-
234
- return $restAddress;
235
  }
236
 
237
 
@@ -239,10 +237,10 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Address extends Coperni
239
  * Set address entity
240
  * It is expecting to receive one of magento address types.
241
  *
242
- * @param Mage_Customer_Model_Address|Mage_Sales_Model_Order_Address|Mage_Sales_Model_Quote_Address $address
243
  */
244
  public function setAddress($address)
245
  {
246
- $this->_address = $address;
247
  }
248
- }
29
  /**
30
  * Magento address model
31
  *
32
+ * @var Mage_Customer_Model_Address
33
  */
34
  protected $_address = null;
35
 
42
  {
43
  switch (get_class($this->_address)) {
44
  case 'Mage_Customer_Model_Address':
45
+ return 'ca_'.$this->_address->getId();
46
+
47
  case 'Mage_Sales_Model_Order_Address':
48
  if ($customerAddressId = $this->_address->getCustomerAddressId()) {
49
+ return 'ca_'.$customerAddressId;
50
+ } else {
51
+ return 'oa_'.$this->_address->getId();
 
52
  }
53
 
54
  case 'Mage_Sales_Model_Quote_Address':
55
  if ($customerAddressId = $this->_address->getCustomerAddressId()) {
56
+ return 'ca_'.$customerAddressId;
57
+ } else {
58
+ return 'ca_'.$customerAddressId;
 
59
  }
60
 
61
  default:
62
+ return $this->_address->getId();
63
  }
64
  }
65
 
66
  /**
67
  * Fetch email
68
  *
69
+ * @return string
70
  */
71
  public function fetchEmail()
72
  {
73
  if ($email = $this->_address->getEmail()) {
74
+ return $email;
75
  }
76
 
77
  if (is_object($order = $this->_address->getOrder()) && $email = $order->getCustomerEmail()) {
78
+ return $email;
79
  }
80
 
81
  if (is_object($quote = $this->_address->getQuote()) && $email = $quote->getCustomerEmail()) {
82
+ return $email;
83
  }
84
 
85
  if (is_object($customer = $this->_address->getCustomer()) && $email = $customer->getEmail()) {
86
+ return $email;
87
  }
88
 
89
  return '';
92
  /**
93
  * Fetch name object for this address
94
  *
95
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Name
96
  */
97
  public function fetchName()
98
  {
102
  /**
103
  * Fetch firstname
104
  *
105
+ * @return string
106
  */
107
  public function fetchFirstname()
108
  {
112
  /**
113
  * Fetch middlename
114
  *
115
+ * @return string
116
  */
117
  public function fetchMiddlename()
118
  {
122
  /**
123
  * Fetch lastname
124
  *
125
+ * @return string
126
  */
127
  public function fetchLastname()
128
  {
132
  /**
133
  * Fetch prefix
134
  *
135
+ * @return string
136
  */
137
  public function fetchPrefix()
138
  {
142
  /**
143
  * Fetch street
144
  *
145
+ * @return string
146
  */
147
  public function fetchStreet()
148
  {
152
  /**
153
  * Fetch city
154
  *
155
+ * @return string
156
  */
157
  public function fetchCity()
158
  {
162
  /**
163
  * Fetch postal code
164
  *
165
+ * @return string
166
  */
167
  public function fetchZipcode()
168
  {
172
  /**
173
  * Fetch state
174
  *
175
+ * @return string
176
  */
177
  public function fetchState()
178
  {
182
  /**
183
  * Fetch country
184
  *
185
+ * @return string
186
  */
187
  public function fetchCountryId()
188
  {
192
  /**
193
  * Fetch company
194
  *
195
+ * @return string
196
  */
197
  public function fetchCompany()
198
  {
202
  /**
203
  * Fetch telephone
204
  *
205
+ * @return string
206
  */
207
  public function fetchTelephone()
208
  {
212
  /**
213
  * Fetch fax
214
  *
215
+ * @return string
216
  */
217
  public function fetchFax()
218
  {
222
  /**
223
  * Get REST address entity
224
  *
225
+ * @return Copernica_MarketingSoftware_Model_Rest_Address
226
  */
227
  public function getRestAddress()
228
  {
229
+ $restAddress = Mage::getModel('marketingsoftware/rest_address');
230
+ $restAddress->setAddressEntity($this);
231
+
232
+ return $restAddress;
233
  }
234
 
235
 
237
  * Set address entity
238
  * It is expecting to receive one of magento address types.
239
  *
240
+ * @param Mage_Customer_Model_Address|Mage_Sales_Model_Order_Address|Mage_Sales_Model_Quote_Address $address
241
  */
242
  public function setAddress($address)
243
  {
244
+ $this->_address = $address;
245
  }
246
+ }
app/code/community/Copernica/MarketingSoftware/Model/Copernica/Entity/Customer.php CHANGED
@@ -32,21 +32,21 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Customer extends Copern
32
  /**
33
  * Magento customer
34
  *
35
- * @var Mage_Customer_Model_Customer
36
  */
37
  protected $_customer = null;
38
 
39
  /**
40
  * Array of customer addresses
41
  *
42
- * @var array
43
  */
44
  protected $_addresses = null;
45
 
46
  /**
47
  * Array of customer orders
48
  *
49
- * @var array
50
  */
51
  protected $_orders = null;
52
 
@@ -54,14 +54,14 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Customer extends Copern
54
  /**
55
  * Array of customer wishlist items
56
  *
57
- * @var array
58
  */
59
  protected $_wishlistItems = null;
60
 
61
  /**
62
  * Cache profile Id
63
  *
64
- * @var string
65
  */
66
  protected $_profileId = null;
67
 
@@ -78,12 +78,12 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Customer extends Copern
78
  * @return Copernica_MarketingSoftware_Model_Abstraction_Storeview
79
  */
80
  public function fetchStoreView()
81
- {
82
- if ($this->_store) {
83
- return $this->_store;
84
- } else {
85
- return Mage::getModel('marketingsoftware/abstraction_storeview')->setOriginal($this->_customer->getStore());
86
- }
87
  }
88
 
89
  /**
@@ -176,7 +176,7 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Customer extends Copern
176
  $subscriber = Mage::getModel('newsletter/subscriber')->loadByCustomer($this->_customer);
177
 
178
  if (!$subscriber->getId()) {
179
- return 'unknown';
180
  }
181
 
182
  switch($subscriber->getStatus()) {
@@ -210,7 +210,7 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Customer extends Copern
210
 
211
  foreach ($options as $option) {
212
  if ($option['value'] == $customerGenderIdx) {
213
- return $option['label'];
214
  }
215
  }
216
 
@@ -235,15 +235,15 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Customer extends Copern
235
  public function getAddresses()
236
  {
237
  if (!is_null($this->_addresses)) {
238
- return $this->_addresses;
239
  }
240
 
241
  $addresses = array();
242
 
243
  foreach ($this->_customer->getAddresses() as $address) {
244
- $addressEntity = Mage::getModel('marketingsoftware/copernica_entity_address');
245
- $addressEntity->setAddress($address);
246
-
247
  $addresses[] = $addressEntity;
248
  }
249
 
@@ -258,7 +258,7 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Customer extends Copern
258
  public function getOrders()
259
  {
260
  if (!is_null($this->_orders)) {
261
- return $this->_orders;
262
  }
263
 
264
  $orders = array();
@@ -266,9 +266,9 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Customer extends Copern
266
  $ordersCollection = Mage::getModel('sales/order')->getCollection()->addFieldToFilter('customer_id', $this->_customer->getId());
267
 
268
  foreach ($ordersCollection as $order) {
269
- $orderEntity = Mage::getModel('marketingsoftware/copernica_entity_order');
270
- $orderEntity->setOrder($order);
271
-
272
  $orders[] = $orderEntity;
273
  }
274
 
@@ -282,24 +282,24 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Customer extends Copern
282
  */
283
  public function getWishlistItems()
284
  {
285
- if (!is_null($this->_wishlistItems)) {
286
- return $this->_wishlistItems;
287
- }
288
 
289
- $wishlistItems = array();
290
 
291
- $wishlist = Mage::getModel('wishlist/wishlist')->loadByCustomer($this->getId());
292
-
293
- $wishlistItemCollection = Mage::getModel('wishlist/item')->getCollection()->addFieldToFilter('wishlist_id', $wishlist->getId());
294
-
295
- foreach ($wishlistItemCollection as $wishlistItem) {
296
- $wishlistItemEntity = Mage::getModel('marketingsoftware/copernica_entity_wishlist_item');
297
- $wishlistItemEntity->setWishlistItem($wishlistItem);
298
-
299
- $wishlistItems[] = $wishlistItemEntity;
300
- }
301
 
302
- return $this->_wishlistItems = $wishlistItems;
303
  }
304
 
305
  /**
@@ -319,33 +319,35 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Customer extends Copern
319
  */
320
  public function getRestCustomer()
321
  {
322
- $restCustomer = Mage::getModel('marketingsoftware/rest_customer');
323
- $restCustomer->setCustomerEntity($this);
324
-
325
- return $restCustomer;
326
  }
327
 
328
  /**
329
  * Get profile Id
330
  *
331
- * @param string $storeviewText
332
- * @param int $id
333
  * @return string|false
334
  */
335
  public function getProfileId()
336
  {
337
  if (!is_null($this->_profileId)) {
338
- return $this->_profileId;
339
  }
340
 
341
- $profileId = Mage::helper('marketingsoftware/api')->getProfileId(array(
 
342
  'id' => $this->getCustomerId(),
343
  'email' => $this->getEmail(),
344
  'storeView' => strval($this->getStoreView()),
345
- ));
 
346
 
347
  if ($profileId) {
348
- return $this->_profileId = $profileId;
349
  }
350
 
351
  return false;
@@ -354,31 +356,31 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Customer extends Copern
354
  /**
355
  * Set customer entity
356
  *
357
- * @param int $customerId
358
  */
359
  public function setCustomer($customerId)
360
  {
361
- $customer = Mage::getModel('customer/customer')->load($customerId);
362
-
363
- if (!$customer->isObjectNew()) {
364
- $this->_customer = $customer;
365
- } else {
366
- throw Mage::exception('Copernica_MarketingSoftware', 'Customer does not exists', Copernica_MarketingSoftware_Exception::CUSTOMER_NOT_EXISTS);
367
- }
368
  }
369
 
370
  /**
371
  * Set the storeView
372
  *
373
- * @param Copernica_MarketingSoftware_Model_Abstraction_Storeview $store
374
  */
375
  public function setStore($store)
376
  {
377
- if (!$this->_store || $this->_store->id() != $store->id()) {
378
- unset($this->_data['storeView']);
379
- unset($this->_data['customerId']);
380
- $this->_profileId = null;
381
- $this->_store = $store;
382
- }
383
  }
384
  }
32
  /**
33
  * Magento customer
34
  *
35
+ * @var Mage_Customer_Model_Customer
36
  */
37
  protected $_customer = null;
38
 
39
  /**
40
  * Array of customer addresses
41
  *
42
+ * @var array
43
  */
44
  protected $_addresses = null;
45
 
46
  /**
47
  * Array of customer orders
48
  *
49
+ * @var array
50
  */
51
  protected $_orders = null;
52
 
54
  /**
55
  * Array of customer wishlist items
56
  *
57
+ * @var array
58
  */
59
  protected $_wishlistItems = null;
60
 
61
  /**
62
  * Cache profile Id
63
  *
64
+ * @var string
65
  */
66
  protected $_profileId = null;
67
 
78
  * @return Copernica_MarketingSoftware_Model_Abstraction_Storeview
79
  */
80
  public function fetchStoreView()
81
+ {
82
+ if ($this->_store) {
83
+ return $this->_store;
84
+ } else {
85
+ return Mage::getModel('marketingsoftware/abstraction_storeview')->setOriginal($this->_customer->getStore());
86
+ }
87
  }
88
 
89
  /**
176
  $subscriber = Mage::getModel('newsletter/subscriber')->loadByCustomer($this->_customer);
177
 
178
  if (!$subscriber->getId()) {
179
+ return 'unknown';
180
  }
181
 
182
  switch($subscriber->getStatus()) {
210
 
211
  foreach ($options as $option) {
212
  if ($option['value'] == $customerGenderIdx) {
213
+ return $option['label'];
214
  }
215
  }
216
 
235
  public function getAddresses()
236
  {
237
  if (!is_null($this->_addresses)) {
238
+ return $this->_addresses;
239
  }
240
 
241
  $addresses = array();
242
 
243
  foreach ($this->_customer->getAddresses() as $address) {
244
+ $addressEntity = Mage::getModel('marketingsoftware/copernica_entity_address');
245
+ $addressEntity->setAddress($address);
246
+
247
  $addresses[] = $addressEntity;
248
  }
249
 
258
  public function getOrders()
259
  {
260
  if (!is_null($this->_orders)) {
261
+ return $this->_orders;
262
  }
263
 
264
  $orders = array();
266
  $ordersCollection = Mage::getModel('sales/order')->getCollection()->addFieldToFilter('customer_id', $this->_customer->getId());
267
 
268
  foreach ($ordersCollection as $order) {
269
+ $orderEntity = Mage::getModel('marketingsoftware/copernica_entity_order');
270
+ $orderEntity->setOrder($order);
271
+
272
  $orders[] = $orderEntity;
273
  }
274
 
282
  */
283
  public function getWishlistItems()
284
  {
285
+ if (!is_null($this->_wishlistItems)) {
286
+ return $this->_wishlistItems;
287
+ }
288
 
289
+ $wishlistItems = array();
290
 
291
+ $wishlist = Mage::getModel('wishlist/wishlist')->loadByCustomer($this->getId());
292
+
293
+ $wishlistItemCollection = Mage::getModel('wishlist/item')->getCollection()->addFieldToFilter('wishlist_id', $wishlist->getId());
294
+
295
+ foreach ($wishlistItemCollection as $wishlistItem) {
296
+ $wishlistItemEntity = Mage::getModel('marketingsoftware/copernica_entity_wishlist_item');
297
+ $wishlistItemEntity->setWishlistItem($wishlistItem);
298
+
299
+ $wishlistItems[] = $wishlistItemEntity;
300
+ }
301
 
302
+ return $this->_wishlistItems = $wishlistItems;
303
  }
304
 
305
  /**
319
  */
320
  public function getRestCustomer()
321
  {
322
+ $restCustomer = Mage::getModel('marketingsoftware/rest_customer');
323
+ $restCustomer->setCustomerEntity($this);
324
+
325
+ return $restCustomer;
326
  }
327
 
328
  /**
329
  * Get profile Id
330
  *
331
+ * @param string $storeviewText
332
+ * @param int $id
333
  * @return string|false
334
  */
335
  public function getProfileId()
336
  {
337
  if (!is_null($this->_profileId)) {
338
+ return $this->_profileId;
339
  }
340
 
341
+ $profileId = Mage::helper('marketingsoftware/api')->getProfileId(
342
+ array(
343
  'id' => $this->getCustomerId(),
344
  'email' => $this->getEmail(),
345
  'storeView' => strval($this->getStoreView()),
346
+ )
347
+ );
348
 
349
  if ($profileId) {
350
+ return $this->_profileId = $profileId;
351
  }
352
 
353
  return false;
356
  /**
357
  * Set customer entity
358
  *
359
+ * @param int $customerId
360
  */
361
  public function setCustomer($customerId)
362
  {
363
+ $customer = Mage::getModel('customer/customer')->load($customerId);
364
+
365
+ if (!$customer->isObjectNew()) {
366
+ $this->_customer = $customer;
367
+ } else {
368
+ throw Mage::exception('Copernica_MarketingSoftware', 'Customer does not exists', Copernica_MarketingSoftware_Exception::CUSTOMER_NOT_EXISTS);
369
+ }
370
  }
371
 
372
  /**
373
  * Set the storeView
374
  *
375
+ * @param Copernica_MarketingSoftware_Model_Abstraction_Storeview $store
376
  */
377
  public function setStore($store)
378
  {
379
+ if (!$this->_store || $this->_store->id() != $store->id()) {
380
+ unset($this->_data['storeView']);
381
+ unset($this->_data['customerId']);
382
+ $this->_profileId = null;
383
+ $this->_store = $store;
384
+ }
385
  }
386
  }
app/code/community/Copernica/MarketingSoftware/Model/Copernica/Entity/Order.php CHANGED
@@ -32,14 +32,14 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Order extends Copernica
32
  /**
33
  * Cached order instance
34
  *
35
- * @var Mage_Sales_Model_Order
36
  */
37
  protected $_order = null;
38
 
39
  /**
40
  * Cache for order items
41
  *
42
- * @var array
43
  */
44
  protected $_items = null;
45
 
@@ -164,6 +164,38 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Order extends Copernica
164
  return $this->_order->getWeight();
165
  }
166
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
167
  /**
168
  * Get last modification date
169
  *
@@ -171,7 +203,7 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Order extends Copernica
171
  */
172
  public function fetchUpdatedAt()
173
  {
174
- return $this->_order->getUpdatedAt();
175
  }
176
 
177
  /**
@@ -181,7 +213,7 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Order extends Copernica
181
  */
182
  public function fetchCreatedAt()
183
  {
184
- return $this->_order->getCreatedAt();
185
  }
186
 
187
  /**
@@ -215,7 +247,9 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Order extends Copernica
215
  try {
216
  if ($payment->getMethod() == 'klarna_partpayment') return 'Klarna';
217
  else return $payment->getMethodInstance()->getTitle();
218
- } catch (Mage_Core_Exception $exception) { }
 
 
219
  }
220
 
221
  return '';
@@ -232,10 +266,10 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Order extends Copernica
232
  $address = $this->_order->getShippingAddress();
233
 
234
  if (is_object($address)) {
235
- $addressEntity = Mage::getModel('marketingsoftware/copernica_entity_address');
236
- $addressEntity->setAddress($address);
237
-
238
- return $addressEntity;
239
  }
240
 
241
  // $addresses = $this->_order->getAddressesCollection();
@@ -247,17 +281,17 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Order extends Copernica
247
  * Get billing address. When no valid address can be found this method will
248
  * return null value.
249
  *
250
- * @return Copernica_MarketingSoftware_Model_Copernica_Entity_Address
251
  */
252
  public function fetchBillingAddress()
253
  {
254
  $address = $this->_order->getBillingAddress();
255
 
256
  if (is_object($address)) {
257
- $addressEntity = Mage::getModel('marketingsoftware/copernica_entity_address');
258
- $addressEntity->setAddress($address);
259
-
260
- return $addressEntity;
261
  }
262
 
263
  // foreach($this->_order->getAddressCollection() as $magentoAddress) {
@@ -275,7 +309,7 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Order extends Copernica
275
  public function fetchShippingAddressId()
276
  {
277
  if (is_object($address = $this->getShippingAddress())) {
278
- return $address->getId();
279
  }
280
 
281
  return null;
@@ -289,7 +323,7 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Order extends Copernica
289
  public function fetchBillingAddressId()
290
  {
291
  if (is_object($address = $this->getBillingAddress())) {
292
- return $address->getId();
293
  }
294
 
295
  return null;
@@ -303,16 +337,16 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Order extends Copernica
303
  public function getItems()
304
  {
305
  if (!is_null($this->_items)) {
306
- return $this->_items;
307
  }
308
 
309
  $data = array();
310
 
311
  foreach ($this->_order->getAllItems() as $orderItem) {
312
- $orderItemEntity = Mage::getModel('marketingsoftware/copernica_entity_order_item');
313
- $orderItemEntity->setOrderItem($orderItem);
314
-
315
- $data[] = $orderItemEntity;
316
  }
317
 
318
  return $this->_items = $data;
@@ -330,9 +364,9 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Order extends Copernica
330
  $convertedAddresses = array();
331
 
332
  foreach ($addresses as $address) {
333
- $addressEntity = Mage::getModel('marketingsoftware/copernica_entity_address');
334
- $addressEntity->setAddress($address);
335
-
336
  $convertedAddresses[] = $addressEntity;
337
  }
338
 
@@ -356,19 +390,19 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Order extends Copernica
356
  */
357
  public function getRestOrder()
358
  {
359
- $restOrder = Mage::getModel('marketingsoftware/rest_order');
360
- $restOrder->setOrderEntity($this);
361
-
362
- return $restOrder;
363
  }
364
 
365
  /**
366
  * Set copernica order
367
  *
368
- * @param Mage_Sales_Model_Order $order
369
  */
370
  public function setOrder($order)
371
  {
372
- $this->_order = $order;
373
  }
374
- }
32
  /**
33
  * Cached order instance
34
  *
35
+ * @var Mage_Sales_Model_Order
36
  */
37
  protected $_order = null;
38
 
39
  /**
40
  * Cache for order items
41
  *
42
+ * @var array
43
  */
44
  protected $_items = null;
45
 
164
  return $this->_order->getWeight();
165
  }
166
 
167
+ /**
168
+ * Get product creation date
169
+ *
170
+ * @return string
171
+ */
172
+ public function fetchTrackAndTrace()
173
+ {
174
+ $trackAndTrace = '';
175
+
176
+ $shipments = $this->_order->getShipmentsCollection();
177
+
178
+ if (count($shipments) > 0) {
179
+ /* @var Mage_Sales_Model_Order_Shipment $shipment */
180
+ foreach ($shipments as $shipment) {
181
+ $tracks = $shipment->getAllTracks();
182
+
183
+ if (count($tracks) > 0) {
184
+ /* @var Mage_Sales_Model_Order_Shipment_Track $track */
185
+ foreach ($tracks as $track) {
186
+ $trackAndTrace .= "shipment_id:" . $shipment->getId();
187
+ $trackAndTrace .= "|title:" . $track->getTitle();
188
+ $trackAndTrace .= "|track_number:" . $track->getNumber();
189
+ $trackAndTrace .= "\n";
190
+ }
191
+ }
192
+ }
193
+ }
194
+
195
+ return $trackAndTrace;
196
+ }
197
+
198
+
199
  /**
200
  * Get last modification date
201
  *
203
  */
204
  public function fetchUpdatedAt()
205
  {
206
+ return $this->_order->getUpdatedAt();
207
  }
208
 
209
  /**
213
  */
214
  public function fetchCreatedAt()
215
  {
216
+ return $this->_order->getCreatedAt();
217
  }
218
 
219
  /**
247
  try {
248
  if ($payment->getMethod() == 'klarna_partpayment') return 'Klarna';
249
  else return $payment->getMethodInstance()->getTitle();
250
+ } catch (Mage_Core_Exception $exception) {
251
+ Mage::logException($exception);
252
+ }
253
  }
254
 
255
  return '';
266
  $address = $this->_order->getShippingAddress();
267
 
268
  if (is_object($address)) {
269
+ $addressEntity = Mage::getModel('marketingsoftware/copernica_entity_address');
270
+ $addressEntity->setAddress($address);
271
+
272
+ return $addressEntity;
273
  }
274
 
275
  // $addresses = $this->_order->getAddressesCollection();
281
  * Get billing address. When no valid address can be found this method will
282
  * return null value.
283
  *
284
+ * @return Copernica_MarketingSoftware_Model_Copernica_Entity_Address
285
  */
286
  public function fetchBillingAddress()
287
  {
288
  $address = $this->_order->getBillingAddress();
289
 
290
  if (is_object($address)) {
291
+ $addressEntity = Mage::getModel('marketingsoftware/copernica_entity_address');
292
+ $addressEntity->setAddress($address);
293
+
294
+ return $addressEntity;
295
  }
296
 
297
  // foreach($this->_order->getAddressCollection() as $magentoAddress) {
309
  public function fetchShippingAddressId()
310
  {
311
  if (is_object($address = $this->getShippingAddress())) {
312
+ return $address->getId();
313
  }
314
 
315
  return null;
323
  public function fetchBillingAddressId()
324
  {
325
  if (is_object($address = $this->getBillingAddress())) {
326
+ return $address->getId();
327
  }
328
 
329
  return null;
337
  public function getItems()
338
  {
339
  if (!is_null($this->_items)) {
340
+ return $this->_items;
341
  }
342
 
343
  $data = array();
344
 
345
  foreach ($this->_order->getAllItems() as $orderItem) {
346
+ $orderItemEntity = Mage::getModel('marketingsoftware/copernica_entity_order_item');
347
+ $orderItemEntity->setOrderItem($orderItem);
348
+
349
+ $data[] = $orderItemEntity;
350
  }
351
 
352
  return $this->_items = $data;
364
  $convertedAddresses = array();
365
 
366
  foreach ($addresses as $address) {
367
+ $addressEntity = Mage::getModel('marketingsoftware/copernica_entity_address');
368
+ $addressEntity->setAddress($address);
369
+
370
  $convertedAddresses[] = $addressEntity;
371
  }
372
 
390
  */
391
  public function getRestOrder()
392
  {
393
+ $restOrder = Mage::getModel('marketingsoftware/rest_order');
394
+ $restOrder->setOrderEntity($this);
395
+
396
+ return $restOrder;
397
  }
398
 
399
  /**
400
  * Set copernica order
401
  *
402
+ * @param Mage_Sales_Model_Order $order
403
  */
404
  public function setOrder($order)
405
  {
406
+ $this->_order = $order;
407
  }
408
+ }
app/code/community/Copernica/MarketingSoftware/Model/Copernica/Entity/Order/Item.php CHANGED
@@ -32,7 +32,7 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Order_Item extends Cope
32
  /**
33
  * Cached item
34
  *
35
- * @var Mage_Sales_Model_Order_Item|Mage_Sales_Model_Quote_Item
36
  */
37
  protected $_orderItem = null;
38
 
@@ -43,7 +43,7 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Order_Item extends Cope
43
  */
44
  public function fetchId()
45
  {
46
- return $this->_orderItem->getId();
47
  }
48
 
49
  /**
@@ -54,7 +54,7 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Order_Item extends Cope
54
  public function fetchQuantity()
55
  {
56
  if ($this->_orderItem instanceOf Mage_Sales_Model_Quote_Item) {
57
- return $this->_orderItem->getQty();
58
  }
59
 
60
  return $this->_orderItem->getQtyOrdered();
@@ -107,9 +107,9 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Order_Item extends Cope
107
  */
108
  public function fetchStoreView()
109
  {
110
- $store = Mage::getModel('core/store')->load($this->getStoreId());
111
-
112
- return Mage::getModel('marketingsoftware/abstraction_storeview')->setOriginal($store);
113
  }
114
 
115
  /**
@@ -119,7 +119,7 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Order_Item extends Cope
119
  */
120
  public function getUpdatedAt()
121
  {
122
- return $this->_orderItem->getUpdatedAt();
123
  }
124
 
125
  /**
@@ -129,7 +129,7 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Order_Item extends Cope
129
  */
130
  public function getCreatedAt()
131
  {
132
- return $this->_orderItem->getCreatedAt();
133
  }
134
 
135
  /**
@@ -139,7 +139,11 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Order_Item extends Cope
139
  */
140
  public function fetchStatus()
141
  {
142
- return $this->_orderItem->getStatus();
 
 
 
 
143
  }
144
 
145
  /**
@@ -150,15 +154,15 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Order_Item extends Cope
150
  public function getStoreId()
151
  {
152
  if ($this->_orderItem instanceof Mage_Sales_Model_Quote_Item) {
153
- if ($this->_orderItem->getQuote()) {
154
- return $this->_orderItem->getQuote()->getStoreId();
155
- } elseif ($this->_orderItem->getQuoteId()) {
156
- return Mage::getModel('sales/quote')->loadByIdWithoutStore($this->_orderItem->getQuoteId())->getStoreId();
157
- } else {
158
- throw new Exception(Mage::helper('marketingsoftware')->__("Could not load store id from quote."));
159
- }
160
  } elseif ($this->_orderItem instanceof Mage_Sales_Model_Order_Item) {
161
- return $this->_orderItem->getOrder()->getStoreId();
162
  }
163
 
164
  return 0;
@@ -177,8 +181,8 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Order_Item extends Cope
177
  /**
178
  * Options can be nested so this function will allow us to parse them in recursive manner.
179
  *
180
- * @param mixed $values
181
- * @param string $prefix
182
  * @return string
183
  */
184
  protected function _stringifyOptions($values, $prefix = '')
@@ -188,12 +192,12 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Order_Item extends Cope
188
  foreach ($values as $value) {
189
  if (is_array($value['value'])) {
190
  if (isset($value['value'][0]) && count($value['value']) == 1) {
191
- $value['value'] = $value['value'][0];
192
  }
193
 
194
  $result .= $prefix.$value['label'].":\n".$this->_stringifyOptions($value['value'], $prefix.' ');
195
  } else {
196
- $result .= $prefix.$value['label'].":".$value['value']."\n";
197
  }
198
  }
199
 
@@ -207,24 +211,24 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Order_Item extends Cope
207
  */
208
  public function getRestOrderItem()
209
  {
210
- $restOrderItem = Mage::getModel('marketingsoftware/rest_order_item');
211
- $restOrderItem->setOrderItemEntity($this);
212
-
213
- return $restOrderItem;
214
  }
215
 
216
  /**
217
  * Set copernica order item
218
  *
219
- * @param Mage_Sales_Model_Order_Item|Mage_Sales_Model_Quote_Item $orderItem
220
  */
221
  public function setOrderItem($orderItem)
222
  {
223
- if ($orderItem->getId()) {
224
- $this->_orderItem = $orderItem;
225
- $this->setProduct($orderItem->getProductId(), $this->getStoreId());
226
- } else {
227
- throw new Exception(Mage::helper('marketingsoftware')->__('Set an empty quote item or order item object.'));
228
- }
229
  }
230
- }
32
  /**
33
  * Cached item
34
  *
35
+ * @var Mage_Sales_Model_Order_Item|Mage_Sales_Model_Quote_Item
36
  */
37
  protected $_orderItem = null;
38
 
43
  */
44
  public function fetchId()
45
  {
46
+ return $this->_orderItem->getId();
47
  }
48
 
49
  /**
54
  public function fetchQuantity()
55
  {
56
  if ($this->_orderItem instanceOf Mage_Sales_Model_Quote_Item) {
57
+ return $this->_orderItem->getQty();
58
  }
59
 
60
  return $this->_orderItem->getQtyOrdered();
107
  */
108
  public function fetchStoreView()
109
  {
110
+ $store = Mage::getModel('core/store')->load($this->getStoreId());
111
+
112
+ return Mage::getModel('marketingsoftware/abstraction_storeview')->setOriginal($store);
113
  }
114
 
115
  /**
119
  */
120
  public function getUpdatedAt()
121
  {
122
+ return $this->_orderItem->getUpdatedAt();
123
  }
124
 
125
  /**
129
  */
130
  public function getCreatedAt()
131
  {
132
+ return $this->_orderItem->getCreatedAt();
133
  }
134
 
135
  /**
139
  */
140
  public function fetchStatus()
141
  {
142
+ if ($this->_orderItem->getParentItem()) {
143
+ return $this->_orderItem->getParentItem()->getStatus();
144
+ } else {
145
+ return $this->_orderItem->getStatus();
146
+ }
147
  }
148
 
149
  /**
154
  public function getStoreId()
155
  {
156
  if ($this->_orderItem instanceof Mage_Sales_Model_Quote_Item) {
157
+ if ($this->_orderItem->getQuote()) {
158
+ return $this->_orderItem->getQuote()->getStoreId();
159
+ } elseif ($this->_orderItem->getQuoteId()) {
160
+ return Mage::getModel('sales/quote')->loadByIdWithoutStore($this->_orderItem->getQuoteId())->getStoreId();
161
+ } else {
162
+ throw new Exception(Mage::helper('marketingsoftware')->__("Could not load store id from quote."));
163
+ }
164
  } elseif ($this->_orderItem instanceof Mage_Sales_Model_Order_Item) {
165
+ return $this->_orderItem->getOrder()->getStoreId();
166
  }
167
 
168
  return 0;
181
  /**
182
  * Options can be nested so this function will allow us to parse them in recursive manner.
183
  *
184
+ * @param mixed $values
185
+ * @param string $prefix
186
  * @return string
187
  */
188
  protected function _stringifyOptions($values, $prefix = '')
192
  foreach ($values as $value) {
193
  if (is_array($value['value'])) {
194
  if (isset($value['value'][0]) && count($value['value']) == 1) {
195
+ $value['value'] = $value['value'][0];
196
  }
197
 
198
  $result .= $prefix.$value['label'].":\n".$this->_stringifyOptions($value['value'], $prefix.' ');
199
  } else {
200
+ $result .= $prefix.$value['label'].":".$value['value']."\n";
201
  }
202
  }
203
 
211
  */
212
  public function getRestOrderItem()
213
  {
214
+ $restOrderItem = Mage::getModel('marketingsoftware/rest_order_item');
215
+ $restOrderItem->setOrderItemEntity($this);
216
+
217
+ return $restOrderItem;
218
  }
219
 
220
  /**
221
  * Set copernica order item
222
  *
223
+ * @param Mage_Sales_Model_Order_Item|Mage_Sales_Model_Quote_Item $orderItem
224
  */
225
  public function setOrderItem($orderItem)
226
  {
227
+ if ($orderItem->getId()) {
228
+ $this->_orderItem = $orderItem;
229
+ $this->setProduct($orderItem->getProductId(), $this->getStoreId());
230
+ } else {
231
+ throw new Exception(Mage::helper('marketingsoftware')->__('Set an empty quote item or order item object.'));
232
+ }
233
  }
234
+ }
app/code/community/Copernica/MarketingSoftware/Model/Copernica/Entity/Product.php CHANGED
@@ -32,14 +32,14 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Product extends Coperni
32
  /**
33
  * Magento product that will be used during sync
34
  *
35
- * @var Mage_Catalog_Model_Product
36
  */
37
  protected $_product = null;
38
 
39
  /**
40
  * Timestamp of when the product was viewed
41
  *
42
- * @var int
43
  */
44
  protected $_timestamp;
45
 
@@ -121,7 +121,7 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Product extends Coperni
121
  */
122
  public function fetchTimestamp()
123
  {
124
- return $this->_timestamp;
125
  }
126
 
127
  /**
@@ -134,7 +134,7 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Product extends Coperni
134
  $url = $this->_product->getProductUrl($this->getStoreId());
135
 
136
  if (strpos($url, 'processQueue.php')) {
137
- $url = str_replace('processQueue.php', 'index.php', $url);
138
  }
139
 
140
  return $url;
@@ -147,7 +147,7 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Product extends Coperni
147
  * When image can't be found or identified or magento has some other
148
  * problems with beforementioned image empty string will be returned.
149
  *
150
- * @return string
151
  */
152
  protected function _getImageByType($type)
153
  {
@@ -162,7 +162,7 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Product extends Coperni
162
  /**
163
  * Get URL to product image
164
  *
165
- * @return string
166
  */
167
  public function fetchImage()
168
  {
@@ -172,7 +172,7 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Product extends Coperni
172
  /**
173
  * Get URL to product thumbnail
174
  *
175
- * @return string
176
  */
177
  public function fetchThumbnail()
178
  {
@@ -188,11 +188,11 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Product extends Coperni
188
  */
189
  public function getStoreId()
190
  {
191
- if ($this->_product->getStoreId()) {
192
- return $this->_product->getStoreId();
193
- } else {
194
- return 0;
195
- }
196
  }
197
 
198
  /**
@@ -202,9 +202,9 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Product extends Coperni
202
  */
203
  public function fetchId()
204
  {
205
- if (!$this->_product) {
206
- throw new Exception('asdf');
207
- }
208
  return $this->_product->getId();
209
  }
210
 
@@ -215,9 +215,9 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Product extends Coperni
215
  */
216
  public function fetchStoreView()
217
  {
218
- $store = Mage::getModel('core/store')->load($this->getStoreId());
219
-
220
- return Mage::getModel('marketingsoftware/abstraction_storeview')->setOriginal($store);
221
  }
222
 
223
  /**
@@ -266,7 +266,7 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Product extends Coperni
266
 
267
  $parent = Mage::getModel('catalog/category')->load($id);
268
 
269
- while($parent->getId() > 1) {
270
  $categoryName [] = $parent->getName();
271
 
272
  $parent = $parent->getParentCategory();
@@ -325,13 +325,13 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Product extends Coperni
325
 
326
  foreach ($attributes as $attr) {
327
  if (!$attr->getIsUserDefined()) {
328
- continue;
329
  }
330
 
331
  $compareArray = array('text', 'select', 'multiline', 'textarea', 'price', 'date', 'multiselect');
332
 
333
  if (!in_array($attr->getFrontendInput(), $compareArray)) {
334
- continue;
335
  }
336
 
337
  if ($attr->getAttributeCode() && $value = $attr->getFrontend()->getValue($this->_product)) {
@@ -358,7 +358,7 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Product extends Coperni
358
  $newsTo = $this->_product->getNewsToDate();
359
 
360
  if (!$newsFrom && !$newsTo) {
361
- return false;
362
  }
363
 
364
  $from = Mage::app()->getLocale()->date($newsFrom);
@@ -380,15 +380,17 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Product extends Coperni
380
  */
381
  public function fetchAttributes()
382
  {
383
- $attributes = array_map( function ($item) {
 
384
  return sprintf("%s: %s", $item['code'], $item['value']);
385
- }, $this->getAttributesList());
 
386
 
387
  if (!is_array($attributes)) {
388
- return '';
389
  }
390
 
391
- return implode ("\n", $attributes);
392
  }
393
 
394
  /**
@@ -410,25 +412,25 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Product extends Coperni
410
  */
411
  public function getRestProduct()
412
  {
413
- $restProduct = Mage::getModel('marketingsoftware/rest_product');
414
- $restProduct->setProductEntity($this);
415
-
416
- return $restProduct;
417
  }
418
 
419
  /**
420
  * Set product entity
421
  *
422
- * @param int $productId
423
  * @param int $storeId
424
  */
425
  public function setProduct($productId, $storeId = null)
426
  {
427
- if (!$storeId) {
428
- $storeId = Mage::app()->getStore()->getId();
429
- }
430
-
431
- $this->_product = Mage::getModel('catalog/product')->setStoreId($storeId)->load($productId);
432
  }
433
 
434
 
@@ -439,6 +441,6 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Product extends Coperni
439
  */
440
  public function setTimestamp($viewedAt)
441
  {
442
- $this->_timestamp = $viewedAt;
443
  }
444
- }
32
  /**
33
  * Magento product that will be used during sync
34
  *
35
+ * @var Mage_Catalog_Model_Product
36
  */
37
  protected $_product = null;
38
 
39
  /**
40
  * Timestamp of when the product was viewed
41
  *
42
+ * @var int
43
  */
44
  protected $_timestamp;
45
 
121
  */
122
  public function fetchTimestamp()
123
  {
124
+ return $this->_timestamp;
125
  }
126
 
127
  /**
134
  $url = $this->_product->getProductUrl($this->getStoreId());
135
 
136
  if (strpos($url, 'processQueue.php')) {
137
+ $url = str_replace('processQueue.php', 'index.php', $url);
138
  }
139
 
140
  return $url;
147
  * When image can't be found or identified or magento has some other
148
  * problems with beforementioned image empty string will be returned.
149
  *
150
+ * @return string
151
  */
152
  protected function _getImageByType($type)
153
  {
162
  /**
163
  * Get URL to product image
164
  *
165
+ * @return string
166
  */
167
  public function fetchImage()
168
  {
172
  /**
173
  * Get URL to product thumbnail
174
  *
175
+ * @return string
176
  */
177
  public function fetchThumbnail()
178
  {
188
  */
189
  public function getStoreId()
190
  {
191
+ if ($this->_product->getStoreId()) {
192
+ return $this->_product->getStoreId();
193
+ } else {
194
+ return 0;
195
+ }
196
  }
197
 
198
  /**
202
  */
203
  public function fetchId()
204
  {
205
+ if (!$this->_product) {
206
+ throw new Exception('asdf');
207
+ }
208
  return $this->_product->getId();
209
  }
210
 
215
  */
216
  public function fetchStoreView()
217
  {
218
+ $store = Mage::getModel('core/store')->load($this->getStoreId());
219
+
220
+ return Mage::getModel('marketingsoftware/abstraction_storeview')->setOriginal($store);
221
  }
222
 
223
  /**
266
 
267
  $parent = Mage::getModel('catalog/category')->load($id);
268
 
269
+ while ($parent->getId() > 1) {
270
  $categoryName [] = $parent->getName();
271
 
272
  $parent = $parent->getParentCategory();
325
 
326
  foreach ($attributes as $attr) {
327
  if (!$attr->getIsUserDefined()) {
328
+ continue;
329
  }
330
 
331
  $compareArray = array('text', 'select', 'multiline', 'textarea', 'price', 'date', 'multiselect');
332
 
333
  if (!in_array($attr->getFrontendInput(), $compareArray)) {
334
+ continue;
335
  }
336
 
337
  if ($attr->getAttributeCode() && $value = $attr->getFrontend()->getValue($this->_product)) {
358
  $newsTo = $this->_product->getNewsToDate();
359
 
360
  if (!$newsFrom && !$newsTo) {
361
+ return false;
362
  }
363
 
364
  $from = Mage::app()->getLocale()->date($newsFrom);
380
  */
381
  public function fetchAttributes()
382
  {
383
+ $attributes = array_map(
384
+ function ($item) {
385
  return sprintf("%s: %s", $item['code'], $item['value']);
386
+ }, $this->getAttributesList()
387
+ );
388
 
389
  if (!is_array($attributes)) {
390
+ return '';
391
  }
392
 
393
+ return implode("\n", $attributes);
394
  }
395
 
396
  /**
412
  */
413
  public function getRestProduct()
414
  {
415
+ $restProduct = Mage::getModel('marketingsoftware/rest_product');
416
+ $restProduct->setProductEntity($this);
417
+
418
+ return $restProduct;
419
  }
420
 
421
  /**
422
  * Set product entity
423
  *
424
+ * @param int $productId
425
  * @param int $storeId
426
  */
427
  public function setProduct($productId, $storeId = null)
428
  {
429
+ if (!$storeId) {
430
+ $storeId = Mage::app()->getStore()->getId();
431
+ }
432
+
433
+ $this->_product = Mage::getModel('catalog/product')->setStoreId($storeId)->load($productId);
434
  }
435
 
436
 
441
  */
442
  public function setTimestamp($viewedAt)
443
  {
444
+ $this->_timestamp = $viewedAt;
445
  }
446
+ }
app/code/community/Copernica/MarketingSoftware/Model/Copernica/Entity/Quote.php CHANGED
@@ -32,14 +32,14 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Quote extends Copernica
32
  /**
33
  * Cached quote instance
34
  *
35
- * @var Mage_Sales_Model_Quote
36
  */
37
  protected $_quote;
38
 
39
  /**
40
  * Cached quote items
41
  *
42
- * @var array
43
  */
44
  protected $_quoteItems;
45
 
@@ -49,16 +49,16 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Quote extends Copernica
49
  public function getItems()
50
  {
51
  if (!is_null($this->_quoteItems)) {
52
- return $this->_quoteItems;
53
  }
54
 
55
  $quoteItems = array();
56
 
57
  foreach ($this->_quote->getAllItems() as $quoteItem) {
58
- $quoteItemEntity = Mage::getModel('marketingsoftware/copernica_entity_quote_item');
59
- $quoteItemEntity->setQuoteItem($quoteItem);
60
-
61
- $quoteItems[] = $quoteItemEntity;
62
  }
63
 
64
  return $this->_quoteItems = $quoteItems;
@@ -71,19 +71,19 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Quote extends Copernica
71
  */
72
  public function getRestQuote()
73
  {
74
- $restQuote = Mage::getModel('marketingsoftware/rest_quote');
75
- $restQuote->setQuoteEntity($this);
76
-
77
- return $restQuote;
78
  }
79
 
80
  /**
81
  * Set quote entity
82
  *
83
- * @param Mage_Sales_Model_Quote $quote
84
  */
85
  public function setQuote($quote)
86
  {
87
- $this->_quote = $quote;
88
  }
89
- }
32
  /**
33
  * Cached quote instance
34
  *
35
+ * @var Mage_Sales_Model_Quote
36
  */
37
  protected $_quote;
38
 
39
  /**
40
  * Cached quote items
41
  *
42
+ * @var array
43
  */
44
  protected $_quoteItems;
45
 
49
  public function getItems()
50
  {
51
  if (!is_null($this->_quoteItems)) {
52
+ return $this->_quoteItems;
53
  }
54
 
55
  $quoteItems = array();
56
 
57
  foreach ($this->_quote->getAllItems() as $quoteItem) {
58
+ $quoteItemEntity = Mage::getModel('marketingsoftware/copernica_entity_quote_item');
59
+ $quoteItemEntity->setQuoteItem($quoteItem);
60
+
61
+ $quoteItems[] = $quoteItemEntity;
62
  }
63
 
64
  return $this->_quoteItems = $quoteItems;
71
  */
72
  public function getRestQuote()
73
  {
74
+ $restQuote = Mage::getModel('marketingsoftware/rest_quote');
75
+ $restQuote->setQuoteEntity($this);
76
+
77
+ return $restQuote;
78
  }
79
 
80
  /**
81
  * Set quote entity
82
  *
83
+ * @param Mage_Sales_Model_Quote $quote
84
  */
85
  public function setQuote($quote)
86
  {
87
+ $this->_quote = $quote;
88
  }
89
+ }
app/code/community/Copernica/MarketingSoftware/Model/Copernica/Entity/Quote/Item.php CHANGED
@@ -28,7 +28,8 @@
28
  * Brigde class between Copernica subprofile and magento quote item
29
  */
30
  class Copernica_MarketingSoftware_Model_Copernica_Entity_Quote_Item extends Copernica_MarketingSoftware_Model_Copernica_Entity_Order_Item
31
- {
 
32
  /**
33
  * Fetch status of an item.
34
  *
@@ -47,7 +48,7 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Quote_Item extends Cope
47
  $order = Mage::getModel('sales/order')->getCollection()->addFieldToFilter('quote_id', $quoteId)->getFirstItem();
48
 
49
  if ($order->getId() > 0) {
50
- return 'completed';
51
  }
52
 
53
  $forgottenCollection = Mage::getResourceModel('reports/quote_collection');
@@ -62,7 +63,7 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Quote_Item extends Cope
62
  $forgottenCollection->prepareForAbandonedReport(array());
63
 
64
  if (count($forgottenCollection)) {
65
- return 'abandoned';
66
  }
67
 
68
  return 'basket';
@@ -75,19 +76,19 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Quote_Item extends Cope
75
  */
76
  public function getRestQuoteItem()
77
  {
78
- $restQuoteItem = Mage::getModel('marketingsoftware/rest_quote_item');
79
- $restQuoteItem->setQuoteItemEntity($this);
80
-
81
- return $restQuoteItem;
82
  }
83
 
84
  /**
85
  * Set copernica quote item
86
  *
87
- * @param Mage_Sales_Model_Quote_Item $quoteItem
88
  */
89
  public function setQuoteItem(Mage_Sales_Model_Quote_Item $quoteItem)
90
  {
91
- $this->setOrderItem($quoteItem);
92
  }
93
- }
28
  * Brigde class between Copernica subprofile and magento quote item
29
  */
30
  class Copernica_MarketingSoftware_Model_Copernica_Entity_Quote_Item extends Copernica_MarketingSoftware_Model_Copernica_Entity_Order_Item
31
+ {
32
+
33
  /**
34
  * Fetch status of an item.
35
  *
48
  $order = Mage::getModel('sales/order')->getCollection()->addFieldToFilter('quote_id', $quoteId)->getFirstItem();
49
 
50
  if ($order->getId() > 0) {
51
+ return 'completed';
52
  }
53
 
54
  $forgottenCollection = Mage::getResourceModel('reports/quote_collection');
63
  $forgottenCollection->prepareForAbandonedReport(array());
64
 
65
  if (count($forgottenCollection)) {
66
+ return 'abandoned';
67
  }
68
 
69
  return 'basket';
76
  */
77
  public function getRestQuoteItem()
78
  {
79
+ $restQuoteItem = Mage::getModel('marketingsoftware/rest_quote_item');
80
+ $restQuoteItem->setQuoteItemEntity($this);
81
+
82
+ return $restQuoteItem;
83
  }
84
 
85
  /**
86
  * Set copernica quote item
87
  *
88
+ * @param Mage_Sales_Model_Quote_Item $quoteItem
89
  */
90
  public function setQuoteItem(Mage_Sales_Model_Quote_Item $quoteItem)
91
  {
92
+ $this->setOrderItem($quoteItem);
93
  }
94
+ }
app/code/community/Copernica/MarketingSoftware/Model/Copernica/Entity/Subscription.php CHANGED
@@ -32,7 +32,7 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Subscription extends Co
32
  /**
33
  * Our subscriber
34
  *
35
- * @var Mage_Newsletter_Model_Subscriber
36
  */
37
  protected $_subscriber;
38
 
@@ -88,9 +88,9 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Subscription extends Co
88
  */
89
  public function fetchStoreView()
90
  {
91
- $store = Mage::getModel('core/store')->load($this->getStoreId());
92
-
93
- return Mage::getModel('marketingsoftware/abstraction_storeview')->setOriginal($store);
94
  }
95
 
96
  /**
@@ -105,9 +105,9 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Subscription extends Co
105
  $customer = Mage::getModel('customer/customer')->setWebsiteId($store->getWebsiteId())->loadByEmail($this->_subscriber->getEmail());
106
 
107
  if ($customer->isObjectNew()) {
108
- $identifier = $this->_subscriber->getEmail();
109
  } else {
110
- $identifier = $customer->getId();
111
  }
112
 
113
  return $identifier.'|'.$this->_subscriber->getStoreId();
@@ -120,11 +120,11 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Subscription extends Co
120
  */
121
  public function getStoreId()
122
  {
123
- if($this->_subscriber->getStoreId()) {
124
- return $this->_subscriber->getStoreId();
125
- } else {
126
- return 0;
127
- }
128
  }
129
 
130
  /**
@@ -134,19 +134,19 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Subscription extends Co
134
  */
135
  public function getRestSubscription()
136
  {
137
- $restSubscription = Mage::getModel('marketingsoftware/rest_subscription');
138
- $restSubscription->setSubscriptionEntity($this);
139
-
140
- return $restSubscription;
141
  }
142
 
143
  /**
144
  * Set subscription entity
145
  *
146
- * @param Mage_Newsletter_Model_Subscriber $subscriber
147
  */
148
  public function setSubscription($subscriber)
149
  {
150
- $this->_subscriber = $subscriber;
151
  }
152
- }
32
  /**
33
  * Our subscriber
34
  *
35
+ * @var Mage_Newsletter_Model_Subscriber
36
  */
37
  protected $_subscriber;
38
 
88
  */
89
  public function fetchStoreView()
90
  {
91
+ $store = Mage::getModel('core/store')->load($this->getStoreId());
92
+
93
+ return Mage::getModel('marketingsoftware/abstraction_storeview')->setOriginal($store);
94
  }
95
 
96
  /**
105
  $customer = Mage::getModel('customer/customer')->setWebsiteId($store->getWebsiteId())->loadByEmail($this->_subscriber->getEmail());
106
 
107
  if ($customer->isObjectNew()) {
108
+ $identifier = $this->_subscriber->getEmail();
109
  } else {
110
+ $identifier = $customer->getId();
111
  }
112
 
113
  return $identifier.'|'.$this->_subscriber->getStoreId();
120
  */
121
  public function getStoreId()
122
  {
123
+ if ($this->_subscriber->getStoreId()) {
124
+ return $this->_subscriber->getStoreId();
125
+ } else {
126
+ return 0;
127
+ }
128
  }
129
 
130
  /**
134
  */
135
  public function getRestSubscription()
136
  {
137
+ $restSubscription = Mage::getModel('marketingsoftware/rest_subscription');
138
+ $restSubscription->setSubscriptionEntity($this);
139
+
140
+ return $restSubscription;
141
  }
142
 
143
  /**
144
  * Set subscription entity
145
  *
146
+ * @param Mage_Newsletter_Model_Subscriber $subscriber
147
  */
148
  public function setSubscription($subscriber)
149
  {
150
+ $this->_subscriber = $subscriber;
151
  }
152
+ }
app/code/community/Copernica/MarketingSoftware/Model/Copernica/Entity/Wishlist.php CHANGED
@@ -32,14 +32,14 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Wishlist extends Copern
32
  /**
33
  * Cached wishlist instance
34
  *
35
- * @var Mage_Wishlist_Model_Wishlist
36
  */
37
  protected $_wishlist;
38
 
39
  /**
40
  * Cached wishlist items
41
  *
42
- * @var array
43
  */
44
  protected $_wishlistItems;
45
 
@@ -50,25 +50,25 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Wishlist extends Copern
50
  */
51
  public function fetchId()
52
  {
53
- return $this->_wishlist->getId();
54
  }
55
-
56
  /**
57
  * @return array
58
  */
59
  public function getItems()
60
  {
61
  if (!is_null($this->_wishlistItems)) {
62
- return $this->_wishlistItems;
63
  }
64
 
65
  $wishlistItems = array();
66
 
67
  foreach ($this->_wishlist->getItemCollection() as $wishlistItem) {
68
- $wishlistItemEntity = Mage::getModel('marketingsoftware/copernica_entity_wishlist_item');
69
- $wishlistItemEntity->setWishlistItem($wishlistItem);
70
-
71
- $wishlistItems[] = $wishlistItemEntity;
72
  }
73
 
74
  return $this->_wishlistItems = $wishlistItems;
@@ -81,19 +81,19 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Wishlist extends Copern
81
  */
82
  public function getRestWishlist()
83
  {
84
- $restWishlist = Mage::getModel('marketingsoftware/rest_wishlist');
85
- $restWishlist->setWishlistEntity($this);
86
-
87
- return $restWishlist;
88
  }
89
 
90
  /**
91
  * Set wishlist entity
92
  *
93
- * @param Mage_Wishlist_Model_Wishlist $wishlist
94
  */
95
  public function setWishlist(Mage_Wishlist_Model_Wishlist $wishlist)
96
  {
97
- $this->_wishlist = $wishlist;
98
  }
99
- }
32
  /**
33
  * Cached wishlist instance
34
  *
35
+ * @var Mage_Wishlist_Model_Wishlist
36
  */
37
  protected $_wishlist;
38
 
39
  /**
40
  * Cached wishlist items
41
  *
42
+ * @var array
43
  */
44
  protected $_wishlistItems;
45
 
50
  */
51
  public function fetchId()
52
  {
53
+ return $this->_wishlist->getId();
54
  }
55
+
56
  /**
57
  * @return array
58
  */
59
  public function getItems()
60
  {
61
  if (!is_null($this->_wishlistItems)) {
62
+ return $this->_wishlistItems;
63
  }
64
 
65
  $wishlistItems = array();
66
 
67
  foreach ($this->_wishlist->getItemCollection() as $wishlistItem) {
68
+ $wishlistItemEntity = Mage::getModel('marketingsoftware/copernica_entity_wishlist_item');
69
+ $wishlistItemEntity->setWishlistItem($wishlistItem);
70
+
71
+ $wishlistItems[] = $wishlistItemEntity;
72
  }
73
 
74
  return $this->_wishlistItems = $wishlistItems;
81
  */
82
  public function getRestWishlist()
83
  {
84
+ $restWishlist = Mage::getModel('marketingsoftware/rest_wishlist');
85
+ $restWishlist->setWishlistEntity($this);
86
+
87
+ return $restWishlist;
88
  }
89
 
90
  /**
91
  * Set wishlist entity
92
  *
93
+ * @param Mage_Wishlist_Model_Wishlist $wishlist
94
  */
95
  public function setWishlist(Mage_Wishlist_Model_Wishlist $wishlist)
96
  {
97
+ $this->_wishlist = $wishlist;
98
  }
99
+ }
app/code/community/Copernica/MarketingSoftware/Model/Copernica/Entity/Wishlist/Item.php CHANGED
@@ -28,106 +28,107 @@
28
  * Brigde class between Copernica subprofile and magento wishlist item
29
  */
30
  class Copernica_MarketingSoftware_Model_Copernica_Entity_Wishlist_Item extends Copernica_MarketingSoftware_Model_Copernica_Entity_Product
31
- {
32
- /**
33
- * Cached item
34
- *
35
- * @var Mage_Wishlist_Model_Item
36
- */
37
- protected $_wishlistItem = null;
38
-
39
- /**
40
- * Fetch wishlist item Id
41
- *
42
- * @return string
43
- */
44
- public function fetchId()
45
- {
46
- return $this->_wishlistItem->getId();
47
- }
48
-
49
- /**
50
- * Fetch wishlist Id
51
- *
52
- * @return string
53
- */
54
- public function fetchWishlistId()
55
- {
56
- return $this->_wishlistItem->getWishlistId();
57
- }
58
-
59
- /**
60
- * Fetch quantity
61
- *
62
- * @return string
63
- */
64
- public function fetchDescription()
65
- {
66
- return $this->_wishlistItem->getDescription();
67
- }
68
-
69
- /**
70
- * Fetch quantity
71
- *
72
- * @return string
73
- */
74
- public function fetchQuantity()
75
- {
76
- return $this->_wishlistItem->getQty();
77
- }
78
-
79
- /**
80
- * Fetch total
81
- *
82
- * @return string
83
- */
84
- public function fetchTotalPrice()
85
- {
86
- return $this->_wishlistItem->getProduct()->getPrice() * $this->getQuantity();
87
- }
88
-
89
- /**
90
- * Fetch price
91
- *
92
- * @return string
93
- */
94
- public function fetchPrice()
95
- {
96
- return $this->_wishlistItem->getProduct()->getPrice();
97
- }
98
-
99
- /**
100
- * Fetch timestamp
101
- *
102
- * @return string
103
- */
104
- public function getCreatedAt()
105
- {
106
- return $this->_wishlistItem->getAddedAt();
107
- }
108
-
109
- /**
110
- * Fetch store view
111
- *
112
- * @return string
113
- */
114
- public function fetchStoreView()
115
- {
116
- $store = Mage::getModel('core/store')->load($this->getStoreId());
117
-
118
- return Mage::getModel('marketingsoftware/abstraction_storeview')->setOriginal($store);
119
- }
120
-
121
- /**
122
- * Get store Id
123
- *
124
- * @return int
125
- */
126
- public function getStoreId()
127
- {
128
- return $this->_wishlistItem->getStoreId();
129
- }
130
-
 
131
  /**
132
  * Get REST wishlist item entity
133
  *
@@ -135,21 +136,21 @@ class Copernica_MarketingSoftware_Model_Copernica_Entity_Wishlist_Item extends C
135
  */
136
  public function getRestWishlistItem()
137
  {
138
- $restWishlistItem = Mage::getModel('marketingsoftware/rest_wishlist_item');
139
- $restWishlistItem->setWishlistItemEntity($this);
140
-
141
- return $restWishlistItem;
142
  }
143
 
144
  /**
145
  * Set copernica wishlist item
146
  *
147
- * @param Mage_Wishlist_Model_Item $wishlistItem
148
  */
149
  public function setWishlistItem(Mage_Wishlist_Model_Item $wishlistItem)
150
  {
151
- $this->_wishlistItem = $wishlistItem;
152
-
153
- $this->setProduct($wishlistItem->getProductId(), $this->getStoreId());
154
  }
155
- }
28
  * Brigde class between Copernica subprofile and magento wishlist item
29
  */
30
  class Copernica_MarketingSoftware_Model_Copernica_Entity_Wishlist_Item extends Copernica_MarketingSoftware_Model_Copernica_Entity_Product
31
+ {
32
+
33
+ /**
34
+ * Cached item
35
+ *
36
+ * @var Mage_Wishlist_Model_Item
37
+ */
38
+ protected $_wishlistItem = null;
39
+
40
+ /**
41
+ * Fetch wishlist item Id
42
+ *
43
+ * @return string
44
+ */
45
+ public function fetchId()
46
+ {
47
+ return $this->_wishlistItem->getId();
48
+ }
49
+
50
+ /**
51
+ * Fetch wishlist Id
52
+ *
53
+ * @return string
54
+ */
55
+ public function fetchWishlistId()
56
+ {
57
+ return $this->_wishlistItem->getWishlistId();
58
+ }
59
+
60
+ /**
61
+ * Fetch quantity
62
+ *
63
+ * @return string
64
+ */
65
+ public function fetchDescription()
66
+ {
67
+ return $this->_wishlistItem->getDescription();
68
+ }
69
+
70
+ /**
71
+ * Fetch quantity
72
+ *
73
+ * @return string
74
+ */
75
+ public function fetchQuantity()
76
+ {
77
+ return $this->_wishlistItem->getQty();
78
+ }
79
+
80
+ /**
81
+ * Fetch total
82
+ *
83
+ * @return string
84
+ */
85
+ public function fetchTotalPrice()
86
+ {
87
+ return $this->_wishlistItem->getProduct()->getPrice() * $this->getQuantity();
88
+ }
89
+
90
+ /**
91
+ * Fetch price
92
+ *
93
+ * @return string
94
+ */
95
+ public function fetchPrice()
96
+ {
97
+ return $this->_wishlistItem->getProduct()->getPrice();
98
+ }
99
+
100
+ /**
101
+ * Fetch timestamp
102
+ *
103
+ * @return string
104
+ */
105
+ public function getCreatedAt()
106
+ {
107
+ return $this->_wishlistItem->getAddedAt();
108
+ }
109
+
110
+ /**
111
+ * Fetch store view
112
+ *
113
+ * @return string
114
+ */
115
+ public function fetchStoreView()
116
+ {
117
+ $store = Mage::getModel('core/store')->load($this->getStoreId());
118
+
119
+ return Mage::getModel('marketingsoftware/abstraction_storeview')->setOriginal($store);
120
+ }
121
+
122
+ /**
123
+ * Get store Id
124
+ *
125
+ * @return int
126
+ */
127
+ public function getStoreId()
128
+ {
129
+ return $this->_wishlistItem->getStoreId();
130
+ }
131
+
132
  /**
133
  * Get REST wishlist item entity
134
  *
136
  */
137
  public function getRestWishlistItem()
138
  {
139
+ $restWishlistItem = Mage::getModel('marketingsoftware/rest_wishlist_item');
140
+ $restWishlistItem->setWishlistItemEntity($this);
141
+
142
+ return $restWishlistItem;
143
  }
144
 
145
  /**
146
  * Set copernica wishlist item
147
  *
148
+ * @param Mage_Wishlist_Model_Item $wishlistItem
149
  */
150
  public function setWishlistItem(Mage_Wishlist_Model_Item $wishlistItem)
151
  {
152
+ $this->_wishlistItem = $wishlistItem;
153
+
154
+ $this->setProduct($wishlistItem->getProductId(), $this->getStoreId());
155
  }
156
+ }
app/code/community/Copernica/MarketingSoftware/Model/Copernica/Order/Subprofile.php CHANGED
@@ -30,7 +30,7 @@
30
  class Copernica_MarketingSoftware_Model_Copernica_Order_Subprofile extends Copernica_MarketingSoftware_Model_Copernica_Abstract
31
  {
32
  /**
33
- * @var Copernica_MarketingSoftware_Model_Abstraction_Order
34
  */
35
  protected $_order = false;
36
 
@@ -47,7 +47,7 @@ class Copernica_MarketingSoftware_Model_Copernica_Order_Subprofile extends Coper
47
  /**
48
  * Try to store a quote item
49
  *
50
- * @param Copernica_MarketingSoftware_Model_Abstract $order
51
  * @return Copernica_MarketingSoftware_Model_Copernica_Order_Subprofile
52
  */
53
  public function setOrder(Copernica_MarketingSoftware_Model_Abstract $order)
@@ -89,15 +89,15 @@ class Copernica_MarketingSoftware_Model_Copernica_Order_Subprofile extends Coper
89
  $addresses = $this->_order->addresses();
90
 
91
  if (is_array($addresses)) {
92
- foreach ($addresses as $address) {
93
- if (in_array('billing', $address->type())) {
94
- $billingAddress = $address;
95
- }
96
-
97
- if (in_array('shipping', $address->type())) {
98
- $shippingAddress = $address;
99
- }
100
- }
101
  }
102
 
103
  $price = $this->_order->price();
30
  class Copernica_MarketingSoftware_Model_Copernica_Order_Subprofile extends Copernica_MarketingSoftware_Model_Copernica_Abstract
31
  {
32
  /**
33
+ * @var Copernica_MarketingSoftware_Model_Abstraction_Order
34
  */
35
  protected $_order = false;
36
 
47
  /**
48
  * Try to store a quote item
49
  *
50
+ * @param Copernica_MarketingSoftware_Model_Abstract $order
51
  * @return Copernica_MarketingSoftware_Model_Copernica_Order_Subprofile
52
  */
53
  public function setOrder(Copernica_MarketingSoftware_Model_Abstract $order)
89
  $addresses = $this->_order->addresses();
90
 
91
  if (is_array($addresses)) {
92
+ foreach ($addresses as $address) {
93
+ if (in_array('billing', $address->type())) {
94
+ $billingAddress = $address;
95
+ }
96
+
97
+ if (in_array('shipping', $address->type())) {
98
+ $shippingAddress = $address;
99
+ }
100
+ }
101
  }
102
 
103
  $price = $this->_order->price();
app/code/community/Copernica/MarketingSoftware/Model/Copernica/Orderitem/Subprofile.php CHANGED
@@ -30,7 +30,7 @@
30
  class Copernica_MarketingSoftware_Model_Copernica_Orderitem_Subprofile extends Copernica_MarketingSoftware_Model_Copernica_Abstract
31
  {
32
  /**
33
- * @var Copernica_MarketingSoftware_Model_Abstraction_Order_Item
34
  */
35
  protected $_orderItem = false;
36
 
@@ -113,7 +113,7 @@ class Copernica_MarketingSoftware_Model_Copernica_Orderitem_Subprofile extends C
113
  $data['url'] = $product->productUrl($storeId);
114
  $data['image'] = $product->imageUrl($storeId);
115
  } else {
116
- $data['order_id'] = null;
117
  }
118
 
119
  $price = $orderItem->price();
@@ -123,10 +123,14 @@ class Copernica_MarketingSoftware_Model_Copernica_Orderitem_Subprofile extends C
123
  $data['total_price'] = $price->total();
124
  }
125
 
126
- $data['categories'] = implode("\n", array_map(function($category) {
127
- return implode(' > ', $category);
128
- }, $product->categories()));
 
 
 
 
129
 
130
  return $data;
131
  }
132
- }
30
  class Copernica_MarketingSoftware_Model_Copernica_Orderitem_Subprofile extends Copernica_MarketingSoftware_Model_Copernica_Abstract
31
  {
32
  /**
33
+ * @var Copernica_MarketingSoftware_Model_Abstraction_Order_Item
34
  */
35
  protected $_orderItem = false;
36
 
113
  $data['url'] = $product->productUrl($storeId);
114
  $data['image'] = $product->imageUrl($storeId);
115
  } else {
116
+ $data['order_id'] = null;
117
  }
118
 
119
  $price = $orderItem->price();
123
  $data['total_price'] = $price->total();
124
  }
125
 
126
+ $data['categories'] = implode(
127
+ "\n", array_map(
128
+ function($category) {
129
+ return implode(' > ', $category);
130
+ }, $product->categories()
131
+ )
132
+ );
133
 
134
  return $data;
135
  }
136
+ }
app/code/community/Copernica/MarketingSoftware/Model/Copernica/Product/Viewed/Subprofile.php CHANGED
@@ -30,7 +30,7 @@
30
  class Copernica_MarketingSoftware_Model_Copernica_Product_Viewed_Subprofile extends Copernica_MarketingSoftware_Model_Copernica_Abstract
31
  {
32
  /**
33
- * @var Copernica_MarketingSoftware_Model_Abstraction_Product_Viewed
34
  */
35
  protected $_viewedProduct = false;
36
 
@@ -52,7 +52,7 @@ class Copernica_MarketingSoftware_Model_Copernica_Product_Viewed_Subprofile exte
52
  /**
53
  * Try to store a quote item
54
  *
55
- * @param Copernica_MarketingSoftware_Model_Abstraction_Product_Viewed $product
56
  */
57
  public function setViewedProduct(Copernica_MarketingSoftware_Model_Abstraction_Product_Viewed $product)
58
  {
@@ -96,7 +96,7 @@ class Copernica_MarketingSoftware_Model_Copernica_Product_Viewed_Subprofile exte
96
 
97
  if ($product->categories()) {
98
  foreach ($product->categories() as $category) {
99
- $categories[] = implode(' > ', $category);
100
  }
101
  }
102
 
@@ -115,4 +115,4 @@ class Copernica_MarketingSoftware_Model_Copernica_Product_Viewed_Subprofile exte
115
  'timestamp' => $product->timestamp()
116
  );
117
  }
118
- }
30
  class Copernica_MarketingSoftware_Model_Copernica_Product_Viewed_Subprofile extends Copernica_MarketingSoftware_Model_Copernica_Abstract
31
  {
32
  /**
33
+ * @var Copernica_MarketingSoftware_Model_Abstraction_Product_Viewed
34
  */
35
  protected $_viewedProduct = false;
36
 
52
  /**
53
  * Try to store a quote item
54
  *
55
+ * @param Copernica_MarketingSoftware_Model_Abstraction_Product_Viewed $product
56
  */
57
  public function setViewedProduct(Copernica_MarketingSoftware_Model_Abstraction_Product_Viewed $product)
58
  {
96
 
97
  if ($product->categories()) {
98
  foreach ($product->categories() as $category) {
99
+ $categories[] = implode(' > ', $category);
100
  }
101
  }
102
 
115
  'timestamp' => $product->timestamp()
116
  );
117
  }
118
+ }
app/code/community/Copernica/MarketingSoftware/Model/Copernica/Profile/Customer.php CHANGED
@@ -30,15 +30,15 @@
30
  class Copernica_MarketingSoftware_Model_Copernica_Profile_Customer extends Copernica_MarketingSoftware_Model_Copernica_Profile
31
  {
32
  /**
33
- * @var Copernica_MarketingSoftware_Model_Abstraction_Customer
34
  */
35
  protected $_customer = false;
36
 
37
  /**
38
  * Set the customer object to this object
39
  *
40
- * @param Copernica_MarketingSoftware_Model_Abstraction_Customer $customer
41
- * @return Copernica_MarketingSoftware_Model_Copernica_Profile_Customer
42
  */
43
  public function setCustomer(Copernica_MarketingSoftware_Model_Abstraction_Customer $customer)
44
  {
30
  class Copernica_MarketingSoftware_Model_Copernica_Profile_Customer extends Copernica_MarketingSoftware_Model_Copernica_Profile
31
  {
32
  /**
33
+ * @var Copernica_MarketingSoftware_Model_Abstraction_Customer
34
  */
35
  protected $_customer = false;
36
 
37
  /**
38
  * Set the customer object to this object
39
  *
40
+ * @param Copernica_MarketingSoftware_Model_Abstraction_Customer $customer
41
+ * @return Copernica_MarketingSoftware_Model_Copernica_Profile_Customer
42
  */
43
  public function setCustomer(Copernica_MarketingSoftware_Model_Abstraction_Customer $customer)
44
  {
app/code/community/Copernica/MarketingSoftware/Model/Copernica/Profile/Order.php CHANGED
@@ -30,14 +30,14 @@
30
  class Copernica_MarketingSoftware_Model_Copernica_Profile_Order extends Copernica_MarketingSoftware_Model_Copernica_Profile
31
  {
32
  /**
33
- * @var Copernica_MarketingSoftware_Model_Abstraction_Order
34
  */
35
  protected $_order = false;
36
 
37
  /**
38
  * Set the order object to this object
39
  *
40
- * @param Copernica_MarketingSoftware_Model_Abstraction_Order $order
41
  * @return Copernica_MarketingSoftware_Model_Copernica_Profile_Order
42
  */
43
  public function setOrder(Copernica_MarketingSoftware_Model_Abstraction_Order $order)
@@ -57,7 +57,7 @@ class Copernica_MarketingSoftware_Model_Copernica_Profile_Order extends Copernic
57
 
58
  foreach ($addresses as $address) {
59
  if (in_array('billing', $addr->type())) {
60
- return $address->email();
61
  }
62
  }
63
 
@@ -84,20 +84,20 @@ class Copernica_MarketingSoftware_Model_Copernica_Profile_Order extends Copernic
84
  $addresses = $this->_order->addresses();
85
 
86
  if (count($addresses) == 1) {
87
- $address = $addresses[0];
88
  } else {
89
- foreach ($addresses as $addr) {
90
- if (in_array('billing', $addr->type())) {
91
- $address = $addr;
92
- }
93
- }
94
  }
95
 
96
  if (Mage::getModel('newsletter/subscriber')->loadByEmail($address->email())->getId()) {
97
  $subscription = Mage::getModel('marketingsoftware/abstraction_subscription')
98
  ->setOriginal(Mage::getModel('newsletter/subscriber')->loadByEmail($address->email()));
99
  } else {
100
- $subscription = false;
101
  }
102
 
103
  $name = $address->name();
@@ -105,9 +105,9 @@ class Copernica_MarketingSoftware_Model_Copernica_Profile_Order extends Copernic
105
  $customerId = null;
106
 
107
  if ($customer = $this->_order->customer()) {
108
- $customerId = Mage::helper('marketingsoftware/profile')->getCustomerCopernicaId($customer, $this->_order->storeview());
109
  } else {
110
- $customerId = Mage::helper('marketingsoftware/profile')->getEmailCopernicaId($address->email(), (string)$this->_order->storeview());
111
  }
112
 
113
  return array(
30
  class Copernica_MarketingSoftware_Model_Copernica_Profile_Order extends Copernica_MarketingSoftware_Model_Copernica_Profile
31
  {
32
  /**
33
+ * @var Copernica_MarketingSoftware_Model_Abstraction_Order
34
  */
35
  protected $_order = false;
36
 
37
  /**
38
  * Set the order object to this object
39
  *
40
+ * @param Copernica_MarketingSoftware_Model_Abstraction_Order $order
41
  * @return Copernica_MarketingSoftware_Model_Copernica_Profile_Order
42
  */
43
  public function setOrder(Copernica_MarketingSoftware_Model_Abstraction_Order $order)
57
 
58
  foreach ($addresses as $address) {
59
  if (in_array('billing', $addr->type())) {
60
+ return $address->email();
61
  }
62
  }
63
 
84
  $addresses = $this->_order->addresses();
85
 
86
  if (count($addresses) == 1) {
87
+ $address = $addresses[0];
88
  } else {
89
+ foreach ($addresses as $addr) {
90
+ if (in_array('billing', $addr->type())) {
91
+ $address = $addr;
92
+ }
93
+ }
94
  }
95
 
96
  if (Mage::getModel('newsletter/subscriber')->loadByEmail($address->email())->getId()) {
97
  $subscription = Mage::getModel('marketingsoftware/abstraction_subscription')
98
  ->setOriginal(Mage::getModel('newsletter/subscriber')->loadByEmail($address->email()));
99
  } else {
100
+ $subscription = false;
101
  }
102
 
103
  $name = $address->name();
105
  $customerId = null;
106
 
107
  if ($customer = $this->_order->customer()) {
108
+ $customerId = Mage::helper('marketingsoftware/profile')->getCustomerCopernicaId($customer, $this->_order->storeview());
109
  } else {
110
+ $customerId = Mage::helper('marketingsoftware/profile')->getEmailCopernicaId($address->email(), (string)$this->_order->storeview());
111
  }
112
 
113
  return array(
app/code/community/Copernica/MarketingSoftware/Model/Copernica/Profile/Quote.php CHANGED
@@ -30,15 +30,15 @@
30
  class Copernica_MarketingSoftware_Model_Copernica_Profile_Quote extends Copernica_MarketingSoftware_Model_Copernica_Profile
31
  {
32
  /**
33
- * @var Copernica_MarketingSoftware_Model_Abstraction_Quote
34
  */
35
  protected $_quote = false;
36
 
37
  /**
38
  * Set the quote object to this object
39
  *
40
- * @param Copernica_MarketingSoftware_Model_Abstraction_Quote $quote
41
- * @return Copernica_MarketingSoftware_Model_Copernica_Profile_Quote
42
  */
43
  public function setQuote(Copernica_MarketingSoftware_Model_Abstraction_Quote $quote)
44
  {
@@ -58,7 +58,7 @@ class Copernica_MarketingSoftware_Model_Copernica_Profile_Quote extends Copernic
58
 
59
  foreach ($addresses as $address) {
60
  if (in_array('billing', $addr->type())) {
61
- return $address->email();
62
  }
63
  }
64
 
@@ -68,7 +68,7 @@ class Copernica_MarketingSoftware_Model_Copernica_Profile_Quote extends Copernic
68
  /**
69
  * Return store view associated with profile
70
  *
71
- * @return string
72
  */
73
  public function storeView()
74
  {
@@ -88,13 +88,13 @@ class Copernica_MarketingSoftware_Model_Copernica_Profile_Quote extends Copernic
88
 
89
  if (is_array($addresses)) {
90
  if (count($addresses) == 1) {
91
- $address = $addresses[0];
92
  } else {
93
- foreach ($addresses as $addr) {
94
- if (in_array('billing', $addr->type())) {
95
- $address = $addr;
96
- }
97
- }
98
  }
99
  }
100
 
@@ -102,7 +102,7 @@ class Copernica_MarketingSoftware_Model_Copernica_Profile_Quote extends Copernic
102
  $subscription = Mage::getModel('marketingsoftware/abstraction_subscription')
103
  ->setOriginal(Mage::getModel('newsletter/subscriber')->loadByEmail($address->email()));
104
  } else {
105
- $subscription = false;
106
  }
107
 
108
  $name = is_object($address) ? $address->name() : null;
@@ -110,9 +110,9 @@ class Copernica_MarketingSoftware_Model_Copernica_Profile_Quote extends Copernic
110
  $customerId = null;
111
 
112
  if ($customer = $this->_quote->customer()) {
113
- $customerId = Mage::helper('marketingsoftware/profile')->getCustomerCopernicaId($customer, $this->_quote->storeview());
114
  } else {
115
- $customerId = Mage::helper('marketingsoftware/profile')->getEmailCopernicaId($address->email(), $this->_quote->storeview());
116
  }
117
 
118
  return array(
30
  class Copernica_MarketingSoftware_Model_Copernica_Profile_Quote extends Copernica_MarketingSoftware_Model_Copernica_Profile
31
  {
32
  /**
33
+ * @var Copernica_MarketingSoftware_Model_Abstraction_Quote
34
  */
35
  protected $_quote = false;
36
 
37
  /**
38
  * Set the quote object to this object
39
  *
40
+ * @param Copernica_MarketingSoftware_Model_Abstraction_Quote $quote
41
+ * @return Copernica_MarketingSoftware_Model_Copernica_Profile_Quote
42
  */
43
  public function setQuote(Copernica_MarketingSoftware_Model_Abstraction_Quote $quote)
44
  {
58
 
59
  foreach ($addresses as $address) {
60
  if (in_array('billing', $addr->type())) {
61
+ return $address->email();
62
  }
63
  }
64
 
68
  /**
69
  * Return store view associated with profile
70
  *
71
+ * @return string
72
  */
73
  public function storeView()
74
  {
88
 
89
  if (is_array($addresses)) {
90
  if (count($addresses) == 1) {
91
+ $address = $addresses[0];
92
  } else {
93
+ foreach ($addresses as $addr) {
94
+ if (in_array('billing', $addr->type())) {
95
+ $address = $addr;
96
+ }
97
+ }
98
  }
99
  }
100
 
102
  $subscription = Mage::getModel('marketingsoftware/abstraction_subscription')
103
  ->setOriginal(Mage::getModel('newsletter/subscriber')->loadByEmail($address->email()));
104
  } else {
105
+ $subscription = false;
106
  }
107
 
108
  $name = is_object($address) ? $address->name() : null;
110
  $customerId = null;
111
 
112
  if ($customer = $this->_quote->customer()) {
113
+ $customerId = Mage::helper('marketingsoftware/profile')->getCustomerCopernicaId($customer, $this->_quote->storeview());
114
  } else {
115
+ $customerId = Mage::helper('marketingsoftware/profile')->getEmailCopernicaId($address->email(), $this->_quote->storeview());
116
  }
117
 
118
  return array(
app/code/community/Copernica/MarketingSoftware/Model/Copernica/Profile/Subscription.php CHANGED
@@ -30,14 +30,14 @@
30
  class Copernica_MarketingSoftware_Model_Copernica_Profile_Subscription extends Copernica_MarketingSoftware_Model_Copernica_Profile
31
  {
32
  /**
33
- * @var Copernica_MarketingSoftware_Model_Abstraction_Subscription
34
  */
35
  protected $_abstractSubscription = false;
36
 
37
  /**
38
  * Set the subscription object to this object.
39
  *
40
- * @param Copernica_MarketingSoftware_Model_Abstraction_Subscription $subscription
41
  * @return Copernica_MarketingSoftware_Model_Copernica_Profile_Subscription
42
  */
43
  public function setSubscription(Copernica_MarketingSoftware_Model_Abstraction_Subscription $subscription)
@@ -77,9 +77,9 @@ class Copernica_MarketingSoftware_Model_Copernica_Profile_Subscription extends C
77
  $customerId = null;
78
 
79
  if ($customer = $this->_abstractSubscription->customer()) {
80
- $customerId = Mage::helper('marketingsoftware/profile')->getCustomerCopernicaId($customer, $this->_abstractSubscription->storeView());
81
  } else {
82
- $customerId = Mage::helper('marketingsoftware/profile')->getEmailCopernicaId($this->_abstractSubscription->email(), $this->_abstractSubscription->storeView());
83
  }
84
 
85
  return array(
30
  class Copernica_MarketingSoftware_Model_Copernica_Profile_Subscription extends Copernica_MarketingSoftware_Model_Copernica_Profile
31
  {
32
  /**
33
+ * @var Copernica_MarketingSoftware_Model_Abstraction_Subscription
34
  */
35
  protected $_abstractSubscription = false;
36
 
37
  /**
38
  * Set the subscription object to this object.
39
  *
40
+ * @param Copernica_MarketingSoftware_Model_Abstraction_Subscription $subscription
41
  * @return Copernica_MarketingSoftware_Model_Copernica_Profile_Subscription
42
  */
43
  public function setSubscription(Copernica_MarketingSoftware_Model_Abstraction_Subscription $subscription)
77
  $customerId = null;
78
 
79
  if ($customer = $this->_abstractSubscription->customer()) {
80
+ $customerId = Mage::helper('marketingsoftware/profile')->getCustomerCopernicaId($customer, $this->_abstractSubscription->storeView());
81
  } else {
82
+ $customerId = Mage::helper('marketingsoftware/profile')->getEmailCopernicaId($this->_abstractSubscription->email(), $this->_abstractSubscription->storeView());
83
  }
84
 
85
  return array(
app/code/community/Copernica/MarketingSoftware/Model/Copernica/Quote/Item/Subprofile.php CHANGED
@@ -42,8 +42,8 @@ class Copernica_MarketingSoftware_Model_Copernica_Quote_Item_Subprofile extends
42
  /**
43
  * Set the status of this quote item
44
  *
45
- * @param string $status
46
- * @return Copernica_MarketingSoftware_Model_Copernica_Quote_Item_Subprofile
47
  */
48
  public function setStatus($status)
49
  {
@@ -65,8 +65,8 @@ class Copernica_MarketingSoftware_Model_Copernica_Quote_Item_Subprofile extends
65
  /**
66
  * Try to store a quote item
67
  *
68
- * @param Copernica_MarketingSoftware_Model_Abstraction_Quote_Item $item
69
- * @return Copernica_MarketingSoftware_Model_Copernica_Quote_Item_Subprofile;
70
  */
71
  public function setQuoteItem(Copernica_MarketingSoftware_Model_Abstraction_Quote_Item $item)
72
  {
@@ -142,10 +142,14 @@ class Copernica_MarketingSoftware_Model_Copernica_Quote_Item_Subprofile extends
142
  $data['total_price'] = $price->total();
143
  }
144
 
145
- $data['categories'] = implode("\n", array_map(function($category) {
146
- return implode(' > ', $category);
147
- }, $product->categories()));
 
 
 
 
148
 
149
  return $data;
150
  }
151
- }
42
  /**
43
  * Set the status of this quote item
44
  *
45
+ * @param string $status
46
+ * @return Copernica_MarketingSoftware_Model_Copernica_Quote_Item_Subprofile
47
  */
48
  public function setStatus($status)
49
  {
65
  /**
66
  * Try to store a quote item
67
  *
68
+ * @param Copernica_MarketingSoftware_Model_Abstraction_Quote_Item $item
69
+ * @return Copernica_MarketingSoftware_Model_Copernica_Quote_Item_Subprofile;
70
  */
71
  public function setQuoteItem(Copernica_MarketingSoftware_Model_Abstraction_Quote_Item $item)
72
  {
142
  $data['total_price'] = $price->total();
143
  }
144
 
145
+ $data['categories'] = implode(
146
+ "\n", array_map(
147
+ function($category) {
148
+ return implode(' > ', $category);
149
+ }, $product->categories()
150
+ )
151
+ );
152
 
153
  return $data;
154
  }
155
+ }
app/code/community/Copernica/MarketingSoftware/Model/Copernica/Wishlist/Item/Subprofile.php CHANGED
@@ -47,8 +47,8 @@ class Copernica_MarketingSoftware_Model_Copernica_Wishlist_Item_Subprofile exten
47
  /**
48
  * Try to store a wishlist item
49
  *
50
- * @param Copernica_MarketingSoftware_Model_Abstraction_Wishlist_Item $item
51
- * @return Copernica_MarketingSoftware_Model_Copernica_Wishlist_Item_Subprofile;
52
  */
53
  public function setWishlistItem(Copernica_MarketingSoftware_Model_Abstraction_Wishlist_Item $item)
54
  {
@@ -74,7 +74,7 @@ class Copernica_MarketingSoftware_Model_Copernica_Wishlist_Item_Subprofile exten
74
  */
75
  public function requiredFields()
76
  {
77
- return Mage::helper('marketingsoftware')->requiredWishlistItemFields();
78
  }
79
 
80
  /**
@@ -123,10 +123,14 @@ class Copernica_MarketingSoftware_Model_Copernica_Wishlist_Item_Subprofile exten
123
  $data['total_price'] = $price->total();
124
  }
125
 
126
- $data['categories'] = implode("\n", array_map(function($category) {
127
- return implode(' > ', $category);
128
- }, $product->categories()));
 
 
 
 
129
 
130
  return $data;
131
  }
132
- }
47
  /**
48
  * Try to store a wishlist item
49
  *
50
+ * @param Copernica_MarketingSoftware_Model_Abstraction_Wishlist_Item $item
51
+ * @return Copernica_MarketingSoftware_Model_Copernica_Wishlist_Item_Subprofile;
52
  */
53
  public function setWishlistItem(Copernica_MarketingSoftware_Model_Abstraction_Wishlist_Item $item)
54
  {
74
  */
75
  public function requiredFields()
76
  {
77
+ return Mage::helper('marketingsoftware')->requiredWishlistItemFields();
78
  }
79
 
80
  /**
123
  $data['total_price'] = $price->total();
124
  }
125
 
126
+ $data['categories'] = implode(
127
+ "\n", array_map(
128
+ function($category) {
129
+ return implode(' > ', $category);
130
+ }, $product->categories()
131
+ )
132
+ );
133
 
134
  return $data;
135
  }
136
+ }
app/code/community/Copernica/MarketingSoftware/Model/Error/Queue.php CHANGED
@@ -50,7 +50,7 @@ class Copernica_MarketingSoftware_Model_Error_Queue extends Mage_Core_Model_Abst
50
  /**
51
  * Set object instance
52
  *
53
- * @param object $object
54
  */
55
  public function setObject($object)
56
  {
@@ -60,7 +60,7 @@ class Copernica_MarketingSoftware_Model_Error_Queue extends Mage_Core_Model_Abst
60
  /**
61
  * Set customer Id
62
  *
63
- * @param int $customerId
64
  */
65
  public function setCustomerId($customerId)
66
  {
@@ -87,10 +87,10 @@ class Copernica_MarketingSoftware_Model_Error_Queue extends Mage_Core_Model_Abst
87
 
88
  /**
89
  * This method will create instance from processing queue item
90
- *
91
- * @param Copernica_MarketingSoftware_Model_Queue_Event_Item $queueItem
92
  */
93
- static public function createFromQueueItem(Copernica_MarketingSoftware_Model_Queue_Event_Item $queueItem)
94
  {
95
  $errorModel = Mage::getModel('marketingsoftware/error_queue');
96
  $errorModel->setObject($queueItem->getObject());
@@ -103,4 +103,4 @@ class Copernica_MarketingSoftware_Model_Error_Queue extends Mage_Core_Model_Abst
103
 
104
  return $errorModel;
105
  }
106
- }
50
  /**
51
  * Set object instance
52
  *
53
+ * @param object $object
54
  */
55
  public function setObject($object)
56
  {
60
  /**
61
  * Set customer Id
62
  *
63
+ * @param int $customerId
64
  */
65
  public function setCustomerId($customerId)
66
  {
87
 
88
  /**
89
  * This method will create instance from processing queue item
90
+ *
91
+ * @param Copernica_MarketingSoftware_Model_Queue_Item $queueItem
92
  */
93
+ static public function createFromQueueItem(Copernica_MarketingSoftware_Model_Queue_Item $queueItem)
94
  {
95
  $errorModel = Mage::getModel('marketingsoftware/error_queue');
96
  $errorModel->setObject($queueItem->getObject());
103
 
104
  return $errorModel;
105
  }
106
+ }
app/code/community/Copernica/MarketingSoftware/Model/Mysql4/Queue/Item.php CHANGED
@@ -52,7 +52,7 @@ class Copernica_MarketingSoftware_Model_Mysql4_Queue_Item extends Mage_Core_Mode
52
  $lockResult = $adapter->query("select get_lock('COPERNICA_".$row['customer']."', 1) as 'lock'")->fetchAll();
53
 
54
  if ($lockResult[0]['lock'] == 1) {
55
- return $row['customer'];
56
  }
57
  }
58
  }
52
  $lockResult = $adapter->query("select get_lock('COPERNICA_".$row['customer']."', 1) as 'lock'")->fetchAll();
53
 
54
  if ($lockResult[0]['lock'] == 1) {
55
+ return $row['customer'];
56
  }
57
  }
58
  }
app/code/community/Copernica/MarketingSoftware/Model/Observer.php CHANGED
@@ -48,14 +48,14 @@ class Copernica_MarketingSoftware_Model_Observer
48
  * This method is fired during checkout process, after the customer has entered billing address
49
  * and saved the shipping method
50
  *
51
- * @param Varien_Event_Observer $observer
52
  */
53
  public function checkoutSaveStep(Varien_Event_Observer $observer)
54
  {
55
- $quote = $observer->getEvent()->getQuote();
56
-
57
  if (!$this->_enabled() || !$this->_isValidStore() || !is_object($quote)) {
58
- return;
59
  }
60
 
61
  $customerId = $quote->getCustomerId();
@@ -76,14 +76,14 @@ class Copernica_MarketingSoftware_Model_Observer
76
  * Method for event 'sales_quote_item_delete_before'.
77
  * An item is removed from a quote
78
  *
79
- * @param Varien_Event_Observer $observer
80
  */
81
  public function quoteItemRemoved(Varien_Event_Observer $observer)
82
  {
83
- $quoteItem = $observer->getEvent()->getItem();
84
-
85
  if (!$this->_enabled() || !$this->_isValidStore() || !is_object($quoteItem) || $quoteItem->getParentItemId()) {
86
- return;
87
  }
88
 
89
  $quote = $quoteItem->getQuote();
@@ -91,24 +91,24 @@ class Copernica_MarketingSoftware_Model_Observer
91
  $customerId = $quote->getCustomerId();
92
 
93
  if (!$customerId) {
94
- if (!Mage::getSingleton('customer/session')->isLoggedIn()) {
95
- return;
96
- }
97
 
98
- $customerId = Mage::getSingleton('customer/session')->getCustomer()->getId();
99
 
100
- if (!$customerId) {
101
- return;
102
- }
103
  }
104
 
105
  $quoteItemEntity = Mage::getModel('marketingsoftware/copernica_entity_quote_item');
106
  $quoteItemEntity->setQuoteItem($quoteItem);
107
 
108
  $quoteItemData = array(
109
- 'item_id' => $quoteItemEntity->getId(),
110
- 'storeview_id' => $quoteItemEntity->getStoreView()->id(),
111
- 'status' => 'deleted',
112
  );
113
 
114
  $queue = Mage::getModel('marketingsoftware/queue_item')
@@ -124,14 +124,14 @@ class Copernica_MarketingSoftware_Model_Observer
124
  * Method for event 'sales_quote_item_save_after'.
125
  * An item is added or modified
126
  *
127
- * @param Varien_Event_Observer $observer
128
  */
129
  public function quoteItemModified(Varien_Event_Observer $observer)
130
  {
131
- $quoteItem = $observer->getEvent()->getItem();
132
-
133
  if (!$this->_enabled() || !$this->_isValidStore() || !is_object($quoteItem) || $quoteItem->getParentItemId()) {
134
- return;
135
  }
136
 
137
  if (method_exists($quoteItem, 'hasDataChanges') && !$quoteItem->hasDataChanges()) {
@@ -144,50 +144,50 @@ class Copernica_MarketingSoftware_Model_Observer
144
 
145
  if (!$customerId) {
146
  if (!Mage::getSingleton('customer/session')->isLoggedIn()) {
147
- return;
148
  }
149
 
150
  $customerId = Mage::getSingleton('customer/session')->getCustomer()->getId();
151
 
152
  if (!$customerId) {
153
- return;
154
  }
155
  }
156
 
157
  $queue = Mage::getModel('marketingsoftware/queue_item')
158
- ->setObject(array('quoteItemId' => $quoteItem->getId(), 'quoteId' => $quote->getId(), 'customerId' => $customerId))
159
- ->setCustomer($customerId)
160
- ->setName('item')
161
- ->setAction($quoteItem->isObjectNew() ? 'add' : 'modify')
162
- ->setEntityId($quoteItem->getId())
163
- ->save();
164
  }
165
 
166
  /**
167
  * Listen to when quote is removed.
168
  *
169
- * @todo Review this one
170
- * @param Varien_Event_Observer $observer
171
  */
172
  public function quoteDelete(Varien_Event_Observer $observer)
173
  {
174
- $quote = $observer->getEvent()->getQuote();
175
-
176
  if (!$this->_enabled() || !$this->_isValidStore() || !is_object($quote)) {
177
- return;
178
  }
179
 
180
  $customerId = $quote->getCustomerId();
181
 
182
  if (!$customerId) {
183
  if (!Mage::getSingleton('customer/session')->isLoggedIn()) {
184
- return;
185
  }
186
 
187
  $customerId = Mage::getSingleton('customer/session')->getCustomer()->getId();
188
 
189
  if (!$customerId) {
190
- return;
191
  }
192
  }
193
 
@@ -202,13 +202,13 @@ class Copernica_MarketingSoftware_Model_Observer
202
  $storeView = implode(' > ', array ($website->getName(), $group->getName(), $store->getName()));
203
 
204
  if ($email) {
205
- Mage::getModel('marketingsoftware/queue_item')
206
- ->setObject(array('storeView' => $storeView, 'quoteId' => $quote->getId(), 'customerId' => $customerId))
207
- ->setCustomer($customerId)
208
- ->setName('quote')
209
- ->setAction('remove')
210
- ->setEntityId($quote->getEntityId())
211
- ->save();
212
  }
213
  }
214
 
@@ -218,10 +218,10 @@ class Copernica_MarketingSoftware_Model_Observer
218
  */
219
  public function orderModified(Varien_Event_Observer $observer)
220
  {
221
- $order = $observer->getEvent()->getOrder();
222
-
223
  if (!$this->_enabled() || !$this->_isValidStore() || !is_object($order) || !$order->getState()) {
224
- return;
225
  }
226
 
227
  $customerId = $order->getCustomerId();
@@ -241,10 +241,10 @@ class Copernica_MarketingSoftware_Model_Observer
241
  */
242
  public function wishlistItemModified(Varien_Event_Observer $observer)
243
  {
244
- $wishlistItem = $observer->getEvent()->getItem();
245
-
246
  if (!$this->_enabled() || !$this->_isValidStore() || !is_object($wishlistItem)) {
247
- return;
248
  }
249
 
250
  $wishlist = Mage::getModel('wishlist/wishlist')->load($wishlistItem->getWishlistId());
@@ -252,12 +252,12 @@ class Copernica_MarketingSoftware_Model_Observer
252
  $customerId = $wishlist->getCustomerId();
253
 
254
  $queue = Mage::getModel('marketingsoftware/queue_item')
255
- ->setObject(array('wishlistItemId' => $wishlistItem->getId(), 'customerId' => $customerId))
256
- ->setCustomer($customerId)
257
- ->setName('wishlist_item')
258
- ->setAction($wishlistItem->isObjectNew() ? 'add' : 'modify')
259
- ->setEntityId($wishlistItem->getId())
260
- ->save();
261
  }
262
 
263
  /**
@@ -266,10 +266,10 @@ class Copernica_MarketingSoftware_Model_Observer
266
  */
267
  public function newsletterSubscriptionRemoved(Varien_Event_Observer $observer)
268
  {
269
- $subscriber = $observer->getEvent()->getSubscriber();
270
-
271
  if (!$this->_enabled() || !$this->_isValidStore() || !is_object($subscriber)) {
272
- return;
273
  }
274
 
275
  $customerId = $subscriber->getCustomerId();
@@ -289,10 +289,10 @@ class Copernica_MarketingSoftware_Model_Observer
289
  */
290
  public function newsletterSubscriptionModified(Varien_Event_Observer $observer)
291
  {
292
- $subscriber = $observer->getEvent()->getSubscriber();
293
-
294
  if (!$this->_enabled() || !$this->_isValidStore() || !is_object($subscriber)) {
295
- return;
296
  }
297
 
298
  if (method_exists($subscriber, 'hasDataChanges') && !$subscriber->hasDataChanges()) {
@@ -315,24 +315,24 @@ class Copernica_MarketingSoftware_Model_Observer
315
  */
316
  public function customerRemoved(Varien_Event_Observer $observer)
317
  {
318
- $customer = $observer->getEvent()->getCustomer();
319
-
320
  if (!$this->_enabled() || !$this->_isValidStore() || !is_object($customer)) {
321
- return;
322
  }
323
 
324
  $customerId = $customer->getId();
325
 
326
  if (!$customerId) {
327
- if (!Mage::getSingleton('customer/session')->isLoggedIn()) {
328
- return;
329
- }
330
 
331
- $customerId = Mage::getSingleton('customer/session')->getCustomer()->getId();
332
 
333
- if (!$customerId) {
334
- return;
335
- }
336
  }
337
 
338
  $customerEntity = Mage::getModel('marketingsoftware/copernica_entity_customer');
@@ -353,30 +353,30 @@ class Copernica_MarketingSoftware_Model_Observer
353
  */
354
  public function customerModified(Varien_Event_Observer $observer)
355
  {
356
- $address = $observer->getEvent()->getCustomerAddress();
357
-
358
- if(is_object($address)) {
359
- $customer = $address->getCustomer();
360
- } else {
361
- $customer = $observer->getEvent()->getCustomer();
362
- }
363
-
364
  if (!$this->_enabled() || !$this->_isValidStore() || !is_object($customer)) {
365
- return;
366
  }
367
 
368
  $customerId = $customer->getId();
369
 
370
- if (!$customerId) {
371
- if (!Mage::getSingleton('customer/session')->isLoggedIn()) {
372
- return;
373
- }
374
 
375
- $customerId = Mage::getSingleton('customer/session')->getCustomer()->getId();
376
 
377
- if (!$customerId) {
378
- return;
379
- }
380
  }
381
 
382
  $queue = Mage::getModel('marketingsoftware/queue_item')
@@ -394,10 +394,10 @@ class Copernica_MarketingSoftware_Model_Observer
394
  */
395
  public function productViewed(Varien_Event_Observer $observer)
396
  {
397
- $product = $observer->getEvent()->getProduct();
398
-
399
  if (!$this->_enabled() || !$this->_isValidStore() || !is_object($product)) {
400
- return;
401
  }
402
 
403
  $customer = Mage::getSingleton('customer/session')->getCustomer();
@@ -405,15 +405,15 @@ class Copernica_MarketingSoftware_Model_Observer
405
  $customerId = $customer->getId();
406
 
407
  if (!$customerId) {
408
- if (!Mage::getSingleton('customer/session')->isLoggedIn()) {
409
- return;
410
- }
411
 
412
- $customerId = Mage::getSingleton('customer/session')->getCustomer()->getId();
413
 
414
- if (!$customerId) {
415
- return;
416
- }
417
  }
418
 
419
  $queue = Mage::getModel('marketingsoftware/queue_item')
@@ -432,7 +432,7 @@ class Copernica_MarketingSoftware_Model_Observer
432
  public function detectAbandonedCarts()
433
  {
434
  if (!$this->_enabled()) {
435
- return;
436
  }
437
 
438
  $processor = Mage::getModel('marketingsoftware/abandoned_carts_processor');
@@ -457,7 +457,7 @@ class Copernica_MarketingSoftware_Model_Observer
457
  public function processQueue()
458
  {
459
  if (!$this->_enabled() || !Mage::helper('marketingsoftware/config')->getVanillaCrons()) {
460
- return;
461
  }
462
 
463
  $queueProcessor = Mage::getModel('marketingsoftware/queue_processor');
48
  * This method is fired during checkout process, after the customer has entered billing address
49
  * and saved the shipping method
50
  *
51
+ * @param Varien_Event_Observer $observer
52
  */
53
  public function checkoutSaveStep(Varien_Event_Observer $observer)
54
  {
55
+ $quote = $observer->getEvent()->getQuote();
56
+
57
  if (!$this->_enabled() || !$this->_isValidStore() || !is_object($quote)) {
58
+ return;
59
  }
60
 
61
  $customerId = $quote->getCustomerId();
76
  * Method for event 'sales_quote_item_delete_before'.
77
  * An item is removed from a quote
78
  *
79
+ * @param Varien_Event_Observer $observer
80
  */
81
  public function quoteItemRemoved(Varien_Event_Observer $observer)
82
  {
83
+ $quoteItem = $observer->getEvent()->getItem();
84
+
85
  if (!$this->_enabled() || !$this->_isValidStore() || !is_object($quoteItem) || $quoteItem->getParentItemId()) {
86
+ return;
87
  }
88
 
89
  $quote = $quoteItem->getQuote();
91
  $customerId = $quote->getCustomerId();
92
 
93
  if (!$customerId) {
94
+ if (!Mage::getSingleton('customer/session')->isLoggedIn()) {
95
+ return;
96
+ }
97
 
98
+ $customerId = Mage::getSingleton('customer/session')->getCustomer()->getId();
99
 
100
+ if (!$customerId) {
101
+ return;
102
+ }
103
  }
104
 
105
  $quoteItemEntity = Mage::getModel('marketingsoftware/copernica_entity_quote_item');
106
  $quoteItemEntity->setQuoteItem($quoteItem);
107
 
108
  $quoteItemData = array(
109
+ 'item_id' => $quoteItemEntity->getId(),
110
+ 'storeview_id' => $quoteItemEntity->getStoreView()->id(),
111
+ 'status' => 'deleted',
112
  );
113
 
114
  $queue = Mage::getModel('marketingsoftware/queue_item')
124
  * Method for event 'sales_quote_item_save_after'.
125
  * An item is added or modified
126
  *
127
+ * @param Varien_Event_Observer $observer
128
  */
129
  public function quoteItemModified(Varien_Event_Observer $observer)
130
  {
131
+ $quoteItem = $observer->getEvent()->getItem();
132
+
133
  if (!$this->_enabled() || !$this->_isValidStore() || !is_object($quoteItem) || $quoteItem->getParentItemId()) {
134
+ return;
135
  }
136
 
137
  if (method_exists($quoteItem, 'hasDataChanges') && !$quoteItem->hasDataChanges()) {
144
 
145
  if (!$customerId) {
146
  if (!Mage::getSingleton('customer/session')->isLoggedIn()) {
147
+ return;
148
  }
149
 
150
  $customerId = Mage::getSingleton('customer/session')->getCustomer()->getId();
151
 
152
  if (!$customerId) {
153
+ return;
154
  }
155
  }
156
 
157
  $queue = Mage::getModel('marketingsoftware/queue_item')
158
+ ->setObject(array('quoteItemId' => $quoteItem->getId(), 'quoteId' => $quote->getId(), 'customerId' => $customerId))
159
+ ->setCustomer($customerId)
160
+ ->setName('item')
161
+ ->setAction($quoteItem->isObjectNew() ? 'add' : 'modify')
162
+ ->setEntityId($quoteItem->getId())
163
+ ->save();
164
  }
165
 
166
  /**
167
  * Listen to when quote is removed.
168
  *
169
+ * @todo Review this one
170
+ * @param Varien_Event_Observer $observer
171
  */
172
  public function quoteDelete(Varien_Event_Observer $observer)
173
  {
174
+ $quote = $observer->getEvent()->getQuote();
175
+
176
  if (!$this->_enabled() || !$this->_isValidStore() || !is_object($quote)) {
177
+ return;
178
  }
179
 
180
  $customerId = $quote->getCustomerId();
181
 
182
  if (!$customerId) {
183
  if (!Mage::getSingleton('customer/session')->isLoggedIn()) {
184
+ return;
185
  }
186
 
187
  $customerId = Mage::getSingleton('customer/session')->getCustomer()->getId();
188
 
189
  if (!$customerId) {
190
+ return;
191
  }
192
  }
193
 
202
  $storeView = implode(' > ', array ($website->getName(), $group->getName(), $store->getName()));
203
 
204
  if ($email) {
205
+ Mage::getModel('marketingsoftware/queue_item')
206
+ ->setObject(array('storeView' => $storeView, 'quoteId' => $quote->getId(), 'customerId' => $customerId))
207
+ ->setCustomer($customerId)
208
+ ->setName('quote')
209
+ ->setAction('remove')
210
+ ->setEntityId($quote->getEntityId())
211
+ ->save();
212
  }
213
  }
214
 
218
  */
219
  public function orderModified(Varien_Event_Observer $observer)
220
  {
221
+ $order = $observer->getEvent()->getOrder();
222
+
223
  if (!$this->_enabled() || !$this->_isValidStore() || !is_object($order) || !$order->getState()) {
224
+ return;
225
  }
226
 
227
  $customerId = $order->getCustomerId();
241
  */
242
  public function wishlistItemModified(Varien_Event_Observer $observer)
243
  {
244
+ $wishlistItem = $observer->getEvent()->getItem();
245
+
246
  if (!$this->_enabled() || !$this->_isValidStore() || !is_object($wishlistItem)) {
247
+ return;
248
  }
249
 
250
  $wishlist = Mage::getModel('wishlist/wishlist')->load($wishlistItem->getWishlistId());
252
  $customerId = $wishlist->getCustomerId();
253
 
254
  $queue = Mage::getModel('marketingsoftware/queue_item')
255
+ ->setObject(array('wishlistItemId' => $wishlistItem->getId(), 'customerId' => $customerId))
256
+ ->setCustomer($customerId)
257
+ ->setName('wishlist_item')
258
+ ->setAction($wishlistItem->isObjectNew() ? 'add' : 'modify')
259
+ ->setEntityId($wishlistItem->getId())
260
+ ->save();
261
  }
262
 
263
  /**
266
  */
267
  public function newsletterSubscriptionRemoved(Varien_Event_Observer $observer)
268
  {
269
+ $subscriber = $observer->getEvent()->getSubscriber();
270
+
271
  if (!$this->_enabled() || !$this->_isValidStore() || !is_object($subscriber)) {
272
+ return;
273
  }
274
 
275
  $customerId = $subscriber->getCustomerId();
289
  */
290
  public function newsletterSubscriptionModified(Varien_Event_Observer $observer)
291
  {
292
+ $subscriber = $observer->getEvent()->getSubscriber();
293
+
294
  if (!$this->_enabled() || !$this->_isValidStore() || !is_object($subscriber)) {
295
+ return;
296
  }
297
 
298
  if (method_exists($subscriber, 'hasDataChanges') && !$subscriber->hasDataChanges()) {
315
  */
316
  public function customerRemoved(Varien_Event_Observer $observer)
317
  {
318
+ $customer = $observer->getEvent()->getCustomer();
319
+
320
  if (!$this->_enabled() || !$this->_isValidStore() || !is_object($customer)) {
321
+ return;
322
  }
323
 
324
  $customerId = $customer->getId();
325
 
326
  if (!$customerId) {
327
+ if (!Mage::getSingleton('customer/session')->isLoggedIn()) {
328
+ return;
329
+ }
330
 
331
+ $customerId = Mage::getSingleton('customer/session')->getCustomer()->getId();
332
 
333
+ if (!$customerId) {
334
+ return;
335
+ }
336
  }
337
 
338
  $customerEntity = Mage::getModel('marketingsoftware/copernica_entity_customer');
353
  */
354
  public function customerModified(Varien_Event_Observer $observer)
355
  {
356
+ $address = $observer->getEvent()->getCustomerAddress();
357
+
358
+ if (is_object($address)) {
359
+ $customer = $address->getCustomer();
360
+ } else {
361
+ $customer = $observer->getEvent()->getCustomer();
362
+ }
363
+
364
  if (!$this->_enabled() || !$this->_isValidStore() || !is_object($customer)) {
365
+ return;
366
  }
367
 
368
  $customerId = $customer->getId();
369
 
370
+ if (!$customerId) {
371
+ if (!Mage::getSingleton('customer/session')->isLoggedIn()) {
372
+ return;
373
+ }
374
 
375
+ $customerId = Mage::getSingleton('customer/session')->getCustomer()->getId();
376
 
377
+ if (!$customerId) {
378
+ return;
379
+ }
380
  }
381
 
382
  $queue = Mage::getModel('marketingsoftware/queue_item')
394
  */
395
  public function productViewed(Varien_Event_Observer $observer)
396
  {
397
+ $product = $observer->getEvent()->getProduct();
398
+
399
  if (!$this->_enabled() || !$this->_isValidStore() || !is_object($product)) {
400
+ return;
401
  }
402
 
403
  $customer = Mage::getSingleton('customer/session')->getCustomer();
405
  $customerId = $customer->getId();
406
 
407
  if (!$customerId) {
408
+ if (!Mage::getSingleton('customer/session')->isLoggedIn()) {
409
+ return;
410
+ }
411
 
412
+ $customerId = Mage::getSingleton('customer/session')->getCustomer()->getId();
413
 
414
+ if (!$customerId) {
415
+ return;
416
+ }
417
  }
418
 
419
  $queue = Mage::getModel('marketingsoftware/queue_item')
432
  public function detectAbandonedCarts()
433
  {
434
  if (!$this->_enabled()) {
435
+ return;
436
  }
437
 
438
  $processor = Mage::getModel('marketingsoftware/abandoned_carts_processor');
457
  public function processQueue()
458
  {
459
  if (!$this->_enabled() || !Mage::helper('marketingsoftware/config')->getVanillaCrons()) {
460
+ return;
461
  }
462
 
463
  $queueProcessor = Mage::getModel('marketingsoftware/queue_processor');
app/code/community/Copernica/MarketingSoftware/Model/Profile/Cache.php CHANGED
@@ -58,7 +58,7 @@ class Copernica_MarketingSoftware_Model_Profile_Cache extends Mage_Core_Model_Ab
58
  /**
59
  * Set profile Id
60
  *
61
- * @param int $profileId
62
  * @return Copernica_MarketingSoftware_Model_Profile_Cache
63
  */
64
  public function setProfileId($profileId)
@@ -71,7 +71,7 @@ class Copernica_MarketingSoftware_Model_Profile_Cache extends Mage_Core_Model_Ab
71
  /**
72
  * Set customer Id
73
  *
74
- * @param string $customerId
75
  * @return Copernica_MarketingSoftware_Model_Profile_Cache
76
  */
77
  public function setCustomerId($customerId)
@@ -80,4 +80,4 @@ class Copernica_MarketingSoftware_Model_Profile_Cache extends Mage_Core_Model_Ab
80
 
81
  return $this;
82
  }
83
- }
58
  /**
59
  * Set profile Id
60
  *
61
+ * @param int $profileId
62
  * @return Copernica_MarketingSoftware_Model_Profile_Cache
63
  */
64
  public function setProfileId($profileId)
71
  /**
72
  * Set customer Id
73
  *
74
+ * @param string $customerId
75
  * @return Copernica_MarketingSoftware_Model_Profile_Cache
76
  */
77
  public function setCustomerId($customerId)
80
 
81
  return $this;
82
  }
83
+ }
app/code/community/Copernica/MarketingSoftware/Model/Queue/Event/Abstract.php CHANGED
@@ -32,14 +32,14 @@ abstract class Copernica_MarketingSoftware_Model_Queue_Event_Abstract
32
  /**
33
  * What queue item was used to construct this item
34
  *
35
- * @var Copernica_MarketingSoftware_Model_Queue_Item
36
  */
37
  protected $_queueItem;
38
 
39
  /**
40
  * Construct the item given the queueitem
41
  *
42
- * @param Copernica_MarketingSoftware_Model_Queue_Item $item
43
  */
44
  public function setQueueItem(Copernica_MarketingSoftware_Model_Queue_Item $item)
45
  {
@@ -49,8 +49,8 @@ abstract class Copernica_MarketingSoftware_Model_Queue_Event_Abstract
49
  /**
50
  * Get the object for this queue item
51
  *
52
- * @todo Not used?
53
- * @return Abstraction object
54
  */
55
  protected function _getObject()
56
  {
@@ -60,8 +60,8 @@ abstract class Copernica_MarketingSoftware_Model_Queue_Event_Abstract
60
  /**
61
  * Get the entity Id
62
  *
63
- * @todo Not used?
64
- * @return int
65
  */
66
  protected function _getEntityId()
67
  {
@@ -71,7 +71,7 @@ abstract class Copernica_MarketingSoftware_Model_Queue_Event_Abstract
71
  /**
72
  * Get the customer Id
73
  *
74
- * @todo Not used?
75
  * @return int
76
  */
77
  protected function _getCustomerId()
@@ -89,7 +89,7 @@ abstract class Copernica_MarketingSoftware_Model_Queue_Event_Abstract
89
  $methodName = 'action'.ucfirst($this->_queueItem->getAction());
90
 
91
  if (!method_exists($this, $methodName)) {
92
- return false;
93
  }
94
 
95
  return $this->$methodName();
@@ -106,4 +106,4 @@ abstract class Copernica_MarketingSoftware_Model_Queue_Event_Abstract
106
  ->setAction($this->_queueItem->getAction())
107
  ->save();
108
  }
109
- }
32
  /**
33
  * What queue item was used to construct this item
34
  *
35
+ * @var Copernica_MarketingSoftware_Model_Queue_Item
36
  */
37
  protected $_queueItem;
38
 
39
  /**
40
  * Construct the item given the queueitem
41
  *
42
+ * @param Copernica_MarketingSoftware_Model_Queue_Item $item
43
  */
44
  public function setQueueItem(Copernica_MarketingSoftware_Model_Queue_Item $item)
45
  {
49
  /**
50
  * Get the object for this queue item
51
  *
52
+ * @todo Not used?
53
+ * @return Abstraction object
54
  */
55
  protected function _getObject()
56
  {
60
  /**
61
  * Get the entity Id
62
  *
63
+ * @todo Not used?
64
+ * @return int
65
  */
66
  protected function _getEntityId()
67
  {
71
  /**
72
  * Get the customer Id
73
  *
74
+ * @todo Not used?
75
  * @return int
76
  */
77
  protected function _getCustomerId()
89
  $methodName = 'action'.ucfirst($this->_queueItem->getAction());
90
 
91
  if (!method_exists($this, $methodName)) {
92
+ return false;
93
  }
94
 
95
  return $this->$methodName();
106
  ->setAction($this->_queueItem->getAction())
107
  ->save();
108
  }
109
+ }
app/code/community/Copernica/MarketingSoftware/Model/Queue/Event/Checkout.php CHANGED
@@ -32,17 +32,17 @@
32
  */
33
  class Copernica_MarketingSoftware_Model_Queue_Event_Checkout extends Copernica_MarketingSoftware_Model_Queue_Event_Abstract
34
  {
35
- /**
36
- * Customer entity
37
- *
38
- * @var Copernica_MarketingSoftware_Model_Copernica_Entity_Customer
39
- */
40
- protected $_customerEntity;
41
-
42
  /**
43
  * Process add action
44
  *
45
- * @return boolean
46
  */
47
  public function actionAdd()
48
  {
@@ -52,15 +52,15 @@ class Copernica_MarketingSoftware_Model_Queue_Event_Checkout extends Copernica_M
52
  /**
53
  * Modify action on checkout event
54
  *
55
- * @return boolean
56
  */
57
  public function actionModify()
58
  {
59
- $customerEntity = $this->_getCustomerEntity();
60
-
61
- if (!$customerEntity) {
62
- return false;
63
- }
64
 
65
  $quote = Mage::getModel('sales/quote')->loadByIdWithoutStore($this->_getEntityId());
66
 
@@ -71,21 +71,23 @@ class Copernica_MarketingSoftware_Model_Queue_Event_Checkout extends Copernica_M
71
  $quoteItemCollection = Mage::helper('marketingsoftware/config')->getQuoteItemCollectionId();
72
 
73
  if ($quoteItemCollection) {
74
- $response = $request->get('/profile/'.$customerEntity->getProfileId().'/subprofiles/'.$quoteItemCollection, array(
75
- 'fields' => array('quote_id=='.$this->_getEntityId())
76
- ));
 
 
77
  }
78
 
79
  foreach ($response['data'] as $subprofile) {
80
- $request->delete('/subprofile/'.$subprofile['ID']);
81
  }
82
  } else {
83
  foreach ($quote->getAllItems() as $quoteItem) {
84
- $quoteItemEntity = Mage::getModel('marketingsoftware/copernica_entity_quote_item');
85
- $quoteItemEntity->setQuoteItem($quoteItem);
86
-
87
- $restQuoteItem = $quoteItemEntity->getRestQuoteItem();
88
- $restQuoteItem->syncWithQuote($customerEntity, $quote->getId());
89
  }
90
  }
91
 
@@ -96,19 +98,19 @@ class Copernica_MarketingSoftware_Model_Queue_Event_Checkout extends Copernica_M
96
 
97
  protected function _getCustomerEntity()
98
  {
99
- if ($this->_customerEntity) {
100
- return $this->_customerEntity;
101
- } else {
102
- $object = $this->_getObject();
103
 
104
- if (property_exists($object, 'customerId') && is_numeric($object->customerId)) {
105
- $customerEntity = Mage::getModel('marketingsoftware/copernica_entity_customer');
106
- $customerEntity->setCustomer($object->customerId);
107
-
108
- return $this->_customerEntity = $customerEntity;
109
- } else {
110
- return false;
111
- }
112
- }
113
  }
114
- }
32
  */
33
  class Copernica_MarketingSoftware_Model_Queue_Event_Checkout extends Copernica_MarketingSoftware_Model_Queue_Event_Abstract
34
  {
35
+ /**
36
+ * Customer entity
37
+ *
38
+ * @var Copernica_MarketingSoftware_Model_Copernica_Entity_Customer
39
+ */
40
+ protected $_customerEntity;
41
+
42
  /**
43
  * Process add action
44
  *
45
+ * @return boolean
46
  */
47
  public function actionAdd()
48
  {
52
  /**
53
  * Modify action on checkout event
54
  *
55
+ * @return boolean
56
  */
57
  public function actionModify()
58
  {
59
+ $customerEntity = $this->_getCustomerEntity();
60
+
61
+ if (!$customerEntity) {
62
+ return false;
63
+ }
64
 
65
  $quote = Mage::getModel('sales/quote')->loadByIdWithoutStore($this->_getEntityId());
66
 
71
  $quoteItemCollection = Mage::helper('marketingsoftware/config')->getQuoteItemCollectionId();
72
 
73
  if ($quoteItemCollection) {
74
+ $response = $request->get(
75
+ '/profile/'.$customerEntity->getProfileId().'/subprofiles/'.$quoteItemCollection, array(
76
+ 'fields' => array('quote_id=='.$this->_getEntityId())
77
+ )
78
+ );
79
  }
80
 
81
  foreach ($response['data'] as $subprofile) {
82
+ $request->delete('/subprofile/'.$subprofile['ID']);
83
  }
84
  } else {
85
  foreach ($quote->getAllItems() as $quoteItem) {
86
+ $quoteItemEntity = Mage::getModel('marketingsoftware/copernica_entity_quote_item');
87
+ $quoteItemEntity->setQuoteItem($quoteItem);
88
+
89
+ $restQuoteItem = $quoteItemEntity->getRestQuoteItem();
90
+ $restQuoteItem->syncWithQuote($customerEntity, $quote->getId());
91
  }
92
  }
93
 
98
 
99
  protected function _getCustomerEntity()
100
  {
101
+ if ($this->_customerEntity) {
102
+ return $this->_customerEntity;
103
+ } else {
104
+ $object = $this->_getObject();
105
 
106
+ if (property_exists($object, 'customerId') && is_numeric($object->customerId)) {
107
+ $customerEntity = Mage::getModel('marketingsoftware/copernica_entity_customer');
108
+ $customerEntity->setCustomer($object->customerId);
109
+
110
+ return $this->_customerEntity = $customerEntity;
111
+ } else {
112
+ return false;
113
+ }
114
+ }
115
  }
116
+ }
app/code/community/Copernica/MarketingSoftware/Model/Queue/Event/Customer.php CHANGED
@@ -35,7 +35,7 @@ class Copernica_MarketingSoftware_Model_Queue_Event_Customer extends Copernica_M
35
  /**
36
  * Handle customer add action. It's basicaly the same as modify action.
37
  *
38
- * @return boolean
39
  */
40
  public function actionAdd()
41
  {
@@ -47,7 +47,7 @@ class Copernica_MarketingSoftware_Model_Queue_Event_Customer extends Copernica_M
47
  * when customer is modified. So on administrative edition or when customer
48
  * himself is modifying his data.
49
  *
50
- * @return boolean
51
  */
52
  public function actionModify()
53
  {
@@ -68,7 +68,7 @@ class Copernica_MarketingSoftware_Model_Queue_Event_Customer extends Copernica_M
68
  * This action is expensive both with time and resources. It should be called
69
  * only when there is a need for that.
70
  *
71
- * @return boolean
72
  */
73
  public function actionFull()
74
  {
@@ -79,13 +79,13 @@ class Copernica_MarketingSoftware_Model_Queue_Event_Customer extends Copernica_M
79
  $restCustomer->setProfile();
80
 
81
  foreach ($customerEntity->getOrders() as $orderEntity) {
82
- $restOrder = $orderEntity->getRestOrder();
83
- $restOrder->syncWithCustomer($customerEntity);
84
  }
85
 
86
- foreach($customerEntity->getWishlistItems() as $wishlistItemEntity) {
87
- $restWishlistItem = $wishlistItemEntity->getRestWishlistItem();
88
- $restWishlistItem->syncWithCustomer($customerEntity);
89
  }
90
 
91
  //$request->commit();
@@ -110,7 +110,8 @@ class Copernica_MarketingSoftware_Model_Queue_Event_Customer extends Copernica_M
110
 
111
  $group = $store->getGroup();
112
 
113
- $storeView = implode(' > ', array (
 
114
  $website->getName(),
115
  $group->getName(),
116
  $store->getName())
@@ -125,16 +126,16 @@ class Copernica_MarketingSoftware_Model_Queue_Event_Customer extends Copernica_M
125
  $profileCache = $profileCacheCollection->getFirstItem();
126
 
127
  if (!$profileCache->isObjectNew()) {
128
- $profileCache->delete();
129
  }
130
  }
131
 
132
  if (!property_exists($object, 'profileId')) {
133
- return false;
134
  }
135
 
136
  Mage::helper('marketingsoftware/rest_request')->delete('/profile/'.$object->profileId);
137
 
138
  return true;
139
  }
140
- }
35
  /**
36
  * Handle customer add action. It's basicaly the same as modify action.
37
  *
38
+ * @return boolean
39
  */
40
  public function actionAdd()
41
  {
47
  * when customer is modified. So on administrative edition or when customer
48
  * himself is modifying his data.
49
  *
50
+ * @return boolean
51
  */
52
  public function actionModify()
53
  {
68
  * This action is expensive both with time and resources. It should be called
69
  * only when there is a need for that.
70
  *
71
+ * @return boolean
72
  */
73
  public function actionFull()
74
  {
79
  $restCustomer->setProfile();
80
 
81
  foreach ($customerEntity->getOrders() as $orderEntity) {
82
+ $restOrder = $orderEntity->getRestOrder();
83
+ $restOrder->syncWithCustomer($customerEntity);
84
  }
85
 
86
+ foreach ($customerEntity->getWishlistItems() as $wishlistItemEntity) {
87
+ $restWishlistItem = $wishlistItemEntity->getRestWishlistItem();
88
+ $restWishlistItem->syncWithCustomer($customerEntity);
89
  }
90
 
91
  //$request->commit();
110
 
111
  $group = $store->getGroup();
112
 
113
+ $storeView = implode(
114
+ ' > ', array (
115
  $website->getName(),
116
  $group->getName(),
117
  $store->getName())
126
  $profileCache = $profileCacheCollection->getFirstItem();
127
 
128
  if (!$profileCache->isObjectNew()) {
129
+ $profileCache->delete();
130
  }
131
  }
132
 
133
  if (!property_exists($object, 'profileId')) {
134
+ return false;
135
  }
136
 
137
  Mage::helper('marketingsoftware/rest_request')->delete('/profile/'.$object->profileId);
138
 
139
  return true;
140
  }
141
+ }
app/code/community/Copernica/MarketingSoftware/Model/Queue/Event/Factory.php CHANGED
@@ -76,7 +76,7 @@ class Copernica_MarketingSoftware_Model_Queue_Event_Factory
76
  $classname = "marketingsoftware/queue_event_product_viewed".$action;
77
  break;
78
 
79
- case "Copernica_MarketingSoftware_Model_Abstraction_Wishlist":
80
  $classname = "marketingsoftware/queue_event_wishlist".$action;
81
  break;
82
  }
@@ -93,4 +93,4 @@ class Copernica_MarketingSoftware_Model_Queue_Event_Factory
93
 
94
  return new $classname($queueItem);
95
  }
96
- }
76
  $classname = "marketingsoftware/queue_event_product_viewed".$action;
77
  break;
78
 
79
+ case "Copernica_MarketingSoftware_Model_Abstraction_Wishlist":
80
  $classname = "marketingsoftware/queue_event_wishlist".$action;
81
  break;
82
  }
93
 
94
  return new $classname($queueItem);
95
  }
96
+ }
app/code/community/Copernica/MarketingSoftware/Model/Queue/Event/Item.php CHANGED
@@ -38,12 +38,12 @@ class Copernica_MarketingSoftware_Model_Queue_Event_Item extends Copernica_Marke
38
  {
39
  $object = $this->_getObject();
40
 
41
- if(!$object->quoteId || !is_numeric($object->quoteId)) {
42
- return false;
43
  }
44
 
45
  if ($object->customerId && is_numeric($object->customerId) ) {
46
- $this->syncQuote();
47
  }
48
 
49
  $collection = Mage::getModel('marketingsoftware/abandoned_cart')->getCollection()->addFieldToFilter('quote_id', $object->quoteId);
@@ -51,7 +51,7 @@ class Copernica_MarketingSoftware_Model_Queue_Event_Item extends Copernica_Marke
51
  $abandonedCart = $collection->getFirstItem();
52
 
53
  if ($abandonedCart->isObjectNew()) {
54
- return true;
55
  }
56
 
57
  $abandonedCart->delete();
@@ -87,7 +87,7 @@ class Copernica_MarketingSoftware_Model_Queue_Event_Item extends Copernica_Marke
87
  $object = $this->_getObject();
88
 
89
  if (!$object->quoteId || !is_numeric($object->quoteId) || !$object->customerId || !is_numeric($object->customerId) || !$object->quoteItem) {
90
- return false;
91
  }
92
 
93
  $quoteItemData = get_object_vars($object->quoteItem);
@@ -107,38 +107,42 @@ class Copernica_MarketingSoftware_Model_Queue_Event_Item extends Copernica_Marke
107
  $customerEntity->setStore($storeview);
108
 
109
  if (($profileId = $customerEntity->getProfileId()) === false) {
110
- return false;
111
  }
112
 
113
  $quoteItemCollectionId = Mage::helper('marketingsoftware/config')->getQuoteItemCollectionId();
114
 
115
 
116
- $response = $request->get('/profile/'.$profileId.'/subprofiles/'.$quoteItemCollectionId, array(
117
- 'item_id' => $itemId,
118
- 'quote_id' => $quoteId,
119
- ));
 
 
120
 
121
- if (!array_key_exists('data', $response) || count($response['data']) == 0) {
122
- if (!Mage::helper('marketingsoftware/config')->getRemoveFinishedQuoteItem()) {
123
- $request->post('/profile/'.$profileId.'/subprofiles/'.$quoteItemCollectionId, $quoteItemData);
124
- }
125
 
126
- return true;
127
- }
128
 
129
  if (Mage::helper('marketingsoftware/config')->getRemoveFinishedQuoteItem()) {
130
  foreach ($response['data'] as $subprofile) {
131
- $request->delete('/subprofile/'.$subprofile['ID']);
132
  }
133
  } else {
134
- $request->put('/profile/'.$profileId.'/subprofiles/'.$quoteItemCollectionId, array(
 
135
  'status' => 'deleted'
136
- ), array (
137
  'fields' => array(
138
  'quote_id=='.$quoteId,
139
  'item_id=='.$itemId
140
  )
141
- ));
 
142
  }
143
 
144
  return true;
@@ -152,27 +156,27 @@ class Copernica_MarketingSoftware_Model_Queue_Event_Item extends Copernica_Marke
152
  $object = $this->_getObject();
153
 
154
  if (!$object->customerId || !is_numeric($object->customerId)) {
155
- return false;
156
  }
157
 
158
- if($object->quoteId && is_numeric($object->quoteId)) {
159
- $quoteId = $object->quoteId;
160
  } else {
161
- $quote = Mage::getModel('sales/quote')->loadByCustomer($object->customerId);
162
- $quoteId = $quote->getId();
163
  }
164
 
165
  $quoteItem = Mage::getModel('sales/quote_item')->load($object->quoteItemId);
166
 
167
  if ($quoteId && $quoteItem->getId()) {
168
- $customerEntity = Mage::getModel('marketingsoftware/copernica_entity_customer');
169
- $customerEntity->setCustomer($object->customerId);
170
-
171
- $quoteItemEntity = Mage::getModel('marketingsoftware/copernica_entity_quote_item');
172
- $quoteItemEntity->setQuoteItem($quoteItem);
173
-
174
- $restQuoteItem = $quoteItemEntity->getRestQuoteItem();
175
- $restQuoteItem->syncWithQuote($customerEntity, $quoteId);
176
  }
177
  }
178
  }
38
  {
39
  $object = $this->_getObject();
40
 
41
+ if (!$object->quoteId || !is_numeric($object->quoteId)) {
42
+ return false;
43
  }
44
 
45
  if ($object->customerId && is_numeric($object->customerId) ) {
46
+ $this->syncQuote();
47
  }
48
 
49
  $collection = Mage::getModel('marketingsoftware/abandoned_cart')->getCollection()->addFieldToFilter('quote_id', $object->quoteId);
51
  $abandonedCart = $collection->getFirstItem();
52
 
53
  if ($abandonedCart->isObjectNew()) {
54
+ return true;
55
  }
56
 
57
  $abandonedCart->delete();
87
  $object = $this->_getObject();
88
 
89
  if (!$object->quoteId || !is_numeric($object->quoteId) || !$object->customerId || !is_numeric($object->customerId) || !$object->quoteItem) {
90
+ return false;
91
  }
92
 
93
  $quoteItemData = get_object_vars($object->quoteItem);
107
  $customerEntity->setStore($storeview);
108
 
109
  if (($profileId = $customerEntity->getProfileId()) === false) {
110
+ return false;
111
  }
112
 
113
  $quoteItemCollectionId = Mage::helper('marketingsoftware/config')->getQuoteItemCollectionId();
114
 
115
 
116
+ $response = $request->get(
117
+ '/profile/'.$profileId.'/subprofiles/'.$quoteItemCollectionId, array(
118
+ 'item_id' => $itemId,
119
+ 'quote_id' => $quoteId,
120
+ )
121
+ );
122
 
123
+ if (!array_key_exists('data', $response) || count($response['data']) == 0) {
124
+ if (!Mage::helper('marketingsoftware/config')->getRemoveFinishedQuoteItem()) {
125
+ $request->post('/profile/'.$profileId.'/subprofiles/'.$quoteItemCollectionId, $quoteItemData);
126
+ }
127
 
128
+ return true;
129
+ }
130
 
131
  if (Mage::helper('marketingsoftware/config')->getRemoveFinishedQuoteItem()) {
132
  foreach ($response['data'] as $subprofile) {
133
+ $request->delete('/subprofile/'.$subprofile['ID']);
134
  }
135
  } else {
136
+ $request->put(
137
+ '/profile/'.$profileId.'/subprofiles/'.$quoteItemCollectionId, array(
138
  'status' => 'deleted'
139
+ ), array (
140
  'fields' => array(
141
  'quote_id=='.$quoteId,
142
  'item_id=='.$itemId
143
  )
144
+ )
145
+ );
146
  }
147
 
148
  return true;
156
  $object = $this->_getObject();
157
 
158
  if (!$object->customerId || !is_numeric($object->customerId)) {
159
+ return false;
160
  }
161
 
162
+ if ($object->quoteId && is_numeric($object->quoteId)) {
163
+ $quoteId = $object->quoteId;
164
  } else {
165
+ $quote = Mage::getModel('sales/quote')->loadByCustomer($object->customerId);
166
+ $quoteId = $quote->getId();
167
  }
168
 
169
  $quoteItem = Mage::getModel('sales/quote_item')->load($object->quoteItemId);
170
 
171
  if ($quoteId && $quoteItem->getId()) {
172
+ $customerEntity = Mage::getModel('marketingsoftware/copernica_entity_customer');
173
+ $customerEntity->setCustomer($object->customerId);
174
+
175
+ $quoteItemEntity = Mage::getModel('marketingsoftware/copernica_entity_quote_item');
176
+ $quoteItemEntity->setQuoteItem($quoteItem);
177
+
178
+ $restQuoteItem = $quoteItemEntity->getRestQuoteItem();
179
+ $restQuoteItem->syncWithQuote($customerEntity, $quoteId);
180
  }
181
  }
182
  }
app/code/community/Copernica/MarketingSoftware/Model/Queue/Event/Order.php CHANGED
@@ -29,13 +29,13 @@
29
  */
30
  class Copernica_MarketingSoftware_Model_Queue_Event_Order extends Copernica_MarketingSoftware_Model_Queue_Event_Abstract
31
  {
32
- /**
33
- * Customer entity
34
- *
35
- * @var Copernica_MarketingSoftware_Model_Copernica_Entity_Customer
36
- */
37
- protected $_customerEntity;
38
-
39
  /**
40
  * This action will be run on order modify event
41
  *
@@ -52,7 +52,7 @@ class Copernica_MarketingSoftware_Model_Queue_Event_Order extends Copernica_Mark
52
 
53
  $customerEntity = $this->_getCustomerEntity();
54
 
55
- if ($customerEntity) {
56
  return $restOrder->syncWithCustomer($customerEntity);
57
  } else {
58
  $data = array (
@@ -64,23 +64,23 @@ class Copernica_MarketingSoftware_Model_Queue_Event_Order extends Copernica_Mark
64
  );
65
 
66
  if ($middlename = $vanillaOrder->getCustomerMiddlename()) {
67
- $data['middlename'] = $middlename;
68
  }
69
 
70
- if ($dateOfBirth = $vanillaOrder->getCustomerDob()) {
71
- $data['birthdate'] = date('Y-m-d H:i:s', strtotime($dateOfBirth));
72
  }
73
 
74
  if ($gender = $vanillaOrder->getCustomerGender()) {
75
- $options = Mage::getModel('customer/customer')->getAttribute('gender')->getSource()->getAllOptions();
76
-
77
- foreach ($options as $option) {
78
- if ($option['value'] == $gender) {
79
- $gender = $option['label'];
80
- }
81
- }
82
-
83
- $data['gender'] = $gender;
84
  }
85
 
86
  $group = $vanillaOrder->getCustomerGroupId();
@@ -104,8 +104,8 @@ class Copernica_MarketingSoftware_Model_Queue_Event_Order extends Copernica_Mark
104
 
105
  $customerEntity = $this->_getCustomerEntity();
106
 
107
- if(!$customerEntity) {
108
- return true;
109
  }
110
 
111
  $request = Mage::helper('marketingsoftware/rest_request');
@@ -113,24 +113,26 @@ class Copernica_MarketingSoftware_Model_Queue_Event_Order extends Copernica_Mark
113
  $quoteItemCollection = Mage::helper('marketingsoftware/config')->getQuoteItemCollectionId();
114
 
115
  if ($quoteItemCollection) {
116
- $response = $request->get('/profile/'.$customerEntity->getProfileId().'/subprofiles/'.$quoteItemCollection, array(
117
- 'fields' => array('quote_id=='.$order->getQuoteId())
118
- ));
 
 
119
  }
120
 
121
  if (array_key_exists('data', $response) || count($response['data']) == 0) {
122
- return true;
123
  }
124
 
125
  $request->prepare();
126
 
127
  if (Mage::helper('marketingsoftware/config')->getRemoveFinishedQuoteItem()) {
128
  foreach ($response['data'] as $subprofile) {
129
- $request->delete('/subprofile/'.$subprofile['ID']);
130
  }
131
  } else {
132
  foreach ($response['data'] as $subprofile) {
133
- $request->put('/subprofile/'.$subprofile['ID'].'/fields/', array('status' => 'completed'));
134
  }
135
  }
136
 
@@ -141,19 +143,19 @@ class Copernica_MarketingSoftware_Model_Queue_Event_Order extends Copernica_Mark
141
 
142
  protected function _getCustomerEntity()
143
  {
144
- if ($this->_customerEntity) {
145
- return $this->_customerEntity;
146
- } else {
147
- $object = $this->_getObject();
148
-
149
- if ($object->customerId && is_numeric($object->customerId)) {
150
- $customerEntity = Mage::getModel('marketingsoftware/copernica_entity_customer');
151
- $customerEntity->setCustomer($object->customerId);
152
-
153
- return $this->_customerEntity = $customerEntity;
154
- } else {
155
- return false;
156
- }
157
- }
158
  }
159
- }
29
  */
30
  class Copernica_MarketingSoftware_Model_Queue_Event_Order extends Copernica_MarketingSoftware_Model_Queue_Event_Abstract
31
  {
32
+ /**
33
+ * Customer entity
34
+ *
35
+ * @var Copernica_MarketingSoftware_Model_Copernica_Entity_Customer
36
+ */
37
+ protected $_customerEntity;
38
+
39
  /**
40
  * This action will be run on order modify event
41
  *
52
 
53
  $customerEntity = $this->_getCustomerEntity();
54
 
55
+ if ($customerEntity) {
56
  return $restOrder->syncWithCustomer($customerEntity);
57
  } else {
58
  $data = array (
64
  );
65
 
66
  if ($middlename = $vanillaOrder->getCustomerMiddlename()) {
67
+ $data['middlename'] = $middlename;
68
  }
69
 
70
+ if ($dateOfBirth = $vanillaOrder->getCustomerDob()) {
71
+ $data['birthdate'] = date('Y-m-d H:i:s', strtotime($dateOfBirth));
72
  }
73
 
74
  if ($gender = $vanillaOrder->getCustomerGender()) {
75
+ $options = Mage::getModel('customer/customer')->getAttribute('gender')->getSource()->getAllOptions();
76
+
77
+ foreach ($options as $option) {
78
+ if ($option['value'] == $gender) {
79
+ $gender = $option['label'];
80
+ }
81
+ }
82
+
83
+ $data['gender'] = $gender;
84
  }
85
 
86
  $group = $vanillaOrder->getCustomerGroupId();
104
 
105
  $customerEntity = $this->_getCustomerEntity();
106
 
107
+ if (!$customerEntity) {
108
+ return true;
109
  }
110
 
111
  $request = Mage::helper('marketingsoftware/rest_request');
113
  $quoteItemCollection = Mage::helper('marketingsoftware/config')->getQuoteItemCollectionId();
114
 
115
  if ($quoteItemCollection) {
116
+ $response = $request->get(
117
+ '/profile/'.$customerEntity->getProfileId().'/subprofiles/'.$quoteItemCollection, array(
118
+ 'fields' => array('quote_id=='.$order->getQuoteId())
119
+ )
120
+ );
121
  }
122
 
123
  if (array_key_exists('data', $response) || count($response['data']) == 0) {
124
+ return true;
125
  }
126
 
127
  $request->prepare();
128
 
129
  if (Mage::helper('marketingsoftware/config')->getRemoveFinishedQuoteItem()) {
130
  foreach ($response['data'] as $subprofile) {
131
+ $request->delete('/subprofile/'.$subprofile['ID']);
132
  }
133
  } else {
134
  foreach ($response['data'] as $subprofile) {
135
+ $request->put('/subprofile/'.$subprofile['ID'].'/fields/', array('status' => 'completed'));
136
  }
137
  }
138
 
143
 
144
  protected function _getCustomerEntity()
145
  {
146
+ if ($this->_customerEntity) {
147
+ return $this->_customerEntity;
148
+ } else {
149
+ $object = $this->_getObject();
150
+
151
+ if ($object->customerId && is_numeric($object->customerId)) {
152
+ $customerEntity = Mage::getModel('marketingsoftware/copernica_entity_customer');
153
+ $customerEntity->setCustomer($object->customerId);
154
+
155
+ return $this->_customerEntity = $customerEntity;
156
+ } else {
157
+ return false;
158
+ }
159
+ }
160
  }
161
+ }
app/code/community/Copernica/MarketingSoftware/Model/Queue/Event/Quote.php CHANGED
@@ -60,30 +60,34 @@ class Copernica_MarketingSoftware_Model_Queue_Event_Quote extends Copernica_Mark
60
  */
61
  public function actionRemove()
62
  {
63
- $object = $this->_getObject();
64
-
65
- if (!$object->customerId || !is_numeric($object->customerId) || !$object->storeView) {
66
- return false;
67
- }
68
-
69
  $quoteItemCollectionId = Mage::helper('marketingsoftware/config')->getQuoteItemCollectionId();
70
 
71
  $customerEntity = Mage::getModel('marketingsoftware/copernica_entity_customer');
72
  $customerEntity->setCustomer($object->customerId);
73
 
74
- $profileId = Mage::helper('marketingsoftware/api')->getProfileId(array(
 
75
  'id' => $customerEntity->fetchId(),
76
  'storeView' => $object->storeView,
77
  'email' => $customerEntity->fetchEmail()
78
- ));
 
79
 
80
  $request = Mage::helper('marketingsoftware/rest_request');
81
 
82
- $result = $request->get('/profile/'.$profileId.'/subprofiles/'.$quoteItemCollectionId, array(
 
83
  'fields' => array(
84
  'quote_id=='.$this->_getEntityId()
85
  )
86
- ));
 
87
 
88
  $request->prepare();
89
 
60
  */
61
  public function actionRemove()
62
  {
63
+ $object = $this->_getObject();
64
+
65
+ if (!$object->customerId || !is_numeric($object->customerId) || !$object->storeView) {
66
+ return false;
67
+ }
68
+
69
  $quoteItemCollectionId = Mage::helper('marketingsoftware/config')->getQuoteItemCollectionId();
70
 
71
  $customerEntity = Mage::getModel('marketingsoftware/copernica_entity_customer');
72
  $customerEntity->setCustomer($object->customerId);
73
 
74
+ $profileId = Mage::helper('marketingsoftware/api')->getProfileId(
75
+ array(
76
  'id' => $customerEntity->fetchId(),
77
  'storeView' => $object->storeView,
78
  'email' => $customerEntity->fetchEmail()
79
+ )
80
+ );
81
 
82
  $request = Mage::helper('marketingsoftware/rest_request');
83
 
84
+ $result = $request->get(
85
+ '/profile/'.$profileId.'/subprofiles/'.$quoteItemCollectionId, array(
86
  'fields' => array(
87
  'quote_id=='.$this->_getEntityId()
88
  )
89
+ )
90
+ );
91
 
92
  $request->prepare();
93
 
app/code/community/Copernica/MarketingSoftware/Model/Queue/Event/Startsync.php CHANGED
@@ -34,7 +34,7 @@ class Copernica_MarketingSoftware_Model_Queue_Event_Startsync extends Copernica_
34
  /**
35
  * How many events we want to spawn for each of customers/orders/subscriptions
36
  *
37
- * @var int
38
  */
39
  protected $_eventsLimit = 500;
40
 
@@ -43,7 +43,7 @@ class Copernica_MarketingSoftware_Model_Queue_Event_Startsync extends Copernica_
43
  * scheduled for synchronization. Also it does contain stores id that should
44
  * be used to filter entites results.
45
  *
46
- * @var Copernica_MarketingSoftware_Model_Sync_Status
47
  */
48
  protected $_currentStatus;
49
 
@@ -52,27 +52,28 @@ class Copernica_MarketingSoftware_Model_Queue_Event_Startsync extends Copernica_
52
  * event will respawn with new set of data. Note that this event will be
53
  * respawning till all entities will be scheduled to sync.
54
  *
55
- * @return boolean
56
  */
57
- public function process() {
 
58
  $this->_currentStatus = Copernica_MarketingSoftware_Model_Sync_Status::fromStd($this->_getObject());
59
 
60
  $shouldRespawn = false;
61
 
62
  if ($this->_addCustomersToQueue() == $this->_eventsLimit) {
63
- $shouldRespawn = true;
64
  }
65
 
66
  if ($this->_addOrdersToQueue() == $this->_eventsLimit) {
67
- $shouldRespawn = true;
68
  }
69
 
70
  if ($this->_addSubscriptionsToQueue() == $this->_eventsLimit) {
71
- $shouldRespawn = true;
72
  }
73
 
74
  if ($shouldRespawn) {
75
- $this->respawn();
76
  }
77
 
78
  return true;
@@ -103,7 +104,7 @@ class Copernica_MarketingSoftware_Model_Queue_Event_Startsync extends Copernica_
103
  $enabledStores = $this->_currentStatus->getStoresFilter();
104
 
105
  if (count($enabledStores) == 0) {
106
- return null;
107
  }
108
 
109
  $filterArray = array();
@@ -164,17 +165,21 @@ class Copernica_MarketingSoftware_Model_Queue_Event_Startsync extends Copernica_
164
  $addedEvents = 0;
165
 
166
  $ordersCollection = Mage::getModel('sales/order')->getCollection();
167
- $ordersCollection->addAttributeToFilter('entity_id', array (
 
168
  'gt' => $this->_currentStatus->getLastOrderId()
169
- ));
 
170
 
171
  if ($filterArray = $this->_getStoresFilter()) {
172
  $ordersCollection->addAttributeToFilter('store_id', $filterArray);
173
  }
174
 
175
- $ordersCollection->addFieldToFilter('customer_id', array(
 
176
  'null' => true
177
- ));
 
178
  $ordersCollection->addAttributeToSort('entity_id', 'ASC');
179
  $ordersCollection->setPageSize($this->_eventsLimit);
180
 
@@ -209,14 +214,18 @@ class Copernica_MarketingSoftware_Model_Queue_Event_Startsync extends Copernica_
209
  $addedEvents = 0;
210
 
211
  $subscriptionsCollection = Mage::getModel('newsletter/subscriber')->getCollection();
212
- $subscriptionsCollection->addFieldToFilter('subscriber_id', array(
 
213
  'gt' => $this->_currentStatus->getLastSubscriptionId()
214
- ));
 
215
  $subscriptionsCollection->setOrder('subscriber_id', 'ASC');
216
- $subscriptionsCollection->addFieldToFilter('customer_id', array(
 
217
  'eq' => 0,
218
  'null' => true
219
- ));
 
220
 
221
  if ($filterArray = $this->_getStoresFilter()) {
222
  $subscriptionsCollection->addFieldToFilter('store_id', $filterArray);
@@ -240,4 +249,4 @@ class Copernica_MarketingSoftware_Model_Queue_Event_Startsync extends Copernica_
240
 
241
  return $addedEvents;
242
  }
243
- }
34
  /**
35
  * How many events we want to spawn for each of customers/orders/subscriptions
36
  *
37
+ * @var int
38
  */
39
  protected $_eventsLimit = 500;
40
 
43
  * scheduled for synchronization. Also it does contain stores id that should
44
  * be used to filter entites results.
45
  *
46
+ * @var Copernica_MarketingSoftware_Model_Sync_Status
47
  */
48
  protected $_currentStatus;
49
 
52
  * event will respawn with new set of data. Note that this event will be
53
  * respawning till all entities will be scheduled to sync.
54
  *
55
+ * @return boolean
56
  */
57
+ public function process()
58
+ {
59
  $this->_currentStatus = Copernica_MarketingSoftware_Model_Sync_Status::fromStd($this->_getObject());
60
 
61
  $shouldRespawn = false;
62
 
63
  if ($this->_addCustomersToQueue() == $this->_eventsLimit) {
64
+ $shouldRespawn = true;
65
  }
66
 
67
  if ($this->_addOrdersToQueue() == $this->_eventsLimit) {
68
+ $shouldRespawn = true;
69
  }
70
 
71
  if ($this->_addSubscriptionsToQueue() == $this->_eventsLimit) {
72
+ $shouldRespawn = true;
73
  }
74
 
75
  if ($shouldRespawn) {
76
+ $this->respawn();
77
  }
78
 
79
  return true;
104
  $enabledStores = $this->_currentStatus->getStoresFilter();
105
 
106
  if (count($enabledStores) == 0) {
107
+ return null;
108
  }
109
 
110
  $filterArray = array();
165
  $addedEvents = 0;
166
 
167
  $ordersCollection = Mage::getModel('sales/order')->getCollection();
168
+ $ordersCollection->addAttributeToFilter(
169
+ 'entity_id', array (
170
  'gt' => $this->_currentStatus->getLastOrderId()
171
+ )
172
+ );
173
 
174
  if ($filterArray = $this->_getStoresFilter()) {
175
  $ordersCollection->addAttributeToFilter('store_id', $filterArray);
176
  }
177
 
178
+ $ordersCollection->addFieldToFilter(
179
+ 'customer_id', array(
180
  'null' => true
181
+ )
182
+ );
183
  $ordersCollection->addAttributeToSort('entity_id', 'ASC');
184
  $ordersCollection->setPageSize($this->_eventsLimit);
185
 
214
  $addedEvents = 0;
215
 
216
  $subscriptionsCollection = Mage::getModel('newsletter/subscriber')->getCollection();
217
+ $subscriptionsCollection->addFieldToFilter(
218
+ 'subscriber_id', array(
219
  'gt' => $this->_currentStatus->getLastSubscriptionId()
220
+ )
221
+ );
222
  $subscriptionsCollection->setOrder('subscriber_id', 'ASC');
223
+ $subscriptionsCollection->addFieldToFilter(
224
+ 'customer_id', array(
225
  'eq' => 0,
226
  'null' => true
227
+ )
228
+ );
229
 
230
  if ($filterArray = $this->_getStoresFilter()) {
231
  $subscriptionsCollection->addFieldToFilter('store_id', $filterArray);
249
 
250
  return $addedEvents;
251
  }
252
+ }
app/code/community/Copernica/MarketingSoftware/Model/Queue/Event/Subscription.php CHANGED
@@ -27,14 +27,15 @@ class Copernica_MarketingSoftware_Model_Queue_Event_Subscription extends Coperni
27
  $profileLinkedFields = Mage::helper('marketingsoftware/config')->getLinkedCustomerFields();
28
 
29
  if (!$object->email && !$object->storeId) {
30
- return false;
31
  }
32
 
33
  $store = Mage::getModel('core/store')->load($object->storeId);
34
  $website = $store->getWebsite();
35
  $group = $store->getGroup();
36
 
37
- $storeView = implode(' > ', array (
 
38
  $website->getName(),
39
  $group->getName(),
40
  $store->getName())
@@ -49,24 +50,26 @@ class Copernica_MarketingSoftware_Model_Queue_Event_Subscription extends Coperni
49
  $profileCache = $profileCacheCollection->getFirstItem();
50
 
51
  if (!$profileCache->isObjectNew()) {
52
- $profileCache->delete();
53
  }
54
 
55
  $request = Mage::helper('marketingsoftware/rest_request');
56
 
57
  $databaseId = Mage::helper('marketingsoftware/config')->getDatabaseId();
58
 
59
- $result = $request->get('/database/'.$databaseId.'/profiles', array('fields' => array(
 
60
  $profileLinkedFields['email'].'=='.$object->email,
61
  $profileLinkedFields['storeView'].'=='.$storeView
62
- )));
 
63
 
64
  if (!isset($result['total']) && $result['total'] == 0) {
65
- return false;
66
  }
67
 
68
  foreach ($result['data'] as $profile) {
69
- $request->delete('/profile/'.$profile['ID']);
70
  }
71
 
72
  return true;
@@ -82,7 +85,7 @@ class Copernica_MarketingSoftware_Model_Queue_Event_Subscription extends Coperni
82
  $subscriber = Mage::getModel('newsletter/subscriber')->load($this->_getEntityId());
83
 
84
  if ($subscriber->isObjectNew()) {
85
- return true;
86
  }
87
 
88
  $subscriptionEntity = Mage::getModel('marketingsoftware/copernica_entity_subscription');
27
  $profileLinkedFields = Mage::helper('marketingsoftware/config')->getLinkedCustomerFields();
28
 
29
  if (!$object->email && !$object->storeId) {
30
+ return false;
31
  }
32
 
33
  $store = Mage::getModel('core/store')->load($object->storeId);
34
  $website = $store->getWebsite();
35
  $group = $store->getGroup();
36
 
37
+ $storeView = implode(
38
+ ' > ', array (
39
  $website->getName(),
40
  $group->getName(),
41
  $store->getName())
50
  $profileCache = $profileCacheCollection->getFirstItem();
51
 
52
  if (!$profileCache->isObjectNew()) {
53
+ $profileCache->delete();
54
  }
55
 
56
  $request = Mage::helper('marketingsoftware/rest_request');
57
 
58
  $databaseId = Mage::helper('marketingsoftware/config')->getDatabaseId();
59
 
60
+ $result = $request->get(
61
+ '/database/'.$databaseId.'/profiles', array('fields' => array(
62
  $profileLinkedFields['email'].'=='.$object->email,
63
  $profileLinkedFields['storeView'].'=='.$storeView
64
+ ))
65
+ );
66
 
67
  if (!isset($result['total']) && $result['total'] == 0) {
68
+ return false;
69
  }
70
 
71
  foreach ($result['data'] as $profile) {
72
+ $request->delete('/profile/'.$profile['ID']);
73
  }
74
 
75
  return true;
85
  $subscriber = Mage::getModel('newsletter/subscriber')->load($this->_getEntityId());
86
 
87
  if ($subscriber->isObjectNew()) {
88
+ return true;
89
  }
90
 
91
  $subscriptionEntity = Mage::getModel('marketingsoftware/copernica_entity_subscription');
app/code/community/Copernica/MarketingSoftware/Model/Queue/Event/View.php CHANGED
@@ -36,15 +36,15 @@ class Copernica_MarketingSoftware_Model_Queue_Event_View extends Copernica_Marke
36
  */
37
  public function actionAdd()
38
  {
39
- $object = $this->_getObject();
40
-
41
- if (!$object->customerId || !is_numeric($object->customerId) || !$object->productId || !is_numeric($object->productId) || !$object->viewedAt || !is_numeric($object->viewedAt)) {
42
- return false;
43
- }
44
 
45
- $customerEntity = Mage::getModel('marketingsoftware/copernica_entity_customer');
46
- $customerEntity->setCustomer($object->customerId);
47
-
48
  $productEntity = Mage::getModel('marketingsoftware/copernica_entity_product');
49
  $productEntity->setProduct($object->productId, $object->storeId);
50
  $productEntity->setTimestamp(date('Y-m-d G:i:s', $object->viewedAt));
@@ -54,4 +54,4 @@ class Copernica_MarketingSoftware_Model_Queue_Event_View extends Copernica_Marke
54
 
55
  return true;
56
  }
57
- }
36
  */
37
  public function actionAdd()
38
  {
39
+ $object = $this->_getObject();
40
+
41
+ if (!$object->customerId || !is_numeric($object->customerId) || !$object->productId || !is_numeric($object->productId) || !$object->viewedAt || !is_numeric($object->viewedAt)) {
42
+ return false;
43
+ }
44
 
45
+ $customerEntity = Mage::getModel('marketingsoftware/copernica_entity_customer');
46
+ $customerEntity->setCustomer($object->customerId);
47
+
48
  $productEntity = Mage::getModel('marketingsoftware/copernica_entity_product');
49
  $productEntity->setProduct($object->productId, $object->storeId);
50
  $productEntity->setTimestamp(date('Y-m-d G:i:s', $object->viewedAt));
54
 
55
  return true;
56
  }
57
+ }
app/code/community/Copernica/MarketingSoftware/Model/Queue/Event/Wishlist/Item.php CHANGED
@@ -29,16 +29,16 @@
29
  */
30
  class Copernica_MarketingSoftware_Model_Queue_Event_Wishlist_Item extends Copernica_MarketingSoftware_Model_Queue_Event_Abstract
31
  {
32
- /**
33
- * Add functionality is the same as that of modify
34
- *
35
- * @return boolean
36
- */
37
- public function actionAdd()
38
- {
39
- return $this->actionModify();
40
- }
41
-
42
  /**
43
  * Handle modify action
44
  *
@@ -46,12 +46,12 @@ class Copernica_MarketingSoftware_Model_Queue_Event_Wishlist_Item extends Copern
46
  */
47
  public function actionModify()
48
  {
49
- $object = $this->_getObject();
50
-
51
- if (!$object->wishlistItemId || !is_numeric($object->wishlistItemId) || !$object->customerId || !is_numeric($object->customerId)) {
52
- return false;
53
- }
54
-
55
  $wishlistItem = Mage::getModel('wishlist/item')->load($object->wishlistItemId);
56
 
57
  $customerId = $object->customerId;
@@ -75,30 +75,34 @@ class Copernica_MarketingSoftware_Model_Queue_Event_Wishlist_Item extends Copern
75
  */
76
  public function actionRemove()
77
  {
78
- $object = $this->getObject();
79
-
80
- if (!$object->customerId || !is_numeric($object->customerId)) {
81
- return false;
82
- }
83
-
84
  $wishlistItemCollectionId = Mage::helper('marketingsoftware/config')->getWishlistItemCollectionId();
85
 
86
  $customerEntity = Mage::getModel('marketingsoftware/copernica_entity_customer');
87
  $customerEntity->setCustomer($object->customerId);
88
 
89
- $profileId = Mage::helper('marketingsoftware/api')->getProfileId(array(
 
90
  'id' => $customerEntity->fetchId(),
91
  'storeView' => $customerEntity->fetchStoreView(),
92
  'email' => $customerEntity->fetchEmail()
93
- ));
 
94
 
95
  $request = Mage::helper('marketingsoftware/rest_request');
96
 
97
- $result = $request->get('/profile/'.$profileId.'/subprofiles/'.$wishlistItemCollectionId, array(
 
98
  'fields' => array(
99
  'item_id=='.$this->_getEntityId()
100
  )
101
- ));
 
102
 
103
  $request->prepare();
104
 
29
  */
30
  class Copernica_MarketingSoftware_Model_Queue_Event_Wishlist_Item extends Copernica_MarketingSoftware_Model_Queue_Event_Abstract
31
  {
32
+ /**
33
+ * Add functionality is the same as that of modify
34
+ *
35
+ * @return boolean
36
+ */
37
+ public function actionAdd()
38
+ {
39
+ return $this->actionModify();
40
+ }
41
+
42
  /**
43
  * Handle modify action
44
  *
46
  */
47
  public function actionModify()
48
  {
49
+ $object = $this->_getObject();
50
+
51
+ if (!$object->wishlistItemId || !is_numeric($object->wishlistItemId) || !$object->customerId || !is_numeric($object->customerId)) {
52
+ return false;
53
+ }
54
+
55
  $wishlistItem = Mage::getModel('wishlist/item')->load($object->wishlistItemId);
56
 
57
  $customerId = $object->customerId;
75
  */
76
  public function actionRemove()
77
  {
78
+ $object = $this->getObject();
79
+
80
+ if (!$object->customerId || !is_numeric($object->customerId)) {
81
+ return false;
82
+ }
83
+
84
  $wishlistItemCollectionId = Mage::helper('marketingsoftware/config')->getWishlistItemCollectionId();
85
 
86
  $customerEntity = Mage::getModel('marketingsoftware/copernica_entity_customer');
87
  $customerEntity->setCustomer($object->customerId);
88
 
89
+ $profileId = Mage::helper('marketingsoftware/api')->getProfileId(
90
+ array(
91
  'id' => $customerEntity->fetchId(),
92
  'storeView' => $customerEntity->fetchStoreView(),
93
  'email' => $customerEntity->fetchEmail()
94
+ )
95
+ );
96
 
97
  $request = Mage::helper('marketingsoftware/rest_request');
98
 
99
+ $result = $request->get(
100
+ '/profile/'.$profileId.'/subprofiles/'.$wishlistItemCollectionId, array(
101
  'fields' => array(
102
  'item_id=='.$this->_getEntityId()
103
  )
104
+ )
105
+ );
106
 
107
  $request->prepare();
108
 
app/code/community/Copernica/MarketingSoftware/Model/Queue/Item.php CHANGED
@@ -60,7 +60,7 @@ class Copernica_MarketingSoftware_Model_Queue_Item extends Mage_Core_Model_Abstr
60
  $object = json_decode($data);
61
 
62
  if (!is_null($object)) {
63
- return $object;
64
  }
65
 
66
  return unserialize($this->getData('object'));
@@ -69,7 +69,7 @@ class Copernica_MarketingSoftware_Model_Queue_Item extends Mage_Core_Model_Abstr
69
  /**
70
  * Set the data to the model
71
  *
72
- * @param object $object
73
  * @return Copernica_MarketingSoftware_Model_Queue_Item
74
  */
75
  public function setObject($object = null)
@@ -90,7 +90,7 @@ class Copernica_MarketingSoftware_Model_Queue_Item extends Mage_Core_Model_Abstr
90
  /**
91
  * Set the customer that is interested in queue item
92
  *
93
- * @param int $customerId
94
  * @return Copernica_MarketingSoftware_Model_Queue_Item
95
  */
96
  public function setCustomerId($customerId)
@@ -113,7 +113,7 @@ class Copernica_MarketingSoftware_Model_Queue_Item extends Mage_Core_Model_Abstr
113
  /**
114
  * Set name of the event
115
  *
116
- * @param string $name
117
  * @return Copernica_MarketingSoftware_Model_Queue_Item
118
  */
119
  public function setName($name)
@@ -136,7 +136,7 @@ class Copernica_MarketingSoftware_Model_Queue_Item extends Mage_Core_Model_Abstr
136
  /**
137
  * Set associated entity Id
138
  *
139
- * @param int $id
140
  * @return Copernica_MarketingSoftware_Model_Queue_Item
141
  */
142
  public function setEntityId($id)
@@ -167,7 +167,7 @@ class Copernica_MarketingSoftware_Model_Queue_Item extends Mage_Core_Model_Abstr
167
  $modelName = 'marketingsoftware/queue_event_'. $this->getName();
168
 
169
  if (!class_exists(Mage::getConfig()->getModelClassName($modelName))) {
170
- return null;
171
  }
172
 
173
  $event = Mage::getModel($modelName);
@@ -191,14 +191,14 @@ class Copernica_MarketingSoftware_Model_Queue_Item extends Mage_Core_Model_Abstr
191
  $this->setQueueTime(date("Y-m-d H:i:s"));
192
 
193
  if ($this->getAction() == 'remove') {
194
- $this->_clearNoRemoveSiblings();
195
  }
196
 
197
  if ($this->getAction() == 'add' || $this->getAction() == 'modify') {
198
  if ($this->_shouldSave()) {
199
- parent::save();
200
  } else {
201
- return $this;
202
  }
203
  }
204
 
@@ -217,7 +217,7 @@ class Copernica_MarketingSoftware_Model_Queue_Item extends Mage_Core_Model_Abstr
217
  ->addFilter('entity_id', $this->getEntityId());
218
 
219
  foreach ($collection as $event) {
220
- $event->delete();
221
  }
222
 
223
  $collection = $this->getCollection()
@@ -227,7 +227,7 @@ class Copernica_MarketingSoftware_Model_Queue_Item extends Mage_Core_Model_Abstr
227
  ->addFilter('entity_id', $this->getEntityId());
228
 
229
  foreach ($collection as $event) {
230
- $event->delete();
231
  }
232
  }
233
 
60
  $object = json_decode($data);
61
 
62
  if (!is_null($object)) {
63
+ return $object;
64
  }
65
 
66
  return unserialize($this->getData('object'));
69
  /**
70
  * Set the data to the model
71
  *
72
+ * @param object $object
73
  * @return Copernica_MarketingSoftware_Model_Queue_Item
74
  */
75
  public function setObject($object = null)
90
  /**
91
  * Set the customer that is interested in queue item
92
  *
93
+ * @param int $customerId
94
  * @return Copernica_MarketingSoftware_Model_Queue_Item
95
  */
96
  public function setCustomerId($customerId)
113
  /**
114
  * Set name of the event
115
  *
116
+ * @param string $name
117
  * @return Copernica_MarketingSoftware_Model_Queue_Item
118
  */
119
  public function setName($name)
136
  /**
137
  * Set associated entity Id
138
  *
139
+ * @param int $id
140
  * @return Copernica_MarketingSoftware_Model_Queue_Item
141
  */
142
  public function setEntityId($id)
167
  $modelName = 'marketingsoftware/queue_event_'. $this->getName();
168
 
169
  if (!class_exists(Mage::getConfig()->getModelClassName($modelName))) {
170
+ return null;
171
  }
172
 
173
  $event = Mage::getModel($modelName);
191
  $this->setQueueTime(date("Y-m-d H:i:s"));
192
 
193
  if ($this->getAction() == 'remove') {
194
+ $this->_clearNoRemoveSiblings();
195
  }
196
 
197
  if ($this->getAction() == 'add' || $this->getAction() == 'modify') {
198
  if ($this->_shouldSave()) {
199
+ parent::save();
200
  } else {
201
+ return $this;
202
  }
203
  }
204
 
217
  ->addFilter('entity_id', $this->getEntityId());
218
 
219
  foreach ($collection as $event) {
220
+ $event->delete();
221
  }
222
 
223
  $collection = $this->getCollection()
227
  ->addFilter('entity_id', $this->getEntityId());
228
 
229
  foreach ($collection as $event) {
230
+ $event->delete();
231
  }
232
  }
233
 
app/code/community/Copernica/MarketingSoftware/Model/Queue/Processor.php CHANGED
@@ -32,7 +32,7 @@ class Copernica_MarketingSoftware_Model_Queue_Processor
32
  /**
33
  * Number of processed tasks by this processor
34
  *
35
- * @var int
36
  */
37
  protected $_processedTasks = 0;
38
 
@@ -44,21 +44,21 @@ class Copernica_MarketingSoftware_Model_Queue_Processor
44
  /**
45
  * How many items we want to process in one run?
46
  *
47
- * @var int
48
  */
49
  protected $_itemsLimit = 10000000;
50
 
51
  /**
52
  * For what is our timelimit for queue processing? in seconds.
53
  *
54
- * @var int
55
  */
56
  protected $_timeLimit = 3075840000;
57
 
58
  /**
59
  * Currently locked customer
60
  *
61
- * @var int
62
  */
63
  protected $_currentCustomer = null;
64
 
@@ -72,11 +72,11 @@ class Copernica_MarketingSoftware_Model_Queue_Processor
72
  $config = Mage::helper('marketingsoftware/config');
73
 
74
  if ($itemsLimit = $config->getItemsPerRun()) {
75
- $this->_itemsLimit = $itemsLimit;
76
  }
77
 
78
  if ($timeLimit = $config->getTimePerRun()) {
79
- $this->_timeLimit = $timeLimit;
80
  }
81
 
82
  $config = Mage::helper('marketingsoftware/config');
@@ -108,21 +108,21 @@ class Copernica_MarketingSoftware_Model_Queue_Processor
108
  /**
109
  * Process queue with lock
110
  *
111
- * @param string $lock
112
  */
113
  public function processWithLocking($lock)
114
  {
115
  if (is_numeric($lock)) {
116
- $this->processQueue($this->_currentCustomer);
117
  } elseif (is_null($lock)) {
118
- $this->processQueue(null);
119
  }
120
  }
121
 
122
  /**
123
  * Process queue
124
  *
125
- * @param string $customerId
126
  */
127
  public function processQueue($customerId = -1)
128
  {
@@ -134,16 +134,16 @@ class Copernica_MarketingSoftware_Model_Queue_Processor
134
  ->addDefaultOrder()->setPageSize($this->_itemsLimit < 150 ? 150 : $this->_itemsLimit);
135
 
136
  if (is_null($customerId)) {
137
- $queue->addFieldToFilter('customer', array('null' => true));
138
  } elseif ($customerId > -1) {
139
- $queue->addFilter('customer', $customerId);
140
  }
141
 
142
  $this->_prepareProcessor();
143
 
144
  foreach ($queue as $item) {
145
  if ($this->_isLimitsReached()) {
146
- break;
147
  }
148
 
149
  $this->_processItem($item);
@@ -173,15 +173,15 @@ class Copernica_MarketingSoftware_Model_Queue_Processor
173
  /**
174
  * Process queue item
175
  *
176
- * @param Copernica_MarketingSoftware_Model_Queue_Item $item
177
  */
178
  protected function _processItem(Copernica_MarketingSoftware_Model_Queue_Item $item)
179
  {
180
  try {
181
  if ($item->process()) {
182
- $item->delete();
183
  } else {
184
- $this->_transferItemToErrorQueue($item);
185
  }
186
 
187
  $this->_processedTasks++;
@@ -199,7 +199,7 @@ class Copernica_MarketingSoftware_Model_Queue_Processor
199
  /**
200
  * Transfer queue item to error queue.
201
  *
202
- * @param Copernica_MarketingSoftware_Model_Queue_Item $item
203
  */
204
  protected function _transferItemToErrorQueue(Copernica_MarketingSoftware_Model_Queue_Item $item)
205
  {
@@ -212,7 +212,7 @@ class Copernica_MarketingSoftware_Model_Queue_Processor
212
  /**
213
  * Fetch data about current run.
214
  *
215
- * @param string $type
216
  */
217
  public function fetchReport($type)
218
  {
@@ -240,4 +240,4 @@ class Copernica_MarketingSoftware_Model_Queue_Processor
240
  return $report;
241
  }
242
  }
243
- }
32
  /**
33
  * Number of processed tasks by this processor
34
  *
35
+ * @var int
36
  */
37
  protected $_processedTasks = 0;
38
 
44
  /**
45
  * How many items we want to process in one run?
46
  *
47
+ * @var int
48
  */
49
  protected $_itemsLimit = 10000000;
50
 
51
  /**
52
  * For what is our timelimit for queue processing? in seconds.
53
  *
54
+ * @var int
55
  */
56
  protected $_timeLimit = 3075840000;
57
 
58
  /**
59
  * Currently locked customer
60
  *
61
+ * @var int
62
  */
63
  protected $_currentCustomer = null;
64
 
72
  $config = Mage::helper('marketingsoftware/config');
73
 
74
  if ($itemsLimit = $config->getItemsPerRun()) {
75
+ $this->_itemsLimit = $itemsLimit;
76
  }
77
 
78
  if ($timeLimit = $config->getTimePerRun()) {
79
+ $this->_timeLimit = $timeLimit;
80
  }
81
 
82
  $config = Mage::helper('marketingsoftware/config');
108
  /**
109
  * Process queue with lock
110
  *
111
+ * @param string $lock
112
  */
113
  public function processWithLocking($lock)
114
  {
115
  if (is_numeric($lock)) {
116
+ $this->processQueue($this->_currentCustomer);
117
  } elseif (is_null($lock)) {
118
+ $this->processQueue(null);
119
  }
120
  }
121
 
122
  /**
123
  * Process queue
124
  *
125
+ * @param string $customerId
126
  */
127
  public function processQueue($customerId = -1)
128
  {
134
  ->addDefaultOrder()->setPageSize($this->_itemsLimit < 150 ? 150 : $this->_itemsLimit);
135
 
136
  if (is_null($customerId)) {
137
+ $queue->addFieldToFilter('customer', array('null' => true));
138
  } elseif ($customerId > -1) {
139
+ $queue->addFilter('customer', $customerId);
140
  }
141
 
142
  $this->_prepareProcessor();
143
 
144
  foreach ($queue as $item) {
145
  if ($this->_isLimitsReached()) {
146
+ break;
147
  }
148
 
149
  $this->_processItem($item);
173
  /**
174
  * Process queue item
175
  *
176
+ * @param Copernica_MarketingSoftware_Model_Queue_Item $item
177
  */
178
  protected function _processItem(Copernica_MarketingSoftware_Model_Queue_Item $item)
179
  {
180
  try {
181
  if ($item->process()) {
182
+ $item->delete();
183
  } else {
184
+ $this->_transferItemToErrorQueue($item);
185
  }
186
 
187
  $this->_processedTasks++;
199
  /**
200
  * Transfer queue item to error queue.
201
  *
202
+ * @param Copernica_MarketingSoftware_Model_Queue_Item $item
203
  */
204
  protected function _transferItemToErrorQueue(Copernica_MarketingSoftware_Model_Queue_Item $item)
205
  {
212
  /**
213
  * Fetch data about current run.
214
  *
215
+ * @param string $type
216
  */
217
  public function fetchReport($type)
218
  {
240
  return $report;
241
  }
242
  }
243
+ }
app/code/community/Copernica/MarketingSoftware/Model/Rest.php CHANGED
@@ -30,12 +30,13 @@
30
  * API.
31
  */
32
  abstract class Copernica_MarketingSoftware_Model_Rest
33
- {
 
34
  /**
35
  * Get request data that will can be passed to REST request
36
  *
37
- * @param Copernica_MarketingSoftware_Model_Copernica_Entity $entity
38
- * @param array $syncedFields
39
  * @return array
40
  */
41
  protected function _getRequestData(Copernica_MarketingSoftware_Model_Copernica_Entity $entity, $syncedFields)
@@ -44,7 +45,7 @@ abstract class Copernica_MarketingSoftware_Model_Rest
44
 
45
  foreach ($syncedFields as $fieldType => $copernicaField) {
46
  if (empty($copernicaField)) {
47
- continue;
48
  }
49
 
50
  $getMethod = 'get'.ucfirst($fieldType);
@@ -59,13 +60,12 @@ abstract class Copernica_MarketingSoftware_Model_Rest
59
  * Create profile. Parameter can be supplied as customer entity or array data.
60
  * Array data should correspond to supported customer fields.
61
  *
62
- * @param array|Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $data
63
  * @return int|false
64
  */
65
  protected function _createProfile($data)
66
- {
67
- if ($data instanceof Copernica_MarketingSoftware_Model_Copernica_Entity_Customer)
68
- {
69
  $id = $data->getCustomerId();
70
  $email = $data->getEmail();
71
  $storeView = (string) $data->getStoreView();
@@ -75,27 +75,29 @@ abstract class Copernica_MarketingSoftware_Model_Rest
75
  $restCustomer->setProfile();
76
  } else {
77
  if (!is_array($data) && !isset($data['storeviewId'])) {
78
- return;
79
  }
80
 
81
  $profileData = array();
82
 
83
  if (isset($data['id'])) {
84
- $profileData['customer_id'] = $data['id'].'|'.$data['storeViewId'];
85
  } else if (isset($data['email'])) {
86
- $profileData['customer_id'] = $data['email'].'|'.$data['storeViewId'];
87
  } else {
88
- return false;
89
  }
90
 
91
  if (!isset($data['storeView'])) {
92
  $store = Mage::getModel('core/store')->load($data['storeViewId']);
93
 
94
- $data['storeView'] = implode(' > ', array(
 
95
  $store->getWebsite()->getName(),
96
  $store->getGroup()->getName(),
97
  $store->getName(),
98
- ));
 
99
  }
100
 
101
  $id = $data['id'];
@@ -106,7 +108,7 @@ abstract class Copernica_MarketingSoftware_Model_Rest
106
 
107
  foreach ($customerLinking as $magentoField => $copernicaField) {
108
  if (empty($copernicaField) || is_null($data[$magentoField])) {
109
- continue;
110
  }
111
 
112
  $profileData[$copernicaField] = $data[$magentoField];
@@ -117,10 +119,12 @@ abstract class Copernica_MarketingSoftware_Model_Rest
117
  Mage::helper('marketingsoftware/rest_request')->post('/database/'.$databaseId.'/profiles', $profileData);
118
  }
119
 
120
- return Mage::helper('marketingsoftware/api')->getProfileId(array(
 
121
  'id' => $id,
122
  'storeView' => $storeView,
123
  'email' => $email,
124
- ));
 
125
  }
126
- }
30
  * API.
31
  */
32
  abstract class Copernica_MarketingSoftware_Model_Rest
33
+ {
34
+
35
  /**
36
  * Get request data that will can be passed to REST request
37
  *
38
+ * @param Copernica_MarketingSoftware_Model_Copernica_Entity $entity
39
+ * @param array $syncedFields
40
  * @return array
41
  */
42
  protected function _getRequestData(Copernica_MarketingSoftware_Model_Copernica_Entity $entity, $syncedFields)
45
 
46
  foreach ($syncedFields as $fieldType => $copernicaField) {
47
  if (empty($copernicaField)) {
48
+ continue;
49
  }
50
 
51
  $getMethod = 'get'.ucfirst($fieldType);
60
  * Create profile. Parameter can be supplied as customer entity or array data.
61
  * Array data should correspond to supported customer fields.
62
  *
63
+ * @param array|Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $data
64
  * @return int|false
65
  */
66
  protected function _createProfile($data)
67
+ {
68
+ if ($data instanceof Copernica_MarketingSoftware_Model_Copernica_Entity_Customer) {
 
69
  $id = $data->getCustomerId();
70
  $email = $data->getEmail();
71
  $storeView = (string) $data->getStoreView();
75
  $restCustomer->setProfile();
76
  } else {
77
  if (!is_array($data) && !isset($data['storeviewId'])) {
78
+ return;
79
  }
80
 
81
  $profileData = array();
82
 
83
  if (isset($data['id'])) {
84
+ $profileData['customer_id'] = $data['id'].'|'.$data['storeViewId'];
85
  } else if (isset($data['email'])) {
86
+ $profileData['customer_id'] = $data['email'].'|'.$data['storeViewId'];
87
  } else {
88
+ return false;
89
  }
90
 
91
  if (!isset($data['storeView'])) {
92
  $store = Mage::getModel('core/store')->load($data['storeViewId']);
93
 
94
+ $data['storeView'] = implode(
95
+ ' > ', array(
96
  $store->getWebsite()->getName(),
97
  $store->getGroup()->getName(),
98
  $store->getName(),
99
+ )
100
+ );
101
  }
102
 
103
  $id = $data['id'];
108
 
109
  foreach ($customerLinking as $magentoField => $copernicaField) {
110
  if (empty($copernicaField) || is_null($data[$magentoField])) {
111
+ continue;
112
  }
113
 
114
  $profileData[$copernicaField] = $data[$magentoField];
119
  Mage::helper('marketingsoftware/rest_request')->post('/database/'.$databaseId.'/profiles', $profileData);
120
  }
121
 
122
+ return Mage::helper('marketingsoftware/api')->getProfileId(
123
+ array(
124
  'id' => $id,
125
  'storeView' => $storeView,
126
  'email' => $email,
127
+ )
128
+ );
129
  }
130
+ }
app/code/community/Copernica/MarketingSoftware/Model/Rest/Address.php CHANGED
@@ -32,34 +32,36 @@ class Copernica_MarketingSoftware_Model_Rest_Address extends Copernica_Marketing
32
  /**
33
  * Cached address entity
34
  *
35
- * @var Copernica_MarketingSoftware_Model_Copernica_Entity_Address
36
  */
37
  protected $_addressEntity;
38
 
39
  /**
40
  * Bind address to customer
41
  *
42
- * @param Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer
43
  * @return boolean
44
  */
45
  public function bindToCustomer(Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer)
46
- {
47
- $customer->setStore($customer->getStoreview());
48
-
49
- $profileId = Mage::helper('marketingsoftware/api')->getProfileId(array(
50
- 'id' => $customer->getCustomerId(),
51
- 'storeView' => (string) $customer->getStoreView(),
52
- 'email' => $customer->getEmail(),
53
- ));
54
-
55
- if (!$profileId) {
56
- $profileId = $this->_createProfile($customer);
57
-
58
- if(!$profileId) {
59
- return false;
60
- }
61
- }
62
-
 
 
63
  $this->syncWithProfile($profileId);
64
 
65
  return true;
@@ -68,7 +70,7 @@ class Copernica_MarketingSoftware_Model_Rest_Address extends Copernica_Marketing
68
  /**
69
  * Sync address data with certain profile
70
  *
71
- * @param int $profileId
72
  * @return bool
73
  */
74
  public function syncWithProfile($profileId)
@@ -76,14 +78,16 @@ class Copernica_MarketingSoftware_Model_Rest_Address extends Copernica_Marketing
76
  $addressCollectionId = Mage::helper('marketingsoftware/config')->getAddressesCollectionId();
77
 
78
  if ($addressCollectionId) {
79
- Mage::helper('marketingsoftware/rest_request')->put('/profile/'.$profileId.'/subprofiles/'.$addressCollectionId, $this->_getSubprofileData(), array(
80
- 'fields[]' => 'address_id=='.$this->_addressEntity->getId(),
81
- 'create' => 'true'
82
- ));
 
 
83
 
84
  return true;
85
  } else {
86
- return false;
87
  }
88
  }
89
 
@@ -104,10 +108,10 @@ class Copernica_MarketingSoftware_Model_Rest_Address extends Copernica_Marketing
104
 
105
  /**
106
  * Set REST address entity
107
- * @param Copernica_MarketingSoftware_Model_Copernica_Entity_Address $address
108
  */
109
  public function setAddressEntity(Copernica_MarketingSoftware_Model_Copernica_Entity_Address $address)
110
  {
111
- $this->_addressEntity = $address;
112
  }
113
- }
32
  /**
33
  * Cached address entity
34
  *
35
+ * @var Copernica_MarketingSoftware_Model_Copernica_Entity_Address
36
  */
37
  protected $_addressEntity;
38
 
39
  /**
40
  * Bind address to customer
41
  *
42
+ * @param Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer
43
  * @return boolean
44
  */
45
  public function bindToCustomer(Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer)
46
+ {
47
+ $customer->setStore($customer->getStoreview());
48
+
49
+ $profileId = Mage::helper('marketingsoftware/api')->getProfileId(
50
+ array(
51
+ 'id' => $customer->getCustomerId(),
52
+ 'storeView' => (string) $customer->getStoreView(),
53
+ 'email' => $customer->getEmail(),
54
+ )
55
+ );
56
+
57
+ if (!$profileId) {
58
+ $profileId = $this->_createProfile($customer);
59
+
60
+ if (!$profileId) {
61
+ return false;
62
+ }
63
+ }
64
+
65
  $this->syncWithProfile($profileId);
66
 
67
  return true;
70
  /**
71
  * Sync address data with certain profile
72
  *
73
+ * @param int $profileId
74
  * @return bool
75
  */
76
  public function syncWithProfile($profileId)
78
  $addressCollectionId = Mage::helper('marketingsoftware/config')->getAddressesCollectionId();
79
 
80
  if ($addressCollectionId) {
81
+ Mage::helper('marketingsoftware/rest_request')->put(
82
+ '/profile/'.$profileId.'/subprofiles/'.$addressCollectionId, $this->_getSubprofileData(), array(
83
+ 'fields[]' => 'address_id=='.$this->_addressEntity->getId(),
84
+ 'create' => 'true'
85
+ )
86
+ );
87
 
88
  return true;
89
  } else {
90
+ return false;
91
  }
92
  }
93
 
108
 
109
  /**
110
  * Set REST address entity
111
+ * @param Copernica_MarketingSoftware_Model_Copernica_Entity_Address $address
112
  */
113
  public function setAddressEntity(Copernica_MarketingSoftware_Model_Copernica_Entity_Address $address)
114
  {
115
+ $this->_addressEntity = $address;
116
  }
117
+ }
app/code/community/Copernica/MarketingSoftware/Model/Rest/Customer.php CHANGED
@@ -32,7 +32,7 @@ class Copernica_MarketingSoftware_Model_Rest_Customer extends Copernica_Marketin
32
  /**
33
  * Customer that will be used to send data
34
  *
35
- * @var Copernica_MarketingSoftware_Model_Copernica_Entity_Customer
36
  */
37
  protected $_customerEntity;
38
 
@@ -42,7 +42,7 @@ class Copernica_MarketingSoftware_Model_Rest_Customer extends Copernica_Marketin
42
  * @return bool
43
  */
44
  public function setProfile()
45
- {
46
  $profileId = $this->_customerEntity->getProfileId();
47
 
48
  $profileData = $this->_getProfileData();
@@ -61,10 +61,11 @@ class Copernica_MarketingSoftware_Model_Rest_Customer extends Copernica_Marketin
61
  /**
62
  * Set REST customer entity
63
  *
64
- * @param Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer
65
  */
66
- public function setCustomerEntity(Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customerEntity) {
67
- $this->_customerEntity = $customerEntity;
 
68
  }
69
 
70
  /**
32
  /**
33
  * Customer that will be used to send data
34
  *
35
+ * @var Copernica_MarketingSoftware_Model_Copernica_Entity_Customer
36
  */
37
  protected $_customerEntity;
38
 
42
  * @return bool
43
  */
44
  public function setProfile()
45
+ {
46
  $profileId = $this->_customerEntity->getProfileId();
47
 
48
  $profileData = $this->_getProfileData();
61
  /**
62
  * Set REST customer entity
63
  *
64
+ * @param Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer
65
  */
66
+ public function setCustomerEntity(Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customerEntity)
67
+ {
68
+ $this->_customerEntity = $customerEntity;
69
  }
70
 
71
  /**
app/code/community/Copernica/MarketingSoftware/Model/Rest/Order.php CHANGED
@@ -32,7 +32,7 @@ class Copernica_MarketingSoftware_Model_Rest_Order extends Copernica_MarketingSo
32
  /**
33
  * Cached order entity
34
  *
35
- * @var Copernica_MarketingSoftware_Model_Copernica_Entity_Order
36
  */
37
  protected $_orderEntity = null;
38
 
@@ -44,19 +44,21 @@ class Copernica_MarketingSoftware_Model_Rest_Order extends Copernica_MarketingSo
44
  public function syncWithCustomer(Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer)
45
  {
46
  $customer->setStore($this->_orderEntity->getStoreView());
47
-
48
- $profileId = Mage::helper('marketingsoftware/api')->getProfileId(array(
 
49
  'id' => $customer->getCustomerId(),
50
  'storeView' => (string) $customer->getStoreView(),
51
  'email' => $customer->getEmail(),
52
- ));
 
53
 
54
  if (!$profileId) {
55
- $profileId = $this->_createProfile($customer);
56
-
57
- if(!$profileId) {
58
- return false;
59
- }
60
  }
61
 
62
  $this->syncWithProfile($profileId);
@@ -67,15 +69,17 @@ class Copernica_MarketingSoftware_Model_Rest_Order extends Copernica_MarketingSo
67
  /**
68
  * Sync with guest data.
69
  *
70
- * @param array $guestData
71
  * @return bool
72
  */
73
  public function syncWithGuest($guestData)
74
- {
75
- $profileId = Mage::helper('marketingsoftware/api')->getProfileId(array(
 
76
  'storeView' => $guestData['storeView'],
77
  'email' => $guestData['email'],
78
- ));
 
79
 
80
  if ($profileId) {
81
  $data = array();
@@ -86,8 +90,8 @@ class Copernica_MarketingSoftware_Model_Rest_Order extends Copernica_MarketingSo
86
  } else {
87
  $profileId = $this->_createProfile($guestData);
88
 
89
- if ($profileId == false) {
90
- return false;
91
  }
92
  }
93
 
@@ -99,36 +103,38 @@ class Copernica_MarketingSoftware_Model_Rest_Order extends Copernica_MarketingSo
99
  /**
100
  * Sync order with certain profile
101
  *
102
- * @param int $profileId
103
  */
104
  public function syncWithProfile($profileId)
105
- {
106
  $collectionId = Mage::helper('marketingsoftware/config')->getOrdersCollectionId();
107
 
108
- if ($collectionId) Mage::helper('marketingsoftware/rest_request')->put('/profile/'.$profileId.'/subprofiles/'.$collectionId, $this->_getSubprofileData(), array(
 
109
  'fields' => array(
110
  'order_id=='.$this->_orderEntity->getId(),
111
  'quote_id=='.$this->_orderEntity->getQuoteId()
112
  ),
113
  'create' => 'true'
114
- ));
 
115
 
116
  $shippingAddress = $this->_orderEntity->getShippingAddress();
117
  $billingAddress = $this->_orderEntity->getBillingAddress();
118
 
119
  if ($shippingAddress) {
120
- $restAddress = $shippingAddress->getRestAddress();
121
- $restAddress->syncWithProfile($profileId);
122
  }
123
 
124
  if ($billingAddress) {
125
- $restAddress = $billingAddress->getRestAddress();
126
- $restAddress->syncWithProfile($profileId);
127
  }
128
 
129
  foreach ($this->_orderEntity->getItems() as $orderItemEntity) {
130
- $restOrderItem = $orderItemEntity->getRestOrderItem();
131
- $restOrderItem->syncWithProfile($profileId, $this->_orderEntity);
132
  }
133
  }
134
 
@@ -149,10 +155,10 @@ class Copernica_MarketingSoftware_Model_Rest_Order extends Copernica_MarketingSo
149
  /**
150
  * Set REST order entity
151
  *
152
- * @param Copernica_MarketingSoftware_Model_Copernica_Entity_Order $orderEntity
153
  */
154
  public function setOrderEntity(Copernica_MarketingSoftware_Model_Copernica_Entity_Order $orderEntity)
155
  {
156
- $this->_orderEntity = $orderEntity;
157
  }
158
- }
32
  /**
33
  * Cached order entity
34
  *
35
+ * @var Copernica_MarketingSoftware_Model_Copernica_Entity_Order
36
  */
37
  protected $_orderEntity = null;
38
 
44
  public function syncWithCustomer(Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer)
45
  {
46
  $customer->setStore($this->_orderEntity->getStoreView());
47
+
48
+ $profileId = Mage::helper('marketingsoftware/api')->getProfileId(
49
+ array(
50
  'id' => $customer->getCustomerId(),
51
  'storeView' => (string) $customer->getStoreView(),
52
  'email' => $customer->getEmail(),
53
+ )
54
+ );
55
 
56
  if (!$profileId) {
57
+ $profileId = $this->_createProfile($customer);
58
+
59
+ if (!$profileId) {
60
+ return false;
61
+ }
62
  }
63
 
64
  $this->syncWithProfile($profileId);
69
  /**
70
  * Sync with guest data.
71
  *
72
+ * @param array $guestData
73
  * @return bool
74
  */
75
  public function syncWithGuest($guestData)
76
+ {
77
+ $profileId = Mage::helper('marketingsoftware/api')->getProfileId(
78
+ array(
79
  'storeView' => $guestData['storeView'],
80
  'email' => $guestData['email'],
81
+ )
82
+ );
83
 
84
  if ($profileId) {
85
  $data = array();
90
  } else {
91
  $profileId = $this->_createProfile($guestData);
92
 
93
+ if ($profileId == false) {
94
+ return false;
95
  }
96
  }
97
 
103
  /**
104
  * Sync order with certain profile
105
  *
106
+ * @param int $profileId
107
  */
108
  public function syncWithProfile($profileId)
109
+ {
110
  $collectionId = Mage::helper('marketingsoftware/config')->getOrdersCollectionId();
111
 
112
+ if ($collectionId) Mage::helper('marketingsoftware/rest_request')->put(
113
+ '/profile/'.$profileId.'/subprofiles/'.$collectionId, $this->_getSubprofileData(), array(
114
  'fields' => array(
115
  'order_id=='.$this->_orderEntity->getId(),
116
  'quote_id=='.$this->_orderEntity->getQuoteId()
117
  ),
118
  'create' => 'true'
119
+ )
120
+ );
121
 
122
  $shippingAddress = $this->_orderEntity->getShippingAddress();
123
  $billingAddress = $this->_orderEntity->getBillingAddress();
124
 
125
  if ($shippingAddress) {
126
+ $restAddress = $shippingAddress->getRestAddress();
127
+ $restAddress->syncWithProfile($profileId);
128
  }
129
 
130
  if ($billingAddress) {
131
+ $restAddress = $billingAddress->getRestAddress();
132
+ $restAddress->syncWithProfile($profileId);
133
  }
134
 
135
  foreach ($this->_orderEntity->getItems() as $orderItemEntity) {
136
+ $restOrderItem = $orderItemEntity->getRestOrderItem();
137
+ $restOrderItem->syncWithProfile($profileId, $this->_orderEntity);
138
  }
139
  }
140
 
155
  /**
156
  * Set REST order entity
157
  *
158
+ * @param Copernica_MarketingSoftware_Model_Copernica_Entity_Order $orderEntity
159
  */
160
  public function setOrderEntity(Copernica_MarketingSoftware_Model_Copernica_Entity_Order $orderEntity)
161
  {
162
+ $this->_orderEntity = $orderEntity;
163
  }
164
+ }
app/code/community/Copernica/MarketingSoftware/Model/Rest/Order/Item.php CHANGED
@@ -32,33 +32,35 @@ class Copernica_MarketingSoftware_Model_Rest_Order_Item extends Copernica_Market
32
  /**
33
  * Item that we want to use
34
  *
35
- * @var Copernica_MarketingSoftware_Model_Copernica_Entity_Order_Item
36
  */
37
  protected $_orderItemEntity = null;
38
 
39
  /**
40
  * Sync item with customer
41
  *
42
- * @param Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer
43
- * @param Copernica_MarketingSoftware_Model_Copernica_Entity_Order $order
44
  * @return boolean
45
  */
46
  public function syncWithCustomer(Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer, Copernica_MarketingSoftware_Model_Copernica_Entity_Order $order)
47
  {
48
- $customer->setStore($this->_orderItemEntity->getStoreView());
49
-
50
- $profileId = Mage::helper('marketingsoftware/api')->getProfileId(array(
 
51
  'id' => $customer->getCustomerId(),
52
  'storeView' => (string) $customer->getStoreView(),
53
  'email' => $customer->getEmail(),
54
- ));
 
55
 
56
- if (!$profileId) {
57
- $profileId = $this->_createProfile($customer);
58
-
59
- if(!$profileId) {
60
- return false;
61
- }
62
  }
63
 
64
  $this->syncWithProfile($profileId);
@@ -69,8 +71,8 @@ class Copernica_MarketingSoftware_Model_Rest_Order_Item extends Copernica_Market
69
  /**
70
  * Sync order items with certain profile
71
  *
72
- * @param int $profileId
73
- * @param Copernica_MarketingSoftware_Model_Copernica_Entity_Order $order
74
  * @return bool
75
  */
76
  public function syncWithProfile($profileId, Copernica_MarketingSoftware_Model_Copernica_Entity_Order $order)
@@ -78,17 +80,19 @@ class Copernica_MarketingSoftware_Model_Rest_Order_Item extends Copernica_Market
78
  $itemCollectionId = Mage::helper('marketingsoftware/config')->getOrderItemCollectionId();
79
 
80
  if ($itemCollectionId) {
81
- Mage::helper('marketingsoftware/rest_request')->put('/profile/'.$profileId.'/subprofiles/'.$itemCollectionId, $this->_getSubprofileData($order), array(
82
- 'fields' => array (
83
- 'item_id=='.$this->_orderItemEntity->getId(),
 
84
  'order_id=='.$order->getId()
85
  ),
86
  'create' => 'true'
87
- ));
 
88
 
89
  return true;
90
  } else {
91
- return false;
92
  }
93
 
94
  }
@@ -96,8 +100,8 @@ class Copernica_MarketingSoftware_Model_Rest_Order_Item extends Copernica_Market
96
  /**
97
  * Prepare subprofile data
98
  *
99
- * @param Copernica_MarketingSoftware_Model_Copernica_Entity_Order $order
100
- * @return array
101
  */
102
  protected function _getSubprofileData(Copernica_MarketingSoftware_Model_Copernica_Entity_Order $order)
103
  {
@@ -106,7 +110,7 @@ class Copernica_MarketingSoftware_Model_Rest_Order_Item extends Copernica_Market
106
  $data = $this->_getRequestData($this->_orderItemEntity, $syncedFields);
107
 
108
  if (!empty($syncedFields['incrementId'])) {
109
- $data['incrementId'] = $order->getIncrementId();
110
  }
111
 
112
  $data['item_id'] = $this->_orderItemEntity->getId();
@@ -117,10 +121,10 @@ class Copernica_MarketingSoftware_Model_Rest_Order_Item extends Copernica_Market
117
 
118
  /**
119
  * Set REST order item entity
120
- * @param Copernica_MarketingSoftware_Model_Copernica_Entity_Order_Item $orderItem
121
  */
122
  public function setOrderItemEntity(Copernica_MarketingSoftware_Model_Copernica_Entity_Order_Item $orderItem)
123
  {
124
- $this->_orderItemEntity = $orderItem;
125
  }
126
  }
32
  /**
33
  * Item that we want to use
34
  *
35
+ * @var Copernica_MarketingSoftware_Model_Copernica_Entity_Order_Item
36
  */
37
  protected $_orderItemEntity = null;
38
 
39
  /**
40
  * Sync item with customer
41
  *
42
+ * @param Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer
43
+ * @param Copernica_MarketingSoftware_Model_Copernica_Entity_Order $order
44
  * @return boolean
45
  */
46
  public function syncWithCustomer(Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer, Copernica_MarketingSoftware_Model_Copernica_Entity_Order $order)
47
  {
48
+ $customer->setStore($this->_orderItemEntity->getStoreView());
49
+
50
+ $profileId = Mage::helper('marketingsoftware/api')->getProfileId(
51
+ array(
52
  'id' => $customer->getCustomerId(),
53
  'storeView' => (string) $customer->getStoreView(),
54
  'email' => $customer->getEmail(),
55
+ )
56
+ );
57
 
58
+ if (!$profileId) {
59
+ $profileId = $this->_createProfile($customer);
60
+
61
+ if (!$profileId) {
62
+ return false;
63
+ }
64
  }
65
 
66
  $this->syncWithProfile($profileId);
71
  /**
72
  * Sync order items with certain profile
73
  *
74
+ * @param int $profileId
75
+ * @param Copernica_MarketingSoftware_Model_Copernica_Entity_Order $order
76
  * @return bool
77
  */
78
  public function syncWithProfile($profileId, Copernica_MarketingSoftware_Model_Copernica_Entity_Order $order)
80
  $itemCollectionId = Mage::helper('marketingsoftware/config')->getOrderItemCollectionId();
81
 
82
  if ($itemCollectionId) {
83
+ Mage::helper('marketingsoftware/rest_request')->put(
84
+ '/profile/'.$profileId.'/subprofiles/'.$itemCollectionId, $this->_getSubprofileData($order), array(
85
+ 'fields' => array (
86
+ 'item_id=='.$this->_orderItemEntity->getId(),
87
  'order_id=='.$order->getId()
88
  ),
89
  'create' => 'true'
90
+ )
91
+ );
92
 
93
  return true;
94
  } else {
95
+ return false;
96
  }
97
 
98
  }
100
  /**
101
  * Prepare subprofile data
102
  *
103
+ * @param Copernica_MarketingSoftware_Model_Copernica_Entity_Order $order
104
+ * @return array
105
  */
106
  protected function _getSubprofileData(Copernica_MarketingSoftware_Model_Copernica_Entity_Order $order)
107
  {
110
  $data = $this->_getRequestData($this->_orderItemEntity, $syncedFields);
111
 
112
  if (!empty($syncedFields['incrementId'])) {
113
+ $data['incrementId'] = $order->getIncrementId();
114
  }
115
 
116
  $data['item_id'] = $this->_orderItemEntity->getId();
121
 
122
  /**
123
  * Set REST order item entity
124
+ * @param Copernica_MarketingSoftware_Model_Copernica_Entity_Order_Item $orderItem
125
  */
126
  public function setOrderItemEntity(Copernica_MarketingSoftware_Model_Copernica_Entity_Order_Item $orderItem)
127
  {
128
+ $this->_orderItemEntity = $orderItem;
129
  }
130
  }
app/code/community/Copernica/MarketingSoftware/Model/Rest/Product.php CHANGED
@@ -32,7 +32,7 @@ class Copernica_MarketingSoftware_Model_Rest_Product extends Copernica_Marketing
32
  /**
33
  * Cached product entity
34
  *
35
- * @var Copernica_MarketingSoftware_Model_Copernica_Entity_Product
36
  */
37
  protected $_productEntity;
38
 
@@ -54,42 +54,47 @@ class Copernica_MarketingSoftware_Model_Rest_Product extends Copernica_Marketing
54
  /**
55
  * Tell Copernica platform that product was viewed by a customer
56
  *
57
- * @param Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer
58
  */
59
  public function viewedBy(Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer)
60
  {
61
- $customer->setStore($this->_productEntity->getStoreView());
62
-
63
- $profileId = Mage::helper('marketingsoftware/api')->getProfileId(array(
 
64
  'id' => $customer->getCustomerId(),
65
  'storeView' => (string) $customer->getStoreView(),
66
  'email' => $customer->getEmail(),
67
- ));
 
68
 
69
  if (!$profileId) {
70
- $profileId = $this->_createProfile($customer);
71
-
72
- if(!$profileId) {
73
- return false;
74
- }
75
  }
76
 
77
  $collectionId = Mage::helper('marketingsoftware/config')->getViewedProductCollectionId();
78
 
79
  if ($collectionId) {
80
- Mage::helper('marketingsoftware/rest_request')->put('/profile/'.$profileId.'/subprofiles/'.$collectionId, $this->_getSubprofileData(), array(
81
- 'fields[]' => 'product_id=='.$this->_productEntity->getId(),
82
- 'create' => 'true'
83
- ));
 
 
84
  }
85
  }
86
 
87
  /**
88
  * Set REST product entity
89
  *
90
- * @param Copernica_MarketingSoftware_Model_Copernica_Entity_Product $productEntity
91
  */
92
- public function setProductEntity(Copernica_MarketingSoftware_Model_Copernica_Entity_Product $productEntity) {
93
- $this->_productEntity = $productEntity;
 
94
  }
95
- }
32
  /**
33
  * Cached product entity
34
  *
35
+ * @var Copernica_MarketingSoftware_Model_Copernica_Entity_Product
36
  */
37
  protected $_productEntity;
38
 
54
  /**
55
  * Tell Copernica platform that product was viewed by a customer
56
  *
57
+ * @param Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer
58
  */
59
  public function viewedBy(Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer)
60
  {
61
+ $customer->setStore($this->_productEntity->getStoreView());
62
+
63
+ $profileId = Mage::helper('marketingsoftware/api')->getProfileId(
64
+ array(
65
  'id' => $customer->getCustomerId(),
66
  'storeView' => (string) $customer->getStoreView(),
67
  'email' => $customer->getEmail(),
68
+ )
69
+ );
70
 
71
  if (!$profileId) {
72
+ $profileId = $this->_createProfile($customer);
73
+
74
+ if (!$profileId) {
75
+ return false;
76
+ }
77
  }
78
 
79
  $collectionId = Mage::helper('marketingsoftware/config')->getViewedProductCollectionId();
80
 
81
  if ($collectionId) {
82
+ Mage::helper('marketingsoftware/rest_request')->put(
83
+ '/profile/'.$profileId.'/subprofiles/'.$collectionId, $this->_getSubprofileData(), array(
84
+ 'fields[]' => 'product_id=='.$this->_productEntity->getId(),
85
+ 'create' => 'true'
86
+ )
87
+ );
88
  }
89
  }
90
 
91
  /**
92
  * Set REST product entity
93
  *
94
+ * @param Copernica_MarketingSoftware_Model_Copernica_Entity_Product $productEntity
95
  */
96
+ public function setProductEntity(Copernica_MarketingSoftware_Model_Copernica_Entity_Product $productEntity)
97
+ {
98
+ $this->_productEntity = $productEntity;
99
  }
100
+ }
app/code/community/Copernica/MarketingSoftware/Model/Rest/Quote.php CHANGED
@@ -32,7 +32,7 @@ class Copernica_MarketingSoftware_Model_Rest_Quote extends Copernica_MarketingSo
32
  /**
33
  * Copernica entity
34
  *
35
- * @var Copernica_MarketingSoftware_Model_Copernica_Entity_Quote
36
  */
37
  protected $_quoteEntity;
38
 
@@ -59,22 +59,23 @@ class Copernica_MarketingSoftware_Model_Rest_Quote extends Copernica_MarketingSo
59
  /**
60
  * Sync quote with customer
61
  *
62
- * @param Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer
63
  */
64
  public function syncWithCustomer(Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer)
65
  {
66
  foreach ($this->_quoteEntity->getItems() as $quoteItemEntity) {
67
- $restQuoteItem = $quoteItemEntity->getRestQuoteItem();
68
- $restQuoteItem->syncWithQuote($customer, $this->_quoteEntity->getId());
69
  }
70
  }
71
 
72
  /**
73
  * Set REST quote entity
74
  *
75
- * @param Copernica_MarketingSoftware_Model_Copernica_Entity_Quote $quoteEntity
76
  */
77
- public function setQuoteEntity(Copernica_MarketingSoftware_Model_Copernica_Entity_Quote $quoteEntity) {
78
- $this->_quoteEntity = $quoteEntity;
 
79
  }
80
- }
32
  /**
33
  * Copernica entity
34
  *
35
+ * @var Copernica_MarketingSoftware_Model_Copernica_Entity_Quote
36
  */
37
  protected $_quoteEntity;
38
 
59
  /**
60
  * Sync quote with customer
61
  *
62
+ * @param Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer
63
  */
64
  public function syncWithCustomer(Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer)
65
  {
66
  foreach ($this->_quoteEntity->getItems() as $quoteItemEntity) {
67
+ $restQuoteItem = $quoteItemEntity->getRestQuoteItem();
68
+ $restQuoteItem->syncWithQuote($customer, $this->_quoteEntity->getId());
69
  }
70
  }
71
 
72
  /**
73
  * Set REST quote entity
74
  *
75
+ * @param Copernica_MarketingSoftware_Model_Copernica_Entity_Quote $quoteEntity
76
  */
77
+ public function setQuoteEntity(Copernica_MarketingSoftware_Model_Copernica_Entity_Quote $quoteEntity)
78
+ {
79
+ $this->_quoteEntity = $quoteEntity;
80
  }
81
+ }
app/code/community/Copernica/MarketingSoftware/Model/Rest/Quote/Item.php CHANGED
@@ -1,49 +1,54 @@
1
  <?php
2
 
3
  class Copernica_MarketingSoftware_Model_Rest_Quote_Item extends Copernica_MarketingSoftware_Model_Rest_Order_Item
4
- {
5
- /**
6
- * Customer that will be used to send data
7
- *
8
- * @var Copernica_MarketingSoftware_Model_Copernica_Entity_Quote_Item
9
- */
10
- protected $_quoteItemEntity;
11
-
 
12
  /**
13
  * Sync item with quote
14
  *
15
- * @param Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer
16
- * @param int $quoteId
17
  * @return boolean
18
  */
19
  public function syncWithQuote(Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer, $quoteId)
20
  {
21
- $customer->setStore($this->_quoteItemEntity->getStoreView());
22
-
23
- $profileId = Mage::helper('marketingsoftware/api')->getProfileId(array(
 
24
  'id' => $customer->getCustomerId(),
25
  'storeView' => (string) $customer->getStoreView(),
26
  'email' => $customer->getEmail(),
27
- ));
 
28
 
29
  if (!$profileId) {
30
- $profileId = $this->_createProfile($customer);
31
-
32
- if(!$profileId) {
33
- return false;
34
- }
35
  }
36
 
37
  $quoteItemCollectionId = Mage::helper('marketingsoftware/config')->getQuoteItemCollectionId();
38
 
39
  if ($quoteItemCollectionId) {
40
- Mage::helper('marketingsoftware/rest_request')->put('/profile/'.$profileId.'/subprofiles/'.$quoteItemCollectionId, $this->getQuoteItemSubprofileData($quoteId), array(
41
- 'fields' => array(
42
- 'item_id=='.$this->_quoteItemEntity->getId(),
43
- 'quote_id=='.$quoteId
44
- ),
45
- 'create' => 'true'
46
- ));
 
 
47
  }
48
 
49
  return true;
@@ -52,7 +57,7 @@ class Copernica_MarketingSoftware_Model_Rest_Quote_Item extends Copernica_Market
52
  /**
53
  * Prepare subprofile date
54
  *
55
- * @param int $quoteId
56
  * @return array
57
  */
58
  public function getQuoteItemSubprofileData($quoteId)
@@ -71,10 +76,10 @@ class Copernica_MarketingSoftware_Model_Rest_Quote_Item extends Copernica_Market
71
  /**
72
  * Set REST quote item entity
73
  *
74
- * @param Copernica_MarketingSoftware_Model_Copernica_Entity_Quote_Item $quoteItemEntity
75
  */
76
  public function setQuoteItemEntity(Copernica_MarketingSoftware_Model_Copernica_Entity_Quote_Item $quoteItemEntity)
77
  {
78
- $this->_quoteItemEntity = $quoteItemEntity;
79
  }
80
- }
1
  <?php
2
 
3
  class Copernica_MarketingSoftware_Model_Rest_Quote_Item extends Copernica_MarketingSoftware_Model_Rest_Order_Item
4
+ {
5
+
6
+ /**
7
+ * Customer that will be used to send data
8
+ *
9
+ * @var Copernica_MarketingSoftware_Model_Copernica_Entity_Quote_Item
10
+ */
11
+ protected $_quoteItemEntity;
12
+
13
  /**
14
  * Sync item with quote
15
  *
16
+ * @param Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer
17
+ * @param int $quoteId
18
  * @return boolean
19
  */
20
  public function syncWithQuote(Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer, $quoteId)
21
  {
22
+ $customer->setStore($this->_quoteItemEntity->getStoreView());
23
+
24
+ $profileId = Mage::helper('marketingsoftware/api')->getProfileId(
25
+ array(
26
  'id' => $customer->getCustomerId(),
27
  'storeView' => (string) $customer->getStoreView(),
28
  'email' => $customer->getEmail(),
29
+ )
30
+ );
31
 
32
  if (!$profileId) {
33
+ $profileId = $this->_createProfile($customer);
34
+
35
+ if (!$profileId) {
36
+ return false;
37
+ }
38
  }
39
 
40
  $quoteItemCollectionId = Mage::helper('marketingsoftware/config')->getQuoteItemCollectionId();
41
 
42
  if ($quoteItemCollectionId) {
43
+ Mage::helper('marketingsoftware/rest_request')->put(
44
+ '/profile/'.$profileId.'/subprofiles/'.$quoteItemCollectionId, $this->getQuoteItemSubprofileData($quoteId), array(
45
+ 'fields' => array(
46
+ 'item_id=='.$this->_quoteItemEntity->getId(),
47
+ 'quote_id=='.$quoteId
48
+ ),
49
+ 'create' => 'true'
50
+ )
51
+ );
52
  }
53
 
54
  return true;
57
  /**
58
  * Prepare subprofile date
59
  *
60
+ * @param int $quoteId
61
  * @return array
62
  */
63
  public function getQuoteItemSubprofileData($quoteId)
76
  /**
77
  * Set REST quote item entity
78
  *
79
+ * @param Copernica_MarketingSoftware_Model_Copernica_Entity_Quote_Item $quoteItemEntity
80
  */
81
  public function setQuoteItemEntity(Copernica_MarketingSoftware_Model_Copernica_Entity_Quote_Item $quoteItemEntity)
82
  {
83
+ $this->_quoteItemEntity = $quoteItemEntity;
84
  }
85
+ }
app/code/community/Copernica/MarketingSoftware/Model/Rest/Subscription.php CHANGED
@@ -33,14 +33,14 @@ class Copernica_MarketingSoftware_Model_Rest_Subscription extends Copernica_Mark
33
  * Subscription entity that we will use to create proper profile inside
34
  * copernica database.
35
  *
36
- * @var Copernica_MarketingSoftware_Model_Copernica_Entity_Subscription
37
  */
38
  protected $_subscriptionEntity;
39
 
40
  /**
41
  * Get data that should be update in copernica database
42
  *
43
- * @param string $storeView
44
  * @return array
45
  */
46
  protected function _getProfileData($storeview)
@@ -64,12 +64,14 @@ class Copernica_MarketingSoftware_Model_Rest_Subscription extends Copernica_Mark
64
  public function sync()
65
  {
66
  $storeview = (string) $this->_subscriptionEntity->getStoreView();
67
-
68
- $profileId = Mage::helper('marketingsoftware/api')->getProfileId(array(
 
69
  'id' => null,
70
- 'storeView' => $storeview,
71
  'email' => $this->_subscriptionEntity->getEmail(),
72
- ));
 
73
 
74
  $request = Mage::helper('marketingsoftware/rest_request');
75
 
@@ -87,10 +89,10 @@ class Copernica_MarketingSoftware_Model_Rest_Subscription extends Copernica_Mark
87
  /**
88
  * Set REST subscription entity
89
  *
90
- * @param Copernica_MarketingSoftware_Model_Copernica_Entity_Subscription $subscriptionEntity
91
  */
92
- public function setSubscriptionEntity(Copernica_MarketingSoftware_Model_Copernica_Entity_Quote $subscriptionEntity)
93
  {
94
- $this->_subscriptionEntity = $subscriptionEntity;
95
  }
96
  }
33
  * Subscription entity that we will use to create proper profile inside
34
  * copernica database.
35
  *
36
+ * @var Copernica_MarketingSoftware_Model_Copernica_Entity_Subscription
37
  */
38
  protected $_subscriptionEntity;
39
 
40
  /**
41
  * Get data that should be update in copernica database
42
  *
43
+ * @param string $storeView
44
  * @return array
45
  */
46
  protected function _getProfileData($storeview)
64
  public function sync()
65
  {
66
  $storeview = (string) $this->_subscriptionEntity->getStoreView();
67
+
68
+ $profileId = Mage::helper('marketingsoftware/api')->getProfileId(
69
+ array(
70
  'id' => null,
71
+ 'storeView' => $storeview,
72
  'email' => $this->_subscriptionEntity->getEmail(),
73
+ )
74
+ );
75
 
76
  $request = Mage::helper('marketingsoftware/rest_request');
77
 
89
  /**
90
  * Set REST subscription entity
91
  *
92
+ * @param Copernica_MarketingSoftware_Model_Copernica_Entity_Subscription $subscriptionEntity
93
  */
94
+ public function setSubscriptionEntity(Copernica_MarketingSoftware_Model_Copernica_Entity_Subscription $subscriptionEntity)
95
  {
96
+ $this->_subscriptionEntity = $subscriptionEntity;
97
  }
98
  }
app/code/community/Copernica/MarketingSoftware/Model/Rest/Wishlist.php CHANGED
@@ -32,7 +32,7 @@ class Copernica_MarketingSoftware_Model_Rest_Wishlist extends Copernica_Marketin
32
  /**
33
  * Copernica entity
34
  *
35
- * @var Copernica_MarketingSoftware_Model_Copernica_Entity_Wishlist
36
  */
37
  protected $_wishlistEntity;
38
 
@@ -49,22 +49,23 @@ class Copernica_MarketingSoftware_Model_Rest_Wishlist extends Copernica_Marketin
49
  /**
50
  * Sync wishlist with customer
51
  *
52
- * @param Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer
53
  */
54
  public function syncWithCustomer(Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer)
55
  {
56
  foreach ($this->_wishlistEntity->getItems() as $wishlistItemEntity) {
57
- $restWishlistItem = $wishlistItemEntity->getRestWishlistItem();
58
- $restWishlistItem->syncWithWishlist($customer, $this->_wishlistEntity->getId());
59
  }
60
  }
61
 
62
  /**
63
  * Set REST wishlist entity
64
  *
65
- * @param Copernica_MarketingSoftware_Model_Copernica_Entity_Wishlist $wishlistEntity
66
  */
67
- public function setWishlistEntity(Copernica_MarketingSoftware_Model_Copernica_Entity_Wishlist $wishlistEntity) {
68
- $this->_wishlistEntity = $wishlistEntity;
 
69
  }
70
- }
32
  /**
33
  * Copernica entity
34
  *
35
+ * @var Copernica_MarketingSoftware_Model_Copernica_Entity_Wishlist
36
  */
37
  protected $_wishlistEntity;
38
 
49
  /**
50
  * Sync wishlist with customer
51
  *
52
+ * @param Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer
53
  */
54
  public function syncWithCustomer(Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer)
55
  {
56
  foreach ($this->_wishlistEntity->getItems() as $wishlistItemEntity) {
57
+ $restWishlistItem = $wishlistItemEntity->getRestWishlistItem();
58
+ $restWishlistItem->syncWithWishlist($customer, $this->_wishlistEntity->getId());
59
  }
60
  }
61
 
62
  /**
63
  * Set REST wishlist entity
64
  *
65
+ * @param Copernica_MarketingSoftware_Model_Copernica_Entity_Wishlist $wishlistEntity
66
  */
67
+ public function setWishlistEntity(Copernica_MarketingSoftware_Model_Copernica_Entity_Wishlist $wishlistEntity)
68
+ {
69
+ $this->_wishlistEntity = $wishlistEntity;
70
  }
71
+ }
app/code/community/Copernica/MarketingSoftware/Model/Rest/Wishlist/Item.php CHANGED
@@ -1,37 +1,40 @@
1
  <?php
2
 
3
  class Copernica_MarketingSoftware_Model_Rest_Wishlist_Item extends Copernica_MarketingSoftware_Model_Rest
4
- {
5
- /**
6
- * Wishlist that will be used to send data
7
- *
8
- * @var Copernica_MarketingSoftware_Model_Copernica_Entity_Wishlist_Item
9
- */
10
- protected $_wishlistItemEntity;
11
-
 
12
  /**
13
  * Sync item with wishlist
14
  *
15
- * @param Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer
16
- * @param int $wishlistId
17
  * @return boolean
18
  */
19
  public function syncWithCustomer(Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer)
20
- {
21
- $customer->setStore($this->_wishlistItemEntity->getStoreView());
22
-
23
- $profileId = Mage::helper('marketingsoftware/api')->getProfileId(array(
 
24
  'id' => $customer->getCustomerId(),
25
  'storeView' => (string) $customer->getStoreView(),
26
  'email' => $customer->getEmail(),
27
- ));
 
28
 
29
  if (!$profileId) {
30
- $profileId = $this->_createProfile($customer);
31
-
32
- if(!$profileId) {
33
- return false;
34
- }
35
  }
36
 
37
  $wishlistId = $this->_wishlistItemEntity->getWishlistId();
@@ -39,13 +42,15 @@ class Copernica_MarketingSoftware_Model_Rest_Wishlist_Item extends Copernica_Mar
39
  $wishlistItemCollectionId = Mage::helper('marketingsoftware/config')->getWishlistItemCollectionId();
40
 
41
  if ($wishlistItemCollectionId) {
42
- Mage::helper('marketingsoftware/rest_request')->put('/profile/'.$profileId.'/subprofiles/'.$wishlistItemCollectionId, $this->getWishlistSubprofileData($wishlistId), array(
43
- 'fields' => array(
44
- 'item_id=='.$this->_wishlistItemEntity->getId(),
45
- 'wishlist_id=='.$wishlistId
46
- ),
47
- 'create' => 'true'
48
- ));
 
 
49
  }
50
 
51
  return true;
@@ -54,7 +59,7 @@ class Copernica_MarketingSoftware_Model_Rest_Wishlist_Item extends Copernica_Mar
54
  /**
55
  * Prepare subprofile date
56
  *
57
- * @param int $wishlistId
58
  * @return array
59
  */
60
  public function getWishlistSubprofileData($wishlistId)
@@ -71,10 +76,10 @@ class Copernica_MarketingSoftware_Model_Rest_Wishlist_Item extends Copernica_Mar
71
  /**
72
  * Set REST wishlist item entity
73
  *
74
- * @param Copernica_MarketingSoftware_Model_Copernica_Entity_Wishlist_Item $wishlistItemEntity
75
  */
76
  public function setWishlistItemEntity(Copernica_MarketingSoftware_Model_Copernica_Entity_Wishlist_Item $wishlistItemEntity)
77
  {
78
- $this->_wishlistItemEntity = $wishlistItemEntity;
79
  }
80
- }
1
  <?php
2
 
3
  class Copernica_MarketingSoftware_Model_Rest_Wishlist_Item extends Copernica_MarketingSoftware_Model_Rest
4
+ {
5
+
6
+ /**
7
+ * Wishlist that will be used to send data
8
+ *
9
+ * @var Copernica_MarketingSoftware_Model_Copernica_Entity_Wishlist_Item
10
+ */
11
+ protected $_wishlistItemEntity;
12
+
13
  /**
14
  * Sync item with wishlist
15
  *
16
+ * @param Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer
17
+ * @param int $wishlistId
18
  * @return boolean
19
  */
20
  public function syncWithCustomer(Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer)
21
+ {
22
+ $customer->setStore($this->_wishlistItemEntity->getStoreView());
23
+
24
+ $profileId = Mage::helper('marketingsoftware/api')->getProfileId(
25
+ array(
26
  'id' => $customer->getCustomerId(),
27
  'storeView' => (string) $customer->getStoreView(),
28
  'email' => $customer->getEmail(),
29
+ )
30
+ );
31
 
32
  if (!$profileId) {
33
+ $profileId = $this->_createProfile($customer);
34
+
35
+ if (!$profileId) {
36
+ return false;
37
+ }
38
  }
39
 
40
  $wishlistId = $this->_wishlistItemEntity->getWishlistId();
42
  $wishlistItemCollectionId = Mage::helper('marketingsoftware/config')->getWishlistItemCollectionId();
43
 
44
  if ($wishlistItemCollectionId) {
45
+ Mage::helper('marketingsoftware/rest_request')->put(
46
+ '/profile/'.$profileId.'/subprofiles/'.$wishlistItemCollectionId, $this->getWishlistSubprofileData($wishlistId), array(
47
+ 'fields' => array(
48
+ 'item_id=='.$this->_wishlistItemEntity->getId(),
49
+ 'wishlist_id=='.$wishlistId
50
+ ),
51
+ 'create' => 'true'
52
+ )
53
+ );
54
  }
55
 
56
  return true;
59
  /**
60
  * Prepare subprofile date
61
  *
62
+ * @param int $wishlistId
63
  * @return array
64
  */
65
  public function getWishlistSubprofileData($wishlistId)
76
  /**
77
  * Set REST wishlist item entity
78
  *
79
+ * @param Copernica_MarketingSoftware_Model_Copernica_Entity_Wishlist_Item $wishlistItemEntity
80
  */
81
  public function setWishlistItemEntity(Copernica_MarketingSoftware_Model_Copernica_Entity_Wishlist_Item $wishlistItemEntity)
82
  {
83
+ $this->_wishlistItemEntity = $wishlistItemEntity;
84
  }
85
+ }
app/code/community/Copernica/MarketingSoftware/Model/Sync/Profile.php CHANGED
@@ -53,13 +53,13 @@ class Copernica_MarketingSoftware_Model_Sync_Profile extends Mage_Core_Model_Abs
53
  /**
54
  * Set client key
55
  *
56
- * @param string $clientKey
57
  * @return Copernica_MarketingSoftware_Model_Sync_Profile
58
  */
59
  public function setClientKey($clientKey)
60
  {
61
  if (parent::getData('client_key') != $clientKey) {
62
- parent::setData('access_token', '');
63
  }
64
 
65
  parent::setData('client_key', $clientKey);
@@ -80,13 +80,13 @@ class Copernica_MarketingSoftware_Model_Sync_Profile extends Mage_Core_Model_Abs
80
  /**
81
  * Set client secret for this sync profile
82
  *
83
- * @param string $clientSecret
84
  * @return Copernica_MarketingSoftware_Model_Sync_Profile
85
  */
86
  public function setClientSecret($clientSecret)
87
  {
88
  if (parent::getData('client_secret') != $clientSecret) {
89
- parent::setData('access_token', '');
90
  }
91
 
92
  parent::setData('client_secret', $clientSecret);
@@ -107,7 +107,7 @@ class Copernica_MarketingSoftware_Model_Sync_Profile extends Mage_Core_Model_Abs
107
  /**
108
  * Set access token for this sync profile
109
  *
110
- * @param string $accessToken
111
  * @return Copernica_MarketingSoftware_Model_Sync_Profile
112
  */
113
  public function setAccessToken($accessToken)
@@ -130,7 +130,7 @@ class Copernica_MarketingSoftware_Model_Sync_Profile extends Mage_Core_Model_Abs
130
  /**
131
  * Set name for this sync profile
132
  *
133
- * @param string $name
134
  * @return Copernica_MarketingSoftware_Model_Sync_Profile
135
  */
136
  public function setName($name)
@@ -153,19 +153,19 @@ class Copernica_MarketingSoftware_Model_Sync_Profile extends Mage_Core_Model_Abs
153
  /**
154
  * Assign store view to current sync profile
155
  *
156
- * @param StoreView|int $storeView
157
  * @return Copernica_MarketingSoftware_Model_Sync_Profile
158
  */
159
  public function assignStoreView($storeView)
160
  {
161
  if (is_object($storeView)) {
162
- $storeView = $storeView->getId();
163
  }
164
 
165
  $bindings = Mage::helper('marketingsoftware/config')->getSyncProfilesBindings();
166
 
167
  if ($this->getId() >= 1) {
168
- $this->save();
169
  }
170
 
171
  $bindings[$store] = $this->getId();
@@ -186,7 +186,7 @@ class Copernica_MarketingSoftware_Model_Sync_Profile extends Mage_Core_Model_Abs
186
 
187
  foreach ($bindings as $storeId => $profileId) {
188
  if ($profileId == $this->getId()) {
189
- $bindings[$storeId] = -1;
190
  }
191
  }
192
 
@@ -195,4 +195,4 @@ class Copernica_MarketingSoftware_Model_Sync_Profile extends Mage_Core_Model_Abs
195
  //@todo implement
196
  return $this;
197
  }
198
- }
53
  /**
54
  * Set client key
55
  *
56
+ * @param string $clientKey
57
  * @return Copernica_MarketingSoftware_Model_Sync_Profile
58
  */
59
  public function setClientKey($clientKey)
60
  {
61
  if (parent::getData('client_key') != $clientKey) {
62
+ parent::setData('access_token', '');
63
  }
64
 
65
  parent::setData('client_key', $clientKey);
80
  /**
81
  * Set client secret for this sync profile
82
  *
83
+ * @param string $clientSecret
84
  * @return Copernica_MarketingSoftware_Model_Sync_Profile
85
  */
86
  public function setClientSecret($clientSecret)
87
  {
88
  if (parent::getData('client_secret') != $clientSecret) {
89
+ parent::setData('access_token', '');
90
  }
91
 
92
  parent::setData('client_secret', $clientSecret);
107
  /**
108
  * Set access token for this sync profile
109
  *
110
+ * @param string $accessToken
111
  * @return Copernica_MarketingSoftware_Model_Sync_Profile
112
  */
113
  public function setAccessToken($accessToken)
130
  /**
131
  * Set name for this sync profile
132
  *
133
+ * @param string $name
134
  * @return Copernica_MarketingSoftware_Model_Sync_Profile
135
  */
136
  public function setName($name)
153
  /**
154
  * Assign store view to current sync profile
155
  *
156
+ * @param StoreView|int $storeView
157
  * @return Copernica_MarketingSoftware_Model_Sync_Profile
158
  */
159
  public function assignStoreView($storeView)
160
  {
161
  if (is_object($storeView)) {
162
+ $storeView = $storeView->getId();
163
  }
164
 
165
  $bindings = Mage::helper('marketingsoftware/config')->getSyncProfilesBindings();
166
 
167
  if ($this->getId() >= 1) {
168
+ $this->save();
169
  }
170
 
171
  $bindings[$store] = $this->getId();
186
 
187
  foreach ($bindings as $storeId => $profileId) {
188
  if ($profileId == $this->getId()) {
189
+ $bindings[$storeId] = -1;
190
  }
191
  }
192
 
195
  //@todo implement
196
  return $this;
197
  }
198
+ }
app/code/community/Copernica/MarketingSoftware/Model/Sync/Status.php CHANGED
@@ -9,69 +9,71 @@ class Copernica_MarketingSoftware_Model_Sync_Status implements Serializable
9
  /**
10
  * What is the last customer Id
11
  *
12
- * @var int
13
  */
14
  protected $_lastCustomerId = 0;
15
 
16
  /**
17
  * What is the last order id
18
  *
19
- * @var int
20
  */
21
  protected $_lastOrderId = 0;
22
 
23
  /**
24
  * What is the last subscription id
25
  *
26
- * @var int
27
  */
28
  protected $_lastSubscriptionId = 0;
29
 
30
  /**
31
  * This array should contain all stores Ids that we want to use as a filter.
32
  *
33
- * @var array
34
  */
35
  protected $_storesFilter = array();
36
 
37
  /**
38
  * Serialize instance
39
  *
40
- * @return string
41
  */
42
  public function serialize()
43
  {
44
- return serialize(array(
 
45
  'lastCustomer' => $this->_lastCustomerId,
46
  'lastOrder' => $this->_lastOrderId,
47
  'lastSub' => $this->_lastSubscriptionId,
48
  'storesFilter' => $this->_storesFilter
49
- ));
 
50
  }
51
 
52
  /**
53
  * Unserialize instance
54
  *
55
- * @param string $data
56
  */
57
  public function unserialize($data)
58
  {
59
  $data = unserialize($data);
60
 
61
- if(isset($data['lastCustomer'])) {
62
- $this->_lastCustomerId = $data['lastCustomer'];
63
  }
64
 
65
- if(isset($data['lastOrder'])) {
66
- $this->_lastOrderId = $data['lastOrder'];
67
  }
68
 
69
- if(isset($data['lastSub'])) {
70
- $this->_lastSubscriptionId = $data['lastSub'];
71
  }
72
 
73
- if(isset($data['storesFilter'])) {
74
- $this->_storesFilter = $data['storesFilter'];
75
  }
76
  }
77
 
@@ -94,7 +96,7 @@ class Copernica_MarketingSoftware_Model_Sync_Status implements Serializable
94
  /**
95
  * Create instance of this class from stdClass
96
  *
97
- * @param StdClass $stdObject
98
  * @return Copernica_MarketingSoftware_Model_Sync_Status
99
  */
100
  static public function fromStd(StdClass $stdObject)
@@ -109,8 +111,8 @@ class Copernica_MarketingSoftware_Model_Sync_Status implements Serializable
109
  );
110
 
111
  foreach ($trans as $inObject => $property) {
112
- if (property_exists($stdObject, $inObject)) {
113
- $instance->$property = $stdObject->$inObject;
114
  }
115
  }
116
 
@@ -120,8 +122,8 @@ class Copernica_MarketingSoftware_Model_Sync_Status implements Serializable
120
  /**
121
  * We want to overload __call so we can define setters and getters.
122
  *
123
- * @param string $methodName
124
- * @param array $arguments
125
  * @return mixed
126
  */
127
  public function __call($methodName, $arguments)
@@ -146,4 +148,4 @@ class Copernica_MarketingSoftware_Model_Sync_Status implements Serializable
146
  return $this->$property;
147
  }
148
  }
149
- }
9
  /**
10
  * What is the last customer Id
11
  *
12
+ * @var int
13
  */
14
  protected $_lastCustomerId = 0;
15
 
16
  /**
17
  * What is the last order id
18
  *
19
+ * @var int
20
  */
21
  protected $_lastOrderId = 0;
22
 
23
  /**
24
  * What is the last subscription id
25
  *
26
+ * @var int
27
  */
28
  protected $_lastSubscriptionId = 0;
29
 
30
  /**
31
  * This array should contain all stores Ids that we want to use as a filter.
32
  *
33
+ * @var array
34
  */
35
  protected $_storesFilter = array();
36
 
37
  /**
38
  * Serialize instance
39
  *
40
+ * @return string
41
  */
42
  public function serialize()
43
  {
44
+ return serialize(
45
+ array(
46
  'lastCustomer' => $this->_lastCustomerId,
47
  'lastOrder' => $this->_lastOrderId,
48
  'lastSub' => $this->_lastSubscriptionId,
49
  'storesFilter' => $this->_storesFilter
50
+ )
51
+ );
52
  }
53
 
54
  /**
55
  * Unserialize instance
56
  *
57
+ * @param string $data
58
  */
59
  public function unserialize($data)
60
  {
61
  $data = unserialize($data);
62
 
63
+ if (isset($data['lastCustomer'])) {
64
+ $this->_lastCustomerId = $data['lastCustomer'];
65
  }
66
 
67
+ if (isset($data['lastOrder'])) {
68
+ $this->_lastOrderId = $data['lastOrder'];
69
  }
70
 
71
+ if (isset($data['lastSub'])) {
72
+ $this->_lastSubscriptionId = $data['lastSub'];
73
  }
74
 
75
+ if (isset($data['storesFilter'])) {
76
+ $this->_storesFilter = $data['storesFilter'];
77
  }
78
  }
79
 
96
  /**
97
  * Create instance of this class from stdClass
98
  *
99
+ * @param StdClass $stdObject
100
  * @return Copernica_MarketingSoftware_Model_Sync_Status
101
  */
102
  static public function fromStd(StdClass $stdObject)
111
  );
112
 
113
  foreach ($trans as $inObject => $property) {
114
+ if (property_exists($stdObject, $inObject)) {
115
+ $instance->$property = $stdObject->$inObject;
116
  }
117
  }
118
 
122
  /**
123
  * We want to overload __call so we can define setters and getters.
124
  *
125
+ * @param string $methodName
126
+ * @param array $arguments
127
  * @return mixed
128
  */
129
  public function __call($methodName, $arguments)
148
  return $this->$property;
149
  }
150
  }
151
+ }
app/code/community/Copernica/MarketingSoftware/controllers/Adminhtml/Marketingsoftware/AccessTokenController.php CHANGED
@@ -46,7 +46,7 @@ class Copernica_MarketingSoftware_AdminHtml_MarketingSoftware_AccesstokenControl
46
  $session = Mage::getSingleton('adminhtml/session');
47
 
48
  if (!$session->getState()) {
49
- $session->setState($this->generateState());
50
  }
51
 
52
  $this->renderLayout();
@@ -65,4 +65,4 @@ class Copernica_MarketingSoftware_AdminHtml_MarketingSoftware_AccesstokenControl
65
 
66
  return $this->_redirect('*/marketingsoftware_settings/index');
67
  }
68
- }
46
  $session = Mage::getSingleton('adminhtml/session');
47
 
48
  if (!$session->getState()) {
49
+ $session->setState($this->generateState());
50
  }
51
 
52
  $this->renderLayout();
65
 
66
  return $this->_redirect('*/marketingsoftware_settings/index');
67
  }
68
+ }
app/code/community/Copernica/MarketingSoftware/controllers/Adminhtml/Marketingsoftware/AjaxcollectionController.php CHANGED
@@ -44,7 +44,7 @@ class Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_AjaxcollectionCont
44
 
45
  try {
46
  if ($post['type'] == 'main') {
47
- try {
48
  $validator->validateDatabase($post['name']);
49
  } catch (Copernica_MarketingSoftware_Exception $exception) {
50
  array_push($problems, $exception->getMessage());
@@ -102,9 +102,13 @@ class Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_AjaxcollectionCont
102
  $response = $this->getResponse();
103
 
104
  if (!isset($post['name'])) {
105
- return $response->setBody(json_encode(array(
106
- 'message' => 'Invalid input'
107
- )));
 
 
 
 
108
  }
109
 
110
  $config = Mage::helper('marketingsoftware/config');
@@ -112,16 +116,20 @@ class Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_AjaxcollectionCont
112
 
113
  $database = $config->getDatabaseName();
114
 
115
- $db_not_needed = false;
116
 
117
- if($post['name'] == 'main') {
118
- $db_not_needed = true;
119
  }
120
 
121
- if (empty($database) && !$db_not_needed) {
122
- return $response->setBody(json_encode(array(
123
- 'error' => 'no database'
124
- )));
 
 
 
 
125
  }
126
 
127
  $linkedName = '';
@@ -174,11 +182,11 @@ class Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_AjaxcollectionCont
174
  break;
175
 
176
  case 'wishlistproducts':
177
- $linkedName = $config->getWishlistItemCollectionName();
178
- $supportedFields = $data->supportedWishlistItemFields();
179
- $linkedFields = $config->getLinkedWishlistItemFields();
180
- $label = 'Wishlist items collection';
181
- break;
182
  }
183
 
184
  $fields = array();
@@ -191,12 +199,16 @@ class Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_AjaxcollectionCont
191
  );
192
  }
193
 
194
- $response->setBody(json_encode(array(
195
- 'name' => $post['name'],
196
- 'linkedName' => $linkedName,
197
- 'label' => $label,
198
- 'fields' => $fields,
199
- )));
 
 
 
 
200
  }
201
 
202
  /**
@@ -253,11 +265,18 @@ class Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_AjaxcollectionCont
253
 
254
  $profileCacheCollection = Mage::getModel('marketingsoftware/profile_cache')->getCollection();
255
 
256
- foreach($profileCacheCollection as $profileCache) {
257
- $profileCache->delete();
258
  }
259
 
260
  $config->unsDatabaseId();
 
 
 
 
 
 
 
261
  $config->setDatabaseName($post['name']);
262
 
263
  $fields = array();
@@ -319,11 +338,11 @@ class Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_AjaxcollectionCont
319
  $config->setLinkedQuoteItemFields($fields);
320
  break;
321
 
322
- case 'wishlistproducts':
323
  $config->unsWishlistItemCollectionId();
324
  $config->setWishlistItemCollectionName($post['name']);
325
- $config->setLinkedWishlistItemFields($fields);
326
- break;
327
  }
328
  break;
329
  }
@@ -349,8 +368,8 @@ class Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_AjaxcollectionCont
349
 
350
  $profileCacheCollection = Mage::getModel('marketingsoftware/profile_cache')->getCollection();
351
 
352
- foreach($profileCacheCollection as $profileCache) {
353
- $profileCache->delete();
354
  }
355
 
356
  $supportedFields = $data->supportedCustomerFields();
@@ -366,7 +385,7 @@ class Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_AjaxcollectionCont
366
  /*
367
  * Quote items collection
368
  */
369
- $builder->createCollection($databaseName, 'Cart_Items' ,'cartproducts');
370
  $config->setQuoteItemCollectionName('Cart_Items');
371
  $supportedFields = $data->supportedQuoteItemFields();
372
  $linkedFields = array();
@@ -381,7 +400,7 @@ class Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_AjaxcollectionCont
381
  /*
382
  * Orders collection
383
  */
384
- $builder->createCollection($databaseName, 'Orders' ,'orders');
385
  $config->setOrdersCollectionName('Orders');
386
  $supportedFields = $data->supportedOrderFields();
387
  $linkedFields = array();
@@ -396,7 +415,7 @@ class Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_AjaxcollectionCont
396
  /*
397
  * Orders items collection
398
  */
399
- $builder->createCollection($databaseName, 'Orders_Items' ,'orderproducts');
400
  $config->setOrderItemCollectionName('Orders_Items');
401
  $supportedFields = $data->supportedOrderItemFields();
402
  $linkedFields = array();
@@ -411,7 +430,7 @@ class Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_AjaxcollectionCont
411
  /*
412
  * Addresses collection
413
  */
414
- $builder->createCollection($databaseName, 'Addresses' ,'addresses');
415
  $config->setAddressCollectionName('Addresses');
416
  $supportedFields = $data->supportedAddressFields();
417
  $linkedFields = array();
@@ -426,7 +445,7 @@ class Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_AjaxcollectionCont
426
  /*
427
  * Viewed products collection
428
  */
429
- $builder->createCollection($databaseName, 'Viewed_Products' ,'viewedproducts');
430
  $config->setViewedProductCollectionName('Viewed_Products');
431
  $supportedFields = $data->supportedViewedProductFields();
432
  $linkedFields = array();
@@ -441,16 +460,16 @@ class Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_AjaxcollectionCont
441
  /*
442
  * Wishlist items collection
443
  */
444
- $builder->createCollection($databaseName, 'Wishlist_Items' ,'wishlistproducts');
445
  $config->setWishlistItemCollectionName('Wishlist_Items');
446
  $supportedFields = $data->supportedWishlistItemFields();
447
  $linkedFields = array();
448
 
449
  foreach ($supportedFields as $name => $label) {
450
- $builder->createCollectionField($databaseName, 'Wishlist_Items', 'wishlistproducts', $name, $name);
451
- $linkedFields[$name] = $name;
452
  }
453
 
454
  $config->setLinkedWishlistItemFields($linkedFields);
455
  }
456
- }
44
 
45
  try {
46
  if ($post['type'] == 'main') {
47
+ try {
48
  $validator->validateDatabase($post['name']);
49
  } catch (Copernica_MarketingSoftware_Exception $exception) {
50
  array_push($problems, $exception->getMessage());
102
  $response = $this->getResponse();
103
 
104
  if (!isset($post['name'])) {
105
+ return $response->setBody(
106
+ json_encode(
107
+ array(
108
+ 'message' => 'Invalid input'
109
+ )
110
+ )
111
+ );
112
  }
113
 
114
  $config = Mage::helper('marketingsoftware/config');
116
 
117
  $database = $config->getDatabaseName();
118
 
119
+ $dbNotNeeded = false;
120
 
121
+ if ($post['name'] == 'main') {
122
+ $dbNotNeeded = true;
123
  }
124
 
125
+ if (empty($database) && !$dbNotNeeded) {
126
+ return $response->setBody(
127
+ json_encode(
128
+ array(
129
+ 'error' => 'no database'
130
+ )
131
+ )
132
+ );
133
  }
134
 
135
  $linkedName = '';
182
  break;
183
 
184
  case 'wishlistproducts':
185
+ $linkedName = $config->getWishlistItemCollectionName();
186
+ $supportedFields = $data->supportedWishlistItemFields();
187
+ $linkedFields = $config->getLinkedWishlistItemFields();
188
+ $label = 'Wishlist items collection';
189
+ break;
190
  }
191
 
192
  $fields = array();
199
  );
200
  }
201
 
202
+ $response->setBody(
203
+ json_encode(
204
+ array(
205
+ 'name' => $post['name'],
206
+ 'linkedName' => $linkedName,
207
+ 'label' => $label,
208
+ 'fields' => $fields,
209
+ )
210
+ )
211
+ );
212
  }
213
 
214
  /**
265
 
266
  $profileCacheCollection = Mage::getModel('marketingsoftware/profile_cache')->getCollection();
267
 
268
+ foreach ($profileCacheCollection as $profileCache) {
269
+ $profileCache->delete();
270
  }
271
 
272
  $config->unsDatabaseId();
273
+ $config->unsOrdersCollectionId();
274
+ $config->unsOrderItemCollectionId();
275
+ $config->unsAddressCollectionId();
276
+ $config->unsViewedProductCollectionId();
277
+ $config->unsQuoteItemCollectionId();
278
+ $config->unsWishlistItemCollectionId();
279
+
280
  $config->setDatabaseName($post['name']);
281
 
282
  $fields = array();
338
  $config->setLinkedQuoteItemFields($fields);
339
  break;
340
 
341
+ case 'wishlistproducts':
342
  $config->unsWishlistItemCollectionId();
343
  $config->setWishlistItemCollectionName($post['name']);
344
+ $config->setLinkedWishlistItemFields($fields);
345
+ break;
346
  }
347
  break;
348
  }
368
 
369
  $profileCacheCollection = Mage::getModel('marketingsoftware/profile_cache')->getCollection();
370
 
371
+ foreach ($profileCacheCollection as $profileCache) {
372
+ $profileCache->delete();
373
  }
374
 
375
  $supportedFields = $data->supportedCustomerFields();
385
  /*
386
  * Quote items collection
387
  */
388
+ $builder->createCollection($databaseName, 'Cart_Items', 'cartproducts');
389
  $config->setQuoteItemCollectionName('Cart_Items');
390
  $supportedFields = $data->supportedQuoteItemFields();
391
  $linkedFields = array();
400
  /*
401
  * Orders collection
402
  */
403
+ $builder->createCollection($databaseName, 'Orders', 'orders');
404
  $config->setOrdersCollectionName('Orders');
405
  $supportedFields = $data->supportedOrderFields();
406
  $linkedFields = array();
415
  /*
416
  * Orders items collection
417
  */
418
+ $builder->createCollection($databaseName, 'Orders_Items', 'orderproducts');
419
  $config->setOrderItemCollectionName('Orders_Items');
420
  $supportedFields = $data->supportedOrderItemFields();
421
  $linkedFields = array();
430
  /*
431
  * Addresses collection
432
  */
433
+ $builder->createCollection($databaseName, 'Addresses', 'addresses');
434
  $config->setAddressCollectionName('Addresses');
435
  $supportedFields = $data->supportedAddressFields();
436
  $linkedFields = array();
445
  /*
446
  * Viewed products collection
447
  */
448
+ $builder->createCollection($databaseName, 'Viewed_Products', 'viewedproducts');
449
  $config->setViewedProductCollectionName('Viewed_Products');
450
  $supportedFields = $data->supportedViewedProductFields();
451
  $linkedFields = array();
460
  /*
461
  * Wishlist items collection
462
  */
463
+ $builder->createCollection($databaseName, 'Wishlist_Items', 'wishlistproducts');
464
  $config->setWishlistItemCollectionName('Wishlist_Items');
465
  $supportedFields = $data->supportedWishlistItemFields();
466
  $linkedFields = array();
467
 
468
  foreach ($supportedFields as $name => $label) {
469
+ $builder->createCollectionField($databaseName, 'Wishlist_Items', 'wishlistproducts', $name, $name);
470
+ $linkedFields[$name] = $name;
471
  }
472
 
473
  $config->setLinkedWishlistItemFields($linkedFields);
474
  }
475
+ }
app/code/community/Copernica/MarketingSoftware/controllers/Adminhtml/Marketingsoftware/ExportController.php CHANGED
@@ -30,17 +30,17 @@
30
  */
31
  class Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_ExportController extends Copernica_MarketingSoftware_Controller_Action
32
  {
33
- /**
34
- * Check if cache management is allowed
35
- *
36
- * @return bool
37
- */
38
- protected function _isAllowed()
39
- {
40
- return Mage::getSingleton('admin/session')->isAllowed('copernica/export');
41
- }
42
-
43
-
44
  /**
45
  * Takes care of displaying the form which
46
  * contains the details used for the SOAP connection.
@@ -116,7 +116,7 @@ class Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_ExportController e
116
  Mage::getSingleton('adminhtml/session')
117
  ->addError('A synchronization has already been scheduled, please be patient for it to finish.');
118
  } else {
119
- $this->_startSync();
120
  }
121
 
122
  return $this->_redirect('*/*');
@@ -136,7 +136,7 @@ class Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_ExportController e
136
  $syncStatus = Mage::getModel('marketingsoftware/sync_status');
137
 
138
  if ($enabledStores = $config->getEnabledStores()) {
139
- $syncStatus->setStoresFilter($enabledStores);
140
  }
141
 
142
  $queue = Mage::getModel('marketingsoftware/queue_item')
@@ -147,4 +147,4 @@ class Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_ExportController e
147
 
148
  Mage::getSingleton('adminhtml/session')->addSuccess("The synchronization process has been scheduled!");
149
  }
150
- }
30
  */
31
  class Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_ExportController extends Copernica_MarketingSoftware_Controller_Action
32
  {
33
+ /**
34
+ * Check if cache management is allowed
35
+ *
36
+ * @return bool
37
+ */
38
+ protected function _isAllowed()
39
+ {
40
+ return Mage::getSingleton('admin/session')->isAllowed('copernica/export');
41
+ }
42
+
43
+
44
  /**
45
  * Takes care of displaying the form which
46
  * contains the details used for the SOAP connection.
116
  Mage::getSingleton('adminhtml/session')
117
  ->addError('A synchronization has already been scheduled, please be patient for it to finish.');
118
  } else {
119
+ $this->_startSync();
120
  }
121
 
122
  return $this->_redirect('*/*');
136
  $syncStatus = Mage::getModel('marketingsoftware/sync_status');
137
 
138
  if ($enabledStores = $config->getEnabledStores()) {
139
+ $syncStatus->setStoresFilter($enabledStores);
140
  }
141
 
142
  $queue = Mage::getModel('marketingsoftware/queue_item')
147
 
148
  Mage::getSingleton('adminhtml/session')->addSuccess("The synchronization process has been scheduled!");
149
  }
150
+ }
app/code/community/Copernica/MarketingSoftware/controllers/Adminhtml/Marketingsoftware/LinkController.php CHANGED
@@ -30,16 +30,16 @@
30
  */
31
  class Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_LinkController extends Copernica_MarketingSoftware_Controller_Action
32
  {
33
- /**
34
- * Check if cache management is allowed
35
- *
36
- * @return bool
37
- */
38
- protected function _isAllowed()
39
- {
40
- return Mage::getSingleton('admin/session')->isAllowed('copernica/links');
41
- }
42
-
43
  /**
44
  * indexAction() takes care of displaying the form which
45
  * contains the details used for the SOAP connection
@@ -67,7 +67,7 @@ class Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_LinkController ext
67
 
68
  /**
69
  * This action will save all form data.
70
- * @todo Never used, Ajaxcollection is always called to perform the save per collection.
71
  */
72
  public function saveFormAction()
73
  {
@@ -75,11 +75,11 @@ class Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_LinkController ext
75
  $post = json_decode($post['data'], true);
76
 
77
  if (isset($post['database']['name'])) {
78
- $this->_saveDatabaseData($post['database']);
79
  }
80
 
81
  if (isset($post['collections'])) {
82
- $this->_saveCollections($post['collections']);
83
  }
84
 
85
  $this->_setResponse();
@@ -88,7 +88,7 @@ class Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_LinkController ext
88
  /**
89
  * This method will save database related informations.
90
  *
91
- * @param assoc $data
92
  */
93
  protected function _saveDatabaseData($data)
94
  {
@@ -112,7 +112,7 @@ class Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_LinkController ext
112
  /**
113
  * This method will save database fields
114
  *
115
- * @param assoc $data
116
  */
117
  protected function _saveDatabaseFields($data)
118
  {
@@ -122,7 +122,7 @@ class Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_LinkController ext
122
  /**
123
  * This method will save all collections from data
124
  *
125
- * @param assoc $data
126
  */
127
  protected function _saveCollections($data)
128
  {
@@ -131,30 +131,30 @@ class Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_LinkController ext
131
  $config->clearLinkedCollections();
132
 
133
  if (isset($data['cartproducts'])) {
134
- $this->_saveQuoteProductsCollection($data['cartproducts']);
135
  }
136
 
137
  if (isset($data['orders'])) {
138
- $this->_saveOrdersCollection($data['orders']);
139
  }
140
 
141
  if (isset($data['orderproducts'])) {
142
- $this->_saveOrderItemsCollection($data['orderproducts']);
143
  }
144
 
145
  if (isset($data['addresses'])) {
146
- $this->_saveAddressesCollection($data['addresses']);
147
  }
148
 
149
  if (isset($data['viewedproduct'])) {
150
- $this->_saveViewedProductsCollection($data['viewedproduct']);
151
  }
152
  }
153
 
154
  /**
155
  * Save cart products info
156
  *
157
- * @param assoc $data
158
  */
159
  protected function _saveQuoteProductsCollection($data)
160
  {
@@ -169,7 +169,7 @@ class Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_LinkController ext
169
  /**
170
  * Save order collection info
171
  *
172
- * @param assoc $data
173
  */
174
  protected function _saveOrdersCollection($data)
175
  {
@@ -184,7 +184,7 @@ class Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_LinkController ext
184
  /**
185
  * Save order items collection info
186
  *
187
- * @param assoc $data
188
  */
189
  protected function _saveOrderItemsCollection($data)
190
  {
@@ -199,7 +199,7 @@ class Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_LinkController ext
199
  /**
200
  * Save addresses collection info
201
  *
202
- * @param assoc $data
203
  */
204
  protected function _saveAddressesCollection($data)
205
  {
@@ -214,7 +214,7 @@ class Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_LinkController ext
214
  /**
215
  * Save viewed products collection info
216
  *
217
- * @param assoc $data
218
  */
219
  protected function _saveViewedProductsCollection($data)
220
  {
@@ -237,14 +237,18 @@ class Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_LinkController ext
237
  }
238
 
239
  /**
240
- * @param bool $error
241
  */
242
  protected function _setResponse($error = false)
243
  {
244
  $this->_prepareAjaxResponse();
245
 
246
- $this->getResponse()->setBody(json_encode(Array(
247
- 'error' => $error ? 1 : 0
248
- )));
 
 
 
 
249
  }
250
- }
30
  */
31
  class Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_LinkController extends Copernica_MarketingSoftware_Controller_Action
32
  {
33
+ /**
34
+ * Check if cache management is allowed
35
+ *
36
+ * @return bool
37
+ */
38
+ protected function _isAllowed()
39
+ {
40
+ return Mage::getSingleton('admin/session')->isAllowed('copernica/links');
41
+ }
42
+
43
  /**
44
  * indexAction() takes care of displaying the form which
45
  * contains the details used for the SOAP connection
67
 
68
  /**
69
  * This action will save all form data.
70
+ * @todo Never used, Ajaxcollection is always called to perform the save per collection.
71
  */
72
  public function saveFormAction()
73
  {
75
  $post = json_decode($post['data'], true);
76
 
77
  if (isset($post['database']['name'])) {
78
+ $this->_saveDatabaseData($post['database']);
79
  }
80
 
81
  if (isset($post['collections'])) {
82
+ $this->_saveCollections($post['collections']);
83
  }
84
 
85
  $this->_setResponse();
88
  /**
89
  * This method will save database related informations.
90
  *
91
+ * @param assoc $data
92
  */
93
  protected function _saveDatabaseData($data)
94
  {
112
  /**
113
  * This method will save database fields
114
  *
115
+ * @param assoc $data
116
  */
117
  protected function _saveDatabaseFields($data)
118
  {
122
  /**
123
  * This method will save all collections from data
124
  *
125
+ * @param assoc $data
126
  */
127
  protected function _saveCollections($data)
128
  {
131
  $config->clearLinkedCollections();
132
 
133
  if (isset($data['cartproducts'])) {
134
+ $this->_saveQuoteProductsCollection($data['cartproducts']);
135
  }
136
 
137
  if (isset($data['orders'])) {
138
+ $this->_saveOrdersCollection($data['orders']);
139
  }
140
 
141
  if (isset($data['orderproducts'])) {
142
+ $this->_saveOrderItemsCollection($data['orderproducts']);
143
  }
144
 
145
  if (isset($data['addresses'])) {
146
+ $this->_saveAddressesCollection($data['addresses']);
147
  }
148
 
149
  if (isset($data['viewedproduct'])) {
150
+ $this->_saveViewedProductsCollection($data['viewedproduct']);
151
  }
152
  }
153
 
154
  /**
155
  * Save cart products info
156
  *
157
+ * @param assoc $data
158
  */
159
  protected function _saveQuoteProductsCollection($data)
160
  {
169
  /**
170
  * Save order collection info
171
  *
172
+ * @param assoc $data
173
  */
174
  protected function _saveOrdersCollection($data)
175
  {
184
  /**
185
  * Save order items collection info
186
  *
187
+ * @param assoc $data
188
  */
189
  protected function _saveOrderItemsCollection($data)
190
  {
199
  /**
200
  * Save addresses collection info
201
  *
202
+ * @param assoc $data
203
  */
204
  protected function _saveAddressesCollection($data)
205
  {
214
  /**
215
  * Save viewed products collection info
216
  *
217
+ * @param assoc $data
218
  */
219
  protected function _saveViewedProductsCollection($data)
220
  {
237
  }
238
 
239
  /**
240
+ * @param bool $error
241
  */
242
  protected function _setResponse($error = false)
243
  {
244
  $this->_prepareAjaxResponse();
245
 
246
+ $this->getResponse()->setBody(
247
+ json_encode(
248
+ Array(
249
+ 'error' => $error ? 1 : 0
250
+ )
251
+ )
252
+ );
253
  }
254
+ }
app/code/community/Copernica/MarketingSoftware/controllers/Adminhtml/Marketingsoftware/SettingsController.php CHANGED
@@ -30,16 +30,16 @@
30
  */
31
  class Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_SettingsController extends Copernica_MarketingSoftware_Controller_Action
32
  {
33
- /**
34
- * Check if cache management is allowed
35
- *
36
- * @return bool
37
- */
38
- protected function _isAllowed()
39
- {
40
- return Mage::getSingleton('admin/session')->isAllowed('copernica/settings');
41
- }
42
-
43
  /**
44
  * indexAction() takes care of displaying the form which
45
  * contains the details used for the SOAP connection
@@ -74,12 +74,12 @@ class Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_SettingsController
74
  */
75
  public function stateAction()
76
  {
77
- $session = Mage::getSingleton('adminhtml/session');
78
-
79
  $state = $this->getRequest()->getParam('state');
80
 
81
  if ($state != $session->getState()) {
82
- return $this->_redirect('*/*', array('response' => 'invalid-state'));
83
  }
84
 
85
  $code = $this->getRequest()->getParam('code');
@@ -90,7 +90,7 @@ class Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_SettingsController
90
  Mage::helper('marketingsoftware/config')->getClientKey(),
91
  Mage::helper('marketingsoftware/config')->getClientSecret(),
92
  Mage::helper('adminhtml')->getUrl('*/*/state'),
93
- $code
94
  );
95
 
96
  if ($accessToken === false) {
@@ -141,21 +141,21 @@ class Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_SettingsController
141
 
142
  if (isset($post['chk-store-disable'])) {
143
  $config->setEnabledStores(null);
144
-
145
  Mage::getSingleton('core/session')->addSuccess('Stores settings have been saved');
146
- session_write_close(); // To make sure the success message is passed
147
-
148
  return $this->_redirect('*/*');
149
  }
150
-
151
- $enabledStores = array();
152
-
153
- if(isset($post['store'])) {
154
- foreach($post['store'] as $store) {
155
- $enabledStores[] = $store;
156
- }
157
- }
158
-
159
  $config->setEnabledStores($enabledStores);
160
 
161
  Mage::getSingleton('core/session')->addSuccess('Stores settings have been saved');
@@ -194,11 +194,11 @@ class Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_SettingsController
194
  $clientSecret = $config->getClientSecret();
195
 
196
  if ($clientKey == $post['cp_client_key'] && $clientSecret == $post['cp_client_secret']) {
197
- return $this->_redirect('*/*');
198
  }
199
 
200
  if (!isset($post['cp_client_key'])) {
201
- return $this->_redirect('*/*');
202
  }
203
 
204
  $config->setClientKey($post['cp_client_key']);
@@ -210,4 +210,4 @@ class Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_SettingsController
210
 
211
  return $this->_redirect('*/*');
212
  }
213
- }
30
  */
31
  class Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_SettingsController extends Copernica_MarketingSoftware_Controller_Action
32
  {
33
+ /**
34
+ * Check if cache management is allowed
35
+ *
36
+ * @return bool
37
+ */
38
+ protected function _isAllowed()
39
+ {
40
+ return Mage::getSingleton('admin/session')->isAllowed('copernica/settings');
41
+ }
42
+
43
  /**
44
  * indexAction() takes care of displaying the form which
45
  * contains the details used for the SOAP connection
74
  */
75
  public function stateAction()
76
  {
77
+ $session = Mage::getSingleton('adminhtml/session');
78
+
79
  $state = $this->getRequest()->getParam('state');
80
 
81
  if ($state != $session->getState()) {
82
+ return $this->_redirect('*/*', array('response' => 'invalid-state'));
83
  }
84
 
85
  $code = $this->getRequest()->getParam('code');
90
  Mage::helper('marketingsoftware/config')->getClientKey(),
91
  Mage::helper('marketingsoftware/config')->getClientSecret(),
92
  Mage::helper('adminhtml')->getUrl('*/*/state'),
93
+ $code
94
  );
95
 
96
  if ($accessToken === false) {
141
 
142
  if (isset($post['chk-store-disable'])) {
143
  $config->setEnabledStores(null);
144
+
145
  Mage::getSingleton('core/session')->addSuccess('Stores settings have been saved');
146
+ session_write_close(); // To make sure the success message is passed
147
+
148
  return $this->_redirect('*/*');
149
  }
150
+
151
+ $enabledStores = array();
152
+
153
+ if (isset($post['store'])) {
154
+ foreach ($post['store'] as $store) {
155
+ $enabledStores[] = $store;
156
+ }
157
+ }
158
+
159
  $config->setEnabledStores($enabledStores);
160
 
161
  Mage::getSingleton('core/session')->addSuccess('Stores settings have been saved');
194
  $clientSecret = $config->getClientSecret();
195
 
196
  if ($clientKey == $post['cp_client_key'] && $clientSecret == $post['cp_client_secret']) {
197
+ return $this->_redirect('*/*');
198
  }
199
 
200
  if (!isset($post['cp_client_key'])) {
201
+ return $this->_redirect('*/*');
202
  }
203
 
204
  $config->setClientKey($post['cp_client_key']);
210
 
211
  return $this->_redirect('*/*');
212
  }
213
+ }
app/code/community/Copernica/MarketingSoftware/controllers/Adminhtml/Marketingsoftware/SyncController.php CHANGED
@@ -30,17 +30,17 @@
30
  */
31
  class Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_SyncController extends Copernica_MarketingSoftware_Controller_Action
32
  {
33
-
34
- /**
35
- * Check if cache management is allowed
36
- *
37
- * @return bool
38
- */
39
- protected function _isAllowed()
40
- {
41
- return Mage::getSingleton('admin/session')->isAllowed('copernica/sync');
42
- }
43
-
44
  /**
45
  * This action is a default one. Will be executed when user arrives on page.
46
  */
@@ -72,7 +72,7 @@ class Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_SyncController ext
72
  $syncProfile = Mage::getModel('marketingsoftware/sync_profile');
73
 
74
  if (array_key_exists('id', $post) && $post['id']) {
75
- $syncProfile->load($post['id']);
76
  }
77
 
78
  $syncProfile
@@ -96,11 +96,13 @@ class Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_SyncController ext
96
  foreach (Mage::app()->getWebsites() as $website) {
97
  foreach ($website->getGroups() as $group) {
98
  foreach ($group->getStores() as $store) {
99
- $stores[$store->getId()] = implode(' > ', array(
 
100
  $website->getName(),
101
  $group->getName(),
102
  $store->getName()
103
- ));
 
104
  }
105
  }
106
  }
@@ -127,7 +129,7 @@ class Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_SyncController ext
127
 
128
  $this->getResponse()->setBody(json_encode(array_merge($profile->toArray(), array('state' => $state, 'stores' => $stores))));
129
  } else {
130
- $this->getResponse()->setBody(json_encode('error'));
131
  }
132
  }
133
 
@@ -139,11 +141,11 @@ class Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_SyncController ext
139
  $post = $this->getRequest()->getPost();
140
 
141
  if (array_key_exists('id', $post)) {
142
- Mage::getModel('marketingsoftware/sync_profile')
143
  ->load($post['id'])
144
  ->delete();
145
  } else {
146
- $this->getResponse()->setBody(json_encode('error'));
147
  }
148
 
149
  }
@@ -158,16 +160,16 @@ class Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_SyncController ext
158
  $params = $this->getRequest()->getParams();
159
 
160
  if (!array_key_exists('state', $params)) {
161
- return $this->_redirect('*/*', array('result' => 'invalid-state'));
162
  }
163
 
164
  if (!array_key_exists('code', $params)) {
165
- return $this->_redirect('*/*', array('result' => 'invalid-code'));
166
  }
167
 
168
  foreach (Mage::getModel('marketingsoftware/sync_profile')->getCollection() as $profile) {
169
- if ($params['state'] != md5(Mage::getSingleton('adminhtml/session')->getEncryptedSessionId().date('dmY').$profile->getId())) {
170
- continue;
171
  }
172
 
173
  $accessToken = Mage::helper('marketingsoftware/api')->upgradeRequest(
@@ -178,7 +180,7 @@ class Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_SyncController ext
178
  );
179
 
180
  if ($accessToken == false) {
181
- return $this->_redirect('*/*', array('result' => 'invalid-token'));
182
  }
183
 
184
  $profile->setAccessToken($accessToken)->save();
30
  */
31
  class Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_SyncController extends Copernica_MarketingSoftware_Controller_Action
32
  {
33
+
34
+ /**
35
+ * Check if cache management is allowed
36
+ *
37
+ * @return bool
38
+ */
39
+ protected function _isAllowed()
40
+ {
41
+ return Mage::getSingleton('admin/session')->isAllowed('copernica/sync');
42
+ }
43
+
44
  /**
45
  * This action is a default one. Will be executed when user arrives on page.
46
  */
72
  $syncProfile = Mage::getModel('marketingsoftware/sync_profile');
73
 
74
  if (array_key_exists('id', $post) && $post['id']) {
75
+ $syncProfile->load($post['id']);
76
  }
77
 
78
  $syncProfile
96
  foreach (Mage::app()->getWebsites() as $website) {
97
  foreach ($website->getGroups() as $group) {
98
  foreach ($group->getStores() as $store) {
99
+ $stores[$store->getId()] = implode(
100
+ ' > ', array(
101
  $website->getName(),
102
  $group->getName(),
103
  $store->getName()
104
+ )
105
+ );
106
  }
107
  }
108
  }
129
 
130
  $this->getResponse()->setBody(json_encode(array_merge($profile->toArray(), array('state' => $state, 'stores' => $stores))));
131
  } else {
132
+ $this->getResponse()->setBody(json_encode('error'));
133
  }
134
  }
135
 
141
  $post = $this->getRequest()->getPost();
142
 
143
  if (array_key_exists('id', $post)) {
144
+ Mage::getModel('marketingsoftware/sync_profile')
145
  ->load($post['id'])
146
  ->delete();
147
  } else {
148
+ $this->getResponse()->setBody(json_encode('error'));
149
  }
150
 
151
  }
160
  $params = $this->getRequest()->getParams();
161
 
162
  if (!array_key_exists('state', $params)) {
163
+ return $this->_redirect('*/*', array('result' => 'invalid-state'));
164
  }
165
 
166
  if (!array_key_exists('code', $params)) {
167
+ return $this->_redirect('*/*', array('result' => 'invalid-code'));
168
  }
169
 
170
  foreach (Mage::getModel('marketingsoftware/sync_profile')->getCollection() as $profile) {
171
+ if ($params['state'] != md5(Mage::getSingleton('adminhtml/session')->getEncryptedSessionId().date('dmY').$profile->getId())) {
172
+ continue;
173
  }
174
 
175
  $accessToken = Mage::helper('marketingsoftware/api')->upgradeRequest(
180
  );
181
 
182
  if ($accessToken == false) {
183
+ return $this->_redirect('*/*', array('result' => 'invalid-token'));
184
  }
185
 
186
  $profile->setAccessToken($accessToken)->save();
app/code/community/Copernica/MarketingSoftware/controllers/CartController.php CHANGED
@@ -28,30 +28,32 @@
28
  * Marketing software cart controller
29
  */
30
  class Copernica_MarketingSoftware_CartController extends Mage_Core_Controller_Front_Action
31
- {
32
- public function resumeAction()
33
- {
34
- $emailAddress = $this->getRequest()->getParam('email');
35
- $quoteId = $this->getRequest()->getParam('quote_id');
36
-
37
- /* @var $quote Mage_Sales_Model_Quote */
38
- $quote = Mage::getModel('sales/quote')->load($quoteId);
39
-
40
- if ($quote->getCustomerEmail() == $emailAddress) {
41
- Mage::getSingleton('checkout/session')->replaceQuote($quote);
42
-
43
- $customer = Mage::getModel('customer/customer')
44
- ->setWebsiteId(Mage::app()->getStore()->getWebsiteId())
45
- ->loadByEmail($emailAddress);
46
-
47
- if ($customerId = $customer->getId()) {
48
- $session = Mage::getSingleton('customer/session');
49
- if ($session->isLoggedIn() && $customerId != $session->getCustomerId()) {
50
- $session->logout();
51
- }
52
- }
53
- }
54
-
55
- $this->getResponse()->setRedirect(Mage::getUrl('checkout/cart'));
56
- }
57
- }
 
 
28
  * Marketing software cart controller
29
  */
30
  class Copernica_MarketingSoftware_CartController extends Mage_Core_Controller_Front_Action
31
+ {
32
+ public function resumeAction()
33
+ {
34
+ $emailAddress = $this->getRequest()->getParam('email');
35
+ $quoteId = $this->getRequest()->getParam('quote_id');
36
+
37
+ /* @var $quote Mage_Sales_Model_Quote */
38
+ $quote = Mage::getModel('sales/quote')->load($quoteId);
39
+ $quote->setIsActive(true);
40
+ $quote->save();
41
+
42
+ if ($quote->getCustomerEmail() == $emailAddress) {
43
+ Mage::getSingleton('checkout/session')->replaceQuote($quote);
44
+
45
+ $customer = Mage::getModel('customer/customer')
46
+ ->setWebsiteId(Mage::app()->getStore()->getWebsiteId())
47
+ ->loadByEmail($emailAddress);
48
+
49
+ if ($customerId = $customer->getId()) {
50
+ $session = Mage::getSingleton('customer/session');
51
+ if ($session->isLoggedIn() && $customerId != $session->getCustomerId()) {
52
+ $session->logout();
53
+ }
54
+ }
55
+ }
56
+
57
+ $this->getResponse()->setRedirect(Mage::getUrl('checkout/cart'));
58
+ }
59
+ }
app/code/community/Copernica/MarketingSoftware/controllers/ProductController.php CHANGED
@@ -28,7 +28,8 @@
28
  * Controls the product actions.
29
  */
30
  class Copernica_MarketingSoftware_ProductController extends Mage_Core_Controller_Front_Action
31
- {
 
32
  /**
33
  * The DOM document that will be used to return XML content.
34
  *
@@ -52,12 +53,12 @@ class Copernica_MarketingSoftware_ProductController extends Mage_Core_Controller
52
  $product = Mage::getModel('catalog/product')->load($productId);
53
 
54
  if ($product->getId() && $product->getStatus() == Mage_Catalog_Model_Product_Status::STATUS_ENABLED) {
55
- $productEntity = Mage::getModel('marketingsoftware/copernica_entity_product');
56
- $productEntity->setProduct($product->getId());
57
 
58
- $xml = $this->_buildProductXML($productEntity);
59
  } else {
60
- $xml = $this->_buildErrorXml("Product not found with ID: ". $request->getParam('id'));
61
  }
62
 
63
  $this->_prepareResponse($xml);
@@ -66,8 +67,8 @@ class Copernica_MarketingSoftware_ProductController extends Mage_Core_Controller
66
  /**
67
  * This is a helper method to append simple nodes to document tree
68
  *
69
- * @param DOMElement $parent
70
- * @param string $name
71
  * @param mixed $value
72
  */
73
  protected function _appendSimpleNode(DOMElement $parent, $name, $value)
@@ -83,16 +84,20 @@ class Copernica_MarketingSoftware_ProductController extends Mage_Core_Controller
83
  $today = date('Y-m-d H:i:s');
84
 
85
  $collection = Mage::getResourceModel('catalog/product_collection');
86
- $collection->addAttributeToFilter('news_from_date', array (
 
87
  'date' => true,
88
  'to' => $today
89
- ));
90
- $collection->addAttributeToFilter('news_to_date', array (
 
 
91
  'or' => array (
92
  array ('date' => true, 'from' => $todayDate),
93
  array ('is' => new Zend_Db_Expr('null'))
94
  ), 'left'
95
- ));
 
96
  $collection->addAttributeToSelect('id');
97
 
98
  $xml = $this->_buildCollectionXML($collection);
@@ -102,18 +107,18 @@ class Copernica_MarketingSoftware_ProductController extends Mage_Core_Controller
102
 
103
  protected function _buildErrorXml($message)
104
  {
105
- $element = $this->_document->createElement('error');
106
- $this->_appendSimpleNode($element, 'message', $message);
107
- return $element;
108
  }
109
-
110
 
111
  /**
112
  * Prepare xml tree for one product instance.
113
  *
114
- * @param Copernica_MarketingSoftware_Model_Copernica_Entity_Product $product
115
- * @param bool $noParents
116
- * @param bool $noChildren
117
  * @return DOMElement
118
  */
119
  protected function _buildProductXML(Copernica_MarketingSoftware_Model_Copernica_Entity_Product $product, $noParents = false, $noChildren = false)
@@ -147,11 +152,11 @@ class Copernica_MarketingSoftware_ProductController extends Mage_Core_Controller
147
  $element->appendChild($this->_buildAttributesXML($product));
148
 
149
  if (!$noParents) {
150
- $element->appendChild($this->_buildParentsXML($product));
151
  }
152
 
153
  if (!$noChildren) {
154
- $element->appendChild($this->_buildChildrenXML($product));
155
  }
156
 
157
  return $element;
@@ -160,7 +165,7 @@ class Copernica_MarketingSoftware_ProductController extends Mage_Core_Controller
160
  /**
161
  * Build product categories XML
162
  *
163
- * @param Copernica_MarketingSoftware_Model_Copernica_Entity_Product $product
164
  * @return DOMElement
165
  */
166
  protected function _buildCategoriesXML(Copernica_MarketingSoftware_Model_Copernica_Entity_Product $product)
@@ -179,7 +184,7 @@ class Copernica_MarketingSoftware_ProductController extends Mage_Core_Controller
179
  /**
180
  * Build product attributes XML
181
  *
182
- * @param Copernica_MarketingSoftware_Model_Copernica_Entity_Product $product
183
  * @return DOMElement
184
  */
185
  protected function _buildAttributesXML(Copernica_MarketingSoftware_Model_Copernica_Entity_Product $product)
@@ -201,25 +206,25 @@ class Copernica_MarketingSoftware_ProductController extends Mage_Core_Controller
201
  /**
202
  * Build parents xml
203
  *
204
- * @param Copernica_MarketingSoftware_Model_Copernica_Entity_Product $product
205
  * @return DOMElement
206
  */
207
  protected function _buildParentsXML(Copernica_MarketingSoftware_Model_Copernica_Entity_Product $product)
208
  {
209
  $parentIds = array();
210
 
211
- foreach(Mage_Catalog_Model_Product_Type::getTypes() as $type) {
212
  $result = Mage::getModel($type['model'])->getParentIdsByChild($product->getId());
213
- $parentIds = array_unique(array_merge( $parentIds, $result));
214
  }
215
 
216
  $parents = $this->_document->createElement('parents');
217
 
218
  foreach ($parentIds as $id) {
219
- $product = Mage::getModel('marketingsoftware/copernica_entity_product');
220
- $product->setProduct($id);
221
-
222
- $parents->appendChild($this->_buildProductXML($product, false, true));
223
  }
224
 
225
  return $parents;
@@ -228,7 +233,7 @@ class Copernica_MarketingSoftware_ProductController extends Mage_Core_Controller
228
  /**
229
  * Build children xml
230
  *
231
- * @param Copernica_MarketingSoftware_Model_Copernica_Entity_Product $product
232
  * @return DOMElement
233
  */
234
  protected function _buildChildrenXML(Copernica_MarketingSoftware_Model_Copernica_Entity_Product $product)
@@ -241,9 +246,9 @@ class Copernica_MarketingSoftware_ProductController extends Mage_Core_Controller
241
  $group = $this->_document->createElement('group');
242
 
243
  foreach ($groupIds as $id) {
244
- $product = Mage::getModel('marketingsoftware/copernica_entity_product');
245
- $product->setProduct($id);
246
-
247
  $group->appendChild($this->_buildProductXML($product, true, false));
248
  }
249
 
@@ -256,7 +261,7 @@ class Copernica_MarketingSoftware_ProductController extends Mage_Core_Controller
256
  /**
257
  * Prepare XML tree for whole collection of products.
258
  *
259
- * @param Mage_Catalog_Model_Resource_Product_Collection $collection
260
  * @return DOMElement
261
  */
262
  protected function _buildCollectionXML(Mage_Catalog_Model_Resource_Product_Collection $collection)
@@ -277,7 +282,7 @@ class Copernica_MarketingSoftware_ProductController extends Mage_Core_Controller
277
  /**
278
  * Prepare response based on passed element.
279
  *
280
- * @param DOMElement $element
281
  */
282
  protected function _prepareResponse(DOMElement $element)
283
  {
@@ -321,13 +326,13 @@ class Copernica_MarketingSoftware_ProductController extends Mage_Core_Controller
321
  $this->_document = new DOMDocument('1.0', 'utf-8');
322
 
323
  if ($request->getParam('new')) {
324
- return $this->_showCollection();
325
  }
326
 
327
  if ($request->getParam('id')) {
328
- return $this->_showProduct();
329
  }
330
 
331
  $this->norouteAction();
332
  }
333
- }
28
  * Controls the product actions.
29
  */
30
  class Copernica_MarketingSoftware_ProductController extends Mage_Core_Controller_Front_Action
31
+ {
32
+
33
  /**
34
  * The DOM document that will be used to return XML content.
35
  *
53
  $product = Mage::getModel('catalog/product')->load($productId);
54
 
55
  if ($product->getId() && $product->getStatus() == Mage_Catalog_Model_Product_Status::STATUS_ENABLED) {
56
+ $productEntity = Mage::getModel('marketingsoftware/copernica_entity_product');
57
+ $productEntity->setProduct($product->getId());
58
 
59
+ $xml = $this->_buildProductXML($productEntity);
60
  } else {
61
+ $xml = $this->_buildErrorXml("Product not found with ID: ". $request->getParam('id'));
62
  }
63
 
64
  $this->_prepareResponse($xml);
67
  /**
68
  * This is a helper method to append simple nodes to document tree
69
  *
70
+ * @param DOMElement $parent
71
+ * @param string $name
72
  * @param mixed $value
73
  */
74
  protected function _appendSimpleNode(DOMElement $parent, $name, $value)
84
  $today = date('Y-m-d H:i:s');
85
 
86
  $collection = Mage::getResourceModel('catalog/product_collection');
87
+ $collection->addAttributeToFilter(
88
+ 'news_from_date', array (
89
  'date' => true,
90
  'to' => $today
91
+ )
92
+ );
93
+ $collection->addAttributeToFilter(
94
+ 'news_to_date', array (
95
  'or' => array (
96
  array ('date' => true, 'from' => $todayDate),
97
  array ('is' => new Zend_Db_Expr('null'))
98
  ), 'left'
99
+ )
100
+ );
101
  $collection->addAttributeToSelect('id');
102
 
103
  $xml = $this->_buildCollectionXML($collection);
107
 
108
  protected function _buildErrorXml($message)
109
  {
110
+ $element = $this->_document->createElement('error');
111
+ $this->_appendSimpleNode($element, 'message', $message);
112
+ return $element;
113
  }
114
+
115
 
116
  /**
117
  * Prepare xml tree for one product instance.
118
  *
119
+ * @param Copernica_MarketingSoftware_Model_Copernica_Entity_Product $product
120
+ * @param bool $noParents
121
+ * @param bool $noChildren
122
  * @return DOMElement
123
  */
124
  protected function _buildProductXML(Copernica_MarketingSoftware_Model_Copernica_Entity_Product $product, $noParents = false, $noChildren = false)
152
  $element->appendChild($this->_buildAttributesXML($product));
153
 
154
  if (!$noParents) {
155
+ $element->appendChild($this->_buildParentsXML($product));
156
  }
157
 
158
  if (!$noChildren) {
159
+ $element->appendChild($this->_buildChildrenXML($product));
160
  }
161
 
162
  return $element;
165
  /**
166
  * Build product categories XML
167
  *
168
+ * @param Copernica_MarketingSoftware_Model_Copernica_Entity_Product $product
169
  * @return DOMElement
170
  */
171
  protected function _buildCategoriesXML(Copernica_MarketingSoftware_Model_Copernica_Entity_Product $product)
184
  /**
185
  * Build product attributes XML
186
  *
187
+ * @param Copernica_MarketingSoftware_Model_Copernica_Entity_Product $product
188
  * @return DOMElement
189
  */
190
  protected function _buildAttributesXML(Copernica_MarketingSoftware_Model_Copernica_Entity_Product $product)
206
  /**
207
  * Build parents xml
208
  *
209
+ * @param Copernica_MarketingSoftware_Model_Copernica_Entity_Product $product
210
  * @return DOMElement
211
  */
212
  protected function _buildParentsXML(Copernica_MarketingSoftware_Model_Copernica_Entity_Product $product)
213
  {
214
  $parentIds = array();
215
 
216
+ foreach (Mage_Catalog_Model_Product_Type::getTypes() as $type) {
217
  $result = Mage::getModel($type['model'])->getParentIdsByChild($product->getId());
218
+ $parentIds = array_unique(array_merge($parentIds, $result));
219
  }
220
 
221
  $parents = $this->_document->createElement('parents');
222
 
223
  foreach ($parentIds as $id) {
224
+ $product = Mage::getModel('marketingsoftware/copernica_entity_product');
225
+ $product->setProduct($id);
226
+
227
+ $parents->appendChild($this->_buildProductXML($product, false, true));
228
  }
229
 
230
  return $parents;
233
  /**
234
  * Build children xml
235
  *
236
+ * @param Copernica_MarketingSoftware_Model_Copernica_Entity_Product $product
237
  * @return DOMElement
238
  */
239
  protected function _buildChildrenXML(Copernica_MarketingSoftware_Model_Copernica_Entity_Product $product)
246
  $group = $this->_document->createElement('group');
247
 
248
  foreach ($groupIds as $id) {
249
+ $product = Mage::getModel('marketingsoftware/copernica_entity_product');
250
+ $product->setProduct($id);
251
+
252
  $group->appendChild($this->_buildProductXML($product, true, false));
253
  }
254
 
261
  /**
262
  * Prepare XML tree for whole collection of products.
263
  *
264
+ * @param Mage_Catalog_Model_Resource_Product_Collection $collection
265
  * @return DOMElement
266
  */
267
  protected function _buildCollectionXML(Mage_Catalog_Model_Resource_Product_Collection $collection)
282
  /**
283
  * Prepare response based on passed element.
284
  *
285
+ * @param DOMElement $element
286
  */
287
  protected function _prepareResponse(DOMElement $element)
288
  {
326
  $this->_document = new DOMDocument('1.0', 'utf-8');
327
 
328
  if ($request->getParam('new')) {
329
+ return $this->_showCollection();
330
  }
331
 
332
  if ($request->getParam('id')) {
333
+ return $this->_showProduct();
334
  }
335
 
336
  $this->norouteAction();
337
  }
338
+ }
app/code/community/Copernica/MarketingSoftware/controllers/UnsubscribeController.php CHANGED
@@ -48,18 +48,28 @@ class Copernica_MarketingSoftware_UnsubscribeController extends Mage_Core_Contro
48
  $email = $data->profile->fields->$fields['email'];
49
 
50
  $subscriber = Mage::getModel('newsletter/subscriber');
51
-
52
- if (
53
- $subscriber->loadByCustomer($customer)->getId() ||
54
- $subscriber->loadByEmail($email)->getId()
55
- ) {
56
- // we have a valid subscriber object now, so unsubscribe the user
57
- $subscriber->setSubscriberStatus(Mage_Newsletter_Model_Subscriber::STATUS_UNSUBSCRIBED)->save();
58
- echo 'ok';
59
- return;
60
- }
 
 
 
 
 
 
 
 
 
 
61
  }
62
  }
63
  echo 'not ok';
64
  }
65
- }
48
  $email = $data->profile->fields->$fields['email'];
49
 
50
  $subscriber = Mage::getModel('newsletter/subscriber');
51
+ if (
52
+ $subscriber->loadByCustomer($customer)->getId() ||
53
+ $subscriber->loadByEmail($email)->getId()
54
+ ) {
55
+ // we have a valid subscriber object now, so unsubscribe the user
56
+ $subscriber->setSubscriberStatus(Mage_Newsletter_Model_Subscriber::STATUS_UNSUBSCRIBED)->save();
57
+ echo 'ok';
58
+ return;
59
+ } elseif ($customer->getId()) {
60
+ $subscriber->setCustomerId($customer->getId());
61
+ $subscriber->setEmail($email);
62
+ $subscriber->setStoreId($customer->getStoreId());
63
+ $subscriber->setSubscriberStatus(Mage_Newsletter_Model_Subscriber::STATUS_UNSUBSCRIBED)->save();
64
+ echo 'ok';
65
+ } else {
66
+ $subscriber->setEmail($email);
67
+ $subscriber->setStoreId(Mage::app()->getStore()->getId());
68
+ $subscriber->setSubscriberStatus(Mage_Newsletter_Model_Subscriber::STATUS_UNSUBSCRIBED)->save();
69
+ echo 'ok';
70
+ }
71
  }
72
  }
73
  echo 'not ok';
74
  }
75
+ }
app/code/community/Copernica/MarketingSoftware/cron/clearCopernicaDatabase.php CHANGED
@@ -38,7 +38,7 @@ require_once 'app/Mage.php';
38
  umask(0);
39
 
40
  if (!Mage::isInstalled()) {
41
- exit;
42
  }
43
 
44
  Mage::app('admin')->setUseSessionInUrl(false);
@@ -52,5 +52,5 @@ $databaseId = Mage::helper('marketingsoftware/config')->getDatabaseId();
52
  $profiles = $request->get('database/'.$databaseId.'/profiles');
53
 
54
  foreach ($profiles['data'] as $profile) {
55
- $request->delete('profile/'.$profile['ID']);
56
- }
38
  umask(0);
39
 
40
  if (!Mage::isInstalled()) {
41
+ exit;
42
  }
43
 
44
  Mage::app('admin')->setUseSessionInUrl(false);
52
  $profiles = $request->get('database/'.$databaseId.'/profiles');
53
 
54
  foreach ($profiles['data'] as $profile) {
55
+ $request->delete('profile/'.$profile['ID']);
56
+ }
app/code/community/Copernica/MarketingSoftware/cron/detectAbandonedCarts.php CHANGED
@@ -42,7 +42,7 @@ require_once 'app/Mage.php';
42
  umask(0);
43
 
44
  if (!Mage::isInstalled()) {
45
- exit;
46
  }
47
 
48
  Mage::app('admin')->setUseSessionInUrl(false);
@@ -50,4 +50,4 @@ Mage::app('admin')->setUseSessionInUrl(false);
50
  Mage::getConfig()->init();
51
 
52
  $observer = Mage::getModel('marketingsoftware/observer');
53
- $observer->detectAbandonedCarts();
42
  umask(0);
43
 
44
  if (!Mage::isInstalled()) {
45
+ exit;
46
  }
47
 
48
  Mage::app('admin')->setUseSessionInUrl(false);
50
  Mage::getConfig()->init();
51
 
52
  $observer = Mage::getModel('marketingsoftware/observer');
53
+ $observer->detectAbandonedCarts();
app/code/community/Copernica/MarketingSoftware/cron/fullSync.php CHANGED
@@ -38,7 +38,7 @@ require_once 'app/Mage.php';
38
  umask(0);
39
 
40
  if (!Mage::isInstalled()) {
41
- exit;
42
  }
43
 
44
  Mage::app('admin')->setUseSessionInUrl(false);
@@ -52,11 +52,11 @@ $config->setOrderProgressStatus('1945-08-06 08:15:00');
52
  $syncStatus = Mage::getModel('marketingsoftware/sync_status');
53
 
54
  if ($enabledStores = $config->getEnabledStores()) {
55
- $syncStatus->setStoresFilter($enabledStores);
56
  }
57
 
58
  $queue = Mage::getModel('marketingsoftware/queue_item')
59
  ->setObject($syncStatus->toArray())
60
  ->setAction('start_sync')
61
  ->setName('startsync')
62
- ->save();
38
  umask(0);
39
 
40
  if (!Mage::isInstalled()) {
41
+ exit;
42
  }
43
 
44
  Mage::app('admin')->setUseSessionInUrl(false);
52
  $syncStatus = Mage::getModel('marketingsoftware/sync_status');
53
 
54
  if ($enabledStores = $config->getEnabledStores()) {
55
+ $syncStatus->setStoresFilter($enabledStores);
56
  }
57
 
58
  $queue = Mage::getModel('marketingsoftware/queue_item')
59
  ->setObject($syncStatus->toArray())
60
  ->setAction('start_sync')
61
  ->setName('startsync')
62
+ ->save();
app/code/community/Copernica/MarketingSoftware/cron/processQueue.php CHANGED
@@ -75,7 +75,7 @@ try {
75
  $customerId = array_key_exists('c', $cliOptions) ? $cliOptions['c'] : 0;
76
 
77
  if (array_key_exists('customer', $cliOptions)) {
78
- $customerId = $cliOptions['customer'];
79
  }
80
  }
81
 
@@ -91,7 +91,7 @@ try {
91
  $verbose = array_key_exists('v', $cliOptions) ? $cliOptions['v'] : 'TEXT';
92
 
93
  if (array_key_exists('verbose', $cliOptions)) {
94
- $verbose = $cliOptions['verbose'] ? $cliOptions['verbose'] : 'TEXT';
95
  }
96
  }
97
 
@@ -101,7 +101,7 @@ try {
101
  $runtime = array_key_exists('r', $cliOptions) ? $cliOptions['r'] : 45;
102
 
103
  if (array_key_exists('runtime', $cliOptions)) {
104
- $runtime = $cliOptions['runtime'];
105
  }
106
  }
107
 
@@ -110,7 +110,7 @@ try {
110
  umask(0);
111
 
112
  if (!Mage::isInstalled()) {
113
- exit;
114
  }
115
 
116
  Mage::app('admin')->setUseSessionInUrl(false);
@@ -120,13 +120,13 @@ try {
120
  $processor = Mage::getModel('marketingsoftware/queue_processor');
121
 
122
  if ($lock === false) {
123
- $processor->processQueue($customerId);
124
  } else {
125
  $lock = $processor->aqcuireLock();
126
 
127
  if ($lock === false) {
128
  if ($runtime > 0 ) {
129
- sleep($runtime);
130
  }
131
  return;
132
  }
@@ -135,8 +135,8 @@ try {
135
  }
136
 
137
  if ($verbose !== false) {
138
- echo $processor->fetchReport($verbose);
139
  }
140
  } catch (Exception $e) {
141
  print_r($e);
142
- }
75
  $customerId = array_key_exists('c', $cliOptions) ? $cliOptions['c'] : 0;
76
 
77
  if (array_key_exists('customer', $cliOptions)) {
78
+ $customerId = $cliOptions['customer'];
79
  }
80
  }
81
 
91
  $verbose = array_key_exists('v', $cliOptions) ? $cliOptions['v'] : 'TEXT';
92
 
93
  if (array_key_exists('verbose', $cliOptions)) {
94
+ $verbose = $cliOptions['verbose'] ? $cliOptions['verbose'] : 'TEXT';
95
  }
96
  }
97
 
101
  $runtime = array_key_exists('r', $cliOptions) ? $cliOptions['r'] : 45;
102
 
103
  if (array_key_exists('runtime', $cliOptions)) {
104
+ $runtime = $cliOptions['runtime'];
105
  }
106
  }
107
 
110
  umask(0);
111
 
112
  if (!Mage::isInstalled()) {
113
+ exit;
114
  }
115
 
116
  Mage::app('admin')->setUseSessionInUrl(false);
120
  $processor = Mage::getModel('marketingsoftware/queue_processor');
121
 
122
  if ($lock === false) {
123
+ $processor->processQueue($customerId);
124
  } else {
125
  $lock = $processor->aqcuireLock();
126
 
127
  if ($lock === false) {
128
  if ($runtime > 0 ) {
129
+ sleep($runtime);
130
  }
131
  return;
132
  }
135
  }
136
 
137
  if ($verbose !== false) {
138
+ echo $processor->fetchReport($verbose);
139
  }
140
  } catch (Exception $e) {
141
  print_r($e);
142
+ }
app/code/community/Copernica/MarketingSoftware/data/marketingsoftware_setup/data-upgrade-3.4.0-3.4.1.php CHANGED
@@ -34,14 +34,12 @@ return;
34
  $linkedFieldConfigs = array('linked_customer_fields', 'linked_cart_item_fields', 'linked_order_fields', 'linked_order_item_fields', 'linked_address_fields', 'linked_viewed_product_fields');
35
 
36
  // iterate over all linked fields configs
37
- foreach ($linkedFieldConfigs as $config)
38
- {
39
  // get model
40
  $model = Mage::getModel('marketingsoftware/config')->loadByKey($config);
41
 
42
  // we have tocheck if model is ok
43
- if ($model->getId())
44
- {
45
  // get json value
46
  $json = $model->getValue();
47
 
@@ -49,8 +47,7 @@ foreach ($linkedFieldConfigs as $config)
49
  $array = json_decode($json, true);
50
 
51
  // we have to convert all unverscore case keys to camel case keys
52
- foreach ($array as $key => $value)
53
- {
54
  // unset old value
55
  unset($array[$key]);
56
 
@@ -67,4 +64,4 @@ foreach ($linkedFieldConfigs as $config)
67
  // store converted array
68
  $model->setValue(json_encode($array));
69
  }
70
- }
34
  $linkedFieldConfigs = array('linked_customer_fields', 'linked_cart_item_fields', 'linked_order_fields', 'linked_order_item_fields', 'linked_address_fields', 'linked_viewed_product_fields');
35
 
36
  // iterate over all linked fields configs
37
+ foreach ($linkedFieldConfigs as $config) {
 
38
  // get model
39
  $model = Mage::getModel('marketingsoftware/config')->loadByKey($config);
40
 
41
  // we have tocheck if model is ok
42
+ if ($model->getId()) {
 
43
  // get json value
44
  $json = $model->getValue();
45
 
47
  $array = json_decode($json, true);
48
 
49
  // we have to convert all unverscore case keys to camel case keys
50
+ foreach ($array as $key => $value) {
 
51
  // unset old value
52
  unset($array[$key]);
53
 
64
  // store converted array
65
  $model->setValue(json_encode($array));
66
  }
67
+ }
app/code/community/Copernica/MarketingSoftware/etc/config.xml CHANGED
@@ -2,7 +2,7 @@
2
  <config>
3
  <modules>
4
  <Copernica_MarketingSoftware>
5
- <version>3.2.3</version>
6
  </Copernica_MarketingSoftware>
7
  </modules>
8
  <global>
2
  <config>
3
  <modules>
4
  <Copernica_MarketingSoftware>
5
+ <version>3.2.4</version>
6
  </Copernica_MarketingSoftware>
7
  </modules>
8
  <global>
app/code/community/Copernica/MarketingSoftware/sql/marketingsoftware_setup/mysql4-install-1.2.0.php CHANGED
@@ -28,7 +28,8 @@ $installer = $this;
28
 
29
  $installer->startSetup();
30
 
31
- $installer->run("
 
32
  DROP TABLE IF EXISTS `{$installer->getTable('marketingsoftware/queue_item')}`;
33
  CREATE TABLE `{$installer->getTable('marketingsoftware/queue_item')}` (
34
  `id` int(10) unsigned NOT NULL auto_increment,
@@ -39,6 +40,7 @@ CREATE TABLE `{$installer->getTable('marketingsoftware/queue_item')}` (
39
  `result_time` timestamp NULL,
40
  PRIMARY KEY (`id`)
41
  ) ENGINE=InnoDB default CHARSET=utf8;
42
- ");
 
43
 
44
  $installer->endSetup();
28
 
29
  $installer->startSetup();
30
 
31
+ $installer->run(
32
+ "
33
  DROP TABLE IF EXISTS `{$installer->getTable('marketingsoftware/queue_item')}`;
34
  CREATE TABLE `{$installer->getTable('marketingsoftware/queue_item')}` (
35
  `id` int(10) unsigned NOT NULL auto_increment,
40
  `result_time` timestamp NULL,
41
  PRIMARY KEY (`id`)
42
  ) ENGINE=InnoDB default CHARSET=utf8;
43
+ "
44
+ );
45
 
46
  $installer->endSetup();
app/code/community/Copernica/MarketingSoftware/sql/marketingsoftware_setup/mysql4-upgrade-1.1.5-1.1.6.php CHANGED
@@ -33,13 +33,15 @@
33
  $installer = $this;
34
  $installer->startSetup();
35
 
36
- $installer->run("
 
37
  ALTER TABLE {$installer->getTable('copernica_marketingsoftware')}
38
  ADD extensionversion VARCHAR(250) NOT NULL;
39
 
40
  UPDATE {$installer->getTable('copernica_marketingsoftware')}
41
  SET `extensionversion` = '1.1.6'
42
  WHERE 1 = 1;
43
- ");
 
44
 
45
  $installer->endSetup();
33
  $installer = $this;
34
  $installer->startSetup();
35
 
36
+ $installer->run(
37
+ "
38
  ALTER TABLE {$installer->getTable('copernica_marketingsoftware')}
39
  ADD extensionversion VARCHAR(250) NOT NULL;
40
 
41
  UPDATE {$installer->getTable('copernica_marketingsoftware')}
42
  SET `extensionversion` = '1.1.6'
43
  WHERE 1 = 1;
44
+ "
45
+ );
46
 
47
  $installer->endSetup();
app/code/community/Copernica/MarketingSoftware/sql/marketingsoftware_setup/mysql4-upgrade-1.1.6-1.1.7.php CHANGED
@@ -33,10 +33,12 @@
33
  $installer = $this;
34
  $installer->startSetup();
35
 
36
- $installer->run("
 
37
  UPDATE {$installer->getTable('copernica_marketingsoftware')}
38
  SET `extensionversion` = '1.1.7'
39
  WHERE 1 = 1;
40
- ");
 
41
 
42
  $installer->endSetup();
33
  $installer = $this;
34
  $installer->startSetup();
35
 
36
+ $installer->run(
37
+ "
38
  UPDATE {$installer->getTable('copernica_marketingsoftware')}
39
  SET `extensionversion` = '1.1.7'
40
  WHERE 1 = 1;
41
+ "
42
+ );
43
 
44
  $installer->endSetup();
app/code/community/Copernica/MarketingSoftware/sql/marketingsoftware_setup/mysql4-upgrade-1.1.7-1.1.8.php CHANGED
@@ -33,7 +33,8 @@
33
  $installer = $this;
34
  $installer->startSetup();
35
 
36
- $installer->run("
 
37
  ALTER TABLE {$installer->getTable('copernica_marketingsoftware')}
38
  ADD login_valid ENUM('yes', 'no') NOT NULL default 'yes',
39
  ADD linked_fields_valid ENUM('yes', 'no') NOT NULL default 'no',
@@ -44,6 +45,7 @@ $installer->run("
44
 
45
  UPDATE {$installer->getTable('copernica_marketingsoftware')}
46
  SET progressstatus = 'none', addresscollectionname = '';
47
- ");
 
48
 
49
  $installer->endSetup();
33
  $installer = $this;
34
  $installer->startSetup();
35
 
36
+ $installer->run(
37
+ "
38
  ALTER TABLE {$installer->getTable('copernica_marketingsoftware')}
39
  ADD login_valid ENUM('yes', 'no') NOT NULL default 'yes',
40
  ADD linked_fields_valid ENUM('yes', 'no') NOT NULL default 'no',
45
 
46
  UPDATE {$installer->getTable('copernica_marketingsoftware')}
47
  SET progressstatus = 'none', addresscollectionname = '';
48
+ "
49
+ );
50
 
51
  $installer->endSetup();
app/code/community/Copernica/MarketingSoftware/sql/marketingsoftware_setup/mysql4-upgrade-1.1.8-1.2.0.php CHANGED
@@ -33,7 +33,8 @@
33
  $installer = $this;
34
  $installer->startSetup();
35
 
36
- $installer->run("
 
37
  INSERT INTO `{$installer->getTable('core_config_data')}` (path, value)
38
  SELECT 'marketingsoftware/hostname', hostname
39
  FROM {$installer->getTable('copernica_marketingsoftware')}
@@ -105,6 +106,7 @@ CREATE TABLE `{$installer->getTable('marketingsoftware/queue_item')}` (
105
  `result_time` timestamp NULL,
106
  PRIMARY KEY (`id`)
107
  ) ENGINE=InnoDB default CHARSET=utf8;
108
- ");
 
109
 
110
  $installer->endSetup();
33
  $installer = $this;
34
  $installer->startSetup();
35
 
36
+ $installer->run(
37
+ "
38
  INSERT INTO `{$installer->getTable('core_config_data')}` (path, value)
39
  SELECT 'marketingsoftware/hostname', hostname
40
  FROM {$installer->getTable('copernica_marketingsoftware')}
106
  `result_time` timestamp NULL,
107
  PRIMARY KEY (`id`)
108
  ) ENGINE=InnoDB default CHARSET=utf8;
109
+ "
110
+ );
111
 
112
  $installer->endSetup();
app/code/community/Copernica/MarketingSoftware/sql/marketingsoftware_setup/mysql4-upgrade-2.0.1-2.0.2.php CHANGED
@@ -28,7 +28,8 @@ $installer = $this;
28
  $installer->startSetup();
29
 
30
  try {
31
- $installer->run("
 
32
  DROP TABLE IF EXISTS {$this->getTable('marketingsoftware/config_data')};
33
  CREATE TABLE `{$this->getTable('marketingsoftware/config_data')}` (
34
  `config_id` int(11) NOT NULL auto_increment,
@@ -36,7 +37,10 @@ try {
36
  `value` TEXT NOT NULL,
37
  PRIMARY KEY (`config_id`),
38
  UNIQUE config_data_key_name (`key_name`)
39
- ) ENGINE = InnoDB DEFAULT CHARSET = utf8;");
40
- } catch(Exception $e) {}
 
 
 
41
 
42
  $installer->endSetup();
28
  $installer->startSetup();
29
 
30
  try {
31
+ $installer->run(
32
+ "
33
  DROP TABLE IF EXISTS {$this->getTable('marketingsoftware/config_data')};
34
  CREATE TABLE `{$this->getTable('marketingsoftware/config_data')}` (
35
  `config_id` int(11) NOT NULL auto_increment,
37
  `value` TEXT NOT NULL,
38
  PRIMARY KEY (`config_id`),
39
  UNIQUE config_data_key_name (`key_name`)
40
+ ) ENGINE = InnoDB DEFAULT CHARSET = utf8;"
41
+ );
42
+ } catch(Exception $e) {
43
+ Mage::logException($e);
44
+ }
45
 
46
  $installer->endSetup();
app/code/community/Copernica/MarketingSoftware/sql/marketingsoftware_setup/mysql4-upgrade-2.1.0.1-2.2.0.php CHANGED
@@ -28,9 +28,13 @@ $installer = $this;
28
  $installer->startSetup();
29
 
30
  try {
31
- $installer->run("
 
32
  ALTER TABLE {$this->getTable('marketingsoftware/queue_item')}
33
- MODIFY object LONGTEXT;");
34
- } catch(Exception $e) {}
 
 
 
35
 
36
- $installer->endSetup();
28
  $installer->startSetup();
29
 
30
  try {
31
+ $installer->run(
32
+ "
33
  ALTER TABLE {$this->getTable('marketingsoftware/queue_item')}
34
+ MODIFY object LONGTEXT;"
35
+ );
36
+ } catch(Exception $e) {
37
+ Mage::logException($e);
38
+ }
39
 
40
+ $installer->endSetup();
app/code/community/Copernica/MarketingSoftware/sql/marketingsoftware_setup/mysql4-upgrade-2.2.0.1-2.3.0.php CHANGED
@@ -28,9 +28,13 @@ $installer = $this;
28
  $installer->startSetup();
29
 
30
  try {
31
- $installer->run("
 
32
  ALTER TABLE {$this->getTable('marketingsoftware/queue_item')}
33
- ADD COLUMN customer int NULL DEFAULT NULL;");
34
- } catch(Exception $e) {}
 
 
 
35
 
36
- $installer->endSetup();
28
  $installer->startSetup();
29
 
30
  try {
31
+ $installer->run(
32
+ "
33
  ALTER TABLE {$this->getTable('marketingsoftware/queue_item')}
34
+ ADD COLUMN customer int NULL DEFAULT NULL;"
35
+ );
36
+ } catch(Exception $e) {
37
+ Mage::logException($e);
38
+ }
39
 
40
+ $installer->endSetup();
app/code/community/Copernica/MarketingSoftware/sql/marketingsoftware_setup/mysql4-upgrade-2.3.0-2.3.1.php CHANGED
@@ -30,7 +30,8 @@ $installer->startSetup();
30
 
31
  try {
32
  // create profile cache table
33
- $installer->run("
 
34
  DROP TABLE IF EXISTS `{$installer->getTable('marketingsoftware/profile_cache')}`;
35
  CREATE TABLE `{$installer->getTable('marketingsoftware/profile_cache')}` (
36
  `id` int(10) unsigned auto_increment,
@@ -38,7 +39,8 @@ try {
38
  `profile_id` int(10) unsigned NOT NULL,
39
  PRIMARY KEY (`id`)
40
  ) ENGINE=InnoDB default CHARSET=utf8;
41
- ");
 
42
 
43
  // finalize setup
44
  $installer->endSetup();
30
 
31
  try {
32
  // create profile cache table
33
+ $installer->run(
34
+ "
35
  DROP TABLE IF EXISTS `{$installer->getTable('marketingsoftware/profile_cache')}`;
36
  CREATE TABLE `{$installer->getTable('marketingsoftware/profile_cache')}` (
37
  `id` int(10) unsigned auto_increment,
39
  `profile_id` int(10) unsigned NOT NULL,
40
  PRIMARY KEY (`id`)
41
  ) ENGINE=InnoDB default CHARSET=utf8;
42
+ "
43
+ );
44
 
45
  // finalize setup
46
  $installer->endSetup();
app/code/community/Copernica/MarketingSoftware/sql/marketingsoftware_setup/mysql4-upgrade-2.3.1-2.3.2.php CHANGED
@@ -30,7 +30,8 @@ $installer->startSetup();
30
 
31
  try {
32
  // create error queue table
33
- $installer->run("
 
34
  DROP TABLE IF EXISTS `{$installer->getTable('marketingsoftware/error_queue')}`;
35
  CREATE TABLE `{$installer->getTable('marketingsoftware/error_queue')}` (
36
  `id` int(10) unsigned auto_increment,
@@ -43,7 +44,8 @@ try {
43
  `customer` int(11),
44
  PRIMARY KEY (`id`)
45
  ) ENGINE=InnoDB default CHARSET=utf8;
46
- ");
 
47
 
48
  // finish setup
49
  $installer->endSetup();
30
 
31
  try {
32
  // create error queue table
33
+ $installer->run(
34
+ "
35
  DROP TABLE IF EXISTS `{$installer->getTable('marketingsoftware/error_queue')}`;
36
  CREATE TABLE `{$installer->getTable('marketingsoftware/error_queue')}` (
37
  `id` int(10) unsigned auto_increment,
44
  `customer` int(11),
45
  PRIMARY KEY (`id`)
46
  ) ENGINE=InnoDB default CHARSET=utf8;
47
+ "
48
+ );
49
 
50
  // finish setup
51
  $installer->endSetup();
app/code/community/Copernica/MarketingSoftware/sql/marketingsoftware_setup/mysql4-upgrade-2.3.2-2.3.3.php CHANGED
@@ -22,37 +22,49 @@ try {
22
  $table = $installer->getConnection()->newTable($tableName);
23
 
24
  // add Id column
25
- $table->addColumn('id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
 
26
  'unsigned' => true,
27
  'nullable' => false,
28
  'primary' => true,
29
  'identity' => true,
30
- ), 'Profile Cache Id');
 
31
 
32
  // add customer Id column
33
- $table->addColumn('customer_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
 
34
  'unsigned' => true
35
- ), 'Customer Id');
 
36
 
37
  // add copernica customer Id column
38
- $table->addColumn('copernica_id', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
 
39
  'nullable' => true
40
- ), 'Copernica customer Id');
 
41
 
42
  // add profile id column
43
- $table->addColumn('profile_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
 
44
  'nullable' => true
45
- ), 'Profile Id');
 
46
 
47
  // add email column
48
- $table->addColumn('email', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
 
49
  'nullable' => true
50
- ), 'Email address');
 
51
 
52
  // add store view column
53
- $table->addColumn('store_view', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
 
54
  'nullable' => true
55
- ), 'Store view');
 
56
 
57
  // tell connection to create table
58
  $installer->getConnection()->createTable($table);
22
  $table = $installer->getConnection()->newTable($tableName);
23
 
24
  // add Id column
25
+ $table->addColumn(
26
+ 'id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
27
  'unsigned' => true,
28
  'nullable' => false,
29
  'primary' => true,
30
  'identity' => true,
31
+ ), 'Profile Cache Id'
32
+ );
33
 
34
  // add customer Id column
35
+ $table->addColumn(
36
+ 'customer_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
37
  'unsigned' => true
38
+ ), 'Customer Id'
39
+ );
40
 
41
  // add copernica customer Id column
42
+ $table->addColumn(
43
+ 'copernica_id', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
44
  'nullable' => true
45
+ ), 'Copernica customer Id'
46
+ );
47
 
48
  // add profile id column
49
+ $table->addColumn(
50
+ 'profile_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
51
  'nullable' => true
52
+ ), 'Profile Id'
53
+ );
54
 
55
  // add email column
56
+ $table->addColumn(
57
+ 'email', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
58
  'nullable' => true
59
+ ), 'Email address'
60
+ );
61
 
62
  // add store view column
63
+ $table->addColumn(
64
+ 'store_view', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
65
  'nullable' => true
66
+ ), 'Store view'
67
+ );
68
 
69
  // tell connection to create table
70
  $installer->getConnection()->createTable($table);
app/code/community/Copernica/MarketingSoftware/sql/marketingsoftware_setup/mysql4-upgrade-2.3.8-2.4.0.php CHANGED
@@ -51,25 +51,28 @@ try
51
  $textType = defined('Varien_Db_Ddl_Table::TYPE_TEXT') ? Varien_Db_Ddl_Table::TYPE_TEXT : Varien_Db_Ddl_Table::TYPE_VARCHAR;
52
 
53
  // We will need a name for our events.
54
- $installer->getConnection()->addColumn($queueTableName, 'name', array(
 
55
  'comment' => 'name of the event',
56
  'type' => $textType,
57
  'length' => 255,
58
  'nullable' => true,
59
  'default' => null
60
- ));
 
61
 
62
  // we will need associated entity for our events
63
- $installer->getConnection()->addColumn($queueTableName, 'entity_id', array(
 
64
  'comment' => 'entity id associated with event',
65
  'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
66
  'nullable' => true,
67
  'default' => null
68
- ));
 
69
 
70
  // iterate over all unique customer that we found on old queue
71
- foreach ($result as $row)
72
- {
73
  // create new events to sync all unique custoemr that we found on old queue
74
  Mage::getModel('marketingsoftware/queue_item')
75
  ->setObject(null)
@@ -98,4 +101,4 @@ try
98
  catch(Exception $exception)
99
  {
100
  Mage::log($exception->getMessage());
101
- }
51
  $textType = defined('Varien_Db_Ddl_Table::TYPE_TEXT') ? Varien_Db_Ddl_Table::TYPE_TEXT : Varien_Db_Ddl_Table::TYPE_VARCHAR;
52
 
53
  // We will need a name for our events.
54
+ $installer->getConnection()->addColumn(
55
+ $queueTableName, 'name', array(
56
  'comment' => 'name of the event',
57
  'type' => $textType,
58
  'length' => 255,
59
  'nullable' => true,
60
  'default' => null
61
+ )
62
+ );
63
 
64
  // we will need associated entity for our events
65
+ $installer->getConnection()->addColumn(
66
+ $queueTableName, 'entity_id', array(
67
  'comment' => 'entity id associated with event',
68
  'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
69
  'nullable' => true,
70
  'default' => null
71
+ )
72
+ );
73
 
74
  // iterate over all unique customer that we found on old queue
75
+ foreach ($result as $row) {
 
76
  // create new events to sync all unique custoemr that we found on old queue
77
  Mage::getModel('marketingsoftware/queue_item')
78
  ->setObject(null)
101
  catch(Exception $exception)
102
  {
103
  Mage::log($exception->getMessage());
104
+ }
app/code/community/Copernica/MarketingSoftware/sql/marketingsoftware_setup/mysql4-upgrade-2.4.0-2.4.1.php CHANGED
@@ -37,14 +37,12 @@ $installer->startSetup();
37
  $linkedFieldConfigs = array('linked_customer_fields', 'linked_cart_item_fields', 'linked_order_fields', 'linked_order_item_fields', 'linked_address_fields', 'linked_viewed_product_fields');
38
 
39
  // iterate over all linked fields configs
40
- foreach ($linkedFieldConfigs as $config)
41
- {
42
  // get model
43
  $model = Mage::getModel('marketingsoftware/config')->loadByKey($config);
44
 
45
  // we have to check if model is ok
46
- if ($model->getId())
47
- {
48
  // get json value
49
  $json = $model->getValue();
50
 
@@ -52,8 +50,7 @@ foreach ($linkedFieldConfigs as $config)
52
  $array = json_decode($json, true);
53
 
54
  // we have to convert all underscore case keys to camel case keys
55
- foreach ($array as $key => $value)
56
- {
57
  // unset old value
58
  unset($array[$key]);
59
 
37
  $linkedFieldConfigs = array('linked_customer_fields', 'linked_cart_item_fields', 'linked_order_fields', 'linked_order_item_fields', 'linked_address_fields', 'linked_viewed_product_fields');
38
 
39
  // iterate over all linked fields configs
40
+ foreach ($linkedFieldConfigs as $config) {
 
41
  // get model
42
  $model = Mage::getModel('marketingsoftware/config')->loadByKey($config);
43
 
44
  // we have to check if model is ok
45
+ if ($model->getId()) {
 
46
  // get json value
47
  $json = $model->getValue();
48
 
50
  $array = json_decode($json, true);
51
 
52
  // we have to convert all underscore case keys to camel case keys
53
+ foreach ($array as $key => $value) {
 
54
  // unset old value
55
  unset($array[$key]);
56
 
app/code/community/Copernica/MarketingSoftware/sql/marketingsoftware_setup/mysql4-upgrade-2.4.1-2.4.2.php CHANGED
@@ -46,32 +46,42 @@ try
46
  $table = $installer->getConnection()->newTable($tableName);
47
 
48
  // add Id column
49
- $table->addColumn('id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
 
50
  'unsigned' => true,
51
  'nullable' => false,
52
  'primary' => true,
53
  'identity' => true,
54
- ), 'Sync profile Id');
 
55
 
56
  // add customer Id column
57
- $table->addColumn('client_key', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
 
58
  'nullable' => false
59
- ), 'Copernica client key');
 
60
 
61
  // add copernica customer Id column
62
- $table->addColumn('client_secret', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
 
63
  'nullable' => false
64
- ), 'Copernica client secret');
 
65
 
66
  // add profile id column
67
- $table->addColumn('access_token', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
 
68
  'nullable' => true
69
- ), 'Client access token');
 
70
 
71
  // add email column
72
- $table->addColumn('name', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
 
73
  'nullable' => false
74
- ), 'Name of the sync profile');
 
75
 
76
  // tell connection to create table
77
  $installer->getConnection()->createTable($table);
46
  $table = $installer->getConnection()->newTable($tableName);
47
 
48
  // add Id column
49
+ $table->addColumn(
50
+ 'id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
51
  'unsigned' => true,
52
  'nullable' => false,
53
  'primary' => true,
54
  'identity' => true,
55
+ ), 'Sync profile Id'
56
+ );
57
 
58
  // add customer Id column
59
+ $table->addColumn(
60
+ 'client_key', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
61
  'nullable' => false
62
+ ), 'Copernica client key'
63
+ );
64
 
65
  // add copernica customer Id column
66
+ $table->addColumn(
67
+ 'client_secret', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
68
  'nullable' => false
69
+ ), 'Copernica client secret'
70
+ );
71
 
72
  // add profile id column
73
+ $table->addColumn(
74
+ 'access_token', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
75
  'nullable' => true
76
+ ), 'Client access token'
77
+ );
78
 
79
  // add email column
80
+ $table->addColumn(
81
+ 'name', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
82
  'nullable' => false
83
+ ), 'Name of the sync profile'
84
+ );
85
 
86
  // tell connection to create table
87
  $installer->getConnection()->createTable($table);
app/code/community/Copernica/MarketingSoftware/sql/marketingsoftware_setup/mysql4-upgrade-2.4.2-2.4.3.php CHANGED
@@ -46,23 +46,29 @@ try
46
  $table = $installer->getConnection()->newTable($tableName);
47
 
48
  // add Id column
49
- $table->addColumn('id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
 
50
  'unsigned' => true,
51
  'nullable' => false,
52
  'primary' => true,
53
  'identity' => true,
54
- ), 'Abandoned cart auto increment Id');
 
55
 
56
  // add customer Id column
57
- $table->addColumn('quote_id', Varien_Db_Ddl_Table::TYPE_INTEGER, 255, array(
 
58
  'unsigned' => true,
59
  'nullable' => false
60
- ), 'Quote id associated with abandoned cart');
 
61
 
62
  // add copernica customer Id column
63
- $table->addColumn('timestamp', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, 255, array(
 
64
  'nullable' => false
65
- ), 'When cart was detected');
 
66
 
67
  // tell connection to create table
68
  $installer->getConnection()->createTable($table);
46
  $table = $installer->getConnection()->newTable($tableName);
47
 
48
  // add Id column
49
+ $table->addColumn(
50
+ 'id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
51
  'unsigned' => true,
52
  'nullable' => false,
53
  'primary' => true,
54
  'identity' => true,
55
+ ), 'Abandoned cart auto increment Id'
56
+ );
57
 
58
  // add customer Id column
59
+ $table->addColumn(
60
+ 'quote_id', Varien_Db_Ddl_Table::TYPE_INTEGER, 255, array(
61
  'unsigned' => true,
62
  'nullable' => false
63
+ ), 'Quote id associated with abandoned cart'
64
+ );
65
 
66
  // add copernica customer Id column
67
+ $table->addColumn(
68
+ 'timestamp', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, 255, array(
69
  'nullable' => false
70
+ ), 'When cart was detected'
71
+ );
72
 
73
  // tell connection to create table
74
  $installer->getConnection()->createTable($table);
app/code/community/Copernica/MarketingSoftware/sql/marketingsoftware_setup/mysql4-upgrade-2.4.3-2.4.4.php CHANGED
@@ -49,37 +49,49 @@ try
49
  $table = $installer->getConnection()->newTable($tableName);
50
 
51
  // add Id column
52
- $table->addColumn('id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
 
53
  'unsigned' => true,
54
  'nullable' => false,
55
  'primary' => true,
56
  'identity' => true,
57
- ), 'Profile Cache Id');
 
58
 
59
  // add customer Id column
60
- $table->addColumn('customer_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
 
61
  'unsigned' => true
62
- ), 'Customer Id');
 
63
 
64
  // add copernica customer Id column
65
- $table->addColumn('copernica_id', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
 
66
  'nullable' => true
67
- ), 'Copernica customer Id');
 
68
 
69
  // add profile id column
70
- $table->addColumn('profile_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
 
71
  'nullable' => true
72
- ), 'Profile Id');
 
73
 
74
  // add email column
75
- $table->addColumn('email', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
 
76
  'nullable' => true
77
- ), 'Email address');
 
78
 
79
  // add store view column
80
- $table->addColumn('store_view', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
 
81
  'nullable' => true
82
- ), 'Store view');
 
83
 
84
  // tell connection to create table
85
  $installer->getConnection()->createTable($table);
@@ -98,4 +110,4 @@ catch (Exception $e)
98
  {
99
  // tell magento to log exception.
100
  Mage::logException($exception);
101
- }
49
  $table = $installer->getConnection()->newTable($tableName);
50
 
51
  // add Id column
52
+ $table->addColumn(
53
+ 'id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
54
  'unsigned' => true,
55
  'nullable' => false,
56
  'primary' => true,
57
  'identity' => true,
58
+ ), 'Profile Cache Id'
59
+ );
60
 
61
  // add customer Id column
62
+ $table->addColumn(
63
+ 'customer_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
64
  'unsigned' => true
65
+ ), 'Customer Id'
66
+ );
67
 
68
  // add copernica customer Id column
69
+ $table->addColumn(
70
+ 'copernica_id', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
71
  'nullable' => true
72
+ ), 'Copernica customer Id'
73
+ );
74
 
75
  // add profile id column
76
+ $table->addColumn(
77
+ 'profile_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
78
  'nullable' => true
79
+ ), 'Profile Id'
80
+ );
81
 
82
  // add email column
83
+ $table->addColumn(
84
+ 'email', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
85
  'nullable' => true
86
+ ), 'Email address'
87
+ );
88
 
89
  // add store view column
90
+ $table->addColumn(
91
+ 'store_view', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
92
  'nullable' => true
93
+ ), 'Store view'
94
+ );
95
 
96
  // tell connection to create table
97
  $installer->getConnection()->createTable($table);
110
  {
111
  // tell magento to log exception.
112
  Mage::logException($exception);
113
+ }
app/design/adminhtml/default/default/template/marketingsoftware/settings.phtml CHANGED
@@ -316,9 +316,9 @@ function init() {
316
  </label>
317
  <br>
318
  <?php
319
- foreach(Mage::app()->getWebsites() as $website){
320
  foreach($website->getGroups() as $group){
321
- foreach($group->getStores() as $store) {
322
 
323
  $enabledStore = is_array($_config->getEnabledStores()) && in_array($store->getId(), $_config->getEnabledStores());
324
 
316
  </label>
317
  <br>
318
  <?php
319
+ foreach(Mage::app()->getWebsites(true) as $website){
320
  foreach($website->getGroups() as $group){
321
+ foreach($group->getStores(true) as $store) {
322
 
323
  $enabledStore = is_array($_config->getEnabledStores()) && in_array($store->getId(), $_config->getEnabledStores());
324
 
package.xml CHANGED
@@ -1,18 +1,18 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Copernica_MarketingSoftware</name>
4
- <version>3.2.3</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/osl-3.0.php">Open Software License (OSL 3.0)</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Plugin to exchange data from Magento with Copernica Marketing Software.</summary>
10
  <description>When you install the integration, all contact, order and shop cart data from Magento will be automatically synchronized and stored in Copernica. By synchronizing data between your Magento webshop and Copernica, you are able to set up targeted email campaigns. For example you can consider emailing customers with abandoned shopcarts automatically every week. Your contacts will only receive information relevant to them, which will make them come back to your shop time and again. The available integration is also compatible with the Magento Enterprise edition. Please note that this extension does not work with PHP 5.4.X. and should be run with the Magento system requirements in mind.</description>
11
- <notes>Copernica - Version 3.2.3</notes>
12
  <authors><author><name>Cream</name><user>creaminternet</user><email>info@cream.nl</email></author></authors>
13
- <date>2015-08-12</date>
14
- <time>10:13:08</time>
15
- <contents><target name="magecommunity"><dir name="Copernica"><dir name="MarketingSoftware"><dir name="Block"><dir name="Adminhtml"><dir name="Marketingsoftware"><file name="Accesstoken.php" hash="29cfec58c1b5d9a057b646f1dad96de0"/><file name="Export.php" hash="b399cc65bba668de91f9621b85d3e27e"/><file name="Link.php" hash="2886fb943191bb9be459fcb4963bc70b"/><file name="Settings.php" hash="af7b8723a4e9210d11fbfac05fe5080b"/><file name="Sync.php" hash="4a10ec20871f136bb0dae602aa4df77d"/></dir></dir></dir><dir name="Controller"><file name="Action.php" hash="2610a082ca6e8bd4790442652e341c85"/></dir><file name="Exception.php" hash="fec6721cdc464233cfdbf5d653e7b41b"/><dir name="Helper"><dir name="Api"><file name="Abstract.php" hash="b9f0183a3615331cae2e682ad3e6c054"/><file name="Builder.php" hash="c5603b3c54b309103af2d2083246f2bb"/><file name="Validator.php" hash="867ed42d76ac5b720afe1517a930b6b6"/></dir><file name="Api.php" hash="b091dd61ec789cda46140c540fe659c0"/><file name="Config.php" hash="c71f09c00f0ffd62a12f8e0e02e17cb1"/><file name="Data.php" hash="1c8425a2b1232c62cfc10fb6fcba9ad0"/><file name="DataWriter.php" hash="91eec8f0426e30b273e4709488d775c3"/><file name="Profile.php" hash="2ed47a7a9b3df84fac7fd74e76aaf67b"/><dir name="Rest"><file name="Request.php" hash="1fb9cece0ca0a4fa8ba682755c031899"/></dir></dir><dir name="Model"><dir name="Abandoned"><file name="Cart.php" hash="33fa4f7d4f89ef45f8b8876a612abada"/><dir name="Carts"><file name="Processor.php" hash="33344ff5bfd584305d062df953bb84f9"/></dir></dir><dir name="Abstraction"><file name="Address.php" hash="b62d10f1986d08c7726bd2a1874936ac"/><file name="Attributes.php" hash="aa543079441ad7137a2033f326ea1bab"/><file name="Customer.php" hash="c418a0d637ad3b044bdb9a4a9b7fd26d"/><file name="Name.php" hash="ff4834f323e408211b0099d869e85051"/><dir name="Order"><dir name="Item"><file name="Options.php" hash="3483f1b10e4b2ac0d1c47e5d03c21730"/></dir><file name="Item.php" hash="25b76c7661e73547ce860a04698df774"/></dir><file name="Order.php" hash="7a5212a3618304259b78f891858474c0"/><file name="Price.php" hash="444016a4eb5273b55165f6238d370814"/><dir name="Product"><file name="Viewed.php" hash="7d3dfde4c154a404fef5977038209865"/></dir><file name="Product.php" hash="d7c29c651dda6e7c2624344e936e1c51"/><dir name="Quote"><dir name="Item"><file name="Options.php" hash="ee909690f8ec01319b5ebce7afa67ea2"/></dir><file name="Item.php" hash="1cd86f01d1877df31f8ed4621d45eb7d"/></dir><file name="Quote.php" hash="86c0556ec70886f09a9999893dea8fda"/><file name="Storeview.php" hash="e074587d66ad7c8a8dffdda1423e18bb"/><file name="Subscription.php" hash="4a4e2c25857ae553f4bfceadcddbb8c9"/><dir name="Wishlist"><dir name="Item"><file name="Options.php" hash="88372eac4289a923915b02f00140e2e0"/></dir><file name="Item.php" hash="6311c147e868d99c90d57f8a2bba10bc"/></dir><file name="Wishlist.php" hash="171d08e53f87b4ec126941bff4f0877a"/><file name="readme.txt" hash="90f0b9c7e67b6e9ed1e172f28afcc660"/></dir><file name="AsyncPomSoapClient.php" hash="96963e05a0de2a3cad9189efdcafdac9"/><file name="Config.php" hash="b3abe602faead6f095c82d111c6bb23e"/><dir name="Copernica"><file name="Abstract.php" hash="d29d93cf6a0ce943f3a85a62b05b8363"/><dir name="Address"><file name="Subprofile.php" hash="297a7bbac3af8f041242510fb1365c38"/></dir><dir name="Entity"><file name="Address.php" hash="9d340fe9dc6c95a59cafaad8dd57ad84"/><file name="Customer.php" hash="b34b599cd4d5aae4bf58040930664f17"/><dir name="Order"><file name="Item.php" hash="b1178b8c9acb892337f5b9d3f5e04a57"/></dir><file name="Order.php" hash="613e9d432001da97d287437a917fb3a8"/><file name="Product.php" hash="7918bdeba188bf9174ff23d1a8f8056d"/><dir name="Quote"><file name="Item.php" hash="57aba64004cb24b83854d06591d0992d"/></dir><file name="Quote.php" hash="260c2befc428abe459d3bb506272012d"/><file name="Subscription.php" hash="175ff77340c5fe991d18488487ff1fa5"/><dir name="Wishlist"><file name="Item.php" hash="c66838fd6120410be7026ff9d9671879"/></dir><file name="Wishlist.php" hash="b20b9a585c8d6216245f39cdd6e132f6"/></dir><file name="Entity.php" hash="2953aeaa6ccfdacedfccb792ea51e616"/><dir name="Order"><file name="Subprofile.php" hash="c2731345ef2f9ee5e94c08cc436ff3c9"/></dir><dir name="Orderitem"><file name="Subprofile.php" hash="c7e616219f54be72c076e62bcf0e7d3f"/></dir><dir name="Product"><dir name="Viewed"><file name="Subprofile.php" hash="65e6feb393b4c62285525a568e52f23a"/></dir></dir><dir name="Profile"><file name="Customer.php" hash="bcc695433e9edadc2ca1980494c5862c"/><file name="Order.php" hash="622f8d09de8c75307afada3aa22f3a4b"/><file name="Quote.php" hash="7934de49a073e5e00f5a763cb83d0b20"/><file name="Subscription.php" hash="297639611a3bd882b2c5fee0689f476d"/></dir><file name="Profile.php" hash="02e1327d4d58109b936793023235994a"/><dir name="Quote"><dir name="Item"><file name="Subprofile.php" hash="f69f63fda8b148a3019dfd010c3df414"/></dir></dir><dir name="Wishlist"><dir name="Item"><file name="Subprofile.php" hash="ae547f8304fc6cfe703efb13360660ea"/></dir></dir></dir><dir name="Error"><file name="Queue.php" hash="1240537c6560f59e48a066b440127d94"/></dir><file name="Error.php" hash="b8c1e456f0c398511d24ec5c9dab17d1"/><file name="Marketingsoftware.php" hash="05d6809f438672c945cbd36c2ee6a095"/><dir name="Mysql4"><dir name="Abandoned"><dir name="Cart"><file name="Collection.php" hash="5c6caa13d70a26b9c8fa246ae758e1bb"/></dir><file name="Cart.php" hash="a256e52ef1c583e6868d00d965b8aafc"/></dir><dir name="Config"><file name="Collection.php" hash="ea24387a0a68db651ce32d2bb93ccff0"/></dir><file name="Config.php" hash="0e248da13b5f4059e01fd9b8a082720e"/><dir name="Error"><dir name="Queue"><file name="Collection.php" hash="3c3ab32179c9d3d25d730b603cd1fa6d"/></dir><file name="Queue.php" hash="3d6d03ba0a14c2839ec8fafb536fa9e2"/></dir><dir name="Profile"><dir name="Cache"><file name="Collection.php" hash="fe9f9e4157dc686279b1d8311c672d28"/></dir><file name="Cache.php" hash="86a91eb32e4fe5243b333d02aa0b52ee"/></dir><dir name="Queue"><dir name="Item"><file name="Collection.php" hash="1f881d9c6d1137092965af6fd3199e44"/></dir><file name="Item.php" hash="a488b88725c05bb3c0afe58c915704c4"/></dir><dir name="Sync"><dir name="Profile"><file name="Collection.php" hash="e37f86cf075a1bf172fc9469384c17b2"/></dir><file name="Profile.php" hash="56b8054ee3b3d2d7eb6093e6766212bc"/></dir></dir><file name="Observer.php" hash="00258d5cd05ffc15416d740ddbdf0178"/><file name="PomSoapClient.php" hash="7268370f5c2e7e40b2f6040b5c846ffe"/><dir name="Profile"><file name="Cache.php" hash="a9a2a68edcb1137882136bd01a443f78"/></dir><dir name="Queue"><dir name="Event"><file name="Abstract.php" hash="b740109c3c08ec59f0408ac557e5aecf"/><file name="Checkout.php" hash="555539db5b0b08d17b2113e3a5b43d38"/><file name="Customer.php" hash="d623d272a3b4f88fe1d98ba8a0c948a9"/><file name="Factory.php" hash="9d1856bd9eeca7f65c35bb392d434163"/><file name="Item.php" hash="2f74f53e5e8caec754dd705ec0c64ba7"/><file name="Order.php" hash="4c2c6b34cb8eb1479197b780099947fe"/><file name="Quote.php" hash="145b051c6acd678c221b739e75350f52"/><file name="Startsync.php" hash="8bb3bdb9e1f714f8461eaee0f7f97f13"/><file name="Subscription.php" hash="5f309b3062118e4a3dab7e18a2205006"/><file name="View.php" hash="8d18e1c349f55d0366cb3d790f203914"/><dir name="Wishlist"><file name="Item.php" hash="38905e1f809f14e9eb9bba8ad6e3e61e"/></dir></dir><file name="Item.php" hash="5e68df4c1f1697f5bf9918b47f769888"/><file name="Processor.php" hash="e714c7ca00a15ad89a766a889edf61af"/></dir><dir name="QueueEvent"><file name="FileSync.php" hash="63c9d75f1d3d6723e126844892f55831"/></dir><dir name="Rest"><file name="Address.php" hash="54fa365d02adfe989ab298c9e324fe9a"/><file name="Customer.php" hash="959c715c5783a58afd387d3ef404d220"/><dir name="Order"><file name="Item.php" hash="d63834144ea20631ef638f44593d7b5b"/></dir><file name="Order.php" hash="799ae78183400fb3a5add95c39b29686"/><file name="Product.php" hash="8bb55b8fcf58b8a176f27704d3c98ad9"/><dir name="Quote"><file name="Item.php" hash="7869c9946789d2c576309f992ab0aace"/></dir><file name="Quote.php" hash="5ead39088a3052b1d26b6ce8d6c74700"/><file name="Subscription.php" hash="e05e6cd33afe7c83d54eb9e6585eaafe"/><dir name="Wishlist"><file name="Item.php" hash="084eb2c462e9c689fdc1be19aaf10d49"/></dir><file name="Wishlist.php" hash="9c5240286bbf590b3a47d01286f2bd5b"/></dir><file name="Rest.php" hash="5496864599550bc109f7b9671083f515"/><dir name="Sync"><file name="Profile.php" hash="8db80345fe051d946dd8a6d8ee361397"/><file name="Status.php" hash="7cd4b2ee0e82f594bd9737ce519be728"/></dir></dir><dir name="controllers"><dir name="Adminhtml"><dir name="Marketingsoftware"><file name="AccessTokenController.php" hash="3b40ecacecf8ce8b93dcaa6a911a4006"/><file name="AjaxcollectionController.php" hash="5d91aadce4e802cbaaa94f2e4f63a6ec"/><file name="AjaxcollectionfieldController.php" hash="adedd9277f1607f6fcdca1a049d98499"/><file name="AjaxdatabaseController.php" hash="b9652b5eb2a5487d291128179ff27cc8"/><file name="AjaxdatabasefieldController.php" hash="15534b4a534897ea26546bb1275531ea"/><file name="ExportController.php" hash="7cd425f78b29034a88f836062009c0ff"/><file name="LinkController.php" hash="b0e2c8340faab128d306a674fcf94d77"/><file name="SettingsController.php" hash="41e704facb5292f9fb6224db291c1e8a"/><file name="SyncController.php" hash="0f8ef81702154bab758b92989f651375"/></dir></dir><file name="CartController.php" hash="1e050714257f366d16295974040a80e6"/><file name="ProductController.php" hash="90a651eb0f0f9ef939a989f060ef6939"/><file name="UnsubscribeController.php" hash="035a0288154754e41e7acc34d0e572d0"/></dir><dir name="cron"><file name="clearCopernicaDatabase.php" hash="757d80b4546291e8a2556e05dd388b0c"/><file name="detectAbandonedCarts.php" hash="bbc722e15de6319a25da11b1108149c2"/><file name="fullSync.php" hash="fa649c36d18e250cbd4118a61573f94b"/><file name="processQueue.php" hash="32295fcbd7f254df2dd91b0719f509c4"/></dir><dir name="data"><dir name="marketingsoftware_setup"><file name="data-upgrade-3.4.0-3.4.1.php" hash="c97b1ab3d07a73b2a6b17f68f5ada75c"/></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="f3372c2961c0a2e9d388240997f30a4f"/><file name="config.xml" hash="6074061c82614e848d9bc6b86426ddc8"/></dir><dir name="sql"><dir name="marketingsoftware_setup"><file name="mysql4-install-1.2.0.php" hash="c3576632268f4fc2913a27ad736b62c0"/><file name="mysql4-upgrade-1.1.5-1.1.6.php" hash="926b042ef4f2f950584525e46c9134f5"/><file name="mysql4-upgrade-1.1.6-1.1.7.php" hash="f16fddc74e100a874d2ca84401b0aeaa"/><file name="mysql4-upgrade-1.1.7-1.1.8.php" hash="0b5d023b79291e6510618ffecad28c57"/><file name="mysql4-upgrade-1.1.8-1.2.0.php" hash="eac4f661e6cb30d6abad991f47347a55"/><file name="mysql4-upgrade-2.0.1-2.0.2.php" hash="ddf9d4be53e6681c281d9b2e6ce81c85"/><file name="mysql4-upgrade-2.1.0.1-2.2.0.php" hash="e6177e25e045d11d92f553a35fd5264a"/><file name="mysql4-upgrade-2.2.0.1-2.3.0.php" hash="f189f97086c4e120751d32b94684ab2e"/><file name="mysql4-upgrade-2.3.0-2.3.1.php" hash="a0736033be30db3227c13d59e1e14e90"/><file name="mysql4-upgrade-2.3.1-2.3.2.php" hash="5ae1aa5ded957969c5825e49da14fb4c"/><file name="mysql4-upgrade-2.3.2-2.3.3.php" hash="06ddd3fe61e3f674b2a9c61d477f833f"/><file name="mysql4-upgrade-2.3.3-2.3.4.php" hash="303ea277057d9d9ef54f79580b654073"/><file name="mysql4-upgrade-2.3.4-2.3.5.php" hash="e7dbca98126ad8bda9f3a864efac362e"/><file name="mysql4-upgrade-2.3.8-2.4.0.php" hash="f9c9b9e29ef20b42c7b048c48e89f409"/><file name="mysql4-upgrade-2.4.0-2.4.1.php" hash="c7b24ef413bee0e33695927f04081f69"/><file name="mysql4-upgrade-2.4.1-2.4.2.php" hash="574dfd2dbaf5c4ce17595851c97e5510"/><file name="mysql4-upgrade-2.4.2-2.4.3.php" hash="9178c14960f7f45f1be0b046a4a47961"/><file name="mysql4-upgrade-2.4.3-2.4.4.php" hash="b6351806267421b392691d8d61d6ffab"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Copernica_MarketingSoftware.xml" hash="1d3e901ef934e74a837d779f815882d0"/></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="marketingsoftware"><file name="accessToken.phtml" hash="a469b1e89b523636c45c4609dcee53c3"/><file name="export.phtml" hash="70adeb24375c0b2e350808ddefa091b0"/><file name="link.phtml" hash="b6756106bc5471378a4e5851fbfa256d"/><file name="settings.phtml" hash="a0df1b13f0be5a0aa50dde33b3a1b4b2"/><file name="sync.phtml" hash="ec3749674fab02f124bbc55d618a28e8"/></dir></dir></dir></dir></dir></target><target name="mageweb"><dir name="js"><dir name="copernica"><dir name="marketingsoftware"><file name="collection.js" hash="6c36cb25e5aa7c8396d9d4cf8331f2fc"/><file name="database.js" hash="3a71e50e837ca2fe049bbfe9001fbc2d"/><file name="field.js" hash="31ac2badb9f982e5cefca1006993c17f"/><file name="link.js" hash="0b2c0e242bbf3b785065b3c85b9aa235"/></dir></dir></dir></target></contents>
16
  <compatible/>
17
- <dependencies><required><php><min>5.2.0</min><max>5.6.99</max></php><extension><name>PDO</name><min/><max/></extension><extension><name>curl</name><min/><max/></extension></required></dependencies>
18
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Copernica_MarketingSoftware</name>
4
+ <version>3.2.4</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/osl-3.0.php">Open Software License (OSL 3.0)</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Plugin to exchange data from Magento with Copernica Marketing Software.</summary>
10
  <description>When you install the integration, all contact, order and shop cart data from Magento will be automatically synchronized and stored in Copernica. By synchronizing data between your Magento webshop and Copernica, you are able to set up targeted email campaigns. For example you can consider emailing customers with abandoned shopcarts automatically every week. Your contacts will only receive information relevant to them, which will make them come back to your shop time and again. The available integration is also compatible with the Magento Enterprise edition. Please note that this extension does not work with PHP 5.4.X. and should be run with the Magento system requirements in mind.</description>
11
+ <notes>Copernica - Version 3.2.4</notes>
12
  <authors><author><name>Cream</name><user>creaminternet</user><email>info@cream.nl</email></author></authors>
13
+ <date>2016-11-21</date>
14
+ <time>14:05:55</time>
15
+ <contents><target name="magecommunity"><dir name="Copernica"><dir name="MarketingSoftware"><dir name="Block"><dir name="Adminhtml"><dir name="Marketingsoftware"><file name="Accesstoken.php" hash="29cfec58c1b5d9a057b646f1dad96de0"/><file name="Export.php" hash="b399cc65bba668de91f9621b85d3e27e"/><file name="Link.php" hash="2886fb943191bb9be459fcb4963bc70b"/><file name="Settings.php" hash="af7b8723a4e9210d11fbfac05fe5080b"/><file name="Sync.php" hash="122f9d8583bbf50868a6819f8649ddff"/></dir></dir></dir><dir name="Controller"><file name="Action.php" hash="d9255f436958ae6538318b89009068e3"/></dir><file name="Exception.php" hash="fec6721cdc464233cfdbf5d653e7b41b"/><dir name="Helper"><dir name="Api"><file name="Abstract.php" hash="5497d6e806e347bbd6e106fc60e02bb7"/><file name="Builder.php" hash="b30c1951207a1ae330f8b47971f3db1d"/><file name="Validator.php" hash="c4f618bd2f647859c7ab0d245c1f55b7"/></dir><file name="Api.php" hash="43bca02de3d6f213a2bd68250d665ef9"/><file name="Config.php" hash="08eabbda85d784aa7ad894884d8da335"/><file name="Data.php" hash="39757938980e4bb9cd8e856f03a67acc"/><file name="DataWriter.php" hash="7ad32c7c6aecf76d913a5005e0f2fe24"/><file name="Profile.php" hash="b62db37dce77e77f64f97b92dae987c2"/><dir name="Rest"><file name="Request.php" hash="c17a65d27143c1b9da611df0eff4fc1c"/></dir></dir><dir name="Model"><dir name="Abandoned"><file name="Cart.php" hash="b5fd0e21aa343ea2069c0ded702f4299"/><dir name="Carts"><file name="Processor.php" hash="bd8fc533fb6c52bd6bd8e4b6bf7d467b"/></dir></dir><dir name="Abstraction"><file name="Address.php" hash="14d6cec8b4b58373033a7e903a5eb078"/><file name="Attributes.php" hash="3fdc528d820aecb7d893d16c7b5883fd"/><file name="Customer.php" hash="4483309f6541789e1b4e4af57ac06ec2"/><file name="Name.php" hash="1efde24a7cb68874e717b43287dd7c44"/><dir name="Order"><dir name="Item"><file name="Options.php" hash="14afef26fb7c1616f81fb2eb359ce145"/></dir><file name="Item.php" hash="be20a494b99b1ef23e10b1c1a7cedf83"/></dir><file name="Order.php" hash="eebeab37aae3ca0120b1f7d4e8f62b92"/><file name="Price.php" hash="e8e5e1bfa06057e2f96bc5e446c2b8f6"/><dir name="Product"><file name="Viewed.php" hash="2f6243fb6685c8aeee70778e836830b2"/></dir><file name="Product.php" hash="a6f43a8541cb9264ca55cd9fa1d2effa"/><dir name="Quote"><dir name="Item"><file name="Options.php" hash="f08f7977d64ebf7c27dccabe999e60e4"/></dir><file name="Item.php" hash="166d29efd6ec69aa19ad9cba9bfaac41"/></dir><file name="Quote.php" hash="ed0cef69a82ef286736b145f574a03bf"/><file name="Storeview.php" hash="66e21d2a1a1cae137bd3bfc2e0076504"/><file name="Subscription.php" hash="1a65b38f5297b0b58ba5a4d3b4e10e88"/><dir name="Wishlist"><dir name="Item"><file name="Options.php" hash="b6cfdfdab937c0349f6e8b2d5b86dce4"/></dir><file name="Item.php" hash="38a190a44f684c47926d9aac00fc167c"/></dir><file name="Wishlist.php" hash="fa73664e205ac185b2a4377f01ff2c2a"/><file name="readme.txt" hash="90f0b9c7e67b6e9ed1e172f28afcc660"/></dir><file name="AsyncPomSoapClient.php" hash="96963e05a0de2a3cad9189efdcafdac9"/><file name="Config.php" hash="63b64459885d8763fbb48820fd8c673c"/><dir name="Copernica"><file name="Abstract.php" hash="91c01c42bb4e37f3d29fb949e45b0aab"/><dir name="Address"><file name="Subprofile.php" hash="eeaf99907befedbb610bc7d034e2a801"/></dir><dir name="Entity"><file name="Address.php" hash="61baa384e1f33d16477d0fea0a5c738b"/><file name="Customer.php" hash="efe189bbcb5c790ea6affdbcb6f5476b"/><dir name="Order"><file name="Item.php" hash="f1eeb238241c3824f555ed87e5e12fab"/></dir><file name="Order.php" hash="c93854fbc14981839d45bda43d04a15c"/><file name="Product.php" hash="47b4ab2c57a54e42a3162958407c7840"/><dir name="Quote"><file name="Item.php" hash="3c0161f91e723665139e1aeb7c61a89f"/></dir><file name="Quote.php" hash="7b1f8b0d545f540b3952dda3a4814d7f"/><file name="Subscription.php" hash="aac9bb39731457c1b2842645601754ac"/><dir name="Wishlist"><file name="Item.php" hash="5da463b6775a0bb8c5347c9e8ab9324a"/></dir><file name="Wishlist.php" hash="40a89059a46ab5320aba5a8457d6d41a"/></dir><file name="Entity.php" hash="56df78821c248e9bf81bb3cc5e1556e0"/><dir name="Order"><file name="Subprofile.php" hash="565c834e73916318d2619c9af9e3073f"/></dir><dir name="Orderitem"><file name="Subprofile.php" hash="11d6b8a0a9e30e79af1ec4420b12434e"/></dir><dir name="Product"><dir name="Viewed"><file name="Subprofile.php" hash="1d5718bfc755cd3f0f96afcf019c9395"/></dir></dir><dir name="Profile"><file name="Customer.php" hash="c5b9ccf90d820b8b380fb4d854320ad6"/><file name="Order.php" hash="a9b0203ee469a3980c2e820eebc4aabc"/><file name="Quote.php" hash="22ec06d896275ed9da0a10da92849e13"/><file name="Subscription.php" hash="d6f682ddfb4822c6bb8dfef3150d8ea4"/></dir><file name="Profile.php" hash="02e1327d4d58109b936793023235994a"/><dir name="Quote"><dir name="Item"><file name="Subprofile.php" hash="f73b54b6573b8e635d8ac640a46df874"/></dir></dir><dir name="Wishlist"><dir name="Item"><file name="Subprofile.php" hash="b3fab4a13f3284a023606a71082b6809"/></dir></dir></dir><dir name="Error"><file name="Queue.php" hash="6eff7fb8aaa5fc2b04cafbe9ab869151"/></dir><file name="Error.php" hash="b8c1e456f0c398511d24ec5c9dab17d1"/><file name="Marketingsoftware.php" hash="05d6809f438672c945cbd36c2ee6a095"/><dir name="Mysql4"><dir name="Abandoned"><dir name="Cart"><file name="Collection.php" hash="5c6caa13d70a26b9c8fa246ae758e1bb"/></dir><file name="Cart.php" hash="a256e52ef1c583e6868d00d965b8aafc"/></dir><dir name="Config"><file name="Collection.php" hash="ea24387a0a68db651ce32d2bb93ccff0"/></dir><file name="Config.php" hash="0e248da13b5f4059e01fd9b8a082720e"/><dir name="Error"><dir name="Queue"><file name="Collection.php" hash="3c3ab32179c9d3d25d730b603cd1fa6d"/></dir><file name="Queue.php" hash="3d6d03ba0a14c2839ec8fafb536fa9e2"/></dir><dir name="Profile"><dir name="Cache"><file name="Collection.php" hash="fe9f9e4157dc686279b1d8311c672d28"/></dir><file name="Cache.php" hash="86a91eb32e4fe5243b333d02aa0b52ee"/></dir><dir name="Queue"><dir name="Item"><file name="Collection.php" hash="1f881d9c6d1137092965af6fd3199e44"/></dir><file name="Item.php" hash="e8db3465be56e3fa8561544585ebf745"/></dir><dir name="Sync"><dir name="Profile"><file name="Collection.php" hash="e37f86cf075a1bf172fc9469384c17b2"/></dir><file name="Profile.php" hash="56b8054ee3b3d2d7eb6093e6766212bc"/></dir></dir><file name="Observer.php" hash="c67454849a28e37fc9911743e907a9cb"/><file name="PomSoapClient.php" hash="7268370f5c2e7e40b2f6040b5c846ffe"/><dir name="Profile"><file name="Cache.php" hash="62e67510ca22ccfa941027af26cd513c"/></dir><dir name="Queue"><dir name="Event"><file name="Abstract.php" hash="f10362e1bbb6b004cf40490bce9b87b9"/><file name="Checkout.php" hash="f63bf7026f19e69890e8173f65400837"/><file name="Customer.php" hash="7ac49869fefd694106ddb1977a754066"/><file name="Factory.php" hash="c4a151702cc57bc2c05685ffd86b9e23"/><file name="Item.php" hash="7338f21f0a05c3d4902fc41a04e75947"/><file name="Order.php" hash="33a730a7ab7e6f46b3e72d142487daa1"/><file name="Quote.php" hash="611f9ca82a869b8dc5ba64a3119c608e"/><file name="Startsync.php" hash="2a472a41c0b4b145a4abfb6efe9002a2"/><file name="Subscription.php" hash="a57c953d30a8d60f505c2adbfff2b357"/><file name="View.php" hash="499c27e9c751fc1d542c0833a6c49c4a"/><dir name="Wishlist"><file name="Item.php" hash="574f0a95056ba5e73d82db2dea8acc1f"/></dir></dir><file name="Item.php" hash="2b690ba8da1e59d38338add167c14889"/><file name="Processor.php" hash="5279052790b9d4fe48e53464cadf5120"/></dir><dir name="QueueEvent"><file name="FileSync.php" hash="63c9d75f1d3d6723e126844892f55831"/></dir><dir name="Rest"><file name="Address.php" hash="bea5dca4b237cbf1cc08499241853b72"/><file name="Customer.php" hash="0b80358d34da1b277284ab2a2702bb80"/><dir name="Order"><file name="Item.php" hash="5f28bffcd47d3b04978ff0321adc6bac"/></dir><file name="Order.php" hash="a5c7c3005f27173cca4abf746b585c9f"/><file name="Product.php" hash="0582907ddd4315e1d573b9986f44fee7"/><dir name="Quote"><file name="Item.php" hash="92ffbd2681fd53774353fb5ebbbb06c5"/></dir><file name="Quote.php" hash="bc3204d648f4a4f216ab93722b88ea76"/><file name="Subscription.php" hash="a158f75b8311b621937df245be5beb83"/><dir name="Wishlist"><file name="Item.php" hash="5968643208609a982617cea663f7378a"/></dir><file name="Wishlist.php" hash="77ed8d0d30bbcff134e87117efb30708"/></dir><file name="Rest.php" hash="9c8f3197277fad399c40f51000911d13"/><dir name="Sync"><file name="Profile.php" hash="1d9b87c76b2ec1470e7185ec01bf3e2e"/><file name="Status.php" hash="28b31da86aad5fa5bf64fb3e2b09e0e9"/></dir></dir><dir name="controllers"><dir name="Adminhtml"><dir name="Marketingsoftware"><file name="AccessTokenController.php" hash="4f69ed4624902afd7100c66844334838"/><file name="AjaxcollectionController.php" hash="7044bab4729874196431fadaf54f9b7e"/><file name="AjaxcollectionfieldController.php" hash="adedd9277f1607f6fcdca1a049d98499"/><file name="AjaxdatabaseController.php" hash="b9652b5eb2a5487d291128179ff27cc8"/><file name="AjaxdatabasefieldController.php" hash="15534b4a534897ea26546bb1275531ea"/><file name="ExportController.php" hash="5e4efe87bd8468e168e77905823eec7b"/><file name="LinkController.php" hash="b2bab9e04fa06db5539ba9806fce599b"/><file name="SettingsController.php" hash="14d91dc7fa344284ecd02004fc6f77d8"/><file name="SyncController.php" hash="913e5eebcc985499cd8c331375787ec7"/></dir></dir><file name="CartController.php" hash="742767b72318a1b037fcaac411a0c7ad"/><file name="ProductController.php" hash="ae5f15a4faf5aeded896a0ca13955a87"/><file name="UnsubscribeController.php" hash="9f9a2ad9ccc7156c6efae8e13eccf3c8"/></dir><dir name="cron"><file name="clearCopernicaDatabase.php" hash="ce2872df7aa0d54bb67949da7f4cbe12"/><file name="detectAbandonedCarts.php" hash="33c38f817222ff9a6037b2e2c4b0b843"/><file name="fullSync.php" hash="596f1e38f5f9dd0ee3bd471b0ca05543"/><file name="processQueue.php" hash="5e9fe45eb9812cf616b842f9f85fe836"/></dir><dir name="data"><dir name="marketingsoftware_setup"><file name="data-upgrade-3.4.0-3.4.1.php" hash="517ac2b2c9a64f2e234cb1a4c8ff90da"/></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="f3372c2961c0a2e9d388240997f30a4f"/><file name="config.xml" hash="9fef459bb1dc9bc8a3115e7c24331f6c"/></dir><dir name="sql"><dir name="marketingsoftware_setup"><file name="mysql4-install-1.2.0.php" hash="99eef95d81744181bea56ce3b2838dc2"/><file name="mysql4-upgrade-1.1.5-1.1.6.php" hash="dbdede14f3814cfe74a969828d75d6ec"/><file name="mysql4-upgrade-1.1.6-1.1.7.php" hash="a717aa62efdf86edfb351d5e2ea194b6"/><file name="mysql4-upgrade-1.1.7-1.1.8.php" hash="e834059d501a0d50e32e427ee888df4e"/><file name="mysql4-upgrade-1.1.8-1.2.0.php" hash="d0f725335a866663a2b0597da015d361"/><file name="mysql4-upgrade-2.0.1-2.0.2.php" hash="d97c4f5d85806a7c22715f118e499b99"/><file name="mysql4-upgrade-2.1.0.1-2.2.0.php" hash="f3240bbc4a07548bb5aa9d6a571c955f"/><file name="mysql4-upgrade-2.2.0.1-2.3.0.php" hash="c8558171aaa41f7cbb4f14459a7979cd"/><file name="mysql4-upgrade-2.3.0-2.3.1.php" hash="1f0eac4bb3ac25934141a937e00641ab"/><file name="mysql4-upgrade-2.3.1-2.3.2.php" hash="9eaa34ef3f79d41e527e87f2238ffd78"/><file name="mysql4-upgrade-2.3.2-2.3.3.php" hash="0533cf49440b8d18b86d878a49c2cc8d"/><file name="mysql4-upgrade-2.3.3-2.3.4.php" hash="303ea277057d9d9ef54f79580b654073"/><file name="mysql4-upgrade-2.3.4-2.3.5.php" hash="e7dbca98126ad8bda9f3a864efac362e"/><file name="mysql4-upgrade-2.3.8-2.4.0.php" hash="cf82d771f8075cb36279c146d88ea33c"/><file name="mysql4-upgrade-2.4.0-2.4.1.php" hash="46ab2a0eb632aabe0c418245260bce61"/><file name="mysql4-upgrade-2.4.1-2.4.2.php" hash="8502c9dca934903ec6d05bf69a73f121"/><file name="mysql4-upgrade-2.4.2-2.4.3.php" hash="3364ade30c34eec7273d319d8c1d1247"/><file name="mysql4-upgrade-2.4.3-2.4.4.php" hash="5b68f4707cf5d85841b2cbd49d3ee9cf"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Copernica_MarketingSoftware.xml" hash="1d3e901ef934e74a837d779f815882d0"/></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="marketingsoftware"><file name="accessToken.phtml" hash="a469b1e89b523636c45c4609dcee53c3"/><file name="export.phtml" hash="70adeb24375c0b2e350808ddefa091b0"/><file name="link.phtml" hash="b6756106bc5471378a4e5851fbfa256d"/><file name="settings.phtml" hash="346948e8ed1097ed715e54a2a9b3b998"/><file name="sync.phtml" hash="ec3749674fab02f124bbc55d618a28e8"/></dir></dir></dir></dir></dir></target><target name="mageweb"><dir name="js"><dir name="copernica"><dir name="marketingsoftware"><file name="collection.js" hash="6c36cb25e5aa7c8396d9d4cf8331f2fc"/><file name="database.js" hash="3a71e50e837ca2fe049bbfe9001fbc2d"/><file name="field.js" hash="31ac2badb9f982e5cefca1006993c17f"/><file name="link.js" hash="0b2c0e242bbf3b785065b3c85b9aa235"/></dir></dir></dir></target></contents>
16
  <compatible/>
17
+ <dependencies><required><php><min>5.2.0</min><max>7.0.99</max></php><extension><name>PDO</name><min/><max/></extension><extension><name>curl</name><min/><max/></extension></required></dependencies>
18
  </package>