Fixed resetting customer's fields in Prestashop in case of it deleting in RetailCRM

This commit is contained in:
opheugene 2020-11-19 12:29:30 +03:00 committed by GitHub
parent 114ae5efd1
commit 54959b7a15
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 20 deletions

View File

@ -87,34 +87,39 @@ class RetailcrmHistory
$customerBuilder->setDataCrm($customerHistory); $customerBuilder->setDataCrm($customerHistory);
if (isset($customerHistory['externalId'])) { if (isset($customerHistory['externalId'])) {
$customerData = self::$api->customersGet($customerHistory['externalId'], 'externalId'); $customerData = self::$api->customersGet($customerHistory['externalId'], 'externalId');
$foundCustomer = new Customer($customerHistory['externalId']); if (isset($customerData['customer']) && $customerData['customer']) {
$customerAddress = new Address(RetailcrmTools::searchIndividualAddress($foundCustomer));
$addressBuilder = new RetailcrmCustomerAddressBuilder();
$addressBuilder $foundCustomer = new Customer($customerHistory['externalId']);
->setCustomerAddress($customerAddress); $customerAddress = new Address(RetailcrmTools::searchIndividualAddress($foundCustomer));
$addressBuilder = new RetailcrmCustomerAddressBuilder();
$customerBuilder $addressBuilder
->setCustomer($foundCustomer) ->setCustomerAddress($customerAddress);
->setAddressBuilder($addressBuilder)
->setDataCrm($customerData['customer'])
->build();
$customer = $customerBuilder->getData()->getCustomer(); $customerBuilder
$address = $customerBuilder->getData()->getCustomerAddress(); ->setCustomer($foundCustomer)
->setAddressBuilder($addressBuilder)
->setDataCrm($customerData['customer'])
->build();
if (self::loadInCMS($customer, 'update') === false) { $customer = $customerBuilder->getData()->getCustomer();
continue; $address = $customerBuilder->getData()->getCustomerAddress();
}
if (!empty($address)) { if (self::loadInCMS($customer, 'update') === false) {
RetailcrmTools::assignAddressIdsByFields($customer, $address);
if (self::loadInCMS($address, 'update') === false) {
continue; continue;
} }
if (!empty($address)) {
RetailcrmTools::assignAddressIdsByFields($customer, $address);
if (self::loadInCMS($address, 'update') === false) {
continue;
}
}
} }
} else { } else {
$customerBuilder->build(); $customerBuilder->build();

View File

@ -171,7 +171,6 @@ class RetailcrmHistoryHelper {
if (isset($change['deleted']) if (isset($change['deleted'])
&& $change['deleted'] && $change['deleted']
&& isset($customers[$change['customer']['id']])
) { ) {
$customers[$change['customer']['id']]['deleted'] = true; $customers[$change['customer']['id']]['deleted'] = true;
continue; continue;

View File

@ -47,6 +47,19 @@ class RetailcrmHistoryTest extends RetailcrmTestCase
) )
); );
$this->apiMock->expects($this->any())
->method('customersGet')
->willReturn(
new RetailcrmApiResponse(
'200',
json_encode(
array(
'customer' => $this->getApiCustomer()
)
)
)
);
RetailcrmHistory::$default_lang = (int)Configuration::get('PS_LANG_DEFAULT'); RetailcrmHistory::$default_lang = (int)Configuration::get('PS_LANG_DEFAULT');
RetailcrmHistory::$api = $this->apiMock; RetailcrmHistory::$api = $this->apiMock;