Search in sources :

Example 1 with Breadcrumb

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

the class LandingController method displayLanding.

@RequestMapping(value = { Constants.SHOP_URI + "/home.html", Constants.SHOP_URI + "/", Constants.SHOP_URI }, method = RequestMethod.GET)
public String displayLanding(Model model, HttpServletRequest request, HttpServletResponse response, Locale locale) throws Exception {
    Language language = (Language) request.getAttribute(Constants.LANGUAGE);
    MerchantStore store = (MerchantStore) request.getAttribute(Constants.MERCHANT_STORE);
    request.setAttribute(Constants.LINK_CODE, HOME_LINK_CODE);
    Content content = contentService.getByCode(LANDING_PAGE, store, language);
    /**
     * Rebuild breadcrumb *
     */
    BreadcrumbItem item = new BreadcrumbItem();
    item.setItemType(BreadcrumbItemType.HOME);
    item.setLabel(messages.getMessage(Constants.HOME_MENU_KEY, locale));
    item.setUrl(Constants.HOME_URL);
    Breadcrumb breadCrumb = new Breadcrumb();
    breadCrumb.setLanguage(language);
    List<BreadcrumbItem> items = new ArrayList<BreadcrumbItem>();
    items.add(item);
    breadCrumb.setBreadCrumbs(items);
    request.getSession().setAttribute(Constants.BREADCRUMB, breadCrumb);
    request.setAttribute(Constants.BREADCRUMB, breadCrumb);
    if (content != null) {
        ContentDescription description = content.getDescription();
        model.addAttribute("page", description);
        PageInformation pageInformation = new PageInformation();
        pageInformation.setPageTitle(description.getName());
        pageInformation.setPageDescription(description.getMetatagDescription());
        pageInformation.setPageKeywords(description.getMetatagKeywords());
        request.setAttribute(Constants.REQUEST_PAGE_INFORMATION, pageInformation);
    }
    ReadableProductPopulator populator = new ReadableProductPopulator();
    populator.setPricingService(pricingService);
    populator.setimageUtils(imageUtils);
    // featured items
    List<ProductRelationship> relationships = productRelationshipService.getByType(store, ProductRelationshipType.FEATURED_ITEM, language);
    List<ReadableProduct> featuredItems = new ArrayList<ReadableProduct>();
    Date today = new Date();
    for (ProductRelationship relationship : relationships) {
        Product product = relationship.getRelatedProduct();
        if (product.isAvailable() && DateUtil.dateBeforeEqualsDate(product.getDateAvailable(), today)) {
            ReadableProduct proxyProduct = populator.populate(product, new ReadableProduct(), store, language);
            featuredItems.add(proxyProduct);
        }
    }
    String tmpl = store.getStoreTemplate();
    if (StringUtils.isBlank(tmpl)) {
        tmpl = "generic";
    }
    model.addAttribute("featuredItems", featuredItems);
    /**
     * template *
     */
    StringBuilder template = new StringBuilder().append("landing.").append(tmpl);
    return template.toString();
}
Also used : BreadcrumbItem(com.salesmanager.shop.model.shop.BreadcrumbItem) ArrayList(java.util.ArrayList) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) Product(com.salesmanager.core.model.catalog.product.Product) Breadcrumb(com.salesmanager.shop.model.shop.Breadcrumb) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) Date(java.util.Date) Language(com.salesmanager.core.model.reference.language.Language) PageInformation(com.salesmanager.shop.model.shop.PageInformation) ReadableProductPopulator(com.salesmanager.shop.populator.catalog.ReadableProductPopulator) ProductRelationship(com.salesmanager.core.model.catalog.product.relationship.ProductRelationship) 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)

Example 2 with Breadcrumb

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

the class BreadcrumbsUtils method buildCategoryBreadcrumb.

