feat(104-apaczka-weekend-delivery): Apaczka Paczka w Weekend dla paczkomatow InPost
Phase 104 complete: - Backend: ApaczkaShipmentService::buildOptionsPayload() mapuje weekend_delivery -> option[19] = 1 w payloadzie API Apaczka v2 - Stala OPTION_KEYS jako rozszerzalne mapowanie pole formularza -> id opcji Apaczki - Frontend: checkbox "Dostawa w weekend (sobota)" w prepare.php widoczny tylko dla supplier=INPOST + paczkomat (door_to_point=1 lub point_to_point=1) - JS toggle oparty na atrybutach data-supplier/data-paczkomat z resetem stanu - 3 nowe testy jednostkowe pokrywajace mapowanie buildOptionsPayload (phpunit OK 11/11) - Hotfix integracyjny po UAT: ShipmentController::create() nie przekazywal pola weekend_delivery z requestu do formData providera (root cause: reczna lista pol w controllerze) - Dokumentacja zaktualizowana (DOCS/ARCHITECTURE.md, DOCS/TECH_CHANGELOG.md) DEFER-104-01: rozwazyc test integracyjny pelnego flow controller -> service lub refactor na request->all(). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -15,6 +15,15 @@ final class ApaczkaShipmentService implements ShipmentProviderInterface
|
||||
{
|
||||
private const PICKUP_DATE_RETRY_DAYS = 7;
|
||||
|
||||
/**
|
||||
* Mapowanie pol formularza na klucze opcji API Apaczki (option[]).
|
||||
* Wartosci kluczy to identyfikatory z service_structure.response.options.
|
||||
* - 19 = dostawa w sobote (InPost Paczka w Weekend)
|
||||
*/
|
||||
private const OPTION_KEYS = [
|
||||
'weekend_delivery' => 19,
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array<string, array{street:string,postal_code:string,city:string}>
|
||||
*/
|
||||
@@ -100,6 +109,10 @@ final class ApaczkaShipmentService implements ShipmentProviderInterface
|
||||
'content' => 'orderPRO ' . ($sourceOrderId !== '' ? $sourceOrderId : (string) $orderId),
|
||||
'comment' => 'orderPRO ' . ($sourceOrderId !== '' ? $sourceOrderId : (string) $orderId),
|
||||
];
|
||||
$options = $this->buildOptionsPayload($formData);
|
||||
if ($options !== []) {
|
||||
$apiPayload['option'] = $options;
|
||||
}
|
||||
$pickup = $this->buildPickupPayload($serviceDefinition, $senderPointId, $formData);
|
||||
if ($pickup !== []) {
|
||||
$apiPayload['pickup'] = $pickup;
|
||||
@@ -818,6 +831,24 @@ final class ApaczkaShipmentService implements ShipmentProviderInterface
|
||||
return 'COURIER';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $formData
|
||||
* @return array<int, int>
|
||||
*/
|
||||
private function buildOptionsPayload(array $formData): array
|
||||
{
|
||||
$result = [];
|
||||
foreach (self::OPTION_KEYS as $formField => $apiOptionId) {
|
||||
$value = $formData[$formField] ?? null;
|
||||
$isTruthy = filter_var($value, FILTER_VALIDATE_BOOL, FILTER_NULL_ON_FAILURE);
|
||||
if ($isTruthy === true) {
|
||||
$result[$apiOptionId] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed>|null $serviceDefinition
|
||||
* @param array<string, mixed> $formData
|
||||
|
||||
@@ -204,6 +204,7 @@ final class ShipmentController
|
||||
'receiver_email' => (string) $request->input('receiver_email', ''),
|
||||
'receiver_point_id' => (string) $request->input('receiver_point_id', ''),
|
||||
'sender_point_id' => (string) $request->input('sender_point_id', ''),
|
||||
'weekend_delivery' => (string) $request->input('weekend_delivery', ''),
|
||||
]);
|
||||
|
||||
$packageId = (int) ($result['package_id'] ?? 0);
|
||||
|
||||
Reference in New Issue
Block a user