diff --git a/retailcrm/retailcrm.php b/retailcrm/retailcrm.php index 08e7128..f3a219c 100644 --- a/retailcrm/retailcrm.php +++ b/retailcrm/retailcrm.php @@ -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; } diff --git a/tests/RetailcrmTest.php b/tests/RetailcrmTest.php index 5bdcbd0..91de33c 100644 --- a/tests/RetailcrmTest.php +++ b/tests/RetailcrmTest.php @@ -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)); }