Version Notes
Copernica - Version 3.2.2
Download this release
Release Info
Developer | Cream |
Extension | Copernica_MarketingSoftware |
Version | 3.2.2 |
Comparing to | |
See all releases |
Code changes from version 3.2.1 to 3.2.2
- app/code/community/Copernica/MarketingSoftware/Block/Adminhtml/Marketingsoftware/Accesstoken.php +60 -60
- app/code/community/Copernica/MarketingSoftware/Block/Adminhtml/Marketingsoftware/Export.php +71 -71
- app/code/community/Copernica/MarketingSoftware/Block/Adminhtml/Marketingsoftware/Link.php +81 -81
- app/code/community/Copernica/MarketingSoftware/Block/Adminhtml/Marketingsoftware/Settings.php +91 -91
- app/code/community/Copernica/MarketingSoftware/Block/Adminhtml/Marketingsoftware/Sync.php +118 -118
- app/code/community/Copernica/MarketingSoftware/Controller/Action.php +181 -181
- app/code/community/Copernica/MarketingSoftware/Exception.php +80 -80
- app/code/community/Copernica/MarketingSoftware/Helper/Api.php +1 -1
- app/code/community/Copernica/MarketingSoftware/Helper/Api/Abstract.php +431 -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 +1224 -1224
- app/code/community/Copernica/MarketingSoftware/Helper/Data.php +532 -532
- app/code/community/Copernica/MarketingSoftware/Helper/DataWriter.php +24 -24
- app/code/community/Copernica/MarketingSoftware/Helper/Profile.php +217 -217
- app/code/community/Copernica/MarketingSoftware/Helper/Rest/Request.php +363 -351
- app/code/community/Copernica/MarketingSoftware/Model/Abandoned/Cart.php +65 -65
- app/code/community/Copernica/MarketingSoftware/Model/Abandoned/Carts/Processor.php +129 -129
- app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Address.php +320 -320
- 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 +333 -333
- app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Product/Viewed.php +418 -418
- app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Quote.php +333 -333
- app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Quote/Item.php +212 -212
- app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Quote/Item/Options.php +163 -163
- app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Storeview.php +186 -186
- app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Subscription.php +179 -179
- app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Wishlist.php +369 -369
- app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Wishlist/Item.php +209 -209
- app/code/community/Copernica/MarketingSoftware/Model/Abstraction/Wishlist/Item/Options.php +163 -163
- app/code/community/Copernica/MarketingSoftware/Model/Abstraction/readme.txt +7 -0
- app/code/community/Copernica/MarketingSoftware/Model/AsyncPomSoapClient.php +295 -0
- app/code/community/Copernica/MarketingSoftware/Model/Config.php +64 -64
- app/code/community/Copernica/MarketingSoftware/Model/Copernica/Abstract.php +158 -158
- app/code/community/Copernica/MarketingSoftware/Model/Copernica/Address/Subprofile.php +104 -104
- app/code/community/Copernica/MarketingSoftware/Model/Copernica/Entity.php +82 -82
- app/code/community/Copernica/MarketingSoftware/Model/Copernica/Entity/Address.php +248 -248
- app/code/community/Copernica/MarketingSoftware/Model/Copernica/Entity/Customer.php +384 -384
- app/code/community/Copernica/MarketingSoftware/Model/Copernica/Entity/Order.php +364 -364
- app/code/community/Copernica/MarketingSoftware/Model/Copernica/Entity/Order/Item.php +200 -200
- app/code/community/Copernica/MarketingSoftware/Model/Copernica/Entity/Product.php +444 -444
- app/code/community/Copernica/MarketingSoftware/Model/Copernica/Entity/Quote.php +89 -89
- app/code/community/Copernica/MarketingSoftware/Model/Copernica/Entity/Quote/Item.php +93 -93
- app/code/community/Copernica/MarketingSoftware/Model/Copernica/Entity/Subscription.php +152 -152
- app/code/community/Copernica/MarketingSoftware/Model/Copernica/Entity/Wishlist.php +99 -99
- app/code/community/Copernica/MarketingSoftware/Model/Copernica/Entity/Wishlist/Item.php +155 -155
- app/code/community/Copernica/MarketingSoftware/Model/Copernica/Order/Subprofile.php +124 -124
- app/code/community/Copernica/MarketingSoftware/Model/Copernica/Orderitem/Subprofile.php +132 -132
- app/code/community/Copernica/MarketingSoftware/Model/Copernica/Product/Viewed/Subprofile.php +118 -118
- app/code/community/Copernica/MarketingSoftware/Model/Copernica/Profile.php +85 -85
- app/code/community/Copernica/MarketingSoftware/Model/Copernica/Profile/Customer.php +119 -119
- app/code/community/Copernica/MarketingSoftware/Model/Copernica/Profile/Order.php +125 -125
- app/code/community/Copernica/MarketingSoftware/Model/Copernica/Profile/Quote.php +129 -129
- app/code/community/Copernica/MarketingSoftware/Model/Copernica/Profile/Subscription.php +93 -93
- app/code/community/Copernica/MarketingSoftware/Model/Copernica/Quote/Item/Subprofile.php +151 -151
- app/code/community/Copernica/MarketingSoftware/Model/Copernica/Wishlist/Item/Subprofile.php +132 -132
- app/code/community/Copernica/MarketingSoftware/Model/Error.php +115 -0
- app/code/community/Copernica/MarketingSoftware/Model/Error/Queue.php +106 -106
- app/code/community/Copernica/MarketingSoftware/Model/Marketingsoftware.php +34 -0
- app/code/community/Copernica/MarketingSoftware/Model/Mysql4/Abandoned/Cart.php +39 -39
- app/code/community/Copernica/MarketingSoftware/Model/Mysql4/Abandoned/Cart/Collection.php +12 -12
- app/code/community/Copernica/MarketingSoftware/Model/Mysql4/Config.php +33 -33
- app/code/community/Copernica/MarketingSoftware/Model/Mysql4/Config/Collection.php +33 -33
- app/code/community/Copernica/MarketingSoftware/Model/Mysql4/Error/Queue.php +36 -36
- app/code/community/Copernica/MarketingSoftware/Model/Mysql4/Error/Queue/Collection.php +36 -36
- app/code/community/Copernica/MarketingSoftware/Model/Mysql4/Profile/Cache.php +39 -39
- app/code/community/Copernica/MarketingSoftware/Model/Mysql4/Profile/Cache/Collection.php +33 -33
- app/code/community/Copernica/MarketingSoftware/Model/Mysql4/Queue/Item.php +62 -62
- app/code/community/Copernica/MarketingSoftware/Model/Mysql4/Queue/Item/Collection.php +67 -67
- app/code/community/Copernica/MarketingSoftware/Model/Mysql4/Sync/Profile.php +36 -36
- app/code/community/Copernica/MarketingSoftware/Model/Mysql4/Sync/Profile/Collection.php +33 -33
- app/code/community/Copernica/MarketingSoftware/Model/Observer.php +1 -1
- app/code/community/Copernica/MarketingSoftware/Model/PomSoapClient.php +280 -0
- app/code/community/Copernica/MarketingSoftware/Model/Profile/Cache.php +83 -83
- app/code/community/Copernica/MarketingSoftware/Model/Queue/Event/Abstract.php +109 -109
- app/code/community/Copernica/MarketingSoftware/Model/Queue/Event/Checkout.php +114 -114
- app/code/community/Copernica/MarketingSoftware/Model/Queue/Event/Customer.php +140 -140
- app/code/community/Copernica/MarketingSoftware/Model/Queue/Event/Factory.php +96 -96
- app/code/community/Copernica/MarketingSoftware/Model/Queue/Event/Item.php +178 -178
- app/code/community/Copernica/MarketingSoftware/Model/Queue/Event/Order.php +159 -159
- app/code/community/Copernica/MarketingSoftware/Model/Queue/Event/Quote.php +98 -98
- app/code/community/Copernica/MarketingSoftware/Model/Queue/Event/Startsync.php +243 -243
- app/code/community/Copernica/MarketingSoftware/Model/Queue/Event/Subscription.php +96 -96
- app/code/community/Copernica/MarketingSoftware/Model/Queue/Event/View.php +57 -57
- app/code/community/Copernica/MarketingSoftware/Model/Queue/Event/Wishlist/Item.php +113 -113
- app/code/community/Copernica/MarketingSoftware/Model/Queue/Item.php +249 -249
- app/code/community/Copernica/MarketingSoftware/Model/Queue/Processor.php +243 -243
- app/code/community/Copernica/MarketingSoftware/Model/QueueEvent/FileSync.php +468 -0
- app/code/community/Copernica/MarketingSoftware/Model/Rest.php +126 -126
- app/code/community/Copernica/MarketingSoftware/Model/Rest/Address.php +113 -113
- app/code/community/Copernica/MarketingSoftware/Model/Rest/Customer.php +84 -84
- app/code/community/Copernica/MarketingSoftware/Model/Rest/Order.php +158 -158
- app/code/community/Copernica/MarketingSoftware/Model/Rest/Order/Item.php +126 -126
- app/code/community/Copernica/MarketingSoftware/Model/Rest/Product.php +95 -95
- app/code/community/Copernica/MarketingSoftware/Model/Rest/Quote.php +80 -80
- app/code/community/Copernica/MarketingSoftware/Model/Rest/Quote/Item.php +80 -80
- app/code/community/Copernica/MarketingSoftware/Model/Rest/Subscription.php +96 -96
- app/code/community/Copernica/MarketingSoftware/Model/Rest/Wishlist.php +70 -70
- app/code/community/Copernica/MarketingSoftware/Model/Rest/Wishlist/Item.php +80 -80
- app/code/community/Copernica/MarketingSoftware/Model/Sync/Profile.php +98 -198
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-2015 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-2015 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/Export.php
CHANGED
@@ -1,71 +1,71 @@
|
|
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-2015 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 Block
|
29 |
-
*
|
30 |
-
*/
|
31 |
-
class Copernica_MarketingSoftware_Block_Adminhtml_Marketingsoftware_Export extends Mage_Core_Block_Template
|
32 |
-
{
|
33 |
-
/**
|
34 |
-
* Constructor
|
35 |
-
*/
|
36 |
-
public function __construct()
|
37 |
-
{
|
38 |
-
parent::__construct();
|
39 |
-
$this->setTemplate('marketingsoftware/export.phtml');
|
40 |
-
}
|
41 |
-
|
42 |
-
/**
|
43 |
-
* Returns the iframe URL
|
44 |
-
*
|
45 |
-
* @return string
|
46 |
-
*/
|
47 |
-
public function getIframeUrl()
|
48 |
-
{
|
49 |
-
return $this->getUrl('*/*/progress', array('_secure' => true));
|
50 |
-
}
|
51 |
-
|
52 |
-
/**
|
53 |
-
* Returns the post URL
|
54 |
-
*
|
55 |
-
* @return string
|
56 |
-
*/
|
57 |
-
public function getPostUrl()
|
58 |
-
{
|
59 |
-
return $this->getUrl('*/*/get', array('_secure' => true));
|
60 |
-
}
|
61 |
-
|
62 |
-
/**
|
63 |
-
* Get url that will try to start data sync.
|
64 |
-
*
|
65 |
-
* @return string
|
66 |
-
*/
|
67 |
-
public function getDataUrl()
|
68 |
-
{
|
69 |
-
return $this->getUrl('*/*/dataSync', array('_secure' => true));
|
70 |
-
}
|
71 |
-
}
|
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-2015 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 Block
|
29 |
+
*
|
30 |
+
*/
|
31 |
+
class Copernica_MarketingSoftware_Block_Adminhtml_Marketingsoftware_Export extends Mage_Core_Block_Template
|
32 |
+
{
|
33 |
+
/**
|
34 |
+
* Constructor
|
35 |
+
*/
|
36 |
+
public function __construct()
|
37 |
+
{
|
38 |
+
parent::__construct();
|
39 |
+
$this->setTemplate('marketingsoftware/export.phtml');
|
40 |
+
}
|
41 |
+
|
42 |
+
/**
|
43 |
+
* Returns the iframe URL
|
44 |
+
*
|
45 |
+
* @return string
|
46 |
+
*/
|
47 |
+
public function getIframeUrl()
|
48 |
+
{
|
49 |
+
return $this->getUrl('*/*/progress', array('_secure' => true));
|
50 |
+
}
|
51 |
+
|
52 |
+
/**
|
53 |
+
* Returns the post URL
|
54 |
+
*
|
55 |
+
* @return string
|
56 |
+
*/
|
57 |
+
public function getPostUrl()
|
58 |
+
{
|
59 |
+
return $this->getUrl('*/*/get', array('_secure' => true));
|
60 |
+
}
|
61 |
+
|
62 |
+
/**
|
63 |
+
* Get url that will try to start data sync.
|
64 |
+
*
|
65 |
+
* @return string
|
66 |
+
*/
|
67 |
+
public function getDataUrl()
|
68 |
+
{
|
69 |
+
return $this->getUrl('*/*/dataSync', array('_secure' => true));
|
70 |
+
}
|
71 |
+
}
|
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-2015 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-2015 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/Settings.php
CHANGED
@@ -1,91 +1,91 @@
|
|
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-2015 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 Block
|
29 |
-
*/
|
30 |
-
class Copernica_MarketingSoftware_Block_Adminhtml_Marketingsoftware_Settings extends Mage_Core_Block_Template
|
31 |
-
{
|
32 |
-
/**
|
33 |
-
* Constructor
|
34 |
-
*
|
35 |
-
*/
|
36 |
-
public function __construct()
|
37 |
-
{
|
38 |
-
parent::__construct();
|
39 |
-
$this->setTemplate('marketingsoftware/settings.phtml');
|
40 |
-
}
|
41 |
-
|
42 |
-
/**
|
43 |
-
* Returns the post URL.
|
44 |
-
*
|
45 |
-
* @return string
|
46 |
-
*/
|
47 |
-
public function getPostUrl()
|
48 |
-
{
|
49 |
-
return $this->getUrl('*/*/send', array('_secure' => true));
|
50 |
-
}
|
51 |
-
|
52 |
-
/**
|
53 |
-
* Returns the state URL
|
54 |
-
*
|
55 |
-
* @return string
|
56 |
-
*/
|
57 |
-
public function getStateUrl()
|
58 |
-
{
|
59 |
-
return Mage::helper('adminhtml')->getUrl('*/*/state');
|
60 |
-
}
|
61 |
-
|
62 |
-
/**
|
63 |
-
* Returns the queue URL
|
64 |
-
*
|
65 |
-
* @return string
|
66 |
-
*/
|
67 |
-
public function getQueuePostUrl()
|
68 |
-
{
|
69 |
-
return Mage::helper('adminhtml')->getUrl('*/*/queue');
|
70 |
-
}
|
71 |
-
|
72 |
-
/**
|
73 |
-
* Returns the stores URL
|
74 |
-
*
|
75 |
-
* @return string
|
76 |
-
*/
|
77 |
-
public function getStoresPostUrl()
|
78 |
-
{
|
79 |
-
return Mage::helper('adminhtml')->getUrl('*/*/stores');
|
80 |
-
}
|
81 |
-
|
82 |
-
/**
|
83 |
-
* Access token form url
|
84 |
-
*
|
85 |
-
* @return string
|
86 |
-
*/
|
87 |
-
public function getAccessTokenUrl()
|
88 |
-
{
|
89 |
-
return Mage::helper('adminhtml')->getUrl('*/marketingsoftware_accessToken/index');
|
90 |
-
}
|
91 |
-
}
|
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-2015 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 Block
|
29 |
+
*/
|
30 |
+
class Copernica_MarketingSoftware_Block_Adminhtml_Marketingsoftware_Settings extends Mage_Core_Block_Template
|
31 |
+
{
|
32 |
+
/**
|
33 |
+
* Constructor
|
34 |
+
*
|
35 |
+
*/
|
36 |
+
public function __construct()
|
37 |
+
{
|
38 |
+
parent::__construct();
|
39 |
+
$this->setTemplate('marketingsoftware/settings.phtml');
|
40 |
+
}
|
41 |
+
|
42 |
+
/**
|
43 |
+
* Returns the post URL.
|
44 |
+
*
|
45 |
+
* @return string
|
46 |
+
*/
|
47 |
+
public function getPostUrl()
|
48 |
+
{
|
49 |
+
return $this->getUrl('*/*/send', array('_secure' => true));
|
50 |
+
}
|
51 |
+
|
52 |
+
/**
|
53 |
+
* Returns the state URL
|
54 |
+
*
|
55 |
+
* @return string
|
56 |
+
*/
|
57 |
+
public function getStateUrl()
|
58 |
+
{
|
59 |
+
return Mage::helper('adminhtml')->getUrl('*/*/state');
|
60 |
+
}
|
61 |
+
|
62 |
+
/**
|
63 |
+
* Returns the queue URL
|
64 |
+
*
|
65 |
+
* @return string
|
66 |
+
*/
|
67 |
+
public function getQueuePostUrl()
|
68 |
+
{
|
69 |
+
return Mage::helper('adminhtml')->getUrl('*/*/queue');
|
70 |
+
}
|
71 |
+
|
72 |
+
/**
|
73 |
+
* Returns the stores URL
|
74 |
+
*
|
75 |
+
* @return string
|
76 |
+
*/
|
77 |
+
public function getStoresPostUrl()
|
78 |
+
{
|
79 |
+
return Mage::helper('adminhtml')->getUrl('*/*/stores');
|
80 |
+
}
|
81 |
+
|
82 |
+
/**
|
83 |
+
* Access token form url
|
84 |
+
*
|
85 |
+
* @return string
|
86 |
+
*/
|
87 |
+
public function getAccessTokenUrl()
|
88 |
+
{
|
89 |
+
return Mage::helper('adminhtml')->getUrl('*/marketingsoftware_accessToken/index');
|
90 |
+
}
|
91 |
+
}
|
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-2015 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-2015 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-2015 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-2015 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-2015 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-2015 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.php
CHANGED
@@ -295,7 +295,7 @@ class Copernica_MarketingSoftware_Helper_Api extends Copernica_MarketingSoftware
|
|
295 |
$this->_restRequest()->put(
|
296 |
'profile/'.$profileID.'/subprofiles/'.$collectionId, $data->toArray(), array(
|
297 |
'fields[]' => 'id=='.$data->id(),
|
298 |
-
'create' => 'true'
|
299 |
)
|
300 |
);
|
301 |
}
|
295 |
$this->_restRequest()->put(
|
296 |
'profile/'.$profileID.'/subprofiles/'.$collectionId, $data->toArray(), array(
|
297 |
'fields[]' => 'id=='.$data->id(),
|
298 |
+
'create' => 'true'
|
299 |
)
|
300 |
);
|
301 |
}
|
app/code/community/Copernica/MarketingSoftware/Helper/Api/Abstract.php
CHANGED
@@ -1,427 +1,431 @@
|
|
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-2015 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 |
-
$
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
if (
|
400 |
-
return false;
|
401 |
-
}
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
*
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
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-2015 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 |
+
if (!isset($customerLinkedFields['email']) || !isset($customerLinkedFields['storeView'])) {
|
389 |
+
return false;
|
390 |
+
}
|
391 |
+
|
392 |
+
$requestParams = array(
|
393 |
+
$customerLinkedFields['email'].'=='.$email,
|
394 |
+
$customerLinkedFields['storeView'].'=='.$storeView
|
395 |
+
);
|
396 |
+
|
397 |
+
$profiles = $this->_restRequest()->get('database/'.$this->getDatabaseId().'/profiles', array ( 'fields' => $requestParams ));
|
398 |
+
|
399 |
+
if (!isset($profiles['data'][0])) {
|
400 |
+
return false;
|
401 |
+
}
|
402 |
+
|
403 |
+
if (is_null($profiles['data'][0]['ID']) || (int)$profiles['data'][0]['ID'] == 0) {
|
404 |
+
return false;
|
405 |
+
}
|
406 |
+
|
407 |
+
return $profiles['data'][0]['ID'];
|
408 |
+
}
|
409 |
+
|
410 |
+
/**
|
411 |
+
* Get profile Id from cache
|
412 |
+
*
|
413 |
+
* @todo not used, why??
|
414 |
+
* @param string $customerId
|
415 |
+
* @return int
|
416 |
+
*/
|
417 |
+
protected function _getProfileIdFromCache($customerId)
|
418 |
+
{
|
419 |
+
$profileCache = Mage::getModel('marketingsoftware/profile_cache')
|
420 |
+
->getCollection()
|
421 |
+
->addFieldToFilter('customer_id', $customerId)
|
422 |
+
->setPageSize(1)
|
423 |
+
->getFirstItem();
|
424 |
+
|
425 |
+
$profileId = $profileCache->getProfileId();
|
426 |
+
|
427 |
+
if (!is_null($profileId)) {
|
428 |
+
return $profileId;
|
429 |
+
}
|
430 |
+
}
|
431 |
+
}
|
app/code/community/Copernica/MarketingSoftware/Helper/Api/Builder.php
CHANGED
@@ -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-2015 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-2015 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-2015 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-2015 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-2015 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-2015 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-2015 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-2015 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/DataWriter.php
CHANGED
@@ -1,27 +1,27 @@
|
|
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-2015 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 |
/**
|
@@ -217,4 +217,4 @@ class Copernica_MarketingSoftware_Helper_Datawriter
|
|
217 |
{
|
218 |
$this->_write($profile);
|
219 |
}
|
220 |
-
}
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* Copernica Marketing Software
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0).
|
8 |
+
* It is available through the world-wide-web at this URL:
|
9 |
+
* http://opensource.org/licenses/osl-3.0.php
|
10 |
+
* If you are unable to obtain a copy of the license through the
|
11 |
+
* world-wide-web, please send an email to copernica@support.cream.nl
|
12 |
+
* so we can send you a copy immediately.
|
13 |
+
*
|
14 |
+
* DISCLAIMER
|
15 |
+
*
|
16 |
+
* Do not edit or add to this file if you wish to upgrade this software
|
17 |
+
* to newer versions in the future. If you wish to customize this module
|
18 |
+
* for your needs please refer to http://www.magento.com/ for more
|
19 |
+
* information.
|
20 |
+
*
|
21 |
+
* @category Copernica
|
22 |
+
* @package Copernica_MarketingSoftware
|
23 |
+
* @copyright Copyright (c) 2011-2015 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 |
/**
|
217 |
{
|
218 |
$this->_write($profile);
|
219 |
}
|
220 |
+
}
|
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-2015 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-2015 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,351 +1,363 @@
|
|
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 |
-
// Sometimes ssl gives problems so the verification is off.
|
146 |
-
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
|
147 |
-
|
148 |
-
return $curl;
|
149 |
-
}
|
150 |
-
|
151 |
-
/**
|
152 |
-
* Make a GET requst
|
153 |
-
*
|
154 |
-
* @param string $request
|
155 |
-
* @param assoc $data
|
156 |
-
* @return assoc
|
157 |
-
*/
|
158 |
-
public function get($request, $data = null)
|
159 |
-
{
|
160 |
-
$curl = $this->_prepareCurl();
|
161 |
-
|
162 |
-
if ($this->_accessToken) {
|
163 |
-
$request.=$this->_buildQueryString(array_merge(array(
|
164 |
-
'access_token' => $this->_accessToken),
|
165 |
-
is_null($data) ? array() : $data
|
166 |
-
));
|
167 |
-
} else {
|
168 |
-
$request.=$this->_buildQueryString(is_null($data) ? array() : $data);
|
169 |
-
}
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
*
|
186 |
-
*
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
)
|
205 |
-
curl_setopt($curl,
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
)
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
// Sometimes ssl gives problems so the verification is off.
|
146 |
+
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
|
147 |
+
|
148 |
+
return $curl;
|
149 |
+
}
|
150 |
+
|
151 |
+
/**
|
152 |
+
* Make a GET requst
|
153 |
+
*
|
154 |
+
* @param string $request
|
155 |
+
* @param assoc $data
|
156 |
+
* @return assoc
|
157 |
+
*/
|
158 |
+
public function get($request, $data = null)
|
159 |
+
{
|
160 |
+
$curl = $this->_prepareCurl();
|
161 |
+
|
162 |
+
if ($this->_accessToken) {
|
163 |
+
$request.=$this->_buildQueryString(array_merge(array(
|
164 |
+
'access_token' => $this->_accessToken),
|
165 |
+
is_null($data) ? array() : $data
|
166 |
+
));
|
167 |
+
} else {
|
168 |
+
$request.=$this->_buildQueryString(is_null($data) ? array() : $data);
|
169 |
+
}
|
170 |
+
|
171 |
+
// Check to remove unnecessary slashes from the request
|
172 |
+
$request = ltrim($request, '/');
|
173 |
+
|
174 |
+
curl_setopt($curl, CURLOPT_URL, $this->_hostname.'/'.$request);
|
175 |
+
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
176 |
+
|
177 |
+
$output = json_decode(curl_exec($curl), true);
|
178 |
+
|
179 |
+
curl_close($curl);
|
180 |
+
|
181 |
+
return $output;
|
182 |
+
}
|
183 |
+
|
184 |
+
/**
|
185 |
+
* Make a POST request
|
186 |
+
*
|
187 |
+
* @param string $request
|
188 |
+
* @param assoc $data
|
189 |
+
* @param assoc $query
|
190 |
+
*/
|
191 |
+
public function post($request, $data = null, $query = null)
|
192 |
+
{
|
193 |
+
if (is_array($query)) {
|
194 |
+
$request.= $this->_buildQueryString(array_merge( $query, array('access_token' => $this->_accessToken) ));
|
195 |
+
} else {
|
196 |
+
$request.='?access_token='.$this->_accessToken;
|
197 |
+
}
|
198 |
+
|
199 |
+
$curl = $this->_prepareCurl();
|
200 |
+
|
201 |
+
// Check to remove unnecessary slashes from the request
|
202 |
+
$request = ltrim($request, '/');
|
203 |
+
|
204 |
+
curl_setopt($curl, CURLOPT_URL, $this->_hostname.'/'.$request);
|
205 |
+
curl_setopt($curl, CURLOPT_POST, true);
|
206 |
+
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
|
207 |
+
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
|
208 |
+
'content-type: application/json',
|
209 |
+
'accept: application/json'
|
210 |
+
));
|
211 |
+
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
|
212 |
+
|
213 |
+
if ($this->_appendMulti($curl)) {
|
214 |
+
return true;
|
215 |
+
}
|
216 |
+
|
217 |
+
curl_exec($curl);
|
218 |
+
|
219 |
+
curl_close($curl);
|
220 |
+
|
221 |
+
return true;
|
222 |
+
}
|
223 |
+
|
224 |
+
/**
|
225 |
+
* Make a PUT request
|
226 |
+
*
|
227 |
+
* @param string $request
|
228 |
+
* @param assoc $data
|
229 |
+
* @param assoc $query
|
230 |
+
*/
|
231 |
+
public function put($request, $data = null, $query = null)
|
232 |
+
{
|
233 |
+
if (is_array($query)) {
|
234 |
+
$request.= $this->_buildQueryString(array_merge( $query, array('access_token' => $this->_accessToken) ));
|
235 |
+
} else {
|
236 |
+
$request.='?access_token='.$this->_accessToken;
|
237 |
+
}
|
238 |
+
|
239 |
+
$curl = $this->_prepareCurl();
|
240 |
+
|
241 |
+
// Check to remove unnecessary slashes from the request
|
242 |
+
$request = ltrim($request, '/');
|
243 |
+
|
244 |
+
curl_setopt($curl, CURLOPT_URL, $this->_hostname.'/'.$request);
|
245 |
+
curl_setopt($curl, CURLOPT_POST, true);
|
246 |
+
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
|
247 |
+
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
|
248 |
+
'content-type: application/json',
|
249 |
+
'accept: application/json'
|
250 |
+
));
|
251 |
+
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
|
252 |
+
// curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
253 |
+
|
254 |
+
if ($this->_appendMulti($curl)) {
|
255 |
+
return true;
|
256 |
+
}
|
257 |
+
|
258 |
+
curl_exec($curl);
|
259 |
+
|
260 |
+
curl_close($curl);
|
261 |
+
|
262 |
+
return true;
|
263 |
+
}
|
264 |
+
|
265 |
+
/**
|
266 |
+
* Make a DELETE request
|
267 |
+
*
|
268 |
+
* @param string $request
|
269 |
+
* @param assoc $data
|
270 |
+
*/
|
271 |
+
public function delete($request, $data = null)
|
272 |
+
{
|
273 |
+
$curl = $this->_prepareCurl();
|
274 |
+
|
275 |
+
$request.='?access_token='.$this->_accessToken;
|
276 |
+
|
277 |
+
// Check to remove unnecessary slashes from the request
|
278 |
+
$request = ltrim($request, '/');
|
279 |
+
|
280 |
+
curl_setopt($curl, CURLOPT_URL, $this->_hostname.'/'.$request);
|
281 |
+
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");
|
282 |
+
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
|
283 |
+
'content-type: application/json',
|
284 |
+
'accept: application/json'
|
285 |
+
));
|
286 |
+
|
287 |
+
if ($this->_appendMulti($curl)) {
|
288 |
+
return true;
|
289 |
+
}
|
290 |
+
|
291 |
+
curl_exec($curl);
|
292 |
+
|
293 |
+
curl_close($curl);
|
294 |
+
|
295 |
+
return true;
|
296 |
+
}
|
297 |
+
|
298 |
+
/**
|
299 |
+
* This method will start preparing calls to execute them later on with
|
300 |
+
* 'multi' interface.
|
301 |
+
*/
|
302 |
+
public function prepare()
|
303 |
+
{
|
304 |
+
$this->_multi = curl_multi_init();
|
305 |
+
|
306 |
+
return $this;
|
307 |
+
}
|
308 |
+
|
309 |
+
/**
|
310 |
+
* Commit all prepared calls
|
311 |
+
*/
|
312 |
+
public function commit()
|
313 |
+
{
|
314 |
+
$active = true;
|
315 |
+
|
316 |
+
if (is_null($this->_multi)) {
|
317 |
+
return $this;
|
318 |
+
}
|
319 |
+
|
320 |
+
do {
|
321 |
+
while (CURLM_CALL_MULTI_PERFORM === curl_multi_exec($this->_multi, $running));
|
322 |
+
if (!$running) {
|
323 |
+
break;
|
324 |
+
}
|
325 |
+
|
326 |
+
while (($res = curl_multi_select($this->_multi)) === 0){};
|
327 |
+
|
328 |
+
if ($res === false) {
|
329 |
+
break;
|
330 |
+
}
|
331 |
+
} while(true);
|
332 |
+
|
333 |
+
foreach ($this->_children as $child) {
|
334 |
+
curl_multi_remove_handle($this->_multi, $child);
|
335 |
+
}
|
336 |
+
|
337 |
+
curl_multi_close($this->_multi);
|
338 |
+
|
339 |
+
$this->_multi = null;
|
340 |
+
|
341 |
+
return $this;
|
342 |
+
}
|
343 |
+
|
344 |
+
/**
|
345 |
+
* Append another curl request to multi interface
|
346 |
+
*/
|
347 |
+
protected function _appendMulti($curl)
|
348 |
+
{
|
349 |
+
if (!is_resource($this->_multi)) {
|
350 |
+
return false;
|
351 |
+
}
|
352 |
+
|
353 |
+
$code = curl_multi_add_handle($this->_multi, $curl);
|
354 |
+
|
355 |
+
if ($code == 0) {
|
356 |
+
$this->_children[] = $curl;
|
357 |
+
|
358 |
+
return true;
|
359 |
+
}
|
360 |
+
|
361 |
+
return false;
|
362 |
+
}
|
363 |
+
}
|
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-2015 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-2015 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-2015 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-2015 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-2015 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-2015 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-2015 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-2015 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-2015 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-2015 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-2015 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-2015 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-2015 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-2015 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-2015 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-2015 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-2015 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-2015 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-2015 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-2015 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-2015 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-2015 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-2015 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-2015 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,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-2015 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 |
-
|
316 |
-
/**
|
317 |
-
* Unserialize the object
|
318 |
-
*
|
319 |
-
* @todo Two returns??
|
320 |
-
* @param string $string
|
321 |
-
* @return Copernica_MarketingSoftware_Model_Abstraction_Quote
|
322 |
-
*/
|
323 |
-
public function unserialize($string)
|
324 |
-
{
|
325 |
-
list (
|
326 |
-
$this->_quoteId
|
327 |
-
) = unserialize($string);
|
328 |
-
|
329 |
-
$this->loadQuote($this->_quoteId);
|
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-2015 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 |
+
|
316 |
+
/**
|
317 |
+
* Unserialize the object
|
318 |
+
*
|
319 |
+
* @todo Two returns??
|
320 |
+
* @param string $string
|
321 |
+
* @return Copernica_MarketingSoftware_Model_Abstraction_Quote
|
322 |
+
*/
|
323 |
+
public function unserialize($string)
|
324 |
+
{
|
325 |
+
list (
|
326 |
+
$this->_quoteId
|
327 |
+
) = unserialize($string);
|
328 |
+
|
329 |
+
$this->loadQuote($this->_quoteId);
|
330 |
+
|
331 |
+
return $this;
|
332 |
+
}
|
333 |
+
}
|
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-2015 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-2015 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-2015 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-2015 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-2015 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-2015 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-2015 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-2015 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-2015 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-2015 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-2015 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-2015 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-2015 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-2015 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/Abstraction/readme.txt
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Note:
|
2 |
+
To ensure compatibility with Magento, Mage::getModel is used to load classes.
|
3 |
+
However, the Abstraction classes (and possibly other classes) do not extend
|
4 |
+
Mage_Core_Model_Abstract as documented in the getModel function's return type.
|
5 |
+
Extending this class would result in unnecessary overhead.
|
6 |
+
If you do encounter problems with model loading in future versions of Magento,
|
7 |
+
please check the getModel function in app/Mage.php.
|
app/code/community/Copernica/MarketingSoftware/Model/AsyncPomSoapClient.php
ADDED
@@ -0,0 +1,295 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Asynchronous SOAP api client.
|
4 |
+
* This is an extension to the normal soap client, because it can run multiple
|
5 |
+
* calls at the same time. It differs from the normal PomSoapClient class because
|
6 |
+
* the PxPomSoapClient::methodToCall() method does not return the result, but
|
7 |
+
* a handle that can be queried to see if it has already returned data.
|
8 |
+
*
|
9 |
+
* Example use:
|
10 |
+
*
|
11 |
+
* $client = new PomAsyncSoapClient($url, $login, $account, $password);
|
12 |
+
* $req1 = $client->someSoapMethod(...);
|
13 |
+
* $req2 = $client->someSoapMethod(...);
|
14 |
+
* $req3 = $client->someSoapMethod(...);
|
15 |
+
* $answer1 = $client->result($req1);
|
16 |
+
* $answer2 = $client->result($req2);
|
17 |
+
* $answer3 = $client->result($req3);
|
18 |
+
*/
|
19 |
+
class Copernica_MarketingSoftware_Model_AsyncPomSoapClient extends Copernica_MarketingSoftware_Model_PomSoapClient
|
20 |
+
{
|
21 |
+
/**
|
22 |
+
* The curl multi handle
|
23 |
+
* @var resource
|
24 |
+
*/
|
25 |
+
private $curl = false;
|
26 |
+
|
27 |
+
/**
|
28 |
+
* Set of pending requests ID's
|
29 |
+
* This is an assoc array: request ID maps to a array with handle and request
|
30 |
+
* @var array
|
31 |
+
*/
|
32 |
+
private $pending = array();
|
33 |
+
|
34 |
+
/**
|
35 |
+
* Set of requests for which the answer has been received
|
36 |
+
* This is an assoc array: request ID maps to the received answer
|
37 |
+
* @var array
|
38 |
+
*/
|
39 |
+
private $completed = array();
|
40 |
+
|
41 |
+
/**
|
42 |
+
* The last assigned request ID
|
43 |
+
* @var integer
|
44 |
+
*/
|
45 |
+
private $freeID = 0;
|
46 |
+
|
47 |
+
/**
|
48 |
+
* Name of the cookie file
|
49 |
+
* @var string
|
50 |
+
*/
|
51 |
+
private $cookies = false;
|
52 |
+
|
53 |
+
/**
|
54 |
+
* Is the object currently busy parsing an async answer?
|
55 |
+
* @var resource CURL resource identifier of the request that is internally processed
|
56 |
+
*/
|
57 |
+
private $internalRequest = false;
|
58 |
+
|
59 |
+
|
60 |
+
/**
|
61 |
+
* Destructor
|
62 |
+
*/
|
63 |
+
public function __destruct()
|
64 |
+
{
|
65 |
+
// skip if no calls were made
|
66 |
+
if (!$this->cookies) return;
|
67 |
+
|
68 |
+
// wait until everything is ready
|
69 |
+
$this->run();
|
70 |
+
|
71 |
+
// remove the cookie file
|
72 |
+
//unlink($this->cookies);
|
73 |
+
|
74 |
+
// close the connections
|
75 |
+
if(is_resource($this->curl)) curl_multi_close($this->curl);
|
76 |
+
}
|
77 |
+
|
78 |
+
/**
|
79 |
+
* Method returns the ID's of all requests, both the pending ones and the
|
80 |
+
* ones that have already been completed
|
81 |
+
* @return array of int
|
82 |
+
*/
|
83 |
+
public function allRequests()
|
84 |
+
{
|
85 |
+
return array_merge($this->pendingRequests(), $this->completedRequests());
|
86 |
+
}
|
87 |
+
|
88 |
+
/**
|
89 |
+
* Method to retrieve the ID's of all pending requests
|
90 |
+
* @return array
|
91 |
+
*/
|
92 |
+
public function pendingRequests()
|
93 |
+
{
|
94 |
+
return array_keys($this->pending);
|
95 |
+
}
|
96 |
+
|
97 |
+
/**
|
98 |
+
* Method to retrieve the ID's of all completed requests
|
99 |
+
* @return array
|
100 |
+
*/
|
101 |
+
public function completedRequests()
|
102 |
+
{
|
103 |
+
return array_keys($this->completed);
|
104 |
+
}
|
105 |
+
|
106 |
+
/**
|
107 |
+
* Get the result of a certain request
|
108 |
+
* This method will block until the request has been completed
|
109 |
+
* @param integer ID of a request
|
110 |
+
* @return mixed The response from the request
|
111 |
+
*/
|
112 |
+
public function result($requestID)
|
113 |
+
{
|
114 |
+
// if this a request for which the result was already found
|
115 |
+
if (isset($this->completed[$requestID])) return $this->completed[$requestID];
|
116 |
+
|
117 |
+
// skip if an invalid ID was supplied
|
118 |
+
if (!isset($this->pending[$requestID])) return false;
|
119 |
+
|
120 |
+
// wait for the next call
|
121 |
+
$this->wait();
|
122 |
+
|
123 |
+
// fetch the result (with recursion)
|
124 |
+
return $this->result($requestID);
|
125 |
+
}
|
126 |
+
|
127 |
+
/**
|
128 |
+
* Wait for the next pending request to complete
|
129 |
+
* This method will block until a SOAP call completes
|
130 |
+
* It returns the request ID of the soap call that completed
|
131 |
+
* @param float Timeout in seconds
|
132 |
+
* @return integer The ID of the request that was completed
|
133 |
+
*/
|
134 |
+
public function wait($timeout = 1.0)
|
135 |
+
{
|
136 |
+
// not possible when nothing is pending
|
137 |
+
if (count($this->pending) == 0) return false;
|
138 |
+
|
139 |
+
// exec the connections
|
140 |
+
$active = null;
|
141 |
+
while(($execrun = curl_multi_exec($this->curl, $active)) == CURLM_CALL_MULTI_PERFORM) { /* do nothing */ }
|
142 |
+
|
143 |
+
// run a select call to wait for a connection to become ready
|
144 |
+
$ready = curl_multi_select($this->curl, $timeout);
|
145 |
+
|
146 |
+
// find all requests that are ready
|
147 |
+
while ($info = curl_multi_info_read($this->curl))
|
148 |
+
{
|
149 |
+
// find the request ID
|
150 |
+
$requestID = $this->resource2id($info['handle']);
|
151 |
+
$info = $this->pending[$requestID];
|
152 |
+
|
153 |
+
// make an internal call to find the answer
|
154 |
+
$this->internalRequest = $info['handle'];
|
155 |
+
$answer = $this->__call($info['method'], $info['params']);
|
156 |
+
$this->internalRequest = false;
|
157 |
+
|
158 |
+
// we have the answer
|
159 |
+
$this->completed[$requestID] = $answer;
|
160 |
+
|
161 |
+
// request is no longer pending
|
162 |
+
unset($this->pending[$requestID]);
|
163 |
+
|
164 |
+
// resource is no longer busy
|
165 |
+
curl_multi_remove_handle($this->curl, $info['handle']);
|
166 |
+
curl_close($info['handle']);
|
167 |
+
|
168 |
+
// done
|
169 |
+
return $requestID;
|
170 |
+
}
|
171 |
+
|
172 |
+
// not found
|
173 |
+
return false;
|
174 |
+
}
|
175 |
+
|
176 |
+
/**
|
177 |
+
* Run all requests
|
178 |
+
* This method will process all requests, until none of them is pending
|
179 |
+
*/
|
180 |
+
public function run()
|
181 |
+
{
|
182 |
+
// keep waiting until all requests are completed
|
183 |
+
while (count($this->pending) > 0) $this->wait();
|
184 |
+
}
|
185 |
+
|
186 |
+
/**
|
187 |
+
* Helper method to map a curl resource to a request ID
|
188 |
+
* @param resource CURL resource
|
189 |
+
* @return integer Request ID
|
190 |
+
*/
|
191 |
+
private function resource2id($resource)
|
192 |
+
{
|
193 |
+
// loop through all pending requests
|
194 |
+
foreach ($this->pending as $request => $data)
|
195 |
+
{
|
196 |
+
// compare ID's
|
197 |
+
if ($data['handle'] == $resource) return $request;
|
198 |
+
}
|
199 |
+
|
200 |
+
// not found
|
201 |
+
return false;
|
202 |
+
}
|
203 |
+
|
204 |
+
/**
|
205 |
+
* Overridden implementation of the __doRequest call. This method filters
|
206 |
+
* all calls, and adds them to the set of pending calls.
|
207 |
+
* @param string SOAP XML string to send to the server
|
208 |
+
* @param string URL to connect to
|
209 |
+
* @param string The SOAP action
|
210 |
+
* @param integer The SOAP version
|
211 |
+
* @param integer One way traffic, no result is expected
|
212 |
+
*/
|
213 |
+
public function __doRequest($request, $location, $action, $version, $one_way = 0)
|
214 |
+
{
|
215 |
+
// is this an internal request, in that case we have already started the
|
216 |
+
// connection, and only need to fetch the data
|
217 |
+
if ($this->internalRequest) return curl_multi_getcontent($this->internalRequest);
|
218 |
+
|
219 |
+
// create a new curl resource
|
220 |
+
$curl = curl_init($location);
|
221 |
+
|
222 |
+
// do we already have a cookie file?
|
223 |
+
if (!$this->cookies) $this->cookies = Mage::getBaseDir('tmp') .'copernica.tmp';
|
224 |
+
|
225 |
+
// set all options for it
|
226 |
+
curl_setopt_array($curl, array(
|
227 |
+
CURLOPT_POST => true,
|
228 |
+
CURLOPT_RETURNTRANSFER => true,
|
229 |
+
CURLOPT_COOKIEFILE => $this->cookies,
|
230 |
+
CURLOPT_COOKIEJAR => $this->cookies,
|
231 |
+
CURLOPT_POSTFIELDS => $request,
|
232 |
+
));
|
233 |
+
|
234 |
+
// find the method name
|
235 |
+
$methodName = preg_match('/#(.*)$/', $action, $matches) ? $matches[1] : '';
|
236 |
+
|
237 |
+
// is this a call that should be done immediately, and not asynchronous?
|
238 |
+
if (in_array($methodName, array('login')))
|
239 |
+
{
|
240 |
+
// the login call should not be postponed
|
241 |
+
return curl_exec($curl);
|
242 |
+
}
|
243 |
+
else
|
244 |
+
{
|
245 |
+
// do we a resource for multiple connections?
|
246 |
+
if (!$this->curl) $this->curl = curl_multi_init();
|
247 |
+
|
248 |
+
// add the curl handle
|
249 |
+
curl_multi_add_handle($this->curl, $curl);
|
250 |
+
|
251 |
+
// store the handle in the array of pending requests
|
252 |
+
$this->pending[$this->freeID] = array(
|
253 |
+
'handle' => $curl,
|
254 |
+
);
|
255 |
+
|
256 |
+
// return the handle
|
257 |
+
return $this->freeID++;
|
258 |
+
}
|
259 |
+
}
|
260 |
+
|
261 |
+
/**
|
262 |
+
* Method that handles the calls to the API
|
263 |
+
* @param string Name of the method
|
264 |
+
* @param array Associative array of parameters
|
265 |
+
* @return mixed
|
266 |
+
*/
|
267 |
+
public function __call($methodname, $params)
|
268 |
+
{
|
269 |
+
// get all current pending requests
|
270 |
+
$pending = $this->pendingRequests();
|
271 |
+
|
272 |
+
try
|
273 |
+
{
|
274 |
+
// make the call
|
275 |
+
$result = parent::__call($methodname, $params);
|
276 |
+
return $result;
|
277 |
+
}
|
278 |
+
catch (Exception $e)
|
279 |
+
{
|
280 |
+
// do we have a new pending request
|
281 |
+
$newPending = array_values(array_diff($this->pendingRequests(), $pending));
|
282 |
+
if (count($newPending) < 1) return false;
|
283 |
+
|
284 |
+
// we have the request ID
|
285 |
+
$requestID = $newPending[0];
|
286 |
+
|
287 |
+
// we must add the methodname and parameters to the internal data structure
|
288 |
+
$this->pending[$requestID]['method'] = $methodname;
|
289 |
+
$this->pending[$requestID]['params'] = $params;
|
290 |
+
|
291 |
+
// return the result
|
292 |
+
return $requestID;
|
293 |
+
}
|
294 |
+
}
|
295 |
+
}
|
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-2015 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-2015 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/Abstract.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-2015 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 |
-
abstract class Copernica_MarketingSoftware_Model_Copernica_Abstract implements ArrayAccess
|
31 |
-
{
|
32 |
-
/**
|
33 |
-
* To where data will be saved? Posible values are 'copernica' and 'magento'
|
34 |
-
*
|
35 |
-
* @var String
|
36 |
-
*/
|
37 |
-
protected $_direction = 'copernica';
|
38 |
-
|
39 |
-
/**
|
40 |
-
* Set the direction for this synchronisation
|
41 |
-
*
|
42 |
-
* @param string $direction
|
43 |
-
* @return Copernica_MarketingSoftware_Model_Copernica_Orderitem_Subprofile
|
44 |
-
*/
|
45 |
-
public function setDirection($direction)
|
46 |
-
{
|
47 |
-
$this->_direction = $direction;
|
48 |
-
|
49 |
-
return $this;
|
50 |
-
}
|
51 |
-
|
52 |
-
/**
|
53 |
-
* Return the identifier for this profile
|
54 |
-
*
|
55 |
-
* @return string
|
56 |
-
*/
|
57 |
-
abstract public function id();
|
58 |
-
|
59 |
-
/**
|
60 |
-
* Retrieve the data for this object
|
61 |
-
*
|
62 |
-
* @return array
|
63 |
-
*/
|
64 |
-
abstract protected function _data();
|
65 |
-
|
66 |
-
/**
|
67 |
-
* Get linked fields
|
68 |
-
*
|
69 |
-
* @return array
|
70 |
-
*/
|
71 |
-
abstract public function linkedFields();
|
72 |
-
|
73 |
-
/**
|
74 |
-
* Get the required fields
|
75 |
-
*
|
76 |
-
* @return array
|
77 |
-
*/
|
78 |
-
abstract public function requiredFields();
|
79 |
-
|
80 |
-
/**
|
81 |
-
* Check if offset exists in array
|
82 |
-
*
|
83 |
-
* @param mixed $offset
|
84 |
-
* @return boolean
|
85 |
-
*/
|
86 |
-
public function offsetExists($offset)
|
87 |
-
{
|
88 |
-
$data = $this->toArray();
|
89 |
-
|
90 |
-
return isset($data[$offset]);
|
91 |
-
}
|
92 |
-
|
93 |
-
/**
|
94 |
-
* Get offset in array
|
95 |
-
*
|
96 |
-
* @param mixed $offset
|
97 |
-
* @return mixed
|
98 |
-
*/
|
99 |
-
public function offsetGet($offset)
|
100 |
-
{
|
101 |
-
$data = $this->toArray();
|
102 |
-
|
103 |
-
return isset($data[$offset]) ? $data[$offset] : null;
|
104 |
-
}
|
105 |
-
|
106 |
-
/**
|
107 |
-
* Convert the data to an array for usage in SOAP
|
108 |
-
*
|
109 |
-
* @return array
|
110 |
-
*/
|
111 |
-
public function toArray()
|
112 |
-
{
|
113 |
-
$data = $this->_data();
|
114 |
-
|
115 |
-
if ($this->_direction == 'magento') {
|
116 |
-
return $data;
|
117 |
-
}
|
118 |
-
|
119 |
-
$returndata = array();
|
120 |
-
|
121 |
-
foreach ($this->requiredFields() as $field) {
|
122 |
-
$returndata[$field] = $data[$field];
|
123 |
-
}
|
124 |
-
|
125 |
-
foreach ($this->linkedFields() as $magentoField => $copernicaField) {
|
126 |
-
if (empty($copernicaField) || !isset($data[$magentoField])) {
|
127 |
-
continue;
|
128 |
-
}
|
129 |
-
|
130 |
-
$returndata[$copernicaField] = $data[$magentoField];
|
131 |
-
}
|
132 |
-
|
133 |
-
return $returndata;
|
134 |
-
}
|
135 |
-
|
136 |
-
/**
|
137 |
-
* Set entry in offset of array
|
138 |
-
*
|
139 |
-
* @deprecated
|
140 |
-
* @param mixed $offset
|
141 |
-
* @param mixed $value
|
142 |
-
*/
|
143 |
-
public function offsetSet($offset, $value)
|
144 |
-
{
|
145 |
-
return;
|
146 |
-
}
|
147 |
-
|
148 |
-
/**
|
149 |
-
* Remove entry by offset in array
|
150 |
-
*
|
151 |
-
* @deprecated
|
152 |
-
* @param mixed $offset
|
153 |
-
*/
|
154 |
-
public function offsetUnset($offset)
|
155 |
-
{
|
156 |
-
return;
|
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-2015 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 |
+
abstract class Copernica_MarketingSoftware_Model_Copernica_Abstract implements ArrayAccess
|
31 |
+
{
|
32 |
+
/**
|
33 |
+
* To where data will be saved? Posible values are 'copernica' and 'magento'
|
34 |
+
*
|
35 |
+
* @var String
|
36 |
+
*/
|
37 |
+
protected $_direction = 'copernica';
|
38 |
+
|
39 |
+
/**
|
40 |
+
* Set the direction for this synchronisation
|
41 |
+
*
|
42 |
+
* @param string $direction
|
43 |
+
* @return Copernica_MarketingSoftware_Model_Copernica_Orderitem_Subprofile
|
44 |
+
*/
|
45 |
+
public function setDirection($direction)
|
46 |
+
{
|
47 |
+
$this->_direction = $direction;
|
48 |
+
|
49 |
+
return $this;
|
50 |
+
}
|
51 |
+
|
52 |
+
/**
|
53 |
+
* Return the identifier for this profile
|
54 |
+
*
|
55 |
+
* @return string
|
56 |
+
*/
|
57 |
+
abstract public function id();
|
58 |
+
|
59 |
+
/**
|
60 |
+
* Retrieve the data for this object
|
61 |
+
*
|
62 |
+
* @return array
|
63 |
+
*/
|
64 |
+
abstract protected function _data();
|
65 |
+
|
66 |
+
/**
|
67 |
+
* Get linked fields
|
68 |
+
*
|
69 |
+
* @return array
|
70 |
+
*/
|
71 |
+
abstract public function linkedFields();
|
72 |
+
|
73 |
+
/**
|
74 |
+
* Get the required fields
|
75 |
+
*
|
76 |
+
* @return array
|
77 |
+
*/
|
78 |
+
abstract public function requiredFields();
|
79 |
+
|
80 |
+
/**
|
81 |
+
* Check if offset exists in array
|
82 |
+
*
|
83 |
+
* @param mixed $offset
|
84 |
+
* @return boolean
|
85 |
+
*/
|
86 |
+
public function offsetExists($offset)
|
87 |
+
{
|
88 |
+
$data = $this->toArray();
|
89 |
+
|
90 |
+
return isset($data[$offset]);
|
91 |
+
}
|
92 |
+
|
93 |
+
/**
|
94 |
+
* Get offset in array
|
95 |
+
*
|
96 |
+
* @param mixed $offset
|
97 |
+
* @return mixed
|
98 |
+
*/
|
99 |
+
public function offsetGet($offset)
|
100 |
+
{
|
101 |
+
$data = $this->toArray();
|
102 |
+
|
103 |
+
return isset($data[$offset]) ? $data[$offset] : null;
|
104 |
+
}
|
105 |
+
|
106 |
+
/**
|
107 |
+
* Convert the data to an array for usage in SOAP
|
108 |
+
*
|
109 |
+
* @return array
|
110 |
+
*/
|
111 |
+
public function toArray()
|
112 |
+
{
|
113 |
+
$data = $this->_data();
|
114 |
+
|
115 |
+
if ($this->_direction == 'magento') {
|
116 |
+
return $data;
|
117 |
+
}
|
118 |
+
|
119 |
+
$returndata = array();
|
120 |
+
|
121 |
+
foreach ($this->requiredFields() as $field) {
|
122 |
+
$returndata[$field] = $data[$field];
|
123 |
+
}
|
124 |
+
|
125 |
+
foreach ($this->linkedFields() as $magentoField => $copernicaField) {
|
126 |
+
if (empty($copernicaField) || !isset($data[$magentoField])) {
|
127 |
+
continue;
|
128 |
+
}
|
129 |
+
|
130 |
+
$returndata[$copernicaField] = $data[$magentoField];
|
131 |
+
}
|
132 |
+
|
133 |
+
return $returndata;
|
134 |
+
}
|
135 |
+
|
136 |
+
/**
|
137 |
+
* Set entry in offset of array
|
138 |
+
*
|
139 |
+
* @deprecated
|
140 |
+
* @param mixed $offset
|
141 |
+
* @param mixed $value
|
142 |
+
*/
|
143 |
+
public function offsetSet($offset, $value)
|
144 |
+
{
|
145 |
+
return;
|
146 |
+
}
|
147 |
+
|
148 |
+
/**
|
149 |
+
* Remove entry by offset in array
|
150 |
+
*
|
151 |
+
* @deprecated
|
152 |
+
* @param mixed $offset
|
153 |
+
*/
|
154 |
+
public function offsetUnset($offset)
|
155 |
+
{
|
156 |
+
return;
|
157 |
+
}
|
158 |
+
}
|
app/code/community/Copernica/MarketingSoftware/Model/Copernica/Address/Subprofile.php
CHANGED
@@ -1,104 +1,104 @@
|
|
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-2015 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_Address_Subprofile extends Copernica_MarketingSoftware_Model_Copernica_Abstract
|
31 |
-
{
|
32 |
-
/**
|
33 |
-
* Return the identifier for this profile
|
34 |
-
*
|
35 |
-
* @return string
|
36 |
-
*/
|
37 |
-
public function id()
|
38 |
-
{
|
39 |
-
return $this['address_id'];
|
40 |
-
}
|
41 |
-
|
42 |
-
/**
|
43 |
-
* Try to store a quote item
|
44 |
-
*
|
45 |
-
* @param Copernica_MarketingSoftware_Model_Abstraction_Address $address
|
46 |
-
*/
|
47 |
-
public function setAddress($address)
|
48 |
-
{
|
49 |
-
$this->address = $address;
|
50 |
-
|
51 |
-
return $this;
|
52 |
-
}
|
53 |
-
|
54 |
-
/**
|
55 |
-
* Get linked fields
|
56 |
-
*
|
57 |
-
* @return array
|
58 |
-
*/
|
59 |
-
public function linkedFields()
|
60 |
-
{
|
61 |
-
return Mage::helper('marketingsoftware/config')->getLinkedAddressFields();
|
62 |
-
}
|
63 |
-
|
64 |
-
/**
|
65 |
-
* Get the required fields
|
66 |
-
*
|
67 |
-
* @return array
|
68 |
-
*/
|
69 |
-
public function requiredFields()
|
70 |
-
{
|
71 |
-
return array('address_id');
|
72 |
-
}
|
73 |
-
|
74 |
-
/**
|
75 |
-
* Retrieve the data for this object
|
76 |
-
*
|
77 |
-
* @return array
|
78 |
-
*/
|
79 |
-
protected function _data()
|
80 |
-
{
|
81 |
-
if (($email = $this->address->email()) == "" && is_object($customer = $this->address->customer())) {
|
82 |
-
$email = $customer->email();
|
83 |
-
}
|
84 |
-
|
85 |
-
$name = $this->address->name();
|
86 |
-
|
87 |
-
return array(
|
88 |
-
'address_id' => $this->address->id(),
|
89 |
-
'firstname' => is_object($name) ? $name->firstname() : null,
|
90 |
-
'prefix' => is_object($name) ? $name->prefix() : null,
|
91 |
-
'middlename' => is_object($name) ? $name->middlename() : null,
|
92 |
-
'lastname' => is_object($name) ? $name->lastname() : null,
|
93 |
-
'email' => $email,
|
94 |
-
'company' => $this->address->company(),
|
95 |
-
'street' => $this->address->street(),
|
96 |
-
'city' => $this->address->city(),
|
97 |
-
'state' => $this->address->state(),
|
98 |
-
'zipcode' => $this->address->zipcode(),
|
99 |
-
'country_id' => $this->address->countryId(),
|
100 |
-
'telephone' => $this->address->telephone(),
|
101 |
-
'fax' => $this->address->fax(),
|
102 |
-
);
|
103 |
-
}
|
104 |
-
}
|
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-2015 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_Address_Subprofile extends Copernica_MarketingSoftware_Model_Copernica_Abstract
|
31 |
+
{
|
32 |
+
/**
|
33 |
+
* Return the identifier for this profile
|
34 |
+
*
|
35 |
+
* @return string
|
36 |
+
*/
|
37 |
+
public function id()
|
38 |
+
{
|
39 |
+
return $this['address_id'];
|
40 |
+
}
|
41 |
+
|
42 |
+
/**
|
43 |
+
* Try to store a quote item
|
44 |
+
*
|
45 |
+
* @param Copernica_MarketingSoftware_Model_Abstraction_Address $address
|
46 |
+
*/
|
47 |
+
public function setAddress($address)
|
48 |
+
{
|
49 |
+
$this->address = $address;
|
50 |
+
|
51 |
+
return $this;
|
52 |
+
}
|
53 |
+
|
54 |
+
/**
|
55 |
+
* Get linked fields
|
56 |
+
*
|
57 |
+
* @return array
|
58 |
+
*/
|
59 |
+
public function linkedFields()
|
60 |
+
{
|
61 |
+
return Mage::helper('marketingsoftware/config')->getLinkedAddressFields();
|
62 |
+
}
|
63 |
+
|
64 |
+
/**
|
65 |
+
* Get the required fields
|
66 |
+
*
|
67 |
+
* @return array
|
68 |
+
*/
|
69 |
+
public function requiredFields()
|
70 |
+
{
|
71 |
+
return array('address_id');
|
72 |
+
}
|
73 |
+
|
74 |
+
/**
|
75 |
+
* Retrieve the data for this object
|
76 |
+
*
|
77 |
+
* @return array
|
78 |
+
*/
|
79 |
+
protected function _data()
|
80 |
+
{
|
81 |
+
if (($email = $this->address->email()) == "" && is_object($customer = $this->address->customer())) {
|
82 |
+
$email = $customer->email();
|
83 |
+
}
|
84 |
+
|
85 |
+
$name = $this->address->name();
|
86 |
+
|
87 |
+
return array(
|
88 |
+
'address_id' => $this->address->id(),
|
89 |
+
'firstname' => is_object($name) ? $name->firstname() : null,
|
90 |
+
'prefix' => is_object($name) ? $name->prefix() : null,
|
91 |
+
'middlename' => is_object($name) ? $name->middlename() : null,
|
92 |
+
'lastname' => is_object($name) ? $name->lastname() : null,
|
93 |
+
'email' => $email,
|
94 |
+
'company' => $this->address->company(),
|
95 |
+
'street' => $this->address->street(),
|
96 |
+
'city' => $this->address->city(),
|
97 |
+
'state' => $this->address->state(),
|
98 |
+
'zipcode' => $this->address->zipcode(),
|
99 |
+
'country_id' => $this->address->countryId(),
|
100 |
+
'telephone' => $this->address->telephone(),
|
101 |
+
'fax' => $this->address->fax(),
|
102 |
+
);
|
103 |
+
}
|
104 |
+
}
|
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-2015 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-2015 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-2015 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-2015 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-2015 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-2015 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-2015 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->
|
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-2015 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->getAllItems() 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,200 +1,200 @@
|
|
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-2015 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 |
-
} elseif ($this->_orderItem->getQuoteId()) {
|
126 |
-
return Mage::getModel('sales/quote')->loadByIdWithoutStore($this->_orderItem->getQuoteId())->getStoreId();
|
127 |
-
} else {
|
128 |
-
throw new Exception(Mage::helper('marketingsoftware')->__("Could not load store id from quote."));
|
129 |
-
}
|
130 |
-
} elseif ($this->_orderItem instanceof Mage_Sales_Model_Order_Item) {
|
131 |
-
return $this->_orderItem->getOrder()->getStoreId();
|
132 |
-
}
|
133 |
-
|
134 |
-
return 0;
|
135 |
-
}
|
136 |
-
|
137 |
-
/**
|
138 |
-
* Fetch sales rules
|
139 |
-
*
|
140 |
-
* @return string
|
141 |
-
*/
|
142 |
-
public function fetchSalesRules()
|
143 |
-
{
|
144 |
-
return $this->_orderItem->getAppliedRuleIds();
|
145 |
-
}
|
146 |
-
|
147 |
-
/**
|
148 |
-
* Options can be nested so this function will allow us to parse them in recursive manner.
|
149 |
-
*
|
150 |
-
* @param mixed $values
|
151 |
-
* @param string $prefix
|
152 |
-
* @return string
|
153 |
-
*/
|
154 |
-
protected function _stringifyOptions($values, $prefix = '')
|
155 |
-
{
|
156 |
-
$result = '';
|
157 |
-
|
158 |
-
foreach ($values as $value) {
|
159 |
-
if (is_array($value['value'])) {
|
160 |
-
if (isset($value['value'][0]) && count($value['value']) == 1) {
|
161 |
-
$value['value'] = $value['value'][0];
|
162 |
-
}
|
163 |
-
|
164 |
-
$result .= $prefix.$value['label'].":\n".$this->_stringifyOptions($value['value'], $prefix.' ');
|
165 |
-
} else {
|
166 |
-
$result .= $prefix.$value['label'].":".$value['value']."\n";
|
167 |
-
}
|
168 |
-
}
|
169 |
-
|
170 |
-
return $result;
|
171 |
-
}
|
172 |
-
|
173 |
-
/**
|
174 |
-
* Get REST order item entity
|
175 |
-
*
|
176 |
-
* @return Copernica_MarketingSoftware_Model_Rest_Order_Item
|
177 |
-
*/
|
178 |
-
public function getRestOrderItem()
|
179 |
-
{
|
180 |
-
$restOrderItem = Mage::getModel('marketingsoftware/rest_order_item');
|
181 |
-
$restOrderItem->setOrderItemEntity($this);
|
182 |
-
|
183 |
-
return $restOrderItem;
|
184 |
-
}
|
185 |
-
|
186 |
-
/**
|
187 |
-
* Set copernica order item
|
188 |
-
*
|
189 |
-
* @param Mage_Sales_Model_Order_Item|Mage_Sales_Model_Quote_Item $orderItem
|
190 |
-
*/
|
191 |
-
public function setOrderItem($orderItem)
|
192 |
-
{
|
193 |
-
if ($orderItem->getId()) {
|
194 |
-
$this->_orderItem = $orderItem;
|
195 |
-
$this->setProduct($orderItem->getProductId(), $this->getStoreId());
|
196 |
-
} else {
|
197 |
-
throw new Exception(Mage::helper('marketingsoftware')->__('Set an empty quote item or order item object.'));
|
198 |
-
}
|
199 |
-
}
|
200 |
-
}
|
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-2015 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 |
+
} elseif ($this->_orderItem->getQuoteId()) {
|
126 |
+
return Mage::getModel('sales/quote')->loadByIdWithoutStore($this->_orderItem->getQuoteId())->getStoreId();
|
127 |
+
} else {
|
128 |
+
throw new Exception(Mage::helper('marketingsoftware')->__("Could not load store id from quote."));
|
129 |
+
}
|
130 |
+
} elseif ($this->_orderItem instanceof Mage_Sales_Model_Order_Item) {
|
131 |
+
return $this->_orderItem->getOrder()->getStoreId();
|
132 |
+
}
|
133 |
+
|
134 |
+
return 0;
|
135 |
+
}
|
136 |
+
|
137 |
+
/**
|
138 |
+
* Fetch sales rules
|
139 |
+
*
|
140 |
+
* @return string
|
141 |
+
*/
|
142 |
+
public function fetchSalesRules()
|
143 |
+
{
|
144 |
+
return $this->_orderItem->getAppliedRuleIds();
|
145 |
+
}
|
146 |
+
|
147 |
+
/**
|
148 |
+
* Options can be nested so this function will allow us to parse them in recursive manner.
|
149 |
+
*
|
150 |
+
* @param mixed $values
|
151 |
+
* @param string $prefix
|
152 |
+
* @return string
|
153 |
+
*/
|
154 |
+
protected function _stringifyOptions($values, $prefix = '')
|
155 |
+
{
|
156 |
+
$result = '';
|
157 |
+
|
158 |
+
foreach ($values as $value) {
|
159 |
+
if (is_array($value['value'])) {
|
160 |
+
if (isset($value['value'][0]) && count($value['value']) == 1) {
|
161 |
+
$value['value'] = $value['value'][0];
|
162 |
+
}
|
163 |
+
|
164 |
+
$result .= $prefix.$value['label'].":\n".$this->_stringifyOptions($value['value'], $prefix.' ');
|
165 |
+
} else {
|
166 |
+
$result .= $prefix.$value['label'].":".$value['value']."\n";
|
167 |
+
}
|
168 |
+
}
|
169 |
+
|
170 |
+
return $result;
|
171 |
+
}
|
172 |
+
|
173 |
+
/**
|
174 |
+
* Get REST order item entity
|
175 |
+
*
|
176 |
+
* @return Copernica_MarketingSoftware_Model_Rest_Order_Item
|
177 |
+
*/
|
178 |
+
public function getRestOrderItem()
|
179 |
+
{
|
180 |
+
$restOrderItem = Mage::getModel('marketingsoftware/rest_order_item');
|
181 |
+
$restOrderItem->setOrderItemEntity($this);
|
182 |
+
|
183 |
+
return $restOrderItem;
|
184 |
+
}
|
185 |
+
|
186 |
+
/**
|
187 |
+
* Set copernica order item
|
188 |
+
*
|
189 |
+
* @param Mage_Sales_Model_Order_Item|Mage_Sales_Model_Quote_Item $orderItem
|
190 |
+
*/
|
191 |
+
public function setOrderItem($orderItem)
|
192 |
+
{
|
193 |
+
if ($orderItem->getId()) {
|
194 |
+
$this->_orderItem = $orderItem;
|
195 |
+
$this->setProduct($orderItem->getProductId(), $this->getStoreId());
|
196 |
+
} else {
|
197 |
+
throw new Exception(Mage::helper('marketingsoftware')->__('Set an empty quote item or order item object.'));
|
198 |
+
}
|
199 |
+
}
|
200 |
+
}
|
app/code/community/Copernica/MarketingSoftware/Model/Copernica/Entity/Product.php
CHANGED
@@ -1,444 +1,444 @@
|
|
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-2015 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 |
-
if (!$this->_product) {
|
206 |
-
throw new Exception('asdf');
|
207 |
-
}
|
208 |
-
return $this->_product->getId();
|
209 |
-
}
|
210 |
-
|
211 |
-
/**
|
212 |
-
* Fetch store view
|
213 |
-
*
|
214 |
-
* @return string
|
215 |
-
*/
|
216 |
-
public function fetchStoreView()
|
217 |
-
{
|
218 |
-
$store = Mage::getModel('core/store')->load($this->getStoreId());
|
219 |
-
|
220 |
-
return Mage::getModel('marketingsoftware/abstraction_storeview')->setOriginal($store);
|
221 |
-
}
|
222 |
-
|
223 |
-
/**
|
224 |
-
* Get product weight
|
225 |
-
*
|
226 |
-
* @return string
|
227 |
-
*/
|
228 |
-
public function fetchWeight()
|
229 |
-
{
|
230 |
-
return $this->_product->getWeight();
|
231 |
-
}
|
232 |
-
|
233 |
-
/**
|
234 |
-
* Get last modification date
|
235 |
-
*
|
236 |
-
* @return string
|
237 |
-
*/
|
238 |
-
public function getModified()
|
239 |
-
{
|
240 |
-
return $this->_product->getUpdatedAt();
|
241 |
-
}
|
242 |
-
|
243 |
-
/**
|
244 |
-
* Get product creation date
|
245 |
-
*
|
246 |
-
* @return string
|
247 |
-
*/
|
248 |
-
public function getCreated()
|
249 |
-
{
|
250 |
-
return $this->_product->getCreatedAt();
|
251 |
-
}
|
252 |
-
|
253 |
-
/**
|
254 |
-
* Fetch categories list
|
255 |
-
*
|
256 |
-
* @return array
|
257 |
-
*/
|
258 |
-
public function fetchCategoriesList()
|
259 |
-
{
|
260 |
-
$categoryIds = $this->_product->getCategoryIds();
|
261 |
-
|
262 |
-
$data = array();
|
263 |
-
|
264 |
-
foreach ($categoryIds as $id) {
|
265 |
-
$categoryName = array();
|
266 |
-
|
267 |
-
$parent = Mage::getModel('catalog/category')->load($id);
|
268 |
-
|
269 |
-
while($parent->getId() > 1) {
|
270 |
-
$categoryName [] = $parent->getName();
|
271 |
-
|
272 |
-
$parent = $parent->getParentCategory();
|
273 |
-
}
|
274 |
-
|
275 |
-
$data[$id] = implode(' > ', $categoryName);
|
276 |
-
}
|
277 |
-
|
278 |
-
return $data;
|
279 |
-
}
|
280 |
-
|
281 |
-
/**
|
282 |
-
* Get product category path
|
283 |
-
*
|
284 |
-
* @return string
|
285 |
-
*/
|
286 |
-
public function fetchCategories()
|
287 |
-
{
|
288 |
-
return implode("\n", $this->fetchCategoriesList());
|
289 |
-
}
|
290 |
-
|
291 |
-
/**
|
292 |
-
* Fetch options associated with given product.
|
293 |
-
*
|
294 |
-
* @return string
|
295 |
-
*/
|
296 |
-
public function fetchOptions()
|
297 |
-
{
|
298 |
-
$options = $this->_product->getTypeInstance(true)->getOrderOptions($this->_product);
|
299 |
-
|
300 |
-
$neededOptions = array();
|
301 |
-
|
302 |
-
if (isset($options['attributes_info'])) {
|
303 |
-
$neededOptions = $options['attributes_info'];
|
304 |
-
} elseif (isset($options['bundle_options'])) {
|
305 |
-
$neededOptions = $options['bundle_options'];
|
306 |
-
} elseif (isset($options['options'])) {
|
307 |
-
$neeededOptions = $options['options'];
|
308 |
-
}
|
309 |
-
|
310 |
-
return $this->_stringifyOptions($neededOptions);
|
311 |
-
}
|
312 |
-
|
313 |
-
/**
|
314 |
-
* Fetch attribute list
|
315 |
-
*
|
316 |
-
* @return array
|
317 |
-
*/
|
318 |
-
public function fetchAttributesList()
|
319 |
-
{
|
320 |
-
$attributes = $this->_product->getAttributes();
|
321 |
-
|
322 |
-
$resultSet = array();
|
323 |
-
|
324 |
-
$stringRepresentation = '';
|
325 |
-
|
326 |
-
foreach ($attributes as $attr) {
|
327 |
-
if (!$attr->getIsUserDefined()) {
|
328 |
-
continue;
|
329 |
-
}
|
330 |
-
|
331 |
-
$compareArray = array('text', 'select', 'multiline', 'textarea', 'price', 'date', 'multiselect');
|
332 |
-
|
333 |
-
if (!in_array($attr->getFrontendInput(), $compareArray)) {
|
334 |
-
continue;
|
335 |
-
}
|
336 |
-
|
337 |
-
if ($attr->getAttributeCode() && $value = $attr->getFrontend()->getValue($this->_product)) {
|
338 |
-
$resultSet []= array (
|
339 |
-
'code' => $attr->getAttributeCode(),
|
340 |
-
'value' => $value,
|
341 |
-
'type' => $attr->getFrontendInput(),
|
342 |
-
'label' => $attr->getFrontendLabel()
|
343 |
-
);
|
344 |
-
}
|
345 |
-
}
|
346 |
-
|
347 |
-
return $resultSet;
|
348 |
-
}
|
349 |
-
|
350 |
-
/**
|
351 |
-
* Is product a new product?
|
352 |
-
*
|
353 |
-
* @return boolean
|
354 |
-
*/
|
355 |
-
public function fetchNew()
|
356 |
-
{
|
357 |
-
$newsFrom = $this->_product->getNewsFromDate();
|
358 |
-
$newsTo = $this->_product->getNewsToDate();
|
359 |
-
|
360 |
-
if (!$newsFrom && !$newsTo) {
|
361 |
-
return false;
|
362 |
-
}
|
363 |
-
|
364 |
-
$from = Mage::app()->getLocale()->date($newsFrom);
|
365 |
-
$to = Mage::app()->getLocale()->date($newsTo);
|
366 |
-
$now = Zend_Date::now();
|
367 |
-
|
368 |
-
$new = true;
|
369 |
-
|
370 |
-
$new = $from ? $new && $from->isEarlier($now) : $new;
|
371 |
-
$new = $to ? $new && $to->isLater($now) : $new;
|
372 |
-
|
373 |
-
return $new;
|
374 |
-
}
|
375 |
-
|
376 |
-
/**
|
377 |
-
* Fetch attributes string representation.
|
378 |
-
*
|
379 |
-
* @return string
|
380 |
-
*/
|
381 |
-
public function fetchAttributes()
|
382 |
-
{
|
383 |
-
$attributes = array_map( function ($item) {
|
384 |
-
return sprintf("%s: %s", $item['code'], $item['value']);
|
385 |
-
}, $this->getAttributesList());
|
386 |
-
|
387 |
-
if (!is_array($attributes)) {
|
388 |
-
return '';
|
389 |
-
}
|
390 |
-
|
391 |
-
return implode ("\n", $attributes);
|
392 |
-
}
|
393 |
-
|
394 |
-
/**
|
395 |
-
* Fetch attribute set name
|
396 |
-
*
|
397 |
-
* @return string
|
398 |
-
*/
|
399 |
-
public function fetchAttributeSet()
|
400 |
-
{
|
401 |
-
$set = Mage::getModel('eav/entity_attribute_set')->load($this->_product->getAttributeSetId());
|
402 |
-
|
403 |
-
return $set->getAttributeSetName();
|
404 |
-
}
|
405 |
-
|
406 |
-
/**
|
407 |
-
* Get REST product entity
|
408 |
-
*
|
409 |
-
* @return Copernica_MarketingSoftware_Model_Rest_Product
|
410 |
-
*/
|
411 |
-
public function getRestProduct()
|
412 |
-
{
|
413 |
-
$restProduct = Mage::getModel('marketingsoftware/rest_product');
|
414 |
-
$restProduct->setProductEntity($this);
|
415 |
-
|
416 |
-
return $restProduct;
|
417 |
-
}
|
418 |
-
|
419 |
-
/**
|
420 |
-
* Set product entity
|
421 |
-
*
|
422 |
-
* @param int $productId
|
423 |
-
* @param int $storeId
|
424 |
-
*/
|
425 |
-
public function setProduct($productId, $storeId = null)
|
426 |
-
{
|
427 |
-
if (!$storeId) {
|
428 |
-
$storeId = Mage::app()->getStore()->getId();
|
429 |
-
}
|
430 |
-
|
431 |
-
$this->_product = Mage::getModel('catalog/product')->setStoreId($storeId)->load($productId);
|
432 |
-
}
|
433 |
-
|
434 |
-
|
435 |
-
/**
|
436 |
-
* Set the timestamp for when the product was viewed
|
437 |
-
*
|
438 |
-
* @param unknown $viewedAt
|
439 |
-
*/
|
440 |
-
public function setTimestamp($viewedAt)
|
441 |
-
{
|
442 |
-
$this->_timestamp = $viewedAt;
|
443 |
-
}
|
444 |
-
}
|
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-2015 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 |
+
if (!$this->_product) {
|
206 |
+
throw new Exception('asdf');
|
207 |
+
}
|
208 |
+
return $this->_product->getId();
|
209 |
+
}
|
210 |
+
|
211 |
+
/**
|
212 |
+
* Fetch store view
|
213 |
+
*
|
214 |
+
* @return string
|
215 |
+
*/
|
216 |
+
public function fetchStoreView()
|
217 |
+
{
|
218 |
+
$store = Mage::getModel('core/store')->load($this->getStoreId());
|
219 |
+
|
220 |
+
return Mage::getModel('marketingsoftware/abstraction_storeview')->setOriginal($store);
|
221 |
+
}
|
222 |
+
|
223 |
+
/**
|
224 |
+
* Get product weight
|
225 |
+
*
|
226 |
+
* @return string
|
227 |
+
*/
|
228 |
+
public function fetchWeight()
|
229 |
+
{
|
230 |
+
return $this->_product->getWeight();
|
231 |
+
}
|
232 |
+
|
233 |
+
/**
|
234 |
+
* Get last modification date
|
235 |
+
*
|
236 |
+
* @return string
|
237 |
+
*/
|
238 |
+
public function getModified()
|
239 |
+
{
|
240 |
+
return $this->_product->getUpdatedAt();
|
241 |
+
}
|
242 |
+
|
243 |
+
/**
|
244 |
+
* Get product creation date
|
245 |
+
*
|
246 |
+
* @return string
|
247 |
+
*/
|
248 |
+
public function getCreated()
|
249 |
+
{
|
250 |
+
return $this->_product->getCreatedAt();
|
251 |
+
}
|
252 |
+
|
253 |
+
/**
|
254 |
+
* Fetch categories list
|
255 |
+
*
|
256 |
+
* @return array
|
257 |
+
*/
|
258 |
+
public function fetchCategoriesList()
|
259 |
+
{
|
260 |
+
$categoryIds = $this->_product->getCategoryIds();
|
261 |
+
|
262 |
+
$data = array();
|
263 |
+
|
264 |
+
foreach ($categoryIds as $id) {
|
265 |
+
$categoryName = array();
|
266 |
+
|
267 |
+
$parent = Mage::getModel('catalog/category')->load($id);
|
268 |
+
|
269 |
+
while($parent->getId() > 1) {
|
270 |
+
$categoryName [] = $parent->getName();
|
271 |
+
|
272 |
+
$parent = $parent->getParentCategory();
|
273 |
+
}
|
274 |
+
|
275 |
+
$data[$id] = implode(' > ', $categoryName);
|
276 |
+
}
|
277 |
+
|
278 |
+
return $data;
|
279 |
+
}
|
280 |
+
|
281 |
+
/**
|
282 |
+
* Get product category path
|
283 |
+
*
|
284 |
+
* @return string
|
285 |
+
*/
|
286 |
+
public function fetchCategories()
|
287 |
+
{
|
288 |
+
return implode("\n", $this->fetchCategoriesList());
|
289 |
+
}
|
290 |
+
|
291 |
+
/**
|
292 |
+
* Fetch options associated with given product.
|
293 |
+
*
|
294 |
+
* @return string
|
295 |
+
*/
|
296 |
+
public function fetchOptions()
|
297 |
+
{
|
298 |
+
$options = $this->_product->getTypeInstance(true)->getOrderOptions($this->_product);
|
299 |
+
|
300 |
+
$neededOptions = array();
|
301 |
+
|
302 |
+
if (isset($options['attributes_info'])) {
|
303 |
+
$neededOptions = $options['attributes_info'];
|
304 |
+
} elseif (isset($options['bundle_options'])) {
|
305 |
+
$neededOptions = $options['bundle_options'];
|
306 |
+
} elseif (isset($options['options'])) {
|
307 |
+
$neeededOptions = $options['options'];
|
308 |
+
}
|
309 |
+
|
310 |
+
return $this->_stringifyOptions($neededOptions);
|
311 |
+
}
|
312 |
+
|
313 |
+
/**
|
314 |
+
* Fetch attribute list
|
315 |
+
*
|
316 |
+
* @return array
|
317 |
+
*/
|
318 |
+
public function fetchAttributesList()
|
319 |
+
{
|
320 |
+
$attributes = $this->_product->getAttributes();
|
321 |
+
|
322 |
+
$resultSet = array();
|
323 |
+
|
324 |
+
$stringRepresentation = '';
|
325 |
+
|
326 |
+
foreach ($attributes as $attr) {
|
327 |
+
if (!$attr->getIsUserDefined()) {
|
328 |
+
continue;
|
329 |
+
}
|
330 |
+
|
331 |
+
$compareArray = array('text', 'select', 'multiline', 'textarea', 'price', 'date', 'multiselect');
|
332 |
+
|
333 |
+
if (!in_array($attr->getFrontendInput(), $compareArray)) {
|
334 |
+
continue;
|
335 |
+
}
|
336 |
+
|
337 |
+
if ($attr->getAttributeCode() && $value = $attr->getFrontend()->getValue($this->_product)) {
|
338 |
+
$resultSet []= array (
|
339 |
+
'code' => $attr->getAttributeCode(),
|
340 |
+
'value' => $value,
|
341 |
+
'type' => $attr->getFrontendInput(),
|
342 |
+
'label' => $attr->getFrontendLabel()
|
343 |
+
);
|
344 |
+
}
|
345 |
+
}
|
346 |
+
|
347 |
+
return $resultSet;
|
348 |
+
}
|
349 |
+
|
350 |
+
/**
|
351 |
+
* Is product a new product?
|
352 |
+
*
|
353 |
+
* @return boolean
|
354 |
+
*/
|
355 |
+
public function fetchNew()
|
356 |
+
{
|
357 |
+
$newsFrom = $this->_product->getNewsFromDate();
|
358 |
+
$newsTo = $this->_product->getNewsToDate();
|
359 |
+
|
360 |
+
if (!$newsFrom && !$newsTo) {
|
361 |
+
return false;
|
362 |
+
}
|
363 |
+
|
364 |
+
$from = Mage::app()->getLocale()->date($newsFrom);
|
365 |
+
$to = Mage::app()->getLocale()->date($newsTo);
|
366 |
+
$now = Zend_Date::now();
|
367 |
+
|
368 |
+
$new = true;
|
369 |
+
|
370 |
+
$new = $from ? $new && $from->isEarlier($now) : $new;
|
371 |
+
$new = $to ? $new && $to->isLater($now) : $new;
|
372 |
+
|
373 |
+
return $new;
|
374 |
+
}
|
375 |
+
|
376 |
+
/**
|
377 |
+
* Fetch attributes string representation.
|
378 |
+
*
|
379 |
+
* @return string
|
380 |
+
*/
|
381 |
+
public function fetchAttributes()
|
382 |
+
{
|
383 |
+
$attributes = array_map( function ($item) {
|
384 |
+
return sprintf("%s: %s", $item['code'], $item['value']);
|
385 |
+
}, $this->getAttributesList());
|
386 |
+
|
387 |
+
if (!is_array($attributes)) {
|
388 |
+
return '';
|
389 |
+
}
|
390 |
+
|
391 |
+
return implode ("\n", $attributes);
|
392 |
+
}
|
393 |
+
|
394 |
+
/**
|
395 |
+
* Fetch attribute set name
|
396 |
+
*
|
397 |
+
* @return string
|
398 |
+
*/
|
399 |
+
public function fetchAttributeSet()
|
400 |
+
{
|
401 |
+
$set = Mage::getModel('eav/entity_attribute_set')->load($this->_product->getAttributeSetId());
|
402 |
+
|
403 |
+
return $set->getAttributeSetName();
|
404 |
+
}
|
405 |
+
|
406 |
+
/**
|
407 |
+
* Get REST product entity
|
408 |
+
*
|
409 |
+
* @return Copernica_MarketingSoftware_Model_Rest_Product
|
410 |
+
*/
|
411 |
+
public function getRestProduct()
|
412 |
+
{
|
413 |
+
$restProduct = Mage::getModel('marketingsoftware/rest_product');
|
414 |
+
$restProduct->setProductEntity($this);
|
415 |
+
|
416 |
+
return $restProduct;
|
417 |
+
}
|
418 |
+
|
419 |
+
/**
|
420 |
+
* Set product entity
|
421 |
+
*
|
422 |
+
* @param int $productId
|
423 |
+
* @param int $storeId
|
424 |
+
*/
|
425 |
+
public function setProduct($productId, $storeId = null)
|
426 |
+
{
|
427 |
+
if (!$storeId) {
|
428 |
+
$storeId = Mage::app()->getStore()->getId();
|
429 |
+
}
|
430 |
+
|
431 |
+
$this->_product = Mage::getModel('catalog/product')->setStoreId($storeId)->load($productId);
|
432 |
+
}
|
433 |
+
|
434 |
+
|
435 |
+
/**
|
436 |
+
* Set the timestamp for when the product was viewed
|
437 |
+
*
|
438 |
+
* @param unknown $viewedAt
|
439 |
+
*/
|
440 |
+
public function setTimestamp($viewedAt)
|
441 |
+
{
|
442 |
+
$this->_timestamp = $viewedAt;
|
443 |
+
}
|
444 |
+
}
|
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-2015 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 |
-
}
|
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-2015 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-2015 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-2015 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-2015 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-2015 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-2015 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-2015 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-2015 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(), $this->getStoreId());
|
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-2015 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(), $this->getStoreId());
|
154 |
+
}
|
155 |
+
}
|
app/code/community/Copernica/MarketingSoftware/Model/Copernica/Order/Subprofile.php
CHANGED
@@ -1,124 +1,124 @@
|
|
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-2015 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_Order_Subprofile extends Copernica_MarketingSoftware_Model_Copernica_Abstract
|
31 |
-
{
|
32 |
-
/**
|
33 |
-
* @var Copernica_MarketingSoftware_Model_Abstraction_Order
|
34 |
-
*/
|
35 |
-
protected $_order = false;
|
36 |
-
|
37 |
-
/**
|
38 |
-
* Return the identifier for this profile
|
39 |
-
*
|
40 |
-
* @return string
|
41 |
-
*/
|
42 |
-
public function id()
|
43 |
-
{
|
44 |
-
return $this['order_id'];
|
45 |
-
}
|
46 |
-
|
47 |
-
/**
|
48 |
-
* Try to store a quote item
|
49 |
-
*
|
50 |
-
* @param Copernica_MarketingSoftware_Model_Abstract $order
|
51 |
-
* @return Copernica_MarketingSoftware_Model_Copernica_Order_Subprofile
|
52 |
-
*/
|
53 |
-
public function setOrder(Copernica_MarketingSoftware_Model_Abstract $order)
|
54 |
-
{
|
55 |
-
$this->_order = $order;
|
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')->getLinkedOrderFields();
|
68 |
-
}
|
69 |
-
|
70 |
-
/**
|
71 |
-
* Get the required fields
|
72 |
-
*
|
73 |
-
* @return array
|
74 |
-
*/
|
75 |
-
public function requiredFields()
|
76 |
-
{
|
77 |
-
return array('order_id', 'quote_id');
|
78 |
-
}
|
79 |
-
|
80 |
-
/**
|
81 |
-
* Retrieve the data for this object
|
82 |
-
*
|
83 |
-
* @return array
|
84 |
-
*/
|
85 |
-
protected function _data()
|
86 |
-
{
|
87 |
-
$billingAddress = $shippingAddress = false;
|
88 |
-
|
89 |
-
$addresses = $this->_order->addresses();
|
90 |
-
|
91 |
-
if (is_array($addresses)) {
|
92 |
-
foreach ($addresses as $address) {
|
93 |
-
if (in_array('billing', $address->type())) {
|
94 |
-
$billingAddress = $address;
|
95 |
-
}
|
96 |
-
|
97 |
-
if (in_array('shipping', $address->type())) {
|
98 |
-
$shippingAddress = $address;
|
99 |
-
}
|
100 |
-
}
|
101 |
-
}
|
102 |
-
|
103 |
-
$price = $this->_order->price();
|
104 |
-
|
105 |
-
return array(
|
106 |
-
'order_id' => $this->_order->id(),
|
107 |
-
'quote_id' => $this->_order->quoteId(),
|
108 |
-
'increment_id' => $this->_order->incrementId(),
|
109 |
-
'timestamp' => $this->_order->timestamp(),
|
110 |
-
'quantity' => $this->_order->quantity(),
|
111 |
-
'total' => is_object($price) ? $price->total() : null,
|
112 |
-
'shipping' => is_object($price) ? $price->shipping() : null,
|
113 |
-
'currency' => is_object($price) ? $price->currency() : null,
|
114 |
-
'weight' => $this->_order->weight(),
|
115 |
-
'status' => $this->_order->status(),
|
116 |
-
'store_view' => (string)$this->_order->storeview(),
|
117 |
-
'remote_ip' => $this->_order->customerIP(),
|
118 |
-
'shipping_description' => $this->_order->shippingDescription(),
|
119 |
-
'payment_description' => $this->_order->paymentDescription(),
|
120 |
-
'shipping_address_id' => is_object($shippingAddress) ? $shippingAddress->id() : '',
|
121 |
-
'billing_address_id' => is_object($billingAddress) ? $billingAddress->id() : '',
|
122 |
-
);
|
123 |
-
}
|
124 |
-
}
|
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-2015 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_Order_Subprofile extends Copernica_MarketingSoftware_Model_Copernica_Abstract
|
31 |
+
{
|
32 |
+
/**
|
33 |
+
* @var Copernica_MarketingSoftware_Model_Abstraction_Order
|
34 |
+
*/
|
35 |
+
protected $_order = false;
|
36 |
+
|
37 |
+
/**
|
38 |
+
* Return the identifier for this profile
|
39 |
+
*
|
40 |
+
* @return string
|
41 |
+
*/
|
42 |
+
public function id()
|
43 |
+
{
|
44 |
+
return $this['order_id'];
|
45 |
+
}
|
46 |
+
|
47 |
+
/**
|
48 |
+
* Try to store a quote item
|
49 |
+
*
|
50 |
+
* @param Copernica_MarketingSoftware_Model_Abstract $order
|
51 |
+
* @return Copernica_MarketingSoftware_Model_Copernica_Order_Subprofile
|
52 |
+
*/
|
53 |
+
public function setOrder(Copernica_MarketingSoftware_Model_Abstract $order)
|
54 |
+
{
|
55 |
+
$this->_order = $order;
|
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')->getLinkedOrderFields();
|
68 |
+
}
|
69 |
+
|
70 |
+
/**
|
71 |
+
* Get the required fields
|
72 |
+
*
|
73 |
+
* @return array
|
74 |
+
*/
|
75 |
+
public function requiredFields()
|
76 |
+
{
|
77 |
+
return array('order_id', 'quote_id');
|
78 |
+
}
|
79 |
+
|
80 |
+
/**
|
81 |
+
* Retrieve the data for this object
|
82 |
+
*
|
83 |
+
* @return array
|
84 |
+
*/
|
85 |
+
protected function _data()
|
86 |
+
{
|
87 |
+
$billingAddress = $shippingAddress = false;
|
88 |
+
|
89 |
+
$addresses = $this->_order->addresses();
|
90 |
+
|
91 |
+
if (is_array($addresses)) {
|
92 |
+
foreach ($addresses as $address) {
|
93 |
+
if (in_array('billing', $address->type())) {
|
94 |
+
$billingAddress = $address;
|
95 |
+
}
|
96 |
+
|
97 |
+
if (in_array('shipping', $address->type())) {
|
98 |
+
$shippingAddress = $address;
|
99 |
+
}
|
100 |
+
}
|
101 |
+
}
|
102 |
+
|
103 |
+
$price = $this->_order->price();
|
104 |
+
|
105 |
+
return array(
|
106 |
+
'order_id' => $this->_order->id(),
|
107 |
+
'quote_id' => $this->_order->quoteId(),
|
108 |
+
'increment_id' => $this->_order->incrementId(),
|
109 |
+
'timestamp' => $this->_order->timestamp(),
|
110 |
+
'quantity' => $this->_order->quantity(),
|
111 |
+
'total' => is_object($price) ? $price->total() : null,
|
112 |
+
'shipping' => is_object($price) ? $price->shipping() : null,
|
113 |
+
'currency' => is_object($price) ? $price->currency() : null,
|
114 |
+
'weight' => $this->_order->weight(),
|
115 |
+
'status' => $this->_order->status(),
|
116 |
+
'store_view' => (string)$this->_order->storeview(),
|
117 |
+
'remote_ip' => $this->_order->customerIP(),
|
118 |
+
'shipping_description' => $this->_order->shippingDescription(),
|
119 |
+
'payment_description' => $this->_order->paymentDescription(),
|
120 |
+
'shipping_address_id' => is_object($shippingAddress) ? $shippingAddress->id() : '',
|
121 |
+
'billing_address_id' => is_object($billingAddress) ? $billingAddress->id() : '',
|
122 |
+
);
|
123 |
+
}
|
124 |
+
}
|
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-2015 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-2015 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-2015 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-2015 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.php
CHANGED
@@ -1,85 +1,85 @@
|
|
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-2015 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 |
-
abstract class Copernica_MarketingSoftware_Model_Copernica_Profile extends Copernica_MarketingSoftware_Model_Copernica_Abstract
|
31 |
-
{
|
32 |
-
/**
|
33 |
-
* Return the identifier for this profile
|
34 |
-
*
|
35 |
-
* @return string
|
36 |
-
*/
|
37 |
-
public function id()
|
38 |
-
{
|
39 |
-
return $this['customer_id'];
|
40 |
-
}
|
41 |
-
|
42 |
-
/**
|
43 |
-
* Return email associated with profile
|
44 |
-
*
|
45 |
-
* @return string
|
46 |
-
*/
|
47 |
-
abstract public function email();
|
48 |
-
|
49 |
-
/**
|
50 |
-
* Return store view associated with profile
|
51 |
-
*
|
52 |
-
* @return string
|
53 |
-
*/
|
54 |
-
abstract public function storeView();
|
55 |
-
|
56 |
-
/**
|
57 |
-
* Fallback method for profile objects not having this method.
|
58 |
-
*
|
59 |
-
* @return string
|
60 |
-
*/
|
61 |
-
public function originalId()
|
62 |
-
{
|
63 |
-
return $this->id();
|
64 |
-
}
|
65 |
-
|
66 |
-
/**
|
67 |
-
* Get linked fields
|
68 |
-
*
|
69 |
-
* @return array
|
70 |
-
*/
|
71 |
-
public function linkedFields()
|
72 |
-
{
|
73 |
-
return Mage::helper('marketingsoftware/config')->getLinkedCustomerFields();
|
74 |
-
}
|
75 |
-
|
76 |
-
/**
|
77 |
-
* Get the required fields
|
78 |
-
*
|
79 |
-
* @return array
|
80 |
-
*/
|
81 |
-
public function requiredFields()
|
82 |
-
{
|
83 |
-
return array('customer_id');
|
84 |
-
}
|
85 |
-
}
|
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-2015 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 |
+
abstract class Copernica_MarketingSoftware_Model_Copernica_Profile extends Copernica_MarketingSoftware_Model_Copernica_Abstract
|
31 |
+
{
|
32 |
+
/**
|
33 |
+
* Return the identifier for this profile
|
34 |
+
*
|
35 |
+
* @return string
|
36 |
+
*/
|
37 |
+
public function id()
|
38 |
+
{
|
39 |
+
return $this['customer_id'];
|
40 |
+
}
|
41 |
+
|
42 |
+
/**
|
43 |
+
* Return email associated with profile
|
44 |
+
*
|
45 |
+
* @return string
|
46 |
+
*/
|
47 |
+
abstract public function email();
|
48 |
+
|
49 |
+
/**
|
50 |
+
* Return store view associated with profile
|
51 |
+
*
|
52 |
+
* @return string
|
53 |
+
*/
|
54 |
+
abstract public function storeView();
|
55 |
+
|
56 |
+
/**
|
57 |
+
* Fallback method for profile objects not having this method.
|
58 |
+
*
|
59 |
+
* @return string
|
60 |
+
*/
|
61 |
+
public function originalId()
|
62 |
+
{
|
63 |
+
return $this->id();
|
64 |
+
}
|
65 |
+
|
66 |
+
/**
|
67 |
+
* Get linked fields
|
68 |
+
*
|
69 |
+
* @return array
|
70 |
+
*/
|
71 |
+
public function linkedFields()
|
72 |
+
{
|
73 |
+
return Mage::helper('marketingsoftware/config')->getLinkedCustomerFields();
|
74 |
+
}
|
75 |
+
|
76 |
+
/**
|
77 |
+
* Get the required fields
|
78 |
+
*
|
79 |
+
* @return array
|
80 |
+
*/
|
81 |
+
public function requiredFields()
|
82 |
+
{
|
83 |
+
return array('customer_id');
|
84 |
+
}
|
85 |
+
}
|
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-2015 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-2015 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/Profile/Order.php
CHANGED
@@ -1,125 +1,125 @@
|
|
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-2015 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_Order extends Copernica_MarketingSoftware_Model_Copernica_Profile
|
31 |
-
{
|
32 |
-
/**
|
33 |
-
* @var Copernica_MarketingSoftware_Model_Abstraction_Order
|
34 |
-
*/
|
35 |
-
protected $_order = false;
|
36 |
-
|
37 |
-
/**
|
38 |
-
* Set the order object to this object
|
39 |
-
*
|
40 |
-
* @param Copernica_MarketingSoftware_Model_Abstraction_Order $order
|
41 |
-
* @return Copernica_MarketingSoftware_Model_Copernica_Profile_Order
|
42 |
-
*/
|
43 |
-
public function setOrder(Copernica_MarketingSoftware_Model_Abstraction_Order $order)
|
44 |
-
{
|
45 |
-
$this->_order = $order;
|
46 |
-
return $this;
|
47 |
-
}
|
48 |
-
|
49 |
-
/**
|
50 |
-
* Get profile email.
|
51 |
-
*
|
52 |
-
* @return string
|
53 |
-
*/
|
54 |
-
public function email()
|
55 |
-
{
|
56 |
-
$addresses = $this->_order->addresses();
|
57 |
-
|
58 |
-
foreach ($addresses as $address) {
|
59 |
-
if (in_array('billing', $addr->type())) {
|
60 |
-
return $address->email();
|
61 |
-
}
|
62 |
-
}
|
63 |
-
|
64 |
-
return '';
|
65 |
-
}
|
66 |
-
|
67 |
-
/**
|
68 |
-
* Return store view associated with profile
|
69 |
-
*
|
70 |
-
* @return string
|
71 |
-
*/
|
72 |
-
public function storeView()
|
73 |
-
{
|
74 |
-
return (string)$this->_order->storeview();
|
75 |
-
}
|
76 |
-
|
77 |
-
/**
|
78 |
-
* Retrieve the data for this object
|
79 |
-
*
|
80 |
-
* @return array
|
81 |
-
*/
|
82 |
-
protected function _data()
|
83 |
-
{
|
84 |
-
$addresses = $this->_order->addresses();
|
85 |
-
|
86 |
-
if (count($addresses) == 1) {
|
87 |
-
$address = $addresses[0];
|
88 |
-
} else {
|
89 |
-
foreach ($addresses as $addr) {
|
90 |
-
if (in_array('billing', $addr->type())) {
|
91 |
-
$address = $addr;
|
92 |
-
}
|
93 |
-
}
|
94 |
-
}
|
95 |
-
|
96 |
-
if (Mage::getModel('newsletter/subscriber')->loadByEmail($address->email())->getId()) {
|
97 |
-
$subscription = Mage::getModel('marketingsoftware/abstraction_subscription')
|
98 |
-
->setOriginal(Mage::getModel('newsletter/subscriber')->loadByEmail($address->email()));
|
99 |
-
} else {
|
100 |
-
$subscription = false;
|
101 |
-
}
|
102 |
-
|
103 |
-
$name = $address->name();
|
104 |
-
|
105 |
-
$customerId = null;
|
106 |
-
|
107 |
-
if ($customer = $this->_order->customer()) {
|
108 |
-
$customerId = Mage::helper('marketingsoftware/profile')->getCustomerCopernicaId($customer, $this->_order->storeview());
|
109 |
-
} else {
|
110 |
-
$customerId = Mage::helper('marketingsoftware/profile')->getEmailCopernicaId($address->email(), (string)$this->_order->storeview());
|
111 |
-
}
|
112 |
-
|
113 |
-
return array(
|
114 |
-
'customer_id' => $customerId,
|
115 |
-
'store_view' => (string)$this->_order->storeview(),
|
116 |
-
'firstname' => is_object($name) ? $name->firstname() : null,
|
117 |
-
'middlename' => is_object($name) ? $name->middlename() : null,
|
118 |
-
'lastname' => is_object($name) ? $name->lastname() : null,
|
119 |
-
'email' => $address->email(),
|
120 |
-
'group' => Mage::getModel('customer/group')->load(0)->getCode(),
|
121 |
-
'newsletter' => is_object($subscription) ? $subscription->status() : 'unknown',
|
122 |
-
'gender' => 'unknown'
|
123 |
-
);
|
124 |
-
}
|
125 |
-
}
|
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-2015 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_Order extends Copernica_MarketingSoftware_Model_Copernica_Profile
|
31 |
+
{
|
32 |
+
/**
|
33 |
+
* @var Copernica_MarketingSoftware_Model_Abstraction_Order
|
34 |
+
*/
|
35 |
+
protected $_order = false;
|
36 |
+
|
37 |
+
/**
|
38 |
+
* Set the order object to this object
|
39 |
+
*
|
40 |
+
* @param Copernica_MarketingSoftware_Model_Abstraction_Order $order
|
41 |
+
* @return Copernica_MarketingSoftware_Model_Copernica_Profile_Order
|
42 |
+
*/
|
43 |
+
public function setOrder(Copernica_MarketingSoftware_Model_Abstraction_Order $order)
|
44 |
+
{
|
45 |
+
$this->_order = $order;
|
46 |
+
return $this;
|
47 |
+
}
|
48 |
+
|
49 |
+
/**
|
50 |
+
* Get profile email.
|
51 |
+
*
|
52 |
+
* @return string
|
53 |
+
*/
|
54 |
+
public function email()
|
55 |
+
{
|
56 |
+
$addresses = $this->_order->addresses();
|
57 |
+
|
58 |
+
foreach ($addresses as $address) {
|
59 |
+
if (in_array('billing', $addr->type())) {
|
60 |
+
return $address->email();
|
61 |
+
}
|
62 |
+
}
|
63 |
+
|
64 |
+
return '';
|
65 |
+
}
|
66 |
+
|
67 |
+
/**
|
68 |
+
* Return store view associated with profile
|
69 |
+
*
|
70 |
+
* @return string
|
71 |
+
*/
|
72 |
+
public function storeView()
|
73 |
+
{
|
74 |
+
return (string)$this->_order->storeview();
|
75 |
+
}
|
76 |
+
|
77 |
+
/**
|
78 |
+
* Retrieve the data for this object
|
79 |
+
*
|
80 |
+
* @return array
|
81 |
+
*/
|
82 |
+
protected function _data()
|
83 |
+
{
|
84 |
+
$addresses = $this->_order->addresses();
|
85 |
+
|
86 |
+
if (count($addresses) == 1) {
|
87 |
+
$address = $addresses[0];
|
88 |
+
} else {
|
89 |
+
foreach ($addresses as $addr) {
|
90 |
+
if (in_array('billing', $addr->type())) {
|
91 |
+
$address = $addr;
|
92 |
+
}
|
93 |
+
}
|
94 |
+
}
|
95 |
+
|
96 |
+
if (Mage::getModel('newsletter/subscriber')->loadByEmail($address->email())->getId()) {
|
97 |
+
$subscription = Mage::getModel('marketingsoftware/abstraction_subscription')
|
98 |
+
->setOriginal(Mage::getModel('newsletter/subscriber')->loadByEmail($address->email()));
|
99 |
+
} else {
|
100 |
+
$subscription = false;
|
101 |
+
}
|
102 |
+
|
103 |
+
$name = $address->name();
|
104 |
+
|
105 |
+
$customerId = null;
|
106 |
+
|
107 |
+
if ($customer = $this->_order->customer()) {
|
108 |
+
$customerId = Mage::helper('marketingsoftware/profile')->getCustomerCopernicaId($customer, $this->_order->storeview());
|
109 |
+
} else {
|
110 |
+
$customerId = Mage::helper('marketingsoftware/profile')->getEmailCopernicaId($address->email(), (string)$this->_order->storeview());
|
111 |
+
}
|
112 |
+
|
113 |
+
return array(
|
114 |
+
'customer_id' => $customerId,
|
115 |
+
'store_view' => (string)$this->_order->storeview(),
|
116 |
+
'firstname' => is_object($name) ? $name->firstname() : null,
|
117 |
+
'middlename' => is_object($name) ? $name->middlename() : null,
|
118 |
+
'lastname' => is_object($name) ? $name->lastname() : null,
|
119 |
+
'email' => $address->email(),
|
120 |
+
'group' => Mage::getModel('customer/group')->load(0)->getCode(),
|
121 |
+
'newsletter' => is_object($subscription) ? $subscription->status() : 'unknown',
|
122 |
+
'gender' => 'unknown'
|
123 |
+
);
|
124 |
+
}
|
125 |
+
}
|
app/code/community/Copernica/MarketingSoftware/Model/Copernica/Profile/Quote.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-2015 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_Quote extends Copernica_MarketingSoftware_Model_Copernica_Profile
|
31 |
-
{
|
32 |
-
/**
|
33 |
-
* @var Copernica_MarketingSoftware_Model_Abstraction_Quote
|
34 |
-
*/
|
35 |
-
protected $_quote = false;
|
36 |
-
|
37 |
-
/**
|
38 |
-
* Set the quote object to this object
|
39 |
-
*
|
40 |
-
* @param Copernica_MarketingSoftware_Model_Abstraction_Quote $quote
|
41 |
-
* @return Copernica_MarketingSoftware_Model_Copernica_Profile_Quote
|
42 |
-
*/
|
43 |
-
public function setQuote(Copernica_MarketingSoftware_Model_Abstraction_Quote $quote)
|
44 |
-
{
|
45 |
-
$this->_quote = $quote;
|
46 |
-
|
47 |
-
return $this;
|
48 |
-
}
|
49 |
-
|
50 |
-
/**
|
51 |
-
* Get profile email.
|
52 |
-
*
|
53 |
-
* @return string
|
54 |
-
*/
|
55 |
-
public function email()
|
56 |
-
{
|
57 |
-
$addresses = $this->_quote->addresses();
|
58 |
-
|
59 |
-
foreach ($addresses as $address) {
|
60 |
-
if (in_array('billing', $addr->type())) {
|
61 |
-
return $address->email();
|
62 |
-
}
|
63 |
-
}
|
64 |
-
|
65 |
-
return '';
|
66 |
-
}
|
67 |
-
|
68 |
-
/**
|
69 |
-
* Return store view associated with profile
|
70 |
-
*
|
71 |
-
* @return string
|
72 |
-
*/
|
73 |
-
public function storeView()
|
74 |
-
{
|
75 |
-
return (string)$this->_quote->storeview();
|
76 |
-
}
|
77 |
-
|
78 |
-
/**
|
79 |
-
* Retrieve the data for this object
|
80 |
-
*
|
81 |
-
* @return array
|
82 |
-
*/
|
83 |
-
protected function _data()
|
84 |
-
{
|
85 |
-
$addresses = $this->_quote->addresses();
|
86 |
-
|
87 |
-
$address = null;
|
88 |
-
|
89 |
-
if (is_array($addresses)) {
|
90 |
-
if (count($addresses) == 1) {
|
91 |
-
$address = $addresses[0];
|
92 |
-
} else {
|
93 |
-
foreach ($addresses as $addr) {
|
94 |
-
if (in_array('billing', $addr->type())) {
|
95 |
-
$address = $addr;
|
96 |
-
}
|
97 |
-
}
|
98 |
-
}
|
99 |
-
}
|
100 |
-
|
101 |
-
if (Mage::getModel('newsletter/subscriber')->loadByEmail($address->email())->getId()) {
|
102 |
-
$subscription = Mage::getModel('marketingsoftware/abstraction_subscription')
|
103 |
-
->setOriginal(Mage::getModel('newsletter/subscriber')->loadByEmail($address->email()));
|
104 |
-
} else {
|
105 |
-
$subscription = false;
|
106 |
-
}
|
107 |
-
|
108 |
-
$name = is_object($address) ? $address->name() : null;
|
109 |
-
|
110 |
-
$customerId = null;
|
111 |
-
|
112 |
-
if ($customer = $this->_quote->customer()) {
|
113 |
-
$customerId = Mage::helper('marketingsoftware/profile')->getCustomerCopernicaId($customer, $this->_quote->storeview());
|
114 |
-
} else {
|
115 |
-
$customerId = Mage::helper('marketingsoftware/profile')->getEmailCopernicaId($address->email(), $this->_quote->storeview());
|
116 |
-
}
|
117 |
-
|
118 |
-
return array(
|
119 |
-
'customer_id' => $customerId,
|
120 |
-
'store_view' => (string)$this->_quote->storeview(),
|
121 |
-
'firstname' => is_object($name) ? $name->firstname() : null,
|
122 |
-
'middlename' => is_object($name) ? $name->middlename() : null,
|
123 |
-
'lastname' => is_object($name) ? $name->lastname() : null,
|
124 |
-
'email' => $address->email(),
|
125 |
-
'group' => Mage::getModel('customer/group')->load(0)->getCode(),
|
126 |
-
'newsletter' => is_object($subscription) ? $subscription->status() : 'unknown',
|
127 |
-
);
|
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-2015 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_Quote extends Copernica_MarketingSoftware_Model_Copernica_Profile
|
31 |
+
{
|
32 |
+
/**
|
33 |
+
* @var Copernica_MarketingSoftware_Model_Abstraction_Quote
|
34 |
+
*/
|
35 |
+
protected $_quote = false;
|
36 |
+
|
37 |
+
/**
|
38 |
+
* Set the quote object to this object
|
39 |
+
*
|
40 |
+
* @param Copernica_MarketingSoftware_Model_Abstraction_Quote $quote
|
41 |
+
* @return Copernica_MarketingSoftware_Model_Copernica_Profile_Quote
|
42 |
+
*/
|
43 |
+
public function setQuote(Copernica_MarketingSoftware_Model_Abstraction_Quote $quote)
|
44 |
+
{
|
45 |
+
$this->_quote = $quote;
|
46 |
+
|
47 |
+
return $this;
|
48 |
+
}
|
49 |
+
|
50 |
+
/**
|
51 |
+
* Get profile email.
|
52 |
+
*
|
53 |
+
* @return string
|
54 |
+
*/
|
55 |
+
public function email()
|
56 |
+
{
|
57 |
+
$addresses = $this->_quote->addresses();
|
58 |
+
|
59 |
+
foreach ($addresses as $address) {
|
60 |
+
if (in_array('billing', $addr->type())) {
|
61 |
+
return $address->email();
|
62 |
+
}
|
63 |
+
}
|
64 |
+
|
65 |
+
return '';
|
66 |
+
}
|
67 |
+
|
68 |
+
/**
|
69 |
+
* Return store view associated with profile
|
70 |
+
*
|
71 |
+
* @return string
|
72 |
+
*/
|
73 |
+
public function storeView()
|
74 |
+
{
|
75 |
+
return (string)$this->_quote->storeview();
|
76 |
+
}
|
77 |
+
|
78 |
+
/**
|
79 |
+
* Retrieve the data for this object
|
80 |
+
*
|
81 |
+
* @return array
|
82 |
+
*/
|
83 |
+
protected function _data()
|
84 |
+
{
|
85 |
+
$addresses = $this->_quote->addresses();
|
86 |
+
|
87 |
+
$address = null;
|
88 |
+
|
89 |
+
if (is_array($addresses)) {
|
90 |
+
if (count($addresses) == 1) {
|
91 |
+
$address = $addresses[0];
|
92 |
+
} else {
|
93 |
+
foreach ($addresses as $addr) {
|
94 |
+
if (in_array('billing', $addr->type())) {
|
95 |
+
$address = $addr;
|
96 |
+
}
|
97 |
+
}
|
98 |
+
}
|
99 |
+
}
|
100 |
+
|
101 |
+
if (Mage::getModel('newsletter/subscriber')->loadByEmail($address->email())->getId()) {
|
102 |
+
$subscription = Mage::getModel('marketingsoftware/abstraction_subscription')
|
103 |
+
->setOriginal(Mage::getModel('newsletter/subscriber')->loadByEmail($address->email()));
|
104 |
+
} else {
|
105 |
+
$subscription = false;
|
106 |
+
}
|
107 |
+
|
108 |
+
$name = is_object($address) ? $address->name() : null;
|
109 |
+
|
110 |
+
$customerId = null;
|
111 |
+
|
112 |
+
if ($customer = $this->_quote->customer()) {
|
113 |
+
$customerId = Mage::helper('marketingsoftware/profile')->getCustomerCopernicaId($customer, $this->_quote->storeview());
|
114 |
+
} else {
|
115 |
+
$customerId = Mage::helper('marketingsoftware/profile')->getEmailCopernicaId($address->email(), $this->_quote->storeview());
|
116 |
+
}
|
117 |
+
|
118 |
+
return array(
|
119 |
+
'customer_id' => $customerId,
|
120 |
+
'store_view' => (string)$this->_quote->storeview(),
|
121 |
+
'firstname' => is_object($name) ? $name->firstname() : null,
|
122 |
+
'middlename' => is_object($name) ? $name->middlename() : null,
|
123 |
+
'lastname' => is_object($name) ? $name->lastname() : null,
|
124 |
+
'email' => $address->email(),
|
125 |
+
'group' => Mage::getModel('customer/group')->load(0)->getCode(),
|
126 |
+
'newsletter' => is_object($subscription) ? $subscription->status() : 'unknown',
|
127 |
+
);
|
128 |
+
}
|
129 |
+
}
|
app/code/community/Copernica/MarketingSoftware/Model/Copernica/Profile/Subscription.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-2015 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_Subscription extends Copernica_MarketingSoftware_Model_Copernica_Profile
|
31 |
-
{
|
32 |
-
/**
|
33 |
-
* @var Copernica_MarketingSoftware_Model_Abstraction_Subscription
|
34 |
-
*/
|
35 |
-
protected $_abstractSubscription = false;
|
36 |
-
|
37 |
-
/**
|
38 |
-
* Set the subscription object to this object.
|
39 |
-
*
|
40 |
-
* @param Copernica_MarketingSoftware_Model_Abstraction_Subscription $subscription
|
41 |
-
* @return Copernica_MarketingSoftware_Model_Copernica_Profile_Subscription
|
42 |
-
*/
|
43 |
-
public function setSubscription(Copernica_MarketingSoftware_Model_Abstraction_Subscription $subscription)
|
44 |
-
{
|
45 |
-
$this->_abstractSubscription = $subscription;
|
46 |
-
|
47 |
-
return $this;
|
48 |
-
}
|
49 |
-
|
50 |
-
/**
|
51 |
-
* Get profile email.
|
52 |
-
*
|
53 |
-
* @return string
|
54 |
-
*/
|
55 |
-
public function email()
|
56 |
-
{
|
57 |
-
return (string)$this->_abstractSubscription->storeView();
|
58 |
-
}
|
59 |
-
|
60 |
-
/**
|
61 |
-
* Return store view associated with profile
|
62 |
-
*
|
63 |
-
* @return string
|
64 |
-
*/
|
65 |
-
public function storeView()
|
66 |
-
{
|
67 |
-
return (string)$this->_abstractSubscription->storeview();
|
68 |
-
}
|
69 |
-
|
70 |
-
/**
|
71 |
-
* Retrieve the data for this object.
|
72 |
-
*
|
73 |
-
* @return array
|
74 |
-
*/
|
75 |
-
protected function _data()
|
76 |
-
{
|
77 |
-
$customerId = null;
|
78 |
-
|
79 |
-
if ($customer = $this->_abstractSubscription->customer()) {
|
80 |
-
$customerId = Mage::helper('marketingsoftware/profile')->getCustomerCopernicaId($customer, $this->_abstractSubscription->storeView());
|
81 |
-
} else {
|
82 |
-
$customerId = Mage::helper('marketingsoftware/profile')->getEmailCopernicaId($this->_abstractSubscription->email(), $this->_abstractSubscription->storeView());
|
83 |
-
}
|
84 |
-
|
85 |
-
return array(
|
86 |
-
'customer_id' => $customerId,
|
87 |
-
'store_view' => (string)$this->_abstractSubscription->storeView(),
|
88 |
-
'email' => $this->_abstractSubscription->email(),
|
89 |
-
'group' => Mage::getModel('customer/group')->load(0)->getCode(),
|
90 |
-
'newsletter' => $this->_abstractSubscription->status(),
|
91 |
-
);
|
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-2015 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_Subscription extends Copernica_MarketingSoftware_Model_Copernica_Profile
|
31 |
+
{
|
32 |
+
/**
|
33 |
+
* @var Copernica_MarketingSoftware_Model_Abstraction_Subscription
|
34 |
+
*/
|
35 |
+
protected $_abstractSubscription = false;
|
36 |
+
|
37 |
+
/**
|
38 |
+
* Set the subscription object to this object.
|
39 |
+
*
|
40 |
+
* @param Copernica_MarketingSoftware_Model_Abstraction_Subscription $subscription
|
41 |
+
* @return Copernica_MarketingSoftware_Model_Copernica_Profile_Subscription
|
42 |
+
*/
|
43 |
+
public function setSubscription(Copernica_MarketingSoftware_Model_Abstraction_Subscription $subscription)
|
44 |
+
{
|
45 |
+
$this->_abstractSubscription = $subscription;
|
46 |
+
|
47 |
+
return $this;
|
48 |
+
}
|
49 |
+
|
50 |
+
/**
|
51 |
+
* Get profile email.
|
52 |
+
*
|
53 |
+
* @return string
|
54 |
+
*/
|
55 |
+
public function email()
|
56 |
+
{
|
57 |
+
return (string)$this->_abstractSubscription->storeView();
|
58 |
+
}
|
59 |
+
|
60 |
+
/**
|
61 |
+
* Return store view associated with profile
|
62 |
+
*
|
63 |
+
* @return string
|
64 |
+
*/
|
65 |
+
public function storeView()
|
66 |
+
{
|
67 |
+
return (string)$this->_abstractSubscription->storeview();
|
68 |
+
}
|
69 |
+
|
70 |
+
/**
|
71 |
+
* Retrieve the data for this object.
|
72 |
+
*
|
73 |
+
* @return array
|
74 |
+
*/
|
75 |
+
protected function _data()
|
76 |
+
{
|
77 |
+
$customerId = null;
|
78 |
+
|
79 |
+
if ($customer = $this->_abstractSubscription->customer()) {
|
80 |
+
$customerId = Mage::helper('marketingsoftware/profile')->getCustomerCopernicaId($customer, $this->_abstractSubscription->storeView());
|
81 |
+
} else {
|
82 |
+
$customerId = Mage::helper('marketingsoftware/profile')->getEmailCopernicaId($this->_abstractSubscription->email(), $this->_abstractSubscription->storeView());
|
83 |
+
}
|
84 |
+
|
85 |
+
return array(
|
86 |
+
'customer_id' => $customerId,
|
87 |
+
'store_view' => (string)$this->_abstractSubscription->storeView(),
|
88 |
+
'email' => $this->_abstractSubscription->email(),
|
89 |
+
'group' => Mage::getModel('customer/group')->load(0)->getCode(),
|
90 |
+
'newsletter' => $this->_abstractSubscription->status(),
|
91 |
+
);
|
92 |
+
}
|
93 |
+
}
|
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-2015 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-2015 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-2015 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-2015 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.php
ADDED
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* This file holds the implmentation of the Copernica_MarketingSoftware_Model_Error class.
|
4 |
+
* Copernica Marketing Software v 1.2.0
|
5 |
+
* March 2011
|
6 |
+
* http://www.copernica.com/
|
7 |
+
*/
|
8 |
+
|
9 |
+
/**
|
10 |
+
* All error codes that are defined
|
11 |
+
*/
|
12 |
+
define('COPERNICAERROR_UNREACHABLE', 1); // The SOAP API is unreachable
|
13 |
+
define('COPERNICAERROR_LOGINFAILURE', 2); // The login information for the API is not correct
|
14 |
+
define('COPERNICAERROR_NODATABASE', 3); // The database does not exist, or could not be created
|
15 |
+
define('COPERNICAERROR_INVALIDDATABASE', 4); // The database structure is wrong
|
16 |
+
define('COPERNICAERROR_NOCOLLECTION', 5); // The collection does not exist, or could not created
|
17 |
+
define('COPERNICAERROR_DEFAULTFIELDSEXISTS', 6); // The database default fields already exists
|
18 |
+
define('COPERNICAERROR_NOFIELD', 7); // The field doesn't exists
|
19 |
+
define('COPERNICAERROR_CANNOTCREATEFIELD', 8); // The field can't be created
|
20 |
+
define('COPERNICAERROR_NOCOLLECTIONFIELDS', 9); // The default collection fields set doesn't exists
|
21 |
+
define('COPERNICAERROR_NOCOLLECTIONFIELDSMISSING', 10); // There aren't any default collection fields missing
|
22 |
+
define('COPERNICAERROR_PCNTLNOTENABLED', 11); // The PCNTL module is not enabled
|
23 |
+
define('COPERNICAERROR_CLINOTENABLED', 12); // The CLI is not enabled
|
24 |
+
define('COPERNICAERROR_SOAPNOTENABLED', 13); // The SOAP is not enabled
|
25 |
+
define('COPERNICAERROR_CURLNOTENABLED', 14); // The CURL is not enabled
|
26 |
+
define('COPERNICAERROR_CANNOTSEARCHPROFILE', 15); // Cannot search profile
|
27 |
+
define('COPERNICAERROR_CANNOTUPDATESUBPROFILE', 16); // Cannot update subprofile
|
28 |
+
define('COPERNICAERROR_CANNOTMATCHPROFILE', 17); // Cannot match the profile
|
29 |
+
define('COPERNICAERROR_CANNOTREMOVESUBPROFILE', 18); // Cannot remove the subprofile
|
30 |
+
define('COPERNICAERROR_LOGINNOTVALID', 19); // The login credentials/hostname are not valid
|
31 |
+
define('COPERNICAERROR_FIELDLINKSNOTVALID', 20); // Not all required fields are linked
|
32 |
+
define('COPERNICAERROR_UPGRADEWARNING118', 21); // We upgraded to this version, so a warning has to given
|
33 |
+
define('COPERNICAERROR_UNRECOGNIZEDEVENT', 22);
|
34 |
+
|
35 |
+
/**
|
36 |
+
* Instances of the Copernica_MarketingSoftware_Model_Error class are returned whenever our Model and API
|
37 |
+
* objects need to report an error
|
38 |
+
*/
|
39 |
+
class CopernicaError extends Exception
|
40 |
+
{
|
41 |
+
/**
|
42 |
+
* Construct the exception
|
43 |
+
* @param integer numeric value indicating a certain error message
|
44 |
+
*/
|
45 |
+
public function __construct($code)
|
46 |
+
{
|
47 |
+
$this->code = $code;
|
48 |
+
parent::__construct($this->getDescription(), $code);
|
49 |
+
}
|
50 |
+
|
51 |
+
/**
|
52 |
+
* Return an string representation
|
53 |
+
* @return string
|
54 |
+
*/
|
55 |
+
public function __toString()
|
56 |
+
{
|
57 |
+
return $this->getDescription();
|
58 |
+
}
|
59 |
+
|
60 |
+
/**
|
61 |
+
* Return an error description
|
62 |
+
* @return string
|
63 |
+
*/
|
64 |
+
public function getDescription()
|
65 |
+
{
|
66 |
+
// we loop throught our error codes to send back the error description
|
67 |
+
switch ($this->code)
|
68 |
+
{
|
69 |
+
case COPERNICAERROR_UNREACHABLE:
|
70 |
+
return "Invalid hostname. Please use the following example as format: http://publisher.copernica.nl";
|
71 |
+
case COPERNICAERROR_LOGINFAILURE:
|
72 |
+
return "Invalid credentials, please check your accountname, username and password.";
|
73 |
+
case COPERNICAERROR_NODATABASE:
|
74 |
+
return "The database does not exist";
|
75 |
+
case COPERNICAERROR_INVALIDDATABASE:
|
76 |
+
return "notvalid";
|
77 |
+
case COPERNICAERROR_NOCOLLECTION:
|
78 |
+
return "One of the collections does not exist";
|
79 |
+
case COPERNICAERROR_DEFAULTFIELDSEXISTS:
|
80 |
+
return "The database default fields already exists";
|
81 |
+
case COPERNICAERROR_NOFIELD:
|
82 |
+
return "notexists";
|
83 |
+
case COPERNICAERROR_CANNOTCREATEFIELD:
|
84 |
+
return "notexists";
|
85 |
+
case COPERNICAERROR_NOCOLLECTIONFIELDS:
|
86 |
+
return "notvalid";
|
87 |
+
case COPERNICAERROR_NOCOLLECTIONFIELDSMISSING:
|
88 |
+
return "There aren't any default collection fields missing";
|
89 |
+
case COPERNICAERROR_PCNTLNOTENABLED:
|
90 |
+
return "Warning: The PCNTL module is not enabled in your PHP installation. You need this module to activate Copernica background processing feature.";
|
91 |
+
case COPERNICAERROR_CLINOTENABLED:
|
92 |
+
return "Warning: The CLI (command line) module is not enabled in your PHP installation. You need this module to activate Copernica background processing feature.";
|
93 |
+
case COPERNICAERROR_SOAPNOTENABLED:
|
94 |
+
return "Error: The SOAP module is not enabled in your PHP installation. You need this module to activate Copernica extension";
|
95 |
+
case COPERNICAERROR_CURLNOTENABLED:
|
96 |
+
return "Error: The CURL module is not enabled in your PHP installation, and 'allow_url_fopen' is set to 'Off' in your php.ini configuration. To activate the Copernica extension, either the allow_url_fopen setting should be set to 'On' or the CURL module should be installed";
|
97 |
+
case COPERNICAERROR_LOGINNOTVALID:
|
98 |
+
return "Error: The supplied hostname and/or credentials are not correct, you must <a href=\"../settings/\">correct this</a> in order to make the plugin function.";
|
99 |
+
case COPERNICAERROR_FIELDLINKSNOTVALID:
|
100 |
+
return "Error: Some of the required fields are not linked, you must <a href=\"../link/\">correct this</a> in order to make the plugin function.";
|
101 |
+
case COPERNICAERROR_CANNOTSEARCHPROFILE:
|
102 |
+
return "Cannot search profile";
|
103 |
+
case COPERNICAERROR_CANNOTUPDATESUBPROFILE:
|
104 |
+
return "Cannot update subprofile";
|
105 |
+
case COPERNICAERROR_CANNOTMATCHPROFILE:
|
106 |
+
return "Cannot match the profile";
|
107 |
+
case COPERNICAERROR_CANNOTREMOVESUBPROFILE:
|
108 |
+
return "Cannot remove the subprofile";
|
109 |
+
case COPERNICAERROR_UNRECOGNIZEDEVENT:
|
110 |
+
return "This event has not been recognized.";
|
111 |
+
default:
|
112 |
+
return "There has been an error with your request";
|
113 |
+
}
|
114 |
+
}
|
115 |
+
}
|
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-2015 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-2015 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/Marketingsoftware.php
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Copernica_MarketingSoftware_Model_MarketingSoftware extends Varien_Object
|
3 |
+
{
|
4 |
+
/**
|
5 |
+
* Holds API object
|
6 |
+
*
|
7 |
+
* @var Copernica_MarketingSoftware_Helper_Api
|
8 |
+
*/
|
9 |
+
protected $_api;
|
10 |
+
|
11 |
+
/**
|
12 |
+
* Get the API helper object with the settings as defined in the config.
|
13 |
+
*
|
14 |
+
* @return Copernica_MarketingSoftware_Helper_Api
|
15 |
+
*/
|
16 |
+
public function api()
|
17 |
+
{
|
18 |
+
if (!$this->_api) {
|
19 |
+
// Get the config helper
|
20 |
+
$config = Mage::helper('marketingsoftware/config');
|
21 |
+
|
22 |
+
// Get an api which is logged on on the right Copernica env
|
23 |
+
$this->_api = Mage::helper('marketingsoftware/api')->init(
|
24 |
+
$config->getHostname(),
|
25 |
+
$config->getUsername(),
|
26 |
+
$config->getAccount(),
|
27 |
+
$config->getPassword()
|
28 |
+
);
|
29 |
+
}
|
30 |
+
|
31 |
+
// Return the api object
|
32 |
+
return $this->_api;
|
33 |
+
}
|
34 |
+
}
|
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-2015 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-2015 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-2015 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-2015 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-2015 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-2015 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-2015 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-2015 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-2015 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-2015 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-2015 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-2015 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-2015 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-2015 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.php
CHANGED
@@ -1,62 +1,62 @@
|
|
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-2015 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 extends Mage_Core_Model_Mysql4_Abstract
|
28 |
-
{
|
29 |
-
/**
|
30 |
-
* Construct the object and initialize the values
|
31 |
-
*/
|
32 |
-
protected function _construct()
|
33 |
-
{
|
34 |
-
$this->_init('marketingsoftware/queue_item', 'id');
|
35 |
-
}
|
36 |
-
|
37 |
-
/**
|
38 |
-
* Get first free lock that can be aqcuired
|
39 |
-
*
|
40 |
-
* @return string|false
|
41 |
-
*/
|
42 |
-
public function getFirstFree()
|
43 |
-
{
|
44 |
-
$adapter = $this->_getReadAdapter();
|
45 |
-
|
46 |
-
$result = $adapter->query('SELECT DISTINCT customer FROM '.$this->getMainTable().';')->fetchAll();
|
47 |
-
|
48 |
-
foreach ($result as $row) {
|
49 |
-
$lockResult = $adapter->query("select is_free_lock('COPERNICA_".$row['customer']."') as 'lock'")->fetchAll();
|
50 |
-
|
51 |
-
if ($lockResult[0]['lock']) {
|
52 |
-
$lockResult = $adapter->query("select get_lock('COPERNICA_".$row['customer']."', 1) as 'lock'")->fetchAll();
|
53 |
-
|
54 |
-
if ($lockResult[0]['lock'] == 1) {
|
55 |
-
return $row['customer'];
|
56 |
-
}
|
57 |
-
}
|
58 |
-
}
|
59 |
-
|
60 |
-
return false;
|
61 |
-
}
|
62 |
-
}
|
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-2015 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 extends Mage_Core_Model_Mysql4_Abstract
|
28 |
+
{
|
29 |
+
/**
|
30 |
+
* Construct the object and initialize the values
|
31 |
+
*/
|
32 |
+
protected function _construct()
|
33 |
+
{
|
34 |
+
$this->_init('marketingsoftware/queue_item', 'id');
|
35 |
+
}
|
36 |
+
|
37 |
+
/**
|
38 |
+
* Get first free lock that can be aqcuired
|
39 |
+
*
|
40 |
+
* @return string|false
|
41 |
+
*/
|
42 |
+
public function getFirstFree()
|
43 |
+
{
|
44 |
+
$adapter = $this->_getReadAdapter();
|
45 |
+
|
46 |
+
$result = $adapter->query('SELECT DISTINCT customer FROM '.$this->getMainTable().';')->fetchAll();
|
47 |
+
|
48 |
+
foreach ($result as $row) {
|
49 |
+
$lockResult = $adapter->query("select is_free_lock('COPERNICA_".$row['customer']."') as 'lock'")->fetchAll();
|
50 |
+
|
51 |
+
if ($lockResult[0]['lock']) {
|
52 |
+
$lockResult = $adapter->query("select get_lock('COPERNICA_".$row['customer']."', 1) as 'lock'")->fetchAll();
|
53 |
+
|
54 |
+
if ($lockResult[0]['lock'] == 1) {
|
55 |
+
return $row['customer'];
|
56 |
+
}
|
57 |
+
}
|
58 |
+
}
|
59 |
+
|
60 |
+
return false;
|
61 |
+
}
|
62 |
+
}
|
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-2015 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-2015 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-2015 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-2015 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-2015 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-2015 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/Observer.php
CHANGED
@@ -108,7 +108,7 @@ class Copernica_MarketingSoftware_Model_Observer
|
|
108 |
$quoteItemData = array(
|
109 |
'item_id' => $quoteItemEntity->getId(),
|
110 |
'storeview_id' => $quoteItemEntity->getStoreView()->id(),
|
111 |
-
'status' => 'deleted',
|
112 |
);
|
113 |
|
114 |
$queue = Mage::getModel('marketingsoftware/queue_item')
|
108 |
$quoteItemData = array(
|
109 |
'item_id' => $quoteItemEntity->getId(),
|
110 |
'storeview_id' => $quoteItemEntity->getStoreView()->id(),
|
111 |
+
'status' => 'deleted',
|
112 |
);
|
113 |
|
114 |
$queue = Mage::getModel('marketingsoftware/queue_item')
|
app/code/community/Copernica/MarketingSoftware/Model/PomSoapClient.php
ADDED
@@ -0,0 +1,280 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copernica Soap Client
|
4 |
+
* @version 1.1
|
5 |
+
*/
|
6 |
+
class Copernica_MarketingSoftware_Model_PomSoapClient extends SoapClient
|
7 |
+
{
|
8 |
+
/**
|
9 |
+
* Sets connection settings
|
10 |
+
* @param string URL of the application
|
11 |
+
* @param string Login name
|
12 |
+
* @param string Account name
|
13 |
+
* @param string Password
|
14 |
+
*/
|
15 |
+
public function __construct($connectionSettings)
|
16 |
+
{
|
17 |
+
// parameters for the SOAP connection
|
18 |
+
$params = array(
|
19 |
+
'soap_version' => SOAP_1_1,
|
20 |
+
'cache_wsdl' => WSDL_CACHE_BOTH,
|
21 |
+
'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP,
|
22 |
+
);
|
23 |
+
|
24 |
+
// url of the wsdl
|
25 |
+
$url = $connectionSettings['url']."?SOAPAPI=WSDL";
|
26 |
+
|
27 |
+
// create connection
|
28 |
+
parent::__construct($url, $params);
|
29 |
+
|
30 |
+
// try to login
|
31 |
+
// @todo check session time
|
32 |
+
$result = $this->login(array(
|
33 |
+
'username' => $connectionSettings['login'],
|
34 |
+
'password' => $connectionSettings['password'],
|
35 |
+
'account' => $connectionSettings['account'],
|
36 |
+
));
|
37 |
+
}
|
38 |
+
|
39 |
+
/**
|
40 |
+
* Method that handles the calls to the API
|
41 |
+
* @param string Name of the method
|
42 |
+
* @param array Associative array of parameters
|
43 |
+
* @return mixed
|
44 |
+
*/
|
45 |
+
public function __call($methodname, $params)
|
46 |
+
{
|
47 |
+
// one parameter is required
|
48 |
+
$params = count($params) == 0 ? array() : $params[0];
|
49 |
+
|
50 |
+
// check if the first param was an array
|
51 |
+
if (!is_array($params)) trigger_error("Invalid parameters, array is required");
|
52 |
+
|
53 |
+
// convert the parameters
|
54 |
+
foreach ($params as $key => $value)
|
55 |
+
{
|
56 |
+
// check the type of the value, and so some conversions
|
57 |
+
if (self::isAssoc($value)) {
|
58 |
+
$params[$key] = self::encodeAssoc($value);
|
59 |
+
} elseif (is_array($value)) {
|
60 |
+
$params[$key] = self::encodeArray($value);
|
61 |
+
} elseif (is_object($value)) {
|
62 |
+
$params[$key] = self::encodeObject($value);
|
63 |
+
} else {
|
64 |
+
$params[$key] = $value;
|
65 |
+
}
|
66 |
+
}
|
67 |
+
|
68 |
+
// convert the parameters to an object
|
69 |
+
$params = self::toObject($params);
|
70 |
+
|
71 |
+
// call the method
|
72 |
+
$result = parent::__call($methodname, array($params));
|
73 |
+
|
74 |
+
return self::decodeResult($result);
|
75 |
+
}
|
76 |
+
|
77 |
+
/**
|
78 |
+
* Helper method that converts the result
|
79 |
+
* @param object with the result
|
80 |
+
* @return mixed
|
81 |
+
*/
|
82 |
+
private static function decodeResult($result)
|
83 |
+
{
|
84 |
+
// is this a regular, scalar, result?
|
85 |
+
if (isset($result->value)) return $result->value;
|
86 |
+
|
87 |
+
// is this an array result?
|
88 |
+
if (isset($result->array))
|
89 |
+
{
|
90 |
+
// check if there are items
|
91 |
+
if (!isset($result->array->item)) return array();
|
92 |
+
|
93 |
+
// get the items, and make sure they are an array
|
94 |
+
$items = $result->array->item;
|
95 |
+
return array($items);
|
96 |
+
}
|
97 |
+
|
98 |
+
// is this an assoc result
|
99 |
+
if (isset($result->map))
|
100 |
+
{
|
101 |
+
// check if there are pairs
|
102 |
+
if (!isset($result->map->pair)) return array();
|
103 |
+
|
104 |
+
// get the pairs and make sure they are an array
|
105 |
+
$pairs = $result->map->pair;
|
106 |
+
if (!is_array($pairs)) $pairs = array($pairs);
|
107 |
+
|
108 |
+
// loop through the pairs and convert them to an array
|
109 |
+
$result = array();
|
110 |
+
foreach ($pairs as $pair) $result[$pair->key] = $pair->value;
|
111 |
+
return $result;
|
112 |
+
}
|
113 |
+
|
114 |
+
// is this a collection?
|
115 |
+
if (isset($result->start) && isset($result->length) && isset($result->total) && isset($result->items))
|
116 |
+
{
|
117 |
+
// empty array
|
118 |
+
$items = array();
|
119 |
+
|
120 |
+
// what is the name of the collection?
|
121 |
+
$vars = array_keys(get_object_vars($result->items));
|
122 |
+
foreach (array_unique($vars) as $membername)
|
123 |
+
{
|
124 |
+
// get the members
|
125 |
+
$members = isset($result->items->$membername) ? $result->items->$membername : array();
|
126 |
+
if (!is_array($members)) $members = array($members);
|
127 |
+
|
128 |
+
// loop through the members
|
129 |
+
foreach ($members as $member)
|
130 |
+
{
|
131 |
+
// replace the items
|
132 |
+
$items[] = self::decodeObject($member);
|
133 |
+
}
|
134 |
+
}
|
135 |
+
|
136 |
+
// done
|
137 |
+
$result->items = $items;
|
138 |
+
return $result;
|
139 |
+
}
|
140 |
+
|
141 |
+
// finally, we assume this is an entity
|
142 |
+
$vars = array_keys(get_object_vars($result));
|
143 |
+
if (count($vars) == 0) return false;
|
144 |
+
$membername = $vars[0];
|
145 |
+
|
146 |
+
// return just the member
|
147 |
+
return self::decodeObject($result->$membername);
|
148 |
+
}
|
149 |
+
|
150 |
+
/**
|
151 |
+
* Encode an associative array to be used as parameter
|
152 |
+
* @param associative array
|
153 |
+
* @return array
|
154 |
+
*/
|
155 |
+
private static function encodeAssoc($array)
|
156 |
+
{
|
157 |
+
// we are going to construct an array of pairs
|
158 |
+
$pairs = array();
|
159 |
+
|
160 |
+
// loop through all keys and values in the array
|
161 |
+
foreach ($array as $key => $value)
|
162 |
+
{
|
163 |
+
// check if the assoc array is nested
|
164 |
+
if ((!is_scalar($key) && !is_null($key)) || (!is_scalar($value) && !is_null($value)))
|
165 |
+
{
|
166 |
+
trigger_error('Nested assoc array is not supported');
|
167 |
+
continue;
|
168 |
+
}
|
169 |
+
|
170 |
+
// create a pair
|
171 |
+
$pairs[] = self::toObject(array('key' => $key, 'value' => $value));
|
172 |
+
}
|
173 |
+
|
174 |
+
// done
|
175 |
+
return $pairs;
|
176 |
+
}
|
177 |
+
|
178 |
+
/**
|
179 |
+
* Encode a normal array to be used as parameter
|
180 |
+
* @param Normal array
|
181 |
+
* @return array
|
182 |
+
*/
|
183 |
+
private static function encodeArray($array)
|
184 |
+
{
|
185 |
+
// the result array
|
186 |
+
$result = array();
|
187 |
+
|
188 |
+
// loop through the values
|
189 |
+
foreach ($array as $value)
|
190 |
+
{
|
191 |
+
// array values should be objects
|
192 |
+
if (is_object($value)) $result[] = self::encodeObject($value);
|
193 |
+
elseif (is_array($value)) trigger_error('Invalid parameter: arrays of objects are not supported');
|
194 |
+
else $result[] = $value;
|
195 |
+
}
|
196 |
+
|
197 |
+
// done
|
198 |
+
return $result;
|
199 |
+
}
|
200 |
+
|
201 |
+
/**
|
202 |
+
* Encode an object to be used as parameter
|
203 |
+
* @param object
|
204 |
+
* @return object
|
205 |
+
*/
|
206 |
+
private static function encodeObject($object)
|
207 |
+
{
|
208 |
+
// result object
|
209 |
+
$result = new stdClass();
|
210 |
+
|
211 |
+
// loop through the object vars
|
212 |
+
foreach (get_object_vars($object) as $key => $value)
|
213 |
+
{
|
214 |
+
// check if the assoc array is nested
|
215 |
+
if ((!is_scalar($key) && !is_null($key)) || (!is_scalar($value) && !is_null($value)))
|
216 |
+
{
|
217 |
+
trigger_error('Nested object is not supported');
|
218 |
+
continue;
|
219 |
+
}
|
220 |
+
|
221 |
+
// add the var
|
222 |
+
$result->$key = $value;
|
223 |
+
}
|
224 |
+
|
225 |
+
// done
|
226 |
+
return $result;
|
227 |
+
}
|
228 |
+
|
229 |
+
/**
|
230 |
+
* Decode an object to be used as result
|
231 |
+
* @param object
|
232 |
+
* @return object
|
233 |
+
*/
|
234 |
+
private static function decodeObject($object)
|
235 |
+
{
|
236 |
+
// result object
|
237 |
+
$result = new stdClass();
|
238 |
+
|
239 |
+
// loop through the object vars
|
240 |
+
foreach (get_object_vars($object) as $key => $value)
|
241 |
+
{
|
242 |
+
if (is_object($value)) $value = self::decodeObject($value);
|
243 |
+
|
244 |
+
// add the var
|
245 |
+
$result->$key = $value;
|
246 |
+
}
|
247 |
+
|
248 |
+
// done
|
249 |
+
return $result;
|
250 |
+
}
|
251 |
+
|
252 |
+
/**
|
253 |
+
* Helper function checks if an array is associative
|
254 |
+
* @param array
|
255 |
+
* @return boolean
|
256 |
+
*/
|
257 |
+
public static function isAssoc($array)
|
258 |
+
{
|
259 |
+
if (!is_array($array)) return false;
|
260 |
+
foreach (array_keys($array) as $k => $v)
|
261 |
+
{
|
262 |
+
if ($k !== $v) return true;
|
263 |
+
}
|
264 |
+
return false;
|
265 |
+
}
|
266 |
+
|
267 |
+
/**
|
268 |
+
* Helper function that maps an assoc array to an object
|
269 |
+
* @param associative array
|
270 |
+
* @return object
|
271 |
+
*/
|
272 |
+
public static function toObject($array)
|
273 |
+
{
|
274 |
+
$object = new stdClass();
|
275 |
+
foreach ($array as $key => $value) $object->$key = $value;
|
276 |
+
return $object;
|
277 |
+
}
|
278 |
+
}
|
279 |
+
|
280 |
+
?>
|
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-2015 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-2015 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-2015 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-2015 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-2015 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->
|
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-2015 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->getAllItems() as $quoteItem) {
|
84 |
+
$quoteItemEntity = Mage::getModel('marketingsoftware/copernica_entity_quote_item');
|
85 |
+
$quoteItemEntity->setQuoteItem($quoteItem);
|
86 |
+
|
87 |
+
$restQuoteItem = $quoteItemEntity->getRestQuoteItem();
|
88 |
+
$restQuoteItem->syncWithQuote($customerEntity, $quote->getId());
|
89 |
+
}
|
90 |
+
}
|
91 |
+
|
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,140 +1,140 @@
|
|
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-2015 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 |
-
return true;
|
61 |
-
}
|
62 |
-
|
63 |
-
/**
|
64 |
-
* Handle customer full sync action. This action should be called only when
|
65 |
-
* we want to sync whole customer. For example initial data sync when
|
66 |
-
* extension is installed for 1st time, or when changing copernica database.
|
67 |
-
*
|
68 |
-
* This action is expensive both with time and resources. It should be called
|
69 |
-
* only when there is a need for that.
|
70 |
-
*
|
71 |
-
* @return boolean
|
72 |
-
*/
|
73 |
-
public function actionFull()
|
74 |
-
{
|
75 |
-
$customerEntity = Mage::getModel('marketingsoftware/copernica_entity_customer');
|
76 |
-
$customerEntity->setCustomer($this->_getEntityId());
|
77 |
-
|
78 |
-
$restCustomer = $customerEntity->getRestCustomer();
|
79 |
-
$restCustomer->setProfile();
|
80 |
-
|
81 |
-
foreach ($customerEntity->getOrders() as $orderEntity) {
|
82 |
-
$restOrder = $orderEntity->getRestOrder();
|
83 |
-
$restOrder->syncWithCustomer($customerEntity);
|
84 |
-
}
|
85 |
-
|
86 |
-
foreach($customerEntity->getWishlistItems() as $wishlistItemEntity) {
|
87 |
-
$restWishlistItem = $wishlistItemEntity->getRestWishlistItem();
|
88 |
-
$restWishlistItem->syncWithCustomer($customerEntity);
|
89 |
-
}
|
90 |
-
|
91 |
-
//$request->commit();
|
92 |
-
|
93 |
-
return true;
|
94 |
-
}
|
95 |
-
|
96 |
-
/**
|
97 |
-
* This action should be called only when there is a need to remove a customer
|
98 |
-
* from copernica platform.
|
99 |
-
*
|
100 |
-
* @return boolean
|
101 |
-
*/
|
102 |
-
public function actionRemove()
|
103 |
-
{
|
104 |
-
$object = $this->_getObject();
|
105 |
-
|
106 |
-
if (property_exists($object, 'email') && property_exists($object, 'storeId')) {
|
107 |
-
$store = Mage::getModel('core/store')->load($object->storeId);
|
108 |
-
|
109 |
-
$website = $store->getWebsite();
|
110 |
-
|
111 |
-
$group = $store->getGroup();
|
112 |
-
|
113 |
-
$storeView = implode(' > ', array (
|
114 |
-
$website->getName(),
|
115 |
-
$group->getName(),
|
116 |
-
$store->getName())
|
117 |
-
);
|
118 |
-
|
119 |
-
$profileCacheCollection = Mage::getModel('marketingsoftware/profile_cache')
|
120 |
-
->getCollection()
|
121 |
-
->setPageSize(1)
|
122 |
-
->addFieldToFilter('email', $object->email)
|
123 |
-
->addFieldToFilter('store_view', $storeView);
|
124 |
-
|
125 |
-
$profileCache = $profileCacheCollection->getFirstItem();
|
126 |
-
|
127 |
-
if (!$profileCache->isObjectNew()) {
|
128 |
-
$profileCache->delete();
|
129 |
-
}
|
130 |
-
}
|
131 |
-
|
132 |
-
if (!property_exists($object, 'profileId')) {
|
133 |
-
return false;
|
134 |
-
}
|
135 |
-
|
136 |
-
Mage::helper('marketingsoftware/rest_request')->delete('/profile/'.$object->profileId);
|
137 |
-
|
138 |
-
return true;
|
139 |
-
}
|
140 |
-
}
|
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-2015 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 |
+
return true;
|
61 |
+
}
|
62 |
+
|
63 |
+
/**
|
64 |
+
* Handle customer full sync action. This action should be called only when
|
65 |
+
* we want to sync whole customer. For example initial data sync when
|
66 |
+
* extension is installed for 1st time, or when changing copernica database.
|
67 |
+
*
|
68 |
+
* This action is expensive both with time and resources. It should be called
|
69 |
+
* only when there is a need for that.
|
70 |
+
*
|
71 |
+
* @return boolean
|
72 |
+
*/
|
73 |
+
public function actionFull()
|
74 |
+
{
|
75 |
+
$customerEntity = Mage::getModel('marketingsoftware/copernica_entity_customer');
|
76 |
+
$customerEntity->setCustomer($this->_getEntityId());
|
77 |
+
|
78 |
+
$restCustomer = $customerEntity->getRestCustomer();
|
79 |
+
$restCustomer->setProfile();
|
80 |
+
|
81 |
+
foreach ($customerEntity->getOrders() as $orderEntity) {
|
82 |
+
$restOrder = $orderEntity->getRestOrder();
|
83 |
+
$restOrder->syncWithCustomer($customerEntity);
|
84 |
+
}
|
85 |
+
|
86 |
+
foreach($customerEntity->getWishlistItems() as $wishlistItemEntity) {
|
87 |
+
$restWishlistItem = $wishlistItemEntity->getRestWishlistItem();
|
88 |
+
$restWishlistItem->syncWithCustomer($customerEntity);
|
89 |
+
}
|
90 |
+
|
91 |
+
//$request->commit();
|
92 |
+
|
93 |
+
return true;
|
94 |
+
}
|
95 |
+
|
96 |
+
/**
|
97 |
+
* This action should be called only when there is a need to remove a customer
|
98 |
+
* from copernica platform.
|
99 |
+
*
|
100 |
+
* @return boolean
|
101 |
+
*/
|
102 |
+
public function actionRemove()
|
103 |
+
{
|
104 |
+
$object = $this->_getObject();
|
105 |
+
|
106 |
+
if (property_exists($object, 'email') && property_exists($object, 'storeId')) {
|
107 |
+
$store = Mage::getModel('core/store')->load($object->storeId);
|
108 |
+
|
109 |
+
$website = $store->getWebsite();
|
110 |
+
|
111 |
+
$group = $store->getGroup();
|
112 |
+
|
113 |
+
$storeView = implode(' > ', array (
|
114 |
+
$website->getName(),
|
115 |
+
$group->getName(),
|
116 |
+
$store->getName())
|
117 |
+
);
|
118 |
+
|
119 |
+
$profileCacheCollection = Mage::getModel('marketingsoftware/profile_cache')
|
120 |
+
->getCollection()
|
121 |
+
->setPageSize(1)
|
122 |
+
->addFieldToFilter('email', $object->email)
|
123 |
+
->addFieldToFilter('store_view', $storeView);
|
124 |
+
|
125 |
+
$profileCache = $profileCacheCollection->getFirstItem();
|
126 |
+
|
127 |
+
if (!$profileCache->isObjectNew()) {
|
128 |
+
$profileCache->delete();
|
129 |
+
}
|
130 |
+
}
|
131 |
+
|
132 |
+
if (!property_exists($object, 'profileId')) {
|
133 |
+
return false;
|
134 |
+
}
|
135 |
+
|
136 |
+
Mage::helper('marketingsoftware/rest_request')->delete('/profile/'.$object->profileId);
|
137 |
+
|
138 |
+
return true;
|
139 |
+
}
|
140 |
+
}
|
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-2015 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-2015 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,178 +1,178 @@
|
|
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-2015 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 |
-
if ($quoteId && $quoteItem->getId()) {
|
168 |
-
$customerEntity = Mage::getModel('marketingsoftware/copernica_entity_customer');
|
169 |
-
$customerEntity->setCustomer($object->customerId);
|
170 |
-
|
171 |
-
$quoteItemEntity = Mage::getModel('marketingsoftware/copernica_entity_quote_item');
|
172 |
-
$quoteItemEntity->setQuoteItem($quoteItem);
|
173 |
-
|
174 |
-
$restQuoteItem = $quoteItemEntity->getRestQuoteItem();
|
175 |
-
$restQuoteItem->syncWithQuote($customerEntity, $quoteId);
|
176 |
-
}
|
177 |
-
}
|
178 |
-
}
|
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-2015 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 |
+
if ($quoteId && $quoteItem->getId()) {
|
168 |
+
$customerEntity = Mage::getModel('marketingsoftware/copernica_entity_customer');
|
169 |
+
$customerEntity->setCustomer($object->customerId);
|
170 |
+
|
171 |
+
$quoteItemEntity = Mage::getModel('marketingsoftware/copernica_entity_quote_item');
|
172 |
+
$quoteItemEntity->setQuoteItem($quoteItem);
|
173 |
+
|
174 |
+
$restQuoteItem = $quoteItemEntity->getRestQuoteItem();
|
175 |
+
$restQuoteItem->syncWithQuote($customerEntity, $quoteId);
|
176 |
+
}
|
177 |
+
}
|
178 |
+
}
|
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-2015 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-2015 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-2015 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) || !$object->storeView) {
|
66 |
-
return false;
|
67 |
-
}
|
68 |
-
|
69 |
-
$quoteItemCollectionId = Mage::helper('marketingsoftware/config')->getQuoteItemCollectionId();
|
70 |
-
|
71 |
-
$customerEntity = Mage::getModel('marketingsoftware/copernica_entity_customer');
|
72 |
-
$customerEntity->setCustomer($object->customerId);
|
73 |
-
|
74 |
-
$profileId = Mage::helper('marketingsoftware/api')->getProfileId(array(
|
75 |
-
'id' => $customerEntity->fetchId(),
|
76 |
-
'storeView' => $object->storeView,
|
77 |
-
'email' => $customerEntity->fetchEmail()
|
78 |
-
));
|
79 |
-
|
80 |
-
$request = Mage::helper('marketingsoftware/rest_request');
|
81 |
-
|
82 |
-
$result = $request->get('/profile/'.$profileId.'/subprofiles/'.$quoteItemCollectionId, array(
|
83 |
-
'fields' => array(
|
84 |
-
'quote_id=='.$this->_getEntityId()
|
85 |
-
)
|
86 |
-
));
|
87 |
-
|
88 |
-
$request->prepare();
|
89 |
-
|
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-2015 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) || !$object->storeView) {
|
66 |
+
return false;
|
67 |
+
}
|
68 |
+
|
69 |
+
$quoteItemCollectionId = Mage::helper('marketingsoftware/config')->getQuoteItemCollectionId();
|
70 |
+
|
71 |
+
$customerEntity = Mage::getModel('marketingsoftware/copernica_entity_customer');
|
72 |
+
$customerEntity->setCustomer($object->customerId);
|
73 |
+
|
74 |
+
$profileId = Mage::helper('marketingsoftware/api')->getProfileId(array(
|
75 |
+
'id' => $customerEntity->fetchId(),
|
76 |
+
'storeView' => $object->storeView,
|
77 |
+
'email' => $customerEntity->fetchEmail()
|
78 |
+
));
|
79 |
+
|
80 |
+
$request = Mage::helper('marketingsoftware/rest_request');
|
81 |
+
|
82 |
+
$result = $request->get('/profile/'.$profileId.'/subprofiles/'.$quoteItemCollectionId, array(
|
83 |
+
'fields' => array(
|
84 |
+
'quote_id=='.$this->_getEntityId()
|
85 |
+
)
|
86 |
+
));
|
87 |
+
|
88 |
+
$request->prepare();
|
89 |
+
|
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-2015 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-2015 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->storeId) {
|
30 |
-
return false;
|
31 |
-
}
|
32 |
-
|
33 |
-
$store = Mage::getModel('core/store')->load($object->storeId);
|
34 |
-
$website = $store->getWebsite();
|
35 |
-
$group = $store->getGroup();
|
36 |
-
|
37 |
-
$storeView = implode(' > ', array (
|
38 |
-
$website->getName(),
|
39 |
-
$group->getName(),
|
40 |
-
$store->getName())
|
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->storeId) {
|
30 |
+
return false;
|
31 |
+
}
|
32 |
+
|
33 |
+
$store = Mage::getModel('core/store')->load($object->storeId);
|
34 |
+
$website = $store->getWebsite();
|
35 |
+
$group = $store->getGroup();
|
36 |
+
|
37 |
+
$storeView = implode(' > ', array (
|
38 |
+
$website->getName(),
|
39 |
+
$group->getName(),
|
40 |
+
$store->getName())
|
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-2015 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->_getObject();
|
40 |
-
|
41 |
-
if (!$object->customerId || !is_numeric($object->customerId) || !$object->productId || !is_numeric($object->productId) || !$object->viewedAt || !is_numeric($object->viewedAt)) {
|
42 |
-
return false;
|
43 |
-
}
|
44 |
-
|
45 |
-
$customerEntity = Mage::getModel('marketingsoftware/copernica_entity_customer');
|
46 |
-
$customerEntity->setCustomer($object->customerId);
|
47 |
-
|
48 |
-
$productEntity = Mage::getModel('marketingsoftware/copernica_entity_product');
|
49 |
-
$productEntity->setProduct($object->productId, $object->storeId);
|
50 |
-
$productEntity->setTimestamp(date('Y-m-d G:i:s', $object->viewedAt));
|
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-2015 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->_getObject();
|
40 |
+
|
41 |
+
if (!$object->customerId || !is_numeric($object->customerId) || !$object->productId || !is_numeric($object->productId) || !$object->viewedAt || !is_numeric($object->viewedAt)) {
|
42 |
+
return false;
|
43 |
+
}
|
44 |
+
|
45 |
+
$customerEntity = Mage::getModel('marketingsoftware/copernica_entity_customer');
|
46 |
+
$customerEntity->setCustomer($object->customerId);
|
47 |
+
|
48 |
+
$productEntity = Mage::getModel('marketingsoftware/copernica_entity_product');
|
49 |
+
$productEntity->setProduct($object->productId, $object->storeId);
|
50 |
+
$productEntity->setTimestamp(date('Y-m-d G:i:s', $object->viewedAt));
|
51 |
+
|
52 |
+
$restProduct = $productEntity->getRestProduct();
|
53 |
+
$restProduct->viewedBy($customerEntity);
|
54 |
+
|
55 |
+
return true;
|
56 |
+
}
|
57 |
+
}
|
app/code/community/Copernica/MarketingSoftware/Model/Queue/Event/Wishlist/Item.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-2015 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 wishlsit changes
|
29 |
-
*/
|
30 |
-
class Copernica_MarketingSoftware_Model_Queue_Event_Wishlist_Item extends Copernica_MarketingSoftware_Model_Queue_Event_Abstract
|
31 |
-
{
|
32 |
-
/**
|
33 |
-
* Add functionality is the same as that of modify
|
34 |
-
*
|
35 |
-
* @return boolean
|
36 |
-
*/
|
37 |
-
public function actionAdd()
|
38 |
-
{
|
39 |
-
return $this->actionModify();
|
40 |
-
}
|
41 |
-
|
42 |
-
/**
|
43 |
-
* Handle modify action
|
44 |
-
*
|
45 |
-
* @return boolean
|
46 |
-
*/
|
47 |
-
public function actionModify()
|
48 |
-
{
|
49 |
-
$object = $this->_getObject();
|
50 |
-
|
51 |
-
if (!$object->wishlistItemId || !is_numeric($object->wishlistItemId) || !$object->customerId || !is_numeric($object->customerId)) {
|
52 |
-
return false;
|
53 |
-
}
|
54 |
-
|
55 |
-
$wishlistItem = Mage::getModel('wishlist/item')->load($object->wishlistItemId);
|
56 |
-
|
57 |
-
$customerId = $object->customerId;
|
58 |
-
|
59 |
-
$wishlistItemEntity = Mage::getModel('marketingsoftware/copernica_entity_wishlist_item');
|
60 |
-
$wishlistItemEntity->setWishlistItem($wishlistItem);
|
61 |
-
|
62 |
-
$customerEntity = Mage::getModel('marketingsoftware/copernica_entity_customer');
|
63 |
-
$customerEntity->setCustomer($customerId);
|
64 |
-
|
65 |
-
$restWishlistItem = $wishlistItemEntity->getRestWishlistItem();
|
66 |
-
$restWishlistItem->syncWithCustomer($customerEntity);
|
67 |
-
|
68 |
-
return true;
|
69 |
-
}
|
70 |
-
|
71 |
-
/**
|
72 |
-
* Handle wishlist removal
|
73 |
-
*
|
74 |
-
* @return boolean
|
75 |
-
*/
|
76 |
-
public function actionRemove()
|
77 |
-
{
|
78 |
-
$object = $this->getObject();
|
79 |
-
|
80 |
-
if (!$object->customerId || !is_numeric($object->customerId)) {
|
81 |
-
return false;
|
82 |
-
}
|
83 |
-
|
84 |
-
$wishlistItemCollectionId = Mage::helper('marketingsoftware/config')->getWishlistItemCollectionId();
|
85 |
-
|
86 |
-
$customerEntity = Mage::getModel('marketingsoftware/copernica_entity_customer');
|
87 |
-
$customerEntity->setCustomer($object->customerId);
|
88 |
-
|
89 |
-
$profileId = Mage::helper('marketingsoftware/api')->getProfileId(array(
|
90 |
-
'id' => $customerEntity->fetchId(),
|
91 |
-
'storeView' => $customerEntity->fetchStoreView(),
|
92 |
-
'email' => $customerEntity->fetchEmail()
|
93 |
-
));
|
94 |
-
|
95 |
-
$request = Mage::helper('marketingsoftware/rest_request');
|
96 |
-
|
97 |
-
$result = $request->get('/profile/'.$profileId.'/subprofiles/'.$wishlistItemCollectionId, array(
|
98 |
-
'fields' => array(
|
99 |
-
'item_id=='.$this->_getEntityId()
|
100 |
-
)
|
101 |
-
));
|
102 |
-
|
103 |
-
$request->prepare();
|
104 |
-
|
105 |
-
if (array_key_exists('data', $result) && is_array($result['data'])) foreach ($result['data'] as $item) {
|
106 |
-
$request->delete('/subprofile/'.$item['ID']);
|
107 |
-
}
|
108 |
-
|
109 |
-
$request->commit();
|
110 |
-
|
111 |
-
return true;
|
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-2015 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 wishlsit changes
|
29 |
+
*/
|
30 |
+
class Copernica_MarketingSoftware_Model_Queue_Event_Wishlist_Item extends Copernica_MarketingSoftware_Model_Queue_Event_Abstract
|
31 |
+
{
|
32 |
+
/**
|
33 |
+
* Add functionality is the same as that of modify
|
34 |
+
*
|
35 |
+
* @return boolean
|
36 |
+
*/
|
37 |
+
public function actionAdd()
|
38 |
+
{
|
39 |
+
return $this->actionModify();
|
40 |
+
}
|
41 |
+
|
42 |
+
/**
|
43 |
+
* Handle modify action
|
44 |
+
*
|
45 |
+
* @return boolean
|
46 |
+
*/
|
47 |
+
public function actionModify()
|
48 |
+
{
|
49 |
+
$object = $this->_getObject();
|
50 |
+
|
51 |
+
if (!$object->wishlistItemId || !is_numeric($object->wishlistItemId) || !$object->customerId || !is_numeric($object->customerId)) {
|
52 |
+
return false;
|
53 |
+
}
|
54 |
+
|
55 |
+
$wishlistItem = Mage::getModel('wishlist/item')->load($object->wishlistItemId);
|
56 |
+
|
57 |
+
$customerId = $object->customerId;
|
58 |
+
|
59 |
+
$wishlistItemEntity = Mage::getModel('marketingsoftware/copernica_entity_wishlist_item');
|
60 |
+
$wishlistItemEntity->setWishlistItem($wishlistItem);
|
61 |
+
|
62 |
+
$customerEntity = Mage::getModel('marketingsoftware/copernica_entity_customer');
|
63 |
+
$customerEntity->setCustomer($customerId);
|
64 |
+
|
65 |
+
$restWishlistItem = $wishlistItemEntity->getRestWishlistItem();
|
66 |
+
$restWishlistItem->syncWithCustomer($customerEntity);
|
67 |
+
|
68 |
+
return true;
|
69 |
+
}
|
70 |
+
|
71 |
+
/**
|
72 |
+
* Handle wishlist removal
|
73 |
+
*
|
74 |
+
* @return boolean
|
75 |
+
*/
|
76 |
+
public function actionRemove()
|
77 |
+
{
|
78 |
+
$object = $this->getObject();
|
79 |
+
|
80 |
+
if (!$object->customerId || !is_numeric($object->customerId)) {
|
81 |
+
return false;
|
82 |
+
}
|
83 |
+
|
84 |
+
$wishlistItemCollectionId = Mage::helper('marketingsoftware/config')->getWishlistItemCollectionId();
|
85 |
+
|
86 |
+
$customerEntity = Mage::getModel('marketingsoftware/copernica_entity_customer');
|
87 |
+
$customerEntity->setCustomer($object->customerId);
|
88 |
+
|
89 |
+
$profileId = Mage::helper('marketingsoftware/api')->getProfileId(array(
|
90 |
+
'id' => $customerEntity->fetchId(),
|
91 |
+
'storeView' => $customerEntity->fetchStoreView(),
|
92 |
+
'email' => $customerEntity->fetchEmail()
|
93 |
+
));
|
94 |
+
|
95 |
+
$request = Mage::helper('marketingsoftware/rest_request');
|
96 |
+
|
97 |
+
$result = $request->get('/profile/'.$profileId.'/subprofiles/'.$wishlistItemCollectionId, array(
|
98 |
+
'fields' => array(
|
99 |
+
'item_id=='.$this->_getEntityId()
|
100 |
+
)
|
101 |
+
));
|
102 |
+
|
103 |
+
$request->prepare();
|
104 |
+
|
105 |
+
if (array_key_exists('data', $result) && is_array($result['data'])) foreach ($result['data'] as $item) {
|
106 |
+
$request->delete('/subprofile/'.$item['ID']);
|
107 |
+
}
|
108 |
+
|
109 |
+
$request->commit();
|
110 |
+
|
111 |
+
return true;
|
112 |
+
}
|
113 |
+
}
|
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-2015 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 |
-
}
|
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-2015 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-2015 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-2015 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/QueueEvent/FileSync.php
ADDED
@@ -0,0 +1,468 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 write all relevant for us data to files. This way Copernica
|
29 |
+
* employees can sync the data withing short time inserting all data directly
|
30 |
+
* into servers rather than dealing with REST API.
|
31 |
+
*/
|
32 |
+
class Copernica_MarketingSoftware_Model_QueueEvent_FileSync extends Copernica_MarketingSoftware_Model_QueueEvent_Abstract
|
33 |
+
{
|
34 |
+
/**
|
35 |
+
* How many entities we want to sync.
|
36 |
+
* By default we will sync 50000 entites at once.
|
37 |
+
* @var int
|
38 |
+
*/
|
39 |
+
private $writesLimit = 50000;
|
40 |
+
|
41 |
+
/**
|
42 |
+
* Upper time limit that will be used to limit number of entities that will
|
43 |
+
* be writted to file. By default we are stting it to 4 minutes (240 seconds).
|
44 |
+
* @var int
|
45 |
+
*/
|
46 |
+
private $timeLimit = 240;
|
47 |
+
|
48 |
+
/**
|
49 |
+
* Time in seconds when we did start form unix epoch. 1 > x > 0 part represetns
|
50 |
+
* nearest micorsecond.
|
51 |
+
* @var float
|
52 |
+
*/
|
53 |
+
private $startTime;
|
54 |
+
|
55 |
+
/**
|
56 |
+
* Current event status.
|
57 |
+
*/
|
58 |
+
private $currentStatus;
|
59 |
+
|
60 |
+
/**
|
61 |
+
* Process event.
|
62 |
+
* @return boolean
|
63 |
+
*/
|
64 |
+
public function process()
|
65 |
+
{
|
66 |
+
// initialize event to be processed
|
67 |
+
$this->init();
|
68 |
+
|
69 |
+
// event should be respawned?
|
70 |
+
$shouldRespawn = false;
|
71 |
+
|
72 |
+
try {
|
73 |
+
// write customers data
|
74 |
+
if($this->writeCustomersData() == $this->writesLimit) {
|
75 |
+
// respawn this event cause we have something to do
|
76 |
+
$this->respawn();
|
77 |
+
|
78 |
+
// we are done here
|
79 |
+
return true;
|
80 |
+
}
|
81 |
+
|
82 |
+
// some of the orders can not have a valid customer instance tied to them
|
83 |
+
// we want to sync them also.
|
84 |
+
if($this->writeOrdersData() == $this->writesLimit){
|
85 |
+
// respawn this event cause we have somethid to do
|
86 |
+
$this->respawn();
|
87 |
+
|
88 |
+
// we are done here
|
89 |
+
return true;
|
90 |
+
}
|
91 |
+
|
92 |
+
// write subscribers data. Some of the subscribers could not be customers.
|
93 |
+
// we want to sync them also.
|
94 |
+
if ($this->writeSubscribersData() == $this->writesLimit) {
|
95 |
+
// respawn this event cause we have something to do
|
96 |
+
$this->respawn();
|
97 |
+
|
98 |
+
// we are done here
|
99 |
+
return true;
|
100 |
+
}
|
101 |
+
}
|
102 |
+
// we are throwing an exception only in one case. When the time limit is
|
103 |
+
// reached. In that case we should stop processing entities and close this
|
104 |
+
// event.
|
105 |
+
catch (Exception $exception) {
|
106 |
+
// nothing special to do really. All data will be closed automatically.
|
107 |
+
|
108 |
+
// if we did reached time limit that means we really should respawn
|
109 |
+
// the event on event queue
|
110 |
+
$this->respawn();
|
111 |
+
}
|
112 |
+
|
113 |
+
// everything went just dandy
|
114 |
+
return true;
|
115 |
+
}
|
116 |
+
|
117 |
+
/**
|
118 |
+
* This method will prepare event to be processed.
|
119 |
+
*/
|
120 |
+
private function init()
|
121 |
+
{
|
122 |
+
// get sync status object
|
123 |
+
$this->currentStatus = $this->getObject();
|
124 |
+
|
125 |
+
// if sum of last processed ids is then we can assume that we are doing
|
126 |
+
// a new sync. So we want to clear old data files so we can make new ones.
|
127 |
+
// if ($this->currentStatus->getLastCustomerId() == 0
|
128 |
+
// && $this->currentStatus->getLastOrderId() == 0
|
129 |
+
// && $this->currentStatus->getLastSubscriptionId() == 0
|
130 |
+
// )
|
131 |
+
// Mage::helper('marketingsoftware/DataWriter')->clearDataFiles();
|
132 |
+
|
133 |
+
// store start time for this event
|
134 |
+
$this->startTime = microtime(true);
|
135 |
+
}
|
136 |
+
|
137 |
+
/**
|
138 |
+
* This event has an internal timer that will keep track how much time left
|
139 |
+
* we have to process entities. This method will tell us if we are reaching
|
140 |
+
* that time or not.
|
141 |
+
* @return boolean
|
142 |
+
*/
|
143 |
+
private function isTimeLimitReached()
|
144 |
+
{
|
145 |
+
return $this->timeLimit < (microtime(true) - $this->startTime);
|
146 |
+
}
|
147 |
+
|
148 |
+
/**
|
149 |
+
* Write customers data to files.
|
150 |
+
* @return int Number of written customers
|
151 |
+
*/
|
152 |
+
private function writeCustomersData()
|
153 |
+
{
|
154 |
+
// counter that will report how many events we did added
|
155 |
+
$addedCustomers = 0;
|
156 |
+
|
157 |
+
// get customeres collection
|
158 |
+
$customersCollection = Mage::getModel('customer/customer')->getCollection();
|
159 |
+
|
160 |
+
// we want to get the collection in certain order
|
161 |
+
$customersCollection->addAttributeToSort('entity_id', 'ASC');
|
162 |
+
|
163 |
+
// set the customers collection
|
164 |
+
$customersCollection->addAttributeToFilter('entity_id', array('gt' => $this->currentStatus->getLastCustomerId() ));
|
165 |
+
|
166 |
+
// set the customers collection
|
167 |
+
$customersCollection->setPageSize($this->writesLimit);
|
168 |
+
|
169 |
+
// iterate over all customers in collection
|
170 |
+
foreach ($customersCollection as $customer) {
|
171 |
+
// write customer data
|
172 |
+
$this->writeCustomer($customer);
|
173 |
+
|
174 |
+
// set new last customer Id
|
175 |
+
$this->currentStatus->setLastCustomerId($customer->getEntityId());
|
176 |
+
|
177 |
+
// increase events counter
|
178 |
+
$addedCustomers++;
|
179 |
+
|
180 |
+
// if we are reaching time limit we should stop processing
|
181 |
+
if ($this->isTimeLimitReached()) {
|
182 |
+
throw new Exception('Time limit reached');
|
183 |
+
}
|
184 |
+
}
|
185 |
+
|
186 |
+
// return number of written customers
|
187 |
+
return $addedCustomers;
|
188 |
+
}
|
189 |
+
|
190 |
+
/**
|
191 |
+
* Write orders data to files.
|
192 |
+
* @return int Number of orders written to file
|
193 |
+
*/
|
194 |
+
private function writeOrdersData()
|
195 |
+
{
|
196 |
+
// counter that will remember number of orders that we did write
|
197 |
+
$addedOrders = 0;
|
198 |
+
|
199 |
+
// get collection of orders
|
200 |
+
$ordersCollection = Mage::getModel('sales/order')->getCollection();
|
201 |
+
|
202 |
+
// we want orders that do not have a proper customer instance
|
203 |
+
$ordersCollection->addFieldToFilter('customer_id', array(
|
204 |
+
'eq' => 0,
|
205 |
+
'null' => true
|
206 |
+
));
|
207 |
+
|
208 |
+
// we want to pick up from where we stoped
|
209 |
+
$ordersCollection->addAttributeToFilter('entity_id', array (
|
210 |
+
'gt' => $this->currentStatus->getLastOrderId()
|
211 |
+
));
|
212 |
+
|
213 |
+
// we want to get collection in certain order
|
214 |
+
$ordersCollection->addAttributeToSort('entity_id', 'ASC');
|
215 |
+
|
216 |
+
// set collections page size to write limit
|
217 |
+
$ordersCollection->setPageSize($this->writesLimit);
|
218 |
+
|
219 |
+
// iterate over all orders and write them to data file
|
220 |
+
foreach ($ordersCollection as $order)
|
221 |
+
{
|
222 |
+
// write order
|
223 |
+
$this->writeOrder($order);
|
224 |
+
|
225 |
+
// increase order counter
|
226 |
+
$addedOrders++;
|
227 |
+
|
228 |
+
// remember what was last order Id
|
229 |
+
$this->currentStatus->setLastOrderId($order->getEntityId());
|
230 |
+
|
231 |
+
// if we are reaching time limit we should stop processing
|
232 |
+
if ($this->isTimeLimitReached()) {
|
233 |
+
throw new Exception('Time limit reached');
|
234 |
+
}
|
235 |
+
}
|
236 |
+
|
237 |
+
// return number of orders that we added to data file
|
238 |
+
return $addedOrders;
|
239 |
+
}
|
240 |
+
|
241 |
+
/**
|
242 |
+
* Wrtie subscribers to files.
|
243 |
+
* @return int Number of subscribers written to file.
|
244 |
+
*/
|
245 |
+
private function writeSubscribersData()
|
246 |
+
{
|
247 |
+
// subscribers counter
|
248 |
+
$addedSubs = 0;
|
249 |
+
|
250 |
+
// get subscribers collection
|
251 |
+
$subscribersCollection = Mage::getModel('newsletter/subscriber')->getCollection();
|
252 |
+
|
253 |
+
// we only want subscribers that are not customers
|
254 |
+
$subscribersCollection->addFieldToFilter('customer_id', array(
|
255 |
+
'eq' => 0,
|
256 |
+
'null' => true
|
257 |
+
));
|
258 |
+
|
259 |
+
// we want to pick up from where we did stop last time
|
260 |
+
$subscribersCollection->addFieldToFilter('subscriber_id', array(
|
261 |
+
'gt' => $this->currentStatus->getLastSubscriptionId()
|
262 |
+
));
|
263 |
+
|
264 |
+
// we want to get sorted collection
|
265 |
+
$subscribersCollection->setOrder('subscriber_id', 'ASC');
|
266 |
+
|
267 |
+
// cap collection with current writes limit
|
268 |
+
$subscribersCollection->setPageSize($this->writesLimit);
|
269 |
+
|
270 |
+
// iterate over all subscribers and write such profiles to data files
|
271 |
+
foreach ($subscribersCollection as $subscriber) {
|
272 |
+
// write subscriber
|
273 |
+
$this->writeSubscriber($subscriber);
|
274 |
+
|
275 |
+
// increament counter
|
276 |
+
$addedSubs++;
|
277 |
+
|
278 |
+
// store last subscription Id
|
279 |
+
$this->currentStatus->setLastSubscriptionId($subscriber->getId());
|
280 |
+
|
281 |
+
// if we are reaching time limit we should stop processing
|
282 |
+
if ($this->isTimeLimitReached()) {
|
283 |
+
throw new Exception('Time limit reached');
|
284 |
+
}
|
285 |
+
}
|
286 |
+
|
287 |
+
// return amount of subscribers that we add
|
288 |
+
return $addedSubs;
|
289 |
+
}
|
290 |
+
|
291 |
+
/**
|
292 |
+
* This method will respawn event. This way we can write all data to files
|
293 |
+
* and not freeze server for longer period of time.
|
294 |
+
*/
|
295 |
+
private function respawn()
|
296 |
+
{
|
297 |
+
// create new event at the end of the queue
|
298 |
+
Mage::getModel('marketingsoftware/queue')
|
299 |
+
->setObject($this->currentStatus)
|
300 |
+
->setAction('file_sync')
|
301 |
+
->save();
|
302 |
+
}
|
303 |
+
|
304 |
+
/**
|
305 |
+
* Write profile data
|
306 |
+
* @param
|
307 |
+
*/
|
308 |
+
private function writeCustomer($customer)
|
309 |
+
{
|
310 |
+
// get data writer inside local scope
|
311 |
+
$dataWriter = Mage::helper('marketingsoftware/DataWriter');
|
312 |
+
|
313 |
+
// create customer copernica abstract
|
314 |
+
$customerAbstract = Mage::getModel('marketingsoftware/abstraction_customer')->loadCustomer($customer->getEntityId());
|
315 |
+
|
316 |
+
// create customer data
|
317 |
+
$customerProfile = Mage::getModel('marketingsoftware/copernica_profilecustomer')->setCustomer($customerAbstract);
|
318 |
+
$customerData = $customerProfile->toArray();
|
319 |
+
|
320 |
+
// specify orders section for customer
|
321 |
+
$orders = array();
|
322 |
+
|
323 |
+
// get orders that belong to current customer
|
324 |
+
$ordersCollection = Mage::getModel('sales/order')->getCollection();
|
325 |
+
$ordersCollection->addFieldToFilter('customer_id', array('eq' => $customer->getId()));
|
326 |
+
|
327 |
+
// iterate over all customers order and get data for them
|
328 |
+
foreach ($ordersCollection as $order) $orders[] = $this->getOrderData($order);
|
329 |
+
|
330 |
+
// assign orders to customer data
|
331 |
+
$customerData['orders'] = $orders;
|
332 |
+
|
333 |
+
// placeholder for customer addresses
|
334 |
+
$addresses = array();
|
335 |
+
|
336 |
+
// iterate over all customers addresses and get data for them
|
337 |
+
foreach ($customer->getAddresses() as $address) $addresses[] = $this->getAddressData($address);
|
338 |
+
|
339 |
+
// assign addresses data to customer data
|
340 |
+
$customerData['addresses'] = $addresses;
|
341 |
+
|
342 |
+
// write customer to data files
|
343 |
+
$dataWriter->storeProfile($customerData);
|
344 |
+
}
|
345 |
+
|
346 |
+
/**
|
347 |
+
* This method will write order as a profile. It should be done only on orders
|
348 |
+
* that do not have a proper customer instance (it was removed or it never
|
349 |
+
* existed like with anonymous orders). For orders that do have a proper
|
350 |
+
* customer instance it will corrupt data since data insert will not be able
|
351 |
+
* to upgrade customer_id field.
|
352 |
+
* @param Mage_Sales_Model_Order
|
353 |
+
*/
|
354 |
+
private function writeOrder($order)
|
355 |
+
{
|
356 |
+
// get order profile assoc data that we can use in json encoder
|
357 |
+
$orderAbstract = Mage::getModel('marketingsoftware/abstraction_order')->setOriginal($order);
|
358 |
+
$orderProfile = Mage::getModel('marketingsoftware/copernica_profileorder')->setOrder($orderAbstract);
|
359 |
+
$profileData = $orderProfile->toArray();
|
360 |
+
|
361 |
+
// we will need order data so we can build a proper profile
|
362 |
+
$orderSubprofile = Mage::getModel('marketingsoftware/copernica_Order_Subprofile')->setOrder($orderAbstract);
|
363 |
+
$orderData = $orderSubprofile->toArray();
|
364 |
+
|
365 |
+
// placeholder for items
|
366 |
+
$items = array();
|
367 |
+
|
368 |
+
// iterate over all item and get theirs data
|
369 |
+
foreach ($order->getItemsCollection() as $item) {
|
370 |
+
$items[] = $this->getItemData($item);
|
371 |
+
}
|
372 |
+
|
373 |
+
// assign items data to order data
|
374 |
+
$orderData['items'] = $items;
|
375 |
+
|
376 |
+
// set orders to progile
|
377 |
+
$profileData['orders'] = array( $orderData );
|
378 |
+
|
379 |
+
// write profile to data files
|
380 |
+
Mage::helper('marketingsoftware/DataWriter')->storeProfile($profileData);
|
381 |
+
}
|
382 |
+
|
383 |
+
/**
|
384 |
+
* Get order data array that can be passed to json encoder. This way we can
|
385 |
+
* transfer data in form of objects and arrays.
|
386 |
+
* @param Mage_Sales_Model_Order
|
387 |
+
* @return assoc
|
388 |
+
*/
|
389 |
+
private function getOrderData($order)
|
390 |
+
{
|
391 |
+
// get order subprofile instance
|
392 |
+
$orderAbstract = Mage::getModel('marketingsoftware/abstraction_order')->importFromOriginal($order);
|
393 |
+
$orderSubprofile = Mage::getModel('marketingsoftware/Copernica_Order_Subprofile')->setOrder($orderAbstract);
|
394 |
+
|
395 |
+
// get order data array
|
396 |
+
$orderData = $orderSubprofile->toArray();
|
397 |
+
|
398 |
+
// placeholder for items array
|
399 |
+
$items = array();
|
400 |
+
|
401 |
+
/**
|
402 |
+
* Order has 3 (or more) methods to get set of items. ::getAllItems(),
|
403 |
+
* ::getAllVisibleItems() and ::getItemsCollection(). ::getAllItems()
|
404 |
+
* and getAllVisibleItems() returns an array and items have some missing
|
405 |
+
* data (or are just populated in odd way). ::getAllVisibleItems() seems
|
406 |
+
* to return all orders configurable items, so top-level items.
|
407 |
+
* ::getItemsCollection() seems to fetch proper items collection that
|
408 |
+
* we can use.
|
409 |
+
* It's nice of magento to provide such friendly interface.
|
410 |
+
*/
|
411 |
+
$itemsCollection = $order->getItemsCollection();
|
412 |
+
|
413 |
+
// iterate over all items
|
414 |
+
foreach ($itemsCollection as $item) $items[] = $this->getItemData($item);
|
415 |
+
|
416 |
+
// add items to order data
|
417 |
+
$orderData['items'] = $items;
|
418 |
+
|
419 |
+
// return order data array
|
420 |
+
return $orderData;
|
421 |
+
}
|
422 |
+
|
423 |
+
/**
|
424 |
+
* Get assoc array of order item.
|
425 |
+
* @param Mage_Sales_Model_Order_Item
|
426 |
+
* @return assoc
|
427 |
+
*/
|
428 |
+
private function getItemData($item)
|
429 |
+
{
|
430 |
+
// get order item data array.
|
431 |
+
$itemAbstract = Mage::getModel('marketingsoftware/abstraction_Order_Item')->setOriginal($item);
|
432 |
+
$itemSubprofile = Mage::getModel('marketingsoftware/Copernica_Orderitem_Subprofile')->setOrderItem($itemAbstract);
|
433 |
+
|
434 |
+
// return assoc array that can be passed to json encoder
|
435 |
+
return $itemSubprofile->toArray();
|
436 |
+
}
|
437 |
+
|
438 |
+
/**
|
439 |
+
* Get address data from Magento raw object.
|
440 |
+
* @param Mage_Customer_Model_Address
|
441 |
+
* @return assoc
|
442 |
+
*/
|
443 |
+
private function getAddressData($address)
|
444 |
+
{
|
445 |
+
// get Copernica instance of address subprofile that we can use in JSON
|
446 |
+
// file.
|
447 |
+
$addressAbstract = Mage::getModel('marketingsoftware/abstraction_address')->setOriginal($address);
|
448 |
+
$addressSubprofile = Mage::getModel('marketingsoftware/copernica_Address_Subprofile')->setAddress($addressAbstract);
|
449 |
+
|
450 |
+
// return address subprofile data
|
451 |
+
return $addressSubprofile->toArray();
|
452 |
+
}
|
453 |
+
|
454 |
+
/**
|
455 |
+
* This function will write subscriber to data files
|
456 |
+
* @param Mage_Newsletter_Model_Subscriber
|
457 |
+
*/
|
458 |
+
private function writeSubscriber($subscriber)
|
459 |
+
{
|
460 |
+
// get subscriber profile so we can use it to get assoc array to write
|
461 |
+
// to JSON data files
|
462 |
+
$subscriberAbstract = Mage::getModel('marketingsoftware/abstraction_Subscription')->setOriginal($subscriber);
|
463 |
+
$subscriberProfile = Mage::getModel('marketingsoftware/copernica_Profilesubscription')->setSubscription($subscriberAbstract);
|
464 |
+
|
465 |
+
// store subscriber data in data files
|
466 |
+
Mage::helper('marketingsoftware/DataWriter')->storeProfile($subscriberProfile->toArray());
|
467 |
+
}
|
468 |
+
}
|
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-2015 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-2015 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-2015 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-2015 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-2015 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-2015 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-2015 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
|
153 |
-
*/
|
154 |
-
public function setOrderEntity(
|
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-2015 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_MarketingSoftware_Model_Copernica_Entity_Order $orderEntity
|
153 |
+
*/
|
154 |
+
public function setOrderEntity(Copernica_MarketingSoftware_Model_Copernica_Entity_Order $orderEntity)
|
155 |
+
{
|
156 |
+
$this->_orderEntity = $orderEntity;
|
157 |
+
}
|
158 |
+
}
|
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-2015 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-2015 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-2015 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-2015 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-2015 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-2015 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-2015 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-2015 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-2015 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-2015 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-2015 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 |
-
*
|
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-2015 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 |
+
*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|