예제 #1
0
 /** {@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);
 }
예제 #2
0
 /**
  * Create price view.
  *
  * @param id component id.
  * @param productPriceModel price model.
  * @param appliedPromos applied promotions
  * @param showCurrencySymbol currency symbol.
  * @param showSavings show user friendly percentage savings
  * @param showTax show tax information
  * @param showTaxNet prices are net (without tax)
  * @param showTaxAmount show amount of tax (rather than percent)
  */
 public PriceView(
     final String id,
     final ProductPriceModel productPriceModel,
     final String appliedPromos,
     final boolean showCurrencySymbol,
     final boolean showSavings,
     final boolean showTax,
     final boolean showTaxNet,
     final boolean showTaxAmount) {
   super(id);
   this.productPriceModel = productPriceModel;
   this.showCurrencySymbol = showCurrencySymbol;
   this.showSavings = showSavings;
   this.promos = appliedPromos;
   this.showTax = showTax && productPriceModel != null && productPriceModel.getPriceTax() != null;
   this.showTaxNet = showTaxNet;
   this.showTaxAmount = showTaxAmount;
 }
예제 #3
0
  @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();
  }