use of com.salesmanager.core.model.catalog.product.relationship.ProductRelationship in project shopizer by shopizer-ecommerce.
the class ProductItemsFacadeImpl method removeItemFromGroup.
@Override
public ReadableProductList removeItemFromGroup(Product product, String group, MerchantStore store, Language language) throws Exception {
ProductRelationship relationship = null;
List<ProductRelationship> relationships = productRelationshipService.getByType(store, product, group);
for (ProductRelationship r : relationships) {
if (r.getRelatedProduct().getId().longValue() == product.getId().longValue()) {
productRelationshipService.delete(relationship);
}
}
return listItemsByGroup(group, store, language);
}
use of com.salesmanager.core.model.catalog.product.relationship.ProductRelationship in project shopizer by shopizer-ecommerce.
the class ProductRelationshipServiceImpl method activateGroup.
@Override
public void activateGroup(MerchantStore store, String groupName) throws ServiceException {
List<ProductRelationship> entities = getGroupDefinition(store, groupName);
for (ProductRelationship relation : entities) {
relation.setActive(true);
this.saveOrUpdate(relation);
}
}
use of com.salesmanager.core.model.catalog.product.relationship.ProductRelationship in project shopizer by shopizer-ecommerce.
the class ProductRelationshipServiceImpl method addGroup.
@Override
public void addGroup(MerchantStore store, String groupName) throws ServiceException {
ProductRelationship relationship = new ProductRelationship();
relationship.setCode(groupName);
relationship.setStore(store);
relationship.setActive(true);
this.save(relationship);
}
use of com.salesmanager.core.model.catalog.product.relationship.ProductRelationship in project shopizer by shopizer-ecommerce.
the class ProductItemsRESTController method getProductItemsByGroup.
/**
* Query for a product group
* public/products/{store code}/products/group/{id}?lang=fr|en
* no lang it will take session lang or default store lang
* @param store
* @param language
* @param groupCode
* @param request
* @param response
* @return
* @throws Exception
*/
@RequestMapping("/public/{store}/products/group/{code}")
@ResponseBody
public ReadableProductList getProductItemsByGroup(@PathVariable String store, @PathVariable final String code, HttpServletRequest request, HttpServletResponse response) throws Exception {
try {
MerchantStore merchantStore = (MerchantStore) request.getAttribute(Constants.MERCHANT_STORE);
if (merchantStore != null) {
if (!merchantStore.getCode().equals(store)) {
// reset for the current request
merchantStore = null;
}
}
if (merchantStore == null) {
merchantStore = merchantStoreService.getByCode(store);
}
if (merchantStore == null) {
LOGGER.error("Merchant store is null for code " + store);
// TODO localized message
response.sendError(503, "Merchant store is null for code " + store);
return null;
}
Language lang = languageUtils.getRequestLanguage(request, response);
// get product group
List<ProductRelationship> group = productRelationshipService.getByGroup(merchantStore, code, lang);
if (group != null) {
Date today = new Date();
List<Long> ids = new ArrayList<Long>();
for (ProductRelationship relationship : group) {
Product product = relationship.getRelatedProduct();
if (product.isAvailable() && DateUtil.dateBeforeEqualsDate(product.getDateAvailable(), today)) {
ids.add(product.getId());
}
}
ReadableProductList list = productItemsFacade.listItemsByIds(merchantStore, lang, ids, 0, 0);
return list;
}
} catch (Exception e) {
LOGGER.error("Error while getting products", e);
response.sendError(503, "An error occured while retrieving products " + e.getMessage());
}
return null;
}
use of com.salesmanager.core.model.catalog.product.relationship.ProductRelationship in project shopizer by shopizer-ecommerce.
the class ProductRelationshipServiceImpl method deactivateGroup.
@Override
public void deactivateGroup(MerchantStore store, String groupName) throws ServiceException {
List<ProductRelationship> entities = getGroupDefinition(store, groupName);
for (ProductRelationship relation : entities) {
relation.setActive(false);
this.saveOrUpdate(relation);
}
}
Aggregations