upload in CRM of the customer's address after registration, upload updates customers

This commit is contained in:
iyzoer 2017-05-18 17:29:28 +03:00
parent 95152eebd7
commit d860f6203c
4 changed files with 158 additions and 3 deletions

View File

@ -54,6 +54,27 @@ class ControllerExtensionModuleRetailcrm extends Controller
'catalog/model/account/customer/addCustomer/after',
'extension/module/retailcrm/customer_create'
);
$this->model_extension_event
->addEvent(
'retailcrm',
'catalog/model/account/customer/editCustomer/after',
'extension/module/retailcrm/customer_edit'
);
$this->model_extension_event
->addEvent(
'retailcrm',
'catalog/model/account/address/editAddress/after',
'extension/module/retailcrm/customer_edit'
);
$this->model_extension_event
->addEvent(
'retailcrm',
'admin/model/customer/customer/editCustomer/after',
'extension/module/retailcrm/customer_edit'
);
}
/**
@ -78,7 +99,6 @@ class ControllerExtensionModuleRetailcrm extends Controller
*/
public function index()
{
$this->load->model('localisation/country');
$this->load->model('setting/setting');
$this->load->model('extension/module');
@ -311,6 +331,44 @@ class ControllerExtensionModuleRetailcrm extends Controller
}
}
/**
* Update customer on event
*
* @param int $customer_id customer identificator
*
* @return void
*/
public function customer_edit($route, $customer)
{
$this->load->model('localisation/country');
$this->load->model('localisation/zone');
$this->load->model('customer/customer');
$customerId = $customer[0];
$customer = $customer[1];
$addresses = $customer['address'];
unset($customer);
$customer = $this->model_customer_customer->getCustomer($customerId);
foreach ($addresses as $address) {
$country = $this->model_localisation_country->getCountry($address['country_id']);
$zone = $this->model_localisation_zone->getZone($address['zone_id']);
$customer['address'] = array(
'address_1' => $address['address_1'],
'address_2' => $address['address_2'],
'city' => $address['city'],
'postcode' => $address['postcode'],
'iso_code_2' => $country['iso_code_2'],
'zone' => $zone['name']
);
}
$this->load->model('extension/retailcrm/customer');
$this->model_extension_retailcrm_customer->changeInCrm($customer);
}
/**
* Export single order
*

View File

@ -32,6 +32,28 @@ class ModelExtensionRetailcrmCustomer extends Model {
}
}
public function changeInCrm($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 . 'storage/logs/retailcrm.log'
);
$customerToCrm = $this->process($customer);
$this->retailcrmApi->customersEdit($customerToCrm);
}
private function process($customer) {
$customerToCrm = array(
'externalId' => $customer['customer_id'],
@ -46,6 +68,16 @@ class ModelExtensionRetailcrmCustomer extends Model {
'createdAt' => $customer['date_added']
);
if (isset($customer['address'])) {
$customerToCrm['address'] = array(
'index' => $customer['address']['postcode'],
'countryIso' => $customer['address']['iso_code_2'],
'region' => $customer['address']['zone'],
'city' => $customer['address']['city'],
'text' => $customer['address']['address_1'] . ' ' . $customer['address']['address_2']
);
}
return $customerToCrm;
}
}

View File

@ -53,6 +53,13 @@ class ControllerExtensionModuleRetailcrm extends Controller
}
}
/**
* Update order on event
*
* @param int $order_id order identificator
*
* @return void
*/
public function order_edit($parameter1, $parameter2 = null) {
$order_id = $parameter2[0];
@ -94,12 +101,48 @@ class ControllerExtensionModuleRetailcrm extends Controller
* @return void
*/
public function customer_create($parameter1, $parameter2 = null, $parameter3 = null) {
$customerId = $parameter3;
$this->load->model('account/customer');
$this->load->model('localisation/country');
$this->load->model('localisation/zone');
$customerId = $parameter3;
$customer = $this->model_account_customer->getCustomer($customerId);
if ($this->request->post) {
$country = $this->model_localisation_country->getCountry($this->request->post['country_id']);
$zone = $this->model_localisation_zone->getZone($this->request->post['zone_id']);
$customer['address'] = array(
'address_1' => $this->request->post['address_1'],
'address_2' => $this->request->post['address_2'],
'city' => $this->request->post['city'],
'postcode' => $this->request->post['postcode'],
'iso_code_2' => $country['iso_code_2'],
'zone' => $zone['name']
);
}
$this->load->model('extension/retailcrm/customer');
$this->model_extension_retailcrm_customer->sendToCrm($customer);
}
/**
* Update customer on event
*
* @param int $customerId customer identificator
*
* @return void
*/
public function customer_edit($parameter1, $parameter2, $parameter3) {
$customerId = $this->customer->getId();
$this->load->model('account/customer');
$customer = $this->model_account_customer->getCustomer($customerId);
$this->load->model('account/address');
$customer['address'] = $this->model_account_address->getAddress($customer['address_id']);
$this->load->model('extension/retailcrm/customer');
$this->model_extension_retailcrm_customer->changeInCrm($customer);
}
}

View File

@ -23,6 +23,28 @@ class ModelExtensionRetailcrmCustomer extends Model {
$this->retailcrmApi->customersCreate($customerToCrm);
}
public function changeInCrm($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 . 'storage/logs/retailcrm.log'
);
$customerToCrm = $this->process($customer);
$this->retailcrmApi->customersEdit($customerToCrm);
}
private function process($customer) {
$customerToCrm = array(
'externalId' => $customer['customer_id'],