KonaKart Community Forum

Installation / Configuration => Programming of KonaKart => Topic started by: ssharma on March 17, 2008, 05:25:37 am

Title: how to less database call
Post by: ssharma on March 17, 2008, 05:25:37 am
hi
    i want to search product's detaills according to category wise but for gettng product description i have to include this line          

      forDesc=eng.getProduct(sessionId,relProduct.getId(),-1);


because by using this code i am not able to get products description

                                products=eng.searchForProducts(null, dataDesc, prodSearch, -1);
            relProduct=products.getProductArray();

and for this databsse call inincreased  and it is not sufficient so please help me for solving that problem

package org.argus.konakart;
import java.math.BigDecimal;
import java.util.*;

import org.medicalert.website.idm.entities.Product;
import org.medicalert.website.idm.entities.impl.ProductImpl;

import com.konakart.app.DataDescriptor;
import com.konakart.app.Products;
import com.konakart.appif.ProductIf;
import com.konakart.appif.ProductsIf;
import com.konakart.app.ProductSearch;
import com.konakart.appif.CategoryIf;


public class GetCategory_Detaila extends BaseApiExample
{   
    public static void main(String[] args)
    {
        try
        {
           // Initialize the connection with konakart and acquire session Id
      
      GetCategoryInfo();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
    public static void GetCategoryInfo()
    {
       Date senddt = new Date();
      long d1 = senddt.getTime();
       init();
       if(sessionId == null)
       {
          System.out.println("not exist");
       }
       try
       {
      int i;
      CategoryIf category[]=eng.getCategoryTree(-1,true);
      CategoryIf subcategory[];
      
      int no_sub,j,l;

      // Create Data Desc object
      DataDescriptor dataDesc = new DataDescriptor();
      dataDesc.setOffset(0);
      // Set maximum no of row fetched from database at a time.
      dataDesc.setLimit(50);
      
      ProductSearch prodSearch = new ProductSearch();
      
        ProductsIf products =null;
       // eng.getProduct(sessionId,product_id,-1);
      //eng.searchForProducts(null, dataDesc, prodSearch, -1);
      
      
      ProductIf relProduct[];
      ProductIf output;
      
      int total_category;
      total_category = category.length;
      System.out.println("The total categoies are :::" +total_category);
      System.out.println("\n =================================================== \n");   
      
      HashMap<String,List> temp = new HashMap<String,List>();
      
      for(j=0;j<total_category;j++)
      {
         subcategory=category[j].getChildren();      
         no_sub=category[j].getNumberOfProducts();
         System.out.println("\n\nCategory :"+category[j].getName()+ "("+no_sub +")");
         List productList = new ArrayList();
         ProductIf forDesc;
         for(l=0;l<subcategory.length;l++){
            prodSearch.setCategoryId(subcategory[l].getId());               
            prodSearch.setSearchInSubCats(true);
            products=eng.searchForProducts(null, dataDesc, prodSearch, -1);
            relProduct=products.getProductArray();
            //output=eng.getProduct(sessionId,relProduct[l].getId(),-1);
            
            Product product = null;
            
            
            for(i=0;i<relProduct.length;i++){
               
               //System.out.println("Products name is :;" +relProduct);
               product = new ProductImpl();
               product.setProductId(String.valueOf(relProduct.getId()));
               product.setProductName(relProduct.getName());
               product.setPrice(relProduct.getPriceExTax().doubleValue());
               product.setDiscountedPrice(0.0);
      
               //product.setProductDescription(relProduct.getDescription());
               product.setProductImage(relProduct.getImage());
               forDesc=eng.getProduct(sessionId,relProduct.getId(),-1);
               product.setProductDescription(forDesc.getDescription());
               System.out.println("Desc is "+product.getProductDescription());
               productList.add(product);
         
               
            }
            
         }
         System.out.println("Size of List :: "+productList.size());
         temp.put(category[j].getName(), productList);
      }
      
      /*
      System.out.println("----------------------------------");
      List<Product> l1 = null;
      for(String keyStr : temp.keySet()){
         System.out.println(keyStr);
         l1 = temp.get(keyStr);
         for(Product p : l1){
            System.out.println(p.getProductId());
         }
      }
      System.out.println("----------------------------------");
      List tempList = temp.get("Software");
      
      System.out.println(tempList.size());
      */
      /*for(int t=0;t<temp.size();t++)
      {
         temp.get(key)
      }*/
      Date recdt = new Date();
      long d2 = recdt.getTime();
      long diff=d2-d1;
      System.out.println("Time to execute progrma in miliseconds :  "+ diff);
   }
       catch(Exception e)
       {
             System.out.println("Error is"+e);
       }
     }
}
Title: Re: how to less database call
Post by: kate on March 17, 2008, 06:03:00 am
Hi,

I don't understand what your problem is here.

Please explain why in your case  using searchForProducts() then getProduct() for each description is no good for you?

What are you trying to achieve?

Kate
Title: Re: how to less database call
Post by: ssharma on March 17, 2008, 07:07:19 am
hi
I am using konakart API as am ecommerce application and there is need to access product by certain criteri and i am using
                                prodSearch.setCategoryId(subcategory[l].getId());               
            prodSearch.setSearchInSubCats(true);
            products=eng.searchForProducts(null, dataDesc, prodSearch, -1);
but i am not getting product description so again i am using
forDesc=eng.getProduct(sessionId,relProduct.getId(),-1);
so plese help me how i will get all product detail including description with a single database call
Title: Re: how to less database call
Post by: julie on March 17, 2008, 08:41:24 am
Hi,

As explained by Kate, you need to use two calls to the KonaKart API.