Skip to content

fix(checkout): use cart weights for pickup validation - #678

Open
NabDevs wants to merge 1 commit into
mainfrom
feat/pickup-weight-validation
Open

fix(checkout): use cart weights for pickup validation#678
NabDevs wants to merge 1 commit into
mainfrom
feat/pickup-weight-validation

Conversation

@NabDevs

@NabDevs NabDevs commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

The cart can use the base product weight when the customer selects a variant with a different weight. This can cause the checkout to show or hide pickup incorrectly.

This change:

  • Uses the weight from each cart item, including the selected variant and custom options.
  • Keeps each cart product separate to prevent weight changes from affecting other variants.
  • Treats missing variant weights as unknown.
  • Uses an explicit weight unit when supplied. Otherwise, it uses the shop weight unit.

Relates to (needs): PDK PR

Resolves #671 , resolves #633

Resolves INT-1895

@codecov

codecov Bot commented Sep 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 54.06%. Comparing base (fabc5fc) to head (fd546ae).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@             Coverage Diff              @@
##               main     #678      +/-   ##
============================================
+ Coverage     53.77%   54.06%   +0.28%     
- Complexity      732      738       +6     
============================================
  Files           161      161              
  Lines          4461     4469       +8     
  Branches         57       57              
============================================
+ Hits           2399     2416      +17     
+ Misses         2005     1996       -9     
  Partials         57       57              
Flag Coverage Δ
backend 81.09% <100.00%> (+0.35%) ⬆️
frontend 2.28% <ø> (ø)
php7.4 81.09% <100.00%> (+0.35%) ⬆️
php8.0 81.06% <100.00%> (+0.35%) ⬆️
php8.1 81.01% <100.00%> (+0.36%) ⬆️
php8.2 81.01% <100.00%> (+0.36%) ⬆️
php8.3 81.01% <100.00%> (+0.36%) ⬆️
php8.4 81.01% <100.00%> (+0.36%) ⬆️
php8.5 81.01% <100.00%> (+0.36%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

🟢 Approval recommended

The changes are focused, align with the stated checkout-weight problem, and are backed by targeted unit tests for both cart-line weight mapping and unit resolution.

Pull request overview

This PR fixes pickup (servicepoint) eligibility validation during checkout by ensuring shipment weight is derived from the cart line items (including combinations/customizations) rather than potentially stale/base product weights. This prevents incorrect showing/hiding of pickup options when a selected variant has a different weight than the base product.

Changes:

  • Update PsPdkCartRepository to use per-cart-line resolved weights (and clone base products to avoid mutating cached product instances).
  • Extend PsWeightService::convertToGrams() to prefer an explicit unit when provided, otherwise fall back to the PrestaShop configured weight unit.
  • Add/extend unit tests covering cart-line weight handling, independence across combinations, and weight unit resolution.
File summaries
File Description
tests/Unit/Pdk/Cart/Repository/PsPdkCartRepositoryTest.php Adds coverage to ensure cart line weights are used without mutating cached base products and that combinations remain independent.
tests/Unit/Pdk/Base/Service/PsWeightServiceTest.php Adds tests verifying unit selection behavior (shop unit vs explicit unit).
src/Pdk/Cart/Repository/PsPdkCartRepository.php Uses cart line weights (incl. variant/customization) and avoids cross-line side effects by cloning products.
src/Pdk/Base/Service/PsWeightService.php Resolves weight unit from an explicit argument when supplied, otherwise uses PS_WEIGHT_UNIT.
Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@myparcel-bot

myparcel-bot Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

✅ Build successful!

You can find a link to the downloadable artifact below.

Name Link
Commit fd546ae
Logs https://github.com/myparcelnl/prestashop/actions/runs/34597165078
Download https://github.com/myparcelnl/prestashop/suites/93719893048/artifacts/10261569695

$product = $this->productRepository->getProduct($item['id_product']);
// getProducts() already includes combination and customization weight in shop units.
// Keep the per-line weight off the cached base product and other variants of it.
$product = clone $this->productRepository->getProduct($item['id_product']);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Would it not make more sense for the PS implementation to carry a PsPdkProductRepository (implementation of the PdkProductRepository) which always converts the weight to grams?

That way we can be sure the weight is consistently in the unit the PDK expects, not only when expressing products through the order lines in the cart.

@NabDevs NabDevs Sep 8, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

PsPdkProductRepository already converts product weights to grams. This change uses the cart item weight because it includes the selected variant and customization, which can differ from the base product.

We convert that raw cart weight to grams and apply it to a clone. This keeps the cached base product unchanged, the existing PDK weight is not converted twice.

Would you still prefer to move this cart-specific mapping into PsPdkProductRepository?

@myparcel-bot myparcel-bot Bot added the changes requested (Auto) label Sep 8, 2026
@NabDevs
NabDevs requested a review from FreekVR September 8, 2026 10:47
@NabDevs

NabDevs commented Sep 8, 2026

Copy link
Copy Markdown
Contributor Author

@FreekVR I will follow the approach discussed in myparcelnl/pdk#532 and move the weight check to DO. The variant weight will stay in the cart repository, as it depends on the selected cart item. I will update the ticket with the related changes.

@myparcel-bot
myparcel-bot Bot force-pushed the feat/pickup-weight-validation branch from 99a05d4 to 8f34bde Compare September 10, 2026 06:45
@myparcel-bot
myparcel-bot Bot force-pushed the feat/pickup-weight-validation branch from 8f34bde to fd546ae Compare September 11, 2026 12:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

validatie van gewicht voor zendingen naar een afhaalpunt beperkingen van gewicht voor zendingen naar een afhaalpunt

3 participants