Fixed the error with same client addresses (#85)

This commit is contained in:
Dima Uryvskiy 2020-11-11 18:34:57 +03:00 committed by GitHub
parent f8620c9951
commit 41ce30b143
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 8 deletions

View File

@ -196,6 +196,24 @@ class RetailcrmOrderBuilder
return (empty($this->apiSite) || is_bool($this->apiSite)) ? null : $this->apiSite;
}
/**
* Clear object
*
* @return mixed
*/
public function reset()
{
$this->cmsOrder = null;
$this->cmsCart = null;
$this->cmsCustomer = null;
$this->invoiceAddress = null;
$this->deliveryAddress = null;
$this->createdCustomer = null;
$this->corporateCompanyExtractCache = null;
return $this;
}
/**
* Returns order with prepared customer data. Customer is created if it's not exist, shouldn't be called to just
* build order.

View File

@ -65,11 +65,21 @@ class RetailcrmExportEvent extends RetailcrmAbstractEvent implements RetailcrmEv
$orderBuilder->defaultLangFromConfiguration()->setApi($api);
foreach ($orderRecords as $record) {
$orderBuilder->reset();
$order = new Order($record['id_order']);
$orderCart = new Cart($order->id_cart);
$orderCustomer = new Customer($order->id_customer);
$orderBuilder->setCmsOrder($order);
if (!empty($orderCart->id)) {
$orderBuilder->setCmsCart($orderCart);
} else {
$orderBuilder->setCmsCart(null);
}
if (!empty($orderCustomer->id)) {
$orderBuilder->setCmsCustomer($orderCustomer);
} else {
@ -79,14 +89,6 @@ class RetailcrmExportEvent extends RetailcrmAbstractEvent implements RetailcrmEv
$orderBuilder->setCmsCustomer(null);
}
if (!empty($orderCart->id)) {
$orderBuilder->setCmsCart($orderCart);
} else {
$orderBuilder->setCmsCart(null);
}
$orderBuilder->setCmsOrder($order);
try {
$orders[] = $orderBuilder->buildOrderWithPreparedCustomer();
} catch (\InvalidArgumentException $exception) {