mirror of
https://github.com/retailcrm/prestashop-module.git
synced 2025-03-01 19:03:14 +03:00
Added customer search by email
This commit is contained in:
parent
4098be6a13
commit
c27a932f2e
@ -1,5 +1,10 @@
|
||||
# Customers
|
||||
|
||||
## Предотвращение дублирования клиентов
|
||||
|
||||
При создании нового клиента в Prestashop происходит поиск клиента в CRM по externalId и по email. Если клиент найден, то в CRM обновляется его адрес и `externalId`.
|
||||
Для отключения поиска по email необходимо использовать [фильтр](../../3.%20Customization/Filters.md) `RetailcrmFilterFindCustomerByEmail`, который должен возвращать пустой массив `[]`.
|
||||
|
||||
## Адреса корпоративных клиентов
|
||||
|
||||
Клиент считается корпоративным, если в его `invoice address` поле `company` не пустое.
|
||||
|
@ -2,4 +2,9 @@
|
||||
|
||||
## Create
|
||||
|
||||
## Предотвращение дублирования клиентов
|
||||
|
||||
При создании нового заказа в Prestashop происходит поиск клиента в CRM по externalId и по email. Если клиент найден, то в CRM обновляется его адрес и `externalId`.
|
||||
Для отключения поиска по email необходимо использовать [фильтр](../../3.%20Customization/Filters.md) `RetailcrmFilterFindCustomerByEmail`, который должен возвращать пустой массив `[]`.
|
||||
|
||||
## Update
|
||||
|
@ -25,6 +25,7 @@ There are list of available filters:
|
||||
* *RetailcrmFilterOrdersHistoryCreate* - array with order info, loaded from CRM
|
||||
* *RetailcrmFilterOrdersHistoryUpdate* - array with assembled history for order, loaded from CRM
|
||||
|
||||
* *RetailcrmFilterFindCustomerByEmail* - customer array, found by email in CRM (to prevent duplicating)
|
||||
* *RetailcrmFilterSaveCustomer* - built customer object, which will be saved to CMS
|
||||
* *RetailcrmFilterSaveCustomerAddress* - built customer address object, which will be saved to CMS
|
||||
* *RetailcrmFilterSaveCorporateCustomer* - built corporate customer object, which will be saved to CMS
|
||||
|
@ -251,7 +251,7 @@ class RetailcrmOrderBuilder
|
||||
*
|
||||
* @return array|bool
|
||||
*/
|
||||
private function createCustomerIfNotExist()
|
||||
public function createCustomerIfNotExist()
|
||||
{
|
||||
$this->validateCmsCustomer();
|
||||
|
||||
@ -271,12 +271,24 @@ class RetailcrmOrderBuilder
|
||||
$customer = $this->createdCustomer;
|
||||
} else {
|
||||
$crmCustomer = RetailcrmTools::mergeCustomerAddress($customer, $this->buildRegularAddress());
|
||||
if (!RetailcrmTools::isEqualCustomerAddress($customer, $crmCustomer)) {
|
||||
|
||||
if (
|
||||
!RetailcrmTools::isEqualCustomerAddress($customer, $crmCustomer)
|
||||
|| !isset($crmCustomer['externalId'])
|
||||
|| $crmCustomer['externalId'] !== $this->cmsCustomer->id
|
||||
) {
|
||||
if (isset($crmCustomer['tags'])) {
|
||||
unset($crmCustomer['tags']);
|
||||
}
|
||||
|
||||
$response = $this->api->customersEdit($crmCustomer);
|
||||
$by = 'externalId';
|
||||
|
||||
if (!isset($crmCustomer['externalId']) || $crmCustomer['externalId'] !== $this->cmsCustomer->id) {
|
||||
$crmCustomer['externalId'] = $this->cmsCustomer->id;
|
||||
$by = 'id';
|
||||
}
|
||||
|
||||
$response = $this->api->customersEdit($crmCustomer, $by);
|
||||
|
||||
if ($response instanceof RetailcrmApiResponse && $response->isSuccessful()) {
|
||||
$customer = $crmCustomer;
|
||||
@ -609,21 +621,7 @@ class RetailcrmOrderBuilder
|
||||
{
|
||||
$this->validateCmsCustomer();
|
||||
|
||||
if (empty($this->cmsCustomer->id) || $this->cmsCustomer->is_guest) {
|
||||
if (!empty($this->cmsCustomer->email)) {
|
||||
$customers = $this->api->customersList(['email' => $this->cmsCustomer->email]);
|
||||
|
||||
if ($customers
|
||||
&& $customers->isSuccessful()
|
||||
&& $customers->offsetExists('customers')
|
||||
&& !empty($customers['customers'])
|
||||
) {
|
||||
$customers = $customers['customers'];
|
||||
|
||||
return reset($customers);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!empty($this->cmsCustomer->id) && !$this->cmsCustomer->is_guest) {
|
||||
$customer = $this->api->customersGet($this->cmsCustomer->id);
|
||||
|
||||
if ($customer && $customer->isSuccessful() && $customer->offsetExists('customer')) {
|
||||
@ -631,6 +629,28 @@ class RetailcrmOrderBuilder
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($this->cmsCustomer->email)) {
|
||||
$customers = $this->api->customersList(['email' => $this->cmsCustomer->email]);
|
||||
|
||||
if ($customers
|
||||
&& $customers->isSuccessful()
|
||||
&& $customers->offsetExists('customers')
|
||||
&& !empty($customers['customers'])
|
||||
) {
|
||||
$customer = reset($customers['customers']);
|
||||
|
||||
if ($customer['email'] === $this->cmsCustomer->email) {
|
||||
return RetailcrmTools::filter(
|
||||
'RetailcrmFilterFindCustomerByEmail',
|
||||
$customer,
|
||||
[
|
||||
'cmsCustomer' => $this->cmsCustomer,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
|
@ -460,9 +460,14 @@ class RetailCRM extends Module
|
||||
{
|
||||
if ($this->api) {
|
||||
$customer = $params['newCustomer'];
|
||||
$customerSend = RetailcrmOrderBuilder::buildCrmCustomer($customer);
|
||||
|
||||
$this->api->customersCreate($customerSend);
|
||||
$orderBuilder = new RetailcrmOrderBuilder();
|
||||
$orderBuilder
|
||||
->defaultLangFromConfiguration()
|
||||
->setApi($this->api)
|
||||
->setCmsCustomer($customer)
|
||||
->createCustomerIfNotExist()
|
||||
;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user