Skip to content

feat(checkout): pass the cart's shipment options to the delivery options widget - #510

Open
FreekVR wants to merge 5 commits into
mainfrom
fix/INT-1596-checkout-shipment-options
Open

feat(checkout): pass the cart's shipment options to the delivery options widget#510
FreekVR wants to merge 5 commits into
mainfrom
fix/INT-1596-checkout-shipment-options

Conversation

@FreekVR

@FreekVR FreekVR commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Adds the cart's calculated shipment options to the checkout context, and fixes the age check (18+) rules on the carrier settings screen.

The checkout context gets a new optional cartShipmentOptions key (a sibling of config): per carrier, the widget's camelCase option name → boolean, calculated by running the cart through the same pipeline an order export uses. The delivery options widget shows those options (like the ones 18+ requires) as checked and locked for the consumer; without the key the widget behaves as before. js-pdk forwards the key to the widget in myparcelnl/js-pdk#381.

On the carrier settings screen the 18+ rules now lock signature and only recipient only when 18+ is actually on — the lock previously also matched "inherit". Test fixtures now carry the real capability rules for age verification (requires signature and only recipient, excludes receipt code), with regression tests pinning the export path.

Merge order for INT-1596:

  1. feat(checkout): lock shipment options the cart already decided on delivery-options#480 — its release adds cartShipmentOptions to the widget input.
  2. fix(admin): enforce carrier rules on shipment options in settings and orders js-pdk#381 — bump @myparcel-dev/delivery-options there afterwards to turn its typecheck green.
  3. This PR — independent, can merge any time.

Fixes INT-1596
Subtask: INT-1732

🤖 Generated with Claude Code

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 extends the checkout context with cart-calculated shipment options per carrier (so the delivery options widget can display/lock merchant-forced options like 18+) and fixes the age-check (18+) locking logic on the carrier settings UI to only apply when age check is explicitly enabled.

Changes:

  • Add DeliveryOptionsServiceInterface::createCartShipmentOptions() and compute per-carrier shipment options by running a cart-derived synthetic order through the export calculation pipeline.
  • Add CheckoutContext::cartShipmentOptions and convert calculated ShipmentOptions tri-state values into widget-format booleans at the context boundary.
  • Fix carrier settings UI behavior so signature/only-recipient are locked only when age check is explicitly ENABLED, and update/add regression tests + fixtures to reflect real capability requires/excludes rules.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/Unit/Frontend/View/CarrierSettingsItemViewTest.php Adds regression coverage for strict tri-state operations and correct locking behavior for age check.
tests/Unit/App/Order/Service/PdkOrderOptionsServiceTest.php Adds regression test ensuring capability “requires/excludes” are enforced when age check originates from carrier settings.
tests/Unit/App/DeliveryOptions/Service/DeliveryOptionsServiceCartShipmentOptionsTest.php New tests covering per-carrier cart shipment-options calculation and exposure through checkout context as widget booleans.
tests/Unit/App/Action/Backend/Order/ExportOrderActionTest.php Strengthens export assertions for age check cascading behavior.
tests/SdkApi/Response/ExampleContractDefinitionsResponse.php Documents API asymmetry: requires/excludes relations live on capabilities, not contract definitions.
tests/Bootstrap/MockCarrierCapabilitiesRepository.php Updates permissive capabilities fixture with real age-verification requires/excludes relations.
tests/snapshots/SettingsViewTest__it_gets_settings_view_with_data_set_carrier_settings__1.json Snapshot update reflecting strict $eq conditions for read-only behavior.
tests/snapshots/FrontendRenderServiceTest__it_renders_component_with_data_set_plugin_settings__1.json Snapshot update reflecting strict $eq conditions for read-only behavior.
tests/snapshots/FrontendRenderServiceTest__it_renders_component_with_data_set_delivery_options__1.json Snapshot update adding cartShipmentOptions to checkout context output.
tests/snapshots/ContextServiceTest__it_gets_context_data_with_data_set_delivery_options_config__1.json Snapshot update adding cartShipmentOptions to checkout context output.
src/Shipment/Model/ShipmentOptions.php Adds ShipmentOptions::toBooleanOptions() to convert strict tri-state options to widget booleans.
src/Shipment/Collection/ShipmentOptionsCollection.php Introduces a typed collection for ShipmentOptions, used as return type for cart shipment options per carrier.
src/Frontend/View/CarrierSettingsItemView.php Fixes age-check dependent locking to only apply when age check is explicitly enabled.
src/Context/Model/CheckoutContext.php Adds cartShipmentOptions to the checkout context and populates it from the cart calculation pipeline.
src/App/DeliveryOptions/Service/DeliveryOptionsService.php Implements cart shipment option calculation per carrier via synthetic order + export pipeline.
src/App/DeliveryOptions/Contract/DeliveryOptionsServiceInterface.php Adds new createCartShipmentOptions() contract method.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/App/DeliveryOptions/Service/DeliveryOptionsService.php
Comment thread tests/Unit/App/Action/Backend/Order/ExportOrderActionTest.php Outdated
Comment thread src/Context/Model/CheckoutContext.php
@codecov

