Search in sources :

Example 1 with FulfillmentPricingProvider

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

the class FulfillmentPricingServiceImpl method calculateCostForFulfillmentGroup.

@Override
public FulfillmentGroup calculateCostForFulfillmentGroup(FulfillmentGroup fulfillmentGroup) throws FulfillmentPriceException {
    if (fulfillmentGroup.getFulfillmentOption() == null) {
        // There is no shipping option yet. We'll simply set the shipping price to zero for now, and continue.
        fulfillmentGroup.setRetailFulfillmentPrice(Money.ZERO);
        fulfillmentGroup.setFulfillmentPrice(Money.ZERO);
        fulfillmentGroup.setSaleFulfillmentPrice(Money.ZERO);
        return fulfillmentGroup;
    }
    for (FulfillmentPricingProvider provider : providers) {
        if (provider.canCalculateCostForFulfillmentGroup(fulfillmentGroup, fulfillmentGroup.getFulfillmentOption())) {
            return provider.calculateCostForFulfillmentGroup(fulfillmentGroup);
        }
    }
    throw new FulfillmentPriceException("No valid processor was found to calculate the FulfillmentGroup cost with " + "FulfillmentOption id: " + fulfillmentGroup.getFulfillmentOption().getId() + " and name: " + fulfillmentGroup.getFulfillmentOption().getName());
}
Also used : FulfillmentPricingProvider(org.broadleafcommerce.core.pricing.service.fulfillment.provider.FulfillmentPricingProvider) FulfillmentPriceException(org.broadleafcommerce.common.vendor.service.exception.FulfillmentPriceException)

Example 2 with FulfillmentPricingProvider

use of org.broadleafcommerce.core.pricing.service.fulfillment.provider.FulfillmentPricingProvider 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)

Aggregations

FulfillmentPriceException (org.broadleafcommerce.common.vendor.service.exception.FulfillmentPriceException)2 FulfillmentPricingProvider (org.broadleafcommerce.core.pricing.service.fulfillment.provider.FulfillmentPricingProvider)2 HashMap (java.util.HashMap)1 Money (org.broadleafcommerce.common.money.Money)1 FulfillmentOption (org.broadleafcommerce.core.order.domain.FulfillmentOption)1 FulfillmentEstimationResponse (org.broadleafcommerce.core.pricing.service.fulfillment.provider.FulfillmentEstimationResponse)1