public Breadcrumb buildCategoryBreadcrumb(ReadableCategory categoryClicked, MerchantStore store, Language language, String contextPath) throws Exception {
    /**
     * Rebuild breadcrumb *
     */
    BreadcrumbItem home = new BreadcrumbItem();
    home.setItemType(BreadcrumbItemType.HOME);
    home.setLabel(messages.getMessage(Constants.HOME_MENU_KEY, LocaleUtils.getLocale(language)));
    home.setUrl(filePathUtils.buildStoreUri(store, contextPath) + Constants.SHOP_URI);
    Breadcrumb breadCrumb = new Breadcrumb();
    breadCrumb.setLanguage(language);
    List<BreadcrumbItem> items = new ArrayList<BreadcrumbItem>();
    items.add(home);
    List<String> categoryIds = parseCategoryLineage(categoryClicked.getLineage());
    List<Long> ids = new ArrayList<Long>();
    for (String c : categoryIds) {
        ids.add(Long.parseLong(c));
    }
    ids.add(categoryClicked.getId());
    List<Category> categories = categoryService.listByIds(store, ids, language);
    // category path - use lineage
    for (Category c : categories) {
        BreadcrumbItem categoryBreadcrump = new BreadcrumbItem();
        categoryBreadcrump.setItemType(BreadcrumbItemType.CATEGORY);
        categoryBreadcrump.setLabel(c.getDescription().getName());
        categoryBreadcrump.setUrl(filePathUtils.buildCategoryUrl(store, contextPath, c.getDescription().getSeUrl()));
        items.add(categoryBreadcrump);
    }
    breadCrumb.setUrlRefContent(buildBreadCrumb(ids));
    breadCrumb.setBreadCrumbs(items);
    breadCrumb.setItemType(BreadcrumbItemType.CATEGORY);
    return breadCrumb;
}
Also used : Category(com.salesmanager.core.model.catalog.category.Category) ReadableCategory(com.salesmanager.shop.model.catalog.category.ReadableCategory) BreadcrumbItem(com.salesmanager.shop.model.shop.BreadcrumbItem) ArrayList(java.util.ArrayList) Breadcrumb(com.salesmanager.shop.model.shop.Breadcrumb)

Example 3 with Breadcrumb

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

the class BreadcrumbsUtils method buildProductBreadcrumb.

public Breadcrumb buildProductBreadcrumb(String refContent, ReadableProduct productClicked, MerchantStore store, Language language, String contextPath) throws Exception {
    /**
     * Rebuild breadcrumb *
     */
    BreadcrumbItem home = new BreadcrumbItem();
    home.setItemType(BreadcrumbItemType.HOME);
    home.setLabel(messages.getMessage(Constants.HOME_MENU_KEY, LocaleUtils.getLocale(language)));
    home.setUrl(filePathUtils.buildStoreUri(store, contextPath) + Constants.SHOP_URI);
    Breadcrumb breadCrumb = new Breadcrumb();
    breadCrumb.setLanguage(language);
    List<BreadcrumbItem> items = new ArrayList<BreadcrumbItem>();
    items.add(home);
    if (!StringUtils.isBlank(refContent)) {
        List<String> categoryIds = parseBreadCrumb(refContent);
        List<Long> ids = new ArrayList<Long>();
        for (String c : categoryIds) {
            ids.add(Long.parseLong(c));
        }
        List<Category> categories = categoryService.listByIds(store, ids, language);
        // category path - use lineage
        for (Category c : categories) {
            BreadcrumbItem categoryBreadcrump = new BreadcrumbItem();
            categoryBreadcrump.setItemType(BreadcrumbItemType.CATEGORY);
            categoryBreadcrump.setLabel(c.getDescription().getName());
            categoryBreadcrump.setUrl(filePathUtils.buildCategoryUrl(store, contextPath, c.getDescription().getSeUrl()));
            items.add(categoryBreadcrump);
        }
        breadCrumb.setUrlRefContent(buildBreadCrumb(ids));
    }
    BreadcrumbItem productBreadcrump = new BreadcrumbItem();
    productBreadcrump.setItemType(BreadcrumbItemType.PRODUCT);
    productBreadcrump.setLabel(productClicked.getDescription().getName());
    productBreadcrump.setUrl(filePathUtils.buildProductUrl(store, contextPath, productClicked.getDescription().getFriendlyUrl()));
    items.add(productBreadcrump);
    breadCrumb.setBreadCrumbs(items);
    breadCrumb.setItemType(BreadcrumbItemType.CATEGORY);
    return breadCrumb;
}
Also used : Category(com.salesmanager.core.model.catalog.category.Category) ReadableCategory(com.salesmanager.shop.model.catalog.category.ReadableCategory) BreadcrumbItem(com.salesmanager.shop.model.shop.BreadcrumbItem) ArrayList(java.util.ArrayList) Breadcrumb(com.salesmanager.shop.model.shop.Breadcrumb)

Example 4 with Breadcrumb

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

the class StoreFilter method setBreadcrumb.

