use of org.broadleafcommerce.core.catalog.domain.Product in project BroadleafCommerce by BroadleafCommerce.
the class AdminProductTranslationExtensionHandler method applyTransformation.
/**
* If we are trying to translate a field on Product that starts with "defaultSku.", we really want to associate the
* translation with Sku, its associated id, and the property name without "defaultSku."
*/
@Override
public ExtensionResultStatusType applyTransformation(TranslationForm form) {
String defaultSkuPrefix = "defaultSku.";
String unencodedPropertyName = JSCompatibilityHelper.unencode(form.getPropertyName());
if (form.getCeilingEntity().equals(Product.class.getName()) && unencodedPropertyName.startsWith(defaultSkuPrefix)) {
Product p = catalogService.findProductById(Long.parseLong(form.getEntityId()));
form.setCeilingEntity(Sku.class.getName());
form.setEntityId(String.valueOf(p.getDefaultSku().getId()));
form.setPropertyName(unencodedPropertyName.substring(defaultSkuPrefix.length()));
}
return ExtensionResultStatusType.HANDLED;
}
use of org.broadleafcommerce.core.catalog.domain.Product in project BroadleafCommerce by BroadleafCommerce.
the class BroadleafCategoryController method handleRequest.
@Override
@SuppressWarnings("unchecked")
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
ModelAndView model = new ModelAndView();
if (request.getParameterMap().containsKey("facetField")) {
// If we receive a facetField parameter, we need to convert the field to the
// product search criteria expected format. This is used in multi-facet selection. We
// will send a redirect to the appropriate URL to maintain canonical URLs
String fieldName = request.getParameter("facetField");
List<String> activeFieldFilters = new ArrayList<String>();
Map<String, String[]> parameters = new HashMap<String, String[]>(request.getParameterMap());
for (Iterator<Entry<String, String[]>> iter = parameters.entrySet().iterator(); iter.hasNext(); ) {
Map.Entry<String, String[]> entry = iter.next();
String key = entry.getKey();
if (key.startsWith(fieldName + "-")) {
activeFieldFilters.add(key.substring(key.indexOf('-') + 1));
iter.remove();
}
}
parameters.remove(SearchCriteria.PAGE_NUMBER);
parameters.put(fieldName, activeFieldFilters.toArray(new String[activeFieldFilters.size()]));
parameters.remove("facetField");
String newUrl = ProcessorUtils.getUrl(request.getRequestURL().toString(), parameters);
model.setViewName("redirect:" + newUrl);
} else {
// Else, if we received a GET to the category URL (either the user clicked this link or we redirected
// from the POST method, we can actually process the results
Category category = (Category) request.getAttribute(CategoryHandlerMapping.CURRENT_CATEGORY_ATTRIBUTE_NAME);
assert (category != null);
SearchCriteria searchCriteria = facetService.buildSearchCriteria(request);
SearchResult result = getSearchService().findSearchResults(searchCriteria);
facetService.setActiveFacetResults(result.getFacets(), request);
model.addObject(CATEGORY_ATTRIBUTE_NAME, category);
model.addObject(PRODUCTS_ATTRIBUTE_NAME, result.getProducts());
model.addObject(SKUS_ATTRIBUTE_NAME, result.getSkus());
model.addObject(FACETS_ATTRIBUTE_NAME, result.getFacets());
model.addObject(PRODUCT_SEARCH_RESULT_ATTRIBUTE_NAME, result);
if (request.getParameterMap().containsKey("q")) {
model.addObject(ORIGINAL_QUERY_ATTRIBUTE_NAME, request.getParameter("q"));
}
model.addObject("BLC_PAGE_TYPE", "category");
if (result.getProducts() != null) {
model.addObject(ALL_PRODUCTS_ATTRIBUTE_NAME, new HashSet<Product>(result.getProducts()));
}
if (result.getSkus() != null) {
model.addObject(ALL_SKUS_ATTRIBUTE_NAME, new HashSet<Sku>(result.getSkus()));
}
addDeepLink(model, deepLinkService, category);
String templatePath = null;
// Use the categories custom template if available
if (StringUtils.isNotBlank(category.getDisplayTemplate())) {
templatePath = category.getDisplayTemplate();
} else {
// Otherwise, use the controller default.
templatePath = getDefaultCategoryView();
}
// Allow extension managers to override.
ExtensionResultHolder<String> erh = new ExtensionResultHolder<String>();
ExtensionResultStatusType extResult = templateOverrideManager.getProxy().getOverrideTemplate(erh, category);
if (extResult != ExtensionResultStatusType.NOT_HANDLED) {
templatePath = erh.getResult();
}
model.setViewName(templatePath);
}
return model;
}
use of org.broadleafcommerce.core.catalog.domain.Product in project BroadleafCommerce by BroadleafCommerce.
the class BroadleafSearchController method search.
public String search(Model model, HttpServletRequest request, HttpServletResponse response, String query) throws ServletException, IOException, ServiceException {
if (request.getParameterMap().containsKey("facetField")) {
// If we receive a facetField parameter, we need to convert the field to the
// product search criteria expected format. This is used in multi-facet selection. We
// will send a redirect to the appropriate URL to maintain canonical URLs
String fieldName = request.getParameter("facetField");
List<String> activeFieldFilters = new ArrayList<String>();
Map<String, String[]> parameters = new HashMap<String, String[]>(request.getParameterMap());
for (Iterator<Entry<String, String[]>> iter = parameters.entrySet().iterator(); iter.hasNext(); ) {
Map.Entry<String, String[]> entry = iter.next();
String key = entry.getKey();
if (key.startsWith(fieldName + "-")) {
activeFieldFilters.add(key.substring(key.indexOf('-') + 1));
iter.remove();
}
}
parameters.remove(SearchCriteria.PAGE_NUMBER);
parameters.put(fieldName, activeFieldFilters.toArray(new String[activeFieldFilters.size()]));
parameters.remove("facetField");
String newUrl = ProcessorUtils.getUrl(request.getRequestURL().toString(), parameters);
return "redirect:" + newUrl;
} else {
// Else, if we received a GET to the category URL (either the user performed a search or we redirected
// from the POST method, we can actually process the results
SearchRedirect handler = searchRedirectService.findSearchRedirectBySearchTerm(query);
if (handler != null) {
String contextPath = request.getContextPath();
String url = UrlUtil.fixRedirectUrl(contextPath, handler.getUrl());
response.sendRedirect(url);
return null;
}
if (StringUtils.isNotEmpty(query)) {
SearchCriteria searchCriteria = facetService.buildSearchCriteria(request);
if (StringUtils.isEmpty(searchCriteria.getQuery())) {
// if our query is empty or null, we want to redirect.
return "redirect:/";
}
SearchResult result = getSearchService().findSearchResults(searchCriteria);
facetService.setActiveFacetResults(result.getFacets(), request);
model.addAttribute(PRODUCTS_ATTRIBUTE_NAME, result.getProducts());
model.addAttribute(SKUS_ATTRIBUTE_NAME, result.getSkus());
model.addAttribute(FACETS_ATTRIBUTE_NAME, result.getFacets());
model.addAttribute(PRODUCT_SEARCH_RESULT_ATTRIBUTE_NAME, result);
model.addAttribute(ORIGINAL_QUERY_ATTRIBUTE_NAME, query);
if (result.getProducts() != null) {
model.addAttribute(ALL_PRODUCTS_ATTRIBUTE_NAME, new HashSet<Product>(result.getProducts()));
}
if (result.getSkus() != null) {
model.addAttribute(ALL_SKUS_ATTRIBUTE_NAME, new HashSet<Sku>(result.getSkus()));
}
}
}
updateQueryRequestAttribute(query);
return getSearchView();
}
use of org.broadleafcommerce.core.catalog.domain.Product in project BroadleafCommerce by BroadleafCommerce.
the class BroadleafCartController method configure.
/**
* Takes a product id and builds out a dependant order item tree. If it determines the order
* item is safe to add, it will proceed to calling the "add" method.
*
* If the method was invoked via an AJAX call, it will render the "ajax/configure" template.
* Otherwise, it will perform a 302 redirect to "/cart/configure"
*
* In the case that an "add" happened it will render either the "ajax/cart" or perform a 302
* redirect to "/cart"
*
* @param request
* @param response
* @param model
* @param productId
* @throws IOException
* @throws AddToCartException
* @throws PricingException
*/
public String configure(HttpServletRequest request, HttpServletResponse response, Model model, Long productId) throws IOException, AddToCartException, PricingException, Exception {
Product product = catalogService.findProductById(productId);
ConfigurableOrderItemRequest itemRequest = orderItemService.createConfigurableOrderItemRequestFromProduct(product);
orderItemService.modifyOrderItemRequest(itemRequest);
// If this item request is safe to add, go ahead and add it.
if (isSafeToAdd(itemRequest)) {
return add(request, response, model, itemRequest);
}
model.addAttribute("baseItem", itemRequest);
model.addAttribute("isUpdateRequest", Boolean.TRUE);
model.addAttribute(ALL_PRODUCTS_ATTRIBUTE_NAME, orderItemService.findAllProductsInRequest(itemRequest));
return isAjaxRequest(request) ? getConfigureView() : getConfigurePageRedirect();
}
use of org.broadleafcommerce.core.catalog.domain.Product in project BroadleafCommerce by BroadleafCommerce.
the class BroadleafCartController method isSafeToAdd.
protected boolean isSafeToAdd(ConfigurableOrderItemRequest itemRequest) {
if (!automaticallyAddCompleteItems) {
return false;
}
boolean canSafelyAdd = true;
for (OrderItemRequestDTO child : itemRequest.getChildOrderItems()) {
ConfigurableOrderItemRequest configurableRequest = (ConfigurableOrderItemRequest) child;
Product childProduct = configurableRequest.getProduct();
if (childProduct == null) {
return false;
}
int minQty = configurableRequest.getMinQuantity();
if (minQty == 0 || childProduct.getProductOptionXrefs().size() > 0) {
return false;
}
canSafelyAdd = isSafeToAdd(configurableRequest);
}
return canSafelyAdd;
}
Aggregations