use of org.broadleafcommerce.presentation.model.BroadleafAttributeModifier in project BroadleafCommerce by BroadleafCommerce.
the class PaginationPageLinkProcessor 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());
Integer page = (Integer) context.parseExpression(attributeValue);
if (page != null && page > 1) {
params.put(SearchCriteria.PAGE_NUMBER, new String[] { page.toString() });
} else {
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.presentation.model.BroadleafAttributeModifier in project BroadleafCommerce by BroadleafCommerce.
the class ProductOptionValueProcessor method getModifiedAttributes.
@Override
public BroadleafAttributeModifier getModifiedAttributes(String tagName, Map<String, String> tagAttributes, String attributeName, String attributeValue, BroadleafTemplateContext context) {
Map<String, String> newAttributes = new HashMap<>();
ProductOptionValue productOptionValue = (ProductOptionValue) context.parseExpression(attributeValue);
ProductOptionValueDTO dto = new ProductOptionValueDTO();
dto.setOptionId(productOptionValue.getProductOption().getId());
dto.setValueId(productOptionValue.getId());
dto.setValueName(productOptionValue.getAttributeValue());
dto.setRawValue(productOptionValue.getRawAttributeValue());
if (productOptionValue.getPriceAdjustment() != null) {
dto.setPriceAdjustment(productOptionValue.getPriceAdjustment().getAmount());
}
try {
ObjectMapper mapper = new ObjectMapper();
Writer strWriter = new StringWriter();
mapper.writeValue(strWriter, dto);
newAttributes.put("data-product-option-value", strWriter.toString());
} catch (Exception ex) {
LOG.error("There was a problem writing the product option value to JSON", ex);
}
return new BroadleafAttributeModifier(newAttributes);
}
use of org.broadleafcommerce.presentation.model.BroadleafAttributeModifier 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.presentation.model.BroadleafAttributeModifier 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.presentation.model.BroadleafAttributeModifier in project BroadleafCommerce by BroadleafCommerce.
the class AdminComponentIdProcessor method getModifiedAttributes.
@Override
public BroadleafAttributeModifier getModifiedAttributes(String tagName, Map<String, String> tagAttributes, String attributeName, String attributeValue, BroadleafTemplateContext context) {
Object component = context.parseExpression(attributeValue);
String fieldName = "";
String id = "";
if (component instanceof ListGrid) {
ListGrid lg = (ListGrid) component;
fieldName = "listGrid-" + lg.getListGridType();
if (StringUtils.isNotBlank(lg.getSubCollectionFieldName())) {
fieldName += "-" + lg.getSubCollectionFieldName();
}
} else if (component instanceof Field) {
Field field = (Field) component;
fieldName = "field-" + field.getName();
}
if (StringUtils.isNotBlank(fieldName)) {
id = cleanCssIdString(fieldName);
}
Map<String, String> attrs = new HashMap<>();
attrs.put("id", id);
return new BroadleafAttributeModifier(attrs);
}
Aggregations