42 lines
1.5 KiB
PHP
42 lines
1.5 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Esun\LingxingErp\Controller\Adminhtml\Sku;
|
|
|
|
use Esun\LingxingErp\Model\Sku\SkuSynchronizer;
|
|
use Magento\Backend\App\Action;
|
|
use Magento\Framework\App\Action\HttpGetActionInterface;
|
|
|
|
class Sync extends Action implements HttpGetActionInterface
|
|
{
|
|
public const ADMIN_RESOURCE = 'Esun_LingxingErp::sync_sku_mappings';
|
|
|
|
public function __construct(Action\Context $context, private readonly SkuSynchronizer $synchronizer)
|
|
{
|
|
parent::__construct($context);
|
|
}
|
|
|
|
public function execute()
|
|
{
|
|
try {
|
|
$summary = $this->synchronizer->synchronizeAll();
|
|
if ($summary['errors'] !== []) {
|
|
$this->messageManager->addErrorMessage(__(
|
|
'ERP SKU synchronization completed with %1 Website error(s). Review Synchronization Logs.',
|
|
count($summary['errors'])
|
|
));
|
|
}
|
|
$this->messageManager->addSuccessMessage(__(
|
|
'Processed %1 Website(s) and %2 pair(s): %3 mapped, %4 products remain without an ERP SKU.',
|
|
$summary['websites'],
|
|
$summary['pairs'],
|
|
$summary['mapped'],
|
|
$summary['unmapped']
|
|
));
|
|
} catch (\Throwable $exception) {
|
|
$this->messageManager->addErrorMessage(__('ERP SKU synchronization failed: %1', $exception->getMessage()));
|
|
}
|
|
return $this->resultRedirectFactory->create()->setPath('esun_lingxing/store/index');
|
|
}
|
|
}
|