Copernica_MarketingSoftware - Version 2.2.0

Version Notes

New features:
- Now works with PHP 5.4
- Added tier prices to the product XML which can be fetched

Improvements:
- Maximum number of record for one sync increased to 300.
- Changed database field to longtext so really big serialized objects will be saved in full.

Download this release

Release Info

Developer Cream
Extension Copernica_MarketingSoftware
Version 2.2.0
Comparing to
See all releases


Code changes from version 2.1.0.1 to 2.2.0

Files changed (33) hide show
  1. app/code/community/Copernica/MarketingSoftware/Helper/Api.php +64 -1
  2. app/code/community/Copernica/MarketingSoftware/Helper/Config.php +44 -0
  3. app/code/community/Copernica/MarketingSoftware/Helper/Data.php +25 -0
  4. app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Address.php +83 -133
  5. app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Attributes.php +34 -45
  6. app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Customer.php +52 -99
  7. app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Name.php +9 -31
  8. app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Order.php +74 -137
  9. app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Order/Item.php +22 -66
  10. app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Order/Item/Options.php +27 -39
  11. app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Price.php +75 -98
  12. app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Product.php +106 -141
  13. app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Quote.php +67 -130
  14. app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Quote/Item.php +25 -67
  15. app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Quote/Item/Options.php +31 -44
  16. app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Storeview.php +17 -51
  17. app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Subscription.php +32 -60
  18. app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Viewedproduct.php +427 -0
  19. app/code/community/Copernica/MarketingSoftware/Model/Abstraction/readme.txt +0 -7
  20. app/code/community/Copernica/MarketingSoftware/Model/Copernica/Viewedproduct/Subprofile.php +113 -0
  21. app/code/community/Copernica/MarketingSoftware/Model/Observer.php +34 -2
  22. app/code/community/Copernica/MarketingSoftware/Model/Queue.php +1 -1
  23. app/code/community/Copernica/MarketingSoftware/Model/QueueEvent/Factory.php +7 -3
  24. app/code/community/Copernica/MarketingSoftware/Model/QueueEvent/StartSync.php +7 -7
  25. app/code/community/Copernica/MarketingSoftware/Model/QueueEvent/ViewedProductAdd.php +68 -0
  26. app/code/community/Copernica/MarketingSoftware/controllers/Adminhtml/Marketingsoftware/LinkController.php +9 -1
  27. app/code/community/Copernica/MarketingSoftware/controllers/ProductController.php +103 -48
  28. app/code/community/Copernica/MarketingSoftware/etc/config.xml +9 -1
  29. app/code/community/Copernica/MarketingSoftware/sql/marketingsoftware_setup/mysql4-upgrade-2.1.0.1-2.2.0.php +36 -0
  30. app/design/adminhtml/default/default/template/marketingsoftware/link.phtml +91 -1
  31. js/copernica/marketingsoftware/collection.js +1 -0
  32. js/copernica/marketingsoftware/database.js +8 -1
  33. package.xml +13 -7
app/code/community/Copernica/MarketingSoftware/Helper/Api.php CHANGED
@@ -131,6 +131,7 @@ class Copernica_MarketingSoftware_Helper_Api extends Mage_Core_Helper_Abstract
131
  $this->getCollectionId($config->getOrdersCollectionName());
132
  $this->getCollectionId($config->getOrderItemsCollectionName());
133
  $this->getCollectionId($config->getAddressesCollectionName());
 
134
 
135
  // else we have a valid login
136
  return true;
@@ -471,6 +472,34 @@ class Copernica_MarketingSoftware_Helper_Api extends Mage_Core_Helper_Abstract
471
  ));
472
  }
473
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
474
  /**
475
  * Does a database with the given name exist?.
476
  *
@@ -583,6 +612,7 @@ class Copernica_MarketingSoftware_Helper_Api extends Mage_Core_Helper_Abstract
583
  'orders' => array('order_id', 'quote_id'),
584
  'orderproducts' => array('item_id', 'order_id'),
585
  'addresses' => array('address_id'),
 
586
  );
587
 
588
  // is this a known collection type
@@ -651,6 +681,7 @@ class Copernica_MarketingSoftware_Helper_Api extends Mage_Core_Helper_Abstract
651
  'orders' => array('order_id', 'quote_id'),
652
  'orderproducts' => array('item_id', 'order_id'),
653
  'addresses' => array('address_id'),
 
654
  );
655
 
656
  // is this a known collection type
@@ -690,6 +721,7 @@ class Copernica_MarketingSoftware_Helper_Api extends Mage_Core_Helper_Abstract
690
  case "orders": return $this->validateOrdersField($database, $collectionName, $magentoFieldName, $copernicaFieldName);
691
  case "orderproducts": return $this->validateOrderProductsField($database, $collectionName, $magentoFieldName, $copernicaFieldName);
692
  case "addresses": return $this->validateAddressesField($database, $collectionName, $magentoFieldName, $copernicaFieldName);
 
693
 
694
  // no collection given use database
695
  default: return $this->validateDatabaseField($database, $magentoFieldName, $copernicaFieldName);
@@ -920,6 +952,37 @@ class Copernica_MarketingSoftware_Helper_Api extends Mage_Core_Helper_Abstract
920
  return 'ok';
921
  }
922
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
923
  /**
924
  * Repair the field, given the collection name.
925
  * When the collection name is empty the check is performed for the database
@@ -1095,7 +1158,7 @@ class Copernica_MarketingSoftware_Helper_Api extends Mage_Core_Helper_Abstract
1095
  */
1096
  protected function getFieldDefinition($collection, $fieldName, $definition)
1097
  {
1098
- if ($collection == 'cartproducts' || $collection == 'orderproducts')
1099
  {
1100
  // some special cases, for the cart / order products
1101
  switch($fieldName)
131
  $this->getCollectionId($config->getOrdersCollectionName());
132
  $this->getCollectionId($config->getOrderItemsCollectionName());
133
  $this->getCollectionId($config->getAddressesCollectionName());
134
+ $this->getCollectionId($config->getViewedProductCollectionName());
135
 
136
  // else we have a valid login
137
  return true;
472
  ));
473
  }
474
 
475
+ /**
476
+ * Update the subprofiles given, the profile identifier
477
+ * the collection name and the data
478
+ * @param string customer identifier
479
+ * @param Copernica_MarketingSoftware_Model_Copernica_Subprofile
480
+ */
481
+ public function updateViewedProductSubProfiles($profileID, $data)
482
+ {
483
+ // The collection name and id are determined
484
+ $collectionName = Mage::helper('marketingsoftware/config')->getViewedProductCollectionName();
485
+ $collectionId = $this->getCollectionId($collectionName);
486
+
487
+ // Update the subprofiles
488
+ $this->soapclient->Profile_updateSubProfiles(array(
489
+ 'id' => $profileID,
490
+ 'requirements' => array(
491
+ $this->soapclient->toObject(array(
492
+ 'fieldname' => 'id',
493
+ 'value' => $data->id(),
494
+ 'operator' => '='
495
+ ))
496
+ ),
497
+ 'collection' => $this->soapclient->toObject(array('id' => $collectionId)),
498
+ 'create' => true,
499
+ 'fields' => $data->toArray(),
500
+ ));
501
+ }
502
+
503
  /**
504
  * Does a database with the given name exist?.
505
  *
612
  'orders' => array('order_id', 'quote_id'),
613
  'orderproducts' => array('item_id', 'order_id'),
614
  'addresses' => array('address_id'),
615
+ 'viewedproduct' => array('product_id'),
616
  );
617
 
618
  // is this a known collection type
681
  'orders' => array('order_id', 'quote_id'),
682
  'orderproducts' => array('item_id', 'order_id'),
683
  'addresses' => array('address_id'),
684
+ 'viewedproduct' => array('product_id'),
685
  );
686
 
687
  // is this a known collection type
721
  case "orders": return $this->validateOrdersField($database, $collectionName, $magentoFieldName, $copernicaFieldName);
722
  case "orderproducts": return $this->validateOrderProductsField($database, $collectionName, $magentoFieldName, $copernicaFieldName);
723
  case "addresses": return $this->validateAddressesField($database, $collectionName, $magentoFieldName, $copernicaFieldName);
724
+ case "viewedproduct": return $this->validateViewedProductField($database, $collectionName, $magentoFieldName, $copernicaFieldName);
725
 
726
  // no collection given use database
727
  default: return $this->validateDatabaseField($database, $magentoFieldName, $copernicaFieldName);
952
  return 'ok';
953
  }
954
 
955
+ /**
956
+ * Validate the field from the cart items collection
957
+ * @param String name of the database in the customers Copernica environment
958
+ * @param String name of the collection in the customers Copernica environment
959
+ * @param String name of the field in our Magento plug-in
960
+ * @param String fieldname in the customers Copernica environment
961
+ * @return 'ok', 'notexists', 'notvalid'
962
+ */
963
+ protected function validateViewedProductField($database, $collectionName, $magentoFieldName, $copernicaFieldName)
964
+ {
965
+ // Get the id of this collection
966
+ $object = $this->collectionFieldData($database, $collectionName, $copernicaFieldName);
967
+
968
+ // does the field exist
969
+ if (!is_object($object) || $object->id == 0) return 'notexists';
970
+
971
+ // some special cases
972
+ switch($magentoFieldName)
973
+ {
974
+ case 'timestamp': return (in_array($object->type, array('empty_datetime', 'datetime'))) ? 'ok' : 'notvalid';
975
+ case 'url':
976
+ case 'image': return ($object->length > 100) ? 'ok' : 'notvalid';
977
+ case 'categories':
978
+ case 'options':
979
+ case 'attributes': return (($object->length > 150 || $object->big) && isset($object->lines) && $object->lines > 1) ? 'ok' : 'notvalid';
980
+ }
981
+
982
+ // default it is okay
983
+ return 'ok';
984
+ }
985
+
986
  /**
987
  * Repair the field, given the collection name.
988
  * When the collection name is empty the check is performed for the database
1158
  */
1159
  protected function getFieldDefinition($collection, $fieldName, $definition)
