Search in sources :

Example 1 with OrderMultishipOption

use of org.broadleafcommerce.core.order.domain.OrderMultishipOption in project BroadleafCommerce by BroadleafCommerce.

the class OfferServiceTest method testApplyOffersToOrder_Items.

public void testApplyOffersToOrder_Items() throws Exception {
    final ThreadLocal<Order> myOrder = new ThreadLocal<>();
    EasyMock.expect(offerDaoMock.createOrderItemPriceDetailAdjustment()).andAnswer(OfferDataItemProvider.getCreateOrderItemPriceDetailAdjustmentAnswer()).anyTimes();
    CandidateItemOfferAnswer answer = new CandidateItemOfferAnswer();
    OrderItemAdjustmentAnswer answer2 = new OrderItemAdjustmentAnswer();
    OrderItemPriceDetailAnswer orderItemPriceDetailAnswer = new OrderItemPriceDetailAnswer();
    EasyMock.expect(orderItemDaoMock.createOrderItemPriceDetail()).andAnswer(orderItemPriceDetailAnswer).atLeastOnce();
    OrderItemQualifierAnswer orderItemQualifierAnswer = new OrderItemQualifierAnswer();
    EasyMock.expect(orderItemDaoMock.createOrderItemQualifier()).andAnswer(orderItemQualifierAnswer).atLeastOnce();
    EasyMock.expect(orderServiceMock.getAutomaticallyMergeLikeItems()).andReturn(true).anyTimes();
    EasyMock.expect(orderServiceMock.save(EasyMock.isA(Order.class), EasyMock.isA(Boolean.class))).andAnswer(OfferDataItemProvider.getSaveOrderAnswer()).anyTimes();
    EasyMock.expect(orderItemServiceMock.saveOrderItem(EasyMock.isA(OrderItem.class))).andAnswer(OfferDataItemProvider.getSaveOrderItemAnswer()).anyTimes();
    EasyMock.expect(fgItemDaoMock.save(EasyMock.isA(FulfillmentGroupItem.class))).andAnswer(OfferDataItemProvider.getSaveFulfillmentGroupItemAnswer()).anyTimes();
    EasyMock.expect(fgServiceMock.addItemToFulfillmentGroup(EasyMock.isA(FulfillmentGroupItemRequest.class), EasyMock.eq(false))).andAnswer(OfferDataItemProvider.getAddItemToFulfillmentGroupAnswer()).anyTimes();
    EasyMock.expect(orderServiceMock.removeItem(EasyMock.isA(Long.class), EasyMock.isA(Long.class), EasyMock.eq(false))).andAnswer(OfferDataItemProvider.getRemoveItemFromOrderAnswer()).anyTimes();
    EasyMock.expect(multishipOptionServiceMock.findOrderMultishipOptions(EasyMock.isA(Long.class))).andAnswer(new IAnswer<List<OrderMultishipOption>>() {

        @Override
        public List<OrderMultishipOption> answer() throws Throwable {
            return new ArrayList<>();
        }
    }).anyTimes();
    EasyMock.expect(orderServiceMock.findOrderById(EasyMock.isA(Long.class))).andAnswer(new IAnswer<Order>() {

        @Override
        public Order answer() throws Throwable {
            return myOrder.get();
        }
    }).anyTimes();
    multishipOptionServiceMock.deleteAllOrderMultishipOptions(EasyMock.isA(Order.class));
    EasyMock.expectLastCall().anyTimes();
    EasyMock.expect(fgServiceMock.collapseToOneShippableFulfillmentGroup(EasyMock.isA(Order.class), EasyMock.eq(false))).andAnswer(OfferDataItemProvider.getSameOrderAnswer()).anyTimes();
    EasyMock.expect(fgItemDaoMock.create()).andAnswer(OfferDataItemProvider.getCreateFulfillmentGroupItemAnswer()).anyTimes();
    fgItemDaoMock.delete(EasyMock.isA(FulfillmentGroupItem.class));
    EasyMock.expectLastCall().anyTimes();
    EasyMock.expect(offerTimeZoneProcessorMock.getTimeZone(EasyMock.isA(OfferImpl.class))).andReturn(TimeZone.getTimeZone("CST")).anyTimes();
    replay();
    Order order = dataProvider.createBasicPromotableOrder().getOrder();
    myOrder.set(order);
    List<Offer> offers = dataProvider.createItemBasedOfferWithItemCriteria("order.subTotal.getAmount()>20", OfferDiscountType.PERCENT_OFF, "([MVEL.eval(\"toUpperCase()\",\"test1\"), MVEL.eval(\"toUpperCase()\",\"test2\")] contains MVEL.eval(\"toUpperCase()\", discreteOrderItem.category.name))", "([MVEL.eval(\"toUpperCase()\",\"test1\"), MVEL.eval(\"toUpperCase()\",\"test2\")] contains MVEL.eval(\"toUpperCase()\", discreteOrderItem.category.name))");
    offerService.applyAndSaveOffersToOrder(offers, order);
    int adjustmentCount = countItemAdjustments(order);
    assertTrue(adjustmentCount == 2);
    order = dataProvider.createBasicPromotableOrder().getOrder();
    myOrder.set(order);
    offers = dataProvider.createItemBasedOfferWithItemCriteria("order.subTotal.getAmount()>20", OfferDiscountType.PERCENT_OFF, "([MVEL.eval(\"toUpperCase()\",\"test1\"), MVEL.eval(\"toUpperCase()\",\"test2\")] contains MVEL.eval(\"toUpperCase()\", discreteOrderItem.category.name))", "([MVEL.eval(\"toUpperCase()\",\"test5\"), MVEL.eval(\"toUpperCase()\",\"test6\")] contains MVEL.eval(\"toUpperCase()\", discreteOrderItem.category.name))");
    offerService.applyAndSaveOffersToOrder(offers, order);
    adjustmentCount = countItemAdjustments(order);
    // Qualifiers are there, but the targets are not, so no adjustments
    assertTrue(adjustmentCount == 0);
    verify();
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) ArrayList(java.util.ArrayList) IAnswer(org.easymock.IAnswer) CandidateItemOffer(org.broadleafcommerce.core.offer.domain.CandidateItemOffer) Offer(org.broadleafcommerce.core.offer.domain.Offer) CandidateOrderOffer(org.broadleafcommerce.core.offer.domain.CandidateOrderOffer) CustomerOffer(org.broadleafcommerce.core.offer.domain.CustomerOffer) FulfillmentGroupItem(org.broadleafcommerce.core.order.domain.FulfillmentGroupItem) OrderMultishipOption(org.broadleafcommerce.core.order.domain.OrderMultishipOption)

