use of org.broadleafcommerce.core.order.domain.FulfillmentGroup in project BroadleafCommerce by BroadleafCommerce.
the class LegacyOrderServiceImpl method removeAllFulfillmentGroupsFromOrder.
@Override
public void removeAllFulfillmentGroupsFromOrder(Order order, boolean priceOrder) throws PricingException {
if (order.getFulfillmentGroups() != null) {
for (Iterator<FulfillmentGroup> iterator = order.getFulfillmentGroups().iterator(); iterator.hasNext(); ) {
FulfillmentGroup fulfillmentGroup = iterator.next();
iterator.remove();
fulfillmentGroupDao.delete(fulfillmentGroup);
}
updateOrder(order, priceOrder);
}
}
use of org.broadleafcommerce.core.order.domain.FulfillmentGroup in project BroadleafCommerce by BroadleafCommerce.
the class FulfillmentGroupItemStrategyImpl method onItemAdded.
@Override
public CartOperationRequest onItemAdded(CartOperationRequest request) throws PricingException {
Order order = request.getOrder();
OrderItem orderItem = request.getOrderItem();
Map<FulfillmentType, FulfillmentGroup> fulfillmentGroups = new HashMap<FulfillmentType, FulfillmentGroup>();
FulfillmentGroup nullFulfillmentTypeGroup = null;
// We'll use the first of each type that we find. Implementors can choose to move groups / items around later.
if (order.getFulfillmentGroups() != null) {
for (FulfillmentGroup group : order.getFulfillmentGroups()) {
if (group.getType() == null) {
if (nullFulfillmentTypeGroup == null) {
nullFulfillmentTypeGroup = group;
}
} else {
if (fulfillmentGroups.get(group.getType()) == null) {
fulfillmentGroups.put(group.getType(), group);
}
}
}
}
if (orderItem instanceof BundleOrderItem) {
// We only care about the discrete order items
List<DiscreteOrderItem> itemsToAdd = new ArrayList<DiscreteOrderItem>(((BundleOrderItem) orderItem).getDiscreteOrderItems());
for (DiscreteOrderItem doi : itemsToAdd) {
FulfillmentGroup fulfillmentGroup = null;
FulfillmentType type = resolveFulfillmentType(doi);
if (type == null) {
// Use the fulfillment group with a null type
fulfillmentGroup = nullFulfillmentTypeGroup;
} else {
if (FulfillmentType.PHYSICAL_PICKUP_OR_SHIP.equals(type)) {
// This is really a special case. "PICKUP_OR_SHIP" is convenient to allow a sku to be picked up or shipped.
// However, it is ambiguous when actually trying to create a fulfillment group. So we default to "PHYSICAL_SHIP".
type = FulfillmentType.PHYSICAL_SHIP;
}
// Use the fulfillment group with the specified type
fulfillmentGroup = fulfillmentGroups.get(type);
}
// If the null type or specified type, above were null, then we need to create a new fulfillment group
boolean createdFulfillmentGroup = false;
if (fulfillmentGroup == null) {
fulfillmentGroup = fulfillmentGroupService.createEmptyFulfillmentGroup();
// Set the type
fulfillmentGroup.setType(type);
fulfillmentGroup.setOrder(order);
order.getFulfillmentGroups().add(fulfillmentGroup);
createdFulfillmentGroup = true;
}
fulfillmentGroup = addItemToFulfillmentGroup(order, doi, doi.getQuantity() * orderItem.getQuantity(), fulfillmentGroup);
order = fulfillmentGroup.getOrder();
// of fulfillment groups
if (createdFulfillmentGroup) {
if (type == null) {
nullFulfillmentTypeGroup = fulfillmentGroup;
} else {
fulfillmentGroups.put(type, fulfillmentGroup);
}
}
}
} else if (orderItem instanceof DiscreteOrderItem) {
DiscreteOrderItem doi = (DiscreteOrderItem) orderItem;
FulfillmentGroup fulfillmentGroup = null;
FulfillmentType type = resolveFulfillmentType(doi);
if (type == null) {
// Use the fulfillment group with a null type
fulfillmentGroup = nullFulfillmentTypeGroup;
} else {
if (FulfillmentType.PHYSICAL_PICKUP_OR_SHIP.equals(type)) {
// This is really a special case. "PICKUP_OR_SHIP" is convenient to allow a sku to be picked up or shipped.
// However, it is ambiguous when actually trying to create a fulfillment group. So we default to "PHYSICAL_SHIP".
type = FulfillmentType.PHYSICAL_SHIP;
}
// Use the fulfillment group with the specified type
fulfillmentGroup = fulfillmentGroups.get(type);
}
// If the null type or specified type, above were null, then we need to create a new fulfillment group
if (fulfillmentGroup == null) {
fulfillmentGroup = fulfillmentGroupService.createEmptyFulfillmentGroup();
// Set the type
fulfillmentGroup.setType(type);
fulfillmentGroup.setOrder(order);
order.getFulfillmentGroups().add(fulfillmentGroup);
}
fulfillmentGroup = addItemToFulfillmentGroup(order, orderItem, fulfillmentGroup);
order = fulfillmentGroup.getOrder();
} else {
FulfillmentGroup fulfillmentGroup = nullFulfillmentTypeGroup;
if (fulfillmentGroup == null) {
fulfillmentGroup = fulfillmentGroupService.createEmptyFulfillmentGroup();
fulfillmentGroup.setOrder(order);
order.getFulfillmentGroups().add(fulfillmentGroup);
}
fulfillmentGroup = addItemToFulfillmentGroup(order, orderItem, fulfillmentGroup);
}
return request;
}
use of org.broadleafcommerce.core.order.domain.FulfillmentGroup in project BroadleafCommerce by BroadleafCommerce.
the class PaymentResponseDTOToEntityServiceImpl method populateShippingInfo.
@Override
public void populateShippingInfo(PaymentResponseDTO responseDTO, Order order) {
FulfillmentGroup shippableFulfillmentGroup = fulfillmentGroupService.getFirstShippableFulfillmentGroup(order);
if (responseDTO.getShipTo() != null && responseDTO.getShipTo().addressPopulated() && shippableFulfillmentGroup != null) {
Address shippingAddress = addressService.create();
AddressDTO<PaymentResponseDTO> shipToDTO = responseDTO.getShipTo();
populateAddressInfo(shipToDTO, shippingAddress);
shippableFulfillmentGroup = fulfillmentGroupService.findFulfillmentGroupById(shippableFulfillmentGroup.getId());
if (shippableFulfillmentGroup != null) {
shippableFulfillmentGroup.setAddress(shippingAddress);
fulfillmentGroupService.save(shippableFulfillmentGroup);
}
}
}
use of org.broadleafcommerce.core.order.domain.FulfillmentGroup in project BroadleafCommerce by BroadleafCommerce.
the class AddWorkflowPriceOrderIfNecessaryActivity method getOiFgiMap.
protected void getOiFgiMap(Order order, Map<OrderItem, List<FulfillmentGroupItem>> oiFgiMap, OrderItem oi) {
List<FulfillmentGroupItem> fgis = new ArrayList<>();
for (FulfillmentGroup fg : order.getFulfillmentGroups()) {
for (FulfillmentGroupItem fgi : fg.getFulfillmentGroupItems()) {
if (fgi.getOrderItem().equals(oi)) {
fgis.add(fgi);
}
}
}
oiFgiMap.put(oi, fgis);
}
use of org.broadleafcommerce.core.order.domain.FulfillmentGroup 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;
}
Aggregations