use of org.broadleafcommerce.core.order.domain.DiscreteOrderItem 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.DiscreteOrderItem in project BroadleafCommerce by BroadleafCommerce.
the class FulfillmentGroupServiceImpl method getFulfillmentGroupItemsForOrderItem.
@Override
public List<FulfillmentGroupItem> getFulfillmentGroupItemsForOrderItem(Order order, OrderItem orderItem) {
List<FulfillmentGroupItem> fgis = new ArrayList<FulfillmentGroupItem>();
List<FulfillmentGroup> fulfillmentGroups = order.getFulfillmentGroups();
for (FulfillmentGroup fulfillmentGroup : fulfillmentGroups) {
for (FulfillmentGroupItem fulfillmentGroupItem : fulfillmentGroup.getFulfillmentGroupItems()) {
if (fulfillmentGroupItem.getOrderItem().equals(orderItem)) {
fgis.add(fulfillmentGroupItem);
} else if (orderItem instanceof BundleOrderItem) {
BundleOrderItem bundleOrderItem = (BundleOrderItem) orderItem;
for (DiscreteOrderItem discreteOrderItem : bundleOrderItem.getDiscreteOrderItems()) {
if (fulfillmentGroupItem.getOrderItem().equals(discreteOrderItem)) {
fgis.add(fulfillmentGroupItem);
break;
}
}
}
}
}
return fgis;
}
use of org.broadleafcommerce.core.order.domain.DiscreteOrderItem in project BroadleafCommerce by BroadleafCommerce.
the class FulfillmentGroupServiceImpl method matchFulfillmentGroupsToMultishipOptions.
@Override
@Transactional("blTransactionManager")
public Order matchFulfillmentGroupsToMultishipOptions(Order order, boolean priceOrder) throws PricingException {
List<OrderMultishipOption> multishipOptions = orderMultishipOptionService.findOrderMultishipOptions(order.getId());
// Build map of fulfillmentGroupItemId --> FulfillmentGroupItem.quantity
// Also build map of addressId:fulfillmentOptionId --> FulfillmentGroup
Map<Long, Integer> fgItemQuantityMap = new HashMap<Long, Integer>();
Map<String, FulfillmentGroup> multishipGroups = new HashMap<String, FulfillmentGroup>();
for (FulfillmentGroup fg : order.getFulfillmentGroups()) {
if (!isShippable(fg.getType())) {
continue;
}
String key = getKey(fg.getAddress(), fg.getFulfillmentOption(), fg.getType());
multishipGroups.put(key, fg);
for (FulfillmentGroupItem fgi : fg.getFulfillmentGroupItems()) {
fgItemQuantityMap.put(fgi.getId(), fgi.getQuantity());
}
}
for (OrderMultishipOption option : multishipOptions) {
String key = getKey(option.getAddress(), option.getFulfillmentOption(), ((DiscreteOrderItem) option.getOrderItem()).getSku().getFulfillmentType());
FulfillmentGroup fg = multishipGroups.get(key);
// Get or create a fulfillment group that matches this OrderMultishipOption destination
if (fg == null) {
FulfillmentGroupRequest fgr = new FulfillmentGroupRequest();
fgr.setOrder(order);
if (option.getAddress() != null) {
fgr.setAddress(option.getAddress());
}
if (option.getFulfillmentOption() != null) {
fgr.setOption(option.getFulfillmentOption());
}
fgr.setFulfillmentType(((DiscreteOrderItem) option.getOrderItem()).getSku().getFulfillmentType());
fg = addFulfillmentGroupToOrder(fgr, false);
fg = save(fg);
order.getFulfillmentGroups().add(fg);
}
// See if there is a fulfillment group item that matches this OrderMultishipOption
// OrderItem request
FulfillmentGroupItem fulfillmentGroupItem = null;
for (FulfillmentGroupItem fgi : fg.getFulfillmentGroupItems()) {
if (fgi.getOrderItem().getId().equals(option.getOrderItem().getId())) {
fulfillmentGroupItem = fgi;
}
}
// If there is no matching fulfillment group item, create a new one with quantity 1
if (fulfillmentGroupItem == null) {
fulfillmentGroupItem = fulfillmentGroupItemDao.create();
fulfillmentGroupItem.setFulfillmentGroup(fg);
fulfillmentGroupItem.setOrderItem(option.getOrderItem());
fulfillmentGroupItem.setQuantity(1);
fulfillmentGroupItem = fulfillmentGroupItemDao.save(fulfillmentGroupItem);
fg.getFulfillmentGroupItems().add(fulfillmentGroupItem);
} else {
// (fulfillmentGroupItem.getId() == null)
if (fulfillmentGroupItem.getId() != null) {
Integer qty = fgItemQuantityMap.get(fulfillmentGroupItem.getId());
if (qty == null || qty == 0) {
fulfillmentGroupItem.setQuantity(fulfillmentGroupItem.getQuantity() + 1);
} else {
qty -= 1;
fgItemQuantityMap.put(fulfillmentGroupItem.getId(), qty);
}
} else {
fulfillmentGroupItem.setQuantity(fulfillmentGroupItem.getQuantity() + 1);
}
}
multishipGroups.put(key, fg);
}
// Furthermore, delete the empty fulfillment groups.
for (Entry<Long, Integer> entry : fgItemQuantityMap.entrySet()) {
if (entry.getValue() > 0) {
FulfillmentGroupItem fgi = fulfillmentGroupItemDao.readFulfillmentGroupItemById(entry.getKey());
if (fgi.getQuantity() == entry.getValue()) {
FulfillmentGroup fg = fgi.getFulfillmentGroup();
fg.getFulfillmentGroupItems().remove(fgi);
fulfillmentGroupItemDao.delete(fgi);
if (fg.getFulfillmentGroupItems().size() == 0) {
order.getFulfillmentGroups().remove(fg);
fulfillmentGroupDao.delete(fg);
}
} else {
fgi.setQuantity(fgi.getQuantity() - entry.getValue());
fulfillmentGroupItemDao.save(fgi);
}
}
}
return orderService.save(order, priceOrder);
}
use of org.broadleafcommerce.core.order.domain.DiscreteOrderItem in project BroadleafCommerce by BroadleafCommerce.
the class MergeCartServiceImpl method reconstructCart.
@Override
public ReconstructCartResponse reconstructCart(Customer customer, boolean priceOrder) throws PricingException, RemoveFromCartException {
ReconstructCartResponse reconstructCartResponse = new ReconstructCartResponse();
Order customerCart = orderService.findCartForCustomerWithEnhancements(customer);
if (customerCart != null) {
List<OrderItem> itemsToRemove = new ArrayList<OrderItem>();
for (OrderItem orderItem : customerCart.getOrderItems()) {
if (orderItem instanceof DiscreteOrderItem) {
DiscreteOrderItem doi = (DiscreteOrderItem) orderItem;
if (!checkActive(doi) || !checkInventory(doi) || !checkOtherValidity(orderItem)) {
itemsToRemove.add(orderItem);
}
} else if (orderItem instanceof BundleOrderItem) {
BundleOrderItem bundleOrderItem = (BundleOrderItem) orderItem;
for (DiscreteOrderItem doi : bundleOrderItem.getDiscreteOrderItems()) {
if (!checkActive(doi) || !checkInventory(doi) || !checkOtherValidity(orderItem)) {
itemsToRemove.add(doi.getBundleOrderItem());
}
}
}
}
// Remove any giftwrap items who have one or more wrapped item members that have been removed
for (OrderItem orderItem : customerCart.getOrderItems()) {
if (orderItem instanceof GiftWrapOrderItem) {
for (OrderItem wrappedItem : ((GiftWrapOrderItem) orderItem).getWrappedItems()) {
if (itemsToRemove.contains(wrappedItem)) {
itemsToRemove.add(orderItem);
break;
}
}
}
}
for (OrderItem item : itemsToRemove) {
orderService.removeItem(customerCart.getId(), item.getId(), false);
}
reconstructCartResponse.setRemovedItems(itemsToRemove);
customerCart = orderService.save(customerCart, priceOrder);
}
reconstructCartResponse.setOrder(customerCart);
return reconstructCartResponse;
}
use of org.broadleafcommerce.core.order.domain.DiscreteOrderItem in project BroadleafCommerce by BroadleafCommerce.
the class OrderItemServiceImpl method createDiscreteOrderItem.
@Override
public DiscreteOrderItem createDiscreteOrderItem(final DiscreteOrderItemRequest itemRequest) {
final DiscreteOrderItem item = (DiscreteOrderItem) orderItemDao.create(OrderItemType.DISCRETE);
populateDiscreteOrderItem(item, itemRequest);
item.setBundleOrderItem(itemRequest.getBundleOrderItem());
if (itemRequest.getSalePriceOverride() != null) {
item.setBaseSalePrice(itemRequest.getSalePriceOverride());
}
item.setDiscreteOrderItemFeePrices(itemRequest.getDiscreteOrderItemFeePrices());
if (itemRequest.getSalePriceOverride() != null) {
item.setSalePriceOverride(Boolean.TRUE);
item.setSalePrice(itemRequest.getSalePriceOverride());
item.setBaseSalePrice(itemRequest.getSalePriceOverride());
}
if (itemRequest.getRetailPriceOverride() != null) {
item.setRetailPriceOverride(Boolean.TRUE);
item.setRetailPrice(itemRequest.getRetailPriceOverride());
item.setBaseRetailPrice(itemRequest.getRetailPriceOverride());
}
for (DiscreteOrderItemFeePrice feePrice : item.getDiscreteOrderItemFeePrices()) {
feePrice.setDiscreteOrderItem(item);
}
if (MapUtils.isNotEmpty(itemRequest.getAdditionalAttributes())) {
item.setAdditionalAttributes(itemRequest.getAdditionalAttributes());
}
item.setPersonalMessage(itemRequest.getPersonalMessage());
applyAdditionalOrderItemProperties(item);
return item;
}
Aggregations