Search in sources :

Example 6 with FixedPriceFulfillmentOptionImpl

use of org.broadleafcommerce.core.order.fulfillment.domain.FixedPriceFulfillmentOptionImpl in project BroadleafCommerce by BroadleafCommerce.

the class OfferServiceTest method createTestOrderWithOfferAndGiftWrap.

private Order createTestOrderWithOfferAndGiftWrap() throws PricingException {
    Customer customer = customerService.createCustomerFromId(null);
    Order order = orderService.createNewCartForCustomer(customer);
    customerService.saveCustomer(order.getCustomer());
    createCountry();
    createState();
    Address address = new AddressImpl();
    address.setAddressLine1("123 Test Rd");
    address.setCity("Dallas");
    address.setFirstName("Jeff");
    address.setLastName("Fischer");
    address.setPostalCode("75240");
    address.setPrimaryPhone("972-978-9067");
    address.setState(stateService.findStateByAbbreviation("KY"));
    address.setCountry(countryService.findCountryByAbbreviation("US"));
    address.setIsoCountrySubdivision("US-KY");
    address.setIsoCountryAlpha2(isoService.findISOCountryByAlpha2Code("US"));
    FulfillmentGroup group = new FulfillmentGroupImpl();
    group.setAddress(address);
    group.setIsShippingPriceTaxable(true);
    List<FulfillmentGroup> groups = new ArrayList<FulfillmentGroup>();
    FixedPriceFulfillmentOption option = new FixedPriceFulfillmentOptionImpl();
    option.setPrice(new Money("8.50"));
    option.setFulfillmentType(FulfillmentType.PHYSICAL_SHIP);
    group.setFulfillmentOption(option);
    group.setFulfillmentOption(option);
    group.setOrder(order);
    groups.add(group);
    order.setFulfillmentGroups(groups);
    Money total = new Money(5D);
    group.setRetailShippingPrice(total);
    group.setShippingPrice(total);
    DiscreteOrderItem item1;
    {
        item1 = new DiscreteOrderItemImpl();
        Sku sku = new SkuImpl();
        sku.setName("Test Sku");
        sku.setRetailPrice(new Money(10D));
        sku.setDiscountable(true);
        sku = catalogService.saveSku(sku);
        item1.setSku(sku);
        item1.setQuantity(2);
        item1.setOrder(order);
        item1.setOrderItemType(OrderItemType.DISCRETE);
        item1 = (DiscreteOrderItem) orderItemService.saveOrderItem(item1);
        order.addOrderItem(item1);
        FulfillmentGroupItem fgItem = new FulfillmentGroupItemImpl();
        fgItem.setFulfillmentGroup(group);
        fgItem.setOrderItem(item1);
        fgItem.setQuantity(2);
        // fgItem.setPrice(new Money(0D));
        group.addFulfillmentGroupItem(fgItem);
    }
    {
        DiscreteOrderItem item = new DiscreteOrderItemImpl();
        Sku sku = new SkuImpl();
        sku.setName("Test Product 2");
        sku.setRetailPrice(new Money(20D));
        sku.setDiscountable(true);
        sku = catalogService.saveSku(sku);
        item.setSku(sku);
        item.setQuantity(1);
        item.setOrder(order);
        item.setOrderItemType(OrderItemType.DISCRETE);
        item = (DiscreteOrderItem) orderItemService.saveOrderItem(item);
        order.addOrderItem(item);
        FulfillmentGroupItem fgItem = new FulfillmentGroupItemImpl();
        fgItem.setFulfillmentGroup(group);
        fgItem.setOrderItem(item);
        fgItem.setQuantity(1);
        // fgItem.setPrice(new Money(0D));
        group.addFulfillmentGroupItem(fgItem);
    }
    {
        GiftWrapOrderItem item = new GiftWrapOrderItemImpl();
        Sku sku = new SkuImpl();
        sku.setName("Test GiftWrap");
        sku.setRetailPrice(new Money(1D));
        sku.setDiscountable(true);
        sku = catalogService.saveSku(sku);
        item.setSku(sku);
        item.setQuantity(1);
        item.setOrder(order);
        item.getWrappedItems().add(item1);
        item.setOrderItemType(OrderItemType.GIFTWRAP);
        item = (GiftWrapOrderItem) orderItemService.saveOrderItem(item);
        order.addOrderItem(item);
        FulfillmentGroupItem fgItem = new FulfillmentGroupItemImpl();
        fgItem.setFulfillmentGroup(group);
        fgItem.setOrderItem(item);
        fgItem.setQuantity(1);
        // fgItem.setPrice(new Money(0D));
        group.addFulfillmentGroupItem(fgItem);
    }
    return order;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) FulfillmentGroupImpl(org.broadleafcommerce.core.order.domain.FulfillmentGroupImpl) Address(org.broadleafcommerce.profile.core.domain.Address) Customer(org.broadleafcommerce.profile.core.domain.Customer) DiscreteOrderItemImpl(org.broadleafcommerce.core.order.domain.DiscreteOrderItemImpl) ArrayList(java.util.ArrayList) Money(org.broadleafcommerce.common.money.Money) SkuImpl(org.broadleafcommerce.core.catalog.domain.SkuImpl) FixedPriceFulfillmentOption(org.broadleafcommerce.core.order.fulfillment.domain.FixedPriceFulfillmentOption) FulfillmentGroupItem(org.broadleafcommerce.core.order.domain.FulfillmentGroupItem) AddressImpl(org.broadleafcommerce.profile.core.domain.AddressImpl) GiftWrapOrderItem(org.broadleafcommerce.core.order.domain.GiftWrapOrderItem) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup) GiftWrapOrderItemImpl(org.broadleafcommerce.core.order.domain.GiftWrapOrderItemImpl) Sku(org.broadleafcommerce.core.catalog.domain.Sku) FixedPriceFulfillmentOptionImpl(org.broadleafcommerce.core.order.fulfillment.domain.FixedPriceFulfillmentOptionImpl) FulfillmentGroupItemImpl(org.broadleafcommerce.core.order.domain.FulfillmentGroupItemImpl)

