Search in sources :

Example 1 with Currency

use of com.salesmanager.core.model.reference.currency.Currency in project shopizer by shopizer-ecommerce.

the class UtilsTestCase method testCurrency.

// @Test
@Ignore
public void testCurrency() throws Exception {
    Currency currency = currencyService.getByCode("BGN");
    java.util.Currency c = currency.getCurrency();
    NumberFormat numberFormat = NumberFormat.getCurrencyInstance(Locale.US);
    numberFormat.setCurrency(c);
    System.out.println("Done");
}
Also used : Currency(com.salesmanager.core.model.reference.currency.Currency) NumberFormat(java.text.NumberFormat) Ignore(org.junit.Ignore)

Example 2 with Currency

use of com.salesmanager.core.model.reference.currency.Currency in project shopizer by shopizer-ecommerce.

the class InitializationDatabaseImpl method createCurrencies.

private void createCurrencies() throws ServiceException {
    LOGGER.info(String.format("%s : Populating Currencies ", name));
    for (String code : SchemaConstant.CURRENCY_MAP.keySet()) {
        try {
            java.util.Currency c = java.util.Currency.getInstance(code);
            if (c == null) {
                LOGGER.info(String.format("%s : Populating Currencies : no currency for code : %s", name, code));
            }
            // check if it exist
            Currency currency = new Currency();
            currency.setName(c.getCurrencyCode());
            currency.setCurrency(c);
            currencyService.create(currency);
        // System.out.println(l.getCountry() + "   " + c.getSymbol() + "  " + c.getSymbol(l));
        } catch (IllegalArgumentException e) {
            LOGGER.info(String.format("%s : Populating Currencies : no currency for code : %s", name, code));
        }
    }
}
Also used : Currency(com.salesmanager.core.model.reference.currency.Currency)

Example 3 with Currency

use of com.salesmanager.core.model.reference.currency.Currency in project shopizer by shopizer-ecommerce.

the class InitializationDatabaseImpl method createMerchant.

private void createMerchant() throws ServiceException {
    LOGGER.info(String.format("%s : Creating merchant ", name));
    Date date = new Date(System.currentTimeMillis());
    Language en = languageService.getByCode("en");
    Country ca = countryService.getByCode("CA");
    Currency currency = currencyService.getByCode("CAD");
    Zone qc = zoneService.getByCode("QC");
    List<Language> supportedLanguages = new ArrayList<Language>();
    supportedLanguages.add(en);
    // create a merchant
    MerchantStore store = new MerchantStore();
    store.setCountry(ca);
    store.setCurrency(currency);
    store.setDefaultLanguage(en);
    store.setInBusinessSince(date);
    store.setZone(qc);
    store.setStorename("Default store");
    store.setStorephone("888-888-8888");
    store.setCode(MerchantStore.DEFAULT_STORE);
    store.setStorecity("My city");
    store.setStoreaddress("1234 Street address");
    store.setStorepostalcode("H2H-2H2");
    store.setStoreEmailAddress("john@test.com");
    store.setDomainName("localhost:8080");
    store.setStoreTemplate("december");
    store.setRetailer(true);
    store.setLanguages(supportedLanguages);
    merchantService.create(store);
    TaxClass taxclass = new TaxClass(TaxClass.DEFAULT_TAX_CLASS);
    taxclass.setMerchantStore(store);
    taxClassService.create(taxclass);
    // create default manufacturer
    Manufacturer defaultManufacturer = new Manufacturer();
    defaultManufacturer.setCode("DEFAULT");
    defaultManufacturer.setMerchantStore(store);
    ManufacturerDescription manufacturerDescription = new ManufacturerDescription();
    manufacturerDescription.setLanguage(en);
    manufacturerDescription.setName("DEFAULT");
    manufacturerDescription.setManufacturer(defaultManufacturer);
    manufacturerDescription.setDescription("DEFAULT");
    defaultManufacturer.getDescriptions().add(manufacturerDescription);
    manufacturerService.create(defaultManufacturer);
    Optin newsletter = new Optin();
    newsletter.setCode(OptinType.NEWSLETTER.name());
    newsletter.setMerchant(store);
    newsletter.setOptinType(OptinType.NEWSLETTER);
    optinService.create(newsletter);
}
Also used : Language(com.salesmanager.core.model.reference.language.Language) Optin(com.salesmanager.core.model.system.optin.Optin) Zone(com.salesmanager.core.model.reference.zone.Zone) Currency(com.salesmanager.core.model.reference.currency.Currency) ArrayList(java.util.ArrayList) Manufacturer(com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer) Country(com.salesmanager.core.model.reference.country.Country) ManufacturerDescription(com.salesmanager.core.model.catalog.product.manufacturer.ManufacturerDescription) TaxClass(com.salesmanager.core.model.tax.taxclass.TaxClass) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) Date(java.sql.Date)

