v2.4.0
This commit is contained in:
parent
b15f8ec5a8
commit
a6d80bf154
@ -1,3 +1,6 @@
|
||||
## 2018-12-25 v.2.4.0
|
||||
* Добавлен функционал получения остатков из retailCRM
|
||||
|
||||
## 2018-12-25 v.2.3.2
|
||||
* Добавлена выгрузка картинок категорий товаров в ICML
|
||||
|
||||
|
24
src/Cron/Inventories.php
Normal file
24
src/Cron/Inventories.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Retailcrm\Retailcrm\Cron;
|
||||
|
||||
class Inventories
|
||||
{
|
||||
private $inventoriesUpload;
|
||||
private $helper;
|
||||
|
||||
public function __construct(
|
||||
\Retailcrm\Retailcrm\Helper\Data $helper,
|
||||
\Retailcrm\Retailcrm\Model\Service\InventoriesUpload $InventoriesUpload
|
||||
) {
|
||||
$this->helper = $helper;
|
||||
$this->inventoriesUpload = $InventoriesUpload;
|
||||
}
|
||||
|
||||
public function execute()
|
||||
{
|
||||
if ($this->helper->getInventoriesUpload() == true) {
|
||||
$this->inventoriesUpload->uploadInventory();
|
||||
}
|
||||
}
|
||||
}
|
@ -131,6 +131,20 @@ class Data extends AbstractHelper
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getInventoriesUpload()
|
||||
{
|
||||
$inventories = $this->scopeConfig->getValue(
|
||||
self::XML_PATH_RETAILCRM . self::XML_PATH_INVENTORIES . 'active',
|
||||
ScopeConfigInterface::SCOPE_TYPE_DEFAULT
|
||||
);
|
||||
|
||||
if ($inventories) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $website
|
||||
*
|
||||
|
55
src/Model/Service/InventoriesUpload.php
Normal file
55
src/Model/Service/InventoriesUpload.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace Retailcrm\Retailcrm\Model\Service;
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
|
||||
class InventoriesUpload
|
||||
{
|
||||
private $productRepo;
|
||||
private $api;
|
||||
|
||||
public function __construct(
|
||||
ProductRepositoryInterface $productRepo,
|
||||
\Retailcrm\Retailcrm\Helper\Proxy $api
|
||||
) {
|
||||
$this->productRepo = $productRepo;
|
||||
$this->api = $api;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function uploadInventory()
|
||||
{
|
||||
if (!$this->api->isConfigured()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$page = 1;
|
||||
|
||||
do {
|
||||
$response = $this->api->storeInventories(array(), $page, 250);
|
||||
|
||||
if ($response === false || !$response->isSuccessful()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($response['offers'] as $offer) {
|
||||
if (isset($offer['externalId'])) {
|
||||
$product = $this->productRepo->getById($offer['externalId']);
|
||||
$product->setStockData(
|
||||
['qty' => $offer['quantity'],
|
||||
'is_in_stock' => $offer['quantity'] > 0]
|
||||
);
|
||||
$product->save();
|
||||
}
|
||||
}
|
||||
|
||||
$totalPageCount = $response['pagination']['totalPageCount'];
|
||||
$page++;
|
||||
} while ($page <= $totalPageCount);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -2,7 +2,7 @@
|
||||
|
||||
namespace Retailcrm\Retailcrm\Model\Setting;
|
||||
|
||||
class DaemonCollector implements \Magento\Framework\Option\ArrayInterface
|
||||
class Select implements \Magento\Framework\Option\ArrayInterface
|
||||
{
|
||||
public function toOptionArray()
|
||||
{
|
123
src/Test/Unit/Model/Service/InventoriesUploadTest.php
Normal file
123
src/Test/Unit/Model/Service/InventoriesUploadTest.php
Normal file
@ -0,0 +1,123 @@
|
||||
<?php
|
||||
|
||||
namespace Retailcrm\Retailcrm\Test\Unit\Model\Service;
|
||||
|
||||
class InventoriesUploadTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
private $mockApi;
|
||||
private $mockProductRepository;
|
||||
private $mockResponse;
|
||||
private $mockProduct;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->mockApi = $this->getMockBuilder(\Retailcrm\Retailcrm\Helper\Proxy::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods([
|
||||
'storeInventories',
|
||||
'isConfigured'
|
||||
])
|
||||
->getMock();
|
||||
|
||||
$this->mockProductRepository = $this->getMockBuilder(\Magento\Catalog\Api\ProductRepositoryInterface::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(['getById'])
|
||||
->getMockForAbstractClass();
|
||||
|
||||
$this->mockResponse = $this->getMockBuilder(\RetailCrm\Response\ApiResponse::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(['isSuccessful'])
|
||||
->getMock();
|
||||
|
||||
$this->mockProduct = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods([
|
||||
'setStockData',
|
||||
'save'
|
||||
])
|
||||
->getMock();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $response
|
||||
*
|
||||
* @dataProvider dataProviderLoadStocks
|
||||
*/
|
||||
public function testInventoriesUpdload($response)
|
||||
{
|
||||
if ($response != false) {
|
||||
$responseInventories = new \RetailCrm\Response\ApiResponse(200, json_encode($response));
|
||||
|
||||
$this->mockResponse->expects($this->any())
|
||||
->method('isSuccessful')
|
||||
->willReturn(true);
|
||||
|
||||
$this->mockApi->expects($this->any())
|
||||
->method('isConfigured')
|
||||
->willReturn(true);
|
||||
|
||||
$this->mockApi->expects($this->any())
|
||||
->method('storeInventories')
|
||||
->willReturn($responseInventories);
|
||||
|
||||
$this->mockProductRepository->expects($this->any())
|
||||
->method('getById')
|
||||
->willReturn($this->mockProduct);
|
||||
} else {
|
||||
$this->mockResponse->expects($this->any())
|
||||
->method('isSuccessful')
|
||||
->willReturn($response);
|
||||
}
|
||||
|
||||
$inventoriesUpload = new \Retailcrm\Retailcrm\Model\Service\InventoriesUpload($this->mockProductRepository, $this->mockApi);
|
||||
$result = $inventoriesUpload->uploadInventory();
|
||||
|
||||
if (!$response['success']) {
|
||||
$this->assertEquals(false, $result);
|
||||
} else {
|
||||
$this->assertEquals(true, $result);
|
||||
}
|
||||
}
|
||||
|
||||
private function getResponseData()
|
||||
{
|
||||
return array(
|
||||
'true' => $this->getApiInventories(),
|
||||
'false' => false
|
||||
);
|
||||
}
|
||||
|
||||
public function dataProviderLoadStocks()
|
||||
{
|
||||
$response = $this->getResponseData();
|
||||
|
||||
return array(
|
||||
array(
|
||||
'response' => $response['true']
|
||||
),
|
||||
array(
|
||||
'response' => $response['false']
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private function getApiInventories()
|
||||
{
|
||||
return array(
|
||||
'success' => true,
|
||||
'pagination' => array(
|
||||
'limit' => 250,
|
||||
'totalCount' => 1,
|
||||
'currentPage' => 1,
|
||||
'totalPageCount' => 1
|
||||
),
|
||||
'offers' => array(
|
||||
array(
|
||||
'externalId' => 1,
|
||||
'xmlId' => 'xmlId',
|
||||
'quantity' => 10
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
@ -68,12 +68,19 @@
|
||||
<label>Daemon Collector</label>
|
||||
<field id="active" translate="label" type="select" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="0">
|
||||
<label>Activate</label>
|
||||
<source_model>Retailcrm\Retailcrm\Model\Setting\DaemonCollector</source_model>
|
||||
<source_model>Retailcrm\Retailcrm\Model\Setting\Select</source_model>
|
||||
</field>
|
||||
<field id="key" translate="label" type="text" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="0">
|
||||
<label>Site key</label>
|
||||
</field>
|
||||
</group>
|
||||
<group id="inventories_upload" translate="label" type="select" sortOrder="90" showInDefault="1" showInWebsite="0" showInStore="0">
|
||||
<label>Synchronization of the stock balance</label>
|
||||
<field id="active" translate="label" type="select" sortOrder="30" showInDefault="1" showInWebsite="0" showInStore="0">
|
||||
<label>Activate</label>
|
||||
<source_model>Retailcrm\Retailcrm\Model\Setting\Select</source_model>
|
||||
</field>
|
||||
</group>
|
||||
</section>
|
||||
</system>
|
||||
</config>
|
||||
|
@ -7,5 +7,8 @@
|
||||
<job name="order_hystory" instance="Retailcrm\Retailcrm\Cron\OrderHistory" method="execute">
|
||||
<schedule>*/5 * * * *</schedule>
|
||||
</job>
|
||||
<job name="inventories" instance="Retailcrm\Retailcrm\Cron\Inventories" method="execute">
|
||||
<schedule>*/15 * * * *</schedule>
|
||||
</job>
|
||||
</group>
|
||||
</config>
|
@ -23,4 +23,5 @@
|
||||
"Send","Enviar"
|
||||
"Default site","Tienda por defecto"
|
||||
"Activate","Active"
|
||||
"Site key","Clave de la página web"
|
||||
"Site key","Clave de la página web"
|
||||
"Synchronization of the stock balance","Sincronizar el stock"
|
|
@ -23,4 +23,5 @@
|
||||
"Send","Выгрузить"
|
||||
"Default site","Сайт по умолчанию"
|
||||
"Activate","Активировать"
|
||||
"Site key","Ключ сайта"
|
||||
"Site key","Ключ сайта"
|
||||
"Synchronization of the stock balance","Синхронизация остатков"
|
|
Loading…
Reference in New Issue
Block a user