protected FulfillmentGroup addItemToFulfillmentGroup(Order order, OrderItem orderItem, int quantity, FulfillmentGroup fulfillmentGroup) throws PricingException { FulfillmentGroupItemRequest fulfillmentGroupItemRequest = new FulfillmentGroupItemRequest(); fulfillmentGroupItemRequest.setOrder(order); fulfillmentGroupItemRequest.setOrderItem(orderItem); fulfillmentGroupItemRequest.setQuantity(quantity); fulfillmentGroupItemRequest.setFulfillmentGroup(fulfillmentGroup); return fulfillmentGroupService.addItemToFulfillmentGroup(fulfillmentGroupItemRequest, false, false); }
@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); } } }
/** * Converts the order to single ship by collapsing all of the shippable fulfillment groups into the default (first) * shippable fulfillment group. Allows modules to add module specific shipping logic. * * @param request * @param response * @param model * @return a redirect to /checkout * @throws org.broadleafcommerce.core.pricing.service.exception.PricingException */ public String convertToSingleship(HttpServletRequest request, HttpServletResponse response, Model model) throws PricingException { Order cart = CartState.getCart(); fulfillmentGroupService.collapseToOneShippableFulfillmentGroup(cart, true); //Add module specific logic checkoutControllerExtensionManager.getProxy().performAdditionalShippingAction(); return getCheckoutPageRedirect(); }
EasyMock.expect(offerDaoMock.createOrderItemPriceDetailAdjustment()).andAnswer(OfferDataItemProvider.getCreateOrderItemPriceDetailAdjustmentAnswer()).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(orderServiceMock.save(EasyMock.isA(Order.class), EasyMock.isA(Boolean.class))).andAnswer(OfferDataItemProvider.getSaveOrderAnswer()).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));
fulfillmentGroupItemRequest.setOrder(orderEntity); fulfillmentGroupItemRequest.setOrderItem(orderItem); fulfillmentGroup = fulfillmentGroupService.addItemToFulfillmentGroup(fulfillmentGroupItemRequest, false); fulfillmentGroupService.save(fulfillmentGroup); orderService.save(orderEntity, true);
/** * This method will copy the shipping address of the first fulfillment group on the order * to the billing address on the PaymentInfoForm that is passed in. */ protected void copyShippingAddressToBillingAddress(Order order, PaymentInfoForm paymentInfoForm) { if (fulfillmentGroupService.getFirstShippableFulfillmentGroup(order) != null) { Address shipping = fulfillmentGroupService.getFirstShippableFulfillmentGroup(order).getAddress(); if (shipping != null) { Address billing = addressService.copyAddress(shipping) ; paymentInfoForm.setAddress(billing); } } }
public String saveMultiShipInstruction(HttpServletRequest request, HttpServletResponse response, Model model, MultiShipInstructionForm instructionForm) throws ServiceException, PricingException { Order cart = CartState.getCart(); FulfillmentGroup fulfillmentGroup = null; for (FulfillmentGroup tempFulfillmentGroup : cart.getFulfillmentGroups()) { if (tempFulfillmentGroup.getId().equals(instructionForm.getFulfillmentGroupId())) { fulfillmentGroup = tempFulfillmentGroup; } } fulfillmentGroup.setPersonalMessage(instructionForm.getPersonalMessage()); fulfillmentGroup.setDeliveryInstruction(instructionForm.getDeliveryMessage()); fulfillmentGroupService.save(fulfillmentGroup); //append current time to redirect to fix a problem with ajax caching in IE return getCheckoutPageRedirect()+ "?_=" + System.currentTimeMillis(); }
if (SkuFeeType.FULFILLMENT.equals(fee.getFeeType())) { if (shouldApplyFeeToFulfillmentGroup(fee, fulfillmentGroup)) { FulfillmentGroupFee fulfillmentFee = fulfillmentGroupService.createFulfillmentGroupFee(); fulfillmentFee.setName(fee.getName()); fulfillmentFee.setTaxable(fee.getTaxable()); fulfillmentGroup = fulfillmentGroupService.save(fulfillmentGroup);
fulfillmentGroup = fulfillmentGroupService.createEmptyFulfillmentGroup(); fulfillmentGroup = fulfillmentGroupService.createEmptyFulfillmentGroup(); FulfillmentGroup fulfillmentGroup = nullFulfillmentTypeGroup; if (fulfillmentGroup == null) { fulfillmentGroup = fulfillmentGroupService.createEmptyFulfillmentGroup(); fulfillmentGroup.setOrder(order); order.getFulfillmentGroups().add(fulfillmentGroup);
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; } }
/** * Processes the given options for multiship. Validates that all options are * selected before performing any actions. Allows modules to add module specific shipping logic. * * @see #showMultiship(HttpServletRequest, HttpServletResponse, Model) * * @param request * @param response * @param model * @param orderMultishipOptionForm * @return a redirect to the checkout page * @throws PricingException * @throws ServiceException */ public String saveMultiship(HttpServletRequest request, HttpServletResponse response, Model model, OrderMultishipOptionForm orderMultishipOptionForm, BindingResult result) throws PricingException, ServiceException { Order cart = CartState.getCart(); orderMultishipOptionService.saveOrderMultishipOptions(cart, orderMultishipOptionForm.getOptions()); cart = fulfillmentGroupService.matchFulfillmentGroupsToMultishipOptions(cart, true); //Add module specific logic checkoutControllerExtensionManager.getProxy().performAdditionalShippingAction(); return getMultishipSuccessView(); }
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(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));
fulfillmentGroupItemRequest.setOrderItem(orderItemEntity); return fulfillmentGroupService.addItemToFulfillmentGroup(fulfillmentGroupItemRequest, true); }).onFailure((e) -> {throw new ResourceNotFoundException();}); }); fulfillmentGroupService.save(updatedFulfillmentGroupEntity); Try.ofFailable(() -> orderService.save(orderEntity, true)).onFailure(ex -> log.error("Error saving object", ex));
/** * A helper method to retrieve all fulfillment options for the cart and estimate the cost of applying * fulfillment options on the first shippable fulfillment group. * */ protected void populateFulfillmentOptionsAndEstimationOnModel(Map<String, Object> localVars) { List<FulfillmentOption> fulfillmentOptions = fulfillmentOptionService.readAllFulfillmentOptions(); Order cart = CartState.getCart(); if (!(cart instanceof NullOrderImpl) && cart.getFulfillmentGroups().size() > 0 && hasPopulatedShippingAddress(cart)) { Set<FulfillmentOption> options = new HashSet<>(); options.addAll(fulfillmentOptions); FulfillmentEstimationResponse estimateResponse = null; try { estimateResponse = fulfillmentPricingService.estimateCostForFulfillmentGroup(fulfillmentGroupService.getFirstShippableFulfillmentGroup(cart), options); } catch (FulfillmentPriceException e) { } localVars.put("estimateResponse", estimateResponse); } localVars.put("fulfillmentOptions", fulfillmentOptions); }
@Test(groups = "createFulfillmentGroup", dataProvider = "basicFulfillmentGroup", dataProviderClass = FulfillmentGroupDataProvider.class) @Transactional @Rollback(false) public void createFulfillmentGroup(FulfillmentGroup fulfillmentGroup) { Customer customer = createCustomerWithBasicOrderAndAddresses(); Address address = (customerAddressDao.readActiveCustomerAddressesByCustomerId(customer.getId())).get(0).getAddress(); Order salesOrder = orderDao.readOrdersForCustomer(customer.getId()).get(0); FulfillmentGroup newFG = fulfillmentGroupDao.create(); newFG.setAddress(address); newFG.setRetailShippingPrice(fulfillmentGroup.getRetailShippingPrice()); newFG.setMethod(fulfillmentGroup.getMethod()); newFG.setService(fulfillmentGroup.getService()); newFG.setReferenceNumber(fulfillmentGroup.getReferenceNumber()); newFG.setOrder(salesOrder); assert newFG.getId() == null; fulfillmentGroup = fulfillmentGroupService.save(newFG); assert fulfillmentGroup.getId() != null; fulfillmentGroupId = fulfillmentGroup.getId(); }
@Override public FulfillmentGroup createDefaultFulfillmentGroup(Order order, Address address) { for (FulfillmentGroup fulfillmentGroup : order.getFulfillmentGroups()) { if (fulfillmentGroup.isPrimary()) { return fulfillmentGroup; } } FulfillmentGroup newFg = fulfillmentGroupService.createEmptyFulfillmentGroup(); newFg.setOrder(order); newFg.setPrimary(true); newFg.setAddress(address); for (OrderItem orderItem : order.getOrderItems()) { newFg.addFulfillmentGroupItem(createFulfillmentGroupItemFromOrderItem(orderItem, newFg, orderItem.getQuantity())); } return newFg; }
@Override public boolean cartHasPopulatedShippingAddress() { Order cart = CartState.getCart(); for (FulfillmentGroup fulfillmentGroup : CollectionUtils.emptyIfNull(cart.getFulfillmentGroups())) { if (fulfillmentGroupService.isShippable(fulfillmentGroup.getType())) { if (fulfillmentGroup.getAddress() != null && fulfillmentGroup.getFulfillmentOption() != null) { return true; } } } return false; }
orderMultishipOptionService.save(option); order = fulfillmentGroupService.matchFulfillmentGroupsToMultishipOptions(order, true);
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(orderServiceMock.save(EasyMock.isA(Order.class), EasyMock.isA(Boolean.class))).andAnswer(OfferDataItemProvider.getSaveOrderAnswer()).anyTimes(); EasyMock.expect(fgServiceMock.collapseToOneShippableFulfillmentGroup(EasyMock.isA(Order.class), EasyMock.eq(false))).andAnswer(new IAnswer<Order>() {
public FulfillmentEstimationResponse getFulfillmentEstimateResponse() { Order cart = CartState.getCart(); if (!isNullOrder(cart) && cart.getFulfillmentGroups().size() > 0 && cartStateService.cartHasPopulatedShippingAddress()) { try { List<FulfillmentOption> fulfillmentOptions = fulfillmentOptionService.readAllFulfillmentOptions(); FulfillmentGroup firstShippableFulfillmentGroup = fulfillmentGroupService.getFirstShippableFulfillmentGroup(cart); return fulfillmentPricingService.estimateCostForFulfillmentGroup(firstShippableFulfillmentGroup, new HashSet<>(fulfillmentOptions)); } catch (FulfillmentPriceException e) { // do nothing } } return null; }