Catalogue 0.1.16: A smart pricing function for apps that sell from the catalogue
Catalogue 0.1.16 changes nothing in the admin. It gives apps that build on the catalogue, such as a shop or a quote tool, a ready function to price smart items, so they no longer need their own copy of the calculation.
For developers:
Catalogue.evaluate_smart_rules/2takes order lines and writes a computed price on each smart item; standard items pass through. It raises a clear error when the rules or the catalogue were not loaded, instead of pricing at zero without a word.Catalogue.list_items_by_uuids/2returns items in the order asked for, skipping deleted and missing ones, for rebuilding a saved order.Catalogue.category_summary_for_catalogue/2returns a catalogue’s categories with item counts in two queries.- The item lookups take a
:preloadoption, andget_item!/2now loads the item’s catalogue by default.
The Smart Catalogues guide now calls the new function instead of showing a long reference implementation. The module’s reported version, stuck at 0.1.13, is correct again.
Full release notes: Catalogue 0.1.16
0.1.16 · 5 May 2026
Added
Catalogue.evaluate_smart_rules/2(issue #20) — public smart-pricing evaluator. Standard entries pass through; smart items get a computed price written to a configurable key (default:smart_price). Single consumer-policy injection point::line_totallambda (defaultbase_price × qty). Lives in newPhoenixKitCatalogue.Catalogue.SmartPricingsubmodule. LoudArgumentErrorraises when:catalogueor:catalogue_rulesis%NotLoaded{}on any entry — better than silent zero-pricing.Catalogue.list_items_by_uuids/2(issue #19) — order-preserving, soft-delete excluded, deduped, nonilplaceholders for missing UUIDs. Designed for order-snapshot rehydration without leakingRepoto consumers.Catalogue.category_summary_for_catalogue/2(issue #21) — returns%{categories:, item_counts:, uncategorized_count:}in two queries. Replaces the three-roundtrip pattern (list_categories_metadata_for_catalogue+item_counts_by_category_for_catalogue+uncategorized_count_for_catalogue) lazy-load consumers had to write.:preloadopt on bulk fetchers (issue #19) —search_items/2,search_items_in_catalogue/3,list_items_for_category/2,list_items_for_catalogue/2,list_uncategorized_items/2,list_items_for_category_paged/2,list_uncategorized_items_paged/2,get_item/2,get_item!/2, andlist_items_by_uuids/2all accept:preload, concatenating onto each function’s defaults. Pass[catalogue_rules: :referenced_catalogue]for smart-pricing.Catalogue.Helpers.merge_preloads/2— single-source preload concat helper (was duplicated incatalogue.exandsearch.ex).
Changed
get_item!/2default preloads expanded to[:catalogue, :category, :manufacturer]. The previous arity-1 form silently omitted:catalogue, which downstream smart-pricing callers had to add via a separateRepo.preload. Pure addition for callers that didn’t access.catalogue.list_uncategorized_items/2default preload widened from[:manufacturer]to[:catalogue, :manufacturer]. Pure addition.guides/smart_catalogues.md§4 rewritten to callevaluate_smart_rules/2directly. The 100-line copy-paste reference impl is gone; one source of truth lives in the package now. §5 (preload pitfall) updated to reference the new:preloadopt.- Test infrastructure switched from
Ecto.Migrator.run([{0, PhoenixKit.Migration}])toPhoenixKit.Migration.ensure_current/2. The old pattern was idempotent at the outer Ecto.Migrator layer (version0cached inschema_migrations) so newly-shipped Vxxx migrations silently never applied. Requiresphoenix_kit ~> 1.7.105for the test suite; runtime constraint unchanged. - Test-helper rescue narrowed to
[DBConnection.ConnectionError, Postgrex.Error]only — code/version bugs (UndefinedFunctionError, etc.) now propagate loudly instead of dark-running the:integrationsuite under a misleading “DB unavailable” banner.
Fixed
evaluate_smart_rules/2%NotLoaded{}raise message for:catalogueno longer points readers at:catalogue_rules(separate raise below already names that one).Catalogue.Helpers.merge_preloads/2docstring now matches the pinning test incatalogue_test.exs— bare-atom + nested-keyword collision merges (parent loads AND nested child loads), not “silently prefers nested” as the doc previously claimed.lib/phoenix_kit_catalogue.exversion/0and theversion/0test were stuck at"0.1.13"since the 0.1.13 release — now match the package version.- Closes #16, #17 — already shipped in 0.1.14 (PR #18) but didn’t auto-close on GitHub.
Catalogue 0.1.16. Install or update: {:phoenix_kit_catalogue, "~> 0.1"}, then mix deps.get && mix phoenix_kit.update. Full history: CHANGELOG.