protected String getText(Arguments arguments, Element element, String attributeName) {
    Money price;

    try {
      price =
          (Money)
              StandardExpressionProcessor.processExpression(
                  arguments, element.getAttributeValue(attributeName));
    } catch (ClassCastException e) {
      Number value =
          (Number)
              StandardExpressionProcessor.processExpression(
                  arguments, element.getAttributeValue(attributeName));
      price = new Money(value.doubleValue());
    }

    if (price == null) {
      return "Not Available";
    }
    BroadleafRequestContext brc = BroadleafRequestContext.getBroadleafRequestContext();
    if (brc.getJavaLocale() != null) {
      NumberFormat format = NumberFormat.getCurrencyInstance(brc.getJavaLocale());
      if (price.getCurrency().getCurrencyCode().equals("AUD")) {
        return "☯ " + price.getAmount().toString();
      }
      format.setCurrency(price.getCurrency());
      return format.format(price.getAmount());
    } else {

      return "$ " + price.getAmount().toString();
    }
  }
예제 #2
0
 @Override
 protected String getText(
     final Arguments arguments, final Element element, final String attributeName) {
   final String attributeValue = element.getAttributeValue(attributeName);
   Money price = null;
   Object result = StandardExpressionProcessor.processExpression(arguments, attributeValue);
   if (result instanceof Money) {
     price = (Money) result;
   } else if (result instanceof BigDecimal) {
     price = new Money((BigDecimal) result);
   } else if (result == null) {
     price = Money.ZERO;
   } else {
     throw new IllegalArgumentException("Input is not of type Money or BigDecimal");
   }
   HttpServletRequest curRequest =
       ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();
   Locale curLocale =
       (Locale)
           WebUtils.getSessionAttribute(
               curRequest, SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME);
   curLocale = (curLocale == null) ? Locale.US : curLocale;
   NumberFormat format = NumberFormat.getCurrencyInstance(curLocale);
   format.setCurrency(price.getCurrency());
   return format.format(price.getAmount());
 }
  @Override
  protected ProcessorResult processAttribute(
      Arguments arguments, Element element, String attributeName) {

    ProductOptionValue productOptionValue =
        (ProductOptionValue)
            StandardExpressionProcessor.processExpression(
                arguments, element.getAttributeValue(attributeName));
    ProductOptionValueDTO dto = new ProductOptionValueDTO();
    dto.setOptionId(productOptionValue.getProductOption().getId());
    dto.setValueId(productOptionValue.getId());
    dto.setValueName(productOptionValue.getAttributeValue());
    if (productOptionValue.getPriceAdjustment() != null) {
      dto.setPriceAdjustment(productOptionValue.getPriceAdjustment().getAmount());
    }
    try {
      ObjectMapper mapper = new ObjectMapper();
      Writer strWriter = new StringWriter();
      mapper.writeValue(strWriter, dto);
      element.setAttribute("data-product-option-value", strWriter.toString());
      return ProcessorResult.OK;
    } catch (Exception ex) {
      LOG.error("There was a problem writing the product option value to JSON", ex);
    }

    return null;
  }