Search in sources :

Example 1 with FulfillmentGroupImpl

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;
}
Also used : Money(org.broadleafcommerce.common.money.Money) FulfillmentGroupImpl(org.broadleafcommerce.core.order.domain.FulfillmentGroupImpl) FixedPriceFulfillmentOption(org.broadleafcommerce.core.order.fulfillment.domain.FixedPriceFulfillmentOption) ArrayList(java.util.ArrayList) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup) FixedPriceFulfillmentOptionImpl(org.broadleafcommerce.core.order.fulfillment.domain.FixedPriceFulfillmentOptionImpl)

Example 2 with FulfillmentGroupImpl

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;
}
Also used : Money(org.broadleafcommerce.common.money.Money) FulfillmentGroupImpl(org.broadleafcommerce.core.order.domain.FulfillmentGroupImpl) Serializable(java.io.Serializable) HashMap(java.util.HashMap) OrderImpl(org.broadleafcommerce.core.order.domain.OrderImpl) OfferImpl(org.broadleafcommerce.core.offer.domain.OfferImpl) ParserContext(org.mvel2.ParserContext) Test(org.testng.annotations.Test)

Example 3 with FulfillmentGroupImpl

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;
}
Also used : FulfillmentGroupImpl(org.broadleafcommerce.core.order.domain.FulfillmentGroupImpl) Address(org.broadleafcommerce.profile.core.domain.Address) ArrayList(java.util.ArrayList) StateImpl(org.broadleafcommerce.profile.core.domain.StateImpl) Money(org.broadleafcommerce.common.money.Money) ISOCountryImpl(org.broadleafcommerce.common.i18n.domain.ISOCountryImpl) CountryImpl(org.broadleafcommerce.profile.core.domain.CountryImpl) State(org.broadleafcommerce.profile.core.domain.State) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) FulfillmentGroupItem(org.broadleafcommerce.core.order.domain.FulfillmentGroupItem) AddressImpl(org.broadleafcommerce.profile.core.domain.AddressImpl) Country(org.broadleafcommerce.profile.core.domain.Country) ISOCountry(org.broadleafcommerce.common.i18n.domain.ISOCountry) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup) ISOCountryImpl(org.broadleafcommerce.common.i18n.domain.ISOCountryImpl) ISOCountry(org.broadleafcommerce.common.i18n.domain.ISOCountry) FulfillmentGroupItemImpl(org.broadleafcommerce.core.order.domain.FulfillmentGroupItemImpl)

Example 4 with FulfillmentGroupImpl

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 } };
}
Also used : Money(org.broadleafcommerce.common.money.Money) FulfillmentGroupImpl(org.broadleafcommerce.core.order.domain.FulfillmentGroupImpl) FixedPriceFulfillmentOption(org.broadleafcommerce.core.order.fulfillment.domain.FixedPriceFulfillmentOption) FixedPriceFulfillmentOptionImpl(org.broadleafcommerce.core.order.fulfillment.domain.FixedPriceFulfillmentOptionImpl) DataProvider(org.testng.annotations.DataProvider)

Example 5 with FulfillmentGroupImpl

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);
}
Also used : FulfillmentGroupImpl(org.broadleafcommerce.core.order.domain.FulfillmentGroupImpl) Query(javax.persistence.Query)

Aggregations

FulfillmentGroupImpl (org.broadleafcommerce.core.order.domain.FulfillmentGroupImpl)13 Money (org.broadleafcommerce.common.money.Money)11 FulfillmentGroup (org.broadleafcommerce.core.order.domain.FulfillmentGroup)9 DiscreteOrderItem (org.broadleafcommerce.core.order.domain.DiscreteOrderItem)7 FulfillmentGroupItem (org.broadleafcommerce.core.order.domain.FulfillmentGroupItem)7 FulfillmentGroupItemImpl (org.broadleafcommerce.core.order.domain.FulfillmentGroupItemImpl)7 ArrayList (java.util.ArrayList)6 Sku (org.broadleafcommerce.core.catalog.domain.Sku)6 SkuImpl (org.broadleafcommerce.core.catalog.domain.SkuImpl)6 DiscreteOrderItemImpl (org.broadleafcommerce.core.order.domain.DiscreteOrderItemImpl)6 Order (org.broadleafcommerce.core.order.domain.Order)6 Address (org.broadleafcommerce.profile.core.domain.Address)6 AddressImpl (org.broadleafcommerce.profile.core.domain.AddressImpl)6 ISOCountry (org.broadleafcommerce.common.i18n.domain.ISOCountry)5 ISOCountryImpl (org.broadleafcommerce.common.i18n.domain.ISOCountryImpl)5 Country (org.broadleafcommerce.profile.core.domain.Country)5 CountryImpl (org.broadleafcommerce.profile.core.domain.CountryImpl)5 State (org.broadleafcommerce.profile.core.domain.State)5 StateImpl (org.broadleafcommerce.profile.core.domain.StateImpl)5 OrderImpl (org.broadleafcommerce.core.order.domain.OrderImpl)4