Version Notes
New internal api
Download this release
Release Info
Developer | Jonathan Martin |
Extension | yuzu |
Version | 1.1.0 |
Comparing to | |
See all releases |
Code changes from version 1.0.7 to 1.1.0
app/code/community/Yuzu/Tags/Helper/Api.php
ADDED
@@ -0,0 +1,313 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Api Helper
|
5 |
+
*
|
6 |
+
* @category Yuzu
|
7 |
+
* @package Yuzu_Tags
|
8 |
+
* @copyright Copyright (c) 2015 Yuzu (http://www.yuzu.co)
|
9 |
+
* @author Olivier Mouren <olivier@yuzu.co>
|
10 |
+
*/
|
11 |
+
class Yuzu_Tags_Helper_Api extends Mage_Core_Helper_Abstract
|
12 |
+
{
|
13 |
+
private $request;
|
14 |
+
|
15 |
+
private $message;
|
16 |
+
|
17 |
+
private $res = array();
|
18 |
+
|
19 |
+
public function setRequest(Mage_Core_Controller_Request_Http $request)
|
20 |
+
{
|
21 |
+
$this->request = $request;
|
22 |
+
$this->message = json_decode($this->decodeBase64($this->getPostData()['message']), true);
|
23 |
+
}
|
24 |
+
|
25 |
+
public function getPostData()
|
26 |
+
{
|
27 |
+
return $this->request->getPost();
|
28 |
+
}
|
29 |
+
|
30 |
+
/**
|
31 |
+
* @return array
|
32 |
+
*/
|
33 |
+
public function getResponse()
|
34 |
+
{
|
35 |
+
return $this->res;
|
36 |
+
}
|
37 |
+
|
38 |
+
public function encodeBase64($data)
|
39 |
+
{
|
40 |
+
return base64_encode($data);
|
41 |
+
}
|
42 |
+
|
43 |
+
public function decodeBase64($data)
|
44 |
+
{
|
45 |
+
return base64_decode($data);
|
46 |
+
}
|
47 |
+
|
48 |
+
public function getOrders()
|
49 |
+
{
|
50 |
+
$query = json_decode($this->getPostData()['query'], true);
|
51 |
+
|
52 |
+
$page = (int) $query['page'];
|
53 |
+
$limit = (int) $query['limit'];
|
54 |
+
|
55 |
+
/** @var Mage_Sales_Model_Resource_Order_Collection $q */
|
56 |
+
$q = Mage::getModel('sales/order')->getCollection()
|
57 |
+
->addAttributeToSort('updated_at', 'asc')
|
58 |
+
->setCurPage($page)
|
59 |
+
->setPageSize($limit);
|
60 |
+
|
61 |
+
if (!empty($query['date_from']) && !empty($query['date_to'])) {
|
62 |
+
$q = $q->addAttributeToFilter('updated_at', ['from' => $query['date_from'], 'to' => $query['date_to']]);
|
63 |
+
} elseif (!empty($query['date_from'])) {
|
64 |
+
$q = $q->addAttributeToFilter('updated_at', ['from' => $query['date_from']]);
|
65 |
+
} elseif (!empty($query['date_to'])) {
|
66 |
+
$q = $q->addAttributeToFilter('updated_at', ['to' => $query['date_from']]);
|
67 |
+
}
|
68 |
+
|
69 |
+
if (!empty($this->message['id_shop'])) {
|
70 |
+
$q = $q->addAttributeToFilter('store_id', $this->message['id_shop']);
|
71 |
+
}
|
72 |
+
|
73 |
+
$this->signResponse();
|
74 |
+
|
75 |
+
if ($page > $q->getLastPageNumber()) {
|
76 |
+
return null;
|
77 |
+
}
|
78 |
+
|
79 |
+
return $q;
|
80 |
+
}
|
81 |
+
|
82 |
+
public function getOrder()
|
83 |
+
{
|
84 |
+
$query = json_decode($this->getPostData()['query'], true);
|
85 |
+
|
86 |
+
/** @var Mage_Sales_Model_Resource_Order_Collection $q */
|
87 |
+
$q = Mage::getModel('sales/order')->getCollection()
|
88 |
+
->addAttributeToFilter('increment_id', $query['id_order']);
|
89 |
+
|
90 |
+
if (!empty($this->message['id_shop'])) {
|
91 |
+
$q = $q->addAttributeToFilter('store_id', $this->message['id_shop']);
|
92 |
+
}
|
93 |
+
|
94 |
+
$this->signResponse();
|
95 |
+
|
96 |
+
return $q->getFirstItem()->getId() ? $q->getFirstItem() : null;
|
97 |
+
}
|
98 |
+
|
99 |
+
public function formatOrder(Mage_Sales_Model_Order $order)
|
100 |
+
{
|
101 |
+
$customer = Mage::getModel('customer/customer')->load($order->getCustomerId())->getData();
|
102 |
+
|
103 |
+
$products = array();
|
104 |
+
/** @var Mage_Sales_Model_Order_Item $product */
|
105 |
+
foreach ($order->getItemsCollection() as $product) {
|
106 |
+
$products[] = array(
|
107 |
+
'id_product' => $product->getId(),
|
108 |
+
'sku' => $product->getSku(),
|
109 |
+
'name' => $product->getName(),
|
110 |
+
'quantity' => $product->getQtyOrdered(),
|
111 |
+
'price' => $product->getPrice(),
|
112 |
+
);
|
113 |
+
}
|
114 |
+
|
115 |
+
$formatedOrder = array(
|
116 |
+
'order' => array(
|
117 |
+
'id_order' => $order->getIncrementId(),
|
118 |
+
'created_at' => $order->getCreatedAt(),
|
119 |
+
'updated_at' => $order->getUpdatedAt(),
|
120 |
+
'status' => $order->getStatus(),
|
121 |
+
'coupon_code' => $order->getCouponCode(),
|
122 |
+
// 'coupon_rule_name' => $order->getCouponCode(),
|
123 |
+
'shipping_description' => $order->getShippingDescription(),
|
124 |
+
'grand_total' => $order->getGrandTotal(),
|
125 |
+
'shipping_amount' => $order->getShippingAmount(),
|
126 |
+
'discount_amount' => $order->getDiscountAmount(),
|
127 |
+
'discount_description' => $order->getDiscountDescription(),
|
128 |
+
'tax_amount' => $order->getTaxAmount(),
|
129 |
+
'subtotal' => $order->getSubtotal(),
|
130 |
+
'weight' => $order->getWeight(),
|
131 |
+
'currency_code' => $order->getOrderCurrencyCode(),
|
132 |
+
'is_virtual' => $order->getIsVirtual(),
|
133 |
+
'ip' => $order->getRemoteIp(),
|
134 |
+
'gift_message_id' => $order->getGiftMessageId(),
|
135 |
+
'store_id' => $order->getStoreId(),
|
136 |
+
),
|
137 |
+
'customer' => array(
|
138 |
+
'id_customer' => $order->getCustomerId(),
|
139 |
+
'firstname' => $order->getCustomerFirstname(),
|
140 |
+
'lastname' => $order->getCustomerLastname(),
|
141 |
+
'email' => $order->getCustomerEmail(),
|
142 |
+
'dob' => $customer['dob'],
|
143 |
+
// 'phone' => 'phone',
|
144 |
+
'group_id' => $order->getCustomerGroupId(),
|
145 |
+
'gender' => $customer['gender'],
|
146 |
+
'taxvat' => $customer['taxvat'],
|
147 |
+
'is_guest' => $order->getCustomerIsGuest(),
|
148 |
+
),
|
149 |
+
'products' => $products,
|
150 |
+
);
|
151 |
+
|
152 |
+
$billingAddress = $order->getBillingAddress();
|
153 |
+
$shippingAddress = $order->getShippingAddress();
|
154 |
+
|
155 |
+
if ($billingAddress) {
|
156 |
+
$formatedOrder['billing_address'] = array(
|
157 |
+
'id' => $order->getBillingAddressId(),
|
158 |
+
'region' => $billingAddress->getRegion(),
|
159 |
+
'postcode' => $billingAddress->getPostcode(),
|
160 |
+
'prefix' => $billingAddress->getPrefix(),
|
161 |
+
'company' => $billingAddress->getCompany(),
|
162 |
+
'firstname' => $billingAddress->getFirstname(),
|
163 |
+
'lastname' => $billingAddress->getLastname(),
|
164 |
+
'street' => $billingAddress->getStreet(),
|
165 |
+
'city' => $billingAddress->getCity(),
|
166 |
+
'fax' => $billingAddress->getFax(),
|
167 |
+
'telephone' => $billingAddress->getTelephone(),
|
168 |
+
'country_id' => $billingAddress->getCountryId(),
|
169 |
+
);
|
170 |
+
}
|
171 |
+
|
172 |
+
if ($shippingAddress) {
|
173 |
+
$formatedOrder['shipping_address'] = array(
|
174 |
+
'id' => $order->getShippingAddressId(),
|
175 |
+
'region' => $shippingAddress->getRegion(),
|
176 |
+
'postcode' => $shippingAddress->getPostcode(),
|
177 |
+
'prefix' => $shippingAddress->getPrefix(),
|
178 |
+
'company' => $shippingAddress->getCompany(),
|
179 |
+
'firstname' => $shippingAddress->getFirstname(),
|
180 |
+
'lastname' => $shippingAddress->getLastname(),
|
181 |
+
'street' => $shippingAddress->getStreet(),
|
182 |
+
'city' => $shippingAddress->getCity(),
|
183 |
+
'fax' => $shippingAddress->getFax(),
|
184 |
+
'telephone' => $shippingAddress->getTelephone(),
|
185 |
+
'country_id' => $shippingAddress->getCountryId(),
|
186 |
+
);
|
187 |
+
}
|
188 |
+
|
189 |
+
return $formatedOrder;
|
190 |
+
}
|
191 |
+
|
192 |
+
public function getCartRules()
|
193 |
+
{
|
194 |
+
/** @var Mage_SalesRule_Model_Resource_Rule_Collection $q */
|
195 |
+
$q = Mage::getModel('salesrule/rule')->getCollection();
|
196 |
+
|
197 |
+
$this->signResponse();
|
198 |
+
|
199 |
+
return $q;
|
200 |
+
}
|
201 |
+
|
202 |
+
public function formatCartRule(Mage_SalesRule_Model_Rule $rule)
|
203 |
+
{
|
204 |
+
return array(
|
205 |
+
'id_quote' => $rule->getId(),
|
206 |
+
'name' => $rule->getName(),
|
207 |
+
'description' => $rule->getDescription(),
|
208 |
+
'code' => $rule->getPrimaryCoupon()->getCode(),
|
209 |
+
'date_from' => $rule->getFromDate(),
|
210 |
+
'date_to' => $rule->getToDate(),
|
211 |
+
'active' => $rule->getIsActive(),
|
212 |
+
'action' => $rule->getSimpleAction(),
|
213 |
+
'amount' => $rule->getDiscountAmount(),
|
214 |
+
'quantity' => $rule->getUsesPerCoupon(),
|
215 |
+
'quantity_per_user' => $rule->getUsesPerCustomer(),
|
216 |
+
);
|
217 |
+
}
|
218 |
+
|
219 |
+
public function getCategories()
|
220 |
+
{
|
221 |
+
/** @var Mage_Catalog_Model_Resource_Category_Collection $q */
|
222 |
+
$q = Mage::getModel('catalog/category')->getCollection()
|
223 |
+
->addAttributeToSelect('name')
|
224 |
+
->addAttributeToSelect('description');
|
225 |
+
|
226 |
+
if (!empty($this->message['id_shop'])) {
|
227 |
+
$rootid = Mage::app()->getStore($this->message['id_shop'])->getRootCategoryId();
|
228 |
+
$q = $q->addFieldToFilter('path', ['like' => "1/$rootid/%"]);
|
229 |
+
}
|
230 |
+
|
231 |
+
$this->signResponse();
|
232 |
+
|
233 |
+
return $q;
|
234 |
+
}
|
235 |
+
|
236 |
+
public function formatCategory(Mage_Catalog_Model_Category $category)
|
237 |
+
{
|
238 |
+
return array(
|
239 |
+
'id_category' => $category->getId(),
|
240 |
+
'id_parent' => $category->getParentId(),
|
241 |
+
'name' => $category->getName(),
|
242 |
+
'description' => $category->getDescription(),
|
243 |
+
);
|
244 |
+
}
|
245 |
+
|
246 |
+
public function getProducts()
|
247 |
+
{
|
248 |
+
$query = json_decode($this->getPostData()['query'], true);
|
249 |
+
|
250 |
+
$page = (int) $query['page'];
|
251 |
+
$limit = (int) $query['limit'];
|
252 |
+
|
253 |
+
/** @var Mage_Catalog_Model_Resource_Product_Collection $q */
|
254 |
+
$q = Mage::getModel('catalog/product')->getCollection()
|
255 |
+
->addAttributeToSelect('name')
|
256 |
+
->addAttributeToSelect('description')
|
257 |
+
->addAttributeToSelect('price')
|
258 |
+
->setCurPage($page)
|
259 |
+
->setPageSize($limit);
|
260 |
+
|
261 |
+
|
262 |
+
if (!empty($this->message['id_shop'])) {
|
263 |
+
$q = $q->addStoreFilter($this->message['id_shop']);
|
264 |
+
}
|
265 |
+
|
266 |
+
$this->signResponse();
|
267 |
+
|
268 |
+
if ($page > $q->getLastPageNumber()) {
|
269 |
+
return null;
|
270 |
+
}
|
271 |
+
|
272 |
+
return $q;
|
273 |
+
}
|
274 |
+
|
275 |
+
public function formatProduct(Mage_Catalog_Model_Product $product)
|
276 |
+
{
|
277 |
+
$fullProduct = Mage::getModel('catalog/product')->load($product->getId());
|
278 |
+
|
279 |
+
$images = array();
|
280 |
+
foreach ($fullProduct->getMediaGalleryImages() as $image) {
|
281 |
+
$images[] = $image->getUrl();
|
282 |
+
}
|
283 |
+
|
284 |
+
return array(
|
285 |
+
'id_product' => $product->getId(),
|
286 |
+
'sku' => $product->getSku(),
|
287 |
+
'name' => $product->getName(),
|
288 |
+
'description' => $product->getDescription(),
|
289 |
+
'price' => $product->getPrice(),
|
290 |
+
'categories' => $product->getCategoryIds(),
|
291 |
+
'url' => $product->getProductUrl(),
|
292 |
+
'images' => $images,
|
293 |
+
'active' => $product->getStatus(),
|
294 |
+
);
|
295 |
+
}
|
296 |
+
|
297 |
+
private function signResponse()
|
298 |
+
{
|
299 |
+
if (!empty($this->message['id_shop'])) {
|
300 |
+
$this->res['sign'] = sha1(
|
301 |
+
$this->getPostData()['query']
|
302 |
+
.Mage::helper('yuzu_tags')->getConfig('yuzu_tags/general/merchant_key', $this->message['id_shop'])
|
303 |
+
.Mage::helper('yuzu_tags')->getConfig('yuzu_tags/general/secret_key', $this->message['id_shop'])
|
304 |
+
);
|
305 |
+
} else {
|
306 |
+
$this->res['sign'] = sha1(
|
307 |
+
$this->getPostData()['query']
|
308 |
+
.Mage::helper('yuzu_tags')->getConfig('yuzu_tags/general/merchant_key')
|
309 |
+
.Mage::helper('yuzu_tags')->getConfig('yuzu_tags/general/secret_key')
|
310 |
+
);
|
311 |
+
}
|
312 |
+
}
|
313 |
+
}
|
app/code/community/Yuzu/Tags/controllers/ApiController.php
ADDED
@@ -0,0 +1,263 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Check controller
|
5 |
+
*
|
6 |
+
* @category Yuzu
|
7 |
+
* @package Yuzu_Tags
|
8 |
+
* @copyright Copyright (c) 2015 Yuzu (http://www.yuzu.co)
|
9 |
+
* @author Olivier Mouren <olivier@yuzu.co>
|
10 |
+
*/
|
11 |
+
class Yuzu_Tags_ApiController extends Mage_Core_Controller_Front_Action
|
12 |
+
{
|
13 |
+
/** @var Yuzu_Tags_Helper_Api */
|
14 |
+
private $api;
|
15 |
+
|
16 |
+
public function indexAction()
|
17 |
+
{
|
18 |
+
$request = $this->getRequest();
|
19 |
+
$this->api = Mage::helper('yuzu_tags/Api');
|
20 |
+
$this->api->setRequest($request);
|
21 |
+
|
22 |
+
$this->checkRequest();
|
23 |
+
|
24 |
+
$res = '';
|
25 |
+
$action = json_decode($this->api->getPostData()['query'], true)['action'];
|
26 |
+
switch ($action) {
|
27 |
+
case 'getOrders':
|
28 |
+
$res = $this->getOrders();
|
29 |
+
break;
|
30 |
+
case 'getOrder':
|
31 |
+
$res = $this->getOrder();
|
32 |
+
break;
|
33 |
+
case 'getCodes':
|
34 |
+
$res = $this->getCodes();
|
35 |
+
break;
|
36 |
+
case 'getCategories':
|
37 |
+
$res = $this->getCategories();
|
38 |
+
break;
|
39 |
+
case 'getProducts':
|
40 |
+
$res = $this->getProducts();
|
41 |
+
break;
|
42 |
+
default:
|
43 |
+
break;
|
44 |
+
}
|
45 |
+
|
46 |
+
die($this->api->encodeBase64(json_encode(array_merge($res, $this->api->getResponse()))));
|
47 |
+
}
|
48 |
+
|
49 |
+
private function checkRequest()
|
50 |
+
{
|
51 |
+
$postData = $this->api->getPostData();
|
52 |
+
if (!count($postData)) {
|
53 |
+
$res = array();
|
54 |
+
$res['debug'] = 'No POST DATA received';
|
55 |
+
$res['return'] = 2;
|
56 |
+
|
57 |
+
die($this->api->encodeBase64(json_encode($res)));
|
58 |
+
}
|
59 |
+
|
60 |
+
$isActive = $this->isModuleActive();
|
61 |
+
if ($isActive['return'] !== 1) {
|
62 |
+
die($this->api->encodeBase64(json_encode($isActive)));
|
63 |
+
}
|
64 |
+
|
65 |
+
$checkSign = $this->checkSign();
|
66 |
+
if ($checkSign['return'] !== 1) {
|
67 |
+
die($this->api->encodeBase64(json_encode($checkSign)));
|
68 |
+
}
|
69 |
+
}
|
70 |
+
|
71 |
+
private function isModuleActive()
|
72 |
+
{
|
73 |
+
$res = array();
|
74 |
+
$active = false;
|
75 |
+
$message = json_decode($this->api->decodeBase64($this->api->getPostData()['message']), true);
|
76 |
+
|
77 |
+
if (!empty($message['id_shop'])) {
|
78 |
+
$active = Mage::helper('yuzu_tags')->getConfig('yuzu_tags/general/enable', $message['id_shop']) ? true : false;
|
79 |
+
} else {
|
80 |
+
$active = Mage::helper('yuzu_tags')->getConfig('yuzu_tags/general/enable') ? true : false;
|
81 |
+
}
|
82 |
+
|
83 |
+
if (!$active) {
|
84 |
+
$res['debug'] = 'Module disabled';
|
85 |
+
$res['return'] = 2;
|
86 |
+
$res['query'] = 'isActiveModule';
|
87 |
+
|
88 |
+
return $res;
|
89 |
+
}
|
90 |
+
|
91 |
+
$res['debug'] = 'Module installed and enabled';
|
92 |
+
if (!empty($message['id_shop'])) {
|
93 |
+
$res['sign'] = sha1(
|
94 |
+
$this->api->getPostData()['query']
|
95 |
+
.Mage::helper('yuzu_tags')->getConfig('yuzu_tags/general/merchant_key', $message['id_shop'])
|
96 |
+
.Mage::helper('yuzu_tags')->getConfig('yuzu_tags/general/secret_key', $message['id_shop'])
|
97 |
+
);
|
98 |
+
} else {
|
99 |
+
$res['sign'] = sha1(
|
100 |
+
$this->api->getPostData()['query']
|
101 |
+
.Mage::helper('yuzu_tags')->getConfig('yuzu_tags/general/merchant_key')
|
102 |
+
.Mage::helper('yuzu_tags')->getConfig('yuzu_tags/general/secret_key')
|
103 |
+
);
|
104 |
+
}
|
105 |
+
|
106 |
+
$res['return'] = 1;
|
107 |
+
$res['query'] = $this->api->getPostData()['query'];
|
108 |
+
|
109 |
+
return $res;
|
110 |
+
}
|
111 |
+
|
112 |
+
private function checkSign()
|
113 |
+
{
|
114 |
+
$res = array();
|
115 |
+
$message = json_decode($this->api->decodeBase64($this->api->getPostData()['message']), true);
|
116 |
+
|
117 |
+
if (empty($message)) {
|
118 |
+
$res['debug'] = 'Empty message';
|
119 |
+
$res['return'] = 2;
|
120 |
+
$res['query'] = 'checkSign';
|
121 |
+
|
122 |
+
return $res;
|
123 |
+
}
|
124 |
+
|
125 |
+
if (!empty($message['id_shop'])) {
|
126 |
+
$merchantKey = Mage::helper('yuzu_tags')->getConfig('yuzu_tags/general/merchant_key', $message['id_shop']);
|
127 |
+
$secretKey = Mage::helper('yuzu_tags')->getConfig('yuzu_tags/general/secret_key', $message['id_shop']);
|
128 |
+
|
129 |
+
$res['query'] = 'checkSign';
|
130 |
+
if (!$merchantKey || !$secretKey) {
|
131 |
+
$res['debug'] = 'Identifiants client non renseignés sur le module';
|
132 |
+
$res['message'] = 'Identifiants client non renseignés sur le module';
|
133 |
+
$res['return'] = 3;
|
134 |
+
|
135 |
+
return $res;
|
136 |
+
} elseif ($message['merchantKey'] !== $merchantKey) {
|
137 |
+
$res['message'] = 'MerchantKey incorrecte';
|
138 |
+
$res['debug'] = 'MerchantKey incorrecte';
|
139 |
+
$res['return'] = 4;
|
140 |
+
|
141 |
+
return $res;
|
142 |
+
} elseif (sha1($this->api->getPostData()['query'].$merchantKey.$secretKey) !== $message['sign']) {
|
143 |
+
$res['message'] = 'La signature est incorrecte';
|
144 |
+
$res['debug'] = 'La signature est incorrecte';
|
145 |
+
$res['return'] = 5;
|
146 |
+
|
147 |
+
return $res;
|
148 |
+
} else {
|
149 |
+
$res['message'] = 'Identifiants client Ok';
|
150 |
+
$res['debug'] = 'Identifiants client Ok';
|
151 |
+
$res['return'] = 1;
|
152 |
+
$res['sign'] = sha1($this->api->getPostData()['query'].$merchantKey.$secretKey);
|
153 |
+
|
154 |
+
return $res;
|
155 |
+
}
|
156 |
+
} else {
|
157 |
+
$merchantKey = Mage::helper('yuzu_tags')->getConfig('yuzu_tags/general/merchant_key');
|
158 |
+
$secretKey = Mage::helper('yuzu_tags')->getConfig('yuzu_tags/general/secret_key');
|
159 |
+
|
160 |
+
if (!$merchantKey || !$secretKey) {
|
161 |
+
$res['debug'] = 'Identifiants client non renseignés sur le module';
|
162 |
+
$res['message'] = 'Identifiants client non renseignés sur le module';
|
163 |
+
$res['return'] = 3;
|
164 |
+
$res['query'] = 'checkSign';
|
165 |
+
|
166 |
+
return $res;
|
167 |
+
} elseif ($message['merchantKey'] !== $merchantKey) {
|
168 |
+
$res['message'] = 'MerchantKey incorrecte';
|
169 |
+
$res['debug'] = 'MerchantKey incorrecte';
|
170 |
+
$res['return'] = 4;
|
171 |
+
$res['query'] = 'checkSign';
|
172 |
+
|
173 |
+
return $res;
|
174 |
+
} elseif (sha1($this->api->getPostData()['query'].$merchantKey.$secretKey) !== $message['sign']) {
|
175 |
+
$res['message'] = 'La signature est incorrecte';
|
176 |
+
$res['debug'] = 'La signature est incorrecte';
|
177 |
+
$res['return'] = 5;
|
178 |
+
$res['query'] = 'checkSign';
|
179 |
+
|
180 |
+
return $res;
|
181 |
+
}
|
182 |
+
$res['message'] = 'Identifiants Client Ok';
|
183 |
+
$res['debug'] = 'Identifiants Client Ok';
|
184 |
+
$res['return'] = 1;
|
185 |
+
$res['sign'] = sha1($this->api->getPostData()['query'].$merchantKey.$secretKey);
|
186 |
+
$res['query'] = 'checkSign';
|
187 |
+
|
188 |
+
return $res;
|
189 |
+
}
|
190 |
+
}
|
191 |
+
|
192 |
+
private function getOrders()
|
193 |
+
{
|
194 |
+
$res = array();
|
195 |
+
$results = $this->api->getOrders();
|
196 |
+
|
197 |
+
$orders = array();
|
198 |
+
foreach ($results as $order) {
|
199 |
+
$orders[] = $this->api->formatOrder($order);
|
200 |
+
}
|
201 |
+
|
202 |
+
$res['message']['orders'] = $orders;
|
203 |
+
|
204 |
+
return $res;
|
205 |
+
}
|
206 |
+
|
207 |
+
private function getOrder()
|
208 |
+
{
|
209 |
+
$res = array();
|
210 |
+
$order = $this->api->getOrder();
|
211 |
+
|
212 |
+
if ($order) {
|
213 |
+
$res['message'] = $this->api->formatOrder($order);
|
214 |
+
}
|
215 |
+
|
216 |
+
return $res;
|
217 |
+
}
|
218 |
+
|
219 |
+
private function getCodes()
|
220 |
+
{
|
221 |
+
$res = array();
|
222 |
+
$results = $this->api->getCartRules();
|
223 |
+
|
224 |
+
$codes = array();
|
225 |
+
foreach ($results as $quote) {
|
226 |
+
$codes[] = $this->api->formatCartRule($quote);
|
227 |
+
}
|
228 |
+
|
229 |
+
$res['message']['codes'] = $codes;
|
230 |
+
|
231 |
+
return $res;
|
232 |
+
}
|
233 |
+
|
234 |
+
private function getProducts()
|
235 |
+
{
|
236 |
+
$res = array();
|
237 |
+
$results = $this->api->getProducts();
|
238 |
+
|
239 |
+
$products = array();
|
240 |
+
foreach ($results as $product) {
|
241 |
+
$products[] = $this->api->formatProduct($product);
|
242 |
+
}
|
243 |
+
|
244 |
+
$res['message']['products'] = $products;
|
245 |
+
|
246 |
+
return $res;
|
247 |
+
}
|
248 |
+
|
249 |
+
private function getCategories()
|
250 |
+
{
|
251 |
+
$res = array();
|
252 |
+
$results = $this->api->getCategories();
|
253 |
+
|
254 |
+
$categories = array();
|
255 |
+
foreach ($results as $category) {
|
256 |
+
$categories[] = $this->api->formatCategory($category);
|
257 |
+
}
|
258 |
+
|
259 |
+
$res['message']['categories'] = $categories;
|
260 |
+
|
261 |
+
return $res;
|
262 |
+
}
|
263 |
+
}
|
app/code/community/Yuzu/Tags/etc/config.xml
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
<config>
|
3 |
<modules>
|
4 |
<Yuzu_Tags>
|
5 |
-
<version>1.0
|
6 |
</Yuzu_Tags>
|
7 |
</modules>
|
8 |
|
2 |
<config>
|
3 |
<modules>
|
4 |
<Yuzu_Tags>
|
5 |
+
<version>1.1.0</version>
|
6 |
</Yuzu_Tags>
|
7 |
</modules>
|
8 |
|
package.xml
CHANGED
@@ -1,18 +1,18 @@
|
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>yuzu</name>
|
4 |
-
<version>1.0
|
5 |
<stability>stable</stability>
|
6 |
<license uri="http://www.yuzu.co">Custom licence</license>
|
7 |
<channel>community</channel>
|
8 |
<extends/>
|
9 |
<summary>Yuzu</summary>
|
10 |
<description>Yuzu</description>
|
11 |
-
<notes>
|
12 |
<authors><author><name>Jonathan Martin</name><user>jmartin</user><email>jonathan@yuzu.co</email></author></authors>
|
13 |
-
<date>2016-
|
14 |
-
<time>11:
|
15 |
-
<contents><target name="magecommunity"><dir name="Yuzu"><dir name="Tags"><dir name="Block"><file name="Abstract.php" hash="b91713e3df84ab1d843a5f0259f37f43"/><file name="Checkout.php" hash="7027a87b8282f517cf2cfe4939e6aad0"/><file name="Email.php" hash="2972f781ff145ac1a9419a58f84d023e"/><file name="Tags.php" hash="2cdaa0836f4c0a834e7d2fef9904f4c4"/></dir><dir name="Helper"><file name="Data.php" hash="2e4f4453c348f04862c80efd45c6881b"/></dir><dir name="Model"><file name="Data.php" hash="e3985f42b22422a0d75ee56f68272d44"/><file name="Event.php" hash="87423a3e8a3d696cbf758c01e9501a3a"/><file name="Feed.php" hash="704c1b798925ed46d7e754170fcd172c"/><file name="Notifier.php" hash="e8fd5f3b758f5f761d849e808f9ecc0d"/><file name="Observer.php" hash="5caf983c0c77663a672ed4660eb7540f"/><dir name="System"><dir name="Config"><dir name="Source"><file name="Nb.php" hash="fc539e10886ba8a5c9af56c991cd63d0"/></dir></dir></dir></dir><dir name="controllers"><file name="CheckController.php" hash="f3a6d2a65e29079096cc1ebca50efaac"/></dir><dir name="etc"><file name="adminhtml.xml" hash="1402ebcefa884063791db10144f314a3"/><file name="config.xml" hash="
|
16 |
<compatible/>
|
17 |
<dependencies><required><php><min>5.2.0</min><max>5.6.0</max></php></required></dependencies>
|
18 |
</package>
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>yuzu</name>
|
4 |
+
<version>1.1.0</version>
|
5 |
<stability>stable</stability>
|
6 |
<license uri="http://www.yuzu.co">Custom licence</license>
|
7 |
<channel>community</channel>
|
8 |
<extends/>
|
9 |
<summary>Yuzu</summary>
|
10 |
<description>Yuzu</description>
|
11 |
+
<notes>New internal api</notes>
|
12 |
<authors><author><name>Jonathan Martin</name><user>jmartin</user><email>jonathan@yuzu.co</email></author></authors>
|
13 |
+
<date>2016-06-03</date>
|
14 |
+
<time>11:57:48</time>
|
15 |
+
<contents><target name="magecommunity"><dir name="Yuzu"><dir name="Tags"><dir name="Block"><file name="Abstract.php" hash="b91713e3df84ab1d843a5f0259f37f43"/><file name="Checkout.php" hash="7027a87b8282f517cf2cfe4939e6aad0"/><file name="Email.php" hash="2972f781ff145ac1a9419a58f84d023e"/><file name="Tags.php" hash="2cdaa0836f4c0a834e7d2fef9904f4c4"/></dir><dir name="Helper"><file name="Api.php" hash="2238fdc90084ee0f7644e5c935fad850"/><file name="Data.php" hash="2e4f4453c348f04862c80efd45c6881b"/></dir><dir name="Model"><file name="Data.php" hash="e3985f42b22422a0d75ee56f68272d44"/><file name="Event.php" hash="87423a3e8a3d696cbf758c01e9501a3a"/><file name="Feed.php" hash="704c1b798925ed46d7e754170fcd172c"/><file name="Notifier.php" hash="e8fd5f3b758f5f761d849e808f9ecc0d"/><file name="Observer.php" hash="5caf983c0c77663a672ed4660eb7540f"/><dir name="System"><dir name="Config"><dir name="Source"><file name="Nb.php" hash="fc539e10886ba8a5c9af56c991cd63d0"/></dir></dir></dir></dir><dir name="controllers"><file name="ApiController.php" hash="10303b60cbee77d3beb56f7346d12623"/><file name="CheckController.php" hash="f3a6d2a65e29079096cc1ebca50efaac"/></dir><dir name="etc"><file name="adminhtml.xml" hash="1402ebcefa884063791db10144f314a3"/><file name="config.xml" hash="bd61e841838d1ff735c2b81998849c09"/><file name="system.xml" hash="c2fbd8fb0967cb9d873a91a1987ea617"/></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="yuzu_tags.xml" hash="4182e2bcf83fcf1b238f972ef6004f9a"/></dir><dir name="template"><dir name="yuzu_tags"><file name="async_tag.phtml" hash="6d64dc98d0886411a7833de6e9a76ccf"/><dir><dir name="email"><dir name="invoice"><file name="items.phtml" hash="a69e17038115272fc4b1f2f7318f7c35"/></dir><file name="offers.phtml" hash="83ad1604a5d6029af17083f0ff3ddaa0"/><dir name="order"><file name="items.phtml" hash="7e604a8b4b29183499f2673d28daba55"/></dir><dir name="shipment"><file name="items.phtml" hash="997065e2d6a6fec7704c99a743521731"/></dir></dir></dir><file name="event.phtml" hash="04de9167cd5165aff94d86e1df0c33af"/><file name="iframewrap.phtml" hash="82f92521e77a0401b76c97329316290c"/><file name="init.phtml" hash="12362eeb227843b6af0d9837decc87ff"/><file name="post_purchase.phtml" hash="6e95f079b990cde565931a02cfe5e98b"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Yuzu_Tags.xml" hash="966c25c3c7f93c697b07295201bb460c"/></dir></target></contents>
|
16 |
<compatible/>
|
17 |
<dependencies><required><php><min>5.2.0</min><max>5.6.0</max></php></required></dependencies>
|
18 |
</package>
|