Search in sources :

Example 1 with ProductRelationship

use of com.salesmanager.core.model.catalog.product.relationship.ProductRelationship 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 ProductRelationship

use of com.salesmanager.core.model.catalog.product.relationship.ProductRelationship in project shopizer by shopizer-ecommerce.

the class ShopProductController method relatedItems.

private List<ReadableProduct> relatedItems(MerchantStore store, Product product, Language language) throws Exception {
    ReadableProductPopulator populator = new ReadableProductPopulator();
    populator.setPricingService(pricingService);
    populator.setimageUtils(imageUtils);
    List<ProductRelationship> relatedItems = productRelationshipService.getByType(store, product, ProductRelationshipType.RELATED_ITEM);
    if (relatedItems != null && relatedItems.size() > 0) {
        List<ReadableProduct> items = new ArrayList<ReadableProduct>();
        for (ProductRelationship relationship : relatedItems) {
            Product relatedProduct = relationship.getRelatedProduct();
            ReadableProduct proxyProduct = populator.populate(relatedProduct, new ReadableProduct(), store, language);
            items.add(proxyProduct);
        }
        return items;
    }
    return null;
}
Also used : ReadableProductPopulator(com.salesmanager.shop.populator.catalog.ReadableProductPopulator) ProductRelationship(com.salesmanager.core.model.catalog.product.relationship.ProductRelationship) ArrayList(java.util.ArrayList) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) Product(com.salesmanager.core.model.catalog.product.Product) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct)

Example 3 with ProductRelationship

use of com.salesmanager.core.model.catalog.product.relationship.ProductRelationship in project shopizer by shopizer-ecommerce.

the class ProductTest method testCreateRelationShip.

private void testCreateRelationShip(Product product) throws Exception {
    MerchantStore store = merchantService.getByCode(MerchantStore.DEFAULT_STORE);
    Language en = languageService.getByCode("en");
    Manufacturer oreilley = manufacturerService.getByCode(store, "oreilley");
    ProductType generalType = productTypeService.getProductType(ProductType.GENERAL_TYPE);
    Category tech = categoryService.getByCode(store, "tech");
    // create new related product
    // PRODUCT 1
    Product related = new Product();
    related.setProductHeight(new BigDecimal(4));
    related.setProductLength(new BigDecimal(3));
    related.setProductWidth(new BigDecimal(1));
    related.setSku("TB67891");
    related.setManufacturer(oreilley);
    related.setType(generalType);
    related.setMerchantStore(store);
    // Product description
    ProductDescription description = new ProductDescription();
    description.setName("Spring 4 in Action");
    description.setLanguage(en);
    description.setProduct(related);
    product.getDescriptions().add(description);
    // add category
    product.getCategories().add(tech);
    // Availability
    ProductAvailability availability = new ProductAvailability();
    availability.setProductDateAvailable(date);
    availability.setProductQuantity(200);
    availability.setRegion("*");
    // associate with product
    availability.setProduct(related);
    // productAvailabilityService.create(availability);
    related.getAvailabilities().add(availability);
    ProductPrice dprice = new ProductPrice();
    dprice.setDefaultPrice(true);
    dprice.setProductPriceAmount(new BigDecimal(39.99));
    dprice.setProductAvailability(availability);
    ProductPriceDescription dpd = new ProductPriceDescription();
    dpd.setName("Base price");
    dpd.setProductPrice(dprice);
    dpd.setLanguage(en);
    dprice.getDescriptions().add(dpd);
    availability.getPrices().add(dprice);
    related.getAvailabilities().add(availability);
    productService.save(related);
    ProductRelationship relationship = new ProductRelationship();
    relationship.setActive(true);
    relationship.setCode("spring");
    relationship.setProduct(product);
    relationship.setRelatedProduct(related);
    relationship.setStore(store);
    // because relationships are nor joined fetched, make sure you query relationships first, then ad to an existing list
    // so relationship and review are they only objects not joined fetch when querying a product
    // need to do a subsequent query
    List<ProductRelationship> relationships = productRelationshipService.listByProduct(product);
    relationships.add(relationship);
    product.setRelationships(new HashSet<ProductRelationship>(relationships));
    productService.save(product);
}
Also used : Category(com.salesmanager.core.model.catalog.category.Category) ProductType(com.salesmanager.core.model.catalog.product.type.ProductType) Product(com.salesmanager.core.model.catalog.product.Product) ProductPrice(com.salesmanager.core.model.catalog.product.price.ProductPrice) BigDecimal(java.math.BigDecimal) Language(com.salesmanager.core.model.reference.language.Language) ProductAvailability(com.salesmanager.core.model.catalog.product.availability.ProductAvailability) ProductRelationship(com.salesmanager.core.model.catalog.product.relationship.ProductRelationship) Manufacturer(com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer) ProductDescription(com.salesmanager.core.model.catalog.product.description.ProductDescription) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ProductPriceDescription(com.salesmanager.core.model.catalog.product.price.ProductPriceDescription)

