use of org.broadleafcommerce.core.order.fulfillment.domain.FixedPriceFulfillmentOption in project BroadleafCommerce by BroadleafCommerce.
the class FixedPriceFulfillmentPricingProvider method estimateCostForFulfillmentGroup.
@Override
public FulfillmentEstimationResponse estimateCostForFulfillmentGroup(FulfillmentGroup fulfillmentGroup, Set<FulfillmentOption> options) throws FulfillmentPriceException {
FulfillmentEstimationResponse response = new FulfillmentEstimationResponse();
HashMap<FulfillmentOption, Money> shippingPrices = new HashMap<FulfillmentOption, Money>();
response.setFulfillmentOptionPrices(shippingPrices);
for (FulfillmentOption option : options) {
if (canCalculateCostForFulfillmentGroup(fulfillmentGroup, option)) {
Money price = ((FixedPriceFulfillmentOption) option).getPrice();
shippingPrices.put(option, price);
}
}
return response;
}
use of org.broadleafcommerce.core.order.fulfillment.domain.FixedPriceFulfillmentOption in project BroadleafCommerce by BroadleafCommerce.
the class FixedPriceFulfillmentPricingProvider method calculateCostForFulfillmentGroup.
@Override
public FulfillmentGroup calculateCostForFulfillmentGroup(FulfillmentGroup fulfillmentGroup) throws FulfillmentPriceException {
if (canCalculateCostForFulfillmentGroup(fulfillmentGroup, fulfillmentGroup.getFulfillmentOption())) {
Money price = ((FixedPriceFulfillmentOption) fulfillmentGroup.getFulfillmentOption()).getPrice();
fulfillmentGroup.setRetailShippingPrice(price);
fulfillmentGroup.setSaleShippingPrice(price);
fulfillmentGroup.setShippingPrice(price);
return fulfillmentGroup;
}
throw new IllegalArgumentException("Cannot estimate shipping cost for the fulfillment option: " + fulfillmentGroup.getFulfillmentOption().getClass().getName());
}
use of org.broadleafcommerce.core.order.fulfillment.domain.FixedPriceFulfillmentOption 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;
}
use of org.broadleafcommerce.core.order.fulfillment.domain.FixedPriceFulfillmentOption 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)));
}
use of org.broadleafcommerce.core.order.fulfillment.domain.FixedPriceFulfillmentOption 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)));
}
Aggregations