Example 4 with Currency

use of com.salesmanager.core.model.reference.currency.Currency in project shopizer by shopizer-ecommerce.

the class PersistableOrderApiPopulator method populate.

@Override
public Order populate(PersistableOrder source, Order target, MerchantStore store, Language language) throws ConversionException {
    /*		Validate.notNull(currencyService,"currencyService must be set");
		Validate.notNull(customerService,"customerService must be set");
		Validate.notNull(shoppingCartService,"shoppingCartService must be set");
		Validate.notNull(productService,"productService must be set");
		Validate.notNull(productAttributeService,"productAttributeService must be set");
		Validate.notNull(digitalProductService,"digitalProductService must be set");*/
    Validate.notNull(source.getPayment(), "Payment cannot be null");
    try {
        if (target == null) {
            target = new Order();
        }
        // target.setLocale(LocaleUtils.getLocale(store));
        target.setLocale(LocaleUtils.getLocale(store));
        Currency currency = null;
        try {
            currency = currencyService.getByCode(source.getCurrency());
        } catch (Exception e) {
            throw new ConversionException("Currency not found for code " + source.getCurrency());
        }
        if (currency == null) {
            throw new ConversionException("Currency not found for code " + source.getCurrency());
        }
        // Customer
        Customer customer = null;
        if (source.getCustomerId() != null && source.getCustomerId().longValue() > 0) {
            Long customerId = source.getCustomerId();
            customer = customerService.getById(customerId);
            if (customer == null) {
                throw new ConversionException("Curstomer with id " + source.getCustomerId() + " does not exist");
            }
            target.setCustomerId(customerId);
        } else {
            if (source instanceof PersistableAnonymousOrder) {
                PersistableCustomer persistableCustomer = ((PersistableAnonymousOrder) source).getCustomer();
                customer = new Customer();
                customer = customerPopulator.populate(persistableCustomer, customer, store, language);
            } else {
                throw new ConversionException("Curstomer details or id not set in request");
            }
        }
        target.setCustomerEmailAddress(customer.getEmailAddress());
        Delivery delivery = customer.getDelivery();
        target.setDelivery(delivery);
        Billing billing = customer.getBilling();
        target.setBilling(billing);
        if (source.getAttributes() != null && source.getAttributes().size() > 0) {
            Set<OrderAttribute> attrs = new HashSet<OrderAttribute>();
            for (com.salesmanager.shop.model.order.OrderAttribute attribute : source.getAttributes()) {
                OrderAttribute attr = new OrderAttribute();
                attr.setKey(attribute.getKey());
                attr.setValue(attribute.getValue());
                attr.setOrder(target);
                attrs.add(attr);
            }
            target.setOrderAttributes(attrs);
        }
        target.setDatePurchased(new Date());
        target.setCurrency(currency);
        target.setCurrencyValue(new BigDecimal(0));
        target.setMerchant(store);
        target.setChannel(OrderChannel.API);
        // need this
        target.setStatus(OrderStatus.ORDERED);
        target.setPaymentModuleCode(source.getPayment().getPaymentModule());
        target.setPaymentType(PaymentType.valueOf(source.getPayment().getPaymentType()));
        target.setCustomerAgreement(source.isCustomerAgreement());
        // force this to true, cannot perform this activity from the API
        target.setConfirmedAddress(true);
        if (!StringUtils.isBlank(source.getComments())) {
            OrderStatusHistory statusHistory = new OrderStatusHistory();
            statusHistory.setStatus(null);
            statusHistory.setOrder(target);
            statusHistory.setComments(source.getComments());
            target.getOrderHistory().add(statusHistory);
        }
        return target;
    } catch (Exception e) {
        throw new ConversionException(e);
    }
}
Also used : PersistableAnonymousOrder(com.salesmanager.shop.model.order.v1.PersistableAnonymousOrder) Order(com.salesmanager.core.model.order.Order) PersistableOrder(com.salesmanager.shop.model.order.v1.PersistableOrder) ConversionException(com.salesmanager.core.business.exception.ConversionException) Customer(com.salesmanager.core.model.customer.Customer) PersistableCustomer(com.salesmanager.shop.model.customer.PersistableCustomer) PersistableCustomer(com.salesmanager.shop.model.customer.PersistableCustomer) ConversionException(com.salesmanager.core.business.exception.ConversionException) Date(java.util.Date) BigDecimal(java.math.BigDecimal) Currency(com.salesmanager.core.model.reference.currency.Currency) Billing(com.salesmanager.core.model.common.Billing) OrderAttribute(com.salesmanager.core.model.order.attributes.OrderAttribute) PersistableAnonymousOrder(com.salesmanager.shop.model.order.v1.PersistableAnonymousOrder) Delivery(com.salesmanager.core.model.common.Delivery) OrderStatusHistory(com.salesmanager.core.model.order.orderstatus.OrderStatusHistory) HashSet(java.util.HashSet)

