use of org.broadleafcommerce.core.order.domain.FulfillmentOption in project BroadleafCommerce by BroadleafCommerce.
the class BandedPriceFulfillmentTest method calculationResponse.
protected Money calculationResponse(FulfillmentOption option, Order order) throws Exception {
Set<FulfillmentOption> options = new HashSet<FulfillmentOption>();
options.add(option);
BandedFulfillmentPricingProvider provider = new BandedFulfillmentPricingProvider();
return provider.estimateCostForFulfillmentGroup(order.getFulfillmentGroups().get(0), options).getFulfillmentOptionPrices().get(option);
}
use of org.broadleafcommerce.core.order.domain.FulfillmentOption in project BroadleafCommerce by BroadleafCommerce.
the class FixedPriceFulfillmentTest method testNullFulfillmentOptionInEstimation.
public void testNullFulfillmentOptionInEstimation() throws Exception {
Set<FulfillmentOption> options = new HashSet<FulfillmentOption>();
FixedPriceFulfillmentOption option1 = new FixedPriceFulfillmentOptionImpl();
option1.setPrice(new Money(BigDecimal.ONE));
FixedPriceFulfillmentOption option2 = new FixedPriceFulfillmentOptionImpl();
option2.setPrice(new Money(BigDecimal.TEN));
options.add(option1);
options.add(option2);
FixedPriceFulfillmentPricingProvider provider = new FixedPriceFulfillmentPricingProvider();
FulfillmentGroup fg = new FulfillmentGroupImpl();
FulfillmentEstimationResponse response = provider.estimateCostForFulfillmentGroup(fg, options);
for (Entry<? extends FulfillmentOption, Money> entry : response.getFulfillmentOptionPrices().entrySet()) {
assertEquals(((FixedPriceFulfillmentOption) entry.getKey()).getPrice(), entry.getValue());
}
}
use of org.broadleafcommerce.core.order.domain.FulfillmentOption in project BroadleafCommerce by BroadleafCommerce.
the class FulfillmentVariableExpression method getFulfillmentEstimateResponse.
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;
}
use of org.broadleafcommerce.core.order.domain.FulfillmentOption in project BroadleafCommerce by BroadleafCommerce.
the class BroadleafShippingInfoController method saveSingleShip.
/**
* Processes the request to save a single shipping address. Allows modules to add module specific shipping logic.
*
* Note: the default Broadleaf implementation creates an order
* with a single fulfillment group. In the case of shipping to multiple addresses,
* the multiship methods should be used.
*
* @param request
* @param response
* @param model
* @param shippingForm
* @return the return path
* @throws org.broadleafcommerce.common.exception.ServiceException
*/
public String saveSingleShip(HttpServletRequest request, HttpServletResponse response, Model model, ShippingInfoForm shippingForm, BindingResult result) throws PricingException, ServiceException {
Order cart = CartState.getCart();
if (shippingForm.shouldUseBillingAddress()) {
copyBillingAddressToShippingAddress(cart, shippingForm);
}
addressService.populateAddressISOCountrySub(shippingForm.getAddress());
shippingInfoFormValidator.validate(shippingForm, result);
if (result.hasErrors()) {
return getCheckoutView();
}
if ((shippingForm.getAddress().getPhonePrimary() != null) && (StringUtils.isEmpty(shippingForm.getAddress().getPhonePrimary().getPhoneNumber()))) {
shippingForm.getAddress().setPhonePrimary(null);
}
if ((shippingForm.getAddress().getPhoneSecondary() != null) && (StringUtils.isEmpty(shippingForm.getAddress().getPhoneSecondary().getPhoneNumber()))) {
shippingForm.getAddress().setPhoneSecondary(null);
}
if ((shippingForm.getAddress().getPhoneFax() != null) && (StringUtils.isEmpty(shippingForm.getAddress().getPhoneFax().getPhoneNumber()))) {
shippingForm.getAddress().setPhoneFax(null);
}
Customer customer = CustomerState.getCustomer();
if (!customer.isAnonymous() && shippingForm.isSaveAsDefault()) {
Address address = addressService.saveAddress(shippingForm.getAddress());
CustomerAddress customerAddress = customerAddressService.create();
customerAddress.setAddress(address);
customerAddress.setAddressName(shippingForm.getAddressName());
customerAddress.setCustomer(customer);
customerAddress = customerAddressService.saveCustomerAddress(customerAddress);
customerAddressService.makeCustomerAddressDefault(customerAddress.getId(), customer.getId());
}
FulfillmentGroup shippableFulfillmentGroup = fulfillmentGroupService.getFirstShippableFulfillmentGroup(cart);
if (shippableFulfillmentGroup != null) {
shippableFulfillmentGroup.setAddress(shippingForm.getAddress());
shippableFulfillmentGroup.setPersonalMessage(shippingForm.getPersonalMessage());
shippableFulfillmentGroup.setDeliveryInstruction(shippingForm.getDeliveryMessage());
FulfillmentOption fulfillmentOption = fulfillmentOptionService.readFulfillmentOptionById(shippingForm.getFulfillmentOptionId());
shippableFulfillmentGroup.setFulfillmentOption(fulfillmentOption);
cart = orderService.save(cart, true);
}
// Add module specific logic
checkoutControllerExtensionManager.getProxy().performAdditionalShippingAction();
if (isAjaxRequest(request)) {
// Add module specific model variables
checkoutControllerExtensionManager.getProxy().addAdditionalModelVariables(model);
return getCheckoutView();
} else {
return getCheckoutPageRedirect();
}
}
use of org.broadleafcommerce.core.order.domain.FulfillmentOption 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;
}
Aggregations