Search in sources :

Example 1 with FulfillmentEstimationResponse

use of org.broadleafcommerce.core.pricing.service.fulfillment.provider.FulfillmentEstimationResponse in project BroadleafCommerce by BroadleafCommerce.

the class FulfillmentPricingServiceImpl method estimateCostForFulfillmentGroup.

@Override
public FulfillmentEstimationResponse estimateCostForFulfillmentGroup(FulfillmentGroup fulfillmentGroup, Set<FulfillmentOption> options) throws FulfillmentPriceException {
    FulfillmentEstimationResponse response = new FulfillmentEstimationResponse();
    HashMap<FulfillmentOption, Money> prices = new HashMap<FulfillmentOption, Money>();
    response.setFulfillmentOptionPrices(prices);
    for (FulfillmentPricingProvider provider : providers) {
        // to, then the response from the pricing provider should not include the options that it could not respond to.
        try {
            FulfillmentEstimationResponse processorResponse = provider.estimateCostForFulfillmentGroup(fulfillmentGroup, options);
            if (processorResponse != null && processorResponse.getFulfillmentOptionPrices() != null && processorResponse.getFulfillmentOptionPrices().size() > 0) {
                prices.putAll(processorResponse.getFulfillmentOptionPrices());
            }
        } catch (FulfillmentPriceException e) {
            // Shouldn't completely fail the rest of the estimation on a pricing exception. Another provider might still
            // be able to respond
            String errorMessage = "FulfillmentPriceException thrown when trying to estimate fulfillment costs from ";
            errorMessage += provider.getClass().getName();
            errorMessage += ". Underlying message was: " + e.getMessage();
            LOG.error(errorMessage);
        }
    }
    return response;
}
Also used : Money(org.broadleafcommerce.common.money.Money) FulfillmentPricingProvider(org.broadleafcommerce.core.pricing.service.fulfillment.provider.FulfillmentPricingProvider) HashMap(java.util.HashMap) FulfillmentPriceException(org.broadleafcommerce.common.vendor.service.exception.FulfillmentPriceException) FulfillmentEstimationResponse(org.broadleafcommerce.core.pricing.service.fulfillment.provider.FulfillmentEstimationResponse) FulfillmentOption(org.broadleafcommerce.core.order.domain.FulfillmentOption)

Example 2 with FulfillmentEstimationResponse

use of org.broadleafcommerce.core.pricing.service.fulfillment.provider.FulfillmentEstimationResponse in project BroadleafCommerce by BroadleafCommerce.

the class OnePageCheckoutProcessor method populateFulfillmentOptionsAndEstimationOnModel.

/**
 * 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);
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) FulfillmentPriceException(org.broadleafcommerce.common.vendor.service.exception.FulfillmentPriceException) FulfillmentEstimationResponse(org.broadleafcommerce.core.pricing.service.fulfillment.provider.FulfillmentEstimationResponse) FulfillmentOption(org.broadleafcommerce.core.order.domain.FulfillmentOption) NullOrderImpl(org.broadleafcommerce.core.order.domain.NullOrderImpl) HashSet(java.util.HashSet)

Example 3 with FulfillmentEstimationResponse

use of org.broadleafcommerce.core.pricing.service.fulfillment.provider.FulfillmentEstimationResponse 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());
    }
}
Also used : FixedPriceFulfillmentPricingProvider(org.broadleafcommerce.core.pricing.service.fulfillment.provider.FixedPriceFulfillmentPricingProvider) Money(org.broadleafcommerce.common.money.Money) FulfillmentGroupImpl(org.broadleafcommerce.core.order.domain.FulfillmentGroupImpl) FixedPriceFulfillmentOption(org.broadleafcommerce.core.order.fulfillment.domain.FixedPriceFulfillmentOption) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup) FulfillmentEstimationResponse(org.broadleafcommerce.core.pricing.service.fulfillment.provider.FulfillmentEstimationResponse) FixedPriceFulfillmentOption(org.broadleafcommerce.core.order.fulfillment.domain.FixedPriceFulfillmentOption) FulfillmentOption(org.broadleafcommerce.core.order.domain.FulfillmentOption) FixedPriceFulfillmentOptionImpl(org.broadleafcommerce.core.order.fulfillment.domain.FixedPriceFulfillmentOptionImpl) HashSet(java.util.HashSet)

Aggregations

FulfillmentOption (org.broadleafcommerce.core.order.domain.FulfillmentOption)3 FulfillmentEstimationResponse (org.broadleafcommerce.core.pricing.service.fulfillment.provider.FulfillmentEstimationResponse)3 HashSet (java.util.HashSet)2 Money (org.broadleafcommerce.common.money.Money)2 FulfillmentPriceException (org.broadleafcommerce.common.vendor.service.exception.FulfillmentPriceException)2 HashMap (java.util.HashMap)1 FulfillmentGroup (org.broadleafcommerce.core.order.domain.FulfillmentGroup)1 FulfillmentGroupImpl (org.broadleafcommerce.core.order.domain.FulfillmentGroupImpl)1 NullOrderImpl (org.broadleafcommerce.core.order.domain.NullOrderImpl)1 Order (org.broadleafcommerce.core.order.domain.Order)1 FixedPriceFulfillmentOption (org.broadleafcommerce.core.order.fulfillment.domain.FixedPriceFulfillmentOption)1 FixedPriceFulfillmentOptionImpl (org.broadleafcommerce.core.order.fulfillment.domain.FixedPriceFulfillmentOptionImpl)1 FixedPriceFulfillmentPricingProvider (org.broadleafcommerce.core.pricing.service.fulfillment.provider.FixedPriceFulfillmentPricingProvider)1 FulfillmentPricingProvider (org.broadleafcommerce.core.pricing.service.fulfillment.provider.FulfillmentPricingProvider)1