Example 5 with Currency

use of com.salesmanager.core.model.reference.currency.Currency in project shopizer by shopizer-ecommerce.

the class PersistableOrderPopulator method populate.

@Override
public Order populate(PersistableOrder source, Order target, MerchantStore store, Language language) throws ConversionException {
    Validate.notNull(productService, "productService must be set");
    Validate.notNull(digitalProductService, "digitalProductService must be set");
    Validate.notNull(productAttributeService, "productAttributeService must be set");
    Validate.notNull(customerService, "customerService must be set");
    Validate.notNull(countryService, "countryService must be set");
    Validate.notNull(zoneService, "zoneService must be set");
    Validate.notNull(currencyService, "currencyService must be set");
    try {
        Map<String, Country> countriesMap = countryService.getCountriesMap(language);
        Map<String, Zone> zonesMap = zoneService.getZones(language);
        /**
         * customer *
         */
        PersistableCustomer customer = source.getCustomer();
        if (customer != null) {
            if (customer.getId() != null && customer.getId() > 0) {
                Customer modelCustomer = customerService.getById(customer.getId());
                if (modelCustomer == null) {
                    throw new ConversionException("Customer id " + customer.getId() + " does not exists");
                }
                if (modelCustomer.getMerchantStore().getId().intValue() != store.getId().intValue()) {
                    throw new ConversionException("Customer id " + customer.getId() + " does not exists for store " + store.getCode());
                }
                target.setCustomerId(modelCustomer.getId());
                target.setBilling(modelCustomer.getBilling());
                target.setDelivery(modelCustomer.getDelivery());
                target.setCustomerEmailAddress(source.getCustomer().getEmailAddress());
            }
        }
        target.setLocale(LocaleUtils.getLocale(store));
        CreditCard creditCard = source.getCreditCard();
        if (creditCard != null) {
            String maskedNumber = CreditCardUtils.maskCardNumber(creditCard.getCcNumber());
            creditCard.setCcNumber(maskedNumber);
            target.setCreditCard(creditCard);
        }
        Currency currency = null;
        try {
            currency = currencyService.getByCode(source.getCurrency());
        } catch (Exception e) {
            throw new ConversionException("Currency not found for code " + source.getCurrency());
        }
        if (currency == null) {
            throw new ConversionException("Currency not found for code " + source.getCurrency());
        }
        target.setCurrency(currency);
        target.setDatePurchased(source.getDatePurchased());
        // target.setCurrency(store.getCurrency());
        target.setCurrencyValue(new BigDecimal(0));
        target.setMerchant(store);
        target.setStatus(source.getOrderStatus());
        target.setPaymentModuleCode(source.getPaymentModule());
        target.setPaymentType(source.getPaymentType());
        target.setShippingModuleCode(source.getShippingModule());
        target.setCustomerAgreement(source.isCustomerAgreed());
        target.setConfirmedAddress(source.isConfirmedAddress());
        if (source.getPreviousOrderStatus() != null) {
            List<OrderStatus> orderStatusList = source.getPreviousOrderStatus();
            for (OrderStatus status : orderStatusList) {
                OrderStatusHistory statusHistory = new OrderStatusHistory();
                statusHistory.setStatus(status);
                statusHistory.setOrder(target);
                target.getOrderHistory().add(statusHistory);
            }
        }
        if (!StringUtils.isBlank(source.getComments())) {
            OrderStatusHistory statusHistory = new OrderStatusHistory();
            statusHistory.setStatus(null);
            statusHistory.setOrder(target);
            statusHistory.setComments(source.getComments());
            target.getOrderHistory().add(statusHistory);
        }
        List<PersistableOrderProduct> products = source.getOrderProductItems();
        if (CollectionUtils.isEmpty(products)) {
            throw new ConversionException("Requires at least 1 PersistableOrderProduct");
        }
        com.salesmanager.shop.populator.order.PersistableOrderProductPopulator orderProductPopulator = new PersistableOrderProductPopulator();
        orderProductPopulator.setProductAttributeService(productAttributeService);
        orderProductPopulator.setProductService(productService);
        orderProductPopulator.setDigitalProductService(digitalProductService);
        for (PersistableOrderProduct orderProduct : products) {
            OrderProduct modelOrderProduct = new OrderProduct();
            orderProductPopulator.populate(orderProduct, modelOrderProduct, store, language);
            target.getOrderProducts().add(modelOrderProduct);
        }
        List<OrderTotal> orderTotals = source.getTotals();
        if (CollectionUtils.isNotEmpty(orderTotals)) {
            for (OrderTotal total : orderTotals) {
                com.salesmanager.core.model.order.OrderTotal totalModel = new com.salesmanager.core.model.order.OrderTotal();
                totalModel.setModule(total.getModule());
                totalModel.setOrder(target);
                totalModel.setOrderTotalCode(total.getCode());
                totalModel.setTitle(total.getTitle());
                totalModel.setValue(total.getValue());
                target.getOrderTotal().add(totalModel);
            }
        }
    } catch (Exception e) {
        throw new ConversionException(e);
    }
    return target;
}
Also used : OrderProduct(com.salesmanager.core.model.order.orderproduct.OrderProduct) PersistableOrderProduct(com.salesmanager.shop.model.order.PersistableOrderProduct) Customer(com.salesmanager.core.model.customer.Customer) PersistableCustomer(com.salesmanager.shop.model.customer.PersistableCustomer) PersistableCustomer(com.salesmanager.shop.model.customer.PersistableCustomer) PersistableOrderProduct(com.salesmanager.shop.model.order.PersistableOrderProduct) OrderStatus(com.salesmanager.core.model.order.orderstatus.OrderStatus) Currency(com.salesmanager.core.model.reference.currency.Currency) ConversionException(com.salesmanager.core.business.exception.ConversionException) Zone(com.salesmanager.core.model.reference.zone.Zone) CreditCard(com.salesmanager.core.model.order.payment.CreditCard) ConversionException(com.salesmanager.core.business.exception.ConversionException) BigDecimal(java.math.BigDecimal) Country(com.salesmanager.core.model.reference.country.Country) OrderStatusHistory(com.salesmanager.core.model.order.orderstatus.OrderStatusHistory) OrderTotal(com.salesmanager.shop.model.order.total.OrderTotal)

