Merge branch 'gwinn-master'

This commit is contained in:
Alex Lushpai 2016-02-09 16:32:47 +03:00
commit 778ced2b6c
5 changed files with 448 additions and 295 deletions

View File

@ -2,24 +2,42 @@
require_once DIR_SYSTEM . 'library/retailcrm/bootstrap.php'; require_once DIR_SYSTEM . 'library/retailcrm/bootstrap.php';
/**
* Class ControllerModule
*/
class ControllerModuleRetailcrm extends Controller class ControllerModuleRetailcrm extends Controller
{ {
private $error = array(); private $_error = array();
protected $log, $statuses, $payments, $deliveryTypes, $retailcrm; protected $log, $statuses, $payments, $deliveryTypes, $retailcrm;
public $children, $template; public $children, $template;
/**
* Install method
*
* @return void
*/
public function install() public function install()
{ {
$this->load->model('setting/setting'); $this->load->model('setting/setting');
$this->model_setting_setting->editSetting('retailcrm', array('retailcrm_status' => 1)); $this->model_setting_setting
->editSetting('retailcrm', array('retailcrm_status' => 1));
} }
/**
* Uninstall method
*
* @return void
*/
public function uninstall() public function uninstall()
{ {
$this->load->model('setting/setting'); $this->load->model('setting/setting');
$this->model_setting_setting->editSetting('retailcrm', array('retailcrm_status' => 0)); $this->model_setting_setting
->editSetting('retailcrm', array('retailcrm_status' => 0));
} }
/**
* Setup page
*/
public function index() public function index()
{ {
@ -59,8 +77,12 @@ class ControllerModuleRetailcrm extends Controller
$this->data['retailcrm_errors'] = array(); $this->data['retailcrm_errors'] = array();
$this->data['saved_settings'] = $this->model_setting_setting->getSetting('retailcrm'); $this->data['saved_settings'] = $this->model_setting_setting->getSetting('retailcrm');
$url = $this->data['saved_settings']['retailcrm_url']; $url = isset($this->data['saved_settings']['retailcrm_url'])
$key = $this->data['saved_settings']['retailcrm_apikey']; ? $this->data['saved_settings']['retailcrm_url']
: null;
$key = isset($this->data['saved_settings']['retailcrm_apikey'])
? $this->data['saved_settings']['retailcrm_apikey']
: null;
if (!empty($url) && !empty($key)) { if (!empty($url) && !empty($key)) {
@ -151,6 +173,9 @@ class ControllerModuleRetailcrm extends Controller
$this->response->setOutput($this->render()); $this->response->setOutput($this->render());
} }
/**
* History method
*/
public function history() public function history()
{ {
if (file_exists(DIR_APPLICATION . 'model/retailcrm/custom/history.php')) { if (file_exists(DIR_APPLICATION . 'model/retailcrm/custom/history.php')) {
@ -162,6 +187,9 @@ class ControllerModuleRetailcrm extends Controller
} }
} }
/**
* ICML generation
*/
public function icml() public function icml()
{ {
if (file_exists(DIR_APPLICATION . 'model/retailcrm/custom/icml.php')) { if (file_exists(DIR_APPLICATION . 'model/retailcrm/custom/icml.php')) {
@ -173,13 +201,18 @@ class ControllerModuleRetailcrm extends Controller
} }
} }
/**
* Validate
*
* @return bool
*/
private function validate() private function validate()
{ {
if (!$this->user->hasPermission('modify', 'module/retailcrm')) { if (!$this->user->hasPermission('modify', 'module/retailcrm')) {
$this->error['warning'] = $this->language->get('error_permission'); $this->_error['warning'] = $this->language->get('error_permission');
} }
if (!$this->error) { if (!$this->_error) {
return TRUE; return TRUE;
} else { } else {
return FALSE; return FALSE;

View File

@ -2,192 +2,152 @@
class ModelRetailcrmHistory extends Model class ModelRetailcrmHistory extends Model
{ {
protected $createResult;
public function request() public function request()
{ {
$this->load->model('setting/setting'); $this->load->model('setting/setting');
$this->load->model('setting/store'); $this->load->model('setting/store');
$this->load->model('sale/order'); $this->load->model('sale/order');
$this->load->model('sale/customer'); $this->load->model('sale/customer');
$this->load->model('retailcrm/tools'); $this->load->model('retailcrm/references');
$this->load->model('catalog/product'); $this->load->model('catalog/product');
$this->load->model('localisation/zone'); $this->load->model('localisation/zone');
$this->load->language('module/retailcrm'); $this->load->language('module/retailcrm');
$settings = $this->model_setting_setting->getSetting('retailcrm'); $settings = $this->model_setting_setting->getSetting('retailcrm');
$history = $this->model_setting_setting->getSetting('retailcrm_history');
$settings['domain'] = parse_url(HTTP_SERVER, PHP_URL_HOST); $settings['domain'] = parse_url(HTTP_SERVER, PHP_URL_HOST);
if (!empty($settings['retailcrm_url']) && !empty($settings['retailcrm_apikey'])) { $url = isset($settings['retailcrm_url']) ? $settings['retailcrm_url'] : null;
$key = isset($settings['retailcrm_apikey']) ? $settings['retailcrm_apikey'] : null;
if (empty($url) || empty($key)) {
$this->log->addNotice('You need to configure retailcrm module first.');
return false;
}
$crm = new RetailcrmProxy( $crm = new RetailcrmProxy(
$settings['retailcrm_url'], $settings['retailcrm_url'],
$settings['retailcrm_apikey'], $settings['retailcrm_apikey'],
DIR_SYSTEM . 'logs/retailcrm.log' DIR_SYSTEM . 'logs/retailcrm.log'
); );
$orders = $crm->ordersHistory(); $lastRun = !empty($history['retailcrm_history'])
$ordersIdsFix = array(); ? new DateTime($history['retailcrm_history'])
$customersIdsFix = array(); : new DateTime(date('Y-m-d H:i:s', strtotime('-1 days', strtotime(date('Y-m-d H:i:s')))));
$subtotalSettings = $this->model_setting_setting->getSetting('sub_total');
$totalSettings = $this->model_setting_setting->getSetting('total');
$shippingSettings = $this->model_setting_setting->getSetting('shipping');
$delivery = array_flip($settings['retailcrm_delivery']); $orders = $crm->ordersHistory($lastRun);
$payment = array_flip($settings['retailcrm_payment']); $generatedAt = $orders['generatedAt'];
$status = array_flip($settings['retailcrm_status']);
$ocPayment = $this->model_retailcrm_tools->getOpercartPaymentTypes(); $this->subtotalSettings = $this->model_setting_setting->getSetting('sub_total');
$ocDelivery = $this->model_retailcrm_tools->getOpercartDeliveryMethods(); $this->totalSettings = $this->model_setting_setting->getSetting('total');
$this->shippingSettings = $this->model_setting_setting->getSetting('shipping');
$zones = $this->model_localisation_zone->getZones(); $this->delivery = array_flip($settings['retailcrm_delivery']);
$this->payment = array_flip($settings['retailcrm_payment']);
$this->status = array_flip($settings['retailcrm_status']);
$this->ocPayment = $this->model_retailcrm_references
->getOpercartPaymentTypes();
$this->ocDelivery = $this->model_retailcrm_references
->getOpercartDeliveryTypes();
$this->zones = $this->model_localisation_zone->getZones();
$updatedOrders = array();
$newOrders = array();
foreach ($orders['orders'] as $order) {
if (isset($order['deleted'])) continue;
if (isset($order['externalId'])) {
$updatedOrders[] = $order['id'];
} else {
$newOrders[] = $order['id'];
}
}
unset($orders);
if (!empty($newOrders)) {
$orders = $crm->ordersList($filter = array('ids' => $newOrders));
if ($orders) {
$this->createResult = $this->createOrders($orders['orders']);
}
}
if (!empty($updatedOrders)) {
$orders = $crm->ordersList($filter = array('ids' => $updatedOrders));
if ($orders) {
$this->updateOrders($orders['orders']);
}
}
$this->model_setting_setting->editSetting('retailcrm_history', array('retailcrm_history' => $generatedAt));
if (!empty($this->createResult['customers'])) {
$crm->customersFixExternalIds($this->createResult['customers']);
}
if (!empty($this->createResult['customers'])) {
$crm->ordersFixExternalIds($this->createResult['orders']);
}
}
protected function updateOrders($orders)
{
foreach ($orders as $order) { foreach ($orders as $order) {
$store = $this->config->get('config_store_id');
if (empty($order['deleted'])) {
$data = array(); $data = array();
$customer_id = (!empty($order['customer']['externalId'])) $data['store_id'] = $store == null ? 0 : $store;
? $order['customer']['externalId'] $data['customer'] = $order['firstName'];
: '' $data['customer_id'] = (!empty($order['customer']['externalId'])) ? $order['customer']['externalId'] : 0;
;
if (isset($order['externalId'])) {
/*
* opercart developers believe that to remove all
* products from the order during the editing is a good
* idea...
*
* so we have to get order data from crm
*
*/
$order = $crm->getOrder($order['externalId']);
} else {
if ($customer_id == '') {
$cData = array(
'customer_group_id' => '1',
'firstname' => $order['customer']['firstName'],
'lastname' => (isset($order['customer']['lastName']))
? $order['customer']['lastName']
: ' '
,
'email' => $order['customer']['email'],
'telephone' => (isset($order['customer']['phones'][0]['number']))
? $order['customer']['phones'][0]['number']
: ' '
,
'newsletter' => 0,
'password' => 'tmppass',
'status' => 1,
'address' => array(
'firstname' => $order['customer']['firstName'],
'lastname' => (isset($order['customer']['lastName']))
? $order['customer']['lastName']
: ' '
,
'address_1' => $order['customer']['address']['text'],
'city' => isset($order['customer']['address']['city'])
? $order['customer']['address']['city']
: $order['delivery']['address']['city']
,
'postcode' => isset($order['customer']['address']['index'])
? $order['customer']['address']['index']
: $order['delivery']['address']['index']
,
),
'tax_id' => '',
'zone_id' => '',
);
$this->model_sale_customer->addCustomer($cData);
if (isset($order['customer']['email']) && $order['customer']['email'] != '') {
$tryToFind = $this->model_sale_customer->getCustomerByEmail($order['customer']['email']);
$customer_id = $tryToFind['customer_id'];
} else {
$last = $this->model_sale_customer->getCustomers(
$data = array('order' => 'DESC', 'limit' => 1)
);
$customer_id = $last[0]['customer_id'];
}
$customersIdsFix[] = array('id' => $order['customer']['id'], 'externalId' => (int)$customer_id);
}
}
/*
* Build order data
*/
$data['store_id'] = ($this->config->get('config_store_id') == null)
? 0
: $this->config->get('config_store_id')
;
$data['customer'] = $order['customer']['firstName'];
$data['customer_id'] = $customer_id;
$data['customer_group_id'] = 1; $data['customer_group_id'] = 1;
$data['firstname'] = $order['firstName']; $data['firstname'] = $order['firstName'];
$data['lastname'] = (isset($order['lastName'])) ? $order['lastName'] : ' '; $data['lastname'] = (!empty($order['lastName'])) ? $order['lastName'] : ' ';
$data['email'] = $order['customer']['email']; $data['email'] = $order['email'];
$data['telephone'] = (isset($order['customer']['phones'][0]['number'])) $data['telephone'] = (!empty($order['phone']['number'])) ? $order['phone']['number'] : ' ';
? $order['customer']['phones'][0]['number'] $data['comment'] = !empty($order['customerComment']) ? $order['customerComment'] : '';
: ' '
;
$data['comment'] = isset($order['customerComment']) ? $order['customerComment'] : '';
$data['fax'] = ''; $data['fax'] = '';
$data['payment_address'] = '0'; $data['payment_address'] = '0';
$data['payment_firstname'] = $order['firstName']; $data['payment_firstname'] = $order['firstName'];
$data['payment_lastname'] = (isset($order['lastName'])) ? $order['lastName'] : ' '; $data['payment_lastname'] = (!empty($order['lastName'])) ? $order['lastName'] : ' ';
$data['payment_address_1'] = $order['customer']['address']['text']; $data['payment_address_1'] = $order['customer']['address']['text'];
$data['payment_address_2'] = ''; $data['payment_address_2'] = '';
$data['payment_company'] = ''; $data['payment_company'] = '';
$data['payment_company_id'] = ''; $data['payment_company_id'] = '';
$data['payment_city'] = isset($order['customer']['address']['city']) $data['payment_city'] = !empty($order['customer']['address']['city']) ? $order['customer']['address']['city'] : $order['delivery']['address']['city'];
? $order['customer']['address']['city'] $data['payment_postcode'] = !empty( $order['customer']['address']['index'] ) ? $order['customer']['address']['index'] : $order['delivery']['address']['index'];
: $order['delivery']['address']['city']
;
$data['payment_postcode'] = isset($order['customer']['address']['index'])
? $order['customer']['address']['index']
: $order['delivery']['address']['index']
;
/*
* Country & zone id detection
*/
$country = 0;
$region = ''; $region = '';
if (is_int($order['delivery']['address']['region'])) { if (is_int($order['delivery']['address']['region'])) {
$region = $order['delivery']['address']['region']; $region = $order['delivery']['address']['region'];
} else { } else {
foreach($zones as $zone) { foreach ($this->zones as $zone) {
if ($order['delivery']['address']['region'] == $zone['name']) { if ($order['delivery']['address']['region'] == $zone['name']) {
$region = $zone['zone_id']; $region = $zone['zone_id'];
} }
} }
} }
$data['payment_country_id'] = isset($order['customer']['address']['country']) $data['payment_country_id'] = !empty($order['delivery']['address']['country']) ? $order['delivery']['address']['country'] : 0;
? $order['customer']['address']['country'] $data['payment_zone_id'] = !empty($order['delivery']['address']['region']) ? $order['delivery']['address']['region'] : $region;
: $order['delivery']['address']['country']
;
$data['payment_zone_id'] = isset($order['customer']['address']['region'])
? $order['customer']['address']['region']
: $region
;
$data['shipping_country_id'] = $order['delivery']['address']['country']; $data['shipping_country_id'] = !empty($order['delivery']['address']['country']) ? $order['delivery']['address']['country'] : 0;
$data['shipping_zone_id'] = $region; $data['shipping_zone_id'] = $region;
$data['shipping_address'] = '0'; $data['shipping_address'] = '0';
$data['shipping_firstname'] = $order['customer']['firstName']; $data['shipping_firstname'] = $order['firstName'];
$data['shipping_lastname'] = (isset($order['customer']['lastName'])) $data['shipping_lastname'] = (!empty($order['lastName'])) ? $order['lastName'] : ' ';
? $order['customer']['lastName']
: ' '
;
$data['shipping_address_1'] = $order['delivery']['address']['text']; $data['shipping_address_1'] = $order['delivery']['address']['text'];
$data['shipping_address_2'] = ''; $data['shipping_address_2'] = '';
$data['shipping_company'] = ''; $data['shipping_company'] = '';
@ -195,12 +155,12 @@ class ModelRetailcrmHistory extends Model
$data['shipping_city'] = $order['delivery']['address']['city']; $data['shipping_city'] = $order['delivery']['address']['city'];
$data['shipping_postcode'] = $order['delivery']['address']['index']; $data['shipping_postcode'] = $order['delivery']['address']['index'];
$data['shipping'] = $delivery[$order['delivery']['code']]; $data['shipping'] = $this->delivery[$order['delivery']['code']];
$data['shipping_method'] = $ocDelivery[$data['shipping']]; $data['shipping_method'] = $this->ocDelivery[$data['shipping']];
$data['shipping_code'] = $delivery[$order['delivery']['code']]; $data['shipping_code'] = $this->delivery[$order['delivery']['code']];
$data['payment'] = $payment[$order['paymentType']]; $data['payment'] = $this->payment[$order['paymentType']];
$data['payment_method'] = $ocPayment[$data['payment']]; $data['payment_method'] = $this->ocPayment[$data['payment']];
$data['payment_code'] = $payment[$order['paymentType']]; $data['payment_code'] = $this->payment[$order['paymentType']];
// this data will not retrive from crm for now // this data will not retrive from crm for now
$data['tax'] = ''; $data['tax'] = '';
@ -220,14 +180,14 @@ class ModelRetailcrmHistory extends Model
$data['order_product'] = array(); $data['order_product'] = array();
foreach ($order['items'] as $item) { foreach ($order['items'] as $item) {
$p = $this->model_catalog_product->getProduct($item['offer']['externalId']); $product = $this->model_catalog_product->getProduct($item['offer']['externalId']);
$data['order_product'][] = array( $data['order_product'][] = array(
'product_id' => $item['offer']['externalId'], 'product_id' => $item['offer']['externalId'],
'name' => $item['offer']['name'], 'name' => $item['offer']['name'],
'quantity' => $item['quantity'], 'quantity' => $item['quantity'],
'price' => $item['initialPrice'], 'price' => $item['initialPrice'],
'total' => $item['initialPrice'] * $item['quantity'], 'total' => $item['initialPrice'] * $item['quantity'],
'model' => $p['model'], 'model' => $product['model'],
// this data will not retrive from crm // this data will not retrive from crm
'order_product_id' => '', 'order_product_id' => '',
@ -236,7 +196,7 @@ class ModelRetailcrmHistory extends Model
); );
} }
$deliveryCost = isset($order['delivery']['cost']) ? $order['delivery']['cost'] : 0; $deliveryCost = !empty($order['delivery']['cost']) ? $order['delivery']['cost'] : 0;
$data['order_total'] = array( $data['order_total'] = array(
array( array(
@ -245,63 +205,222 @@ class ModelRetailcrmHistory extends Model
'title' => $this->language->get('product_summ'), 'title' => $this->language->get('product_summ'),
'value' => $order['summ'], 'value' => $order['summ'],
'text' => $order['summ'], 'text' => $order['summ'],
'sort_order' => $subtotalSettings['sub_total_sort_order'] 'sort_order' => $this->subtotalSettings['sub_total_sort_order']
), ),
array( array(
'order_total_id' => '', 'order_total_id' => '',
'code' => 'shipping', 'code' => 'shipping',
'title' => $ocDelivery[$data['shipping_code']], 'title' => $this->ocDelivery[$data['shipping_code']],
'value' => $deliveryCost, 'value' => $deliveryCost,
'text' => $deliveryCost, 'text' => $deliveryCost,
'sort_order' => $shippingSettings['shipping_sort_order'] 'sort_order' => $this->shippingSettings['shipping_sort_order']
), ),
array( array(
'order_total_id' => '', 'order_total_id' => '',
'code' => 'total', 'code' => 'total',
'title' => $this->language->get('column_total'), 'title' => $this->language->get('column_total'),
'value' => isset($order['totalSumm']) 'value' => isset($order['totalSumm']) ? $order['totalSumm'] : $order['summ'] + $deliveryCost,
? $order['totalSumm'] 'text' => isset($order['totalSumm']) ? $order['totalSumm'] : $order['summ'] + $deliveryCost,
: $order['summ'] + $deliveryCost 'sort_order' => $this->totalSettings['total_sort_order']
,
'text' => isset($order['totalSumm'])
? $order['totalSumm']
: $order['summ'] + $deliveryCost
,
'sort_order' => $totalSettings['total_sort_order']
) )
); );
$data['fromApi'] = true; $data['fromApi'] = true;
if (isset($order['externalId'])) { if (array_key_exists($order['status'], $this->status)) {
if(array_key_exists($order['status'], $status)) { $data['order_status_id'] = $this->status[$order['status']];
$data['order_status_id'] = $status[$order['status']];
} else { } else {
$tmpOrder = $this->model_sale_order->getOrder($order['externalId']); $tmpOrder = $this->model_sale_order->getOrder($order['externalId']);
$data['order_status_id'] = $tmpOrder['order_status_id']; $data['order_status_id'] = $tmpOrder['order_status_id'];
} }
$this->model_sale_order->editOrder($order['externalId'], $data); $this->model_sale_order->editOrder($order['externalId'], $data);
}
}
protected function createOrders($orders)
{
$customersIdsFix = array();
$ordersIdsFix = array();
foreach ($orders as $order) {
$store = $this->config->get('config_store_id');
$customer_id = (!empty($order['customer']['externalId']))
? $order['customer']['externalId']
: 0;
$data = array();
if ($customer_id == 0) {
$cData = array(
'store_id' => 0,
'customer_group_id' => '1',
'firstname' => $order['firstName'],
'lastname' => (!empty($order['lastName'])) ? $order['lastName'] : ' ',
'email' => $order['email'],
'telephone' => (!empty($order['customer']['phones'][0]['number']) ) ? $order['customer']['phones'][0]['number'] : ' ',
'fax' => '',
'newsletter' => 0,
'password' => 'tmppass',
'status' => 1,
'address' => array(
array(
'firstname' => $order['firstName'],
'lastname' => (!empty($order['lastName'])) ? $order['lastName'] : ' ',
'address_1' => $order['customer']['address']['text'],
'address_2' => ' ',
'city' => !empty($order['customer']['address']['city']) ? $order['customer']['address']['city'] : $order['delivery']['address']['city'],
'postcode' => isset($order['customer']['address']['index']) ? $order['customer']['address']['index'] : $order['delivery']['address']['index'],
'tax_id' => '1',
'company' => '',
'company_id' => '',
'zone_id' => '0',
'country_id' => 0
)
),
);
$this->model_sale_customer->addCustomer($cData);
if (!empty($order['email'])) {
$tryToFind = $this->model_sale_customer->getCustomerByEmail($order['email']);
$customer_id = $tryToFind['customer_id'];
} else { } else {
$last = $this->model_sale_customer->getCustomers($data = array('order' => 'DESC', 'limit' => 1));
$customer_id = $last[0]['customer_id'];
}
$customersIdsFix[] = array('id' => $order['customer']['id'], 'externalId' => (int)$customer_id);
}
$data['store_id'] = $store == null ? 0 : $store;
$data['customer'] = $order['firstName'];
$data['customer_id'] = $customer_id;
$data['customer_group_id'] = 1;
$data['firstname'] = $order['firstName'];
$data['lastname'] = (!empty($order['lastName'])) ? $order['lastName'] : ' ';
$data['email'] = $order['email'];
$data['telephone'] = (!empty($order['customer']['phones'][0]['number'])) ? $order['customer']['phones'][0]['number'] : ' ';
$data['comment'] = !empty($order['customerComment']) ? $order['customerComment'] : '';
$data['fax'] = '';
$data['payment_address'] = '0';
$data['payment_firstname'] = $order['firstName'];
$data['payment_lastname'] = (!empty($order['lastName'])) ? $order['lastName'] : ' ';
$data['payment_address_1'] = $order['customer']['address']['text'];
$data['payment_address_2'] = '';
$data['payment_company'] = '';
$data['payment_company_id'] = '';
$data['payment_city'] = !empty($order['customer']['address']['city']) ? $order['customer']['address']['city'] : $order['delivery']['address']['city'];
$data['payment_postcode'] = !empty($order['customer']['address']['index']) ? $order['customer']['address']['index'] : $order['delivery']['address']['index'];
$region = '';
if (!empty($order['delivery']['address']['region']) && is_int($order['delivery']['address']['region'])) {
$region = $order['delivery']['address']['region'];
} else {
foreach ($this->zones as $zone) {
if ($order['delivery']['address']['region'] == $zone['name']) {
$region = $zone['zone_id'];
}
}
}
$data['payment_country_id'] = !empty($order['delivery']['address']['country']) ? $order['delivery']['address']['country'] : 0;
$data['payment_zone_id'] = !empty($order['delivery']['address']['region']) ? $order['delivery']['address']['region'] : $region;
$data['shipping_country_id'] = !empty($order['delivery']['address']['country']) ? $order['delivery']['address']['country'] : 0;
$data['shipping_zone_id'] = $region;
$data['shipping_address'] = '0';
$data['shipping_firstname'] = $order['firstName'];
$data['shipping_lastname'] = (!empty($order['lastName'])) ? $order['lastName'] : ' ';
$data['shipping_address_1'] = $order['delivery']['address']['text'];
$data['shipping_address_2'] = '';
$data['shipping_company'] = '';
$data['shipping_company_id'] = '';
$data['shipping_city'] = $order['delivery']['address']['city'];
$data['shipping_postcode'] = $order['delivery']['address']['index'];
$data['shipping'] = $this->delivery[$order['delivery']['code']];
$data['shipping_method'] = $this->ocDelivery[$data['shipping']];
$data['shipping_code'] = $this->delivery[$order['delivery']['code']];
$data['payment'] = $this->payment[$order['paymentType']];
$data['payment_method'] = $this->ocPayment[$data['payment']];
$data['payment_code'] = $this->payment[$order['paymentType']];
// this data will not retrive from crm for now
$data['tax'] = '';
$data['tax_id'] = '';
$data['product'] = '';
$data['product_id'] = '';
$data['reward'] = '';
$data['affiliate'] = '';
$data['affiliate_id'] = '';
$data['payment_tax_id'] = '';
$data['order_product_id'] = '';
$data['payment_company'] = '';
$data['payment_company_id'] = '';
$data['company'] = '';
$data['company_id'] = '';
$data['order_product'] = array();
foreach ($order['items'] as $item) {
$product = $this->model_catalog_product->getProduct($item['offer']['externalId']);
$data['order_product'][] = array(
'product_id' => $item['offer']['externalId'],
'name' => $item['offer']['name'],
'quantity' => $item['quantity'],
'price' => $item['initialPrice'],
'total' => $item['initialPrice'] * $item['quantity'],
'model' => $product['model'],
// this data will not retrive from crm
'order_product_id' => '',
'tax' => 0,
'reward' => 0
);
}
$deliveryCost = !empty($order['delivery']['cost']) ? $order['delivery']['cost'] : 0;
$data['order_total'] = array(
array(
'order_total_id' => '',
'code' => 'sub_total',
'title' => $this->language->get('product_summ'),
'value' => $order['summ'],
'text' => $order['summ'],
'sort_order' => $this->subtotalSettings['sub_total_sort_order']
),
array(
'order_total_id' => '',
'code' => 'shipping',
'title' => $this->ocDelivery[$data['shipping_code']],
'value' => $deliveryCost,
'text' => $deliveryCost,
'sort_order' => $this->shippingSettings['shipping_sort_order']
),
array(
'order_total_id' => '',
'code' => 'total',
'title' => $this->language->get('column_total'),
'value' => !empty($order['totalSumm']) ? $order['totalSumm'] : $order['summ'] + $deliveryCost,
'text' => isset($order['totalSumm']) ? $order['totalSumm'] : $order['summ'] + $deliveryCost,
'sort_order' => $this->totalSettings['total_sort_order']
)
);
$data['fromApi'] = true;
$data['order_status_id'] = 1; $data['order_status_id'] = 1;
$this->model_sale_order->addOrder($data); $this->model_sale_order->addOrder($data);
$last = $this->model_sale_order->getOrders($data = array('order' => 'DESC', 'limit' => 1));
$last = $this->model_sale_order->getOrders($data = array('order' => 'DESC', 'limit' => 1, 'start' => 0));
$ordersIdsFix[] = array('id' => $order['id'], 'externalId' => (int) $last[0]['order_id']); $ordersIdsFix[] = array('id' => $order['id'], 'externalId' => (int) $last[0]['order_id']);
} }
} return array('customers' => $customersIdsFix, 'orders' => $ordersIdsFix);
}
if (!empty($customersIdsFix)) {
$crm->customersFixExternalIds($customersIdsFix);
}
if (!empty($ordersIdsFix)) {
$crm->ordersFixExternalIds($ordersIdsFix);
}
} else {
$this->log->addNotice('You need to configure retailcrm module first.');
}
} }
} }

View File

@ -47,7 +47,7 @@ class ModelRetailcrmIcml extends Model
$this->dd->saveXML(); $this->dd->saveXML();
$downloadPath = DIR_SYSTEM . '/../download/'; $downloadPath = DIR_SYSTEM . '/../';
if (!file_exists($downloadPath)) { if (!file_exists($downloadPath)) {
mkdir($downloadPath, 0755); mkdir($downloadPath, 0755);

View File

@ -30,7 +30,7 @@ class ModelRetailcrmReferences extends Model
); );
} }
protected function getOpercartDeliveryTypes() public function getOpercartDeliveryTypes()
{ {
$deliveryMethods = array(); $deliveryMethods = array();
$files = glob(DIR_APPLICATION . 'controller/shipping/*.php'); $files = glob(DIR_APPLICATION . 'controller/shipping/*.php');
@ -52,7 +52,7 @@ class ModelRetailcrmReferences extends Model
return $deliveryMethods; return $deliveryMethods;
} }
protected function getOpercartOrderStatuses() public function getOpercartOrderStatuses()
{ {
$this->load->model('localisation/order_status'); $this->load->model('localisation/order_status');
@ -60,7 +60,7 @@ class ModelRetailcrmReferences extends Model
->getOrderStatuses(array()); ->getOrderStatuses(array());
} }
protected function getOpercartPaymentTypes() public function getOpercartPaymentTypes()
{ {
$paymentTypes = array(); $paymentTypes = array();
$files = glob(DIR_APPLICATION . 'controller/payment/*.php'); $files = glob(DIR_APPLICATION . 'controller/payment/*.php');
@ -82,7 +82,7 @@ class ModelRetailcrmReferences extends Model
return $paymentTypes; return $paymentTypes;
} }
protected function getApiDeliveryTypes() public function getApiDeliveryTypes()
{ {
$this->load->model('setting/setting'); $this->load->model('setting/setting');
$settings = $this->model_setting_setting->getSetting('retailcrm'); $settings = $this->model_setting_setting->getSetting('retailcrm');
@ -100,7 +100,7 @@ class ModelRetailcrmReferences extends Model
} }
} }
protected function getApiOrderStatuses() public function getApiOrderStatuses()
{ {
$this->load->model('setting/setting'); $this->load->model('setting/setting');
$settings = $this->model_setting_setting->getSetting('retailcrm'); $settings = $this->model_setting_setting->getSetting('retailcrm');
@ -118,7 +118,7 @@ class ModelRetailcrmReferences extends Model
} }
} }
protected function getApiPaymentTypes() public function getApiPaymentTypes()
{ {
$this->load->model('setting/setting'); $this->load->model('setting/setting');
$settings = $this->model_setting_setting->getSetting('retailcrm'); $settings = $this->model_setting_setting->getSetting('retailcrm');

View File

@ -37,4 +37,5 @@
]]></add> ]]></add>
</operation> </operation>
</file> </file>
</modification> </modification>