private void setBreadcrumb(HttpServletRequest request, Locale locale) {
    try {
        // breadcrumb
        Breadcrumb breadCrumb = (Breadcrumb) request.getSession().getAttribute(Constants.BREADCRUMB);
        Language language = (Language) request.getAttribute(Constants.LANGUAGE);
        if (breadCrumb == null) {
            breadCrumb = new Breadcrumb();
            breadCrumb.setLanguage(language);
            BreadcrumbItem item = this.getDefaultBreadcrumbItem(language, locale);
            breadCrumb.getBreadCrumbs().add(item);
        } else {
            // check language
            if (language.getCode().equals(breadCrumb.getLanguage().getCode())) {
                // rebuild using the appropriate language
                List<BreadcrumbItem> items = new ArrayList<BreadcrumbItem>();
                for (BreadcrumbItem item : breadCrumb.getBreadCrumbs()) {
                    if (item.getItemType().name().equals(BreadcrumbItemType.HOME)) {
                        BreadcrumbItem homeItem = this.getDefaultBreadcrumbItem(language, locale);
                        homeItem.setItemType(BreadcrumbItemType.HOME);
                        homeItem.setLabel(messages.getMessage(Constants.HOME_MENU_KEY, locale));
                        homeItem.setUrl(Constants.HOME_URL);
                        items.add(homeItem);
                    } else if (item.getItemType().name().equals(BreadcrumbItemType.PRODUCT)) {
                        Product product = productService.getProductForLocale(item.getId(), language, locale);
                        if (product != null) {
                            BreadcrumbItem productItem = new BreadcrumbItem();
                            productItem.setId(product.getId());
                            productItem.setItemType(BreadcrumbItemType.PRODUCT);
                            productItem.setLabel(product.getProductDescription().getName());
                            productItem.setUrl(product.getProductDescription().getSeUrl());
                            items.add(productItem);
                        }
                    } else if (item.getItemType().name().equals(BreadcrumbItemType.CATEGORY)) {
                        Category category = categoryService.getOneByLanguage(item.getId(), language);
                        if (category != null) {
                            BreadcrumbItem categoryItem = new BreadcrumbItem();
                            categoryItem.setId(category.getId());
                            categoryItem.setItemType(BreadcrumbItemType.CATEGORY);
                            categoryItem.setLabel(category.getDescription().getName());
                            categoryItem.setUrl(category.getDescription().getSeUrl());
                            items.add(categoryItem);
                        }
                    } else if (item.getItemType().name().equals(BreadcrumbItemType.PAGE)) {
                        Content content = contentService.getByLanguage(item.getId(), language);
                        if (content != null) {
                            BreadcrumbItem contentItem = new BreadcrumbItem();
                            contentItem.setId(content.getId());
                            contentItem.setItemType(BreadcrumbItemType.PAGE);
                            contentItem.setLabel(content.getDescription().getName());
                            contentItem.setUrl(content.getDescription().getSeUrl());
                            items.add(contentItem);
                        }
                    }
                }
                breadCrumb = new Breadcrumb();
                breadCrumb.setLanguage(language);
                breadCrumb.setBreadCrumbs(items);
            }
        }
        request.getSession().setAttribute(Constants.BREADCRUMB, breadCrumb);
        request.setAttribute(Constants.BREADCRUMB, breadCrumb);
    } catch (Exception e) {
        LOGGER.error("Error while building breadcrumbs", e);
    }
}
Also used : ReadableCategory(com.salesmanager.shop.model.catalog.category.ReadableCategory) Category(com.salesmanager.core.model.catalog.category.Category) Language(com.salesmanager.core.model.reference.language.Language) BreadcrumbItem(com.salesmanager.shop.model.shop.BreadcrumbItem) Content(com.salesmanager.core.model.content.Content) Product(com.salesmanager.core.model.catalog.product.Product) Breadcrumb(com.salesmanager.shop.model.shop.Breadcrumb)

Example 5 with Breadcrumb

use of com.salesmanager.shop.model.shop.Breadcrumb 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)

Aggregations

Breadcrumb (com.salesmanager.shop.model.shop.Breadcrumb)6 ArrayList (java.util.ArrayList)5 Category (com.salesmanager.core.model.catalog.category.Category)4 Language (com.salesmanager.core.model.reference.language.Language)4 ReadableCategory (com.salesmanager.shop.model.catalog.category.ReadableCategory)4 BreadcrumbItem (com.salesmanager.shop.model.shop.BreadcrumbItem)4 Product (com.salesmanager.core.model.catalog.product.Product)3 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)3 PageInformation (com.salesmanager.shop.model.shop.PageInformation)3 Content (com.salesmanager.core.model.content.Content)2 ReadableProduct (com.salesmanager.shop.model.catalog.product.ReadableProduct)2 ReadableProductPopulator (com.salesmanager.shop.populator.catalog.ReadableProductPopulator)2 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 ProductRelationship (com.salesmanager.core.model.catalog.product.relationship.ProductRelationship)1 ProductReview (com.salesmanager.core.model.catalog.product.review.ProductReview)1 ContentDescription (com.salesmanager.core.model.content.ContentDescription)1 ReadableManufacturer (com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturer)1 ReadableProductReview (com.salesmanager.shop.model.catalog.product.ReadableProductReview)1