Example 7 with FixedPriceFulfillmentOptionImpl

use of org.broadleafcommerce.core.order.fulfillment.domain.FixedPriceFulfillmentOptionImpl in project BroadleafCommerce by BroadleafCommerce.

the class OfferTest method testTwoPercentOffOffers.

@Test(groups = { "testPercentageOffOffer" }, dependsOnGroups = { "offerCreateSku1", "offerCreateSku2" })
@Transactional
public void testTwoPercentOffOffers() 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, 1, 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("15 Percent Off Item Sku2 Offer", OfferType.ORDER_ITEM, OfferDiscountType.PERCENT_OFF, 15, "discreteOrderItem.sku.id == " + sku2, false, true, 10));
    List<Offer> offers = offerService.buildOfferListForOrder(order);
    offerService.applyAndSaveOffersToOrder(offers, order);
    assert (order.getSubTotal().equals(new Money(985D)));
}
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 8 with FixedPriceFulfillmentOptionImpl

use of org.broadleafcommerce.core.order.fulfillment.domain.FixedPriceFulfillmentOptionImpl in project BroadleafCommerce by BroadleafCommerce.

the class OfferTest method testBOGOCombination.

@Test(groups = { "testPercentageOffOffer" }, dependsOnGroups = { "offerCreateSku1", "offerCreateSku2" })
@Transactional
public void testBOGOCombination() 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 Percent Off Second Item Sku2 Offer", OfferType.ORDER_ITEM, OfferDiscountType.PERCENT_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 9 with FixedPriceFulfillmentOptionImpl

use of org.broadleafcommerce.core.order.fulfillment.domain.FixedPriceFulfillmentOptionImpl in project BroadleafCommerce by BroadleafCommerce.

the class OfferTest method testPercentOffOfferWithScaleGreaterThanTwo.

@Test(groups = { "testPercentageOffOffer" }, dependsOnGroups = { "offerCreateSku1", "offerCreateSku2" })
@Transactional
public void testPercentOffOfferWithScaleGreaterThanTwo() throws Exception {
    Order order = orderService.createNewCartForCustomer(createCustomer());
    FixedPriceFulfillmentOption option = new FixedPriceFulfillmentOptionImpl();
    option.setPrice(new Money(0));
    option.setFulfillmentType(FulfillmentType.PHYSICAL_SHIP);
    order.setFulfillmentGroups(createFulfillmentGroups(option, 5D, order));
    orderService.save(order, false);
    order.addOrderItem(createDiscreteOrderItem(sku1, 100D, null, true, 2, order));
    order.addOrderItem(createDiscreteOrderItem(sku2, 100D, null, true, 1, order));
    order.addOfferCode(createOfferUtility.createOfferCode("20.5 Percent Off Item Offer", OfferType.ORDER_ITEM, OfferDiscountType.PERCENT_OFF, 20.5, null, true, true, 10));
    List<Offer> offers = offerService.buildOfferListForOrder(order);
    offerService.applyAndSaveOffersToOrder(offers, order);
    // 20% results in $240.  20.5% off results in $238.50
    assert (order.getSubTotal().equals(new Money(238.50D)));
}
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 10 with FixedPriceFulfillmentOptionImpl

