Search in sources :

Example 31 with Customer

use of com.salesmanager.core.model.customer.Customer in project shopizer by shopizer-ecommerce.

the class OrderFacadeImpl method getShippingQuote.

@Override
public ShippingQuote getShippingQuote(PersistableCustomer persistableCustomer, ShoppingCart cart, ShopOrder order, MerchantStore store, Language language) throws Exception {
    // create shipping products
    List<ShippingProduct> shippingProducts = shoppingCartService.createShippingProduct(cart);
    if (CollectionUtils.isEmpty(shippingProducts)) {
        // products are virtual
        return null;
    }
    Customer customer = customerFacade.getCustomerModel(persistableCustomer, store, language);
    Delivery delivery = new Delivery();
    // adjust shipping and billing
    if (order.isShipToBillingAdress() && !order.isShipToDeliveryAddress()) {
        Billing billing = customer.getBilling();
        String postalCode = billing.getPostalCode();
        postalCode = validatePostalCode(postalCode);
        delivery.setAddress(billing.getAddress());
        delivery.setCompany(billing.getCompany());
        delivery.setCity(billing.getCity());
        delivery.setPostalCode(billing.getPostalCode());
        delivery.setState(billing.getState());
        delivery.setCountry(billing.getCountry());
        delivery.setZone(billing.getZone());
    } else {
        delivery = customer.getDelivery();
    }
    ShippingQuote quote = shippingService.getShippingQuote(cart.getId(), store, delivery, shippingProducts, language);
    return quote;
}
Also used : ShippingQuote(com.salesmanager.core.model.shipping.ShippingQuote) ReadableCustomer(com.salesmanager.shop.model.customer.ReadableCustomer) Customer(com.salesmanager.core.model.customer.Customer) PersistableCustomer(com.salesmanager.shop.model.customer.PersistableCustomer) Billing(com.salesmanager.core.model.common.Billing) ShippingProduct(com.salesmanager.core.model.shipping.ShippingProduct) Delivery(com.salesmanager.core.model.common.Delivery)

Example 32 with Customer

use of com.salesmanager.core.model.customer.Customer in project shopizer by shopizer-ecommerce.

the class OrderFacadeImpl method calculateOrderTotal.

@Override
public OrderTotalSummary calculateOrderTotal(MerchantStore store, ShopOrder order, Language language) throws Exception {
    Customer customer = customerFacade.getCustomerModel(order.getCustomer(), store, language);
    OrderTotalSummary summary = calculateOrderTotal(store, customer, order, language);
    this.setOrderTotals(order, summary);
    return summary;
}
Also used : ReadableCustomer(com.salesmanager.shop.model.customer.ReadableCustomer) Customer(com.salesmanager.core.model.customer.Customer) PersistableCustomer(com.salesmanager.shop.model.customer.PersistableCustomer) OrderTotalSummary(com.salesmanager.core.model.order.OrderTotalSummary)

Example 33 with Customer

use of com.salesmanager.core.model.customer.Customer in project shopizer by shopizer-ecommerce.

the class OrderFacadeImpl method initEmptyCustomer.

@Override
public Customer initEmptyCustomer(MerchantStore store) {
    Customer customer = new Customer();
    Billing billing = new Billing();
    billing.setCountry(store.getCountry());
    billing.setZone(store.getZone());
    billing.setState(store.getStorestateprovince());
    /**
     * empty postal code for initial quote *
     */
    // billing.setPostalCode(store.getStorepostalcode());
    customer.setBilling(billing);
    Delivery delivery = new Delivery();
    delivery.setCountry(store.getCountry());
    delivery.setZone(store.getZone());
    delivery.setState(store.getStorestateprovince());
    /**
     * empty postal code for initial quote *
     */
    // delivery.setPostalCode(store.getStorepostalcode());
    customer.setDelivery(delivery);
    return customer;
}
Also used : ReadableCustomer(com.salesmanager.shop.model.customer.ReadableCustomer) Customer(com.salesmanager.core.model.customer.Customer) PersistableCustomer(com.salesmanager.shop.model.customer.PersistableCustomer) Billing(com.salesmanager.core.model.common.Billing) Delivery(com.salesmanager.core.model.common.Delivery)

Example 34 with Customer

use of com.salesmanager.core.model.customer.Customer in project shopizer by shopizer-ecommerce.

the class CustomerReviewServiceImpl method saveOrUpdate.

