Skip to content

Fixed quantity range in pricing matrix#560

Open
girishpanchal30 wants to merge 4 commits intodevelopmentfrom
bugfix/pro/338
Open

Fixed quantity range in pricing matrix#560
girishpanchal30 wants to merge 4 commits intodevelopmentfrom
bugfix/pro/338

Conversation

@girishpanchal30
Copy link
Copy Markdown
Contributor

Summary

Improved the price matrix handling by correctly supporting “less than”, range, and “greater than” conditions.

Screenshot

image

Test instructions

  1. Add a single quantity value to represent the “less than” condition (e.g., 12) and provide an appropriate label (e.g., “Less than 12”).
  2. Add range-based quantities for intermediate values using a hyphen (e.g., 12-23, 24-35) and assign suitable labels for each range.
  3. Add a final single quantity value to represent the “greater than” condition (e.g., 35) and provide a label such as “More than 35”
  • Test with different product quantities to ensure:
  • Quantities below the first value match the “less than” condition.
  • Quantities within defined ranges match the correct range.
  • Quantities above the last value match the “more than” condition.

Check before Pull Request is ready:

Closes https://github.com/Codeinwp/ppom-pro/issues/338

@girishpanchal30 girishpanchal30 requested a review from Copilot April 6, 2026 09:33
@girishpanchal30 girishpanchal30 added the pr-checklist-skip Allow this Pull Request to skip checklist. label Apr 6, 2026
@pirate-bot pirate-bot added the pr-checklist-complete The Pull Request checklist is complete. (automatic label) label Apr 6, 2026
@pirate-bot
Copy link
Copy Markdown
Contributor

pirate-bot commented Apr 6, 2026

Plugin build for 6cfc70a is ready 🛎️!

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

Comment thread inc/validation.php Outdated
Comment thread inc/validation.php Outdated
Comment thread inc/functions.php Outdated
Comment thread inc/functions.php Outdated
Comment on lines 1538 to 1554
$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++;
}
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment thread js/price/ppom-price.js Outdated
Comment thread js/price/ppom-price.js Outdated
Comment on lines +820 to +822
// Sort properly by "from".
ranges.sort((a, b) => a.from - b.from);
let product_qty = ppom_get_order_quantity();
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment thread inc/validation.php Outdated
@Soare-Robert-Daniel
Copy link
Copy Markdown
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-checklist-complete The Pull Request checklist is complete. (automatic label) pr-checklist-skip Allow this Pull Request to skip checklist.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants