use of com.salesmanager.core.model.catalog.product.Product in project shopizer by shopizer-ecommerce.
the class ProductImageApi method imageDetails.
/**
* Patch image (change position)
*
* @param id
* @param files
* @param position
* @param merchantStore
* @param language
* @throws IOException
*/
@ResponseStatus(HttpStatus.OK)
@RequestMapping(value = { "/private/products/{id}/image/{imageId}", "/auth/products/{id}/image/{id}" }, method = RequestMethod.PATCH)
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
public void imageDetails(@PathVariable Long id, @PathVariable Long imageId, @RequestParam(value = "order", required = false, defaultValue = "0") Integer position, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) throws IOException {
try {
Product p = productService.getById(id);
if (p == null) {
throw new ResourceNotFoundException("Product image [" + imageId + "] not found for product id [" + id + "] and merchant [" + merchantStore.getCode() + "]");
}
if (p.getMerchantStore().getId() != merchantStore.getId()) {
throw new ResourceNotFoundException("Product image [" + imageId + "] not found for product id [" + id + "] and merchant [" + merchantStore.getCode() + "]");
}
Optional<ProductImage> productImage = productImageService.getProductImage(imageId, id, merchantStore);
if (productImage.isPresent()) {
productImage.get().setSortOrder(position);
productImageService.updateProductImage(p, productImage.get());
} else {
throw new ResourceNotFoundException("Product image [" + imageId + "] not found for product id [" + id + "] and merchant [" + merchantStore.getCode() + "]");
}
} catch (Exception e) {
LOGGER.error("Error while deleting ProductImage", e);
throw new ServiceRuntimeException("ProductImage [" + imageId + "] cannot be edited");
}
}
use of com.salesmanager.core.model.catalog.product.Product in project shopizer by shopizer-ecommerce.
the class ProductReviewApi method getAll.
@RequestMapping(value = "/products/{id}/reviews", method = RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
public List<ReadableProductReview> getAll(@PathVariable final Long id, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletResponse response) {
try {
// product exist
Product product = productService.getById(id);
if (product == null) {
response.sendError(404, "Product id " + id + " does not exists");
return null;
}
List<ReadableProductReview> reviews = productCommonFacade.getProductReviews(product, merchantStore, language);
return reviews;
} catch (Exception e) {
LOGGER.error("Error while getting product reviews", e);
try {
response.sendError(503, "Error while getting product reviews" + e.getMessage());
} catch (Exception ignore) {
}
return null;
}
}
use of com.salesmanager.core.model.catalog.product.Product in project shopizer by shopizer-ecommerce.
the class PackingBox method getItemPackagesDetails.
@Override
public List<PackageDetails> getItemPackagesDetails(List<ShippingProduct> products, MerchantStore store) throws ServiceException {
List<PackageDetails> packages = new ArrayList<PackageDetails>();
for (ShippingProduct shippingProduct : products) {
Product product = shippingProduct.getProduct();
if (product.isProductVirtual()) {
continue;
}
// BigDecimal weight = product.getProductWeight();
Set<ProductAttribute> attributes = product.getAttributes();
// set attributes values
BigDecimal w = product.getProductWeight();
BigDecimal h = product.getProductHeight();
BigDecimal l = product.getProductLength();
BigDecimal wd = product.getProductWidth();
if (w == null) {
w = new BigDecimal(defaultWeight);
}
if (h == null) {
h = new BigDecimal(defaultHeight);
}
if (l == null) {
l = new BigDecimal(defaultLength);
}
if (wd == null) {
wd = new BigDecimal(defaultWidth);
}
if (attributes != null && attributes.size() > 0) {
for (ProductAttribute attribute : attributes) {
if (attribute.getAttributeAdditionalWeight() != null && attribute.getProductAttributeWeight() != null) {
w = w.add(attribute.getProductAttributeWeight());
}
}
}
if (shippingProduct.getQuantity() == 1) {
PackageDetails detail = new PackageDetails();
detail.setShippingHeight(h.doubleValue());
detail.setShippingLength(l.doubleValue());
detail.setShippingWeight(w.doubleValue());
detail.setShippingWidth(wd.doubleValue());
detail.setShippingQuantity(shippingProduct.getQuantity());
String description = "item";
if (product.getDescriptions().size() > 0) {
description = product.getDescriptions().iterator().next().getName();
}
detail.setItemName(description);
packages.add(detail);
} else if (shippingProduct.getQuantity() > 1) {
for (int i = 0; i < shippingProduct.getQuantity(); i++) {
PackageDetails detail = new PackageDetails();
detail.setShippingHeight(h.doubleValue());
detail.setShippingLength(l.doubleValue());
detail.setShippingWeight(w.doubleValue());
detail.setShippingWidth(wd.doubleValue());
// issue seperate shipping
detail.setShippingQuantity(1);
String description = "item";
if (product.getDescriptions().size() > 0) {
description = product.getDescriptions().iterator().next().getName();
}
detail.setItemName(description);
packages.add(detail);
}
}
}
return packages;
}
use of com.salesmanager.core.model.catalog.product.Product in project shopizer by shopizer-ecommerce.
the class OrderFacadeImpl method processOrderModel.
/**
* Commit an order
* @param order
* @param customer
* @param transaction
* @param store
* @param language
* @return
* @throws ServiceException
*/
private Order processOrderModel(ShopOrder order, Customer customer, Transaction transaction, MerchantStore store, Language language) throws ServiceException {
try {
if (order.isShipToBillingAdress()) {
// customer shipping is billing
PersistableCustomer orderCustomer = order.getCustomer();
Address billing = orderCustomer.getBilling();
orderCustomer.setDelivery(billing);
}
Order modelOrder = new Order();
modelOrder.setDatePurchased(new Date());
modelOrder.setBilling(customer.getBilling());
modelOrder.setDelivery(customer.getDelivery());
modelOrder.setPaymentModuleCode(order.getPaymentModule());
modelOrder.setPaymentType(PaymentType.valueOf(order.getPaymentMethodType()));
modelOrder.setShippingModuleCode(order.getShippingModule());
modelOrder.setCustomerAgreement(order.isCustomerAgreed());
// set the store
modelOrder.setLocale(LocaleUtils.getLocale(store));
// locale based
// on the
// country for
// order $
// formatting
List<ShoppingCartItem> shoppingCartItems = order.getShoppingCartItems();
Set<OrderProduct> orderProducts = new LinkedHashSet<OrderProduct>();
if (!StringUtils.isBlank(order.getComments())) {
OrderStatusHistory statusHistory = new OrderStatusHistory();
statusHistory.setStatus(OrderStatus.ORDERED);
statusHistory.setOrder(modelOrder);
statusHistory.setDateAdded(new Date());
statusHistory.setComments(order.getComments());
modelOrder.getOrderHistory().add(statusHistory);
}
OrderProductPopulator orderProductPopulator = new OrderProductPopulator();
orderProductPopulator.setDigitalProductService(digitalProductService);
orderProductPopulator.setProductAttributeService(productAttributeService);
orderProductPopulator.setProductService(productService);
String shoppingCartCode = null;
for (ShoppingCartItem item : shoppingCartItems) {
if (shoppingCartCode == null && item.getShoppingCart() != null) {
shoppingCartCode = item.getShoppingCart().getShoppingCartCode();
}
/**
* Before processing order quantity of item must be > 0
*/
Product product = productService.getById(item.getProductId());
if (product == null) {
throw new ServiceException(ServiceException.EXCEPTION_INVENTORY_MISMATCH);
}
LOGGER.debug("Validate inventory");
for (ProductAvailability availability : product.getAvailabilities()) {
if (availability.getRegion().equals(Constants.ALL_REGIONS)) {
int qty = availability.getProductQuantity();
if (qty < item.getQuantity()) {
throw new ServiceException(ServiceException.EXCEPTION_INVENTORY_MISMATCH);
}
}
}
OrderProduct orderProduct = new OrderProduct();
orderProduct = orderProductPopulator.populate(item, orderProduct, store, language);
orderProduct.setOrder(modelOrder);
orderProducts.add(orderProduct);
}
modelOrder.setOrderProducts(orderProducts);
OrderTotalSummary summary = order.getOrderTotalSummary();
List<com.salesmanager.core.model.order.OrderTotal> totals = summary.getTotals();
// re-order totals
Collections.sort(totals, new Comparator<com.salesmanager.core.model.order.OrderTotal>() {
public int compare(com.salesmanager.core.model.order.OrderTotal x, com.salesmanager.core.model.order.OrderTotal y) {
if (x.getSortOrder() == y.getSortOrder())
return 0;
return x.getSortOrder() < y.getSortOrder() ? -1 : 1;
}
});
Set<com.salesmanager.core.model.order.OrderTotal> modelTotals = new LinkedHashSet<com.salesmanager.core.model.order.OrderTotal>();
for (com.salesmanager.core.model.order.OrderTotal total : totals) {
total.setOrder(modelOrder);
modelTotals.add(total);
}
modelOrder.setOrderTotal(modelTotals);
modelOrder.setTotal(order.getOrderTotalSummary().getTotal());
// order misc objects
modelOrder.setCurrency(store.getCurrency());
modelOrder.setMerchant(store);
// customer object
orderCustomer(customer, modelOrder, language);
// populate shipping information
if (!StringUtils.isBlank(order.getShippingModule())) {
modelOrder.setShippingModuleCode(order.getShippingModule());
}
String paymentType = order.getPaymentMethodType();
Payment payment = new Payment();
payment.setPaymentType(PaymentType.valueOf(paymentType));
payment.setAmount(order.getOrderTotalSummary().getTotal());
payment.setModuleName(order.getPaymentModule());
payment.setCurrency(modelOrder.getCurrency());
if (order.getPayment() != null && order.getPayment().get("paymentToken") != null) {
// set
// token
String paymentToken = order.getPayment().get("paymentToken");
Map<String, String> paymentMetaData = new HashMap<String, String>();
payment.setPaymentMetaData(paymentMetaData);
paymentMetaData.put("paymentToken", paymentToken);
}
if (PaymentType.CREDITCARD.name().equals(paymentType)) {
payment = new CreditCardPayment();
((CreditCardPayment) payment).setCardOwner(order.getPayment().get("creditcard_card_holder"));
((CreditCardPayment) payment).setCredidCardValidationNumber(order.getPayment().get("creditcard_card_cvv"));
((CreditCardPayment) payment).setCreditCardNumber(order.getPayment().get("creditcard_card_number"));
((CreditCardPayment) payment).setExpirationMonth(order.getPayment().get("creditcard_card_expirationmonth"));
((CreditCardPayment) payment).setExpirationYear(order.getPayment().get("creditcard_card_expirationyear"));
Map<String, String> paymentMetaData = order.getPayment();
payment.setPaymentMetaData(paymentMetaData);
payment.setPaymentType(PaymentType.valueOf(paymentType));
payment.setAmount(order.getOrderTotalSummary().getTotal());
payment.setModuleName(order.getPaymentModule());
payment.setCurrency(modelOrder.getCurrency());
CreditCardType creditCardType = null;
String cardType = order.getPayment().get("creditcard_card_type");
// supported credit cards
if (CreditCardType.AMEX.name().equalsIgnoreCase(cardType)) {
creditCardType = CreditCardType.AMEX;
} else if (CreditCardType.VISA.name().equalsIgnoreCase(cardType)) {
creditCardType = CreditCardType.VISA;
} else if (CreditCardType.MASTERCARD.name().equalsIgnoreCase(cardType)) {
creditCardType = CreditCardType.MASTERCARD;
} else if (CreditCardType.DINERS.name().equalsIgnoreCase(cardType)) {
creditCardType = CreditCardType.DINERS;
} else if (CreditCardType.DISCOVERY.name().equalsIgnoreCase(cardType)) {
creditCardType = CreditCardType.DISCOVERY;
}
((CreditCardPayment) payment).setCreditCard(creditCardType);
if (creditCardType != null) {
CreditCard cc = new CreditCard();
cc.setCardType(creditCardType);
cc.setCcCvv(((CreditCardPayment) payment).getCredidCardValidationNumber());
cc.setCcOwner(((CreditCardPayment) payment).getCardOwner());
cc.setCcExpires(((CreditCardPayment) payment).getExpirationMonth() + "-" + ((CreditCardPayment) payment).getExpirationYear());
// hash credit card number
if (!StringUtils.isBlank(cc.getCcNumber())) {
String maskedNumber = CreditCardUtils.maskCardNumber(order.getPayment().get("creditcard_card_number"));
cc.setCcNumber(maskedNumber);
modelOrder.setCreditCard(cc);
}
}
}
if (PaymentType.PAYPAL.name().equals(paymentType)) {
// check for previous transaction
if (transaction == null) {
throw new ServiceException("payment.error");
}
payment = new com.salesmanager.core.model.payments.PaypalPayment();
((com.salesmanager.core.model.payments.PaypalPayment) payment).setPayerId(transaction.getTransactionDetails().get("PAYERID"));
((com.salesmanager.core.model.payments.PaypalPayment) payment).setPaymentToken(transaction.getTransactionDetails().get("TOKEN"));
}
modelOrder.setShoppingCartCode(shoppingCartCode);
modelOrder.setPaymentModuleCode(order.getPaymentModule());
payment.setModuleName(order.getPaymentModule());
if (transaction != null) {
orderService.processOrder(modelOrder, customer, order.getShoppingCartItems(), summary, payment, store);
} else {
orderService.processOrder(modelOrder, customer, order.getShoppingCartItems(), summary, payment, transaction, store);
}
return modelOrder;
} catch (ServiceException se) {
// may be invalid credit card
throw se;
} catch (Exception e) {
throw new ServiceException(e);
}
}
use of com.salesmanager.core.model.catalog.product.Product in project shopizer by shopizer-ecommerce.
the class SearchFacadeImpl method convertToSearchProductList.
@Override
public SearchProductList convertToSearchProductList(SearchResponse searchResponse, MerchantStore merchantStore, int start, int count, Language language) {
SearchProductList returnList = new SearchProductList();
List<SearchEntry> entries = searchResponse.getEntries();
if (CollectionUtils.isNotEmpty(entries)) {
List<Long> ids = entries.stream().map(SearchEntry::getIndexProduct).map(IndexProduct::getId).map(Long::parseLong).collect(Collectors.toList());
ProductCriteria searchCriteria = new ProductCriteria();
searchCriteria.setMaxCount(count);
searchCriteria.setStartIndex(start);
searchCriteria.setProductIds(ids);
searchCriteria.setAvailable(true);
ProductList productList = productService.listByStore(merchantStore, language, searchCriteria);
List<ReadableProduct> readableProducts = productList.getProducts().stream().map(product -> convertProductToReadableProduct(product, merchantStore, language)).collect(Collectors.toList());
returnList.getProducts().addAll(readableProducts);
returnList.setProductCount(productList.getProducts().size());
}
// Facets
Map<String, List<SearchFacet>> facets = Optional.ofNullable(searchResponse.getFacets()).orElse(Collections.emptyMap());
List<ReadableCategory> categoryProxies = getCategoryFacets(merchantStore, language, facets);
returnList.setCategoryFacets(categoryProxies);
List<SearchFacet> manufacturersFacets = facets.entrySet().stream().filter(e -> MANUFACTURER_FACET_NAME.equals(e.getKey())).findFirst().map(Entry::getValue).orElse(Collections.emptyList());
if (CollectionUtils.isNotEmpty(manufacturersFacets)) {
// TODO add manufacturer facets
}
return returnList;
}
Aggregations