Search in sources :

Example 6 with ProductRelationship

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);
}
Also used : ProductRelationship(com.salesmanager.core.model.catalog.product.relationship.ProductRelationship)

Example 7 with ProductRelationship

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);
    }
}
Also used : ProductRelationship(com.salesmanager.core.model.catalog.product.relationship.ProductRelationship)

Example 8 with ProductRelationship

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);
}
Also used : ProductRelationship(com.salesmanager.core.model.catalog.product.relationship.ProductRelationship)

Example 9 with ProductRelationship

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;
}
Also used : ReadableProductList(com.salesmanager.shop.model.catalog.product.ReadableProductList) Language(com.salesmanager.core.model.reference.language.Language) ProductRelationship(com.salesmanager.core.model.catalog.product.relationship.ProductRelationship) ArrayList(java.util.ArrayList) Product(com.salesmanager.core.model.catalog.product.Product) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) Date(java.util.Date) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 10 with ProductRelationship

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);
    }
}
Also used : ProductRelationship(com.salesmanager.core.model.catalog.product.relationship.ProductRelationship)

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