use of org.broadleafcommerce.common.currency.domain.BroadleafCurrency in project BroadleafCommerce by BroadleafCommerce.
the class OfferCustomPersistenceHandler method fetch.
@Override
public DynamicResultSet fetch(PersistencePackage persistencePackage, CriteriaTransferObject cto, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
addIsActiveFiltering(cto);
DynamicResultSet resultSet = helper.getCompatibleModule(OperationType.BASIC).fetch(persistencePackage, cto);
String customCriteria = "";
if (persistencePackage.getCustomCriteria().length > 0) {
customCriteria = persistencePackage.getCustomCriteria()[0];
}
for (Entity entity : resultSet.getRecords()) {
Property discountType = entity.findProperty("discountType");
Property discountValue = entity.findProperty("value");
String value = discountValue.getValue();
if (discountType == null || StringUtils.isBlank(discountType.getValue())) {
discountValue.setValue("");
} else if (discountType.getValue().equals("PERCENT_OFF")) {
value = !value.contains(".") ? value : value.replaceAll("0*$", "").replaceAll("\\.$", "");
discountValue.setValue(value + "%");
} else if (discountType.getValue().equals("AMOUNT_OFF")) {
Locale locale = BroadleafRequestContext.getBroadleafRequestContext().getLocale();
BroadleafCurrency currency = BroadleafRequestContext.getBroadleafRequestContext().getBroadleafCurrency();
NumberFormat nf = BroadleafCurrencyUtils.getNumberFormatFromCache(locale.getJavaLocale(), currency.getJavaCurrency());
discountValue.setValue(nf.format(new BigDecimal(value)));
}
Property timeRule = entity.findProperty("offerMatchRules---TIME");
entity.addProperty(buildAdvancedVisibilityOptionsProperty(timeRule));
Property offerItemQualifierRuleType = entity.findProperty(OFFER_ITEM_QUALIFIER_RULE_TYPE);
entity.addProperty(buildQualifiersCanBeQualifiersProperty(offerItemQualifierRuleType));
entity.addProperty(buildQualifiersCanBeTargetsProperty(offerItemQualifierRuleType));
Property offerItemTargetRuleType = entity.findProperty(OFFER_ITEM_TARGET_RULE_TYPE);
entity.addProperty(buildStackableProperty(offerItemTargetRuleType));
if (!"listGridView".equals(customCriteria)) {
String setValue = discountValue.getValue();
setValue = setValue.replaceAll("\\%", "").replaceAll("\\$", "");
discountValue.setValue(setValue);
}
addIsActiveStatus(helper, entity);
}
return resultSet;
}
use of org.broadleafcommerce.common.currency.domain.BroadleafCurrency in project BroadleafCommerce by BroadleafCommerce.
the class SkuPricingPersistenceProvider method getCurrency.
@Override
protected Currency getCurrency(ExtractValueRequest extractValueRequest, Property property) {
BroadleafCurrency bc = null;
if (extractValueRequest.getEntity() instanceof Product && isDefaultSkuProperty(extractValueRequest, property)) {
Product p = (Product) extractValueRequest.getEntity();
bc = p.getDefaultSku().getCurrency();
} else if (extractValueRequest.getEntity() instanceof Sku) {
Sku s = (Sku) extractValueRequest.getEntity();
bc = s.getCurrency();
}
if (bc == null) {
BroadleafRequestContext brc = BroadleafRequestContext.getBroadleafRequestContext();
return brc.getJavaCurrency();
} else {
return Currency.getInstance(bc.getCurrencyCode());
}
}
use of org.broadleafcommerce.common.currency.domain.BroadleafCurrency in project BroadleafCommerce by BroadleafCommerce.
the class ValidateAddRequestActivity method hasSameCurrency.
protected boolean hasSameCurrency(OrderItemRequestDTO orderItemRequestDTO, CartOperationRequest request, Sku sku) {
if (orderItemRequestDTO instanceof NonDiscreteOrderItemRequestDTO || sku == null || sku.getCurrency() == null) {
return true;
} else {
BroadleafCurrency orderCurrency = request.getOrder().getCurrency();
BroadleafCurrency skuCurrency = sku.getCurrency();
return orderCurrency.equals(skuCurrency);
}
}
use of org.broadleafcommerce.common.currency.domain.BroadleafCurrency in project BroadleafCommerce by BroadleafCommerce.
the class BroadleafCurrencyUtils method getUnitAmount.
/**
* Returns the unit amount (e.g. .01 for US and all other 2 decimal currencies)
*
* @param blCurrency
* @return
*/
public static Money getUnitAmount(BroadleafCurrency blCurrency) {
Currency currency = getCurrency(blCurrency);
BigDecimal divisor = new BigDecimal(Math.pow(10, currency.getDefaultFractionDigits()));
BigDecimal unitAmount = new BigDecimal("1").divide(divisor);
return new Money(unitAmount, currency);
}
use of org.broadleafcommerce.common.currency.domain.BroadleafCurrency in project BroadleafCommerce by BroadleafCommerce.
the class UpdateCartServiceImpl method copyCartToCurrentContext.
@Override
public UpdateCartResponse copyCartToCurrentContext(Order currentCart) {
if (currentCart.getOrderItems() == null) {
return null;
}
BroadleafCurrency currency = findActiveCurrency();
if (currency == null) {
return null;
}
// Reprice order logic
List<OrderItemRequestDTO> itemsToReprice = new ArrayList<>();
List<OrderItem> itemsToRemove = new ArrayList<>();
List<OrderItem> itemsToReset = new ArrayList<>();
boolean repriceOrder = true;
for (OrderItem orderItem : currentCart.getOrderItems()) {
// Lookup price in price list, if null, then add to itemsToRemove
if (orderItem instanceof DiscreteOrderItem) {
DiscreteOrderItem doi = (DiscreteOrderItem) orderItem;
if (checkAvailabilityInLocale(doi, currency)) {
OrderItemRequestDTO itemRequest = new OrderItemRequestDTO();
itemRequest.setProductId(doi.getProduct().getId());
itemRequest.setQuantity(doi.getQuantity());
itemsToReprice.add(itemRequest);
itemsToReset.add(orderItem);
} else {
itemsToRemove.add(orderItem);
}
} else if (orderItem instanceof BundleOrderItem) {
BundleOrderItem boi = (BundleOrderItem) orderItem;
for (DiscreteOrderItem doi : boi.getDiscreteOrderItems()) {
if (checkAvailabilityInLocale(doi, currency)) {
OrderItemRequestDTO itemRequest = new OrderItemRequestDTO();
itemRequest.setProductId(doi.getProduct().getId());
itemRequest.setQuantity(doi.getQuantity());
itemsToReprice.add(itemRequest);
itemsToReset.add(orderItem);
} else {
itemsToRemove.add(orderItem);
}
}
}
}
for (OrderItem orderItem : itemsToReset) {
try {
currentCart = orderService.removeItem(currentCart.getId(), orderItem.getId(), false);
} catch (RemoveFromCartException e) {
LOG.error("Could not remove from cart.", e);
}
}
for (OrderItemRequestDTO itemRequest : itemsToReprice) {
try {
currentCart = orderService.addItem(currentCart.getId(), itemRequest, false);
} catch (AddToCartException e) {
LOG.error("Could not add to cart.", e);
}
}
// Reprice and save the cart
try {
currentCart = orderService.save(currentCart, repriceOrder);
} catch (PricingException e) {
LOG.error("Could not save cart.", e);
}
setSavedCurrency(currency);
UpdateCartResponse updateCartResponse = new UpdateCartResponse();
updateCartResponse.setRemovedItems(itemsToRemove);
updateCartResponse.setOrder(currentCart);
return updateCartResponse;
}
Aggregations