mirror of
https://github.com/retailcrm/opencart-module.git
synced 2024-11-21 12:46:06 +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
|
## v4.1.12
|
||||||
* Added escaping for db query in method for getting zone
|
* Added escaping for db query in method for getting zone
|
||||||
|
|
||||||
|
@ -822,6 +822,13 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
|||||||
'extension/module/retailcrm/customer_edit'
|
'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}
|
$this->{'model_' . $this->modelEvent}
|
||||||
->addEvent(
|
->addEvent(
|
||||||
$this->moduleTitle,
|
$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
|
* Update customer on event
|
||||||
*
|
*
|
||||||
|
@ -38,10 +38,14 @@ class Customer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$customer_data['firstname'] = $customer['firstName'];
|
$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['email'] = $customer['email'];
|
||||||
$customer_data['telephone'] = $customer['phones'] ? $customer['phones'][0]['number'] : '';
|
$customer_data['telephone'] = $customer['phones'] ? $customer['phones'][0]['number'] : '';
|
||||||
|
|
||||||
|
if (!empty($customer['emailMarketingUnsubscribedAt'])) {
|
||||||
|
$customer_data['newsletter'] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
$customer_data['affiliate'] = false;
|
$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) {
|
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);
|
$this->api->customersCreate($customer);
|
||||||
}
|
}
|
||||||
@ -23,13 +23,22 @@ class CustomerManager {
|
|||||||
$this->api->customersEdit($customer);
|
$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) {
|
public function uploadCustomers($customers) {
|
||||||
$this->api->customersUpload($customers);
|
$this->api->customersUpload($customers);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function prepareCustomer($customer_data, $address) {
|
public function prepareCustomer($customer_data, $address, $isSubscribed = null) {
|
||||||
return $this->customer_converter
|
return $this->customer_converter
|
||||||
->initCustomerData($customer_data, $address)
|
->initCustomerData($customer_data, $address, $isSubscribed)
|
||||||
->setCustomerData()
|
->setCustomerData()
|
||||||
->setAddress()
|
->setAddress()
|
||||||
->setCustomFields()
|
->setCustomFields()
|
||||||
|
@ -4,9 +4,9 @@ namespace retailcrm\service;
|
|||||||
|
|
||||||
class RetailcrmCustomerConverter {
|
class RetailcrmCustomerConverter {
|
||||||
protected $data;
|
protected $data;
|
||||||
protected $customer_data = array();
|
protected $customer_data = [];
|
||||||
protected $address = array();
|
protected $address = [];
|
||||||
|
protected $isSubscribed;
|
||||||
protected $settingsManager;
|
protected $settingsManager;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
@ -19,10 +19,11 @@ class RetailcrmCustomerConverter {
|
|||||||
return $this->data;
|
return $this->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function initCustomerData($customer_data, $address) {
|
public function initCustomerData($customer_data, $address, $isSubscribed) {
|
||||||
$this->data = array();
|
$this->data = [];
|
||||||
$this->customer_data = $customer_data;
|
$this->customer_data = $customer_data;
|
||||||
$this->address = $address;
|
$this->address = $address;
|
||||||
|
$this->isSubscribed = $isSubscribed;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@ -34,12 +35,12 @@ class RetailcrmCustomerConverter {
|
|||||||
$this->data['email'] = $this->customer_data['email'];
|
$this->data['email'] = $this->customer_data['email'];
|
||||||
$this->data['createdAt'] = $this->customer_data['date_added'];
|
$this->data['createdAt'] = $this->customer_data['date_added'];
|
||||||
|
|
||||||
|
if ($this->isSubscribed !== null) {
|
||||||
|
$this->data['subscribed'] = $this->isSubscribed;
|
||||||
|
}
|
||||||
|
|
||||||
if (!empty($this->customer_data['telephone'])) {
|
if (!empty($this->customer_data['telephone'])) {
|
||||||
$this->data['phones'] = array(
|
$this->data['phones'] = [['number' => $this->customer_data['telephone']]];
|
||||||
array(
|
|
||||||
'number' => $this->customer_data['telephone']
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
@ -47,13 +48,13 @@ class RetailcrmCustomerConverter {
|
|||||||
|
|
||||||
public function setAddress() {
|
public function setAddress() {
|
||||||
if (!empty($this->address)) {
|
if (!empty($this->address)) {
|
||||||
$this->data['address'] = array(
|
$this->data['address'] = [
|
||||||
'index' => $this->address['postcode'],
|
'index' => $this->address['postcode'],
|
||||||
'countryIso' => $this->address['iso_code_2'],
|
'countryIso' => $this->address['iso_code_2'],
|
||||||
'region' => $this->address['zone'],
|
'region' => $this->address['zone'],
|
||||||
'city' => $this->address['city'],
|
'city' => $this->address['city'],
|
||||||
'text' => $this->address['address_1'] . ' ' . $this->address['address_2']
|
'text' => $this->address['address_1'] . ' ' . $this->address['address_2']
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
<field id="cumulative_discount" group="customer">cumulativeDiscount</field>
|
<field id="cumulative_discount" group="customer">cumulativeDiscount</field>
|
||||||
<field id="personal_discount" group="customer">personalDiscount</field>
|
<field id="personal_discount" group="customer">personalDiscount</field>
|
||||||
<field id="discount_card_number" group="customer">discountCardNumber</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.index" group="customerAddress">index</field>
|
||||||
<field id="address.country" group="customerAddress">country</field>
|
<field id="address.country" group="customerAddress">country</field>
|
||||||
|
@ -11,7 +11,7 @@ class RetailcrmCustomerConverterTest extends TestCase {
|
|||||||
$customer_data = $model->getCustomer(1);
|
$customer_data = $model->getCustomer(1);
|
||||||
|
|
||||||
$customer = $converter
|
$customer = $converter
|
||||||
->initCustomerData($customer_data, array())
|
->initCustomerData($customer_data, [], true)
|
||||||
->setCustomerData()
|
->setCustomerData()
|
||||||
->getCustomer();
|
->getCustomer();
|
||||||
|
|
||||||
@ -20,23 +20,24 @@ class RetailcrmCustomerConverterTest extends TestCase {
|
|||||||
$this->assertEquals($customer_data['lastname'], $customer['lastName']);
|
$this->assertEquals($customer_data['lastname'], $customer['lastName']);
|
||||||
$this->assertEquals($customer_data['email'], $customer['email']);
|
$this->assertEquals($customer_data['email'], $customer['email']);
|
||||||
$this->assertEquals($customer_data['date_added'], $customer['createdAt']);
|
$this->assertEquals($customer_data['date_added'], $customer['createdAt']);
|
||||||
|
$this->assertTrue($customer['subscribed']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSetAddress() {
|
public function testSetAddress() {
|
||||||
$converter = \retailcrm\factory\CustomerConverterFactory::create(static::$registry);
|
$converter = \retailcrm\factory\CustomerConverterFactory::create(static::$registry);
|
||||||
$model = $this->loadModel('account/customer');
|
$model = $this->loadModel('account/customer');
|
||||||
$customer_data = $model->getCustomer(static::CUSTOMER_ID);
|
$customer_data = $model->getCustomer(static::CUSTOMER_ID);
|
||||||
$address = array(
|
$address = [
|
||||||
'postcode' => '111111',
|
'postcode' => '111111',
|
||||||
'iso_code_2' => 'EN',
|
'iso_code_2' => 'EN',
|
||||||
'zone' => 'Zone',
|
'zone' => 'Zone',
|
||||||
'city' => 'City',
|
'city' => 'City',
|
||||||
'address_1' => 'Address',
|
'address_1' => 'Address',
|
||||||
'address_2' => ''
|
'address_2' => ''
|
||||||
);
|
];
|
||||||
|
|
||||||
$customer = $converter
|
$customer = $converter
|
||||||
->initCustomerData($customer_data, $address)
|
->initCustomerData($customer_data, $address, null)
|
||||||
->setAddress()
|
->setAddress()
|
||||||
->getCustomer();
|
->getCustomer();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user