use of org.broadleafcommerce.core.order.domain.FulfillmentGroupImpl in project BroadleafCommerce by BroadleafCommerce.
the class CheckoutTest method buildFulfillmentGroup.
private FulfillmentGroup buildFulfillmentGroup(Order order, Address address) {
FulfillmentGroup group = new FulfillmentGroupImpl();
group.setIsShippingPriceTaxable(true);
group.setOrder(order);
group.setAddress(address);
List<FulfillmentGroup> groups = new ArrayList<>();
groups.add(group);
order.setFulfillmentGroups(groups);
Money total = new Money(5D);
group.setShippingPrice(total);
FixedPriceFulfillmentOption option = new FixedPriceFulfillmentOptionImpl();
option.setPrice(new Money(0));
option.setFulfillmentType(FulfillmentType.PHYSICAL_SHIP);
group.setFulfillmentOption(option);
return group;
}
use of org.broadleafcommerce.core.order.domain.FulfillmentGroupImpl in project BroadleafCommerce by BroadleafCommerce.
the class MVELTest method testOfferAppliesToFulfillmentGroup.
// @Test
// No longer a valid test
// public void testMarkLawnmowerWhenOfferAppliesToHats() {
// OrderImpl order = new OrderImpl();
// ArrayList<OrderItem> items = new ArrayList<OrderItem>();
// order.setOrderItems(items);
// DiscreteOrderItemImpl item = new DiscreteOrderItemImpl();
// Money amount = new Money(10D);
// items.add(item);
// item.setSalePrice(amount);
// ProductImpl product = new ProductImpl();
// CategoryImpl category = new CategoryImpl();
// category.setName("hat");
// product.setDefaultCategory(category);
// item.setProduct(product);
// item.setQuantity(3);
//
// DiscreteOrderItemImpl item2 = new DiscreteOrderItemImpl();
// Money amount2 = new Money(250D);
// items.add(item2);
// item2.setSalePrice(amount2);
// ProductImpl product2 = new ProductImpl();
// CategoryImpl category2 = new CategoryImpl();
// category2.setName("lawnmower");
// product2.setDefaultCategory(category2);
// item2.setProduct(product2);
// item2.setQuantity(1);
//
// HashMap<String, Object> vars = new HashMap<String, Object>();
// vars.put("currentItem", item);
// vars.put("order", order);
// vars.put("doMark", true);
//
// //This test makes use of the static MVEL function "orderContains(quantity)".
// StringBuffer expression = new StringBuffer(functions);
// expression.append("def evalItemForOrderContains(item) {")
// .append(" return item.product.defaultCategory.name == 'lawnmower'")
// .append(" } ")
// .append(" return (orderContainsPlusMark(1) and currentItem.product.defaultCategory.name == 'hat');");
//
// Boolean result = (Boolean)MVEL.eval(expression.toString(), vars);
// assert result != null && result;
// assert item2.getMarkedForOffer() == 1;
// assert item.getMarkedForOffer() == 0;
// }
@Test
public void testOfferAppliesToFulfillmentGroup() {
OrderImpl order = new OrderImpl();
order.setSubTotal(new Money(110D));
FulfillmentGroupImpl group = new FulfillmentGroupImpl();
group.setPrimary(true);
OfferImpl offer = new OfferImpl();
offer.setType(OfferType.FULFILLMENT_GROUP);
order.getFulfillmentGroups().add(group);
// Set up MVEL Context
ParserContext context = new ParserContext();
// Import OfferType into the MVEL context since it may be used
context.addImport("OfferType", OfferType.class);
context.addImport("FulfillmentType", FulfillmentType.class);
// Compile the MVEL Expression
// This could test SHIPPING, or PICK_UP_AT_STORE, etc.
// Could also apply to order instead of FULFILLMENT_GROUP
Serializable domainExp1 = MVEL.compileExpression("offer.type.equals(OfferType.FULFILLMENT_GROUP) and (($ in order.fulfillmentGroups if $.type.equals(FulfillmentType.PHYSICAL)) != empty)", context);
// Add variables to a HashMap that should be passed in to execute the expression
HashMap<String, Object> domainVars = new HashMap<>();
domainVars.put("order", order);
domainVars.put("offer", offer);
// Execute the expression
Boolean expressionOutcome1 = (Boolean) MVEL.executeExpression(domainExp1, domainVars);
assert expressionOutcome1 != null && expressionOutcome1;
}
use of org.broadleafcommerce.core.order.domain.FulfillmentGroupImpl in project BroadleafCommerce by BroadleafCommerce.
the class OfferTest method createFulfillmentGroups.
private List<FulfillmentGroup> createFulfillmentGroups(FulfillmentOption option, Double shippingPrice, Order order) {
List<FulfillmentGroup> groups = new ArrayList<FulfillmentGroup>();
FulfillmentGroup group = new FulfillmentGroupImpl();
group.setFulfillmentOption(option);
groups.add(group);
group.setRetailShippingPrice(new Money(shippingPrice));
group.setOrder(order);
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");
Country country = new CountryImpl();
country.setAbbreviation("US");
country.setName("United States");
countryService.save(country);
ISOCountry isoCountry = new ISOCountryImpl();
isoCountry.setAlpha2("US");
isoCountry.setName("UNITED STATES");
isoService.save(isoCountry);
State state = new StateImpl();
state.setAbbreviation("TX");
state.setName("Texas");
state.setCountry(country);
stateService.save(state);
address.setState(state);
address.setCountry(country);
address.setIsoCountrySubdivision("US-TX");
address.setIsoCountryAlpha2(isoCountry);
for (OrderItem orderItem : order.getOrderItems()) {
FulfillmentGroupItem fgItem = new FulfillmentGroupItemImpl();
fgItem.setFulfillmentGroup(group);
fgItem.setOrderItem(orderItem);
fgItem.setQuantity(orderItem.getQuantity());
group.addFulfillmentGroupItem(fgItem);
}
group.setAddress(address);
return groups;
}
use of org.broadleafcommerce.core.order.domain.FulfillmentGroupImpl in project BroadleafCommerce by BroadleafCommerce.
the class FulfillmentGroupDataProvider method provideBasicSalesFulfillmentGroup.
@DataProvider(name = "basicFulfillmentGroup")
public static Object[][] provideBasicSalesFulfillmentGroup() {
FulfillmentGroupImpl sos = new FulfillmentGroupImpl();
sos.setReferenceNumber("123456789");
FixedPriceFulfillmentOption option = new FixedPriceFulfillmentOptionImpl();
option.setPrice(new Money(0));
sos.setFulfillmentOption(option);
return new Object[][] { { sos } };
}
use of org.broadleafcommerce.core.order.domain.FulfillmentGroupImpl in project BroadleafCommerce by BroadleafCommerce.
the class FulfillmentGroupDaoImpl method readDefaultFulfillmentGroupForOrder.
@Override
public FulfillmentGroupImpl readDefaultFulfillmentGroupForOrder(final Order order) {
final Query query = em.createNamedQuery("BC_READ_DEFAULT_FULFILLMENT_GROUP_BY_ORDER_ID");
query.setParameter("orderId", order.getId());
@SuppressWarnings("unchecked") List<FulfillmentGroupImpl> fulfillmentGroups = query.getResultList();
return fulfillmentGroups == null || fulfillmentGroups.isEmpty() ? null : fulfillmentGroups.get(0);
}
Aggregations