use of com.salesmanager.core.model.order.orderstatus.OrderStatus in project shopizer by shopizer-ecommerce.
the class PersistableOrderPopulator method populate.
@Override
public Order populate(PersistableOrder source, Order target, MerchantStore store, Language language) throws ConversionException {
Validate.notNull(productService, "productService must be set");
Validate.notNull(digitalProductService, "digitalProductService must be set");
Validate.notNull(productAttributeService, "productAttributeService must be set");
Validate.notNull(customerService, "customerService must be set");
Validate.notNull(countryService, "countryService must be set");
Validate.notNull(zoneService, "zoneService must be set");
Validate.notNull(currencyService, "currencyService must be set");
try {
Map<String, Country> countriesMap = countryService.getCountriesMap(language);
Map<String, Zone> zonesMap = zoneService.getZones(language);
/**
* customer *
*/
PersistableCustomer customer = source.getCustomer();
if (customer != null) {
if (customer.getId() != null && customer.getId() > 0) {
Customer modelCustomer = customerService.getById(customer.getId());
if (modelCustomer == null) {
throw new ConversionException("Customer id " + customer.getId() + " does not exists");
}
if (modelCustomer.getMerchantStore().getId().intValue() != store.getId().intValue()) {
throw new ConversionException("Customer id " + customer.getId() + " does not exists for store " + store.getCode());
}
target.setCustomerId(modelCustomer.getId());
target.setBilling(modelCustomer.getBilling());
target.setDelivery(modelCustomer.getDelivery());
target.setCustomerEmailAddress(source.getCustomer().getEmailAddress());
}
}
target.setLocale(LocaleUtils.getLocale(store));
CreditCard creditCard = source.getCreditCard();
if (creditCard != null) {
String maskedNumber = CreditCardUtils.maskCardNumber(creditCard.getCcNumber());
creditCard.setCcNumber(maskedNumber);
target.setCreditCard(creditCard);
}
Currency currency = null;
try {
currency = currencyService.getByCode(source.getCurrency());
} catch (Exception e) {
throw new ConversionException("Currency not found for code " + source.getCurrency());
}
if (currency == null) {
throw new ConversionException("Currency not found for code " + source.getCurrency());
}
target.setCurrency(currency);
target.setDatePurchased(source.getDatePurchased());
// target.setCurrency(store.getCurrency());
target.setCurrencyValue(new BigDecimal(0));
target.setMerchant(store);
target.setStatus(source.getOrderStatus());
target.setPaymentModuleCode(source.getPaymentModule());
target.setPaymentType(source.getPaymentType());
target.setShippingModuleCode(source.getShippingModule());
target.setCustomerAgreement(source.isCustomerAgreed());
target.setConfirmedAddress(source.isConfirmedAddress());
if (source.getPreviousOrderStatus() != null) {
List<OrderStatus> orderStatusList = source.getPreviousOrderStatus();
for (OrderStatus status : orderStatusList) {
OrderStatusHistory statusHistory = new OrderStatusHistory();
statusHistory.setStatus(status);
statusHistory.setOrder(target);
target.getOrderHistory().add(statusHistory);
}
}
if (!StringUtils.isBlank(source.getComments())) {
OrderStatusHistory statusHistory = new OrderStatusHistory();
statusHistory.setStatus(null);
statusHistory.setOrder(target);
statusHistory.setComments(source.getComments());
target.getOrderHistory().add(statusHistory);
}
List<PersistableOrderProduct> products = source.getOrderProductItems();
if (CollectionUtils.isEmpty(products)) {
throw new ConversionException("Requires at least 1 PersistableOrderProduct");
}
com.salesmanager.shop.populator.order.PersistableOrderProductPopulator orderProductPopulator = new PersistableOrderProductPopulator();
orderProductPopulator.setProductAttributeService(productAttributeService);
orderProductPopulator.setProductService(productService);
orderProductPopulator.setDigitalProductService(digitalProductService);
for (PersistableOrderProduct orderProduct : products) {
OrderProduct modelOrderProduct = new OrderProduct();
orderProductPopulator.populate(orderProduct, modelOrderProduct, store, language);
target.getOrderProducts().add(modelOrderProduct);
}
List<OrderTotal> orderTotals = source.getTotals();
if (CollectionUtils.isNotEmpty(orderTotals)) {
for (OrderTotal total : orderTotals) {
com.salesmanager.core.model.order.OrderTotal totalModel = new com.salesmanager.core.model.order.OrderTotal();
totalModel.setModule(total.getModule());
totalModel.setOrder(target);
totalModel.setOrderTotalCode(total.getCode());
totalModel.setTitle(total.getTitle());
totalModel.setValue(total.getValue());
target.getOrderTotal().add(totalModel);
}
}
} catch (Exception e) {
throw new ConversionException(e);
}
return target;
}
use of com.salesmanager.core.model.order.orderstatus.OrderStatus in project shopizer by shopizer-ecommerce.
the class OrderFacadeImpl method initializeOrder.
@Override
public ShopOrder initializeOrder(MerchantStore store, Customer customer, ShoppingCart shoppingCart, Language language) throws Exception {
// assert not null shopping cart items
ShopOrder order = new ShopOrder();
OrderStatus orderStatus = OrderStatus.ORDERED;
order.setOrderStatus(orderStatus);
if (customer == null) {
customer = this.initEmptyCustomer(store);
}
PersistableCustomer persistableCustomer = persistableCustomer(customer, store, language);
order.setCustomer(persistableCustomer);
// keep list of shopping cart items for core price calculation
List<ShoppingCartItem> items = new ArrayList<ShoppingCartItem>(shoppingCart.getLineItems());
order.setShoppingCartItems(items);
return order;
}
use of com.salesmanager.core.model.order.orderstatus.OrderStatus in project shopizer by shopizer-ecommerce.
the class OrderApi method updateOrderStatus.
@RequestMapping(value = { "/private/orders/{id}/status" }, method = RequestMethod.PUT)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "string", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "string", defaultValue = "en") })
public void updateOrderStatus(@PathVariable final Long id, @Valid @RequestBody String status, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) {
String user = authorizationUtils.authenticatedUser();
authorizationUtils.authorizeUser(user, Stream.of(Constants.GROUP_SUPERADMIN, Constants.GROUP_ADMIN, Constants.GROUP_ADMIN_ORDER, Constants.GROUP_ADMIN_RETAIL).collect(Collectors.toList()), merchantStore);
Order order = orderService.getOrder(id, merchantStore);
if (order == null) {
throw new GenericRuntimeException("412", "Order not found [" + id + "]");
}
OrderStatus statusEnum = OrderStatus.valueOf(status);
orderFacade.updateOrderStatus(order, statusEnum, merchantStore);
return;
}
use of com.salesmanager.core.model.order.orderstatus.OrderStatus in project shopizer by shopizer-ecommerce.
the class OrderFacadeImpl method updateOrderStatus.
@Override
public void updateOrderStatus(Order order, OrderStatus newStatus, MerchantStore store) {
// make sure we are changing to different that current status
if (order.getStatus().equals(newStatus)) {
// we have the same status, lets just return
return;
}
OrderStatus oldStatus = order.getStatus();
order.setStatus(newStatus);
OrderStatusHistory history = new OrderStatusHistory();
history.setComments(messages.getMessage("email.order.status.changed", new String[] { oldStatus.name(), newStatus.name() }, LocaleUtils.getLocale(store)));
history.setCustomerNotified(0);
history.setStatus(newStatus);
history.setDateAdded(new Date());
try {
orderService.addOrderStatusHistory(order, history);
} catch (ServiceException e) {
e.printStackTrace();
}
}
use of com.salesmanager.core.model.order.orderstatus.OrderStatus in project shopizer by shopizer-ecommerce.
the class OrderServiceImpl method process.
private Order process(Order order, Customer customer, List<ShoppingCartItem> items, OrderTotalSummary summary, Payment payment, Transaction transaction, MerchantStore store) throws ServiceException {
Validate.notNull(order, "Order cannot be null");
Validate.notNull(customer, "Customer cannot be null (even if anonymous order)");
Validate.notEmpty(items, "ShoppingCart items cannot be null");
Validate.notNull(payment, "Payment cannot be null");
Validate.notNull(store, "MerchantStore cannot be null");
Validate.notNull(summary, "Order total Summary cannot be null");
UserContext context = UserContext.getCurrentInstance();
if (context != null) {
String ipAddress = context.getIpAddress();
if (!StringUtils.isBlank(ipAddress)) {
order.setIpAddress(ipAddress);
}
}
// first process payment
Transaction processTransaction = paymentService.processPayment(customer, store, payment, items, order);
if (order.getOrderHistory() == null || order.getOrderHistory().size() == 0 || order.getStatus() == null) {
OrderStatus status = order.getStatus();
if (status == null) {
status = OrderStatus.ORDERED;
order.setStatus(status);
}
Set<OrderStatusHistory> statusHistorySet = new HashSet<OrderStatusHistory>();
OrderStatusHistory statusHistory = new OrderStatusHistory();
statusHistory.setStatus(status);
statusHistory.setDateAdded(new Date());
statusHistory.setOrder(order);
statusHistorySet.add(statusHistory);
order.setOrderHistory(statusHistorySet);
}
if (customer.getId() == null || customer.getId() == 0) {
customerService.create(customer);
}
order.setCustomerId(customer.getId());
this.create(order);
if (transaction != null) {
transaction.setOrder(order);
if (transaction.getId() == null || transaction.getId() == 0) {
transactionService.create(transaction);
} else {
transactionService.update(transaction);
}
}
if (processTransaction != null) {
processTransaction.setOrder(order);
if (processTransaction.getId() == null || processTransaction.getId() == 0) {
transactionService.create(processTransaction);
} else {
transactionService.update(processTransaction);
}
}
/**
* decrement inventory
*/
LOGGER.debug("Update inventory");
Set<OrderProduct> products = order.getOrderProducts();
for (OrderProduct orderProduct : products) {
orderProduct.getProductQuantity();
Product p = productService.getById(orderProduct.getId());
if (p == null)
throw new ServiceException(ServiceException.EXCEPTION_INVENTORY_MISMATCH);
for (ProductAvailability availability : p.getAvailabilities()) {
int qty = availability.getProductQuantity();
if (qty < orderProduct.getProductQuantity()) {
// throw new ServiceException(ServiceException.EXCEPTION_INVENTORY_MISMATCH);
LOGGER.error("APP-BACKEND [" + ServiceException.EXCEPTION_INVENTORY_MISMATCH + "]");
}
qty = qty - orderProduct.getProductQuantity();
availability.setProductQuantity(qty);
}
productService.update(p);
}
return order;
}
Aggregations