Version Notes
Add email campaigns support; minor fixes.
Download this release
Release Info
Developer | Alexander Kitov |
Extension | Perpetto_Perpetto |
Version | 0.3.0 |
Comparing to | |
See all releases |
Version 0.3.0
- app/code/community/Perpetto/Perpetto/Block/Adminhtml/System/Config/Form/Abstract.php +47 -0
- app/code/community/Perpetto/Perpetto/Block/Adminhtml/System/Config/Form/Account.php +38 -0
- app/code/community/Perpetto/Perpetto/Block/Adminhtml/System/Config/Form/Campaigns.php +157 -0
- app/code/community/Perpetto/Perpetto/Block/Adminhtml/System/Config/Form/Header.php +58 -0
- app/code/community/Perpetto/Perpetto/Block/Adminhtml/System/Config/Form/Recommendations.php +177 -0
- app/code/community/Perpetto/Perpetto/Block/Recommendations.php +76 -0
- app/code/community/Perpetto/Perpetto/Block/Service/Cart.php +50 -0
- app/code/community/Perpetto/Perpetto/Block/Service/Category.php +32 -0
- app/code/community/Perpetto/Perpetto/Block/Service/Product.php +108 -0
- app/code/community/Perpetto/Perpetto/Block/Service/Success.php +37 -0
- app/code/community/Perpetto/Perpetto/Block/Service/User.php +152 -0
- app/code/community/Perpetto/Perpetto/Controller/Action.php +30 -0
- app/code/community/Perpetto/Perpetto/Exception.php +9 -0
- app/code/community/Perpetto/Perpetto/Helper/Api.php +281 -0
- app/code/community/Perpetto/Perpetto/Helper/Catalog.php +131 -0
- app/code/community/Perpetto/Perpetto/Helper/Data.php +132 -0
- app/code/community/Perpetto/Perpetto/Helper/Url.php +180 -0
- app/code/community/Perpetto/Perpetto/Helper/Widget.php +217 -0
- app/code/community/Perpetto/Perpetto/Model/Observer.php +258 -0
- app/code/community/Perpetto/Perpetto/Model/Resource/Slot.php +17 -0
- app/code/community/Perpetto/Perpetto/Model/Resource/Slot/Collection.php +17 -0
- app/code/community/Perpetto/Perpetto/Model/Slot.php +22 -0
- app/code/community/Perpetto/Perpetto/Model/Source/Slots.php +54 -0
- app/code/community/Perpetto/Perpetto/controllers/Adminhtml/Perpetto/CampaignsController.php +32 -0
- app/code/community/Perpetto/Perpetto/controllers/OrdersController.php +219 -0
- app/code/community/Perpetto/Perpetto/controllers/RecommendationsController.php +52 -0
- app/code/community/Perpetto/Perpetto/etc/adminhtml.xml +28 -0
- app/code/community/Perpetto/Perpetto/etc/config.xml +182 -0
- app/code/community/Perpetto/Perpetto/etc/system.xml +72 -0
- app/code/community/Perpetto/Perpetto/etc/widget.xml +22 -0
- app/code/community/Perpetto/Perpetto/sql/perpetto_setup/install-0.1.0.php +89 -0
- app/design/adminhtml/default/default/template/perpetto/adminhtml/system/config/form/account.phtml +41 -0
- app/design/adminhtml/default/default/template/perpetto/adminhtml/system/config/form/campaigns.phtml +102 -0
- app/design/adminhtml/default/default/template/perpetto/adminhtml/system/config/form/header.phtml +11 -0
- app/design/adminhtml/default/default/template/perpetto/adminhtml/system/config/form/recommendations.phtml +111 -0
- app/design/frontend/base/default/layout/perpetto/perpetto.xml +36 -0
- app/design/frontend/base/default/template/perpetto/javascript-sdk.phtml +13 -0
- app/design/frontend/base/default/template/perpetto/recommendations.phtml +8 -0
- app/design/frontend/base/default/template/perpetto/service/category-page.phtml +4 -0
- app/design/frontend/base/default/template/perpetto/service/checkout-cart.phtml +25 -0
- app/design/frontend/base/default/template/perpetto/service/product-page.phtml +30 -0
- app/design/frontend/base/default/template/perpetto/service/success-page.phtml +6 -0
- app/design/frontend/base/default/template/perpetto/service/user.phtml +11 -0
- app/etc/modules/Perpetto_Perpetto.xml +9 -0
- lib/Perpetto/Client.php +212 -0
- lib/Perpetto/Exception.php +9 -0
- lib/Perpetto/Product.php +266 -0
- lib/Perpetto/Response.php +148 -0
- package.xml +18 -0
- skin/adminhtml/default/default/perpetto.css +210 -0
app/code/community/Perpetto/Perpetto/Block/Adminhtml/System/Config/Form/Abstract.php
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Class Perpetto_Perpetto_Block_Adminhtml_System_Config_Form_Abstract
|
5 |
+
*/
|
6 |
+
abstract class Perpetto_Perpetto_Block_Adminhtml_System_Config_Form_Abstract extends Mage_Adminhtml_Block_System_Config_Form
|
7 |
+
{
|
8 |
+
/**
|
9 |
+
* @var Perpetto_Perpetto_Block_Adminhtml_System_Config_Form_Header
|
10 |
+
*/
|
11 |
+
protected $_header;
|
12 |
+
|
13 |
+
/**
|
14 |
+
* @return Mage_Core_Block_Abstract
|
15 |
+
*/
|
16 |
+
protected function _prepareLayout()
|
17 |
+
{
|
18 |
+
$layout = $this->getLayout();
|
19 |
+
$head = $layout->getBlock('head');
|
20 |
+
/** @var $head Mage_Adminhtml_Block_Page_Head */
|
21 |
+
|
22 |
+
$head->addCss('perpetto.css');
|
23 |
+
|
24 |
+
$block = $layout->createBlock('perpetto/adminhtml_system_config_form_header');
|
25 |
+
$this->_header = $block;
|
26 |
+
|
27 |
+
return parent::_prepareLayout();
|
28 |
+
}
|
29 |
+
|
30 |
+
/**
|
31 |
+
* Get form header html
|
32 |
+
*
|
33 |
+
* @return string
|
34 |
+
*/
|
35 |
+
public function getHeaderHtml()
|
36 |
+
{
|
37 |
+
return $this->getHeaderBlock()->toHtml();
|
38 |
+
}
|
39 |
+
|
40 |
+
/**
|
41 |
+
* @return Perpetto_Perpetto_Block_Adminhtml_System_Config_Form_Header|null
|
42 |
+
*/
|
43 |
+
public function getHeaderBlock()
|
44 |
+
{
|
45 |
+
return $this->_header;
|
46 |
+
}
|
47 |
+
}
|
app/code/community/Perpetto/Perpetto/Block/Adminhtml/System/Config/Form/Account.php
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Class Perpetto_Perpetto_Block_Adminhtml_System_Config_Form_Account
|
5 |
+
*/
|
6 |
+
class Perpetto_Perpetto_Block_Adminhtml_System_Config_Form_Account extends Perpetto_Perpetto_Block_Adminhtml_System_Config_Form_Abstract
|
7 |
+
{
|
8 |
+
/**
|
9 |
+
* Init
|
10 |
+
*/
|
11 |
+
public function _construct()
|
12 |
+
{
|
13 |
+
parent::_construct();
|
14 |
+
|
15 |
+
$this->setTemplate('perpetto/adminhtml/system/config/form/account.phtml');
|
16 |
+
}
|
17 |
+
|
18 |
+
/**
|
19 |
+
* @return string
|
20 |
+
*/
|
21 |
+
public function getSignInUrl()
|
22 |
+
{
|
23 |
+
$url = Mage::helper('perpetto/url')->getSignInUrl();
|
24 |
+
|
25 |
+
return $url;
|
26 |
+
}
|
27 |
+
|
28 |
+
/**
|
29 |
+
* @return string
|
30 |
+
*/
|
31 |
+
public function getSignUpUrl()
|
32 |
+
{
|
33 |
+
$url = Mage::helper('perpetto/url')->getSignUpUrl();
|
34 |
+
|
35 |
+
return $url;
|
36 |
+
}
|
37 |
+
|
38 |
+
}
|
app/code/community/Perpetto/Perpetto/Block/Adminhtml/System/Config/Form/Campaigns.php
ADDED
@@ -0,0 +1,157 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Class Perpetto_Perpetto_Block_Adminhtml_System_Config_Form_Campaigns
|
5 |
+
*/
|
6 |
+
class Perpetto_Perpetto_Block_Adminhtml_System_Config_Form_Campaigns extends Perpetto_Perpetto_Block_Adminhtml_System_Config_Form_Abstract
|
7 |
+
{
|
8 |
+
/**
|
9 |
+
* @var Perpetto_Perpetto_Model_Resource_Slot_Collection
|
10 |
+
*/
|
11 |
+
protected $_campaigns;
|
12 |
+
|
13 |
+
/**
|
14 |
+
* Init
|
15 |
+
*/
|
16 |
+
protected function _construct()
|
17 |
+
{
|
18 |
+
parent::_construct();
|
19 |
+
|
20 |
+
$this->setTemplate('perpetto/adminhtml/system/config/form/campaigns.phtml');
|
21 |
+
|
22 |
+
// @TODO: calls the API every time
|
23 |
+
try {
|
24 |
+
Mage::helper('perpetto/api')->updateEmailCampaigns();
|
25 |
+
} catch (Exception $e) {
|
26 |
+
Mage::log($e);
|
27 |
+
}
|
28 |
+
}
|
29 |
+
|
30 |
+
/**
|
31 |
+
* Retrieve slots grouped by page
|
32 |
+
*
|
33 |
+
* @return array
|
34 |
+
*/
|
35 |
+
public function getEmailCampaigns()
|
36 |
+
{
|
37 |
+
$helper = Mage::helper('perpetto');
|
38 |
+
$campaigns = $helper->getEmailCampaigns();
|
39 |
+
|
40 |
+
return $campaigns;
|
41 |
+
}
|
42 |
+
|
43 |
+
/**
|
44 |
+
* @return string
|
45 |
+
*/
|
46 |
+
public function getDashboardUrl()
|
47 |
+
{
|
48 |
+
$url = Mage::helper('perpetto/url')->getEmailCampaignsDashboardUrl();
|
49 |
+
|
50 |
+
return $url;
|
51 |
+
}
|
52 |
+
|
53 |
+
/**
|
54 |
+
* @return string
|
55 |
+
*/
|
56 |
+
public function getContactsUrl()
|
57 |
+
{
|
58 |
+
$url = Mage::helper('perpetto/url')->getContactsUrl();
|
59 |
+
|
60 |
+
return $url;
|
61 |
+
}
|
62 |
+
|
63 |
+
/**
|
64 |
+
* @return string
|
65 |
+
*/
|
66 |
+
public function getBillingUrl()
|
67 |
+
{
|
68 |
+
$url = Mage::helper('perpetto/url')->getBillingUrl();
|
69 |
+
|
70 |
+
return $url;
|
71 |
+
}
|
72 |
+
|
73 |
+
/**
|
74 |
+
* @return string
|
75 |
+
*/
|
76 |
+
public function getEmailCampaignsUrl()
|
77 |
+
{
|
78 |
+
$url = Mage::helper('perpetto/url')->getEmailCampaignsUrl();
|
79 |
+
|
80 |
+
return $url;
|
81 |
+
}
|
82 |
+
|
83 |
+
/**
|
84 |
+
* @param $campaignId
|
85 |
+
* @param $emailId
|
86 |
+
* @return string
|
87 |
+
*/
|
88 |
+
public function getEmailCampaignTestUrl($campaignId, $emailId)
|
89 |
+
{
|
90 |
+
$url = $this->getUrl('*/perpetto_campaigns/test', array('campaign' => $campaignId, 'email' => $emailId));
|
91 |
+
|
92 |
+
return $url;
|
93 |
+
}
|
94 |
+
|
95 |
+
/**
|
96 |
+
* @return bool
|
97 |
+
*/
|
98 |
+
public function showCampaigns()
|
99 |
+
{
|
100 |
+
$showSlots = Mage::helper('perpetto')->isActive();
|
101 |
+
|
102 |
+
return $showSlots;
|
103 |
+
}
|
104 |
+
|
105 |
+
/**
|
106 |
+
* @return bool
|
107 |
+
*/
|
108 |
+
public function showLinks()
|
109 |
+
{
|
110 |
+
$showLinks = Mage::helper('perpetto')->isActive();
|
111 |
+
|
112 |
+
return $showLinks;
|
113 |
+
}
|
114 |
+
|
115 |
+
/**
|
116 |
+
* @return string
|
117 |
+
*/
|
118 |
+
public function getBillingTitle()
|
119 |
+
{
|
120 |
+
$helper = Mage::helper('perpetto');
|
121 |
+
$title = 'Billing Information';
|
122 |
+
|
123 |
+
if ($helper->isTrial()) {
|
124 |
+
$days = $helper->getTrialDaysLeft();
|
125 |
+
$title = $this->__('Free Trial (%d Day%s Left)', $days, $days != 1 ? 's' : '');
|
126 |
+
}
|
127 |
+
|
128 |
+
return $title;
|
129 |
+
}
|
130 |
+
|
131 |
+
/**
|
132 |
+
* @return string
|
133 |
+
*/
|
134 |
+
public function getBillingText()
|
135 |
+
{
|
136 |
+
$helper = Mage::helper('perpetto');
|
137 |
+
$text = $helper->isTrial()
|
138 |
+
? 'Don\'t forget to add your billing information before the trial ends.'
|
139 |
+
: 'You can see your current bill and the forecast for this month.';
|
140 |
+
|
141 |
+
return $text;
|
142 |
+
}
|
143 |
+
|
144 |
+
/**
|
145 |
+
* @return string
|
146 |
+
*/
|
147 |
+
public function getBillingButtonText()
|
148 |
+
{
|
149 |
+
$helper = Mage::helper('perpetto');
|
150 |
+
$text = $helper->isTrial()
|
151 |
+
? 'Add Billing Information Securely'
|
152 |
+
: 'Check Current Bill';
|
153 |
+
|
154 |
+
return $text;
|
155 |
+
}
|
156 |
+
|
157 |
+
}
|
app/code/community/Perpetto/Perpetto/Block/Adminhtml/System/Config/Form/Header.php
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Perpetto_Perpetto_Block_Adminhtml_System_Config_Form_Header extends Mage_Adminhtml_Block_Abstract
|
4 |
+
{
|
5 |
+
|
6 |
+
/**
|
7 |
+
* @var string
|
8 |
+
*/
|
9 |
+
protected $_messages;
|
10 |
+
|
11 |
+
/**
|
12 |
+
* Initialize block template
|
13 |
+
*/
|
14 |
+
public function _construct()
|
15 |
+
{
|
16 |
+
parent::_construct();
|
17 |
+
$this->setTemplate('perpetto/adminhtml/system/config/form/header.phtml');
|
18 |
+
}
|
19 |
+
|
20 |
+
/**
|
21 |
+
* @return Mage_Core_Block_Abstract
|
22 |
+
*/
|
23 |
+
protected function _prepareLayout()
|
24 |
+
{
|
25 |
+
$layout = $this->getLayout();
|
26 |
+
$messages = $layout->getBlock('messages');
|
27 |
+
/** @var $messages Mage_Core_Block_Messages */
|
28 |
+
|
29 |
+
$perpetto = Mage::helper('perpetto');
|
30 |
+
|
31 |
+
if (!$messages->getMessageCollection()->count()) {
|
32 |
+
if (!$perpetto->isActive()) {
|
33 |
+
$messages->addWarning('No connection can be established to your account. Please check the Account ID and Secret in the Account Tab.');
|
34 |
+
}
|
35 |
+
}
|
36 |
+
|
37 |
+
if ($perpetto->isActive()) {
|
38 |
+
if ($perpetto->isTrial() && $perpetto->getTrialDaysLeft() < 1) {
|
39 |
+
$messages->addWarning('Your trial period has ended. All results can be seen in the Perpetto Dashboard. Please add the billing information needed to continue using Perpetto.');
|
40 |
+
} else {
|
41 |
+
$messages->addSuccess('Your Perpetto account is connected and the recommendations are activated.');
|
42 |
+
}
|
43 |
+
}
|
44 |
+
|
45 |
+
$this->_messages = $layout->getBlock('messages')->toHtml();
|
46 |
+
$layout->unsetBlock('messages');
|
47 |
+
|
48 |
+
return parent::_prepareLayout();
|
49 |
+
}
|
50 |
+
|
51 |
+
/**
|
52 |
+
* @return string
|
53 |
+
*/
|
54 |
+
public function getMessagesHtml()
|
55 |
+
{
|
56 |
+
return $this->_messages;
|
57 |
+
}
|
58 |
+
}
|
app/code/community/Perpetto/Perpetto/Block/Adminhtml/System/Config/Form/Recommendations.php
ADDED
@@ -0,0 +1,177 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Class Perpetto_Perpetto_Block_Adminhtml_System_Config_Form_Recommendations
|
5 |
+
*/
|
6 |
+
class Perpetto_Perpetto_Block_Adminhtml_System_Config_Form_Recommendations extends Perpetto_Perpetto_Block_Adminhtml_System_Config_Form_Abstract
|
7 |
+
{
|
8 |
+
/**
|
9 |
+
* @var Perpetto_Perpetto_Model_Resource_Slot_Collection
|
10 |
+
*/
|
11 |
+
protected $_slots;
|
12 |
+
|
13 |
+
/**
|
14 |
+
* Init
|
15 |
+
*/
|
16 |
+
protected function _construct()
|
17 |
+
{
|
18 |
+
parent::_construct();
|
19 |
+
|
20 |
+
$this->setTemplate('perpetto/adminhtml/system/config/form/recommendations.phtml');
|
21 |
+
}
|
22 |
+
|
23 |
+
/**
|
24 |
+
* Retrieve slots collection
|
25 |
+
*
|
26 |
+
* @return Perpetto_Perpetto_Model_Resource_Slot_Collection
|
27 |
+
*/
|
28 |
+
public function getSlotsCollection()
|
29 |
+
{
|
30 |
+
if (is_null($this->_slots)) {
|
31 |
+
$slots = Mage::getResourceModel('perpetto/slot_collection');
|
32 |
+
|
33 |
+
$this->_slots = $slots;
|
34 |
+
}
|
35 |
+
|
36 |
+
return $this->_slots;
|
37 |
+
}
|
38 |
+
|
39 |
+
/**
|
40 |
+
* Retrieve slots grouped by page
|
41 |
+
*
|
42 |
+
* @return array
|
43 |
+
*/
|
44 |
+
public function getGroupedSlots()
|
45 |
+
{
|
46 |
+
$slots = $this->getSlotsCollection();
|
47 |
+
|
48 |
+
$data = array();
|
49 |
+
|
50 |
+
foreach ($slots as $slot) {
|
51 |
+
/** @var $slot Perpetto_Perpetto_Model_Slot */
|
52 |
+
|
53 |
+
$page = $slot->getPage();
|
54 |
+
|
55 |
+
if (!array_key_exists($page, $data)) {
|
56 |
+
$data[$page] = array();
|
57 |
+
}
|
58 |
+
|
59 |
+
array_push($data[$page], $slot);
|
60 |
+
}
|
61 |
+
|
62 |
+
return $data;
|
63 |
+
}
|
64 |
+
|
65 |
+
/**
|
66 |
+
* @return string
|
67 |
+
*/
|
68 |
+
public function getDashboardUrl()
|
69 |
+
{
|
70 |
+
$url = Mage::helper('perpetto/url')->getRecommendationsDashboardUrl();
|
71 |
+
|
72 |
+
return $url;
|
73 |
+
}
|
74 |
+
|
75 |
+
/**
|
76 |
+
* @return string
|
77 |
+
*/
|
78 |
+
public function getContactsUrl()
|
79 |
+
{
|
80 |
+
$url = Mage::helper('perpetto/url')->getContactsUrl();
|
81 |
+
|
82 |
+
return $url;
|
83 |
+
}
|
84 |
+
|
85 |
+
/**
|
86 |
+
* @return string
|
87 |
+
*/
|
88 |
+
public function getBillingUrl()
|
89 |
+
{
|
90 |
+
$url = Mage::helper('perpetto/url')->getBillingUrl();
|
91 |
+
|
92 |
+
return $url;
|
93 |
+
}
|
94 |
+
|
95 |
+
/**
|
96 |
+
* @return string
|
97 |
+
*/
|
98 |
+
public function getRandomProductPreviewUrl()
|
99 |
+
{
|
100 |
+
$url = Mage::helper('perpetto/url')->getRandomProductPreviewUrl();
|
101 |
+
|
102 |
+
return $url;
|
103 |
+
}
|
104 |
+
|
105 |
+
/**
|
106 |
+
* @return string
|
107 |
+
*/
|
108 |
+
public function getRecommendationsUrl()
|
109 |
+
{
|
110 |
+
$url = Mage::helper('perpetto/url')->getRecommendationsUrl();
|
111 |
+
|
112 |
+
return $url;
|
113 |
+
}
|
114 |
+
|
115 |
+
/**
|
116 |
+
* @return bool
|
117 |
+
*/
|
118 |
+
public function showLinks()
|
119 |
+
{
|
120 |
+
$showLinks = Mage::helper('perpetto')->isActive();
|
121 |
+
|
122 |
+
return $showLinks;
|
123 |
+
}
|
124 |
+
|
125 |
+
/**
|
126 |
+
* @return bool
|
127 |
+
*/
|
128 |
+
public function showSlots()
|
129 |
+
{
|
130 |
+
$showSlots = Mage::helper('perpetto')->isActive();
|
131 |
+
|
132 |
+
return $showSlots;
|
133 |
+
}
|
134 |
+
|
135 |
+
/**
|
136 |
+
* @return string
|
137 |
+
*/
|
138 |
+
public function getBillingTitle()
|
139 |
+
{
|
140 |
+
$helper = Mage::helper('perpetto');
|
141 |
+
$title = 'Billing Information';
|
142 |
+
|
143 |
+
if ($helper->isTrial()) {
|
144 |
+
$days = $helper->getTrialDaysLeft();
|
145 |
+
$title = $this->__('Free Trial (%d Day%s Left)', $days, $days != 1 ? 's' : '');
|
146 |
+
}
|
147 |
+
|
148 |
+
return $title;
|
149 |
+
}
|
150 |
+
|
151 |
+
/**
|
152 |
+
* @return string
|
153 |
+
*/
|
154 |
+
public function getBillingText()
|
155 |
+
{
|
156 |
+
$helper = Mage::helper('perpetto');
|
157 |
+
$text = $helper->isTrial()
|
158 |
+
? 'Don\'t forget to add your billing information before the trial ends.'
|
159 |
+
: 'You can see your current bill and the forecast for this month.';
|
160 |
+
|
161 |
+
return $text;
|
162 |
+
}
|
163 |
+
|
164 |
+
/**
|
165 |
+
* @return string
|
166 |
+
*/
|
167 |
+
public function getBillingButtonText()
|
168 |
+
{
|
169 |
+
$helper = Mage::helper('perpetto');
|
170 |
+
$text = $helper->isTrial()
|
171 |
+
? 'Add Billing Information Securely'
|
172 |
+
: 'Check Current Bill';
|
173 |
+
|
174 |
+
return $text;
|
175 |
+
}
|
176 |
+
|
177 |
+
}
|
app/code/community/Perpetto/Perpetto/Block/Recommendations.php
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Class Perpetto_Perpetto_Block_Recommendations
|
5 |
+
*/
|
6 |
+
class Perpetto_Perpetto_Block_Recommendations extends Mage_Core_Block_Template implements Mage_Widget_Block_Interface
|
7 |
+
{
|
8 |
+
/**
|
9 |
+
* @var string
|
10 |
+
*/
|
11 |
+
protected $_class = 'ptto-rec-slot-token';
|
12 |
+
|
13 |
+
/**
|
14 |
+
* @var Perpetto_Perpetto_Model_Slot
|
15 |
+
*/
|
16 |
+
protected $_slot;
|
17 |
+
|
18 |
+
/**
|
19 |
+
* Init
|
20 |
+
*/
|
21 |
+
protected function _construct()
|
22 |
+
{
|
23 |
+
parent::_construct();
|
24 |
+
$this->setTemplate('perpetto/recommendations.phtml');
|
25 |
+
}
|
26 |
+
|
27 |
+
/**
|
28 |
+
* @return string
|
29 |
+
*/
|
30 |
+
public function getClass()
|
31 |
+
{
|
32 |
+
return $this->_class;
|
33 |
+
}
|
34 |
+
|
35 |
+
/**
|
36 |
+
* @return Perpetto_Perpetto_Model_Slot
|
37 |
+
*/
|
38 |
+
public function getSlot()
|
39 |
+
{
|
40 |
+
return $this->_slot;
|
41 |
+
}
|
42 |
+
|
43 |
+
/**
|
44 |
+
* @return $this
|
45 |
+
*/
|
46 |
+
protected function _beforeToHtml()
|
47 |
+
{
|
48 |
+
$slotId = $this->getData('slot_id');
|
49 |
+
$class = $this->getData('attr_class');
|
50 |
+
|
51 |
+
$slot = Mage::getModel('perpetto/slot')->load($slotId, 'perpetto_id');
|
52 |
+
if ($slot->getId()) {
|
53 |
+
$this->_slot = $slot;
|
54 |
+
$engine = $slot->getEngineName();
|
55 |
+
$class = sprintf('ptto-%s %s', strtolower(str_replace('_', '-', $engine)), $class);
|
56 |
+
}
|
57 |
+
|
58 |
+
$this->_class .= ' ' . $class;
|
59 |
+
|
60 |
+
parent::_beforeToHtml();
|
61 |
+
}
|
62 |
+
|
63 |
+
|
64 |
+
/**
|
65 |
+
* @return string
|
66 |
+
*/
|
67 |
+
protected function _toHtml()
|
68 |
+
{
|
69 |
+
if (!$this->_slot instanceof Perpetto_Perpetto_Model_Slot) {
|
70 |
+
return '';
|
71 |
+
}
|
72 |
+
|
73 |
+
return parent::_toHtml();
|
74 |
+
}
|
75 |
+
|
76 |
+
}
|
app/code/community/Perpetto/Perpetto/Block/Service/Cart.php
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Class Perpetto_Perpetto_Block_Service_Cart
|
5 |
+
*/
|
6 |
+
class Perpetto_Perpetto_Block_Service_Cart extends Mage_Core_Block_Template
|
7 |
+
{
|
8 |
+
/**
|
9 |
+
* Init
|
10 |
+
*/
|
11 |
+
public function _construct()
|
12 |
+
{
|
13 |
+
parent::_construct();
|
14 |
+
$this->setTemplate('perpetto/service/checkout-cart.phtml');
|
15 |
+
}
|
16 |
+
|
17 |
+
/**
|
18 |
+
* @return string
|
19 |
+
*/
|
20 |
+
protected function _toHtml()
|
21 |
+
{
|
22 |
+
$quote = $this->getQuote();
|
23 |
+
if (!$quote->hasItems()) {
|
24 |
+
return '';
|
25 |
+
}
|
26 |
+
|
27 |
+
return parent::_toHtml();
|
28 |
+
}
|
29 |
+
|
30 |
+
/**
|
31 |
+
* Retrieve quote object
|
32 |
+
*
|
33 |
+
* @return Mage_Sales_Model_Quote
|
34 |
+
*/
|
35 |
+
protected function getQuote()
|
36 |
+
{
|
37 |
+
return $this->_getSession()->getQuote();
|
38 |
+
}
|
39 |
+
|
40 |
+
/**
|
41 |
+
* Retrieve session object
|
42 |
+
*
|
43 |
+
* @return Mage_Checkout_Model_Session
|
44 |
+
*/
|
45 |
+
protected function _getSession()
|
46 |
+
{
|
47 |
+
return Mage::getSingleton('checkout/session');
|
48 |
+
}
|
49 |
+
|
50 |
+
}
|
app/code/community/Perpetto/Perpetto/Block/Service/Category.php
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Class Perpetto_Perpetto_Block_Service_Category
|
5 |
+
*/
|
6 |
+
class Perpetto_Perpetto_Block_Service_Category extends Mage_Core_Block_Template
|
7 |
+
{
|
8 |
+
/**
|
9 |
+
* Init
|
10 |
+
*/
|
11 |
+
public function _construct()
|
12 |
+
{
|
13 |
+
parent::_construct();
|
14 |
+
$this->setTemplate('perpetto/service/category-page.phtml');
|
15 |
+
}
|
16 |
+
|
17 |
+
/**
|
18 |
+
* @return string
|
19 |
+
*/
|
20 |
+
public function getCurrentCategoryPath()
|
21 |
+
{
|
22 |
+
$path = '';
|
23 |
+
|
24 |
+
$category = Mage::registry('current_category');
|
25 |
+
if ($category instanceof Mage_Catalog_Model_Category) {
|
26 |
+
$helper = Mage::helper('perpetto/catalog');
|
27 |
+
$path = $helper->getCategoryPath($category);
|
28 |
+
}
|
29 |
+
|
30 |
+
return $path;
|
31 |
+
}
|
32 |
+
}
|
app/code/community/Perpetto/Perpetto/Block/Service/Product.php
ADDED
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Class Perpetto_Perpetto_Block_Service_Product
|
5 |
+
*/
|
6 |
+
class Perpetto_Perpetto_Block_Service_Product extends Mage_Core_Block_Template
|
7 |
+
{
|
8 |
+
|
9 |
+
/**
|
10 |
+
* @var Mage_Catalog_Model_Product
|
11 |
+
*/
|
12 |
+
protected $_product;
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Init
|
16 |
+
*/
|
17 |
+
public function _construct()
|
18 |
+
{
|
19 |
+
parent::_construct();
|
20 |
+
$this->setTemplate('perpetto/service/product-page.phtml');
|
21 |
+
}
|
22 |
+
|
23 |
+
/**
|
24 |
+
* Get current product
|
25 |
+
*
|
26 |
+
* @return Mage_Catalog_Model_Product
|
27 |
+
*/
|
28 |
+
public function getProduct()
|
29 |
+
{
|
30 |
+
if (is_null($this->_product)) {
|
31 |
+
$this->_product = Mage::registry('current_product');
|
32 |
+
}
|
33 |
+
|
34 |
+
return $this->_product;
|
35 |
+
}
|
36 |
+
|
37 |
+
/**
|
38 |
+
* Get current product image URL
|
39 |
+
*
|
40 |
+
* @return string
|
41 |
+
*/
|
42 |
+
public function getProductImageUrl()
|
43 |
+
{
|
44 |
+
$url = Mage::helper('catalog/image')->init($this->getProduct(), 'image')->__toString();
|
45 |
+
|
46 |
+
return $url;
|
47 |
+
}
|
48 |
+
|
49 |
+
/**
|
50 |
+
* Get current categories path
|
51 |
+
*
|
52 |
+
* @return string
|
53 |
+
*/
|
54 |
+
public function getCurrentCategoryPath()
|
55 |
+
{
|
56 |
+
$path = '';
|
57 |
+
|
58 |
+
$category = Mage::registry('current_category');
|
59 |
+
if ($category instanceof Mage_Catalog_Model_Category) {
|
60 |
+
$helper = Mage::helper('perpetto/catalog');
|
61 |
+
$path = $helper->getCategoryPath($category);
|
62 |
+
}
|
63 |
+
|
64 |
+
return $path;
|
65 |
+
}
|
66 |
+
|
67 |
+
/**
|
68 |
+
* Get product categories paths
|
69 |
+
*
|
70 |
+
* @return string
|
71 |
+
*/
|
72 |
+
public function getProductCategoriesPaths()
|
73 |
+
{
|
74 |
+
$result = '';
|
75 |
+
|
76 |
+
$product = $this->getProduct();
|
77 |
+
if ($product instanceof Mage_Catalog_Model_Product) {
|
78 |
+
$helper = Mage::helper('perpetto/catalog');
|
79 |
+
$paths = $helper->getProductCategoryPaths($product);
|
80 |
+
$result = implode(',', $paths);
|
81 |
+
}
|
82 |
+
|
83 |
+
return $result;
|
84 |
+
}
|
85 |
+
|
86 |
+
/**
|
87 |
+
* @return string
|
88 |
+
*/
|
89 |
+
public function getProductPrice()
|
90 |
+
{
|
91 |
+
$product = $this->getProduct();
|
92 |
+
return Mage::helper('perpetto/catalog')->getProductPrice($product);
|
93 |
+
}
|
94 |
+
|
95 |
+
/**
|
96 |
+
* @return string
|
97 |
+
*/
|
98 |
+
protected function _toHtml()
|
99 |
+
{
|
100 |
+
$product = $this->getProduct();
|
101 |
+
if (!$product instanceof Mage_Catalog_Model_Product) {
|
102 |
+
return '';
|
103 |
+
}
|
104 |
+
|
105 |
+
return parent::_toHtml();
|
106 |
+
}
|
107 |
+
|
108 |
+
}
|
app/code/community/Perpetto/Perpetto/Block/Service/Success.php
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Class Perpetto_Perpetto_Block_Service_Success
|
5 |
+
*/
|
6 |
+
class Perpetto_Perpetto_Block_Service_Success extends Mage_Core_Block_Template
|
7 |
+
{
|
8 |
+
/**
|
9 |
+
* Init
|
10 |
+
*/
|
11 |
+
public function _construct()
|
12 |
+
{
|
13 |
+
parent::_construct();
|
14 |
+
$this->setTemplate('perpetto/service/success-page.phtml');
|
15 |
+
}
|
16 |
+
|
17 |
+
/**
|
18 |
+
* @return int
|
19 |
+
*/
|
20 |
+
public function getLastSuccessQuoteId()
|
21 |
+
{
|
22 |
+
$session = $this->getOnepage()->getCheckout();
|
23 |
+
$lastOrder = $session->getLastRealOrder();
|
24 |
+
|
25 |
+
return $lastOrder->getQuoteId();
|
26 |
+
}
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Get one page checkout model
|
30 |
+
*
|
31 |
+
* @return Mage_Checkout_Model_Type_Onepage
|
32 |
+
*/
|
33 |
+
public function getOnepage()
|
34 |
+
{
|
35 |
+
return Mage::getSingleton('checkout/type_onepage');
|
36 |
+
}
|
37 |
+
}
|
app/code/community/Perpetto/Perpetto/Block/Service/User.php
ADDED
@@ -0,0 +1,152 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Class Perpetto_Perpetto_Block_Service_User
|
5 |
+
*/
|
6 |
+
class Perpetto_Perpetto_Block_Service_User extends Mage_Core_Block_Template
|
7 |
+
{
|
8 |
+
/**
|
9 |
+
* Init
|
10 |
+
*/
|
11 |
+
public function _construct()
|
12 |
+
{
|
13 |
+
parent::_construct();
|
14 |
+
$this->setTemplate('perpetto/service/user.phtml');
|
15 |
+
}
|
16 |
+
|
17 |
+
/**
|
18 |
+
* Get user email
|
19 |
+
*
|
20 |
+
* @return string
|
21 |
+
*/
|
22 |
+
public function getEmail()
|
23 |
+
{
|
24 |
+
$session = $this->_getSession();
|
25 |
+
$email = $session->getCustomUserServiceEmail();
|
26 |
+
|
27 |
+
if (!$email) {
|
28 |
+
$user = $this->getUser();
|
29 |
+
if ($user instanceof Mage_Customer_Model_Customer) {
|
30 |
+
$email = $user->getEmail();
|
31 |
+
}
|
32 |
+
}
|
33 |
+
|
34 |
+
return $email;
|
35 |
+
}
|
36 |
+
|
37 |
+
/**
|
38 |
+
* @return string
|
39 |
+
*/
|
40 |
+
public function getFirstname()
|
41 |
+
{
|
42 |
+
$session = $this->_getSession();
|
43 |
+
$firstname = $session->getCustomUserServiceFirstname();
|
44 |
+
|
45 |
+
if (!$firstname) {
|
46 |
+
$user = $this->getUser();
|
47 |
+
if ($user instanceof Mage_Customer_Model_Customer) {
|
48 |
+
$firstname = $user->getFirstname();
|
49 |
+
}
|
50 |
+
}
|
51 |
+
return $firstname;
|
52 |
+
}
|
53 |
+
|
54 |
+
/**
|
55 |
+
* @return string
|
56 |
+
*/
|
57 |
+
public function getLastname()
|
58 |
+
{
|
59 |
+
$session = $this->_getSession();
|
60 |
+
$lastname = $session->getCustomUserServiceLastname();
|
61 |
+
|
62 |
+
if (!$lastname) {
|
63 |
+
$user = $this->getUser();
|
64 |
+
if ($user instanceof Mage_Customer_Model_Customer) {
|
65 |
+
$lastname = $user->getLastname();
|
66 |
+
}
|
67 |
+
}
|
68 |
+
|
69 |
+
return $lastname;
|
70 |
+
}
|
71 |
+
|
72 |
+
/**
|
73 |
+
* Check if we should show customer service block
|
74 |
+
*
|
75 |
+
* @return bool
|
76 |
+
*/
|
77 |
+
public function showBlock()
|
78 |
+
{
|
79 |
+
$session = $this->_getSession();
|
80 |
+
$showBlock = (bool)$session->getData('_should_show_user_service_block');
|
81 |
+
|
82 |
+
return $showBlock;
|
83 |
+
}
|
84 |
+
|
85 |
+
/**
|
86 |
+
* Get the current logged in customer
|
87 |
+
*
|
88 |
+
* @return Mage_Customer_Model_Customer
|
89 |
+
*/
|
90 |
+
public function getUser()
|
91 |
+
{
|
92 |
+
$session = $this->_getSession();
|
93 |
+
$customer = $session->getCustomer();
|
94 |
+
|
95 |
+
return $customer;
|
96 |
+
}
|
97 |
+
|
98 |
+
/**
|
99 |
+
* @param bool $clear
|
100 |
+
* @return bool
|
101 |
+
*/
|
102 |
+
public function isNewCustomer($clear = true)
|
103 |
+
{
|
104 |
+
$session = $this->_getSession();
|
105 |
+
$isNewCustomer = (bool)$session->getData('perpetto_customer_register_success', $clear);
|
106 |
+
|
107 |
+
return $isNewCustomer;
|
108 |
+
}
|
109 |
+
|
110 |
+
/**
|
111 |
+
* Retrieve session object
|
112 |
+
*
|
113 |
+
* @return Mage_Customer_Model_Session
|
114 |
+
*/
|
115 |
+
protected function _getSession()
|
116 |
+
{
|
117 |
+
return Mage::getSingleton('customer/session');
|
118 |
+
}
|
119 |
+
|
120 |
+
/**
|
121 |
+
* @return string
|
122 |
+
*/
|
123 |
+
protected function _toHtml()
|
124 |
+
{
|
125 |
+
$user = $this->getUser();
|
126 |
+
|
127 |
+
if ($user instanceof Mage_Customer_Model_Customer && $user->getId() || $this->showBlock()) {
|
128 |
+
$session = $this->_getSession();
|
129 |
+
$session->setData('_should_show_user_service_block', false);
|
130 |
+
|
131 |
+
return parent::_toHtml();
|
132 |
+
}
|
133 |
+
|
134 |
+
return '';
|
135 |
+
}
|
136 |
+
|
137 |
+
/**
|
138 |
+
* @param string $html
|
139 |
+
* @return string
|
140 |
+
*/
|
141 |
+
protected function _afterToHtml($html)
|
142 |
+
{
|
143 |
+
$session = $this->_getSession();
|
144 |
+
|
145 |
+
$session->setData('custom_user_service_email', false);
|
146 |
+
$session->setData('custom_user_service_firstname', false);
|
147 |
+
$session->setData('custom_user_service_lastname', false);
|
148 |
+
|
149 |
+
return parent::_afterToHtml($html);
|
150 |
+
}
|
151 |
+
|
152 |
+
}
|
app/code/community/Perpetto/Perpetto/Controller/Action.php
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Class Perpetto_Perpetto_Controller_Action
|
5 |
+
*/
|
6 |
+
class Perpetto_Perpetto_Controller_Action extends Mage_Core_Controller_Front_Action
|
7 |
+
{
|
8 |
+
/**
|
9 |
+
* @throws Perpetto_Perpetto_Exception
|
10 |
+
*/
|
11 |
+
protected function _validateRequest()
|
12 |
+
{
|
13 |
+
$request = $this->getRequest();
|
14 |
+
$perpetto = Mage::helper('perpetto');
|
15 |
+
|
16 |
+
if (!$perpetto->isActive()) {
|
17 |
+
$headers['HTTP/1.1'] = '403 Forbidden';
|
18 |
+
throw new Perpetto_Perpetto_Exception('Perpetto is not activated.');
|
19 |
+
}
|
20 |
+
|
21 |
+
$accountId = $request->getParam('account_id');
|
22 |
+
$secret = $request->getParam('secret');
|
23 |
+
|
24 |
+
if ($accountId != $perpetto->getAccountId() || $secret != $perpetto->getSecret()) {
|
25 |
+
$headers['HTTP/1.1'] = '401 Unauthorized';
|
26 |
+
throw new Perpetto_Perpetto_Exception('Account ID and secret do not match local configuration.');
|
27 |
+
}
|
28 |
+
}
|
29 |
+
|
30 |
+
}
|
app/code/community/Perpetto/Perpetto/Exception.php
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Class Perpetto_Perpetto_Exception
|
5 |
+
*/
|
6 |
+
class Perpetto_Perpetto_Exception extends Mage_Exception
|
7 |
+
{
|
8 |
+
|
9 |
+
}
|
app/code/community/Perpetto/Perpetto/Helper/Api.php
ADDED
@@ -0,0 +1,281 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Class Perpetto_Perpetto_Helper_Api
|
5 |
+
*/
|
6 |
+
class Perpetto_Perpetto_Helper_Api extends Mage_Core_Helper_Abstract
|
7 |
+
{
|
8 |
+
const ERROR_PREFIX = 'Perpetto API Error: ';
|
9 |
+
|
10 |
+
/**
|
11 |
+
* @var array
|
12 |
+
*/
|
13 |
+
protected $_clients = array();
|
14 |
+
|
15 |
+
/**
|
16 |
+
* @param null $accountId
|
17 |
+
* @param null $secret
|
18 |
+
* @return Perpetto_Client
|
19 |
+
*/
|
20 |
+
protected function _getApiClient($accountId = null, $secret = null)
|
21 |
+
{
|
22 |
+
$accountId = is_null($accountId)
|
23 |
+
? Mage::helper('perpetto')->getAccountId()
|
24 |
+
: $accountId;
|
25 |
+
|
26 |
+
$secret = is_null($secret)
|
27 |
+
? Mage::helper('perpetto')->getSecret()
|
28 |
+
: $secret;
|
29 |
+
|
30 |
+
$key = sprintf('%s_%s', $accountId, $secret);
|
31 |
+
|
32 |
+
if (!array_key_exists($key, $this->_clients)) {
|
33 |
+
$api = new Perpetto_Client($accountId, $secret);
|
34 |
+
$this->_clients[$key] = $api;
|
35 |
+
}
|
36 |
+
|
37 |
+
return $this->_clients[$key];
|
38 |
+
}
|
39 |
+
|
40 |
+
/**
|
41 |
+
* @param $campaignId
|
42 |
+
* @param $emailId
|
43 |
+
* @return $this
|
44 |
+
* @throws Perpetto_Perpetto_Exception
|
45 |
+
*/
|
46 |
+
public function sendEmailCampaignTestEmail($campaignId, $emailId)
|
47 |
+
{
|
48 |
+
$api = $this->_getApiClient();
|
49 |
+
|
50 |
+
try {
|
51 |
+
$result = $api->sendEmailCampaignTestEmail($campaignId, $emailId);
|
52 |
+
if ($result->hasError()) {
|
53 |
+
throw new Perpetto_Perpetto_Exception('Perpetto API Error: ' . $result->getError());
|
54 |
+
}
|
55 |
+
} catch (Perpetto_Exception $e) {
|
56 |
+
$code = $e->getCode();
|
57 |
+
$message = self::ERROR_PREFIX . $e->getMessage();
|
58 |
+
throw new Perpetto_Perpetto_Exception($message, $code, $e);
|
59 |
+
}
|
60 |
+
|
61 |
+
return $this;
|
62 |
+
}
|
63 |
+
|
64 |
+
/**
|
65 |
+
* @param null $accountId
|
66 |
+
* @param null $secret
|
67 |
+
* @return $this
|
68 |
+
* @throws Perpetto_Perpetto_Exception
|
69 |
+
*/
|
70 |
+
public function updateEmailCampaigns($accountId = null, $secret = null)
|
71 |
+
{
|
72 |
+
$api = $this->_getApiClient($accountId, $secret);
|
73 |
+
|
74 |
+
try {
|
75 |
+
$response = $api->loadEmailCampaigns();
|
76 |
+
} catch (Perpetto_Exception $e) {
|
77 |
+
$code = $e->getCode();
|
78 |
+
$message = self::ERROR_PREFIX . $e->getMessage();
|
79 |
+
throw new Perpetto_Perpetto_Exception($message, $code, $e);
|
80 |
+
}
|
81 |
+
|
82 |
+
if ($response->hasError()) {
|
83 |
+
$message = self::ERROR_PREFIX . $response->getError();
|
84 |
+
throw new Perpetto_Perpetto_Exception($message);
|
85 |
+
}
|
86 |
+
|
87 |
+
$campaignsJSON = $response->getJSON();
|
88 |
+
|
89 |
+
$config = Mage::getModel('core/config');
|
90 |
+
$config->saveConfig(Perpetto_Perpetto_Helper_Data::XML_PATH_CAMPAIGNS_JSON, $campaignsJSON, 'default', 0);
|
91 |
+
|
92 |
+
return $this;
|
93 |
+
}
|
94 |
+
|
95 |
+
/**
|
96 |
+
* @param null $accountId
|
97 |
+
* @param null $secret
|
98 |
+
* @return $this
|
99 |
+
* @throws Perpetto_Perpetto_Exception
|
100 |
+
*/
|
101 |
+
public function updateInfo($accountId = null, $secret = null)
|
102 |
+
{
|
103 |
+
$config = Mage::getModel('core/config');
|
104 |
+
$config->saveConfig(Perpetto_Perpetto_Helper_Data::XML_PATH_ACTIVE_FLAG, 0, 'default', 0);
|
105 |
+
$config->saveConfig(Perpetto_Perpetto_Helper_Data::XML_PATH_ACCOUNT_ID, $accountId, 'default', 0);
|
106 |
+
$config->saveConfig(Perpetto_Perpetto_Helper_Data::XML_PATH_SECRET, $secret, 'default', 0);
|
107 |
+
|
108 |
+
$api = $this->_getApiClient($accountId, $secret);
|
109 |
+
|
110 |
+
try {
|
111 |
+
$response = $api->loadInfo();
|
112 |
+
} catch (Perpetto_Exception $e) {
|
113 |
+
$code = $e->getCode();
|
114 |
+
$message = self::ERROR_PREFIX . $e->getMessage();
|
115 |
+
throw new Perpetto_Perpetto_Exception($message, $code, $e);
|
116 |
+
}
|
117 |
+
|
118 |
+
if ($response->hasError()) {
|
119 |
+
$message = self::ERROR_PREFIX . $response->getError();
|
120 |
+
throw new Perpetto_Perpetto_Exception($message);
|
121 |
+
}
|
122 |
+
|
123 |
+
$infoJSON = $response->getJSON();
|
124 |
+
$storeId = $response->getData('store/id');
|
125 |
+
$embedJsUrl = $response->getData('store/embedjs_uri');
|
126 |
+
$accountRealId = $response->getData('store/account_id');
|
127 |
+
|
128 |
+
if (!is_numeric($storeId)) {
|
129 |
+
throw new Perpetto_Perpetto_Exception('Invalid store ID.');
|
130 |
+
}
|
131 |
+
|
132 |
+
$config->saveConfig(Perpetto_Perpetto_Helper_Data::XML_PATH_ACCOUNT_REAL_ID, $accountRealId, 'default', 0);
|
133 |
+
$config->saveConfig(Perpetto_Perpetto_Helper_Data::XML_PATH_ACTIVE_FLAG, 1, 'default', 0);
|
134 |
+
$config->saveConfig(Perpetto_Perpetto_Helper_Data::XML_PATH_STORE_ID, $storeId, 'default', 0);
|
135 |
+
$config->saveConfig(Perpetto_Perpetto_Helper_Data::XML_PATH_EMBED_JS_URI, $embedJsUrl, 'default', 0);
|
136 |
+
$config->saveConfig(Perpetto_Perpetto_Helper_Data::XML_PATH_INFO_JSON, $infoJSON, 'default', 0);
|
137 |
+
|
138 |
+
$data = array(
|
139 |
+
'account_id' => $accountId,
|
140 |
+
'secret' => $secret,
|
141 |
+
'store_id' => $storeId,
|
142 |
+
'embedjs_uri' => $embedJsUrl,
|
143 |
+
'info_json' => $infoJSON,
|
144 |
+
);
|
145 |
+
|
146 |
+
Mage::dispatchEvent('perpetto_info_update_after', $data);
|
147 |
+
|
148 |
+
return $this;
|
149 |
+
}
|
150 |
+
|
151 |
+
/**
|
152 |
+
* @param null $accountId
|
153 |
+
* @param null $secret
|
154 |
+
* @return $this
|
155 |
+
* @throws Perpetto_Perpetto_Exception
|
156 |
+
*/
|
157 |
+
public function updateSlots($accountId = null, $secret = null)
|
158 |
+
{
|
159 |
+
$api = $this->_getApiClient($accountId, $secret);
|
160 |
+
|
161 |
+
try {
|
162 |
+
$response = $api->loadSlots();
|
163 |
+
} catch (Perpetto_Exception $e) {
|
164 |
+
$code = $e->getCode();
|
165 |
+
$message = self::ERROR_PREFIX . $e->getMessage();
|
166 |
+
throw new Perpetto_Perpetto_Exception($message, $code, $e);
|
167 |
+
}
|
168 |
+
|
169 |
+
if ($response->hasError()) {
|
170 |
+
$message = self::ERROR_PREFIX . $response->getError();
|
171 |
+
throw new Perpetto_Perpetto_Exception($message);
|
172 |
+
}
|
173 |
+
|
174 |
+
$slotsJSON = $response->getJSON();
|
175 |
+
|
176 |
+
$config = Mage::getModel('core/config');
|
177 |
+
$config->saveConfig(Perpetto_Perpetto_Helper_Data::XML_PATH_SLOTS_JSON, $slotsJSON, 'default', 0);
|
178 |
+
|
179 |
+
// Get slots entities by Perpetto slot ID
|
180 |
+
$slotsCollection = Mage::getResourceModel('perpetto/slot_collection');
|
181 |
+
$slotsById = array();
|
182 |
+
foreach ($slotsCollection as $slot) {
|
183 |
+
$slotsById[$slot->getPerpettoId()] = $slot;
|
184 |
+
}
|
185 |
+
|
186 |
+
// Iterate slots
|
187 |
+
$slots = array();
|
188 |
+
$slotsData = (array)$response->getData('slots');
|
189 |
+
foreach ($slotsData as $index => &$slotData) {
|
190 |
+
$slotData = (array)$slotData;
|
191 |
+
if (!array_key_exists('id', $slotData) || !is_numeric($slotData['id'])) {
|
192 |
+
$message = sprintf('Invalid ID for slot index %d', $index);
|
193 |
+
throw new Perpetto_Perpetto_Exception($message);
|
194 |
+
}
|
195 |
+
|
196 |
+
$perpettoId = $slotData['id'];
|
197 |
+
unset($slotData['id']);
|
198 |
+
|
199 |
+
$slotData['perpetto_id'] = $perpettoId;
|
200 |
+
|
201 |
+
$slot = array_key_exists($slotData['perpetto_id'], $slotsById)
|
202 |
+
? $slotsById[$slotData['perpetto_id']]
|
203 |
+
: Mage::getModel('perpetto/slot');
|
204 |
+
|
205 |
+
$slot->addData($slotData);
|
206 |
+
$slot->save();
|
207 |
+
|
208 |
+
array_push($slots, $slot);
|
209 |
+
unset($slotsById[$perpettoId]);
|
210 |
+
}
|
211 |
+
|
212 |
+
// Delete old slots
|
213 |
+
foreach ($slotsById as $slot) {
|
214 |
+
/** @var $slot Perpetto_Perpetto_Model_Slot */
|
215 |
+
$slot->delete();
|
216 |
+
}
|
217 |
+
|
218 |
+
$data = array(
|
219 |
+
'slots' => $slots
|
220 |
+
);
|
221 |
+
|
222 |
+
Mage::dispatchEvent('perpetto_slots_update_after', $data);
|
223 |
+
|
224 |
+
return $this;
|
225 |
+
}
|
226 |
+
|
227 |
+
/**
|
228 |
+
* @param Mage_Catalog_Model_Product $product
|
229 |
+
* @return $this
|
230 |
+
* @throws Perpetto_Perpetto_Exception
|
231 |
+
*/
|
232 |
+
public function updateProduct(Mage_Catalog_Model_Product $product)
|
233 |
+
{
|
234 |
+
$imageUrl = Mage::helper('catalog/image')->init($product, 'image')->__toString();
|
235 |
+
|
236 |
+
$helper = Mage::helper('perpetto/catalog');
|
237 |
+
$categories = $product->getCategoryCollection();
|
238 |
+
$paths = array();
|
239 |
+
|
240 |
+
$defaultStoreId = Mage::app()->getDefaultStoreView()->getId();
|
241 |
+
$breakId = Mage::app()->getStore($defaultStoreId)->getRootCategoryId();
|
242 |
+
|
243 |
+
foreach ($categories as $category) {
|
244 |
+
/** @var Mage_Catalog_Model_Category $category */
|
245 |
+
$paths[] = $helper->getCategoryPath($category, $breakId);
|
246 |
+
}
|
247 |
+
|
248 |
+
$price = $helper->getProductPrice($product);
|
249 |
+
|
250 |
+
$perpettoProduct = new Perpetto_Product();
|
251 |
+
$perpettoProduct->setId($product->getId())
|
252 |
+
->setName($product->getName())
|
253 |
+
->setImage($imageUrl)
|
254 |
+
->setUrl($product->getProductUrl())
|
255 |
+
->setListPrice($price)
|
256 |
+
->setCurrency($product->getStore()->getCurrentCurrencyCode())
|
257 |
+
->setAvailability($product->isAvailable())
|
258 |
+
->setCategories($paths)
|
259 |
+
->setPrice($product->getFinalPrice())
|
260 |
+
->setBrand($product->getBrand())
|
261 |
+
->setSummary($product->getDescription());
|
262 |
+
|
263 |
+
$api = $this->_getApiClient();
|
264 |
+
|
265 |
+
try {
|
266 |
+
$response = $api->updateProduct($perpettoProduct);
|
267 |
+
} catch (Perpetto_Exception $e) {
|
268 |
+
$code = $e->getCode();
|
269 |
+
$message = self::ERROR_PREFIX . $e->getMessage();
|
270 |
+
throw new Perpetto_Perpetto_Exception($message, $code, $e);
|
271 |
+
}
|
272 |
+
|
273 |
+
if ($response->hasError()) {
|
274 |
+
$message = self::ERROR_PREFIX . $response->getError();
|
275 |
+
throw new Perpetto_Perpetto_Exception($message);
|
276 |
+
}
|
277 |
+
|
278 |
+
return $this;
|
279 |
+
}
|
280 |
+
|
281 |
+
}
|
app/code/community/Perpetto/Perpetto/Helper/Catalog.php
ADDED
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Class Perpetto_Perpetto_Helper_Catalog
|
5 |
+
*/
|
6 |
+
class Perpetto_Perpetto_Helper_Catalog extends Mage_Core_Helper_Abstract
|
7 |
+
{
|
8 |
+
/**
|
9 |
+
* Cache tag
|
10 |
+
*/
|
11 |
+
const CACHE_TAG = 'perpetto';
|
12 |
+
|
13 |
+
/**
|
14 |
+
* Get category name from cache by ID
|
15 |
+
*
|
16 |
+
* @param $categoryId
|
17 |
+
* @return string
|
18 |
+
*/
|
19 |
+
public function getCategoryNameById($categoryId)
|
20 |
+
{
|
21 |
+
$categoryId = (int)$categoryId;
|
22 |
+
$storeId = Mage::app()->getStore()->getId();
|
23 |
+
|
24 |
+
$cache = Mage::app()->getCache();
|
25 |
+
$categoryNameCacheKey = sprintf('perpetto_category_name_%d_%d', $storeId, $categoryId);
|
26 |
+
$categoryName = $cache->load($categoryNameCacheKey);
|
27 |
+
|
28 |
+
if (!$categoryName) {
|
29 |
+
$category = Mage::getModel('catalog/category')->load($categoryId);
|
30 |
+
if ($category->getId()) {
|
31 |
+
$categoryName = $category->getName();
|
32 |
+
$tags = array(self::CACHE_TAG, Mage_Catalog_Model_Category::CACHE_TAG);
|
33 |
+
$cache->save($categoryNameCacheKey, $categoryName, $tags);
|
34 |
+
}
|
35 |
+
}
|
36 |
+
|
37 |
+
return $categoryName;
|
38 |
+
}
|
39 |
+
|
40 |
+
/**
|
41 |
+
* Get category path
|
42 |
+
*
|
43 |
+
* @param Mage_Catalog_Model_Category $category
|
44 |
+
* @param int $breakId
|
45 |
+
* @return string
|
46 |
+
*/
|
47 |
+
public function getCategoryPath(Mage_Catalog_Model_Category $category, $breakId = null)
|
48 |
+
{
|
49 |
+
$categoryNames = array();
|
50 |
+
$pathIds = $category->getPathIds();
|
51 |
+
|
52 |
+
rsort($pathIds);
|
53 |
+
|
54 |
+
foreach ($pathIds as $categoryId) {
|
55 |
+
if ($categoryId == Mage::app()->getStore()->getRootCategoryId() || $breakId == $categoryId) {
|
56 |
+
break;
|
57 |
+
}
|
58 |
+
|
59 |
+
$categoryNames[] = $this->getCategoryNameById($categoryId);
|
60 |
+
}
|
61 |
+
|
62 |
+
$categoryNames = array_reverse($categoryNames);
|
63 |
+
|
64 |
+
$path = implode('/', $categoryNames);
|
65 |
+
|
66 |
+
return $path;
|
67 |
+
}
|
68 |
+
|
69 |
+
/**
|
70 |
+
* @param Mage_Catalog_Model_Product $product
|
71 |
+
* @return array
|
72 |
+
* @throws Exception
|
73 |
+
*/
|
74 |
+
public function getProductCategoryPaths(Mage_Catalog_Model_Product $product)
|
75 |
+
{
|
76 |
+
$storeId = Mage::app()->getStore()->getId();
|
77 |
+
$productId = $product->getId();
|
78 |
+
|
79 |
+
$pathsCacheKey = sprintf('perpetto_product_paths_%d_%d', $storeId, $productId);
|
80 |
+
|
81 |
+
$cache = Mage::app()->getCache();
|
82 |
+
$pathsData = $cache->load($pathsCacheKey);
|
83 |
+
|
84 |
+
if (!$pathsData) {
|
85 |
+
$paths = array();
|
86 |
+
|
87 |
+
$categories = $product->getCategoryCollection();
|
88 |
+
foreach ($categories as $category) {
|
89 |
+
/** @var Mage_Catalog_Model_Category $category */
|
90 |
+
$paths[] = $this->getCategoryPath($category);
|
91 |
+
|
92 |
+
$pathsData = serialize($paths);
|
93 |
+
$tags = array(self::CACHE_TAG, Mage_Catalog_Model_Product::CACHE_TAG);
|
94 |
+
$cache->save($pathsCacheKey, $pathsData, $tags);
|
95 |
+
}
|
96 |
+
} else {
|
97 |
+
$paths = (array)unserialize($pathsData);
|
98 |
+
}
|
99 |
+
|
100 |
+
return $paths;
|
101 |
+
}
|
102 |
+
|
103 |
+
/**
|
104 |
+
* @param Mage_Catalog_Model_Product $product
|
105 |
+
* @return number
|
106 |
+
*/
|
107 |
+
public function getProductPrice($product)
|
108 |
+
{
|
109 |
+
$price = (string)$product->getPrice();
|
110 |
+
|
111 |
+
if ($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_BUNDLE
|
112 |
+
&& $product->getPriceType() == Mage_Bundle_Model_Product_Price::PRICE_TYPE_DYNAMIC
|
113 |
+
) {
|
114 |
+
$priceModel = $product->getPriceModel();
|
115 |
+
/** @var $priceModel Mage_Bundle_Model_Product_Price */
|
116 |
+
|
117 |
+
$tax = Mage::helper('tax');
|
118 |
+
|
119 |
+
if ($tax->displayPriceIncludingTax()) {
|
120 |
+
$minPrice = $priceModel->getTotalPrices($product, 'min', true, false);
|
121 |
+
} else {
|
122 |
+
$minPrice = $priceModel->getTotalPrices($product, 'min', null, false);
|
123 |
+
}
|
124 |
+
|
125 |
+
$price = $minPrice;
|
126 |
+
}
|
127 |
+
|
128 |
+
return $price;
|
129 |
+
}
|
130 |
+
|
131 |
+
}
|
app/code/community/Perpetto/Perpetto/Helper/Data.php
ADDED
@@ -0,0 +1,132 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Class Perpetto_Perpetto_Helper_Data
|
5 |
+
*/
|
6 |
+
class Perpetto_Perpetto_Helper_Data extends Mage_Core_Helper_Abstract
|
7 |
+
{
|
8 |
+
const XML_PATH_ACTIVE_FLAG = 'perpetto/general/active';
|
9 |
+
const XML_PATH_ACCOUNT_ID = 'perpetto/general/account_id';
|
10 |
+
const XML_PATH_ACCOUNT_REAL_ID = 'perpetto/general/account_real_id'; // This is lame
|
11 |
+
const XML_PATH_SECRET = 'perpetto/general/secret';
|
12 |
+
const XML_PATH_STORE_ID = 'perpetto/general/store_id';
|
13 |
+
const XML_PATH_EMBED_JS_URI = 'perpetto/general/embed_js_uri';
|
14 |
+
const XML_PATH_CAMPAIGNS_JSON = 'perpetto/general/campaigns_json';
|
15 |
+
const XML_PATH_INFO_JSON = 'perpetto/general/info_json';
|
16 |
+
const XML_PATH_SLOTS_JSON = 'perpetto/general/slots_json';
|
17 |
+
|
18 |
+
/**
|
19 |
+
* @return string
|
20 |
+
*/
|
21 |
+
public function getAccountId()
|
22 |
+
{
|
23 |
+
$accountId = Mage::getStoreConfig(self::XML_PATH_ACCOUNT_ID);
|
24 |
+
|
25 |
+
return $accountId;
|
26 |
+
}
|
27 |
+
|
28 |
+
/**
|
29 |
+
* @return string
|
30 |
+
*/
|
31 |
+
public function getAccountRealId()
|
32 |
+
{
|
33 |
+
$accountId = Mage::getStoreConfig(self::XML_PATH_ACCOUNT_REAL_ID);
|
34 |
+
|
35 |
+
return $accountId;
|
36 |
+
}
|
37 |
+
|
38 |
+
/**
|
39 |
+
* @return mixed
|
40 |
+
*/
|
41 |
+
public function getAccountInfo()
|
42 |
+
{
|
43 |
+
$json = Mage::getStoreConfig(self::XML_PATH_INFO_JSON);
|
44 |
+
$info = json_decode($json, JSON_OBJECT_AS_ARRAY);
|
45 |
+
|
46 |
+
return $info;
|
47 |
+
}
|
48 |
+
|
49 |
+
/**
|
50 |
+
* @return array
|
51 |
+
*/
|
52 |
+
public function getEmailCampaigns()
|
53 |
+
{
|
54 |
+
$json = Mage::getStoreConfig(self::XML_PATH_CAMPAIGNS_JSON);
|
55 |
+
$info = json_decode($json, JSON_OBJECT_AS_ARRAY);
|
56 |
+
|
57 |
+
$campaigns = array();
|
58 |
+
if (is_array($info) && isset($info['data']['campaigns']) && is_array($info['data']['campaigns'])) {
|
59 |
+
$campaigns = $info['data']['campaigns'];
|
60 |
+
}
|
61 |
+
|
62 |
+
return $campaigns;
|
63 |
+
}
|
64 |
+
|
65 |
+
/**
|
66 |
+
* @return string
|
67 |
+
*/
|
68 |
+
public function getEmbedJsUrl()
|
69 |
+
{
|
70 |
+
$jsUrl = Mage::getStoreConfig(self::XML_PATH_EMBED_JS_URI);
|
71 |
+
|
72 |
+
return $jsUrl;
|
73 |
+
}
|
74 |
+
|
75 |
+
/**
|
76 |
+
* @return string
|
77 |
+
*/
|
78 |
+
public function getSecret()
|
79 |
+
{
|
80 |
+
$secret = Mage::getStoreConfig(self::XML_PATH_SECRET);
|
81 |
+
|
82 |
+
return $secret;
|
83 |
+
}
|
84 |
+
|
85 |
+
/**
|
86 |
+
* @return mixed
|
87 |
+
*/
|
88 |
+
public function getStoreId()
|
89 |
+
{
|
90 |
+
$storeId = Mage::getStoreConfig(self::XML_PATH_STORE_ID);
|
91 |
+
|
92 |
+
return $storeId;
|
93 |
+
}
|
94 |
+
|
95 |
+
/**
|
96 |
+
* @return bool
|
97 |
+
*/
|
98 |
+
public function isActive()
|
99 |
+
{
|
100 |
+
$isActive = (bool)Mage::getStoreConfig(self::XML_PATH_ACTIVE_FLAG);
|
101 |
+
|
102 |
+
return $isActive;
|
103 |
+
}
|
104 |
+
|
105 |
+
/**
|
106 |
+
* @return bool
|
107 |
+
*/
|
108 |
+
public function isTrial()
|
109 |
+
{
|
110 |
+
$info = $this->getAccountInfo();
|
111 |
+
$store = $info['data']['store'];
|
112 |
+
$isTrial = array_key_exists('trial_days_left', $store) && !empty($store['trial_days_left']);
|
113 |
+
|
114 |
+
return $isTrial;
|
115 |
+
}
|
116 |
+
|
117 |
+
/**
|
118 |
+
* @return int
|
119 |
+
*/
|
120 |
+
public function getTrialDaysLeft()
|
121 |
+
{
|
122 |
+
$days = 0;
|
123 |
+
|
124 |
+
$info = $this->getAccountInfo();
|
125 |
+
if (array_key_exists('trial_days_left', $info)) {
|
126 |
+
$days = (int)$info['trial_days_left'];
|
127 |
+
$days = max(0, $days);
|
128 |
+
}
|
129 |
+
|
130 |
+
return $days;
|
131 |
+
}
|
132 |
+
}
|
app/code/community/Perpetto/Perpetto/Helper/Url.php
ADDED
@@ -0,0 +1,180 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Class Perpetto_Perpetto_Helper_Url
|
5 |
+
*/
|
6 |
+
class Perpetto_Perpetto_Helper_Url extends Mage_Core_Helper_Abstract
|
7 |
+
{
|
8 |
+
const BASE_URL = 'https://admin.perpetto.com';
|
9 |
+
|
10 |
+
/**
|
11 |
+
* @return string
|
12 |
+
*/
|
13 |
+
public function getSignInUrl()
|
14 |
+
{
|
15 |
+
$url = self::BASE_URL . '/#/sign_in';
|
16 |
+
|
17 |
+
return $url;
|
18 |
+
}
|
19 |
+
|
20 |
+
/**
|
21 |
+
* @return string
|
22 |
+
*/
|
23 |
+
public function getSignUpUrl()
|
24 |
+
{
|
25 |
+
$url = self::BASE_URL . '/#/sign_up/start/plugin_magento';
|
26 |
+
|
27 |
+
return $url;
|
28 |
+
}
|
29 |
+
|
30 |
+
/**
|
31 |
+
* @return string
|
32 |
+
*/
|
33 |
+
public function getBillingUrl()
|
34 |
+
{
|
35 |
+
$url = '';
|
36 |
+
|
37 |
+
$helper = Mage::helper('perpetto');
|
38 |
+
if ($helper->isActive()) {
|
39 |
+
$accountId = $helper->getAccountRealId();
|
40 |
+
|
41 |
+
$path = sprintf('/#/account/%s/settings/billing', $accountId);
|
42 |
+
$url = self::BASE_URL . $path;
|
43 |
+
}
|
44 |
+
|
45 |
+
return $url;
|
46 |
+
}
|
47 |
+
|
48 |
+
/**
|
49 |
+
* @return string
|
50 |
+
*/
|
51 |
+
public function getContactsUrl()
|
52 |
+
{
|
53 |
+
$url = '';
|
54 |
+
|
55 |
+
$helper = Mage::helper('perpetto');
|
56 |
+
if ($helper->isActive()) {
|
57 |
+
$accountId = $helper->getAccountRealId();
|
58 |
+
$storeId = $helper->getStoreId();
|
59 |
+
|
60 |
+
$path = sprintf('/#/account/%s/store/details/%d/settings/intercom', $accountId, $storeId);
|
61 |
+
$url = self::BASE_URL . $path;
|
62 |
+
}
|
63 |
+
|
64 |
+
return $url;
|
65 |
+
}
|
66 |
+
|
67 |
+
/**
|
68 |
+
* @return string
|
69 |
+
*/
|
70 |
+
public function getEmailCampaignsDashboardUrl()
|
71 |
+
{
|
72 |
+
$url = '';
|
73 |
+
|
74 |
+
$helper = Mage::helper('perpetto');
|
75 |
+
if ($helper->isActive()) {
|
76 |
+
$accountId = $helper->getAccountRealId();
|
77 |
+
$storeId = $helper->getStoreId();
|
78 |
+
|
79 |
+
$path = sprintf('/#/account/%s/dashboard/%d/emails/', $accountId, $storeId);
|
80 |
+
$url = self::BASE_URL . $path;
|
81 |
+
}
|
82 |
+
|
83 |
+
return $url;
|
84 |
+
}
|
85 |
+
|
86 |
+
/**
|
87 |
+
* @return string
|
88 |
+
*/
|
89 |
+
public function getEmailCampaignsUrl()
|
90 |
+
{
|
91 |
+
$url = '';
|
92 |
+
|
93 |
+
$helper = Mage::helper('perpetto');
|
94 |
+
if ($helper->isActive()) {
|
95 |
+
$accountId = $helper->getAccountRealId();
|
96 |
+
$storeId = $helper->getStoreId();
|
97 |
+
|
98 |
+
$path = sprintf('/#/account/%s/emails/%d/campaigns', $accountId, $storeId);
|
99 |
+
$url = self::BASE_URL . $path;
|
100 |
+
}
|
101 |
+
|
102 |
+
return $url;
|
103 |
+
}
|
104 |
+
|
105 |
+
/**
|
106 |
+
* @return string
|
107 |
+
*/
|
108 |
+
public function getRecommendationsDashboardUrl()
|
109 |
+
{
|
110 |
+
$url = '';
|
111 |
+
|
112 |
+
$helper = Mage::helper('perpetto');
|
113 |
+
if ($helper->isActive()) {
|
114 |
+
$accountId = $helper->getAccountRealId();
|
115 |
+
$storeId = $helper->getStoreId();
|
116 |
+
|
117 |
+
$path = sprintf('/#/account/%s/dashboard/%d/recommendations/', $accountId, $storeId);
|
118 |
+
$url = self::BASE_URL . $path;
|
119 |
+
}
|
120 |
+
|
121 |
+
return $url;
|
122 |
+
}
|
123 |
+
|
124 |
+
/**
|
125 |
+
* @return string
|
126 |
+
*/
|
127 |
+
public function getRecommendationsUrl()
|
128 |
+
{
|
129 |
+
$url = '';
|
130 |
+
|
131 |
+
$helper = Mage::helper('perpetto');
|
132 |
+
if ($helper->isActive()) {
|
133 |
+
$accountId = $helper->getAccountRealId();
|
134 |
+
$storeId = $helper->getStoreId();
|
135 |
+
|
136 |
+
$path = sprintf('/#/account/%s/recs/%d/list', $accountId, $storeId);
|
137 |
+
$url = self::BASE_URL . $path;
|
138 |
+
}
|
139 |
+
|
140 |
+
return $url;
|
141 |
+
}
|
142 |
+
|
143 |
+
/**
|
144 |
+
* @return string
|
145 |
+
*/
|
146 |
+
public function getRandomProductPreviewUrl()
|
147 |
+
{
|
148 |
+
$storeId = 0;
|
149 |
+
foreach (Mage::app()->getWebsites(true) as $website) {
|
150 |
+
/** @var Mage_Core_Model_Website $website */
|
151 |
+
$storeId = $website->getDefaultStore()->getId();
|
152 |
+
if ($website->getIsDefault()) {
|
153 |
+
break;
|
154 |
+
}
|
155 |
+
}
|
156 |
+
|
157 |
+
$appEmulation = Mage::getSingleton('core/app_emulation');
|
158 |
+
$initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($storeId);
|
159 |
+
|
160 |
+
$collection = Mage::getModel('catalog/product')->getCollection();
|
161 |
+
$collection->addStoreFilter($storeId);
|
162 |
+
$collection->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds());
|
163 |
+
$collection->getSelect()->orderRand('entity_id');
|
164 |
+
$collection->getSelect()->limit('1');
|
165 |
+
|
166 |
+
$url = '';
|
167 |
+
|
168 |
+
if ($collection->count() > 0) {
|
169 |
+
$product = $collection->getFirstItem();
|
170 |
+
/** @var $product Mage_Catalog_Model_Product */
|
171 |
+
|
172 |
+
$url = $product->getUrlModel()->getUrl($product, array('_query' => 'ptto_env=PREVIEW'));
|
173 |
+
}
|
174 |
+
|
175 |
+
$appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
|
176 |
+
|
177 |
+
return $url;
|
178 |
+
}
|
179 |
+
|
180 |
+
}
|
app/code/community/Perpetto/Perpetto/Helper/Widget.php
ADDED
@@ -0,0 +1,217 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Class Perpetto_Perpetto_Helper_Widget
|
5 |
+
*/
|
6 |
+
class Perpetto_Perpetto_Helper_Widget extends Mage_Core_Helper_Abstract
|
7 |
+
{
|
8 |
+
|
9 |
+
/**
|
10 |
+
* @var array
|
11 |
+
*/
|
12 |
+
protected $_packageThemes = array();
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Create slot widget
|
16 |
+
*
|
17 |
+
* @param Perpetto_Perpetto_Model_Slot $slot
|
18 |
+
* @param string $packageTheme
|
19 |
+
* @param int $sortOrder
|
20 |
+
* @return $this
|
21 |
+
*/
|
22 |
+
public function createSlotWidget(Perpetto_Perpetto_Model_Slot $slot, $packageTheme = null, $sortOrder = 10)
|
23 |
+
{
|
24 |
+
$widgetInstance = Mage::getModel('widget/widget_instance');
|
25 |
+
|
26 |
+
$title = sprintf('Perpetto - %s - %s', $slot->getName(), $slot->getTitle());
|
27 |
+
$widgetInstance->setTitle($title);
|
28 |
+
|
29 |
+
$widgetInstance->setType('perpetto/recommendations');
|
30 |
+
$widgetInstance->setPackageTheme($packageTheme);
|
31 |
+
$widgetInstance->setStoreIds(array(0));
|
32 |
+
$widgetInstance->setSortOrder($sortOrder);
|
33 |
+
|
34 |
+
$slotId = (string)$slot->getPerpettoId();
|
35 |
+
$params = array(
|
36 |
+
'slot_id' => $slotId,
|
37 |
+
'attr_class' => '',
|
38 |
+
);
|
39 |
+
$params = serialize($params);
|
40 |
+
$widgetInstance->setWidgetParameters($params);
|
41 |
+
|
42 |
+
$groups = $this->_getSlotPageGroups($slot);
|
43 |
+
$widgetInstance->setPageGroups($groups);
|
44 |
+
|
45 |
+
$widgetInstance->save();
|
46 |
+
|
47 |
+
return $this;
|
48 |
+
}
|
49 |
+
|
50 |
+
/**
|
51 |
+
* @param Perpetto_Perpetto_Model_Slot $slot
|
52 |
+
* @param int $sortOrder
|
53 |
+
* @return $this
|
54 |
+
*/
|
55 |
+
public function createSlotWidgets(Perpetto_Perpetto_Model_Slot $slot, $sortOrder = 10)
|
56 |
+
{
|
57 |
+
$packageThemes = $this->_getActivePackageThemes();
|
58 |
+
|
59 |
+
foreach ($packageThemes as $packageTheme) {
|
60 |
+
if (!$this->slotWidgetExists($slot, $packageTheme)) {
|
61 |
+
$this->createSlotWidget($slot, $packageTheme, $sortOrder);
|
62 |
+
}
|
63 |
+
}
|
64 |
+
|
65 |
+
return $this;
|
66 |
+
}
|
67 |
+
|
68 |
+
/**
|
69 |
+
* @param Perpetto_Perpetto_Model_Slot $slot
|
70 |
+
* @return $this
|
71 |
+
* @throws Exception
|
72 |
+
*/
|
73 |
+
public function deleteSlotWidgets(Perpetto_Perpetto_Model_Slot $slot)
|
74 |
+
{
|
75 |
+
$perpettoId = $slot->getPerpettoId();
|
76 |
+
|
77 |
+
$like = sprintf('%%"slot_id";s:%d:"%d"%%', strlen($perpettoId), $perpettoId);
|
78 |
+
|
79 |
+
$collection = Mage::getModel('widget/widget_instance')->getCollection()
|
80 |
+
->addFieldToFilter('instance_type', 'perpetto/recommendations')
|
81 |
+
->addFieldToFilter('widget_parameters', array('like' => $like));
|
82 |
+
|
83 |
+
foreach ($collection as $widget) {
|
84 |
+
/** @var $widget Mage_Widget_Model_Widget_Instance */
|
85 |
+
$widget->delete();
|
86 |
+
}
|
87 |
+
|
88 |
+
return $this;
|
89 |
+
}
|
90 |
+
|
91 |
+
/**
|
92 |
+
* @param Perpetto_Perpetto_Model_Slot $slot
|
93 |
+
* @param string $packageTheme
|
94 |
+
* @return bool
|
95 |
+
*/
|
96 |
+
public function slotWidgetExists(Perpetto_Perpetto_Model_Slot $slot, $packageTheme)
|
97 |
+
{
|
98 |
+
$perpettoId = $slot->getPerpettoId();
|
99 |
+
|
100 |
+
$like = sprintf('%%"slot_id";s:%d:"%d"%%', strlen($perpettoId), $perpettoId);
|
101 |
+
|
102 |
+
$collection = Mage::getModel('widget/widget_instance')->getCollection()
|
103 |
+
->addFieldToFilter('instance_type', 'perpetto/recommendations')
|
104 |
+
->addFieldToFilter('package_theme', $packageTheme)
|
105 |
+
->addFieldToFilter('widget_parameters', array('like' => $like));
|
106 |
+
|
107 |
+
$result = $collection->count() > 0;
|
108 |
+
|
109 |
+
return $result;
|
110 |
+
}
|
111 |
+
|
112 |
+
/**
|
113 |
+
* Get all active themes
|
114 |
+
*
|
115 |
+
* @return array
|
116 |
+
*/
|
117 |
+
protected function _getActivePackageThemes()
|
118 |
+
{
|
119 |
+
if (empty($this->_packageThemes)) {
|
120 |
+
foreach (Mage::app()->getStores() as $store) {
|
121 |
+
$design = Mage::getModel('core/design_package');
|
122 |
+
$design->setStore($store);
|
123 |
+
|
124 |
+
$package = $design->getPackageName();
|
125 |
+
$theme = $design->getTheme('frontend');
|
126 |
+
|
127 |
+
$packageTheme = sprintf('%s/%s', $package, $theme);
|
128 |
+
|
129 |
+
$this->_packageThemes[$packageTheme] = $packageTheme;
|
130 |
+
}
|
131 |
+
}
|
132 |
+
|
133 |
+
return $this->_packageThemes;
|
134 |
+
}
|
135 |
+
|
136 |
+
/**
|
137 |
+
* Get page groups
|
138 |
+
*
|
139 |
+
* @param Perpetto_Perpetto_Model_Slot $slot
|
140 |
+
* @return array
|
141 |
+
*/
|
142 |
+
protected function _getSlotPageGroups(Perpetto_Perpetto_Model_Slot $slot)
|
143 |
+
{
|
144 |
+
$groups = array();
|
145 |
+
|
146 |
+
switch ($slot->getPage()) {
|
147 |
+
case 'product_page':
|
148 |
+
$groups[] = array(
|
149 |
+
'page_group' => 'all_products',
|
150 |
+
'all_products' => array(
|
151 |
+
'page_id' => 0,
|
152 |
+
'layout_handle' => 'default,catalog_product_view',
|
153 |
+
'for' => 'all',
|
154 |
+
'block' => 'content',
|
155 |
+
'is_anchor_only' => null,
|
156 |
+
'product_type_id' => null,
|
157 |
+
'entities' => null
|
158 |
+
)
|
159 |
+
);
|
160 |
+
break;
|
161 |
+
|
162 |
+
case 'home_page':
|
163 |
+
$groups[] = array(
|
164 |
+
'page_group' => 'pages',
|
165 |
+
'pages' => array(
|
166 |
+
'page_id' => 0,
|
167 |
+
'layout_handle' => 'cms_index_index',
|
168 |
+
'for' => 'all',
|
169 |
+
'block' => 'content'
|
170 |
+
)
|
171 |
+
);
|
172 |
+
break;
|
173 |
+
|
174 |
+
case 'category_page':
|
175 |
+
$groups[] = array(
|
176 |
+
'page_group' => 'anchor_categories',
|
177 |
+
'anchor_categories' => array(
|
178 |
+
'page_id' => 0,
|
179 |
+
'layout_handle' => 'default,catalog_category_layered',
|
180 |
+
'for' => 'all',
|
181 |
+
'block' => 'content',
|
182 |
+
'is_anchor_only' => 1,
|
183 |
+
'product_type_id' => null,
|
184 |
+
'entities' => null
|
185 |
+
)
|
186 |
+
);
|
187 |
+
$groups[] = array(
|
188 |
+
'page_group' => 'notanchor_categories',
|
189 |
+
'notanchor_categories' => array(
|
190 |
+
'page_id' => 0,
|
191 |
+
'layout_handle' => 'default,catalog_category_layered',
|
192 |
+
'for' => 'all',
|
193 |
+
'block' => 'content',
|
194 |
+
'is_anchor_only' => 0,
|
195 |
+
'product_type_id' => null,
|
196 |
+
'entities' => null
|
197 |
+
)
|
198 |
+
);
|
199 |
+
break;
|
200 |
+
|
201 |
+
case 'cart_page':
|
202 |
+
$groups[] = array(
|
203 |
+
'page_group' => 'pages',
|
204 |
+
'pages' => array(
|
205 |
+
'page_id' => 0,
|
206 |
+
'layout_handle' => 'checkout_cart_index',
|
207 |
+
'for' => 'all',
|
208 |
+
'block' => 'content'
|
209 |
+
)
|
210 |
+
);
|
211 |
+
break;
|
212 |
+
}
|
213 |
+
|
214 |
+
return $groups;
|
215 |
+
}
|
216 |
+
|
217 |
+
}
|
app/code/community/Perpetto/Perpetto/Model/Observer.php
ADDED
@@ -0,0 +1,258 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Class Perpetto_Perpetto_Model_Observer
|
5 |
+
*/
|
6 |
+
class Perpetto_Perpetto_Model_Observer
|
7 |
+
{
|
8 |
+
protected $_perpettoSlotsUpdated = false;
|
9 |
+
|
10 |
+
/**
|
11 |
+
* @param Varien_Event_Observer $observer
|
12 |
+
* @throws Perpetto_Perpetto_Exception
|
13 |
+
*/
|
14 |
+
public function saveAdminSettings(Varien_Event_Observer $observer)
|
15 |
+
{
|
16 |
+
if ($this->_perpettoSlotsUpdated) {
|
17 |
+
return;
|
18 |
+
}
|
19 |
+
|
20 |
+
$config = $observer->getObject();
|
21 |
+
|
22 |
+
if ($config instanceof Mage_Adminhtml_Model_Config_Data && $config->getSection() == 'perpetto') {
|
23 |
+
$groups = $config->getGroups();
|
24 |
+
|
25 |
+
$accountId = trim(@$groups['general']['fields']['account_id']['value']);
|
26 |
+
$secret = trim(@$groups['general']['fields']['secret']['value']);
|
27 |
+
|
28 |
+
$apiHelper = Mage::helper('perpetto/api');
|
29 |
+
$apiHelper->updateInfo($accountId, $secret);
|
30 |
+
$apiHelper->updateSlots($accountId, $secret);
|
31 |
+
$apiHelper->updateEmailCampaigns($accountId, $secret);
|
32 |
+
|
33 |
+
$config->setGroups(array());
|
34 |
+
$this->_perpettoSlotsUpdated = true;
|
35 |
+
}
|
36 |
+
|
37 |
+
/** @var Mage_Core_Model_Config_Data $config */
|
38 |
+
$config = $observer->getConfigData();
|
39 |
+
if ($config instanceof Mage_Core_Model_Config_Data && $config->getPath() == 'perpetto/general/account_id') {
|
40 |
+
$groups = $config->getGroups();
|
41 |
+
|
42 |
+
$accountId = trim(@$groups['general']['fields']['account_id']['value']);
|
43 |
+
$secret = trim(@$groups['general']['fields']['secret']['value']);
|
44 |
+
|
45 |
+
$apiHelper = Mage::helper('perpetto/api');
|
46 |
+
$apiHelper->updateInfo($accountId, $secret);
|
47 |
+
$apiHelper->updateSlots($accountId, $secret);
|
48 |
+
$apiHelper->updateEmailCampaigns($accountId, $secret);
|
49 |
+
|
50 |
+
$this->_perpettoSlotsUpdated = true;
|
51 |
+
}
|
52 |
+
}
|
53 |
+
|
54 |
+
/**
|
55 |
+
* Delete slot widgets
|
56 |
+
*/
|
57 |
+
public function deleteSlotWidgets(Varien_Event_Observer $observer)
|
58 |
+
{
|
59 |
+
$slot = $observer->getObject();
|
60 |
+
if ($slot instanceof Perpetto_Perpetto_Model_Slot) {
|
61 |
+
$pttoWidget = Mage::helper('perpetto/widget');
|
62 |
+
$pttoWidget->deleteSlotWidgets($slot);
|
63 |
+
}
|
64 |
+
}
|
65 |
+
|
66 |
+
/**
|
67 |
+
* Update slots widgets
|
68 |
+
*/
|
69 |
+
public function updateSlotsWidgets()
|
70 |
+
{
|
71 |
+
$slotsCollection = Mage::getResourceModel('perpetto/slot_collection');
|
72 |
+
|
73 |
+
$pagesSortOrders = array();
|
74 |
+
|
75 |
+
foreach ($slotsCollection as $slot) {
|
76 |
+
/** @var $slot Perpetto_Perpetto_Model_Slot */
|
77 |
+
|
78 |
+
$page = $slot->getPage();
|
79 |
+
if (!array_key_exists($page, $pagesSortOrders)) {
|
80 |
+
$pagesSortOrders[$page] = 0;
|
81 |
+
}
|
82 |
+
|
83 |
+
$sortOrder = $pagesSortOrders[$page] += 10;
|
84 |
+
|
85 |
+
Mage::helper('perpetto/widget')->createSlotWidgets($slot, $sortOrder);
|
86 |
+
}
|
87 |
+
}
|
88 |
+
|
89 |
+
/**
|
90 |
+
* Send product data to perpetto on product save
|
91 |
+
*
|
92 |
+
* @observer catalog_product_save_after
|
93 |
+
* @param Varien_Event_Observer $observer
|
94 |
+
*/
|
95 |
+
public function saveProduct(Varien_Event_Observer $observer)
|
96 |
+
{
|
97 |
+
$product = $observer->getProduct();
|
98 |
+
|
99 |
+
if ($product instanceof Mage_Catalog_Model_Product && $product->isVisibleInCatalog()) {
|
100 |
+
try {
|
101 |
+
$api = Mage::helper('perpetto/api');
|
102 |
+
$api->updateProduct($product);
|
103 |
+
} catch (Exception $e) {
|
104 |
+
Mage::logException($e);
|
105 |
+
}
|
106 |
+
}
|
107 |
+
}
|
108 |
+
|
109 |
+
/**
|
110 |
+
* Enable the showing of the customer service block
|
111 |
+
*
|
112 |
+
* @observe customer_register_success
|
113 |
+
* @param Varien_Event_Observer $observer
|
114 |
+
*/
|
115 |
+
public function setShowCustomerServiceBlock(Varien_Event_Observer $observer)
|
116 |
+
{
|
117 |
+
$this->_setShowCustomerServiceBlock(true);
|
118 |
+
}
|
119 |
+
|
120 |
+
/**
|
121 |
+
* Enable the showing of the customer service block
|
122 |
+
*
|
123 |
+
* @observe checkout_type_onepage_save_order_after
|
124 |
+
* @param Varien_Event_Observer $observer
|
125 |
+
*/
|
126 |
+
public function setShowCustomerServiceBlockAfterOrder(Varien_Event_Observer $observer)
|
127 |
+
{
|
128 |
+
$order = $observer->getData('order');
|
129 |
+
|
130 |
+
if ($order instanceof Mage_Sales_Model_Order) {
|
131 |
+
$session = $this->_getSession();
|
132 |
+
$session->setData('custom_user_service_email', $order->getCustomerEmail());
|
133 |
+
$session->setData('custom_user_service_firstname', $order->getCustomerFirstname());
|
134 |
+
$session->setData('custom_user_service_lastname', $order->getCustomerLastname());
|
135 |
+
|
136 |
+
$this->_setShowCustomerServiceBlock(true);
|
137 |
+
}
|
138 |
+
}
|
139 |
+
|
140 |
+
/**
|
141 |
+
* Enable the showing of the customer service block
|
142 |
+
*
|
143 |
+
* @observe customer_register_success
|
144 |
+
* @param Varien_Event_Observer $observer
|
145 |
+
*/
|
146 |
+
public function setShowCustomerServiceBlockEdit(Varien_Event_Observer $observer)
|
147 |
+
{
|
148 |
+
$request = Mage::app()->getRequest();
|
149 |
+
$controllerName = $request->getControllerName();
|
150 |
+
|
151 |
+
if ($controllerName == 'account') {
|
152 |
+
$this->_setShowCustomerServiceBlock(true);
|
153 |
+
}
|
154 |
+
}
|
155 |
+
|
156 |
+
/**
|
157 |
+
* Enable the showing of the customer service block
|
158 |
+
*
|
159 |
+
* @observe newsletter_subscriber_save_commit_after
|
160 |
+
* @param Varien_Event_Observer $observer
|
161 |
+
*/
|
162 |
+
public function setShowCustomerServiceBlockOnNewsletterSubscription(Varien_Event_Observer $observer)
|
163 |
+
{
|
164 |
+
$subscriber = $observer->getSubscriber();
|
165 |
+
|
166 |
+
if ($subscriber instanceof Mage_Newsletter_Model_Subscriber) {
|
167 |
+
$subscriberStatus = $subscriber->getSubscriberStatus();
|
168 |
+
if (Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED == $subscriberStatus) {
|
169 |
+
$session = $this->_getSession();
|
170 |
+
$session->setData('custom_user_service_email', $subscriber->getEmail());
|
171 |
+
|
172 |
+
$this->_setShowCustomerServiceBlock(true);
|
173 |
+
}
|
174 |
+
}
|
175 |
+
}
|
176 |
+
|
177 |
+
/**
|
178 |
+
* @param bool $status
|
179 |
+
*/
|
180 |
+
protected function _setShowCustomerServiceBlock($status = true)
|
181 |
+
{
|
182 |
+
$session = $this->_getSession();
|
183 |
+
$session->setData('_should_show_user_service_block', $status);
|
184 |
+
}
|
185 |
+
|
186 |
+
/**
|
187 |
+
* @return Mage_Customer_Model_Session
|
188 |
+
*/
|
189 |
+
protected function _getSession()
|
190 |
+
{
|
191 |
+
$session = Mage::getSingleton('customer/session');
|
192 |
+
|
193 |
+
return $session;
|
194 |
+
}
|
195 |
+
|
196 |
+
/**
|
197 |
+
* Put last registered customer to session
|
198 |
+
*
|
199 |
+
* @param Varien_Event_Observer $observer
|
200 |
+
*/
|
201 |
+
public function customerRegisterSuccess(Varien_Event_Observer $observer)
|
202 |
+
{
|
203 |
+
$customer = $observer->getEvent()->getCustomer();
|
204 |
+
if ($customer instanceof Mage_Customer_Model_Customer && $customer->getId()) {
|
205 |
+
$customerEmail = $customer->getEmail();
|
206 |
+
|
207 |
+
$orderCollection = Mage::getResourceModel('sales/order_collection')
|
208 |
+
->addFieldToFilter('customer_email', array('eq' => $customerEmail))
|
209 |
+
->setPageSize(1);
|
210 |
+
|
211 |
+
if ($orderCollection->count() > 0) {
|
212 |
+
return;
|
213 |
+
}
|
214 |
+
|
215 |
+
$this->_getSession()->setData('perpetto_customer_register_success', true);
|
216 |
+
}
|
217 |
+
}
|
218 |
+
|
219 |
+
/**
|
220 |
+
* @param Varien_Event_Observer $observer
|
221 |
+
*/
|
222 |
+
public function salesOrderPlaceAfter(Varien_Event_Observer $observer)
|
223 |
+
{
|
224 |
+
$order = $observer->getEvent()->getOrder();
|
225 |
+
$quote = Mage::getSingleton('checkout/session')->getQuote();
|
226 |
+
|
227 |
+
if ($order instanceof Mage_Sales_Model_Order) {
|
228 |
+
|
229 |
+
if ($order->getCustomerIsGuest() || $quote->getCheckoutMethod(true) == 'register') {
|
230 |
+
$customerEmail = $order->getCustomerEmail();
|
231 |
+
|
232 |
+
$orderCollection = Mage::getResourceModel('sales/order_collection')
|
233 |
+
->addFieldToFilter('customer_email', array('eq' => $customerEmail))
|
234 |
+
->addFieldToFilter('entity_id', array('neq' => $order->getId()))
|
235 |
+
->setPageSize(1);
|
236 |
+
|
237 |
+
if ($orderCollection->count() > 0) {
|
238 |
+
return;
|
239 |
+
}
|
240 |
+
|
241 |
+
$customerCollection = Mage::getResourceModel('customer/customer_collection')
|
242 |
+
->addFieldToFilter('email', array('eq' => $customerEmail))
|
243 |
+
->setPageSize(1);
|
244 |
+
|
245 |
+
if ($order->getCustomerId()) {
|
246 |
+
$customerCollection->addFieldToFilter('entity_id', array('neq' => $order->getCustomerId()));
|
247 |
+
}
|
248 |
+
|
249 |
+
if ($customerCollection->getSize() > 0) {
|
250 |
+
return;
|
251 |
+
}
|
252 |
+
|
253 |
+
$this->_getSession()->setData('perpetto_customer_register_success', true);
|
254 |
+
}
|
255 |
+
}
|
256 |
+
}
|
257 |
+
|
258 |
+
}
|
app/code/community/Perpetto/Perpetto/Model/Resource/Slot.php
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Class Perpetto_Perpetto_Model_Resource_Slot
|
5 |
+
*/
|
6 |
+
class Perpetto_Perpetto_Model_Resource_Slot extends Mage_Core_Model_Resource_Db_Abstract
|
7 |
+
{
|
8 |
+
|
9 |
+
/**
|
10 |
+
* Init
|
11 |
+
*/
|
12 |
+
protected function _construct()
|
13 |
+
{
|
14 |
+
$this->_init('perpetto/slots', 'slot_id');
|
15 |
+
}
|
16 |
+
|
17 |
+
}
|
app/code/community/Perpetto/Perpetto/Model/Resource/Slot/Collection.php
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Class Perpetto_Perpetto_Model_Resource_Slot_Collection
|
5 |
+
*/
|
6 |
+
class Perpetto_Perpetto_Model_Resource_Slot_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
|
7 |
+
{
|
8 |
+
|
9 |
+
/**
|
10 |
+
* Init
|
11 |
+
*/
|
12 |
+
protected function _construct()
|
13 |
+
{
|
14 |
+
$this->_init('perpetto/slot');
|
15 |
+
}
|
16 |
+
|
17 |
+
}
|
app/code/community/Perpetto/Perpetto/Model/Slot.php
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Class Perpetto_Perpetto_Model_Slot
|
5 |
+
*/
|
6 |
+
class Perpetto_Perpetto_Model_Slot extends Mage_Core_Model_Abstract
|
7 |
+
{
|
8 |
+
|
9 |
+
/**
|
10 |
+
* @var string
|
11 |
+
*/
|
12 |
+
protected $_eventPrefix = 'perpetto_slot';
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Init
|
16 |
+
*/
|
17 |
+
protected function _construct()
|
18 |
+
{
|
19 |
+
$this->_init('perpetto/slot');
|
20 |
+
}
|
21 |
+
|
22 |
+
}
|
app/code/community/Perpetto/Perpetto/Model/Source/Slots.php
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Class Perpetto_Perpetto_Model_Source_Slots
|
5 |
+
*/
|
6 |
+
class Perpetto_Perpetto_Model_Source_Slots
|
7 |
+
{
|
8 |
+
|
9 |
+
/**
|
10 |
+
* @return array
|
11 |
+
*/
|
12 |
+
public function toOptionArray()
|
13 |
+
{
|
14 |
+
$slots = Mage::getResourceModel('perpetto/slot_collection');
|
15 |
+
|
16 |
+
$groups = array();
|
17 |
+
|
18 |
+
foreach ($slots as $slot) {
|
19 |
+
$page = $slot->getPage();
|
20 |
+
|
21 |
+
if (!array_key_exists($page, $groups)) {
|
22 |
+
$groups[$page] = array();
|
23 |
+
}
|
24 |
+
|
25 |
+
array_push($groups[$page], $slot);
|
26 |
+
}
|
27 |
+
|
28 |
+
$options = array(
|
29 |
+
array(
|
30 |
+
'label' => '-- Select Perpetto Slot --',
|
31 |
+
'value' => '',
|
32 |
+
),
|
33 |
+
);
|
34 |
+
|
35 |
+
foreach ($groups as $page => $slots) {
|
36 |
+
$pageLabel = ucwords(str_replace('_', ' ', $page));
|
37 |
+
|
38 |
+
foreach ($slots as $slot) {
|
39 |
+
$label = sprintf('%s - %s', $pageLabel, $slot->getTitle());
|
40 |
+
$value = $slot->getPerpettoId();
|
41 |
+
|
42 |
+
$option = array(
|
43 |
+
'label' => $label,
|
44 |
+
'value' => $value,
|
45 |
+
);
|
46 |
+
|
47 |
+
array_push($options, $option);
|
48 |
+
}
|
49 |
+
}
|
50 |
+
|
51 |
+
return $options;
|
52 |
+
}
|
53 |
+
|
54 |
+
}
|
app/code/community/Perpetto/Perpetto/controllers/Adminhtml/Perpetto/CampaignsController.php
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Class Perpetto_Perpetto_Adminhtml_Perpetto_CampaignsController
|
5 |
+
*/
|
6 |
+
class Perpetto_Perpetto_Adminhtml_Perpetto_CampaignsController extends Mage_Adminhtml_Controller_Action
|
7 |
+
{
|
8 |
+
|
9 |
+
/**
|
10 |
+
* @return $this
|
11 |
+
*/
|
12 |
+
public function testAction()
|
13 |
+
{
|
14 |
+
$request = $this->getRequest();
|
15 |
+
$campaignId = (int) $request->getParam('campaign');
|
16 |
+
$emailId = (int) $request->getParam('email');
|
17 |
+
|
18 |
+
$api = Mage::helper('perpetto/api');
|
19 |
+
|
20 |
+
try {
|
21 |
+
$api->sendEmailCampaignTestEmail($campaignId, $emailId);
|
22 |
+
$this->_getSession()->addSuccess('Test email successfully dispatched.');
|
23 |
+
} catch (Exception $e) {
|
24 |
+
$message = 'Test email failed: ' . $e->getMessage();
|
25 |
+
$this->_getSession()->addError($message);
|
26 |
+
}
|
27 |
+
|
28 |
+
$this->_redirect('*/system_config/edit', array('section' => 'perpetto_campaigns'));
|
29 |
+
|
30 |
+
return $this;
|
31 |
+
}
|
32 |
+
}
|
app/code/community/Perpetto/Perpetto/controllers/OrdersController.php
ADDED
@@ -0,0 +1,219 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Class Perpetto_Perpetto_OrdersController
|
5 |
+
*/
|
6 |
+
class Perpetto_Perpetto_OrdersController extends Perpetto_Perpetto_Controller_Action
|
7 |
+
{
|
8 |
+
/**
|
9 |
+
* Slots action
|
10 |
+
*/
|
11 |
+
public function infoAction()
|
12 |
+
{
|
13 |
+
$response = $this->getResponse();
|
14 |
+
$request = $this->getRequest();
|
15 |
+
|
16 |
+
$core = Mage::helper('core');
|
17 |
+
|
18 |
+
$headers = array();
|
19 |
+
|
20 |
+
try {
|
21 |
+
$this->_validateRequest();
|
22 |
+
|
23 |
+
$startTime = $request->getParam('startTime');
|
24 |
+
$endTime = $request->getParam('endTime');
|
25 |
+
$count = 0;
|
26 |
+
$firstOrderId = 0;
|
27 |
+
$lastOrderId = 0;
|
28 |
+
|
29 |
+
/** @var Mage_Sales_Model_Resource_Order_Collection $collection */
|
30 |
+
$collection = Mage::getModel('sales/order')->getCollection();
|
31 |
+
if (!empty($startTime)) {
|
32 |
+
$startTime = gmdate('Y-m-d H:i:s', $startTime);
|
33 |
+
}
|
34 |
+
if (!empty($endTime)) {
|
35 |
+
$endTime = gmdate('Y-m-d H:i:s', $endTime);
|
36 |
+
}
|
37 |
+
|
38 |
+
if (!empty($startTime)) {
|
39 |
+
$collection->addFieldToFilter('created_at', array('gteq' => $startTime));
|
40 |
+
}
|
41 |
+
|
42 |
+
if (!empty($endTime)) {
|
43 |
+
$collection->addFieldToFilter('created_at', array('lteq' => $endTime));
|
44 |
+
}
|
45 |
+
|
46 |
+
if ($collection->count() > 0) {
|
47 |
+
/** @var Mage_Sales_Model_Order $firstOrder */
|
48 |
+
$firstOrder = $collection->getFirstItem();
|
49 |
+
$firstOrderId = $firstOrder->getId();
|
50 |
+
if (empty($startTime)) {
|
51 |
+
$startTime = $firstOrder->getCreatedAt();
|
52 |
+
}
|
53 |
+
|
54 |
+
/** @var Mage_Sales_Model_Order $lastOrder */
|
55 |
+
$lastOrder = $collection->getLastItem();
|
56 |
+
$lastOrderId = $lastOrder->getId();
|
57 |
+
if (empty($endTime)) {
|
58 |
+
$endTime = $lastOrder->getCreatedAt();
|
59 |
+
}
|
60 |
+
|
61 |
+
$count = $collection->count();
|
62 |
+
}
|
63 |
+
|
64 |
+
$data = array(
|
65 |
+
'info' => array(
|
66 |
+
'start_time' => strtotime($startTime . ' GMT'),
|
67 |
+
'end_time' => strtotime($endTime . ' GMT'),
|
68 |
+
'orders_count' => $count,
|
69 |
+
'first_order_id' => $firstOrderId,
|
70 |
+
'last_order_id' => $lastOrderId
|
71 |
+
)
|
72 |
+
);
|
73 |
+
|
74 |
+
} catch (Exception $e) {
|
75 |
+
$data = array(
|
76 |
+
'status' => 'error',
|
77 |
+
'error' => $e->getMessage(),
|
78 |
+
);
|
79 |
+
|
80 |
+
if (!array_key_exists('HTTP/1.1', $headers)) {
|
81 |
+
$headers['HTTP/1.1'] = '500 Internal Server Error';
|
82 |
+
}
|
83 |
+
}
|
84 |
+
|
85 |
+
$json = $core->jsonEncode($data);
|
86 |
+
$response->setBody($json);
|
87 |
+
|
88 |
+
$response->clearHeaders();
|
89 |
+
$response->setHeader('Content-Type', 'application/json', true);
|
90 |
+
foreach ($headers as $name => $value) {
|
91 |
+
$response->setHeader($name, $value);
|
92 |
+
}
|
93 |
+
}
|
94 |
+
|
95 |
+
/**
|
96 |
+
* Slots action
|
97 |
+
*/
|
98 |
+
public function listAction()
|
99 |
+
{
|
100 |
+
$response = $this->getResponse();
|
101 |
+
$request = $this->getRequest();
|
102 |
+
|
103 |
+
$core = Mage::helper('core');
|
104 |
+
|
105 |
+
$headers = array();
|
106 |
+
|
107 |
+
try {
|
108 |
+
$this->_validateRequest();
|
109 |
+
|
110 |
+
$pageSize = (int) $request->getParam('pageSize');
|
111 |
+
if ($pageSize == 0) {
|
112 |
+
throw new Perpetto_Perpetto_Exception('Invalid request, missing parameter pageSize.');
|
113 |
+
}
|
114 |
+
|
115 |
+
$firstOrderId = (int) $request->getParam('firstOrderId');
|
116 |
+
$lastOrderId = (int) $request->getParam('lastOrderId');
|
117 |
+
|
118 |
+
/** @var Mage_Sales_Model_Resource_Order_Collection $collection */
|
119 |
+
$collection = Mage::getModel('sales/order')->getCollection();
|
120 |
+
if ($firstOrderId > 0) {
|
121 |
+
$collection->addFieldToFilter('entity_id', array('gteq' => $firstOrderId));
|
122 |
+
} else if ($lastOrderId > 0) {
|
123 |
+
$collection->addFieldToFilter('entity_id', array('gt' => $lastOrderId));
|
124 |
+
}
|
125 |
+
|
126 |
+
$collection->setPageSize($pageSize);
|
127 |
+
$data = array(
|
128 |
+
'orders' => array(),
|
129 |
+
);
|
130 |
+
|
131 |
+
$orderIds = $collection->getAllIds();
|
132 |
+
$orderItems = Mage::getModel('sales/order_item')->getCollection();
|
133 |
+
$orderItems->addFieldToFilter('order_id', array('in' => $orderIds));
|
134 |
+
$itemData = array();
|
135 |
+
foreach ($orderItems as $item) {
|
136 |
+
if ($item->getParentItemId()) {
|
137 |
+
continue;
|
138 |
+
}
|
139 |
+
/** @var Mage_Catalog_Model_Product $product */
|
140 |
+
$product = Mage::getModel('catalog/product')
|
141 |
+
->setStoreId($item->getOrder()->getStoreId())
|
142 |
+
->load($item->getProduct()->getId());
|
143 |
+
|
144 |
+
$url = Mage::helper('catalog/image')->init($product, 'image')->__toString();
|
145 |
+
$price = Mage::helper('perpetto/catalog')->getProductPrice($product);
|
146 |
+
$finalPrice = $product->getFinalPrice();
|
147 |
+
|
148 |
+
$paths = Mage::helper('perpetto/catalog')->getProductCategoryPaths($product);
|
149 |
+
$categories = implode(',', $paths);
|
150 |
+
|
151 |
+
$productDetails = array(
|
152 |
+
'id' => $product->getId(),
|
153 |
+
'name' => $product->getName(),
|
154 |
+
'image' => $url,
|
155 |
+
'url' => $product->getUrlInStore(),
|
156 |
+
'listprice' => $price,
|
157 |
+
'currency' => Mage::app()->getStore($item->getOrder()->getStoreId())->getCurrentCurrencyCode(),
|
158 |
+
'availability' => (int)$product->getIsSalable(),
|
159 |
+
'categories' => $categories,
|
160 |
+
'category' => '',
|
161 |
+
'brand' => $product->getBrand(),
|
162 |
+
'tags' => '',
|
163 |
+
'summary' => $product->getDescription(),
|
164 |
+
);
|
165 |
+
|
166 |
+
if ($price != $finalPrice) {
|
167 |
+
$productDetails['price'] = $finalPrice;
|
168 |
+
}
|
169 |
+
|
170 |
+
/** @var Mage_Sales_Model_Order_Item $item */
|
171 |
+
$itemData[$item->getOrderId()][] = array(
|
172 |
+
'id' => $item->getId(),
|
173 |
+
'quantity' => $item->getQtyOrdered(),
|
174 |
+
'price' => $item->getPrice(),
|
175 |
+
'itemTotal' => $item->getRowTotal(),
|
176 |
+
'product' => $productDetails
|
177 |
+
);
|
178 |
+
}
|
179 |
+
|
180 |
+
foreach($collection as $order) {
|
181 |
+
/** @var Mage_Sales_Model_Order $order */
|
182 |
+
$data['orders'][] = array(
|
183 |
+
'cartid' => $order->getId(),
|
184 |
+
'total' => $order->getGrandTotal(),
|
185 |
+
'currency' => $order->getOrderCurrencyCode(),
|
186 |
+
'created_at' => strtotime($order->getCreatedAt() . ' GMT'),
|
187 |
+
'paid' => ($order->getBaseTotalDue() > 0),
|
188 |
+
'profile' => array(
|
189 |
+
'email' => $order->getCustomerEmail(),
|
190 |
+
'firstname' => $order->getCustomerFirstname(),
|
191 |
+
'lastname' => $order->getCustomerLastname(),
|
192 |
+
),
|
193 |
+
'items' => $itemData[$order->getId()],
|
194 |
+
);
|
195 |
+
}
|
196 |
+
|
197 |
+
|
198 |
+
} catch (Exception $e) {
|
199 |
+
$data = array(
|
200 |
+
'status' => 'error',
|
201 |
+
'error' => $e->getMessage(),
|
202 |
+
);
|
203 |
+
|
204 |
+
if (!array_key_exists('HTTP/1.1', $headers)) {
|
205 |
+
$headers['HTTP/1.1'] = '500 Internal Server Error';
|
206 |
+
}
|
207 |
+
}
|
208 |
+
|
209 |
+
$json = $core->jsonEncode($data);
|
210 |
+
$response->setBody($json);
|
211 |
+
|
212 |
+
$response->clearHeaders();
|
213 |
+
$response->setHeader('Content-Type', 'application/json', true);
|
214 |
+
foreach ($headers as $name => $value) {
|
215 |
+
$response->setHeader($name, $value);
|
216 |
+
}
|
217 |
+
}
|
218 |
+
|
219 |
+
}
|
app/code/community/Perpetto/Perpetto/controllers/RecommendationsController.php
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Class Perpetto_Perpetto_RecommendationsController
|
5 |
+
*/
|
6 |
+
class Perpetto_Perpetto_RecommendationsController extends Perpetto_Perpetto_Controller_Action
|
7 |
+
{
|
8 |
+
/**
|
9 |
+
* Slots action
|
10 |
+
*/
|
11 |
+
public function slotsAction()
|
12 |
+
{
|
13 |
+
$response = $this->getResponse();
|
14 |
+
$core = Mage::helper('core');
|
15 |
+
|
16 |
+
$headers = array();
|
17 |
+
|
18 |
+
try {
|
19 |
+
$this->_validateRequest();
|
20 |
+
|
21 |
+
$api = Mage::helper('perpetto/api');
|
22 |
+
$api->updateInfo();
|
23 |
+
$api->updateSlots();
|
24 |
+
$api->updateEmailCampaigns();
|
25 |
+
|
26 |
+
Mage::app()->getCacheInstance()->cleanType('layout');
|
27 |
+
Mage::app()->getCacheInstance()->cleanType('block_html');
|
28 |
+
|
29 |
+
$data = array('status' => 'success');
|
30 |
+
|
31 |
+
} catch (Exception $e) {
|
32 |
+
$data = array(
|
33 |
+
'status' => 'error',
|
34 |
+
'error' => $e->getMessage(),
|
35 |
+
);
|
36 |
+
|
37 |
+
if (!array_key_exists('HTTP/1.1', $headers)) {
|
38 |
+
$headers['HTTP/1.1'] = '500 Internal Server Error';
|
39 |
+
}
|
40 |
+
}
|
41 |
+
|
42 |
+
$json = $core->jsonEncode($data);
|
43 |
+
$response->setBody($json);
|
44 |
+
|
45 |
+
$response->clearHeaders();
|
46 |
+
$response->setHeader('Content-Type', 'application/json', true);
|
47 |
+
foreach ($headers as $name => $value) {
|
48 |
+
$response->setHeader($name, $value);
|
49 |
+
}
|
50 |
+
}
|
51 |
+
|
52 |
+
}
|
app/code/community/Perpetto/Perpetto/etc/adminhtml.xml
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<acl>
|
4 |
+
<resources>
|
5 |
+
<admin>
|
6 |
+
<children>
|
7 |
+
<system>
|
8 |
+
<children>
|
9 |
+
<config>
|
10 |
+
<children>
|
11 |
+
<perpetto translate="title" module="perpetto">
|
12 |
+
<title>Perpetto Account</title>
|
13 |
+
</perpetto>
|
14 |
+
<perpetto_recommendations translate="title" module="perpetto">
|
15 |
+
<title>Perpetto Recommendations</title>
|
16 |
+
</perpetto_recommendations>
|
17 |
+
<perpetto_campaigns translate="title" module="perpetto">
|
18 |
+
<title>Perpetto Email Automation</title>
|
19 |
+
</perpetto_campaigns>
|
20 |
+
</children>
|
21 |
+
</config>
|
22 |
+
</children>
|
23 |
+
</system>
|
24 |
+
</children>
|
25 |
+
</admin>
|
26 |
+
</resources>
|
27 |
+
</acl>
|
28 |
+
</config>
|
app/code/community/Perpetto/Perpetto/etc/config.xml
ADDED
@@ -0,0 +1,182 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<Perpetto_Perpetto>
|
5 |
+
<version>0.3.0</version>
|
6 |
+
</Perpetto_Perpetto>
|
7 |
+
</modules>
|
8 |
+
<admin>
|
9 |
+
<routers>
|
10 |
+
<adminhtml>
|
11 |
+
<args>
|
12 |
+
<modules>
|
13 |
+
<Perpetto_Perpetto after="Mage_Adminhtml">Perpetto_Perpetto_Adminhtml</Perpetto_Perpetto>
|
14 |
+
</modules>
|
15 |
+
</args>
|
16 |
+
</adminhtml>
|
17 |
+
</routers>
|
18 |
+
</admin>
|
19 |
+
<global>
|
20 |
+
<events>
|
21 |
+
<perpetto_slot_delete_commit_after>
|
22 |
+
<observers>
|
23 |
+
<perpetto_delete_slot_widgets>
|
24 |
+
<class>perpetto/observer</class>
|
25 |
+
<method>deleteSlotWidgets</method>
|
26 |
+
</perpetto_delete_slot_widgets>
|
27 |
+
</observers>
|
28 |
+
</perpetto_slot_delete_commit_after>
|
29 |
+
<perpetto_slots_update_after>
|
30 |
+
<observers>
|
31 |
+
<perpetto_update_slots_widgets>
|
32 |
+
<class>perpetto/observer</class>
|
33 |
+
<method>updateSlotsWidgets</method>
|
34 |
+
</perpetto_update_slots_widgets>
|
35 |
+
</observers>
|
36 |
+
</perpetto_slots_update_after>
|
37 |
+
</events>
|
38 |
+
<models>
|
39 |
+
<perpetto>
|
40 |
+
<class>Perpetto_Perpetto_Model</class>
|
41 |
+
<resourceModel>perpetto_resource</resourceModel>
|
42 |
+
</perpetto>
|
43 |
+
<perpetto_resource>
|
44 |
+
<class>Perpetto_Perpetto_Model_Resource</class>
|
45 |
+
<entities>
|
46 |
+
<slots>
|
47 |
+
<table>perpetto_slots</table>
|
48 |
+
</slots>
|
49 |
+
</entities>
|
50 |
+
</perpetto_resource>
|
51 |
+
</models>
|
52 |
+
<resources>
|
53 |
+
<perpetto_setup>
|
54 |
+
<setup>
|
55 |
+
<module>Perpetto_Perpetto</module>
|
56 |
+
</setup>
|
57 |
+
</perpetto_setup>
|
58 |
+
</resources>
|
59 |
+
<blocks>
|
60 |
+
<perpetto>
|
61 |
+
<class>Perpetto_Perpetto_Block</class>
|
62 |
+
</perpetto>
|
63 |
+
</blocks>
|
64 |
+
<helpers>
|
65 |
+
<perpetto>
|
66 |
+
<class>Perpetto_Perpetto_Helper</class>
|
67 |
+
</perpetto>
|
68 |
+
</helpers>
|
69 |
+
</global>
|
70 |
+
<adminhtml>
|
71 |
+
<events>
|
72 |
+
<core_config_data_save_before>
|
73 |
+
<observers>
|
74 |
+
<perpetto_admin_setting_save_old_magento>
|
75 |
+
<type>singleton</type>
|
76 |
+
<class>perpetto/observer</class>
|
77 |
+
<method>saveAdminSettings</method>
|
78 |
+
</perpetto_admin_setting_save_old_magento>
|
79 |
+
</observers>
|
80 |
+
</core_config_data_save_before>
|
81 |
+
<model_config_data_save_before>
|
82 |
+
<observers>
|
83 |
+
<perpetto_admin_setting_save>
|
84 |
+
<type>singleton</type>
|
85 |
+
<class>perpetto/observer</class>
|
86 |
+
<method>saveAdminSettings</method>
|
87 |
+
</perpetto_admin_setting_save>
|
88 |
+
</observers>
|
89 |
+
</model_config_data_save_before>
|
90 |
+
<catalog_product_save_after>
|
91 |
+
<observers>
|
92 |
+
<perpetto_admin_product_save>
|
93 |
+
<class>perpetto/observer</class>
|
94 |
+
<method>saveProduct</method>
|
95 |
+
</perpetto_admin_product_save>
|
96 |
+
</observers>
|
97 |
+
</catalog_product_save_after>
|
98 |
+
<admin_system_config_changed_section_design>
|
99 |
+
<observers>
|
100 |
+
<perpetto_update_slots_widgets>
|
101 |
+
<class>perpetto/observer</class>
|
102 |
+
<method>updateSlotsWidgets</method>
|
103 |
+
</perpetto_update_slots_widgets>
|
104 |
+
</observers>
|
105 |
+
</admin_system_config_changed_section_design>
|
106 |
+
</events>
|
107 |
+
</adminhtml>
|
108 |
+
<frontend>
|
109 |
+
<events>
|
110 |
+
<sales_order_place_after>
|
111 |
+
<observers>
|
112 |
+
<perpetto_detect_new_customer>
|
113 |
+
<class>perpetto/observer</class>
|
114 |
+
<method>salesOrderPlaceAfter</method>
|
115 |
+
<type>singleton</type>
|
116 |
+
</perpetto_detect_new_customer>
|
117 |
+
</observers>
|
118 |
+
</sales_order_place_after>
|
119 |
+
<customer_register_success>
|
120 |
+
<observers>
|
121 |
+
<perpetto_customer_register_success>
|
122 |
+
<class>perpetto/observer</class>
|
123 |
+
<method>customerRegisterSuccess</method>
|
124 |
+
<type>singleton</type>
|
125 |
+
</perpetto_customer_register_success>
|
126 |
+
<perpetto_register_customer_service_block>
|
127 |
+
<class>perpetto/observer</class>
|
128 |
+
<method>setShowCustomerServiceBlock</method>
|
129 |
+
</perpetto_register_customer_service_block>
|
130 |
+
</observers>
|
131 |
+
</customer_register_success>
|
132 |
+
<customer_login>
|
133 |
+
<observers>
|
134 |
+
<perpetto_loging_customer_service>
|
135 |
+
<class>perpetto/observer</class>
|
136 |
+
<method>setShowCustomerServiceBlock</method>
|
137 |
+
</perpetto_loging_customer_service>
|
138 |
+
</observers>
|
139 |
+
</customer_login>
|
140 |
+
<customer_save_after>
|
141 |
+
<observers>
|
142 |
+
<perpetto_edit_customer_service>
|
143 |
+
<class>perpetto/observer</class>
|
144 |
+
<method>setShowCustomerServiceBlockEdit</method>
|
145 |
+
</perpetto_edit_customer_service>
|
146 |
+
</observers>
|
147 |
+
</customer_save_after>
|
148 |
+
<newsletter_subscriber_save_commit_after>
|
149 |
+
<observers>
|
150 |
+
<perpetto_newsletter_customer_service>
|
151 |
+
<class>perpetto/observer</class>
|
152 |
+
<method>setShowCustomerServiceBlockOnNewsletterSubscription</method>
|
153 |
+
</perpetto_newsletter_customer_service>
|
154 |
+
</observers>
|
155 |
+
</newsletter_subscriber_save_commit_after>
|
156 |
+
<checkout_type_onepage_save_order_after>
|
157 |
+
<observers>
|
158 |
+
<perpetto_order_customer_service>
|
159 |
+
<class>perpetto/observer</class>
|
160 |
+
<method>setShowCustomerServiceBlockAfterOrder</method>
|
161 |
+
</perpetto_order_customer_service>
|
162 |
+
</observers>
|
163 |
+
</checkout_type_onepage_save_order_after>
|
164 |
+
</events>
|
165 |
+
<layout>
|
166 |
+
<updates>
|
167 |
+
<perpetto_perpetto>
|
168 |
+
<file>perpetto/perpetto.xml</file>
|
169 |
+
</perpetto_perpetto>
|
170 |
+
</updates>
|
171 |
+
</layout>
|
172 |
+
<routers>
|
173 |
+
<perpetto>
|
174 |
+
<use>standard</use>
|
175 |
+
<args>
|
176 |
+
<module>Perpetto_Perpetto</module>
|
177 |
+
<frontName>perpetto</frontName>
|
178 |
+
</args>
|
179 |
+
</perpetto>
|
180 |
+
</routers>
|
181 |
+
</frontend>
|
182 |
+
</config>
|
app/code/community/Perpetto/Perpetto/etc/system.xml
ADDED
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<tabs>
|
4 |
+
<perpetto translate="label" module="perpetto">
|
5 |
+
<label>Perpetto</label>
|
6 |
+
<sort_order>250</sort_order>
|
7 |
+
</perpetto>
|
8 |
+
</tabs>
|
9 |
+
<sections>
|
10 |
+
<perpetto translate="label" module="perpetto">
|
11 |
+
<label>Account</label>
|
12 |
+
<tab>perpetto</tab>
|
13 |
+
<frontend_model>perpetto/adminhtml_system_config_form_account</frontend_model>
|
14 |
+
<frontend_type>text</frontend_type>
|
15 |
+
<sort_order>100</sort_order>
|
16 |
+
<show_in_default>1</show_in_default>
|
17 |
+
<show_in_website>1</show_in_website>
|
18 |
+
<show_in_store>1</show_in_store>
|
19 |
+
<groups>
|
20 |
+
<general translate="label comment">
|
21 |
+
<label>Account ID and Secret</label>
|
22 |
+
<frontend_type>text</frontend_type>
|
23 |
+
<comment><![CDATA[Insert the Account ID and Secret of your Perpetto account to get started. You can find them in the Store section after you sign in.]]></comment>
|
24 |
+
<sort_order>5</sort_order>
|
25 |
+
<show_in_default>1</show_in_default>
|
26 |
+
<show_in_website>1</show_in_website>
|
27 |
+
<show_in_store>1</show_in_store>
|
28 |
+
<expanded>1</expanded>
|
29 |
+
<fields>
|
30 |
+
<account_id translate="label comment">
|
31 |
+
<label>Account ID</label>
|
32 |
+
<sort_order>10</sort_order>
|
33 |
+
<frontend_type>text</frontend_type>
|
34 |
+
<show_in_default>1</show_in_default>
|
35 |
+
<show_in_website>0</show_in_website>
|
36 |
+
<show_in_store>0</show_in_store>
|
37 |
+
<validate>required-entry</validate>
|
38 |
+
</account_id>
|
39 |
+
<secret translate="label comment">
|
40 |
+
<label>Secret</label>
|
41 |
+
<sort_order>20</sort_order>
|
42 |
+
<frontend_type>text</frontend_type>
|
43 |
+
<show_in_default>1</show_in_default>
|
44 |
+
<show_in_website>0</show_in_website>
|
45 |
+
<show_in_store>0</show_in_store>
|
46 |
+
<validate>required-entry</validate>
|
47 |
+
</secret>
|
48 |
+
</fields>
|
49 |
+
</general>
|
50 |
+
</groups>
|
51 |
+
</perpetto>
|
52 |
+
<perpetto_recommendations translate="label" module="perpetto">
|
53 |
+
<label>Recommendations</label>
|
54 |
+
<tab>perpetto</tab>
|
55 |
+
<frontend_model>perpetto/adminhtml_system_config_form_recommendations</frontend_model>
|
56 |
+
<frontend_type>text</frontend_type>
|
57 |
+
<sort_order>200</sort_order>
|
58 |
+
<show_in_default>1</show_in_default>
|
59 |
+
<show_in_website>1</show_in_website>
|
60 |
+
<show_in_store>1</show_in_store>
|
61 |
+
</perpetto_recommendations>
|
62 |
+
<perpetto_campaigns translate="label" module="perpetto">
|
63 |
+
<label>Email Automation</label>
|
64 |
+
<tab>perpetto</tab>
|
65 |
+
<frontend_model>perpetto/adminhtml_system_config_form_campaigns</frontend_model>
|
66 |
+
<sort_order>300</sort_order>
|
67 |
+
<show_in_default>1</show_in_default>
|
68 |
+
<show_in_website>1</show_in_website>
|
69 |
+
<show_in_store>1</show_in_store>
|
70 |
+
</perpetto_campaigns>
|
71 |
+
</sections>
|
72 |
+
</config>
|
app/code/community/Perpetto/Perpetto/etc/widget.xml
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<widgets>
|
3 |
+
<perpetto_reccomendations type="perpetto/recommendations" translate="name description" module="perpetto">
|
4 |
+
<name>Perpetto Recommendations</name>
|
5 |
+
<description>Allows to add Perpetto Recommendations block</description>
|
6 |
+
<parameters>
|
7 |
+
<slot_id>
|
8 |
+
<label>Perpetto Slot</label>
|
9 |
+
<visible>1</visible>
|
10 |
+
<required>1</required>
|
11 |
+
<type>select</type>
|
12 |
+
<source_model>perpetto/source_slots</source_model>
|
13 |
+
</slot_id>
|
14 |
+
<attr_class>
|
15 |
+
<label>Extra Classes</label>
|
16 |
+
<visible>1</visible>
|
17 |
+
<required>0</required>
|
18 |
+
<type>text</type>
|
19 |
+
</attr_class>
|
20 |
+
</parameters>
|
21 |
+
</perpetto_reccomendations>
|
22 |
+
</widgets>
|
app/code/community/Perpetto/Perpetto/sql/perpetto_setup/install-0.1.0.php
ADDED
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/* @var $this Mage_Core_Model_Resource_Setup */
|
3 |
+
|
4 |
+
$this->startSetup();
|
5 |
+
|
6 |
+
$connection = $this->getConnection();
|
7 |
+
|
8 |
+
$slotsTableName = $this->getTable('perpetto/slots');
|
9 |
+
|
10 |
+
$slotsTable = $connection->newTable($slotsTableName)
|
11 |
+
->addColumn('slot_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
|
12 |
+
'identity' => true,
|
13 |
+
'unsigned' => true,
|
14 |
+
'nullable' => false,
|
15 |
+
'primary' => true,
|
16 |
+
), 'Entity ID')
|
17 |
+
->addColumn('perpetto_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
|
18 |
+
'unsigned' => true,
|
19 |
+
'nullable' => false,
|
20 |
+
), 'Perpetto Slot ID')
|
21 |
+
->addColumn('name', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
|
22 |
+
'nullable' => false,
|
23 |
+
), 'Slot Name')
|
24 |
+
->addColumn('count', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
|
25 |
+
'unsigned' => true,
|
26 |
+
'nullable' => true,
|
27 |
+
), 'Count')
|
28 |
+
->addColumn('html', Varien_Db_Ddl_Table::TYPE_TEXT, null, array(), 'HTML')
|
29 |
+
->addColumn('token', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
|
30 |
+
'nullable' => false,
|
31 |
+
), 'Token')
|
32 |
+
->addColumn('owner_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
|
33 |
+
'unsigned' => true,
|
34 |
+
'nullable' => true,
|
35 |
+
), 'Owner ID')
|
36 |
+
->addColumn('domain_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
|
37 |
+
'unsigned' => true,
|
38 |
+
'nullable' => true,
|
39 |
+
), 'Store ID')
|
40 |
+
->addColumn('created_at', Varien_Db_Ddl_Table::TYPE_DATETIME, null, array(
|
41 |
+
'nullable' => true,
|
42 |
+
), 'Create Time')
|
43 |
+
->addColumn('updated_at', Varien_Db_Ddl_Table::TYPE_DATETIME, null, array(
|
44 |
+
'nullable' => true,
|
45 |
+
), 'Update Time')
|
46 |
+
->addColumn('page', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
|
47 |
+
'nullable' => false,
|
48 |
+
), 'Page')
|
49 |
+
->addColumn('status', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
|
50 |
+
'nullable' => true,
|
51 |
+
), 'Status')
|
52 |
+
->addColumn('running', Varien_Db_Ddl_Table::TYPE_TINYINT, null, array(
|
53 |
+
'unsigned' => true,
|
54 |
+
'nullable' => true,
|
55 |
+
), 'Running Flag')
|
56 |
+
->addColumn('css', Varien_Db_Ddl_Table::TYPE_TEXT, null, array(
|
57 |
+
'nullable' => true,
|
58 |
+
), 'CSS')
|
59 |
+
->addColumn('compressed_css', Varien_Db_Ddl_Table::TYPE_TEXT, null, array(
|
60 |
+
'nullable' => true,
|
61 |
+
), 'Compressed CSS')
|
62 |
+
->addColumn('title', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
|
63 |
+
'nullable' => false,
|
64 |
+
), 'Title')
|
65 |
+
->addColumn('template_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
|
66 |
+
'unsigned' => true,
|
67 |
+
'nullable' => true,
|
68 |
+
), 'Template ID')
|
69 |
+
->addColumn('compiled_html', Varien_Db_Ddl_Table::TYPE_TEXT, null, array(
|
70 |
+
'nullable' => true,
|
71 |
+
), 'Compiled HTML')
|
72 |
+
->addColumn('engine_name', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
|
73 |
+
'nullable' => true,
|
74 |
+
), 'Recommendations Engine')
|
75 |
+
->addIndex('IDX_PERPETTO_ID',
|
76 |
+
array('perpetto_id'),
|
77 |
+
array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE))
|
78 |
+
->addIndex('IDX_PERPETTO_TEMPLATE_ID',
|
79 |
+
array('template_id'),
|
80 |
+
array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX))
|
81 |
+
->setComment('Perpetto Slots Table');
|
82 |
+
|
83 |
+
if ($connection->isTableExists($slotsTableName)) {
|
84 |
+
$connection->dropTable($slotsTableName);
|
85 |
+
}
|
86 |
+
|
87 |
+
$connection->createTable($slotsTable);
|
88 |
+
|
89 |
+
$this->endSetup();
|
app/design/adminhtml/default/default/template/perpetto/adminhtml/system/config/form/account.phtml
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/** @var $this Perpetto_Perpetto_Block_Adminhtml_System_Config_Form_Account */
|
3 |
+
?>
|
4 |
+
<div class="perpetto">
|
5 |
+
<?php echo $this->getHeaderHtml(); ?>
|
6 |
+
<?php if (!Mage::helper('perpetto')->isActive()): ?>
|
7 |
+
<div class="box-left">
|
8 |
+
<div class="entry-edit entry-edit-box">
|
9 |
+
<div class="entry-edit-head">
|
10 |
+
<h4><?php echo $this->__('Get your Account ID and Secret'); ?></h4>
|
11 |
+
</div>
|
12 |
+
<div class="fieldset">
|
13 |
+
<p><?php echo $this->__('Sign in here and go to the Store section to copy your Account ID and Secret.'); ?></p>
|
14 |
+
<a class="button" href="<?php echo $this->getSignInUrl(); ?>"
|
15 |
+
target="_blank"><?php echo $this->__('Sign In'); ?></a>
|
16 |
+
</div>
|
17 |
+
</div>
|
18 |
+
</div>
|
19 |
+
|
20 |
+
<div class="box-right">
|
21 |
+
<div class="entry-edit entry-edit-box">
|
22 |
+
<div class="entry-edit-head">
|
23 |
+
<h4><?php echo $this->__('Don\'t have a Perpetto account?'); ?></h4>
|
24 |
+
</div>
|
25 |
+
<div class="fieldset">
|
26 |
+
<p><?php echo $this->__('Sign up free here to get started, it only takes a few seconds.'); ?></p>
|
27 |
+
<a class="button" href="<?php echo $this->getSignUpUrl(); ?>"
|
28 |
+
target="_blank"><?php echo $this->__('Sign Up Free Here'); ?></a>
|
29 |
+
</div>
|
30 |
+
</div>
|
31 |
+
</div>
|
32 |
+
|
33 |
+
<div class="clear"></div>
|
34 |
+
|
35 |
+
<?php endif; ?>
|
36 |
+
|
37 |
+
<div class="entry-edit">
|
38 |
+
<?php echo $this->getFormHtml(); ?>
|
39 |
+
</div>
|
40 |
+
<?php echo $this->getChildHtml('form_after'); ?>
|
41 |
+
</div>
|
app/design/adminhtml/default/default/template/perpetto/adminhtml/system/config/form/campaigns.phtml
ADDED
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/** @var $this Perpetto_Perpetto_Block_Adminhtml_System_Config_Form_Campaigns */
|
3 |
+
?>
|
4 |
+
<div class="perpetto">
|
5 |
+
<?php echo $this->getHeaderHtml(); ?>
|
6 |
+
<?php if ($this->showLinks()): ?>
|
7 |
+
<table cellpadding="0" cellspacing="0" width="100%">
|
8 |
+
<tr>
|
9 |
+
<td style="padding-right: 10px;">
|
10 |
+
<div class="entry-edit entry-edit-box">
|
11 |
+
<div class="entry-edit-head">
|
12 |
+
<h4><?php echo $this->__('Emails Dashboard'); ?></h4>
|
13 |
+
</div>
|
14 |
+
<div class="fieldset">
|
15 |
+
<p><?php echo $this->__('View your Emails Dashboard to see the results from Email Campaigns.'); ?></p>
|
16 |
+
<a class="button" href="<?php echo $this->getDashboardUrl() ?>"
|
17 |
+
target="_blank"><?php echo $this->__('Emails Dashboard'); ?></a>
|
18 |
+
</div>
|
19 |
+
</div>
|
20 |
+
</td>
|
21 |
+
<td style="padding-right: 10px; padding-left: 10px;">
|
22 |
+
<div class="entry-edit entry-edit-box">
|
23 |
+
<div class="entry-edit-head">
|
24 |
+
<h4><?php echo $this->__('Ask-Us-Anything Support'); ?></h4>
|
25 |
+
</div>
|
26 |
+
<div class="fieldset">
|
27 |
+
<p><?php echo $this->__('Ask us anything you might need to know. We are here to help.'); ?></p>
|
28 |
+
<a class="button" href="<?php echo $this->getContactsUrl() ?>"
|
29 |
+
target="_blank"><?php echo $this->__('Get In Touch'); ?></a>
|
30 |
+
</div>
|
31 |
+
</div>
|
32 |
+
</td>
|
33 |
+
<td style="padding-left: 10px;">
|
34 |
+
<div class="entry-edit entry-edit-box">
|
35 |
+
<div class="entry-edit-head">
|
36 |
+
<h4><?php echo $this->getBillingTitle() ?></h4>
|
37 |
+
</div>
|
38 |
+
<div class="fieldset">
|
39 |
+
<p><?php echo $this->getBillingText() ?></p>
|
40 |
+
<a class="button" href="<?php echo $this->getBillingUrl() ?>"
|
41 |
+
target="_blank"><?php echo $this->getBillingButtonText() ?></a>
|
42 |
+
</div>
|
43 |
+
</div>
|
44 |
+
</td>
|
45 |
+
</tr>
|
46 |
+
</table>
|
47 |
+
|
48 |
+
<div class="clear"></div>
|
49 |
+
<?php endif ?>
|
50 |
+
<?php if ($this->showCampaigns()): ?>
|
51 |
+
<div class="entry-edit">
|
52 |
+
<div class="entry-edit-head">
|
53 |
+
<h4><?php echo $this->__('Email Campaigns'); ?></h4>
|
54 |
+
</div>
|
55 |
+
<div class="fieldset">
|
56 |
+
<p class="box-left"><?php echo $this->__('Here you can see what email campaigns are configured in your
|
57 |
+
account. You can send a test email to your Perpetto account email, or edit the campaigns in the
|
58 |
+
Perpetto administration area using the "Edit Email Campaigns" button.'); ?></p>
|
59 |
+
|
60 |
+
<div class="box-right align-right">
|
61 |
+
<a class="button" href="<?php echo $this->getEmailCampaignsUrl(); ?>"
|
62 |
+
target="_blank"><?php echo $this->__('Edit Email Campaigns'); ?></a>
|
63 |
+
</div>
|
64 |
+
|
65 |
+
<div class="clear"></div>
|
66 |
+
|
67 |
+
<?php foreach ($this->getEmailCampaigns() as $campaign): ?>
|
68 |
+
<?php
|
69 |
+
$emails = (array)$campaign['emails'];
|
70 |
+
$emailsCount = count($emails);
|
71 |
+
?>
|
72 |
+
<table class="perpetto-slots" cellpadding="0" cellspacing="0" width="100%">
|
73 |
+
<tbody>
|
74 |
+
<tr>
|
75 |
+
<th rowspan="<?php echo $emailsCount + 1 ?>"><?php echo $this->escapeHtml($campaign['name']) ?></th>
|
76 |
+
<th><?php echo $this->__('Email Title'); ?></th>
|
77 |
+
<th><?php echo $this->__('Email Subject'); ?></th>
|
78 |
+
<th colspan="2"><?php echo $this->__('Status'); ?></th>
|
79 |
+
</tr>
|
80 |
+
<?php foreach ($emails as $email): /** @var $slot Perpetto_Perpetto_Model_Slot */ ?>
|
81 |
+
<tr>
|
82 |
+
<td><?php echo $this->escapeHtml($email['title']) ?></td>
|
83 |
+
<td><?php echo $this->escapeHtml($email['subject']) ?></td>
|
84 |
+
<td><?php echo $this->escapeHtml(ucwords($email['status'])); ?></td>
|
85 |
+
<td><a href="<?php echo $this->getEmailCampaignTestUrl($campaign['id'],
|
86 |
+
$email['id']) ?>"><?php echo $this->__('Send Test Email') ?></a></td>
|
87 |
+
</tr>
|
88 |
+
<?php endforeach; ?>
|
89 |
+
</tbody>
|
90 |
+
</table>
|
91 |
+
|
92 |
+
<?php endforeach; ?>
|
93 |
+
</div>
|
94 |
+
</div>
|
95 |
+
<?php endif ?>
|
96 |
+
<?php echo $this->getChildHtml('form_after'); ?>
|
97 |
+
</div>
|
98 |
+
<script type="text/javascript">
|
99 |
+
$$('#content .content-header button').each(function (item) {
|
100 |
+
item.remove();
|
101 |
+
});
|
102 |
+
</script>
|
app/design/adminhtml/default/default/template/perpetto/adminhtml/system/config/form/header.phtml
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/** @var $this Perpetto_Perpetto_Block_Adminhtml_System_Config_Form_Header */
|
3 |
+
?>
|
4 |
+
|
5 |
+
<div class="clear"></div>
|
6 |
+
<div class="perpetto-header">
|
7 |
+
<img class="perpetto-logo" alt="<?php echo $this->__('Perpetto') ?>"
|
8 |
+
src="https://ptto-srv-cdn.azureedge.net/assets/ptto-logo.png"/>
|
9 |
+
<?php echo $this->getMessagesHtml() ?>
|
10 |
+
<div class="clear"></div>
|
11 |
+
</div>
|
app/design/adminhtml/default/default/template/perpetto/adminhtml/system/config/form/recommendations.phtml
ADDED
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/** @var $this Perpetto_Perpetto_Block_Adminhtml_System_Config_Form_Recommendations */
|
3 |
+
?>
|
4 |
+
<div class="perpetto">
|
5 |
+
<?php echo $this->getHeaderHtml(); ?>
|
6 |
+
<?php if ($this->showLinks()): ?>
|
7 |
+
<table cellpadding="0" cellspacing="0" width="100%">
|
8 |
+
<tr>
|
9 |
+
<td style="padding-right: 10px;">
|
10 |
+
<div class="entry-edit entry-edit-box">
|
11 |
+
<div class="entry-edit-head">
|
12 |
+
<h4><?php echo $this->__('Recommendations Dashboard'); ?></h4>
|
13 |
+
</div>
|
14 |
+
<div class="fieldset">
|
15 |
+
<p><?php echo $this->__('View your Dashboard to see how Perpetto is helping your store.'); ?></p>
|
16 |
+
<a class="button" href="<?php echo $this->getDashboardUrl() ?>"
|
17 |
+
target="_blank"><?php echo $this->__('Recommendations Dashboard'); ?></a>
|
18 |
+
</div>
|
19 |
+
</div>
|
20 |
+
</td>
|
21 |
+
<td style="padding-right: 10px; padding-left: 10px;">
|
22 |
+
<div class="entry-edit entry-edit-box">
|
23 |
+
<div class="entry-edit-head">
|
24 |
+
<h4><?php echo $this->__('Ask-Us-Anything Support'); ?></h4>
|
25 |
+
</div>
|
26 |
+
<div class="fieldset">
|
27 |
+
<p><?php echo $this->__('Ask us anything you might need to know. We are here to help.'); ?></p>
|
28 |
+
<a class="button" href="<?php echo $this->getContactsUrl() ?>"
|
29 |
+
target="_blank"><?php echo $this->__('Get In Touch'); ?></a>
|
30 |
+
</div>
|
31 |
+
</div>
|
32 |
+
</td>
|
33 |
+
<td style="padding-left: 10px;">
|
34 |
+
<div class="entry-edit entry-edit-box">
|
35 |
+
<div class="entry-edit-head">
|
36 |
+
<h4><?php echo $this->getBillingTitle() ?></h4>
|
37 |
+
</div>
|
38 |
+
<div class="fieldset">
|
39 |
+
<p><?php echo $this->getBillingText() ?></p>
|
40 |
+
<a class="button" href="<?php echo $this->getBillingUrl() ?>"
|
41 |
+
target="_blank"><?php echo $this->getBillingButtonText() ?></a>
|
42 |
+
</div>
|
43 |
+
</div>
|
44 |
+
</td>
|
45 |
+
</tr>
|
46 |
+
</table>
|
47 |
+
|
48 |
+
<div class="clear"></div>
|
49 |
+
<?php endif ?>
|
50 |
+
<?php if ($this->showSlots()): ?>
|
51 |
+
<div class="entry-edit">
|
52 |
+
<div class="entry-edit-head">
|
53 |
+
<h4><?php echo $this->__('Recommendation Slots'); ?></h4>
|
54 |
+
</div>
|
55 |
+
<div class="fieldset">
|
56 |
+
<p class="box-left"><?php echo $this->__('Here you can see what recommendations are installed. You can see how they will look with the' .
|
57 |
+
'"Preview" button and change their algorithm, number of displayed items or styling in the Perpetto ' .
|
58 |
+
'administration area using the "Edit Recommendations" button'); ?></p>
|
59 |
+
|
60 |
+
<div class="box-right align-right">
|
61 |
+
<?php $url = $this->getRandomProductPreviewUrl(); ?>
|
62 |
+
<?php if ($url != ''): ?>
|
63 |
+
<a class="button" href="<?php echo $url; ?>"
|
64 |
+
target="_blank"><?php echo $this->__('Preview'); ?></a>
|
65 |
+
<?php endif; ?>
|
66 |
+
<a class="button" href="<?php echo $this->getRecommendationsUrl(); ?>"
|
67 |
+
target="_blank"><?php echo $this->__('Edit Recommendations'); ?></a>
|
68 |
+
</div>
|
69 |
+
|
70 |
+
<div class="clear"></div>
|
71 |
+
|
72 |
+
<?php $pages = $this->getGroupedSlots(); ?>
|
73 |
+
<?php foreach ($pages as $page => $slots): ?>
|
74 |
+
<?php
|
75 |
+
$pageLabel = ucwords(str_replace('_', ' ', $page));
|
76 |
+
$slotsCount = count($slots);
|
77 |
+
?>
|
78 |
+
<table class="perpetto-slots" cellpadding="0" cellspacing="0" width="100%">
|
79 |
+
<tbody>
|
80 |
+
<tr>
|
81 |
+
<th rowspan="<?php echo $slotsCount + 1 ?>"><?php echo $pageLabel ?></th>
|
82 |
+
<th><?php echo $this->__('Slot Title'); ?></th>
|
83 |
+
<th><?php echo $this->__('Recommendation Algorithm'); ?></th>
|
84 |
+
<th><?php echo $this->__('Slot Container'); ?></th>
|
85 |
+
</tr>
|
86 |
+
<?php foreach ($slots as $slot): /** @var $slot Perpetto_Perpetto_Model_Slot */ ?>
|
87 |
+
<?php
|
88 |
+
$format = '<div class="ptto-rec-slot-token" data-ptto-token="%s"></div>';
|
89 |
+
$containerHtml = sprintf($format, $slot->getToken());
|
90 |
+
$algorithmName = ucwords(str_replace('_', ' ', $slot->getEngineName()));
|
91 |
+
?>
|
92 |
+
<tr>
|
93 |
+
<td><?php echo $this->escapeHtml($slot->getTitle()) ?></td>
|
94 |
+
<td><?php echo $this->escapeHtml($algorithmName) ?></td>
|
95 |
+
<td><?php echo $this->escapeHtml($containerHtml); ?></td>
|
96 |
+
</tr>
|
97 |
+
<?php endforeach; ?>
|
98 |
+
</tbody>
|
99 |
+
</table>
|
100 |
+
|
101 |
+
<?php endforeach; ?>
|
102 |
+
</div>
|
103 |
+
</div>
|
104 |
+
<?php endif ?>
|
105 |
+
<?php echo $this->getChildHtml('form_after'); ?>
|
106 |
+
</div>
|
107 |
+
<script type="text/javascript">
|
108 |
+
$$('#content .content-header button').each(function (item) {
|
109 |
+
item.remove();
|
110 |
+
});
|
111 |
+
</script>
|
app/design/frontend/base/default/layout/perpetto/perpetto.xml
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<layout version="0.1.0">
|
3 |
+
<default>
|
4 |
+
<reference name="head">
|
5 |
+
<block type="core/template" name="perpetto.javascript.sdk" template="perpetto/javascript-sdk.phtml"/>
|
6 |
+
</reference>
|
7 |
+
<reference name="after_body_start">
|
8 |
+
<block type="perpetto/service_user" name="perpetto.service.user"/>
|
9 |
+
</reference>
|
10 |
+
</default>
|
11 |
+
|
12 |
+
<catalog_category_view>
|
13 |
+
<reference name="after_body_start">
|
14 |
+
<block type="perpetto/service_category" name="perpetto.service.category"/>
|
15 |
+
</reference>
|
16 |
+
</catalog_category_view>
|
17 |
+
|
18 |
+
<catalog_product_view>
|
19 |
+
<reference name="after_body_start">
|
20 |
+
<block type="perpetto/service_product" name="perpetto.service.product"/>
|
21 |
+
</reference>
|
22 |
+
</catalog_product_view>
|
23 |
+
|
24 |
+
<checkout_cart_index>
|
25 |
+
<reference name="after_body_start">
|
26 |
+
<block type="perpetto/service_cart" name="perpetto.service.cart"/>
|
27 |
+
</reference>
|
28 |
+
</checkout_cart_index>
|
29 |
+
|
30 |
+
<checkout_onepage_success>
|
31 |
+
<reference name="after_body_start">
|
32 |
+
<block type="perpetto/service_success" name="perpetto.service.success"/>
|
33 |
+
</reference>
|
34 |
+
</checkout_onepage_success>
|
35 |
+
|
36 |
+
</layout>
|
app/design/frontend/base/default/template/perpetto/javascript-sdk.phtml
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/** @var $this Mage_Core_Model_Template */
|
3 |
+
|
4 |
+
$helper = Mage::helper('perpetto');
|
5 |
+
$accountId = $helper->getAccountId();
|
6 |
+
?>
|
7 |
+
<script type="text/javascript">
|
8 |
+
window.PERPETTO_ACCOUNT = '<?php echo $accountId ?>';
|
9 |
+
window.onPerpettoLoaded = function () {
|
10 |
+
Perpetto.update();
|
11 |
+
};
|
12 |
+
</script>
|
13 |
+
<script type="text/javascript" src="<?php echo Mage::helper('perpetto')->getEmbedJsUrl(); ?>"></script>
|
app/design/frontend/base/default/template/perpetto/recommendations.phtml
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/** @var $this Perpetto_Perpetto_Block_Recommendations */
|
3 |
+
|
4 |
+
$slot = $this->getSlot();
|
5 |
+
$token = $slot->getToken();
|
6 |
+
$class = $this->getClass();
|
7 |
+
?>
|
8 |
+
<div class="<?php echo $class ?>" data-ptto-token="<?php echo $token ?>"></div>
|
app/design/frontend/base/default/template/perpetto/service/category-page.phtml
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/** @var $this Perpetto_Perpetto_Block_Service_Category */
|
3 |
+
?>
|
4 |
+
<div class="ptto-category" style="display: none;"><?php echo $this->getCurrentCategoryPath(); ?></div>
|
app/design/frontend/base/default/template/perpetto/service/checkout-cart.phtml
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/** @var $this Perpetto_Perpetto_Block_Service_Cart */
|
3 |
+
|
4 |
+
$quote = $this->getQuote();
|
5 |
+
$taxHelper = Mage::helper('tax');
|
6 |
+
$checkoutHelper = Mage::helper('checkout');
|
7 |
+
?>
|
8 |
+
<div class="ptto-cart" style="display: none;">
|
9 |
+
<div class="ptto-cart-id"><?php echo $quote->getId(); ?></div>
|
10 |
+
<div class="ptto-total"><?php echo $quote->getGrandTotal(); ?></div>
|
11 |
+
<div class="ptto-currency"><?php echo Mage::app()->getStore()->getCurrentCurrencyCode(); ?></div>
|
12 |
+
<?php foreach ($quote->getAllVisibleItems() as $item): /** @var $item Mage_Sales_Model_Quote_Item */ ?>
|
13 |
+
<?php
|
14 |
+
$rowTotal = $taxHelper->displayCartPriceExclTax()
|
15 |
+
? $item->getRowTotal()
|
16 |
+
: $checkoutHelper->getSubtotalInclTax($_item);
|
17 |
+
?>
|
18 |
+
<div class="ptto-item">
|
19 |
+
<div class="ptto-id"><?php echo $item->getProduct()->getId(); ?></div>
|
20 |
+
<div class="ptto-quantity"><?php echo $item->getQty(); ?></div>
|
21 |
+
<div class="ptto-price"><?php echo $item->getPrice(); ?></div>
|
22 |
+
<div class="ptto-itemTotal"><?php echo $rowTotal; ?></div>
|
23 |
+
</div>
|
24 |
+
<?php endforeach; ?>
|
25 |
+
</div>
|
app/design/frontend/base/default/template/perpetto/service/product-page.phtml
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/** @var $this Perpetto_Perpetto_Block_Service_Product */
|
3 |
+
|
4 |
+
$product = $this->getProduct();
|
5 |
+
|
6 |
+
$price = $this->getProductPrice();
|
7 |
+
$finalPrice = $product->getFinalPrice();
|
8 |
+
?>
|
9 |
+
<?php if ($product instanceof Mage_Catalog_Model_Product): ?>
|
10 |
+
<div class="ptto-item-details" style="display: none;">
|
11 |
+
<div class="ptto-id"><?php echo $product->getId(); ?></div>
|
12 |
+
<div class="ptto-name"><?php echo $product->getName(); ?></div>
|
13 |
+
<img class="ptto-image" src="<?php echo $this->getProductImageUrl(); ?>"/>
|
14 |
+
<div class="ptto-url"><?php echo $product->getUrlInStore(); ?></div>
|
15 |
+
<div class="ptto-listprice"><?php echo $price ?></div>
|
16 |
+
<div class="ptto-currency"><?php echo Mage::app()->getStore()->getCurrentCurrencyCode(); ?></div>
|
17 |
+
<div class="ptto-availability"><?php echo (int)$product->getIsSalable(); ?></div>
|
18 |
+
|
19 |
+
<div class="ptto-categories"><?php echo $this->getProductCategoriesPaths(); ?></div>
|
20 |
+
<div class="ptto-category"><?php echo $this->getCurrentCategoryPath(); ?></div>
|
21 |
+
|
22 |
+
<?php if ($price != $finalPrice): ?>
|
23 |
+
<div class="ptto-price"><?php echo $finalPrice ?></div>
|
24 |
+
<?php endif ?>
|
25 |
+
|
26 |
+
<div class="ptto-brand"><?php echo $product->getBrand(); ?></div>
|
27 |
+
<div class="ptto-tags"></div>
|
28 |
+
<div class="ptto-summary"><?php echo $product->getDescription(); ?></div>
|
29 |
+
</div>
|
30 |
+
<?php endif; ?>
|
app/design/frontend/base/default/template/perpetto/service/success-page.phtml
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/** @var $this Perpetto_Perpetto_Block_Service_Success */
|
3 |
+
?>
|
4 |
+
<div class="ptto-cart-paid" style="display: none;">
|
5 |
+
<div class="ptto-cart-id"><?php echo $this->getLastSuccessQuoteId(); ?></div>
|
6 |
+
</div>
|
app/design/frontend/base/default/template/perpetto/service/user.phtml
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/** @var $this Perpetto_Perpetto_Block_Service_User */
|
3 |
+
?>
|
4 |
+
<div class="ptto-user-details" style="display: none;">
|
5 |
+
<div class="ptto-email"><?php echo $this->getEmail(); ?></div>
|
6 |
+
<div class="ptto-firstname"><?php echo $this->getFirstname(); ?></div>
|
7 |
+
<div class="ptto-lastname"><?php echo $this->getLastname(); ?></div>
|
8 |
+
<?php if ($this->isNewCustomer()): ?>
|
9 |
+
<div class="ptto-new-user">true</div>
|
10 |
+
<?php endif ?>
|
11 |
+
</div>
|
app/etc/modules/Perpetto_Perpetto.xml
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<Perpetto_Perpetto>
|
5 |
+
<active>true</active>
|
6 |
+
<codePool>community</codePool>
|
7 |
+
</Perpetto_Perpetto>
|
8 |
+
</modules>
|
9 |
+
</config>
|
lib/Perpetto/Client.php
ADDED
@@ -0,0 +1,212 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
require_once __DIR__ . '/Response.php';
|
4 |
+
|
5 |
+
/**
|
6 |
+
* Class Perpetto_Client
|
7 |
+
*/
|
8 |
+
class Perpetto_Client
|
9 |
+
{
|
10 |
+
const API_HOST = 'https://%s.api.perpetto.com';
|
11 |
+
const API_PATH_INFO = '/v0/info';
|
12 |
+
const API_PATH_EMAIL_CAMPAIGNS = '/v1/info/campaigns';
|
13 |
+
const API_PATH_EMAIL_CAMPAIGNS_TEST_EMAIL = '/v1/info/campaigns/%d/emails/%d/test_email';
|
14 |
+
const API_PATH_SLOTS = '/v0/info/slots';
|
15 |
+
const API_PATH_UPDATE_PRODUCT = '/v0/update/product';
|
16 |
+
|
17 |
+
/**
|
18 |
+
* Whether to use CURL over file_get_contents
|
19 |
+
*
|
20 |
+
* @var bool
|
21 |
+
*/
|
22 |
+
protected $useCurl = false;
|
23 |
+
|
24 |
+
/**
|
25 |
+
* Client account ID used in requests
|
26 |
+
*
|
27 |
+
* @var string
|
28 |
+
*/
|
29 |
+
protected $accountId = null;
|
30 |
+
|
31 |
+
/**
|
32 |
+
* Client secret used in requests
|
33 |
+
*
|
34 |
+
* @var string
|
35 |
+
*/
|
36 |
+
protected $clientSecret = null;
|
37 |
+
|
38 |
+
/**
|
39 |
+
* Perpetto_Client constructor.
|
40 |
+
*
|
41 |
+
* @param $accountId
|
42 |
+
* @param $clientSecret
|
43 |
+
*/
|
44 |
+
public function __construct($accountId, $clientSecret)
|
45 |
+
{
|
46 |
+
$this->accountId = $accountId;
|
47 |
+
$this->clientSecret = $clientSecret;
|
48 |
+
$this->useCurl = extension_loaded('curl');
|
49 |
+
}
|
50 |
+
|
51 |
+
/**
|
52 |
+
* @param $campaignId
|
53 |
+
* @param $emailId
|
54 |
+
* @return Perpetto_Response
|
55 |
+
*/
|
56 |
+
public function sendEmailCampaignTestEmail($campaignId, $emailId)
|
57 |
+
{
|
58 |
+
$urlFormat = $this->getBaseUrl() . self::API_PATH_EMAIL_CAMPAIGNS_TEST_EMAIL;
|
59 |
+
$url = sprintf($urlFormat, $campaignId, $emailId);
|
60 |
+
$response = $this->request($url);
|
61 |
+
|
62 |
+
return $response;
|
63 |
+
}
|
64 |
+
|
65 |
+
/**
|
66 |
+
* @return Perpetto_Response
|
67 |
+
*/
|
68 |
+
public function loadEmailCampaigns()
|
69 |
+
{
|
70 |
+
$url = $this->getBaseUrl() . self::API_PATH_EMAIL_CAMPAIGNS;
|
71 |
+
$response = $this->request($url);
|
72 |
+
|
73 |
+
return $response;
|
74 |
+
}
|
75 |
+
|
76 |
+
/**
|
77 |
+
* @return Perpetto_Response
|
78 |
+
*/
|
79 |
+
public function loadInfo()
|
80 |
+
{
|
81 |
+
$url = $this->getBaseUrl() . self::API_PATH_INFO;
|
82 |
+
$response = $this->request($url);
|
83 |
+
|
84 |
+
return $response;
|
85 |
+
}
|
86 |
+
|
87 |
+
/**
|
88 |
+
* @return Perpetto_Response
|
89 |
+
*/
|
90 |
+
public function loadSlots()
|
91 |
+
{
|
92 |
+
$url = $this->getBaseUrl() . self::API_PATH_SLOTS;
|
93 |
+
$response = $this->request($url);
|
94 |
+
|
95 |
+
return $response;
|
96 |
+
}
|
97 |
+
|
98 |
+
/**
|
99 |
+
* @param Perpetto_Product $product
|
100 |
+
* @return Perpetto_Response
|
101 |
+
*/
|
102 |
+
public function updateProduct(Perpetto_Product $product)
|
103 |
+
{
|
104 |
+
$url = $this->getBaseUrl() . self::API_PATH_UPDATE_PRODUCT;
|
105 |
+
|
106 |
+
$post = array(
|
107 |
+
'item' => $product->toArray(),
|
108 |
+
);
|
109 |
+
|
110 |
+
$response = $this->request($url, array(), $post);
|
111 |
+
|
112 |
+
return $response;
|
113 |
+
}
|
114 |
+
|
115 |
+
/**
|
116 |
+
* @return string
|
117 |
+
*/
|
118 |
+
protected function getBaseUrl()
|
119 |
+
{
|
120 |
+
$url = sprintf(self::API_HOST, $this->accountId);
|
121 |
+
|
122 |
+
return $url;
|
123 |
+
}
|
124 |
+
|
125 |
+
/**
|
126 |
+
* @param $url
|
127 |
+
* @param array $params
|
128 |
+
* @return Perpetto_Response
|
129 |
+
*/
|
130 |
+
protected function request($url, array $params = array(), array $post = array())
|
131 |
+
{
|
132 |
+
$params = array_merge($params, array(
|
133 |
+
'secret' => $this->clientSecret,
|
134 |
+
));
|
135 |
+
|
136 |
+
$response = $this->useCurl
|
137 |
+
? $this->requestCurl($url, $params, $post)
|
138 |
+
: $this->requestRaw($url, $params, $post);
|
139 |
+
|
140 |
+
return $response;
|
141 |
+
}
|
142 |
+
|
143 |
+
/**
|
144 |
+
* @param $url
|
145 |
+
* @param array $params
|
146 |
+
* @param array $post
|
147 |
+
* @return Perpetto_Response
|
148 |
+
*/
|
149 |
+
protected function requestCurl($url, array $params = array(), array $post = array())
|
150 |
+
{
|
151 |
+
$options = array(
|
152 |
+
CURLOPT_RETURNTRANSFER => true,
|
153 |
+
CURLOPT_HEADER => false,
|
154 |
+
CURLOPT_FOLLOWLOCATION => true,
|
155 |
+
CURLOPT_MAXREDIRS => 10,
|
156 |
+
CURLOPT_AUTOREFERER => true,
|
157 |
+
CURLOPT_CONNECTTIMEOUT => 120,
|
158 |
+
CURLOPT_TIMEOUT => 120,
|
159 |
+
);
|
160 |
+
|
161 |
+
$query = http_build_query($params);
|
162 |
+
$url .= '?' . $query;
|
163 |
+
|
164 |
+
$ch = curl_init($url);
|
165 |
+
curl_setopt_array($ch, $options);
|
166 |
+
if (!empty($post)) {
|
167 |
+
$fields = http_build_query($post);
|
168 |
+
curl_setopt($ch, CURLOPT_POST, true);
|
169 |
+
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
|
170 |
+
}
|
171 |
+
$content = curl_exec($ch);
|
172 |
+
curl_close($ch);
|
173 |
+
|
174 |
+
$response = new Perpetto_Response($content);
|
175 |
+
|
176 |
+
return $response;
|
177 |
+
}
|
178 |
+
|
179 |
+
/**
|
180 |
+
* @param $url
|
181 |
+
* @param array $params
|
182 |
+
* @param array $post
|
183 |
+
* @return Perpetto_Response
|
184 |
+
*/
|
185 |
+
protected function requestRaw($url, array $params = array(), array $post = array())
|
186 |
+
{
|
187 |
+
$query = http_build_query($params);
|
188 |
+
$url .= '?' . $query;
|
189 |
+
|
190 |
+
$flags = null;
|
191 |
+
$context = null;
|
192 |
+
|
193 |
+
if (!empty($post)) {
|
194 |
+
$options = array(
|
195 |
+
'http' => array(
|
196 |
+
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
|
197 |
+
'method' => 'POST',
|
198 |
+
'content' => http_build_query($post)
|
199 |
+
)
|
200 |
+
);
|
201 |
+
$flags = false;
|
202 |
+
$context = stream_context_create($options);
|
203 |
+
}
|
204 |
+
|
205 |
+
$content = file_get_contents($url, $flags, $context);
|
206 |
+
|
207 |
+
$response = new Perpetto_Response($content);
|
208 |
+
|
209 |
+
return $response;
|
210 |
+
}
|
211 |
+
|
212 |
+
}
|
lib/Perpetto/Exception.php
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Class Perpetto_Exception
|
5 |
+
*/
|
6 |
+
class Perpetto_Exception extends Exception
|
7 |
+
{
|
8 |
+
|
9 |
+
}
|
lib/Perpetto/Product.php
ADDED
@@ -0,0 +1,266 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Class Perpetto_Product
|
5 |
+
*/
|
6 |
+
class Perpetto_Product
|
7 |
+
{
|
8 |
+
protected $id;
|
9 |
+
protected $name;
|
10 |
+
protected $image;
|
11 |
+
protected $url;
|
12 |
+
protected $listPrice;
|
13 |
+
protected $currency;
|
14 |
+
protected $availability;
|
15 |
+
protected $categories = array();
|
16 |
+
protected $category;
|
17 |
+
protected $price;
|
18 |
+
protected $brand;
|
19 |
+
protected $tags = array();
|
20 |
+
protected $summary;
|
21 |
+
|
22 |
+
/**
|
23 |
+
* @return int
|
24 |
+
*/
|
25 |
+
public function getId()
|
26 |
+
{
|
27 |
+
return $this->id;
|
28 |
+
}
|
29 |
+
|
30 |
+
/**
|
31 |
+
* @param int $id
|
32 |
+
* @return Perpetto_Product
|
33 |
+
*/
|
34 |
+
public function setId($id)
|
35 |
+
{
|
36 |
+
|
37 |
+
$this->id = (int)$id;
|
38 |
+
return $this;
|
39 |
+
}
|
40 |
+
|
41 |
+
/**
|
42 |
+
* @return mixed
|
43 |
+
*/
|
44 |
+
public function getName()
|
45 |
+
{
|
46 |
+
return $this->name;
|
47 |
+
}
|
48 |
+
|
49 |
+
/**
|
50 |
+
* @param string $name
|
51 |
+
* @return Perpetto_Product
|
52 |
+
*/
|
53 |
+
public function setName($name)
|
54 |
+
{
|
55 |
+
$this->name = $name;
|
56 |
+
return $this;
|
57 |
+
}
|
58 |
+
|
59 |
+
/**
|
60 |
+
* @return mixed
|
61 |
+
*/
|
62 |
+
public function getImage()
|
63 |
+
{
|
64 |
+
return $this->image;
|
65 |
+
}
|
66 |
+
|
67 |
+
/**
|
68 |
+
* @param string $image
|
69 |
+
* @return Perpetto_Product
|
70 |
+
*/
|
71 |
+
public function setImage($image)
|
72 |
+
{
|
73 |
+
$this->image = $image;
|
74 |
+
return $this;
|
75 |
+
}
|
76 |
+
|
77 |
+
/**
|
78 |
+
* @return mixed
|
79 |
+
*/
|
80 |
+
public function getUrl()
|
81 |
+
{
|
82 |
+
return $this->url;
|
83 |
+
}
|
84 |
+
|
85 |
+
/**
|
86 |
+
* @param string $url
|
87 |
+
* @return Perpetto_Product
|
88 |
+
*/
|
89 |
+
public function setUrl($url)
|
90 |
+
{
|
91 |
+
$this->url = $url;
|
92 |
+
return $this;
|
93 |
+
}
|
94 |
+
|
95 |
+
/**
|
96 |
+
* @return mixed
|
97 |
+
*/
|
98 |
+
public function getListPrice()
|
99 |
+
{
|
100 |
+
return $this->listPrice;
|
101 |
+
}
|
102 |
+
|
103 |
+
/**
|
104 |
+
* @param number $listPrice
|
105 |
+
* @return Perpetto_Product
|
106 |
+
*/
|
107 |
+
public function setListPrice($listPrice)
|
108 |
+
{
|
109 |
+
$this->listPrice = $listPrice;
|
110 |
+
return $this;
|
111 |
+
}
|
112 |
+
|
113 |
+
/**
|
114 |
+
* @return mixed
|
115 |
+
*/
|
116 |
+
public function getCurrency()
|
117 |
+
{
|
118 |
+
return $this->currency;
|
119 |
+
}
|
120 |
+
|
121 |
+
/**
|
122 |
+
* @param mixed $currency
|
123 |
+
* @return Perpetto_Product
|
124 |
+
*/
|
125 |
+
public function setCurrency($currency)
|
126 |
+
{
|
127 |
+
$this->currency = $currency;
|
128 |
+
return $this;
|
129 |
+
}
|
130 |
+
|
131 |
+
/**
|
132 |
+
* @return bool
|
133 |
+
*/
|
134 |
+
public function getAvailability()
|
135 |
+
{
|
136 |
+
return $this->availability;
|
137 |
+
}
|
138 |
+
|
139 |
+
/**
|
140 |
+
* @param bool $availability
|
141 |
+
* @return Perpetto_Product
|
142 |
+
*/
|
143 |
+
public function setAvailability($availability)
|
144 |
+
{
|
145 |
+
$this->availability = (int)(bool)$availability;
|
146 |
+
return $this;
|
147 |
+
}
|
148 |
+
|
149 |
+
/**
|
150 |
+
* @return array
|
151 |
+
*/
|
152 |
+
public function getCategories()
|
153 |
+
{
|
154 |
+
return $this->categories;
|
155 |
+
}
|
156 |
+
|
157 |
+
/**
|
158 |
+
* @param array $categories
|
159 |
+
* @return Perpetto_Product
|
160 |
+
*/
|
161 |
+
public function setCategories(array $categories)
|
162 |
+
{
|
163 |
+
$this->categories = $categories;
|
164 |
+
return $this;
|
165 |
+
}
|
166 |
+
|
167 |
+
/**
|
168 |
+
* @return mixed
|
169 |
+
*/
|
170 |
+
public function getCategory()
|
171 |
+
{
|
172 |
+
return $this->category;
|
173 |
+
}
|
174 |
+
|
175 |
+
/**
|
176 |
+
* @param mixed $category
|
177 |
+
* @return Perpetto_Product
|
178 |
+
*/
|
179 |
+
public function setCategory($category)
|
180 |
+
{
|
181 |
+
$this->category = $category;
|
182 |
+
return $this;
|
183 |
+
}
|
184 |
+
|
185 |
+
/**
|
186 |
+
* @return mixed
|
187 |
+
*/
|
188 |
+
public function getPrice()
|
189 |
+
{
|
190 |
+
return $this->price;
|
191 |
+
}
|
192 |
+
|
193 |
+
/**
|
194 |
+
* @param mixed $price
|
195 |
+
* @return Perpetto_Product
|
196 |
+
*/
|
197 |
+
public function setPrice($price)
|
198 |
+
{
|
199 |
+
$this->price = $price;
|
200 |
+
return $this;
|
201 |
+
}
|
202 |
+
|
203 |
+
/**
|
204 |
+
* @return mixed
|
205 |
+
*/
|
206 |
+
public function getBrand()
|
207 |
+
{
|
208 |
+
return $this->brand;
|
209 |
+
}
|
210 |
+
|
211 |
+
/**
|
212 |
+
* @param mixed $brand
|
213 |
+
* @return Perpetto_Product
|
214 |
+
*/
|
215 |
+
public function setBrand($brand)
|
216 |
+
{
|
217 |
+
$this->brand = $brand;
|
218 |
+
return $this;
|
219 |
+
}
|
220 |
+
|
221 |
+
/**
|
222 |
+
* @return array
|
223 |
+
*/
|
224 |
+
public function getTags()
|
225 |
+
{
|
226 |
+
return $this->tags;
|
227 |
+
}
|
228 |
+
|
229 |
+
/**
|
230 |
+
* @param array $tags
|
231 |
+
* @return Perpetto_Product
|
232 |
+
*/
|
233 |
+
public function setTags(array $tags)
|
234 |
+
{
|
235 |
+
$this->tags = $tags;
|
236 |
+
return $this;
|
237 |
+
}
|
238 |
+
|
239 |
+
/**
|
240 |
+
* @return mixed
|
241 |
+
*/
|
242 |
+
public function getSummary()
|
243 |
+
{
|
244 |
+
return $this->summary;
|
245 |
+
}
|
246 |
+
|
247 |
+
/**
|
248 |
+
* @param mixed $summary
|
249 |
+
* @return Perpetto_Product
|
250 |
+
*/
|
251 |
+
public function setSummary($summary)
|
252 |
+
{
|
253 |
+
$this->summary = $summary;
|
254 |
+
return $this;
|
255 |
+
}
|
256 |
+
|
257 |
+
/**
|
258 |
+
* @return array
|
259 |
+
*/
|
260 |
+
public function toArray()
|
261 |
+
{
|
262 |
+
$data = get_object_vars($this);
|
263 |
+
|
264 |
+
return $data;
|
265 |
+
}
|
266 |
+
}
|
lib/Perpetto/Response.php
ADDED
@@ -0,0 +1,148 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
require_once __DIR__ . '/Exception.php';
|
4 |
+
|
5 |
+
/**
|
6 |
+
* Class Perpetto_Response
|
7 |
+
*/
|
8 |
+
class Perpetto_Response
|
9 |
+
{
|
10 |
+
/**
|
11 |
+
* @var array
|
12 |
+
*/
|
13 |
+
protected $data = array();
|
14 |
+
|
15 |
+
/**
|
16 |
+
* @var string
|
17 |
+
*/
|
18 |
+
protected $error;
|
19 |
+
|
20 |
+
/**
|
21 |
+
* @var string
|
22 |
+
*/
|
23 |
+
protected $json;
|
24 |
+
|
25 |
+
/**
|
26 |
+
* Perpetto_Response constructor.
|
27 |
+
*
|
28 |
+
* @param string $content
|
29 |
+
* @throws Perpetto_Exception
|
30 |
+
*/
|
31 |
+
public function __construct($content)
|
32 |
+
{
|
33 |
+
if (empty($content)) {
|
34 |
+
throw new Perpetto_Exception('Empty content.');
|
35 |
+
}
|
36 |
+
|
37 |
+
$data = json_decode($content, true);
|
38 |
+
|
39 |
+
if (JSON_ERROR_NONE != json_last_error()) {
|
40 |
+
throw new Perpetto_Exception(json_last_error_msg());
|
41 |
+
}
|
42 |
+
|
43 |
+
$this->json = $content;
|
44 |
+
|
45 |
+
if (array_key_exists('data', $data)) {
|
46 |
+
$this->data = $data['data'];
|
47 |
+
}
|
48 |
+
|
49 |
+
if (array_key_exists('error', $data)) {
|
50 |
+
$this->error = $data['error'];
|
51 |
+
} elseif (empty($this->data)) {
|
52 |
+
$this->error = 'No data in response.';
|
53 |
+
}
|
54 |
+
}
|
55 |
+
|
56 |
+
/**
|
57 |
+
* @return string
|
58 |
+
*/
|
59 |
+
public function getError()
|
60 |
+
{
|
61 |
+
return $this->error;
|
62 |
+
}
|
63 |
+
|
64 |
+
/**
|
65 |
+
* @return bool
|
66 |
+
*/
|
67 |
+
public function hasError()
|
68 |
+
{
|
69 |
+
return !empty($this->error);
|
70 |
+
}
|
71 |
+
|
72 |
+
/**
|
73 |
+
* @param null $key
|
74 |
+
* @return bool
|
75 |
+
*/
|
76 |
+
public function hasData($key = null)
|
77 |
+
{
|
78 |
+
$hasData = $key && array_key_exists($key, $this->data)
|
79 |
+
? !empty($this->data[$key])
|
80 |
+
: !empty($this->data);
|
81 |
+
|
82 |
+
return $hasData;
|
83 |
+
}
|
84 |
+
|
85 |
+
/**
|
86 |
+
* @param null $key
|
87 |
+
* @return mixed
|
88 |
+
*/
|
89 |
+
public function getData($key = null)
|
90 |
+
{
|
91 |
+
$value = null;
|
92 |
+
|
93 |
+
if (!$key) {
|
94 |
+
$value = $this->data;
|
95 |
+
} elseif (array_key_exists($key, $this->data)) {
|
96 |
+
$value = $this->data[$key];
|
97 |
+
} elseif (strpos($key, '/')) {
|
98 |
+
$parts = explode('/', $key);
|
99 |
+
|
100 |
+
$data = &$this->data;
|
101 |
+
while (!empty($parts)) {
|
102 |
+
$part = array_shift($parts);
|
103 |
+
$value = is_array($data) && array_key_exists($part, $data) ? $data[$part] : null;
|
104 |
+
$data = &$value;
|
105 |
+
}
|
106 |
+
}
|
107 |
+
|
108 |
+
return $value;
|
109 |
+
}
|
110 |
+
|
111 |
+
/**
|
112 |
+
* @return string
|
113 |
+
*/
|
114 |
+
public function getJSON()
|
115 |
+
{
|
116 |
+
$json = $this->json;
|
117 |
+
|
118 |
+
return $json;
|
119 |
+
}
|
120 |
+
|
121 |
+
/**
|
122 |
+
* @param $method
|
123 |
+
* @param $args
|
124 |
+
* @return mixed
|
125 |
+
* @throws Exception
|
126 |
+
*/
|
127 |
+
public function __call($method, $args)
|
128 |
+
{
|
129 |
+
switch (substr($method, 0, 3)) {
|
130 |
+
case 'get' :
|
131 |
+
$key = strtolower(substr($method, 3));
|
132 |
+
$data = $this->getData($key);
|
133 |
+
|
134 |
+
return $data;
|
135 |
+
}
|
136 |
+
|
137 |
+
throw new Exception("Invalid method " . __METHOD__);
|
138 |
+
}
|
139 |
+
|
140 |
+
/**
|
141 |
+
* @param $key
|
142 |
+
* @return mixed
|
143 |
+
*/
|
144 |
+
public function __get($key)
|
145 |
+
{
|
146 |
+
return $this->getData($key);
|
147 |
+
}
|
148 |
+
}
|
package.xml
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<package>
|
3 |
+
<name>Perpetto_Perpetto</name>
|
4 |
+
<version>0.3.0</version>
|
5 |
+
<stability>stable</stability>
|
6 |
+
<license uri="https://opensource.org/licenses/GPL-3.0">GPL-3.0</license>
|
7 |
+
<channel>community</channel>
|
8 |
+
<extends/>
|
9 |
+
<summary>Integration with Perpetto service</summary>
|
10 |
+
<description>Integration with Perpetto service</description>
|
11 |
+
<notes>Add email campaigns support; minor fixes.</notes>
|
12 |
+
<authors><author><name>Alexander Kitov</name><user>Perpetto135</user><email>alex@perpetto.com</email></author></authors>
|
13 |
+
<date>2016-07-07</date>
|
14 |
+
<time>13:46:06</time>
|
15 |
+
<contents><target name="magecommunity"><dir name="Perpetto"><dir name="Perpetto"><dir name="Block"><dir name="Adminhtml"><dir name="System"><dir name="Config"><dir name="Form"><file name="Abstract.php" hash="dd49c3c870ac168368fc31c319b4bb36"/><file name="Account.php" hash="bea6bff2c90169211f4bddc4d8c633a7"/><file name="Campaigns.php" hash="fc5d91400f5fdeb5ba38c14ca4f60b23"/><file name="Header.php" hash="765f7400544f4866148337ab79c22d85"/><file name="Recommendations.php" hash="1296acb019e09d1b4ce0da2ef6506dfc"/></dir></dir></dir></dir><file name="Recommendations.php" hash="7018abbfb8f67e00d804d955706c150d"/><dir name="Service"><file name="Cart.php" hash="2a7737c2fc58cf9f525ac478b2984269"/><file name="Category.php" hash="87dfb8c2663afcb89d257c81fd15ac5a"/><file name="Product.php" hash="0c5608d50dc5775946dd7cdac1c50fb3"/><file name="Success.php" hash="fade7f991f2fd66ea548513c878a3c31"/><file name="User.php" hash="3ecc91d4905691d82791c5d1dc82dae7"/></dir></dir><dir name="Controller"><file name="Action.php" hash="1b8c66780b294c4d962102b092bd7207"/></dir><file name="Exception.php" hash="3dcd48e3f0bc3aea2aac8487a8289877"/><dir name="Helper"><file name="Api.php" hash="241e375484d5bc01c3e54f2558d5e4d0"/><file name="Catalog.php" hash="5924f9121d329d27761db49822ef3bcb"/><file name="Data.php" hash="fee0bcd2243a584c14985ce127fbdbe3"/><file name="Url.php" hash="1cf99bf10618a1e7cb4efe24c760e709"/><file name="Widget.php" hash="7c8a2b5881fa7b160358e90f81ba170b"/></dir><dir name="Model"><file name="Observer.php" hash="52b5418fe035f4feb40bf31c76e373bc"/><dir name="Resource"><dir name="Slot"><file name="Collection.php" hash="d7b1318bb3671f0aba9b811f0f6b717f"/></dir><file name="Slot.php" hash="3188ea05e2df4d1ede4cc59ff9382783"/></dir><file name="Slot.php" hash="c2957f48cb5a4d0692429077b7a82be8"/><dir name="Source"><file name="Slots.php" hash="d22b40006df74d1e56d1c7175e11d85d"/></dir></dir><dir name="controllers"><dir name="Adminhtml"><dir name="Perpetto"><file name="CampaignsController.php" hash="d36b4299d6f80e6aef9656c18a7c5d10"/></dir></dir><file name="OrdersController.php" hash="536ff23530876501aa3a1d3343bc5e65"/><file name="RecommendationsController.php" hash="d452a3146d0fb0912e68cebb483a66c8"/></dir><dir name="etc"><file name="adminhtml.xml" hash="3664637a6ff7ce79f1e2e85862e58e54"/><file name="config.xml" hash="5322588bbd00cfdb2a03fc5b6d725d75"/><file name="system.xml" hash="5a47205b884e3eb818e4e27e2a159a35"/><file name="widget.xml" hash="a58b58f6dbde4cb01d3ec6abc4d8e37d"/></dir><dir name="sql"><dir name="perpetto_setup"><file name="install-0.1.0.php" hash="77795322f494b492a6b659c15a81eff0"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><dir name="perpetto"><file name="perpetto.xml" hash="b9473fe700b37a27096d7a8cab331772"/></dir></dir><dir name="template"><dir name="perpetto"><file name="javascript-sdk.phtml" hash="3db6a3b3776b2a077c1291a4eeea9cca"/><file name="recommendations.phtml" hash="e9ce152c3e7ab9af41449b96defe4d01"/><dir name="service"><file name="category-page.phtml" hash="ab968dd4931fc9f3a287070e96adf9e8"/><file name="checkout-cart.phtml" hash="6c2105200877e9ae552960a6f511a833"/><file name="product-page.phtml" hash="330d21e8e5b225194e8162036dbe457d"/><file name="success-page.phtml" hash="e4021ae06985ca232dd7dfaea713ef8e"/><file name="user.phtml" hash="4730743e9afa00642ee812d1b6d40b55"/></dir></dir></dir></dir></dir></dir><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="perpetto"><dir name="adminhtml"><dir name="system"><dir name="config"><dir name="form"><file name="account.phtml" hash="2809a707e0ac7eec6122bef9edad4986"/><file name="campaigns.phtml" hash="8f00d976bd8d370f8252040135909ff3"/><file name="header.phtml" hash="c464bc62a0a7bfa9bab9c52515a12496"/><file name="recommendations.phtml" hash="ddc567f252dca3e369270eafbd02b254"/></dir></dir></dir></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Perpetto_Perpetto.xml" hash="41894aacd62084ffb2b02e0eae5c88f1"/></dir></target><target name="magelib"><dir name="Perpetto"><file name="Client.php" hash="df2a1b76a202744b84123d0ec6e14a4f"/><file name="Exception.php" hash="e982bd6a09364adee95a69c3da31268f"/><file name="Product.php" hash="9b17da412af2861dd7fe8cded6034eec"/><file name="Response.php" hash="b4407a5f08a4bf617909fe7766238eed"/></dir></target><target name="mageskin"><dir name="adminhtml"><dir name="default"><dir name="default"><file name="perpetto.css" hash="72b0803faaaff91b4cc21c25f6208cbb"/></dir></dir></dir></target></contents>
|
16 |
+
<compatible/>
|
17 |
+
<dependencies><required><php><min>5.3.3</min><max>8.0.0</max></php></required></dependencies>
|
18 |
+
</package>
|
skin/adminhtml/default/default/perpetto.css
ADDED
@@ -0,0 +1,210 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.perpetto,
|
2 |
+
.perpetto * {
|
3 |
+
margin: 0;
|
4 |
+
padding: 0;
|
5 |
+
border: 0;
|
6 |
+
font-size: 100%;
|
7 |
+
vertical-align: baseline;
|
8 |
+
}
|
9 |
+
|
10 |
+
.perpetto {
|
11 |
+
color: #7a7a7a;
|
12 |
+
font-family: Arial, Helvetica, sans-serif;
|
13 |
+
font-size: 12px;
|
14 |
+
}
|
15 |
+
|
16 |
+
.perpetto .align-center {
|
17 |
+
text-align: center;
|
18 |
+
}
|
19 |
+
|
20 |
+
.perpetto .align-left {
|
21 |
+
text-align: left;
|
22 |
+
}
|
23 |
+
|
24 |
+
.perpetto .align-right {
|
25 |
+
text-align: right;
|
26 |
+
}
|
27 |
+
|
28 |
+
.perpetto p {
|
29 |
+
margin-bottom: 20px;
|
30 |
+
}
|
31 |
+
|
32 |
+
.perpetto a {
|
33 |
+
color: #008db1;
|
34 |
+
}
|
35 |
+
|
36 |
+
.perpetto a.button {
|
37 |
+
background: #fff;
|
38 |
+
border: 1px solid #008db1;
|
39 |
+
border-radius: 20px;
|
40 |
+
color: #008db1;
|
41 |
+
display: inline-block;
|
42 |
+
font-size: 14px;
|
43 |
+
margin: 5px 10px;
|
44 |
+
padding: 7px 20px;
|
45 |
+
text-align: center;
|
46 |
+
text-decoration: none;
|
47 |
+
transition: all 0.5s ease 0s;
|
48 |
+
width: 210px;
|
49 |
+
}
|
50 |
+
|
51 |
+
.perpetto a.button:hover {
|
52 |
+
background: #008db1;
|
53 |
+
color: #fff;
|
54 |
+
}
|
55 |
+
|
56 |
+
.perpetto .perpetto-header .perpetto-logo {
|
57 |
+
display: block;
|
58 |
+
float: left;
|
59 |
+
margin: 5px 30px 20px 1px;
|
60 |
+
width: 140px;
|
61 |
+
}
|
62 |
+
|
63 |
+
.perpetto .perpetto-header .messages {
|
64 |
+
margin-left: 160px;
|
65 |
+
}
|
66 |
+
|
67 |
+
.perpetto .perpetto-header .messages > li {
|
68 |
+
background-position-y: 16px !important;
|
69 |
+
border: none;
|
70 |
+
padding-top: 16px !important;
|
71 |
+
padding-bottom: 10px!important;
|
72 |
+
}
|
73 |
+
|
74 |
+
.perpetto .perpetto-header .messages li {
|
75 |
+
font-size: 14px !important;
|
76 |
+
font-weight: normal !important;
|
77 |
+
}
|
78 |
+
|
79 |
+
.perpetto .perpetto-header .messages .error-msg,
|
80 |
+
.perpetto .perpetto-header .messages .warning-msg,
|
81 |
+
.perpetto .perpetto-header .messages .success-msg {
|
82 |
+
border: none !important;
|
83 |
+
font-size: 14px !important;
|
84 |
+
font-weight: normal !important;
|
85 |
+
}
|
86 |
+
|
87 |
+
|
88 |
+
.perpetto .perpetto-header .messages .error-msg {
|
89 |
+
background-color: #F2DEDE !important;
|
90 |
+
}
|
91 |
+
|
92 |
+
.perpetto .perpetto-header .messages .error-msg li {
|
93 |
+
color: #000;
|
94 |
+
}
|
95 |
+
|
96 |
+
|
97 |
+
.perpetto .perpetto-header .messages .success-msg {
|
98 |
+
background-color: #CBE8BA !important;
|
99 |
+
}
|
100 |
+
|
101 |
+
.perpetto .perpetto-header .messages .warning-msg {
|
102 |
+
background-color: #FFD783 !important;
|
103 |
+
}
|
104 |
+
|
105 |
+
.perpetto .entry-edit {
|
106 |
+
background: none;
|
107 |
+
border-top: 1px solid #EBEBEB;
|
108 |
+
margin: 0 0 30px 0;
|
109 |
+
padding: 0;
|
110 |
+
position: relative;
|
111 |
+
}
|
112 |
+
|
113 |
+
.perpetto .entry-edit.entry-edit-box {
|
114 |
+
background: #EBEBEB;
|
115 |
+
border: none;
|
116 |
+
padding: 10px 10px 30px;
|
117 |
+
text-align: center;
|
118 |
+
}
|
119 |
+
|
120 |
+
.perpetto .entry-edit-head {
|
121 |
+
background: none;
|
122 |
+
margin: 0;
|
123 |
+
padding: 0;
|
124 |
+
}
|
125 |
+
|
126 |
+
.perpetto .entry-edit .entry-edit-head > a,
|
127 |
+
.perpetto .entry-edit .entry-edit-head > h4 {
|
128 |
+
background: none;
|
129 |
+
color: #000;
|
130 |
+
float: none;
|
131 |
+
font-size: 20px;
|
132 |
+
font-weight: normal;
|
133 |
+
margin: 20px 0 10px;
|
134 |
+
}
|
135 |
+
|
136 |
+
.perpetto .entry-edit .entry-edit-head > a:after {
|
137 |
+
content: ' ▼';
|
138 |
+
font-size: 16px;
|
139 |
+
}
|
140 |
+
|
141 |
+
.perpetto .entry-edit .entry-edit-head > a.open:after {
|
142 |
+
content: ' ▲';
|
143 |
+
}
|
144 |
+
|
145 |
+
.perpetto .entry-edit fieldset,
|
146 |
+
.perpetto .entry-edit .fieldset {
|
147 |
+
border: none;
|
148 |
+
background: none;
|
149 |
+
margin: 0;
|
150 |
+
padding: 0;
|
151 |
+
}
|
152 |
+
|
153 |
+
.perpetto .entry-edit .comment {
|
154 |
+
padding: 0;
|
155 |
+
}
|
156 |
+
|
157 |
+
.perpetto .entry-edit fieldset > .form-list {
|
158 |
+
margin-top: 20px;
|
159 |
+
}
|
160 |
+
|
161 |
+
.perpetto .entry-edit fieldset > .form-list td.label {
|
162 |
+
font-size: 14px;
|
163 |
+
padding-left: 0 !important;
|
164 |
+
}
|
165 |
+
|
166 |
+
.perpetto .entry-edit fieldset > .form-list td.value {
|
167 |
+
font-size: 14px;
|
168 |
+
padding-bottom: 15px !important;
|
169 |
+
}
|
170 |
+
|
171 |
+
.perpetto .entry-edit fieldset > .form-list td.scope-label {
|
172 |
+
font-size: 14px;
|
173 |
+
padding-top: 12px !important;
|
174 |
+
}
|
175 |
+
|
176 |
+
.perpetto .entry-edit fieldset > .form-list input.input-text {
|
177 |
+
border: 1px solid #EBEBEB;
|
178 |
+
border-radius: 5px;
|
179 |
+
font-size: 14px;
|
180 |
+
padding: 10px;
|
181 |
+
}
|
182 |
+
|
183 |
+
.perpetto table.perpetto-slots {
|
184 |
+
border: 1px solid #EBEBEB;
|
185 |
+
table-layout: fixed;
|
186 |
+
margin-bottom: 20px;
|
187 |
+
}
|
188 |
+
|
189 |
+
.perpetto table.perpetto-slots td,
|
190 |
+
.perpetto table.perpetto-slots th {
|
191 |
+
padding: 10px 10px;
|
192 |
+
}
|
193 |
+
|
194 |
+
.perpetto table.perpetto-slots td {
|
195 |
+
border-top: 1px solid #EBEBEB;
|
196 |
+
color: #000;
|
197 |
+
font-size: 14px;
|
198 |
+
}
|
199 |
+
|
200 |
+
.perpetto table.perpetto-slots th {
|
201 |
+
font-weight: normal;
|
202 |
+
vertical-align: bottom;
|
203 |
+
white-space: nowrap;
|
204 |
+
}
|
205 |
+
|
206 |
+
.perpetto table.perpetto-slots th:first-child {
|
207 |
+
color: #000;
|
208 |
+
font-size: 18px;
|
209 |
+
vertical-align: top;
|
210 |
+
}
|