3

I am developing an e-commerce application in android using Ksaop2 library. I want to sort products, is there any magento Ksoap API to sort products according to price, name etc.

4
  • Did you ever figure this out? Jun 25 '15 at 16:53
  • No I still dint find any solution.I may try with "collection.sort" method of java class. I am also searching for filter of products.
    – user26406
    Jun 26 '15 at 5:03
  • I tried filters with "catalogProductList" to filter the products its working for whole product list, I need this one for particular category and with some arrays.
    – user26406
    Jun 26 '15 at 5:11
  • okay cool - I had to sort by newest so I ended up just sorting the response by ID (not ideal), but I couldn't seem to find a solution after playing around with this most of the afternoon. Jun 26 '15 at 14:38
1

I am using the class which implements Comparable interface. Below is my pojo class where I am using setters and getters to get product's information like, Price, Name, etc.

package com.outthinking.totaltoys;

import java.util.ArrayList;
import java.util.Comparator;

import org.ksoap2.serialization.SoapObject;

    public class ProductInfo implements Comparable {

        String productName;
        String productImgURL;
        Double productPrice;
        int productPosition;
        String productShortDescription;
        String productCompleteDescription;
        String productURLPath;
        String prodID;
        String productSKUID;
        SoapObject productURLSoap;

        public ProductInfo() {
        }

        public ProductInfo(String productName, String productImgURL,
                Double productPrice, int productPosition,
                String productShortDescription, String productCompleteDescription,
                String productURLPath, String prodID, String productSKUID,
                SoapObject productURLSoap) {
            super();
            this.productName = productName;
            this.productImgURL = productImgURL;
            this.productPrice = productPrice;
            this.productPosition = productPosition;
            this.productShortDescription = productShortDescription;
            this.productCompleteDescription = productCompleteDescription;
            this.productURLPath = productURLPath;
            this.prodID = prodID;
            this.productSKUID = productSKUID;
            this.productURLSoap = productURLSoap;
        }

        public String getProductName() {
            return productName;
        }

        public void setProductName(String productName) {
            this.productName = productName;
        }

        public String getProductImgURL() {
            return productImgURL;
        }

        public void setProductImgURL(String productImgURL) {
            this.productImgURL = productImgURL;
        }

        public Double getProductPrice() {
            return productPrice;
        }

        public void setProductPrice(Double productPrice) {
            this.productPrice = productPrice;
        }

        public int getProductPosition() {
            return productPosition;
        }

        public void setProductPosition(int productPosition) {
            this.productPosition = productPosition;
        }

        public String getProductShortDescription() {
            return productShortDescription;
        }

        public void setProductShortDescription(String productShortDescription) {
            this.productShortDescription = productShortDescription;
        }

        public String getProductCompleteDescription() {
            return productCompleteDescription;
        }

        public void setProductCompleteDescription(String productCompleteDescription) {
            this.productCompleteDescription = productCompleteDescription;
        }

        public String getProductURLPath() {
            return productURLPath;
        }

        public void setProductURLPath(String productURLPath) {
            this.productURLPath = productURLPath;
        }

        public String getProdID() {
            return prodID;
        }

        public void setProdID(String prodID) {
            this.prodID = prodID;
        }

        public String getProductSKUID() {
            return productSKUID;
        }

        public void setProductSKUID(String productSKUID) {
            this.productSKUID = productSKUID;
        }

        public SoapObject getProductURLSoap() {
            return productURLSoap;
        }

        public void setProductURLSoap(SoapObject productURLSoap) {
            this.productURLSoap = productURLSoap;
        }

        @Override
        public int compareTo(Object another) {
            ProductInfo info = (ProductInfo) another;
            return productName.compareTo(info.productName);
        }

        public static class PriceSort implements Comparator {
            public int compare(Object o1, Object o2) {
                if (!(o1 instanceof ProductInfo) || !(o2 instanceof ProductInfo))
                    throw new ClassCastException();

                ProductInfo e1 = (ProductInfo) o1;
                ProductInfo e2 = (ProductInfo) o2;

                return (int) (e1.getProductPrice() - e2.getProductPrice());
            }
        }

}

then call the methods in your class

Collections.sort(productInfos,new ProductInfo.PriceSort());

in which "PriceSort()" will return the array, by comparing price from low to high.

or to get list in alphabetical order then call

`Collections.sort(productInfos,new ProductInfo.compareTo());` 

which returns list in alphabetical order.

6
  • Hi Gururaj... May I know how did you get the product list and the product details? Dec 17 '15 at 7:06
  • Hi Rishad Appat, I was using "catalogCategoryAssignedProducts" magento api to get list of array of id's of products of particular category with CAATEGORY_ID as argument. From those id's, we can get product details by calling "catalogProductInfo" api of magento "PRODUCT_ID" or "SKU as argument".
    – user26406
    Dec 17 '15 at 9:51
  • Yahh... I have followed the same procedure... but it takes too much time to get the list of all product details of a specific category... Mine I have limited like 20 request per time, it takes around 30 seconds to retrieve and display the data.. is that normal? Dec 17 '15 at 10:23
  • Rishad u need to write magento custom api.
    – user26406
    Dec 22 '15 at 9:43
  • Omg... I am not familiar with web development and php... is it too hard? Dec 22 '15 at 10:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy