Search in sources :

Example 6 with OrderTotal

use of com.salesmanager.core.model.order.OrderTotal in project shopizer by shopizer-ecommerce.

the class PromoCodeCalculatorModule method caculateProductPiceVariation.

@Override
public OrderTotal caculateProductPiceVariation(OrderSummary summary, ShoppingCartItem shoppingCartItem, Product product, Customer customer, MerchantStore store) throws Exception {
    Validate.notNull(summary, "OrderTotalSummary must not be null");
    Validate.notNull(store, "MerchantStore must not be null");
    if (StringUtils.isBlank(summary.getPromoCode())) {
        return null;
    }
    KieSession kieSession = droolsBeanFactory.getKieSession(ResourceFactory.newClassPathResource("com/salesmanager/drools/rules/PromoCoupon.drl"));
    OrderTotalResponse resp = new OrderTotalResponse();
    OrderTotalInputParameters inputParameters = new OrderTotalInputParameters();
    inputParameters.setPromoCode(summary.getPromoCode());
    inputParameters.setDate(new Date());
    kieSession.insert(inputParameters);
    kieSession.setGlobal("total", resp);
    kieSession.fireAllRules();
    if (resp.getDiscount() != null) {
        OrderTotal orderTotal = null;
        if (resp.getDiscount() != null) {
            orderTotal = new OrderTotal();
            orderTotal.setOrderTotalCode(Constants.OT_DISCOUNT_TITLE);
            orderTotal.setOrderTotalType(OrderTotalType.SUBTOTAL);
            orderTotal.setTitle(Constants.OT_SUBTOTAL_MODULE_CODE);
            orderTotal.setText(summary.getPromoCode());
            // calculate discount that will be added as a negative value
            FinalPrice productPrice = pricingService.calculateProductPrice(product);
            Double discount = resp.getDiscount();
            BigDecimal reduction = productPrice.getFinalPrice().multiply(new BigDecimal(discount));
            reduction = reduction.multiply(new BigDecimal(shoppingCartItem.getQuantity()));
            // discount value
            orderTotal.setValue(reduction);
        // TODO check expiration
        }
        return orderTotal;
    }
    return null;
}
Also used : KieSession(org.kie.api.runtime.KieSession) OrderTotal(com.salesmanager.core.model.order.OrderTotal) Date(java.util.Date) BigDecimal(java.math.BigDecimal) FinalPrice(com.salesmanager.core.model.catalog.product.price.FinalPrice)

Example 7 with OrderTotal

use of com.salesmanager.core.model.order.OrderTotal 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 8 with OrderTotal

use of com.salesmanager.core.model.order.OrderTotal 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)

Example 9 with OrderTotal

use of com.salesmanager.core.model.order.OrderTotal in project shopizer by shopizer-ecommerce.

the class OrderFacadeImpl method orderConfirmation.

