use of org.broadleafcommerce.core.catalog.domain.SkuFeeImpl in project BroadleafCommerce by BroadleafCommerce.
the class PricingTest method testPricing.
@Test(groups = { "testPricing" }, dependsOnGroups = { "testShippingInsert", "createCustomerIdGeneration" })
@Transactional
public void testPricing() throws Exception {
Order order = orderService.createNewCartForCustomer(createCustomer());
customerService.saveCustomer(order.getCustomer());
Country country = new CountryImpl();
country.setAbbreviation("US");
country.setName("United States");
country = countryService.save(country);
ISOCountry isoCountry = new ISOCountryImpl();
isoCountry.setAlpha2("US");
isoCountry.setName("UNITED STATES");
isoCountry = isoService.save(isoCountry);
State state = new StateImpl();
state.setAbbreviation("TX");
state.setName("Texas");
state.setCountry(country);
state = stateService.save(state);
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(state);
address.setCountry(country);
address.setIsoCountrySubdivision("US-TX");
address.setIsoCountryAlpha2(isoCountry);
FulfillmentGroup group = new FulfillmentGroupImpl();
group.setAddress(address);
List<FulfillmentGroup> groups = new ArrayList<>();
group.setMethod("standard");
group.setService(ShippingServiceType.BANDED_SHIPPING.getType());
group.setOrder(order);
groups.add(group);
order.setFulfillmentGroups(groups);
Money total = new Money(8.5D);
group.setShippingPrice(total);
{
DiscreteOrderItem item = new DiscreteOrderItemImpl();
Sku sku = new SkuImpl();
sku.setName("Test Sku");
sku.setRetailPrice(new Money(10D));
sku.setDiscountable(true);
SkuFee fee = new SkuFeeImpl();
fee.setFeeType(SkuFeeType.FULFILLMENT);
fee.setName("fee test");
fee.setAmount(new Money(10D));
fee = catalogService.saveSkuFee(fee);
List<SkuFee> fees = new ArrayList<>();
fees.add(fee);
sku.setFees(fees);
sku = catalogService.saveSku(sku);
item.setSku(sku);
item.setQuantity(2);
item.setOrder(order);
item = (DiscreteOrderItem) orderItemService.saveOrderItem(item);
order.addOrderItem(item);
FulfillmentGroupItem fgItem = new FulfillmentGroupItemImpl();
fgItem.setFulfillmentGroup(group);
fgItem.setOrderItem(item);
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 = (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);
}
order.addOfferCode(createOfferCode("20 Percent Off Item Offer", OfferType.ORDER_ITEM, OfferDiscountType.PERCENT_OFF, 20, null, "discreteOrderItem.sku.name==\"Test Sku\""));
order.addOfferCode(createOfferCode("3 Dollars Off Item Offer", OfferType.ORDER_ITEM, OfferDiscountType.AMOUNT_OFF, 3, null, "discreteOrderItem.sku.name!=\"Test Sku\""));
order.addOfferCode(createOfferCode("1.20 Dollars Off Order Offer", OfferType.ORDER, OfferDiscountType.AMOUNT_OFF, 1.20, null, null));
order.setTotalShipping(new Money(0D));
orderService.save(order, true);
assert order.getSubTotal().subtract(order.getOrderAdjustmentsValue()).equals(new Money(31.80D));
assert (order.getTotal().greaterThan(order.getSubTotal()));
// Shipping is not taxable
assert (order.getTotalTax().equals(order.getSubTotal().subtract(order.getOrderAdjustmentsValue()).multiply(0.05D)));
// determine the total cost of the fulfillment group fees
Money fulfillmentGroupFeeTotal = getFulfillmentGroupFeeTotal(order);
assert (order.getTotal().equals(order.getSubTotal().add(order.getTotalTax()).add(order.getTotalShipping()).add(fulfillmentGroupFeeTotal).subtract(order.getOrderAdjustmentsValue())));
}
Aggregations