use of com.salesmanager.core.model.order.OrderList in project shopizer by shopizer-ecommerce.
the class OrderFacadeImpl method getReadableOrderList.
@Override
public com.salesmanager.shop.model.order.v0.ReadableOrderList getReadableOrderList(OrderCriteria criteria, MerchantStore store) {
try {
criteria.setLegacyPagination(false);
OrderList orderList = orderService.getOrders(criteria, store);
List<Order> orders = orderList.getOrders();
com.salesmanager.shop.model.order.v0.ReadableOrderList returnList = new com.salesmanager.shop.model.order.v0.ReadableOrderList();
if (CollectionUtils.isEmpty(orders)) {
returnList.setRecordsTotal(0);
return returnList;
}
List<com.salesmanager.shop.model.order.v0.ReadableOrder> readableOrders = new ArrayList<com.salesmanager.shop.model.order.v0.ReadableOrder>();
for (Order order : orders) {
com.salesmanager.shop.model.order.v0.ReadableOrder readableOrder = new com.salesmanager.shop.model.order.v0.ReadableOrder();
readableOrderPopulator.populate(order, readableOrder, null, null);
readableOrders.add(readableOrder);
}
returnList.setOrders(readableOrders);
returnList.setRecordsTotal(orderList.getTotalCount());
returnList.setTotalPages(orderList.getTotalPages());
returnList.setNumber(orderList.getOrders().size());
returnList.setRecordsFiltered(orderList.getOrders().size());
return returnList;
} catch (Exception e) {
throw new ServiceRuntimeException("Error while getting orders", e);
}
}
use of com.salesmanager.core.model.order.OrderList in project shopizer by shopizer-ecommerce.
the class OrderFacadeImpl method getReadableOrderList.
private com.salesmanager.shop.model.order.v0.ReadableOrderList getReadableOrderList(OrderCriteria criteria, MerchantStore store, Language language) throws Exception {
OrderList orderList = orderService.listByStore(store, criteria);
// ReadableOrderPopulator orderPopulator = new ReadableOrderPopulator();
Locale locale = LocaleUtils.getLocale(language);
readableOrderPopulator.setLocale(locale);
List<Order> orders = orderList.getOrders();
com.salesmanager.shop.model.order.v0.ReadableOrderList returnList = new com.salesmanager.shop.model.order.v0.ReadableOrderList();
if (CollectionUtils.isEmpty(orders)) {
returnList.setRecordsTotal(0);
// returnList.setMessage("No results for store code " + store);
return null;
}
List<com.salesmanager.shop.model.order.v0.ReadableOrder> readableOrders = new ArrayList<com.salesmanager.shop.model.order.v0.ReadableOrder>();
for (Order order : orders) {
com.salesmanager.shop.model.order.v0.ReadableOrder readableOrder = new com.salesmanager.shop.model.order.v0.ReadableOrder();
readableOrderPopulator.populate(order, readableOrder, store, language);
readableOrders.add(readableOrder);
}
returnList.setRecordsTotal(orderList.getTotalCount());
return this.populateOrderList(orderList, store, language);
}
use of com.salesmanager.core.model.order.OrderList in project shopizer by shopizer-ecommerce.
the class OrderRepositoryImpl method listOrders.
@Override
public OrderList listOrders(MerchantStore store, OrderCriteria criteria) {
OrderList orderList = new OrderList();
StringBuilder countBuilderSelect = new StringBuilder();
StringBuilder objectBuilderSelect = new StringBuilder();
String orderByCriteria = " order by o.id desc";
if (criteria.getOrderBy() != null) {
if (CriteriaOrderBy.ASC.name().equals(criteria.getOrderBy().name())) {
orderByCriteria = " order by o.id asc";
}
}
String baseQuery = "select o from Order as o left join fetch o.delivery.country left join fetch o.delivery.zone left join fetch o.billing.country left join fetch o.billing.zone left join fetch o.orderTotal ot left join fetch o.orderProducts op left join fetch o.orderAttributes oa left join fetch op.orderAttributes opo left join fetch op.prices opp";
String countBaseQuery = "select count(o) from Order as o";
countBuilderSelect.append(countBaseQuery);
objectBuilderSelect.append(baseQuery);
StringBuilder objectBuilderWhere = new StringBuilder();
String storeQuery = " where o.merchant.code=:mCode";
objectBuilderWhere.append(storeQuery);
countBuilderSelect.append(storeQuery);
if (!StringUtils.isEmpty(criteria.getCustomerName())) {
String nameQuery = " and o.billing.firstName like:name or o.billing.lastName like:name";
objectBuilderWhere.append(nameQuery);
countBuilderSelect.append(nameQuery);
}
if (!StringUtils.isEmpty(criteria.getEmail())) {
String nameQuery = " and o.customerEmailAddress like:email";
objectBuilderWhere.append(nameQuery);
countBuilderSelect.append(nameQuery);
}
// id
if (criteria.getId() != null) {
String nameQuery = " and str(o.id) like:id";
objectBuilderWhere.append(nameQuery);
countBuilderSelect.append(nameQuery);
}
// phone
if (!StringUtils.isEmpty(criteria.getCustomerPhone())) {
String nameQuery = " and o.billing.telephone like:phone or o.delivery.telephone like:phone";
objectBuilderWhere.append(nameQuery);
countBuilderSelect.append(nameQuery);
}
// status
if (!StringUtils.isEmpty(criteria.getStatus())) {
String nameQuery = " and o.status =:status";
objectBuilderWhere.append(nameQuery);
countBuilderSelect.append(nameQuery);
}
objectBuilderWhere.append(orderByCriteria);
// count query
Query countQ = em.createQuery(countBuilderSelect.toString());
// object query
Query objectQ = em.createQuery(objectBuilderSelect.toString() + objectBuilderWhere.toString());
// customer name
if (!StringUtils.isEmpty(criteria.getCustomerName())) {
countQ.setParameter("name", like(criteria.getCustomerName()));
objectQ.setParameter("name", like(criteria.getCustomerName()));
}
// email
if (!StringUtils.isEmpty(criteria.getEmail())) {
countQ.setParameter("email", like(criteria.getEmail()));
objectQ.setParameter("email", like(criteria.getEmail()));
}
// id
if (criteria.getId() != null) {
countQ.setParameter("id", like(String.valueOf(criteria.getId())));
objectQ.setParameter("id", like(String.valueOf(criteria.getId())));
}
// phone
if (!StringUtils.isEmpty(criteria.getCustomerPhone())) {
countQ.setParameter("phone", like(criteria.getCustomerPhone()));
objectQ.setParameter("phone", like(criteria.getCustomerPhone()));
}
// status
if (!StringUtils.isEmpty(criteria.getStatus())) {
countQ.setParameter("status", OrderStatus.valueOf(criteria.getStatus().toUpperCase()));
objectQ.setParameter("status", OrderStatus.valueOf(criteria.getStatus().toUpperCase()));
}
countQ.setParameter("mCode", store.getCode());
objectQ.setParameter("mCode", store.getCode());
Number count = (Number) countQ.getSingleResult();
if (count.intValue() == 0)
return orderList;
@SuppressWarnings("rawtypes") GenericEntityList entityList = new GenericEntityList();
entityList.setTotalCount(count.intValue());
objectQ = RepositoryHelper.paginateQuery(objectQ, count, entityList, criteria);
// TODO use GenericEntityList
orderList.setTotalCount(entityList.getTotalCount());
orderList.setTotalPages(entityList.getTotalPages());
orderList.setOrders(objectQ.getResultList());
return orderList;
}
use of com.salesmanager.core.model.order.OrderList in project shopizer by shopizer-ecommerce.
the class OrderRepositoryImpl method listByStore.
/**
* @deprecated
*/
@SuppressWarnings("unchecked")
@Override
public OrderList listByStore(MerchantStore store, OrderCriteria criteria) {
OrderList orderList = new OrderList();
StringBuilder countBuilderSelect = new StringBuilder();
StringBuilder objectBuilderSelect = new StringBuilder();
String orderByCriteria = " order by o.id desc";
if (criteria.getOrderBy() != null) {
if (CriteriaOrderBy.ASC.name().equals(criteria.getOrderBy().name())) {
orderByCriteria = " order by o.id asc";
}
}
String countBaseQuery = "select count(o) from Order as o";
String baseQuery = "select o from Order as o left join fetch o.orderTotal ot left join fetch o.orderProducts op left join fetch o.orderAttributes oa left join fetch op.orderAttributes opo left join fetch op.prices opp";
countBuilderSelect.append(countBaseQuery);
objectBuilderSelect.append(baseQuery);
StringBuilder countBuilderWhere = new StringBuilder();
StringBuilder objectBuilderWhere = new StringBuilder();
String whereQuery = " where o.merchant.id=:mId";
countBuilderWhere.append(whereQuery);
objectBuilderWhere.append(whereQuery);
if (!StringUtils.isBlank(criteria.getCustomerName())) {
String nameQuery = " and o.billing.firstName like:nm or o.billing.lastName like:nm";
countBuilderWhere.append(nameQuery);
objectBuilderWhere.append(nameQuery);
}
if (!StringUtils.isBlank(criteria.getPaymentMethod())) {
String paymentQuery = " and o.paymentModuleCode like:pm";
countBuilderWhere.append(paymentQuery);
objectBuilderWhere.append(paymentQuery);
}
if (criteria.getCustomerId() != null) {
String customerQuery = " and o.customerId =:cid";
countBuilderWhere.append(customerQuery);
objectBuilderWhere.append(customerQuery);
}
objectBuilderWhere.append(orderByCriteria);
// count query
Query countQ = em.createQuery(countBuilderSelect.toString() + countBuilderWhere.toString());
// object query
Query objectQ = em.createQuery(objectBuilderSelect.toString() + objectBuilderWhere.toString());
countQ.setParameter("mId", store.getId());
objectQ.setParameter("mId", store.getId());
if (!StringUtils.isBlank(criteria.getCustomerName())) {
String nameParam = new StringBuilder().append("%").append(criteria.getCustomerName()).append("%").toString();
countQ.setParameter("nm", nameParam);
objectQ.setParameter("nm", nameParam);
}
if (!StringUtils.isBlank(criteria.getPaymentMethod())) {
String payementParam = new StringBuilder().append("%").append(criteria.getPaymentMethod()).append("%").toString();
countQ.setParameter("pm", payementParam);
objectQ.setParameter("pm", payementParam);
}
if (criteria.getCustomerId() != null) {
countQ.setParameter("cid", criteria.getCustomerId());
objectQ.setParameter("cid", criteria.getCustomerId());
}
Number count = (Number) countQ.getSingleResult();
orderList.setTotalCount(count.intValue());
if (count.intValue() == 0)
return orderList;
// TO BE USED
int max = criteria.getMaxCount();
int first = criteria.getStartIndex();
objectQ.setFirstResult(first);
if (max > 0) {
int maxCount = first + max;
objectQ.setMaxResults(Math.min(maxCount, count.intValue()));
}
orderList.setOrders(objectQ.getResultList());
return orderList;
}
use of com.salesmanager.core.model.order.OrderList in project shopizer by shopizer-ecommerce.
the class OrderTest method getMerchantOrders.
@Test
public void getMerchantOrders() throws ServiceException {
Currency currency = currencyService.getByCode(USD_CURRENCY_CODE);
Country country = countryService.getByCode("US");
Zone zone = zoneService.getByCode("VT");
Language en = languageService.getByCode("en");
MerchantStore merchant = merchantService.getByCode(MerchantStore.DEFAULT_STORE);
/**
* Create a customer *
*/
Customer customer = new Customer();
customer.setMerchantStore(merchant);
customer.setDefaultLanguage(en);
customer.setEmailAddress("email@email.com");
customer.setPassword("-1999");
customer.setNick("My New nick");
customer.setCompany(" Apple");
customer.setGender(CustomerGender.M);
customer.setDateOfBirth(new Date());
Billing billing = new Billing();
billing.setAddress("Billing address");
billing.setCity("Billing city");
billing.setCompany("Billing company");
billing.setCountry(country);
billing.setFirstName("Carl");
billing.setLastName("Samson");
billing.setPostalCode("Billing postal code");
billing.setState("Billing state");
billing.setZone(zone);
Delivery delivery = new Delivery();
delivery.setAddress("Shipping address");
delivery.setCountry(country);
delivery.setZone(zone);
customer.setBilling(billing);
customer.setDelivery(delivery);
customerService.create(customer);
// create a product with attributes
/**
* CATALOG CREATION *
*/
ProductType generalType = productTypeService.getProductType(ProductType.GENERAL_TYPE);
/**
* Create the category
*/
Category shirts = new Category();
shirts.setMerchantStore(merchant);
shirts.setCode("shirts");
CategoryDescription shirtsEnglishDescription = new CategoryDescription();
shirtsEnglishDescription.setName("Shirts");
shirtsEnglishDescription.setCategory(shirts);
shirtsEnglishDescription.setLanguage(en);
Set<CategoryDescription> descriptions = new HashSet<CategoryDescription>();
descriptions.add(shirtsEnglishDescription);
shirts.setDescriptions(descriptions);
categoryService.create(shirts);
/**
* Create a manufacturer
*/
Manufacturer addidas = new Manufacturer();
addidas.setMerchantStore(merchant);
addidas.setCode("addidas");
ManufacturerDescription addidasDesc = new ManufacturerDescription();
addidasDesc.setLanguage(en);
addidasDesc.setManufacturer(addidas);
addidasDesc.setName("Addidas");
addidas.getDescriptions().add(addidasDesc);
manufacturerService.create(addidas);
/**
* Create an option
*/
ProductOption option = new ProductOption();
option.setMerchantStore(merchant);
option.setCode("color");
option.setProductOptionType(ProductOptionType.Radio.name());
ProductOptionDescription optionDescription = new ProductOptionDescription();
optionDescription.setLanguage(en);
optionDescription.setName("Color");
optionDescription.setDescription("Item color");
optionDescription.setProductOption(option);
option.getDescriptions().add(optionDescription);
productOptionService.saveOrUpdate(option);
/**
* first option value *
*/
ProductOptionValue white = new ProductOptionValue();
white.setMerchantStore(merchant);
white.setCode("white");
ProductOptionValueDescription whiteDescription = new ProductOptionValueDescription();
whiteDescription.setLanguage(en);
whiteDescription.setName("White");
whiteDescription.setDescription("White color");
whiteDescription.setProductOptionValue(white);
white.getDescriptions().add(whiteDescription);
productOptionValueService.saveOrUpdate(white);
ProductOptionValue black = new ProductOptionValue();
black.setMerchantStore(merchant);
black.setCode("black");
/**
* second option value *
*/
ProductOptionValueDescription blackDesc = new ProductOptionValueDescription();
blackDesc.setLanguage(en);
blackDesc.setName("Black");
blackDesc.setDescription("Black color");
blackDesc.setProductOptionValue(black);
black.getDescriptions().add(blackDesc);
productOptionValueService.saveOrUpdate(black);
/**
* Create a complex product
*/
Product product = new Product();
product.setProductHeight(new BigDecimal(4));
product.setProductLength(new BigDecimal(3));
product.setProductWidth(new BigDecimal(1));
product.setSku("TB12345");
product.setManufacturer(addidas);
product.setType(generalType);
product.setMerchantStore(merchant);
// Product description
ProductDescription description = new ProductDescription();
description.setName("Short sleeves shirt");
description.setLanguage(en);
description.setProduct(product);
product.getDescriptions().add(description);
product.getCategories().add(shirts);
// availability
ProductAvailability availability = new ProductAvailability();
availability.setProductDateAvailable(new Date());
availability.setProductQuantity(100);
availability.setRegion("*");
// associate with product
availability.setProduct(product);
// price
ProductPrice dprice = new ProductPrice();
dprice.setDefaultPrice(true);
dprice.setProductPriceAmount(new BigDecimal(29.99));
dprice.setProductAvailability(availability);
ProductPriceDescription dpd = new ProductPriceDescription();
dpd.setName("Base price");
dpd.setProductPrice(dprice);
dpd.setLanguage(en);
dprice.getDescriptions().add(dpd);
availability.getPrices().add(dprice);
product.getAvailabilities().add(availability);
// attributes
// white
ProductAttribute whiteAttribute = new ProductAttribute();
whiteAttribute.setProduct(product);
whiteAttribute.setProductOption(option);
whiteAttribute.setAttributeDefault(true);
// no price variation
whiteAttribute.setProductAttributePrice(new BigDecimal(0));
// no weight variation
whiteAttribute.setProductAttributeWeight(new BigDecimal(0));
whiteAttribute.setProductOption(option);
whiteAttribute.setProductOptionValue(white);
product.getAttributes().add(whiteAttribute);
// black
ProductAttribute blackAttribute = new ProductAttribute();
blackAttribute.setProduct(product);
blackAttribute.setProductOption(option);
// 5 + dollars
blackAttribute.setProductAttributePrice(new BigDecimal(5));
// no weight variation
blackAttribute.setProductAttributeWeight(new BigDecimal(0));
blackAttribute.setProductOption(option);
blackAttribute.setProductOptionValue(black);
product.getAttributes().add(blackAttribute);
productService.create(product);
/**
* Create an order *
*/
Order order = new Order();
/**
* payment details *
*/
CreditCard creditCard = new CreditCard();
creditCard.setCardType(CreditCardType.VISA);
creditCard.setCcCvv("123");
creditCard.setCcExpires("12/30/2020");
creditCard.setCcNumber("123456789");
creditCard.setCcOwner("ccOwner");
order.setCreditCard(creditCard);
/**
* order core attributes *
*/
order.setDatePurchased(new Date());
order.setCurrency(currency);
order.setMerchant(merchant);
order.setLastModified(new Date());
// no price variation because of the currency
order.setCurrencyValue(new BigDecimal(1));
order.setCustomerId(1L);
order.setDelivery(delivery);
order.setIpAddress("ipAddress");
order.setMerchant(merchant);
order.setOrderDateFinished(new Date());
order.setPaymentType(PaymentType.CREDITCARD);
order.setPaymentModuleCode("payment Module Code");
order.setShippingModuleCode("UPS");
order.setStatus(OrderStatus.ORDERED);
order.setCustomerAgreement(true);
order.setConfirmedAddress(true);
order.setTotal(dprice.getProductPriceAmount());
order.setCustomerEmailAddress(customer.getEmailAddress());
order.setBilling(billing);
order.setDelivery(delivery);
/**
* ORDER PRODUCT *
*/
// OrderProduct
OrderProduct oproduct = new OrderProduct();
oproduct.setDownloads(null);
oproduct.setOneTimeCharge(dprice.getProductPriceAmount());
oproduct.setOrder(order);
oproduct.setProductName(description.getName());
oproduct.setProductQuantity(1);
oproduct.setSku(product.getSku());
// set order product price
OrderProductPrice orderProductPrice = new OrderProductPrice();
// default price (same as default product price)
orderProductPrice.setDefaultPrice(true);
orderProductPrice.setOrderProduct(oproduct);
orderProductPrice.setProductPrice(dprice.getProductPriceAmount());
orderProductPrice.setProductPriceCode(ProductPriceType.ONE_TIME.name());
oproduct.getPrices().add(orderProductPrice);
// order product attribute
OrderProductAttribute orderProductAttribute = new OrderProductAttribute();
orderProductAttribute.setOrderProduct(oproduct);
// no extra charge
orderProductAttribute.setProductAttributePrice(new BigDecimal("0.00"));
orderProductAttribute.setProductAttributeName(whiteDescription.getName());
orderProductAttribute.setProductOptionId(option.getId());
orderProductAttribute.setProductOptionValueId(white.getId());
oproduct.getOrderAttributes().add(orderProductAttribute);
order.getOrderProducts().add(oproduct);
/**
* ORDER TOTAL *
*/
OrderTotal subTotal = new OrderTotal();
subTotal.setOrder(order);
subTotal.setOrderTotalCode(Constants.OT_SUBTOTAL_MODULE_CODE);
subTotal.setSortOrder(0);
subTotal.setTitle("Sub Total");
subTotal.setValue(dprice.getProductPriceAmount());
order.getOrderTotal().add(subTotal);
OrderTotal total = new OrderTotal();
total.setOrder(order);
total.setOrderTotalCode(Constants.OT_TOTAL_MODULE_CODE);
total.setSortOrder(1);
total.setTitle("Total");
total.setValue(dprice.getProductPriceAmount());
order.getOrderTotal().add(total);
/**
* ORDER HISTORY *
*/
// create a log entry in order history
OrderStatusHistory history = new OrderStatusHistory();
history.setOrder(order);
history.setDateAdded(new Date());
history.setStatus(OrderStatus.ORDERED);
history.setComments("We received your order");
order.getOrderHistory().add(history);
/**
* CREATE ORDER *
*/
orderService.create(order);
/**
* SEARCH ORDERS *
*/
OrderCriteria criteria = new OrderCriteria();
criteria.setStartIndex(0);
criteria.setMaxCount(10);
OrderList ordserList = orderService.listByStore(merchant, criteria);
Assert.assertNotNull(ordserList);
Assert.assertNotNull("Merchant Orders are null.", ordserList.getOrders());
Assert.assertTrue("Merchant Orders count is not one.", (ordserList.getOrders() != null && ordserList.getOrders().size() == 1));
}
Aggregations