@Override
public ReadableOrderConfirmation orderConfirmation(Order order, Customer customer, MerchantStore store, Language language) {
    Validate.notNull(order, "Order cannot be null");
    Validate.notNull(customer, "Customer cannot be null");
    Validate.notNull(store, "MerchantStore cannot be null");
    ReadableOrderConfirmation orderConfirmation = new ReadableOrderConfirmation();
    ReadableCustomer readableCustomer = readableCustomerMapper.convert(customer, store, language);
    orderConfirmation.setBilling(readableCustomer.getBilling());
    orderConfirmation.setDelivery(readableCustomer.getDelivery());
    ReadableTotal readableTotal = new ReadableTotal();
    Set<OrderTotal> totals = order.getOrderTotal();
    List<ReadableOrderTotal> readableTotals = totals.stream().sorted(Comparator.comparingInt(OrderTotal::getSortOrder)).map(tot -> convertOrderTotal(tot, store, language)).collect(Collectors.toList());
    readableTotal.setTotals(readableTotals);
    Optional<ReadableOrderTotal> grandTotal = readableTotals.stream().filter(tot -> tot.getCode().equals("order.total.total")).findFirst();
    if (grandTotal.isPresent()) {
        readableTotal.setGrandTotal(grandTotal.get().getText());
    }
    orderConfirmation.setTotal(readableTotal);
    List<ReadableOrderProduct> products = order.getOrderProducts().stream().map(pr -> convertOrderProduct(pr, store, language)).collect(Collectors.toList());
    orderConfirmation.setProducts(products);
    if (!StringUtils.isBlank(order.getShippingModuleCode())) {
        StringBuilder optionCodeBuilder = new StringBuilder();
        try {
            optionCodeBuilder.append("module.shipping.").append(order.getShippingModuleCode());
            String shippingName = messages.getMessage(optionCodeBuilder.toString(), new String[] { store.getStorename() }, languageService.toLocale(language, store));
            orderConfirmation.setShipping(shippingName);
        } catch (Exception e) {
            // label not found
            LOGGER.warn("No shipping code found for " + optionCodeBuilder.toString());
        }
    }
    if (order.getPaymentType() != null) {
        orderConfirmation.setPayment(order.getPaymentType().name());
    }
    /**
     * Confirmation may be formatted
     */
    orderConfirmation.setId(order.getId());
    return orderConfirmation;
}
Also used : ReadableOrderTotalMapper(com.salesmanager.shop.mapper.order.ReadableOrderTotalMapper) Order(com.salesmanager.core.model.order.Order) OrderProduct(com.salesmanager.core.model.order.orderproduct.OrderProduct) ReadableCustomerMapper(com.salesmanager.shop.mapper.customer.ReadableCustomerMapper) ReadableOrderTotal(com.salesmanager.shop.model.order.total.ReadableOrderTotal) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) LanguageService(com.salesmanager.core.business.services.reference.language.LanguageService) Language(com.salesmanager.core.model.reference.language.Language) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) LabelUtils(com.salesmanager.shop.utils.LabelUtils) Service(org.springframework.stereotype.Service) Logger(org.slf4j.Logger) ReadableOrderProduct(com.salesmanager.shop.model.order.ReadableOrderProduct) Customer(com.salesmanager.core.model.customer.Customer) ReadableOrderConfirmation(com.salesmanager.shop.model.order.v1.ReadableOrderConfirmation) Set(java.util.Set) Collectors(java.util.stream.Collectors) ReadableCustomer(com.salesmanager.shop.model.customer.ReadableCustomer) List(java.util.List) Validate(org.apache.commons.lang3.Validate) OrderFacade(com.salesmanager.shop.store.controller.order.facade.v1.OrderFacade) Optional(java.util.Optional) Comparator(java.util.Comparator) ReadableOrderProductMapper(com.salesmanager.shop.mapper.order.ReadableOrderProductMapper) ReadableTotal(com.salesmanager.shop.model.order.total.ReadableTotal) OrderTotal(com.salesmanager.core.model.order.OrderTotal) ReadableTotal(com.salesmanager.shop.model.order.total.ReadableTotal) ReadableOrderTotal(com.salesmanager.shop.model.order.total.ReadableOrderTotal) ReadableOrderProduct(com.salesmanager.shop.model.order.ReadableOrderProduct) ReadableCustomer(com.salesmanager.shop.model.customer.ReadableCustomer) ReadableOrderConfirmation(com.salesmanager.shop.model.order.v1.ReadableOrderConfirmation) ReadableOrderTotal(com.salesmanager.shop.model.order.total.ReadableOrderTotal) OrderTotal(com.salesmanager.core.model.order.OrderTotal)

Example 10 with OrderTotal

use of com.salesmanager.core.model.order.OrderTotal in project shopizer by shopizer-ecommerce.

the class OrderTest method getMerchantOrders.

