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
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:
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.
Context
PR #772 introduced
Receipt_Data_BuilderandPreview_Receipt_Builderwhich both build store-info arrays from a POS store object. The fix commits (5551e41,02c7891) added defensive store resolution and aget_store_value()helper — but these were copy-pasted into both classes.Duplicated code
Both
Receipt_Data_BuilderandPreview_Receipt_Buildernow contain identical private methods:get_store_value($pos_store, $getter, $fallback)— safe getter with method_exists checkformat_country_state($country, $state)— converts country/state codes to display namesThe store-info array construction (~60 lines) is also nearly identical: reading all store getters, building the
$storearray, formatting opening hours, resolving logo, etc.Suggested approach
Extract a shared
Store_Info_Resolverclass or trait that:get_store_value()andformat_country_state()onceBoth builders would delegate to it instead of duplicating the logic.
Additional notes from PR #772 review
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()inReceipt.phpreads$_GET['store_id']directly, coupling a service method to the HTTP request. Themodeparameter should be the single source of truth for preview behavior.Receipt_Snapshot_StoreandReceipt_I18n_Labelsare now orphaned after fix: use POS store data for receipts instead of hardcoded WooCommerce options #772 removed their last consumer.receipt.phpdiscount display is inconsistent.