You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Sale_lib::sort_and_filter_cart() crashes when cart has no printable items #4685
Sale_lib::sort_and_filter_cart() (app/Libraries/Sale_lib.php:190) crashes with a TypeError when the cart, after filtering to items with print_option == PRINT_YES, ends up empty.
TypeError: array_multisort(): Argument #1 ($array) must be an array or a sort flag
app/Libraries/Sale_lib.php:214
Root cause
When line_sequence config is '0' (Entry sequence):
If $filtered_cart is empty (e.g. every cart line has print_option != PRINT_YES), the foreach loop never runs, so $sort['line'] is never set — array_multisort() then receives null instead of an array, causing the crash. The same shape of bug likely applies to the other line_sequence branches in this function ($sort['stock_type'], etc.) for the same empty-$filtered_cart case.
Repro
Complete a sale (invoice or quote mode) where the entire cart has print_option values other than PRINT_YES (0, from app/Config/Constants.php:123). sort_and_filter_cart() is called from postComplete() in app/Controllers/Sales.php before rendering the invoice/quote/work-order view, so this can crash a real checkout.
Suggested fix
Guard the array_multisort() calls (or the whole if/elseif chain) for the case where $filtered_cart is empty, e.g. return early with return $filtered_cart; right after the filtering loop if it's empty.
Activity
Return early from sortAndFilterCart() when no items are printable (#4713