Search in sources :

Example 11 with ShippingConfiguration

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

the class ShippingFacadeImpl method saveExpeditionConfiguration.

@Override
public void saveExpeditionConfiguration(ExpeditionConfiguration expedition, MerchantStore store) {
    Validate.notNull(expedition, "ExpeditionConfiguration cannot be null");
    try {
        // get original configuration
        ShippingConfiguration config = getDbConfig(store);
        config.setTaxOnShipping(expedition.isTaxOnShipping());
        config.setShippingType(expedition.isIternationalShipping() ? ShippingType.INTERNATIONAL : ShippingType.NATIONAL);
        this.saveShippingConfiguration(config, store);
        shippingService.setSupportedCountries(store, expedition.getShipToCountry());
    } catch (ServiceException e) {
        LOGGER.error("Error while getting expedition configuration", e);
        throw new ServiceRuntimeException("Error while getting Expedition configuration for store[" + store.getCode() + "]", e);
    }
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) ShippingConfiguration(com.salesmanager.core.model.shipping.ShippingConfiguration) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 12 with ShippingConfiguration

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

the class ShippingFacadeImpl method deletePackage.

@Override
public void deletePackage(String code, MerchantStore store) {
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notEmpty(code, "Packaging unique code cannot be empty");
    ShippingConfiguration config = getDbConfig(store);
    List<com.salesmanager.core.model.shipping.Package> packages = config.getPackages();
    List<com.salesmanager.core.model.shipping.Package> packList = config.getPackages().stream().filter(p -> p.getCode().equalsIgnoreCase(code)).collect(Collectors.toList());
    if (!packList.isEmpty()) {
        packages.removeAll(packList);
        config.setPackages(packages);
        this.saveShippingConfiguration(config, store);
    }
}
Also used : ExpeditionConfiguration(com.salesmanager.shop.model.shipping.ExpeditionConfiguration) ShippingOrigin(com.salesmanager.core.model.shipping.ShippingOrigin) ShippingType(com.salesmanager.core.model.shipping.ShippingType) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) Zone(com.salesmanager.core.model.reference.zone.Zone) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) ServiceException(com.salesmanager.core.business.exception.ServiceException) ZoneService(com.salesmanager.core.business.services.reference.zone.ZoneService) Language(com.salesmanager.core.model.reference.language.Language) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException) ShippingOriginService(com.salesmanager.core.business.services.shipping.ShippingOriginService) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) Service(org.springframework.stereotype.Service) ReadableCountryPopulator(com.salesmanager.shop.populator.references.ReadableCountryPopulator) ShippingService(com.salesmanager.core.business.services.shipping.ShippingService) ReadableCountry(com.salesmanager.shop.model.references.ReadableCountry) OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) CountryService(com.salesmanager.core.business.services.reference.country.CountryService) Validate(org.jsoup.helper.Validate) Logger(org.slf4j.Logger) Country(com.salesmanager.core.model.reference.country.Country) Collectors(java.util.stream.Collectors) List(java.util.List) ShippingPackageType(com.salesmanager.core.model.shipping.ShippingPackageType) PackageDetails(com.salesmanager.core.model.shipping.PackageDetails) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ConversionException(com.salesmanager.core.business.exception.ConversionException) PersistableAddress(com.salesmanager.shop.model.references.PersistableAddress) ReadableAddress(com.salesmanager.shop.model.references.ReadableAddress) ShippingConfiguration(com.salesmanager.core.model.shipping.ShippingConfiguration) Comparator(java.util.Comparator) ShippingConfiguration(com.salesmanager.core.model.shipping.ShippingConfiguration)

Example 13 with ShippingConfiguration

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

the class ShippingFacadeImpl method getPackage.

@Override
public PackageDetails getPackage(String code, MerchantStore store) {
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notEmpty(code, "Packaging unique code cannot be empty");
    ShippingConfiguration config = getDbConfig(store);
    com.salesmanager.core.model.shipping.Package p = this.packageDetails(config, code);
    if (p == null) {
        throw new ResourceNotFoundException("Package with unique code [" + code + "] not found");
    }
    return toPackageDetails(p);
}
Also used : ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ShippingConfiguration(com.salesmanager.core.model.shipping.ShippingConfiguration)

