mirror of
https://github.com/retailcrm/opencart-module.git
synced 2024-11-23 21:56:07 +03:00
This commit is contained in:
parent
a375804086
commit
571263ca2c
@ -1,3 +1,6 @@
|
||||
## v4.1.13
|
||||
* Changed the logic of customer subscriptions to promotional newsletters
|
||||
|
||||
## v4.1.12
|
||||
* Added escaping for db query in method for getting zone
|
||||
|
||||
|
@ -822,6 +822,13 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
||||
'extension/module/retailcrm/customer_edit'
|
||||
);
|
||||
|
||||
$this->{'model_' . $this->modelEvent}
|
||||
->addEvent(
|
||||
$this->moduleTitle,
|
||||
'catalog/model/account/customer/editNewsletter/after',
|
||||
'extension/module/retailcrm/customer_edit_newsletter'
|
||||
);
|
||||
|
||||
$this->{'model_' . $this->modelEvent}
|
||||
->addEvent(
|
||||
$this->moduleTitle,
|
||||
|
@ -138,6 +138,20 @@ class ControllerExtensionModuleRetailcrm extends Controller {
|
||||
}
|
||||
}
|
||||
|
||||
public function customer_edit_newsletter($parameter1, $parameter2, $parameter3)
|
||||
{
|
||||
$customerId = $this->customer->getId();
|
||||
$customer = $this->model_account_customer->getCustomer($customerId);
|
||||
|
||||
if (file_exists(DIR_APPLICATION . 'model/extension/retailcrm/custom/customer.php')) {
|
||||
$this->load->model('extension/retailcrm/custom/customer');
|
||||
$this->model_extension_retailcrm_custom_customer->changeInCrm($customer, $this->retailcrmApiClient);
|
||||
} else {
|
||||
$customer_manager = $this->retailcrm->getCustomerManager();
|
||||
$customer_manager->editCustomerNewsLetter($customer);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update customer on event
|
||||
*
|
||||
|
@ -38,10 +38,14 @@ class Customer {
|
||||
}
|
||||
|
||||
$customer_data['firstname'] = $customer['firstName'];
|
||||
$customer_data['lastname'] = isset($customer['lastName']) ? $customer['lastName'] : '';
|
||||
$customer_data['lastname'] = $customer['lastName'] ?? '';
|
||||
$customer_data['email'] = $customer['email'];
|
||||
$customer_data['telephone'] = $customer['phones'] ? $customer['phones'][0]['number'] : '';
|
||||
|
||||
if (!empty($customer['emailMarketingUnsubscribedAt'])) {
|
||||
$customer_data['newsletter'] = 0;
|
||||
}
|
||||
|
||||
$customer_data['affiliate'] = false;
|
||||
}
|
||||
|
||||
@ -109,7 +113,7 @@ class Customer {
|
||||
}
|
||||
}
|
||||
|
||||
$customer_data['custom_field'] = isset($custom_fields) ? $custom_fields : '';
|
||||
$customer_data['custom_field'] = $custom_fields ?? [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ class CustomerManager {
|
||||
}
|
||||
|
||||
public function createCustomer($customer_data, $address) {
|
||||
$customer = $this->prepareCustomer($customer_data, $address);
|
||||
$customer = $this->prepareCustomer($customer_data, $address, !empty($customer_data['newsletter']));
|
||||
|
||||
$this->api->customersCreate($customer);
|
||||
}
|
||||
@ -23,13 +23,22 @@ class CustomerManager {
|
||||
$this->api->customersEdit($customer);
|
||||
}
|
||||
|
||||
public function editCustomerNewsLetter($customer_data) {
|
||||
$this->api->customersEdit(
|
||||
[
|
||||
'externalId' => $customer_data['customer_id'],
|
||||
'subscribed' => !empty($customer_data['newsletter']),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function uploadCustomers($customers) {
|
||||
$this->api->customersUpload($customers);
|
||||
}
|
||||
|
||||
public function prepareCustomer($customer_data, $address) {
|
||||
public function prepareCustomer($customer_data, $address, $isSubscribed = null) {
|
||||
return $this->customer_converter
|
||||
->initCustomerData($customer_data, $address)
|
||||
->initCustomerData($customer_data, $address, $isSubscribed)
|
||||
->setCustomerData()
|
||||
->setAddress()
|
||||
->setCustomFields()
|
||||
|
@ -4,9 +4,9 @@ namespace retailcrm\service;
|
||||
|
||||
class RetailcrmCustomerConverter {
|
||||
protected $data;
|
||||
protected $customer_data = array();
|
||||
protected $address = array();
|
||||
|
||||
protected $customer_data = [];
|
||||
protected $address = [];
|
||||
protected $isSubscribed;
|
||||
protected $settingsManager;
|
||||
|
||||
public function __construct(
|
||||
@ -19,10 +19,11 @@ class RetailcrmCustomerConverter {
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
public function initCustomerData($customer_data, $address) {
|
||||
$this->data = array();
|
||||
public function initCustomerData($customer_data, $address, $isSubscribed) {
|
||||
$this->data = [];
|
||||
$this->customer_data = $customer_data;
|
||||
$this->address = $address;
|
||||
$this->isSubscribed = $isSubscribed;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@ -34,12 +35,12 @@ class RetailcrmCustomerConverter {
|
||||
$this->data['email'] = $this->customer_data['email'];
|
||||
$this->data['createdAt'] = $this->customer_data['date_added'];
|
||||
|
||||
if ($this->isSubscribed !== null) {
|
||||
$this->data['subscribed'] = $this->isSubscribed;
|
||||
}
|
||||
|
||||
if (!empty($this->customer_data['telephone'])) {
|
||||
$this->data['phones'] = array(
|
||||
array(
|
||||
'number' => $this->customer_data['telephone']
|
||||
)
|
||||
);
|
||||
$this->data['phones'] = [['number' => $this->customer_data['telephone']]];
|
||||
}
|
||||
|
||||
return $this;
|
||||
@ -47,13 +48,13 @@ class RetailcrmCustomerConverter {
|
||||
|
||||
public function setAddress() {
|
||||
if (!empty($this->address)) {
|
||||
$this->data['address'] = array(
|
||||
$this->data['address'] = [
|
||||
'index' => $this->address['postcode'],
|
||||
'countryIso' => $this->address['iso_code_2'],
|
||||
'region' => $this->address['zone'],
|
||||
'city' => $this->address['city'],
|
||||
'text' => $this->address['address_1'] . ' ' . $this->address['address_2']
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
return $this;
|
||||
|
@ -14,6 +14,7 @@
|
||||
<field id="cumulative_discount" group="customer">cumulativeDiscount</field>
|
||||
<field id="personal_discount" group="customer">personalDiscount</field>
|
||||
<field id="discount_card_number" group="customer">discountCardNumber</field>
|
||||
<field id="email_marketing_unsubscribed_at" group="customer">emailMarketingUnsubscribedAt</field>
|
||||
|
||||
<field id="address.index" group="customerAddress">index</field>
|
||||
<field id="address.country" group="customerAddress">country</field>
|
||||
|
@ -11,7 +11,7 @@ class RetailcrmCustomerConverterTest extends TestCase {
|
||||
$customer_data = $model->getCustomer(1);
|
||||
|
||||
$customer = $converter
|
||||
->initCustomerData($customer_data, array())
|
||||
->initCustomerData($customer_data, [], true)
|
||||
->setCustomerData()
|
||||
->getCustomer();
|
||||
|
||||
@ -20,23 +20,24 @@ class RetailcrmCustomerConverterTest extends TestCase {
|
||||
$this->assertEquals($customer_data['lastname'], $customer['lastName']);
|
||||
$this->assertEquals($customer_data['email'], $customer['email']);
|
||||
$this->assertEquals($customer_data['date_added'], $customer['createdAt']);
|
||||
$this->assertTrue($customer['subscribed']);
|
||||
}
|
||||
|
||||
public function testSetAddress() {
|
||||
$converter = \retailcrm\factory\CustomerConverterFactory::create(static::$registry);
|
||||
$model = $this->loadModel('account/customer');
|
||||
$customer_data = $model->getCustomer(static::CUSTOMER_ID);
|
||||
$address = array(
|
||||
$address = [
|
||||
'postcode' => '111111',
|
||||
'iso_code_2' => 'EN',
|
||||
'zone' => 'Zone',
|
||||
'city' => 'City',
|
||||
'address_1' => 'Address',
|
||||
'address_2' => ''
|
||||
);
|
||||
];
|
||||
|
||||
$customer = $converter
|
||||
->initCustomerData($customer_data, $address)
|
||||
->initCustomerData($customer_data, $address, null)
|
||||
->setAddress()
|
||||
->getCustomer();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user