Search in sources :

Example 6 with PageInformation

use of com.salesmanager.shop.model.shop.PageInformation in project shopizer by shopizer-ecommerce.

the class ShopProductController method display.

@SuppressWarnings("unchecked")
public String display(final String reference, final String friendlyUrl, Model model, HttpServletRequest request, HttpServletResponse response, Locale locale) throws Exception {
    MerchantStore store = (MerchantStore) request.getAttribute(Constants.MERCHANT_STORE);
    Language language = (Language) request.getAttribute("LANGUAGE");
    Product product = productService.getBySeUrl(store, friendlyUrl, locale);
    if (product == null) {
        return PageBuilderUtils.build404(store);
    }
    ReadableProductPopulator populator = new ReadableProductPopulator();
    populator.setPricingService(pricingService);
    populator.setimageUtils(imageUtils);
    ReadableProduct productProxy = populator.populate(product, new ReadableProduct(), store, language);
    // meta information
    PageInformation pageInformation = new PageInformation();
    pageInformation.setPageDescription(productProxy.getDescription().getMetaDescription());
    pageInformation.setPageKeywords(productProxy.getDescription().getKeyWords());
    pageInformation.setPageTitle(productProxy.getDescription().getTitle());
    pageInformation.setPageUrl(productProxy.getDescription().getFriendlyUrl());
    if (productProxy.getImage() != null) {
        MerchantStore merchantStore = (MerchantStore) request.getAttribute(Constants.MERCHANT_STORE);
        StringBuilder imageUrl = new StringBuilder(filePathUtils.buildStoreForwardedUri(merchantStore, request));
        imageUrl.append(productProxy.getImage().getImageUrl());
        pageInformation.setPageImageUrl(imageUrl.toString());
    }
    request.setAttribute(Constants.REQUEST_PAGE_INFORMATION, pageInformation);
    Breadcrumb breadCrumb = breadcrumbsUtils.buildProductBreadcrumb(reference, productProxy, store, language, request.getContextPath());
    request.getSession().setAttribute(Constants.BREADCRUMB, breadCrumb);
    request.setAttribute(Constants.BREADCRUMB, breadCrumb);
    StringBuilder relatedItemsCacheKey = new StringBuilder();
    relatedItemsCacheKey.append(store.getId()).append("_").append(Constants.RELATEDITEMS_CACHE_KEY).append("-").append(language.getCode());
    StringBuilder relatedItemsMissed = new StringBuilder();
    relatedItemsMissed.append(relatedItemsCacheKey.toString()).append(Constants.MISSED_CACHE_KEY);
    Map<Long, List<ReadableProduct>> relatedItemsMap = null;
    List<ReadableProduct> relatedItems = null;
    if (store.isUseCache()) {
        // get from the cache
        relatedItemsMap = (Map<Long, List<ReadableProduct>>) cache.getFromCache(relatedItemsCacheKey.toString());
        if (relatedItemsMap == null) {
            // get from missed cache
            // Boolean missedContent = (Boolean)cache.getFromCache(relatedItemsMissed.toString());
            // if(missedContent==null) {
            relatedItems = relatedItems(store, product, language);
            if (relatedItems != null) {
                relatedItemsMap = new HashMap<Long, List<ReadableProduct>>();
                relatedItemsMap.put(product.getId(), relatedItems);
                cache.putInCache(relatedItemsMap, relatedItemsCacheKey.toString());
            } else {
            // cache.putInCache(new Boolean(true), relatedItemsMissed.toString());
            }
        // }
        } else {
            relatedItems = relatedItemsMap.get(product.getId());
        }
    } else {
        relatedItems = relatedItems(store, product, language);
    }
    model.addAttribute("relatedProducts", relatedItems);
    Set<ProductAttribute> attributes = product.getAttributes();
    // split read only and options
    Map<Long, Attribute> readOnlyAttributes = null;
    Map<Long, Attribute> selectableOptions = null;
    if (!CollectionUtils.isEmpty(attributes)) {
        for (ProductAttribute attribute : attributes) {
            Attribute attr = null;
            AttributeValue attrValue = new AttributeValue();
            ProductOptionValue optionValue = attribute.getProductOptionValue();
            if (attribute.getAttributeDisplayOnly() == true) {
                // read only attribute
                if (readOnlyAttributes == null) {
                    readOnlyAttributes = new TreeMap<Long, Attribute>();
                }
                attr = readOnlyAttributes.get(attribute.getProductOption().getId());
                if (attr == null) {
                    attr = createAttribute(attribute, language);
                }
                if (attr != null) {
                    readOnlyAttributes.put(attribute.getProductOption().getId(), attr);
                    attr.setReadOnlyValue(attrValue);
                }
            } else {
                // selectable option
                if (selectableOptions == null) {
                    selectableOptions = new TreeMap<Long, Attribute>();
                }
                attr = selectableOptions.get(attribute.getProductOption().getId());
                if (attr == null) {
                    attr = createAttribute(attribute, language);
                }
                if (attr != null) {
                    selectableOptions.put(attribute.getProductOption().getId(), attr);
                }
            }
            attrValue.setDefaultAttribute(attribute.getAttributeDefault());
            // id of the attribute
            attrValue.setId(attribute.getId());
            attrValue.setLanguage(language.getCode());
            if (attribute.getProductAttributePrice() != null && attribute.getProductAttributePrice().doubleValue() > 0) {
                String formatedPrice = pricingService.getDisplayAmount(attribute.getProductAttributePrice(), store);
                attrValue.setPrice(formatedPrice);
            }
            if (!StringUtils.isBlank(attribute.getProductOptionValue().getProductOptionValueImage())) {
                attrValue.setImage(imageUtils.buildProductPropertyImageUtils(store, attribute.getProductOptionValue().getProductOptionValueImage()));
            }
            attrValue.setSortOrder(0);
            if (attribute.getProductOptionSortOrder() != null) {
                attrValue.setSortOrder(attribute.getProductOptionSortOrder().intValue());
            }
            List<ProductOptionValueDescription> descriptions = optionValue.getDescriptionsSettoList();
            ProductOptionValueDescription description = null;
            if (descriptions != null && descriptions.size() > 0) {
                description = descriptions.get(0);
                if (descriptions.size() > 1) {
                    for (ProductOptionValueDescription optionValueDescription : descriptions) {
                        if (optionValueDescription.getLanguage().getId().intValue() == language.getId().intValue()) {
                            description = optionValueDescription;
                            break;
                        }
                    }
                }
            }
            attrValue.setName(description.getName());
            attrValue.setDescription(description.getDescription());
            List<AttributeValue> attrs = attr.getValues();
            if (attrs == null) {
                attrs = new ArrayList<AttributeValue>();
                attr.setValues(attrs);
            }
            attrs.add(attrValue);
        }
    }
    List<ProductReview> reviews = productReviewService.getByProduct(product, language);
    if (!CollectionUtils.isEmpty(reviews)) {
        List<ReadableProductReview> revs = new ArrayList<ReadableProductReview>();
        ReadableProductReviewPopulator reviewPopulator = new ReadableProductReviewPopulator();
        for (ProductReview review : reviews) {
            ReadableProductReview rev = new ReadableProductReview();
            reviewPopulator.populate(review, rev, store, language);
            revs.add(rev);
        }
        model.addAttribute("reviews", revs);
    }
    List<Attribute> attributesList = null;
    if (readOnlyAttributes != null) {
        attributesList = new ArrayList<Attribute>(readOnlyAttributes.values());
    }
    List<Attribute> optionsList = null;
    if (selectableOptions != null) {
        optionsList = new ArrayList<Attribute>(selectableOptions.values());
        // order attributes by sort order
        for (Attribute attr : optionsList) {
            Collections.sort(attr.getValues(), new Comparator<AttributeValue>() {

                public int compare(AttributeValue o1, AttributeValue o2) {
                    if (o1.getSortOrder() == o2.getSortOrder())
                        return 0;
                    return o1.getSortOrder() < o2.getSortOrder() ? -1 : 1;
                }
            });
        }
    }
    model.addAttribute("attributes", attributesList);
    model.addAttribute("options", optionsList);
    model.addAttribute("product", productProxy);
    /**
     * template *
     */
    StringBuilder template = new StringBuilder().append(ControllerConstants.Tiles.Product.product).append(".").append(store.getStoreTemplate());
    return template.toString();
}
Also used : AttributeValue(com.salesmanager.shop.store.model.catalog.AttributeValue) ProductAttribute(com.salesmanager.core.model.catalog.product.attribute.ProductAttribute) Attribute(com.salesmanager.shop.store.model.catalog.Attribute) ReadableProductReview(com.salesmanager.shop.model.catalog.product.ReadableProductReview) ArrayList(java.util.ArrayList) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) Product(com.salesmanager.core.model.catalog.product.Product) ProductAttribute(com.salesmanager.core.model.catalog.product.attribute.ProductAttribute) ProductReview(com.salesmanager.core.model.catalog.product.review.ProductReview) ReadableProductReview(com.salesmanager.shop.model.catalog.product.ReadableProductReview) ReadableProductReviewPopulator(com.salesmanager.shop.populator.catalog.ReadableProductReviewPopulator) ProductOptionValue(com.salesmanager.core.model.catalog.product.attribute.ProductOptionValue) Language(com.salesmanager.core.model.reference.language.Language) ReadableProductPopulator(com.salesmanager.shop.populator.catalog.ReadableProductPopulator) PageInformation(com.salesmanager.shop.model.shop.PageInformation) List(java.util.List) ArrayList(java.util.ArrayList) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) Breadcrumb(com.salesmanager.shop.model.shop.Breadcrumb) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) ProductOptionValueDescription(com.salesmanager.core.model.catalog.product.attribute.ProductOptionValueDescription)

