/** {@inheritDoc} */ public boolean isVisible() { return super.isVisible() && productPriceModel.getRegularPrice() != null && !MoneyUtils.isFirstEqualToSecond( Total.ZERO, productPriceModel .getRegularPrice() .setScale(Constants.DEFAULT_SCALE, BigDecimal.ROUND_HALF_UP), 2); }
@Override protected void onBeforeRender() { boolean showSave = false; String savePercent = ""; final String lang = getLocale().getLanguage(); BigDecimal priceToFormat = productPriceModel.getRegularPrice(); String cssModificator = "regular"; if (productPriceModel.getSalePrice() != null && MoneyUtils.isFirstBiggerThanSecond( productPriceModel.getRegularPrice(), productPriceModel.getSalePrice())) { priceToFormat = productPriceModel.getSalePrice(); cssModificator = "sale"; showSave = this.showSavings; if (showSave) { final BigDecimal save = MoneyUtils.getDiscountDisplayValue( productPriceModel.getRegularPrice(), productPriceModel.getSalePrice()); savePercent = save.toString(); } } final String[] formatted = getFormattedPrice(priceToFormat); addOrReplace( new Label(WHOLE_LABEL, formatted[0]) .add(new AttributeModifier(HTML_CLASS, cssModificator + CSS_SUFFIX_WHOLE))); addOrReplace( new Label(DOT_LABEL, ".") .setVisible( StringUtils.isNotBlank(formatted[0]) || StringUtils.isNotBlank(formatted[1])) .add(new AttributeModifier(HTML_CLASS, cssModificator + CSS_SUFFIX_DOT))); addOrReplace( new Label(DECIMAL_LABEL, formatted[1]) .setVisible( StringUtils.isNotBlank(formatted[0]) || StringUtils.isNotBlank(formatted[1])) .add(new AttributeModifier(HTML_CLASS, cssModificator + CSS_SUFFIX_DECIMAL))); final Pair<String, Boolean> symbol = currencySymbolService.getCurrencySymbol(productPriceModel.getCurrency()); addOrReplace( new Label(CURRENCY_LABEL, symbol.getFirst()) .setVisible(showCurrencySymbol && !symbol.getSecond()) .setEscapeModelStrings(false) .add(new AttributeModifier(HTML_CLASS, cssModificator + CSS_SUFFIX_CURRENCY))); addOrReplace( new Label(CURRENCY2_LABEL, symbol.getFirst()) .setVisible(showCurrencySymbol && symbol.getSecond()) .setEscapeModelStrings(false) .add(new AttributeModifier(HTML_CLASS, cssModificator + CSS_SUFFIX_CURRENCY))); final Map<String, Object> tax = new HashMap<String, Object>(); if (this.showTaxAmount) { tax.put( "tax", this.productPriceModel.getPriceTax() != null ? this.productPriceModel.getPriceTax().toPlainString() : Total.ZERO.toPlainString()); } else { tax.put( "tax", this.productPriceModel.getPriceTaxRate() != null ? this.productPriceModel.getPriceTaxRate().stripTrailingZeros().toPlainString() + "%" : "0%"); } tax.put("code", this.productPriceModel.getPriceTaxCode()); final String taxNote = this.showTaxNet ? "taxNoteNet" : "taxNoteGross"; addOrReplace( new Label(TAX_LABEL, WicketUtil.createStringResourceModel(this, taxNote, tax)) .setVisible(this.showTax) .add(new AttributeModifier(HTML_CLASS, cssModificator + CSS_SUFFIX_TAX))); final Label discount = new Label( SAVE_LABEL, WicketUtil.createStringResourceModel( this, "savePercent", Collections.<String, Object>singletonMap("discount", savePercent))); discount.setVisible(showSave); discount.add(new AttributeModifier(HTML_CLASS, "sale-price-save")); if (showSave && StringUtils.isNotBlank(promos)) { final Map<String, ProductPromotionModel> promoModels = productServiceFacade.getPromotionModel(promos); final StringBuilder details = new StringBuilder(); for (final ProductPromotionModel model : promoModels.values()) { final String name = model.getName().getValue(lang); final String desc = model.getDescription().getValue(lang); details.append(name); if (model.getCouponCode() != null) { details.append(" (").append(model.getCouponCode()).append(")"); } if (StringUtils.isNotBlank(desc)) { details.append(": ").append(desc); } details.append("\n"); } discount.add(new AttributeModifier("title", details.toString())); } else { discount.add( new AttributeModifier( "title", WicketUtil.createStringResourceModel(this, "savePercentTitle"))); } addOrReplace(discount); addOrReplace( new Label(PROMO_LABEL, promos) .setVisible(StringUtils.isNotBlank(promos)) .add(new AttributeModifier(HTML_CLASS, "sale-price-save sale-price-save-details"))); super.onBeforeRender(); }