Fixed quantity range in pricing matrix#560
Fixed quantity range in pricing matrix#560girishpanchal30 wants to merge 4 commits intodevelopmentfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Improves Price Matrix quantity tier selection to support “less than”, explicit ranges, and “greater than” configurations across front-end pricing and back-end matrix extraction.
Changes:
- Updated
ppom_update_get_prices()to parse matrix keys as single values or ranges and apply the correct tier for < first, within ranges, and > last. - Adjusted product limit derivation to handle non-range (single-value) entries for min/max quantity inference.
- Updated server-side matrix extraction to support single-value “boundary” entries.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
| js/price/ppom-price.js | Updates client-side tier selection logic for single-value boundaries and ranges (adds helper). |
| inc/validation.php | Adjusts min/max quantity inference from matrix options and updates quantity input args behavior. |
| inc/functions.php | Updates server-side selection logic to interpret single-value matrix entries as boundaries. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| $matrix_index = 0; | ||
| $quantity = intval( $quantity ); | ||
| foreach ( $ranges as $range => $data ) { | ||
|
|
||
| $range_array = explode( '-', $range ); | ||
| $range_start = $range_array[0]; | ||
| $range_end = $range_array[1]; | ||
| $range_end = isset( $range_array[1] ) ? $range_array[1] : -1; | ||
|
|
||
| $quantity = intval( $quantity ); | ||
| if ( $quantity >= $range_start && $quantity <= $range_end ) { | ||
| if ( 0 === $matrix_index && $quantity < intval( $range_start ) && -1 === $range_end ) { | ||
| $matrix = $data; | ||
| break; | ||
| } elseif ( 0 !== $matrix_index && $quantity >= $range_start && ( $quantity <= $range_end || $range_end == -1 ) ) { | ||
| $matrix = $data; | ||
| break; | ||
| } | ||
| $matrix_index++; | ||
| } |
There was a problem hiding this comment.
This change introduces new selection semantics for single-value matrix keys ("less than" and "greater than") but there are no PHPUnit tests covering ppom_extract_matrix_by_quantity. Adding unit tests for boundary cases (below first, within a range, above last, and misordered/mixed single+range entries) would help prevent regressions.
| // Sort properly by "from". | ||
| ranges.sort((a, b) => a.from - b.from); | ||
| let product_qty = ppom_get_order_quantity(); |
There was a problem hiding this comment.
The client-side logic now sorts matrix ranges by the numeric start value, but the server-side selection (ppom_extract_matrix_by_quantity) iterates ranges in their saved order without sorting. If matrix options are saved out-of-order, this can lead to the front-end showing one tier while back-end pricing/cart validation applies a different tier. Consider applying the same sorting on the PHP side (and/or ensuring ranges are normalized when saved) to keep client/server behavior consistent.
|
@girishpanchal30, when you have some time, can you check this failed test https://github.com/Codeinwp/woocommerce-product-addon/actions/runs/24407920997/job/71296264046?pr=560 in case there is a possible regression or not (like an outdated test). And, also to merge it with the new changes from |
Summary
Improved the price matrix handling by correctly supporting “less than”, range, and “greater than” conditions.
Screenshot
Test instructions
Check before Pull Request is ready:
Closes https://github.com/Codeinwp/ppom-pro/issues/338