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);
}
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);
}
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;
}
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;
}
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);
}
}
Aggregations