diff --git a/retailcrm/lib/RetailcrmOrderBuilder.php b/retailcrm/lib/RetailcrmOrderBuilder.php index 331112e..44ae657 100644 --- a/retailcrm/lib/RetailcrmOrderBuilder.php +++ b/retailcrm/lib/RetailcrmOrderBuilder.php @@ -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. diff --git a/retailcrm/lib/events/RetailcrmExportEvent.php b/retailcrm/lib/events/RetailcrmExportEvent.php index 1092de2..a34e6c7 100644 --- a/retailcrm/lib/events/RetailcrmExportEvent.php +++ b/retailcrm/lib/events/RetailcrmExportEvent.php @@ -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) {