fix(checkout): use cart weights for pickup validation - #678
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🟢 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
PsPdkCartRepositoryto 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.
|
✅ Build successful! You can find a link to the downloadable artifact below.
|
| $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']); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
|
@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. |
99a05d4 to
8f34bde
Compare
8f34bde to
fd546ae
Compare
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:
Relates to (needs): PDK PR
Resolves #671 , resolves #633
Resolves INT-1895