1
0
mirror of synced 2024-11-21 20:46:06 +03:00

Merge pull request #20 from sergeygw1990/master

v2.4.0
This commit is contained in:
Alex Lushpai 2019-01-24 14:33:56 +03:00 committed by GitHub
commit 86124b1978
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 238 additions and 6 deletions

View File

@ -1,3 +1,6 @@
## 2018-12-25 v.2.4.0
* Добавлен функционал получения остатков из retailCRM
## 2018-12-25 v.2.3.2 ## 2018-12-25 v.2.3.2
* Добавлена выгрузка картинок категорий товаров в ICML * Добавлена выгрузка картинок категорий товаров в ICML

View File

@ -1 +1 @@
2.3.2 2.4.0

24
src/Cron/Inventories.php Normal file
View 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();
}
}
}

View File

@ -16,6 +16,7 @@ class Data extends AbstractHelper
const XML_PATH_DEFAULT_SITE = 'retailcrm_site/default'; const XML_PATH_DEFAULT_SITE = 'retailcrm_site/default';
const XML_PATH_SITES = 'retailcrm_sites/'; const XML_PATH_SITES = 'retailcrm_sites/';
const XML_PATH_DAEMON_COLLECTOR = 'daemon_collector/'; const XML_PATH_DAEMON_COLLECTOR = 'daemon_collector/';
const XML_PATH_INVENTORIES = 'inventories_upload/';
public function __construct( public function __construct(
Context $context, Context $context,
@ -131,6 +132,20 @@ class Data extends AbstractHelper
return false; 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 * @param $website
* *

View 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;
}
}

View File

@ -2,7 +2,7 @@
namespace Retailcrm\Retailcrm\Model\Setting; namespace Retailcrm\Retailcrm\Model\Setting;
class DaemonCollector implements \Magento\Framework\Option\ArrayInterface class Select implements \Magento\Framework\Option\ArrayInterface
{ {
public function toOptionArray() public function toOptionArray()
{ {

View 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
)
)
);
}
}

View File

@ -5,7 +5,7 @@
"retailcrm/api-client-php": "~5.0" "retailcrm/api-client-php": "~5.0"
}, },
"type": "magento2-module", "type": "magento2-module",
"version": "2.3.2", "version": "2.4.0",
"license": [ "license": [
"OSL-3.0", "OSL-3.0",
"AFL-3.0" "AFL-3.0"

View File

@ -68,12 +68,19 @@
<label>Daemon Collector</label> <label>Daemon Collector</label>
<field id="active" translate="label" type="select" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="0"> <field id="active" translate="label" type="select" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Activate</label> <label>Activate</label>
<source_model>Retailcrm\Retailcrm\Model\Setting\DaemonCollector</source_model> <source_model>Retailcrm\Retailcrm\Model\Setting\Select</source_model>
</field> </field>
<field id="key" translate="label" type="text" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="0"> <field id="key" translate="label" type="text" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Site key</label> <label>Site key</label>
</field> </field>
</group> </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> </section>
</system> </system>
</config> </config>

View File

@ -7,5 +7,8 @@
<job name="order_hystory" instance="Retailcrm\Retailcrm\Cron\OrderHistory" method="execute"> <job name="order_hystory" instance="Retailcrm\Retailcrm\Cron\OrderHistory" method="execute">
<schedule>*/5 * * * *</schedule> <schedule>*/5 * * * *</schedule>
</job> </job>
<job name="inventories" instance="Retailcrm\Retailcrm\Cron\Inventories" method="execute">
<schedule>*/15 * * * *</schedule>
</job>
</group> </group>
</config> </config>

View File

@ -23,4 +23,5 @@
"Send","Enviar" "Send","Enviar"
"Default site","Tienda por defecto" "Default site","Tienda por defecto"
"Activate","Active" "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"
1 Settings La configuración
23 Send Enviar
24 Default site Tienda por defecto
25 Activate Active
26 Site key Clave de la página web
27 Synchronization of the stock balance Sincronizar el stock

View File

@ -23,4 +23,5 @@
"Send","Выгрузить" "Send","Выгрузить"
"Default site","Сайт по умолчанию" "Default site","Сайт по умолчанию"
"Activate","Активировать" "Activate","Активировать"
"Site key","Ключ сайта" "Site key","Ключ сайта"
"Synchronization of the stock balance","Синхронизация остатков"
1 Settings Настройки
23 Send Выгрузить
24 Default site Сайт по умолчанию
25 Activate Активировать
26 Site key Ключ сайта
27 Synchronization of the stock balance Синхронизация остатков