mirror of
https://github.com/retailcrm/opencart-module.git
synced 2024-11-22 13:16:07 +03:00
upload in CRM of the customer's address after registration, upload updates customers
This commit is contained in:
parent
95152eebd7
commit
d860f6203c
@ -54,6 +54,27 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
|||||||
'catalog/model/account/customer/addCustomer/after',
|
'catalog/model/account/customer/addCustomer/after',
|
||||||
'extension/module/retailcrm/customer_create'
|
'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()
|
public function index()
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->load->model('localisation/country');
|
$this->load->model('localisation/country');
|
||||||
$this->load->model('setting/setting');
|
$this->load->model('setting/setting');
|
||||||
$this->load->model('extension/module');
|
$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
|
* Export single order
|
||||||
*
|
*
|
||||||
|
@ -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) {
|
private function process($customer) {
|
||||||
$customerToCrm = array(
|
$customerToCrm = array(
|
||||||
'externalId' => $customer['customer_id'],
|
'externalId' => $customer['customer_id'],
|
||||||
@ -46,6 +68,16 @@ class ModelExtensionRetailcrmCustomer extends Model {
|
|||||||
'createdAt' => $customer['date_added']
|
'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;
|
return $customerToCrm;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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) {
|
public function order_edit($parameter1, $parameter2 = null) {
|
||||||
$order_id = $parameter2[0];
|
$order_id = $parameter2[0];
|
||||||
|
|
||||||
@ -94,12 +101,48 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
|||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function customer_create($parameter1, $parameter2 = null, $parameter3 = null) {
|
public function customer_create($parameter1, $parameter2 = null, $parameter3 = null) {
|
||||||
$customerId = $parameter3;
|
|
||||||
|
|
||||||
$this->load->model('account/customer');
|
$this->load->model('account/customer');
|
||||||
|
$this->load->model('localisation/country');
|
||||||
|
$this->load->model('localisation/zone');
|
||||||
|
|
||||||
|
$customerId = $parameter3;
|
||||||
$customer = $this->model_account_customer->getCustomer($customerId);
|
$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->load->model('extension/retailcrm/customer');
|
||||||
$this->model_extension_retailcrm_customer->sendToCrm($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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,28 @@ class ModelExtensionRetailcrmCustomer extends Model {
|
|||||||
$this->retailcrmApi->customersCreate($customerToCrm);
|
$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) {
|
private function process($customer) {
|
||||||
$customerToCrm = array(
|
$customerToCrm = array(
|
||||||
'externalId' => $customer['customer_id'],
|
'externalId' => $customer['customer_id'],
|
||||||
|
Loading…
Reference in New Issue
Block a user