Search in sources :

Example 26 with BroadleafRequestContext

use of org.broadleafcommerce.common.web.BroadleafRequestContext in project BroadleafCommerce by BroadleafCommerce.

the class RemoveFacetValuesLinkProcessor method getModifiedAttributes.

@Override
public BroadleafAttributeModifier getModifiedAttributes(String tagName, Map<String, String> tagAttributes, String attributeName, String attributeValue, BroadleafTemplateContext context) {
    BroadleafRequestContext blcContext = BroadleafRequestContext.getBroadleafRequestContext();
    HttpServletRequest request = blcContext.getRequest();
    String baseUrl = request.getRequestURL().toString();
    Map<String, String[]> params = new HashMap<>(request.getParameterMap());
    SearchFacetDTO facet = (SearchFacetDTO) context.parseExpression(attributeValue);
    String key = searchFacetDTOService.getUrlKey(facet);
    params.remove(key);
    params.remove(SearchCriteria.PAGE_NUMBER);
    String url = ProcessorUtils.getUrl(baseUrl, params);
    Map<String, String> newAttributes = new HashMap<>();
    newAttributes.put("href", url);
    return new BroadleafAttributeModifier(newAttributes);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HashMap(java.util.HashMap) BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext) SearchFacetDTO(org.broadleafcommerce.core.search.domain.SearchFacetDTO) BroadleafAttributeModifier(org.broadleafcommerce.presentation.model.BroadleafAttributeModifier)

Example 27 with BroadleafRequestContext

use of org.broadleafcommerce.common.web.BroadleafRequestContext in project BroadleafCommerce by BroadleafCommerce.

the class ToggleFacetLinkProcessor method getModifiedAttributes.

@Override
public BroadleafAttributeModifier getModifiedAttributes(String tagName, Map<String, String> tagAttributes, String attributeName, String attributeValue, BroadleafTemplateContext context) {
    BroadleafRequestContext blcContext = BroadleafRequestContext.getBroadleafRequestContext();
    HttpServletRequest request = blcContext.getRequest();
    String baseUrl = request.getRequestURL().toString();
    Map<String, String[]> params = new HashMap<>(request.getParameterMap());
    SearchFacetResultDTO result = (SearchFacetResultDTO) context.parseExpression(attributeValue);
    String key = facetService.getUrlKey(result);
    String value = facetService.getValue(result);
    String[] paramValues = params.get(key);
    if (ArrayUtils.contains(paramValues, facetService.getValue(result))) {
        paramValues = (String[]) ArrayUtils.removeElement(paramValues, facetService.getValue(result));
    } else {
        paramValues = (String[]) ArrayUtils.add(paramValues, value);
    }
    params.remove(SearchCriteria.PAGE_NUMBER);
    params.put(key, paramValues);
    String url = ProcessorUtils.getUrl(baseUrl, params);
    Map<String, String> newAttributes = new HashMap<>();
    newAttributes.put("href", url);
    return new BroadleafAttributeModifier(newAttributes);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HashMap(java.util.HashMap) BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext) SearchFacetResultDTO(org.broadleafcommerce.core.search.domain.SearchFacetResultDTO) BroadleafAttributeModifier(org.broadleafcommerce.presentation.model.BroadleafAttributeModifier)

Example 28 with BroadleafRequestContext

use of org.broadleafcommerce.common.web.BroadleafRequestContext in project BroadleafCommerce by BroadleafCommerce.

the class i18nUpdateCartServiceExtensionHandler method updateAndValidateCart.

/**
 * If the locale of the cart does not match the current locale, then this extension handler will
 * attempt to translate the order items.
 *
 * The property "clearCartOnLocaleSwitch" can be set to true if the implementation desires to
 * create a new cart when the locale is switched (3.0.6 and prior behavior).
 *
 * @param cart
 * @param resultHolder
 * @return
 */
public ExtensionResultStatusType updateAndValidateCart(Order cart, ExtensionResultHolder resultHolder) {
    if (BroadleafRequestContext.hasLocale()) {
        BroadleafRequestContext brc = BroadleafRequestContext.getBroadleafRequestContext();
        if (!brc.getLocale().getLocaleCode().matches(cart.getLocale().getLocaleCode())) {
            if (LOG.isDebugEnabled()) {
                String message = "The cart Locale [" + StringUtil.sanitize(cart.getLocale().getLocaleCode()) + "] does not match the current locale [" + StringUtil.sanitize(brc.getLocale().getLocaleCode()) + "]";
                LOG.debug(message);
            }
            if (getClearCartOnLocaleSwitch()) {
                resultHolder.getContextMap().put("clearCart", Boolean.TRUE);
            } else {
                fixTranslations(cart);
                cart.setLocale(brc.getLocale());
                resultHolder.getContextMap().put("saveCart", Boolean.TRUE);
            }
        }
    }
    return ExtensionResultStatusType.HANDLED_CONTINUE;
}
Also used : BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext)