Example 4 with ProductRelationship

use of com.salesmanager.core.model.catalog.product.relationship.ProductRelationship in project shopizer by shopizer-ecommerce.

the class ProductFacadeV2Impl method relatedItems.

@Override
public List<ReadableProduct> relatedItems(MerchantStore store, Product product, Language language) throws Exception {
    // same as v1
    ReadableProductPopulator populator = new ReadableProductPopulator();
    populator.setPricingService(pricingService);
    populator.setimageUtils(imageUtils);
    List<ProductRelationship> relatedItems = productRelationshipService.getByType(store, product, ProductRelationshipType.RELATED_ITEM);
    if (relatedItems != null && relatedItems.size() > 0) {
        List<ReadableProduct> items = new ArrayList<ReadableProduct>();
        for (ProductRelationship relationship : relatedItems) {
            Product relatedProduct = relationship.getRelatedProduct();
            ReadableProduct proxyProduct = populator.populate(relatedProduct, new ReadableProduct(), store, language);
            items.add(proxyProduct);
        }
        return items;
    }
    return null;
}
Also used : ReadableProductPopulator(com.salesmanager.shop.populator.catalog.ReadableProductPopulator) ProductRelationship(com.salesmanager.core.model.catalog.product.relationship.ProductRelationship) ArrayList(java.util.ArrayList) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) Product(com.salesmanager.core.model.catalog.product.Product) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct)

Example 5 with ProductRelationship

use of com.salesmanager.core.model.catalog.product.relationship.ProductRelationship in project shopizer by shopizer-ecommerce.

the class ProductItemsFacadeImpl method addItemToGroup.

@Override
public ReadableProductList addItemToGroup(Product product, String group, MerchantStore store, Language language) {
    Validate.notNull(product, "Product must not be null");
    Validate.notNull(group, "group must not be null");
    // check if product is already in group
    List<ProductRelationship> existList = null;
    try {
        existList = productRelationshipService.getByGroup(store, group).stream().filter(prod -> prod.getRelatedProduct() != null && (product.getId().longValue() == prod.getRelatedProduct().getId())).collect(Collectors.toList());
    } catch (ServiceException e) {
        throw new ServiceRuntimeException("ExceptionWhile getting product group [" + group + "]", e);
    }
    if (existList.size() > 0) {
        throw new OperationNotAllowedException("Product with id [" + product.getId() + "] is already in the group");
    }
    ProductRelationship relationship = new ProductRelationship();
    relationship.setActive(true);
    relationship.setCode(group);
    relationship.setStore(store);
    relationship.setRelatedProduct(product);
    try {
        productRelationshipService.saveOrUpdate(relationship);
        return listItemsByGroup(group, store, language);
    } catch (Exception e) {
        throw new ServiceRuntimeException("ExceptionWhile getting product group [" + group + "]", e);
    }
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) ProductRelationship(com.salesmanager.core.model.catalog.product.relationship.ProductRelationship) OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) ServiceException(com.salesmanager.core.business.exception.ServiceException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Aggregations

ProductRelationship (com.salesmanager.core.model.catalog.product.relationship.ProductRelationship)14 Product (com.salesmanager.core.model.catalog.product.Product)7 ArrayList (java.util.ArrayList)7 ReadableProduct (com.salesmanager.shop.model.catalog.product.ReadableProduct)5 ReadableProductPopulator (com.salesmanager.shop.populator.catalog.ReadableProductPopulator)4 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)3 Language (com.salesmanager.core.model.reference.language.Language)3 ReadableProductList (com.salesmanager.shop.model.catalog.product.ReadableProductList)2 Date (java.util.Date)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ServiceException (com.salesmanager.core.business.exception.ServiceException)1 Category (com.salesmanager.core.model.catalog.category.Category)1 ProductAvailability (com.salesmanager.core.model.catalog.product.availability.ProductAvailability)1 ProductDescription (com.salesmanager.core.model.catalog.product.description.ProductDescription)1 ProductImage (com.salesmanager.core.model.catalog.product.image.ProductImage)1 Manufacturer (com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer)1 ProductPrice (com.salesmanager.core.model.catalog.product.price.ProductPrice)1 ProductPriceDescription (com.salesmanager.core.model.catalog.product.price.ProductPriceDescription)1 ProductReview (com.salesmanager.core.model.catalog.product.review.ProductReview)1 ProductType (com.salesmanager.core.model.catalog.product.type.ProductType)1