use of org.broadleafcommerce.core.order.domain.GiftWrapOrderItem in project BroadleafCommerce by BroadleafCommerce.
the class OfferServiceTest method testOrderItemOfferWithGiftWrap.
@Test(groups = { "testOffersWithGiftWrap" }, dependsOnGroups = { "testShippingInsert" })
@Transactional
public void testOrderItemOfferWithGiftWrap() throws PricingException {
Order order = createTestOrderWithOfferAndGiftWrap();
OfferDataItemProvider dataProvider = new OfferDataItemProvider();
List<Offer> offers = dataProvider.createItemBasedOfferWithItemCriteria("order.subTotal.getAmount()>20", OfferDiscountType.PERCENT_OFF, "([MVEL.eval(\"toUpperCase()\",\"Test Sku\")] contains MVEL.eval(\"toUpperCase()\", discreteOrderItem.sku.name))", "([MVEL.eval(\"toUpperCase()\",\"Test Sku\")] contains MVEL.eval(\"toUpperCase()\", discreteOrderItem.sku.name))");
for (Offer offer : offers) {
offer.setName("testOffer");
// //reset the offer is the targets and qualifiers, otherwise the reference is incorrect
// for (OfferItemCriteria criteria : offer.getTargetItemCriteria()) {
// criteria.setTargetOffer(null);
// }
// for (OfferItemCriteria criteria : offer.getQualifyingItemCriteria()) {
// criteria.setQualifyingOffer(null);
// }
offerService.save(offer);
}
order = orderService.save(order, false);
Set<OrderMultishipOption> options = new HashSet<OrderMultishipOption>();
for (FulfillmentGroup fg : order.getFulfillmentGroups()) {
Address address = fg.getAddress();
for (FulfillmentGroupItem fgItem : fg.getFulfillmentGroupItems()) {
for (int j = 0; j < fgItem.getQuantity(); j++) {
OrderMultishipOption option = new OrderMultishipOptionImpl();
option.setOrder(order);
option.setAddress(address);
option.setOrderItem(fgItem.getOrderItem());
option.setFulfillmentOption(fg.getFulfillmentOption());
options.add(option);
}
}
}
for (OrderMultishipOption option : options) {
orderMultishipOptionService.save(option);
}
order = fulfillmentGroupService.matchFulfillmentGroupsToMultishipOptions(order, true);
assert order.getOrderItems().size() == 3;
assert order.getTotalTax().equals(new Money("2.00"));
assert order.getTotalShipping().equals(new Money("8.50"));
assert order.getSubTotal().equals(new Money("40.00"));
assert order.getTotal().equals(new Money("50.50"));
boolean foundGiftItemAndCorrectQuantity = false;
for (OrderItem orderItem : order.getOrderItems()) {
if (orderItem instanceof GiftWrapOrderItem && ((GiftWrapOrderItem) orderItem).getWrappedItems().size() == 1) {
foundGiftItemAndCorrectQuantity = true;
break;
}
}
assert foundGiftItemAndCorrectQuantity;
}
use of org.broadleafcommerce.core.order.domain.GiftWrapOrderItem in project BroadleafCommerce by BroadleafCommerce.
the class OrderServiceImpl method addGiftWrapItemToOrder.
@Override
@Transactional("blTransactionManager")
public OrderItem addGiftWrapItemToOrder(Order order, GiftWrapOrderItemRequest itemRequest, boolean priceOrder) throws PricingException {
GiftWrapOrderItem item = orderItemService.createGiftWrapOrderItem(itemRequest);
item.setOrder(order);
item = (GiftWrapOrderItem) orderItemService.saveOrderItem(item);
order.getOrderItems().add(item);
order = save(order, priceOrder);
return item;
}
use of org.broadleafcommerce.core.order.domain.GiftWrapOrderItem in project BroadleafCommerce by BroadleafCommerce.
the class LegacyMergeCartServiceImpl method removeExpiredGiftWrapOrderItems.
protected Order removeExpiredGiftWrapOrderItems(MergeCartResponse mergeCartResponse, Order customerCart, Map<OrderItem, OrderItem> oldNewItemMap) throws PricingException {
// clear out any Gift Wrap items that contain one or more removed wrapped items
Iterator<OrderItem> addedItems = mergeCartResponse.getAddedItems().iterator();
while (addedItems.hasNext()) {
OrderItem addedItem = addedItems.next();
if (addedItem instanceof GiftWrapOrderItem) {
GiftWrapOrderItem giftWrapOrderItem = (GiftWrapOrderItem) addedItem;
boolean removeItem = false;
for (OrderItem wrappedItem : giftWrapOrderItem.getWrappedItems()) {
if (mergeCartResponse.getRemovedItems().contains(wrappedItem)) {
removeItem = true;
break;
}
}
if (removeItem) {
for (OrderItem wrappedItem : giftWrapOrderItem.getWrappedItems()) {
wrappedItem.setGiftWrapOrderItem(null);
}
giftWrapOrderItem.getWrappedItems().clear();
for (OrderItem cartItem : customerCart.getOrderItems()) {
if (cartItem.getGiftWrapOrderItem() != null && oldNewItemMap.containsKey(cartItem.getGiftWrapOrderItem())) {
cartItem.setGiftWrapOrderItem(null);
}
}
customerCart = removeItemFromOrder(customerCart, giftWrapOrderItem, false);
addedItems.remove();
mergeCartResponse.getRemovedItems().add(giftWrapOrderItem);
}
}
}
return customerCart;
}
use of org.broadleafcommerce.core.order.domain.GiftWrapOrderItem in project BroadleafCommerce by BroadleafCommerce.
the class LegacyMergeCartServiceImpl method reconstructCart.
@Override
public ReconstructCartResponse reconstructCart(Customer customer, boolean priceOrder) throws PricingException {
ReconstructCartResponse reconstructCartResponse = new ReconstructCartResponse();
Order customerCart = orderService.findCartForCustomer(customer);
if (customerCart != null) {
List<OrderItem> itemsToRemove = new ArrayList<OrderItem>();
for (OrderItem orderItem : customerCart.getOrderItems()) {
if (orderItem instanceof DiscreteOrderItem) {
DiscreteOrderItem discreteOrderItem = (DiscreteOrderItem) orderItem;
if (discreteOrderItem.getSku().getActiveStartDate() != null) {
if (!discreteOrderItem.getSku().isActive(discreteOrderItem.getProduct(), orderItem.getCategory())) {
itemsToRemove.add(orderItem);
}
} else {
if (!discreteOrderItem.getProduct().isActive() || !orderItem.getCategory().isActive()) {
itemsToRemove.add(orderItem);
}
}
} else if (orderItem instanceof BundleOrderItem) {
BundleOrderItem bundleOrderItem = (BundleOrderItem) orderItem;
boolean removeBundle = false;
for (DiscreteOrderItem discreteOrderItem : bundleOrderItem.getDiscreteOrderItems()) {
if (discreteOrderItem.getSku().getActiveStartDate() != null) {
if (!discreteOrderItem.getSku().isActive(discreteOrderItem.getProduct(), orderItem.getCategory())) {
/*
* Bundle has an inactive item in it -- remove the
* whole bundle
*/
removeBundle = true;
break;
}
} else {
if (!discreteOrderItem.getProduct().isActive() || !orderItem.getCategory().isActive()) {
removeBundle = true;
break;
}
}
}
if (removeBundle) {
itemsToRemove.add(orderItem);
}
}
}
// 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) {
removeItemFromOrder(customerCart, item, priceOrder);
}
reconstructCartResponse.setRemovedItems(itemsToRemove);
}
reconstructCartResponse.setOrder(customerCart);
return reconstructCartResponse;
}
use of org.broadleafcommerce.core.order.domain.GiftWrapOrderItem in project BroadleafCommerce by BroadleafCommerce.
the class OrderItemServiceImpl method createGiftWrapOrderItem.
@Override
public GiftWrapOrderItem createGiftWrapOrderItem(final GiftWrapOrderItemRequest itemRequest) {
final GiftWrapOrderItem item = (GiftWrapOrderItem) orderItemDao.create(OrderItemType.GIFTWRAP);
item.setSku(itemRequest.getSku());
item.setOrder(itemRequest.getOrder());
item.setBundleOrderItem(itemRequest.getBundleOrderItem());
item.setQuantity(itemRequest.getQuantity());
item.setCategory(itemRequest.getCategory());
item.setProduct(itemRequest.getProduct());
item.setBaseSalePrice(itemRequest.getSku().getSalePrice());
item.setBaseRetailPrice(itemRequest.getSku().getRetailPrice());
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());
}
// item.updatePrices();
item.updateSaleAndRetailPrices();
item.assignFinalPrice();
item.getWrappedItems().addAll(itemRequest.getWrappedItems());
for (OrderItem orderItem : item.getWrappedItems()) {
orderItem.setGiftWrapOrderItem(item);
}
applyAdditionalOrderItemProperties(item);
return item;
}
Aggregations