Example 29 with BroadleafRequestContext

use of org.broadleafcommerce.common.web.BroadleafRequestContext in project BroadleafCommerce by BroadleafCommerce.

the class AbstractRuleBuilderFieldService method constructFieldDTOFromFieldData.

protected FieldDTO constructFieldDTOFromFieldData(FieldData field) {
    FieldDTO fieldDTO = new FieldDTO();
    // translate the label to display
    String label = field.getFieldLabel();
    BroadleafRequestContext context = BroadleafRequestContext.getBroadleafRequestContext();
    MessageSource messages = context.getMessageSource();
    if (messages != null) {
        label = messages.getMessage(label, null, label, context.getJavaLocale());
    }
    fieldDTO.setLabel(label);
    fieldDTO.setId(field.getFieldName());
    fieldDTO.setOperators(field.getOperators());
    fieldDTO.setSelectizeSectionKey(field.getSelectizeSectionKey());
    fieldDTO.setValues(field.getOptions());
    if (SupportedFieldType.BROADLEAF_ENUMERATION.equals(field.getFieldType())) {
        fieldDTO.setInput("select");
    } else {
        fieldDTO.setInput("text");
    }
    return fieldDTO;
}
Also used : BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext) MessageSource(org.springframework.context.MessageSource) FieldDTO(org.broadleafcommerce.openadmin.web.rulebuilder.dto.FieldDTO)

Example 30 with BroadleafRequestContext

use of org.broadleafcommerce.common.web.BroadleafRequestContext in project BroadleafCommerce by BroadleafCommerce.

the class IdentityExecutionUtils method runOperationByIdentifier.

public static <T, G extends Throwable> T runOperationByIdentifier(IdentityOperation<T, G> operation, Site site, Site profile, Catalog catalog, PlatformTransactionManager transactionManager) throws G {
    IdentityUtilContext context = new IdentityUtilContext();
    context.setIdentifier(site);
    IdentityUtilContext.setUtilContext(context);
    BroadleafRequestContext brc = BroadleafRequestContext.getBroadleafRequestContext();
    Site previousSite = brc.getSite();
    Catalog previousCatalog = brc.getCurrentCatalog();
    Site previousProfile = brc.getCurrentProfile();
    boolean isNew = initRequestContext(site, profile, catalog);
    activateSession();
    TransactionContainer container = null;
    if (transactionManager != null) {
        container = establishTransaction(transactionManager);
    }
    boolean isError = false;
    try {
        return operation.execute();
    } catch (RuntimeException e) {
        isError = true;
        throw e;
    } finally {
        if (container != null) {
            finalizeTransaction(transactionManager, container, isError);
        }
        IdentityUtilContext.setUtilContext(null);
        if (isNew) {
            BroadleafRequestContext.setBroadleafRequestContext(null);
        }
        BroadleafRequestContext.getBroadleafRequestContext().setSite(previousSite);
        BroadleafRequestContext.getBroadleafRequestContext().setCurrentCatalog(previousCatalog);
        BroadleafRequestContext.getBroadleafRequestContext().setCurrentProfile(previousProfile);
    }
}
Also used : Site(org.broadleafcommerce.common.site.domain.Site) BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext) Catalog(org.broadleafcommerce.common.site.domain.Catalog)

Aggregations

BroadleafRequestContext (org.broadleafcommerce.common.web.BroadleafRequestContext)78 Site (org.broadleafcommerce.common.site.domain.Site)16 HashMap (java.util.HashMap)12 HttpServletRequest (javax.servlet.http.HttpServletRequest)11 ArrayList (java.util.ArrayList)9 Map (java.util.Map)9 Locale (org.broadleafcommerce.common.locale.domain.Locale)8 SandBox (org.broadleafcommerce.common.sandbox.domain.SandBox)5 StructuredContentDTO (org.broadleafcommerce.common.structure.dto.StructuredContentDTO)5 MessageSource (org.springframework.context.MessageSource)5 List (java.util.List)4 StructuredContent (org.broadleafcommerce.cms.structure.domain.StructuredContent)4 Field (java.lang.reflect.Field)3 HashSet (java.util.HashSet)3 Locale (java.util.Locale)3 Catalog (org.broadleafcommerce.common.site.domain.Catalog)3 BroadleafAttributeModifier (org.broadleafcommerce.presentation.model.BroadleafAttributeModifier)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 File (java.io.File)2 PrintWriter (java.io.PrintWriter)2