Example 14 with ShippingConfiguration

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

the class OrderServiceImpl method caculateOrder.

private OrderTotalSummary caculateOrder(OrderSummary summary, Customer customer, final MerchantStore store, final Language language) throws Exception {
    OrderTotalSummary totalSummary = new OrderTotalSummary();
    List<OrderTotal> orderTotals = new ArrayList<OrderTotal>();
    Map<String, OrderTotal> otherPricesTotals = new HashMap<String, OrderTotal>();
    ShippingConfiguration shippingConfiguration = null;
    BigDecimal grandTotal = new BigDecimal(0);
    grandTotal.setScale(2, RoundingMode.HALF_UP);
    // price by item
    /**
     * qty * price
     * subtotal
     */
    BigDecimal subTotal = new BigDecimal(0);
    subTotal.setScale(2, RoundingMode.HALF_UP);
    for (ShoppingCartItem item : summary.getProducts()) {
        BigDecimal st = item.getItemPrice().multiply(new BigDecimal(item.getQuantity()));
        item.setSubTotal(st);
        subTotal = subTotal.add(st);
        // Other prices
        FinalPrice finalPrice = item.getFinalPrice();
        if (finalPrice != null) {
            List<FinalPrice> otherPrices = finalPrice.getAdditionalPrices();
            if (otherPrices != null) {
                for (FinalPrice price : otherPrices) {
                    if (!price.isDefaultPrice()) {
                        OrderTotal itemSubTotal = otherPricesTotals.get(price.getProductPrice().getCode());
                        if (itemSubTotal == null) {
                            itemSubTotal = new OrderTotal();
                            itemSubTotal.setModule(Constants.OT_ITEM_PRICE_MODULE_CODE);
                            itemSubTotal.setTitle(Constants.OT_ITEM_PRICE_MODULE_CODE);
                            itemSubTotal.setOrderTotalCode(price.getProductPrice().getCode());
                            itemSubTotal.setOrderTotalType(OrderTotalType.PRODUCT);
                            itemSubTotal.setSortOrder(0);
                            otherPricesTotals.put(price.getProductPrice().getCode(), itemSubTotal);
                        }
                        BigDecimal orderTotalValue = itemSubTotal.getValue();
                        if (orderTotalValue == null) {
                            orderTotalValue = new BigDecimal(0);
                            orderTotalValue.setScale(2, RoundingMode.HALF_UP);
                        }
                        orderTotalValue = orderTotalValue.add(price.getFinalPrice());
                        itemSubTotal.setValue(orderTotalValue);
                        if (price.getProductPrice().getProductPriceType().name().equals(OrderValueType.ONE_TIME)) {
                            subTotal = subTotal.add(price.getFinalPrice());
                        }
                    }
                }
            }
        }
    }
    // only in order page, otherwise invokes too many processing
    if (OrderSummaryType.ORDERTOTAL.name().equals(summary.getOrderSummaryType().name()) || OrderSummaryType.SHOPPINGCART.name().equals(summary.getOrderSummaryType().name())) {
        // Post processing order total variation modules for sub total calculation - drools, custom modules
        // may affect the sub total
        OrderTotalVariation orderTotalVariation = orderTotalService.findOrderTotalVariation(summary, customer, store, language);
        int currentCount = 10;
        if (CollectionUtils.isNotEmpty(orderTotalVariation.getVariations())) {
            for (OrderTotal variation : orderTotalVariation.getVariations()) {
                variation.setSortOrder(currentCount++);
                orderTotals.add(variation);
                subTotal = subTotal.subtract(variation.getValue());
            }
        }
    }
    totalSummary.setSubTotal(subTotal);
    grandTotal = grandTotal.add(subTotal);
    OrderTotal orderTotalSubTotal = new OrderTotal();
    orderTotalSubTotal.setModule(Constants.OT_SUBTOTAL_MODULE_CODE);
    orderTotalSubTotal.setOrderTotalType(OrderTotalType.SUBTOTAL);
    orderTotalSubTotal.setOrderTotalCode("order.total.subtotal");
    orderTotalSubTotal.setTitle(Constants.OT_SUBTOTAL_MODULE_CODE);
    orderTotalSubTotal.setSortOrder(5);
    orderTotalSubTotal.setValue(subTotal);
    orderTotals.add(orderTotalSubTotal);
    // shipping
    if (summary.getShippingSummary() != null) {
        OrderTotal shippingSubTotal = new OrderTotal();
        shippingSubTotal.setModule(Constants.OT_SHIPPING_MODULE_CODE);
        shippingSubTotal.setOrderTotalType(OrderTotalType.SHIPPING);
        shippingSubTotal.setOrderTotalCode("order.total.shipping");
        shippingSubTotal.setTitle(Constants.OT_SHIPPING_MODULE_CODE);
        shippingSubTotal.setSortOrder(100);
        orderTotals.add(shippingSubTotal);
        if (!summary.getShippingSummary().isFreeShipping()) {
            shippingSubTotal.setValue(summary.getShippingSummary().getShipping());
            grandTotal = grandTotal.add(summary.getShippingSummary().getShipping());
        } else {
            shippingSubTotal.setValue(new BigDecimal(0));
            grandTotal = grandTotal.add(new BigDecimal(0));
        }
        // check handling fees
        shippingConfiguration = shippingService.getShippingConfiguration(store);
        if (summary.getShippingSummary().getHandling() != null && summary.getShippingSummary().getHandling().doubleValue() > 0) {
            if (shippingConfiguration.getHandlingFees() != null && shippingConfiguration.getHandlingFees().doubleValue() > 0) {
                OrderTotal handlingubTotal = new OrderTotal();
                handlingubTotal.setModule(Constants.OT_HANDLING_MODULE_CODE);
                handlingubTotal.setOrderTotalType(OrderTotalType.HANDLING);
                handlingubTotal.setOrderTotalCode("order.total.handling");
                handlingubTotal.setTitle(Constants.OT_HANDLING_MODULE_CODE);
                // handlingubTotal.setText("order.total.handling");
                handlingubTotal.setSortOrder(120);
                handlingubTotal.setValue(summary.getShippingSummary().getHandling());
                orderTotals.add(handlingubTotal);
                grandTotal = grandTotal.add(summary.getShippingSummary().getHandling());
            }
        }
    }
    // tax
    List<TaxItem> taxes = taxService.calculateTax(summary, customer, store, language);
    if (taxes != null && taxes.size() > 0) {
        BigDecimal totalTaxes = new BigDecimal(0);
        totalTaxes.setScale(2, RoundingMode.HALF_UP);
        int taxCount = 200;
        for (TaxItem tax : taxes) {
            OrderTotal taxLine = new OrderTotal();
            taxLine.setModule(Constants.OT_TAX_MODULE_CODE);
            taxLine.setOrderTotalType(OrderTotalType.TAX);
            taxLine.setOrderTotalCode(tax.getLabel());
            taxLine.setSortOrder(taxCount);
            taxLine.setTitle(Constants.OT_TAX_MODULE_CODE);
            taxLine.setText(tax.getLabel());
            taxLine.setValue(tax.getItemPrice());
            totalTaxes = totalTaxes.add(tax.getItemPrice());
            orderTotals.add(taxLine);
            // grandTotal=grandTotal.add(tax.getItemPrice());
            taxCount++;
        }
        grandTotal = grandTotal.add(totalTaxes);
        totalSummary.setTaxTotal(totalTaxes);
    }
    // grand total
    OrderTotal orderTotal = new OrderTotal();
    orderTotal.setModule(Constants.OT_TOTAL_MODULE_CODE);
    orderTotal.setOrderTotalType(OrderTotalType.TOTAL);
    orderTotal.setOrderTotalCode("order.total.total");
    orderTotal.setTitle(Constants.OT_TOTAL_MODULE_CODE);
    // orderTotal.setText("order.total.total");
    orderTotal.setSortOrder(500);
    orderTotal.setValue(grandTotal);
    orderTotals.add(orderTotal);
    totalSummary.setTotal(grandTotal);
    totalSummary.setTotals(orderTotals);
    return totalSummary;
}
Also used : HashMap(java.util.HashMap) OrderTotalSummary(com.salesmanager.core.model.order.OrderTotalSummary) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) ShippingConfiguration(com.salesmanager.core.model.shipping.ShippingConfiguration) TaxItem(com.salesmanager.core.model.tax.TaxItem) OrderTotalVariation(com.salesmanager.core.model.order.OrderTotalVariation) ShoppingCartItem(com.salesmanager.core.model.shoppingcart.ShoppingCartItem) OrderTotal(com.salesmanager.core.model.order.OrderTotal) FinalPrice(com.salesmanager.core.model.catalog.product.price.FinalPrice)

