Skip to content

Add has_records flag to top-level list APIs - #376

Open
ashraful1971 wants to merge 2 commits into
devfrom
chore/has-records
Open

ashraful1971 wants to merge 2 commits into
devfrom
chore/has-records

Conversation

@ashraful1971

Copy link
Copy Markdown
Collaborator

Summary

List pages guessed their first-use empty state from total === 0 and the active filters. The server now says if the table holds any record, whatever the search or filters.

  • New ListPaginator (extends the framework Paginator) adds has_records to the paginated payload. It takes a bool or a fresh unfiltered query. A query runs exists() only when the page total is 0, so a page with rows costs no extra query.
  • Returned by products, orders, variants (inventory), collections, categories, tags, brands, customers and coupons. No controller or resource change.
  • Products ignore trashed rows. Orders scope the check to the customer when one is given (storefront account list).
  • The nine list pages read has_records and the @todo guesses are gone. Only an explicit false shows the first-use state, so loading and failed requests keep the table.
  • Fixes dashboard net sales taking shipping tax off twice. base_tax_total and base_shipping_total both hold the shipping tax, so net sales now subtracts the shipping total without its tax.
  • Adds the list-record-presence spec, archives the list-api-has-record change, and updates docs/data-table.md, docs/home.md and the merchant-home-dashboard spec.

Test plan

  • composer test:unit (415 pass), including the new ListPaginatorTest
  • Integration tests for all nine endpoints: empty table gives false, a no-match search keeps true, products with only trashed rows give false
  • DashboardApiTest (13 pass), including a new shipping tax case
  • npm run typecheck && npm test in resources/app (1552 pass), including the new list-page empty-state test
  • Look at the nine empty states in the browser
  • Known: StorePresetsTest "Presets leave order and invoice numbering unchanged" fails in a full integration run with and without this change, and passes alone.

List pages guessed their first-use empty state from `total === 0` and the
active filters. The server now reports whether the table holds any record,
independent of search and filters.

- Add ListPaginator, a Paginator subclass that adds `has_records` to the
  paginated payload. It accepts a bool or a fresh unfiltered query, and runs
  `exists()` only when the page total is 0.
- Return it from products, orders, variants, collections, categories, tags,
  brands, customers and coupons. Products ignore trashed rows; orders scope
  the check to the customer when one is given.
- Read `has_records` on the nine list pages and remove the @todo guesses.
- Cover it with a unit test, integration tests per endpoint, and a
  list-page empty-state test.
- Update docs/data-table.md, add the list-record-presence spec and archive
  the list-api-has-record change.
An order's tax total already holds its shipping tax, and its shipping total
is gross of that tax. Net sales subtracted both in full, so the shipping tax
was removed twice. Subtract the shipping total without its tax instead.

- Sum base_shipping_tax_amount in the dashboard totals query.
- Add an integration test for an order with shipping tax.
- Update the net sales formula in docs/home.md and the
  merchant-home-dashboard spec.
@ashraful1971
ashraful1971 requested a review from ahamed October 16, 2026 10:35
@ashraful1971 ashraful1971 self-assigned this Oct 16, 2026
Comment on lines +125 to +127
$has_records = Order::query()->when(is_numeric($dto->customer_id), function (QueryBuilder $query) use ($dto) {
return $query->where('customer_id', $dto->customer_id);
});

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why do we need this?

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.

2 participants