init
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Esun\SeventeenTrack\Model;
|
||||
|
||||
use Magento\Sales\Api\OrderRepositoryInterface;
|
||||
|
||||
class DeliveryStatusUpdater
|
||||
{
|
||||
public function __construct(
|
||||
private readonly Config $config,
|
||||
private readonly TrackingRepository $tracking,
|
||||
private readonly OrderRepositoryInterface $orders
|
||||
) {
|
||||
}
|
||||
|
||||
public function execute(array $orderIds): void
|
||||
{
|
||||
if (!$this->config->shouldAutoReceive()) {
|
||||
return;
|
||||
}
|
||||
foreach (array_unique(array_map('intval', $orderIds)) as $orderId) {
|
||||
if (!$this->tracking->isOrderDelivered($orderId)) {
|
||||
continue;
|
||||
}
|
||||
$order = $this->orders->get($orderId);
|
||||
if ((string)$order->getStatus() !== 'shipped') {
|
||||
continue;
|
||||
}
|
||||
$order->setStatus('received');
|
||||
$order->addCommentToStatusHistory(
|
||||
__('17TRACK confirmed that every shipment was delivered and signed for.'),
|
||||
'received',
|
||||
false
|
||||
);
|
||||
$this->orders->save($order);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user