Search in sources :

Example 1 with PersistableOrderPopulator

use of com.salesmanager.shop.populator.order.PersistableOrderPopulator in project shopizer by shopizer-ecommerce.

the class OrderRESTController method createOrder.

/**
 * This method is for adding order to the system. Generally used for the purpose of migration only
 * This method won't process any payment nor create transactions
 * @param store
 * @param order
 * @param request
 * @param response
 * @return
 * @throws Exception
 * Use v1 methods
 */
@RequestMapping(value = "/{store}/order", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
@ResponseBody
@Deprecated
public PersistableOrder createOrder(@PathVariable final String store, @Valid @RequestBody PersistableOrder order, 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;
    }
    PersistableCustomer cust = order.getCustomer();
    if (cust != null) {
        Customer customer = new Customer();
        /*			CustomerPopulator populator = new CustomerPopulator();
			populator.setCountryService(countryService);
			populator.setCustomerOptionService(customerOptionService);
			populator.setCustomerOptionValueService(customerOptionValueService);
			populator.setLanguageService(languageService);
			populator.setZoneService(zoneService);
			populator.setGroupService(groupService);*/
        customerPopulator.populate(cust, customer, merchantStore, merchantStore.getDefaultLanguage());
        customerService.save(customer);
        cust.setId(customer.getId());
    }
    Order modelOrder = new Order();
    PersistableOrderPopulator populator = new PersistableOrderPopulator();
    populator.setDigitalProductService(digitalProductService);
    populator.setProductAttributeService(productAttributeService);
    populator.setProductService(productService);
    populator.populate(order, modelOrder, merchantStore, merchantStore.getDefaultLanguage());
    orderService.save(modelOrder);
    order.setId(modelOrder.getId());
    return order;
}
Also used : Order(com.salesmanager.core.model.order.Order) PersistableOrder(com.salesmanager.shop.model.order.v0.PersistableOrder) PersistableOrderPopulator(com.salesmanager.shop.populator.order.PersistableOrderPopulator) Customer(com.salesmanager.core.model.customer.Customer) PersistableCustomer(com.salesmanager.shop.model.customer.PersistableCustomer) PersistableCustomer(com.salesmanager.shop.model.customer.PersistableCustomer) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore)

Aggregations

Customer (com.salesmanager.core.model.customer.Customer)1 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)1 Order (com.salesmanager.core.model.order.Order)1 PersistableCustomer (com.salesmanager.shop.model.customer.PersistableCustomer)1 PersistableOrder (com.salesmanager.shop.model.order.v0.PersistableOrder)1 PersistableOrderPopulator (com.salesmanager.shop.populator.order.PersistableOrderPopulator)1