Skip to content

fix(checkout): guard invalid carrier settings - #521

Open
NabDevs wants to merge 6 commits into
mainfrom
feat/guard-invalid-carrier-settings
Open

fix(checkout): guard invalid carrier settings#521
NabDevs wants to merge 6 commits into
mainfrom
feat/guard-invalid-carrier-settings

Conversation

@NabDevs

@NabDevs NabDevs commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Note: this PR was previously merged as #513, but had to be rolled back from main because it still needs to be tested. It was already approved by @joerivanveen and @FreekVR at the time.

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

@NabDevs
NabDevs requested a review from a team as a code owner August 7, 2026 08:40
Copilot AI lite review requested due to automatic review settings August 7, 2026 08:40
@github-project-automation github-project-automation Bot moved this to Todo in PDK Aug 7, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
});
@myparcel-bot myparcel-bot Bot added the approved (Auto) label Aug 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved (Auto)

Development

Successfully merging this pull request may close these issues.

4 participants