Search in sources :

Example 1 with ReadableOrderProductDownload

use of com.salesmanager.shop.model.order.ReadableOrderProductDownload in project shopizer by shopizer-ecommerce.

the class CustomerOrdersController method orderDetails.

@PreAuthorize("hasRole('AUTH_CUSTOMER')")
@RequestMapping(value = "/order.html", method = { RequestMethod.GET, RequestMethod.POST })
public String orderDetails(final Model model, final HttpServletRequest request, @RequestParam(value = "orderId", required = true) final String orderId) throws Exception {
    MerchantStore store = getSessionAttribute(Constants.MERCHANT_STORE, request);
    Language language = (Language) request.getAttribute(Constants.LANGUAGE);
    if (StringUtils.isBlank(orderId)) {
        LOGGER.error("Order Id can not be null or empty");
    }
    LOGGER.info("Fetching order details for Id " + orderId);
    // get order id
    Long lOrderId = null;
    try {
        lOrderId = Long.parseLong(orderId);
    } catch (NumberFormatException nfe) {
        LOGGER.error("Cannot parse orderId to long " + orderId);
        return "redirect:/" + Constants.SHOP_URI;
    }
    // check if order belongs to customer logged in
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    Customer customer = null;
    if (auth != null && request.isUserInRole("AUTH_CUSTOMER")) {
        customer = customerFacade.getCustomerByUserName(auth.getName(), store);
    }
    if (customer == null) {
        return "redirect:/" + Constants.SHOP_URI;
    }
    ReadableOrder order = orderFacade.getReadableOrder(lOrderId, store, customer.getDefaultLanguage());
    model.addAttribute("order", order);
    // check if any downloads exist for this order
    List<OrderProductDownload> orderProductDownloads = orderProdctDownloadService.getByOrderId(order.getId());
    if (CollectionUtils.isNotEmpty(orderProductDownloads)) {
        ReadableOrderProductDownloadPopulator populator = new ReadableOrderProductDownloadPopulator();
        List<ReadableOrderProductDownload> downloads = new ArrayList<ReadableOrderProductDownload>();
        for (OrderProductDownload download : orderProductDownloads) {
            ReadableOrderProductDownload view = new ReadableOrderProductDownload();
            populator.populate(download, view, store, language);
            downloads.add(view);
        }
        model.addAttribute("downloads", downloads);
    }
    StringBuilder template = new StringBuilder().append(ControllerConstants.Tiles.Customer.customerOrder).append(".").append(store.getStoreTemplate());
    return template.toString();
}
Also used : ReadableOrderProductDownloadPopulator(com.salesmanager.shop.populator.order.ReadableOrderProductDownloadPopulator) Customer(com.salesmanager.core.model.customer.Customer) ReadableOrderProductDownload(com.salesmanager.shop.model.order.ReadableOrderProductDownload) ArrayList(java.util.ArrayList) ReadableOrder(com.salesmanager.shop.model.order.v0.ReadableOrder) Language(com.salesmanager.core.model.reference.language.Language) Authentication(org.springframework.security.core.Authentication) OrderProductDownload(com.salesmanager.core.model.order.orderproduct.OrderProductDownload) ReadableOrderProductDownload(com.salesmanager.shop.model.order.ReadableOrderProductDownload) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with ReadableOrderProductDownload

use of com.salesmanager.shop.model.order.ReadableOrderProductDownload in project shopizer by shopizer-ecommerce.

the class ShoppingOrderConfirmationController method displayConfirmation.

/**
 * Invoked once the payment is complete and order is fulfilled
 * @param model
 * @param request
 * @param response
 * @param locale
 * @return
 * @throws Exception
 */