codecov Bot commented Jul 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.56716% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.25%. Comparing base (0a13274) to head (6538122).

Files with missing lines Patch % Lines
...DeliveryOptions/Service/DeliveryOptionsService.php 79.41% 7 Missing ⚠️
.../Carrier/Service/CapabilitiesValidationService.php 75.00% 1 Missing ⚠️
...tings/Repository/AbstractPdkSettingsRepository.php 85.71% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main     #510      +/-   ##
============================================
- Coverage     94.33%   94.25%   -0.08%     
- Complexity     2414     2434      +20     
============================================
  Files           352      352              
  Lines          7726     7784      +58     
============================================
+ Hits           7288     7337      +49     
- Misses          438      447       +9     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@NabDevs NabDevs 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.

1 thing to check, looks good otherwise.

Comment thread src/App/DeliveryOptions/Service/DeliveryOptionsService.php
@github-project-automation github-project-automation Bot moved this from Todo to Needs work in PDK Jul 24, 2026
@myparcel-bot myparcel-bot Bot added the changes requested (Auto) label Jul 24, 2026
Comment thread src/App/DeliveryOptions/Service/DeliveryOptionsService.php
@FreekVR
FreekVR requested a review from NabDevs July 29, 2026 09:24
@FreekVR
FreekVR requested a review from GravendeelJochem July 30, 2026 07:35
@github-project-automation github-project-automation Bot moved this from Needs work to Testing in PDK Jul 30, 2026
@myparcel-bot myparcel-bot Bot added approved (Auto) and removed changes requested (Auto) labels Jul 30, 2026
@myparcel-bot
myparcel-bot Bot force-pushed the fix/INT-1596-checkout-shipment-options branch 6 times, most recently from 1a5abae to f38fb67 Compare August 6, 2026 14:18
@myparcel-bot
myparcel-bot Bot force-pushed the fix/INT-1596-checkout-shipment-options branch from f38fb67 to f030936 Compare August 7, 2026 08:39
* Guard carrier settings

* test: clean carrier guard

* fix: validate carrier entries

* fix: ignore malformed carrier settings

* refactor: simplify carrier settings guard
FreekVR and others added 4 commits August 7, 2026 14:34
The checkout context now contains, per carrier, the shipment options
an order from this cart would be exported with — resolved through the
same settings chain and capabilities rules the export runs. The
delivery options widget uses this to show and lock options that are
already decided on the merchant side, like 18+ forcing signature and
only recipient on.

Also fixes the carrier settings screen locking signature and only
recipient while 18+ was merely inheriting, and gives the test
fixtures the real age verification rules from the capabilities API so
the requires propagation is pinned by tests end to end.

Resolves INT-1596

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…in the age check export test

The createCartShipmentOptions docblock claimed the result is converted to the
capabilities key-space; it returns calculated ShipmentOptions models, and the
widget-format boolean conversion happens at the CheckoutContext boundary. The
age check export test now also asserts that receipt code is off, matching the
capability rules it already describes.

Resolves INT-1596

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…tion uses the customer note

Building the checkout context runs the cart through the same calculation an
export does, on an order that only exists in memory. With [CUSTOMER_NOTE] in
the label description setting, that calculation asked the shop for the order's
notes, and looking notes up without an order identifier throws in WooCommerce
and PrestaShop — taking the checkout down with it.

An order without an identifier now simply has no notes, so nothing asks the
shop for them, and the cart's order is built with empty notes to say so up
front. Tests use a note repository that rejects a missing identifier like the
platforms do, so this cannot pass silently again.

Resolves INT-1596

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…s from the cart

the application should degrade gracefully if the shipment options from a pending cart cannot be calculated for whatever reason
@myparcel-bot
myparcel-bot Bot force-pushed the fix/INT-1596-checkout-shipment-options branch from f030936 to 6538122 Compare August 7, 2026 14:34
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