private void saveOrUpdate(CustomerReview review) throws ServiceException {
    Validate.notNull(review, "CustomerReview cannot be null");
    Validate.notNull(review.getCustomer(), "CustomerReview.customer cannot be null");
    Validate.notNull(review.getReviewedCustomer(), "CustomerReview.reviewedCustomer cannot be null");
    // refresh customer
    Customer customer = customerService.getById(review.getReviewedCustomer().getId());
    // ajust product rating
    Integer count = 0;
    if (customer.getCustomerReviewCount() != null) {
        count = customer.getCustomerReviewCount();
    }
    BigDecimal averageRating = customer.getCustomerReviewAvg();
    if (averageRating == null) {
        averageRating = new BigDecimal(0);
    }
    // get reviews
    BigDecimal totalRating = averageRating.multiply(new BigDecimal(count));
    totalRating = totalRating.add(new BigDecimal(review.getReviewRating()));
    count = count + 1;
    double avg = totalRating.doubleValue() / count;
    customer.setCustomerReviewAvg(new BigDecimal(avg));
    customer.setCustomerReviewCount(count);
    super.save(review);
    customerService.update(customer);
    review.setReviewedCustomer(customer);
}
Also used : Customer(com.salesmanager.core.model.customer.Customer) BigDecimal(java.math.BigDecimal)

Example 35 with Customer

use of com.salesmanager.core.model.customer.Customer in project shopizer by shopizer-ecommerce.

the class OrderRESTController method listOrders.

/**
 * Get a list of orders for a given customer
 * accept request parameter 'lang' [en,fr...] otherwise store dafault language
 * accept request parameter 'start' start index for count
 * accept request parameter 'max' maximum number count, otherwise returns all
 * @param store
 * @param order
 * @param request
 * @param response
 * @return
 * @throws Exception
 */
@RequestMapping(value = "/{store}/orders/customer/{id}", method = RequestMethod.GET)
@ResponseStatus(HttpStatus.ACCEPTED)
@ResponseBody
public ReadableOrderList listOrders(@PathVariable final String store, @PathVariable final Long id, HttpServletRequest request, HttpServletResponse response) throws Exception {
    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(503, "Merchant store is null for code " + store);
        return null;
    }
    // get additional request parameters for orders
    String lang = request.getParameter(Constants.LANG);
    String start = request.getParameter(Constants.START);
    String max = request.getParameter(Constants.MAX);
    int startCount = 0;
    int maxCount = 0;
    if (StringUtils.isBlank(lang)) {
        lang = merchantStore.getDefaultLanguage().getCode();
    }
    Language language = languageService.getByCode(lang);
    if (language == null) {
        LOGGER.error("Language is null for code " + lang);
        response.sendError(503, "Language is null for code " + lang);
        return null;
    }
    try {
        startCount = Integer.parseInt(start);
    } catch (Exception e) {
        LOGGER.info("Invalid value for start " + start);
    }
    try {
        maxCount = Integer.parseInt(max);
    } catch (Exception e) {
        LOGGER.info("Invalid value for max " + max);
    }
    Customer customer = customerService.getById(id);
    if (customer == null) {
        LOGGER.error("Customer is null for id " + id);
        response.sendError(503, "Customer is null for id " + id);
        return null;
    }
    if (customer.getMerchantStore().getId().intValue() != merchantStore.getId().intValue()) {
        LOGGER.error("Customer is null for id " + id + " and store id " + store);
        response.sendError(503, "Customer is null for id " + id + " and store id " + store);
        return null;
    }
    ReadableOrderList returnList = orderFacade.getReadableOrderList(merchantStore, startCount, maxCount, language);
    return returnList;
}
Also used : ReadableOrderList(com.salesmanager.shop.model.order.v0.ReadableOrderList) Language(com.salesmanager.core.model.reference.language.Language) Customer(com.salesmanager.core.model.customer.Customer) PersistableCustomer(com.salesmanager.shop.model.customer.PersistableCustomer) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore)

Aggregations

Customer (com.salesmanager.core.model.customer.Customer)71 PersistableCustomer (com.salesmanager.shop.model.customer.PersistableCustomer)33 ReadableCustomer (com.salesmanager.shop.model.customer.ReadableCustomer)32 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)31 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)30 Language (com.salesmanager.core.model.reference.language.Language)26 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)17 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)17 ConversionException (com.salesmanager.core.business.exception.ConversionException)16 ServiceException (com.salesmanager.core.business.exception.ServiceException)16 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)16 ShoppingCart (com.salesmanager.core.model.shoppingcart.ShoppingCart)12 ApiImplicitParams (io.swagger.annotations.ApiImplicitParams)12 Authentication (org.springframework.security.core.Authentication)12 Date (java.util.Date)11 ConversionRuntimeException (com.salesmanager.shop.store.api.exception.ConversionRuntimeException)10 ArrayList (java.util.ArrayList)10 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)10 Product (com.salesmanager.core.model.catalog.product.Product)9 Country (com.salesmanager.core.model.reference.country.Country)9