2016-03-10 02:07:25 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class ControllerModule
|
|
|
|
*
|
|
|
|
* @category RetailCrm
|
|
|
|
* @package RetailCrm
|
|
|
|
* @author RetailCrm <integration@retailcrm.ru>
|
|
|
|
* @license https://opensource.org/licenses/MIT MIT License
|
|
|
|
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion3
|
|
|
|
*/
|
|
|
|
class ControllerModuleRetailcrm extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Create order on event
|
|
|
|
*
|
|
|
|
* @param int $order_id order identificator
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2016-08-02 14:20:56 +03:00
|
|
|
public function order_create($parameter1, $parameter2 = null)
|
2016-03-10 02:07:25 +03:00
|
|
|
{
|
|
|
|
$this->load->model('checkout/order');
|
|
|
|
$this->load->model('account/order');
|
|
|
|
|
2016-08-02 14:20:56 +03:00
|
|
|
if($parameter2 != null)
|
|
|
|
$order_id = $parameter2;
|
|
|
|
else
|
|
|
|
$order_id = $parameter1;
|
|
|
|
|
2016-03-10 02:07:25 +03:00
|
|
|
$data = $this->model_checkout_order->getOrder($order_id);
|
2016-08-02 14:20:56 +03:00
|
|
|
|
2016-03-10 02:07:25 +03:00
|
|
|
$data['products'] = $this->model_account_order->getOrderProducts($order_id);
|
2016-07-25 17:21:15 +03:00
|
|
|
foreach($data['products'] as $key => $product) {
|
|
|
|
$productOptions = $this->model_account_order->getOrderOptions($order_id, $product['order_product_id']);
|
|
|
|
|
|
|
|
if(!empty($productOptions))
|
|
|
|
$data['products'][$key]['option'] = $productOptions;
|
|
|
|
}
|
2016-03-10 02:07:25 +03:00
|
|
|
|
2017-10-30 13:33:57 +03:00
|
|
|
$data['totals'] = $this->model_account_order->getOrderTotals($order_id);
|
|
|
|
|
2016-03-10 02:07:25 +03:00
|
|
|
if (!isset($data['fromApi'])) {
|
|
|
|
$this->load->model('setting/setting');
|
|
|
|
$status = $this->model_setting_setting->getSetting('retailcrm');
|
2016-03-11 14:15:24 +03:00
|
|
|
if ($data['order_status_id'] > 0) {
|
|
|
|
$data['order_status'] = $status['retailcrm_status'][$data['order_status_id']];
|
|
|
|
}
|
2016-03-10 02:07:25 +03:00
|
|
|
|
|
|
|
$this->load->model('retailcrm/order');
|
2016-03-11 14:15:24 +03:00
|
|
|
$this->model_retailcrm_order->sendToCrm($data, $data['order_id']);
|
2016-03-10 02:07:25 +03:00
|
|
|
}
|
|
|
|
}
|
2016-04-08 14:59:15 +03:00
|
|
|
|
2016-08-02 14:20:56 +03:00
|
|
|
public function order_edit($parameter1, $parameter2 = null, $parameter3 = null, $parameter4 = null) {
|
|
|
|
if($parameter4 != null)
|
|
|
|
$order_id = $parameter3;
|
|
|
|
else
|
|
|
|
$order_id = $parameter1;
|
|
|
|
|
2016-04-08 14:59:15 +03:00
|
|
|
$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);
|
|
|
|
|
2016-07-25 17:21:15 +03:00
|
|
|
foreach($data['products'] as $key => $product) {
|
|
|
|
$productOptions = $this->model_account_order->getOrderOptions($order_id, $product['order_product_id']);
|
|
|
|
|
|
|
|
if(!empty($productOptions))
|
|
|
|
$data['products'][$key]['option'] = $productOptions;
|
|
|
|
}
|
|
|
|
|
2017-10-30 13:33:57 +03:00
|
|
|
$data['totals'] = $this->model_account_order->getOrderTotals($order_id);
|
|
|
|
|
2016-04-08 14:59:15 +03:00
|
|
|
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']);
|
|
|
|
}
|
|
|
|
}
|
2016-08-31 17:28:11 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create customer on event
|
|
|
|
*
|
|
|
|
* @param int $customerId customer identificator
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2016-09-05 12:16:37 +03:00
|
|
|
public function customer_create($parameter1, $parameter2 = null) {
|
2016-08-31 17:28:11 +03:00
|
|
|
if($parameter2 != null)
|
|
|
|
$customerId = $parameter2;
|
|
|
|
else
|
|
|
|
$customerId = $parameter1;
|
|
|
|
|
|
|
|
$this->load->model('account/customer');
|
|
|
|
$customer = $this->model_account_customer->getCustomer($customerId);
|
|
|
|
|
|
|
|
$this->load->model('retailcrm/customer');
|
|
|
|
$this->model_retailcrm_customer->sendToCrm($customer);
|
|
|
|
}
|
2016-03-10 02:07:25 +03:00
|
|
|
}
|