@RequestMapping("/confirmation.html")
public String displayConfirmation(Model model, HttpServletRequest request, HttpServletResponse response, Locale locale) throws Exception {
    Language language = (Language) request.getAttribute("LANGUAGE");
    MerchantStore store = (MerchantStore) request.getAttribute(Constants.MERCHANT_STORE);
    Long orderId = super.getSessionAttribute(Constants.ORDER_ID, request);
    if (orderId == null) {
        return new StringBuilder().append("redirect:").append(Constants.SHOP_URI).toString();
    }
    // get the order
    Order order = orderService.getById(orderId);
    if (order == null) {
        LOGGER.warn("Order id [" + orderId + "] does not exist");
        throw new Exception("Order id [" + orderId + "] does not exist");
    }
    if (order.getMerchant().getId().intValue() != store.getId().intValue()) {
        LOGGER.warn("Store id [" + store.getId() + "] differs from order.store.id [" + order.getMerchant().getId() + "]");
        return new StringBuilder().append("redirect:").append(Constants.SHOP_URI).toString();
    }
    if (super.getSessionAttribute(Constants.ORDER_ID_TOKEN, request) != null) {
        // set this unique token for performing unique operations in the confirmation
        model.addAttribute("confirmation", "confirmation");
    }
    // remove unique token
    super.removeAttribute(Constants.ORDER_ID_TOKEN, request);
    String[] orderMessageParams = { store.getStorename() };
    String orderMessage = messages.getMessage("label.checkout.text", orderMessageParams, locale);
    model.addAttribute("ordermessage", orderMessage);
    String[] orderIdParams = { String.valueOf(order.getId()) };
    String orderMessageId = messages.getMessage("label.checkout.orderid", orderIdParams, locale);
    model.addAttribute("ordermessageid", orderMessageId);
    String[] orderEmailParams = { order.getCustomerEmailAddress() };
    String orderEmailMessage = messages.getMessage("label.checkout.email", orderEmailParams, locale);
    model.addAttribute("orderemail", orderEmailMessage);
    ReadableOrder readableOrder = orderFacade.getReadableOrder(orderId, store, language);
    // resolve country and Zone for GA
    String countryCode = readableOrder.getCustomer().getBilling().getCountry();
    Map<String, Country> countriesMap = countryService.getCountriesMap(language);
    Country billingCountry = countriesMap.get(countryCode);
    if (billingCountry != null) {
        readableOrder.getCustomer().getBilling().setCountry(billingCountry.getName());
    }
    String zoneCode = readableOrder.getCustomer().getBilling().getZone();
    Map<String, Zone> zonesMap = zoneService.getZones(language);
    Zone billingZone = zonesMap.get(zoneCode);
    if (billingZone != null) {
        readableOrder.getCustomer().getBilling().setZone(billingZone.getName());
    }
    model.addAttribute("order", readableOrder);
    // check if any downloads exist for this order
    List<OrderProductDownload> orderProductDownloads = orderProdctDownloadService.getByOrderId(order.getId());
    if (CollectionUtils.isNotEmpty(orderProductDownloads)) {
        ReadableOrderProductDownloadPopulator populator = new ReadableOrderProductDownloadPopulator();
        List<ReadableOrderProductDownload> downloads = new ArrayList<ReadableOrderProductDownload>();
        for (OrderProductDownload download : orderProductDownloads) {
            ReadableOrderProductDownload view = new ReadableOrderProductDownload();
            populator.populate(download, view, store, language);
            downloads.add(view);
        }
        model.addAttribute("downloads", downloads);
    }
    /**
     * template *
     */
    StringBuilder template = new StringBuilder().append(ControllerConstants.Tiles.Checkout.confirmation).append(".").append(store.getStoreTemplate());
    return template.toString();
}
Also used : Order(com.salesmanager.core.model.order.Order) ReadableOrder(com.salesmanager.shop.model.order.v0.ReadableOrder) ReadableOrderProductDownloadPopulator(com.salesmanager.shop.populator.order.ReadableOrderProductDownloadPopulator) Zone(com.salesmanager.core.model.reference.zone.Zone) ReadableOrderProductDownload(com.salesmanager.shop.model.order.ReadableOrderProductDownload) ArrayList(java.util.ArrayList) ReadableOrder(com.salesmanager.shop.model.order.v0.ReadableOrder) Language(com.salesmanager.core.model.reference.language.Language) Country(com.salesmanager.core.model.reference.country.Country) OrderProductDownload(com.salesmanager.core.model.order.orderproduct.OrderProductDownload) ReadableOrderProductDownload(com.salesmanager.shop.model.order.ReadableOrderProductDownload) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)2 OrderProductDownload (com.salesmanager.core.model.order.orderproduct.OrderProductDownload)2 Language (com.salesmanager.core.model.reference.language.Language)2 ReadableOrderProductDownload (com.salesmanager.shop.model.order.ReadableOrderProductDownload)2 ReadableOrder (com.salesmanager.shop.model.order.v0.ReadableOrder)2 ReadableOrderProductDownloadPopulator (com.salesmanager.shop.populator.order.ReadableOrderProductDownloadPopulator)2 ArrayList (java.util.ArrayList)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 Customer (com.salesmanager.core.model.customer.Customer)1 Order (com.salesmanager.core.model.order.Order)1 Country (com.salesmanager.core.model.reference.country.Country)1 Zone (com.salesmanager.core.model.reference.zone.Zone)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1 Authentication (org.springframework.security.core.Authentication)1