• Welcome to KonaKart Community Forum. Please login or sign up.
 

Saving a new order, not using normal checkout

Started by xzistance, February 10, 2009, 09:17:45 pm

Previous topic - Next topic

xzistance

So, I'm working on implementing Google Checkout, which has a Notification API that sends an XML string to a URL I specify to handle. So, a customer would go through the site and add the products they want to their cart, and then instead of doing the normal KK checkout, they'd hit the Google Checkout button which sends them off to Google with their cart info. They complete the order via Google.

When the order has been placed on Google, they send a new order notification to the URL I mentioned above.
I'm working on parsing that XML and creating a new order in KK so Google Checkout orders are still trackable in the KK system.

I've made pretty good progress, but am hitting a snag with the sessionId when trying to snag. Basically, it requires a session, and the session has to be a valid session in order for the order to save, using kkAppEng.getOrderMgr().saveOrder(/*send email?*/false);

Is there a way to get around this session issue or maybe a different way to save the order? I'm trying to avoid doing manual SQL queries to insert the order and its info..

Thanks for your help in advance,
Andy

trevor

Have you checked whether Google allows you to send in a parameter (i.e. the sessionId) which it sends back to you in the callback ?

xzistance

As far as I can tell, no, without figuring out some custom way of putting it in there and retrieving it.

xzistance

Hmm, even if I wanted to, it seems that kkAppEng.getSessionId() returns null at the cart page anyway. Any idea when it's supposed to get set or how to generate one based on the current customer?

julie

A session id gets generated when a customer logs in to KonaKart an is used to identify the customer in all API calls where you need to be logged in. If you want to create an order in KonaKart which you store in the KonaKart database, it has to be connected to a customer so that you know who made the order.

If your idea is for the customer to only identify himself to Google (by logging in) but not to KonaKart, then I think that what you need to do is to receive the XML (which I assume contains some sort of customer reference), and automatically create a customer matching that reference (using the KK API) if that customer doesn't already exist. Once you've created the customer, you can log him in using credentials which you used when you created him. The logging in process will give you a sessionId.   

xzistance

Thanks Julie-

I'll use this strategy going forward.

xzistance

Hey Julie (or anyone else that can help) -

I'm trying to do the logic for getting a CustomerIf object by doing some sort of search. I haven't been able to find methods in the CustomerMgr() that seem to do this, other than getting a Customer by passing in their sessionId. I know I could do a manual query, but my problem then is, how do I decrypt the password for that user so I can log them in to get the sessionId?

I hope this makes sense..

Thanks in advance,
Andy

julie

QuoteIf your idea is for the customer to only identify himself to Google (by logging in) but not to KonaKart, then I think that what you need to do is to receive the XML (which I assume contains some sort of customer reference), and automatically create a customer matching that reference (using the KK API) if that customer doesn't already exist. Once you've created the customer, you can log him in using credentials which you used when you created him. The logging in process will give you a sessionId. 


Since you create the customer, you also decide what credentials he has . Somewhere in the data passed back from Google you need to have the id for the customer you created (usually his eMail). You try logging in with this id and if the login fails, then you must register the customer, otherwise the login gives you a session id which you can use to create the order.

xzistance

Hey guys-

I'm trying to track down a case where I'm getting an exception when saving an order. This isn't happening all of the time, but on occasion.

Exception msg:
Exception Name = com.konakart.app.KKException<br>Exception Message = java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result.

Server log output:
WARN  (OrderMgr.java:saveOrder:471) Exception saving an order: Query details:
Criteria:: orders_products.products_model<=>orders_products.products_model='pallet':  orders_products.orders_id<=>orders_products.orders_id=103397:  orders_products.products_type<=>orders_products.products_type=0:  orders_products.products_price_0<=>orders_products.products_price_0=2.38:  orders_products.products_id<=>orders_products.products_id=1319:  orders_products.products_price<=>orders_products.products_price=2.38:  orders_products.products_name<=>orders_products.products_name='JFC White Shirataki Noodles 16.0 oz': 
Current Query SQL (may not be complete or applicable): SELECT  FROM orders_products WHERE orders_products.products_model='pallet' AND orders_products.orders_id=103397 AND orders_products.products_type=0 AND orders_products.products_price_0=2.38 AND orders_products.products_id=1319 AND orders_products.products_price=2.38 AND orders_products.products_name='JFC White Shirataki Noodles 16.0 oz'

