use of org.broadleafcommerce.common.money.Money in project BroadleafCommerce by BroadleafCommerce.
the class PromotableCandidateItemOfferImpl method calculateSavingsForOrderItem.
@Override
public Money calculateSavingsForOrderItem(PromotableOrderItem orderItem, int qtyToReceiveSavings) {
Money savings = new Money(promotableOrder.getOrderCurrency());
originalPrice = orderItem.getPriceBeforeAdjustments(getOffer().getApplyDiscountToSalePrice());
BigDecimal offerUnitValue = PromotableOfferUtility.determineOfferUnitValue(offer, this);
savings = PromotableOfferUtility.computeAdjustmentValue(originalPrice, offerUnitValue, this, this);
return savings.multiply(qtyToReceiveSavings);
}
use of org.broadleafcommerce.common.money.Money in project BroadleafCommerce by BroadleafCommerce.
the class PromotableCandidateOrderOfferImpl method calculatePotentialSavings.
protected void calculatePotentialSavings() {
Money amountBeforeAdjustments = promotableOrder.calculateSubtotalWithoutAdjustments();
potentialSavings = BroadleafCurrencyUtils.getMoney(BigDecimal.ZERO, getCurrency());
if (getOffer().getDiscountType().equals(OfferDiscountType.AMOUNT_OFF)) {
potentialSavings = BroadleafCurrencyUtils.getMoney(getOffer().getValue(), getCurrency());
} else if (getOffer().getDiscountType().equals(OfferDiscountType.FIX_PRICE)) {
potentialSavings = amountBeforeAdjustments.subtract(BroadleafCurrencyUtils.getMoney(getOffer().getValue(), getCurrency()));
} else if (getOffer().getDiscountType().equals(OfferDiscountType.PERCENT_OFF)) {
potentialSavings = amountBeforeAdjustments.multiply(getOffer().getValue().divide(new BigDecimal("100")));
}
if (potentialSavings.greaterThan(amountBeforeAdjustments)) {
potentialSavings = amountBeforeAdjustments;
}
}
use of org.broadleafcommerce.common.money.Money in project BroadleafCommerce by BroadleafCommerce.
the class ProductLinkedDataGeneratorImpl method addSkus.
protected void addSkus(final HttpServletRequest request, final Product product, final JSONObject productData, final String url) throws JSONException {
final JSONArray offers = new JSONArray();
final String currency = product.getRetailPrice().getCurrency().getCurrencyCode();
BigDecimal highPrice = BigDecimal.ZERO;
BigDecimal lowPrice = null;
for (final Sku sku : product.getAllSellableSkus()) {
final JSONObject offer = new JSONObject();
offer.put("@type", "Offer");
offer.put("sku", sku.getId());
offer.put("priceCurrency", currency);
offer.put("availability", determineAvailability(sku));
offer.put("url", url);
offer.put("category", product.getCategory().getName());
if (sku.getActiveEndDate() != null) {
offer.put("priceValidUntil", ISO_8601_FORMAT.format(sku.getActiveEndDate()));
}
final Money price = sku.getPriceData().getPrice();
offer.put("price", price.getAmount());
if (price.greaterThan(highPrice)) {
highPrice = price.getAmount();
}
if (lowPrice == null || price.lessThan(lowPrice)) {
lowPrice = price.getAmount();
}
extensionManager.getProxy().addSkuData(request, product, offer);
offers.put(offer);
}
// use aggregateOffer to handle multiple sellable SKUs for a single product
if (offers.length() > 1) {
final JSONObject aggregateOffer = new JSONObject();
aggregateOffer.put("@type", "AggregateOffer");
aggregateOffer.put("highPrice", highPrice.doubleValue());
aggregateOffer.put("lowPrice", lowPrice.doubleValue());
aggregateOffer.put("priceCurrency", currency);
aggregateOffer.put("offerCount", offers.length());
aggregateOffer.put("offers", offers);
extensionManager.getProxy().addAggregateSkuData(request, product, aggregateOffer);
productData.put("offers", aggregateOffer);
} else {
productData.put("offers", offers);
}
}
use of org.broadleafcommerce.common.money.Money in project BroadleafCommerce by BroadleafCommerce.
the class CheckoutFormVariableExpression method shouldShowAllPaymentMethods.
/**
* Toggle the Payment Info Section based on what payments were applied to the order
* (e.g. Third Party Account (i.e. PayPal Express) or Gift Cards/Customer Credit)
*/
public boolean shouldShowAllPaymentMethods() {
Money orderTotalAfterAppliedPayments = CartState.getCart().getTotalAfterAppliedPayments();
boolean totalCoveredByAppliedPayments = (orderTotalAfterAppliedPayments != null && orderTotalAfterAppliedPayments.isZero());
return !cartStateService.cartHasThirdPartyPayment() && !totalCoveredByAppliedPayments;
}
use of org.broadleafcommerce.common.money.Money in project BroadleafCommerce by BroadleafCommerce.
the class OnePageCheckoutProcessor method populateSectionViewStates.
/**
* This method is responsible of populating the variables necessary to draw the checkout page.
* This logic is highly dependent on your layout. If your layout does not follow the same flow
* as the HeatClinic demo, you will need to override with your own custom layout implementation
*
* @param localVars
*/
protected void populateSectionViewStates(Map<String, Object> localVars) {
boolean orderInfoPopulated = hasPopulatedOrderInfo(CartState.getCart());
boolean billingPopulated = hasPopulatedBillingAddress(CartState.getCart());
boolean shippingPopulated = hasPopulatedShippingAddress(CartState.getCart());
localVars.put("orderInfoPopulated", orderInfoPopulated);
localVars.put("billingPopulated", billingPopulated);
localVars.put("shippingPopulated", shippingPopulated);
// Logic to show/hide sections based on state of the order
// show all sections including header unless specifically hidden
// (e.g. hide shipping if no shippable items in order or hide billing section if the order payment doesn't need
// an address i.e. PayPal Express)
boolean showBillingInfoSection = true;
boolean showShippingInfoSection = true;
boolean showAllPaymentMethods = true;
boolean showPaymentMethodSection = true;
int numShippableFulfillmentGroups = calculateNumShippableFulfillmentGroups();
if (numShippableFulfillmentGroups == 0) {
showShippingInfoSection = false;
}
boolean orderContainsThirdPartyPayment = false;
boolean orderContainsUnconfirmedCreditCard = false;
OrderPayment unconfirmedCC = null;
if (CartState.getCart().getPayments() != null) {
for (OrderPayment payment : CartState.getCart().getPayments()) {
if (payment.isActive() && PaymentType.THIRD_PARTY_ACCOUNT.equals(payment.getType())) {
orderContainsThirdPartyPayment = true;
}
if (payment.isActive() && (PaymentType.CREDIT_CARD.equals(payment.getType()) && !PaymentGatewayType.TEMPORARY.equals(payment.getGatewayType()))) {
orderContainsUnconfirmedCreditCard = true;
unconfirmedCC = payment;
}
}
}
// Toggle the Payment Info Section based on what payments were applied to the order
// (e.g. Third Party Account (i.e. PayPal Express) or Gift Cards/Customer Credit)
Money orderTotalAfterAppliedPayments = CartState.getCart().getTotalAfterAppliedPayments();
if (orderContainsThirdPartyPayment || orderContainsUnconfirmedCreditCard) {
showBillingInfoSection = false;
showAllPaymentMethods = false;
} else if (orderTotalAfterAppliedPayments != null && orderTotalAfterAppliedPayments.isZero()) {
// If all the applied payments (e.g. gift cards) cover the entire amount
// we don't need to show all payment method options.
showAllPaymentMethods = false;
}
localVars.put("showBillingInfoSection", showBillingInfoSection);
localVars.put("showAllPaymentMethods", showAllPaymentMethods);
localVars.put("showPaymentMethodSection", showPaymentMethodSection);
localVars.put("orderContainsThirdPartyPayment", orderContainsThirdPartyPayment);
localVars.put("orderContainsUnconfirmedCreditCard", orderContainsUnconfirmedCreditCard);
localVars.put("unconfirmedCC", unconfirmedCC);
// The Sections are all initialized to INACTIVE view
List<CheckoutSectionDTO> drawnSections = new LinkedList<>();
CheckoutSectionDTO orderInfoSection = new CheckoutSectionDTO(CheckoutSectionViewType.ORDER_INFO, orderInfoPopulated);
CheckoutSectionDTO billingInfoSection = new CheckoutSectionDTO(CheckoutSectionViewType.BILLING_INFO, billingPopulated);
CheckoutSectionDTO shippingInfoSection = new CheckoutSectionDTO(CheckoutSectionViewType.SHIPPING_INFO, shippingPopulated);
CheckoutSectionDTO paymentInfoSection = new CheckoutSectionDTO(CheckoutSectionViewType.PAYMENT_INFO, false);
String orderInfoHelpMessage = (String) localVars.get("orderInfoHelpMessage");
String billingInfoHelpMessage = (String) localVars.get("billingInfoHelpMessage");
String shippingInfoHelpMessage = (String) localVars.get("shippingInfoHelpMessage");
// Add the Order Info Section
drawnSections.add(orderInfoSection);
// Add the Billing Section
if (showBillingInfoSection) {
billingInfoSection.setHelpMessage(orderInfoHelpMessage);
drawnSections.add(billingInfoSection);
}
// Add the Shipping Section
if (showShippingInfoSection) {
if (showBillingInfoSection) {
shippingInfoSection.setHelpMessage(billingInfoHelpMessage);
} else {
shippingInfoSection.setHelpMessage(orderInfoHelpMessage);
}
drawnSections.add(shippingInfoSection);
}
// Add the Payment Section
if (showShippingInfoSection) {
paymentInfoSection.setHelpMessage(shippingInfoHelpMessage);
} else if (showBillingInfoSection) {
paymentInfoSection.setHelpMessage(billingInfoHelpMessage);
} else {
paymentInfoSection.setHelpMessage(orderInfoHelpMessage);
}
drawnSections.add(paymentInfoSection);
// Logic to toggle state between form view, saved view, and inactive view
// This is dependent on the layout of your checkout form. Override this if layout is different.
// initialize first view to always be a FORM view
CheckoutSectionDTO firstSection = drawnSections.get(0);
firstSection.setState(CheckoutSectionStateType.FORM);
for (ListIterator<CheckoutSectionDTO> itr = drawnSections.listIterator(); itr.hasNext(); ) {
CheckoutSectionDTO previousSection = null;
if (itr.hasPrevious()) {
previousSection = drawnSections.get(itr.previousIndex());
}
CheckoutSectionDTO section = itr.next();
// if the previous section is populated, set this section to a Form View
if (previousSection != null && previousSection.isPopulated()) {
section.setState(CheckoutSectionStateType.FORM);
}
// If this sections is populated then set this section to the Saved View
if (section.isPopulated()) {
section.setState(CheckoutSectionStateType.SAVED);
}
// {@see DefaultPaymentGatewayCheckoutService where payments are invalidated on an unsuccessful transaction}
if (CheckoutSectionViewType.PAYMENT_INFO.equals(section.getView())) {
if (showBillingInfoSection && !billingPopulated) {
section.setState(CheckoutSectionStateType.INACTIVE);
section.setHelpMessage(billingInfoHelpMessage);
}
}
// Finally, if the edit button is explicitly clicked, set the section to Form View
BroadleafRequestContext blcContext = BroadleafRequestContext.getBroadleafRequestContext();
HttpServletRequest request = blcContext.getRequest();
boolean editOrderInfo = BooleanUtils.toBoolean(request.getParameter("edit-order-info"));
boolean editBillingInfo = BooleanUtils.toBoolean(request.getParameter("edit-billing"));
boolean editShippingInfo = BooleanUtils.toBoolean(request.getParameter("edit-shipping"));
if (CheckoutSectionViewType.ORDER_INFO.equals(section.getView()) && editOrderInfo) {
section.setState(CheckoutSectionStateType.FORM);
} else if (CheckoutSectionViewType.BILLING_INFO.equals(section.getView()) && editBillingInfo) {
section.setState(CheckoutSectionStateType.FORM);
} else if (CheckoutSectionViewType.SHIPPING_INFO.equals(section.getView()) && editShippingInfo) {
section.setState(CheckoutSectionStateType.FORM);
}
}
localVars.put("checkoutSectionDTOs", drawnSections);
}
Aggregations