• Welcome to KonaKart Community Forum. Please login or sign up.
 
April 28, 2024, 10:04:22 pm

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Messages - jeffzzang

1
I am using the KKEngIf to integrate KonaKart into my existing JSP application. It looks like KKEngIf has a way to update the shipping address  for an order (before it has been saved to the database) by using KKEngIf.changeDeliveryAddress(). When I call this and save the order, the database shows the correct shipping address. However, I can't find a similar method for changing the billing address from the default customer address. Do I have to manually copy all the billing address fields using the Order.setBillingXXX() functions? Thanks!

A small code snippet:

Note: At the time this code is executed, the shipping and billing information has already been collected from the user.


/** Defined at top of the class, included for reference **/
AddressIf selectedBillingAddress;
AddressIf selectedShippingAddress;
CreditCardIf curCreditCardInfo;
String sessionId;
KKEngIf eng;


...class body omitted...

OrderIf curOrder = eng.createOrderWithOptions(this.sessionId, eng.getBasketItemsPerCustomer(this.sessionId, this.customerId, KonaKartConstants.DEFAULT_KK_LANGUAGE_ID),null,KonaKartConstants.DEFAULT_KK_LANGUAGE_ID);

/** Thought this would work **/
curOrder.setBillingAddrId(this.selectedBillingAddress.getId());

curOrder = eng.changeDeliveryAddress(this.sessionId, curOrder, this.selectedShippingAddress);

eng.getOrderTotals(curOrder,KonaKartConstants.DEFAULT_KK_LANGUAGE_ID);

PaymentDetailsIf curPaymentDetails = eng.getPaymentGateway(curOrder, "authorizenet", KonaKartConstants.DEFAULT_KK_LANGUAGE_ID);

curPaymentDetails.setCcExpiryMonth(this.ccExpiryMonth);
curPaymentDetails.setCcExpiryYear(this.ccExpiryYear);
curPaymentDetails.setCcOwner(this.curCreditCardInfo.getCcOwner());
curPaymentDetails.setCcNumber(this.curCreditCardInfo.getCcNumber());

curOrder.setPaymentDetails(curPaymentDetails);

curOrder.setStatus(1);
OrderStatusHistoryIf osHistory = new OrderStatusHistory();
osHistory.setOrderStatusId(1);

OrderStatusHistoryIf[] statusArray = new OrderStatusHistoryIf[] { osHistory};
curOrder.setStatusTrail(statusArray);

eng.saveOrder(this.sessionId,curOrder,KonaKartConstants.DEFAULT_KK_LANGUAGE_ID);
2
This may be a shot in the dark, but would you mind posting your CyberSource payment module?
3
I want to extend the functionality of the com.konakart.app.Product bean so that it contains an additional method called getBriefDescription() which basically returns the description of the product, truncated to 20 characters. My first idea was to extend the Product bean as follows:


public class MyProduct extends Product {

  public String getBriefDescription(){

if (this.getDescription().length() > 20){
return this.getDescription().substring(0,20) + "...";
}
                else{
       return this.getDescription();
               }

}
}


Using this technique, MyProduct contains all the same methods as Product and adds one additional method (getBriefDescription()). However, when I try to use this bean in the following code:


//get all the products from the db - the products will NOT be populated
ProductIf[] prodArray = kkEng.searchForProducts(null, null, productSearch, -1).getProductArray();

//populate each product
for (int x = 0; x < prodArray.length; x++){
  MyProduct myP = (MyProduct)kkEng.getProduct(null,prodArray[x].getId(),-1));
}


This throws a run-time ClassCastException because I am downcasting from Product to MyProduct.

My second thought is to use the Decorator pattern which essentially wraps the Product bean and adds the getBriefDescription() method:


public class ProductDecorator extends Product {

protected Product p;

public ProductDecorator(Product p){
this.p = p;
}

public String getBriefDescription(){

if (this.p.getDescription().length() > 20){
return this.p.getDescription().substring(0,20)+"...";
}
return this.p.getDescription();

}
}


Then in the code that gets the products from the db:


//get all the products from the db - the products will NOT be populated
ProductIf[] prodArray = kkEng.searchForProducts(null, null, productSearch, -1).getProductArray();

//populate each product
for (int x = 0; x < prodArray.length; x++){
  ProductDecorator myP = new ProductDecorator((Product)kkEng.getProduct(null,prodArray[x].getId(),-1)));
  ...add it to the collection that will be returned...
}



