Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Facing an issue with checkout api #986

Open
Sagar11221 opened this issue Feb 2, 2024 · 1 comment
Open

Facing an issue with checkout api #986

Sagar11221 opened this issue Feb 2, 2024 · 1 comment

Comments

@Sagar11221
Copy link

I am not able to place order when using this checkout api (" http://localhost:8080/api/v1/cart/{code}/checkout").

@Sagar11221
Copy link
Author

Sagar11221 commented Feb 4, 2024

In order to solve this issue, the modifications in certain .java classes have to be done-

1-OrderApi.java
This class consist of a checkout method which is actually being executed by Checkout Api .In this you have to comment the "if condition" that is checking " //check if customer already exist" for every new registered use because of which it is throwing "ServiceRuntimeException"

2-OrderFacadeImpl.java
In this also you have to comment the same "if condition" line that is after "//lookup existing customer" and also comment try and catch block that is coming after "// update cart" and "//email management" line.

3 OrderService.java
In this you have to add some @params above the "processOrder()" method to where there is no transaction parameter in the method, inorder to make "processOrder()" method work.

        /**
             * Placing orders. Mainly used in the administration tool
             * @param order
             * @param customer
             * @param items
             * @param summary
             * @param payment
             * @param store
             * @return
             * @throws ServiceException
             */

4 OrderServiceImpl.java

Comment the lines

      "// first process payment
              // Transaction processTransaction = paymentService.processPayment(customer,
              // store, payment, items, order);"

Write this code after the "if condition" that is after the above commented line

     Set<OrderStatusHistory> statusHistorySet = new HashSet<OrderStatusHistory>();
     OrderStatusHistory statusHistory = new OrderStatusHistory();
     statusHistory.setStatus(order.getStatus());
     statusHistory.setDateAdded(order.getDatePurchased());
     System.out.println("&&&&&&&&&&&&&&&&&&&&&&&&&&&aftersetdateadded&&");
     statusHistory.setOrder(order);
     statusHistorySet.add(statusHistory);
     order.setOrderHistory(statusHistorySet);

If not adding this above code will get the "not-null property exception" for "dateAdded" property in OrderStatusHistory.java class because eventually the dateAdded property is not getting set after if condition.

Comment these lines

    // 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);
    // }

And you can test the checkoutapi now, it will work fine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant