Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
536 views
in Technique[技术] by (71.8m points)

c# - how to get more than 5000 entities by using Factories GetByFilter method with prestasharp

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:

PrestaSharp GetByFilter with pagination always return same entity list

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(because of a loop) 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() + "]"); // returns same products in every iteration
    if (products?.Any() == true) // to check the list is not empty
    {
        AllProducts.AddRange(products);
        if (products.Count < count)
        {
            break;
        }
    }
    else
        break;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...