Files
esun3d/app/code/Esun/LingxingErp/Controller/Adminhtml/Sync/Retry.php
T
2026-09-15 10:35:56 +08:00

38 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
namespace Esun\LingxingErp\Controller\Adminhtml\Sync;
use Esun\LingxingErp\Model\Sync\OrderSyncRepository;
use Esun\LingxingErp\Model\Sync\ShipmentSyncRepository;
use Magento\Backend\App\Action;
use Magento\Framework\Controller\Result\Redirect;
class Retry extends Action
{
public const ADMIN_RESOURCE = 'Esun_LingxingErp::retry';
public function __construct(
Action\Context $context,
private readonly OrderSyncRepository $orderRepository,
private readonly ShipmentSyncRepository $shipmentRepository
) {
parent::__construct($context);
}
public function execute(): Redirect
{
$id = (int)$this->getRequest()->getParam('id');
$type = (string)$this->getRequest()->getParam('type');
$retried = $type === 'order'
? $this->orderRepository->retry($id)
: ($type === 'shipment' && $this->shipmentRepository->retry($id));
if ($retried) {
$this->messageManager->addSuccessMessage(__('The synchronization was queued for retry.'));
} else {
$this->messageManager->addErrorMessage(__('This record cannot be retried in its current state.'));
}
return $this->resultRedirectFactory->create()->setRefererUrl();
}
}