Search in sources :

Example 6 with Locale

use of org.broadleafcommerce.common.locale.domain.Locale in project BroadleafCommerce by BroadleafCommerce.

the class LocaleDaoImpl method findLocaleByCode.

/**
 * @return The locale for the passed in code
 */
@Override
public Locale findLocaleByCode(String localeCode) {
    Query query = em.createNamedQuery("BC_READ_LOCALE_BY_CODE");
    query.setParameter("localeCode", localeCode);
    query.setHint(org.hibernate.ejb.QueryHints.HINT_CACHEABLE, true);
    List<Locale> localeList = (List<Locale>) query.getResultList();
    if (localeList.size() >= 1) {
        if (localeList.size() > 1) {
            LOG.warn("Locale code " + StringUtil.sanitize(localeCode) + " exists for more than one locale");
        }
        return localeList.get(0);
    }
    return null;
}
Also used : Locale(org.broadleafcommerce.common.locale.domain.Locale) Query(javax.persistence.Query) List(java.util.List)

Example 7 with Locale

use of org.broadleafcommerce.common.locale.domain.Locale in project BroadleafCommerce by BroadleafCommerce.

the class LocaleDaoImpl method findDefaultLocale.

/**
 * Returns the page template with the passed in id.
 *
 * @return The default locale
 */
@Override
public Locale findDefaultLocale() {
    Query query = em.createNamedQuery("BC_READ_DEFAULT_LOCALE");
    query.setHint(org.hibernate.ejb.QueryHints.HINT_CACHEABLE, true);
    List<Locale> localeList = (List<Locale>) query.getResultList();
    if (localeList.size() >= 1) {
        if (localeList.size() > 1) {
            LOG.warn("There is more than one default locale configured");
        }
        return localeList.get(0);
    }
    return null;
}
Also used : Locale(org.broadleafcommerce.common.locale.domain.Locale) Query(javax.persistence.Query) List(java.util.List)

Example 8 with Locale

use of org.broadleafcommerce.common.locale.domain.Locale in project BroadleafCommerce by BroadleafCommerce.

the class OrderDaoImpl method readNamedOrderForCustomer.

@Override
@SuppressWarnings("unchecked")
public Order readNamedOrderForCustomer(final Customer customer, final String name) {
    final Query query = em.createNamedQuery("BC_READ_NAMED_ORDER_FOR_CUSTOMER");
    query.setParameter("customerId", customer.getId());
    query.setParameter("orderStatus", OrderStatus.NAMED.getType());
    query.setParameter("orderName", name);
    query.setHint(QueryHints.HINT_CACHEABLE, true);
    query.setHint(QueryHints.HINT_CACHE_REGION, "query.Order");
    List<Order> orders = query.getResultList();
    // Filter out orders that don't match the current locale (if one is set)
    if (BroadleafRequestContext.getBroadleafRequestContext() != null) {
        ListIterator<Order> iter = orders.listIterator();
        while (iter.hasNext()) {
            Locale locale = BroadleafRequestContext.getBroadleafRequestContext().getLocale();
            Order order = iter.next();
            if (locale != null && !locale.equals(order.getLocale())) {
                iter.remove();
            }
        }
    }
    // Apply any additional filters that extension modules have registered
    if (orders != null && !orders.isEmpty() && extensionManager != null) {
        extensionManager.getProxy().applyAdditionalOrderLookupFilter(customer, name, orders);
    }
    return orders == null || orders.isEmpty() ? null : orders.get(0);
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) Locale(org.broadleafcommerce.common.locale.domain.Locale) TypedQuery(javax.persistence.TypedQuery) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Query(javax.persistence.Query)

Example 9 with Locale

use of org.broadleafcommerce.common.locale.domain.Locale in project BroadleafCommerce by BroadleafCommerce.

the class I18nSolrIndexServiceExtensionHandler method addPropertyValues.

