update
This commit is contained in:
@@ -4,8 +4,16 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Email;
|
||||
|
||||
use App\Modules\Shipments\DeliveryStatus;
|
||||
use App\Modules\Shipments\ShipmentPackageRepository;
|
||||
|
||||
final class VariableResolver
|
||||
{
|
||||
public function __construct(
|
||||
private readonly ShipmentPackageRepository $shipmentPackageRepository
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $order
|
||||
* @param array<int, array<string, mixed>> $addresses
|
||||
@@ -27,7 +35,7 @@ final class VariableResolver
|
||||
$orderedAt = date('Y-m-d', $ts);
|
||||
}
|
||||
|
||||
return [
|
||||
$baseVariables = [
|
||||
'zamowienie.numer' => (string) ($order['internal_order_number'] ?? $order['id'] ?? ''),
|
||||
'zamowienie.numer_zewnetrzny' => (string) ($order['external_order_id'] ?? $order['source_order_id'] ?? ''),
|
||||
'zamowienie.zrodlo' => ucfirst((string) ($order['source'] ?? '')),
|
||||
@@ -45,6 +53,8 @@ final class VariableResolver
|
||||
'firma.nazwa' => (string) ($companySettings['company_name'] ?? ''),
|
||||
'firma.nip' => (string) ($companySettings['tax_number'] ?? ''),
|
||||
];
|
||||
|
||||
return $baseVariables + $this->resolveShipmentVariables($order);
|
||||
}
|
||||
|
||||
public function resolve(string $template, array $variableMap): string
|
||||
@@ -70,4 +80,37 @@ final class VariableResolver
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $order
|
||||
* @return array<string, string>
|
||||
*/
|
||||
private function resolveShipmentVariables(array $order): array
|
||||
{
|
||||
$orderId = (int) ($order['id'] ?? 0);
|
||||
if ($orderId <= 0) {
|
||||
return [
|
||||
'przesylka.numer' => '',
|
||||
'przesylka.link_sledzenia' => '',
|
||||
];
|
||||
}
|
||||
|
||||
$latestPackage = $this->shipmentPackageRepository->findLatestByOrderId($orderId);
|
||||
if (!is_array($latestPackage)) {
|
||||
return [
|
||||
'przesylka.numer' => '',
|
||||
'przesylka.link_sledzenia' => '',
|
||||
];
|
||||
}
|
||||
|
||||
$trackingNumber = trim((string) ($latestPackage['tracking_number'] ?? ''));
|
||||
$provider = trim((string) ($latestPackage['provider'] ?? ''));
|
||||
$carrierId = trim((string) ($latestPackage['carrier_id'] ?? ''));
|
||||
$trackingUrl = DeliveryStatus::trackingUrl($provider, $trackingNumber, $carrierId) ?? '';
|
||||
|
||||
return [
|
||||
'przesylka.numer' => $trackingNumber,
|
||||
'przesylka.link_sledzenia' => $trackingUrl,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user