I'm trying to get bestsellers collection, and set a period. I want to load diffrent period collection if chosen one is empty, but I get old collection instead. I tried to use clear/reset/load but it doesnt work.

$bestsellers = $this->bestsellersCollection->setPeriod($period);

    foreach ($bestsellers as $product) {
        $productIds[] = $product->getProductId();

    if (empty($productIds) && ($period != 'year')){

1 Answer 1


Check this answer https://magento.stackexchange.com/a/213009/108929

Try resetting the where condition, And then add the conditions back

  • Thanks, that also works. As a workaround I used Bestsellers\CollectionFactory instead of Collection and create new collection in "if" statement.
    – Konrad
    Commented Oct 19, 2022 at 9:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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