40 lines
1.1 KiB
PHP
40 lines
1.1 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Esun\LingxingErp\Observer;
|
|
|
|
use Esun\LingxingErp\Model\Config;
|
|
use Esun\LingxingErp\Model\Sync\OrderSyncRepository;
|
|
use Magento\Framework\Event\Observer;
|
|
use Magento\Framework\Event\ObserverInterface;
|
|
use Psr\Log\LoggerInterface;
|
|
|
|
class EnqueueOrder implements ObserverInterface
|
|
{
|
|
public function __construct(
|
|
private readonly Config $config,
|
|
private readonly OrderSyncRepository $repository,
|
|
private readonly LoggerInterface $logger
|
|
) {
|
|
}
|
|
|
|
public function execute(Observer $observer): void
|
|
{
|
|
if (!$this->config->isEnabled()) {
|
|
return;
|
|
}
|
|
$order = $observer->getEvent()->getOrder();
|
|
if (!$order || !in_array((string)$order->getStatus(), $this->config->getEligibleStatuses(), true)) {
|
|
return;
|
|
}
|
|
try {
|
|
$this->repository->enqueue($order);
|
|
} catch (\Throwable $exception) {
|
|
$this->logger->error('Unable to enqueue Magento order for Lingxing.', [
|
|
'order_id' => $order->getEntityId(),
|
|
'exception' => $exception,
|
|
]);
|
|
}
|
|
}
|
|
}
|