Search in sources :

Example 41 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, com.salesmanager.shop.model.order.v0.PersistableOrder order, Language language) throws Exception {
    List<PersistableOrderProduct> orderProducts = order.getOrderProductItems();
    ShoppingCartItemPopulator populator = new ShoppingCartItemPopulator();
    populator.setProductAttributeService(productAttributeService);
    populator.setProductService(productService);
    populator.setShoppingCartService(shoppingCartService);
    List<ShoppingCartItem> items = new ArrayList<ShoppingCartItem>();
    for (PersistableOrderProduct orderProduct : orderProducts) {
        ShoppingCartItem item = populator.populate(orderProduct, new ShoppingCartItem(), store, language);
        items.add(item);
    }
    Customer customer = customer(order.getCustomer(), store, language);
    OrderTotalSummary summary = this.calculateOrderTotal(store, customer, order, language);
    return summary;
}
Also used : ShoppingCartItemPopulator(com.salesmanager.shop.populator.order.ShoppingCartItemPopulator) 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) ArrayList(java.util.ArrayList) ShoppingCartItem(com.salesmanager.core.model.shoppingcart.ShoppingCartItem) PersistableOrderProduct(com.salesmanager.shop.model.order.PersistableOrderProduct)

Example 42 with Customer

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

the class ShoppingCartApi method getByCustomer.

@Deprecated
@ResponseStatus(HttpStatus.OK)
@RequestMapping(value = "/auth/customer/{id}/cart", method = RequestMethod.GET)
@ApiOperation(httpMethod = "GET", value = "Get a shopping cart by customer id. Customer must be authenticated", notes = "", produces = "application/json", response = ReadableShoppingCart.class)
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
// customer
@ResponseBody
public // customer
ReadableShoppingCart getByCustomer(// customer
@PathVariable Long id, // cart code
@RequestParam Optional<String> cart, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletRequest request, HttpServletResponse response) {
    Principal principal = request.getUserPrincipal();
    // lookup customer
    Customer customer = customerService.getById(id);
    if (customer == null) {
        throw new ResourceNotFoundException("No Customer found for id [" + id + "]");
    }
    customerFacadev1.authorize(customer, principal);
    ReadableShoppingCart readableCart = shoppingCartFacadev1.get(cart, id, merchantStore, language);
    if (readableCart == null) {
        throw new ResourceNotFoundException("No cart found for customerid [" + id + "]");
    }
    return readableCart;
}
Also used : Customer(com.salesmanager.core.model.customer.Customer) ReadableShoppingCart(com.salesmanager.shop.model.shoppingcart.ReadableShoppingCart) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) Principal(java.security.Principal) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 43 with Customer

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

the class ShoppingCartApi method getByCustomer.

@ResponseStatus(HttpStatus.OK)
@RequestMapping(value = "/auth/customer/cart", method = RequestMethod.GET)
@ApiOperation(httpMethod = "GET", value = "Get a shopping cart by authenticated customer", notes = "", produces = "application/json", response = ReadableShoppingCart.class)
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
@ResponseBody
public ReadableShoppingCart getByCustomer(// cart code
@RequestParam Optional<String> cart, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletRequest request, HttpServletResponse response) {
    Principal principal = request.getUserPrincipal();
    Customer customer = null;
    try {
        customer = customerFacade.getCustomerByUserName(principal.getName(), merchantStore);
    } catch (Exception e) {
        throw new ServiceRuntimeException("Exception while getting customer [ " + principal.getName() + "]");
    }
    if (customer == null) {
        throw new ResourceNotFoundException("No Customer found for principal[" + principal.getName() + "]");
    }
    customerFacadev1.authorize(customer, principal);
    ReadableShoppingCart readableCart = shoppingCartFacadev1.get(cart, customer.getId(), merchantStore, language);
    if (readableCart == null) {
        throw new ResourceNotFoundException("No cart found for customer [" + principal.getName() + "]");
    }
    return readableCart;
}
Also used : Customer(com.salesmanager.core.model.customer.Customer) ReadableShoppingCart(com.salesmanager.shop.model.shoppingcart.ReadableShoppingCart) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) Principal(java.security.Principal) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 44 with Customer

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

