-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeepincrm.php
More file actions
executable file
·105 lines (88 loc) · 3.63 KB
/
keepincrm.php
File metadata and controls
executable file
·105 lines (88 loc) · 3.63 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
defined('_JEXEC') or die('Direct Access to ' . basename(__FILE__) . ' is not allowed.');
defined('DS') or define('DS', DIRECTORY_SEPARATOR);
if (!class_exists('vmCustomPlugin')) {
require JPATH_VM_PLUGINS . '/vmcustomplugin.php';
}
if (!class_exists('vmPSPlugin')) {
require JPATH_VM_PLUGINS . '/vmpsplugin.php';
}
class plgVmPaymentKeepincrm extends vmPSPlugin {
public function plgVmConfirmedOrder($cart, $orderDetails) {
$order = $orderDetails['details']['BT'];
$orderItems = $orderDetails['items'];
$api_key = $this->params->get('keepincrm_api_key');
$source_id = $this->params->get('keepincrm_source_id');
$user = '';
$comment = '';
$country = shopfunctions::getCountryByID($order->virtuemart_country_id);
$payment_method = VmModel::getModel('paymentmethod')->getPayment($order->virtuemart_paymentmethod_id);
$shipping_method = VmModel::getModel('shipmentmethod')->getShipment($order->virtuemart_shipmentmethod_id);
$i = 0;
$products_list = array();
foreach($orderItems as $item) {
$title .= $item->order_item_name;
if (!empty($item->product_attribute)) {
if(!class_exists('VirtueMartModelCustomfields')) require(JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'customfields.php');
$product_attribute = VirtueMartModelCustomfields::CustomsFieldOrderDisplay($item, 'BE');
$title .= '; ' . strip_tags($product_attribute);
}
$products_list[$i] = array (
'amount' => $item->product_quantity,
'product_attributes' => array (
'sku' => $item->product_sku,
'title' => $title,
'price' => $item->product_final_price
)
);
$i++;
}
if ($country) {
$comment .= 'Страна: ' . $country . '; ';
}
if ($order->city) {
$comment .= 'Город: ' . $order->city . '; ';
}
if ($payment_method->payment_name) {
$comment .= 'Оплата: ' . $payment_method->payment_name . '; ';
}
if ($shipping_method->shipment_name) {
$comment .= 'Доставка: ' . $shipping_method->shipment_name . '; ';
}
if ($order->comment) {
$comment .= 'Комментарий: ' . $order->comment;
}
if ($order->user_name) {
$user .= $order->user_name;
}
if ($order->first_name || $order->last_name) {
$user .= $order->first_name . ' ' . $order->last_name;
}
$agreement_details = array (
'title' => 'Заказ #'.$order->order_number,
'total' => $order->order_total,
'comment' => $comment,
'client_attributes' => array (
'person' => $user,
'lead' => false,
'source_id' => $source_id,
'email' => $order->email,
'phones' => array (
0 => $order->phone_1
)
),
'jobs_attributes' => $products_list
);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://api.keepincrm.com/v1/agreements');
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Accept: application/json', 'X-Auth-Token: ' . $api_key . '', 'Content-Type: application/json'));
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($agreement_details));
curl_exec($curl);
curl_close($curl);
return true;
}
}