Search in sources :

Example 11 with ShoppingCartItem

use of com.salesmanager.core.model.shoppingcart.ShoppingCartItem in project shopizer by shopizer-ecommerce.

the class OrderFacadeImpl method processOrderModel.

/**
 * Commit an order
 * @param order
 * @param customer
 * @param transaction
 * @param store
 * @param language
 * @return
 * @throws ServiceException
 */
private Order processOrderModel(ShopOrder order, Customer customer, Transaction transaction, MerchantStore store, Language language) throws ServiceException {
    try {
        if (order.isShipToBillingAdress()) {
            // customer shipping is billing
            PersistableCustomer orderCustomer = order.getCustomer();
            Address billing = orderCustomer.getBilling();
            orderCustomer.setDelivery(billing);
        }
        Order modelOrder = new Order();
        modelOrder.setDatePurchased(new Date());
        modelOrder.setBilling(customer.getBilling());
        modelOrder.setDelivery(customer.getDelivery());
        modelOrder.setPaymentModuleCode(order.getPaymentModule());
        modelOrder.setPaymentType(PaymentType.valueOf(order.getPaymentMethodType()));
        modelOrder.setShippingModuleCode(order.getShippingModule());
        modelOrder.setCustomerAgreement(order.isCustomerAgreed());
        // set the store
        modelOrder.setLocale(LocaleUtils.getLocale(store));
        // locale based
        // on the
        // country for
        // order $
        // formatting
        List<ShoppingCartItem> shoppingCartItems = order.getShoppingCartItems();
        Set<OrderProduct> orderProducts = new LinkedHashSet<OrderProduct>();
        if (!StringUtils.isBlank(order.getComments())) {
            OrderStatusHistory statusHistory = new OrderStatusHistory();
            statusHistory.setStatus(OrderStatus.ORDERED);
            statusHistory.setOrder(modelOrder);
            statusHistory.setDateAdded(new Date());
            statusHistory.setComments(order.getComments());
            modelOrder.getOrderHistory().add(statusHistory);
        }
        OrderProductPopulator orderProductPopulator = new OrderProductPopulator();
        orderProductPopulator.setDigitalProductService(digitalProductService);
        orderProductPopulator.setProductAttributeService(productAttributeService);
        orderProductPopulator.setProductService(productService);
        String shoppingCartCode = null;
        for (ShoppingCartItem item : shoppingCartItems) {
            if (shoppingCartCode == null && item.getShoppingCart() != null) {
                shoppingCartCode = item.getShoppingCart().getShoppingCartCode();
            }
            /**
             * Before processing order quantity of item must be > 0
             */
            Product product = productService.getById(item.getProductId());
            if (product == null) {
                throw new ServiceException(ServiceException.EXCEPTION_INVENTORY_MISMATCH);
            }
            LOGGER.debug("Validate inventory");
            for (ProductAvailability availability : product.getAvailabilities()) {
                if (availability.getRegion().equals(Constants.ALL_REGIONS)) {
                    int qty = availability.getProductQuantity();
                    if (qty < item.getQuantity()) {
                        throw new ServiceException(ServiceException.EXCEPTION_INVENTORY_MISMATCH);
                    }
                }
            }
            OrderProduct orderProduct = new OrderProduct();
            orderProduct = orderProductPopulator.populate(item, orderProduct, store, language);
            orderProduct.setOrder(modelOrder);
            orderProducts.add(orderProduct);
        }
        modelOrder.setOrderProducts(orderProducts);
        OrderTotalSummary summary = order.getOrderTotalSummary();
        List<com.salesmanager.core.model.order.OrderTotal> totals = summary.getTotals();
        // re-order totals
        Collections.sort(totals, new Comparator<com.salesmanager.core.model.order.OrderTotal>() {

            public int compare(com.salesmanager.core.model.order.OrderTotal x, com.salesmanager.core.model.order.OrderTotal y) {
                if (x.getSortOrder() == y.getSortOrder())
                    return 0;
                return x.getSortOrder() < y.getSortOrder() ? -1 : 1;
            }
        });
        Set<com.salesmanager.core.model.order.OrderTotal> modelTotals = new LinkedHashSet<com.salesmanager.core.model.order.OrderTotal>();
        for (com.salesmanager.core.model.order.OrderTotal total : totals) {
            total.setOrder(modelOrder);
            modelTotals.add(total);
        }
        modelOrder.setOrderTotal(modelTotals);
        modelOrder.setTotal(order.getOrderTotalSummary().getTotal());
        // order misc objects
        modelOrder.setCurrency(store.getCurrency());
        modelOrder.setMerchant(store);
        // customer object
        orderCustomer(customer, modelOrder, language);
        // populate shipping information
        if (!StringUtils.isBlank(order.getShippingModule())) {
            modelOrder.setShippingModuleCode(order.getShippingModule());
        }
        String paymentType = order.getPaymentMethodType();
        Payment payment = new Payment();
        payment.setPaymentType(PaymentType.valueOf(paymentType));
        payment.setAmount(order.getOrderTotalSummary().getTotal());
        payment.setModuleName(order.getPaymentModule());
        payment.setCurrency(modelOrder.getCurrency());
        if (order.getPayment() != null && order.getPayment().get("paymentToken") != null) {
            // set
            // token
            String paymentToken = order.getPayment().get("paymentToken");
            Map<String, String> paymentMetaData = new HashMap<String, String>();
            payment.setPaymentMetaData(paymentMetaData);
            paymentMetaData.put("paymentToken", paymentToken);
        }
        if (PaymentType.CREDITCARD.name().equals(paymentType)) {
            payment = new CreditCardPayment();
            ((CreditCardPayment) payment).setCardOwner(order.getPayment().get("creditcard_card_holder"));
            ((CreditCardPayment) payment).setCredidCardValidationNumber(order.getPayment().get("creditcard_card_cvv"));
            ((CreditCardPayment) payment).setCreditCardNumber(order.getPayment().get("creditcard_card_number"));
            ((CreditCardPayment) payment).setExpirationMonth(order.getPayment().get("creditcard_card_expirationmonth"));
            ((CreditCardPayment) payment).setExpirationYear(order.getPayment().get("creditcard_card_expirationyear"));
            Map<String, String> paymentMetaData = order.getPayment();
            payment.setPaymentMetaData(paymentMetaData);
            payment.setPaymentType(PaymentType.valueOf(paymentType));
            payment.setAmount(order.getOrderTotalSummary().getTotal());
            payment.setModuleName(order.getPaymentModule());
            payment.setCurrency(modelOrder.getCurrency());
            CreditCardType creditCardType = null;
            String cardType = order.getPayment().get("creditcard_card_type");
            // supported credit cards
            if (CreditCardType.AMEX.name().equalsIgnoreCase(cardType)) {
                creditCardType = CreditCardType.AMEX;
            } else if (CreditCardType.VISA.name().equalsIgnoreCase(cardType)) {
                creditCardType = CreditCardType.VISA;
            } else if (CreditCardType.MASTERCARD.name().equalsIgnoreCase(cardType)) {
                creditCardType = CreditCardType.MASTERCARD;
            } else if (CreditCardType.DINERS.name().equalsIgnoreCase(cardType)) {
                creditCardType = CreditCardType.DINERS;
            } else if (CreditCardType.DISCOVERY.name().equalsIgnoreCase(cardType)) {
                creditCardType = CreditCardType.DISCOVERY;
            }
            ((CreditCardPayment) payment).setCreditCard(creditCardType);
            if (creditCardType != null) {
                CreditCard cc = new CreditCard();
                cc.setCardType(creditCardType);
                cc.setCcCvv(((CreditCardPayment) payment).getCredidCardValidationNumber());
                cc.setCcOwner(((CreditCardPayment) payment).getCardOwner());
                cc.setCcExpires(((CreditCardPayment) payment).getExpirationMonth() + "-" + ((CreditCardPayment) payment).getExpirationYear());
                // hash credit card number
                if (!StringUtils.isBlank(cc.getCcNumber())) {
                    String maskedNumber = CreditCardUtils.maskCardNumber(order.getPayment().get("creditcard_card_number"));
                    cc.setCcNumber(maskedNumber);
                    modelOrder.setCreditCard(cc);
                }
            }
        }
        if (PaymentType.PAYPAL.name().equals(paymentType)) {
            // check for previous transaction
            if (transaction == null) {
                throw new ServiceException("payment.error");
            }
            payment = new com.salesmanager.core.model.payments.PaypalPayment();
            ((com.salesmanager.core.model.payments.PaypalPayment) payment).setPayerId(transaction.getTransactionDetails().get("PAYERID"));
            ((com.salesmanager.core.model.payments.PaypalPayment) payment).setPaymentToken(transaction.getTransactionDetails().get("TOKEN"));
        }
        modelOrder.setShoppingCartCode(shoppingCartCode);
        modelOrder.setPaymentModuleCode(order.getPaymentModule());
        payment.setModuleName(order.getPaymentModule());
        if (transaction != null) {
            orderService.processOrder(modelOrder, customer, order.getShoppingCartItems(), summary, payment, store);
        } else {
            orderService.processOrder(modelOrder, customer, order.getShoppingCartItems(), summary, payment, transaction, store);
        }
        return modelOrder;
    } catch (ServiceException se) {
        // may be invalid credit card
        throw se;
    } catch (Exception e) {
        throw new ServiceException(e);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Address(com.salesmanager.shop.model.customer.address.Address) OrderProduct(com.salesmanager.core.model.order.orderproduct.OrderProduct) PersistableOrderProduct(com.salesmanager.shop.model.order.PersistableOrderProduct) ReadableOrderProduct(com.salesmanager.shop.model.order.ReadableOrderProduct) OrderProductPopulator(com.salesmanager.shop.populator.order.OrderProductPopulator) ReadableOrderProductPopulator(com.salesmanager.shop.populator.order.ReadableOrderProductPopulator) HashMap(java.util.HashMap) PersistableCustomer(com.salesmanager.shop.model.customer.PersistableCustomer) OrderTotalSummary(com.salesmanager.core.model.order.OrderTotalSummary) OrderProduct(com.salesmanager.core.model.order.orderproduct.OrderProduct) ShippingProduct(com.salesmanager.core.model.shipping.ShippingProduct) PersistableOrderProduct(com.salesmanager.shop.model.order.PersistableOrderProduct) Product(com.salesmanager.core.model.catalog.product.Product) ReadableOrderProduct(com.salesmanager.shop.model.order.ReadableOrderProduct) ProductAvailability(com.salesmanager.core.model.catalog.product.availability.ProductAvailability) ShopOrder(com.salesmanager.shop.model.order.ShopOrder) Order(com.salesmanager.core.model.order.Order) CreditCardType(com.salesmanager.core.model.payments.CreditCardType) Date(java.util.Date) LocalDate(java.time.LocalDate) CreditCard(com.salesmanager.core.model.order.payment.CreditCard) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ServiceException(com.salesmanager.core.business.exception.ServiceException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ConversionException(com.salesmanager.core.business.exception.ConversionException) CreditCardPayment(com.salesmanager.core.model.payments.CreditCardPayment) CreditCardPayment(com.salesmanager.core.model.payments.CreditCardPayment) Payment(com.salesmanager.core.model.payments.Payment) ServiceException(com.salesmanager.core.business.exception.ServiceException) ShoppingCartItem(com.salesmanager.core.model.shoppingcart.ShoppingCartItem) ReadableOrderStatusHistory(com.salesmanager.shop.model.order.history.ReadableOrderStatusHistory) PersistableOrderStatusHistory(com.salesmanager.shop.model.order.history.PersistableOrderStatusHistory) OrderStatusHistory(com.salesmanager.core.model.order.orderstatus.OrderStatusHistory) OrderTotal(com.salesmanager.shop.model.order.total.OrderTotal)

Example 12 with ShoppingCartItem

use of com.salesmanager.core.model.shoppingcart.ShoppingCartItem in project shopizer by shopizer-ecommerce.

the class OrderFacadeImpl method calculateOrderTotal.

@Override
public OrderTotalSummary calculateOrderTotal(MerchantStore store, com.salesmanager.shop.model.order.v0.PersistableOrder order, Language language) throws Exception {
    List<PersistableOrderProduct> orderProducts = order.getOrderProductItems();
    ShoppingCartItemPopulator populator = new ShoppingCartItemPopulator();
    populator.setProductAttributeService(productAttributeService);
    populator.setProductService(productService);
    populator.setShoppingCartService(shoppingCartService);
    List<ShoppingCartItem> items = new ArrayList<ShoppingCartItem>();
    for (PersistableOrderProduct orderProduct : orderProducts) {
        ShoppingCartItem item = populator.populate(orderProduct, new ShoppingCartItem(), store, language);
        items.add(item);
    }
    Customer customer = customer(order.getCustomer(), store, language);
    OrderTotalSummary summary = this.calculateOrderTotal(store, customer, order, language);
    return summary;
}
Also used : ShoppingCartItemPopulator(com.salesmanager.shop.populator.order.ShoppingCartItemPopulator) ReadableCustomer(com.salesmanager.shop.model.customer.ReadableCustomer) Customer(com.salesmanager.core.model.customer.Customer) PersistableCustomer(com.salesmanager.shop.model.customer.PersistableCustomer) OrderTotalSummary(com.salesmanager.core.model.order.OrderTotalSummary) ArrayList(java.util.ArrayList) ShoppingCartItem(com.salesmanager.core.model.shoppingcart.ShoppingCartItem) PersistableOrderProduct(com.salesmanager.shop.model.order.PersistableOrderProduct)

Example 13 with ShoppingCartItem

use of com.salesmanager.core.model.shoppingcart.ShoppingCartItem 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 14 with ShoppingCartItem

use of com.salesmanager.core.model.shoppingcart.ShoppingCartItem in project shopizer by shopizer-ecommerce.

the class OrderServiceImpl method caculateShoppingCart.

private OrderTotalSummary caculateShoppingCart(ShoppingCart shoppingCart, final Customer customer, final MerchantStore store, final Language language) throws Exception {
    OrderSummary orderSummary = new OrderSummary();
    orderSummary.setOrderSummaryType(OrderSummaryType.SHOPPINGCART);
    if (!StringUtils.isBlank(shoppingCart.getPromoCode())) {
        // promo valid 1 day
        Date promoDateAdded = shoppingCart.getPromoAdded();
        if (promoDateAdded == null) {
            promoDateAdded = new Date();
        }
        Instant instant = promoDateAdded.toInstant();
        ZonedDateTime zdt = instant.atZone(ZoneId.systemDefault());
        LocalDate date = zdt.toLocalDate();
        // date added < date + 1 day
        LocalDate tomorrow = LocalDate.now().plusDays(1);
        if (date.isBefore(tomorrow)) {
            orderSummary.setPromoCode(shoppingCart.getPromoCode());
        } else {
            // clear promo
            shoppingCart.setPromoCode(null);
            shoppingCartService.saveOrUpdate(shoppingCart);
        }
    }
    List<ShoppingCartItem> itemList = new ArrayList<ShoppingCartItem>(shoppingCart.getLineItems());
    // filter out unavailable
    itemList = itemList.stream().filter(p -> p.getProduct().isAvailable()).collect(Collectors.toList());
    orderSummary.setProducts(itemList);
    return caculateOrder(orderSummary, customer, store, language);
}
Also used : ZonedDateTime(java.time.ZonedDateTime) OrderSummary(com.salesmanager.core.model.order.OrderSummary) Instant(java.time.Instant) ArrayList(java.util.ArrayList) ShoppingCartItem(com.salesmanager.core.model.shoppingcart.ShoppingCartItem) LocalDate(java.time.LocalDate) Date(java.util.Date) LocalDate(java.time.LocalDate)

Example 15 with ShoppingCartItem

use of com.salesmanager.core.model.shoppingcart.ShoppingCartItem in project shopizer by shopizer-ecommerce.

the class OrderTotalServiceImpl method findOrderTotalVariation.

@Override
public OrderTotalVariation findOrderTotalVariation(OrderSummary summary, Customer customer, MerchantStore store, Language language) throws Exception {
    RebatesOrderTotalVariation variation = new RebatesOrderTotalVariation();
    List<OrderTotal> totals = null;
    if (orderTotalPostProcessors != null) {
        for (OrderTotalPostProcessorModule module : orderTotalPostProcessors) {
            // TODO check if the module is enabled from the Admin
            List<ShoppingCartItem> items = summary.getProducts();
            for (ShoppingCartItem item : items) {
                Long productId = item.getProductId();
                Product product = productService.getProductForLocale(productId, language, languageService.toLocale(language, store));
                OrderTotal orderTotal = module.caculateProductPiceVariation(summary, item, product, customer, store);
                if (orderTotal == null) {
                    continue;
                }
                if (totals == null) {
                    totals = new ArrayList<OrderTotal>();
                    variation.setVariations(totals);
                }
                // if product is null it will be catched when invoking the module
                orderTotal.setText(StringUtils.isNoneBlank(orderTotal.getText()) ? orderTotal.getText() : product.getProductDescription().getName());
                variation.getVariations().add(orderTotal);
            }
        }
    }
    return variation;
}
Also used : OrderTotalPostProcessorModule(com.salesmanager.core.modules.order.total.OrderTotalPostProcessorModule) Product(com.salesmanager.core.model.catalog.product.Product) ShoppingCartItem(com.salesmanager.core.model.shoppingcart.ShoppingCartItem) OrderTotal(com.salesmanager.core.model.order.OrderTotal) RebatesOrderTotalVariation(com.salesmanager.core.model.order.RebatesOrderTotalVariation)

Aggregations

ShoppingCartItem (com.salesmanager.core.model.shoppingcart.ShoppingCartItem)24 ArrayList (java.util.ArrayList)15 OrderTotalSummary (com.salesmanager.core.model.order.OrderTotalSummary)11 ServiceException (com.salesmanager.core.business.exception.ServiceException)9 ShippingSummary (com.salesmanager.core.model.shipping.ShippingSummary)9 Product (com.salesmanager.core.model.catalog.product.Product)7 HashMap (java.util.HashMap)7 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)6 Language (com.salesmanager.core.model.reference.language.Language)6 FinalPrice (com.salesmanager.core.model.catalog.product.price.FinalPrice)5 OrderTotal (com.salesmanager.core.model.order.OrderTotal)5 PersistableCustomer (com.salesmanager.shop.model.customer.PersistableCustomer)5 ShopOrder (com.salesmanager.shop.model.order.ShopOrder)5 OrderSummary (com.salesmanager.core.model.order.OrderSummary)4 ShippingOption (com.salesmanager.core.model.shipping.ShippingOption)4 ShoppingCart (com.salesmanager.core.model.shoppingcart.ShoppingCart)4 ReadableDelivery (com.salesmanager.shop.model.customer.ReadableDelivery)4 ReadableShopOrder (com.salesmanager.shop.model.order.ReadableShopOrder)4 ReadableShippingSummary (com.salesmanager.shop.model.order.shipping.ReadableShippingSummary)4