Bukimedia / PrestaSharp

CSharp .Net client library for the PrestaShop API via web service
GNU General Public License v3.0
155 stars 153 forks source link

GetByFilter with pagination always return same entity list #414

Closed enesbehlul closed 3 years ago

enesbehlul commented 3 years ago

Library Version:

1.2.9

NuGet Package Url:

https://www.nuget.org/packages/PrestaSharp/1.2.9

Prestashop version:

1.7.7.0

Describe the Bug:

Since ProductFactory's GetByFilter method returns null if there are more than 5000 products that match the filter. I decide to get them by pagination like this

_productFactory.GetIdsByFilter(filter, null, "[" + startingIndex.ToString() + "," + (count).ToString() + "]");

but even if startingIndex changes the result is the same

Full code:

`

filter.Add("date_upd", "[" + dFrom + "," + dTo + "]");

int i = 0;

List<long> AllProducts = new List<long>();
List<long> products;
while (true) // this loop never breaks
{ 
    int startingIndex = i  * count;
    products = _productFactory.GetIdsByFilter(filter, null, "[" + startingIndex.ToString() + "," + (count).ToString() + "]");
    if (products?.Any() == true) // to check the list is not empty
    {
        AllProducts.AddRange(products);
        if (products.Count < count)
        {
            break;
        }
    }
    else
        break;
}

`

thank you.

CristiaanRojas commented 3 years ago

You just have to remove the brackets from the 'limit' parameter. It is an error in the Github documentation when they give the example with brackets.