the class CustomerFacadeImpl method getCustomerDataByUserName.

/**
 * Method used to fetch customer based on the username and storecode. Customer username is unique
 * to each store.
 *
 * @param userName
 * @param store
 * @throws ConversionException
 */
@Override
public CustomerEntity getCustomerDataByUserName(final String userName, final MerchantStore store, final Language language) throws Exception {
    LOG.info("Fetching customer with userName" + userName);
    Customer customer = customerService.getByNick(userName);
    if (customer != null) {
        LOG.info("Found customer, converting to CustomerEntity");
        try {
            CustomerEntityPopulator customerEntityPopulator = new CustomerEntityPopulator();
            // store, language
            return customerEntityPopulator.populate(customer, store, language);
        } catch (ConversionException ex) {
            LOG.error("Error while converting Customer to CustomerEntity", ex);
            throw new Exception(ex);
        }
    }
    return null;
}
Also used : ConversionException(com.salesmanager.core.business.exception.ConversionException) ReadableCustomer(com.salesmanager.shop.model.customer.ReadableCustomer) Customer(com.salesmanager.core.model.customer.Customer) PersistableCustomer(com.salesmanager.shop.model.customer.PersistableCustomer) CustomerEntityPopulator(com.salesmanager.shop.populator.customer.CustomerEntityPopulator) ServiceException(com.salesmanager.core.business.exception.ServiceException) UserAlreadyExistException(com.salesmanager.shop.model.customer.UserAlreadyExistException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ConversionException(com.salesmanager.core.business.exception.ConversionException)

Example 45 with Customer

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

the class CustomerFacadeImpl method getAllCustomerReviewsByReviewed.

@Override
public List<ReadableCustomerReview> getAllCustomerReviewsByReviewed(Long customerId, MerchantStore store, Language language) {
    // customer exist
    Customer customer = getCustomerById(customerId);
    Validate.notNull(customer, "Reviewed customer cannot be null");
    return customerReviewService.getByReviewedCustomer(customer).stream().map(customerReview -> convertCustomerReviewToReadableCustomerReview(customerReview, store, language)).collect(Collectors.toList());
}
Also used : ShoppingCart(com.salesmanager.core.model.shoppingcart.ShoppingCart) PermissionService(com.salesmanager.core.business.services.user.PermissionService) CustomerList(com.salesmanager.core.model.customer.CustomerList) CustomerEntityPopulator(com.salesmanager.shop.populator.customer.CustomerEntityPopulator) Date(java.util.Date) EmailConstants(com.salesmanager.shop.constants.EmailConstants) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) LanguageService(com.salesmanager.core.business.services.reference.language.LanguageService) ServiceException(com.salesmanager.core.business.exception.ServiceException) CustomerOptinService(com.salesmanager.core.business.services.customer.optin.CustomerOptinService) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) CustomerReviewService(com.salesmanager.core.business.services.customer.review.CustomerReviewService) UserAlreadyExistException(com.salesmanager.shop.model.customer.UserAlreadyExistException) Locale(java.util.Locale) Map(java.util.Map) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) CustomerService(com.salesmanager.core.business.services.customer.CustomerService) CountryService(com.salesmanager.core.business.services.reference.country.CountryService) UUID(org.jgroups.util.UUID) ReadableCustomerReview(com.salesmanager.shop.model.customer.ReadableCustomerReview) CustomerEntity(com.salesmanager.shop.model.customer.CustomerEntity) Collection(java.util.Collection) Collectors(java.util.stream.Collectors) GrantedAuthority(org.springframework.security.core.GrantedAuthority) ReadableCustomer(com.salesmanager.shop.model.customer.ReadableCustomer) List(java.util.List) CustomerBillingAddressPopulator(com.salesmanager.shop.populator.customer.CustomerBillingAddressPopulator) LocaleUtils(com.salesmanager.shop.utils.LocaleUtils) CoreConfiguration(com.salesmanager.core.business.utils.CoreConfiguration) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) Optional(java.util.Optional) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) Optin(com.salesmanager.core.model.system.optin.Optin) Authentication(org.springframework.security.core.Authentication) Address(com.salesmanager.shop.model.customer.address.Address) EmailService(com.salesmanager.core.business.services.system.EmailService) OptinType(com.salesmanager.core.model.system.optin.OptinType) Async(org.springframework.scheduling.annotation.Async) Email(com.salesmanager.core.business.modules.email.Email) Group(com.salesmanager.core.model.user.Group) Constants(com.salesmanager.shop.constants.Constants) ReadableCustomerPopulator(com.salesmanager.shop.populator.customer.ReadableCustomerPopulator) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) Zone(com.salesmanager.core.model.reference.zone.Zone) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) ZoneService(com.salesmanager.core.business.services.reference.zone.ZoneService) Inject(javax.inject.Inject) Language(com.salesmanager.core.model.reference.language.Language) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException) Permission(com.salesmanager.core.model.user.Permission) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) LabelUtils(com.salesmanager.shop.utils.LabelUtils) Service(org.springframework.stereotype.Service) Qualifier(org.springframework.beans.factory.annotation.Qualifier) EmailUtils(com.salesmanager.shop.utils.EmailUtils) CustomerDeliveryAddressPopulator(com.salesmanager.shop.populator.customer.CustomerDeliveryAddressPopulator) CustomerPopulator(com.salesmanager.shop.populator.customer.CustomerPopulator) CustomerReview(com.salesmanager.core.model.customer.review.CustomerReview) PersistableCustomerReview(com.salesmanager.shop.model.customer.PersistableCustomerReview) ShoppingCartService(com.salesmanager.core.business.services.shoppingcart.ShoppingCartService) Logger(org.slf4j.Logger) AuthenticationManager(org.springframework.security.authentication.AuthenticationManager) Country(com.salesmanager.core.model.reference.country.Country) Customer(com.salesmanager.core.model.customer.Customer) CustomerCriteria(com.salesmanager.core.model.customer.CustomerCriteria) CustomerOptin(com.salesmanager.core.model.system.optin.CustomerOptin) ImageFilePath(com.salesmanager.shop.utils.ImageFilePath) EmailTemplatesUtils(com.salesmanager.shop.utils.EmailTemplatesUtils) PersistableCustomerBillingAddressPopulator(com.salesmanager.shop.populator.customer.PersistableCustomerBillingAddressPopulator) PersistableCustomerShippingAddressPopulator(com.salesmanager.shop.populator.customer.PersistableCustomerShippingAddressPopulator) GroupType(com.salesmanager.core.model.user.GroupType) PersistableCustomer(com.salesmanager.shop.model.customer.PersistableCustomer) Validate(org.apache.commons.lang3.Validate) PasswordEncoder(org.springframework.security.crypto.password.PasswordEncoder) PersistableCustomerOptin(com.salesmanager.shop.model.customer.optin.PersistableCustomerOptin) GroupService(com.salesmanager.core.business.services.user.GroupService) ConversionException(com.salesmanager.core.business.exception.ConversionException) OptinService(com.salesmanager.core.business.services.system.optin.OptinService) PersistableCustomerReviewPopulator(com.salesmanager.shop.populator.customer.PersistableCustomerReviewPopulator) ReadableCustomerReviewPopulator(com.salesmanager.shop.populator.customer.ReadableCustomerReviewPopulator) ReadableCustomerList(com.salesmanager.shop.populator.customer.ReadableCustomerList) ReadableCustomer(com.salesmanager.shop.model.customer.ReadableCustomer) Customer(com.salesmanager.core.model.customer.Customer) PersistableCustomer(com.salesmanager.shop.model.customer.PersistableCustomer)

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