This commit is contained in:
Sergey 2019-01-21 14:42:19 +03:00
parent f520e7b181
commit b64bb2599c
6 changed files with 108 additions and 85 deletions

View File

@ -1,5 +1,7 @@
## v2.2.9
* Добавлена выгрузка габаритов в специальный тег dimensions
* Добавлена выгрузка остатков из CRM
* Добавлена передача номера заказа
## v2.2.8
* Добавлена выгрузка картинок категорий товаров в ICML

View File

@ -34,6 +34,14 @@ Add to cron:
*/7 * * * * /usr/bin/php /path/to/your/site/modules/retailcrm/job/sync.php
```
#### Receiving balances from retailCRM
Add to cron:
```
*/15 * * * * /usr/bin/php /path/to/your/site/modules/retailcrm/job/sync.php
```
#### Single orders archive export to retailCRM
```

View File

@ -29,6 +29,14 @@ Prestashop module
*/7 * * * * /usr/bin/php /path/to/your/site/modules/retailcrm/job/sync.php
```
#### Получение остатков из retailCRM
Добавьте в крон запись вида
```
*/15 * * * * /usr/bin/php /path/to/your/site/modules/retailcrm/job/sync.php
```
#### Единоразовая выгрузка архива клиентов и заказов в retailCRM
```

View File

@ -3,7 +3,7 @@
* @author Retail Driver LCC
* @copyright RetailCRM
* @license GPL
* @version 2.2.0
* @version 2.2.9
* @link https://retailcrm.ru
*
*/
@ -18,7 +18,6 @@ $apiUrl = Configuration::get('RETAILCRM_ADDRESS');
$apiKey = Configuration::get('RETAILCRM_API_TOKEN');
$apiVersion = Configuration::get('RETAILCRM_API_VERSION');
if (!empty($apiUrl) && !empty($apiKey)) {
RetailcrmInventories::$api = new RetailcrmProxy($apiUrl, $apiKey, _PS_ROOT_DIR_ . '/retailcrm.log', $apiVersion);
} else {
@ -26,4 +25,4 @@ if (!empty($apiUrl) && !empty($apiKey)) {
exit();
}
RetailcrmInventories::load_stocks();
RetailcrmInventories::loadStocks();

View File

@ -1,53 +1,44 @@
<?php
class RetailcrmInventories
{
public static $api;
public static $default_lang;
public static $apiVersion;
/**
* Load stock from retailCRM
*
* @return mixed
*/
public function load_stocks() {
public static function loadStocks()
{
$page = 1;
do {
$result = self::$api->storeInventories(array(), $page, 250);
if (!$result->isSuccessful()) {
return null;
if ($result === false) {
return $result;
}
foreach ($result['offers'] as $offer) {
self::setQuantityOffer($offer);
}
$totalPageCount = $result['pagination']['totalPageCount'];
$page++;
foreach ($result['offers'] as $offer) {
if (isset($offer['externalId'])) {
$invOffer = explode('#', $offer['externalId']);
if (isset($invOffer[1])) {
StockAvailable::setQuantity($invOffer[0], $invOffer[1], $offer['quantity']);
} else {
StockAvailable::setQuantity($offer['externalId'], 0, $offer['quantity']);
}
}
}
} while ($page <= $totalPageCount);
return $success;
}
/**
* Update stock quantity in WooCommerce
*
* @return mixed
*/
public function updateQuantity() {
private static function setQuantityOffer($offer)
{
if (isset($offer['externalId'])) {
$invOffer = explode('#', $offer['externalId']);
return $this->load_stocks();
if (isset($invOffer[1])) {
StockAvailable::setQuantity($invOffer[0], $invOffer[1], $offer['quantity']);
} else {
StockAvailable::setQuantity($offer['externalId'], 0, $offer['quantity']);
}
}
}
}

View File

@ -3,8 +3,12 @@
class RetailcrmInventoriesTest extends RetailcrmTestCase
{
private $apiMock;
private $product;
private $product1;
private $product2;
const PRODUCT1_QUANTITY = 10;
const PRODUCT2_QUANTITY = 15;
public function setUp()
{
parent::setUp();
@ -17,83 +21,61 @@ class RetailcrmInventoriesTest extends RetailcrmTestCase
)
)
->getMock();
$catalog = new RetailcrmCatalog();
$data = $catalog->getData();
$this->product = $data[1][0];
$this->setConfig();
$this->product1 = $data[1][0];
$this->product2 = $data[1][1];
}
private function getResponseData()
{
return array(
'true' => array(
'success' => true,
'pagination' => array(
'limit' => 250,
'totalCount' => 1,
'currentPage' => 1,
'totalPageCount' => 1
),
'offers' => array(
array(
'id' => 1,
'xmlId' => 'xmlId',
'quantity' => 10
)
)
),
'false' => array(
'success' => false,
'errorMsg' => 'Forbidden'
)
);
}
/**
* @param $apiVersion
* @param $response
*
* @dataProvider dataProviderLoadStocks
*/
public function test_load_stocks($apiVersion, $response)
public function testLoadStocks($apiVersion, $response)
{
if ($response['success'] == true) {
$response['offers'][0]['externalId'] = $this->product['id'];
$this->apiMock->expects($this->any())
->method('isSuccessful')
->willReturn(true);
} elseif ($response['success'] == false) {
$this->apiMock->expects($this->any())
->method('isSuccessful')
->willReturn(false);
}
$this->apiMock->setResponse($response);
$this->apiMock->expects($this->any())
->method('storeInventories')
->willReturn($this->apiMock);
RetailcrmInventories::$apiVersion = $apiVersion;
->willReturn(
new RetailcrmApiResponse(
'200',
json_encode(
$this->getApiInventories()
)
)
);
} else {
$this->apiMock->expects($this->any())
->method('storeInventories')
->willReturn($response);
}
RetailcrmInventories::$api = $this->apiMock;
RetailcrmInventories::load_stocks();
RetailcrmInventories::loadStocks();
$product1Id = explode('#', $this->product1['id']);
$product2Id = explode('#', $this->product2['id']);
$prod1Quantity = StockAvailable::getQuantityAvailableByProduct($product1Id[0], $product1Id[1] );
$prod2Quantity = StockAvailable::getQuantityAvailableByProduct($product2Id[0], $product2Id[1] );
$this->assertEquals(self::PRODUCT1_QUANTITY, $prod1Quantity);
$this->assertEquals(self::PRODUCT2_QUANTITY, $prod2Quantity);
}
public function dataProviderLoadStocks()
{
$this->setUp();
$response = $this->getResponseData();
return array(
array(
'api_version' => 4,
'response' => $response['true'],
'api_version' => 4
),
array(
'api_version' => 5,
@ -109,4 +91,37 @@ class RetailcrmInventoriesTest extends RetailcrmTestCase
)
);
}
}
private function getResponseData()
{
return array(
'true' => $this->getApiInventories(),
'false' => false
);
}
private function getApiInventories()
{
return array(
"success" => true,
"pagination"=> array(
"limit"=> 250,
"totalCount"=> 1,
"currentPage"=> 1,
"totalPageCount"=> 1
),
"offers" => array(
array(
'externalId' => $this->product1['id'],
'xmlId' => 'xmlId',
'quantity' => self::PRODUCT1_QUANTITY,
),
array(
'externalId' => $this->product2['id'],
'xmlId' => 'xmlId',
'quantity' => self::PRODUCT2_QUANTITY,
)
)
);
}
}