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

how to fetch totalnumber of products for particular manufacturer.

Started by ssharma, February 20, 2008, 12:05:44 pm

Previous topic - Next topic

ssharma

hi,
   i want to search product details according to manufacturer . i got all the manufacturer -name bt i didnt get product details.And there is no method available in konakart API to get total number of products so please help me .
package org.argus.konakart;

import com.konakart.app.DataDescriptor;
import com.konakart.app.Manufacturer;
import com.konakart.app.ProductSearch;
import com.konakart.appif.ManufacturerIf;
import com.konakart.appif.ProductIf;
import com.konakart.appif.ProductsIf;

public class price extends BaseApiExample
{

   public static void main(String[] args)
   {
      try
      {
         Search_Criteria();
      }
      catch(Exception e)
      {
         e.printStackTrace();
      }
   }
   public static void Search_Criteria()
   {
      init();
      try
         {   
            ManufacturerIf manufacturer[];
            DataDescriptor datadesc = new DataDescriptor();
            datadesc.setOffset(0);
            datadesc.setLimit(0);
            ProductSearch prodsearch = new ProductSearch();
            eng.searchForProducts(null, datadesc, prodsearch, -1);
            manufacturer = eng.getAllManufacturers();
            ProductIf product_list[];
            System.out.println("The total number of manufacturer are ::" +manufacturer.length);
            
                     for(int i=0;i<manufacturer.length;i++)
                     {
                           ProductsIf products;
                           System.out.println("The name of manufacturer is :::: " +manufacturer.getName());
                           prodsearch.setManufacturerId(manufacturer.getId());
                           products = eng.getAllProducts(sessionId,datadesc, -1);
                           product_list = products.getProductArray();
                           //System.out.println("The name eof product is ::: "  +product_list.getManufacturerName());
                           //prodsearch.setSearchInSubCats(true);
                           products = eng.searchForProducts(null, datadesc, prodsearch, -1);
                           //product_list = products.getProductArray();
                                 for(int j=0;j<5;j++ )
                                    {
                                       System.out.println("The name of product is :::" +product_list.getName());
                                    }   
                     }
         }
      catch(Exception e)
      {
         e.printStackTrace();
      }
      
   }
}




heidi

Hi,

You had setLimit(0) - this would limit the number of products returned to 0.

This version gets the products for each manufacturer in turn:

            // First get all the Manufacturers...
            ManufacturerIf manufacturer[] = eng.getAllManufacturers();

            System.out.println("Total number of Manufacturers: " + manufacturer.length);

            DataDescriptor datadesc = new DataDescriptor();
            datadesc.setOffset(0);
            datadesc.setLimit(-1);

            for (int man = 0; man < manufacturer.length; man++)
            {
                System.out.println("Manufacturer Name: " + manufacturer[man].getName());

                // Now for each manufacturer, we'll get all their products...
               
                ProductSearch prodSearch = new ProductSearch();
                prodSearch.setManufacturerId(manufacturer[man].getId());

                ProductsIf products = eng.searchForProducts(sessionId, datadesc, prodSearch, -1);
                ProductIf[] product_list = products.getProductArray();
               
                for (int j = 0; j < product_list.length; j++)
                {
                    System.out.println("The name of product is " + product_list[j].getName());
                }
            }

Heidi