Example 7 with PageInformation

use of com.salesmanager.shop.model.shop.PageInformation in project shopizer by shopizer-ecommerce.

the class ContactController method display.

@RequestMapping("/shop/store/contactus.html")
public String display(Model model, HttpServletRequest request, HttpServletResponse response, Locale locale) throws Exception {
    MerchantStore store = (MerchantStore) request.getAttribute(Constants.MERCHANT_STORE);
    model.addAttribute("googleMapsKey", googleMapsKey);
    request.setAttribute(Constants.LINK_CODE, CONTACT_LINK);
    Language language = (Language) request.getAttribute("LANGUAGE");
    ContactForm contact = new ContactForm();
    model.addAttribute("contact", contact);
    model.addAttribute("recapatcha_public_key", siteKeyKey);
    Content content = contentService.getByCode(Constants.CONTENT_CONTACT_US, store, language);
    ContentDescription contentDescription = null;
    if (content != null && content.isVisible()) {
        contentDescription = content.getDescription();
    }
    if (contentDescription != null) {
        // meta information
        PageInformation pageInformation = new PageInformation();
        pageInformation.setPageDescription(contentDescription.getMetatagDescription());
        pageInformation.setPageKeywords(contentDescription.getMetatagKeywords());
        pageInformation.setPageTitle(contentDescription.getTitle());
        pageInformation.setPageUrl(contentDescription.getName());
        request.setAttribute(Constants.REQUEST_PAGE_INFORMATION, pageInformation);
        model.addAttribute("content", contentDescription);
    }
    /**
     * template *
     */
    StringBuilder template = new StringBuilder().append(ControllerConstants.Tiles.Content.contactus).append(".").append(store.getStoreTemplate());
    return template.toString();
}
Also used : Language(com.salesmanager.core.model.reference.language.Language) PageInformation(com.salesmanager.shop.model.shop.PageInformation) Content(com.salesmanager.core.model.content.Content) ContactForm(com.salesmanager.shop.model.shop.ContactForm) ContentDescription(com.salesmanager.core.model.content.ContentDescription) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with PageInformation

