init
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Esun\LingxingErp\Block\Adminhtml\Store;
|
||||
|
||||
use Magento\Backend\Block\Widget\Button;
|
||||
|
||||
class ErpSkuSyncButton extends Button
|
||||
{
|
||||
protected function _construct(): void
|
||||
{
|
||||
parent::_construct();
|
||||
$url = $this->getUrl('esun_lingxing/sku/sync');
|
||||
$message = (string)__('Fetch ERP SKUs for products in all configured Websites now?');
|
||||
$this->setData([
|
||||
'label' => __('Sync Product ERP SKUs'),
|
||||
'class' => 'secondary',
|
||||
'style' => 'margin-left: 12px;',
|
||||
'onclick' => sprintf(
|
||||
'confirmSetLocation(%s, %s)',
|
||||
json_encode($message, JSON_HEX_APOS | JSON_HEX_QUOT),
|
||||
json_encode($url, JSON_HEX_APOS | JSON_HEX_QUOT)
|
||||
),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Esun\LingxingErp\Block\Adminhtml\Store;
|
||||
|
||||
use Magento\Backend\Block\Widget\Button;
|
||||
|
||||
class SyncButton extends Button
|
||||
{
|
||||
protected function _construct(): void
|
||||
{
|
||||
parent::_construct();
|
||||
$url = $this->getUrl('esun_lingxing/store/sync');
|
||||
$message = (string)__('Fetch all stores from Lingxing now?');
|
||||
$this->setData([
|
||||
'label' => __('Sync Stores'),
|
||||
'class' => 'primary',
|
||||
'onclick' => sprintf(
|
||||
'confirmSetLocation(%s, %s)',
|
||||
json_encode($message, JSON_HEX_APOS | JSON_HEX_QUOT),
|
||||
json_encode($url, JSON_HEX_APOS | JSON_HEX_QUOT)
|
||||
),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Esun\LingxingErp\Block\Adminhtml\Sync;
|
||||
|
||||
use Esun\LingxingErp\Model\Sync\DetailProvider;
|
||||
use Magento\Backend\Block\Template;
|
||||
use Magento\Backend\Block\Template\Context;
|
||||
|
||||
class Details extends Template
|
||||
{
|
||||
private ?array $record = null;
|
||||
|
||||
public function __construct(
|
||||
Context $context,
|
||||
private readonly DetailProvider $detailProvider,
|
||||
array $data = []
|
||||
) {
|
||||
parent::__construct($context, $data);
|
||||
}
|
||||
|
||||
public function getSyncType(): string
|
||||
{
|
||||
return (string)$this->getData('sync_type');
|
||||
}
|
||||
|
||||
/** @return array<string, mixed> */
|
||||
public function getRecord(): array
|
||||
{
|
||||
if ($this->record === null) {
|
||||
$this->record = $this->detailProvider->getRecord(
|
||||
$this->getSyncType(),
|
||||
(int)$this->getRequest()->getParam('id')
|
||||
) ?? [];
|
||||
}
|
||||
return $this->record;
|
||||
}
|
||||
|
||||
/** @return array<int, array<string, mixed>> */
|
||||
public function getLogs(): array
|
||||
{
|
||||
$record = $this->getRecord();
|
||||
return $record === [] ? [] : $this->detailProvider->getLogs($this->getSyncType(), $record);
|
||||
}
|
||||
|
||||
public function getBackUrl(): string
|
||||
{
|
||||
return $this->getUrl('esun_lingxing/' . $this->getSyncType() . '/index');
|
||||
}
|
||||
|
||||
public function prettyPayload(mixed $payload): string
|
||||
{
|
||||
if ($payload === null || $payload === '') {
|
||||
return (string)__('No data recorded.');
|
||||
}
|
||||
if (is_string($payload)) {
|
||||
try {
|
||||
$decoded = json_decode($payload, true, 512, JSON_THROW_ON_ERROR);
|
||||
return (string)json_encode(
|
||||
$decoded,
|
||||
JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_THROW_ON_ERROR
|
||||
);
|
||||
} catch (\JsonException) {
|
||||
return $payload;
|
||||
}
|
||||
}
|
||||
try {
|
||||
return (string)json_encode(
|
||||
$payload,
|
||||
JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_THROW_ON_ERROR
|
||||
);
|
||||
} catch (\JsonException) {
|
||||
return (string)__('Unable to display data.');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Esun\LingxingErp\Block\Adminhtml\Warehouse;
|
||||
|
||||
use Magento\Backend\Block\Widget\Button;
|
||||
|
||||
class InventorySyncButton extends Button
|
||||
{
|
||||
protected function _construct(): void
|
||||
{
|
||||
parent::_construct();
|
||||
$this->setData([
|
||||
'label' => __('Sync Inventory'),
|
||||
'class' => 'secondary',
|
||||
'style' => 'margin-left: 12px;',
|
||||
'onclick' => sprintf(
|
||||
'confirmSetLocation(%s, %s)',
|
||||
json_encode((string)__('Synchronize product_valid_num for Sources assigned to Website Stocks now?'), JSON_HEX_APOS | JSON_HEX_QUOT),
|
||||
json_encode($this->getUrl('esun_lingxing/warehouse/syncInventory'), JSON_HEX_APOS | JSON_HEX_QUOT)
|
||||
),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Esun\LingxingErp\Block\Adminhtml\Warehouse;
|
||||
|
||||
use Magento\Backend\Block\Widget\Button;
|
||||
|
||||
class ManageSourcesButton extends Button
|
||||
{
|
||||
protected function _construct(): void
|
||||
{
|
||||
parent::_construct();
|
||||
$this->setData([
|
||||
'label' => __('Map Source Warehouses'),
|
||||
'class' => 'secondary',
|
||||
'style' => 'margin-left: 12px;',
|
||||
'onclick' => sprintf('setLocation(%s)', json_encode(
|
||||
$this->getUrl('inventory/source/index'),
|
||||
JSON_HEX_APOS | JSON_HEX_QUOT
|
||||
)),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Esun\LingxingErp\Block\Adminhtml\Warehouse;
|
||||
|
||||
use Magento\Backend\Block\Widget\Button;
|
||||
|
||||
class ManageStocksButton extends Button
|
||||
{
|
||||
protected function _construct(): void
|
||||
{
|
||||
parent::_construct();
|
||||
$this->setData([
|
||||
'label' => __('Manage Stock Assignments'),
|
||||
'class' => 'secondary',
|
||||
'style' => 'margin-left: 12px;',
|
||||
'onclick' => sprintf('setLocation(%s)', json_encode(
|
||||
$this->getUrl('inventory/stock/index'),
|
||||
JSON_HEX_APOS | JSON_HEX_QUOT
|
||||
)),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Esun\LingxingErp\Block\Adminhtml\Warehouse;
|
||||
|
||||
use Magento\Backend\Block\Widget\Button;
|
||||
|
||||
class SyncButton extends Button
|
||||
{
|
||||
protected function _construct(): void
|
||||
{
|
||||
parent::_construct();
|
||||
$this->setData([
|
||||
'label' => __('Sync Warehouses'),
|
||||
'class' => 'primary',
|
||||
'onclick' => sprintf(
|
||||
'confirmSetLocation(%s, %s)',
|
||||
json_encode((string)__('Fetch and cache Lingxing type 3 warehouses now? Magento Sources will not be changed.'), JSON_HEX_APOS | JSON_HEX_QUOT),
|
||||
json_encode($this->getUrl('esun_lingxing/warehouse/sync'), JSON_HEX_APOS | JSON_HEX_QUOT)
|
||||
),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user