-
Notifications
You must be signed in to change notification settings - Fork 26
/
mlapp.php
59 lines (34 loc) · 955 Bytes
/
mlapp.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
require_once 'app/Mage.php';
Mage::app();
$inputJSON = file_get_contents('php://input');
if($inputJSON){
$notification = Mage::getModel('mercadolivre/notification');
$notification->setNotification($inputJSON);
$input = json_decode( $inputJSON, TRUE ); //convert JSON into array
$id = explode("/", $input['resource']);
$notification->setMlId($id[2]);
$notification->save();
// Mage::log($input);
switch ($input['topic']) {
case 'orders':
$order = Mage::getModel('mercadolivre/order')->load($id[2],'ml_id');
if (!$order->getId()) {
$order->setMlId($id[2]);
$order->setContent($inputJSON);
$order->save();
}else{
}
break;
case 'items':
// Mage::dispatchEvent('mercadolivre_items_notification', $notification);
break;
case 'questions':
Mage::dispatchEvent('mercadolivre_questions_notification', $input);
break;
default:
# code...
break;
}
}
echo "ok";