KonaKart Community Forum

General Category => Feature Requests => Topic started by: ssharma on February 15, 2008, 11:57:49 am

Title: Search product_options from product through API
Post by: ssharma on February 15, 2008, 11:57:49 am
hi ,
     I want to fetch product_attributes through konakart API bt i found null pointer exception. Can anybody help me to found products_attributes. i am posting the code also.
import java.util.*;
import java.io.*;
import com.konakart.app.KKException;
import com.konakart.app.DataDescriptor;
import com.konakartadmin.app.*;
import com.konakart.appif.ProductsIf;
import com.konakart.appif.ProductIf;
import com.konakart.appif.OptionIf;
public class FetchProductPrice4 extends BaseApiExample
{
   
    public static void main(String[] args)
    {
        try
        {
      init(); 
      int i;
      ProductsIf output;
      ProductIf data[];
      OptionIf option_data[];
      DataDescriptor dataDesc = new DataDescriptor();
      //DataDescriptorIf dataDesc = new DataDescriptorIf();
      dataDesc.setOffset(0);
      dataDesc.setLimit(50);
      output=eng.getAllProducts(sessionId,dataDesc,-1);
      data=output.getProductArray();
      System.out.println("\n\n\n\n\n\n\n\n\n");
      for(i=0;i<output.getTotalNumProducts();i++)
      {
            
            option_data = data.getOpts();
            System.out.println("\nAfter the getopts method");
            System.out.println("The value of i is :: " +option_data);
            System.out.println("The price is  ::: " +option_data.getValueId());
         
      }
   
      
      
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
}
Title: Re: Search product_options from product through API
Post by: heidi on February 15, 2008, 12:16:25 pm
Hi ssharma,

I believe the problem is that you do not get a full product object returned from the getAllProducts calls (this is for performance reasons).

From the javadoc:
"Only Products with a non zero status and non zero invisible are returned. The description (which can be very long) and the array of options are not set. "

To get a fully-populated product you need to call getProduct for each product as you go through your loop.

Heidi
Title: Re: Search product_options from product through API
Post by: ssharma on February 18, 2008, 08:43:18 am
hi heidi
    thank you very much for answering my question.
Title: Re: Search product_options from product through API
Post by: heidi on February 18, 2008, 08:53:45 am
You're welcome  :)

Good luck with your KonaKart project,

Heidi