use of org.broadleafcommerce.core.order.domain.FulfillmentGroup in project BroadleafCommerce by BroadleafCommerce.
the class CheckoutFormServiceImpl method prePopulateShippingInfoForm.
@Override
public ShippingInfoForm prePopulateShippingInfoForm(ShippingInfoForm shippingInfoForm, Order cart) {
FulfillmentGroup firstShippableFulfillmentGroup = fulfillmentGroupService.getFirstShippableFulfillmentGroup(cart);
if (firstShippableFulfillmentGroup != null) {
// if the cart has already has fulfillment information
if (firstShippableFulfillmentGroup.getAddress() != null) {
shippingInfoForm.setAddress(firstShippableFulfillmentGroup.getAddress());
} else {
// check for a default address for the customer
CustomerAddress defaultAddress = customerAddressService.findDefaultCustomerAddress(CustomerState.getCustomer().getId());
if (defaultAddress != null) {
shippingInfoForm.setAddress(defaultAddress.getAddress());
shippingInfoForm.setAddressName(defaultAddress.getAddressName());
}
}
FulfillmentOption fulfillmentOption = firstShippableFulfillmentGroup.getFulfillmentOption();
if (fulfillmentOption != null) {
shippingInfoForm.setFulfillmentOption(fulfillmentOption);
shippingInfoForm.setFulfillmentOptionId(fulfillmentOption.getId());
}
}
return shippingInfoForm;
}
use of org.broadleafcommerce.core.order.domain.FulfillmentGroup in project BroadleafCommerce by BroadleafCommerce.
the class FulfillmentGroupServiceImpl method addItemToFulfillmentGroup.
@Override
public // @Transactional("blTransactionManager")
FulfillmentGroup addItemToFulfillmentGroup(FulfillmentGroupItemRequest fulfillmentGroupItemRequest, boolean priceOrder, boolean save) throws PricingException {
if (priceOrder && !save) {
throw new IllegalArgumentException("Pricing requires a save");
}
Order order = fulfillmentGroupItemRequest.getOrder();
OrderItem item = fulfillmentGroupItemRequest.getOrderItem();
FulfillmentGroup fulfillmentGroup = fulfillmentGroupItemRequest.getFulfillmentGroup();
if (order == null) {
if (item.getOrder() != null) {
order = item.getOrder();
} else {
throw new IllegalArgumentException("Order must not be null");
}
}
// 1) Find the order item's existing fulfillment group, if any
for (FulfillmentGroup fg : order.getFulfillmentGroups()) {
Iterator<FulfillmentGroupItem> itr = fg.getFulfillmentGroupItems().iterator();
while (itr.hasNext()) {
FulfillmentGroupItem fgItem = itr.next();
if (fgItem.getOrderItem().equals(item)) {
// 2) remove item from it's existing fulfillment group
itr.remove();
fulfillmentGroupItemDao.delete(fgItem);
}
}
}
if (fulfillmentGroup == null) {
// API user is trying to add an item to a fulfillment group not created
fulfillmentGroup = fulfillmentGroupDao.create();
FulfillmentGroupRequest fgRequest = new FulfillmentGroupRequest();
fgRequest.setOrder(order);
fulfillmentGroup = addFulfillmentGroupToOrder(fgRequest, false);
fulfillmentGroup = save(fulfillmentGroup);
order.getFulfillmentGroups().add(fulfillmentGroup);
}
FulfillmentGroupItem fgi = createFulfillmentGroupItemFromOrderItem(item, fulfillmentGroup, fulfillmentGroupItemRequest.getQuantity());
if (save) {
fgi = fulfillmentGroupItemDao.save(fgi);
}
// 3) add the item to the new fulfillment group
fulfillmentGroup.addFulfillmentGroupItem(fgi);
if (save) {
order = orderService.save(order, priceOrder);
}
return fulfillmentGroup;
}
use of org.broadleafcommerce.core.order.domain.FulfillmentGroup in project BroadleafCommerce by BroadleafCommerce.
the class FulfillmentGroupServiceImpl method getAllShippableFulfillmentGroups.
@Override
public List<FulfillmentGroup> getAllShippableFulfillmentGroups(Order order) {
List<FulfillmentGroup> fulfillmentGroups = order.getFulfillmentGroups();
List<FulfillmentGroup> shippable = new ArrayList<FulfillmentGroup>();
if (fulfillmentGroups != null) {
for (FulfillmentGroup fulfillmentGroup : fulfillmentGroups) {
if (isShippable(fulfillmentGroup.getType())) {
shippable.add(fulfillmentGroup);
}
}
}
return shippable;
}
use of org.broadleafcommerce.core.order.domain.FulfillmentGroup in project BroadleafCommerce by BroadleafCommerce.
the class FulfillmentGroupServiceImpl method removeOrderItemFromFullfillmentGroups.
@Override
@Transactional("blTransactionManager")
public void removeOrderItemFromFullfillmentGroups(Order order, OrderItem orderItem) {
List<FulfillmentGroup> fulfillmentGroups = order.getFulfillmentGroups();
for (FulfillmentGroup fulfillmentGroup : fulfillmentGroups) {
Iterator<FulfillmentGroupItem> itr = fulfillmentGroup.getFulfillmentGroupItems().iterator();
while (itr.hasNext()) {
FulfillmentGroupItem fulfillmentGroupItem = itr.next();
if (fulfillmentGroupItem.getOrderItem().equals(orderItem)) {
itr.remove();
fulfillmentGroupItemDao.delete(fulfillmentGroupItem);
} else if (orderItem instanceof BundleOrderItem) {
BundleOrderItem bundleOrderItem = (BundleOrderItem) orderItem;
for (DiscreteOrderItem discreteOrderItem : bundleOrderItem.getDiscreteOrderItems()) {
if (fulfillmentGroupItem.getOrderItem().equals(discreteOrderItem)) {
itr.remove();
fulfillmentGroupItemDao.delete(fulfillmentGroupItem);
break;
}
}
}
}
}
}
use of org.broadleafcommerce.core.order.domain.FulfillmentGroup in project BroadleafCommerce by BroadleafCommerce.
the class FulfillmentGroupServiceImpl method removeAllFulfillmentGroupsFromOrder.
@Override
@Transactional("blTransactionManager")
public Order 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);
}
order = orderService.save(order, priceOrder);
}
return order;
}
Aggregations