use of org.broadleafcommerce.core.order.fulfillment.domain.FixedPriceFulfillmentOptionImpl in project BroadleafCommerce by BroadleafCommerce.

the class FixedPriceFulfillmentTest method testNullFulfillmentOptionInEstimation.

public void testNullFulfillmentOptionInEstimation() throws Exception {
    Set<FulfillmentOption> options = new HashSet<FulfillmentOption>();
    FixedPriceFulfillmentOption option1 = new FixedPriceFulfillmentOptionImpl();
    option1.setPrice(new Money(BigDecimal.ONE));
    FixedPriceFulfillmentOption option2 = new FixedPriceFulfillmentOptionImpl();
    option2.setPrice(new Money(BigDecimal.TEN));
    options.add(option1);
    options.add(option2);
    FixedPriceFulfillmentPricingProvider provider = new FixedPriceFulfillmentPricingProvider();
    FulfillmentGroup fg = new FulfillmentGroupImpl();
    FulfillmentEstimationResponse response = provider.estimateCostForFulfillmentGroup(fg, options);
    for (Entry<? extends FulfillmentOption, Money> entry : response.getFulfillmentOptionPrices().entrySet()) {
        assertEquals(((FixedPriceFulfillmentOption) entry.getKey()).getPrice(), entry.getValue());
    }
}
Also used : FixedPriceFulfillmentPricingProvider(org.broadleafcommerce.core.pricing.service.fulfillment.provider.FixedPriceFulfillmentPricingProvider) Money(org.broadleafcommerce.common.money.Money) FulfillmentGroupImpl(org.broadleafcommerce.core.order.domain.FulfillmentGroupImpl) FixedPriceFulfillmentOption(org.broadleafcommerce.core.order.fulfillment.domain.FixedPriceFulfillmentOption) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup) FulfillmentEstimationResponse(org.broadleafcommerce.core.pricing.service.fulfillment.provider.FulfillmentEstimationResponse) FixedPriceFulfillmentOption(org.broadleafcommerce.core.order.fulfillment.domain.FixedPriceFulfillmentOption) FulfillmentOption(org.broadleafcommerce.core.order.domain.FulfillmentOption) FixedPriceFulfillmentOptionImpl(org.broadleafcommerce.core.order.fulfillment.domain.FixedPriceFulfillmentOptionImpl) HashSet(java.util.HashSet)

Aggregations

Money (org.broadleafcommerce.common.money.Money)10 FixedPriceFulfillmentOption (org.broadleafcommerce.core.order.fulfillment.domain.FixedPriceFulfillmentOption)10 FixedPriceFulfillmentOptionImpl (org.broadleafcommerce.core.order.fulfillment.domain.FixedPriceFulfillmentOptionImpl)10 Order (org.broadleafcommerce.core.order.domain.Order)7 CustomerOffer (org.broadleafcommerce.core.offer.domain.CustomerOffer)6 Offer (org.broadleafcommerce.core.offer.domain.Offer)6 CommonSetupBaseTest (org.broadleafcommerce.test.CommonSetupBaseTest)6 Transactional (org.springframework.transaction.annotation.Transactional)6 Test (org.testng.annotations.Test)6 FulfillmentGroupImpl (org.broadleafcommerce.core.order.domain.FulfillmentGroupImpl)4 FulfillmentGroup (org.broadleafcommerce.core.order.domain.FulfillmentGroup)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)1 Sku (org.broadleafcommerce.core.catalog.domain.Sku)1 SkuImpl (org.broadleafcommerce.core.catalog.domain.SkuImpl)1 DiscreteOrderItem (org.broadleafcommerce.core.order.domain.DiscreteOrderItem)1 DiscreteOrderItemImpl (org.broadleafcommerce.core.order.domain.DiscreteOrderItemImpl)1 FulfillmentGroupItem (org.broadleafcommerce.core.order.domain.FulfillmentGroupItem)1 FulfillmentGroupItemImpl (org.broadleafcommerce.core.order.domain.FulfillmentGroupItemImpl)1 FulfillmentOption (org.broadleafcommerce.core.order.domain.FulfillmentOption)1