Skip to content

Return early from sortAndFilterCart() when no items are printable - #4713

Merged
objecttothis merged 4 commits into
opensourcepos:masterfrom
minutechreview:fix/4685-empty-filtered-cart
Oct 8, 2026
Merged

objecttothis merged 4 commits into
opensourcepos:masterfrom
minutechreview:fix/4685-empty-filtered-cart

Conversation

@minutechreview

@minutechreview minutechreview commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #4685

When a cart has lines but none are printable, filtering leaves an empty result and the sorting branches can call array_multisort() on keys that were never set. sortAndFilterCart() now returns the empty filtered cart immediately after filtering, before any sorting happens.

As requested in objecttothis’s review, the helper and its $filteredCart local use camelCase naming, and all four internal call sites in the Sales controller are updated. A repository-wide search found no route, AJAX, or frontend references to the helper name. Filtering and sorting behavior is preserved.

Summary by CodeRabbit

  • Bug Fixes
    • Prevented sorting errors when filtering leaves no printable cart items.
    • Cart filtering continues to preserve printable items, clear discounts on zero-price items, and apply the configured line sequence. Sales, returns, quotes, work orders, and invoices continue through their existing completion flows after cart filtering.

@coderabbitai

coderabbitai Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5a16f916-6252-4b24-b93b-305260974567
📥 Commits

Reviewing files that changed from the base of the PR and between 81d3bf7 and a73bde6.

📒 Files selected for processing (2)
  • app/Controllers/Sales.php
  • app/Libraries/Sale_lib.php
 _________________________________
< Ripgrepping your code for bugs. >
 ---------------------------------
  \
   \   \
        \ /\
        ( )
      .( o ).

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f3721645-785d-4ccb-968e-937f2e2958a5
📥 Commits

Reviewing files that changed from the base of the PR and between b219fe5 and 81d3bf7.

📒 Files selected for processing (2)
  • app/Controllers/Sales.php
  • app/Libraries/Sale_lib.php

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

sort_and_filter_cart() is now sortAndFilterCart(). It returns the filtered cart when no printable items remain. All four sales completion branches call the renamed method.

Changes

Empty cart handling

Layer / File(s) Summary
Return when no printable items remain
app/Libraries/Sale_lib.php, app/Controllers/Sales.php
The method returns the empty filtered cart before sorting. Invoice, work-order, quote, and sale or return completion branches call the renamed method. The filtering and sorting criteria remain unchanged.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: jekkos

Merge Risk: ⚪ Minimal · up to 81d3b

The completion flows use the renamed method, and an empty printable cart returns safely before sorting. No actionable merge risk is evident.

Security Architecture Review

Security architecture risk: 🔵 Low · up to b0c01

The change affects an unusual invoice-printing case after a sale is saved. No new access path or change to the saved sale is apparent, but the exact invoice display and prior failure behavior have not been verified.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The identified effect is confined to the saved sale’s print-cart result and subsequent invoice and session path. The supplied evidence does not establish a broader caller or tenant impact.

Trust Boundaries and Controls

  • inferred — The inspected caller invokes the public library method internally after saving the sale; the changed lines do not introduce a route, identity transition, or control bypass. HTTP route exposure was not independently verified.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The PR also renames the public method from sort_and_filter_cart to sortAndFilterCart and updates four controller calls. Issue #4685 requires the empty-result guard and does not require a public AP… Keep the existing sort_and_filter_cart method name and its existing call sites, or provide a backward-compatible alias. Limit the change to the empty filtered-cart guard unless a separate requirement justifies the API rename.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Issue #4685 requires an early return when filtering produces no printable lines. Sale_lib::sortAndFilterCart() checks empty($filteredCart) after the filter loop and returns before every `array_mul…
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the primary behavior change: returning early when filtering leaves no printable items. It uses the updated method name and matches the pull request objectives.
Full details: Out of Scope Changes check

Explanation

The PR also renames the public method from sort_and_filter_cart to sortAndFilterCart and updates four controller calls. Issue #4685 requires the empty-result guard and does not require a public API rename. This change exceeds the stated fix scope.

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Comment thread app/Libraries/Sale_lib.php Resolved
@minutechreview minutechreview changed the title Return early from sort_and_filter_cart() when no items are printable Return early from sortAndFilterCart() when no items are printable Oct 8, 2026
@objecttothis
objecttothis merged commit 7ea3f21 into opensourcepos:master Oct 8, 2026
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sale_lib::sort_and_filter_cart() crashes when cart has no printable items

4 participants