Version Notes
Loyalty programme for success pages
Download this release
Release Info
Developer | Magento Core Team |
Extension | Bonusbox_Bonusbox1 |
Version | 1.1.0 |
Comparing to | |
See all releases |
Code changes from version 0.9.1 to 1.1.0
- app/code/community/Bonusbox/Bonusbox/Block/Checkout/Success.php +16 -29
- app/code/community/Bonusbox/Bonusbox/Exception.php +5 -0
- app/code/community/Bonusbox/Bonusbox/Helper/Data.php +110 -10
- app/code/community/Bonusbox/Bonusbox/Helper/Successpage.php +27 -4
- app/code/community/Bonusbox/Bonusbox/Model/Client.php +110 -124
- app/code/community/Bonusbox/Bonusbox/Model/Client/Badges.php +14 -0
- app/code/community/Bonusbox/Bonusbox/Model/Client/Coupons.php +28 -0
- app/code/community/Bonusbox/Bonusbox/Model/Client/Successpages.php +112 -0
- app/code/community/Bonusbox/Bonusbox/Model/Sales/Observer.php +35 -0
- app/code/community/Bonusbox/Bonusbox/Model/SalesRule/Condition/Bonusbox.php +80 -0
- app/code/community/Bonusbox/Bonusbox/Model/SalesRule/Validator.php +71 -0
- app/code/community/Bonusbox/Bonusbox/Model/Session.php +24 -0
- app/code/community/Bonusbox/Bonusbox/controllers/TestController.php +4 -2
- app/code/community/Bonusbox/Bonusbox/etc/config.xml +29 -5
- app/code/community/Bonusbox/Bonusbox/etc/system.xml +1 -47
- package.xml +4 -4
app/code/community/Bonusbox/Bonusbox/Block/Checkout/Success.php
CHANGED
@@ -3,40 +3,27 @@ class Bonusbox_Bonusbox_Block_Checkout_Success extends Mage_Core_Block_Template
|
|
3 |
{
|
4 |
protected $_template = 'bonusbox/checkout/success.phtml';
|
5 |
|
6 |
-
|
|
|
|
|
|
|
|
|
7 |
{
|
8 |
-
|
9 |
-
try {
|
10 |
-
if (Mage::helper('bonusbox/successpage')->isOperational())
|
11 |
-
{
|
12 |
-
$orderId = Mage::getSingleton('checkout/session')->getLastOrderId();
|
13 |
-
$order = Mage::getModel('sales/order')->load($orderId);
|
14 |
-
if ($order->getId())
|
15 |
-
{
|
16 |
-
$response = Mage::getModel('bonusbox/client')->requestSuccessPage($order);
|
17 |
-
$this->setSuccessPageUrl($response['success_page']['url']);
|
18 |
-
}
|
19 |
-
else {
|
20 |
-
throw new Exception('No Order found for success page.');
|
21 |
-
}
|
22 |
-
}
|
23 |
-
else {
|
24 |
-
Mage::log('Bonusbox Success Page is missing config data.');
|
25 |
-
}
|
26 |
-
}
|
27 |
-
catch (Exception $ex)
|
28 |
{
|
29 |
-
|
|
|
|
|
30 |
}
|
31 |
-
|
32 |
}
|
33 |
|
34 |
-
|
35 |
-
|
|
|
|
|
36 |
{
|
37 |
-
|
38 |
-
|
39 |
-
return parent::_toHtml();
|
40 |
-
}
|
41 |
}
|
|
|
42 |
}
|
3 |
{
|
4 |
protected $_template = 'bonusbox/checkout/success.phtml';
|
5 |
|
6 |
+
/**
|
7 |
+
* Checks if a bonusbox success url exits. After rendering the url is removed from the session.
|
8 |
+
* Otherwise nothing is rendered.
|
9 |
+
*/
|
10 |
+
protected function _toHtml()
|
11 |
{
|
12 |
+
if ($this->getSuccessPageUrl())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
{
|
14 |
+
$html = parent::_toHtml();
|
15 |
+
Mage::helper('bonusbox')->getSession()->setSuccessPage(null);
|
16 |
+
return $html;
|
17 |
}
|
|
|
18 |
}
|
19 |
|
20 |
+
/**
|
21 |
+
* Retrieves the bonusbox success url from the session.
|
22 |
+
*/
|
23 |
+
public function getSuccessPageUrl()
|
24 |
{
|
25 |
+
$successPage = Mage::helper('bonusbox')->getSession()->getSuccessPage();
|
26 |
+
return $successPage['url'];
|
|
|
|
|
27 |
}
|
28 |
+
|
29 |
}
|
app/code/community/Bonusbox/Bonusbox/Exception.php
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Bonusbox_Bonusbox_Exception extends Zend_Exception
|
3 |
+
{
|
4 |
+
|
5 |
+
}
|
app/code/community/Bonusbox/Bonusbox/Helper/Data.php
CHANGED
@@ -5,9 +5,13 @@ class Bonusbox_Bonusbox_Helper_Data extends Mage_Core_Helper_Data
|
|
5 |
|
6 |
protected $configSection = 'general';
|
7 |
|
8 |
-
|
|
|
|
|
|
|
|
|
9 |
{
|
10 |
-
return Mage::getStoreConfig($this->configCode . '/' . $this->configSection . '/' . $
|
11 |
}
|
12 |
|
13 |
|
@@ -22,22 +26,33 @@ class Bonusbox_Bonusbox_Helper_Data extends Mage_Core_Helper_Data
|
|
22 |
return $this->getConfig('live');
|
23 |
}
|
24 |
|
25 |
-
|
|
|
|
|
26 |
public function isOperational()
|
27 |
{
|
28 |
return $this->isEnabled() && $this->getKey('public') && $this->getKey('secret');
|
29 |
}
|
30 |
|
31 |
-
|
32 |
-
|
|
|
|
|
|
|
|
|
33 |
{
|
34 |
$mode = $this->isLive() ? 'live' : 'test';
|
35 |
$type = $secret ? 'secret' : 'public';
|
36 |
-
return $this->getConfig($mode . '_' . $type . '_key');
|
37 |
}
|
38 |
|
39 |
-
|
40 |
-
|
|
|
|
|
|
|
|
|
|
|
41 |
{
|
42 |
if ($this->isLive())
|
43 |
{
|
@@ -63,8 +78,93 @@ class Bonusbox_Bonusbox_Helper_Data extends Mage_Core_Helper_Data
|
|
63 |
throw $message;
|
64 |
}
|
65 |
else {
|
66 |
-
|
|
|
67 |
}
|
68 |
}
|
69 |
}
|
70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
protected $configSection = 'general';
|
7 |
|
8 |
+
/**
|
9 |
+
* Convinience method for access to config data.
|
10 |
+
* @param string $field
|
11 |
+
*/
|
12 |
+
public function getConfig($field, $storeId = null)
|
13 |
{
|
14 |
+
return Mage::getStoreConfig($this->configCode . '/' . $this->configSection . '/' . $field, $storeId);
|
15 |
}
|
16 |
|
17 |
|
26 |
return $this->getConfig('live');
|
27 |
}
|
28 |
|
29 |
+
/**
|
30 |
+
* Checks if modulke is enabled and if keys are provided
|
31 |
+
*/
|
32 |
public function isOperational()
|
33 |
{
|
34 |
return $this->isEnabled() && $this->getKey('public') && $this->getKey('secret');
|
35 |
}
|
36 |
|
37 |
+
|
38 |
+
/**
|
39 |
+
* Returns the key for the selected live mode (live|test) and the given param (public|secret)
|
40 |
+
* @param bool $secret
|
41 |
+
*/
|
42 |
+
public function getKey($secret, $storeId = null)
|
43 |
{
|
44 |
$mode = $this->isLive() ? 'live' : 'test';
|
45 |
$type = $secret ? 'secret' : 'public';
|
46 |
+
return $this->getConfig($mode . '_' . $type . '_key', $storeId);
|
47 |
}
|
48 |
|
49 |
+
/**
|
50 |
+
* If live mode is enabled an email is sent to the configured debug mail address (see config.xml). In test mode an excption is thrown.
|
51 |
+
* @param string|Exception $message
|
52 |
+
* @throws Exception
|
53 |
+
* @throws Mage_Core_Exception
|
54 |
+
*/
|
55 |
+
public function handleError($message)
|
56 |
{
|
57 |
if ($this->isLive())
|
58 |
{
|
78 |
throw $message;
|
79 |
}
|
80 |
else {
|
81 |
+
require_once 'Bonusbox/Bonusbox/Exception.php';
|
82 |
+
throw new Bonusbox_Bonusbox_Exception($message);
|
83 |
}
|
84 |
}
|
85 |
}
|
86 |
+
|
87 |
+
/**
|
88 |
+
* Retrieves an options array with the id, title (incl. the benefit).
|
89 |
+
* The Badges are cached in the session.
|
90 |
+
* @TODO refactor and extract to badge helper class
|
91 |
+
* @return array
|
92 |
+
*/
|
93 |
+
public function getBadgeOptions()
|
94 |
+
{
|
95 |
+
$session = Mage::getSingleton('bonusbox/session');
|
96 |
+
if (!$session->getData('badge_options'))
|
97 |
+
{
|
98 |
+
$secret = true;
|
99 |
+
foreach (Mage::app()->getGroups() as $storeGroup)
|
100 |
+
{
|
101 |
+
$apiKey = $this->getKey($secret, $storeGroup->getDefaultStoreId());
|
102 |
+
$storeGroups[$apiKey] = $storeGroup;
|
103 |
+
}
|
104 |
+
|
105 |
+
$client = Mage::getModel('bonusbox/client_badges');
|
106 |
+
foreach ($storeGroups as $storeGroup)
|
107 |
+
{
|
108 |
+
$badges = $client->setStoreId($storeGroup->getDefaultStoreId())->get();
|
109 |
+
foreach ($badges as $badge)
|
110 |
+
{
|
111 |
+
$badge = $badge['badge'];
|
112 |
+
$label = $badge['title'];
|
113 |
+
if ($badge['benefit'])
|
114 |
+
{
|
115 |
+
$label = sprintf('%s (%s)', $label, $badge['benefit']);
|
116 |
+
}
|
117 |
+
if (count($storeGroups) > 1)
|
118 |
+
{
|
119 |
+
$label = sprintf('%s - %s', $storeGroup->getName(), $label);
|
120 |
+
}
|
121 |
+
$badgeOptions[] = array('value' => $badge['id'], 'label' => $label);
|
122 |
+
}
|
123 |
+
}
|
124 |
+
$session->setData('badge_options', $badgeOptions);
|
125 |
+
}
|
126 |
+
return $session->getData('badge_options');
|
127 |
+
}
|
128 |
+
|
129 |
+
/**
|
130 |
+
* Checks if coupon code is a valid bonusbox code
|
131 |
+
* @param string $couponCode
|
132 |
+
* @return bool
|
133 |
+
*/
|
134 |
+
public function isValidBonusboxCouponCode($couponCode)
|
135 |
+
{
|
136 |
+
$request = new Varien_Object();
|
137 |
+
$request->setCouponCode($couponCode);
|
138 |
+
return $this->getCustomerBadge($request) !== null;
|
139 |
+
}
|
140 |
+
|
141 |
+
/**
|
142 |
+
* Retrieves the badge id for a given coupon code.
|
143 |
+
* The response is cached in the session.
|
144 |
+
* @TODO extract to badge helper class
|
145 |
+
* @param Varien_Object $quote
|
146 |
+
* @return int
|
147 |
+
*/
|
148 |
+
public function getCustomerBadge(Varien_Object $request)
|
149 |
+
{
|
150 |
+
$couponCode = $request->getCouponCode();
|
151 |
+
if ($couponCode)
|
152 |
+
{
|
153 |
+
$session = $this->getSession();
|
154 |
+
if (!$session->getCustomerBadgeByCoupon($couponCode))
|
155 |
+
{
|
156 |
+
$response = Mage::getModel('bonusbox/client_coupons')->get($couponCode);
|
157 |
+
$session->setCustomerBadgeByCoupon($couponCode, $response['coupon']['user']['badge']['id']);
|
158 |
+
}
|
159 |
+
return $session->getCustomerBadgeByCoupon($couponCode);
|
160 |
+
}
|
161 |
+
}
|
162 |
+
|
163 |
+
/**
|
164 |
+
* @return Bonusbox_Bonusbox_Model_Session
|
165 |
+
*/
|
166 |
+
public function getSession()
|
167 |
+
{
|
168 |
+
return Mage::getSingleton('bonusbox/session');
|
169 |
+
}
|
170 |
+
}
|
app/code/community/Bonusbox/Bonusbox/Helper/Successpage.php
CHANGED
@@ -1,10 +1,33 @@
|
|
1 |
<?php
|
2 |
class Bonusbox_Bonusbox_Helper_Successpage extends Bonusbox_Bonusbox_Helper_Data
|
3 |
{
|
4 |
-
protected $configSection = 'success_page';
|
|
|
5 |
|
6 |
public function isOperational()
|
7 |
{
|
8 |
-
return Mage::helper('bonusbox')->isOperational()
|
9 |
-
}
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
<?php
|
2 |
class Bonusbox_Bonusbox_Helper_Successpage extends Bonusbox_Bonusbox_Helper_Data
|
3 |
{
|
4 |
+
protected $configSection = 'success_page';
|
5 |
+
|
6 |
|
7 |
public function isOperational()
|
8 |
{
|
9 |
+
return Mage::helper('bonusbox')->isOperational();
|
10 |
+
}
|
11 |
+
|
12 |
+
|
13 |
+
public function getCssUrl($appendTimestampp = true)
|
14 |
+
{
|
15 |
+
$url = Mage::getBaseUrl('skin');
|
16 |
+
$url = Mage::getDesign()->getSkinUrl($this->getConfig('style_url'), array());
|
17 |
+
if ($appendTimestampp)
|
18 |
+
{
|
19 |
+
$filename = $this->getCssFile();
|
20 |
+
if (file_exists($filename))
|
21 |
+
{
|
22 |
+
$url .= '?' . filemtime($filename);
|
23 |
+
}
|
24 |
+
}
|
25 |
+
return $url;
|
26 |
+
}
|
27 |
+
|
28 |
+
|
29 |
+
public function getCssFile()
|
30 |
+
{
|
31 |
+
return Mage::getDesign()->getFilename($this->getConfig('style_url'), array('_type' => 'skin'));
|
32 |
+
}
|
33 |
+
}
|
app/code/community/Bonusbox/Bonusbox/Model/Client.php
CHANGED
@@ -1,18 +1,77 @@
|
|
1 |
<?php
|
2 |
-
class Bonusbox_Bonusbox_Model_Client extends
|
3 |
{
|
4 |
const CONTENT_TYPE = 'application/json';
|
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
/**
|
7 |
-
*
|
8 |
*/
|
9 |
public function __construct()
|
10 |
{
|
11 |
parent::__construct();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
$this
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
15 |
;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
}
|
17 |
|
18 |
/**
|
@@ -26,147 +85,75 @@ class Bonusbox_Bonusbox_Model_Client extends Varien_Http_Client
|
|
26 |
|
27 |
/**
|
28 |
* Decodes data from json format
|
29 |
-
* @param
|
30 |
*/
|
31 |
public function decodeData($body)
|
32 |
{
|
33 |
return json_decode($body, true);
|
34 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
/**
|
37 |
-
* Request a resource with given data.
|
38 |
-
* @
|
39 |
-
* @param
|
40 |
-
* @param
|
|
|
|
|
|
|
41 |
*/
|
42 |
-
public function requestResource($
|
43 |
{
|
44 |
try {
|
45 |
-
$this
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
if (strpos($response->getStatus(), '2') === 0) # codes in the 2xx range indicate success
|
52 |
{
|
53 |
-
|
|
|
54 |
}
|
55 |
-
|
56 |
-
|
|
|
|
|
|
|
|
|
|
|
57 |
}
|
|
|
|
|
58 |
}
|
59 |
catch (Exception $ex)
|
60 |
{
|
61 |
-
Mage::helper('bonusbox')->
|
62 |
}
|
63 |
}
|
64 |
|
65 |
-
/**
|
66 |
-
* Sets required data from address object to array
|
67 |
-
* @param Mage_Sales_Model_Order_Address $address
|
68 |
-
*/
|
69 |
-
protected function getAddressPost(Mage_Sales_Model_Order_Address $address)
|
70 |
-
{
|
71 |
-
return array(
|
72 |
-
'code' => $address->getAddressType(),
|
73 |
-
'city' => $address->getCity(),
|
74 |
-
'company' => $address->getCompany(),
|
75 |
-
'region' => $address->getRegion(),
|
76 |
-
'country' => $address->getCountry(),
|
77 |
-
'firstname' => $address->getFirstname(),
|
78 |
-
'lastname' => $address->getLastname(),
|
79 |
-
'phone' => $address->getTelephone(),
|
80 |
-
'fax' => $address->getFax(),
|
81 |
-
'email' => $address->getEmail(),
|
82 |
-
'street' => $address->getStreetFull(),
|
83 |
-
'zip' => $address->getPostcode()
|
84 |
-
);
|
85 |
-
}
|
86 |
-
|
87 |
-
/**
|
88 |
-
* Formats decimal values to int by multiplying and rounding
|
89 |
-
* @param decimal $value
|
90 |
-
* @param int $precision
|
91 |
-
* @return int
|
92 |
-
*/
|
93 |
-
protected function encodeDecimal($value, $precision = 2)
|
94 |
-
{
|
95 |
-
return round($value * pow(10, $precision));
|
96 |
-
}
|
97 |
-
|
98 |
-
/**
|
99 |
-
* Request resource success_pages with order data
|
100 |
-
* Return url and token, if successful, otherwise detailed error description
|
101 |
-
* @param Mage_Sales_Model_Order $order
|
102 |
-
* @return mixed
|
103 |
-
*/
|
104 |
-
public function requestSuccessPage(Mage_Sales_Model_Order $order)
|
105 |
-
{
|
106 |
-
$payment = $order->getPayment();
|
107 |
-
$helper = Mage::helper('bonusbox/successpage');
|
108 |
-
|
109 |
-
$data = array(
|
110 |
-
'addresses' => array(
|
111 |
-
$this->getAddressPost($order->getBillingAddress()),
|
112 |
-
$this->getAddressPost($order->getShippingAddress())
|
113 |
-
),
|
114 |
-
'discount' => array(
|
115 |
-
'token' => $helper->getConfig('coupon_code'),
|
116 |
-
'expires_at' => $helper->getConfig('coupon_expires_at'),
|
117 |
-
'title' => $helper->getConfig('coupon_title'),
|
118 |
-
'description' => $helper->getConfig('coupon_description')
|
119 |
-
),
|
120 |
-
'discounts_used' => $order->getCouponCode() ? array($order->getCouponCode()) : null,
|
121 |
-
'items' => array(
|
122 |
-
array(
|
123 |
-
'code' => 'shipping',
|
124 |
-
'quantity' => $this->encodeDecimal(1),
|
125 |
-
'sku' => $order->getShippingMethod(),
|
126 |
-
'title' => $order->getShippingDescription(),
|
127 |
-
'price' => $this->encodeDecimal($order->getData('shipping_amount')),
|
128 |
-
'vat_amount' => $this->encodeDecimal($order->getData('shipping_tax_amount')),
|
129 |
-
'vat_rate' => $order->getData('shipping_amount') > 0 ? $this->encodeDecimal($order->getData('shipping_tax_amount') / ($order->getData('shipping_amount'))) : 0
|
130 |
-
),
|
131 |
-
array(
|
132 |
-
'code' => 'payment',
|
133 |
-
'quantity' => $this->encodeDecimal(1),
|
134 |
-
'sku' => $payment->getMethod(),
|
135 |
-
'title' => $payment->getMethodInstance()->getTitle(),
|
136 |
-
'price' => 0,
|
137 |
-
'vat_amount' => 0,
|
138 |
-
'vat_rate' => 0
|
139 |
-
),
|
140 |
-
),
|
141 |
-
'currency' => $order->getData('order_currency_code'),
|
142 |
-
'order_number' => $order->getData('increment_id'),
|
143 |
-
'new_user_text' => $helper->getConfig('new_user_text'),
|
144 |
-
'bonusbox_user_text' => $helper->getConfig('bonusbox_user_text'),
|
145 |
-
'style_url' => Mage::getDesign()->getSkinUrl($helper->getConfig('style_url'), array())
|
146 |
-
);
|
147 |
-
|
148 |
-
foreach ($order->getAllItems() as $item)
|
149 |
-
{
|
150 |
-
$product = Mage::getModel('catalog/product')->load($item->getProductId());
|
151 |
-
$data['items'][] = array(
|
152 |
-
'code' => 'product',
|
153 |
-
'sku' => $item->getSku(),
|
154 |
-
'quantity' => round($item->getQtyOrdered()),
|
155 |
-
'title' => $item->getName(),
|
156 |
-
'description' => $item->getDescription(),
|
157 |
-
'price' => $this->encodeDecimal($item->getData('price')),
|
158 |
-
'vat_rate' => $this->encodeDecimal($item->getData('tax_percent')),
|
159 |
-
'vat_amount' => $this->encodeDecimal($item->getData('tax_amount')),
|
160 |
-
'landing_page' => $product->getUrlModel()->getUrl($product, array('_ignore_category' => true)),
|
161 |
-
'image_url' => Mage::helper('catalog/image')->init($product, 'image')->__toString()
|
162 |
-
);
|
163 |
-
}
|
164 |
-
return $this->requestResource('success_pages', true, $data);
|
165 |
-
}
|
166 |
-
|
167 |
/**
|
168 |
* Super class does not support __toString
|
169 |
* @return string
|
|
|
170 |
*/
|
171 |
public function __toString()
|
172 |
{
|
@@ -175,9 +162,8 @@ class Bonusbox_Bonusbox_Model_Client extends Varien_Http_Client
|
|
175 |
$headers[] = $header[0] . ': ' . $header[1];
|
176 |
}
|
177 |
return implode("\n", array(
|
178 |
-
|
179 |
implode("\n", $headers),
|
180 |
-
'Authorization: ' . $this->auth['type'] . ' ' . $this->auth['user'] . ':' . $this->auth['password'],
|
181 |
$this->raw_post_data
|
182 |
));
|
183 |
}
|
1 |
<?php
|
2 |
+
class Bonusbox_Bonusbox_Model_Client extends Zend_Http_Client
|
3 |
{
|
4 |
const CONTENT_TYPE = 'application/json';
|
5 |
|
6 |
+
const
|
7 |
+
METHOD_POST = 'POST',
|
8 |
+
METHOD_PUT = 'PUT',
|
9 |
+
METHOD_GET = 'GET',
|
10 |
+
METHOD_DELETE = 'DELETE'
|
11 |
+
;
|
12 |
+
|
13 |
+
/**
|
14 |
+
* Name of requested resource -> is set by sub classes
|
15 |
+
* @var string
|
16 |
+
*/
|
17 |
+
protected $_resourceName;
|
18 |
+
|
19 |
+
/**
|
20 |
+
* determines store and which config data will be used
|
21 |
+
* @TODO resolve with config object
|
22 |
+
* @var int
|
23 |
+
*/
|
24 |
+
protected $_storeId;
|
25 |
+
|
26 |
/**
|
27 |
+
* object is created with empty array by magento -> if constructor is invoked with empty array, it requires to contain a valid url
|
28 |
*/
|
29 |
public function __construct()
|
30 |
{
|
31 |
parent::__construct();
|
32 |
+
$adapter = new Zend_Http_Client_Adapter_Curl();
|
33 |
+
$this->setAdapter($adapter);
|
34 |
+
$adapter->setConfig(array(
|
35 |
+
'curloptions' => array(
|
36 |
+
CURLOPT_SSL_VERIFYPEER => 0,
|
37 |
+
CURLOPT_SSL_VERIFYHOST => 0
|
38 |
+
)
|
39 |
+
));
|
40 |
+
}
|
41 |
+
|
42 |
+
/**
|
43 |
+
* Initialize request
|
44 |
+
* @param bool $useSecretKey
|
45 |
+
*/
|
46 |
+
public function init($useSecretKey = true)
|
47 |
+
{
|
48 |
+
$helper = Mage::helper('bonusbox');
|
49 |
$this
|
50 |
+
->resetParameters(true)
|
51 |
+
->setUri($helper->getConfig('url') . $this->_resourceName)
|
52 |
+
->setHeaders('Accept', $helper->getConfig('accept_header'))
|
53 |
+
->setHeaders('Content-Type', self::CONTENT_TYPE)
|
54 |
+
->setAuth($helper->getKey($useSecretKey, $this->getStoreId())) // to collect all badges with multiple shops, request has ti be executed with different store context
|
55 |
+
->setRawData(null)
|
56 |
;
|
57 |
+
return $this;
|
58 |
+
}
|
59 |
+
|
60 |
+
/**
|
61 |
+
* @return int
|
62 |
+
*/
|
63 |
+
public function getStoreId()
|
64 |
+
{
|
65 |
+
return $this->_storeId;
|
66 |
+
}
|
67 |
+
|
68 |
+
/**
|
69 |
+
* @param int $value
|
70 |
+
*/
|
71 |
+
public function setStoreId($value)
|
72 |
+
{
|
73 |
+
$this->_storeId = $value;
|
74 |
+
return $this;
|
75 |
}
|
76 |
|
77 |
/**
|
85 |
|
86 |
/**
|
87 |
* Decodes data from json format
|
88 |
+
* @param mixed $body
|
89 |
*/
|
90 |
public function decodeData($body)
|
91 |
{
|
92 |
return json_decode($body, true);
|
93 |
}
|
94 |
+
|
95 |
+
/**
|
96 |
+
* Formats decimal values to int by multiplying and rounding
|
97 |
+
* @param decimal $value
|
98 |
+
* @param int $precision
|
99 |
+
* @return int
|
100 |
+
*/
|
101 |
+
public function encodeDecimal($value, $precision = 2)
|
102 |
+
{
|
103 |
+
return (int)round($value * pow(10, $precision));
|
104 |
+
}
|
105 |
|
106 |
/**
|
107 |
+
* Request a resource with given method and data.
|
108 |
+
* @link https://github.com/bonusboxme/api_documentation/wiki
|
109 |
+
* @param string $method
|
110 |
+
* @param bool $useSecretKey - Flag for secure/public key
|
111 |
+
* @param mixed $queryData
|
112 |
+
* @param mixed $rawData
|
113 |
+
* @param array $acceptedErrors codes that do not invoke an exception, if an error is provided in the response @TODO move to handleError method for every client
|
114 |
*/
|
115 |
+
public function requestResource($method, $useSecretKey, $queryData = null, $rawData = null, $acceptedErrors = null)
|
116 |
{
|
117 |
try {
|
118 |
+
$this->init($useSecretKey);
|
119 |
+
if ($queryData)
|
120 |
+
{
|
121 |
+
// @todo if array is provided
|
122 |
+
$this->setUri($this->getUri() . '/' . $queryData);
|
123 |
+
}
|
124 |
+
if ($rawData)
|
125 |
+
{
|
126 |
+
$this->setRawData($this->encodeData($rawData));
|
127 |
+
}
|
128 |
+
$this->setMethod($method);
|
129 |
+
|
130 |
+
$response = $this->request();
|
131 |
if (strpos($response->getStatus(), '2') === 0) # codes in the 2xx range indicate success
|
132 |
{
|
133 |
+
$responseBody = $this->decodeData($response->getBody());
|
134 |
+
return $responseBody;
|
135 |
}
|
136 |
+
if (is_array($acceptedErrors) && in_array($response->getStatus(), $acceptedErrors))
|
137 |
+
{
|
138 |
+
$responseBody = $this->decodeData($response->getBody());
|
139 |
+
if ($responseBody['error'])
|
140 |
+
{
|
141 |
+
return null;
|
142 |
+
}
|
143 |
}
|
144 |
+
require_once 'Bonusbox/Bonusbox/Exception.php';
|
145 |
+
throw new Bonusbox_Bonusbox_Exception("Invalid Response\n" . (string)$this . "\n\n" . (string)$response);
|
146 |
}
|
147 |
catch (Exception $ex)
|
148 |
{
|
149 |
+
Mage::helper('bonusbox')->handleError($ex);
|
150 |
}
|
151 |
}
|
152 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
153 |
/**
|
154 |
* Super class does not support __toString
|
155 |
* @return string
|
156 |
+
* @codeCoverageIgnore
|
157 |
*/
|
158 |
public function __toString()
|
159 |
{
|
162 |
$headers[] = $header[0] . ': ' . $header[1];
|
163 |
}
|
164 |
return implode("\n", array(
|
165 |
+
$this->method . ' ' . $this->getUri(),
|
166 |
implode("\n", $headers),
|
|
|
167 |
$this->raw_post_data
|
168 |
));
|
169 |
}
|
app/code/community/Bonusbox/Bonusbox/Model/Client/Badges.php
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Bonusbox_Bonusbox_Model_Client_Badges extends Bonusbox_Bonusbox_Model_Client
|
3 |
+
{
|
4 |
+
protected $_resourceName = 'badges';
|
5 |
+
|
6 |
+
/**
|
7 |
+
* @link https://github.com/bonusboxme/api_documentation/wiki/Get--badges
|
8 |
+
* @return mixed
|
9 |
+
*/
|
10 |
+
public function get()
|
11 |
+
{
|
12 |
+
return $this->requestResource(self::METHOD_GET, true);
|
13 |
+
}
|
14 |
+
}
|
app/code/community/Bonusbox/Bonusbox/Model/Client/Coupons.php
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Bonusbox_Bonusbox_Model_Client_Coupons extends Bonusbox_Bonusbox_Model_Client
|
3 |
+
{
|
4 |
+
protected $_resourceName = 'coupons';
|
5 |
+
|
6 |
+
/**
|
7 |
+
* Retrieves info for a bonusbox coupon
|
8 |
+
* @link https://github.com/bonusboxme/api_documentation/wiki/GET-coupons
|
9 |
+
* @param string $couponCode
|
10 |
+
* @return mixed
|
11 |
+
*/
|
12 |
+
public function get($couponCode)
|
13 |
+
{
|
14 |
+
return $this->requestResource(self::METHOD_GET, true, $couponCode, null, array(404));
|
15 |
+
}
|
16 |
+
|
17 |
+
|
18 |
+
/**
|
19 |
+
* Deletes a bonusbox coupon
|
20 |
+
* @link https://github.com/bonusboxme/api_documentation/wiki/DELETE-coupons
|
21 |
+
* @param string $couponCode
|
22 |
+
* @return mixed
|
23 |
+
*/
|
24 |
+
public function delete($couponCode)
|
25 |
+
{
|
26 |
+
return $this->requestResource(self::METHOD_DELETE, true, $couponCode);
|
27 |
+
}
|
28 |
+
}
|
app/code/community/Bonusbox/Bonusbox/Model/Client/Successpages.php
ADDED
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Bonusbox_Bonusbox_Model_Client_Successpages extends Bonusbox_Bonusbox_Model_Client
|
3 |
+
{
|
4 |
+
protected $_resourceName = 'success_pages';
|
5 |
+
|
6 |
+
/**
|
7 |
+
* Sets required data from address object to array
|
8 |
+
* @param Mage_Sales_Model_Order_Address $address
|
9 |
+
* @return array
|
10 |
+
*/
|
11 |
+
protected function encodeAddress(Mage_Sales_Model_Order_Address $address)
|
12 |
+
{
|
13 |
+
return array(
|
14 |
+
'code' => $address->getAddressType(),
|
15 |
+
'city' => $address->getCity(),
|
16 |
+
'company' => $address->getCompany(),
|
17 |
+
'region' => $address->getRegion(),
|
18 |
+
'country' => $address->getCountry(),
|
19 |
+
'firstname' => $address->getFirstname(),
|
20 |
+
'lastname' => $address->getLastname(),
|
21 |
+
'phone' => $address->getTelephone(),
|
22 |
+
'fax' => $address->getFax(),
|
23 |
+
'email' => $address->getEmail(),
|
24 |
+
'street' => $address->getStreetFull(),
|
25 |
+
'zip' => $address->getPostcode()
|
26 |
+
);
|
27 |
+
}
|
28 |
+
|
29 |
+
/**
|
30 |
+
* Sets required data from item object to array
|
31 |
+
* @param Mage_Sales_Model_Order_Item $item
|
32 |
+
* @return array
|
33 |
+
*/
|
34 |
+
protected function encodeItem(Mage_Sales_Model_Order_Item $item)
|
35 |
+
{
|
36 |
+
$product = Mage::getModel('catalog/product')->load($item->getProductId()); // ensure that all product attributes are loaded
|
37 |
+
return array(
|
38 |
+
'code' => 'product',
|
39 |
+
'sku' => $item->getSku(),
|
40 |
+
'quantity' => round($item->getQtyOrdered()),
|
41 |
+
'title' => $item->getName(),
|
42 |
+
'description' => $item->getDescription(),
|
43 |
+
'price' => $this->encodeDecimal($item->getData('price')),
|
44 |
+
'vat_rate' => $this->encodeDecimal($item->getData('tax_percent')),
|
45 |
+
'vat_amount' => $this->encodeDecimal($item->getData('tax_amount')),
|
46 |
+
'landing_page' => $product->getUrlModel()->getUrl($product, array('_ignore_category' => true)),
|
47 |
+
'image_url' => Mage::helper('catalog/image')->init($product, 'image')->__toString()
|
48 |
+
);
|
49 |
+
}
|
50 |
+
|
51 |
+
/**
|
52 |
+
* Encodes order to array
|
53 |
+
* @param Mage_Sales_Model_Order $order
|
54 |
+
* @return array
|
55 |
+
*/
|
56 |
+
public function encodeOrder(Mage_Sales_Model_Order $order)
|
57 |
+
{
|
58 |
+
$helper = Mage::helper('bonusbox/successpage');
|
59 |
+
$payment = $order->getPayment();
|
60 |
+
|
61 |
+
$addresses[] = $this->encodeAddress($order->getBillingAddress());
|
62 |
+
if (!$order->getIsVirtual())
|
63 |
+
{
|
64 |
+
$addresses[] = $this->encodeAddress($order->getShippingAddress());
|
65 |
+
}
|
66 |
+
$data = array(
|
67 |
+
'addresses' => $addresses,
|
68 |
+
'currency' => $order->getData('order_currency_code'),
|
69 |
+
'order_number' => $order->getData('increment_id'),
|
70 |
+
'discounts_used' => $order->getCouponCode() ? array($order->getCouponCode()) : null,
|
71 |
+
'style_url' => $helper->getCssUrl(),
|
72 |
+
'items' => array(
|
73 |
+
array(
|
74 |
+
'code' => 'shipping',
|
75 |
+
'quantity' => $this->encodeDecimal(1),
|
76 |
+
'sku' => $order->getShippingMethod(),
|
77 |
+
'title' => $order->getShippingDescription(),
|
78 |
+
'price' => $this->encodeDecimal($order->getData('shipping_amount')),
|
79 |
+
'vat_amount' => $this->encodeDecimal($order->getData('shipping_tax_amount')),
|
80 |
+
'vat_rate' => $order->getData('shipping_amount') > 0 ? $this->encodeDecimal($order->getData('shipping_tax_amount') / $order->getData('shipping_amount') * 100) : 0
|
81 |
+
),
|
82 |
+
array(
|
83 |
+
'code' => 'payment',
|
84 |
+
'quantity' => $this->encodeDecimal(1),
|
85 |
+
'sku' => $payment->getMethod(),
|
86 |
+
'title' => $payment->getMethodInstance()->getTitle(),
|
87 |
+
'price' => 0,
|
88 |
+
'vat_amount' => 0,
|
89 |
+
'vat_rate' => 0
|
90 |
+
)
|
91 |
+
)
|
92 |
+
);
|
93 |
+
|
94 |
+
foreach ($order->getAllItems() as $item)
|
95 |
+
{
|
96 |
+
$data['items'][] = $this->encodeItem($item);
|
97 |
+
}
|
98 |
+
return $data;
|
99 |
+
}
|
100 |
+
|
101 |
+
/**
|
102 |
+
* Request resource success_pages with order data
|
103 |
+
* Return url and token, if successful, otherwise detailed error description
|
104 |
+
* @link https://github.com/bonusboxme/api_documentation/wiki/CREATE-success_pages
|
105 |
+
* @param Mage_Sales_Model_Order $order
|
106 |
+
* @return mixed
|
107 |
+
*/
|
108 |
+
public function post(Mage_Sales_Model_Order $order)
|
109 |
+
{
|
110 |
+
return $this->requestResource(self::METHOD_POST, true, null, $this->encodeOrder($order));
|
111 |
+
}
|
112 |
+
}
|
app/code/community/Bonusbox/Bonusbox/Model/Sales/Observer.php
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Bonusbox_Bonusbox_Model_Sales_Observer
|
3 |
+
{
|
4 |
+
/**
|
5 |
+
* Forwards order to bonuxbox and saves url for success page iframe in session.
|
6 |
+
* Deletes bonusbox coupon code.
|
7 |
+
* @param Varien_Event_Observer $observer
|
8 |
+
*/
|
9 |
+
public function forwardOrder(Varien_Event_Observer $observer)
|
10 |
+
{
|
11 |
+
$order = $observer->getOrder();
|
12 |
+
if (Mage::helper('bonusbox')->isEnabled())
|
13 |
+
{
|
14 |
+
if (Mage::helper('bonusbox/successpage')->isOperational())
|
15 |
+
{
|
16 |
+
// send order to bonusbox
|
17 |
+
$response = Mage::getModel('bonusbox/client_successpages')->post($order);
|
18 |
+
Mage::helper('bonusbox')->getSession()->setSuccessPage($response['success_page']);
|
19 |
+
|
20 |
+
// delete coupon code from bonusbox
|
21 |
+
if (Mage::helper('bonusbox')->isValidBonusboxCouponCode($order->getCouponCode()))
|
22 |
+
{
|
23 |
+
Mage::getModel('bonusbox/client_coupons')->delete($order->getCouponCode());
|
24 |
+
}
|
25 |
+
|
26 |
+
// invalidate Customer Badge Cache
|
27 |
+
Mage::helper('bonusbox')->getSession()->setCustomerBadgesByCoupon(null);
|
28 |
+
}
|
29 |
+
else {
|
30 |
+
Mage::log('Bonusbox Success Page is missing config data.');
|
31 |
+
}
|
32 |
+
}
|
33 |
+
}
|
34 |
+
|
35 |
+
}
|
app/code/community/Bonusbox/Bonusbox/Model/SalesRule/Condition/Bonusbox.php
ADDED
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Bonusbox_Bonusbox_Model_SalesRule_Condition_Bonusbox extends Mage_Rule_Model_Condition_Abstract
|
3 |
+
{
|
4 |
+
public function addConditions(Varien_Event_Observer $observer)
|
5 |
+
{
|
6 |
+
$class = 'bonusbox/salesrule_condition_bonusbox';
|
7 |
+
$condition = Mage::getModel($class);
|
8 |
+
$condition->loadAttributeOptions();
|
9 |
+
foreach ($condition->getAttributeOption() as $attribute => $label)
|
10 |
+
{
|
11 |
+
$attributes = array(
|
12 |
+
array('value' => $class . '|' . $attribute, 'label' => $label)
|
13 |
+
);
|
14 |
+
}
|
15 |
+
$conditions = array(array('label' => Mage::helper('bonusbox')->__('Bonusbox'), 'value' => $attributes));
|
16 |
+
$observer->getEvent()->getAdditional()->setConditions($conditions);
|
17 |
+
}
|
18 |
+
|
19 |
+
|
20 |
+
public function loadAttributeOptions()
|
21 |
+
{
|
22 |
+
$this->setAttributesMeta(array(
|
23 |
+
'badge' => array(
|
24 |
+
'label' => Mage::helper('bonusbox')->__('Badge'),
|
25 |
+
'input_type' => 'select',
|
26 |
+
'value_element_type' => 'select'
|
27 |
+
)
|
28 |
+
));
|
29 |
+
|
30 |
+
foreach ($this->getAttributesMeta() as $attribute => $attributeMeta)
|
31 |
+
{
|
32 |
+
$attributes[$attribute] = $attributeMeta['label'];
|
33 |
+
}
|
34 |
+
$this->setAttributeOption($attributes);
|
35 |
+
return $this;
|
36 |
+
}
|
37 |
+
|
38 |
+
|
39 |
+
public function getInputType()
|
40 |
+
{
|
41 |
+
$attributesMeta = $this->getAttributesMeta();
|
42 |
+
return $attributesMeta[$this->getAttribute()]['input_type'];
|
43 |
+
}
|
44 |
+
|
45 |
+
|
46 |
+
public function getValueElementType()
|
47 |
+
{
|
48 |
+
$attributesMeta = $this->getAttributesMeta();
|
49 |
+
return $attributesMeta[$this->getAttribute()]['value_element_type'];
|
50 |
+
}
|
51 |
+
|
52 |
+
|
53 |
+
public function getValueSelectOptions()
|
54 |
+
{
|
55 |
+
if (!$this->hasData('value_select_options'))
|
56 |
+
{
|
57 |
+
switch ($this->getAttribute())
|
58 |
+
{
|
59 |
+
case 'badge':
|
60 |
+
$options = Mage::helper('bonusbox')->getBadgeOptions();
|
61 |
+
break;
|
62 |
+
}
|
63 |
+
$this->setData('value_select_options', $options);
|
64 |
+
}
|
65 |
+
return $this->getData('value_select_options');
|
66 |
+
}
|
67 |
+
|
68 |
+
/**
|
69 |
+
* Validate Bonusbox Badge Conditions
|
70 |
+
*
|
71 |
+
* @param Varien_Object $object
|
72 |
+
* @return bool
|
73 |
+
*/
|
74 |
+
public function validate(Varien_Object $object)
|
75 |
+
{
|
76 |
+
$bonusbox = new Varien_Object();
|
77 |
+
$bonusbox->setBadge(Mage::helper('bonusbox')->getCustomerBadge($object->getQuote()));
|
78 |
+
return parent::validate($bonusbox);
|
79 |
+
}
|
80 |
+
}
|
app/code/community/Bonusbox/Bonusbox/Model/SalesRule/Validator.php
ADDED
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Bonusbox_Bonusbox_Model_SalesRule_Validator extends Mage_SalesRule_Model_Validator
|
3 |
+
{
|
4 |
+
/**
|
5 |
+
* Removes the coupon code if it is an bonusbox coupon code an stores it. After validation the bonusbox code is set order.
|
6 |
+
* @param int $websiteId
|
7 |
+
* @param int $customerGroupId
|
8 |
+
* @param string $couponCode
|
9 |
+
* @see Mage_SalesRule_Model_Validator::init($websiteId, $customerGroupId, $couponCode)
|
10 |
+
*/
|
11 |
+
public function init($websiteId, $customerGroupId, $couponCode)
|
12 |
+
{
|
13 |
+
if (Mage::helper('bonusbox')->isValidBonusboxCouponCode($couponCode))
|
14 |
+
{
|
15 |
+
$this->setBonusboxCode($couponCode);
|
16 |
+
$couponCode = null;
|
17 |
+
}
|
18 |
+
else {
|
19 |
+
$this->setBonusboxCode(null);
|
20 |
+
}
|
21 |
+
return parent::init($websiteId, $customerGroupId, $couponCode);
|
22 |
+
}
|
23 |
+
|
24 |
+
/**
|
25 |
+
* Checks if rule contains bonusbox Conditions and if a bonusbox code is set.
|
26 |
+
* @param Mage_SalesRule_Model_Rule $rule
|
27 |
+
* @return boolean
|
28 |
+
*/
|
29 |
+
public function isBonusboxRule($rule)
|
30 |
+
{
|
31 |
+
if ($this->getBonusboxCode() && !$rule->getCouponCode())
|
32 |
+
{
|
33 |
+
return $this->hasBonusboxConditions($rule->getConditions()->getConditions());
|
34 |
+
}
|
35 |
+
}
|
36 |
+
|
37 |
+
/**
|
38 |
+
* Check if $conditions contains a bonusbox condition and searches recursively if a combine condition is contained.
|
39 |
+
* @param array $conditions
|
40 |
+
*/
|
41 |
+
public function hasBonusboxConditions($conditions)
|
42 |
+
{
|
43 |
+
foreach ($conditions as $condition)
|
44 |
+
{
|
45 |
+
if ( $condition instanceof Bonusbox_Bonusbox_Model_SalesRule_Condition_Bonusbox
|
46 |
+
|| $this->hasBonusboxConditions($condition->getConditions())
|
47 |
+
) {
|
48 |
+
return true;
|
49 |
+
}
|
50 |
+
}
|
51 |
+
}
|
52 |
+
|
53 |
+
/**
|
54 |
+
* If one of the applied rules is a bonusbox rule, the code is set to the address
|
55 |
+
* @see Mage_SalesRule_Model_Validator::process($item)
|
56 |
+
*/
|
57 |
+
public function process(Mage_Sales_Model_Quote_Item_Abstract $item)
|
58 |
+
{
|
59 |
+
parent::process($item);
|
60 |
+
$appliedRuleIds = explode(',', $item->getQuote()->getAppliedRuleIds());
|
61 |
+
foreach ($this->_getRules() as $rule)
|
62 |
+
{
|
63 |
+
if (in_array($rule->getId(), $appliedRuleIds) && $this->isBonusboxRule($rule))
|
64 |
+
{
|
65 |
+
$this->_getAddress($item)->setCouponCode($this->getBonusboxCode());
|
66 |
+
break;
|
67 |
+
}
|
68 |
+
}
|
69 |
+
return $this;
|
70 |
+
}
|
71 |
+
}
|
app/code/community/Bonusbox/Bonusbox/Model/Session.php
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Bonusbox_Bonusbox_Model_Session extends Mage_Core_Model_Session_Abstract
|
3 |
+
{
|
4 |
+
public function __construct()
|
5 |
+
{
|
6 |
+
$this->init('bonusbox');
|
7 |
+
}
|
8 |
+
|
9 |
+
|
10 |
+
public function getCustomerBadgeByCoupon($couponCode)
|
11 |
+
{
|
12 |
+
$badges = $this->getCustomerBadgesByCoupon();
|
13 |
+
return $badges[$couponCode];
|
14 |
+
}
|
15 |
+
|
16 |
+
|
17 |
+
public function setCustomerBadgeByCoupon($couponCode, $badge)
|
18 |
+
{
|
19 |
+
$badges = $this->getCustomerBadgesByCoupon();
|
20 |
+
$badges[$couponCode] = $badge;
|
21 |
+
$this->setCustomerBadgesByCoupon($badges);
|
22 |
+
return $this;
|
23 |
+
}
|
24 |
+
}
|
app/code/community/Bonusbox/Bonusbox/controllers/TestController.php
CHANGED
@@ -1,5 +1,8 @@
|
|
1 |
<?php
|
2 |
require_once 'Mage/Checkout/controllers/OnepageController.php';
|
|
|
|
|
|
|
3 |
class Bonusbox_Bonusbox_TestController extends Mage_Checkout_OnepageController
|
4 |
{
|
5 |
protected function getOrder()
|
@@ -14,8 +17,7 @@ class Bonusbox_Bonusbox_TestController extends Mage_Checkout_OnepageController
|
|
14 |
public function successAction()
|
15 |
{
|
16 |
$order = $this->getOrder();
|
17 |
-
|
18 |
-
$session->setLastOrderId($order->getId());
|
19 |
|
20 |
$this->loadLayout();
|
21 |
$this->getLayout()->getBlock('content')->append($this->getLayout()->createBlock('bonusbox/checkout_success'));
|
1 |
<?php
|
2 |
require_once 'Mage/Checkout/controllers/OnepageController.php';
|
3 |
+
/**
|
4 |
+
* @codeCoverageIgnore
|
5 |
+
*/
|
6 |
class Bonusbox_Bonusbox_TestController extends Mage_Checkout_OnepageController
|
7 |
{
|
8 |
protected function getOrder()
|
17 |
public function successAction()
|
18 |
{
|
19 |
$order = $this->getOrder();
|
20 |
+
Mage::dispatchEvent('sales_model_service_quote_submit_after', array('order'=>$order));
|
|
|
21 |
|
22 |
$this->loadLayout();
|
23 |
$this->getLayout()->getBlock('content')->append($this->getLayout()->createBlock('bonusbox/checkout_success'));
|
app/code/community/Bonusbox/Bonusbox/etc/config.xml
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
<config>
|
3 |
<modules>
|
4 |
<bonusbox_bonusbox>
|
5 |
-
<version>
|
6 |
</bonusbox_bonusbox>
|
7 |
</modules>
|
8 |
<global>
|
@@ -10,6 +10,11 @@
|
|
10 |
<bonusbox>
|
11 |
<class>Bonusbox_Bonusbox_Model</class>
|
12 |
</bonusbox>
|
|
|
|
|
|
|
|
|
|
|
13 |
</models>
|
14 |
<helpers>
|
15 |
<bonusbox>
|
@@ -34,6 +39,26 @@
|
|
34 |
<connection><use>core_read</use></connection>
|
35 |
</bonusbox_read>
|
36 |
</resources>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
</global>
|
38 |
|
39 |
<frontend>
|
@@ -110,10 +135,9 @@
|
|
110 |
<accept_header><![CDATA[application/json,application/vnd.api;ver=1]]></accept_header>
|
111 |
<debug_email><![CDATA[no-reply@bonusbox.me]]></debug_email>
|
112 |
</general>
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
</success_page>
|
117 |
</bonusbox>
|
118 |
</default>
|
119 |
</config>
|
2 |
<config>
|
3 |
<modules>
|
4 |
<bonusbox_bonusbox>
|
5 |
+
<version>1.1.0</version>
|
6 |
</bonusbox_bonusbox>
|
7 |
</modules>
|
8 |
<global>
|
10 |
<bonusbox>
|
11 |
<class>Bonusbox_Bonusbox_Model</class>
|
12 |
</bonusbox>
|
13 |
+
<salesrule>
|
14 |
+
<rewrite>
|
15 |
+
<validator>Bonusbox_Bonusbox_Model_SalesRule_Validator</validator>
|
16 |
+
</rewrite>
|
17 |
+
</salesrule>
|
18 |
</models>
|
19 |
<helpers>
|
20 |
<bonusbox>
|
39 |
<connection><use>core_read</use></connection>
|
40 |
</bonusbox_read>
|
41 |
</resources>
|
42 |
+
|
43 |
+
<events>
|
44 |
+
<salesrule_rule_condition_combine>
|
45 |
+
<observers>
|
46 |
+
<bonusbox>
|
47 |
+
<class>bonusbox/salesrule_condition_bonusbox</class>
|
48 |
+
<method>addConditions</method>
|
49 |
+
</bonusbox>
|
50 |
+
</observers>
|
51 |
+
</salesrule_rule_condition_combine>
|
52 |
+
|
53 |
+
<sales_model_service_quote_submit_after>
|
54 |
+
<observers>
|
55 |
+
<bonusbox>
|
56 |
+
<class>bonusbox/sales_observer</class>
|
57 |
+
<method>forwardOrder</method>
|
58 |
+
</bonusbox>
|
59 |
+
</observers>
|
60 |
+
</sales_model_service_quote_submit_after>
|
61 |
+
</events>
|
62 |
</global>
|
63 |
|
64 |
<frontend>
|
135 |
<accept_header><![CDATA[application/json,application/vnd.api;ver=1]]></accept_header>
|
136 |
<debug_email><![CDATA[no-reply@bonusbox.me]]></debug_email>
|
137 |
</general>
|
138 |
+
<success_page>
|
139 |
+
<style_url>css/bonusbox.css</style_url>
|
140 |
+
</success_page>
|
|
|
141 |
</bonusbox>
|
142 |
</default>
|
143 |
</config>
|
app/code/community/Bonusbox/Bonusbox/etc/system.xml
CHANGED
@@ -29,7 +29,7 @@
|
|
29 |
<label>Live Mode</label>
|
30 |
<frontend_type>select</frontend_type>
|
31 |
<source_model>adminhtml/system_config_source_yesno</source_model>
|
32 |
-
<comment>
|
33 |
<sort_order>20</sort_order>
|
34 |
<show_in_default>1</show_in_default>
|
35 |
<show_in_website>1</show_in_website>
|
@@ -72,52 +72,6 @@
|
|
72 |
<show_in_website>1</show_in_website>
|
73 |
<show_in_store>1</show_in_store>
|
74 |
<fields>
|
75 |
-
<coupon_code translate="label">
|
76 |
-
<label>Coupon Code</label>
|
77 |
-
<comment>A valid shopping cart price rule with this code must exists.</comment>
|
78 |
-
<sort_order>10</sort_order>
|
79 |
-
<show_in_default>1</show_in_default>
|
80 |
-
<show_in_website>1</show_in_website>
|
81 |
-
<show_in_store>1</show_in_store>
|
82 |
-
</coupon_code>
|
83 |
-
<coupon_title translate="label">
|
84 |
-
<label>Title</label>
|
85 |
-
<sort_order>20</sort_order>
|
86 |
-
<show_in_default>1</show_in_default>
|
87 |
-
<show_in_website>1</show_in_website>
|
88 |
-
<show_in_store>1</show_in_store>
|
89 |
-
</coupon_title>
|
90 |
-
<coupon_description translate="label">
|
91 |
-
<label>Description</label>
|
92 |
-
<frontend_type>textarea</frontend_type>
|
93 |
-
<sort_order>30</sort_order>
|
94 |
-
<show_in_default>1</show_in_default>
|
95 |
-
<show_in_website>1</show_in_website>
|
96 |
-
<show_in_store>1</show_in_store>
|
97 |
-
</coupon_description>
|
98 |
-
<coupon_expires_at translate="label">
|
99 |
-
<label>Coupon Expires At</label>
|
100 |
-
<sort_order>40</sort_order>
|
101 |
-
<show_in_default>1</show_in_default>
|
102 |
-
<show_in_website>1</show_in_website>
|
103 |
-
<show_in_store>1</show_in_store>
|
104 |
-
</coupon_expires_at>
|
105 |
-
<new_user_text translate="label">
|
106 |
-
<label>New User Text</label>
|
107 |
-
<frontend_type>textarea</frontend_type>
|
108 |
-
<sort_order>50</sort_order>
|
109 |
-
<show_in_default>1</show_in_default>
|
110 |
-
<show_in_website>1</show_in_website>
|
111 |
-
<show_in_store>1</show_in_store>
|
112 |
-
</new_user_text>
|
113 |
-
<bonusbox_user_text translate="label">
|
114 |
-
<label>Bonusbox User Text</label>
|
115 |
-
<frontend_type>textarea</frontend_type>
|
116 |
-
<sort_order>60</sort_order>
|
117 |
-
<show_in_default>1</show_in_default>
|
118 |
-
<show_in_website>1</show_in_website>
|
119 |
-
<show_in_store>1</show_in_store>
|
120 |
-
</bonusbox_user_text>
|
121 |
<style_url translate="label">
|
122 |
<label>Stylesheet</label>
|
123 |
<comment>Provide the path relative to your skin path (e.g. "css/bonusbox.css").</comment>
|
29 |
<label>Live Mode</label>
|
30 |
<frontend_type>select</frontend_type>
|
31 |
<source_model>adminhtml/system_config_source_yesno</source_model>
|
32 |
+
<comment>Yes = Live Mode, No = Test Mode.</comment>
|
33 |
<sort_order>20</sort_order>
|
34 |
<show_in_default>1</show_in_default>
|
35 |
<show_in_website>1</show_in_website>
|
72 |
<show_in_website>1</show_in_website>
|
73 |
<show_in_store>1</show_in_store>
|
74 |
<fields>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
<style_url translate="label">
|
76 |
<label>Stylesheet</label>
|
77 |
<comment>Provide the path relative to your skin path (e.g. "css/bonusbox.css").</comment>
|
package.xml
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>Bonusbox_Bonusbox1</name>
|
4 |
-
<version>
|
5 |
<stability>stable</stability>
|
6 |
<license uri="http://opensource.org/licenses/MIT">MIT License</license>
|
7 |
<channel>community</channel>
|
@@ -12,9 +12,9 @@
|
|
12 |
For further information, check out our homepage www.bonusbox.me.</description>
|
13 |
<notes>Loyalty programme for success pages</notes>
|
14 |
<authors><author><name>Jan Riethmayer</name><user>auto-converted</user><email>jan@bonusbox.me</email></author></authors>
|
15 |
-
<date>
|
16 |
-
<time>
|
17 |
-
<contents><target name="magecommunity"><dir name="Bonusbox"><dir name="Bonusbox"><dir name="Block"><dir name="Checkout"><file name="Success.php" hash="
|
18 |
<compatible/>
|
19 |
<dependencies/>
|
20 |
</package>
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>Bonusbox_Bonusbox1</name>
|
4 |
+
<version>1.1.0</version>
|
5 |
<stability>stable</stability>
|
6 |
<license uri="http://opensource.org/licenses/MIT">MIT License</license>
|
7 |
<channel>community</channel>
|
12 |
For further information, check out our homepage www.bonusbox.me.</description>
|
13 |
<notes>Loyalty programme for success pages</notes>
|
14 |
<authors><author><name>Jan Riethmayer</name><user>auto-converted</user><email>jan@bonusbox.me</email></author></authors>
|
15 |
+
<date>2012-01-16</date>
|
16 |
+
<time>15:56:27</time>
|
17 |
+
<contents><target name="magecommunity"><dir name="Bonusbox"><dir name="Bonusbox"><dir name="Block"><dir name="Checkout"><file name="Success.php" hash="c60b2ff6d08a990d4c2fee03dad8fd76"/></dir></dir><dir name="controllers"><file name="TestController.php" hash="c0b4a8bc94e61ad974cb2639a9f31d2e"/></dir><dir name="etc"><file name="config.xml" hash="92cf2bd374f43cf21c39104f261ad3cf"/><file name="system.xml" hash="34c55484b3db6b7df74078ff9259831a"/></dir><dir name="Helper"><file name="Data.php" hash="960efbbb590a566219933dfb7a82fd77"/><file name="Successpage.php" hash="bc389365d75932a6054df02f3359597d"/></dir><dir name="Model"><dir name="Client"><file name="Badges.php" hash="ef1b25b841ab24db961a9007de26d3a2"/><file name="Coupons.php" hash="d194a60a18c8ef5d50885de48edd5f58"/><file name="Successpages.php" hash="f90e95b81a385aa6e11ca7ece3ade63b"/></dir><dir name="Sales"><file name="Observer.php" hash="ca70bb57f270691743c9683438cda6c0"/></dir><dir name="SalesRule"><dir name="Condition"><file name="Bonusbox.php" hash="2b7fdf4bfb6e6102b4cfc5db1fa817ae"/></dir><file name="Validator.php" hash="361099ff2b3bd934cbdeef84dd631010"/></dir><file name="Client.php" hash="e6d07ee4bad0b5fd0023f1b407d9cf1f"/><file name="Session.php" hash="e577a8dc2ed9ed6ef1f32c8130c03fa8"/></dir><file name="Exception.php" hash="3816ef60762bc800941bfb975525d581"/></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="default"><dir name="default"><dir name="layout"><file name="bonusbox.xml" hash="f54448012a1ded76fba3e17626fe36da"/></dir><dir name="template"><dir name="bonusbox"><dir name="checkout"><file name="success.phtml" hash="2db7c3f9ba5bc1ba70332550c9def603"/></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Bonusbox_Bonusbox.xml" hash="924b6d17825c821f6d4e5846eba164c5"/></dir></target></contents>
|
18 |
<compatible/>
|
19 |
<dependencies/>
|
20 |
</package>
|