8

I am getting products list using catalogProductList, its taking too long time to return the values(see screenshot) actually my products count is 24K, how can i run by using limit 10 and if i click page 2 then only load next 10 (Now load everything then only print the value).

Now my design look like,

enter image description here

Code :

$proxy = new SoapClient('www.abc.com/api/v2_soap/?wsdl=1');
        $sessionId = $proxy->login((object)array('username' => 'abc', 'apiKey' => 'abc123'));
        $result = $proxy->catalogProductList((object)array('sessionId' => $sessionId->result, 'filters' => null));      
        return $result->result();

Note : https://datatables.net/examples/styling/bootstrap4

How to run API soap v2 as limit 10, and should be next 10 load when i click page 2?

6
+25

Unfortunately as far as I know you can't simply pass a limit to the SOAP API.

One approach which would work if you don't need to filter the list by any attributes, want to get all attributes and have no missing entity_ids for products (i.e. you have never deleted a product). This is the approach to get bunches of x products based on the maximum entity_id and a given page.

Anyway if the above assumptions are not acceptable for your requirement, you shouldn't use it :-)

//soap v2
$client = new SoapClient('http://yoursite/api/v2_soap/?wsdl=1');

$session = $client->login('login', 'password');

//get the maximum entity_id from your database
$maxID = 101; 

//get your page parameter beginning with 1 for the first page
$page = 2; 

 //set your pagesize
$pageSize = 20;

//this is thenumber of pages you will get
$pagesInPagination = ceil ($maxID / $pageSize);

$start = $maxID - ($page - 1) * $pageSize;

$end = $start - $pageSize;

$entityIdList = [];
for ($i = $start; $i > $end; $i--){
    $entityIdList[] = $i;
}


$complexFilter = array(
    'complex_filter' => array(
        array(
            'key' => 'entity_id',
            'value' => array('key' => 'in', 'value' => implode (',',$entityIdList))
        ),
    )
);
$result = $client->catalogProductList($session, $complexFilter);

foreach($result as $product) {
    $data = (array) $product;
    echo $data['product_id']. "\n";
}
1
<?php 
defined('BASEPATH') OR exit('No direct script access allowed'); 
error_reporting(-1); 
ini_set('display_errors', 'On'); 
class Live_stock extends CI_Controller { 

public function index() 
{ 


$this->load->view("header_view"); 

$proxy = new SoapClient('abc.com/api/v2_soap/?wsdl=1'); // TODO : change url 
$sessionId = $proxy->login((object)array('username' => 'abc', 'apiKey' => 'abc123')); 
$result["productArray"] = $proxy->catalogProductList((object)array('sessionId' => $sessionId->result, 'filters' => null)); 
$this->load->view("live_stock_view",$result); 

$this->load->view("footer_view"); 



} 
}

here limit code also available

$in = array();
for ($i = ($page * $size) - $size; $i < ($page * $size); $i++) {
    $in[] = $i + 1;
}
$complexFilter = array('complex_filter' => 
    array(
        array(
            'key' => 'product_id',
            'value' => array(
                'key' => 'in', 
                'value' => join(",", $in)
            )
        )
    )
);

useful link

  • @ZUS i have updated my answer – Rakesh Donga Mar 2 at 11:18

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.