mirror of
https://github.com/retailcrm/prestashop-module.git
synced 2025-03-02 19:33:14 +03:00
v2.2.9
This commit is contained in:
parent
f520e7b181
commit
b64bb2599c
@ -1,5 +1,7 @@
|
|||||||
## v2.2.9
|
## v2.2.9
|
||||||
* Добавлена выгрузка габаритов в специальный тег dimensions
|
* Добавлена выгрузка габаритов в специальный тег dimensions
|
||||||
|
* Добавлена выгрузка остатков из CRM
|
||||||
|
* Добавлена передача номера заказа
|
||||||
|
|
||||||
## v2.2.8
|
## v2.2.8
|
||||||
* Добавлена выгрузка картинок категорий товаров в ICML
|
* Добавлена выгрузка картинок категорий товаров в ICML
|
||||||
|
@ -34,6 +34,14 @@ Add to cron:
|
|||||||
*/7 * * * * /usr/bin/php /path/to/your/site/modules/retailcrm/job/sync.php
|
*/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
|
#### Single orders archive export to retailCRM
|
||||||
|
|
||||||
```
|
```
|
||||||
|
@ -29,6 +29,14 @@ Prestashop module
|
|||||||
*/7 * * * * /usr/bin/php /path/to/your/site/modules/retailcrm/job/sync.php
|
*/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
|
#### Единоразовая выгрузка архива клиентов и заказов в retailCRM
|
||||||
|
|
||||||
```
|
```
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
* @author Retail Driver LCC
|
* @author Retail Driver LCC
|
||||||
* @copyright RetailCRM
|
* @copyright RetailCRM
|
||||||
* @license GPL
|
* @license GPL
|
||||||
* @version 2.2.0
|
* @version 2.2.9
|
||||||
* @link https://retailcrm.ru
|
* @link https://retailcrm.ru
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ -18,7 +18,6 @@ $apiUrl = Configuration::get('RETAILCRM_ADDRESS');
|
|||||||
$apiKey = Configuration::get('RETAILCRM_API_TOKEN');
|
$apiKey = Configuration::get('RETAILCRM_API_TOKEN');
|
||||||
$apiVersion = Configuration::get('RETAILCRM_API_VERSION');
|
$apiVersion = Configuration::get('RETAILCRM_API_VERSION');
|
||||||
|
|
||||||
|
|
||||||
if (!empty($apiUrl) && !empty($apiKey)) {
|
if (!empty($apiUrl) && !empty($apiKey)) {
|
||||||
RetailcrmInventories::$api = new RetailcrmProxy($apiUrl, $apiKey, _PS_ROOT_DIR_ . '/retailcrm.log', $apiVersion);
|
RetailcrmInventories::$api = new RetailcrmProxy($apiUrl, $apiKey, _PS_ROOT_DIR_ . '/retailcrm.log', $apiVersion);
|
||||||
} else {
|
} else {
|
||||||
@ -26,4 +25,4 @@ if (!empty($apiUrl) && !empty($apiKey)) {
|
|||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
RetailcrmInventories::load_stocks();
|
RetailcrmInventories::loadStocks();
|
||||||
|
@ -1,53 +1,44 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
class RetailcrmInventories
|
class RetailcrmInventories
|
||||||
{
|
{
|
||||||
public static $api;
|
public static $api;
|
||||||
public static $default_lang;
|
|
||||||
public static $apiVersion;
|
|
||||||
/**
|
/**
|
||||||
* Load stock from retailCRM
|
* Load stock from retailCRM
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function load_stocks() {
|
public static function loadStocks()
|
||||||
|
{
|
||||||
$page = 1;
|
$page = 1;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
$result = self::$api->storeInventories(array(), $page, 250);
|
$result = self::$api->storeInventories(array(), $page, 250);
|
||||||
|
|
||||||
if (!$result->isSuccessful()) {
|
if ($result === false) {
|
||||||
return null;
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($result['offers'] as $offer) {
|
||||||
|
self::setQuantityOffer($offer);
|
||||||
}
|
}
|
||||||
|
|
||||||
$totalPageCount = $result['pagination']['totalPageCount'];
|
$totalPageCount = $result['pagination']['totalPageCount'];
|
||||||
$page++;
|
$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);
|
} while ($page <= $totalPageCount);
|
||||||
|
|
||||||
return $success;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private static function setQuantityOffer($offer)
|
||||||
* Update stock quantity in WooCommerce
|
{
|
||||||
*
|
if (isset($offer['externalId'])) {
|
||||||
* @return mixed
|
$invOffer = explode('#', $offer['externalId']);
|
||||||
*/
|
|
||||||
public function updateQuantity() {
|
|
||||||
|
|
||||||
return $this->load_stocks();
|
if (isset($invOffer[1])) {
|
||||||
|
StockAvailable::setQuantity($invOffer[0], $invOffer[1], $offer['quantity']);
|
||||||
|
} else {
|
||||||
|
StockAvailable::setQuantity($offer['externalId'], 0, $offer['quantity']);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,12 @@
|
|||||||
class RetailcrmInventoriesTest extends RetailcrmTestCase
|
class RetailcrmInventoriesTest extends RetailcrmTestCase
|
||||||
{
|
{
|
||||||
private $apiMock;
|
private $apiMock;
|
||||||
private $product;
|
private $product1;
|
||||||
|
private $product2;
|
||||||
|
|
||||||
|
const PRODUCT1_QUANTITY = 10;
|
||||||
|
const PRODUCT2_QUANTITY = 15;
|
||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
@ -17,83 +21,61 @@ class RetailcrmInventoriesTest extends RetailcrmTestCase
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
->getMock();
|
->getMock();
|
||||||
|
|
||||||
$catalog = new RetailcrmCatalog();
|
$catalog = new RetailcrmCatalog();
|
||||||
$data = $catalog->getData();
|
$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 $apiVersion
|
||||||
* @param $response
|
* @param $response
|
||||||
*
|
*
|
||||||
* @dataProvider dataProviderLoadStocks
|
* @dataProvider dataProviderLoadStocks
|
||||||
*/
|
*/
|
||||||
public function test_load_stocks($apiVersion, $response)
|
public function testLoadStocks($apiVersion, $response)
|
||||||
{
|
{
|
||||||
if ($response['success'] == true) {
|
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())
|
$this->apiMock->expects($this->any())
|
||||||
->method('storeInventories')
|
->method('storeInventories')
|
||||||
->willReturn($this->apiMock);
|
->willReturn(
|
||||||
|
new RetailcrmApiResponse(
|
||||||
|
'200',
|
||||||
RetailcrmInventories::$apiVersion = $apiVersion;
|
json_encode(
|
||||||
|
$this->getApiInventories()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$this->apiMock->expects($this->any())
|
||||||
|
->method('storeInventories')
|
||||||
|
->willReturn($response);
|
||||||
|
}
|
||||||
|
|
||||||
RetailcrmInventories::$api = $this->apiMock;
|
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()
|
public function dataProviderLoadStocks()
|
||||||
{
|
{
|
||||||
$this->setUp();
|
|
||||||
|
|
||||||
$response = $this->getResponseData();
|
$response = $this->getResponseData();
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
array(
|
array(
|
||||||
|
'api_version' => 4,
|
||||||
'response' => $response['true'],
|
'response' => $response['true'],
|
||||||
'api_version' => 4
|
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'api_version' => 5,
|
'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,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user