Skip to content

Refactor: extract shared store-info building logic from receipt builders #773

@kilbot

Description

@kilbot

Context

PR #772 introduced Receipt_Data_Builder and Preview_Receipt_Builder which both build store-info arrays from a POS store object. The fix commits (5551e41, 02c7891) added defensive store resolution and a get_store_value() helper — but these were copy-pasted into both classes.

Duplicated code

Both Receipt_Data_Builder and Preview_Receipt_Builder now contain identical private methods:

  • get_store_value($pos_store, $getter, $fallback) — safe getter with method_exists check
  • format_country_state($country, $state) — converts country/state codes to display names

The store-info array construction (~60 lines) is also nearly identical: reading all store getters, building the $store array, formatting opening hours, resolving logo, etc.

Suggested approach

Extract a shared Store_Info_Resolver class or trait that:

  1. Accepts a store object (already resolved)
  2. Builds the canonical store-info array (name, address_lines, phone, email, opening hours, logo, policies, etc.)
  3. Contains get_store_value() and format_country_state() once

Both builders would delegate to it instead of duplicating the logic.

Additional notes from PR #772 review

  • The triple-fallback store resolution in Receipt_Data_Builder::build() (order meta → default store → new Store()) is intentional — receipts should render with empty data rather than fatal. Worth documenting.
  • get_receipt_data() in Receipt.php reads $_GET['store_id'] directly, coupling a service method to the HTTP request. The mode parameter should be the single source of truth for preview behavior.
  • Check if Receipt_Snapshot_Store and Receipt_I18n_Labels are now orphaned after fix: use POS store data for receipts instead of hardcoded WooCommerce options #772 removed their last consumer.
  • Template indentation in receipt.php discount display is inconsistent.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions