Search in sources :

Example 6 with ProductReview

use of com.salesmanager.core.model.catalog.product.review.ProductReview in project shopizer by shopizer-ecommerce.

the class ProductReviewApi method create.

@RequestMapping(value = { "/private/products/{id}/reviews", "/auth/products/{id}/reviews", "/auth/products/{id}/reviews", "/auth/products/{id}/reviews" }, method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
@ResponseBody
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
public PersistableProductReview create(@PathVariable final Long id, @Valid @RequestBody PersistableProductReview review, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletRequest request, HttpServletResponse response) {
    try {
        // rating already exist
        ProductReview prodReview = productReviewService.getByProductAndCustomer(review.getProductId(), review.getCustomerId());
        if (prodReview != null) {
            response.sendError(500, "A review already exist for this customer and product");
            return null;
        }
        // rating maximum 5
        if (review.getRating() > Constants.MAX_REVIEW_RATING_SCORE) {
            response.sendError(503, "Maximum rating score is " + Constants.MAX_REVIEW_RATING_SCORE);
            return null;
        }
        review.setProductId(id);
        productCommonFacade.saveOrUpdateReview(review, merchantStore, language);
        return review;
    } catch (Exception e) {
        LOGGER.error("Error while saving product review", e);
        try {
            response.sendError(503, "Error while saving product review" + e.getMessage());
        } catch (Exception ignore) {
        }
        return null;
    }
}
Also used : ReadableProductReview(com.salesmanager.shop.model.catalog.product.ReadableProductReview) ProductReview(com.salesmanager.core.model.catalog.product.review.ProductReview) PersistableProductReview(com.salesmanager.shop.model.catalog.product.PersistableProductReview) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 7 with ProductReview

use of com.salesmanager.core.model.catalog.product.review.ProductReview in project shopizer by shopizer-ecommerce.

the class ProductReviewApi method update.

@RequestMapping(value = { "/private/products/{id}/reviews/{reviewid}", "/auth/products/{id}/reviews/{reviewid}" }, method = RequestMethod.PUT)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
public PersistableProductReview update(@PathVariable final Long id, @PathVariable final Long reviewId, @Valid @RequestBody PersistableProductReview review, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletRequest request, HttpServletResponse response) {
    try {
        ProductReview prodReview = productReviewService.getById(reviewId);
        if (prodReview == null) {
            response.sendError(404, "Product review with id " + reviewId + " does not exist");
            return null;
        }
        if (prodReview.getCustomer().getId().longValue() != review.getCustomerId().longValue()) {
            response.sendError(404, "Product review with id " + reviewId + " does not exist");
            return null;
        }
        // rating maximum 5
        if (review.getRating() > Constants.MAX_REVIEW_RATING_SCORE) {
            response.sendError(503, "Maximum rating score is " + Constants.MAX_REVIEW_RATING_SCORE);
            return null;
        }
        review.setProductId(id);
        productCommonFacade.saveOrUpdateReview(review, merchantStore, language);
        return review;
    } catch (Exception e) {
        LOGGER.error("Error while saving product review", e);
        try {
            response.sendError(503, "Error while saving product review" + e.getMessage());
        } catch (Exception ignore) {
        }
        return null;
    }
}
Also used : ReadableProductReview(com.salesmanager.shop.model.catalog.product.ReadableProductReview) ProductReview(com.salesmanager.core.model.catalog.product.review.ProductReview) PersistableProductReview(com.salesmanager.shop.model.catalog.product.PersistableProductReview) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 8 with ProductReview

use of com.salesmanager.core.model.catalog.product.review.ProductReview in project shopizer by shopizer-ecommerce.

the class ProductServiceImpl method delete.

@Override
public void delete(Product product) throws ServiceException {
    LOGGER.debug("Deleting product");
    Validate.notNull(product, "Product cannot be null");
    Validate.notNull(product.getMerchantStore(), "MerchantStore cannot be null in product");
    // Prevents detached entity
    product = this.getById(product.getId());
    // error
    product.setCategories(null);
    Set<ProductImage> images = product.getImages();
    for (ProductImage image : images) {
        productImageService.removeProductImage(image);
    }
    product.setImages(null);
    // delete reviews
    List<ProductReview> reviews = productReviewService.getByProductNoCustomers(product);
    for (ProductReview review : reviews) {
        productReviewService.delete(review);
    }
    // related - featured
    List<ProductRelationship> relationships = productRelationshipService.listByProduct(product);
    for (ProductRelationship relationship : relationships) {
        productRelationshipService.deleteRelationship(relationship);
    }
    super.delete(product);
    searchService.deleteIndex(product.getMerchantStore(), product);
}
Also used : ProductRelationship(com.salesmanager.core.model.catalog.product.relationship.ProductRelationship) ProductImage(com.salesmanager.core.model.catalog.product.image.ProductImage) ProductReview(com.salesmanager.core.model.catalog.product.review.ProductReview)

Example 9 with ProductReview

use of com.salesmanager.core.model.catalog.product.review.ProductReview in project shopizer by shopizer-ecommerce.

the class ProductTest method testReview.

// REVIEW
private void testReview(Product product) throws Exception {
    ProductReview review = new ProductReview();
    review.setProduct(product);
    review.setReviewRating(4d);
    Language en = languageService.getByCode("en");
    ProductReviewDescription reviewDescription = new ProductReviewDescription();
    reviewDescription.setLanguage(en);
    reviewDescription.setDescription("This is a product review");
    reviewDescription.setName("A review for you");
    reviewDescription.setProductReview(review);
    review.getDescriptions().add(reviewDescription);
    productReviewService.create(review);
}
Also used : Language(com.salesmanager.core.model.reference.language.Language) ProductReviewDescription(com.salesmanager.core.model.catalog.product.review.ProductReviewDescription) ProductReview(com.salesmanager.core.model.catalog.product.review.ProductReview)

Example 10 with ProductReview

use of com.salesmanager.core.model.catalog.product.review.ProductReview in project shopizer by shopizer-ecommerce.

the class ShopProductRESTController method createProductReview.

@RequestMapping(value = "/private/{store}/product/review", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
@ResponseBody
public PersistableProductReview createProductReview(@PathVariable final String store, @Valid @RequestBody PersistableProductReview review, HttpServletRequest request, HttpServletResponse response) throws Exception {
    try {
        MerchantStore merchantStore = (MerchantStore) request.getAttribute(Constants.MERCHANT_STORE);
        if (merchantStore != null) {
            if (!merchantStore.getCode().equals(store)) {
                merchantStore = null;
            }
        }
        if (merchantStore == null) {
            merchantStore = merchantStoreService.getByCode(store);
        }
        if (merchantStore == null) {
            LOGGER.error("Merchant store is null for code " + store);
            response.sendError(500, "Merchant store is null for code " + store);
            return null;
        }
        // rating already exist
        ProductReview prodReview = productReviewService.getByProductAndCustomer(review.getProductId(), review.getCustomerId());
        if (prodReview != null) {
            response.sendError(500, "A review already exist for this customer and product");
            return null;
        }
        // rating maximum 5
        if (review.getRating() > Constants.MAX_REVIEW_RATING_SCORE) {
            response.sendError(503, "Maximum rating score is " + Constants.MAX_REVIEW_RATING_SCORE);
            return null;
        }
        PersistableProductReviewPopulator populator = new PersistableProductReviewPopulator();
        populator.setLanguageService(languageService);
        populator.setCustomerService(customerService);
        populator.setProductService(productService);
        com.salesmanager.core.model.catalog.product.review.ProductReview rev = new com.salesmanager.core.model.catalog.product.review.ProductReview();
        populator.populate(review, rev, merchantStore, merchantStore.getDefaultLanguage());
        productReviewService.create(rev);
        review.setId(rev.getId());
        return review;
    } catch (Exception e) {
        LOGGER.error("Error while saving product review", e);
        try {
            response.sendError(503, "Error while saving product review" + e.getMessage());
        } catch (Exception ignore) {
        }
        return null;
    }
}
Also used : ProductReview(com.salesmanager.core.model.catalog.product.review.ProductReview) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ProductReview(com.salesmanager.core.model.catalog.product.review.ProductReview) PersistableProductReview(com.salesmanager.shop.model.catalog.product.PersistableProductReview) PersistableProductReviewPopulator(com.salesmanager.shop.populator.catalog.PersistableProductReviewPopulator) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

ProductReview (com.salesmanager.core.model.catalog.product.review.ProductReview)12 PersistableProductReview (com.salesmanager.shop.model.catalog.product.PersistableProductReview)9 ReadableProductReview (com.salesmanager.shop.model.catalog.product.ReadableProductReview)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 Language (com.salesmanager.core.model.reference.language.Language)5 ReadableProductReviewPopulator (com.salesmanager.shop.populator.catalog.ReadableProductReviewPopulator)5 Product (com.salesmanager.core.model.catalog.product.Product)4 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)4 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)4 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)4 Customer (com.salesmanager.core.model.customer.Customer)3 ReadableProduct (com.salesmanager.shop.model.catalog.product.ReadableProduct)3 ReadableProductPopulator (com.salesmanager.shop.populator.catalog.ReadableProductPopulator)3 ApiImplicitParams (io.swagger.annotations.ApiImplicitParams)3 ArrayList (java.util.ArrayList)3 ProductReviewDescription (com.salesmanager.core.model.catalog.product.review.ProductReviewDescription)2 PersistableProductReviewPopulator (com.salesmanager.shop.populator.catalog.PersistableProductReviewPopulator)2 Date (java.util.Date)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2 ConversionException (com.salesmanager.core.business.exception.ConversionException)1