[MSHOP-31] Prices are not properly formatted Created: 12/Sep/12  Updated: 22/Feb/13  Resolved: 19/Feb/13

Status: Closed
Project: Magnolia Shop (closed)
Component/s: None
Affects Version/s: None
Fix Version/s: 1.1.1

Type: Bug Priority: Neutral
Reporter: Will Scheidegger Assignee: Teresa Miyar
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: 1h
Time Spent: Not Specified
Original Estimate: 1h

Issue Links:
relation
is related to MSHOP-46 Migrate code to the latest Magnolia API Closed
Template:
Patch included:
Yes
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Bug DoR:
[ ]* Steps to reproduce, expected, and actual results filled
[ ]* Affected version filled
Date of First Response:

 Description   

The TemplateProductPriceBean formats the prices according to the pattern stored with the currency in the shop configuration, but it does not respect the current local stored in the aggregation state (instead uses the default locale). This "patch" would fix the problem:

    public String getPrice() {
        try {
            if (price >= 0 && StringUtils.isNotBlank(this.getFormatting())) {
                NumberFormat formatter = NumberFormat.getNumberInstance(MgnlContext.getAggregationState().getLocale());
                DecimalFormat df = (DecimalFormat)formatter;
                df.applyPattern(this.getFormatting());
                return df.format(price);
            }
        } catch (Exception e) {
            log.error("error reading price", e);
        }
        return "" + price;
    }


 Comments   
Comment by Jan Haderka [ 22/Jan/13 ]

Test is missing.

Comment by Jan Haderka [ 22/Jan/13 ]

Also what if you try to call this bean out of context, say when rendering mail or from data importer? There's no aggregation state in such cases and you end up w/ NPE.

Generated at Mon Feb 12 07:08:35 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.