Search in sources :

Example 1 with ShippingBasisType

use of com.salesmanager.core.model.shipping.ShippingBasisType in project shopizer by shopizer-ecommerce.

the class CustomWeightBasedShippingQuote method getShippingQuotes.

@Override
public List<ShippingOption> getShippingQuotes(ShippingQuote shippingQuote, List<PackageDetails> packages, BigDecimal orderTotal, Delivery delivery, ShippingOrigin origin, MerchantStore store, IntegrationConfiguration configuration, IntegrationModule module, ShippingConfiguration shippingConfiguration, Locale locale) throws IntegrationException {
    if (StringUtils.isBlank(delivery.getPostalCode())) {
        return null;
    }
    // get configuration
    CustomShippingQuotesConfiguration customConfiguration = (CustomShippingQuotesConfiguration) this.getCustomModuleConfiguration(store);
    List<CustomShippingQuotesRegion> regions = customConfiguration.getRegions();
    ShippingBasisType shippingType = shippingConfiguration.getShippingBasisType();
    ShippingOption shippingOption = null;
    try {
        for (CustomShippingQuotesRegion region : customConfiguration.getRegions()) {
            for (String countryCode : region.getCountries()) {
                if (countryCode.equals(delivery.getCountry().getIsoCode())) {
                    // determine shipping weight
                    double weight = 0;
                    for (PackageDetails packageDetail : packages) {
                        weight = weight + packageDetail.getShippingWeight();
                    }
                    // see the price associated with the width
                    List<CustomShippingQuoteWeightItem> quoteItems = region.getQuoteItems();
                    for (CustomShippingQuoteWeightItem quoteItem : quoteItems) {
                        if (weight <= quoteItem.getMaximumWeight()) {
                            shippingOption = new ShippingOption();
                            shippingOption.setOptionCode(new StringBuilder().append(CUSTOM_WEIGHT).toString());
                            shippingOption.setOptionId(new StringBuilder().append(CUSTOM_WEIGHT).append("_").append(region.getCustomRegionName()).toString());
                            shippingOption.setOptionPrice(quoteItem.getPrice());
                            shippingOption.setOptionPriceText(productPriceUtils.getStoreFormatedAmountWithCurrency(store, quoteItem.getPrice()));
                            break;
                        }
                    }
                }
            }
        }
        if (shippingOption != null) {
            List<ShippingOption> options = new ArrayList<ShippingOption>();
            options.add(shippingOption);
            return options;
        }
        return null;
    } catch (Exception e) {
        throw new IntegrationException(e);
    }
}
Also used : ShippingBasisType(com.salesmanager.core.model.shipping.ShippingBasisType) IntegrationException(com.salesmanager.core.modules.integration.IntegrationException) CustomShippingQuotesConfiguration(com.salesmanager.core.modules.integration.shipping.model.CustomShippingQuotesConfiguration) CustomShippingQuotesRegion(com.salesmanager.core.modules.integration.shipping.model.CustomShippingQuotesRegion) ArrayList(java.util.ArrayList) ServiceException(com.salesmanager.core.business.exception.ServiceException) IntegrationException(com.salesmanager.core.modules.integration.IntegrationException) ShippingOption(com.salesmanager.core.model.shipping.ShippingOption) CustomShippingQuoteWeightItem(com.salesmanager.core.modules.integration.shipping.model.CustomShippingQuoteWeightItem) PackageDetails(com.salesmanager.core.model.shipping.PackageDetails)

Aggregations

ServiceException (com.salesmanager.core.business.exception.ServiceException)1 PackageDetails (com.salesmanager.core.model.shipping.PackageDetails)1 ShippingBasisType (com.salesmanager.core.model.shipping.ShippingBasisType)1 ShippingOption (com.salesmanager.core.model.shipping.ShippingOption)1 IntegrationException (com.salesmanager.core.modules.integration.IntegrationException)1 CustomShippingQuoteWeightItem (com.salesmanager.core.modules.integration.shipping.model.CustomShippingQuoteWeightItem)1 CustomShippingQuotesConfiguration (com.salesmanager.core.modules.integration.shipping.model.CustomShippingQuotesConfiguration)1 CustomShippingQuotesRegion (com.salesmanager.core.modules.integration.shipping.model.CustomShippingQuotesRegion)1 ArrayList (java.util.ArrayList)1