@Override
public ExtensionResultStatusType addPropertyValues(Indexable indexable, Field field, FieldType fieldType, Map<String, Object> values, String propertyName, List<Locale> locales) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    Set<String> processedLocaleCodes = new HashSet<String>();
    ExtensionResultStatusType result = ExtensionResultStatusType.NOT_HANDLED;
    if (field.getTranslatable()) {
        result = ExtensionResultStatusType.HANDLED;
        TranslationConsiderationContext.setTranslationConsiderationContext(getTranslationEnabled());
        TranslationConsiderationContext.setTranslationService(translationService);
        BroadleafRequestContext tempContext = BroadleafRequestContext.getBroadleafRequestContext();
        if (tempContext == null) {
            tempContext = new BroadleafRequestContext();
            BroadleafRequestContext.setBroadleafRequestContext(tempContext);
        }
        Locale originalLocale = tempContext.getLocale();
        try {
            for (Locale locale : locales) {
                String localeCode = locale.getLocaleCode();
                if (Boolean.FALSE.equals(locale.getUseCountryInSearchIndex())) {
                    int pos = localeCode.indexOf("_");
                    if (pos > 0) {
                        localeCode = localeCode.substring(0, pos);
                        if (processedLocaleCodes.contains(localeCode)) {
                            continue;
                        } else {
                            locale = localeService.findLocaleByCode(localeCode);
                        }
                    }
                }
                processedLocaleCodes.add(localeCode);
                tempContext.setLocale(locale);
                Object propertyValue = shs.getPropertyValue(indexable, propertyName);
                values.put(localeCode, propertyValue);
            }
        } finally {
            // Reset the original locale.
            tempContext.setLocale(originalLocale);
        }
    }
    return result;
}
Also used : Locale(org.broadleafcommerce.common.locale.domain.Locale) BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType) HashSet(java.util.HashSet)

Example 10 with Locale

use of org.broadleafcommerce.common.locale.domain.Locale in project BroadleafCommerce by BroadleafCommerce.

the class I18nSolrIndexServiceExtensionHandler method getLocalePrefix.

/**
 * If the field is translatable, take the current locale and add that as a prefix.
 * @param context
 * @param field
 * @return
 */
protected ExtensionResultStatusType getLocalePrefix(Field field, List<String> prefixList) {
    if (field.getTranslatable()) {
        if (BroadleafRequestContext.getBroadleafRequestContext() != null) {
            Locale locale = BroadleafRequestContext.getBroadleafRequestContext().getLocale();
            if (locale != null) {
                String localeCode = locale.getLocaleCode();
                if (!Boolean.TRUE.equals(locale.getUseCountryInSearchIndex())) {
                    int pos = localeCode.indexOf("_");
                    if (pos > 0) {
                        localeCode = localeCode.substring(0, pos);
                    }
                }
                prefixList.add(localeCode);
                return ExtensionResultStatusType.HANDLED_CONTINUE;
            }
        }
    }
    return ExtensionResultStatusType.NOT_HANDLED;
}
Also used : Locale(org.broadleafcommerce.common.locale.domain.Locale)

Aggregations

Locale (org.broadleafcommerce.common.locale.domain.Locale)24 BroadleafRequestContext (org.broadleafcommerce.common.web.BroadleafRequestContext)8 HashMap (java.util.HashMap)7 Map (java.util.Map)5 ArrayList (java.util.ArrayList)4 Site (org.broadleafcommerce.common.site.domain.Site)4 StructuredContentDTO (org.broadleafcommerce.common.structure.dto.StructuredContentDTO)4 List (java.util.List)3 Query (javax.persistence.Query)3 StructuredContent (org.broadleafcommerce.cms.structure.domain.StructuredContent)3 BroadleafRequestedCurrencyDto (org.broadleafcommerce.common.currency.domain.BroadleafRequestedCurrencyDto)3 IOException (java.io.IOException)2 TimeZone (java.util.TimeZone)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 BroadleafCurrency (org.broadleafcommerce.common.currency.domain.BroadleafCurrency)2 LocaleImpl (org.broadleafcommerce.common.locale.domain.LocaleImpl)2 SandBox (org.broadleafcommerce.common.sandbox.domain.SandBox)2 ComboField (org.broadleafcommerce.openadmin.web.form.entity.ComboField)2 BigDecimal (java.math.BigDecimal)1 NumberFormat (java.text.NumberFormat)1