opencart-module/admin/model/extension/retailcrm/customer.php
iyzoer 3be4ac76a9 Update to v2.3 (#22)
* restruct for 2.3
* new files for 2.3
2017-03-22 12:12:54 +03:00

52 lines
1.5 KiB
PHP

<?php
class ModelExtensionRetailcrmCustomer extends Model {
public function uploadToCrm($customers) {
$this->load->model('setting/setting');
$settings = $this->model_setting_setting->getSetting('retailcrm');
if(empty($customers))
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'
);
$customersToCrm = array();
foreach($customers as $customer) {
$customersToCrm[] = $this->process($customer);
}
$chunkedCustomers = array_chunk($customersToCrm, 50);
foreach($chunkedCustomers as $customersPart) {
$this->retailcrmApi->customersUpload($customersPart);
}
}
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;
}
}