Skip to main content

Price-range filter silently breaks ALL shop filtering when max price has a thousand separator (toCent() returns 0)

Hi team β€” I hit a reproducible bug where using any shop filter empties the entire product grid, and I traced it to the price-range filter's value parsing. Sharing full detail since the root cause is precise.

Environment

FluentCart 1.6.1, WordPress, currency GBP. Shop built with the FluentCart Products block (Gutenberg). Catalog max price is Β£2,705.08.

Steps to reproduce

  1. Have a store where the highest product price is β‰₯ 1000 (so it formats with a thousands separator, e.g. 2,705.08), in a locale that uses a comma as the thousands separator.
  2. On the shop page, enable the Filter sidebar with Product Categories + Price.
  3. Tick any single category (don't touch the price slider at all).

Expected: the grid shows products in that category.
Actual: the grid goes completely empty ("No results"), for every category, brand, or any filter selection. The unfiltered page shows products fine β€” it only breaks the moment a filter is applied.

Root cause

The filter request always includes the price range, even when the user only selected a category. Observed request:

GET /wp-json/fluent-cart/v2/public/product-views
   ?filters[product-categories]=29
   &filters[price_range_from]=13.53
   &filters[price_range_to]=2,705.08   ← thousands separator

Server-side, ShopResource applies the price constraint via min_price BETWEEN [Helper::toCent($from), Helper::toCent($to)]. But Helper::toCent() (app/Helpers/Helper.php) bails on any non-numeric string:

php

public static function toCent($amount): int
{
    if (!is_numeric($amount)) {
        return 0;                       // "2,705.08" is NOT is_numeric β†’ 0
    }
    $amount = floatval($amount) * 100;
    return (int) round($amount);
}

So toCent('2,705.08') returns 0. The price filter becomes min_price BETWEEN 1353 AND 0 β€” an impossible range β€” and every product is excluded. Confirmed directly:

  • toCent('2,705.08') β†’ 0 vs toCent('2705.08') β†’ 270508
  • Same category query: comma value β†’ 0 products, plain value β†’ 7 products

The value carries a comma because the slider's default max is the formatted price string, so the front-end submits 2,705.08 verbatim.

Suggested fixes (any one resolves it)

  1. Front-end: submit the raw, unformatted numeric value for price_range_from / price_range_to (no thousands separators).
  2. toCent(): strip locale thousands separators before is_numeric/floatval (respecting the store's decimal/thousands settings).
  3. Server-side guard: if the parsed max is 0 or less than the min, ignore the price constraint rather than returning an empty set β€” a filter should never silently zero out results.

Impact is broad: this hits any store with a product priced β‰₯ 1000 in a comma-grouping locale, and it disables the whole filter feature, not just price. Happy to provide more detail or test a patch. Thanks!

Shahjahan Jewel

Tagging Sarkar RiponΒ