Example 2 with OrderMultishipOption

use of org.broadleafcommerce.core.order.domain.OrderMultishipOption 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;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) Address(org.broadleafcommerce.profile.core.domain.Address) OrderMultishipOptionImpl(org.broadleafcommerce.core.order.domain.OrderMultishipOptionImpl) Money(org.broadleafcommerce.common.money.Money) Offer(org.broadleafcommerce.core.offer.domain.Offer) FulfillmentGroupItem(org.broadleafcommerce.core.order.domain.FulfillmentGroupItem) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) GiftWrapOrderItem(org.broadleafcommerce.core.order.domain.GiftWrapOrderItem) OrderMultishipOption(org.broadleafcommerce.core.order.domain.OrderMultishipOption) GiftWrapOrderItem(org.broadleafcommerce.core.order.domain.GiftWrapOrderItem) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup) HashSet(java.util.HashSet) Test(org.testng.annotations.Test) CommonSetupBaseTest(org.broadleafcommerce.test.CommonSetupBaseTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with OrderMultishipOption

use of org.broadleafcommerce.core.order.domain.OrderMultishipOption in project BroadleafCommerce by BroadleafCommerce.

the class OrderMultishipOptionServiceImpl method createPopulatedOrderMultishipOption.

protected List<OrderMultishipOption> createPopulatedOrderMultishipOption(Order order, DiscreteOrderItem item, Integer quantity) {
    List<OrderMultishipOption> orderMultishipOptions = new ArrayList<OrderMultishipOption>();
    if (!fulfillmentGroupService.isShippable(item.getSku().getFulfillmentType()) || quantity == 0) {
        return orderMultishipOptions;
    }
    // for (int i = 0; i < quantity; i++) {
    OrderMultishipOption orderMultishipOption = new OrderMultishipOptionImpl();
    orderMultishipOption.setOrder(order);
    orderMultishipOption.setOrderItem(item);
    orderMultishipOptions.add(orderMultishipOption);
    // }
    return orderMultishipOptions;
}
Also used : OrderMultishipOptionImpl(org.broadleafcommerce.core.order.domain.OrderMultishipOptionImpl) ArrayList(java.util.ArrayList) OrderMultishipOption(org.broadleafcommerce.core.order.domain.OrderMultishipOption)

Example 4 with OrderMultishipOption

use of org.broadleafcommerce.core.order.domain.OrderMultishipOption in project BroadleafCommerce by BroadleafCommerce.

the class OrderMultishipOptionServiceImpl method saveOrderMultishipOptions.

@Override
public void saveOrderMultishipOptions(Order order, List<OrderMultishipOptionDTO> optionDTOs) {
    Map<Long, OrderMultishipOption> currentOptions = new HashMap<Long, OrderMultishipOption>();
    for (OrderMultishipOption option : findOrderMultishipOptions(order.getId())) {
        currentOptions.put(option.getId(), option);
    }
    List<OrderMultishipOption> orderMultishipOptions = new ArrayList<OrderMultishipOption>();
    for (OrderMultishipOptionDTO dto : optionDTOs) {
        OrderMultishipOption option = currentOptions.get(dto.getId());
        if (option == null) {
            option = orderMultishipOptionDao.create();
        }
        option.setOrder(order);
        option.setOrderItem(orderItemService.readOrderItemById(dto.getOrderItemId()));
        if (dto.getAddressId() != null) {
            option.setAddress(addressService.readAddressById(dto.getAddressId()));
        } else {
            option.setAddress(null);
        }
        if (dto.getFulfillmentOptionId() != null) {
            option.setFulfillmentOption(fulfillmentOptionService.readFulfillmentOptionById(dto.getFulfillmentOptionId()));
        } else {
            option.setFulfillmentOption(null);
        }
        orderMultishipOptions.add(option);
    }
    for (OrderMultishipOption option : orderMultishipOptions) {
        save(option);
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) OrderMultishipOption(org.broadleafcommerce.core.order.domain.OrderMultishipOption) OrderMultishipOptionDTO(org.broadleafcommerce.core.order.service.call.OrderMultishipOptionDTO)

Example 5 with OrderMultishipOption

use of org.broadleafcommerce.core.order.domain.OrderMultishipOption in project BroadleafCommerce by BroadleafCommerce.

the class OrderMultishipOptionServiceImpl method getOrGenerateOrderMultishipOptions.

@Override
public List<OrderMultishipOption> getOrGenerateOrderMultishipOptions(Order order) {
    List<OrderMultishipOption> orderMultishipOptions = findOrderMultishipOptions(order.getId());
    if (orderMultishipOptions == null || orderMultishipOptions.size() == 0) {
        orderMultishipOptions = generateOrderMultishipOptions(order);
    }
    // Create a map representing the current discrete order item counts for the order
    Map<Long, Integer> orderDiscreteOrderItemCounts = new HashMap<Long, Integer>();
    for (DiscreteOrderItem item : order.getDiscreteOrderItems()) {
        orderDiscreteOrderItemCounts.put(item.getId(), item.getQuantity());
    }
    List<OrderMultishipOption> optionsToRemove = new ArrayList<OrderMultishipOption>();
    for (OrderMultishipOption option : orderMultishipOptions) {
        Integer count = orderDiscreteOrderItemCounts.get(option.getOrderItem().getId());
        if (count == null || count == 0) {
            optionsToRemove.add(option);
        } else {
            count--;
            orderDiscreteOrderItemCounts.put(option.getOrderItem().getId(), count);
        }
    }
    for (Entry<Long, Integer> entry : orderDiscreteOrderItemCounts.entrySet()) {
        DiscreteOrderItem item = (DiscreteOrderItem) orderItemService.readOrderItemById(entry.getKey());
        orderMultishipOptions.addAll(createPopulatedOrderMultishipOption(order, item, entry.getValue()));
    }
    orderMultishipOptions.removeAll(optionsToRemove);
    orderMultishipOptionDao.deleteAll(optionsToRemove);
    return orderMultishipOptions;
}
Also used : DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) OrderMultishipOption(org.broadleafcommerce.core.order.domain.OrderMultishipOption)

Aggregations

OrderMultishipOption (org.broadleafcommerce.core.order.domain.OrderMultishipOption)9 ArrayList (java.util.ArrayList)7 FulfillmentGroupItem (org.broadleafcommerce.core.order.domain.FulfillmentGroupItem)5 Offer (org.broadleafcommerce.core.offer.domain.Offer)4 Order (org.broadleafcommerce.core.order.domain.Order)4 OrderMultishipOptionImpl (org.broadleafcommerce.core.order.domain.OrderMultishipOptionImpl)4 HashMap (java.util.HashMap)3 CandidateItemOffer (org.broadleafcommerce.core.offer.domain.CandidateItemOffer)3 DiscreteOrderItem (org.broadleafcommerce.core.order.domain.DiscreteOrderItem)3 FulfillmentGroup (org.broadleafcommerce.core.order.domain.FulfillmentGroup)3 IAnswer (org.easymock.IAnswer)3 BigDecimal (java.math.BigDecimal)2 Money (org.broadleafcommerce.common.money.Money)2 CandidateOrderOffer (org.broadleafcommerce.core.offer.domain.CandidateOrderOffer)2 CustomerOffer (org.broadleafcommerce.core.offer.domain.CustomerOffer)2 OrderItem (org.broadleafcommerce.core.order.domain.OrderItem)2 OrderMultishipOptionDTO (org.broadleafcommerce.core.order.service.call.OrderMultishipOptionDTO)2 Address (org.broadleafcommerce.profile.core.domain.Address)2 Transactional (org.springframework.transaction.annotation.Transactional)2 HashSet (java.util.HashSet)1