Aggregations

Currency (com.salesmanager.core.model.reference.currency.Currency)7 Country (com.salesmanager.core.model.reference.country.Country)4 Zone (com.salesmanager.core.model.reference.zone.Zone)4 ConversionException (com.salesmanager.core.business.exception.ConversionException)3 Customer (com.salesmanager.core.model.customer.Customer)3 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)3 OrderStatusHistory (com.salesmanager.core.model.order.orderstatus.OrderStatusHistory)3 Language (com.salesmanager.core.model.reference.language.Language)3 BigDecimal (java.math.BigDecimal)3 Date (java.util.Date)3 Manufacturer (com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer)2 ManufacturerDescription (com.salesmanager.core.model.catalog.product.manufacturer.ManufacturerDescription)2 Billing (com.salesmanager.core.model.common.Billing)2 Delivery (com.salesmanager.core.model.common.Delivery)2 Order (com.salesmanager.core.model.order.Order)2 OrderProduct (com.salesmanager.core.model.order.orderproduct.OrderProduct)2 CreditCard (com.salesmanager.core.model.order.payment.CreditCard)2 PersistableCustomer (com.salesmanager.shop.model.customer.PersistableCustomer)2 HashSet (java.util.HashSet)2 ServiceException (com.salesmanager.core.business.exception.ServiceException)1