send customer to crm on opencart event customer create

This commit is contained in:
dkorol 2016-08-05 11:44:18 +03:00
parent ff980b56ac
commit 9b2081d841
3 changed files with 69 additions and 0 deletions

View file

@ -43,6 +43,13 @@ class ControllerModuleRetailcrm extends Controller
version_compare(VERSION, '2.2', '>=') ? 'catalog/model/checkout/order/addOrderHistory/after' : 'post.order.history.add',
'module/retailcrm/order_edit'
);
$this->model_extension_event
->addEvent(
'retailcrm',
version_compare(VERSION, '2.2', '>=') ? 'catalog/model/account/customer/addCustomer/after' : 'post.customer.add',
'module/retailcrm/customer_create'
);
}
/**

View file

@ -94,4 +94,24 @@ class ControllerModuleRetailcrm extends Controller
$this->model_retailcrm_order->changeInCrm($data, $data['order_id']);
}
}
/**
* Create customer on event
*
* @param int $customerId customer identificator
*
* @return void
*/
public function customer_create($parameter1, $parameter2) {
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);
}
}

View file

@ -0,0 +1,42 @@
<?php
class ModelRetailcrmCustomer extends Model {
public function sendToCrm($customer) {
$this->load->model('setting/setting');
$settings = $this->model_setting_setting->getSetting('retailcrm');
if(empty($customer))
return false;
if(empty($settings['retailcrm_url']) || empty($settings['retailcrm_apikey']))
return false;
require_once DIR_SYSTEM . 'library/retailcrm/bootstrap.php';
$this->retailcrmApi = new RetailcrmProxy(
$settings['retailcrm_url'],
$settings['retailcrm_apikey'],
DIR_SYSTEM . 'logs/retailcrm.log'
);
$customerToCrm = $this->process($customer);
$this->retailcrmApi->customersCreate($customerToCrm);
}
private function process($customer) {
$customerToCrm = array(
'externalId' => $customer['customer_id'],
'firstName' => $customer['firstname'],
'lastName' => $customer['lastname'],
'email' => $customer['email'],
'phones' => array(
array(
'number' => $customer['telephone']
)
),
'createdAt' => $customer['date_added']
);
return $customerToCrm;
}
}