Version Notes
[COPE-199] - Bug in Magento Extensie
[COPE-202] - Validation not working correctly on some fields
[COPE-203] - Ingelogde klanten kunnen geen producten verwijderen
[COPE-207] - Foutmelding bij installeren module nieuwe installatie
Download this release
Release Info
| Developer | Cream |
| Extension | Copernica_MarketingSoftware |
| Version | 3.1.1 |
| Comparing to | |
| See all releases | |
Code changes from version 3.1.0 to 3.1.1
- app/code/community/Copernica/MarketingSoftware/Block/Adminhtml/Marketingsoftware/Accesstoken.php +59 -59
- app/code/community/Copernica/MarketingSoftware/Block/Adminhtml/Marketingsoftware/Link.php +80 -80
- app/code/community/Copernica/MarketingSoftware/Block/Adminhtml/Marketingsoftware/Sync.php +117 -117
- app/code/community/Copernica/MarketingSoftware/Controller/Action.php +180 -180
- app/code/community/Copernica/MarketingSoftware/Exception.php +79 -79
- app/code/community/Copernica/MarketingSoftware/Helper/Api/Abstract.php +427 -427
- app/code/community/Copernica/MarketingSoftware/Helper/Api/Builder.php +243 -243
- app/code/community/Copernica/MarketingSoftware/Helper/Api/Validator.php +382 -382
- app/code/community/Copernica/MarketingSoftware/Helper/Config.php +1223 -1223
- app/code/community/Copernica/MarketingSoftware/Helper/Data.php +532 -532
- app/code/community/Copernica/MarketingSoftware/Helper/Profile.php +216 -216
- app/code/community/Copernica/MarketingSoftware/Helper/Rest/Request.php +361 -361
- app/code/community/Copernica/MarketingSoftware/Model/Abandoned/Cart.php +64 -64
- app/code/community/Copernica/MarketingSoftware/Model/Abandoned/Carts/Processor.php +129 -129
- app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Address.php +319 -319
- app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Attributes.php +136 -136
- app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Customer.php +309 -309
- app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Name.php +131 -131
- app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Order.php +361 -361
- app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Order/Item.php +191 -191
- app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Order/Item/Options.php +157 -157
- app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Price.php +248 -248
- app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Product.php +332 -332
- app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Product/Viewed.php +417 -417
- app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Quote.php +368 -368
- app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Quote/Item.php +211 -211
- app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Quote/Item/Options.php +163 -163
- app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Storeview.php +185 -185
- app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Subscription.php +179 -179
- app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Wishlist.php +368 -368
- app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Wishlist/Item.php +208 -208
- app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Wishlist/Item/Options.php +163 -163
- app/code/community/Copernica/MarketingSoftware/Model/Config.php +63 -63
- app/code/community/Copernica/MarketingSoftware/Model/Copernica/Entity.php +81 -81
- app/code/community/Copernica/MarketingSoftware/Model/Copernica/Entity/Address.php +247 -247
- app/code/community/Copernica/MarketingSoftware/Model/Copernica/Entity/Customer.php +384 -384
- app/code/community/Copernica/MarketingSoftware/Model/Copernica/Entity/Order.php +363 -363
- app/code/community/Copernica/MarketingSoftware/Model/Copernica/Entity/Order/Item.php +194 -194
- app/code/community/Copernica/MarketingSoftware/Model/Copernica/Entity/Product.php +435 -435
- app/code/community/Copernica/MarketingSoftware/Model/Copernica/Entity/Quote.php +88 -88
- app/code/community/Copernica/MarketingSoftware/Model/Copernica/Entity/Quote/Item.php +92 -92
- app/code/community/Copernica/MarketingSoftware/Model/Copernica/Entity/Subscription.php +151 -151
- app/code/community/Copernica/MarketingSoftware/Model/Copernica/Entity/Wishlist.php +98 -98
- app/code/community/Copernica/MarketingSoftware/Model/Copernica/Entity/Wishlist/Item.php +154 -154
- app/code/community/Copernica/MarketingSoftware/Model/Copernica/Orderitem/Subprofile.php +131 -131
- app/code/community/Copernica/MarketingSoftware/Model/Copernica/Product/Viewed/Subprofile.php +117 -117
- app/code/community/Copernica/MarketingSoftware/Model/Copernica/Profile/Customer.php +119 -119
- app/code/community/Copernica/MarketingSoftware/Model/Copernica/Quote/Item/Subprofile.php +150 -150
- app/code/community/Copernica/MarketingSoftware/Model/Copernica/Wishlist/Item/Subprofile.php +131 -131
- app/code/community/Copernica/MarketingSoftware/Model/Error/Queue.php +105 -105
- app/code/community/Copernica/MarketingSoftware/Model/Mysql4/Abandoned/Cart.php +38 -38
- app/code/community/Copernica/MarketingSoftware/Model/Mysql4/Abandoned/Cart/Collection.php +11 -11
- app/code/community/Copernica/MarketingSoftware/Model/Mysql4/Config.php +32 -32
- app/code/community/Copernica/MarketingSoftware/Model/Mysql4/Config/Collection.php +32 -32
- app/code/community/Copernica/MarketingSoftware/Model/Mysql4/Error/Queue.php +35 -35
- app/code/community/Copernica/MarketingSoftware/Model/Mysql4/Error/Queue/Collection.php +35 -35
- app/code/community/Copernica/MarketingSoftware/Model/Mysql4/Profile/Cache.php +38 -38
- app/code/community/Copernica/MarketingSoftware/Model/Mysql4/Profile/Cache/Collection.php +32 -32
- app/code/community/Copernica/MarketingSoftware/Model/Mysql4/Queue/Item/Collection.php +66 -66
- app/code/community/Copernica/MarketingSoftware/Model/Mysql4/Sync/Profile.php +35 -35
- app/code/community/Copernica/MarketingSoftware/Model/Mysql4/Sync/Profile/Collection.php +32 -32
- app/code/community/Copernica/MarketingSoftware/Model/Profile/Cache.php +82 -82
- app/code/community/Copernica/MarketingSoftware/Model/Queue/Event/Abstract.php +108 -108
- app/code/community/Copernica/MarketingSoftware/Model/Queue/Event/Checkout.php +113 -113
- app/code/community/Copernica/MarketingSoftware/Model/Queue/Event/Customer.php +157 -157
- app/code/community/Copernica/MarketingSoftware/Model/Queue/Event/Factory.php +95 -95
- app/code/community/Copernica/MarketingSoftware/Model/Queue/Event/Item.php +176 -176
- app/code/community/Copernica/MarketingSoftware/Model/Queue/Event/Order.php +158 -158
- app/code/community/Copernica/MarketingSoftware/Model/Queue/Event/Quote.php +98 -98
- app/code/community/Copernica/MarketingSoftware/Model/Queue/Event/Startsync.php +242 -242
- app/code/community/Copernica/MarketingSoftware/Model/Queue/Event/Subscription.php +96 -96
- app/code/community/Copernica/MarketingSoftware/Model/Queue/Event/View.php +56 -56
- app/code/community/Copernica/MarketingSoftware/Model/Queue/Item.php +249 -249
- app/code/community/Copernica/MarketingSoftware/Model/Queue/Processor.php +242 -242
- app/code/community/Copernica/MarketingSoftware/Model/Rest.php +125 -125
- app/code/community/Copernica/MarketingSoftware/Model/Rest/Address.php +112 -112
- app/code/community/Copernica/MarketingSoftware/Model/Rest/Customer.php +84 -84
- app/code/community/Copernica/MarketingSoftware/Model/Rest/Order.php +157 -157
- app/code/community/Copernica/MarketingSoftware/Model/Rest/Order/Item.php +126 -126
- app/code/community/Copernica/MarketingSoftware/Model/Rest/Product.php +94 -94
- app/code/community/Copernica/MarketingSoftware/Model/Rest/Quote.php +79 -79
- app/code/community/Copernica/MarketingSoftware/Model/Rest/Quote/Item.php +79 -79
- app/code/community/Copernica/MarketingSoftware/Model/Rest/Subscription.php +96 -96
- app/code/community/Copernica/MarketingSoftware/Model/Rest/Wishlist.php +69 -69
- app/code/community/Copernica/MarketingSoftware/Model/Rest/Wishlist/Item.php +79 -79
- app/code/community/Copernica/MarketingSoftware/Model/Sync/Profile.php +197 -197
- app/code/community/Copernica/MarketingSoftware/Model/Sync/Status.php +148 -148
- app/code/community/Copernica/MarketingSoftware/controllers/Adminhtml/Marketingsoftware/AccessTokenController.php +67 -67
- app/code/community/Copernica/MarketingSoftware/controllers/Adminhtml/Marketingsoftware/AjaxcollectionController.php +455 -453
- app/code/community/Copernica/MarketingSoftware/controllers/Adminhtml/Marketingsoftware/ExportController.php +138 -138
- app/code/community/Copernica/MarketingSoftware/controllers/Adminhtml/Marketingsoftware/LinkController.php +239 -239
- app/code/community/Copernica/MarketingSoftware/controllers/Adminhtml/Marketingsoftware/SettingsController.php +202 -202
- app/code/community/Copernica/MarketingSoftware/controllers/Adminhtml/Marketingsoftware/SyncController.php +180 -180
- app/code/community/Copernica/MarketingSoftware/controllers/ProductController.php +263 -307
app/code/community/Copernica/MarketingSoftware/Block/Adminhtml/Marketingsoftware/Accesstoken.php
CHANGED
|
@@ -1,60 +1,60 @@
|
|
| 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 |
-
* Accesstoken Block
|
| 29 |
-
*/
|
| 30 |
-
class Copernica_MarketingSoftware_Block_Adminhtml_Marketingsoftware_Accesstoken extends Mage_Core_Block_Template
|
| 31 |
-
{
|
| 32 |
-
/**
|
| 33 |
-
* Constructor
|
| 34 |
-
*/
|
| 35 |
-
public function __construct()
|
| 36 |
-
{
|
| 37 |
-
parent::__construct();
|
| 38 |
-
$this->setTemplate('marketingsoftware/accessToken.phtml');
|
| 39 |
-
}
|
| 40 |
-
|
| 41 |
-
/**
|
| 42 |
-
* Returns the post URL.
|
| 43 |
-
*
|
| 44 |
-
* @return string
|
| 45 |
-
*/
|
| 46 |
-
public function getPostUrl()
|
| 47 |
-
{
|
| 48 |
-
return $this->getUrl('*/*/send', array('_secure' => true));
|
| 49 |
-
}
|
| 50 |
-
|
| 51 |
-
/**
|
| 52 |
-
* Get current access token value
|
| 53 |
-
*
|
| 54 |
-
* @return string
|
| 55 |
-
*/
|
| 56 |
-
public function getAccessTokenValue()
|
| 57 |
-
{
|
| 58 |
-
return Mage::helper('marketingsoftware/config')->getAccessToken();
|
| 59 |
-
}
|
| 60 |
}
|
| 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 |
+
* Accesstoken Block
|
| 29 |
+
*/
|
| 30 |
+
class Copernica_MarketingSoftware_Block_Adminhtml_Marketingsoftware_Accesstoken extends Mage_Core_Block_Template
|
| 31 |
+
{
|
| 32 |
+
/**
|
| 33 |
+
* Constructor
|
| 34 |
+
*/
|
| 35 |
+
public function __construct()
|
| 36 |
+
{
|
| 37 |
+
parent::__construct();
|
| 38 |
+
$this->setTemplate('marketingsoftware/accessToken.phtml');
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
/**
|
| 42 |
+
* Returns the post URL.
|
| 43 |
+
*
|
| 44 |
+
* @return string
|
| 45 |
+
*/
|
| 46 |
+
public function getPostUrl()
|
| 47 |
+
{
|
| 48 |
+
return $this->getUrl('*/*/send', array('_secure' => true));
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
/**
|
| 52 |
+
* Get current access token value
|
| 53 |
+
*
|
| 54 |
+
* @return string
|
| 55 |
+
*/
|
| 56 |
+
public function getAccessTokenValue()
|
| 57 |
+
{
|
| 58 |
+
return Mage::helper('marketingsoftware/config')->getAccessToken();
|
| 59 |
+
}
|
| 60 |
}
|
app/code/community/Copernica/MarketingSoftware/Block/Adminhtml/Marketingsoftware/Link.php
CHANGED
|
@@ -1,81 +1,81 @@
|
|
| 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 |
-
* Link Block
|
| 29 |
-
*/
|
| 30 |
-
class Copernica_MarketingSoftware_Block_Adminhtml_Marketingsoftware_Link extends Mage_Core_Block_Template
|
| 31 |
-
{
|
| 32 |
-
/**
|
| 33 |
-
* Constructor
|
| 34 |
-
*
|
| 35 |
-
*/
|
| 36 |
-
public function __construct()
|
| 37 |
-
{
|
| 38 |
-
parent::__construct();
|
| 39 |
-
$this->setTemplate('marketingsoftware/link.phtml');
|
| 40 |
-
}
|
| 41 |
-
|
| 42 |
-
/**
|
| 43 |
-
* Return Ajax url that can be used to validate collection
|
| 44 |
-
*
|
| 45 |
-
* @return string
|
| 46 |
-
*/
|
| 47 |
-
public function getAjaxCollectionValidateUrl()
|
| 48 |
-
{
|
| 49 |
-
return $this->getUrl('*/marketingsoftware_ajaxcollection/validate', array('_secure' => true));
|
| 50 |
-
}
|
| 51 |
-
|
| 52 |
-
/**
|
| 53 |
-
* Return Ajax url that can be used ti fetch information about collection field
|
| 54 |
-
*
|
| 55 |
-
* @return string
|
| 56 |
-
*/
|
| 57 |
-
public function getAjaxCollectionFetchUrl()
|
| 58 |
-
{
|
| 59 |
-
return $this->getUrl('*/marketingsoftware_ajaxcollection/fetch', array('_secure' => true));
|
| 60 |
-
}
|
| 61 |
-
|
| 62 |
-
/**
|
| 63 |
-
* Return Ajax url that can be used to store collection.
|
| 64 |
-
*
|
| 65 |
-
* @return string
|
| 66 |
-
*/
|
| 67 |
-
public function getAjaxCollectionStoreUrl()
|
| 68 |
-
{
|
| 69 |
-
return $this->getUrl('*/marketingsoftware_ajaxcollection/store', array('_secure' => true));
|
| 70 |
-
}
|
| 71 |
-
|
| 72 |
-
/**
|
| 73 |
-
* Return Ajax url that can be used to create default structure.
|
| 74 |
-
*
|
| 75 |
-
* @return string
|
| 76 |
-
*/
|
| 77 |
-
public function getAjaxCollectionDefaultUrl()
|
| 78 |
-
{
|
| 79 |
-
return $this->getUrl('*/marketingsoftware_ajaxcollection/default', array('_secure' => true));
|
| 80 |
-
}
|
| 81 |
}
|
| 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 |
+
* Link Block
|
| 29 |
+
*/
|
| 30 |
+
class Copernica_MarketingSoftware_Block_Adminhtml_Marketingsoftware_Link extends Mage_Core_Block_Template
|
| 31 |
+
{
|
| 32 |
+
/**
|
| 33 |
+
* Constructor
|
| 34 |
+
*
|
| 35 |
+
*/
|
| 36 |
+
public function __construct()
|
| 37 |
+
{
|
| 38 |
+
parent::__construct();
|
| 39 |
+
$this->setTemplate('marketingsoftware/link.phtml');
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
/**
|
| 43 |
+
* Return Ajax url that can be used to validate collection
|
| 44 |
+
*
|
| 45 |
+
* @return string
|
| 46 |
+
*/
|
| 47 |
+
public function getAjaxCollectionValidateUrl()
|
| 48 |
+
{
|
| 49 |
+
return $this->getUrl('*/marketingsoftware_ajaxcollection/validate', array('_secure' => true));
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
/**
|
| 53 |
+
* Return Ajax url that can be used ti fetch information about collection field
|
| 54 |
+
*
|
| 55 |
+
* @return string
|
| 56 |
+
*/
|
| 57 |
+
public function getAjaxCollectionFetchUrl()
|
| 58 |
+
{
|
| 59 |
+
return $this->getUrl('*/marketingsoftware_ajaxcollection/fetch', array('_secure' => true));
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
/**
|
| 63 |
+
* Return Ajax url that can be used to store collection.
|
| 64 |
+
*
|
| 65 |
+
* @return string
|
| 66 |
+
*/
|
| 67 |
+
public function getAjaxCollectionStoreUrl()
|
| 68 |
+
{
|
| 69 |
+
return $this->getUrl('*/marketingsoftware_ajaxcollection/store', array('_secure' => true));
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
/**
|
| 73 |
+
* Return Ajax url that can be used to create default structure.
|
| 74 |
+
*
|
| 75 |
+
* @return string
|
| 76 |
+
*/
|
| 77 |
+
public function getAjaxCollectionDefaultUrl()
|
| 78 |
+
{
|
| 79 |
+
return $this->getUrl('*/marketingsoftware_ajaxcollection/default', array('_secure' => true));
|
| 80 |
+
}
|
| 81 |
}
|
app/code/community/Copernica/MarketingSoftware/Block/Adminhtml/Marketingsoftware/Sync.php
CHANGED
|
@@ -1,118 +1,118 @@
|
|
| 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 |
-
* Sync block
|
| 29 |
-
*/
|
| 30 |
-
class Copernica_MarketingSoftware_Block_Adminhtml_MarketingSoftware_Sync extends Mage_Core_Block_Template
|
| 31 |
-
{
|
| 32 |
-
/**
|
| 33 |
-
* Construct block
|
| 34 |
-
*/
|
| 35 |
-
public function __construct()
|
| 36 |
-
{
|
| 37 |
-
parent::__construct();
|
| 38 |
-
$this->setTemplate('marketingsoftware/sync.phtml');
|
| 39 |
-
}
|
| 40 |
-
|
| 41 |
-
/**
|
| 42 |
-
* Get url that will point to 'post' action in contoller
|
| 43 |
-
*
|
| 44 |
-
* @return string
|
| 45 |
-
*/
|
| 46 |
-
public function getPostUrl()
|
| 47 |
-
{
|
| 48 |
-
return $this->getUrl('*/*/post', array('_secure' => true));
|
| 49 |
-
}
|
| 50 |
-
|
| 51 |
-
/**
|
| 52 |
-
* Get sync profiles collection
|
| 53 |
-
*
|
| 54 |
-
* @return Copernica_MarketingSoftware_Model_Mysql4_SyncProfile_Collection
|
| 55 |
-
*/
|
| 56 |
-
public function getSyncProfiles()
|
| 57 |
-
{
|
| 58 |
-
return Mage::getModel('marketingsoftware/sync_profile')->getCollection();
|
| 59 |
-
}
|
| 60 |
-
|
| 61 |
-
/**
|
| 62 |
-
* Get url that will point to 'get profile' action in contoller
|
| 63 |
-
*
|
| 64 |
-
* @return string
|
| 65 |
-
*/
|
| 66 |
-
public function getProfileUrl()
|
| 67 |
-
{
|
| 68 |
-
return $this->getUrl('*/*/getProfile', array('_secure' => true));
|
| 69 |
-
}
|
| 70 |
-
|
| 71 |
-
/**
|
| 72 |
-
* Get url that will point to delete action in controller
|
| 73 |
-
*
|
| 74 |
-
* @return string
|
| 75 |
-
*/
|
| 76 |
-
public function getDeleteUrl()
|
| 77 |
-
{
|
| 78 |
-
return $this->getUrl('*/*/delete', array('_secure' => true));
|
| 79 |
-
}
|
| 80 |
-
|
| 81 |
-
/**
|
| 82 |
-
* Get url that will point to state action in controller
|
| 83 |
-
*
|
| 84 |
-
* @todo Two returns????
|
| 85 |
-
* @return string
|
| 86 |
-
*/
|
| 87 |
-
public function getStateUrl()
|
| 88 |
-
{
|
| 89 |
-
return Mage::helper('adminhtml')->getUrl('*/*/state');
|
| 90 |
-
return $this->getUrl('*/*/state', array('_secure' => true));
|
| 91 |
-
}
|
| 92 |
-
|
| 93 |
-
/**
|
| 94 |
-
* Return authorization string
|
| 95 |
-
*
|
| 96 |
-
* @return string
|
| 97 |
-
*/
|
| 98 |
-
public function getAuthorizationUrl()
|
| 99 |
-
{
|
| 100 |
-
$authUrl = 'https://www.copernica.com/en/authorize';
|
| 101 |
-
|
| 102 |
-
$query = array (
|
| 103 |
-
'scope' => 'all',
|
| 104 |
-
'response_type' => 'code',
|
| 105 |
-
// 'state' => Mage::getSingleton('adminhtml/session')->getState(),
|
| 106 |
-
'redirect_uri' => $this->getStateUrl(),
|
| 107 |
-
// 'client_id' => ''
|
| 108 |
-
);
|
| 109 |
-
|
| 110 |
-
$parts = array();
|
| 111 |
-
|
| 112 |
-
foreach ($query as $key => $value) {
|
| 113 |
-
$parts[] = implode('=', array($key, urlencode($value)));
|
| 114 |
-
}
|
| 115 |
-
|
| 116 |
-
return $authUrl.'?'.implode('&', $parts);
|
| 117 |
-
}
|
| 118 |
}
|
| 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 |
+
* Sync block
|
| 29 |
+
*/
|
| 30 |
+
class Copernica_MarketingSoftware_Block_Adminhtml_MarketingSoftware_Sync extends Mage_Core_Block_Template
|
| 31 |
+
{
|
| 32 |
+
/**
|
| 33 |
+
* Construct block
|
| 34 |
+
*/
|
| 35 |
+
public function __construct()
|
| 36 |
+
{
|
| 37 |
+
parent::__construct();
|
| 38 |
+
$this->setTemplate('marketingsoftware/sync.phtml');
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
/**
|
| 42 |
+
* Get url that will point to 'post' action in contoller
|
| 43 |
+
*
|
| 44 |
+
* @return string
|
| 45 |
+
*/
|
| 46 |
+
public function getPostUrl()
|
| 47 |
+
{
|
| 48 |
+
return $this->getUrl('*/*/post', array('_secure' => true));
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
/**
|
| 52 |
+
* Get sync profiles collection
|
| 53 |
+
*
|
| 54 |
+
* @return Copernica_MarketingSoftware_Model_Mysql4_SyncProfile_Collection
|
| 55 |
+
*/
|
| 56 |
+
public function getSyncProfiles()
|
| 57 |
+
{
|
| 58 |
+
return Mage::getModel('marketingsoftware/sync_profile')->getCollection();
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
/**
|
| 62 |
+
* Get url that will point to 'get profile' action in contoller
|
| 63 |
+
*
|
| 64 |
+
* @return string
|
| 65 |
+
*/
|
| 66 |
+
public function getProfileUrl()
|
| 67 |
+
{
|
| 68 |
+
return $this->getUrl('*/*/getProfile', array('_secure' => true));
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
/**
|
| 72 |
+
* Get url that will point to delete action in controller
|
| 73 |
+
*
|
| 74 |
+
* @return string
|
| 75 |
+
*/
|
| 76 |
+
public function getDeleteUrl()
|
| 77 |
+
{
|
| 78 |
+
return $this->getUrl('*/*/delete', array('_secure' => true));
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
/**
|
| 82 |
+
* Get url that will point to state action in controller
|
| 83 |
+
*
|
| 84 |
+
* @todo Two returns????
|
| 85 |
+
* @return string
|
| 86 |
+
*/
|
| 87 |
+
public function getStateUrl()
|
| 88 |
+
{
|
| 89 |
+
return Mage::helper('adminhtml')->getUrl('*/*/state');
|
| 90 |
+
return $this->getUrl('*/*/state', array('_secure' => true));
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
/**
|
| 94 |
+
* Return authorization string
|
| 95 |
+
*
|
| 96 |
+
* @return string
|
| 97 |
+
*/
|
| 98 |
+
public function getAuthorizationUrl()
|
| 99 |
+
{
|
| 100 |
+
$authUrl = 'https://www.copernica.com/en/authorize';
|
| 101 |
+
|
| 102 |
+
$query = array (
|
| 103 |
+
'scope' => 'all',
|
| 104 |
+
'response_type' => 'code',
|
| 105 |
+
// 'state' => Mage::getSingleton('adminhtml/session')->getState(),
|
| 106 |
+
'redirect_uri' => $this->getStateUrl(),
|
| 107 |
+
// 'client_id' => ''
|
| 108 |
+
);
|
| 109 |
+
|
| 110 |
+
$parts = array();
|
| 111 |
+
|
| 112 |
+
foreach ($query as $key => $value) {
|
| 113 |
+
$parts[] = implode('=', array($key, urlencode($value)));
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
return $authUrl.'?'.implode('&', $parts);
|
| 117 |
+
}
|
| 118 |
}
|
app/code/community/Copernica/MarketingSoftware/Controller/Action.php
CHANGED
|
@@ -1,181 +1,181 @@
|
|
| 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 |
-
* This class will be a base for our visual constrollers.
|
| 29 |
-
*/
|
| 30 |
-
class Copernica_MarketingSoftware_Controller_Action extends Mage_Adminhtml_Controller_Action
|
| 31 |
-
{
|
| 32 |
-
/**
|
| 33 |
-
* Since default magento notification system is being derpy from version to
|
| 34 |
-
* version we will use our own one. All notes that we will want to display
|
| 35 |
-
* will be stored in this arrays as entries. For now we will just store it
|
| 36 |
-
* in super easy format.
|
| 37 |
-
*
|
| 38 |
-
* array (
|
| 39 |
-
* 'errors' => string[],
|
| 40 |
-
* 'warnings' => string[]
|
| 41 |
-
* )
|
| 42 |
-
*
|
| 43 |
-
* @var array
|
| 44 |
-
*/
|
| 45 |
-
protected $_notes = array();
|
| 46 |
-
|
| 47 |
-
/**
|
| 48 |
-
* index action.
|
| 49 |
-
*/
|
| 50 |
-
public function _construct()
|
| 51 |
-
{
|
| 52 |
-
$queue = Mage::getModel('marketingsoftware/queue_item')->getCollection();
|
| 53 |
-
|
| 54 |
-
$this->_checkQueueSize($queue);
|
| 55 |
-
|
| 56 |
-
$this->_checkQueueTime($queue);
|
| 57 |
-
|
| 58 |
-
$this->_checkApiAccess();
|
| 59 |
-
}
|
| 60 |
-
|
| 61 |
-
/**
|
| 62 |
-
* Check if queue have too many items. This method will output messages on
|
| 63 |
-
* admin session to inform him about current state.
|
| 64 |
-
*
|
| 65 |
-
* @param Copernica_MarketingSoftware_Model_Mysql4_Queue_Item_Collection $queue
|
| 66 |
-
*/
|
| 67 |
-
protected function _checkQueueSize(Copernica_MarketingSoftware_Model_Mysql4_Queue_Item_Collection $queue)
|
| 68 |
-
{
|
| 69 |
-
$queueSize = $queue->getSize();
|
| 70 |
-
|
| 71 |
-
if ($queueSize < 100) {
|
| 72 |
-
return;
|
| 73 |
-
}
|
| 74 |
-
|
| 75 |
-
$this->_addWarning(Mage::helper('marketingsoftware')->__("There is queue of %d local modification waiting to be processed", $queueSize));
|
| 76 |
-
}
|
| 77 |
-
|
| 78 |
-
/**
|
| 79 |
-
* Check if queue have too old items.
|
| 80 |
-
*
|
| 81 |
-
* @param Copernica_MarketingSoftware_Model_Mysql4_Queue_Item_Collection $queue
|
| 82 |
-
*/
|
| 83 |
-
protected function _checkQueueTime(Copernica_MarketingSoftware_Model_Mysql4_Queue_Item_Collection $queue)
|
| 84 |
-
{
|
| 85 |
-
$oldestItemTimestamp = $queue->getQueueStartTime();
|
| 86 |
-
|
| 87 |
-
if (is_null($oldestItemTimestamp)) {
|
| 88 |
-
return;
|
| 89 |
-
}
|
| 90 |
-
|
| 91 |
-
if (time() - strtotime($oldestItemTimestamp) < 60*60*24) {
|
| 92 |
-
return;
|
| 93 |
-
}
|
| 94 |
-
|
| 95 |
-
$printableTime = Mage::helper('core')->formatDate($oldestItemTimestamp, 'short', true);
|
| 96 |
-
|
| 97 |
-
$this->_addWarning(Mage::helper('marketingsoftware')->__("There is still a modification of %s that is not synchronized with Copernica.", $printableTime));
|
| 98 |
-
}
|
| 99 |
-
|
| 100 |
-
/**
|
| 101 |
-
* This function will check if we have an access to API.
|
| 102 |
-
*/
|
| 103 |
-
protected function _checkApiAccess()
|
| 104 |
-
{
|
| 105 |
-
$accessToken = Mage::helper('marketingsoftware/config')->getAccessToken();
|
| 106 |
-
|
| 107 |
-
if ($accessToken) {
|
| 108 |
-
return;
|
| 109 |
-
}
|
| 110 |
-
|
| 111 |
-
$this->_addWarning(Mage::helper('marketingsoftware')->__('There is no access token for API communication.'));
|
| 112 |
-
}
|
| 113 |
-
|
| 114 |
-
/**
|
| 115 |
-
* Add warning message to controller.
|
| 116 |
-
*
|
| 117 |
-
* @param string $text
|
| 118 |
-
* @return self
|
| 119 |
-
*/
|
| 120 |
-
protected function _addWarning($text)
|
| 121 |
-
{
|
| 122 |
-
$this->_notes['warnings'][] = $text;
|
| 123 |
-
|
| 124 |
-
return $this;
|
| 125 |
-
}
|
| 126 |
-
|
| 127 |
-
/**
|
| 128 |
-
* Add error message to controller.
|
| 129 |
-
*
|
| 130 |
-
* @todo Not used???
|
| 131 |
-
* @param string $text
|
| 132 |
-
* @return self
|
| 133 |
-
*/
|
| 134 |
-
protected function _addError($text)
|
| 135 |
-
{
|
| 136 |
-
$this->_notes['errors'][] = $text;
|
| 137 |
-
|
| 138 |
-
return $this;
|
| 139 |
-
}
|
| 140 |
-
|
| 141 |
-
/**
|
| 142 |
-
* Get current list of warnings.
|
| 143 |
-
*
|
| 144 |
-
* @return array
|
| 145 |
-
*/
|
| 146 |
-
public function getWarnings()
|
| 147 |
-
{
|
| 148 |
-
return $this->_getNotifications('warnings');
|
| 149 |
-
}
|
| 150 |
-
|
| 151 |
-
/**
|
| 152 |
-
* Get current list of errors
|
| 153 |
-
*
|
| 154 |
-
* @return array
|
| 155 |
-
*/
|
| 156 |
-
public function getErrors()
|
| 157 |
-
{
|
| 158 |
-
return $this->_getNotifications('errors');
|
| 159 |
-
}
|
| 160 |
-
|
| 161 |
-
/**
|
| 162 |
-
* Get notifications of given type
|
| 163 |
-
*
|
| 164 |
-
* @param string $type
|
| 165 |
-
* @return array
|
| 166 |
-
*/
|
| 167 |
-
protected function _getNotifications($type)
|
| 168 |
-
{
|
| 169 |
-
if (!array_key_exists($type, $this->_notes)) {
|
| 170 |
-
return array();
|
| 171 |
-
}
|
| 172 |
-
|
| 173 |
-
$output = $this->_notes[$type];
|
| 174 |
-
|
| 175 |
-
if(is_array($output)) {
|
| 176 |
-
return $output;
|
| 177 |
-
}
|
| 178 |
-
|
| 179 |
-
return array();
|
| 180 |
-
}
|
| 181 |
}
|
| 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 |
+
* This class will be a base for our visual constrollers.
|
| 29 |
+
*/
|
| 30 |
+
class Copernica_MarketingSoftware_Controller_Action extends Mage_Adminhtml_Controller_Action
|
| 31 |
+
{
|
| 32 |
+
/**
|
| 33 |
+
* Since default magento notification system is being derpy from version to
|
| 34 |
+
* version we will use our own one. All notes that we will want to display
|
| 35 |
+
* will be stored in this arrays as entries. For now we will just store it
|
| 36 |
+
* in super easy format.
|
| 37 |
+
*
|
| 38 |
+
* array (
|
| 39 |
+
* 'errors' => string[],
|
| 40 |
+
* 'warnings' => string[]
|
| 41 |
+
* )
|
| 42 |
+
*
|
| 43 |
+
* @var array
|
| 44 |
+
*/
|
| 45 |
+
protected $_notes = array();
|
| 46 |
+
|
| 47 |
+
/**
|
| 48 |
+
* index action.
|
| 49 |
+
*/
|
| 50 |
+
public function _construct()
|
| 51 |
+
{
|
| 52 |
+
$queue = Mage::getModel('marketingsoftware/queue_item')->getCollection();
|
| 53 |
+
|
| 54 |
+
$this->_checkQueueSize($queue);
|
| 55 |
+
|
| 56 |
+
$this->_checkQueueTime($queue);
|
| 57 |
+
|
| 58 |
+
$this->_checkApiAccess();
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
/**
|
| 62 |
+
* Check if queue have too many items. This method will output messages on
|
| 63 |
+
* admin session to inform him about current state.
|
| 64 |
+
*
|
| 65 |
+
* @param Copernica_MarketingSoftware_Model_Mysql4_Queue_Item_Collection $queue
|
| 66 |
+
*/
|
| 67 |
+
protected function _checkQueueSize(Copernica_MarketingSoftware_Model_Mysql4_Queue_Item_Collection $queue)
|
| 68 |
+
{
|
| 69 |
+
$queueSize = $queue->getSize();
|
| 70 |
+
|
| 71 |
+
if ($queueSize < 100) {
|
| 72 |
+
return;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
$this->_addWarning(Mage::helper('marketingsoftware')->__("There is queue of %d local modification waiting to be processed", $queueSize));
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
/**
|
| 79 |
+
* Check if queue have too old items.
|
| 80 |
+
*
|
| 81 |
+
* @param Copernica_MarketingSoftware_Model_Mysql4_Queue_Item_Collection $queue
|
| 82 |
+
*/
|
| 83 |
+
protected function _checkQueueTime(Copernica_MarketingSoftware_Model_Mysql4_Queue_Item_Collection $queue)
|
| 84 |
+
{
|
| 85 |
+
$oldestItemTimestamp = $queue->getQueueStartTime();
|
| 86 |
+
|
| 87 |
+
if (is_null($oldestItemTimestamp)) {
|
| 88 |
+
return;
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
if (time() - strtotime($oldestItemTimestamp) < 60*60*24) {
|
| 92 |
+
return;
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
$printableTime = Mage::helper('core')->formatDate($oldestItemTimestamp, 'short', true);
|
| 96 |
+
|
| 97 |
+
$this->_addWarning(Mage::helper('marketingsoftware')->__("There is still a modification of %s that is not synchronized with Copernica.", $printableTime));
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
/**
|
| 101 |
+
* This function will check if we have an access to API.
|
| 102 |
+
*/
|
| 103 |
+
protected function _checkApiAccess()
|
| 104 |
+
{
|
| 105 |
+
$accessToken = Mage::helper('marketingsoftware/config')->getAccessToken();
|
| 106 |
+
|
| 107 |
+
if ($accessToken) {
|
| 108 |
+
return;
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
$this->_addWarning(Mage::helper('marketingsoftware')->__('There is no access token for API communication.'));
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
/**
|
| 115 |
+
* Add warning message to controller.
|
| 116 |
+
*
|
| 117 |
+
* @param string $text
|
| 118 |
+
* @return self
|
| 119 |
+
*/
|
| 120 |
+
protected function _addWarning($text)
|
| 121 |
+
{
|
| 122 |
+
$this->_notes['warnings'][] = $text;
|
| 123 |
+
|
| 124 |
+
return $this;
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
/**
|
| 128 |
+
* Add error message to controller.
|
| 129 |
+
*
|
| 130 |
+
* @todo Not used???
|
| 131 |
+
* @param string $text
|
| 132 |
+
* @return self
|
| 133 |
+
*/
|
| 134 |
+
protected function _addError($text)
|
| 135 |
+
{
|
| 136 |
+
$this->_notes['errors'][] = $text;
|
| 137 |
+
|
| 138 |
+
return $this;
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
/**
|
| 142 |
+
* Get current list of warnings.
|
| 143 |
+
*
|
| 144 |
+
* @return array
|
| 145 |
+
*/
|
| 146 |
+
public function getWarnings()
|
| 147 |
+
{
|
| 148 |
+
return $this->_getNotifications('warnings');
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
/**
|
| 152 |
+
* Get current list of errors
|
| 153 |
+
*
|
| 154 |
+
* @return array
|
| 155 |
+
*/
|
| 156 |
+
public function getErrors()
|
| 157 |
+
{
|
| 158 |
+
return $this->_getNotifications('errors');
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
/**
|
| 162 |
+
* Get notifications of given type
|
| 163 |
+
*
|
| 164 |
+
* @param string $type
|
| 165 |
+
* @return array
|
| 166 |
+
*/
|
| 167 |
+
protected function _getNotifications($type)
|
| 168 |
+
{
|
| 169 |
+
if (!array_key_exists($type, $this->_notes)) {
|
| 170 |
+
return array();
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
$output = $this->_notes[$type];
|
| 174 |
+
|
| 175 |
+
if(is_array($output)) {
|
| 176 |
+
return $output;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
return array();
|
| 180 |
+
}
|
| 181 |
}
|
app/code/community/Copernica/MarketingSoftware/Exception.php
CHANGED
|
@@ -1,80 +1,80 @@
|
|
| 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 |
-
* This class holds implementation for exception class that will be used in this
|
| 29 |
-
* extension. To throw an exception use
|
| 30 |
-
*
|
| 31 |
-
* throw Mage::exception('Copernica_MarketingSoftware', $message, $code);
|
| 32 |
-
*/
|
| 33 |
-
class Copernica_MarketingSoftware_Exception extends Exception
|
| 34 |
-
{
|
| 35 |
-
/*
|
| 36 |
-
* List of error codes as constants
|
| 37 |
-
*/
|
| 38 |
-
|
| 39 |
-
// whenever we have a situation when user is not supplying is with correct input
|
| 40 |
-
const INVALID_INPUT = 1;
|
| 41 |
-
|
| 42 |
-
// when we have an error on Api request
|
| 43 |
-
const API_REQUEST_ERROR = 2;
|
| 44 |
-
|
| 45 |
-
// when database does not exists
|
| 46 |
-
const DATABASE_NOT_EXISTS = 3;
|
| 47 |
-
|
| 48 |
-
// when database does have invalid structure
|
| 49 |
-
const DATABASE_STRUCT_INVALID = 4;
|
| 50 |
-
|
| 51 |
-
// magento field is not linked to copernica field
|
| 52 |
-
const FIELD_NOT_LINKED = 5;
|
| 53 |
-
|
| 54 |
-
// field on copernica platform does not exists
|
| 55 |
-
const FIELD_NOT_EXISTS = 6;
|
| 56 |
-
|
| 57 |
-
// structure of field is invalid
|
| 58 |
-
const FIELD_STRUCT_INVALID = 7;
|
| 59 |
-
|
| 60 |
-
// collection does not exist
|
| 61 |
-
const COLLECTION_NOT_EXISTS = 8;
|
| 62 |
-
|
| 63 |
-
// invalid collection type
|
| 64 |
-
const COLLECTION_INVALID_TYPE = 9;
|
| 65 |
-
|
| 66 |
-
// collection does not have a proper structure
|
| 67 |
-
const COLLECTION_STRUCT_INVALID = 10;
|
| 68 |
-
|
| 69 |
-
// missing valid event type
|
| 70 |
-
const EVENT_NO_TYPE = 11;
|
| 71 |
-
|
| 72 |
-
// event class does not exists or it can not be loaded
|
| 73 |
-
const EVENT_TYPE_NOT_EXISTS = 12;
|
| 74 |
-
|
| 75 |
-
// when something really, really bad happens with API
|
| 76 |
-
const API_ERROR = 13;
|
| 77 |
-
|
| 78 |
-
// when we want to access customer that does no longer exists
|
| 79 |
-
const CUSTOMER_NOT_EXISTS = 100;
|
| 80 |
}
|
| 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 |
+
* This class holds implementation for exception class that will be used in this
|
| 29 |
+
* extension. To throw an exception use
|
| 30 |
+
*
|
| 31 |
+
* throw Mage::exception('Copernica_MarketingSoftware', $message, $code);
|
| 32 |
+
*/
|
| 33 |
+
class Copernica_MarketingSoftware_Exception extends Exception
|
| 34 |
+
{
|
| 35 |
+
/*
|
| 36 |
+
* List of error codes as constants
|
| 37 |
+
*/
|
| 38 |
+
|
| 39 |
+
// whenever we have a situation when user is not supplying is with correct input
|
| 40 |
+
const INVALID_INPUT = 1;
|
| 41 |
+
|
| 42 |
+
// when we have an error on Api request
|
| 43 |
+
const API_REQUEST_ERROR = 2;
|
| 44 |
+
|
| 45 |
+
// when database does not exists
|
| 46 |
+
const DATABASE_NOT_EXISTS = 3;
|
| 47 |
+
|
| 48 |
+
// when database does have invalid structure
|
| 49 |
+
const DATABASE_STRUCT_INVALID = 4;
|
| 50 |
+
|
| 51 |
+
// magento field is not linked to copernica field
|
| 52 |
+
const FIELD_NOT_LINKED = 5;
|
| 53 |
+
|
| 54 |
+
// field on copernica platform does not exists
|
| 55 |
+
const FIELD_NOT_EXISTS = 6;
|
| 56 |
+
|
| 57 |
+
// structure of field is invalid
|
| 58 |
+
const FIELD_STRUCT_INVALID = 7;
|
| 59 |
+
|
| 60 |
+
// collection does not exist
|
| 61 |
+
const COLLECTION_NOT_EXISTS = 8;
|
| 62 |
+
|
| 63 |
+
// invalid collection type
|
| 64 |
+
const COLLECTION_INVALID_TYPE = 9;
|
| 65 |
+
|
| 66 |
+
// collection does not have a proper structure
|
| 67 |
+
const COLLECTION_STRUCT_INVALID = 10;
|
| 68 |
+
|
| 69 |
+
// missing valid event type
|
| 70 |
+
const EVENT_NO_TYPE = 11;
|
| 71 |
+
|
| 72 |
+
// event class does not exists or it can not be loaded
|
| 73 |
+
const EVENT_TYPE_NOT_EXISTS = 12;
|
| 74 |
+
|
| 75 |
+
// when something really, really bad happens with API
|
| 76 |
+
const API_ERROR = 13;
|
| 77 |
+
|
| 78 |
+
// when we want to access customer that does no longer exists
|
| 79 |
+
const CUSTOMER_NOT_EXISTS = 100;
|
| 80 |
}
|
app/code/community/Copernica/MarketingSoftware/Helper/Api/Abstract.php
CHANGED
|
@@ -1,427 +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 base class for API helpers. This class should have only the most general
|
| 29 |
-
* method that we will use.
|
| 30 |
-
*/
|
| 31 |
-
class Copernica_MarketingSoftware_Helper_Api_Abstract extends Mage_Core_Helper_Abstract
|
| 32 |
-
{
|
| 33 |
-
/**
|
| 34 |
-
* Since Magento is cheating with theirs singleton implementation, we want
|
| 35 |
-
* to use static fields for storing request instance.
|
| 36 |
-
*
|
| 37 |
-
* @var Copernica_MarketingSoftware_Helper_Rest_Request
|
| 38 |
-
*/
|
| 39 |
-
static protected $_restRequest = null;
|
| 40 |
-
|
| 41 |
-
/**
|
| 42 |
-
* Database id that is on Copernica platform.
|
| 43 |
-
*
|
| 44 |
-
* @var int
|
| 45 |
-
*/
|
| 46 |
-
static protected $_databaseId = false;
|
| 47 |
-
|
| 48 |
-
/**
|
| 49 |
-
* Cache for collection ids
|
| 50 |
-
*
|
| 51 |
-
* @var array
|
| 52 |
-
*/
|
| 53 |
-
static protected $_collectionIdCache = array();
|
| 54 |
-
|
| 55 |
-
/**
|
| 56 |
-
* Should we use profile cache?
|
| 57 |
-
*
|
| 58 |
-
* @var bool
|
| 59 |
-
*/
|
| 60 |
-
protected $_useProfileCache = false;
|
| 61 |
-
|
| 62 |
-
/**
|
| 63 |
-
* Public, standard PHP constructor. Mage_Core_Helper_Abstract is not a child
|
| 64 |
-
* of Varien_Object, so we want to use good old PHP constructor.
|
| 65 |
-
*/
|
| 66 |
-
public function __construct()
|
| 67 |
-
{
|
| 68 |
-
$this->init();
|
| 69 |
-
}
|
| 70 |
-
|
| 71 |
-
/**
|
| 72 |
-
* Initialize helper.
|
| 73 |
-
*
|
| 74 |
-
* @return Copernica_MarketingSoftware_Helper_Api_Abstract
|
| 75 |
-
*/
|
| 76 |
-
public function init()
|
| 77 |
-
{
|
| 78 |
-
$this->_restRequest();
|
| 79 |
-
|
| 80 |
-
$this->_useProfileCache = Mage::helper('marketingsoftware/config')->getProfileCache();
|
| 81 |
-
|
| 82 |
-
return $this;
|
| 83 |
-
}
|
| 84 |
-
|
| 85 |
-
/**
|
| 86 |
-
* Get Request instance.
|
| 87 |
-
* We do cache/shield request instance mostly cause it's very specific to
|
| 88 |
-
* API and circumstances. That is why we don't want to rely on magento
|
| 89 |
-
* helpers as a final solution for reqeust instance.
|
| 90 |
-
*
|
| 91 |
-
* @return Copernica_MarketingSoftware_Helper_Rest_Request
|
| 92 |
-
*/
|
| 93 |
-
protected function _restRequest()
|
| 94 |
-
{
|
| 95 |
-
if (!is_null(self::$_restRequest)) {
|
| 96 |
-
return self::$_restRequest;
|
| 97 |
-
}
|
| 98 |
-
|
| 99 |
-
return self::$_restRequest = Mage::helper('marketingsoftware/rest_request');
|
| 100 |
-
}
|
| 101 |
-
|
| 102 |
-
/**
|
| 103 |
-
* Set database Id
|
| 104 |
-
*
|
| 105 |
-
* @param int $id
|
| 106 |
-
*/
|
| 107 |
-
protected function _setDatabaseId($id)
|
| 108 |
-
{
|
| 109 |
-
self::$_databaseId = $id;
|
| 110 |
-
}
|
| 111 |
-
|
| 112 |
-
/**
|
| 113 |
-
* Check if this API instance is valid.
|
| 114 |
-
*
|
| 115 |
-
* @param boolean $extensive
|
| 116 |
-
* @return boolean
|
| 117 |
-
*/
|
| 118 |
-
public function check($extensive = false)
|
| 119 |
-
{
|
| 120 |
-
return $this->_restRequest()->check();
|
| 121 |
-
}
|
| 122 |
-
|
| 123 |
-
/**
|
| 124 |
-
* Get stored database Id. This function will return false when we can not
|
| 125 |
-
* get stored database Id.
|
| 126 |
-
*
|
| 127 |
-
* @return int|false
|
| 128 |
-
*/
|
| 129 |
-
protected function _getStoredDatabaseId()
|
| 130 |
-
{
|
| 131 |
-
$databaseId = Mage::helper('marketingsoftware/config')->getDatabaseId();
|
| 132 |
-
|
| 133 |
-
if ($databaseId) {
|
| 134 |
-
return $databaseId;
|
| 135 |
-
}
|
| 136 |
-
|
| 137 |
-
$databaseName = Mage::helper('marketingsoftware/config')->getDatabaseName();
|
| 138 |
-
|
| 139 |
-
if (!$databaseName) {
|
| 140 |
-
return false;
|
| 141 |
-
}
|
| 142 |
-
|
| 143 |
-
$databaseId = $this->_getDatabaseIdByName($databaseName);
|
| 144 |
-
|
| 145 |
-
Mage::helper('marketingsoftware/config')->setDatabaseId($databaseId);
|
| 146 |
-
|
| 147 |
-
$this->_setDatabaseId($databaseId);
|
| 148 |
-
|
| 149 |
-
return $databaseId;
|
| 150 |
-
}
|
| 151 |
-
|
| 152 |
-
/**
|
| 153 |
-
* Get database Id by its name. This method will return false when we can
|
| 154 |
-
* not fetch database.
|
| 155 |
-
*
|
| 156 |
-
* @param string $databaseName
|
| 157 |
-
* @return int|false
|
| 158 |
-
*/
|
| 159 |
-
protected function _getDatabaseIdByName($databaseName)
|
| 160 |
-
{
|
| 161 |
-
$output = $this->_restRequest()->get(
|
| 162 |
-
'database/'.$databaseName
|
| 163 |
-
);
|
| 164 |
-
|
| 165 |
-
if (isset($output['error'])) {
|
| 166 |
-
return false;
|
| 167 |
-
}
|
| 168 |
-
|
| 169 |
-
return isset($output['ID']) ? $output['ID'] : false;
|
| 170 |
-
}
|
| 171 |
-
|
| 172 |
-
/**
|
| 173 |
-
* Get database id that will be used inside Copernica platform
|
| 174 |
-
*
|
| 175 |
-
* @param string|false $databaseName
|
| 176 |
-
* @return int
|
| 177 |
-
*/
|
| 178 |
-
public function getDatabaseId($databaseName = false)
|
| 179 |
-
{
|
| 180 |
-
if ($databaseName === false) {
|
| 181 |
-
$databaseId = $this->_getStoredDatabaseID();
|
| 182 |
-
} else {
|
| 183 |
-
$databaseId = $this->_getDatabaseIdByName($databaseName);
|
| 184 |
-
}
|
| 185 |
-
|
| 186 |
-
return $databaseId;
|
| 187 |
-
}
|
| 188 |
-
|
| 189 |
-
/**
|
| 190 |
-
* Translate collection name into an ID.
|
| 191 |
-
*
|
| 192 |
-
* @param string $name
|
| 193 |
-
* @return int
|
| 194 |
-
*/
|
| 195 |
-
public function getCollectionId($name)
|
| 196 |
-
{
|
| 197 |
-
if (!is_null(self::$_collectionIdCache) && array_key_exists($name, self::$_collectionIdCache)) {
|
| 198 |
-
return self::$_collectionIdCache[$name];
|
| 199 |
-
}
|
| 200 |
-
|
| 201 |
-
$output = $this->_restRequest()->get(
|
| 202 |
-
'database/'.$this->getDatabaseId().'/collections'
|
| 203 |
-
);
|
| 204 |
-
|
| 205 |
-
if ($output['total'] == 0) {
|
| 206 |
-
return false;
|
| 207 |
-
}
|
| 208 |
-
|
| 209 |
-
self::$_collectionIdCache = array();
|
| 210 |
-
|
| 211 |
-
foreach ($output['data'] as $collection) {
|
| 212 |
-
self::$_collectionIdCache[$collection['name']] = $collection['ID'];
|
| 213 |
-
}
|
| 214 |
-
|
| 215 |
-
if (array_key_exists($name, self::$_collectionIdCache)) {
|
| 216 |
-
return self::$_collectionIdCache[$name];
|
| 217 |
-
}
|
| 218 |
-
|
| 219 |
-
return false;
|
| 220 |
-
}
|
| 221 |
-
|
| 222 |
-
/**
|
| 223 |
-
* Get copernica profile Id by magento customer Id.
|
| 224 |
-
* This method is little bit more flexible. It's possible to supply customer
|
| 225 |
-
* data by copernica model or by array with 'id', 'storeView', 'email' fields.
|
| 226 |
-
*
|
| 227 |
-
* @param Copernica_MarketingSoftware_Model_Copernica_Entity_Customer|array $customer
|
| 228 |
-
* @return int the copernica profile Id
|
| 229 |
-
*/
|
| 230 |
-
public function getProfileId($customer)
|
| 231 |
-
{
|
| 232 |
-
if (!is_array($customer)) {
|
| 233 |
-
$customerId = $customer->getId();
|
| 234 |
-
$storeView = $customer->getStoreView();
|
| 235 |
-
$email = $customer->getEmail();
|
| 236 |
-
} else {
|
| 237 |
-
$customerId = $customer['id'];
|
| 238 |
-
$storeView = $customer['storeView'];
|
| 239 |
-
$email = $customer['email'];
|
| 240 |
-
}
|
| 241 |
-
|
| 242 |
-
$profileId = false;
|
| 243 |
-
|
| 244 |
-
if ($customerId === false) {
|
| 245 |
-
return false;
|
| 246 |
-
}
|
| 247 |
-
|
| 248 |
-
$profileCacheCollection = Mage::getModel('marketingsoftware/profile_cache')
|
| 249 |
-
->getCollection()
|
| 250 |
-
->setPageSize(1)
|
| 251 |
-
->addFieldToFilter('copernica_id', $customerId)
|
| 252 |
-
->addFieldToFilter('store_view', $storeView);
|
| 253 |
-
|
| 254 |
-
$profileCache = $profileCacheCollection->getFirstItem();
|
| 255 |
-
|
| 256 |
-
if (!$profileCache->isObjectNew()) {
|
| 257 |
-
$profileId = $profileCache->getProfileId();
|
| 258 |
-
|
| 259 |
-
if ($profileId > 0 && $profileId !== false && !is_null($profileId)) {
|
| 260 |
-
return $profileId;
|
| 261 |
-
} else {
|
| 262 |
-
$profileCache->delete();
|
| 263 |
-
}
|
| 264 |
-
}
|
| 265 |
-
|
| 266 |
-
if (strlen($email) && strlen($storeView)) {
|
| 267 |
-
$profileCacheCollection = Mage::getModel('marketingsoftware/profile_cache')
|
| 268 |
-
->getCollection()
|
| 269 |
-
->setPageSize(1)
|
| 270 |
-
->addFieldToFilter('email', $email)
|
| 271 |
-
->addFieldToFilter('store_view', $storeView);
|
| 272 |
-
|
| 273 |
-
$profileCache = $profileCacheCollection->getFirstItem();
|
| 274 |
-
|
| 275 |
-
$profileCopernicaId = $profileCache->getCopernicaId();
|
| 276 |
-
|
| 277 |
-
// if ($profileCopernicaId != $customerId && !is_null($customerId))
|
| 278 |
-
// {
|
| 279 |
-
// if (strpos($profileCopernicaId, '|') === false) {
|
| 280 |
-
// $profileCache->setCopernicaId($customerId);
|
| 281 |
-
// $profileCache->save();
|
| 282 |
-
// } elseif (is_string(array_shift(explode('|', $profileCopernicaId)))) {
|
| 283 |
-
// if (is_numeric(array_shift(explode('|', $customerId)))) {
|
| 284 |
-
// $profileCache->setCopernicaId($customerId);
|
| 285 |
-
// $profileCache->save();
|
| 286 |
-
// }
|
| 287 |
-
// }
|
| 288 |
-
// }
|
| 289 |
-
|
| 290 |
-
$profileId = $profileCache->getProfileId();
|
| 291 |
-
|
| 292 |
-
if ($profileId > 0 && $profileId !== false && !is_null($profileId)) {
|
| 293 |
-
return $profileId;
|
| 294 |
-
}
|
| 295 |
-
}
|
| 296 |
-
|
| 297 |
-
/**
|
| 298 |
-
* Could be that we will try to get a profile Id by email and store view
|
| 299 |
-
* only. In such case we should just skip this step cause we don't have
|
| 300 |
-
* a customer Id.
|
| 301 |
-
*/
|
| 302 |
-
if (!is_null($customerId) && strlen($customerId)) {
|
| 303 |
-
$profileId = $this->_getProfileIdByCustomerId($customerId);
|
| 304 |
-
}
|
| 305 |
-
|
| 306 |
-
if ($profileId !== false) {
|
| 307 |
-
if ($profileId > 0 && $profileId !== false && !is_null($profileId)) {
|
| 308 |
-
if (strlen($email)) {
|
| 309 |
-
$profileCache->setEmail($email);
|
| 310 |
-
}
|
| 311 |
-
|
| 312 |
-
if (strlen($storeView)) {
|
| 313 |
-
$profileCache->setStoreView($storeView);
|
| 314 |
-
}
|
| 315 |
-
|
| 316 |
-
if (!is_null($customerId)) {
|
| 317 |
-
$profileCache->setCopernicaId($customerId);
|
| 318 |
-
}
|
| 319 |
-
|
| 320 |
-
$profileCache->setProfileId($profileId);
|
| 321 |
-
$profileCache->save();
|
| 322 |
-
|
| 323 |
-
return $profileId;
|
| 324 |
-
}
|
| 325 |
-
}
|
| 326 |
-
|
| 327 |
-
if (strlen($email) == 0) {
|
| 328 |
-
return false;
|
| 329 |
-
}
|
| 330 |
-
|
| 331 |
-
$profileId = $this->_getProfileIdByEmail($email, $storeView);
|
| 332 |
-
|
| 333 |
-
if ($profileId !== false) {
|
| 334 |
-
if (!is_null($customerId)) {
|
| 335 |
-
$profileCache->setCopernicaId($customerId);
|
| 336 |
-
}
|
| 337 |
-
|
| 338 |
-
$profileCache->setStoreView($storeView);
|
| 339 |
-
$profileCache->setEmail($email);
|
| 340 |
-
$profileCache->setProfileId($profileId);
|
| 341 |
-
$profileCache->save();
|
| 342 |
-
|
| 343 |
-
return $profileId;
|
| 344 |
-
}
|
| 345 |
-
|
| 346 |
-
return false;
|
| 347 |
-
}
|
| 348 |
-
|
| 349 |
-
/**
|
| 350 |
-
* Get profile Id by customer Id. When profile can not be found FALSE will
|
| 351 |
-
* be returned.
|
| 352 |
-
*
|
| 353 |
-
* @param string $customerId
|
| 354 |
-
* @return int|false
|
| 355 |
-
*/
|
| 356 |
-
protected function _getProfileIdByCustomerId($customerId)
|
| 357 |
-
{
|
| 358 |
-
$profiles = $this->_restRequest()->get(
|
| 359 |
-
'database/'.$this->getDatabaseId().'/profiles',
|
| 360 |
-
array (
|
| 361 |
-
'fields[]' => 'customer_id=='.$customerId
|
| 362 |
-
)
|
| 363 |
-
);
|
| 364 |
-
|
| 365 |
-
if (!isset($profiles['data'][0])) {
|
| 366 |
-
return false;
|
| 367 |
-
}
|
| 368 |
-
|
| 369 |
-
if (is_null($profiles['data'][0]['ID']) || (int)$profiles['data'][0]['ID'] == 0) {
|
| 370 |
-
return false;
|
| 371 |
-
}
|
| 372 |
-
|
| 373 |
-
return $profiles['data'][0]['ID'];
|
| 374 |
-
}
|
| 375 |
-
|
| 376 |
-
/**
|
| 377 |
-
* Get profile Id by email address. FALSE will be returned if profile was not
|
| 378 |
-
* found.
|
| 379 |
-
*
|
| 380 |
-
* @param string $email
|
| 381 |
-
* @param string $storeView
|
| 382 |
-
* @return int
|
| 383 |
-
*/
|
| 384 |
-
protected function _getProfileIdByEmail($email, $storeView)
|
| 385 |
-
{
|
| 386 |
-
$customerLinkedFields = Mage::helper('marketingsoftware/config')->getLinkedCustomerFields();
|
| 387 |
-
|
| 388 |
-
$requestParams = array(
|
| 389 |
-
$customerLinkedFields['email'].'=='.$email,
|
| 390 |
-
$customerLinkedFields['storeView'].'=='.$storeView
|
| 391 |
-
);
|
| 392 |
-
|
| 393 |
-
$profiles = $this->_restRequest()->get('database/'.$this->getDatabaseId().'/profiles', array ( 'fields' => $requestParams ));
|
| 394 |
-
|
| 395 |
-
if (!isset($profiles['data'][0])) {
|
| 396 |
-
return false;
|
| 397 |
-
}
|
| 398 |
-
|
| 399 |
-
if (is_null($profiles['data'][0]['ID']) || (int)$profiles['data'][0]['ID'] == 0) {
|
| 400 |
-
return false;
|
| 401 |
-
}
|
| 402 |
-
|
| 403 |
-
return $profiles['data'][0]['ID'];
|
| 404 |
-
}
|
| 405 |
-
|
| 406 |
-
/**
|
| 407 |
-
* Get profile Id from cache
|
| 408 |
-
*
|
| 409 |
-
* @todo not used, why??
|
| 410 |
-
* @param string $customerId
|
| 411 |
-
* @return int
|
| 412 |
-
*/
|
| 413 |
-
protected function _getProfileIdFromCache($customerId)
|
| 414 |
-
{
|
| 415 |
-
$profileCache = Mage::getModel('marketingsoftware/profile_cache')
|
| 416 |
-
->getCollection()
|
| 417 |
-
->addFieldToFilter('customer_id', $customerId)
|
| 418 |
-
->setPageSize(1)
|
| 419 |
-
->getFirstItem();
|
| 420 |
-
|
| 421 |
-
$profileId = $profileCache->getProfileId();
|
| 422 |
-
|
| 423 |
-
if (!is_null($profileId)) {
|
| 424 |
-
return $profileId;
|
| 425 |
-
}
|
| 426 |
-
}
|
| 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 base class for API helpers. This class should have only the most general
|
| 29 |
+
* method that we will use.
|
| 30 |
+
*/
|
| 31 |
+
class Copernica_MarketingSoftware_Helper_Api_Abstract extends Mage_Core_Helper_Abstract
|
| 32 |
+
{
|
| 33 |
+
/**
|
| 34 |
+
* Since Magento is cheating with theirs singleton implementation, we want
|
| 35 |
+
* to use static fields for storing request instance.
|
| 36 |
+
*
|
| 37 |
+
* @var Copernica_MarketingSoftware_Helper_Rest_Request
|
| 38 |
+
*/
|
| 39 |
+
static protected $_restRequest = null;
|
| 40 |
+
|
| 41 |
+
/**
|
| 42 |
+
* Database id that is on Copernica platform.
|
| 43 |
+
*
|
| 44 |
+
* @var int
|
| 45 |
+
*/
|
| 46 |
+
static protected $_databaseId = false;
|
| 47 |
+
|
| 48 |
+
/**
|
| 49 |
+
* Cache for collection ids
|
| 50 |
+
*
|
| 51 |
+
* @var array
|
| 52 |
+
*/
|
| 53 |
+
static protected $_collectionIdCache = array();
|
| 54 |
+
|
| 55 |
+
/**
|
| 56 |
+
* Should we use profile cache?
|
| 57 |
+
*
|
| 58 |
+
* @var bool
|
| 59 |
+
*/
|
| 60 |
+
protected $_useProfileCache = false;
|
| 61 |
+
|
| 62 |
+
/**
|
| 63 |
+
* Public, standard PHP constructor. Mage_Core_Helper_Abstract is not a child
|
| 64 |
+
* of Varien_Object, so we want to use good old PHP constructor.
|
| 65 |
+
*/
|
| 66 |
+
public function __construct()
|
| 67 |
+
{
|
| 68 |
+
$this->init();
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
/**
|
| 72 |
+
* Initialize helper.
|
| 73 |
+
*
|
| 74 |
+
* @return Copernica_MarketingSoftware_Helper_Api_Abstract
|
| 75 |
+
*/
|
| 76 |
+
public function init()
|
| 77 |
+
{
|
| 78 |
+
$this->_restRequest();
|
| 79 |
+
|
| 80 |
+
$this->_useProfileCache = Mage::helper('marketingsoftware/config')->getProfileCache();
|
| 81 |
+
|
| 82 |
+
return $this;
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
/**
|
| 86 |
+
* Get Request instance.
|
| 87 |
+
* We do cache/shield request instance mostly cause it's very specific to
|
| 88 |
+
* API and circumstances. That is why we don't want to rely on magento
|
| 89 |
+
* helpers as a final solution for reqeust instance.
|
| 90 |
+
*
|
| 91 |
+
* @return Copernica_MarketingSoftware_Helper_Rest_Request
|
| 92 |
+
*/
|
| 93 |
+
protected function _restRequest()
|
| 94 |
+
{
|
| 95 |
+
if (!is_null(self::$_restRequest)) {
|
| 96 |
+
return self::$_restRequest;
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
return self::$_restRequest = Mage::helper('marketingsoftware/rest_request');
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
/**
|
| 103 |
+
* Set database Id
|
| 104 |
+
*
|
| 105 |
+
* @param int $id
|
| 106 |
+
*/
|
| 107 |
+
protected function _setDatabaseId($id)
|
| 108 |
+
{
|
| 109 |
+
self::$_databaseId = $id;
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
/**
|
| 113 |
+
* Check if this API instance is valid.
|
| 114 |
+
*
|
| 115 |
+
* @param boolean $extensive
|
| 116 |
+
* @return boolean
|
| 117 |
+
*/
|
| 118 |
+
public function check($extensive = false)
|
| 119 |
+
{
|
| 120 |
+
return $this->_restRequest()->check();
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
/**
|
| 124 |
+
* Get stored database Id. This function will return false when we can not
|
| 125 |
+
* get stored database Id.
|
| 126 |
+
*
|
| 127 |
+
* @return int|false
|
| 128 |
+
*/
|
| 129 |
+
protected function _getStoredDatabaseId()
|
| 130 |
+
{
|
| 131 |
+
$databaseId = Mage::helper('marketingsoftware/config')->getDatabaseId();
|
| 132 |
+
|
| 133 |
+
if ($databaseId) {
|
| 134 |
+
return $databaseId;
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
$databaseName = Mage::helper('marketingsoftware/config')->getDatabaseName();
|
| 138 |
+
|
| 139 |
+
if (!$databaseName) {
|
| 140 |
+
return false;
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
$databaseId = $this->_getDatabaseIdByName($databaseName);
|
| 144 |
+
|
| 145 |
+
Mage::helper('marketingsoftware/config')->setDatabaseId($databaseId);
|
| 146 |
+
|
| 147 |
+
$this->_setDatabaseId($databaseId);
|
| 148 |
+
|
| 149 |
+
return $databaseId;
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
/**
|
| 153 |
+
* Get database Id by its name. This method will return false when we can
|
| 154 |
+
* not fetch database.
|
| 155 |
+
*
|
| 156 |
+
* @param string $databaseName
|
| 157 |
+
* @return int|false
|
| 158 |
+
*/
|
| 159 |
+
protected function _getDatabaseIdByName($databaseName)
|
| 160 |
+
{
|
| 161 |
+
$output = $this->_restRequest()->get(
|
| 162 |
+
'database/'.$databaseName
|
| 163 |
+
);
|
| 164 |
+
|
| 165 |
+
if (isset($output['error'])) {
|
| 166 |
+
return false;
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
return isset($output['ID']) ? $output['ID'] : false;
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
/**
|
| 173 |
+
* Get database id that will be used inside Copernica platform
|
| 174 |
+
*
|
| 175 |
+
* @param string|false $databaseName
|
| 176 |
+
* @return int
|
| 177 |
+
*/
|
| 178 |
+
public function getDatabaseId($databaseName = false)
|
| 179 |
+
{
|
| 180 |
+
if ($databaseName === false) {
|
| 181 |
+
$databaseId = $this->_getStoredDatabaseID();
|
| 182 |
+
} else {
|
| 183 |
+
$databaseId = $this->_getDatabaseIdByName($databaseName);
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
return $databaseId;
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
/**
|
| 190 |
+
* Translate collection name into an ID.
|
| 191 |
+
*
|
| 192 |
+
* @param string $name
|
| 193 |
+
* @return int
|
| 194 |
+
*/
|
| 195 |
+
public function getCollectionId($name)
|
| 196 |
+
{
|
| 197 |
+
if (!is_null(self::$_collectionIdCache) && array_key_exists($name, self::$_collectionIdCache)) {
|
| 198 |
+
return self::$_collectionIdCache[$name];
|
| 199 |
+
}
|
| 200 |
+
|
| 201 |
+
$output = $this->_restRequest()->get(
|
| 202 |
+
'database/'.$this->getDatabaseId().'/collections'
|
| 203 |
+
);
|
| 204 |
+
|
| 205 |
+
if ($output['total'] == 0) {
|
| 206 |
+
return false;
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
self::$_collectionIdCache = array();
|
| 210 |
+
|
| 211 |
+
foreach ($output['data'] as $collection) {
|
| 212 |
+
self::$_collectionIdCache[$collection['name']] = $collection['ID'];
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
+
if (array_key_exists($name, self::$_collectionIdCache)) {
|
| 216 |
+
return self::$_collectionIdCache[$name];
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
return false;
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
+
/**
|
| 223 |
+
* Get copernica profile Id by magento customer Id.
|
| 224 |
+
* This method is little bit more flexible. It's possible to supply customer
|
| 225 |
+
* data by copernica model or by array with 'id', 'storeView', 'email' fields.
|
| 226 |
+
*
|
| 227 |
+
* @param Copernica_MarketingSoftware_Model_Copernica_Entity_Customer|array $customer
|
| 228 |
+
* @return int the copernica profile Id
|
| 229 |
+
*/
|
| 230 |
+
public function getProfileId($customer)
|
| 231 |
+
{
|
| 232 |
+
if (!is_array($customer)) {
|
| 233 |
+
$customerId = $customer->getId();
|
| 234 |
+
$storeView = $customer->getStoreView();
|
| 235 |
+
$email = $customer->getEmail();
|
| 236 |
+
} else {
|
| 237 |
+
$customerId = $customer['id'];
|
| 238 |
+
$storeView = $customer['storeView'];
|
| 239 |
+
$email = $customer['email'];
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
+
$profileId = false;
|
| 243 |
+
|
| 244 |
+
if ($customerId === false) {
|
| 245 |
+
return false;
|
| 246 |
+
}
|
| 247 |
+
|
| 248 |
+
$profileCacheCollection = Mage::getModel('marketingsoftware/profile_cache')
|
| 249 |
+
->getCollection()
|
| 250 |
+
->setPageSize(1)
|
| 251 |
+
->addFieldToFilter('copernica_id', $customerId)
|
| 252 |
+
->addFieldToFilter('store_view', $storeView);
|
| 253 |
+
|
| 254 |
+
$profileCache = $profileCacheCollection->getFirstItem();
|
| 255 |
+
|
| 256 |
+
if (!$profileCache->isObjectNew()) {
|
| 257 |
+
$profileId = $profileCache->getProfileId();
|
| 258 |
+
|
| 259 |
+
if ($profileId > 0 && $profileId !== false && !is_null($profileId)) {
|
| 260 |
+
return $profileId;
|
| 261 |
+
} else {
|
| 262 |
+
$profileCache->delete();
|
| 263 |
+
}
|
| 264 |
+
}
|
| 265 |
+
|
| 266 |
+
if (strlen($email) && strlen($storeView)) {
|
| 267 |
+
$profileCacheCollection = Mage::getModel('marketingsoftware/profile_cache')
|
| 268 |
+
->getCollection()
|
| 269 |
+
->setPageSize(1)
|
| 270 |
+
->addFieldToFilter('email', $email)
|
| 271 |
+
->addFieldToFilter('store_view', $storeView);
|
| 272 |
+
|
| 273 |
+
$profileCache = $profileCacheCollection->getFirstItem();
|
| 274 |
+
|
| 275 |
+
$profileCopernicaId = $profileCache->getCopernicaId();
|
| 276 |
+
|
| 277 |
+
// if ($profileCopernicaId != $customerId && !is_null($customerId))
|
| 278 |
+
// {
|
| 279 |
+
// if (strpos($profileCopernicaId, '|') === false) {
|
| 280 |
+
// $profileCache->setCopernicaId($customerId);
|
| 281 |
+
// $profileCache->save();
|
| 282 |
+
// } elseif (is_string(array_shift(explode('|', $profileCopernicaId)))) {
|
| 283 |
+
// if (is_numeric(array_shift(explode('|', $customerId)))) {
|
| 284 |
+
// $profileCache->setCopernicaId($customerId);
|
| 285 |
+
// $profileCache->save();
|
| 286 |
+
// }
|
| 287 |
+
// }
|
| 288 |
+
// }
|
| 289 |
+
|
| 290 |
+
$profileId = $profileCache->getProfileId();
|
| 291 |
+
|
| 292 |
+
if ($profileId > 0 && $profileId !== false && !is_null($profileId)) {
|
| 293 |
+
return $profileId;
|
| 294 |
+
}
|
| 295 |
+
}
|
| 296 |
+
|
| 297 |
+
/**
|
| 298 |
+
* Could be that we will try to get a profile Id by email and store view
|
| 299 |
+
* only. In such case we should just skip this step cause we don't have
|
| 300 |
+
* a customer Id.
|
| 301 |
+
*/
|
| 302 |
+
if (!is_null($customerId) && strlen($customerId)) {
|
| 303 |
+
$profileId = $this->_getProfileIdByCustomerId($customerId);
|
| 304 |
+
}
|
| 305 |
+
|
| 306 |
+
if ($profileId !== false) {
|
| 307 |
+
if ($profileId > 0 && $profileId !== false && !is_null($profileId)) {
|
| 308 |
+
if (strlen($email)) {
|
| 309 |
+
$profileCache->setEmail($email);
|
| 310 |
+
}
|
| 311 |
+
|
| 312 |
+
if (strlen($storeView)) {
|
| 313 |
+
$profileCache->setStoreView($storeView);
|
| 314 |
+
}
|
| 315 |
+
|
| 316 |
+
if (!is_null($customerId)) {
|
| 317 |
+
$profileCache->setCopernicaId($customerId);
|
| 318 |
+
}
|
| 319 |
+
|
| 320 |
+
$profileCache->setProfileId($profileId);
|
| 321 |
+
$profileCache->save();
|
| 322 |
+
|
| 323 |
+
return $profileId;
|
| 324 |
+
}
|
| 325 |
+
}
|
| 326 |
+
|
| 327 |
+
if (strlen($email) == 0) {
|
| 328 |
+
return false;
|
| 329 |
+
}
|
| 330 |
+
|
| 331 |
+
$profileId = $this->_getProfileIdByEmail($email, $storeView);
|
| 332 |
+
|
| 333 |
+
if ($profileId !== false) {
|
| 334 |
+
if (!is_null($customerId)) {
|
| 335 |
+
$profileCache->setCopernicaId($customerId);
|
| 336 |
+
}
|
| 337 |
+
|
| 338 |
+
$profileCache->setStoreView($storeView);
|
| 339 |
+
$profileCache->setEmail($email);
|
| 340 |
+
$profileCache->setProfileId($profileId);
|
| 341 |
+
$profileCache->save();
|
| 342 |
+
|
| 343 |
+
return $profileId;
|
| 344 |
+
}
|
| 345 |
+
|
| 346 |
+
return false;
|
| 347 |
+
}
|
| 348 |
+
|
| 349 |
+
/**
|
| 350 |
+
* Get profile Id by customer Id. When profile can not be found FALSE will
|
| 351 |
+
* be returned.
|
| 352 |
+
*
|
| 353 |
+
* @param string $customerId
|
| 354 |
+
* @return int|false
|
| 355 |
+
*/
|
| 356 |
+
protected function _getProfileIdByCustomerId($customerId)
|
| 357 |
+
{
|
| 358 |
+
$profiles = $this->_restRequest()->get(
|
| 359 |
+
'database/'.$this->getDatabaseId().'/profiles',
|
| 360 |
+
array (
|
| 361 |
+
'fields[]' => 'customer_id=='.$customerId
|
| 362 |
+
)
|
| 363 |
+
);
|
| 364 |
+
|
| 365 |
+
if (!isset($profiles['data'][0])) {
|
| 366 |
+
return false;
|
| 367 |
+
}
|
| 368 |
+
|
| 369 |
+
if (is_null($profiles['data'][0]['ID']) || (int)$profiles['data'][0]['ID'] == 0) {
|
| 370 |
+
return false;
|
| 371 |
+
}
|
| 372 |
+
|
| 373 |
+
return $profiles['data'][0]['ID'];
|
| 374 |
+
}
|
| 375 |
+
|
| 376 |
+
/**
|
| 377 |
+
* Get profile Id by email address. FALSE will be returned if profile was not
|
| 378 |
+
* found.
|
| 379 |
+
*
|
| 380 |
+
* @param string $email
|
| 381 |
+
* @param string $storeView
|
| 382 |
+
* @return int
|
| 383 |
+
*/
|
| 384 |
+
protected function _getProfileIdByEmail($email, $storeView)
|
| 385 |
+
{
|
| 386 |
+
$customerLinkedFields = Mage::helper('marketingsoftware/config')->getLinkedCustomerFields();
|
| 387 |
+
|
| 388 |
+
$requestParams = array(
|
| 389 |
+
$customerLinkedFields['email'].'=='.$email,
|
| 390 |
+
$customerLinkedFields['storeView'].'=='.$storeView
|
| 391 |
+
);
|
| 392 |
+
|
| 393 |
+
$profiles = $this->_restRequest()->get('database/'.$this->getDatabaseId().'/profiles', array ( 'fields' => $requestParams ));
|
| 394 |
+
|
| 395 |
+
if (!isset($profiles['data'][0])) {
|
| 396 |
+
return false;
|
| 397 |
+
}
|
| 398 |
+
|
| 399 |
+
if (is_null($profiles['data'][0]['ID']) || (int)$profiles['data'][0]['ID'] == 0) {
|
| 400 |
+
return false;
|
| 401 |
+
}
|
| 402 |
+
|
| 403 |
+
return $profiles['data'][0]['ID'];
|
| 404 |
+
}
|
| 405 |
+
|
| 406 |
+
/**
|
| 407 |
+
* Get profile Id from cache
|
| 408 |
+
*
|
| 409 |
+
* @todo not used, why??
|
| 410 |
+
* @param string $customerId
|
| 411 |
+
* @return int
|
| 412 |
+
*/
|
| 413 |
+
protected function _getProfileIdFromCache($customerId)
|
| 414 |
+
{
|
| 415 |
+
$profileCache = Mage::getModel('marketingsoftware/profile_cache')
|
| 416 |
+
->getCollection()
|
| 417 |
+
->addFieldToFilter('customer_id', $customerId)
|
| 418 |
+
->setPageSize(1)
|
| 419 |
+
->getFirstItem();
|
| 420 |
+
|
| 421 |
+
$profileId = $profileCache->getProfileId();
|
| 422 |
+
|
| 423 |
+
if (!is_null($profileId)) {
|
| 424 |
+
return $profileId;
|
| 425 |
+
}
|
| 426 |
+
}
|
| 427 |
+
}
|
app/code/community/Copernica/MarketingSoftware/Helper/Api/Builder.php
CHANGED
|
@@ -1,243 +1,243 @@
|
|
| 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 |
-
* This class will assist in any creation process performed on API.
|
| 29 |
-
*/
|
| 30 |
-
class Copernica_MarketingSoftware_Helper_Api_Builder extends Copernica_MarketingSoftware_Helper_Api_Abstract
|
| 31 |
-
{
|
| 32 |
-
/**
|
| 33 |
-
* Will create proper database in Copernica platform
|
| 34 |
-
*
|
| 35 |
-
* @param string $databaseName
|
| 36 |
-
*/
|
| 37 |
-
public function createDatabase($databaseName)
|
| 38 |
-
{
|
| 39 |
-
$data['name'] = $databaseName;
|
| 40 |
-
$data['description'] = 'Database created by magento extension.';
|
| 41 |
-
|
| 42 |
-
$this->_restRequest()->post('databases', $data);
|
| 43 |
-
|
| 44 |
-
$this->createDatabaseField($databaseName, 'customer_id', array(
|
| 45 |
-
'type' => 'text',
|
| 46 |
-
'length' => 64
|
| 47 |
-
));
|
| 48 |
-
}
|
| 49 |
-
|
| 50 |
-
/**
|
| 51 |
-
* Create field in given database.
|
| 52 |
-
* For more info about what can be supplied in $options argument go:
|
| 53 |
-
* @see https://www.copernica.com/en/support/rest/database-fields
|
| 54 |
-
*
|
| 55 |
-
* @param string $databaseName
|
| 56 |
-
* @param string $fieldName
|
| 57 |
-
* @param array $options
|
| 58 |
-
*/
|
| 59 |
-
public function createDatabaseField($databaseName, $fieldName, $options = array())
|
| 60 |
-
{
|
| 61 |
-
$options = array_merge( array ('name' => $fieldName), array('displayed' => true), $options);
|
| 62 |
-
|
| 63 |
-
$this->_restRequest()->post( 'database/'.urlencode($databaseName).'/fields', $options );
|
| 64 |
-
}
|
| 65 |
-
|
| 66 |
-
/**
|
| 67 |
-
* Helper method to create date fields.
|
| 68 |
-
*
|
| 69 |
-
* @param string $databaseName
|
| 70 |
-
* @param string $fieldName
|
| 71 |
-
*/
|
| 72 |
-
public function createDatabaseDateField($databaseName, $fieldName)
|
| 73 |
-
{
|
| 74 |
-
$options['type'] = 'date';
|
| 75 |
-
|
| 76 |
-
$this->createDatabaseField($databaseName, $fieldName, $options);
|
| 77 |
-
}
|
| 78 |
-
|
| 79 |
-
/**
|
| 80 |
-
* Helper method to create datetime fields.
|
| 81 |
-
*
|
| 82 |
-
* @param string $databaseName
|
| 83 |
-
* @param string $fieldName
|
| 84 |
-
*/
|
| 85 |
-
public function createDatabaseDatetimeField($databaseName, $fieldName)
|
| 86 |
-
{
|
| 87 |
-
$options['type'] = 'datetime';
|
| 88 |
-
|
| 89 |
-
$this->createDatabaseField($databaseName, $fieldName, $options);
|
| 90 |
-
}
|
| 91 |
-
|
| 92 |
-
/**
|
| 93 |
-
* Helper method to create email fields.
|
| 94 |
-
*
|
| 95 |
-
* @param string $databaseName
|
| 96 |
-
* @param string $fieldName
|
| 97 |
-
*/
|
| 98 |
-
public function createDatabaseEmailField($databaseName, $fieldName)
|
| 99 |
-
{
|
| 100 |
-
$options['type'] = 'email';
|
| 101 |
-
$options['length'] = 160;
|
| 102 |
-
|
| 103 |
-
$this->createDatabaseField($databaseName, $fieldName, $options);
|
| 104 |
-
}
|
| 105 |
-
|
| 106 |
-
/**
|
| 107 |
-
* Helper method to create newsletter fields.
|
| 108 |
-
*
|
| 109 |
-
* @param string $databaseName
|
| 110 |
-
* @param string $fieldName
|
| 111 |
-
*/
|
| 112 |
-
public function createDatabaseNewsletterField($databaseName, $fieldName)
|
| 113 |
-
{
|
| 114 |
-
$options['type'] = 'text';
|
| 115 |
-
|
| 116 |
-
$this->createDatabaseField($databaseName, $fieldName, $options);
|
| 117 |
-
|
| 118 |
-
$this->_restRequest()->post(
|
| 119 |
-
'database/'.urlencode($databaseName).'/unsubscribe',
|
| 120 |
-
array (
|
| 121 |
-
'behavior' => 'update',
|
| 122 |
-
'fields' => array ( $fieldName => 'unsubscribed_copernica')
|
| 123 |
-
)
|
| 124 |
-
);
|
| 125 |
-
|
| 126 |
-
$this->_restRequest()->post(
|
| 127 |
-
'database/'.urlencode($databaseName).'/callbacks',
|
| 128 |
-
array (
|
| 129 |
-
'url' => Mage::helper('marketingsoftware')->unsubscribeCallbackUrl(),
|
| 130 |
-
'method' => 'json',
|
| 131 |
-
'expression' => "profile.$fieldName == 'unsubscribed_copernica';"
|
| 132 |
-
)
|
| 133 |
-
);
|
| 134 |
-
}
|
| 135 |
-
|
| 136 |
-
/**
|
| 137 |
-
* Create collection inside given database.
|
| 138 |
-
*
|
| 139 |
-
* @param string $databaseName
|
| 140 |
-
* @param string $collectionName
|
| 141 |
-
* @param string $collectionType
|
| 142 |
-
* @throws Copernica_MarketingSoftware_Exception
|
| 143 |
-
*/
|
| 144 |
-
public function createCollection($databaseName, $collectionName, $collectionType)
|
| 145 |
-
{
|
| 146 |
-
$this->_restRequest()->post( 'database/'.urlencode($databaseName).'/collections', array ( 'name' => $collectionName ) );
|
| 147 |
-
|
| 148 |
-
$requiredFields = $this->_requiredCollectionFields($collectionType);
|
| 149 |
-
|
| 150 |
-
foreach ($requiredFields as $field) {
|
| 151 |
-
$this->createCollectionField($databaseName, $collectionName, $collectionType, $field, $field);
|
| 152 |
-
}
|
| 153 |
-
}
|
| 154 |
-
|
| 155 |
-
/**
|
| 156 |
-
* This method created collection field.
|
| 157 |
-
*
|
| 158 |
-
* @param string $databaseName
|
| 159 |
-
* @param string $collectionName
|
| 160 |
-
* @param string $collectionType
|
| 161 |
-
* @param string $copernicaName
|
| 162 |
-
* @param string $magentoName
|
| 163 |
-
* @throws Copernica_MarketingSoftware_Exception
|
| 164 |
-
*/
|
| 165 |
-
public function createCollectionField($databaseName, $collectionName, $collectionType, $copernicaName, $magentoName)
|
| 166 |
-
{
|
| 167 |
-
$fieldDefinition = Mage::helper('marketingsoftware/data')->getCollectionFieldDefinition($collectionType, $magentoName);
|
| 168 |
-
|
| 169 |
-
$fieldDefinition = array_merge(array ('displayed' => true), $fieldDefinition);
|
| 170 |
-
|
| 171 |
-
$collectionId = $this->_getCollectionIdFromDatabase($databaseName, $collectionName);
|
| 172 |
-
|
| 173 |
-
$this->_restRequest()->post( 'collection/'.$collectionId.'/fields', array_merge($fieldDefinition, array(
|
| 174 |
-
'name' => $copernicaName
|
| 175 |
-
)));
|
| 176 |
-
}
|
| 177 |
-
|
| 178 |
-
/**
|
| 179 |
-
* Get collection Id by it's name and database name that it's in.
|
| 180 |
-
*
|
| 181 |
-
* @param string $databaseName
|
| 182 |
-
* @param string $collectionName
|
| 183 |
-
* @return numeric
|
| 184 |
-
* @throws Copernica_MarketingSoftware_Exception
|
| 185 |
-
*/
|
| 186 |
-
protected function _getCollectionIdFromDatabase($databaseName, $collectionName)
|
| 187 |
-
{
|
| 188 |
-
$output = $this->_restRequest()->get('database/'. urlencode($databaseName) .'/collections');
|
| 189 |
-
|
| 190 |
-
if (isset($output['error'])) {
|
| 191 |
-
if (strpos($output['error']['message'], 'No database') !== false) {
|
| 192 |
-
throw Mage::exception('Copernica_MarketingSoftware', 'No database', Copernica_MarketingSoftware_Exception::DATABASE_NOT_EXISTS);
|
| 193 |
-
} else {
|
| 194 |
-
throw Mage::exception('Copernica_MarketingSoftware', $output['message'], Copernica_MarketingSoftware_Exception::API_REQUEST_ERROR);
|
| 195 |
-
}
|
| 196 |
-
} else if (!is_array($output['data'])) {
|
| 197 |
-
throw Mage::exception('Copernica_MarketingSoftware', 'Unknown error' ,Copernica_MarketingSoftware_Exception::API_REQUEST_ERROR);
|
| 198 |
-
}
|
| 199 |
-
|
| 200 |
-
$collectionId = false;
|
| 201 |
-
|
| 202 |
-
foreach ($output['data'] as $collection) {
|
| 203 |
-
if ($collection['name'] == $collectionName) {
|
| 204 |
-
$collectionId = $collection['ID'];
|
| 205 |
-
}
|
| 206 |
-
}
|
| 207 |
-
|
| 208 |
-
if ($collectionId === false) {
|
| 209 |
-
throw Mage::exception('Copernica_MarketingSoftware', 'Collection does not exists', Copernica_MarketingSoftware_Exception::COLLECTION_NOT_EXISTS);
|
| 210 |
-
}
|
| 211 |
-
|
| 212 |
-
return $collectionId;
|
| 213 |
-
}
|
| 214 |
-
|
| 215 |
-
/**
|
| 216 |
-
* Get required fields for a collection of given type.
|
| 217 |
-
*
|
| 218 |
-
* @param string $collectionType
|
| 219 |
-
* @return array
|
| 220 |
-
*/
|
| 221 |
-
protected function _requiredCollectionFields($collectionType)
|
| 222 |
-
{
|
| 223 |
-
switch ($collectionType) {
|
| 224 |
-
case 'cartproducts':
|
| 225 |
-
return Mage::helper('marketingsoftware')->requiredQuoteItemFields();
|
| 226 |
-
|
| 227 |
-
case 'orders' :
|
| 228 |
-
return Mage::helper('marketingsoftware')->requiredOrderFields();
|
| 229 |
-
|
| 230 |
-
case 'orderproducts':
|
| 231 |
-
return Mage::helper('marketingsoftware')->requiredOrderItemFields();
|
| 232 |
-
|
| 233 |
-
case 'addresses':
|
| 234 |
-
return Mage::helper('marketingsoftware')->requiredAddressFields();
|
| 235 |
-
|
| 236 |
-
case 'viewedproducts':
|
| 237 |
-
return Mage::helper('marketingsoftware')->requiredViewedProductFields();
|
| 238 |
-
|
| 239 |
-
case 'wishlistproducts':
|
| 240 |
-
return Mage::helper('marketingsoftware')->requiredWishlistItemFields();
|
| 241 |
-
}
|
| 242 |
-
}
|
| 243 |
-
}
|
| 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 |
+
* This class will assist in any creation process performed on API.
|
| 29 |
+
*/
|
| 30 |
+
class Copernica_MarketingSoftware_Helper_Api_Builder extends Copernica_MarketingSoftware_Helper_Api_Abstract
|
| 31 |
+
{
|
| 32 |
+
/**
|
| 33 |
+
* Will create proper database in Copernica platform
|
| 34 |
+
*
|
| 35 |
+
* @param string $databaseName
|
| 36 |
+
*/
|
| 37 |
+
public function createDatabase($databaseName)
|
| 38 |
+
{
|
| 39 |
+
$data['name'] = $databaseName;
|
| 40 |
+
$data['description'] = 'Database created by magento extension.';
|
| 41 |
+
|
| 42 |
+
$this->_restRequest()->post('databases', $data);
|
| 43 |
+
|
| 44 |
+
$this->createDatabaseField($databaseName, 'customer_id', array(
|
| 45 |
+
'type' => 'text',
|
| 46 |
+
'length' => 64
|
| 47 |
+
));
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
/**
|
| 51 |
+
* Create field in given database.
|
| 52 |
+
* For more info about what can be supplied in $options argument go:
|
| 53 |
+
* @see https://www.copernica.com/en/support/rest/database-fields
|
| 54 |
+
*
|
| 55 |
+
* @param string $databaseName
|
| 56 |
+
* @param string $fieldName
|
| 57 |
+
* @param array $options
|
| 58 |
+
*/
|
| 59 |
+
public function createDatabaseField($databaseName, $fieldName, $options = array())
|
| 60 |
+
{
|
| 61 |
+
$options = array_merge( array ('name' => $fieldName), array('displayed' => true), $options);
|
| 62 |
+
|
| 63 |
+
$this->_restRequest()->post( 'database/'.urlencode($databaseName).'/fields', $options );
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
/**
|
| 67 |
+
* Helper method to create date fields.
|
| 68 |
+
*
|
| 69 |
+
* @param string $databaseName
|
| 70 |
+
* @param string $fieldName
|
| 71 |
+
*/
|
| 72 |
+
public function createDatabaseDateField($databaseName, $fieldName)
|
| 73 |
+
{
|
| 74 |
+
$options['type'] = 'date';
|
| 75 |
+
|
| 76 |
+
$this->createDatabaseField($databaseName, $fieldName, $options);
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
/**
|
| 80 |
+
* Helper method to create datetime fields.
|
| 81 |
+
*
|
| 82 |
+
* @param string $databaseName
|
| 83 |
+
* @param string $fieldName
|
| 84 |
+
*/
|
| 85 |
+
public function createDatabaseDatetimeField($databaseName, $fieldName)
|
| 86 |
+
{
|
| 87 |
+
$options['type'] = 'datetime';
|
| 88 |
+
|
| 89 |
+
$this->createDatabaseField($databaseName, $fieldName, $options);
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
/**
|
| 93 |
+
* Helper method to create email fields.
|
| 94 |
+
*
|
| 95 |
+
* @param string $databaseName
|
| 96 |
+
* @param string $fieldName
|
| 97 |
+
*/
|
| 98 |
+
public function createDatabaseEmailField($databaseName, $fieldName)
|
| 99 |
+
{
|
| 100 |
+
$options['type'] = 'email';
|
| 101 |
+
$options['length'] = 160;
|
| 102 |
+
|
| 103 |
+
$this->createDatabaseField($databaseName, $fieldName, $options);
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
/**
|
| 107 |
+
* Helper method to create newsletter fields.
|
| 108 |
+
*
|
| 109 |
+
* @param string $databaseName
|
| 110 |
+
* @param string $fieldName
|
| 111 |
+
*/
|
| 112 |
+
public function createDatabaseNewsletterField($databaseName, $fieldName)
|
| 113 |
+
{
|
| 114 |
+
$options['type'] = 'text';
|
| 115 |
+
|
| 116 |
+
$this->createDatabaseField($databaseName, $fieldName, $options);
|
| 117 |
+
|
| 118 |
+
$this->_restRequest()->post(
|
| 119 |
+
'database/'.urlencode($databaseName).'/unsubscribe',
|
| 120 |
+
array (
|
| 121 |
+
'behavior' => 'update',
|
| 122 |
+
'fields' => array ( $fieldName => 'unsubscribed_copernica')
|
| 123 |
+
)
|
| 124 |
+
);
|
| 125 |
+
|
| 126 |
+
$this->_restRequest()->post(
|
| 127 |
+
'database/'.urlencode($databaseName).'/callbacks',
|
| 128 |
+
array (
|
| 129 |
+
'url' => Mage::helper('marketingsoftware')->unsubscribeCallbackUrl(),
|
| 130 |
+
'method' => 'json',
|
| 131 |
+
'expression' => "profile.$fieldName == 'unsubscribed_copernica';"
|
| 132 |
+
)
|
| 133 |
+
);
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
/**
|
| 137 |
+
* Create collection inside given database.
|
| 138 |
+
*
|
| 139 |
+
* @param string $databaseName
|
| 140 |
+
* @param string $collectionName
|
| 141 |
+
* @param string $collectionType
|
| 142 |
+
* @throws Copernica_MarketingSoftware_Exception
|
| 143 |
+
*/
|
| 144 |
+
public function createCollection($databaseName, $collectionName, $collectionType)
|
| 145 |
+
{
|
| 146 |
+
$this->_restRequest()->post( 'database/'.urlencode($databaseName).'/collections', array ( 'name' => $collectionName ) );
|
| 147 |
+
|
| 148 |
+
$requiredFields = $this->_requiredCollectionFields($collectionType);
|
| 149 |
+
|
| 150 |
+
foreach ($requiredFields as $field) {
|
| 151 |
+
$this->createCollectionField($databaseName, $collectionName, $collectionType, $field, $field);
|
| 152 |
+
}
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
/**
|
| 156 |
+
* This method created collection field.
|
| 157 |
+
*
|
| 158 |
+
* @param string $databaseName
|
| 159 |
+
* @param string $collectionName
|
| 160 |
+
* @param string $collectionType
|
| 161 |
+
* @param string $copernicaName
|
| 162 |
+
* @param string $magentoName
|
| 163 |
+
* @throws Copernica_MarketingSoftware_Exception
|
| 164 |
+
*/
|
| 165 |
+
public function createCollectionField($databaseName, $collectionName, $collectionType, $copernicaName, $magentoName)
|
| 166 |
+
{
|
| 167 |
+
$fieldDefinition = Mage::helper('marketingsoftware/data')->getCollectionFieldDefinition($collectionType, $magentoName);
|
| 168 |
+
|
| 169 |
+
$fieldDefinition = array_merge(array ('displayed' => true), $fieldDefinition);
|
| 170 |
+
|
| 171 |
+
$collectionId = $this->_getCollectionIdFromDatabase($databaseName, $collectionName);
|
| 172 |
+
|
| 173 |
+
$this->_restRequest()->post( 'collection/'.$collectionId.'/fields', array_merge($fieldDefinition, array(
|
| 174 |
+
'name' => $copernicaName
|
| 175 |
+
)));
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
/**
|
| 179 |
+
* Get collection Id by it's name and database name that it's in.
|
| 180 |
+
*
|
| 181 |
+
* @param string $databaseName
|
| 182 |
+
* @param string $collectionName
|
| 183 |
+
* @return numeric
|
| 184 |
+
* @throws Copernica_MarketingSoftware_Exception
|
| 185 |
+
*/
|
| 186 |
+
protected function _getCollectionIdFromDatabase($databaseName, $collectionName)
|
| 187 |
+
{
|
| 188 |
+
$output = $this->_restRequest()->get('database/'. urlencode($databaseName) .'/collections');
|
| 189 |
+
|
| 190 |
+
if (isset($output['error'])) {
|
| 191 |
+
if (strpos($output['error']['message'], 'No database') !== false) {
|
| 192 |
+
throw Mage::exception('Copernica_MarketingSoftware', 'No database', Copernica_MarketingSoftware_Exception::DATABASE_NOT_EXISTS);
|
| 193 |
+
} else {
|
| 194 |
+
throw Mage::exception('Copernica_MarketingSoftware', $output['message'], Copernica_MarketingSoftware_Exception::API_REQUEST_ERROR);
|
| 195 |
+
}
|
| 196 |
+
} else if (!is_array($output['data'])) {
|
| 197 |
+
throw Mage::exception('Copernica_MarketingSoftware', 'Unknown error' ,Copernica_MarketingSoftware_Exception::API_REQUEST_ERROR);
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
$collectionId = false;
|
| 201 |
+
|
| 202 |
+
foreach ($output['data'] as $collection) {
|
| 203 |
+
if ($collection['name'] == $collectionName) {
|
| 204 |
+
$collectionId = $collection['ID'];
|
| 205 |
+
}
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
if ($collectionId === false) {
|
| 209 |
+
throw Mage::exception('Copernica_MarketingSoftware', 'Collection does not exists', Copernica_MarketingSoftware_Exception::COLLECTION_NOT_EXISTS);
|
| 210 |
+
}
|
| 211 |
+
|
| 212 |
+
return $collectionId;
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
+
/**
|
| 216 |
+
* Get required fields for a collection of given type.
|
| 217 |
+
*
|
| 218 |
+
* @param string $collectionType
|
| 219 |
+
* @return array
|
| 220 |
+
*/
|
| 221 |
+
protected function _requiredCollectionFields($collectionType)
|
| 222 |
+
{
|
| 223 |
+
switch ($collectionType) {
|
| 224 |
+
case 'cartproducts':
|
| 225 |
+
return Mage::helper('marketingsoftware')->requiredQuoteItemFields();
|
| 226 |
+
|
| 227 |
+
case 'orders' :
|
| 228 |
+
return Mage::helper('marketingsoftware')->requiredOrderFields();
|
| 229 |
+
|
| 230 |
+
case 'orderproducts':
|
| 231 |
+
return Mage::helper('marketingsoftware')->requiredOrderItemFields();
|
| 232 |
+
|
| 233 |
+
case 'addresses':
|
| 234 |
+
return Mage::helper('marketingsoftware')->requiredAddressFields();
|
| 235 |
+
|
| 236 |
+
case 'viewedproducts':
|
| 237 |
+
return Mage::helper('marketingsoftware')->requiredViewedProductFields();
|
| 238 |
+
|
| 239 |
+
case 'wishlistproducts':
|
| 240 |
+
return Mage::helper('marketingsoftware')->requiredWishlistItemFields();
|
| 241 |
+
}
|
| 242 |
+
}
|
| 243 |
+
}
|
app/code/community/Copernica/MarketingSoftware/Helper/Api/Validator.php
CHANGED
|
@@ -1,382 +1,382 @@
|
|
| 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 |
-
* Copernica API validator.
|
| 29 |
-
* This class holds methods that should validate structures connected to API.
|
| 30 |
-
*/
|
| 31 |
-
class Copernica_MarketingSoftware_Helper_Api_Validator extends Copernica_MarketingSoftware_Helper_Api_Abstract
|
| 32 |
-
{
|
| 33 |
-
/**
|
| 34 |
-
* Validate database. When something is wrong this method will throw
|
| 35 |
-
* custom exception to report that.
|
| 36 |
-
*
|
| 37 |
-
* @param string $databaseName
|
| 38 |
-
* @throws Copernica_MarketingSoftware_Exception
|
| 39 |
-
*/
|
| 40 |
-
public function validateDatabase($databaseName)
|
| 41 |
-
{
|
| 42 |
-
$output = $this->_restRequest()->get( 'database/'.urlencode($databaseName) );
|
| 43 |
-
|
| 44 |
-
if (isset($output['error']) || !isset($output['name'])) {
|
| 45 |
-
if (strpos($output['error']['message'], 'No database') !== false) {
|
| 46 |
-
throw Mage::exception('Copernica_MarketingSoftware', 'Database does not exists', Copernica_MarketingSoftware_Exception::DATABASE_NOT_EXISTS);
|
| 47 |
-
} else {
|
| 48 |
-
throw Mage::exception('Copernica_MarketingSoftware', 'Database could not be checked', Copernica_MarketingSoftware_Exception::API_REQUEST_ERROR);
|
| 49 |
-
}
|
| 50 |
-
}
|
| 51 |
-
|
| 52 |
-
foreach ($output['fields']['data'] as $field) {
|
| 53 |
-
if ($field['name'] == 'customer_id') {
|
| 54 |
-
return;
|
| 55 |
-
}
|
| 56 |
-
}
|
| 57 |
-
|
| 58 |
-
throw Mage::exception('Copernica_MarketingSoftware', 'Database does not have required customer_id field', Copernica_MarketingSoftware_Exception::DATABASE_STRUCT_INVALID);
|
| 59 |
-
}
|
| 60 |
-
|
| 61 |
-
/**
|
| 62 |
-
* Validate database field.
|
| 63 |
-
*
|
| 64 |
-
* @param string $databaseName
|
| 65 |
-
* @param string $fieldName
|
| 66 |
-
* @param string $magentoField
|
| 67 |
-
* @throws Copernica_MarketingSoftware_Exception
|
| 68 |
-
*/
|
| 69 |
-
public function validateDatabaseField($databaseName, $fieldName, $magentoField)
|
| 70 |
-
{
|
| 71 |
-
if (trim($fieldName) == '') {
|
| 72 |
-
throw Mage::exception('Copernica_MarketingSoftware', 'Field not linked', Copernica_MarketingSoftware_Exception::FIELD_NOT_LINKED);
|
| 73 |
-
}
|
| 74 |
-
|
| 75 |
-
$output = $this->_restRequest()->get('database/'.urlencode($databaseName).'/fields');
|
| 76 |
-
|
| 77 |
-
if (isset($output['error'])) {
|
| 78 |
-
if (strpos($output['error']['message'], 'No database') !== false) {
|
| 79 |
-
throw Mage::exception('Copernica_MarketingSoftware', 'Database does not exists', Copernica_MarketingSoftware_Exception::DATABASE_NOT_EXISTS);
|
| 80 |
-
} else {
|
| 81 |
-
throw Mage::exception('Copernica_MarketingSoftware', 'Database could not be checked', Copernica_MarketingSoftware_Exception::API_REQUEST_ERROR);
|
| 82 |
-
}
|
| 83 |
-
}
|
| 84 |
-
|
| 85 |
-
foreach ($output['data'] as $field) {
|
| 86 |
-
if ($field['name'] != $fieldName) {
|
| 87 |
-
continue;
|
| 88 |
-
}
|
| 89 |
-
|
| 90 |
-
if (!$this->_checkDatabaseFieldType($magentoField, $field, $databaseName)) {
|
| 91 |
-
throw Mage::exception('Copernica_MarketingSoftware', 'Field is invalid', Copernica_MarketingSoftware_Exception::FIELD_STRUCT_INVALID);
|
| 92 |
-
}
|
| 93 |
-
|
| 94 |
-
return;
|
| 95 |
-
}
|
| 96 |
-
|
| 97 |
-
throw Mage::exception('Copernica_MarketingSoftware', 'Field does not exists', Copernica_MarketingSoftware_Exception::FIELD_NOT_EXISTS);
|
| 98 |
-
}
|
| 99 |
-
|
| 100 |
-
/**
|
| 101 |
-
* Validate collection.
|
| 102 |
-
*
|
| 103 |
-
* @param string $databaseName
|
| 104 |
-
* @param string $collectionName
|
| 105 |
-
* @param string $collectionType
|
| 106 |
-
* @throws Copenica_MarketingSoftware_Exception
|
| 107 |
-
*/
|
| 108 |
-
public function validateCollection($databaseName, $collectionName, $collectionType)
|
| 109 |
-
{
|
| 110 |
-
$output = $this->_restRequest()->get('database/'.$databaseName.'/collections');
|
| 111 |
-
|
| 112 |
-
if (isset($output['error'])) {
|
| 113 |
-
if (strpos($output['error']['message'], 'No database') !== false) {
|
| 114 |
-
throw Mage::exception('Copernica_MarketingSoftware', 'Database does not exists', Copernica_MarketingSoftware_Exception::DATABASE_NOT_EXISTS);
|
| 115 |
-
} else {
|
| 116 |
-
throw Mage::exception('Copernica_MarketingSoftware', 'Collection could not be checked', Copernica_MarketingSoftware_Exception::API_REQUEST_ERROR);
|
| 117 |
-
}
|
| 118 |
-
}
|
| 119 |
-
|
| 120 |
-
if ($output['total'] == 0) {
|
| 121 |
-
throw Mage::exception('Copernica_MarketingSoftware', 'Collection does not exists', Copernica_MarketingSoftware_Exception::COLLECTION_NOT_EXISTS);
|
| 122 |
-
}
|
| 123 |
-
|
| 124 |
-
foreach ($output['data'] as $collection) {
|
| 125 |
-
if ($collection['name'] != $collectionName) {
|
| 126 |
-
continue;
|
| 127 |
-
}
|
| 128 |
-
|
| 129 |
-
if ($this->_isCollectionFieldsValid($collection['fields'], $collectionType)) {
|
| 130 |
-
return;
|
| 131 |
-
}
|
| 132 |
-
|
| 133 |
-
throw Mage::exception('Copernica_MarketingSoftware', 'Collection structure is invalid.', Copernica_MarketingSoftware_Exception::COLLECTION_STRUCT_INVALID);
|
| 134 |
-
}
|
| 135 |
-
|
| 136 |
-
throw Mage::exception('Copernica_MarketingSoftware', 'Collection does not exists', Copernica_MarketingSoftware_Exception::COLLECTION_NOT_EXISTS);
|
| 137 |
-
}
|
| 138 |
-
|
| 139 |
-
/**
|
| 140 |
-
* Check collection field structure.
|
| 141 |
-
*
|
| 142 |
-
* @param assoc $collectionFieldStruct
|
| 143 |
-
* @param string $collectionType
|
| 144 |
-
* @return bool
|
| 145 |
-
*/
|
| 146 |
-
protected function _isCollectionFieldsValid($collectionFieldStruct, $collectionType)
|
| 147 |
-
{
|
| 148 |
-
$requiredFields = $this->_requiredCollectionFields($collectionType);
|
| 149 |
-
|
| 150 |
-
$collectionFields = array();
|
| 151 |
-
|
| 152 |
-
foreach ($collectionFieldStruct['data'] as $field) {
|
| 153 |
-
$collectionFields[] = $field['name'];
|
| 154 |
-
}
|
| 155 |
-
|
| 156 |
-
if (count(array_intersect($collectionFields, $requiredFields)) == count($requiredFields)) {
|
| 157 |
-
return true;
|
| 158 |
-
}
|
| 159 |
-
|
| 160 |
-
return false;
|
| 161 |
-
}
|
| 162 |
-
|
| 163 |
-
/**
|
| 164 |
-
* Validate collection field.
|
| 165 |
-
*
|
| 166 |
-
* @param string $databaseName
|
| 167 |
-
* @param string $collectionName
|
| 168 |
-
* @param string $collectionType
|
| 169 |
-
* @param string $magentoFieldName
|
| 170 |
-
* @param string $copernicaFieldName
|
| 171 |
-
* @throws Copernica_MarketingSoftware_Exception
|
| 172 |
-
*/
|
| 173 |
-
public function validateCollectionField($databaseName, $collectionName, $collectionType, $magentoFieldName, $copernicaFieldName)
|
| 174 |
-
{
|
| 175 |
-
$output = $this->_restRequest()->get(
|
| 176 |
-
'database/'.$databaseName.'/collections'
|
| 177 |
-
);
|
| 178 |
-
|
| 179 |
-
if (isset($output['error'])) {
|
| 180 |
-
if (strpos($output['error']['message'], 'No database') !== false) {
|
| 181 |
-
throw Mage::exception('Copernica_MarketingSoftware', 'Database does not exists', Copernica_MarketingSoftware_Exception::DATABASE_NOT_EXISTS);
|
| 182 |
-
} else {
|
| 183 |
-
throw Mage::exception('Copernica_MarketingSoftware', 'API error', Copernica_MarketingSoftware_Exception::API_REQUEST_ERROR);
|
| 184 |
-
}
|
| 185 |
-
}
|
| 186 |
-
|
| 187 |
-
if ($output['total'] == 0) {
|
| 188 |
-
throw Mage::exception('Copernica_MarketingSoftware', 'Collection does not exists', Copernica_MarketingSoftware_Exception::COLLECTION_NOT_EXISTS);
|
| 189 |
-
}
|
| 190 |
-
|
| 191 |
-
$collectionId = false;
|
| 192 |
-
|
| 193 |
-
foreach ($output['data'] as $collection) {
|
| 194 |
-
if ($collection['name'] == $collectionName) {
|
| 195 |
-
$collectionId = $collection['ID'];
|
| 196 |
-
}
|
| 197 |
-
}
|
| 198 |
-
|
| 199 |
-
if ($collectionId === false) {
|
| 200 |
-
throw Mage::exception('Copernica_MarketingSoftware', 'Collection does not exits', Copernica_MarketingSoftware_Exception::COLLECTION_NOT_EXISTS);
|
| 201 |
-
}
|
| 202 |
-
|
| 203 |
-
$output = $this->_restRequest()->get( 'collection/'.$collectionId.'/fields' );
|
| 204 |
-
|
| 205 |
-
if (isset($output['error']) || !isset($output['data'])) {
|
| 206 |
-
throw Mage::exception('Copernica_MarketingSoftware', 'API error', Copernica_MarketingSoftware_Exception::API_REQUEST_ERROR);
|
| 207 |
-
}
|
| 208 |
-
|
| 209 |
-
if ($output['total'] == 0) {
|
| 210 |
-
throw Mage::exception('Copernica_MarketingSoftware', 'Field does not exists', Copernica_MarketingSoftware_Exception::FIELD_NOT_EXISTS);
|
| 211 |
-
}
|
| 212 |
-
|
| 213 |
-
foreach ($output['data'] as $field) {
|
| 214 |
-
if ($field['name'] != $copernicaFieldName) {
|
| 215 |
-
continue;
|
| 216 |
-
}
|
| 217 |
-
|
| 218 |
-
$fieldDefinition = Mage::helper('marketingsoftware/data')->getCollectionFieldDefinition($collectionType, $magentoFieldName);
|
| 219 |
-
|
| 220 |
-
if ($fieldDefinition['type'] != $field['type']) {
|
| 221 |
-
throw Mage::exception('Copernica_MarketingSoftware', 'Field has invalid structure. Field should have \''.$fieldDefinition['type'].'\' type.', Copernica_MarketingSoftware_Exception::FIELD_STRUCT_INVALID);
|
| 222 |
-
}
|
| 223 |
-
|
| 224 |
-
return;
|
| 225 |
-
}
|
| 226 |
-
|
| 227 |
-
throw Mage::exception('Copernica_MarketingSoftware', 'Field does not exists', Copernica_MarketingSoftware_Exception::FIELD_NOT_EXISTS);
|
| 228 |
-
}
|
| 229 |
-
|
| 230 |
-
/**
|
| 231 |
-
* Get required fields for a collection of given type.
|
| 232 |
-
*
|
| 233 |
-
* @param string $collectionType
|
| 234 |
-
* @return array
|
| 235 |
-
*/
|
| 236 |
-
protected function _requiredCollectionFields($collectionType)
|
| 237 |
-
{
|
| 238 |
-
switch ($collectionType)
|
| 239 |
-
{
|
| 240 |
-
case 'cartproducts':
|
| 241 |
-
return Mage::helper('marketingsoftware')->requiredQuoteItemFields();
|
| 242 |
-
|
| 243 |
-
case 'orders' :
|
| 244 |
-
return Mage::helper('marketingsoftware')->requiredOrderFields();
|
| 245 |
-
|
| 246 |
-
case 'orderproducts':
|
| 247 |
-
return Mage::helper('marketingsoftware')->requiredOrderItemFields();
|
| 248 |
-
|
| 249 |
-
case 'addresses':
|
| 250 |
-
return Mage::helper('marketingsoftware')->requiredAddressFields();
|
| 251 |
-
|
| 252 |
-
case 'viewedproduct':
|
| 253 |
-
return Mage::helper('marketingsoftware')->requiredViewedProductFields();
|
| 254 |
-
|
| 255 |
-
case 'wishlistproducts':
|
| 256 |
-
return Mage::helper('marketingsoftware')->requiredWishlistItemFields();
|
| 257 |
-
|
| 258 |
-
default:
|
| 259 |
-
return array();
|
| 260 |
-
}
|
| 261 |
-
}
|
| 262 |
-
|
| 263 |
-
/**
|
| 264 |
-
* Check database field if copernica type match magento type.
|
| 265 |
-
*
|
| 266 |
-
* @param string $magentoField
|
| 267 |
-
* @param assoc $copernicaStructure
|
| 268 |
-
* @param string $databaseName
|
| 269 |
-
* @return boolean
|
| 270 |
-
*/
|
| 271 |
-
protected function _checkDatabaseFieldType($magentoField, $copernicaStructure, $databaseName)
|
| 272 |
-
{
|
| 273 |
-
switch ($magentoField) {
|
| 274 |
-
case 'email' :
|
| 275 |
-
return $this->_checkEmailField($copernicaStructure);
|
| 276 |
-
|
| 277 |
-
case 'newsletter':
|
| 278 |
-
return $this->_checkNewsletterField($copernicaStructure, $databaseName);
|
| 279 |
-
|
| 280 |
-
case 'birthdate':
|
| 281 |
-
return $this->_checkDateField($copernicaStructure);
|
| 282 |
-
|
| 283 |
-
case 'registrationDate':
|
| 284 |
-
return $this->_checkDatetimeField($copernicaStructure);
|
| 285 |
-
|
| 286 |
-
default:
|
| 287 |
-
return $this->_checkDefaultField($copernicaStructure);
|
| 288 |
-
}
|
| 289 |
-
}
|
| 290 |
-
|
| 291 |
-
/**
|
| 292 |
-
* Check if newsletter field is correct
|
| 293 |
-
*
|
| 294 |
-
* @return boolean
|
| 295 |
-
*/
|
| 296 |
-
protected function _checkNewsletterField($copernicaStructure, $databaseName)
|
| 297 |
-
{
|
| 298 |
-
$databaseUnsubscribe = $this->_restRequest()->get('database/'.urlencode($databaseName).'/unsubscribe');
|
| 299 |
-
|
| 300 |
-
if (isset($databaseUnsubscribe['error'])) {
|
| 301 |
-
throw Mage::exception('Copernica_MarketingSoftware', 'Field could not be checked', Copernica_MarketingSoftware_Exception::API_REQUEST_ERROR);
|
| 302 |
-
}
|
| 303 |
-
|
| 304 |
-
if ($databaseUnsubscribe['behavior'] != 'update') {
|
| 305 |
-
return false;
|
| 306 |
-
}
|
| 307 |
-
|
| 308 |
-
$fieldName = $copernicaStructure['name'];
|
| 309 |
-
|
| 310 |
-
if (!array_key_exists($fieldName, $databaseUnsubscribe['fields'])) {
|
| 311 |
-
return false;
|
| 312 |
-
}
|
| 313 |
-
|
| 314 |
-
if ($databaseUnsubscribe['fields'][$fieldName] != 'unsubscribed_copernica') {
|
| 315 |
-
return false;
|
| 316 |
-
}
|
| 317 |
-
|
| 318 |
-
$databaseCallbacks = $this->_restRequest()->get('database/'.urlencode($databaseName).'/callbacks');
|
| 319 |
-
|
| 320 |
-
if (isset($databaseCallbacks['error'])) {
|
| 321 |
-
throw Mage::exception('Copernica_MarketingSoftware', 'Field could not be checked', Copernica_MarketingSoftware_Exception::API_REQUEST_ERROR);
|
| 322 |
-
}
|
| 323 |
-
|
| 324 |
-
$callbackUrl = Mage::helper('marketingsoftware')->unsubscribeCallbackUrl();
|
| 325 |
-
|
| 326 |
-
if ($databaseCallbacks['total'] == 0) {
|
| 327 |
-
return false;
|
| 328 |
-
}
|
| 329 |
-
|
| 330 |
-
foreach ($databaseCallbacks['data'] as $callback) {
|
| 331 |
-
if ($callback['url'] == $callbackUrl && $callback['method'] == 'json' && $callback['expression'] == "profile.$fieldName == 'unsubscribed_copernica';") {
|
| 332 |
-
return true;
|
| 333 |
-
}
|
| 334 |
-
}
|
| 335 |
-
|
| 336 |
-
return false;
|
| 337 |
-
}
|
| 338 |
-
|
| 339 |
-
/**
|
| 340 |
-
* Check field if it's a email field.
|
| 341 |
-
*
|
| 342 |
-
* @param assoc $copernicaStructure
|
| 343 |
-
* @return boolean
|
| 344 |
-
*/
|
| 345 |
-
protected function _checkEmailField($copernicaStructure)
|
| 346 |
-
{
|
| 347 |
-
return $copernicaStructure['type'] == 'email';
|
| 348 |
-
}
|
| 349 |
-
|
| 350 |
-
/**
|
| 351 |
-
* Check field if it's a date field.
|
| 352 |
-
*
|
| 353 |
-
* @param assoc $copernicaStructure
|
| 354 |
-
* @return boolean
|
| 355 |
-
*/
|
| 356 |
-
protected function _checkDateField($copernicaStructure)
|
| 357 |
-
{
|
| 358 |
-
return $copernicaStructure['type'] == 'date';
|
| 359 |
-
}
|
| 360 |
-
|
| 361 |
-
/**
|
| 362 |
-
* Check field if it's a datetime field
|
| 363 |
-
*
|
| 364 |
-
* @param assoc $copernicaStructure
|
| 365 |
-
* @return boolean
|
| 366 |
-
*/
|
| 367 |
-
protected function _checkDatetimeField($copernicaStructure)
|
| 368 |
-
{
|
| 369 |
-
return $copernicaStructure['type'] == 'datetime';
|
| 370 |
-
}
|
| 371 |
-
|
| 372 |
-
/**
|
| 373 |
-
* Check field if it's a default field.
|
| 374 |
-
*
|
| 375 |
-
* @param assoc $copernicaStructure
|
| 376 |
-
* @return boolean
|
| 377 |
-
*/
|
| 378 |
-
protected function _checkDefaultField($copernicaStructure)
|
| 379 |
-
{
|
| 380 |
-
return $copernicaStructure['type'] == 'text';
|
| 381 |
-
}
|
| 382 |
-
}
|
| 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 |
+
* Copernica API validator.
|
| 29 |
+
* This class holds methods that should validate structures connected to API.
|
| 30 |
+
*/
|
| 31 |
+
class Copernica_MarketingSoftware_Helper_Api_Validator extends Copernica_MarketingSoftware_Helper_Api_Abstract
|
| 32 |
+
{
|
| 33 |
+
/**
|
| 34 |
+
* Validate database. When something is wrong this method will throw
|
| 35 |
+
* custom exception to report that.
|
| 36 |
+
*
|
| 37 |
+
* @param string $databaseName
|
| 38 |
+
* @throws Copernica_MarketingSoftware_Exception
|
| 39 |
+
*/
|
| 40 |
+
public function validateDatabase($databaseName)
|
| 41 |
+
{
|
| 42 |
+
$output = $this->_restRequest()->get( 'database/'.urlencode($databaseName) );
|
| 43 |
+
|
| 44 |
+
if (isset($output['error']) || !isset($output['name'])) {
|
| 45 |
+
if (strpos($output['error']['message'], 'No database') !== false) {
|
| 46 |
+
throw Mage::exception('Copernica_MarketingSoftware', 'Database does not exists', Copernica_MarketingSoftware_Exception::DATABASE_NOT_EXISTS);
|
| 47 |
+
} else {
|
| 48 |
+
throw Mage::exception('Copernica_MarketingSoftware', 'Database could not be checked', Copernica_MarketingSoftware_Exception::API_REQUEST_ERROR);
|
| 49 |
+
}
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
foreach ($output['fields']['data'] as $field) {
|
| 53 |
+
if ($field['name'] == 'customer_id') {
|
| 54 |
+
return;
|
| 55 |
+
}
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
throw Mage::exception('Copernica_MarketingSoftware', 'Database does not have required customer_id field', Copernica_MarketingSoftware_Exception::DATABASE_STRUCT_INVALID);
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
/**
|
| 62 |
+
* Validate database field.
|
| 63 |
+
*
|
| 64 |
+
* @param string $databaseName
|
| 65 |
+
* @param string $fieldName
|
| 66 |
+
* @param string $magentoField
|
| 67 |
+
* @throws Copernica_MarketingSoftware_Exception
|
| 68 |
+
*/
|
| 69 |
+
public function validateDatabaseField($databaseName, $fieldName, $magentoField)
|
| 70 |
+
{
|
| 71 |
+
if (trim($fieldName) == '') {
|
| 72 |
+
throw Mage::exception('Copernica_MarketingSoftware', 'Field not linked', Copernica_MarketingSoftware_Exception::FIELD_NOT_LINKED);
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
$output = $this->_restRequest()->get('database/'.urlencode($databaseName).'/fields');
|
| 76 |
+
|
| 77 |
+
if (isset($output['error'])) {
|
| 78 |
+
if (strpos($output['error']['message'], 'No database') !== false) {
|
| 79 |
+
throw Mage::exception('Copernica_MarketingSoftware', 'Database does not exists', Copernica_MarketingSoftware_Exception::DATABASE_NOT_EXISTS);
|
| 80 |
+
} else {
|
| 81 |
+
throw Mage::exception('Copernica_MarketingSoftware', 'Database could not be checked', Copernica_MarketingSoftware_Exception::API_REQUEST_ERROR);
|
| 82 |
+
}
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
foreach ($output['data'] as $field) {
|
| 86 |
+
if ($field['name'] != $fieldName) {
|
| 87 |
+
continue;
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
if (!$this->_checkDatabaseFieldType($magentoField, $field, $databaseName)) {
|
| 91 |
+
throw Mage::exception('Copernica_MarketingSoftware', 'Field is invalid', Copernica_MarketingSoftware_Exception::FIELD_STRUCT_INVALID);
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
return;
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
throw Mage::exception('Copernica_MarketingSoftware', 'Field does not exists', Copernica_MarketingSoftware_Exception::FIELD_NOT_EXISTS);
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
/**
|
| 101 |
+
* Validate collection.
|
| 102 |
+
*
|
| 103 |
+
* @param string $databaseName
|
| 104 |
+
* @param string $collectionName
|
| 105 |
+
* @param string $collectionType
|
| 106 |
+
* @throws Copenica_MarketingSoftware_Exception
|
| 107 |
+
*/
|
| 108 |
+
public function validateCollection($databaseName, $collectionName, $collectionType)
|
| 109 |
+
{
|
| 110 |
+
$output = $this->_restRequest()->get('database/'.$databaseName.'/collections');
|
| 111 |
+
|
| 112 |
+
if (isset($output['error'])) {
|
| 113 |
+
if (strpos($output['error']['message'], 'No database') !== false) {
|
| 114 |
+
throw Mage::exception('Copernica_MarketingSoftware', 'Database does not exists', Copernica_MarketingSoftware_Exception::DATABASE_NOT_EXISTS);
|
| 115 |
+
} else {
|
| 116 |
+
throw Mage::exception('Copernica_MarketingSoftware', 'Collection could not be checked', Copernica_MarketingSoftware_Exception::API_REQUEST_ERROR);
|
| 117 |
+
}
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
if ($output['total'] == 0) {
|
| 121 |
+
throw Mage::exception('Copernica_MarketingSoftware', 'Collection does not exists', Copernica_MarketingSoftware_Exception::COLLECTION_NOT_EXISTS);
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
foreach ($output['data'] as $collection) {
|
| 125 |
+
if ($collection['name'] != $collectionName) {
|
| 126 |
+
continue;
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
if ($this->_isCollectionFieldsValid($collection['fields'], $collectionType)) {
|
| 130 |
+
return;
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
throw Mage::exception('Copernica_MarketingSoftware', 'Collection structure is invalid.', Copernica_MarketingSoftware_Exception::COLLECTION_STRUCT_INVALID);
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
throw Mage::exception('Copernica_MarketingSoftware', 'Collection does not exists', Copernica_MarketingSoftware_Exception::COLLECTION_NOT_EXISTS);
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
/**
|
| 140 |
+
* Check collection field structure.
|
| 141 |
+
*
|
| 142 |
+
* @param assoc $collectionFieldStruct
|
| 143 |
+
* @param string $collectionType
|
| 144 |
+
* @return bool
|
| 145 |
+
*/
|
| 146 |
+
protected function _isCollectionFieldsValid($collectionFieldStruct, $collectionType)
|
| 147 |
+
{
|
| 148 |
+
$requiredFields = $this->_requiredCollectionFields($collectionType);
|
| 149 |
+
|
| 150 |
+
$collectionFields = array();
|
| 151 |
+
|
| 152 |
+
foreach ($collectionFieldStruct['data'] as $field) {
|
| 153 |
+
$collectionFields[] = $field['name'];
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
if (count(array_intersect($collectionFields, $requiredFields)) == count($requiredFields)) {
|
| 157 |
+
return true;
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
return false;
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
/**
|
| 164 |
+
* Validate collection field.
|
| 165 |
+
*
|
| 166 |
+
* @param string $databaseName
|
| 167 |
+
* @param string $collectionName
|
| 168 |
+
* @param string $collectionType
|
| 169 |
+
* @param string $magentoFieldName
|
| 170 |
+
* @param string $copernicaFieldName
|
| 171 |
+
* @throws Copernica_MarketingSoftware_Exception
|
| 172 |
+
*/
|
| 173 |
+
public function validateCollectionField($databaseName, $collectionName, $collectionType, $magentoFieldName, $copernicaFieldName)
|
| 174 |
+
{
|
| 175 |
+
$output = $this->_restRequest()->get(
|
| 176 |
+
'database/'.$databaseName.'/collections'
|
| 177 |
+
);
|
| 178 |
+
|
| 179 |
+
if (isset($output['error'])) {
|
| 180 |
+
if (strpos($output['error']['message'], 'No database') !== false) {
|
| 181 |
+
throw Mage::exception('Copernica_MarketingSoftware', 'Database does not exists', Copernica_MarketingSoftware_Exception::DATABASE_NOT_EXISTS);
|
| 182 |
+
} else {
|
| 183 |
+
throw Mage::exception('Copernica_MarketingSoftware', 'API error', Copernica_MarketingSoftware_Exception::API_REQUEST_ERROR);
|
| 184 |
+
}
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
if ($output['total'] == 0) {
|
| 188 |
+
throw Mage::exception('Copernica_MarketingSoftware', 'Collection does not exists', Copernica_MarketingSoftware_Exception::COLLECTION_NOT_EXISTS);
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
$collectionId = false;
|
| 192 |
+
|
| 193 |
+
foreach ($output['data'] as $collection) {
|
| 194 |
+
if ($collection['name'] == $collectionName) {
|
| 195 |
+
$collectionId = $collection['ID'];
|
| 196 |
+
}
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
if ($collectionId === false) {
|
| 200 |
+
throw Mage::exception('Copernica_MarketingSoftware', 'Collection does not exits', Copernica_MarketingSoftware_Exception::COLLECTION_NOT_EXISTS);
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
$output = $this->_restRequest()->get( 'collection/'.$collectionId.'/fields' );
|
| 204 |
+
|
| 205 |
+
if (isset($output['error']) || !isset($output['data'])) {
|
| 206 |
+
throw Mage::exception('Copernica_MarketingSoftware', 'API error', Copernica_MarketingSoftware_Exception::API_REQUEST_ERROR);
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
if ($output['total'] == 0) {
|
| 210 |
+
throw Mage::exception('Copernica_MarketingSoftware', 'Field does not exists', Copernica_MarketingSoftware_Exception::FIELD_NOT_EXISTS);
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
foreach ($output['data'] as $field) {
|
| 214 |
+
if ($field['name'] != $copernicaFieldName) {
|
| 215 |
+
continue;
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
$fieldDefinition = Mage::helper('marketingsoftware/data')->getCollectionFieldDefinition($collectionType, $magentoFieldName);
|
| 219 |
+
|
| 220 |
+
if ($fieldDefinition['type'] != $field['type']) {
|
| 221 |
+
throw Mage::exception('Copernica_MarketingSoftware', 'Field has invalid structure. Field should have \''.$fieldDefinition['type'].'\' type.', Copernica_MarketingSoftware_Exception::FIELD_STRUCT_INVALID);
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
return;
|
| 225 |
+
}
|
| 226 |
+
|
| 227 |
+
throw Mage::exception('Copernica_MarketingSoftware', 'Field does not exists', Copernica_MarketingSoftware_Exception::FIELD_NOT_EXISTS);
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
/**
|
| 231 |
+
* Get required fields for a collection of given type.
|
| 232 |
+
*
|
| 233 |
+
* @param string $collectionType
|
| 234 |
+
* @return array
|
| 235 |
+
*/
|
| 236 |
+
protected function _requiredCollectionFields($collectionType)
|
| 237 |
+
{
|
| 238 |
+
switch ($collectionType)
|
| 239 |
+
{
|
| 240 |
+
case 'cartproducts':
|
| 241 |
+
return Mage::helper('marketingsoftware')->requiredQuoteItemFields();
|
| 242 |
+
|
| 243 |
+
case 'orders' :
|
| 244 |
+
return Mage::helper('marketingsoftware')->requiredOrderFields();
|
| 245 |
+
|
| 246 |
+
case 'orderproducts':
|
| 247 |
+
return Mage::helper('marketingsoftware')->requiredOrderItemFields();
|
| 248 |
+
|
| 249 |
+
case 'addresses':
|
| 250 |
+
return Mage::helper('marketingsoftware')->requiredAddressFields();
|
| 251 |
+
|
| 252 |
+
case 'viewedproduct':
|
| 253 |
+
return Mage::helper('marketingsoftware')->requiredViewedProductFields();
|
| 254 |
+
|
| 255 |
+
case 'wishlistproducts':
|
| 256 |
+
return Mage::helper('marketingsoftware')->requiredWishlistItemFields();
|
| 257 |
+
|
| 258 |
+
default:
|
| 259 |
+
return array();
|
| 260 |
+
}
|
| 261 |
+
}
|
| 262 |
+
|
| 263 |
+
/**
|
| 264 |
+
* Check database field if copernica type match magento type.
|
| 265 |
+
*
|
| 266 |
+
* @param string $magentoField
|
| 267 |
+
* @param assoc $copernicaStructure
|
| 268 |
+
* @param string $databaseName
|
| 269 |
+
* @return boolean
|
| 270 |
+
*/
|
| 271 |
+
protected function _checkDatabaseFieldType($magentoField, $copernicaStructure, $databaseName)
|
| 272 |
+
{
|
| 273 |
+
switch ($magentoField) {
|
| 274 |
+
case 'email' :
|
| 275 |
+
return $this->_checkEmailField($copernicaStructure);
|
| 276 |
+
|
| 277 |
+
case 'newsletter':
|
| 278 |
+
return $this->_checkNewsletterField($copernicaStructure, $databaseName);
|
| 279 |
+
|
| 280 |
+
case 'birthdate':
|
| 281 |
+
return $this->_checkDateField($copernicaStructure);
|
| 282 |
+
|
| 283 |
+
case 'registrationDate':
|
| 284 |
+
return $this->_checkDatetimeField($copernicaStructure);
|
| 285 |
+
|
| 286 |
+
default:
|
| 287 |
+
return $this->_checkDefaultField($copernicaStructure);
|
| 288 |
+
}
|
| 289 |
+
}
|
| 290 |
+
|
| 291 |
+
/**
|
| 292 |
+
* Check if newsletter field is correct
|
| 293 |
+
*
|
| 294 |
+
* @return boolean
|
| 295 |
+
*/
|
| 296 |
+
protected function _checkNewsletterField($copernicaStructure, $databaseName)
|
| 297 |
+
{
|
| 298 |
+
$databaseUnsubscribe = $this->_restRequest()->get('database/'.urlencode($databaseName).'/unsubscribe');
|
| 299 |
+
|
| 300 |
+
if (isset($databaseUnsubscribe['error'])) {
|
| 301 |
+
throw Mage::exception('Copernica_MarketingSoftware', 'Field could not be checked', Copernica_MarketingSoftware_Exception::API_REQUEST_ERROR);
|
| 302 |
+
}
|
| 303 |
+
|
| 304 |
+
if ($databaseUnsubscribe['behavior'] != 'update') {
|
| 305 |
+
return false;
|
| 306 |
+
}
|
| 307 |
+
|
| 308 |
+
$fieldName = $copernicaStructure['name'];
|
| 309 |
+
|
| 310 |
+
if (!array_key_exists($fieldName, $databaseUnsubscribe['fields'])) {
|
| 311 |
+
return false;
|
| 312 |
+
}
|
| 313 |
+
|
| 314 |
+
if ($databaseUnsubscribe['fields'][$fieldName] != 'unsubscribed_copernica') {
|
| 315 |
+
return false;
|
| 316 |
+
}
|
| 317 |
+
|
| 318 |
+
$databaseCallbacks = $this->_restRequest()->get('database/'.urlencode($databaseName).'/callbacks');
|
| 319 |
+
|
| 320 |
+
if (isset($databaseCallbacks['error'])) {
|
| 321 |
+
throw Mage::exception('Copernica_MarketingSoftware', 'Field could not be checked', Copernica_MarketingSoftware_Exception::API_REQUEST_ERROR);
|
| 322 |
+
}
|
| 323 |
+
|
| 324 |
+
$callbackUrl = Mage::helper('marketingsoftware')->unsubscribeCallbackUrl();
|
| 325 |
+
|
| 326 |
+
if ($databaseCallbacks['total'] == 0) {
|
| 327 |
+
return false;
|
| 328 |
+
}
|
| 329 |
+
|
| 330 |
+
foreach ($databaseCallbacks['data'] as $callback) {
|
| 331 |
+
if ($callback['url'] == $callbackUrl && $callback['method'] == 'json' && $callback['expression'] == "profile.$fieldName == 'unsubscribed_copernica';") {
|
| 332 |
+
return true;
|
| 333 |
+
}
|
| 334 |
+
}
|
| 335 |
+
|
| 336 |
+
return false;
|
| 337 |
+
}
|
| 338 |
+
|
| 339 |
+
/**
|
| 340 |
+
* Check field if it's a email field.
|
| 341 |
+
*
|
| 342 |
+
* @param assoc $copernicaStructure
|
| 343 |
+
* @return boolean
|
| 344 |
+
*/
|
| 345 |
+
protected function _checkEmailField($copernicaStructure)
|
| 346 |
+
{
|
| 347 |
+
return $copernicaStructure['type'] == 'email';
|
| 348 |
+
}
|
| 349 |
+
|
| 350 |
+
/**
|
| 351 |
+
* Check field if it's a date field.
|
| 352 |
+
*
|
| 353 |
+
* @param assoc $copernicaStructure
|
| 354 |
+
* @return boolean
|
| 355 |
+
*/
|
| 356 |
+
protected function _checkDateField($copernicaStructure)
|
| 357 |
+
{
|
| 358 |
+
return $copernicaStructure['type'] == 'date';
|
| 359 |
+
}
|
| 360 |
+
|
| 361 |
+
/**
|
| 362 |
+
* Check field if it's a datetime field
|
| 363 |
+
*
|
| 364 |
+
* @param assoc $copernicaStructure
|
| 365 |
+
* @return boolean
|
| 366 |
+
*/
|
| 367 |
+
protected function _checkDatetimeField($copernicaStructure)
|
| 368 |
+
{
|
| 369 |
+
return $copernicaStructure['type'] == 'datetime';
|
| 370 |
+
}
|
| 371 |
+
|
| 372 |
+
/**
|
| 373 |
+
* Check field if it's a default field.
|
| 374 |
+
*
|
| 375 |
+
* @param assoc $copernicaStructure
|
| 376 |
+
* @return boolean
|
| 377 |
+
*/
|
| 378 |
+
protected function _checkDefaultField($copernicaStructure)
|
| 379 |
+
{
|
| 380 |
+
return $copernicaStructure['type'] == 'text';
|
| 381 |
+
}
|
| 382 |
+
}
|
app/code/community/Copernica/MarketingSoftware/Helper/Config.php
CHANGED
|
@@ -1,1224 +1,1224 @@
|
|
| 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 |
-
* Copernica config helper
|
| 29 |
-
*
|
| 30 |
-
* @todo check if this clas can be better...
|
| 31 |
-
*/
|
| 32 |
-
class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstract
|
| 33 |
-
{
|
| 34 |
-
/**
|
| 35 |
-
* Define a prefix used for the config
|
| 36 |
-
*
|
| 37 |
-
* @name CONFIG_BASE
|
| 38 |
-
*/
|
| 39 |
-
const CONFIG_BASE = 'marketingsoftware/';
|
| 40 |
-
|
| 41 |
-
/**
|
| 42 |
-
* Holds a list of previously requested key names
|
| 43 |
-
*
|
| 44 |
-
* @var array
|
| 45 |
-
*/
|
| 46 |
-
protected static $_keyNameCache = array();
|
| 47 |
-
|
| 48 |
-
/**
|
| 49 |
-
* List of already requested or used config entries
|
| 50 |
-
*
|
| 51 |
-
* @var array
|
| 52 |
-
*/
|
| 53 |
-
protected static $_configEntryCache = array();
|
| 54 |
-
|
| 55 |
-
/**
|
| 56 |
-
* Magic method to get configurations from the database
|
| 57 |
-
*
|
| 58 |
-
* @param string $method
|
| 59 |
-
* @param array $params
|
| 60 |
-
* @return string
|
| 61 |
-
*/
|
| 62 |
-
public function __call($method, $params)
|
| 63 |
-
{
|
| 64 |
-
switch (substr($method, 0, 3)) {
|
| 65 |
-
case 'get':
|
| 66 |
-
$key = $this->_toKeyName(substr($method, 3));
|
| 67 |
-
return $this->_getCustomConfig($key);
|
| 68 |
-
|
| 69 |
-
break;
|
| 70 |
-
|
| 71 |
-
case 'set':
|
| 72 |
-
if (!isset($params) || !isset($params[0])) {
|
| 73 |
-
return false;
|
| 74 |
-
}
|
| 75 |
-
|
| 76 |
-
$key = $this->_toKeyName(substr($method, 3));
|
| 77 |
-
$this->_setCustomConfig($key, $params[0]);
|
| 78 |
-
|
| 79 |
-
break;
|
| 80 |
-
|
| 81 |
-
case 'has':
|
| 82 |
-
$key = $this->_toKeyName(substr($method, 3));
|
| 83 |
-
return $this->_hasCustomConfig($key);
|
| 84 |
-
|
| 85 |
-
break;
|
| 86 |
-
|
| 87 |
-
case 'uns':
|
| 88 |
-
$key = $this->_toKeyName(substr($method, 3));
|
| 89 |
-
$model = $this->_getModel($key);
|
| 90 |
-
|
| 91 |
-
if ($model !== false) {
|
| 92 |
-
try {
|
| 93 |
-
$model->delete();
|
| 94 |
-
|
| 95 |
-
if (isset(self::$_configEntryCache[$key])) {
|
| 96 |
-
self::$_configEntryCache[$key] = null;
|
| 97 |
-
}
|
| 98 |
-
} catch (Exception $e) {
|
| 99 |
-
Mage::log('Marketingsoftware Config: ' . $e->getMessage());
|
| 100 |
-
}
|
| 101 |
-
}
|
| 102 |
-
|
| 103 |
-
break;
|
| 104 |
-
}
|
| 105 |
-
|
| 106 |
-
return false;
|
| 107 |
-
}
|
| 108 |
-
|
| 109 |
-
/**
|
| 110 |
-
* Tries to get config value from custom config table
|
| 111 |
-
*
|
| 112 |
-
* @param string $key
|
| 113 |
-
* @return string
|
| 114 |
-
*/
|
| 115 |
-
protected function _getCustomConfig($key)
|
| 116 |
-
{
|
| 117 |
-
if (isset(self::$_configEntryCache[$key])) {
|
| 118 |
-
return self::$_configEntryCache[$key];
|
| 119 |
-
}
|
| 120 |
-
|
| 121 |
-
$model = $this->_getModel($key);
|
| 122 |
-
|
| 123 |
-
if ($model !== false) {
|
| 124 |
-
return $model->getValue();
|
| 125 |
-
}
|
| 126 |
-
|
| 127 |
-
return null;
|
| 128 |
-
}
|
| 129 |
-
|
| 130 |
-
/**
|
| 131 |
-
* Sets a config entry in the custom config tab
|
| 132 |
-
*
|
| 133 |
-
* @param string $key
|
| 134 |
-
* @param string $value
|
| 135 |
-
*/
|
| 136 |
-
protected function _setCustomConfig($key, $value)
|
| 137 |
-
{
|
| 138 |
-
$model = $this->_getModel($key);
|
| 139 |
-
|
| 140 |
-
if ($model === false) {
|
| 141 |
-
$model = Mage::getModel('marketingsoftware/config');
|
| 142 |
-
}
|
| 143 |
-
|
| 144 |
-
try {
|
| 145 |
-
$model->setKeyName($key);
|
| 146 |
-
$model->setValue($value);
|
| 147 |
-
$model->save();
|
| 148 |
-
|
| 149 |
-
self::$_configEntryCache[$key] = $model->getValue();
|
| 150 |
-
|
| 151 |
-
return $model->getValue();
|
| 152 |
-
} catch (Exception $e) {
|
| 153 |
-
Mage::log('Marketingsoftware Config: ' . $e->getMessage());
|
| 154 |
-
}
|
| 155 |
-
}
|
| 156 |
-
|
| 157 |
-
/**
|
| 158 |
-
* Checks if an entry exists in the custom config table
|
| 159 |
-
*
|
| 160 |
-
* @param string $key
|
| 161 |
-
* @return boolean
|
| 162 |
-
*/
|
| 163 |
-
protected function _hasCustomConfig($key)
|
| 164 |
-
{
|
| 165 |
-
return ((isset(self::$_configEntryCache[$key]) && !empty(self::$_configEntryCache[$key])) || ($this->_getModel($key) !== false));
|
| 166 |
-
}
|
| 167 |
-
|
| 168 |
-
/**
|
| 169 |
-
* Loads the requested model config object if possible
|
| 170 |
-
*
|
| 171 |
-
* @param string $key
|
| 172 |
-
* @return Copernica_MarketingSoftware_Model_Config
|
| 173 |
-
*/
|
| 174 |
-
protected function _getModel($key)
|
| 175 |
-
{
|
| 176 |
-
$model = Mage::getModel('marketingsoftware/config')->loadByKey($key);
|
| 177 |
-
|
| 178 |
-
if ($model && $model->getId()) {
|
| 179 |
-
self::$_configEntryCache[$key] = $model->getValue();
|
| 180 |
-
|
| 181 |
-
return $model;
|
| 182 |
-
}
|
| 183 |
-
|
| 184 |
-
return false;
|
| 185 |
-
}
|
| 186 |
-
|
| 187 |
-
/**
|
| 188 |
-
* Prepends uppercase characters with underscores and lowers
|
| 189 |
-
* the whole string
|
| 190 |
-
*
|
| 191 |
-
* @param string $name
|
| 192 |
-
* @return string
|
| 193 |
-
*/
|
| 194 |
-
protected function _toKeyName($name)
|
| 195 |
-
{
|
| 196 |
-
if (isset(self::$_keyNameCache[$name])) {
|
| 197 |
-
return self::$_keyNameCache[$name];
|
| 198 |
-
}
|
| 199 |
-
|
| 200 |
-
$result = strtolower(preg_replace('/(.)([A-Z])/', "$1_$2", $name));
|
| 201 |
-
|
| 202 |
-
self::$_keyNameCache[$name] = $result;
|
| 203 |
-
return $result;
|
| 204 |
-
}
|
| 205 |
-
|
| 206 |
-
/**
|
| 207 |
-
* Get the config item from the custom config table, otherwise from
|
| 208 |
-
* the basic magento component.
|
| 209 |
-
*
|
| 210 |
-
* @param string $name
|
| 211 |
-
*/
|
| 212 |
-
protected function _getConfig($name)
|
| 213 |
-
{
|
| 214 |
-
return $this->_getCustomConfig($name);
|
| 215 |
-
|
| 216 |
-
if ($this->_hasCustomConfig($name)) {
|
| 217 |
-
return $this->_getCustomConfig($name);
|
| 218 |
-
} else {
|
| 219 |
-
return (string) Mage::getConfig()->getNode(self::CONFIG_BASE . $name, 'default', 0);
|
| 220 |
-
}
|
| 221 |
-
}
|
| 222 |
-
|
| 223 |
-
/**
|
| 224 |
-
* Set the config item from the basic magento component
|
| 225 |
-
*
|
| 226 |
-
* @param string $name
|
| 227 |
-
* @param string $value
|
| 228 |
-
*/
|
| 229 |
-
protected function _setConfig($name, $value)
|
| 230 |
-
{
|
| 231 |
-
if ($value === $this->_getConfig($name)) {
|
| 232 |
-
return;
|
| 233 |
-
}
|
| 234 |
-
|
| 235 |
-
$this->_setCustomConfig($name, $value);
|
| 236 |
-
|
| 237 |
-
// Some config items are not needed
|
| 238 |
-
if (in_array($name, array(
|
| 239 |
-
'customer_progress_status',
|
| 240 |
-
'order_progress_status',
|
| 241 |
-
'subscription_progress_status',
|
| 242 |
-
'cronjob_starttime',
|
| 243 |
-
'cronjob_endtime',
|
| 244 |
-
'cronjob_processedtasks',
|
| 245 |
-
))) return;
|
| 246 |
-
|
| 247 |
-
$this->setCustomerProgressStatus('0');
|
| 248 |
-
|
| 249 |
-
$this->setOrderProgressStatus('0');
|
| 250 |
-
|
| 251 |
-
$this->setSubscriptionProgressStatus('0');
|
| 252 |
-
}
|
| 253 |
-
|
| 254 |
-
/**
|
| 255 |
-
* Check if store is enabled.
|
| 256 |
-
*
|
| 257 |
-
* @param int
|
| 258 |
-
* @return bool
|
| 259 |
-
*/
|
| 260 |
-
public function isEnabledStore($storeId)
|
| 261 |
-
{
|
| 262 |
-
$stores = @unserialize($this->_getConfig('enabled_stores'));
|
| 263 |
-
|
| 264 |
-
if (!is_array($stores)) {
|
| 265 |
-
return true;
|
| 266 |
-
}
|
| 267 |
-
|
| 268 |
-
return in_array($storeId, $stores);
|
| 269 |
-
}
|
| 270 |
-
|
| 271 |
-
/**
|
| 272 |
-
* Set stores. Pass null to disable store filtering.
|
| 273 |
-
*
|
| 274 |
-
* @param array|null
|
| 275 |
-
* @return Copernica_MarketingSoftware_Helper_Config
|
| 276 |
-
*/
|
| 277 |
-
public function setEnabledStores($collectionOfStoresId)
|
| 278 |
-
{
|
| 279 |
-
$this->_setConfig('enabled_stores', serialize($collectionOfStoresId));
|
| 280 |
-
|
| 281 |
-
return $this;
|
| 282 |
-
}
|
| 283 |
-
|
| 284 |
-
/**
|
| 285 |
-
* Get list of enabled stores
|
| 286 |
-
*
|
| 287 |
-
* @return array|null
|
| 288 |
-
*/
|
| 289 |
-
public function getEnabledStores()
|
| 290 |
-
{
|
| 291 |
-
return unserialize($this->_getConfig('enabled_stores'));
|
| 292 |
-
}
|
| 293 |
-
|
| 294 |
-
/**
|
| 295 |
-
* Get the hostname from the config
|
| 296 |
-
*
|
| 297 |
-
* @return string
|
| 298 |
-
*/
|
| 299 |
-
public function getHostname()
|
| 300 |
-
{
|
| 301 |
-
return $this->_getConfig('hostname');
|
| 302 |
-
}
|
| 303 |
-
|
| 304 |
-
/**
|
| 305 |
-
* Set the hostname from the config
|
| 306 |
-
*
|
| 307 |
-
* @return Copernica_MarketingSoftware_Helper_Config
|
| 308 |
-
*/
|
| 309 |
-
public function setHostname($value)
|
| 310 |
-
{
|
| 311 |
-
$this->_setConfig('hostname', $value);
|
| 312 |
-
|
| 313 |
-
return $this;
|
| 314 |
-
}
|
| 315 |
-
|
| 316 |
-
/**
|
| 317 |
-
* Get the name of the database
|
| 318 |
-
*
|
| 319 |
-
* @return string
|
| 320 |
-
*/
|
| 321 |
-
public function getDatabaseName()
|
| 322 |
-
{
|
| 323 |
-
return $this->_getConfig('database');
|
| 324 |
-
}
|
| 325 |
-
|
| 326 |
-
/**
|
| 327 |
-
* Set the name of the database
|
| 328 |
-
*
|
| 329 |
-
* @param string $value
|
| 330 |
-
* @return Copernica_MarketingSoftware_Helper_Config
|
| 331 |
-
*/
|
| 332 |
-
public function setDatabaseName($value)
|
| 333 |
-
{
|
| 334 |
-
$this->_setConfig('database', $value);
|
| 335 |
-
|
| 336 |
-
return $this;
|
| 337 |
-
}
|
| 338 |
-
|
| 339 |
-
/**
|
| 340 |
-
* Get the linked customer fields
|
| 341 |
-
*
|
| 342 |
-
* @return array
|
| 343 |
-
*/
|
| 344 |
-
public function getLinkedCustomerFields()
|
| 345 |
-
{
|
| 346 |
-
$value = $this->_getConfig('linked_customer_fields');
|
| 347 |
-
$value = empty($value) ? array() : json_decode($value, true);
|
| 348 |
-
|
| 349 |
-
if (!isset($value['customer_email'])) {
|
| 350 |
-
return $value;
|
| 351 |
-
}
|
| 352 |
-
|
| 353 |
-
$oldValues = $value;
|
| 354 |
-
|
| 355 |
-
$newValues = array();
|
| 356 |
-
|
| 357 |
-
foreach ($oldValues as $key => $value) {
|
| 358 |
-
$key = str_replace('customer_', '', $key);
|
| 359 |
-
|
| 360 |
-
$newValues[$key] = $value;
|
| 361 |
-
}
|
| 362 |
-
|
| 363 |
-
$this->setLinkedCustomerFields($newValues);
|
| 364 |
-
|
| 365 |
-
return $newValues;
|
| 366 |
-
}
|
| 367 |
-
|
| 368 |
-
/**
|
| 369 |
-
* Set the linked customer fields
|
| 370 |
-
*
|
| 371 |
-
* @param array $value
|
| 372 |
-
* @return Copernica_MarketingSoftware_Helper_Config
|
| 373 |
-
*/
|
| 374 |
-
public function setLinkedCustomerFields($value)
|
| 375 |
-
{
|
| 376 |
-
$this->_setConfig('linked_customer_fields', json_encode($value), true);
|
| 377 |
-
|
| 378 |
-
return $this;
|
| 379 |
-
}
|
| 380 |
-
|
| 381 |
-
/**
|
| 382 |
-
* Get the id of the quote item collection
|
| 383 |
-
*
|
| 384 |
-
* @return int
|
| 385 |
-
*/
|
| 386 |
-
public function getQuoteItemCollectionId()
|
| 387 |
-
{
|
| 388 |
-
$id = $this->_getConfig('quote_item_collection_id');
|
| 389 |
-
|
| 390 |
-
if ($id) {
|
| 391 |
-
return $id;
|
| 392 |
-
}
|
| 393 |
-
|
| 394 |
-
$name = $this->getQuoteItemCollectionName();
|
| 395 |
-
|
| 396 |
-
if (!$name) {
|
| 397 |
-
return null;
|
| 398 |
-
}
|
| 399 |
-
|
| 400 |
-
$id = Mage::helper('marketingsoftware/api_abstract')->getCollectionId($name);
|
| 401 |
-
|
| 402 |
-
if (!$id) {
|
| 403 |
-
return null;
|
| 404 |
-
}
|
| 405 |
-
|
| 406 |
-
$this->_setConfig('quote_item_collection_id', $id);
|
| 407 |
-
|
| 408 |
-
return $id;
|
| 409 |
-
}
|
| 410 |
-
|
| 411 |
-
/**
|
| 412 |
-
* Get the name of the quote item collection
|
| 413 |
-
*
|
| 414 |
-
* @return string
|
| 415 |
-
*/
|
| 416 |
-
public function getQuoteItemCollectionName()
|
| 417 |
-
{
|
| 418 |
-
return $this->_getConfig('quote_item_collection_name');
|
| 419 |
-
}
|
| 420 |
-
|
| 421 |
-
/**
|
| 422 |
-
* Set the name of the quote item collection
|
| 423 |
-
*
|
| 424 |
-
* @param string $value
|
| 425 |
-
* @return Copernica_MarketingSoftware_Helper_Config
|
| 426 |
-
*/
|
| 427 |
-
public function setQuoteItemCollectionName($value)
|
| 428 |
-
{
|
| 429 |
-
$this->_setConfig('quote_item_collection_name', $value);
|
| 430 |
-
|
| 431 |
-
return $this;
|
| 432 |
-
}
|
| 433 |
-
|
| 434 |
-
/**
|
| 435 |
-
* Get the linked quote item fields
|
| 436 |
-
*
|
| 437 |
-
* @return array
|
| 438 |
-
*/
|
| 439 |
-
public function getLinkedQuoteItemFields()
|
| 440 |
-
{
|
| 441 |
-
$value = $this->_getConfig('linked_quote_item_fields');
|
| 442 |
-
|
| 443 |
-
if (empty($value)) {
|
| 444 |
-
return array();
|
| 445 |
-
} else {
|
| 446 |
-
return json_decode($value, true);
|
| 447 |
-
}
|
| 448 |
-
}
|
| 449 |
-
|
| 450 |
-
/**
|
| 451 |
-
* Get the linked quote item fields
|
| 452 |
-
*
|
| 453 |
-
* @param array $value
|
| 454 |
-
* @return Copernica_MarketingSoftware_Helper_Config
|
| 455 |
-
*/
|
| 456 |
-
public function setLinkedQuoteItemFields($value)
|
| 457 |
-
{
|
| 458 |
-
$this->_setConfig('linked_quote_item_fields', json_encode($value), true);
|
| 459 |
-
|
| 460 |
-
return $this;
|
| 461 |
-
}
|
| 462 |
-
|
| 463 |
-
/**
|
| 464 |
-
* Get the name of the orders collection
|
| 465 |
-
*
|
| 466 |
-
* @return string
|
| 467 |
-
*/
|
| 468 |
-
public function getOrdersCollectionName()
|
| 469 |
-
{
|
| 470 |
-
return $this->_getConfig('orders_collection_name');
|
| 471 |
-
}
|
| 472 |
-
|
| 473 |
-
/**
|
| 474 |
-
* Get the id of the orders collection
|
| 475 |
-
*
|
| 476 |
-
* @return int
|
| 477 |
-
*/
|
| 478 |
-
public function getOrdersCollectionId()
|
| 479 |
-
{
|
| 480 |
-
$id = $this->_getConfig('orders_collection_id');
|
| 481 |
-
|
| 482 |
-
if ($id) {
|
| 483 |
-
return $id;
|
| 484 |
-
}
|
| 485 |
-
|
| 486 |
-
$name = $this->getOrdersCollectionName();
|
| 487 |
-
|
| 488 |
-
if (!$name) {
|
| 489 |
-
return null;
|
| 490 |
-
}
|
| 491 |
-
|
| 492 |
-
$id = Mage::helper('marketingsoftware/api_abstract')->getCollectionId($name);
|
| 493 |
-
|
| 494 |
-
if (!$id) {
|
| 495 |
-
return null;
|
| 496 |
-
}
|
| 497 |
-
|
| 498 |
-
$this->_setConfig('orders_collection_id', $id);
|
| 499 |
-
|
| 500 |
-
return $id;
|
| 501 |
-
}
|
| 502 |
-
|
| 503 |
-
/**
|
| 504 |
-
* Set the name of the orders collection
|
| 505 |
-
*
|
| 506 |
-
* @param string $value
|
| 507 |
-
* @return Copernica_MarketingSoftware_Helper_Config
|
| 508 |
-
*/
|
| 509 |
-
public function setOrdersCollectionName($value)
|
| 510 |
-
{
|
| 511 |
-
$this->_setConfig('orders_collection_name', $value);
|
| 512 |
-
|
| 513 |
-
return $this;
|
| 514 |
-
}
|
| 515 |
-
|
| 516 |
-
/**
|
| 517 |
-
* Get the linked order fields
|
| 518 |
-
*
|
| 519 |
-
* @return array
|
| 520 |
-
*/
|
| 521 |
-
public function getLinkedOrderFields()
|
| 522 |
-
{
|
| 523 |
-
$value = $this->_getConfig('linked_order_fields');
|
| 524 |
-
$value = empty($value) ? array() : json_decode($value, true);
|
| 525 |
-
|
| 526 |
-
if (!isset($value['order_timestamp'])) {
|
| 527 |
-
return $value;
|
| 528 |
-
}
|
| 529 |
-
|
| 530 |
-
$oldValues = $value;
|
| 531 |
-
|
| 532 |
-
$newValues = array();
|
| 533 |
-
|
| 534 |
-
foreach ($oldValues as $key => $value) {
|
| 535 |
-
$key = ($key == 'order_qty') ? 'quantity' : str_replace('order_', '', $key);
|
| 536 |
-
|
| 537 |
-
$newValues[$key] = $value;
|
| 538 |
-
}
|
| 539 |
-
|
| 540 |
-
$this->setLinkedOrderFields($newValues);
|
| 541 |
-
|
| 542 |
-
return $newValues;
|
| 543 |
-
}
|
| 544 |
-
|
| 545 |
-
/**
|
| 546 |
-
* Set the linked order fields
|
| 547 |
-
*
|
| 548 |
-
* @param array $value
|
| 549 |
-
* @return Copernica_MarketingSoftware_Helper_Config
|
| 550 |
-
*/
|
| 551 |
-
public function setLinkedOrderFields($value)
|
| 552 |
-
{
|
| 553 |
-
$this->_setConfig('linked_order_fields', json_encode($value), true);
|
| 554 |
-
|
| 555 |
-
return $this;
|
| 556 |
-
}
|
| 557 |
-
|
| 558 |
-
/**
|
| 559 |
-
* Get the name of the collection were all the orders are stored
|
| 560 |
-
*
|
| 561 |
-
* @return string
|
| 562 |
-
*/
|
| 563 |
-
public function getOrderItemCollectionName()
|
| 564 |
-
{
|
| 565 |
-
return $this->_getConfig('order_item_collection_name');
|
| 566 |
-
}
|
| 567 |
-
|
| 568 |
-
/**
|
| 569 |
-
* Get the id of the order item collection
|
| 570 |
-
*
|
| 571 |
-
* @return int
|
| 572 |
-
*/
|
| 573 |
-
public function getOrderItemCollectionId()
|
| 574 |
-
{
|
| 575 |
-
$id = $this->_getConfig('order_item_collection_id');
|
| 576 |
-
|
| 577 |
-
if ($id) {
|
| 578 |
-
return $id;
|
| 579 |
-
}
|
| 580 |
-
|
| 581 |
-
$name = $this->getOrderItemCollectionName();
|
| 582 |
-
|
| 583 |
-
if (!$name) {
|
| 584 |
-
return null;
|
| 585 |
-
}
|
| 586 |
-
|
| 587 |
-
$id = Mage::helper('marketingsoftware/api_abstract')->getCollectionId($name);
|
| 588 |
-
|
| 589 |
-
if (!$id) {
|
| 590 |
-
return null;
|
| 591 |
-
}
|
| 592 |
-
|
| 593 |
-
$this->_setConfig('order_item_collection_id', $id);
|
| 594 |
-
|
| 595 |
-
return $id;
|
| 596 |
-
}
|
| 597 |
-
|
| 598 |
-
/**
|
| 599 |
-
* Get the name of the collection were all the orders are stored
|
| 600 |
-
*
|
| 601 |
-
* @param string
|
| 602 |
-
*/
|
| 603 |
-
public function setOrderItemCollectionName($value)
|
| 604 |
-
{
|
| 605 |
-
$this->_setConfig('order_item_collection_name', $value);
|
| 606 |
-
|
| 607 |
-
return $this;
|
| 608 |
-
}
|
| 609 |
-
|
| 610 |
-
/**
|
| 611 |
-
* Get the linked order item fields
|
| 612 |
-
*
|
| 613 |
-
* @return array
|
| 614 |
-
*/
|
| 615 |
-
public function getLinkedOrderItemFields()
|
| 616 |
-
{
|
| 617 |
-
$value = $this->_getConfig('linked_order_item_fields');
|
| 618 |
-
$value = empty($value) ? array() : json_decode($value, true);
|
| 619 |
-
|
| 620 |
-
if (!isset($value['product_internal_id'])) {
|
| 621 |
-
return $value;
|
| 622 |
-
}
|
| 623 |
-
|
| 624 |
-
$oldValues = $value;
|
| 625 |
-
|
| 626 |
-
$newValues = array();
|
| 627 |
-
|
| 628 |
-
foreach ($oldValues as $key => $value) {
|
| 629 |
-
switch($key) {
|
| 630 |
-
case 'product_qty':
|
| 631 |
-
$key = 'quantity';
|
| 632 |
-
break;
|
| 633 |
-
|
| 634 |
-
case 'product_base_row_total':
|
| 635 |
-
$key = 'total_price';
|
| 636 |
-
break;
|
| 637 |
-
|
| 638 |
-
default:
|
| 639 |
-
$key = str_replace('product_', '', $key);
|
| 640 |
-
break;
|
| 641 |
-
}
|
| 642 |
-
|
| 643 |
-
$newValues[$key] = $value;
|
| 644 |
-
}
|
| 645 |
-
|
| 646 |
-
$this->setLinkedOrderItemFields($newValues);
|
| 647 |
-
|
| 648 |
-
return $newValues;
|
| 649 |
-
}
|
| 650 |
-
|
| 651 |
-
/**
|
| 652 |
-
* Set the linked order item fields
|
| 653 |
-
*
|
| 654 |
-
* @param array $value
|
| 655 |
-
* @return Copernica_MarketingSoftware_Helper_Config
|
| 656 |
-
*/
|
| 657 |
-
public function setLinkedOrderItemFields($value)
|
| 658 |
-
{
|
| 659 |
-
$this->_setConfig('linked_order_item_fields', json_encode($value), true);
|
| 660 |
-
|
| 661 |
-
return $this;
|
| 662 |
-
}
|
| 663 |
-
|
| 664 |
-
/**
|
| 665 |
-
* Get the address collection name
|
| 666 |
-
*
|
| 667 |
-
* @return string
|
| 668 |
-
*/
|
| 669 |
-
public function getAddressesCollectionName()
|
| 670 |
-
{
|
| 671 |
-
return $this->_getConfig('address_collection_name');
|
| 672 |
-
}
|
| 673 |
-
|
| 674 |
-
/**
|
| 675 |
-
* Get the id of the address collection
|
| 676 |
-
* @return int
|
| 677 |
-
*/
|
| 678 |
-
public function getAddressesCollectionId()
|
| 679 |
-
{
|
| 680 |
-
$id = $this->_getConfig('address_collection_id');
|
| 681 |
-
|
| 682 |
-
if ($id) {
|
| 683 |
-
return $id;
|
| 684 |
-
}
|
| 685 |
-
|
| 686 |
-
$name = $this->getAddressesCollectionName();
|
| 687 |
-
|
| 688 |
-
if (!$name) {
|
| 689 |
-
return null;
|
| 690 |
-
}
|
| 691 |
-
|
| 692 |
-
$id = Mage::helper('marketingsoftware/api_abstract')->getCollectionId($name);
|
| 693 |
-
|
| 694 |
-
if (!$id) {
|
| 695 |
-
return null;
|
| 696 |
-
}
|
| 697 |
-
|
| 698 |
-
$this->_setConfig('address_collection_id', $id);
|
| 699 |
-
|
| 700 |
-
return $id;
|
| 701 |
-
}
|
| 702 |
-
|
| 703 |
-
/**
|
| 704 |
-
* Set the name of the collection with addresses
|
| 705 |
-
*/
|
| 706 |
-
public function setAddressCollectionName($value)
|
| 707 |
-
{
|
| 708 |
-
$this->_setConfig('address_collection_name', $value);
|
| 709 |
-
|
| 710 |
-
return $this;
|
| 711 |
-
}
|
| 712 |
-
|
| 713 |
-
/**
|
| 714 |
-
* Get the linked address fields
|
| 715 |
-
*
|
| 716 |
-
* @return array
|
| 717 |
-
*/
|
| 718 |
-
public function getLinkedAddressFields()
|
| 719 |
-
{
|
| 720 |
-
$value = $this->_getConfig('linked_address_fields');
|
| 721 |
-
$value = empty($value) ? array() : json_decode($value, true);
|
| 722 |
-
|
| 723 |
-
if (!isset($value['address_firstname'])) {
|
| 724 |
-
return $value;
|
| 725 |
-
}
|
| 726 |
-
|
| 727 |
-
$oldValues = $value;
|
| 728 |
-
|
| 729 |
-
$newValues = array();
|
| 730 |
-
|
| 731 |
-
foreach ($oldValues as $key => $value) {
|
| 732 |
-
$key = str_replace('address_', '', $key);
|
| 733 |
-
|
| 734 |
-
$newValues[$key] = $value;
|
| 735 |
-
}
|
| 736 |
-
|
| 737 |
-
$this->setLinkedAddressFields($newValues);
|
| 738 |
-
|
| 739 |
-
return $newValues;
|
| 740 |
-
}
|
| 741 |
-
|
| 742 |
-
/**
|
| 743 |
-
* set the linked address fields
|
| 744 |
-
*
|
| 745 |
-
* @param array $value
|
| 746 |
-
* @return Copernica_MarketingSoftware_Helper_Config
|
| 747 |
-
*/
|
| 748 |
-
public function setLinkedAddressFields($value)
|
| 749 |
-
{
|
| 750 |
-
$this->_setConfig('linked_address_fields', json_encode($value), true);
|
| 751 |
-
|
| 752 |
-
return $this;
|
| 753 |
-
}
|
| 754 |
-
|
| 755 |
-
/**
|
| 756 |
-
* Get the name of the viewed products collection
|
| 757 |
-
*
|
| 758 |
-
* @return string
|
| 759 |
-
*/
|
| 760 |
-
public function getViewedProductCollectionName()
|
| 761 |
-
{
|
| 762 |
-
return $this->_getConfig('viewed_product_collection_name');
|
| 763 |
-
}
|
| 764 |
-
|
| 765 |
-
/**
|
| 766 |
-
* Get the id of the address collection
|
| 767 |
-
*
|
| 768 |
-
* @return int
|
| 769 |
-
*/
|
| 770 |
-
public function getViewedProductCollectionId()
|
| 771 |
-
{
|
| 772 |
-
$id = $this->_getConfig('viewed_product_collection_id');
|
| 773 |
-
|
| 774 |
-
if ($id) {
|
| 775 |
-
return $id;
|
| 776 |
-
}
|
| 777 |
-
|
| 778 |
-
$name = $this->getViewedProductCollectionName();
|
| 779 |
-
|
| 780 |
-
if (!$name) {
|
| 781 |
-
return null;
|
| 782 |
-
}
|
| 783 |
-
|
| 784 |
-
$id = Mage::helper('marketingsoftware/api_abstract')->getCollectionId($name);
|
| 785 |
-
|
| 786 |
-
if (!$id) {
|
| 787 |
-
return null;
|
| 788 |
-
}
|
| 789 |
-
|
| 790 |
-
$this->_setConfig('viewed_product_collection_id', $id);
|
| 791 |
-
|
| 792 |
-
return $id;
|
| 793 |
-
}
|
| 794 |
-
|
| 795 |
-
/**
|
| 796 |
-
* Set the name of the viewed products collection
|
| 797 |
-
*
|
| 798 |
-
* @param string $value
|
| 799 |
-
* @return Copernica_MarketingSoftware_Helper_Config
|
| 800 |
-
*/
|
| 801 |
-
public function setViewedProductCollectionName($value)
|
| 802 |
-
{
|
| 803 |
-
$this->_setConfig('viewed_product_collection_name', $value);
|
| 804 |
-
|
| 805 |
-
return $this;
|
| 806 |
-
}
|
| 807 |
-
|
| 808 |
-
/**
|
| 809 |
-
* Get the linked customer fields
|
| 810 |
-
*
|
| 811 |
-
* @return array
|
| 812 |
-
*/
|
| 813 |
-
public function getLinkedViewedProductFields()
|
| 814 |
-
{
|
| 815 |
-
$value = $this->_getConfig('linked_viewed_product_fields');
|
| 816 |
-
|
| 817 |
-
if (empty($value)) {
|
| 818 |
-
return array();
|
| 819 |
-
} else {
|
| 820 |
-
return json_decode($value, true);
|
| 821 |
-
}
|
| 822 |
-
}
|
| 823 |
-
|
| 824 |
-
/**
|
| 825 |
-
* Get the linked customer fields
|
| 826 |
-
*
|
| 827 |
-
* @param array $value
|
| 828 |
-
* @return Copernica_MarketingSoftware_Helper_Config
|
| 829 |
-
*/
|
| 830 |
-
public function setLinkedViewedProductFields($value)
|
| 831 |
-
{
|
| 832 |
-
$this->_setConfig('linked_viewed_product_fields', json_encode($value), true);
|
| 833 |
-
|
| 834 |
-
return $this;
|
| 835 |
-
}
|
| 836 |
-
|
| 837 |
-
/**
|
| 838 |
-
* Get the name of the wishlist item collection
|
| 839 |
-
*
|
| 840 |
-
* @return string
|
| 841 |
-
*/
|
| 842 |
-
public function getWishlistItemCollectionName()
|
| 843 |
-
{
|
| 844 |
-
return $this->_getConfig('wishlist_item_collection_name');
|
| 845 |
-
}
|
| 846 |
-
|
| 847 |
-
/**
|
| 848 |
-
* Get the id of the wishlist item collection
|
| 849 |
-
*
|
| 850 |
-
* @return int
|
| 851 |
-
*/
|
| 852 |
-
public function getWishlistItemCollectionId()
|
| 853 |
-
{
|
| 854 |
-
$id = $this->_getConfig('wishlist_item_collection_id');
|
| 855 |
-
|
| 856 |
-
if ($id) {
|
| 857 |
-
return $id;
|
| 858 |
-
}
|
| 859 |
-
|
| 860 |
-
$name = $this->getWishlistItemCollectionName();
|
| 861 |
-
|
| 862 |
-
if (!$name) {
|
| 863 |
-
return null;
|
| 864 |
-
}
|
| 865 |
-
|
| 866 |
-
$id = Mage::helper('marketingsoftware/api_abstract')->getCollectionId($name);
|
| 867 |
-
|
| 868 |
-
if (!$id) {
|
| 869 |
-
return null;
|
| 870 |
-
}
|
| 871 |
-
|
| 872 |
-
$this->_setConfig('wishlist_item_collection_id', $id);
|
| 873 |
-
|
| 874 |
-
return $id;
|
| 875 |
-
}
|
| 876 |
-
|
| 877 |
-
/**
|
| 878 |
-
* Set the name of the wishlist item collection
|
| 879 |
-
*
|
| 880 |
-
* @param string $value
|
| 881 |
-
* @return Copernica_MarketingSoftware_Helper_Config
|
| 882 |
-
*/
|
| 883 |
-
public function setWishlistItemCollectionName($value)
|
| 884 |
-
{
|
| 885 |
-
$this->_setConfig('wishlist_item_collection_name', $value);
|
| 886 |
-
|
| 887 |
-
return $this;
|
| 888 |
-
}
|
| 889 |
-
|
| 890 |
-
/**
|
| 891 |
-
* Get the linked wishlist item fields
|
| 892 |
-
*
|
| 893 |
-
* @return array
|
| 894 |
-
*/
|
| 895 |
-
public function getLinkedWishlistItemFields()
|
| 896 |
-
{
|
| 897 |
-
$value = $this->_getConfig('linked_wishlist_item_fields');
|
| 898 |
-
|
| 899 |
-
if (empty($value)) {
|
| 900 |
-
return array();
|
| 901 |
-
} else {
|
| 902 |
-
return json_decode($value, true);
|
| 903 |
-
}
|
| 904 |
-
}
|
| 905 |
-
|
| 906 |
-
/**
|
| 907 |
-
* Set the linked wishlist item fields
|
| 908 |
-
*
|
| 909 |
-
* @param array $value
|
| 910 |
-
* @return Copernica_MarketingSoftware_Helper_Config
|
| 911 |
-
*/
|
| 912 |
-
public function setLinkedWishlistItemFields($value)
|
| 913 |
-
{
|
| 914 |
-
$this->_setConfig('linked_wishlist_item_fields', json_encode($value), true);
|
| 915 |
-
|
| 916 |
-
return $this;
|
| 917 |
-
}
|
| 918 |
-
|
| 919 |
-
/**
|
| 920 |
-
* Get the progress status for customers
|
| 921 |
-
* This is the created timestamp of the most recent customer which has
|
| 922 |
-
* been queued for synchronisation
|
| 923 |
-
*
|
| 924 |
-
* @return datetime
|
| 925 |
-
*/
|
| 926 |
-
public function getCustomerProgressStatus()
|
| 927 |
-
{
|
| 928 |
-
return $this->_getConfig('customer_progress_status');
|
| 929 |
-
}
|
| 930 |
-
|
| 931 |
-
/**
|
| 932 |
-
* Set the progress status for customers
|
| 933 |
-
* This is the created timestamp of the most recent customer which has
|
| 934 |
-
* been queued for synchronisation
|
| 935 |
-
*
|
| 936 |
-
* @param datetime $value
|
| 937 |
-
* @return Copernica_MarketingSoftware_Helper_Config
|
| 938 |
-
*/
|
| 939 |
-
public function setCustomerProgressStatus($value)
|
| 940 |
-
{
|
| 941 |
-
$this->_setConfig('customer_progress_status', $value);
|
| 942 |
-
|
| 943 |
-
return $this;
|
| 944 |
-
}
|
| 945 |
-
|
| 946 |
-
/**
|
| 947 |
-
* Get the progress status for orders
|
| 948 |
-
* This is the created timestamp of the most recent order which has
|
| 949 |
-
* been queued for synchronisation
|
| 950 |
-
*
|
| 951 |
-
* @return datetime
|
| 952 |
-
*/
|
| 953 |
-
public function getOrderProgressStatus()
|
| 954 |
-
{
|
| 955 |
-
return $this->_getConfig('order_progress_status');
|
| 956 |
-
}
|
| 957 |
-
|
| 958 |
-
/**
|
| 959 |
-
* Set the progress status for orders
|
| 960 |
-
* This is the created timestamp of the most recent order which has
|
| 961 |
-
* been queued for synchronisation
|
| 962 |
-
*
|
| 963 |
-
* @param datetime $value
|
| 964 |
-
* @return Copernica_MarketingSoftware_Helper_Config
|
| 965 |
-
*/
|
| 966 |
-
public function setOrderProgressStatus($value)
|
| 967 |
-
{
|
| 968 |
-
$this->_setConfig('order_progress_status', $value);
|
| 969 |
-
|
| 970 |
-
return $this;
|
| 971 |
-
}
|
| 972 |
-
|
| 973 |
-
/**
|
| 974 |
-
* Get the progress status for subscriptions
|
| 975 |
-
* This is the created timestamp of the most recent subscription which has
|
| 976 |
-
* been queued for synchronisation
|
| 977 |
-
*
|
| 978 |
-
* @return datetime
|
| 979 |
-
*/
|
| 980 |
-
public function getSubscriptionProgressStatus()
|
| 981 |
-
{
|
| 982 |
-
return $this->_getConfig('subscription_progress_status');
|
| 983 |
-
}
|
| 984 |
-
|
| 985 |
-
/**
|
| 986 |
-
* Set the progress status for subscriptions
|
| 987 |
-
* This is the created timestamp of the most recent subscription which has
|
| 988 |
-
* been queued for synchronisation
|
| 989 |
-
*
|
| 990 |
-
* @param datetime $value
|
| 991 |
-
* @return Copernica_MarketingSoftware_Helper_Config
|
| 992 |
-
*/
|
| 993 |
-
public function setSubscriptionProgressStatus($value)
|
| 994 |
-
{
|
| 995 |
-
$this->_setConfig('subscription_progress_status', $value);
|
| 996 |
-
|
| 997 |
-
return $this;
|
| 998 |
-
}
|
| 999 |
-
|
| 1000 |
-
/**
|
| 1001 |
-
* Get the last start time of the cronjob.
|
| 1002 |
-
*
|
| 1003 |
-
* @return datetime
|
| 1004 |
-
*/
|
| 1005 |
-
public function getLastStartTimeCronjob()
|
| 1006 |
-
{
|
| 1007 |
-
return $this->_getConfig('cronjob_starttime');
|
| 1008 |
-
}
|
| 1009 |
-
|
| 1010 |
-
/**
|
| 1011 |
-
* Set the last start time of the cronjob.
|
| 1012 |
-
*
|
| 1013 |
-
* @param datetime $value
|
| 1014 |
-
* @return Copernica_MarketingSoftware_Helper_Config
|
| 1015 |
-
*/
|
| 1016 |
-
public function setLastStartTimeCronjob($value)
|
| 1017 |
-
{
|
| 1018 |
-
$this->_setConfig('cronjob_starttime', $value);
|
| 1019 |
-
|
| 1020 |
-
return $this;
|
| 1021 |
-
}
|
| 1022 |
-
|
| 1023 |
-
/**
|
| 1024 |
-
* Get the last end time of the cronjob.
|
| 1025 |
-
*
|
| 1026 |
-
* @return datetime
|
| 1027 |
-
*/
|
| 1028 |
-
public function getLastEndTimeCronjob()
|
| 1029 |
-
{
|
| 1030 |
-
return $this->_getConfig('cronjob_endtime');
|
| 1031 |
-
}
|
| 1032 |
-
|
| 1033 |
-
/**
|
| 1034 |
-
* Set the last end time of the cronjob.
|
| 1035 |
-
*
|
| 1036 |
-
* @param datetime $value
|
| 1037 |
-
* @return Copernica_MarketingSoftware_Helper_Config
|
| 1038 |
-
*/
|
| 1039 |
-
public function setLastEndTimeCronjob($value)
|
| 1040 |
-
{
|
| 1041 |
-
$this->_setConfig('cronjob_endtime', $value, true);
|
| 1042 |
-
|
| 1043 |
-
return $this;
|
| 1044 |
-
}
|
| 1045 |
-
|
| 1046 |
-
/**
|
| 1047 |
-
* Get the number of processed records of the last cronjob run.
|
| 1048 |
-
*
|
| 1049 |
-
* @return integer
|
| 1050 |
-
*/
|
| 1051 |
-
public function getLastCronjobProcessedTasks()
|
| 1052 |
-
{
|
| 1053 |
-
return (int)$this->_getConfig('cronjob_processedtasks');
|
| 1054 |
-
}
|
| 1055 |
-
|
| 1056 |
-
/**
|
| 1057 |
-
* Set the last end time of the cronjob.
|
| 1058 |
-
*
|
| 1059 |
-
* @param integer $value
|
| 1060 |
-
* @return Copernica_MarketingSoftware_Helper_Config
|
| 1061 |
-
*/
|
| 1062 |
-
public function setLastCronjobProcessedTasks($value)
|
| 1063 |
-
{
|
| 1064 |
-
$this->_setConfig('cronjob_processedtasks', $value);
|
| 1065 |
-
|
| 1066 |
-
return $this;
|
| 1067 |
-
}
|
| 1068 |
-
|
| 1069 |
-
/**
|
| 1070 |
-
* Should our extension use vanilla magento cron schedulers to execute
|
| 1071 |
-
* queue? Or should we sync all data by processQueue.php file?
|
| 1072 |
-
*
|
| 1073 |
-
* @param boolean $vanilla
|
| 1074 |
-
* @return Copernica_MarketingSoftware_Helper_Config
|
| 1075 |
-
*/
|
| 1076 |
-
public function setVanillaCrons($vanilla)
|
| 1077 |
-
{
|
| 1078 |
-
$this->_setConfig('vanilla_crons', (bool) $vanilla ? 1 : 0);
|
| 1079 |
-
|
| 1080 |
-
return $this;
|
| 1081 |
-
}
|
| 1082 |
-
|
| 1083 |
-
/**
|
| 1084 |
-
* Get stored config about vanilla crons schedulers.
|
| 1085 |
-
*
|
| 1086 |
-
* @return boolean
|
| 1087 |
-
*/
|
| 1088 |
-
public function getVanillaCrons()
|
| 1089 |
-
{
|
| 1090 |
-
return (bool)$this->_getConfig('vanilla_crons');
|
| 1091 |
-
}
|
| 1092 |
-
|
| 1093 |
-
/**
|
| 1094 |
-
* Get last timestamp that we used to check magento forgotten carts
|
| 1095 |
-
*
|
| 1096 |
-
* @return string
|
| 1097 |
-
*/
|
| 1098 |
-
public function getAbandonedLastCheck()
|
| 1099 |
-
{
|
| 1100 |
-
$lastTimestamp = $this->_getConfig('lastAbandonedCheck');
|
| 1101 |
-
|
| 1102 |
-
return $lastTimestamp ? $lastTimestamp : '0000-00-00 00:00:00';
|
| 1103 |
-
}
|
| 1104 |
-
|
| 1105 |
-
/**
|
| 1106 |
-
* Set timestamp when we did check forgotten carts list
|
| 1107 |
-
*
|
| 1108 |
-
* @param string $time
|
| 1109 |
-
* @return Copernica_MarketingSoftware_Helper_Config
|
| 1110 |
-
*/
|
| 1111 |
-
public function setAbandonedLastCheck($time = null)
|
| 1112 |
-
{
|
| 1113 |
-
$this->_setConfig('lastAbandonedCheck', $time ? $time : date("Y-m-d H:i:s"));
|
| 1114 |
-
|
| 1115 |
-
return $this;
|
| 1116 |
-
}
|
| 1117 |
-
|
| 1118 |
-
/**
|
| 1119 |
-
* Set number of minutes that have to pass from last quote item update to consider
|
| 1120 |
-
* cart abandonded.
|
| 1121 |
-
*
|
| 1122 |
-
* @param int $timeout
|
| 1123 |
-
* @return Copernica_MarketingSoftware_Helper_Config
|
| 1124 |
-
*/
|
| 1125 |
-
public function setAbandonedTimeout($timeout)
|
| 1126 |
-
{
|
| 1127 |
-
$this->_setConfig('abandondedTimeout', $timeout);
|
| 1128 |
-
|
| 1129 |
-
return $this;
|
| 1130 |
-
}
|
| 1131 |
-
|
| 1132 |
-
/**
|
| 1133 |
-
* Get number of minutes that have to pass from last quote item update to consider
|
| 1134 |
-
* cart abandonded.
|
| 1135 |
-
*
|
| 1136 |
-
* @return int
|
| 1137 |
-
*/
|
| 1138 |
-
public function getAbandonedTimeout()
|
| 1139 |
-
{
|
| 1140 |
-
$timeout = $this->_getConfig('abandondedTimeout');
|
| 1141 |
-
|
| 1142 |
-
return is_numeric($timeout) ? $timeout : 90;
|
| 1143 |
-
}
|
| 1144 |
-
|
| 1145 |
-
/**
|
| 1146 |
-
* Carts older than supplied number of minutes will not be synchronized
|
| 1147 |
-
* with Copernica.
|
| 1148 |
-
*
|
| 1149 |
-
* @param int $timeout
|
| 1150 |
-
* @return Copernica_MarketingSoftware_Helper_Config
|
| 1151 |
-
*/
|
| 1152 |
-
public function setAbandonedPeriod($timeout)
|
| 1153 |
-
{
|
| 1154 |
-
$this->_setConfig('abandondedPeriod', $timeout);
|
| 1155 |
-
|
| 1156 |
-
return $this;
|
| 1157 |
-
}
|
| 1158 |
-
|
| 1159 |
-
/**
|
| 1160 |
-
* Carts older than supplied number of minutes will not be synchronized
|
| 1161 |
-
* with Copernica.
|
| 1162 |
-
*
|
| 1163 |
-
* @return int
|
| 1164 |
-
*/
|
| 1165 |
-
public function getAbandonedPeriod()
|
| 1166 |
-
{
|
| 1167 |
-
$timeout = $this->_getConfig('abandondedPeriod');
|
| 1168 |
-
|
| 1169 |
-
return is_numeric($timeout) ? $timeout : 21600;
|
| 1170 |
-
}
|
| 1171 |
-
|
| 1172 |
-
/**
|
| 1173 |
-
* Should finished (removed or ordered) quote item be removed from profile?
|
| 1174 |
-
*
|
| 1175 |
-
* @param boolean $remove
|
| 1176 |
-
* @return Copernica_MarketingSoftware_Helper_Config
|
| 1177 |
-
*/
|
| 1178 |
-
public function setRemoveFinishedQuoteItem($remove)
|
| 1179 |
-
{
|
| 1180 |
-
$this->_setConfig('removeFinished', $remove ? 1 : 0);
|
| 1181 |
-
|
| 1182 |
-
return $this;
|
| 1183 |
-
}
|
| 1184 |
-
|
| 1185 |
-
/**
|
| 1186 |
-
* Should finished (removed or ordered) quote item be removed from profile?
|
| 1187 |
-
*
|
| 1188 |
-
* @return bool
|
| 1189 |
-
*/
|
| 1190 |
-
public function getRemoveFinishedQuoteItem()
|
| 1191 |
-
{
|
| 1192 |
-
return (bool)$this->_getConfig('removeFinished');
|
| 1193 |
-
}
|
| 1194 |
-
|
| 1195 |
-
/**
|
| 1196 |
-
* This method will purge all data about linked collections.
|
| 1197 |
-
*/
|
| 1198 |
-
public function clearLinkedCollections()
|
| 1199 |
-
{
|
| 1200 |
-
$this->unsQuoteItemCollectionName();
|
| 1201 |
-
$this->unsQuoteItemCollectionId();
|
| 1202 |
-
$this->unsLinkedQuoteItemFields();
|
| 1203 |
-
|
| 1204 |
-
$this->unsOrdersCollectionName();
|
| 1205 |
-
$this->unsOrdersCollectionId();
|
| 1206 |
-
$this->unsLinkedOrderFields();
|
| 1207 |
-
|
| 1208 |
-
$this->unsOrderItemCollectionName();
|
| 1209 |
-
$this->unsOrderItemCollectionId();
|
| 1210 |
-
$this->unsLinkedOrderItemFields();
|
| 1211 |
-
|
| 1212 |
-
$this->unsAddressCollectionName();
|
| 1213 |
-
$this->unsAddressCollectionId();
|
| 1214 |
-
$this->unsLinkedAddressFields();
|
| 1215 |
-
|
| 1216 |
-
$this->unsViewedProductCollectionName();
|
| 1217 |
-
$this->unsViewedProductCollectionId();
|
| 1218 |
-
$this->unsLinkedViewedProductFields();
|
| 1219 |
-
|
| 1220 |
-
$this->unsWishlistItemCollectionName();
|
| 1221 |
-
$this->unsWishlistItemCollectionId();
|
| 1222 |
-
$this->unsLinkedWishlistItemFields();
|
| 1223 |
-
}
|
| 1224 |
}
|
| 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 |
+
* Copernica config helper
|
| 29 |
+
*
|
| 30 |
+
* @todo check if this clas can be better...
|
| 31 |
+
*/
|
| 32 |
+
class Copernica_MarketingSoftware_Helper_Config extends Mage_Core_Helper_Abstract
|
| 33 |
+
{
|
| 34 |
+
/**
|
| 35 |
+
* Define a prefix used for the config
|
| 36 |
+
*
|
| 37 |
+
* @name CONFIG_BASE
|
| 38 |
+
*/
|
| 39 |
+
const CONFIG_BASE = 'marketingsoftware/';
|
| 40 |
+
|
| 41 |
+
/**
|
| 42 |
+
* Holds a list of previously requested key names
|
| 43 |
+
*
|
| 44 |
+
* @var array
|
| 45 |
+
*/
|
| 46 |
+
protected static $_keyNameCache = array();
|
| 47 |
+
|
| 48 |
+
/**
|
| 49 |
+
* List of already requested or used config entries
|
| 50 |
+
*
|
| 51 |
+
* @var array
|
| 52 |
+
*/
|
| 53 |
+
protected static $_configEntryCache = array();
|
| 54 |
+
|
| 55 |
+
/**
|
| 56 |
+
* Magic method to get configurations from the database
|
| 57 |
+
*
|
| 58 |
+
* @param string $method
|
| 59 |
+
* @param array $params
|
| 60 |
+
* @return string
|
| 61 |
+
*/
|
| 62 |
+
public function __call($method, $params)
|
| 63 |
+
{
|
| 64 |
+
switch (substr($method, 0, 3)) {
|
| 65 |
+
case 'get':
|
| 66 |
+
$key = $this->_toKeyName(substr($method, 3));
|
| 67 |
+
return $this->_getCustomConfig($key);
|
| 68 |
+
|
| 69 |
+
break;
|
| 70 |
+
|
| 71 |
+
case 'set':
|
| 72 |
+
if (!isset($params) || !isset($params[0])) {
|
| 73 |
+
return false;
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
$key = $this->_toKeyName(substr($method, 3));
|
| 77 |
+
$this->_setCustomConfig($key, $params[0]);
|
| 78 |
+
|
| 79 |
+
break;
|
| 80 |
+
|
| 81 |
+
case 'has':
|
| 82 |
+
$key = $this->_toKeyName(substr($method, 3));
|
| 83 |
+
return $this->_hasCustomConfig($key);
|
| 84 |
+
|
| 85 |
+
break;
|
| 86 |
+
|
| 87 |
+
case 'uns':
|
| 88 |
+
$key = $this->_toKeyName(substr($method, 3));
|
| 89 |
+
$model = $this->_getModel($key);
|
| 90 |
+
|
| 91 |
+
if ($model !== false) {
|
| 92 |
+
try {
|
| 93 |
+
$model->delete();
|
| 94 |
+
|
| 95 |
+
if (isset(self::$_configEntryCache[$key])) {
|
| 96 |
+
self::$_configEntryCache[$key] = null;
|
| 97 |
+
}
|
| 98 |
+
} catch (Exception $e) {
|
| 99 |
+
Mage::log('Marketingsoftware Config: ' . $e->getMessage());
|
| 100 |
+
}
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
break;
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
return false;
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
/**
|
| 110 |
+
* Tries to get config value from custom config table
|
| 111 |
+
*
|
| 112 |
+
* @param string $key
|
| 113 |
+
* @return string
|
| 114 |
+
*/
|
| 115 |
+
protected function _getCustomConfig($key)
|
| 116 |
+
{
|
| 117 |
+
if (isset(self::$_configEntryCache[$key])) {
|
| 118 |
+
return self::$_configEntryCache[$key];
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
$model = $this->_getModel($key);
|
| 122 |
+
|
| 123 |
+
if ($model !== false) {
|
| 124 |
+
return $model->getValue();
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
return null;
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
/**
|
| 131 |
+
* Sets a config entry in the custom config tab
|
| 132 |
+
*
|
| 133 |
+
* @param string $key
|
| 134 |
+
* @param string $value
|
| 135 |
+
*/
|
| 136 |
+
protected function _setCustomConfig($key, $value)
|
| 137 |
+
{
|
| 138 |
+
$model = $this->_getModel($key);
|
| 139 |
+
|
| 140 |
+
if ($model === false) {
|
| 141 |
+
$model = Mage::getModel('marketingsoftware/config');
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
try {
|
| 145 |
+
$model->setKeyName($key);
|
| 146 |
+
$model->setValue($value);
|
| 147 |
+
$model->save();
|
| 148 |
+
|
| 149 |
+
self::$_configEntryCache[$key] = $model->getValue();
|
| 150 |
+
|
| 151 |
+
return $model->getValue();
|
| 152 |
+
} catch (Exception $e) {
|
| 153 |
+
Mage::log('Marketingsoftware Config: ' . $e->getMessage());
|
| 154 |
+
}
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
/**
|
| 158 |
+
* Checks if an entry exists in the custom config table
|
| 159 |
+
*
|
| 160 |
+
* @param string $key
|
| 161 |
+
* @return boolean
|
| 162 |
+
*/
|
| 163 |
+
protected function _hasCustomConfig($key)
|
| 164 |
+
{
|
| 165 |
+
return ((isset(self::$_configEntryCache[$key]) && !empty(self::$_configEntryCache[$key])) || ($this->_getModel($key) !== false));
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
/**
|
| 169 |
+
* Loads the requested model config object if possible
|
| 170 |
+
*
|
| 171 |
+
* @param string $key
|
| 172 |
+
* @return Copernica_MarketingSoftware_Model_Config
|
| 173 |
+
*/
|
| 174 |
+
protected function _getModel($key)
|
| 175 |
+
{
|
| 176 |
+
$model = Mage::getModel('marketingsoftware/config')->loadByKey($key);
|
| 177 |
+
|
| 178 |
+
if ($model && $model->getId()) {
|
| 179 |
+
self::$_configEntryCache[$key] = $model->getValue();
|
| 180 |
+
|
| 181 |
+
return $model;
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
return false;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
/**
|
| 188 |
+
* Prepends uppercase characters with underscores and lowers
|
| 189 |
+
* the whole string
|
| 190 |
+
*
|
| 191 |
+
* @param string $name
|
| 192 |
+
* @return string
|
| 193 |
+
*/
|
| 194 |
+
protected function _toKeyName($name)
|
| 195 |
+
{
|
| 196 |
+
if (isset(self::$_keyNameCache[$name])) {
|
| 197 |
+
return self::$_keyNameCache[$name];
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
$result = strtolower(preg_replace('/(.)([A-Z])/', "$1_$2", $name));
|
| 201 |
+
|
| 202 |
+
self::$_keyNameCache[$name] = $result;
|
| 203 |
+
return $result;
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
/**
|
| 207 |
+
* Get the config item from the custom config table, otherwise from
|
| 208 |
+
* the basic magento component.
|
| 209 |
+
*
|
| 210 |
+
* @param string $name
|
| 211 |
+
*/
|
| 212 |
+
protected function _getConfig($name)
|
| 213 |
+
{
|
| 214 |
+
return $this->_getCustomConfig($name);
|
| 215 |
+
|
| 216 |
+
if ($this->_hasCustomConfig($name)) {
|
| 217 |
+
return $this->_getCustomConfig($name);
|
| 218 |
+
} else {
|
| 219 |
+
return (string) Mage::getConfig()->getNode(self::CONFIG_BASE . $name, 'default', 0);
|
| 220 |
+
}
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
+
/**
|
| 224 |
+
* Set the config item from the basic magento component
|
| 225 |
+
*
|
| 226 |
+
* @param string $name
|
| 227 |
+
* @param string $value
|
| 228 |
+
*/
|
| 229 |
+
protected function _setConfig($name, $value)
|
| 230 |
+
{
|
| 231 |
+
if ($value === $this->_getConfig($name)) {
|
| 232 |
+
return;
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
$this->_setCustomConfig($name, $value);
|
| 236 |
+
|
| 237 |
+
// Some config items are not needed
|
| 238 |
+
if (in_array($name, array(
|
| 239 |
+
'customer_progress_status',
|
| 240 |
+
'order_progress_status',
|
| 241 |
+
'subscription_progress_status',
|
| 242 |
+
'cronjob_starttime',
|
| 243 |
+
'cronjob_endtime',
|
| 244 |
+
'cronjob_processedtasks',
|
| 245 |
+
))) return;
|
| 246 |
+
|
| 247 |
+
$this->setCustomerProgressStatus('0');
|
| 248 |
+
|
| 249 |
+
$this->setOrderProgressStatus('0');
|
| 250 |
+
|
| 251 |
+
$this->setSubscriptionProgressStatus('0');
|
| 252 |
+
}
|
| 253 |
+
|
| 254 |
+
/**
|
| 255 |
+
* Check if store is enabled.
|
| 256 |
+
*
|
| 257 |
+
* @param int
|
| 258 |
+
* @return bool
|
| 259 |
+
*/
|
| 260 |
+
public function isEnabledStore($storeId)
|
| 261 |
+
{
|
| 262 |
+
$stores = @unserialize($this->_getConfig('enabled_stores'));
|
| 263 |
+
|
| 264 |
+
if (!is_array($stores)) {
|
| 265 |
+
return true;
|
| 266 |
+
}
|
| 267 |
+
|
| 268 |
+
return in_array($storeId, $stores);
|
| 269 |
+
}
|
| 270 |
+
|
| 271 |
+
/**
|
| 272 |
+
* Set stores. Pass null to disable store filtering.
|
| 273 |
+
*
|
| 274 |
+
* @param array|null
|
| 275 |
+
* @return Copernica_MarketingSoftware_Helper_Config
|
| 276 |
+
*/
|
| 277 |
+
public function setEnabledStores($collectionOfStoresId)
|
| 278 |
+
{
|
| 279 |
+
$this->_setConfig('enabled_stores', serialize($collectionOfStoresId));
|
| 280 |
+
|
| 281 |
+
return $this;
|
| 282 |
+
}
|
| 283 |
+
|
| 284 |
+
/**
|
| 285 |
+
* Get list of enabled stores
|
| 286 |
+
*
|
| 287 |
+
* @return array|null
|
| 288 |
+
*/
|
| 289 |
+
public function getEnabledStores()
|
| 290 |
+
{
|
| 291 |
+
return unserialize($this->_getConfig('enabled_stores'));
|
| 292 |
+
}
|
| 293 |
+
|
| 294 |
+
/**
|
| 295 |
+
* Get the hostname from the config
|
| 296 |
+
*
|
| 297 |
+
* @return string
|
| 298 |
+
*/
|
| 299 |
+
public function getHostname()
|
| 300 |
+
{
|
| 301 |
+
return $this->_getConfig('hostname');
|
| 302 |
+
}
|
| 303 |
+
|
| 304 |
+
/**
|
| 305 |
+
* Set the hostname from the config
|
| 306 |
+
*
|
| 307 |
+
* @return Copernica_MarketingSoftware_Helper_Config
|
| 308 |
+
*/
|
| 309 |
+
public function setHostname($value)
|
| 310 |
+
{
|
| 311 |
+
$this->_setConfig('hostname', $value);
|
| 312 |
+
|
| 313 |
+
return $this;
|
| 314 |
+
}
|
| 315 |
+
|
| 316 |
+
/**
|
| 317 |
+
* Get the name of the database
|
| 318 |
+
*
|
| 319 |
+
* @return string
|
| 320 |
+
*/
|
| 321 |
+
public function getDatabaseName()
|
| 322 |
+
{
|
| 323 |
+
return $this->_getConfig('database');
|
| 324 |
+
}
|
| 325 |
+
|
| 326 |
+
/**
|
| 327 |
+
* Set the name of the database
|
| 328 |
+
*
|
| 329 |
+
* @param string $value
|
| 330 |
+
* @return Copernica_MarketingSoftware_Helper_Config
|
| 331 |
+
*/
|
| 332 |
+
public function setDatabaseName($value)
|
| 333 |
+
{
|
| 334 |
+
$this->_setConfig('database', $value);
|
| 335 |
+
|
| 336 |
+
return $this;
|
| 337 |
+
}
|
| 338 |
+
|
| 339 |
+
/**
|
| 340 |
+
* Get the linked customer fields
|
| 341 |
+
*
|
| 342 |
+
* @return array
|
| 343 |
+
*/
|
| 344 |
+
public function getLinkedCustomerFields()
|
| 345 |
+
{
|
| 346 |
+
$value = $this->_getConfig('linked_customer_fields');
|
| 347 |
+
$value = empty($value) ? array() : json_decode($value, true);
|
| 348 |
+
|
| 349 |
+
if (!isset($value['customer_email'])) {
|
| 350 |
+
return $value;
|
| 351 |
+
}
|
| 352 |
+
|
| 353 |
+
$oldValues = $value;
|
| 354 |
+
|
| 355 |
+
$newValues = array();
|
| 356 |
+
|
| 357 |
+
foreach ($oldValues as $key => $value) {
|
| 358 |
+
$key = str_replace('customer_', '', $key);
|
| 359 |
+
|
| 360 |
+
$newValues[$key] = $value;
|
| 361 |
+
}
|
| 362 |
+
|
| 363 |
+
$this->setLinkedCustomerFields($newValues);
|
| 364 |
+
|
| 365 |
+
return $newValues;
|
| 366 |
+
}
|
| 367 |
+
|
| 368 |
+
/**
|
| 369 |
+
* Set the linked customer fields
|
| 370 |
+
*
|
| 371 |
+
* @param array $value
|
| 372 |
+
* @return Copernica_MarketingSoftware_Helper_Config
|
| 373 |
+
*/
|
| 374 |
+
public function setLinkedCustomerFields($value)
|
| 375 |
+
{
|
| 376 |
+
$this->_setConfig('linked_customer_fields', json_encode($value), true);
|
| 377 |
+
|
| 378 |
+
return $this;
|
| 379 |
+
}
|
| 380 |
+
|
| 381 |
+
/**
|
| 382 |
+
* Get the id of the quote item collection
|
| 383 |
+
*
|
| 384 |
+
* @return int
|
| 385 |
+
*/
|
| 386 |
+
public function getQuoteItemCollectionId()
|
| 387 |
+
{
|
| 388 |
+
$id = $this->_getConfig('quote_item_collection_id');
|
| 389 |
+
|
| 390 |
+
if ($id) {
|
| 391 |
+
return $id;
|
| 392 |
+
}
|
| 393 |
+
|
| 394 |
+
$name = $this->getQuoteItemCollectionName();
|
| 395 |
+
|
| 396 |
+
if (!$name) {
|
| 397 |
+
return null;
|
| 398 |
+
}
|
| 399 |
+
|
| 400 |
+
$id = Mage::helper('marketingsoftware/api_abstract')->getCollectionId($name);
|
| 401 |
+
|
| 402 |
+
if (!$id) {
|
| 403 |
+
return null;
|
| 404 |
+
}
|
| 405 |
+
|
| 406 |
+
$this->_setConfig('quote_item_collection_id', $id);
|
| 407 |
+
|
| 408 |
+
return $id;
|
| 409 |
+
}
|
| 410 |
+
|
| 411 |
+
/**
|
| 412 |
+
* Get the name of the quote item collection
|
| 413 |
+
*
|
| 414 |
+
* @return string
|
| 415 |
+
*/
|
| 416 |
+
public function getQuoteItemCollectionName()
|
| 417 |
+
{
|
| 418 |
+
return $this->_getConfig('quote_item_collection_name');
|
| 419 |
+
}
|
| 420 |
+
|
| 421 |
+
/**
|
| 422 |
+
* Set the name of the quote item collection
|
| 423 |
+
*
|
| 424 |
+
* @param string $value
|
| 425 |
+
* @return Copernica_MarketingSoftware_Helper_Config
|
| 426 |
+
*/
|
| 427 |
+
public function setQuoteItemCollectionName($value)
|
| 428 |
+
{
|
| 429 |
+
$this->_setConfig('quote_item_collection_name', $value);
|
| 430 |
+
|
| 431 |
+
return $this;
|
| 432 |
+
}
|
| 433 |
+
|
| 434 |
+
/**
|
| 435 |
+
* Get the linked quote item fields
|
| 436 |
+
*
|
| 437 |
+
* @return array
|
| 438 |
+
*/
|
| 439 |
+
public function getLinkedQuoteItemFields()
|
| 440 |
+
{
|
| 441 |
+
$value = $this->_getConfig('linked_quote_item_fields');
|
| 442 |
+
|
| 443 |
+
if (empty($value)) {
|
| 444 |
+
return array();
|
| 445 |
+
} else {
|
| 446 |
+
return json_decode($value, true);
|
| 447 |
+
}
|
| 448 |
+
}
|
| 449 |
+
|
| 450 |
+
/**
|
| 451 |
+
* Get the linked quote item fields
|
| 452 |
+
*
|
| 453 |
+
* @param array $value
|
| 454 |
+
* @return Copernica_MarketingSoftware_Helper_Config
|
| 455 |
+
*/
|
| 456 |
+
public function setLinkedQuoteItemFields($value)
|
| 457 |
+
{
|
| 458 |
+
$this->_setConfig('linked_quote_item_fields', json_encode($value), true);
|
| 459 |
+
|
| 460 |
+
return $this;
|
| 461 |
+
}
|
| 462 |
+
|
| 463 |
+
/**
|
| 464 |
+
* Get the name of the orders collection
|
| 465 |
+
*
|
| 466 |
+
* @return string
|
| 467 |
+
*/
|
| 468 |
+
public function getOrdersCollectionName()
|
| 469 |
+
{
|
| 470 |
+
return $this->_getConfig('orders_collection_name');
|
| 471 |
+
}
|
| 472 |
+
|
| 473 |
+
/**
|
| 474 |
+
* Get the id of the orders collection
|
| 475 |
+
*
|
| 476 |
+
* @return int
|
| 477 |
+
*/
|
| 478 |
+
public function getOrdersCollectionId()
|
| 479 |
+
{
|
| 480 |
+
$id = $this->_getConfig('orders_collection_id');
|
| 481 |
+
|
| 482 |
+
if ($id) {
|
| 483 |
+
return $id;
|
| 484 |
+
}
|
| 485 |
+
|
| 486 |
+
$name = $this->getOrdersCollectionName();
|
| 487 |
+
|
| 488 |
+
if (!$name) {
|
| 489 |
+
return null;
|
| 490 |
+
}
|
| 491 |
+
|
| 492 |
+
$id = Mage::helper('marketingsoftware/api_abstract')->getCollectionId($name);
|
| 493 |
+
|
| 494 |
+
if (!$id) {
|
| 495 |
+
return null;
|
| 496 |
+
}
|
| 497 |
+
|
| 498 |
+
$this->_setConfig('orders_collection_id', $id);
|
| 499 |
+
|
| 500 |
+
return $id;
|
| 501 |
+
}
|
| 502 |
+
|
| 503 |
+
/**
|
| 504 |
+
* Set the name of the orders collection
|
| 505 |
+
*
|
| 506 |
+
* @param string $value
|
| 507 |
+
* @return Copernica_MarketingSoftware_Helper_Config
|
| 508 |
+
*/
|
| 509 |
+
public function setOrdersCollectionName($value)
|
| 510 |
+
{
|
| 511 |
+
$this->_setConfig('orders_collection_name', $value);
|
| 512 |
+
|
| 513 |
+
return $this;
|
| 514 |
+
}
|
| 515 |
+
|
| 516 |
+
/**
|
| 517 |
+
* Get the linked order fields
|
| 518 |
+
*
|
| 519 |
+
* @return array
|
| 520 |
+
*/
|
| 521 |
+
public function getLinkedOrderFields()
|
| 522 |
+
{
|
| 523 |
+
$value = $this->_getConfig('linked_order_fields');
|
| 524 |
+
$value = empty($value) ? array() : json_decode($value, true);
|
| 525 |
+
|
| 526 |
+
if (!isset($value['order_timestamp'])) {
|
| 527 |
+
return $value;
|
| 528 |
+
}
|
| 529 |
+
|
| 530 |
+
$oldValues = $value;
|
| 531 |
+
|
| 532 |
+
$newValues = array();
|
| 533 |
+
|
| 534 |
+
foreach ($oldValues as $key => $value) {
|
| 535 |
+
$key = ($key == 'order_qty') ? 'quantity' : str_replace('order_', '', $key);
|
| 536 |
+
|
| 537 |
+
$newValues[$key] = $value;
|
| 538 |
+
}
|
| 539 |
+
|
| 540 |
+
$this->setLinkedOrderFields($newValues);
|
| 541 |
+
|
| 542 |
+
return $newValues;
|
| 543 |
+
}
|
| 544 |
+
|
| 545 |
+
/**
|
| 546 |
+
* Set the linked order fields
|
| 547 |
+
*
|
| 548 |
+
* @param array $value
|
| 549 |
+
* @return Copernica_MarketingSoftware_Helper_Config
|
| 550 |
+
*/
|
| 551 |
+
public function setLinkedOrderFields($value)
|
| 552 |
+
{
|
| 553 |
+
$this->_setConfig('linked_order_fields', json_encode($value), true);
|
| 554 |
+
|
| 555 |
+
return $this;
|
| 556 |
+
}
|
| 557 |
+
|
| 558 |
+
/**
|
| 559 |
+
* Get the name of the collection were all the orders are stored
|
| 560 |
+
*
|
| 561 |
+
* @return string
|
| 562 |
+
*/
|
| 563 |
+
public function getOrderItemCollectionName()
|
| 564 |
+
{
|
| 565 |
+
return $this->_getConfig('order_item_collection_name');
|
| 566 |
+
}
|
| 567 |
+
|
| 568 |
+
/**
|
| 569 |
+
* Get the id of the order item collection
|
| 570 |
+
*
|
| 571 |
+
* @return int
|
| 572 |
+
*/
|
| 573 |
+
public function getOrderItemCollectionId()
|
| 574 |
+
{
|
| 575 |
+
$id = $this->_getConfig('order_item_collection_id');
|
| 576 |
+
|
| 577 |
+
if ($id) {
|
| 578 |
+
return $id;
|
| 579 |
+
}
|
| 580 |
+
|
| 581 |
+
$name = $this->getOrderItemCollectionName();
|
| 582 |
+
|
| 583 |
+
if (!$name) {
|
| 584 |
+
return null;
|
| 585 |
+
}
|
| 586 |
+
|
| 587 |
+
$id = Mage::helper('marketingsoftware/api_abstract')->getCollectionId($name);
|
| 588 |
+
|
| 589 |
+
if (!$id) {
|
| 590 |
+
return null;
|
| 591 |
+
}
|
| 592 |
+
|
| 593 |
+
$this->_setConfig('order_item_collection_id', $id);
|
| 594 |
+
|
| 595 |
+
return $id;
|
| 596 |
+
}
|
| 597 |
+
|
| 598 |
+
/**
|
| 599 |
+
* Get the name of the collection were all the orders are stored
|
| 600 |
+
*
|
| 601 |
+
* @param string
|
| 602 |
+
*/
|
| 603 |
+
public function setOrderItemCollectionName($value)
|
| 604 |
+
{
|
| 605 |
+
$this->_setConfig('order_item_collection_name', $value);
|
| 606 |
+
|
| 607 |
+
return $this;
|
| 608 |
+
}
|
| 609 |
+
|
| 610 |
+
/**
|
| 611 |
+
* Get the linked order item fields
|
| 612 |
+
*
|
| 613 |
+
* @return array
|
| 614 |
+
*/
|
| 615 |
+
public function getLinkedOrderItemFields()
|
| 616 |
+
{
|
| 617 |
+
$value = $this->_getConfig('linked_order_item_fields');
|
| 618 |
+
$value = empty($value) ? array() : json_decode($value, true);
|
| 619 |
+
|
| 620 |
+
if (!isset($value['product_internal_id'])) {
|
| 621 |
+
return $value;
|
| 622 |
+
}
|
| 623 |
+
|
| 624 |
+
$oldValues = $value;
|
| 625 |
+
|
| 626 |
+
$newValues = array();
|
| 627 |
+
|
| 628 |
+
foreach ($oldValues as $key => $value) {
|
| 629 |
+
switch($key) {
|
| 630 |
+
case 'product_qty':
|
| 631 |
+
$key = 'quantity';
|
| 632 |
+
break;
|
| 633 |
+
|
| 634 |
+
case 'product_base_row_total':
|
| 635 |
+
$key = 'total_price';
|
| 636 |
+
break;
|
| 637 |
+
|
| 638 |
+
default:
|
| 639 |
+
$key = str_replace('product_', '', $key);
|
| 640 |
+
break;
|
| 641 |
+
}
|
| 642 |
+
|
| 643 |
+
$newValues[$key] = $value;
|
| 644 |
+
}
|
| 645 |
+
|
| 646 |
+
$this->setLinkedOrderItemFields($newValues);
|
| 647 |
+
|
| 648 |
+
return $newValues;
|
| 649 |
+
}
|
| 650 |
+
|
| 651 |
+
/**
|
| 652 |
+
* Set the linked order item fields
|
| 653 |
+
*
|
| 654 |
+
* @param array $value
|
| 655 |
+
* @return Copernica_MarketingSoftware_Helper_Config
|
| 656 |
+
*/
|
| 657 |
+
public function setLinkedOrderItemFields($value)
|
| 658 |
+
{
|
| 659 |
+
$this->_setConfig('linked_order_item_fields', json_encode($value), true);
|
| 660 |
+
|
| 661 |
+
return $this;
|
| 662 |
+
}
|
| 663 |
+
|
| 664 |
+
/**
|
| 665 |
+
* Get the address collection name
|
| 666 |
+
*
|
| 667 |
+
* @return string
|
| 668 |
+
*/
|
| 669 |
+
public function getAddressesCollectionName()
|
| 670 |
+
{
|
| 671 |
+
return $this->_getConfig('address_collection_name');
|
| 672 |
+
}
|
| 673 |
+
|
| 674 |
+
/**
|
| 675 |
+
* Get the id of the address collection
|
| 676 |
+
* @return int
|
| 677 |
+
*/
|
| 678 |
+
public function getAddressesCollectionId()
|
| 679 |
+
{
|
| 680 |
+
$id = $this->_getConfig('address_collection_id');
|
| 681 |
+
|
| 682 |
+
if ($id) {
|
| 683 |
+
return $id;
|
| 684 |
+
}
|
| 685 |
+
|
| 686 |
+
$name = $this->getAddressesCollectionName();
|
| 687 |
+
|
| 688 |
+
if (!$name) {
|
| 689 |
+
return null;
|
| 690 |
+
}
|
| 691 |
+
|
| 692 |
+
$id = Mage::helper('marketingsoftware/api_abstract')->getCollectionId($name);
|
| 693 |
+
|
| 694 |
+
if (!$id) {
|
| 695 |
+
return null;
|
| 696 |
+
}
|
| 697 |
+
|
| 698 |
+
$this->_setConfig('address_collection_id', $id);
|
| 699 |
+
|
| 700 |
+
return $id;
|
| 701 |
+
}
|
| 702 |
+
|
| 703 |
+
/**
|
| 704 |
+
* Set the name of the collection with addresses
|
| 705 |
+
*/
|
| 706 |
+
public function setAddressCollectionName($value)
|
| 707 |
+
{
|
| 708 |
+
$this->_setConfig('address_collection_name', $value);
|
| 709 |
+
|
| 710 |
+
return $this;
|
| 711 |
+
}
|
| 712 |
+
|
| 713 |
+
/**
|
| 714 |
+
* Get the linked address fields
|
| 715 |
+
*
|
| 716 |
+
* @return array
|
| 717 |
+
*/
|
| 718 |
+
public function getLinkedAddressFields()
|
| 719 |
+
{
|
| 720 |
+
$value = $this->_getConfig('linked_address_fields');
|
| 721 |
+
$value = empty($value) ? array() : json_decode($value, true);
|
| 722 |
+
|
| 723 |
+
if (!isset($value['address_firstname'])) {
|
| 724 |
+
return $value;
|
| 725 |
+
}
|
| 726 |
+
|
| 727 |
+
$oldValues = $value;
|
| 728 |
+
|
| 729 |
+
$newValues = array();
|
| 730 |
+
|
| 731 |
+
foreach ($oldValues as $key => $value) {
|
| 732 |
+
$key = str_replace('address_', '', $key);
|
| 733 |
+
|
| 734 |
+
$newValues[$key] = $value;
|
| 735 |
+
}
|
| 736 |
+
|
| 737 |
+
$this->setLinkedAddressFields($newValues);
|
| 738 |
+
|
| 739 |
+
return $newValues;
|
| 740 |
+
}
|
| 741 |
+
|
| 742 |
+
/**
|
| 743 |
+
* set the linked address fields
|
| 744 |
+
*
|
| 745 |
+
* @param array $value
|
| 746 |
+
* @return Copernica_MarketingSoftware_Helper_Config
|
| 747 |
+
*/
|
| 748 |
+
public function setLinkedAddressFields($value)
|
| 749 |
+
{
|
| 750 |
+
$this->_setConfig('linked_address_fields', json_encode($value), true);
|
| 751 |
+
|
| 752 |
+
return $this;
|
| 753 |
+
}
|
| 754 |
+
|
| 755 |
+
/**
|
| 756 |
+
* Get the name of the viewed products collection
|
| 757 |
+
*
|
| 758 |
+
* @return string
|
| 759 |
+
*/
|
| 760 |
+
public function getViewedProductCollectionName()
|
| 761 |
+
{
|
| 762 |
+
return $this->_getConfig('viewed_product_collection_name');
|
| 763 |
+
}
|
| 764 |
+
|
| 765 |
+
/**
|
| 766 |
+
* Get the id of the address collection
|
| 767 |
+
*
|
| 768 |
+
* @return int
|
| 769 |
+
*/
|
| 770 |
+
public function getViewedProductCollectionId()
|
| 771 |
+
{
|
| 772 |
+
$id = $this->_getConfig('viewed_product_collection_id');
|
| 773 |
+
|
| 774 |
+
if ($id) {
|
| 775 |
+
return $id;
|
| 776 |
+
}
|
| 777 |
+
|
| 778 |
+
$name = $this->getViewedProductCollectionName();
|
| 779 |
+
|
| 780 |
+
if (!$name) {
|
| 781 |
+
return null;
|
| 782 |
+
}
|
| 783 |
+
|
| 784 |
+
$id = Mage::helper('marketingsoftware/api_abstract')->getCollectionId($name);
|
| 785 |
+
|
| 786 |
+
if (!$id) {
|
| 787 |
+
return null;
|
| 788 |
+
}
|
| 789 |
+
|
| 790 |
+
$this->_setConfig('viewed_product_collection_id', $id);
|
| 791 |
+
|
| 792 |
+
return $id;
|
| 793 |
+
}
|
| 794 |
+
|
| 795 |
+
/**
|
| 796 |
+
* Set the name of the viewed products collection
|
| 797 |
+
*
|
| 798 |
+
* @param string $value
|
| 799 |
+
* @return Copernica_MarketingSoftware_Helper_Config
|
| 800 |
+
*/
|
| 801 |
+
public function setViewedProductCollectionName($value)
|
| 802 |
+
{
|
| 803 |
+
$this->_setConfig('viewed_product_collection_name', $value);
|
| 804 |
+
|
| 805 |
+
return $this;
|
| 806 |
+
}
|
| 807 |
+
|
| 808 |
+
/**
|
| 809 |
+
* Get the linked customer fields
|
| 810 |
+
*
|
| 811 |
+
* @return array
|
| 812 |
+
*/
|
| 813 |
+
public function getLinkedViewedProductFields()
|
| 814 |
+
{
|
| 815 |
+
$value = $this->_getConfig('linked_viewed_product_fields');
|
| 816 |
+
|
| 817 |
+
if (empty($value)) {
|
| 818 |
+
return array();
|
| 819 |
+
} else {
|
| 820 |
+
return json_decode($value, true);
|
| 821 |
+
}
|
| 822 |
+
}
|
| 823 |
+
|
| 824 |
+
/**
|
| 825 |
+
* Get the linked customer fields
|
| 826 |
+
*
|
| 827 |
+
* @param array $value
|
| 828 |
+
* @return Copernica_MarketingSoftware_Helper_Config
|
| 829 |
+
*/
|
| 830 |
+
public function setLinkedViewedProductFields($value)
|
| 831 |
+
{
|
| 832 |
+
$this->_setConfig('linked_viewed_product_fields', json_encode($value), true);
|
| 833 |
+
|
| 834 |
+
return $this;
|
| 835 |
+
}
|
| 836 |
+
|
| 837 |
+
/**
|
| 838 |
+
* Get the name of the wishlist item collection
|
| 839 |
+
*
|
| 840 |
+
* @return string
|
| 841 |
+
*/
|
| 842 |
+
public function getWishlistItemCollectionName()
|
| 843 |
+
{
|
| 844 |
+
return $this->_getConfig('wishlist_item_collection_name');
|
| 845 |
+
}
|
| 846 |
+
|
| 847 |
+
/**
|
| 848 |
+
* Get the id of the wishlist item collection
|
| 849 |
+
*
|
| 850 |
+
* @return int
|
| 851 |
+
*/
|
| 852 |
+
public function getWishlistItemCollectionId()
|
| 853 |
+
{
|
| 854 |
+
$id = $this->_getConfig('wishlist_item_collection_id');
|
| 855 |
+
|
| 856 |
+
if ($id) {
|
| 857 |
+
return $id;
|
| 858 |
+
}
|
| 859 |
+
|
| 860 |
+
$name = $this->getWishlistItemCollectionName();
|
| 861 |
+
|
| 862 |
+
if (!$name) {
|
| 863 |
+
return null;
|
| 864 |
+
}
|
| 865 |
+
|
| 866 |
+
$id = Mage::helper('marketingsoftware/api_abstract')->getCollectionId($name);
|
| 867 |
+
|
| 868 |
+
if (!$id) {
|
| 869 |
+
return null;
|
| 870 |
+
}
|
| 871 |
+
|
| 872 |
+
$this->_setConfig('wishlist_item_collection_id', $id);
|
| 873 |
+
|
| 874 |
+
return $id;
|
| 875 |
+
}
|
| 876 |
+
|
| 877 |
+
/**
|
| 878 |
+
* Set the name of the wishlist item collection
|
| 879 |
+
*
|
| 880 |
+
* @param string $value
|
| 881 |
+
* @return Copernica_MarketingSoftware_Helper_Config
|
| 882 |
+
*/
|
| 883 |
+
public function setWishlistItemCollectionName($value)
|
| 884 |
+
{
|
| 885 |
+
$this->_setConfig('wishlist_item_collection_name', $value);
|
| 886 |
+
|
| 887 |
+
return $this;
|
| 888 |
+
}
|
| 889 |
+
|
| 890 |
+
/**
|
| 891 |
+
* Get the linked wishlist item fields
|
| 892 |
+
*
|
| 893 |
+
* @return array
|
| 894 |
+
*/
|
| 895 |
+
public function getLinkedWishlistItemFields()
|
| 896 |
+
{
|
| 897 |
+
$value = $this->_getConfig('linked_wishlist_item_fields');
|
| 898 |
+
|
| 899 |
+
if (empty($value)) {
|
| 900 |
+
return array();
|
| 901 |
+
} else {
|
| 902 |
+
return json_decode($value, true);
|
| 903 |
+
}
|
| 904 |
+
}
|
| 905 |
+
|
| 906 |
+
/**
|
| 907 |
+
* Set the linked wishlist item fields
|
| 908 |
+
*
|
| 909 |
+
* @param array $value
|
| 910 |
+
* @return Copernica_MarketingSoftware_Helper_Config
|
| 911 |
+
*/
|
| 912 |
+
public function setLinkedWishlistItemFields($value)
|
| 913 |
+
{
|
| 914 |
+
$this->_setConfig('linked_wishlist_item_fields', json_encode($value), true);
|
| 915 |
+
|
| 916 |
+
return $this;
|
| 917 |
+
}
|
| 918 |
+
|
| 919 |
+
/**
|
| 920 |
+
* Get the progress status for customers
|
| 921 |
+
* This is the created timestamp of the most recent customer which has
|
| 922 |
+
* been queued for synchronisation
|
| 923 |
+
*
|
| 924 |
+
* @return datetime
|
| 925 |
+
*/
|
| 926 |
+
public function getCustomerProgressStatus()
|
| 927 |
+
{
|
| 928 |
+
return $this->_getConfig('customer_progress_status');
|
| 929 |
+
}
|
| 930 |
+
|
| 931 |
+
/**
|
| 932 |
+
* Set the progress status for customers
|
| 933 |
+
* This is the created timestamp of the most recent customer which has
|
| 934 |
+
* been queued for synchronisation
|
| 935 |
+
*
|
| 936 |
+
* @param datetime $value
|
| 937 |
+
* @return Copernica_MarketingSoftware_Helper_Config
|
| 938 |
+
*/
|
| 939 |
+
public function setCustomerProgressStatus($value)
|
| 940 |
+
{
|
| 941 |
+
$this->_setConfig('customer_progress_status', $value);
|
| 942 |
+
|
| 943 |
+
return $this;
|
| 944 |
+
}
|
| 945 |
+
|
| 946 |
+
/**
|
| 947 |
+
* Get the progress status for orders
|
| 948 |
+
* This is the created timestamp of the most recent order which has
|
| 949 |
+
* been queued for synchronisation
|
| 950 |
+
*
|
| 951 |
+
* @return datetime
|
| 952 |
+
*/
|
| 953 |
+
public function getOrderProgressStatus()
|
| 954 |
+
{
|
| 955 |
+
return $this->_getConfig('order_progress_status');
|
| 956 |
+
}
|
| 957 |
+
|
| 958 |
+
/**
|
| 959 |
+
* Set the progress status for orders
|
| 960 |
+
* This is the created timestamp of the most recent order which has
|
| 961 |
+
* been queued for synchronisation
|
| 962 |
+
*
|
| 963 |
+
* @param datetime $value
|
| 964 |
+
* @return Copernica_MarketingSoftware_Helper_Config
|
| 965 |
+
*/
|
| 966 |
+
public function setOrderProgressStatus($value)
|
| 967 |
+
{
|
| 968 |
+
$this->_setConfig('order_progress_status', $value);
|
| 969 |
+
|
| 970 |
+
return $this;
|
| 971 |
+
}
|
| 972 |
+
|
| 973 |
+
/**
|
| 974 |
+
* Get the progress status for subscriptions
|
| 975 |
+
* This is the created timestamp of the most recent subscription which has
|
| 976 |
+
* been queued for synchronisation
|
| 977 |
+
*
|
| 978 |
+
* @return datetime
|
| 979 |
+
*/
|
| 980 |
+
public function getSubscriptionProgressStatus()
|
| 981 |
+
{
|
| 982 |
+
return $this->_getConfig('subscription_progress_status');
|
| 983 |
+
}
|
| 984 |
+
|
| 985 |
+
/**
|
| 986 |
+
* Set the progress status for subscriptions
|
| 987 |
+
* This is the created timestamp of the most recent subscription which has
|
| 988 |
+
* been queued for synchronisation
|
| 989 |
+
*
|
| 990 |
+
* @param datetime $value
|
| 991 |
+
* @return Copernica_MarketingSoftware_Helper_Config
|
| 992 |
+
*/
|
| 993 |
+
public function setSubscriptionProgressStatus($value)
|
| 994 |
+
{
|
| 995 |
+
$this->_setConfig('subscription_progress_status', $value);
|
| 996 |
+
|
| 997 |
+
return $this;
|
| 998 |
+
}
|
| 999 |
+
|
| 1000 |
+
/**
|
| 1001 |
+
* Get the last start time of the cronjob.
|
| 1002 |
+
*
|
| 1003 |
+
* @return datetime
|
| 1004 |
+
*/
|
| 1005 |
+
public function getLastStartTimeCronjob()
|
| 1006 |
+
{
|
| 1007 |
+
return $this->_getConfig('cronjob_starttime');
|
| 1008 |
+
}
|
| 1009 |
+
|
| 1010 |
+
/**
|
| 1011 |
+
* Set the last start time of the cronjob.
|
| 1012 |
+
*
|
| 1013 |
+
* @param datetime $value
|
| 1014 |
+
* @return Copernica_MarketingSoftware_Helper_Config
|
| 1015 |
+
*/
|
| 1016 |
+
public function setLastStartTimeCronjob($value)
|
| 1017 |
+
{
|
| 1018 |
+
$this->_setConfig('cronjob_starttime', $value);
|
| 1019 |
+
|
| 1020 |
+
return $this;
|
| 1021 |
+
}
|
| 1022 |
+
|
| 1023 |
+
/**
|
| 1024 |
+
* Get the last end time of the cronjob.
|
| 1025 |
+
*
|
| 1026 |
+
* @return datetime
|
| 1027 |
+
*/
|
| 1028 |
+
public function getLastEndTimeCronjob()
|
| 1029 |
+
{
|
| 1030 |
+
return $this->_getConfig('cronjob_endtime');
|
| 1031 |
+
}
|
| 1032 |
+
|
| 1033 |
+
/**
|
| 1034 |
+
* Set the last end time of the cronjob.
|
| 1035 |
+
*
|
| 1036 |
+
* @param datetime $value
|
| 1037 |
+
* @return Copernica_MarketingSoftware_Helper_Config
|
| 1038 |
+
*/
|
| 1039 |
+
public function setLastEndTimeCronjob($value)
|
| 1040 |
+
{
|
| 1041 |
+
$this->_setConfig('cronjob_endtime', $value, true);
|
| 1042 |
+
|
| 1043 |
+
return $this;
|
| 1044 |
+
}
|
| 1045 |
+
|
| 1046 |
+
/**
|
| 1047 |
+
* Get the number of processed records of the last cronjob run.
|
| 1048 |
+
*
|
| 1049 |
+
* @return integer
|
| 1050 |
+
*/
|
| 1051 |
+
public function getLastCronjobProcessedTasks()
|
| 1052 |
+
{
|
| 1053 |
+
return (int)$this->_getConfig('cronjob_processedtasks');
|
| 1054 |
+
}
|
| 1055 |
+
|
| 1056 |
+
/**
|
| 1057 |
+
* Set the last end time of the cronjob.
|
| 1058 |
+
*
|
| 1059 |
+
* @param integer $value
|
| 1060 |
+
* @return Copernica_MarketingSoftware_Helper_Config
|
| 1061 |
+
*/
|
| 1062 |
+
public function setLastCronjobProcessedTasks($value)
|
| 1063 |
+
{
|
| 1064 |
+
$this->_setConfig('cronjob_processedtasks', $value);
|
| 1065 |
+
|
| 1066 |
+
return $this;
|
| 1067 |
+
}
|
| 1068 |
+
|
| 1069 |
+
/**
|
| 1070 |
+
* Should our extension use vanilla magento cron schedulers to execute
|
| 1071 |
+
* queue? Or should we sync all data by processQueue.php file?
|
| 1072 |
+
*
|
| 1073 |
+
* @param boolean $vanilla
|
| 1074 |
+
* @return Copernica_MarketingSoftware_Helper_Config
|
| 1075 |
+
*/
|
| 1076 |
+
public function setVanillaCrons($vanilla)
|
| 1077 |
+
{
|
| 1078 |
+
$this->_setConfig('vanilla_crons', (bool) $vanilla ? 1 : 0);
|
| 1079 |
+
|
| 1080 |
+
return $this;
|
| 1081 |
+
}
|
| 1082 |
+
|
| 1083 |
+
/**
|
| 1084 |
+
* Get stored config about vanilla crons schedulers.
|
| 1085 |
+
*
|
| 1086 |
+
* @return boolean
|
| 1087 |
+
*/
|
| 1088 |
+
public function getVanillaCrons()
|
| 1089 |
+
{
|
| 1090 |
+
return (bool)$this->_getConfig('vanilla_crons');
|
| 1091 |
+
}
|
| 1092 |
+
|
| 1093 |
+
/**
|
| 1094 |
+
* Get last timestamp that we used to check magento forgotten carts
|
| 1095 |
+
*
|
| 1096 |
+
* @return string
|
| 1097 |
+
*/
|
| 1098 |
+
public function getAbandonedLastCheck()
|
| 1099 |
+
{
|
| 1100 |
+
$lastTimestamp = $this->_getConfig('lastAbandonedCheck');
|
| 1101 |
+
|
| 1102 |
+
return $lastTimestamp ? $lastTimestamp : '0000-00-00 00:00:00';
|
| 1103 |
+
}
|
| 1104 |
+
|
| 1105 |
+
/**
|
| 1106 |
+
* Set timestamp when we did check forgotten carts list
|
| 1107 |
+
*
|
| 1108 |
+
* @param string $time
|
| 1109 |
+
* @return Copernica_MarketingSoftware_Helper_Config
|
| 1110 |
+
*/
|
| 1111 |
+
public function setAbandonedLastCheck($time = null)
|
| 1112 |
+
{
|
| 1113 |
+
$this->_setConfig('lastAbandonedCheck', $time ? $time : date("Y-m-d H:i:s"));
|
| 1114 |
+
|
| 1115 |
+
return $this;
|
| 1116 |
+
}
|
| 1117 |
+
|
| 1118 |
+
/**
|
| 1119 |
+
* Set number of minutes that have to pass from last quote item update to consider
|
| 1120 |
+
* cart abandonded.
|
| 1121 |
+
*
|
| 1122 |
+
* @param int $timeout
|
| 1123 |
+
* @return Copernica_MarketingSoftware_Helper_Config
|
| 1124 |
+
*/
|
| 1125 |
+
public function setAbandonedTimeout($timeout)
|
| 1126 |
+
{
|
| 1127 |
+
$this->_setConfig('abandondedTimeout', $timeout);
|
| 1128 |
+
|
| 1129 |
+
return $this;
|
| 1130 |
+
}
|
| 1131 |
+
|
| 1132 |
+
/**
|
| 1133 |
+
* Get number of minutes that have to pass from last quote item update to consider
|
| 1134 |
+
* cart abandonded.
|
| 1135 |
+
*
|
| 1136 |
+
* @return int
|
| 1137 |
+
*/
|
| 1138 |
+
public function getAbandonedTimeout()
|
| 1139 |
+
{
|
| 1140 |
+
$timeout = $this->_getConfig('abandondedTimeout');
|
| 1141 |
+
|
| 1142 |
+
return is_numeric($timeout) ? $timeout : 90;
|
| 1143 |
+
}
|
| 1144 |
+
|
| 1145 |
+
/**
|
| 1146 |
+
* Carts older than supplied number of minutes will not be synchronized
|
| 1147 |
+
* with Copernica.
|
| 1148 |
+
*
|
| 1149 |
+
* @param int $timeout
|
| 1150 |
+
* @return Copernica_MarketingSoftware_Helper_Config
|
| 1151 |
+
*/
|
| 1152 |
+
public function setAbandonedPeriod($timeout)
|
| 1153 |
+
{
|
| 1154 |
+
$this->_setConfig('abandondedPeriod', $timeout);
|
| 1155 |
+
|
| 1156 |
+
return $this;
|
| 1157 |
+
}
|
| 1158 |
+
|
| 1159 |
+
/**
|
| 1160 |
+
* Carts older than supplied number of minutes will not be synchronized
|
| 1161 |
+
* with Copernica.
|
| 1162 |
+
*
|
| 1163 |
+
* @return int
|
| 1164 |
+
*/
|
| 1165 |
+
public function getAbandonedPeriod()
|
| 1166 |
+
{
|
| 1167 |
+
$timeout = $this->_getConfig('abandondedPeriod');
|
| 1168 |
+
|
| 1169 |
+
return is_numeric($timeout) ? $timeout : 21600;
|
| 1170 |
+
}
|
| 1171 |
+
|
| 1172 |
+
/**
|
| 1173 |
+
* Should finished (removed or ordered) quote item be removed from profile?
|
| 1174 |
+
*
|
| 1175 |
+
* @param boolean $remove
|
| 1176 |
+
* @return Copernica_MarketingSoftware_Helper_Config
|
| 1177 |
+
*/
|
| 1178 |
+
public function setRemoveFinishedQuoteItem($remove)
|
| 1179 |
+
{
|
| 1180 |
+
$this->_setConfig('removeFinished', $remove ? 1 : 0);
|
| 1181 |
+
|
| 1182 |
+
return $this;
|
| 1183 |
+
}
|
| 1184 |
+
|
| 1185 |
+
/**
|
| 1186 |
+
* Should finished (removed or ordered) quote item be removed from profile?
|
| 1187 |
+
*
|
| 1188 |
+
* @return bool
|
| 1189 |
+
*/
|
| 1190 |
+
public function getRemoveFinishedQuoteItem()
|
| 1191 |
+
{
|
| 1192 |
+
return (bool)$this->_getConfig('removeFinished');
|
| 1193 |
+
}
|
| 1194 |
+
|
| 1195 |
+
/**
|
| 1196 |
+
* This method will purge all data about linked collections.
|
| 1197 |
+
*/
|
| 1198 |
+
public function clearLinkedCollections()
|
| 1199 |
+
{
|
| 1200 |
+
$this->unsQuoteItemCollectionName();
|
| 1201 |
+
$this->unsQuoteItemCollectionId();
|
| 1202 |
+
$this->unsLinkedQuoteItemFields();
|
| 1203 |
+
|
| 1204 |
+
$this->unsOrdersCollectionName();
|
| 1205 |
+
$this->unsOrdersCollectionId();
|
| 1206 |
+
$this->unsLinkedOrderFields();
|
| 1207 |
+
|
| 1208 |
+
$this->unsOrderItemCollectionName();
|
| 1209 |
+
$this->unsOrderItemCollectionId();
|
| 1210 |
+
$this->unsLinkedOrderItemFields();
|
| 1211 |
+
|
| 1212 |
+
$this->unsAddressCollectionName();
|
| 1213 |
+
$this->unsAddressCollectionId();
|
| 1214 |
+
$this->unsLinkedAddressFields();
|
| 1215 |
+
|
| 1216 |
+
$this->unsViewedProductCollectionName();
|
| 1217 |
+
$this->unsViewedProductCollectionId();
|
| 1218 |
+
$this->unsLinkedViewedProductFields();
|
| 1219 |
+
|
| 1220 |
+
$this->unsWishlistItemCollectionName();
|
| 1221 |
+
$this->unsWishlistItemCollectionId();
|
| 1222 |
+
$this->unsLinkedWishlistItemFields();
|
| 1223 |
+
}
|
| 1224 |
}
|
app/code/community/Copernica/MarketingSoftware/Helper/Data.php
CHANGED
|
@@ -1,532 +1,532 @@
|
|
| 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 |
-
* The base helper for the Copernica Marketingsoftware plug-in
|
| 29 |
-
*/
|
| 30 |
-
class Copernica_MarketingSoftware_Helper_Data extends Mage_Core_Helper_Abstract
|
| 31 |
-
{
|
| 32 |
-
/**
|
| 33 |
-
* Helper method returns all supported customer fields
|
| 34 |
-
*
|
| 35 |
-
* @return array
|
| 36 |
-
*/
|
| 37 |
-
public function supportedCustomerFields()
|
| 38 |
-
{
|
| 39 |
-
return array(
|
| 40 |
-
'gender' => 'Gender',
|
| 41 |
-
'firstname' => 'Firstname',
|
| 42 |
-
'middlename' => 'Middlename',
|
| 43 |
-
'lastname' => 'Lastname',
|
| 44 |
-
'email' => 'E-mail',
|
| 45 |
-
'birthdate' => 'Birth date',
|
| 46 |
-
'group' => 'Customer group',
|
| 47 |
-
'newsletter' => 'Newsletter',
|
| 48 |
-
'storeView' => 'Store view',
|
| 49 |
-
'registrationDate' => 'Registration date',
|
| 50 |
-
);
|
| 51 |
-
}
|
| 52 |
-
|
| 53 |
-
/**
|
| 54 |
-
* Helper method returns all supported fields for
|
| 55 |
-
* the quote item collection
|
| 56 |
-
*
|
| 57 |
-
* @return array
|
| 58 |
-
*/
|
| 59 |
-
public function supportedQuoteItemFields()
|
| 60 |
-
{
|
| 61 |
-
return array(
|
| 62 |
-
'productId' => 'Product id',
|
| 63 |
-
'name' => 'Product name',
|
| 64 |
-
'sku' => 'SKU',
|
| 65 |
-
'attributeSet' => 'Attribute set',
|
| 66 |
-
'weight' => 'Weight',
|
| 67 |
-
'quantity' => 'Quantity',
|
| 68 |
-
'price' => 'Price',
|
| 69 |
-
'totalPrice' => 'Total price',
|
| 70 |
-
'timestamp' => 'Modified',
|
| 71 |
-
'storeView' => 'Store view',
|
| 72 |
-
'url' => 'Details URL',
|
| 73 |
-
'image' => 'Image URL',
|
| 74 |
-
'categories' => 'Categories',
|
| 75 |
-
'options' => 'Product options',
|
| 76 |
-
'attributes' => 'Product Attributes',
|
| 77 |
-
);
|
| 78 |
-
}
|
| 79 |
-
|
| 80 |
-
/**
|
| 81 |
-
* Helper method returns all supported fields for
|
| 82 |
-
* the order collection
|
| 83 |
-
*
|
| 84 |
-
* @return array
|
| 85 |
-
*/
|
| 86 |
-
public function supportedOrderFields()
|
| 87 |
-
{
|
| 88 |
-
return array(
|
| 89 |
-
'incrementId' => 'Increment id',
|
| 90 |
-
'timestamp' => 'Timestamp',
|
| 91 |
-
'quantity' => 'Quantity',
|
| 92 |
-
//'subtotal' => 'Subtotal',
|
| 93 |
-
'shipping' => 'Shipping costs',
|
| 94 |
-
'total' => 'Order total',
|
| 95 |
-
'weight' => 'Total weight',
|
| 96 |
-
'currency' => 'Currency',
|
| 97 |
-
'status' => 'Order status',
|
| 98 |
-
'storeView' => 'Store view',
|
| 99 |
-
'remoteIp' => 'Order ip address',
|
| 100 |
-
'shippingDescription' => 'Shipping description',
|
| 101 |
-
'paymentDescription' => 'Payment description',
|
| 102 |
-
'shippingAddressId' => 'Shipping Address id',
|
| 103 |
-
'billingAddressId' => 'Billing Address id',
|
| 104 |
-
'couponCode' => 'Coupon code',
|
| 105 |
-
);
|
| 106 |
-
}
|
| 107 |
-
|
| 108 |
-
/**
|
| 109 |
-
* Helper method returns all supported fields for
|
| 110 |
-
* the order item collection
|
| 111 |
-
*
|
| 112 |
-
* @return array
|
| 113 |
-
*/
|
| 114 |
-
public function supportedOrderItemFields()
|
| 115 |
-
{
|
| 116 |
-
return array(
|
| 117 |
-
'productId' => 'Product id',
|
| 118 |
-
'incrementId' => 'Increment id',
|
| 119 |
-
'name' => 'Product name',
|
| 120 |
-
'sku' => 'SKU',
|
| 121 |
-
'attributeSet' => 'Attribute set',
|
| 122 |
-
'weight' => 'Weight',
|
| 123 |
-
'quantity' => 'Quantity',
|
| 124 |
-
'price' => 'Price',
|
| 125 |
-
'totalPrice' => 'Total price',
|
| 126 |
-
'timestamp' => 'Modified',
|
| 127 |
-
'storeView' => 'Store view',
|
| 128 |
-
'url' => 'Details URL',
|
| 129 |
-
'image' => 'Image URL',
|
| 130 |
-
'categories' => 'Categories',
|
| 131 |
-
'options' => 'Product options',
|
| 132 |
-
'attributes' => 'Product Attributes',
|
| 133 |
-
'salesRules' => 'Sales rules',
|
| 134 |
-
);
|
| 135 |
-
}
|
| 136 |
-
|
| 137 |
-
/**
|
| 138 |
-
* Helper method returns all supported fields for
|
| 139 |
-
* the address collection
|
| 140 |
-
*
|
| 141 |
-
* @return array
|
| 142 |
-
*/
|
| 143 |
-
public function supportedAddressFields()
|
| 144 |
-
{
|
| 145 |
-
return array(
|
| 146 |
-
'firstname' => 'Firstname',
|
| 147 |
-
'middlename' => 'Middlename',
|
| 148 |
-
'prefix' => 'Prefix',
|
| 149 |
-
'lastname' => 'Lastname',
|
| 150 |
-
'email' => 'E-mail',
|
| 151 |
-
'company' => 'Company',
|
| 152 |
-
'street' => 'Street',
|
| 153 |
-
'city' => 'City',
|
| 154 |
-
'state' => 'State',
|
| 155 |
-
'zipcode' => 'Zip code',
|
| 156 |
-
'countryId' => 'Country',
|
| 157 |
-
'telephone' => 'Telephone number',
|
| 158 |
-
'fax' => 'Fax number',
|
| 159 |
-
);
|
| 160 |
-
}
|
| 161 |
-
|
| 162 |
-
/**
|
| 163 |
-
* Helper method returns all supported fields for
|
| 164 |
-
* the viewed product collection
|
| 165 |
-
*
|
| 166 |
-
* @return array
|
| 167 |
-
*/
|
| 168 |
-
public function supportedViewedProductFields()
|
| 169 |
-
{
|
| 170 |
-
return array(
|
| 171 |
-
'productId' => 'Product id',
|
| 172 |
-
'name' => 'Product name',
|
| 173 |
-
'sku' => 'SKU',
|
| 174 |
-
'attributeSet' => 'Attribute set',
|
| 175 |
-
'weight' => 'Weight',
|
| 176 |
-
'price' => 'Price',
|
| 177 |
-
'timestamp' => 'Timestamp',
|
| 178 |
-
'storeView' => 'Store view',
|
| 179 |
-
'url' => 'Details URL',
|
| 180 |
-
'image' => 'Image URL',
|
| 181 |
-
'categories' => 'Categories',
|
| 182 |
-
'options' => 'Product options',
|
| 183 |
-
'attributes' => 'Product Attributes',
|
| 184 |
-
);
|
| 185 |
-
}
|
| 186 |
-
|
| 187 |
-
/**
|
| 188 |
-
* Helper method returns all supported fields for
|
| 189 |
-
* the wishlist item collection
|
| 190 |
-
*
|
| 191 |
-
* @return array
|
| 192 |
-
*/
|
| 193 |
-
public function supportedWishlistItemFields()
|
| 194 |
-
{
|
| 195 |
-
return array(
|
| 196 |
-
'productId' => 'Product id',
|
| 197 |
-
'name' => 'Product name',
|
| 198 |
-
'sku' => 'SKU',
|
| 199 |
-
'attributeSet' => 'Attribute set',
|
| 200 |
-
'weight' => 'Weight',
|
| 201 |
-
'quantity' => 'Quantity',
|
| 202 |
-
'price' => 'Price',
|
| 203 |
-
'totalPrice' => 'Total price',
|
| 204 |
-
'timestamp' => 'Timestamp',
|
| 205 |
-
'description' => 'Description',
|
| 206 |
-
'storeView' => 'Store view',
|
| 207 |
-
'url' => 'Details URL',
|
| 208 |
-
'image' => 'Image URL',
|
| 209 |
-
'categories' => 'Categories',
|
| 210 |
-
'options' => 'Product options',
|
| 211 |
-
'attributes' => 'Product Attributes',
|
| 212 |
-
);
|
| 213 |
-
}
|
| 214 |
-
|
| 215 |
-
/**
|
| 216 |
-
* Required fields for copernica customer profile.
|
| 217 |
-
*
|
| 218 |
-
* @return array
|
| 219 |
-
*/
|
| 220 |
-
public function requiredCustomerFields()
|
| 221 |
-
{
|
| 222 |
-
return array('customer_id');
|
| 223 |
-
}
|
| 224 |
-
|
| 225 |
-
/**
|
| 226 |
-
* Required fields for copernica quote item collection.
|
| 227 |
-
*
|
| 228 |
-
* @return array
|
| 229 |
-
*/
|
| 230 |
-
public function requiredQuoteItemFields()
|
| 231 |
-
{
|
| 232 |
-
return array('item_id', 'quote_id', 'status');
|
| 233 |
-
}
|
| 234 |
-
|
| 235 |
-
/**
|
| 236 |
-
* Required fields for copernica orders collection
|
| 237 |
-
*
|
| 238 |
-
* @return array
|
| 239 |
-
*/
|
| 240 |
-
public function requiredOrderFields()
|
| 241 |
-
{
|
| 242 |
-
return array('order_id', 'quote_id');
|
| 243 |
-
}
|
| 244 |
-
|
| 245 |
-
/**
|
| 246 |
-
* Required fields for copernica order item collection
|
| 247 |
-
*
|
| 248 |
-
* @return array
|
| 249 |
-
*/
|
| 250 |
-
public function requiredOrderItemFields()
|
| 251 |
-
{
|
| 252 |
-
return array('item_id', 'order_id');
|
| 253 |
-
}
|
| 254 |
-
|
| 255 |
-
/**
|
| 256 |
-
* Required fields for copernica address collection
|
| 257 |
-
*
|
| 258 |
-
* @return array
|
| 259 |
-
*/
|
| 260 |
-
public function requiredAddressFields()
|
| 261 |
-
{
|
| 262 |
-
return array('address_id');
|
| 263 |
-
}
|
| 264 |
-
|
| 265 |
-
/**
|
| 266 |
-
* Required fields for copernica viewed products collection
|
| 267 |
-
*
|
| 268 |
-
* @return array
|
| 269 |
-
*/
|
| 270 |
-
public function requiredViewedProductFields()
|
| 271 |
-
{
|
| 272 |
-
return array('product_id');
|
| 273 |
-
}
|
| 274 |
-
|
| 275 |
-
/**
|
| 276 |
-
* Required fields for copernica wislist collection
|
| 277 |
-
*
|
| 278 |
-
* @return array
|
| 279 |
-
*/
|
| 280 |
-
public function requiredWishlistItemFields()
|
| 281 |
-
{
|
| 282 |
-
return array('item_id', 'wishlist_id');
|
| 283 |
-
}
|
| 284 |
-
|
| 285 |
-
/**
|
| 286 |
-
* Get field definition by collection type and magento field name.
|
| 287 |
-
*
|
| 288 |
-
* Some of collections fields should have special definitions. That is mostly
|
| 289 |
-
* caused by meaning of data. Fox emaple when there is an email field we
|
| 290 |
-
* want to be able to recognize data from that field as email. So, in copernica
|
| 291 |
-
* platform we should also have a field of type email. Same goes for phones,
|
| 292 |
-
* dates, etc.
|
| 293 |
-
*
|
| 294 |
-
* @param string $collectionType
|
| 295 |
-
* @param string $magentoName
|
| 296 |
-
* @return array
|
| 297 |
-
*/
|
| 298 |
-
public function getCollectionFieldDefinition($collectionType, $magentoName)
|
| 299 |
-
{
|
| 300 |
-
$definitions = array(
|
| 301 |
-
'cartproducts' => array (
|
| 302 |
-
'timestamp' => array (
|
| 303 |
-
'type' => 'datetime'
|
| 304 |
-
),
|
| 305 |
-
'url' => array (
|
| 306 |
-
'type' => 'text',
|
| 307 |
-
'length' => 255
|
| 308 |
-
),
|
| 309 |
-
'image' => array (
|
| 310 |
-
'type' => 'text',
|
| 311 |
-
'length' => 255
|
| 312 |
-
),
|
| 313 |
-
'categories' => array (
|
| 314 |
-
'type' => 'text',
|
| 315 |
-
'length' => 255,
|
| 316 |
-
'textlines' => 4,
|
| 317 |
-
'lines' => 4
|
| 318 |
-
),
|
| 319 |
-
'storeView' => array (
|
| 320 |
-
'type' => 'text',
|
| 321 |
-
'length' => 250
|
| 322 |
-
),
|
| 323 |
-
'options' => array (
|
| 324 |
-
'type' => 'big',
|
| 325 |
-
'textlines' => 4,
|
| 326 |
-
'lines' => 4
|
| 327 |
-
),
|
| 328 |
-
'attributes' => array (
|
| 329 |
-
'type' => 'big',
|
| 330 |
-
'textlines' => 4,
|
| 331 |
-
'lines' => 4
|
| 332 |
-
),
|
| 333 |
-
),
|
| 334 |
-
'orderproducts' => array (
|
| 335 |
-
'timestamp' => array (
|
| 336 |
-
'type' => 'datetime'
|
| 337 |
-
),
|
| 338 |
-
'url' => array (
|
| 339 |
-
'type' => 'text',
|
| 340 |
-
'length' => 255
|
| 341 |
-
),
|
| 342 |
-
'image' => array (
|
| 343 |
-
'type' => 'text',
|
| 344 |
-
'length' => 255
|
| 345 |
-
),
|
| 346 |
-
'categories' => array (
|
| 347 |
-
'type' => 'text',
|
| 348 |
-
'length' => 255,
|
| 349 |
-
'textlines' => 4,
|
| 350 |
-
'lines' => 4
|
| 351 |
-
),
|
| 352 |
-
'storeView' => array (
|
| 353 |
-
'type' => 'text',
|
| 354 |
-
'length' => 250
|
| 355 |
-
),
|
| 356 |
-
'options' => array (
|
| 357 |
-
'type' => 'big',
|
| 358 |
-
'textlines' => 4,
|
| 359 |
-
'lines' => 4
|
| 360 |
-
),
|
| 361 |
-
'attributes' => array (
|
| 362 |
-
'type' => 'big',
|
| 363 |
-
'textlines' => 4,
|
| 364 |
-
'lines' => 4
|
| 365 |
-
),
|
| 366 |
-
'salesRules' => array (
|
| 367 |
-
'type' => 'big',
|
| 368 |
-
'textlines' => 4,
|
| 369 |
-
'lines' => 4
|
| 370 |
-
),
|
| 371 |
-
),
|
| 372 |
-
'viewedproducts' => array (
|
| 373 |
-
'timestamp' => array (
|
| 374 |
-
'type' => 'datetime'
|
| 375 |
-
),
|
| 376 |
-
'url' => array (
|
| 377 |
-
'type' => 'text',
|
| 378 |
-
'length' => 255
|
| 379 |
-
),
|
| 380 |
-
'image' => array (
|
| 381 |
-
'type' => 'text',
|
| 382 |
-
'length' => 255
|
| 383 |
-
),
|
| 384 |
-
'categories' => array (
|
| 385 |
-
'type' => 'text',
|
| 386 |
-
'length' => 255,
|
| 387 |
-
'textlines' => 4,
|
| 388 |
-
'lines' => 4
|
| 389 |
-
),
|
| 390 |
-
'storeView' => array (
|
| 391 |
-
'type' => 'text',
|
| 392 |
-
'length' => 250
|
| 393 |
-
),
|
| 394 |
-
'options' => array (
|
| 395 |
-
'type' => 'big',
|
| 396 |
-
'textlines' => 4,
|
| 397 |
-
'lines' => 4
|
| 398 |
-
),
|
| 399 |
-
'attributes' => array (
|
| 400 |
-
'type' => 'big',
|
| 401 |
-
'textlines' => 4,
|
| 402 |
-
'lines' => 4
|
| 403 |
-
)
|
| 404 |
-
),
|
| 405 |
-
'orders' => array (
|
| 406 |
-
'timestamp' => array (
|
| 407 |
-
'type' => 'datetime'
|
| 408 |
-
),
|
| 409 |
-
'storeView' => array (
|
| 410 |
-
'type' => 'text',
|
| 411 |
-
'length' => 250
|
| 412 |
-
),
|
| 413 |
-
'shippingDescription' => array (
|
| 414 |
-
'type' => 'big',
|
| 415 |
-
'textlines' => 4,
|
| 416 |
-
'lines' => 4
|
| 417 |
-
),
|
| 418 |
-
'paymentDescription' => array (
|
| 419 |
-
'type' => 'big',
|
| 420 |
-
'textlines' => 4,
|
| 421 |
-
'lines' => 4
|
| 422 |
-
),
|
| 423 |
-
'couponCode' => array (
|
| 424 |
-
'type' => 'text',
|
| 425 |
-
'length' => 255
|
| 426 |
-
)
|
| 427 |
-
),
|
| 428 |
-
'addresses' => array (
|
| 429 |
-
'email' => array (
|
| 430 |
-
'type' => 'email',
|
| 431 |
-
),
|
| 432 |
-
'telephone' => array (
|
| 433 |
-
'type' => 'phone_gsm'
|
| 434 |
-
),
|
| 435 |
-
'fax' => array (
|
| 436 |
-
'type' => 'phone_fax'
|
| 437 |
-
)
|
| 438 |
-
),
|
| 439 |
-
'wishlistproducts' => array (
|
| 440 |
-
'timestamp' => array (
|
| 441 |
-
'type' => 'datetime'
|
| 442 |
-
),
|
| 443 |
-
'description' => array (
|
| 444 |
-
'type' => 'big',
|
| 445 |
-
'textlines' => 4,
|
| 446 |
-
'lines' => 4
|
| 447 |
-
),
|
| 448 |
-
'url' => array (
|
| 449 |
-
'type' => 'text',
|
| 450 |
-
'length' => 255
|
| 451 |
-
),
|
| 452 |
-
'image' => array (
|
| 453 |
-
'type' => 'text',
|
| 454 |
-
'length' => 255
|
| 455 |
-
),
|
| 456 |
-
'categories' => array (
|
| 457 |
-
'type' => 'text',
|
| 458 |
-
'length' => 255,
|
| 459 |
-
'textlines' => 4,
|
| 460 |
-
'lines' => 4
|
| 461 |
-
),
|
| 462 |
-
'storeView' => array (
|
| 463 |
-
'type' => 'text',
|
| 464 |
-
'length' => 250
|
| 465 |
-
),
|
| 466 |
-
'options' => array (
|
| 467 |
-
'type' => 'big',
|
| 468 |
-
'textlines' => 4,
|
| 469 |
-
'lines' => 4
|
| 470 |
-
),
|
| 471 |
-
'attributes' => array (
|
| 472 |
-
'type' => 'big',
|
| 473 |
-
'textlines' => 4,
|
| 474 |
-
'lines' => 4
|
| 475 |
-
),
|
| 476 |
-
)
|
| 477 |
-
);
|
| 478 |
-
|
| 479 |
-
if (!isset($definitions[$collectionType]) || !isset($definitions[$collectionType][$magentoName])) {
|
| 480 |
-
return array ('type' => 'text');
|
| 481 |
-
}
|
| 482 |
-
|
| 483 |
-
return $definitions[$collectionType][$magentoName];
|
| 484 |
-
}
|
| 485 |
-
|
| 486 |
-
/**
|
| 487 |
-
* Get the version of this extension.
|
| 488 |
-
*
|
| 489 |
-
* @return string
|
| 490 |
-
*/
|
| 491 |
-
public function getExtensionVersion()
|
| 492 |
-
{
|
| 493 |
-
$config = Mage::getConfig()->getModuleConfig('Copernica_MarketingSoftware')->asArray();
|
| 494 |
-
|
| 495 |
-
return $config['version'];
|
| 496 |
-
}
|
| 497 |
-
|
| 498 |
-
/**
|
| 499 |
-
* Get the url for the unsubscribe callback
|
| 500 |
-
*
|
| 501 |
-
* @return string
|
| 502 |
-
*/
|
| 503 |
-
public function unsubscribeCallbackUrl()
|
| 504 |
-
{
|
| 505 |
-
return Mage::getModel('core/url')->getUrl('copernica/unsubscribe/process', array());
|
| 506 |
-
}
|
| 507 |
-
|
| 508 |
-
/**
|
| 509 |
-
* Does the queue contain the magic token, which indicates that the synchronisation
|
| 510 |
-
* should be started?
|
| 511 |
-
*
|
| 512 |
-
* @return boolean
|
| 513 |
-
*/
|
| 514 |
-
public function isSynchronisationStartScheduled()
|
| 515 |
-
{
|
| 516 |
-
$count = Mage::getResourceModel('marketingsoftware/queue_item_collection')
|
| 517 |
-
->addFieldToFilter('action', 'start_sync')
|
| 518 |
-
->getSize();
|
| 519 |
-
|
| 520 |
-
return ($count > 0);
|
| 521 |
-
}
|
| 522 |
-
|
| 523 |
-
/**
|
| 524 |
-
* Is the Copernica module enabled?
|
| 525 |
-
*
|
| 526 |
-
* @return boolean
|
| 527 |
-
*/
|
| 528 |
-
public function enabled()
|
| 529 |
-
{
|
| 530 |
-
return (Mage::getConfig()->getNode('advanced/modules_disable_output/Copernica_MarketingSoftware', 'default', 0) == 0);
|
| 531 |
-
}
|
| 532 |
-
}
|
| 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 |
+
* The base helper for the Copernica Marketingsoftware plug-in
|
| 29 |
+
*/
|
| 30 |
+
class Copernica_MarketingSoftware_Helper_Data extends Mage_Core_Helper_Abstract
|
| 31 |
+
{
|
| 32 |
+
/**
|
| 33 |
+
* Helper method returns all supported customer fields
|
| 34 |
+
*
|
| 35 |
+
* @return array
|
| 36 |
+
*/
|
| 37 |
+
public function supportedCustomerFields()
|
| 38 |
+
{
|
| 39 |
+
return array(
|
| 40 |
+
'gender' => 'Gender',
|
| 41 |
+
'firstname' => 'Firstname',
|
| 42 |
+
'middlename' => 'Middlename',
|
| 43 |
+
'lastname' => 'Lastname',
|
| 44 |
+
'email' => 'E-mail',
|
| 45 |
+
'birthdate' => 'Birth date',
|
| 46 |
+
'group' => 'Customer group',
|
| 47 |
+
'newsletter' => 'Newsletter',
|
| 48 |
+
'storeView' => 'Store view',
|
| 49 |
+
'registrationDate' => 'Registration date',
|
| 50 |
+
);
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
/**
|
| 54 |
+
* Helper method returns all supported fields for
|
| 55 |
+
* the quote item collection
|
| 56 |
+
*
|
| 57 |
+
* @return array
|
| 58 |
+
*/
|
| 59 |
+
public function supportedQuoteItemFields()
|
| 60 |
+
{
|
| 61 |
+
return array(
|
| 62 |
+
'productId' => 'Product id',
|
| 63 |
+
'name' => 'Product name',
|
| 64 |
+
'sku' => 'SKU',
|
| 65 |
+
'attributeSet' => 'Attribute set',
|
| 66 |
+
'weight' => 'Weight',
|
| 67 |
+
'quantity' => 'Quantity',
|
| 68 |
+
'price' => 'Price',
|
| 69 |
+
'totalPrice' => 'Total price',
|
| 70 |
+
'timestamp' => 'Modified',
|
| 71 |
+
'storeView' => 'Store view',
|
| 72 |
+
'url' => 'Details URL',
|
| 73 |
+
'image' => 'Image URL',
|
| 74 |
+
'categories' => 'Categories',
|
| 75 |
+
'options' => 'Product options',
|
| 76 |
+
'attributes' => 'Product Attributes',
|
| 77 |
+
);
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
/**
|
| 81 |
+
* Helper method returns all supported fields for
|
| 82 |
+
* the order collection
|
| 83 |
+
*
|
| 84 |
+
* @return array
|
| 85 |
+
*/
|
| 86 |
+
public function supportedOrderFields()
|
| 87 |
+
{
|
| 88 |
+
return array(
|
| 89 |
+
'incrementId' => 'Increment id',
|
| 90 |
+
'timestamp' => 'Timestamp',
|
| 91 |
+
'quantity' => 'Quantity',
|
| 92 |
+
//'subtotal' => 'Subtotal',
|
| 93 |
+
'shipping' => 'Shipping costs',
|
| 94 |
+
'total' => 'Order total',
|
| 95 |
+
'weight' => 'Total weight',
|
| 96 |
+
'currency' => 'Currency',
|
| 97 |
+
'status' => 'Order status',
|
| 98 |
+
'storeView' => 'Store view',
|
| 99 |
+
'remoteIp' => 'Order ip address',
|
| 100 |
+
'shippingDescription' => 'Shipping description',
|
| 101 |
+
'paymentDescription' => 'Payment description',
|
| 102 |
+
'shippingAddressId' => 'Shipping Address id',
|
| 103 |
+
'billingAddressId' => 'Billing Address id',
|
| 104 |
+
'couponCode' => 'Coupon code',
|
| 105 |
+
);
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
/**
|
| 109 |
+
* Helper method returns all supported fields for
|
| 110 |
+
* the order item collection
|
| 111 |
+
*
|
| 112 |
+
* @return array
|
| 113 |
+
*/
|
| 114 |
+
public function supportedOrderItemFields()
|
| 115 |
+
{
|
| 116 |
+
return array(
|
| 117 |
+
'productId' => 'Product id',
|
| 118 |
+
'incrementId' => 'Increment id',
|
| 119 |
+
'name' => 'Product name',
|
| 120 |
+
'sku' => 'SKU',
|
| 121 |
+
'attributeSet' => 'Attribute set',
|
| 122 |
+
'weight' => 'Weight',
|
| 123 |
+
'quantity' => 'Quantity',
|
| 124 |
+
'price' => 'Price',
|
| 125 |
+
'totalPrice' => 'Total price',
|
| 126 |
+
'timestamp' => 'Modified',
|
| 127 |
+
'storeView' => 'Store view',
|
| 128 |
+
'url' => 'Details URL',
|
| 129 |
+
'image' => 'Image URL',
|
| 130 |
+
'categories' => 'Categories',
|
| 131 |
+
'options' => 'Product options',
|
| 132 |
+
'attributes' => 'Product Attributes',
|
| 133 |
+
'salesRules' => 'Sales rules',
|
| 134 |
+
);
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
/**
|
| 138 |
+
* Helper method returns all supported fields for
|
| 139 |
+
* the address collection
|
| 140 |
+
*
|
| 141 |
+
* @return array
|
| 142 |
+
*/
|
| 143 |
+
public function supportedAddressFields()
|
| 144 |
+
{
|
| 145 |
+
return array(
|
| 146 |
+
'firstname' => 'Firstname',
|
| 147 |
+
'middlename' => 'Middlename',
|
| 148 |
+
'prefix' => 'Prefix',
|
| 149 |
+
'lastname' => 'Lastname',
|
| 150 |
+
'email' => 'E-mail',
|
| 151 |
+
'company' => 'Company',
|
| 152 |
+
'street' => 'Street',
|
| 153 |
+
'city' => 'City',
|
| 154 |
+
'state' => 'State',
|
| 155 |
+
'zipcode' => 'Zip code',
|
| 156 |
+
'countryId' => 'Country',
|
| 157 |
+
'telephone' => 'Telephone number',
|
| 158 |
+
'fax' => 'Fax number',
|
| 159 |
+
);
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
/**
|
| 163 |
+
* Helper method returns all supported fields for
|
| 164 |
+
* the viewed product collection
|
| 165 |
+
*
|
| 166 |
+
* @return array
|
| 167 |
+
*/
|
| 168 |
+
public function supportedViewedProductFields()
|
| 169 |
+
{
|
| 170 |
+
return array(
|
| 171 |
+
'productId' => 'Product id',
|
| 172 |
+
'name' => 'Product name',
|
| 173 |
+
'sku' => 'SKU',
|
| 174 |
+
'attributeSet' => 'Attribute set',
|
| 175 |
+
'weight' => 'Weight',
|
| 176 |
+
'price' => 'Price',
|
| 177 |
+
'timestamp' => 'Timestamp',
|
| 178 |
+
'storeView' => 'Store view',
|
| 179 |
+
'url' => 'Details URL',
|
| 180 |
+
'image' => 'Image URL',
|
| 181 |
+
'categories' => 'Categories',
|
| 182 |
+
'options' => 'Product options',
|
| 183 |
+
'attributes' => 'Product Attributes',
|
| 184 |
+
);
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
/**
|
| 188 |
+
* Helper method returns all supported fields for
|
| 189 |
+
* the wishlist item collection
|
| 190 |
+
*
|
| 191 |
+
* @return array
|
| 192 |
+
*/
|
| 193 |
+
public function supportedWishlistItemFields()
|
| 194 |
+
{
|
| 195 |
+
return array(
|
| 196 |
+
'productId' => 'Product id',
|
| 197 |
+
'name' => 'Product name',
|
| 198 |
+
'sku' => 'SKU',
|
| 199 |
+
'attributeSet' => 'Attribute set',
|
| 200 |
+
'weight' => 'Weight',
|
| 201 |
+
'quantity' => 'Quantity',
|
| 202 |
+
'price' => 'Price',
|
| 203 |
+
'totalPrice' => 'Total price',
|
| 204 |
+
'timestamp' => 'Timestamp',
|
| 205 |
+
'description' => 'Description',
|
| 206 |
+
'storeView' => 'Store view',
|
| 207 |
+
'url' => 'Details URL',
|
| 208 |
+
'image' => 'Image URL',
|
| 209 |
+
'categories' => 'Categories',
|
| 210 |
+
'options' => 'Product options',
|
| 211 |
+
'attributes' => 'Product Attributes',
|
| 212 |
+
);
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
+
/**
|
| 216 |
+
* Required fields for copernica customer profile.
|
| 217 |
+
*
|
| 218 |
+
* @return array
|
| 219 |
+
*/
|
| 220 |
+
public function requiredCustomerFields()
|
| 221 |
+
{
|
| 222 |
+
return array('customer_id');
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
/**
|
| 226 |
+
* Required fields for copernica quote item collection.
|
| 227 |
+
*
|
| 228 |
+
* @return array
|
| 229 |
+
*/
|
| 230 |
+
public function requiredQuoteItemFields()
|
| 231 |
+
{
|
| 232 |
+
return array('item_id', 'quote_id', 'status');
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
/**
|
| 236 |
+
* Required fields for copernica orders collection
|
| 237 |
+
*
|
| 238 |
+
* @return array
|
| 239 |
+
*/
|
| 240 |
+
public function requiredOrderFields()
|
| 241 |
+
{
|
| 242 |
+
return array('order_id', 'quote_id');
|
| 243 |
+
}
|
| 244 |
+
|
| 245 |
+
/**
|
| 246 |
+
* Required fields for copernica order item collection
|
| 247 |
+
*
|
| 248 |
+
* @return array
|
| 249 |
+
*/
|
| 250 |
+
public function requiredOrderItemFields()
|
| 251 |
+
{
|
| 252 |
+
return array('item_id', 'order_id');
|
| 253 |
+
}
|
| 254 |
+
|
| 255 |
+
/**
|
| 256 |
+
* Required fields for copernica address collection
|
| 257 |
+
*
|
| 258 |
+
* @return array
|
| 259 |
+
*/
|
| 260 |
+
public function requiredAddressFields()
|
| 261 |
+
{
|
| 262 |
+
return array('address_id');
|
| 263 |
+
}
|
| 264 |
+
|
| 265 |
+
/**
|
| 266 |
+
* Required fields for copernica viewed products collection
|
| 267 |
+
*
|
| 268 |
+
* @return array
|
| 269 |
+
*/
|
| 270 |
+
public function requiredViewedProductFields()
|
| 271 |
+
{
|
| 272 |
+
return array('product_id');
|
| 273 |
+
}
|
| 274 |
+
|
| 275 |
+
/**
|
| 276 |
+
* Required fields for copernica wislist collection
|
| 277 |
+
*
|
| 278 |
+
* @return array
|
| 279 |
+
*/
|
| 280 |
+
public function requiredWishlistItemFields()
|
| 281 |
+
{
|
| 282 |
+
return array('item_id', 'wishlist_id');
|
| 283 |
+
}
|
| 284 |
+
|
| 285 |
+
/**
|
| 286 |
+
* Get field definition by collection type and magento field name.
|
| 287 |
+
*
|
| 288 |
+
* Some of collections fields should have special definitions. That is mostly
|
| 289 |
+
* caused by meaning of data. Fox emaple when there is an email field we
|
| 290 |
+
* want to be able to recognize data from that field as email. So, in copernica
|
| 291 |
+
* platform we should also have a field of type email. Same goes for phones,
|
| 292 |
+
* dates, etc.
|
| 293 |
+
*
|
| 294 |
+
* @param string $collectionType
|
| 295 |
+
* @param string $magentoName
|
| 296 |
+
* @return array
|
| 297 |
+
*/
|
| 298 |
+
public function getCollectionFieldDefinition($collectionType, $magentoName)
|
| 299 |
+
{
|
| 300 |
+
$definitions = array(
|
| 301 |
+
'cartproducts' => array (
|
| 302 |
+
'timestamp' => array (
|
| 303 |
+
'type' => 'datetime'
|
| 304 |
+
),
|
| 305 |
+
'url' => array (
|
| 306 |
+
'type' => 'text',
|
| 307 |
+
'length' => 255
|
| 308 |
+
),
|
| 309 |
+
'image' => array (
|
| 310 |
+
'type' => 'text',
|
| 311 |
+
'length' => 255
|
| 312 |
+
),
|
| 313 |
+
'categories' => array (
|
| 314 |
+
'type' => 'text',
|
| 315 |
+
'length' => 255,
|
| 316 |
+
'textlines' => 4,
|
| 317 |
+
'lines' => 4
|
| 318 |
+
),
|
| 319 |
+
'storeView' => array (
|
| 320 |
+
'type' => 'text',
|
| 321 |
+
'length' => 250
|
| 322 |
+
),
|
| 323 |
+
'options' => array (
|
| 324 |
+
'type' => 'big',
|
| 325 |
+
'textlines' => 4,
|
| 326 |
+
'lines' => 4
|
| 327 |
+
),
|
| 328 |
+
'attributes' => array (
|
| 329 |
+
'type' => 'big',
|
| 330 |
+
'textlines' => 4,
|
| 331 |
+
'lines' => 4
|
| 332 |
+
),
|
| 333 |
+
),
|
| 334 |
+
'orderproducts' => array (
|
| 335 |
+
'timestamp' => array (
|
| 336 |
+
'type' => 'datetime'
|
| 337 |
+
),
|
| 338 |
+
'url' => array (
|
| 339 |
+
'type' => 'text',
|
| 340 |
+
'length' => 255
|
| 341 |
+
),
|
| 342 |
+
'image' => array (
|
| 343 |
+
'type' => 'text',
|
| 344 |
+
'length' => 255
|
| 345 |
+
),
|
| 346 |
+
'categories' => array (
|
| 347 |
+
'type' => 'text',
|
| 348 |
+
'length' => 255,
|
| 349 |
+
'textlines' => 4,
|
| 350 |
+
'lines' => 4
|
| 351 |
+
),
|
| 352 |
+
'storeView' => array (
|
| 353 |
+
'type' => 'text',
|
| 354 |
+
'length' => 250
|
| 355 |
+
),
|
| 356 |
+
'options' => array (
|
| 357 |
+
'type' => 'big',
|
| 358 |
+
'textlines' => 4,
|
| 359 |
+
'lines' => 4
|
| 360 |
+
),
|
| 361 |
+
'attributes' => array (
|
| 362 |
+
'type' => 'big',
|
| 363 |
+
'textlines' => 4,
|
| 364 |
+
'lines' => 4
|
| 365 |
+
),
|
| 366 |
+
'salesRules' => array (
|
| 367 |
+
'type' => 'big',
|
| 368 |
+
'textlines' => 4,
|
| 369 |
+
'lines' => 4
|
| 370 |
+
),
|
| 371 |
+
),
|
| 372 |
+
'viewedproducts' => array (
|
| 373 |
+
'timestamp' => array (
|
| 374 |
+
'type' => 'datetime'
|
| 375 |
+
),
|
| 376 |
+
'url' => array (
|
| 377 |
+
'type' => 'text',
|
| 378 |
+
'length' => 255
|
| 379 |
+
),
|
| 380 |
+
'image' => array (
|
| 381 |
+
'type' => 'text',
|
| 382 |
+
'length' => 255
|
| 383 |
+
),
|
| 384 |
+
'categories' => array (
|
| 385 |
+
'type' => 'text',
|
| 386 |
+
'length' => 255,
|
| 387 |
+
'textlines' => 4,
|
| 388 |
+
'lines' => 4
|
| 389 |
+
),
|
| 390 |
+
'storeView' => array (
|
| 391 |
+
'type' => 'text',
|
| 392 |
+
'length' => 250
|
| 393 |
+
),
|
| 394 |
+
'options' => array (
|
| 395 |
+
'type' => 'big',
|
| 396 |
+
'textlines' => 4,
|
| 397 |
+
'lines' => 4
|
| 398 |
+
),
|
| 399 |
+
'attributes' => array (
|
| 400 |
+
'type' => 'big',
|
| 401 |
+
'textlines' => 4,
|
| 402 |
+
'lines' => 4
|
| 403 |
+
)
|
| 404 |
+
),
|
| 405 |
+
'orders' => array (
|
| 406 |
+
'timestamp' => array (
|
| 407 |
+
'type' => 'datetime'
|
| 408 |
+
),
|
| 409 |
+
'storeView' => array (
|
| 410 |
+
'type' => 'text',
|
| 411 |
+
'length' => 250
|
| 412 |
+
),
|
| 413 |
+
'shippingDescription' => array (
|
| 414 |
+
'type' => 'big',
|
| 415 |
+
'textlines' => 4,
|
| 416 |
+
'lines' => 4
|
| 417 |
+
),
|
| 418 |
+
'paymentDescription' => array (
|
| 419 |
+
'type' => 'big',
|
| 420 |
+
'textlines' => 4,
|
| 421 |
+
'lines' => 4
|
| 422 |
+
),
|
| 423 |
+
'couponCode' => array (
|
| 424 |
+
'type' => 'text',
|
| 425 |
+
'length' => 255
|
| 426 |
+
)
|
| 427 |
+
),
|
| 428 |
+
'addresses' => array (
|
| 429 |
+
'email' => array (
|
| 430 |
+
'type' => 'email',
|
| 431 |
+
),
|
| 432 |
+
'telephone' => array (
|
| 433 |
+
'type' => 'phone_gsm'
|
| 434 |
+
),
|
| 435 |
+
'fax' => array (
|
| 436 |
+
'type' => 'phone_fax'
|
| 437 |
+
)
|
| 438 |
+
),
|
| 439 |
+
'wishlistproducts' => array (
|
| 440 |
+
'timestamp' => array (
|
| 441 |
+
'type' => 'datetime'
|
| 442 |
+
),
|
| 443 |
+
'description' => array (
|
| 444 |
+
'type' => 'big',
|
| 445 |
+
'textlines' => 4,
|
| 446 |
+
'lines' => 4
|
| 447 |
+
),
|
| 448 |
+
'url' => array (
|
| 449 |
+
'type' => 'text',
|
| 450 |
+
'length' => 255
|
| 451 |
+
),
|
| 452 |
+
'image' => array (
|
| 453 |
+
'type' => 'text',
|
| 454 |
+
'length' => 255
|
| 455 |
+
),
|
| 456 |
+
'categories' => array (
|
| 457 |
+
'type' => 'text',
|
| 458 |
+
'length' => 255,
|
| 459 |
+
'textlines' => 4,
|
| 460 |
+
'lines' => 4
|
| 461 |
+
),
|
| 462 |
+
'storeView' => array (
|
| 463 |
+
'type' => 'text',
|
| 464 |
+
'length' => 250
|
| 465 |
+
),
|
| 466 |
+
'options' => array (
|
| 467 |
+
'type' => 'big',
|
| 468 |
+
'textlines' => 4,
|
| 469 |
+
'lines' => 4
|
| 470 |
+
),
|
| 471 |
+
'attributes' => array (
|
| 472 |
+
'type' => 'big',
|
| 473 |
+
'textlines' => 4,
|
| 474 |
+
'lines' => 4
|
| 475 |
+
),
|
| 476 |
+
)
|
| 477 |
+
);
|
| 478 |
+
|
| 479 |
+
if (!isset($definitions[$collectionType]) || !isset($definitions[$collectionType][$magentoName])) {
|
| 480 |
+
return array ('type' => 'text');
|
| 481 |
+
}
|
| 482 |
+
|
| 483 |
+
return $definitions[$collectionType][$magentoName];
|
| 484 |
+
}
|
| 485 |
+
|
| 486 |
+
/**
|
| 487 |
+
* Get the version of this extension.
|
| 488 |
+
*
|
| 489 |
+
* @return string
|
| 490 |
+
*/
|
| 491 |
+
public function getExtensionVersion()
|
| 492 |
+
{
|
| 493 |
+
$config = Mage::getConfig()->getModuleConfig('Copernica_MarketingSoftware')->asArray();
|
| 494 |
+
|
| 495 |
+
return $config['version'];
|
| 496 |
+
}
|
| 497 |
+
|
| 498 |
+
/**
|
| 499 |
+
* Get the url for the unsubscribe callback
|
| 500 |
+
*
|
| 501 |
+
* @return string
|
| 502 |
+
*/
|
| 503 |
+
public function unsubscribeCallbackUrl()
|
| 504 |
+
{
|
| 505 |
+
return Mage::getModel('core/url')->getUrl('copernica/unsubscribe/process', array());
|
| 506 |
+
}
|
| 507 |
+
|
| 508 |
+
/**
|
| 509 |
+
* Does the queue contain the magic token, which indicates that the synchronisation
|
| 510 |
+
* should be started?
|
| 511 |
+
*
|
| 512 |
+
* @return boolean
|
| 513 |
+
*/
|
| 514 |
+
public function isSynchronisationStartScheduled()
|
| 515 |
+
{
|
| 516 |
+
$count = Mage::getResourceModel('marketingsoftware/queue_item_collection')
|
| 517 |
+
->addFieldToFilter('action', 'start_sync')
|
| 518 |
+
->getSize();
|
| 519 |
+
|
| 520 |
+
return ($count > 0);
|
| 521 |
+
}
|
| 522 |
+
|
| 523 |
+
/**
|
| 524 |
+
* Is the Copernica module enabled?
|
| 525 |
+
*
|
| 526 |
+
* @return boolean
|
| 527 |
+
*/
|
| 528 |
+
public function enabled()
|
| 529 |
+
{
|
| 530 |
+
return (Mage::getConfig()->getNode('advanced/modules_disable_output/Copernica_MarketingSoftware', 'default', 0) == 0);
|
| 531 |
+
}
|
| 532 |
+
}
|
app/code/community/Copernica/MarketingSoftware/Helper/Profile.php
CHANGED
|
@@ -1,217 +1,217 @@
|
|
| 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 |
-
* This class will help with customer-profile relation.
|
| 29 |
-
*
|
| 30 |
-
* Profiles in copernica plarform represents either a customer in store view,
|
| 31 |
-
* or email in store view. It's important to understand that there could be more
|
| 32 |
-
* than one profile for one customer. It's cause one customer can be in more
|
| 33 |
-
* than one store view. Same applies to email addresses cause of same reasons.
|
| 34 |
-
*/
|
| 35 |
-
class Copernica_MarketingSoftware_Helper_Profile
|
| 36 |
-
{
|
| 37 |
-
/**
|
| 38 |
-
* Get copernica Id based on something and store view.
|
| 39 |
-
*
|
| 40 |
-
* @param mixed $something
|
| 41 |
-
* @param Copernica_MarketingSoftware_Model_Abstraction_Storeview $storeview
|
| 42 |
-
*/
|
| 43 |
-
public function getCopernicaId($something, Copernica_MarketingSoftware_Model_Abstraction_Storeview $storeview)
|
| 44 |
-
{
|
| 45 |
-
switch (true) {
|
| 46 |
-
// is it a customer instance?
|
| 47 |
-
case ($something instanceof Copernica_MarketingSoftware_Model_Copernica_Profile_Customer):
|
| 48 |
-
return $this->getCustomerCopernicaId($something, $storeview);
|
| 49 |
-
|
| 50 |
-
// is it a string? most likely it's an email address
|
| 51 |
-
case (is_string($something)):
|
| 52 |
-
return $this->getEmailCopernicaId($something, $storeview);
|
| 53 |
-
}
|
| 54 |
-
}
|
| 55 |
-
|
| 56 |
-
/**
|
| 57 |
-
* Get copernica Id by customer instance
|
| 58 |
-
*
|
| 59 |
-
* @param Copernica_MarketingSoftware_Model_Abstraction_Customer $customer
|
| 60 |
-
* @param Copernica_MarketingSoftware_Model_Abstraction_Storeview $storeview
|
| 61 |
-
* @return string
|
| 62 |
-
*/
|
| 63 |
-
public function getCustomerCopernicaId(Copernica_MarketingSoftware_Model_Abstraction_Customer $customer, Copernica_MarketingSoftware_Model_Abstraction_Storeview $storeview)
|
| 64 |
-
{
|
| 65 |
-
$customerId = $customer->id();
|
| 66 |
-
|
| 67 |
-
$profileCache = Mage::getModel('marketingsoftware/profile_cache')
|
| 68 |
-
->getCollection()
|
| 69 |
-
->addFieldToFilter('customer_id', $customerId)
|
| 70 |
-
->addFieldToFilter('store_view', $storeview->id())
|
| 71 |
-
->setPageSize(1);
|
| 72 |
-
|
| 73 |
-
if ($profileCache->count()) {
|
| 74 |
-
return $profileCache->getFirstItem()->getCopernicaId();
|
| 75 |
-
}
|
| 76 |
-
|
| 77 |
-
$profileCache = Mage::getModel('marketingsoftware/profile_cache')
|
| 78 |
-
->getCollection()
|
| 79 |
-
->addFieldToFilter('store_view', $storeview->id())
|
| 80 |
-
->addFieldToFilter('email', $customer->email())
|
| 81 |
-
->setPageSize(1);
|
| 82 |
-
|
| 83 |
-
if ($profileCache->count()) {
|
| 84 |
-
$profileCache = $profileCache->getFirstItem();
|
| 85 |
-
$profileCache->setCustomerId($customer->id());
|
| 86 |
-
|
| 87 |
-
$this->_upgradeSubscriberCopernicaId($profileCache);
|
| 88 |
-
|
| 89 |
-
$copernicaId = $this->generateCustomerCopernicaId($customer, $storeview);
|
| 90 |
-
|
| 91 |
-
$this->_convertCustomerId($this->generateEmailCopernicaId($customer->email(), $storeview), $copernicaId);
|
| 92 |
-
|
| 93 |
-
return $copernicaId;
|
| 94 |
-
}
|
| 95 |
-
|
| 96 |
-
$profileCache = $profileCache->getFirstItem();
|
| 97 |
-
|
| 98 |
-
$copernicaId = $this->generateCustomerCopernicaId($customer, $storeview);
|
| 99 |
-
|
| 100 |
-
$profileCache->setCopernicaId($copernicaId);
|
| 101 |
-
$profileCache->setStoreView($storeview->id());
|
| 102 |
-
$profileCache->setCustomerId($customer->id());
|
| 103 |
-
$profileCache->save();
|
| 104 |
-
|
| 105 |
-
$oldCopernicaId = $this->_generateOldCopernicaId($customer->oldEmail(), (string)$storeview);
|
| 106 |
-
|
| 107 |
-
$this->_convertCustomerId($oldCopernicaId, $copernicaId);
|
| 108 |
-
|
| 109 |
-
return $copernicaId;
|
| 110 |
-
}
|
| 111 |
-
|
| 112 |
-
/**
|
| 113 |
-
* This method will upgrade profile cache data.
|
| 114 |
-
*
|
| 115 |
-
* @param Copernica_MarketingSoftware_Model_Profile_Cache $profileCache
|
| 116 |
-
*/
|
| 117 |
-
protected function _upgradeSubscriberCopernicaId(Copernica_MarketingSoftware_Model_Profile_Cache $profileCache)
|
| 118 |
-
{
|
| 119 |
-
$customerId = $profileCache->getCustomerId();
|
| 120 |
-
|
| 121 |
-
$storeviewId = $profileCache->getStoreView();
|
| 122 |
-
|
| 123 |
-
$profileCache->setCopernicaId($customerId.'|'.$storeviewId);
|
| 124 |
-
$profileCache->save();
|
| 125 |
-
}
|
| 126 |
-
|
| 127 |
-
/**
|
| 128 |
-
* Generate Copernica Id from our customer instance and store view
|
| 129 |
-
*
|
| 130 |
-
* @param Copernica_MarketingSoftware_Model_Abstraction_Customer $customer
|
| 131 |
-
* @param Copernica_MarketingSoftware_Model_Abstraction_Storeview $storeview
|
| 132 |
-
* @return string
|
| 133 |
-
*/
|
| 134 |
-
public function generateCustomerCopernicaId(Copernica_MarketingSoftware_Model_Abstraction_Customer $customer, Copernica_MarketingSoftware_Model_Abstraction_Storeview $storeview)
|
| 135 |
-
{
|
| 136 |
-
return $customer->id().'|'.$storeview->id();
|
| 137 |
-
}
|
| 138 |
-
|
| 139 |
-
/**
|
| 140 |
-
* Generate copernica Id from an email address and store View.
|
| 141 |
-
*
|
| 142 |
-
* @param string $email
|
| 143 |
-
* @param Copernica_MarketingSoftware_Model_Abstraction_Storeview $storeview
|
| 144 |
-
* @return string
|
| 145 |
-
*/
|
| 146 |
-
public function getEmailCopernicaId($email, Copernica_MarketingSoftware_Model_Abstraction_Storeview $storeview)
|
| 147 |
-
{
|
| 148 |
-
$profileCache = Mage::getModel('marketingsoftware/profile_cache')
|
| 149 |
-
->getCollection()
|
| 150 |
-
->addFieldToFilter('email', $email)
|
| 151 |
-
->addFieldToFilter('store_view', $storeview->id())
|
| 152 |
-
->setPageSize(1);
|
| 153 |
-
|
| 154 |
-
if ($profileCache->count()) {
|
| 155 |
-
return $profileCache->getFirstItem()->getCopernicaId();
|
| 156 |
-
}
|
| 157 |
-
|
| 158 |
-
$profileCache = $profileCache->getFirstItem();
|
| 159 |
-
|
| 160 |
-
$oldCopernicaId = $this->_generateOldCopernicaId($email, (string)$storeview);
|
| 161 |
-
|
| 162 |
-
$copernicaId = $this->generateEmailCopernicaId($email, $storeview);
|
| 163 |
-
|
| 164 |
-
$this->_convertCustomerId($oldCopernicaId, $copernicaId);
|
| 165 |
-
|
| 166 |
-
$profileCache->setEmail($email);
|
| 167 |
-
$profileCache->setCopernicaId($copernicaId);
|
| 168 |
-
$profileCache->setStoreView($storeview->id());
|
| 169 |
-
|
| 170 |
-
$profileCache->save();
|
| 171 |
-
|
| 172 |
-
return $copernicaId;
|
| 173 |
-
}
|
| 174 |
-
|
| 175 |
-
/**
|
| 176 |
-
* Generate Copernica Id from our email and store view
|
| 177 |
-
*
|
| 178 |
-
* @param string $email
|
| 179 |
-
* @param Copernica_MarketingSoftware_Model_Abstraction_Storeview $storeview
|
| 180 |
-
* @return string
|
| 181 |
-
*/
|
| 182 |
-
public function generateEmailCopernicaId($email, Copernica_MarketingSoftware_Model_Abstraction_Storeview $storeview)
|
| 183 |
-
{
|
| 184 |
-
return $email.'|'.$storeview->id();
|
| 185 |
-
}
|
| 186 |
-
|
| 187 |
-
/**
|
| 188 |
-
* Basically it's a helper method that will convert old customer Id in
|
| 189 |
-
* Copernica platform into normal Magento customer Id.
|
| 190 |
-
*
|
| 191 |
-
* @param string $oldCopernicaId
|
| 192 |
-
* @param string $newCustomerId
|
| 193 |
-
*/
|
| 194 |
-
protected function _convertCustomerId($oldCopernicaId, $newCustomerId)
|
| 195 |
-
{
|
| 196 |
-
$request = Mage::helper('marketingsoftware/rest_request');
|
| 197 |
-
|
| 198 |
-
$databaseId = Mage::helper('marketingsoftware/api')->getDatabaseId();
|
| 199 |
-
|
| 200 |
-
$request->put('database/'.$databaseId.'/profiles',
|
| 201 |
-
array( 'customer_id' => $newCustomerId),
|
| 202 |
-
array( 'fields[]' => 'customer_id=='.$oldCopernicaId )
|
| 203 |
-
);
|
| 204 |
-
}
|
| 205 |
-
|
| 206 |
-
/**
|
| 207 |
-
* Generates a unique customer ID based on the e-mail address and the storeview.
|
| 208 |
-
*
|
| 209 |
-
* @param string $email
|
| 210 |
-
* @param Copernica_MarketingSoftware_Model_Abstraction_Storeview $storeview
|
| 211 |
-
* @return string
|
| 212 |
-
*/
|
| 213 |
-
protected function _generateOldCopernicaId($email, Copernica_MarketingSoftware_Model_Abstraction_Storeview $storeview)
|
| 214 |
-
{
|
| 215 |
-
return md5(strtolower($email) . $storeview);
|
| 216 |
-
}
|
| 217 |
}
|
| 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 |
+
* This class will help with customer-profile relation.
|
| 29 |
+
*
|
| 30 |
+
* Profiles in copernica plarform represents either a customer in store view,
|
| 31 |
+
* or email in store view. It's important to understand that there could be more
|
| 32 |
+
* than one profile for one customer. It's cause one customer can be in more
|
| 33 |
+
* than one store view. Same applies to email addresses cause of same reasons.
|
| 34 |
+
*/
|
| 35 |
+
class Copernica_MarketingSoftware_Helper_Profile
|
| 36 |
+
{
|
| 37 |
+
/**
|
| 38 |
+
* Get copernica Id based on something and store view.
|
| 39 |
+
*
|
| 40 |
+
* @param mixed $something
|
| 41 |
+
* @param Copernica_MarketingSoftware_Model_Abstraction_Storeview $storeview
|
| 42 |
+
*/
|
| 43 |
+
public function getCopernicaId($something, Copernica_MarketingSoftware_Model_Abstraction_Storeview $storeview)
|
| 44 |
+
{
|
| 45 |
+
switch (true) {
|
| 46 |
+
// is it a customer instance?
|
| 47 |
+
case ($something instanceof Copernica_MarketingSoftware_Model_Copernica_Profile_Customer):
|
| 48 |
+
return $this->getCustomerCopernicaId($something, $storeview);
|
| 49 |
+
|
| 50 |
+
// is it a string? most likely it's an email address
|
| 51 |
+
case (is_string($something)):
|
| 52 |
+
return $this->getEmailCopernicaId($something, $storeview);
|
| 53 |
+
}
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
/**
|
| 57 |
+
* Get copernica Id by customer instance
|
| 58 |
+
*
|
| 59 |
+
* @param Copernica_MarketingSoftware_Model_Abstraction_Customer $customer
|
| 60 |
+
* @param Copernica_MarketingSoftware_Model_Abstraction_Storeview $storeview
|
| 61 |
+
* @return string
|
| 62 |
+
*/
|
| 63 |
+
public function getCustomerCopernicaId(Copernica_MarketingSoftware_Model_Abstraction_Customer $customer, Copernica_MarketingSoftware_Model_Abstraction_Storeview $storeview)
|
| 64 |
+
{
|
| 65 |
+
$customerId = $customer->id();
|
| 66 |
+
|
| 67 |
+
$profileCache = Mage::getModel('marketingsoftware/profile_cache')
|
| 68 |
+
->getCollection()
|
| 69 |
+
->addFieldToFilter('customer_id', $customerId)
|
| 70 |
+
->addFieldToFilter('store_view', $storeview->id())
|
| 71 |
+
->setPageSize(1);
|
| 72 |
+
|
| 73 |
+
if ($profileCache->count()) {
|
| 74 |
+
return $profileCache->getFirstItem()->getCopernicaId();
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
$profileCache = Mage::getModel('marketingsoftware/profile_cache')
|
| 78 |
+
->getCollection()
|
| 79 |
+
->addFieldToFilter('store_view', $storeview->id())
|
| 80 |
+
->addFieldToFilter('email', $customer->email())
|
| 81 |
+
->setPageSize(1);
|
| 82 |
+
|
| 83 |
+
if ($profileCache->count()) {
|
| 84 |
+
$profileCache = $profileCache->getFirstItem();
|
| 85 |
+
$profileCache->setCustomerId($customer->id());
|
| 86 |
+
|
| 87 |
+
$this->_upgradeSubscriberCopernicaId($profileCache);
|
| 88 |
+
|
| 89 |
+
$copernicaId = $this->generateCustomerCopernicaId($customer, $storeview);
|
| 90 |
+
|
| 91 |
+
$this->_convertCustomerId($this->generateEmailCopernicaId($customer->email(), $storeview), $copernicaId);
|
| 92 |
+
|
| 93 |
+
return $copernicaId;
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
$profileCache = $profileCache->getFirstItem();
|
| 97 |
+
|
| 98 |
+
$copernicaId = $this->generateCustomerCopernicaId($customer, $storeview);
|
| 99 |
+
|
| 100 |
+
$profileCache->setCopernicaId($copernicaId);
|
| 101 |
+
$profileCache->setStoreView($storeview->id());
|
| 102 |
+
$profileCache->setCustomerId($customer->id());
|
| 103 |
+
$profileCache->save();
|
| 104 |
+
|
| 105 |
+
$oldCopernicaId = $this->_generateOldCopernicaId($customer->oldEmail(), (string)$storeview);
|
| 106 |
+
|
| 107 |
+
$this->_convertCustomerId($oldCopernicaId, $copernicaId);
|
| 108 |
+
|
| 109 |
+
return $copernicaId;
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
/**
|
| 113 |
+
* This method will upgrade profile cache data.
|
| 114 |
+
*
|
| 115 |
+
* @param Copernica_MarketingSoftware_Model_Profile_Cache $profileCache
|
| 116 |
+
*/
|
| 117 |
+
protected function _upgradeSubscriberCopernicaId(Copernica_MarketingSoftware_Model_Profile_Cache $profileCache)
|
| 118 |
+
{
|
| 119 |
+
$customerId = $profileCache->getCustomerId();
|
| 120 |
+
|
| 121 |
+
$storeviewId = $profileCache->getStoreView();
|
| 122 |
+
|
| 123 |
+
$profileCache->setCopernicaId($customerId.'|'.$storeviewId);
|
| 124 |
+
$profileCache->save();
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
/**
|
| 128 |
+
* Generate Copernica Id from our customer instance and store view
|
| 129 |
+
*
|
| 130 |
+
* @param Copernica_MarketingSoftware_Model_Abstraction_Customer $customer
|
| 131 |
+
* @param Copernica_MarketingSoftware_Model_Abstraction_Storeview $storeview
|
| 132 |
+
* @return string
|
| 133 |
+
*/
|
| 134 |
+
public function generateCustomerCopernicaId(Copernica_MarketingSoftware_Model_Abstraction_Customer $customer, Copernica_MarketingSoftware_Model_Abstraction_Storeview $storeview)
|
| 135 |
+
{
|
| 136 |
+
return $customer->id().'|'.$storeview->id();
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
/**
|
| 140 |
+
* Generate copernica Id from an email address and store View.
|
| 141 |
+
*
|
| 142 |
+
* @param string $email
|
| 143 |
+
* @param Copernica_MarketingSoftware_Model_Abstraction_Storeview $storeview
|
| 144 |
+
* @return string
|
| 145 |
+
*/
|
| 146 |
+
public function getEmailCopernicaId($email, Copernica_MarketingSoftware_Model_Abstraction_Storeview $storeview)
|
| 147 |
+
{
|
| 148 |
+
$profileCache = Mage::getModel('marketingsoftware/profile_cache')
|
| 149 |
+
->getCollection()
|
| 150 |
+
->addFieldToFilter('email', $email)
|
| 151 |
+
->addFieldToFilter('store_view', $storeview->id())
|
| 152 |
+
->setPageSize(1);
|
| 153 |
+
|
| 154 |
+
if ($profileCache->count()) {
|
| 155 |
+
return $profileCache->getFirstItem()->getCopernicaId();
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
$profileCache = $profileCache->getFirstItem();
|
| 159 |
+
|
| 160 |
+
$oldCopernicaId = $this->_generateOldCopernicaId($email, (string)$storeview);
|
| 161 |
+
|
| 162 |
+
$copernicaId = $this->generateEmailCopernicaId($email, $storeview);
|
| 163 |
+
|
| 164 |
+
$this->_convertCustomerId($oldCopernicaId, $copernicaId);
|
| 165 |
+
|
| 166 |
+
$profileCache->setEmail($email);
|
| 167 |
+
$profileCache->setCopernicaId($copernicaId);
|
| 168 |
+
$profileCache->setStoreView($storeview->id());
|
| 169 |
+
|
| 170 |
+
$profileCache->save();
|
| 171 |
+
|
| 172 |
+
return $copernicaId;
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
/**
|
| 176 |
+
* Generate Copernica Id from our email and store view
|
| 177 |
+
*
|
| 178 |
+
* @param string $email
|
| 179 |
+
* @param Copernica_MarketingSoftware_Model_Abstraction_Storeview $storeview
|
| 180 |
+
* @return string
|
| 181 |
+
*/
|
| 182 |
+
public function generateEmailCopernicaId($email, Copernica_MarketingSoftware_Model_Abstraction_Storeview $storeview)
|
| 183 |
+
{
|
| 184 |
+
return $email.'|'.$storeview->id();
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
/**
|
| 188 |
+
* Basically it's a helper method that will convert old customer Id in
|
| 189 |
+
* Copernica platform into normal Magento customer Id.
|
| 190 |
+
*
|
| 191 |
+
* @param string $oldCopernicaId
|
| 192 |
+
* @param string $newCustomerId
|
| 193 |
+
*/
|
| 194 |
+
protected function _convertCustomerId($oldCopernicaId, $newCustomerId)
|
| 195 |
+
{
|
| 196 |
+
$request = Mage::helper('marketingsoftware/rest_request');
|
| 197 |
+
|
| 198 |
+
$databaseId = Mage::helper('marketingsoftware/api')->getDatabaseId();
|
| 199 |
+
|
| 200 |
+
$request->put('database/'.$databaseId.'/profiles',
|
| 201 |
+
array( 'customer_id' => $newCustomerId),
|
| 202 |
+
array( 'fields[]' => 'customer_id=='.$oldCopernicaId )
|
| 203 |
+
);
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
/**
|
| 207 |
+
* Generates a unique customer ID based on the e-mail address and the storeview.
|
| 208 |
+
*
|
| 209 |
+
* @param string $email
|
| 210 |
+
* @param Copernica_MarketingSoftware_Model_Abstraction_Storeview $storeview
|
| 211 |
+
* @return string
|
| 212 |
+
*/
|
| 213 |
+
protected function _generateOldCopernicaId($email, Copernica_MarketingSoftware_Model_Abstraction_Storeview $storeview)
|
| 214 |
+
{
|
| 215 |
+
return md5(strtolower($email) . $storeview);
|
| 216 |
+
}
|
| 217 |
}
|
app/code/community/Copernica/MarketingSoftware/Helper/Rest/Request.php
CHANGED
|
@@ -1,361 +1,361 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
/**
|
| 3 |
-
* Copernica Marketing Software
|
| 4 |
-
*
|
| 5 |
-
* @category Copernica
|
| 6 |
-
* @package Copernica_MarketingSoftware
|
| 7 |
-
*/
|
| 8 |
-
|
| 9 |
-
/**
|
| 10 |
-
* Copernica REST request helper. This helper is a reusable API request. To
|
| 11 |
-
* utilize REST API use 4 basic methods: self::get, self::post(), self::put(),
|
| 12 |
-
* self::delete().
|
| 13 |
-
*/
|
| 14 |
-
class Copernica_MarketingSoftware_Helper_Rest_Request
|
| 15 |
-
{
|
| 16 |
-
/**
|
| 17 |
-
* Access token that we want to use with our request.
|
| 18 |
-
*
|
| 19 |
-
* @var string
|
| 20 |
-
*/
|
| 21 |
-
protected $_accessToken = '';
|
| 22 |
-
|
| 23 |
-
/**
|
| 24 |
-
* The url to API that we will use.
|
| 25 |
-
*
|
| 26 |
-
* @var string
|
| 27 |
-
*/
|
| 28 |
-
protected $_hostname = 'https://api.copernica.com';
|
| 29 |
-
|
| 30 |
-
/**
|
| 31 |
-
* The curl objects
|
| 32 |
-
*
|
| 33 |
-
* @var array
|
| 34 |
-
*/
|
| 35 |
-
protected $_children = array();
|
| 36 |
-
|
| 37 |
-
/**
|
| 38 |
-
* Multi curl interface
|
| 39 |
-
*
|
| 40 |
-
* @var resource
|
| 41 |
-
*/
|
| 42 |
-
protected $_multi;
|
| 43 |
-
|
| 44 |
-
/**
|
| 45 |
-
* Cipher lists for different crypto libs
|
| 46 |
-
*
|
| 47 |
-
* @var array
|
| 48 |
-
*/
|
| 49 |
-
static protected $_cipherList = array(
|
| 50 |
-
'openssl' => "ECDHE-RSA-AES128-SHA256:AES128-GCM-SHA256:RC4:+HIGH",
|
| 51 |
-
'nss' => "ecdhe_rsa_aes_256_sha:rc4",
|
| 52 |
-
);
|
| 53 |
-
|
| 54 |
-
/**
|
| 55 |
-
* The currently used crypto lib.
|
| 56 |
-
*
|
| 57 |
-
* @var string
|
| 58 |
-
*/
|
| 59 |
-
static protected $_cryptoLib = null;
|
| 60 |
-
|
| 61 |
-
/**
|
| 62 |
-
* We use normal PHP constructor cause Helpers are not childs of
|
| 63 |
-
* Varien_Object class, so no _construct is called.
|
| 64 |
-
*/
|
| 65 |
-
public function __construct()
|
| 66 |
-
{
|
| 67 |
-
$config = Mage::helper('marketingsoftware/config');
|
| 68 |
-
|
| 69 |
-
if ($hostname = $config->getApiHostname()) {
|
| 70 |
-
$this->_hostname = $hostname;
|
| 71 |
-
} else {
|
| 72 |
-
$this->_hostname = 'https://api.copernica.com';
|
| 73 |
-
|
| 74 |
-
$config->setApiHostname($this->_hostname);
|
| 75 |
-
}
|
| 76 |
-
|
| 77 |
-
$accessToken = $config->getAccessToken();
|
| 78 |
-
|
| 79 |
-
if ($accessToken) {
|
| 80 |
-
$this->_accessToken = $accessToken;
|
| 81 |
-
}
|
| 82 |
-
}
|
| 83 |
-
|
| 84 |
-
/**
|
| 85 |
-
* Destructor for this object.
|
| 86 |
-
*/
|
| 87 |
-
public function __destruct()
|
| 88 |
-
{
|
| 89 |
-
if (!is_null($this->_multi)) {
|
| 90 |
-
$this->commit();
|
| 91 |
-
}
|
| 92 |
-
}
|
| 93 |
-
|
| 94 |
-
/**
|
| 95 |
-
* Check request instance. This method will check all essentials to make an
|
| 96 |
-
* API call.
|
| 97 |
-
*
|
| 98 |
-
* @return bool
|
| 99 |
-
*/
|
| 100 |
-
public function check ()
|
| 101 |
-
{
|
| 102 |
-
if (empty($this->_accessToken)) {
|
| 103 |
-
return false;
|
| 104 |
-
}
|
| 105 |
-
|
| 106 |
-
if (empty($this->_hostname)) {
|
| 107 |
-
return false;
|
| 108 |
-
}
|
| 109 |
-
|
| 110 |
-
return true;
|
| 111 |
-
}
|
| 112 |
-
|
| 113 |
-
/**
|
| 114 |
-
* Helper method to build up a query string
|
| 115 |
-
*
|
| 116 |
-
* @param assoc $data
|
| 117 |
-
* @return string
|
| 118 |
-
*/
|
| 119 |
-
protected function _buildQueryString($data)
|
| 120 |
-
{
|
| 121 |
-
$parts = array();
|
| 122 |
-
|
| 123 |
-
foreach ($data as $key => $value) {
|
| 124 |
-
if (is_array($value)) {
|
| 125 |
-
foreach ($value as $valueItem) {
|
| 126 |
-
$parts[] = $key.'[]='.urlencode(strval($valueItem));
|
| 127 |
-
}
|
| 128 |
-
} else {
|
| 129 |
-
$parts[] = $key.'='.urlencode(strval($value));
|
| 130 |
-
}
|
| 131 |
-
}
|
| 132 |
-
|
| 133 |
-
return '?'.implode('&', $parts);
|
| 134 |
-
}
|
| 135 |
-
|
| 136 |
-
/**
|
| 137 |
-
* Prepare a proper version of curl instance
|
| 138 |
-
*
|
| 139 |
-
* @return resource
|
| 140 |
-
*/
|
| 141 |
-
protected function _prepareCurl()
|
| 142 |
-
{
|
| 143 |
-
$curl = curl_init();
|
| 144 |
-
|
| 145 |
-
if (is_null(self::$_cryptoLib)) {
|
| 146 |
-
$version = curl_version();
|
| 147 |
-
|
| 148 |
-
if (strpos($version['ssl_version'], 'NSS') !== false) {
|
| 149 |
-
self::$_cryptoLib = 'nss';
|
| 150 |
-
} else {
|
| 151 |
-
self::$_cryptoLib = 'openssl';
|
| 152 |
-
}
|
| 153 |
-
}
|
| 154 |
-
|
| 155 |
-
curl_setopt($curl, CURLOPT_SSL_CIPHER_LIST, self::$_cipherList[self::$_cryptoLib]);
|
| 156 |
-
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
|
| 157 |
-
|
| 158 |
-
return $curl;
|
| 159 |
-
}
|
| 160 |
-
|
| 161 |
-
/**
|
| 162 |
-
* Make a GET requst
|
| 163 |
-
*
|
| 164 |
-
* @param string $request
|
| 165 |
-
* @param assoc $data
|
| 166 |
-
* @return assoc
|
| 167 |
-
*/
|
| 168 |
-
public function get($request, $data = null)
|
| 169 |
-
{
|
| 170 |
-
$curl = $this->_prepareCurl();
|
| 171 |
-
|
| 172 |
-
if ($this->_accessToken) {
|
| 173 |
-
$request.=$this->_buildQueryString(array_merge(array(
|
| 174 |
-
'access_token' => $this->_accessToken),
|
| 175 |
-
is_null($data) ? array() : $data
|
| 176 |
-
));
|
| 177 |
-
} else {
|
| 178 |
-
$request.=$this->_buildQueryString(is_null($data) ? array() : $data);
|
| 179 |
-
}
|
| 180 |
-
|
| 181 |
-
curl_setopt($curl, CURLOPT_URL, $this->_hostname.'/'.$request);
|
| 182 |
-
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
| 183 |
-
|
| 184 |
-
$output = json_decode(curl_exec($curl), true);
|
| 185 |
-
|
| 186 |
-
curl_close($curl);
|
| 187 |
-
|
| 188 |
-
return $output;
|
| 189 |
-
}
|
| 190 |
-
|
| 191 |
-
/**
|
| 192 |
-
* Make a POST request
|
| 193 |
-
*
|
| 194 |
-
* @param string $request
|
| 195 |
-
* @param assoc $data
|
| 196 |
-
* @param assoc $query
|
| 197 |
-
*/
|
| 198 |
-
public function post($request, $data = null, $query = null)
|
| 199 |
-
{
|
| 200 |
-
if (is_array($query)) {
|
| 201 |
-
$request.= $this->_buildQueryString(array_merge( $query, array('access_token' => $this->_accessToken) ));
|
| 202 |
-
} else {
|
| 203 |
-
$request.='?access_token='.$this->_accessToken;
|
| 204 |
-
}
|
| 205 |
-
|
| 206 |
-
$curl = $this->_prepareCurl();
|
| 207 |
-
|
| 208 |
-
curl_setopt($curl, CURLOPT_URL, $this->_hostname.'/'.$request);
|
| 209 |
-
curl_setopt($curl, CURLOPT_POST, true);
|
| 210 |
-
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
|
| 211 |
-
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
|
| 212 |
-
'content-type: application/json',
|
| 213 |
-
'accept: application/json'
|
| 214 |
-
));
|
| 215 |
-
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
|
| 216 |
-
|
| 217 |
-
if ($this->_appendMulti($curl)) {
|
| 218 |
-
return true;
|
| 219 |
-
}
|
| 220 |
-
|
| 221 |
-
curl_exec($curl);
|
| 222 |
-
|
| 223 |
-
curl_close($curl);
|
| 224 |
-
|
| 225 |
-
return true;
|
| 226 |
-
}
|
| 227 |
-
|
| 228 |
-
/**
|
| 229 |
-
* Make a PUT request
|
| 230 |
-
*
|
| 231 |
-
* @param string $request
|
| 232 |
-
* @param assoc $data
|
| 233 |
-
* @param assoc $query
|
| 234 |
-
*/
|
| 235 |
-
public function put($request, $data = null, $query = null)
|
| 236 |
-
{
|
| 237 |
-
if (is_array($query)) {
|
| 238 |
-
$request.= $this->_buildQueryString(array_merge( $query, array('access_token' => $this->_accessToken) ));
|
| 239 |
-
} else {
|
| 240 |
-
$request.='?access_token='.$this->_accessToken;
|
| 241 |
-
}
|
| 242 |
-
|
| 243 |
-
$curl = $this->_prepareCurl();
|
| 244 |
-
|
| 245 |
-
curl_setopt($curl, CURLOPT_URL, $this->_hostname.'/'.$request);
|
| 246 |
-
curl_setopt($curl, CURLOPT_POST, true);
|
| 247 |
-
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
|
| 248 |
-
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
|
| 249 |
-
'content-type: application/json',
|
| 250 |
-
'accept: application/json'
|
| 251 |
-
));
|
| 252 |
-
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
|
| 253 |
-
// curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
| 254 |
-
|
| 255 |
-
if ($this->_appendMulti($curl)) {
|
| 256 |
-
return true;
|
| 257 |
-
}
|
| 258 |
-
|
| 259 |
-
curl_exec($curl);
|
| 260 |
-
|
| 261 |
-
curl_close($curl);
|
| 262 |
-
|
| 263 |
-
return true;
|
| 264 |
-
}
|
| 265 |
-
|
| 266 |
-
/**
|
| 267 |
-
* Make a DELETE request
|
| 268 |
-
*
|
| 269 |
-
* @param string $request
|
| 270 |
-
* @param assoc $data
|
| 271 |
-
*/
|
| 272 |
-
public function delete($request, $data = null)
|
| 273 |
-
{
|
| 274 |
-
$curl = $this->_prepareCurl();
|
| 275 |
-
|
| 276 |
-
$request.='?access_token='.$this->_accessToken;
|
| 277 |
-
|
| 278 |
-
curl_setopt($curl, CURLOPT_URL, $this->_hostname.'/'.$request);
|
| 279 |
-
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");
|
| 280 |
-
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
|
| 281 |
-
'content-type: application/json',
|
| 282 |
-
'accept: application/json'
|
| 283 |
-
));
|
| 284 |
-
|
| 285 |
-
if ($this->_appendMulti($curl)) {
|
| 286 |
-
return true;
|
| 287 |
-
}
|
| 288 |
-
|
| 289 |
-
curl_exec($curl);
|
| 290 |
-
|
| 291 |
-
curl_close($curl);
|
| 292 |
-
|
| 293 |
-
return true;
|
| 294 |
-
}
|
| 295 |
-
|
| 296 |
-
/**
|
| 297 |
-
* This method will start preparing calls to execute them later on with
|
| 298 |
-
* 'multi' interface.
|
| 299 |
-
*/
|
| 300 |
-
public function prepare()
|
| 301 |
-
{
|
| 302 |
-
$this->_multi = curl_multi_init();
|
| 303 |
-
|
| 304 |
-
return $this;
|
| 305 |
-
}
|
| 306 |
-
|
| 307 |
-
/**
|
| 308 |
-
* Commit all prepared calls
|
| 309 |
-
*/
|
| 310 |
-
public function commit()
|
| 311 |
-
{
|
| 312 |
-
$active = true;
|
| 313 |
-
|
| 314 |
-
if (is_null($this->_multi)) {
|
| 315 |
-
return $this;
|
| 316 |
-
}
|
| 317 |
-
|
| 318 |
-
do {
|
| 319 |
-
while (CURLM_CALL_MULTI_PERFORM === curl_multi_exec($this->_multi, $running));
|
| 320 |
-
if (!$running) {
|
| 321 |
-
break;
|
| 322 |
-
}
|
| 323 |
-
|
| 324 |
-
while (($res = curl_multi_select($this->_multi)) === 0){};
|
| 325 |
-
|
| 326 |
-
if ($res === false) {
|
| 327 |
-
break;
|
| 328 |
-
}
|
| 329 |
-
} while(true);
|
| 330 |
-
|
| 331 |
-
foreach ($this->_children as $child) {
|
| 332 |
-
curl_multi_remove_handle($this->_multi, $child);
|
| 333 |
-
}
|
| 334 |
-
|
| 335 |
-
curl_multi_close($this->_multi);
|
| 336 |
-
|
| 337 |
-
$this->_multi = null;
|
| 338 |
-
|
| 339 |
-
return $this;
|
| 340 |
-
}
|
| 341 |
-
|
| 342 |
-
/**
|
| 343 |
-
* Append another curl request to multi interface
|
| 344 |
-
*/
|
| 345 |
-
protected function _appendMulti($curl)
|
| 346 |
-
{
|
| 347 |
-
if (!is_resource($this->_multi)) {
|
| 348 |
-
return false;
|
| 349 |
-
}
|
| 350 |
-
|
| 351 |
-
$code = curl_multi_add_handle($this->_multi, $curl);
|
| 352 |
-
|
| 353 |
-
if ($code == 0) {
|
| 354 |
-
$this->_children[] = $curl;
|
| 355 |
-
|
| 356 |
-
return true;
|
| 357 |
-
}
|
| 358 |
-
|
| 359 |
-
return false;
|
| 360 |
-
}
|
| 361 |
-
}
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Copernica Marketing Software
|
| 4 |
+
*
|
| 5 |
+
* @category Copernica
|
| 6 |
+
* @package Copernica_MarketingSoftware
|
| 7 |
+
*/
|
| 8 |
+
|
| 9 |
+
/**
|
| 10 |
+
* Copernica REST request helper. This helper is a reusable API request. To
|
| 11 |
+
* utilize REST API use 4 basic methods: self::get, self::post(), self::put(),
|
| 12 |
+
* self::delete().
|
| 13 |
+
*/
|
| 14 |
+
class Copernica_MarketingSoftware_Helper_Rest_Request
|
| 15 |
+
{
|
| 16 |
+
/**
|
| 17 |
+
* Access token that we want to use with our request.
|
| 18 |
+
*
|
| 19 |
+
* @var string
|
| 20 |
+
*/
|
| 21 |
+
protected $_accessToken = '';
|
| 22 |
+
|
| 23 |
+
/**
|
| 24 |
+
* The url to API that we will use.
|
| 25 |
+
*
|
| 26 |
+
* @var string
|
| 27 |
+
*/
|
| 28 |
+
protected $_hostname = 'https://api.copernica.com';
|
| 29 |
+
|
| 30 |
+
/**
|
| 31 |
+
* The curl objects
|
| 32 |
+
*
|
| 33 |
+
* @var array
|
| 34 |
+
*/
|
| 35 |
+
protected $_children = array();
|
| 36 |
+
|
| 37 |
+
/**
|
| 38 |
+
* Multi curl interface
|
| 39 |
+
*
|
| 40 |
+
* @var resource
|
| 41 |
+
*/
|
| 42 |
+
protected $_multi;
|
| 43 |
+
|
| 44 |
+
/**
|
| 45 |
+
* Cipher lists for different crypto libs
|
| 46 |
+
*
|
| 47 |
+
* @var array
|
| 48 |
+
*/
|
| 49 |
+
static protected $_cipherList = array(
|
| 50 |
+
'openssl' => "ECDHE-RSA-AES128-SHA256:AES128-GCM-SHA256:RC4:+HIGH",
|
| 51 |
+
'nss' => "ecdhe_rsa_aes_256_sha:rc4",
|
| 52 |
+
);
|
| 53 |
+
|
| 54 |
+
/**
|
| 55 |
+
* The currently used crypto lib.
|
| 56 |
+
*
|
| 57 |
+
* @var string
|
| 58 |
+
*/
|
| 59 |
+
static protected $_cryptoLib = null;
|
| 60 |
+
|
| 61 |
+
/**
|
| 62 |
+
* We use normal PHP constructor cause Helpers are not childs of
|
| 63 |
+
* Varien_Object class, so no _construct is called.
|
| 64 |
+
*/
|
| 65 |
+
public function __construct()
|
| 66 |
+
{
|
| 67 |
+
$config = Mage::helper('marketingsoftware/config');
|
| 68 |
+
|
| 69 |
+
if ($hostname = $config->getApiHostname()) {
|
| 70 |
+
$this->_hostname = $hostname;
|
| 71 |
+
} else {
|
| 72 |
+
$this->_hostname = 'https://api.copernica.com';
|
| 73 |
+
|
| 74 |
+
$config->setApiHostname($this->_hostname);
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
$accessToken = $config->getAccessToken();
|
| 78 |
+
|
| 79 |
+
if ($accessToken) {
|
| 80 |
+
$this->_accessToken = $accessToken;
|
| 81 |
+
}
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
/**
|
| 85 |
+
* Destructor for this object.
|
| 86 |
+
*/
|
| 87 |
+
public function __destruct()
|
| 88 |
+
{
|
| 89 |
+
if (!is_null($this->_multi)) {
|
| 90 |
+
$this->commit();
|
| 91 |
+
}
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
/**
|
| 95 |
+
* Check request instance. This method will check all essentials to make an
|
| 96 |
+
* API call.
|
| 97 |
+
*
|
| 98 |
+
* @return bool
|
| 99 |
+
*/
|
| 100 |
+
public function check ()
|
| 101 |
+
{
|
| 102 |
+
if (empty($this->_accessToken)) {
|
| 103 |
+
return false;
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
if (empty($this->_hostname)) {
|
| 107 |
+
return false;
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
return true;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
/**
|
| 114 |
+
* Helper method to build up a query string
|
| 115 |
+
*
|
| 116 |
+
* @param assoc $data
|
| 117 |
+
* @return string
|
| 118 |
+
*/
|
| 119 |
+
protected function _buildQueryString($data)
|
| 120 |
+
{
|
| 121 |
+
$parts = array();
|
| 122 |
+
|
| 123 |
+
foreach ($data as $key => $value) {
|
| 124 |
+
if (is_array($value)) {
|
| 125 |
+
foreach ($value as $valueItem) {
|
| 126 |
+
$parts[] = $key.'[]='.urlencode(strval($valueItem));
|
| 127 |
+
}
|
| 128 |
+
} else {
|
| 129 |
+
$parts[] = $key.'='.urlencode(strval($value));
|
| 130 |
+
}
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
return '?'.implode('&', $parts);
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
/**
|
| 137 |
+
* Prepare a proper version of curl instance
|
| 138 |
+
*
|
| 139 |
+
* @return resource
|
| 140 |
+
*/
|
| 141 |
+
protected function _prepareCurl()
|
| 142 |
+
{
|
| 143 |
+
$curl = curl_init();
|
| 144 |
+
|
| 145 |
+
if (is_null(self::$_cryptoLib)) {
|
| 146 |
+
$version = curl_version();
|
| 147 |
+
|
| 148 |
+
if (strpos($version['ssl_version'], 'NSS') !== false) {
|
| 149 |
+
self::$_cryptoLib = 'nss';
|
| 150 |
+
} else {
|
| 151 |
+
self::$_cryptoLib = 'openssl';
|
| 152 |
+
}
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
curl_setopt($curl, CURLOPT_SSL_CIPHER_LIST, self::$_cipherList[self::$_cryptoLib]);
|
| 156 |
+
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
|
| 157 |
+
|
| 158 |
+
return $curl;
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
/**
|
| 162 |
+
* Make a GET requst
|
| 163 |
+
*
|
| 164 |
+
* @param string $request
|
| 165 |
+
* @param assoc $data
|
| 166 |
+
* @return assoc
|
| 167 |
+
*/
|
| 168 |
+
public function get($request, $data = null)
|
| 169 |
+
{
|
| 170 |
+
$curl = $this->_prepareCurl();
|
| 171 |
+
|
| 172 |
+
if ($this->_accessToken) {
|
| 173 |
+
$request.=$this->_buildQueryString(array_merge(array(
|
| 174 |
+
'access_token' => $this->_accessToken),
|
| 175 |
+
is_null($data) ? array() : $data
|
| 176 |
+
));
|
| 177 |
+
} else {
|
| 178 |
+
$request.=$this->_buildQueryString(is_null($data) ? array() : $data);
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
curl_setopt($curl, CURLOPT_URL, $this->_hostname.'/'.$request);
|
| 182 |
+
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
| 183 |
+
|
| 184 |
+
$output = json_decode(curl_exec($curl), true);
|
| 185 |
+
|
| 186 |
+
curl_close($curl);
|
| 187 |
+
|
| 188 |
+
return $output;
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
/**
|
| 192 |
+
* Make a POST request
|
| 193 |
+
*
|
| 194 |
+
* @param string $request
|
| 195 |
+
* @param assoc $data
|
| 196 |
+
* @param assoc $query
|
| 197 |
+
*/
|
| 198 |
+
public function post($request, $data = null, $query = null)
|
| 199 |
+
{
|
| 200 |
+
if (is_array($query)) {
|
| 201 |
+
$request.= $this->_buildQueryString(array_merge( $query, array('access_token' => $this->_accessToken) ));
|
| 202 |
+
} else {
|
| 203 |
+
$request.='?access_token='.$this->_accessToken;
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
$curl = $this->_prepareCurl();
|
| 207 |
+
|
| 208 |
+
curl_setopt($curl, CURLOPT_URL, $this->_hostname.'/'.$request);
|
| 209 |
+
curl_setopt($curl, CURLOPT_POST, true);
|
| 210 |
+
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
|
| 211 |
+
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
|
| 212 |
+
'content-type: application/json',
|
| 213 |
+
'accept: application/json'
|
| 214 |
+
));
|
| 215 |
+
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
|
| 216 |
+
|
| 217 |
+
if ($this->_appendMulti($curl)) {
|
| 218 |
+
return true;
|
| 219 |
+
}
|
| 220 |
+
|
| 221 |
+
curl_exec($curl);
|
| 222 |
+
|
| 223 |
+
curl_close($curl);
|
| 224 |
+
|
| 225 |
+
return true;
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
/**
|
| 229 |
+
* Make a PUT request
|
| 230 |
+
*
|
| 231 |
+
* @param string $request
|
| 232 |
+
* @param assoc $data
|
| 233 |
+
* @param assoc $query
|
| 234 |
+
*/
|
| 235 |
+
public function put($request, $data = null, $query = null)
|
| 236 |
+
{
|
| 237 |
+
if (is_array($query)) {
|
| 238 |
+
$request.= $this->_buildQueryString(array_merge( $query, array('access_token' => $this->_accessToken) ));
|
| 239 |
+
} else {
|
| 240 |
+
$request.='?access_token='.$this->_accessToken;
|
| 241 |
+
}
|
| 242 |
+
|
| 243 |
+
$curl = $this->_prepareCurl();
|
| 244 |
+
|
| 245 |
+
curl_setopt($curl, CURLOPT_URL, $this->_hostname.'/'.$request);
|
| 246 |
+
curl_setopt($curl, CURLOPT_POST, true);
|
| 247 |
+
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
|
| 248 |
+
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
|
| 249 |
+
'content-type: application/json',
|
| 250 |
+
'accept: application/json'
|
| 251 |
+
));
|
| 252 |
+
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
|
| 253 |
+
// curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
| 254 |
+
|
| 255 |
+
if ($this->_appendMulti($curl)) {
|
| 256 |
+
return true;
|
| 257 |
+
}
|
| 258 |
+
|
| 259 |
+
curl_exec($curl);
|
| 260 |
+
|
| 261 |
+
curl_close($curl);
|
| 262 |
+
|
| 263 |
+
return true;
|
| 264 |
+
}
|
| 265 |
+
|
| 266 |
+
/**
|
| 267 |
+
* Make a DELETE request
|
| 268 |
+
*
|
| 269 |
+
* @param string $request
|
| 270 |
+
* @param assoc $data
|
| 271 |
+
*/
|
| 272 |
+
public function delete($request, $data = null)
|
| 273 |
+
{
|
| 274 |
+
$curl = $this->_prepareCurl();
|
| 275 |
+
|
| 276 |
+
$request.='?access_token='.$this->_accessToken;
|
| 277 |
+
|
| 278 |
+
curl_setopt($curl, CURLOPT_URL, $this->_hostname.'/'.$request);
|
| 279 |
+
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");
|
| 280 |
+
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
|
| 281 |
+
'content-type: application/json',
|
| 282 |
+
'accept: application/json'
|
| 283 |
+
));
|
| 284 |
+
|
| 285 |
+
if ($this->_appendMulti($curl)) {
|
| 286 |
+
return true;
|
| 287 |
+
}
|
| 288 |
+
|
| 289 |
+
curl_exec($curl);
|
| 290 |
+
|
| 291 |
+
curl_close($curl);
|
| 292 |
+
|
| 293 |
+
return true;
|
| 294 |
+
}
|
| 295 |
+
|
| 296 |
+
/**
|
| 297 |
+
* This method will start preparing calls to execute them later on with
|
| 298 |
+
* 'multi' interface.
|
| 299 |
+
*/
|
| 300 |
+
public function prepare()
|
| 301 |
+
{
|
| 302 |
+
$this->_multi = curl_multi_init();
|
| 303 |
+
|
| 304 |
+
return $this;
|
| 305 |
+
}
|
| 306 |
+
|
| 307 |
+
/**
|
| 308 |
+
* Commit all prepared calls
|
| 309 |
+
*/
|
| 310 |
+
public function commit()
|
| 311 |
+
{
|
| 312 |
+
$active = true;
|
| 313 |
+
|
| 314 |
+
if (is_null($this->_multi)) {
|
| 315 |
+
return $this;
|
| 316 |
+
}
|
| 317 |
+
|
| 318 |
+
do {
|
| 319 |
+
while (CURLM_CALL_MULTI_PERFORM === curl_multi_exec($this->_multi, $running));
|
| 320 |
+
if (!$running) {
|
| 321 |
+
break;
|
| 322 |
+
}
|
| 323 |
+
|
| 324 |
+
while (($res = curl_multi_select($this->_multi)) === 0){};
|
| 325 |
+
|
| 326 |
+
if ($res === false) {
|
| 327 |
+
break;
|
| 328 |
+
}
|
| 329 |
+
} while(true);
|
| 330 |
+
|
| 331 |
+
foreach ($this->_children as $child) {
|
| 332 |
+
curl_multi_remove_handle($this->_multi, $child);
|
| 333 |
+
}
|
| 334 |
+
|
| 335 |
+
curl_multi_close($this->_multi);
|
| 336 |
+
|
| 337 |
+
$this->_multi = null;
|
| 338 |
+
|
| 339 |
+
return $this;
|
| 340 |
+
}
|
| 341 |
+
|
| 342 |
+
/**
|
| 343 |
+
* Append another curl request to multi interface
|
| 344 |
+
*/
|
| 345 |
+
protected function _appendMulti($curl)
|
| 346 |
+
{
|
| 347 |
+
if (!is_resource($this->_multi)) {
|
| 348 |
+
return false;
|
| 349 |
+
}
|
| 350 |
+
|
| 351 |
+
$code = curl_multi_add_handle($this->_multi, $curl);
|
| 352 |
+
|
| 353 |
+
if ($code == 0) {
|
| 354 |
+
$this->_children[] = $curl;
|
| 355 |
+
|
| 356 |
+
return true;
|
| 357 |
+
}
|
| 358 |
+
|
| 359 |
+
return false;
|
| 360 |
+
}
|
| 361 |
+
}
|
app/code/community/Copernica/MarketingSoftware/Model/Abandoned/Cart.php
CHANGED
|
@@ -1,65 +1,65 @@
|
|
| 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 |
-
* This model will be used to track all abandoned carts that we sent to copernica.
|
| 29 |
-
*/
|
| 30 |
-
class Copernica_MarketingSoftware_Model_Abandoned_Cart extends Mage_Core_Model_Abstract
|
| 31 |
-
{
|
| 32 |
-
/**
|
| 33 |
-
* Construct abandoned cart model
|
| 34 |
-
*/
|
| 35 |
-
protected function _construct()
|
| 36 |
-
{
|
| 37 |
-
$this->_init('marketingsoftware/abandoned_cart');
|
| 38 |
-
}
|
| 39 |
-
|
| 40 |
-
/**
|
| 41 |
-
* Set quote Id
|
| 42 |
-
*
|
| 43 |
-
* @param int $quoteID
|
| 44 |
-
*/
|
| 45 |
-
public function setQuoteId($quoteID)
|
| 46 |
-
{
|
| 47 |
-
parent::setData('quote_id', $quoteID);
|
| 48 |
-
|
| 49 |
-
$timestamp = new DateTime();
|
| 50 |
-
|
| 51 |
-
parent::setData('timestamp', $timestamp->format("Y-m-d H:i:s"));
|
| 52 |
-
|
| 53 |
-
return $this;
|
| 54 |
-
}
|
| 55 |
-
|
| 56 |
-
/**
|
| 57 |
-
* Get quote Id
|
| 58 |
-
*
|
| 59 |
-
* @return int
|
| 60 |
-
*/
|
| 61 |
-
public function getQuoteId()
|
| 62 |
-
{
|
| 63 |
-
return parent::getData('quote_id');
|
| 64 |
-
}
|
| 65 |
}
|
| 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 |
+
* This model will be used to track all abandoned carts that we sent to copernica.
|
| 29 |
+
*/
|
| 30 |
+
class Copernica_MarketingSoftware_Model_Abandoned_Cart extends Mage_Core_Model_Abstract
|
| 31 |
+
{
|
| 32 |
+
/**
|
| 33 |
+
* Construct abandoned cart model
|
| 34 |
+
*/
|
| 35 |
+
protected function _construct()
|
| 36 |
+
{
|
| 37 |
+
$this->_init('marketingsoftware/abandoned_cart');
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
/**
|
| 41 |
+
* Set quote Id
|
| 42 |
+
*
|
| 43 |
+
* @param int $quoteID
|
| 44 |
+
*/
|
| 45 |
+
public function setQuoteId($quoteID)
|
| 46 |
+
{
|
| 47 |
+
parent::setData('quote_id', $quoteID);
|
| 48 |
+
|
| 49 |
+
$timestamp = new DateTime();
|
| 50 |
+
|
| 51 |
+
parent::setData('timestamp', $timestamp->format("Y-m-d H:i:s"));
|
| 52 |
+
|
| 53 |
+
return $this;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
/**
|
| 57 |
+
* Get quote Id
|
| 58 |
+
*
|
| 59 |
+
* @return int
|
| 60 |
+
*/
|
| 61 |
+
public function getQuoteId()
|
| 62 |
+
{
|
| 63 |
+
return parent::getData('quote_id');
|
| 64 |
+
}
|
| 65 |
}
|
app/code/community/Copernica/MarketingSoftware/Model/Abandoned/Carts/Processor.php
CHANGED
|
@@ -1,129 +1,129 @@
|
|
| 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 |
-
* Since magento does not have a valid way to detect proper abandoned carts, we
|
| 29 |
-
* have to do it by ourselfs. This class will take care of such detection and
|
| 30 |
-
* will spawn proper events on queue to sync all relevant carts.
|
| 31 |
-
*/
|
| 32 |
-
class Copernica_MarketingSoftware_Model_Abandoned_Carts_Processor
|
| 33 |
-
{
|
| 34 |
-
/**
|
| 35 |
-
* Check if we did already marked
|
| 36 |
-
*
|
| 37 |
-
* @param array $quoteCollection
|
| 38 |
-
* @return boolean
|
| 39 |
-
*/
|
| 40 |
-
protected function _filterNotMarked($quoteCollection)
|
| 41 |
-
{
|
| 42 |
-
$quotesIds = array();
|
| 43 |
-
|
| 44 |
-
foreach ($quoteCollection as $quote) {
|
| 45 |
-
$quotesIds[] = $quote->getId();
|
| 46 |
-
}
|
| 47 |
-
|
| 48 |
-
$markedQuotesIds = Mage::getModel('marketingsoftware/abandoned_cart')->getCollection()->addFieldToFilter('quote_id', array('in' => $quotesIds));
|
| 49 |
-
|
| 50 |
-
$markedArray = array();
|
| 51 |
-
|
| 52 |
-
foreach ($markedQuotesIds as $abandonedCart) {
|
| 53 |
-
$markedArray[] = $abandonedCart->getQuoteId();
|
| 54 |
-
}
|
| 55 |
-
|
| 56 |
-
$notMarkedQuotes = array();
|
| 57 |
-
|
| 58 |
-
foreach ($quoteCollection as $quote) {
|
| 59 |
-
if (in_array($quote->getId(), $markedArray)) {
|
| 60 |
-
continue;
|
| 61 |
-
}
|
| 62 |
-
|
| 63 |
-
$notMarkedQuotes[] = $quote;
|
| 64 |
-
}
|
| 65 |
-
|
| 66 |
-
return $notMarkedQuotes;
|
| 67 |
-
}
|
| 68 |
-
|
| 69 |
-
/**
|
| 70 |
-
* This function will determine abandoned carts that we should
|
| 71 |
-
*/
|
| 72 |
-
public function detectAbandonedCarts()
|
| 73 |
-
{
|
| 74 |
-
$collection = Mage::getResourceModel('reports/quote_collection');
|
| 75 |
-
|
| 76 |
-
$config = Mage::helper('marketingsoftware/config');
|
| 77 |
-
|
| 78 |
-
$storeIds = $config->getEnabledStores();
|
| 79 |
-
|
| 80 |
-
if (!is_array($storeIds)) {
|
| 81 |
-
$storeIds = array();
|
| 82 |
-
}
|
| 83 |
-
|
| 84 |
-
$timeoutLimit = new DateTime();
|
| 85 |
-
$timeoutInterval = new DateInterval("PT".(int)($config->getAbandonedTimeout())."M");
|
| 86 |
-
$timeoutInterval->invert = 1;
|
| 87 |
-
$timeoutLimit->add($timeoutInterval);
|
| 88 |
-
|
| 89 |
-
$createdLimit = new DateTime();
|
| 90 |
-
$createdInterval = new DateInterval("PT".(int)($config->getAbandonedPeriod())."M");
|
| 91 |
-
$createdInterval->invert = 1;
|
| 92 |
-
$createdLimit->add($createdInterval);
|
| 93 |
-
|
| 94 |
-
$collection->prepareForAbandonedReport($storeIds);
|
| 95 |
-
$collection->addFieldToFilter('main_table.updated_at', array('lt' => $timeoutLimit->format("Y-m-d H:i:s")));
|
| 96 |
-
$collection->addFieldToFilter('main_table.created_at', array('gt' => $createdLimit->format("Y-m-d H:i:s")));
|
| 97 |
-
$collection->setPageSize(500);
|
| 98 |
-
|
| 99 |
-
$pages = $collection->getLastPageNumber();
|
| 100 |
-
|
| 101 |
-
$currentPage = 1;
|
| 102 |
-
|
| 103 |
-
do {
|
| 104 |
-
$collection->setCurPage($currentPage);
|
| 105 |
-
$collection->load();
|
| 106 |
-
|
| 107 |
-
$filteredCollection = $this->_filterNotMarked($collection);
|
| 108 |
-
|
| 109 |
-
foreach ($filteredCollection as $quote) {
|
| 110 |
-
$abandonedCart = Mage::getModel('marketingsoftware/abandoned_cart')
|
| 111 |
-
->setQuoteId($quote->getId())
|
| 112 |
-
->save();
|
| 113 |
-
|
| 114 |
-
$queue = Mage::getModel('marketingsoftware/queue_item')
|
| 115 |
-
->setObject()
|
| 116 |
-
->setCustomer($quote->getCustomerId())
|
| 117 |
-
->setAction('modify')
|
| 118 |
-
->setName('quote')
|
| 119 |
-
->setEntityId($quote->getEntityId())
|
| 120 |
-
->save();
|
| 121 |
-
}
|
| 122 |
-
|
| 123 |
-
$currentPage++;
|
| 124 |
-
|
| 125 |
-
$collection->clear();
|
| 126 |
-
|
| 127 |
-
} while ($currentPage <= $pages);
|
| 128 |
-
}
|
| 129 |
-
}
|
| 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 |
+
* Since magento does not have a valid way to detect proper abandoned carts, we
|
| 29 |
+
* have to do it by ourselfs. This class will take care of such detection and
|
| 30 |
+
* will spawn proper events on queue to sync all relevant carts.
|
| 31 |
+
*/
|
| 32 |
+
class Copernica_MarketingSoftware_Model_Abandoned_Carts_Processor
|
| 33 |
+
{
|
| 34 |
+
/**
|
| 35 |
+
* Check if we did already marked
|
| 36 |
+
*
|
| 37 |
+
* @param array $quoteCollection
|
| 38 |
+
* @return boolean
|
| 39 |
+
*/
|
| 40 |
+
protected function _filterNotMarked($quoteCollection)
|
| 41 |
+
{
|
| 42 |
+
$quotesIds = array();
|
| 43 |
+
|
| 44 |
+
foreach ($quoteCollection as $quote) {
|
| 45 |
+
$quotesIds[] = $quote->getId();
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
$markedQuotesIds = Mage::getModel('marketingsoftware/abandoned_cart')->getCollection()->addFieldToFilter('quote_id', array('in' => $quotesIds));
|
| 49 |
+
|
| 50 |
+
$markedArray = array();
|
| 51 |
+
|
| 52 |
+
foreach ($markedQuotesIds as $abandonedCart) {
|
| 53 |
+
$markedArray[] = $abandonedCart->getQuoteId();
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
$notMarkedQuotes = array();
|
| 57 |
+
|
| 58 |
+
foreach ($quoteCollection as $quote) {
|
| 59 |
+
if (in_array($quote->getId(), $markedArray)) {
|
| 60 |
+
continue;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
$notMarkedQuotes[] = $quote;
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
return $notMarkedQuotes;
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
/**
|
| 70 |
+
* This function will determine abandoned carts that we should
|
| 71 |
+
*/
|
| 72 |
+
public function detectAbandonedCarts()
|
| 73 |
+
{
|
| 74 |
+
$collection = Mage::getResourceModel('reports/quote_collection');
|
| 75 |
+
|
| 76 |
+
$config = Mage::helper('marketingsoftware/config');
|
| 77 |
+
|
| 78 |
+
$storeIds = $config->getEnabledStores();
|
| 79 |
+
|
| 80 |
+
if (!is_array($storeIds)) {
|
| 81 |
+
$storeIds = array();
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
$timeoutLimit = new DateTime();
|
| 85 |
+
$timeoutInterval = new DateInterval("PT".(int)($config->getAbandonedTimeout())."M");
|
| 86 |
+
$timeoutInterval->invert = 1;
|
| 87 |
+
$timeoutLimit->add($timeoutInterval);
|
| 88 |
+
|
| 89 |
+
$createdLimit = new DateTime();
|
| 90 |
+
$createdInterval = new DateInterval("PT".(int)($config->getAbandonedPeriod())."M");
|
| 91 |
+
$createdInterval->invert = 1;
|
| 92 |
+
$createdLimit->add($createdInterval);
|
| 93 |
+
|
| 94 |
+
$collection->prepareForAbandonedReport($storeIds);
|
| 95 |
+
$collection->addFieldToFilter('main_table.updated_at', array('lt' => $timeoutLimit->format("Y-m-d H:i:s")));
|
| 96 |
+
$collection->addFieldToFilter('main_table.created_at', array('gt' => $createdLimit->format("Y-m-d H:i:s")));
|
| 97 |
+
$collection->setPageSize(500);
|
| 98 |
+
|
| 99 |
+
$pages = $collection->getLastPageNumber();
|
| 100 |
+
|
| 101 |
+
$currentPage = 1;
|
| 102 |
+
|
| 103 |
+
do {
|
| 104 |
+
$collection->setCurPage($currentPage);
|
| 105 |
+
$collection->load();
|
| 106 |
+
|
| 107 |
+
$filteredCollection = $this->_filterNotMarked($collection);
|
| 108 |
+
|
| 109 |
+
foreach ($filteredCollection as $quote) {
|
| 110 |
+
$abandonedCart = Mage::getModel('marketingsoftware/abandoned_cart')
|
| 111 |
+
->setQuoteId($quote->getId())
|
| 112 |
+
->save();
|
| 113 |
+
|
| 114 |
+
$queue = Mage::getModel('marketingsoftware/queue_item')
|
| 115 |
+
->setObject()
|
| 116 |
+
->setCustomer($quote->getCustomerId())
|
| 117 |
+
->setAction('modify')
|
| 118 |
+
->setName('quote')
|
| 119 |
+
->setEntityId($quote->getEntityId())
|
| 120 |
+
->save();
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
$currentPage++;
|
| 124 |
+
|
| 125 |
+
$collection->clear();
|
| 126 |
+
|
| 127 |
+
} while ($currentPage <= $pages);
|
| 128 |
+
}
|
| 129 |
+
}
|
app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Address.php
CHANGED
|
@@ -1,320 +1,320 @@
|
|
| 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 Address
|
| 29 |
-
*/
|
| 30 |
-
class Copernica_MarketingSoftware_Model_Abstraction_Address implements Serializable
|
| 31 |
-
{
|
| 32 |
-
/**
|
| 33 |
-
* The original object
|
| 34 |
-
*
|
| 35 |
-
* @todo Not used???
|
| 36 |
-
* @var Mage_Sales_Model_Order_Address|Mage_Sales_Model_Quote_Address|Mage_Customer_Model_Address
|
| 37 |
-
*/
|
| 38 |
-
protected $_original;
|
| 39 |
-
|
| 40 |
-
/**
|
| 41 |
-
* Predefine the internal fields
|
| 42 |
-
*/
|
| 43 |
-
protected $_id;
|
| 44 |
-
protected $_type;
|
| 45 |
-
protected $_name;
|
| 46 |
-
protected $_email;
|
| 47 |
-
protected $_street;
|
| 48 |
-
protected $_city;
|
| 49 |
-
protected $_zipcode;
|
| 50 |
-
protected $_state;
|
| 51 |
-
protected $_countryId;
|
| 52 |
-
protected $_telephone;
|
| 53 |
-
protected $_fax;
|
| 54 |
-
protected $_company;
|
| 55 |
-
protected $_customerId = null;
|
| 56 |
-
|
| 57 |
-
/**
|
| 58 |
-
* Sets the original model
|
| 59 |
-
*
|
| 60 |
-
* @param Mage_Sales_Model_Order_Address|Mage_Sales_Model_Quote_Address|Mage_Customer_Model_Address $original
|
| 61 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Address
|
| 62 |
-
*/
|
| 63 |
-
public function setOriginal($original)
|
| 64 |
-
{
|
| 65 |
-
$this->_name = Mage::getModel('marketingsoftware/abstraction_name')->setOriginal($original);
|
| 66 |
-
$this->_street = $original->getStreetFull();
|
| 67 |
-
$this->_city = $original->getCity();
|
| 68 |
-
$this->_zipcode = $original->getPostcode();
|
| 69 |
-
$this->_state = $original->getRegion();
|
| 70 |
-
$this->_company = $original->getCompany();
|
| 71 |
-
$this->_countryId = $original->getCountryId();
|
| 72 |
-
$this->_telephone = $original->getTelephone();
|
| 73 |
-
$this->_fax = $original->getFax();
|
| 74 |
-
|
| 75 |
-
if ($type = $original->getAddressType()) {
|
| 76 |
-
$this->_type = array($type);
|
| 77 |
-
} else {
|
| 78 |
-
$types = array();
|
| 79 |
-
|
| 80 |
-
if ($customer = $original->getCustomer()) {
|
| 81 |
-
$id = $original->getId();
|
| 82 |
-
|
| 83 |
-
if ($customer->getData('default_billing') == $id) {
|
| 84 |
-
$types[] = 'billing';
|
| 85 |
-
}
|
| 86 |
-
|
| 87 |
-
if ($customer->getData('default_shipping') == $id) {
|
| 88 |
-
$types[] = 'shipping';
|
| 89 |
-
}
|
| 90 |
-
}
|
| 91 |
-
$this->_type = $types;
|
| 92 |
-
}
|
| 93 |
-
|
| 94 |
-
if ($customerId = $original->getCustomerId()) {
|
| 95 |
-
$this->_customerId = $original->getCustomerId();
|
| 96 |
-
} elseif ($customer = $original->getCustomer()) {
|
| 97 |
-
$this->_customerId = $customer->getId();
|
| 98 |
-
}
|
| 99 |
-
|
| 100 |
-
$id = $original->getId();
|
| 101 |
-
|
| 102 |
-
switch(get_class($original)) {
|
| 103 |
-
case "Mage_Sales_Model_Order_Address":
|
| 104 |
-
if ($cid = $original->getCustomerAddressId()) {
|
| 105 |
-
$this->_id = 'ca_'.$cid;
|
| 106 |
-
} else {
|
| 107 |
-
$this->_id = 'oa_'.$id;
|
| 108 |
-
}
|
| 109 |
-
break;
|
| 110 |
-
case "Mage_Sales_Model_Quote_Address":
|
| 111 |
-
if ($cid = $original->getCustomerAddressId()) {
|
| 112 |
-
$this->_id = 'ca_'.$cid;
|
| 113 |
-
} else {
|
| 114 |
-
$this->_id = 'qa_'.$id;
|
| 115 |
-
}
|
| 116 |
-
break;
|
| 117 |
-
case "Mage_Customer_Model_Address":
|
| 118 |
-
$this->_id = 'ca_'.$id;
|
| 119 |
-
break;
|
| 120 |
-
default:
|
| 121 |
-
$this->_id = $id;
|
| 122 |
-
}
|
| 123 |
-
|
| 124 |
-
if ($email = $original->getEmail()) {
|
| 125 |
-
$this->_email = $email;
|
| 126 |
-
} elseif (is_object($order = $original->getOrder()) && $customerEmail = $order->getCustomerEmail()) {
|
| 127 |
-
$this->_email = $customerEmail;
|
| 128 |
-
} elseif (is_object($quote = $original->getQuote()) && $customerEmail = $quote->getCustomerEmail()) {
|
| 129 |
-
$this->_email = $customerEmail;
|
| 130 |
-
}
|
| 131 |
-
|
| 132 |
-
return $this;
|
| 133 |
-
}
|
| 134 |
-
|
| 135 |
-
/**
|
| 136 |
-
* Return the type of this address
|
| 137 |
-
*
|
| 138 |
-
* @return array
|
| 139 |
-
*/
|
| 140 |
-
public function type()
|
| 141 |
-
{
|
| 142 |
-
return $this->_type;
|
| 143 |
-
}
|
| 144 |
-
|
| 145 |
-
/**
|
| 146 |
-
* The customer may return null
|
| 147 |
-
*
|
| 148 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Customer|null
|
| 149 |
-
*/
|
| 150 |
-
public function customer()
|
| 151 |
-
{
|
| 152 |
-
if ($this->_customerId) {
|
| 153 |
-
return Mage::getModel('marketingsoftware/abstraction_customer')->loadCustomer($this->_customerId);
|
| 154 |
-
} else {
|
| 155 |
-
return null;
|
| 156 |
-
}
|
| 157 |
-
}
|
| 158 |
-
|
| 159 |
-
/**
|
| 160 |
-
* We want to return a unique id, but to do this we need to append
|
| 161 |
-
* a prefix based on the type of address
|
| 162 |
-
*
|
| 163 |
-
* @return string
|
| 164 |
-
*/
|
| 165 |
-
public function id()
|
| 166 |
-
{
|
| 167 |
-
return $this->_id;
|
| 168 |
-
}
|
| 169 |
-
|
| 170 |
-
/**
|
| 171 |
-
* Return the name belonging to this address
|
| 172 |
-
*
|
| 173 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Name
|
| 174 |
-
*/
|
| 175 |
-
public function name()
|
| 176 |
-
{
|
| 177 |
-
return $this->_name;
|
| 178 |
-
}
|
| 179 |
-
|
| 180 |
-
/**
|
| 181 |
-
* Return the e-mail address of this address
|
| 182 |
-
*
|
| 183 |
-
* @return string
|
| 184 |
-
*/
|
| 185 |
-
public function email()
|
| 186 |
-
{
|
| 187 |
-
return $this->_email;
|
| 188 |
-
}
|
| 189 |
-
|
| 190 |
-
/**
|
| 191 |
-
* Return the street of this addresses
|
| 192 |
-
*
|
| 193 |
-
* @return string
|
| 194 |
-
*/
|
| 195 |
-
public function street()
|
| 196 |
-
{
|
| 197 |
-
return $this->_street;
|
| 198 |
-
}
|
| 199 |
-
|
| 200 |
-
/**
|
| 201 |
-
* Get the city of this addresses
|
| 202 |
-
*
|
| 203 |
-
* @return string
|
| 204 |
-
*/
|
| 205 |
-
public function city()
|
| 206 |
-
{
|
| 207 |
-
return $this->_city;
|
| 208 |
-
}
|
| 209 |
-
|
| 210 |
-
/**
|
| 211 |
-
* Get the zipcode of this addresses
|
| 212 |
-
*
|
| 213 |
-
* @return string
|
| 214 |
-
*/
|
| 215 |
-
public function zipcode()
|
| 216 |
-
{
|
| 217 |
-
return $this->_zipcode;
|
| 218 |
-
}
|
| 219 |
-
|
| 220 |
-
/**
|
| 221 |
-
* Get the state of this addresses
|
| 222 |
-
*
|
| 223 |
-
* @return string
|
| 224 |
-
*/
|
| 225 |
-
public function state()
|
| 226 |
-
{
|
| 227 |
-
return $this->_state;
|
| 228 |
-
}
|
| 229 |
-
|
| 230 |
-
/**
|
| 231 |
-
* Get the country id of this addresses
|
| 232 |
-
*
|
| 233 |
-
* @return string
|
| 234 |
-
*/
|
| 235 |
-
public function countryId()
|
| 236 |
-
{
|
| 237 |
-
return $this->_countryId;
|
| 238 |
-
}
|
| 239 |
-
|
| 240 |
-
/**
|
| 241 |
-
* Get the telephone number of this addresses
|
| 242 |
-
*
|
| 243 |
-
* @return string
|
| 244 |
-
*/
|
| 245 |
-
public function telephone()
|
| 246 |
-
{
|
| 247 |
-
return $this->_telephone;
|
| 248 |
-
}
|
| 249 |
-
|
| 250 |
-
/**
|
| 251 |
-
* Get the fax number of this addresses
|
| 252 |
-
*
|
| 253 |
-
* @return string
|
| 254 |
-
*/
|
| 255 |
-
public function fax()
|
| 256 |
-
{
|
| 257 |
-
return $this->_fax;
|
| 258 |
-
}
|
| 259 |
-
|
| 260 |
-
/**
|
| 261 |
-
* Get the company of this address
|
| 262 |
-
*
|
| 263 |
-
* @return string
|
| 264 |
-
*/
|
| 265 |
-
public function company()
|
| 266 |
-
{
|
| 267 |
-
return $this->_company;
|
| 268 |
-
}
|
| 269 |
-
|
| 270 |
-
/**
|
| 271 |
-
* Serialize the object
|
| 272 |
-
*
|
| 273 |
-
* @return string
|
| 274 |
-
*/
|
| 275 |
-
public function serialize()
|
| 276 |
-
{
|
| 277 |
-
return serialize(array(
|
| 278 |
-
$this->id(),
|
| 279 |
-
$this->type(),
|
| 280 |
-
$this->name(),
|
| 281 |
-
$this->email(),
|
| 282 |
-
$this->street(),
|
| 283 |
-
$this->city(),
|
| 284 |
-
$this->zipcode(),
|
| 285 |
-
$this->state(),
|
| 286 |
-
$this->countryId(),
|
| 287 |
-
$this->telephone(),
|
| 288 |
-
$this->fax(),
|
| 289 |
-
$this->company(),
|
| 290 |
-
is_object($customer = $this->customer()) ? $customer->id() : null,
|
| 291 |
-
));
|
| 292 |
-
}
|
| 293 |
-
|
| 294 |
-
/**
|
| 295 |
-
* Unserialize the object
|
| 296 |
-
*
|
| 297 |
-
* @param string $string
|
| 298 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Address
|
| 299 |
-
*/
|
| 300 |
-
public function unserialize($string)
|
| 301 |
-
{
|
| 302 |
-
list(
|
| 303 |
-
$this->_id,
|
| 304 |
-
$this->_type,
|
| 305 |
-
$this->_name,
|
| 306 |
-
$this->_email,
|
| 307 |
-
$this->_street,
|
| 308 |
-
$this->_city,
|
| 309 |
-
$this->_zipcode,
|
| 310 |
-
$this->_state,
|
| 311 |
-
$this->_countryId,
|
| 312 |
-
$this->_telephone,
|
| 313 |
-
$this->_fax,
|
| 314 |
-
$this->_company,
|
| 315 |
-
$this->_customerId
|
| 316 |
-
) = unserialize($string);
|
| 317 |
-
|
| 318 |
-
return $this;
|
| 319 |
-
}
|
| 320 |
}
|
| 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 Address
|
| 29 |
+
*/
|
| 30 |
+
class Copernica_MarketingSoftware_Model_Abstraction_Address implements Serializable
|
| 31 |
+
{
|
| 32 |
+
/**
|
| 33 |
+
* The original object
|
| 34 |
+
*
|
| 35 |
+
* @todo Not used???
|
| 36 |
+
* @var Mage_Sales_Model_Order_Address|Mage_Sales_Model_Quote_Address|Mage_Customer_Model_Address
|
| 37 |
+
*/
|
| 38 |
+
protected $_original;
|
| 39 |
+
|
| 40 |
+
/**
|
| 41 |
+
* Predefine the internal fields
|
| 42 |
+
*/
|
| 43 |
+
protected $_id;
|
| 44 |
+
protected $_type;
|
| 45 |
+
protected $_name;
|
| 46 |
+
protected $_email;
|
| 47 |
+
protected $_street;
|
| 48 |
+
protected $_city;
|
| 49 |
+
protected $_zipcode;
|
| 50 |
+
protected $_state;
|
| 51 |
+
protected $_countryId;
|
| 52 |
+
protected $_telephone;
|
| 53 |
+
protected $_fax;
|
| 54 |
+
protected $_company;
|
| 55 |
+
protected $_customerId = null;
|
| 56 |
+
|
| 57 |
+
/**
|
| 58 |
+
* Sets the original model
|
| 59 |
+
*
|
| 60 |
+
* @param Mage_Sales_Model_Order_Address|Mage_Sales_Model_Quote_Address|Mage_Customer_Model_Address $original
|
| 61 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Address
|
| 62 |
+
*/
|
| 63 |
+
public function setOriginal($original)
|
| 64 |
+
{
|
| 65 |
+
$this->_name = Mage::getModel('marketingsoftware/abstraction_name')->setOriginal($original);
|
| 66 |
+
$this->_street = $original->getStreetFull();
|
| 67 |
+
$this->_city = $original->getCity();
|
| 68 |
+
$this->_zipcode = $original->getPostcode();
|
| 69 |
+
$this->_state = $original->getRegion();
|
| 70 |
+
$this->_company = $original->getCompany();
|
| 71 |
+
$this->_countryId = $original->getCountryId();
|
| 72 |
+
$this->_telephone = $original->getTelephone();
|
| 73 |
+
$this->_fax = $original->getFax();
|
| 74 |
+
|
| 75 |
+
if ($type = $original->getAddressType()) {
|
| 76 |
+
$this->_type = array($type);
|
| 77 |
+
} else {
|
| 78 |
+
$types = array();
|
| 79 |
+
|
| 80 |
+
if ($customer = $original->getCustomer()) {
|
| 81 |
+
$id = $original->getId();
|
| 82 |
+
|
| 83 |
+
if ($customer->getData('default_billing') == $id) {
|
| 84 |
+
$types[] = 'billing';
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
if ($customer->getData('default_shipping') == $id) {
|
| 88 |
+
$types[] = 'shipping';
|
| 89 |
+
}
|
| 90 |
+
}
|
| 91 |
+
$this->_type = $types;
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
if ($customerId = $original->getCustomerId()) {
|
| 95 |
+
$this->_customerId = $original->getCustomerId();
|
| 96 |
+
} elseif ($customer = $original->getCustomer()) {
|
| 97 |
+
$this->_customerId = $customer->getId();
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
$id = $original->getId();
|
| 101 |
+
|
| 102 |
+
switch(get_class($original)) {
|
| 103 |
+
case "Mage_Sales_Model_Order_Address":
|
| 104 |
+
if ($cid = $original->getCustomerAddressId()) {
|
| 105 |
+
$this->_id = 'ca_'.$cid;
|
| 106 |
+
} else {
|
| 107 |
+
$this->_id = 'oa_'.$id;
|
| 108 |
+
}
|
| 109 |
+
break;
|
| 110 |
+
case "Mage_Sales_Model_Quote_Address":
|
| 111 |
+
if ($cid = $original->getCustomerAddressId()) {
|
| 112 |
+
$this->_id = 'ca_'.$cid;
|
| 113 |
+
} else {
|
| 114 |
+
$this->_id = 'qa_'.$id;
|
| 115 |
+
}
|
| 116 |
+
break;
|
| 117 |
+
case "Mage_Customer_Model_Address":
|
| 118 |
+
$this->_id = 'ca_'.$id;
|
| 119 |
+
break;
|
| 120 |
+
default:
|
| 121 |
+
$this->_id = $id;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
if ($email = $original->getEmail()) {
|
| 125 |
+
$this->_email = $email;
|
| 126 |
+
} elseif (is_object($order = $original->getOrder()) && $customerEmail = $order->getCustomerEmail()) {
|
| 127 |
+
$this->_email = $customerEmail;
|
| 128 |
+
} elseif (is_object($quote = $original->getQuote()) && $customerEmail = $quote->getCustomerEmail()) {
|
| 129 |
+
$this->_email = $customerEmail;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
return $this;
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
/**
|
| 136 |
+
* Return the type of this address
|
| 137 |
+
*
|
| 138 |
+
* @return array
|
| 139 |
+
*/
|
| 140 |
+
public function type()
|
| 141 |
+
{
|
| 142 |
+
return $this->_type;
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
/**
|
| 146 |
+
* The customer may return null
|
| 147 |
+
*
|
| 148 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Customer|null
|
| 149 |
+
*/
|
| 150 |
+
public function customer()
|
| 151 |
+
{
|
| 152 |
+
if ($this->_customerId) {
|
| 153 |
+
return Mage::getModel('marketingsoftware/abstraction_customer')->loadCustomer($this->_customerId);
|
| 154 |
+
} else {
|
| 155 |
+
return null;
|
| 156 |
+
}
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
/**
|
| 160 |
+
* We want to return a unique id, but to do this we need to append
|
| 161 |
+
* a prefix based on the type of address
|
| 162 |
+
*
|
| 163 |
+
* @return string
|
| 164 |
+
*/
|
| 165 |
+
public function id()
|
| 166 |
+
{
|
| 167 |
+
return $this->_id;
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
/**
|
| 171 |
+
* Return the name belonging to this address
|
| 172 |
+
*
|
| 173 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Name
|
| 174 |
+
*/
|
| 175 |
+
public function name()
|
| 176 |
+
{
|
| 177 |
+
return $this->_name;
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
/**
|
| 181 |
+
* Return the e-mail address of this address
|
| 182 |
+
*
|
| 183 |
+
* @return string
|
| 184 |
+
*/
|
| 185 |
+
public function email()
|
| 186 |
+
{
|
| 187 |
+
return $this->_email;
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
/**
|
| 191 |
+
* Return the street of this addresses
|
| 192 |
+
*
|
| 193 |
+
* @return string
|
| 194 |
+
*/
|
| 195 |
+
public function street()
|
| 196 |
+
{
|
| 197 |
+
return $this->_street;
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
/**
|
| 201 |
+
* Get the city of this addresses
|
| 202 |
+
*
|
| 203 |
+
* @return string
|
| 204 |
+
*/
|
| 205 |
+
public function city()
|
| 206 |
+
{
|
| 207 |
+
return $this->_city;
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
/**
|
| 211 |
+
* Get the zipcode of this addresses
|
| 212 |
+
*
|
| 213 |
+
* @return string
|
| 214 |
+
*/
|
| 215 |
+
public function zipcode()
|
| 216 |
+
{
|
| 217 |
+
return $this->_zipcode;
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
/**
|
| 221 |
+
* Get the state of this addresses
|
| 222 |
+
*
|
| 223 |
+
* @return string
|
| 224 |
+
*/
|
| 225 |
+
public function state()
|
| 226 |
+
{
|
| 227 |
+
return $this->_state;
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
/**
|
| 231 |
+
* Get the country id of this addresses
|
| 232 |
+
*
|
| 233 |
+
* @return string
|
| 234 |
+
*/
|
| 235 |
+
public function countryId()
|
| 236 |
+
{
|
| 237 |
+
return $this->_countryId;
|
| 238 |
+
}
|
| 239 |
+
|
| 240 |
+
/**
|
| 241 |
+
* Get the telephone number of this addresses
|
| 242 |
+
*
|
| 243 |
+
* @return string
|
| 244 |
+
*/
|
| 245 |
+
public function telephone()
|
| 246 |
+
{
|
| 247 |
+
return $this->_telephone;
|
| 248 |
+
}
|
| 249 |
+
|
| 250 |
+
/**
|
| 251 |
+
* Get the fax number of this addresses
|
| 252 |
+
*
|
| 253 |
+
* @return string
|
| 254 |
+
*/
|
| 255 |
+
public function fax()
|
| 256 |
+
{
|
| 257 |
+
return $this->_fax;
|
| 258 |
+
}
|
| 259 |
+
|
| 260 |
+
/**
|
| 261 |
+
* Get the company of this address
|
| 262 |
+
*
|
| 263 |
+
* @return string
|
| 264 |
+
*/
|
| 265 |
+
public function company()
|
| 266 |
+
{
|
| 267 |
+
return $this->_company;
|
| 268 |
+
}
|
| 269 |
+
|
| 270 |
+
/**
|
| 271 |
+
* Serialize the object
|
| 272 |
+
*
|
| 273 |
+
* @return string
|
| 274 |
+
*/
|
| 275 |
+
public function serialize()
|
| 276 |
+
{
|
| 277 |
+
return serialize(array(
|
| 278 |
+
$this->id(),
|
| 279 |
+
$this->type(),
|
| 280 |
+
$this->name(),
|
| 281 |
+
$this->email(),
|
| 282 |
+
$this->street(),
|
| 283 |
+
$this->city(),
|
| 284 |
+
$this->zipcode(),
|
| 285 |
+
$this->state(),
|
| 286 |
+
$this->countryId(),
|
| 287 |
+
$this->telephone(),
|
| 288 |
+
$this->fax(),
|
| 289 |
+
$this->company(),
|
| 290 |
+
is_object($customer = $this->customer()) ? $customer->id() : null,
|
| 291 |
+
));
|
| 292 |
+
}
|
| 293 |
+
|
| 294 |
+
/**
|
| 295 |
+
* Unserialize the object
|
| 296 |
+
*
|
| 297 |
+
* @param string $string
|
| 298 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Address
|
| 299 |
+
*/
|
| 300 |
+
public function unserialize($string)
|
| 301 |
+
{
|
| 302 |
+
list(
|
| 303 |
+
$this->_id,
|
| 304 |
+
$this->_type,
|
| 305 |
+
$this->_name,
|
| 306 |
+
$this->_email,
|
| 307 |
+
$this->_street,
|
| 308 |
+
$this->_city,
|
| 309 |
+
$this->_zipcode,
|
| 310 |
+
$this->_state,
|
| 311 |
+
$this->_countryId,
|
| 312 |
+
$this->_telephone,
|
| 313 |
+
$this->_fax,
|
| 314 |
+
$this->_company,
|
| 315 |
+
$this->_customerId
|
| 316 |
+
) = unserialize($string);
|
| 317 |
+
|
| 318 |
+
return $this;
|
| 319 |
+
}
|
| 320 |
}
|
app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Attributes.php
CHANGED
|
@@ -1,136 +1,136 @@
|
|
| 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 attributes
|
| 29 |
-
*/
|
| 30 |
-
class Copernica_MarketingSoftware_Model_Abstraction_Attributes implements Serializable
|
| 31 |
-
{
|
| 32 |
-
/**
|
| 33 |
-
* Predefine the internal fields
|
| 34 |
-
*/
|
| 35 |
-
protected $_name;
|
| 36 |
-
protected $_attributes;
|
| 37 |
-
|
| 38 |
-
/**
|
| 39 |
-
* Sets the original model
|
| 40 |
-
*
|
| 41 |
-
* @param Mage_Catalog_Model_Product $original
|
| 42 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Attributes
|
| 43 |
-
*/
|
| 44 |
-
public function setOriginal(Mage_Catalog_Model_Product $original)
|
| 45 |
-
{
|
| 46 |
-
if ($attributeSet = Mage::getModel('eav/entity_attribute_set')->load($original->getAttributeSetId())) {
|
| 47 |
-
$this->_name = $attributeSet->getAttributeSetName();
|
| 48 |
-
}
|
| 49 |
-
|
| 50 |
-
$data = array();
|
| 51 |
-
|
| 52 |
-
$attributes = $original->getAttributes();
|
| 53 |
-
|
| 54 |
-
foreach ($attributes as $attribute) {
|
| 55 |
-
if (
|
| 56 |
-
$attribute->getIsUserDefined() &&
|
| 57 |
-
in_array($attribute->getFrontendInput(), array('text', 'select', 'multiline', 'textarea', 'price', 'date', 'multiselect')) &&
|
| 58 |
-
($label = $attribute->getAttributeCode()) &&
|
| 59 |
-
($value = $attribute->getFrontend()->getValue($original))
|
| 60 |
-
) {
|
| 61 |
-
$data[$label] = $value;
|
| 62 |
-
}
|
| 63 |
-
}
|
| 64 |
-
|
| 65 |
-
$this->_attributes = $data;
|
| 66 |
-
|
| 67 |
-
return $this;
|
| 68 |
-
}
|
| 69 |
-
|
| 70 |
-
/**
|
| 71 |
-
* The name of this product
|
| 72 |
-
*
|
| 73 |
-
* @return integer
|
| 74 |
-
*/
|
| 75 |
-
public function name()
|
| 76 |
-
{
|
| 77 |
-
return $this->_name;
|
| 78 |
-
}
|
| 79 |
-
|
| 80 |
-
/**
|
| 81 |
-
* Return an assoc array with attributes.
|
| 82 |
-
*
|
| 83 |
-
* @param Bool $useAttribcode
|
| 84 |
-
* @return array
|
| 85 |
-
*/
|
| 86 |
-
public function attributes($useAttribCode = false)
|
| 87 |
-
{
|
| 88 |
-
return $this->_attributes;
|
| 89 |
-
}
|
| 90 |
-
|
| 91 |
-
/**
|
| 92 |
-
* Return a string representation
|
| 93 |
-
*
|
| 94 |
-
* @return string
|
| 95 |
-
*/
|
| 96 |
-
public function __toString()
|
| 97 |
-
{
|
| 98 |
-
$options = "";
|
| 99 |
-
|
| 100 |
-
foreach ($this->attributes() as $key => $value) {
|
| 101 |
-
$options .= "$key: $value\n";
|
| 102 |
-
}
|
| 103 |
-
|
| 104 |
-
return $options;
|
| 105 |
-
}
|
| 106 |
-
|
| 107 |
-
/**
|
| 108 |
-
* Serialize the object
|
| 109 |
-
*
|
| 110 |
-
* @return string
|
| 111 |
-
*/
|
| 112 |
-
public function serialize()
|
| 113 |
-
{
|
| 114 |
-
return serialize(array(
|
| 115 |
-
$this->name(),
|
| 116 |
-
$this->attributes(),
|
| 117 |
-
));
|
| 118 |
-
}
|
| 119 |
-
|
| 120 |
-
/**
|
| 121 |
-
* Unserialize the object
|
| 122 |
-
*
|
| 123 |
-
* @param string $string
|
| 124 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Attributes
|
| 125 |
-
*/
|
| 126 |
-
public function unserialize($string)
|
| 127 |
-
{
|
| 128 |
-
list(
|
| 129 |
-
$this->_name,
|
| 130 |
-
$this->_attributes
|
| 131 |
-
) = unserialize($string);
|
| 132 |
-
|
| 133 |
-
return $this;
|
| 134 |
-
}
|
| 135 |
-
}
|
| 136 |
-
|
| 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 attributes
|
| 29 |
+
*/
|
| 30 |
+
class Copernica_MarketingSoftware_Model_Abstraction_Attributes implements Serializable
|
| 31 |
+
{
|
| 32 |
+
/**
|
| 33 |
+
* Predefine the internal fields
|
| 34 |
+
*/
|
| 35 |
+
protected $_name;
|
| 36 |
+
protected $_attributes;
|
| 37 |
+
|
| 38 |
+
/**
|
| 39 |
+
* Sets the original model
|
| 40 |
+
*
|
| 41 |
+
* @param Mage_Catalog_Model_Product $original
|
| 42 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Attributes
|
| 43 |
+
*/
|
| 44 |
+
public function setOriginal(Mage_Catalog_Model_Product $original)
|
| 45 |
+
{
|
| 46 |
+
if ($attributeSet = Mage::getModel('eav/entity_attribute_set')->load($original->getAttributeSetId())) {
|
| 47 |
+
$this->_name = $attributeSet->getAttributeSetName();
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
$data = array();
|
| 51 |
+
|
| 52 |
+
$attributes = $original->getAttributes();
|
| 53 |
+
|
| 54 |
+
foreach ($attributes as $attribute) {
|
| 55 |
+
if (
|
| 56 |
+
$attribute->getIsUserDefined() &&
|
| 57 |
+
in_array($attribute->getFrontendInput(), array('text', 'select', 'multiline', 'textarea', 'price', 'date', 'multiselect')) &&
|
| 58 |
+
($label = $attribute->getAttributeCode()) &&
|
| 59 |
+
($value = $attribute->getFrontend()->getValue($original))
|
| 60 |
+
) {
|
| 61 |
+
$data[$label] = $value;
|
| 62 |
+
}
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
$this->_attributes = $data;
|
| 66 |
+
|
| 67 |
+
return $this;
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
/**
|
| 71 |
+
* The name of this product
|
| 72 |
+
*
|
| 73 |
+
* @return integer
|
| 74 |
+
*/
|
| 75 |
+
public function name()
|
| 76 |
+
{
|
| 77 |
+
return $this->_name;
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
/**
|
| 81 |
+
* Return an assoc array with attributes.
|
| 82 |
+
*
|
| 83 |
+
* @param Bool $useAttribcode
|
| 84 |
+
* @return array
|
| 85 |
+
*/
|
| 86 |
+
public function attributes($useAttribCode = false)
|
| 87 |
+
{
|
| 88 |
+
return $this->_attributes;
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
/**
|
| 92 |
+
* Return a string representation
|
| 93 |
+
*
|
| 94 |
+
* @return string
|
| 95 |
+
*/
|
| 96 |
+
public function __toString()
|
| 97 |
+
{
|
| 98 |
+
$options = "";
|
| 99 |
+
|
| 100 |
+
foreach ($this->attributes() as $key => $value) {
|
| 101 |
+
$options .= "$key: $value\n";
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
return $options;
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
/**
|
| 108 |
+
* Serialize the object
|
| 109 |
+
*
|
| 110 |
+
* @return string
|
| 111 |
+
*/
|
| 112 |
+
public function serialize()
|
| 113 |
+
{
|
| 114 |
+
return serialize(array(
|
| 115 |
+
$this->name(),
|
| 116 |
+
$this->attributes(),
|
| 117 |
+
));
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
/**
|
| 121 |
+
* Unserialize the object
|
| 122 |
+
*
|
| 123 |
+
* @param string $string
|
| 124 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Attributes
|
| 125 |
+
*/
|
| 126 |
+
public function unserialize($string)
|
| 127 |
+
{
|
| 128 |
+
list(
|
| 129 |
+
$this->_name,
|
| 130 |
+
$this->_attributes
|
| 131 |
+
) = unserialize($string);
|
| 132 |
+
|
| 133 |
+
return $this;
|
| 134 |
+
}
|
| 135 |
+
}
|
| 136 |
+
|
app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Customer.php
CHANGED
|
@@ -1,309 +1,309 @@
|
|
| 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 |
-
* @documentation public
|
| 26 |
-
*/
|
| 27 |
-
|
| 28 |
-
/**
|
| 29 |
-
* A wrapper object around a magento Customer
|
| 30 |
-
*/
|
| 31 |
-
class Copernica_MarketingSoftware_Model_Abstraction_Customer implements Serializable
|
| 32 |
-
{
|
| 33 |
-
/**
|
| 34 |
-
* The id
|
| 35 |
-
*
|
| 36 |
-
* @var int
|
| 37 |
-
*/
|
| 38 |
-
protected $_id;
|
| 39 |
-
|
| 40 |
-
/**
|
| 41 |
-
* The original object
|
| 42 |
-
*
|
| 43 |
-
* @var Mage_Customer_Model_Customer
|
| 44 |
-
*/
|
| 45 |
-
protected $_original;
|
| 46 |
-
|
| 47 |
-
/**
|
| 48 |
-
* Sets the original model
|
| 49 |
-
*
|
| 50 |
-
* @param Mage_Customer_Model_Customer $original
|
| 51 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Customer
|
| 52 |
-
*/
|
| 53 |
-
public function setOriginal(Mage_Customer_Model_Customer $original)
|
| 54 |
-
{
|
| 55 |
-
$this->_original = $original;
|
| 56 |
-
$this->_id = $original->getId();
|
| 57 |
-
|
| 58 |
-
return $this;
|
| 59 |
-
}
|
| 60 |
-
|
| 61 |
-
/**
|
| 62 |
-
* Returns the original model
|
| 63 |
-
*
|
| 64 |
-
* @return Mage_Customer_Model_Customer
|
| 65 |
-
*/
|
| 66 |
-
protected function _original()
|
| 67 |
-
{
|
| 68 |
-
return $this->_original;
|
| 69 |
-
}
|
| 70 |
-
|
| 71 |
-
/**
|
| 72 |
-
* Loads a customer model
|
| 73 |
-
*
|
| 74 |
-
* @param int $customerId
|
| 75 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Customer
|
| 76 |
-
*/
|
| 77 |
-
public function loadCustomer($customerId)
|
| 78 |
-
{
|
| 79 |
-
$customer = Mage::getModel('customer/customer')->load($customerId);
|
| 80 |
-
|
| 81 |
-
if ($customer->getId()) {
|
| 82 |
-
$this->setOriginal($customer);
|
| 83 |
-
}
|
| 84 |
-
|
| 85 |
-
return $this;
|
| 86 |
-
}
|
| 87 |
-
|
| 88 |
-
/**
|
| 89 |
-
* Return the id of the customer
|
| 90 |
-
*
|
| 91 |
-
* @return string
|
| 92 |
-
*/
|
| 93 |
-
public function id()
|
| 94 |
-
{
|
| 95 |
-
if (!$this->_original()) {
|
| 96 |
-
return null;
|
| 97 |
-
}
|
| 98 |
-
|
| 99 |
-
return $this->_original()->getId();
|
| 100 |
-
}
|
| 101 |
-
|
| 102 |
-
/**
|
| 103 |
-
* Return the name of this customer
|
| 104 |
-
* Note that null may also be returned to indicate that the name is not known
|
| 105 |
-
*
|
| 106 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Name
|
| 107 |
-
*/
|
| 108 |
-
public function name()
|
| 109 |
-
{
|
| 110 |
-
return Mage::getModel('marketingsoftware/abstraction_name')->setOriginal($this->_original());
|
| 111 |
-
}
|
| 112 |
-
|
| 113 |
-
/**
|
| 114 |
-
* Return the e-mail address of the customer
|
| 115 |
-
*
|
| 116 |
-
* @return string
|
| 117 |
-
*/
|
| 118 |
-
public function email()
|
| 119 |
-
{
|
| 120 |
-
return $this->_original()->getEmail();
|
| 121 |
-
}
|
| 122 |
-
|
| 123 |
-
/**
|
| 124 |
-
* Return a customer's date of birth
|
| 125 |
-
*
|
| 126 |
-
* @return string
|
| 127 |
-
*/
|
| 128 |
-
public function birthDate()
|
| 129 |
-
{
|
| 130 |
-
return $this->_original()->getDob();
|
| 131 |
-
}
|
| 132 |
-
|
| 133 |
-
/**
|
| 134 |
-
* Method to retrieve the previous email if possible
|
| 135 |
-
* Falls back on self::email()
|
| 136 |
-
*
|
| 137 |
-
* @return string
|
| 138 |
-
*/
|
| 139 |
-
public function oldEmail()
|
| 140 |
-
{
|
| 141 |
-
$oldEmail = $this->_original()->getOrigData('email');
|
| 142 |
-
|
| 143 |
-
if (isset($oldEmail)) {
|
| 144 |
-
return $oldEmail;
|
| 145 |
-
}
|
| 146 |
-
|
| 147 |
-
return $this->email();
|
| 148 |
-
}
|
| 149 |
-
|
| 150 |
-
/**
|
| 151 |
-
* Returns the gender
|
| 152 |
-
*
|
| 153 |
-
* @return string
|
| 154 |
-
*/
|
| 155 |
-
public function gender()
|
| 156 |
-
{
|
| 157 |
-
$original = $this->_original();
|
| 158 |
-
|
| 159 |
-
$options = $original->getAttribute('gender')->getSource()->getAllOptions();
|
| 160 |
-
|
| 161 |
-
foreach ($options as $option) {
|
| 162 |
-
if ($option['value'] == $original->getGender()) {
|
| 163 |
-
return $option['label'];
|
| 164 |
-
}
|
| 165 |
-
}
|
| 166 |
-
|
| 167 |
-
return 'unknown';
|
| 168 |
-
}
|
| 169 |
-
|
| 170 |
-
/**
|
| 171 |
-
* Return the subscription of the customer
|
| 172 |
-
*
|
| 173 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Subscription
|
| 174 |
-
*/
|
| 175 |
-
public function subscription()
|
| 176 |
-
{
|
| 177 |
-
$subscriber = Mage::getModel('newsletter/subscriber');
|
| 178 |
-
|
| 179 |
-
if (!$subscriber->loadByCustomer($this->_original())->getId()) {
|
| 180 |
-
return null;
|
| 181 |
-
}
|
| 182 |
-
|
| 183 |
-
if ($subscriber->getStoreId() !== $this->_original()->getStoreId()) {
|
| 184 |
-
return null;
|
| 185 |
-
}
|
| 186 |
-
|
| 187 |
-
return Mage::getModel('marketingsoftware/abstraction_subscription')->setOriginal($subscriber);
|
| 188 |
-
}
|
| 189 |
-
|
| 190 |
-
/**
|
| 191 |
-
* Return the group to which this customer belongs
|
| 192 |
-
*
|
| 193 |
-
* @return string
|
| 194 |
-
*/
|
| 195 |
-
public function group()
|
| 196 |
-
{
|
| 197 |
-
return Mage::getModel('customer/group')->load($this->_original()->getGroupId())->getCode();
|
| 198 |
-
}
|
| 199 |
-
|
| 200 |
-
/**
|
| 201 |
-
* Get the quotes for this customer
|
| 202 |
-
*
|
| 203 |
-
* @return array
|
| 204 |
-
*/
|
| 205 |
-
public function quotes()
|
| 206 |
-
{
|
| 207 |
-
$data = array();
|
| 208 |
-
|
| 209 |
-
$quoteIds = Mage::getResourceModel('sales/quote_collection')
|
| 210 |
-
->addFieldToFilter('customer_id', $this->id())->getAllIds();
|
| 211 |
-
|
| 212 |
-
foreach ($quoteIds as $id) {
|
| 213 |
-
$data[] = Mage::getModel('marketingsoftware/abstraction_quote')->loadQuote($id);
|
| 214 |
-
}
|
| 215 |
-
|
| 216 |
-
return $data;
|
| 217 |
-
}
|
| 218 |
-
|
| 219 |
-
/**
|
| 220 |
-
* Get the orders for this customer
|
| 221 |
-
*
|
| 222 |
-
* @return array
|
| 223 |
-
*/
|
| 224 |
-
public function orders()
|
| 225 |
-
{
|
| 226 |
-
$data = array();
|
| 227 |
-
|
| 228 |
-
$orderIds = Mage::getResourceModel('sales/order_collection')
|
| 229 |
-
->addAttributeToFilter('customer_id', $this->id())->getAllIds();
|
| 230 |
-
|
| 231 |
-
foreach ($orderIds as $id) {
|
| 232 |
-
$data[] = Mage::getModel('marketingsoftware/abstraction_order')->loadOrder($id);
|
| 233 |
-
}
|
| 234 |
-
|
| 235 |
-
return $data;
|
| 236 |
-
}
|
| 237 |
-
|
| 238 |
-
/**
|
| 239 |
-
* Get the wishlist for this customer
|
| 240 |
-
*
|
| 241 |
-
* @return array
|
| 242 |
-
*/
|
| 243 |
-
public function wishlist()
|
| 244 |
-
{
|
| 245 |
-
$data = array();
|
| 246 |
-
|
| 247 |
-
$wishlistIds = Mage::getResourceModel('wishlist/wishlist_collection')
|
| 248 |
-
->addAttributeToFilter('customer_id', $this->id())->getAllIds();
|
| 249 |
-
|
| 250 |
-
foreach ($wishlistIds as $id) {
|
| 251 |
-
$data[] = Mage::getModel('marketingsoftware/abstraction_wishlist')->loadWishlist($id);
|
| 252 |
-
}
|
| 253 |
-
|
| 254 |
-
return $data;
|
| 255 |
-
}
|
| 256 |
-
|
| 257 |
-
/**
|
| 258 |
-
* Get the addresses for this customer
|
| 259 |
-
*
|
| 260 |
-
* @return array
|
| 261 |
-
*/
|
| 262 |
-
public function addresses()
|
| 263 |
-
{
|
| 264 |
-
$data = array();
|
| 265 |
-
|
| 266 |
-
$addresses = $this->_original()->getAddressesCollection();
|
| 267 |
-
|
| 268 |
-
foreach ($addresses as $address) {
|
| 269 |
-
$data[] = Mage::getModel('marketingsoftware/abstraction_address')->setOriginal($address);
|
| 270 |
-
}
|
| 271 |
-
|
| 272 |
-
return $data;
|
| 273 |
-
}
|
| 274 |
-
|
| 275 |
-
/**
|
| 276 |
-
* To what storeview does this order belong
|
| 277 |
-
*
|
| 278 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Storeview
|
| 279 |
-
*/
|
| 280 |
-
public function storeview()
|
| 281 |
-
{
|
| 282 |
-
return Mage::getModel('marketingsoftware/abstraction_storeview')->setOriginal($this->_original()->getStore());
|
| 283 |
-
}
|
| 284 |
-
|
| 285 |
-
/**
|
| 286 |
-
* Serialize the object
|
| 287 |
-
*
|
| 288 |
-
* @return string
|
| 289 |
-
*/
|
| 290 |
-
public function serialize()
|
| 291 |
-
{
|
| 292 |
-
return serialize(array($this->id()));
|
| 293 |
-
}
|
| 294 |
-
|
| 295 |
-
/**
|
| 296 |
-
* Unserialize the object
|
| 297 |
-
*
|
| 298 |
-
* @param string $string
|
| 299 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Customer
|
| 300 |
-
*/
|
| 301 |
-
public function unserialize($string)
|
| 302 |
-
{
|
| 303 |
-
list($id) = unserialize($string);
|
| 304 |
-
|
| 305 |
-
$this->loadCustomer($id);
|
| 306 |
-
|
| 307 |
-
return $this;
|
| 308 |
-
}
|
| 309 |
-
}
|
| 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 |
+
* @documentation public
|
| 26 |
+
*/
|
| 27 |
+
|
| 28 |
+
/**
|
| 29 |
+
* A wrapper object around a magento Customer
|
| 30 |
+
*/
|
| 31 |
+
class Copernica_MarketingSoftware_Model_Abstraction_Customer implements Serializable
|
| 32 |
+
{
|
| 33 |
+
/**
|
| 34 |
+
* The id
|
| 35 |
+
*
|
| 36 |
+
* @var int
|
| 37 |
+
*/
|
| 38 |
+
protected $_id;
|
| 39 |
+
|
| 40 |
+
/**
|
| 41 |
+
* The original object
|
| 42 |
+
*
|
| 43 |
+
* @var Mage_Customer_Model_Customer
|
| 44 |
+
*/
|
| 45 |
+
protected $_original;
|
| 46 |
+
|
| 47 |
+
/**
|
| 48 |
+
* Sets the original model
|
| 49 |
+
*
|
| 50 |
+
* @param Mage_Customer_Model_Customer $original
|
| 51 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Customer
|
| 52 |
+
*/
|
| 53 |
+
public function setOriginal(Mage_Customer_Model_Customer $original)
|
| 54 |
+
{
|
| 55 |
+
$this->_original = $original;
|
| 56 |
+
$this->_id = $original->getId();
|
| 57 |
+
|
| 58 |
+
return $this;
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
/**
|
| 62 |
+
* Returns the original model
|
| 63 |
+
*
|
| 64 |
+
* @return Mage_Customer_Model_Customer
|
| 65 |
+
*/
|
| 66 |
+
protected function _original()
|
| 67 |
+
{
|
| 68 |
+
return $this->_original;
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
/**
|
| 72 |
+
* Loads a customer model
|
| 73 |
+
*
|
| 74 |
+
* @param int $customerId
|
| 75 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Customer
|
| 76 |
+
*/
|
| 77 |
+
public function loadCustomer($customerId)
|
| 78 |
+
{
|
| 79 |
+
$customer = Mage::getModel('customer/customer')->load($customerId);
|
| 80 |
+
|
| 81 |
+
if ($customer->getId()) {
|
| 82 |
+
$this->setOriginal($customer);
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
return $this;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
/**
|
| 89 |
+
* Return the id of the customer
|
| 90 |
+
*
|
| 91 |
+
* @return string
|
| 92 |
+
*/
|
| 93 |
+
public function id()
|
| 94 |
+
{
|
| 95 |
+
if (!$this->_original()) {
|
| 96 |
+
return null;
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
return $this->_original()->getId();
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
/**
|
| 103 |
+
* Return the name of this customer
|
| 104 |
+
* Note that null may also be returned to indicate that the name is not known
|
| 105 |
+
*
|
| 106 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Name
|
| 107 |
+
*/
|
| 108 |
+
public function name()
|
| 109 |
+
{
|
| 110 |
+
return Mage::getModel('marketingsoftware/abstraction_name')->setOriginal($this->_original());
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
/**
|
| 114 |
+
* Return the e-mail address of the customer
|
| 115 |
+
*
|
| 116 |
+
* @return string
|
| 117 |
+
*/
|
| 118 |
+
public function email()
|
| 119 |
+
{
|
| 120 |
+
return $this->_original()->getEmail();
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
/**
|
| 124 |
+
* Return a customer's date of birth
|
| 125 |
+
*
|
| 126 |
+
* @return string
|
| 127 |
+
*/
|
| 128 |
+
public function birthDate()
|
| 129 |
+
{
|
| 130 |
+
return $this->_original()->getDob();
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
/**
|
| 134 |
+
* Method to retrieve the previous email if possible
|
| 135 |
+
* Falls back on self::email()
|
| 136 |
+
*
|
| 137 |
+
* @return string
|
| 138 |
+
*/
|
| 139 |
+
public function oldEmail()
|
| 140 |
+
{
|
| 141 |
+
$oldEmail = $this->_original()->getOrigData('email');
|
| 142 |
+
|
| 143 |
+
if (isset($oldEmail)) {
|
| 144 |
+
return $oldEmail;
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
return $this->email();
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
/**
|
| 151 |
+
* Returns the gender
|
| 152 |
+
*
|
| 153 |
+
* @return string
|
| 154 |
+
*/
|
| 155 |
+
public function gender()
|
| 156 |
+
{
|
| 157 |
+
$original = $this->_original();
|
| 158 |
+
|
| 159 |
+
$options = $original->getAttribute('gender')->getSource()->getAllOptions();
|
| 160 |
+
|
| 161 |
+
foreach ($options as $option) {
|
| 162 |
+
if ($option['value'] == $original->getGender()) {
|
| 163 |
+
return $option['label'];
|
| 164 |
+
}
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
return 'unknown';
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
/**
|
| 171 |
+
* Return the subscription of the customer
|
| 172 |
+
*
|
| 173 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Subscription
|
| 174 |
+
*/
|
| 175 |
+
public function subscription()
|
| 176 |
+
{
|
| 177 |
+
$subscriber = Mage::getModel('newsletter/subscriber');
|
| 178 |
+
|
| 179 |
+
if (!$subscriber->loadByCustomer($this->_original())->getId()) {
|
| 180 |
+
return null;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
if ($subscriber->getStoreId() !== $this->_original()->getStoreId()) {
|
| 184 |
+
return null;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
return Mage::getModel('marketingsoftware/abstraction_subscription')->setOriginal($subscriber);
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
/**
|
| 191 |
+
* Return the group to which this customer belongs
|
| 192 |
+
*
|
| 193 |
+
* @return string
|
| 194 |
+
*/
|
| 195 |
+
public function group()
|
| 196 |
+
{
|
| 197 |
+
return Mage::getModel('customer/group')->load($this->_original()->getGroupId())->getCode();
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
/**
|
| 201 |
+
* Get the quotes for this customer
|
| 202 |
+
*
|
| 203 |
+
* @return array
|
| 204 |
+
*/
|
| 205 |
+
public function quotes()
|
| 206 |
+
{
|
| 207 |
+
$data = array();
|
| 208 |
+
|
| 209 |
+
$quoteIds = Mage::getResourceModel('sales/quote_collection')
|
| 210 |
+
->addFieldToFilter('customer_id', $this->id())->getAllIds();
|
| 211 |
+
|
| 212 |
+
foreach ($quoteIds as $id) {
|
| 213 |
+
$data[] = Mage::getModel('marketingsoftware/abstraction_quote')->loadQuote($id);
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
return $data;
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
/**
|
| 220 |
+
* Get the orders for this customer
|
| 221 |
+
*
|
| 222 |
+
* @return array
|
| 223 |
+
*/
|
| 224 |
+
public function orders()
|
| 225 |
+
{
|
| 226 |
+
$data = array();
|
| 227 |
+
|
| 228 |
+
$orderIds = Mage::getResourceModel('sales/order_collection')
|
| 229 |
+
->addAttributeToFilter('customer_id', $this->id())->getAllIds();
|
| 230 |
+
|
| 231 |
+
foreach ($orderIds as $id) {
|
| 232 |
+
$data[] = Mage::getModel('marketingsoftware/abstraction_order')->loadOrder($id);
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
return $data;
|
| 236 |
+
}
|
| 237 |
+
|
| 238 |
+
/**
|
| 239 |
+
* Get the wishlist for this customer
|
| 240 |
+
*
|
| 241 |
+
* @return array
|
| 242 |
+
*/
|
| 243 |
+
public function wishlist()
|
| 244 |
+
{
|
| 245 |
+
$data = array();
|
| 246 |
+
|
| 247 |
+
$wishlistIds = Mage::getResourceModel('wishlist/wishlist_collection')
|
| 248 |
+
->addAttributeToFilter('customer_id', $this->id())->getAllIds();
|
| 249 |
+
|
| 250 |
+
foreach ($wishlistIds as $id) {
|
| 251 |
+
$data[] = Mage::getModel('marketingsoftware/abstraction_wishlist')->loadWishlist($id);
|
| 252 |
+
}
|
| 253 |
+
|
| 254 |
+
return $data;
|
| 255 |
+
}
|
| 256 |
+
|
| 257 |
+
/**
|
| 258 |
+
* Get the addresses for this customer
|
| 259 |
+
*
|
| 260 |
+
* @return array
|
| 261 |
+
*/
|
| 262 |
+
public function addresses()
|
| 263 |
+
{
|
| 264 |
+
$data = array();
|
| 265 |
+
|
| 266 |
+
$addresses = $this->_original()->getAddressesCollection();
|
| 267 |
+
|
| 268 |
+
foreach ($addresses as $address) {
|
| 269 |
+
$data[] = Mage::getModel('marketingsoftware/abstraction_address')->setOriginal($address);
|
| 270 |
+
}
|
| 271 |
+
|
| 272 |
+
return $data;
|
| 273 |
+
}
|
| 274 |
+
|
| 275 |
+
/**
|
| 276 |
+
* To what storeview does this order belong
|
| 277 |
+
*
|
| 278 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Storeview
|
| 279 |
+
*/
|
| 280 |
+
public function storeview()
|
| 281 |
+
{
|
| 282 |
+
return Mage::getModel('marketingsoftware/abstraction_storeview')->setOriginal($this->_original()->getStore());
|
| 283 |
+
}
|
| 284 |
+
|
| 285 |
+
/**
|
| 286 |
+
* Serialize the object
|
| 287 |
+
*
|
| 288 |
+
* @return string
|
| 289 |
+
*/
|
| 290 |
+
public function serialize()
|
| 291 |
+
{
|
| 292 |
+
return serialize(array($this->id()));
|
| 293 |
+
}
|
| 294 |
+
|
| 295 |
+
/**
|
| 296 |
+
* Unserialize the object
|
| 297 |
+
*
|
| 298 |
+
* @param string $string
|
| 299 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Customer
|
| 300 |
+
*/
|
| 301 |
+
public function unserialize($string)
|
| 302 |
+
{
|
| 303 |
+
list($id) = unserialize($string);
|
| 304 |
+
|
| 305 |
+
$this->loadCustomer($id);
|
| 306 |
+
|
| 307 |
+
return $this;
|
| 308 |
+
}
|
| 309 |
+
}
|
app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Name.php
CHANGED
|
@@ -1,131 +1,131 @@
|
|
| 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 name, note this is not an Magento object
|
| 29 |
-
*/
|
| 30 |
-
class Copernica_MarketingSoftware_Model_Abstraction_Name implements Serializable
|
| 31 |
-
{
|
| 32 |
-
/**
|
| 33 |
-
* Predefine the internal fields
|
| 34 |
-
*/
|
| 35 |
-
protected $_firstname;
|
| 36 |
-
protected $_prefix;
|
| 37 |
-
protected $_middlename;
|
| 38 |
-
protected $_lastname;
|
| 39 |
-
|
| 40 |
-
/**
|
| 41 |
-
* Sets the original model
|
| 42 |
-
*
|
| 43 |
-
* @param Mage_Customer_Model_Customer|Mage_Customer_Model_Customer_Address|Mage_Sales_Model_Order_Address|Mage_Sales_Model_Quote_Address|Mage_Customer_Model_Address
|
| 44 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Name
|
| 45 |
-
*/
|
| 46 |
-
public function setOriginal($original)
|
| 47 |
-
{
|
| 48 |
-
$this->_firstname = $original->getFirstname();
|
| 49 |
-
$this->_prefix = $original->getPrefix();
|
| 50 |
-
$this->_middlename = $original->getMiddlename();
|
| 51 |
-
$this->_lastname = $original->getLastname();
|
| 52 |
-
|
| 53 |
-
return $this;
|
| 54 |
-
}
|
| 55 |
-
|
| 56 |
-
/**
|
| 57 |
-
* Return the firstname of the customer
|
| 58 |
-
*
|
| 59 |
-
* @return string
|
| 60 |
-
*/
|
| 61 |
-
public function firstname()
|
| 62 |
-
{
|
| 63 |
-
return $this->_firstname;
|
| 64 |
-
}
|
| 65 |
-
|
| 66 |
-
/**
|
| 67 |
-
* Return the prefix of the customer
|
| 68 |
-
* NOTE: the prefix field is not displayed by default
|
| 69 |
-
*
|
| 70 |
-
* @return string
|
| 71 |
-
*/
|
| 72 |
-
public function prefix()
|
| 73 |
-
{
|
| 74 |
-
return $this->_prefix;
|
| 75 |
-
}
|
| 76 |
-
|
| 77 |
-
/**
|
| 78 |
-
* Return the middlename of the customer
|
| 79 |
-
* NOTE: the middlename field is not displayed by default
|
| 80 |
-
*
|
| 81 |
-
* @return string
|
| 82 |
-
*/
|
| 83 |
-
public function middlename()
|
| 84 |
-
{
|
| 85 |
-
return $this->_middlename;
|
| 86 |
-
}
|
| 87 |
-
|
| 88 |
-
/**
|
| 89 |
-
* Return the lastname of the customer
|
| 90 |
-
*
|
| 91 |
-
* @return string
|
| 92 |
-
*/
|
| 93 |
-
public function lastname()
|
| 94 |
-
{
|
| 95 |
-
return $this->_lastname;
|
| 96 |
-
}
|
| 97 |
-
|
| 98 |
-
/**
|
| 99 |
-
* Serialize the object
|
| 100 |
-
*
|
| 101 |
-
* @return string
|
| 102 |
-
*/
|
| 103 |
-
public function serialize()
|
| 104 |
-
{
|
| 105 |
-
return serialize(array(
|
| 106 |
-
$this->firstname(),
|
| 107 |
-
$this->prefix(),
|
| 108 |
-
$this->middlename(),
|
| 109 |
-
$this->lastname(),
|
| 110 |
-
));
|
| 111 |
-
}
|
| 112 |
-
|
| 113 |
-
/**
|
| 114 |
-
* Unserialize the object
|
| 115 |
-
*
|
| 116 |
-
* @param string $string
|
| 117 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Name
|
| 118 |
-
*/
|
| 119 |
-
public function unserialize($string)
|
| 120 |
-
{
|
| 121 |
-
list(
|
| 122 |
-
$this->_firstname,
|
| 123 |
-
$this->_prefix,
|
| 124 |
-
$this->_middlename,
|
| 125 |
-
$this->_lastname
|
| 126 |
-
) = unserialize($string);
|
| 127 |
-
|
| 128 |
-
return $this;
|
| 129 |
-
}
|
| 130 |
-
}
|
| 131 |
-
|
| 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 name, note this is not an Magento object
|
| 29 |
+
*/
|
| 30 |
+
class Copernica_MarketingSoftware_Model_Abstraction_Name implements Serializable
|
| 31 |
+
{
|
| 32 |
+
/**
|
| 33 |
+
* Predefine the internal fields
|
| 34 |
+
*/
|
| 35 |
+
protected $_firstname;
|
| 36 |
+
protected $_prefix;
|
| 37 |
+
protected $_middlename;
|
| 38 |
+
protected $_lastname;
|
| 39 |
+
|
| 40 |
+
/**
|
| 41 |
+
* Sets the original model
|
| 42 |
+
*
|
| 43 |
+
* @param Mage_Customer_Model_Customer|Mage_Customer_Model_Customer_Address|Mage_Sales_Model_Order_Address|Mage_Sales_Model_Quote_Address|Mage_Customer_Model_Address
|
| 44 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Name
|
| 45 |
+
*/
|
| 46 |
+
public function setOriginal($original)
|
| 47 |
+
{
|
| 48 |
+
$this->_firstname = $original->getFirstname();
|
| 49 |
+
$this->_prefix = $original->getPrefix();
|
| 50 |
+
$this->_middlename = $original->getMiddlename();
|
| 51 |
+
$this->_lastname = $original->getLastname();
|
| 52 |
+
|
| 53 |
+
return $this;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
/**
|
| 57 |
+
* Return the firstname of the customer
|
| 58 |
+
*
|
| 59 |
+
* @return string
|
| 60 |
+
*/
|
| 61 |
+
public function firstname()
|
| 62 |
+
{
|
| 63 |
+
return $this->_firstname;
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
/**
|
| 67 |
+
* Return the prefix of the customer
|
| 68 |
+
* NOTE: the prefix field is not displayed by default
|
| 69 |
+
*
|
| 70 |
+
* @return string
|
| 71 |
+
*/
|
| 72 |
+
public function prefix()
|
| 73 |
+
{
|
| 74 |
+
return $this->_prefix;
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
/**
|
| 78 |
+
* Return the middlename of the customer
|
| 79 |
+
* NOTE: the middlename field is not displayed by default
|
| 80 |
+
*
|
| 81 |
+
* @return string
|
| 82 |
+
*/
|
| 83 |
+
public function middlename()
|
| 84 |
+
{
|
| 85 |
+
return $this->_middlename;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
/**
|
| 89 |
+
* Return the lastname of the customer
|
| 90 |
+
*
|
| 91 |
+
* @return string
|
| 92 |
+
*/
|
| 93 |
+
public function lastname()
|
| 94 |
+
{
|
| 95 |
+
return $this->_lastname;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
/**
|
| 99 |
+
* Serialize the object
|
| 100 |
+
*
|
| 101 |
+
* @return string
|
| 102 |
+
*/
|
| 103 |
+
public function serialize()
|
| 104 |
+
{
|
| 105 |
+
return serialize(array(
|
| 106 |
+
$this->firstname(),
|
| 107 |
+
$this->prefix(),
|
| 108 |
+
$this->middlename(),
|
| 109 |
+
$this->lastname(),
|
| 110 |
+
));
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
/**
|
| 114 |
+
* Unserialize the object
|
| 115 |
+
*
|
| 116 |
+
* @param string $string
|
| 117 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Name
|
| 118 |
+
*/
|
| 119 |
+
public function unserialize($string)
|
| 120 |
+
{
|
| 121 |
+
list(
|
| 122 |
+
$this->_firstname,
|
| 123 |
+
$this->_prefix,
|
| 124 |
+
$this->_middlename,
|
| 125 |
+
$this->_lastname
|
| 126 |
+
) = unserialize($string);
|
| 127 |
+
|
| 128 |
+
return $this;
|
| 129 |
+
}
|
| 130 |
+
}
|
| 131 |
+
|
app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Order.php
CHANGED
|
@@ -1,361 +1,361 @@
|
|
| 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 Order
|
| 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
|
| 43 |
-
*/
|
| 44 |
-
protected $_id;
|
| 45 |
-
protected $_incrementId;
|
| 46 |
-
protected $_quoteId;
|
| 47 |
-
protected $_quantity;
|
| 48 |
-
protected $_currency;
|
| 49 |
-
protected $_timestamp;
|
| 50 |
-
protected $_customerIP;
|
| 51 |
-
protected $_items;
|
| 52 |
-
|
| 53 |
-
/**
|
| 54 |
-
* The storeview object
|
| 55 |
-
*
|
| 56 |
-
* @var Copernica_MarketingSoftware_Model_Abstraction_Storeview
|
| 57 |
-
*/
|
| 58 |
-
protected $_storeview;
|
| 59 |
-
|
| 60 |
-
protected $_customerId;
|
| 61 |
-
protected $_addresses;
|
| 62 |
-
protected $_price;
|
| 63 |
-
protected $_weight;
|
| 64 |
-
protected $_state;
|
| 65 |
-
protected $_status;
|
| 66 |
-
protected $_shippingDescription;
|
| 67 |
-
protected $_paymentDescription;
|
| 68 |
-
|
| 69 |
-
/**
|
| 70 |
-
* Sets the original model
|
| 71 |
-
*
|
| 72 |
-
* @param Mage_Sales_Model_Order $original
|
| 73 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Order
|
| 74 |
-
*/
|
| 75 |
-
public function setOriginal(Mage_Sales_Model_Order $original)
|
| 76 |
-
{
|
| 77 |
-
$this->_id = $original->getId();
|
| 78 |
-
|
| 79 |
-
return $this;
|
| 80 |
-
|
| 81 |
-
}
|
| 82 |
-
|
| 83 |
-
/**
|
| 84 |
-
* This method will set the state of this order from original magento order
|
| 85 |
-
*
|
| 86 |
-
* @param Mage_Sales_Model_Order $original
|
| 87 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Order
|
| 88 |
-
*/
|
| 89 |
-
public function importFromOriginal(Mage_Sales_Model_Order $original)
|
| 90 |
-
{
|
| 91 |
-
$this->_id = $original->getId();
|
| 92 |
-
$this->_incrementId = $original->getIncrementId();
|
| 93 |
-
$this->_quoteId = $original->getQuoteId();
|
| 94 |
-
$this->_state = $original->getState();
|
| 95 |
-
$this->_status = $original->getStatus();
|
| 96 |
-
$this->_quantity = $original->getTotalQtyOrdered();
|
| 97 |
-
$this->_currency = $original->getOrderCurrencyCode();
|
| 98 |
-
$this->_price = Mage::getModel('marketingsoftware/abstraction_price')->setOriginal($original);
|
| 99 |
-
$this->_weight = $original->getWeight();
|
| 100 |
-
$this->_storeview = Mage::getModel('marketingsoftware/abstraction_storeview')->setOriginal($original->getStore());
|
| 101 |
-
$this->_timestamp = $original->getUpdatedAt();
|
| 102 |
-
$this->_shippingDescription = $original->getShippingDescription();
|
| 103 |
-
$this->_customerIP = $original->getRemoteIp();
|
| 104 |
-
|
| 105 |
-
$data = array();
|
| 106 |
-
|
| 107 |
-
$items = $original->getAllVisibleItems();
|
| 108 |
-
|
| 109 |
-
foreach ($items as $item) {
|
| 110 |
-
$data[] = Mage::getModel('marketingsoftware/abstraction_order_item')->setOriginal($item);
|
| 111 |
-
}
|
| 112 |
-
|
| 113 |
-
$this->_items = $data;
|
| 114 |
-
|
| 115 |
-
if ($customerId = $original->getCustomerId()) {
|
| 116 |
-
$this->_customerId = $customerId;
|
| 117 |
-
}
|
| 118 |
-
|
| 119 |
-
$data = array();
|
| 120 |
-
|
| 121 |
-
$addresses = $original->getAddressesCollection();
|
| 122 |
-
|
| 123 |
-
foreach ($addresses as $address) {
|
| 124 |
-
$data[] = Mage::getModel('marketingsoftware/abstraction_address')->setOriginal($address);
|
| 125 |
-
}
|
| 126 |
-
|
| 127 |
-
$this->_addresses = $data;
|
| 128 |
-
|
| 129 |
-
if ($payment = $original->getPayment()) {
|
| 130 |
-
try {
|
| 131 |
-
if ($payment->getMethod() == self::PAYMENT_METHOD_KLARNA) {
|
| 132 |
-
$this->_paymentDescription = 'Klarna';
|
| 133 |
-
} else {
|
| 134 |
-
$this->_paymentDescription = $payment->getMethodInstance()->getTitle();
|
| 135 |
-
}
|
| 136 |
-
} catch (Mage_Core_Exception $exception) { }
|
| 137 |
-
}
|
| 138 |
-
|
| 139 |
-
return $this;
|
| 140 |
-
}
|
| 141 |
-
|
| 142 |
-
/**
|
| 143 |
-
* Loads an order model
|
| 144 |
-
*
|
| 145 |
-
* @param integer $orderId
|
| 146 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Order
|
| 147 |
-
*/
|
| 148 |
-
public function loadOrder($orderId)
|
| 149 |
-
{
|
| 150 |
-
$order = Mage::getModel('sales/order')->load($orderId);
|
| 151 |
-
|
| 152 |
-
if ($order->getId()) {
|
| 153 |
-
$this->importFromOriginal($order);
|
| 154 |
-
}
|
| 155 |
-
|
| 156 |
-
return $this;
|
| 157 |
-
}
|
| 158 |
-
|
| 159 |
-
/**
|
| 160 |
-
* The id of this order object
|
| 161 |
-
*
|
| 162 |
-
* @return integer
|
| 163 |
-
*/
|
| 164 |
-
public function id()
|
| 165 |
-
{
|
| 166 |
-
return $this->_id;
|
| 167 |
-
}
|
| 168 |
-
|
| 169 |
-
/**
|
| 170 |
-
* The increment (longer) id of this order object
|
| 171 |
-
*
|
| 172 |
-
* @return integer
|
| 173 |
-
*/
|
| 174 |
-
public function incrementId()
|
| 175 |
-
{
|
| 176 |
-
return $this->_incrementId;
|
| 177 |
-
}
|
| 178 |
-
|
| 179 |
-
/**
|
| 180 |
-
* The quote id of this order object
|
| 181 |
-
*
|
| 182 |
-
* @return integer
|
| 183 |
-
*/
|
| 184 |
-
public function quoteId()
|
| 185 |
-
{
|
| 186 |
-
return $this->_quoteId;
|
| 187 |
-
}
|
| 188 |
-
|
| 189 |
-
/**
|
| 190 |
-
* The state of this order
|
| 191 |
-
*
|
| 192 |
-
* @return string
|
| 193 |
-
*/
|
| 194 |
-
public function state()
|
| 195 |
-
{
|
| 196 |
-
return $this->_state;
|
| 197 |
-
}
|
| 198 |
-
|
| 199 |
-
/**
|
| 200 |
-
* The status of this order
|
| 201 |
-
*
|
| 202 |
-
* @return string
|
| 203 |
-
*/
|
| 204 |
-
public function status()
|
| 205 |
-
{
|
| 206 |
-
return $this->_status;
|
| 207 |
-
}
|
| 208 |
-
|
| 209 |
-
/**
|
| 210 |
-
* The number of items present in this order
|
| 211 |
-
*
|
| 212 |
-
* @return integer
|
| 213 |
-
*/
|
| 214 |
-
public function quantity()
|
| 215 |
-
{
|
| 216 |
-
return $this->_quantity;
|
| 217 |
-
}
|
| 218 |
-
|
| 219 |
-
/**
|
| 220 |
-
* The number of items present in this order
|
| 221 |
-
*
|
| 222 |
-
* @return integer
|
| 223 |
-
*/
|
| 224 |
-
public function currency()
|
| 225 |
-
{
|
| 226 |
-
return $this->_currency;
|
| 227 |
-
}
|
| 228 |
-
|
| 229 |
-
/**
|
| 230 |
-
* The price
|
| 231 |
-
* Note that an object is returned, which may consist of multiple components
|
| 232 |
-
*
|
| 233 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Price
|
| 234 |
-
*/
|
| 235 |
-
public function price()
|
| 236 |
-
{
|
| 237 |
-
return $this->_price;
|
| 238 |
-
}
|
| 239 |
-
|
| 240 |
-
/**
|
| 241 |
-
* The weight
|
| 242 |
-
*
|
| 243 |
-
* @return float
|
| 244 |
-
*/
|
| 245 |
-
public function weight()
|
| 246 |
-
{
|
| 247 |
-
return $this->_weight;
|
| 248 |
-
}
|
| 249 |
-
|
| 250 |
-
/**
|
| 251 |
-
* To what storeview does this order belong
|
| 252 |
-
*
|
| 253 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Storeview
|
| 254 |
-
*/
|
| 255 |
-
public function storeview()
|
| 256 |
-
{
|
| 257 |
-
return $this->_storeview;
|
| 258 |
-
}
|
| 259 |
-
|
| 260 |
-
/**
|
| 261 |
-
* Get the items from the order
|
| 262 |
-
*
|
| 263 |
-
* @return array
|
| 264 |
-
*/
|
| 265 |
-
public function items()
|
| 266 |
-
{
|
| 267 |
-
return $this->_items;
|
| 268 |
-
}
|
| 269 |
-
|
| 270 |
-
/**
|
| 271 |
-
* The timestamp at which this order was modified
|
| 272 |
-
*
|
| 273 |
-
* @return string
|
| 274 |
-
*/
|
| 275 |
-
public function timestamp()
|
| 276 |
-
{
|
| 277 |
-
return $this->_timestamp;
|
| 278 |
-
}
|
| 279 |
-
|
| 280 |
-
/**
|
| 281 |
-
* The customer may return null
|
| 282 |
-
*
|
| 283 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Customer|null
|
| 284 |
-
*/
|
| 285 |
-
public function customer()
|
| 286 |
-
{
|
| 287 |
-
if ($this->_customerId) {
|
| 288 |
-
return Mage::getModel('marketingsoftware/abstraction_customer')->loadCustomer($this->_customerId);
|
| 289 |
-
} else {
|
| 290 |
-
return null;
|
| 291 |
-
}
|
| 292 |
-
}
|
| 293 |
-
|
| 294 |
-
/**
|
| 295 |
-
* The addresses of the order
|
| 296 |
-
*
|
| 297 |
-
* @return array of Copernica_MarketingSoftware_Model_Abstraction_Address
|
| 298 |
-
*/
|
| 299 |
-
public function addresses()
|
| 300 |
-
{
|
| 301 |
-
return $this->_addresses;
|
| 302 |
-
}
|
| 303 |
-
|
| 304 |
-
/**
|
| 305 |
-
* The shipping method of the order
|
| 306 |
-
*
|
| 307 |
-
* @return string
|
| 308 |
-
*/
|
| 309 |
-
public function shippingDescription()
|
| 310 |
-
{
|
| 311 |
-
return $this->_shippingDescription;
|
| 312 |
-
}
|
| 313 |
-
|
| 314 |
-
/**
|
| 315 |
-
* The payment method of the order
|
| 316 |
-
*
|
| 317 |
-
* @return string
|
| 318 |
-
*/
|
| 319 |
-
public function paymentDescription()
|
| 320 |
-
{
|
| 321 |
-
return $this->_paymentDescription;
|
| 322 |
-
}
|
| 323 |
-
|
| 324 |
-
/**
|
| 325 |
-
* The IP from which this order was constructed
|
| 326 |
-
*
|
| 327 |
-
* @return string
|
| 328 |
-
*/
|
| 329 |
-
public function customerIP()
|
| 330 |
-
{
|
| 331 |
-
return $this->_customerIP;
|
| 332 |
-
}
|
| 333 |
-
|
| 334 |
-
/**
|
| 335 |
-
* Serialize the object
|
| 336 |
-
*
|
| 337 |
-
* @return string
|
| 338 |
-
*/
|
| 339 |
-
public function serialize()
|
| 340 |
-
{
|
| 341 |
-
return serialize(array($this->id()));
|
| 342 |
-
}
|
| 343 |
-
|
| 344 |
-
/**
|
| 345 |
-
* Unserialize the object
|
| 346 |
-
*
|
| 347 |
-
* @param string $string
|
| 348 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Order
|
| 349 |
-
*/
|
| 350 |
-
public function unserialize($string)
|
| 351 |
-
{
|
| 352 |
-
list(
|
| 353 |
-
$this->_id
|
| 354 |
-
) = unserialize($string);
|
| 355 |
-
|
| 356 |
-
$this->loadOrder($this->_id);
|
| 357 |
-
|
| 358 |
-
return $this;
|
| 359 |
-
}
|
| 360 |
-
}
|
| 361 |
-
|
| 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 Order
|
| 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
|
| 43 |
+
*/
|
| 44 |
+
protected $_id;
|
| 45 |
+
protected $_incrementId;
|
| 46 |
+
protected $_quoteId;
|
| 47 |
+
protected $_quantity;
|
| 48 |
+
protected $_currency;
|
| 49 |
+
protected $_timestamp;
|
| 50 |
+
protected $_customerIP;
|
| 51 |
+
protected $_items;
|
| 52 |
+
|
| 53 |
+
/**
|
| 54 |
+
* The storeview object
|
| 55 |
+
*
|
| 56 |
+
* @var Copernica_MarketingSoftware_Model_Abstraction_Storeview
|
| 57 |
+
*/
|
| 58 |
+
protected $_storeview;
|
| 59 |
+
|
| 60 |
+
protected $_customerId;
|
| 61 |
+
protected $_addresses;
|
| 62 |
+
protected $_price;
|
| 63 |
+
protected $_weight;
|
| 64 |
+
protected $_state;
|
| 65 |
+
protected $_status;
|
| 66 |
+
protected $_shippingDescription;
|
| 67 |
+
protected $_paymentDescription;
|
| 68 |
+
|
| 69 |
+
/**
|
| 70 |
+
* Sets the original model
|
| 71 |
+
*
|
| 72 |
+
* @param Mage_Sales_Model_Order $original
|
| 73 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Order
|
| 74 |
+
*/
|
| 75 |
+
public function setOriginal(Mage_Sales_Model_Order $original)
|
| 76 |
+
{
|
| 77 |
+
$this->_id = $original->getId();
|
| 78 |
+
|
| 79 |
+
return $this;
|
| 80 |
+
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
/**
|
| 84 |
+
* This method will set the state of this order from original magento order
|
| 85 |
+
*
|
| 86 |
+
* @param Mage_Sales_Model_Order $original
|
| 87 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Order
|
| 88 |
+
*/
|
| 89 |
+
public function importFromOriginal(Mage_Sales_Model_Order $original)
|
| 90 |
+
{
|
| 91 |
+
$this->_id = $original->getId();
|
| 92 |
+
$this->_incrementId = $original->getIncrementId();
|
| 93 |
+
$this->_quoteId = $original->getQuoteId();
|
| 94 |
+
$this->_state = $original->getState();
|
| 95 |
+
$this->_status = $original->getStatus();
|
| 96 |
+
$this->_quantity = $original->getTotalQtyOrdered();
|
| 97 |
+
$this->_currency = $original->getOrderCurrencyCode();
|
| 98 |
+
$this->_price = Mage::getModel('marketingsoftware/abstraction_price')->setOriginal($original);
|
| 99 |
+
$this->_weight = $original->getWeight();
|
| 100 |
+
$this->_storeview = Mage::getModel('marketingsoftware/abstraction_storeview')->setOriginal($original->getStore());
|
| 101 |
+
$this->_timestamp = $original->getUpdatedAt();
|
| 102 |
+
$this->_shippingDescription = $original->getShippingDescription();
|
| 103 |
+
$this->_customerIP = $original->getRemoteIp();
|
| 104 |
+
|
| 105 |
+
$data = array();
|
| 106 |
+
|
| 107 |
+
$items = $original->getAllVisibleItems();
|
| 108 |
+
|
| 109 |
+
foreach ($items as $item) {
|
| 110 |
+
$data[] = Mage::getModel('marketingsoftware/abstraction_order_item')->setOriginal($item);
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
$this->_items = $data;
|
| 114 |
+
|
| 115 |
+
if ($customerId = $original->getCustomerId()) {
|
| 116 |
+
$this->_customerId = $customerId;
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
$data = array();
|
| 120 |
+
|
| 121 |
+
$addresses = $original->getAddressesCollection();
|
| 122 |
+
|
| 123 |
+
foreach ($addresses as $address) {
|
| 124 |
+
$data[] = Mage::getModel('marketingsoftware/abstraction_address')->setOriginal($address);
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
$this->_addresses = $data;
|
| 128 |
+
|
| 129 |
+
if ($payment = $original->getPayment()) {
|
| 130 |
+
try {
|
| 131 |
+
if ($payment->getMethod() == self::PAYMENT_METHOD_KLARNA) {
|
| 132 |
+
$this->_paymentDescription = 'Klarna';
|
| 133 |
+
} else {
|
| 134 |
+
$this->_paymentDescription = $payment->getMethodInstance()->getTitle();
|
| 135 |
+
}
|
| 136 |
+
} catch (Mage_Core_Exception $exception) { }
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
return $this;
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
/**
|
| 143 |
+
* Loads an order model
|
| 144 |
+
*
|
| 145 |
+
* @param integer $orderId
|
| 146 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Order
|
| 147 |
+
*/
|
| 148 |
+
public function loadOrder($orderId)
|
| 149 |
+
{
|
| 150 |
+
$order = Mage::getModel('sales/order')->load($orderId);
|
| 151 |
+
|
| 152 |
+
if ($order->getId()) {
|
| 153 |
+
$this->importFromOriginal($order);
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
return $this;
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
/**
|
| 160 |
+
* The id of this order object
|
| 161 |
+
*
|
| 162 |
+
* @return integer
|
| 163 |
+
*/
|
| 164 |
+
public function id()
|
| 165 |
+
{
|
| 166 |
+
return $this->_id;
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
/**
|
| 170 |
+
* The increment (longer) id of this order object
|
| 171 |
+
*
|
| 172 |
+
* @return integer
|
| 173 |
+
*/
|
| 174 |
+
public function incrementId()
|
| 175 |
+
{
|
| 176 |
+
return $this->_incrementId;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
/**
|
| 180 |
+
* The quote id of this order object
|
| 181 |
+
*
|
| 182 |
+
* @return integer
|
| 183 |
+
*/
|
| 184 |
+
public function quoteId()
|
| 185 |
+
{
|
| 186 |
+
return $this->_quoteId;
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
/**
|
| 190 |
+
* The state of this order
|
| 191 |
+
*
|
| 192 |
+
* @return string
|
| 193 |
+
*/
|
| 194 |
+
public function state()
|
| 195 |
+
{
|
| 196 |
+
return $this->_state;
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
/**
|
| 200 |
+
* The status of this order
|
| 201 |
+
*
|
| 202 |
+
* @return string
|
| 203 |
+
*/
|
| 204 |
+
public function status()
|
| 205 |
+
{
|
| 206 |
+
return $this->_status;
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
/**
|
| 210 |
+
* The number of items present in this order
|
| 211 |
+
*
|
| 212 |
+
* @return integer
|
| 213 |
+
*/
|
| 214 |
+
public function quantity()
|
| 215 |
+
{
|
| 216 |
+
return $this->_quantity;
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
/**
|
| 220 |
+
* The number of items present in this order
|
| 221 |
+
*
|
| 222 |
+
* @return integer
|
| 223 |
+
*/
|
| 224 |
+
public function currency()
|
| 225 |
+
{
|
| 226 |
+
return $this->_currency;
|
| 227 |
+
}
|
| 228 |
+
|
| 229 |
+
/**
|
| 230 |
+
* The price
|
| 231 |
+
* Note that an object is returned, which may consist of multiple components
|
| 232 |
+
*
|
| 233 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Price
|
| 234 |
+
*/
|
| 235 |
+
public function price()
|
| 236 |
+
{
|
| 237 |
+
return $this->_price;
|
| 238 |
+
}
|
| 239 |
+
|
| 240 |
+
/**
|
| 241 |
+
* The weight
|
| 242 |
+
*
|
| 243 |
+
* @return float
|
| 244 |
+
*/
|
| 245 |
+
public function weight()
|
| 246 |
+
{
|
| 247 |
+
return $this->_weight;
|
| 248 |
+
}
|
| 249 |
+
|
| 250 |
+
/**
|
| 251 |
+
* To what storeview does this order belong
|
| 252 |
+
*
|
| 253 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Storeview
|
| 254 |
+
*/
|
| 255 |
+
public function storeview()
|
| 256 |
+
{
|
| 257 |
+
return $this->_storeview;
|
| 258 |
+
}
|
| 259 |
+
|
| 260 |
+
/**
|
| 261 |
+
* Get the items from the order
|
| 262 |
+
*
|
| 263 |
+
* @return array
|
| 264 |
+
*/
|
| 265 |
+
public function items()
|
| 266 |
+
{
|
| 267 |
+
return $this->_items;
|
| 268 |
+
}
|
| 269 |
+
|
| 270 |
+
/**
|
| 271 |
+
* The timestamp at which this order was modified
|
| 272 |
+
*
|
| 273 |
+
* @return string
|
| 274 |
+
*/
|
| 275 |
+
public function timestamp()
|
| 276 |
+
{
|
| 277 |
+
return $this->_timestamp;
|
| 278 |
+
}
|
| 279 |
+
|
| 280 |
+
/**
|
| 281 |
+
* The customer may return null
|
| 282 |
+
*
|
| 283 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Customer|null
|
| 284 |
+
*/
|
| 285 |
+
public function customer()
|
| 286 |
+
{
|
| 287 |
+
if ($this->_customerId) {
|
| 288 |
+
return Mage::getModel('marketingsoftware/abstraction_customer')->loadCustomer($this->_customerId);
|
| 289 |
+
} else {
|
| 290 |
+
return null;
|
| 291 |
+
}
|
| 292 |
+
}
|
| 293 |
+
|
| 294 |
+
/**
|
| 295 |
+
* The addresses of the order
|
| 296 |
+
*
|
| 297 |
+
* @return array of Copernica_MarketingSoftware_Model_Abstraction_Address
|
| 298 |
+
*/
|
| 299 |
+
public function addresses()
|
| 300 |
+
{
|
| 301 |
+
return $this->_addresses;
|
| 302 |
+
}
|
| 303 |
+
|
| 304 |
+
/**
|
| 305 |
+
* The shipping method of the order
|
| 306 |
+
*
|
| 307 |
+
* @return string
|
| 308 |
+
*/
|
| 309 |
+
public function shippingDescription()
|
| 310 |
+
{
|
| 311 |
+
return $this->_shippingDescription;
|
| 312 |
+
}
|
| 313 |
+
|
| 314 |
+
/**
|
| 315 |
+
* The payment method of the order
|
| 316 |
+
*
|
| 317 |
+
* @return string
|
| 318 |
+
*/
|
| 319 |
+
public function paymentDescription()
|
| 320 |
+
{
|
| 321 |
+
return $this->_paymentDescription;
|
| 322 |
+
}
|
| 323 |
+
|
| 324 |
+
/**
|
| 325 |
+
* The IP from which this order was constructed
|
| 326 |
+
*
|
| 327 |
+
* @return string
|
| 328 |
+
*/
|
| 329 |
+
public function customerIP()
|
| 330 |
+
{
|
| 331 |
+
return $this->_customerIP;
|
| 332 |
+
}
|
| 333 |
+
|
| 334 |
+
/**
|
| 335 |
+
* Serialize the object
|
| 336 |
+
*
|
| 337 |
+
* @return string
|
| 338 |
+
*/
|
| 339 |
+
public function serialize()
|
| 340 |
+
{
|
| 341 |
+
return serialize(array($this->id()));
|
| 342 |
+
}
|
| 343 |
+
|
| 344 |
+
/**
|
| 345 |
+
* Unserialize the object
|
| 346 |
+
*
|
| 347 |
+
* @param string $string
|
| 348 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Order
|
| 349 |
+
*/
|
| 350 |
+
public function unserialize($string)
|
| 351 |
+
{
|
| 352 |
+
list(
|
| 353 |
+
$this->_id
|
| 354 |
+
) = unserialize($string);
|
| 355 |
+
|
| 356 |
+
$this->loadOrder($this->_id);
|
| 357 |
+
|
| 358 |
+
return $this;
|
| 359 |
+
}
|
| 360 |
+
}
|
| 361 |
+
|
app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Order/Item.php
CHANGED
|
@@ -1,191 +1,191 @@
|
|
| 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 Order Item
|
| 29 |
-
*/
|
| 30 |
-
class Copernica_MarketingSoftware_Model_Abstraction_Order_Item implements Serializable
|
| 31 |
-
{
|
| 32 |
-
/**
|
| 33 |
-
* Predefine the internal fields
|
| 34 |
-
*/
|
| 35 |
-
protected $_id;
|
| 36 |
-
protected $_orderId;
|
| 37 |
-
protected $_quantity;
|
| 38 |
-
protected $_price;
|
| 39 |
-
protected $_weight;
|
| 40 |
-
protected $_timestamp;
|
| 41 |
-
protected $_options;
|
| 42 |
-
protected $_product;
|
| 43 |
-
|
| 44 |
-
/**
|
| 45 |
-
* Sets the original model
|
| 46 |
-
*
|
| 47 |
-
* @param Mage_Sales_Model_Order_Item $original
|
| 48 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Order_Item
|
| 49 |
-
*/
|
| 50 |
-
public function setOriginal(Mage_Sales_Model_Order_Item $original)
|
| 51 |
-
{
|
| 52 |
-
$this->_id = $original->getId();
|
| 53 |
-
$this->_orderId = $original->getOrder()->getId();
|
| 54 |
-
$this->_quantity = $original->getQtyOrdered();
|
| 55 |
-
$this->_price = Mage::getModel('marketingsoftware/abstraction_price')->setOriginal($original);
|
| 56 |
-
$this->_weight = $original->getWeight();
|
| 57 |
-
$this->_timestamp = $original->getUpdatedAt();
|
| 58 |
-
$this->_product = Mage::getModel('marketingsoftware/abstraction_product')->setOriginal($original);
|
| 59 |
-
|
| 60 |
-
$options = Mage::getModel('marketingsoftware/abstraction_order_item_options')->setOriginal($original);
|
| 61 |
-
|
| 62 |
-
if ($options->attributes()) {
|
| 63 |
-
$this->_options = $options;
|
| 64 |
-
}
|
| 65 |
-
|
| 66 |
-
return $this;
|
| 67 |
-
}
|
| 68 |
-
|
| 69 |
-
/**
|
| 70 |
-
* The id of this order item object
|
| 71 |
-
*
|
| 72 |
-
* @return integer
|
| 73 |
-
*/
|
| 74 |
-
public function id()
|
| 75 |
-
{
|
| 76 |
-
return $this->_id;
|
| 77 |
-
}
|
| 78 |
-
|
| 79 |
-
/**
|
| 80 |
-
* Get the order to which this item belongs
|
| 81 |
-
*
|
| 82 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Order
|
| 83 |
-
*/
|
| 84 |
-
public function order()
|
| 85 |
-
{
|
| 86 |
-
return Mage::getModel('marketingsoftware/abstraction_order')->loadOrder($this->_orderId);
|
| 87 |
-
}
|
| 88 |
-
|
| 89 |
-
/**
|
| 90 |
-
* The amount of this order item
|
| 91 |
-
*
|
| 92 |
-
* @return integer
|
| 93 |
-
*/
|
| 94 |
-
public function quantity()
|
| 95 |
-
{
|
| 96 |
-
return $this->_quantity;
|
| 97 |
-
}
|
| 98 |
-
|
| 99 |
-
/**
|
| 100 |
-
* The price
|
| 101 |
-
* Note that an object is returned, which may consist of multiple components
|
| 102 |
-
*
|
| 103 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Price
|
| 104 |
-
*/
|
| 105 |
-
public function price()
|
| 106 |
-
{
|
| 107 |
-
return $this->_price;
|
| 108 |
-
}
|
| 109 |
-
|
| 110 |
-
/**
|
| 111 |
-
* The weight
|
| 112 |
-
*
|
| 113 |
-
* @return float
|
| 114 |
-
*/
|
| 115 |
-
public function weight()
|
| 116 |
-
{
|
| 117 |
-
return $this->_weight;
|
| 118 |
-
}
|
| 119 |
-
|
| 120 |
-
/**
|
| 121 |
-
* The timestamp at which this order was modified
|
| 122 |
-
*
|
| 123 |
-
* @return string
|
| 124 |
-
*/
|
| 125 |
-
public function timestamp()
|
| 126 |
-
{
|
| 127 |
-
return $this->_timestamp;
|
| 128 |
-
}
|
| 129 |
-
|
| 130 |
-
/**
|
| 131 |
-
* Get the options of this order item
|
| 132 |
-
*
|
| 133 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Order_Item_Options
|
| 134 |
-
*/
|
| 135 |
-
public function options()
|
| 136 |
-
{
|
| 137 |
-
return $this->_options;
|
| 138 |
-
}
|
| 139 |
-
|
| 140 |
-
/**
|
| 141 |
-
* Get the product which belongs to this item
|
| 142 |
-
*
|
| 143 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Product
|
| 144 |
-
*/
|
| 145 |
-
public function product()
|
| 146 |
-
{
|
| 147 |
-
return $this->_product;
|
| 148 |
-
}
|
| 149 |
-
|
| 150 |
-
/**
|
| 151 |
-
* Serialize the object
|
| 152 |
-
*
|
| 153 |
-
* @return string
|
| 154 |
-
*/
|
| 155 |
-
public function serialize()
|
| 156 |
-
{
|
| 157 |
-
return serialize(array(
|
| 158 |
-
$this->_id(),
|
| 159 |
-
is_object($order = $this->order()) ? $order->id() : null,
|
| 160 |
-
$this->_quantity(),
|
| 161 |
-
$this->_price(),
|
| 162 |
-
$this->_weight(),
|
| 163 |
-
$this->_timestamp(),
|
| 164 |
-
$this->_options(),
|
| 165 |
-
$this->_product(),
|
| 166 |
-
));
|
| 167 |
-
}
|
| 168 |
-
|
| 169 |
-
/**
|
| 170 |
-
* Unserialize the object
|
| 171 |
-
*
|
| 172 |
-
* @param string $string
|
| 173 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Order_Item
|
| 174 |
-
*/
|
| 175 |
-
public function unserialize($string)
|
| 176 |
-
{
|
| 177 |
-
list(
|
| 178 |
-
$this->_id,
|
| 179 |
-
$this->_orderId,
|
| 180 |
-
$this->_quantity,
|
| 181 |
-
$this->_price,
|
| 182 |
-
$this->_weight,
|
| 183 |
-
$this->_timestamp,
|
| 184 |
-
$this->_options,
|
| 185 |
-
$this->_product
|
| 186 |
-
) = unserialize($string);
|
| 187 |
-
|
| 188 |
-
return $this;
|
| 189 |
-
}
|
| 190 |
-
}
|
| 191 |
-
|
| 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 Order Item
|
| 29 |
+
*/
|
| 30 |
+
class Copernica_MarketingSoftware_Model_Abstraction_Order_Item implements Serializable
|
| 31 |
+
{
|
| 32 |
+
/**
|
| 33 |
+
* Predefine the internal fields
|
| 34 |
+
*/
|
| 35 |
+
protected $_id;
|
| 36 |
+
protected $_orderId;
|
| 37 |
+
protected $_quantity;
|
| 38 |
+
protected $_price;
|
| 39 |
+
protected $_weight;
|
| 40 |
+
protected $_timestamp;
|
| 41 |
+
protected $_options;
|
| 42 |
+
protected $_product;
|
| 43 |
+
|
| 44 |
+
/**
|
| 45 |
+
* Sets the original model
|
| 46 |
+
*
|
| 47 |
+
* @param Mage_Sales_Model_Order_Item $original
|
| 48 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Order_Item
|
| 49 |
+
*/
|
| 50 |
+
public function setOriginal(Mage_Sales_Model_Order_Item $original)
|
| 51 |
+
{
|
| 52 |
+
$this->_id = $original->getId();
|
| 53 |
+
$this->_orderId = $original->getOrder()->getId();
|
| 54 |
+
$this->_quantity = $original->getQtyOrdered();
|
| 55 |
+
$this->_price = Mage::getModel('marketingsoftware/abstraction_price')->setOriginal($original);
|
| 56 |
+
$this->_weight = $original->getWeight();
|
| 57 |
+
$this->_timestamp = $original->getUpdatedAt();
|
| 58 |
+
$this->_product = Mage::getModel('marketingsoftware/abstraction_product')->setOriginal($original);
|
| 59 |
+
|
| 60 |
+
$options = Mage::getModel('marketingsoftware/abstraction_order_item_options')->setOriginal($original);
|
| 61 |
+
|
| 62 |
+
if ($options->attributes()) {
|
| 63 |
+
$this->_options = $options;
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
return $this;
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
/**
|
| 70 |
+
* The id of this order item object
|
| 71 |
+
*
|
| 72 |
+
* @return integer
|
| 73 |
+
*/
|
| 74 |
+
public function id()
|
| 75 |
+
{
|
| 76 |
+
return $this->_id;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
/**
|
| 80 |
+
* Get the order to which this item belongs
|
| 81 |
+
*
|
| 82 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Order
|
| 83 |
+
*/
|
| 84 |
+
public function order()
|
| 85 |
+
{
|
| 86 |
+
return Mage::getModel('marketingsoftware/abstraction_order')->loadOrder($this->_orderId);
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
/**
|
| 90 |
+
* The amount of this order item
|
| 91 |
+
*
|
| 92 |
+
* @return integer
|
| 93 |
+
*/
|
| 94 |
+
public function quantity()
|
| 95 |
+
{
|
| 96 |
+
return $this->_quantity;
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
/**
|
| 100 |
+
* The price
|
| 101 |
+
* Note that an object is returned, which may consist of multiple components
|
| 102 |
+
*
|
| 103 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Price
|
| 104 |
+
*/
|
| 105 |
+
public function price()
|
| 106 |
+
{
|
| 107 |
+
return $this->_price;
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
/**
|
| 111 |
+
* The weight
|
| 112 |
+
*
|
| 113 |
+
* @return float
|
| 114 |
+
*/
|
| 115 |
+
public function weight()
|
| 116 |
+
{
|
| 117 |
+
return $this->_weight;
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
/**
|
| 121 |
+
* The timestamp at which this order was modified
|
| 122 |
+
*
|
| 123 |
+
* @return string
|
| 124 |
+
*/
|
| 125 |
+
public function timestamp()
|
| 126 |
+
{
|
| 127 |
+
return $this->_timestamp;
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
/**
|
| 131 |
+
* Get the options of this order item
|
| 132 |
+
*
|
| 133 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Order_Item_Options
|
| 134 |
+
*/
|
| 135 |
+
public function options()
|
| 136 |
+
{
|
| 137 |
+
return $this->_options;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
/**
|
| 141 |
+
* Get the product which belongs to this item
|
| 142 |
+
*
|
| 143 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Product
|
| 144 |
+
*/
|
| 145 |
+
public function product()
|
| 146 |
+
{
|
| 147 |
+
return $this->_product;
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
/**
|
| 151 |
+
* Serialize the object
|
| 152 |
+
*
|
| 153 |
+
* @return string
|
| 154 |
+
*/
|
| 155 |
+
public function serialize()
|
| 156 |
+
{
|
| 157 |
+
return serialize(array(
|
| 158 |
+
$this->_id(),
|
| 159 |
+
is_object($order = $this->order()) ? $order->id() : null,
|
| 160 |
+
$this->_quantity(),
|
| 161 |
+
$this->_price(),
|
| 162 |
+
$this->_weight(),
|
| 163 |
+
$this->_timestamp(),
|
| 164 |
+
$this->_options(),
|
| 165 |
+
$this->_product(),
|
| 166 |
+
));
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
/**
|
| 170 |
+
* Unserialize the object
|
| 171 |
+
*
|
| 172 |
+
* @param string $string
|
| 173 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Order_Item
|
| 174 |
+
*/
|
| 175 |
+
public function unserialize($string)
|
| 176 |
+
{
|
| 177 |
+
list(
|
| 178 |
+
$this->_id,
|
| 179 |
+
$this->_orderId,
|
| 180 |
+
$this->_quantity,
|
| 181 |
+
$this->_price,
|
| 182 |
+
$this->_weight,
|
| 183 |
+
$this->_timestamp,
|
| 184 |
+
$this->_options,
|
| 185 |
+
$this->_product
|
| 186 |
+
) = unserialize($string);
|
| 187 |
+
|
| 188 |
+
return $this;
|
| 189 |
+
}
|
| 190 |
+
}
|
| 191 |
+
|
app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Order/Item/Options.php
CHANGED
|
@@ -1,157 +1,157 @@
|
|
| 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 order item options
|
| 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 |
-
/**
|
| 40 |
-
* Sets the original model
|
| 41 |
-
*
|
| 42 |
-
* @param Mage_Sales_Model_Order_Item $original
|
| 43 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Order_Item_Options
|
| 44 |
-
*/
|
| 45 |
-
public function setOriginal(Mage_Sales_Model_Order_Item $original)
|
| 46 |
-
{
|
| 47 |
-
$this->_name = $original->getName();
|
| 48 |
-
|
| 49 |
-
$attributes = array();
|
| 50 |
-
$data = array();
|
| 51 |
-
$options = $original->getProductOptions();
|
| 52 |
-
|
| 53 |
-
if (isset($options['attributes_info'])) {
|
| 54 |
-
$attributes = $options['attributes_info'];
|
| 55 |
-
} elseif (isset($options['bundle_options'])) {
|
| 56 |
-
$attributes = $options['bundle_options'];
|
| 57 |
-
} elseif (isset($options['options'])) {
|
| 58 |
-
$attributes = $options['options'];
|
| 59 |
-
}
|
| 60 |
-
|
| 61 |
-
if ($attributes) {
|
| 62 |
-
foreach ($attributes as $attribute) {
|
| 63 |
-
$data[$attribute['label']] = $attribute['value'];
|
| 64 |
-
}
|
| 65 |
-
|
| 66 |
-
$this->_attributes = $data;
|
| 67 |
-
}
|
| 68 |
-
|
| 69 |
-
return $this;
|
| 70 |
-
}
|
| 71 |
-
|
| 72 |
-
/**
|
| 73 |
-
* The name of this order item
|
| 74 |
-
*
|
| 75 |
-
* @return integer
|
| 76 |
-
*/
|
| 77 |
-
public function name()
|
| 78 |
-
{
|
| 79 |
-
return $this->_name;
|
| 80 |
-
}
|
| 81 |
-
|
| 82 |
-
/**
|
| 83 |
-
* Return an assoc array with attributes
|
| 84 |
-
*
|
| 85 |
-
* @return array
|
| 86 |
-
*/
|
| 87 |
-
public function attributes()
|
| 88 |
-
{
|
| 89 |
-
return $this->_attributes;
|
| 90 |
-
}
|
| 91 |
-
|
| 92 |
-
/**
|
| 93 |
-
* Return a string representation
|
| 94 |
-
*
|
| 95 |
-
* @return string
|
| 96 |
-
*/
|
| 97 |
-
public function __toString()
|
| 98 |
-
{
|
| 99 |
-
return $this->_arrayToString($this->_attributes());
|
| 100 |
-
}
|
| 101 |
-
|
| 102 |
-
/**
|
| 103 |
-
* Return a string representation of an array
|
| 104 |
-
*
|
| 105 |
-
* @param array $value
|
| 106 |
-
* @param string $prefix
|
| 107 |
-
* @return string
|
| 108 |
-
*/
|
| 109 |
-
protected function _arrayToString($value, $prefix = '')
|
| 110 |
-
{
|
| 111 |
-
$string = "";
|
| 112 |
-
|
| 113 |
-
foreach ($value as $key => $value) {
|
| 114 |
-
if (is_array($value)) {
|
| 115 |
-
if (isset($value[0]) && count($value) == 1) {
|
| 116 |
-
$value = $value[0];
|
| 117 |
-
}
|
| 118 |
-
|
| 119 |
-
$string .= $prefix.$key.":\n".$this->_arrayToString($value, $prefix.' ');
|
| 120 |
-
} else {
|
| 121 |
-
$string.= $prefix.$key.": $value\n";
|
| 122 |
-
}
|
| 123 |
-
}
|
| 124 |
-
|
| 125 |
-
return $string;
|
| 126 |
-
}
|
| 127 |
-
|
| 128 |
-
/**
|
| 129 |
-
* Serialize the object
|
| 130 |
-
*
|
| 131 |
-
* @return string
|
| 132 |
-
*/
|
| 133 |
-
public function serialize()
|
| 134 |
-
{
|
| 135 |
-
return serialize(array(
|
| 136 |
-
$this->_name(),
|
| 137 |
-
$this->_attributes(),
|
| 138 |
-
));
|
| 139 |
-
}
|
| 140 |
-
|
| 141 |
-
/**
|
| 142 |
-
* Unserialize the object
|
| 143 |
-
*
|
| 144 |
-
* @param string $string
|
| 145 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Order_Item_Options
|
| 146 |
-
*/
|
| 147 |
-
public function unserialize($string)
|
| 148 |
-
{
|
| 149 |
-
list(
|
| 150 |
-
$this->_name,
|
| 151 |
-
$this->_attributes
|
| 152 |
-
) = unserialize($string);
|
| 153 |
-
|
| 154 |
-
return $this;
|
| 155 |
-
}
|
| 156 |
-
}
|
| 157 |
-
|
| 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 order item options
|
| 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 |
+
/**
|
| 40 |
+
* Sets the original model
|
| 41 |
+
*
|
| 42 |
+
* @param Mage_Sales_Model_Order_Item $original
|
| 43 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Order_Item_Options
|
| 44 |
+
*/
|
| 45 |
+
public function setOriginal(Mage_Sales_Model_Order_Item $original)
|
| 46 |
+
{
|
| 47 |
+
$this->_name = $original->getName();
|
| 48 |
+
|
| 49 |
+
$attributes = array();
|
| 50 |
+
$data = array();
|
| 51 |
+
$options = $original->getProductOptions();
|
| 52 |
+
|
| 53 |
+
if (isset($options['attributes_info'])) {
|
| 54 |
+
$attributes = $options['attributes_info'];
|
| 55 |
+
} elseif (isset($options['bundle_options'])) {
|
| 56 |
+
$attributes = $options['bundle_options'];
|
| 57 |
+
} elseif (isset($options['options'])) {
|
| 58 |
+
$attributes = $options['options'];
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
if ($attributes) {
|
| 62 |
+
foreach ($attributes as $attribute) {
|
| 63 |
+
$data[$attribute['label']] = $attribute['value'];
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
$this->_attributes = $data;
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
return $this;
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
/**
|
| 73 |
+
* The name of this order item
|
| 74 |
+
*
|
| 75 |
+
* @return integer
|
| 76 |
+
*/
|
| 77 |
+
public function name()
|
| 78 |
+
{
|
| 79 |
+
return $this->_name;
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
/**
|
| 83 |
+
* Return an assoc array with attributes
|
| 84 |
+
*
|
| 85 |
+
* @return array
|
| 86 |
+
*/
|
| 87 |
+
public function attributes()
|
| 88 |
+
{
|
| 89 |
+
return $this->_attributes;
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
/**
|
| 93 |
+
* Return a string representation
|
| 94 |
+
*
|
| 95 |
+
* @return string
|
| 96 |
+
*/
|
| 97 |
+
public function __toString()
|
| 98 |
+
{
|
| 99 |
+
return $this->_arrayToString($this->_attributes());
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
/**
|
| 103 |
+
* Return a string representation of an array
|
| 104 |
+
*
|
| 105 |
+
* @param array $value
|
| 106 |
+
* @param string $prefix
|
| 107 |
+
* @return string
|
| 108 |
+
*/
|
| 109 |
+
protected function _arrayToString($value, $prefix = '')
|
| 110 |
+
{
|
| 111 |
+
$string = "";
|
| 112 |
+
|
| 113 |
+
foreach ($value as $key => $value) {
|
| 114 |
+
if (is_array($value)) {
|
| 115 |
+
if (isset($value[0]) && count($value) == 1) {
|
| 116 |
+
$value = $value[0];
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
$string .= $prefix.$key.":\n".$this->_arrayToString($value, $prefix.' ');
|
| 120 |
+
} else {
|
| 121 |
+
$string.= $prefix.$key.": $value\n";
|
| 122 |
+
}
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
return $string;
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
/**
|
| 129 |
+
* Serialize the object
|
| 130 |
+
*
|
| 131 |
+
* @return string
|
| 132 |
+
*/
|
| 133 |
+
public function serialize()
|
| 134 |
+
{
|
| 135 |
+
return serialize(array(
|
| 136 |
+
$this->_name(),
|
| 137 |
+
$this->_attributes(),
|
| 138 |
+
));
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
/**
|
| 142 |
+
* Unserialize the object
|
| 143 |
+
*
|
| 144 |
+
* @param string $string
|
| 145 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Order_Item_Options
|
| 146 |
+
*/
|
| 147 |
+
public function unserialize($string)
|
| 148 |
+
{
|
| 149 |
+
list(
|
| 150 |
+
$this->_name,
|
| 151 |
+
$this->_attributes
|
| 152 |
+
) = unserialize($string);
|
| 153 |
+
|
| 154 |
+
return $this;
|
| 155 |
+
}
|
| 156 |
+
}
|
| 157 |
+
|
app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Price.php
CHANGED
|
@@ -1,248 +1,248 @@
|
|
| 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 price
|
| 29 |
-
* This is not representing a magento object
|
| 30 |
-
* Note that the price can consist of a lot of components:
|
| 31 |
-
* - price
|
| 32 |
-
* - shippingcost
|
| 33 |
-
* - discount
|
| 34 |
-
* - additional_fees (is a list of custom configurable fees)
|
| 35 |
-
* - tax
|
| 36 |
-
* - total_price
|
| 37 |
-
*/
|
| 38 |
-
class Copernica_MarketingSoftware_Model_Abstraction_Price implements Serializable
|
| 39 |
-
{
|
| 40 |
-
/**
|
| 41 |
-
* Predefine the internal fields
|
| 42 |
-
*/
|
| 43 |
-
protected $_total;
|
| 44 |
-
protected $_costs;
|
| 45 |
-
protected $_itemPrice;
|
| 46 |
-
protected $_originalPrice;
|
| 47 |
-
protected $_discount;
|
| 48 |
-
protected $_tax;
|
| 49 |
-
protected $_shipping;
|
| 50 |
-
protected $_currency;
|
| 51 |
-
|
| 52 |
-
/**
|
| 53 |
-
* Sets the original model
|
| 54 |
-
*
|
| 55 |
-
* @param Mage_Sales_Model_Quote|Mage_Sales_Model_Order|Mage_Sales_Model_Quote_Item|Mage_Sales_Model_Order_Item $original
|
| 56 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Price
|
| 57 |
-
*/
|
| 58 |
-
public function setOriginal($original)
|
| 59 |
-
{
|
| 60 |
-
if ($grandTotal = $original->getGrandTotal()) {
|
| 61 |
-
$this->_total = $grandTotal;
|
| 62 |
-
} elseif ($rowTotalInclTax = $original->getRowTotalInclTax()) {
|
| 63 |
-
$this->_total = $rowTotalInclTax;
|
| 64 |
-
} elseif ($baseRowTotal = $original->getBaseRowTotal()) {
|
| 65 |
-
$this->_total = $baseRowTotal;
|
| 66 |
-
}
|
| 67 |
-
|
| 68 |
-
if ($original instanceOf Mage_Sales_Model_Quote || $original instanceOf Mage_Sales_Model_Order) {
|
| 69 |
-
$costs = 0;
|
| 70 |
-
|
| 71 |
-
foreach ($original->getAllVisibleItems() as $item) {
|
| 72 |
-
$costs += $item->getBaseCost();
|
| 73 |
-
}
|
| 74 |
-
|
| 75 |
-
$this->_costs = $costs;
|
| 76 |
-
} elseif ($baseCost = $original->getBaseCost()) {
|
| 77 |
-
$this->_costs = $baseCost;
|
| 78 |
-
}
|
| 79 |
-
|
| 80 |
-
if ($original instanceOf Mage_Sales_Model_Quote || $original instanceOf Mage_Sales_Model_Order) {
|
| 81 |
-
$this->_itemPrice = 0;
|
| 82 |
-
} elseif ($price = $original->getPrice()) {
|
| 83 |
-
$this->_itemPrice = $price;
|
| 84 |
-
}
|
| 85 |
-
|
| 86 |
-
if ($original instanceOf Mage_Sales_Model_Quote || $original instanceOf Mage_Sales_Model_Order) {
|
| 87 |
-
$this->_originalPrice = 0;
|
| 88 |
-
} elseif ($original instanceOf Mage_Sales_Model_Quote_Item) {
|
| 89 |
-
$this->_originalPrice = 0;
|
| 90 |
-
} elseif ($originalPrice = $original->getOriginalPrice()) {
|
| 91 |
-
$this->_originalPrice = $originalPrice;
|
| 92 |
-
}
|
| 93 |
-
|
| 94 |
-
if ($discountAmount = $original->getDiscountAmount()) {
|
| 95 |
-
$this->_discount = $discountAmount;
|
| 96 |
-
}
|
| 97 |
-
|
| 98 |
-
if ($taxAmount = $original->getTaxAmount()) {
|
| 99 |
-
$this->_tax = $taxAmount;
|
| 100 |
-
}
|
| 101 |
-
|
| 102 |
-
if ($original instanceOf Mage_Sales_Model_Quote || $original instanceOf Mage_Sales_Model_Order) {
|
| 103 |
-
if ($shippingAmount = $original->getShippingAmount()) {
|
| 104 |
-
$this->_shipping = $shippingAmount;
|
| 105 |
-
} else {
|
| 106 |
-
$this->_shipping = 0;
|
| 107 |
-
}
|
| 108 |
-
} else {
|
| 109 |
-
$this->_shipping = 0;
|
| 110 |
-
}
|
| 111 |
-
|
| 112 |
-
if ($currency = $original->getOrderCurrencyCode()) {
|
| 113 |
-
$this->_currency = $currency;
|
| 114 |
-
} elseif ($currency = $original->getQuoteCurrencyCode()) {
|
| 115 |
-
$this->_currency = $currency;
|
| 116 |
-
} elseif (($order = $original->getOrder()) && ($currency = $order->getOrderCurrencyCode())) {
|
| 117 |
-
$this->_currency = $currency;
|
| 118 |
-
} elseif (($quote = $original->getQuote()) && ($currency = $quote->getQuoteCurrencyCode())) {
|
| 119 |
-
$this->_currency = $currency;
|
| 120 |
-
} else {
|
| 121 |
-
$this->_currency = '';
|
| 122 |
-
}
|
| 123 |
-
|
| 124 |
-
return $this;
|
| 125 |
-
}
|
| 126 |
-
|
| 127 |
-
/**
|
| 128 |
-
* Return the total price
|
| 129 |
-
*
|
| 130 |
-
* @return float
|
| 131 |
-
*/
|
| 132 |
-
public function total()
|
| 133 |
-
{
|
| 134 |
-
return $this->_total;
|
| 135 |
-
}
|
| 136 |
-
|
| 137 |
-
/**
|
| 138 |
-
* Return the price for the individual item
|
| 139 |
-
*
|
| 140 |
-
* @return float
|
| 141 |
-
*/
|
| 142 |
-
public function costs()
|
| 143 |
-
{
|
| 144 |
-
return $this->_costs;
|
| 145 |
-
}
|
| 146 |
-
|
| 147 |
-
/**
|
| 148 |
-
* Return the price for the individual item
|
| 149 |
-
*
|
| 150 |
-
* @return float
|
| 151 |
-
*/
|
| 152 |
-
public function itemPrice()
|
| 153 |
-
{
|
| 154 |
-
return $this->_itemPrice;
|
| 155 |
-
}
|
| 156 |
-
|
| 157 |
-
/**
|
| 158 |
-
* Return the original price for the individual item
|
| 159 |
-
*
|
| 160 |
-
* @return float
|
| 161 |
-
*/
|
| 162 |
-
public function originalPrice()
|
| 163 |
-
{
|
| 164 |
-
return $this->_originalPrice;
|
| 165 |
-
}
|
| 166 |
-
|
| 167 |
-
/**
|
| 168 |
-
* Return the discount which was given
|
| 169 |
-
*
|
| 170 |
-
* @return float
|
| 171 |
-
*/
|
| 172 |
-
public function discount()
|
| 173 |
-
{
|
| 174 |
-
return $this->_discount;
|
| 175 |
-
}
|
| 176 |
-
|
| 177 |
-
/**
|
| 178 |
-
* Return the tax which was paid
|
| 179 |
-
*
|
| 180 |
-
* @return float
|
| 181 |
-
*/
|
| 182 |
-
public function tax()
|
| 183 |
-
{
|
| 184 |
-
return $this->_tax;
|
| 185 |
-
}
|
| 186 |
-
|
| 187 |
-
/**
|
| 188 |
-
* Return the shipping costs
|
| 189 |
-
*
|
| 190 |
-
* @return float
|
| 191 |
-
*/
|
| 192 |
-
public function shipping()
|
| 193 |
-
{
|
| 194 |
-
return $this->_shipping;
|
| 195 |
-
}
|
| 196 |
-
|
| 197 |
-
/**
|
| 198 |
-
* Return the currency code
|
| 199 |
-
*
|
| 200 |
-
* @return float
|
| 201 |
-
*/
|
| 202 |
-
public function currency()
|
| 203 |
-
{
|
| 204 |
-
return $this->_currency;
|
| 205 |
-
}
|
| 206 |
-
|
| 207 |
-
/**
|
| 208 |
-
* Serialize the object
|
| 209 |
-
*
|
| 210 |
-
* @return string
|
| 211 |
-
*/
|
| 212 |
-
public function serialize()
|
| 213 |
-
{
|
| 214 |
-
return serialize(array(
|
| 215 |
-
$this->total(),
|
| 216 |
-
$this->costs(),
|
| 217 |
-
$this->itemPrice(),
|
| 218 |
-
$this->originalPrice(),
|
| 219 |
-
$this->discount(),
|
| 220 |
-
$this->tax(),
|
| 221 |
-
$this->shipping(),
|
| 222 |
-
$this->currency(),
|
| 223 |
-
));
|
| 224 |
-
}
|
| 225 |
-
|
| 226 |
-
/**
|
| 227 |
-
* Unserialize the object
|
| 228 |
-
*
|
| 229 |
-
* @param string $string
|
| 230 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Price
|
| 231 |
-
*/
|
| 232 |
-
public function unserialize($string)
|
| 233 |
-
{
|
| 234 |
-
list(
|
| 235 |
-
$this->_total,
|
| 236 |
-
$this->_costs,
|
| 237 |
-
$this->_itemPrice,
|
| 238 |
-
$this->_originalPrice,
|
| 239 |
-
$this->_discount,
|
| 240 |
-
$this->_tax,
|
| 241 |
-
$this->_shipping,
|
| 242 |
-
$this->_currency
|
| 243 |
-
) = unserialize($string);
|
| 244 |
-
|
| 245 |
-
return $this;
|
| 246 |
-
}
|
| 247 |
-
}
|
| 248 |
-
|
| 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 price
|
| 29 |
+
* This is not representing a magento object
|
| 30 |
+
* Note that the price can consist of a lot of components:
|
| 31 |
+
* - price
|
| 32 |
+
* - shippingcost
|
| 33 |
+
* - discount
|
| 34 |
+
* - additional_fees (is a list of custom configurable fees)
|
| 35 |
+
* - tax
|
| 36 |
+
* - total_price
|
| 37 |
+
*/
|
| 38 |
+
class Copernica_MarketingSoftware_Model_Abstraction_Price implements Serializable
|
| 39 |
+
{
|
| 40 |
+
/**
|
| 41 |
+
* Predefine the internal fields
|
| 42 |
+
*/
|
| 43 |
+
protected $_total;
|
| 44 |
+
protected $_costs;
|
| 45 |
+
protected $_itemPrice;
|
| 46 |
+
protected $_originalPrice;
|
| 47 |
+
protected $_discount;
|
| 48 |
+
protected $_tax;
|
| 49 |
+
protected $_shipping;
|
| 50 |
+
protected $_currency;
|
| 51 |
+
|
| 52 |
+
/**
|
| 53 |
+
* Sets the original model
|
| 54 |
+
*
|
| 55 |
+
* @param Mage_Sales_Model_Quote|Mage_Sales_Model_Order|Mage_Sales_Model_Quote_Item|Mage_Sales_Model_Order_Item $original
|
| 56 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Price
|
| 57 |
+
*/
|
| 58 |
+
public function setOriginal($original)
|
| 59 |
+
{
|
| 60 |
+
if ($grandTotal = $original->getGrandTotal()) {
|
| 61 |
+
$this->_total = $grandTotal;
|
| 62 |
+
} elseif ($rowTotalInclTax = $original->getRowTotalInclTax()) {
|
| 63 |
+
$this->_total = $rowTotalInclTax;
|
| 64 |
+
} elseif ($baseRowTotal = $original->getBaseRowTotal()) {
|
| 65 |
+
$this->_total = $baseRowTotal;
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
if ($original instanceOf Mage_Sales_Model_Quote || $original instanceOf Mage_Sales_Model_Order) {
|
| 69 |
+
$costs = 0;
|
| 70 |
+
|
| 71 |
+
foreach ($original->getAllVisibleItems() as $item) {
|
| 72 |
+
$costs += $item->getBaseCost();
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
$this->_costs = $costs;
|
| 76 |
+
} elseif ($baseCost = $original->getBaseCost()) {
|
| 77 |
+
$this->_costs = $baseCost;
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
if ($original instanceOf Mage_Sales_Model_Quote || $original instanceOf Mage_Sales_Model_Order) {
|
| 81 |
+
$this->_itemPrice = 0;
|
| 82 |
+
} elseif ($price = $original->getPrice()) {
|
| 83 |
+
$this->_itemPrice = $price;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
if ($original instanceOf Mage_Sales_Model_Quote || $original instanceOf Mage_Sales_Model_Order) {
|
| 87 |
+
$this->_originalPrice = 0;
|
| 88 |
+
} elseif ($original instanceOf Mage_Sales_Model_Quote_Item) {
|
| 89 |
+
$this->_originalPrice = 0;
|
| 90 |
+
} elseif ($originalPrice = $original->getOriginalPrice()) {
|
| 91 |
+
$this->_originalPrice = $originalPrice;
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
if ($discountAmount = $original->getDiscountAmount()) {
|
| 95 |
+
$this->_discount = $discountAmount;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
if ($taxAmount = $original->getTaxAmount()) {
|
| 99 |
+
$this->_tax = $taxAmount;
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
if ($original instanceOf Mage_Sales_Model_Quote || $original instanceOf Mage_Sales_Model_Order) {
|
| 103 |
+
if ($shippingAmount = $original->getShippingAmount()) {
|
| 104 |
+
$this->_shipping = $shippingAmount;
|
| 105 |
+
} else {
|
| 106 |
+
$this->_shipping = 0;
|
| 107 |
+
}
|
| 108 |
+
} else {
|
| 109 |
+
$this->_shipping = 0;
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
if ($currency = $original->getOrderCurrencyCode()) {
|
| 113 |
+
$this->_currency = $currency;
|
| 114 |
+
} elseif ($currency = $original->getQuoteCurrencyCode()) {
|
| 115 |
+
$this->_currency = $currency;
|
| 116 |
+
} elseif (($order = $original->getOrder()) && ($currency = $order->getOrderCurrencyCode())) {
|
| 117 |
+
$this->_currency = $currency;
|
| 118 |
+
} elseif (($quote = $original->getQuote()) && ($currency = $quote->getQuoteCurrencyCode())) {
|
| 119 |
+
$this->_currency = $currency;
|
| 120 |
+
} else {
|
| 121 |
+
$this->_currency = '';
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
return $this;
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
/**
|
| 128 |
+
* Return the total price
|
| 129 |
+
*
|
| 130 |
+
* @return float
|
| 131 |
+
*/
|
| 132 |
+
public function total()
|
| 133 |
+
{
|
| 134 |
+
return $this->_total;
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
/**
|
| 138 |
+
* Return the price for the individual item
|
| 139 |
+
*
|
| 140 |
+
* @return float
|
| 141 |
+
*/
|
| 142 |
+
public function costs()
|
| 143 |
+
{
|
| 144 |
+
return $this->_costs;
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
/**
|
| 148 |
+
* Return the price for the individual item
|
| 149 |
+
*
|
| 150 |
+
* @return float
|
| 151 |
+
*/
|
| 152 |
+
public function itemPrice()
|
| 153 |
+
{
|
| 154 |
+
return $this->_itemPrice;
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
/**
|
| 158 |
+
* Return the original price for the individual item
|
| 159 |
+
*
|
| 160 |
+
* @return float
|
| 161 |
+
*/
|
| 162 |
+
public function originalPrice()
|
| 163 |
+
{
|
| 164 |
+
return $this->_originalPrice;
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
/**
|
| 168 |
+
* Return the discount which was given
|
| 169 |
+
*
|
| 170 |
+
* @return float
|
| 171 |
+
*/
|
| 172 |
+
public function discount()
|
| 173 |
+
{
|
| 174 |
+
return $this->_discount;
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
/**
|
| 178 |
+
* Return the tax which was paid
|
| 179 |
+
*
|
| 180 |
+
* @return float
|
| 181 |
+
*/
|
| 182 |
+
public function tax()
|
| 183 |
+
{
|
| 184 |
+
return $this->_tax;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
/**
|
| 188 |
+
* Return the shipping costs
|
| 189 |
+
*
|
| 190 |
+
* @return float
|
| 191 |
+
*/
|
| 192 |
+
public function shipping()
|
| 193 |
+
{
|
| 194 |
+
return $this->_shipping;
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
/**
|
| 198 |
+
* Return the currency code
|
| 199 |
+
*
|
| 200 |
+
* @return float
|
| 201 |
+
*/
|
| 202 |
+
public function currency()
|
| 203 |
+
{
|
| 204 |
+
return $this->_currency;
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
/**
|
| 208 |
+
* Serialize the object
|
| 209 |
+
*
|
| 210 |
+
* @return string
|
| 211 |
+
*/
|
| 212 |
+
public function serialize()
|
| 213 |
+
{
|
| 214 |
+
return serialize(array(
|
| 215 |
+
$this->total(),
|
| 216 |
+
$this->costs(),
|
| 217 |
+
$this->itemPrice(),
|
| 218 |
+
$this->originalPrice(),
|
| 219 |
+
$this->discount(),
|
| 220 |
+
$this->tax(),
|
| 221 |
+
$this->shipping(),
|
| 222 |
+
$this->currency(),
|
| 223 |
+
));
|
| 224 |
+
}
|
| 225 |
+
|
| 226 |
+
/**
|
| 227 |
+
* Unserialize the object
|
| 228 |
+
*
|
| 229 |
+
* @param string $string
|
| 230 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Price
|
| 231 |
+
*/
|
| 232 |
+
public function unserialize($string)
|
| 233 |
+
{
|
| 234 |
+
list(
|
| 235 |
+
$this->_total,
|
| 236 |
+
$this->_costs,
|
| 237 |
+
$this->_itemPrice,
|
| 238 |
+
$this->_originalPrice,
|
| 239 |
+
$this->_discount,
|
| 240 |
+
$this->_tax,
|
| 241 |
+
$this->_shipping,
|
| 242 |
+
$this->_currency
|
| 243 |
+
) = unserialize($string);
|
| 244 |
+
|
| 245 |
+
return $this;
|
| 246 |
+
}
|
| 247 |
+
}
|
| 248 |
+
|
app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Product.php
CHANGED
|
@@ -1,333 +1,333 @@
|
|
| 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_Product implements Serializable
|
| 31 |
-
{
|
| 32 |
-
/**
|
| 33 |
-
* The original object
|
| 34 |
-
*
|
| 35 |
-
* @todo Not used???
|
| 36 |
-
* @var Mage_Catalog_Model_Product|Mage_Sales_Model_Quote_Item|Mage_Sales_Model_Order_Item
|
| 37 |
-
*/
|
| 38 |
-
protected $_original;
|
| 39 |
-
|
| 40 |
-
/**
|
| 41 |
-
* Predefine the internal fields
|
| 42 |
-
*/
|
| 43 |
-
protected $_id;
|
| 44 |
-
protected $_sku;
|
| 45 |
-
protected $_name;
|
| 46 |
-
protected $_description;
|
| 47 |
-
protected $_productUrl = '';
|
| 48 |
-
protected $_imagePath = '';
|
| 49 |
-
protected $_weight;
|
| 50 |
-
protected $_categories = array();
|
| 51 |
-
protected $_price;
|
| 52 |
-
protected $_created = '';
|
| 53 |
-
protected $_modified = '';
|
| 54 |
-
protected $_attributes = '';
|
| 55 |
-
protected $_attributeSet = '';
|
| 56 |
-
|
| 57 |
-
/**
|
| 58 |
-
* Sets the original model
|
| 59 |
-
*
|
| 60 |
-
* @param Mage_Catalog_Model_Product|Mage_Sales_Model_Quote_Item|Mage_Sales_Model_Order_Item $original
|
| 61 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Product
|
| 62 |
-
*/
|
| 63 |
-
public function setOriginal($original)
|
| 64 |
-
{
|
| 65 |
-
if ($original instanceof Mage_Catalog_Model_Product) {
|
| 66 |
-
$this->_createFromProductModel($original);
|
| 67 |
-
} else {
|
| 68 |
-
$product = Mage::getModel('catalog/product')->load($original->getProductId());
|
| 69 |
-
|
| 70 |
-
if ($product->getID()) {
|
| 71 |
-
$this->_createFromProductModel($product);
|
| 72 |
-
} else {
|
| 73 |
-
$this->_id = $original->getProductId();
|
| 74 |
-
$this->_sku = $original->getSKU();
|
| 75 |
-
$this->_name = $original->getName();
|
| 76 |
-
$this->_description = $original->getDescription();
|
| 77 |
-
$this->_weight = $original->getWeight();
|
| 78 |
-
$this->_price = $original->getPrice();
|
| 79 |
-
}
|
| 80 |
-
}
|
| 81 |
-
|
| 82 |
-
return $this;
|
| 83 |
-
}
|
| 84 |
-
|
| 85 |
-
/**
|
| 86 |
-
* Create product from model.
|
| 87 |
-
*
|
| 88 |
-
* @param Mage_Catalog_Model_Product $model
|
| 89 |
-
*/
|
| 90 |
-
protected function _createFromProductModel(Mage_Catalog_Model_Product $model)
|
| 91 |
-
{
|
| 92 |
-
$this->_id = $model->getId();
|
| 93 |
-
$this->_sku = $model->getSku();
|
| 94 |
-
$this->_name = $model->getName();
|
| 95 |
-
$this->_description = $model->getShortDescription();
|
| 96 |
-
$this->_price = $model->getPrice();
|
| 97 |
-
$this->_created = $model->getCreatedAt();
|
| 98 |
-
$this->_modified = $model->getUpdatedAt();
|
| 99 |
-
$this->_productUrl = $model->getProductUrl();
|
| 100 |
-
$this->_imagePath = $model->getImageUrl();
|
| 101 |
-
$this->_weight = $model->getWeight();
|
| 102 |
-
|
| 103 |
-
$data = array();
|
| 104 |
-
|
| 105 |
-
$categoryIds = $model->getCategoryIds();
|
| 106 |
-
|
| 107 |
-
foreach ($categoryIds as $categoryId) {
|
| 108 |
-
$category = Mage::getModel('catalog/category')->load($categoryId);
|
| 109 |
-
|
| 110 |
-
$data[] = $this->_getFullCategoryName($category);
|
| 111 |
-
}
|
| 112 |
-
|
| 113 |
-
$this->_categories = $data;
|
| 114 |
-
|
| 115 |
-
$this->_attributes = Mage::getModel('marketingsoftware/abstraction_attributes')->setOriginal($model);
|
| 116 |
-
|
| 117 |
-
$attributeSetModel = Mage::getModel("eav/entity_attribute_set");
|
| 118 |
-
$attributeSetModel->load($model->getAttributeSetId());
|
| 119 |
-
|
| 120 |
-
$this->_attributeSet = $attributeSetModel->getAttributeSetName();
|
| 121 |
-
|
| 122 |
-
$this->timestamp = time();
|
| 123 |
-
}
|
| 124 |
-
|
| 125 |
-
/**
|
| 126 |
-
* Loads a product model
|
| 127 |
-
*
|
| 128 |
-
* @param integer $productId
|
| 129 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Product
|
| 130 |
-
*/
|
| 131 |
-
public function loadProduct($productId)
|
| 132 |
-
{
|
| 133 |
-
$product = Mage::getModel('catalog/product')->load($productId);
|
| 134 |
-
|
| 135 |
-
if ($product->getId()) {
|
| 136 |
-
$this->setOriginal($product);
|
| 137 |
-
} else {
|
| 138 |
-
$this->_id = $productId;
|
| 139 |
-
}
|
| 140 |
-
|
| 141 |
-
return $this;
|
| 142 |
-
}
|
| 143 |
-
|
| 144 |
-
/**
|
| 145 |
-
* Return the identifier for this object
|
| 146 |
-
*
|
| 147 |
-
* @return integer
|
| 148 |
-
*/
|
| 149 |
-
public function id()
|
| 150 |
-
{
|
| 151 |
-
return $this->_id;
|
| 152 |
-
}
|
| 153 |
-
|
| 154 |
-
/**
|
| 155 |
-
* Return the sku (stock keeping unit), which is an unique identifier
|
| 156 |
-
* for a magento product
|
| 157 |
-
*
|
| 158 |
-
* @return string
|
| 159 |
-
*/
|
| 160 |
-
public function sku()
|
| 161 |
-
{
|
| 162 |
-
return $this->_sku;
|
| 163 |
-
}
|
| 164 |
-
|
| 165 |
-
/**
|
| 166 |
-
* Return the name of this magento product
|
| 167 |
-
*
|
| 168 |
-
* @return string
|
| 169 |
-
*/
|
| 170 |
-
public function name()
|
| 171 |
-
{
|
| 172 |
-
return $this->_name;
|
| 173 |
-
}
|
| 174 |
-
|
| 175 |
-
/**
|
| 176 |
-
* Return the description of this magento product
|
| 177 |
-
*
|
| 178 |
-
* @return string
|
| 179 |
-
*/
|
| 180 |
-
public function description()
|
| 181 |
-
{
|
| 182 |
-
return $this->_description;
|
| 183 |
-
}
|
| 184 |
-
|
| 185 |
-
/**
|
| 186 |
-
* Return the price of this magento product
|
| 187 |
-
*
|
| 188 |
-
* @return string
|
| 189 |
-
*/
|
| 190 |
-
public function price()
|
| 191 |
-
{
|
| 192 |
-
return $this->_price;
|
| 193 |
-
}
|
| 194 |
-
|
| 195 |
-
/**
|
| 196 |
-
* Return the creation date of this magento product
|
| 197 |
-
*
|
| 198 |
-
* @return string
|
| 199 |
-
*/
|
| 200 |
-
public function created()
|
| 201 |
-
{
|
| 202 |
-
return $this->_created;
|
| 203 |
-
}
|
| 204 |
-
|
| 205 |
-
/**
|
| 206 |
-
* Return the modification date of this magento product
|
| 207 |
-
*
|
| 208 |
-
* @return string
|
| 209 |
-
*/
|
| 210 |
-
public function modified()
|
| 211 |
-
{
|
| 212 |
-
return $this->_modified;
|
| 213 |
-
}
|
| 214 |
-
|
| 215 |
-
/**
|
| 216 |
-
* Return the product url of this magento product
|
| 217 |
-
*
|
| 218 |
-
* @param integer $storeId
|
| 219 |
-
* @return string
|
| 220 |
-
*/
|
| 221 |
-
public function productUrl($storeId = null)
|
| 222 |
-
{
|
| 223 |
-
return $this->_productUrl;
|
| 224 |
-
}
|
| 225 |
-
|
| 226 |
-
/**
|
| 227 |
-
* Return the image url of this magento product
|
| 228 |
-
*
|
| 229 |
-
* @param integer $storeId
|
| 230 |
-
* @return string
|
| 231 |
-
*/
|
| 232 |
-
public function imageUrl($storeId = null)
|
| 233 |
-
{
|
| 234 |
-
return $this->_imagePath;
|
| 235 |
-
}
|
| 236 |
-
|
| 237 |
-
/**
|
| 238 |
-
* Return the weight of this magento product
|
| 239 |
-
*
|
| 240 |
-
* @return float
|
| 241 |
-
*/
|
| 242 |
-
public function weight()
|
| 243 |
-
{
|
| 244 |
-
return $this->_weight;
|
| 245 |
-
}
|
| 246 |
-
|
| 247 |
-
/**
|
| 248 |
-
* Return the categories of this product
|
| 249 |
-
*
|
| 250 |
-
* @return array
|
| 251 |
-
*/
|
| 252 |
-
public function categories()
|
| 253 |
-
{
|
| 254 |
-
return $this->_categories;
|
| 255 |
-
}
|
| 256 |
-
|
| 257 |
-
/**
|
| 258 |
-
* Return the flattened tree of the given category
|
| 259 |
-
*
|
| 260 |
-
* @param Mage_Catalog_Model_Category $category
|
| 261 |
-
* @return array
|
| 262 |
-
*/
|
| 263 |
-
protected function _getFullCategoryName(Mage_Catalog_Model_Category $category)
|
| 264 |
-
{
|
| 265 |
-
if ($category->getParentId() > 1) {
|
| 266 |
-
$parent = $category->getParentCategory();
|
| 267 |
-
|
| 268 |
-
$data = $this->_getFullCategoryName($parent);
|
| 269 |
-
} else {
|
| 270 |
-
$data = array();
|
| 271 |
-
}
|
| 272 |
-
|
| 273 |
-
$data[$category->getId()] = $category->getName();
|
| 274 |
-
|
| 275 |
-
return $data;
|
| 276 |
-
}
|
| 277 |
-
|
| 278 |
-
/**
|
| 279 |
-
* Return the attributes for this product
|
| 280 |
-
*
|
| 281 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Attributes
|
| 282 |
-
*/
|
| 283 |
-
public function attributes()
|
| 284 |
-
{
|
| 285 |
-
return $this->_attributes;
|
| 286 |
-
}
|
| 287 |
-
|
| 288 |
-
public function attributeSet()
|
| 289 |
-
{
|
| 290 |
-
return $this->_attributeSet;
|
| 291 |
-
}
|
| 292 |
-
|
| 293 |
-
/**
|
| 294 |
-
* Serialize the object
|
| 295 |
-
*
|
| 296 |
-
* @todo This method, is it even used?
|
| 297 |
-
* @return string
|
| 298 |
-
*/
|
| 299 |
-
public function serialize()
|
| 300 |
-
{
|
| 301 |
-
return serialize(array($this->id()));
|
| 302 |
-
}
|
| 303 |
-
|
| 304 |
-
/**
|
| 305 |
-
* Unserialize the object
|
| 306 |
-
*
|
| 307 |
-
* @todo This method, is it even used? And $isNew???
|
| 308 |
-
* @param string $string
|
| 309 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Product
|
| 310 |
-
*/
|
| 311 |
-
public function unserialize($string)
|
| 312 |
-
{
|
| 313 |
-
list(
|
| 314 |
-
$this->_id,
|
| 315 |
-
$this->_sku,
|
| 316 |
-
$this->_attributeSet,
|
| 317 |
-
$this->_name,
|
| 318 |
-
$this->_description,
|
| 319 |
-
$this->_productUrl,
|
| 320 |
-
$this->_imagePath,
|
| 321 |
-
$this->_weight,
|
| 322 |
-
$this->_categories,
|
| 323 |
-
$isNew,
|
| 324 |
-
$this->_price,
|
| 325 |
-
$specialPrice,
|
| 326 |
-
$this->_created,
|
| 327 |
-
$this->_modified,
|
| 328 |
-
$this->_attributes
|
| 329 |
-
) = unserialize($string);
|
| 330 |
-
|
| 331 |
-
return $this;
|
| 332 |
-
}
|
| 333 |
}
|
| 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_Product implements Serializable
|
| 31 |
+
{
|
| 32 |
+
/**
|
| 33 |
+
* The original object
|
| 34 |
+
*
|
| 35 |
+
* @todo Not used???
|
| 36 |
+
* @var Mage_Catalog_Model_Product|Mage_Sales_Model_Quote_Item|Mage_Sales_Model_Order_Item
|
| 37 |
+
*/
|
| 38 |
+
protected $_original;
|
| 39 |
+
|
| 40 |
+
/**
|
| 41 |
+
* Predefine the internal fields
|
| 42 |
+
*/
|
| 43 |
+
protected $_id;
|
| 44 |
+
protected $_sku;
|
| 45 |
+
protected $_name;
|
| 46 |
+
protected $_description;
|
| 47 |
+
protected $_productUrl = '';
|
| 48 |
+
protected $_imagePath = '';
|
| 49 |
+
protected $_weight;
|
| 50 |
+
protected $_categories = array();
|
| 51 |
+
protected $_price;
|
| 52 |
+
protected $_created = '';
|
| 53 |
+
protected $_modified = '';
|
| 54 |
+
protected $_attributes = '';
|
| 55 |
+
protected $_attributeSet = '';
|
| 56 |
+
|
| 57 |
+
/**
|
| 58 |
+
* Sets the original model
|
| 59 |
+
*
|
| 60 |
+
* @param Mage_Catalog_Model_Product|Mage_Sales_Model_Quote_Item|Mage_Sales_Model_Order_Item $original
|
| 61 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Product
|
| 62 |
+
*/
|
| 63 |
+
public function setOriginal($original)
|
| 64 |
+
{
|
| 65 |
+
if ($original instanceof Mage_Catalog_Model_Product) {
|
| 66 |
+
$this->_createFromProductModel($original);
|
| 67 |
+
} else {
|
| 68 |
+
$product = Mage::getModel('catalog/product')->load($original->getProductId());
|
| 69 |
+
|
| 70 |
+
if ($product->getID()) {
|
| 71 |
+
$this->_createFromProductModel($product);
|
| 72 |
+
} else {
|
| 73 |
+
$this->_id = $original->getProductId();
|
| 74 |
+
$this->_sku = $original->getSKU();
|
| 75 |
+
$this->_name = $original->getName();
|
| 76 |
+
$this->_description = $original->getDescription();
|
| 77 |
+
$this->_weight = $original->getWeight();
|
| 78 |
+
$this->_price = $original->getPrice();
|
| 79 |
+
}
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
return $this;
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
/**
|
| 86 |
+
* Create product from model.
|
| 87 |
+
*
|
| 88 |
+
* @param Mage_Catalog_Model_Product $model
|
| 89 |
+
*/
|
| 90 |
+
protected function _createFromProductModel(Mage_Catalog_Model_Product $model)
|
| 91 |
+
{
|
| 92 |
+
$this->_id = $model->getId();
|
| 93 |
+
$this->_sku = $model->getSku();
|
| 94 |
+
$this->_name = $model->getName();
|
| 95 |
+
$this->_description = $model->getShortDescription();
|
| 96 |
+
$this->_price = $model->getPrice();
|
| 97 |
+
$this->_created = $model->getCreatedAt();
|
| 98 |
+
$this->_modified = $model->getUpdatedAt();
|
| 99 |
+
$this->_productUrl = $model->getProductUrl();
|
| 100 |
+
$this->_imagePath = $model->getImageUrl();
|
| 101 |
+
$this->_weight = $model->getWeight();
|
| 102 |
+
|
| 103 |
+
$data = array();
|
| 104 |
+
|
| 105 |
+
$categoryIds = $model->getCategoryIds();
|
| 106 |
+
|
| 107 |
+
foreach ($categoryIds as $categoryId) {
|
| 108 |
+
$category = Mage::getModel('catalog/category')->load($categoryId);
|
| 109 |
+
|
| 110 |
+
$data[] = $this->_getFullCategoryName($category);
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
$this->_categories = $data;
|
| 114 |
+
|
| 115 |
+
$this->_attributes = Mage::getModel('marketingsoftware/abstraction_attributes')->setOriginal($model);
|
| 116 |
+
|
| 117 |
+
$attributeSetModel = Mage::getModel("eav/entity_attribute_set");
|
| 118 |
+
$attributeSetModel->load($model->getAttributeSetId());
|
| 119 |
+
|
| 120 |
+
$this->_attributeSet = $attributeSetModel->getAttributeSetName();
|
| 121 |
+
|
| 122 |
+
$this->timestamp = time();
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
/**
|
| 126 |
+
* Loads a product model
|
| 127 |
+
*
|
| 128 |
+
* @param integer $productId
|
| 129 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Product
|
| 130 |
+
*/
|
| 131 |
+
public function loadProduct($productId)
|
| 132 |
+
{
|
| 133 |
+
$product = Mage::getModel('catalog/product')->load($productId);
|
| 134 |
+
|
| 135 |
+
if ($product->getId()) {
|
| 136 |
+
$this->setOriginal($product);
|
| 137 |
+
} else {
|
| 138 |
+
$this->_id = $productId;
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
return $this;
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
/**
|
| 145 |
+
* Return the identifier for this object
|
| 146 |
+
*
|
| 147 |
+
* @return integer
|
| 148 |
+
*/
|
| 149 |
+
public function id()
|
| 150 |
+
{
|
| 151 |
+
return $this->_id;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
/**
|
| 155 |
+
* Return the sku (stock keeping unit), which is an unique identifier
|
| 156 |
+
* for a magento product
|
| 157 |
+
*
|
| 158 |
+
* @return string
|
| 159 |
+
*/
|
| 160 |
+
public function sku()
|
| 161 |
+
{
|
| 162 |
+
return $this->_sku;
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
/**
|
| 166 |
+
* Return the name of this magento product
|
| 167 |
+
*
|
| 168 |
+
* @return string
|
| 169 |
+
*/
|
| 170 |
+
public function name()
|
| 171 |
+
{
|
| 172 |
+
return $this->_name;
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
/**
|
| 176 |
+
* Return the description of this magento product
|
| 177 |
+
*
|
| 178 |
+
* @return string
|
| 179 |
+
*/
|
| 180 |
+
public function description()
|
| 181 |
+
{
|
| 182 |
+
return $this->_description;
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
/**
|
| 186 |
+
* Return the price of this magento product
|
| 187 |
+
*
|
| 188 |
+
* @return string
|
| 189 |
+
*/
|
| 190 |
+
public function price()
|
| 191 |
+
{
|
| 192 |
+
return $this->_price;
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
/**
|
| 196 |
+
* Return the creation date of this magento product
|
| 197 |
+
*
|
| 198 |
+
* @return string
|
| 199 |
+
*/
|
| 200 |
+
public function created()
|
| 201 |
+
{
|
| 202 |
+
return $this->_created;
|
| 203 |
+
}
|
| 204 |
+
|
| 205 |
+
/**
|
| 206 |
+
* Return the modification date of this magento product
|
| 207 |
+
*
|
| 208 |
+
* @return string
|
| 209 |
+
*/
|
| 210 |
+
public function modified()
|
| 211 |
+
{
|
| 212 |
+
return $this->_modified;
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
+
/**
|
| 216 |
+
* Return the product url of this magento product
|
| 217 |
+
*
|
| 218 |
+
* @param integer $storeId
|
| 219 |
+
* @return string
|
| 220 |
+
*/
|
| 221 |
+
public function productUrl($storeId = null)
|
| 222 |
+
{
|
| 223 |
+
return $this->_productUrl;
|
| 224 |
+
}
|
| 225 |
+
|
| 226 |
+
/**
|
| 227 |
+
* Return the image url of this magento product
|
| 228 |
+
*
|
| 229 |
+
* @param integer $storeId
|
| 230 |
+
* @return string
|
| 231 |
+
*/
|
| 232 |
+
public function imageUrl($storeId = null)
|
| 233 |
+
{
|
| 234 |
+
return $this->_imagePath;
|
| 235 |
+
}
|
| 236 |
+
|
| 237 |
+
/**
|
| 238 |
+
* Return the weight of this magento product
|
| 239 |
+
*
|
| 240 |
+
* @return float
|
| 241 |
+
*/
|
| 242 |
+
public function weight()
|
| 243 |
+
{
|
| 244 |
+
return $this->_weight;
|
| 245 |
+
}
|
| 246 |
+
|
| 247 |
+
/**
|
| 248 |
+
* Return the categories of this product
|
| 249 |
+
*
|
| 250 |
+
* @return array
|
| 251 |
+
*/
|
| 252 |
+
public function categories()
|
| 253 |
+
{
|
| 254 |
+
return $this->_categories;
|
| 255 |
+
}
|
| 256 |
+
|
| 257 |
+
/**
|
| 258 |
+
* Return the flattened tree of the given category
|
| 259 |
+
*
|
| 260 |
+
* @param Mage_Catalog_Model_Category $category
|
| 261 |
+
* @return array
|
| 262 |
+
*/
|
| 263 |
+
protected function _getFullCategoryName(Mage_Catalog_Model_Category $category)
|
| 264 |
+
{
|
| 265 |
+
if ($category->getParentId() > 1) {
|
| 266 |
+
$parent = $category->getParentCategory();
|
| 267 |
+
|
| 268 |
+
$data = $this->_getFullCategoryName($parent);
|
| 269 |
+
} else {
|
| 270 |
+
$data = array();
|
| 271 |
+
}
|
| 272 |
+
|
| 273 |
+
$data[$category->getId()] = $category->getName();
|
| 274 |
+
|
| 275 |
+
return $data;
|
| 276 |
+
}
|
| 277 |
+
|
| 278 |
+
/**
|
| 279 |
+
* Return the attributes for this product
|
| 280 |
+
*
|
| 281 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Attributes
|
| 282 |
+
*/
|
| 283 |
+
public function attributes()
|
| 284 |
+
{
|
| 285 |
+
return $this->_attributes;
|
| 286 |
+
}
|
| 287 |
+
|
| 288 |
+
public function attributeSet()
|
| 289 |
+
{
|
| 290 |
+
return $this->_attributeSet;
|
| 291 |
+
}
|
| 292 |
+
|
| 293 |
+
/**
|
| 294 |
+
* Serialize the object
|
| 295 |
+
*
|
| 296 |
+
* @todo This method, is it even used?
|
| 297 |
+
* @return string
|
| 298 |
+
*/
|
| 299 |
+
public function serialize()
|
| 300 |
+
{
|
| 301 |
+
return serialize(array($this->id()));
|
| 302 |
+
}
|
| 303 |
+
|
| 304 |
+
/**
|
| 305 |
+
* Unserialize the object
|
| 306 |
+
*
|
| 307 |
+
* @todo This method, is it even used? And $isNew???
|
| 308 |
+
* @param string $string
|
| 309 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Product
|
| 310 |
+
*/
|
| 311 |
+
public function unserialize($string)
|
| 312 |
+
{
|
| 313 |
+
list(
|
| 314 |
+
$this->_id,
|
| 315 |
+
$this->_sku,
|
| 316 |
+
$this->_attributeSet,
|
| 317 |
+
$this->_name,
|
| 318 |
+
$this->_description,
|
| 319 |
+
$this->_productUrl,
|
| 320 |
+
$this->_imagePath,
|
| 321 |
+
$this->_weight,
|
| 322 |
+
$this->_categories,
|
| 323 |
+
$isNew,
|
| 324 |
+
$this->_price,
|
| 325 |
+
$specialPrice,
|
| 326 |
+
$this->_created,
|
| 327 |
+
$this->_modified,
|
| 328 |
+
$this->_attributes
|
| 329 |
+
) = unserialize($string);
|
| 330 |
+
|
| 331 |
+
return $this;
|
| 332 |
+
}
|
| 333 |
}
|
app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Product/Viewed.php
CHANGED
|
@@ -1,418 +1,418 @@
|
|
| 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_Product_Viewed implements Serializable
|
| 31 |
-
{
|
| 32 |
-
/**
|
| 33 |
-
* Predefine the internal fields
|
| 34 |
-
*/
|
| 35 |
-
public $id;
|
| 36 |
-
public $customerId;
|
| 37 |
-
protected $_sku;
|
| 38 |
-
protected $_name;
|
| 39 |
-
protected $_description;
|
| 40 |
-
protected $_productUrl;
|
| 41 |
-
protected $_imagePath;
|
| 42 |
-
protected $_weight;
|
| 43 |
-
protected $_categories = array();
|
| 44 |
-
protected $_isNew;
|
| 45 |
-
protected $_price;
|
| 46 |
-
protected $_specialPrice;
|
| 47 |
-
protected $_created;
|
| 48 |
-
protected $_modified;
|
| 49 |
-
protected $_attributes;
|
| 50 |
-
protected $_attributeSet;
|
| 51 |
-
protected $_timestamp;
|
| 52 |
-
|
| 53 |
-
/**
|
| 54 |
-
* Sets the original model
|
| 55 |
-
*
|
| 56 |
-
* @param Mage_Catalog_Model_Product|Mage_Sales_Model_Quote_Item|Mage_Sales_Model_Order_Item $original
|
| 57 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Product
|
| 58 |
-
*/
|
| 59 |
-
public function setOriginal($original, $id)
|
| 60 |
-
{
|
| 61 |
-
if ($original instanceof Mage_Catalog_Model_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 |
-
|
| 76 |
-
$categoryIds = $original->getCategoryIds();
|
| 77 |
-
|
| 78 |
-
foreach ($categoryIds as $categoryId) {
|
| 79 |
-
$category = Mage::getModel('catalog/category')->load($categoryId);
|
| 80 |
-
|
| 81 |
-
$data[] = $this->_getFullCategoryName($category);
|
| 82 |
-
}
|
| 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 |
-
|
| 89 |
-
if ($from || $to) {
|
| 90 |
-
$new = true;
|
| 91 |
-
|
| 92 |
-
$now = Zend_Date::now();
|
| 93 |
-
|
| 94 |
-
if ($from) {
|
| 95 |
-
$new = $new && $from->isEarlier($now);
|
| 96 |
-
}
|
| 97 |
-
|
| 98 |
-
if ($to) {
|
| 99 |
-
$new = $new && $to->isLater($now);
|
| 100 |
-
}
|
| 101 |
-
|
| 102 |
-
$this->_isNew = $new;
|
| 103 |
-
} else {
|
| 104 |
-
$this->_isNew = false;
|
| 105 |
-
}
|
| 106 |
-
|
| 107 |
-
$this->_attributes = Mage::getModel('marketingsoftware/abstraction_attributes')->setOriginal($original);
|
| 108 |
-
|
| 109 |
-
$attributeSetModel = Mage::getModel("eav/entity_attribute_set");
|
| 110 |
-
$attributeSetModel->load($original->getAttributeSetId());
|
| 111 |
-
|
| 112 |
-
$this->_attributeSet = $attributeSetModel->getAttributeSetName();
|
| 113 |
-
|
| 114 |
-
$this->_timestamp = time();
|
| 115 |
-
|
| 116 |
-
$this->customerId = $id;
|
| 117 |
-
|
| 118 |
-
$this->storeId = Mage::app()->getStore()->getStoreId();
|
| 119 |
-
|
| 120 |
-
return $this;
|
| 121 |
-
} else {
|
| 122 |
-
$product = Mage::getModel('catalog/product')->load($original->getProductId());
|
| 123 |
-
|
| 124 |
-
if ($product->getId()) {
|
| 125 |
-
$this->id = $product->getId();
|
| 126 |
-
$this->_sku = $product->getSku();
|
| 127 |
-
$this->_name = $product->getName();
|
| 128 |
-
$this->_description = $product->getShortDescription();
|
| 129 |
-
$this->_price = $product->getPrice();
|
| 130 |
-
$this->_specialPrice = $product->getSpecialPrice();
|
| 131 |
-
$this->_created = $product->getCreatedAt();
|
| 132 |
-
$this->_modified = $product->getUpdatedAt();
|
| 133 |
-
$this->_productUrl = $product->getProductUrl();
|
| 134 |
-
$this->_imagePath = 'catalog' . DS . 'product' . $product->getImage();
|
| 135 |
-
$this->_weight = $product->getWeight();
|
| 136 |
-
|
| 137 |
-
$data = array();
|
| 138 |
-
|
| 139 |
-
$categoryIds = $product->getCategoryIds();
|
| 140 |
-
|
| 141 |
-
foreach ($categoryIds as $categoryId) {
|
| 142 |
-
$category = Mage::getModel('catalog/category')->load($categoryId);
|
| 143 |
-
|
| 144 |
-
$data[] = $this->_getFullCategoryName($category);
|
| 145 |
-
}
|
| 146 |
-
|
| 147 |
-
$this->_categories = $data;
|
| 148 |
-
|
| 149 |
-
$from = $product->getNewsFromDate() ? Mage::app()->getLocale()->date($product->getNewsFromDate()) : null;
|
| 150 |
-
$to = $product->getNewsToDate() ? Mage::app()->getLocale()->date($product->getNewsToDate()) : null;
|
| 151 |
-
|
| 152 |
-
if ($from || $to) {
|
| 153 |
-
$new = true;
|
| 154 |
-
|
| 155 |
-
$now = Zend_Date::now();
|
| 156 |
-
|
| 157 |
-
if ($from) {
|
| 158 |
-
$new = $new && $from->isEarlier($now);
|
| 159 |
-
}
|
| 160 |
-
|
| 161 |
-
if ($to) {
|
| 162 |
-
$new = $new && $to->isLater($now);
|
| 163 |
-
}
|
| 164 |
-
|
| 165 |
-
$this->_isNew = $new;
|
| 166 |
-
} else {
|
| 167 |
-
$this->_isNew = false;
|
| 168 |
-
}
|
| 169 |
-
|
| 170 |
-
$this->_attributes = Mage::getModel('marketingsoftware/abstraction_attributes')->setOriginal($product);
|
| 171 |
-
|
| 172 |
-
$attributeSetModel = Mage::getModel("eav/entity_attribute_set");
|
| 173 |
-
$attributeSetModel->load($product->getAttributeSetId());
|
| 174 |
-
|
| 175 |
-
$this->_attributeSet = $attributeSetModel->getAttributeSetName();
|
| 176 |
-
|
| 177 |
-
$this->_timestamp = time();
|
| 178 |
-
} else {
|
| 179 |
-
$this->id = $original->getProductId();
|
| 180 |
-
$this->_sku = $original->getSKU();
|
| 181 |
-
$this->_attributeSet = '';
|
| 182 |
-
$this->_name = $original->getName();
|
| 183 |
-
$this->_description = $original->getDescription();
|
| 184 |
-
$this->_productUrl = '';
|
| 185 |
-
$this->_imagePath = '';
|
| 186 |
-
$this->_weight = $original->getWeight();
|
| 187 |
-
$this->_categories = array();
|
| 188 |
-
$this->_isNew = false;
|
| 189 |
-
$this->_price = $original->getPrice();
|
| 190 |
-
$this->_created = '';
|
| 191 |
-
$this->_modified = '';
|
| 192 |
-
$this->_attributes = '';
|
| 193 |
-
$this->customerId = $id;
|
| 194 |
-
$this->storeId = Mage::app()->getStore()->getStoreId();
|
| 195 |
-
}
|
| 196 |
-
|
| 197 |
-
return $this;
|
| 198 |
-
}
|
| 199 |
-
}
|
| 200 |
-
|
| 201 |
-
/**
|
| 202 |
-
* Loads a product model
|
| 203 |
-
*
|
| 204 |
-
* @param integer $productId
|
| 205 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Product
|
| 206 |
-
*/
|
| 207 |
-
public function loadProduct($productId)
|
| 208 |
-
{
|
| 209 |
-
$product = Mage::getModel('catalog/product')->load($productId);
|
| 210 |
-
|
| 211 |
-
if ($product->getId()) {
|
| 212 |
-
$this->setOriginal($product);
|
| 213 |
-
} else {
|
| 214 |
-
$this->id = $productId;
|
| 215 |
-
}
|
| 216 |
-
|
| 217 |
-
return $this;
|
| 218 |
-
}
|
| 219 |
-
|
| 220 |
-
/**
|
| 221 |
-
* Return the identifier for this object
|
| 222 |
-
*
|
| 223 |
-
* @return integer
|
| 224 |
-
*/
|
| 225 |
-
public function id()
|
| 226 |
-
{
|
| 227 |
-
return $this->id;
|
| 228 |
-
}
|
| 229 |
-
|
| 230 |
-
/**
|
| 231 |
-
* Return the sku (stock keeping unit), which is an unique identifier
|
| 232 |
-
* for a magento product
|
| 233 |
-
*
|
| 234 |
-
* @return string
|
| 235 |
-
*/
|
| 236 |
-
public function sku()
|
| 237 |
-
{
|
| 238 |
-
return $this->_sku;
|
| 239 |
-
}
|
| 240 |
-
|
| 241 |
-
/**
|
| 242 |
-
* Return the name of this magento product
|
| 243 |
-
*
|
| 244 |
-
* @return string
|
| 245 |
-
*/
|
| 246 |
-
public function name()
|
| 247 |
-
{
|
| 248 |
-
return $this->_name;
|
| 249 |
-
}
|
| 250 |
-
|
| 251 |
-
/**
|
| 252 |
-
* Return the description of this magento product
|
| 253 |
-
*
|
| 254 |
-
* @return string
|
| 255 |
-
*/
|
| 256 |
-
public function description()
|
| 257 |
-
{
|
| 258 |
-
return $this->_description;
|
| 259 |
-
}
|
| 260 |
-
|
| 261 |
-
/**
|
| 262 |
-
* Return the price of this magento product
|
| 263 |
-
*
|
| 264 |
-
* @return string
|
| 265 |
-
*/
|
| 266 |
-
public function price()
|
| 267 |
-
{
|
| 268 |
-
return $this->_price;
|
| 269 |
-
}
|
| 270 |
-
|
| 271 |
-
/**
|
| 272 |
-
* Return the price of this magento product
|
| 273 |
-
*
|
| 274 |
-
* @return string
|
| 275 |
-
*/
|
| 276 |
-
public function specialPrice()
|
| 277 |
-
{
|
| 278 |
-
return $this->_specialPrice;
|
| 279 |
-
}
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
/**
|
| 283 |
-
* Return the creation date of this magento product
|
| 284 |
-
*
|
| 285 |
-
* @return string
|
| 286 |
-
*/
|
| 287 |
-
public function created()
|
| 288 |
-
{
|
| 289 |
-
return $this->_created;
|
| 290 |
-
}
|
| 291 |
-
|
| 292 |
-
/**
|
| 293 |
-
* Return the modification date of this magento product
|
| 294 |
-
*
|
| 295 |
-
* @return string
|
| 296 |
-
*/
|
| 297 |
-
public function modified()
|
| 298 |
-
{
|
| 299 |
-
return $this->_modified;
|
| 300 |
-
}
|
| 301 |
-
|
| 302 |
-
/**
|
| 303 |
-
* Return the product url of this magento product
|
| 304 |
-
*
|
| 305 |
-
* @param integer $storeId
|
| 306 |
-
* @return string
|
| 307 |
-
*/
|
| 308 |
-
public function productUrl($storeId = null)
|
| 309 |
-
{
|
| 310 |
-
return $this->_productUrl;
|
| 311 |
-
}
|
| 312 |
-
|
| 313 |
-
/**
|
| 314 |
-
* Return the image url of this magento product
|
| 315 |
-
*
|
| 316 |
-
* @param integer $storeId
|
| 317 |
-
* @return string
|
| 318 |
-
*/
|
| 319 |
-
public function imageUrl($storeId = null)
|
| 320 |
-
{
|
| 321 |
-
return $this->_imagePath;
|
| 322 |
-
}
|
| 323 |
-
|
| 324 |
-
/**
|
| 325 |
-
* Return the weight of this magento product
|
| 326 |
-
*
|
| 327 |
-
* @return float
|
| 328 |
-
*/
|
| 329 |
-
public function weight()
|
| 330 |
-
{
|
| 331 |
-
return $this->_weight;
|
| 332 |
-
}
|
| 333 |
-
|
| 334 |
-
/**
|
| 335 |
-
* Return the categories of this product
|
| 336 |
-
*
|
| 337 |
-
* @return array
|
| 338 |
-
*/
|
| 339 |
-
public function categories()
|
| 340 |
-
{
|
| 341 |
-
return $this->_categories;
|
| 342 |
-
}
|
| 343 |
-
|
| 344 |
-
/**
|
| 345 |
-
* Return the flattened tree of the given category
|
| 346 |
-
*
|
| 347 |
-
* @param Mage_Catalog_Model_Category $category
|
| 348 |
-
* @return array
|
| 349 |
-
*/
|
| 350 |
-
protected function _getFullCategoryName(Mage_Catalog_Model_Category $category)
|
| 351 |
-
{
|
| 352 |
-
if ($category->getParentId() > 1) {
|
| 353 |
-
$parent = $category->getParentCategory();
|
| 354 |
-
|
| 355 |
-
$data = $this->_getFullCategoryName($parent);
|
| 356 |
-
} else {
|
| 357 |
-
$data = array();
|
| 358 |
-
}
|
| 359 |
-
|
| 360 |
-
$data[$category->getId()] = $category->getName();
|
| 361 |
-
|
| 362 |
-
return $data;
|
| 363 |
-
}
|
| 364 |
-
|
| 365 |
-
/**
|
| 366 |
-
* Return whether this product is new
|
| 367 |
-
*
|
| 368 |
-
* @return boolean
|
| 369 |
-
*/
|
| 370 |
-
public function isNew()
|
| 371 |
-
{
|
| 372 |
-
return $this->_isNew;
|
| 373 |
-
}
|
| 374 |
-
|
| 375 |
-
/**
|
| 376 |
-
* Return the attributes for this product
|
| 377 |
-
*
|
| 378 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Attributes
|
| 379 |
-
*/
|
| 380 |
-
public function attributes()
|
| 381 |
-
{
|
| 382 |
-
return $this->_attributes;
|
| 383 |
-
}
|
| 384 |
-
|
| 385 |
-
public function attributeSet()
|
| 386 |
-
{
|
| 387 |
-
return $this->_attributeSet;
|
| 388 |
-
}
|
| 389 |
-
|
| 390 |
-
public function timestamp()
|
| 391 |
-
{
|
| 392 |
-
return $this->_timestamp;
|
| 393 |
-
}
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
/**
|
| 397 |
-
* Serialize the object
|
| 398 |
-
*
|
| 399 |
-
* @return string
|
| 400 |
-
*/
|
| 401 |
-
public function serialize()
|
| 402 |
-
{
|
| 403 |
-
return serialize(array($this->id()));
|
| 404 |
-
}
|
| 405 |
-
|
| 406 |
-
/**
|
| 407 |
-
* Unserialize the object
|
| 408 |
-
*
|
| 409 |
-
* @param string $string
|
| 410 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Product
|
| 411 |
-
*/
|
| 412 |
-
public function unserialize($string)
|
| 413 |
-
{
|
| 414 |
-
list($this->id) = unserialize($string);
|
| 415 |
-
|
| 416 |
-
return $this;
|
| 417 |
-
}
|
| 418 |
}
|
| 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_Product_Viewed implements Serializable
|
| 31 |
+
{
|
| 32 |
+
/**
|
| 33 |
+
* Predefine the internal fields
|
| 34 |
+
*/
|
| 35 |
+
public $id;
|
| 36 |
+
public $customerId;
|
| 37 |
+
protected $_sku;
|
| 38 |
+
protected $_name;
|
| 39 |
+
protected $_description;
|
| 40 |
+
protected $_productUrl;
|
| 41 |
+
protected $_imagePath;
|
| 42 |
+
protected $_weight;
|
| 43 |
+
protected $_categories = array();
|
| 44 |
+
protected $_isNew;
|
| 45 |
+
protected $_price;
|
| 46 |
+
protected $_specialPrice;
|
| 47 |
+
protected $_created;
|
| 48 |
+
protected $_modified;
|
| 49 |
+
protected $_attributes;
|
| 50 |
+
protected $_attributeSet;
|
| 51 |
+
protected $_timestamp;
|
| 52 |
+
|
| 53 |
+
/**
|
| 54 |
+
* Sets the original model
|
| 55 |
+
*
|
| 56 |
+
* @param Mage_Catalog_Model_Product|Mage_Sales_Model_Quote_Item|Mage_Sales_Model_Order_Item $original
|
| 57 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Product
|
| 58 |
+
*/
|
| 59 |
+
public function setOriginal($original, $id)
|
| 60 |
+
{
|
| 61 |
+
if ($original instanceof Mage_Catalog_Model_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 |
+
|
| 76 |
+
$categoryIds = $original->getCategoryIds();
|
| 77 |
+
|
| 78 |
+
foreach ($categoryIds as $categoryId) {
|
| 79 |
+
$category = Mage::getModel('catalog/category')->load($categoryId);
|
| 80 |
+
|
| 81 |
+
$data[] = $this->_getFullCategoryName($category);
|
| 82 |
+
}
|
| 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 |
+
|
| 89 |
+
if ($from || $to) {
|
| 90 |
+
$new = true;
|
| 91 |
+
|
| 92 |
+
$now = Zend_Date::now();
|
| 93 |
+
|
| 94 |
+
if ($from) {
|
| 95 |
+
$new = $new && $from->isEarlier($now);
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
if ($to) {
|
| 99 |
+
$new = $new && $to->isLater($now);
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
$this->_isNew = $new;
|
| 103 |
+
} else {
|
| 104 |
+
$this->_isNew = false;
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
$this->_attributes = Mage::getModel('marketingsoftware/abstraction_attributes')->setOriginal($original);
|
| 108 |
+
|
| 109 |
+
$attributeSetModel = Mage::getModel("eav/entity_attribute_set");
|
| 110 |
+
$attributeSetModel->load($original->getAttributeSetId());
|
| 111 |
+
|
| 112 |
+
$this->_attributeSet = $attributeSetModel->getAttributeSetName();
|
| 113 |
+
|
| 114 |
+
$this->_timestamp = time();
|
| 115 |
+
|
| 116 |
+
$this->customerId = $id;
|
| 117 |
+
|
| 118 |
+
$this->storeId = Mage::app()->getStore()->getStoreId();
|
| 119 |
+
|
| 120 |
+
return $this;
|
| 121 |
+
} else {
|
| 122 |
+
$product = Mage::getModel('catalog/product')->load($original->getProductId());
|
| 123 |
+
|
| 124 |
+
if ($product->getId()) {
|
| 125 |
+
$this->id = $product->getId();
|
| 126 |
+
$this->_sku = $product->getSku();
|
| 127 |
+
$this->_name = $product->getName();
|
| 128 |
+
$this->_description = $product->getShortDescription();
|
| 129 |
+
$this->_price = $product->getPrice();
|
| 130 |
+
$this->_specialPrice = $product->getSpecialPrice();
|
| 131 |
+
$this->_created = $product->getCreatedAt();
|
| 132 |
+
$this->_modified = $product->getUpdatedAt();
|
| 133 |
+
$this->_productUrl = $product->getProductUrl();
|
| 134 |
+
$this->_imagePath = 'catalog' . DS . 'product' . $product->getImage();
|
| 135 |
+
$this->_weight = $product->getWeight();
|
| 136 |
+
|
| 137 |
+
$data = array();
|
| 138 |
+
|
| 139 |
+
$categoryIds = $product->getCategoryIds();
|
| 140 |
+
|
| 141 |
+
foreach ($categoryIds as $categoryId) {
|
| 142 |
+
$category = Mage::getModel('catalog/category')->load($categoryId);
|
| 143 |
+
|
| 144 |
+
$data[] = $this->_getFullCategoryName($category);
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
$this->_categories = $data;
|
| 148 |
+
|
| 149 |
+
$from = $product->getNewsFromDate() ? Mage::app()->getLocale()->date($product->getNewsFromDate()) : null;
|
| 150 |
+
$to = $product->getNewsToDate() ? Mage::app()->getLocale()->date($product->getNewsToDate()) : null;
|
| 151 |
+
|
| 152 |
+
if ($from || $to) {
|
| 153 |
+
$new = true;
|
| 154 |
+
|
| 155 |
+
$now = Zend_Date::now();
|
| 156 |
+
|
| 157 |
+
if ($from) {
|
| 158 |
+
$new = $new && $from->isEarlier($now);
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
if ($to) {
|
| 162 |
+
$new = $new && $to->isLater($now);
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
$this->_isNew = $new;
|
| 166 |
+
} else {
|
| 167 |
+
$this->_isNew = false;
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
$this->_attributes = Mage::getModel('marketingsoftware/abstraction_attributes')->setOriginal($product);
|
| 171 |
+
|
| 172 |
+
$attributeSetModel = Mage::getModel("eav/entity_attribute_set");
|
| 173 |
+
$attributeSetModel->load($product->getAttributeSetId());
|
| 174 |
+
|
| 175 |
+
$this->_attributeSet = $attributeSetModel->getAttributeSetName();
|
| 176 |
+
|
| 177 |
+
$this->_timestamp = time();
|
| 178 |
+
} else {
|
| 179 |
+
$this->id = $original->getProductId();
|
| 180 |
+
$this->_sku = $original->getSKU();
|
| 181 |
+
$this->_attributeSet = '';
|
| 182 |
+
$this->_name = $original->getName();
|
| 183 |
+
$this->_description = $original->getDescription();
|
| 184 |
+
$this->_productUrl = '';
|
| 185 |
+
$this->_imagePath = '';
|
| 186 |
+
$this->_weight = $original->getWeight();
|
| 187 |
+
$this->_categories = array();
|
| 188 |
+
$this->_isNew = false;
|
| 189 |
+
$this->_price = $original->getPrice();
|
| 190 |
+
$this->_created = '';
|
| 191 |
+
$this->_modified = '';
|
| 192 |
+
$this->_attributes = '';
|
| 193 |
+
$this->customerId = $id;
|
| 194 |
+
$this->storeId = Mage::app()->getStore()->getStoreId();
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
return $this;
|
| 198 |
+
}
|
| 199 |
+
}
|
| 200 |
+
|
| 201 |
+
/**
|
| 202 |
+
* Loads a product model
|
| 203 |
+
*
|
| 204 |
+
* @param integer $productId
|
| 205 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Product
|
| 206 |
+
*/
|
| 207 |
+
public function loadProduct($productId)
|
| 208 |
+
{
|
| 209 |
+
$product = Mage::getModel('catalog/product')->load($productId);
|
| 210 |
+
|
| 211 |
+
if ($product->getId()) {
|
| 212 |
+
$this->setOriginal($product);
|
| 213 |
+
} else {
|
| 214 |
+
$this->id = $productId;
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
return $this;
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
/**
|
| 221 |
+
* Return the identifier for this object
|
| 222 |
+
*
|
| 223 |
+
* @return integer
|
| 224 |
+
*/
|
| 225 |
+
public function id()
|
| 226 |
+
{
|
| 227 |
+
return $this->id;
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
/**
|
| 231 |
+
* Return the sku (stock keeping unit), which is an unique identifier
|
| 232 |
+
* for a magento product
|
| 233 |
+
*
|
| 234 |
+
* @return string
|
| 235 |
+
*/
|
| 236 |
+
public function sku()
|
| 237 |
+
{
|
| 238 |
+
return $this->_sku;
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
/**
|
| 242 |
+
* Return the name of this magento product
|
| 243 |
+
*
|
| 244 |
+
* @return string
|
| 245 |
+
*/
|
| 246 |
+
public function name()
|
| 247 |
+
{
|
| 248 |
+
return $this->_name;
|
| 249 |
+
}
|
| 250 |
+
|
| 251 |
+
/**
|
| 252 |
+
* Return the description of this magento product
|
| 253 |
+
*
|
| 254 |
+
* @return string
|
| 255 |
+
*/
|
| 256 |
+
public function description()
|
| 257 |
+
{
|
| 258 |
+
return $this->_description;
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
/**
|
| 262 |
+
* Return the price of this magento product
|
| 263 |
+
*
|
| 264 |
+
* @return string
|
| 265 |
+
*/
|
| 266 |
+
public function price()
|
| 267 |
+
{
|
| 268 |
+
return $this->_price;
|
| 269 |
+
}
|
| 270 |
+
|
| 271 |
+
/**
|
| 272 |
+
* Return the price of this magento product
|
| 273 |
+
*
|
| 274 |
+
* @return string
|
| 275 |
+
*/
|
| 276 |
+
public function specialPrice()
|
| 277 |
+
{
|
| 278 |
+
return $this->_specialPrice;
|
| 279 |
+
}
|
| 280 |
+
|
| 281 |
+
|
| 282 |
+
/**
|
| 283 |
+
* Return the creation date of this magento product
|
| 284 |
+
*
|
| 285 |
+
* @return string
|
| 286 |
+
*/
|
| 287 |
+
public function created()
|
| 288 |
+
{
|
| 289 |
+
return $this->_created;
|
| 290 |
+
}
|
| 291 |
+
|
| 292 |
+
/**
|
| 293 |
+
* Return the modification date of this magento product
|
| 294 |
+
*
|
| 295 |
+
* @return string
|
| 296 |
+
*/
|
| 297 |
+
public function modified()
|
| 298 |
+
{
|
| 299 |
+
return $this->_modified;
|
| 300 |
+
}
|
| 301 |
+
|
| 302 |
+
/**
|
| 303 |
+
* Return the product url of this magento product
|
| 304 |
+
*
|
| 305 |
+
* @param integer $storeId
|
| 306 |
+
* @return string
|
| 307 |
+
*/
|
| 308 |
+
public function productUrl($storeId = null)
|
| 309 |
+
{
|
| 310 |
+
return $this->_productUrl;
|
| 311 |
+
}
|
| 312 |
+
|
| 313 |
+
/**
|
| 314 |
+
* Return the image url of this magento product
|
| 315 |
+
*
|
| 316 |
+
* @param integer $storeId
|
| 317 |
+
* @return string
|
| 318 |
+
*/
|
| 319 |
+
public function imageUrl($storeId = null)
|
| 320 |
+
{
|
| 321 |
+
return $this->_imagePath;
|
| 322 |
+
}
|
| 323 |
+
|
| 324 |
+
/**
|
| 325 |
+
* Return the weight of this magento product
|
| 326 |
+
*
|
| 327 |
+
* @return float
|
| 328 |
+
*/
|
| 329 |
+
public function weight()
|
| 330 |
+
{
|
| 331 |
+
return $this->_weight;
|
| 332 |
+
}
|
| 333 |
+
|
| 334 |
+
/**
|
| 335 |
+
* Return the categories of this product
|
| 336 |
+
*
|
| 337 |
+
* @return array
|
| 338 |
+
*/
|
| 339 |
+
public function categories()
|
| 340 |
+
{
|
| 341 |
+
return $this->_categories;
|
| 342 |
+
}
|
| 343 |
+
|
| 344 |
+
/**
|
| 345 |
+
* Return the flattened tree of the given category
|
| 346 |
+
*
|
| 347 |
+
* @param Mage_Catalog_Model_Category $category
|
| 348 |
+
* @return array
|
| 349 |
+
*/
|
| 350 |
+
protected function _getFullCategoryName(Mage_Catalog_Model_Category $category)
|
| 351 |
+
{
|
| 352 |
+
if ($category->getParentId() > 1) {
|
| 353 |
+
$parent = $category->getParentCategory();
|
| 354 |
+
|
| 355 |
+
$data = $this->_getFullCategoryName($parent);
|
| 356 |
+
} else {
|
| 357 |
+
$data = array();
|
| 358 |
+
}
|
| 359 |
+
|
| 360 |
+
$data[$category->getId()] = $category->getName();
|
| 361 |
+
|
| 362 |
+
return $data;
|
| 363 |
+
}
|
| 364 |
+
|
| 365 |
+
/**
|
| 366 |
+
* Return whether this product is new
|
| 367 |
+
*
|
| 368 |
+
* @return boolean
|
| 369 |
+
*/
|
| 370 |
+
public function isNew()
|
| 371 |
+
{
|
| 372 |
+
return $this->_isNew;
|
| 373 |
+
}
|
| 374 |
+
|
| 375 |
+
/**
|
| 376 |
+
* Return the attributes for this product
|
| 377 |
+
*
|
| 378 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Attributes
|
| 379 |
+
*/
|
| 380 |
+
public function attributes()
|
| 381 |
+
{
|
| 382 |
+
return $this->_attributes;
|
| 383 |
+
}
|
| 384 |
+
|
| 385 |
+
public function attributeSet()
|
| 386 |
+
{
|
| 387 |
+
return $this->_attributeSet;
|
| 388 |
+
}
|
| 389 |
+
|
| 390 |
+
public function timestamp()
|
| 391 |
+
{
|
| 392 |
+
return $this->_timestamp;
|
| 393 |
+
}
|
| 394 |
+
|
| 395 |
+
|
| 396 |
+
/**
|
| 397 |
+
* Serialize the object
|
| 398 |
+
*
|
| 399 |
+
* @return string
|
| 400 |
+
*/
|
| 401 |
+
public function serialize()
|
| 402 |
+
{
|
| 403 |
+
return serialize(array($this->id()));
|
| 404 |
+
}
|
| 405 |
+
|
| 406 |
+
/**
|
| 407 |
+
* Unserialize the object
|
| 408 |
+
*
|
| 409 |
+
* @param string $string
|
| 410 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Product
|
| 411 |
+
*/
|
| 412 |
+
public function unserialize($string)
|
| 413 |
+
{
|
| 414 |
+
list($this->id) = unserialize($string);
|
| 415 |
+
|
| 416 |
+
return $this;
|
| 417 |
+
}
|
| 418 |
}
|
app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Quote.php
CHANGED
|
@@ -1,369 +1,369 @@
|
|
| 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 Quote
|
| 29 |
-
*/
|
| 30 |
-
class Copernica_MarketingSoftware_Model_Abstraction_Quote implements Serializable
|
| 31 |
-
{
|
| 32 |
-
/**
|
| 33 |
-
* Predefine the internal fields
|
| 34 |
-
*/
|
| 35 |
-
protected $_quoteId;
|
| 36 |
-
protected $_quantity;
|
| 37 |
-
protected $_currency;
|
| 38 |
-
protected $_timestamp;
|
| 39 |
-
protected $_customerIP;
|
| 40 |
-
protected $_items;
|
| 41 |
-
|
| 42 |
-
/**
|
| 43 |
-
* The storeview object
|
| 44 |
-
*
|
| 45 |
-
* @var Copernica_MarketingSoftware_Model_Abstraction_Storeview
|
| 46 |
-
*/
|
| 47 |
-
protected $_storeview;
|
| 48 |
-
|
| 49 |
-
protected $_customerId;
|
| 50 |
-
protected $_addresses;
|
| 51 |
-
protected $_price;
|
| 52 |
-
protected $_weight;
|
| 53 |
-
protected $_active;
|
| 54 |
-
protected $_shippingDescription;
|
| 55 |
-
protected $_paymentDescription;
|
| 56 |
-
|
| 57 |
-
/**
|
| 58 |
-
* Sets the original model
|
| 59 |
-
*
|
| 60 |
-
* @param Mage_Sales_Model_Quote $original
|
| 61 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Quote
|
| 62 |
-
*/
|
| 63 |
-
public function setOriginal(Mage_Sales_Model_Quote $original)
|
| 64 |
-
{
|
| 65 |
-
$this->_quoteId = $original->getId();
|
| 66 |
-
|
| 67 |
-
return $this;
|
| 68 |
-
}
|
| 69 |
-
|
| 70 |
-
/**
|
| 71 |
-
* Loads a quote model
|
| 72 |
-
*
|
| 73 |
-
* @param integer $quoteId
|
| 74 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Quote
|
| 75 |
-
*/
|
| 76 |
-
public function loadQuote($quoteId)
|
| 77 |
-
{
|
| 78 |
-
$quote = Mage::getModel('sales/quote');
|
| 79 |
-
|
| 80 |
-
if (!is_callable($quote, 'loadByIdWithoutStore')) {
|
| 81 |
-
$storeIDs = array();
|
| 82 |
-
|
| 83 |
-
foreach (Mage::app()->getStores() as $id => $store) {
|
| 84 |
-
$storeIDs[] = $id;
|
| 85 |
-
}
|
| 86 |
-
|
| 87 |
-
$quote->setSharedStoreIds($storeIDs);
|
| 88 |
-
$quote->load($quoteId);
|
| 89 |
-
} else {
|
| 90 |
-
$quote->loadByIdWithoutStore($quoteId);
|
| 91 |
-
}
|
| 92 |
-
|
| 93 |
-
if ($quote->getId()) {
|
| 94 |
-
$this->_importFromObject($quote);
|
| 95 |
-
} else {
|
| 96 |
-
$this->_quoteId = $quoteId;
|
| 97 |
-
}
|
| 98 |
-
|
| 99 |
-
return $this;
|
| 100 |
-
}
|
| 101 |
-
|
| 102 |
-
/**
|
| 103 |
-
* Import this abstract from a real magento one
|
| 104 |
-
*
|
| 105 |
-
* @param Mage_Sales_Model_Quote $original
|
| 106 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Quote
|
| 107 |
-
*/
|
| 108 |
-
protected function _importFromObject(Mage_Sales_Model_Quote $original)
|
| 109 |
-
{
|
| 110 |
-
$this->_quoteId = $original->getId();
|
| 111 |
-
$this->_active = (bool) $original->getIsActive();
|
| 112 |
-
$this->_quantity = $original->getItemsQty();
|
| 113 |
-
$this->_currency = $original->getQuoteCurrencyCode();
|
| 114 |
-
$this->_price = Mage::getModel('marketingsoftware/abstraction_price')->setOriginal($original);
|
| 115 |
-
$this->_storeview = Mage::getModel('marketingsoftware/abstraction_storeview')->setOriginal($original->getStore());
|
| 116 |
-
$this->_timestamp = $original->getUpdatedAt();
|
| 117 |
-
$this->_customerIP = $original->getRemoteIp();
|
| 118 |
-
|
| 119 |
-
if ($address = $original->getShippingAddress()) {
|
| 120 |
-
$this->_weight = $address->getWeight();
|
| 121 |
-
}
|
| 122 |
-
|
| 123 |
-
$data = array();
|
| 124 |
-
|
| 125 |
-
$items = $original->getAllVisibleItems();
|
| 126 |
-
|
| 127 |
-
foreach ($items as $item) {
|
| 128 |
-
$data[] = Mage::getModel('marketingsoftware/abstraction_quote_item')->setOriginal($item);
|
| 129 |
-
}
|
| 130 |
-
|
| 131 |
-
$this->_items = $data;
|
| 132 |
-
|
| 133 |
-
if ($customerId = $original->getCustomerId()) {
|
| 134 |
-
$this->_customerId = $customerId;
|
| 135 |
-
}
|
| 136 |
-
|
| 137 |
-
$data = array();
|
| 138 |
-
|
| 139 |
-
$addresses = $original->getAddressesCollection();
|
| 140 |
-
|
| 141 |
-
foreach ($addresses as $address) {
|
| 142 |
-
$data[] = Mage::getModel('marketingsoftware/abstraction_address')->setOriginal($address);
|
| 143 |
-
}
|
| 144 |
-
|
| 145 |
-
$this->_addresses = $data;
|
| 146 |
-
|
| 147 |
-
if ($address = $original->getShippingAddress()) {
|
| 148 |
-
$this->_shippingDescription = $address->getShippingDescription();
|
| 149 |
-
}
|
| 150 |
-
|
| 151 |
-
if ($payment = $original->getPayment()) {
|
| 152 |
-
try {
|
| 153 |
-
$this->_paymentDescription = $payment->getMethodInstance()->getTitle();
|
| 154 |
-
} catch (Mage_Core_Exception $exception) { }
|
| 155 |
-
}
|
| 156 |
-
}
|
| 157 |
-
|
| 158 |
-
/**
|
| 159 |
-
* The quote id of this quote object
|
| 160 |
-
*
|
| 161 |
-
* @return integer
|
| 162 |
-
*/
|
| 163 |
-
public function id()
|
| 164 |
-
{
|
| 165 |
-
return $this->_quoteId;
|
| 166 |
-
}
|
| 167 |
-
|
| 168 |
-
/**
|
| 169 |
-
* Is this quote still active
|
| 170 |
-
*
|
| 171 |
-
* @return boolean
|
| 172 |
-
*/
|
| 173 |
-
public function active()
|
| 174 |
-
{
|
| 175 |
-
return $this->_active;
|
| 176 |
-
}
|
| 177 |
-
|
| 178 |
-
/**
|
| 179 |
-
* The number of items present in this quote
|
| 180 |
-
*
|
| 181 |
-
* @return integer
|
| 182 |
-
*/
|
| 183 |
-
public function quantity()
|
| 184 |
-
{
|
| 185 |
-
return $this->_quantity;
|
| 186 |
-
}
|
| 187 |
-
|
| 188 |
-
/**
|
| 189 |
-
* The payment currency of this quote
|
| 190 |
-
*
|
| 191 |
-
* @return string
|
| 192 |
-
*/
|
| 193 |
-
public function currency()
|
| 194 |
-
{
|
| 195 |
-
return $this->_currency;
|
| 196 |
-
}
|
| 197 |
-
|
| 198 |
-
/**
|
| 199 |
-
* The price
|
| 200 |
-
* Note that an object is returned, which may consist of multiple components
|
| 201 |
-
*
|
| 202 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Price
|
| 203 |
-
*/
|
| 204 |
-
public function price()
|
| 205 |
-
{
|
| 206 |
-
return $this->_price;
|
| 207 |
-
}
|
| 208 |
-
|
| 209 |
-
/**
|
| 210 |
-
* The weight
|
| 211 |
-
*
|
| 212 |
-
* @return float
|
| 213 |
-
*/
|
| 214 |
-
public function weight()
|
| 215 |
-
{
|
| 216 |
-
return $this->_weight;
|
| 217 |
-
}
|
| 218 |
-
|
| 219 |
-
/**
|
| 220 |
-
* To what storeview does this quote belong
|
| 221 |
-
*
|
| 222 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Storeview
|
| 223 |
-
*/
|
| 224 |
-
public function storeview()
|
| 225 |
-
{
|
| 226 |
-
return $this->_storeview;
|
| 227 |
-
}
|
| 228 |
-
|
| 229 |
-
/**
|
| 230 |
-
* Get the items from the quote
|
| 231 |
-
*
|
| 232 |
-
* @return array
|
| 233 |
-
*/
|
| 234 |
-
public function items()
|
| 235 |
-
{
|
| 236 |
-
return $this->_items;
|
| 237 |
-
}
|
| 238 |
-
|
| 239 |
-
/**
|
| 240 |
-
* The timestamp at which this quote was modified
|
| 241 |
-
*
|
| 242 |
-
* @return string
|
| 243 |
-
*/
|
| 244 |
-
public function timestamp()
|
| 245 |
-
{
|
| 246 |
-
return $this->_timestamp;
|
| 247 |
-
}
|
| 248 |
-
|
| 249 |
-
/**
|
| 250 |
-
* The customer may return null
|
| 251 |
-
*
|
| 252 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Customer|null
|
| 253 |
-
*/
|
| 254 |
-
public function customer()
|
| 255 |
-
{
|
| 256 |
-
if ($this->_customerId) {
|
| 257 |
-
return Mage::getModel('marketingsoftware/abstraction_customer')->loadCustomer($this->_customerId);
|
| 258 |
-
} else {
|
| 259 |
-
return null;
|
| 260 |
-
}
|
| 261 |
-
}
|
| 262 |
-
|
| 263 |
-
/**
|
| 264 |
-
* The addresses of this quote
|
| 265 |
-
*
|
| 266 |
-
* @return array
|
| 267 |
-
*/
|
| 268 |
-
public function addresses()
|
| 269 |
-
{
|
| 270 |
-
return $this->_addresses;
|
| 271 |
-
}
|
| 272 |
-
|
| 273 |
-
/**
|
| 274 |
-
* The IP from which this quote was constructed
|
| 275 |
-
*
|
| 276 |
-
* @return string
|
| 277 |
-
*/
|
| 278 |
-
public function customerIP()
|
| 279 |
-
{
|
| 280 |
-
return $this->_customerIP;
|
| 281 |
-
}
|
| 282 |
-
|
| 283 |
-
/**
|
| 284 |
-
* The shipping method of this quote
|
| 285 |
-
*
|
| 286 |
-
* @return string
|
| 287 |
-
*/
|
| 288 |
-
public function shippingDescription()
|
| 289 |
-
{
|
| 290 |
-
return $this->_shippingDescription;
|
| 291 |
-
}
|
| 292 |
-
|
| 293 |
-
/**
|
| 294 |
-
* The payment method of this quote
|
| 295 |
-
*
|
| 296 |
-
* @return string
|
| 297 |
-
*/
|
| 298 |
-
public function paymentDescription()
|
| 299 |
-
{
|
| 300 |
-
return $this->_paymentDescription;
|
| 301 |
-
}
|
| 302 |
-
|
| 303 |
-
/**
|
| 304 |
-
* Serialize the object
|
| 305 |
-
*
|
| 306 |
-
* @todo Two returns??
|
| 307 |
-
* @return string
|
| 308 |
-
*/
|
| 309 |
-
public function serialize()
|
| 310 |
-
{
|
| 311 |
-
return serialize(array(
|
| 312 |
-
$this->id()
|
| 313 |
-
));
|
| 314 |
-
|
| 315 |
-
return serialize(array(
|
| 316 |
-
$this->id(),
|
| 317 |
-
$this->quantity(),
|
| 318 |
-
$this->currency(),
|
| 319 |
-
$this->timestamp(),
|
| 320 |
-
$this->customerIP(),
|
| 321 |
-
$this->items(),
|
| 322 |
-
$this->storeview(),
|
| 323 |
-
is_object($customer = $this->customer()) ? $customer->id() : null,
|
| 324 |
-
$this->addresses(),
|
| 325 |
-
$this->price(),
|
| 326 |
-
$this->weight(),
|
| 327 |
-
$this->active(),
|
| 328 |
-
$this->shippingDescription(),
|
| 329 |
-
$this->paymentDescription()
|
| 330 |
-
));
|
| 331 |
-
}
|
| 332 |
-
|
| 333 |
-
/**
|
| 334 |
-
* Unserialize the object
|
| 335 |
-
*
|
| 336 |
-
* @todo Two returns??
|
| 337 |
-
* @param string $string
|
| 338 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Quote
|
| 339 |
-
*/
|
| 340 |
-
public function unserialize($string)
|
| 341 |
-
{
|
| 342 |
-
list (
|
| 343 |
-
$this->_quoteId
|
| 344 |
-
) = unserialize($string);
|
| 345 |
-
|
| 346 |
-
$this->loadQuote($this->_quoteId);
|
| 347 |
-
|
| 348 |
-
return $this;
|
| 349 |
-
|
| 350 |
-
list(
|
| 351 |
-
$this->_quoteId,
|
| 352 |
-
$this->_quantity,
|
| 353 |
-
$this->_currency,
|
| 354 |
-
$this->_timestamp,
|
| 355 |
-
$this->_customerIP,
|
| 356 |
-
$this->_items,
|
| 357 |
-
$this->_storeview,
|
| 358 |
-
$this->_customerId,
|
| 359 |
-
$this->_addresses,
|
| 360 |
-
$this->_price,
|
| 361 |
-
$this->_weight,
|
| 362 |
-
$this->_active,
|
| 363 |
-
$this->_shippingDescription,
|
| 364 |
-
$this->_paymentDescription
|
| 365 |
-
) = unserialize($string);
|
| 366 |
-
|
| 367 |
-
return $this;
|
| 368 |
-
}
|
| 369 |
}
|
| 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 Quote
|
| 29 |
+
*/
|
| 30 |
+
class Copernica_MarketingSoftware_Model_Abstraction_Quote implements Serializable
|
| 31 |
+
{
|
| 32 |
+
/**
|
| 33 |
+
* Predefine the internal fields
|
| 34 |
+
*/
|
| 35 |
+
protected $_quoteId;
|
| 36 |
+
protected $_quantity;
|
| 37 |
+
protected $_currency;
|
| 38 |
+
protected $_timestamp;
|
| 39 |
+
protected $_customerIP;
|
| 40 |
+
protected $_items;
|
| 41 |
+
|
| 42 |
+
/**
|
| 43 |
+
* The storeview object
|
| 44 |
+
*
|
| 45 |
+
* @var Copernica_MarketingSoftware_Model_Abstraction_Storeview
|
| 46 |
+
*/
|
| 47 |
+
protected $_storeview;
|
| 48 |
+
|
| 49 |
+
protected $_customerId;
|
| 50 |
+
protected $_addresses;
|
| 51 |
+
protected $_price;
|
| 52 |
+
protected $_weight;
|
| 53 |
+
protected $_active;
|
| 54 |
+
protected $_shippingDescription;
|
| 55 |
+
protected $_paymentDescription;
|
| 56 |
+
|
| 57 |
+
/**
|
| 58 |
+
* Sets the original model
|
| 59 |
+
*
|
| 60 |
+
* @param Mage_Sales_Model_Quote $original
|
| 61 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Quote
|
| 62 |
+
*/
|
| 63 |
+
public function setOriginal(Mage_Sales_Model_Quote $original)
|
| 64 |
+
{
|
| 65 |
+
$this->_quoteId = $original->getId();
|
| 66 |
+
|
| 67 |
+
return $this;
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
/**
|
| 71 |
+
* Loads a quote model
|
| 72 |
+
*
|
| 73 |
+
* @param integer $quoteId
|
| 74 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Quote
|
| 75 |
+
*/
|
| 76 |
+
public function loadQuote($quoteId)
|
| 77 |
+
{
|
| 78 |
+
$quote = Mage::getModel('sales/quote');
|
| 79 |
+
|
| 80 |
+
if (!is_callable($quote, 'loadByIdWithoutStore')) {
|
| 81 |
+
$storeIDs = array();
|
| 82 |
+
|
| 83 |
+
foreach (Mage::app()->getStores() as $id => $store) {
|
| 84 |
+
$storeIDs[] = $id;
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
$quote->setSharedStoreIds($storeIDs);
|
| 88 |
+
$quote->load($quoteId);
|
| 89 |
+
} else {
|
| 90 |
+
$quote->loadByIdWithoutStore($quoteId);
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
if ($quote->getId()) {
|
| 94 |
+
$this->_importFromObject($quote);
|
| 95 |
+
} else {
|
| 96 |
+
$this->_quoteId = $quoteId;
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
return $this;
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
/**
|
| 103 |
+
* Import this abstract from a real magento one
|
| 104 |
+
*
|
| 105 |
+
* @param Mage_Sales_Model_Quote $original
|
| 106 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Quote
|
| 107 |
+
*/
|
| 108 |
+
protected function _importFromObject(Mage_Sales_Model_Quote $original)
|
| 109 |
+
{
|
| 110 |
+
$this->_quoteId = $original->getId();
|
| 111 |
+
$this->_active = (bool) $original->getIsActive();
|
| 112 |
+
$this->_quantity = $original->getItemsQty();
|
| 113 |
+
$this->_currency = $original->getQuoteCurrencyCode();
|
| 114 |
+
$this->_price = Mage::getModel('marketingsoftware/abstraction_price')->setOriginal($original);
|
| 115 |
+
$this->_storeview = Mage::getModel('marketingsoftware/abstraction_storeview')->setOriginal($original->getStore());
|
| 116 |
+
$this->_timestamp = $original->getUpdatedAt();
|
| 117 |
+
$this->_customerIP = $original->getRemoteIp();
|
| 118 |
+
|
| 119 |
+
if ($address = $original->getShippingAddress()) {
|
| 120 |
+
$this->_weight = $address->getWeight();
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
$data = array();
|
| 124 |
+
|
| 125 |
+
$items = $original->getAllVisibleItems();
|
| 126 |
+
|
| 127 |
+
foreach ($items as $item) {
|
| 128 |
+
$data[] = Mage::getModel('marketingsoftware/abstraction_quote_item')->setOriginal($item);
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
$this->_items = $data;
|
| 132 |
+
|
| 133 |
+
if ($customerId = $original->getCustomerId()) {
|
| 134 |
+
$this->_customerId = $customerId;
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
$data = array();
|
| 138 |
+
|
| 139 |
+
$addresses = $original->getAddressesCollection();
|
| 140 |
+
|
| 141 |
+
foreach ($addresses as $address) {
|
| 142 |
+
$data[] = Mage::getModel('marketingsoftware/abstraction_address')->setOriginal($address);
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
$this->_addresses = $data;
|
| 146 |
+
|
| 147 |
+
if ($address = $original->getShippingAddress()) {
|
| 148 |
+
$this->_shippingDescription = $address->getShippingDescription();
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
if ($payment = $original->getPayment()) {
|
| 152 |
+
try {
|
| 153 |
+
$this->_paymentDescription = $payment->getMethodInstance()->getTitle();
|
| 154 |
+
} catch (Mage_Core_Exception $exception) { }
|
| 155 |
+
}
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
/**
|
| 159 |
+
* The quote id of this quote object
|
| 160 |
+
*
|
| 161 |
+
* @return integer
|
| 162 |
+
*/
|
| 163 |
+
public function id()
|
| 164 |
+
{
|
| 165 |
+
return $this->_quoteId;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
/**
|
| 169 |
+
* Is this quote still active
|
| 170 |
+
*
|
| 171 |
+
* @return boolean
|
| 172 |
+
*/
|
| 173 |
+
public function active()
|
| 174 |
+
{
|
| 175 |
+
return $this->_active;
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
/**
|
| 179 |
+
* The number of items present in this quote
|
| 180 |
+
*
|
| 181 |
+
* @return integer
|
| 182 |
+
*/
|
| 183 |
+
public function quantity()
|
| 184 |
+
{
|
| 185 |
+
return $this->_quantity;
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
/**
|
| 189 |
+
* The payment currency of this quote
|
| 190 |
+
*
|
| 191 |
+
* @return string
|
| 192 |
+
*/
|
| 193 |
+
public function currency()
|
| 194 |
+
{
|
| 195 |
+
return $this->_currency;
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
/**
|
| 199 |
+
* The price
|
| 200 |
+
* Note that an object is returned, which may consist of multiple components
|
| 201 |
+
*
|
| 202 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Price
|
| 203 |
+
*/
|
| 204 |
+
public function price()
|
| 205 |
+
{
|
| 206 |
+
return $this->_price;
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
/**
|
| 210 |
+
* The weight
|
| 211 |
+
*
|
| 212 |
+
* @return float
|
| 213 |
+
*/
|
| 214 |
+
public function weight()
|
| 215 |
+
{
|
| 216 |
+
return $this->_weight;
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
/**
|
| 220 |
+
* To what storeview does this quote belong
|
| 221 |
+
*
|
| 222 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Storeview
|
| 223 |
+
*/
|
| 224 |
+
public function storeview()
|
| 225 |
+
{
|
| 226 |
+
return $this->_storeview;
|
| 227 |
+
}
|
| 228 |
+
|
| 229 |
+
/**
|
| 230 |
+
* Get the items from the quote
|
| 231 |
+
*
|
| 232 |
+
* @return array
|
| 233 |
+
*/
|
| 234 |
+
public function items()
|
| 235 |
+
{
|
| 236 |
+
return $this->_items;
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
/**
|
| 240 |
+
* The timestamp at which this quote was modified
|
| 241 |
+
*
|
| 242 |
+
* @return string
|
| 243 |
+
*/
|
| 244 |
+
public function timestamp()
|
| 245 |
+
{
|
| 246 |
+
return $this->_timestamp;
|
| 247 |
+
}
|
| 248 |
+
|
| 249 |
+
/**
|
| 250 |
+
* The customer may return null
|
| 251 |
+
*
|
| 252 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Customer|null
|
| 253 |
+
*/
|
| 254 |
+
public function customer()
|
| 255 |
+
{
|
| 256 |
+
if ($this->_customerId) {
|
| 257 |
+
return Mage::getModel('marketingsoftware/abstraction_customer')->loadCustomer($this->_customerId);
|
| 258 |
+
} else {
|
| 259 |
+
return null;
|
| 260 |
+
}
|
| 261 |
+
}
|
| 262 |
+
|
| 263 |
+
/**
|
| 264 |
+
* The addresses of this quote
|
| 265 |
+
*
|
| 266 |
+
* @return array
|
| 267 |
+
*/
|
| 268 |
+
public function addresses()
|
| 269 |
+
{
|
| 270 |
+
return $this->_addresses;
|
| 271 |
+
}
|
| 272 |
+
|
| 273 |
+
/**
|
| 274 |
+
* The IP from which this quote was constructed
|
| 275 |
+
*
|
| 276 |
+
* @return string
|
| 277 |
+
*/
|
| 278 |
+
public function customerIP()
|
| 279 |
+
{
|
| 280 |
+
return $this->_customerIP;
|
| 281 |
+
}
|
| 282 |
+
|
| 283 |
+
/**
|
| 284 |
+
* The shipping method of this quote
|
| 285 |
+
*
|
| 286 |
+
* @return string
|
| 287 |
+
*/
|
| 288 |
+
public function shippingDescription()
|
| 289 |
+
{
|
| 290 |
+
return $this->_shippingDescription;
|
| 291 |
+
}
|
| 292 |
+
|
| 293 |
+
/**
|
| 294 |
+
* The payment method of this quote
|
| 295 |
+
*
|
| 296 |
+
* @return string
|
| 297 |
+
*/
|
| 298 |
+
public function paymentDescription()
|
| 299 |
+
{
|
| 300 |
+
return $this->_paymentDescription;
|
| 301 |
+
}
|
| 302 |
+
|
| 303 |
+
/**
|
| 304 |
+
* Serialize the object
|
| 305 |
+
*
|
| 306 |
+
* @todo Two returns??
|
| 307 |
+
* @return string
|
| 308 |
+
*/
|
| 309 |
+
public function serialize()
|
| 310 |
+
{
|
| 311 |
+
return serialize(array(
|
| 312 |
+
$this->id()
|
| 313 |
+
));
|
| 314 |
+
|
| 315 |
+
return serialize(array(
|
| 316 |
+
$this->id(),
|
| 317 |
+
$this->quantity(),
|
| 318 |
+
$this->currency(),
|
| 319 |
+
$this->timestamp(),
|
| 320 |
+
$this->customerIP(),
|
| 321 |
+
$this->items(),
|
| 322 |
+
$this->storeview(),
|
| 323 |
+
is_object($customer = $this->customer()) ? $customer->id() : null,
|
| 324 |
+
$this->addresses(),
|
| 325 |
+
$this->price(),
|
| 326 |
+
$this->weight(),
|
| 327 |
+
$this->active(),
|
| 328 |
+
$this->shippingDescription(),
|
| 329 |
+
$this->paymentDescription()
|
| 330 |
+
));
|
| 331 |
+
}
|
| 332 |
+
|
| 333 |
+
/**
|
| 334 |
+
* Unserialize the object
|
| 335 |
+
*
|
| 336 |
+
* @todo Two returns??
|
| 337 |
+
* @param string $string
|
| 338 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Quote
|
| 339 |
+
*/
|
| 340 |
+
public function unserialize($string)
|
| 341 |
+
{
|
| 342 |
+
list (
|
| 343 |
+
$this->_quoteId
|
| 344 |
+
) = unserialize($string);
|
| 345 |
+
|
| 346 |
+
$this->loadQuote($this->_quoteId);
|
| 347 |
+
|
| 348 |
+
return $this;
|
| 349 |
+
|
| 350 |
+
list(
|
| 351 |
+
$this->_quoteId,
|
| 352 |
+
$this->_quantity,
|
| 353 |
+
$this->_currency,
|
| 354 |
+
$this->_timestamp,
|
| 355 |
+
$this->_customerIP,
|
| 356 |
+
$this->_items,
|
| 357 |
+
$this->_storeview,
|
| 358 |
+
$this->_customerId,
|
| 359 |
+
$this->_addresses,
|
| 360 |
+
$this->_price,
|
| 361 |
+
$this->_weight,
|
| 362 |
+
$this->_active,
|
| 363 |
+
$this->_shippingDescription,
|
| 364 |
+
$this->_paymentDescription
|
| 365 |
+
) = unserialize($string);
|
| 366 |
+
|
| 367 |
+
return $this;
|
| 368 |
+
}
|
| 369 |
}
|
app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Quote/Item.php
CHANGED
|
@@ -1,212 +1,212 @@
|
|
| 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 Quote Item
|
| 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;
|
| 40 |
-
protected $_timestamp;
|
| 41 |
-
protected $_options;
|
| 42 |
-
protected $_product;
|
| 43 |
-
|
| 44 |
-
/**
|
| 45 |
-
* Sets the original model
|
| 46 |
-
*
|
| 47 |
-
* @param Mage_Sales_Model_Quote_Item $original
|
| 48 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Quote_Item
|
| 49 |
-
*/
|
| 50 |
-
public function setOriginal(Mage_Sales_Model_Quote_Item $original)
|
| 51 |
-
{
|
| 52 |
-
$this->_id = $original->getId();
|
| 53 |
-
$this->_quantity = $original->getQty();
|
| 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_quote_item_options')->setOriginal($original);
|
| 60 |
-
|
| 61 |
-
if ($options->attributes()) {
|
| 62 |
-
$this->_options = $options;
|
| 63 |
-
}
|
| 64 |
-
|
| 65 |
-
if ($quote = $original->getQuote()) {
|
| 66 |
-
$this->_quoteId = $quote->getId();
|
| 67 |
-
}
|
| 68 |
-
|
| 69 |
-
return $this;
|
| 70 |
-
}
|
| 71 |
-
|
| 72 |
-
/**
|
| 73 |
-
* The id of this quote item object
|
| 74 |
-
*
|
| 75 |
-
* @return integer
|
| 76 |
-
*/
|
| 77 |
-
public function id()
|
| 78 |
-
{
|
| 79 |
-
return $this->_id;
|
| 80 |
-
}
|
| 81 |
-
|
| 82 |
-
/**
|
| 83 |
-
* Get the quote to which this item belongs
|
| 84 |
-
*
|
| 85 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Quote
|
| 86 |
-
*/
|
| 87 |
-
public function quote()
|
| 88 |
-
{
|
| 89 |
-
return Mage::getModel('marketingsoftware/abstraction_quote')->loadQuote($this->_quoteId);
|
| 90 |
-
}
|
| 91 |
-
|
| 92 |
-
/**
|
| 93 |
-
* The amount of this quote item
|
| 94 |
-
*
|
| 95 |
-
* @return integer
|
| 96 |
-
*/
|
| 97 |
-
public function quantity()
|
| 98 |
-
{
|
| 99 |
-
return $this->_quantity;
|
| 100 |
-
}
|
| 101 |
-
|
| 102 |
-
/**
|
| 103 |
-
* The price
|
| 104 |
-
* Note that an object is returned, which may consist of multiple components
|
| 105 |
-
*
|
| 106 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Price
|
| 107 |
-
*/
|
| 108 |
-
public function price()
|
| 109 |
-
{
|
| 110 |
-
return $this->_price;
|
| 111 |
-
}
|
| 112 |
-
|
| 113 |
-
/**
|
| 114 |
-
* The weight
|
| 115 |
-
*
|
| 116 |
-
* @return float
|
| 117 |
-
*/
|
| 118 |
-
public function weight()
|
| 119 |
-
{
|
| 120 |
-
return $this->_weight;
|
| 121 |
-
}
|
| 122 |
-
|
| 123 |
-
/**
|
| 124 |
-
* The timestamp at which this quote item was modified
|
| 125 |
-
*
|
| 126 |
-
* @return string
|
| 127 |
-
*/
|
| 128 |
-
public function timestamp()
|
| 129 |
-
{
|
| 130 |
-
return $this->_timestamp;
|
| 131 |
-
}
|
| 132 |
-
|
| 133 |
-
/**
|
| 134 |
-
* Get the options of this quote item
|
| 135 |
-
*
|
| 136 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Quote_Item_Options
|
| 137 |
-
*/
|
| 138 |
-
public function options()
|
| 139 |
-
{
|
| 140 |
-
return $this->_options;
|
| 141 |
-
}
|
| 142 |
-
|
| 143 |
-
/**
|
| 144 |
-
* Get the product which belongs to this item
|
| 145 |
-
*
|
| 146 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Product
|
| 147 |
-
*/
|
| 148 |
-
public function product()
|
| 149 |
-
{
|
| 150 |
-
return $this->_product;
|
| 151 |
-
}
|
| 152 |
-
|
| 153 |
-
/**
|
| 154 |
-
* Loads a product model
|
| 155 |
-
*
|
| 156 |
-
* @param integer $productId
|
| 157 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Product
|
| 158 |
-
*/
|
| 159 |
-
public function loadQuoteItem($quoteId)
|
| 160 |
-
{
|
| 161 |
-
$quoteItem = Mage::getModel('sales/quote_item')->load($quoteId);
|
| 162 |
-
|
| 163 |
-
if ($quoteItem->getId()) {
|
| 164 |
-
$this->setOriginal($quoteItem);
|
| 165 |
-
} else {
|
| 166 |
-
$this->id = $quoteId;
|
| 167 |
-
}
|
| 168 |
-
|
| 169 |
-
return $this;
|
| 170 |
-
}
|
| 171 |
-
|
| 172 |
-
/**
|
| 173 |
-
* Serialize the object
|
| 174 |
-
*
|
| 175 |
-
* @return string
|
| 176 |
-
*/
|
| 177 |
-
public function serialize()
|
| 178 |
-
{
|
| 179 |
-
return serialize(array(
|
| 180 |
-
$this->id(),
|
| 181 |
-
is_object($quote = $this->quote()) ? $quote->id() : null,
|
| 182 |
-
$this->quantity(),
|
| 183 |
-
$this->price(),
|
| 184 |
-
$this->weight(),
|
| 185 |
-
$this->timestamp(),
|
| 186 |
-
$this->options(),
|
| 187 |
-
$this->product(),
|
| 188 |
-
));
|
| 189 |
-
}
|
| 190 |
-
|
| 191 |
-
/**
|
| 192 |
-
* Unserialize the object
|
| 193 |
-
*
|
| 194 |
-
* @param string $string
|
| 195 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Quote_Item
|
| 196 |
-
*/
|
| 197 |
-
public function unserialize($string)
|
| 198 |
-
{
|
| 199 |
-
list(
|
| 200 |
-
$this->_id,
|
| 201 |
-
$this->_quoteId,
|
| 202 |
-
$this->_quantity,
|
| 203 |
-
$this->_price,
|
| 204 |
-
$this->_weight,
|
| 205 |
-
$this->_timestamp,
|
| 206 |
-
$this->_options,
|
| 207 |
-
$this->_product
|
| 208 |
-
) = unserialize($string);
|
| 209 |
-
|
| 210 |
-
return $this;
|
| 211 |
-
}
|
| 212 |
}
|
| 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 Quote Item
|
| 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;
|
| 40 |
+
protected $_timestamp;
|
| 41 |
+
protected $_options;
|
| 42 |
+
protected $_product;
|
| 43 |
+
|
| 44 |
+
/**
|
| 45 |
+
* Sets the original model
|
| 46 |
+
*
|
| 47 |
+
* @param Mage_Sales_Model_Quote_Item $original
|
| 48 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Quote_Item
|
| 49 |
+
*/
|
| 50 |
+
public function setOriginal(Mage_Sales_Model_Quote_Item $original)
|
| 51 |
+
{
|
| 52 |
+
$this->_id = $original->getId();
|
| 53 |
+
$this->_quantity = $original->getQty();
|
| 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_quote_item_options')->setOriginal($original);
|
| 60 |
+
|
| 61 |
+
if ($options->attributes()) {
|
| 62 |
+
$this->_options = $options;
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
if ($quote = $original->getQuote()) {
|
| 66 |
+
$this->_quoteId = $quote->getId();
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
return $this;
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
/**
|
| 73 |
+
* The id of this quote item object
|
| 74 |
+
*
|
| 75 |
+
* @return integer
|
| 76 |
+
*/
|
| 77 |
+
public function id()
|
| 78 |
+
{
|
| 79 |
+
return $this->_id;
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
/**
|
| 83 |
+
* Get the quote to which this item belongs
|
| 84 |
+
*
|
| 85 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Quote
|
| 86 |
+
*/
|
| 87 |
+
public function quote()
|
| 88 |
+
{
|
| 89 |
+
return Mage::getModel('marketingsoftware/abstraction_quote')->loadQuote($this->_quoteId);
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
/**
|
| 93 |
+
* The amount of this quote item
|
| 94 |
+
*
|
| 95 |
+
* @return integer
|
| 96 |
+
*/
|
| 97 |
+
public function quantity()
|
| 98 |
+
{
|
| 99 |
+
return $this->_quantity;
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
/**
|
| 103 |
+
* The price
|
| 104 |
+
* Note that an object is returned, which may consist of multiple components
|
| 105 |
+
*
|
| 106 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Price
|
| 107 |
+
*/
|
| 108 |
+
public function price()
|
| 109 |
+
{
|
| 110 |
+
return $this->_price;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
/**
|
| 114 |
+
* The weight
|
| 115 |
+
*
|
| 116 |
+
* @return float
|
| 117 |
+
*/
|
| 118 |
+
public function weight()
|
| 119 |
+
{
|
| 120 |
+
return $this->_weight;
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
/**
|
| 124 |
+
* The timestamp at which this quote item was modified
|
| 125 |
+
*
|
| 126 |
+
* @return string
|
| 127 |
+
*/
|
| 128 |
+
public function timestamp()
|
| 129 |
+
{
|
| 130 |
+
return $this->_timestamp;
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
/**
|
| 134 |
+
* Get the options of this quote item
|
| 135 |
+
*
|
| 136 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Quote_Item_Options
|
| 137 |
+
*/
|
| 138 |
+
public function options()
|
| 139 |
+
{
|
| 140 |
+
return $this->_options;
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
/**
|
| 144 |
+
* Get the product which belongs to this item
|
| 145 |
+
*
|
| 146 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Product
|
| 147 |
+
*/
|
| 148 |
+
public function product()
|
| 149 |
+
{
|
| 150 |
+
return $this->_product;
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
/**
|
| 154 |
+
* Loads a product model
|
| 155 |
+
*
|
| 156 |
+
* @param integer $productId
|
| 157 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Product
|
| 158 |
+
*/
|
| 159 |
+
public function loadQuoteItem($quoteId)
|
| 160 |
+
{
|
| 161 |
+
$quoteItem = Mage::getModel('sales/quote_item')->load($quoteId);
|
| 162 |
+
|
| 163 |
+
if ($quoteItem->getId()) {
|
| 164 |
+
$this->setOriginal($quoteItem);
|
| 165 |
+
} else {
|
| 166 |
+
$this->id = $quoteId;
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
return $this;
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
/**
|
| 173 |
+
* Serialize the object
|
| 174 |
+
*
|
| 175 |
+
* @return string
|
| 176 |
+
*/
|
| 177 |
+
public function serialize()
|
| 178 |
+
{
|
| 179 |
+
return serialize(array(
|
| 180 |
+
$this->id(),
|
| 181 |
+
is_object($quote = $this->quote()) ? $quote->id() : null,
|
| 182 |
+
$this->quantity(),
|
| 183 |
+
$this->price(),
|
| 184 |
+
$this->weight(),
|
| 185 |
+
$this->timestamp(),
|
| 186 |
+
$this->options(),
|
| 187 |
+
$this->product(),
|
| 188 |
+
));
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
/**
|
| 192 |
+
* Unserialize the object
|
| 193 |
+
*
|
| 194 |
+
* @param string $string
|
| 195 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Quote_Item
|
| 196 |
+
*/
|
| 197 |
+
public function unserialize($string)
|
| 198 |
+
{
|
| 199 |
+
list(
|
| 200 |
+
$this->_id,
|
| 201 |
+
$this->_quoteId,
|
| 202 |
+
$this->_quantity,
|
| 203 |
+
$this->_price,
|
| 204 |
+
$this->_weight,
|
| 205 |
+
$this->_timestamp,
|
| 206 |
+
$this->_options,
|
| 207 |
+
$this->_product
|
| 208 |
+
) = unserialize($string);
|
| 209 |
+
|
| 210 |
+
return $this;
|
| 211 |
+
}
|
| 212 |
}
|
app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Quote/Item/Options.php
CHANGED
|
@@ -1,163 +1,163 @@
|
|
| 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 quote item options
|
| 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 |
-
/**
|
| 40 |
-
* Sets the original model
|
| 41 |
-
*
|
| 42 |
-
* @param Mage_Sales_Model_Quote_Item $original
|
| 43 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Quote_Item_Options
|
| 44 |
-
*/
|
| 45 |
-
public function setOriginal(Mage_Sales_Model_Quote_Item $original)
|
| 46 |
-
{
|
| 47 |
-
$this->_name = $original->getName();
|
| 48 |
-
|
| 49 |
-
$data = array();
|
| 50 |
-
|
| 51 |
-
if ($optionData = $original->getOptionByCode('info_buyRequest')) {
|
| 52 |
-
$product = $optionData->getProduct();
|
| 53 |
-
|
| 54 |
-
$options = $original->getProduct()->getTypeInstance(true)->getOrderOptions($original->getProduct());
|
| 55 |
-
|
| 56 |
-
$attributes = array();
|
| 57 |
-
|
| 58 |
-
if (isset($options['attributes_info'])) {
|
| 59 |
-
$attributes = $options['attributes_info'];
|
| 60 |
-
} elseif (isset($options['bundle_options'])) {
|
| 61 |
-
$attributes = $options['bundle_options'];
|
| 62 |
-
} elseif (isset($options['options'])) {
|
| 63 |
-
$attributes = $options['options'];
|
| 64 |
-
}
|
| 65 |
-
|
| 66 |
-
if ($attributes) {
|
| 67 |
-
foreach ($attributes as $attribute) {
|
| 68 |
-
$data[$attribute['label']] = $attribute['value'];
|
| 69 |
-
}
|
| 70 |
-
|
| 71 |
-
$this->_attributes = $data;
|
| 72 |
-
}
|
| 73 |
-
}
|
| 74 |
-
|
| 75 |
-
return $this;
|
| 76 |
-
}
|
| 77 |
-
|
| 78 |
-
/**
|
| 79 |
-
* The name of this set of options
|
| 80 |
-
*
|
| 81 |
-
* @return integer
|
| 82 |
-
*/
|
| 83 |
-
public function name()
|
| 84 |
-
{
|
| 85 |
-
return $this->_name;
|
| 86 |
-
}
|
| 87 |
-
|
| 88 |
-
/**
|
| 89 |
-
* Return an assoc array with attributes
|
| 90 |
-
*
|
| 91 |
-
* @return array
|
| 92 |
-
*/
|
| 93 |
-
public function attributes()
|
| 94 |
-
{
|
| 95 |
-
return $this->_attributes;
|
| 96 |
-
}
|
| 97 |
-
|
| 98 |
-
/**
|
| 99 |
-
* Return a string representation
|
| 100 |
-
*
|
| 101 |
-
* @return string
|
| 102 |
-
*/
|
| 103 |
-
public function __toString()
|
| 104 |
-
{
|
| 105 |
-
return $this->_arrayToString($this->_attributes());
|
| 106 |
-
}
|
| 107 |
-
|
| 108 |
-
/**
|
| 109 |
-
* Return a string representation of an array
|
| 110 |
-
*
|
| 111 |
-
* @param array $value
|
| 112 |
-
* @param string $prefix
|
| 113 |
-
* @return string
|
| 114 |
-
*/
|
| 115 |
-
protected function _arrayToString($value, $prefix = '')
|
| 116 |
-
{
|
| 117 |
-
$string = "";
|
| 118 |
-
|
| 119 |
-
foreach ($value as $key => $value) {
|
| 120 |
-
if (is_array($value)) {
|
| 121 |
-
if (isset($value[0]) && count($value) == 1) {
|
| 122 |
-
$value = $value[0];
|
| 123 |
-
}
|
| 124 |
-
|
| 125 |
-
$string .= $prefix.$key.":\n".$this->_arrayToString($value, $prefix.' ');
|
| 126 |
-
} else {
|
| 127 |
-
$string.= $prefix.$key.": $value\n";
|
| 128 |
-
}
|
| 129 |
-
}
|
| 130 |
-
|
| 131 |
-
return $string;
|
| 132 |
-
}
|
| 133 |
-
|
| 134 |
-
/**
|
| 135 |
-
* Serialize the object
|
| 136 |
-
*
|
| 137 |
-
* @return string
|
| 138 |
-
*/
|
| 139 |
-
public function serialize()
|
| 140 |
-
{
|
| 141 |
-
return serialize(array(
|
| 142 |
-
$this->name(),
|
| 143 |
-
$this->attributes(),
|
| 144 |
-
));
|
| 145 |
-
}
|
| 146 |
-
|
| 147 |
-
/**
|
| 148 |
-
* Unserialize the object
|
| 149 |
-
*
|
| 150 |
-
* @param string $string
|
| 151 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Quote_Item_Options
|
| 152 |
-
*/
|
| 153 |
-
public function unserialize($string)
|
| 154 |
-
{
|
| 155 |
-
list(
|
| 156 |
-
$this->_name,
|
| 157 |
-
$this->_attributes
|
| 158 |
-
) = unserialize($string);
|
| 159 |
-
|
| 160 |
-
return $this;
|
| 161 |
-
}
|
| 162 |
-
}
|
| 163 |
-
|
| 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 quote item options
|
| 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 |
+
/**
|
| 40 |
+
* Sets the original model
|
| 41 |
+
*
|
| 42 |
+
* @param Mage_Sales_Model_Quote_Item $original
|
| 43 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Quote_Item_Options
|
| 44 |
+
*/
|
| 45 |
+
public function setOriginal(Mage_Sales_Model_Quote_Item $original)
|
| 46 |
+
{
|
| 47 |
+
$this->_name = $original->getName();
|
| 48 |
+
|
| 49 |
+
$data = array();
|
| 50 |
+
|
| 51 |
+
if ($optionData = $original->getOptionByCode('info_buyRequest')) {
|
| 52 |
+
$product = $optionData->getProduct();
|
| 53 |
+
|
| 54 |
+
$options = $original->getProduct()->getTypeInstance(true)->getOrderOptions($original->getProduct());
|
| 55 |
+
|
| 56 |
+
$attributes = array();
|
| 57 |
+
|
| 58 |
+
if (isset($options['attributes_info'])) {
|
| 59 |
+
$attributes = $options['attributes_info'];
|
| 60 |
+
} elseif (isset($options['bundle_options'])) {
|
| 61 |
+
$attributes = $options['bundle_options'];
|
| 62 |
+
} elseif (isset($options['options'])) {
|
| 63 |
+
$attributes = $options['options'];
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
if ($attributes) {
|
| 67 |
+
foreach ($attributes as $attribute) {
|
| 68 |
+
$data[$attribute['label']] = $attribute['value'];
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
$this->_attributes = $data;
|
| 72 |
+
}
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
return $this;
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
/**
|
| 79 |
+
* The name of this set of options
|
| 80 |
+
*
|
| 81 |
+
* @return integer
|
| 82 |
+
*/
|
| 83 |
+
public function name()
|
| 84 |
+
{
|
| 85 |
+
return $this->_name;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
/**
|
| 89 |
+
* Return an assoc array with attributes
|
| 90 |
+
*
|
| 91 |
+
* @return array
|
| 92 |
+
*/
|
| 93 |
+
public function attributes()
|
| 94 |
+
{
|
| 95 |
+
return $this->_attributes;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
/**
|
| 99 |
+
* Return a string representation
|
| 100 |
+
*
|
| 101 |
+
* @return string
|
| 102 |
+
*/
|
| 103 |
+
public function __toString()
|
| 104 |
+
{
|
| 105 |
+
return $this->_arrayToString($this->_attributes());
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
/**
|
| 109 |
+
* Return a string representation of an array
|
| 110 |
+
*
|
| 111 |
+
* @param array $value
|
| 112 |
+
* @param string $prefix
|
| 113 |
+
* @return string
|
| 114 |
+
*/
|
| 115 |
+
protected function _arrayToString($value, $prefix = '')
|
| 116 |
+
{
|
| 117 |
+
$string = "";
|
| 118 |
+
|
| 119 |
+
foreach ($value as $key => $value) {
|
| 120 |
+
if (is_array($value)) {
|
| 121 |
+
if (isset($value[0]) && count($value) == 1) {
|
| 122 |
+
$value = $value[0];
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
$string .= $prefix.$key.":\n".$this->_arrayToString($value, $prefix.' ');
|
| 126 |
+
} else {
|
| 127 |
+
$string.= $prefix.$key.": $value\n";
|
| 128 |
+
}
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
return $string;
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
/**
|
| 135 |
+
* Serialize the object
|
| 136 |
+
*
|
| 137 |
+
* @return string
|
| 138 |
+
*/
|
| 139 |
+
public function serialize()
|
| 140 |
+
{
|
| 141 |
+
return serialize(array(
|
| 142 |
+
$this->name(),
|
| 143 |
+
$this->attributes(),
|
| 144 |
+
));
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
/**
|
| 148 |
+
* Unserialize the object
|
| 149 |
+
*
|
| 150 |
+
* @param string $string
|
| 151 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Quote_Item_Options
|
| 152 |
+
*/
|
| 153 |
+
public function unserialize($string)
|
| 154 |
+
{
|
| 155 |
+
list(
|
| 156 |
+
$this->_name,
|
| 157 |
+
$this->_attributes
|
| 158 |
+
) = unserialize($string);
|
| 159 |
+
|
| 160 |
+
return $this;
|
| 161 |
+
}
|
| 162 |
+
}
|
| 163 |
+
|
app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Storeview.php
CHANGED
|
@@ -1,186 +1,186 @@
|
|
| 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 Store
|
| 29 |
-
*/
|
| 30 |
-
class Copernica_MarketingSoftware_Model_Abstraction_Storeview implements Serializable
|
| 31 |
-
{
|
| 32 |
-
/**
|
| 33 |
-
* Predefine the internal fields
|
| 34 |
-
*/
|
| 35 |
-
protected $_id;
|
| 36 |
-
protected $_websiteCode;
|
| 37 |
-
protected $_websiteLabel;
|
| 38 |
-
protected $_storeCode;
|
| 39 |
-
protected $_storeLabel;
|
| 40 |
-
protected $_viewCode;
|
| 41 |
-
protected $_viewLabel;
|
| 42 |
-
|
| 43 |
-
/**
|
| 44 |
-
* Sets the original model
|
| 45 |
-
*
|
| 46 |
-
* @param Mage_Core_Model_Store $original
|
| 47 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Storeview
|
| 48 |
-
*/
|
| 49 |
-
public function setOriginal(Mage_Core_Model_Store $original)
|
| 50 |
-
{
|
| 51 |
-
if ($original->getWebsite() instanceof Mage_Core_Model_Website) {
|
| 52 |
-
$this->_id = $original->getId();
|
| 53 |
-
$this->_websiteCode = $original->getWebsite()->getCode();
|
| 54 |
-
$this->_websiteLabel = $original->getWebsite()->getName();
|
| 55 |
-
$this->_storeCode = $original->getGroup()->getId();
|
| 56 |
-
$this->_storeLabel = $original->getGroup()->getName();
|
| 57 |
-
$this->_viewCode = $original->getCode();
|
| 58 |
-
$this->_viewLabel = $original->getName();
|
| 59 |
-
}
|
| 60 |
-
|
| 61 |
-
return $this;
|
| 62 |
-
}
|
| 63 |
-
|
| 64 |
-
/**
|
| 65 |
-
* Return the id for the storeview
|
| 66 |
-
*
|
| 67 |
-
* @return int
|
| 68 |
-
*/
|
| 69 |
-
public function id()
|
| 70 |
-
{
|
| 71 |
-
return $this->_id;
|
| 72 |
-
}
|
| 73 |
-
|
| 74 |
-
/**
|
| 75 |
-
* Return the code for the website
|
| 76 |
-
*
|
| 77 |
-
* @return string
|
| 78 |
-
*/
|
| 79 |
-
public function websiteCode()
|
| 80 |
-
{
|
| 81 |
-
return $this->_websiteCode;
|
| 82 |
-
}
|
| 83 |
-
|
| 84 |
-
/**
|
| 85 |
-
* Return the label for the website
|
| 86 |
-
*
|
| 87 |
-
* @return string
|
| 88 |
-
*/
|
| 89 |
-
public function websiteLabel()
|
| 90 |
-
{
|
| 91 |
-
return $this->_websiteLabel;
|
| 92 |
-
}
|
| 93 |
-
|
| 94 |
-
/**
|
| 95 |
-
* Return the code for the store
|
| 96 |
-
*
|
| 97 |
-
* @return string
|
| 98 |
-
*/
|
| 99 |
-
public function storeCode()
|
| 100 |
-
{
|
| 101 |
-
return $this->_storeCode;
|
| 102 |
-
}
|
| 103 |
-
|
| 104 |
-
/**
|
| 105 |
-
* Return the label for the store
|
| 106 |
-
*
|
| 107 |
-
* @return string
|
| 108 |
-
*/
|
| 109 |
-
public function storeLabel()
|
| 110 |
-
{
|
| 111 |
-
return $this->_storeLabel;
|
| 112 |
-
}
|
| 113 |
-
|
| 114 |
-
/**
|
| 115 |
-
* Return the code for the store
|
| 116 |
-
*
|
| 117 |
-
* @return string
|
| 118 |
-
*/
|
| 119 |
-
public function viewCode()
|
| 120 |
-
{
|
| 121 |
-
return $this->_viewCode;
|
| 122 |
-
}
|
| 123 |
-
|
| 124 |
-
/**
|
| 125 |
-
* Return the label for the store
|
| 126 |
-
*
|
| 127 |
-
* @return string
|
| 128 |
-
*/
|
| 129 |
-
public function viewLabel()
|
| 130 |
-
{
|
| 131 |
-
return $this->_viewLabel;
|
| 132 |
-
}
|
| 133 |
-
|
| 134 |
-
/**
|
| 135 |
-
* Convert this value to a string
|
| 136 |
-
*
|
| 137 |
-
* @return String
|
| 138 |
-
*/
|
| 139 |
-
public function __toString()
|
| 140 |
-
{
|
| 141 |
-
return implode(' > ', array(
|
| 142 |
-
$this->websiteLabel(),
|
| 143 |
-
$this->storeLabel(),
|
| 144 |
-
$this->viewLabel(),
|
| 145 |
-
));
|
| 146 |
-
}
|
| 147 |
-
|
| 148 |
-
/**
|
| 149 |
-
* Serialize the object
|
| 150 |
-
*
|
| 151 |
-
* @return string
|
| 152 |
-
*/
|
| 153 |
-
public function serialize()
|
| 154 |
-
{
|
| 155 |
-
return serialize(array(
|
| 156 |
-
$this->id(),
|
| 157 |
-
$this->websiteCode(),
|
| 158 |
-
$this->websiteLabel(),
|
| 159 |
-
$this->storeCode(),
|
| 160 |
-
$this->storeLabel(),
|
| 161 |
-
$this->viewCode(),
|
| 162 |
-
$this->viewLabel(),
|
| 163 |
-
));
|
| 164 |
-
}
|
| 165 |
-
|
| 166 |
-
/**
|
| 167 |
-
* Unserialize the object
|
| 168 |
-
*
|
| 169 |
-
* @param string $string
|
| 170 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Storeview
|
| 171 |
-
*/
|
| 172 |
-
public function unserialize($string)
|
| 173 |
-
{
|
| 174 |
-
list(
|
| 175 |
-
$this->_id,
|
| 176 |
-
$this->_websiteCode,
|
| 177 |
-
$this->_websiteLabel,
|
| 178 |
-
$this->_storeCode,
|
| 179 |
-
$this->_storeLabel,
|
| 180 |
-
$this->_viewCode,
|
| 181 |
-
$this->_viewLabel
|
| 182 |
-
) = unserialize($string);
|
| 183 |
-
|
| 184 |
-
return $this;
|
| 185 |
-
}
|
| 186 |
}
|
| 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 Store
|
| 29 |
+
*/
|
| 30 |
+
class Copernica_MarketingSoftware_Model_Abstraction_Storeview implements Serializable
|
| 31 |
+
{
|
| 32 |
+
/**
|
| 33 |
+
* Predefine the internal fields
|
| 34 |
+
*/
|
| 35 |
+
protected $_id;
|
| 36 |
+
protected $_websiteCode;
|
| 37 |
+
protected $_websiteLabel;
|
| 38 |
+
protected $_storeCode;
|
| 39 |
+
protected $_storeLabel;
|
| 40 |
+
protected $_viewCode;
|
| 41 |
+
protected $_viewLabel;
|
| 42 |
+
|
| 43 |
+
/**
|
| 44 |
+
* Sets the original model
|
| 45 |
+
*
|
| 46 |
+
* @param Mage_Core_Model_Store $original
|
| 47 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Storeview
|
| 48 |
+
*/
|
| 49 |
+
public function setOriginal(Mage_Core_Model_Store $original)
|
| 50 |
+
{
|
| 51 |
+
if ($original->getWebsite() instanceof Mage_Core_Model_Website) {
|
| 52 |
+
$this->_id = $original->getId();
|
| 53 |
+
$this->_websiteCode = $original->getWebsite()->getCode();
|
| 54 |
+
$this->_websiteLabel = $original->getWebsite()->getName();
|
| 55 |
+
$this->_storeCode = $original->getGroup()->getId();
|
| 56 |
+
$this->_storeLabel = $original->getGroup()->getName();
|
| 57 |
+
$this->_viewCode = $original->getCode();
|
| 58 |
+
$this->_viewLabel = $original->getName();
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
return $this;
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
/**
|
| 65 |
+
* Return the id for the storeview
|
| 66 |
+
*
|
| 67 |
+
* @return int
|
| 68 |
+
*/
|
| 69 |
+
public function id()
|
| 70 |
+
{
|
| 71 |
+
return $this->_id;
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
/**
|
| 75 |
+
* Return the code for the website
|
| 76 |
+
*
|
| 77 |
+
* @return string
|
| 78 |
+
*/
|
| 79 |
+
public function websiteCode()
|
| 80 |
+
{
|
| 81 |
+
return $this->_websiteCode;
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
/**
|
| 85 |
+
* Return the label for the website
|
| 86 |
+
*
|
| 87 |
+
* @return string
|
| 88 |
+
*/
|
| 89 |
+
public function websiteLabel()
|
| 90 |
+
{
|
| 91 |
+
return $this->_websiteLabel;
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
/**
|
| 95 |
+
* Return the code for the store
|
| 96 |
+
*
|
| 97 |
+
* @return string
|
| 98 |
+
*/
|
| 99 |
+
public function storeCode()
|
| 100 |
+
{
|
| 101 |
+
return $this->_storeCode;
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
/**
|
| 105 |
+
* Return the label for the store
|
| 106 |
+
*
|
| 107 |
+
* @return string
|
| 108 |
+
*/
|
| 109 |
+
public function storeLabel()
|
| 110 |
+
{
|
| 111 |
+
return $this->_storeLabel;
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
/**
|
| 115 |
+
* Return the code for the store
|
| 116 |
+
*
|
| 117 |
+
* @return string
|
| 118 |
+
*/
|
| 119 |
+
public function viewCode()
|
| 120 |
+
{
|
| 121 |
+
return $this->_viewCode;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
/**
|
| 125 |
+
* Return the label for the store
|
| 126 |
+
*
|
| 127 |
+
* @return string
|
| 128 |
+
*/
|
| 129 |
+
public function viewLabel()
|
| 130 |
+
{
|
| 131 |
+
return $this->_viewLabel;
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
/**
|
| 135 |
+
* Convert this value to a string
|
| 136 |
+
*
|
| 137 |
+
* @return String
|
| 138 |
+
*/
|
| 139 |
+
public function __toString()
|
| 140 |
+
{
|
| 141 |
+
return implode(' > ', array(
|
| 142 |
+
$this->websiteLabel(),
|
| 143 |
+
$this->storeLabel(),
|
| 144 |
+
$this->viewLabel(),
|
| 145 |
+
));
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
/**
|
| 149 |
+
* Serialize the object
|
| 150 |
+
*
|
| 151 |
+
* @return string
|
| 152 |
+
*/
|
| 153 |
+
public function serialize()
|
| 154 |
+
{
|
| 155 |
+
return serialize(array(
|
| 156 |
+
$this->id(),
|
| 157 |
+
$this->websiteCode(),
|
| 158 |
+
$this->websiteLabel(),
|
| 159 |
+
$this->storeCode(),
|
| 160 |
+
$this->storeLabel(),
|
| 161 |
+
$this->viewCode(),
|
| 162 |
+
$this->viewLabel(),
|
| 163 |
+
));
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
/**
|
| 167 |
+
* Unserialize the object
|
| 168 |
+
*
|
| 169 |
+
* @param string $string
|
| 170 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Storeview
|
| 171 |
+
*/
|
| 172 |
+
public function unserialize($string)
|
| 173 |
+
{
|
| 174 |
+
list(
|
| 175 |
+
$this->_id,
|
| 176 |
+
$this->_websiteCode,
|
| 177 |
+
$this->_websiteLabel,
|
| 178 |
+
$this->_storeCode,
|
| 179 |
+
$this->_storeLabel,
|
| 180 |
+
$this->_viewCode,
|
| 181 |
+
$this->_viewLabel
|
| 182 |
+
) = unserialize($string);
|
| 183 |
+
|
| 184 |
+
return $this;
|
| 185 |
+
}
|
| 186 |
}
|
app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Subscription.php
CHANGED
|
@@ -1,179 +1,179 @@
|
|
| 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 Newsletter Subscription
|
| 29 |
-
*/
|
| 30 |
-
class Copernica_MarketingSoftware_Model_Abstraction_Subscription implements Serializable
|
| 31 |
-
{
|
| 32 |
-
/**
|
| 33 |
-
* Predefine the internal fields
|
| 34 |
-
*/
|
| 35 |
-
protected $_id;
|
| 36 |
-
protected $_email;
|
| 37 |
-
protected $_status;
|
| 38 |
-
|
| 39 |
-
/**
|
| 40 |
-
* The storeview object
|
| 41 |
-
*
|
| 42 |
-
* @var Copernica_MarketingSoftware_Model_Abstraction_Storeview
|
| 43 |
-
*/
|
| 44 |
-
protected $_storeview;
|
| 45 |
-
|
| 46 |
-
protected $_customerId;
|
| 47 |
-
|
| 48 |
-
/**
|
| 49 |
-
* Sets the original model
|
| 50 |
-
*
|
| 51 |
-
* @param Mage_Newsletter_Model_Subscriber $original
|
| 52 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Subscription
|
| 53 |
-
*/
|
| 54 |
-
public function setOriginal(Mage_Newsletter_Model_Subscriber $original)
|
| 55 |
-
{
|
| 56 |
-
$this->_id = $original->getId();
|
| 57 |
-
$this->_email = $original->getEmail();
|
| 58 |
-
$this->_customerId = $original->getCustomerId();
|
| 59 |
-
|
| 60 |
-
$store = Mage::getModel('core/store')->load($original->getStoreId());
|
| 61 |
-
|
| 62 |
-
$this->_storeview = Mage::getModel('marketingsoftware/abstraction_storeview')->setOriginal($store);
|
| 63 |
-
|
| 64 |
-
switch ($original->getStatus()) {
|
| 65 |
-
case Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED:
|
| 66 |
-
$this->_status = 'subscribed';
|
| 67 |
-
break;
|
| 68 |
-
|
| 69 |
-
case Mage_Newsletter_Model_Subscriber::STATUS_NOT_ACTIVE:
|
| 70 |
-
$this->_status = 'not active';
|
| 71 |
-
break;
|
| 72 |
-
|
| 73 |
-
case Mage_Newsletter_Model_Subscriber::STATUS_UNSUBSCRIBED:
|
| 74 |
-
$this->_status = 'unsubscribed';
|
| 75 |
-
break;
|
| 76 |
-
|
| 77 |
-
case Mage_Newsletter_Model_Subscriber::STATUS_UNCONFIRMED:
|
| 78 |
-
$this->_status = 'unconfirmed';
|
| 79 |
-
break;
|
| 80 |
-
|
| 81 |
-
default:
|
| 82 |
-
$this->_status = 'unknown';
|
| 83 |
-
break;
|
| 84 |
-
}
|
| 85 |
-
|
| 86 |
-
return $this;
|
| 87 |
-
}
|
| 88 |
-
|
| 89 |
-
/**
|
| 90 |
-
* Return the identifier for this object
|
| 91 |
-
*
|
| 92 |
-
* @return integer
|
| 93 |
-
*/
|
| 94 |
-
public function id()
|
| 95 |
-
{
|
| 96 |
-
return $this->_id;
|
| 97 |
-
}
|
| 98 |
-
|
| 99 |
-
/**
|
| 100 |
-
* Return the e-mail address with which the user is subscribed
|
| 101 |
-
*
|
| 102 |
-
* @return string
|
| 103 |
-
*/
|
| 104 |
-
public function email()
|
| 105 |
-
{
|
| 106 |
-
return $this->_email;
|
| 107 |
-
}
|
| 108 |
-
|
| 109 |
-
/**
|
| 110 |
-
* Return the status of this subscription
|
| 111 |
-
* Note that subscribed might be returned but the record is currently removed
|
| 112 |
-
*
|
| 113 |
-
* @return string
|
| 114 |
-
*/
|
| 115 |
-
public function status()
|
| 116 |
-
{
|
| 117 |
-
return $this->_status;
|
| 118 |
-
}
|
| 119 |
-
|
| 120 |
-
/**
|
| 121 |
-
* The customer may return null
|
| 122 |
-
*
|
| 123 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Customer
|
| 124 |
-
*/
|
| 125 |
-
public function customer()
|
| 126 |
-
{
|
| 127 |
-
if ($this->_customerId) {
|
| 128 |
-
return Mage::getModel('marketingsoftware/abstraction_customer')->loadCustomer($this->_customerId);
|
| 129 |
-
} else {
|
| 130 |
-
return null;
|
| 131 |
-
}
|
| 132 |
-
}
|
| 133 |
-
|
| 134 |
-
/**
|
| 135 |
-
* Return the storeview for this subscription
|
| 136 |
-
*
|
| 137 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Storeview
|
| 138 |
-
*/
|
| 139 |
-
public function storeView()
|
| 140 |
-
{
|
| 141 |
-
return $this->_storeview;
|
| 142 |
-
}
|
| 143 |
-
|
| 144 |
-
/**
|
| 145 |
-
* Serialize the object
|
| 146 |
-
*
|
| 147 |
-
* @return string
|
| 148 |
-
*/
|
| 149 |
-
public function serialize()
|
| 150 |
-
{
|
| 151 |
-
return serialize(array(
|
| 152 |
-
$this->id(),
|
| 153 |
-
$this->email(),
|
| 154 |
-
$this->status(),
|
| 155 |
-
$this->storeview(),
|
| 156 |
-
is_object($customer = $this->customer()) ? $customer->id() : null,
|
| 157 |
-
));
|
| 158 |
-
}
|
| 159 |
-
|
| 160 |
-
/**
|
| 161 |
-
* Unserialize the object
|
| 162 |
-
*
|
| 163 |
-
* @param string $string
|
| 164 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Subscription
|
| 165 |
-
*/
|
| 166 |
-
public function unserialize($string)
|
| 167 |
-
{
|
| 168 |
-
list(
|
| 169 |
-
$this->_id,
|
| 170 |
-
$this->_email,
|
| 171 |
-
$this->_status,
|
| 172 |
-
$this->_storeview,
|
| 173 |
-
$this->_customerId
|
| 174 |
-
) = unserialize($string);
|
| 175 |
-
|
| 176 |
-
return $this;
|
| 177 |
-
}
|
| 178 |
-
}
|
| 179 |
-
|
| 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 Newsletter Subscription
|
| 29 |
+
*/
|
| 30 |
+
class Copernica_MarketingSoftware_Model_Abstraction_Subscription implements Serializable
|
| 31 |
+
{
|
| 32 |
+
/**
|
| 33 |
+
* Predefine the internal fields
|
| 34 |
+
*/
|
| 35 |
+
protected $_id;
|
| 36 |
+
protected $_email;
|
| 37 |
+
protected $_status;
|
| 38 |
+
|
| 39 |
+
/**
|
| 40 |
+
* The storeview object
|
| 41 |
+
*
|
| 42 |
+
* @var Copernica_MarketingSoftware_Model_Abstraction_Storeview
|
| 43 |
+
*/
|
| 44 |
+
protected $_storeview;
|
| 45 |
+
|
| 46 |
+
protected $_customerId;
|
| 47 |
+
|
| 48 |
+
/**
|
| 49 |
+
* Sets the original model
|
| 50 |
+
*
|
| 51 |
+
* @param Mage_Newsletter_Model_Subscriber $original
|
| 52 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Subscription
|
| 53 |
+
*/
|
| 54 |
+
public function setOriginal(Mage_Newsletter_Model_Subscriber $original)
|
| 55 |
+
{
|
| 56 |
+
$this->_id = $original->getId();
|
| 57 |
+
$this->_email = $original->getEmail();
|
| 58 |
+
$this->_customerId = $original->getCustomerId();
|
| 59 |
+
|
| 60 |
+
$store = Mage::getModel('core/store')->load($original->getStoreId());
|
| 61 |
+
|
| 62 |
+
$this->_storeview = Mage::getModel('marketingsoftware/abstraction_storeview')->setOriginal($store);
|
| 63 |
+
|
| 64 |
+
switch ($original->getStatus()) {
|
| 65 |
+
case Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED:
|
| 66 |
+
$this->_status = 'subscribed';
|
| 67 |
+
break;
|
| 68 |
+
|
| 69 |
+
case Mage_Newsletter_Model_Subscriber::STATUS_NOT_ACTIVE:
|
| 70 |
+
$this->_status = 'not active';
|
| 71 |
+
break;
|
| 72 |
+
|
| 73 |
+
case Mage_Newsletter_Model_Subscriber::STATUS_UNSUBSCRIBED:
|
| 74 |
+
$this->_status = 'unsubscribed';
|
| 75 |
+
break;
|
| 76 |
+
|
| 77 |
+
case Mage_Newsletter_Model_Subscriber::STATUS_UNCONFIRMED:
|
| 78 |
+
$this->_status = 'unconfirmed';
|
| 79 |
+
break;
|
| 80 |
+
|
| 81 |
+
default:
|
| 82 |
+
$this->_status = 'unknown';
|
| 83 |
+
break;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
return $this;
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
/**
|
| 90 |
+
* Return the identifier for this object
|
| 91 |
+
*
|
| 92 |
+
* @return integer
|
| 93 |
+
*/
|
| 94 |
+
public function id()
|
| 95 |
+
{
|
| 96 |
+
return $this->_id;
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
/**
|
| 100 |
+
* Return the e-mail address with which the user is subscribed
|
| 101 |
+
*
|
| 102 |
+
* @return string
|
| 103 |
+
*/
|
| 104 |
+
public function email()
|
| 105 |
+
{
|
| 106 |
+
return $this->_email;
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
/**
|
| 110 |
+
* Return the status of this subscription
|
| 111 |
+
* Note that subscribed might be returned but the record is currently removed
|
| 112 |
+
*
|
| 113 |
+
* @return string
|
| 114 |
+
*/
|
| 115 |
+
public function status()
|
| 116 |
+
{
|
| 117 |
+
return $this->_status;
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
/**
|
| 121 |
+
* The customer may return null
|
| 122 |
+
*
|
| 123 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Customer
|
| 124 |
+
*/
|
| 125 |
+
public function customer()
|
| 126 |
+
{
|
| 127 |
+
if ($this->_customerId) {
|
| 128 |
+
return Mage::getModel('marketingsoftware/abstraction_customer')->loadCustomer($this->_customerId);
|
| 129 |
+
} else {
|
| 130 |
+
return null;
|
| 131 |
+
}
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
/**
|
| 135 |
+
* Return the storeview for this subscription
|
| 136 |
+
*
|
| 137 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Storeview
|
| 138 |
+
*/
|
| 139 |
+
public function storeView()
|
| 140 |
+
{
|
| 141 |
+
return $this->_storeview;
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
/**
|
| 145 |
+
* Serialize the object
|
| 146 |
+
*
|
| 147 |
+
* @return string
|
| 148 |
+
*/
|
| 149 |
+
public function serialize()
|
| 150 |
+
{
|
| 151 |
+
return serialize(array(
|
| 152 |
+
$this->id(),
|
| 153 |
+
$this->email(),
|
| 154 |
+
$this->status(),
|
| 155 |
+
$this->storeview(),
|
| 156 |
+
is_object($customer = $this->customer()) ? $customer->id() : null,
|
| 157 |
+
));
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
/**
|
| 161 |
+
* Unserialize the object
|
| 162 |
+
*
|
| 163 |
+
* @param string $string
|
| 164 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Subscription
|
| 165 |
+
*/
|
| 166 |
+
public function unserialize($string)
|
| 167 |
+
{
|
| 168 |
+
list(
|
| 169 |
+
$this->_id,
|
| 170 |
+
$this->_email,
|
| 171 |
+
$this->_status,
|
| 172 |
+
$this->_storeview,
|
| 173 |
+
$this->_customerId
|
| 174 |
+
) = unserialize($string);
|
| 175 |
+
|
| 176 |
+
return $this;
|
| 177 |
+
}
|
| 178 |
+
}
|
| 179 |
+
|
app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Wishlist.php
CHANGED
|
@@ -1,369 +1,369 @@
|
|
| 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 wishlist
|
| 29 |
-
*/
|
| 30 |
-
class Copernica_MarketingSoftware_Model_Abstraction_Wishlist implements Serializable
|
| 31 |
-
{
|
| 32 |
-
/**
|
| 33 |
-
* Predefine the internal fields
|
| 34 |
-
*/
|
| 35 |
-
protected $_wishlistId;
|
| 36 |
-
protected $_quantity;
|
| 37 |
-
protected $_currency;
|
| 38 |
-
protected $_timestamp;
|
| 39 |
-
protected $_customerIP;
|
| 40 |
-
protected $_items;
|
| 41 |
-
|
| 42 |
-
/**
|
| 43 |
-
* The storeview object
|
| 44 |
-
*
|
| 45 |
-
* @var Copernica_MarketingSoftware_Model_Abstraction_Storeview
|
| 46 |
-
*/
|
| 47 |
-
protected $_storeview;
|
| 48 |
-
|
| 49 |
-
protected $_customerId;
|
| 50 |
-
protected $_addresses;
|
| 51 |
-
protected $_price;
|
| 52 |
-
protected $_weight;
|
| 53 |
-
protected $_active;
|
| 54 |
-
protected $_shippingDescription;
|
| 55 |
-
protected $_paymentDescription;
|
| 56 |
-
|
| 57 |
-
/**
|
| 58 |
-
* Sets the original model
|
| 59 |
-
*
|
| 60 |
-
* @param Mage_Wishlist_Model_Wishlist $original
|
| 61 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Wishlist
|
| 62 |
-
*/
|
| 63 |
-
public function setOriginal(Mage_Wishlist_Model_Wishlist $original)
|
| 64 |
-
{
|
| 65 |
-
$this->_wishlistId = $original->getId();
|
| 66 |
-
|
| 67 |
-
return $this;
|
| 68 |
-
}
|
| 69 |
-
|
| 70 |
-
/**
|
| 71 |
-
* Loads a wishlist model
|
| 72 |
-
*
|
| 73 |
-
* @param integer $wishlistId
|
| 74 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Wishlist
|
| 75 |
-
*/
|
| 76 |
-
public function loadWishlist($wishlistId)
|
| 77 |
-
{
|
| 78 |
-
$wishlist = Mage::getModel('wishlist/wishlist');
|
| 79 |
-
|
| 80 |
-
if (!is_callable($wishlist, 'loadByIdWithoutStore')) {
|
| 81 |
-
$storeIDs = array();
|
| 82 |
-
|
| 83 |
-
foreach (Mage::app()->getStores() as $id => $store) {
|
| 84 |
-
$storeIDs[] = $id;
|
| 85 |
-
}
|
| 86 |
-
|
| 87 |
-
$wishlist->setSharedStoreIds($storeIDs);
|
| 88 |
-
$wishlist->load($wishlistId);
|
| 89 |
-
} else {
|
| 90 |
-
$wishlist->loadByIdWithoutStore($wishlistId);
|
| 91 |
-
}
|
| 92 |
-
|
| 93 |
-
if ($wishlist->getId()) {
|
| 94 |
-
$this->_importFromObject($wishlist);
|
| 95 |
-
} else {
|
| 96 |
-
$this->_wishlistId = $wishlistId;
|
| 97 |
-
}
|
| 98 |
-
|
| 99 |
-
return $this;
|
| 100 |
-
}
|
| 101 |
-
|
| 102 |
-
/**
|
| 103 |
-
* Import this abstract from a real magento one
|
| 104 |
-
*
|
| 105 |
-
* @param Mage_Wishlist_Model_Wishlist $original
|
| 106 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Wishlist
|
| 107 |
-
*/
|
| 108 |
-
protected function _importFromObject(Mage_Wishlist_Model_Wishlist $original)
|
| 109 |
-
{
|
| 110 |
-
$this->_wishlistId = $original->getId();
|
| 111 |
-
$this->_active = (bool) $original->getIsActive();
|
| 112 |
-
$this->_quantity = $original->getItemsQty();
|
| 113 |
-
$this->_currency = $original->getWishlistCurrencyCode();
|
| 114 |
-
$this->_price = Mage::getModel('marketingsoftware/abstraction_price')->setOriginal($original);
|
| 115 |
-
$this->_storeview = Mage::getModel('marketingsoftware/abstraction_storeview')->setOriginal($original->getStore());
|
| 116 |
-
$this->_timestamp = $original->getUpdatedAt();
|
| 117 |
-
$this->_customerIP = $original->getRemoteIp();
|
| 118 |
-
|
| 119 |
-
if ($address = $original->getShippingAddress()) {
|
| 120 |
-
$this->_weight = $address->getWeight();
|
| 121 |
-
}
|
| 122 |
-
|
| 123 |
-
$data = array();
|
| 124 |
-
|
| 125 |
-
$items = $original->getAllVisibleItems();
|
| 126 |
-
|
| 127 |
-
foreach ($items as $item) {
|
| 128 |
-
$data[] = Mage::getModel('marketingsoftware/abstraction_wishlist_item')->setOriginal($item);
|
| 129 |
-
}
|
| 130 |
-
|
| 131 |
-
$this->_items = $data;
|
| 132 |
-
|
| 133 |
-
if ($customerId = $original->getCustomerId()) {
|
| 134 |
-
$this->_customerId = $customerId;
|
| 135 |
-
}
|
| 136 |
-
|
| 137 |
-
$data = array();
|
| 138 |
-
|
| 139 |
-
$addresses = $original->getAddressesCollection();
|
| 140 |
-
|
| 141 |
-
foreach ($addresses as $address) {
|
| 142 |
-
$data[] = Mage::getModel('marketingsoftware/abstraction_address')->setOriginal($address);
|
| 143 |
-
}
|
| 144 |
-
|
| 145 |
-
$this->_addresses = $data;
|
| 146 |
-
|
| 147 |
-
if ($address = $original->getShippingAddress()) {
|
| 148 |
-
$this->_shippingDescription = $address->getShippingDescription();
|
| 149 |
-
}
|
| 150 |
-
|
| 151 |
-
if ($payment = $original->getPayment()) {
|
| 152 |
-
try {
|
| 153 |
-
$this->_paymentDescription = $payment->getMethodInstance()->getTitle();
|
| 154 |
-
} catch (Mage_Core_Exception $exception) { }
|
| 155 |
-
}
|
| 156 |
-
}
|
| 157 |
-
|
| 158 |
-
/**
|
| 159 |
-
* The wishlist id of this wishlist object
|
| 160 |
-
*
|
| 161 |
-
* @return integer
|
| 162 |
-
*/
|
| 163 |
-
public function id()
|
| 164 |
-
{
|
| 165 |
-
return $this->_wishlistId;
|
| 166 |
-
}
|
| 167 |
-
|
| 168 |
-
/**
|
| 169 |
-
* Is this wishlist still active
|
| 170 |
-
*
|
| 171 |
-
* @return boolean
|
| 172 |
-
*/
|
| 173 |
-
public function active()
|
| 174 |
-
{
|
| 175 |
-
return $this->_active;
|
| 176 |
-
}
|
| 177 |
-
|
| 178 |
-
/**
|
| 179 |
-
* The number of items present in this wishlist
|
| 180 |
-
*
|
| 181 |
-
* @return integer
|
| 182 |
-
*/
|
| 183 |
-
public function quantity()
|
| 184 |
-
{
|
| 185 |
-
return $this->_quantity;
|
| 186 |
-
}
|
| 187 |
-
|
| 188 |
-
/**
|
| 189 |
-
* The payment currency of this wishlist
|
| 190 |
-
*
|
| 191 |
-
* @return string
|
| 192 |
-
*/
|
| 193 |
-
public function currency()
|
| 194 |
-
{
|
| 195 |
-
return $this->_currency;
|
| 196 |
-
}
|
| 197 |
-
|
| 198 |
-
/**
|
| 199 |
-
* The price
|
| 200 |
-
* Note that an object is returned, which may consist of multiple components
|
| 201 |
-
*
|
| 202 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Price
|
| 203 |
-
*/
|
| 204 |
-
public function price()
|
| 205 |
-
{
|
| 206 |
-
return $this->_price;
|
| 207 |
-
}
|
| 208 |
-
|
| 209 |
-
/**
|
| 210 |
-
* The weight
|
| 211 |
-
*
|
| 212 |
-
* @return float
|
| 213 |
-
*/
|
| 214 |
-
public function weight()
|
| 215 |
-
{
|
| 216 |
-
return $this->_weight;
|
| 217 |
-
}
|
| 218 |
-
|
| 219 |
-
/**
|
| 220 |
-
* To what storeview does this wishlist belong
|
| 221 |
-
*
|
| 222 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Storeview
|
| 223 |
-
*/
|
| 224 |
-
public function storeview()
|
| 225 |
-
{
|
| 226 |
-
return $this->_storeview;
|
| 227 |
-
}
|
| 228 |
-
|
| 229 |
-
/**
|
| 230 |
-
* Get the items from the wishlist
|
| 231 |
-
*
|
| 232 |
-
* @return array
|
| 233 |
-
*/
|
| 234 |
-
public function items()
|
| 235 |
-
{
|
| 236 |
-
return $this->_items;
|
| 237 |
-
}
|
| 238 |
-
|
| 239 |
-
/**
|
| 240 |
-
* The timestamp at which this wishlist was modified
|
| 241 |
-
*
|
| 242 |
-
* @return string
|
| 243 |
-
*/
|
| 244 |
-
public function timestamp()
|
| 245 |
-
{
|
| 246 |
-
return $this->_timestamp;
|
| 247 |
-
}
|
| 248 |
-
|
| 249 |
-
/**
|
| 250 |
-
* The customer may return null
|
| 251 |
-
*
|
| 252 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Customer|null
|
| 253 |
-
*/
|
| 254 |
-
public function customer()
|
| 255 |
-
{
|
| 256 |
-
if ($this->_customerId) {
|
| 257 |
-
return Mage::getModel('marketingsoftware/abstraction_customer')->loadCustomer($this->_customerId);
|
| 258 |
-
} else {
|
| 259 |
-
return null;
|
| 260 |
-
}
|
| 261 |
-
}
|
| 262 |
-
|
| 263 |
-
/**
|
| 264 |
-
* The addresses of this wishlist
|
| 265 |
-
*
|
| 266 |
-
* @return array
|
| 267 |
-
*/
|
| 268 |
-
public function addresses()
|
| 269 |
-
{
|
| 270 |
-
return $this->_addresses;
|
| 271 |
-
}
|
| 272 |
-
|
| 273 |
-
/**
|
| 274 |
-
* The IP from which this wishlist was constructed
|
| 275 |
-
*
|
| 276 |
-
* @return string
|
| 277 |
-
*/
|
| 278 |
-
public function customerIP()
|
| 279 |
-
{
|
| 280 |
-
return $this->_customerIP;
|
| 281 |
-
}
|
| 282 |
-
|
| 283 |
-
/**
|
| 284 |
-
* The shipping method of this wishlist
|
| 285 |
-
*
|
| 286 |
-
* @return string
|
| 287 |
-
*/
|
| 288 |
-
public function shippingDescription()
|
| 289 |
-
{
|
| 290 |
-
return $this->_shippingDescription;
|
| 291 |
-
}
|
| 292 |
-
|
| 293 |
-
/**
|
| 294 |
-
* The payment method of this wishlist
|
| 295 |
-
*
|
| 296 |
-
* @return string
|
| 297 |
-
*/
|
| 298 |
-
public function paymentDescription()
|
| 299 |
-
{
|
| 300 |
-
return $this->_paymentDescription;
|
| 301 |
-
}
|
| 302 |
-
|
| 303 |
-
/**
|
| 304 |
-
* Serialize the object
|
| 305 |
-
*
|
| 306 |
-
* @todo Two returns??
|
| 307 |
-
* @return string
|
| 308 |
-
*/
|
| 309 |
-
public function serialize()
|
| 310 |
-
{
|
| 311 |
-
return serialize(array(
|
| 312 |
-
$this->id()
|
| 313 |
-
));
|
| 314 |
-
|
| 315 |
-
return serialize(array(
|
| 316 |
-
$this->id(),
|
| 317 |
-
$this->quantity(),
|
| 318 |
-
$this->currency(),
|
| 319 |
-
$this->timestamp(),
|
| 320 |
-
$this->customerIP(),
|
| 321 |
-
$this->items(),
|
| 322 |
-
$this->storeview(),
|
| 323 |
-
is_object($customer = $this->customer()) ? $customer->id() : null,
|
| 324 |
-
$this->addresses(),
|
| 325 |
-
$this->price(),
|
| 326 |
-
$this->weight(),
|
| 327 |
-
$this->active(),
|
| 328 |
-
$this->shippingDescription(),
|
| 329 |
-
$this->paymentDescription()
|
| 330 |
-
));
|
| 331 |
-
}
|
| 332 |
-
|
| 333 |
-
/**
|
| 334 |
-
* Unserialize the object
|
| 335 |
-
*
|
| 336 |
-
* @todo Two returns??
|
| 337 |
-
* @param string $string
|
| 338 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Wishlist
|
| 339 |
-
*/
|
| 340 |
-
public function unserialize($string)
|
| 341 |
-
{
|
| 342 |
-
list (
|
| 343 |
-
$this->_wishlistId
|
| 344 |
-
) = unserialize($string);
|
| 345 |
-
|
| 346 |
-
$this->loadWishlist($this->_wishlistId);
|
| 347 |
-
|
| 348 |
-
return $this;
|
| 349 |
-
|
| 350 |
-
list(
|
| 351 |
-
$this->_wishlistId,
|
| 352 |
-
$this->_quantity,
|
| 353 |
-
$this->_currency,
|
| 354 |
-
$this->_timestamp,
|
| 355 |
-
$this->_customerIP,
|
| 356 |
-
$this->_items,
|
| 357 |
-
$this->_storeview,
|
| 358 |
-
$this->_customerId,
|
| 359 |
-
$this->_addresses,
|
| 360 |
-
$this->_price,
|
| 361 |
-
$this->_weight,
|
| 362 |
-
$this->_active,
|
| 363 |
-
$this->_shippingDescription,
|
| 364 |
-
$this->_paymentDescription
|
| 365 |
-
) = unserialize($string);
|
| 366 |
-
|
| 367 |
-
return $this;
|
| 368 |
-
}
|
| 369 |
}
|
| 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 wishlist
|
| 29 |
+
*/
|
| 30 |
+
class Copernica_MarketingSoftware_Model_Abstraction_Wishlist implements Serializable
|
| 31 |
+
{
|
| 32 |
+
/**
|
| 33 |
+
* Predefine the internal fields
|
| 34 |
+
*/
|
| 35 |
+
protected $_wishlistId;
|
| 36 |
+
protected $_quantity;
|
| 37 |
+
protected $_currency;
|
| 38 |
+
protected $_timestamp;
|
| 39 |
+
protected $_customerIP;
|
| 40 |
+
protected $_items;
|
| 41 |
+
|
| 42 |
+
/**
|
| 43 |
+
* The storeview object
|
| 44 |
+
*
|
| 45 |
+
* @var Copernica_MarketingSoftware_Model_Abstraction_Storeview
|
| 46 |
+
*/
|
| 47 |
+
protected $_storeview;
|
| 48 |
+
|
| 49 |
+
protected $_customerId;
|
| 50 |
+
protected $_addresses;
|
| 51 |
+
protected $_price;
|
| 52 |
+
protected $_weight;
|
| 53 |
+
protected $_active;
|
| 54 |
+
protected $_shippingDescription;
|
| 55 |
+
protected $_paymentDescription;
|
| 56 |
+
|
| 57 |
+
/**
|
| 58 |
+
* Sets the original model
|
| 59 |
+
*
|
| 60 |
+
* @param Mage_Wishlist_Model_Wishlist $original
|
| 61 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Wishlist
|
| 62 |
+
*/
|
| 63 |
+
public function setOriginal(Mage_Wishlist_Model_Wishlist $original)
|
| 64 |
+
{
|
| 65 |
+
$this->_wishlistId = $original->getId();
|
| 66 |
+
|
| 67 |
+
return $this;
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
/**
|
| 71 |
+
* Loads a wishlist model
|
| 72 |
+
*
|
| 73 |
+
* @param integer $wishlistId
|
| 74 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Wishlist
|
| 75 |
+
*/
|
| 76 |
+
public function loadWishlist($wishlistId)
|
| 77 |
+
{
|
| 78 |
+
$wishlist = Mage::getModel('wishlist/wishlist');
|
| 79 |
+
|
| 80 |
+
if (!is_callable($wishlist, 'loadByIdWithoutStore')) {
|
| 81 |
+
$storeIDs = array();
|
| 82 |
+
|
| 83 |
+
foreach (Mage::app()->getStores() as $id => $store) {
|
| 84 |
+
$storeIDs[] = $id;
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
$wishlist->setSharedStoreIds($storeIDs);
|
| 88 |
+
$wishlist->load($wishlistId);
|
| 89 |
+
} else {
|
| 90 |
+
$wishlist->loadByIdWithoutStore($wishlistId);
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
if ($wishlist->getId()) {
|
| 94 |
+
$this->_importFromObject($wishlist);
|
| 95 |
+
} else {
|
| 96 |
+
$this->_wishlistId = $wishlistId;
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
return $this;
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
/**
|
| 103 |
+
* Import this abstract from a real magento one
|
| 104 |
+
*
|
| 105 |
+
* @param Mage_Wishlist_Model_Wishlist $original
|
| 106 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Wishlist
|
| 107 |
+
*/
|
| 108 |
+
protected function _importFromObject(Mage_Wishlist_Model_Wishlist $original)
|
| 109 |
+
{
|
| 110 |
+
$this->_wishlistId = $original->getId();
|
| 111 |
+
$this->_active = (bool) $original->getIsActive();
|
| 112 |
+
$this->_quantity = $original->getItemsQty();
|
| 113 |
+
$this->_currency = $original->getWishlistCurrencyCode();
|
| 114 |
+
$this->_price = Mage::getModel('marketingsoftware/abstraction_price')->setOriginal($original);
|
| 115 |
+
$this->_storeview = Mage::getModel('marketingsoftware/abstraction_storeview')->setOriginal($original->getStore());
|
| 116 |
+
$this->_timestamp = $original->getUpdatedAt();
|
| 117 |
+
$this->_customerIP = $original->getRemoteIp();
|
| 118 |
+
|
| 119 |
+
if ($address = $original->getShippingAddress()) {
|
| 120 |
+
$this->_weight = $address->getWeight();
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
$data = array();
|
| 124 |
+
|
| 125 |
+
$items = $original->getAllVisibleItems();
|
| 126 |
+
|
| 127 |
+
foreach ($items as $item) {
|
| 128 |
+
$data[] = Mage::getModel('marketingsoftware/abstraction_wishlist_item')->setOriginal($item);
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
$this->_items = $data;
|
| 132 |
+
|
| 133 |
+
if ($customerId = $original->getCustomerId()) {
|
| 134 |
+
$this->_customerId = $customerId;
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
$data = array();
|
| 138 |
+
|
| 139 |
+
$addresses = $original->getAddressesCollection();
|
| 140 |
+
|
| 141 |
+
foreach ($addresses as $address) {
|
| 142 |
+
$data[] = Mage::getModel('marketingsoftware/abstraction_address')->setOriginal($address);
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
$this->_addresses = $data;
|
| 146 |
+
|
| 147 |
+
if ($address = $original->getShippingAddress()) {
|
| 148 |
+
$this->_shippingDescription = $address->getShippingDescription();
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
if ($payment = $original->getPayment()) {
|
| 152 |
+
try {
|
| 153 |
+
$this->_paymentDescription = $payment->getMethodInstance()->getTitle();
|
| 154 |
+
} catch (Mage_Core_Exception $exception) { }
|
| 155 |
+
}
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
/**
|
| 159 |
+
* The wishlist id of this wishlist object
|
| 160 |
+
*
|
| 161 |
+
* @return integer
|
| 162 |
+
*/
|
| 163 |
+
public function id()
|
| 164 |
+
{
|
| 165 |
+
return $this->_wishlistId;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
/**
|
| 169 |
+
* Is this wishlist still active
|
| 170 |
+
*
|
| 171 |
+
* @return boolean
|
| 172 |
+
*/
|
| 173 |
+
public function active()
|
| 174 |
+
{
|
| 175 |
+
return $this->_active;
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
/**
|
| 179 |
+
* The number of items present in this wishlist
|
| 180 |
+
*
|
| 181 |
+
* @return integer
|
| 182 |
+
*/
|
| 183 |
+
public function quantity()
|
| 184 |
+
{
|
| 185 |
+
return $this->_quantity;
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
/**
|
| 189 |
+
* The payment currency of this wishlist
|
| 190 |
+
*
|
| 191 |
+
* @return string
|
| 192 |
+
*/
|
| 193 |
+
public function currency()
|
| 194 |
+
{
|
| 195 |
+
return $this->_currency;
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
/**
|
| 199 |
+
* The price
|
| 200 |
+
* Note that an object is returned, which may consist of multiple components
|
| 201 |
+
*
|
| 202 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Price
|
| 203 |
+
*/
|
| 204 |
+
public function price()
|
| 205 |
+
{
|
| 206 |
+
return $this->_price;
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
/**
|
| 210 |
+
* The weight
|
| 211 |
+
*
|
| 212 |
+
* @return float
|
| 213 |
+
*/
|
| 214 |
+
public function weight()
|
| 215 |
+
{
|
| 216 |
+
return $this->_weight;
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
/**
|
| 220 |
+
* To what storeview does this wishlist belong
|
| 221 |
+
*
|
| 222 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Storeview
|
| 223 |
+
*/
|
| 224 |
+
public function storeview()
|
| 225 |
+
{
|
| 226 |
+
return $this->_storeview;
|
| 227 |
+
}
|
| 228 |
+
|
| 229 |
+
/**
|
| 230 |
+
* Get the items from the wishlist
|
| 231 |
+
*
|
| 232 |
+
* @return array
|
| 233 |
+
*/
|
| 234 |
+
public function items()
|
| 235 |
+
{
|
| 236 |
+
return $this->_items;
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
/**
|
| 240 |
+
* The timestamp at which this wishlist was modified
|
| 241 |
+
*
|
| 242 |
+
* @return string
|
| 243 |
+
*/
|
| 244 |
+
public function timestamp()
|
| 245 |
+
{
|
| 246 |
+
return $this->_timestamp;
|
| 247 |
+
}
|
| 248 |
+
|
| 249 |
+
/**
|
| 250 |
+
* The customer may return null
|
| 251 |
+
*
|
| 252 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Customer|null
|
| 253 |
+
*/
|
| 254 |
+
public function customer()
|
| 255 |
+
{
|
| 256 |
+
if ($this->_customerId) {
|
| 257 |
+
return Mage::getModel('marketingsoftware/abstraction_customer')->loadCustomer($this->_customerId);
|
| 258 |
+
} else {
|
| 259 |
+
return null;
|
| 260 |
+
}
|
| 261 |
+
}
|
| 262 |
+
|
| 263 |
+
/**
|
| 264 |
+
* The addresses of this wishlist
|
| 265 |
+
*
|
| 266 |
+
* @return array
|
| 267 |
+
*/
|
| 268 |
+
public function addresses()
|
| 269 |
+
{
|
| 270 |
+
return $this->_addresses;
|
| 271 |
+
}
|
| 272 |
+
|
| 273 |
+
/**
|
| 274 |
+
* The IP from which this wishlist was constructed
|
| 275 |
+
*
|
| 276 |
+
* @return string
|
| 277 |
+
*/
|
| 278 |
+
public function customerIP()
|
| 279 |
+
{
|
| 280 |
+
return $this->_customerIP;
|
| 281 |
+
}
|
| 282 |
+
|
| 283 |
+
/**
|
| 284 |
+
* The shipping method of this wishlist
|
| 285 |
+
*
|
| 286 |
+
* @return string
|
| 287 |
+
*/
|
| 288 |
+
public function shippingDescription()
|
| 289 |
+
{
|
| 290 |
+
return $this->_shippingDescription;
|
| 291 |
+
}
|
| 292 |
+
|
| 293 |
+
/**
|
| 294 |
+
* The payment method of this wishlist
|
| 295 |
+
*
|
| 296 |
+
* @return string
|
| 297 |
+
*/
|
| 298 |
+
public function paymentDescription()
|
| 299 |
+
{
|
| 300 |
+
return $this->_paymentDescription;
|
| 301 |
+
}
|
| 302 |
+
|
| 303 |
+
/**
|
| 304 |
+
* Serialize the object
|
| 305 |
+
*
|
| 306 |
+
* @todo Two returns??
|
| 307 |
+
* @return string
|
| 308 |
+
*/
|
| 309 |
+
public function serialize()
|
| 310 |
+
{
|
| 311 |
+
return serialize(array(
|
| 312 |
+
$this->id()
|
| 313 |
+
));
|
| 314 |
+
|
| 315 |
+
return serialize(array(
|
| 316 |
+
$this->id(),
|
| 317 |
+
$this->quantity(),
|
| 318 |
+
$this->currency(),
|
| 319 |
+
$this->timestamp(),
|
| 320 |
+
$this->customerIP(),
|
| 321 |
+
$this->items(),
|
| 322 |
+
$this->storeview(),
|
| 323 |
+
is_object($customer = $this->customer()) ? $customer->id() : null,
|
| 324 |
+
$this->addresses(),
|
| 325 |
+
$this->price(),
|
| 326 |
+
$this->weight(),
|
| 327 |
+
$this->active(),
|
| 328 |
+
$this->shippingDescription(),
|
| 329 |
+
$this->paymentDescription()
|
| 330 |
+
));
|
| 331 |
+
}
|
| 332 |
+
|
| 333 |
+
/**
|
| 334 |
+
* Unserialize the object
|
| 335 |
+
*
|
| 336 |
+
* @todo Two returns??
|
| 337 |
+
* @param string $string
|
| 338 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Wishlist
|
| 339 |
+
*/
|
| 340 |
+
public function unserialize($string)
|
| 341 |
+
{
|
| 342 |
+
list (
|
| 343 |
+
$this->_wishlistId
|
| 344 |
+
) = unserialize($string);
|
| 345 |
+
|
| 346 |
+
$this->loadWishlist($this->_wishlistId);
|
| 347 |
+
|
| 348 |
+
return $this;
|
| 349 |
+
|
| 350 |
+
list(
|
| 351 |
+
$this->_wishlistId,
|
| 352 |
+
$this->_quantity,
|
| 353 |
+
$this->_currency,
|
| 354 |
+
$this->_timestamp,
|
| 355 |
+
$this->_customerIP,
|
| 356 |
+
$this->_items,
|
| 357 |
+
$this->_storeview,
|
| 358 |
+
$this->_customerId,
|
| 359 |
+
$this->_addresses,
|
| 360 |
+
$this->_price,
|
| 361 |
+
$this->_weight,
|
| 362 |
+
$this->_active,
|
| 363 |
+
$this->_shippingDescription,
|
| 364 |
+
$this->_paymentDescription
|
| 365 |
+
) = unserialize($string);
|
| 366 |
+
|
| 367 |
+
return $this;
|
| 368 |
+
}
|
| 369 |
}
|
app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Wishlist/Item.php
CHANGED
|
@@ -1,209 +1,209 @@
|
|
| 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 wishlist Item
|
| 29 |
-
*/
|
| 30 |
-
class Copernica_MarketingSoftware_Model_Abstraction_Wishlist_Item implements Serializable
|
| 31 |
-
{
|
| 32 |
-
/**
|
| 33 |
-
* Predefine the internal fields
|
| 34 |
-
*/
|
| 35 |
-
protected $_id;
|
| 36 |
-
protected $_wishlistId;
|
| 37 |
-
protected $_quantity;
|
| 38 |
-
protected $_price;
|
| 39 |
-
protected $_weight;
|
| 40 |
-
protected $_timestamp;
|
| 41 |
-
protected $_options;
|
| 42 |
-
protected $_product;
|
| 43 |
-
|
| 44 |
-
/**
|
| 45 |
-
* Sets the original model
|
| 46 |
-
*
|
| 47 |
-
* @param Mage_Wishlist_Model_Item $original
|
| 48 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Wishlist_Item
|
| 49 |
-
*/
|
| 50 |
-
public function setOriginal(Mage_Wishlist_Model_Item $original)
|
| 51 |
-
{
|
| 52 |
-
$this->_id = $original->getId();
|
| 53 |
-
$this->_wishlistId = $original->getWishlist()->getId();
|
| 54 |
-
$this->_quantity = $original->getQty();
|
| 55 |
-
$this->_price = Mage::getModel('marketingsoftware/abstraction_price')->setOriginal($original);
|
| 56 |
-
$this->_weight = $original->getWeight();
|
| 57 |
-
$this->_timestamp = $original->getUpdatedAt();
|
| 58 |
-
$this->_product = Mage::getModel('marketingsoftware/abstraction_product')->setOriginal($original);
|
| 59 |
-
|
| 60 |
-
$options = Mage::getModel('marketingsoftware/abstraction_wishlist_item_options')->setOriginal($original);
|
| 61 |
-
|
| 62 |
-
if ($options->attributes()) {
|
| 63 |
-
$this->_options = $options;
|
| 64 |
-
}
|
| 65 |
-
|
| 66 |
-
return $this;
|
| 67 |
-
}
|
| 68 |
-
|
| 69 |
-
/**
|
| 70 |
-
* The id of this wishlist item object
|
| 71 |
-
*
|
| 72 |
-
* @return integer
|
| 73 |
-
*/
|
| 74 |
-
public function id()
|
| 75 |
-
{
|
| 76 |
-
return $this->_id;
|
| 77 |
-
}
|
| 78 |
-
|
| 79 |
-
/**
|
| 80 |
-
* Get the wishlist to which this item belongs
|
| 81 |
-
*
|
| 82 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Wishlist
|
| 83 |
-
*/
|
| 84 |
-
public function wishlist()
|
| 85 |
-
{
|
| 86 |
-
return Mage::getModel('marketingsoftware/abstraction_wishlist')->loadWishlist($this->_wishlistId);
|
| 87 |
-
}
|
| 88 |
-
|
| 89 |
-
/**
|
| 90 |
-
* The amount of this wishlist item
|
| 91 |
-
*
|
| 92 |
-
* @return integer
|
| 93 |
-
*/
|
| 94 |
-
public function quantity()
|
| 95 |
-
{
|
| 96 |
-
return $this->_quantity;
|
| 97 |
-
}
|
| 98 |
-
|
| 99 |
-
/**
|
| 100 |
-
* The price
|
| 101 |
-
* Note that an object is returned, which may consist of multiple components
|
| 102 |
-
*
|
| 103 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Price
|
| 104 |
-
*/
|
| 105 |
-
public function price()
|
| 106 |
-
{
|
| 107 |
-
return $this->_price;
|
| 108 |
-
}
|
| 109 |
-
|
| 110 |
-
/**
|
| 111 |
-
* The weight
|
| 112 |
-
*
|
| 113 |
-
* @return float
|
| 114 |
-
*/
|
| 115 |
-
public function weight()
|
| 116 |
-
{
|
| 117 |
-
return $this->_weight;
|
| 118 |
-
}
|
| 119 |
-
|
| 120 |
-
/**
|
| 121 |
-
* The timestamp at which this wishlist item was modified
|
| 122 |
-
*
|
| 123 |
-
* @return string
|
| 124 |
-
*/
|
| 125 |
-
public function timestamp()
|
| 126 |
-
{
|
| 127 |
-
return $this->_timestamp;
|
| 128 |
-
}
|
| 129 |
-
|
| 130 |
-
/**
|
| 131 |
-
* Get the options of this wishlist item
|
| 132 |
-
*
|
| 133 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Wishlist_Item_Options
|
| 134 |
-
*/
|
| 135 |
-
public function options()
|
| 136 |
-
{
|
| 137 |
-
return $this->_options;
|
| 138 |
-
}
|
| 139 |
-
|
| 140 |
-
/**
|
| 141 |
-
* Get the product which belongs to this item
|
| 142 |
-
*
|
| 143 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Product
|
| 144 |
-
*/
|
| 145 |
-
public function product()
|
| 146 |
-
{
|
| 147 |
-
return $this->_product;
|
| 148 |
-
}
|
| 149 |
-
|
| 150 |
-
/**
|
| 151 |
-
* Loads a wishlist model
|
| 152 |
-
*
|
| 153 |
-
* @param integer $wishlistId
|
| 154 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Wishlist_Item
|
| 155 |
-
*/
|
| 156 |
-
public function loadWishlistItem($wishlistItemId)
|
| 157 |
-
{
|
| 158 |
-
$wishlistItem = Mage::getModel('wishlist/item')->load($wishlistItemId);
|
| 159 |
-
|
| 160 |
-
if ($wishlistItem->getId()) {
|
| 161 |
-
$this->setOriginal($wishlistItem);
|
| 162 |
-
} else {
|
| 163 |
-
$this->id = $wishlistItemId;
|
| 164 |
-
}
|
| 165 |
-
|
| 166 |
-
return $this;
|
| 167 |
-
}
|
| 168 |
-
|
| 169 |
-
/**
|
| 170 |
-
* Serialize the object
|
| 171 |
-
*
|
| 172 |
-
* @return string
|
| 173 |
-
*/
|
| 174 |
-
public function serialize()
|
| 175 |
-
{
|
| 176 |
-
return serialize(array(
|
| 177 |
-
$this->id(),
|
| 178 |
-
is_object($wishlist = $this->wishlist()) ? $wishlist->id() : null,
|
| 179 |
-
$this->quantity(),
|
| 180 |
-
$this->price(),
|
| 181 |
-
$this->weight(),
|
| 182 |
-
$this->timestamp(),
|
| 183 |
-
$this->options(),
|
| 184 |
-
$this->product(),
|
| 185 |
-
));
|
| 186 |
-
}
|
| 187 |
-
|
| 188 |
-
/**
|
| 189 |
-
* Unserialize the object
|
| 190 |
-
*
|
| 191 |
-
* @param string $string
|
| 192 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Wishlist_Item
|
| 193 |
-
*/
|
| 194 |
-
public function unserialize($string)
|
| 195 |
-
{
|
| 196 |
-
list(
|
| 197 |
-
$this->_id,
|
| 198 |
-
$this->_wishlistId,
|
| 199 |
-
$this->_quantity,
|
| 200 |
-
$this->_price,
|
| 201 |
-
$this->_weight,
|
| 202 |
-
$this->_timestamp,
|
| 203 |
-
$this->_options,
|
| 204 |
-
$this->_product
|
| 205 |
-
) = unserialize($string);
|
| 206 |
-
|
| 207 |
-
return $this;
|
| 208 |
-
}
|
| 209 |
}
|
| 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 wishlist Item
|
| 29 |
+
*/
|
| 30 |
+
class Copernica_MarketingSoftware_Model_Abstraction_Wishlist_Item implements Serializable
|
| 31 |
+
{
|
| 32 |
+
/**
|
| 33 |
+
* Predefine the internal fields
|
| 34 |
+
*/
|
| 35 |
+
protected $_id;
|
| 36 |
+
protected $_wishlistId;
|
| 37 |
+
protected $_quantity;
|
| 38 |
+
protected $_price;
|
| 39 |
+
protected $_weight;
|
| 40 |
+
protected $_timestamp;
|
| 41 |
+
protected $_options;
|
| 42 |
+
protected $_product;
|
| 43 |
+
|
| 44 |
+
/**
|
| 45 |
+
* Sets the original model
|
| 46 |
+
*
|
| 47 |
+
* @param Mage_Wishlist_Model_Item $original
|
| 48 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Wishlist_Item
|
| 49 |
+
*/
|
| 50 |
+
public function setOriginal(Mage_Wishlist_Model_Item $original)
|
| 51 |
+
{
|
| 52 |
+
$this->_id = $original->getId();
|
| 53 |
+
$this->_wishlistId = $original->getWishlist()->getId();
|
| 54 |
+
$this->_quantity = $original->getQty();
|
| 55 |
+
$this->_price = Mage::getModel('marketingsoftware/abstraction_price')->setOriginal($original);
|
| 56 |
+
$this->_weight = $original->getWeight();
|
| 57 |
+
$this->_timestamp = $original->getUpdatedAt();
|
| 58 |
+
$this->_product = Mage::getModel('marketingsoftware/abstraction_product')->setOriginal($original);
|
| 59 |
+
|
| 60 |
+
$options = Mage::getModel('marketingsoftware/abstraction_wishlist_item_options')->setOriginal($original);
|
| 61 |
+
|
| 62 |
+
if ($options->attributes()) {
|
| 63 |
+
$this->_options = $options;
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
return $this;
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
/**
|
| 70 |
+
* The id of this wishlist item object
|
| 71 |
+
*
|
| 72 |
+
* @return integer
|
| 73 |
+
*/
|
| 74 |
+
public function id()
|
| 75 |
+
{
|
| 76 |
+
return $this->_id;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
/**
|
| 80 |
+
* Get the wishlist to which this item belongs
|
| 81 |
+
*
|
| 82 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Wishlist
|
| 83 |
+
*/
|
| 84 |
+
public function wishlist()
|
| 85 |
+
{
|
| 86 |
+
return Mage::getModel('marketingsoftware/abstraction_wishlist')->loadWishlist($this->_wishlistId);
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
/**
|
| 90 |
+
* The amount of this wishlist item
|
| 91 |
+
*
|
| 92 |
+
* @return integer
|
| 93 |
+
*/
|
| 94 |
+
public function quantity()
|
| 95 |
+
{
|
| 96 |
+
return $this->_quantity;
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
/**
|
| 100 |
+
* The price
|
| 101 |
+
* Note that an object is returned, which may consist of multiple components
|
| 102 |
+
*
|
| 103 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Price
|
| 104 |
+
*/
|
| 105 |
+
public function price()
|
| 106 |
+
{
|
| 107 |
+
return $this->_price;
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
/**
|
| 111 |
+
* The weight
|
| 112 |
+
*
|
| 113 |
+
* @return float
|
| 114 |
+
*/
|
| 115 |
+
public function weight()
|
| 116 |
+
{
|
| 117 |
+
return $this->_weight;
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
/**
|
| 121 |
+
* The timestamp at which this wishlist item was modified
|
| 122 |
+
*
|
| 123 |
+
* @return string
|
| 124 |
+
*/
|
| 125 |
+
public function timestamp()
|
| 126 |
+
{
|
| 127 |
+
return $this->_timestamp;
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
/**
|
| 131 |
+
* Get the options of this wishlist item
|
| 132 |
+
*
|
| 133 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Wishlist_Item_Options
|
| 134 |
+
*/
|
| 135 |
+
public function options()
|
| 136 |
+
{
|
| 137 |
+
return $this->_options;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
/**
|
| 141 |
+
* Get the product which belongs to this item
|
| 142 |
+
*
|
| 143 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Product
|
| 144 |
+
*/
|
| 145 |
+
public function product()
|
| 146 |
+
{
|
| 147 |
+
return $this->_product;
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
/**
|
| 151 |
+
* Loads a wishlist model
|
| 152 |
+
*
|
| 153 |
+
* @param integer $wishlistId
|
| 154 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Wishlist_Item
|
| 155 |
+
*/
|
| 156 |
+
public function loadWishlistItem($wishlistItemId)
|
| 157 |
+
{
|
| 158 |
+
$wishlistItem = Mage::getModel('wishlist/item')->load($wishlistItemId);
|
| 159 |
+
|
| 160 |
+
if ($wishlistItem->getId()) {
|
| 161 |
+
$this->setOriginal($wishlistItem);
|
| 162 |
+
} else {
|
| 163 |
+
$this->id = $wishlistItemId;
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
return $this;
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
/**
|
| 170 |
+
* Serialize the object
|
| 171 |
+
*
|
| 172 |
+
* @return string
|
| 173 |
+
*/
|
| 174 |
+
public function serialize()
|
| 175 |
+
{
|
| 176 |
+
return serialize(array(
|
| 177 |
+
$this->id(),
|
| 178 |
+
is_object($wishlist = $this->wishlist()) ? $wishlist->id() : null,
|
| 179 |
+
$this->quantity(),
|
| 180 |
+
$this->price(),
|
| 181 |
+
$this->weight(),
|
| 182 |
+
$this->timestamp(),
|
| 183 |
+
$this->options(),
|
| 184 |
+
$this->product(),
|
| 185 |
+
));
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
/**
|
| 189 |
+
* Unserialize the object
|
| 190 |
+
*
|
| 191 |
+
* @param string $string
|
| 192 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Wishlist_Item
|
| 193 |
+
*/
|
| 194 |
+
public function unserialize($string)
|
| 195 |
+
{
|
| 196 |
+
list(
|
| 197 |
+
$this->_id,
|
| 198 |
+
$this->_wishlistId,
|
| 199 |
+
$this->_quantity,
|
| 200 |
+
$this->_price,
|
| 201 |
+
$this->_weight,
|
| 202 |
+
$this->_timestamp,
|
| 203 |
+
$this->_options,
|
| 204 |
+
$this->_product
|
| 205 |
+
) = unserialize($string);
|
| 206 |
+
|
| 207 |
+
return $this;
|
| 208 |
+
}
|
| 209 |
}
|
app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Wishlist/Item/Options.php
CHANGED
|
@@ -1,163 +1,163 @@
|
|
| 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 wishlist item options
|
| 29 |
-
*/
|
| 30 |
-
class Copernica_MarketingSoftware_Model_Abstraction_Wishlist_Item_Options implements Serializable
|
| 31 |
-
{
|
| 32 |
-
/**
|
| 33 |
-
* Predefine the internal fields
|
| 34 |
-
*/
|
| 35 |
-
protected $_name;
|
| 36 |
-
protected $_attributes = null;
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
/**
|
| 40 |
-
* Sets the original model
|
| 41 |
-
*
|
| 42 |
-
* @param Mage_Wishlist_Model_Item $original
|
| 43 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Wishlist_Item_Options
|
| 44 |
-
*/
|
| 45 |
-
public function setOriginal(Mage_Wishlist_Model_Item $original)
|
| 46 |
-
{
|
| 47 |
-
$this->_name = $original->getName();
|
| 48 |
-
|
| 49 |
-
$data = array();
|
| 50 |
-
|
| 51 |
-
if ($optionData = $original->getOptionByCode('info_buyRequest')) {
|
| 52 |
-
$product = $optionData->getProduct();
|
| 53 |
-
|
| 54 |
-
$options = $original->getProduct()->getTypeInstance(true)->getOrderOptions($original->getProduct());
|
| 55 |
-
|
| 56 |
-
$attributes = array();
|
| 57 |
-
|
| 58 |
-
if (isset($options['attributes_info'])) {
|
| 59 |
-
$attributes = $options['attributes_info'];
|
| 60 |
-
} elseif (isset($options['bundle_options'])) {
|
| 61 |
-
$attributes = $options['bundle_options'];
|
| 62 |
-
} elseif (isset($options['options'])) {
|
| 63 |
-
$attributes = $options['options'];
|
| 64 |
-
}
|
| 65 |
-
|
| 66 |
-
if ($attributes) {
|
| 67 |
-
foreach ($attributes as $attribute) {
|
| 68 |
-
$data[$attribute['label']] = $attribute['value'];
|
| 69 |
-
}
|
| 70 |
-
|
| 71 |
-
$this->_attributes = $data;
|
| 72 |
-
}
|
| 73 |
-
}
|
| 74 |
-
|
| 75 |
-
return $this;
|
| 76 |
-
}
|
| 77 |
-
|
| 78 |
-
/**
|
| 79 |
-
* The name of this set of options
|
| 80 |
-
*
|
| 81 |
-
* @return integer
|
| 82 |
-
*/
|
| 83 |
-
public function name()
|
| 84 |
-
{
|
| 85 |
-
return $this->_name;
|
| 86 |
-
}
|
| 87 |
-
|
| 88 |
-
/**
|
| 89 |
-
* Return an assoc array with attributes
|
| 90 |
-
*
|
| 91 |
-
* @return array
|
| 92 |
-
*/
|
| 93 |
-
public function attributes()
|
| 94 |
-
{
|
| 95 |
-
return $this->_attributes;
|
| 96 |
-
}
|
| 97 |
-
|
| 98 |
-
/**
|
| 99 |
-
* Return a string representation
|
| 100 |
-
*
|
| 101 |
-
* @return string
|
| 102 |
-
*/
|
| 103 |
-
public function __toString()
|
| 104 |
-
{
|
| 105 |
-
return $this->_arrayToString($this->_attributes());
|
| 106 |
-
}
|
| 107 |
-
|
| 108 |
-
/**
|
| 109 |
-
* Return a string representation of an array
|
| 110 |
-
*
|
| 111 |
-
* @param array $value
|
| 112 |
-
* @param string $prefix
|
| 113 |
-
* @return string
|
| 114 |
-
*/
|
| 115 |
-
protected function _arrayToString($value, $prefix = '')
|
| 116 |
-
{
|
| 117 |
-
$string = "";
|
| 118 |
-
|
| 119 |
-
foreach ($value as $key => $value) {
|
| 120 |
-
if (is_array($value)) {
|
| 121 |
-
if (isset($value[0]) && count($value) == 1) {
|
| 122 |
-
$value = $value[0];
|
| 123 |
-
}
|
| 124 |
-
|
| 125 |
-
$string .= $prefix.$key.":\n".$this->_arrayToString($value, $prefix.' ');
|
| 126 |
-
} else {
|
| 127 |
-
$string.= $prefix.$key.": $value\n";
|
| 128 |
-
}
|
| 129 |
-
}
|
| 130 |
-
|
| 131 |
-
return $string;
|
| 132 |
-
}
|
| 133 |
-
|
| 134 |
-
/**
|
| 135 |
-
* Serialize the object
|
| 136 |
-
*
|
| 137 |
-
* @return string
|
| 138 |
-
*/
|
| 139 |
-
public function serialize()
|
| 140 |
-
{
|
| 141 |
-
return serialize(array(
|
| 142 |
-
$this->name(),
|
| 143 |
-
$this->attributes(),
|
| 144 |
-
));
|
| 145 |
-
}
|
| 146 |
-
|
| 147 |
-
/**
|
| 148 |
-
* Unserialize the object
|
| 149 |
-
*
|
| 150 |
-
* @param string $string
|
| 151 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Wishlist_Item_Options
|
| 152 |
-
*/
|
| 153 |
-
public function unserialize($string)
|
| 154 |
-
{
|
| 155 |
-
list(
|
| 156 |
-
$this->_name,
|
| 157 |
-
$this->_attributes
|
| 158 |
-
) = unserialize($string);
|
| 159 |
-
|
| 160 |
-
return $this;
|
| 161 |
-
}
|
| 162 |
-
}
|
| 163 |
-
|
| 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 wishlist item options
|
| 29 |
+
*/
|
| 30 |
+
class Copernica_MarketingSoftware_Model_Abstraction_Wishlist_Item_Options implements Serializable
|
| 31 |
+
{
|
| 32 |
+
/**
|
| 33 |
+
* Predefine the internal fields
|
| 34 |
+
*/
|
| 35 |
+
protected $_name;
|
| 36 |
+
protected $_attributes = null;
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
/**
|
| 40 |
+
* Sets the original model
|
| 41 |
+
*
|
| 42 |
+
* @param Mage_Wishlist_Model_Item $original
|
| 43 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Wishlist_Item_Options
|
| 44 |
+
*/
|
| 45 |
+
public function setOriginal(Mage_Wishlist_Model_Item $original)
|
| 46 |
+
{
|
| 47 |
+
$this->_name = $original->getName();
|
| 48 |
+
|
| 49 |
+
$data = array();
|
| 50 |
+
|
| 51 |
+
if ($optionData = $original->getOptionByCode('info_buyRequest')) {
|
| 52 |
+
$product = $optionData->getProduct();
|
| 53 |
+
|
| 54 |
+
$options = $original->getProduct()->getTypeInstance(true)->getOrderOptions($original->getProduct());
|
| 55 |
+
|
| 56 |
+
$attributes = array();
|
| 57 |
+
|
| 58 |
+
if (isset($options['attributes_info'])) {
|
| 59 |
+
$attributes = $options['attributes_info'];
|
| 60 |
+
} elseif (isset($options['bundle_options'])) {
|
| 61 |
+
$attributes = $options['bundle_options'];
|
| 62 |
+
} elseif (isset($options['options'])) {
|
| 63 |
+
$attributes = $options['options'];
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
if ($attributes) {
|
| 67 |
+
foreach ($attributes as $attribute) {
|
| 68 |
+
$data[$attribute['label']] = $attribute['value'];
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
$this->_attributes = $data;
|
| 72 |
+
}
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
return $this;
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
/**
|
| 79 |
+
* The name of this set of options
|
| 80 |
+
*
|
| 81 |
+
* @return integer
|
| 82 |
+
*/
|
| 83 |
+
public function name()
|
| 84 |
+
{
|
| 85 |
+
return $this->_name;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
/**
|
| 89 |
+
* Return an assoc array with attributes
|
| 90 |
+
*
|
| 91 |
+
* @return array
|
| 92 |
+
*/
|
| 93 |
+
public function attributes()
|
| 94 |
+
{
|
| 95 |
+
return $this->_attributes;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
/**
|
| 99 |
+
* Return a string representation
|
| 100 |
+
*
|
| 101 |
+
* @return string
|
| 102 |
+
*/
|
| 103 |
+
public function __toString()
|
| 104 |
+
{
|
| 105 |
+
return $this->_arrayToString($this->_attributes());
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
/**
|
| 109 |
+
* Return a string representation of an array
|
| 110 |
+
*
|
| 111 |
+
* @param array $value
|
| 112 |
+
* @param string $prefix
|
| 113 |
+
* @return string
|
| 114 |
+
*/
|
| 115 |
+
protected function _arrayToString($value, $prefix = '')
|
| 116 |
+
{
|
| 117 |
+
$string = "";
|
| 118 |
+
|
| 119 |
+
foreach ($value as $key => $value) {
|
| 120 |
+
if (is_array($value)) {
|
| 121 |
+
if (isset($value[0]) && count($value) == 1) {
|
| 122 |
+
$value = $value[0];
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
$string .= $prefix.$key.":\n".$this->_arrayToString($value, $prefix.' ');
|
| 126 |
+
} else {
|
| 127 |
+
$string.= $prefix.$key.": $value\n";
|
| 128 |
+
}
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
return $string;
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
/**
|
| 135 |
+
* Serialize the object
|
| 136 |
+
*
|
| 137 |
+
* @return string
|
| 138 |
+
*/
|
| 139 |
+
public function serialize()
|
| 140 |
+
{
|
| 141 |
+
return serialize(array(
|
| 142 |
+
$this->name(),
|
| 143 |
+
$this->attributes(),
|
| 144 |
+
));
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
/**
|
| 148 |
+
* Unserialize the object
|
| 149 |
+
*
|
| 150 |
+
* @param string $string
|
| 151 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Wishlist_Item_Options
|
| 152 |
+
*/
|
| 153 |
+
public function unserialize($string)
|
| 154 |
+
{
|
| 155 |
+
list(
|
| 156 |
+
$this->_name,
|
| 157 |
+
$this->_attributes
|
| 158 |
+
) = unserialize($string);
|
| 159 |
+
|
| 160 |
+
return $this;
|
| 161 |
+
}
|
| 162 |
+
}
|
| 163 |
+
|
app/code/community/Copernica/MarketingSoftware/Model/Config.php
CHANGED
|
@@ -1,64 +1,64 @@
|
|
| 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 |
-
* With the config object the configuration options of the marketing
|
| 29 |
-
* software module are accessible.
|
| 30 |
-
*
|
| 31 |
-
* We do not use the Core_Config model, because everytime a config
|
| 32 |
-
* value is saved it will empty the config cache, which might throw
|
| 33 |
-
* errors on a high traffic website.
|
| 34 |
-
*
|
| 35 |
-
*/
|
| 36 |
-
class Copernica_MarketingSoftware_Model_Config extends Mage_Core_Model_Abstract
|
| 37 |
-
{
|
| 38 |
-
/**
|
| 39 |
-
* Constructor
|
| 40 |
-
*
|
| 41 |
-
* @see Varien_Object::_construct()
|
| 42 |
-
*/
|
| 43 |
-
protected function _construct()
|
| 44 |
-
{
|
| 45 |
-
$this->_init('marketingsoftware/config');
|
| 46 |
-
}
|
| 47 |
-
|
| 48 |
-
/**
|
| 49 |
-
* Load configuration row by it's key.
|
| 50 |
-
*
|
| 51 |
-
* @param string $key
|
| 52 |
-
* @return Copernica_MarketingSoftware_Model_Config
|
| 53 |
-
*/
|
| 54 |
-
public function loadByKey($key)
|
| 55 |
-
{
|
| 56 |
-
$this->_beforeLoad($key, 'key_name');
|
| 57 |
-
$this->_getResource()->load($this, $key, 'key_name');
|
| 58 |
-
$this->_afterLoad();
|
| 59 |
-
$this->setOrigData();
|
| 60 |
-
$this->_hasDataChanges = false;
|
| 61 |
-
|
| 62 |
-
return $this;
|
| 63 |
-
}
|
| 64 |
}
|
| 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 |
+
* With the config object the configuration options of the marketing
|
| 29 |
+
* software module are accessible.
|
| 30 |
+
*
|
| 31 |
+
* We do not use the Core_Config model, because everytime a config
|
| 32 |
+
* value is saved it will empty the config cache, which might throw
|
| 33 |
+
* errors on a high traffic website.
|
| 34 |
+
*
|
| 35 |
+
*/
|
| 36 |
+
class Copernica_MarketingSoftware_Model_Config extends Mage_Core_Model_Abstract
|
| 37 |
+
{
|
| 38 |
+
/**
|
| 39 |
+
* Constructor
|
| 40 |
+
*
|
| 41 |
+
* @see Varien_Object::_construct()
|
| 42 |
+
*/
|
| 43 |
+
protected function _construct()
|
| 44 |
+
{
|
| 45 |
+
$this->_init('marketingsoftware/config');
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
/**
|
| 49 |
+
* Load configuration row by it's key.
|
| 50 |
+
*
|
| 51 |
+
* @param string $key
|
| 52 |
+
* @return Copernica_MarketingSoftware_Model_Config
|
| 53 |
+
*/
|
| 54 |
+
public function loadByKey($key)
|
| 55 |
+
{
|
| 56 |
+
$this->_beforeLoad($key, 'key_name');
|
| 57 |
+
$this->_getResource()->load($this, $key, 'key_name');
|
| 58 |
+
$this->_afterLoad();
|
| 59 |
+
$this->setOrigData();
|
| 60 |
+
$this->_hasDataChanges = false;
|
| 61 |
+
|
| 62 |
+
return $this;
|
| 63 |
+
}
|
| 64 |
}
|
app/code/community/Copernica/MarketingSoftware/Model/Copernica/Entity.php
CHANGED
|
@@ -1,82 +1,82 @@
|
|
| 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 |
-
* This is a base class for all bridge classes between Magento and Copernica
|
| 29 |
-
*/
|
| 30 |
-
abstract class Copernica_MarketingSoftware_Model_Copernica_Entity
|
| 31 |
-
{
|
| 32 |
-
/**
|
| 33 |
-
* Cached data.
|
| 34 |
-
*
|
| 35 |
-
* @var array
|
| 36 |
-
*/
|
| 37 |
-
protected $_data = array();
|
| 38 |
-
|
| 39 |
-
/**
|
| 40 |
-
* This is a factory method that will produce proper entities.
|
| 41 |
-
*
|
| 42 |
-
* @todo Verify whether it is actually needed
|
| 43 |
-
* @param string $itemName
|
| 44 |
-
* @return Copernica_MarketingSoftware_Model_Copernica_Entity
|
| 45 |
-
*/
|
| 46 |
-
public function create($itemName)
|
| 47 |
-
{
|
| 48 |
-
$modelName = 'marketingsoftware/copernica_entity_'. $itemName;
|
| 49 |
-
|
| 50 |
-
if (!class_exists(Mage::getConfig()->getModelClassName($modelName))) {
|
| 51 |
-
return null;
|
| 52 |
-
}
|
| 53 |
-
|
| 54 |
-
return Mage::getModel($modelName);
|
| 55 |
-
}
|
| 56 |
-
|
| 57 |
-
/**
|
| 58 |
-
* @todo param arguments
|
| 59 |
-
* @param string $methodName
|
| 60 |
-
*/
|
| 61 |
-
public function __call($methodName, $arguments)
|
| 62 |
-
{
|
| 63 |
-
if (substr($methodName, 0, 3) != 'get') {
|
| 64 |
-
return null;
|
| 65 |
-
}
|
| 66 |
-
|
| 67 |
-
$property = substr($methodName, 3);
|
| 68 |
-
$property{0} = strtolower($property{0});
|
| 69 |
-
|
| 70 |
-
if (array_key_exists($property, $this->_data)) {
|
| 71 |
-
return $this->_data[$property];
|
| 72 |
-
}
|
| 73 |
-
|
| 74 |
-
$fetchMethod = 'fetch'.ucfirst($property);
|
| 75 |
-
|
| 76 |
-
if (method_exists($this, $fetchMethod) && !is_null($value = $this->$fetchMethod())) {
|
| 77 |
-
return $this->_data[$property] = $value;
|
| 78 |
-
}
|
| 79 |
-
|
| 80 |
-
return null;
|
| 81 |
-
}
|
| 82 |
}
|
| 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 |
+
* This is a base class for all bridge classes between Magento and Copernica
|
| 29 |
+
*/
|
| 30 |
+
abstract class Copernica_MarketingSoftware_Model_Copernica_Entity
|
| 31 |
+
{
|
| 32 |
+
/**
|
| 33 |
+
* Cached data.
|
| 34 |
+
*
|
| 35 |
+
* @var array
|
| 36 |
+
*/
|
| 37 |
+
protected $_data = array();
|
| 38 |
+
|
| 39 |
+
/**
|
| 40 |
+
* This is a factory method that will produce proper entities.
|
| 41 |
+
*
|
| 42 |
+
* @todo Verify whether it is actually needed
|
| 43 |
+
* @param string $itemName
|
| 44 |
+
* @return Copernica_MarketingSoftware_Model_Copernica_Entity
|
| 45 |
+
*/
|
| 46 |
+
public function create($itemName)
|
| 47 |
+
{
|
| 48 |
+
$modelName = 'marketingsoftware/copernica_entity_'. $itemName;
|
| 49 |
+
|
| 50 |
+
if (!class_exists(Mage::getConfig()->getModelClassName($modelName))) {
|
| 51 |
+
return null;
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
return Mage::getModel($modelName);
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
/**
|
| 58 |
+
* @todo param arguments
|
| 59 |
+
* @param string $methodName
|
| 60 |
+
*/
|
| 61 |
+
public function __call($methodName, $arguments)
|
| 62 |
+
{
|
| 63 |
+
if (substr($methodName, 0, 3) != 'get') {
|
| 64 |
+
return null;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
$property = substr($methodName, 3);
|
| 68 |
+
$property{0} = strtolower($property{0});
|
| 69 |
+
|
| 70 |
+
if (array_key_exists($property, $this->_data)) {
|
| 71 |
+
return $this->_data[$property];
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
$fetchMethod = 'fetch'.ucfirst($property);
|
| 75 |
+
|
| 76 |
+
if (method_exists($this, $fetchMethod) && !is_null($value = $this->$fetchMethod())) {
|
| 77 |
+
return $this->_data[$property] = $value;
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
return null;
|
| 81 |
+
}
|
| 82 |
}
|
app/code/community/Copernica/MarketingSoftware/Model/Copernica/Entity/Address.php
CHANGED
|
@@ -1,248 +1,248 @@
|
|
| 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 |
-
class Copernica_MarketingSoftware_Model_Copernica_Entity_Address extends Copernica_MarketingSoftware_Model_Copernica_Entity
|
| 28 |
-
{
|
| 29 |
-
/**
|
| 30 |
-
* Magento address model
|
| 31 |
-
*
|
| 32 |
-
* @var Mage_Customer_Model_Address
|
| 33 |
-
*/
|
| 34 |
-
protected $_address = null;
|
| 35 |
-
|
| 36 |
-
/**
|
| 37 |
-
* Due to legacy code this method is complicated.
|
| 38 |
-
*
|
| 39 |
-
* @return string
|
| 40 |
-
*/
|
| 41 |
-
public function fetchId()
|
| 42 |
-
{
|
| 43 |
-
switch (get_class($this->_address)) {
|
| 44 |
-
case 'Mage_Customer_Model_Address':
|
| 45 |
-
return 'ca_'.$this->_address->getId();
|
| 46 |
-
|
| 47 |
-
case 'Mage_Sales_Model_Order_Address':
|
| 48 |
-
if ($customerAddressId = $this->_address->getCustomerAddressId()) {
|
| 49 |
-
return 'ca_'.$customerAddressId;
|
| 50 |
-
}
|
| 51 |
-
else {
|
| 52 |
-
return 'oa_'.$this->_address->getId();
|
| 53 |
-
}
|
| 54 |
-
|
| 55 |
-
case 'Mage_Sales_Model_Quote_Address':
|
| 56 |
-
if ($customerAddressId = $this->_address->getCustomerAddressId()) {
|
| 57 |
-
return 'ca_'.$customerAddressId;
|
| 58 |
-
}
|
| 59 |
-
else {
|
| 60 |
-
return 'ca_'.$customerAddressId;
|
| 61 |
-
}
|
| 62 |
-
|
| 63 |
-
default:
|
| 64 |
-
return $this->_address->getId();
|
| 65 |
-
}
|
| 66 |
-
}
|
| 67 |
-
|
| 68 |
-
/**
|
| 69 |
-
* Fetch email
|
| 70 |
-
*
|
| 71 |
-
* @return string
|
| 72 |
-
*/
|
| 73 |
-
public function fetchEmail()
|
| 74 |
-
{
|
| 75 |
-
if ($email = $this->_address->getEmail()) {
|
| 76 |
-
return $email;
|
| 77 |
-
}
|
| 78 |
-
|
| 79 |
-
if (is_object($order = $this->_address->getOrder()) && $email = $order->getCustomerEmail()) {
|
| 80 |
-
return $email;
|
| 81 |
-
}
|
| 82 |
-
|
| 83 |
-
if (is_object($quote = $this->_address->getQuote()) && $email = $quote->getCustomerEmail()) {
|
| 84 |
-
return $email;
|
| 85 |
-
}
|
| 86 |
-
|
| 87 |
-
if (is_object($customer = $this->_address->getCustomer()) && $email = $customer->getEmail()) {
|
| 88 |
-
return $email;
|
| 89 |
-
}
|
| 90 |
-
|
| 91 |
-
return '';
|
| 92 |
-
}
|
| 93 |
-
|
| 94 |
-
/**
|
| 95 |
-
* Fetch name object for this address
|
| 96 |
-
*
|
| 97 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Name
|
| 98 |
-
*/
|
| 99 |
-
public function fetchName()
|
| 100 |
-
{
|
| 101 |
-
return Mage::getModel('marketingsoftware/abstraction_name')->setOriginal($this->_address);
|
| 102 |
-
}
|
| 103 |
-
|
| 104 |
-
/**
|
| 105 |
-
* Fetch firstname
|
| 106 |
-
*
|
| 107 |
-
* @return string
|
| 108 |
-
*/
|
| 109 |
-
public function fetchFirstname()
|
| 110 |
-
{
|
| 111 |
-
return $this->getName()->firstname();
|
| 112 |
-
}
|
| 113 |
-
|
| 114 |
-
/**
|
| 115 |
-
* Fetch middlename
|
| 116 |
-
*
|
| 117 |
-
* @return string
|
| 118 |
-
*/
|
| 119 |
-
public function fetchMiddlename()
|
| 120 |
-
{
|
| 121 |
-
return $this->getName()->middlename();
|
| 122 |
-
}
|
| 123 |
-
|
| 124 |
-
/**
|
| 125 |
-
* Fetch lastname
|
| 126 |
-
*
|
| 127 |
-
* @return string
|
| 128 |
-
*/
|
| 129 |
-
public function fetchLastname()
|
| 130 |
-
{
|
| 131 |
-
return $this->getName()->lastname();
|
| 132 |
-
}
|
| 133 |
-
|
| 134 |
-
/**
|
| 135 |
-
* Fetch prefix
|
| 136 |
-
*
|
| 137 |
-
* @return string
|
| 138 |
-
*/
|
| 139 |
-
public function fetchPrefix()
|
| 140 |
-
{
|
| 141 |
-
return $this->getName()->prefix();
|
| 142 |
-
}
|
| 143 |
-
|
| 144 |
-
/**
|
| 145 |
-
* Fetch street
|
| 146 |
-
*
|
| 147 |
-
* @return string
|
| 148 |
-
*/
|
| 149 |
-
public function fetchStreet()
|
| 150 |
-
{
|
| 151 |
-
return $this->_address->getStreetFull();
|
| 152 |
-
}
|
| 153 |
-
|
| 154 |
-
/**
|
| 155 |
-
* Fetch city
|
| 156 |
-
*
|
| 157 |
-
* @return string
|
| 158 |
-
*/
|
| 159 |
-
public function fetchCity()
|
| 160 |
-
{
|
| 161 |
-
return $this->_address->getCity();
|
| 162 |
-
}
|
| 163 |
-
|
| 164 |
-
/**
|
| 165 |
-
* Fetch postal code
|
| 166 |
-
*
|
| 167 |
-
* @return string
|
| 168 |
-
*/
|
| 169 |
-
public function fetchZipcode()
|
| 170 |
-
{
|
| 171 |
-
return $this->_address->getPostcode();
|
| 172 |
-
}
|
| 173 |
-
|
| 174 |
-
/**
|
| 175 |
-
* Fetch state
|
| 176 |
-
*
|
| 177 |
-
* @return string
|
| 178 |
-
*/
|
| 179 |
-
public function fetchState()
|
| 180 |
-
{
|
| 181 |
-
return $this->_address->getRegion();
|
| 182 |
-
}
|
| 183 |
-
|
| 184 |
-
/**
|
| 185 |
-
* Fetch country
|
| 186 |
-
*
|
| 187 |
-
* @return string
|
| 188 |
-
*/
|
| 189 |
-
public function fetchCountryId()
|
| 190 |
-
{
|
| 191 |
-
return $this->_address->getCountryId();
|
| 192 |
-
}
|
| 193 |
-
|
| 194 |
-
/**
|
| 195 |
-
* Fetch company
|
| 196 |
-
*
|
| 197 |
-
* @return string
|
| 198 |
-
*/
|
| 199 |
-
public function fetchCompany()
|
| 200 |
-
{
|
| 201 |
-
return $this->_address->getCompany();
|
| 202 |
-
}
|
| 203 |
-
|
| 204 |
-
/**
|
| 205 |
-
* Fetch telephone
|
| 206 |
-
*
|
| 207 |
-
* @return string
|
| 208 |
-
*/
|
| 209 |
-
public function fetchTelephone()
|
| 210 |
-
{
|
| 211 |
-
return $this->_address->getTelephone();
|
| 212 |
-
}
|
| 213 |
-
|
| 214 |
-
/**
|
| 215 |
-
* Fetch fax
|
| 216 |
-
*
|
| 217 |
-
* @return string
|
| 218 |
-
*/
|
| 219 |
-
public function fetchFax()
|
| 220 |
-
{
|
| 221 |
-
return $this->_address->getFax();
|
| 222 |
-
}
|
| 223 |
-
|
| 224 |
-
/**
|
| 225 |
-
* Get REST address entity
|
| 226 |
-
*
|
| 227 |
-
* @return Copernica_MarketingSoftware_Model_Rest_Address
|
| 228 |
-
*/
|
| 229 |
-
public function getRestAddress()
|
| 230 |
-
{
|
| 231 |
-
$restAddress = Mage::getModel('marketingsoftware/rest_address');
|
| 232 |
-
$restAddress->setAddressEntity($this);
|
| 233 |
-
|
| 234 |
-
return $restAddress;
|
| 235 |
-
}
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
/**
|
| 239 |
-
* Set address entity
|
| 240 |
-
* It is expecting to receive one of magento address types.
|
| 241 |
-
*
|
| 242 |
-
* @param Mage_Customer_Model_Address|Mage_Sales_Model_Order_Address|Mage_Sales_Model_Quote_Address $address
|
| 243 |
-
*/
|
| 244 |
-
public function setAddress($address)
|
| 245 |
-
{
|
| 246 |
-
$this->_address = $address;
|
| 247 |
-
}
|
| 248 |
}
|
| 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 |
+
class Copernica_MarketingSoftware_Model_Copernica_Entity_Address extends Copernica_MarketingSoftware_Model_Copernica_Entity
|
| 28 |
+
{
|
| 29 |
+
/**
|
| 30 |
+
* Magento address model
|
| 31 |
+
*
|
| 32 |
+
* @var Mage_Customer_Model_Address
|
| 33 |
+
*/
|
| 34 |
+
protected $_address = null;
|
| 35 |
+
|
| 36 |
+
/**
|
| 37 |
+
* Due to legacy code this method is complicated.
|
| 38 |
+
*
|
| 39 |
+
* @return string
|
| 40 |
+
*/
|
| 41 |
+
public function fetchId()
|
| 42 |
+
{
|
| 43 |
+
switch (get_class($this->_address)) {
|
| 44 |
+
case 'Mage_Customer_Model_Address':
|
| 45 |
+
return 'ca_'.$this->_address->getId();
|
| 46 |
+
|
| 47 |
+
case 'Mage_Sales_Model_Order_Address':
|
| 48 |
+
if ($customerAddressId = $this->_address->getCustomerAddressId()) {
|
| 49 |
+
return 'ca_'.$customerAddressId;
|
| 50 |
+
}
|
| 51 |
+
else {
|
| 52 |
+
return 'oa_'.$this->_address->getId();
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
case 'Mage_Sales_Model_Quote_Address':
|
| 56 |
+
if ($customerAddressId = $this->_address->getCustomerAddressId()) {
|
| 57 |
+
return 'ca_'.$customerAddressId;
|
| 58 |
+
}
|
| 59 |
+
else {
|
| 60 |
+
return 'ca_'.$customerAddressId;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
default:
|
| 64 |
+
return $this->_address->getId();
|
| 65 |
+
}
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
/**
|
| 69 |
+
* Fetch email
|
| 70 |
+
*
|
| 71 |
+
* @return string
|
| 72 |
+
*/
|
| 73 |
+
public function fetchEmail()
|
| 74 |
+
{
|
| 75 |
+
if ($email = $this->_address->getEmail()) {
|
| 76 |
+
return $email;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
if (is_object($order = $this->_address->getOrder()) && $email = $order->getCustomerEmail()) {
|
| 80 |
+
return $email;
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
if (is_object($quote = $this->_address->getQuote()) && $email = $quote->getCustomerEmail()) {
|
| 84 |
+
return $email;
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
if (is_object($customer = $this->_address->getCustomer()) && $email = $customer->getEmail()) {
|
| 88 |
+
return $email;
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
return '';
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
/**
|
| 95 |
+
* Fetch name object for this address
|
| 96 |
+
*
|
| 97 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Name
|
| 98 |
+
*/
|
| 99 |
+
public function fetchName()
|
| 100 |
+
{
|
| 101 |
+
return Mage::getModel('marketingsoftware/abstraction_name')->setOriginal($this->_address);
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
/**
|
| 105 |
+
* Fetch firstname
|
| 106 |
+
*
|
| 107 |
+
* @return string
|
| 108 |
+
*/
|
| 109 |
+
public function fetchFirstname()
|
| 110 |
+
{
|
| 111 |
+
return $this->getName()->firstname();
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
/**
|
| 115 |
+
* Fetch middlename
|
| 116 |
+
*
|
| 117 |
+
* @return string
|
| 118 |
+
*/
|
| 119 |
+
public function fetchMiddlename()
|
| 120 |
+
{
|
| 121 |
+
return $this->getName()->middlename();
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
/**
|
| 125 |
+
* Fetch lastname
|
| 126 |
+
*
|
| 127 |
+
* @return string
|
| 128 |
+
*/
|
| 129 |
+
public function fetchLastname()
|
| 130 |
+
{
|
| 131 |
+
return $this->getName()->lastname();
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
/**
|
| 135 |
+
* Fetch prefix
|
| 136 |
+
*
|
| 137 |
+
* @return string
|
| 138 |
+
*/
|
| 139 |
+
public function fetchPrefix()
|
| 140 |
+
{
|
| 141 |
+
return $this->getName()->prefix();
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
/**
|
| 145 |
+
* Fetch street
|
| 146 |
+
*
|
| 147 |
+
* @return string
|
| 148 |
+
*/
|
| 149 |
+
public function fetchStreet()
|
| 150 |
+
{
|
| 151 |
+
return $this->_address->getStreetFull();
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
/**
|
| 155 |
+
* Fetch city
|
| 156 |
+
*
|
| 157 |
+
* @return string
|
| 158 |
+
*/
|
| 159 |
+
public function fetchCity()
|
| 160 |
+
{
|
| 161 |
+
return $this->_address->getCity();
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
/**
|
| 165 |
+
* Fetch postal code
|
| 166 |
+
*
|
| 167 |
+
* @return string
|
| 168 |
+
*/
|
| 169 |
+
public function fetchZipcode()
|
| 170 |
+
{
|
| 171 |
+
return $this->_address->getPostcode();
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
/**
|
| 175 |
+
* Fetch state
|
| 176 |
+
*
|
| 177 |
+
* @return string
|
| 178 |
+
*/
|
| 179 |
+
public function fetchState()
|
| 180 |
+
{
|
| 181 |
+
return $this->_address->getRegion();
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
/**
|
| 185 |
+
* Fetch country
|
| 186 |
+
*
|
| 187 |
+
* @return string
|
| 188 |
+
*/
|
| 189 |
+
public function fetchCountryId()
|
| 190 |
+
{
|
| 191 |
+
return $this->_address->getCountryId();
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
/**
|
| 195 |
+
* Fetch company
|
| 196 |
+
*
|
| 197 |
+
* @return string
|
| 198 |
+
*/
|
| 199 |
+
public function fetchCompany()
|
| 200 |
+
{
|
| 201 |
+
return $this->_address->getCompany();
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
/**
|
| 205 |
+
* Fetch telephone
|
| 206 |
+
*
|
| 207 |
+
* @return string
|
| 208 |
+
*/
|
| 209 |
+
public function fetchTelephone()
|
| 210 |
+
{
|
| 211 |
+
return $this->_address->getTelephone();
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
/**
|
| 215 |
+
* Fetch fax
|
| 216 |
+
*
|
| 217 |
+
* @return string
|
| 218 |
+
*/
|
| 219 |
+
public function fetchFax()
|
| 220 |
+
{
|
| 221 |
+
return $this->_address->getFax();
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
/**
|
| 225 |
+
* Get REST address entity
|
| 226 |
+
*
|
| 227 |
+
* @return Copernica_MarketingSoftware_Model_Rest_Address
|
| 228 |
+
*/
|
| 229 |
+
public function getRestAddress()
|
| 230 |
+
{
|
| 231 |
+
$restAddress = Mage::getModel('marketingsoftware/rest_address');
|
| 232 |
+
$restAddress->setAddressEntity($this);
|
| 233 |
+
|
| 234 |
+
return $restAddress;
|
| 235 |
+
}
|
| 236 |
+
|
| 237 |
+
|
| 238 |
+
/**
|
| 239 |
+
* Set address entity
|
| 240 |
+
* It is expecting to receive one of magento address types.
|
| 241 |
+
*
|
| 242 |
+
* @param Mage_Customer_Model_Address|Mage_Sales_Model_Order_Address|Mage_Sales_Model_Quote_Address $address
|
| 243 |
+
*/
|
| 244 |
+
public function setAddress($address)
|
| 245 |
+
{
|
| 246 |
+
$this->_address = $address;
|
| 247 |
+
}
|
| 248 |
}
|
app/code/community/Copernica/MarketingSoftware/Model/Copernica/Entity/Customer.php
CHANGED
|
@@ -1,384 +1,384 @@
|
|
| 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 |
-
* This class is a bridge class between magento customer and copernica profile
|
| 29 |
-
*/
|
| 30 |
-
class Copernica_MarketingSoftware_Model_Copernica_Entity_Customer extends Copernica_MarketingSoftware_Model_Copernica_Entity
|
| 31 |
-
{
|
| 32 |
-
/**
|
| 33 |
-
* Magento customer
|
| 34 |
-
*
|
| 35 |
-
* @var Mage_Customer_Model_Customer
|
| 36 |
-
*/
|
| 37 |
-
protected $_customer = null;
|
| 38 |
-
|
| 39 |
-
/**
|
| 40 |
-
* Array of customer addresses
|
| 41 |
-
*
|
| 42 |
-
* @var array
|
| 43 |
-
*/
|
| 44 |
-
protected $_addresses = null;
|
| 45 |
-
|
| 46 |
-
/**
|
| 47 |
-
* Array of customer orders
|
| 48 |
-
*
|
| 49 |
-
* @var array
|
| 50 |
-
*/
|
| 51 |
-
protected $_orders = null;
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
/**
|
| 55 |
-
* Array of customer wishlist items
|
| 56 |
-
*
|
| 57 |
-
* @var array
|
| 58 |
-
*/
|
| 59 |
-
protected $_wishlistItems = null;
|
| 60 |
-
|
| 61 |
-
/**
|
| 62 |
-
* Cache profile Id
|
| 63 |
-
*
|
| 64 |
-
* @var string
|
| 65 |
-
*/
|
| 66 |
-
protected $_profileId = null;
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
/**
|
| 70 |
-
*
|
| 71 |
-
* @var Copernica_MarketingSoftware_Model_Abstraction_Storeview
|
| 72 |
-
*/
|
| 73 |
-
protected $_store = null;
|
| 74 |
-
|
| 75 |
-
/**
|
| 76 |
-
* Fetch store view
|
| 77 |
-
*
|
| 78 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Storeview
|
| 79 |
-
*/
|
| 80 |
-
public function fetchStoreView()
|
| 81 |
-
{
|
| 82 |
-
if ($this->_store) {
|
| 83 |
-
return $this->_store;
|
| 84 |
-
} else {
|
| 85 |
-
return Mage::getModel('marketingsoftware/abstraction_storeview')->setOriginal($this->_customer->getStore());
|
| 86 |
-
}
|
| 87 |
-
}
|
| 88 |
-
|
| 89 |
-
/**
|
| 90 |
-
* Fetch magento customer id
|
| 91 |
-
*
|
| 92 |
-
* @return string
|
| 93 |
-
*/
|
| 94 |
-
public function fetchId()
|
| 95 |
-
{
|
| 96 |
-
return $this->_customer->getId();
|
| 97 |
-
}
|
| 98 |
-
|
| 99 |
-
/**
|
| 100 |
-
* Our unique customer ID in the form of customer_ID|storeView_ID
|
| 101 |
-
*
|
| 102 |
-
* @return string
|
| 103 |
-
*/
|
| 104 |
-
public function fetchCustomerId()
|
| 105 |
-
{
|
| 106 |
-
return $this->getId().'|'.$this->getStoreView()->id();
|
| 107 |
-
}
|
| 108 |
-
|
| 109 |
-
/**
|
| 110 |
-
* Fetch name
|
| 111 |
-
*
|
| 112 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Name
|
| 113 |
-
*/
|
| 114 |
-
public function fetchName()
|
| 115 |
-
{
|
| 116 |
-
return Mage::getModel('marketingsoftware/abstraction_name')->setOriginal($this->_customer);
|
| 117 |
-
}
|
| 118 |
-
|
| 119 |
-
/**
|
| 120 |
-
* Fetch firstname
|
| 121 |
-
*
|
| 122 |
-
* @return string
|
| 123 |
-
*/
|
| 124 |
-
public function fetchFirstname()
|
| 125 |
-
{
|
| 126 |
-
return $this->getName()->firstname();
|
| 127 |
-
}
|
| 128 |
-
|
| 129 |
-
/**
|
| 130 |
-
* Fetch middlename
|
| 131 |
-
*
|
| 132 |
-
* @return string
|
| 133 |
-
*/
|
| 134 |
-
public function fetchMiddlename()
|
| 135 |
-
{
|
| 136 |
-
return $this->getName()->middlename();
|
| 137 |
-
}
|
| 138 |
-
|
| 139 |
-
/**
|
| 140 |
-
* Fetch lastname
|
| 141 |
-
*
|
| 142 |
-
* @return string
|
| 143 |
-
*/
|
| 144 |
-
public function fetchLastname()
|
| 145 |
-
{
|
| 146 |
-
return $this->getName()->lastname();
|
| 147 |
-
}
|
| 148 |
-
|
| 149 |
-
/**
|
| 150 |
-
* Fetch email
|
| 151 |
-
*
|
| 152 |
-
* @return string
|
| 153 |
-
*/
|
| 154 |
-
public function fetchEmail()
|
| 155 |
-
{
|
| 156 |
-
return $this->_customer->getEmail();
|
| 157 |
-
}
|
| 158 |
-
|
| 159 |
-
/**
|
| 160 |
-
* Fetch registration date
|
| 161 |
-
*
|
| 162 |
-
* @return string
|
| 163 |
-
*/
|
| 164 |
-
public function fetchRegistrationDate()
|
| 165 |
-
{
|
| 166 |
-
return date('Y-m-d H:i:s', $this->_customer->getCreatedAtTimestamp());
|
| 167 |
-
}
|
| 168 |
-
|
| 169 |
-
/**
|
| 170 |
-
* Fetch newsletter status
|
| 171 |
-
*
|
| 172 |
-
* @return string
|
| 173 |
-
*/
|
| 174 |
-
public function fetchNewsletter()
|
| 175 |
-
{
|
| 176 |
-
$subscriber = Mage::getModel('newsletter/subscriber')->loadByCustomer($this->_customer);
|
| 177 |
-
|
| 178 |
-
if (!$subscriber->getId()) {
|
| 179 |
-
return 'unknown';
|
| 180 |
-
}
|
| 181 |
-
|
| 182 |
-
switch($subscriber->getStatus()) {
|
| 183 |
-
case Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED:
|
| 184 |
-
return 'subscribed';
|
| 185 |
-
|
| 186 |
-
case Mage_Newsletter_Model_Subscriber::STATUS_NOT_ACTIVE:
|
| 187 |
-
return 'not active';
|
| 188 |
-
|
| 189 |
-
case Mage_Newsletter_Model_Subscriber::STATUS_UNSUBSCRIBED:
|
| 190 |
-
return 'unsubscribed';
|
| 191 |
-
|
| 192 |
-
case Mage_Newsletter_Model_Subscriber::STATUS_UNCONFIRMED:
|
| 193 |
-
return 'unconfirmed';
|
| 194 |
-
|
| 195 |
-
default:
|
| 196 |
-
return 'unknown';
|
| 197 |
-
}
|
| 198 |
-
}
|
| 199 |
-
|
| 200 |
-
/**
|
| 201 |
-
* Fetch gender
|
| 202 |
-
*
|
| 203 |
-
* @return string
|
| 204 |
-
*/
|
| 205 |
-
public function fetchGender()
|
| 206 |
-
{
|
| 207 |
-
$options = $this->_customer->getAttribute('gender')->getSource()->getAllOptions();
|
| 208 |
-
|
| 209 |
-
$customerGenderIdx = $this->_customer->getGender();
|
| 210 |
-
|
| 211 |
-
foreach ($options as $option) {
|
| 212 |
-
if ($option['value'] == $customerGenderIdx) {
|
| 213 |
-
return $option['label'];
|
| 214 |
-
}
|
| 215 |
-
}
|
| 216 |
-
|
| 217 |
-
return 'unknown';
|
| 218 |
-
}
|
| 219 |
-
|
| 220 |
-
/**
|
| 221 |
-
* Fetch date of birth
|
| 222 |
-
*
|
| 223 |
-
* @return string
|
| 224 |
-
*/
|
| 225 |
-
public function getBirthDate()
|
| 226 |
-
{
|
| 227 |
-
return $this->_customer->getDob();
|
| 228 |
-
}
|
| 229 |
-
|
| 230 |
-
/**
|
| 231 |
-
* Return all customer addresses
|
| 232 |
-
*
|
| 233 |
-
* @return array
|
| 234 |
-
*/
|
| 235 |
-
public function getAddresses()
|
| 236 |
-
{
|
| 237 |
-
if (!is_null($this->_addresses)) {
|
| 238 |
-
return $this->_addresses;
|
| 239 |
-
}
|
| 240 |
-
|
| 241 |
-
$addresses = array();
|
| 242 |
-
|
| 243 |
-
foreach ($this->_customer->getAddresses() as $address) {
|
| 244 |
-
$addressEntity = Mage::getModel('marketingsoftware/copernica_entity_address');
|
| 245 |
-
$addressEntity->setAddress($address);
|
| 246 |
-
|
| 247 |
-
$addresses[] = $addressEntity;
|
| 248 |
-
}
|
| 249 |
-
|
| 250 |
-
return $this->_addresses = $addresses;
|
| 251 |
-
}
|
| 252 |
-
|
| 253 |
-
/**
|
| 254 |
-
* Get all customer orders
|
| 255 |
-
*
|
| 256 |
-
* @return array
|
| 257 |
-
*/
|
| 258 |
-
public function getOrders()
|
| 259 |
-
{
|
| 260 |
-
if (!is_null($this->_orders)) {
|
| 261 |
-
return $this->_orders;
|
| 262 |
-
}
|
| 263 |
-
|
| 264 |
-
$orders = array();
|
| 265 |
-
|
| 266 |
-
$ordersCollection = Mage::getModel('sales/order')->getCollection()->addFieldToFilter('customer_id', $this->_customer->getId());
|
| 267 |
-
|
| 268 |
-
foreach ($ordersCollection as $order) {
|
| 269 |
-
$orderEntity = Mage::getModel('marketingsoftware/copernica_entity_order');
|
| 270 |
-
$orderEntity->setOrder($order);
|
| 271 |
-
|
| 272 |
-
$orders[] = $orderEntity;
|
| 273 |
-
}
|
| 274 |
-
|
| 275 |
-
return $this->_orders = $orders;
|
| 276 |
-
}
|
| 277 |
-
|
| 278 |
-
/**
|
| 279 |
-
* Get all customer wishlist items
|
| 280 |
-
*
|
| 281 |
-
* @return array
|
| 282 |
-
*/
|
| 283 |
-
public function getWishlistItems()
|
| 284 |
-
{
|
| 285 |
-
if (!is_null($this->_wishlistItems)) {
|
| 286 |
-
return $this->_wishlistItems;
|
| 287 |
-
}
|
| 288 |
-
|
| 289 |
-
$wishlistItems = array();
|
| 290 |
-
|
| 291 |
-
$wishlist = Mage::getModel('wishlist/wishlist')->loadByCustomer($this->getId());
|
| 292 |
-
|
| 293 |
-
$wishlistItemCollection = Mage::getModel('wishlist/item')->getCollection()->addFieldToFilter('wishlist_id', $wishlist->getId());
|
| 294 |
-
|
| 295 |
-
foreach ($wishlistItemCollection as $wishlistItem) {
|
| 296 |
-
$wishlistItemEntity = Mage::getModel('marketingsoftware/copernica_entity_wishlist_item');
|
| 297 |
-
$wishlistItemEntity->setWishlistItem($wishlistItem);
|
| 298 |
-
|
| 299 |
-
$wishlistItems[] = $wishlistItemEntity;
|
| 300 |
-
}
|
| 301 |
-
|
| 302 |
-
return $this->_wishlistItems = $wishlistItems;
|
| 303 |
-
}
|
| 304 |
-
|
| 305 |
-
/**
|
| 306 |
-
* Fetch group
|
| 307 |
-
*
|
| 308 |
-
* @return string
|
| 309 |
-
*/
|
| 310 |
-
public function fetchGroup()
|
| 311 |
-
{
|
| 312 |
-
return Mage::getModel('customer/group')->load($this->_customer->getGroupId())->getCode();
|
| 313 |
-
}
|
| 314 |
-
|
| 315 |
-
/**
|
| 316 |
-
* Get REST customer
|
| 317 |
-
*
|
| 318 |
-
* @return Copernica_MarketingSoftware_Model_Rest_Customer
|
| 319 |
-
*/
|
| 320 |
-
public function getRestCustomer()
|
| 321 |
-
{
|
| 322 |
-
$restCustomer = Mage::getModel('marketingsoftware/rest_customer');
|
| 323 |
-
$restCustomer->setCustomerEntity($this);
|
| 324 |
-
|
| 325 |
-
return $restCustomer;
|
| 326 |
-
}
|
| 327 |
-
|
| 328 |
-
/**
|
| 329 |
-
* Get profile Id
|
| 330 |
-
*
|
| 331 |
-
* @param string $storeviewText
|
| 332 |
-
* @param int $id
|
| 333 |
-
* @return string|false
|
| 334 |
-
*/
|
| 335 |
-
public function getProfileId()
|
| 336 |
-
{
|
| 337 |
-
if (!is_null($this->_profileId)) {
|
| 338 |
-
return $this->_profileId;
|
| 339 |
-
}
|
| 340 |
-
|
| 341 |
-
$profileId = Mage::helper('marketingsoftware/api')->getProfileId(array(
|
| 342 |
-
'id' => $this->getCustomerId(),
|
| 343 |
-
'email' => $this->getEmail(),
|
| 344 |
-
'storeView' => strval($this->getStoreView()),
|
| 345 |
-
));
|
| 346 |
-
|
| 347 |
-
if ($profileId) {
|
| 348 |
-
return $this->_profileId = $profileId;
|
| 349 |
-
}
|
| 350 |
-
|
| 351 |
-
return false;
|
| 352 |
-
}
|
| 353 |
-
|
| 354 |
-
/**
|
| 355 |
-
* Set customer entity
|
| 356 |
-
*
|
| 357 |
-
* @param int $customerId
|
| 358 |
-
*/
|
| 359 |
-
public function setCustomer($customerId)
|
| 360 |
-
{
|
| 361 |
-
$customer = Mage::getModel('customer/customer')->load($customerId);
|
| 362 |
-
|
| 363 |
-
if (!$customer->isObjectNew()) {
|
| 364 |
-
$this->_customer = $customer;
|
| 365 |
-
} else {
|
| 366 |
-
throw Mage::exception('Copernica_MarketingSoftware', 'Customer does not exists', Copernica_MarketingSoftware_Exception::CUSTOMER_NOT_EXISTS);
|
| 367 |
-
}
|
| 368 |
-
}
|
| 369 |
-
|
| 370 |
-
/**
|
| 371 |
-
* Set the storeView
|
| 372 |
-
*
|
| 373 |
-
* @param Copernica_MarketingSoftware_Model_Abstraction_Storeview $store
|
| 374 |
-
*/
|
| 375 |
-
public function setStore($store)
|
| 376 |
-
{
|
| 377 |
-
if (!$this->_store || $this->_store->id() != $store->id()) {
|
| 378 |
-
unset($this->_data['storeView']);
|
| 379 |
-
unset($this->_data['customerId']);
|
| 380 |
-
$this->_profileId = null;
|
| 381 |
-
$this->_store = $store;
|
| 382 |
-
}
|
| 383 |
-
}
|
| 384 |
-
}
|
| 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 |
+
* This class is a bridge class between magento customer and copernica profile
|
| 29 |
+
*/
|
| 30 |
+
class Copernica_MarketingSoftware_Model_Copernica_Entity_Customer extends Copernica_MarketingSoftware_Model_Copernica_Entity
|
| 31 |
+
{
|
| 32 |
+
/**
|
| 33 |
+
* Magento customer
|
| 34 |
+
*
|
| 35 |
+
* @var Mage_Customer_Model_Customer
|
| 36 |
+
*/
|
| 37 |
+
protected $_customer = null;
|
| 38 |
+
|
| 39 |
+
/**
|
| 40 |
+
* Array of customer addresses
|
| 41 |
+
*
|
| 42 |
+
* @var array
|
| 43 |
+
*/
|
| 44 |
+
protected $_addresses = null;
|
| 45 |
+
|
| 46 |
+
/**
|
| 47 |
+
* Array of customer orders
|
| 48 |
+
*
|
| 49 |
+
* @var array
|
| 50 |
+
*/
|
| 51 |
+
protected $_orders = null;
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
/**
|
| 55 |
+
* Array of customer wishlist items
|
| 56 |
+
*
|
| 57 |
+
* @var array
|
| 58 |
+
*/
|
| 59 |
+
protected $_wishlistItems = null;
|
| 60 |
+
|
| 61 |
+
/**
|
| 62 |
+
* Cache profile Id
|
| 63 |
+
*
|
| 64 |
+
* @var string
|
| 65 |
+
*/
|
| 66 |
+
protected $_profileId = null;
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
/**
|
| 70 |
+
*
|
| 71 |
+
* @var Copernica_MarketingSoftware_Model_Abstraction_Storeview
|
| 72 |
+
*/
|
| 73 |
+
protected $_store = null;
|
| 74 |
+
|
| 75 |
+
/**
|
| 76 |
+
* Fetch store view
|
| 77 |
+
*
|
| 78 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Storeview
|
| 79 |
+
*/
|
| 80 |
+
public function fetchStoreView()
|
| 81 |
+
{
|
| 82 |
+
if ($this->_store) {
|
| 83 |
+
return $this->_store;
|
| 84 |
+
} else {
|
| 85 |
+
return Mage::getModel('marketingsoftware/abstraction_storeview')->setOriginal($this->_customer->getStore());
|
| 86 |
+
}
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
/**
|
| 90 |
+
* Fetch magento customer id
|
| 91 |
+
*
|
| 92 |
+
* @return string
|
| 93 |
+
*/
|
| 94 |
+
public function fetchId()
|
| 95 |
+
{
|
| 96 |
+
return $this->_customer->getId();
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
/**
|
| 100 |
+
* Our unique customer ID in the form of customer_ID|storeView_ID
|
| 101 |
+
*
|
| 102 |
+
* @return string
|
| 103 |
+
*/
|
| 104 |
+
public function fetchCustomerId()
|
| 105 |
+
{
|
| 106 |
+
return $this->getId().'|'.$this->getStoreView()->id();
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
/**
|
| 110 |
+
* Fetch name
|
| 111 |
+
*
|
| 112 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Name
|
| 113 |
+
*/
|
| 114 |
+
public function fetchName()
|
| 115 |
+
{
|
| 116 |
+
return Mage::getModel('marketingsoftware/abstraction_name')->setOriginal($this->_customer);
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
/**
|
| 120 |
+
* Fetch firstname
|
| 121 |
+
*
|
| 122 |
+
* @return string
|
| 123 |
+
*/
|
| 124 |
+
public function fetchFirstname()
|
| 125 |
+
{
|
| 126 |
+
return $this->getName()->firstname();
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
/**
|
| 130 |
+
* Fetch middlename
|
| 131 |
+
*
|
| 132 |
+
* @return string
|
| 133 |
+
*/
|
| 134 |
+
public function fetchMiddlename()
|
| 135 |
+
{
|
| 136 |
+
return $this->getName()->middlename();
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
/**
|
| 140 |
+
* Fetch lastname
|
| 141 |
+
*
|
| 142 |
+
* @return string
|
| 143 |
+
*/
|
| 144 |
+
public function fetchLastname()
|
| 145 |
+
{
|
| 146 |
+
return $this->getName()->lastname();
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
/**
|
| 150 |
+
* Fetch email
|
| 151 |
+
*
|
| 152 |
+
* @return string
|
| 153 |
+
*/
|
| 154 |
+
public function fetchEmail()
|
| 155 |
+
{
|
| 156 |
+
return $this->_customer->getEmail();
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
/**
|
| 160 |
+
* Fetch registration date
|
| 161 |
+
*
|
| 162 |
+
* @return string
|
| 163 |
+
*/
|
| 164 |
+
public function fetchRegistrationDate()
|
| 165 |
+
{
|
| 166 |
+
return date('Y-m-d H:i:s', $this->_customer->getCreatedAtTimestamp());
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
/**
|
| 170 |
+
* Fetch newsletter status
|
| 171 |
+
*
|
| 172 |
+
* @return string
|
| 173 |
+
*/
|
| 174 |
+
public function fetchNewsletter()
|
| 175 |
+
{
|
| 176 |
+
$subscriber = Mage::getModel('newsletter/subscriber')->loadByCustomer($this->_customer);
|
| 177 |
+
|
| 178 |
+
if (!$subscriber->getId()) {
|
| 179 |
+
return 'unknown';
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
switch($subscriber->getStatus()) {
|
| 183 |
+
case Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED:
|
| 184 |
+
return 'subscribed';
|
| 185 |
+
|
| 186 |
+
case Mage_Newsletter_Model_Subscriber::STATUS_NOT_ACTIVE:
|
| 187 |
+
return 'not active';
|
| 188 |
+
|
| 189 |
+
case Mage_Newsletter_Model_Subscriber::STATUS_UNSUBSCRIBED:
|
| 190 |
+
return 'unsubscribed';
|
| 191 |
+
|
| 192 |
+
case Mage_Newsletter_Model_Subscriber::STATUS_UNCONFIRMED:
|
| 193 |
+
return 'unconfirmed';
|
| 194 |
+
|
| 195 |
+
default:
|
| 196 |
+
return 'unknown';
|
| 197 |
+
}
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
/**
|
| 201 |
+
* Fetch gender
|
| 202 |
+
*
|
| 203 |
+
* @return string
|
| 204 |
+
*/
|
| 205 |
+
public function fetchGender()
|
| 206 |
+
{
|
| 207 |
+
$options = $this->_customer->getAttribute('gender')->getSource()->getAllOptions();
|
| 208 |
+
|
| 209 |
+
$customerGenderIdx = $this->_customer->getGender();
|
| 210 |
+
|
| 211 |
+
foreach ($options as $option) {
|
| 212 |
+
if ($option['value'] == $customerGenderIdx) {
|
| 213 |
+
return $option['label'];
|
| 214 |
+
}
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
return 'unknown';
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
/**
|
| 221 |
+
* Fetch date of birth
|
| 222 |
+
*
|
| 223 |
+
* @return string
|
| 224 |
+
*/
|
| 225 |
+
public function getBirthDate()
|
| 226 |
+
{
|
| 227 |
+
return $this->_customer->getDob();
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
/**
|
| 231 |
+
* Return all customer addresses
|
| 232 |
+
*
|
| 233 |
+
* @return array
|
| 234 |
+
*/
|
| 235 |
+
public function getAddresses()
|
| 236 |
+
{
|
| 237 |
+
if (!is_null($this->_addresses)) {
|
| 238 |
+
return $this->_addresses;
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
$addresses = array();
|
| 242 |
+
|
| 243 |
+
foreach ($this->_customer->getAddresses() as $address) {
|
| 244 |
+
$addressEntity = Mage::getModel('marketingsoftware/copernica_entity_address');
|
| 245 |
+
$addressEntity->setAddress($address);
|
| 246 |
+
|
| 247 |
+
$addresses[] = $addressEntity;
|
| 248 |
+
}
|
| 249 |
+
|
| 250 |
+
return $this->_addresses = $addresses;
|
| 251 |
+
}
|
| 252 |
+
|
| 253 |
+
/**
|
| 254 |
+
* Get all customer orders
|
| 255 |
+
*
|
| 256 |
+
* @return array
|
| 257 |
+
*/
|
| 258 |
+
public function getOrders()
|
| 259 |
+
{
|
| 260 |
+
if (!is_null($this->_orders)) {
|
| 261 |
+
return $this->_orders;
|
| 262 |
+
}
|
| 263 |
+
|
| 264 |
+
$orders = array();
|
| 265 |
+
|
| 266 |
+
$ordersCollection = Mage::getModel('sales/order')->getCollection()->addFieldToFilter('customer_id', $this->_customer->getId());
|
| 267 |
+
|
| 268 |
+
foreach ($ordersCollection as $order) {
|
| 269 |
+
$orderEntity = Mage::getModel('marketingsoftware/copernica_entity_order');
|
| 270 |
+
$orderEntity->setOrder($order);
|
| 271 |
+
|
| 272 |
+
$orders[] = $orderEntity;
|
| 273 |
+
}
|
| 274 |
+
|
| 275 |
+
return $this->_orders = $orders;
|
| 276 |
+
}
|
| 277 |
+
|
| 278 |
+
/**
|
| 279 |
+
* Get all customer wishlist items
|
| 280 |
+
*
|
| 281 |
+
* @return array
|
| 282 |
+
*/
|
| 283 |
+
public function getWishlistItems()
|
| 284 |
+
{
|
| 285 |
+
if (!is_null($this->_wishlistItems)) {
|
| 286 |
+
return $this->_wishlistItems;
|
| 287 |
+
}
|
| 288 |
+
|
| 289 |
+
$wishlistItems = array();
|
| 290 |
+
|
| 291 |
+
$wishlist = Mage::getModel('wishlist/wishlist')->loadByCustomer($this->getId());
|
| 292 |
+
|
| 293 |
+
$wishlistItemCollection = Mage::getModel('wishlist/item')->getCollection()->addFieldToFilter('wishlist_id', $wishlist->getId());
|
| 294 |
+
|
| 295 |
+
foreach ($wishlistItemCollection as $wishlistItem) {
|
| 296 |
+
$wishlistItemEntity = Mage::getModel('marketingsoftware/copernica_entity_wishlist_item');
|
| 297 |
+
$wishlistItemEntity->setWishlistItem($wishlistItem);
|
| 298 |
+
|
| 299 |
+
$wishlistItems[] = $wishlistItemEntity;
|
| 300 |
+
}
|
| 301 |
+
|
| 302 |
+
return $this->_wishlistItems = $wishlistItems;
|
| 303 |
+
}
|
| 304 |
+
|
| 305 |
+
/**
|
| 306 |
+
* Fetch group
|
| 307 |
+
*
|
| 308 |
+
* @return string
|
| 309 |
+
*/
|
| 310 |
+
public function fetchGroup()
|
| 311 |
+
{
|
| 312 |
+
return Mage::getModel('customer/group')->load($this->_customer->getGroupId())->getCode();
|
| 313 |
+
}
|
| 314 |
+
|
| 315 |
+
/**
|
| 316 |
+
* Get REST customer
|
| 317 |
+
*
|
| 318 |
+
* @return Copernica_MarketingSoftware_Model_Rest_Customer
|
| 319 |
+
*/
|
| 320 |
+
public function getRestCustomer()
|
| 321 |
+
{
|
| 322 |
+
$restCustomer = Mage::getModel('marketingsoftware/rest_customer');
|
| 323 |
+
$restCustomer->setCustomerEntity($this);
|
| 324 |
+
|
| 325 |
+
return $restCustomer;
|
| 326 |
+
}
|
| 327 |
+
|
| 328 |
+
/**
|
| 329 |
+
* Get profile Id
|
| 330 |
+
*
|
| 331 |
+
* @param string $storeviewText
|
| 332 |
+
* @param int $id
|
| 333 |
+
* @return string|false
|
| 334 |
+
*/
|
| 335 |
+
public function getProfileId()
|
| 336 |
+
{
|
| 337 |
+
if (!is_null($this->_profileId)) {
|
| 338 |
+
return $this->_profileId;
|
| 339 |
+
}
|
| 340 |
+
|
| 341 |
+
$profileId = Mage::helper('marketingsoftware/api')->getProfileId(array(
|
| 342 |
+
'id' => $this->getCustomerId(),
|
| 343 |
+
'email' => $this->getEmail(),
|
| 344 |
+
'storeView' => strval($this->getStoreView()),
|
| 345 |
+
));
|
| 346 |
+
|
| 347 |
+
if ($profileId) {
|
| 348 |
+
return $this->_profileId = $profileId;
|
| 349 |
+
}
|
| 350 |
+
|
| 351 |
+
return false;
|
| 352 |
+
}
|
| 353 |
+
|
| 354 |
+
/**
|
| 355 |
+
* Set customer entity
|
| 356 |
+
*
|
| 357 |
+
* @param int $customerId
|
| 358 |
+
*/
|
| 359 |
+
public function setCustomer($customerId)
|
| 360 |
+
{
|
| 361 |
+
$customer = Mage::getModel('customer/customer')->load($customerId);
|
| 362 |
+
|
| 363 |
+
if (!$customer->isObjectNew()) {
|
| 364 |
+
$this->_customer = $customer;
|
| 365 |
+
} else {
|
| 366 |
+
throw Mage::exception('Copernica_MarketingSoftware', 'Customer does not exists', Copernica_MarketingSoftware_Exception::CUSTOMER_NOT_EXISTS);
|
| 367 |
+
}
|
| 368 |
+
}
|
| 369 |
+
|
| 370 |
+
/**
|
| 371 |
+
* Set the storeView
|
| 372 |
+
*
|
| 373 |
+
* @param Copernica_MarketingSoftware_Model_Abstraction_Storeview $store
|
| 374 |
+
*/
|
| 375 |
+
public function setStore($store)
|
| 376 |
+
{
|
| 377 |
+
if (!$this->_store || $this->_store->id() != $store->id()) {
|
| 378 |
+
unset($this->_data['storeView']);
|
| 379 |
+
unset($this->_data['customerId']);
|
| 380 |
+
$this->_profileId = null;
|
| 381 |
+
$this->_store = $store;
|
| 382 |
+
}
|
| 383 |
+
}
|
| 384 |
+
}
|
app/code/community/Copernica/MarketingSoftware/Model/Copernica/Entity/Order.php
CHANGED
|
@@ -1,364 +1,364 @@
|
|
| 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 |
-
* Bridge class between copernica and magento
|
| 29 |
-
*/
|
| 30 |
-
class Copernica_MarketingSoftware_Model_Copernica_Entity_Order extends Copernica_MarketingSoftware_Model_Copernica_Entity
|
| 31 |
-
{
|
| 32 |
-
/**
|
| 33 |
-
* Cached order instance
|
| 34 |
-
*
|
| 35 |
-
* @var Mage_Sales_Model_Order
|
| 36 |
-
*/
|
| 37 |
-
protected $_order = null;
|
| 38 |
-
|
| 39 |
-
/**
|
| 40 |
-
* Cache for order items
|
| 41 |
-
*
|
| 42 |
-
* @var array
|
| 43 |
-
*/
|
| 44 |
-
protected $_items = null;
|
| 45 |
-
|
| 46 |
-
/**
|
| 47 |
-
* Fetch order Id
|
| 48 |
-
*
|
| 49 |
-
* @return string
|
| 50 |
-
*/
|
| 51 |
-
public function fetchId()
|
| 52 |
-
{
|
| 53 |
-
return $this->_order->getId();
|
| 54 |
-
}
|
| 55 |
-
|
| 56 |
-
/**
|
| 57 |
-
* Fetch increment Id
|
| 58 |
-
*
|
| 59 |
-
* @return string
|
| 60 |
-
*/
|
| 61 |
-
public function fetchIncrementId()
|
| 62 |
-
{
|
| 63 |
-
return $this->_order->getIncrementId();
|
| 64 |
-
}
|
| 65 |
-
|
| 66 |
-
/**
|
| 67 |
-
* Fetch quote Id
|
| 68 |
-
*
|
| 69 |
-
* @return string
|
| 70 |
-
*/
|
| 71 |
-
public function fetchQuoteId()
|
| 72 |
-
{
|
| 73 |
-
return $this->_order->getQuoteId();
|
| 74 |
-
}
|
| 75 |
-
|
| 76 |
-
/**
|
| 77 |
-
* Fetch status
|
| 78 |
-
*
|
| 79 |
-
* @return string
|
| 80 |
-
*/
|
| 81 |
-
public function fetchStatus()
|
| 82 |
-
{
|
| 83 |
-
return $this->_order->getStatus();
|
| 84 |
-
}
|
| 85 |
-
|
| 86 |
-
/**
|
| 87 |
-
* Fetch state
|
| 88 |
-
*
|
| 89 |
-
* @return string
|
| 90 |
-
*/
|
| 91 |
-
public function fetchState()
|
| 92 |
-
{
|
| 93 |
-
return $this->_order->getState();
|
| 94 |
-
}
|
| 95 |
-
|
| 96 |
-
/**
|
| 97 |
-
* Fetch quantity
|
| 98 |
-
*
|
| 99 |
-
* @return string
|
| 100 |
-
*/
|
| 101 |
-
public function fetchQuantity()
|
| 102 |
-
{
|
| 103 |
-
return $this->_order->getTotalQtyOrdered();
|
| 104 |
-
}
|
| 105 |
-
|
| 106 |
-
/**
|
| 107 |
-
* Fetch currency
|
| 108 |
-
*
|
| 109 |
-
* @return string
|
| 110 |
-
*/
|
| 111 |
-
public function fetchCurrency()
|
| 112 |
-
{
|
| 113 |
-
return $this->getPrice()->currency();
|
| 114 |
-
}
|
| 115 |
-
|
| 116 |
-
/**
|
| 117 |
-
* Fetch prive
|
| 118 |
-
*
|
| 119 |
-
* @return string
|
| 120 |
-
*/
|
| 121 |
-
public function fetchPrice()
|
| 122 |
-
{
|
| 123 |
-
// @todo really? new class to parse a price ?
|
| 124 |
-
return Mage::getModel('marketingsoftware/abstraction_price')->setOriginal($this->_order);
|
| 125 |
-
}
|
| 126 |
-
|
| 127 |
-
/**
|
| 128 |
-
* Fetch shipping cost
|
| 129 |
-
*
|
| 130 |
-
* @return string
|
| 131 |
-
*/
|
| 132 |
-
public function fetchShipping()
|
| 133 |
-
{
|
| 134 |
-
return $this->getPrice()->shipping();
|
| 135 |
-
}
|
| 136 |
-
|
| 137 |
-
/**
|
| 138 |
-
* Fetch total prive
|
| 139 |
-
*
|
| 140 |
-
* @return string
|
| 141 |
-
*/
|
| 142 |
-
public function fetchTotal()
|
| 143 |
-
{
|
| 144 |
-
return $this->getPrice()->total();
|
| 145 |
-
}
|
| 146 |
-
|
| 147 |
-
/**
|
| 148 |
-
* Fetch store view
|
| 149 |
-
*
|
| 150 |
-
* @return string
|
| 151 |
-
*/
|
| 152 |
-
public function fetchStoreView()
|
| 153 |
-
{
|
| 154 |
-
return Mage::getModel('marketingsoftware/abstraction_storeview')->setOriginal($this->_order->getStore());
|
| 155 |
-
}
|
| 156 |
-
|
| 157 |
-
/**
|
| 158 |
-
* Fetch weight
|
| 159 |
-
*
|
| 160 |
-
* @return string
|
| 161 |
-
*/
|
| 162 |
-
public function fetchWeight()
|
| 163 |
-
{
|
| 164 |
-
return $this->_order->getWeight();
|
| 165 |
-
}
|
| 166 |
-
|
| 167 |
-
/**
|
| 168 |
-
* Fetch timestamp
|
| 169 |
-
*
|
| 170 |
-
* @return string
|
| 171 |
-
*/
|
| 172 |
-
public function fetchTimestamp()
|
| 173 |
-
{
|
| 174 |
-
return $this->_order->getUpdatedAt();
|
| 175 |
-
}
|
| 176 |
-
|
| 177 |
-
/**
|
| 178 |
-
* Fetch shipping description
|
| 179 |
-
*
|
| 180 |
-
* @return string
|
| 181 |
-
*/
|
| 182 |
-
public function fetchShippingDescription()
|
| 183 |
-
{
|
| 184 |
-
return $this->_order->getShippingDescription();
|
| 185 |
-
}
|
| 186 |
-
|
| 187 |
-
/**
|
| 188 |
-
* Fetch customer IP
|
| 189 |
-
*
|
| 190 |
-
* @return string
|
| 191 |
-
*/
|
| 192 |
-
public function fetchRemoteIp()
|
| 193 |
-
{
|
| 194 |
-
return $this->_order->getRemoteIp();
|
| 195 |
-
}
|
| 196 |
-
|
| 197 |
-
/**
|
| 198 |
-
* Fetch payment description
|
| 199 |
-
*
|
| 200 |
-
* @return string
|
| 201 |
-
*/
|
| 202 |
-
public function fetchPaymentDescription()
|
| 203 |
-
{
|
| 204 |
-
if ($payment = $this->_order->getPayment()) {
|
| 205 |
-
try {
|
| 206 |
-
if ($payment->getMethod() == 'klarna_partpayment') return 'Klarna';
|
| 207 |
-
else return $payment->getMethodInstance()->getTitle();
|
| 208 |
-
} catch (Mage_Core_Exception $exception) { }
|
| 209 |
-
}
|
| 210 |
-
|
| 211 |
-
return '';
|
| 212 |
-
}
|
| 213 |
-
|
| 214 |
-
/**
|
| 215 |
-
* Get shipping address. When no valid address can be found this method will
|
| 216 |
-
* return null value.
|
| 217 |
-
*
|
| 218 |
-
* @return Copernica_MarketingSoftware_Model_Copernica_Entity_Address|null
|
| 219 |
-
*/
|
| 220 |
-
public function fetchShippingAddress()
|
| 221 |
-
{
|
| 222 |
-
$address = $this->_order->getShippingAddress();
|
| 223 |
-
|
| 224 |
-
if (is_object($address)) {
|
| 225 |
-
$addressEntity = Mage::getModel('marketingsoftware/copernica_entity_address');
|
| 226 |
-
$addressEntity->setAddress($address);
|
| 227 |
-
|
| 228 |
-
return $addressEntity;
|
| 229 |
-
}
|
| 230 |
-
|
| 231 |
-
// $addresses = $this->_order->getAddressesCollection();
|
| 232 |
-
|
| 233 |
-
return null;
|
| 234 |
-
}
|
| 235 |
-
|
| 236 |
-
/**
|
| 237 |
-
* Get billing address. When no valid address can be found this method will
|
| 238 |
-
* return null value.
|
| 239 |
-
*
|
| 240 |
-
* @return Copernica_MarketingSoftware_Model_Copernica_Entity_Address
|
| 241 |
-
*/
|
| 242 |
-
public function fetchBillingAddress()
|
| 243 |
-
{
|
| 244 |
-
$address = $this->_order->getBillingAddress();
|
| 245 |
-
|
| 246 |
-
if (is_object($address)) {
|
| 247 |
-
$addressEntity = Mage::getModel('marketingsoftware/copernica_entity_address');
|
| 248 |
-
$addressEntity->setAddress($address);
|
| 249 |
-
|
| 250 |
-
return $addressEntity;
|
| 251 |
-
}
|
| 252 |
-
|
| 253 |
-
// foreach($this->_order->getAddressCollection() as $magentoAddress) {
|
| 254 |
-
// $address = new Copernica_MarketingSoftware_Model_Copernica_Entity_Address($magentoAddress);
|
| 255 |
-
// }
|
| 256 |
-
|
| 257 |
-
return null;
|
| 258 |
-
}
|
| 259 |
-
|
| 260 |
-
/**
|
| 261 |
-
* Fetch shipping address id
|
| 262 |
-
*
|
| 263 |
-
* @return string
|
| 264 |
-
*/
|
| 265 |
-
public function fetchShippingAddressId()
|
| 266 |
-
{
|
| 267 |
-
if (is_object($address = $this->getShippingAddress())) {
|
| 268 |
-
return $address->getId();
|
| 269 |
-
}
|
| 270 |
-
|
| 271 |
-
return null;
|
| 272 |
-
}
|
| 273 |
-
|
| 274 |
-
/**
|
| 275 |
-
* Fetch billing address Id
|
| 276 |
-
*
|
| 277 |
-
* @return string
|
| 278 |
-
*/
|
| 279 |
-
public function fetchBillingAddressId()
|
| 280 |
-
{
|
| 281 |
-
if (is_object($address = $this->getBillingAddress())) {
|
| 282 |
-
return $address->getId();
|
| 283 |
-
}
|
| 284 |
-
|
| 285 |
-
return null;
|
| 286 |
-
}
|
| 287 |
-
|
| 288 |
-
/**
|
| 289 |
-
* Return array of all orders items
|
| 290 |
-
*
|
| 291 |
-
* @return array
|
| 292 |
-
*/
|
| 293 |
-
public function getItems()
|
| 294 |
-
{
|
| 295 |
-
if (!is_null($this->_items)) {
|
| 296 |
-
return $this->_items;
|
| 297 |
-
}
|
| 298 |
-
|
| 299 |
-
$data = array();
|
| 300 |
-
|
| 301 |
-
foreach ($this->_order->getAllVisibleItems() as $orderItem) {
|
| 302 |
-
$orderItemEntity = Mage::getModel('marketingsoftware/copernica_entity_order_item');
|
| 303 |
-
$orderItemEntity->setOrderItem($orderItem);
|
| 304 |
-
|
| 305 |
-
$data[] = $orderItemEntity;
|
| 306 |
-
}
|
| 307 |
-
|
| 308 |
-
return $this->_items = $data;
|
| 309 |
-
}
|
| 310 |
-
|
| 311 |
-
/**
|
| 312 |
-
* Return array of all addresses
|
| 313 |
-
*
|
| 314 |
-
* @return array
|
| 315 |
-
*/
|
| 316 |
-
public function getAddresses()
|
| 317 |
-
{
|
| 318 |
-
$addresses = Mage::getModel('sales/order_address')->getCollection()->addFieldToFilter('order_id', $this->_order->getId());
|
| 319 |
-
|
| 320 |
-
$convertedAddresses = array();
|
| 321 |
-
|
| 322 |
-
foreach ($addresses as $address) {
|
| 323 |
-
$addressEntity = Mage::getModel('marketingsoftware/copernica_entity_address');
|
| 324 |
-
$addressEntity->setAddress($address);
|
| 325 |
-
|
| 326 |
-
$convertedAddresses[] = $addressEntity;
|
| 327 |
-
}
|
| 328 |
-
|
| 329 |
-
return $convertedAddresses;
|
| 330 |
-
}
|
| 331 |
-
|
| 332 |
-
/**
|
| 333 |
-
* Return coupon code that was used when finalizing this order.
|
| 334 |
-
*
|
| 335 |
-
* @return string
|
| 336 |
-
*/
|
| 337 |
-
public function fetchCouponCode()
|
| 338 |
-
{
|
| 339 |
-
return $this->_order->getCouponCode();
|
| 340 |
-
}
|
| 341 |
-
|
| 342 |
-
/**
|
| 343 |
-
* Get REST order
|
| 344 |
-
*
|
| 345 |
-
* @return Copernica_MarketingSoftware_Model_Rest_Order
|
| 346 |
-
*/
|
| 347 |
-
public function getRestOrder()
|
| 348 |
-
{
|
| 349 |
-
$restOrder = Mage::getModel('marketingsoftware/rest_order');
|
| 350 |
-
$restOrder->setOrderEntity($this);
|
| 351 |
-
|
| 352 |
-
return $restOrder;
|
| 353 |
-
}
|
| 354 |
-
|
| 355 |
-
/**
|
| 356 |
-
* Set copernica order
|
| 357 |
-
*
|
| 358 |
-
* @param Mage_Sales_Model_Order $order
|
| 359 |
-
*/
|
| 360 |
-
public function setOrder($order)
|
| 361 |
-
{
|
| 362 |
-
$this->_order = $order;
|
| 363 |
-
}
|
| 364 |
}
|
| 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 |
+
* Bridge class between copernica and magento
|
| 29 |
+
*/
|
| 30 |
+
class Copernica_MarketingSoftware_Model_Copernica_Entity_Order extends Copernica_MarketingSoftware_Model_Copernica_Entity
|
| 31 |
+
{
|
| 32 |
+
/**
|
| 33 |
+
* Cached order instance
|
| 34 |
+
*
|
| 35 |
+
* @var Mage_Sales_Model_Order
|
| 36 |
+
*/
|
| 37 |
+
protected $_order = null;
|
| 38 |
+
|
| 39 |
+
/**
|
| 40 |
+
* Cache for order items
|
| 41 |
+
*
|
| 42 |
+
* @var array
|
| 43 |
+
*/
|
| 44 |
+
protected $_items = null;
|
| 45 |
+
|
| 46 |
+
/**
|
| 47 |
+
* Fetch order Id
|
| 48 |
+
*
|
| 49 |
+
* @return string
|
| 50 |
+
*/
|
| 51 |
+
public function fetchId()
|
| 52 |
+
{
|
| 53 |
+
return $this->_order->getId();
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
/**
|
| 57 |
+
* Fetch increment Id
|
| 58 |
+
*
|
| 59 |
+
* @return string
|
| 60 |
+
*/
|
| 61 |
+
public function fetchIncrementId()
|
| 62 |
+
{
|
| 63 |
+
return $this->_order->getIncrementId();
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
/**
|
| 67 |
+
* Fetch quote Id
|
| 68 |
+
*
|
| 69 |
+
* @return string
|
| 70 |
+
*/
|
| 71 |
+
public function fetchQuoteId()
|
| 72 |
+
{
|
| 73 |
+
return $this->_order->getQuoteId();
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
/**
|
| 77 |
+
* Fetch status
|
| 78 |
+
*
|
| 79 |
+
* @return string
|
| 80 |
+
*/
|
| 81 |
+
public function fetchStatus()
|
| 82 |
+
{
|
| 83 |
+
return $this->_order->getStatus();
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
/**
|
| 87 |
+
* Fetch state
|
| 88 |
+
*
|
| 89 |
+
* @return string
|
| 90 |
+
*/
|
| 91 |
+
public function fetchState()
|
| 92 |
+
{
|
| 93 |
+
return $this->_order->getState();
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
/**
|
| 97 |
+
* Fetch quantity
|
| 98 |
+
*
|
| 99 |
+
* @return string
|
| 100 |
+
*/
|
| 101 |
+
public function fetchQuantity()
|
| 102 |
+
{
|
| 103 |
+
return $this->_order->getTotalQtyOrdered();
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
/**
|
| 107 |
+
* Fetch currency
|
| 108 |
+
*
|
| 109 |
+
* @return string
|
| 110 |
+
*/
|
| 111 |
+
public function fetchCurrency()
|
| 112 |
+
{
|
| 113 |
+
return $this->getPrice()->currency();
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
/**
|
| 117 |
+
* Fetch prive
|
| 118 |
+
*
|
| 119 |
+
* @return string
|
| 120 |
+
*/
|
| 121 |
+
public function fetchPrice()
|
| 122 |
+
{
|
| 123 |
+
// @todo really? new class to parse a price ?
|
| 124 |
+
return Mage::getModel('marketingsoftware/abstraction_price')->setOriginal($this->_order);
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
/**
|
| 128 |
+
* Fetch shipping cost
|
| 129 |
+
*
|
| 130 |
+
* @return string
|
| 131 |
+
*/
|
| 132 |
+
public function fetchShipping()
|
| 133 |
+
{
|
| 134 |
+
return $this->getPrice()->shipping();
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
/**
|
| 138 |
+
* Fetch total prive
|
| 139 |
+
*
|
| 140 |
+
* @return string
|
| 141 |
+
*/
|
| 142 |
+
public function fetchTotal()
|
| 143 |
+
{
|
| 144 |
+
return $this->getPrice()->total();
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
/**
|
| 148 |
+
* Fetch store view
|
| 149 |
+
*
|
| 150 |
+
* @return string
|
| 151 |
+
*/
|
| 152 |
+
public function fetchStoreView()
|
| 153 |
+
{
|
| 154 |
+
return Mage::getModel('marketingsoftware/abstraction_storeview')->setOriginal($this->_order->getStore());
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
/**
|
| 158 |
+
* Fetch weight
|
| 159 |
+
*
|
| 160 |
+
* @return string
|
| 161 |
+
*/
|
| 162 |
+
public function fetchWeight()
|
| 163 |
+
{
|
| 164 |
+
return $this->_order->getWeight();
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
/**
|
| 168 |
+
* Fetch timestamp
|
| 169 |
+
*
|
| 170 |
+
* @return string
|
| 171 |
+
*/
|
| 172 |
+
public function fetchTimestamp()
|
| 173 |
+
{
|
| 174 |
+
return $this->_order->getUpdatedAt();
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
/**
|
| 178 |
+
* Fetch shipping description
|
| 179 |
+
*
|
| 180 |
+
* @return string
|
| 181 |
+
*/
|
| 182 |
+
public function fetchShippingDescription()
|
| 183 |
+
{
|
| 184 |
+
return $this->_order->getShippingDescription();
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
/**
|
| 188 |
+
* Fetch customer IP
|
| 189 |
+
*
|
| 190 |
+
* @return string
|
| 191 |
+
*/
|
| 192 |
+
public function fetchRemoteIp()
|
| 193 |
+
{
|
| 194 |
+
return $this->_order->getRemoteIp();
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
/**
|
| 198 |
+
* Fetch payment description
|
| 199 |
+
*
|
| 200 |
+
* @return string
|
| 201 |
+
*/
|
| 202 |
+
public function fetchPaymentDescription()
|
| 203 |
+
{
|
| 204 |
+
if ($payment = $this->_order->getPayment()) {
|
| 205 |
+
try {
|
| 206 |
+
if ($payment->getMethod() == 'klarna_partpayment') return 'Klarna';
|
| 207 |
+
else return $payment->getMethodInstance()->getTitle();
|
| 208 |
+
} catch (Mage_Core_Exception $exception) { }
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
return '';
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
/**
|
| 215 |
+
* Get shipping address. When no valid address can be found this method will
|
| 216 |
+
* return null value.
|
| 217 |
+
*
|
| 218 |
+
* @return Copernica_MarketingSoftware_Model_Copernica_Entity_Address|null
|
| 219 |
+
*/
|
| 220 |
+
public function fetchShippingAddress()
|
| 221 |
+
{
|
| 222 |
+
$address = $this->_order->getShippingAddress();
|
| 223 |
+
|
| 224 |
+
if (is_object($address)) {
|
| 225 |
+
$addressEntity = Mage::getModel('marketingsoftware/copernica_entity_address');
|
| 226 |
+
$addressEntity->setAddress($address);
|
| 227 |
+
|
| 228 |
+
return $addressEntity;
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
// $addresses = $this->_order->getAddressesCollection();
|
| 232 |
+
|
| 233 |
+
return null;
|
| 234 |
+
}
|
| 235 |
+
|
| 236 |
+
/**
|
| 237 |
+
* Get billing address. When no valid address can be found this method will
|
| 238 |
+
* return null value.
|
| 239 |
+
*
|
| 240 |
+
* @return Copernica_MarketingSoftware_Model_Copernica_Entity_Address
|
| 241 |
+
*/
|
| 242 |
+
public function fetchBillingAddress()
|
| 243 |
+
{
|
| 244 |
+
$address = $this->_order->getBillingAddress();
|
| 245 |
+
|
| 246 |
+
if (is_object($address)) {
|
| 247 |
+
$addressEntity = Mage::getModel('marketingsoftware/copernica_entity_address');
|
| 248 |
+
$addressEntity->setAddress($address);
|
| 249 |
+
|
| 250 |
+
return $addressEntity;
|
| 251 |
+
}
|
| 252 |
+
|
| 253 |
+
// foreach($this->_order->getAddressCollection() as $magentoAddress) {
|
| 254 |
+
// $address = new Copernica_MarketingSoftware_Model_Copernica_Entity_Address($magentoAddress);
|
| 255 |
+
// }
|
| 256 |
+
|
| 257 |
+
return null;
|
| 258 |
+
}
|
| 259 |
+
|
| 260 |
+
/**
|
| 261 |
+
* Fetch shipping address id
|
| 262 |
+
*
|
| 263 |
+
* @return string
|
| 264 |
+
*/
|
| 265 |
+
public function fetchShippingAddressId()
|
| 266 |
+
{
|
| 267 |
+
if (is_object($address = $this->getShippingAddress())) {
|
| 268 |
+
return $address->getId();
|
| 269 |
+
}
|
| 270 |
+
|
| 271 |
+
return null;
|
| 272 |
+
}
|
| 273 |
+
|
| 274 |
+
/**
|
| 275 |
+
* Fetch billing address Id
|
| 276 |
+
*
|
| 277 |
+
* @return string
|
| 278 |
+
*/
|
| 279 |
+
public function fetchBillingAddressId()
|
| 280 |
+
{
|
| 281 |
+
if (is_object($address = $this->getBillingAddress())) {
|
| 282 |
+
return $address->getId();
|
| 283 |
+
}
|
| 284 |
+
|
| 285 |
+
return null;
|
| 286 |
+
}
|
| 287 |
+
|
| 288 |
+
/**
|
| 289 |
+
* Return array of all orders items
|
| 290 |
+
*
|
| 291 |
+
* @return array
|
| 292 |
+
*/
|
| 293 |
+
public function getItems()
|
| 294 |
+
{
|
| 295 |
+
if (!is_null($this->_items)) {
|
| 296 |
+
return $this->_items;
|
| 297 |
+
}
|
| 298 |
+
|
| 299 |
+
$data = array();
|
| 300 |
+
|
| 301 |
+
foreach ($this->_order->getAllVisibleItems() as $orderItem) {
|
| 302 |
+
$orderItemEntity = Mage::getModel('marketingsoftware/copernica_entity_order_item');
|
| 303 |
+
$orderItemEntity->setOrderItem($orderItem);
|
| 304 |
+
|
| 305 |
+
$data[] = $orderItemEntity;
|
| 306 |
+
}
|
| 307 |
+
|
| 308 |
+
return $this->_items = $data;
|
| 309 |
+
}
|
| 310 |
+
|
| 311 |
+
/**
|
| 312 |
+
* Return array of all addresses
|
| 313 |
+
*
|
| 314 |
+
* @return array
|
| 315 |
+
*/
|
| 316 |
+
public function getAddresses()
|
| 317 |
+
{
|
| 318 |
+
$addresses = Mage::getModel('sales/order_address')->getCollection()->addFieldToFilter('order_id', $this->_order->getId());
|
| 319 |
+
|
| 320 |
+
$convertedAddresses = array();
|
| 321 |
+
|
| 322 |
+
foreach ($addresses as $address) {
|
| 323 |
+
$addressEntity = Mage::getModel('marketingsoftware/copernica_entity_address');
|
| 324 |
+
$addressEntity->setAddress($address);
|
| 325 |
+
|
| 326 |
+
$convertedAddresses[] = $addressEntity;
|
| 327 |
+
}
|
| 328 |
+
|
| 329 |
+
return $convertedAddresses;
|
| 330 |
+
}
|
| 331 |
+
|
| 332 |
+
/**
|
| 333 |
+
* Return coupon code that was used when finalizing this order.
|
| 334 |
+
*
|
| 335 |
+
* @return string
|
| 336 |
+
*/
|
| 337 |
+
public function fetchCouponCode()
|
| 338 |
+
{
|
| 339 |
+
return $this->_order->getCouponCode();
|
| 340 |
+
}
|
| 341 |
+
|
| 342 |
+
/**
|
| 343 |
+
* Get REST order
|
| 344 |
+
*
|
| 345 |
+
* @return Copernica_MarketingSoftware_Model_Rest_Order
|
| 346 |
+
*/
|
| 347 |
+
public function getRestOrder()
|
| 348 |
+
{
|
| 349 |
+
$restOrder = Mage::getModel('marketingsoftware/rest_order');
|
| 350 |
+
$restOrder->setOrderEntity($this);
|
| 351 |
+
|
| 352 |
+
return $restOrder;
|
| 353 |
+
}
|
| 354 |
+
|
| 355 |
+
/**
|
| 356 |
+
* Set copernica order
|
| 357 |
+
*
|
| 358 |
+
* @param Mage_Sales_Model_Order $order
|
| 359 |
+
*/
|
| 360 |
+
public function setOrder($order)
|
| 361 |
+
{
|
| 362 |
+
$this->_order = $order;
|
| 363 |
+
}
|
| 364 |
}
|
app/code/community/Copernica/MarketingSoftware/Model/Copernica/Entity/Order/Item.php
CHANGED
|
@@ -1,195 +1,195 @@
|
|
| 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 |
-
* Bridge class between magento item and copernica subprofile
|
| 29 |
-
*/
|
| 30 |
-
class Copernica_MarketingSoftware_Model_Copernica_Entity_Order_Item extends Copernica_MarketingSoftware_Model_Copernica_Entity_Product
|
| 31 |
-
{
|
| 32 |
-
/**
|
| 33 |
-
* Cached item
|
| 34 |
-
*
|
| 35 |
-
* @var Mage_Sales_Model_Order_Item|Mage_Sales_Model_Quote_Item
|
| 36 |
-
*/
|
| 37 |
-
protected $_orderItem = null;
|
| 38 |
-
|
| 39 |
-
/**
|
| 40 |
-
* Get item Id
|
| 41 |
-
*
|
| 42 |
-
* @return string
|
| 43 |
-
*/
|
| 44 |
-
public function fetchId()
|
| 45 |
-
{
|
| 46 |
-
return $this->_orderItem->getId();
|
| 47 |
-
}
|
| 48 |
-
|
| 49 |
-
/**
|
| 50 |
-
* Fetch quantity
|
| 51 |
-
*
|
| 52 |
-
* @return string
|
| 53 |
-
*/
|
| 54 |
-
public function fetchQuantity()
|
| 55 |
-
{
|
| 56 |
-
if ($this->_orderItem instanceOf Mage_Sales_Model_Quote_Item) {
|
| 57 |
-
return $this->_orderItem->getQty();
|
| 58 |
-
}
|
| 59 |
-
|
| 60 |
-
return $this->_orderItem->getQtyOrdered();
|
| 61 |
-
}
|
| 62 |
-
|
| 63 |
-
/**
|
| 64 |
-
* Fetch price
|
| 65 |
-
*
|
| 66 |
-
* @return Copernia_MarketingSoftware_Model_Abstraction_Price
|
| 67 |
-
*/
|
| 68 |
-
public function fetchFullPrice()
|
| 69 |
-
{
|
| 70 |
-
return Mage::getModel('marketingsoftware/abstraction_price')->setOriginal($this->_orderItem);
|
| 71 |
-
}
|
| 72 |
-
|
| 73 |
-
/**
|
| 74 |
-
* Fetch total
|
| 75 |
-
*
|
| 76 |
-
* @return string
|
| 77 |
-
*/
|
| 78 |
-
public function fetchTotalPrice()
|
| 79 |
-
{
|
| 80 |
-
return $this->getFullPrice()->total();
|
| 81 |
-
}
|
| 82 |
-
|
| 83 |
-
/**
|
| 84 |
-
* Fetch price
|
| 85 |
-
*
|
| 86 |
-
* @return string
|
| 87 |
-
*/
|
| 88 |
-
public function fetchPrice()
|
| 89 |
-
{
|
| 90 |
-
return $this->getFullPrice()->itemPrice();
|
| 91 |
-
}
|
| 92 |
-
|
| 93 |
-
/**
|
| 94 |
-
* Fetch timestamp
|
| 95 |
-
*
|
| 96 |
-
* @return string
|
| 97 |
-
*/
|
| 98 |
-
public function fetchTimestamp()
|
| 99 |
-
{
|
| 100 |
-
return $this->_orderItem->getUpdatedAt();
|
| 101 |
-
}
|
| 102 |
-
|
| 103 |
-
/**
|
| 104 |
-
* Fetch store view
|
| 105 |
-
*
|
| 106 |
-
* @return string
|
| 107 |
-
*/
|
| 108 |
-
public function fetchStoreView()
|
| 109 |
-
{
|
| 110 |
-
$store = Mage::getModel('core/store')->load($this->getStoreId());
|
| 111 |
-
|
| 112 |
-
return Mage::getModel('marketingsoftware/abstraction_storeview')->setOriginal($store);
|
| 113 |
-
}
|
| 114 |
-
|
| 115 |
-
/**
|
| 116 |
-
* Get store Id
|
| 117 |
-
*
|
| 118 |
-
* @return int
|
| 119 |
-
*/
|
| 120 |
-
public function getStoreId()
|
| 121 |
-
{
|
| 122 |
-
if ($this->_orderItem instanceof Mage_Sales_Model_Quote_Item) {
|
| 123 |
-
if ($this->_orderItem->getQuote()) {
|
| 124 |
-
return $this->_orderItem->getQuote()->getStoreId();
|
| 125 |
-
} else {
|
| 126 |
-
return Mage::getModel('sales/quote')->load($this->_orderItem->getQuoteId())->getStoreId();
|
| 127 |
-
}
|
| 128 |
-
} elseif ($this->_orderItem instanceof Mage_Sales_Model_Order_Item) {
|
| 129 |
-
return $this->_orderItem->getOrder()->getStoreId();
|
| 130 |
-
}
|
| 131 |
-
|
| 132 |
-
return 0;
|
| 133 |
-
}
|
| 134 |
-
|
| 135 |
-
/**
|
| 136 |
-
* Fetch sales rules
|
| 137 |
-
*
|
| 138 |
-
* @return string
|
| 139 |
-
*/
|
| 140 |
-
public function fetchSalesRules()
|
| 141 |
-
{
|
| 142 |
-
return $this->_orderItem->getAppliedRuleIds();
|
| 143 |
-
}
|
| 144 |
-
|
| 145 |
-
/**
|
| 146 |
-
* Options can be nested so this function will allow us to parse them in recursive manner.
|
| 147 |
-
*
|
| 148 |
-
* @param mixed $values
|
| 149 |
-
* @param string $prefix
|
| 150 |
-
* @return string
|
| 151 |
-
*/
|
| 152 |
-
protected function _stringifyOptions($values, $prefix = '')
|
| 153 |
-
{
|
| 154 |
-
$result = '';
|
| 155 |
-
|
| 156 |
-
foreach ($values as $value) {
|
| 157 |
-
if (is_array($value['value'])) {
|
| 158 |
-
if (isset($value['value'][0]) && count($value['value']) == 1) {
|
| 159 |
-
$value['value'] = $value['value'][0];
|
| 160 |
-
}
|
| 161 |
-
|
| 162 |
-
$result .= $prefix.$value['label'].":\n".$this->_stringifyOptions($value['value'], $prefix.' ');
|
| 163 |
-
} else {
|
| 164 |
-
$result .= $prefix.$value['label'].":".$value['value']."\n";
|
| 165 |
-
}
|
| 166 |
-
}
|
| 167 |
-
|
| 168 |
-
return $result;
|
| 169 |
-
}
|
| 170 |
-
|
| 171 |
-
/**
|
| 172 |
-
* Get REST order item entity
|
| 173 |
-
*
|
| 174 |
-
* @return Copernica_MarketingSoftware_Model_Rest_Order_Item
|
| 175 |
-
*/
|
| 176 |
-
public function getRestOrderItem()
|
| 177 |
-
{
|
| 178 |
-
$restOrderItem = Mage::getModel('marketingsoftware/rest_order_item');
|
| 179 |
-
$restOrderItem->setOrderItemEntity($this);
|
| 180 |
-
|
| 181 |
-
return $restOrderItem;
|
| 182 |
-
}
|
| 183 |
-
|
| 184 |
-
/**
|
| 185 |
-
* Set copernica order item
|
| 186 |
-
*
|
| 187 |
-
* @param Mage_Sales_Model_Order_Item|Mage_Sales_Model_Quote_Item $orderItem
|
| 188 |
-
*/
|
| 189 |
-
public function setOrderItem($orderItem)
|
| 190 |
-
{
|
| 191 |
-
$this->_orderItem = $orderItem;
|
| 192 |
-
|
| 193 |
-
$this->setProduct($orderItem->getProductId());
|
| 194 |
-
}
|
| 195 |
}
|
| 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 |
+
* Bridge class between magento item and copernica subprofile
|
| 29 |
+
*/
|
| 30 |
+
class Copernica_MarketingSoftware_Model_Copernica_Entity_Order_Item extends Copernica_MarketingSoftware_Model_Copernica_Entity_Product
|
| 31 |
+
{
|
| 32 |
+
/**
|
| 33 |
+
* Cached item
|
| 34 |
+
*
|
| 35 |
+
* @var Mage_Sales_Model_Order_Item|Mage_Sales_Model_Quote_Item
|
| 36 |
+
*/
|
| 37 |
+
protected $_orderItem = null;
|
| 38 |
+
|
| 39 |
+
/**
|
| 40 |
+
* Get item Id
|
| 41 |
+
*
|
| 42 |
+
* @return string
|
| 43 |
+
*/
|
| 44 |
+
public function fetchId()
|
| 45 |
+
{
|
| 46 |
+
return $this->_orderItem->getId();
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
/**
|
| 50 |
+
* Fetch quantity
|
| 51 |
+
*
|
| 52 |
+
* @return string
|
| 53 |
+
*/
|
| 54 |
+
public function fetchQuantity()
|
| 55 |
+
{
|
| 56 |
+
if ($this->_orderItem instanceOf Mage_Sales_Model_Quote_Item) {
|
| 57 |
+
return $this->_orderItem->getQty();
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
return $this->_orderItem->getQtyOrdered();
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
/**
|
| 64 |
+
* Fetch price
|
| 65 |
+
*
|
| 66 |
+
* @return Copernia_MarketingSoftware_Model_Abstraction_Price
|
| 67 |
+
*/
|
| 68 |
+
public function fetchFullPrice()
|
| 69 |
+
{
|
| 70 |
+
return Mage::getModel('marketingsoftware/abstraction_price')->setOriginal($this->_orderItem);
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
/**
|
| 74 |
+
* Fetch total
|
| 75 |
+
*
|
| 76 |
+
* @return string
|
| 77 |
+
*/
|
| 78 |
+
public function fetchTotalPrice()
|
| 79 |
+
{
|
| 80 |
+
return $this->getFullPrice()->total();
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
/**
|
| 84 |
+
* Fetch price
|
| 85 |
+
*
|
| 86 |
+
* @return string
|
| 87 |
+
*/
|
| 88 |
+
public function fetchPrice()
|
| 89 |
+
{
|
| 90 |
+
return $this->getFullPrice()->itemPrice();
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
/**
|
| 94 |
+
* Fetch timestamp
|
| 95 |
+
*
|
| 96 |
+
* @return string
|
| 97 |
+
*/
|
| 98 |
+
public function fetchTimestamp()
|
| 99 |
+
{
|
| 100 |
+
return $this->_orderItem->getUpdatedAt();
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
/**
|
| 104 |
+
* Fetch store view
|
| 105 |
+
*
|
| 106 |
+
* @return string
|
| 107 |
+
*/
|
| 108 |
+
public function fetchStoreView()
|
| 109 |
+
{
|
| 110 |
+
$store = Mage::getModel('core/store')->load($this->getStoreId());
|
| 111 |
+
|
| 112 |
+
return Mage::getModel('marketingsoftware/abstraction_storeview')->setOriginal($store);
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
/**
|
| 116 |
+
* Get store Id
|
| 117 |
+
*
|
| 118 |
+
* @return int
|
| 119 |
+
*/
|
| 120 |
+
public function getStoreId()
|
| 121 |
+
{
|
| 122 |
+
if ($this->_orderItem instanceof Mage_Sales_Model_Quote_Item) {
|
| 123 |
+
if ($this->_orderItem->getQuote()) {
|
| 124 |
+
return $this->_orderItem->getQuote()->getStoreId();
|
| 125 |
+
} else {
|
| 126 |
+
return Mage::getModel('sales/quote')->load($this->_orderItem->getQuoteId())->getStoreId();
|
| 127 |
+
}
|
| 128 |
+
} elseif ($this->_orderItem instanceof Mage_Sales_Model_Order_Item) {
|
| 129 |
+
return $this->_orderItem->getOrder()->getStoreId();
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
return 0;
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
/**
|
| 136 |
+
* Fetch sales rules
|
| 137 |
+
*
|
| 138 |
+
* @return string
|
| 139 |
+
*/
|
| 140 |
+
public function fetchSalesRules()
|
| 141 |
+
{
|
| 142 |
+
return $this->_orderItem->getAppliedRuleIds();
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
/**
|
| 146 |
+
* Options can be nested so this function will allow us to parse them in recursive manner.
|
| 147 |
+
*
|
| 148 |
+
* @param mixed $values
|
| 149 |
+
* @param string $prefix
|
| 150 |
+
* @return string
|
| 151 |
+
*/
|
| 152 |
+
protected function _stringifyOptions($values, $prefix = '')
|
| 153 |
+
{
|
| 154 |
+
$result = '';
|
| 155 |
+
|
| 156 |
+
foreach ($values as $value) {
|
| 157 |
+
if (is_array($value['value'])) {
|
| 158 |
+
if (isset($value['value'][0]) && count($value['value']) == 1) {
|
| 159 |
+
$value['value'] = $value['value'][0];
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
$result .= $prefix.$value['label'].":\n".$this->_stringifyOptions($value['value'], $prefix.' ');
|
| 163 |
+
} else {
|
| 164 |
+
$result .= $prefix.$value['label'].":".$value['value']."\n";
|
| 165 |
+
}
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
return $result;
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
/**
|
| 172 |
+
* Get REST order item entity
|
| 173 |
+
*
|
| 174 |
+
* @return Copernica_MarketingSoftware_Model_Rest_Order_Item
|
| 175 |
+
*/
|
| 176 |
+
public function getRestOrderItem()
|
| 177 |
+
{
|
| 178 |
+
$restOrderItem = Mage::getModel('marketingsoftware/rest_order_item');
|
| 179 |
+
$restOrderItem->setOrderItemEntity($this);
|
| 180 |
+
|
| 181 |
+
return $restOrderItem;
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
/**
|
| 185 |
+
* Set copernica order item
|
| 186 |
+
*
|
| 187 |
+
* @param Mage_Sales_Model_Order_Item|Mage_Sales_Model_Quote_Item $orderItem
|
| 188 |
+
*/
|
| 189 |
+
public function setOrderItem($orderItem)
|
| 190 |
+
{
|
| 191 |
+
$this->_orderItem = $orderItem;
|
| 192 |
+
|
| 193 |
+
$this->setProduct($orderItem->getProductId());
|
| 194 |
+
}
|
| 195 |
}
|
app/code/community/Copernica/MarketingSoftware/Model/Copernica/Entity/Product.php
CHANGED
|
@@ -1,436 +1,436 @@
|
|
| 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 |
-
* Representation of a product for Copernica platform
|
| 29 |
-
*/
|
| 30 |
-
class Copernica_MarketingSoftware_Model_Copernica_Entity_Product extends Copernica_MarketingSoftware_Model_Copernica_Entity
|
| 31 |
-
{
|
| 32 |
-
/**
|
| 33 |
-
* Magento product that will be used during sync
|
| 34 |
-
*
|
| 35 |
-
* @var Mage_Catalog_Model_Product
|
| 36 |
-
*/
|
| 37 |
-
protected $_product = null;
|
| 38 |
-
|
| 39 |
-
/**
|
| 40 |
-
* Timestamp of when the product was viewed
|
| 41 |
-
*
|
| 42 |
-
* @var int
|
| 43 |
-
*/
|
| 44 |
-
protected $_timestamp;
|
| 45 |
-
|
| 46 |
-
/**
|
| 47 |
-
* Get native magento object
|
| 48 |
-
*
|
| 49 |
-
* @return Mage_Catalog_Model_Product
|
| 50 |
-
*/
|
| 51 |
-
public function getNative()
|
| 52 |
-
{
|
| 53 |
-
return $this->_product;
|
| 54 |
-
}
|
| 55 |
-
|
| 56 |
-
/**
|
| 57 |
-
* Fetch product Id
|
| 58 |
-
*
|
| 59 |
-
* @return string
|
| 60 |
-
*/
|
| 61 |
-
public function fetchProductId()
|
| 62 |
-
{
|
| 63 |
-
return $this->_product->getId();
|
| 64 |
-
}
|
| 65 |
-
|
| 66 |
-
/**
|
| 67 |
-
* Get product name
|
| 68 |
-
*
|
| 69 |
-
* @return string
|
| 70 |
-
*/
|
| 71 |
-
public function fetchName()
|
| 72 |
-
{
|
| 73 |
-
return $this->_product->getName();
|
| 74 |
-
}
|
| 75 |
-
|
| 76 |
-
/**
|
| 77 |
-
* Get SKU
|
| 78 |
-
*
|
| 79 |
-
* @return string
|
| 80 |
-
*/
|
| 81 |
-
public function fetchSku()
|
| 82 |
-
{
|
| 83 |
-
return $this->_product->getSku();
|
| 84 |
-
}
|
| 85 |
-
|
| 86 |
-
/**
|
| 87 |
-
* Get description
|
| 88 |
-
*
|
| 89 |
-
* @return string
|
| 90 |
-
*/
|
| 91 |
-
public function fetchDescription()
|
| 92 |
-
{
|
| 93 |
-
return $this->_product->getShortDescription();
|
| 94 |
-
}
|
| 95 |
-
|
| 96 |
-
/**
|
| 97 |
-
* Get price
|
| 98 |
-
*
|
| 99 |
-
* @return string
|
| 100 |
-
*/
|
| 101 |
-
public function fetchPrice()
|
| 102 |
-
{
|
| 103 |
-
return $this->_product->getPrice();
|
| 104 |
-
}
|
| 105 |
-
|
| 106 |
-
/**
|
| 107 |
-
* Fetch special price
|
| 108 |
-
*
|
| 109 |
-
* @todo test me!
|
| 110 |
-
* @return string
|
| 111 |
-
*/
|
| 112 |
-
public function fetchSpecialPrice()
|
| 113 |
-
{
|
| 114 |
-
return $this->_product->getSpecialPrice();
|
| 115 |
-
}
|
| 116 |
-
|
| 117 |
-
/**
|
| 118 |
-
* Get product viewed at
|
| 119 |
-
*
|
| 120 |
-
* @return string
|
| 121 |
-
*/
|
| 122 |
-
public function fetchTimestamp()
|
| 123 |
-
{
|
| 124 |
-
return $this->_timestamp;
|
| 125 |
-
}
|
| 126 |
-
|
| 127 |
-
/**
|
| 128 |
-
* Get url to product page
|
| 129 |
-
*
|
| 130 |
-
* @return string
|
| 131 |
-
*/
|
| 132 |
-
public function fetchUrl()
|
| 133 |
-
{
|
| 134 |
-
$url = $this->_product->getProductUrl($this->getStoreId());
|
| 135 |
-
|
| 136 |
-
if (strpos($url, 'processQueue.php')) {
|
| 137 |
-
$url = str_replace('processQueue.php', 'index.php', $url);
|
| 138 |
-
}
|
| 139 |
-
|
| 140 |
-
return $url;
|
| 141 |
-
}
|
| 142 |
-
|
| 143 |
-
/**
|
| 144 |
-
* Get image URL by it's type. Note that type should be compatible with
|
| 145 |
-
* magento internal types, so 'image' or 'thumbnail' can be used.
|
| 146 |
-
*
|
| 147 |
-
* When image can't be found or identified or magento has some other
|
| 148 |
-
* problems with beforementioned image empty string will be returned.
|
| 149 |
-
*
|
| 150 |
-
* @return string
|
| 151 |
-
*/
|
| 152 |
-
protected function _getImageByType($type)
|
| 153 |
-
{
|
| 154 |
-
try {
|
| 155 |
-
return Mage::helper('catalog/image')->init($this->_product, $type);
|
| 156 |
-
} catch (Exception $e) {
|
| 157 |
-
Mage::logException($e);
|
| 158 |
-
return '';
|
| 159 |
-
}
|
| 160 |
-
}
|
| 161 |
-
|
| 162 |
-
/**
|
| 163 |
-
* Get URL to product image
|
| 164 |
-
*
|
| 165 |
-
* @return string
|
| 166 |
-
*/
|
| 167 |
-
public function fetchImage()
|
| 168 |
-
{
|
| 169 |
-
return $this->_getImageByType('image');
|
| 170 |
-
}
|
| 171 |
-
|
| 172 |
-
/**
|
| 173 |
-
* Get URL to product thumbnail
|
| 174 |
-
*
|
| 175 |
-
* @return string
|
| 176 |
-
*/
|
| 177 |
-
public function fetchThumbnail()
|
| 178 |
-
{
|
| 179 |
-
return $this->_getImageByType('thumbnail');
|
| 180 |
-
}
|
| 181 |
-
|
| 182 |
-
/**
|
| 183 |
-
* This method should be overriden in child classes because product can be
|
| 184 |
-
* placed inside multiple stores so it's not possible to point to one certain
|
| 185 |
-
* store Id.
|
| 186 |
-
*
|
| 187 |
-
* @return int
|
| 188 |
-
*/
|
| 189 |
-
public function getStoreId()
|
| 190 |
-
{
|
| 191 |
-
if ($this->_product->getStoreId()) {
|
| 192 |
-
return $this->_product->getStoreId();
|
| 193 |
-
} else {
|
| 194 |
-
return 0;
|
| 195 |
-
}
|
| 196 |
-
}
|
| 197 |
-
|
| 198 |
-
/**
|
| 199 |
-
* Get product Id
|
| 200 |
-
*
|
| 201 |
-
* @return string
|
| 202 |
-
*/
|
| 203 |
-
public function fetchId()
|
| 204 |
-
{
|
| 205 |
-
return $this->_product->getId();
|
| 206 |
-
}
|
| 207 |
-
|
| 208 |
-
/**
|
| 209 |
-
* Fetch store view
|
| 210 |
-
*
|
| 211 |
-
* @return string
|
| 212 |
-
*/
|
| 213 |
-
public function fetchStoreView()
|
| 214 |
-
{
|
| 215 |
-
$store = Mage::getModel('core/store')->load($this->getStoreId());
|
| 216 |
-
|
| 217 |
-
return Mage::getModel('marketingsoftware/abstraction_storeview')->setOriginal($store);
|
| 218 |
-
}
|
| 219 |
-
|
| 220 |
-
/**
|
| 221 |
-
* Get product weight
|
| 222 |
-
*
|
| 223 |
-
* @return string
|
| 224 |
-
*/
|
| 225 |
-
public function fetchWeight()
|
| 226 |
-
{
|
| 227 |
-
return $this->_product->getWeight();
|
| 228 |
-
}
|
| 229 |
-
|
| 230 |
-
/**
|
| 231 |
-
* Get last modification date
|
| 232 |
-
*
|
| 233 |
-
* @return string
|
| 234 |
-
*/
|
| 235 |
-
public function getModified()
|
| 236 |
-
{
|
| 237 |
-
return $this->_product->getUpdatedAt();
|
| 238 |
-
}
|
| 239 |
-
|
| 240 |
-
/**
|
| 241 |
-
* Get product creation date
|
| 242 |
-
*
|
| 243 |
-
* @return string
|
| 244 |
-
*/
|
| 245 |
-
public function getCreated()
|
| 246 |
-
{
|
| 247 |
-
return $this->_product->getCreatedAt();
|
| 248 |
-
}
|
| 249 |
-
|
| 250 |
-
/**
|
| 251 |
-
* Fetch categories list
|
| 252 |
-
*
|
| 253 |
-
* @return array
|
| 254 |
-
*/
|
| 255 |
-
public function fetchCategoriesList()
|
| 256 |
-
{
|
| 257 |
-
$categoryIds = $this->_product->getCategoryIds();
|
| 258 |
-
|
| 259 |
-
$data = array();
|
| 260 |
-
|
| 261 |
-
foreach ($categoryIds as $id) {
|
| 262 |
-
$categoryName = array();
|
| 263 |
-
|
| 264 |
-
$parent = Mage::getModel('catalog/category')->load($id);
|
| 265 |
-
|
| 266 |
-
while($parent->getId() > 1) {
|
| 267 |
-
$categoryName [] = $parent->getName();
|
| 268 |
-
|
| 269 |
-
$parent = $parent->getParentCategory();
|
| 270 |
-
}
|
| 271 |
-
|
| 272 |
-
$data[$id] = implode(' > ', $categoryName);
|
| 273 |
-
}
|
| 274 |
-
|
| 275 |
-
return $data;
|
| 276 |
-
}
|
| 277 |
-
|
| 278 |
-
/**
|
| 279 |
-
* Get product category path
|
| 280 |
-
*
|
| 281 |
-
* @return string
|
| 282 |
-
*/
|
| 283 |
-
public function fetchCategories()
|
| 284 |
-
{
|
| 285 |
-
return implode("\n", $this->fetchCategoriesList());
|
| 286 |
-
}
|
| 287 |
-
|
| 288 |
-
/**
|
| 289 |
-
* Fetch options associated with given product.
|
| 290 |
-
*
|
| 291 |
-
* @return string
|
| 292 |
-
*/
|
| 293 |
-
public function fetchOptions()
|
| 294 |
-
{
|
| 295 |
-
$options = $this->_product->getTypeInstance(true)->getOrderOptions($this->_product);
|
| 296 |
-
|
| 297 |
-
$neededOptions = array();
|
| 298 |
-
|
| 299 |
-
if (isset($options['attributes_info'])) {
|
| 300 |
-
$neededOptions = $options['attributes_info'];
|
| 301 |
-
} elseif (isset($options['bundle_options'])) {
|
| 302 |
-
$neededOptions = $options['bundle_options'];
|
| 303 |
-
} elseif (isset($options['options'])) {
|
| 304 |
-
$neeededOptions = $options['options'];
|
| 305 |
-
}
|
| 306 |
-
|
| 307 |
-
return $this->_stringifyOptions($neededOptions);
|
| 308 |
-
}
|
| 309 |
-
|
| 310 |
-
/**
|
| 311 |
-
* Fetch attribute list
|
| 312 |
-
*
|
| 313 |
-
* @return array
|
| 314 |
-
*/
|
| 315 |
-
public function fetchAttributesList()
|
| 316 |
-
{
|
| 317 |
-
$attributes = $this->_product->getAttributes();
|
| 318 |
-
|
| 319 |
-
$resultSet = array();
|
| 320 |
-
|
| 321 |
-
$stringRepresentation = '';
|
| 322 |
-
|
| 323 |
-
foreach ($attributes as $attr) {
|
| 324 |
-
if (!$attr->getIsUserDefined()) {
|
| 325 |
-
continue;
|
| 326 |
-
}
|
| 327 |
-
|
| 328 |
-
$compareArray = array('text', 'select', 'multiline', 'textarea', 'price', 'date', 'multiselect');
|
| 329 |
-
|
| 330 |
-
if (!in_array($attr->getFrontendInput(), $compareArray)) {
|
| 331 |
-
continue;
|
| 332 |
-
}
|
| 333 |
-
|
| 334 |
-
if ($attr->getAttributeCode() && $value = $attr->getFrontend()->getValue($this->_product)) {
|
| 335 |
-
$resultSet []= array (
|
| 336 |
-
'code' => $attr->getAttributeCode(),
|
| 337 |
-
'value' => $value,
|
| 338 |
-
'type' => $attr->getFrontendInput(),
|
| 339 |
-
'label' => $attr->getFrontendLabel()
|
| 340 |
-
);
|
| 341 |
-
}
|
| 342 |
-
}
|
| 343 |
-
|
| 344 |
-
return $resultSet;
|
| 345 |
-
}
|
| 346 |
-
|
| 347 |
-
/**
|
| 348 |
-
* Is product a new product?
|
| 349 |
-
*
|
| 350 |
-
* @return boolean
|
| 351 |
-
*/
|
| 352 |
-
public function fetchNew()
|
| 353 |
-
{
|
| 354 |
-
$newsFrom = $this->_product->getNewsFromDate();
|
| 355 |
-
$newsTo = $this->_product->getNewsToDate();
|
| 356 |
-
|
| 357 |
-
if (!$newsFrom && !$newsTo) {
|
| 358 |
-
return false;
|
| 359 |
-
}
|
| 360 |
-
|
| 361 |
-
$from = Mage::app()->getLocale()->date($newsFrom);
|
| 362 |
-
$to = Mage::app()->getLocale()->date($newsTo);
|
| 363 |
-
$now = Zend_Date::now();
|
| 364 |
-
|
| 365 |
-
$new = true;
|
| 366 |
-
|
| 367 |
-
$new = $from ? $new && $from->isEarlier($now) : $new;
|
| 368 |
-
$new = $to ? $new && $to->isLater($now) : $new;
|
| 369 |
-
|
| 370 |
-
return $new;
|
| 371 |
-
}
|
| 372 |
-
|
| 373 |
-
/**
|
| 374 |
-
* Fetch attributes string representation.
|
| 375 |
-
*
|
| 376 |
-
* @return string
|
| 377 |
-
*/
|
| 378 |
-
public function fetchAttributes()
|
| 379 |
-
{
|
| 380 |
-
$attributes = array_map( function ($item) {
|
| 381 |
-
return sprintf("%s: %s", $item['code'], $item['value']);
|
| 382 |
-
}, $this->getAttributesList());
|
| 383 |
-
|
| 384 |
-
if (!is_array($attributes)) {
|
| 385 |
-
return '';
|
| 386 |
-
}
|
| 387 |
-
|
| 388 |
-
return implode ("\n", $attributes);
|
| 389 |
-
}
|
| 390 |
-
|
| 391 |
-
/**
|
| 392 |
-
* Fetch attribute set name
|
| 393 |
-
*
|
| 394 |
-
* @return string
|
| 395 |
-
*/
|
| 396 |
-
public function fetchAttributeSet()
|
| 397 |
-
{
|
| 398 |
-
$set = Mage::getModel('eav/entity_attribute_set')->load($this->_product->getAttributeSetId());
|
| 399 |
-
|
| 400 |
-
return $set->getAttributeSetName();
|
| 401 |
-
}
|
| 402 |
-
|
| 403 |
-
/**
|
| 404 |
-
* Get REST product entity
|
| 405 |
-
*
|
| 406 |
-
* @return Copernica_MarketingSoftware_Model_Rest_Product
|
| 407 |
-
*/
|
| 408 |
-
public function getRestProduct()
|
| 409 |
-
{
|
| 410 |
-
$restProduct = Mage::getModel('marketingsoftware/rest_product');
|
| 411 |
-
$restProduct->setProductEntity($this);
|
| 412 |
-
|
| 413 |
-
return $restProduct;
|
| 414 |
-
}
|
| 415 |
-
|
| 416 |
-
/**
|
| 417 |
-
* Set product entity
|
| 418 |
-
*
|
| 419 |
-
* @param int $productId
|
| 420 |
-
*/
|
| 421 |
-
public function setProduct($productId)
|
| 422 |
-
{
|
| 423 |
-
$this->_product = Mage::getModel('catalog/product')->load($productId);
|
| 424 |
-
}
|
| 425 |
-
|
| 426 |
-
|
| 427 |
-
/**
|
| 428 |
-
* Set the timestamp for when the product was viewed
|
| 429 |
-
*
|
| 430 |
-
* @param unknown $viewedAt
|
| 431 |
-
*/
|
| 432 |
-
public function setTimestamp($viewedAt)
|
| 433 |
-
{
|
| 434 |
-
$this->_timestamp = $viewedAt;
|
| 435 |
-
}
|
| 436 |
}
|
| 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 |
+
* Representation of a product for Copernica platform
|
| 29 |
+
*/
|
| 30 |
+
class Copernica_MarketingSoftware_Model_Copernica_Entity_Product extends Copernica_MarketingSoftware_Model_Copernica_Entity
|
| 31 |
+
{
|
| 32 |
+
/**
|
| 33 |
+
* Magento product that will be used during sync
|
| 34 |
+
*
|
| 35 |
+
* @var Mage_Catalog_Model_Product
|
| 36 |
+
*/
|
| 37 |
+
protected $_product = null;
|
| 38 |
+
|
| 39 |
+
/**
|
| 40 |
+
* Timestamp of when the product was viewed
|
| 41 |
+
*
|
| 42 |
+
* @var int
|
| 43 |
+
*/
|
| 44 |
+
protected $_timestamp;
|
| 45 |
+
|
| 46 |
+
/**
|
| 47 |
+
* Get native magento object
|
| 48 |
+
*
|
| 49 |
+
* @return Mage_Catalog_Model_Product
|
| 50 |
+
*/
|
| 51 |
+
public function getNative()
|
| 52 |
+
{
|
| 53 |
+
return $this->_product;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
/**
|
| 57 |
+
* Fetch product Id
|
| 58 |
+
*
|
| 59 |
+
* @return string
|
| 60 |
+
*/
|
| 61 |
+
public function fetchProductId()
|
| 62 |
+
{
|
| 63 |
+
return $this->_product->getId();
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
/**
|
| 67 |
+
* Get product name
|
| 68 |
+
*
|
| 69 |
+
* @return string
|
| 70 |
+
*/
|
| 71 |
+
public function fetchName()
|
| 72 |
+
{
|
| 73 |
+
return $this->_product->getName();
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
/**
|
| 77 |
+
* Get SKU
|
| 78 |
+
*
|
| 79 |
+
* @return string
|
| 80 |
+
*/
|
| 81 |
+
public function fetchSku()
|
| 82 |
+
{
|
| 83 |
+
return $this->_product->getSku();
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
/**
|
| 87 |
+
* Get description
|
| 88 |
+
*
|
| 89 |
+
* @return string
|
| 90 |
+
*/
|
| 91 |
+
public function fetchDescription()
|
| 92 |
+
{
|
| 93 |
+
return $this->_product->getShortDescription();
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
/**
|
| 97 |
+
* Get price
|
| 98 |
+
*
|
| 99 |
+
* @return string
|
| 100 |
+
*/
|
| 101 |
+
public function fetchPrice()
|
| 102 |
+
{
|
| 103 |
+
return $this->_product->getPrice();
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
/**
|
| 107 |
+
* Fetch special price
|
| 108 |
+
*
|
| 109 |
+
* @todo test me!
|
| 110 |
+
* @return string
|
| 111 |
+
*/
|
| 112 |
+
public function fetchSpecialPrice()
|
| 113 |
+
{
|
| 114 |
+
return $this->_product->getSpecialPrice();
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
/**
|
| 118 |
+
* Get product viewed at
|
| 119 |
+
*
|
| 120 |
+
* @return string
|
| 121 |
+
*/
|
| 122 |
+
public function fetchTimestamp()
|
| 123 |
+
{
|
| 124 |
+
return $this->_timestamp;
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
/**
|
| 128 |
+
* Get url to product page
|
| 129 |
+
*
|
| 130 |
+
* @return string
|
| 131 |
+
*/
|
| 132 |
+
public function fetchUrl()
|
| 133 |
+
{
|
| 134 |
+
$url = $this->_product->getProductUrl($this->getStoreId());
|
| 135 |
+
|
| 136 |
+
if (strpos($url, 'processQueue.php')) {
|
| 137 |
+
$url = str_replace('processQueue.php', 'index.php', $url);
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
return $url;
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
/**
|
| 144 |
+
* Get image URL by it's type. Note that type should be compatible with
|
| 145 |
+
* magento internal types, so 'image' or 'thumbnail' can be used.
|
| 146 |
+
*
|
| 147 |
+
* When image can't be found or identified or magento has some other
|
| 148 |
+
* problems with beforementioned image empty string will be returned.
|
| 149 |
+
*
|
| 150 |
+
* @return string
|
| 151 |
+
*/
|
| 152 |
+
protected function _getImageByType($type)
|
| 153 |
+
{
|
| 154 |
+
try {
|
| 155 |
+
return Mage::helper('catalog/image')->init($this->_product, $type);
|
| 156 |
+
} catch (Exception $e) {
|
| 157 |
+
Mage::logException($e);
|
| 158 |
+
return '';
|
| 159 |
+
}
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
/**
|
| 163 |
+
* Get URL to product image
|
| 164 |
+
*
|
| 165 |
+
* @return string
|
| 166 |
+
*/
|
| 167 |
+
public function fetchImage()
|
| 168 |
+
{
|
| 169 |
+
return $this->_getImageByType('image');
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
/**
|
| 173 |
+
* Get URL to product thumbnail
|
| 174 |
+
*
|
| 175 |
+
* @return string
|
| 176 |
+
*/
|
| 177 |
+
public function fetchThumbnail()
|
| 178 |
+
{
|
| 179 |
+
return $this->_getImageByType('thumbnail');
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
/**
|
| 183 |
+
* This method should be overriden in child classes because product can be
|
| 184 |
+
* placed inside multiple stores so it's not possible to point to one certain
|
| 185 |
+
* store Id.
|
| 186 |
+
*
|
| 187 |
+
* @return int
|
| 188 |
+
*/
|
| 189 |
+
public function getStoreId()
|
| 190 |
+
{
|
| 191 |
+
if ($this->_product->getStoreId()) {
|
| 192 |
+
return $this->_product->getStoreId();
|
| 193 |
+
} else {
|
| 194 |
+
return 0;
|
| 195 |
+
}
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
/**
|
| 199 |
+
* Get product Id
|
| 200 |
+
*
|
| 201 |
+
* @return string
|
| 202 |
+
*/
|
| 203 |
+
public function fetchId()
|
| 204 |
+
{
|
| 205 |
+
return $this->_product->getId();
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
/**
|
| 209 |
+
* Fetch store view
|
| 210 |
+
*
|
| 211 |
+
* @return string
|
| 212 |
+
*/
|
| 213 |
+
public function fetchStoreView()
|
| 214 |
+
{
|
| 215 |
+
$store = Mage::getModel('core/store')->load($this->getStoreId());
|
| 216 |
+
|
| 217 |
+
return Mage::getModel('marketingsoftware/abstraction_storeview')->setOriginal($store);
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
/**
|
| 221 |
+
* Get product weight
|
| 222 |
+
*
|
| 223 |
+
* @return string
|
| 224 |
+
*/
|
| 225 |
+
public function fetchWeight()
|
| 226 |
+
{
|
| 227 |
+
return $this->_product->getWeight();
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
/**
|
| 231 |
+
* Get last modification date
|
| 232 |
+
*
|
| 233 |
+
* @return string
|
| 234 |
+
*/
|
| 235 |
+
public function getModified()
|
| 236 |
+
{
|
| 237 |
+
return $this->_product->getUpdatedAt();
|
| 238 |
+
}
|
| 239 |
+
|
| 240 |
+
/**
|
| 241 |
+
* Get product creation date
|
| 242 |
+
*
|
| 243 |
+
* @return string
|
| 244 |
+
*/
|
| 245 |
+
public function getCreated()
|
| 246 |
+
{
|
| 247 |
+
return $this->_product->getCreatedAt();
|
| 248 |
+
}
|
| 249 |
+
|
| 250 |
+
/**
|
| 251 |
+
* Fetch categories list
|
| 252 |
+
*
|
| 253 |
+
* @return array
|
| 254 |
+
*/
|
| 255 |
+
public function fetchCategoriesList()
|
| 256 |
+
{
|
| 257 |
+
$categoryIds = $this->_product->getCategoryIds();
|
| 258 |
+
|
| 259 |
+
$data = array();
|
| 260 |
+
|
| 261 |
+
foreach ($categoryIds as $id) {
|
| 262 |
+
$categoryName = array();
|
| 263 |
+
|
| 264 |
+
$parent = Mage::getModel('catalog/category')->load($id);
|
| 265 |
+
|
| 266 |
+
while($parent->getId() > 1) {
|
| 267 |
+
$categoryName [] = $parent->getName();
|
| 268 |
+
|
| 269 |
+
$parent = $parent->getParentCategory();
|
| 270 |
+
}
|
| 271 |
+
|
| 272 |
+
$data[$id] = implode(' > ', $categoryName);
|
| 273 |
+
}
|
| 274 |
+
|
| 275 |
+
return $data;
|
| 276 |
+
}
|
| 277 |
+
|
| 278 |
+
/**
|
| 279 |
+
* Get product category path
|
| 280 |
+
*
|
| 281 |
+
* @return string
|
| 282 |
+
*/
|
| 283 |
+
public function fetchCategories()
|
| 284 |
+
{
|
| 285 |
+
return implode("\n", $this->fetchCategoriesList());
|
| 286 |
+
}
|
| 287 |
+
|
| 288 |
+
/**
|
| 289 |
+
* Fetch options associated with given product.
|
| 290 |
+
*
|
| 291 |
+
* @return string
|
| 292 |
+
*/
|
| 293 |
+
public function fetchOptions()
|
| 294 |
+
{
|
| 295 |
+
$options = $this->_product->getTypeInstance(true)->getOrderOptions($this->_product);
|
| 296 |
+
|
| 297 |
+
$neededOptions = array();
|
| 298 |
+
|
| 299 |
+
if (isset($options['attributes_info'])) {
|
| 300 |
+
$neededOptions = $options['attributes_info'];
|
| 301 |
+
} elseif (isset($options['bundle_options'])) {
|
| 302 |
+
$neededOptions = $options['bundle_options'];
|
| 303 |
+
} elseif (isset($options['options'])) {
|
| 304 |
+
$neeededOptions = $options['options'];
|
| 305 |
+
}
|
| 306 |
+
|
| 307 |
+
return $this->_stringifyOptions($neededOptions);
|
| 308 |
+
}
|
| 309 |
+
|
| 310 |
+
/**
|
| 311 |
+
* Fetch attribute list
|
| 312 |
+
*
|
| 313 |
+
* @return array
|
| 314 |
+
*/
|
| 315 |
+
public function fetchAttributesList()
|
| 316 |
+
{
|
| 317 |
+
$attributes = $this->_product->getAttributes();
|
| 318 |
+
|
| 319 |
+
$resultSet = array();
|
| 320 |
+
|
| 321 |
+
$stringRepresentation = '';
|
| 322 |
+
|
| 323 |
+
foreach ($attributes as $attr) {
|
| 324 |
+
if (!$attr->getIsUserDefined()) {
|
| 325 |
+
continue;
|
| 326 |
+
}
|
| 327 |
+
|
| 328 |
+
$compareArray = array('text', 'select', 'multiline', 'textarea', 'price', 'date', 'multiselect');
|
| 329 |
+
|
| 330 |
+
if (!in_array($attr->getFrontendInput(), $compareArray)) {
|
| 331 |
+
continue;
|
| 332 |
+
}
|
| 333 |
+
|
| 334 |
+
if ($attr->getAttributeCode() && $value = $attr->getFrontend()->getValue($this->_product)) {
|
| 335 |
+
$resultSet []= array (
|
| 336 |
+
'code' => $attr->getAttributeCode(),
|
| 337 |
+
'value' => $value,
|
| 338 |
+
'type' => $attr->getFrontendInput(),
|
| 339 |
+
'label' => $attr->getFrontendLabel()
|
| 340 |
+
);
|
| 341 |
+
}
|
| 342 |
+
}
|
| 343 |
+
|
| 344 |
+
return $resultSet;
|
| 345 |
+
}
|
| 346 |
+
|
| 347 |
+
/**
|
| 348 |
+
* Is product a new product?
|
| 349 |
+
*
|
| 350 |
+
* @return boolean
|
| 351 |
+
*/
|
| 352 |
+
public function fetchNew()
|
| 353 |
+
{
|
| 354 |
+
$newsFrom = $this->_product->getNewsFromDate();
|
| 355 |
+
$newsTo = $this->_product->getNewsToDate();
|
| 356 |
+
|
| 357 |
+
if (!$newsFrom && !$newsTo) {
|
| 358 |
+
return false;
|
| 359 |
+
}
|
| 360 |
+
|
| 361 |
+
$from = Mage::app()->getLocale()->date($newsFrom);
|
| 362 |
+
$to = Mage::app()->getLocale()->date($newsTo);
|
| 363 |
+
$now = Zend_Date::now();
|
| 364 |
+
|
| 365 |
+
$new = true;
|
| 366 |
+
|
| 367 |
+
$new = $from ? $new && $from->isEarlier($now) : $new;
|
| 368 |
+
$new = $to ? $new && $to->isLater($now) : $new;
|
| 369 |
+
|
| 370 |
+
return $new;
|
| 371 |
+
}
|
| 372 |
+
|
| 373 |
+
/**
|
| 374 |
+
* Fetch attributes string representation.
|
| 375 |
+
*
|
| 376 |
+
* @return string
|
| 377 |
+
*/
|
| 378 |
+
public function fetchAttributes()
|
| 379 |
+
{
|
| 380 |
+
$attributes = array_map( function ($item) {
|
| 381 |
+
return sprintf("%s: %s", $item['code'], $item['value']);
|
| 382 |
+
}, $this->getAttributesList());
|
| 383 |
+
|
| 384 |
+
if (!is_array($attributes)) {
|
| 385 |
+
return '';
|
| 386 |
+
}
|
| 387 |
+
|
| 388 |
+
return implode ("\n", $attributes);
|
| 389 |
+
}
|
| 390 |
+
|
| 391 |
+
/**
|
| 392 |
+
* Fetch attribute set name
|
| 393 |
+
*
|
| 394 |
+
* @return string
|
| 395 |
+
*/
|
| 396 |
+
public function fetchAttributeSet()
|
| 397 |
+
{
|
| 398 |
+
$set = Mage::getModel('eav/entity_attribute_set')->load($this->_product->getAttributeSetId());
|
| 399 |
+
|
| 400 |
+
return $set->getAttributeSetName();
|
| 401 |
+
}
|
| 402 |
+
|
| 403 |
+
/**
|
| 404 |
+
* Get REST product entity
|
| 405 |
+
*
|
| 406 |
+
* @return Copernica_MarketingSoftware_Model_Rest_Product
|
| 407 |
+
*/
|
| 408 |
+
public function getRestProduct()
|
| 409 |
+
{
|
| 410 |
+
$restProduct = Mage::getModel('marketingsoftware/rest_product');
|
| 411 |
+
$restProduct->setProductEntity($this);
|
| 412 |
+
|
| 413 |
+
return $restProduct;
|
| 414 |
+
}
|
| 415 |
+
|
| 416 |
+
/**
|
| 417 |
+
* Set product entity
|
| 418 |
+
*
|
| 419 |
+
* @param int $productId
|
| 420 |
+
*/
|
| 421 |
+
public function setProduct($productId)
|
| 422 |
+
{
|
| 423 |
+
$this->_product = Mage::getModel('catalog/product')->load($productId);
|
| 424 |
+
}
|
| 425 |
+
|
| 426 |
+
|
| 427 |
+
/**
|
| 428 |
+
* Set the timestamp for when the product was viewed
|
| 429 |
+
*
|
| 430 |
+
* @param unknown $viewedAt
|
| 431 |
+
*/
|
| 432 |
+
public function setTimestamp($viewedAt)
|
| 433 |
+
{
|
| 434 |
+
$this->_timestamp = $viewedAt;
|
| 435 |
+
}
|
| 436 |
}
|
app/code/community/Copernica/MarketingSoftware/Model/Copernica/Entity/Quote.php
CHANGED
|
@@ -1,89 +1,89 @@
|
|
| 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 |
-
* Bridge between magento quote and copernica subprofile
|
| 29 |
-
*/
|
| 30 |
-
class Copernica_MarketingSoftware_Model_Copernica_Entity_Quote extends Copernica_MarketingSoftware_Model_Copernica_Entity
|
| 31 |
-
{
|
| 32 |
-
/**
|
| 33 |
-
* Cached quote instance
|
| 34 |
-
*
|
| 35 |
-
* @var Mage_Sales_Model_Quote
|
| 36 |
-
*/
|
| 37 |
-
protected $_quote;
|
| 38 |
-
|
| 39 |
-
/**
|
| 40 |
-
* Cached quote items
|
| 41 |
-
*
|
| 42 |
-
* @var array
|
| 43 |
-
*/
|
| 44 |
-
protected $_quoteItems;
|
| 45 |
-
|
| 46 |
-
/**
|
| 47 |
-
* @return array
|
| 48 |
-
*/
|
| 49 |
-
public function getItems()
|
| 50 |
-
{
|
| 51 |
-
if (!is_null($this
|
| 52 |
-
return $this
|
| 53 |
-
}
|
| 54 |
-
|
| 55 |
-
$quoteItems = array();
|
| 56 |
-
|
| 57 |
-
foreach ($this->_quote->getAllItems() as $quoteItem) {
|
| 58 |
-
$quoteItemEntity = Mage::getModel('marketingsoftware/copernica_entity_quote_item');
|
| 59 |
-
$quoteItemEntity->setQuoteItem($quoteItem);
|
| 60 |
-
|
| 61 |
-
$quoteItems[] = $quoteItemEntity;
|
| 62 |
-
}
|
| 63 |
-
|
| 64 |
-
return $this->_quoteItems = $quoteItems;
|
| 65 |
-
}
|
| 66 |
-
|
| 67 |
-
/**
|
| 68 |
-
* Get REST quote entity
|
| 69 |
-
*
|
| 70 |
-
* @return Copernica_MarketingSoftware_Model_Rest_Quote
|
| 71 |
-
*/
|
| 72 |
-
public function getRestQuote()
|
| 73 |
-
{
|
| 74 |
-
$restQuote = Mage::getModel('marketingsoftware/rest_quote');
|
| 75 |
-
$restQuote->setQuoteEntity($this);
|
| 76 |
-
|
| 77 |
-
return $restQuote;
|
| 78 |
-
}
|
| 79 |
-
|
| 80 |
-
/**
|
| 81 |
-
* Set quote entity
|
| 82 |
-
*
|
| 83 |
-
* @param Mage_Sales_Model_Quote $quote
|
| 84 |
-
*/
|
| 85 |
-
public function setQuote($quote)
|
| 86 |
-
{
|
| 87 |
-
$this->_quote = $quote;
|
| 88 |
-
}
|
| 89 |
}
|
| 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 |
+
* Bridge between magento quote and copernica subprofile
|
| 29 |
+
*/
|
| 30 |
+
class Copernica_MarketingSoftware_Model_Copernica_Entity_Quote extends Copernica_MarketingSoftware_Model_Copernica_Entity
|
| 31 |
+
{
|
| 32 |
+
/**
|
| 33 |
+
* Cached quote instance
|
| 34 |
+
*
|
| 35 |
+
* @var Mage_Sales_Model_Quote
|
| 36 |
+
*/
|
| 37 |
+
protected $_quote;
|
| 38 |
+
|
| 39 |
+
/**
|
| 40 |
+
* Cached quote items
|
| 41 |
+
*
|
| 42 |
+
* @var array
|
| 43 |
+
*/
|
| 44 |
+
protected $_quoteItems;
|
| 45 |
+
|
| 46 |
+
/**
|
| 47 |
+
* @return array
|
| 48 |
+
*/
|
| 49 |
+
public function getItems()
|
| 50 |
+
{
|
| 51 |
+
if (!is_null($this->_quoteItems)) {
|
| 52 |
+
return $this->_quoteItems;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
$quoteItems = array();
|
| 56 |
+
|
| 57 |
+
foreach ($this->_quote->getAllItems() as $quoteItem) {
|
| 58 |
+
$quoteItemEntity = Mage::getModel('marketingsoftware/copernica_entity_quote_item');
|
| 59 |
+
$quoteItemEntity->setQuoteItem($quoteItem);
|
| 60 |
+
|
| 61 |
+
$quoteItems[] = $quoteItemEntity;
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
return $this->_quoteItems = $quoteItems;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
/**
|
| 68 |
+
* Get REST quote entity
|
| 69 |
+
*
|
| 70 |
+
* @return Copernica_MarketingSoftware_Model_Rest_Quote
|
| 71 |
+
*/
|
| 72 |
+
public function getRestQuote()
|
| 73 |
+
{
|
| 74 |
+
$restQuote = Mage::getModel('marketingsoftware/rest_quote');
|
| 75 |
+
$restQuote->setQuoteEntity($this);
|
| 76 |
+
|
| 77 |
+
return $restQuote;
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
/**
|
| 81 |
+
* Set quote entity
|
| 82 |
+
*
|
| 83 |
+
* @param Mage_Sales_Model_Quote $quote
|
| 84 |
+
*/
|
| 85 |
+
public function setQuote($quote)
|
| 86 |
+
{
|
| 87 |
+
$this->_quote = $quote;
|
| 88 |
+
}
|
| 89 |
}
|
app/code/community/Copernica/MarketingSoftware/Model/Copernica/Entity/Quote/Item.php
CHANGED
|
@@ -1,93 +1,93 @@
|
|
| 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 |
-
* Brigde class between Copernica subprofile and magento quote item
|
| 29 |
-
*/
|
| 30 |
-
class Copernica_MarketingSoftware_Model_Copernica_Entity_Quote_Item extends Copernica_MarketingSoftware_Model_Copernica_Entity_Order_Item
|
| 31 |
-
{
|
| 32 |
-
/**
|
| 33 |
-
* Fetch status of an item.
|
| 34 |
-
*
|
| 35 |
-
* Magento does not have ability to determine if item was removed or if it's
|
| 36 |
-
* in cart that was forgotten by customer. We have to make that decision here.
|
| 37 |
-
*
|
| 38 |
-
* @return string
|
| 39 |
-
*/
|
| 40 |
-
public function fetchStatus()
|
| 41 |
-
{
|
| 42 |
-
$quoteId = $this->_orderItem->getQuoteId();
|
| 43 |
-
|
| 44 |
-
$quote = Mage::getModel('sales/quote');
|
| 45 |
-
$quote->loadByIdWithoutStore($quoteId);
|
| 46 |
-
|
| 47 |
-
$order = Mage::getModel('sales/order')->getCollection()->addFieldToFilter('quote_id', $quoteId)->getFirstItem();
|
| 48 |
-
|
| 49 |
-
if ($order->getId() > 0) {
|
| 50 |
-
return 'completed';
|
| 51 |
-
}
|
| 52 |
-
|
| 53 |
-
$forgottenCollection = Mage::getResourceModel('reports/quote_collection');
|
| 54 |
-
$forgottenCollection->addFieldToFilter('main_table.entity_id', $quoteId);
|
| 55 |
-
|
| 56 |
-
$timeoutLimit = new DateTime();
|
| 57 |
-
$timeoutInterval = new DateInterval("PT".(int)(Mage::helper('marketingsoftware/config')->getAbandonedTimeout())."M");
|
| 58 |
-
$timeoutInterval->invert = 1;
|
| 59 |
-
$timeoutLimit->add($timeoutInterval);
|
| 60 |
-
|
| 61 |
-
$forgottenCollection->addFieldToFilter('main_table.updated_at', array('lt' => $timeoutLimit->format("Y-m-d H:i:s")));
|
| 62 |
-
$forgottenCollection->prepareForAbandonedReport(array());
|
| 63 |
-
|
| 64 |
-
if (count($forgottenCollection)) {
|
| 65 |
-
return 'abandoned';
|
| 66 |
-
}
|
| 67 |
-
|
| 68 |
-
return 'basket';
|
| 69 |
-
}
|
| 70 |
-
|
| 71 |
-
/**
|
| 72 |
-
* Get REST quote item entity
|
| 73 |
-
*
|
| 74 |
-
* @return Copernica_MarketingSoftware_Model_Rest_Quote_Item
|
| 75 |
-
*/
|
| 76 |
-
public function getRestQuoteItem()
|
| 77 |
-
{
|
| 78 |
-
$restQuoteItem = Mage::getModel('marketingsoftware/rest_quote_item');
|
| 79 |
-
$restQuoteItem->setQuoteItemEntity($this);
|
| 80 |
-
|
| 81 |
-
return $restQuoteItem;
|
| 82 |
-
}
|
| 83 |
-
|
| 84 |
-
/**
|
| 85 |
-
* Set copernica quote item
|
| 86 |
-
*
|
| 87 |
-
* @param Mage_Sales_Model_Quote_Item $quoteItem
|
| 88 |
-
*/
|
| 89 |
-
public function setQuoteItem(Mage_Sales_Model_Quote_Item $quoteItem)
|
| 90 |
-
{
|
| 91 |
-
$this->setOrderItem($quoteItem);
|
| 92 |
-
}
|
| 93 |
}
|
| 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 |
+
* Brigde class between Copernica subprofile and magento quote item
|
| 29 |
+
*/
|
| 30 |
+
class Copernica_MarketingSoftware_Model_Copernica_Entity_Quote_Item extends Copernica_MarketingSoftware_Model_Copernica_Entity_Order_Item
|
| 31 |
+
{
|
| 32 |
+
/**
|
| 33 |
+
* Fetch status of an item.
|
| 34 |
+
*
|
| 35 |
+
* Magento does not have ability to determine if item was removed or if it's
|
| 36 |
+
* in cart that was forgotten by customer. We have to make that decision here.
|
| 37 |
+
*
|
| 38 |
+
* @return string
|
| 39 |
+
*/
|
| 40 |
+
public function fetchStatus()
|
| 41 |
+
{
|
| 42 |
+
$quoteId = $this->_orderItem->getQuoteId();
|
| 43 |
+
|
| 44 |
+
$quote = Mage::getModel('sales/quote');
|
| 45 |
+
$quote->loadByIdWithoutStore($quoteId);
|
| 46 |
+
|
| 47 |
+
$order = Mage::getModel('sales/order')->getCollection()->addFieldToFilter('quote_id', $quoteId)->getFirstItem();
|
| 48 |
+
|
| 49 |
+
if ($order->getId() > 0) {
|
| 50 |
+
return 'completed';
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
$forgottenCollection = Mage::getResourceModel('reports/quote_collection');
|
| 54 |
+
$forgottenCollection->addFieldToFilter('main_table.entity_id', $quoteId);
|
| 55 |
+
|
| 56 |
+
$timeoutLimit = new DateTime();
|
| 57 |
+
$timeoutInterval = new DateInterval("PT".(int)(Mage::helper('marketingsoftware/config')->getAbandonedTimeout())."M");
|
| 58 |
+
$timeoutInterval->invert = 1;
|
| 59 |
+
$timeoutLimit->add($timeoutInterval);
|
| 60 |
+
|
| 61 |
+
$forgottenCollection->addFieldToFilter('main_table.updated_at', array('lt' => $timeoutLimit->format("Y-m-d H:i:s")));
|
| 62 |
+
$forgottenCollection->prepareForAbandonedReport(array());
|
| 63 |
+
|
| 64 |
+
if (count($forgottenCollection)) {
|
| 65 |
+
return 'abandoned';
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
return 'basket';
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
/**
|
| 72 |
+
* Get REST quote item entity
|
| 73 |
+
*
|
| 74 |
+
* @return Copernica_MarketingSoftware_Model_Rest_Quote_Item
|
| 75 |
+
*/
|
| 76 |
+
public function getRestQuoteItem()
|
| 77 |
+
{
|
| 78 |
+
$restQuoteItem = Mage::getModel('marketingsoftware/rest_quote_item');
|
| 79 |
+
$restQuoteItem->setQuoteItemEntity($this);
|
| 80 |
+
|
| 81 |
+
return $restQuoteItem;
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
/**
|
| 85 |
+
* Set copernica quote item
|
| 86 |
+
*
|
| 87 |
+
* @param Mage_Sales_Model_Quote_Item $quoteItem
|
| 88 |
+
*/
|
| 89 |
+
public function setQuoteItem(Mage_Sales_Model_Quote_Item $quoteItem)
|
| 90 |
+
{
|
| 91 |
+
$this->setOrderItem($quoteItem);
|
| 92 |
+
}
|
| 93 |
}
|
app/code/community/Copernica/MarketingSoftware/Model/Copernica/Entity/Subscription.php
CHANGED
|
@@ -1,152 +1,152 @@
|
|
| 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 |
-
* Copernica subscription model
|
| 29 |
-
*/
|
| 30 |
-
class Copernica_MarketingSoftware_Model_Copernica_Entity_Subscription extends Copernica_MarketingSoftware_Model_Copernica_Entity
|
| 31 |
-
{
|
| 32 |
-
/**
|
| 33 |
-
* Our subscriber
|
| 34 |
-
*
|
| 35 |
-
* @var Mage_Newsletter_Model_Subscriber
|
| 36 |
-
*/
|
| 37 |
-
protected $_subscriber;
|
| 38 |
-
|
| 39 |
-
/**
|
| 40 |
-
* Fetch email address
|
| 41 |
-
*
|
| 42 |
-
* @return string
|
| 43 |
-
*/
|
| 44 |
-
public function fetchEmail()
|
| 45 |
-
{
|
| 46 |
-
return $this->_subscriber->getEmail();
|
| 47 |
-
}
|
| 48 |
-
|
| 49 |
-
/**
|
| 50 |
-
* Fetch status
|
| 51 |
-
*
|
| 52 |
-
* @return string
|
| 53 |
-
*/
|
| 54 |
-
public function fetchStatus()
|
| 55 |
-
{
|
| 56 |
-
switch ($this->_subscriber->getStatus()) {
|
| 57 |
-
case Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED:
|
| 58 |
-
return 'subscribed';
|
| 59 |
-
|
| 60 |
-
case Mage_Newsletter_Model_Subscriber::STATUS_NOT_ACTIVE:
|
| 61 |
-
return 'not active';
|
| 62 |
-
|
| 63 |
-
case Mage_Newsletter_Model_Subscriber::STATUS_UNSUBSCRIBED:
|
| 64 |
-
return 'unsubscribed';
|
| 65 |
-
|
| 66 |
-
case Mage_Newsletter_Model_Subscriber::STATUS_UNCONFIRMED:
|
| 67 |
-
return 'unconfirmed';
|
| 68 |
-
|
| 69 |
-
default:
|
| 70 |
-
return 'unknown';
|
| 71 |
-
}
|
| 72 |
-
}
|
| 73 |
-
|
| 74 |
-
/**
|
| 75 |
-
* Fetch group
|
| 76 |
-
*
|
| 77 |
-
* @return string
|
| 78 |
-
*/
|
| 79 |
-
public function fetchGroup()
|
| 80 |
-
{
|
| 81 |
-
return Mage::getModel('customer/group')->load(0)->getCode();
|
| 82 |
-
}
|
| 83 |
-
|
| 84 |
-
/**
|
| 85 |
-
* Fetch store view
|
| 86 |
-
*
|
| 87 |
-
* @return string
|
| 88 |
-
*/
|
| 89 |
-
public function fetchStoreView()
|
| 90 |
-
{
|
| 91 |
-
$store = Mage::getModel('core/store')->load($this->getStoreId());
|
| 92 |
-
|
| 93 |
-
return Mage::getModel('marketingsoftware/abstraction_storeview')->setOriginal($store);
|
| 94 |
-
}
|
| 95 |
-
|
| 96 |
-
/**
|
| 97 |
-
* Fetch subscriber customer Id
|
| 98 |
-
*
|
| 99 |
-
* @return string
|
| 100 |
-
*/
|
| 101 |
-
public function fetchCustomerId()
|
| 102 |
-
{
|
| 103 |
-
$store = Mage::getModel('core/store')->load($this->_subscriber->getStoreId());
|
| 104 |
-
|
| 105 |
-
$customer = Mage::getModel('customer/customer')->setWebsiteId($store->getWebsiteId())->loadByEmail($this->_subscriber->getEmail());
|
| 106 |
-
|
| 107 |
-
if ($customer->isObjectNew()) {
|
| 108 |
-
$identifier = $this->_subscriber->getEmail();
|
| 109 |
-
} else {
|
| 110 |
-
$identifier = $customer->getId();
|
| 111 |
-
}
|
| 112 |
-
|
| 113 |
-
return $identifier.'|'.$this->_subscriber->getStoreId();
|
| 114 |
-
}
|
| 115 |
-
|
| 116 |
-
/**
|
| 117 |
-
* Get subscribtion store Id
|
| 118 |
-
*
|
| 119 |
-
* @return int
|
| 120 |
-
*/
|
| 121 |
-
public function getStoreId()
|
| 122 |
-
{
|
| 123 |
-
if($this->_subscriber->getStoreId()) {
|
| 124 |
-
return $this->_subscriber->getStoreId();
|
| 125 |
-
} else {
|
| 126 |
-
return 0;
|
| 127 |
-
}
|
| 128 |
-
}
|
| 129 |
-
|
| 130 |
-
/**
|
| 131 |
-
* Get REST subscription entity
|
| 132 |
-
*
|
| 133 |
-
* @return Copernica_MarketingSoftware_Model_Rest_Subscription
|
| 134 |
-
*/
|
| 135 |
-
public function getRestSubscription()
|
| 136 |
-
{
|
| 137 |
-
$restSubscription = Mage::getModel('marketingsoftware/rest_subscription');
|
| 138 |
-
$restSubscription->setSubscriptionEntity($this);
|
| 139 |
-
|
| 140 |
-
return $restSubscription;
|
| 141 |
-
}
|
| 142 |
-
|
| 143 |
-
/**
|
| 144 |
-
* Set subscription entity
|
| 145 |
-
*
|
| 146 |
-
* @param Mage_Newsletter_Model_Subscriber $subscriber
|
| 147 |
-
*/
|
| 148 |
-
public function setSubscription($subscriber)
|
| 149 |
-
{
|
| 150 |
-
$this->_subscriber = $subscriber;
|
| 151 |
-
}
|
| 152 |
}
|
| 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 |
+
* Copernica subscription model
|
| 29 |
+
*/
|
| 30 |
+
class Copernica_MarketingSoftware_Model_Copernica_Entity_Subscription extends Copernica_MarketingSoftware_Model_Copernica_Entity
|
| 31 |
+
{
|
| 32 |
+
/**
|
| 33 |
+
* Our subscriber
|
| 34 |
+
*
|
| 35 |
+
* @var Mage_Newsletter_Model_Subscriber
|
| 36 |
+
*/
|
| 37 |
+
protected $_subscriber;
|
| 38 |
+
|
| 39 |
+
/**
|
| 40 |
+
* Fetch email address
|
| 41 |
+
*
|
| 42 |
+
* @return string
|
| 43 |
+
*/
|
| 44 |
+
public function fetchEmail()
|
| 45 |
+
{
|
| 46 |
+
return $this->_subscriber->getEmail();
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
/**
|
| 50 |
+
* Fetch status
|
| 51 |
+
*
|
| 52 |
+
* @return string
|
| 53 |
+
*/
|
| 54 |
+
public function fetchStatus()
|
| 55 |
+
{
|
| 56 |
+
switch ($this->_subscriber->getStatus()) {
|
| 57 |
+
case Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED:
|
| 58 |
+
return 'subscribed';
|
| 59 |
+
|
| 60 |
+
case Mage_Newsletter_Model_Subscriber::STATUS_NOT_ACTIVE:
|
| 61 |
+
return 'not active';
|
| 62 |
+
|
| 63 |
+
case Mage_Newsletter_Model_Subscriber::STATUS_UNSUBSCRIBED:
|
| 64 |
+
return 'unsubscribed';
|
| 65 |
+
|
| 66 |
+
case Mage_Newsletter_Model_Subscriber::STATUS_UNCONFIRMED:
|
| 67 |
+
return 'unconfirmed';
|
| 68 |
+
|
| 69 |
+
default:
|
| 70 |
+
return 'unknown';
|
| 71 |
+
}
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
/**
|
| 75 |
+
* Fetch group
|
| 76 |
+
*
|
| 77 |
+
* @return string
|
| 78 |
+
*/
|
| 79 |
+
public function fetchGroup()
|
| 80 |
+
{
|
| 81 |
+
return Mage::getModel('customer/group')->load(0)->getCode();
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
/**
|
| 85 |
+
* Fetch store view
|
| 86 |
+
*
|
| 87 |
+
* @return string
|
| 88 |
+
*/
|
| 89 |
+
public function fetchStoreView()
|
| 90 |
+
{
|
| 91 |
+
$store = Mage::getModel('core/store')->load($this->getStoreId());
|
| 92 |
+
|
| 93 |
+
return Mage::getModel('marketingsoftware/abstraction_storeview')->setOriginal($store);
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
/**
|
| 97 |
+
* Fetch subscriber customer Id
|
| 98 |
+
*
|
| 99 |
+
* @return string
|
| 100 |
+
*/
|
| 101 |
+
public function fetchCustomerId()
|
| 102 |
+
{
|
| 103 |
+
$store = Mage::getModel('core/store')->load($this->_subscriber->getStoreId());
|
| 104 |
+
|
| 105 |
+
$customer = Mage::getModel('customer/customer')->setWebsiteId($store->getWebsiteId())->loadByEmail($this->_subscriber->getEmail());
|
| 106 |
+
|
| 107 |
+
if ($customer->isObjectNew()) {
|
| 108 |
+
$identifier = $this->_subscriber->getEmail();
|
| 109 |
+
} else {
|
| 110 |
+
$identifier = $customer->getId();
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
return $identifier.'|'.$this->_subscriber->getStoreId();
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
/**
|
| 117 |
+
* Get subscribtion store Id
|
| 118 |
+
*
|
| 119 |
+
* @return int
|
| 120 |
+
*/
|
| 121 |
+
public function getStoreId()
|
| 122 |
+
{
|
| 123 |
+
if($this->_subscriber->getStoreId()) {
|
| 124 |
+
return $this->_subscriber->getStoreId();
|
| 125 |
+
} else {
|
| 126 |
+
return 0;
|
| 127 |
+
}
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
/**
|
| 131 |
+
* Get REST subscription entity
|
| 132 |
+
*
|
| 133 |
+
* @return Copernica_MarketingSoftware_Model_Rest_Subscription
|
| 134 |
+
*/
|
| 135 |
+
public function getRestSubscription()
|
| 136 |
+
{
|
| 137 |
+
$restSubscription = Mage::getModel('marketingsoftware/rest_subscription');
|
| 138 |
+
$restSubscription->setSubscriptionEntity($this);
|
| 139 |
+
|
| 140 |
+
return $restSubscription;
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
/**
|
| 144 |
+
* Set subscription entity
|
| 145 |
+
*
|
| 146 |
+
* @param Mage_Newsletter_Model_Subscriber $subscriber
|
| 147 |
+
*/
|
| 148 |
+
public function setSubscription($subscriber)
|
| 149 |
+
{
|
| 150 |
+
$this->_subscriber = $subscriber;
|
| 151 |
+
}
|
| 152 |
}
|
app/code/community/Copernica/MarketingSoftware/Model/Copernica/Entity/Wishlist.php
CHANGED
|
@@ -1,99 +1,99 @@
|
|
| 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 |
-
* Bridge between magento wishlist and copernica subprofile
|
| 29 |
-
*/
|
| 30 |
-
class Copernica_MarketingSoftware_Model_Copernica_Entity_Wishlist extends Copernica_MarketingSoftware_Model_Copernica_Entity
|
| 31 |
-
{
|
| 32 |
-
/**
|
| 33 |
-
* Cached wishlist instance
|
| 34 |
-
*
|
| 35 |
-
* @var Mage_Wishlist_Model_Wishlist
|
| 36 |
-
*/
|
| 37 |
-
protected $_wishlist;
|
| 38 |
-
|
| 39 |
-
/**
|
| 40 |
-
* Cached wishlist items
|
| 41 |
-
*
|
| 42 |
-
* @var array
|
| 43 |
-
*/
|
| 44 |
-
protected $_wishlistItems;
|
| 45 |
-
|
| 46 |
-
/**
|
| 47 |
-
* Fetch wishlist Id
|
| 48 |
-
*
|
| 49 |
-
* @return string
|
| 50 |
-
*/
|
| 51 |
-
public function fetchId()
|
| 52 |
-
{
|
| 53 |
-
return $this->_wishlist->getId();
|
| 54 |
-
}
|
| 55 |
-
|
| 56 |
-
/**
|
| 57 |
-
* @return array
|
| 58 |
-
*/
|
| 59 |
-
public function getItems()
|
| 60 |
-
{
|
| 61 |
-
if (!is_null($this->_wishlistItems)) {
|
| 62 |
-
return $this->_wishlistItems;
|
| 63 |
-
}
|
| 64 |
-
|
| 65 |
-
$wishlistItems = array();
|
| 66 |
-
|
| 67 |
-
foreach ($this->_wishlist->getItemCollection() as $wishlistItem) {
|
| 68 |
-
$wishlistItemEntity = Mage::getModel('marketingsoftware/copernica_entity_wishlist_item');
|
| 69 |
-
$wishlistItemEntity->setWishlistItem($wishlistItem);
|
| 70 |
-
|
| 71 |
-
$wishlistItems[] = $wishlistItemEntity;
|
| 72 |
-
}
|
| 73 |
-
|
| 74 |
-
return $this->_wishlistItems = $wishlistItems;
|
| 75 |
-
}
|
| 76 |
-
|
| 77 |
-
/**
|
| 78 |
-
* Get REST wishlist entity
|
| 79 |
-
*
|
| 80 |
-
* @return Copernica_MarketingSoftware_Model_Rest_Wishlist
|
| 81 |
-
*/
|
| 82 |
-
public function getRestWishlist()
|
| 83 |
-
{
|
| 84 |
-
$restWishlist = Mage::getModel('marketingsoftware/rest_wishlist');
|
| 85 |
-
$restWishlist->setWishlistEntity($this);
|
| 86 |
-
|
| 87 |
-
return $restWishlist;
|
| 88 |
-
}
|
| 89 |
-
|
| 90 |
-
/**
|
| 91 |
-
* Set wishlist entity
|
| 92 |
-
*
|
| 93 |
-
* @param Mage_Wishlist_Model_Wishlist $wishlist
|
| 94 |
-
*/
|
| 95 |
-
public function setWishlist(Mage_Wishlist_Model_Wishlist $wishlist)
|
| 96 |
-
{
|
| 97 |
-
$this->_wishlist = $wishlist;
|
| 98 |
-
}
|
| 99 |
}
|
| 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 |
+
* Bridge between magento wishlist and copernica subprofile
|
| 29 |
+
*/
|
| 30 |
+
class Copernica_MarketingSoftware_Model_Copernica_Entity_Wishlist extends Copernica_MarketingSoftware_Model_Copernica_Entity
|
| 31 |
+
{
|
| 32 |
+
/**
|
| 33 |
+
* Cached wishlist instance
|
| 34 |
+
*
|
| 35 |
+
* @var Mage_Wishlist_Model_Wishlist
|
| 36 |
+
*/
|
| 37 |
+
protected $_wishlist;
|
| 38 |
+
|
| 39 |
+
/**
|
| 40 |
+
* Cached wishlist items
|
| 41 |
+
*
|
| 42 |
+
* @var array
|
| 43 |
+
*/
|
| 44 |
+
protected $_wishlistItems;
|
| 45 |
+
|
| 46 |
+
/**
|
| 47 |
+
* Fetch wishlist Id
|
| 48 |
+
*
|
| 49 |
+
* @return string
|
| 50 |
+
*/
|
| 51 |
+
public function fetchId()
|
| 52 |
+
{
|
| 53 |
+
return $this->_wishlist->getId();
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
/**
|
| 57 |
+
* @return array
|
| 58 |
+
*/
|
| 59 |
+
public function getItems()
|
| 60 |
+
{
|
| 61 |
+
if (!is_null($this->_wishlistItems)) {
|
| 62 |
+
return $this->_wishlistItems;
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
$wishlistItems = array();
|
| 66 |
+
|
| 67 |
+
foreach ($this->_wishlist->getItemCollection() as $wishlistItem) {
|
| 68 |
+
$wishlistItemEntity = Mage::getModel('marketingsoftware/copernica_entity_wishlist_item');
|
| 69 |
+
$wishlistItemEntity->setWishlistItem($wishlistItem);
|
| 70 |
+
|
| 71 |
+
$wishlistItems[] = $wishlistItemEntity;
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
return $this->_wishlistItems = $wishlistItems;
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
/**
|
| 78 |
+
* Get REST wishlist entity
|
| 79 |
+
*
|
| 80 |
+
* @return Copernica_MarketingSoftware_Model_Rest_Wishlist
|
| 81 |
+
*/
|
| 82 |
+
public function getRestWishlist()
|
| 83 |
+
{
|
| 84 |
+
$restWishlist = Mage::getModel('marketingsoftware/rest_wishlist');
|
| 85 |
+
$restWishlist->setWishlistEntity($this);
|
| 86 |
+
|
| 87 |
+
return $restWishlist;
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
/**
|
| 91 |
+
* Set wishlist entity
|
| 92 |
+
*
|
| 93 |
+
* @param Mage_Wishlist_Model_Wishlist $wishlist
|
| 94 |
+
*/
|
| 95 |
+
public function setWishlist(Mage_Wishlist_Model_Wishlist $wishlist)
|
| 96 |
+
{
|
| 97 |
+
$this->_wishlist = $wishlist;
|
| 98 |
+
}
|
| 99 |
}
|
app/code/community/Copernica/MarketingSoftware/Model/Copernica/Entity/Wishlist/Item.php
CHANGED
|
@@ -1,155 +1,155 @@
|
|
| 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 |
-
* Brigde class between Copernica subprofile and magento wishlist item
|
| 29 |
-
*/
|
| 30 |
-
class Copernica_MarketingSoftware_Model_Copernica_Entity_Wishlist_Item extends Copernica_MarketingSoftware_Model_Copernica_Entity_Product
|
| 31 |
-
{
|
| 32 |
-
/**
|
| 33 |
-
* Cached item
|
| 34 |
-
*
|
| 35 |
-
* @var Mage_Wishlist_Model_Item
|
| 36 |
-
*/
|
| 37 |
-
protected $_wishlistItem = null;
|
| 38 |
-
|
| 39 |
-
/**
|
| 40 |
-
* Fetch wishlist item Id
|
| 41 |
-
*
|
| 42 |
-
* @return string
|
| 43 |
-
*/
|
| 44 |
-
public function fetchId()
|
| 45 |
-
{
|
| 46 |
-
return $this->_wishlistItem->getId();
|
| 47 |
-
}
|
| 48 |
-
|
| 49 |
-
/**
|
| 50 |
-
* Fetch wishlist Id
|
| 51 |
-
*
|
| 52 |
-
* @return string
|
| 53 |
-
*/
|
| 54 |
-
public function fetchWishlistId()
|
| 55 |
-
{
|
| 56 |
-
return $this->_wishlistItem->getWishlistId();
|
| 57 |
-
}
|
| 58 |
-
|
| 59 |
-
/**
|
| 60 |
-
* Fetch quantity
|
| 61 |
-
*
|
| 62 |
-
* @return string
|
| 63 |
-
*/
|
| 64 |
-
public function fetchDescription()
|
| 65 |
-
{
|
| 66 |
-
return $this->_wishlistItem->getDescription();
|
| 67 |
-
}
|
| 68 |
-
|
| 69 |
-
/**
|
| 70 |
-
* Fetch quantity
|
| 71 |
-
*
|
| 72 |
-
* @return string
|
| 73 |
-
*/
|
| 74 |
-
public function fetchQuantity()
|
| 75 |
-
{
|
| 76 |
-
return $this->_wishlistItem->getQty();
|
| 77 |
-
}
|
| 78 |
-
|
| 79 |
-
/**
|
| 80 |
-
* Fetch total
|
| 81 |
-
*
|
| 82 |
-
* @return string
|
| 83 |
-
*/
|
| 84 |
-
public function fetchTotalPrice()
|
| 85 |
-
{
|
| 86 |
-
return $this->_wishlistItem->getProduct()->getPrice() * $this->getQuantity();
|
| 87 |
-
}
|
| 88 |
-
|
| 89 |
-
/**
|
| 90 |
-
* Fetch price
|
| 91 |
-
*
|
| 92 |
-
* @return string
|
| 93 |
-
*/
|
| 94 |
-
public function fetchPrice()
|
| 95 |
-
{
|
| 96 |
-
return $this->_wishlistItem->getProduct()->getPrice();
|
| 97 |
-
}
|
| 98 |
-
|
| 99 |
-
/**
|
| 100 |
-
* Fetch timestamp
|
| 101 |
-
*
|
| 102 |
-
* @return string
|
| 103 |
-
*/
|
| 104 |
-
public function fetchTimestamp()
|
| 105 |
-
{
|
| 106 |
-
return $this->_wishlistItem->getAddedAt();
|
| 107 |
-
}
|
| 108 |
-
|
| 109 |
-
/**
|
| 110 |
-
* Fetch store view
|
| 111 |
-
*
|
| 112 |
-
* @return string
|
| 113 |
-
*/
|
| 114 |
-
public function fetchStoreView()
|
| 115 |
-
{
|
| 116 |
-
$store = Mage::getModel('core/store')->load($this->getStoreId());
|
| 117 |
-
|
| 118 |
-
return Mage::getModel('marketingsoftware/abstraction_storeview')->setOriginal($store);
|
| 119 |
-
}
|
| 120 |
-
|
| 121 |
-
/**
|
| 122 |
-
* Get store Id
|
| 123 |
-
*
|
| 124 |
-
* @return int
|
| 125 |
-
*/
|
| 126 |
-
public function getStoreId()
|
| 127 |
-
{
|
| 128 |
-
return $this->_wishlistItem->getStoreId();
|
| 129 |
-
}
|
| 130 |
-
|
| 131 |
-
/**
|
| 132 |
-
* Get REST wishlist item entity
|
| 133 |
-
*
|
| 134 |
-
* @return Copernica_MarketingSoftware_Model_Rest_Wishlist_Item
|
| 135 |
-
*/
|
| 136 |
-
public function getRestWishlistItem()
|
| 137 |
-
{
|
| 138 |
-
$restWishlistItem = Mage::getModel('marketingsoftware/rest_wishlist_item');
|
| 139 |
-
$restWishlistItem->setWishlistItemEntity($this);
|
| 140 |
-
|
| 141 |
-
return $restWishlistItem;
|
| 142 |
-
}
|
| 143 |
-
|
| 144 |
-
/**
|
| 145 |
-
* Set copernica wishlist item
|
| 146 |
-
*
|
| 147 |
-
* @param Mage_Wishlist_Model_Item $wishlistItem
|
| 148 |
-
*/
|
| 149 |
-
public function setWishlistItem(Mage_Wishlist_Model_Item $wishlistItem)
|
| 150 |
-
{
|
| 151 |
-
$this->_wishlistItem = $wishlistItem;
|
| 152 |
-
|
| 153 |
-
$this->setProduct($wishlistItem->getProductId());
|
| 154 |
-
}
|
| 155 |
}
|
| 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 |
+
* Brigde class between Copernica subprofile and magento wishlist item
|
| 29 |
+
*/
|
| 30 |
+
class Copernica_MarketingSoftware_Model_Copernica_Entity_Wishlist_Item extends Copernica_MarketingSoftware_Model_Copernica_Entity_Product
|
| 31 |
+
{
|
| 32 |
+
/**
|
| 33 |
+
* Cached item
|
| 34 |
+
*
|
| 35 |
+
* @var Mage_Wishlist_Model_Item
|
| 36 |
+
*/
|
| 37 |
+
protected $_wishlistItem = null;
|
| 38 |
+
|
| 39 |
+
/**
|
| 40 |
+
* Fetch wishlist item Id
|
| 41 |
+
*
|
| 42 |
+
* @return string
|
| 43 |
+
*/
|
| 44 |
+
public function fetchId()
|
| 45 |
+
{
|
| 46 |
+
return $this->_wishlistItem->getId();
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
/**
|
| 50 |
+
* Fetch wishlist Id
|
| 51 |
+
*
|
| 52 |
+
* @return string
|
| 53 |
+
*/
|
| 54 |
+
public function fetchWishlistId()
|
| 55 |
+
{
|
| 56 |
+
return $this->_wishlistItem->getWishlistId();
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
/**
|
| 60 |
+
* Fetch quantity
|
| 61 |
+
*
|
| 62 |
+
* @return string
|
| 63 |
+
*/
|
| 64 |
+
public function fetchDescription()
|
| 65 |
+
{
|
| 66 |
+
return $this->_wishlistItem->getDescription();
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
/**
|
| 70 |
+
* Fetch quantity
|
| 71 |
+
*
|
| 72 |
+
* @return string
|
| 73 |
+
*/
|
| 74 |
+
public function fetchQuantity()
|
| 75 |
+
{
|
| 76 |
+
return $this->_wishlistItem->getQty();
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
/**
|
| 80 |
+
* Fetch total
|
| 81 |
+
*
|
| 82 |
+
* @return string
|
| 83 |
+
*/
|
| 84 |
+
public function fetchTotalPrice()
|
| 85 |
+
{
|
| 86 |
+
return $this->_wishlistItem->getProduct()->getPrice() * $this->getQuantity();
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
/**
|
| 90 |
+
* Fetch price
|
| 91 |
+
*
|
| 92 |
+
* @return string
|
| 93 |
+
*/
|
| 94 |
+
public function fetchPrice()
|
| 95 |
+
{
|
| 96 |
+
return $this->_wishlistItem->getProduct()->getPrice();
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
/**
|
| 100 |
+
* Fetch timestamp
|
| 101 |
+
*
|
| 102 |
+
* @return string
|
| 103 |
+
*/
|
| 104 |
+
public function fetchTimestamp()
|
| 105 |
+
{
|
| 106 |
+
return $this->_wishlistItem->getAddedAt();
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
/**
|
| 110 |
+
* Fetch store view
|
| 111 |
+
*
|
| 112 |
+
* @return string
|
| 113 |
+
*/
|
| 114 |
+
public function fetchStoreView()
|
| 115 |
+
{
|
| 116 |
+
$store = Mage::getModel('core/store')->load($this->getStoreId());
|
| 117 |
+
|
| 118 |
+
return Mage::getModel('marketingsoftware/abstraction_storeview')->setOriginal($store);
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
/**
|
| 122 |
+
* Get store Id
|
| 123 |
+
*
|
| 124 |
+
* @return int
|
| 125 |
+
*/
|
| 126 |
+
public function getStoreId()
|
| 127 |
+
{
|
| 128 |
+
return $this->_wishlistItem->getStoreId();
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
/**
|
| 132 |
+
* Get REST wishlist item entity
|
| 133 |
+
*
|
| 134 |
+
* @return Copernica_MarketingSoftware_Model_Rest_Wishlist_Item
|
| 135 |
+
*/
|
| 136 |
+
public function getRestWishlistItem()
|
| 137 |
+
{
|
| 138 |
+
$restWishlistItem = Mage::getModel('marketingsoftware/rest_wishlist_item');
|
| 139 |
+
$restWishlistItem->setWishlistItemEntity($this);
|
| 140 |
+
|
| 141 |
+
return $restWishlistItem;
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
/**
|
| 145 |
+
* Set copernica wishlist item
|
| 146 |
+
*
|
| 147 |
+
* @param Mage_Wishlist_Model_Item $wishlistItem
|
| 148 |
+
*/
|
| 149 |
+
public function setWishlistItem(Mage_Wishlist_Model_Item $wishlistItem)
|
| 150 |
+
{
|
| 151 |
+
$this->_wishlistItem = $wishlistItem;
|
| 152 |
+
|
| 153 |
+
$this->setProduct($wishlistItem->getProductId());
|
| 154 |
+
}
|
| 155 |
}
|
app/code/community/Copernica/MarketingSoftware/Model/Copernica/Orderitem/Subprofile.php
CHANGED
|
@@ -1,132 +1,132 @@
|
|
| 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_Orderitem_Subprofile extends Copernica_MarketingSoftware_Model_Copernica_Abstract
|
| 31 |
-
{
|
| 32 |
-
/**
|
| 33 |
-
* @var Copernica_MarketingSoftware_Model_Abstraction_Order_Item
|
| 34 |
-
*/
|
| 35 |
-
protected $_orderItem = false;
|
| 36 |
-
|
| 37 |
-
/**
|
| 38 |
-
* Return the identifier for this profile
|
| 39 |
-
*
|
| 40 |
-
* @return string
|
| 41 |
-
*/
|
| 42 |
-
public function id()
|
| 43 |
-
{
|
| 44 |
-
return $this['item_id'];
|
| 45 |
-
}
|
| 46 |
-
|
| 47 |
-
/**
|
| 48 |
-
* Try to store a quote item
|
| 49 |
-
*
|
| 50 |
-
* @return Copernica_MarketingSoftware_Model_Copernica_Orderitem_Subprofile
|
| 51 |
-
*/
|
| 52 |
-
public function setOrderItem($item)
|
| 53 |
-
{
|
| 54 |
-
$this->_orderItem = $item;
|
| 55 |
-
|
| 56 |
-
return $this;
|
| 57 |
-
}
|
| 58 |
-
|
| 59 |
-
/**
|
| 60 |
-
* Get linked fields
|
| 61 |
-
*
|
| 62 |
-
* @return array
|
| 63 |
-
*/
|
| 64 |
-
public function linkedFields()
|
| 65 |
-
{
|
| 66 |
-
return Mage::helper('marketingsoftware/config')->getLinkedOrderItemFields();
|
| 67 |
-
}
|
| 68 |
-
|
| 69 |
-
/**
|
| 70 |
-
* Get the required fields
|
| 71 |
-
*
|
| 72 |
-
* @return array
|
| 73 |
-
*/
|
| 74 |
-
public function requiredFields()
|
| 75 |
-
{
|
| 76 |
-
return array('item_id','order_id');
|
| 77 |
-
}
|
| 78 |
-
|
| 79 |
-
/**
|
| 80 |
-
* Retrieve the data for this object
|
| 81 |
-
*
|
| 82 |
-
* @return array
|
| 83 |
-
*/
|
| 84 |
-
protected function _data()
|
| 85 |
-
{
|
| 86 |
-
$orderItem = $this->_orderItem;
|
| 87 |
-
|
| 88 |
-
$product = $orderItem->product();
|
| 89 |
-
|
| 90 |
-
$data = array(
|
| 91 |
-
'item_id' => $orderItem->id(),
|
| 92 |
-
'product_id' => $product->id(),
|
| 93 |
-
'name' => $product->name(),
|
| 94 |
-
'sku' => $product->sku(),
|
| 95 |
-
'attribute_set' => $product->attributeSet(),
|
| 96 |
-
'attributes' => (string)$product->attributes(),
|
| 97 |
-
'weight' => $orderItem->weight(),
|
| 98 |
-
'quantity' => $orderItem->quantity(),
|
| 99 |
-
'timestamp' => $orderItem->timestamp(),
|
| 100 |
-
'options' => (string)$orderItem->options()
|
| 101 |
-
);
|
| 102 |
-
|
| 103 |
-
$order = $orderItem->order();
|
| 104 |
-
|
| 105 |
-
if (is_object($order)) {
|
| 106 |
-
$data['order_id'] = $order->id();
|
| 107 |
-
$data['increment_id'] = $order->incrementId();
|
| 108 |
-
|
| 109 |
-
$storeView = $order->storeView();
|
| 110 |
-
$storeId = $storeView->id();
|
| 111 |
-
|
| 112 |
-
$data['store_view'] = (string)$storeView;
|
| 113 |
-
$data['url'] = $product->productUrl($storeId);
|
| 114 |
-
$data['image'] = $product->imageUrl($storeId);
|
| 115 |
-
} else {
|
| 116 |
-
$data['order_id'] = null;
|
| 117 |
-
}
|
| 118 |
-
|
| 119 |
-
$price = $orderItem->price();
|
| 120 |
-
|
| 121 |
-
if (is_object($price)) {
|
| 122 |
-
$data['price'] = $price->itemPrice();
|
| 123 |
-
$data['total_price'] = $price->total();
|
| 124 |
-
}
|
| 125 |
-
|
| 126 |
-
$data['categories'] = implode("\n", array_map(function($category) {
|
| 127 |
-
return implode(' > ', $category);
|
| 128 |
-
}, $product->categories()));
|
| 129 |
-
|
| 130 |
-
return $data;
|
| 131 |
-
}
|
| 132 |
}
|
| 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_Orderitem_Subprofile extends Copernica_MarketingSoftware_Model_Copernica_Abstract
|
| 31 |
+
{
|
| 32 |
+
/**
|
| 33 |
+
* @var Copernica_MarketingSoftware_Model_Abstraction_Order_Item
|
| 34 |
+
*/
|
| 35 |
+
protected $_orderItem = false;
|
| 36 |
+
|
| 37 |
+
/**
|
| 38 |
+
* Return the identifier for this profile
|
| 39 |
+
*
|
| 40 |
+
* @return string
|
| 41 |
+
*/
|
| 42 |
+
public function id()
|
| 43 |
+
{
|
| 44 |
+
return $this['item_id'];
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
/**
|
| 48 |
+
* Try to store a quote item
|
| 49 |
+
*
|
| 50 |
+
* @return Copernica_MarketingSoftware_Model_Copernica_Orderitem_Subprofile
|
| 51 |
+
*/
|
| 52 |
+
public function setOrderItem($item)
|
| 53 |
+
{
|
| 54 |
+
$this->_orderItem = $item;
|
| 55 |
+
|
| 56 |
+
return $this;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
/**
|
| 60 |
+
* Get linked fields
|
| 61 |
+
*
|
| 62 |
+
* @return array
|
| 63 |
+
*/
|
| 64 |
+
public function linkedFields()
|
| 65 |
+
{
|
| 66 |
+
return Mage::helper('marketingsoftware/config')->getLinkedOrderItemFields();
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
/**
|
| 70 |
+
* Get the required fields
|
| 71 |
+
*
|
| 72 |
+
* @return array
|
| 73 |
+
*/
|
| 74 |
+
public function requiredFields()
|
| 75 |
+
{
|
| 76 |
+
return array('item_id','order_id');
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
/**
|
| 80 |
+
* Retrieve the data for this object
|
| 81 |
+
*
|
| 82 |
+
* @return array
|
| 83 |
+
*/
|
| 84 |
+
protected function _data()
|
| 85 |
+
{
|
| 86 |
+
$orderItem = $this->_orderItem;
|
| 87 |
+
|
| 88 |
+
$product = $orderItem->product();
|
| 89 |
+
|
| 90 |
+
$data = array(
|
| 91 |
+
'item_id' => $orderItem->id(),
|
| 92 |
+
'product_id' => $product->id(),
|
| 93 |
+
'name' => $product->name(),
|
| 94 |
+
'sku' => $product->sku(),
|
| 95 |
+
'attribute_set' => $product->attributeSet(),
|
| 96 |
+
'attributes' => (string)$product->attributes(),
|
| 97 |
+
'weight' => $orderItem->weight(),
|
| 98 |
+
'quantity' => $orderItem->quantity(),
|
| 99 |
+
'timestamp' => $orderItem->timestamp(),
|
| 100 |
+
'options' => (string)$orderItem->options()
|
| 101 |
+
);
|
| 102 |
+
|
| 103 |
+
$order = $orderItem->order();
|
| 104 |
+
|
| 105 |
+
if (is_object($order)) {
|
| 106 |
+
$data['order_id'] = $order->id();
|
| 107 |
+
$data['increment_id'] = $order->incrementId();
|
| 108 |
+
|
| 109 |
+
$storeView = $order->storeView();
|
| 110 |
+
$storeId = $storeView->id();
|
| 111 |
+
|
| 112 |
+
$data['store_view'] = (string)$storeView;
|
| 113 |
+
$data['url'] = $product->productUrl($storeId);
|
| 114 |
+
$data['image'] = $product->imageUrl($storeId);
|
| 115 |
+
} else {
|
| 116 |
+
$data['order_id'] = null;
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
$price = $orderItem->price();
|
| 120 |
+
|
| 121 |
+
if (is_object($price)) {
|
| 122 |
+
$data['price'] = $price->itemPrice();
|
| 123 |
+
$data['total_price'] = $price->total();
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
$data['categories'] = implode("\n", array_map(function($category) {
|
| 127 |
+
return implode(' > ', $category);
|
| 128 |
+
}, $product->categories()));
|
| 129 |
+
|
| 130 |
+
return $data;
|
| 131 |
+
}
|
| 132 |
}
|
app/code/community/Copernica/MarketingSoftware/Model/Copernica/Product/Viewed/Subprofile.php
CHANGED
|
@@ -1,118 +1,118 @@
|
|
| 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_Product_Viewed_Subprofile extends Copernica_MarketingSoftware_Model_Copernica_Abstract
|
| 31 |
-
{
|
| 32 |
-
/**
|
| 33 |
-
* @var Copernica_MarketingSoftware_Model_Abstraction_Product_Viewed
|
| 34 |
-
*/
|
| 35 |
-
protected $_viewedProduct = false;
|
| 36 |
-
|
| 37 |
-
/**
|
| 38 |
-
* Return the identifier for this profile
|
| 39 |
-
*
|
| 40 |
-
* @return string
|
| 41 |
-
*/
|
| 42 |
-
public function id()
|
| 43 |
-
{
|
| 44 |
-
return $this->_viewedProduct->id;
|
| 45 |
-
}
|
| 46 |
-
|
| 47 |
-
public function customerId()
|
| 48 |
-
{
|
| 49 |
-
return $this->_viewedProduct->customerId;
|
| 50 |
-
}
|
| 51 |
-
|
| 52 |
-
/**
|
| 53 |
-
* Try to store a quote item
|
| 54 |
-
*
|
| 55 |
-
* @param Copernica_MarketingSoftware_Model_Abstraction_Product_Viewed $product
|
| 56 |
-
*/
|
| 57 |
-
public function setViewedProduct(Copernica_MarketingSoftware_Model_Abstraction_Product_Viewed $product)
|
| 58 |
-
{
|
| 59 |
-
$this->_viewedProduct = $product;
|
| 60 |
-
|
| 61 |
-
return $this;
|
| 62 |
-
}
|
| 63 |
-
|
| 64 |
-
/**
|
| 65 |
-
* Get linked fields
|
| 66 |
-
*
|
| 67 |
-
* @return array
|
| 68 |
-
*/
|
| 69 |
-
public function linkedFields()
|
| 70 |
-
{
|
| 71 |
-
return Mage::helper('marketingsoftware/config')->getLinkedViewedProductFields();
|
| 72 |
-
}
|
| 73 |
-
|
| 74 |
-
/**
|
| 75 |
-
* Get the required fields
|
| 76 |
-
*
|
| 77 |
-
* @return array
|
| 78 |
-
*/
|
| 79 |
-
public function requiredFields()
|
| 80 |
-
{
|
| 81 |
-
return array('product_id');
|
| 82 |
-
}
|
| 83 |
-
|
| 84 |
-
/**
|
| 85 |
-
* Retrieve the data for this object
|
| 86 |
-
*
|
| 87 |
-
* @return array
|
| 88 |
-
*/
|
| 89 |
-
protected function _data()
|
| 90 |
-
{
|
| 91 |
-
$product = $this->_viewedProduct;
|
| 92 |
-
|
| 93 |
-
$storeId = $product->storeId;
|
| 94 |
-
|
| 95 |
-
$categories = array();
|
| 96 |
-
|
| 97 |
-
if ($product->categories()) {
|
| 98 |
-
foreach ($product->categories() as $category) {
|
| 99 |
-
$categories[] = implode(' > ', $category);
|
| 100 |
-
}
|
| 101 |
-
}
|
| 102 |
-
|
| 103 |
-
return array(
|
| 104 |
-
'product_id' => $product->id(),
|
| 105 |
-
'price' => $product->price(),
|
| 106 |
-
'name' => $product->name(),
|
| 107 |
-
'sku' => $product->sku(),
|
| 108 |
-
'attribute_set' => $product->attributeSet(),
|
| 109 |
-
'weight' => $product->weight(),
|
| 110 |
-
'total_price' => $product->price(),
|
| 111 |
-
'url' => $product->productUrl($storeId),
|
| 112 |
-
'image' => $product->imageUrl($storeId),
|
| 113 |
-
'categories' => implode("\n", $categories),
|
| 114 |
-
'attributes' => (string)$product->attributes(),
|
| 115 |
-
'timestamp' => $product->timestamp()
|
| 116 |
-
);
|
| 117 |
-
}
|
| 118 |
}
|
| 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_Product_Viewed_Subprofile extends Copernica_MarketingSoftware_Model_Copernica_Abstract
|
| 31 |
+
{
|
| 32 |
+
/**
|
| 33 |
+
* @var Copernica_MarketingSoftware_Model_Abstraction_Product_Viewed
|
| 34 |
+
*/
|
| 35 |
+
protected $_viewedProduct = false;
|
| 36 |
+
|
| 37 |
+
/**
|
| 38 |
+
* Return the identifier for this profile
|
| 39 |
+
*
|
| 40 |
+
* @return string
|
| 41 |
+
*/
|
| 42 |
+
public function id()
|
| 43 |
+
{
|
| 44 |
+
return $this->_viewedProduct->id;
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
public function customerId()
|
| 48 |
+
{
|
| 49 |
+
return $this->_viewedProduct->customerId;
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
/**
|
| 53 |
+
* Try to store a quote item
|
| 54 |
+
*
|
| 55 |
+
* @param Copernica_MarketingSoftware_Model_Abstraction_Product_Viewed $product
|
| 56 |
+
*/
|
| 57 |
+
public function setViewedProduct(Copernica_MarketingSoftware_Model_Abstraction_Product_Viewed $product)
|
| 58 |
+
{
|
| 59 |
+
$this->_viewedProduct = $product;
|
| 60 |
+
|
| 61 |
+
return $this;
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
/**
|
| 65 |
+
* Get linked fields
|
| 66 |
+
*
|
| 67 |
+
* @return array
|
| 68 |
+
*/
|
| 69 |
+
public function linkedFields()
|
| 70 |
+
{
|
| 71 |
+
return Mage::helper('marketingsoftware/config')->getLinkedViewedProductFields();
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
/**
|
| 75 |
+
* Get the required fields
|
| 76 |
+
*
|
| 77 |
+
* @return array
|
| 78 |
+
*/
|
| 79 |
+
public function requiredFields()
|
| 80 |
+
{
|
| 81 |
+
return array('product_id');
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
/**
|
| 85 |
+
* Retrieve the data for this object
|
| 86 |
+
*
|
| 87 |
+
* @return array
|
| 88 |
+
*/
|
| 89 |
+
protected function _data()
|
| 90 |
+
{
|
| 91 |
+
$product = $this->_viewedProduct;
|
| 92 |
+
|
| 93 |
+
$storeId = $product->storeId;
|
| 94 |
+
|
| 95 |
+
$categories = array();
|
| 96 |
+
|
| 97 |
+
if ($product->categories()) {
|
| 98 |
+
foreach ($product->categories() as $category) {
|
| 99 |
+
$categories[] = implode(' > ', $category);
|
| 100 |
+
}
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
return array(
|
| 104 |
+
'product_id' => $product->id(),
|
| 105 |
+
'price' => $product->price(),
|
| 106 |
+
'name' => $product->name(),
|
| 107 |
+
'sku' => $product->sku(),
|
| 108 |
+
'attribute_set' => $product->attributeSet(),
|
| 109 |
+
'weight' => $product->weight(),
|
| 110 |
+
'total_price' => $product->price(),
|
| 111 |
+
'url' => $product->productUrl($storeId),
|
| 112 |
+
'image' => $product->imageUrl($storeId),
|
| 113 |
+
'categories' => implode("\n", $categories),
|
| 114 |
+
'attributes' => (string)$product->attributes(),
|
| 115 |
+
'timestamp' => $product->timestamp()
|
| 116 |
+
);
|
| 117 |
+
}
|
| 118 |
}
|
app/code/community/Copernica/MarketingSoftware/Model/Copernica/Profile/Customer.php
CHANGED
|
@@ -1,119 +1,119 @@
|
|
| 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_Profile_Customer extends Copernica_MarketingSoftware_Model_Copernica_Profile
|
| 31 |
-
{
|
| 32 |
-
/**
|
| 33 |
-
* @var Copernica_MarketingSoftware_Model_Abstraction_Customer
|
| 34 |
-
*/
|
| 35 |
-
protected $_customer = false;
|
| 36 |
-
|
| 37 |
-
/**
|
| 38 |
-
* Set the customer object to this object
|
| 39 |
-
*
|
| 40 |
-
* @param Copernica_MarketingSoftware_Model_Abstraction_Customer $customer
|
| 41 |
-
* @return Copernica_MarketingSoftware_Model_Copernica_Profile_Customer
|
| 42 |
-
*/
|
| 43 |
-
public function setCustomer(Copernica_MarketingSoftware_Model_Abstraction_Customer $customer)
|
| 44 |
-
{
|
| 45 |
-
$this->_customer = $customer;
|
| 46 |
-
|
| 47 |
-
return $this;
|
| 48 |
-
}
|
| 49 |
-
|
| 50 |
-
/**
|
| 51 |
-
* Returns customer_id based on the original (previous) email, if possible.
|
| 52 |
-
* Falls back on the customer_id using the current email.
|
| 53 |
-
*
|
| 54 |
-
* @return string
|
| 55 |
-
*/
|
| 56 |
-
public function originalId()
|
| 57 |
-
{
|
| 58 |
-
return Mage::helper('marketingsoftware/profile')->getCustomerCopernicaId($this->_customer, $this->_customer->storeview());
|
| 59 |
-
}
|
| 60 |
-
|
| 61 |
-
/**
|
| 62 |
-
* Get profile email.
|
| 63 |
-
*
|
| 64 |
-
* @return string
|
| 65 |
-
*/
|
| 66 |
-
public function email()
|
| 67 |
-
{
|
| 68 |
-
return $this->_customer->email();
|
| 69 |
-
}
|
| 70 |
-
|
| 71 |
-
/**
|
| 72 |
-
* Return store view associated with profile.
|
| 73 |
-
*
|
| 74 |
-
* @return string
|
| 75 |
-
*/
|
| 76 |
-
public function storeView()
|
| 77 |
-
{
|
| 78 |
-
return (string)$this->_customer->storeview();
|
| 79 |
-
}
|
| 80 |
-
|
| 81 |
-
/**
|
| 82 |
-
* Retrieve the data for this object
|
| 83 |
-
*
|
| 84 |
-
* @return array
|
| 85 |
-
*/
|
| 86 |
-
protected function _data()
|
| 87 |
-
{
|
| 88 |
-
$subscription = $this->_customer->subscription();
|
| 89 |
-
|
| 90 |
-
$name = $this->_customer->name();
|
| 91 |
-
|
| 92 |
-
$email = $this->_customer->email();
|
| 93 |
-
|
| 94 |
-
$storeview = $this->_customer->storeview();
|
| 95 |
-
|
| 96 |
-
$customerId = Mage::helper('marketingsoftware/profile')->getCustomerCopernicaId($this->_customer, $storeview);
|
| 97 |
-
|
| 98 |
-
$customerBirthDate = $this->_customer->birthDate();
|
| 99 |
-
|
| 100 |
-
if(is_object($customerBirthDate))
|
| 101 |
-
$birthDate = $customerBirthDate->gmtDate();
|
| 102 |
-
elseif(is_string($customerBirthDate) && strtotime($customerBirthDate))
|
| 103 |
-
$birthDate = $customerBirthDate;
|
| 104 |
-
else $birthDate = '0000-00-00';
|
| 105 |
-
|
| 106 |
-
return array(
|
| 107 |
-
'customer_id' => $customerId,
|
| 108 |
-
'store_view' => (string)$storeview,
|
| 109 |
-
'firstname' => is_object($name) ? $name->firstname() : null,
|
| 110 |
-
'middlename' => is_object($name) ? $name->middlename() : null,
|
| 111 |
-
'lastname' => is_object($name) ? $name->lastname() : null,
|
| 112 |
-
'email' => $email,
|
| 113 |
-
'birthdate' => $birthDate,
|
| 114 |
-
'group' => $this->_customer->group(),
|
| 115 |
-
'newsletter' => is_object($subscription) ? $subscription->status() : 'unknown',
|
| 116 |
-
'gender' => $this->_customer->gender()
|
| 117 |
-
);
|
| 118 |
-
}
|
| 119 |
-
}
|
| 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_Profile_Customer extends Copernica_MarketingSoftware_Model_Copernica_Profile
|
| 31 |
+
{
|
| 32 |
+
/**
|
| 33 |
+
* @var Copernica_MarketingSoftware_Model_Abstraction_Customer
|
| 34 |
+
*/
|
| 35 |
+
protected $_customer = false;
|
| 36 |
+
|
| 37 |
+
/**
|
| 38 |
+
* Set the customer object to this object
|
| 39 |
+
*
|
| 40 |
+
* @param Copernica_MarketingSoftware_Model_Abstraction_Customer $customer
|
| 41 |
+
* @return Copernica_MarketingSoftware_Model_Copernica_Profile_Customer
|
| 42 |
+
*/
|
| 43 |
+
public function setCustomer(Copernica_MarketingSoftware_Model_Abstraction_Customer $customer)
|
| 44 |
+
{
|
| 45 |
+
$this->_customer = $customer;
|
| 46 |
+
|
| 47 |
+
return $this;
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
/**
|
| 51 |
+
* Returns customer_id based on the original (previous) email, if possible.
|
| 52 |
+
* Falls back on the customer_id using the current email.
|
| 53 |
+
*
|
| 54 |
+
* @return string
|
| 55 |
+
*/
|
| 56 |
+
public function originalId()
|
| 57 |
+
{
|
| 58 |
+
return Mage::helper('marketingsoftware/profile')->getCustomerCopernicaId($this->_customer, $this->_customer->storeview());
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
/**
|
| 62 |
+
* Get profile email.
|
| 63 |
+
*
|
| 64 |
+
* @return string
|
| 65 |
+
*/
|
| 66 |
+
public function email()
|
| 67 |
+
{
|
| 68 |
+
return $this->_customer->email();
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
/**
|
| 72 |
+
* Return store view associated with profile.
|
| 73 |
+
*
|
| 74 |
+
* @return string
|
| 75 |
+
*/
|
| 76 |
+
public function storeView()
|
| 77 |
+
{
|
| 78 |
+
return (string)$this->_customer->storeview();
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
/**
|
| 82 |
+
* Retrieve the data for this object
|
| 83 |
+
*
|
| 84 |
+
* @return array
|
| 85 |
+
*/
|
| 86 |
+
protected function _data()
|
| 87 |
+
{
|
| 88 |
+
$subscription = $this->_customer->subscription();
|
| 89 |
+
|
| 90 |
+
$name = $this->_customer->name();
|
| 91 |
+
|
| 92 |
+
$email = $this->_customer->email();
|
| 93 |
+
|
| 94 |
+
$storeview = $this->_customer->storeview();
|
| 95 |
+
|
| 96 |
+
$customerId = Mage::helper('marketingsoftware/profile')->getCustomerCopernicaId($this->_customer, $storeview);
|
| 97 |
+
|
| 98 |
+
$customerBirthDate = $this->_customer->birthDate();
|
| 99 |
+
|
| 100 |
+
if(is_object($customerBirthDate))
|
| 101 |
+
$birthDate = $customerBirthDate->gmtDate();
|
| 102 |
+
elseif(is_string($customerBirthDate) && strtotime($customerBirthDate))
|
| 103 |
+
$birthDate = $customerBirthDate;
|
| 104 |
+
else $birthDate = '0000-00-00';
|
| 105 |
+
|
| 106 |
+
return array(
|
| 107 |
+
'customer_id' => $customerId,
|
| 108 |
+
'store_view' => (string)$storeview,
|
| 109 |
+
'firstname' => is_object($name) ? $name->firstname() : null,
|
| 110 |
+
'middlename' => is_object($name) ? $name->middlename() : null,
|
| 111 |
+
'lastname' => is_object($name) ? $name->lastname() : null,
|
| 112 |
+
'email' => $email,
|
| 113 |
+
'birthdate' => $birthDate,
|
| 114 |
+
'group' => $this->_customer->group(),
|
| 115 |
+
'newsletter' => is_object($subscription) ? $subscription->status() : 'unknown',
|
| 116 |
+
'gender' => $this->_customer->gender()
|
| 117 |
+
);
|
| 118 |
+
}
|
| 119 |
+
}
|
app/code/community/Copernica/MarketingSoftware/Model/Copernica/Quote/Item/Subprofile.php
CHANGED
|
@@ -1,151 +1,151 @@
|
|
| 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_Quote_Item_Subprofile extends Copernica_MarketingSoftware_Model_Copernica_Abstract
|
| 31 |
-
{
|
| 32 |
-
/**
|
| 33 |
-
* @var Copernica_MarketingSoftware_Model_Abstraction_Quote_Item
|
| 34 |
-
*/
|
| 35 |
-
protected $_quoteItem = false;
|
| 36 |
-
|
| 37 |
-
/**
|
| 38 |
-
* @var string
|
| 39 |
-
*/
|
| 40 |
-
protected $_status = 'basket';
|
| 41 |
-
|
| 42 |
-
/**
|
| 43 |
-
* Set the status of this quote item
|
| 44 |
-
*
|
| 45 |
-
* @param string $status
|
| 46 |
-
* @return Copernica_MarketingSoftware_Model_Copernica_Quote_Item_Subprofile
|
| 47 |
-
*/
|
| 48 |
-
public function setStatus($status)
|
| 49 |
-
{
|
| 50 |
-
$this->_status = $status;
|
| 51 |
-
|
| 52 |
-
return $this;
|
| 53 |
-
}
|
| 54 |
-
|
| 55 |
-
/**
|
| 56 |
-
* Return the identifier for this profile
|
| 57 |
-
*
|
| 58 |
-
* @return string
|
| 59 |
-
*/
|
| 60 |
-
public function id()
|
| 61 |
-
{
|
| 62 |
-
return $this['item_id'];
|
| 63 |
-
}
|
| 64 |
-
|
| 65 |
-
/**
|
| 66 |
-
* Try to store a quote item
|
| 67 |
-
*
|
| 68 |
-
* @param Copernica_MarketingSoftware_Model_Abstraction_Quote_Item $item
|
| 69 |
-
* @return Copernica_MarketingSoftware_Model_Copernica_Quote_Item_Subprofile;
|
| 70 |
-
*/
|
| 71 |
-
public function setQuoteItem(Copernica_MarketingSoftware_Model_Abstraction_Quote_Item $item)
|
| 72 |
-
{
|
| 73 |
-
$this->_quoteItem = $item;
|
| 74 |
-
|
| 75 |
-
return $this;
|
| 76 |
-
}
|
| 77 |
-
|
| 78 |
-
/**
|
| 79 |
-
* Get linked fields
|
| 80 |
-
*
|
| 81 |
-
* @return array
|
| 82 |
-
*/
|
| 83 |
-
public function linkedFields()
|
| 84 |
-
{
|
| 85 |
-
return Mage::helper('marketingsoftware/config')->getLinkedQuoteItemFields();
|
| 86 |
-
}
|
| 87 |
-
|
| 88 |
-
/**
|
| 89 |
-
* Get the required fields
|
| 90 |
-
*
|
| 91 |
-
* @return array
|
| 92 |
-
*/
|
| 93 |
-
public function requiredFields()
|
| 94 |
-
{
|
| 95 |
-
return array('item_id', 'quote_id', 'status');
|
| 96 |
-
}
|
| 97 |
-
|
| 98 |
-
/**
|
| 99 |
-
* Retrieve the data for this object
|
| 100 |
-
*
|
| 101 |
-
* @return array
|
| 102 |
-
*/
|
| 103 |
-
protected function _data()
|
| 104 |
-
{
|
| 105 |
-
$quoteItem = $this->_quoteItem;
|
| 106 |
-
|
| 107 |
-
$product = $quoteItem->product();
|
| 108 |
-
|
| 109 |
-
$quote = $quoteItem->quote();
|
| 110 |
-
|
| 111 |
-
$data = array(
|
| 112 |
-
'item_id' => $quoteItem->id(),
|
| 113 |
-
'quote_id' => $quote->id(),
|
| 114 |
-
'product_id' => $product->id(),
|
| 115 |
-
'status' => $this->_status,
|
| 116 |
-
'name' => $product->name(),
|
| 117 |
-
'sku' => $product->sku(),
|
| 118 |
-
'attribute_set' => $product->attributeSet(),
|
| 119 |
-
'weight' => $quoteItem->weight(),
|
| 120 |
-
'quantity' => $quoteItem->quantity(),
|
| 121 |
-
'timestamp' => $quoteItem->timestamp(),
|
| 122 |
-
'attributes' => (string)$product->attributes(),
|
| 123 |
-
'options' => (string)$quoteItem->options()
|
| 124 |
-
);
|
| 125 |
-
|
| 126 |
-
$storeView = $quote->storeView();
|
| 127 |
-
|
| 128 |
-
if ($storeView) {
|
| 129 |
-
$storeId = $storeView->id();
|
| 130 |
-
|
| 131 |
-
$data['store_view'] = (string)$storeView;
|
| 132 |
-
$data['url'] = $product->productUrl($storeId);
|
| 133 |
-
$data['image'] = $product->imageUrl($storeId);
|
| 134 |
-
} else {
|
| 135 |
-
$data['store_view'] = '';
|
| 136 |
-
$data['url'] = '';
|
| 137 |
-
$data['image'] = '';
|
| 138 |
-
}
|
| 139 |
-
|
| 140 |
-
if ($price = $quoteItem->price()) {
|
| 141 |
-
$data['price'] = $price->itemPrice();
|
| 142 |
-
$data['total_price'] = $price->total();
|
| 143 |
-
}
|
| 144 |
-
|
| 145 |
-
$data['categories'] = implode("\n", array_map(function($category) {
|
| 146 |
-
return implode(' > ', $category);
|
| 147 |
-
}, $product->categories()));
|
| 148 |
-
|
| 149 |
-
return $data;
|
| 150 |
-
}
|
| 151 |
}
|
| 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_Quote_Item_Subprofile extends Copernica_MarketingSoftware_Model_Copernica_Abstract
|
| 31 |
+
{
|
| 32 |
+
/**
|
| 33 |
+
* @var Copernica_MarketingSoftware_Model_Abstraction_Quote_Item
|
| 34 |
+
*/
|
| 35 |
+
protected $_quoteItem = false;
|
| 36 |
+
|
| 37 |
+
/**
|
| 38 |
+
* @var string
|
| 39 |
+
*/
|
| 40 |
+
protected $_status = 'basket';
|
| 41 |
+
|
| 42 |
+
/**
|
| 43 |
+
* Set the status of this quote item
|
| 44 |
+
*
|
| 45 |
+
* @param string $status
|
| 46 |
+
* @return Copernica_MarketingSoftware_Model_Copernica_Quote_Item_Subprofile
|
| 47 |
+
*/
|
| 48 |
+
public function setStatus($status)
|
| 49 |
+
{
|
| 50 |
+
$this->_status = $status;
|
| 51 |
+
|
| 52 |
+
return $this;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
/**
|
| 56 |
+
* Return the identifier for this profile
|
| 57 |
+
*
|
| 58 |
+
* @return string
|
| 59 |
+
*/
|
| 60 |
+
public function id()
|
| 61 |
+
{
|
| 62 |
+
return $this['item_id'];
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
/**
|
| 66 |
+
* Try to store a quote item
|
| 67 |
+
*
|
| 68 |
+
* @param Copernica_MarketingSoftware_Model_Abstraction_Quote_Item $item
|
| 69 |
+
* @return Copernica_MarketingSoftware_Model_Copernica_Quote_Item_Subprofile;
|
| 70 |
+
*/
|
| 71 |
+
public function setQuoteItem(Copernica_MarketingSoftware_Model_Abstraction_Quote_Item $item)
|
| 72 |
+
{
|
| 73 |
+
$this->_quoteItem = $item;
|
| 74 |
+
|
| 75 |
+
return $this;
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
/**
|
| 79 |
+
* Get linked fields
|
| 80 |
+
*
|
| 81 |
+
* @return array
|
| 82 |
+
*/
|
| 83 |
+
public function linkedFields()
|
| 84 |
+
{
|
| 85 |
+
return Mage::helper('marketingsoftware/config')->getLinkedQuoteItemFields();
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
/**
|
| 89 |
+
* Get the required fields
|
| 90 |
+
*
|
| 91 |
+
* @return array
|
| 92 |
+
*/
|
| 93 |
+
public function requiredFields()
|
| 94 |
+
{
|
| 95 |
+
return array('item_id', 'quote_id', 'status');
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
/**
|
| 99 |
+
* Retrieve the data for this object
|
| 100 |
+
*
|
| 101 |
+
* @return array
|
| 102 |
+
*/
|
| 103 |
+
protected function _data()
|
| 104 |
+
{
|
| 105 |
+
$quoteItem = $this->_quoteItem;
|
| 106 |
+
|
| 107 |
+
$product = $quoteItem->product();
|
| 108 |
+
|
| 109 |
+
$quote = $quoteItem->quote();
|
| 110 |
+
|
| 111 |
+
$data = array(
|
| 112 |
+
'item_id' => $quoteItem->id(),
|
| 113 |
+
'quote_id' => $quote->id(),
|
| 114 |
+
'product_id' => $product->id(),
|
| 115 |
+
'status' => $this->_status,
|
| 116 |
+
'name' => $product->name(),
|
| 117 |
+
'sku' => $product->sku(),
|
| 118 |
+
'attribute_set' => $product->attributeSet(),
|
| 119 |
+
'weight' => $quoteItem->weight(),
|
| 120 |
+
'quantity' => $quoteItem->quantity(),
|
| 121 |
+
'timestamp' => $quoteItem->timestamp(),
|
| 122 |
+
'attributes' => (string)$product->attributes(),
|
| 123 |
+
'options' => (string)$quoteItem->options()
|
| 124 |
+
);
|
| 125 |
+
|
| 126 |
+
$storeView = $quote->storeView();
|
| 127 |
+
|
| 128 |
+
if ($storeView) {
|
| 129 |
+
$storeId = $storeView->id();
|
| 130 |
+
|
| 131 |
+
$data['store_view'] = (string)$storeView;
|
| 132 |
+
$data['url'] = $product->productUrl($storeId);
|
| 133 |
+
$data['image'] = $product->imageUrl($storeId);
|
| 134 |
+
} else {
|
| 135 |
+
$data['store_view'] = '';
|
| 136 |
+
$data['url'] = '';
|
| 137 |
+
$data['image'] = '';
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
if ($price = $quoteItem->price()) {
|
| 141 |
+
$data['price'] = $price->itemPrice();
|
| 142 |
+
$data['total_price'] = $price->total();
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
$data['categories'] = implode("\n", array_map(function($category) {
|
| 146 |
+
return implode(' > ', $category);
|
| 147 |
+
}, $product->categories()));
|
| 148 |
+
|
| 149 |
+
return $data;
|
| 150 |
+
}
|
| 151 |
}
|
app/code/community/Copernica/MarketingSoftware/Model/Copernica/Wishlist/Item/Subprofile.php
CHANGED
|
@@ -1,132 +1,132 @@
|
|
| 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_Wishlist_Item_Subprofile extends Copernica_MarketingSoftware_Model_Copernica_Abstract
|
| 31 |
-
{
|
| 32 |
-
/**
|
| 33 |
-
* @var Copernica_MarketingSoftware_Model_Abstraction_Wishlist_Item
|
| 34 |
-
*/
|
| 35 |
-
protected $_wishlistItem = false;
|
| 36 |
-
|
| 37 |
-
/**
|
| 38 |
-
* Return the identifier for this profile
|
| 39 |
-
*
|
| 40 |
-
* @return string
|
| 41 |
-
*/
|
| 42 |
-
public function id()
|
| 43 |
-
{
|
| 44 |
-
return $this['item_id'];
|
| 45 |
-
}
|
| 46 |
-
|
| 47 |
-
/**
|
| 48 |
-
* Try to store a wishlist item
|
| 49 |
-
*
|
| 50 |
-
* @param Copernica_MarketingSoftware_Model_Abstraction_Wishlist_Item $item
|
| 51 |
-
* @return Copernica_MarketingSoftware_Model_Copernica_Wishlist_Item_Subprofile;
|
| 52 |
-
*/
|
| 53 |
-
public function setWishlistItem(Copernica_MarketingSoftware_Model_Abstraction_Wishlist_Item $item)
|
| 54 |
-
{
|
| 55 |
-
$this->_wishlistItem = $item;
|
| 56 |
-
|
| 57 |
-
return $this;
|
| 58 |
-
}
|
| 59 |
-
|
| 60 |
-
/**
|
| 61 |
-
* Get linked fields
|
| 62 |
-
*
|
| 63 |
-
* @return array
|
| 64 |
-
*/
|
| 65 |
-
public function linkedFields()
|
| 66 |
-
{
|
| 67 |
-
return Mage::helper('marketingsoftware/config')->getLinkedWishlistFields();
|
| 68 |
-
}
|
| 69 |
-
|
| 70 |
-
/**
|
| 71 |
-
* Get the required fields
|
| 72 |
-
*
|
| 73 |
-
* @return array
|
| 74 |
-
*/
|
| 75 |
-
public function requiredFields()
|
| 76 |
-
{
|
| 77 |
-
return Mage::helper('marketingsoftware')->requiredWishlistItemFields();
|
| 78 |
-
}
|
| 79 |
-
|
| 80 |
-
/**
|
| 81 |
-
* Retrieve the data for this object
|
| 82 |
-
*
|
| 83 |
-
* @return array
|
| 84 |
-
*/
|
| 85 |
-
protected function _data()
|
| 86 |
-
{
|
| 87 |
-
$wishlistItem = $this->_wishlistItem;
|
| 88 |
-
|
| 89 |
-
$product = $wishlistItem->product();
|
| 90 |
-
|
| 91 |
-
$wishlist = $wishlistItem->wishlist();
|
| 92 |
-
|
| 93 |
-
$data = array(
|
| 94 |
-
'item_id' => $wishlistItem->id(),
|
| 95 |
-
'wishlist_id' => $wishlist->id(),
|
| 96 |
-
'product_id' => $product->id(),
|
| 97 |
-
'name' => $product->name(),
|
| 98 |
-
'sku' => $product->sku(),
|
| 99 |
-
'attribute_set' => $product->attributeSet(),
|
| 100 |
-
'weight' => $wishlistItem->weight(),
|
| 101 |
-
'quantity' => $wishlistItem->quantity(),
|
| 102 |
-
'timestamp' => $wishlistItem->timestamp(),
|
| 103 |
-
'attributes' => (string)$product->attributes(),
|
| 104 |
-
'options' => (string)$wishlistItem->options()
|
| 105 |
-
);
|
| 106 |
-
|
| 107 |
-
$storeView = $wishlist->storeView();
|
| 108 |
-
|
| 109 |
-
if ($storeView) {
|
| 110 |
-
$storeId = $storeView->id();
|
| 111 |
-
|
| 112 |
-
$data['store_view'] = (string)$storeView;
|
| 113 |
-
$data['url'] = $product->productUrl($storeId);
|
| 114 |
-
$data['image'] = $product->imageUrl($storeId);
|
| 115 |
-
} else {
|
| 116 |
-
$data['store_view'] = '';
|
| 117 |
-
$data['url'] = '';
|
| 118 |
-
$data['image'] = '';
|
| 119 |
-
}
|
| 120 |
-
|
| 121 |
-
if ($price = $wishlistItem->price()) {
|
| 122 |
-
$data['price'] = $price->itemPrice();
|
| 123 |
-
$data['total_price'] = $price->total();
|
| 124 |
-
}
|
| 125 |
-
|
| 126 |
-
$data['categories'] = implode("\n", array_map(function($category) {
|
| 127 |
-
return implode(' > ', $category);
|
| 128 |
-
}, $product->categories()));
|
| 129 |
-
|
| 130 |
-
return $data;
|
| 131 |
-
}
|
| 132 |
}
|
| 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_Wishlist_Item_Subprofile extends Copernica_MarketingSoftware_Model_Copernica_Abstract
|
| 31 |
+
{
|
| 32 |
+
/**
|
| 33 |
+
* @var Copernica_MarketingSoftware_Model_Abstraction_Wishlist_Item
|
| 34 |
+
*/
|
| 35 |
+
protected $_wishlistItem = false;
|
| 36 |
+
|
| 37 |
+
/**
|
| 38 |
+
* Return the identifier for this profile
|
| 39 |
+
*
|
| 40 |
+
* @return string
|
| 41 |
+
*/
|
| 42 |
+
public function id()
|
| 43 |
+
{
|
| 44 |
+
return $this['item_id'];
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
/**
|
| 48 |
+
* Try to store a wishlist item
|
| 49 |
+
*
|
| 50 |
+
* @param Copernica_MarketingSoftware_Model_Abstraction_Wishlist_Item $item
|
| 51 |
+
* @return Copernica_MarketingSoftware_Model_Copernica_Wishlist_Item_Subprofile;
|
| 52 |
+
*/
|
| 53 |
+
public function setWishlistItem(Copernica_MarketingSoftware_Model_Abstraction_Wishlist_Item $item)
|
| 54 |
+
{
|
| 55 |
+
$this->_wishlistItem = $item;
|
| 56 |
+
|
| 57 |
+
return $this;
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
/**
|
| 61 |
+
* Get linked fields
|
| 62 |
+
*
|
| 63 |
+
* @return array
|
| 64 |
+
*/
|
| 65 |
+
public function linkedFields()
|
| 66 |
+
{
|
| 67 |
+
return Mage::helper('marketingsoftware/config')->getLinkedWishlistFields();
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
/**
|
| 71 |
+
* Get the required fields
|
| 72 |
+
*
|
| 73 |
+
* @return array
|
| 74 |
+
*/
|
| 75 |
+
public function requiredFields()
|
| 76 |
+
{
|
| 77 |
+
return Mage::helper('marketingsoftware')->requiredWishlistItemFields();
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
/**
|
| 81 |
+
* Retrieve the data for this object
|
| 82 |
+
*
|
| 83 |
+
* @return array
|
| 84 |
+
*/
|
| 85 |
+
protected function _data()
|
| 86 |
+
{
|
| 87 |
+
$wishlistItem = $this->_wishlistItem;
|
| 88 |
+
|
| 89 |
+
$product = $wishlistItem->product();
|
| 90 |
+
|
| 91 |
+
$wishlist = $wishlistItem->wishlist();
|
| 92 |
+
|
| 93 |
+
$data = array(
|
| 94 |
+
'item_id' => $wishlistItem->id(),
|
| 95 |
+
'wishlist_id' => $wishlist->id(),
|
| 96 |
+
'product_id' => $product->id(),
|
| 97 |
+
'name' => $product->name(),
|
| 98 |
+
'sku' => $product->sku(),
|
| 99 |
+
'attribute_set' => $product->attributeSet(),
|
| 100 |
+
'weight' => $wishlistItem->weight(),
|
| 101 |
+
'quantity' => $wishlistItem->quantity(),
|
| 102 |
+
'timestamp' => $wishlistItem->timestamp(),
|
| 103 |
+
'attributes' => (string)$product->attributes(),
|
| 104 |
+
'options' => (string)$wishlistItem->options()
|
| 105 |
+
);
|
| 106 |
+
|
| 107 |
+
$storeView = $wishlist->storeView();
|
| 108 |
+
|
| 109 |
+
if ($storeView) {
|
| 110 |
+
$storeId = $storeView->id();
|
| 111 |
+
|
| 112 |
+
$data['store_view'] = (string)$storeView;
|
| 113 |
+
$data['url'] = $product->productUrl($storeId);
|
| 114 |
+
$data['image'] = $product->imageUrl($storeId);
|
| 115 |
+
} else {
|
| 116 |
+
$data['store_view'] = '';
|
| 117 |
+
$data['url'] = '';
|
| 118 |
+
$data['image'] = '';
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
if ($price = $wishlistItem->price()) {
|
| 122 |
+
$data['price'] = $price->itemPrice();
|
| 123 |
+
$data['total_price'] = $price->total();
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
$data['categories'] = implode("\n", array_map(function($category) {
|
| 127 |
+
return implode(' > ', $category);
|
| 128 |
+
}, $product->categories()));
|
| 129 |
+
|
| 130 |
+
return $data;
|
| 131 |
+
}
|
| 132 |
}
|
app/code/community/Copernica/MarketingSoftware/Model/Error/Queue.php
CHANGED
|
@@ -1,106 +1,106 @@
|
|
| 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 |
-
* This class will represent item from error queue.
|
| 29 |
-
*/
|
| 30 |
-
class Copernica_MarketingSoftware_Model_Error_Queue extends Mage_Core_Model_Abstract
|
| 31 |
-
{
|
| 32 |
-
/**
|
| 33 |
-
* Construct the model
|
| 34 |
-
*/
|
| 35 |
-
protected function _construct()
|
| 36 |
-
{
|
| 37 |
-
$this->_init('marketingsoftware/error_queue');
|
| 38 |
-
}
|
| 39 |
-
|
| 40 |
-
/**
|
| 41 |
-
* Get object instance.
|
| 42 |
-
*
|
| 43 |
-
* @return object
|
| 44 |
-
*/
|
| 45 |
-
public function getObject()
|
| 46 |
-
{
|
| 47 |
-
return unserialize(parent::getData('object'));
|
| 48 |
-
}
|
| 49 |
-
|
| 50 |
-
/**
|
| 51 |
-
* Set object instance
|
| 52 |
-
*
|
| 53 |
-
* @param object $object
|
| 54 |
-
*/
|
| 55 |
-
public function setObject($object)
|
| 56 |
-
{
|
| 57 |
-
return parent::setData('object', serialize($object));
|
| 58 |
-
}
|
| 59 |
-
|
| 60 |
-
/**
|
| 61 |
-
* Set customer Id
|
| 62 |
-
*
|
| 63 |
-
* @param int $customerId
|
| 64 |
-
*/
|
| 65 |
-
public function setCustomerId($customerId)
|
| 66 |
-
{
|
| 67 |
-
return parent::setData('customer', $customerId);
|
| 68 |
-
}
|
| 69 |
-
|
| 70 |
-
/**
|
| 71 |
-
* Get customer Id
|
| 72 |
-
*
|
| 73 |
-
* @return int
|
| 74 |
-
*/
|
| 75 |
-
public function getCustomerId()
|
| 76 |
-
{
|
| 77 |
-
return parent::getData('customer');
|
| 78 |
-
}
|
| 79 |
-
|
| 80 |
-
/**
|
| 81 |
-
* Save model
|
| 82 |
-
*/
|
| 83 |
-
public function save()
|
| 84 |
-
{
|
| 85 |
-
return parent::save();
|
| 86 |
-
}
|
| 87 |
-
|
| 88 |
-
/**
|
| 89 |
-
* This method will create instance from processing queue item
|
| 90 |
-
*
|
| 91 |
-
* @param Copernica_MarketingSoftware_Model_Queue_Event_Item $queueItem
|
| 92 |
-
*/
|
| 93 |
-
static public function createFromQueueItem(Copernica_MarketingSoftware_Model_Queue_Event_Item $queueItem)
|
| 94 |
-
{
|
| 95 |
-
$errorModel = Mage::getModel('marketingsoftware/error_queue');
|
| 96 |
-
$errorModel->setObject($queueItem->getObject());
|
| 97 |
-
$errorModel->setOldId($queueItem->getId());
|
| 98 |
-
$errorModel->setAction($queueItem->getAction());
|
| 99 |
-
$errorModel->setQueueTime($queueItem->getQueueTime());
|
| 100 |
-
$errorModel->setResult($queueItem->getResult());
|
| 101 |
-
$errorModel->setResultTime($queueItem->getResultTime());
|
| 102 |
-
$errorModel->setCustomerId($queueItem->getCustomerId());
|
| 103 |
-
|
| 104 |
-
return $errorModel;
|
| 105 |
-
}
|
| 106 |
}
|
| 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 |
+
* This class will represent item from error queue.
|
| 29 |
+
*/
|
| 30 |
+
class Copernica_MarketingSoftware_Model_Error_Queue extends Mage_Core_Model_Abstract
|
| 31 |
+
{
|
| 32 |
+
/**
|
| 33 |
+
* Construct the model
|
| 34 |
+
*/
|
| 35 |
+
protected function _construct()
|
| 36 |
+
{
|
| 37 |
+
$this->_init('marketingsoftware/error_queue');
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
/**
|
| 41 |
+
* Get object instance.
|
| 42 |
+
*
|
| 43 |
+
* @return object
|
| 44 |
+
*/
|
| 45 |
+
public function getObject()
|
| 46 |
+
{
|
| 47 |
+
return unserialize(parent::getData('object'));
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
/**
|
| 51 |
+
* Set object instance
|
| 52 |
+
*
|
| 53 |
+
* @param object $object
|
| 54 |
+
*/
|
| 55 |
+
public function setObject($object)
|
| 56 |
+
{
|
| 57 |
+
return parent::setData('object', serialize($object));
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
/**
|
| 61 |
+
* Set customer Id
|
| 62 |
+
*
|
| 63 |
+
* @param int $customerId
|
| 64 |
+
*/
|
| 65 |
+
public function setCustomerId($customerId)
|
| 66 |
+
{
|
| 67 |
+
return parent::setData('customer', $customerId);
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
/**
|
| 71 |
+
* Get customer Id
|
| 72 |
+
*
|
| 73 |
+
* @return int
|
| 74 |
+
*/
|
| 75 |
+
public function getCustomerId()
|
| 76 |
+
{
|
| 77 |
+
return parent::getData('customer');
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
/**
|
| 81 |
+
* Save model
|
| 82 |
+
*/
|
| 83 |
+
public function save()
|
| 84 |
+
{
|
| 85 |
+
return parent::save();
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
/**
|
| 89 |
+
* This method will create instance from processing queue item
|
| 90 |
+
*
|
| 91 |
+
* @param Copernica_MarketingSoftware_Model_Queue_Event_Item $queueItem
|
| 92 |
+
*/
|
| 93 |
+
static public function createFromQueueItem(Copernica_MarketingSoftware_Model_Queue_Event_Item $queueItem)
|
| 94 |
+
{
|
| 95 |
+
$errorModel = Mage::getModel('marketingsoftware/error_queue');
|
| 96 |
+
$errorModel->setObject($queueItem->getObject());
|
| 97 |
+
$errorModel->setOldId($queueItem->getId());
|
| 98 |
+
$errorModel->setAction($queueItem->getAction());
|
| 99 |
+
$errorModel->setQueueTime($queueItem->getQueueTime());
|
| 100 |
+
$errorModel->setResult($queueItem->getResult());
|
| 101 |
+
$errorModel->setResultTime($queueItem->getResultTime());
|
| 102 |
+
$errorModel->setCustomerId($queueItem->getCustomerId());
|
| 103 |
+
|
| 104 |
+
return $errorModel;
|
| 105 |
+
}
|
| 106 |
}
|
app/code/community/Copernica/MarketingSoftware/Model/Mysql4/Abandoned/Cart.php
CHANGED
|
@@ -1,39 +1,39 @@
|
|
| 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 |
-
* Resource that we will use to track abandoned carts sent to copernica.
|
| 29 |
-
*/
|
| 30 |
-
class Copernica_MarketingSoftware_Model_Mysql4_Abandoned_Cart extends Mage_Core_Model_Mysql4_Abstract
|
| 31 |
-
{
|
| 32 |
-
/**
|
| 33 |
-
* Construct model
|
| 34 |
-
*/
|
| 35 |
-
protected function _construct()
|
| 36 |
-
{
|
| 37 |
-
$this->_init('marketingsoftware/abandoned_cart', 'id');
|
| 38 |
-
}
|
| 39 |
}
|
| 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 |
+
* Resource that we will use to track abandoned carts sent to copernica.
|
| 29 |
+
*/
|
| 30 |
+
class Copernica_MarketingSoftware_Model_Mysql4_Abandoned_Cart extends Mage_Core_Model_Mysql4_Abstract
|
| 31 |
+
{
|
| 32 |
+
/**
|
| 33 |
+
* Construct model
|
| 34 |
+
*/
|
| 35 |
+
protected function _construct()
|
| 36 |
+
{
|
| 37 |
+
$this->_init('marketingsoftware/abandoned_cart', 'id');
|
| 38 |
+
}
|
| 39 |
}
|
app/code/community/Copernica/MarketingSoftware/Model/Mysql4/Abandoned/Cart/Collection.php
CHANGED
|
@@ -1,12 +1,12 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
|
| 3 |
-
class Copernica_MarketingSoftware_Model_Mysql4_Abandoned_Cart_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
|
| 4 |
-
{
|
| 5 |
-
/**
|
| 6 |
-
* Construct and initialize object
|
| 7 |
-
*/
|
| 8 |
-
protected function _construct()
|
| 9 |
-
{
|
| 10 |
-
$this->_init('marketingsoftware/abandoned_cart');
|
| 11 |
-
}
|
| 12 |
}
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
class Copernica_MarketingSoftware_Model_Mysql4_Abandoned_Cart_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
|
| 4 |
+
{
|
| 5 |
+
/**
|
| 6 |
+
* Construct and initialize object
|
| 7 |
+
*/
|
| 8 |
+
protected function _construct()
|
| 9 |
+
{
|
| 10 |
+
$this->_init('marketingsoftware/abandoned_cart');
|
| 11 |
+
}
|
| 12 |
}
|
app/code/community/Copernica/MarketingSoftware/Model/Mysql4/Config.php
CHANGED
|
@@ -1,33 +1,33 @@
|
|
| 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 |
-
class Copernica_MarketingSoftware_Model_Mysql4_Config extends Mage_Core_Model_Mysql4_Abstract
|
| 28 |
-
{
|
| 29 |
-
protected function _construct()
|
| 30 |
-
{
|
| 31 |
-
$this->_init('marketingsoftware/config_data', 'config_id');
|
| 32 |
-
}
|
| 33 |
}
|
| 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 |
+
class Copernica_MarketingSoftware_Model_Mysql4_Config extends Mage_Core_Model_Mysql4_Abstract
|
| 28 |
+
{
|
| 29 |
+
protected function _construct()
|
| 30 |
+
{
|
| 31 |
+
$this->_init('marketingsoftware/config_data', 'config_id');
|
| 32 |
+
}
|
| 33 |
}
|
app/code/community/Copernica/MarketingSoftware/Model/Mysql4/Config/Collection.php
CHANGED
|
@@ -1,33 +1,33 @@
|
|
| 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 |
-
class Copernica_MarketingSoftware_Model_Mysql4_Config_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
|
| 28 |
-
{
|
| 29 |
-
protected function _construct()
|
| 30 |
-
{
|
| 31 |
-
$this->_init('marketingsoftware/config');
|
| 32 |
-
}
|
| 33 |
}
|
| 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 |
+
class Copernica_MarketingSoftware_Model_Mysql4_Config_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
|
| 28 |
+
{
|
| 29 |
+
protected function _construct()
|
| 30 |
+
{
|
| 31 |
+
$this->_init('marketingsoftware/config');
|
| 32 |
+
}
|
| 33 |
}
|
app/code/community/Copernica/MarketingSoftware/Model/Mysql4/Error/Queue.php
CHANGED
|
@@ -1,36 +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 |
-
* 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 |
-
class Copernica_MarketingSoftware_Model_Mysql4_Error_Queue extends Mage_Core_Model_Mysql4_Abstract
|
| 28 |
-
{
|
| 29 |
-
/**
|
| 30 |
-
* Fancy, magento-only constructor for initializing objects
|
| 31 |
-
*/
|
| 32 |
-
protected function _construct()
|
| 33 |
-
{
|
| 34 |
-
$this->_init('marketingsoftware/error_queue', 'id');
|
| 35 |
-
}
|
| 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 |
+
* 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 |
+
class Copernica_MarketingSoftware_Model_Mysql4_Error_Queue extends Mage_Core_Model_Mysql4_Abstract
|
| 28 |
+
{
|
| 29 |
+
/**
|
| 30 |
+
* Fancy, magento-only constructor for initializing objects
|
| 31 |
+
*/
|
| 32 |
+
protected function _construct()
|
| 33 |
+
{
|
| 34 |
+
$this->_init('marketingsoftware/error_queue', 'id');
|
| 35 |
+
}
|
| 36 |
}
|
app/code/community/Copernica/MarketingSoftware/Model/Mysql4/Error/Queue/Collection.php
CHANGED
|
@@ -1,36 +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 |
-
* 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 |
-
class Copernica_MarketingSoftware_Model_Mysql4_Error_Queue_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
|
| 28 |
-
{
|
| 29 |
-
/**
|
| 30 |
-
* Construct and initialize object
|
| 31 |
-
*/
|
| 32 |
-
protected function _construct()
|
| 33 |
-
{
|
| 34 |
-
$this->_init('marketingsoftware/error_queue');
|
| 35 |
-
}
|
| 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 |
+
* 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 |
+
class Copernica_MarketingSoftware_Model_Mysql4_Error_Queue_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
|
| 28 |
+
{
|
| 29 |
+
/**
|
| 30 |
+
* Construct and initialize object
|
| 31 |
+
*/
|
| 32 |
+
protected function _construct()
|
| 33 |
+
{
|
| 34 |
+
$this->_init('marketingsoftware/error_queue');
|
| 35 |
+
}
|
| 36 |
}
|
app/code/community/Copernica/MarketingSoftware/Model/Mysql4/Profile/Cache.php
CHANGED
|
@@ -1,39 +1,39 @@
|
|
| 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 |
-
* This class will present and interface to copernica_profile_cache mysql table.
|
| 29 |
-
*/
|
| 30 |
-
class Copernica_MarketingSoftware_Model_Mysql4_Profile_Cache extends Mage_Core_Model_Mysql4_Abstract
|
| 31 |
-
{
|
| 32 |
-
/**
|
| 33 |
-
* Construct model
|
| 34 |
-
*/
|
| 35 |
-
protected function _construct()
|
| 36 |
-
{
|
| 37 |
-
$this->_init('marketingsoftware/profile_cache', 'id');
|
| 38 |
-
}
|
| 39 |
}
|
| 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 |
+
* This class will present and interface to copernica_profile_cache mysql table.
|
| 29 |
+
*/
|
| 30 |
+
class Copernica_MarketingSoftware_Model_Mysql4_Profile_Cache extends Mage_Core_Model_Mysql4_Abstract
|
| 31 |
+
{
|
| 32 |
+
/**
|
| 33 |
+
* Construct model
|
| 34 |
+
*/
|
| 35 |
+
protected function _construct()
|
| 36 |
+
{
|
| 37 |
+
$this->_init('marketingsoftware/profile_cache', 'id');
|
| 38 |
+
}
|
| 39 |
}
|
app/code/community/Copernica/MarketingSoftware/Model/Mysql4/Profile/Cache/Collection.php
CHANGED
|
@@ -1,33 +1,33 @@
|
|
| 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 |
-
class Copernica_MarketingSoftware_Model_Mysql4_Profile_Cache_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
|
| 28 |
-
{
|
| 29 |
-
protected function _construct()
|
| 30 |
-
{
|
| 31 |
-
$this->_init('marketingsoftware/profile_cache');
|
| 32 |
-
}
|
| 33 |
}
|
| 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 |
+
class Copernica_MarketingSoftware_Model_Mysql4_Profile_Cache_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
|
| 28 |
+
{
|
| 29 |
+
protected function _construct()
|
| 30 |
+
{
|
| 31 |
+
$this->_init('marketingsoftware/profile_cache');
|
| 32 |
+
}
|
| 33 |
}
|
app/code/community/Copernica/MarketingSoftware/Model/Mysql4/Queue/Item/Collection.php
CHANGED
|
@@ -1,67 +1,67 @@
|
|
| 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 |
-
class Copernica_MarketingSoftware_Model_Mysql4_Queue_Item_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
|
| 28 |
-
{
|
| 29 |
-
/**
|
| 30 |
-
* Construct and initialize object
|
| 31 |
-
*/
|
| 32 |
-
protected function _construct()
|
| 33 |
-
{
|
| 34 |
-
$this->_init('marketingsoftware/queue_item');
|
| 35 |
-
}
|
| 36 |
-
|
| 37 |
-
/**
|
| 38 |
-
* Add a default order, sorted ascending by queue time
|
| 39 |
-
*
|
| 40 |
-
* @return Copernica_MarketingSoftware_Model_Mysql4_Queue_Item_Collection
|
| 41 |
-
*/
|
| 42 |
-
public function addDefaultOrder()
|
| 43 |
-
{
|
| 44 |
-
return $this->addOrder('result_time', self::SORT_ORDER_ASC)
|
| 45 |
-
->addOrder('queue_time', self::SORT_ORDER_ASC);
|
| 46 |
-
}
|
| 47 |
-
|
| 48 |
-
/**
|
| 49 |
-
* Get the time of the oldest record
|
| 50 |
-
*
|
| 51 |
-
* @return string
|
| 52 |
-
*/
|
| 53 |
-
public function getQueueStartTime()
|
| 54 |
-
{
|
| 55 |
-
return $this->addDefaultOrder()->setPageSize(1)->getFirstItem()->getQueueTime();
|
| 56 |
-
}
|
| 57 |
-
|
| 58 |
-
/**
|
| 59 |
-
* Get the result of the oldest record
|
| 60 |
-
*
|
| 61 |
-
* @return string
|
| 62 |
-
*/
|
| 63 |
-
public function getOldestResult()
|
| 64 |
-
{
|
| 65 |
-
return $this->addDefaultOrder()->setPageSize(1)->getFirstItem()->getResult();
|
| 66 |
-
}
|
| 67 |
}
|
| 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 |
+
class Copernica_MarketingSoftware_Model_Mysql4_Queue_Item_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
|
| 28 |
+
{
|
| 29 |
+
/**
|
| 30 |
+
* Construct and initialize object
|
| 31 |
+
*/
|
| 32 |
+
protected function _construct()
|
| 33 |
+
{
|
| 34 |
+
$this->_init('marketingsoftware/queue_item');
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
/**
|
| 38 |
+
* Add a default order, sorted ascending by queue time
|
| 39 |
+
*
|
| 40 |
+
* @return Copernica_MarketingSoftware_Model_Mysql4_Queue_Item_Collection
|
| 41 |
+
*/
|
| 42 |
+
public function addDefaultOrder()
|
| 43 |
+
{
|
| 44 |
+
return $this->addOrder('result_time', self::SORT_ORDER_ASC)
|
| 45 |
+
->addOrder('queue_time', self::SORT_ORDER_ASC);
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
/**
|
| 49 |
+
* Get the time of the oldest record
|
| 50 |
+
*
|
| 51 |
+
* @return string
|
| 52 |
+
*/
|
| 53 |
+
public function getQueueStartTime()
|
| 54 |
+
{
|
| 55 |
+
return $this->addDefaultOrder()->setPageSize(1)->getFirstItem()->getQueueTime();
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
/**
|
| 59 |
+
* Get the result of the oldest record
|
| 60 |
+
*
|
| 61 |
+
* @return string
|
| 62 |
+
*/
|
| 63 |
+
public function getOldestResult()
|
| 64 |
+
{
|
| 65 |
+
return $this->addDefaultOrder()->setPageSize(1)->getFirstItem()->getResult();
|
| 66 |
+
}
|
| 67 |
}
|
app/code/community/Copernica/MarketingSoftware/Model/Mysql4/Sync/Profile.php
CHANGED
|
@@ -1,36 +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 |
-
* 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 |
-
class Copernica_MarketingSoftware_Model_Mysql4_Sync_Profile extends Mage_Core_Model_Mysql4_Abstract
|
| 28 |
-
{
|
| 29 |
-
/**
|
| 30 |
-
* Construct model
|
| 31 |
-
*/
|
| 32 |
-
protected function _construct()
|
| 33 |
-
{
|
| 34 |
-
$this->_init('marketingsoftware/sync_profile', 'id');
|
| 35 |
-
}
|
| 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 |
+
* 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 |
+
class Copernica_MarketingSoftware_Model_Mysql4_Sync_Profile extends Mage_Core_Model_Mysql4_Abstract
|
| 28 |
+
{
|
| 29 |
+
/**
|
| 30 |
+
* Construct model
|
| 31 |
+
*/
|
| 32 |
+
protected function _construct()
|
| 33 |
+
{
|
| 34 |
+
$this->_init('marketingsoftware/sync_profile', 'id');
|
| 35 |
+
}
|
| 36 |
}
|
app/code/community/Copernica/MarketingSoftware/Model/Mysql4/Sync/Profile/Collection.php
CHANGED
|
@@ -1,33 +1,33 @@
|
|
| 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 |
-
class Copernica_MarketingSoftware_Model_Mysql4_Sync_Profile_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
|
| 28 |
-
{
|
| 29 |
-
protected function _construct()
|
| 30 |
-
{
|
| 31 |
-
$this->_init('marketingsoftware/sync_profile');
|
| 32 |
-
}
|
| 33 |
}
|
| 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 |
+
class Copernica_MarketingSoftware_Model_Mysql4_Sync_Profile_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
|
| 28 |
+
{
|
| 29 |
+
protected function _construct()
|
| 30 |
+
{
|
| 31 |
+
$this->_init('marketingsoftware/sync_profile');
|
| 32 |
+
}
|
| 33 |
}
|
app/code/community/Copernica/MarketingSoftware/Model/Profile/Cache.php
CHANGED
|
@@ -1,83 +1,83 @@
|
|
| 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 |
-
* This class will present and interface to copernica_profile_cache mysql table.
|
| 29 |
-
*/
|
| 30 |
-
class Copernica_MarketingSoftware_Model_Profile_Cache extends Mage_Core_Model_Abstract
|
| 31 |
-
{
|
| 32 |
-
/**
|
| 33 |
-
* Construct model
|
| 34 |
-
*/
|
| 35 |
-
protected function _construct()
|
| 36 |
-
{
|
| 37 |
-
$this->_init('marketingsoftware/profile_cache');
|
| 38 |
-
}
|
| 39 |
-
|
| 40 |
-
/**
|
| 41 |
-
* Get the profile Id
|
| 42 |
-
*
|
| 43 |
-
* @return int
|
| 44 |
-
*/
|
| 45 |
-
public function getProfileId()
|
| 46 |
-
{
|
| 47 |
-
return parent::getData('profile_id');
|
| 48 |
-
}
|
| 49 |
-
|
| 50 |
-
/**
|
| 51 |
-
* Get the customer Id
|
| 52 |
-
*/
|
| 53 |
-
public function getCustomerId()
|
| 54 |
-
{
|
| 55 |
-
return parent::getData('customer_id');
|
| 56 |
-
}
|
| 57 |
-
|
| 58 |
-
/**
|
| 59 |
-
* Set profile Id
|
| 60 |
-
*
|
| 61 |
-
* @param int $profileId
|
| 62 |
-
* @return Copernica_MarketingSoftware_Model_Profile_Cache
|
| 63 |
-
*/
|
| 64 |
-
public function setProfileId($profileId)
|
| 65 |
-
{
|
| 66 |
-
parent::setData('profile_id', $profileId);
|
| 67 |
-
|
| 68 |
-
return $this;
|
| 69 |
-
}
|
| 70 |
-
|
| 71 |
-
/**
|
| 72 |
-
* Set customer Id
|
| 73 |
-
*
|
| 74 |
-
* @param string $customerId
|
| 75 |
-
* @return Copernica_MarketingSoftware_Model_Profile_Cache
|
| 76 |
-
*/
|
| 77 |
-
public function setCustomerId($customerId)
|
| 78 |
-
{
|
| 79 |
-
parent::setData('customer_id', $customerId);
|
| 80 |
-
|
| 81 |
-
return $this;
|
| 82 |
-
}
|
| 83 |
}
|
| 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 |
+
* This class will present and interface to copernica_profile_cache mysql table.
|
| 29 |
+
*/
|
| 30 |
+
class Copernica_MarketingSoftware_Model_Profile_Cache extends Mage_Core_Model_Abstract
|
| 31 |
+
{
|
| 32 |
+
/**
|
| 33 |
+
* Construct model
|
| 34 |
+
*/
|
| 35 |
+
protected function _construct()
|
| 36 |
+
{
|
| 37 |
+
$this->_init('marketingsoftware/profile_cache');
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
/**
|
| 41 |
+
* Get the profile Id
|
| 42 |
+
*
|
| 43 |
+
* @return int
|
| 44 |
+
*/
|
| 45 |
+
public function getProfileId()
|
| 46 |
+
{
|
| 47 |
+
return parent::getData('profile_id');
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
/**
|
| 51 |
+
* Get the customer Id
|
| 52 |
+
*/
|
| 53 |
+
public function getCustomerId()
|
| 54 |
+
{
|
| 55 |
+
return parent::getData('customer_id');
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
/**
|
| 59 |
+
* Set profile Id
|
| 60 |
+
*
|
| 61 |
+
* @param int $profileId
|
| 62 |
+
* @return Copernica_MarketingSoftware_Model_Profile_Cache
|
| 63 |
+
*/
|
| 64 |
+
public function setProfileId($profileId)
|
| 65 |
+
{
|
| 66 |
+
parent::setData('profile_id', $profileId);
|
| 67 |
+
|
| 68 |
+
return $this;
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
/**
|
| 72 |
+
* Set customer Id
|
| 73 |
+
*
|
| 74 |
+
* @param string $customerId
|
| 75 |
+
* @return Copernica_MarketingSoftware_Model_Profile_Cache
|
| 76 |
+
*/
|
| 77 |
+
public function setCustomerId($customerId)
|
| 78 |
+
{
|
| 79 |
+
parent::setData('customer_id', $customerId);
|
| 80 |
+
|
| 81 |
+
return $this;
|
| 82 |
+
}
|
| 83 |
}
|
app/code/community/Copernica/MarketingSoftware/Model/Queue/Event/Abstract.php
CHANGED
|
@@ -1,109 +1,109 @@
|
|
| 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 |
-
abstract class Copernica_MarketingSoftware_Model_Queue_Event_Abstract
|
| 31 |
-
{
|
| 32 |
-
/**
|
| 33 |
-
* What queue item was used to construct this item
|
| 34 |
-
*
|
| 35 |
-
* @var Copernica_MarketingSoftware_Model_Queue_Item
|
| 36 |
-
*/
|
| 37 |
-
protected $_queueItem;
|
| 38 |
-
|
| 39 |
-
/**
|
| 40 |
-
* Construct the item given the queueitem
|
| 41 |
-
*
|
| 42 |
-
* @param Copernica_MarketingSoftware_Model_Queue_Item $item
|
| 43 |
-
*/
|
| 44 |
-
public function setQueueItem(Copernica_MarketingSoftware_Model_Queue_Item $item)
|
| 45 |
-
{
|
| 46 |
-
$this->_queueItem = $item;
|
| 47 |
-
}
|
| 48 |
-
|
| 49 |
-
/**
|
| 50 |
-
* Get the object for this queue item
|
| 51 |
-
*
|
| 52 |
-
* @todo Not used?
|
| 53 |
-
* @return Abstraction object
|
| 54 |
-
*/
|
| 55 |
-
protected function _getObject()
|
| 56 |
-
{
|
| 57 |
-
return $this->_queueItem->getObject();
|
| 58 |
-
}
|
| 59 |
-
|
| 60 |
-
/**
|
| 61 |
-
* Get the entity Id
|
| 62 |
-
*
|
| 63 |
-
* @todo Not used?
|
| 64 |
-
* @return int
|
| 65 |
-
*/
|
| 66 |
-
protected function _getEntityId()
|
| 67 |
-
{
|
| 68 |
-
return $this->_queueItem->getEntityId();
|
| 69 |
-
}
|
| 70 |
-
|
| 71 |
-
/**
|
| 72 |
-
* Get the customer Id
|
| 73 |
-
*
|
| 74 |
-
* @todo Not used?
|
| 75 |
-
* @return int
|
| 76 |
-
*/
|
| 77 |
-
protected function _getCustomerId()
|
| 78 |
-
{
|
| 79 |
-
return $this->_queueItem->getCustomerId();
|
| 80 |
-
}
|
| 81 |
-
|
| 82 |
-
/**
|
| 83 |
-
* Process this item in the queue
|
| 84 |
-
*
|
| 85 |
-
* @return boolean was the processing successfull
|
| 86 |
-
*/
|
| 87 |
-
public function process()
|
| 88 |
-
{
|
| 89 |
-
$methodName = 'action'.ucfirst($this->_queueItem->getAction());
|
| 90 |
-
|
| 91 |
-
if (!method_exists($this, $methodName)) {
|
| 92 |
-
return false;
|
| 93 |
-
}
|
| 94 |
-
|
| 95 |
-
return $this->$methodName();
|
| 96 |
-
}
|
| 97 |
-
|
| 98 |
-
/**
|
| 99 |
-
* Respawn event on the queue.
|
| 100 |
-
*/
|
| 101 |
-
public function respawn()
|
| 102 |
-
{
|
| 103 |
-
Mage::getModel('marketingsoftware/queue_item')
|
| 104 |
-
->setObject($this->_queueItem->getObject())
|
| 105 |
-
->setCustomer($this->_queueItem->getCustomer())
|
| 106 |
-
->setAction($this->_queueItem->getAction())
|
| 107 |
-
->save();
|
| 108 |
-
}
|
| 109 |
}
|
| 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 |
+
abstract class Copernica_MarketingSoftware_Model_Queue_Event_Abstract
|
| 31 |
+
{
|
| 32 |
+
/**
|
| 33 |
+
* What queue item was used to construct this item
|
| 34 |
+
*
|
| 35 |
+
* @var Copernica_MarketingSoftware_Model_Queue_Item
|
| 36 |
+
*/
|
| 37 |
+
protected $_queueItem;
|
| 38 |
+
|
| 39 |
+
/**
|
| 40 |
+
* Construct the item given the queueitem
|
| 41 |
+
*
|
| 42 |
+
* @param Copernica_MarketingSoftware_Model_Queue_Item $item
|
| 43 |
+
*/
|
| 44 |
+
public function setQueueItem(Copernica_MarketingSoftware_Model_Queue_Item $item)
|
| 45 |
+
{
|
| 46 |
+
$this->_queueItem = $item;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
/**
|
| 50 |
+
* Get the object for this queue item
|
| 51 |
+
*
|
| 52 |
+
* @todo Not used?
|
| 53 |
+
* @return Abstraction object
|
| 54 |
+
*/
|
| 55 |
+
protected function _getObject()
|
| 56 |
+
{
|
| 57 |
+
return $this->_queueItem->getObject();
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
/**
|
| 61 |
+
* Get the entity Id
|
| 62 |
+
*
|
| 63 |
+
* @todo Not used?
|
| 64 |
+
* @return int
|
| 65 |
+
*/
|
| 66 |
+
protected function _getEntityId()
|
| 67 |
+
{
|
| 68 |
+
return $this->_queueItem->getEntityId();
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
/**
|
| 72 |
+
* Get the customer Id
|
| 73 |
+
*
|
| 74 |
+
* @todo Not used?
|
| 75 |
+
* @return int
|
| 76 |
+
*/
|
| 77 |
+
protected function _getCustomerId()
|
| 78 |
+
{
|
| 79 |
+
return $this->_queueItem->getCustomerId();
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
/**
|
| 83 |
+
* Process this item in the queue
|
| 84 |
+
*
|
| 85 |
+
* @return boolean was the processing successfull
|
| 86 |
+
*/
|
| 87 |
+
public function process()
|
| 88 |
+
{
|
| 89 |
+
$methodName = 'action'.ucfirst($this->_queueItem->getAction());
|
| 90 |
+
|
| 91 |
+
if (!method_exists($this, $methodName)) {
|
| 92 |
+
return false;
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
return $this->$methodName();
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
/**
|
| 99 |
+
* Respawn event on the queue.
|
| 100 |
+
*/
|
| 101 |
+
public function respawn()
|
| 102 |
+
{
|
| 103 |
+
Mage::getModel('marketingsoftware/queue_item')
|
| 104 |
+
->setObject($this->_queueItem->getObject())
|
| 105 |
+
->setCustomer($this->_queueItem->getCustomer())
|
| 106 |
+
->setAction($this->_queueItem->getAction())
|
| 107 |
+
->save();
|
| 108 |
+
}
|
| 109 |
}
|
app/code/community/Copernica/MarketingSoftware/Model/Queue/Event/Checkout.php
CHANGED
|
@@ -1,114 +1,114 @@
|
|
| 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 |
-
* This class should take care of all events related to checkout.
|
| 29 |
-
*
|
| 30 |
-
* This class does not matter. It should be not used cause it's same as
|
| 31 |
-
* order modify action.
|
| 32 |
-
*/
|
| 33 |
-
class Copernica_MarketingSoftware_Model_Queue_Event_Checkout extends Copernica_MarketingSoftware_Model_Queue_Event_Abstract
|
| 34 |
-
{
|
| 35 |
-
/**
|
| 36 |
-
* Customer entity
|
| 37 |
-
*
|
| 38 |
-
* @var Copernica_MarketingSoftware_Model_Copernica_Entity_Customer
|
| 39 |
-
*/
|
| 40 |
-
protected $_customerEntity;
|
| 41 |
-
|
| 42 |
-
/**
|
| 43 |
-
* Process add action
|
| 44 |
-
*
|
| 45 |
-
* @return boolean
|
| 46 |
-
*/
|
| 47 |
-
public function actionAdd()
|
| 48 |
-
{
|
| 49 |
-
return $this->actionModify();
|
| 50 |
-
}
|
| 51 |
-
|
| 52 |
-
/**
|
| 53 |
-
* Modify action on checkout event
|
| 54 |
-
*
|
| 55 |
-
* @return boolean
|
| 56 |
-
*/
|
| 57 |
-
public function actionModify()
|
| 58 |
-
{
|
| 59 |
-
$customerEntity = $this->_getCustomerEntity();
|
| 60 |
-
|
| 61 |
-
if (!$customerEntity) {
|
| 62 |
-
return false;
|
| 63 |
-
}
|
| 64 |
-
|
| 65 |
-
$quote = Mage::getModel('sales/quote')->loadByIdWithoutStore($this->_getEntityId());
|
| 66 |
-
|
| 67 |
-
$request = Mage::helper('marketingsoftware/rest_request');
|
| 68 |
-
$request->prepare();
|
| 69 |
-
|
| 70 |
-
if (Mage::helper('marketingsoftware/config')->getRemoveFinishedQuoteItem()) {
|
| 71 |
-
$quoteItemCollection = Mage::helper('marketingsoftware/config')->getQuoteItemCollectionId();
|
| 72 |
-
|
| 73 |
-
if ($quoteItemCollection) {
|
| 74 |
-
$response = $request->get('/profile/'.$customerEntity->getProfileId().'/subprofiles/'.$quoteItemCollection, array(
|
| 75 |
-
'fields' => array('quote_id=='.$this->_getEntityId())
|
| 76 |
-
));
|
| 77 |
-
}
|
| 78 |
-
|
| 79 |
-
foreach ($response['data'] as $subprofile) {
|
| 80 |
-
$request->delete('/subprofile/'.$subprofile['ID']);
|
| 81 |
-
}
|
| 82 |
-
} else {
|
| 83 |
-
foreach ($quote->getAllVisibleItems() as $quoteItem) {
|
| 84 |
-
$quoteItemEntity = Mage::getModel('marketingsoftware/copernica_entity_quote_item');
|
| 85 |
-
$quoteItemEntity->setQuoteItem($quoteItem);
|
| 86 |
-
|
| 87 |
-
$restQuoteItem = $quoteItemEntity->getRestQuoteItem();
|
| 88 |
-
$restQuoteItem->syncWithQuote($customerEntity, $quote->getId());
|
| 89 |
-
}
|
| 90 |
-
}
|
| 91 |
-
|
| 92 |
-
$request->commit();
|
| 93 |
-
|
| 94 |
-
return true;
|
| 95 |
-
}
|
| 96 |
-
|
| 97 |
-
protected function _getCustomerEntity()
|
| 98 |
-
{
|
| 99 |
-
if ($this->_customerEntity) {
|
| 100 |
-
return $this->_customerEntity;
|
| 101 |
-
} else {
|
| 102 |
-
$object = $this->_getObject();
|
| 103 |
-
|
| 104 |
-
if (property_exists($object, 'customerId') && is_numeric($object->customerId)) {
|
| 105 |
-
$customerEntity = Mage::getModel('marketingsoftware/copernica_entity_customer');
|
| 106 |
-
$customerEntity->setCustomer($object->customerId);
|
| 107 |
-
|
| 108 |
-
return $this->_customerEntity = $customerEntity;
|
| 109 |
-
} else {
|
| 110 |
-
return false;
|
| 111 |
-
}
|
| 112 |
-
}
|
| 113 |
-
}
|
| 114 |
}
|
| 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 |
+
* This class should take care of all events related to checkout.
|
| 29 |
+
*
|
| 30 |
+
* This class does not matter. It should be not used cause it's same as
|
| 31 |
+
* order modify action.
|
| 32 |
+
*/
|
| 33 |
+
class Copernica_MarketingSoftware_Model_Queue_Event_Checkout extends Copernica_MarketingSoftware_Model_Queue_Event_Abstract
|
| 34 |
+
{
|
| 35 |
+
/**
|
| 36 |
+
* Customer entity
|
| 37 |
+
*
|
| 38 |
+
* @var Copernica_MarketingSoftware_Model_Copernica_Entity_Customer
|
| 39 |
+
*/
|
| 40 |
+
protected $_customerEntity;
|
| 41 |
+
|
| 42 |
+
/**
|
| 43 |
+
* Process add action
|
| 44 |
+
*
|
| 45 |
+
* @return boolean
|
| 46 |
+
*/
|
| 47 |
+
public function actionAdd()
|
| 48 |
+
{
|
| 49 |
+
return $this->actionModify();
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
/**
|
| 53 |
+
* Modify action on checkout event
|
| 54 |
+
*
|
| 55 |
+
* @return boolean
|
| 56 |
+
*/
|
| 57 |
+
public function actionModify()
|
| 58 |
+
{
|
| 59 |
+
$customerEntity = $this->_getCustomerEntity();
|
| 60 |
+
|
| 61 |
+
if (!$customerEntity) {
|
| 62 |
+
return false;
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
$quote = Mage::getModel('sales/quote')->loadByIdWithoutStore($this->_getEntityId());
|
| 66 |
+
|
| 67 |
+
$request = Mage::helper('marketingsoftware/rest_request');
|
| 68 |
+
$request->prepare();
|
| 69 |
+
|
| 70 |
+
if (Mage::helper('marketingsoftware/config')->getRemoveFinishedQuoteItem()) {
|
| 71 |
+
$quoteItemCollection = Mage::helper('marketingsoftware/config')->getQuoteItemCollectionId();
|
| 72 |
+
|
| 73 |
+
if ($quoteItemCollection) {
|
| 74 |
+
$response = $request->get('/profile/'.$customerEntity->getProfileId().'/subprofiles/'.$quoteItemCollection, array(
|
| 75 |
+
'fields' => array('quote_id=='.$this->_getEntityId())
|
| 76 |
+
));
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
foreach ($response['data'] as $subprofile) {
|
| 80 |
+
$request->delete('/subprofile/'.$subprofile['ID']);
|
| 81 |
+
}
|
| 82 |
+
} else {
|
| 83 |
+
foreach ($quote->getAllVisibleItems() as $quoteItem) {
|
| 84 |
+
$quoteItemEntity = Mage::getModel('marketingsoftware/copernica_entity_quote_item');
|
| 85 |
+
$quoteItemEntity->setQuoteItem($quoteItem);
|
| 86 |
+
|
| 87 |
+
$restQuoteItem = $quoteItemEntity->getRestQuoteItem();
|
| 88 |
+
$restQuoteItem->syncWithQuote($customerEntity, $quote->getId());
|
| 89 |
+
}
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
$request->commit();
|
| 93 |
+
|
| 94 |
+
return true;
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
protected function _getCustomerEntity()
|
| 98 |
+
{
|
| 99 |
+
if ($this->_customerEntity) {
|
| 100 |
+
return $this->_customerEntity;
|
| 101 |
+
} else {
|
| 102 |
+
$object = $this->_getObject();
|
| 103 |
+
|
| 104 |
+
if (property_exists($object, 'customerId') && is_numeric($object->customerId)) {
|
| 105 |
+
$customerEntity = Mage::getModel('marketingsoftware/copernica_entity_customer');
|
| 106 |
+
$customerEntity->setCustomer($object->customerId);
|
| 107 |
+
|
| 108 |
+
return $this->_customerEntity = $customerEntity;
|
| 109 |
+
} else {
|
| 110 |
+
return false;
|
| 111 |
+
}
|
| 112 |
+
}
|
| 113 |
+
}
|
| 114 |
}
|
app/code/community/Copernica/MarketingSoftware/Model/Queue/Event/Customer.php
CHANGED
|
@@ -1,158 +1,158 @@
|
|
| 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 |
-
* This class should take care of all actions performed with customer object.
|
| 29 |
-
* So any modification or additions should go via this class. Also this class
|
| 30 |
-
* can sync almost all customer data in one run via ::actionFull(). Full action
|
| 31 |
-
* should be used only when there is need to that.
|
| 32 |
-
*/
|
| 33 |
-
class Copernica_MarketingSoftware_Model_Queue_Event_Customer extends Copernica_MarketingSoftware_Model_Queue_Event_Abstract
|
| 34 |
-
{
|
| 35 |
-
/**
|
| 36 |
-
* Handle customer add action. It's basicaly the same as modify action.
|
| 37 |
-
*
|
| 38 |
-
* @return boolean
|
| 39 |
-
*/
|
| 40 |
-
public function actionAdd()
|
| 41 |
-
{
|
| 42 |
-
return $this->actionModify();
|
| 43 |
-
}
|
| 44 |
-
|
| 45 |
-
/**
|
| 46 |
-
* Handle customer modify action. This action should be called everytime
|
| 47 |
-
* when customer is modified. So on administrative edition or when customer
|
| 48 |
-
* himself is modifying his data.
|
| 49 |
-
*
|
| 50 |
-
* @return boolean
|
| 51 |
-
*/
|
| 52 |
-
public function actionModify()
|
| 53 |
-
{
|
| 54 |
-
$customerEntity = Mage::getModel('marketingsoftware/copernica_entity_customer');
|
| 55 |
-
$customerEntity->setCustomer($this->_getEntityId());
|
| 56 |
-
|
| 57 |
-
$restCustomer = $customerEntity->getRestCustomer();
|
| 58 |
-
$restCustomer->setProfile();
|
| 59 |
-
|
| 60 |
-
// $request = Mage::helper('marketingsoftware/rest_request');
|
| 61 |
-
// $request->prepare();
|
| 62 |
-
|
| 63 |
-
// foreach ($customerEntity->getAddresses() as $addressEntity) {
|
| 64 |
-
// $restAddress = $addressEntity->getRestAddress();
|
| 65 |
-
// $restAddress->bindToCustomer($customerEntity);
|
| 66 |
-
// }
|
| 67 |
-
|
| 68 |
-
// $request->commit();
|
| 69 |
-
|
| 70 |
-
return true;
|
| 71 |
-
}
|
| 72 |
-
|
| 73 |
-
/**
|
| 74 |
-
* Handle customer full sync action. This action should be called only when
|
| 75 |
-
* we want to sync whole customer. For example initial data sync when
|
| 76 |
-
* extension is installed for 1st time, or when changing copernica database.
|
| 77 |
-
*
|
| 78 |
-
* This action is expensive both with time and resources. It should be called
|
| 79 |
-
* only when there is a need for that.
|
| 80 |
-
*
|
| 81 |
-
* @return boolean
|
| 82 |
-
*/
|
| 83 |
-
public function actionFull()
|
| 84 |
-
{
|
| 85 |
-
$customerEntity = Mage::getModel('marketingsoftware/copernica_entity_customer');
|
| 86 |
-
$customerEntity->setCustomer($this->_getEntityId());
|
| 87 |
-
|
| 88 |
-
$restCustomer = $customerEntity->getRestCustomer();
|
| 89 |
-
$restCustomer->setProfile();
|
| 90 |
-
|
| 91 |
-
//$request = Mage::helper('marketingsoftware/rest_request');
|
| 92 |
-
//$request->prepare();
|
| 93 |
-
|
| 94 |
-
// foreach ($customerEntity->getAddresses() as $addressEntity) {
|
| 95 |
-
// $restAddress = $addressEntity->getRestAddress();
|
| 96 |
-
// $restAddress->bindToCustomer($customerEntity);
|
| 97 |
-
// }
|
| 98 |
-
|
| 99 |
-
foreach ($customerEntity->getOrders() as $orderEntity) {
|
| 100 |
-
$restOrder = $orderEntity->getRestOrder();
|
| 101 |
-
$restOrder->syncWithCustomer($customerEntity);
|
| 102 |
-
}
|
| 103 |
-
|
| 104 |
-
foreach($customerEntity->getWishlistItems() as $wishlistItemEntity) {
|
| 105 |
-
$restWishlistItem = $wishlistItemEntity->getRestWishlistItem();
|
| 106 |
-
$restWishlistItem->syncWithCustomer($customerEntity);
|
| 107 |
-
}
|
| 108 |
-
|
| 109 |
-
//$request->commit();
|
| 110 |
-
|
| 111 |
-
return true;
|
| 112 |
-
}
|
| 113 |
-
|
| 114 |
-
/**
|
| 115 |
-
* This action should be called only when there is a need to remove a customer
|
| 116 |
-
* from copernica platform.
|
| 117 |
-
*
|
| 118 |
-
* @return boolean
|
| 119 |
-
*/
|
| 120 |
-
public function actionRemove()
|
| 121 |
-
{
|
| 122 |
-
$object = $this->getObject();
|
| 123 |
-
|
| 124 |
-
if (property_exists($object, 'email') && property_exists($object, 'storeId')) {
|
| 125 |
-
$store = Mage::getModel('core/store')->load($object->storeId);
|
| 126 |
-
|
| 127 |
-
$website = $store->getWebsite();
|
| 128 |
-
|
| 129 |
-
$group = $store->getGroup();
|
| 130 |
-
|
| 131 |
-
$storeView = implode(' > ', array (
|
| 132 |
-
$website->getName(),
|
| 133 |
-
$group->getName(),
|
| 134 |
-
$store->getName())
|
| 135 |
-
);
|
| 136 |
-
|
| 137 |
-
$profileCacheCollection = Mage::getModel('marketingsoftware/profile_cache')
|
| 138 |
-
->getCollection()
|
| 139 |
-
->setPageSize(1)
|
| 140 |
-
->addFieldToFilter('email', $object->email)
|
| 141 |
-
->addFieldToFilter('store_view', $storeView);
|
| 142 |
-
|
| 143 |
-
$profileCache = $profileCacheCollection->getFirstItem();
|
| 144 |
-
|
| 145 |
-
if (!$profileCache->isObjectNew()) {
|
| 146 |
-
$profileCache->delete();
|
| 147 |
-
}
|
| 148 |
-
}
|
| 149 |
-
|
| 150 |
-
if (!property_exists($object, 'profileId')) {
|
| 151 |
-
return false;
|
| 152 |
-
}
|
| 153 |
-
|
| 154 |
-
Mage::helper('marketingsoftware/rest_request')->delete('/profile/'.$object->profileId);
|
| 155 |
-
|
| 156 |
-
return true;
|
| 157 |
-
}
|
| 158 |
}
|
| 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 |
+
* This class should take care of all actions performed with customer object.
|
| 29 |
+
* So any modification or additions should go via this class. Also this class
|
| 30 |
+
* can sync almost all customer data in one run via ::actionFull(). Full action
|
| 31 |
+
* should be used only when there is need to that.
|
| 32 |
+
*/
|
| 33 |
+
class Copernica_MarketingSoftware_Model_Queue_Event_Customer extends Copernica_MarketingSoftware_Model_Queue_Event_Abstract
|
| 34 |
+
{
|
| 35 |
+
/**
|
| 36 |
+
* Handle customer add action. It's basicaly the same as modify action.
|
| 37 |
+
*
|
| 38 |
+
* @return boolean
|
| 39 |
+
*/
|
| 40 |
+
public function actionAdd()
|
| 41 |
+
{
|
| 42 |
+
return $this->actionModify();
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
/**
|
| 46 |
+
* Handle customer modify action. This action should be called everytime
|
| 47 |
+
* when customer is modified. So on administrative edition or when customer
|
| 48 |
+
* himself is modifying his data.
|
| 49 |
+
*
|
| 50 |
+
* @return boolean
|
| 51 |
+
*/
|
| 52 |
+
public function actionModify()
|
| 53 |
+
{
|
| 54 |
+
$customerEntity = Mage::getModel('marketingsoftware/copernica_entity_customer');
|
| 55 |
+
$customerEntity->setCustomer($this->_getEntityId());
|
| 56 |
+
|
| 57 |
+
$restCustomer = $customerEntity->getRestCustomer();
|
| 58 |
+
$restCustomer->setProfile();
|
| 59 |
+
|
| 60 |
+
// $request = Mage::helper('marketingsoftware/rest_request');
|
| 61 |
+
// $request->prepare();
|
| 62 |
+
|
| 63 |
+
// foreach ($customerEntity->getAddresses() as $addressEntity) {
|
| 64 |
+
// $restAddress = $addressEntity->getRestAddress();
|
| 65 |
+
// $restAddress->bindToCustomer($customerEntity);
|
| 66 |
+
// }
|
| 67 |
+
|
| 68 |
+
// $request->commit();
|
| 69 |
+
|
| 70 |
+
return true;
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
/**
|
| 74 |
+
* Handle customer full sync action. This action should be called only when
|
| 75 |
+
* we want to sync whole customer. For example initial data sync when
|
| 76 |
+
* extension is installed for 1st time, or when changing copernica database.
|
| 77 |
+
*
|
| 78 |
+
* This action is expensive both with time and resources. It should be called
|
| 79 |
+
* only when there is a need for that.
|
| 80 |
+
*
|
| 81 |
+
* @return boolean
|
| 82 |
+
*/
|
| 83 |
+
public function actionFull()
|
| 84 |
+
{
|
| 85 |
+
$customerEntity = Mage::getModel('marketingsoftware/copernica_entity_customer');
|
| 86 |
+
$customerEntity->setCustomer($this->_getEntityId());
|
| 87 |
+
|
| 88 |
+
$restCustomer = $customerEntity->getRestCustomer();
|
| 89 |
+
$restCustomer->setProfile();
|
| 90 |
+
|
| 91 |
+
//$request = Mage::helper('marketingsoftware/rest_request');
|
| 92 |
+
//$request->prepare();
|
| 93 |
+
|
| 94 |
+
// foreach ($customerEntity->getAddresses() as $addressEntity) {
|
| 95 |
+
// $restAddress = $addressEntity->getRestAddress();
|
| 96 |
+
// $restAddress->bindToCustomer($customerEntity);
|
| 97 |
+
// }
|
| 98 |
+
|
| 99 |
+
foreach ($customerEntity->getOrders() as $orderEntity) {
|
| 100 |
+
$restOrder = $orderEntity->getRestOrder();
|
| 101 |
+
$restOrder->syncWithCustomer($customerEntity);
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
foreach($customerEntity->getWishlistItems() as $wishlistItemEntity) {
|
| 105 |
+
$restWishlistItem = $wishlistItemEntity->getRestWishlistItem();
|
| 106 |
+
$restWishlistItem->syncWithCustomer($customerEntity);
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
//$request->commit();
|
| 110 |
+
|
| 111 |
+
return true;
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
/**
|
| 115 |
+
* This action should be called only when there is a need to remove a customer
|
| 116 |
+
* from copernica platform.
|
| 117 |
+
*
|
| 118 |
+
* @return boolean
|
| 119 |
+
*/
|
| 120 |
+
public function actionRemove()
|
| 121 |
+
{
|
| 122 |
+
$object = $this->getObject();
|
| 123 |
+
|
| 124 |
+
if (property_exists($object, 'email') && property_exists($object, 'storeId')) {
|
| 125 |
+
$store = Mage::getModel('core/store')->load($object->storeId);
|
| 126 |
+
|
| 127 |
+
$website = $store->getWebsite();
|
| 128 |
+
|
| 129 |
+
$group = $store->getGroup();
|
| 130 |
+
|
| 131 |
+
$storeView = implode(' > ', array (
|
| 132 |
+
$website->getName(),
|
| 133 |
+
$group->getName(),
|
| 134 |
+
$store->getName())
|
| 135 |
+
);
|
| 136 |
+
|
| 137 |
+
$profileCacheCollection = Mage::getModel('marketingsoftware/profile_cache')
|
| 138 |
+
->getCollection()
|
| 139 |
+
->setPageSize(1)
|
| 140 |
+
->addFieldToFilter('email', $object->email)
|
| 141 |
+
->addFieldToFilter('store_view', $storeView);
|
| 142 |
+
|
| 143 |
+
$profileCache = $profileCacheCollection->getFirstItem();
|
| 144 |
+
|
| 145 |
+
if (!$profileCache->isObjectNew()) {
|
| 146 |
+
$profileCache->delete();
|
| 147 |
+
}
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
if (!property_exists($object, 'profileId')) {
|
| 151 |
+
return false;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
Mage::helper('marketingsoftware/rest_request')->delete('/profile/'.$object->profileId);
|
| 155 |
+
|
| 156 |
+
return true;
|
| 157 |
+
}
|
| 158 |
}
|
app/code/community/Copernica/MarketingSoftware/Model/Queue/Event/Factory.php
CHANGED
|
@@ -1,96 +1,96 @@
|
|
| 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 |
-
* Factory class for getting queue event objects
|
| 29 |
-
*/
|
| 30 |
-
class Copernica_MarketingSoftware_Model_Queue_Event_Factory
|
| 31 |
-
{
|
| 32 |
-
/**
|
| 33 |
-
* Get the right object
|
| 34 |
-
*
|
| 35 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Quote|Copernica_MarketingSoftware_Model_Abstraction_Quote_item|Copernica_MarketingSoftware_Model_Abstraction_Customer|Copernica_MarketingSoftware_Model_Abstraction_Order|Copernica_MarketingSoftware_Model_Abstraction_Subscription|Copernica_MarketingSoftware_Model_Abstraction_Product_Viewed
|
| 36 |
-
*/
|
| 37 |
-
public function get($queueItem)
|
| 38 |
-
{
|
| 39 |
-
if ($queueItem->getAction() == 'start_sync') {
|
| 40 |
-
$classname = Mage::getConfig()->getModelClassName('marketingsoftware/queue_event_startsync');
|
| 41 |
-
|
| 42 |
-
return new $classname($queueItem);
|
| 43 |
-
}
|
| 44 |
-
|
| 45 |
-
if ($queueItem->getAction() == 'upgrade') {
|
| 46 |
-
$classname = Mage::getConfig()->getModelClassName('marketingsoftware/queue_event_customer_upgrade');
|
| 47 |
-
|
| 48 |
-
return new $classname($queueItem);
|
| 49 |
-
}
|
| 50 |
-
|
| 51 |
-
$action = ucfirst($queueItem->getAction());
|
| 52 |
-
|
| 53 |
-
switch (get_class($queueItem->getObject()))
|
| 54 |
-
{
|
| 55 |
-
case "Copernica_MarketingSoftware_Model_Abstraction_Quote":
|
| 56 |
-
$classname = "marketingsoftware/queue_event_quote".$action;
|
| 57 |
-
break;
|
| 58 |
-
|
| 59 |
-
case "Copernica_MarketingSoftware_Model_Abstraction_Quote_item":
|
| 60 |
-
$classname = "marketingsoftware/queue_event_quote_item".$action;
|
| 61 |
-
break;
|
| 62 |
-
|
| 63 |
-
case "Copernica_MarketingSoftware_Model_Abstraction_Customer":
|
| 64 |
-
$classname = "marketingsoftware/queue_event_customer".$action;
|
| 65 |
-
break;
|
| 66 |
-
|
| 67 |
-
case "Copernica_MarketingSoftware_Model_Abstraction_Order":
|
| 68 |
-
$classname = "marketingsoftware/queue_event_order".$action;
|
| 69 |
-
break;
|
| 70 |
-
|
| 71 |
-
case "Copernica_MarketingSoftware_Model_Abstraction_Subscription":
|
| 72 |
-
$classname = "marketingsoftware/queue_event_subscription".$action;
|
| 73 |
-
break;
|
| 74 |
-
|
| 75 |
-
case "Copernica_MarketingSoftware_Model_Abstraction_Product_Viewed":
|
| 76 |
-
$classname = "marketingsoftware/queue_event_product_viewed".$action;
|
| 77 |
-
break;
|
| 78 |
-
|
| 79 |
-
case "Copernica_MarketingSoftware_Model_Abstraction_Wishlist":
|
| 80 |
-
$classname = "marketingsoftware/queue_event_wishlist".$action;
|
| 81 |
-
break;
|
| 82 |
-
}
|
| 83 |
-
|
| 84 |
-
if (!isset($classname)) {
|
| 85 |
-
throw Mage::exception('Copernica_MarketingSoftware', 'Event type does not exists: '.$classname, Copernica_MarketingSoftware_Exception::EVENT_NO_TYPE);
|
| 86 |
-
}
|
| 87 |
-
|
| 88 |
-
$classname = Mage::getConfig()->getModelClassName($classname);
|
| 89 |
-
|
| 90 |
-
if (!class_exists($classname)) {
|
| 91 |
-
throw Mage::exception('Copernica_MarketingSoftware', 'Event type does not exists: '.$classname, Copernica_MarketingSoftware_Exception::EVENT_TYPE_NOT_EXISTS);
|
| 92 |
-
}
|
| 93 |
-
|
| 94 |
-
return new $classname($queueItem);
|
| 95 |
-
}
|
| 96 |
}
|
| 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 |
+
* Factory class for getting queue event objects
|
| 29 |
+
*/
|
| 30 |
+
class Copernica_MarketingSoftware_Model_Queue_Event_Factory
|
| 31 |
+
{
|
| 32 |
+
/**
|
| 33 |
+
* Get the right object
|
| 34 |
+
*
|
| 35 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Quote|Copernica_MarketingSoftware_Model_Abstraction_Quote_item|Copernica_MarketingSoftware_Model_Abstraction_Customer|Copernica_MarketingSoftware_Model_Abstraction_Order|Copernica_MarketingSoftware_Model_Abstraction_Subscription|Copernica_MarketingSoftware_Model_Abstraction_Product_Viewed
|
| 36 |
+
*/
|
| 37 |
+
public function get($queueItem)
|
| 38 |
+
{
|
| 39 |
+
if ($queueItem->getAction() == 'start_sync') {
|
| 40 |
+
$classname = Mage::getConfig()->getModelClassName('marketingsoftware/queue_event_startsync');
|
| 41 |
+
|
| 42 |
+
return new $classname($queueItem);
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
if ($queueItem->getAction() == 'upgrade') {
|
| 46 |
+
$classname = Mage::getConfig()->getModelClassName('marketingsoftware/queue_event_customer_upgrade');
|
| 47 |
+
|
| 48 |
+
return new $classname($queueItem);
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
$action = ucfirst($queueItem->getAction());
|
| 52 |
+
|
| 53 |
+
switch (get_class($queueItem->getObject()))
|
| 54 |
+
{
|
| 55 |
+
case "Copernica_MarketingSoftware_Model_Abstraction_Quote":
|
| 56 |
+
$classname = "marketingsoftware/queue_event_quote".$action;
|
| 57 |
+
break;
|
| 58 |
+
|
| 59 |
+
case "Copernica_MarketingSoftware_Model_Abstraction_Quote_item":
|
| 60 |
+
$classname = "marketingsoftware/queue_event_quote_item".$action;
|
| 61 |
+
break;
|
| 62 |
+
|
| 63 |
+
case "Copernica_MarketingSoftware_Model_Abstraction_Customer":
|
| 64 |
+
$classname = "marketingsoftware/queue_event_customer".$action;
|
| 65 |
+
break;
|
| 66 |
+
|
| 67 |
+
case "Copernica_MarketingSoftware_Model_Abstraction_Order":
|
| 68 |
+
$classname = "marketingsoftware/queue_event_order".$action;
|
| 69 |
+
break;
|
| 70 |
+
|
| 71 |
+
case "Copernica_MarketingSoftware_Model_Abstraction_Subscription":
|
| 72 |
+
$classname = "marketingsoftware/queue_event_subscription".$action;
|
| 73 |
+
break;
|
| 74 |
+
|
| 75 |
+
case "Copernica_MarketingSoftware_Model_Abstraction_Product_Viewed":
|
| 76 |
+
$classname = "marketingsoftware/queue_event_product_viewed".$action;
|
| 77 |
+
break;
|
| 78 |
+
|
| 79 |
+
case "Copernica_MarketingSoftware_Model_Abstraction_Wishlist":
|
| 80 |
+
$classname = "marketingsoftware/queue_event_wishlist".$action;
|
| 81 |
+
break;
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
if (!isset($classname)) {
|
| 85 |
+
throw Mage::exception('Copernica_MarketingSoftware', 'Event type does not exists: '.$classname, Copernica_MarketingSoftware_Exception::EVENT_NO_TYPE);
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
$classname = Mage::getConfig()->getModelClassName($classname);
|
| 89 |
+
|
| 90 |
+
if (!class_exists($classname)) {
|
| 91 |
+
throw Mage::exception('Copernica_MarketingSoftware', 'Event type does not exists: '.$classname, Copernica_MarketingSoftware_Exception::EVENT_TYPE_NOT_EXISTS);
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
return new $classname($queueItem);
|
| 95 |
+
}
|
| 96 |
}
|
app/code/community/Copernica/MarketingSoftware/Model/Queue/Event/Item.php
CHANGED
|
@@ -1,176 +1,176 @@
|
|
| 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 |
-
* This class will take care of syncing items
|
| 29 |
-
*/
|
| 30 |
-
class Copernica_MarketingSoftware_Model_Queue_Event_Item extends Copernica_MarketingSoftware_Model_Queue_Event_Abstract
|
| 31 |
-
{
|
| 32 |
-
/**
|
| 33 |
-
* Process modify action
|
| 34 |
-
*
|
| 35 |
-
* @return boolean
|
| 36 |
-
*/
|
| 37 |
-
public function actionModify()
|
| 38 |
-
{
|
| 39 |
-
$object = $this->_getObject();
|
| 40 |
-
|
| 41 |
-
if(!$object->quoteId || !is_numeric($object->quoteId)) {
|
| 42 |
-
return false;
|
| 43 |
-
}
|
| 44 |
-
|
| 45 |
-
if ($object->customerId && is_numeric($object->customerId) ) {
|
| 46 |
-
$this->syncQuote();
|
| 47 |
-
}
|
| 48 |
-
|
| 49 |
-
$collection = Mage::getModel('marketingsoftware/abandoned_cart')->getCollection()->addFieldToFilter('quote_id', $object->quoteId);
|
| 50 |
-
|
| 51 |
-
$abandonedCart = $collection->getFirstItem();
|
| 52 |
-
|
| 53 |
-
if ($abandonedCart->isObjectNew()) {
|
| 54 |
-
return true;
|
| 55 |
-
}
|
| 56 |
-
|
| 57 |
-
$abandonedCart->delete();
|
| 58 |
-
|
| 59 |
-
$queue = Mage::getModel('marketingsoftware/queue_item')
|
| 60 |
-
->setObject(array('quoteId' => $object->quoteId))
|
| 61 |
-
->setCustomer($object->customerId)
|
| 62 |
-
->setAction('modify')
|
| 63 |
-
->setName('quote')
|
| 64 |
-
->setEntityId($object->quoteId)
|
| 65 |
-
->save();
|
| 66 |
-
|
| 67 |
-
return true;
|
| 68 |
-
}
|
| 69 |
-
|
| 70 |
-
/**
|
| 71 |
-
* Process add action.
|
| 72 |
-
*
|
| 73 |
-
* @return boolean
|
| 74 |
-
*/
|
| 75 |
-
public function actionAdd()
|
| 76 |
-
{
|
| 77 |
-
return $this->actionModify();
|
| 78 |
-
}
|
| 79 |
-
|
| 80 |
-
/**
|
| 81 |
-
* Process remove action
|
| 82 |
-
*
|
| 83 |
-
* @return boolean
|
| 84 |
-
*/
|
| 85 |
-
public function actionRemove()
|
| 86 |
-
{
|
| 87 |
-
$object = $this->_getObject();
|
| 88 |
-
|
| 89 |
-
if (!$object->quoteId || !is_numeric($object->quoteId) || !$object->customerId || !is_numeric($object->customerId) || !$object->quoteItem) {
|
| 90 |
-
return false;
|
| 91 |
-
}
|
| 92 |
-
|
| 93 |
-
$quoteItemData = get_object_vars($object->quoteItem);
|
| 94 |
-
|
| 95 |
-
$request = Mage::helper('marketingsoftware/rest_request');
|
| 96 |
-
|
| 97 |
-
$itemId = $quoteItemData['item_id'];
|
| 98 |
-
|
| 99 |
-
$quoteId = $object->quoteId;
|
| 100 |
-
|
| 101 |
-
$store = Mage::getModel('core/store')->load($quoteItemData['storeview_id']);
|
| 102 |
-
|
| 103 |
-
$storeview = Mage::getModel('marketingsoftware/abstraction_storeview')->setOriginal($store);
|
| 104 |
-
|
| 105 |
-
$customerEntity = Mage::getModel('marketingsoftware/copernica_entity_customer');
|
| 106 |
-
$customerEntity->setCustomer($object->customerId);
|
| 107 |
-
$customerEntity->setStore($storeview);
|
| 108 |
-
|
| 109 |
-
if (($profileId = $customerEntity->getProfileId()) === false) {
|
| 110 |
-
return false;
|
| 111 |
-
}
|
| 112 |
-
|
| 113 |
-
$quoteItemCollectionId = Mage::helper('marketingsoftware/config')->getQuoteItemCollectionId();
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
$response = $request->get('/profile/'.$profileId.'/subprofiles/'.$quoteItemCollectionId, array(
|
| 117 |
-
'item_id' => $itemId,
|
| 118 |
-
'quote_id' => $quoteId,
|
| 119 |
-
));
|
| 120 |
-
|
| 121 |
-
if (!array_key_exists('data', $response) || count($response['data']) == 0) {
|
| 122 |
-
if (!Mage::helper('marketingsoftware/config')->getRemoveFinishedQuoteItem()) {
|
| 123 |
-
$request->post('/profile/'.$profileId.'/subprofiles/'.$quoteItemCollectionId, $quoteItemData);
|
| 124 |
-
}
|
| 125 |
-
|
| 126 |
-
return true;
|
| 127 |
-
}
|
| 128 |
-
|
| 129 |
-
if (Mage::helper('marketingsoftware/config')->getRemoveFinishedQuoteItem()) {
|
| 130 |
-
foreach ($response['data'] as $subprofile) {
|
| 131 |
-
$request->delete('/subprofile/'.$subprofile['ID']);
|
| 132 |
-
}
|
| 133 |
-
} else {
|
| 134 |
-
$request->put('/profile/'.$profileId.'/subprofiles/'.$quoteItemCollectionId, array(
|
| 135 |
-
'status' => 'deleted'
|
| 136 |
-
), array (
|
| 137 |
-
'fields' => array(
|
| 138 |
-
'quote_id=='.$quoteId,
|
| 139 |
-
'item_id=='.$itemId
|
| 140 |
-
)
|
| 141 |
-
));
|
| 142 |
-
}
|
| 143 |
-
|
| 144 |
-
return true;
|
| 145 |
-
}
|
| 146 |
-
|
| 147 |
-
/**
|
| 148 |
-
* Sync item with quote
|
| 149 |
-
*/
|
| 150 |
-
public function syncQuote()
|
| 151 |
-
{
|
| 152 |
-
$object = $this->_getObject();
|
| 153 |
-
|
| 154 |
-
if (!$object->customerId || !is_numeric($object->customerId)) {
|
| 155 |
-
return false;
|
| 156 |
-
}
|
| 157 |
-
|
| 158 |
-
if($object->quoteId && is_numeric($object->quoteId)) {
|
| 159 |
-
$quoteId = $object->quoteId;
|
| 160 |
-
} else {
|
| 161 |
-
$quote = Mage::getModel('sales/quote')->loadByCustomer($object->customerId);
|
| 162 |
-
$quoteId = $quote->getId();
|
| 163 |
-
}
|
| 164 |
-
|
| 165 |
-
$quoteItem = Mage::getModel('sales/quote_item')->load($object->quoteItemId);
|
| 166 |
-
|
| 167 |
-
$customerEntity = Mage::getModel('marketingsoftware/copernica_entity_customer');
|
| 168 |
-
$customerEntity->setCustomer($object->customerId);
|
| 169 |
-
|
| 170 |
-
$quoteItemEntity = Mage::getModel('marketingsoftware/copernica_entity_quote_item');
|
| 171 |
-
$quoteItemEntity->setQuoteItem($quoteItem);
|
| 172 |
-
|
| 173 |
-
$restQuoteItem = $quoteItemEntity->getRestQuoteItem();
|
| 174 |
-
$restQuoteItem->syncWithQuote($customerEntity, $quoteId);
|
| 175 |
-
}
|
| 176 |
-
}
|
| 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 |
+
* This class will take care of syncing items
|
| 29 |
+
*/
|
| 30 |
+
class Copernica_MarketingSoftware_Model_Queue_Event_Item extends Copernica_MarketingSoftware_Model_Queue_Event_Abstract
|
| 31 |
+
{
|
| 32 |
+
/**
|
| 33 |
+
* Process modify action
|
| 34 |
+
*
|
| 35 |
+
* @return boolean
|
| 36 |
+
*/
|
| 37 |
+
public function actionModify()
|
| 38 |
+
{
|
| 39 |
+
$object = $this->_getObject();
|
| 40 |
+
|
| 41 |
+
if(!$object->quoteId || !is_numeric($object->quoteId)) {
|
| 42 |
+
return false;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
if ($object->customerId && is_numeric($object->customerId) ) {
|
| 46 |
+
$this->syncQuote();
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
$collection = Mage::getModel('marketingsoftware/abandoned_cart')->getCollection()->addFieldToFilter('quote_id', $object->quoteId);
|
| 50 |
+
|
| 51 |
+
$abandonedCart = $collection->getFirstItem();
|
| 52 |
+
|
| 53 |
+
if ($abandonedCart->isObjectNew()) {
|
| 54 |
+
return true;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
$abandonedCart->delete();
|
| 58 |
+
|
| 59 |
+
$queue = Mage::getModel('marketingsoftware/queue_item')
|
| 60 |
+
->setObject(array('quoteId' => $object->quoteId))
|
| 61 |
+
->setCustomer($object->customerId)
|
| 62 |
+
->setAction('modify')
|
| 63 |
+
->setName('quote')
|
| 64 |
+
->setEntityId($object->quoteId)
|
| 65 |
+
->save();
|
| 66 |
+
|
| 67 |
+
return true;
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
/**
|
| 71 |
+
* Process add action.
|
| 72 |
+
*
|
| 73 |
+
* @return boolean
|
| 74 |
+
*/
|
| 75 |
+
public function actionAdd()
|
| 76 |
+
{
|
| 77 |
+
return $this->actionModify();
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
/**
|
| 81 |
+
* Process remove action
|
| 82 |
+
*
|
| 83 |
+
* @return boolean
|
| 84 |
+
*/
|
| 85 |
+
public function actionRemove()
|
| 86 |
+
{
|
| 87 |
+
$object = $this->_getObject();
|
| 88 |
+
|
| 89 |
+
if (!$object->quoteId || !is_numeric($object->quoteId) || !$object->customerId || !is_numeric($object->customerId) || !$object->quoteItem) {
|
| 90 |
+
return false;
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
$quoteItemData = get_object_vars($object->quoteItem);
|
| 94 |
+
|
| 95 |
+
$request = Mage::helper('marketingsoftware/rest_request');
|
| 96 |
+
|
| 97 |
+
$itemId = $quoteItemData['item_id'];
|
| 98 |
+
|
| 99 |
+
$quoteId = $object->quoteId;
|
| 100 |
+
|
| 101 |
+
$store = Mage::getModel('core/store')->load($quoteItemData['storeview_id']);
|
| 102 |
+
|
| 103 |
+
$storeview = Mage::getModel('marketingsoftware/abstraction_storeview')->setOriginal($store);
|
| 104 |
+
|
| 105 |
+
$customerEntity = Mage::getModel('marketingsoftware/copernica_entity_customer');
|
| 106 |
+
$customerEntity->setCustomer($object->customerId);
|
| 107 |
+
$customerEntity->setStore($storeview);
|
| 108 |
+
|
| 109 |
+
if (($profileId = $customerEntity->getProfileId()) === false) {
|
| 110 |
+
return false;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
$quoteItemCollectionId = Mage::helper('marketingsoftware/config')->getQuoteItemCollectionId();
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
$response = $request->get('/profile/'.$profileId.'/subprofiles/'.$quoteItemCollectionId, array(
|
| 117 |
+
'item_id' => $itemId,
|
| 118 |
+
'quote_id' => $quoteId,
|
| 119 |
+
));
|
| 120 |
+
|
| 121 |
+
if (!array_key_exists('data', $response) || count($response['data']) == 0) {
|
| 122 |
+
if (!Mage::helper('marketingsoftware/config')->getRemoveFinishedQuoteItem()) {
|
| 123 |
+
$request->post('/profile/'.$profileId.'/subprofiles/'.$quoteItemCollectionId, $quoteItemData);
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
return true;
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
if (Mage::helper('marketingsoftware/config')->getRemoveFinishedQuoteItem()) {
|
| 130 |
+
foreach ($response['data'] as $subprofile) {
|
| 131 |
+
$request->delete('/subprofile/'.$subprofile['ID']);
|
| 132 |
+
}
|
| 133 |
+
} else {
|
| 134 |
+
$request->put('/profile/'.$profileId.'/subprofiles/'.$quoteItemCollectionId, array(
|
| 135 |
+
'status' => 'deleted'
|
| 136 |
+
), array (
|
| 137 |
+
'fields' => array(
|
| 138 |
+
'quote_id=='.$quoteId,
|
| 139 |
+
'item_id=='.$itemId
|
| 140 |
+
)
|
| 141 |
+
));
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
return true;
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
/**
|
| 148 |
+
* Sync item with quote
|
| 149 |
+
*/
|
| 150 |
+
public function syncQuote()
|
| 151 |
+
{
|
| 152 |
+
$object = $this->_getObject();
|
| 153 |
+
|
| 154 |
+
if (!$object->customerId || !is_numeric($object->customerId)) {
|
| 155 |
+
return false;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
if($object->quoteId && is_numeric($object->quoteId)) {
|
| 159 |
+
$quoteId = $object->quoteId;
|
| 160 |
+
} else {
|
| 161 |
+
$quote = Mage::getModel('sales/quote')->loadByCustomer($object->customerId);
|
| 162 |
+
$quoteId = $quote->getId();
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
$quoteItem = Mage::getModel('sales/quote_item')->load($object->quoteItemId);
|
| 166 |
+
|
| 167 |
+
$customerEntity = Mage::getModel('marketingsoftware/copernica_entity_customer');
|
| 168 |
+
$customerEntity->setCustomer($object->customerId);
|
| 169 |
+
|
| 170 |
+
$quoteItemEntity = Mage::getModel('marketingsoftware/copernica_entity_quote_item');
|
| 171 |
+
$quoteItemEntity->setQuoteItem($quoteItem);
|
| 172 |
+
|
| 173 |
+
$restQuoteItem = $quoteItemEntity->getRestQuoteItem();
|
| 174 |
+
$restQuoteItem->syncWithQuote($customerEntity, $quoteId);
|
| 175 |
+
}
|
| 176 |
+
}
|
app/code/community/Copernica/MarketingSoftware/Model/Queue/Event/Order.php
CHANGED
|
@@ -1,159 +1,159 @@
|
|
| 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 |
-
* This clas will take care of all events associated with order
|
| 29 |
-
*/
|
| 30 |
-
class Copernica_MarketingSoftware_Model_Queue_Event_Order extends Copernica_MarketingSoftware_Model_Queue_Event_Abstract
|
| 31 |
-
{
|
| 32 |
-
/**
|
| 33 |
-
* Customer entity
|
| 34 |
-
*
|
| 35 |
-
* @var Copernica_MarketingSoftware_Model_Copernica_Entity_Customer
|
| 36 |
-
*/
|
| 37 |
-
protected $_customerEntity;
|
| 38 |
-
|
| 39 |
-
/**
|
| 40 |
-
* This action will be run on order modify event
|
| 41 |
-
*
|
| 42 |
-
* @return boolean
|
| 43 |
-
*/
|
| 44 |
-
public function actionModify()
|
| 45 |
-
{
|
| 46 |
-
$vanillaOrder = Mage::getModel('sales/order')->load($this->_getEntityId());
|
| 47 |
-
|
| 48 |
-
$orderEntity = Mage::getModel('marketingsoftware/copernica_entity_order');
|
| 49 |
-
$orderEntity->setOrder($vanillaOrder);
|
| 50 |
-
|
| 51 |
-
$restOrder = $orderEntity->getRestOrder();
|
| 52 |
-
|
| 53 |
-
$customerEntity = $this->_getCustomerEntity();
|
| 54 |
-
|
| 55 |
-
if ($customerEntity) {
|
| 56 |
-
return $restOrder->syncWithCustomer($customerEntity);
|
| 57 |
-
} else {
|
| 58 |
-
$data = array (
|
| 59 |
-
'email' => $vanillaOrder->getCustomerEmail(),
|
| 60 |
-
'storeView' => (string) $orderEntity->getStoreView(),
|
| 61 |
-
'storeViewId' => $vanillaOrder->getStoreId(),
|
| 62 |
-
'firstname' => $vanillaOrder->getCustomerFirstname(),
|
| 63 |
-
'lastname' => $vanillaOrder->getCustomerLastname(),
|
| 64 |
-
);
|
| 65 |
-
|
| 66 |
-
if ($middlename = $vanillaOrder->getCustomerMiddlename()) {
|
| 67 |
-
$data['middlename'] = $middlename;
|
| 68 |
-
}
|
| 69 |
-
|
| 70 |
-
if ($dateOfBirth = $vanillaOrder->getCustomerDob()) {
|
| 71 |
-
$data['birthdate'] = date('Y-m-d H:i:s', strtotime($dateOfBirth));
|
| 72 |
-
}
|
| 73 |
-
|
| 74 |
-
if ($gender = $vanillaOrder->getCustomerGender()) {
|
| 75 |
-
$options = Mage::getModel('customer/customer')->getAttribute('gender')->getSource()->getAllOptions();
|
| 76 |
-
|
| 77 |
-
foreach ($options as $option) {
|
| 78 |
-
if ($option['value'] == $gender) {
|
| 79 |
-
$gender = $option['label'];
|
| 80 |
-
}
|
| 81 |
-
}
|
| 82 |
-
|
| 83 |
-
$data['gender'] = $gender;
|
| 84 |
-
}
|
| 85 |
-
|
| 86 |
-
$group = $vanillaOrder->getCustomerGroupId();
|
| 87 |
-
$group = Mage::getModel('customer/group')->load($group)->getCode();
|
| 88 |
-
$data['group'] = $group;
|
| 89 |
-
|
| 90 |
-
return $restOrder->syncWithGuest($data);
|
| 91 |
-
}
|
| 92 |
-
}
|
| 93 |
-
|
| 94 |
-
/**
|
| 95 |
-
* This action will be run on order add event
|
| 96 |
-
*
|
| 97 |
-
* @return boolean
|
| 98 |
-
*/
|
| 99 |
-
public function actionAdd()
|
| 100 |
-
{
|
| 101 |
-
$this->actionModify();
|
| 102 |
-
|
| 103 |
-
$order = Mage::getModel('sales/order')->load($this->_getEntityId());
|
| 104 |
-
|
| 105 |
-
$customerEntity = $this->_getCustomerEntity();
|
| 106 |
-
|
| 107 |
-
if(!$customerEntity) {
|
| 108 |
-
return true;
|
| 109 |
-
}
|
| 110 |
-
|
| 111 |
-
$request = Mage::helper('marketingsoftware/rest_request');
|
| 112 |
-
|
| 113 |
-
$quoteItemCollection = Mage::helper('marketingsoftware/config')->getQuoteItemCollectionId();
|
| 114 |
-
|
| 115 |
-
if ($quoteItemCollection) {
|
| 116 |
-
$response = $request->get('/profile/'.$customerEntity->getProfileId().'/subprofiles/'.$quoteItemCollection, array(
|
| 117 |
-
'fields' => array('quote_id=='.$order->getQuoteId())
|
| 118 |
-
));
|
| 119 |
-
}
|
| 120 |
-
|
| 121 |
-
if (array_key_exists('data', $response) || count($response['data']) == 0) {
|
| 122 |
-
return true;
|
| 123 |
-
}
|
| 124 |
-
|
| 125 |
-
$request->prepare();
|
| 126 |
-
|
| 127 |
-
if (Mage::helper('marketingsoftware/config')->getRemoveFinishedQuoteItem()) {
|
| 128 |
-
foreach ($response['data'] as $subprofile) {
|
| 129 |
-
$request->delete('/subprofile/'.$subprofile['ID']);
|
| 130 |
-
}
|
| 131 |
-
} else {
|
| 132 |
-
foreach ($response['data'] as $subprofile) {
|
| 133 |
-
$request->put('/subprofile/'.$subprofile['ID'].'/fields/', array('status' => 'completed'));
|
| 134 |
-
}
|
| 135 |
-
}
|
| 136 |
-
|
| 137 |
-
$request->commit();
|
| 138 |
-
|
| 139 |
-
return true;
|
| 140 |
-
}
|
| 141 |
-
|
| 142 |
-
protected function _getCustomerEntity()
|
| 143 |
-
{
|
| 144 |
-
if ($this->_customerEntity) {
|
| 145 |
-
return $this->_customerEntity;
|
| 146 |
-
} else {
|
| 147 |
-
$object = $this->_getObject();
|
| 148 |
-
|
| 149 |
-
if ($object->customerId && is_numeric($object->customerId)) {
|
| 150 |
-
$customerEntity = Mage::getModel('marketingsoftware/copernica_entity_customer');
|
| 151 |
-
$customerEntity->setCustomer($object->customerId);
|
| 152 |
-
|
| 153 |
-
return $this->_customerEntity = $customerEntity;
|
| 154 |
-
} else {
|
| 155 |
-
return false;
|
| 156 |
-
}
|
| 157 |
-
}
|
| 158 |
-
}
|
| 159 |
}
|
| 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 |
+
* This clas will take care of all events associated with order
|
| 29 |
+
*/
|
| 30 |
+
class Copernica_MarketingSoftware_Model_Queue_Event_Order extends Copernica_MarketingSoftware_Model_Queue_Event_Abstract
|
| 31 |
+
{
|
| 32 |
+
/**
|
| 33 |
+
* Customer entity
|
| 34 |
+
*
|
| 35 |
+
* @var Copernica_MarketingSoftware_Model_Copernica_Entity_Customer
|
| 36 |
+
*/
|
| 37 |
+
protected $_customerEntity;
|
| 38 |
+
|
| 39 |
+
/**
|
| 40 |
+
* This action will be run on order modify event
|
| 41 |
+
*
|
| 42 |
+
* @return boolean
|
| 43 |
+
*/
|
| 44 |
+
public function actionModify()
|
| 45 |
+
{
|
| 46 |
+
$vanillaOrder = Mage::getModel('sales/order')->load($this->_getEntityId());
|
| 47 |
+
|
| 48 |
+
$orderEntity = Mage::getModel('marketingsoftware/copernica_entity_order');
|
| 49 |
+
$orderEntity->setOrder($vanillaOrder);
|
| 50 |
+
|
| 51 |
+
$restOrder = $orderEntity->getRestOrder();
|
| 52 |
+
|
| 53 |
+
$customerEntity = $this->_getCustomerEntity();
|
| 54 |
+
|
| 55 |
+
if ($customerEntity) {
|
| 56 |
+
return $restOrder->syncWithCustomer($customerEntity);
|
| 57 |
+
} else {
|
| 58 |
+
$data = array (
|
| 59 |
+
'email' => $vanillaOrder->getCustomerEmail(),
|
| 60 |
+
'storeView' => (string) $orderEntity->getStoreView(),
|
| 61 |
+
'storeViewId' => $vanillaOrder->getStoreId(),
|
| 62 |
+
'firstname' => $vanillaOrder->getCustomerFirstname(),
|
| 63 |
+
'lastname' => $vanillaOrder->getCustomerLastname(),
|
| 64 |
+
);
|
| 65 |
+
|
| 66 |
+
if ($middlename = $vanillaOrder->getCustomerMiddlename()) {
|
| 67 |
+
$data['middlename'] = $middlename;
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
if ($dateOfBirth = $vanillaOrder->getCustomerDob()) {
|
| 71 |
+
$data['birthdate'] = date('Y-m-d H:i:s', strtotime($dateOfBirth));
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
if ($gender = $vanillaOrder->getCustomerGender()) {
|
| 75 |
+
$options = Mage::getModel('customer/customer')->getAttribute('gender')->getSource()->getAllOptions();
|
| 76 |
+
|
| 77 |
+
foreach ($options as $option) {
|
| 78 |
+
if ($option['value'] == $gender) {
|
| 79 |
+
$gender = $option['label'];
|
| 80 |
+
}
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
$data['gender'] = $gender;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
$group = $vanillaOrder->getCustomerGroupId();
|
| 87 |
+
$group = Mage::getModel('customer/group')->load($group)->getCode();
|
| 88 |
+
$data['group'] = $group;
|
| 89 |
+
|
| 90 |
+
return $restOrder->syncWithGuest($data);
|
| 91 |
+
}
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
/**
|
| 95 |
+
* This action will be run on order add event
|
| 96 |
+
*
|
| 97 |
+
* @return boolean
|
| 98 |
+
*/
|
| 99 |
+
public function actionAdd()
|
| 100 |
+
{
|
| 101 |
+
$this->actionModify();
|
| 102 |
+
|
| 103 |
+
$order = Mage::getModel('sales/order')->load($this->_getEntityId());
|
| 104 |
+
|
| 105 |
+
$customerEntity = $this->_getCustomerEntity();
|
| 106 |
+
|
| 107 |
+
if(!$customerEntity) {
|
| 108 |
+
return true;
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
$request = Mage::helper('marketingsoftware/rest_request');
|
| 112 |
+
|
| 113 |
+
$quoteItemCollection = Mage::helper('marketingsoftware/config')->getQuoteItemCollectionId();
|
| 114 |
+
|
| 115 |
+
if ($quoteItemCollection) {
|
| 116 |
+
$response = $request->get('/profile/'.$customerEntity->getProfileId().'/subprofiles/'.$quoteItemCollection, array(
|
| 117 |
+
'fields' => array('quote_id=='.$order->getQuoteId())
|
| 118 |
+
));
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
if (array_key_exists('data', $response) || count($response['data']) == 0) {
|
| 122 |
+
return true;
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
$request->prepare();
|
| 126 |
+
|
| 127 |
+
if (Mage::helper('marketingsoftware/config')->getRemoveFinishedQuoteItem()) {
|
| 128 |
+
foreach ($response['data'] as $subprofile) {
|
| 129 |
+
$request->delete('/subprofile/'.$subprofile['ID']);
|
| 130 |
+
}
|
| 131 |
+
} else {
|
| 132 |
+
foreach ($response['data'] as $subprofile) {
|
| 133 |
+
$request->put('/subprofile/'.$subprofile['ID'].'/fields/', array('status' => 'completed'));
|
| 134 |
+
}
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
$request->commit();
|
| 138 |
+
|
| 139 |
+
return true;
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
protected function _getCustomerEntity()
|
| 143 |
+
{
|
| 144 |
+
if ($this->_customerEntity) {
|
| 145 |
+
return $this->_customerEntity;
|
| 146 |
+
} else {
|
| 147 |
+
$object = $this->_getObject();
|
| 148 |
+
|
| 149 |
+
if ($object->customerId && is_numeric($object->customerId)) {
|
| 150 |
+
$customerEntity = Mage::getModel('marketingsoftware/copernica_entity_customer');
|
| 151 |
+
$customerEntity->setCustomer($object->customerId);
|
| 152 |
+
|
| 153 |
+
return $this->_customerEntity = $customerEntity;
|
| 154 |
+
} else {
|
| 155 |
+
return false;
|
| 156 |
+
}
|
| 157 |
+
}
|
| 158 |
+
}
|
| 159 |
}
|
app/code/community/Copernica/MarketingSoftware/Model/Queue/Event/Quote.php
CHANGED
|
@@ -1,98 +1,98 @@
|
|
| 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 |
-
* Event to handler quote changes
|
| 29 |
-
*/
|
| 30 |
-
class Copernica_MarketingSoftware_Model_Queue_Event_Quote extends Copernica_MarketingSoftware_Model_Queue_Event_Abstract
|
| 31 |
-
{
|
| 32 |
-
/**
|
| 33 |
-
* Handle modify action
|
| 34 |
-
*
|
| 35 |
-
* @return boolean
|
| 36 |
-
*/
|
| 37 |
-
public function actionModify()
|
| 38 |
-
{
|
| 39 |
-
$quote = Mage::getModel('sales/quote');
|
| 40 |
-
$quote->loadByIdWithoutStore($this->_getEntityId());
|
| 41 |
-
|
| 42 |
-
$customerId = $quote->getCustomerId();
|
| 43 |
-
|
| 44 |
-
$quoteEntity = Mage::getModel('marketingsoftware/copernica_entity_quote');
|
| 45 |
-
$quoteEntity->setQuote($quote);
|
| 46 |
-
|
| 47 |
-
$customerEntity = Mage::getModel('marketingsoftware/copernica_entity_customer');
|
| 48 |
-
$customerEntity->setCustomer($customerId);
|
| 49 |
-
|
| 50 |
-
$restQuote = $quoteEntity->getRestQuote();
|
| 51 |
-
$restQuote->syncWithCustomer($customerEntity);
|
| 52 |
-
|
| 53 |
-
return true;
|
| 54 |
-
}
|
| 55 |
-
|
| 56 |
-
/**
|
| 57 |
-
* Handle quote removal
|
| 58 |
-
*
|
| 59 |
-
* @return boolean
|
| 60 |
-
*/
|
| 61 |
-
public function actionRemove()
|
| 62 |
-
{
|
| 63 |
-
$object = $this->getObject();
|
| 64 |
-
|
| 65 |
-
if (!$object->customerId || !is_numeric($object->customerId)) {
|
| 66 |
-
return false;
|
| 67 |
-
}
|
| 68 |
-
|
| 69 |
-
$quoteItemCollectionId = Mage::helper('marketingsoftware/config')->getQuoteItemCollectionId();
|
| 70 |
-
|
| 71 |
-
$customerEntity = Mage::getModel('marketingsoftware/copernica_entity_customer');
|
| 72 |
-
$customerEntity->setCustomer($object->customerId);
|
| 73 |
-
|
| 74 |
-
$profileId = Mage::helper('marketingsoftware/api')->getProfileId(array(
|
| 75 |
-
'id' => $customerEntity->fetchId(),
|
| 76 |
-
'storeView' => $customerEntity->fetchStoreView(),
|
| 77 |
-
'email' => $customerEntity->fetchEmail()
|
| 78 |
-
));
|
| 79 |
-
|
| 80 |
-
$request = Mage::helper('marketingsoftware/rest_request');
|
| 81 |
-
|
| 82 |
-
$result = $request->get('/profile/'.$profileId.'/subprofiles/'.$quoteItemCollectionId, array(
|
| 83 |
-
'fields' => array(
|
| 84 |
-
'quote_id=='.$this->_getEntityId()
|
| 85 |
-
)
|
| 86 |
-
));
|
| 87 |
-
|
| 88 |
-
$request->prepare();
|
| 89 |
-
|
| 90 |
-
if (array_key_exists('data', $result) && is_array($result['data'])) foreach ($result['data'] as $item) {
|
| 91 |
-
$request->delete('/subprofile/'.$item['ID']);
|
| 92 |
-
}
|
| 93 |
-
|
| 94 |
-
$request->commit();
|
| 95 |
-
|
| 96 |
-
return true;
|
| 97 |
-
}
|
| 98 |
-
}
|
| 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 |
+
* Event to handler quote changes
|
| 29 |
+
*/
|
| 30 |
+
class Copernica_MarketingSoftware_Model_Queue_Event_Quote extends Copernica_MarketingSoftware_Model_Queue_Event_Abstract
|
| 31 |
+
{
|
| 32 |
+
/**
|
| 33 |
+
* Handle modify action
|
| 34 |
+
*
|
| 35 |
+
* @return boolean
|
| 36 |
+
*/
|
| 37 |
+
public function actionModify()
|
| 38 |
+
{
|
| 39 |
+
$quote = Mage::getModel('sales/quote');
|
| 40 |
+
$quote->loadByIdWithoutStore($this->_getEntityId());
|
| 41 |
+
|
| 42 |
+
$customerId = $quote->getCustomerId();
|
| 43 |
+
|
| 44 |
+
$quoteEntity = Mage::getModel('marketingsoftware/copernica_entity_quote');
|
| 45 |
+
$quoteEntity->setQuote($quote);
|
| 46 |
+
|
| 47 |
+
$customerEntity = Mage::getModel('marketingsoftware/copernica_entity_customer');
|
| 48 |
+
$customerEntity->setCustomer($customerId);
|
| 49 |
+
|
| 50 |
+
$restQuote = $quoteEntity->getRestQuote();
|
| 51 |
+
$restQuote->syncWithCustomer($customerEntity);
|
| 52 |
+
|
| 53 |
+
return true;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
/**
|
| 57 |
+
* Handle quote removal
|
| 58 |
+
*
|
| 59 |
+
* @return boolean
|
| 60 |
+
*/
|
| 61 |
+
public function actionRemove()
|
| 62 |
+
{
|
| 63 |
+
$object = $this->getObject();
|
| 64 |
+
|
| 65 |
+
if (!$object->customerId || !is_numeric($object->customerId)) {
|
| 66 |
+
return false;
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
$quoteItemCollectionId = Mage::helper('marketingsoftware/config')->getQuoteItemCollectionId();
|
| 70 |
+
|
| 71 |
+
$customerEntity = Mage::getModel('marketingsoftware/copernica_entity_customer');
|
| 72 |
+
$customerEntity->setCustomer($object->customerId);
|
| 73 |
+
|
| 74 |
+
$profileId = Mage::helper('marketingsoftware/api')->getProfileId(array(
|
| 75 |
+
'id' => $customerEntity->fetchId(),
|
| 76 |
+
'storeView' => $customerEntity->fetchStoreView(),
|
| 77 |
+
'email' => $customerEntity->fetchEmail()
|
| 78 |
+
));
|
| 79 |
+
|
| 80 |
+
$request = Mage::helper('marketingsoftware/rest_request');
|
| 81 |
+
|
| 82 |
+
$result = $request->get('/profile/'.$profileId.'/subprofiles/'.$quoteItemCollectionId, array(
|
| 83 |
+
'fields' => array(
|
| 84 |
+
'quote_id=='.$this->_getEntityId()
|
| 85 |
+
)
|
| 86 |
+
));
|
| 87 |
+
|
| 88 |
+
$request->prepare();
|
| 89 |
+
|
| 90 |
+
if (array_key_exists('data', $result) && is_array($result['data'])) foreach ($result['data'] as $item) {
|
| 91 |
+
$request->delete('/subprofile/'.$item['ID']);
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
$request->commit();
|
| 95 |
+
|
| 96 |
+
return true;
|
| 97 |
+
}
|
| 98 |
+
}
|
app/code/community/Copernica/MarketingSoftware/Model/Queue/Event/Startsync.php
CHANGED
|
@@ -1,243 +1,243 @@
|
|
| 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 |
-
* This event when it's being processed should spaw customer/orders/subscriptions
|
| 29 |
-
* sync events. It should spawn them in batches so event queue will not grow into
|
| 30 |
-
* cosmic scale.
|
| 31 |
-
*/
|
| 32 |
-
class Copernica_MarketingSoftware_Model_Queue_Event_Startsync extends Copernica_MarketingSoftware_Model_Queue_Event_Abstract
|
| 33 |
-
{
|
| 34 |
-
/**
|
| 35 |
-
* How many events we want to spawn for each of customers/orders/subscriptions
|
| 36 |
-
*
|
| 37 |
-
* @var int
|
| 38 |
-
*/
|
| 39 |
-
protected $_eventsLimit = 5000;
|
| 40 |
-
|
| 41 |
-
/**
|
| 42 |
-
* Current event status. It contains informations about last entites that were
|
| 43 |
-
* scheduled for synchronization. Also it does contain stores id that should
|
| 44 |
-
* be used to filter entites results.
|
| 45 |
-
*
|
| 46 |
-
* @var Copernica_MarketingSoftware_Model_Sync_Status
|
| 47 |
-
*/
|
| 48 |
-
protected $_currentStatus;
|
| 49 |
-
|
| 50 |
-
/**
|
| 51 |
-
* Process event. If not all entities can be added to synchtonization this
|
| 52 |
-
* event will respawn with new set of data. Note that this event will be
|
| 53 |
-
* respawning till all entities will be scheduled to sync.
|
| 54 |
-
*
|
| 55 |
-
* @return boolean
|
| 56 |
-
*/
|
| 57 |
-
public function process() {
|
| 58 |
-
$this->_currentStatus = Copernica_MarketingSoftware_Model_Sync_Status::fromStd($this->_getObject());
|
| 59 |
-
|
| 60 |
-
$shouldRespawn = false;
|
| 61 |
-
|
| 62 |
-
if ($this->_addCustomersToQueue() == $this->_eventsLimit) {
|
| 63 |
-
$shouldRespawn = true;
|
| 64 |
-
}
|
| 65 |
-
|
| 66 |
-
if ($this->_addOrdersToQueue() == $this->_eventsLimit) {
|
| 67 |
-
$shouldRespawn = true;
|
| 68 |
-
}
|
| 69 |
-
|
| 70 |
-
if ($this->_addSubscriptionsToQueue() == $this->_eventsLimit) {
|
| 71 |
-
$shouldRespawn = true;
|
| 72 |
-
}
|
| 73 |
-
|
| 74 |
-
if ($shouldRespawn) {
|
| 75 |
-
$this->respawn();
|
| 76 |
-
}
|
| 77 |
-
|
| 78 |
-
return true;
|
| 79 |
-
}
|
| 80 |
-
|
| 81 |
-
/**
|
| 82 |
-
* Respawn start sync event.
|
| 83 |
-
*/
|
| 84 |
-
public function respawn()
|
| 85 |
-
{
|
| 86 |
-
$queue = Mage::getModel('marketingsoftware/queue_item')
|
| 87 |
-
->setObject($this->_currentStatus->toArray())
|
| 88 |
-
->setAction('start_sync')
|
| 89 |
-
->setName('startsync')
|
| 90 |
-
->save();
|
| 91 |
-
|
| 92 |
-
return true;
|
| 93 |
-
}
|
| 94 |
-
|
| 95 |
-
/**
|
| 96 |
-
* Get ::addAttributeToFilter() compatible array of stores that we want to
|
| 97 |
-
* sync. Null will be returned when there is no stores to filter.
|
| 98 |
-
*
|
| 99 |
-
* @return array|null
|
| 100 |
-
*/
|
| 101 |
-
protected function _getStoresFilter()
|
| 102 |
-
{
|
| 103 |
-
$enabledStores = $this->_currentStatus->getStoresFilter();
|
| 104 |
-
|
| 105 |
-
if (count($enabledStores) == 0) {
|
| 106 |
-
return null;
|
| 107 |
-
}
|
| 108 |
-
|
| 109 |
-
$filterArray = array();
|
| 110 |
-
|
| 111 |
-
foreach ($enabledStores as $store) {
|
| 112 |
-
$filterArray []= array('eq' => $store);
|
| 113 |
-
}
|
| 114 |
-
|
| 115 |
-
return $filterArray;
|
| 116 |
-
}
|
| 117 |
-
|
| 118 |
-
/**
|
| 119 |
-
* Add customers full sync events to queue
|
| 120 |
-
* This method will return number of events that were added to queue.
|
| 121 |
-
*
|
| 122 |
-
* @return int
|
| 123 |
-
*/
|
| 124 |
-
protected function _addCustomersToQueue()
|
| 125 |
-
{
|
| 126 |
-
$addedEvents = 0;
|
| 127 |
-
|
| 128 |
-
$lastCustomerId = $this->_currentStatus->getLastCustomerId();
|
| 129 |
-
|
| 130 |
-
$customersCollection = Mage::getModel('customer/customer')->getCollection();
|
| 131 |
-
$customersCollection->addAttributeToSort('entity_id', 'ASC');
|
| 132 |
-
$customersCollection->setPageSize($this->_eventsLimit)->addAttributeToFilter('entity_id', array('gt' => $lastCustomerId ));
|
| 133 |
-
|
| 134 |
-
if ($filterArray = $this->_getStoresFilter()) {
|
| 135 |
-
$customersCollection->addAttributeToFilter('store_id', $filterArray);
|
| 136 |
-
}
|
| 137 |
-
|
| 138 |
-
foreach ($customersCollection as $customer) {
|
| 139 |
-
$queue = Mage::getModel('marketingsoftware/queue_item')
|
| 140 |
-
->setObject(null)
|
| 141 |
-
->setCustomer($customer->getId())
|
| 142 |
-
->setAction('full')
|
| 143 |
-
->setName('customer')
|
| 144 |
-
->setEntityId($customer->getId())
|
| 145 |
-
->save();
|
| 146 |
-
|
| 147 |
-
$this->_currentStatus->setLastCustomerId($customer->getEntityId());
|
| 148 |
-
|
| 149 |
-
$addedEvents++;
|
| 150 |
-
}
|
| 151 |
-
|
| 152 |
-
Mage::helper('marketingsoftware/config')->setCustomerProgressStatus(date('Y-m-d H:i:s'));
|
| 153 |
-
|
| 154 |
-
return $addedEvents;
|
| 155 |
-
}
|
| 156 |
-
|
| 157 |
-
/**
|
| 158 |
-
* Add all orders that don't have a customer instance tied to them aka 'guest orders'
|
| 159 |
-
*
|
| 160 |
-
* @return int
|
| 161 |
-
*/
|
| 162 |
-
protected function _addOrdersToQueue()
|
| 163 |
-
{
|
| 164 |
-
$addedEvents = 0;
|
| 165 |
-
|
| 166 |
-
$ordersCollection = Mage::getModel('sales/order')->getCollection();
|
| 167 |
-
$ordersCollection->addAttributeToFilter('entity_id', array (
|
| 168 |
-
'gt' => $this->_currentStatus->getLastOrderId()
|
| 169 |
-
));
|
| 170 |
-
|
| 171 |
-
if ($filterArray = $this->_getStoresFilter()) {
|
| 172 |
-
$ordersCollection->addAttributeToFilter('store_id', $filterArray);
|
| 173 |
-
}
|
| 174 |
-
|
| 175 |
-
$ordersCollection->addFieldToFilter('customer_id', array(
|
| 176 |
-
'null' => true
|
| 177 |
-
));
|
| 178 |
-
$ordersCollection->addAttributeToSort('entity_id', 'ASC');
|
| 179 |
-
$ordersCollection->setPageSize($this->_eventsLimit);
|
| 180 |
-
|
| 181 |
-
foreach ($ordersCollection as $order) {
|
| 182 |
-
$queue = Mage::getModel('marketingsoftware/queue_item')
|
| 183 |
-
->setObject(array('customer' => null))
|
| 184 |
-
->setCustomer(null)
|
| 185 |
-
->setAction('modify')
|
| 186 |
-
->setName('order')
|
| 187 |
-
->setEntityId($order->getId())
|
| 188 |
-
->save();
|
| 189 |
-
|
| 190 |
-
$addedEvents++;
|
| 191 |
-
|
| 192 |
-
$this->_currentStatus->setLastOrderId($order->getEntityId());
|
| 193 |
-
}
|
| 194 |
-
|
| 195 |
-
Mage::helper('marketingsoftware/config')->setOrderProgressStatus(date('Y-m-d H:i:s'));
|
| 196 |
-
|
| 197 |
-
return $addedEvents;
|
| 198 |
-
}
|
| 199 |
-
|
| 200 |
-
/**
|
| 201 |
-
* This method will spawn events that will synchronise subscriptions that
|
| 202 |
-
* doen't have customer entity. This method will also return number of new
|
| 203 |
-
* events spawned.
|
| 204 |
-
*
|
| 205 |
-
* @return int
|
| 206 |
-
*/
|
| 207 |
-
protected function _addSubscriptionsToQueue()
|
| 208 |
-
{
|
| 209 |
-
$addedEvents = 0;
|
| 210 |
-
|
| 211 |
-
$subscriptionsCollection = Mage::getModel('newsletter/subscriber')->getCollection();
|
| 212 |
-
$subscriptionsCollection->addFieldToFilter('subscriber_id', array(
|
| 213 |
-
'gt' => $this->_currentStatus->getLastSubscriptionId()
|
| 214 |
-
));
|
| 215 |
-
$subscriptionsCollection->setOrder('subscriber_id', 'ASC');
|
| 216 |
-
$subscriptionsCollection->addFieldToFilter('customer_id', array(
|
| 217 |
-
'eq' => 0,
|
| 218 |
-
'null' => true
|
| 219 |
-
));
|
| 220 |
-
|
| 221 |
-
if ($filterArray = $this->_getStoresFilter()) {
|
| 222 |
-
$subscriptionsCollection->addFieldToFilter('store_id', $filterArray);
|
| 223 |
-
}
|
| 224 |
-
|
| 225 |
-
$subscriptionsCollection->setPageSize($this->_eventsLimit);
|
| 226 |
-
|
| 227 |
-
foreach ($subscriptionsCollection as $subscription) {
|
| 228 |
-
Mage::getModel('marketingsoftware/queue_item')
|
| 229 |
-
->setObject(null)
|
| 230 |
-
->setCustomer($subscription->getCustomerId())
|
| 231 |
-
->setAction('modify')
|
| 232 |
-
->setName('subscription')
|
| 233 |
-
->setEntityId($subscription->getId())
|
| 234 |
-
->save();
|
| 235 |
-
|
| 236 |
-
$this->_currentStatus->setLastSubscriptionId($subscription->getId());
|
| 237 |
-
|
| 238 |
-
$addedEvents++;
|
| 239 |
-
}
|
| 240 |
-
|
| 241 |
-
return $addedEvents;
|
| 242 |
-
}
|
| 243 |
}
|
| 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 |
+
* This event when it's being processed should spaw customer/orders/subscriptions
|
| 29 |
+
* sync events. It should spawn them in batches so event queue will not grow into
|
| 30 |
+
* cosmic scale.
|
| 31 |
+
*/
|
| 32 |
+
class Copernica_MarketingSoftware_Model_Queue_Event_Startsync extends Copernica_MarketingSoftware_Model_Queue_Event_Abstract
|
| 33 |
+
{
|
| 34 |
+
/**
|
| 35 |
+
* How many events we want to spawn for each of customers/orders/subscriptions
|
| 36 |
+
*
|
| 37 |
+
* @var int
|
| 38 |
+
*/
|
| 39 |
+
protected $_eventsLimit = 5000;
|
| 40 |
+
|
| 41 |
+
/**
|
| 42 |
+
* Current event status. It contains informations about last entites that were
|
| 43 |
+
* scheduled for synchronization. Also it does contain stores id that should
|
| 44 |
+
* be used to filter entites results.
|
| 45 |
+
*
|
| 46 |
+
* @var Copernica_MarketingSoftware_Model_Sync_Status
|
| 47 |
+
*/
|
| 48 |
+
protected $_currentStatus;
|
| 49 |
+
|
| 50 |
+
/**
|
| 51 |
+
* Process event. If not all entities can be added to synchtonization this
|
| 52 |
+
* event will respawn with new set of data. Note that this event will be
|
| 53 |
+
* respawning till all entities will be scheduled to sync.
|
| 54 |
+
*
|
| 55 |
+
* @return boolean
|
| 56 |
+
*/
|
| 57 |
+
public function process() {
|
| 58 |
+
$this->_currentStatus = Copernica_MarketingSoftware_Model_Sync_Status::fromStd($this->_getObject());
|
| 59 |
+
|
| 60 |
+
$shouldRespawn = false;
|
| 61 |
+
|
| 62 |
+
if ($this->_addCustomersToQueue() == $this->_eventsLimit) {
|
| 63 |
+
$shouldRespawn = true;
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
if ($this->_addOrdersToQueue() == $this->_eventsLimit) {
|
| 67 |
+
$shouldRespawn = true;
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
if ($this->_addSubscriptionsToQueue() == $this->_eventsLimit) {
|
| 71 |
+
$shouldRespawn = true;
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
if ($shouldRespawn) {
|
| 75 |
+
$this->respawn();
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
return true;
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
/**
|
| 82 |
+
* Respawn start sync event.
|
| 83 |
+
*/
|
| 84 |
+
public function respawn()
|
| 85 |
+
{
|
| 86 |
+
$queue = Mage::getModel('marketingsoftware/queue_item')
|
| 87 |
+
->setObject($this->_currentStatus->toArray())
|
| 88 |
+
->setAction('start_sync')
|
| 89 |
+
->setName('startsync')
|
| 90 |
+
->save();
|
| 91 |
+
|
| 92 |
+
return true;
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
/**
|
| 96 |
+
* Get ::addAttributeToFilter() compatible array of stores that we want to
|
| 97 |
+
* sync. Null will be returned when there is no stores to filter.
|
| 98 |
+
*
|
| 99 |
+
* @return array|null
|
| 100 |
+
*/
|
| 101 |
+
protected function _getStoresFilter()
|
| 102 |
+
{
|
| 103 |
+
$enabledStores = $this->_currentStatus->getStoresFilter();
|
| 104 |
+
|
| 105 |
+
if (count($enabledStores) == 0) {
|
| 106 |
+
return null;
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
$filterArray = array();
|
| 110 |
+
|
| 111 |
+
foreach ($enabledStores as $store) {
|
| 112 |
+
$filterArray []= array('eq' => $store);
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
return $filterArray;
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
/**
|
| 119 |
+
* Add customers full sync events to queue
|
| 120 |
+
* This method will return number of events that were added to queue.
|
| 121 |
+
*
|
| 122 |
+
* @return int
|
| 123 |
+
*/
|
| 124 |
+
protected function _addCustomersToQueue()
|
| 125 |
+
{
|
| 126 |
+
$addedEvents = 0;
|
| 127 |
+
|
| 128 |
+
$lastCustomerId = $this->_currentStatus->getLastCustomerId();
|
| 129 |
+
|
| 130 |
+
$customersCollection = Mage::getModel('customer/customer')->getCollection();
|
| 131 |
+
$customersCollection->addAttributeToSort('entity_id', 'ASC');
|
| 132 |
+
$customersCollection->setPageSize($this->_eventsLimit)->addAttributeToFilter('entity_id', array('gt' => $lastCustomerId ));
|
| 133 |
+
|
| 134 |
+
if ($filterArray = $this->_getStoresFilter()) {
|
| 135 |
+
$customersCollection->addAttributeToFilter('store_id', $filterArray);
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
foreach ($customersCollection as $customer) {
|
| 139 |
+
$queue = Mage::getModel('marketingsoftware/queue_item')
|
| 140 |
+
->setObject(null)
|
| 141 |
+
->setCustomer($customer->getId())
|
| 142 |
+
->setAction('full')
|
| 143 |
+
->setName('customer')
|
| 144 |
+
->setEntityId($customer->getId())
|
| 145 |
+
->save();
|
| 146 |
+
|
| 147 |
+
$this->_currentStatus->setLastCustomerId($customer->getEntityId());
|
| 148 |
+
|
| 149 |
+
$addedEvents++;
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
Mage::helper('marketingsoftware/config')->setCustomerProgressStatus(date('Y-m-d H:i:s'));
|
| 153 |
+
|
| 154 |
+
return $addedEvents;
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
/**
|
| 158 |
+
* Add all orders that don't have a customer instance tied to them aka 'guest orders'
|
| 159 |
+
*
|
| 160 |
+
* @return int
|
| 161 |
+
*/
|
| 162 |
+
protected function _addOrdersToQueue()
|
| 163 |
+
{
|
| 164 |
+
$addedEvents = 0;
|
| 165 |
+
|
| 166 |
+
$ordersCollection = Mage::getModel('sales/order')->getCollection();
|
| 167 |
+
$ordersCollection->addAttributeToFilter('entity_id', array (
|
| 168 |
+
'gt' => $this->_currentStatus->getLastOrderId()
|
| 169 |
+
));
|
| 170 |
+
|
| 171 |
+
if ($filterArray = $this->_getStoresFilter()) {
|
| 172 |
+
$ordersCollection->addAttributeToFilter('store_id', $filterArray);
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
$ordersCollection->addFieldToFilter('customer_id', array(
|
| 176 |
+
'null' => true
|
| 177 |
+
));
|
| 178 |
+
$ordersCollection->addAttributeToSort('entity_id', 'ASC');
|
| 179 |
+
$ordersCollection->setPageSize($this->_eventsLimit);
|
| 180 |
+
|
| 181 |
+
foreach ($ordersCollection as $order) {
|
| 182 |
+
$queue = Mage::getModel('marketingsoftware/queue_item')
|
| 183 |
+
->setObject(array('customer' => null))
|
| 184 |
+
->setCustomer(null)
|
| 185 |
+
->setAction('modify')
|
| 186 |
+
->setName('order')
|
| 187 |
+
->setEntityId($order->getId())
|
| 188 |
+
->save();
|
| 189 |
+
|
| 190 |
+
$addedEvents++;
|
| 191 |
+
|
| 192 |
+
$this->_currentStatus->setLastOrderId($order->getEntityId());
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
Mage::helper('marketingsoftware/config')->setOrderProgressStatus(date('Y-m-d H:i:s'));
|
| 196 |
+
|
| 197 |
+
return $addedEvents;
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
/**
|
| 201 |
+
* This method will spawn events that will synchronise subscriptions that
|
| 202 |
+
* doen't have customer entity. This method will also return number of new
|
| 203 |
+
* events spawned.
|
| 204 |
+
*
|
| 205 |
+
* @return int
|
| 206 |
+
*/
|
| 207 |
+
protected function _addSubscriptionsToQueue()
|
| 208 |
+
{
|
| 209 |
+
$addedEvents = 0;
|
| 210 |
+
|
| 211 |
+
$subscriptionsCollection = Mage::getModel('newsletter/subscriber')->getCollection();
|
| 212 |
+
$subscriptionsCollection->addFieldToFilter('subscriber_id', array(
|
| 213 |
+
'gt' => $this->_currentStatus->getLastSubscriptionId()
|
| 214 |
+
));
|
| 215 |
+
$subscriptionsCollection->setOrder('subscriber_id', 'ASC');
|
| 216 |
+
$subscriptionsCollection->addFieldToFilter('customer_id', array(
|
| 217 |
+
'eq' => 0,
|
| 218 |
+
'null' => true
|
| 219 |
+
));
|
| 220 |
+
|
| 221 |
+
if ($filterArray = $this->_getStoresFilter()) {
|
| 222 |
+
$subscriptionsCollection->addFieldToFilter('store_id', $filterArray);
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
$subscriptionsCollection->setPageSize($this->_eventsLimit);
|
| 226 |
+
|
| 227 |
+
foreach ($subscriptionsCollection as $subscription) {
|
| 228 |
+
Mage::getModel('marketingsoftware/queue_item')
|
| 229 |
+
->setObject(null)
|
| 230 |
+
->setCustomer($subscription->getCustomerId())
|
| 231 |
+
->setAction('modify')
|
| 232 |
+
->setName('subscription')
|
| 233 |
+
->setEntityId($subscription->getId())
|
| 234 |
+
->save();
|
| 235 |
+
|
| 236 |
+
$this->_currentStatus->setLastSubscriptionId($subscription->getId());
|
| 237 |
+
|
| 238 |
+
$addedEvents++;
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
return $addedEvents;
|
| 242 |
+
}
|
| 243 |
}
|
app/code/community/Copernica/MarketingSoftware/Model/Queue/Event/Subscription.php
CHANGED
|
@@ -1,96 +1,96 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
|
| 3 |
-
/**
|
| 4 |
-
* This event should take care of any action done on subscription.
|
| 5 |
-
*/
|
| 6 |
-
class Copernica_MarketingSoftware_Model_Queue_Event_Subscription extends Copernica_MarketingSoftware_Model_Queue_Event_Abstract
|
| 7 |
-
{
|
| 8 |
-
/**
|
| 9 |
-
* Handle add action
|
| 10 |
-
*
|
| 11 |
-
* @return boolean
|
| 12 |
-
*/
|
| 13 |
-
public function actionAdd()
|
| 14 |
-
{
|
| 15 |
-
return $this->actionModify();
|
| 16 |
-
}
|
| 17 |
-
|
| 18 |
-
/**
|
| 19 |
-
* Handle remove action
|
| 20 |
-
*
|
| 21 |
-
* @return boolean
|
| 22 |
-
*/
|
| 23 |
-
public function actionRemove()
|
| 24 |
-
{
|
| 25 |
-
$object = $this->getObject();
|
| 26 |
-
|
| 27 |
-
$profileLinkedFields = Mage::helper('marketingsoftware/config')->getLinkedCustomerFields();
|
| 28 |
-
|
| 29 |
-
if (!$object->email && !$object->store_id) {
|
| 30 |
-
return false;
|
| 31 |
-
}
|
| 32 |
-
|
| 33 |
-
$store = Mage::getModel('core/store')->load($object->store_id);
|
| 34 |
-
$website = $store->getWebsite();
|
| 35 |
-
$group = $store->getGroup();
|
| 36 |
-
|
| 37 |
-
$storeView = implode(' > ', array (
|
| 38 |
-
$website->getName(),
|
| 39 |
-
$group->getName(),
|
| 40 |
-
$store->getName())
|
| 41 |
-
);
|
| 42 |
-
|
| 43 |
-
$profileCacheCollection = Mage::getModel('marketingsoftware/profile_cache')
|
| 44 |
-
->getCollection()
|
| 45 |
-
->setPageSize(1)
|
| 46 |
-
->addFieldToFilter('email', $object->email)
|
| 47 |
-
->addFieldToFilter('store_view', $storeView);
|
| 48 |
-
|
| 49 |
-
$profileCache = $profileCacheCollection->getFirstItem();
|
| 50 |
-
|
| 51 |
-
if (!$profileCache->isObjectNew()) {
|
| 52 |
-
$profileCache->delete();
|
| 53 |
-
}
|
| 54 |
-
|
| 55 |
-
$request = Mage::helper('marketingsoftware/rest_request');
|
| 56 |
-
|
| 57 |
-
$databaseId = Mage::helper('marketingsoftware/config')->getDatabaseId();
|
| 58 |
-
|
| 59 |
-
$result = $request->get('/database/'.$databaseId.'/profiles', array('fields' => array(
|
| 60 |
-
$profileLinkedFields['email'].'=='.$object->email,
|
| 61 |
-
$profileLinkedFields['storeView'].'=='.$storeView
|
| 62 |
-
)));
|
| 63 |
-
|
| 64 |
-
if (!isset($result['total']) && $result['total'] == 0) {
|
| 65 |
-
return false;
|
| 66 |
-
}
|
| 67 |
-
|
| 68 |
-
foreach ($result['data'] as $profile) {
|
| 69 |
-
$request->delete('/profile/'.$profile['ID']);
|
| 70 |
-
}
|
| 71 |
-
|
| 72 |
-
return true;
|
| 73 |
-
}
|
| 74 |
-
|
| 75 |
-
/**
|
| 76 |
-
* Handle modify action
|
| 77 |
-
*
|
| 78 |
-
* @return boolean
|
| 79 |
-
*/
|
| 80 |
-
public function actionModify()
|
| 81 |
-
{
|
| 82 |
-
$subscriber = Mage::getModel('newsletter/subscriber')->load($this->_getEntityId());
|
| 83 |
-
|
| 84 |
-
if ($subscriber->isObjectNew()) {
|
| 85 |
-
return true;
|
| 86 |
-
}
|
| 87 |
-
|
| 88 |
-
$subscriptionEntity = Mage::getModel('marketingsoftware/copernica_entity_subscription');
|
| 89 |
-
$subscriptionEntity->setSubscription($subscriber);
|
| 90 |
-
|
| 91 |
-
$restSubscription = $subscriptionEntity->getRestSubscription();
|
| 92 |
-
$restSubscription->sync();
|
| 93 |
-
|
| 94 |
-
return true;
|
| 95 |
-
}
|
| 96 |
-
}
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* This event should take care of any action done on subscription.
|
| 5 |
+
*/
|
| 6 |
+
class Copernica_MarketingSoftware_Model_Queue_Event_Subscription extends Copernica_MarketingSoftware_Model_Queue_Event_Abstract
|
| 7 |
+
{
|
| 8 |
+
/**
|
| 9 |
+
* Handle add action
|
| 10 |
+
*
|
| 11 |
+
* @return boolean
|
| 12 |
+
*/
|
| 13 |
+
public function actionAdd()
|
| 14 |
+
{
|
| 15 |
+
return $this->actionModify();
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
/**
|
| 19 |
+
* Handle remove action
|
| 20 |
+
*
|
| 21 |
+
* @return boolean
|
| 22 |
+
*/
|
| 23 |
+
public function actionRemove()
|
| 24 |
+
{
|
| 25 |
+
$object = $this->getObject();
|
| 26 |
+
|
| 27 |
+
$profileLinkedFields = Mage::helper('marketingsoftware/config')->getLinkedCustomerFields();
|
| 28 |
+
|
| 29 |
+
if (!$object->email && !$object->store_id) {
|
| 30 |
+
return false;
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
$store = Mage::getModel('core/store')->load($object->store_id);
|
| 34 |
+
$website = $store->getWebsite();
|
| 35 |
+
$group = $store->getGroup();
|
| 36 |
+
|
| 37 |
+
$storeView = implode(' > ', array (
|
| 38 |
+
$website->getName(),
|
| 39 |
+
$group->getName(),
|
| 40 |
+
$store->getName())
|
| 41 |
+
);
|
| 42 |
+
|
| 43 |
+
$profileCacheCollection = Mage::getModel('marketingsoftware/profile_cache')
|
| 44 |
+
->getCollection()
|
| 45 |
+
->setPageSize(1)
|
| 46 |
+
->addFieldToFilter('email', $object->email)
|
| 47 |
+
->addFieldToFilter('store_view', $storeView);
|
| 48 |
+
|
| 49 |
+
$profileCache = $profileCacheCollection->getFirstItem();
|
| 50 |
+
|
| 51 |
+
if (!$profileCache->isObjectNew()) {
|
| 52 |
+
$profileCache->delete();
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
$request = Mage::helper('marketingsoftware/rest_request');
|
| 56 |
+
|
| 57 |
+
$databaseId = Mage::helper('marketingsoftware/config')->getDatabaseId();
|
| 58 |
+
|
| 59 |
+
$result = $request->get('/database/'.$databaseId.'/profiles', array('fields' => array(
|
| 60 |
+
$profileLinkedFields['email'].'=='.$object->email,
|
| 61 |
+
$profileLinkedFields['storeView'].'=='.$storeView
|
| 62 |
+
)));
|
| 63 |
+
|
| 64 |
+
if (!isset($result['total']) && $result['total'] == 0) {
|
| 65 |
+
return false;
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
foreach ($result['data'] as $profile) {
|
| 69 |
+
$request->delete('/profile/'.$profile['ID']);
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
return true;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
/**
|
| 76 |
+
* Handle modify action
|
| 77 |
+
*
|
| 78 |
+
* @return boolean
|
| 79 |
+
*/
|
| 80 |
+
public function actionModify()
|
| 81 |
+
{
|
| 82 |
+
$subscriber = Mage::getModel('newsletter/subscriber')->load($this->_getEntityId());
|
| 83 |
+
|
| 84 |
+
if ($subscriber->isObjectNew()) {
|
| 85 |
+
return true;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
$subscriptionEntity = Mage::getModel('marketingsoftware/copernica_entity_subscription');
|
| 89 |
+
$subscriptionEntity->setSubscription($subscriber);
|
| 90 |
+
|
| 91 |
+
$restSubscription = $subscriptionEntity->getRestSubscription();
|
| 92 |
+
$restSubscription->sync();
|
| 93 |
+
|
| 94 |
+
return true;
|
| 95 |
+
}
|
| 96 |
+
}
|
app/code/community/Copernica/MarketingSoftware/Model/Queue/Event/View.php
CHANGED
|
@@ -1,57 +1,57 @@
|
|
| 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 |
-
* This class will take care of syncing product view.
|
| 29 |
-
* Everytime when user is visiting a page with a product this event is fired up.
|
| 30 |
-
*/
|
| 31 |
-
class Copernica_MarketingSoftware_Model_Queue_Event_View extends Copernica_MarketingSoftware_Model_Queue_Event_Abstract
|
| 32 |
-
{
|
| 33 |
-
/**
|
| 34 |
-
* Tell copernica platform that certain user did view certain product
|
| 35 |
-
* @return boolean
|
| 36 |
-
*/
|
| 37 |
-
public function actionAdd()
|
| 38 |
-
{
|
| 39 |
-
$object = $this->_queueItem->getObject();
|
| 40 |
-
|
| 41 |
-
if (!$object->customerId || !is_numeric($object->customerId) || !$object->productId || !is_numeric($object->productId) || !$object->viewedAt || !is_numeric($object->viewedAt)) {
|
| 42 |
-
return false;
|
| 43 |
-
}
|
| 44 |
-
|
| 45 |
-
$customerEntity = Mage::getModel('marketingsoftware/copernica_entity_customer');
|
| 46 |
-
$customerEntity->setCustomer($object->customerId);
|
| 47 |
-
|
| 48 |
-
$productEntity = Mage::getModel('marketingsoftware/copernica_entity_product');
|
| 49 |
-
$productEntity->setProduct($object->productId);
|
| 50 |
-
$productEntity->setTimestamp(date('Y-m-d G:i:s', $object->viewedAt));
|
| 51 |
-
|
| 52 |
-
$restProduct = $productEntity->getRestProduct();
|
| 53 |
-
$restProduct->viewedBy($customerEntity);
|
| 54 |
-
|
| 55 |
-
return true;
|
| 56 |
-
}
|
| 57 |
}
|
| 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 |
+
* This class will take care of syncing product view.
|
| 29 |
+
* Everytime when user is visiting a page with a product this event is fired up.
|
| 30 |
+
*/
|
| 31 |
+
class Copernica_MarketingSoftware_Model_Queue_Event_View extends Copernica_MarketingSoftware_Model_Queue_Event_Abstract
|
| 32 |
+
{
|
| 33 |
+
/**
|
| 34 |
+
* Tell copernica platform that certain user did view certain product
|
| 35 |
+
* @return boolean
|
| 36 |
+
*/
|
| 37 |
+
public function actionAdd()
|
| 38 |
+
{
|
| 39 |
+
$object = $this->_queueItem->getObject();
|
| 40 |
+
|
| 41 |
+
if (!$object->customerId || !is_numeric($object->customerId) || !$object->productId || !is_numeric($object->productId) || !$object->viewedAt || !is_numeric($object->viewedAt)) {
|
| 42 |
+
return false;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
$customerEntity = Mage::getModel('marketingsoftware/copernica_entity_customer');
|
| 46 |
+
$customerEntity->setCustomer($object->customerId);
|
| 47 |
+
|
| 48 |
+
$productEntity = Mage::getModel('marketingsoftware/copernica_entity_product');
|
| 49 |
+
$productEntity->setProduct($object->productId);
|
| 50 |
+
$productEntity->setTimestamp(date('Y-m-d G:i:s', $object->viewedAt));
|
| 51 |
+
|
| 52 |
+
$restProduct = $productEntity->getRestProduct();
|
| 53 |
+
$restProduct->viewedBy($customerEntity);
|
| 54 |
+
|
| 55 |
+
return true;
|
| 56 |
+
}
|
| 57 |
}
|
app/code/community/Copernica/MarketingSoftware/Model/Queue/Item.php
CHANGED
|
@@ -1,249 +1,249 @@
|
|
| 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 |
-
* Queue object for accessing the events in the queue table.
|
| 29 |
-
*
|
| 30 |
-
*/
|
| 31 |
-
class Copernica_MarketingSoftware_Model_Queue_Item extends Mage_Core_Model_Abstract
|
| 32 |
-
{
|
| 33 |
-
/**
|
| 34 |
-
* Constructor for the model
|
| 35 |
-
*/
|
| 36 |
-
protected function _construct()
|
| 37 |
-
{
|
| 38 |
-
$this->_init('marketingsoftware/queue_item');
|
| 39 |
-
}
|
| 40 |
-
|
| 41 |
-
/**
|
| 42 |
-
* Get 1st free queue event that is not locked by any lock.
|
| 43 |
-
*
|
| 44 |
-
* @return string
|
| 45 |
-
*/
|
| 46 |
-
public function getFirstFree()
|
| 47 |
-
{
|
| 48 |
-
return $this->getResource()->getFirstFree();
|
| 49 |
-
}
|
| 50 |
-
|
| 51 |
-
/**
|
| 52 |
-
* Get the data from the model
|
| 53 |
-
*
|
| 54 |
-
* @return mixed
|
| 55 |
-
*/
|
| 56 |
-
public function getObject()
|
| 57 |
-
{
|
| 58 |
-
$data = $this->getData('object');
|
| 59 |
-
|
| 60 |
-
$object = json_decode($data);
|
| 61 |
-
|
| 62 |
-
if (!is_null($object)) {
|
| 63 |
-
return $object;
|
| 64 |
-
}
|
| 65 |
-
|
| 66 |
-
return unserialize($this->getData('object'));
|
| 67 |
-
}
|
| 68 |
-
|
| 69 |
-
/**
|
| 70 |
-
* Set the data to the model
|
| 71 |
-
*
|
| 72 |
-
* @param object $object
|
| 73 |
-
* @return Copernica_MarketingSoftware_Model_Queue_Item
|
| 74 |
-
*/
|
| 75 |
-
public function setObject($object = null)
|
| 76 |
-
{
|
| 77 |
-
if (is_null($object)) {
|
| 78 |
-
$this->setData('object', '');
|
| 79 |
-
|
| 80 |
-
return $this;
|
| 81 |
-
}
|
| 82 |
-
|
| 83 |
-
$json = json_encode($object);
|
| 84 |
-
|
| 85 |
-
$this->setData('object', $json ? $json : '');
|
| 86 |
-
|
| 87 |
-
return $this;
|
| 88 |
-
}
|
| 89 |
-
|
| 90 |
-
/**
|
| 91 |
-
* Set the customer that is interested in queue item
|
| 92 |
-
*
|
| 93 |
-
* @param int $customerId
|
| 94 |
-
* @return Copernica_MarketingSoftware_Model_Queue_Item
|
| 95 |
-
*/
|
| 96 |
-
public function setCustomerId($customerId)
|
| 97 |
-
{
|
| 98 |
-
$this->setData('customer', $customerId);
|
| 99 |
-
|
| 100 |
-
return $this;
|
| 101 |
-
}
|
| 102 |
-
|
| 103 |
-
/**
|
| 104 |
-
* Get customer that is
|
| 105 |
-
*
|
| 106 |
-
* @return id
|
| 107 |
-
*/
|
| 108 |
-
public function getCustomerId()
|
| 109 |
-
{
|
| 110 |
-
return $this->getData('customer');
|
| 111 |
-
}
|
| 112 |
-
|
| 113 |
-
/**
|
| 114 |
-
* Set name of the event
|
| 115 |
-
*
|
| 116 |
-
* @param string $name
|
| 117 |
-
* @return Copernica_MarketingSoftware_Model_Queue_Item
|
| 118 |
-
*/
|
| 119 |
-
public function setName($name)
|
| 120 |
-
{
|
| 121 |
-
$this->setData('name', $name);
|
| 122 |
-
|
| 123 |
-
return $this;
|
| 124 |
-
}
|
| 125 |
-
|
| 126 |
-
/**
|
| 127 |
-
* Get name of the event
|
| 128 |
-
*
|
| 129 |
-
* @return string
|
| 130 |
-
*/
|
| 131 |
-
public function getName()
|
| 132 |
-
{
|
| 133 |
-
return $this->getData('name');
|
| 134 |
-
}
|
| 135 |
-
|
| 136 |
-
/**
|
| 137 |
-
* Set associated entity Id
|
| 138 |
-
*
|
| 139 |
-
* @param int $id
|
| 140 |
-
* @return Copernica_MarketingSoftware_Model_Queue_Item
|
| 141 |
-
*/
|
| 142 |
-
public function setEntityId($id)
|
| 143 |
-
{
|
| 144 |
-
$this->setData('entity_id', $id);
|
| 145 |
-
|
| 146 |
-
return $this;
|
| 147 |
-
}
|
| 148 |
-
|
| 149 |
-
/**
|
| 150 |
-
* Get associate entity Id
|
| 151 |
-
*
|
| 152 |
-
* @return int
|
| 153 |
-
*/
|
| 154 |
-
public function getEntityId()
|
| 155 |
-
{
|
| 156 |
-
return $this->getData('entity_id');
|
| 157 |
-
}
|
| 158 |
-
|
| 159 |
-
/**
|
| 160 |
-
* Process this item in the queue. Returns true if the event was
|
| 161 |
-
* successfully processed, otherwise returns false.
|
| 162 |
-
*
|
| 163 |
-
* @return boolean
|
| 164 |
-
*/
|
| 165 |
-
public function process()
|
| 166 |
-
{
|
| 167 |
-
$modelName = 'marketingsoftware/queue_event_'. $this->getName();
|
| 168 |
-
|
| 169 |
-
if (!class_exists(Mage::getConfig()->getModelClassName($modelName))) {
|
| 170 |
-
return null;
|
| 171 |
-
}
|
| 172 |
-
|
| 173 |
-
$event = Mage::getModel($modelName);
|
| 174 |
-
$event->setQueueItem($this);
|
| 175 |
-
|
| 176 |
-
return $event->process();
|
| 177 |
-
}
|
| 178 |
-
|
| 179 |
-
/**
|
| 180 |
-
* When saving queue event we should check if it should be saved. When on
|
| 181 |
-
* queue is already same event we don't have to save it again. This way
|
| 182 |
-
* we can save some CPU and network.
|
| 183 |
-
* Also if we are inserting 'remove' event there is no point in syncing all
|
| 184 |
-
* modify/add events before this 'remove' event. We can remove such event
|
| 185 |
-
* before we save one with 'remove'
|
| 186 |
-
*
|
| 187 |
-
* @return Copernica_MarketingSoftware_Model_Queue_Item
|
| 188 |
-
*/
|
| 189 |
-
public function save()
|
| 190 |
-
{
|
| 191 |
-
$this->setQueueTime(date("Y-m-d H:i:s"));
|
| 192 |
-
|
| 193 |
-
if ($this->getAction() == 'remove') {
|
| 194 |
-
$this->_clearNoRemoveSiblings();
|
| 195 |
-
}
|
| 196 |
-
|
| 197 |
-
if ($this->getAction() == 'add' || $this->getAction() == 'modify') {
|
| 198 |
-
if ($this->_shouldSave()) {
|
| 199 |
-
parent::save();
|
| 200 |
-
} else {
|
| 201 |
-
return $this;
|
| 202 |
-
}
|
| 203 |
-
}
|
| 204 |
-
|
| 205 |
-
return parent::save();
|
| 206 |
-
}
|
| 207 |
-
|
| 208 |
-
/**
|
| 209 |
-
* Clear all modify/add events that are before this event.
|
| 210 |
-
*/
|
| 211 |
-
protected function _clearNoRemoveSiblings()
|
| 212 |
-
{
|
| 213 |
-
$collection = $this->getCollection()
|
| 214 |
-
->addFilter('action', 'add')
|
| 215 |
-
->addFilter('name', $this->getName())
|
| 216 |
-
->addFilter('object', ($object = $this->getData('object')) ? $object : '')
|
| 217 |
-
->addFilter('entity_id', $this->
|
| 218 |
-
|
| 219 |
-
foreach ($collection as $event) {
|
| 220 |
-
$event->delete();
|
| 221 |
-
}
|
| 222 |
-
|
| 223 |
-
$collection = $this->getCollection()
|
| 224 |
-
->addFilter('action', 'modify')
|
| 225 |
-
->addFilter('name', $this->getName())
|
| 226 |
-
->addFilter('object', ($object = $this->getData('object')) ? $object : '')
|
| 227 |
-
->addFilter('entity_id', $this->
|
| 228 |
-
|
| 229 |
-
foreach ($collection as $event) {
|
| 230 |
-
$event->delete();
|
| 231 |
-
}
|
| 232 |
-
}
|
| 233 |
-
|
| 234 |
-
/**
|
| 235 |
-
* Merge all siblings
|
| 236 |
-
*
|
| 237 |
-
* @return boolean
|
| 238 |
-
*/
|
| 239 |
-
protected function _shouldSave()
|
| 240 |
-
{
|
| 241 |
-
$collection = $this->getCollection()
|
| 242 |
-
->addFilter('action', $this->getAction())
|
| 243 |
-
->addFilter('name', $this->getName())
|
| 244 |
-
->addFilter('object', ($object = $this->getData('object')) ? $object : '')
|
| 245 |
-
->addFilter('entity_id', $this->getEntityId());
|
| 246 |
-
|
| 247 |
-
return $collection->count() == 0;
|
| 248 |
-
}
|
| 249 |
-
}
|
| 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 |
+
* Queue object for accessing the events in the queue table.
|
| 29 |
+
*
|
| 30 |
+
*/
|
| 31 |
+
class Copernica_MarketingSoftware_Model_Queue_Item extends Mage_Core_Model_Abstract
|
| 32 |
+
{
|
| 33 |
+
/**
|
| 34 |
+
* Constructor for the model
|
| 35 |
+
*/
|
| 36 |
+
protected function _construct()
|
| 37 |
+
{
|
| 38 |
+
$this->_init('marketingsoftware/queue_item');
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
/**
|
| 42 |
+
* Get 1st free queue event that is not locked by any lock.
|
| 43 |
+
*
|
| 44 |
+
* @return string
|
| 45 |
+
*/
|
| 46 |
+
public function getFirstFree()
|
| 47 |
+
{
|
| 48 |
+
return $this->getResource()->getFirstFree();
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
/**
|
| 52 |
+
* Get the data from the model
|
| 53 |
+
*
|
| 54 |
+
* @return mixed
|
| 55 |
+
*/
|
| 56 |
+
public function getObject()
|
| 57 |
+
{
|
| 58 |
+
$data = $this->getData('object');
|
| 59 |
+
|
| 60 |
+
$object = json_decode($data);
|
| 61 |
+
|
| 62 |
+
if (!is_null($object)) {
|
| 63 |
+
return $object;
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
return unserialize($this->getData('object'));
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
/**
|
| 70 |
+
* Set the data to the model
|
| 71 |
+
*
|
| 72 |
+
* @param object $object
|
| 73 |
+
* @return Copernica_MarketingSoftware_Model_Queue_Item
|
| 74 |
+
*/
|
| 75 |
+
public function setObject($object = null)
|
| 76 |
+
{
|
| 77 |
+
if (is_null($object)) {
|
| 78 |
+
$this->setData('object', '');
|
| 79 |
+
|
| 80 |
+
return $this;
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
$json = json_encode($object);
|
| 84 |
+
|
| 85 |
+
$this->setData('object', $json ? $json : '');
|
| 86 |
+
|
| 87 |
+
return $this;
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
/**
|
| 91 |
+
* Set the customer that is interested in queue item
|
| 92 |
+
*
|
| 93 |
+
* @param int $customerId
|
| 94 |
+
* @return Copernica_MarketingSoftware_Model_Queue_Item
|
| 95 |
+
*/
|
| 96 |
+
public function setCustomerId($customerId)
|
| 97 |
+
{
|
| 98 |
+
$this->setData('customer', $customerId);
|
| 99 |
+
|
| 100 |
+
return $this;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
/**
|
| 104 |
+
* Get customer that is
|
| 105 |
+
*
|
| 106 |
+
* @return id
|
| 107 |
+
*/
|
| 108 |
+
public function getCustomerId()
|
| 109 |
+
{
|
| 110 |
+
return $this->getData('customer');
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
/**
|
| 114 |
+
* Set name of the event
|
| 115 |
+
*
|
| 116 |
+
* @param string $name
|
| 117 |
+
* @return Copernica_MarketingSoftware_Model_Queue_Item
|
| 118 |
+
*/
|
| 119 |
+
public function setName($name)
|
| 120 |
+
{
|
| 121 |
+
$this->setData('name', $name);
|
| 122 |
+
|
| 123 |
+
return $this;
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
/**
|
| 127 |
+
* Get name of the event
|
| 128 |
+
*
|
| 129 |
+
* @return string
|
| 130 |
+
*/
|
| 131 |
+
public function getName()
|
| 132 |
+
{
|
| 133 |
+
return $this->getData('name');
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
/**
|
| 137 |
+
* Set associated entity Id
|
| 138 |
+
*
|
| 139 |
+
* @param int $id
|
| 140 |
+
* @return Copernica_MarketingSoftware_Model_Queue_Item
|
| 141 |
+
*/
|
| 142 |
+
public function setEntityId($id)
|
| 143 |
+
{
|
| 144 |
+
$this->setData('entity_id', $id);
|
| 145 |
+
|
| 146 |
+
return $this;
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
/**
|
| 150 |
+
* Get associate entity Id
|
| 151 |
+
*
|
| 152 |
+
* @return int
|
| 153 |
+
*/
|
| 154 |
+
public function getEntityId()
|
| 155 |
+
{
|
| 156 |
+
return $this->getData('entity_id');
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
/**
|
| 160 |
+
* Process this item in the queue. Returns true if the event was
|
| 161 |
+
* successfully processed, otherwise returns false.
|
| 162 |
+
*
|
| 163 |
+
* @return boolean
|
| 164 |
+
*/
|
| 165 |
+
public function process()
|
| 166 |
+
{
|
| 167 |
+
$modelName = 'marketingsoftware/queue_event_'. $this->getName();
|
| 168 |
+
|
| 169 |
+
if (!class_exists(Mage::getConfig()->getModelClassName($modelName))) {
|
| 170 |
+
return null;
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
$event = Mage::getModel($modelName);
|
| 174 |
+
$event->setQueueItem($this);
|
| 175 |
+
|
| 176 |
+
return $event->process();
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
/**
|
| 180 |
+
* When saving queue event we should check if it should be saved. When on
|
| 181 |
+
* queue is already same event we don't have to save it again. This way
|
| 182 |
+
* we can save some CPU and network.
|
| 183 |
+
* Also if we are inserting 'remove' event there is no point in syncing all
|
| 184 |
+
* modify/add events before this 'remove' event. We can remove such event
|
| 185 |
+
* before we save one with 'remove'
|
| 186 |
+
*
|
| 187 |
+
* @return Copernica_MarketingSoftware_Model_Queue_Item
|
| 188 |
+
*/
|
| 189 |
+
public function save()
|
| 190 |
+
{
|
| 191 |
+
$this->setQueueTime(date("Y-m-d H:i:s"));
|
| 192 |
+
|
| 193 |
+
if ($this->getAction() == 'remove') {
|
| 194 |
+
$this->_clearNoRemoveSiblings();
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
if ($this->getAction() == 'add' || $this->getAction() == 'modify') {
|
| 198 |
+
if ($this->_shouldSave()) {
|
| 199 |
+
parent::save();
|
| 200 |
+
} else {
|
| 201 |
+
return $this;
|
| 202 |
+
}
|
| 203 |
+
}
|
| 204 |
+
|
| 205 |
+
return parent::save();
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
/**
|
| 209 |
+
* Clear all modify/add events that are before this event.
|
| 210 |
+
*/
|
| 211 |
+
protected function _clearNoRemoveSiblings()
|
| 212 |
+
{
|
| 213 |
+
$collection = $this->getCollection()
|
| 214 |
+
->addFilter('action', 'add')
|
| 215 |
+
->addFilter('name', $this->getName())
|
| 216 |
+
->addFilter('object', ($object = $this->getData('object')) ? $object : '')
|
| 217 |
+
->addFilter('entity_id', $this->getEntityId());
|
| 218 |
+
|
| 219 |
+
foreach ($collection as $event) {
|
| 220 |
+
$event->delete();
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
+
$collection = $this->getCollection()
|
| 224 |
+
->addFilter('action', 'modify')
|
| 225 |
+
->addFilter('name', $this->getName())
|
| 226 |
+
->addFilter('object', ($object = $this->getData('object')) ? $object : '')
|
| 227 |
+
->addFilter('entity_id', $this->getEntityId());
|
| 228 |
+
|
| 229 |
+
foreach ($collection as $event) {
|
| 230 |
+
$event->delete();
|
| 231 |
+
}
|
| 232 |
+
}
|
| 233 |
+
|
| 234 |
+
/**
|
| 235 |
+
* Merge all siblings
|
| 236 |
+
*
|
| 237 |
+
* @return boolean
|
| 238 |
+
*/
|
| 239 |
+
protected function _shouldSave()
|
| 240 |
+
{
|
| 241 |
+
$collection = $this->getCollection()
|
| 242 |
+
->addFilter('action', $this->getAction())
|
| 243 |
+
->addFilter('name', $this->getName())
|
| 244 |
+
->addFilter('object', ($object = $this->getData('object')) ? $object : '')
|
| 245 |
+
->addFilter('entity_id', $this->getEntityId());
|
| 246 |
+
|
| 247 |
+
return $collection->count() == 0;
|
| 248 |
+
}
|
| 249 |
+
}
|
app/code/community/Copernica/MarketingSoftware/Model/Queue/Processor.php
CHANGED
|
@@ -1,243 +1,243 @@
|
|
| 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 |
-
* This class will process task queue.
|
| 29 |
-
*/
|
| 30 |
-
class Copernica_MarketingSoftware_Model_Queue_Processor
|
| 31 |
-
{
|
| 32 |
-
/**
|
| 33 |
-
* Number of processed tasks by this processor
|
| 34 |
-
*
|
| 35 |
-
* @var int
|
| 36 |
-
*/
|
| 37 |
-
protected $_processedTasks = 0;
|
| 38 |
-
|
| 39 |
-
/**
|
| 40 |
-
* Timestamp when processor starts its job
|
| 41 |
-
*/
|
| 42 |
-
protected $_startTime;
|
| 43 |
-
|
| 44 |
-
/**
|
| 45 |
-
* How many items we want to process in one run?
|
| 46 |
-
*
|
| 47 |
-
* @var int
|
| 48 |
-
*/
|
| 49 |
-
protected $_itemsLimit = 10000000;
|
| 50 |
-
|
| 51 |
-
/**
|
| 52 |
-
* For what is our timelimit for queue processing? in seconds.
|
| 53 |
-
*
|
| 54 |
-
* @var int
|
| 55 |
-
*/
|
| 56 |
-
protected $_timeLimit = 3075840000;
|
| 57 |
-
|
| 58 |
-
/**
|
| 59 |
-
* Currently locked customer
|
| 60 |
-
*
|
| 61 |
-
* @var int
|
| 62 |
-
*/
|
| 63 |
-
protected $_currentCustomer = null;
|
| 64 |
-
|
| 65 |
-
/**
|
| 66 |
-
* Construct object.
|
| 67 |
-
*
|
| 68 |
-
* NOTE: This class is not a varien_object child!
|
| 69 |
-
*/
|
| 70 |
-
public function __construct()
|
| 71 |
-
{
|
| 72 |
-
$config = Mage::helper('marketingsoftware/config');
|
| 73 |
-
|
| 74 |
-
if ($itemsLimit = $config->getItemsPerRun()) {
|
| 75 |
-
$this->_itemsLimit = $itemsLimit;
|
| 76 |
-
}
|
| 77 |
-
|
| 78 |
-
if ($timeLimit = $config->getTimePerRun()) {
|
| 79 |
-
$this->_timeLimit = $timeLimit;
|
| 80 |
-
}
|
| 81 |
-
|
| 82 |
-
$config = Mage::helper('marketingsoftware/config');
|
| 83 |
-
$config->setLastStartTimeCronjob(date("Y-m-d H:i:s"));
|
| 84 |
-
}
|
| 85 |
-
|
| 86 |
-
/**
|
| 87 |
-
* We want to make some final actions when this processor is beeing destroyed.
|
| 88 |
-
*/
|
| 89 |
-
public function __destruct()
|
| 90 |
-
{
|
| 91 |
-
$config = Mage::helper('marketingsoftware/config');
|
| 92 |
-
$config->setLastEndTimeCronjob(date("Y-m-d H:i:s"));
|
| 93 |
-
$config->setLastCronjobProcessedTasks($this->_processedTasks);
|
| 94 |
-
}
|
| 95 |
-
|
| 96 |
-
/**
|
| 97 |
-
* Try to aqcuire 1st lock that can be used to sync data.
|
| 98 |
-
*
|
| 99 |
-
* @return string
|
| 100 |
-
*/
|
| 101 |
-
public function aqcuireLock()
|
| 102 |
-
{
|
| 103 |
-
$firstFree = Mage::getModel('marketingsoftware/queue_item')->getFirstFree();
|
| 104 |
-
|
| 105 |
-
return $this->_currentCustomer = $firstFree;
|
| 106 |
-
}
|
| 107 |
-
|
| 108 |
-
/**
|
| 109 |
-
* Process queue with lock
|
| 110 |
-
*
|
| 111 |
-
* @param string $lock
|
| 112 |
-
*/
|
| 113 |
-
public function processWithLocking($lock)
|
| 114 |
-
{
|
| 115 |
-
if (is_numeric($lock)) {
|
| 116 |
-
$this->processQueue($this->_currentCustomer);
|
| 117 |
-
} elseif (is_null($lock)) {
|
| 118 |
-
$this->processQueue(null);
|
| 119 |
-
}
|
| 120 |
-
}
|
| 121 |
-
|
| 122 |
-
/**
|
| 123 |
-
* Process queue
|
| 124 |
-
*
|
| 125 |
-
* @param string $customerId
|
| 126 |
-
*/
|
| 127 |
-
public function processQueue($customerId = -1)
|
| 128 |
-
{
|
| 129 |
-
$maxExecutionTime = ini_get('max_execution_time');
|
| 130 |
-
|
| 131 |
-
set_time_limit(0);
|
| 132 |
-
|
| 133 |
-
$queue = Mage::getResourceModel('marketingsoftware/queue_item_collection')
|
| 134 |
-
->addDefaultOrder()->setPageSize($this->_itemsLimit < 150 ? 150 : $this->_itemsLimit);
|
| 135 |
-
|
| 136 |
-
if (is_null($customerId)) {
|
| 137 |
-
$queue->addFieldToFilter('customer', array('null' => true));
|
| 138 |
-
} elseif ($customerId > -1) {
|
| 139 |
-
$queue->addFilter('customer', $customerId);
|
| 140 |
-
}
|
| 141 |
-
|
| 142 |
-
$this->_prepareProcessor();
|
| 143 |
-
|
| 144 |
-
foreach ($queue as $item) {
|
| 145 |
-
if ($this->_isLimitsReached()) {
|
| 146 |
-
break;
|
| 147 |
-
}
|
| 148 |
-
|
| 149 |
-
$this->_processItem($item);
|
| 150 |
-
}
|
| 151 |
-
|
| 152 |
-
set_time_limit($maxExecutionTime);
|
| 153 |
-
}
|
| 154 |
-
|
| 155 |
-
/**
|
| 156 |
-
* Make some preparations before we start processing queue
|
| 157 |
-
*/
|
| 158 |
-
protected function _prepareProcessor()
|
| 159 |
-
{
|
| 160 |
-
$this->_startTime = microtime(true);
|
| 161 |
-
}
|
| 162 |
-
|
| 163 |
-
/**
|
| 164 |
-
* Check if we reached limits
|
| 165 |
-
*
|
| 166 |
-
* @return bool
|
| 167 |
-
*/
|
| 168 |
-
protected function _isLimitsReached()
|
| 169 |
-
{
|
| 170 |
-
return $this->_processedTasks > $this->_itemsLimit || microtime(true) > $this->_startTime + $this->_timeLimit;
|
| 171 |
-
}
|
| 172 |
-
|
| 173 |
-
/**
|
| 174 |
-
* Process queue item
|
| 175 |
-
*
|
| 176 |
-
* @param Copernica_MarketingSoftware_Model_Queue_Item $item
|
| 177 |
-
*/
|
| 178 |
-
protected function _processItem(Copernica_MarketingSoftware_Model_Queue_Item $item)
|
| 179 |
-
{
|
| 180 |
-
try {
|
| 181 |
-
if ($item->process()) {
|
| 182 |
-
$item->delete();
|
| 183 |
-
} else {
|
| 184 |
-
$this->_transferItemToErrorQueue($item);
|
| 185 |
-
}
|
| 186 |
-
|
| 187 |
-
$this->_processedTasks++;
|
| 188 |
-
} catch (Copernica_MarketingSoftware_Exception $copernicaException) {
|
| 189 |
-
Mage::log($copernicaException->getMessage(), null, 'copernica_queue_exceptions.log');
|
| 190 |
-
|
| 191 |
-
$this->_transferItemToErrorQueue($item);
|
| 192 |
-
} catch (Exception $exception) {
|
| 193 |
-
Mage::logException($exception);
|
| 194 |
-
|
| 195 |
-
$item->setResult($exception->getMessage())->setResultTime(date('Y-m-d H:i:s'));
|
| 196 |
-
}
|
| 197 |
-
}
|
| 198 |
-
|
| 199 |
-
/**
|
| 200 |
-
* Transfer queue item to error queue.
|
| 201 |
-
*
|
| 202 |
-
* @param Copernica_MarketingSoftware_Model_Queue_Item $item
|
| 203 |
-
*/
|
| 204 |
-
protected function _transferItemToErrorQueue(Copernica_MarketingSoftware_Model_Queue_Item $item)
|
| 205 |
-
{
|
| 206 |
-
$errorItem = Copernica_MarketingSoftware_Model_Error_Queue::createFromQueueItem($item);
|
| 207 |
-
$errorItem->save();
|
| 208 |
-
|
| 209 |
-
$item->delete();
|
| 210 |
-
}
|
| 211 |
-
|
| 212 |
-
/**
|
| 213 |
-
* Fetch data about current run.
|
| 214 |
-
*
|
| 215 |
-
* @param string $type
|
| 216 |
-
*/
|
| 217 |
-
public function fetchReport($type)
|
| 218 |
-
{
|
| 219 |
-
$data = array(
|
| 220 |
-
'startTime' => date('Y-m-d H:i:s', (int)$this->_startTime),
|
| 221 |
-
'runTime' => (microtime(true) - $this->_startTime),
|
| 222 |
-
'processedTasks' => $this->_processedTasks,
|
| 223 |
-
'itemsLimit' => $this->_itemsLimit,
|
| 224 |
-
'timeLimit' => $this->_timeLimit,
|
| 225 |
-
'lockedCustomer' => $this->_currentCustomer
|
| 226 |
-
);
|
| 227 |
-
|
| 228 |
-
$type = strtolower($type);
|
| 229 |
-
|
| 230 |
-
switch ($type) {
|
| 231 |
-
case 'json':
|
| 232 |
-
return json_encode($data);
|
| 233 |
-
|
| 234 |
-
default:
|
| 235 |
-
$report = " Started at ".$data['startTime'].' UTC'.PHP_EOL;
|
| 236 |
-
$report .= " Run took ".$data['runTime']." seconds".PHP_EOL;
|
| 237 |
-
$report .= " Processed ".$data['processedTasks']." tasks".PHP_EOL;
|
| 238 |
-
$report .= " Limited with ".$data['itemsLimit']." items and ".$data['timeLimit']." seconds".PHP_EOL;
|
| 239 |
-
$report .= " ".($data['lockedCustomer'] ? "Locked on ".$data['lockedCustomer'] : "Without a lock").PHP_EOL;
|
| 240 |
-
return $report;
|
| 241 |
-
}
|
| 242 |
-
}
|
| 243 |
}
|
| 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 |
+
* This class will process task queue.
|
| 29 |
+
*/
|
| 30 |
+
class Copernica_MarketingSoftware_Model_Queue_Processor
|
| 31 |
+
{
|
| 32 |
+
/**
|
| 33 |
+
* Number of processed tasks by this processor
|
| 34 |
+
*
|
| 35 |
+
* @var int
|
| 36 |
+
*/
|
| 37 |
+
protected $_processedTasks = 0;
|
| 38 |
+
|
| 39 |
+
/**
|
| 40 |
+
* Timestamp when processor starts its job
|
| 41 |
+
*/
|
| 42 |
+
protected $_startTime;
|
| 43 |
+
|
| 44 |
+
/**
|
| 45 |
+
* How many items we want to process in one run?
|
| 46 |
+
*
|
| 47 |
+
* @var int
|
| 48 |
+
*/
|
| 49 |
+
protected $_itemsLimit = 10000000;
|
| 50 |
+
|
| 51 |
+
/**
|
| 52 |
+
* For what is our timelimit for queue processing? in seconds.
|
| 53 |
+
*
|
| 54 |
+
* @var int
|
| 55 |
+
*/
|
| 56 |
+
protected $_timeLimit = 3075840000;
|
| 57 |
+
|
| 58 |
+
/**
|
| 59 |
+
* Currently locked customer
|
| 60 |
+
*
|
| 61 |
+
* @var int
|
| 62 |
+
*/
|
| 63 |
+
protected $_currentCustomer = null;
|
| 64 |
+
|
| 65 |
+
/**
|
| 66 |
+
* Construct object.
|
| 67 |
+
*
|
| 68 |
+
* NOTE: This class is not a varien_object child!
|
| 69 |
+
*/
|
| 70 |
+
public function __construct()
|
| 71 |
+
{
|
| 72 |
+
$config = Mage::helper('marketingsoftware/config');
|
| 73 |
+
|
| 74 |
+
if ($itemsLimit = $config->getItemsPerRun()) {
|
| 75 |
+
$this->_itemsLimit = $itemsLimit;
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
if ($timeLimit = $config->getTimePerRun()) {
|
| 79 |
+
$this->_timeLimit = $timeLimit;
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
$config = Mage::helper('marketingsoftware/config');
|
| 83 |
+
$config->setLastStartTimeCronjob(date("Y-m-d H:i:s"));
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
/**
|
| 87 |
+
* We want to make some final actions when this processor is beeing destroyed.
|
| 88 |
+
*/
|
| 89 |
+
public function __destruct()
|
| 90 |
+
{
|
| 91 |
+
$config = Mage::helper('marketingsoftware/config');
|
| 92 |
+
$config->setLastEndTimeCronjob(date("Y-m-d H:i:s"));
|
| 93 |
+
$config->setLastCronjobProcessedTasks($this->_processedTasks);
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
/**
|
| 97 |
+
* Try to aqcuire 1st lock that can be used to sync data.
|
| 98 |
+
*
|
| 99 |
+
* @return string
|
| 100 |
+
*/
|
| 101 |
+
public function aqcuireLock()
|
| 102 |
+
{
|
| 103 |
+
$firstFree = Mage::getModel('marketingsoftware/queue_item')->getFirstFree();
|
| 104 |
+
|
| 105 |
+
return $this->_currentCustomer = $firstFree;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
/**
|
| 109 |
+
* Process queue with lock
|
| 110 |
+
*
|
| 111 |
+
* @param string $lock
|
| 112 |
+
*/
|
| 113 |
+
public function processWithLocking($lock)
|
| 114 |
+
{
|
| 115 |
+
if (is_numeric($lock)) {
|
| 116 |
+
$this->processQueue($this->_currentCustomer);
|
| 117 |
+
} elseif (is_null($lock)) {
|
| 118 |
+
$this->processQueue(null);
|
| 119 |
+
}
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
/**
|
| 123 |
+
* Process queue
|
| 124 |
+
*
|
| 125 |
+
* @param string $customerId
|
| 126 |
+
*/
|
| 127 |
+
public function processQueue($customerId = -1)
|
| 128 |
+
{
|
| 129 |
+
$maxExecutionTime = ini_get('max_execution_time');
|
| 130 |
+
|
| 131 |
+
set_time_limit(0);
|
| 132 |
+
|
| 133 |
+
$queue = Mage::getResourceModel('marketingsoftware/queue_item_collection')
|
| 134 |
+
->addDefaultOrder()->setPageSize($this->_itemsLimit < 150 ? 150 : $this->_itemsLimit);
|
| 135 |
+
|
| 136 |
+
if (is_null($customerId)) {
|
| 137 |
+
$queue->addFieldToFilter('customer', array('null' => true));
|
| 138 |
+
} elseif ($customerId > -1) {
|
| 139 |
+
$queue->addFilter('customer', $customerId);
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
$this->_prepareProcessor();
|
| 143 |
+
|
| 144 |
+
foreach ($queue as $item) {
|
| 145 |
+
if ($this->_isLimitsReached()) {
|
| 146 |
+
break;
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
$this->_processItem($item);
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
set_time_limit($maxExecutionTime);
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
/**
|
| 156 |
+
* Make some preparations before we start processing queue
|
| 157 |
+
*/
|
| 158 |
+
protected function _prepareProcessor()
|
| 159 |
+
{
|
| 160 |
+
$this->_startTime = microtime(true);
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
/**
|
| 164 |
+
* Check if we reached limits
|
| 165 |
+
*
|
| 166 |
+
* @return bool
|
| 167 |
+
*/
|
| 168 |
+
protected function _isLimitsReached()
|
| 169 |
+
{
|
| 170 |
+
return $this->_processedTasks > $this->_itemsLimit || microtime(true) > $this->_startTime + $this->_timeLimit;
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
/**
|
| 174 |
+
* Process queue item
|
| 175 |
+
*
|
| 176 |
+
* @param Copernica_MarketingSoftware_Model_Queue_Item $item
|
| 177 |
+
*/
|
| 178 |
+
protected function _processItem(Copernica_MarketingSoftware_Model_Queue_Item $item)
|
| 179 |
+
{
|
| 180 |
+
try {
|
| 181 |
+
if ($item->process()) {
|
| 182 |
+
$item->delete();
|
| 183 |
+
} else {
|
| 184 |
+
$this->_transferItemToErrorQueue($item);
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
$this->_processedTasks++;
|
| 188 |
+
} catch (Copernica_MarketingSoftware_Exception $copernicaException) {
|
| 189 |
+
Mage::log($copernicaException->getMessage(), null, 'copernica_queue_exceptions.log');
|
| 190 |
+
|
| 191 |
+
$this->_transferItemToErrorQueue($item);
|
| 192 |
+
} catch (Exception $exception) {
|
| 193 |
+
Mage::logException($exception);
|
| 194 |
+
|
| 195 |
+
$item->setResult($exception->getMessage())->setResultTime(date('Y-m-d H:i:s'));
|
| 196 |
+
}
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
/**
|
| 200 |
+
* Transfer queue item to error queue.
|
| 201 |
+
*
|
| 202 |
+
* @param Copernica_MarketingSoftware_Model_Queue_Item $item
|
| 203 |
+
*/
|
| 204 |
+
protected function _transferItemToErrorQueue(Copernica_MarketingSoftware_Model_Queue_Item $item)
|
| 205 |
+
{
|
| 206 |
+
$errorItem = Copernica_MarketingSoftware_Model_Error_Queue::createFromQueueItem($item);
|
| 207 |
+
$errorItem->save();
|
| 208 |
+
|
| 209 |
+
$item->delete();
|
| 210 |
+
}
|
| 211 |
+
|
| 212 |
+
/**
|
| 213 |
+
* Fetch data about current run.
|
| 214 |
+
*
|
| 215 |
+
* @param string $type
|
| 216 |
+
*/
|
| 217 |
+
public function fetchReport($type)
|
| 218 |
+
{
|
| 219 |
+
$data = array(
|
| 220 |
+
'startTime' => date('Y-m-d H:i:s', (int)$this->_startTime),
|
| 221 |
+
'runTime' => (microtime(true) - $this->_startTime),
|
| 222 |
+
'processedTasks' => $this->_processedTasks,
|
| 223 |
+
'itemsLimit' => $this->_itemsLimit,
|
| 224 |
+
'timeLimit' => $this->_timeLimit,
|
| 225 |
+
'lockedCustomer' => $this->_currentCustomer
|
| 226 |
+
);
|
| 227 |
+
|
| 228 |
+
$type = strtolower($type);
|
| 229 |
+
|
| 230 |
+
switch ($type) {
|
| 231 |
+
case 'json':
|
| 232 |
+
return json_encode($data);
|
| 233 |
+
|
| 234 |
+
default:
|
| 235 |
+
$report = " Started at ".$data['startTime'].' UTC'.PHP_EOL;
|
| 236 |
+
$report .= " Run took ".$data['runTime']." seconds".PHP_EOL;
|
| 237 |
+
$report .= " Processed ".$data['processedTasks']." tasks".PHP_EOL;
|
| 238 |
+
$report .= " Limited with ".$data['itemsLimit']." items and ".$data['timeLimit']." seconds".PHP_EOL;
|
| 239 |
+
$report .= " ".($data['lockedCustomer'] ? "Locked on ".$data['lockedCustomer'] : "Without a lock").PHP_EOL;
|
| 240 |
+
return $report;
|
| 241 |
+
}
|
| 242 |
+
}
|
| 243 |
}
|
app/code/community/Copernica/MarketingSoftware/Model/Rest.php
CHANGED
|
@@ -1,126 +1,126 @@
|
|
| 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 |
-
/**
|
| 29 |
-
* This is a base class for all classes that will be syncing entities via REST
|
| 30 |
-
* API.
|
| 31 |
-
*/
|
| 32 |
-
abstract class Copernica_MarketingSoftware_Model_Rest
|
| 33 |
-
{
|
| 34 |
-
/**
|
| 35 |
-
* Get request data that will can be passed to REST request
|
| 36 |
-
*
|
| 37 |
-
* @param Copernica_MarketingSoftware_Model_Copernica_Entity $entity
|
| 38 |
-
* @param array $syncedFields
|
| 39 |
-
* @return array
|
| 40 |
-
*/
|
| 41 |
-
protected function _getRequestData(Copernica_MarketingSoftware_Model_Copernica_Entity $entity, $syncedFields)
|
| 42 |
-
{
|
| 43 |
-
$data = array();
|
| 44 |
-
|
| 45 |
-
foreach ($syncedFields as $fieldType => $copernicaField) {
|
| 46 |
-
if (empty($copernicaField)) {
|
| 47 |
-
continue;
|
| 48 |
-
}
|
| 49 |
-
|
| 50 |
-
$getMethod = 'get'.ucfirst($fieldType);
|
| 51 |
-
|
| 52 |
-
$data[$copernicaField] = (string)$entity->$getMethod();
|
| 53 |
-
}
|
| 54 |
-
|
| 55 |
-
return $data;
|
| 56 |
-
}
|
| 57 |
-
|
| 58 |
-
/**
|
| 59 |
-
* Create profile. Parameter can be supplied as customer entity or array data.
|
| 60 |
-
* Array data should correspond to supported customer fields.
|
| 61 |
-
*
|
| 62 |
-
* @param array|Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $data
|
| 63 |
-
* @return int|false
|
| 64 |
-
*/
|
| 65 |
-
protected function _createProfile($data)
|
| 66 |
-
{
|
| 67 |
-
if ($data instanceof Copernica_MarketingSoftware_Model_Copernica_Entity_Customer)
|
| 68 |
-
{
|
| 69 |
-
$id = $data->getCustomerId();
|
| 70 |
-
$email = $data->getEmail();
|
| 71 |
-
$storeView = (string) $data->getStoreView();
|
| 72 |
-
|
| 73 |
-
$restCustomer = $data->getRestCustomer();
|
| 74 |
-
$restCustomer->setCustomerEntity($data);
|
| 75 |
-
$restCustomer->setProfile();
|
| 76 |
-
} else {
|
| 77 |
-
if (!is_array($data) && !isset($data['storeviewId'])) {
|
| 78 |
-
return;
|
| 79 |
-
}
|
| 80 |
-
|
| 81 |
-
$profileData = array();
|
| 82 |
-
|
| 83 |
-
if (isset($data['id'])) {
|
| 84 |
-
$profileData['customer_id'] = $data['id'].'|'.$data['storeViewId'];
|
| 85 |
-
} else if (isset($data['email'])) {
|
| 86 |
-
$profileData['customer_id'] = $data['email'].'|'.$data['storeViewId'];
|
| 87 |
-
} else {
|
| 88 |
-
return false;
|
| 89 |
-
}
|
| 90 |
-
|
| 91 |
-
if (!isset($data['storeView'])) {
|
| 92 |
-
$store = Mage::getModel('core/store')->load($data['storeViewId']);
|
| 93 |
-
|
| 94 |
-
$data['storeView'] = implode(' > ', array(
|
| 95 |
-
$store->getWebsite()->getName(),
|
| 96 |
-
$store->getGroup()->getName(),
|
| 97 |
-
$store->getName(),
|
| 98 |
-
));
|
| 99 |
-
}
|
| 100 |
-
|
| 101 |
-
$id = $data['id'];
|
| 102 |
-
$email = $data['email'];
|
| 103 |
-
$storeView = $data['storeView'];
|
| 104 |
-
|
| 105 |
-
$customerLinking = Mage::helper('marketingsoftware/config')->getLinkedCustomerFields();
|
| 106 |
-
|
| 107 |
-
foreach ($customerLinking as $magentoField => $copernicaField) {
|
| 108 |
-
if (empty($copernicaField) || is_null($data[$magentoField])) {
|
| 109 |
-
continue;
|
| 110 |
-
}
|
| 111 |
-
|
| 112 |
-
$profileData[$copernicaField] = $data[$magentoField];
|
| 113 |
-
}
|
| 114 |
-
|
| 115 |
-
$databaseId = Mage::helper('marketingsoftware/config')->getDatabaseId();
|
| 116 |
-
|
| 117 |
-
Mage::helper('marketingsoftware/rest_request')->post('/database/'.$databaseId.'/profiles', $profileData);
|
| 118 |
-
}
|
| 119 |
-
|
| 120 |
-
return Mage::helper('marketingsoftware/api')->getProfileId(array(
|
| 121 |
-
'id' => $id,
|
| 122 |
-
'storeView' => $storeView,
|
| 123 |
-
'email' => $email,
|
| 124 |
-
));
|
| 125 |
-
}
|
| 126 |
}
|
| 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 |
+
/**
|
| 29 |
+
* This is a base class for all classes that will be syncing entities via REST
|
| 30 |
+
* API.
|
| 31 |
+
*/
|
| 32 |
+
abstract class Copernica_MarketingSoftware_Model_Rest
|
| 33 |
+
{
|
| 34 |
+
/**
|
| 35 |
+
* Get request data that will can be passed to REST request
|
| 36 |
+
*
|
| 37 |
+
* @param Copernica_MarketingSoftware_Model_Copernica_Entity $entity
|
| 38 |
+
* @param array $syncedFields
|
| 39 |
+
* @return array
|
| 40 |
+
*/
|
| 41 |
+
protected function _getRequestData(Copernica_MarketingSoftware_Model_Copernica_Entity $entity, $syncedFields)
|
| 42 |
+
{
|
| 43 |
+
$data = array();
|
| 44 |
+
|
| 45 |
+
foreach ($syncedFields as $fieldType => $copernicaField) {
|
| 46 |
+
if (empty($copernicaField)) {
|
| 47 |
+
continue;
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
$getMethod = 'get'.ucfirst($fieldType);
|
| 51 |
+
|
| 52 |
+
$data[$copernicaField] = (string)$entity->$getMethod();
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
return $data;
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
/**
|
| 59 |
+
* Create profile. Parameter can be supplied as customer entity or array data.
|
| 60 |
+
* Array data should correspond to supported customer fields.
|
| 61 |
+
*
|
| 62 |
+
* @param array|Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $data
|
| 63 |
+
* @return int|false
|
| 64 |
+
*/
|
| 65 |
+
protected function _createProfile($data)
|
| 66 |
+
{
|
| 67 |
+
if ($data instanceof Copernica_MarketingSoftware_Model_Copernica_Entity_Customer)
|
| 68 |
+
{
|
| 69 |
+
$id = $data->getCustomerId();
|
| 70 |
+
$email = $data->getEmail();
|
| 71 |
+
$storeView = (string) $data->getStoreView();
|
| 72 |
+
|
| 73 |
+
$restCustomer = $data->getRestCustomer();
|
| 74 |
+
$restCustomer->setCustomerEntity($data);
|
| 75 |
+
$restCustomer->setProfile();
|
| 76 |
+
} else {
|
| 77 |
+
if (!is_array($data) && !isset($data['storeviewId'])) {
|
| 78 |
+
return;
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
$profileData = array();
|
| 82 |
+
|
| 83 |
+
if (isset($data['id'])) {
|
| 84 |
+
$profileData['customer_id'] = $data['id'].'|'.$data['storeViewId'];
|
| 85 |
+
} else if (isset($data['email'])) {
|
| 86 |
+
$profileData['customer_id'] = $data['email'].'|'.$data['storeViewId'];
|
| 87 |
+
} else {
|
| 88 |
+
return false;
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
if (!isset($data['storeView'])) {
|
| 92 |
+
$store = Mage::getModel('core/store')->load($data['storeViewId']);
|
| 93 |
+
|
| 94 |
+
$data['storeView'] = implode(' > ', array(
|
| 95 |
+
$store->getWebsite()->getName(),
|
| 96 |
+
$store->getGroup()->getName(),
|
| 97 |
+
$store->getName(),
|
| 98 |
+
));
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
$id = $data['id'];
|
| 102 |
+
$email = $data['email'];
|
| 103 |
+
$storeView = $data['storeView'];
|
| 104 |
+
|
| 105 |
+
$customerLinking = Mage::helper('marketingsoftware/config')->getLinkedCustomerFields();
|
| 106 |
+
|
| 107 |
+
foreach ($customerLinking as $magentoField => $copernicaField) {
|
| 108 |
+
if (empty($copernicaField) || is_null($data[$magentoField])) {
|
| 109 |
+
continue;
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
$profileData[$copernicaField] = $data[$magentoField];
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
$databaseId = Mage::helper('marketingsoftware/config')->getDatabaseId();
|
| 116 |
+
|
| 117 |
+
Mage::helper('marketingsoftware/rest_request')->post('/database/'.$databaseId.'/profiles', $profileData);
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
return Mage::helper('marketingsoftware/api')->getProfileId(array(
|
| 121 |
+
'id' => $id,
|
| 122 |
+
'storeView' => $storeView,
|
| 123 |
+
'email' => $email,
|
| 124 |
+
));
|
| 125 |
+
}
|
| 126 |
}
|
app/code/community/Copernica/MarketingSoftware/Model/Rest/Address.php
CHANGED
|
@@ -1,113 +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 |
-
* Address REST entity
|
| 29 |
-
*/
|
| 30 |
-
class Copernica_MarketingSoftware_Model_Rest_Address extends Copernica_MarketingSoftware_Model_Rest
|
| 31 |
-
{
|
| 32 |
-
/**
|
| 33 |
-
* Cached address entity
|
| 34 |
-
*
|
| 35 |
-
* @var Copernica_MarketingSoftware_Model_Copernica_Entity_Address
|
| 36 |
-
*/
|
| 37 |
-
protected $_addressEntity;
|
| 38 |
-
|
| 39 |
-
/**
|
| 40 |
-
* Bind address to customer
|
| 41 |
-
*
|
| 42 |
-
* @param Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer
|
| 43 |
-
* @return boolean
|
| 44 |
-
*/
|
| 45 |
-
public function bindToCustomer(Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer)
|
| 46 |
-
{
|
| 47 |
-
$customer->setStore($customer->getStoreview());
|
| 48 |
-
|
| 49 |
-
$profileId = Mage::helper('marketingsoftware/api')->getProfileId(array(
|
| 50 |
-
'id' => $customer->getCustomerId(),
|
| 51 |
-
'storeView' => (string) $customer->getStoreView(),
|
| 52 |
-
'email' => $customer->getEmail(),
|
| 53 |
-
));
|
| 54 |
-
|
| 55 |
-
if (!$profileId) {
|
| 56 |
-
$profileId = $this->_createProfile($customer);
|
| 57 |
-
|
| 58 |
-
if(!$profileId) {
|
| 59 |
-
return false;
|
| 60 |
-
}
|
| 61 |
-
}
|
| 62 |
-
|
| 63 |
-
$this->syncWithProfile($profileId);
|
| 64 |
-
|
| 65 |
-
return true;
|
| 66 |
-
}
|
| 67 |
-
|
| 68 |
-
/**
|
| 69 |
-
* Sync address data with certain profile
|
| 70 |
-
*
|
| 71 |
-
* @param int $profileId
|
| 72 |
-
* @return bool
|
| 73 |
-
*/
|
| 74 |
-
public function syncWithProfile($profileId)
|
| 75 |
-
{
|
| 76 |
-
$addressCollectionId = Mage::helper('marketingsoftware/config')->getAddressesCollectionId();
|
| 77 |
-
|
| 78 |
-
if ($addressCollectionId) {
|
| 79 |
-
Mage::helper('marketingsoftware/rest_request')->put('/profile/'.$profileId.'/subprofiles/'.$addressCollectionId, $this->_getSubprofileData(), array(
|
| 80 |
-
'fields[]' => 'address_id=='.$this->_addressEntity->getId(),
|
| 81 |
-
'create' => 'true'
|
| 82 |
-
));
|
| 83 |
-
|
| 84 |
-
return true;
|
| 85 |
-
} else {
|
| 86 |
-
return false;
|
| 87 |
-
}
|
| 88 |
-
}
|
| 89 |
-
|
| 90 |
-
/**
|
| 91 |
-
* Get subprofile data
|
| 92 |
-
*
|
| 93 |
-
* @return array
|
| 94 |
-
*/
|
| 95 |
-
protected function _getSubprofileData()
|
| 96 |
-
{
|
| 97 |
-
$syncedFields = Mage::helper('marketingsoftware/config')->getLinkedAddressFields();
|
| 98 |
-
|
| 99 |
-
$data = $this->_getRequestData($this->_addressEntity, $syncedFields);
|
| 100 |
-
$data = array_merge($data, array('address_id' => $this->_addressEntity->getId()));
|
| 101 |
-
|
| 102 |
-
return $data;
|
| 103 |
-
}
|
| 104 |
-
|
| 105 |
-
/**
|
| 106 |
-
* Set REST address entity
|
| 107 |
-
* @param Copernica_MarketingSoftware_Model_Copernica_Entity_Address $address
|
| 108 |
-
*/
|
| 109 |
-
public function setAddressEntity(Copernica_MarketingSoftware_Model_Copernica_Entity_Address $address)
|
| 110 |
-
{
|
| 111 |
-
$this->_addressEntity = $address;
|
| 112 |
-
}
|
| 113 |
}
|
| 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 |
+
* Address REST entity
|
| 29 |
+
*/
|
| 30 |
+
class Copernica_MarketingSoftware_Model_Rest_Address extends Copernica_MarketingSoftware_Model_Rest
|
| 31 |
+
{
|
| 32 |
+
/**
|
| 33 |
+
* Cached address entity
|
| 34 |
+
*
|
| 35 |
+
* @var Copernica_MarketingSoftware_Model_Copernica_Entity_Address
|
| 36 |
+
*/
|
| 37 |
+
protected $_addressEntity;
|
| 38 |
+
|
| 39 |
+
/**
|
| 40 |
+
* Bind address to customer
|
| 41 |
+
*
|
| 42 |
+
* @param Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer
|
| 43 |
+
* @return boolean
|
| 44 |
+
*/
|
| 45 |
+
public function bindToCustomer(Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer)
|
| 46 |
+
{
|
| 47 |
+
$customer->setStore($customer->getStoreview());
|
| 48 |
+
|
| 49 |
+
$profileId = Mage::helper('marketingsoftware/api')->getProfileId(array(
|
| 50 |
+
'id' => $customer->getCustomerId(),
|
| 51 |
+
'storeView' => (string) $customer->getStoreView(),
|
| 52 |
+
'email' => $customer->getEmail(),
|
| 53 |
+
));
|
| 54 |
+
|
| 55 |
+
if (!$profileId) {
|
| 56 |
+
$profileId = $this->_createProfile($customer);
|
| 57 |
+
|
| 58 |
+
if(!$profileId) {
|
| 59 |
+
return false;
|
| 60 |
+
}
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
$this->syncWithProfile($profileId);
|
| 64 |
+
|
| 65 |
+
return true;
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
/**
|
| 69 |
+
* Sync address data with certain profile
|
| 70 |
+
*
|
| 71 |
+
* @param int $profileId
|
| 72 |
+
* @return bool
|
| 73 |
+
*/
|
| 74 |
+
public function syncWithProfile($profileId)
|
| 75 |
+
{
|
| 76 |
+
$addressCollectionId = Mage::helper('marketingsoftware/config')->getAddressesCollectionId();
|
| 77 |
+
|
| 78 |
+
if ($addressCollectionId) {
|
| 79 |
+
Mage::helper('marketingsoftware/rest_request')->put('/profile/'.$profileId.'/subprofiles/'.$addressCollectionId, $this->_getSubprofileData(), array(
|
| 80 |
+
'fields[]' => 'address_id=='.$this->_addressEntity->getId(),
|
| 81 |
+
'create' => 'true'
|
| 82 |
+
));
|
| 83 |
+
|
| 84 |
+
return true;
|
| 85 |
+
} else {
|
| 86 |
+
return false;
|
| 87 |
+
}
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
/**
|
| 91 |
+
* Get subprofile data
|
| 92 |
+
*
|
| 93 |
+
* @return array
|
| 94 |
+
*/
|
| 95 |
+
protected function _getSubprofileData()
|
| 96 |
+
{
|
| 97 |
+
$syncedFields = Mage::helper('marketingsoftware/config')->getLinkedAddressFields();
|
| 98 |
+
|
| 99 |
+
$data = $this->_getRequestData($this->_addressEntity, $syncedFields);
|
| 100 |
+
$data = array_merge($data, array('address_id' => $this->_addressEntity->getId()));
|
| 101 |
+
|
| 102 |
+
return $data;
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
/**
|
| 106 |
+
* Set REST address entity
|
| 107 |
+
* @param Copernica_MarketingSoftware_Model_Copernica_Entity_Address $address
|
| 108 |
+
*/
|
| 109 |
+
public function setAddressEntity(Copernica_MarketingSoftware_Model_Copernica_Entity_Address $address)
|
| 110 |
+
{
|
| 111 |
+
$this->_addressEntity = $address;
|
| 112 |
+
}
|
| 113 |
}
|
app/code/community/Copernica/MarketingSoftware/Model/Rest/Customer.php
CHANGED
|
@@ -1,84 +1,84 @@
|
|
| 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 |
-
* REST bridge between magento customer and copernica platform
|
| 29 |
-
*/
|
| 30 |
-
class Copernica_MarketingSoftware_Model_Rest_Customer extends Copernica_MarketingSoftware_Model_Rest
|
| 31 |
-
{
|
| 32 |
-
/**
|
| 33 |
-
* Customer that will be used to send data
|
| 34 |
-
*
|
| 35 |
-
* @var Copernica_MarketingSoftware_Model_Copernica_Entity_Customer
|
| 36 |
-
*/
|
| 37 |
-
protected $_customerEntity;
|
| 38 |
-
|
| 39 |
-
/**
|
| 40 |
-
* Set profile
|
| 41 |
-
*
|
| 42 |
-
* @return bool
|
| 43 |
-
*/
|
| 44 |
-
public function setProfile()
|
| 45 |
-
{
|
| 46 |
-
$profileId = $this->_customerEntity->getProfileId();
|
| 47 |
-
|
| 48 |
-
$profileData = $this->_getProfileData();
|
| 49 |
-
|
| 50 |
-
if ($profileId) {
|
| 51 |
-
Mage::helper('marketingsoftware/rest_request')->put('/profile/'.$profileId.'/fields', $profileData);
|
| 52 |
-
} else {
|
| 53 |
-
$databaseId = Mage::helper('marketingsoftware/config')->getDatabaseId();
|
| 54 |
-
|
| 55 |
-
Mage::helper('marketingsoftware/rest_request')->post('/database/'.$databaseId.'/profiles', $profileData);
|
| 56 |
-
}
|
| 57 |
-
|
| 58 |
-
return true;
|
| 59 |
-
}
|
| 60 |
-
|
| 61 |
-
/**
|
| 62 |
-
* Set REST customer entity
|
| 63 |
-
*
|
| 64 |
-
* @param Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer
|
| 65 |
-
*/
|
| 66 |
-
public function setCustomerEntity(Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customerEntity) {
|
| 67 |
-
$this->_customerEntity = $customerEntity;
|
| 68 |
-
}
|
| 69 |
-
|
| 70 |
-
/**
|
| 71 |
-
* Get data that will be used to create a profile inside copernica platform
|
| 72 |
-
*
|
| 73 |
-
* @return array
|
| 74 |
-
*/
|
| 75 |
-
protected function _getProfileData()
|
| 76 |
-
{
|
| 77 |
-
$syncedFields = Mage::helper('marketingsoftware/config')->getLinkedCustomerFields();
|
| 78 |
-
|
| 79 |
-
$data = $this->_getRequestData($this->_customerEntity, $syncedFields);
|
| 80 |
-
$data = array_merge($data, array('customer_id' => $this->_customerEntity->getCustomerId()));
|
| 81 |
-
|
| 82 |
-
return $data;
|
| 83 |
-
}
|
| 84 |
-
}
|
| 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 |
+
* REST bridge between magento customer and copernica platform
|
| 29 |
+
*/
|
| 30 |
+
class Copernica_MarketingSoftware_Model_Rest_Customer extends Copernica_MarketingSoftware_Model_Rest
|
| 31 |
+
{
|
| 32 |
+
/**
|
| 33 |
+
* Customer that will be used to send data
|
| 34 |
+
*
|
| 35 |
+
* @var Copernica_MarketingSoftware_Model_Copernica_Entity_Customer
|
| 36 |
+
*/
|
| 37 |
+
protected $_customerEntity;
|
| 38 |
+
|
| 39 |
+
/**
|
| 40 |
+
* Set profile
|
| 41 |
+
*
|
| 42 |
+
* @return bool
|
| 43 |
+
*/
|
| 44 |
+
public function setProfile()
|
| 45 |
+
{
|
| 46 |
+
$profileId = $this->_customerEntity->getProfileId();
|
| 47 |
+
|
| 48 |
+
$profileData = $this->_getProfileData();
|
| 49 |
+
|
| 50 |
+
if ($profileId) {
|
| 51 |
+
Mage::helper('marketingsoftware/rest_request')->put('/profile/'.$profileId.'/fields', $profileData);
|
| 52 |
+
} else {
|
| 53 |
+
$databaseId = Mage::helper('marketingsoftware/config')->getDatabaseId();
|
| 54 |
+
|
| 55 |
+
Mage::helper('marketingsoftware/rest_request')->post('/database/'.$databaseId.'/profiles', $profileData);
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
return true;
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
/**
|
| 62 |
+
* Set REST customer entity
|
| 63 |
+
*
|
| 64 |
+
* @param Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer
|
| 65 |
+
*/
|
| 66 |
+
public function setCustomerEntity(Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customerEntity) {
|
| 67 |
+
$this->_customerEntity = $customerEntity;
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
/**
|
| 71 |
+
* Get data that will be used to create a profile inside copernica platform
|
| 72 |
+
*
|
| 73 |
+
* @return array
|
| 74 |
+
*/
|
| 75 |
+
protected function _getProfileData()
|
| 76 |
+
{
|
| 77 |
+
$syncedFields = Mage::helper('marketingsoftware/config')->getLinkedCustomerFields();
|
| 78 |
+
|
| 79 |
+
$data = $this->_getRequestData($this->_customerEntity, $syncedFields);
|
| 80 |
+
$data = array_merge($data, array('customer_id' => $this->_customerEntity->getCustomerId()));
|
| 81 |
+
|
| 82 |
+
return $data;
|
| 83 |
+
}
|
| 84 |
+
}
|
app/code/community/Copernica/MarketingSoftware/Model/Rest/Order.php
CHANGED
|
@@ -1,158 +1,158 @@
|
|
| 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 |
-
* Order REST entity
|
| 29 |
-
*/
|
| 30 |
-
class Copernica_MarketingSoftware_Model_Rest_Order extends Copernica_MarketingSoftware_Model_Rest
|
| 31 |
-
{
|
| 32 |
-
/**
|
| 33 |
-
* Cached order entity
|
| 34 |
-
*
|
| 35 |
-
* @var Copernica_MarketingSoftware_Model_Copernica_Entity_Order
|
| 36 |
-
*/
|
| 37 |
-
protected $_orderEntity = null;
|
| 38 |
-
|
| 39 |
-
/**
|
| 40 |
-
* Sync order
|
| 41 |
-
*
|
| 42 |
-
* @param Copernica_MarketingSoftware_Model_Copernica_Entity_Customer
|
| 43 |
-
*/
|
| 44 |
-
public function syncWithCustomer(Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer)
|
| 45 |
-
{
|
| 46 |
-
$customer->setStore($this->_orderEntity->getStoreView());
|
| 47 |
-
|
| 48 |
-
$profileId = Mage::helper('marketingsoftware/api')->getProfileId(array(
|
| 49 |
-
'id' => $customer->getCustomerId(),
|
| 50 |
-
'storeView' => (string) $customer->getStoreView(),
|
| 51 |
-
'email' => $customer->getEmail(),
|
| 52 |
-
));
|
| 53 |
-
|
| 54 |
-
if (!$profileId) {
|
| 55 |
-
$profileId = $this->_createProfile($customer);
|
| 56 |
-
|
| 57 |
-
if(!$profileId) {
|
| 58 |
-
return false;
|
| 59 |
-
}
|
| 60 |
-
}
|
| 61 |
-
|
| 62 |
-
$this->syncWithProfile($profileId);
|
| 63 |
-
|
| 64 |
-
return true;
|
| 65 |
-
}
|
| 66 |
-
|
| 67 |
-
/**
|
| 68 |
-
* Sync with guest data.
|
| 69 |
-
*
|
| 70 |
-
* @param array $guestData
|
| 71 |
-
* @return bool
|
| 72 |
-
*/
|
| 73 |
-
public function syncWithGuest($guestData)
|
| 74 |
-
{
|
| 75 |
-
$profileId = Mage::helper('marketingsoftware/api')->getProfileId(array(
|
| 76 |
-
'storeView' => $guestData['storeView'],
|
| 77 |
-
'email' => $guestData['email'],
|
| 78 |
-
));
|
| 79 |
-
|
| 80 |
-
if ($profileId) {
|
| 81 |
-
$data = array();
|
| 82 |
-
|
| 83 |
-
$syncedFields = Mage::helper('marketingsoftware/config')->getLinkedCustomerFields();
|
| 84 |
-
|
| 85 |
-
Mage::helper('marketingsoftware/rest_request')->post('/profile/'.$profileId.'/fields', $guestData);
|
| 86 |
-
} else {
|
| 87 |
-
$profileId = $this->_createProfile($guestData);
|
| 88 |
-
|
| 89 |
-
if ($profileId == false) {
|
| 90 |
-
return false;
|
| 91 |
-
}
|
| 92 |
-
}
|
| 93 |
-
|
| 94 |
-
$this->syncWithProfile($profileId);
|
| 95 |
-
|
| 96 |
-
return true;
|
| 97 |
-
}
|
| 98 |
-
|
| 99 |
-
/**
|
| 100 |
-
* Sync order with certain profile
|
| 101 |
-
*
|
| 102 |
-
* @param int $profileId
|
| 103 |
-
*/
|
| 104 |
-
public function syncWithProfile($profileId)
|
| 105 |
-
{
|
| 106 |
-
$collectionId = Mage::helper('marketingsoftware/config')->getOrdersCollectionId();
|
| 107 |
-
|
| 108 |
-
if ($collectionId) Mage::helper('marketingsoftware/rest_request')->put('/profile/'.$profileId.'/subprofiles/'.$collectionId, $this->_getSubprofileData(), array(
|
| 109 |
-
'fields' => array(
|
| 110 |
-
'order_id=='.$this->_orderEntity->getId(),
|
| 111 |
-
'quote_id=='.$this->_orderEntity->getQuoteId()
|
| 112 |
-
),
|
| 113 |
-
'create' => 'true'
|
| 114 |
-
));
|
| 115 |
-
|
| 116 |
-
$shippingAddress = $this->_orderEntity->getShippingAddress();
|
| 117 |
-
$billingAddress = $this->_orderEntity->getBillingAddress();
|
| 118 |
-
|
| 119 |
-
if ($shippingAddress) {
|
| 120 |
-
$restAddress = $shippingAddress->getRestAddress();
|
| 121 |
-
$restAddress->syncWithProfile($profileId);
|
| 122 |
-
}
|
| 123 |
-
|
| 124 |
-
if ($billingAddress) {
|
| 125 |
-
$restAddress = $billingAddress->getRestAddress();
|
| 126 |
-
$restAddress->syncWithProfile($profileId);
|
| 127 |
-
}
|
| 128 |
-
|
| 129 |
-
foreach ($this->_orderEntity->getItems() as $orderItemEntity) {
|
| 130 |
-
$restOrderItem = $orderItemEntity->getRestOrderItem();
|
| 131 |
-
$restOrderItem->syncWithProfile($profileId, $this->_orderEntity);
|
| 132 |
-
}
|
| 133 |
-
}
|
| 134 |
-
|
| 135 |
-
/**
|
| 136 |
-
* Get subprofile data
|
| 137 |
-
*
|
| 138 |
-
* @return array
|
| 139 |
-
*/
|
| 140 |
-
protected function _getSubprofileData()
|
| 141 |
-
{
|
| 142 |
-
$syncedFields = Mage::helper('marketingsoftware/config')->getLinkedOrderFields();
|
| 143 |
-
|
| 144 |
-
$data = $this->_getRequestData($this->_orderEntity, $syncedFields);
|
| 145 |
-
|
| 146 |
-
return array_merge($data, array('order_id' => $this->_orderEntity->getId(), 'quote_id' => $this->_orderEntity->getQuoteId() ));
|
| 147 |
-
}
|
| 148 |
-
|
| 149 |
-
/**
|
| 150 |
-
* Set REST order entity
|
| 151 |
-
*
|
| 152 |
-
* @param Copernica_MarketingSoftwarer_Model_Copernica_Entity_Order $orderEntity
|
| 153 |
-
*/
|
| 154 |
-
public function setOrderEntity(Copernica_MarketingSoftwarer_Model_Copernica_Entity_Order $orderEntity)
|
| 155 |
-
{
|
| 156 |
-
$this->_orderEntity = $orderEntity;
|
| 157 |
-
}
|
| 158 |
}
|
| 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 |
+
* Order REST entity
|
| 29 |
+
*/
|
| 30 |
+
class Copernica_MarketingSoftware_Model_Rest_Order extends Copernica_MarketingSoftware_Model_Rest
|
| 31 |
+
{
|
| 32 |
+
/**
|
| 33 |
+
* Cached order entity
|
| 34 |
+
*
|
| 35 |
+
* @var Copernica_MarketingSoftware_Model_Copernica_Entity_Order
|
| 36 |
+
*/
|
| 37 |
+
protected $_orderEntity = null;
|
| 38 |
+
|
| 39 |
+
/**
|
| 40 |
+
* Sync order
|
| 41 |
+
*
|
| 42 |
+
* @param Copernica_MarketingSoftware_Model_Copernica_Entity_Customer
|
| 43 |
+
*/
|
| 44 |
+
public function syncWithCustomer(Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer)
|
| 45 |
+
{
|
| 46 |
+
$customer->setStore($this->_orderEntity->getStoreView());
|
| 47 |
+
|
| 48 |
+
$profileId = Mage::helper('marketingsoftware/api')->getProfileId(array(
|
| 49 |
+
'id' => $customer->getCustomerId(),
|
| 50 |
+
'storeView' => (string) $customer->getStoreView(),
|
| 51 |
+
'email' => $customer->getEmail(),
|
| 52 |
+
));
|
| 53 |
+
|
| 54 |
+
if (!$profileId) {
|
| 55 |
+
$profileId = $this->_createProfile($customer);
|
| 56 |
+
|
| 57 |
+
if(!$profileId) {
|
| 58 |
+
return false;
|
| 59 |
+
}
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
$this->syncWithProfile($profileId);
|
| 63 |
+
|
| 64 |
+
return true;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
/**
|
| 68 |
+
* Sync with guest data.
|
| 69 |
+
*
|
| 70 |
+
* @param array $guestData
|
| 71 |
+
* @return bool
|
| 72 |
+
*/
|
| 73 |
+
public function syncWithGuest($guestData)
|
| 74 |
+
{
|
| 75 |
+
$profileId = Mage::helper('marketingsoftware/api')->getProfileId(array(
|
| 76 |
+
'storeView' => $guestData['storeView'],
|
| 77 |
+
'email' => $guestData['email'],
|
| 78 |
+
));
|
| 79 |
+
|
| 80 |
+
if ($profileId) {
|
| 81 |
+
$data = array();
|
| 82 |
+
|
| 83 |
+
$syncedFields = Mage::helper('marketingsoftware/config')->getLinkedCustomerFields();
|
| 84 |
+
|
| 85 |
+
Mage::helper('marketingsoftware/rest_request')->post('/profile/'.$profileId.'/fields', $guestData);
|
| 86 |
+
} else {
|
| 87 |
+
$profileId = $this->_createProfile($guestData);
|
| 88 |
+
|
| 89 |
+
if ($profileId == false) {
|
| 90 |
+
return false;
|
| 91 |
+
}
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
$this->syncWithProfile($profileId);
|
| 95 |
+
|
| 96 |
+
return true;
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
/**
|
| 100 |
+
* Sync order with certain profile
|
| 101 |
+
*
|
| 102 |
+
* @param int $profileId
|
| 103 |
+
*/
|
| 104 |
+
public function syncWithProfile($profileId)
|
| 105 |
+
{
|
| 106 |
+
$collectionId = Mage::helper('marketingsoftware/config')->getOrdersCollectionId();
|
| 107 |
+
|
| 108 |
+
if ($collectionId) Mage::helper('marketingsoftware/rest_request')->put('/profile/'.$profileId.'/subprofiles/'.$collectionId, $this->_getSubprofileData(), array(
|
| 109 |
+
'fields' => array(
|
| 110 |
+
'order_id=='.$this->_orderEntity->getId(),
|
| 111 |
+
'quote_id=='.$this->_orderEntity->getQuoteId()
|
| 112 |
+
),
|
| 113 |
+
'create' => 'true'
|
| 114 |
+
));
|
| 115 |
+
|
| 116 |
+
$shippingAddress = $this->_orderEntity->getShippingAddress();
|
| 117 |
+
$billingAddress = $this->_orderEntity->getBillingAddress();
|
| 118 |
+
|
| 119 |
+
if ($shippingAddress) {
|
| 120 |
+
$restAddress = $shippingAddress->getRestAddress();
|
| 121 |
+
$restAddress->syncWithProfile($profileId);
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
if ($billingAddress) {
|
| 125 |
+
$restAddress = $billingAddress->getRestAddress();
|
| 126 |
+
$restAddress->syncWithProfile($profileId);
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
foreach ($this->_orderEntity->getItems() as $orderItemEntity) {
|
| 130 |
+
$restOrderItem = $orderItemEntity->getRestOrderItem();
|
| 131 |
+
$restOrderItem->syncWithProfile($profileId, $this->_orderEntity);
|
| 132 |
+
}
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
/**
|
| 136 |
+
* Get subprofile data
|
| 137 |
+
*
|
| 138 |
+
* @return array
|
| 139 |
+
*/
|
| 140 |
+
protected function _getSubprofileData()
|
| 141 |
+
{
|
| 142 |
+
$syncedFields = Mage::helper('marketingsoftware/config')->getLinkedOrderFields();
|
| 143 |
+
|
| 144 |
+
$data = $this->_getRequestData($this->_orderEntity, $syncedFields);
|
| 145 |
+
|
| 146 |
+
return array_merge($data, array('order_id' => $this->_orderEntity->getId(), 'quote_id' => $this->_orderEntity->getQuoteId() ));
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
/**
|
| 150 |
+
* Set REST order entity
|
| 151 |
+
*
|
| 152 |
+
* @param Copernica_MarketingSoftwarer_Model_Copernica_Entity_Order $orderEntity
|
| 153 |
+
*/
|
| 154 |
+
public function setOrderEntity(Copernica_MarketingSoftwarer_Model_Copernica_Entity_Order $orderEntity)
|
| 155 |
+
{
|
| 156 |
+
$this->_orderEntity = $orderEntity;
|
| 157 |
+
}
|
| 158 |
}
|
app/code/community/Copernica/MarketingSoftware/Model/Rest/Order/Item.php
CHANGED
|
@@ -1,126 +1,126 @@
|
|
| 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 bridge class between Magento Item and Copernica subprofile
|
| 29 |
-
*/
|
| 30 |
-
class Copernica_MarketingSoftware_Model_Rest_Order_Item extends Copernica_MarketingSoftware_Model_Rest
|
| 31 |
-
{
|
| 32 |
-
/**
|
| 33 |
-
* Item that we want to use
|
| 34 |
-
*
|
| 35 |
-
* @var Copernica_MarketingSoftware_Model_Copernica_Entity_Order_Item
|
| 36 |
-
*/
|
| 37 |
-
protected $_orderItemEntity = null;
|
| 38 |
-
|
| 39 |
-
/**
|
| 40 |
-
* Sync item with customer
|
| 41 |
-
*
|
| 42 |
-
* @param Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer
|
| 43 |
-
* @param Copernica_MarketingSoftware_Model_Copernica_Entity_Order $order
|
| 44 |
-
* @return boolean
|
| 45 |
-
*/
|
| 46 |
-
public function syncWithCustomer(Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer, Copernica_MarketingSoftware_Model_Copernica_Entity_Order $order)
|
| 47 |
-
{
|
| 48 |
-
$customer->setStore($this->_orderItemEntity->getStoreView());
|
| 49 |
-
|
| 50 |
-
$profileId = Mage::helper('marketingsoftware/api')->getProfileId(array(
|
| 51 |
-
'id' => $customer->getCustomerId(),
|
| 52 |
-
'storeView' => (string) $customer->getStoreView(),
|
| 53 |
-
'email' => $customer->getEmail(),
|
| 54 |
-
));
|
| 55 |
-
|
| 56 |
-
if (!$profileId) {
|
| 57 |
-
$profileId = $this->_createProfile($customer);
|
| 58 |
-
|
| 59 |
-
if(!$profileId) {
|
| 60 |
-
return false;
|
| 61 |
-
}
|
| 62 |
-
}
|
| 63 |
-
|
| 64 |
-
$this->syncWithProfile($profileId);
|
| 65 |
-
|
| 66 |
-
return true;
|
| 67 |
-
}
|
| 68 |
-
|
| 69 |
-
/**
|
| 70 |
-
* Sync order items with certain profile
|
| 71 |
-
*
|
| 72 |
-
* @param int $profileId
|
| 73 |
-
* @param Copernica_MarketingSoftware_Model_Copernica_Entity_Order $order
|
| 74 |
-
* @return bool
|
| 75 |
-
*/
|
| 76 |
-
public function syncWithProfile($profileId, Copernica_MarketingSoftware_Model_Copernica_Entity_Order $order)
|
| 77 |
-
{
|
| 78 |
-
$itemCollectionId = Mage::helper('marketingsoftware/config')->getOrderItemCollectionId();
|
| 79 |
-
|
| 80 |
-
if ($itemCollectionId) {
|
| 81 |
-
Mage::helper('marketingsoftware/rest_request')->put('/profile/'.$profileId.'/subprofiles/'.$itemCollectionId, $this->_getSubprofileData($order), array(
|
| 82 |
-
'fields' => array (
|
| 83 |
-
'item_id=='.$this->_orderItemEntity->getId(),
|
| 84 |
-
'order_id=='.$order->getId()
|
| 85 |
-
),
|
| 86 |
-
'create' => 'true'
|
| 87 |
-
));
|
| 88 |
-
|
| 89 |
-
return true;
|
| 90 |
-
} else {
|
| 91 |
-
return false;
|
| 92 |
-
}
|
| 93 |
-
|
| 94 |
-
}
|
| 95 |
-
|
| 96 |
-
/**
|
| 97 |
-
* Prepare subprofile data
|
| 98 |
-
*
|
| 99 |
-
* @param Copernica_MarketingSoftware_Model_Copernica_Entity_Order $order
|
| 100 |
-
* @return array
|
| 101 |
-
*/
|
| 102 |
-
protected function _getSubprofileData(Copernica_MarketingSoftware_Model_Copernica_Entity_Order $order)
|
| 103 |
-
{
|
| 104 |
-
$syncedFields = Mage::helper('marketingsoftware/config')->getLinkedOrderItemFields();
|
| 105 |
-
|
| 106 |
-
$data = $this->_getRequestData($this->_orderItemEntity, $syncedFields);
|
| 107 |
-
|
| 108 |
-
if (!empty($syncedFields['incrementId'])) {
|
| 109 |
-
$data['incrementId'] = $order->getIncrementId();
|
| 110 |
-
}
|
| 111 |
-
|
| 112 |
-
$data['item_id'] = $this->_orderItemEntity->getId();
|
| 113 |
-
$data['order_id'] = $order->getId();
|
| 114 |
-
|
| 115 |
-
return $data;
|
| 116 |
-
}
|
| 117 |
-
|
| 118 |
-
/**
|
| 119 |
-
* Set REST order item entity
|
| 120 |
-
* @param Copernica_MarketingSoftware_Model_Copernica_Entity_Order_Item $orderItem
|
| 121 |
-
*/
|
| 122 |
-
public function setOrderItemEntity(Copernica_MarketingSoftware_Model_Copernica_Entity_Order_Item $orderItem)
|
| 123 |
-
{
|
| 124 |
-
$this->_orderItemEntity = $orderItem;
|
| 125 |
-
}
|
| 126 |
-
}
|
| 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 bridge class between Magento Item and Copernica subprofile
|
| 29 |
+
*/
|
| 30 |
+
class Copernica_MarketingSoftware_Model_Rest_Order_Item extends Copernica_MarketingSoftware_Model_Rest
|
| 31 |
+
{
|
| 32 |
+
/**
|
| 33 |
+
* Item that we want to use
|
| 34 |
+
*
|
| 35 |
+
* @var Copernica_MarketingSoftware_Model_Copernica_Entity_Order_Item
|
| 36 |
+
*/
|
| 37 |
+
protected $_orderItemEntity = null;
|
| 38 |
+
|
| 39 |
+
/**
|
| 40 |
+
* Sync item with customer
|
| 41 |
+
*
|
| 42 |
+
* @param Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer
|
| 43 |
+
* @param Copernica_MarketingSoftware_Model_Copernica_Entity_Order $order
|
| 44 |
+
* @return boolean
|
| 45 |
+
*/
|
| 46 |
+
public function syncWithCustomer(Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer, Copernica_MarketingSoftware_Model_Copernica_Entity_Order $order)
|
| 47 |
+
{
|
| 48 |
+
$customer->setStore($this->_orderItemEntity->getStoreView());
|
| 49 |
+
|
| 50 |
+
$profileId = Mage::helper('marketingsoftware/api')->getProfileId(array(
|
| 51 |
+
'id' => $customer->getCustomerId(),
|
| 52 |
+
'storeView' => (string) $customer->getStoreView(),
|
| 53 |
+
'email' => $customer->getEmail(),
|
| 54 |
+
));
|
| 55 |
+
|
| 56 |
+
if (!$profileId) {
|
| 57 |
+
$profileId = $this->_createProfile($customer);
|
| 58 |
+
|
| 59 |
+
if(!$profileId) {
|
| 60 |
+
return false;
|
| 61 |
+
}
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
$this->syncWithProfile($profileId);
|
| 65 |
+
|
| 66 |
+
return true;
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
/**
|
| 70 |
+
* Sync order items with certain profile
|
| 71 |
+
*
|
| 72 |
+
* @param int $profileId
|
| 73 |
+
* @param Copernica_MarketingSoftware_Model_Copernica_Entity_Order $order
|
| 74 |
+
* @return bool
|
| 75 |
+
*/
|
| 76 |
+
public function syncWithProfile($profileId, Copernica_MarketingSoftware_Model_Copernica_Entity_Order $order)
|
| 77 |
+
{
|
| 78 |
+
$itemCollectionId = Mage::helper('marketingsoftware/config')->getOrderItemCollectionId();
|
| 79 |
+
|
| 80 |
+
if ($itemCollectionId) {
|
| 81 |
+
Mage::helper('marketingsoftware/rest_request')->put('/profile/'.$profileId.'/subprofiles/'.$itemCollectionId, $this->_getSubprofileData($order), array(
|
| 82 |
+
'fields' => array (
|
| 83 |
+
'item_id=='.$this->_orderItemEntity->getId(),
|
| 84 |
+
'order_id=='.$order->getId()
|
| 85 |
+
),
|
| 86 |
+
'create' => 'true'
|
| 87 |
+
));
|
| 88 |
+
|
| 89 |
+
return true;
|
| 90 |
+
} else {
|
| 91 |
+
return false;
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
/**
|
| 97 |
+
* Prepare subprofile data
|
| 98 |
+
*
|
| 99 |
+
* @param Copernica_MarketingSoftware_Model_Copernica_Entity_Order $order
|
| 100 |
+
* @return array
|
| 101 |
+
*/
|
| 102 |
+
protected function _getSubprofileData(Copernica_MarketingSoftware_Model_Copernica_Entity_Order $order)
|
| 103 |
+
{
|
| 104 |
+
$syncedFields = Mage::helper('marketingsoftware/config')->getLinkedOrderItemFields();
|
| 105 |
+
|
| 106 |
+
$data = $this->_getRequestData($this->_orderItemEntity, $syncedFields);
|
| 107 |
+
|
| 108 |
+
if (!empty($syncedFields['incrementId'])) {
|
| 109 |
+
$data['incrementId'] = $order->getIncrementId();
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
$data['item_id'] = $this->_orderItemEntity->getId();
|
| 113 |
+
$data['order_id'] = $order->getId();
|
| 114 |
+
|
| 115 |
+
return $data;
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
/**
|
| 119 |
+
* Set REST order item entity
|
| 120 |
+
* @param Copernica_MarketingSoftware_Model_Copernica_Entity_Order_Item $orderItem
|
| 121 |
+
*/
|
| 122 |
+
public function setOrderItemEntity(Copernica_MarketingSoftware_Model_Copernica_Entity_Order_Item $orderItem)
|
| 123 |
+
{
|
| 124 |
+
$this->_orderItemEntity = $orderItem;
|
| 125 |
+
}
|
| 126 |
+
}
|
app/code/community/Copernica/MarketingSoftware/Model/Rest/Product.php
CHANGED
|
@@ -1,95 +1,95 @@
|
|
| 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 |
-
* REST entity that will communicate with Copernica platform
|
| 29 |
-
*/
|
| 30 |
-
class Copernica_MarketingSoftware_Model_Rest_Product extends Copernica_MarketingSoftware_Model_Rest
|
| 31 |
-
{
|
| 32 |
-
/**
|
| 33 |
-
* Cached product entity
|
| 34 |
-
*
|
| 35 |
-
* @var Copernica_MarketingSoftware_Model_Copernica_Entity_Product
|
| 36 |
-
*/
|
| 37 |
-
protected $_productEntity;
|
| 38 |
-
|
| 39 |
-
/**
|
| 40 |
-
* Get subprofile data
|
| 41 |
-
*
|
| 42 |
-
* @return array
|
| 43 |
-
*/
|
| 44 |
-
protected function _getSubprofileData()
|
| 45 |
-
{
|
| 46 |
-
$syncedFields = Mage::helper('marketingsoftware/config')->getLinkedViewedProductFields();
|
| 47 |
-
|
| 48 |
-
$data = $this->_getRequestData($this->_productEntity, $syncedFields);
|
| 49 |
-
$data['product_id'] = $this->_productEntity->getId();
|
| 50 |
-
|
| 51 |
-
return $data;
|
| 52 |
-
}
|
| 53 |
-
|
| 54 |
-
/**
|
| 55 |
-
* Tell Copernica platform that product was viewed by a customer
|
| 56 |
-
*
|
| 57 |
-
* @param Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer
|
| 58 |
-
*/
|
| 59 |
-
public function viewedBy(Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer)
|
| 60 |
-
{
|
| 61 |
-
$customer->setStore($this->_productEntity->getStoreView());
|
| 62 |
-
|
| 63 |
-
$profileId = Mage::helper('marketingsoftware/api')->getProfileId(array(
|
| 64 |
-
'id' => $customer->getCustomerId(),
|
| 65 |
-
'storeView' => (string) $customer->getStoreView(),
|
| 66 |
-
'email' => $customer->getEmail(),
|
| 67 |
-
));
|
| 68 |
-
|
| 69 |
-
if (!$profileId) {
|
| 70 |
-
$profileId = $this->_createProfile($customer);
|
| 71 |
-
|
| 72 |
-
if(!$profileId) {
|
| 73 |
-
return false;
|
| 74 |
-
}
|
| 75 |
-
}
|
| 76 |
-
|
| 77 |
-
$collectionId = Mage::helper('marketingsoftware/config')->getViewedProductCollectionId();
|
| 78 |
-
|
| 79 |
-
if ($collectionId) {
|
| 80 |
-
Mage::helper('marketingsoftware/rest_request')->put('/profile/'.$profileId.'/subprofiles/'.$collectionId, $this->_getSubprofileData(), array(
|
| 81 |
-
'fields[]' => 'product_id=='.$this->_productEntity->getId(),
|
| 82 |
-
'create' => 'true'
|
| 83 |
-
));
|
| 84 |
-
}
|
| 85 |
-
}
|
| 86 |
-
|
| 87 |
-
/**
|
| 88 |
-
* Set REST product entity
|
| 89 |
-
*
|
| 90 |
-
* @param Copernica_MarketingSoftware_Model_Copernica_Entity_Product $productEntity
|
| 91 |
-
*/
|
| 92 |
-
public function setProductEntity(Copernica_MarketingSoftware_Model_Copernica_Entity_Product $productEntity) {
|
| 93 |
-
$this->_productEntity = $productEntity;
|
| 94 |
-
}
|
| 95 |
}
|
| 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 |
+
* REST entity that will communicate with Copernica platform
|
| 29 |
+
*/
|
| 30 |
+
class Copernica_MarketingSoftware_Model_Rest_Product extends Copernica_MarketingSoftware_Model_Rest
|
| 31 |
+
{
|
| 32 |
+
/**
|
| 33 |
+
* Cached product entity
|
| 34 |
+
*
|
| 35 |
+
* @var Copernica_MarketingSoftware_Model_Copernica_Entity_Product
|
| 36 |
+
*/
|
| 37 |
+
protected $_productEntity;
|
| 38 |
+
|
| 39 |
+
/**
|
| 40 |
+
* Get subprofile data
|
| 41 |
+
*
|
| 42 |
+
* @return array
|
| 43 |
+
*/
|
| 44 |
+
protected function _getSubprofileData()
|
| 45 |
+
{
|
| 46 |
+
$syncedFields = Mage::helper('marketingsoftware/config')->getLinkedViewedProductFields();
|
| 47 |
+
|
| 48 |
+
$data = $this->_getRequestData($this->_productEntity, $syncedFields);
|
| 49 |
+
$data['product_id'] = $this->_productEntity->getId();
|
| 50 |
+
|
| 51 |
+
return $data;
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
/**
|
| 55 |
+
* Tell Copernica platform that product was viewed by a customer
|
| 56 |
+
*
|
| 57 |
+
* @param Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer
|
| 58 |
+
*/
|
| 59 |
+
public function viewedBy(Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer)
|
| 60 |
+
{
|
| 61 |
+
$customer->setStore($this->_productEntity->getStoreView());
|
| 62 |
+
|
| 63 |
+
$profileId = Mage::helper('marketingsoftware/api')->getProfileId(array(
|
| 64 |
+
'id' => $customer->getCustomerId(),
|
| 65 |
+
'storeView' => (string) $customer->getStoreView(),
|
| 66 |
+
'email' => $customer->getEmail(),
|
| 67 |
+
));
|
| 68 |
+
|
| 69 |
+
if (!$profileId) {
|
| 70 |
+
$profileId = $this->_createProfile($customer);
|
| 71 |
+
|
| 72 |
+
if(!$profileId) {
|
| 73 |
+
return false;
|
| 74 |
+
}
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
$collectionId = Mage::helper('marketingsoftware/config')->getViewedProductCollectionId();
|
| 78 |
+
|
| 79 |
+
if ($collectionId) {
|
| 80 |
+
Mage::helper('marketingsoftware/rest_request')->put('/profile/'.$profileId.'/subprofiles/'.$collectionId, $this->_getSubprofileData(), array(
|
| 81 |
+
'fields[]' => 'product_id=='.$this->_productEntity->getId(),
|
| 82 |
+
'create' => 'true'
|
| 83 |
+
));
|
| 84 |
+
}
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
/**
|
| 88 |
+
* Set REST product entity
|
| 89 |
+
*
|
| 90 |
+
* @param Copernica_MarketingSoftware_Model_Copernica_Entity_Product $productEntity
|
| 91 |
+
*/
|
| 92 |
+
public function setProductEntity(Copernica_MarketingSoftware_Model_Copernica_Entity_Product $productEntity) {
|
| 93 |
+
$this->_productEntity = $productEntity;
|
| 94 |
+
}
|
| 95 |
}
|
app/code/community/Copernica/MarketingSoftware/Model/Rest/Quote.php
CHANGED
|
@@ -1,80 +1,80 @@
|
|
| 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 |
-
* Quote REST entity
|
| 29 |
-
*/
|
| 30 |
-
class Copernica_MarketingSoftware_Model_Rest_Quote extends Copernica_MarketingSoftware_Model_Rest
|
| 31 |
-
{
|
| 32 |
-
/**
|
| 33 |
-
* Copernica entity
|
| 34 |
-
*
|
| 35 |
-
* @var Copernica_MarketingSoftware_Model_Copernica_Entity_Quote
|
| 36 |
-
*/
|
| 37 |
-
protected $_quoteEntity;
|
| 38 |
-
|
| 39 |
-
/**
|
| 40 |
-
* Fetch quote Id
|
| 41 |
-
*
|
| 42 |
-
* @return string
|
| 43 |
-
*/
|
| 44 |
-
public function fetchId()
|
| 45 |
-
{
|
| 46 |
-
return $this->_quoteEntity->getId();
|
| 47 |
-
}
|
| 48 |
-
|
| 49 |
-
/**
|
| 50 |
-
* Fetch quote status
|
| 51 |
-
*
|
| 52 |
-
* @return string
|
| 53 |
-
*/
|
| 54 |
-
public function fetchStatus()
|
| 55 |
-
{
|
| 56 |
-
return $this->_quoteEntity->getStatus();
|
| 57 |
-
}
|
| 58 |
-
|
| 59 |
-
/**
|
| 60 |
-
* Sync quote with customer
|
| 61 |
-
*
|
| 62 |
-
* @param Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer
|
| 63 |
-
*/
|
| 64 |
-
public function syncWithCustomer(Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer)
|
| 65 |
-
{
|
| 66 |
-
foreach ($this->_quoteEntity->getItems() as $quoteItemEntity) {
|
| 67 |
-
$restQuoteItem = $quoteItemEntity->getRestQuoteItem();
|
| 68 |
-
$restQuoteItem->syncWithQuote($customer, $this->_quoteEntity->getId());
|
| 69 |
-
}
|
| 70 |
-
}
|
| 71 |
-
|
| 72 |
-
/**
|
| 73 |
-
* Set REST quote entity
|
| 74 |
-
*
|
| 75 |
-
* @param Copernica_MarketingSoftware_Model_Copernica_Entity_Quote $quoteEntity
|
| 76 |
-
*/
|
| 77 |
-
public function setQuoteEntity(Copernica_MarketingSoftware_Model_Copernica_Entity_Quote $quoteEntity) {
|
| 78 |
-
$this->_quoteEntity = $quoteEntity;
|
| 79 |
-
}
|
| 80 |
}
|
| 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 |
+
* Quote REST entity
|
| 29 |
+
*/
|
| 30 |
+
class Copernica_MarketingSoftware_Model_Rest_Quote extends Copernica_MarketingSoftware_Model_Rest
|
| 31 |
+
{
|
| 32 |
+
/**
|
| 33 |
+
* Copernica entity
|
| 34 |
+
*
|
| 35 |
+
* @var Copernica_MarketingSoftware_Model_Copernica_Entity_Quote
|
| 36 |
+
*/
|
| 37 |
+
protected $_quoteEntity;
|
| 38 |
+
|
| 39 |
+
/**
|
| 40 |
+
* Fetch quote Id
|
| 41 |
+
*
|
| 42 |
+
* @return string
|
| 43 |
+
*/
|
| 44 |
+
public function fetchId()
|
| 45 |
+
{
|
| 46 |
+
return $this->_quoteEntity->getId();
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
/**
|
| 50 |
+
* Fetch quote status
|
| 51 |
+
*
|
| 52 |
+
* @return string
|
| 53 |
+
*/
|
| 54 |
+
public function fetchStatus()
|
| 55 |
+
{
|
| 56 |
+
return $this->_quoteEntity->getStatus();
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
/**
|
| 60 |
+
* Sync quote with customer
|
| 61 |
+
*
|
| 62 |
+
* @param Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer
|
| 63 |
+
*/
|
| 64 |
+
public function syncWithCustomer(Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer)
|
| 65 |
+
{
|
| 66 |
+
foreach ($this->_quoteEntity->getItems() as $quoteItemEntity) {
|
| 67 |
+
$restQuoteItem = $quoteItemEntity->getRestQuoteItem();
|
| 68 |
+
$restQuoteItem->syncWithQuote($customer, $this->_quoteEntity->getId());
|
| 69 |
+
}
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
/**
|
| 73 |
+
* Set REST quote entity
|
| 74 |
+
*
|
| 75 |
+
* @param Copernica_MarketingSoftware_Model_Copernica_Entity_Quote $quoteEntity
|
| 76 |
+
*/
|
| 77 |
+
public function setQuoteEntity(Copernica_MarketingSoftware_Model_Copernica_Entity_Quote $quoteEntity) {
|
| 78 |
+
$this->_quoteEntity = $quoteEntity;
|
| 79 |
+
}
|
| 80 |
}
|
app/code/community/Copernica/MarketingSoftware/Model/Rest/Quote/Item.php
CHANGED
|
@@ -1,80 +1,80 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
|
| 3 |
-
class Copernica_MarketingSoftware_Model_Rest_Quote_Item extends Copernica_MarketingSoftware_Model_Rest_Order_Item
|
| 4 |
-
{
|
| 5 |
-
/**
|
| 6 |
-
* Customer that will be used to send data
|
| 7 |
-
*
|
| 8 |
-
* @var Copernica_MarketingSoftware_Model_Copernica_Entity_Quote_Item
|
| 9 |
-
*/
|
| 10 |
-
protected $_quoteItemEntity;
|
| 11 |
-
|
| 12 |
-
/**
|
| 13 |
-
* Sync item with quote
|
| 14 |
-
*
|
| 15 |
-
* @param Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer
|
| 16 |
-
* @param int $quoteId
|
| 17 |
-
* @return boolean
|
| 18 |
-
*/
|
| 19 |
-
public function syncWithQuote(Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer, $quoteId)
|
| 20 |
-
{
|
| 21 |
-
$customer->setStore($this->_quoteItemEntity->getStoreView());
|
| 22 |
-
|
| 23 |
-
$profileId = Mage::helper('marketingsoftware/api')->getProfileId(array(
|
| 24 |
-
'id' => $customer->getCustomerId(),
|
| 25 |
-
'storeView' => (string) $customer->getStoreView(),
|
| 26 |
-
'email' => $customer->getEmail(),
|
| 27 |
-
));
|
| 28 |
-
|
| 29 |
-
if (!$profileId) {
|
| 30 |
-
$profileId = $this->_createProfile($customer);
|
| 31 |
-
|
| 32 |
-
if(!$profileId) {
|
| 33 |
-
return false;
|
| 34 |
-
}
|
| 35 |
-
}
|
| 36 |
-
|
| 37 |
-
$quoteItemCollectionId = Mage::helper('marketingsoftware/config')->getQuoteItemCollectionId();
|
| 38 |
-
|
| 39 |
-
if ($quoteItemCollectionId) {
|
| 40 |
-
Mage::helper('marketingsoftware/rest_request')->put('/profile/'.$profileId.'/subprofiles/'.$quoteItemCollectionId, $this->getQuoteItemSubprofileData($quoteId), array(
|
| 41 |
-
'fields' => array(
|
| 42 |
-
'item_id=='.$this->_quoteItemEntity->getId(),
|
| 43 |
-
'quote_id=='.$quoteId
|
| 44 |
-
),
|
| 45 |
-
'create' => 'true'
|
| 46 |
-
));
|
| 47 |
-
}
|
| 48 |
-
|
| 49 |
-
return true;
|
| 50 |
-
}
|
| 51 |
-
|
| 52 |
-
/**
|
| 53 |
-
* Prepare subprofile date
|
| 54 |
-
*
|
| 55 |
-
* @param int $quoteId
|
| 56 |
-
* @return array
|
| 57 |
-
*/
|
| 58 |
-
public function getQuoteItemSubprofileData($quoteId)
|
| 59 |
-
{
|
| 60 |
-
$syncedFields = Mage::helper('marketingsoftware/config')->getLinkedQuoteItemFields();
|
| 61 |
-
|
| 62 |
-
$data = $this->_getRequestData($this->_quoteItemEntity, $syncedFields);
|
| 63 |
-
$data['quote_id'] = $quoteId;
|
| 64 |
-
$data['item_id'] = $this->_quoteItemEntity->getId();
|
| 65 |
-
$data['status'] = $this->_quoteItemEntity->getStatus();
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
return $data;
|
| 69 |
-
}
|
| 70 |
-
|
| 71 |
-
/**
|
| 72 |
-
* Set REST quote item entity
|
| 73 |
-
*
|
| 74 |
-
* @param Copernica_MarketingSoftware_Model_Copernica_Entity_Quote_Item $quoteItemEntity
|
| 75 |
-
*/
|
| 76 |
-
public function setQuoteItemEntity(Copernica_MarketingSoftware_Model_Copernica_Entity_Quote_Item $quoteItemEntity)
|
| 77 |
-
{
|
| 78 |
-
$this->_quoteItemEntity = $quoteItemEntity;
|
| 79 |
-
}
|
| 80 |
}
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
class Copernica_MarketingSoftware_Model_Rest_Quote_Item extends Copernica_MarketingSoftware_Model_Rest_Order_Item
|
| 4 |
+
{
|
| 5 |
+
/**
|
| 6 |
+
* Customer that will be used to send data
|
| 7 |
+
*
|
| 8 |
+
* @var Copernica_MarketingSoftware_Model_Copernica_Entity_Quote_Item
|
| 9 |
+
*/
|
| 10 |
+
protected $_quoteItemEntity;
|
| 11 |
+
|
| 12 |
+
/**
|
| 13 |
+
* Sync item with quote
|
| 14 |
+
*
|
| 15 |
+
* @param Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer
|
| 16 |
+
* @param int $quoteId
|
| 17 |
+
* @return boolean
|
| 18 |
+
*/
|
| 19 |
+
public function syncWithQuote(Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer, $quoteId)
|
| 20 |
+
{
|
| 21 |
+
$customer->setStore($this->_quoteItemEntity->getStoreView());
|
| 22 |
+
|
| 23 |
+
$profileId = Mage::helper('marketingsoftware/api')->getProfileId(array(
|
| 24 |
+
'id' => $customer->getCustomerId(),
|
| 25 |
+
'storeView' => (string) $customer->getStoreView(),
|
| 26 |
+
'email' => $customer->getEmail(),
|
| 27 |
+
));
|
| 28 |
+
|
| 29 |
+
if (!$profileId) {
|
| 30 |
+
$profileId = $this->_createProfile($customer);
|
| 31 |
+
|
| 32 |
+
if(!$profileId) {
|
| 33 |
+
return false;
|
| 34 |
+
}
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
$quoteItemCollectionId = Mage::helper('marketingsoftware/config')->getQuoteItemCollectionId();
|
| 38 |
+
|
| 39 |
+
if ($quoteItemCollectionId) {
|
| 40 |
+
Mage::helper('marketingsoftware/rest_request')->put('/profile/'.$profileId.'/subprofiles/'.$quoteItemCollectionId, $this->getQuoteItemSubprofileData($quoteId), array(
|
| 41 |
+
'fields' => array(
|
| 42 |
+
'item_id=='.$this->_quoteItemEntity->getId(),
|
| 43 |
+
'quote_id=='.$quoteId
|
| 44 |
+
),
|
| 45 |
+
'create' => 'true'
|
| 46 |
+
));
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
return true;
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
/**
|
| 53 |
+
* Prepare subprofile date
|
| 54 |
+
*
|
| 55 |
+
* @param int $quoteId
|
| 56 |
+
* @return array
|
| 57 |
+
*/
|
| 58 |
+
public function getQuoteItemSubprofileData($quoteId)
|
| 59 |
+
{
|
| 60 |
+
$syncedFields = Mage::helper('marketingsoftware/config')->getLinkedQuoteItemFields();
|
| 61 |
+
|
| 62 |
+
$data = $this->_getRequestData($this->_quoteItemEntity, $syncedFields);
|
| 63 |
+
$data['quote_id'] = $quoteId;
|
| 64 |
+
$data['item_id'] = $this->_quoteItemEntity->getId();
|
| 65 |
+
$data['status'] = $this->_quoteItemEntity->getStatus();
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
return $data;
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
/**
|
| 72 |
+
* Set REST quote item entity
|
| 73 |
+
*
|
| 74 |
+
* @param Copernica_MarketingSoftware_Model_Copernica_Entity_Quote_Item $quoteItemEntity
|
| 75 |
+
*/
|
| 76 |
+
public function setQuoteItemEntity(Copernica_MarketingSoftware_Model_Copernica_Entity_Quote_Item $quoteItemEntity)
|
| 77 |
+
{
|
| 78 |
+
$this->_quoteItemEntity = $quoteItemEntity;
|
| 79 |
+
}
|
| 80 |
}
|
app/code/community/Copernica/MarketingSoftware/Model/Rest/Subscription.php
CHANGED
|
@@ -1,96 +1,96 @@
|
|
| 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 |
-
* Entity that will take care of synchronizing subscription with copernica.
|
| 29 |
-
*/
|
| 30 |
-
class Copernica_MarketingSoftware_Model_Rest_Subscription extends Copernica_MarketingSoftware_Model_Rest
|
| 31 |
-
{
|
| 32 |
-
/**
|
| 33 |
-
* Subscription entity that we will use to create proper profile inside
|
| 34 |
-
* copernica database.
|
| 35 |
-
*
|
| 36 |
-
* @var Copernica_MarketingSoftware_Model_Copernica_Entity_Subscription
|
| 37 |
-
*/
|
| 38 |
-
protected $_subscriptionEntity;
|
| 39 |
-
|
| 40 |
-
/**
|
| 41 |
-
* Get data that should be update in copernica database
|
| 42 |
-
*
|
| 43 |
-
* @param string $storeView
|
| 44 |
-
* @return array
|
| 45 |
-
*/
|
| 46 |
-
protected function _getProfileData($storeview)
|
| 47 |
-
{
|
| 48 |
-
$linkedCustomerFields = Mage::helper('marketingsoftware/config')->getLinkedCustomerFields();
|
| 49 |
-
|
| 50 |
-
return array(
|
| 51 |
-
'customer_id' => $this->_subscriptionEntity->getCustomerId(),
|
| 52 |
-
$linkedCustomerFields['email'] => $this->_subscriptionEntity->getEmail(),
|
| 53 |
-
$linkedCustomerFields['group'] => $this->_subscriptionEntity->getGroup(),
|
| 54 |
-
$linkedCustomerFields['newsletter'] => $this->_subscriptionEntity->getStatus(),
|
| 55 |
-
$linkedCustomerFields['storeView'] => $storeview
|
| 56 |
-
);
|
| 57 |
-
}
|
| 58 |
-
|
| 59 |
-
/**
|
| 60 |
-
* Synchronize magento subscriber with copernica profile.
|
| 61 |
-
*
|
| 62 |
-
* @return boolean
|
| 63 |
-
*/
|
| 64 |
-
public function sync()
|
| 65 |
-
{
|
| 66 |
-
$storeview = (string) $this->_subscriptionEntity->getStoreView();
|
| 67 |
-
|
| 68 |
-
$profileId = Mage::helper('marketingsoftware/api')->getProfileId(array(
|
| 69 |
-
'id' => null,
|
| 70 |
-
'storeView' => $storeview,
|
| 71 |
-
'email' => $this->_subscriptionEntity->getEmail(),
|
| 72 |
-
));
|
| 73 |
-
|
| 74 |
-
$request = Mage::helper('marketingsoftware/rest_request');
|
| 75 |
-
|
| 76 |
-
if ($profileId) {
|
| 77 |
-
$request->post('/profile/'.$profileId.'/fields/', $this->_getProfileData($storeview));
|
| 78 |
-
} else {
|
| 79 |
-
$databaseId = Mage::helper('marketingsoftware/config')->getDatabaseId();
|
| 80 |
-
|
| 81 |
-
$request->post('/database/'.$databaseId.'/profiles/', $this->_getProfileData($storeview));
|
| 82 |
-
}
|
| 83 |
-
|
| 84 |
-
return true;
|
| 85 |
-
}
|
| 86 |
-
|
| 87 |
-
/**
|
| 88 |
-
* Set REST subscription entity
|
| 89 |
-
*
|
| 90 |
-
* @param Copernica_MarketingSoftware_Model_Copernica_Entity_Subscription $subscriptionEntity
|
| 91 |
-
*/
|
| 92 |
-
public function setSubscriptionEntity(Copernica_MarketingSoftware_Model_Copernica_Entity_Quote $subscriptionEntity)
|
| 93 |
-
{
|
| 94 |
-
$this->_subscriptionEntity = $subscriptionEntity;
|
| 95 |
-
}
|
| 96 |
-
}
|
| 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 |
+
* Entity that will take care of synchronizing subscription with copernica.
|
| 29 |
+
*/
|
| 30 |
+
class Copernica_MarketingSoftware_Model_Rest_Subscription extends Copernica_MarketingSoftware_Model_Rest
|
| 31 |
+
{
|
| 32 |
+
/**
|
| 33 |
+
* Subscription entity that we will use to create proper profile inside
|
| 34 |
+
* copernica database.
|
| 35 |
+
*
|
| 36 |
+
* @var Copernica_MarketingSoftware_Model_Copernica_Entity_Subscription
|
| 37 |
+
*/
|
| 38 |
+
protected $_subscriptionEntity;
|
| 39 |
+
|
| 40 |
+
/**
|
| 41 |
+
* Get data that should be update in copernica database
|
| 42 |
+
*
|
| 43 |
+
* @param string $storeView
|
| 44 |
+
* @return array
|
| 45 |
+
*/
|
| 46 |
+
protected function _getProfileData($storeview)
|
| 47 |
+
{
|
| 48 |
+
$linkedCustomerFields = Mage::helper('marketingsoftware/config')->getLinkedCustomerFields();
|
| 49 |
+
|
| 50 |
+
return array(
|
| 51 |
+
'customer_id' => $this->_subscriptionEntity->getCustomerId(),
|
| 52 |
+
$linkedCustomerFields['email'] => $this->_subscriptionEntity->getEmail(),
|
| 53 |
+
$linkedCustomerFields['group'] => $this->_subscriptionEntity->getGroup(),
|
| 54 |
+
$linkedCustomerFields['newsletter'] => $this->_subscriptionEntity->getStatus(),
|
| 55 |
+
$linkedCustomerFields['storeView'] => $storeview
|
| 56 |
+
);
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
/**
|
| 60 |
+
* Synchronize magento subscriber with copernica profile.
|
| 61 |
+
*
|
| 62 |
+
* @return boolean
|
| 63 |
+
*/
|
| 64 |
+
public function sync()
|
| 65 |
+
{
|
| 66 |
+
$storeview = (string) $this->_subscriptionEntity->getStoreView();
|
| 67 |
+
|
| 68 |
+
$profileId = Mage::helper('marketingsoftware/api')->getProfileId(array(
|
| 69 |
+
'id' => null,
|
| 70 |
+
'storeView' => $storeview,
|
| 71 |
+
'email' => $this->_subscriptionEntity->getEmail(),
|
| 72 |
+
));
|
| 73 |
+
|
| 74 |
+
$request = Mage::helper('marketingsoftware/rest_request');
|
| 75 |
+
|
| 76 |
+
if ($profileId) {
|
| 77 |
+
$request->post('/profile/'.$profileId.'/fields/', $this->_getProfileData($storeview));
|
| 78 |
+
} else {
|
| 79 |
+
$databaseId = Mage::helper('marketingsoftware/config')->getDatabaseId();
|
| 80 |
+
|
| 81 |
+
$request->post('/database/'.$databaseId.'/profiles/', $this->_getProfileData($storeview));
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
return true;
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
/**
|
| 88 |
+
* Set REST subscription entity
|
| 89 |
+
*
|
| 90 |
+
* @param Copernica_MarketingSoftware_Model_Copernica_Entity_Subscription $subscriptionEntity
|
| 91 |
+
*/
|
| 92 |
+
public function setSubscriptionEntity(Copernica_MarketingSoftware_Model_Copernica_Entity_Quote $subscriptionEntity)
|
| 93 |
+
{
|
| 94 |
+
$this->_subscriptionEntity = $subscriptionEntity;
|
| 95 |
+
}
|
| 96 |
+
}
|
app/code/community/Copernica/MarketingSoftware/Model/Rest/Wishlist.php
CHANGED
|
@@ -1,70 +1,70 @@
|
|
| 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 |
-
* Wishlist REST entity
|
| 29 |
-
*/
|
| 30 |
-
class Copernica_MarketingSoftware_Model_Rest_Wishlist extends Copernica_MarketingSoftware_Model_Rest
|
| 31 |
-
{
|
| 32 |
-
/**
|
| 33 |
-
* Copernica entity
|
| 34 |
-
*
|
| 35 |
-
* @var Copernica_MarketingSoftware_Model_Copernica_Entity_Wishlist
|
| 36 |
-
*/
|
| 37 |
-
protected $_wishlistEntity;
|
| 38 |
-
|
| 39 |
-
/**
|
| 40 |
-
* Fetch wishlist Id
|
| 41 |
-
*
|
| 42 |
-
* @return string
|
| 43 |
-
*/
|
| 44 |
-
public function fetchId()
|
| 45 |
-
{
|
| 46 |
-
return $this->_wishlistEntity->getId();
|
| 47 |
-
}
|
| 48 |
-
|
| 49 |
-
/**
|
| 50 |
-
* Sync wishlist with customer
|
| 51 |
-
*
|
| 52 |
-
* @param Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer
|
| 53 |
-
*/
|
| 54 |
-
public function syncWithCustomer(Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer)
|
| 55 |
-
{
|
| 56 |
-
foreach ($this->_wishlistEntity->getItems() as $wishlistItemEntity) {
|
| 57 |
-
$restWishlistItem = $wishlistItemEntity->getRestWishlistItem();
|
| 58 |
-
$restWishlistItem->syncWithWishlist($customer, $this->_wishlistEntity->getId());
|
| 59 |
-
}
|
| 60 |
-
}
|
| 61 |
-
|
| 62 |
-
/**
|
| 63 |
-
* Set REST wishlist entity
|
| 64 |
-
*
|
| 65 |
-
* @param Copernica_MarketingSoftware_Model_Copernica_Entity_Wishlist $wishlistEntity
|
| 66 |
-
*/
|
| 67 |
-
public function setWishlistEntity(Copernica_MarketingSoftware_Model_Copernica_Entity_Wishlist $wishlistEntity) {
|
| 68 |
-
$this->_wishlistEntity = $wishlistEntity;
|
| 69 |
-
}
|
| 70 |
}
|
| 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 |
+
* Wishlist REST entity
|
| 29 |
+
*/
|
| 30 |
+
class Copernica_MarketingSoftware_Model_Rest_Wishlist extends Copernica_MarketingSoftware_Model_Rest
|
| 31 |
+
{
|
| 32 |
+
/**
|
| 33 |
+
* Copernica entity
|
| 34 |
+
*
|
| 35 |
+
* @var Copernica_MarketingSoftware_Model_Copernica_Entity_Wishlist
|
| 36 |
+
*/
|
| 37 |
+
protected $_wishlistEntity;
|
| 38 |
+
|
| 39 |
+
/**
|
| 40 |
+
* Fetch wishlist Id
|
| 41 |
+
*
|
| 42 |
+
* @return string
|
| 43 |
+
*/
|
| 44 |
+
public function fetchId()
|
| 45 |
+
{
|
| 46 |
+
return $this->_wishlistEntity->getId();
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
/**
|
| 50 |
+
* Sync wishlist with customer
|
| 51 |
+
*
|
| 52 |
+
* @param Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer
|
| 53 |
+
*/
|
| 54 |
+
public function syncWithCustomer(Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer)
|
| 55 |
+
{
|
| 56 |
+
foreach ($this->_wishlistEntity->getItems() as $wishlistItemEntity) {
|
| 57 |
+
$restWishlistItem = $wishlistItemEntity->getRestWishlistItem();
|
| 58 |
+
$restWishlistItem->syncWithWishlist($customer, $this->_wishlistEntity->getId());
|
| 59 |
+
}
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
/**
|
| 63 |
+
* Set REST wishlist entity
|
| 64 |
+
*
|
| 65 |
+
* @param Copernica_MarketingSoftware_Model_Copernica_Entity_Wishlist $wishlistEntity
|
| 66 |
+
*/
|
| 67 |
+
public function setWishlistEntity(Copernica_MarketingSoftware_Model_Copernica_Entity_Wishlist $wishlistEntity) {
|
| 68 |
+
$this->_wishlistEntity = $wishlistEntity;
|
| 69 |
+
}
|
| 70 |
}
|
app/code/community/Copernica/MarketingSoftware/Model/Rest/Wishlist/Item.php
CHANGED
|
@@ -1,80 +1,80 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
|
| 3 |
-
class Copernica_MarketingSoftware_Model_Rest_Wishlist_Item extends Copernica_MarketingSoftware_Model_Rest
|
| 4 |
-
{
|
| 5 |
-
/**
|
| 6 |
-
* Wishlist that will be used to send data
|
| 7 |
-
*
|
| 8 |
-
* @var Copernica_MarketingSoftware_Model_Copernica_Entity_Wishlist_Item
|
| 9 |
-
*/
|
| 10 |
-
protected $_wishlistItemEntity;
|
| 11 |
-
|
| 12 |
-
/**
|
| 13 |
-
* Sync item with wishlist
|
| 14 |
-
*
|
| 15 |
-
* @param Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer
|
| 16 |
-
* @param int $wishlistId
|
| 17 |
-
* @return boolean
|
| 18 |
-
*/
|
| 19 |
-
public function syncWithCustomer(Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer)
|
| 20 |
-
{
|
| 21 |
-
$customer->setStore($this->_wishlistItemEntity->getStoreView());
|
| 22 |
-
|
| 23 |
-
$profileId = Mage::helper('marketingsoftware/api')->getProfileId(array(
|
| 24 |
-
'id' => $customer->getCustomerId(),
|
| 25 |
-
'storeView' => (string) $customer->getStoreView(),
|
| 26 |
-
'email' => $customer->getEmail(),
|
| 27 |
-
));
|
| 28 |
-
|
| 29 |
-
if (!$profileId) {
|
| 30 |
-
$profileId = $this->_createProfile($customer);
|
| 31 |
-
|
| 32 |
-
if(!$profileId) {
|
| 33 |
-
return false;
|
| 34 |
-
}
|
| 35 |
-
}
|
| 36 |
-
|
| 37 |
-
$wishlistId = $this->_wishlistItemEntity->getWishlistId();
|
| 38 |
-
|
| 39 |
-
$wishlistItemCollectionId = Mage::helper('marketingsoftware/config')->getWishlistItemCollectionId();
|
| 40 |
-
|
| 41 |
-
if ($wishlistItemCollectionId) {
|
| 42 |
-
Mage::helper('marketingsoftware/rest_request')->put('/profile/'.$profileId.'/subprofiles/'.$wishlistItemCollectionId, $this->getWishlistSubprofileData($wishlistId), array(
|
| 43 |
-
'fields' => array(
|
| 44 |
-
'item_id=='.$this->_wishlistItemEntity->getId(),
|
| 45 |
-
'wishlist_id=='.$wishlistId
|
| 46 |
-
),
|
| 47 |
-
'create' => 'true'
|
| 48 |
-
));
|
| 49 |
-
}
|
| 50 |
-
|
| 51 |
-
return true;
|
| 52 |
-
}
|
| 53 |
-
|
| 54 |
-
/**
|
| 55 |
-
* Prepare subprofile date
|
| 56 |
-
*
|
| 57 |
-
* @param int $wishlistId
|
| 58 |
-
* @return array
|
| 59 |
-
*/
|
| 60 |
-
public function getWishlistSubprofileData($wishlistId)
|
| 61 |
-
{
|
| 62 |
-
$syncedFields = Mage::helper('marketingsoftware/config')->getLinkedWishlistItemFields();
|
| 63 |
-
|
| 64 |
-
$data = $this->_getRequestData($this->_wishlistItemEntity, $syncedFields);
|
| 65 |
-
$data['wishlist_id'] = $wishlistId;
|
| 66 |
-
$data['item_id'] = $this->_wishlistItemEntity->getId();
|
| 67 |
-
|
| 68 |
-
return $data;
|
| 69 |
-
}
|
| 70 |
-
|
| 71 |
-
/**
|
| 72 |
-
* Set REST wishlist item entity
|
| 73 |
-
*
|
| 74 |
-
* @param Copernica_MarketingSoftware_Model_Copernica_Entity_Wishlist_Item $wishlistItemEntity
|
| 75 |
-
*/
|
| 76 |
-
public function setWishlistItemEntity(Copernica_MarketingSoftware_Model_Copernica_Entity_Wishlist_Item $wishlistItemEntity)
|
| 77 |
-
{
|
| 78 |
-
$this->_wishlistItemEntity = $wishlistItemEntity;
|
| 79 |
-
}
|
| 80 |
}
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
class Copernica_MarketingSoftware_Model_Rest_Wishlist_Item extends Copernica_MarketingSoftware_Model_Rest
|
| 4 |
+
{
|
| 5 |
+
/**
|
| 6 |
+
* Wishlist that will be used to send data
|
| 7 |
+
*
|
| 8 |
+
* @var Copernica_MarketingSoftware_Model_Copernica_Entity_Wishlist_Item
|
| 9 |
+
*/
|
| 10 |
+
protected $_wishlistItemEntity;
|
| 11 |
+
|
| 12 |
+
/**
|
| 13 |
+
* Sync item with wishlist
|
| 14 |
+
*
|
| 15 |
+
* @param Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer
|
| 16 |
+
* @param int $wishlistId
|
| 17 |
+
* @return boolean
|
| 18 |
+
*/
|
| 19 |
+
public function syncWithCustomer(Copernica_MarketingSoftware_Model_Copernica_Entity_Customer $customer)
|
| 20 |
+
{
|
| 21 |
+
$customer->setStore($this->_wishlistItemEntity->getStoreView());
|
| 22 |
+
|
| 23 |
+
$profileId = Mage::helper('marketingsoftware/api')->getProfileId(array(
|
| 24 |
+
'id' => $customer->getCustomerId(),
|
| 25 |
+
'storeView' => (string) $customer->getStoreView(),
|
| 26 |
+
'email' => $customer->getEmail(),
|
| 27 |
+
));
|
| 28 |
+
|
| 29 |
+
if (!$profileId) {
|
| 30 |
+
$profileId = $this->_createProfile($customer);
|
| 31 |
+
|
| 32 |
+
if(!$profileId) {
|
| 33 |
+
return false;
|
| 34 |
+
}
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
$wishlistId = $this->_wishlistItemEntity->getWishlistId();
|
| 38 |
+
|
| 39 |
+
$wishlistItemCollectionId = Mage::helper('marketingsoftware/config')->getWishlistItemCollectionId();
|
| 40 |
+
|
| 41 |
+
if ($wishlistItemCollectionId) {
|
| 42 |
+
Mage::helper('marketingsoftware/rest_request')->put('/profile/'.$profileId.'/subprofiles/'.$wishlistItemCollectionId, $this->getWishlistSubprofileData($wishlistId), array(
|
| 43 |
+
'fields' => array(
|
| 44 |
+
'item_id=='.$this->_wishlistItemEntity->getId(),
|
| 45 |
+
'wishlist_id=='.$wishlistId
|
| 46 |
+
),
|
| 47 |
+
'create' => 'true'
|
| 48 |
+
));
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
return true;
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
/**
|
| 55 |
+
* Prepare subprofile date
|
| 56 |
+
*
|
| 57 |
+
* @param int $wishlistId
|
| 58 |
+
* @return array
|
| 59 |
+
*/
|
| 60 |
+
public function getWishlistSubprofileData($wishlistId)
|
| 61 |
+
{
|
| 62 |
+
$syncedFields = Mage::helper('marketingsoftware/config')->getLinkedWishlistItemFields();
|
| 63 |
+
|
| 64 |
+
$data = $this->_getRequestData($this->_wishlistItemEntity, $syncedFields);
|
| 65 |
+
$data['wishlist_id'] = $wishlistId;
|
| 66 |
+
$data['item_id'] = $this->_wishlistItemEntity->getId();
|
| 67 |
+
|
| 68 |
+
return $data;
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
/**
|
| 72 |
+
* Set REST wishlist item entity
|
| 73 |
+
*
|
| 74 |
+
* @param Copernica_MarketingSoftware_Model_Copernica_Entity_Wishlist_Item $wishlistItemEntity
|
| 75 |
+
*/
|
| 76 |
+
public function setWishlistItemEntity(Copernica_MarketingSoftware_Model_Copernica_Entity_Wishlist_Item $wishlistItemEntity)
|
| 77 |
+
{
|
| 78 |
+
$this->_wishlistItemEntity = $wishlistItemEntity;
|
| 79 |
+
}
|
| 80 |
}
|
app/code/community/Copernica/MarketingSoftware/Model/Sync/Profile.php
CHANGED
|
@@ -1,198 +1,198 @@
|
|
| 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 |
-
* This class will be responsible for storing and loading sync profiles.
|
| 29 |
-
*
|
| 30 |
-
* A sync profile is a combination of REST credentials that will be used as
|
| 31 |
-
* target in copernica environment.
|
| 32 |
-
*/
|
| 33 |
-
class Copernica_MarketingSoftware_Model_Sync_Profile extends Mage_Core_Model_Abstract
|
| 34 |
-
{
|
| 35 |
-
/**
|
| 36 |
-
* Construct sync profile
|
| 37 |
-
*/
|
| 38 |
-
protected function _construct()
|
| 39 |
-
{
|
| 40 |
-
$this->_init('marketingsoftware/sync_profile');
|
| 41 |
-
}
|
| 42 |
-
|
| 43 |
-
/**
|
| 44 |
-
* Get client key
|
| 45 |
-
*
|
| 46 |
-
* @return string
|
| 47 |
-
*/
|
| 48 |
-
public function getClientKey()
|
| 49 |
-
{
|
| 50 |
-
return parent::getData('client_key');
|
| 51 |
-
}
|
| 52 |
-
|
| 53 |
-
/**
|
| 54 |
-
* Set client key
|
| 55 |
-
*
|
| 56 |
-
* @param string $clientKey
|
| 57 |
-
* @return Copernica_MarketingSoftware_Model_Sync_Profile
|
| 58 |
-
*/
|
| 59 |
-
public function setClientKey($clientKey)
|
| 60 |
-
{
|
| 61 |
-
if (parent::getData('client_key') != $clientKey) {
|
| 62 |
-
parent::setData('access_token', '');
|
| 63 |
-
}
|
| 64 |
-
|
| 65 |
-
parent::setData('client_key', $clientKey);
|
| 66 |
-
|
| 67 |
-
return $this;
|
| 68 |
-
}
|
| 69 |
-
|
| 70 |
-
/**
|
| 71 |
-
* This function will return client secret
|
| 72 |
-
*
|
| 73 |
-
* @return string
|
| 74 |
-
*/
|
| 75 |
-
public function getClientSecret()
|
| 76 |
-
{
|
| 77 |
-
return parent::getData('client_secret');
|
| 78 |
-
}
|
| 79 |
-
|
| 80 |
-
/**
|
| 81 |
-
* Set client secret for this sync profile
|
| 82 |
-
*
|
| 83 |
-
* @param string $clientSecret
|
| 84 |
-
* @return Copernica_MarketingSoftware_Model_Sync_Profile
|
| 85 |
-
*/
|
| 86 |
-
public function setClientSecret($clientSecret)
|
| 87 |
-
{
|
| 88 |
-
if (parent::getData('client_secret') != $clientSecret) {
|
| 89 |
-
parent::setData('access_token', '');
|
| 90 |
-
}
|
| 91 |
-
|
| 92 |
-
parent::setData('client_secret', $clientSecret);
|
| 93 |
-
|
| 94 |
-
return $this;
|
| 95 |
-
}
|
| 96 |
-
|
| 97 |
-
/**
|
| 98 |
-
* Get access token of this sync profile
|
| 99 |
-
*
|
| 100 |
-
* @return string
|
| 101 |
-
*/
|
| 102 |
-
public function getAccessToken()
|
| 103 |
-
{
|
| 104 |
-
return parent::getData('access_token');
|
| 105 |
-
}
|
| 106 |
-
|
| 107 |
-
/**
|
| 108 |
-
* Set access token for this sync profile
|
| 109 |
-
*
|
| 110 |
-
* @param string $accessToken
|
| 111 |
-
* @return Copernica_MarketingSoftware_Model_Sync_Profile
|
| 112 |
-
*/
|
| 113 |
-
public function setAccessToken($accessToken)
|
| 114 |
-
{
|
| 115 |
-
parent::setData('access_token', $accessToken);
|
| 116 |
-
|
| 117 |
-
return $this;
|
| 118 |
-
}
|
| 119 |
-
|
| 120 |
-
/**
|
| 121 |
-
* Get name of this sync profile
|
| 122 |
-
*
|
| 123 |
-
* @return string
|
| 124 |
-
*/
|
| 125 |
-
public function getName()
|
| 126 |
-
{
|
| 127 |
-
return parent::getData('name');
|
| 128 |
-
}
|
| 129 |
-
|
| 130 |
-
/**
|
| 131 |
-
* Set name for this sync profile
|
| 132 |
-
*
|
| 133 |
-
* @param string $name
|
| 134 |
-
* @return Copernica_MarketingSoftware_Model_Sync_Profile
|
| 135 |
-
*/
|
| 136 |
-
public function setName($name)
|
| 137 |
-
{
|
| 138 |
-
parent::setData('name', $name);
|
| 139 |
-
|
| 140 |
-
return $this;
|
| 141 |
-
}
|
| 142 |
-
|
| 143 |
-
/**
|
| 144 |
-
* This function will return array of stores that this profile affect.
|
| 145 |
-
* @return array
|
| 146 |
-
*/
|
| 147 |
-
public function getStores()
|
| 148 |
-
{
|
| 149 |
-
//@todo implement
|
| 150 |
-
return array();
|
| 151 |
-
}
|
| 152 |
-
|
| 153 |
-
/**
|
| 154 |
-
* Assign store view to current sync profile
|
| 155 |
-
*
|
| 156 |
-
* @param StoreView|int $storeView
|
| 157 |
-
* @return Copernica_MarketingSoftware_Model_Sync_Profile
|
| 158 |
-
*/
|
| 159 |
-
public function assignStoreView($storeView)
|
| 160 |
-
{
|
| 161 |
-
if (is_object($storeView)) {
|
| 162 |
-
$storeView = $storeView->getId();
|
| 163 |
-
}
|
| 164 |
-
|
| 165 |
-
$bindings = Mage::helper('marketingsoftware/config')->getSyncProfilesBindings();
|
| 166 |
-
|
| 167 |
-
if ($this->getId() >= 1) {
|
| 168 |
-
$this->save();
|
| 169 |
-
}
|
| 170 |
-
|
| 171 |
-
$bindings[$store] = $this->getId();
|
| 172 |
-
|
| 173 |
-
Mage::helper('marketingsoftware/config')->setSyncProfilesBindings($bindings);
|
| 174 |
-
|
| 175 |
-
return $this;
|
| 176 |
-
}
|
| 177 |
-
|
| 178 |
-
/**
|
| 179 |
-
* Clear assigned store views
|
| 180 |
-
*
|
| 181 |
-
* @return Copernica_MarketingSoftware_Model_Sync_Profile
|
| 182 |
-
*/
|
| 183 |
-
public function clearStoreViews()
|
| 184 |
-
{
|
| 185 |
-
$bindings = Mage::helper('marketingsoftware/config')->getSyncProfilesBindings();
|
| 186 |
-
|
| 187 |
-
foreach ($bindings as $storeId => $profileId) {
|
| 188 |
-
if ($profileId == $this->getId()) {
|
| 189 |
-
$bindings[$storeId] = -1;
|
| 190 |
-
}
|
| 191 |
-
}
|
| 192 |
-
|
| 193 |
-
Mage::helper('marketingsoftware/config')->setSyncProfilesBindings($bindings);
|
| 194 |
-
|
| 195 |
-
//@todo implement
|
| 196 |
-
return $this;
|
| 197 |
-
}
|
| 198 |
}
|
| 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 |
+
* This class will be responsible for storing and loading sync profiles.
|
| 29 |
+
*
|
| 30 |
+
* A sync profile is a combination of REST credentials that will be used as
|
| 31 |
+
* target in copernica environment.
|
| 32 |
+
*/
|
| 33 |
+
class Copernica_MarketingSoftware_Model_Sync_Profile extends Mage_Core_Model_Abstract
|
| 34 |
+
{
|
| 35 |
+
/**
|
| 36 |
+
* Construct sync profile
|
| 37 |
+
*/
|
| 38 |
+
protected function _construct()
|
| 39 |
+
{
|
| 40 |
+
$this->_init('marketingsoftware/sync_profile');
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
/**
|
| 44 |
+
* Get client key
|
| 45 |
+
*
|
| 46 |
+
* @return string
|
| 47 |
+
*/
|
| 48 |
+
public function getClientKey()
|
| 49 |
+
{
|
| 50 |
+
return parent::getData('client_key');
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
/**
|
| 54 |
+
* Set client key
|
| 55 |
+
*
|
| 56 |
+
* @param string $clientKey
|
| 57 |
+
* @return Copernica_MarketingSoftware_Model_Sync_Profile
|
| 58 |
+
*/
|
| 59 |
+
public function setClientKey($clientKey)
|
| 60 |
+
{
|
| 61 |
+
if (parent::getData('client_key') != $clientKey) {
|
| 62 |
+
parent::setData('access_token', '');
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
parent::setData('client_key', $clientKey);
|
| 66 |
+
|
| 67 |
+
return $this;
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
/**
|
| 71 |
+
* This function will return client secret
|
| 72 |
+
*
|
| 73 |
+
* @return string
|
| 74 |
+
*/
|
| 75 |
+
public function getClientSecret()
|
| 76 |
+
{
|
| 77 |
+
return parent::getData('client_secret');
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
/**
|
| 81 |
+
* Set client secret for this sync profile
|
| 82 |
+
*
|
| 83 |
+
* @param string $clientSecret
|
| 84 |
+
* @return Copernica_MarketingSoftware_Model_Sync_Profile
|
| 85 |
+
*/
|
| 86 |
+
public function setClientSecret($clientSecret)
|
| 87 |
+
{
|
| 88 |
+
if (parent::getData('client_secret') != $clientSecret) {
|
| 89 |
+
parent::setData('access_token', '');
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
parent::setData('client_secret', $clientSecret);
|
| 93 |
+
|
| 94 |
+
return $this;
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
/**
|
| 98 |
+
* Get access token of this sync profile
|
| 99 |
+
*
|
| 100 |
+
* @return string
|
| 101 |
+
*/
|
| 102 |
+
public function getAccessToken()
|
| 103 |
+
{
|
| 104 |
+
return parent::getData('access_token');
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
/**
|
| 108 |
+
* Set access token for this sync profile
|
| 109 |
+
*
|
| 110 |
+
* @param string $accessToken
|
| 111 |
+
* @return Copernica_MarketingSoftware_Model_Sync_Profile
|
| 112 |
+
*/
|
| 113 |
+
public function setAccessToken($accessToken)
|
| 114 |
+
{
|
| 115 |
+
parent::setData('access_token', $accessToken);
|
| 116 |
+
|
| 117 |
+
return $this;
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
/**
|
| 121 |
+
* Get name of this sync profile
|
| 122 |
+
*
|
| 123 |
+
* @return string
|
| 124 |
+
*/
|
| 125 |
+
public function getName()
|
| 126 |
+
{
|
| 127 |
+
return parent::getData('name');
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
/**
|
| 131 |
+
* Set name for this sync profile
|
| 132 |
+
*
|
| 133 |
+
* @param string $name
|
| 134 |
+
* @return Copernica_MarketingSoftware_Model_Sync_Profile
|
| 135 |
+
*/
|
| 136 |
+
public function setName($name)
|
| 137 |
+
{
|
| 138 |
+
parent::setData('name', $name);
|
| 139 |
+
|
| 140 |
+
return $this;
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
/**
|
| 144 |
+
* This function will return array of stores that this profile affect.
|
| 145 |
+
* @return array
|
| 146 |
+
*/
|
| 147 |
+
public function getStores()
|
| 148 |
+
{
|
| 149 |
+
//@todo implement
|
| 150 |
+
return array();
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
/**
|
| 154 |
+
* Assign store view to current sync profile
|
| 155 |
+
*
|
| 156 |
+
* @param StoreView|int $storeView
|
| 157 |
+
* @return Copernica_MarketingSoftware_Model_Sync_Profile
|
| 158 |
+
*/
|
| 159 |
+
public function assignStoreView($storeView)
|
| 160 |
+
{
|
| 161 |
+
if (is_object($storeView)) {
|
| 162 |
+
$storeView = $storeView->getId();
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
$bindings = Mage::helper('marketingsoftware/config')->getSyncProfilesBindings();
|
| 166 |
+
|
| 167 |
+
if ($this->getId() >= 1) {
|
| 168 |
+
$this->save();
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
$bindings[$store] = $this->getId();
|
| 172 |
+
|
| 173 |
+
Mage::helper('marketingsoftware/config')->setSyncProfilesBindings($bindings);
|
| 174 |
+
|
| 175 |
+
return $this;
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
/**
|
| 179 |
+
* Clear assigned store views
|
| 180 |
+
*
|
| 181 |
+
* @return Copernica_MarketingSoftware_Model_Sync_Profile
|
| 182 |
+
*/
|
| 183 |
+
public function clearStoreViews()
|
| 184 |
+
{
|
| 185 |
+
$bindings = Mage::helper('marketingsoftware/config')->getSyncProfilesBindings();
|
| 186 |
+
|
| 187 |
+
foreach ($bindings as $storeId => $profileId) {
|
| 188 |
+
if ($profileId == $this->getId()) {
|
| 189 |
+
$bindings[$storeId] = -1;
|
| 190 |
+
}
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
Mage::helper('marketingsoftware/config')->setSyncProfilesBindings($bindings);
|
| 194 |
+
|
| 195 |
+
//@todo implement
|
| 196 |
+
return $this;
|
| 197 |
+
}
|
| 198 |
}
|
app/code/community/Copernica/MarketingSoftware/Model/Sync/Status.php
CHANGED
|
@@ -1,149 +1,149 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
|
| 3 |
-
/**
|
| 4 |
-
* This class will present synchronization status. As well options set with
|
| 5 |
-
* synchronization.
|
| 6 |
-
*/
|
| 7 |
-
class Copernica_MarketingSoftware_Model_Sync_Status implements Serializable
|
| 8 |
-
{
|
| 9 |
-
/**
|
| 10 |
-
* What is the last customer Id
|
| 11 |
-
*
|
| 12 |
-
* @var int
|
| 13 |
-
*/
|
| 14 |
-
protected $_lastCustomerId = 0;
|
| 15 |
-
|
| 16 |
-
/**
|
| 17 |
-
* What is the last order id
|
| 18 |
-
*
|
| 19 |
-
* @var int
|
| 20 |
-
*/
|
| 21 |
-
protected $_lastOrderId = 0;
|
| 22 |
-
|
| 23 |
-
/**
|
| 24 |
-
* What is the last subscription id
|
| 25 |
-
*
|
| 26 |
-
* @var int
|
| 27 |
-
*/
|
| 28 |
-
protected $_lastSubscriptionId = 0;
|
| 29 |
-
|
| 30 |
-
/**
|
| 31 |
-
* This array should contain all stores Ids that we want to use as a filter.
|
| 32 |
-
*
|
| 33 |
-
* @var array
|
| 34 |
-
*/
|
| 35 |
-
protected $_storesFilter = array();
|
| 36 |
-
|
| 37 |
-
/**
|
| 38 |
-
* Serialize instance
|
| 39 |
-
*
|
| 40 |
-
* @return string
|
| 41 |
-
*/
|
| 42 |
-
public function serialize()
|
| 43 |
-
{
|
| 44 |
-
return serialize(array(
|
| 45 |
-
'lastCustomer' => $this->_lastCustomerId,
|
| 46 |
-
'lastOrder' => $this->_lastOrderId,
|
| 47 |
-
'lastSub' => $this->_lastSubscriptionId,
|
| 48 |
-
'storesFilter' => $this->_storesFilter
|
| 49 |
-
));
|
| 50 |
-
}
|
| 51 |
-
|
| 52 |
-
/**
|
| 53 |
-
* Unserialize instance
|
| 54 |
-
*
|
| 55 |
-
* @param string $data
|
| 56 |
-
*/
|
| 57 |
-
public function unserialize($data)
|
| 58 |
-
{
|
| 59 |
-
$data = unserialize($data);
|
| 60 |
-
|
| 61 |
-
if(isset($data['lastCustomer'])) {
|
| 62 |
-
$this->_lastCustomerId = $data['lastCustomer'];
|
| 63 |
-
}
|
| 64 |
-
|
| 65 |
-
if(isset($data['lastOrder'])) {
|
| 66 |
-
$this->_lastOrderId = $data['lastOrder'];
|
| 67 |
-
}
|
| 68 |
-
|
| 69 |
-
if(isset($data['lastSub'])) {
|
| 70 |
-
$this->_lastSubscriptionId = $data['lastSub'];
|
| 71 |
-
}
|
| 72 |
-
|
| 73 |
-
if(isset($data['storesFilter'])) {
|
| 74 |
-
$this->_storesFilter = $data['storesFilter'];
|
| 75 |
-
}
|
| 76 |
-
}
|
| 77 |
-
|
| 78 |
-
/**
|
| 79 |
-
* Since we still support PHP 5.3 we don't have ability to use JsonSerializable
|
| 80 |
-
* interface, so we will serialize array representation of this object.
|
| 81 |
-
*
|
| 82 |
-
* @return array
|
| 83 |
-
*/
|
| 84 |
-
public function toArray()
|
| 85 |
-
{
|
| 86 |
-
return array (
|
| 87 |
-
'lastCustomer' => $this->_lastCustomerId,
|
| 88 |
-
'lastOrder' => $this->_lastOrderId,
|
| 89 |
-
'lastSub' => $this->_lastSubscriptionId,
|
| 90 |
-
'storesFilter' => $this->_storesFilter
|
| 91 |
-
);
|
| 92 |
-
}
|
| 93 |
-
|
| 94 |
-
/**
|
| 95 |
-
* Create instance of this class from stdClass
|
| 96 |
-
*
|
| 97 |
-
* @param StdClass $stdObject
|
| 98 |
-
* @return Copernica_MarketingSoftware_Model_Sync_Status
|
| 99 |
-
*/
|
| 100 |
-
static public function fromStd(StdClass $stdObject)
|
| 101 |
-
{
|
| 102 |
-
$instance = Mage::getModel('marketingsoftware/sync_status');
|
| 103 |
-
|
| 104 |
-
$trans = array(
|
| 105 |
-
'lastCustomer' => '_lastCustomerId',
|
| 106 |
-
'lastOrder' => '_lastOrderId',
|
| 107 |
-
'lastSub' => '_lastSubscriptionId',
|
| 108 |
-
'storesFilter' => '_storesFilter',
|
| 109 |
-
);
|
| 110 |
-
|
| 111 |
-
foreach ($trans as $inObject => $property) {
|
| 112 |
-
if (property_exists($stdObject, $inObject)) {
|
| 113 |
-
$instance->$property = $stdObject->$inObject;
|
| 114 |
-
}
|
| 115 |
-
}
|
| 116 |
-
|
| 117 |
-
return $instance;
|
| 118 |
-
}
|
| 119 |
-
|
| 120 |
-
/**
|
| 121 |
-
* We want to overload __call so we can define setters and getters.
|
| 122 |
-
*
|
| 123 |
-
* @param string $methodName
|
| 124 |
-
* @param array $arguments
|
| 125 |
-
* @return mixed
|
| 126 |
-
*/
|
| 127 |
-
public function __call($methodName, $arguments)
|
| 128 |
-
{
|
| 129 |
-
$action = substr($methodName, 0, 3);
|
| 130 |
-
|
| 131 |
-
$property = '_';
|
| 132 |
-
$property .= substr($methodName, 3);
|
| 133 |
-
$property{1} = strtolower($property{1});
|
| 134 |
-
|
| 135 |
-
//if(!property_exists($this, $property)) {
|
| 136 |
-
// return parent::__call($methodName, $arguments);
|
| 137 |
-
//}
|
| 138 |
-
|
| 139 |
-
switch ($action) {
|
| 140 |
-
case 'set':
|
| 141 |
-
$this->$property = $arguments[0];
|
| 142 |
-
|
| 143 |
-
return $this;
|
| 144 |
-
|
| 145 |
-
case 'get':
|
| 146 |
-
return $this->$property;
|
| 147 |
-
}
|
| 148 |
-
}
|
| 149 |
}
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* This class will present synchronization status. As well options set with
|
| 5 |
+
* synchronization.
|
| 6 |
+
*/
|
| 7 |
+
class Copernica_MarketingSoftware_Model_Sync_Status implements Serializable
|
| 8 |
+
{
|
| 9 |
+
/**
|
| 10 |
+
* What is the last customer Id
|
| 11 |
+
*
|
| 12 |
+
* @var int
|
| 13 |
+
*/
|
| 14 |
+
protected $_lastCustomerId = 0;
|
| 15 |
+
|
| 16 |
+
/**
|
| 17 |
+
* What is the last order id
|
| 18 |
+
*
|
| 19 |
+
* @var int
|
| 20 |
+
*/
|
| 21 |
+
protected $_lastOrderId = 0;
|
| 22 |
+
|
| 23 |
+
/**
|
| 24 |
+
* What is the last subscription id
|
| 25 |
+
*
|
| 26 |
+
* @var int
|
| 27 |
+
*/
|
| 28 |
+
protected $_lastSubscriptionId = 0;
|
| 29 |
+
|
| 30 |
+
/**
|
| 31 |
+
* This array should contain all stores Ids that we want to use as a filter.
|
| 32 |
+
*
|
| 33 |
+
* @var array
|
| 34 |
+
*/
|
| 35 |
+
protected $_storesFilter = array();
|
| 36 |
+
|
| 37 |
+
/**
|
| 38 |
+
* Serialize instance
|
| 39 |
+
*
|
| 40 |
+
* @return string
|
| 41 |
+
*/
|
| 42 |
+
public function serialize()
|
| 43 |
+
{
|
| 44 |
+
return serialize(array(
|
| 45 |
+
'lastCustomer' => $this->_lastCustomerId,
|
| 46 |
+
'lastOrder' => $this->_lastOrderId,
|
| 47 |
+
'lastSub' => $this->_lastSubscriptionId,
|
| 48 |
+
'storesFilter' => $this->_storesFilter
|
| 49 |
+
));
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
/**
|
| 53 |
+
* Unserialize instance
|
| 54 |
+
*
|
| 55 |
+
* @param string $data
|
| 56 |
+
*/
|
| 57 |
+
public function unserialize($data)
|
| 58 |
+
{
|
| 59 |
+
$data = unserialize($data);
|
| 60 |
+
|
| 61 |
+
if(isset($data['lastCustomer'])) {
|
| 62 |
+
$this->_lastCustomerId = $data['lastCustomer'];
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
if(isset($data['lastOrder'])) {
|
| 66 |
+
$this->_lastOrderId = $data['lastOrder'];
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
if(isset($data['lastSub'])) {
|
| 70 |
+
$this->_lastSubscriptionId = $data['lastSub'];
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
if(isset($data['storesFilter'])) {
|
| 74 |
+
$this->_storesFilter = $data['storesFilter'];
|
| 75 |
+
}
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
/**
|
| 79 |
+
* Since we still support PHP 5.3 we don't have ability to use JsonSerializable
|
| 80 |
+
* interface, so we will serialize array representation of this object.
|
| 81 |
+
*
|
| 82 |
+
* @return array
|
| 83 |
+
*/
|
| 84 |
+
public function toArray()
|
| 85 |
+
{
|
| 86 |
+
return array (
|
| 87 |
+
'lastCustomer' => $this->_lastCustomerId,
|
| 88 |
+
'lastOrder' => $this->_lastOrderId,
|
| 89 |
+
'lastSub' => $this->_lastSubscriptionId,
|
| 90 |
+
'storesFilter' => $this->_storesFilter
|
| 91 |
+
);
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
/**
|
| 95 |
+
* Create instance of this class from stdClass
|
| 96 |
+
*
|
| 97 |
+
* @param StdClass $stdObject
|
| 98 |
+
* @return Copernica_MarketingSoftware_Model_Sync_Status
|
| 99 |
+
*/
|
| 100 |
+
static public function fromStd(StdClass $stdObject)
|
| 101 |
+
{
|
| 102 |
+
$instance = Mage::getModel('marketingsoftware/sync_status');
|
| 103 |
+
|
| 104 |
+
$trans = array(
|
| 105 |
+
'lastCustomer' => '_lastCustomerId',
|
| 106 |
+
'lastOrder' => '_lastOrderId',
|
| 107 |
+
'lastSub' => '_lastSubscriptionId',
|
| 108 |
+
'storesFilter' => '_storesFilter',
|
| 109 |
+
);
|
| 110 |
+
|
| 111 |
+
foreach ($trans as $inObject => $property) {
|
| 112 |
+
if (property_exists($stdObject, $inObject)) {
|
| 113 |
+
$instance->$property = $stdObject->$inObject;
|
| 114 |
+
}
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
return $instance;
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
/**
|
| 121 |
+
* We want to overload __call so we can define setters and getters.
|
| 122 |
+
*
|
| 123 |
+
* @param string $methodName
|
| 124 |
+
* @param array $arguments
|
| 125 |
+
* @return mixed
|
| 126 |
+
*/
|
| 127 |
+
public function __call($methodName, $arguments)
|
| 128 |
+
{
|
| 129 |
+
$action = substr($methodName, 0, 3);
|
| 130 |
+
|
| 131 |
+
$property = '_';
|
| 132 |
+
$property .= substr($methodName, 3);
|
| 133 |
+
$property{1} = strtolower($property{1});
|
| 134 |
+
|
| 135 |
+
//if(!property_exists($this, $property)) {
|
| 136 |
+
// return parent::__call($methodName, $arguments);
|
| 137 |
+
//}
|
| 138 |
+
|
| 139 |
+
switch ($action) {
|
| 140 |
+
case 'set':
|
| 141 |
+
$this->$property = $arguments[0];
|
| 142 |
+
|
| 143 |
+
return $this;
|
| 144 |
+
|
| 145 |
+
case 'get':
|
| 146 |
+
return $this->$property;
|
| 147 |
+
}
|
| 148 |
+
}
|
| 149 |
}
|
app/code/community/Copernica/MarketingSoftware/controllers/Adminhtml/Marketingsoftware/AccessTokenController.php
CHANGED
|
@@ -1,68 +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 |
-
class Copernica_MarketingSoftware_AdminHtml_MarketingSoftware_AccesstokenController extends Copernica_MarketingSoftware_Controller_Action
|
| 28 |
-
{
|
| 29 |
-
/**
|
| 30 |
-
* Handler most basic index action
|
| 31 |
-
*/
|
| 32 |
-
public function indexAction()
|
| 33 |
-
{
|
| 34 |
-
$this->loadLayout();
|
| 35 |
-
|
| 36 |
-
$this->_setActiveMenu('copernica');
|
| 37 |
-
|
| 38 |
-
$layout = $this->getLayout();
|
| 39 |
-
|
| 40 |
-
$page = $layout->createBlock('marketingsoftware/adminhtml_marketingsoftware_accesstoken');
|
| 41 |
-
|
| 42 |
-
$layout->getBlock('content')->append($page);
|
| 43 |
-
|
| 44 |
-
$layout->getBlock('head')->setTitle($this->__('Access Token / Copernica Marketing Software / Magento Admin'));
|
| 45 |
-
|
| 46 |
-
$session = Mage::getSingleton('adminhtml/session');
|
| 47 |
-
|
| 48 |
-
if (!$session->getState()) {
|
| 49 |
-
$session->setState($this->generateState());
|
| 50 |
-
}
|
| 51 |
-
|
| 52 |
-
$this->renderLayout();
|
| 53 |
-
}
|
| 54 |
-
|
| 55 |
-
/**
|
| 56 |
-
* Handle form action
|
| 57 |
-
*
|
| 58 |
-
* @return string
|
| 59 |
-
*/
|
| 60 |
-
public function sendAction()
|
| 61 |
-
{
|
| 62 |
-
$data = $this->getRequest()->getPost();
|
| 63 |
-
|
| 64 |
-
Mage::helper('marketingsoftware/config')->setAccessToken($data['access_token']);
|
| 65 |
-
|
| 66 |
-
return $this->_redirect('*/marketingsoftware_settings/index');
|
| 67 |
-
}
|
| 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 |
+
class Copernica_MarketingSoftware_AdminHtml_MarketingSoftware_AccesstokenController extends Copernica_MarketingSoftware_Controller_Action
|
| 28 |
+
{
|
| 29 |
+
/**
|
| 30 |
+
* Handler most basic index action
|
| 31 |
+
*/
|
| 32 |
+
public function indexAction()
|
| 33 |
+
{
|
| 34 |
+
$this->loadLayout();
|
| 35 |
+
|
| 36 |
+
$this->_setActiveMenu('copernica');
|
| 37 |
+
|
| 38 |
+
$layout = $this->getLayout();
|
| 39 |
+
|
| 40 |
+
$page = $layout->createBlock('marketingsoftware/adminhtml_marketingsoftware_accesstoken');
|
| 41 |
+
|
| 42 |
+
$layout->getBlock('content')->append($page);
|
| 43 |
+
|
| 44 |
+
$layout->getBlock('head')->setTitle($this->__('Access Token / Copernica Marketing Software / Magento Admin'));
|
| 45 |
+
|
| 46 |
+
$session = Mage::getSingleton('adminhtml/session');
|
| 47 |
+
|
| 48 |
+
if (!$session->getState()) {
|
| 49 |
+
$session->setState($this->generateState());
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
$this->renderLayout();
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
/**
|
| 56 |
+
* Handle form action
|
| 57 |
+
*
|
| 58 |
+
* @return string
|
| 59 |
+
*/
|
| 60 |
+
public function sendAction()
|
| 61 |
+
{
|
| 62 |
+
$data = $this->getRequest()->getPost();
|
| 63 |
+
|
| 64 |
+
Mage::helper('marketingsoftware/config')->setAccessToken($data['access_token']);
|
| 65 |
+
|
| 66 |
+
return $this->_redirect('*/marketingsoftware_settings/index');
|
| 67 |
+
}
|
| 68 |
}
|
app/code/community/Copernica/MarketingSoftware/controllers/Adminhtml/Marketingsoftware/AjaxcollectionController.php
CHANGED
|
@@ -1,454 +1,456 @@
|
|
| 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 |
-
* This class will answer any Ajax call that is asking info about Copernica
|
| 29 |
-
* collection.
|
| 30 |
-
*/
|
| 31 |
-
class Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_AjaxcollectionController extends Mage_Adminhtml_Controller_Action
|
| 32 |
-
{
|
| 33 |
-
/**
|
| 34 |
-
* Valdiate collection
|
| 35 |
-
*/
|
| 36 |
-
public function validateAction()
|
| 37 |
-
{
|
| 38 |
-
$post = $this->getRequest()->getPost();
|
| 39 |
-
|
| 40 |
-
$config = Mage::helper('marketingsoftware/config');
|
| 41 |
-
$validator = Mage::helper('marketingsoftware/api_validator');
|
| 42 |
-
|
| 43 |
-
$problems = array();
|
| 44 |
-
|
| 45 |
-
try {
|
| 46 |
-
if ($post['type'] == 'main') {
|
| 47 |
-
try {
|
| 48 |
-
$validator->validateDatabase($post['name']);
|
| 49 |
-
} catch (Copernica_MarketingSoftware_Exception $exception) {
|
| 50 |
-
array_push($problems, $exception->getMessage());
|
| 51 |
-
}
|
| 52 |
-
|
| 53 |
-
foreach ($post['fields'] as $field) {
|
| 54 |
-
list($magento, $copernica) = explode(',', $field);
|
| 55 |
-
|
| 56 |
-
try {
|
| 57 |
-
$validator->validateDatabaseField($post['name'], $copernica, $magento);
|
| 58 |
-
} catch (Copernica_MarketingSoftware_Exception $exception) {
|
| 59 |
-
array_push($problems,
|
| 60 |
-
}
|
| 61 |
-
}
|
| 62 |
-
} else {
|
| 63 |
-
$databaseName = $config->getDatabaseName();
|
| 64 |
-
|
| 65 |
-
try {
|
| 66 |
-
$validator->validateCollection($databaseName, $post['name'], $post['type']);
|
| 67 |
-
} catch (Copernica_MarketingSoftware_Exception $exception) {
|
| 68 |
-
array_push($problems, $exception->getMessage());
|
| 69 |
-
}
|
| 70 |
-
|
| 71 |
-
foreach ($post['fields'] as $field) {
|
| 72 |
-
list($magento, $copernica) = explode(',', $field);
|
| 73 |
-
|
| 74 |
-
try {
|
| 75 |
-
$validator->validateCollectionField($databaseName, $post['name'], $post['type'], $
|
| 76 |
-
} catch (Copernica_MarketingSoftware_Exception $exception) {
|
| 77 |
-
array_push($problems,
|
| 78 |
-
}
|
| 79 |
-
}
|
| 80 |
-
}
|
| 81 |
-
}
|
| 82 |
-
/**
|
| 83 |
-
* General exceptions should not happen but, just in case we want to
|
| 84 |
-
* handle them here.
|
| 85 |
-
*/
|
| 86 |
-
catch (Exception $exception) {
|
| 87 |
-
Mage::logException($exception);
|
| 88 |
-
|
| 89 |
-
$this->getResponse()->setBody('Critical error. Check error logs form more info.');
|
| 90 |
-
}
|
| 91 |
-
|
| 92 |
-
$this->getResponse()->setBody(json_encode($problems));
|
| 93 |
-
}
|
| 94 |
-
|
| 95 |
-
/**
|
| 96 |
-
* This ajax call can be used to fetch information about certain field in collection
|
| 97 |
-
*/
|
| 98 |
-
public function fetchAction()
|
| 99 |
-
{
|
| 100 |
-
$post = $this->getRequest()->getPost();
|
| 101 |
-
|
| 102 |
-
$response = $this->getResponse();
|
| 103 |
-
|
| 104 |
-
if (!isset($post['name'])) {
|
| 105 |
-
return $response->setBody(json_encode(array(
|
| 106 |
-
'message' => 'Invalid input'
|
| 107 |
-
)));
|
| 108 |
-
}
|
| 109 |
-
|
| 110 |
-
$config = Mage::helper('marketingsoftware/config');
|
| 111 |
-
$data = Mage::helper('marketingsoftware/data');
|
| 112 |
-
|
| 113 |
-
$database = $config->getDatabaseName();
|
| 114 |
-
|
| 115 |
-
$db_not_needed = false;
|
| 116 |
-
|
| 117 |
-
if($post['name'] == 'main') {
|
| 118 |
-
$db_not_needed = true;
|
| 119 |
-
}
|
| 120 |
-
|
| 121 |
-
if (empty($database) && !$db_not_needed) {
|
| 122 |
-
return $response->setBody(json_encode(array(
|
| 123 |
-
'error' => 'no database'
|
| 124 |
-
)));
|
| 125 |
-
}
|
| 126 |
-
|
| 127 |
-
$linkedName = '';
|
| 128 |
-
|
| 129 |
-
$linkedFields = array();
|
| 130 |
-
$supportedFields = array();
|
| 131 |
-
$linkedFields = array();
|
| 132 |
-
|
| 133 |
-
switch ($post['name']) {
|
| 134 |
-
case 'main':
|
| 135 |
-
$linkedName = $config->getDatabaseName();
|
| 136 |
-
$supportedFields = $data->supportedCustomerFields();
|
| 137 |
-
$linkedFields = $config->getLinkedCustomerFields();
|
| 138 |
-
$label = 'Database';
|
| 139 |
-
break;
|
| 140 |
-
|
| 141 |
-
case 'orders':
|
| 142 |
-
$linkedName = $config->getOrdersCollectionName();
|
| 143 |
-
$supportedFields = $data->supportedOrderFields();
|
| 144 |
-
$linkedFields = $config->getLinkedOrderFields();
|
| 145 |
-
$label = 'Orders collection';
|
| 146 |
-
break;
|
| 147 |
-
|
| 148 |
-
case 'orderproducts':
|
| 149 |
-
$linkedName = $config->getOrderItemCollectionName();
|
| 150 |
-
$supportedFields = $data->supportedOrderItemFields();
|
| 151 |
-
$linkedFields = $config->getLinkedOrderItemFields();
|
| 152 |
-
$label = 'Orders items collection';
|
| 153 |
-
break;
|
| 154 |
-
|
| 155 |
-
case 'addresses':
|
| 156 |
-
$linkedName = $config->getAddressesCollectionName();
|
| 157 |
-
$supportedFields = $data->supportedAddressFields();
|
| 158 |
-
$linkedFields = $config->getLinkedAddressFields();
|
| 159 |
-
$label = 'Addresses collection';
|
| 160 |
-
break;
|
| 161 |
-
|
| 162 |
-
case 'viewedproducts':
|
| 163 |
-
$linkedName = $config->
|
| 164 |
-
$supportedFields = $data->supportedViewedProductFields();
|
| 165 |
-
$linkedFields = $config->
|
| 166 |
-
$label = 'Viewed products collection';
|
| 167 |
-
break;
|
| 168 |
-
|
| 169 |
-
case 'cartproducts':
|
| 170 |
-
$linkedName = $config->getQuoteItemCollectionName();
|
| 171 |
-
$supportedFields = $data->supportedQuoteItemFields();
|
| 172 |
-
$linkedFields = $config->getLinkedQuoteItemFields();
|
| 173 |
-
$label = 'Cart items collection';
|
| 174 |
-
break;
|
| 175 |
-
|
| 176 |
-
case 'wishlistproducts':
|
| 177 |
-
$linkedName = $config->getWishlistItemCollectionName();
|
| 178 |
-
$supportedFields = $data->supportedWishlistItemFields();
|
| 179 |
-
$linkedFields = $config->getLinkedWishlistItemFields();
|
| 180 |
-
$label = 'Wishlist items collection';
|
| 181 |
-
break;
|
| 182 |
-
}
|
| 183 |
-
|
| 184 |
-
$fields = array();
|
| 185 |
-
|
| 186 |
-
foreach ($supportedFields as $fieldName => $fieldLabel) {
|
| 187 |
-
$fields[] = array (
|
| 188 |
-
'magento' => $fieldName,
|
| 189 |
-
'label' => $fieldLabel,
|
| 190 |
-
'copernica' => array_key_exists($fieldName, $linkedFields) ? $linkedFields[$fieldName] : ''
|
| 191 |
-
);
|
| 192 |
-
}
|
| 193 |
-
|
| 194 |
-
$response->setBody(json_encode(array(
|
| 195 |
-
'name' => $post['name'],
|
| 196 |
-
'linkedName' => $linkedName,
|
| 197 |
-
'label' => $label,
|
| 198 |
-
'fields' => $fields,
|
| 199 |
-
)));
|
| 200 |
-
}
|
| 201 |
-
|
| 202 |
-
/**
|
| 203 |
-
* Create field inside given database.
|
| 204 |
-
*
|
| 205 |
-
* @param string $databaseName
|
| 206 |
-
* @param string $fieldName
|
| 207 |
-
* @param string $magentoField
|
| 208 |
-
*/
|
| 209 |
-
protected function _createDatabaseField($databaseName, $fieldName, $magentoField)
|
| 210 |
-
{
|
| 211 |
-
$builder = Mage::helper('marketingsoftware/api_builder');
|
| 212 |
-
|
| 213 |
-
switch ($magentoField) {
|
| 214 |
-
case 'email':
|
| 215 |
-
$builder->createDatabaseEmailField($databaseName, $fieldName);
|
| 216 |
-
break;
|
| 217 |
-
|
| 218 |
-
case 'newsletter' :
|
| 219 |
-
$builder->createDatabaseNewsletterField($databaseName, $fieldName);
|
| 220 |
-
break;
|
| 221 |
-
|
| 222 |
-
case 'birthdate' :
|
| 223 |
-
$builder->createDatabaseDateField($databaseName, $fieldName);
|
| 224 |
-
break;
|
| 225 |
-
|
| 226 |
-
case 'storeView':
|
| 227 |
-
$builder->createDatabaseField($databaseName, $fieldName, array( 'length' => 250 ));
|
| 228 |
-
break;
|
| 229 |
-
|
| 230 |
-
case 'registrationDate' :
|
| 231 |
-
$builder->createDatabaseDatetimeField($databaseName, $fieldName);
|
| 232 |
-
break;
|
| 233 |
-
|
| 234 |
-
default:
|
| 235 |
-
$builder->createDatabaseField($databaseName, $fieldName);
|
| 236 |
-
break;
|
| 237 |
-
}
|
| 238 |
-
}
|
| 239 |
-
|
| 240 |
-
/**
|
| 241 |
-
* This ajax call can be used to store information about certain collection
|
| 242 |
-
*/
|
| 243 |
-
public function storeAction()
|
| 244 |
-
{
|
| 245 |
-
$post = $this->getRequest()->getPost();
|
| 246 |
-
|
| 247 |
-
$builder = Mage::helper('marketingsoftware/api_builder');
|
| 248 |
-
$config = Mage::helper('marketingsoftware/config');
|
| 249 |
-
|
| 250 |
-
switch ($post['type']) {
|
| 251 |
-
case 'main':
|
| 252 |
-
$builder->createDatabase($post['name']);
|
| 253 |
-
|
| 254 |
-
$profileCacheCollection = Mage::getModel('marketingsoftware/profile_cache')->getCollection();
|
| 255 |
-
|
| 256 |
-
foreach($profileCacheCollection as $profileCache) {
|
| 257 |
-
$profileCache->delete();
|
| 258 |
-
}
|
| 259 |
-
|
| 260 |
-
$config->unsDatabaseId();
|
| 261 |
-
$config->setDatabaseName($post['name']);
|
| 262 |
-
|
| 263 |
-
$fields = array();
|
| 264 |
-
|
| 265 |
-
foreach ($post['fields'] as $field) {
|
| 266 |
-
list($magento, $copernica) = explode(',', $field);
|
| 267 |
-
|
| 268 |
-
$fields[$magento] = $copernica;
|
| 269 |
-
|
| 270 |
-
$this->_createDatabaseField($post['name'], $copernica, $magento);
|
| 271 |
-
}
|
| 272 |
-
|
| 273 |
-
$config->setLinkedCustomerFields($fields);
|
| 274 |
-
break;
|
| 275 |
-
|
| 276 |
-
default:
|
| 277 |
-
$databaseName = Mage::helper('marketingsoftware/config')->getDatabaseName();
|
| 278 |
-
|
| 279 |
-
$builder->createCollection($databaseName, $post['name'], $post['type']);
|
| 280 |
-
|
| 281 |
-
$fields = array();
|
| 282 |
-
|
| 283 |
-
foreach ($post['fields'] as $field) {
|
| 284 |
-
list($magento, $copernica) = explode(',', $field);
|
| 285 |
-
|
| 286 |
-
$fields[$magento] = $copernica;
|
| 287 |
-
|
| 288 |
-
$builder->createCollectionField($databaseName, $post['name'], $post['type'], $copernica, $magento);
|
| 289 |
-
}
|
| 290 |
-
|
| 291 |
-
switch ($post['type']) {
|
| 292 |
-
case 'orders':
|
| 293 |
-
$config->unsOrdersCollectionId();
|
| 294 |
-
$config->setOrdersCollectionName($post['name']);
|
| 295 |
-
$config->setLinkedOrderFields($fields);
|
| 296 |
-
break;
|
| 297 |
-
|
| 298 |
-
case 'orderproducts':
|
| 299 |
-
$config->unsOrderItemCollectionId();
|
| 300 |
-
$config->setOrderItemCollectionName($post['name']);
|
| 301 |
-
$config->setLinkedOrderItemFields($fields);
|
| 302 |
-
break;
|
| 303 |
-
|
| 304 |
-
case 'addresses':
|
| 305 |
-
$config->unsAddressCollectionId();
|
| 306 |
-
$config->setAddressCollectionName($post['name']);
|
| 307 |
-
$config->setLinkedAddressFields($fields);
|
| 308 |
-
break;
|
| 309 |
-
|
| 310 |
-
case 'viewedproducts':
|
| 311 |
-
$config->unsViewedProductCollectionId();
|
| 312 |
-
$config->setViewedProductCollectionName($post['name']);
|
| 313 |
-
$config->setLinkedViewedProductFields($fields);
|
| 314 |
-
break;
|
| 315 |
-
|
| 316 |
-
case 'cartproducts':
|
| 317 |
-
$config->unsQuoteItemCollectionId();
|
| 318 |
-
$config->setQuoteItemCollectionName($post['name']);
|
| 319 |
-
$config->setLinkedQuoteItemFields($fields);
|
| 320 |
-
break;
|
| 321 |
-
|
| 322 |
-
case 'wishlistproducts':
|
| 323 |
-
$config->unsWishlistItemCollectionId();
|
| 324 |
-
$config->setWishlistItemCollectionName($post['name']);
|
| 325 |
-
$config->setLinkedWishlistItemFields($fields);
|
| 326 |
-
break;
|
| 327 |
-
}
|
| 328 |
-
break;
|
| 329 |
-
}
|
| 330 |
-
}
|
| 331 |
-
|
| 332 |
-
/**
|
| 333 |
-
* Make default structure.
|
| 334 |
-
*/
|
| 335 |
-
public function defaultAction()
|
| 336 |
-
{
|
| 337 |
-
$databaseName = 'Magento';
|
| 338 |
-
|
| 339 |
-
$builder = Mage::helper('marketingsoftware/api_builder');
|
| 340 |
-
$config = Mage::helper('marketingsoftware/config');
|
| 341 |
-
$data = Mage::helper('marketingsoftware/data');
|
| 342 |
-
|
| 343 |
-
$builder->createDatabase($databaseName);
|
| 344 |
-
|
| 345 |
-
$config->unsDatabaseId();
|
| 346 |
-
$config->setDatabaseName($databaseName);
|
| 347 |
-
|
| 348 |
-
$config->clearLinkedCollections();
|
| 349 |
-
|
| 350 |
-
$profileCacheCollection = Mage::getModel('marketingsoftware/profile_cache')->getCollection();
|
| 351 |
-
|
| 352 |
-
foreach($profileCacheCollection as $profileCache) {
|
| 353 |
-
$profileCache->delete();
|
| 354 |
-
}
|
| 355 |
-
|
| 356 |
-
$supportedFields = $data->supportedCustomerFields();
|
| 357 |
-
$linkedFields = array();
|
| 358 |
-
|
| 359 |
-
foreach ($supportedFields as $name => $label) {
|
| 360 |
-
$this->_createDatabaseField($databaseName, $name, $name);
|
| 361 |
-
$linkedFields[$name] = $name;
|
| 362 |
-
}
|
| 363 |
-
|
| 364 |
-
$config->setLinkedCustomerFields($linkedFields);
|
| 365 |
-
|
| 366 |
-
/*
|
| 367 |
-
* Quote items collection
|
| 368 |
-
*/
|
| 369 |
-
$builder->createCollection($databaseName, 'Cart_Items' ,'cartproducts');
|
| 370 |
-
$config->setQuoteItemCollectionName('Cart_Items');
|
| 371 |
-
$supportedFields = $data->supportedQuoteItemFields();
|
| 372 |
-
$linkedFields = array();
|
| 373 |
-
|
| 374 |
-
foreach ($supportedFields as $name => $label) {
|
| 375 |
-
$builder->createCollectionField($databaseName, 'Cart_Items', 'cartproducts', $name, $name);
|
| 376 |
-
$linkedFields[$name] = $name;
|
| 377 |
-
}
|
| 378 |
-
|
| 379 |
-
$config->setLinkedQuoteItemFields($linkedFields);
|
| 380 |
-
|
| 381 |
-
/*
|
| 382 |
-
* Orders collection
|
| 383 |
-
*/
|
| 384 |
-
$builder->createCollection($databaseName, 'Orders' ,'orders');
|
| 385 |
-
$config->setOrdersCollectionName('Orders');
|
| 386 |
-
$supportedFields = $data->supportedOrderFields();
|
| 387 |
-
$linkedFields = array();
|
| 388 |
-
|
| 389 |
-
foreach ($supportedFields as $name => $label) {
|
| 390 |
-
$builder->createCollectionField($databaseName, 'Orders', 'orders', $name, $name);
|
| 391 |
-
$linkedFields[$name] = $name;
|
| 392 |
-
}
|
| 393 |
-
|
| 394 |
-
$config->setLinkedOrderFields($linkedFields);
|
| 395 |
-
|
| 396 |
-
/*
|
| 397 |
-
* Orders items collection
|
| 398 |
-
*/
|
| 399 |
-
$builder->createCollection($databaseName, 'Orders_Items' ,'orderproducts');
|
| 400 |
-
$config->setOrderItemCollectionName('Orders_Items');
|
| 401 |
-
$supportedFields = $data->supportedOrderItemFields();
|
| 402 |
-
$linkedFields = array();
|
| 403 |
-
|
| 404 |
-
foreach ($supportedFields as $name => $label) {
|
| 405 |
-
$builder->createCollectionField($databaseName, 'Orders_Items', 'orderproducts', $name, $name);
|
| 406 |
-
$linkedFields[$name] = $name;
|
| 407 |
-
}
|
| 408 |
-
|
| 409 |
-
$config->setLinkedOrderItemFields($linkedFields);
|
| 410 |
-
|
| 411 |
-
/*
|
| 412 |
-
* Addresses collection
|
| 413 |
-
*/
|
| 414 |
-
$builder->createCollection($databaseName, 'Addresses' ,'addresses');
|
| 415 |
-
$config->setAddressCollectionName('Addresses');
|
| 416 |
-
$supportedFields = $data->supportedAddressFields();
|
| 417 |
-
$linkedFields = array();
|
| 418 |
-
|
| 419 |
-
foreach ($supportedFields as $name => $label) {
|
| 420 |
-
$builder->createCollectionField($databaseName, 'Addresses', 'addresses', $name, $name);
|
| 421 |
-
$linkedFields[$name] = $name;
|
| 422 |
-
}
|
| 423 |
-
|
| 424 |
-
$config->setLinkedAddressFields($linkedFields);
|
| 425 |
-
|
| 426 |
-
/*
|
| 427 |
-
* Viewed products collection
|
| 428 |
-
*/
|
| 429 |
-
$builder->createCollection($databaseName, 'Viewed_Products' ,'viewedproducts');
|
| 430 |
-
$config->setViewedProductCollectionName('Viewed_Products');
|
| 431 |
-
$supportedFields = $data->supportedViewedProductFields();
|
| 432 |
-
$linkedFields = array();
|
| 433 |
-
|
| 434 |
-
foreach ($supportedFields as $name => $label) {
|
| 435 |
-
$builder->createCollectionField($databaseName, 'Viewed_Products', 'viewedproducts', $name, $name);
|
| 436 |
-
$linkedFields[$name] = $name;
|
| 437 |
-
}
|
| 438 |
-
|
| 439 |
-
|
| 440 |
-
|
| 441 |
-
|
| 442 |
-
|
| 443 |
-
|
| 444 |
-
$
|
| 445 |
-
$
|
| 446 |
-
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
|
| 450 |
-
|
| 451 |
-
|
| 452 |
-
|
| 453 |
-
|
|
|
|
|
|
|
| 454 |
}
|
| 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 |
+
* This class will answer any Ajax call that is asking info about Copernica
|
| 29 |
+
* collection.
|
| 30 |
+
*/
|
| 31 |
+
class Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_AjaxcollectionController extends Mage_Adminhtml_Controller_Action
|
| 32 |
+
{
|
| 33 |
+
/**
|
| 34 |
+
* Valdiate collection
|
| 35 |
+
*/
|
| 36 |
+
public function validateAction()
|
| 37 |
+
{
|
| 38 |
+
$post = $this->getRequest()->getPost();
|
| 39 |
+
|
| 40 |
+
$config = Mage::helper('marketingsoftware/config');
|
| 41 |
+
$validator = Mage::helper('marketingsoftware/api_validator');
|
| 42 |
+
|
| 43 |
+
$problems = array();
|
| 44 |
+
|
| 45 |
+
try {
|
| 46 |
+
if ($post['type'] == 'main') {
|
| 47 |
+
try {
|
| 48 |
+
$validator->validateDatabase($post['name']);
|
| 49 |
+
} catch (Copernica_MarketingSoftware_Exception $exception) {
|
| 50 |
+
array_push($problems, $exception->getMessage());
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
foreach ($post['fields'] as $field) {
|
| 54 |
+
list($magento, $copernica) = explode(',', $field);
|
| 55 |
+
|
| 56 |
+
try {
|
| 57 |
+
$validator->validateDatabaseField($post['name'], $copernica, $magento);
|
| 58 |
+
} catch (Copernica_MarketingSoftware_Exception $exception) {
|
| 59 |
+
array_push($problems, '"'.$copernica.'"'.','.$exception->getMessage());
|
| 60 |
+
}
|
| 61 |
+
}
|
| 62 |
+
} else {
|
| 63 |
+
$databaseName = $config->getDatabaseName();
|
| 64 |
+
|
| 65 |
+
try {
|
| 66 |
+
$validator->validateCollection($databaseName, $post['name'], $post['type']);
|
| 67 |
+
} catch (Copernica_MarketingSoftware_Exception $exception) {
|
| 68 |
+
array_push($problems, $exception->getMessage());
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
foreach ($post['fields'] as $field) {
|
| 72 |
+
list($magento, $copernica) = explode(',', $field);
|
| 73 |
+
|
| 74 |
+
try {
|
| 75 |
+
$validator->validateCollectionField($databaseName, $post['name'], $post['type'], $magento, $copernica);
|
| 76 |
+
} catch (Copernica_MarketingSoftware_Exception $exception) {
|
| 77 |
+
array_push($problems, '"'.$copernica.'"'.','.$exception->getMessage());
|
| 78 |
+
}
|
| 79 |
+
}
|
| 80 |
+
}
|
| 81 |
+
}
|
| 82 |
+
/**
|
| 83 |
+
* General exceptions should not happen but, just in case we want to
|
| 84 |
+
* handle them here.
|
| 85 |
+
*/
|
| 86 |
+
catch (Exception $exception) {
|
| 87 |
+
Mage::logException($exception);
|
| 88 |
+
|
| 89 |
+
$this->getResponse()->setBody('Critical error. Check error logs form more info.');
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
$this->getResponse()->setBody(json_encode($problems));
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
/**
|
| 96 |
+
* This ajax call can be used to fetch information about certain field in collection
|
| 97 |
+
*/
|
| 98 |
+
public function fetchAction()
|
| 99 |
+
{
|
| 100 |
+
$post = $this->getRequest()->getPost();
|
| 101 |
+
|
| 102 |
+
$response = $this->getResponse();
|
| 103 |
+
|
| 104 |
+
if (!isset($post['name'])) {
|
| 105 |
+
return $response->setBody(json_encode(array(
|
| 106 |
+
'message' => 'Invalid input'
|
| 107 |
+
)));
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
$config = Mage::helper('marketingsoftware/config');
|
| 111 |
+
$data = Mage::helper('marketingsoftware/data');
|
| 112 |
+
|
| 113 |
+
$database = $config->getDatabaseName();
|
| 114 |
+
|
| 115 |
+
$db_not_needed = false;
|
| 116 |
+
|
| 117 |
+
if($post['name'] == 'main') {
|
| 118 |
+
$db_not_needed = true;
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
if (empty($database) && !$db_not_needed) {
|
| 122 |
+
return $response->setBody(json_encode(array(
|
| 123 |
+
'error' => 'no database'
|
| 124 |
+
)));
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
$linkedName = '';
|
| 128 |
+
|
| 129 |
+
$linkedFields = array();
|
| 130 |
+
$supportedFields = array();
|
| 131 |
+
$linkedFields = array();
|
| 132 |
+
|
| 133 |
+
switch ($post['name']) {
|
| 134 |
+
case 'main':
|
| 135 |
+
$linkedName = $config->getDatabaseName();
|
| 136 |
+
$supportedFields = $data->supportedCustomerFields();
|
| 137 |
+
$linkedFields = $config->getLinkedCustomerFields();
|
| 138 |
+
$label = 'Database';
|
| 139 |
+
break;
|
| 140 |
+
|
| 141 |
+
case 'orders':
|
| 142 |
+
$linkedName = $config->getOrdersCollectionName();
|
| 143 |
+
$supportedFields = $data->supportedOrderFields();
|
| 144 |
+
$linkedFields = $config->getLinkedOrderFields();
|
| 145 |
+
$label = 'Orders collection';
|
| 146 |
+
break;
|
| 147 |
+
|
| 148 |
+
case 'orderproducts':
|
| 149 |
+
$linkedName = $config->getOrderItemCollectionName();
|
| 150 |
+
$supportedFields = $data->supportedOrderItemFields();
|
| 151 |
+
$linkedFields = $config->getLinkedOrderItemFields();
|
| 152 |
+
$label = 'Orders items collection';
|
| 153 |
+
break;
|
| 154 |
+
|
| 155 |
+
case 'addresses':
|
| 156 |
+
$linkedName = $config->getAddressesCollectionName();
|
| 157 |
+
$supportedFields = $data->supportedAddressFields();
|
| 158 |
+
$linkedFields = $config->getLinkedAddressFields();
|
| 159 |
+
$label = 'Addresses collection';
|
| 160 |
+
break;
|
| 161 |
+
|
| 162 |
+
case 'viewedproducts':
|
| 163 |
+
$linkedName = $config->getViewedProductCollectionName();
|
| 164 |
+
$supportedFields = $data->supportedViewedProductFields();
|
| 165 |
+
$linkedFields = $config->getLinkedViewedProductFields();
|
| 166 |
+
$label = 'Viewed products collection';
|
| 167 |
+
break;
|
| 168 |
+
|
| 169 |
+
case 'cartproducts':
|
| 170 |
+
$linkedName = $config->getQuoteItemCollectionName();
|
| 171 |
+
$supportedFields = $data->supportedQuoteItemFields();
|
| 172 |
+
$linkedFields = $config->getLinkedQuoteItemFields();
|
| 173 |
+
$label = 'Cart items collection';
|
| 174 |
+
break;
|
| 175 |
+
|
| 176 |
+
case 'wishlistproducts':
|
| 177 |
+
$linkedName = $config->getWishlistItemCollectionName();
|
| 178 |
+
$supportedFields = $data->supportedWishlistItemFields();
|
| 179 |
+
$linkedFields = $config->getLinkedWishlistItemFields();
|
| 180 |
+
$label = 'Wishlist items collection';
|
| 181 |
+
break;
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
$fields = array();
|
| 185 |
+
|
| 186 |
+
foreach ($supportedFields as $fieldName => $fieldLabel) {
|
| 187 |
+
$fields[] = array (
|
| 188 |
+
'magento' => $fieldName,
|
| 189 |
+
'label' => $fieldLabel,
|
| 190 |
+
'copernica' => array_key_exists($fieldName, $linkedFields) ? $linkedFields[$fieldName] : ''
|
| 191 |
+
);
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
$response->setBody(json_encode(array(
|
| 195 |
+
'name' => $post['name'],
|
| 196 |
+
'linkedName' => $linkedName,
|
| 197 |
+
'label' => $label,
|
| 198 |
+
'fields' => $fields,
|
| 199 |
+
)));
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
/**
|
| 203 |
+
* Create field inside given database.
|
| 204 |
+
*
|
| 205 |
+
* @param string $databaseName
|
| 206 |
+
* @param string $fieldName
|
| 207 |
+
* @param string $magentoField
|
| 208 |
+
*/
|
| 209 |
+
protected function _createDatabaseField($databaseName, $fieldName, $magentoField)
|
| 210 |
+
{
|
| 211 |
+
$builder = Mage::helper('marketingsoftware/api_builder');
|
| 212 |
+
|
| 213 |
+
switch ($magentoField) {
|
| 214 |
+
case 'email':
|
| 215 |
+
$builder->createDatabaseEmailField($databaseName, $fieldName);
|
| 216 |
+
break;
|
| 217 |
+
|
| 218 |
+
case 'newsletter' :
|
| 219 |
+
$builder->createDatabaseNewsletterField($databaseName, $fieldName);
|
| 220 |
+
break;
|
| 221 |
+
|
| 222 |
+
case 'birthdate' :
|
| 223 |
+
$builder->createDatabaseDateField($databaseName, $fieldName);
|
| 224 |
+
break;
|
| 225 |
+
|
| 226 |
+
case 'storeView':
|
| 227 |
+
$builder->createDatabaseField($databaseName, $fieldName, array( 'length' => 250 ));
|
| 228 |
+
break;
|
| 229 |
+
|
| 230 |
+
case 'registrationDate' :
|
| 231 |
+
$builder->createDatabaseDatetimeField($databaseName, $fieldName);
|
| 232 |
+
break;
|
| 233 |
+
|
| 234 |
+
default:
|
| 235 |
+
$builder->createDatabaseField($databaseName, $fieldName);
|
| 236 |
+
break;
|
| 237 |
+
}
|
| 238 |
+
}
|
| 239 |
+
|
| 240 |
+
/**
|
| 241 |
+
* This ajax call can be used to store information about certain collection
|
| 242 |
+
*/
|
| 243 |
+
public function storeAction()
|
| 244 |
+
{
|
| 245 |
+
$post = $this->getRequest()->getPost();
|
| 246 |
+
|
| 247 |
+
$builder = Mage::helper('marketingsoftware/api_builder');
|
| 248 |
+
$config = Mage::helper('marketingsoftware/config');
|
| 249 |
+
|
| 250 |
+
switch ($post['type']) {
|
| 251 |
+
case 'main':
|
| 252 |
+
$builder->createDatabase($post['name']);
|
| 253 |
+
|
| 254 |
+
$profileCacheCollection = Mage::getModel('marketingsoftware/profile_cache')->getCollection();
|
| 255 |
+
|
| 256 |
+
foreach($profileCacheCollection as $profileCache) {
|
| 257 |
+
$profileCache->delete();
|
| 258 |
+
}
|
| 259 |
+
|
| 260 |
+
$config->unsDatabaseId();
|
| 261 |
+
$config->setDatabaseName($post['name']);
|
| 262 |
+
|
| 263 |
+
$fields = array();
|
| 264 |
+
|
| 265 |
+
foreach ($post['fields'] as $field) {
|
| 266 |
+
list($magento, $copernica) = explode(',', $field);
|
| 267 |
+
|
| 268 |
+
$fields[$magento] = $copernica;
|
| 269 |
+
|
| 270 |
+
$this->_createDatabaseField($post['name'], $copernica, $magento);
|
| 271 |
+
}
|
| 272 |
+
|
| 273 |
+
$config->setLinkedCustomerFields($fields);
|
| 274 |
+
break;
|
| 275 |
+
|
| 276 |
+
default:
|
| 277 |
+
$databaseName = Mage::helper('marketingsoftware/config')->getDatabaseName();
|
| 278 |
+
|
| 279 |
+
$builder->createCollection($databaseName, $post['name'], $post['type']);
|
| 280 |
+
|
| 281 |
+
$fields = array();
|
| 282 |
+
|
| 283 |
+
foreach ($post['fields'] as $field) {
|
| 284 |
+
list($magento, $copernica) = explode(',', $field);
|
| 285 |
+
|
| 286 |
+
$fields[$magento] = $copernica;
|
| 287 |
+
|
| 288 |
+
$builder->createCollectionField($databaseName, $post['name'], $post['type'], $copernica, $magento);
|
| 289 |
+
}
|
| 290 |
+
|
| 291 |
+
switch ($post['type']) {
|
| 292 |
+
case 'orders':
|
| 293 |
+
$config->unsOrdersCollectionId();
|
| 294 |
+
$config->setOrdersCollectionName($post['name']);
|
| 295 |
+
$config->setLinkedOrderFields($fields);
|
| 296 |
+
break;
|
| 297 |
+
|
| 298 |
+
case 'orderproducts':
|
| 299 |
+
$config->unsOrderItemCollectionId();
|
| 300 |
+
$config->setOrderItemCollectionName($post['name']);
|
| 301 |
+
$config->setLinkedOrderItemFields($fields);
|
| 302 |
+
break;
|
| 303 |
+
|
| 304 |
+
case 'addresses':
|
| 305 |
+
$config->unsAddressCollectionId();
|
| 306 |
+
$config->setAddressCollectionName($post['name']);
|
| 307 |
+
$config->setLinkedAddressFields($fields);
|
| 308 |
+
break;
|
| 309 |
+
|
| 310 |
+
case 'viewedproducts':
|
| 311 |
+
$config->unsViewedProductCollectionId();
|
| 312 |
+
$config->setViewedProductCollectionName($post['name']);
|
| 313 |
+
$config->setLinkedViewedProductFields($fields);
|
| 314 |
+
break;
|
| 315 |
+
|
| 316 |
+
case 'cartproducts':
|
| 317 |
+
$config->unsQuoteItemCollectionId();
|
| 318 |
+
$config->setQuoteItemCollectionName($post['name']);
|
| 319 |
+
$config->setLinkedQuoteItemFields($fields);
|
| 320 |
+
break;
|
| 321 |
+
|
| 322 |
+
case 'wishlistproducts':
|
| 323 |
+
$config->unsWishlistItemCollectionId();
|
| 324 |
+
$config->setWishlistItemCollectionName($post['name']);
|
| 325 |
+
$config->setLinkedWishlistItemFields($fields);
|
| 326 |
+
break;
|
| 327 |
+
}
|
| 328 |
+
break;
|
| 329 |
+
}
|
| 330 |
+
}
|
| 331 |
+
|
| 332 |
+
/**
|
| 333 |
+
* Make default structure.
|
| 334 |
+
*/
|
| 335 |
+
public function defaultAction()
|
| 336 |
+
{
|
| 337 |
+
$databaseName = 'Magento';
|
| 338 |
+
|
| 339 |
+
$builder = Mage::helper('marketingsoftware/api_builder');
|
| 340 |
+
$config = Mage::helper('marketingsoftware/config');
|
| 341 |
+
$data = Mage::helper('marketingsoftware/data');
|
| 342 |
+
|
| 343 |
+
$builder->createDatabase($databaseName);
|
| 344 |
+
|
| 345 |
+
$config->unsDatabaseId();
|
| 346 |
+
$config->setDatabaseName($databaseName);
|
| 347 |
+
|
| 348 |
+
$config->clearLinkedCollections();
|
| 349 |
+
|
| 350 |
+
$profileCacheCollection = Mage::getModel('marketingsoftware/profile_cache')->getCollection();
|
| 351 |
+
|
| 352 |
+
foreach($profileCacheCollection as $profileCache) {
|
| 353 |
+
$profileCache->delete();
|
| 354 |
+
}
|
| 355 |
+
|
| 356 |
+
$supportedFields = $data->supportedCustomerFields();
|
| 357 |
+
$linkedFields = array();
|
| 358 |
+
|
| 359 |
+
foreach ($supportedFields as $name => $label) {
|
| 360 |
+
$this->_createDatabaseField($databaseName, $name, $name);
|
| 361 |
+
$linkedFields[$name] = $name;
|
| 362 |
+
}
|
| 363 |
+
|
| 364 |
+
$config->setLinkedCustomerFields($linkedFields);
|
| 365 |
+
|
| 366 |
+
/*
|
| 367 |
+
* Quote items collection
|
| 368 |
+
*/
|
| 369 |
+
$builder->createCollection($databaseName, 'Cart_Items' ,'cartproducts');
|
| 370 |
+
$config->setQuoteItemCollectionName('Cart_Items');
|
| 371 |
+
$supportedFields = $data->supportedQuoteItemFields();
|
| 372 |
+
$linkedFields = array();
|
| 373 |
+
|
| 374 |
+
foreach ($supportedFields as $name => $label) {
|
| 375 |
+
$builder->createCollectionField($databaseName, 'Cart_Items', 'cartproducts', $name, $name);
|
| 376 |
+
$linkedFields[$name] = $name;
|
| 377 |
+
}
|
| 378 |
+
|
| 379 |
+
$config->setLinkedQuoteItemFields($linkedFields);
|
| 380 |
+
|
| 381 |
+
/*
|
| 382 |
+
* Orders collection
|
| 383 |
+
*/
|
| 384 |
+
$builder->createCollection($databaseName, 'Orders' ,'orders');
|
| 385 |
+
$config->setOrdersCollectionName('Orders');
|
| 386 |
+
$supportedFields = $data->supportedOrderFields();
|
| 387 |
+
$linkedFields = array();
|
| 388 |
+
|
| 389 |
+
foreach ($supportedFields as $name => $label) {
|
| 390 |
+
$builder->createCollectionField($databaseName, 'Orders', 'orders', $name, $name);
|
| 391 |
+
$linkedFields[$name] = $name;
|
| 392 |
+
}
|
| 393 |
+
|
| 394 |
+
$config->setLinkedOrderFields($linkedFields);
|
| 395 |
+
|
| 396 |
+
/*
|
| 397 |
+
* Orders items collection
|
| 398 |
+
*/
|
| 399 |
+
$builder->createCollection($databaseName, 'Orders_Items' ,'orderproducts');
|
| 400 |
+
$config->setOrderItemCollectionName('Orders_Items');
|
| 401 |
+
$supportedFields = $data->supportedOrderItemFields();
|
| 402 |
+
$linkedFields = array();
|
| 403 |
+
|
| 404 |
+
foreach ($supportedFields as $name => $label) {
|
| 405 |
+
$builder->createCollectionField($databaseName, 'Orders_Items', 'orderproducts', $name, $name);
|
| 406 |
+
$linkedFields[$name] = $name;
|
| 407 |
+
}
|
| 408 |
+
|
| 409 |
+
$config->setLinkedOrderItemFields($linkedFields);
|
| 410 |
+
|
| 411 |
+
/*
|
| 412 |
+
* Addresses collection
|
| 413 |
+
*/
|
| 414 |
+
$builder->createCollection($databaseName, 'Addresses' ,'addresses');
|
| 415 |
+
$config->setAddressCollectionName('Addresses');
|
| 416 |
+
$supportedFields = $data->supportedAddressFields();
|
| 417 |
+
$linkedFields = array();
|
| 418 |
+
|
| 419 |
+
foreach ($supportedFields as $name => $label) {
|
| 420 |
+
$builder->createCollectionField($databaseName, 'Addresses', 'addresses', $name, $name);
|
| 421 |
+
$linkedFields[$name] = $name;
|
| 422 |
+
}
|
| 423 |
+
|
| 424 |
+
$config->setLinkedAddressFields($linkedFields);
|
| 425 |
+
|
| 426 |
+
/*
|
| 427 |
+
* Viewed products collection
|
| 428 |
+
*/
|
| 429 |
+
$builder->createCollection($databaseName, 'Viewed_Products' ,'viewedproducts');
|
| 430 |
+
$config->setViewedProductCollectionName('Viewed_Products');
|
| 431 |
+
$supportedFields = $data->supportedViewedProductFields();
|
| 432 |
+
$linkedFields = array();
|
| 433 |
+
|
| 434 |
+
foreach ($supportedFields as $name => $label) {
|
| 435 |
+
$builder->createCollectionField($databaseName, 'Viewed_Products', 'viewedproducts', $name, $name);
|
| 436 |
+
$linkedFields[$name] = $name;
|
| 437 |
+
}
|
| 438 |
+
|
| 439 |
+
$config->setLinkedViewedProductFields($linkedFields);
|
| 440 |
+
|
| 441 |
+
/*
|
| 442 |
+
* Wishlist items collection
|
| 443 |
+
*/
|
| 444 |
+
$builder->createCollection($databaseName, 'Wishlist_Items' ,'wishlistproducts');
|
| 445 |
+
$config->setWishlistItemCollectionName('Wishlist_Items');
|
| 446 |
+
$supportedFields = $data->supportedWishlistItemFields();
|
| 447 |
+
$linkedFields = array();
|
| 448 |
+
|
| 449 |
+
foreach ($supportedFields as $name => $label) {
|
| 450 |
+
$builder->createCollectionField($databaseName, 'Wishlist_Items', 'wishlistproducts', $name, $name);
|
| 451 |
+
$linkedFields[$name] = $name;
|
| 452 |
+
}
|
| 453 |
+
|
| 454 |
+
$config->setLinkedWishlistItemFields($linkedFields);
|
| 455 |
+
}
|
| 456 |
}
|
app/code/community/Copernica/MarketingSoftware/controllers/Adminhtml/Marketingsoftware/ExportController.php
CHANGED
|
@@ -1,139 +1,139 @@
|
|
| 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 |
-
* Export Controller takes care of the export data menu.
|
| 29 |
-
*
|
| 30 |
-
*/
|
| 31 |
-
class Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_ExportController extends Copernica_MarketingSoftware_Controller_Action
|
| 32 |
-
{
|
| 33 |
-
/**
|
| 34 |
-
* Takes care of displaying the form which
|
| 35 |
-
* contains the details used for the SOAP connection.
|
| 36 |
-
*/
|
| 37 |
-
public function indexAction()
|
| 38 |
-
{
|
| 39 |
-
$this->loadLayout();
|
| 40 |
-
|
| 41 |
-
$this->_setActiveMenu('copernica');
|
| 42 |
-
|
| 43 |
-
$layout = $this->getLayout();
|
| 44 |
-
|
| 45 |
-
$contentBlock = $layout->getBlock('content');
|
| 46 |
-
|
| 47 |
-
$exportBlock = $layout->createBlock('marketingsoftware/adminhtml_marketingsoftware_export');
|
| 48 |
-
|
| 49 |
-
$contentBlock->append($exportBlock);
|
| 50 |
-
|
| 51 |
-
$layout->getBlock('head')->setTitle($this->__('Synchronize Data / Copernica Marketing Software / Magento Admin'));
|
| 52 |
-
|
| 53 |
-
$this->renderLayout();
|
| 54 |
-
}
|
| 55 |
-
|
| 56 |
-
/**
|
| 57 |
-
* progressAction() takes care of placing a loader during the background
|
| 58 |
-
* export action.
|
| 59 |
-
* Returns a 'completed' or 'in progress' message, depending
|
| 60 |
-
* on the state of the sync tool
|
| 61 |
-
*
|
| 62 |
-
* @return string
|
| 63 |
-
*/
|
| 64 |
-
public function progressAction()
|
| 65 |
-
{
|
| 66 |
-
$queueCollection = Mage::getResourceModel('marketingsoftware/queue_item_collection');
|
| 67 |
-
$helper = Mage::helper('marketingsoftware');
|
| 68 |
-
|
| 69 |
-
$response = $this->getResponse();
|
| 70 |
-
$response->setHeader('Content-Type', 'text/plain', true);
|
| 71 |
-
$response->clearBody();
|
| 72 |
-
$response->sendHeaders();
|
| 73 |
-
|
| 74 |
-
if ($helper->isSynchronisationStartScheduled()) {
|
| 75 |
-
$string = "Synchronisation scheduled to be started.";
|
| 76 |
-
} elseif ($queueCollection->getSize() > 0) {
|
| 77 |
-
$string = "<b>Number of records</b> : " . $queueCollection->getSize();
|
| 78 |
-
$string .= "<br/><b>Oldest record</b> : " . $queueCollection->getQueueStartTime();
|
| 79 |
-
} else {
|
| 80 |
-
$string = 'Idle, no recods in queue.';
|
| 81 |
-
}
|
| 82 |
-
|
| 83 |
-
$response->setBody($string);
|
| 84 |
-
return;
|
| 85 |
-
}
|
| 86 |
-
|
| 87 |
-
/**
|
| 88 |
-
* getAction() takes care of exporting customers account information
|
| 89 |
-
* from Magento to Copernica.
|
| 90 |
-
*
|
| 91 |
-
* @return string
|
| 92 |
-
*/
|
| 93 |
-
public function getAction()
|
| 94 |
-
{
|
| 95 |
-
$post = $this->getRequest()->getPost();
|
| 96 |
-
|
| 97 |
-
if (empty($post)) {
|
| 98 |
-
Mage::getSingleton('adminhtml/session')->addError('Invalid data.');
|
| 99 |
-
return $this->_redirect('*/*');
|
| 100 |
-
}
|
| 101 |
-
|
| 102 |
-
$helper = Mage::helper('marketingsoftware');
|
| 103 |
-
|
| 104 |
-
if ($helper->isSynchronisationStartScheduled()) {
|
| 105 |
-
Mage::getSingleton('adminhtml/session')
|
| 106 |
-
->addError('A synchronization has already been scheduled, please be patient for it to finish.');
|
| 107 |
-
} else {
|
| 108 |
-
$this->_startSync();
|
| 109 |
-
}
|
| 110 |
-
|
| 111 |
-
return $this->_redirect('*/*');
|
| 112 |
-
}
|
| 113 |
-
|
| 114 |
-
/**
|
| 115 |
-
* Start synchronization process. This method should add new 'start_sync'
|
| 116 |
-
* event on the event queue.
|
| 117 |
-
*/
|
| 118 |
-
protected function _startSync()
|
| 119 |
-
{
|
| 120 |
-
$config = Mage::helper('marketingsoftware/config');
|
| 121 |
-
|
| 122 |
-
$config->setCustomerProgressStatus('1945-08-06 08:15:00');
|
| 123 |
-
$config->setOrderProgressStatus('1945-08-06 08:15:00');
|
| 124 |
-
|
| 125 |
-
$syncStatus = Mage::getModel('marketingsoftware/sync_status');
|
| 126 |
-
|
| 127 |
-
if ($enabledStores = $config->getEnabledStores()) {
|
| 128 |
-
$syncStatus->setStoresFilter($enabledStores);
|
| 129 |
-
}
|
| 130 |
-
|
| 131 |
-
$queue = Mage::getModel('marketingsoftware/queue_item')
|
| 132 |
-
->setObject($syncStatus->toArray())
|
| 133 |
-
->setAction('start_sync')
|
| 134 |
-
->setName('startsync')
|
| 135 |
-
->save();
|
| 136 |
-
|
| 137 |
-
Mage::getSingleton('adminhtml/session')->addSuccess("The synchronization process has been scheduled!");
|
| 138 |
-
}
|
| 139 |
}
|
| 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 |
+
* Export Controller takes care of the export data menu.
|
| 29 |
+
*
|
| 30 |
+
*/
|
| 31 |
+
class Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_ExportController extends Copernica_MarketingSoftware_Controller_Action
|
| 32 |
+
{
|
| 33 |
+
/**
|
| 34 |
+
* Takes care of displaying the form which
|
| 35 |
+
* contains the details used for the SOAP connection.
|
| 36 |
+
*/
|
| 37 |
+
public function indexAction()
|
| 38 |
+
{
|
| 39 |
+
$this->loadLayout();
|
| 40 |
+
|
| 41 |
+
$this->_setActiveMenu('copernica');
|
| 42 |
+
|
| 43 |
+
$layout = $this->getLayout();
|
| 44 |
+
|
| 45 |
+
$contentBlock = $layout->getBlock('content');
|
| 46 |
+
|
| 47 |
+
$exportBlock = $layout->createBlock('marketingsoftware/adminhtml_marketingsoftware_export');
|
| 48 |
+
|
| 49 |
+
$contentBlock->append($exportBlock);
|
| 50 |
+
|
| 51 |
+
$layout->getBlock('head')->setTitle($this->__('Synchronize Data / Copernica Marketing Software / Magento Admin'));
|
| 52 |
+
|
| 53 |
+
$this->renderLayout();
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
/**
|
| 57 |
+
* progressAction() takes care of placing a loader during the background
|
| 58 |
+
* export action.
|
| 59 |
+
* Returns a 'completed' or 'in progress' message, depending
|
| 60 |
+
* on the state of the sync tool
|
| 61 |
+
*
|
| 62 |
+
* @return string
|
| 63 |
+
*/
|
| 64 |
+
public function progressAction()
|
| 65 |
+
{
|
| 66 |
+
$queueCollection = Mage::getResourceModel('marketingsoftware/queue_item_collection');
|
| 67 |
+
$helper = Mage::helper('marketingsoftware');
|
| 68 |
+
|
| 69 |
+
$response = $this->getResponse();
|
| 70 |
+
$response->setHeader('Content-Type', 'text/plain', true);
|
| 71 |
+
$response->clearBody();
|
| 72 |
+
$response->sendHeaders();
|
| 73 |
+
|
| 74 |
+
if ($helper->isSynchronisationStartScheduled()) {
|
| 75 |
+
$string = "Synchronisation scheduled to be started.";
|
| 76 |
+
} elseif ($queueCollection->getSize() > 0) {
|
| 77 |
+
$string = "<b>Number of records</b> : " . $queueCollection->getSize();
|
| 78 |
+
$string .= "<br/><b>Oldest record</b> : " . $queueCollection->getQueueStartTime();
|
| 79 |
+
} else {
|
| 80 |
+
$string = 'Idle, no recods in queue.';
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
$response->setBody($string);
|
| 84 |
+
return;
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
/**
|
| 88 |
+
* getAction() takes care of exporting customers account information
|
| 89 |
+
* from Magento to Copernica.
|
| 90 |
+
*
|
| 91 |
+
* @return string
|
| 92 |
+
*/
|
| 93 |
+
public function getAction()
|
| 94 |
+
{
|
| 95 |
+
$post = $this->getRequest()->getPost();
|
| 96 |
+
|
| 97 |
+
if (empty($post)) {
|
| 98 |
+
Mage::getSingleton('adminhtml/session')->addError('Invalid data.');
|
| 99 |
+
return $this->_redirect('*/*');
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
$helper = Mage::helper('marketingsoftware');
|
| 103 |
+
|
| 104 |
+
if ($helper->isSynchronisationStartScheduled()) {
|
| 105 |
+
Mage::getSingleton('adminhtml/session')
|
| 106 |
+
->addError('A synchronization has already been scheduled, please be patient for it to finish.');
|
| 107 |
+
} else {
|
| 108 |
+
$this->_startSync();
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
return $this->_redirect('*/*');
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
/**
|
| 115 |
+
* Start synchronization process. This method should add new 'start_sync'
|
| 116 |
+
* event on the event queue.
|
| 117 |
+
*/
|
| 118 |
+
protected function _startSync()
|
| 119 |
+
{
|
| 120 |
+
$config = Mage::helper('marketingsoftware/config');
|
| 121 |
+
|
| 122 |
+
$config->setCustomerProgressStatus('1945-08-06 08:15:00');
|
| 123 |
+
$config->setOrderProgressStatus('1945-08-06 08:15:00');
|
| 124 |
+
|
| 125 |
+
$syncStatus = Mage::getModel('marketingsoftware/sync_status');
|
| 126 |
+
|
| 127 |
+
if ($enabledStores = $config->getEnabledStores()) {
|
| 128 |
+
$syncStatus->setStoresFilter($enabledStores);
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
$queue = Mage::getModel('marketingsoftware/queue_item')
|
| 132 |
+
->setObject($syncStatus->toArray())
|
| 133 |
+
->setAction('start_sync')
|
| 134 |
+
->setName('startsync')
|
| 135 |
+
->save();
|
| 136 |
+
|
| 137 |
+
Mage::getSingleton('adminhtml/session')->addSuccess("The synchronization process has been scheduled!");
|
| 138 |
+
}
|
| 139 |
}
|
app/code/community/Copernica/MarketingSoftware/controllers/Adminhtml/Marketingsoftware/LinkController.php
CHANGED
|
@@ -1,240 +1,240 @@
|
|
| 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 |
-
* Link Controller takes care of the link fields menu.
|
| 29 |
-
*
|
| 30 |
-
*/
|
| 31 |
-
class Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_LinkController extends Copernica_MarketingSoftware_Controller_Action
|
| 32 |
-
{
|
| 33 |
-
/**
|
| 34 |
-
* indexAction() takes care of displaying the form which
|
| 35 |
-
* contains the details used for the SOAP connection
|
| 36 |
-
*/
|
| 37 |
-
public function indexAction()
|
| 38 |
-
{
|
| 39 |
-
$this->loadLayout();
|
| 40 |
-
|
| 41 |
-
$this->_setActiveMenu('copernica');
|
| 42 |
-
|
| 43 |
-
$layout = $this->getLayout();
|
| 44 |
-
|
| 45 |
-
$contentBlock = $layout->getBlock('content');
|
| 46 |
-
|
| 47 |
-
$linkBlock = $layout->createBlock('marketingsoftware/adminhtml_marketingsoftware_link');
|
| 48 |
-
|
| 49 |
-
$contentBlock->append($linkBlock);
|
| 50 |
-
|
| 51 |
-
$headBlock = $layout->getBlock('head');
|
| 52 |
-
$headBlock->setTitle($this->__('Link Fields / Copernica Marketing Software / Magento Admin'));
|
| 53 |
-
$headBlock->addJs('copernica/marketingsoftware/link.js');
|
| 54 |
-
|
| 55 |
-
$this->renderLayout();
|
| 56 |
-
}
|
| 57 |
-
|
| 58 |
-
/**
|
| 59 |
-
* This action will save all form data.
|
| 60 |
-
* @todo Never used, Ajaxcollection is always called to perform the save per collection.
|
| 61 |
-
*/
|
| 62 |
-
public function saveFormAction()
|
| 63 |
-
{
|
| 64 |
-
$post = $this->getRequest()->getPost();
|
| 65 |
-
$post = json_decode($post['data'], true);
|
| 66 |
-
|
| 67 |
-
if (isset($post['database']['name'])) {
|
| 68 |
-
$this->_saveDatabaseData($post['database']);
|
| 69 |
-
}
|
| 70 |
-
|
| 71 |
-
if (isset($post['collections'])) {
|
| 72 |
-
$this->_saveCollections($post['collections']);
|
| 73 |
-
}
|
| 74 |
-
|
| 75 |
-
$this->_setResponse();
|
| 76 |
-
}
|
| 77 |
-
|
| 78 |
-
/**
|
| 79 |
-
* This method will save database related informations.
|
| 80 |
-
*
|
| 81 |
-
* @param assoc $data
|
| 82 |
-
*/
|
| 83 |
-
protected function _saveDatabaseData($data)
|
| 84 |
-
{
|
| 85 |
-
$this->_saveDatabaseName($data['name']);
|
| 86 |
-
|
| 87 |
-
$this->_saveDatabaseFields($data['fields']);
|
| 88 |
-
}
|
| 89 |
-
|
| 90 |
-
/**
|
| 91 |
-
* This method will store database name.
|
| 92 |
-
*/
|
| 93 |
-
protected function _saveDatabaseName($name)
|
| 94 |
-
{
|
| 95 |
-
Mage::helper('marketingsoftware/config')->setDatabase($name);
|
| 96 |
-
|
| 97 |
-
$databaseId = Mage::helper('marketingsoftware/api_abstract')->getDatabaseId($name);
|
| 98 |
-
|
| 99 |
-
Mage::helper('marketingsoftware/config')->setDatabaseId($databaseId);
|
| 100 |
-
}
|
| 101 |
-
|
| 102 |
-
/**
|
| 103 |
-
* This method will save database fields
|
| 104 |
-
*
|
| 105 |
-
* @param assoc $data
|
| 106 |
-
*/
|
| 107 |
-
protected function _saveDatabaseFields($data)
|
| 108 |
-
{
|
| 109 |
-
Mage::helper('marketingsoftware/config')->setLinkedCustomerFields($data);
|
| 110 |
-
}
|
| 111 |
-
|
| 112 |
-
/**
|
| 113 |
-
* This method will save all collections from data
|
| 114 |
-
*
|
| 115 |
-
* @param assoc $data
|
| 116 |
-
*/
|
| 117 |
-
protected function _saveCollections($data)
|
| 118 |
-
{
|
| 119 |
-
$config = Mage::helper('marketingsoftware/config');
|
| 120 |
-
|
| 121 |
-
$config->clearLinkedCollections();
|
| 122 |
-
|
| 123 |
-
if (isset($data['cartproducts'])) {
|
| 124 |
-
$this->_saveQuoteProductsCollection($data['cartproducts']);
|
| 125 |
-
}
|
| 126 |
-
|
| 127 |
-
if (isset($data['orders'])) {
|
| 128 |
-
$this->_saveOrdersCollection($data['orders']);
|
| 129 |
-
}
|
| 130 |
-
|
| 131 |
-
if (isset($data['orderproducts'])) {
|
| 132 |
-
$this->_saveOrderItemsCollection($data['orderproducts']);
|
| 133 |
-
}
|
| 134 |
-
|
| 135 |
-
if (isset($data['addresses'])) {
|
| 136 |
-
$this->_saveAddressesCollection($data['addresses']);
|
| 137 |
-
}
|
| 138 |
-
|
| 139 |
-
if (isset($data['viewedproduct'])) {
|
| 140 |
-
$this->_saveViewedProductsCollection($data['viewedproduct']);
|
| 141 |
-
}
|
| 142 |
-
}
|
| 143 |
-
|
| 144 |
-
/**
|
| 145 |
-
* Save cart products info
|
| 146 |
-
*
|
| 147 |
-
* @param assoc $data
|
| 148 |
-
*/
|
| 149 |
-
protected function _saveQuoteProductsCollection($data)
|
| 150 |
-
{
|
| 151 |
-
$collectionId = Mage::helper('marketingsoftware/api_abstract')->getCollectionId($data['name']);
|
| 152 |
-
|
| 153 |
-
$config = Mage::helper('marketingsoftware/config');
|
| 154 |
-
$config->setQuoteItemCollectionName($data['name']);
|
| 155 |
-
$config->setQuoteItemCollectionId($collectionId);
|
| 156 |
-
$config->setLinkedQuoteItemFields($data['fields']);
|
| 157 |
-
}
|
| 158 |
-
|
| 159 |
-
/**
|
| 160 |
-
* Save order collection info
|
| 161 |
-
*
|
| 162 |
-
* @param assoc $data
|
| 163 |
-
*/
|
| 164 |
-
protected function _saveOrdersCollection($data)
|
| 165 |
-
{
|
| 166 |
-
$collectionId = Mage::helper('marketingsoftware/api_abstract')->getCollectionId($data['name']);
|
| 167 |
-
|
| 168 |
-
$config = Mage::helper('marketingsoftware/config');
|
| 169 |
-
$config->setOrdersCollectionName($data['name']);
|
| 170 |
-
$config->setOrdersCollectionId($collectionId);
|
| 171 |
-
$config->setLinkedOrderFields($data['fields']);
|
| 172 |
-
}
|
| 173 |
-
|
| 174 |
-
/**
|
| 175 |
-
* Save order items collection info
|
| 176 |
-
*
|
| 177 |
-
* @param assoc $data
|
| 178 |
-
*/
|
| 179 |
-
protected function _saveOrderItemsCollection($data)
|
| 180 |
-
{
|
| 181 |
-
$collectionId = Mage::helper('marketingsoftware/api_abstract')->getCollectionId($data['name']);
|
| 182 |
-
|
| 183 |
-
$config = Mage::helper('marketingsoftware/config');
|
| 184 |
-
$config->setOrderItemCollectionName($data['name']);
|
| 185 |
-
$config->setOrderItemCollectionId($collectionId);
|
| 186 |
-
$config->setLinkedOrderItemFields($data['fields']);
|
| 187 |
-
}
|
| 188 |
-
|
| 189 |
-
/**
|
| 190 |
-
* Save addresses collection info
|
| 191 |
-
*
|
| 192 |
-
* @param assoc $data
|
| 193 |
-
*/
|
| 194 |
-
protected function _saveAddressesCollection($data)
|
| 195 |
-
{
|
| 196 |
-
$collectionId = Mage::helper('marketingsoftware/api_abstract')->getCollectionId($data['name']);
|
| 197 |
-
|
| 198 |
-
$config = Mage::helper('marketingsoftware/config');
|
| 199 |
-
$config->setAddressCollectionName($data['name']);
|
| 200 |
-
$config->setAddressCollectionId($collectionId);
|
| 201 |
-
$config->setLinkedAddressFields($data['fields']);
|
| 202 |
-
}
|
| 203 |
-
|
| 204 |
-
/**
|
| 205 |
-
* Save viewed products collection info
|
| 206 |
-
*
|
| 207 |
-
* @param assoc $data
|
| 208 |
-
*/
|
| 209 |
-
protected function _saveViewedProductsCollection($data)
|
| 210 |
-
{
|
| 211 |
-
$collectionId = Mage::helper('marketingsoftware/api_abstract')->getCollectionId($data['name']);
|
| 212 |
-
|
| 213 |
-
$config = Mage::helper('marketingsoftware/config');
|
| 214 |
-
$config->setViewedProductCollectionName($data['name']);
|
| 215 |
-
$config->setViewedProductCollectionId($collectionId);
|
| 216 |
-
$config->setLinkedViewedProductFields($data['fields']);
|
| 217 |
-
}
|
| 218 |
-
|
| 219 |
-
/**
|
| 220 |
-
* Prepare response instance for AJAX response
|
| 221 |
-
*/
|
| 222 |
-
protected function _prepareAjaxResponse()
|
| 223 |
-
{
|
| 224 |
-
$response = $this->getResponse();
|
| 225 |
-
$response->clearBody();
|
| 226 |
-
$response->setHeader('Content-Type', 'application/json');
|
| 227 |
-
}
|
| 228 |
-
|
| 229 |
-
/**
|
| 230 |
-
* @param bool $error
|
| 231 |
-
*/
|
| 232 |
-
protected function _setResponse($error = false)
|
| 233 |
-
{
|
| 234 |
-
$this->_prepareAjaxResponse();
|
| 235 |
-
|
| 236 |
-
$this->getResponse()->setBody(json_encode(Array(
|
| 237 |
-
'error' => $error ? 1 : 0
|
| 238 |
-
)));
|
| 239 |
-
}
|
| 240 |
}
|
| 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 |
+
* Link Controller takes care of the link fields menu.
|
| 29 |
+
*
|
| 30 |
+
*/
|
| 31 |
+
class Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_LinkController extends Copernica_MarketingSoftware_Controller_Action
|
| 32 |
+
{
|
| 33 |
+
/**
|
| 34 |
+
* indexAction() takes care of displaying the form which
|
| 35 |
+
* contains the details used for the SOAP connection
|
| 36 |
+
*/
|
| 37 |
+
public function indexAction()
|
| 38 |
+
{
|
| 39 |
+
$this->loadLayout();
|
| 40 |
+
|
| 41 |
+
$this->_setActiveMenu('copernica');
|
| 42 |
+
|
| 43 |
+
$layout = $this->getLayout();
|
| 44 |
+
|
| 45 |
+
$contentBlock = $layout->getBlock('content');
|
| 46 |
+
|
| 47 |
+
$linkBlock = $layout->createBlock('marketingsoftware/adminhtml_marketingsoftware_link');
|
| 48 |
+
|
| 49 |
+
$contentBlock->append($linkBlock);
|
| 50 |
+
|
| 51 |
+
$headBlock = $layout->getBlock('head');
|
| 52 |
+
$headBlock->setTitle($this->__('Link Fields / Copernica Marketing Software / Magento Admin'));
|
| 53 |
+
$headBlock->addJs('copernica/marketingsoftware/link.js');
|
| 54 |
+
|
| 55 |
+
$this->renderLayout();
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
/**
|
| 59 |
+
* This action will save all form data.
|
| 60 |
+
* @todo Never used, Ajaxcollection is always called to perform the save per collection.
|
| 61 |
+
*/
|
| 62 |
+
public function saveFormAction()
|
| 63 |
+
{
|
| 64 |
+
$post = $this->getRequest()->getPost();
|
| 65 |
+
$post = json_decode($post['data'], true);
|
| 66 |
+
|
| 67 |
+
if (isset($post['database']['name'])) {
|
| 68 |
+
$this->_saveDatabaseData($post['database']);
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
if (isset($post['collections'])) {
|
| 72 |
+
$this->_saveCollections($post['collections']);
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
$this->_setResponse();
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
/**
|
| 79 |
+
* This method will save database related informations.
|
| 80 |
+
*
|
| 81 |
+
* @param assoc $data
|
| 82 |
+
*/
|
| 83 |
+
protected function _saveDatabaseData($data)
|
| 84 |
+
{
|
| 85 |
+
$this->_saveDatabaseName($data['name']);
|
| 86 |
+
|
| 87 |
+
$this->_saveDatabaseFields($data['fields']);
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
/**
|
| 91 |
+
* This method will store database name.
|
| 92 |
+
*/
|
| 93 |
+
protected function _saveDatabaseName($name)
|
| 94 |
+
{
|
| 95 |
+
Mage::helper('marketingsoftware/config')->setDatabase($name);
|
| 96 |
+
|
| 97 |
+
$databaseId = Mage::helper('marketingsoftware/api_abstract')->getDatabaseId($name);
|
| 98 |
+
|
| 99 |
+
Mage::helper('marketingsoftware/config')->setDatabaseId($databaseId);
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
/**
|
| 103 |
+
* This method will save database fields
|
| 104 |
+
*
|
| 105 |
+
* @param assoc $data
|
| 106 |
+
*/
|
| 107 |
+
protected function _saveDatabaseFields($data)
|
| 108 |
+
{
|
| 109 |
+
Mage::helper('marketingsoftware/config')->setLinkedCustomerFields($data);
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
/**
|
| 113 |
+
* This method will save all collections from data
|
| 114 |
+
*
|
| 115 |
+
* @param assoc $data
|
| 116 |
+
*/
|
| 117 |
+
protected function _saveCollections($data)
|
| 118 |
+
{
|
| 119 |
+
$config = Mage::helper('marketingsoftware/config');
|
| 120 |
+
|
| 121 |
+
$config->clearLinkedCollections();
|
| 122 |
+
|
| 123 |
+
if (isset($data['cartproducts'])) {
|
| 124 |
+
$this->_saveQuoteProductsCollection($data['cartproducts']);
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
if (isset($data['orders'])) {
|
| 128 |
+
$this->_saveOrdersCollection($data['orders']);
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
if (isset($data['orderproducts'])) {
|
| 132 |
+
$this->_saveOrderItemsCollection($data['orderproducts']);
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
if (isset($data['addresses'])) {
|
| 136 |
+
$this->_saveAddressesCollection($data['addresses']);
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
if (isset($data['viewedproduct'])) {
|
| 140 |
+
$this->_saveViewedProductsCollection($data['viewedproduct']);
|
| 141 |
+
}
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
/**
|
| 145 |
+
* Save cart products info
|
| 146 |
+
*
|
| 147 |
+
* @param assoc $data
|
| 148 |
+
*/
|
| 149 |
+
protected function _saveQuoteProductsCollection($data)
|
| 150 |
+
{
|
| 151 |
+
$collectionId = Mage::helper('marketingsoftware/api_abstract')->getCollectionId($data['name']);
|
| 152 |
+
|
| 153 |
+
$config = Mage::helper('marketingsoftware/config');
|
| 154 |
+
$config->setQuoteItemCollectionName($data['name']);
|
| 155 |
+
$config->setQuoteItemCollectionId($collectionId);
|
| 156 |
+
$config->setLinkedQuoteItemFields($data['fields']);
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
/**
|
| 160 |
+
* Save order collection info
|
| 161 |
+
*
|
| 162 |
+
* @param assoc $data
|
| 163 |
+
*/
|
| 164 |
+
protected function _saveOrdersCollection($data)
|
| 165 |
+
{
|
| 166 |
+
$collectionId = Mage::helper('marketingsoftware/api_abstract')->getCollectionId($data['name']);
|
| 167 |
+
|
| 168 |
+
$config = Mage::helper('marketingsoftware/config');
|
| 169 |
+
$config->setOrdersCollectionName($data['name']);
|
| 170 |
+
$config->setOrdersCollectionId($collectionId);
|
| 171 |
+
$config->setLinkedOrderFields($data['fields']);
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
/**
|
| 175 |
+
* Save order items collection info
|
| 176 |
+
*
|
| 177 |
+
* @param assoc $data
|
| 178 |
+
*/
|
| 179 |
+
protected function _saveOrderItemsCollection($data)
|
| 180 |
+
{
|
| 181 |
+
$collectionId = Mage::helper('marketingsoftware/api_abstract')->getCollectionId($data['name']);
|
| 182 |
+
|
| 183 |
+
$config = Mage::helper('marketingsoftware/config');
|
| 184 |
+
$config->setOrderItemCollectionName($data['name']);
|
| 185 |
+
$config->setOrderItemCollectionId($collectionId);
|
| 186 |
+
$config->setLinkedOrderItemFields($data['fields']);
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
/**
|
| 190 |
+
* Save addresses collection info
|
| 191 |
+
*
|
| 192 |
+
* @param assoc $data
|
| 193 |
+
*/
|
| 194 |
+
protected function _saveAddressesCollection($data)
|
| 195 |
+
{
|
| 196 |
+
$collectionId = Mage::helper('marketingsoftware/api_abstract')->getCollectionId($data['name']);
|
| 197 |
+
|
| 198 |
+
$config = Mage::helper('marketingsoftware/config');
|
| 199 |
+
$config->setAddressCollectionName($data['name']);
|
| 200 |
+
$config->setAddressCollectionId($collectionId);
|
| 201 |
+
$config->setLinkedAddressFields($data['fields']);
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
/**
|
| 205 |
+
* Save viewed products collection info
|
| 206 |
+
*
|
| 207 |
+
* @param assoc $data
|
| 208 |
+
*/
|
| 209 |
+
protected function _saveViewedProductsCollection($data)
|
| 210 |
+
{
|
| 211 |
+
$collectionId = Mage::helper('marketingsoftware/api_abstract')->getCollectionId($data['name']);
|
| 212 |
+
|
| 213 |
+
$config = Mage::helper('marketingsoftware/config');
|
| 214 |
+
$config->setViewedProductCollectionName($data['name']);
|
| 215 |
+
$config->setViewedProductCollectionId($collectionId);
|
| 216 |
+
$config->setLinkedViewedProductFields($data['fields']);
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
/**
|
| 220 |
+
* Prepare response instance for AJAX response
|
| 221 |
+
*/
|
| 222 |
+
protected function _prepareAjaxResponse()
|
| 223 |
+
{
|
| 224 |
+
$response = $this->getResponse();
|
| 225 |
+
$response->clearBody();
|
| 226 |
+
$response->setHeader('Content-Type', 'application/json');
|
| 227 |
+
}
|
| 228 |
+
|
| 229 |
+
/**
|
| 230 |
+
* @param bool $error
|
| 231 |
+
*/
|
| 232 |
+
protected function _setResponse($error = false)
|
| 233 |
+
{
|
| 234 |
+
$this->_prepareAjaxResponse();
|
| 235 |
+
|
| 236 |
+
$this->getResponse()->setBody(json_encode(Array(
|
| 237 |
+
'error' => $error ? 1 : 0
|
| 238 |
+
)));
|
| 239 |
+
}
|
| 240 |
}
|
app/code/community/Copernica/MarketingSoftware/controllers/Adminhtml/Marketingsoftware/SettingsController.php
CHANGED
|
@@ -1,203 +1,203 @@
|
|
| 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 |
-
* Settings Controller, which takes care of the settings menu.
|
| 29 |
-
*
|
| 30 |
-
*/
|
| 31 |
-
class Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_SettingsController extends Copernica_MarketingSoftware_Controller_Action
|
| 32 |
-
{
|
| 33 |
-
/**
|
| 34 |
-
* indexAction() takes care of displaying the form which
|
| 35 |
-
* contains the details used for the SOAP connection
|
| 36 |
-
*/
|
| 37 |
-
public function indexAction()
|
| 38 |
-
{
|
| 39 |
-
$this->loadLayout();
|
| 40 |
-
|
| 41 |
-
$this->_setActiveMenu('copernica');
|
| 42 |
-
|
| 43 |
-
$layout = $this->getLayout();
|
| 44 |
-
|
| 45 |
-
$contentBlock = $layout->getBlock('content');
|
| 46 |
-
|
| 47 |
-
$settingsBlock = $layout->createBlock('marketingsoftware/adminhtml_marketingsoftware_settings');
|
| 48 |
-
|
| 49 |
-
$contentBlock->append($settingsBlock);
|
| 50 |
-
|
| 51 |
-
$layout->getBlock('head')->setTitle($this->__('Settings / Copernica Marketing Software / Magento Admin'));
|
| 52 |
-
|
| 53 |
-
$session = Mage::getSingleton('adminhtml/session');
|
| 54 |
-
|
| 55 |
-
$session->setState($this->_generateState());
|
| 56 |
-
|
| 57 |
-
$this->renderLayout();
|
| 58 |
-
}
|
| 59 |
-
|
| 60 |
-
/**
|
| 61 |
-
* Handle urls that contain state variable.
|
| 62 |
-
*
|
| 63 |
-
* @return Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_SettingsController
|
| 64 |
-
*/
|
| 65 |
-
public function stateAction()
|
| 66 |
-
{
|
| 67 |
-
$session = Mage::getSingleton('adminhtml/session');
|
| 68 |
-
|
| 69 |
-
$state = $this->getRequest()->getParam('state');
|
| 70 |
-
|
| 71 |
-
if ($state != $session->getState()) {
|
| 72 |
-
return $this->_redirect('*/*', array('response' => 'invalid-state'));
|
| 73 |
-
}
|
| 74 |
-
|
| 75 |
-
$code = $this->getRequest()->getParam('code');
|
| 76 |
-
|
| 77 |
-
$request = Mage::helper('marketingsoftware/rest_request');
|
| 78 |
-
|
| 79 |
-
$accessToken = Mage::helper('marketingsoftware/api')->upgradeRequest(
|
| 80 |
-
Mage::helper('marketingsoftware/config')->getClientKey(),
|
| 81 |
-
Mage::helper('marketingsoftware/config')->getClientSecret(),
|
| 82 |
-
Mage::helper('adminhtml')->getUrl('*/*/state'),
|
| 83 |
-
$code
|
| 84 |
-
);
|
| 85 |
-
|
| 86 |
-
if ($accessToken === false) {
|
| 87 |
-
Mage::getSingleton('core/session')->setErrorMessage($this->__('No access token available'));
|
| 88 |
-
|
| 89 |
-
return $this->_redirect('*/*', array('response' => 'authorize-error'));
|
| 90 |
-
}
|
| 91 |
-
|
| 92 |
-
Mage::helper('marketingsoftware/config')->setAccessToken($accessToken);
|
| 93 |
-
|
| 94 |
-
return $this->_redirect('*/*', array('response' => 'new-access-token'));
|
| 95 |
-
}
|
| 96 |
-
|
| 97 |
-
/**
|
| 98 |
-
* Handle queue settings storage
|
| 99 |
-
*
|
| 100 |
-
* @return Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_SettingsController
|
| 101 |
-
*/
|
| 102 |
-
public function queueAction()
|
| 103 |
-
{
|
| 104 |
-
$post = $this->getRequest()->getPost();
|
| 105 |
-
|
| 106 |
-
$config = Mage::helper('marketingsoftware/config');
|
| 107 |
-
|
| 108 |
-
$config->setTimePerRun($post['qs_max_time']);
|
| 109 |
-
$config->setItemsPerRun($post['qs_max_items']);
|
| 110 |
-
$config->setApiHostname($post['qs_api_server']);
|
| 111 |
-
$config->setVanillaCrons(array_key_exists('qs_vanilla_crons', $post));
|
| 112 |
-
$config->setAbandonedTimeout($post['qs_abandoned_timeout']);
|
| 113 |
-
$config->setRemoveFinishedQuoteItem(array_key_exists('qs_remove_finished', $post));
|
| 114 |
-
|
| 115 |
-
Mage::getSingleton('core/session')->addSuccess('Synchronization settings have been saved');
|
| 116 |
-
session_write_close(); // To make sure the success message is passed
|
| 117 |
-
|
| 118 |
-
return $this->_redirect('*/*');
|
| 119 |
-
}
|
| 120 |
-
|
| 121 |
-
/**
|
| 122 |
-
* Handles stores settings
|
| 123 |
-
*
|
| 124 |
-
* @return Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_SettingsController
|
| 125 |
-
*/
|
| 126 |
-
public function storesAction()
|
| 127 |
-
{
|
| 128 |
-
$post = $this->getRequest()->getPost();
|
| 129 |
-
|
| 130 |
-
$config = Mage::helper('marketingsoftware/config');
|
| 131 |
-
|
| 132 |
-
if (isset($post['chk-store-disable'])) {
|
| 133 |
-
$config->setEnabledStores(null);
|
| 134 |
-
|
| 135 |
-
Mage::getSingleton('core/session')->addSuccess('Stores settings have been saved');
|
| 136 |
-
session_write_close(); // To make sure the success message is passed
|
| 137 |
-
|
| 138 |
-
return $this->_redirect('*/*');
|
| 139 |
-
}
|
| 140 |
-
|
| 141 |
-
$enabledStores = array();
|
| 142 |
-
|
| 143 |
-
if(isset($post['store'])) {
|
| 144 |
-
foreach($post['store'] as $store) {
|
| 145 |
-
$enabledStores[] = $store;
|
| 146 |
-
}
|
| 147 |
-
}
|
| 148 |
-
|
| 149 |
-
$config->setEnabledStores($enabledStores);
|
| 150 |
-
|
| 151 |
-
Mage::getSingleton('core/session')->addSuccess('Stores settings have been saved');
|
| 152 |
-
session_write_close(); // To make sure the success message is passed
|
| 153 |
-
|
| 154 |
-
return $this->_redirect('*/*');
|
| 155 |
-
}
|
| 156 |
-
|
| 157 |
-
/**
|
| 158 |
-
* Since we have to generate a state code for REST API we want to make
|
| 159 |
-
* it in way that it is possible to regenerate such state for a user in
|
| 160 |
-
* resonable time period (one certain day). We will use for that md5 hash
|
| 161 |
-
* of user's session id and current day-month-year combination.
|
| 162 |
-
*
|
| 163 |
-
* @return string
|
| 164 |
-
*/
|
| 165 |
-
protected function _generateState()
|
| 166 |
-
{
|
| 167 |
-
return md5(Mage::getSingleton('adminhtml/session')->getEncryptedSessionId().date('dmY'));
|
| 168 |
-
}
|
| 169 |
-
|
| 170 |
-
/**
|
| 171 |
-
* sendAction() takes care of checking and storing the login details to the SOAP
|
| 172 |
-
* It also performs checks on database and in case it doesn't exists, it will create it.
|
| 173 |
-
*
|
| 174 |
-
* @return Object Returns the '_redirect' object that loads the parent page
|
| 175 |
-
*/
|
| 176 |
-
public function sendAction()
|
| 177 |
-
{
|
| 178 |
-
$post = $this->getRequest()->getPost();
|
| 179 |
-
|
| 180 |
-
$config = Mage::helper('marketingsoftware/config');
|
| 181 |
-
|
| 182 |
-
$clientKey = $config->getClientKey();
|
| 183 |
-
|
| 184 |
-
$clientSecret = $config->getClientSecret();
|
| 185 |
-
|
| 186 |
-
if ($clientKey == $post['cp_client_key'] && $clientSecret == $post['cp_client_secret']) {
|
| 187 |
-
return $this->_redirect('*/*');
|
| 188 |
-
}
|
| 189 |
-
|
| 190 |
-
if (!isset($post['cp_client_key'])) {
|
| 191 |
-
return $this->_redirect('*/*');
|
| 192 |
-
}
|
| 193 |
-
|
| 194 |
-
$config->setClientKey($post['cp_client_key']);
|
| 195 |
-
$config->setClientSecret($post['cp_client_secret']);
|
| 196 |
-
$config->unsAccessToken();
|
| 197 |
-
|
| 198 |
-
Mage::getSingleton('core/session')->addSuccess('REST settings have been saved');
|
| 199 |
-
session_write_close(); // To make sure the success message is passed
|
| 200 |
-
|
| 201 |
-
return $this->_redirect('*/*');
|
| 202 |
-
}
|
| 203 |
}
|
| 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 |
+
* Settings Controller, which takes care of the settings menu.
|
| 29 |
+
*
|
| 30 |
+
*/
|
| 31 |
+
class Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_SettingsController extends Copernica_MarketingSoftware_Controller_Action
|
| 32 |
+
{
|
| 33 |
+
/**
|
| 34 |
+
* indexAction() takes care of displaying the form which
|
| 35 |
+
* contains the details used for the SOAP connection
|
| 36 |
+
*/
|
| 37 |
+
public function indexAction()
|
| 38 |
+
{
|
| 39 |
+
$this->loadLayout();
|
| 40 |
+
|
| 41 |
+
$this->_setActiveMenu('copernica');
|
| 42 |
+
|
| 43 |
+
$layout = $this->getLayout();
|
| 44 |
+
|
| 45 |
+
$contentBlock = $layout->getBlock('content');
|
| 46 |
+
|
| 47 |
+
$settingsBlock = $layout->createBlock('marketingsoftware/adminhtml_marketingsoftware_settings');
|
| 48 |
+
|
| 49 |
+
$contentBlock->append($settingsBlock);
|
| 50 |
+
|
| 51 |
+
$layout->getBlock('head')->setTitle($this->__('Settings / Copernica Marketing Software / Magento Admin'));
|
| 52 |
+
|
| 53 |
+
$session = Mage::getSingleton('adminhtml/session');
|
| 54 |
+
|
| 55 |
+
$session->setState($this->_generateState());
|
| 56 |
+
|
| 57 |
+
$this->renderLayout();
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
/**
|
| 61 |
+
* Handle urls that contain state variable.
|
| 62 |
+
*
|
| 63 |
+
* @return Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_SettingsController
|
| 64 |
+
*/
|
| 65 |
+
public function stateAction()
|
| 66 |
+
{
|
| 67 |
+
$session = Mage::getSingleton('adminhtml/session');
|
| 68 |
+
|
| 69 |
+
$state = $this->getRequest()->getParam('state');
|
| 70 |
+
|
| 71 |
+
if ($state != $session->getState()) {
|
| 72 |
+
return $this->_redirect('*/*', array('response' => 'invalid-state'));
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
$code = $this->getRequest()->getParam('code');
|
| 76 |
+
|
| 77 |
+
$request = Mage::helper('marketingsoftware/rest_request');
|
| 78 |
+
|
| 79 |
+
$accessToken = Mage::helper('marketingsoftware/api')->upgradeRequest(
|
| 80 |
+
Mage::helper('marketingsoftware/config')->getClientKey(),
|
| 81 |
+
Mage::helper('marketingsoftware/config')->getClientSecret(),
|
| 82 |
+
Mage::helper('adminhtml')->getUrl('*/*/state'),
|
| 83 |
+
$code
|
| 84 |
+
);
|
| 85 |
+
|
| 86 |
+
if ($accessToken === false) {
|
| 87 |
+
Mage::getSingleton('core/session')->setErrorMessage($this->__('No access token available'));
|
| 88 |
+
|
| 89 |
+
return $this->_redirect('*/*', array('response' => 'authorize-error'));
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
Mage::helper('marketingsoftware/config')->setAccessToken($accessToken);
|
| 93 |
+
|
| 94 |
+
return $this->_redirect('*/*', array('response' => 'new-access-token'));
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
/**
|
| 98 |
+
* Handle queue settings storage
|
| 99 |
+
*
|
| 100 |
+
* @return Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_SettingsController
|
| 101 |
+
*/
|
| 102 |
+
public function queueAction()
|
| 103 |
+
{
|
| 104 |
+
$post = $this->getRequest()->getPost();
|
| 105 |
+
|
| 106 |
+
$config = Mage::helper('marketingsoftware/config');
|
| 107 |
+
|
| 108 |
+
$config->setTimePerRun($post['qs_max_time']);
|
| 109 |
+
$config->setItemsPerRun($post['qs_max_items']);
|
| 110 |
+
$config->setApiHostname($post['qs_api_server']);
|
| 111 |
+
$config->setVanillaCrons(array_key_exists('qs_vanilla_crons', $post));
|
| 112 |
+
$config->setAbandonedTimeout($post['qs_abandoned_timeout']);
|
| 113 |
+
$config->setRemoveFinishedQuoteItem(array_key_exists('qs_remove_finished', $post));
|
| 114 |
+
|
| 115 |
+
Mage::getSingleton('core/session')->addSuccess('Synchronization settings have been saved');
|
| 116 |
+
session_write_close(); // To make sure the success message is passed
|
| 117 |
+
|
| 118 |
+
return $this->_redirect('*/*');
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
/**
|
| 122 |
+
* Handles stores settings
|
| 123 |
+
*
|
| 124 |
+
* @return Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_SettingsController
|
| 125 |
+
*/
|
| 126 |
+
public function storesAction()
|
| 127 |
+
{
|
| 128 |
+
$post = $this->getRequest()->getPost();
|
| 129 |
+
|
| 130 |
+
$config = Mage::helper('marketingsoftware/config');
|
| 131 |
+
|
| 132 |
+
if (isset($post['chk-store-disable'])) {
|
| 133 |
+
$config->setEnabledStores(null);
|
| 134 |
+
|
| 135 |
+
Mage::getSingleton('core/session')->addSuccess('Stores settings have been saved');
|
| 136 |
+
session_write_close(); // To make sure the success message is passed
|
| 137 |
+
|
| 138 |
+
return $this->_redirect('*/*');
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
$enabledStores = array();
|
| 142 |
+
|
| 143 |
+
if(isset($post['store'])) {
|
| 144 |
+
foreach($post['store'] as $store) {
|
| 145 |
+
$enabledStores[] = $store;
|
| 146 |
+
}
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
$config->setEnabledStores($enabledStores);
|
| 150 |
+
|
| 151 |
+
Mage::getSingleton('core/session')->addSuccess('Stores settings have been saved');
|
| 152 |
+
session_write_close(); // To make sure the success message is passed
|
| 153 |
+
|
| 154 |
+
return $this->_redirect('*/*');
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
/**
|
| 158 |
+
* Since we have to generate a state code for REST API we want to make
|
| 159 |
+
* it in way that it is possible to regenerate such state for a user in
|
| 160 |
+
* resonable time period (one certain day). We will use for that md5 hash
|
| 161 |
+
* of user's session id and current day-month-year combination.
|
| 162 |
+
*
|
| 163 |
+
* @return string
|
| 164 |
+
*/
|
| 165 |
+
protected function _generateState()
|
| 166 |
+
{
|
| 167 |
+
return md5(Mage::getSingleton('adminhtml/session')->getEncryptedSessionId().date('dmY'));
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
/**
|
| 171 |
+
* sendAction() takes care of checking and storing the login details to the SOAP
|
| 172 |
+
* It also performs checks on database and in case it doesn't exists, it will create it.
|
| 173 |
+
*
|
| 174 |
+
* @return Object Returns the '_redirect' object that loads the parent page
|
| 175 |
+
*/
|
| 176 |
+
public function sendAction()
|
| 177 |
+
{
|
| 178 |
+
$post = $this->getRequest()->getPost();
|
| 179 |
+
|
| 180 |
+
$config = Mage::helper('marketingsoftware/config');
|
| 181 |
+
|
| 182 |
+
$clientKey = $config->getClientKey();
|
| 183 |
+
|
| 184 |
+
$clientSecret = $config->getClientSecret();
|
| 185 |
+
|
| 186 |
+
if ($clientKey == $post['cp_client_key'] && $clientSecret == $post['cp_client_secret']) {
|
| 187 |
+
return $this->_redirect('*/*');
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
if (!isset($post['cp_client_key'])) {
|
| 191 |
+
return $this->_redirect('*/*');
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
$config->setClientKey($post['cp_client_key']);
|
| 195 |
+
$config->setClientSecret($post['cp_client_secret']);
|
| 196 |
+
$config->unsAccessToken();
|
| 197 |
+
|
| 198 |
+
Mage::getSingleton('core/session')->addSuccess('REST settings have been saved');
|
| 199 |
+
session_write_close(); // To make sure the success message is passed
|
| 200 |
+
|
| 201 |
+
return $this->_redirect('*/*');
|
| 202 |
+
}
|
| 203 |
}
|
app/code/community/Copernica/MarketingSoftware/controllers/Adminhtml/Marketingsoftware/SyncController.php
CHANGED
|
@@ -1,180 +1,180 @@
|
|
| 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 |
-
* Settings Controller, which takes care of the settings menu.
|
| 29 |
-
*
|
| 30 |
-
*/
|
| 31 |
-
class Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_SyncController extends Copernica_MarketingSoftware_Controller_Action
|
| 32 |
-
{
|
| 33 |
-
/**
|
| 34 |
-
* This action is a default one. Will be executed when user arrives on page.
|
| 35 |
-
*/
|
| 36 |
-
public function indexAction()
|
| 37 |
-
{
|
| 38 |
-
$this->loadLayout();
|
| 39 |
-
|
| 40 |
-
$this->_setActiveMenu('copernica');
|
| 41 |
-
|
| 42 |
-
$layout = $this->getLayout();
|
| 43 |
-
|
| 44 |
-
$contentBlock = $layout->getBlock('content');
|
| 45 |
-
|
| 46 |
-
$contentBlock->append($layout->createBlock('marketingsoftware/adminhtml_marketingsoftware_sync'));
|
| 47 |
-
|
| 48 |
-
$layout->getBlock('head')->setTitle($this->__('Settings / Copernica Marketing Software / Magento Admin'));
|
| 49 |
-
|
| 50 |
-
$this->renderLayout();
|
| 51 |
-
}
|
| 52 |
-
|
| 53 |
-
/**
|
| 54 |
-
* This action will update or create a sync profile with data received from
|
| 55 |
-
* user.
|
| 56 |
-
*/
|
| 57 |
-
public function postAction()
|
| 58 |
-
{
|
| 59 |
-
$post = $this->getRequest()->getPost();
|
| 60 |
-
|
| 61 |
-
$syncProfile = Mage::getModel('marketingsoftware/sync_profile');
|
| 62 |
-
|
| 63 |
-
if (array_key_exists('id', $post) && $post['id']) {
|
| 64 |
-
$syncProfile->load($post['id']);
|
| 65 |
-
}
|
| 66 |
-
|
| 67 |
-
$syncProfile
|
| 68 |
-
->setClientKey($post['client_key'])
|
| 69 |
-
->setClientSecret($post['client_secret'])
|
| 70 |
-
->setName($post['name'])
|
| 71 |
-
->save();
|
| 72 |
-
|
| 73 |
-
return $this->_redirect('*/*');
|
| 74 |
-
}
|
| 75 |
-
|
| 76 |
-
/**
|
| 77 |
-
* Get array of all stores available
|
| 78 |
-
*
|
| 79 |
-
* @return array
|
| 80 |
-
*/
|
| 81 |
-
protected function _getAvailableStores($profileId)
|
| 82 |
-
{
|
| 83 |
-
$stores = array();
|
| 84 |
-
|
| 85 |
-
foreach (Mage::app()->getWebsites() as $website) {
|
| 86 |
-
foreach ($website->getGroups() as $group) {
|
| 87 |
-
foreach ($group->getStores() as $store) {
|
| 88 |
-
$stores[$store->getId()] = implode(' > ', array(
|
| 89 |
-
$website->getName(),
|
| 90 |
-
$group->getName(),
|
| 91 |
-
$store->getName()
|
| 92 |
-
));
|
| 93 |
-
}
|
| 94 |
-
}
|
| 95 |
-
}
|
| 96 |
-
|
| 97 |
-
return $stores;
|
| 98 |
-
}
|
| 99 |
-
|
| 100 |
-
/**
|
| 101 |
-
* This action will take care of action that requies us to fetch data about
|
| 102 |
-
* a profile.
|
| 103 |
-
*/
|
| 104 |
-
public function getProfileAction()
|
| 105 |
-
{
|
| 106 |
-
$post = $this->getRequest()->getPost();
|
| 107 |
-
|
| 108 |
-
$this->getResponse()->setHeader('Content-Type', 'application/json');
|
| 109 |
-
|
| 110 |
-
if (array_key_exists('id', $post)) {
|
| 111 |
-
$profile = Mage::getModel('marketingsoftware/sync_profile')->load($post['id']);
|
| 112 |
-
|
| 113 |
-
$state = md5(Mage::getModel('adminhtml/session')->getEncryptedSessionId().date('dmY').$profile->getId());
|
| 114 |
-
|
| 115 |
-
$stores = $this->_getAvailableStores($post['id']);
|
| 116 |
-
|
| 117 |
-
$this->getResponse()->setBody(json_encode(array_merge($profile->toArray(), array('state' => $state, 'stores' => $stores))));
|
| 118 |
-
} else {
|
| 119 |
-
$this->getResponse()->setBody(json_encode('error'));
|
| 120 |
-
}
|
| 121 |
-
}
|
| 122 |
-
|
| 123 |
-
/**
|
| 124 |
-
* This action will handle removal of a profile.
|
| 125 |
-
*/
|
| 126 |
-
public function deleteAction()
|
| 127 |
-
{
|
| 128 |
-
$post = $this->getRequest()->getPost();
|
| 129 |
-
|
| 130 |
-
if (array_key_exists('id', $post)) {
|
| 131 |
-
Mage::getModel('marketingsoftware/sync_profile')
|
| 132 |
-
->load($post['id'])
|
| 133 |
-
->delete();
|
| 134 |
-
} else {
|
| 135 |
-
$this->getResponse()->setBody(json_encode('error'));
|
| 136 |
-
}
|
| 137 |
-
|
| 138 |
-
}
|
| 139 |
-
|
| 140 |
-
/**
|
| 141 |
-
* This action will handle finalization of sync profile. This action should
|
| 142 |
-
* be invoked only when user is returning from Copernica webpage with state
|
| 143 |
-
* and code as query parameters.
|
| 144 |
-
*/
|
| 145 |
-
public function stateAction()
|
| 146 |
-
{
|
| 147 |
-
$params = $this->getRequest()->getParams();
|
| 148 |
-
|
| 149 |
-
if (!array_key_exists('state', $params)) {
|
| 150 |
-
return $this->_redirect('*/*', array('result' => 'invalid-state'));
|
| 151 |
-
}
|
| 152 |
-
|
| 153 |
-
if (!array_key_exists('code', $params)) {
|
| 154 |
-
return $this->_redirect('*/*', array('result' => 'invalid-code'));
|
| 155 |
-
}
|
| 156 |
-
|
| 157 |
-
foreach (Mage::getModel('marketingsoftware/sync_profile')->getCollection() as $profile) {
|
| 158 |
-
if ($params['state'] != md5(Mage::getSingleton('adminhtml/session')->getEncryptedSessionId().date('dmY').$profile->getId())) {
|
| 159 |
-
continue;
|
| 160 |
-
}
|
| 161 |
-
|
| 162 |
-
$accessToken = Mage::helper('marketingsoftware/api')->upgradeRequest(
|
| 163 |
-
$profile->getClientKey(),
|
| 164 |
-
$profile->getClientSecret(),
|
| 165 |
-
$params['code'],
|
| 166 |
-
Mage::helper('adminhtml')->getUrl('*/*/state')
|
| 167 |
-
);
|
| 168 |
-
|
| 169 |
-
if ($accessToken == false) {
|
| 170 |
-
return $this->_redirect('*/*', array('result' => 'invalid-token'));
|
| 171 |
-
}
|
| 172 |
-
|
| 173 |
-
$profile->setAccessToken($accessToken)->save();
|
| 174 |
-
|
| 175 |
-
return $this->_redirect('*/*', array('result' => 'ok', 'profileId' => $profile->getId()));
|
| 176 |
-
}
|
| 177 |
-
|
| 178 |
-
return $this->_redirect('*/*', array('result' => 'invalid-state', 'profileId' => $profile->getId()));
|
| 179 |
-
}
|
| 180 |
-
}
|
| 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 |
+
* Settings Controller, which takes care of the settings menu.
|
| 29 |
+
*
|
| 30 |
+
*/
|
| 31 |
+
class Copernica_MarketingSoftware_Adminhtml_Marketingsoftware_SyncController extends Copernica_MarketingSoftware_Controller_Action
|
| 32 |
+
{
|
| 33 |
+
/**
|
| 34 |
+
* This action is a default one. Will be executed when user arrives on page.
|
| 35 |
+
*/
|
| 36 |
+
public function indexAction()
|
| 37 |
+
{
|
| 38 |
+
$this->loadLayout();
|
| 39 |
+
|
| 40 |
+
$this->_setActiveMenu('copernica');
|
| 41 |
+
|
| 42 |
+
$layout = $this->getLayout();
|
| 43 |
+
|
| 44 |
+
$contentBlock = $layout->getBlock('content');
|
| 45 |
+
|
| 46 |
+
$contentBlock->append($layout->createBlock('marketingsoftware/adminhtml_marketingsoftware_sync'));
|
| 47 |
+
|
| 48 |
+
$layout->getBlock('head')->setTitle($this->__('Settings / Copernica Marketing Software / Magento Admin'));
|
| 49 |
+
|
| 50 |
+
$this->renderLayout();
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
/**
|
| 54 |
+
* This action will update or create a sync profile with data received from
|
| 55 |
+
* user.
|
| 56 |
+
*/
|
| 57 |
+
public function postAction()
|
| 58 |
+
{
|
| 59 |
+
$post = $this->getRequest()->getPost();
|
| 60 |
+
|
| 61 |
+
$syncProfile = Mage::getModel('marketingsoftware/sync_profile');
|
| 62 |
+
|
| 63 |
+
if (array_key_exists('id', $post) && $post['id']) {
|
| 64 |
+
$syncProfile->load($post['id']);
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
$syncProfile
|
| 68 |
+
->setClientKey($post['client_key'])
|
| 69 |
+
->setClientSecret($post['client_secret'])
|
| 70 |
+
->setName($post['name'])
|
| 71 |
+
->save();
|
| 72 |
+
|
| 73 |
+
return $this->_redirect('*/*');
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
/**
|
| 77 |
+
* Get array of all stores available
|
| 78 |
+
*
|
| 79 |
+
* @return array
|
| 80 |
+
*/
|
| 81 |
+
protected function _getAvailableStores($profileId)
|
| 82 |
+
{
|
| 83 |
+
$stores = array();
|
| 84 |
+
|
| 85 |
+
foreach (Mage::app()->getWebsites() as $website) {
|
| 86 |
+
foreach ($website->getGroups() as $group) {
|
| 87 |
+
foreach ($group->getStores() as $store) {
|
| 88 |
+
$stores[$store->getId()] = implode(' > ', array(
|
| 89 |
+
$website->getName(),
|
| 90 |
+
$group->getName(),
|
| 91 |
+
$store->getName()
|
| 92 |
+
));
|
| 93 |
+
}
|
| 94 |
+
}
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
return $stores;
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
/**
|
| 101 |
+
* This action will take care of action that requies us to fetch data about
|
| 102 |
+
* a profile.
|
| 103 |
+
*/
|
| 104 |
+
public function getProfileAction()
|
| 105 |
+
{
|
| 106 |
+
$post = $this->getRequest()->getPost();
|
| 107 |
+
|
| 108 |
+
$this->getResponse()->setHeader('Content-Type', 'application/json');
|
| 109 |
+
|
| 110 |
+
if (array_key_exists('id', $post)) {
|
| 111 |
+
$profile = Mage::getModel('marketingsoftware/sync_profile')->load($post['id']);
|
| 112 |
+
|
| 113 |
+
$state = md5(Mage::getModel('adminhtml/session')->getEncryptedSessionId().date('dmY').$profile->getId());
|
| 114 |
+
|
| 115 |
+
$stores = $this->_getAvailableStores($post['id']);
|
| 116 |
+
|
| 117 |
+
$this->getResponse()->setBody(json_encode(array_merge($profile->toArray(), array('state' => $state, 'stores' => $stores))));
|
| 118 |
+
} else {
|
| 119 |
+
$this->getResponse()->setBody(json_encode('error'));
|
| 120 |
+
}
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
/**
|
| 124 |
+
* This action will handle removal of a profile.
|
| 125 |
+
*/
|
| 126 |
+
public function deleteAction()
|
| 127 |
+
{
|
| 128 |
+
$post = $this->getRequest()->getPost();
|
| 129 |
+
|
| 130 |
+
if (array_key_exists('id', $post)) {
|
| 131 |
+
Mage::getModel('marketingsoftware/sync_profile')
|
| 132 |
+
->load($post['id'])
|
| 133 |
+
->delete();
|
| 134 |
+
} else {
|
| 135 |
+
$this->getResponse()->setBody(json_encode('error'));
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
/**
|
| 141 |
+
* This action will handle finalization of sync profile. This action should
|
| 142 |
+
* be invoked only when user is returning from Copernica webpage with state
|
| 143 |
+
* and code as query parameters.
|
| 144 |
+
*/
|
| 145 |
+
public function stateAction()
|
| 146 |
+
{
|
| 147 |
+
$params = $this->getRequest()->getParams();
|
| 148 |
+
|
| 149 |
+
if (!array_key_exists('state', $params)) {
|
| 150 |
+
return $this->_redirect('*/*', array('result' => 'invalid-state'));
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
if (!array_key_exists('code', $params)) {
|
| 154 |
+
return $this->_redirect('*/*', array('result' => 'invalid-code'));
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
foreach (Mage::getModel('marketingsoftware/sync_profile')->getCollection() as $profile) {
|
| 158 |
+
if ($params['state'] != md5(Mage::getSingleton('adminhtml/session')->getEncryptedSessionId().date('dmY').$profile->getId())) {
|
| 159 |
+
continue;
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
$accessToken = Mage::helper('marketingsoftware/api')->upgradeRequest(
|
| 163 |
+
$profile->getClientKey(),
|
| 164 |
+
$profile->getClientSecret(),
|
| 165 |
+
$params['code'],
|
| 166 |
+
Mage::helper('adminhtml')->getUrl('*/*/state')
|
| 167 |
+
);
|
| 168 |
+
|
| 169 |
+
if ($accessToken == false) {
|
| 170 |
+
return $this->_redirect('*/*', array('result' => 'invalid-token'));
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
$profile->setAccessToken($accessToken)->save();
|
| 174 |
+
|
| 175 |
+
return $this->_redirect('*/*', array('result' => 'ok', 'profileId' => $profile->getId()));
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
return $this->_redirect('*/*', array('result' => 'invalid-state', 'profileId' => $profile->getId()));
|
| 179 |
+
}
|
| 180 |
+
}
|
app/code/community/Copernica/MarketingSoftware/controllers/ProductController.php
CHANGED
|
@@ -1,308 +1,308 @@
|
|
| 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 |
-
* Controls the product actions.
|
| 29 |
-
*/
|
| 30 |
-
class Copernica_MarketingSoftware_ProductController extends Mage_Core_Controller_Front_Action
|
| 31 |
-
{
|
| 32 |
-
/**
|
| 33 |
-
* The DOM document that will be used to return XML content.
|
| 34 |
-
*
|
| 35 |
-
* @var DOMDocument
|
| 36 |
-
*/
|
| 37 |
-
protected $_document;
|
| 38 |
-
|
| 39 |
-
/**
|
| 40 |
-
* Show one single product in result collection
|
| 41 |
-
*/
|
| 42 |
-
protected function _showProduct()
|
| 43 |
-
{
|
| 44 |
-
$request = $this->getRequest();
|
| 45 |
-
|
| 46 |
-
if ($request->getParam('identifier') == 'sku') {
|
| 47 |
-
$product = Mage::getModel('catalog/product')->loadByAttribute('sku', $request->getParam('id'));
|
| 48 |
-
} else {
|
| 49 |
-
$product = Mage::getModel('catalog/product')->load($request->getParam('id'));
|
| 50 |
-
}
|
| 51 |
-
|
| 52 |
-
if (!$product->getId()) {
|
| 53 |
-
return $this->norouteAction();
|
| 54 |
-
}
|
| 55 |
-
|
| 56 |
-
$productEntity = Mage::getModel('marketingsoftware/copernica_entity_product');
|
| 57 |
-
$productEntity->setProduct($product->getId());
|
| 58 |
-
|
| 59 |
-
$xml = $this->_buildProductXML($productEntity);
|
| 60 |
-
|
| 61 |
-
$this->_prepareResponse($xml);
|
| 62 |
-
}
|
| 63 |
-
|
| 64 |
-
/**
|
| 65 |
-
* This is a helper method to append simple nodes to document tree
|
| 66 |
-
*
|
| 67 |
-
* @param DOMElement $parent
|
| 68 |
-
* @param string $name
|
| 69 |
-
* @param mixed $value
|
| 70 |
-
*/
|
| 71 |
-
protected function _appendSimpleNode(DOMElement $parent, $name, $value)
|
| 72 |
-
{
|
| 73 |
-
$parent->appendChild($this->_document->createElement($name, htmlspecialchars(html_entity_decode((string)$value))));
|
| 74 |
-
}
|
| 75 |
-
|
| 76 |
-
/**
|
| 77 |
-
* Show whole collection of products
|
| 78 |
-
*/
|
| 79 |
-
protected function _showCollection()
|
| 80 |
-
{
|
| 81 |
-
$today = date('Y-m-d H:i:s');
|
| 82 |
-
|
| 83 |
-
$collection = Mage::getResourceModel('catalog/product_collection');
|
| 84 |
-
$collection->addAttributeToFilter('news_from_date', array (
|
| 85 |
-
'date' => true,
|
| 86 |
-
'to' => $today
|
| 87 |
-
));
|
| 88 |
-
$collection->addAttributeToFilter('news_to_date', array (
|
| 89 |
-
'or' => array (
|
| 90 |
-
array ('date' => true, 'from' => $todayDate),
|
| 91 |
-
array ('is' => new Zend_Db_Expr('null'))
|
| 92 |
-
), 'left'
|
| 93 |
-
));
|
| 94 |
-
$collection->addAttributeToSelect('id');
|
| 95 |
-
|
| 96 |
-
$xml = $this->_buildCollectionXML($collection);
|
| 97 |
-
|
| 98 |
-
$this->_prepareResponse($xml);
|
| 99 |
-
}
|
| 100 |
-
|
| 101 |
-
/**
|
| 102 |
-
* Prepare xml tree for one product instance.
|
| 103 |
-
*
|
| 104 |
-
* @param Copernica_MarketingSoftware_Model_Copernica_Entity_Product $product
|
| 105 |
-
* @param bool $noParents
|
| 106 |
-
* @param bool $noChildren
|
| 107 |
-
* @return DOMElement
|
| 108 |
-
*/
|
| 109 |
-
protected function _buildProductXML(Copernica_MarketingSoftware_Model_Copernica_Entity_Product $product, $noParents = false, $noChildren = false)
|
| 110 |
-
{
|
| 111 |
-
$element = $this->_document->createElement('product');
|
| 112 |
-
$element->setAttribute('xlink:href', Mage::getUrl('*/*/*', array ('id' => $product->getId())));
|
| 113 |
-
$element->setAttribute('xlink:title', 'Product details');
|
| 114 |
-
$element->setAttribute('xlink:type', 'resource');
|
| 115 |
-
$element->setAttribute('xlink:actuate', 'onRequest');
|
| 116 |
-
$element->setAttribute('xlink:show', 'new');
|
| 117 |
-
|
| 118 |
-
$this->_appendSimpleNode($element, 'id', $product->getProductId());
|
| 119 |
-
$this->_appendSimpleNode($element, 'sku', $product->getSku());
|
| 120 |
-
$this->_appendSimpleNode($element, 'name', $product->getName());
|
| 121 |
-
$this->_appendSimpleNode($element, 'description', $product->getDescription());
|
| 122 |
-
$this->_appendSimpleNode($element, 'modified', $product->getModified());
|
| 123 |
-
$this->_appendSimpleNode($element, 'created', $product->getCreated());
|
| 124 |
-
$this->_appendSimpleNode($element, 'productUrl', $product->getUrl());
|
| 125 |
-
$this->_appendSimpleNode($element, 'imageUrl', $product->getImage());
|
| 126 |
-
$this->_appendSimpleNode($element, 'thumbnailUrl', $product->getThumbnail());
|
| 127 |
-
$this->_appendSimpleNode($element, 'weight', $product->getWeight());
|
| 128 |
-
|
| 129 |
-
$value = Mage::helper('core')->currency($product->getPrice(), true, false);
|
| 130 |
-
$this->_appendSimpleNode($element, 'price', $value);
|
| 131 |
-
$value = Mage::helper('core')->currency($product->getSpecialPrice(), true, false);
|
| 132 |
-
$this->_appendSimpleNode($element, 'specialPrice', $value);
|
| 133 |
-
|
| 134 |
-
$this->_appendSimpleNode($element, 'isNew', $product->isNew() ? 'yes' : 'no');
|
| 135 |
-
|
| 136 |
-
$element->appendChild($this->_buildCategoriesXML($product));
|
| 137 |
-
$element->appendChild($this->_buildAttributesXML($product));
|
| 138 |
-
|
| 139 |
-
if (!$noParents) {
|
| 140 |
-
$element->appendChild($this->_buildParentsXML($product));
|
| 141 |
-
}
|
| 142 |
-
|
| 143 |
-
if (!$noChildren) {
|
| 144 |
-
$element->appendChild($this->_buildChildrenXML($product));
|
| 145 |
-
}
|
| 146 |
-
|
| 147 |
-
return $element;
|
| 148 |
-
}
|
| 149 |
-
|
| 150 |
-
/**
|
| 151 |
-
* Build product categories XML
|
| 152 |
-
*
|
| 153 |
-
* @param Copernica_MarketingSoftware_Model_Copernica_Entity_Product $product
|
| 154 |
-
* @return DOMElement
|
| 155 |
-
*/
|
| 156 |
-
protected function _buildCategoriesXML(Copernica_MarketingSoftware_Model_Copernica_Entity_Product $product)
|
| 157 |
-
{
|
| 158 |
-
$categories = $this->_document->createElement('categories');
|
| 159 |
-
|
| 160 |
-
foreach ($product->getCategoriesList() as $id => $category) {
|
| 161 |
-
$category = $this->_document->createElement('category', htmlspecialchars(html_entity_decode($category)));
|
| 162 |
-
$category->setAttribute('id', $id);
|
| 163 |
-
$categories->appendChild($category);
|
| 164 |
-
}
|
| 165 |
-
|
| 166 |
-
return $categories;
|
| 167 |
-
}
|
| 168 |
-
|
| 169 |
-
/**
|
| 170 |
-
* Build product attributes XML
|
| 171 |
-
*
|
| 172 |
-
* @param Copernica_MarketingSoftware_Model_Copernica_Entity_Product $product
|
| 173 |
-
* @return DOMElement
|
| 174 |
-
*/
|
| 175 |
-
protected function _buildAttributesXML(Copernica_MarketingSoftware_Model_Copernica_Entity_Product $product)
|
| 176 |
-
{
|
| 177 |
-
$attributes = $this->_document->createElement('attributes');
|
| 178 |
-
$attributes->setAttribute('name', $product->getAttributeSet());
|
| 179 |
-
|
| 180 |
-
foreach ($product->getAttributesList() as $attribute) {
|
| 181 |
-
$attrElem = $this->_document->createElement($attribute['code'], $attribute['value']);
|
| 182 |
-
$attrElem->setAttribute('type', $attribute['type']);
|
| 183 |
-
$attrElem->setAttribute('label', $attribute['label']);
|
| 184 |
-
|
| 185 |
-
$attributes->appendChild($attrElem);
|
| 186 |
-
}
|
| 187 |
-
|
| 188 |
-
return $attributes;
|
| 189 |
-
}
|
| 190 |
-
|
| 191 |
-
/**
|
| 192 |
-
* Build parents xml
|
| 193 |
-
*
|
| 194 |
-
* @param Copernica_MarketingSoftware_Model_Copernica_Entity_Product $product
|
| 195 |
-
* @return DOMElement
|
| 196 |
-
*/
|
| 197 |
-
protected function _buildParentsXML(Copernica_MarketingSoftware_Model_Copernica_Entity_Product $product)
|
| 198 |
-
{
|
| 199 |
-
$parentIds = $product->getNative()->getTypeInstance()->getParentIdsByChild($product->getId());
|
| 200 |
-
|
| 201 |
-
$parents = $this->_document->createElement('parents');
|
| 202 |
-
|
| 203 |
-
foreach ($parentIds as $id) {
|
| 204 |
-
$parents->appendChild($this->_buildProductXML(new Copernica_MarketingSoftware_Model_Copernica_Entity_Product($id), false, true));
|
| 205 |
-
}
|
| 206 |
-
|
| 207 |
-
return $parents;
|
| 208 |
-
}
|
| 209 |
-
|
| 210 |
-
/**
|
| 211 |
-
* Build children xml
|
| 212 |
-
*
|
| 213 |
-
* @param Copernica_MarketingSoftware_Model_Copernica_Entity_Product $product
|
| 214 |
-
* @return DOMElement
|
| 215 |
-
*/
|
| 216 |
-
protected function _buildChildrenXML(Copernica_MarketingSoftware_Model_Copernica_Entity_Product $product)
|
| 217 |
-
{
|
| 218 |
-
$childrenIds = $product->getNative()->getTypeInstance()->getChildrenIds($product->getId());
|
| 219 |
-
|
| 220 |
-
$children = $this->_document->createElement('children');
|
| 221 |
-
|
| 222 |
-
foreach ($childrenIds as $groupIds) {
|
| 223 |
-
$group = $this->_document->createElement('group');
|
| 224 |
-
|
| 225 |
-
foreach ($groupIds as $id ) {
|
| 226 |
-
$group->appendChild($this->_buildProductXML(new Copernica_MarketingSoftware_Model_Copernica_Entity_Product($id), true, false));
|
| 227 |
-
}
|
| 228 |
-
|
| 229 |
-
$children->appendChild($group);
|
| 230 |
-
}
|
| 231 |
-
|
| 232 |
-
return $children;
|
| 233 |
-
}
|
| 234 |
-
|
| 235 |
-
/**
|
| 236 |
-
* Prepare XML tree for whole collection of products.
|
| 237 |
-
*
|
| 238 |
-
* @param Mage_Catalog_Model_Resource_Product_Collection $collection
|
| 239 |
-
* @return DOMElement
|
| 240 |
-
*/
|
| 241 |
-
protected function _buildCollectionXML(Mage_Catalog_Model_Resource_Product_Collection $collection)
|
| 242 |
-
{
|
| 243 |
-
$element = $this->_buildRootElement();
|
| 244 |
-
|
| 245 |
-
foreach ($collection as $product) {
|
| 246 |
-
$element->appendChild($this->_buildProductXML(new Copernica_MarketingSoftware_Model_Copernica_Entity_Product($product->getId())));
|
| 247 |
-
}
|
| 248 |
-
|
| 249 |
-
return $element;
|
| 250 |
-
}
|
| 251 |
-
|
| 252 |
-
/**
|
| 253 |
-
* Prepare response based on passed element.
|
| 254 |
-
*
|
| 255 |
-
* @param DOMElement $element
|
| 256 |
-
*/
|
| 257 |
-
protected function _prepareResponse(DOMElement $element)
|
| 258 |
-
{
|
| 259 |
-
if ($element->tagName == 'product') {
|
| 260 |
-
$newRoot = $this->_buildRootElement();
|
| 261 |
-
$newRoot->appendChild($element);
|
| 262 |
-
|
| 263 |
-
$element = $newRoot;
|
| 264 |
-
}
|
| 265 |
-
|
| 266 |
-
$this->_document->appendChild($element);
|
| 267 |
-
|
| 268 |
-
$response = $this->getResponse();
|
| 269 |
-
$response->setHeader('Content-Type', 'text/xml', true);
|
| 270 |
-
$response->clearBody();
|
| 271 |
-
$response->sendHeaders();
|
| 272 |
-
$response->setBody($this->_document->saveXML());
|
| 273 |
-
}
|
| 274 |
-
|
| 275 |
-
/**
|
| 276 |
-
* Build a root element
|
| 277 |
-
*
|
| 278 |
-
* @return DOMElement
|
| 279 |
-
*/
|
| 280 |
-
protected function _buildRootElement()
|
| 281 |
-
{
|
| 282 |
-
$rootElement = $this->_document->createElement('products');
|
| 283 |
-
$rootElement->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:xlink', 'http://www.w3.org/1999/xlink');
|
| 284 |
-
|
| 285 |
-
return $rootElement;
|
| 286 |
-
}
|
| 287 |
-
|
| 288 |
-
/**
|
| 289 |
-
* Handles a request to copernica/product/xml
|
| 290 |
-
* Prints a XML with product information.
|
| 291 |
-
*/
|
| 292 |
-
public function xmlAction()
|
| 293 |
-
{
|
| 294 |
-
$request = $this->getRequest();
|
| 295 |
-
|
| 296 |
-
$this->_document = new DOMDocument('1.0', 'utf-8');
|
| 297 |
-
|
| 298 |
-
if ($request->getParam('new')) {
|
| 299 |
-
return $this->_showCollection();
|
| 300 |
-
}
|
| 301 |
-
|
| 302 |
-
if ($request->getParam('id')) {
|
| 303 |
-
return $this->_showProduct();
|
| 304 |
-
}
|
| 305 |
-
|
| 306 |
-
$this->norouteAction();
|
| 307 |
-
}
|
| 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 |
+
* Controls the product actions.
|
| 29 |
+
*/
|
| 30 |
+
class Copernica_MarketingSoftware_ProductController extends Mage_Core_Controller_Front_Action
|
| 31 |
+
{
|
| 32 |
+
/**
|
| 33 |
+
* The DOM document that will be used to return XML content.
|
| 34 |
+
*
|
| 35 |
+
* @var DOMDocument
|
| 36 |
+
*/
|
| 37 |
+
protected $_document;
|
| 38 |
+
|
| 39 |
+
/**
|
| 40 |
+
* Show one single product in result collection
|
| 41 |
+
*/
|
| 42 |
+
protected function _showProduct()
|
| 43 |
+
{
|
| 44 |
+
$request = $this->getRequest();
|
| 45 |
+
|
| 46 |
+
if ($request->getParam('identifier') == 'sku') {
|
| 47 |
+
$product = Mage::getModel('catalog/product')->loadByAttribute('sku', $request->getParam('id'));
|
| 48 |
+
} else {
|
| 49 |
+
$product = Mage::getModel('catalog/product')->load($request->getParam('id'));
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
if (!$product->getId()) {
|
| 53 |
+
return $this->norouteAction();
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
$productEntity = Mage::getModel('marketingsoftware/copernica_entity_product');
|
| 57 |
+
$productEntity->setProduct($product->getId());
|
| 58 |
+
|
| 59 |
+
$xml = $this->_buildProductXML($productEntity);
|
| 60 |
+
|
| 61 |
+
$this->_prepareResponse($xml);
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
/**
|
| 65 |
+
* This is a helper method to append simple nodes to document tree
|
| 66 |
+
*
|
| 67 |
+
* @param DOMElement $parent
|
| 68 |
+
* @param string $name
|
| 69 |
+
* @param mixed $value
|
| 70 |
+
*/
|
| 71 |
+
protected function _appendSimpleNode(DOMElement $parent, $name, $value)
|
| 72 |
+
{
|
| 73 |
+
$parent->appendChild($this->_document->createElement($name, htmlspecialchars(html_entity_decode((string)$value))));
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
/**
|
| 77 |
+
* Show whole collection of products
|
| 78 |
+
*/
|
| 79 |
+
protected function _showCollection()
|
| 80 |
+
{
|
| 81 |
+
$today = date('Y-m-d H:i:s');
|
| 82 |
+
|
| 83 |
+
$collection = Mage::getResourceModel('catalog/product_collection');
|
| 84 |
+
$collection->addAttributeToFilter('news_from_date', array (
|
| 85 |
+
'date' => true,
|
| 86 |
+
'to' => $today
|
| 87 |
+
));
|
| 88 |
+
$collection->addAttributeToFilter('news_to_date', array (
|
| 89 |
+
'or' => array (
|
| 90 |
+
array ('date' => true, 'from' => $todayDate),
|
| 91 |
+
array ('is' => new Zend_Db_Expr('null'))
|
| 92 |
+
), 'left'
|
| 93 |
+
));
|
| 94 |
+
$collection->addAttributeToSelect('id');
|
| 95 |
+
|
| 96 |
+
$xml = $this->_buildCollectionXML($collection);
|
| 97 |
+
|
| 98 |
+
$this->_prepareResponse($xml);
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
/**
|
| 102 |
+
* Prepare xml tree for one product instance.
|
| 103 |
+
*
|
| 104 |
+
* @param Copernica_MarketingSoftware_Model_Copernica_Entity_Product $product
|
| 105 |
+
* @param bool $noParents
|
| 106 |
+
* @param bool $noChildren
|
| 107 |
+
* @return DOMElement
|
| 108 |
+
*/
|
| 109 |
+
protected function _buildProductXML(Copernica_MarketingSoftware_Model_Copernica_Entity_Product $product, $noParents = false, $noChildren = false)
|
| 110 |
+
{
|
| 111 |
+
$element = $this->_document->createElement('product');
|
| 112 |
+
$element->setAttribute('xlink:href', Mage::getUrl('*/*/*', array ('id' => $product->getId())));
|
| 113 |
+
$element->setAttribute('xlink:title', 'Product details');
|
| 114 |
+
$element->setAttribute('xlink:type', 'resource');
|
| 115 |
+
$element->setAttribute('xlink:actuate', 'onRequest');
|
| 116 |
+
$element->setAttribute('xlink:show', 'new');
|
| 117 |
+
|
| 118 |
+
$this->_appendSimpleNode($element, 'id', $product->getProductId());
|
| 119 |
+
$this->_appendSimpleNode($element, 'sku', $product->getSku());
|
| 120 |
+
$this->_appendSimpleNode($element, 'name', $product->getName());
|
| 121 |
+
$this->_appendSimpleNode($element, 'description', $product->getDescription());
|
| 122 |
+
$this->_appendSimpleNode($element, 'modified', $product->getModified());
|
| 123 |
+
$this->_appendSimpleNode($element, 'created', $product->getCreated());
|
| 124 |
+
$this->_appendSimpleNode($element, 'productUrl', $product->getUrl());
|
| 125 |
+
$this->_appendSimpleNode($element, 'imageUrl', $product->getImage());
|
| 126 |
+
$this->_appendSimpleNode($element, 'thumbnailUrl', $product->getThumbnail());
|
| 127 |
+
$this->_appendSimpleNode($element, 'weight', $product->getWeight());
|
| 128 |
+
|
| 129 |
+
$value = Mage::helper('core')->currency($product->getPrice(), true, false);
|
| 130 |
+
$this->_appendSimpleNode($element, 'price', $value);
|
| 131 |
+
$value = Mage::helper('core')->currency($product->getSpecialPrice(), true, false);
|
| 132 |
+
$this->_appendSimpleNode($element, 'specialPrice', $value);
|
| 133 |
+
|
| 134 |
+
$this->_appendSimpleNode($element, 'isNew', $product->isNew() ? 'yes' : 'no');
|
| 135 |
+
|
| 136 |
+
$element->appendChild($this->_buildCategoriesXML($product));
|
| 137 |
+
$element->appendChild($this->_buildAttributesXML($product));
|
| 138 |
+
|
| 139 |
+
if (!$noParents) {
|
| 140 |
+
$element->appendChild($this->_buildParentsXML($product));
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
if (!$noChildren) {
|
| 144 |
+
$element->appendChild($this->_buildChildrenXML($product));
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
return $element;
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
/**
|
| 151 |
+
* Build product categories XML
|
| 152 |
+
*
|
| 153 |
+
* @param Copernica_MarketingSoftware_Model_Copernica_Entity_Product $product
|
| 154 |
+
* @return DOMElement
|
| 155 |
+
*/
|
| 156 |
+
protected function _buildCategoriesXML(Copernica_MarketingSoftware_Model_Copernica_Entity_Product $product)
|
| 157 |
+
{
|
| 158 |
+
$categories = $this->_document->createElement('categories');
|
| 159 |
+
|
| 160 |
+
foreach ($product->getCategoriesList() as $id => $category) {
|
| 161 |
+
$category = $this->_document->createElement('category', htmlspecialchars(html_entity_decode($category)));
|
| 162 |
+
$category->setAttribute('id', $id);
|
| 163 |
+
$categories->appendChild($category);
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
return $categories;
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
/**
|
| 170 |
+
* Build product attributes XML
|
| 171 |
+
*
|
| 172 |
+
* @param Copernica_MarketingSoftware_Model_Copernica_Entity_Product $product
|
| 173 |
+
* @return DOMElement
|
| 174 |
+
*/
|
| 175 |
+
protected function _buildAttributesXML(Copernica_MarketingSoftware_Model_Copernica_Entity_Product $product)
|
| 176 |
+
{
|
| 177 |
+
$attributes = $this->_document->createElement('attributes');
|
| 178 |
+
$attributes->setAttribute('name', $product->getAttributeSet());
|
| 179 |
+
|
| 180 |
+
foreach ($product->getAttributesList() as $attribute) {
|
| 181 |
+
$attrElem = $this->_document->createElement($attribute['code'], $attribute['value']);
|
| 182 |
+
$attrElem->setAttribute('type', $attribute['type']);
|
| 183 |
+
$attrElem->setAttribute('label', $attribute['label']);
|
| 184 |
+
|
| 185 |
+
$attributes->appendChild($attrElem);
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
return $attributes;
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
/**
|
| 192 |
+
* Build parents xml
|
| 193 |
+
*
|
| 194 |
+
* @param Copernica_MarketingSoftware_Model_Copernica_Entity_Product $product
|
| 195 |
+
* @return DOMElement
|
| 196 |
+
*/
|
| 197 |
+
protected function _buildParentsXML(Copernica_MarketingSoftware_Model_Copernica_Entity_Product $product)
|
| 198 |
+
{
|
| 199 |
+
$parentIds = $product->getNative()->getTypeInstance()->getParentIdsByChild($product->getId());
|
| 200 |
+
|
| 201 |
+
$parents = $this->_document->createElement('parents');
|
| 202 |
+
|
| 203 |
+
foreach ($parentIds as $id) {
|
| 204 |
+
$parents->appendChild($this->_buildProductXML(new Copernica_MarketingSoftware_Model_Copernica_Entity_Product($id), false, true));
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
return $parents;
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
/**
|
| 211 |
+
* Build children xml
|
| 212 |
+
*
|
| 213 |
+
* @param Copernica_MarketingSoftware_Model_Copernica_Entity_Product $product
|
| 214 |
+
* @return DOMElement
|
| 215 |
+
*/
|
| 216 |
+
protected function _buildChildrenXML(Copernica_MarketingSoftware_Model_Copernica_Entity_Product $product)
|
| 217 |
+
{
|
| 218 |
+
$childrenIds = $product->getNative()->getTypeInstance()->getChildrenIds($product->getId());
|
| 219 |
+
|
| 220 |
+
$children = $this->_document->createElement('children');
|
| 221 |
+
|
| 222 |
+
foreach ($childrenIds as $groupIds) {
|
| 223 |
+
$group = $this->_document->createElement('group');
|
| 224 |
+
|
| 225 |
+
foreach ($groupIds as $id ) {
|
| 226 |
+
$group->appendChild($this->_buildProductXML(new Copernica_MarketingSoftware_Model_Copernica_Entity_Product($id), true, false));
|
| 227 |
+
}
|
| 228 |
+
|
| 229 |
+
$children->appendChild($group);
|
| 230 |
+
}
|
| 231 |
+
|
| 232 |
+
return $children;
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
/**
|
| 236 |
+
* Prepare XML tree for whole collection of products.
|
| 237 |
+
*
|
| 238 |
+
* @param Mage_Catalog_Model_Resource_Product_Collection $collection
|
| 239 |
+
* @return DOMElement
|
| 240 |
+
*/
|
| 241 |
+
protected function _buildCollectionXML(Mage_Catalog_Model_Resource_Product_Collection $collection)
|
| 242 |
+
{
|
| 243 |
+
$element = $this->_buildRootElement();
|
| 244 |
+
|
| 245 |
+
foreach ($collection as $product) {
|
| 246 |
+
$element->appendChild($this->_buildProductXML(new Copernica_MarketingSoftware_Model_Copernica_Entity_Product($product->getId())));
|
| 247 |
+
}
|
| 248 |
+
|
| 249 |
+
return $element;
|
| 250 |
+
}
|
| 251 |
+
|
| 252 |
+
/**
|
| 253 |
+
* Prepare response based on passed element.
|
| 254 |
+
*
|
| 255 |
+
* @param DOMElement $element
|
| 256 |
+
*/
|
| 257 |
+
protected function _prepareResponse(DOMElement $element)
|
| 258 |
+
{
|
| 259 |
+
if ($element->tagName == 'product') {
|
| 260 |
+
$newRoot = $this->_buildRootElement();
|
| 261 |
+
$newRoot->appendChild($element);
|
| 262 |
+
|
| 263 |
+
$element = $newRoot;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
