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

how to edit products attributes

Started by ssharma, May 06, 2008, 07:34:41 am

Previous topic - Next topic

ssharma

hi,
    I want to edit and the update products attributes and the values are read from the cvs file .the following is my code for that that is working right for insert bt nt for edit.the new values for option is not edited and price prrfix also not edited.can u please verify mu code and guide me.


package org.argus.konakart;

import java.math.BigDecimal;
import java.util.*;
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;
import com.konakart.appif.DataDescriptorIf;
import com.konakart.al.ProdOption;
import java.io.FileReader;
import au.com.bytecode.opencsv.CSVReader;

public class importProductAttribute extends BaseApiExample
{
   private static final String ATTRIBUTE_FILE="example/attributes.csv";
   static int flag;
   
   public static void main(String[] args)
   {
      try
      {
         init();
         ProductsIf output;
         ProductIf data;
         
         
         OptionIf options[];
         
         DataDescriptor dataDesc = new DataDescriptor();
         dataDesc.setOffset(0);
         dataDesc.setLimit(1);
         
         output=eng.getAllProducts(sessionId,dataDesc,-1);
         
         CSVReader csvreader = new CSVReader(new FileReader(ATTRIBUTE_FILE));
         String[] nextLine;
         
            while ((nextLine = csvreader.readNext()) != null)
               {
                  int pid = Integer.parseInt(nextLine[1]);
                  data=eng.getProduct(sessionId,pid ,-1);
                  options=data.getOpts();
                  int flag = 0;
                  for(int i=0;i<options.length;i++)
                  {
                     System.out.println("\n\n\n\n");
                     System.out.println("the option id ::" +options.getId());
                     System.out.println("The option value id is :::" +options.getValueId());
                     System.out.println("The option value id is :::" +options.getValue());
                     int opt_id = options.getId();
                     int opt_valid = options.getValueId();
                     if(opt_id == (Integer.parseInt(nextLine[2])) && opt_valid == (Integer.parseInt(nextLine[3])))
                     {
                        //System.out.println("the attribute for updation.");
                        flag = 1;
                     }
            
                  }
                  System.out.println("The flag is ::" +flag);
                  if(flag == 1)
                  {
                     System.out.println("for updation");
                     AdminProductAttribute adminproductattribute = new AdminProductAttribute();
                       adminproductattribute.setId(Integer.parseInt(nextLine[0]));
                       //adminproductattribute.setProductId(14);
                       adminproductattribute.setProductId(Integer.parseInt(nextLine[1]));
                       adminproductattribute.setOptionId(Integer.parseInt(nextLine[2]));
                       adminproductattribute.setOptionValueId(Integer.parseInt(nextLine[3]));
                       adminproductattribute.setPricePrefix(nextLine[4]);
                       adminproductattribute.setPrice(new BigDecimal(Integer.parseInt(nextLine[5])));
                       System.out.println("the price is ::" +(Integer.parseInt(nextLine[5])));
                       kkadmin.editProductAttribute(sessionId,adminproductattribute);
                     
                  }
                  else
                  {
                     System.out.println("for insert");
                     AdminProductAttribute adminproductattribute = new AdminProductAttribute();
                     adminproductattribute.setId(Integer.parseInt(nextLine[0]));
                     //adminproductattribute.setProductId(14);
                     adminproductattribute.setProductId(Integer.parseInt(nextLine[1]));
                     adminproductattribute.setOptionId(Integer.parseInt(nextLine[2]));
                     adminproductattribute.setOptionValueId(Integer.parseInt(nextLine[3]));
                     adminproductattribute.setPricePrefix(nextLine[4]);
                     adminproductattribute.setPrice(new BigDecimal(Integer.parseInt(nextLine[5])));
                     int newattributeid = kkadmin.insertProductAttribute(sessionId, adminproductattribute);
                     System.out.println("the data is sucessfullu inserted.");
                     System.out.println("The new attribute id is ::" +newattributeid);
                  }
               }
            
         
      
         
         
            /*for(int i=0;i<options.length;i++)
               {
                  System.out.println("\n\n\n\n");
                  System.out.println("the option id ::" +options.getId());
                  System.out.println("The option value id is :::" +options.getValueId());
                  System.out.println("The option value id is :::" +options.getValue());
            
               }*/
         
       
                          
                          /*{
                             System.out.println("updated.");
                             AdminProductAttribute adminproductattribute = new AdminProductAttribute();
                               adminproductattribute.setId(Integer.parseInt(nextLine[0]));
                               //adminproductattribute.setProductId(14);
                               adminproductattribute.setProductId(Integer.parseInt(nextLine[1]));
                               adminproductattribute.setOptionId(Integer.parseInt(nextLine[2]));
                               adminproductattribute.setOptionValueId(Integer.parseInt(nextLine[3]));
                               adminproductattribute.setPricePrefix(nextLine[4]);
                               adminproductattribute.setPrice(new BigDecimal(Integer.parseInt(nextLine[5])));
                               kkadmin.editProductAttribute(sessionId,adminproductattribute);
                               break;
                               
                          }
                       else
                          {
                             AdminProductAttribute adminproductattribute = new AdminProductAttribute();
                             adminproductattribute.setId(Integer.parseInt(nextLine[0]));
                             //adminproductattribute.setProductId(14);
                             adminproductattribute.setProductId(Integer.parseInt(nextLine[1]));
                             adminproductattribute.setOptionId(Integer.parseInt(nextLine[2]));
                             adminproductattribute.setOptionValueId(Integer.parseInt(nextLine[3]));
                             adminproductattribute.setPricePrefix(nextLine[4]);
                             adminproductattribute.setPrice(new BigDecimal(Integer.parseInt(nextLine[5])));
                             int newattributeid = kkadmin.insertProductAttribute(sessionId, adminproductattribute);
                             System.out.println("the data is sucessfullu inserted.");
                             System.out.println("The new attribute id is ::" +newattributeid);
                             break;
                             
                          }
                       */
                       

                    
                 
              
         
      }
      catch(Exception e)
      {
         System.out.println("The exception is ::" +e);
      }
      
         

   }
   
   
}

pete

Hi,

To help you we would need a sample CVS file. If you require this type of detailed support you should contact support AT konakart dot com in order to purchase a support contract.