I did some research on the Arithmetic exception, and it has to do with BigDecimal, usually when the divide function is trying to be used. I know for sure I'm not doing a divide function on any of my BigDecimal order values before I attempt to save. I am doing a couple of multiply functions, however. I've tried following the suggestions here: http://www.jroller.com/nwinkler/entry/the_trouble_with_bigdecimal

They suggest always passing a string to the BigDecimal constructor when creating a new BigDecimal to work with. I get the same error either way.

Is there something on/around line 471 in the saveOrder method that could be helpful in diagnosing why this is happening?

Thanks in advance..

heidi

I can't reproduce this.

Can you reproduce this on a fresh installation of KonaKart or on our online demo or is this only happening with your customised system?

If you can reproduce this on a fresh installation, please let us know how.

--Heidi

sashwill

I'm having the same error on my customized system. ver 2.2.6
order price of 3.72  applying a 1% discount rounded to 3 places gives an order price of 3.6830 quantity of 24

I was able to decomplie the OrderManager class and I noticed this code
Quoteif(orderproduct.getQuantity() > 1)
            {
                bigdecimal = orderproduct.getFinalPriceExTax().divide(new BigDecimal(orderproduct.getQuantity()));
            }


I had errors in my discount module until i changed the divide statement to include scale like this

Quote.divide(new BigDecimal(100), scale, BigDecimal.ROUND_HALF_UP);


Is it possible for me to change this code?
Would you be able to test and or provide a patch if this is confirmed as a problem?

trevor

Hello Sashwill,

This is a community forum . If you need to get patches etc. especially for old versions, you need to contact KonaKart support directly.

sashwill

Is there a bug report forum that I have missed?
I think I may have found a bug in the Konakart software. I was relaying that information to you.  If there was a fix, I was hoping someone might reply with what they did to fix it or since Konakart also helps out people within this forum, one of you might respond with some useful information.  I found a partial answer in another thread that helped me to find a work around. I will post that work-around now for anyone else who might need it. 
Since this appears to be a major bug I thought you might like to know.

In the CheckoutServerPaymentSubmitAction

for (OrderProductIf op : orderProducts) {
                int scale = new Integer(order.getCurrency().getDecimalPlaces()).intValue();
                op.setFinalPriceExTax(op.getPrice().multiply(new BigDecimal(op.getQuantity())).setScale(scale,BigDecimal.ROUND_HALF_UP));
             }


Do this before trying to save the order.

I believe the error is caused by rounding issues as the order is calculated.  Then when the order is saved, the line price is divided by the quantity throwing the exception.  Perhaps it is my issue alone due to the way I wrote my discount module, but if not, perhaps I can save someone else some time.

I have found this forum to be very helpful in the past and hopefully it will continue to be.

P.S.  Ver 3.2 will most likely do the same thing.


Ted

I have the same problem!

This happens when we loaded prices into the system from externally with a lot of precision e.g. we have prices like 4.3538

I tried the code from sashwill to set the total ex price myself with correct scale etc. but still got the dreaded java.lang.ArithmeticException.

In KonkartAdmin on the product details tab the price is shown as 4.35 (but internally in the db its 4.3538). When just saving that product, the price looses precision and is saved as a new value 4.3500 in the database!

We're using this precision for rounding purposes (from exc. to inc. tax and adding etc.) but looks like we have to import products with a price with less precision in order to get it working.

trevor

Have you tried setting the number of decimal places to 4 on the currency object?