mirror of
https://github.com/retailcrm/opencart-module.git
synced 2024-11-29 08:36:05 +03:00
fixed uploading to crm when order changed
This commit is contained in:
parent
a4261d544c
commit
0b5b07a19c
@ -37,6 +37,13 @@ class ControllerModuleRetailcrm extends Controller
|
|||||||
'post.order.add',
|
'post.order.add',
|
||||||
'module/retailcrm/order_create'
|
'module/retailcrm/order_create'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->model_extension_event
|
||||||
|
->addEvent(
|
||||||
|
'retailcrm',
|
||||||
|
'post.order.history.add',
|
||||||
|
'module/retailcrm/order_edit'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -278,7 +285,6 @@ class ControllerModuleRetailcrm extends Controller
|
|||||||
*/
|
*/
|
||||||
public function order_create($order_id)
|
public function order_create($order_id)
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->load->model('checkout/order');
|
$this->load->model('checkout/order');
|
||||||
$this->load->model('account/order');
|
$this->load->model('account/order');
|
||||||
|
|
||||||
|
@ -42,4 +42,32 @@ class ControllerModuleRetailcrm extends Controller
|
|||||||
$this->model_retailcrm_order->sendToCrm($data, $data['order_id']);
|
$this->model_retailcrm_order->sendToCrm($data, $data['order_id']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function order_edit($order_id) {
|
||||||
|
$this->load->model('checkout/order');
|
||||||
|
$this->load->model('account/order');
|
||||||
|
|
||||||
|
$data = $this->model_checkout_order->getOrder($order_id);
|
||||||
|
|
||||||
|
if($data['order_status_id'] == 0) return;
|
||||||
|
|
||||||
|
$data['products'] = $this->model_account_order->getOrderProducts($order_id);
|
||||||
|
|
||||||
|
if (!isset($data['fromApi'])) {
|
||||||
|
$this->load->model('setting/setting');
|
||||||
|
$status = $this->model_setting_setting->getSetting('retailcrm');
|
||||||
|
|
||||||
|
if ($data['order_status_id'] > 0) {
|
||||||
|
$data['order_status'] = $status['retailcrm_status'][$data['order_status_id']];
|
||||||
|
}
|
||||||
|
|
||||||
|
$data['totals'][] = array(
|
||||||
|
'code' => 'shipping',
|
||||||
|
'value' => isset($this->session->data['shipping_method']) ? $this->session->data['shipping_method']['cost'] : ''
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->load->model('retailcrm/order');
|
||||||
|
$this->model_retailcrm_order->changeInCrm($data, $data['order_id']);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,9 +57,17 @@ class ModelRetailcrmOrder extends Model {
|
|||||||
$payment_code = $order_data['payment_code'];
|
$payment_code = $order_data['payment_code'];
|
||||||
$order['paymentType'] = $settings['retailcrm_payment'][$payment_code];
|
$order['paymentType'] = $settings['retailcrm_payment'][$payment_code];
|
||||||
|
|
||||||
|
// Совместимость с 1.5.5, когда этот метод вызывается из model/checkout/order->createOrder(), а не из controller/module/retailcrm->order_create()
|
||||||
|
if(!isset($order_data['shipping_iso_code_2']) && isset($order_data['shipping_country_id'])) {
|
||||||
|
$this->load->model('localisation/country');
|
||||||
|
$shipping_country = $this->model_localisation_country->getCountry($order_data['shipping_country_id']);
|
||||||
|
$order_data['shipping_iso_code_2'] = $shipping_country['iso_code_2'];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
$delivery_code = $order_data['shipping_code'];
|
$delivery_code = $order_data['shipping_code'];
|
||||||
$order['delivery'] = array(
|
$order['delivery'] = array(
|
||||||
'code' => $settings['retailcrm_delivery'][$delivery_code],
|
'code' => !empty($delivery_code) ? $settings['retailcrm_delivery'][$delivery_code] : '',
|
||||||
'cost' => $deliveryCost,
|
'cost' => $deliveryCost,
|
||||||
'address' => array(
|
'address' => array(
|
||||||
'index' => $order_data['shipping_postcode'],
|
'index' => $order_data['shipping_postcode'],
|
||||||
@ -94,5 +102,82 @@ class ModelRetailcrmOrder extends Model {
|
|||||||
$this->retailcrm->ordersCreate($order);
|
$this->retailcrm->ordersCreate($order);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function changeInCrm($order_data, $order_id)
|
||||||
|
{
|
||||||
|
$this->load->model('setting/setting');
|
||||||
|
$settings = $this->model_setting_setting->getSetting('retailcrm');
|
||||||
|
|
||||||
|
if(!empty($settings['retailcrm_url']) && !empty($settings['retailcrm_apikey'])) {
|
||||||
|
require_once DIR_SYSTEM . 'library/retailcrm/bootstrap.php';
|
||||||
|
|
||||||
|
$this->retailcrm = new RetailcrmProxy(
|
||||||
|
$settings['retailcrm_url'],
|
||||||
|
$settings['retailcrm_apikey'],
|
||||||
|
DIR_SYSTEM . 'logs/retailcrm.log'
|
||||||
|
);
|
||||||
|
|
||||||
|
$order = array();
|
||||||
|
|
||||||
|
$payment_code = $order_data['payment_code'];
|
||||||
|
$delivery_code = $order_data['shipping_code'];
|
||||||
|
|
||||||
|
$order['externalId'] = $order_id;
|
||||||
|
$order['firstName'] = $order_data['firstname'];
|
||||||
|
$order['lastName'] = $order_data['lastname'];
|
||||||
|
$order['email'] = $order_data['email'];
|
||||||
|
$order['phone'] = $order_data['telephone'];
|
||||||
|
$order['customerComment'] = $order_data['comment'];
|
||||||
|
|
||||||
|
$deliveryCost = 0;
|
||||||
|
$orderTotals = isset($order_data['totals']) ? $order_data['totals'] : $order_data['order_total'] ;
|
||||||
|
|
||||||
|
foreach ($orderTotals as $totals) {
|
||||||
|
if ($totals['code'] == 'shipping') {
|
||||||
|
$deliveryCost = $totals['value'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$order['createdAt'] = date('Y-m-d H:i:s');
|
||||||
|
$order['paymentType'] = $settings['retailcrm_payment'][$payment_code];
|
||||||
|
|
||||||
|
$country = (isset($order_data['shipping_country'])) ? $order_data['shipping_country'] : '' ;
|
||||||
|
|
||||||
|
$order['delivery'] = array(
|
||||||
|
'code' => !empty($delivery_code) ? $settings['retailcrm_delivery'][$delivery_code] : '',
|
||||||
|
'cost' => $deliveryCost,
|
||||||
|
'address' => array(
|
||||||
|
'index' => $order_data['shipping_postcode'],
|
||||||
|
'city' => $order_data['shipping_city'],
|
||||||
|
'country' => $order_data['shipping_country_id'],
|
||||||
|
'region' => $order_data['shipping_zone_id'],
|
||||||
|
'text' => implode(', ', array(
|
||||||
|
$order_data['shipping_postcode'],
|
||||||
|
$country,
|
||||||
|
$order_data['shipping_city'],
|
||||||
|
$order_data['shipping_address_1'],
|
||||||
|
$order_data['shipping_address_2']
|
||||||
|
))
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$orderProducts = isset($order_data['products']) ? $order_data['products'] : $order_data['order_product'];
|
||||||
|
|
||||||
|
foreach ($orderProducts as $product) {
|
||||||
|
$order['items'][] = array(
|
||||||
|
'productId' => $product['product_id'],
|
||||||
|
'productName' => $product['name'],
|
||||||
|
'initialPrice' => $product['price'],
|
||||||
|
'quantity' => $product['quantity'],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($order_data['order_status_id']) && $order_data['order_status_id'] > 0) {
|
||||||
|
$order['status'] = $settings['retailcrm_status'][$order_data['order_status_id']];
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->retailcrm->ordersEdit($order);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user