1160
  {
1161
+ if ($collection == 'cartproducts' || $collection == 'orderproducts' || $collection == 'viewedproducts')
1162
  {
1163
  // some special cases, for the cart / order products
1164
  switch($fieldName)
app/code/community/Copernica/MarketingSoftware/Helper/Config.php CHANGED
@@ -622,6 +622,50 @@ class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstrac
622
  return $this;
623
  }
624
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
625
  /**
626
  * Get the progress status for customers
627
  * This is the created timestamp of the most recent customer which has
622
  return $this;
623
  }
624
 
625
+ /**
626
+ * Get the name of the viewed products collection
627
+ * @return string
628
+ */
629
+ public function getViewedProductCollectionName()
630
+ {
631
+ return $this->_getConfig('viewed_product_collection_name');
632
+ }
633
+
634
+ /**
635
+ * Set the name of the viewed products collection
636
+ * @param String
637
+ * @return Copernica_MarketingSoftware_Helper_Config
638
+ */
639
+ public function setViewedProductCollectionName($value)
640
+ {
641
+ $this->_setConfig('viewed_product_collection_name', $value);
642
+ return $this;
643
+ }
644
+
645
+ /**
646
+ * Get the linked customer fields
647
+ * @return array assoc array of fields which have been linked
648
+ */
649
+ public function getLinkedViewedProductFields()
650
+ {
651
+ $value = $this->_getConfig('linked_viewed_product_fields');
652
+
653
+ // What value is found?
654
+ if (empty($value)) return array();
655
+ else return json_decode($value, true);
656
+ }
657
+
658
+ /**
659
+ * Get the linked customer fields
660
+ * @param array assoc array of fields which have been linked
661
+ * @return Copernica_MarketingSoftware_Helper_Config
662
+ */
663
+ public function setLinkedViewedProductFields($value)
664
+ {
665
+ $this->_setConfig('linked_viewed_product_fields', json_encode($value), true);
666
+ return $this;
667
+ }
668
+
669
  /**
670
  * Get the progress status for customers
671
  * This is the created timestamp of the most recent customer which has
app/code/community/Copernica/MarketingSoftware/Helper/Data.php CHANGED
@@ -153,6 +153,31 @@ class Copernica_MarketingSoftware_Helper_Data extends Mage_Core_Helper_Abstract
153
  );
154
  }
155
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
156
  /**
157
  * Get the version of this extension.
158
  *
153
  );
154
  }
155
 
156
+ /**
157
+ * Helper method returns all supported fields for
158
+ * the viewed product collection
159
+ * @return array
160
+ */
161
+ public function supportedViewedProductFields()
162
+ {
163
+ return array(
164
+ 'product_id' => 'product id',
165
+ 'name' => 'Product name',
166
+ 'sku' => 'SKU',
167
+ 'attribute_set' => 'Attribute set',
168
+ 'weight' => 'Weight',
169
+ 'price' => 'Price',
170
+ 'store_view' => 'Store view',
171
+ 'total_price' => 'Total price',
172
+ 'url' => 'Details URL',
173
+ 'image' => 'Image URL',
174
+ 'categories' => 'Categories',
175
+ 'options' => 'Product options',
176
+ 'attributes' => 'Product Attributes',
177
+ 'timestamp' => 'Timestamp',
178
+ );
179
+ }
180
+
181
  /**
182
  * Get the version of this extension.
183
  *
app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Address.php CHANGED
@@ -50,7 +50,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Address implements Serializa
50
  protected $telephone;
51
  protected $fax;
52
  protected $company;
53
- protected $customerId;
54
 
55
  /**
56
  * Sets the original model
@@ -59,17 +59,74 @@ class Copernica_MarketingSoftware_Model_Abstraction_Address implements Serializa
59
  */
60
  public function setOriginal($original)
61
  {
62
- $this->original = $original;
63
- return $this;
64
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
 
66
- /**
67
- * Returns the original model
68
- * @return Mage_Sales_Model_Order_Address|Mage_Sales_Model_Quote_Address|Mage_Customer_Model_Address
69
- */
70
- protected function original()
71
- {
72
- return $this->original;
 
 
73
  }
74
 
75
  /**
@@ -78,27 +135,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Address implements Serializa
78
  */
79
  public function type()
80
  {
81
- // Is this object still present?
82
- if (is_object($this->original))
83
- {
84
- if ($type = $this->original->getAddressType()) {
85
- return array($type);
86
- } else {
87
- $types = array();
88
- if ($customer = $this->original->getCustomer()) {
89
- $id = $this->original->getId();
90
- if ($customer->getData('default_billing') == $id) {
91
- $types[] = 'billing';
92
- }
93
- if ($customer->getData('default_shipping') == $id) {
94
- $types[] = 'shipping';
95
- }
96
- }
97
- return $types;
98
- }
99
- return Mage::getModel('marketingsoftware/abstraction_name')->setOriginal($this->original);
100
- }
101
- else return $this->type;
102
  }
103
 
104
  /**
@@ -107,25 +144,11 @@ class Copernica_MarketingSoftware_Model_Abstraction_Address implements Serializa
107
  */
108
  public function customer()
109
  {
110
- // Is this object still present?
111
- if (is_object($this->original))
112
- {
113
- //the order quote address model only returns a customer if it exists
114
- if ($customerId = $this->original->getCustomerId())
115
- {
116
- return Mage::getModel('marketingsoftware/abstraction_customer')->loadCustomer($customerId);
117
- }
118
- elseif ($customer = $this->original->getCustomer())
119
- {
120
- return Mage::getModel('marketingsoftware/abstraction_customer')->setOriginal($customer);
121
- }
122
- else return null;
123
- }
124
- elseif ($this->customerId)
125
- {
126
  return Mage::getModel('marketingsoftware/abstraction_customer')->loadCustomer($this->customerId);
 
 
127
  }
128
- else return null;
129
  }
130
 
131
  /**
@@ -135,26 +158,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Address implements Serializa
135
  */
136
  public function id()
137
  {
138
- // Is this object still present?
139
- if (is_object($this->original))
140
- {
141
- // Get the normal identifier
142
- $id = $this->original->getId();
143
-
144
- // switch depending on the type
145
- switch(get_class($this->original))
146
- {
147
- case "Mage_Sales_Model_Order_Address":
148
- if ($cid = $this->original->getCustomerAddressId()) return 'ca_'.$cid;
149
- return 'oa_'.$id;
150
- case "Mage_Sales_Model_Quote_Address":
151
- if ($cid = $this->original->getCustomerAddressId()) return 'ca_'.$cid;
152
- return 'qa_'.$id;
153
- case "Mage_Customer_Model_Address": return 'ca_'.$id;
154
- default: return $id;
155
- }
156
- }
157
- else return $this->id;
158
  }
159
 
160
  /**
@@ -163,12 +167,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Address implements Serializa
163
  */
164
  public function name()
165
  {
166
- // Is this object still present?
167
- if (is_object($this->original))
168
- {
169
- return Mage::getModel('marketingsoftware/abstraction_name')->setOriginal($this->original);
170
- }
171
- else return $this->name;
172
  }
173
 
174
  /**
@@ -177,16 +176,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Address implements Serializa
177
  */
178
  public function email()
179
  {
180
- // Is this object still present?
181
- if (is_object($this->original))
182
- {
183
- if ($email = $this->original->getEmail()) return $email;
184
- elseif (is_object($order = $this->original->getOrder())
185
- && $customerEmail = $order->getCustomerEmail()) return $customerEmail;
186
- elseif (is_object($quote = $this->original->getQuote())
187
- && $customerEmail = $quote->getCustomerEmail()) return $customerEmail;
188
- }
189
- else return $this->email;
190
  }
191
 
192
  /**
@@ -195,12 +185,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Address implements Serializa
195
  */
196
  public function street()
197
  {
198
- // Is this object still present?
199
- if (is_object($this->original))
200
- {
201
- return $this->original->getStreetFull();
202
- }
203
- else return $this->street;
204
  }
205
 
206
  /**
@@ -209,12 +194,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Address implements Serializa
209
  */
210
  public function city()
211
  {
212
- // Is this object still present?
213
- if (is_object($this->original))
214
- {
215
- return $this->original->getCity();
216
- }
217
- else return $this->city;
218
  }
219
 
220
  /**
@@ -223,12 +203,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Address implements Serializa
223
  */
224
  public function zipcode()
225
  {
226
- // Is this object still present?
227
- if (is_object($this->original))
228
- {
229
- return $this->original->getPostcode();
230
- }
231
- else return $this->zipcode;
232
  }
233
 
234
  /**
@@ -237,12 +212,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Address implements Serializa
237
  */
238
  public function state()
239
  {
240
- // Is this object still present?
241
- if (is_object($this->original))
242
- {
243
- return $this->original->getRegion();
244
- }
245
- else return $this->state;
246
  }
247
 
248
  /**
@@ -251,12 +221,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Address implements Serializa
251
  */
252
  public function countryCode()
253
  {
254
- // Is this object still present?
255
- if (is_object($this->original))
256
- {
257
- return $this->original->getCountryId();
258
- }
259
- else return $this->countryCode;
260
  }
261
 
262
  /**
@@ -265,12 +230,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Address implements Serializa
265
  */
266
  public function telephone()
267
  {
268
- // Is this object still present?
269
- if (is_object($this->original))
270
- {
271
- return $this->original->getTelephone();
272
- }
273
- else return $this->telephone;
274
  }
275
 
276
  /**
@@ -279,12 +239,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Address implements Serializa
279
  */
280
  public function fax()
281
  {
282
- // Is this object still present?
283
- if (is_object($this->original))
284
- {
285
- return $this->original->getFax();
286
- }
287
- else return $this->fax;
288
  }
289
 
290
  /**
@@ -293,12 +248,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Address implements Serializa
293
  */
294
  public function company()
295
  {
296
- // Is this object still present?
297
- if (is_object($this->original))
298
- {
299
- return $this->original->getCompany();
300
- }
301
- else return $this->company;
302
  }
303
 
304
  /**
50
  protected $telephone;
51
  protected $fax;
52
  protected $company;
53
+ protected $customerId = null;
54
 
55
  /**
56
  * Sets the original model
59
  */
60
  public function setOriginal($original)
61
  {
62
+ $this->name = Mage::getModel('marketingsoftware/abstraction_name')->setOriginal($original);
63
+ $this->street = $original->getStreetFull();
64
+ $this->city = $original->getCity();
65
+ $this->zipcode = $original->getPostcode();
66
+ $this->state = $original->getRegion();
67
+ $this->company = $original->getCompany();
68
+ $this->countryCode = $original->getCountryId();
69
+ $this->telephone = $original->getTelephone();
70
+ $this->fax = $original->getFax();
71
+
72
+ if ($type = $original->getAddressType()) {
73
+ $this->type = array($type);
74
+ } else {
75
+ $types = array();
76
+ if ($customer = $original->getCustomer()) {
77
+ $id = $original->getId();
78
+ if ($customer->getData('default_billing') == $id) {
79
+ $types[] = 'billing';
80
+ }
81
+ if ($customer->getData('default_shipping') == $id) {
82
+ $types[] = 'shipping';
83
+ }
84
+ }
85
+ $this->type = $types;
86
+ }
87
+
88
+ //the order quote address model only returns a customer if it exists
89
+ if ($customerId = $original->getCustomerId()) {
90
+ $this->customerId = $original->getCustomerId();
91
+ } elseif ($customer = $original->getCustomer()) {
92
+ $this->customerId = $customer->getId();
93
+ }
94
+
95
+ // Get the normal identifier
96
+ $id = $original->getId();
97
+
98
+ // switch depending on the type
99
+ switch(get_class($original)) {
100
+ case "Mage_Sales_Model_Order_Address":
101
+ if ($cid = $original->getCustomerAddressId()) {
102
+ $this->id = 'ca_'.$cid;
103
+ } else {
104
+ $this->id = 'oa_'.$id;
105
+ }
106
+ break;
107
+ case "Mage_Sales_Model_Quote_Address":
108
+ if ($cid = $original->getCustomerAddressId()) {
109
+ $this->id = 'ca_'.$cid;
110
+ } else {
111
+ $this->id = 'qa_'.$id;
112
+ }
113
+ break;
114
+ case "Mage_Customer_Model_Address":
115
+ $this->id = 'ca_'.$id;
116
+ break;
117
+ default:
118
+ $this->id = $id;
119
+ }
120
 
121
+ if ($email = $original->getEmail()) {
122
+ $this->email = $email;
123
+ } elseif (is_object($order = $original->getOrder()) && $customerEmail = $order->getCustomerEmail()) {
124
+ $this->email = $customerEmail;
125
+ } elseif (is_object($quote = $original->getQuote()) && $customerEmail = $quote->getCustomerEmail()) {
126
+ $this->email = $customerEmail;
127
+ }
128
+
129
+ return $this;
130
  }
131
 
132
  /**
135
  */
136
  public function type()
137
  {
138
+ return $this->type;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139
  }
140
 
141
  /**
144
  */
145
  public function customer()
146
  {
147
+ if ($this->customerId) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148
  return Mage::getModel('marketingsoftware/abstraction_customer')->loadCustomer($this->customerId);
149
+ } else {
150
+ return null;
151
  }
 
152
  }
153
 
154
  /**
158
  */
159
  public function id()
160
  {
161
+ return $this->id;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
162
  }
163
 
164
  /**
167
  */
168
  public function name()
169
  {
170
+ return $this->name;
 
 
 
 
 
171
  }
172
 
173
  /**
176
  */
177
  public function email()
178
  {
179
+ return $this->email;
 
 
 
 
 
 
 
 
 
180
  }
181
 
182
  /**
185
  */
186
  public function street()
187
  {
188
+ return $this->street;
 
 
 
 
 
189
  }
190
 
191
  /**
194
  */
195
  public function city()
196
  {
197
+ return $this->city;
 
 
 
 
 
198
  }
199
 
200
  /**
203
  */
204
  public function zipcode()
205
  {
206
+ return $this->zipcode;
 
 
 
 
 
207
  }
208
 
209
  /**
212
  */
213
  public function state()
214
  {
215
+ return $this->state;
 
 
 
 
 
216
  }
217
 
218
  /**
221
  */
222
  public function countryCode()
223
  {
224
+ return $this->countryCode;
 
 
 
 
 
225
  }
226
 
227
  /**
230
  */
231
  public function telephone()
232
  {
233
+ return $this->telephone;
 
 
 
 
 
234
  }
235
 
236
  /**
239
  */
240
  public function fax()
241
  {
242
+ return $this->fax;
 
 
 
 
 
243
  }
244
 
245
  /**
248
  */
249
  public function company()
250
  {
251
+ return $this->company;
 
 
 
 
 
252
  }
253
 
254
  /**
app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Attributes.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
@@ -29,12 +29,6 @@
29
  */
30
  class Copernica_MarketingSoftware_Model_Abstraction_Attributes implements Serializable
31
  {
32
- /**
33
- * The original object
34
- * @param Mage_Catalog_Model_Product
35
- */
36
- protected $original;
37
-
38
  /**
39
  * Predefine the internal fields
40
  */
@@ -48,7 +42,28 @@ class Copernica_MarketingSoftware_Model_Abstraction_Attributes implements Serial
48
  */
49
  public function setOriginal(Mage_Catalog_Model_Product $original)
50
  {
51
- $this->original = $original;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
  return $this;
53
  }
54
 
@@ -58,44 +73,18 @@ class Copernica_MarketingSoftware_Model_Abstraction_Attributes implements Serial
58
  */
59
  public function name()
60
  {
61
- // Is this object still present?
62
- if (is_object($this->original))
63
- {
64
- if ($attributeSet = Mage::getModel('eav/entity_attribute_set')->load($this->original->getAttributeSetId())) {
65
- return $attributeSet->getAttributeSetName();
66
- }
67
- }
68
- else return $this->name;
69
  }
70
 
71
  /**
72
- * Return an assoc array with attributes
 
 
73
  * @return array
74
  */
75
- public function attributes()
76
  {
77
- // Is this object still present?
78
- if (is_object($this->original))
79
- {
80
- $data = array();
81
- $attributes = $this->original->getAttributes();
82
-
83
- foreach ($attributes as $attribute) {
84
- if (
85
- $attribute->getIsUserDefined() &&
86
- in_array($attribute->getFrontendInput(), array('text', 'select', 'multiline', 'textarea', 'price', 'date', 'multiselect')) &&
87
- ($label = $attribute->getFrontendLabel()) &&
88
- ($value = $attribute->getFrontend()->getValue($this->original))
89
- ) {
90
- // is this an object which is not serializable
91
-
92
- // add the value to the array of data
93
- $data[$label] = $value;
94
- }
95
- }
96
- return $data;
97
- }
98
- else return $this->attributes;
99
  }
100
 
101
  /**
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
29
  */
30
  class Copernica_MarketingSoftware_Model_Abstraction_Attributes implements Serializable
31
  {
 
 
 
 
 
 
32
  /**
33
  * Predefine the internal fields
34
  */
42
  */
43
  public function setOriginal(Mage_Catalog_Model_Product $original)
44
  {
45
+ if ($attributeSet = Mage::getModel('eav/entity_attribute_set')->load($original->getAttributeSetId())) {
46
+ $this->name = $attributeSet->getAttributeSetName();
47
+ }
48
+
49
+ $data = array();
50
+ $attributes = $original->getAttributes();
51
+
52
+ foreach ($attributes as $attribute) {
53
+ if (
54
+ $attribute->getIsUserDefined() &&
55
+ in_array($attribute->getFrontendInput(), array('text', 'select', 'multiline', 'textarea', 'price', 'date', 'multiselect')) &&
56
+ ($label = $attribute->getAttributeCode()) &&
57
+ ($value = $attribute->getFrontend()->getValue($original))
58
+ ) {
59
+ // is this an object which is not serializable
60
+ // add the value to the array of data
61
+ $data[$label] = $value;
62
+ }
63
+ }
64
+ $this->attributes = $data;
65
+
66
+
67
  return $this;
68
  }
69
 
73
  */
74
  public function name()
75
  {
76
+ return $this->name;
 
 
 
 
 
 
 
77
  }
78
 
79
  /**
80
+ * Return an assoc array with attributes.
81
+ *
82
+ * @param Bool $useAttribcode
83
  * @return array
84
  */
85
+ public function attributes($useAttribCode = false)
86
  {
87
+ return $this->attributes;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
  }
89
 
90
  /**
app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Customer.php CHANGED
@@ -29,12 +29,6 @@
29
  */
30
  class Copernica_MarketingSoftware_Model_Abstraction_Customer implements Serializable
31
  {
32
- /**
33
- * The original object
34
- * @param Mage_Customer_Model_Customer
35
- */
36
- protected $original;
37
-
38
  /**
39
  * Predefine the internal fields
40
  */
@@ -56,8 +50,37 @@ class Copernica_MarketingSoftware_Model_Abstraction_Customer implements Serializ
56
  */
57
  public function setOriginal(Mage_Customer_Model_Customer $original)
58
  {
59
- $this->original = $original;
60
- return $this;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  }
62
 
63
  /**
@@ -79,10 +102,8 @@ class Copernica_MarketingSoftware_Model_Abstraction_Customer implements Serializ
79
  $customer = Mage::getModel('customer/customer')->load($customerId);
80
  if ($customer->getId()) {
81
  //set the original model if the customer exists
82
- $this->original = $customer;
83
- }
84
- else
85
- {
86
  // We did load a customer to make sure that it works more
87
  // or less, we assign the customer id here
88
  $this->id = $customerId;
@@ -96,12 +117,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Customer implements Serializ
96
  */
97
  public function id()
98
  {
99
- // Is this object still present?
100
- if (is_object($this->original))
101
- {
102
- return $this->original->getId();
103
- }
104
- else return $this->id;
105
  }
106
 
107
  /**
@@ -111,12 +127,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Customer implements Serializ
111
  */
112
  public function name()
113
  {
114
- // Is this object still present?
115
- if (is_object($this->original))
116
- {
117
- return Mage::getModel('marketingsoftware/abstraction_name')->setOriginal($this->original);
118
- }
119
- else return $this->name;
120
  }
121
 
122
  /**
@@ -125,12 +136,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Customer implements Serializ
125
  */
126
  public function email()
127
  {
128
- // Is this object still present?
129
- if (is_object($this->original))
130
- {
131
- return $this->original->getEmail();
132
- }
133
- else return $this->email;
134
  }
135
 
136
  /**
@@ -141,16 +147,11 @@ class Copernica_MarketingSoftware_Model_Abstraction_Customer implements Serializ
141
  */
142
  public function oldEmail()
143
  {
144
- if (is_object($this->original))
145
- {
146
- return $this->original->getOrigData('email');
147
- }
148
- elseif (isset($this->oldemail))
149
- {
150
- return $this->oldemail;
151
  }
152
-
153
- return $this->email();
154
  }
155
 
156
  /**
@@ -159,18 +160,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Customer implements Serializ
159
  */
160
  public function gender()
161
  {
162
- // Is this object still present?
163
- if (is_object($this->original)) {
164
- $options = $this->original->getAttribute('gender')->getSource()->getAllOptions();
165
-
166
- foreach ($options as $option) {
167
- if ($option['value'] == $this->original->getGender()) {
168
- return $option['label'];
169
- }
170
- }
171
- } else {
172
- return $this->gender;
173
- }
174
  }
175
 
176
  /**
@@ -179,18 +169,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Customer implements Serializ
179
  */
180
  public function subscription()
181
  {
182
- // Is this object still present?
183
- if (is_object($this->original))
184
- {
185
- $subscriber = Mage::getModel('newsletter/subscriber');
186
- if ($subscriber->loadByCustomer($this->original)->getId()) {
187
- if ($subscriber->getStoreId() === $this->original->getStoreId()) {
188
- return Mage::getModel('marketingsoftware/abstraction_subscription')->setOriginal($subscriber);
189
- }
190
- }
191
- } else {
192
- return $this->subscription;
193
- }
194
  }
195
 
196
  /**
@@ -199,12 +178,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Customer implements Serializ
199
  */
200
  public function group()
201
  {
202
- // Is this object still present?
203
- if (is_object($this->original))
204
- {
205
- return Mage::getModel('customer/group')->load($this->original->getGroupId())->getCode();
206
- }
207
- else return $this->group;
208
  }
209
 
210
  /**
@@ -216,10 +190,10 @@ class Copernica_MarketingSoftware_Model_Abstraction_Customer implements Serializ
216
  $data = array();
217
 
218
  //retrieve this customer's quote ids
219
- $quoteIDS = Mage::getResourceModel('sales/quote_collection')
220
  ->addFieldToFilter('customer_id', $this->id())->getAllIds();
221
 
222
- foreach ($quoteIDS as $id) {
223
  $data[] = Mage::getModel('marketingsoftware/abstraction_quote')->loadQuote($id);
224
  }
225
  return $data;
@@ -234,10 +208,10 @@ class Copernica_MarketingSoftware_Model_Abstraction_Customer implements Serializ
234
  $data = array();
235
 
236
  //retrieve this customer's order ids
237
- $orderIDS = Mage::getResourceModel('sales/order_collection')
238
  ->addAttributeToFilter('customer_id', $this->id())->getAllIds();
239
 
240
- foreach ($orderIDS as $id) {
241
  $data[] = Mage::getModel('marketingsoftware/abstraction_order')->loadOrder($id);
242
  }
243
  return $data;
@@ -249,18 +223,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Customer implements Serializ
249
  */
250
  public function addresses()
251
  {
252
- // Is this object still present?
253
- if (is_object($this->original))
254
- {
255
- $data = array();
256
- //retrieve this customer's addresses
257
- $addresses = $this->original->getAddressesCollection();
258
- foreach ($addresses as $address) {
259
- $data[] = Mage::getModel('marketingsoftware/abstraction_address')->setOriginal($address);
260
- }
261
- return $data;
262
- }
263
- else return $this->addresses;
264
  }
265
 
266
  /**
@@ -269,12 +232,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Customer implements Serializ
269
  */
270
  public function storeview()
271
  {
272
- // Is this object still present?
273
- if (is_object($this->original))
274
- {
275
- return Mage::getModel('marketingsoftware/abstraction_storeview')->setOriginal($this->original->getStore());
276
- }
277
- else return $this->storeview;
278
  }
279
 
280
  /**
@@ -304,9 +262,6 @@ class Copernica_MarketingSoftware_Model_Abstraction_Customer implements Serializ
304
  */
305
  public function unserialize($string)
306
  {
307
- // Get the data into an array
308
- $data = unserialize($string);
309
-
310
  // assign the data to the internal vars
311
  list(
312
  $this->id,
@@ -316,11 +271,9 @@ class Copernica_MarketingSoftware_Model_Abstraction_Customer implements Serializ
316
  $this->subscription,
317
  $this->group,
318
  $this->addresses,
319
- $this->gender
320
- ) = $data;
321
-
322
- // do we have a storeview available?
323
- if (isset($data[8])) $this->storeview = $data[8];
324
 
325
  return $this;
326
  }
29
  */
30
  class Copernica_MarketingSoftware_Model_Abstraction_Customer implements Serializable
31
  {
 
 
 
 
 
 
32
  /**
33
  * Predefine the internal fields
34
  */
50
  */
51
  public function setOriginal(Mage_Customer_Model_Customer $original)
52
  {
53
+ $this->id = $original->getId();
54
+ $this->name = Mage::getModel('marketingsoftware/abstraction_name')->setOriginal($original);
55
+ $this->email = $original->getEmail();
56
+ $this->oldemail = $original->getOrigData('email');
57
+ $this->group = Mage::getModel('customer/group')->load($original->getGroupId())->getCode();
58
+ $this->storeview = Mage::getModel('marketingsoftware/abstraction_storeview')->setOriginal($original->getStore());
59
+
60
+ $options = $original->getAttribute('gender')->getSource()->getAllOptions();
61
+
62
+ foreach ($options as $option) {
63
+ if ($option['value'] == $original->getGender()) {
64
+ $this->gender = $option['label'];
65
+ }
66
+ }
67
+
68
+ $subscriber = Mage::getModel('newsletter/subscriber');
69
+ if ($subscriber->loadByCustomer($original)->getId()) {
70
+ if ($subscriber->getStoreId() === $original->getStoreId()) {
71
+ $this->subscription = Mage::getModel('marketingsoftware/abstraction_subscription')->setOriginal($subscriber);
72
+ }
73
+ }
74
+
75
+ $data = array();
76
+ //retrieve this customer's addresses
77
+ $addresses = $original->getAddressesCollection();
78
+ foreach ($addresses as $address) {
79
+ $data[] = Mage::getModel('marketingsoftware/abstraction_address')->setOriginal($address);
80
+ }
81
+ $this->addresses = $data;
82
+
83
+ return $this;
84
  }
85
 
86
  /**
102
  $customer = Mage::getModel('customer/customer')->load($customerId);
103
  if ($customer->getId()) {
104
  //set the original model if the customer exists
105
+ $this->setOriginal($customer);
106
+ } else {
 
 
107
  // We did load a customer to make sure that it works more
108
  // or less, we assign the customer id here
109
  $this->id = $customerId;
117
  */
118
  public function id()
119
  {
120
+ return $this->id;
 
 
 
 
 
121
  }
122
 
123
  /**
127
  */
128
  public function name()
129
  {
130
+ return $this->name;
 
 
 
 
 
131
  }
132
 
133
  /**
136
  */
137
  public function email()
138
  {
139
+ return $this->email;
 
 
 
 
 
140
  }
141
 
142
  /**
147
  */
148
  public function oldEmail()
149
  {
150
+ if (isset($this->oldemail)) {
151
+ return $this->oldemail;
152
+ } else {
153
+ return $this->email();
 
 
 
154
  }
 
 
155
  }
156
 
157
  /**
160
  */
161
  public function gender()
162
  {
163
+ return $this->gender;
 
 
 
 
 
 
 
 
 
 
 
164
  }
165
 
166
  /**
169
  */
170
  public function subscription()
171
  {
172
+ return $this->subscription;
 
 
 
 
 
 
 
 
 
 
 
173
  }
174
 
175
  /**
178
  */
179
  public function group()
180
  {
181
+ return $this->group;
 
 
 
 
 
182
  }
183
 
184
  /**
190
  $data = array();
191
 
192
  //retrieve this customer's quote ids
193
+ $quoteIds = Mage::getResourceModel('sales/quote_collection')
194
  ->addFieldToFilter('customer_id', $this->id())->getAllIds();
195
 
196
+ foreach ($quoteIds as $id) {
197
  $data[] = Mage::getModel('marketingsoftware/abstraction_quote')->loadQuote($id);
198
  }
199
  return $data;
208
  $data = array();
209
 
210
  //retrieve this customer's order ids
211
+ $orderIds = Mage::getResourceModel('sales/order_collection')
212
  ->addAttributeToFilter('customer_id', $this->id())->getAllIds();
213
 
214
+ foreach ($orderIds as $id) {
215
  $data[] = Mage::getModel('marketingsoftware/abstraction_order')->loadOrder($id);
216
  }
217
  return $data;
223
  */
224
  public function addresses()
225
  {
226
+ return $this->addresses;
 
 
 
 
 
 
 
 
 
 
 
227
  }
228
 
229
  /**
232
  */
233
  public function storeview()
234
  {
235
+ return $this->storeview;
 
 
 
 
 
236
  }
237
 
238
  /**
262
  */
263
  public function unserialize($string)
264
  {
 
 
 
265
  // assign the data to the internal vars
266
  list(
267
  $this->id,
271
  $this->subscription,
272
  $this->group,
273
  $this->addresses,
274
+ $this->gender,
275
+ $this->storeview
276
+ ) = unserialize($string);
 
 
277
 
278
  return $this;
279
  }
app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Name.php CHANGED
@@ -29,12 +29,6 @@
29
  */
30
  class Copernica_MarketingSoftware_Model_Abstraction_Name implements Serializable
31
  {
32
- /**
33
- * The original object
34
- * @param Mage_Customer_Model_Customer|Mage_Sales_Model_Order_Address|Mage_Sales_Model_Quote_Address|Mage_Customer_Model_Address
35
- */
36
- protected $original;
37
-
38
  /**
39
  * Predefine the internal fields
40
  */
@@ -50,7 +44,11 @@ class Copernica_MarketingSoftware_Model_Abstraction_Name implements Serializable
50
  */
51
  public function setOriginal($original)
52
  {
53
- $this->original = $original;
 
 
 
 
54
  return $this;
55
  }
56
 
@@ -60,12 +58,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Name implements Serializable
60
  */
61
  public function firstname()
62
  {
63
- // Is this object still present?
64
- if (is_object($this->original))
65
- {
66
- return $this->original->getFirstname();
67
- }
68
- else return $this->firstname;
69
  }
70
 
71
  /**
@@ -75,12 +68,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Name implements Serializable
75
  */
76
  public function prefix()
77
  {
78
- // Is this object still present?
79
- if (is_object($this->original))
80
- {
81
- return $this->original->getPrefix();
82
- }
83
- else return $this->prefix;
84
  }
85
 
86
  /**
@@ -90,12 +78,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Name implements Serializable
90
  */
91
  public function middlename()
92
  {
93
- // Is this object still present?
94
- if (is_object($this->original))
95
- {
96
- return $this->original->getMiddlename();
97
- }
98
- else return $this->middlename;
99
  }
100
 
101
  /**
@@ -104,12 +87,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Name implements Serializable
104
  */
105
  public function lastname()
106
  {
107
- // Is this object still present?
108
- if (is_object($this->original))
109
- {
110
- return $this->original->getLastname();
111
- }
112
- else return $this->lastname;
113
  }
114
 
115
  /**
29
  */
30
  class Copernica_MarketingSoftware_Model_Abstraction_Name implements Serializable
31
  {
 
 
 
 
 
 
32
  /**
33
  * Predefine the internal fields
34
  */
44
  */
45
  public function setOriginal($original)
46
  {
47
+ $this->firstname = $original->getFirstname();
48
+ $this->prefix = $original->getPrefix();
49
+ $this->middlename = $original->getMiddlename();
50
+ $this->lastname = $original->getLastname();
51
+
52
  return $this;
53
  }
54
 
58
  */
59
  public function firstname()
60
  {
61
+ return $this->firstname;
 
 
 
 
 
62
  }
63
 
64
  /**
68
  */
69
  public function prefix()
70
  {
71
+ return $this->prefix;
 
 
 
 
 
72
  }
73
 
74
  /**
78
  */
79
  public function middlename()
80
  {
81
+ return $this->middlename;
 
 
 
 
 
82
  }
83
 
84
  /**
87
  */
88
  public function lastname()
89
  {
90
+ return $this->lastname;
 
 
 
 
 
91
  }
92
 
93
  /**
app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Order.php CHANGED
@@ -29,11 +29,14 @@
29
  */
30
  class Copernica_MarketingSoftware_Model_Abstraction_Order implements Serializable
31
  {
32
- /**
33
- * The original object
34
- * @param Mage_Sales_Model_Order
35
- */
36
- protected $original;
 
 
 
37
 
38
  /**
39
  * Predefine the internal fields
@@ -56,7 +59,6 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order implements Serializabl
56
  protected $shippingDescription;
57
  protected $paymentDescription;
58
 
59
-
60
  /**
61
  * Sets the original model
62
  * @param Mage_Sales_Model_Order $original
@@ -64,7 +66,50 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order implements Serializabl
64
  */
65
  public function setOriginal(Mage_Sales_Model_Order $original)
66
  {
67
- $this->original = $original;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
  return $this;
69
  }
70
 
@@ -78,7 +123,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order implements Serializabl
78
  $order = Mage::getModel('sales/order')->load($orderId);
79
  if ($order->getId()) {
80
  //set the original model if the quote exists
81
- $this->original = $order;
82
  }
83
  return $this;
84
  }
@@ -89,12 +134,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order implements Serializabl
89
  */
90
  public function id()
91
  {
92
- // Is this object still present?
93
- if (is_object($this->original))
94
- {
95
- return $this->original->getId();
96
- }
97
- else return $this->id;
98
  }
99
 
100
  /**
@@ -103,12 +143,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order implements Serializabl
103
  */
104
  public function incrementId()
105
  {
106
- // Is this object still present?
107
- if (is_object($this->original))
108
- {
109
- return $this->original->getIncrementId();
110
- }
111
- else return $this->incrementId;
112
  }
113
 
114
  /**
@@ -117,12 +152,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order implements Serializabl
117
  */
118
  public function quoteId()
119
  {
120
- // Is this object still present?
121
- if (is_object($this->original))
122
- {
123
- return $this->original->getQuoteId();
124
- }
125
- else return $this->quoteId;
126
  }
127
 
128
  /**
@@ -131,12 +161,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order implements Serializabl
131
  */
132
  public function state()
133
  {
134
- // Is this object still present?
135
- if (is_object($this->original))
136
- {
137
- return $this->original->getState();
138
- }
139
- else return $this->state;
140
  }
141
 
142
  /**
@@ -145,12 +170,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order implements Serializabl
145
  */
146
  public function status()
147
  {
148
- // Is this object still present?
149
- if (is_object($this->original))
150
- {
151
- return $this->original->getStatus();
152
- }
153
- else return $this->status;
154
  }
155
 
156
  /**
@@ -159,12 +179,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order implements Serializabl
159
  */
160
  public function quantity()
161
  {
162
- // Is this object still present?
163
- if (is_object($this->original))
164
- {
165
- return $this->original->getTotalQtyOrdered();
166
- }
167
- else return $this->quantity;
168
  }
169
 
170
  /**
@@ -173,12 +188,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order implements Serializabl
173
  */
174
  public function currency()
175
  {
176
- // Is this object still present?
177
- if (is_object($this->original))
178
- {
179
- return $this->original->getOrderCurrencyCode();
180
- }
181
- else return $this->currency;
182
  }
183
 
184
  /**
@@ -188,13 +198,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order implements Serializabl
188
  */
189
  public function price()
190
  {
191
- // Is this object still present?
192
- if (is_object($this->original))
193
- {
194
- // Note that the price may consist of multiple elements
195
- return Mage::getModel('marketingsoftware/abstraction_price')->setOriginal($this->original);
196
- }
197
- else return $this->price;
198
  }
199
 
200
  /**
@@ -203,12 +207,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order implements Serializabl
203
  */
204
  public function weight()
205
  {
206
- // Is this object still present?
207
- if (is_object($this->original))
208
- {
209
- return $this->original->getWeight();
210
- }
211
- else return $this->weight;
212
  }
213
 
214
  /**
@@ -217,12 +216,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order implements Serializabl
217
  */
218
  public function storeview()
219
  {
220
- // Is this object still present?
221
- if (is_object($this->original))
222
- {
223
- return Mage::getModel('marketingsoftware/abstraction_storeview')->setOriginal($this->original->getStore());
224
- }
225
- else return $this->storeview;
226
  }
227
 
228
  /**
@@ -231,17 +225,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order implements Serializabl
231
  */
232
  public function items()
233
  {
234
- // Is this object still present?
235
- if (is_object($this->original))
236
- {
237
- $data = array();
238
- $items = $this->original->getAllVisibleItems();
239
- foreach ($items as $item) {
240
- $data[] = Mage::getModel('marketingsoftware/abstraction_order_item')->setOriginal($item);
241
- }
242
- return $data;
243
- }
244
- else return $this->items;
245
  }
246
 
247
  /**
@@ -250,12 +234,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order implements Serializabl
250
  */
251
  public function timestamp()
252
  {
253
- // Is this object still present?
254
- if (is_object($this->original))
255
- {
256
- return $this->original->getUpdatedAt();
257
- }
258
- else return $this->timestamp;
259
  }
260
 
261
  /**
@@ -264,21 +243,11 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order implements Serializabl
264
  */
265
  public function customer()
266
  {
267
- // Is this object still present?
268
- if (is_object($this->original))
269
- {
270
- //the order model only returns a customer if it exists
271
- if ($customerId = $this->original->getCustomerId()) {
272
- return Mage::getModel('marketingsoftware/abstraction_customer')->loadCustomer($customerId);
273
- } else {
274
- return null;
275
- }
276
- }
277
- elseif ($this->customerId)
278
- {
279
  return Mage::getModel('marketingsoftware/abstraction_customer')->loadCustomer($this->customerId);
 
 
280
  }
281
- else return null;
282
  }
283
 
284
  /**
@@ -287,18 +256,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order implements Serializabl
287
  */
288
  public function addresses()
289
  {
290
- // Is this object still present?
291
- if (is_object($this->original))
292
- {
293
- $data = array();
294
- //retrieve this quote's addresses
295
- $addresses = $this->original->getAddressesCollection();
296
- foreach ($addresses as $address) {
297
- $data[] = Mage::getModel('marketingsoftware/abstraction_address')->setOriginal($address);
298
- }
299
- return $data;
300
- }
301
- else return $this->addresses;
302
  }
303
 
304
  /**
@@ -307,12 +265,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order implements Serializabl
307
  */
308
  public function shippingDescription()
309
  {
310
- // Is this object still present?
311
- if (is_object($this->original))
312
- {
313
- return $this->original->getShippingDescription();
314
- }
315
- else return $this->shippingDescription;
316
  }
317
 
318
  /**
@@ -321,19 +274,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order implements Serializabl
321
  */
322
  public function paymentDescription()
323
  {
324
- // Is this object still present?
325
- if (is_object($this->original))
326
- {
327
- if ($payment = $this->original->getPayment()) {
328
- try {
329
- return $payment->getMethodInstance()->getTitle();
330
- } catch (Mage_Core_Exception $exception) {
331
- return null;
332
- }
333
- }
334
- return null;
335
- }
336
- else return $this->paymentDescription;
337
  }
338
 
339
  /**
@@ -342,12 +283,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order implements Serializabl
342
  */
343
  public function customerIP()
344
  {
345
- // Is this object still present?
346
- if (is_object($this->original))
347
- {
348
- return $this->original->getRemoteIp();
349
- }
350
- else return $this->customerIP;
351
  }
352
 
353
  /**
@@ -355,7 +291,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order implements Serializabl
355
  * @return string
356
  */
357
  public function serialize()
358
- {
359
  // serialize the data
360
  return serialize(array(
361
  $this->id(),
@@ -404,6 +340,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order implements Serializabl
404
  $this->shippingDescription,
405
  $this->paymentDescription
406
  ) = unserialize($string);
 
407
  return $this;
408
  }
409
  }
29
  */
30
  class Copernica_MarketingSoftware_Model_Abstraction_Order implements Serializable
31
  {
32
+ /**
33
+ * Getting payment name does not work with Klarna. Klarna gets the
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
 
41
  /**
42
  * Predefine the internal fields
59
  protected $shippingDescription;
60
  protected $paymentDescription;
61
 
 
62
  /**
63
  * Sets the original model
64
  * @param Mage_Sales_Model_Order $original
66
  */
67
  public function setOriginal(Mage_Sales_Model_Order $original)
68
  {
69
+ $this->id = $original->getId();
70
+ $this->incrementId = $original->getIncrementId();
71
+ $this->quoteId = $original->getQuoteId();
72
+ $this->state = $original->getState();
73
+ $this->status = $original->getStatus();
74
+ $this->quantity = $original->getTotalQtyOrdered();
75
+ $this->currency = $original->getOrderCurrencyCode();
76
+ $this->price = Mage::getModel('marketingsoftware/abstraction_price')->setOriginal($original);
77
+ $this->weight = $original->getWeight();
78
+ $this->storeview = Mage::getModel('marketingsoftware/abstraction_storeview')->setOriginal($original->getStore());
79
+ $this->timestamp = $original->getUpdatedAt();
80
+ $this->shippingDescription = $original->getShippingDescription();
81
+ $this->customerIP = $original->getRemoteIp();
82
+
83
+ $data = array();
84
+ $items = $original->getAllVisibleItems();
85
+ foreach ($items as $item) {
86
+ $data[] = Mage::getModel('marketingsoftware/abstraction_order_item')->setOriginal($item);
87
+ }
88
+ $this->items = $data;
89
+
90
+ //the order model only returns a customer if it exists
91
+ if ($customerId = $original->getCustomerId()) {
92
+ $this->customerId = $customerId;
93
+ }
94
+
95
+ $data = array();
96
+ //retrieve this quote's addresses
97
+ $addresses = $original->getAddressesCollection();
98
+ foreach ($addresses as $address) {
99
+ $data[] = Mage::getModel('marketingsoftware/abstraction_address')->setOriginal($address);
100
+ }
101
+ $this->addresses = $data;
102
+
103
+ if ($payment = $original->getPayment()) {
104
+ try {
105
+ if ($payment->getMethod() == self::PAYMENT_METHOD_KLARNA) {
106
+ $this->paymentDescription = 'Klarna';
107
+ } else {
108
+ $this->paymentDescription = $payment->getMethodInstance()->getTitle();
109
+ }
110
+ } catch (Mage_Core_Exception $exception) { }
111
+ }
112
+
113
  return $this;
114
  }
115
 
123
  $order = Mage::getModel('sales/order')->load($orderId);
124
  if ($order->getId()) {
125
  //set the original model if the quote exists
126
+ $this->setOriginal($order);
127
  }
128
  return $this;
129
  }
134
  */
135
  public function id()
136
  {
137
+ return $this->id;
 
 
 
 
 
138
  }
139
 
140
  /**
143
  */
144
  public function incrementId()
145
  {
146
+ return $this->incrementId;
 
 
 
 
 
147
  }
148
 
149
  /**
152
  */
153
  public function quoteId()
154
  {
155
+ return $this->quoteId;
 
 
 
 
 
156
  }
157
 
158
  /**
161
  */
162
  public function state()
163
  {
164
+ return $this->state;
 
 
 
 
 
165
  }
166
 
167
  /**
170
  */
171
  public function status()
172
  {
173
+ return $this->status;
 
 
 
 
 
174
  }
175
 
176
  /**
179
  */
180
  public function quantity()
181
  {
182
+ return $this->quantity;
 
 
 
 
 
183
  }
184
 
185
  /**
188
  */
189
  public function currency()
190
  {
191
+ return $this->currency;
 
 
 
 
 
192
  }
193
 
194
  /**
198
  */
199
  public function price()
200
  {
201
+ return $this->price;
 
 
 
 
 
 
202
  }
203
 
204
  /**
207
  */
208
  public function weight()
209
  {
210
+ return $this->weight;
 
 
 
 
 
211
  }
212
 
213
  /**
216
  */
217
  public function storeview()
218
  {
219
+ return $this->storeview;
 
 
 
 
 
220
  }
221
 
222
  /**
225
  */
226
  public function items()
227
  {
228
+ return $this->items;
 
 
 
 
 
 
 
 
 
 
229
  }
230
 
231
  /**
234
  */
235
  public function timestamp()
236
  {
237
+ return $this->timestamp;
 
 
 
 
 
238
  }
239
 
240
  /**
243
  */
244
  public function customer()
245
  {
246
+ if ($this->customerId) {
 
 
 
 
 
 
 
 
 
 
 
247
  return Mage::getModel('marketingsoftware/abstraction_customer')->loadCustomer($this->customerId);
248
+ } else {
249
+ return null;
250
  }
 
251
  }
252
 
253
  /**
256
  */
257
  public function addresses()
258
  {
259
+ return $this->addresses;
 
 
 
 
 
 
 
 
 
 
 
260
  }
261
 
262
  /**
265
  */
266
  public function shippingDescription()
267
  {
268
+ return $this->shippingDescription;
 
 
 
 
 
269
  }
270
 
271
  /**
274
  */
275
  public function paymentDescription()
276
  {
277
+ return $this->paymentDescription;
 
 
 
 
 
 
 
 
 
 
 
 
278
  }
279
 
280
  /**
283
  */
284
  public function customerIP()
285
  {
286
+ return $this->customerIP;
 
 
 
 
 
287
  }
288
 
289
  /**
291
  * @return string
292
  */
293
  public function serialize()
294
+ {
295
  // serialize the data
296
  return serialize(array(
297
  $this->id(),
340
  $this->shippingDescription,
341
  $this->paymentDescription
342
  ) = unserialize($string);
343
+
344
  return $this;
345
  }
346
  }
app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Order/Item.php CHANGED
@@ -29,12 +29,6 @@
29
  */
30
  class Copernica_MarketingSoftware_Model_Abstraction_Order_Item implements Serializable
31
  {
32
- /**
33
- * The original object
34
- * @param Mage_Sales_Model_Order_Item
35
- */
36
- protected $original;
37
-
38
  /**
39
  * Predefine the internal fields
40
  */
@@ -54,7 +48,20 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order_Item implements Serial
54
  */
55
  public function setOriginal(Mage_Sales_Model_Order_Item $original)
56
  {
57
- $this->original = $original;
 
 
 
 
 
 
 
 
 
 
 
 
 
58
  return $this;
59
  }
60
 
@@ -64,12 +71,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order_Item implements Serial
64
  */
65
  public function id()
66
  {
67
- // Is this object still present?
68
- if (is_object($this->original))
69
- {
70
- return $this->original->getId();
71
- }
72
- else return $this->id;
73
  }
74
 
75
  /**
@@ -78,16 +80,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order_Item implements Serial
78
  */
79
  public function order()
80
  {
81
- // Is this object still present?
82
- if (is_object($this->original))
83
- {
84
- if ($order = $this->original->getOrder()) {
85
- return Mage::getModel('marketingsoftware/abstraction_order')->setOriginal($order);
86
- } else {
87
- return null;
88
- }
89
- }
90
- else return Mage::getModel('marketingsoftware/abstraction_order')->loadOrder($this->orderId);
91
  }
92
 
93
  /**
@@ -96,12 +89,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order_Item implements Serial
96
  */
97
  public function quantity()
98
  {
99
- // Is this object still present?
100
- if (is_object($this->original))
101
- {
102
- return $this->original->getQtyOrdered();
103
- }
104
- else return $this->quantity;
105
  }
106
 
107
  /**
@@ -111,13 +99,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order_Item implements Serial
111
  */
112
  public function price()
113
  {
114
- // Is this object still present?
115
- if (is_object($this->original))
116
- {
117
- // Note that the price may consist of multiple elements
118
- return Mage::getModel('marketingsoftware/abstraction_price')->setOriginal($this->original);
119
- }
120
- else return $this->price;
121
  }
122
 
123
  /**
@@ -126,12 +108,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order_Item implements Serial
126
  */
127
  public function weight()
128
  {
129
- // Is this object still present?
130
- if (is_object($this->original))
131
- {
132
- return $this->original->getWeight();
133
- }
134
- else return $this->weight;
135
  }
136
 
137
  /**
@@ -140,12 +117,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order_Item implements Serial
140
  */
141
  public function timestamp()
142
  {
143
- // Is this object still present?
144
- if (is_object($this->original))
145
- {
146
- return $this->original->getUpdatedAt();
147
- }
148
- else return $this->timestamp;
149
  }
150
 
151
  /**
@@ -154,18 +126,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order_Item implements Serial
154
  */
155
  public function options()
156
  {
157
- // Is this object still present?
158
- if (is_object($this->original))
159
- {
160
- $options = Mage::getModel('marketingsoftware/abstraction_order_item_options')->setOriginal($this->original);
161
- if ($options->attributes()) {
162
- //only return option object if it this order actually has options
163
- return $options;
164
- } else {
165
- return null;
166
- }
167
- }
168
- else return $this->options;
169
  }
170
 
171
  /**
@@ -174,12 +135,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order_Item implements Serial
174
  */
175
  public function product()
176
  {
177
- // Is this object still present?
178
- if (is_object($this->original))
179
- {
180
- return Mage::getModel('marketingsoftware/abstraction_product')->setOriginal($this->original);
181
- }
182
- else return $this->product;
183
  }
184
 
185
  /**
29
  */
30
  class Copernica_MarketingSoftware_Model_Abstraction_Order_Item implements Serializable
31
  {
 
 
 
 
 
 
32
  /**
33
  * Predefine the internal fields
34
  */
48
  */
49
  public function setOriginal(Mage_Sales_Model_Order_Item $original)
50
  {
51
+ $this->id = $original->getId();
52
+ $this->orderId = $original->getOrder()->getId();
53
+ $this->quantity = $original->getQtyOrdered();
54
+ $this->price = Mage::getModel('marketingsoftware/abstraction_price')->setOriginal($original);
55
+ $this->weight = $original->getWeight();
56
+ $this->timestamp = $original->getUpdatedAt();
57
+ $this->product = Mage::getModel('marketingsoftware/abstraction_product')->setOriginal($original);
58
+
59
+ $options = Mage::getModel('marketingsoftware/abstraction_order_item_options')->setOriginal($original);
60
+ if ($options->attributes()) {
61
+ //only return option object if it this order actually has options
62
+ $this->options = $options;
63
+ }
64
+
65
  return $this;
66
  }
67
 
71
  */
72
  public function id()
73
  {
74
+ return $this->id;
 
 
 
 
 
75
  }
76
 
77
  /**
80
  */
81
  public function order()
82
  {
83
+ return Mage::getModel('marketingsoftware/abstraction_order')->loadOrder($this->orderId);
 
 
 
 
 
 
 
 
 
84
  }
85
 
86
  /**
89
  */
90
  public function quantity()
91
  {
92
+ return $this->quantity;
 
 
 
 
 
93
  }
94
 
95
  /**
99
  */
100
  public function price()
101
  {
102
+ return $this->price;
 
 
 
 
 
 
103
  }
104
 
105
  /**
108
  */
109
  public function weight()
110
  {
111
+ return $this->weight;
 
 
 
 
 
112
  }
113
 
114
  /**
117
  */
118
  public function timestamp()
119
  {
120
+ return $this->timestamp;
 
 
 
 
 
121
  }
122
 
123
  /**
126
  */
127
  public function options()
128
  {
129
+ return $this->options;
 
 
 
 
 
 
 
 
 
 
 
130
  }
131
 
132
  /**
135
  */
136
  public function product()
137
  {
138
+ return $this->product;
 
 
 
 
 
139
  }
140
 
141
  /**
app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Order/Item/Options.php CHANGED
@@ -29,17 +29,11 @@
29
  */
30
  class Copernica_MarketingSoftware_Model_Abstraction_Order_Item_Options implements Serializable
31
  {
32
- /**
33
- * The original object
34
- * @param Mage_Sales_Model_Order_Item
35
- */
36
- protected $original;
37
-
38
  /**
39
  * Predefine the internal fields
40
  */
41
  protected $name;
42
- protected $attributes;
43
 
44
 
45
  /**
@@ -49,7 +43,30 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order_Item_Options implement
49
  */
50
  public function setOriginal(Mage_Sales_Model_Order_Item $original)
51
  {
52
- $this->original = $original;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
  return $this;
54
  }
55
 
@@ -59,12 +76,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order_Item_Options implement
59
  */
60
  public function name()
61
  {
62
- // Is this object still present?
63
- if (is_object($this->original))
64
- {
65
- return $this->original->getName();
66
- }
67
- else return $this->name;
68
  }
69
 
70
  /**
@@ -73,31 +85,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Order_Item_Options implement
73
  */
74
  public function attributes()
75
  {
76
- // Is this object still present?
77
- if (is_object($this->original))
78
- {
79
- $data = array();
80
- $options = $this->original->getProductOptions();
81
- $attributes = array();
82
- if (isset($options['attributes_info'])) {
83
- //configurable products
84
- $attributes = $options['attributes_info'];
85
- } elseif (isset($options['bundle_options'])) {
86
- //bundle products
87
- $attributes = $options['bundle_options'];
88
- } elseif (isset($options['options'])) {
89
- //generic products
90
- $attributes = $options['options'];
91
- }
92
- if ($attributes) {
93
- foreach ($attributes as $attribute) {
94
- $data[$attribute['label']] = $attribute['value'];
95
- }
96
- return $data;
97
- }
98
- return null;
99
- }
100
- else return $this->attributes;
101
  }
102
 
103
  /**
29
  */
30
  class Copernica_MarketingSoftware_Model_Abstraction_Order_Item_Options implements Serializable
31
  {
 
 
 
 
 
 
32
  /**
33
  * Predefine the internal fields
34
  */
35
  protected $name;
36
+ protected $attributes = null;
37
 
38
 
39
  /**
43
  */
44
  public function setOriginal(Mage_Sales_Model_Order_Item $original)
45
  {
46
+ $this->name = $original->getName();
47
+
48
+ $attributes = array();
49
+ $data = array();
50
+ $options = $original->getProductOptions();
51
+
52
+ if (isset($options['attributes_info'])) {
53
+ //configurable products
54
+ $attributes = $options['attributes_info'];
55
+ } elseif (isset($options['bundle_options'])) {
56
+ //bundle products
57
+ $attributes = $options['bundle_options'];
58
+ } elseif (isset($options['options'])) {
59
+ //generic products
60
+ $attributes = $options['options'];
61
+ }
62
+
63
+ if ($attributes) {
64
+ foreach ($attributes as $attribute) {
65
+ $data[$attribute['label']] = $attribute['value'];
66
+ }
67
+ $this->attributes = $data;
68
+ }
69
+
70
  return $this;
71
  }
72
 
76
  */
77
  public function name()
78
  {
79
+ return $this->name;
 
 
 
 
 
80
  }
81
 
82
  /**
85
  */
86
  public function attributes()
87
  {
88
+ return $this->attributes;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
  }
90
 
91
  /**
app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Price.php CHANGED
@@ -37,12 +37,6 @@
37
  */
38
  class Copernica_MarketingSoftware_Model_Abstraction_Price implements Serializable
39
  {
40
- /**
41
- * The original object
42
- * @param Mage_Sales_Model_Quote|Mage_Sales_Model_Order|Mage_Sales_Model_Quote_Item|Mage_Sales_Model_Order_Item
43
- */
44
- protected $original;
45
-
46
  /**
47
  * Predefine the internal fields
48
  */
@@ -62,7 +56,73 @@ class Copernica_MarketingSoftware_Model_Abstraction_Price implements Serializabl
62
  */
63
  public function setOriginal($original)
64
  {
65
- $this->original = $original;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  return $this;
67
  }
68
 
@@ -72,19 +132,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Price implements Serializabl
72
  */
73
  public function total()
74
  {
75
- // Is this object still present?
76
- if (is_object($this->original))
77
- {
78
- // Used for quotes and orders
79
- if ($grandTotal = $this->original->getGrandTotal()) return $grandTotal;
80
-
81
- // Used for quote items and order items
82
- elseif ($rowTotalInclTax = $this->original->getRowTotalInclTax()) return $rowTotalInclTax;
83
-
84
- // Used for quote items and order items (when no tax is configured)
85
- elseif ($baseRowTotal = $this->original->getBaseRowTotal()) return $baseRowTotal;
86
- }
87
- else return $this->total;
88
  }
89
 
90
  /**
@@ -93,28 +141,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Price implements Serializabl
93
  */
94
  public function costs()
95
  {
96
- // Is this object still present?
97
- if (is_object($this->original))
98
- {
99
- // Used for quotes and orders
100
- if ($this->original instanceOf Mage_Sales_Model_Quote || $this->original instanceOf Mage_Sales_Model_Order)
101
- {
102
- $costs = 0;
103
-
104
- // iterate over all visisble items
105
- foreach ($this->original->getAllVisibleItems() as $item)
106
- {
107
- $costs += $item->getBaseCost();
108
- }
109
-
110
- // return the costs
111
- return $costs;
112
- }
113
-
114
- // Used for quote items and order items
115
- elseif ($baseCost = $this->original->getBaseCost()) return $baseCost;
116
- }
117
- else return $this->costs;
118
  }
119
 
120
  /**
@@ -123,16 +150,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Price implements Serializabl
123
  */
124
  public function itemPrice()
125
  {
126
- // Is this object still present?
127
- if (is_object($this->original))
128
- {
129
- // no price for an individual item
130
- if ($this->original instanceOf Mage_Sales_Model_Quote || $this->original instanceOf Mage_Sales_Model_Order) return 0;
131
-
132
- // Used for quote items and order items
133
- elseif ($price = $this->original->getPrice()) return $price;
134
- }
135
- else return $this->itemPrice;
136
  }
137
 
138
  /**
@@ -141,16 +159,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Price implements Serializabl
141
  */
142
  public function originalPrice()
143
  {
144
- // Is this object still present?
145
- if (is_object($this->original))
146
- {
147
- // no price for an individual item
148
- if ($this->original instanceOf Mage_Sales_Model_Quote || $this->original instanceOf Mage_Sales_Model_Order) return 0;
149
-
150
- // Used for quote items and order items
151
- elseif ($originalPrice = $this->original->getOriginalPrice()) return $originalPrice;
152
- }
153
- else return $this->originalPrice;
154
  }
155
 
156
  /**
@@ -159,13 +168,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Price implements Serializabl
159
  */
160
  public function discount()
161
  {
162
- // Is this object still present?
163
- if (is_object($this->original))
164
- {
165
- // Used for all items
166
- if ($discountAmount = $this->original->getDiscountAmount()) return $discountAmount;
167
- }
168
- else return $this->discount;
169
  }
170
 
171
  /**
@@ -174,13 +177,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Price implements Serializabl
174
  */
175
  public function tax()
176
  {
177
- // Is this object still present?
178
- if (is_object($this->original))
179
- {
180
- // Used for all items
181
- if ($taxAmount = $this->original->getTaxAmount()) return $taxAmount;
182
- }
183
- else return $this->tax;
184
  }
185
 
186
  /**
@@ -189,18 +186,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Price implements Serializabl
189
  */
190
  public function shipping()
191
  {
192
- // Is this object still present?
193
- if (is_object($this->original))
194
- {
195
- // Shipping is only available for quotes and orders, but not for items
196
- if ($this->original instanceOf Mage_Sales_Model_Quote || $this->original instanceOf Mage_Sales_Model_Order)
197
- {
198
- // Get the shipping amount
199
- if ($shippingAmount = $this->original->getShippingAmount()) return $shippingAmount;
200
- }
201
- else return 0;
202
- }
203
- else return $this->shipping;
204
  }
205
 
206
  /**
@@ -209,16 +195,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Price implements Serializabl
209
  */
210
  public function currency()
211
  {
212
- // Is this object still present?
213
- if (is_object($this->original))
214
- {
215
- if ($currency = $this->original->getOrderCurrencyCode()) return $currency;
216
- elseif ($currency = $this->original->getQuoteCurrencyCode()) return $currency;
217
- elseif (($order = $this->original->getOrder()) && ($currency = $order->getOrderCurrencyCode())) return $currency;
218
- elseif (($quote = $this->original->getQuote()) && ($currency = $quote->getQuoteCurrencyCode())) return $currency;
219
- else return '';
220
- }
221
- else return $this->currency;
222
  }
223
 
224
  /**
37
  */
38
  class Copernica_MarketingSoftware_Model_Abstraction_Price implements Serializable
39
  {
 
 
 
 
 
 
40
  /**
41
  * Predefine the internal fields
42
  */
56
  */
57
  public function setOriginal($original)
58
  {
59
+ if ($grandTotal = $original->getGrandTotal()) {
60
+ $this->total = $grandTotal;
61
+ } elseif ($rowTotalInclTax = $original->getRowTotalInclTax()) {
62
+ $this->total = $rowTotalInclTax;
63
+ } elseif ($baseRowTotal = $original->getBaseRowTotal()) {
64
+ $this->total = $baseRowTotal;
65
+ }
66
+
67
+ // Used for quotes and orders
68
+ if ($original instanceOf Mage_Sales_Model_Quote || $original instanceOf Mage_Sales_Model_Order) {
69
+ $costs = 0;
70
+
71
+ // iterate over all visisble items
72
+ foreach ($original->getAllVisibleItems() as $item) {
73
+ $costs += $item->getBaseCost();
74
+ }
75
+
76
+ // return the costs
77
+ $this->costs = $costs;
78
+ } elseif ($baseCost = $original->getBaseCost()) {
79
+ $this->costs = $baseCost;
80
+ }
81
+
82
+ // no price for an individual item
83
+ if ($original instanceOf Mage_Sales_Model_Quote || $original instanceOf Mage_Sales_Model_Order)
84
+ $this->itemPrice = 0;
85
+
86
+ // Used for quote items and order items
87
+ elseif ($price = $original->getPrice())
88
+ $this->itemPrice = $price;
89
+
90
+ // no price for an individual item
91
+ if ($original instanceOf Mage_Sales_Model_Quote || $original instanceOf Mage_Sales_Model_Order)
92
+ $this->originalPrice = 0;
93
+
94
+ // Used for quote items and order items
95
+ elseif ($originalPrice = $original->getOriginalPrice())
96
+ $this->originalPrice = $originalPrice;
97
+
98
+ if ($discountAmount = $original->getDiscountAmount())
99
+ $this->discount = $discountAmount;
100
+
101
+ if ($taxAmount = $original->getTaxAmount())
102
+ $this->tax = $taxAmount;
103
+
104
+ // Shipping is only available for quotes and orders, but not for items
105
+ if ($original instanceOf Mage_Sales_Model_Quote || $original instanceOf Mage_Sales_Model_Order)
106
+ {
107
+ // Get the shipping amount
108
+ if ($shippingAmount = $original->getShippingAmount())
109
+ $this->shipping = $shippingAmount;
110
+ else
111
+ $this->shipping = 0;
112
+ }
113
+ else $this->shipping = 0;
114
+
115
+ if ($currency = $original->getOrderCurrencyCode())
116
+ $this->currency = $currency;
117
+ elseif ($currency = $original->getQuoteCurrencyCode())
118
+ $this->currency = $currency;
119
+ elseif (($order = $original->getOrder()) && ($currency = $order->getOrderCurrencyCode()))
120
+ $this->currency = $currency;
121
+ elseif (($quote = $original->getQuote()) && ($currency = $quote->getQuoteCurrencyCode()))
122
+ $this->currency = $currency;
123
+ else
124
+ $this->currency = '';
125
+
126
  return $this;
127
  }
128
 
132
  */
133
  public function total()
134
  {
135
+ return $this->total;
 
 
 
 
 
 
 
 
 
 
 
 
136
  }
137
 
138
  /**
141
  */
142
  public function costs()
143
  {
144
+ return $this->costs;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
145
  }
146
 
147
  /**
150
  */
151
  public function itemPrice()
152
  {
153
+ return $this->itemPrice;
 
 
 
 
 
 
 
 
 
154
  }
155
 
156
  /**
159
  */
160
  public function originalPrice()
161
  {
162
+ return $this->originalPrice;
 
 
 
 
 
 
 
 
 
163
  }
164
 
165
  /**
168
  */
169
  public function discount()
170
  {
171
+ return $this->discount;
 
 
 
 
 
 
172
  }
173
 
174
  /**
177
  */
178
  public function tax()
179
  {
180
+ return $this->tax;
 
 
 
 
 
 
181
  }
182
 
183
  /**
186
  */
187
  public function shipping()
188
  {
189
+ return $this->shipping;
 
 
 
 
 
 
 
 
 
 
 
190
  }
191
 
192
  /**
195
  */
196
  public function currency()
197
  {
198
+ return $this->currency;
 
 
 
 
 
 
 
 
 
199
  }
200
 
201
  /**
app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Product.php CHANGED
@@ -63,7 +63,51 @@ class Copernica_MarketingSoftware_Model_Abstraction_Product implements Serializa
63
  {
64
  if ($original instanceof Mage_Catalog_Model_Product) {
65
  //this is the original product
66
- $this->original = $original;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
 
68
  return $this;
69
  } else {
@@ -71,7 +115,50 @@ class Copernica_MarketingSoftware_Model_Abstraction_Product implements Serializa
71
  $product = Mage::getModel('catalog/product')->load($original->getProductId());
72
  if ($product->getId()) {
73
  //the product exists
74
- $this->original = $product;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
  } else {
76
  // unfortunately we do not have the product any more, but we have the information
77
  // so we can fill a lot of fields, so the functions still work
@@ -105,7 +192,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Product implements Serializa
105
  $product = Mage::getModel('catalog/product')->load($productId);
106
  if ($product->getId()) {
107
  //set the original model if the product exists
108
- $this->original = $product;
109
  }
110
  else
111
  {
@@ -120,12 +207,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Product implements Serializa
120
  */
121
  public function id()
122
  {
123
- // Is this object still present?
124
- if (is_object($this->original))
125
- {
126
- return $this->original->getId();
127
- }
128
- else return $this->id;
129
  }
130
 
131
  /**
@@ -135,12 +217,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Product implements Serializa
135
  */
136
  public function sku()
137
  {
138
- // Is this object still present?
139
- if (is_object($this->original))
140
- {
141
- return $this->original->getSku();
142
- }
143
- else return $this->sku;
144
  }
145
 
146
  /**
@@ -149,12 +226,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Product implements Serializa
149
  */
150
  public function name()
151
  {
152
- // Is this object still present?
153
- if (is_object($this->original))
154
- {
155
- return $this->original->getName();
156
- }
157
- else return $this->name;
158
  }
159
 
160
  /**
@@ -163,12 +235,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Product implements Serializa
163
  */
164
  public function description()
165
  {
166
- // Is this object still present?
167
- if (is_object($this->original))
168
- {
169
- return $this->original->getShortDescription();
170
- }
171
- else return $this->description;
172
  }
173
 
174
  /**
@@ -177,12 +244,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Product implements Serializa
177
  */
178
  public function price()
179
  {
180
- // Is this object still present?
181
- if (is_object($this->original))
182
- {
183
- return $this->original->getPrice();
184
- }
185
- else return $this->price;
186
  }
187
 
188
  /**
@@ -191,12 +253,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Product implements Serializa
191
  */
192
  public function specialPrice()
193
  {
194
- // Is this object still present?
195
- if (is_object($this->original))
196
- {
197
- return $this->original->getSpecialPrice();
198
- }
199
- else return $this->specialPrice;
200
  }
201
 
202
 
@@ -206,12 +263,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Product implements Serializa
206
  */
207
  public function created()
208
  {
209
- // Is this object still present?
210
- if (is_object($this->original))
211
- {
212
- return $this->original->getCreatedAt();
213
- }
214
- else return $this->created;
215
  }
216
 
217
  /**
@@ -220,12 +272,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Product implements Serializa
220
  */
221
  public function modified()
222
  {
223
- // Is this object still present?
224
- if (is_object($this->original))
225
- {
226
- return $this->original->getUpdatedAt();
227
- }
228
- else return $this->modified;
229
  }
230
 
231
  /**
@@ -235,24 +282,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Product implements Serializa
235
  */
236
  public function productUrl($storeId = null)
237
  {
238
- // If the object is not present and there is no store id
239
- // than we fallback to the `cached item`
240
- if (!is_object($this->original) && $storeId === null)
241
- {
242
- return $this->productUrl;
243
- }
244
- else
245
- {
246
- // Get the product
247
- /* @var $product Mage_Catalog_Model_Product */
248
- $product = is_object($this->original) ? $this->original : Mage::getModel('catalog/product')->load($this->id);
249
-
250
- // Could not load the product, return an empty string
251
- if (!$product->getId()) return '';
252
-
253
- // Just return the product URL as is
254
- return $product->getProductUrl();
255
- }
256
  }
257
 
258
  /**
@@ -262,26 +292,8 @@ class Copernica_MarketingSoftware_Model_Abstraction_Product implements Serializa
262
  */
263
  public function imageUrl($storeId = null)
264
  {
265
- // Is this object still present?
266
- if (is_object($this->original))
267
- {
268
- $path = 'catalog' . DS . 'product' . $this->original->getImage();
269
- }
270
- else $path = $this->imagePath;
271
-
272
- // most likely store `false` is supplied to the function, if the path
273
- // is empty it is also not very usefull to prepend a string to it
274
- if ($storeId === false || empty($path)) return $path;
275
-
276
- // Retrieve the requested store, null returns the default store
277
- $store = Mage::app()->getStore($storeId);
278
-
279
- // We did retrieve a store, but was it an object?
280
- if (!is_object($store)) return $path;
281
-
282
- // add a prefix for the store here
283
- return $store->getBaseUrl('media') . $path;
284
- }
285
 
286
  /**
287
  * Return the weight of this magento product
@@ -289,12 +301,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Product implements Serializa
289
  */
290
  public function weight()
291
  {
292
- // Is this object still present?
293
- if (is_object($this->original))
294
- {
295
- return $this->original->getWeight();
296
- }
297
- else return $this->weight;
298
  }
299
 
300
  /**
@@ -303,18 +310,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Product implements Serializa
303
  */
304
  public function categories()
305
  {
306
- // Is this object still present?
307
- if (is_object($this->original))
308
- {
309
- $data = array();
310
- $categoryIds = $this->original->getCategoryIds();
311
- foreach ($categoryIds as $categoryId) {
312
- $category = Mage::getModel('catalog/category')->load($categoryId);
313
- $data[] = $this->_getFullCategoryName($category);
314
- }
315
- return $data;
316
- }
317
- else return $this->categories;
318
  }
319
 
320
  /**
@@ -347,25 +343,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Product implements Serializa
347
  */
348
  public function isNew()
349
  {
350
- // Is this object still present?
351
- if (is_object($this->original))
352
- {
353
- $from = $this->original->getNewsFromDate() ? Mage::app()->getLocale()->date($this->original->getNewsFromDate()) : null;
354
- $to = $this->original->getNewsToDate() ? Mage::app()->getLocale()->date($this->original->getNewsToDate()) : null;
355
- if ($from || $to) {
356
- $new = true;
357
- $now = Zend_Date::now();
358
- if ($from) {
359
- $new = $new && $from->isEarlier($now);
360
- }
361
- if ($to) {
362
- $new = $new && $to->isLater($now);
363
- }
364
- return $new;
365
- }
366
- return false;
367
- }
368
- else return $this->isNew;
369
  }
370
 
371
  /**
@@ -374,25 +352,12 @@ class Copernica_MarketingSoftware_Model_Abstraction_Product implements Serializa
374
  */
375
  public function attributes()
376
  {
377
- // Is this object still present?
378
- if (is_object($this->original))
379
- {
380
- return Mage::getModel('marketingsoftware/abstraction_attributes')->setOriginal($this->original);
381
- }
382
- else return $this->attributes;
383
  }
384
 
385
  public function attributeSet()
386
  {
387
- // Is this object still present?
388
- if (is_object($this->original)) {
389
- $attributeSetModel = Mage::getModel("eav/entity_attribute_set");
390
- $attributeSetModel->load($this->original->getAttributeSetId());
391
-
392
- return $attributeSetModel->getAttributeSetName();
393
- } else {
394
- return $this->attributeSet;
395
- }
396
  }
397
 
398
  /**
63
  {
64
  if ($original instanceof Mage_Catalog_Model_Product) {
65
  //this is the original product
66
+ $this->id = $original->getId();
67
+ $this->sku = $original->getSku();
68
+ $this->name = $original->getName();
69
+ $this->description = $original->getShortDescription();
70
+ $this->price = $original->getPrice();
71
+ $this->specialPrice = $original->getSpecialPrice();
72
+ $this->created = $original->getCreatedAt();
73
+ $this->modified = $original->getUpdatedAt();
74
+ $this->productUrl = $original->getProductUrl();
75
+ $this->imagePath = 'catalog' . DS . 'product' . $original->getImage();
76
+ $this->weight = $original->getWeight();
77
+
78
+ $data = array();
79
+ $categoryIds = $original->getCategoryIds();
80
+ foreach ($categoryIds as $categoryId) {
81
+ $category = Mage::getModel('catalog/category')->load($categoryId);
82
+ $data[] = $this->_getFullCategoryName($category);
83
+ }
84
+ $this->categories = $data;
85
+
86
+ $from = $original->getNewsFromDate() ? Mage::app()->getLocale()->date($original->getNewsFromDate()) : null;
87
+ $to = $original->getNewsToDate() ? Mage::app()->getLocale()->date($original->getNewsToDate()) : null;
88
+ if ($from || $to) {
89
+ $new = true;
90
+ $now = Zend_Date::now();
91
+ if ($from) {
92
+ $new = $new && $from->isEarlier($now);
93
+ }
94
+ if ($to) {
95
+ $new = $new && $to->isLater($now);
96
+ }
97
+ $this->isNew = $new;
98
+ } else {
99
+ $this->isNew = false;
100
+ }
101
+
102
+ $this->attributes = Mage::getModel('marketingsoftware/abstraction_attributes')->setOriginal($original);
103
+
104
+ $attributeSetModel = Mage::getModel("eav/entity_attribute_set");
105
+ $attributeSetModel->load($original->getAttributeSetId());
106
+
107
+ $this->attributeSet = $attributeSetModel->getAttributeSetName();
108
+
109
+ $this->timestamp = time();
110
+
111
 
112
  return $this;
113
  } else {
115
  $product = Mage::getModel('catalog/product')->load($original->getProductId());
116
  if ($product->getId()) {
117
  //the product exists
118
+ $this->id = $product->getId();
119
+ $this->sku = $product->getSku();
120
+ $this->name = $product->getName();
121
+ $this->description = $product->getShortDescription();
122
+ $this->price = $product->getPrice();
123
+ $this->specialPrice = $product->getSpecialPrice();
124
+ $this->created = $product->getCreatedAt();
125
+ $this->modified = $product->getUpdatedAt();
126
+ $this->productUrl = $product->getProductUrl();
127
+ $this->imagePath = 'catalog' . DS . 'product' . $product->getImage();
128
+ $this->weight = $product->getWeight();
129
+
130
+ $data = array();
131
+ $categoryIds = $product->getCategoryIds();
132
+ foreach ($categoryIds as $categoryId) {
133
+ $category = Mage::getModel('catalog/category')->load($categoryId);
134
+ $data[] = $this->_getFullCategoryName($category);
135
+ }
136
+ $this->categories = $data;
137
+
138
+ $from = $product->getNewsFromDate() ? Mage::app()->getLocale()->date($product->getNewsFromDate()) : null;
139
+ $to = $product->getNewsToDate() ? Mage::app()->getLocale()->date($product->getNewsToDate()) : null;
140
+ if ($from || $to) {
141
+ $new = true;
142
+ $now = Zend_Date::now();
143
+ if ($from) {
144
+ $new = $new && $from->isEarlier($now);
145
+ }
146
+ if ($to) {
147
+ $new = $new && $to->isLater($now);
148
+ }
149
+ $this->isNew = $new;
150
+ } else {
151
+ $this->isNew = false;
152
+ }
153
+
154
+ $this->attributes = Mage::getModel('marketingsoftware/abstraction_attributes')->setOriginal($product);
155
+
156
+ $attributeSetModel = Mage::getModel("eav/entity_attribute_set");
157
+ $attributeSetModel->load($product->getAttributeSetId());
158
+
159
+ $this->attributeSet = $attributeSetModel->getAttributeSetName();
160
+
161
+ $this->timestamp = time();
162
  } else {
163
  // unfortunately we do not have the product any more, but we have the information
164
  // so we can fill a lot of fields, so the functions still work
192
  $product = Mage::getModel('catalog/product')->load($productId);
193
  if ($product->getId()) {
194
  //set the original model if the product exists
195
+ $this->setOriginal($product);
196
  }
197
  else
198
  {
207
  */
208
  public function id()
209
  {
210
+ return $this->id;
 
 
 
 
 
211
  }
212
 
213
  /**
217
  */
218
  public function sku()
219
  {
220
+ return $this->sku;
 
 
 
 
 
221
  }
222
 
223
  /**
226
  */
227
  public function name()
228
  {
229
+ return $this->name;
 
 
 
 
 
230
  }
231
 
232
  /**
235
  */
236
  public function description()
237
  {
238
+ return $this->description;
 
 
 
 
 
239
  }
240
 
241
  /**
244
  */
245
  public function price()
246
  {
247
+ return $this->price;
 
 
 
 
 
248
  }
249
 
250
  /**
253
  */
254
  public function specialPrice()
255
  {
256
+ return $this->specialPrice;
 
 
 
 
 
257
  }
258
 
259
 
263
  */
264
  public function created()
265
  {
266
+ return $this->created;
 
 
 
 
 
267
  }
268
 
269
  /**
272
  */
273
  public function modified()
274
  {
275
+ return $this->modified;
 
 
 
 
 
276
  }
277
 
278
  /**
282
  */
283
  public function productUrl($storeId = null)
284
  {
285
+ return $this->productUrl;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
286
  }
287
 
288
  /**
292
  */
293
  public function imageUrl($storeId = null)
294
  {
295
+ return $this->imagePath;
296
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
297
 
298
  /**
299
  * Return the weight of this magento product
301
  */
302
  public function weight()
303
  {
304
+ return $this->weight;
 
 
 
 
 
305
  }
306
 
307
  /**
310
  */
311
  public function categories()
312
  {
313
+ return $this->categories;
 
 
 
 
 
 
 
 
 
 
 
314
  }
315
 
316
  /**
343
  */
344
  public function isNew()
345
  {
346
+ return $this->isNew;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
347
  }
348
 
349
  /**
352
  */
353
  public function attributes()
354
  {
355
+ return $this->attributes;
 
 
 
 
 
356
  }
357
 
358
  public function attributeSet()
359
  {
360
+ return $this->attributeSet;
 
 
 
 
 
 
 
 
361
  }
362
 
363
  /**
app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Quote.php CHANGED
@@ -29,12 +29,6 @@
29
  */
30
  class Copernica_MarketingSoftware_Model_Abstraction_Quote implements Serializable
31
  {
32
- /**
33
- * The original object
34
- * @param Mage_Sales_Model_Quote
35
- */
36
- protected $original;
37
-
38
  /**
39
  * Predefine the internal fields
40
  */
@@ -60,7 +54,51 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote implements Serializabl
60
  */
61
  public function setOriginal(Mage_Sales_Model_Quote $original)
62
  {
63
- $this->original = $original;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
  return $this;
65
  }
66
 
@@ -88,8 +126,11 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote implements Serializabl
88
  else $quote->loadByIdWithoutStore($quoteId);
89
 
90
  // we did load a valid quote, set the original model
91
- if ($quote->getId()) $this->original = $quote;
92
- else $this->quoteId = $quoteId;
 
 
 
93
 
94
  // return this
95
  return $this;
@@ -101,12 +142,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote implements Serializabl
101
  */
102
  public function id()
103
  {
104
- // Is this object still present?
105
- if (is_object($this->original))
106
- {
107
- return $this->original->getId();
108
- }
109
- else return $this->quoteId;
110
  }
111
 
112
  /**
@@ -115,12 +151,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote implements Serializabl
115
  */
116
  public function active()
117
  {
118
- // Is this object still present?
119
- if (is_object($this->original))
120
- {
121
- return (bool)$this->original->getIsActive();
122
- }
123
- else return $this->active;
124
  }
125
 
126
  /**
@@ -129,12 +160,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote implements Serializabl
129
  */
130
  public function quantity()
131
  {
132
- // Is this object still present?
133
- if (is_object($this->original))
134
- {
135
- return $this->original->getItemsQty();
136
- }
137
- else return $this->quantity;
138
  }
139
 
140
  /**
@@ -143,12 +169,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote implements Serializabl
143
  */
144
  public function currency()
145
  {
146
- // Is this object still present?
147
- if (is_object($this->original))
148
- {
149
- return $this->original->getQuoteCurrencyCode();
150
- }
151
- else return $this->currency;
152
  }
153
 
154
  /**
@@ -158,13 +179,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote implements Serializabl
158
  */
159
  public function price()
160
  {
161
- // Is this object still present?
162
- if (is_object($this->original))
163
- {
164
- // Note that the price may consist of multiple elements
165
- return Mage::getModel('marketingsoftware/abstraction_price')->setOriginal($this->original);
166
- }
167
- else return $this->price;
168
  }
169
 
170
  /**
@@ -173,16 +188,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote implements Serializabl
173
  */
174
  public function weight()
175
  {
176
- // Is this object still present?
177
- if (is_object($this->original))
178
- {
179
- if ($address = $this->original->getShippingAddress()) {
180
- return $address->getWeight();
181
- } else {
182
- return null;
183
- }
184
- }
185
- else return $this->price;
186
  }
187
 
188
  /**
@@ -191,12 +197,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote implements Serializabl
191
  */
192
  public function storeview()
193
  {
194
- // Is this object still present?
195
- if (is_object($this->original))
196
- {
197
- return Mage::getModel('marketingsoftware/abstraction_storeview')->setOriginal($this->original->getStore());
198
- }
199
- else return $this->storeview;
200
  }
201
 
202
  /**
@@ -205,17 +206,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote implements Serializabl
205
  */
206
  public function items()
207
  {
208
- // Is this object still present?
209
- if (is_object($this->original))
210
- {
211
- $data = array();
212
- $items = $this->original->getAllVisibleItems();
213
- foreach ($items as $item) {
214
- $data[] = Mage::getModel('marketingsoftware/abstraction_quote_item')->setOriginal($item);
215
- }
216
- return $data;
217
- }
218
- else return $this->items;
219
  }
220
 
221
  /**
@@ -224,12 +215,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote implements Serializabl
224
  */
225
  public function timestamp()
226
  {
227
- // Is this object still present?
228
- if (is_object($this->original))
229
- {
230
- return $this->original->getUpdatedAt();
231
- }
232
- else return $this->timestamp;
233
  }
234
 
235
  /**
@@ -238,22 +224,12 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote implements Serializabl
238
  */
239
  public function customer()
240
  {
241
- // Is this object still present?
242
- if (is_object($this->original))
243
- {
244
- // The quote model only returns a customer if it exists
245
- if ($customerId = $this->original->getCustomerId())
246
- {
247
- return Mage::getModel('marketingsoftware/abstraction_customer')->loadCustomer($customerId);
248
- }
249
- }
250
- elseif ($this->customerId)
251
- {
252
  return Mage::getModel('marketingsoftware/abstraction_customer')->loadCustomer($this->customerId);
 
 
 
253
  }
254
-
255
- // default fallback
256
- return null;
257
  }
258
 
259
  /**
@@ -262,19 +238,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote implements Serializabl
262
  */
263
  public function addresses()
264
  {
265
- // Is this object still present?
266
- if (is_object($this->original))
267
- {
268
- $data = array();
269
- //retrieve this quote's addresses
270
- //Note: this may return empty addresses, since quotes always have address records. Check the email field of the address.
271
- $addresses = $this->original->getAddressesCollection();
272
- foreach ($addresses as $address) {
273
- $data[] = Mage::getModel('marketingsoftware/abstraction_address')->setOriginal($address);
274
- }
275
- return $data;
276
- }
277
- else return $this->addresses;
278
  }
279
 
280
  /**
@@ -283,12 +247,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote implements Serializabl
283
  */
284
  public function customerIP()
285
  {
286
- // Is this object still present?
287
- if (is_object($this->original))
288
- {
289
- return $this->original->getRemoteIp();
290
- }
291
- else return $this->customerIP;
292
  }
293
 
294
  /**
@@ -297,16 +256,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote implements Serializabl
297
  */
298
  public function shippingDescription()
299
  {
300
- // Is this object still present?
301
- if (is_object($this->original))
302
- {
303
- if ($address = $this->original->getShippingAddress()) {
304
- return $address->getShippingDescription();
305
- } else {
306
- return null;
307
- }
308
- }
309
- else return $this->shippingDescription;
310
  }
311
 
312
  /**
@@ -315,20 +265,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote implements Serializabl
315
  */
316
  public function paymentDescription()
317
  {
318
- // Is this object still present?
319
- if (is_object($this->original))
320
- {
321
- if ($payment = $this->original->getPayment()) {
322
- //this try/catch is needed because getMethodInstance throws an exception instead of returning null
323
- try {
324
- return $payment->getMethodInstance()->getTitle();
325
- } catch (Mage_Core_Exception $exception) {
326
- return null;
327
- }
328
- }
329
- return null;
330
- }
331
- else return $this->paymentDescription;
332
  }
333
 
334
  /**
29
  */
30
  class Copernica_MarketingSoftware_Model_Abstraction_Quote implements Serializable
31
  {
 
 
 
 
 
 
32
  /**
33
  * Predefine the internal fields
34
  */
54
  */
55
  public function setOriginal(Mage_Sales_Model_Quote $original)
56
  {
57
+ $this->quoteId = $original->getId();
58
+ $this->active = (bool) $original->getIsActive();
59
+ $this->quantity = $original->getItemsQty();
60
+ $this->currency = $original->getQuoteCurrencyCode();
61
+ $this->price = Mage::getModel('marketingsoftware/abstraction_price')->setOriginal($original);
62
+ $this->storeview = Mage::getModel('marketingsoftware/abstraction_storeview')->setOriginal($original->getStore());
63
+ $this->timestamp = $original->getUpdatedAt();
64
+ $this->customerIP = $original->getRemoteIp();
65
+
66
+ if ($address = $original->getShippingAddress()) {
67
+ $this->weight = $address->getWeight();
68
+ }
69
+
70
+ $data = array();
71
+ $items = $original->getAllVisibleItems();
72
+ foreach ($items as $item) {
73
+ $data[] = Mage::getModel('marketingsoftware/abstraction_quote_item')->setOriginal($item);
74
+ }
75
+ $this->items = $data;
76
+
77
+ // The quote model only returns a customer if it exists
78
+ if ($customerId = $original->getCustomerId()) {
79
+ $this->customerId = $customerId;
80
+ }
81
+
82
+ $data = array();
83
+ //retrieve this quote's addresses
84
+ //Note: this may return empty addresses, since quotes always have address records. Check the email field of the address.
85
+ $addresses = $original->getAddressesCollection();
86
+ foreach ($addresses as $address) {
87
+ $data[] = Mage::getModel('marketingsoftware/abstraction_address')->setOriginal($address);
88
+ }
89
+ $this->addresses = $data;
90
+
91
+ if ($address = $original->getShippingAddress()) {
92
+ $this->shippingDescription = $address->getShippingDescription();
93
+ }
94
+
95
+ if ($payment = $original->getPayment()) {
96
+ //this try/catch is needed because getMethodInstance throws an exception instead of returning null
97
+ try {
98
+ $this->paymentDescription = $payment->getMethodInstance()->getTitle();
99
+ } catch (Mage_Core_Exception $exception) { }
100
+ }
101
+
102
  return $this;
103
  }
104
 
126
  else $quote->loadByIdWithoutStore($quoteId);
127
 
128
  // we did load a valid quote, set the original model
129
+ if ($quote->getId()) {
130
+ $this->setOriginal($quote);
131
+ } else {
132
+ $this->quoteId = $quoteId;
133
+ }
134
 
135
  // return this
136
  return $this;
142
  */
143
  public function id()
144
  {
145
+ return $this->quoteId;
 
 
 
 
 
146
  }
147
 
148
  /**
151
  */
152
  public function active()
153
  {
154
+ return $this->active;
 
 
 
 
 
155
  }
156
 
157
  /**
160
  */
161
  public function quantity()
162
  {
163
+ return $this->quantity;
 
 
 
 
 
164
  }
165
 
166
  /**
169
  */
170
  public function currency()
171
  {
172
+ return $this->currency;
 
 
 
 
 
173
  }
174
 
175
  /**
179
  */
180
  public function price()
181
  {
182
+ return $this->price;
 
 
 
 
 
 
183
  }
184
 
185
  /**
188
  */
189
  public function weight()
190
  {
191
+ return $this->weight;
 
 
 
 
 
 
 
 
 
192
  }
193
 
194
  /**
197
  */
198
  public function storeview()
199
  {
200
+ return $this->storeview;
 
 
 
 
 
201
  }
202
 
203
  /**
206
  */
207
  public function items()
208
  {
209
+ return $this->items;
 
 
 
 
 
 
 
 
 
 
210
  }
211
 
212
  /**
215
  */
216
  public function timestamp()
217
  {
218
+ return $this->timestamp;
 
 
 
 
 
219
  }
220
 
221
  /**
224
  */
225
  public function customer()
226
  {
227
+ if ($this->customerId) {
 
 
 
 
 
 
 
 
 
 
228
  return Mage::getModel('marketingsoftware/abstraction_customer')->loadCustomer($this->customerId);
229
+ } else {
230
+ // default fallback
231
+ return null;
232
  }
 
 
 
233
  }
234
 
235
  /**
238
  */
239
  public function addresses()
240
  {
241
+ return $this->addresses;
 
 
 
 
 
 
 
 
 
 
 
 
242
  }
243
 
244
  /**
247
  */
248
  public function customerIP()
249
  {
250
+ return $this->customerIP;
 
 
 
 
 
251
  }
252
 
253
  /**
256
  */
257
  public function shippingDescription()
258
  {
259
+ return $this->shippingDescription;
 
 
 
 
 
 
 
 
 
260
  }
261
 
262
  /**
265
  */
266
  public function paymentDescription()
267
  {
268
+ return $this->paymentDescription;
 
 
 
 
 
 
 
 
 
 
 
 
 
269
  }
270
 
271
  /**
app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Quote/Item.php CHANGED
@@ -29,18 +29,11 @@
29
  */
30
  class Copernica_MarketingSoftware_Model_Abstraction_Quote_Item implements Serializable
31
  {
32
- /**
33
- * The original object
34
- * @param Mage_Sales_Model_Quote_Item
35
- */
36
- protected $original;
37
-
38
  /**
39
  * Predefine the internal fields
40
  */
41
  protected $id;
42
  protected $quoteId;
43
- protected $storeId;
44
  protected $quantity;
45
  protected $price;
46
  protected $weight;
@@ -55,7 +48,23 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote_Item implements Serial
55
  */
56
  public function setOriginal(Mage_Sales_Model_Quote_Item $original)
57
  {
58
- $this->original = $original;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  return $this;
60
  }
61
 
@@ -65,12 +74,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote_Item implements Serial
65
  */
66
  public function id()
67
  {
68
- // Is this object still present?
69
- if (is_object($this->original))
70
- {
71
- return $this->original->getId();
72
- }
73
- else return $this->id;
74
  }
75
 
76
  /**
@@ -79,16 +83,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote_Item implements Serial
79
  */
80
  public function quote()
81
  {
82
- // Is this object still present?
83
- if (is_object($this->original))
84
- {
85
- if ($quote = $this->original->getQuote()) {
86
- return Mage::getModel('marketingsoftware/abstraction_quote')->setOriginal($quote);
87
- } else {
88
- return null;
89
- }
90
- }
91
- else return Mage::getModel('marketingsoftware/abstraction_quote')->loadQuote($this->quoteId);
92
  }
93
 
94
  /**
@@ -97,12 +92,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote_Item implements Serial
97
  */
98
  public function quantity()
99
  {
100
- // Is this object still present?
101
- if (is_object($this->original))
102
- {
103
- return $this->original->getQty();
104
- }
105
- else return $this->quantity;
106
  }
107
 
108
  /**
@@ -112,13 +102,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote_Item implements Serial
112
  */
113
  public function price()
114
  {
115
- // Is this object still present?
116
- if (is_object($this->original))
117
- {
118
- // Note that the price may consist of multiple elements
119
- return Mage::getModel('marketingsoftware/abstraction_price')->setOriginal($this->original);
120
- }
121
- else return $this->price;
122
  }
123
 
124
  /**
@@ -127,12 +111,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote_Item implements Serial
127
  */
128
  public function weight()
129
  {
130
- // Is this object still present?
131
- if (is_object($this->original))
132
- {
133
- return $this->original->getWeight();
134
- }
135
- else return $this->weight;
136
  }
137
 
138
  /**
@@ -141,12 +120,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote_Item implements Serial
141
  */
142
  public function timestamp()
143
  {
144
- // Is this object still present?
145
- if (is_object($this->original))
146
- {
147
- return $this->original->getUpdatedAt();
148
- }
149
- else return $this->timestamp;
150
  }
151
 
152
  /**
@@ -155,18 +129,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote_Item implements Serial
155
  */
156
  public function options()
157
  {
158
- // Is this object still present?
159
- if (is_object($this->original))
160
- {
161
- $options = Mage::getModel('marketingsoftware/abstraction_quote_item_options')->setOriginal($this->original);
162
- if ($options->attributes()) {
163
- //only return option object if it this quote actually has options
164
- return $options;
165
- } else {
166
- return null;
167
- }
168
- }
169
- else return $this->options;
170
  }
171
 
172
  /**
@@ -175,12 +138,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote_Item implements Serial
175
  */
176
  public function product()
177
  {
178
- // Is this object still present?
179
- if (is_object($this->original))
180
- {
181
- return Mage::getModel('marketingsoftware/abstraction_product')->setOriginal($this->original);
182
- }
183
- else return $this->product;
184
  }
185
 
186
  /**
29
  */
30
  class Copernica_MarketingSoftware_Model_Abstraction_Quote_Item implements Serializable
31
  {
 
 
 
 
 
 
32
  /**
33
  * Predefine the internal fields
34
  */
35
  protected $id;
36
  protected $quoteId;
 
37
  protected $quantity;
38
  protected $price;
39
  protected $weight;
48
  */
49
  public function setOriginal(Mage_Sales_Model_Quote_Item $original)
50
  {
51
+ $this->id = $original->getId();
52
+ $this->quantity = $original->getQty();
53
+ $this->price = Mage::getModel('marketingsoftware/abstraction_price')->setOriginal($original);
54
+ $this->weight = $original->getWeight();
55
+ $this->timestamp = $original->getUpdatedAt();
56
+ $this->product = Mage::getModel('marketingsoftware/abstraction_product')->setOriginal($original);
57
+
58
+ $options = Mage::getModel('marketingsoftware/abstraction_quote_item_options')->setOriginal($original);
59
+ if ($options->attributes()) {
60
+ //only return option object if it this quote actually has options
61
+ $this->options = $options;
62
+ }
63
+
64
+ if ($quote = $original->getQuote()) {
65
+ $this->quoteId = $quote->getId();
66
+ }
67
+
68
  return $this;
69
  }
70
 
74
  */
75
  public function id()
76
  {
77
+ return $this->id;
 
 
 
 
 
78
  }
79
 
80
  /**
83
  */
84
  public function quote()
85
  {
86
+ return Mage::getModel('marketingsoftware/abstraction_quote')->loadQuote($this->quoteId);
 
 
 
 
 
 
 
 
 
87
  }
88
 
89
  /**
92
  */
93
  public function quantity()
94
  {
95
+ return $this->quantity;
 
 
 
 
 
96
  }
97
 
98
  /**
102
  */
103
  public function price()
104
  {
105
+ return $this->price;
 
 
 
 
 
 
106
  }
107
 
108
  /**
111
  */
112
  public function weight()
113
  {
114
+ return $this->weight;
 
 
 
 
 
115
  }
116
 
117
  /**
120
  */
121
  public function timestamp()
122
  {
123
+ return $this->timestamp;
 
 
 
 
 
124
  }
125
 
126
  /**
129
  */
130
  public function options()
131
  {
132
+ return $this->options;
 
 
 
 
 
 
 
 
 
 
 
133
  }
134
 
135
  /**
138
  */
139
  public function product()
140
  {
141
+ return $this->product;
 
 
 
 
 
142
  }
143
 
144
  /**
app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Quote/Item/Options.php CHANGED
@@ -29,17 +29,11 @@
29
  */
30
  class Copernica_MarketingSoftware_Model_Abstraction_Quote_Item_Options implements Serializable
31
  {
32
- /**
33
- * The original object
34
- * @param Mage_Sales_Model_Quote_Item
35
- */
36
- protected $original;
37
-
38
  /**
39
  * Predefine the internal fields
40
  */
41
  protected $name;
42
- protected $attributes;
43
 
44
 
45
  /**
@@ -49,7 +43,34 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote_Item_Options implement
49
  */
50
  public function setOriginal(Mage_Sales_Model_Quote_Item $original)
51
  {
52
- $this->original = $original;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
  return $this;
54
  }
55
 
@@ -59,12 +80,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote_Item_Options implement
59
  */
60
  public function name()
61
  {
62
- // Is this object still present?
63
- if (is_object($this->original))
64
- {
65
- return $this->original->getName();
66
- }
67
- else return $this->name;
68
  }
69
 
70
  /**
@@ -73,36 +89,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Quote_Item_Options implement
73
  */
74
  public function attributes()
75
  {
76
- // Is this object still present?
77
- if (is_object($this->original))
78
- {
79
- $data = array();
80
- if ($optionData = $this->original->getOptionByCode('info_buyRequest')) {
81
- $product = $optionData->getProduct();
82
- //this converts the options to a usable format (same as order items)
83
- //see: Mage_Sales_Model_Convert_Quote::itemToOrderItem
84
- $options = $this->original->getProduct()->getTypeInstance(true)->getOrderOptions($this->original->getProduct());
85
- $attributes = array();
86
- if (isset($options['attributes_info'])) {
87
- //configurable products
88
- $attributes = $options['attributes_info'];
89
- } elseif (isset($options['bundle_options'])) {
90
- //bundle products
91
- $attributes = $options['bundle_options'];
92
- } elseif (isset($options['options'])) {
93
- //generic products
94
- $attributes = $options['options'];
95
- }
96
- if ($attributes) {
97
- foreach ($attributes as $attribute) {
98
- $data[$attribute['label']] = $attribute['value'];
99
- }
100
- return $data;
101
- }
102
- }
103
- return null;
104
- }
105
- else return $this->attributes;
106
  }
107
 
108
  /**
29
  */
30
  class Copernica_MarketingSoftware_Model_Abstraction_Quote_Item_Options implements Serializable
31
  {
 
 
 
 
 
 
32
  /**
33
  * Predefine the internal fields
34
  */
35
  protected $name;
36
+ protected $attributes = null;
37
 
38
 
39
  /**
43
  */
44
  public function setOriginal(Mage_Sales_Model_Quote_Item $original)
45
  {
46
+ $this->name = $original->getName();
47
+
48
+ $data = array();
49
+ if ($optionData = $original->getOptionByCode('info_buyRequest')) {
50
+ $product = $optionData->getProduct();
51
+ //this converts the options to a usable format (same as order items)
52
+ //see: Mage_Sales_Model_Convert_Quote::itemToOrderItem
53
+ $options = $original->getProduct()->getTypeInstance(true)->getOrderOptions($original->getProduct());
54
+ $attributes = array();
55
+ if (isset($options['attributes_info'])) {
56
+ //configurable products
57
+ $attributes = $options['attributes_info'];
58
+ } elseif (isset($options['bundle_options'])) {
59
+ //bundle products
60
+ $attributes = $options['bundle_options'];
61
+ } elseif (isset($options['options'])) {
62
+ //generic products
63
+ $attributes = $options['options'];
64
+ }
65
+
66
+ if ($attributes) {
67
+ foreach ($attributes as $attribute) {
68
+ $data[$attribute['label']] = $attribute['value'];
69
+ }
70
+ $this->attributes = $data;
71
+ }
72
+ }
73
+
74
  return $this;
75
  }
76
 
80
  */
81
  public function name()
82
  {
83
+ return $this->name;
 
 
 
 
 
84
  }
85
 
86
  /**
89
  */
90
  public function attributes()
91
  {
92
+ return $this->attributes;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
  }
94
 
95
  /**
app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Storeview.php CHANGED
@@ -29,12 +29,6 @@
29
  */
30
  class Copernica_MarketingSoftware_Model_Abstraction_Storeview implements Serializable
31
  {
32
- /**
33
- * The original object
34
- * @param Mage_Core_Model_Store
35
- */
36
- protected $original;
37
-
38
  /**
39
  * Predefine the internal fields
40
  */
@@ -46,7 +40,6 @@ class Copernica_MarketingSoftware_Model_Abstraction_Storeview implements Seriali
46
  protected $viewCode;
47
  protected $viewLabel;
48
 
49
-
50
  /**
51
  * Sets the original model
52
  * @param Mage_Core_Model_Store $original
@@ -54,7 +47,16 @@ class Copernica_MarketingSoftware_Model_Abstraction_Storeview implements Seriali
54
  */
55
  public function setOriginal(Mage_Core_Model_Store $original)
56
  {
57
- $this->original = $original;
 
 
 
 
 
 
 
 
 
58
  return $this;
59
  }
60
 
@@ -64,12 +66,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Storeview implements Seriali
64
  */
65
  public function id()
66
  {
67
- // Is this object still present?
68
- if ($this->original instanceof Mage_Core_Model_Store && $this->original->getWebsite() instanceof Mage_Core_Model_Website)
69
- {
70
- return $this->original->getId();
71
- }
72
- else return $this->id;
73
  }
74
 
75
  /**
@@ -77,13 +74,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Storeview implements Seriali
77
  * @return string
78
  */
79
  public function websiteCode()
80
- {
81
- // Is this object still present?
82
- if ($this->original instanceof Mage_Core_Model_Store && $this->original->getWebsite() instanceof Mage_Core_Model_Website)
83
- {
84
- return $this->original->getWebsite()->getCode();
85
- }
86
-
87
  return $this->websiteCode;
88
  }
89
 
@@ -93,12 +84,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Storeview implements Seriali
93
  */
94
  public function websiteLabel()
95
  {
96
- // Is this object still present?
97
- if ($this->original instanceof Mage_Core_Model_Store && $this->original->getWebsite() instanceof Mage_Core_Model_Website)
98
- {
99
- return $this->original->getWebsite()->getName();
100
- }
101
- else return $this->websiteLabel;
102
  }
103
 
104
  /**
@@ -107,12 +93,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Storeview implements Seriali
107
  */
108
  public function storeCode()
109
  {
110
- // Is this object still present?
111
- if ($this->original instanceof Mage_Core_Model_Store && $this->original->getWebsite() instanceof Mage_Core_Model_Website)
112
- {
113
- return $this->original->getGroup()->getId();
114
- }
115
- else return $this->storeCode;
116
  }
117
 
118
  /**
@@ -121,12 +102,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Storeview implements Seriali
121
  */
122
  public function storeLabel()
123
  {
124
- // Is this object still present?
125
- if ($this->original instanceof Mage_Core_Model_Store && $this->original->getWebsite() instanceof Mage_Core_Model_Website)
126
- {
127
- return $this->original->getGroup()->getName();
128
- }
129
- else return $this->storeLabel;
130
  }
131
 
132
  /**
@@ -135,12 +111,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Storeview implements Seriali
135
  */
136
  public function viewCode()
137
  {
138
- // Is this object still present?
139
- if ($this->original instanceof Mage_Core_Model_Store && $this->original->getWebsite() instanceof Mage_Core_Model_Website)
140
- {
141
- return $this->original->getCode();
142
- }
143
- else return $this->viewCode;
144
  }
145
 
146
  /**
@@ -149,12 +120,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Storeview implements Seriali
149
  */
150
  public function viewLabel()
151
  {
152
- // Is this object still present?
153
- if ($this->original instanceof Mage_Core_Model_Store && $this->original->getWebsite() instanceof Mage_Core_Model_Website)
154
- {
155
- return $this->original->getName();
156
- }
157
- else return $this->viewLabel;
158
  }
159
 
160
  /**
29
  */
30
  class Copernica_MarketingSoftware_Model_Abstraction_Storeview implements Serializable
31
  {
 
 
 
 
 
 
32
  /**
33
  * Predefine the internal fields
34
  */
40
  protected $viewCode;
41
  protected $viewLabel;
42
 
 
43
  /**
44
  * Sets the original model
45
  * @param Mage_Core_Model_Store $original
47
  */
48
  public function setOriginal(Mage_Core_Model_Store $original)
49
  {
50
+ if ($original->getWebsite() instanceof Mage_Core_Model_Website) {
51
+ $this->id = $original->getId();
52
+ $this->websiteCode = $original->getWebsite()->getCode();
53
+ $this->websiteLabel = $original->getWebsite()->getName();
54
+ $this->storeCode = $original->getGroup()->getId();
55
+ $this->storeLabel = $original->getGroup()->getName();
56
+ $this->viewCode = $original->getCode();
57
+ $this->viewLabel = $original->getName();
58
+ }
59
+
60
  return $this;
61
  }
62
 
66
  */
67
  public function id()
68
  {
69
+ return $this->id;
 
 
 
 
 
70
  }
71
 
72
  /**
74
  * @return string
75
  */
76
  public function websiteCode()
77
+ {
 
 
 
 
 
 
78
  return $this->websiteCode;
79
  }
80
 
84
  */
85
  public function websiteLabel()
86
  {
87
+ return $this->websiteLabel;
 
 
 
 
 
88
  }
89
 
90
  /**
93
  */
94
  public function storeCode()
95
  {
96
+ return $this->storeCode;
 
 
 
 
 
97
  }
98
 
99
  /**
102
  */
103
  public function storeLabel()
104
  {
105
+ return $this->storeLabel;
 
 
 
 
 
106
  }
107
 
108
  /**
111
  */
112
  public function viewCode()
113
  {
114
+ return $this->viewCode;
 
 
 
 
 
115
  }
116
 
117
  /**
120
  */
121
  public function viewLabel()
122
  {
123
+ return $this->viewLabel;
 
 
 
 
 
124
  }
125
 
126
  /**
app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Subscription.php CHANGED
@@ -29,12 +29,6 @@
29
  */
30
  class Copernica_MarketingSoftware_Model_Abstraction_Subscription implements Serializable
31
  {
32
- /**
33
- * The original object
34
- * @param Mage_Newsletter_Model_Subscriber
35
- */
36
- protected $original;
37
-
38
  /**
39
  * Predefine the internal fields
40
  */
@@ -51,7 +45,31 @@ class Copernica_MarketingSoftware_Model_Abstraction_Subscription implements Seri
51
  */
52
  public function setOriginal(Mage_Newsletter_Model_Subscriber $original)
53
  {
54
- $this->original = $original;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  return $this;
56
  }
57
 
@@ -61,12 +79,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Subscription implements Seri
61
  */
62
  public function id()
63
  {
64
- // Is this object still present?
65
- if (is_object($this->original))
66
- {
67
- return $this->original->getId();
68
- }
69
- else return $this->id;
70
  }
71
 
72
  /**
@@ -75,12 +88,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Subscription implements Seri
75
  */
76
  public function email()
77
  {
78
- // Is this object still present?
79
- if (is_object($this->original))
80
- {
81
- return $this->original->getEmail();
82
- }
83
- else return $this->email;
84
  }
85
 
86
  /**
@@ -90,28 +98,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Subscription implements Seri
90
  */
91
  public function status()
92
  {
93
- // Is this object still present?
94
- if (is_object($this->original))
95
- {
96
- switch ($this->original->getStatus()) {
97
- case Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED:
98
- return 'subscribed';
99
- break;
100
- case Mage_Newsletter_Model_Subscriber::STATUS_NOT_ACTIVE:
101
- return 'not active';
102
- break;
103
- case Mage_Newsletter_Model_Subscriber::STATUS_UNSUBSCRIBED:
104
- return 'unsubscribed';
105
- break;
106
- case Mage_Newsletter_Model_Subscriber::STATUS_UNCONFIRMED:
107
- return 'unconfirmed';
108
- break;
109
- default:
110
- return 'unknown';
111
- break;
112
- }
113
- }
114
- else return $this->status;
115
  }
116
 
117
  /**
@@ -120,21 +107,12 @@ class Copernica_MarketingSoftware_Model_Abstraction_Subscription implements Seri
120
  */
121
  public function customer()
122
  {
123
- // Is this object still present?
124
- if (is_object($this->original))
125
- {
126
- if ($customerId = $this->original->getCustomerId()) {
127
- return Mage::getModel('marketingsoftware/abstraction_customer')->loadCustomer($customerId);
128
- } else {
129
- return null;
130
- }
131
- }
132
- elseif ($this->customerId)
133
- {
134
  // construct an object given the identifier
135
  return Mage::getModel('marketingsoftware/abstraction_customer')->loadCustomer($this->customerId);
 
 
136
  }
137
- else return null;
138
  }
139
 
140
  /**
@@ -143,13 +121,7 @@ class Copernica_MarketingSoftware_Model_Abstraction_Subscription implements Seri
143
  */
144
  public function storeView()
145
  {
146
- // Is this object still present?
147
- if (is_object($this->original))
148
- {
149
- $store = Mage::getModel('core/store')->load($this->original->getStoreId());
150
- return Mage::getModel('marketingsoftware/abstraction_storeview')->setOriginal($store);
151
- }
152
- else return $this->storeview;
153
  }
154
 
155
  /**
29
  */
30
  class Copernica_MarketingSoftware_Model_Abstraction_Subscription implements Serializable
31
  {
 
 
 
 
 
 
32
  /**
33
  * Predefine the internal fields
34
  */
45
  */
46
  public function setOriginal(Mage_Newsletter_Model_Subscriber $original)
47
  {
48
+ $this->id = $original->getId();
49
+ $this->email = $original->getEmail();
50
+ $this->customerId = $original->getCustomerId();
51
+
52
+ $store = Mage::getModel('core/store')->load($original->getStoreId());
53
+ $this->storeview = Mage::getModel('marketingsoftware/abstraction_storeview')->setOriginal($store);
54
+
55
+ switch ($original->getStatus()) {
56
+ case Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED:
57
+ $this->status = 'subscribed';
58
+ break;
59
+ case Mage_Newsletter_Model_Subscriber::STATUS_NOT_ACTIVE:
60
+ $this->status = 'not active';
61
+ break;
62
+ case Mage_Newsletter_Model_Subscriber::STATUS_UNSUBSCRIBED:
63
+ $this->status = 'unsubscribed';
64
+ break;
65
+ case Mage_Newsletter_Model_Subscriber::STATUS_UNCONFIRMED:
66
+ $this->status = 'unconfirmed';
67
+ break;
68
+ default:
69
+ $this->status = 'unknown';
70
+ break;
71
+ }
72
+
73
  return $this;
74
  }
75
 
79
  */
80
  public function id()
81
  {
82
+ return $this->id;
 
 
 
 
 
83
  }
84
 
85
  /**
88
  */
89
  public function email()
90
  {
91
+ return $this->email;
 
 
 
 
 
92
  }
93
 
94
  /**
98
  */
99
  public function status()
100
  {
101
+ return $this->status;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
  }
103
 
104
  /**
107
  */
108
  public function customer()
109
  {
110
+ if ($this->customerId) {
 
 
 
 
 
 
 
 
 
 
111
  // construct an object given the identifier
112
  return Mage::getModel('marketingsoftware/abstraction_customer')->loadCustomer($this->customerId);
113
+ } else {
114
+ return null;
115
  }
 
116
  }
117
 
118
  /**
121
  */
122
  public function storeView()
123
  {
124
+ return $this->storeview;
 
 
 
 
 
 
125
  }
126
 
127
  /**
app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Viewedproduct.php ADDED
@@ -0,0 +1,427 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
22
+ * @package Copernica_MarketingSoftware
23
+ * @copyright Copyright (c) 2011-2012 Copernica & Cream. (http://docs.cream.nl/)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * A wrapper object around a magento Product
29
+ */
30
+ class Copernica_MarketingSoftware_Model_Abstraction_Viewedproduct implements Serializable
31
+ {
32
+ /**
33
+ * Predefine the internal fields
34
+ */
35
+ public $id;
36
+ protected $sku;
37
+ protected $name;
38
+ protected $description;
39
+ protected $productUrl;
40
+ protected $imagePath;
41
+ protected $weight;
42
+ protected $categories = array();
43
+ protected $isNew;
44
+ protected $price;
45
+ protected $specialPrice;
46
+ protected $created;
47
+ protected $modified;
48
+ protected $attributes;
49
+ protected $attributeSet;
50
+ public $customerId;
51
+ protected $timestamp;
52
+
53
+ /**
54
+ * Sets the original model
55
+ * @param Mage_Catalog_Model_Product|Mage_Sales_Model_Quote_Item|Mage_Sales_Model_Order_Item $original
56
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Product
57
+ */
58
+ public function setOriginal($original, $id)
59
+ {
60
+ if ($original instanceof Mage_Catalog_Model_Product) {
61
+ //this is the original product
62
+ $this->id = $original->getId();
63
+ $this->sku = $original->getSku();
64
+ $this->name = $original->getName();
65
+ $this->description = $original->getShortDescription();
66
+ $this->price = $original->getPrice();
67
+ $this->specialPrice = $original->getSpecialPrice();
68
+ $this->created = $original->getCreatedAt();
69
+ $this->modified = $original->getUpdatedAt();
70
+ $this->productUrl = $original->getProductUrl();
71
+ $this->imagePath = 'catalog' . DS . 'product' . $original->getImage();
72
+ $this->weight = $original->getWeight();
73
+
74
+ $data = array();
75
+ $categoryIds = $original->getCategoryIds();
76
+ foreach ($categoryIds as $categoryId) {
77
+ $category = Mage::getModel('catalog/category')->load($categoryId);
78
+ $data[] = $this->_getFullCategoryName($category);
79
+ }
80
+ $this->categories = $data;
81
+
82
+ $from = $original->getNewsFromDate() ? Mage::app()->getLocale()->date($original->getNewsFromDate()) : null;
83
+ $to = $original->getNewsToDate() ? Mage::app()->getLocale()->date($original->getNewsToDate()) : null;
84
+ if ($from || $to) {
85
+ $new = true;
86
+ $now = Zend_Date::now();
87
+ if ($from) {
88
+ $new = $new && $from->isEarlier($now);
89
+ }
90
+ if ($to) {
91
+ $new = $new && $to->isLater($now);
92
+ }
93
+ $this->isNew = $new;
94
+ } else {
95
+ $this->isNew = false;
96
+ }
97
+
98
+ $this->attributes = Mage::getModel('marketingsoftware/abstraction_attributes')->setOriginal($original);
99
+
100
+ $attributeSetModel = Mage::getModel("eav/entity_attribute_set");
101
+ $attributeSetModel->load($original->getAttributeSetId());
102
+
103
+ $this->attributeSet = $attributeSetModel->getAttributeSetName();
104
+
105
+ $this->timestamp = time();
106
+
107
+ $this->customerId = $id;
108
+ $this->storeId = Mage::app()->getStore()->getStoreId();
109
+
110
+ return $this;
111
+ } else {
112
+ //the quote item or order item has a product id
113
+ $product = Mage::getModel('catalog/product')->load($original->getProductId());
114
+ if ($product->getId()) {
115
+ //the product exists
116
+ $this->id = $product->getId();
117
+ $this->sku = $product->getSku();
118
+ $this->name = $product->getName();
119
+ $this->description = $product->getShortDescription();
120
+ $this->price = $product->getPrice();
121
+ $this->specialPrice = $product->getSpecialPrice();
122
+ $this->created = $product->getCreatedAt();
123
+ $this->modified = $product->getUpdatedAt();
124
+ $this->productUrl = $product->getProductUrl();
125
+ $this->imagePath = 'catalog' . DS . 'product' . $product->getImage();
126
+ $this->weight = $product->getWeight();
127
+
128
+ $data = array();
129
+ $categoryIds = $product->getCategoryIds();
130
+ foreach ($categoryIds as $categoryId) {
131
+ $category = Mage::getModel('catalog/category')->load($categoryId);
132
+ $data[] = $this->_getFullCategoryName($category);
133
+ }
134
+ $this->categories = $data;
135
+
136
+ $from = $product->getNewsFromDate() ? Mage::app()->getLocale()->date($product->getNewsFromDate()) : null;
137
+ $to = $product->getNewsToDate() ? Mage::app()->getLocale()->date($product->getNewsToDate()) : null;
138
+ if ($from || $to) {
139
+ $new = true;
140
+ $now = Zend_Date::now();
141
+ if ($from) {
142
+ $new = $new && $from->isEarlier($now);
143
+ }
144
+ if ($to) {
145
+ $new = $new && $to->isLater($now);
146
+ }
147
+ $this->isNew = $new;
148
+ } else {
149
+ $this->isNew = false;
150
+ }
151
+
152
+ $this->attributes = Mage::getModel('marketingsoftware/abstraction_attributes')->setOriginal($product);
153
+
154
+ $attributeSetModel = Mage::getModel("eav/entity_attribute_set");
155
+ $attributeSetModel->load($product->getAttributeSetId());
156
+
157
+ $this->attributeSet = $attributeSetModel->getAttributeSetName();
158
+
159
+ $this->timestamp = time();
160
+ } else {
161
+ // unfortunately we do not have the product any more, but we have the information
162
+ // so we can fill a lot of fields, so the functions still work
163
+ $this->id = $original->getProductId();
164
+ $this->sku = $original->getSKU();
165
+ $this->attributeSet = '';
166
+ $this->name = $original->getName();
167
+ $this->description = $original->getDescription();
168
+ $this->productUrl = '';
169
+ $this->imagePath = '';
170
+ $this->weight = $original->getWeight();
171
+ $this->categories = array();
172
+ $this->isNew = false;
173
+ $this->price = $original->getPrice();
174
+ $this->created = '';
175
+ $this->modified = '';
176
+ $this->attributes = '';
177
+ $this->customerId = $id;
178
+ $this->storeId = Mage::app()->getStore()->getStoreId();
179
+ }
180
+
181
+ return $this;
182
+ }
183
+ }
184
+
185
+ /**
186
+ * Loads a product model
187
+ * @param integer $productId
188
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Product
189
+ */
190
+ public function loadProduct($productId)
191
+ {
192
+ $product = Mage::getModel('catalog/product')->load($productId);
193
+ if ($product->getId()) {
194
+ //set the original model if the product exists
195
+ $this->setOriginal($product);
196
+ }
197
+ else
198
+ {
199
+ $this->id = $productId;
200
+ }
201
+ return $this;
202
+ }
203
+
204
+ /**
205
+ * Return the identifier for this object
206
+ * @return integer
207
+ */
208
+ public function id()
209
+ {
210
+ return $this->id;
211
+ }
212
+
213
+ /**
214
+ * Return the sku (stock keeping unit), which is an unique identifier
215
+ * for a magento product
216
+ * @return string
217
+ */
218
+ public function sku()
219
+ {
220
+ return $this->sku;
221
+ }
222
+
223
+ /**
224
+ * Return the name of this magento product
225
+ * @return string
226
+ */
227
+ public function name()
228
+ {
229
+ return $this->name;
230
+ }
231
+
232
+ /**
233
+ * Return the description of this magento product
234
+ * @return string
235
+ */
236
+ public function description()
237
+ {
238
+ return $this->description;
239
+ }
240
+
241
+ /**
242
+ * Return the price of this magento product
243
+ * @return string
244
+ */
245
+ public function price()
246
+ {
247
+ return $this->price;
248
+ }
249
+
250
+ /**
251
+ * Return the price of this magento product
252
+ * @return string
253
+ */
254
+ public function specialPrice()
255
+ {
256
+ return $this->specialPrice;
257
+ }
258
+
259
+
260
+ /**
261
+ * Return the creation date of this magento product
262
+ * @return string
263
+ */
264
+ public function created()
265
+ {
266
+ return $this->created;
267
+ }
268
+
269
+ /**
270
+ * Return the modification date of this magento product
271
+ * @return string
272
+ */
273
+ public function modified()
274
+ {
275
+ return $this->modified;
276
+ }
277
+
278
+ /**
279
+ * Return the product url of this magento product
280
+ * @param integer optional store id
281
+ * @return string
282
+ */
283
+ public function productUrl($storeId = null)
284
+ {
285
+ return $this->productUrl;
286
+ }
287
+
288
+ /**
289
+ * Return the image url of this magento product
290
+ * @param integer|boolean optional store id, if false is given only the path is returned
291
+ * @return string
292
+ */
293
+ public function imageUrl($storeId = null)
294
+ {
295
+ return $this->imagePath;
296
+ }
297
+
298
+ /**
299
+ * Return the weight of this magento product
300
+ * @return float
301
+ */
302
+ public function weight()
303
+ {
304
+ return $this->weight;
305
+ }
306
+
307
+ /**
308
+ * Return the categories of this product
309
+ * @return array of category ids to category names in a path from the root
310
+ */
311
+ public function categories()
312
+ {
313
+ return $this->categories;
314
+ }
315
+
316
+ /**
317
+ * Return the flattened tree of the given category
318
+ * @param Mage_Catalog_Model_Category $category
319
+ * @return array
320
+ */
321
+ protected function _getFullCategoryName(Mage_Catalog_Model_Category $category)
322
+ {
323
+ // is there a parent?
324
+ if ($category->getParentId() > 1)
325
+ {
326
+ // get the parent
327
+ $parent = $category->getParentCategory();
328
+ $data = $this->_getFullCategoryName($parent);
329
+ } else {
330
+ $data = array();
331
+ }
332
+
333
+ // append the current name
334
+ $data[$category->getId()] = $category->getName();
335
+
336
+ // return the data
337
+ return $data;
338
+ }
339
+
340
+ /**
341
+ * Return whether this product is new
342
+ * @return boolean
343
+ */
344
+ public function isNew()
345
+ {
346
+ return $this->isNew;
347
+ }
348
+
349
+ /**
350
+ * Return the attributes for this product
351
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Attributes
352
+ */
353
+ public function attributes()
354
+ {
355
+ return $this->attributes;
356
+ }
357
+
358
+ public function attributeSet()
359
+ {
360
+ return $this->attributeSet;
361
+ }
362
+
363
+ public function timestamp()
364
+ {
365
+ return $this->timestamp;
366
+ }
367
+
368
+
369
+ /**
370
+ * Serialize the object
371
+ * @return string
372
+ */
373
+ public function serialize()
374
+ {
375
+ // serialize the data
376
+ return serialize(array(
377
+ $this->id(),
378
+ $this->sku(),
379
+ $this->attributeSet(),
380
+ $this->name(),
381
+ $this->description(),
382
+ $this->productUrl(),
383
+ $this->imageUrl(false), // gets the image path if store 'false' is supplied
384
+ $this->weight(),
385
+ $this->categories(),
386
+ $this->isNew(),
387
+ $this->price(),
388
+ $this->specialPrice(),
389
+ $this->created(),
390
+ $this->modified(),
391
+ $this->attributes(),
392
+ $this->customerId,
393
+ $this->storeId,
394
+ $this->timestamp()
395
+ ));
396
+ }
397
+
398
+ /**
399
+ * Unserialize the object
400
+ * @param string
401
+ * @return Copernica_MarketingSoftware_Model_Abstraction_Product
402
+ */
403
+ public function unserialize($string)
404
+ {
405
+ list(
406
+ $this->id,
407
+ $this->sku,
408
+ $this->attributeSet,
409
+ $this->name,
410
+ $this->description,
411
+ $this->productUrl,
412
+ $this->imagePath,
413
+ $this->weight,
414
+ $this->categories,
415
+ $this->isNew,
416
+ $this->price,
417
+ $this->specialPrice,
418
+ $this->created,
419
+ $this->modified,
420
+ $this->attributes,
421
+ $this->customerId,
422
+ $this->storeId,
423
+ $this->timestamp
424
+ ) = unserialize($string);
425
+ return $this;
426
+ }
427
+ }
app/code/community/Copernica/MarketingSoftware/Model/Abstraction/readme.txt DELETED
@@ -1,7 +0,0 @@
1
- Note:
2
- To ensure compatibility with Magento, Mage::getModel is used to load classes.
3
- However, the Abstraction classes (and possibly other classes) do not extend
4
- Mage_Core_Model_Abstract as documented in the getModel function's return type.
5
- Extending this class would result in unnecessary overhead.
6
- If you do encounter problems with model loading in future versions of Magento,
7
- please check the getModel function in app/Mage.php.
 
 
 
 
 
 
 
app/code/community/Copernica/MarketingSoftware/Model/Copernica/Viewedproduct/Subprofile.php ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
22
+ * @package Copernica_MarketingSoftware
23
+ * @copyright Copyright (c) 2011-2012 Copernica & Cream. (http://docs.cream.nl/)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * An object to wrap the Copernica profile
29
+ */
30
+ class Copernica_MarketingSoftware_Model_Copernica_Viewedproduct_Subprofile extends Copernica_MarketingSoftware_Model_Copernica_Abstract
31
+ {
32
+ /**
33
+ * @var Copernica_MarketingSoftware_Model_Abstraction_Viewedproduct
34
+ */
35
+ protected $viewedProduct = false;
36
+
37
+ /**
38
+ * Return the identifier for this profile
39
+ * @return string
40
+ */
41
+ public function id()
42
+ {
43
+ return $this->viewedProduct->id;
44
+ }
45
+
46
+ public function customerId()
47
+ {
48
+ return $this->viewedProduct->customerId;
49
+ }
50
+
51
+ /**
52
+ * Try to store a quote item
53
+ * @param Copernica_MarketingSoftware_Model_Copernica_Orderitem_Subprofile
54
+ */
55
+ public function setViewedProduct($product)
56
+ {
57
+ $this->viewedProduct = $product;
58
+ return $this;
59
+ }
60
+
61
+ /**
62
+ * Get linked fields
63
+ * @return array
64
+ */
65
+ public function linkedFields()
66
+ {
67
+ return Mage::helper('marketingsoftware/config')->getLinkedViewedProductFields();
68
+ }
69
+
70
+ /**
71
+ * Get the required fields
72
+ * @return array
73
+ */
74
+ public function requiredFields()
75
+ {
76
+ return array('id');
77
+ }
78
+
79
+ /**
80
+ * Retrieve the data for this object
81
+ * @return array
82
+ */
83
+ protected function _data()
84
+ {
85
+ // Store the quoteItem and the product localy
86
+ $product = $this->viewedProduct;
87
+
88
+ // Get the store id to make sure that we retrieve the correct url's
89
+ $storeId = $product->storeId;
90
+
91
+ // flatten the categories
92
+ $categories = array();
93
+ if ($product->categories()) {
94
+ foreach ($product->categories() as $category) $categories[] = implode(' > ', $category);
95
+ }
96
+
97
+ // construct an array of data
98
+ return array(
99
+ 'product_id' => $product->id(),
100
+ 'price' => $product->price(),
101
+ 'name' => $product->name(),
102
+ 'sku' => $product->sku(),
103
+ 'attribute_set' => $product->attributeSet(),
104
+ 'weight' => $product->weight(),
105
+ 'total_price' => $product->price(),
106
+ 'url' => $product->productUrl($storeId),
107
+ 'image' => $product->imageUrl($storeId),
108
+ 'categories' => implode("\n", $categories),
109
+ 'attributes' => (string)$product->attributes(),
110
+ 'timestamp' => $product->timestamp()
111
+ );
112
+ }
113
+ }
app/code/community/Copernica/MarketingSoftware/Model/Observer.php CHANGED
@@ -257,6 +257,38 @@ class Copernica_MarketingSoftware_Model_Observer
257
  }
258
  }
259
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
260
  /**
261
  * Is the Copernica module enabled?
262
  *
@@ -286,7 +318,7 @@ class Copernica_MarketingSoftware_Model_Observer
286
  // Set the the time limit to a high number
287
  set_time_limit(0);
288
  $collection = Mage::getResourceModel('marketingsoftware/queue_collection')
289
- ->addDefaultOrder()->setPageSize(150);
290
 
291
  // store the start time
292
  $time = time();
@@ -322,7 +354,7 @@ class Copernica_MarketingSoftware_Model_Observer
322
  {
323
  // Is the timer already expired
324
  if (time() > ($time + 3 * 60)) break;
325
-
326
  try
327
  {
328
  // we still have time, so lets process an item from the queue
257
  }
258
  }
259
 
260
+ /**
261
+ * Method for event 'sales_quote_item_save_after'.
262
+ * An item is added or modified
263
+ */
264
+ public function productViewed(Varien_Event_Observer $observer)
265
+ {
266
+ // if the plug-in is not enabled, skip this
267
+ if (!$this->enabled()) return;
268
+
269
+ // Do we have a valid item?
270
+ if ($item = $observer->getEvent()->getProduct())
271
+ {
272
+ $customer = Mage::getSingleton('customer/session')->getCustomer();
273
+ $id = $customer->getId();
274
+
275
+ if (!$id) {
276
+ //this item cannot be linked to a customer, so is not relevant at this moment
277
+ return;
278
+ }
279
+
280
+ // wrap the object
281
+ $object = Mage::getModel('marketingsoftware/abstraction_viewedproduct')->setOriginal($item, $id);
282
+
283
+ // This quote item should be added to the queue
284
+ $queue = Mage::getModel('marketingsoftware/queue')
285
+ ->setObject($object)
286
+ ->setAction('add')
287
+ ->save();
288
+ }
289
+ }
290
+
291
+
292
  /**
293
  * Is the Copernica module enabled?
294
  *
318
  // Set the the time limit to a high number
319
  set_time_limit(0);
320
  $collection = Mage::getResourceModel('marketingsoftware/queue_collection')
321
+ ->addDefaultOrder()->setPageSize(300);
322
 
323
  // store the start time
324
  $time = time();
354
  {
355
  // Is the timer already expired
356
  if (time() > ($time + 3 * 60)) break;
357
+
358
  try
359
  {
360
  // we still have time, so lets process an item from the queue
app/code/community/Copernica/MarketingSoftware/Model/Queue.php CHANGED
@@ -72,7 +72,7 @@ class Copernica_MarketingSoftware_Model_Queue extends Mage_Core_Model_Abstract
72
  $factory = Mage::getSingleton('marketingsoftware/QueueEvent_Factory');
73
 
74
  // Wrap the event in a command object (pattern alarm!)
75
- $event = $factory->get($this);
76
 
77
  // call the process function on the object
78
  return $event->process();
72
  $factory = Mage::getSingleton('marketingsoftware/QueueEvent_Factory');
73
 
74
  // Wrap the event in a command object (pattern alarm!)
75
+ $event = $factory->get($this);
76
 
77
  // call the process function on the object
78
  return $event->process();
app/code/community/Copernica/MarketingSoftware/Model/QueueEvent/Factory.php CHANGED
@@ -46,7 +46,7 @@ class Copernica_MarketingSoftware_Model_QueueEvent_Factory
46
 
47
  // Prepare the action, to append it to the classname
48
  $action = ucfirst($queueItem->getAction());
49
-
50
  // What kind of class is given
51
  switch (get_class($queueItem->getObject()))
52
  {
@@ -69,15 +69,19 @@ class Copernica_MarketingSoftware_Model_QueueEvent_Factory
69
  case "Copernica_MarketingSoftware_Model_Abstraction_Subscription":
70
  $classname = "marketingsoftware/QueueEvent_Subscription".$action;
71
  break;
 
 
 
 
72
  }
73
 
74
  // No classname, throw an error
75
  if (!isset($classname)) throw new CopernicaError(COPERNICAERROR_UNRECOGNIZEDEVENT);
76
-
77
  // Get correct classname
78
  $classname = Mage::getConfig()->getModelClassName($classname);
79
  if (!class_exists($classname)) throw new CopernicaError(COPERNICAERROR_UNRECOGNIZEDEVENT);
80
-
81
  // construct the object
82
  return new $classname($queueItem);
83
  }
46
 
47
  // Prepare the action, to append it to the classname
48
  $action = ucfirst($queueItem->getAction());
49
+
50
  // What kind of class is given
51
  switch (get_class($queueItem->getObject()))
52
  {
69
  case "Copernica_MarketingSoftware_Model_Abstraction_Subscription":
70
  $classname = "marketingsoftware/QueueEvent_Subscription".$action;
71
  break;
72
+
73
+ case "Copernica_MarketingSoftware_Model_Abstraction_Viewedproduct":
74
+ $classname = "marketingsoftware/QueueEvent_ViewedProduct".$action;
75
+ break;
76
  }
77
 
78
  // No classname, throw an error
79
  if (!isset($classname)) throw new CopernicaError(COPERNICAERROR_UNRECOGNIZEDEVENT);
80
+
81
  // Get correct classname
82
  $classname = Mage::getConfig()->getModelClassName($classname);
83
  if (!class_exists($classname)) throw new CopernicaError(COPERNICAERROR_UNRECOGNIZEDEVENT);
84
+
85
  // construct the object
86
  return new $classname($queueItem);
87
  }
app/code/community/Copernica/MarketingSoftware/Model/QueueEvent/StartSync.php CHANGED
@@ -103,8 +103,8 @@ class Copernica_MarketingSoftware_Model_QueueEvent_StartSync extends Copernica_M
103
  foreach ($customers as $customer)
104
  {
105
  // Was this record changed or modified after the last synchronisation
106
- if ($customer->getCreatedAt() <= $progressDateTime &&
107
- $customer->getUpdatedAt() <= $progressDateTime ) continue;
108
 
109
  // wrap the object
110
  $object = Mage::getModel('marketingsoftware/abstraction_customer')->loadCustomer($customer->getEntityId());
@@ -185,8 +185,11 @@ class Copernica_MarketingSoftware_Model_QueueEvent_StartSync extends Copernica_M
185
  foreach ($orders as $order)
186
  {
187
  // Was this record changed or modified after the last synchronisation
188
- if ($order->getCreatedAt() <= $progressDateTime &&
189
- $order->getUpdatedAt() <= $progressDateTime ) continue;
 
 
 
190
 
191
  // Only sync guest orders
192
  if ($order->getCustomerId()) continue;
@@ -199,9 +202,6 @@ class Copernica_MarketingSoftware_Model_QueueEvent_StartSync extends Copernica_M
199
  ->setObject($object)
200
  ->save();
201
 
202
- // Get the maximum progress time
203
- $progressDateTime = max($progressDateTime, $order->getUpdatedAt());
204
-
205
  // get rid of the order and the object
206
  unset($order);
207
  unset($object);
103
  foreach ($customers as $customer)
104
  {
105
  // Was this record changed or modified after the last synchronisation
106
+ if ($customer->getCreatedAt() < $progressDateTime &&
107
+ $customer->getUpdatedAt() < $progressDateTime ) continue;
108
 
109
  // wrap the object
110
  $object = Mage::getModel('marketingsoftware/abstraction_customer')->loadCustomer($customer->getEntityId());
185
  foreach ($orders as $order)
186
  {
187
  // Was this record changed or modified after the last synchronisation
188
+ if ($order->getCreatedAt() < $progressDateTime &&
189
+ $order->getUpdatedAt() < $progressDateTime ) continue;
190
+
191
+ // Get the maximum progress time
192
+ $progressDateTime = max($progressDateTime, $order->getUpdatedAt());
193
 
194
  // Only sync guest orders
195
  if ($order->getCustomerId()) continue;
202
  ->setObject($object)
203
  ->save();
204
 
 
 
 
205
  // get rid of the order and the object
206
  unset($order);
207
  unset($object);
app/code/community/Copernica/MarketingSoftware/Model/QueueEvent/ViewedProductAdd.php ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
22
+ * @package Copernica_MarketingSoftware
23
+ * @copyright Copyright (c) 2011-2012 Copernica & Cream. (http://docs.cream.nl/)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * A wrapper object around an event
29
+ */
30
+ class Copernica_MarketingSoftware_Model_QueueEvent_ViewedProductAdd extends Copernica_MarketingSoftware_Model_QueueEvent_Abstract
31
+ {
32
+ /**
33
+ * Process this item in the queue
34
+ * @return boolean was the processing successfull
35
+ */
36
+ public function process()
37
+ {
38
+ // Get the copernica API
39
+ $api = Mage::getSingleton('marketingsoftware/marketingsoftware')->api();
40
+
41
+ $product = $this->getObject();
42
+
43
+ // Get the customer
44
+ $productData = Mage::getModel('marketingsoftware/copernica_viewedproduct_subprofile')
45
+ ->setViewedProduct($product = $this->getObject())
46
+ ->setDirection('copernica');
47
+
48
+ $tmpStore = Mage::getModel('core/store')->load($product->storeId);
49
+
50
+ $customer = Mage::getModel('customer/customer')->load($productData->customerId());
51
+
52
+ $storeView = Mage::getModel('marketingsoftware/abstraction_storeview')->setOriginal($tmpStore);
53
+
54
+ $copernicaId = Mage::helper('marketingsoftware')->generateCustomerId($customer->getEmail(), (string)$storeView);
55
+
56
+ $profiles = $api->searchProfiles($copernicaId);
57
+
58
+ // Process all the profiles
59
+ foreach ($profiles->items as $profile)
60
+ {
61
+ // Update the profiles given the customer
62
+ $api->updateViewedProductSubProfiles($profile->id, $productData);
63
+ }
64
+
65
+ // this viewed product is processed
66
+ return true;
67
+ }
68
+ }
app/code/community/Copernica/MarketingSoftware/controllers/Adminhtml/Marketingsoftware/LinkController.php CHANGED
@@ -140,6 +140,7 @@ class Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_LinkController ext
140
  $orders_array = array();
141
  $orderproducts_array = array();
142
  $address_array = array();
 
143
 
144
  // we loop throught the POST data and store each data inside the array it belongs to
145
  foreach ($post as $fieldname => $fieldvalue)
@@ -169,6 +170,11 @@ class Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_LinkController ext
169
  $fieldname = str_replace('input_addresses_', '', $fieldname);
170
  $address_array[$fieldname] = $fieldvalue;
171
  }
 
 
 
 
 
172
  }
173
 
174
  // store the database and collection names
@@ -178,11 +184,13 @@ class Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_LinkController ext
178
  ->setOrdersCollectionName($post['orders_input'])
179
  ->setOrderItemsCollectionName($post['orderproducts_input'])
180
  ->setAddressesCollectionName($post['addresses_input'])
 
181
  ->setLinkedCustomerFields($customer_array)
182
  ->setLinkedCartItemFields($cartproducts_array)
183
  ->setLinkedOrderFields($orders_array)
184
  ->setLinkedOrderItemFields($orderproducts_array)
185
- ->setLinkedAddressFields($address_array);
 
186
 
187
  // add a success notice
188
  Mage::getSingleton('adminhtml/session')->addSuccess('Settings were successfully saved.');
140
  $orders_array = array();
141
  $orderproducts_array = array();
142
  $address_array = array();
143
+ $viewedproduct_array = array();
144
 
145
  // we loop throught the POST data and store each data inside the array it belongs to
146
  foreach ($post as $fieldname => $fieldvalue)
170
  $fieldname = str_replace('input_addresses_', '', $fieldname);
171
  $address_array[$fieldname] = $fieldvalue;
172
  }
173
+ elseif (strpos($fieldname, 'input_viewedproduct') !== false)
174
+ {
175
+ $fieldname = str_replace('input_viewedproduct_', '', $fieldname);
176
+ $viewedproduct_array[$fieldname] = $fieldvalue;
177
+ }
178
  }
179
 
180
  // store the database and collection names
184
  ->setOrdersCollectionName($post['orders_input'])
185
  ->setOrderItemsCollectionName($post['orderproducts_input'])
186
  ->setAddressesCollectionName($post['addresses_input'])
187
+ ->setViewedProductCollectionName($post['viewedproduct_input'])
188
  ->setLinkedCustomerFields($customer_array)
189
  ->setLinkedCartItemFields($cartproducts_array)
190
  ->setLinkedOrderFields($orders_array)
191
  ->setLinkedOrderItemFields($orderproducts_array)
192
+ ->setLinkedAddressFields($address_array)
193
+ ->setLinkedViewedProductFields($viewedproduct_array);
194
 
195
  // add a success notice
196
  Mage::getSingleton('adminhtml/session')->addSuccess('Settings were successfully saved.');
app/code/community/Copernica/MarketingSoftware/controllers/ProductController.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
@@ -25,9 +25,9 @@
25
  */
26
 
27
  /**
28
- * Controls the product actions.
29
- *
30
- *
31
  */
32
  class Copernica_MarketingSoftware_ProductController extends Mage_Core_Controller_Front_Action
33
  {
@@ -39,14 +39,20 @@ class Copernica_MarketingSoftware_ProductController extends Mage_Core_Controller
39
  {
40
  //TODO: some security
41
  $request = $this->getRequest();
42
- if($request->getParam('identifier') == "sku"){
43
  $product = $this->_getProductBySku($request->getParam('id'));
44
  } else {
45
  $product = $this->_getProduct($request->getParam('id'));
46
  }
47
-
 
 
 
 
 
 
48
  if ($product != NULL) {
49
- $xml = $this->_buildProductXML(array($product));
50
  $this->_prepareResponse($xml);
51
  }
52
  elseif ($request->getParam('new'))
@@ -69,7 +75,7 @@ class Copernica_MarketingSoftware_ProductController extends Mage_Core_Controller
69
  ->addAttributeToSelect('id');
70
 
71
  // construct the XML
72
- $xml = $this->_buildProductXML($collection);
73
  $this->_prepareResponse($xml);
74
  } else {
75
  $this->norouteAction();
@@ -80,23 +86,24 @@ class Copernica_MarketingSoftware_ProductController extends Mage_Core_Controller
80
  * Constructs an XML object for the given product
81
  *
82
  * @param Mage_Catalog_Model_Product $product
 
83
  * @return SimpleXMLElement
84
  */
85
- protected function _buildProductXML($collection)
86
  {
87
  $xml = new SimpleXMLElement('<products/>');
88
-
89
  // iterate over the collection
90
- foreach ($collection as $product)
91
- {
92
  // Add a product node
93
  $element = $xml->addChild('product');
94
 
95
  // wrap the product
96
- $product = Mage::getModel('marketingsoftware/abstraction_product')->loadProduct($product->getId());
97
-
98
  // Collection of relevant fields
99
- $fields = array(
100
  'id',
101
  'sku',
102
  'name',
@@ -106,22 +113,22 @@ class Copernica_MarketingSoftware_ProductController extends Mage_Core_Controller
106
  'modified',
107
  'created',
108
  'productUrl',
109
- 'imageUrl',
110
- 'weight',
111
- 'isNew',
112
- 'categories',
113
  'attributes'
114
  );
115
-
116
  // Add the internal product fields to the database
117
- foreach ($fields as $name)
118
  {
119
  // Get the value
120
- $value = $product->$name();
121
-
122
  // Get the attributes of the attributes
123
- if ($name == 'attributes') $value = $value->attributes();
124
-
125
  if (is_bool($value))
126
  {
127
  $element->addChild($name, htmlspecialchars(html_entity_decode($value ? 'yes' : 'no')));
@@ -132,35 +139,87 @@ class Copernica_MarketingSoftware_ProductController extends Mage_Core_Controller
132
  if ($name == 'price' || $name == 'specialPrice') {
133
  $value = Mage::helper('core')->currency($value, true, false);
134
  }
135
-
136
  $element->addChild($name, htmlspecialchars(html_entity_decode((string)$value)));
137
  continue;
138
  }
139
-
140
  // We have an array here
141
-
142
  // Add an element, to bundle all the elements of the array
143
  $node = $element->addChild($name);
144
-
145
  // we have an array here
146
- foreach ($value as $key => $attribute)
147
  {
148
  // prepare the key
149
  if (is_numeric($key)) $key = 'items';
150
  else $key = str_replace(' ', '_', $key);
151
-
152
  // special treatment for categories and empty values
153
  if ($name == 'categories') $attribute = implode(' > ', $attribute);
154
  elseif (trim($attribute) === '') continue;
155
-
156
 
157
-
158
  // Add the child
159
  $node->addChild($key, htmlspecialchars(html_entity_decode((string)$attribute)));
160
  }
161
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
162
  }
163
-
164
  return $xml;
165
  }
166
 
@@ -194,13 +253,12 @@ class Copernica_MarketingSoftware_ProductController extends Mage_Core_Controller
194
  */
195
  protected function _getProduct($productId)
196
  {
197
- $product = Mage::getModel('catalog/product')
198
- ->load($productId);
199
-
200
  // only a product with an id exists
201
  return $product->getId() ? $product : null;
202
  }
203
-
204
  /**
205
  * Retrieves a product by SKU
206
  *
@@ -209,12 +267,9 @@ class Copernica_MarketingSoftware_ProductController extends Mage_Core_Controller
209
  */
210
  protected function _getProductBySku($productSku)
211
  {
212
- $product = Mage::getModel('catalog/product')
213
- ->loadByAttribute('sku',$productSku);
214
-
215
  // only a product with an id exists
216
  return $product->getId() ? $product : null;
217
  }
218
-
219
-
220
  }
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
25
  */
26
 
27
  /**
28
+ * Controls the product actions.
29
+ *
30
+ *
31
  */
32
  class Copernica_MarketingSoftware_ProductController extends Mage_Core_Controller_Front_Action
33
  {
39
  {
40
  //TODO: some security
41
  $request = $this->getRequest();
42
+ if ($request->getParam('identifier') == "sku") {
43
  $product = $this->_getProductBySku($request->getParam('id'));
44
  } else {
45
  $product = $this->_getProduct($request->getParam('id'));
46
  }
47
+
48
+ // Use attribute codes or labels?
49
+ $useAttribCode = false;
50
+ if ($request->getParam('attribkey') == 'code') {
51
+ $useAttribCode = true;
52
+ }
53
+
54
  if ($product != NULL) {
55
+ $xml = $this->_buildProductXML(array($product), $useAttribCode);
56
  $this->_prepareResponse($xml);
57
  }
58
  elseif ($request->getParam('new'))
75
  ->addAttributeToSelect('id');
76
 
77
  // construct the XML
78
+ $xml = $this->_buildProductXML($collection, $useAttribCode);
79
  $this->_prepareResponse($xml);
80
  } else {
81
  $this->norouteAction();
86
  * Constructs an XML object for the given product
87
  *
88
  * @param Mage_Catalog_Model_Product $product
89
+ * @param bool $useAttribCode
90
  * @return SimpleXMLElement
91
  */
92
+ protected function _buildProductXML($collection, $useAttribCode = false)
93
  {
94
  $xml = new SimpleXMLElement('<products/>');
95
+
96
  // iterate over the collection
97
+ foreach ($collection as $product)
98
+ {
99
  // Add a product node
100
  $element = $xml->addChild('product');
101
 
102
  // wrap the product
103
+ $_product = Mage::getModel('marketingsoftware/abstraction_product')->loadProduct($product->getId());
104
+
105
  // Collection of relevant fields
106
+ $fields = array(
107
  'id',
108
  'sku',
109
  'name',
113
  'modified',
114
  'created',
115
  'productUrl',
116
+ 'imageUrl',
117
+ 'weight',
118
+ 'isNew',
119
+ 'categories',
120
  'attributes'
121
  );
122
+
123
  // Add the internal product fields to the database
124
+ foreach ($fields as $name)
125
  {
126
  // Get the value
127
+ $value = $_product->$name();
128
+
129
  // Get the attributes of the attributes
130
+ if ($name == 'attributes') $value = $value->attributes($useAttribCode);
131
+
132
  if (is_bool($value))
133
  {
134
  $element->addChild($name, htmlspecialchars(html_entity_decode($value ? 'yes' : 'no')));
139
  if ($name == 'price' || $name == 'specialPrice') {
140
  $value = Mage::helper('core')->currency($value, true, false);
141
  }
142
+
143
  $element->addChild($name, htmlspecialchars(html_entity_decode((string)$value)));
144
  continue;
145
  }
146
+
147
  // We have an array here
148
+
149
  // Add an element, to bundle all the elements of the array
150
  $node = $element->addChild($name);
151
+
152
  // we have an array here
153
+ foreach ($value as $key => $attribute)
154
  {
155
  // prepare the key
156
  if (is_numeric($key)) $key = 'items';
157
  else $key = str_replace(' ', '_', $key);
158
+
159
  // special treatment for categories and empty values
160
  if ($name == 'categories') $attribute = implode(' > ', $attribute);
161
  elseif (trim($attribute) === '') continue;
 
162
 
 
163
  // Add the child
164
  $node->addChild($key, htmlspecialchars(html_entity_decode((string)$attribute)));
165
  }
166
  }
167
+
168
+ $parentIds = Mage::getResourceSingleton('catalog/product_type_configurable')->getParentIdsByChild($product->getId());
169
+
170
+ if (isset($parentIds[0])) {
171
+ $_product = Mage::getModel('marketingsoftware/abstraction_product')->loadProduct($parentIds[0]);
172
+
173
+ // Add a product node
174
+ $element = $xml->addChild('configurable_product');
175
+
176
+ // Add the internal product fields to the database
177
+ foreach ($fields as $name)
178
+ {
179
+ // Get the value
180
+ $value = $_product->$name();
181
+
182
+ // Get the attributes of the attributes
183
+ if ($name == 'attributes') $value = $value->attributes($useAttribCode);
184
+
185
+ if (is_bool($value))
186
+ {
187
+ $element->addChild($name, htmlspecialchars(html_entity_decode($value ? 'yes' : 'no')));
188
+ continue;
189
+ }
190
+ elseif (!is_array($value))
191
+ {
192
+ if ($name == 'price' || $name == 'specialPrice') {
193
+ $value = Mage::helper('core')->currency($value, true, false);
194
+ }
195
+
196
+ $element->addChild($name, htmlspecialchars(html_entity_decode((string)$value)));
197
+ continue;
198
+ }
199
+
200
+ // We have an array here
201
+
202
+ // Add an element, to bundle all the elements of the array
203
+ $node = $element->addChild($name);
204
+
205
+ // we have an array here
206
+ foreach ($value as $key => $attribute)
207
+ {
208
+ // prepare the key
209
+ if (is_numeric($key)) $key = 'items';
210
+ else $key = str_replace(' ', '_', $key);
211
+
212
+ // special treatment for categories and empty values
213
+ if ($name == 'categories') $attribute = implode(' > ', $attribute);
214
+ elseif (trim($attribute) === '') continue;
215
+
216
+ // Add the child
217
+ $node->addChild($key, htmlspecialchars(html_entity_decode((string)$attribute)));
218
+ }
219
+ }
220
+ }
221
  }
222
+
223
  return $xml;
224
  }
225
 
253
  */
254
  protected function _getProduct($productId)
255
  {
256
+ $product = Mage::getModel('catalog/product')->load($productId);
257
+
 
258
  // only a product with an id exists
259
  return $product->getId() ? $product : null;
260
  }
261
+
262
  /**
263
  * Retrieves a product by SKU
264
  *
267
  */
268
  protected function _getProductBySku($productSku)
269
  {
270
+ $product = Mage::getModel('catalog/product')->loadByAttribute('sku',$productSku);
271
+
 
272
  // only a product with an id exists
273
  return $product->getId() ? $product : null;
274
  }
 
 
275
  }
app/code/community/Copernica/MarketingSoftware/etc/config.xml CHANGED
@@ -2,7 +2,7 @@
2
  <config>
3
  <modules>
4
  <Copernica_MarketingSoftware>
5
- <version>2.1.0</version>
6
  </Copernica_MarketingSoftware>
7
  </modules>
8
  <global>
@@ -99,6 +99,14 @@
99
  </marketingsoftware_observer>
100
  </observers>
101
  </customer_save_after>
 
 
 
 
 
 
 
 
102
  </events>
103
  <resources>
104
  <marketingsoftware_setup>
2
  <config>
3
  <modules>
4
  <Copernica_MarketingSoftware>
5
+ <version>2.2.0</version>
6
  </Copernica_MarketingSoftware>
7
  </modules>
8
  <global>
99
  </marketingsoftware_observer>
100
  </observers>
101
  </customer_save_after>
102
+ <catalog_controller_product_view>
103
+ <observers>
104
+ <marketingsoftware_observer>
105
+ <class>marketingsoftware/observer</class>
106
+ <method>productViewed</method>
107
+ </marketingsoftware_observer>
108
+ </observers>
109
+ </catalog_controller_product_view>
110
  </events>
111
  <resources>
112
  <marketingsoftware_setup>
app/code/community/Copernica/MarketingSoftware/sql/marketingsoftware_setup/mysql4-upgrade-2.1.0.1-2.2.0.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to copernica@support.cream.nl so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Copernica Marketing Software to newer
18
+ * versions in the future. If you wish to customize this module for your
19
+ * needs please refer to http://www.copernica.com/ for more information.
20
+ *
21
+ * @category Copernica
22
+ * @package Copernica_MarketingSoftware
23
+ * @copyright Copyright (c) 2011-2012 Copernica & Cream. (http://docs.cream.nl/)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ $installer = $this;
28
+ $installer->startSetup();
29
+
30
+ try {
31
+ $installer->run("
32
+ ALTER TABLE {$this->getTable('marketingsoftware/queue')}
33
+ MODIFY object LONGTEXT;");
34
+ } catch(Exception $e) {}
35
+
36
+ $installer->endSetup();
app/design/adminhtml/default/default/template/marketingsoftware/link.phtml CHANGED
@@ -482,6 +482,96 @@ $_config = Mage::helper('marketingsoftware/config') ?>
482
  </div>
483
  </div>
484
  <!-- end of fifth section. -->
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
485
 
486
  </form>
487
  <!-- end of fields linking form. -->
@@ -624,7 +714,7 @@ var cartItemFields = <?php echo(json_encode($cartItemFields)); ?>;
624
  var orderFields = <?php echo(json_encode($orderFields)); ?>;
625
  var orderItemFields = <?php echo(json_encode($orderItemFields)); ?>;
626
  var addressFields = <?php echo(json_encode($addressFields)); ?>;
627
-
628
 
629
  /**
630
  * The main database object (that also does all initialisation)
482
  </div>
483
  </div>
484
  <!-- end of fifth section. -->
485
+
486
+ <!-- sixt section: viewed product collection. -->
487
+ <div class="entry-edit-head">
488
+ <h4 class="icon-head head-edit-form fieldset-legend" id="edit_viewedproduct_collection_current_label" name="edit_viewedproduct_collection_current_label">Viewed product Collection</h4>
489
+ <a href="#" onclick ="document.getElementById('collection_help').style.display='block'; return false;" id="page-help-link" style="float: right; line-height:18px;">More information</a>
490
+ </div>
491
+ <div class="fieldset">
492
+ <div class="hor-scroll">
493
+ <table cellspacing="0" class="form-list">
494
+ <tbody>
495
+ <tr>
496
+ <td class="value">Collection name</td>
497
+ </tr>
498
+ <tr>
499
+ <td class="value">
500
+ <input type="text" class="input-text validate-code" title="Viewed Product Collection" value="<?php echo(htmlspecialchars($_config->getViewedProductCollectionName())); ?>" name="viewedproduct_input" id="viewedproduct_input">
501
+ </td>
502
+ <td class="value">
503
+ <span style="display:none;" id="viewedproduct_checking">Checking collection....</span>
504
+ <span style="display:none;" id="viewedproduct_impossible">Collection cannot be checked.</span>
505
+ <span style="display:none;" id="viewedproduct_notexists">Collection does not exist. <a href="javascript:database.viewedProductCollection.create()">Create collection.</a></span>
506
+ <span style="display:none;" id="viewedproduct_notvalid">Collection structure not valid.<a href="javascript:database.viewedProductCollection.repair()">Repair collection.</a></span>
507
+ <span style="display:none;" id="viewedproduct_ok">Collection exists.</span>
508
+ </td>
509
+ </tr>
510
+ </tbody>
511
+ </table>
512
+ </div>
513
+ </div>
514
+ <div class="fieldset">
515
+ <div class="hor-scroll">
516
+ <table cellspacing="0" class="form-list">
517
+ <tbody>
518
+ <tr>
519
+ <td class="value">Magento field</td>
520
+ <td class="value">Copernica link</td>
521
+ <td class="value">Copernica field</td>
522
+ <td class="value">Status</td>
523
+ </tr>
524
+ <?php
525
+ // get the linked Customer fields
526
+ $linkedFields = $_config->getLinkedViewedProductFields();
527
+ $viewedProductFields = array();
528
+
529
+ foreach ($_helper->supportedViewedProductFields() as $magentoField => $label)
530
+ {
531
+ // Get the field which is used in Copernica
532
+ $copernicaField = isset($linkedFields[$magentoField]) ? $linkedFields[$magentoField] : '';
533
+
534
+ // append a prefix to the fieldname
535
+ $magentoField = 'viewedproduct_'.$magentoField;
536
+
537
+ // append the data to the array
538
+ $viewedProductFields[$magentoField] = $copernicaField;
539
+
540
+ // Name for the dropdown field, and name for the textfield
541
+ $dropdown_name = "select_$magentoField";
542
+ $textfield_name = "input_$magentoField";
543
+ ?>
544
+ <tr>
545
+ <td class="value">
546
+ <input type="text" class="input-text disabled" value="<?php echo(htmlspecialchars($label)); ?>" name="<?php echo(htmlspecialchars($label)); ?>" disabled="disabled" />
547
+ </td>
548
+ <td class="value">
549
+ <select class="select" id="<?php echo htmlspecialchars($dropdown_name); ?>" name="<?php echo htmlspecialchars($dropdown_name); ?>">
550
+ <option value="0">Don't link</option>
551
+ <option value="1" <?php if ($copernicaField != '') echo "selected='selected'"; ?>>Create link</option>
552
+ <option value="2">Use default name</option>
553
+ </select>
554
+ </td>
555
+ <td class="value">
556
+ <input type="text" class="input-text validate-code" value="<?php echo htmlspecialchars($copernicaField); ?>" name="<?php echo htmlspecialchars($textfield_name); ?>" id="<?php echo htmlspecialchars($textfield_name); ?>" <?php if ($copernicaField == '') echo "style='display: none;'"; ?>>
557
+ </td>
558
+ <td class="value">
559
+ <span style="display:none;" id="checking_<?php echo $magentoField; ?>">Checking field....</span>
560
+ <span style="display:none;" id="impossible_<?php echo $magentoField; ?>">Field cannot be checked.</span>
561
+ <span style="display:none;" id="notexists_<?php echo $magentoField; ?>">Field does not exist. <a href="javascript:database.viewedProductCollection.field('<?php echo $magentoField; ?>').create()">Create field.</a></span>
562
+ <span style="display:none;" id="notlinked_<?php echo $magentoField; ?>">Field is not linked.</a></span>
563
+ <span style="display:none;" id="notvalid_<?php echo $magentoField; ?>">Field is not valid. <a href="javascript:database.viewedProductCollection.field('<?php echo $magentoField; ?>').repair()">Repair field.</a></span>
564
+ <span style="display:none;" id="ok_<?php echo $magentoField; ?>">Field exists.</span>
565
+ </td>
566
+ </tr>
567
+ <?php
568
+ }
569
+ ?>
570
+ </tbody>
571
+ </table>
572
+ </div>
573
+ </div>
574
+ <!-- end of sixt section. -->
575
 
576
  </form>
577
  <!-- end of fields linking form. -->
714
  var orderFields = <?php echo(json_encode($orderFields)); ?>;
715
  var orderItemFields = <?php echo(json_encode($orderItemFields)); ?>;
716
  var addressFields = <?php echo(json_encode($addressFields)); ?>;
717
+ var viewedProductFields = <?php echo(json_encode($viewedProductFields)); ?>;
718
 
719
  /**
720
  * The main database object (that also does all initialisation)
js/copernica/marketingsoftware/collection.js CHANGED
@@ -25,6 +25,7 @@ function CopernicaCollection(database, type)
25
  if (type == 'cartproducts') var theFields = cartItemFields;
26
  else if (type == 'orders') var theFields = orderFields;
27
  else if (type == 'orderproducts') var theFields = orderItemFields;
 
28
  else var theFields = addressFields;
29
 
30
  // we always want to have an object, PHP can do this
25
  if (type == 'cartproducts') var theFields = cartItemFields;
26
  else if (type == 'orders') var theFields = orderFields;
27
  else if (type == 'orderproducts') var theFields = orderItemFields;
28
+ else if (type == 'viewedproduct') var theFields = viewedProductFields;
29
  else var theFields = addressFields;
30
 
31
  // we always want to have an object, PHP can do this
js/copernica/marketingsoftware/database.js CHANGED
@@ -20,6 +20,7 @@ function CopernicaDatabase()
20
  this.ordersCollection = new CopernicaCollection(this, 'orders');
21
  this.orderItemsCollection = new CopernicaCollection(this, 'orderproducts');
22
  this.addressCollection = new CopernicaCollection(this, 'addresses');
 
23
 
24
  // construct an array of all fields in this collection
25
  this.fields = [];
@@ -88,7 +89,7 @@ CopernicaDatabase.prototype.modified = function()
88
  }
89
 
90
  // check if the collections were modified
91
- return this.cartItemsCollection.modified() || this.orderItemsCollection.modified() || this.ordersCollection.modified() || this.addressCollection.modified();
92
  }
93
 
94
  /**
@@ -256,6 +257,11 @@ CopernicaDatabase.prototype.checkFields = function()
256
  // check the orders collection
257
  self.addressCollection.check(function() { checkField(counter + 1); })
258
  }
 
 
 
 
 
259
  else if (counter < self.fields.length)
260
  {
261
  // check if the field exist, with a callback for checking the next field
@@ -327,6 +333,7 @@ CopernicaDatabase.prototype.setStatus = function(status)
327
  this.cartItemsCollection.setStatus('impossible');
328
  this.orderItemsCollection.setStatus('impossible');
329
  this.addressCollection.setStatus('impossible');
 
330
  }
331
  }
332
 
20
  this.ordersCollection = new CopernicaCollection(this, 'orders');
21
  this.orderItemsCollection = new CopernicaCollection(this, 'orderproducts');
22
  this.addressCollection = new CopernicaCollection(this, 'addresses');
23
+ this.viewedProductCollection = new CopernicaCollection(this, 'viewedproduct');
24
 
25
  // construct an array of all fields in this collection
26
  this.fields = [];
89
  }
90
 
91
  // check if the collections were modified
92
+ return this.cartItemsCollection.modified() || this.orderItemsCollection.modified() || this.ordersCollection.modified() || this.addressCollection.modified() || this.viewedProductCollection.modified();
93
  }
94
 
95
  /**
257
  // check the orders collection
258
  self.addressCollection.check(function() { checkField(counter + 1); })
259
  }
260
+ else if (counter == self.fields.length + 4)
261
+ {
262
+ // check the orders collection
263
+ self.viewedProductCollection.check(function() { checkField(counter + 1); })
264
+ }
265
  else if (counter < self.fields.length)
266
  {
267
  // check if the field exist, with a callback for checking the next field
333
  this.cartItemsCollection.setStatus('impossible');
334
  this.orderItemsCollection.setStatus('impossible');
335
  this.addressCollection.setStatus('impossible');
336
+ this.viewedProductCollection.setStatus('impossible');
337
  }
338
  }
339
 
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Copernica_MarketingSoftware</name>
4
- <version>2.1.0.1</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>
@@ -10,12 +10,18 @@
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.&#xD;
11
  &#xD;
12
  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>
13
- <notes>Improvements:&#xD;
14
- - Fixed a bug in version 2.1.0 throwing an error when syncing a checkout of a guest.</notes>
 
 
 
 
 
 
15
  <authors><author><name>Cream</name><user>creaminternet</user><email>info@cream.nl</email></author></authors>
16
- <date>2013-02-20</date>
17
- <time>19:27:26</time>
18
- <contents><target name="magecommunity"><dir name="Copernica"><dir name="MarketingSoftware"><dir name="Block"><dir name="Adminhtml"><dir name="Marketingsoftware"><file name="Export.php" hash="bdf5b3c9f54b61c297abacebb21bd9e4"/><file name="Link.php" hash="3d3116a9cc0e30bd7988bc01cd731dda"/><file name="Settings.php" hash="89e6626dce0b1cc218967a75a23b50c8"/></dir></dir></dir><dir name="Helper"><file name="Api.php" hash="c814c64cd137d64e6b7b25b403b2871e"/><file name="Config.php" hash="fa1284a6b72c63b295a1fb44e735cfea"/><file name="Data.php" hash="727d8ea36a0946f0152e39536c6ed424"/></dir><dir name="Model"><dir name="Abstraction"><file name="Address.php" hash="0e6d94c15174bf177082f832bdd51f63"/><file name="Attributes.php" hash="196c089955b59b3eac85f127911d117a"/><file name="Customer.php" hash="d182b846cfc5975bf34e910c76af5fc6"/><file name="Name.php" hash="b291754d976ff55642bace1bf79780d8"/><dir name="Order"><dir name="Item"><file name="Options.php" hash="2cbba6a9575ba4cbcaef757e17c8040f"/></dir><file name="Item.php" hash="e6913df33122a058393836c8f89ded65"/></dir><file name="Order.php" hash="7f09861d1448fa7b43e0a207ed0c378f"/><file name="Price.php" hash="fcf88d59cb807d54a867894c63fb7464"/><file name="Product.php" hash="d8915988159bc62b187fe9cfbb276466"/><dir name="Quote"><dir name="Item"><file name="Options.php" hash="8e14fa0d99a871bac8f7486834c8f619"/></dir><file name="Item.php" hash="fde269ab77497786c6d9dcacb8a1df22"/></dir><file name="Quote.php" hash="cdc53d2a92394d80cc0f75c9ee15f687"/><file name="Storeview.php" hash="c2b18ed89b7d703435e49cbe78e9f7e1"/><file name="Subscription.php" hash="b6cd6526f2073019ab34f8cc4ec14abc"/><file name="readme.txt" hash="d450b7fa3d88b6a5c2b5efa526d17077"/></dir><file name="AsyncPomSoapClient.php" hash="6da9a420ed1c142e461f54a7ac0d375b"/><file name="Config.php" hash="88d2334013bb1c0f479fd615dbcb27e0"/><dir name="Copernica"><file name="Abstract.php" hash="59aaf8f767295d5c7e6424d6c9e19723"/><dir name="Address"><file name="Subprofile.php" hash="23367765c877ea7968c6b5d58cc21ea9"/></dir><dir name="Cartitem"><file name="Subprofile.php" hash="f1cbc895e80218538d9dd9aa3a610e3f"/></dir><dir name="Order"><file name="Subprofile.php" hash="ab7fff6418b7b0c75db39c2a88265c5f"/></dir><dir name="Orderitem"><file name="Subprofile.php" hash="6379471f6a420a0d1ea06724c4d860f9"/></dir><file name="Profile.php" hash="2c20adfb68dbcec5601ac20b6635230c"/><file name="Profilecustomer.php" hash="bc693d552ebfd7f29c2a020e16cc03c6"/><file name="Profileorder.php" hash="7b6dc38fa41f7e003784acc73f108d12"/><file name="Profilequote.php" hash="68b3c54c13323fb8f4b4275a72e2ef01"/><file name="Profilesubscription.php" hash="6fc13dedf8ca954cc6843f5b050be9aa"/></dir><file name="Error.php" hash="f7b5a53518d72b081cb0ec50cde1056d"/><file name="Marketingsoftware.php" hash="b32e95ab2aaa34325d0f425100840830"/><dir name="Mysql4"><dir name="Config"><file name="Collection.php" hash="08cf25c2e554c123e97c1ad2f4622eb0"/></dir><file name="Config.php" hash="45beeedbd3f663c2a17157e1a096b131"/><dir name="Queue"><file name="Collection.php" hash="27f34b6af428741aca1040f96cdf7756"/></dir><file name="Queue.php" hash="6bc3ae61a6ba74a5ec926891bbc66099"/></dir><file name="Observer.php" hash="29c76f0eb8ce43eba393004e282f3eef"/><file name="PomSoapClient.php" hash="77c6e2490b381f207ad57c1d27de844a"/><file name="Queue.php" hash="6754f2df037380e6cded42e1642bb8de"/><dir name="QueueEvent"><file name="Abstract.php" hash="df759a3fdd38a31d7ac77c750b40e73f"/><file name="CustomerAdd.php" hash="fdebc7f4f368682af1e08b10421efbe7"/><file name="CustomerFull.php" hash="0f76283508b6f112fc1996d196525a33"/><file name="CustomerModify.php" hash="cc7764a5eb8d6674116cb466792aba5d"/><file name="CustomerRemove.php" hash="8127f5a21912c6b694d9ee1c679fe9f2"/><file name="Factory.php" hash="f8b00661dabb545f93e9e9d7823dbdb3"/><file name="OrderAdd.php" hash="504614d9808ea4473071324ae5221a72"/><file name="OrderModify.php" hash="f5bc8b25cf4bbc9d21d202657a119c01"/><file name="QuoteItem.php" hash="b2dec310c8964a7c1aecc5e81f01d0bd"/><file name="QuoteItemAdd.php" hash="ee09dfb74b1310a9df4f5e2c6d5b0104"/><file name="QuoteItemModify.php" hash="0df6ad182697b481196f9f0c46771f31"/><file name="QuoteItemRemove.php" hash="13096313ccbeff6d8ca1c098b8355cd4"/><file name="QuoteModify.php" hash="8e443feba3fa0693ea898fae36206920"/><file name="StartSync.php" hash="2692107edf6e9772bea60e36c50da7ac"/><file name="SubscriptionAdd.php" hash="e84030df0a7ba39d7ce967f96d0086b6"/><file name="SubscriptionModify.php" hash="acb0a3bcab9529386b2c45b2cd487ac4"/><file name="SubscriptionRemove.php" hash="7286d621debd6c1217e823e816fc0680"/></dir></dir><dir name="controllers"><dir name="Adminhtml"><dir name="Marketingsoftware"><file name="ExportController.php" hash="292acb089445cff2c00b627942589059"/><file name="LinkController.php" hash="63423b5d92722367d846e3e6e3a92d71"/><file name="SettingsController.php" hash="c84d4f89b7557212ad9e283540db5157"/></dir></dir><file name="ProductController.php" hash="87e1046e82fae37daf7abecff6ec60c8"/><file name="UnsubscribeController.php" hash="c92556ae8dc002c132adff23e728c11a"/></dir><dir name="etc"><file name="adminhtml.xml" hash="d3d434a47e118dfdd69cd32b01b83f9f"/><file name="config.xml" hash="979683f4f5513dd0eb6aaf9511abfb1d"/></dir><dir name="sql"><dir name="marketingsoftware_setup"><file name="mysql4-install-1.2.0.php" hash="edaa8a4c29da5a0bb4f5c06e92c4a6e5"/><file name="mysql4-upgrade-1.1.5-1.1.6.php" hash="4902356c13309b6415e1a61c3fcc805c"/><file name="mysql4-upgrade-1.1.6-1.1.7.php" hash="1bfa357933494cbded4c32f4d1d0a45c"/><file name="mysql4-upgrade-1.1.7-1.1.8.php" hash="860e3ce11771bd8e6f7c755f2afa8805"/><file name="mysql4-upgrade-1.1.8-1.2.0.php" hash="42db3d71333deb7430cdbbafb56e80c1"/><file name="mysql4-upgrade-2.0.1-2.0.2.php" hash="5374760e8bee6edb033475cd0cf8fd0a"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Copernica_MarketingSoftware.xml" hash="04c9e69139dbff42d829bad22fa2ab85"/></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="marketingsoftware"><file name="export.phtml" hash="4a3783aac318f5683060bc9119893989"/><file name="link.phtml" hash="390b6e5a5e0b2ac35b886eaa9f4e437e"/><file name="settings.phtml" hash="7497c7d74e93797f455d5b47a846bf82"/></dir></dir></dir></dir></dir></target><target name="mageweb"><dir name="js"><dir name="copernica"><dir name="marketingsoftware"><file name="collection.js" hash="260f06a4e891df402e145bec4d15bc51"/><file name="database.js" hash="4e51925d1fedd36a203c625050fb9b07"/><file name="field.js" hash="c4f98de6a9c210c626db36730485b853"/></dir></dir></dir></target></contents>
19
  <compatible/>
20
- <dependencies><required><php><min>5.2.0</min><max>5.3.21</max></php><extension><name>soap</name><min></min><max></max></extension></required></dependencies>
21
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Copernica_MarketingSoftware</name>
4
+ <version>2.2.0</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>
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.&#xD;
11
  &#xD;
12
  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>
13
+ <notes>New features:&#xD;
14
+ - Now works with PHP 5.4&#xD;
15
+ - Added tier prices to the product XML which can be fetched&#xD;
16
+ &#xD;
17
+ Improvements:&#xD;
18
+ - Maximum number of record for one sync increased to 300.&#xD;
19
+ - Changed database field to longtext so really big serialized objects will be saved in full. &#xD;
20
+ </notes>
21
  <authors><author><name>Cream</name><user>creaminternet</user><email>info@cream.nl</email></author></authors>
22
+ <date>2013-12-26</date>
23
+ <time>13:50:06</time>
24
+ <contents><target name="magecommunity"><dir name="Copernica"><dir name="MarketingSoftware"><dir name="Block"><dir name="Adminhtml"><dir name="Marketingsoftware"><file name="Export.php" hash="bdf5b3c9f54b61c297abacebb21bd9e4"/><file name="Link.php" hash="3d3116a9cc0e30bd7988bc01cd731dda"/><file name="Settings.php" hash="89e6626dce0b1cc218967a75a23b50c8"/></dir></dir></dir><dir name="Helper"><file name="Api.php" hash="009af7761b00e609e9a266ba66f3bcdd"/><file name="Config.php" hash="7d390456a3ff10839ebfc7b0c9c6ffa8"/><file name="Data.php" hash="341236cc0a0d3f1a409f664f609422c7"/></dir><dir name="Model"><dir name="Abstraction"><file name="Address.php" hash="cbc3dbf87075bb659ab0eb128ae838db"/><file name="Attributes.php" hash="647b9239543b1de1d0b2f30fc02c0696"/><file name="Customer.php" hash="4cfa8960247d954af0fc50af3f20694b"/><file name="Name.php" hash="02c8872e1a4c48994a06ec86375a3294"/><dir name="Order"><dir name="Item"><file name="Options.php" hash="615c23e4ae18f38c3799fb3160fe02f4"/></dir><file name="Item.php" hash="9bd019ea34da6d3ffb1bc9c40fc42180"/></dir><file name="Order.php" hash="2f5932dec21f2cc9ee2abc9584084afa"/><file name="Price.php" hash="aefc7c8cd6507053ad8d6e47f8244210"/><file name="Product.php" hash="c549ba0f57b9dec41673f55841bcb322"/><dir name="Quote"><dir name="Item"><file name="Options.php" hash="2ef9e9263bb374c5095d87c6d177195d"/></dir><file name="Item.php" hash="81922644dbd687150f1913ef75ddf378"/></dir><file name="Quote.php" hash="5abef96dd68fe3a430c1409504460205"/><file name="Storeview.php" hash="845b33efa4cd68cb7f33885a5fd065b6"/><file name="Subscription.php" hash="862a7947a68ac732c05e8cb4b1f25649"/><file name="Viewedproduct.php" hash="c921f9ce8725e08f58f836d23b082f8e"/></dir><file name="AsyncPomSoapClient.php" hash="6da9a420ed1c142e461f54a7ac0d375b"/><file name="Config.php" hash="88d2334013bb1c0f479fd615dbcb27e0"/><dir name="Copernica"><file name="Abstract.php" hash="59aaf8f767295d5c7e6424d6c9e19723"/><dir name="Address"><file name="Subprofile.php" hash="23367765c877ea7968c6b5d58cc21ea9"/></dir><dir name="Cartitem"><file name="Subprofile.php" hash="f1cbc895e80218538d9dd9aa3a610e3f"/></dir><dir name="Order"><file name="Subprofile.php" hash="ab7fff6418b7b0c75db39c2a88265c5f"/></dir><dir name="Orderitem"><file name="Subprofile.php" hash="6379471f6a420a0d1ea06724c4d860f9"/></dir><file name="Profile.php" hash="2c20adfb68dbcec5601ac20b6635230c"/><file name="Profilecustomer.php" hash="bc693d552ebfd7f29c2a020e16cc03c6"/><file name="Profileorder.php" hash="7b6dc38fa41f7e003784acc73f108d12"/><file name="Profilequote.php" hash="68b3c54c13323fb8f4b4275a72e2ef01"/><file name="Profilesubscription.php" hash="6fc13dedf8ca954cc6843f5b050be9aa"/><dir name="Viewedproduct"><file name="Subprofile.php" hash="d108a23385da04450273bd82206d7593"/></dir></dir><file name="Error.php" hash="f7b5a53518d72b081cb0ec50cde1056d"/><file name="Marketingsoftware.php" hash="b32e95ab2aaa34325d0f425100840830"/><dir name="Mysql4"><dir name="Config"><file name="Collection.php" hash="08cf25c2e554c123e97c1ad2f4622eb0"/></dir><file name="Config.php" hash="45beeedbd3f663c2a17157e1a096b131"/><dir name="Queue"><file name="Collection.php" hash="27f34b6af428741aca1040f96cdf7756"/></dir><file name="Queue.php" hash="6bc3ae61a6ba74a5ec926891bbc66099"/></dir><file name="Observer.php" hash="c36a475f7ddcd49c2b96cbbb87ef0be7"/><file name="PomSoapClient.php" hash="77c6e2490b381f207ad57c1d27de844a"/><file name="Queue.php" hash="e1aa1df1fd1b54503edfa9af286e01d3"/><dir name="QueueEvent"><file name="Abstract.php" hash="df759a3fdd38a31d7ac77c750b40e73f"/><file name="CustomerAdd.php" hash="fdebc7f4f368682af1e08b10421efbe7"/><file name="CustomerFull.php" hash="0f76283508b6f112fc1996d196525a33"/><file name="CustomerModify.php" hash="cc7764a5eb8d6674116cb466792aba5d"/><file name="CustomerRemove.php" hash="8127f5a21912c6b694d9ee1c679fe9f2"/><file name="Factory.php" hash="d770a367114e1b4c510f2181bae11410"/><file name="OrderAdd.php" hash="504614d9808ea4473071324ae5221a72"/><file name="OrderModify.php" hash="f5bc8b25cf4bbc9d21d202657a119c01"/><file name="QuoteItem.php" hash="b2dec310c8964a7c1aecc5e81f01d0bd"/><file name="QuoteItemAdd.php" hash="ee09dfb74b1310a9df4f5e2c6d5b0104"/><file name="QuoteItemModify.php" hash="0df6ad182697b481196f9f0c46771f31"/><file name="QuoteItemRemove.php" hash="13096313ccbeff6d8ca1c098b8355cd4"/><file name="QuoteModify.php" hash="8e443feba3fa0693ea898fae36206920"/><file name="StartSync.php" hash="95ef6fe6e7d50a1ae6ae5f96269df482"/><file name="SubscriptionAdd.php" hash="e84030df0a7ba39d7ce967f96d0086b6"/><file name="SubscriptionModify.php" hash="acb0a3bcab9529386b2c45b2cd487ac4"/><file name="SubscriptionRemove.php" hash="7286d621debd6c1217e823e816fc0680"/><file name="ViewedProductAdd.php" hash="afea909f1ca992063165d7f5fbca8fb6"/></dir></dir><dir name="controllers"><dir name="Adminhtml"><dir name="Marketingsoftware"><file name="ExportController.php" hash="292acb089445cff2c00b627942589059"/><file name="LinkController.php" hash="91ffbaf6aeb99f6b93f12bb4a334eca9"/><file name="SettingsController.php" hash="c84d4f89b7557212ad9e283540db5157"/></dir></dir><file name="ProductController.php" hash="ec329601e72022f07d10f64a9c3ee4dc"/><file name="UnsubscribeController.php" hash="c92556ae8dc002c132adff23e728c11a"/></dir><dir name="etc"><file name="adminhtml.xml" hash="d3d434a47e118dfdd69cd32b01b83f9f"/><file name="config.xml" hash="0ec9fe51b6205defaf32bebc41770adf"/></dir><dir name="sql"><dir name="marketingsoftware_setup"><file name="mysql4-install-1.2.0.php" hash="edaa8a4c29da5a0bb4f5c06e92c4a6e5"/><file name="mysql4-upgrade-1.1.5-1.1.6.php" hash="4902356c13309b6415e1a61c3fcc805c"/><file name="mysql4-upgrade-1.1.6-1.1.7.php" hash="1bfa357933494cbded4c32f4d1d0a45c"/><file name="mysql4-upgrade-1.1.7-1.1.8.php" hash="860e3ce11771bd8e6f7c755f2afa8805"/><file name="mysql4-upgrade-1.1.8-1.2.0.php" hash="42db3d71333deb7430cdbbafb56e80c1"/><file name="mysql4-upgrade-2.0.1-2.0.2.php" hash="5374760e8bee6edb033475cd0cf8fd0a"/><file name="mysql4-upgrade-2.1.0.1-2.2.0.php" hash="c2f18c3afdb8c5b705057bd29a046f78"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Copernica_MarketingSoftware.xml" hash="04c9e69139dbff42d829bad22fa2ab85"/></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="marketingsoftware"><file name="export.phtml" hash="4a3783aac318f5683060bc9119893989"/><file name="link.phtml" hash="58e19241b9fd92d7a375bc88e4836d7f"/><file name="settings.phtml" hash="7497c7d74e93797f455d5b47a846bf82"/></dir></dir></dir></dir></dir></target><target name="mageweb"><dir name="js"><dir name="copernica"><dir name="marketingsoftware"><file name="collection.js" hash="363d5efc8d38076015996e4a2ad8ca4a"/><file name="database.js" hash="954143b4b5f0ca16fc3fae22a05b5fe3"/><file name="field.js" hash="c4f98de6a9c210c626db36730485b853"/></dir></dir></dir></target></contents>
25
  <compatible/>
26
+ <dependencies><required><php><min>5.2.0</min><max>5.4.23</max></php><extension><name>soap</name><min></min><max></max></extension></required></dependencies>
27
  </package>