Search in sources :

Example 21 with Money

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

the class OfferTest method testOfferNotCombinableItemOffers.

@Test(groups = { "testOfferNotCombinableItemOffers" }, dependsOnGroups = { "offerUsedForPricing" })
@Transactional
public void testOfferNotCombinableItemOffers() throws Exception {
    Order order = orderService.createNewCartForCustomer(createCustomer());
    order.addOrderItem(createDiscreteOrderItem(sku1, 100D, null, true, 2, order));
    order.addOrderItem(createDiscreteOrderItem(sku2, 100D, null, true, 2, order));
    order.addOfferCode(createOfferUtility.createOfferCode("20 Percent Off Item Offer", OfferType.ORDER_ITEM, OfferDiscountType.PERCENT_OFF, 20, "discreteOrderItem.sku.id == " + sku1, true, true, 1));
    order.addOfferCode(createOfferUtility.createOfferCode("30 Dollars Off Item Offer", OfferType.ORDER_ITEM, OfferDiscountType.AMOUNT_OFF, 30, "discreteOrderItem.sku.id == " + sku1, true, false, 1));
    order.addOfferCode(createOfferUtility.createOfferCode("20 Percent Off Item Offer", OfferType.ORDER_ITEM, OfferDiscountType.PERCENT_OFF, 20, "discreteOrderItem.sku.id != " + sku1, true, false, 1));
    order.addOfferCode(createOfferUtility.createOfferCode("30 Dollars Off Item Offer", OfferType.ORDER_ITEM, OfferDiscountType.AMOUNT_OFF, 30, "discreteOrderItem.sku.id != " + sku1, true, true, 1));
    List<Offer> offers = offerService.buildOfferListForOrder(order);
    offerService.applyAndSaveOffersToOrder(offers, order);
    assert (order.getSubTotal().equals(new Money(300D)));
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) Money(org.broadleafcommerce.common.money.Money) Offer(org.broadleafcommerce.core.offer.domain.Offer) CustomerOffer(org.broadleafcommerce.core.offer.domain.CustomerOffer) Test(org.testng.annotations.Test) CommonSetupBaseTest(org.broadleafcommerce.test.CommonSetupBaseTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 22 with Money

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

the class OfferTest method testBOGOAmountOffCombination.

@Test(groups = { "testPercentageOffOffer" }, dependsOnGroups = { "offerCreateSku1", "offerCreateSku2" })
@Transactional
public void testBOGOAmountOffCombination() throws Exception {
    Order order = orderService.createNewCartForCustomer(createCustomer());
    FixedPriceFulfillmentOption option = new FixedPriceFulfillmentOptionImpl();
    option.setPrice(new Money(0));
    orderService.save(order, false);
    order.addOrderItem(createDiscreteOrderItem(sku1, 1000D, null, true, 1, order));
    order.addOrderItem(createDiscreteOrderItem(sku2, 100D, null, true, 2, order));
    order.addOfferCode(createOfferUtility.createOfferCode("10 Percent Off All Item Offer", OfferType.ORDER_ITEM, OfferDiscountType.PERCENT_OFF, 10, null, false, true, 10));
    order.addOfferCode(createOfferUtility.createOfferCode("NONAME", "30 Amount Off Second Item Sku2 Offer", OfferType.ORDER_ITEM, OfferDiscountType.AMOUNT_OFF, 30, "discreteOrderItem.sku.id == " + sku2, false, true, 10, "discreteOrderItem.sku.id == " + sku2));
    List<Offer> offers = offerService.buildOfferListForOrder(order);
    offerService.applyAndSaveOffersToOrder(offers, order);
    assert (order.getSubTotal().equals(new Money(1070D)));
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) Money(org.broadleafcommerce.common.money.Money) Offer(org.broadleafcommerce.core.offer.domain.Offer) CustomerOffer(org.broadleafcommerce.core.offer.domain.CustomerOffer) FixedPriceFulfillmentOption(org.broadleafcommerce.core.order.fulfillment.domain.FixedPriceFulfillmentOption) FixedPriceFulfillmentOptionImpl(org.broadleafcommerce.core.order.fulfillment.domain.FixedPriceFulfillmentOptionImpl) Test(org.testng.annotations.Test) CommonSetupBaseTest(org.broadleafcommerce.test.CommonSetupBaseTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 23 with Money

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

the class OrderPaymentStatusServiceImpl method determinePartiallyComplete.

protected boolean determinePartiallyComplete(OrderPayment payment) {
    Money fullAuthAmount = payment.getSuccessfulTransactionAmountForType(PaymentTransactionType.AUTHORIZE);
    Money fullCaptureAmount = payment.getSuccessfulTransactionAmountForType(PaymentTransactionType.CAPTURE);
    Money totalVoidAmount = payment.getSuccessfulTransactionAmountForType(PaymentTransactionType.VOID);
    Money totalRefundAmount = payment.getSuccessfulTransactionAmountForType(PaymentTransactionType.REFUND);
    return !determineComplete(payment) && ((totalRefundAmount.greaterThan(Money.ZERO) && fullAuthAmount.greaterThan(totalRefundAmount)) || (totalVoidAmount.greaterThan(Money.ZERO) && fullAuthAmount.greaterThan(totalVoidAmount)) || (containsSuccessfulType(payment, PaymentTransactionType.CAPTURE) && fullAuthAmount.greaterThan(Money.ZERO) && fullAuthAmount.greaterThan(fullCaptureAmount)));
}
Also used : Money(org.broadleafcommerce.common.money.Money)

Example 24 with Money

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

the class OfferTest method testGlobalOffers.

@Test(groups = { "testGlobalOffers" }, dependsOnGroups = { "testOfferNotCombinableOrderOffersWithItemOffer" })
@Transactional
public void testGlobalOffers() throws Exception {
    Order order = orderService.createNewCartForCustomer(createCustomer());
    order.addOrderItem(createDiscreteOrderItem(sku1, 10D, null, true, 2, order));
    order.addOrderItem(createDiscreteOrderItem(sku2, 20D, null, true, 1, order));
    order.addOfferCode(createOfferUtility.createOfferCode("20 Percent Off Item Offer", OfferType.ORDER_ITEM, OfferDiscountType.PERCENT_OFF, 20, "discreteOrderItem.sku.id == " + sku1, true, true, 10));
    order.addOfferCode(createOfferUtility.createOfferCode("3 Dollars Off Item Offer", OfferType.ORDER_ITEM, OfferDiscountType.AMOUNT_OFF, 3, "discreteOrderItem.sku.id != " + sku1, true, true, 10));
    Offer offer = createOfferUtility.createOffer("1.20 Dollars Off Order Offer", OfferType.ORDER, OfferDiscountType.AMOUNT_OFF, 1.20, null, true, true, 10, null);
    offer.setAutomaticallyAdded(true);
    offer = offerService.save(offer);
    List<Offer> offers = offerService.buildOfferListForOrder(order);
    offerService.applyAndSaveOffersToOrder(offers, order);
    assert order.getSubTotal().subtract(order.getOrderAdjustmentsValue()).equals(new Money(31.80D));
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) Money(org.broadleafcommerce.common.money.Money) Offer(org.broadleafcommerce.core.offer.domain.Offer) CustomerOffer(org.broadleafcommerce.core.offer.domain.CustomerOffer) Test(org.testng.annotations.Test) CommonSetupBaseTest(org.broadleafcommerce.test.CommonSetupBaseTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 25 with Money

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

the class OfferTest method testThreePercentOffOffers.

@Test(groups = { "testPercentageOffOffer" }, dependsOnGroups = { "offerCreateSku1", "offerCreateSku2" })
@Transactional
public void testThreePercentOffOffers() throws Exception {
    Order order = orderService.createNewCartForCustomer(createCustomer());
    FixedPriceFulfillmentOption option = new FixedPriceFulfillmentOptionImpl();
    option.setPrice(new Money(0));
    orderService.save(order, false);
    order.addOrderItem(createDiscreteOrderItem(sku1, 4.99D, null, true, 1, order));
    order.addOrderItem(createDiscreteOrderItem(sku2, 9.99D, null, true, 1, order));
    order.addOfferCode(createOfferUtility.createOfferCode("60 Percent Off Item Sku1 Offer", OfferType.ORDER_ITEM, OfferDiscountType.PERCENT_OFF, 60, "discreteOrderItem.sku.id == " + sku1, false, true, 10));
    order.addOfferCode(createOfferUtility.createOfferCode("60 Percent Off Item Sku2 Offer", OfferType.ORDER_ITEM, OfferDiscountType.PERCENT_OFF, 60, "discreteOrderItem.sku.id == " + sku2, false, true, 10));
    order.addOfferCode(createOfferUtility.createOfferCode("40 Percent Off All Item Offer", OfferType.ORDER_ITEM, OfferDiscountType.PERCENT_OFF, 40, null, false, true, 10));
    List<Offer> offers = offerService.buildOfferListForOrder(order);
    offerService.applyAndSaveOffersToOrder(offers, order);
    assert (order.getSubTotal().equals(new Money(6D)));
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) Money(org.broadleafcommerce.common.money.Money) Offer(org.broadleafcommerce.core.offer.domain.Offer) CustomerOffer(org.broadleafcommerce.core.offer.domain.CustomerOffer) FixedPriceFulfillmentOption(org.broadleafcommerce.core.order.fulfillment.domain.FixedPriceFulfillmentOption) FixedPriceFulfillmentOptionImpl(org.broadleafcommerce.core.order.fulfillment.domain.FixedPriceFulfillmentOptionImpl) Test(org.testng.annotations.Test) CommonSetupBaseTest(org.broadleafcommerce.test.CommonSetupBaseTest) Transactional(org.springframework.transaction.annotation.Transactional)

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