The only issue I have with this technique is that I can't use ProductDecorator exactly like a Product without having to implement ALL the methods of Product like so:


public String getName(){
return this.p.getName();
}
public BigDecimal getPriceExTax(){
return this.p.getPriceExTax();
}
public BigDecimal getPriceIncTax(){
return this.p.getPriceIncTax();
}

        ..etc..


Does anyone know any good techniques to try to do what I'm doing?
4
I have a database of existing customers and I am storing the ID of the existing customer in the custom1 field in KonaKart's Customers table. Is there any way to query on this field using only the Server API - in other words I want to check to see if a Customer exists with Custom1 = <some id value> to determine if this customer has already been inserted into the KK database. I'd prefer not to use the Admin API unless I absolutely have to.
5
Thanks. It didn't know you can pass in NULL for the session Id.

I also figured out why the .getCustomer() method wasn't throwing an exception. I was passing it session IDs from previous sessions that I thought would have been invalidated when I restarted Tomcat. It looks like session IDs are stored in the SESSIONS table which I'm assuming is where the .getCustomer() method queries.

Thanks for your help!
6
Question about how to use the KonaKart java API:

From reading other forum postings, I've gathered that if we're including the KK jar files in our own web app and using the java api, we should only concern ourselves with calling methods in KKEngIf. However,  many of the methods in KKEngIf requires a session ID to be passed into it.

The Java API examples included in the download package use the credentials root@locahost.com // password when initializing the engine. Is this the username and password that should be used when a user is browsing products and has not yet logged in?

Also, when the user DOES log in, should I be passing the new session ID that is returned by KKEngIf.login() to the KKEngIf methods that require session IDs?

Last, I noticed that passing a random string to KKEngIf.getCustomer(String sessionId) returns a customer with user ID equal to 1 (which is root@localhost.com in the DB) - why does the implementation behavior deviate from what's written in the API documentation? I thought it was supposed Null.
7
Thanks for your response. One other question about integrating KonaKart with an existing database of customers. My existing database has a table of website accounts which contains the normal customer information (name, address, etc.). If I want to integrate KonaKart with this existing table of accounts, do I have to import all the data from the existing database into the KonaKart CUSTOMERS table? If not, then when a customer places an order, what should I put in the ORDERS.CUSTOMERS_ID field? Any guidance would be greatly appreciated.
8
Thanks for your response. If I use the java APIs, will I have to merge any configuration files such as web.xml? Also, can I leave struts-related files such as strut-config.xml out of the merged webapp?
9
We are trying to integrate KonaKart with an existing web app written in JSF. I was successfully able to deploy KonaKart as a war, and dropped it into my Tomcat webapps directory. Both client and admin versions run properly.

I want to use the Java API to make calls to the KKEng object so users on our existing website can use the functionality in KonaKart. My first attempt at this included the following:

In one of my JSF actions, I call:


Class engineClass = Class.forName("com.konakart.app.KKEng");
       
KKEngIf eng = (KKEngIf) engineClass.newInstance();
String sessID = eng.login("someemail@email.com","passpass");

ProductSearchIf pSearch = new ProductSearch();
pSearch.setSearchText("Cisco");
ProductsIf prods = eng.searchForProducts(sessionId,null,pSearch,-1);
ProductIf[] prod = prods.getProductArray();
for (int p = 0; p < prod.length; p++){
    System.out.println("Product: " + prod[p].getName());
}


However when I run this, I get the following error:


PropertyFileFinder.findProperties() Could not find konakart.properties on the classpath
com.konakart.app.KKException: Could not find konakart.properties on the classpath


I also noticed that when the above code is executed, it looks like it loads a new instance of KKEng into memory. The reason I know this is because the KonaKart intro text (license information, default variable values, etc.) gets printed to the logs twice - once at Tomcat startup and a second time when the above code is executed.

I'm assuming one way around this is to load the static instance of the KKEng class from the instance of KonaKart that is already running. How do I get the static instance? I've looked into classloaders in Tomcat, but couldn't really find anything useful.

Another route I've tried is to set crossContext="true" in both webapps. I was able to access KonaKart's ServletContext, but I don't know where to go from there.

Does anyone else have experience integrating an existing site with KonaKart? Any help would be greatly appreciated.