use of com.salesmanager.shop.model.shop.PageInformation in project shopizer by shopizer-ecommerce.

the class ShoppingCategoryController method displayCategory.

@SuppressWarnings("unchecked")
private String displayCategory(final String friendlyUrl, final String ref, Model model, HttpServletRequest request, HttpServletResponse response, Locale locale) throws Exception {
    MerchantStore store = (MerchantStore) request.getAttribute(Constants.MERCHANT_STORE);
    // set ref as request attribute
    String encoded = SanitizeUtils.getSafeRequestParamString(ref);
    if (!encoded.equals(ref)) {
        // possible xss
        throw new Exception("Wrong input parameter [" + ref + "]");
    }
    request.setAttribute("ref", encoded);
    // get category
    Category category = categoryService.getBySeUrl(store, friendlyUrl);
    Language language = (Language) request.getAttribute("LANGUAGE");
    if (category == null) {
        LOGGER.error("No category found for friendlyUrl " + friendlyUrl);
        // redirect on page not found
        return PageBuilderUtils.build404(store);
    }
    if (!category.isVisible()) {
        return PageBuilderUtils.buildHomePage(store);
    }
    ReadableCategoryPopulator populator = new ReadableCategoryPopulator();
    ReadableCategory categoryProxy = populator.populate(category, new ReadableCategory(), store, language);
    Breadcrumb breadCrumb = breadcrumbsUtils.buildCategoryBreadcrumb(categoryProxy, store, language, request.getContextPath());
    request.getSession().setAttribute(Constants.BREADCRUMB, breadCrumb);
    request.setAttribute(Constants.BREADCRUMB, breadCrumb);
    // meta information
    PageInformation pageInformation = new PageInformation();
    pageInformation.setPageDescription(categoryProxy.getDescription().getMetaDescription());
    pageInformation.setPageKeywords(categoryProxy.getDescription().getKeyWords());
    pageInformation.setPageTitle(categoryProxy.getDescription().getTitle());
    pageInformation.setPageUrl(categoryProxy.getDescription().getFriendlyUrl());
    // ** retrieves category id drill down**//
    String lineage = new StringBuilder().append(category.getLineage()).append(Constants.CATEGORY_LINEAGE_DELIMITER).toString();
    request.setAttribute(Constants.REQUEST_PAGE_INFORMATION, pageInformation);
    List<Category> categs = categoryService.getListByLineage(store, lineage);
    categs.add(category);
    StringBuilder subCategoriesCacheKey = new StringBuilder();
    subCategoriesCacheKey.append(store.getId()).append("_").append(category.getId()).append("_").append(Constants.SUBCATEGORIES_CACHE_KEY).append("-").append(language.getCode());
    StringBuilder subCategoriesMissed = new StringBuilder();
    subCategoriesMissed.append(subCategoriesCacheKey.toString()).append(Constants.MISSED_CACHE_KEY);
    List<BigDecimal> prices = new ArrayList<BigDecimal>();
    List<ReadableCategory> subCategories = null;
    Map<Long, Long> countProductsByCategories = null;
    if (store.isUseCache()) {
        // get from the cache
        subCategories = (List<ReadableCategory>) cache.getFromCache(subCategoriesCacheKey.toString());
        if (subCategories == null) {
            // get from missed cache
            // Boolean missedContent = (Boolean)cache.getFromCache(subCategoriesMissed.toString());
            // if(missedContent==null) {
            countProductsByCategories = getProductsByCategory(store, categs);
            subCategories = getSubCategories(store, category, countProductsByCategories, language, locale);
            if (subCategories != null) {
                cache.putInCache(subCategories, subCategoriesCacheKey.toString());
            } else {
            // cache.putInCache(new Boolean(true), subCategoriesCacheKey.toString());
            }
        // }
        }
    } else {
        countProductsByCategories = getProductsByCategory(store, categs);
        subCategories = getSubCategories(store, category, countProductsByCategories, language, locale);
    }
    // Parent category
    ReadableCategory parentProxy = null;
    if (category.getParent() != null) {
        Category parent = categoryService.getById(category.getParent().getId(), store.getId());
        parentProxy = populator.populate(parent, new ReadableCategory(), store, language);
    }
    // ** List of manufacturers **//
    List<ReadableManufacturer> manufacturerList = getManufacturersByProductAndCategory(store, category, categs, language);
    model.addAttribute("manufacturers", manufacturerList);
    model.addAttribute("parent", parentProxy);
    model.addAttribute("category", categoryProxy);
    model.addAttribute("subCategories", subCategories);
    if (parentProxy != null) {
        request.setAttribute(Constants.LINK_CODE, parentProxy.getDescription().getFriendlyUrl());
    }
    /**
     * template *
     */
    StringBuilder template = new StringBuilder().append(ControllerConstants.Tiles.Category.category).append(".").append(store.getStoreTemplate());
    return template.toString();
}
Also used : ReadableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturer) ReadableCategory(com.salesmanager.shop.model.catalog.category.ReadableCategory) Category(com.salesmanager.core.model.catalog.category.Category) ArrayList(java.util.ArrayList) Breadcrumb(com.salesmanager.shop.model.shop.Breadcrumb) BigDecimal(java.math.BigDecimal) Language(com.salesmanager.core.model.reference.language.Language) PageInformation(com.salesmanager.shop.model.shop.PageInformation) ReadableCategory(com.salesmanager.shop.model.catalog.category.ReadableCategory) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ReadableCategoryPopulator(com.salesmanager.shop.populator.catalog.ReadableCategoryPopulator)

