mirror of
https://github.com/retailcrm/opencart-module.git
synced 2024-11-23 21:56:07 +03:00
Create customer if not exist within manual upload
This commit is contained in:
parent
a1f97bc996
commit
4f15310fbb
@ -39,7 +39,10 @@ class OrderManager {
|
||||
public function createOrder($order_data, $order_products, $order_totals) {
|
||||
$order = $this->prepareOrder($order_data, $order_products, $order_totals);
|
||||
|
||||
if (!isset($order['customer'])) {
|
||||
if (!isset($order['customer'])
|
||||
|| (isset($order['customer']['externalId'])
|
||||
&& !$this->checkExistCustomer($order['customer']['externalId']))
|
||||
) {
|
||||
$customer = $this->customer_manager->getCustomerForOrder($order_data);
|
||||
if (!empty($customer)) {
|
||||
$order['customer'] = $customer;
|
||||
@ -167,4 +170,15 @@ class OrderManager {
|
||||
$this->api->ordersPaymentEdit($order_payment);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $customerExternalId Customer's external id
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function checkExistCustomer($customerExternalId) {
|
||||
$result = $this->api->customersGet($customerExternalId);
|
||||
|
||||
return $result && $result->isSuccessful() && $result->offsetExists('customer');
|
||||
}
|
||||
}
|
||||
|
@ -10,11 +10,32 @@ class OrderManagerTest extends TestCase {
|
||||
public function testCreateOrderWithCustomer() {
|
||||
$proxy = $this->getMockBuilder(\RetailcrmProxy::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(['ordersCreate'])
|
||||
->setMethods(['ordersCreate','customersGet'])
|
||||
->getMock();
|
||||
|
||||
$proxy->expects($this->once())->method('ordersCreate');
|
||||
|
||||
$proxy->expects($this->once())
|
||||
->method('customersGet')
|
||||
->willReturn(new \RetailcrmApiResponse(
|
||||
200,
|
||||
json_encode(
|
||||
[
|
||||
'success' => true,
|
||||
'pagination' => [
|
||||
'limit'=> 20,
|
||||
'totalCount' => 0,
|
||||
'currentPage' => 1,
|
||||
'totalPageCount' => 0
|
||||
],
|
||||
'customer' => [
|
||||
'id' => 1,
|
||||
'externalId' => 1
|
||||
]
|
||||
]
|
||||
)
|
||||
));
|
||||
|
||||
$order_manager = $this->getOrderManager($proxy);
|
||||
|
||||
$orderCheckoutModel = $this->loadModel('checkout/order');
|
||||
|
Loading…
Reference in New Issue
Block a user