Version Notes
First public release.
Download this release
Release Info
Developer | Alexander Nevidimov |
Extension | Giftd_Cards |
Version | 1.0.0 |
Comparing to | |
See all releases |
Version 1.0.0
- app/code/community/Giftd/Cards/Helper/Data.php +6 -0
- app/code/community/Giftd/Cards/Model/GiftdClient.php +275 -0
- app/code/community/Giftd/Cards/Model/Observer.php +236 -0
- app/code/community/Giftd/Cards/Model/System/Config/Source/Tabposition.php +32 -0
- app/code/community/Giftd/Cards/etc/config.xml +120 -0
- app/code/community/Giftd/Cards/etc/system.xml +341 -0
- app/design/frontend/base/default/layout/giftd_panel.xml +8 -0
- app/design/frontend/base/default/template/giftd/panel.phtml +30 -0
- package.xml +28 -0
app/code/community/Giftd/Cards/Helper/Data.php
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Giftd_Cards_Helper_Data extends Mage_Core_Helper_Abstract
|
4 |
+
{
|
5 |
+
|
6 |
+
}
|
app/code/community/Giftd/Cards/Model/GiftdClient.php
ADDED
@@ -0,0 +1,275 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class GiftdClient
|
4 |
+
{
|
5 |
+
private $userId;
|
6 |
+
private $apiKey;
|
7 |
+
private $baseUrl;
|
8 |
+
|
9 |
+
const RESPONSE_TYPE_DATA = 'data';
|
10 |
+
const RESPONSE_TYPE_ERROR = 'error';
|
11 |
+
|
12 |
+
const ERROR_NETWORK_ERROR = "networkError";
|
13 |
+
const ERROR_TOKEN_NOT_FOUND = "tokenNotFound";
|
14 |
+
const ERROR_EXTERNAL_ID_NOT_FOUND = "externalIdNotFound";
|
15 |
+
const ERROR_DUPLICATE_EXTERNAL_ID = "duplicateExternalId";
|
16 |
+
const ERROR_TOKEN_ALREADY_USED = "tokenAlreadyUsed";
|
17 |
+
const ERROR_YOUR_ACCOUNT_IS_BANNED = "yourAccountIsBanned";
|
18 |
+
|
19 |
+
public function __construct($userId, $apiKey)
|
20 |
+
{
|
21 |
+
$this->userId = $userId;
|
22 |
+
$this->apiKey = $apiKey;
|
23 |
+
$this->baseUrl = (defined('DEBUG') && DEBUG) ? "https://api.giftd.local/v1/" : "https://api.giftd.ru/v1/";
|
24 |
+
}
|
25 |
+
|
26 |
+
private function httpPost($url, array $params)
|
27 |
+
{
|
28 |
+
$ch = curl_init($url);
|
29 |
+
curl_setopt_array($ch, array(
|
30 |
+
CURLOPT_POST => 1,
|
31 |
+
CURLOPT_POSTFIELDS => $params,
|
32 |
+
CURLOPT_RETURNTRANSFER => 1,
|
33 |
+
));
|
34 |
+
if (defined('DEBUG') && DEBUG) {
|
35 |
+
curl_setopt_array($ch, array(
|
36 |
+
CURLOPT_SSL_VERIFYHOST => 0,
|
37 |
+
CURLOPT_SSL_VERIFYPEER => 0,
|
38 |
+
));
|
39 |
+
}
|
40 |
+
$result = curl_exec($ch);
|
41 |
+
if (curl_errno($ch)) {
|
42 |
+
throw new Giftd_NetworkException(curl_error($ch));
|
43 |
+
}
|
44 |
+
if (!($result = json_decode($result, true))) {
|
45 |
+
throw new Giftd_Exception("Giftd API returned malformed JSON, unable to decode it");
|
46 |
+
}
|
47 |
+
return $result;
|
48 |
+
}
|
49 |
+
|
50 |
+
public function query($method, $params = array(), $suppressExceptions = false)
|
51 |
+
{
|
52 |
+
if (isset($_SERVER['REMOTE_ADDR'])) {
|
53 |
+
$params['client_ip'] = $_SERVER['REMOTE_ADDR'];
|
54 |
+
}
|
55 |
+
|
56 |
+
$params['signature'] = $this->calculateSignature($method, $params);
|
57 |
+
$params['user_id'] = $this->userId;
|
58 |
+
|
59 |
+
$result = $this->httpPost($this->baseUrl . $method, $params);
|
60 |
+
if (empty($result['type'])) {
|
61 |
+
throw new Giftd_Exception("Giftd API returned response without type field, unable to decode it");
|
62 |
+
}
|
63 |
+
if (!$suppressExceptions && $result['type'] == static::RESPONSE_TYPE_ERROR) {
|
64 |
+
$this->throwException($result);
|
65 |
+
}
|
66 |
+
return $result;
|
67 |
+
}
|
68 |
+
|
69 |
+
private function throwException(array $rawResponse)
|
70 |
+
{
|
71 |
+
throw new Giftd_Exception($rawResponse['data'], $rawResponse['code']);
|
72 |
+
}
|
73 |
+
|
74 |
+
private function constructGiftCard(array $rawData)
|
75 |
+
{
|
76 |
+
$card = new Giftd_Card();
|
77 |
+
foreach ($rawData as $key => $value) {
|
78 |
+
$card->$key = $value;
|
79 |
+
}
|
80 |
+
if ($card->charge_details) {
|
81 |
+
$chargeDetails = new Giftd_ChargeDetails();
|
82 |
+
foreach ($card->charge_details as $key => $value) {
|
83 |
+
$chargeDetails->$key = $value;
|
84 |
+
}
|
85 |
+
$card->charge_details = $chargeDetails;
|
86 |
+
}
|
87 |
+
return $card;
|
88 |
+
}
|
89 |
+
|
90 |
+
/**
|
91 |
+
* @param null $token
|
92 |
+
* @param null $external_id
|
93 |
+
* @return Giftd_Card|null
|
94 |
+
* @throws Giftd_Exception
|
95 |
+
*/
|
96 |
+
public function check($token = null, $external_id = null)
|
97 |
+
{
|
98 |
+
$response = $this->query('gift/check', array(
|
99 |
+
'token' => $token,
|
100 |
+
'external_id' => $external_id
|
101 |
+
), true);
|
102 |
+
switch ($response['type']) {
|
103 |
+
case static::RESPONSE_TYPE_ERROR:
|
104 |
+
switch ($response['code']) {
|
105 |
+
case static::ERROR_TOKEN_NOT_FOUND:
|
106 |
+
case static::ERROR_EXTERNAL_ID_NOT_FOUND:
|
107 |
+
return null;
|
108 |
+
default:
|
109 |
+
$this->throwException($response);
|
110 |
+
}
|
111 |
+
break;
|
112 |
+
case static::RESPONSE_TYPE_DATA:
|
113 |
+
return $this->constructGiftCard($response['data']);
|
114 |
+
default:
|
115 |
+
throw new Giftd_Exception("Unknown response type {$response['type']}");
|
116 |
+
}
|
117 |
+
}
|
118 |
+
|
119 |
+
/**
|
120 |
+
* @param $externalId
|
121 |
+
* @return Giftd_Card|null
|
122 |
+
* @throws Giftd_Exception
|
123 |
+
*/
|
124 |
+
public function checkByExternalId($externalId)
|
125 |
+
{
|
126 |
+
return $this->check(null, $externalId);
|
127 |
+
}
|
128 |
+
|
129 |
+
/**
|
130 |
+
* @param $token
|
131 |
+
* @return Giftd_Card|null
|
132 |
+
* @throws Giftd_Exception
|
133 |
+
*/
|
134 |
+
public function checkByToken($token)
|
135 |
+
{
|
136 |
+
return $this->check($token, null);
|
137 |
+
}
|
138 |
+
|
139 |
+
/**
|
140 |
+
* @param $token
|
141 |
+
* @param $amount
|
142 |
+
* @param null $amountTotal
|
143 |
+
* @param null $externalId
|
144 |
+
* @param null $comment
|
145 |
+
* @return Giftd_Card
|
146 |
+
* @throws Giftd_Exception
|
147 |
+
*/
|
148 |
+
public function charge($token, $amount, $amountTotal = null, $externalId = null, $comment = null)
|
149 |
+
{
|
150 |
+
$result = $this->query('gift/charge', array(
|
151 |
+
'token' => $token,
|
152 |
+
'amount' => $amount,
|
153 |
+
'amount_total' => $amountTotal,
|
154 |
+
'external_id' => $externalId,
|
155 |
+
'comment' => $comment
|
156 |
+
));
|
157 |
+
|
158 |
+
return $this->constructGiftCard($result['data']);
|
159 |
+
}
|
160 |
+
|
161 |
+
private function calculateSignature($method, array $params)
|
162 |
+
{
|
163 |
+
$signatureBase = $method . "," . $this->userId. ",";
|
164 |
+
unset($params['user_id'], $params['signature'], $params['api_key']);
|
165 |
+
ksort($params);
|
166 |
+
foreach ($params as $key => $value) {
|
167 |
+
$signatureBase .= $key . "=" . $value . ",";
|
168 |
+
}
|
169 |
+
$signatureBase .= $this->apiKey;
|
170 |
+
return sha1($signatureBase);
|
171 |
+
}
|
172 |
+
}
|
173 |
+
|
174 |
+
/**
|
175 |
+
* @property integer $id
|
176 |
+
* @property string $status
|
177 |
+
* @property string $status_str
|
178 |
+
* @property float $amount_available
|
179 |
+
* @property integer $card_id,
|
180 |
+
* @property string $card_title
|
181 |
+
* @property string $owner_owner_name
|
182 |
+
* @property string $owner_gender
|
183 |
+
* @property bool $amount_total_required
|
184 |
+
* @property float|null $min_amount_total
|
185 |
+
* @property string $charge_type
|
186 |
+
* @property integer $created
|
187 |
+
* @property integer $expires
|
188 |
+
* @property string $token_status
|
189 |
+
* @property Giftd_ChargeDetails|null $charge_details
|
190 |
+
*/
|
191 |
+
class Giftd_Card
|
192 |
+
{
|
193 |
+
const CHARGE_TYPE_ONETIME = 'onetime';
|
194 |
+
const CHARGE_TYPE_MULTIPLE = 'multiple';
|
195 |
+
|
196 |
+
const TOKEN_STATUS_OK = 'ok';
|
197 |
+
const TOKEN_STATUS_USED = 'used';
|
198 |
+
|
199 |
+
public $id;
|
200 |
+
public $status;
|
201 |
+
public $status_str;
|
202 |
+
public $amount_available;
|
203 |
+
public $card_id;
|
204 |
+
public $card_title;
|
205 |
+
public $owner_name;
|
206 |
+
public $owner_gender;
|
207 |
+
public $amount_total_required;
|
208 |
+
public $min_amount_total;
|
209 |
+
public $charge_type;
|
210 |
+
public $created;
|
211 |
+
public $expires;
|
212 |
+
public $token_status;
|
213 |
+
public $charge_details;
|
214 |
+
}
|
215 |
+
|
216 |
+
/**
|
217 |
+
* @property string $token
|
218 |
+
* @property string $external_id
|
219 |
+
* @property integer $time
|
220 |
+
* @property float $amount
|
221 |
+
* @property float $amount_total
|
222 |
+
* @property float $amount_left
|
223 |
+
* @property string $type
|
224 |
+
* @property string $comment
|
225 |
+
*/
|
226 |
+
class Giftd_ChargeDetails
|
227 |
+
{
|
228 |
+
const TYPE_MANUAL = 'manual';
|
229 |
+
const TYPE_API = 'api';
|
230 |
+
|
231 |
+
public $token;
|
232 |
+
public $external_id;
|
233 |
+
public $time;
|
234 |
+
public $amount;
|
235 |
+
public $amount_total;
|
236 |
+
public $amount_left;
|
237 |
+
public $type;
|
238 |
+
public $comment;
|
239 |
+
}
|
240 |
+
|
241 |
+
class Giftd_Exception extends Exception
|
242 |
+
{
|
243 |
+
public $code;
|
244 |
+
public $data;
|
245 |
+
|
246 |
+
protected function _stringifyData($data)
|
247 |
+
{
|
248 |
+
if (!is_array($data)) {
|
249 |
+
return $data;
|
250 |
+
}
|
251 |
+
$result = array();
|
252 |
+
foreach ($data as $key => $value)
|
253 |
+
{
|
254 |
+
if (is_array($value)) {
|
255 |
+
$result[] = implode(", ", $value);
|
256 |
+
} else {
|
257 |
+
$result[] = $value;
|
258 |
+
}
|
259 |
+
}
|
260 |
+
return implode(", ", $result);
|
261 |
+
}
|
262 |
+
|
263 |
+
public function __construct($data, $code = null)
|
264 |
+
{
|
265 |
+
parent::__construct($this->_stringifyData($data));
|
266 |
+
$this->code = $code;
|
267 |
+
$this->data = $data;
|
268 |
+
}
|
269 |
+
}
|
270 |
+
|
271 |
+
class Giftd_NetworkException extends Giftd_Exception
|
272 |
+
{
|
273 |
+
|
274 |
+
}
|
275 |
+
?>
|
app/code/community/Giftd/Cards/Model/Observer.php
ADDED
@@ -0,0 +1,236 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
require_once('GiftdClient.php');
|
4 |
+
|
5 |
+
class Giftd_Cards_Model_Observer
|
6 |
+
{
|
7 |
+
/**
|
8 |
+
* @var GiftdClient $client
|
9 |
+
*/
|
10 |
+
protected $client = false;
|
11 |
+
|
12 |
+
public function init($force=false)
|
13 |
+
{
|
14 |
+
if($this->client && !$force)
|
15 |
+
return true;
|
16 |
+
|
17 |
+
$api_key = Mage::getStoreConfig('giftd_cards/api_settings/api_key',Mage::app()->getStore());
|
18 |
+
$user_id = Mage::getStoreConfig('giftd_cards/api_settings/user_id',Mage::app()->getStore());
|
19 |
+
|
20 |
+
if(strlen($api_key) > 0 && strlen($user_id) > 0)
|
21 |
+
{
|
22 |
+
$this->client = new GiftdClient($user_id, $api_key);
|
23 |
+
return true;
|
24 |
+
}
|
25 |
+
|
26 |
+
return false;
|
27 |
+
}
|
28 |
+
|
29 |
+
public function getStoreInfo()
|
30 |
+
{
|
31 |
+
$schema = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') ? 'https' : 'http';
|
32 |
+
|
33 |
+
$host = (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME']);
|
34 |
+
if (count($hostParts = explode(":", $host)) > 1) {
|
35 |
+
$port = $hostParts[1];
|
36 |
+
if ($port == 80 || $port == 443) {
|
37 |
+
$host = $hostParts[0];
|
38 |
+
}
|
39 |
+
}
|
40 |
+
$url = "$schema://$host";
|
41 |
+
|
42 |
+
$userId = Mage::getSingleton('admin/session')->getUser()->getId();
|
43 |
+
$user = Mage::getModel('admin/user')->load($userId);
|
44 |
+
|
45 |
+
$name = trim($user->getData('firstname').' '.$user->getData('lastname'));
|
46 |
+
|
47 |
+
$result = array(
|
48 |
+
'email' => $user->getData('email'),
|
49 |
+
'url' => $url,
|
50 |
+
'magento_version' => Mage::getVersion()
|
51 |
+
);
|
52 |
+
if ($name) {
|
53 |
+
$result['name'] = $name;
|
54 |
+
}
|
55 |
+
return $result;
|
56 |
+
}
|
57 |
+
|
58 |
+
public function updateApiKey(Varien_Event_Observer $observer)
|
59 |
+
{
|
60 |
+
//kk: do check if api_key or user_id values has changed
|
61 |
+
if(self::init())
|
62 |
+
{
|
63 |
+
$config = new Mage_Core_Model_Config();
|
64 |
+
|
65 |
+
$this->client->query('magento/install', $this->getStoreInfo());
|
66 |
+
Mage::log('Sent store data to Giftd');
|
67 |
+
|
68 |
+
$response = $this->client->query('partner/get');
|
69 |
+
if($response['type'] == 'data') {
|
70 |
+
$config->saveConfig('giftd_cards/api_settings/partner_token', $response['data']['code'], 'default', 0);
|
71 |
+
$config->saveConfig('giftd_cards/api_settings/partner_token_prefix', $response['data']['token_prefix'], 'default', 0);
|
72 |
+
}
|
73 |
+
}
|
74 |
+
}
|
75 |
+
|
76 |
+
public function showMinimumSubtotalError($limit)
|
77 |
+
{
|
78 |
+
|
79 |
+
switch (Mage::app()->getLocale()->getLocaleCode()) {
|
80 |
+
case 'ru_RU':
|
81 |
+
$message = "Для использования этой подарочной карты общая сумма должна быть не менее %s";
|
82 |
+
break;
|
83 |
+
case 'de_DE':
|
84 |
+
$message = "Um diese Geschenkkarte nutzen die Zwischensumme sollte mindestens %s";
|
85 |
+
break;
|
86 |
+
default:
|
87 |
+
$message = "To use this gift card the subtotal should be at least %s";
|
88 |
+
break;
|
89 |
+
}
|
90 |
+
$formattedLimit = Mage::helper('core')->currency($limit, true, false);
|
91 |
+
|
92 |
+
Mage::getSingleton('checkout/session')->addError(sprintf($message, $formattedLimit));
|
93 |
+
}
|
94 |
+
|
95 |
+
public function checkoutCoupon(Varien_Event_Observer $observer)
|
96 |
+
{
|
97 |
+
if(self::init())
|
98 |
+
{
|
99 |
+
$quote = Mage::helper('checkout/cart')->getQuote();
|
100 |
+
if ($coupon_code = $quote->getCouponCode())
|
101 |
+
{
|
102 |
+
if($card = self::getGiftdCard($coupon_code))
|
103 |
+
{
|
104 |
+
$subtotal = $quote->getSubtotal();
|
105 |
+
$order_id = $observer->getEvent()->getOrder()->getId();
|
106 |
+
$visitor = Mage::getSingleton('core/session')->getVisitorData();
|
107 |
+
|
108 |
+
try
|
109 |
+
{
|
110 |
+
$this->client->charge($coupon_code, $card->amount_available, $subtotal, $visitor['visitor_id'].'_'.$visitor['quote_id'].'_'.$order_id);
|
111 |
+
Mage::log('coupon charged - code:'.$coupon_code.' amount:'.$card->amount_available.' subtotal:'.$subtotal.' id:'.$visitor['visitor_id'].'_'.$visitor['quote_id'].'_'.$order_id);
|
112 |
+
|
113 |
+
}
|
114 |
+
catch(Exception $e)
|
115 |
+
{
|
116 |
+
//KK: how should we handle such situations?
|
117 |
+
Mage::logException($e);
|
118 |
+
}
|
119 |
+
|
120 |
+
}
|
121 |
+
}
|
122 |
+
}
|
123 |
+
}
|
124 |
+
|
125 |
+
|
126 |
+
public function processCoupon(Varien_Event_Observer $observer)
|
127 |
+
{
|
128 |
+
if($_REQUEST['remove'] == 1)
|
129 |
+
return;
|
130 |
+
|
131 |
+
$coupon_code = trim($_REQUEST['coupon_code']);
|
132 |
+
$subTotal = Mage::helper('checkout/cart')->getQuote()->getSubtotal();
|
133 |
+
|
134 |
+
$existedCoupon = Mage::getModel('salesrule/coupon')->load($coupon_code, 'code');
|
135 |
+
$rule = $existedCoupon->getRuleId() ? Mage::getModel('salesrule/rule')->load($existedCoupon->getRuleId()) : false;
|
136 |
+
if($rule)
|
137 |
+
{
|
138 |
+
if(strpos($rule->getData('name'), 'Giftd') === 0 && self::init())
|
139 |
+
{
|
140 |
+
if($card = self::getGiftdCard($coupon_code))
|
141 |
+
{
|
142 |
+
if($card->min_amount_total > $subTotal)
|
143 |
+
$this->showMinimumSubtotalError($card->min_amount_total);
|
144 |
+
}
|
145 |
+
}
|
146 |
+
return;
|
147 |
+
}
|
148 |
+
|
149 |
+
if(self::init())
|
150 |
+
{
|
151 |
+
if($card = self::getGiftdCard($coupon_code))
|
152 |
+
{
|
153 |
+
$coupon_value = $card->amount_available;
|
154 |
+
if ($card->min_amount_total > $subTotal)
|
155 |
+
{
|
156 |
+
$this->showMinimumSubtotalError($card->min_amount_total);
|
157 |
+
}
|
158 |
+
self::generateRule("Giftd card", $coupon_code, $coupon_value, $card->min_amount_total);
|
159 |
+
}
|
160 |
+
}
|
161 |
+
}
|
162 |
+
|
163 |
+
public function getGiftdCard($the_coupon_code)
|
164 |
+
{
|
165 |
+
$the_coupon_code = trim($the_coupon_code);
|
166 |
+
$prefix = trim(Mage::getStoreConfig('giftd_cards/api_settings/partner_token_prefix',Mage::app()->getStore()));
|
167 |
+
if($this->client && strlen($the_coupon_code) > 0 && (!$prefix || strpos($the_coupon_code, $prefix) === 0))
|
168 |
+
{
|
169 |
+
$card = $this->client->checkByToken($the_coupon_code);
|
170 |
+
if($card && $card->token_status == Giftd_Card::TOKEN_STATUS_OK)
|
171 |
+
{
|
172 |
+
return $card;
|
173 |
+
}
|
174 |
+
}
|
175 |
+
|
176 |
+
return false;
|
177 |
+
}
|
178 |
+
|
179 |
+
public function generateRule($name, $coupon_code, $discount, $min_amount)
|
180 |
+
{
|
181 |
+
if ($name != null && $coupon_code != null)
|
182 |
+
{
|
183 |
+
$data = array(
|
184 |
+
'product_ids' => null,
|
185 |
+
'name' => $name,
|
186 |
+
'description' => null,
|
187 |
+
'is_active' => 1,
|
188 |
+
'website_ids' => array(1),
|
189 |
+
'customer_group_ids' => array(0,1,2,4,5),
|
190 |
+
'coupon_type' => 2,
|
191 |
+
'coupon_code' => $coupon_code,
|
192 |
+
'uses_per_coupon' => 1,
|
193 |
+
'uses_per_customer' => 1,
|
194 |
+
'from_date' => null,
|
195 |
+
'to_date' => null,
|
196 |
+
'sort_order' => null,
|
197 |
+
'is_rss' => 0,
|
198 |
+
'conditions' => array(
|
199 |
+
"1" => array(
|
200 |
+
"type" => "salesrule/rule_condition_combine",
|
201 |
+
"aggregator" => "all",
|
202 |
+
"value" => "1",
|
203 |
+
"new_child" => null
|
204 |
+
),
|
205 |
+
"1--1" => array(
|
206 |
+
"type" => "salesrule/rule_condition_address",
|
207 |
+
"attribute" => "base_subtotal",
|
208 |
+
"operator" => ">=",
|
209 |
+
"value" => $min_amount
|
210 |
+
)
|
211 |
+
),
|
212 |
+
'simple_action' => 'cart_fixed',
|
213 |
+
'discount_amount' => $discount,
|
214 |
+
'discount_qty' => 0,
|
215 |
+
'discount_step' => null,
|
216 |
+
'apply_to_shipping' => 0,
|
217 |
+
'simple_free_shipping' => 0,
|
218 |
+
'stop_rules_processing' => 0,
|
219 |
+
'store_labels' => array($name)
|
220 |
+
);
|
221 |
+
|
222 |
+
$model = Mage::getModel('salesrule/rule');
|
223 |
+
$validateResult = $model->validateData(new Varien_Object($data));
|
224 |
+
|
225 |
+
if ($validateResult == true)
|
226 |
+
{
|
227 |
+
try {
|
228 |
+
$model->loadPost($data);
|
229 |
+
$model->save();
|
230 |
+
} catch (Exception $e) {
|
231 |
+
Mage::log($e->getMessage());
|
232 |
+
}
|
233 |
+
}
|
234 |
+
}
|
235 |
+
}
|
236 |
+
}
|
app/code/community/Giftd/Cards/Model/System/Config/Source/Tabposition.php
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Giftd_Cards_Model_System_Config_Source_Tabposition
|
4 |
+
{
|
5 |
+
/**
|
6 |
+
* Options getter
|
7 |
+
*
|
8 |
+
* @return array
|
9 |
+
*/
|
10 |
+
public function toOptionArray()
|
11 |
+
{
|
12 |
+
return array(
|
13 |
+
array('value' => 'top', 'label'=>Mage::helper('adminhtml')->__('Top ')),
|
14 |
+
array('value' => 'left', 'label'=>Mage::helper('adminhtml')->__('Left')),
|
15 |
+
array('value' => 'bottom', 'label'=>Mage::helper('adminhtml')->__('Bottom ')),
|
16 |
+
);
|
17 |
+
}
|
18 |
+
|
19 |
+
/**
|
20 |
+
* Get options in "key-value" format
|
21 |
+
*
|
22 |
+
* @return array
|
23 |
+
*/
|
24 |
+
public function toArray()
|
25 |
+
{
|
26 |
+
return array(
|
27 |
+
'top' => Mage::helper('adminhtml')->__('Top'),
|
28 |
+
'left' => Mage::helper('adminhtml')->__('Left'),
|
29 |
+
'bottom' => Mage::helper('adminhtml')->__('Bottom'),
|
30 |
+
);
|
31 |
+
}
|
32 |
+
}
|
app/code/community/Giftd/Cards/etc/config.xml
ADDED
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<Giftd_Cards>
|
5 |
+
<version>1.0.0</version>
|
6 |
+
</Giftd_Cards>
|
7 |
+
</modules>
|
8 |
+
|
9 |
+
<global>
|
10 |
+
<helpers>
|
11 |
+
<giftd_cards>
|
12 |
+
<!-- This is where we define our helper directory -->
|
13 |
+
<class>Giftd_Cards_Helper</class>
|
14 |
+
</giftd_cards>
|
15 |
+
</helpers>
|
16 |
+
|
17 |
+
<models>
|
18 |
+
<giftd_cards>
|
19 |
+
<!-- This is where we define our model directory -->
|
20 |
+
<class>Giftd_Cards_Model</class>
|
21 |
+
</giftd_cards>
|
22 |
+
</models>
|
23 |
+
|
24 |
+
<blocks>
|
25 |
+
<giftd_cards><class>Giftd_Cards_Block</class></giftd_cards>
|
26 |
+
</blocks>
|
27 |
+
|
28 |
+
<!-- And finally we define our resource setup script -->
|
29 |
+
<resources>
|
30 |
+
<giftd_cards_setup>
|
31 |
+
<setup>
|
32 |
+
<module>Giftd_Cards</module>
|
33 |
+
</setup>
|
34 |
+
</giftd_cards_setup>
|
35 |
+
</resources>
|
36 |
+
|
37 |
+
<events>
|
38 |
+
<admin_system_config_changed_section_giftd_cards>
|
39 |
+
<observers>
|
40 |
+
<giftd_cards>
|
41 |
+
<class>giftd_cards/observer</class>
|
42 |
+
<method>updateApiKey</method>
|
43 |
+
<type>singleton</type>
|
44 |
+
</giftd_cards>
|
45 |
+
</observers>
|
46 |
+
</admin_system_config_changed_section_giftd_cards>
|
47 |
+
<controller_action_predispatch_checkout_cart_couponPost>
|
48 |
+
<observers>
|
49 |
+
<giftd_cards>
|
50 |
+
<class>giftd_cards/observer</class>
|
51 |
+
<method>processCoupon</method>
|
52 |
+
<type>singleton</type>
|
53 |
+
</giftd_cards>
|
54 |
+
</observers>
|
55 |
+
</controller_action_predispatch_checkout_cart_couponPost>
|
56 |
+
<sales_order_place_after>
|
57 |
+
<observers>
|
58 |
+
<giftd_cards>
|
59 |
+
<class>giftd_cards/observer</class>
|
60 |
+
<method>checkoutCoupon</method>
|
61 |
+
<type>singleton</type>
|
62 |
+
</giftd_cards>
|
63 |
+
</observers>
|
64 |
+
</sales_order_place_after>
|
65 |
+
</events>
|
66 |
+
</global>
|
67 |
+
|
68 |
+
<frontend>
|
69 |
+
<layout>
|
70 |
+
<updates>
|
71 |
+
<giftd_cards module="giftd_cards">
|
72 |
+
<file>giftd_panel.xml</file>
|
73 |
+
</giftd_cards>
|
74 |
+
</updates>
|
75 |
+
</layout>
|
76 |
+
</frontend>
|
77 |
+
|
78 |
+
<adminhtml>
|
79 |
+
<layout>
|
80 |
+
<updates>
|
81 |
+
<giftd_cards>
|
82 |
+
<file>giftd_cards.xml</file>
|
83 |
+
</giftd_cards>
|
84 |
+
</updates>
|
85 |
+
</layout>
|
86 |
+
<acl>
|
87 |
+
<resources>
|
88 |
+
<admin>
|
89 |
+
<children>
|
90 |
+
<system>
|
91 |
+
<children>
|
92 |
+
<config>
|
93 |
+
<children>
|
94 |
+
<giftd_cards translate="title" module="giftd_cards">
|
95 |
+
<title>Giftd Cards Settings</title>
|
96 |
+
</giftd_cards>
|
97 |
+
</children>
|
98 |
+
</config>
|
99 |
+
</children>
|
100 |
+
</system>
|
101 |
+
</children>
|
102 |
+
</admin>
|
103 |
+
</resources>
|
104 |
+
</acl>
|
105 |
+
</adminhtml>
|
106 |
+
|
107 |
+
<admin>
|
108 |
+
<routers>
|
109 |
+
<adminhtml>
|
110 |
+
<args>
|
111 |
+
<!-- This is how we load our Adminhtml controllers -->
|
112 |
+
<modules>
|
113 |
+
<Giftd_Cards before="Mage_Adminhtml">Giftd_Cards_Adminhtml</Giftd_Cards>
|
114 |
+
</modules>
|
115 |
+
</args>
|
116 |
+
</adminhtml>
|
117 |
+
</routers>
|
118 |
+
</admin>
|
119 |
+
|
120 |
+
</config>
|
app/code/community/Giftd/Cards/etc/system.xml
ADDED
@@ -0,0 +1,341 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<sections>
|
4 |
+
<giftd_cards translate="label" module="giftd_cards">
|
5 |
+
<label>Giftd Cards</label>
|
6 |
+
<tab>sales</tab>
|
7 |
+
<frontend_type>text</frontend_type>
|
8 |
+
<sort_order>991</sort_order>
|
9 |
+
<show_in_default>1</show_in_default>
|
10 |
+
<show_in_website>1</show_in_website>
|
11 |
+
<show_in_store>1</show_in_store>
|
12 |
+
<groups>
|
13 |
+
<api_settings translate="label">
|
14 |
+
<label>Giftd API Settings</label>
|
15 |
+
<frontend_type>text</frontend_type>
|
16 |
+
<sort_order>1</sort_order>
|
17 |
+
<show_in_default>1</show_in_default>
|
18 |
+
<show_in_website>1</show_in_website>
|
19 |
+
<show_in_store>1</show_in_store>
|
20 |
+
<comment>
|
21 |
+
<![CDATA[
|
22 |
+
Access for API (<a id="SIGN_IN" href="https://partner.giftd.ru/site/login?popup=1" onclick="SignIn(this);return false;">Get API access settings</a>)
|
23 |
+
<script type="text/javascript">
|
24 |
+
var popup = null;
|
25 |
+
function openWindow(options) {
|
26 |
+
var
|
27 |
+
screenX = typeof window.screenX != 'undefined' ? window.screenX : window.screenLeft,
|
28 |
+
screenY = typeof window.screenY != 'undefined' ? window.screenY : window.screenTop,
|
29 |
+
outerWidth = typeof window.outerWidth != 'undefined' ? window.outerWidth : document.body.clientWidth,
|
30 |
+
outerHeight = typeof window.outerHeight != 'undefined' ? window.outerHeight : (document.body.clientHeight - 22),
|
31 |
+
width = options.width,
|
32 |
+
height = options.height,
|
33 |
+
left = parseInt(screenX + ((outerWidth - width) / 2), 10),
|
34 |
+
top = parseInt(screenY + ((outerHeight - height) / 2.5), 10),
|
35 |
+
features = (
|
36 |
+
'width=' + width +
|
37 |
+
',height=' + height +
|
38 |
+
',left=' + left +
|
39 |
+
',top=' + top
|
40 |
+
);
|
41 |
+
popup = window.open(options.url, 'giftd_auth_' + new Date().getTime(), features);
|
42 |
+
}
|
43 |
+
|
44 |
+
function update_api_key(user_id, api_key)
|
45 |
+
{
|
46 |
+
giftd_cards_api_settings_api_key.value = api_key;
|
47 |
+
giftd_cards_api_settings_user_id.value = user_id;
|
48 |
+
configForm.submit();
|
49 |
+
}
|
50 |
+
|
51 |
+
function SignIn(a){
|
52 |
+
openWindow({
|
53 |
+
width: 520,
|
54 |
+
height: 453,
|
55 |
+
url: a.href
|
56 |
+
});
|
57 |
+
|
58 |
+
AwaitResponse();
|
59 |
+
}
|
60 |
+
|
61 |
+
function AwaitResponse() {
|
62 |
+
if (window.addEventListener) { // all browsers except IE before version 9
|
63 |
+
window.addEventListener ("message", OnMessage, false);
|
64 |
+
}
|
65 |
+
else {
|
66 |
+
if (window.attachEvent) { // IE before version 9
|
67 |
+
window.attachEvent("onmessage", OnMessage);
|
68 |
+
}
|
69 |
+
}
|
70 |
+
}
|
71 |
+
|
72 |
+
function OnMessage (message) {
|
73 |
+
var rawMessage = message.data || message.originalEvent.data;
|
74 |
+
console.log(rawMessage);
|
75 |
+
if (typeof(rawMessage) == 'string' && rawMessage.indexOf("giftd/auth") === 0) {
|
76 |
+
var message = JSON.parse(rawMessage.split("~", 2)[1]);
|
77 |
+
console.log(message);
|
78 |
+
switch (message.type) {
|
79 |
+
case 'error':
|
80 |
+
alert(message.data);
|
81 |
+
break;
|
82 |
+
case 'data':
|
83 |
+
update_api_key(message.data.user_id, message.data.api_key);
|
84 |
+
break;
|
85 |
+
default:
|
86 |
+
break;
|
87 |
+
}
|
88 |
+
popup.close();
|
89 |
+
}
|
90 |
+
}
|
91 |
+
</script>
|
92 |
+
]]>
|
93 |
+
</comment>
|
94 |
+
<fields>
|
95 |
+
<api_key translate="label comment">
|
96 |
+
<label>API Key</label>
|
97 |
+
<comment></comment>
|
98 |
+
<frontend_type>text</frontend_type>
|
99 |
+
<sort_order>1</sort_order>
|
100 |
+
<show_in_default>1</show_in_default>
|
101 |
+
<show_in_website>1</show_in_website>
|
102 |
+
<show_in_store>1</show_in_store>
|
103 |
+
</api_key>
|
104 |
+
<user_id translate="label comment">
|
105 |
+
<label>User ID</label>
|
106 |
+
<comment></comment>
|
107 |
+
<frontend_type>text</frontend_type>
|
108 |
+
<sort_order>2</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 |
+
</user_id>
|
113 |
+
<partner_token translate="label comment">
|
114 |
+
<label>Partner Token</label>
|
115 |
+
<comment></comment>
|
116 |
+
<frontend_type>text</frontend_type>
|
117 |
+
<sort_order>3</sort_order>
|
118 |
+
<show_in_default>1</show_in_default>
|
119 |
+
<show_in_website>1</show_in_website>
|
120 |
+
<show_in_store>1</show_in_store>
|
121 |
+
</partner_token>
|
122 |
+
<partner_token_prefix translate="label comment">
|
123 |
+
<label>Partner Token Prefix</label>
|
124 |
+
<comment></comment>
|
125 |
+
<frontend_type>text</frontend_type>
|
126 |
+
<sort_order>4</sort_order>
|
127 |
+
<show_in_default>1</show_in_default>
|
128 |
+
<show_in_website>1</show_in_website>
|
129 |
+
<show_in_store>1</show_in_store>
|
130 |
+
</partner_token_prefix>
|
131 |
+
<sent_on_install translate="label comment">
|
132 |
+
<label>Has installed</label>
|
133 |
+
<comment><![CDATA[
|
134 |
+
<script>
|
135 |
+
row_giftd_cards_api_settings_sent_on_install.style.display = "none";
|
136 |
+
</script>
|
137 |
+
]]></comment>
|
138 |
+
<frontend_type>text</frontend_type>
|
139 |
+
<sort_order>5</sort_order>
|
140 |
+
<show_in_default>1</show_in_default>
|
141 |
+
<show_in_website>1</show_in_website>
|
142 |
+
<show_in_store>1</show_in_store>
|
143 |
+
</sent_on_install>
|
144 |
+
</fields>
|
145 |
+
</api_settings>
|
146 |
+
<panel_settings translate="label">
|
147 |
+
<label>Giftd Panel Settings</label>
|
148 |
+
<frontend_type>text</frontend_type>
|
149 |
+
<sort_order>2</sort_order>
|
150 |
+
<show_in_default>1</show_in_default>
|
151 |
+
<show_in_website>1</show_in_website>
|
152 |
+
<show_in_store>1</show_in_store>
|
153 |
+
<comment></comment>
|
154 |
+
<fields>
|
155 |
+
<panel_is_active translate="label comment">
|
156 |
+
<label>Отображать на сайте графический блок Giftd</label>
|
157 |
+
<comment><![CDATA[
|
158 |
+
<script type="text/javascript">
|
159 |
+
function updatePanelSettings()
|
160 |
+
{
|
161 |
+
var is_active = giftd_cards_panel_settings_panel_is_active.value == 1;
|
162 |
+
var display = is_active ? "table-row" : "none";
|
163 |
+
|
164 |
+
giftd_cards_panel_settings.getElementsBySelector('tr').each(function(row){
|
165 |
+
if(row != row_giftd_cards_panel_settings_panel_is_active)
|
166 |
+
row.style.display = display;
|
167 |
+
|
168 |
+
console.log(row);
|
169 |
+
});
|
170 |
+
}
|
171 |
+
|
172 |
+
window.addEventListener('load',
|
173 |
+
function() {
|
174 |
+
giftd_cards_panel_settings_panel_is_active.onchange = updatePanelSettings;
|
175 |
+
updatePanelSettings();
|
176 |
+
}, false );
|
177 |
+
|
178 |
+
</script>
|
179 |
+
]]></comment>
|
180 |
+
<frontend_type>select</frontend_type>
|
181 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
182 |
+
<sort_order>1</sort_order>
|
183 |
+
<show_in_default>1</show_in_default>
|
184 |
+
<show_in_website>1</show_in_website>
|
185 |
+
<show_in_store>1</show_in_store>
|
186 |
+
</panel_is_active>
|
187 |
+
<panel_position translate="label comment">
|
188 |
+
<label>Местоположение вкладки Giftd</label>
|
189 |
+
<comment><![CDATA[<img src="https://partner.giftd.ru/img/embedded_tab_screenshot.png" style="width: 267px;margin-top: 5px;">]]></comment>
|
190 |
+
<frontend_type>select</frontend_type>
|
191 |
+
<source_model>giftd_cards/system_config_source_tabposition</source_model>
|
192 |
+
<sort_order>2</sort_order>
|
193 |
+
<show_in_default>1</show_in_default>
|
194 |
+
<show_in_website>1</show_in_website>
|
195 |
+
<show_in_store>1</show_in_store>
|
196 |
+
</panel_position>
|
197 |
+
</fields>
|
198 |
+
</panel_settings>
|
199 |
+
|
200 |
+
<tab_settings translate="label">
|
201 |
+
<label>Giftd Tab Settings</label>
|
202 |
+
<frontend_type>text</frontend_type>
|
203 |
+
<sort_order>3</sort_order>
|
204 |
+
<show_in_default>1</show_in_default>
|
205 |
+
<show_in_website>1</show_in_website>
|
206 |
+
<show_in_store>1</show_in_store>
|
207 |
+
<comment><![CDATA[]]></comment>
|
208 |
+
<fields>
|
209 |
+
<custom_code_is_active translate="label comment">
|
210 |
+
<label>Настроить внешний вид графическиго блока Giftd</label>
|
211 |
+
<comment><![CDATA[
|
212 |
+
<script type="text/javascript">
|
213 |
+
function updateTabSettings()
|
214 |
+
{
|
215 |
+
var is_active = giftd_cards_tab_settings_custom_code_is_active.value == 1;
|
216 |
+
var display = is_active ? "table-row" : "none";
|
217 |
+
|
218 |
+
giftd_cards_tab_settings.getElementsBySelector('tr').each(function(row){
|
219 |
+
if(row != row_giftd_cards_tab_settings_custom_code_is_active)
|
220 |
+
row.style.display = display;
|
221 |
+
});
|
222 |
+
}
|
223 |
+
|
224 |
+
window.addEventListener('load',
|
225 |
+
function() {
|
226 |
+
giftd_cards_tab_settings_custom_code_is_active.onchange = updateTabSettings;
|
227 |
+
updateTabSettings();
|
228 |
+
}, false );
|
229 |
+
|
230 |
+
</script>
|
231 |
+
]]></comment>
|
232 |
+
<frontend_type>select</frontend_type>
|
233 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
234 |
+
<sort_order>1</sort_order>
|
235 |
+
<show_in_default>1</show_in_default>
|
236 |
+
<show_in_website>1</show_in_website>
|
237 |
+
<show_in_store>1</show_in_store>
|
238 |
+
</custom_code_is_active>
|
239 |
+
<custom_code_info translate="label comment">
|
240 |
+
<label></label>
|
241 |
+
<comment><![CDATA[
|
242 |
+
<p>
|
243 |
+
Ниже вы можете отредактировать JS-код, который встраивается на ваш сайт.
|
244 |
+
В этом коде есть ряд переменных, которые вы можете изменить — <b>цвета надписей, фоновые цвета и изображения</b>.
|
245 |
+
</p>
|
246 |
+
<p>
|
247 |
+
Это образец кода, в котором всем возможным переменным заданы значения — эти значения приводят цвета и изобажения вкладки Giftd в состояние "по умолчанию":
|
248 |
+
</p>
|
249 |
+
<style>
|
250 |
+
pre.giftd-code {
|
251 |
+
background-color: ghostwhite;
|
252 |
+
border: 1px solid silver;
|
253 |
+
padding: 10px 20px;
|
254 |
+
margin: 20px;
|
255 |
+
max-width: 600px;
|
256 |
+
overflow: scroll;;
|
257 |
+
|
258 |
+
}
|
259 |
+
.giftd-code .json-key {
|
260 |
+
color: brown;
|
261 |
+
}
|
262 |
+
.giftd-code .json-value {
|
263 |
+
color: navy;
|
264 |
+
}
|
265 |
+
.giftd-code .json-string {
|
266 |
+
color: olive;
|
267 |
+
}
|
268 |
+
.giftd-code textarea {
|
269 |
+
width: 600px;
|
270 |
+
height: 365px;
|
271 |
+
font-family: courier, monospace;
|
272 |
+
font-size: 12px;
|
273 |
+
line-height: 15px;
|
274 |
+
white-space: nowrap;
|
275 |
+
overflow: auto;
|
276 |
+
}
|
277 |
+
|
278 |
+
ul.bullets {
|
279 |
+
list-style-type: disc;
|
280 |
+
margin-left: 20px;
|
281 |
+
}
|
282 |
+
</style>
|
283 |
+
|
284 |
+
<pre class="giftd-code"><code><span class="json-key">window.giftdOptions</span> = {
|
285 |
+
<span class="json-key">pid</span>: <span class="json-string">"<?php echo GiftdHelper::GetOption('PARTNER_CODE') ?>"</span>,
|
286 |
+
<span class="json-key">tab</span>: {
|
287 |
+
<span class="json-key">enabled</span>: <span class="json-value">true</span>,
|
288 |
+
<span class="json-key">position</span>: <span class="json-string">"left"</span>,
|
289 |
+
<span class="json-key">panelBg</span>: {
|
290 |
+
<span class="json-key">color</span>: <span class="json-string">"#008ede"</span>,
|
291 |
+
<span class="json-key">image</span>: <span class="json-string">"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAwCAYAAADQMxCBAAAAVklEQVQIHW2OUQ6AMAhDCSfz2DvbhOJgDDSRr5aWF+gaMKY1rAClUiOGLXu7ylTfdopkMPWcocr7wgGhAOdRob69qEhRwu5dPdS7fjIrB9qVUPrD8+ABBOQ3zPy6HCkAAAAASUVORK5CYII="</span>
|
292 |
+
},
|
293 |
+
<span class="json-key">panelDecor</span>: {
|
294 |
+
<span class="json-key">top</span>: <span class="json-string">"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADsAAAAxCAMAAABTYCHnAAAAwFBMVEUAAAAAAQEAAQEAAQEAAQEAAQEAAQEAAQEAAQEAAQEAAQEAAQHO3usAAQEAAQEAAQHkge3A1eaouca80N/D1+enusnZ5e+0w87V4+79/f3kge3O3uv5+vze6fLTfuj6+/y7ytbIcdC2z+LTd9vL3OrpmfHvt/T79Pz8+PzG2OjhgOzFddm9a8X67PvKfeTxvvW+0uP00Pfnje/lhe7spfLB1ubN3eu/1OWzxdSrwNHy9vn33fnzyvbZe+LtrfPWed+d0tzIAAAAGXRSTlMANSM5KRIDGgwHPDFmHxYvRGaqF0m22bXy9/6YcAAAAZxJREFUSMfl1l1XgjAcBnBQQEzASnsZYqkgmIn4Vim+9P2/Vftv1RyE4+yCm54bOJzzO3C2sT2KohjNpqk7Ddu2a3fbEU4vRT/x+k8uDsomve8oQA1Ka5p2uwMaICSwkMdfS2ib0FFayqZdbDE1HUzbLZVaj7dH3/fjQ5gsIx7fUKs7tqa1VHW3gPD2dTabHV3IOpzkLXyy1lbV+u4DkrXDqfudcfSXreHX1q+2b5CsJZRmc8G+QDL20z3LUmCfeUu/NhzTa7ENILydA0nw7YlgNlwWbwfM5uc3JjYutO+QAjsRvLcHKbAHuFkhGRut4CaUsiFZWpGMjdd0emXsBi4nJGP3ZKAiKUtW1R7J2ISOsZSFjCcXrU/inmU6x7Yg15wdkvwfKz9W4jmqeG2wNVn5v4A2bGuX/vcr3nPYXlflHiu/t4vPFGYlzzJmxWeo2ObPbrEVdwaL7yqcFXUVi+9InBV1JIvrZszmu1mS62YW3wkHAdhyndDrZrroAmy/lO1jynXgh0UA2BNYeN6hlmDdcRol4ui6aTYNA+AX7gz9bC873/cAAAAASUVORK5CYII="</span>,
|
295 |
+
<span class="json-key">bottom</span>: <span class="json-string">"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAKgAAAAwCAMAAACyoMGoAAAAe1BMVEUAAAA5s/sfou4sq/QQmOYZnusIk+MIk+MTmug4svo+tv0HkuIlpvAWnOk1sPgLlOQZnusJk+McoOwwrfUyrvcdoOwTmug3sfkBjt8doe0ZnusUm+gEkOERmOcLleQ1sPg6tPtAuP4Hk+IOl+Uyrvctq/QlpvA+tvwbn+w2IVSMAAAAGHRSTlMAH8bFWWRKxjYlVufFj1bnjy6PzO7yx1h3FiyaAAABl0lEQVRYw+2R21KDQBBENwYjq0bFaJVKvCfR//9CQ+h5sKlJF1CWS8KBl+6ZhVMQPPJYw/07iJMa7lU+B2qPCR5RiMIzJiv6BUyUe5VNVO0xPUVjuqJvwES5V9lE1R7TWvQVmCj3Kl8BtcccrujdqoZFV0BlE1V7DMaaxbRisfBeMAVB0FaMsoZF1qCtKJ9bE948AdHN7gJIPUQvgeUN8OYMn+PM8PzwRE+A5UfgzRk+x5nheQqim+adpmi3L3oKgsM9HcyB9+Bb4AmovrPoN2BRnrMo95a9nhm2aLZH9AmwqDe/AdxbFj3N+YsORjTbK1puL1eU53Ow7X71yGWjR8FX619fAhblOYtyb9nrGe/Xz5MTzUDoSQlUVudHUeMZqOyeF4yiyYp+ApXd84LjE30BKrvnBcHjDFieFBVxogSzWQ0/h/evQSCEoBaNRZHnW1MlOvtv0cqzMk1fNN/REP0ASpT3L0DjeURX0XwoooP5ogMQLSBKLIES5X1PdEmEv4HF9YtRS0bR5EUfAGfD2ZeMoqNo6qI/fvJUFNWbkq8AAAAASUVORK5CYII="</span>
|
296 |
+
},
|
297 |
+
<span class="json-key">panelTextColor</span>: <span class="json-string">"#fff"</span>,
|
298 |
+
<span class="json-key">panelDescriptionColor</span>: <span class="json-string">"#B0FFA5"</span>,
|
299 |
+
<span class="json-key">panelDescriptionIcon</span>: <span class="json-string">"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAATCAMAAACuuX39AAAAwFBMVEUAAACw/6Ww/6UAAQGn8pwAAQGT1ooFCAUAAQEAAQGv/aQAAQGw/6UAAQE0TTGq9qCw/6Ww/6UOFQ6Q0Ieu/KOw/6VfiVlwo2k2TzMAAQGV2Iyw/6Ww/6WR0oiw/6Wq96Ct+6Kd45Oi65ig6Jap9Z+Gwn6w/6UAAQGw/6Ww/6Wi6pew/6WIxYCFwHxKbEav/aSw/6Wm8Juw/6Wq9p9jj12w/6VMb0iq96Cw/6Ww/6Wm8Zyj7JmW2o2w/6Wu/KOw/6XJxdjGAAAAP3RSTlMAEFEKBi2vHyUQQzzWBUzo+wo5k6dcamsaAlZ9squq+n2apNLelzsbMZ23FomVX41zvmXXROJdw/Ul0ca3//4rIEY4AAAAmUlEQVQY003O5Q7DMAwE4BSTFLXimJmZ3fd/rNXT1vj+3SfrZEZS01ONdu0CcH8Q6EOZhMAQ4an6fIwQ/+tqAfGkV3R4ud1KUnMPy4Bz1xWMmR5enjLL/906gIlktdX8gqnG6yHCTr3YCOzRZnuAYyW+sLhh5aHnTLttvWIZrQGjhM1shBtTGSC8CJyLEnICxtV+Z5JREUKyD26+FQN53O4ZAAAAAElFTkSuQmCC"</span>,
|
300 |
+
<span class="json-key">contentBgImage</span>: <span class="json-string">"https://static.giftd.ru/embedded/content_bg.png?1100409742"</span>,
|
301 |
+
<span class="json-key">contentColor</span>: <span class="json-string">"#5d869e"</span>,
|
302 |
+
<span class="json-key">contentTitleColor</span>: <span class="json-string">"#3496CE"</span>
|
303 |
+
}
|
304 |
+
}</code></pre>
|
305 |
+
<p>
|
306 |
+
На картинке показано соответствие между переменными и элементами встраиваемого решения:
|
307 |
+
</p>
|
308 |
+
<img style="width: 600px;" src="https://partner-static.giftd.ru/img/embedded_customization.png">
|
309 |
+
<p>Нюансы кастомизации встраиваемого решения:</p>
|
310 |
+
<ul class="bullets">
|
311 |
+
<li>В образце кода все переменные заполнены значениями, равными значениям по умолчанию;</li>
|
312 |
+
<li>Свойство <code>position</code> может принимать одно из трех значений: <code>left</code>, <code>right</code> или <code>bottom</code>.</li>
|
313 |
+
<li>Не меняйте свойство <code>pid</code>;</li>
|
314 |
+
<li>Мы советуем удалить из кода переменные, которые вы не будете кастомизировать — будут использованы значения по умолчанию;</li>
|
315 |
+
<li>Не забудьте раскомментировать строчку с переменной, если меняете ее;</li>
|
316 |
+
<li>Картинки можно вставлять как в виде Data URI, так и в виде обычного URL — в образце выше есть и тот, и другой вариант.</li>
|
317 |
+
<li>Для задания фона панели вы можете использовать как свойство <code>panelBg.color</code>, так и <code>panelBg.image</code>. <br><small><i>Рекомендуем использовать обе переменных одновременно — на тот случай, если фоновая картинка не загрузится.</i></small></li>
|
318 |
+
|
319 |
+
</ul>
|
320 |
+
]]></comment>
|
321 |
+
<frontend_type>label</frontend_type>
|
322 |
+
<sort_order>2</sort_order>
|
323 |
+
<show_in_default>1</show_in_default>
|
324 |
+
<show_in_website>1</show_in_website>
|
325 |
+
<show_in_store>1</show_in_store>
|
326 |
+
</custom_code_info>
|
327 |
+
<tab_js_code translate="label comment">
|
328 |
+
<label>JS-код с настройкаи графического блока Giftd</label>
|
329 |
+
<comment></comment>
|
330 |
+
<frontend_type>textarea</frontend_type>
|
331 |
+
<sort_order>12</sort_order>
|
332 |
+
<show_in_default>1</show_in_default>
|
333 |
+
<show_in_website>1</show_in_website>
|
334 |
+
<show_in_store>1</show_in_store>
|
335 |
+
</tab_js_code>
|
336 |
+
</fields>
|
337 |
+
</tab_settings>
|
338 |
+
</groups>
|
339 |
+
</giftd_cards>
|
340 |
+
</sections>
|
341 |
+
</config>
|
app/design/frontend/base/default/layout/giftd_panel.xml
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<layout version="0.1.0">
|
3 |
+
<default>
|
4 |
+
<reference name="before_body_end">
|
5 |
+
<block type="core/template" name="giftdPanel" template="giftd/panel.phtml"/>
|
6 |
+
</reference>
|
7 |
+
</default>
|
8 |
+
</layout>
|
app/design/frontend/base/default/template/giftd/panel.phtml
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
$show_panel = Mage::getStoreConfig('giftd_cards/panel_settings/panel_is_active',Mage::app()->getStore());
|
3 |
+
$use_custom_js = Mage::getStoreConfig('giftd_cards/tab_settings/custom_code_is_active',Mage::app()->getStore());
|
4 |
+
$custom_js = Mage::getStoreConfig('giftd_cards/tab_settings/tab_js_code',Mage::app()->getStore());
|
5 |
+
|
6 |
+
$panel_options =
|
7 |
+
'window.giftdOptions = {'.
|
8 |
+
'pid: "'.Mage::getStoreConfig('giftd_cards/api_settings/partner_token',Mage::app()->getStore()).'",'.
|
9 |
+
'tab: {'.
|
10 |
+
'enabled: '.(Mage::getStoreConfig('giftd_cards/panel_settings/panel_is_active',Mage::app()->getStore()) ? 'true' : 'false').','.
|
11 |
+
'position: "'.(Mage::getStoreConfig('giftd_cards/panel_settings/panel_position',Mage::app()->getStore()) ?: 'left').'"'.
|
12 |
+
'}'.
|
13 |
+
'};';
|
14 |
+
|
15 |
+
if ($show_panel && $use_custom_js && $custom_js)
|
16 |
+
$panel_options = $custom_js . ';';
|
17 |
+
|
18 |
+
?>
|
19 |
+
|
20 |
+
<script>
|
21 |
+
<?=$panel_options?>
|
22 |
+
(function(){
|
23 |
+
var s = (window.giftdOptions.tab && window.giftdOptions.tab.enabled) ? "giftd.js" : "giftd_no_tab.js";
|
24 |
+
var el = document.createElement("script");
|
25 |
+
el.id = "giftd-script";
|
26 |
+
el.async = true;
|
27 |
+
el.src = "https://static.giftd.ru/embedded/" + s;
|
28 |
+
document.getElementsByTagName("head")[0].appendChild(el);
|
29 |
+
})();
|
30 |
+
</script>';
|
package.xml
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<package>
|
3 |
+
<name>Giftd_Cards</name>
|
4 |
+
<version>1.0.0</version>
|
5 |
+
<stability>stable</stability>
|
6 |
+
<license uri="http://opensource.org/licenses/gpl-license.php">GPL</license>
|
7 |
+
<channel>community</channel>
|
8 |
+
<extends/>
|
9 |
+
<summary>Provides integration of Magento and Giftd — digital gift cards platform.</summary>
|
10 |
+
<description>The extension integrates Magento and Giftd. 
|
11 |
+

|
12 |
+
Giftd is a platform-as-a-service. It allows businesses to issue, sell and accept digital gift cards. 
|
13 |
+

|
14 |
+
The extension has three primary features: 
|
15 |
+

|
16 |
+
— Install Giftd embedded solution on your website;
|
17 |
+

|
18 |
+
— Add Giftd tab to your website, allowing users to send gift cards;
|
19 |
+

|
20 |
+
— Accept gift cards using an existing discount code field.</description>
|
21 |
+
<notes>First public release.</notes>
|
22 |
+
<authors><author><name>Alexander Nevidimov</name><user>nevidimov</user><email>nevidimov@giftd.ru</email></author></authors>
|
23 |
+
<date>2014-10-10</date>
|
24 |
+
<time>19:23:02</time>
|
25 |
+
<contents><target name="magecommunity"><dir><dir name="Giftd"><dir name="Cards"><dir name="Helper"><file name="Data.php" hash="a07c9c0bb8c274a37f245be65941df59"/></dir><dir name="Model"><file name="GiftdClient.php" hash="f32c25a85dd0efd8b60b5771f8320e99"/><file name="Observer.php" hash="c2c1de2ff722335c32e05ce2f7832365"/><dir name="System"><dir name="Config"><dir name="Source"><file name="Tabposition.php" hash="cc645c33159bf2449acf58bba336075d"/></dir></dir></dir></dir><dir name="etc"><file name="config.xml" hash="0d6bbce8bbf0f0c1e14920a00e953dde"/><file name="system.xml" hash="70e7e19dc34ff6e38a3ff8f79300c781"/></dir></dir></dir></dir></target><target name="magedesign"><dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="giftd_panel.xml" hash="3d9ad4a36cdeab1cfb4bd7cc5dea5080"/></dir><dir name="template"><dir name="giftd"><file name="panel.phtml" hash="a725ec457409fc71b19243f930c1eede"/></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir><dir name="etc"><dir name="modules"><file name="Giftd_Cards.xml" hash=""/></dir></dir></dir></target></contents>
|
26 |
+
<compatible/>
|
27 |
+
<dependencies><required><php><min>5.0.0</min><max>5.9.9</max></php></required></dependencies>
|
28 |
+
</package>
|