Example 9 with PageInformation

use of com.salesmanager.shop.model.shop.PageInformation in project shopizer by shopizer-ecommerce.

the class ShopContentController method displayContent.

@RequestMapping("/shop/pages/{friendlyUrl}.html")
public String displayContent(@PathVariable final String friendlyUrl, Model model, HttpServletRequest request, HttpServletResponse response, Locale locale) throws Exception {
    MerchantStore store = (MerchantStore) request.getAttribute(Constants.MERCHANT_STORE);
    ContentDescription contentDescription = contentService.getBySeUrl(store, friendlyUrl);
    Content content = null;
    if (contentDescription != null) {
        content = contentDescription.getContent();
        if (!content.isVisible()) {
            return "redirect:/shop";
        }
        // meta information
        PageInformation pageInformation = new PageInformation();
        pageInformation.setPageDescription(contentDescription.getMetatagDescription());
        pageInformation.setPageKeywords(contentDescription.getMetatagKeywords());
        pageInformation.setPageTitle(contentDescription.getTitle());
        pageInformation.setPageUrl(contentDescription.getName());
        request.setAttribute(Constants.REQUEST_PAGE_INFORMATION, pageInformation);
    }
    // TODO breadcrumbs
    request.setAttribute(Constants.LINK_CODE, contentDescription.getSeUrl());
    model.addAttribute("content", contentDescription);
    if (!StringUtils.isBlank(content.getProductGroup())) {
        model.addAttribute("productGroup", content.getProductGroup());
    }
    /**
     * template *
     */
    StringBuilder template = new StringBuilder().append(ControllerConstants.Tiles.Content.content).append(".").append(store.getStoreTemplate());
    return template.toString();
}
Also used : PageInformation(com.salesmanager.shop.model.shop.PageInformation) Content(com.salesmanager.core.model.content.Content) ContentDescription(com.salesmanager.core.model.content.ContentDescription) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)9 PageInformation (com.salesmanager.shop.model.shop.PageInformation)9 Language (com.salesmanager.core.model.reference.language.Language)8 ArrayList (java.util.ArrayList)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 Product (com.salesmanager.core.model.catalog.product.Product)4 ContentDescription (com.salesmanager.core.model.content.ContentDescription)4 Content (com.salesmanager.core.model.content.Content)3 Customer (com.salesmanager.core.model.customer.Customer)3 Breadcrumb (com.salesmanager.shop.model.shop.Breadcrumb)3 ReadableManufacturer (com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturer)2 ReadableProduct (com.salesmanager.shop.model.catalog.product.ReadableProduct)2 ShoppingCartData (com.salesmanager.shop.model.shoppingcart.ShoppingCartData)2 ShoppingCartItem (com.salesmanager.shop.model.shoppingcart.ShoppingCartItem)2 ReadableProductPopulator (com.salesmanager.shop.populator.catalog.ReadableProductPopulator)2 Category (com.salesmanager.core.model.catalog.category.Category)1 ProductAttribute (com.salesmanager.core.model.catalog.product.attribute.ProductAttribute)1 ProductOptionValue (com.salesmanager.core.model.catalog.product.attribute.ProductOptionValue)1 ProductOptionValueDescription (com.salesmanager.core.model.catalog.product.attribute.ProductOptionValueDescription)1 Manufacturer (com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer)1