Search in sources :

Example 1 with MerchantConfig

use of com.salesmanager.core.model.system.MerchantConfig in project shopizer by shopizer-ecommerce.

the class StoreFilter method getConfigurations.

@SuppressWarnings("unused")
private Map<String, Object> getConfigurations(MerchantStore store) {
    Map<String, Object> configs = new HashMap<String, Object>();
    try {
        List<MerchantConfiguration> merchantConfiguration = merchantConfigurationService.listByType(MerchantConfigurationType.CONFIG, store);
        // get social
        List<MerchantConfiguration> socialConfigs = merchantConfigurationService.listByType(MerchantConfigurationType.SOCIAL, store);
        if (!CollectionUtils.isEmpty(socialConfigs)) {
            if (CollectionUtils.isEmpty(merchantConfiguration)) {
                merchantConfiguration = new ArrayList<MerchantConfiguration>();
            }
            merchantConfiguration.addAll(socialConfigs);
        }
        if (CollectionUtils.isEmpty(merchantConfiguration)) {
            return configs;
        }
        for (MerchantConfiguration configuration : merchantConfiguration) {
            configs.put(configuration.getKey(), configuration.getValue());
        }
        configs.put(Constants.SHOP_SCHEME, coreConfiguration.getProperty(Constants.SHOP_SCHEME));
        configs.put(Constants.FACEBOOK_APP_ID, coreConfiguration.getProperty(Constants.FACEBOOK_APP_ID));
        // get MerchantConfig
        MerchantConfig merchantConfig = merchantConfigurationService.getMerchantConfig(store);
        if (merchantConfig != null) {
            if (configs == null) {
                configs = new HashMap<String, Object>();
            }
            ObjectMapper m = new ObjectMapper();
            @SuppressWarnings("unchecked") Map<String, Object> props = m.convertValue(merchantConfig, Map.class);
            for (String key : props.keySet()) {
                configs.put(key, props.get(key));
            }
        }
    } catch (Exception e) {
        LOGGER.error("Exception while getting configurations", e);
    }
    return configs;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) MerchantConfiguration(com.salesmanager.core.model.system.MerchantConfiguration) MerchantConfig(com.salesmanager.core.model.system.MerchantConfig) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with MerchantConfig

use of com.salesmanager.core.model.system.MerchantConfig in project shopizer by shopizer-ecommerce.

the class MerchantConfigurationServiceImpl method getMerchantConfig.

@Override
public MerchantConfig getMerchantConfig(MerchantStore store) throws ServiceException {
    MerchantConfiguration configuration = merchantConfigurationRepository.findByMerchantStoreAndKey(store.getId(), MerchantConfigurationType.CONFIG.name());
    MerchantConfig config = null;
    if (configuration != null) {
        String value = configuration.getValue();
        ObjectMapper mapper = new ObjectMapper();
        try {
            config = mapper.readValue(value, MerchantConfig.class);
        } catch (Exception e) {
            throw new ServiceException("Cannot parse json string " + value);
        }
    }
    return config;
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) MerchantConfiguration(com.salesmanager.core.model.system.MerchantConfiguration) MerchantConfig(com.salesmanager.core.model.system.MerchantConfig) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ServiceException(com.salesmanager.core.business.exception.ServiceException)

Example 3 with MerchantConfig

use of com.salesmanager.core.model.system.MerchantConfig in project shopizer by shopizer-ecommerce.

the class MerchantConfigurationFacadeImpl method getMerchantConfig.

@Override
public Configs getMerchantConfig(MerchantStore merchantStore, Language language) {
    MerchantConfig configs = getMerchantConfig(merchantStore);
    Configs readableConfig = new Configs();
    readableConfig.setAllowOnlinePurchase(configs.isAllowPurchaseItems());
    readableConfig.setDisplaySearchBox(configs.isDisplaySearchBox());
    readableConfig.setDisplayContactUs(configs.isDisplayContactUs());
    readableConfig.setDisplayCustomerSection(configs.isDisplayCustomerSection());
    readableConfig.setDisplayAddToCartOnFeaturedItems(configs.isDisplayAddToCartOnFeaturedItems());
    readableConfig.setDisplayCustomerAgreement(configs.isDisplayCustomerAgreement());
    readableConfig.setDisplayPagesMenu(configs.isDisplayPagesMenu());
    Optional<String> facebookConfigValue = getConfigValue(KEY_FACEBOOK_PAGE_URL, merchantStore);
    facebookConfigValue.ifPresent(readableConfig::setFacebook);
    Optional<String> googleConfigValue = getConfigValue(KEY_GOOGLE_ANALYTICS_URL, merchantStore);
    googleConfigValue.ifPresent(readableConfig::setGa);
    Optional<String> instagramConfigValue = getConfigValue(KEY_INSTAGRAM_URL, merchantStore);
    instagramConfigValue.ifPresent(readableConfig::setInstagram);
    Optional<String> pinterestConfigValue = getConfigValue(KEY_PINTEREST_PAGE_URL, merchantStore);
    pinterestConfigValue.ifPresent(readableConfig::setPinterest);
    readableConfig.setDisplayShipping(false);
    try {
        if (!StringUtils.isBlank(displayShipping)) {
            readableConfig.setDisplayShipping(Boolean.valueOf(displayShipping));
        }
    } catch (Exception e) {
        LOGGER.error("Cannot parse value of " + displayShipping);
    }
    return readableConfig;
}
Also used : Configs(com.salesmanager.shop.model.system.Configs) MerchantConfig(com.salesmanager.core.model.system.MerchantConfig) ServiceException(com.salesmanager.core.business.exception.ServiceException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 4 with MerchantConfig

use of com.salesmanager.core.model.system.MerchantConfig in project shopizer by shopizer-ecommerce.

the class InitializationLoader method init.

@PostConstruct
public void init() {
    try {
        // Check flag to populate or not the database
        if (!this.initDefaultData) {
            return;
        }
        if (initializationDatabase.isEmpty()) {
            // All default data to be created
            LOGGER.info(String.format("%s : Shopizer database is empty, populate it....", "sm-shop"));
            initializationDatabase.populate("sm-shop");
            MerchantStore store = merchantService.getByCode(MerchantStore.DEFAULT_STORE);
            userDetailsService.createDefaultAdmin();
            MerchantConfig config = new MerchantConfig();
            config.setAllowPurchaseItems(true);
            config.setDisplayAddToCartOnFeaturedItems(true);
            merchantConfigurationService.saveMerchantConfig(config, store);
        }
    } catch (Exception e) {
        LOGGER.error("Error in the init method", e);
    }
}
Also used : MerchantConfig(com.salesmanager.core.model.system.MerchantConfig) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ServiceException(com.salesmanager.core.business.exception.ServiceException) PostConstruct(javax.annotation.PostConstruct)

Aggregations

MerchantConfig (com.salesmanager.core.model.system.MerchantConfig)4 ServiceException (com.salesmanager.core.business.exception.ServiceException)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 MerchantConfiguration (com.salesmanager.core.model.system.MerchantConfiguration)2 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)1 Configs (com.salesmanager.shop.model.system.Configs)1 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 PostConstruct (javax.annotation.PostConstruct)1