Example 15 with ShippingConfiguration

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

the class ShippingServiceImpl method getShipToCountryList.

@Override
public List<Country> getShipToCountryList(MerchantStore store, Language language) throws ServiceException {
    ShippingConfiguration shippingConfiguration = getShippingConfiguration(store);
    ShippingType shippingType = ShippingType.INTERNATIONAL;
    List<String> supportedCountries = new ArrayList<String>();
    if (shippingConfiguration == null) {
        shippingConfiguration = new ShippingConfiguration();
    }
    if (shippingConfiguration.getShippingType() != null) {
        shippingType = shippingConfiguration.getShippingType();
    }
    if (shippingType.name().equals(ShippingType.NATIONAL.name())) {
        supportedCountries.add(store.getCountry().getIsoCode());
    } else {
        MerchantConfiguration configuration = merchantConfigurationService.getMerchantConfiguration(SUPPORTED_COUNTRIES, store);
        if (configuration != null) {
            String countries = configuration.getValue();
            if (!StringUtils.isBlank(countries)) {
                Object objRegions = JSONValue.parse(countries);
                JSONArray arrayRegions = (JSONArray) objRegions;
                for (Object arrayRegion : arrayRegions) {
                    supportedCountries.add((String) arrayRegion);
                }
            }
        }
    }
    return countryService.getCountries(supportedCountries, language);
}
Also used : ShippingType(com.salesmanager.core.model.shipping.ShippingType) ArrayList(java.util.ArrayList) MerchantConfiguration(com.salesmanager.core.model.system.MerchantConfiguration) JSONArray(org.json.simple.JSONArray) ShippingConfiguration(com.salesmanager.core.model.shipping.ShippingConfiguration)

Aggregations

ShippingConfiguration (com.salesmanager.core.model.shipping.ShippingConfiguration)17 ArrayList (java.util.ArrayList)10 ServiceException (com.salesmanager.core.business.exception.ServiceException)9 PackageDetails (com.salesmanager.core.model.shipping.PackageDetails)8 Country (com.salesmanager.core.model.reference.country.Country)7 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)6 ShippingOrigin (com.salesmanager.core.model.shipping.ShippingOrigin)6 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)6 BigDecimal (java.math.BigDecimal)6 List (java.util.List)6 Language (com.salesmanager.core.model.reference.language.Language)5 CountryService (com.salesmanager.core.business.services.reference.country.CountryService)4 Zone (com.salesmanager.core.model.reference.zone.Zone)4 ShippingPackageType (com.salesmanager.core.model.shipping.ShippingPackageType)4 ShippingType (com.salesmanager.core.model.shipping.ShippingType)4 IntegrationException (com.salesmanager.core.modules.integration.IntegrationException)4 OperationNotAllowedException (com.salesmanager.shop.store.api.exception.OperationNotAllowedException)4 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4