2018-10-05 17:50:20 +03:00
|
|
|
<?php
|
2021-12-06 14:37:43 +03:00
|
|
|
/**
|
|
|
|
* MIT License
|
|
|
|
*
|
|
|
|
* Copyright (c) 2021 DIGITAL RETAIL TECHNOLOGIES SL
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
|
|
|
*
|
|
|
|
* DISCLAIMER
|
|
|
|
*
|
|
|
|
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
|
|
|
* versions in the future. If you wish to customize PrestaShop for your
|
|
|
|
* needs please refer to http://www.prestashop.com for more information.
|
|
|
|
*
|
|
|
|
* @author DIGITAL RETAIL TECHNOLOGIES SL <mail@simlachat.com>
|
|
|
|
* @copyright 2021 DIGITAL RETAIL TECHNOLOGIES SL
|
|
|
|
* @license https://opensource.org/licenses/MIT The MIT License
|
|
|
|
*
|
|
|
|
* Don't forget to prefix your containers with your own identifier
|
|
|
|
* to avoid any conflicts with others containers.
|
|
|
|
*/
|
2018-10-05 17:50:20 +03:00
|
|
|
|
|
|
|
class RetailcrmHistoryTest extends RetailcrmTestCase
|
|
|
|
{
|
|
|
|
private $apiMock;
|
|
|
|
private $product;
|
|
|
|
|
2021-11-03 16:19:39 +07:00
|
|
|
protected function setUp()
|
2018-10-05 17:50:20 +03:00
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
2021-12-06 14:37:43 +03:00
|
|
|
$this->apiMock = $this->getApiMock(
|
|
|
|
[
|
|
|
|
'customersHistory',
|
|
|
|
'ordersHistory',
|
|
|
|
'ordersGet',
|
|
|
|
'ordersEdit',
|
|
|
|
'customersGet',
|
|
|
|
'customersFixExternalIds',
|
|
|
|
'ordersFixExternalIds',
|
|
|
|
'customersCorporateAddressesEdit',
|
|
|
|
]
|
|
|
|
);
|
2018-10-05 17:50:20 +03:00
|
|
|
|
|
|
|
$catalog = new RetailcrmCatalog();
|
|
|
|
$data = $catalog->getData();
|
2020-12-28 14:51:01 +03:00
|
|
|
$this->product = $data[1]->current();
|
2018-10-05 17:50:20 +03:00
|
|
|
|
2021-07-30 14:30:51 +03:00
|
|
|
Configuration::updateValue(RetailCRM::DELIVERY_DEFAULT, 2);
|
|
|
|
Configuration::updateValue(RetailCRM::PAYMENT_DEFAULT, 'bankwire');
|
2018-10-05 17:50:20 +03:00
|
|
|
|
|
|
|
$this->setConfig();
|
|
|
|
}
|
|
|
|
|
2020-07-08 16:09:45 +03:00
|
|
|
public function testCustomersHistory()
|
|
|
|
{
|
2021-12-06 14:37:43 +03:00
|
|
|
$this->apiClientMock->expects($this->any())
|
2020-07-08 16:09:45 +03:00
|
|
|
->method('customersHistory')
|
|
|
|
->willReturn(
|
|
|
|
new RetailcrmApiResponse(
|
|
|
|
'200',
|
|
|
|
json_encode(
|
|
|
|
$this->getHistoryDataNewCustomer()
|
|
|
|
)
|
|
|
|
)
|
2021-11-03 16:19:39 +07:00
|
|
|
)
|
|
|
|
;
|
2020-07-08 16:09:45 +03:00
|
|
|
|
2021-12-06 14:37:43 +03:00
|
|
|
$this->apiClientMock->expects($this->any())
|
2020-11-19 12:29:30 +03:00
|
|
|
->method('customersGet')
|
|
|
|
->willReturn(
|
|
|
|
new RetailcrmApiResponse(
|
|
|
|
'200',
|
|
|
|
json_encode(
|
2021-11-03 16:19:39 +07:00
|
|
|
[
|
|
|
|
'customer' => $this->getApiCustomer(),
|
|
|
|
]
|
2020-11-19 12:29:30 +03:00
|
|
|
)
|
|
|
|
)
|
2021-11-03 16:19:39 +07:00
|
|
|
)
|
|
|
|
;
|
2020-11-19 12:29:30 +03:00
|
|
|
|
2021-11-03 16:19:39 +07:00
|
|
|
RetailcrmHistory::$default_lang = (int) Configuration::get('PS_LANG_DEFAULT');
|
2020-07-08 16:09:45 +03:00
|
|
|
RetailcrmHistory::$api = $this->apiMock;
|
|
|
|
|
|
|
|
$externalId = isset($this->getApiCustomer()['externalId']) ? $this->getApiCustomer()['externalId'] : null;
|
|
|
|
|
2021-11-03 16:19:39 +07:00
|
|
|
if (!empty($externalId)) {
|
2020-07-08 16:09:45 +03:00
|
|
|
$oldCustomer = new Customer($externalId);
|
|
|
|
RetailcrmHistory::customersHistory();
|
|
|
|
$newCustomer = new Customer($externalId);
|
|
|
|
|
|
|
|
$this->assertNotEquals($oldCustomer, $newCustomer);
|
|
|
|
} else {
|
|
|
|
$oldLastId = RetailcrmTestHelper::getMaxCustomerId();
|
|
|
|
RetailcrmHistory::customersHistory();
|
|
|
|
$newLastId = RetailcrmTestHelper::getMaxCustomerId();
|
|
|
|
|
|
|
|
$this->assertTrue($newLastId > $oldLastId);
|
|
|
|
}
|
|
|
|
|
2021-11-03 16:19:39 +07:00
|
|
|
$this->assertTrue(RetailcrmHistory::customersHistory());
|
2020-07-08 16:09:45 +03:00
|
|
|
}
|
|
|
|
|
2021-07-30 14:30:51 +03:00
|
|
|
public function testOrdersHistory()
|
|
|
|
{
|
2021-11-03 16:19:39 +07:00
|
|
|
RetailcrmHistory::$default_lang = (int) Configuration::get('PS_LANG_DEFAULT');
|
2021-07-30 14:30:51 +03:00
|
|
|
RetailcrmHistory::$api = $this->apiMock;
|
|
|
|
|
|
|
|
$order = new Order(1);
|
|
|
|
$reference = $order->reference;
|
|
|
|
$updReference = 'test';
|
|
|
|
$crmOrder = $this->getApiOrder();
|
|
|
|
$crmOrder['number'] = $updReference;
|
2021-11-03 16:19:39 +07:00
|
|
|
$checkArgs = [
|
|
|
|
'externalId' => 1,
|
2021-07-30 14:30:51 +03:00
|
|
|
'number' => $reference,
|
2021-11-03 16:19:39 +07:00
|
|
|
];
|
2021-07-30 14:30:51 +03:00
|
|
|
|
2021-12-06 14:37:43 +03:00
|
|
|
$this->apiClientMock->expects($this->any())
|
2021-07-30 14:30:51 +03:00
|
|
|
->method('ordersHistory')
|
|
|
|
->willReturn(
|
|
|
|
new RetailcrmApiResponse(
|
|
|
|
'200',
|
|
|
|
json_encode(
|
|
|
|
$this->getHistoryExistOrder($crmOrder)
|
|
|
|
)
|
|
|
|
)
|
2021-11-03 16:19:39 +07:00
|
|
|
)
|
|
|
|
;
|
2021-07-30 14:30:51 +03:00
|
|
|
|
2021-12-06 14:37:43 +03:00
|
|
|
$this->apiClientMock->expects($this->any())
|
2021-07-30 14:30:51 +03:00
|
|
|
->method('ordersGet')
|
|
|
|
->willReturn(
|
|
|
|
new RetailcrmApiResponse(
|
|
|
|
'200',
|
|
|
|
json_encode(
|
2021-11-03 16:19:39 +07:00
|
|
|
[
|
2021-07-30 14:30:51 +03:00
|
|
|
'order' => $crmOrder,
|
2021-11-03 16:19:39 +07:00
|
|
|
]
|
2021-07-30 14:30:51 +03:00
|
|
|
)
|
|
|
|
)
|
2021-11-03 16:19:39 +07:00
|
|
|
)
|
|
|
|
;
|
2021-07-30 14:30:51 +03:00
|
|
|
|
2021-12-06 14:37:43 +03:00
|
|
|
$this->apiClientMock->expects($this->once())
|
2021-07-30 14:30:51 +03:00
|
|
|
->method('ordersEdit')
|
|
|
|
->with($checkArgs)
|
|
|
|
->willReturn(
|
|
|
|
new RetailcrmApiResponse(
|
|
|
|
'200',
|
|
|
|
json_encode(
|
2021-11-03 16:19:39 +07:00
|
|
|
[
|
2021-11-15 15:14:16 +03:00
|
|
|
'success' => true,
|
2021-12-06 14:37:43 +03:00
|
|
|
'id' => $crmOrder['id'],
|
2021-11-15 15:14:16 +03:00
|
|
|
'order' => [
|
|
|
|
'externalId' => $order->id,
|
|
|
|
'number' => $updReference,
|
|
|
|
],
|
2021-11-03 16:19:39 +07:00
|
|
|
]
|
2021-07-30 14:30:51 +03:00
|
|
|
)
|
|
|
|
)
|
2021-11-03 16:19:39 +07:00
|
|
|
)
|
|
|
|
;
|
2021-07-30 14:30:51 +03:00
|
|
|
|
|
|
|
Configuration::updateValue(RetailCRM::ENABLE_ORDER_NUMBER_RECEIVING, false);
|
|
|
|
Configuration::updateValue(RetailCRM::ENABLE_ORDER_NUMBER_SENDING, false);
|
|
|
|
RetailcrmHistory::ordersHistory();
|
|
|
|
$firstUpdOrder = new Order(1);
|
|
|
|
|
|
|
|
$this->assertEquals($reference, $firstUpdOrder->reference);
|
|
|
|
|
|
|
|
Configuration::updateValue(RetailCRM::ENABLE_ORDER_NUMBER_RECEIVING, true);
|
|
|
|
Configuration::updateValue(RetailCRM::ENABLE_ORDER_NUMBER_SENDING, true);
|
|
|
|
RetailcrmHistory::ordersHistory();
|
|
|
|
$secondUpdOrder = new Order(1);
|
|
|
|
|
|
|
|
$this->assertEquals($updReference, $secondUpdOrder->reference);
|
|
|
|
}
|
|
|
|
|
2021-12-06 14:37:43 +03:00
|
|
|
public function orderCreateDataProvider()
|
2020-07-08 16:09:45 +03:00
|
|
|
{
|
2021-12-06 14:37:43 +03:00
|
|
|
return [
|
|
|
|
[
|
|
|
|
'orderData' => $this->getApiOrder(), ],
|
|
|
|
[
|
|
|
|
'orderData' => $this->getApiOrderWitchCorporateCustomer(),
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider orderCreateDataProvider
|
|
|
|
*/
|
|
|
|
public function testOrderCreate($orderData)
|
|
|
|
{
|
|
|
|
$this->apiClientMock->expects($this->any())
|
|
|
|
->method('ordersHistory')
|
|
|
|
->willReturn(
|
|
|
|
new RetailcrmApiResponse(
|
|
|
|
'200',
|
|
|
|
json_encode(
|
|
|
|
$this->getHistoryDataNewOrder($orderData)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
;
|
|
|
|
|
|
|
|
$this->apiClientMock->expects($this->any())
|
|
|
|
->method('ordersGet')
|
|
|
|
->willReturn(
|
|
|
|
new RetailcrmApiResponse(
|
|
|
|
'200',
|
|
|
|
json_encode(
|
|
|
|
[
|
|
|
|
'order' => $orderData,
|
|
|
|
]
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
;
|
|
|
|
|
|
|
|
$this->apiClientMock->expects($this->any())
|
|
|
|
->method('ordersEdit')
|
|
|
|
->willReturn(
|
|
|
|
new RetailcrmApiResponse(
|
|
|
|
'200',
|
|
|
|
json_encode(
|
|
|
|
$this->getEditedOrder($orderData)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
;
|
|
|
|
|
|
|
|
$this->apiClientMock->expects($this->any())
|
|
|
|
->method('ordersFixExternalIds')
|
|
|
|
->willReturn(
|
|
|
|
new RetailcrmApiResponse(
|
|
|
|
'200',
|
|
|
|
json_encode([
|
|
|
|
'success' => true,
|
|
|
|
]
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
;
|
|
|
|
|
2021-11-03 16:19:39 +07:00
|
|
|
RetailcrmHistory::$default_lang = (int) Configuration::get('PS_LANG_DEFAULT');
|
2021-12-06 14:37:43 +03:00
|
|
|
RetailcrmHistory::$api = $this->apiMock;
|
2020-07-08 16:09:45 +03:00
|
|
|
|
|
|
|
$oldLastId = RetailcrmTestHelper::getMaxOrderId();
|
|
|
|
RetailcrmHistory::ordersHistory();
|
|
|
|
$newLastId = RetailcrmTestHelper::getMaxOrderId();
|
|
|
|
|
|
|
|
$this->assertTrue($newLastId > $oldLastId);
|
|
|
|
|
|
|
|
$order = new Order($newLastId);
|
|
|
|
|
|
|
|
$this->assertInstanceOf('Order', $order);
|
2021-07-15 14:29:21 +03:00
|
|
|
|
|
|
|
// delivery address
|
|
|
|
$address = new Address($order->id_address_delivery);
|
2021-11-03 16:19:39 +07:00
|
|
|
$this->assertEquals($orderData['firstName'], $address->firstname);
|
|
|
|
$this->assertEquals($orderData['lastName'], $address->lastname);
|
2021-07-15 14:29:21 +03:00
|
|
|
|
|
|
|
$builder = new RetailcrmAddressBuilder();
|
|
|
|
$addressDelivery = $builder
|
|
|
|
->setMode(RetailcrmAddressBuilder::MODE_ORDER_DELIVERY)
|
|
|
|
->setAddress($address)
|
|
|
|
->build()
|
2021-11-03 16:19:39 +07:00
|
|
|
->getDataArray()
|
|
|
|
;
|
2021-07-15 14:29:21 +03:00
|
|
|
|
|
|
|
$this->assertEquals($orderData['delivery']['address']['countryIso'], $addressDelivery['countryIso']);
|
|
|
|
unset($orderData['delivery']['address']['countryIso']);
|
|
|
|
|
|
|
|
$this->assertEquals($orderData['delivery']['address'], $addressDelivery['delivery']['address']);
|
|
|
|
$this->assertEquals($orderData['phone'], $addressDelivery['phone']);
|
|
|
|
|
|
|
|
// customer address
|
|
|
|
$address = new Address($order->id_address_invoice);
|
2021-11-03 16:19:39 +07:00
|
|
|
$this->assertEquals($orderData['customer']['firstName'], $address->firstname);
|
|
|
|
$this->assertEquals($orderData['customer']['lastName'], $address->lastname);
|
2021-07-15 14:29:21 +03:00
|
|
|
|
|
|
|
$addressInvoice = $builder
|
|
|
|
->setMode(RetailcrmAddressBuilder::MODE_CUSTOMER)
|
|
|
|
->setAddress($address)
|
|
|
|
->build()
|
2021-11-03 16:19:39 +07:00
|
|
|
->getDataArray()
|
|
|
|
;
|
2021-07-15 14:29:21 +03:00
|
|
|
|
2021-11-03 16:19:39 +07:00
|
|
|
if (isset($orderData['customer']['address']['id'])) {
|
2021-07-15 14:29:21 +03:00
|
|
|
unset($orderData['customer']['address']['id']);
|
|
|
|
}
|
|
|
|
$this->assertEquals($orderData['customer']['address'], $addressInvoice['address']);
|
|
|
|
$this->assertEquals($orderData['customer']['phones'][0]['number'], $addressInvoice['phones'][0]['number']);
|
|
|
|
|
|
|
|
// types and totals
|
|
|
|
$this->assertEquals($orderData['totalSumm'], $order->total_paid);
|
|
|
|
$this->assertEquals(10, $order->current_state);
|
|
|
|
$this->assertEquals(1, $order->id_carrier);
|
|
|
|
$this->assertEquals($orderData['payments'][0]['type'], $order->module);
|
2020-07-08 16:09:45 +03:00
|
|
|
}
|
|
|
|
|
2021-07-07 13:14:06 +03:00
|
|
|
private function switchCustomer()
|
2020-07-08 16:09:45 +03:00
|
|
|
{
|
2021-11-03 16:19:39 +07:00
|
|
|
RetailcrmHistory::$default_lang = (int) Configuration::get('PS_LANG_DEFAULT');
|
2020-07-08 16:09:45 +03:00
|
|
|
RetailcrmHistory::$api = $this->apiMock;
|
|
|
|
|
|
|
|
$history = $this->getHistoryExistOrder();
|
|
|
|
|
|
|
|
$newId = $history['history'][0]['newValue']['externalId'];
|
|
|
|
|
|
|
|
RetailcrmHistory::ordersHistory();
|
|
|
|
|
|
|
|
$order = new Order((int) $history['history'][0]['order']['externalId']);
|
|
|
|
|
|
|
|
$this->assertTrue($newId == $order->id_customer);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testOrderSwitchCustomer()
|
2018-10-05 17:50:20 +03:00
|
|
|
{
|
2021-12-06 14:37:43 +03:00
|
|
|
$this->apiClientMock->expects($this->any())
|
2018-10-05 17:50:20 +03:00
|
|
|
->method('ordersHistory')
|
|
|
|
->willReturn(
|
|
|
|
new RetailcrmApiResponse(
|
|
|
|
'200',
|
|
|
|
json_encode(
|
2020-07-08 16:09:45 +03:00
|
|
|
$this->getHistoryExistOrder()
|
2018-10-05 17:50:20 +03:00
|
|
|
)
|
|
|
|
)
|
2021-11-03 16:19:39 +07:00
|
|
|
)
|
|
|
|
;
|
2020-07-08 16:09:45 +03:00
|
|
|
|
2021-12-06 14:37:43 +03:00
|
|
|
$this->apiClientMock->expects($this->any())
|
2018-10-05 17:50:20 +03:00
|
|
|
->method('ordersGet')
|
|
|
|
->willReturn(
|
|
|
|
new RetailcrmApiResponse(
|
|
|
|
'200',
|
|
|
|
json_encode(
|
2021-11-03 16:19:39 +07:00
|
|
|
[
|
|
|
|
'order' => $this->getApiOrder(),
|
|
|
|
]
|
2018-10-05 17:50:20 +03:00
|
|
|
)
|
|
|
|
)
|
2021-11-03 16:19:39 +07:00
|
|
|
)
|
|
|
|
;
|
2018-10-05 17:50:20 +03:00
|
|
|
|
2021-12-06 14:37:43 +03:00
|
|
|
$this->apiClientMock->expects($this->any())
|
|
|
|
->method('ordersEdit')
|
2020-07-08 16:09:45 +03:00
|
|
|
->willReturn(
|
|
|
|
new RetailcrmApiResponse(
|
|
|
|
'200',
|
|
|
|
json_encode(
|
2021-12-06 14:37:43 +03:00
|
|
|
$this->getEditedOrder($this->getApiOrder())
|
2020-07-08 16:09:45 +03:00
|
|
|
)
|
|
|
|
)
|
2021-11-03 16:19:39 +07:00
|
|
|
)
|
|
|
|
;
|
2018-10-05 17:50:20 +03:00
|
|
|
|
2020-07-08 16:09:45 +03:00
|
|
|
$this->switchCustomer();
|
|
|
|
}
|
|
|
|
|
2021-12-06 14:37:43 +03:00
|
|
|
public function testOrderSwitchCorporateCustomer()
|
2020-07-08 16:09:45 +03:00
|
|
|
{
|
2021-12-06 14:37:43 +03:00
|
|
|
$this->apiClientMock->expects($this->any())
|
2020-07-08 16:09:45 +03:00
|
|
|
->method('ordersHistory')
|
|
|
|
->willReturn(
|
|
|
|
new RetailcrmApiResponse(
|
|
|
|
'200',
|
|
|
|
json_encode(
|
2021-12-06 14:37:43 +03:00
|
|
|
$this->getHistoryExistOrder()
|
2020-07-08 16:09:45 +03:00
|
|
|
)
|
|
|
|
)
|
2021-11-03 16:19:39 +07:00
|
|
|
)
|
|
|
|
;
|
2020-07-08 16:09:45 +03:00
|
|
|
|
2021-12-06 14:37:43 +03:00
|
|
|
$this->apiClientMock->expects($this->any())
|
2020-07-08 16:09:45 +03:00
|
|
|
->method('ordersGet')
|
|
|
|
->willReturn(
|
|
|
|
new RetailcrmApiResponse(
|
|
|
|
'200',
|
|
|
|
json_encode(
|
2021-11-03 16:19:39 +07:00
|
|
|
[
|
2021-12-06 14:37:43 +03:00
|
|
|
'order' => $this->getApiOrderWitchCorporateCustomer(),
|
2021-11-03 16:19:39 +07:00
|
|
|
]
|
2020-07-08 16:09:45 +03:00
|
|
|
)
|
|
|
|
)
|
2021-11-03 16:19:39 +07:00
|
|
|
)
|
|
|
|
;
|
2020-07-08 16:09:45 +03:00
|
|
|
|
2021-12-06 14:37:43 +03:00
|
|
|
$this->apiClientMock->expects($this->any())
|
2021-02-26 15:42:08 +03:00
|
|
|
->method('ordersEdit')
|
|
|
|
->willReturn(
|
|
|
|
new RetailcrmApiResponse(
|
|
|
|
'200',
|
|
|
|
json_encode(
|
2021-12-06 14:37:43 +03:00
|
|
|
$this->getEditedOrder($this->getApiOrderWitchCorporateCustomer())
|
2021-02-26 15:42:08 +03:00
|
|
|
)
|
|
|
|
)
|
2021-11-03 16:19:39 +07:00
|
|
|
)
|
|
|
|
;
|
2021-02-26 15:42:08 +03:00
|
|
|
|
2021-12-06 14:37:43 +03:00
|
|
|
$this->switchCustomer();
|
2020-07-08 16:09:45 +03:00
|
|
|
}
|
|
|
|
|
2021-12-06 14:37:43 +03:00
|
|
|
public function testPaymentStatusUpdate()
|
2020-07-08 16:09:45 +03:00
|
|
|
{
|
2021-12-06 14:37:43 +03:00
|
|
|
$lastId = RetailcrmTestHelper::getMaxOrderId();
|
2021-07-15 14:29:21 +03:00
|
|
|
|
2021-12-06 14:37:43 +03:00
|
|
|
$this->apiClientMock->expects($this->any())
|
2020-07-08 16:09:45 +03:00
|
|
|
->method('ordersHistory')
|
|
|
|
->willReturn(
|
|
|
|
new RetailcrmApiResponse(
|
|
|
|
'200',
|
|
|
|
json_encode(
|
2021-12-06 14:37:43 +03:00
|
|
|
$this->getUpdatePaymentStatus($lastId)
|
2020-07-08 16:09:45 +03:00
|
|
|
)
|
|
|
|
)
|
2021-11-03 16:19:39 +07:00
|
|
|
)
|
|
|
|
;
|
2020-07-08 16:09:45 +03:00
|
|
|
|
2021-12-06 14:37:43 +03:00
|
|
|
$this->apiClientMock->expects($this->any())
|
2021-02-26 15:42:08 +03:00
|
|
|
->method('ordersEdit')
|
|
|
|
->willReturn(
|
|
|
|
new RetailcrmApiResponse(
|
|
|
|
'200',
|
|
|
|
json_encode(
|
2021-12-06 14:37:43 +03:00
|
|
|
$this->getEditedOrder($this->getApiOrder())
|
2018-10-05 17:50:20 +03:00
|
|
|
)
|
|
|
|
)
|
2021-11-03 16:19:39 +07:00
|
|
|
)
|
|
|
|
;
|
2018-10-05 17:50:20 +03:00
|
|
|
|
2021-11-03 16:19:39 +07:00
|
|
|
RetailcrmHistory::$default_lang = (int) Configuration::get('PS_LANG_DEFAULT');
|
2018-10-05 17:50:20 +03:00
|
|
|
RetailcrmHistory::$api = $this->apiMock;
|
|
|
|
|
|
|
|
RetailcrmHistory::ordersHistory();
|
|
|
|
}
|
|
|
|
|
2021-07-07 13:14:06 +03:00
|
|
|
public function testOrderAddressUpdate()
|
|
|
|
{
|
|
|
|
$orderId = RetailcrmTestHelper::getMaxOrderId();
|
|
|
|
$crmOrder = $this->getApiOrderAddressUpdate($orderId);
|
|
|
|
|
2021-12-06 14:37:43 +03:00
|
|
|
$this->apiClientMock->expects($this->any())
|
2021-07-07 13:14:06 +03:00
|
|
|
->method('ordersHistory')
|
|
|
|
->willReturn(
|
|
|
|
new RetailcrmApiResponse(
|
|
|
|
'200',
|
|
|
|
json_encode(
|
|
|
|
$this->getHistoryAddressUpdated($orderId)
|
|
|
|
)
|
|
|
|
)
|
2021-11-03 16:19:39 +07:00
|
|
|
)
|
|
|
|
;
|
2021-07-07 13:14:06 +03:00
|
|
|
|
2021-12-06 14:37:43 +03:00
|
|
|
$this->apiClientMock->expects($this->any())
|
2021-07-07 13:14:06 +03:00
|
|
|
->method('ordersGet')
|
|
|
|
->willReturn(
|
|
|
|
new RetailcrmApiResponse(
|
|
|
|
'200',
|
|
|
|
json_encode(
|
2021-11-03 16:19:39 +07:00
|
|
|
[
|
|
|
|
'order' => $crmOrder,
|
|
|
|
]
|
2021-07-07 13:14:06 +03:00
|
|
|
)
|
|
|
|
)
|
2021-11-03 16:19:39 +07:00
|
|
|
)
|
|
|
|
;
|
2021-07-07 13:14:06 +03:00
|
|
|
|
2021-12-06 14:37:43 +03:00
|
|
|
$this->apiClientMock->expects($this->any())
|
|
|
|
->method('ordersEdit')
|
|
|
|
->willReturn(
|
|
|
|
new RetailcrmApiResponse(
|
|
|
|
'200',
|
|
|
|
json_encode(
|
|
|
|
$this->getEditedOrder($this->getApiOrder())
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
;
|
|
|
|
|
2021-11-03 16:19:39 +07:00
|
|
|
RetailcrmHistory::$default_lang = (int) Configuration::get('PS_LANG_DEFAULT');
|
2021-07-07 13:14:06 +03:00
|
|
|
RetailcrmHistory::$api = $this->apiMock;
|
|
|
|
|
|
|
|
$order = new Order($orderId);
|
|
|
|
$idAddress = $order->id_address_delivery;
|
|
|
|
|
|
|
|
RetailcrmHistory::ordersHistory();
|
|
|
|
|
|
|
|
$orderAfter = new Order($orderId);
|
|
|
|
$idAddressAfter = $orderAfter->id_address_delivery;
|
|
|
|
|
|
|
|
if (version_compare(_PS_VERSION_, '1.7.7', '<')) {
|
|
|
|
$this->assertNotEquals($idAddress, $idAddressAfter);
|
|
|
|
}
|
|
|
|
|
|
|
|
$builder = new RetailcrmAddressBuilder();
|
|
|
|
$result = $builder
|
|
|
|
->setMode(RetailcrmAddressBuilder::MODE_ORDER_DELIVERY)
|
|
|
|
->setAddressId($idAddressAfter)
|
|
|
|
->build()
|
2021-11-03 16:19:39 +07:00
|
|
|
->getDataArray()
|
|
|
|
;
|
2021-07-07 13:14:06 +03:00
|
|
|
|
|
|
|
$this->assertEquals($crmOrder['delivery']['address']['countryIso'], $result['countryIso']);
|
|
|
|
unset($crmOrder['delivery']['address']['countryIso']);
|
|
|
|
|
|
|
|
$this->assertEquals($crmOrder['delivery']['address'], $result['delivery']['address']);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testOrderNameUpdate()
|
|
|
|
{
|
|
|
|
$orderId = RetailcrmTestHelper::getMaxOrderId();
|
|
|
|
$crmOrder = $this->getApiOrderNameAndPhoneUpdate($orderId);
|
|
|
|
|
2021-12-06 14:37:43 +03:00
|
|
|
$this->apiClientMock->expects($this->any())
|
2021-07-07 13:14:06 +03:00
|
|
|
->method('ordersHistory')
|
|
|
|
->willReturn(
|
|
|
|
new RetailcrmApiResponse(
|
|
|
|
'200',
|
|
|
|
json_encode(
|
|
|
|
$this->getHistoryNameAndPhoneUpdated($orderId)
|
|
|
|
)
|
|
|
|
)
|
2021-11-03 16:19:39 +07:00
|
|
|
)
|
|
|
|
;
|
2021-07-07 13:14:06 +03:00
|
|
|
|
2021-12-06 14:37:43 +03:00
|
|
|
$this->apiClientMock->expects($this->any())
|
|
|
|
->method('ordersEdit')
|
|
|
|
->willReturn(
|
|
|
|
new RetailcrmApiResponse(
|
|
|
|
'200',
|
|
|
|
json_encode(
|
|
|
|
$this->getEditedOrder($crmOrder)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
;
|
|
|
|
|
2021-11-03 16:19:39 +07:00
|
|
|
RetailcrmHistory::$default_lang = (int) Configuration::get('PS_LANG_DEFAULT');
|
2021-07-07 13:14:06 +03:00
|
|
|
RetailcrmHistory::$api = $this->apiMock;
|
|
|
|
|
|
|
|
$order = new Order($orderId);
|
|
|
|
$idAddress = $order->id_address_delivery;
|
|
|
|
|
|
|
|
RetailcrmHistory::ordersHistory();
|
|
|
|
|
|
|
|
$orderAfter = new Order($orderId);
|
|
|
|
$idAddressAfter = $orderAfter->id_address_delivery;
|
|
|
|
$addressAfter = new Address($idAddressAfter);
|
|
|
|
|
|
|
|
if (version_compare(_PS_VERSION_, '1.7.7', '<')) {
|
|
|
|
$this->assertNotEquals($idAddress, $idAddressAfter);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->assertEquals($crmOrder['firstName'], $addressAfter->firstname);
|
|
|
|
$this->assertEquals($crmOrder['lastName'], $addressAfter->lastname);
|
|
|
|
$this->assertEquals($crmOrder['phone'], $addressAfter->phone);
|
|
|
|
}
|
|
|
|
|
2020-07-08 16:09:45 +03:00
|
|
|
private function getHistoryExistOrder()
|
|
|
|
{
|
2021-11-03 16:19:39 +07:00
|
|
|
return [
|
2020-07-08 16:09:45 +03:00
|
|
|
'success' => true,
|
2021-11-03 16:19:39 +07:00
|
|
|
'history' => [
|
|
|
|
[
|
2020-07-08 16:09:45 +03:00
|
|
|
'id' => 19752,
|
|
|
|
'createdAt' => '2018-01-01 00:00:00',
|
|
|
|
'source' => 'api',
|
|
|
|
'field' => 'customer',
|
2021-11-03 16:19:39 +07:00
|
|
|
'apiKey' => ['current' => false],
|
|
|
|
'oldValue' => [
|
2020-07-08 16:09:45 +03:00
|
|
|
'id' => 7778,
|
|
|
|
'externalId' => '1',
|
2021-11-03 16:19:39 +07:00
|
|
|
'site' => '127.0.0.1:8000',
|
|
|
|
],
|
|
|
|
'newValue' => [
|
2020-07-08 16:09:45 +03:00
|
|
|
'id' => 7777,
|
|
|
|
'externalId' => '777',
|
2021-11-03 16:19:39 +07:00
|
|
|
'site' => '127.0.0.1:8000',
|
|
|
|
],
|
|
|
|
'order' => [
|
2020-07-08 16:09:45 +03:00
|
|
|
'id' => 6025,
|
|
|
|
'externalId' => '1',
|
|
|
|
'site' => '127.0.0.1:8000',
|
2021-11-03 16:19:39 +07:00
|
|
|
'status' => 'new',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'pagination' => [
|
2020-07-08 16:09:45 +03:00
|
|
|
'limit' => 20,
|
|
|
|
'totalCount' => 1,
|
|
|
|
'currentPage' => 1,
|
2021-11-03 16:19:39 +07:00
|
|
|
'totalPageCount' => 1,
|
|
|
|
],
|
|
|
|
];
|
2020-07-08 16:09:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
private function getHistoryDataNewOrder($orderData)
|
2018-10-05 17:50:20 +03:00
|
|
|
{
|
2021-11-03 16:19:39 +07:00
|
|
|
return [
|
2018-10-05 17:50:20 +03:00
|
|
|
'success' => true,
|
2021-11-03 16:19:39 +07:00
|
|
|
'history' => [
|
|
|
|
[
|
2018-10-05 17:50:20 +03:00
|
|
|
'id' => 1,
|
|
|
|
'createdAt' => '2018-01-01 00:00:00',
|
|
|
|
'created' => true,
|
|
|
|
'source' => 'user',
|
2021-11-03 16:19:39 +07:00
|
|
|
'user' => [
|
|
|
|
'id' => 1,
|
|
|
|
],
|
2018-10-05 17:50:20 +03:00
|
|
|
'field' => 'status',
|
|
|
|
'oldValue' => null,
|
2021-11-03 16:19:39 +07:00
|
|
|
'newValue' => [
|
|
|
|
'code' => 'new',
|
|
|
|
],
|
|
|
|
'order' => $orderData,
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'pagination' => [
|
2020-07-08 16:09:45 +03:00
|
|
|
'limit' => 20,
|
|
|
|
'totalCount' => 1,
|
|
|
|
'currentPage' => 1,
|
2021-11-03 16:19:39 +07:00
|
|
|
'totalPageCount' => 1,
|
|
|
|
],
|
|
|
|
];
|
2018-10-05 17:50:20 +03:00
|
|
|
}
|
|
|
|
|
2021-02-26 15:42:08 +03:00
|
|
|
private function getEditedOrder($orderData)
|
|
|
|
{
|
2021-11-03 16:19:39 +07:00
|
|
|
return [
|
2021-02-26 15:42:08 +03:00
|
|
|
'success' => true,
|
|
|
|
'id' => $orderData['id'],
|
2021-11-03 16:19:39 +07:00
|
|
|
'order' => $orderData,
|
|
|
|
];
|
2021-02-26 15:42:08 +03:00
|
|
|
}
|
|
|
|
|
2020-04-16 15:26:03 +03:00
|
|
|
private function getApiOrder()
|
2018-10-05 17:50:20 +03:00
|
|
|
{
|
2021-11-03 16:19:39 +07:00
|
|
|
$order = [
|
2018-10-05 17:50:20 +03:00
|
|
|
'slug' => 1,
|
|
|
|
'id' => 1,
|
|
|
|
'number' => '1C',
|
|
|
|
'orderType' => 'eshop-individual',
|
|
|
|
'orderMethod' => 'phone',
|
|
|
|
'countryIso' => 'RU',
|
|
|
|
'createdAt' => '2018-01-01 00:00:00',
|
|
|
|
'statusUpdatedAt' => '2018-01-01 00:00:00',
|
|
|
|
'summ' => 100,
|
|
|
|
'totalSumm' => 100,
|
|
|
|
'prepaySum' => 0,
|
|
|
|
'purchaseSumm' => 50,
|
|
|
|
'markDatetime' => '2018-01-01 00:00:00',
|
|
|
|
'firstName' => 'Test',
|
|
|
|
'lastName' => 'Test',
|
|
|
|
'phone' => '80000000000',
|
|
|
|
'call' => false,
|
|
|
|
'expired' => false,
|
2021-11-03 16:19:39 +07:00
|
|
|
'customer' => [
|
|
|
|
'segments' => [],
|
2018-10-05 17:50:20 +03:00
|
|
|
'id' => 1,
|
2020-07-08 16:09:45 +03:00
|
|
|
'externalId' => '777',
|
2020-04-16 15:26:03 +03:00
|
|
|
'type' => 'customer',
|
2018-10-05 17:50:20 +03:00
|
|
|
'firstName' => 'Test',
|
|
|
|
'lastName' => 'Test',
|
|
|
|
'email' => 'email@test.ru',
|
2021-11-03 16:19:39 +07:00
|
|
|
'phones' => [
|
|
|
|
[
|
|
|
|
'number' => '111111111111111',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'number' => '+7111111111',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'address' => [
|
2018-10-05 17:50:20 +03:00
|
|
|
'index' => '111111',
|
|
|
|
'countryIso' => 'RU',
|
2021-07-15 14:29:21 +03:00
|
|
|
'region' => 'Buenos Aires',
|
2018-10-05 17:50:20 +03:00
|
|
|
'city' => 'Test',
|
2021-11-03 16:19:39 +07:00
|
|
|
'text' => 'Test text address',
|
|
|
|
],
|
2018-10-05 17:50:20 +03:00
|
|
|
'createdAt' => '2018-01-01 00:00:00',
|
|
|
|
'managerId' => 1,
|
|
|
|
'vip' => false,
|
|
|
|
'bad' => false,
|
|
|
|
'site' => 'test-com',
|
2021-11-03 16:19:39 +07:00
|
|
|
'contragent' => [
|
|
|
|
'contragentType' => 'individual',
|
|
|
|
],
|
2018-10-05 17:50:20 +03:00
|
|
|
'personalDiscount' => 0,
|
|
|
|
'cumulativeDiscount' => 0,
|
|
|
|
'marginSumm' => 58654,
|
|
|
|
'totalSumm' => 61549,
|
|
|
|
'averageSumm' => 15387.25,
|
|
|
|
'ordersCount' => 4,
|
|
|
|
'costSumm' => 101,
|
2021-11-03 16:19:39 +07:00
|
|
|
'customFields' => [
|
|
|
|
'custom' => 'test',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'contragent' => [],
|
|
|
|
'delivery' => [
|
2018-10-05 17:50:20 +03:00
|
|
|
'code' => 'delivery',
|
|
|
|
'cost' => 100,
|
|
|
|
'netCost' => 0,
|
2021-11-03 16:19:39 +07:00
|
|
|
'address' => [
|
2018-10-05 17:50:20 +03:00
|
|
|
'index' => '111111',
|
|
|
|
'countryIso' => 'RU',
|
2021-07-15 14:29:21 +03:00
|
|
|
'region' => 'Buenos Aires',
|
2018-10-05 17:50:20 +03:00
|
|
|
'city' => 'Test',
|
2021-11-03 16:19:39 +07:00
|
|
|
'text' => 'Test text address',
|
|
|
|
],
|
|
|
|
],
|
2018-10-05 17:50:20 +03:00
|
|
|
'site' => 'test-com',
|
|
|
|
'status' => 'new',
|
2021-11-03 16:19:39 +07:00
|
|
|
'items' => [
|
|
|
|
[
|
2018-10-05 17:50:20 +03:00
|
|
|
'id' => 160,
|
|
|
|
'initialPrice' => 100,
|
|
|
|
'createdAt' => '2018-01-01 00:00:00',
|
|
|
|
'quantity' => 1,
|
|
|
|
'status' => 'new',
|
2021-11-03 16:19:39 +07:00
|
|
|
'offer' => [
|
2018-10-05 17:50:20 +03:00
|
|
|
'id' => 1,
|
|
|
|
'externalId' => $this->product['id'],
|
|
|
|
'xmlId' => '1',
|
|
|
|
'name' => 'Test name',
|
2021-11-03 16:19:39 +07:00
|
|
|
'vatRate' => 'none',
|
|
|
|
],
|
|
|
|
'properties' => [],
|
|
|
|
'purchasePrice' => 50,
|
|
|
|
],
|
|
|
|
array_merge(RetailcrmOrderBuilder::getGiftItem(10), ['id' => 25919]),
|
|
|
|
],
|
2018-10-05 17:50:20 +03:00
|
|
|
'fromApi' => false,
|
|
|
|
'length' => 0,
|
|
|
|
'width' => 0,
|
|
|
|
'height' => 0,
|
|
|
|
'shipmentStore' => 'main',
|
|
|
|
'shipped' => false,
|
2021-11-03 16:19:39 +07:00
|
|
|
'customFields' => [],
|
|
|
|
'uploadedToExternalStoreSystem' => false,
|
|
|
|
];
|
2018-10-05 17:50:20 +03:00
|
|
|
|
2021-11-03 16:19:39 +07:00
|
|
|
$order['payments'][] = [
|
2020-04-16 15:26:03 +03:00
|
|
|
'id' => 97,
|
|
|
|
'type' => 'cheque',
|
2021-11-03 16:19:39 +07:00
|
|
|
'amount' => 210,
|
|
|
|
];
|
2018-10-05 17:50:20 +03:00
|
|
|
|
|
|
|
return $order;
|
|
|
|
}
|
|
|
|
|
2020-07-08 16:09:45 +03:00
|
|
|
private function getApiOrderWitchCorporateCustomer()
|
|
|
|
{
|
2021-11-03 16:19:39 +07:00
|
|
|
$orderWithCorporateCustomer = [
|
2020-07-08 16:09:45 +03:00
|
|
|
'slug' => 1,
|
|
|
|
'id' => 2,
|
|
|
|
'number' => '1C',
|
|
|
|
'orderType' => 'eshop-individual',
|
|
|
|
'orderMethod' => 'phone',
|
|
|
|
'countryIso' => 'RU',
|
|
|
|
'createdAt' => '2018-01-01 00:00:00',
|
|
|
|
'statusUpdatedAt' => '2018-01-01 00:00:00',
|
|
|
|
'summ' => 100,
|
|
|
|
'totalSumm' => 100,
|
|
|
|
'prepaySum' => 0,
|
|
|
|
'purchaseSumm' => 50,
|
|
|
|
'markDatetime' => '2018-01-01 00:00:00',
|
|
|
|
'firstName' => 'Test',
|
|
|
|
'lastName' => 'Test',
|
|
|
|
'phone' => '80000000000',
|
|
|
|
'call' => false,
|
|
|
|
'expired' => false,
|
2021-11-03 16:19:39 +07:00
|
|
|
'customer' => [
|
|
|
|
'segments' => [],
|
2020-07-08 16:09:45 +03:00
|
|
|
'id' => 1,
|
|
|
|
'externalId' => '777',
|
|
|
|
'type' => 'customer_corporate',
|
|
|
|
'firstName' => 'Test',
|
|
|
|
'lastName' => 'Test',
|
|
|
|
'email' => 'email@test.ru',
|
2021-11-03 16:19:39 +07:00
|
|
|
'phones' => [
|
|
|
|
[
|
|
|
|
'number' => '111111111111111',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'number' => '+7111111111',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'address' => [
|
2020-07-08 16:09:45 +03:00
|
|
|
'id' => 2345,
|
|
|
|
'index' => '111111',
|
|
|
|
'countryIso' => 'RU',
|
2021-07-15 14:29:21 +03:00
|
|
|
'region' => 'Buenos Aires',
|
2020-07-08 16:09:45 +03:00
|
|
|
'city' => 'Test',
|
2021-11-03 16:19:39 +07:00
|
|
|
'text' => 'Test text address',
|
|
|
|
],
|
2020-07-08 16:09:45 +03:00
|
|
|
'createdAt' => '2018-01-01 00:00:00',
|
|
|
|
'managerId' => 1,
|
|
|
|
'vip' => false,
|
|
|
|
'bad' => false,
|
|
|
|
'site' => 'test-com',
|
2021-11-03 16:19:39 +07:00
|
|
|
'contragent' => [
|
|
|
|
'contragentType' => 'individual',
|
|
|
|
],
|
2020-07-08 16:09:45 +03:00
|
|
|
'personalDiscount' => 0,
|
|
|
|
'cumulativeDiscount' => 0,
|
|
|
|
'marginSumm' => 58654,
|
|
|
|
'totalSumm' => 61549,
|
|
|
|
'averageSumm' => 15387.25,
|
|
|
|
'ordersCount' => 4,
|
|
|
|
'costSumm' => 101,
|
2021-11-03 16:19:39 +07:00
|
|
|
'customFields' => [
|
|
|
|
'custom' => 'test',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'contact' => [
|
2020-07-08 16:09:45 +03:00
|
|
|
'id' => 1,
|
|
|
|
'externalId' => '7777',
|
|
|
|
'type' => 'customer_corporate',
|
|
|
|
'managerId' => 23,
|
|
|
|
'isContact' => true,
|
|
|
|
'vip' => false,
|
|
|
|
'bad' => false,
|
2021-11-03 16:19:39 +07:00
|
|
|
],
|
|
|
|
'contragent' => [],
|
|
|
|
'delivery' => [
|
2020-07-08 16:09:45 +03:00
|
|
|
'code' => 'delivery',
|
|
|
|
'cost' => 100,
|
|
|
|
'netCost' => 0,
|
2021-11-03 16:19:39 +07:00
|
|
|
'address' => [
|
2020-07-08 16:09:45 +03:00
|
|
|
'index' => '111111',
|
|
|
|
'countryIso' => 'RU',
|
2021-07-15 14:29:21 +03:00
|
|
|
'region' => 'Buenos Aires',
|
2020-07-08 16:09:45 +03:00
|
|
|
'city' => 'Test',
|
2021-11-03 16:19:39 +07:00
|
|
|
'text' => 'Test text address',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'company' => [
|
2020-07-08 16:09:45 +03:00
|
|
|
'id' => 7777,
|
2021-11-03 16:19:39 +07:00
|
|
|
'contragent' => [
|
2020-07-08 16:09:45 +03:00
|
|
|
'legalName' => 'test',
|
2021-11-03 16:19:39 +07:00
|
|
|
'INN' => '255222',
|
|
|
|
],
|
|
|
|
'address' => [
|
2020-07-08 16:09:45 +03:00
|
|
|
'id' => 1,
|
|
|
|
'index' => '111111',
|
|
|
|
'countryIso' => 'RU',
|
2021-07-15 14:29:21 +03:00
|
|
|
'region' => 'Buenos Aires',
|
2020-07-08 16:09:45 +03:00
|
|
|
'city' => 'Test',
|
2021-11-03 16:19:39 +07:00
|
|
|
'text' => 'Test text address',
|
|
|
|
],
|
|
|
|
],
|
2020-07-08 16:09:45 +03:00
|
|
|
'site' => 'test-com',
|
|
|
|
'status' => 'new',
|
2021-11-03 16:19:39 +07:00
|
|
|
'items' => [
|
|
|
|
[
|
2020-07-08 16:09:45 +03:00
|
|
|
'id' => 160,
|
|
|
|
'initialPrice' => 100,
|
|
|
|
'createdAt' => '2018-01-01 00:00:00',
|
|
|
|
'quantity' => 1,
|
|
|
|
'status' => 'new',
|
2021-11-03 16:19:39 +07:00
|
|
|
'offer' => [
|
2020-07-08 16:09:45 +03:00
|
|
|
'id' => 1,
|
|
|
|
'externalId' => $this->product['id'],
|
|
|
|
'xmlId' => '1',
|
|
|
|
'name' => 'Test name',
|
2021-11-03 16:19:39 +07:00
|
|
|
'vatRate' => 'none',
|
|
|
|
],
|
|
|
|
'properties' => [],
|
|
|
|
'purchasePrice' => 50,
|
|
|
|
],
|
|
|
|
array_merge(RetailcrmOrderBuilder::getGiftItem(10), ['id' => 25919]),
|
|
|
|
],
|
2020-07-08 16:09:45 +03:00
|
|
|
'fromApi' => false,
|
|
|
|
'length' => 0,
|
|
|
|
'width' => 0,
|
|
|
|
'height' => 0,
|
|
|
|
'shipmentStore' => 'main',
|
|
|
|
'shipped' => false,
|
2021-11-03 16:19:39 +07:00
|
|
|
'customFields' => [],
|
|
|
|
'uploadedToExternalStoreSystem' => false,
|
|
|
|
];
|
2020-07-08 16:09:45 +03:00
|
|
|
|
2021-11-03 16:19:39 +07:00
|
|
|
$orderWithCorporateCustomer['payments'][] = [
|
2020-07-08 16:09:45 +03:00
|
|
|
'id' => 97,
|
|
|
|
'type' => 'cheque',
|
2021-11-03 16:19:39 +07:00
|
|
|
'amount' => 210,
|
|
|
|
];
|
2020-07-08 16:09:45 +03:00
|
|
|
|
|
|
|
return $orderWithCorporateCustomer;
|
|
|
|
}
|
|
|
|
|
2018-10-05 17:50:20 +03:00
|
|
|
private function getUpdatePaymentStatus($orderId)
|
|
|
|
{
|
2021-11-03 16:19:39 +07:00
|
|
|
return [
|
2018-10-05 17:50:20 +03:00
|
|
|
'success' => true,
|
2021-11-03 16:19:39 +07:00
|
|
|
'pagination' => [
|
2020-07-08 16:09:45 +03:00
|
|
|
'limit' => 20,
|
|
|
|
'totalCount' => 1,
|
|
|
|
'currentPage' => 1,
|
2021-11-03 16:19:39 +07:00
|
|
|
'totalPageCount' => 1,
|
|
|
|
],
|
|
|
|
'history' => [
|
|
|
|
[
|
2018-10-05 17:50:20 +03:00
|
|
|
'id' => 654,
|
|
|
|
'createdAt' => '2018-01-01 00:00:00',
|
|
|
|
'source' => 'user',
|
2021-11-03 16:19:39 +07:00
|
|
|
'user' => [
|
|
|
|
'id' => 1,
|
|
|
|
],
|
2018-10-05 17:50:20 +03:00
|
|
|
'field' => 'full_paid_at',
|
|
|
|
'oldValue' => null,
|
|
|
|
'newValue' => '2018-01-01 00:00:00',
|
2021-11-03 16:19:39 +07:00
|
|
|
'order' => [
|
2018-10-05 17:50:20 +03:00
|
|
|
'id' => 1,
|
|
|
|
'externalId' => $orderId,
|
|
|
|
'site' => 'test-com',
|
2021-11-03 16:19:39 +07:00
|
|
|
'status' => 'new',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'id' => 655,
|
2018-10-05 17:50:20 +03:00
|
|
|
'createdAt' => '2018-01-01 00:00:00',
|
|
|
|
'source' => 'user',
|
2021-11-03 16:19:39 +07:00
|
|
|
'user' => [
|
|
|
|
'id' => 1,
|
|
|
|
],
|
2018-10-05 17:50:20 +03:00
|
|
|
'field' => 'payments.paid_at',
|
|
|
|
'oldValue' => null,
|
|
|
|
'newValue' => '2018-01-01 00:00:00',
|
2021-11-03 16:19:39 +07:00
|
|
|
'order' => [
|
2018-10-05 17:50:20 +03:00
|
|
|
'id' => 1,
|
|
|
|
'externalId' => $orderId,
|
|
|
|
'site' => 'test-com',
|
2021-11-03 16:19:39 +07:00
|
|
|
'status' => 'new',
|
|
|
|
],
|
|
|
|
'payment' => [
|
|
|
|
'id' => 102,
|
|
|
|
'type' => 'cheque',
|
|
|
|
'externalId' => 1,
|
|
|
|
],
|
|
|
|
],
|
|
|
|
[
|
2018-10-05 17:50:20 +03:00
|
|
|
'id' => 656,
|
|
|
|
'createdAt' => '2018-01-01 00:00:00',
|
|
|
|
'source' => 'user',
|
2021-11-03 16:19:39 +07:00
|
|
|
'user' => [
|
|
|
|
'id' => 1,
|
|
|
|
],
|
2018-10-05 17:50:20 +03:00
|
|
|
'field' => 'payments.status',
|
2021-11-03 16:19:39 +07:00
|
|
|
'oldValue' => [
|
|
|
|
'code' => 'not-paid',
|
|
|
|
],
|
|
|
|
'newValue' => [
|
|
|
|
'code' => 'paid',
|
|
|
|
],
|
|
|
|
'order' => [
|
2018-10-05 17:50:20 +03:00
|
|
|
'id' => 1,
|
|
|
|
'externalId' => $orderId,
|
|
|
|
'site' => 'test-com',
|
2021-11-03 16:19:39 +07:00
|
|
|
'status' => 'new',
|
|
|
|
],
|
|
|
|
'payment' => [
|
2018-10-05 17:50:20 +03:00
|
|
|
'id' => 102,
|
|
|
|
'type' => 'cheque',
|
2021-11-03 16:19:39 +07:00
|
|
|
'externalId' => 1,
|
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
];
|
2018-10-05 17:50:20 +03:00
|
|
|
}
|
2020-07-08 16:09:45 +03:00
|
|
|
|
|
|
|
private function getHistoryDataNewCustomer()
|
|
|
|
{
|
2021-11-03 16:19:39 +07:00
|
|
|
return [
|
2020-07-08 16:09:45 +03:00
|
|
|
'success' => true,
|
2021-11-03 16:19:39 +07:00
|
|
|
'history' => [
|
|
|
|
[
|
2020-07-08 16:09:45 +03:00
|
|
|
'id' => 1,
|
|
|
|
'createdAt' => '2018-01-01 00:00:00',
|
|
|
|
'created' => true,
|
|
|
|
'source' => 'api',
|
|
|
|
'field' => 'id',
|
|
|
|
'oldValue' => null,
|
|
|
|
'newValue' => 4949,
|
2021-11-03 16:19:39 +07:00
|
|
|
'customer' => $this->getApiCustomer(),
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'pagination' => [
|
2020-07-08 16:09:45 +03:00
|
|
|
'limit' => 20,
|
|
|
|
'totalCount' => 1,
|
|
|
|
'currentPage' => 1,
|
2021-11-03 16:19:39 +07:00
|
|
|
'totalPageCount' => 1,
|
|
|
|
],
|
|
|
|
];
|
2020-07-08 16:09:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
private function getApiCustomer()
|
|
|
|
{
|
2021-11-03 16:19:39 +07:00
|
|
|
return [
|
2020-07-08 16:09:45 +03:00
|
|
|
'type' => 'customer',
|
|
|
|
'id' => 1,
|
|
|
|
'externalId' => '1',
|
|
|
|
'isContact' => false,
|
|
|
|
'createdAt' => '2020-05-08 03:00:38',
|
|
|
|
'vip' => false,
|
|
|
|
'bad' => false,
|
|
|
|
'site' => 'example.com',
|
2021-11-03 16:19:39 +07:00
|
|
|
'contragent' => [
|
|
|
|
'contragentType' => 'individual',
|
|
|
|
],
|
|
|
|
'tags' => [],
|
2020-07-08 16:09:45 +03:00
|
|
|
'marginSumm' => 0,
|
|
|
|
'totalSumm' => 0,
|
|
|
|
'averageSumm' => 0,
|
|
|
|
'ordersCount' => 0,
|
|
|
|
'costSumm' => 0,
|
|
|
|
'customFields' => [],
|
|
|
|
'personalDiscount' => 0,
|
2021-11-03 16:19:39 +07:00
|
|
|
'address' => [
|
2020-07-08 16:09:45 +03:00
|
|
|
'id' => 4053,
|
|
|
|
'countryIso' => 'RU',
|
|
|
|
'index' => '2170',
|
2021-07-15 14:29:21 +03:00
|
|
|
'city' => 'Buenos Aires',
|
2020-07-08 16:09:45 +03:00
|
|
|
'street' => 'Good',
|
|
|
|
'building' => '17',
|
2021-11-03 16:19:39 +07:00
|
|
|
'text' => 'Good, д. 17',
|
|
|
|
],
|
|
|
|
'segments' => [],
|
2020-07-08 16:09:45 +03:00
|
|
|
'email' => 'test@example.com',
|
|
|
|
'firstName' => 'Test',
|
|
|
|
'lastName' => 'Test',
|
2021-11-03 16:19:39 +07:00
|
|
|
'phones' => [
|
|
|
|
'number' => '+79999999999',
|
|
|
|
],
|
|
|
|
];
|
2020-07-08 16:09:45 +03:00
|
|
|
}
|
2021-07-07 13:14:06 +03:00
|
|
|
|
|
|
|
private function getHistoryAddressUpdated($orderId)
|
|
|
|
{
|
2021-11-03 16:19:39 +07:00
|
|
|
return [
|
2021-07-07 13:14:06 +03:00
|
|
|
'success' => true,
|
2021-11-03 16:19:39 +07:00
|
|
|
'history' => [
|
|
|
|
[
|
2021-07-07 13:14:06 +03:00
|
|
|
'id' => 19752,
|
|
|
|
'createdAt' => '2018-01-01 00:00:00',
|
|
|
|
'source' => 'api',
|
|
|
|
'field' => 'delivery_address.city',
|
2021-11-03 16:19:39 +07:00
|
|
|
'apiKey' => ['current' => false],
|
2021-07-07 13:14:06 +03:00
|
|
|
'oldValue' => 'Order City old',
|
|
|
|
'newValue' => 'Order City new',
|
2021-11-03 16:19:39 +07:00
|
|
|
'order' => [
|
2021-07-07 13:14:06 +03:00
|
|
|
'id' => 6025,
|
2021-11-03 16:19:39 +07:00
|
|
|
'externalId' => (string) $orderId,
|
2021-07-07 13:14:06 +03:00
|
|
|
'site' => '127.0.0.1:8000',
|
2021-11-03 16:19:39 +07:00
|
|
|
'status' => 'new',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
[
|
2021-07-07 13:14:06 +03:00
|
|
|
'id' => 19753,
|
|
|
|
'createdAt' => '2018-01-01 00:00:00',
|
|
|
|
'source' => 'api',
|
|
|
|
'field' => 'delivery_address.index',
|
2021-11-03 16:19:39 +07:00
|
|
|
'apiKey' => ['current' => false],
|
2021-07-07 13:14:06 +03:00
|
|
|
'oldValue' => '111',
|
|
|
|
'newValue' => '222',
|
2021-11-03 16:19:39 +07:00
|
|
|
'order' => [
|
2021-07-07 13:14:06 +03:00
|
|
|
'id' => 6025,
|
2021-11-03 16:19:39 +07:00
|
|
|
'externalId' => (string) $orderId,
|
2021-07-07 13:14:06 +03:00
|
|
|
'site' => '127.0.0.1:8000',
|
2021-11-03 16:19:39 +07:00
|
|
|
'status' => 'new',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
[
|
2021-07-15 14:29:21 +03:00
|
|
|
'id' => 19754,
|
|
|
|
'createdAt' => '2018-01-01 00:00:00',
|
|
|
|
'source' => 'api',
|
|
|
|
'field' => 'delivery_address.street',
|
2021-11-03 16:19:39 +07:00
|
|
|
'apiKey' => ['current' => false],
|
2021-07-15 14:29:21 +03:00
|
|
|
'oldValue' => null,
|
|
|
|
'newValue' => 'Test updated address',
|
2021-11-03 16:19:39 +07:00
|
|
|
'order' => [
|
2021-07-15 14:29:21 +03:00
|
|
|
'id' => 6025,
|
2021-11-03 16:19:39 +07:00
|
|
|
'externalId' => (string) $orderId,
|
2021-07-15 14:29:21 +03:00
|
|
|
'site' => '127.0.0.1:8000',
|
2021-11-03 16:19:39 +07:00
|
|
|
'status' => 'new',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'pagination' => [
|
2021-07-07 13:14:06 +03:00
|
|
|
'limit' => 20,
|
2021-07-15 14:29:21 +03:00
|
|
|
'totalCount' => 3,
|
2021-07-07 13:14:06 +03:00
|
|
|
'currentPage' => 1,
|
2021-11-03 16:19:39 +07:00
|
|
|
'totalPageCount' => 1,
|
|
|
|
],
|
|
|
|
];
|
2021-07-07 13:14:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
private function getHistoryNameAndPhoneUpdated($orderId)
|
|
|
|
{
|
2021-11-03 16:19:39 +07:00
|
|
|
return [
|
2021-07-07 13:14:06 +03:00
|
|
|
'success' => true,
|
2021-11-03 16:19:39 +07:00
|
|
|
'history' => [
|
|
|
|
[
|
2021-07-07 13:14:06 +03:00
|
|
|
'id' => 19752,
|
|
|
|
'createdAt' => '2018-01-01 00:00:00',
|
|
|
|
'source' => 'api',
|
|
|
|
'field' => 'first_name',
|
2021-11-03 16:19:39 +07:00
|
|
|
'apiKey' => ['current' => false],
|
2021-07-07 13:14:06 +03:00
|
|
|
'oldValue' => 'name old',
|
|
|
|
'newValue' => 'name new',
|
2021-11-03 16:19:39 +07:00
|
|
|
'order' => [
|
2021-07-07 13:14:06 +03:00
|
|
|
'id' => 6025,
|
2021-11-03 16:19:39 +07:00
|
|
|
'externalId' => (string) $orderId,
|
2021-07-07 13:14:06 +03:00
|
|
|
'site' => '127.0.0.1:8000',
|
2021-11-03 16:19:39 +07:00
|
|
|
'status' => 'new',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
[
|
2021-07-07 13:14:06 +03:00
|
|
|
'id' => 19753,
|
|
|
|
'createdAt' => '2018-01-01 00:00:00',
|
|
|
|
'source' => 'api',
|
|
|
|
'field' => 'phone',
|
2021-11-03 16:19:39 +07:00
|
|
|
'apiKey' => ['current' => false],
|
2021-07-07 13:14:06 +03:00
|
|
|
'oldValue' => '111',
|
|
|
|
'newValue' => '222222',
|
2021-11-03 16:19:39 +07:00
|
|
|
'order' => [
|
2021-07-07 13:14:06 +03:00
|
|
|
'id' => 6025,
|
2021-11-03 16:19:39 +07:00
|
|
|
'externalId' => (string) $orderId,
|
2021-07-07 13:14:06 +03:00
|
|
|
'site' => '127.0.0.1:8000',
|
2021-11-03 16:19:39 +07:00
|
|
|
'status' => 'new',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'pagination' => [
|
2021-07-07 13:14:06 +03:00
|
|
|
'limit' => 20,
|
|
|
|
'totalCount' => 2,
|
|
|
|
'currentPage' => 1,
|
2021-11-03 16:19:39 +07:00
|
|
|
'totalPageCount' => 1,
|
|
|
|
],
|
|
|
|
];
|
2021-07-07 13:14:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
private function getApiOrderAddressUpdate($orderId)
|
|
|
|
{
|
|
|
|
$order = $this->getApiOrder();
|
|
|
|
|
2021-11-03 16:19:39 +07:00
|
|
|
$order['externalId'] = (string) $orderId;
|
2021-07-07 13:14:06 +03:00
|
|
|
$order['delivery']['address']['city'] = 'Order City new';
|
|
|
|
$order['delivery']['address']['index'] = '222';
|
2021-07-15 14:29:21 +03:00
|
|
|
$order['delivery']['address']['text'] = 'Test updated address';
|
2021-07-07 13:14:06 +03:00
|
|
|
unset($order['delivery']['address']['id_customer']);
|
|
|
|
|
|
|
|
return $order;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getApiOrderNameAndPhoneUpdate($orderId)
|
|
|
|
{
|
|
|
|
$order = $this->getApiOrder();
|
|
|
|
|
2021-11-03 16:19:39 +07:00
|
|
|
$order['externalId'] = (string) $orderId;
|
2021-07-07 13:14:06 +03:00
|
|
|
$order['firstName'] = 'name new';
|
|
|
|
$order['phone'] = '222222';
|
|
|
|
|
|
|
|
return $order;
|
|
|
|
}
|
2018-10-05 17:50:20 +03:00
|
|
|
}
|