fix(checkout): guard invalid carrier settings - #521
Open
NabDevs wants to merge 6 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens checkout delivery-options generation against missing or malformed carrier settings to prevent crashes, falling back to the default package type and (in the invalid-settings case) returning no carriers. It also adds/extends unit coverage around malformed settings handling.
Changes:
- Sanitize carrier settings data when reading settings collections and when determining enabled carriers/capabilities.
- Add invalid/missing carrier settings regression tests and extend capability tests to ensure malformed entries don’t break valid carriers.
- Adjust a delivery options config test setup to include carrier settings.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Unit/Settings/Repository/AbstractSettingsRepositoryTest.php | Adds regression test for skipping malformed collection entries (needs null-safety fix). |
| tests/Unit/App/DeliveryOptions/Service/DeliveryOptionsServiceInvalidCarrierSettingsTest.php | New test ensuring invalid/missing carrier settings do not expose carriers and default package type is used. |
| tests/Unit/App/DeliveryOptions/Service/DeliveryOptionsServiceCapabilitiesTest.php | Adds coverage for malformed carrier entry alongside valid settings (needs state cleanup to avoid test pollution). |
| tests/Unit/App/Context/Model/DeliveryOptionsConfigTest.php | Ensures carrier settings exist in the test setup so config calculation remains valid. |
| src/Settings/Repository/AbstractPdkSettingsRepository.php | Skips non-array category payloads and malformed per-item values when reconstructing settings collections. |
| src/Carrier/Service/CapabilitiesValidationService.php | Guards against non-array carrier settings and non-array carrier entries when filtering enabled carriers. |
| src/App/DeliveryOptions/Service/DeliveryOptionsService.php | Filters invalid carrier settings early and returns default package type + no carriers when settings are invalid/empty. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+57
to
+71
| $currentCarrierSettings = $repository->get($createSettingsKey(CarrierSettings::ID)); | ||
|
|
||
| try { | ||
| $repository->store($createSettingsKey(CarrierSettings::ID), array_merge($currentCarrierSettings, [ | ||
| 'valid' => [CarrierSettings::DELIVERY_OPTIONS_ENABLED => true], | ||
| 'invalid' => 'invalid', | ||
| ])); | ||
|
|
||
| $carrierSettings = $repository->all()->carrier; | ||
|
|
||
| expect($carrierSettings->has('valid'))->toBeTrue() | ||
| ->and($carrierSettings->has('invalid'))->toBeFalse(); | ||
| } finally { | ||
| $repository->store($createSettingsKey(CarrierSettings::ID), $currentCarrierSettings); | ||
| } |
Comment on lines
+321
to
+345
| $settingsRepository->store($settingsKey, array_merge($carrierSettings, ['invalid' => 'invalid'])); | ||
|
|
||
| factory(Shop::class) | ||
| ->withCarriers( | ||
| factory(CarrierCollection::class) | ||
| ->push(factory(Carrier::class) | ||
| ->withCarrier($carrierName) | ||
| ->withCapabilityPackageTypes(['PACKAGE'])) | ||
| ) | ||
| ->store(); | ||
|
|
||
| resetStorageCache(); | ||
|
|
||
| enqueueCapabilitiesPerType([ | ||
| 'PACKAGE' => [capabilityResult($carrierName, 100, ['PACKAGE'])], | ||
| ]); | ||
|
|
||
| /** @var DeliveryOptionsServiceInterface $service */ | ||
| $service = Pdk::get(DeliveryOptionsServiceInterface::class); | ||
| $result = $service->createAllCarrierSettings(makeCart('NL')); | ||
|
|
||
| $carrierId = FrontendData::getLegacyCarrierIdentifier($carrierName); | ||
|
|
||
| expect($result['carrierSettings'])->toHaveKey($carrierId); | ||
| }); |
FreekVR
approved these changes
Aug 7, 2026
GravendeelJochem
approved these changes
Aug 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Prevents the checkout from crashing when carrier settings are missing or invalid. In that case, the delivery options service uses the default package type and returns no carriers. Includes regression coverage for missing and malformed settings.
Relates to: Woo PR
fixes INT-1730