create order on edit if it's not present in retailCRM

This commit is contained in:
Pavel 2020-04-23 15:41:11 +03:00 committed by GitHub
parent 36a9c12bf8
commit 5108111654
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 6 deletions

View File

@ -513,7 +513,25 @@ class RetailCRM extends Module
RetailcrmLogger::writeNoCaller($exception->getTraceAsString());
}
$orderCrm = $this->api->ordersGet($order['externalId']);
if (!($orderCrm instanceof RetailcrmApiResponse) || !$orderCrm->isSuccessful()) {
/** @var Order|\OrderCore $order */
$order = $params['order'];
$this->hookNewOrder(array(
'orderStatus' => $order->current_state,
'id_order' => (int) $order->id,
'order' => $order,
'cart' => new Cart($order->id_cart),
'customer' => new Customer($order->id_customer)
));
return false;
}
$comment = $orderdb->getFirstMessage();
if ($comment !== false) {
$order['customerComment'] = $comment;
}

View File

@ -11,7 +11,15 @@ class RetailCRMTest extends RetailcrmTestCase
$this->setConfig();
$this->apiMock = $this->getMockBuilder('RetailcrmProxy')
$this->apiMock = $this->apiMockBuilder()->getMock();
$this->retailcrmModule = new RetailCRM();
$this->retailcrmModule->api = $this->apiMock;
}
private function apiMockBuilder()
{
return $this->getMockBuilder('RetailcrmProxy')
->disableOriginalConstructor()
->setMethods(
array(
@ -24,11 +32,7 @@ class RetailCRMTest extends RetailcrmTestCase
'ordersPaymentEdit',
'ordersPaymentCreate'
)
)
->getMock();
$this->retailcrmModule = new RetailCRM();
$this->retailcrmModule->api = $this->apiMock;
);
}
public function testHookActionCustomerAccountAdd()
@ -52,6 +56,13 @@ class RetailCRMTest extends RetailcrmTestCase
$order = new Order(1);
$customer = new Customer($order->id_customer);
$params = array('order' => $order, 'customer' => $customer);
$this->apiMock->expects($this->any())->method('ordersGet')->willReturn(new RetailcrmApiResponse(
200,
json_encode(array(
'success' => true,
'order' => array()
))
));
$this->assertTrue($this->retailcrmModule->hookActionOrderEdited($params));
}