@Test
public void getMerchantOrders() throws ServiceException {
    Currency currency = currencyService.getByCode(USD_CURRENCY_CODE);
    Country country = countryService.getByCode("US");
    Zone zone = zoneService.getByCode("VT");
    Language en = languageService.getByCode("en");
    MerchantStore merchant = merchantService.getByCode(MerchantStore.DEFAULT_STORE);
    /**
     * Create a customer *
     */
    Customer customer = new Customer();
    customer.setMerchantStore(merchant);
    customer.setDefaultLanguage(en);
    customer.setEmailAddress("email@email.com");
    customer.setPassword("-1999");
    customer.setNick("My New nick");
    customer.setCompany(" Apple");
    customer.setGender(CustomerGender.M);
    customer.setDateOfBirth(new Date());
    Billing billing = new Billing();
    billing.setAddress("Billing address");
    billing.setCity("Billing city");
    billing.setCompany("Billing company");
    billing.setCountry(country);
    billing.setFirstName("Carl");
    billing.setLastName("Samson");
    billing.setPostalCode("Billing postal code");
    billing.setState("Billing state");
    billing.setZone(zone);
    Delivery delivery = new Delivery();
    delivery.setAddress("Shipping address");
    delivery.setCountry(country);
    delivery.setZone(zone);
    customer.setBilling(billing);
    customer.setDelivery(delivery);
    customerService.create(customer);
    // create a product with attributes
    /**
     * CATALOG CREATION *
     */
    ProductType generalType = productTypeService.getProductType(ProductType.GENERAL_TYPE);
    /**
     * Create the category
     */
    Category shirts = new Category();
    shirts.setMerchantStore(merchant);
    shirts.setCode("shirts");
    CategoryDescription shirtsEnglishDescription = new CategoryDescription();
    shirtsEnglishDescription.setName("Shirts");
    shirtsEnglishDescription.setCategory(shirts);
    shirtsEnglishDescription.setLanguage(en);
    Set<CategoryDescription> descriptions = new HashSet<CategoryDescription>();
    descriptions.add(shirtsEnglishDescription);
    shirts.setDescriptions(descriptions);
    categoryService.create(shirts);
    /**
     * Create a manufacturer
     */
    Manufacturer addidas = new Manufacturer();
    addidas.setMerchantStore(merchant);
    addidas.setCode("addidas");
    ManufacturerDescription addidasDesc = new ManufacturerDescription();
    addidasDesc.setLanguage(en);
    addidasDesc.setManufacturer(addidas);
    addidasDesc.setName("Addidas");
    addidas.getDescriptions().add(addidasDesc);
    manufacturerService.create(addidas);
    /**
     * Create an option
     */
    ProductOption option = new ProductOption();
    option.setMerchantStore(merchant);
    option.setCode("color");
    option.setProductOptionType(ProductOptionType.Radio.name());
    ProductOptionDescription optionDescription = new ProductOptionDescription();
    optionDescription.setLanguage(en);
    optionDescription.setName("Color");
    optionDescription.setDescription("Item color");
    optionDescription.setProductOption(option);
    option.getDescriptions().add(optionDescription);
    productOptionService.saveOrUpdate(option);
    /**
     * first option value *
     */
    ProductOptionValue white = new ProductOptionValue();
    white.setMerchantStore(merchant);
    white.setCode("white");
    ProductOptionValueDescription whiteDescription = new ProductOptionValueDescription();
    whiteDescription.setLanguage(en);
    whiteDescription.setName("White");
    whiteDescription.setDescription("White color");
    whiteDescription.setProductOptionValue(white);
    white.getDescriptions().add(whiteDescription);
    productOptionValueService.saveOrUpdate(white);
    ProductOptionValue black = new ProductOptionValue();
    black.setMerchantStore(merchant);
    black.setCode("black");
    /**
     * second option value *
     */
    ProductOptionValueDescription blackDesc = new ProductOptionValueDescription();
    blackDesc.setLanguage(en);
    blackDesc.setName("Black");
    blackDesc.setDescription("Black color");
    blackDesc.setProductOptionValue(black);
    black.getDescriptions().add(blackDesc);
    productOptionValueService.saveOrUpdate(black);
    /**
     * Create a complex product
     */
    Product product = new Product();
    product.setProductHeight(new BigDecimal(4));
    product.setProductLength(new BigDecimal(3));
    product.setProductWidth(new BigDecimal(1));
    product.setSku("TB12345");
    product.setManufacturer(addidas);
    product.setType(generalType);
    product.setMerchantStore(merchant);
    // Product description
    ProductDescription description = new ProductDescription();
    description.setName("Short sleeves shirt");
    description.setLanguage(en);
    description.setProduct(product);
    product.getDescriptions().add(description);
    product.getCategories().add(shirts);
    // availability
    ProductAvailability availability = new ProductAvailability();
    availability.setProductDateAvailable(new Date());
    availability.setProductQuantity(100);
    availability.setRegion("*");
    // associate with product
    availability.setProduct(product);
    // price
    ProductPrice dprice = new ProductPrice();
    dprice.setDefaultPrice(true);
    dprice.setProductPriceAmount(new BigDecimal(29.99));
    dprice.setProductAvailability(availability);
    ProductPriceDescription dpd = new ProductPriceDescription();
    dpd.setName("Base price");
    dpd.setProductPrice(dprice);
    dpd.setLanguage(en);
    dprice.getDescriptions().add(dpd);
    availability.getPrices().add(dprice);
    product.getAvailabilities().add(availability);
    // attributes
    // white
    ProductAttribute whiteAttribute = new ProductAttribute();
    whiteAttribute.setProduct(product);
    whiteAttribute.setProductOption(option);
    whiteAttribute.setAttributeDefault(true);
    // no price variation
    whiteAttribute.setProductAttributePrice(new BigDecimal(0));
    // no weight variation
    whiteAttribute.setProductAttributeWeight(new BigDecimal(0));
    whiteAttribute.setProductOption(option);
    whiteAttribute.setProductOptionValue(white);
    product.getAttributes().add(whiteAttribute);
    // black
    ProductAttribute blackAttribute = new ProductAttribute();
    blackAttribute.setProduct(product);
    blackAttribute.setProductOption(option);
    // 5 + dollars
    blackAttribute.setProductAttributePrice(new BigDecimal(5));
    // no weight variation
    blackAttribute.setProductAttributeWeight(new BigDecimal(0));
    blackAttribute.setProductOption(option);
    blackAttribute.setProductOptionValue(black);
    product.getAttributes().add(blackAttribute);
    productService.create(product);
    /**
     * Create an order *
     */
    Order order = new Order();
    /**
     * payment details *
     */
    CreditCard creditCard = new CreditCard();
    creditCard.setCardType(CreditCardType.VISA);
    creditCard.setCcCvv("123");
    creditCard.setCcExpires("12/30/2020");
    creditCard.setCcNumber("123456789");
    creditCard.setCcOwner("ccOwner");
    order.setCreditCard(creditCard);
    /**
     * order core attributes *
     */
    order.setDatePurchased(new Date());
    order.setCurrency(currency);
    order.setMerchant(merchant);
    order.setLastModified(new Date());
    // no price variation because of the currency
    order.setCurrencyValue(new BigDecimal(1));
    order.setCustomerId(1L);
    order.setDelivery(delivery);
    order.setIpAddress("ipAddress");
    order.setMerchant(merchant);
    order.setOrderDateFinished(new Date());
    order.setPaymentType(PaymentType.CREDITCARD);
    order.setPaymentModuleCode("payment Module Code");
    order.setShippingModuleCode("UPS");
    order.setStatus(OrderStatus.ORDERED);
    order.setCustomerAgreement(true);
    order.setConfirmedAddress(true);
    order.setTotal(dprice.getProductPriceAmount());
    order.setCustomerEmailAddress(customer.getEmailAddress());
    order.setBilling(billing);
    order.setDelivery(delivery);
    /**
     * ORDER PRODUCT *
     */
    // OrderProduct
    OrderProduct oproduct = new OrderProduct();
    oproduct.setDownloads(null);
    oproduct.setOneTimeCharge(dprice.getProductPriceAmount());
    oproduct.setOrder(order);
    oproduct.setProductName(description.getName());
    oproduct.setProductQuantity(1);
    oproduct.setSku(product.getSku());
    // set order product price
    OrderProductPrice orderProductPrice = new OrderProductPrice();
    // default price (same as default product price)
    orderProductPrice.setDefaultPrice(true);
    orderProductPrice.setOrderProduct(oproduct);
    orderProductPrice.setProductPrice(dprice.getProductPriceAmount());
    orderProductPrice.setProductPriceCode(ProductPriceType.ONE_TIME.name());
    oproduct.getPrices().add(orderProductPrice);
    // order product attribute
    OrderProductAttribute orderProductAttribute = new OrderProductAttribute();
    orderProductAttribute.setOrderProduct(oproduct);
    // no extra charge
    orderProductAttribute.setProductAttributePrice(new BigDecimal("0.00"));
    orderProductAttribute.setProductAttributeName(whiteDescription.getName());
    orderProductAttribute.setProductOptionId(option.getId());
    orderProductAttribute.setProductOptionValueId(white.getId());
    oproduct.getOrderAttributes().add(orderProductAttribute);
    order.getOrderProducts().add(oproduct);
    /**
     * ORDER TOTAL *
     */
    OrderTotal subTotal = new OrderTotal();
    subTotal.setOrder(order);
    subTotal.setOrderTotalCode(Constants.OT_SUBTOTAL_MODULE_CODE);
    subTotal.setSortOrder(0);
    subTotal.setTitle("Sub Total");
    subTotal.setValue(dprice.getProductPriceAmount());
    order.getOrderTotal().add(subTotal);
    OrderTotal total = new OrderTotal();
    total.setOrder(order);
    total.setOrderTotalCode(Constants.OT_TOTAL_MODULE_CODE);
    total.setSortOrder(1);
    total.setTitle("Total");
    total.setValue(dprice.getProductPriceAmount());
    order.getOrderTotal().add(total);
    /**
     * ORDER HISTORY *
     */
    // create a log entry in order history
    OrderStatusHistory history = new OrderStatusHistory();
    history.setOrder(order);
    history.setDateAdded(new Date());
    history.setStatus(OrderStatus.ORDERED);
    history.setComments("We received your order");
    order.getOrderHistory().add(history);
    /**
     * CREATE ORDER *
     */
    orderService.create(order);
    /**
     * SEARCH ORDERS *
     */
    OrderCriteria criteria = new OrderCriteria();
    criteria.setStartIndex(0);
    criteria.setMaxCount(10);
    OrderList ordserList = orderService.listByStore(merchant, criteria);
    Assert.assertNotNull(ordserList);
    Assert.assertNotNull("Merchant Orders are null.", ordserList.getOrders());
    Assert.assertTrue("Merchant Orders count is not one.", (ordserList.getOrders() != null && ordserList.getOrders().size() == 1));
}
Also used : Category(com.salesmanager.core.model.catalog.category.Category) OrderProduct(com.salesmanager.core.model.order.orderproduct.OrderProduct) Customer(com.salesmanager.core.model.customer.Customer) OrderProduct(com.salesmanager.core.model.order.orderproduct.OrderProduct) Product(com.salesmanager.core.model.catalog.product.Product) ProductPrice(com.salesmanager.core.model.catalog.product.price.ProductPrice) OrderProductPrice(com.salesmanager.core.model.order.orderproduct.OrderProductPrice) ProductAttribute(com.salesmanager.core.model.catalog.product.attribute.ProductAttribute) OrderProductAttribute(com.salesmanager.core.model.order.orderproduct.OrderProductAttribute) ProductOptionDescription(com.salesmanager.core.model.catalog.product.attribute.ProductOptionDescription) ProductOptionValue(com.salesmanager.core.model.catalog.product.attribute.ProductOptionValue) Language(com.salesmanager.core.model.reference.language.Language) ProductAvailability(com.salesmanager.core.model.catalog.product.availability.ProductAvailability) Currency(com.salesmanager.core.model.reference.currency.Currency) Manufacturer(com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ProductPriceDescription(com.salesmanager.core.model.catalog.product.price.ProductPriceDescription) HashSet(java.util.HashSet) ProductOption(com.salesmanager.core.model.catalog.product.attribute.ProductOption) Order(com.salesmanager.core.model.order.Order) Zone(com.salesmanager.core.model.reference.zone.Zone) ProductType(com.salesmanager.core.model.catalog.product.type.ProductType) OrderCriteria(com.salesmanager.core.model.order.OrderCriteria) Date(java.util.Date) BigDecimal(java.math.BigDecimal) CreditCard(com.salesmanager.core.model.order.payment.CreditCard) Billing(com.salesmanager.core.model.common.Billing) OrderProductPrice(com.salesmanager.core.model.order.orderproduct.OrderProductPrice) OrderProductAttribute(com.salesmanager.core.model.order.orderproduct.OrderProductAttribute) Country(com.salesmanager.core.model.reference.country.Country) ManufacturerDescription(com.salesmanager.core.model.catalog.product.manufacturer.ManufacturerDescription) CategoryDescription(com.salesmanager.core.model.catalog.category.CategoryDescription) Delivery(com.salesmanager.core.model.common.Delivery) ProductDescription(com.salesmanager.core.model.catalog.product.description.ProductDescription) OrderList(com.salesmanager.core.model.order.OrderList) OrderTotal(com.salesmanager.core.model.order.OrderTotal) OrderStatusHistory(com.salesmanager.core.model.order.orderstatus.OrderStatusHistory) ProductOptionValueDescription(com.salesmanager.core.model.catalog.product.attribute.ProductOptionValueDescription) Test(org.junit.Test)

Aggregations

OrderTotal (com.salesmanager.core.model.order.OrderTotal)13 BigDecimal (java.math.BigDecimal)7 ShoppingCartItem (com.salesmanager.core.model.shoppingcart.ShoppingCartItem)5 ArrayList (java.util.ArrayList)5 ServiceException (com.salesmanager.core.business.exception.ServiceException)4 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)4 Language (com.salesmanager.core.model.reference.language.Language)4 ReadableOrderTotal (com.salesmanager.shop.model.order.total.ReadableOrderTotal)4 Date (java.util.Date)4 HashMap (java.util.HashMap)4 FinalPrice (com.salesmanager.core.model.catalog.product.price.FinalPrice)3 OrderTotalSummary (com.salesmanager.core.model.order.OrderTotalSummary)3 OrderProduct (com.salesmanager.core.model.order.orderproduct.OrderProduct)3 ReadableDelivery (com.salesmanager.shop.model.customer.ReadableDelivery)3 Product (com.salesmanager.core.model.catalog.product.Product)2 Customer (com.salesmanager.core.model.customer.Customer)2 Order (com.salesmanager.core.model.order.Order)2 Transaction (com.salesmanager.core.model.payments.Transaction)2 Country (com.salesmanager.core.model.reference.country.Country)2 Zone (com.salesmanager.core.model.reference.zone.Zone)2