Search in sources :

Example 96 with Money

use of org.broadleafcommerce.common.money.Money in project BroadleafCommerce by BroadleafCommerce.

the class PromotableOrderImpl method setOrderSubTotalToPriceWithoutAdjustments.

@Override
public void setOrderSubTotalToPriceWithoutAdjustments() {
    Money calculatedSubTotal = calculateSubtotalWithoutAdjustments();
    order.setSubTotal(calculatedSubTotal);
}
Also used : Money(org.broadleafcommerce.common.money.Money)

Example 97 with Money

use of org.broadleafcommerce.common.money.Money in project BroadleafCommerce by BroadleafCommerce.

the class OrderItemPriceComparator method compare.

public int compare(PromotableOrderItem c1, PromotableOrderItem c2) {
    Money price = c1.getPriceBeforeAdjustments(applyToSalePrice);
    Money price2 = c2.getPriceBeforeAdjustments(applyToSalePrice);
    // highest amount first
    return price2.compareTo(price);
}
Also used : Money(org.broadleafcommerce.common.money.Money)

Example 98 with Money

use of org.broadleafcommerce.common.money.Money in project BroadleafCommerce by BroadleafCommerce.

the class SkuPricingConsiderationContext method getDynamicSkuPrices.

public static DynamicSkuPrices getDynamicSkuPrices(Sku sku) {
    DynamicSkuPrices prices = null;
    if (SkuPricingConsiderationContext.hasDynamicPricing()) {
        if (!getThreadCache().containsKey(sku.getId())) {
            // We have dynamic pricing, so we will pull the retail price from there
            if (!SkuPricingConsiderationContext.isPricingConsiderationActive()) {
                SkuPriceWrapper wrapper = new SkuPriceWrapper(sku);
                SkuPricingConsiderationContext.startPricingConsideration();
                try {
                    prices = SkuPricingConsiderationContext.getSkuPricingService().getSkuPrices(wrapper, SkuPricingConsiderationContext.getSkuPricingConsiderationContext());
                } finally {
                    SkuPricingConsiderationContext.endPricingConsideration();
                }
            } else {
                try {
                    prices = new DynamicSkuPrices();
                    Field retail = getSingleField(sku.getClass(), "retailPrice");
                    Object retailVal = retail.get(sku);
                    Money retailPrice = retailVal == null ? null : new Money((BigDecimal) retailVal);
                    Field sale = getSingleField(sku.getClass(), "salePrice");
                    Object saleVal = sale.get(sku);
                    Money salePrice = saleVal == null ? null : new Money((BigDecimal) saleVal);
                    prices.setRetailPrice(retailPrice);
                    prices.setSalePrice(salePrice);
                } catch (IllegalAccessException e) {
                    throw ExceptionHelper.refineException(e);
                }
            }
            getThreadCache().put(sku.getId(), prices);
        } else {
            prices = getThreadCache().get(sku.getId());
        }
    }
    return prices;
}
Also used : Field(java.lang.reflect.Field) Money(org.broadleafcommerce.common.money.Money) SkuPriceWrapper(org.broadleafcommerce.core.catalog.domain.pricing.SkuPriceWrapper) BigDecimal(java.math.BigDecimal)

Example 99 with Money

use of org.broadleafcommerce.common.money.Money in project BroadleafCommerce by BroadleafCommerce.

the class OrderPaymentConfirmationStrategyImpl method constructPendingTransaction.

protected PaymentResponseDTO constructPendingTransaction(PaymentType paymentType, PaymentGatewayType gatewayType, PaymentRequestDTO confirmationRequest) {
    PaymentResponseDTO responseDTO = new PaymentResponseDTO(paymentType, gatewayType);
    responseDTO.amount(new Money(confirmationRequest.getTransactionTotal())).rawResponse(this.getClass().getName() + ": converting UNCONFIRMED transaction into a PENDING payment").successful(true).paymentTransactionType(PaymentTransactionType.PENDING);
    for (String key : confirmationRequest.getAdditionalFields().keySet()) {
        responseDTO.responseMap(key, confirmationRequest.getAdditionalFields().get(key).toString());
    }
    return responseDTO;
}
Also used : Money(org.broadleafcommerce.common.money.Money) PaymentResponseDTO(org.broadleafcommerce.common.payment.dto.PaymentResponseDTO)

Example 100 with Money

use of org.broadleafcommerce.common.money.Money in project BroadleafCommerce by BroadleafCommerce.

the class SkuImpl method getMargin.

@Override
public Money getMargin() {
    Money margin = null;
    Money price = getPrice();
    Money purchaseCost = getCost();
    if (price == null && hasDefaultSku()) {
        price = lookupDefaultSku().getPrice();
    }
    if (purchaseCost == null && hasDefaultSku()) {
        purchaseCost = lookupDefaultSku().getCost();
    }
    if (price != null && !price.getAmount().equals(BigDecimal.ZERO)) {
        if (purchaseCost != null) {
            margin = price.subtract(purchaseCost).divide(price.getAmount());
        }
    } else {
        margin = Money.ZERO;
    }
    return margin;
}
Also used : Money(org.broadleafcommerce.common.money.Money) ClonePolicyCollectionOverride(org.broadleafcommerce.common.extensibility.jpa.clone.ClonePolicyCollectionOverride)

Aggregations

Money (org.broadleafcommerce.common.money.Money)158 Order (org.broadleafcommerce.core.order.domain.Order)43 BigDecimal (java.math.BigDecimal)38 Offer (org.broadleafcommerce.core.offer.domain.Offer)29 Test (org.testng.annotations.Test)29 Transactional (org.springframework.transaction.annotation.Transactional)24 FulfillmentGroup (org.broadleafcommerce.core.order.domain.FulfillmentGroup)22 ArrayList (java.util.ArrayList)21 CommonSetupBaseTest (org.broadleafcommerce.test.CommonSetupBaseTest)21 FulfillmentGroupItem (org.broadleafcommerce.core.order.domain.FulfillmentGroupItem)19 CustomerOffer (org.broadleafcommerce.core.offer.domain.CustomerOffer)18 Sku (org.broadleafcommerce.core.catalog.domain.Sku)16 DiscreteOrderItemImpl (org.broadleafcommerce.core.order.domain.DiscreteOrderItemImpl)14 OrderItem (org.broadleafcommerce.core.order.domain.OrderItem)13 HashMap (java.util.HashMap)12 SkuImpl (org.broadleafcommerce.core.catalog.domain.SkuImpl)12 FixedPriceFulfillmentOption (org.broadleafcommerce.core.order.fulfillment.domain.FixedPriceFulfillmentOption)12 DiscreteOrderItem (org.broadleafcommerce.core.order.domain.DiscreteOrderItem)11 FulfillmentGroupImpl (org.broadleafcommerce.core.order.domain.FulfillmentGroupImpl)11 FixedPriceFulfillmentOptionImpl (org.broadleafcommerce.core.order.fulfillment.domain.FixedPriceFulfillmentOptionImpl)10