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();
}
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;
}
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);
}
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;
}
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);
}
}
Aggregations