isotope/core

Array sizes are inconsistent

Opened this issue · 9 comments

I have a multilingual shop where all 3 languages are using exactly the same modules and even the products published in these languages are the same. It works for two languages withouth any problem but on the third language I receive the following error in the product list:

ValueError:
Array sizes are inconsistent

  at vendor/isotope/isotope-core/system/modules/isotope/library/Isotope/Model/Product.php:578
  at array_multisort(array('1000', '800', '30', '29', '28', '27', '26', '25', '24', '24', '23', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', ''), 3, 0, array())
     (vendor/isotope/isotope-core/system/modules/isotope/library/Isotope/Model/Product.php:578)
  at Isotope\Model\Product::find(array('column' => array('tl_iso_product.published=\'1\' AND (tl_iso_product.start=\'\' OR tl_iso_product.start<\'1724240580\') AND (tl_iso_product.stop=\'\' OR tl_iso_product.stop>\'1724240640\')', 'tl_iso_product.pid=0', 'c.page_id=625', 'tl_iso_product.is_accessory=0'), 'value' => array(), 'return' => 'Collection', 'order' => 'c.sorting', 'filters' => array(), 'sorting' => array('sortingnr' => object(Sort)), 'group' => 'tl_iso_product.id'))
     (vendor/contao/core-bundle/src/Resources/contao/library/Contao/Model.php:962)
  at Contao\Model::findBy(array('tl_iso_product.published=\'1\' AND (tl_iso_product.start=\'\' OR tl_iso_product.start<\'1724240580\') AND (tl_iso_product.stop=\'\' OR tl_iso_product.stop>\'1724240640\')', 'tl_iso_product.pid=0', 'c.page_id=625', 'tl_iso_product.is_accessory=0'), array(), array('column' => array('tl_iso_product.published=\'1\' AND (tl_iso_product.start=\'\' OR tl_iso_product.start<\'1724240580\') AND (tl_iso_product.stop=\'\' OR tl_iso_product.stop>\'1724240640\')', 'tl_iso_product.pid=0', 'c.page_id=625', 'tl_iso_product.is_accessory=0'), 'value' => array(), 'return' => 'Collection', 'order' => 'c.sorting', 'filters' => array(), 'sorting' => array('sortingnr' => object(Sort))))
     (vendor/isotope/isotope-core/system/modules/isotope/library/Isotope/Model/Product.php:154)
  at Isotope\Model\Product::findPublishedBy(array('tl_iso_product.published=\'1\' AND (tl_iso_product.start=\'\' OR tl_iso_product.start<\'1724240580\') AND (tl_iso_product.stop=\'\' OR tl_iso_product.stop>\'1724240640\')', 'tl_iso_product.pid=0', 'c.page_id=625', 'tl_iso_product.is_accessory=0'), array(), array('order' => 'c.sorting', 'filters' => array(), 'sorting' => array('sortingnr' => object(Sort))))
     (vendor/isotope/isotope-core/system/modules/isotope/library/Isotope/Model/Product.php:323)
  at Isotope\Model\Product::findAvailableBy(array('tl_iso_product.pid=0', 'c.page_id=625', 'tl_iso_product.is_accessory=0'), array(), array('order' => 'c.sorting', 'filters' => array(), 'sorting' => array('sortingnr' => object(Sort))))
     (vendor/isotope/isotope-core/system/modules/isotope/library/Isotope/Module/ProductList.php:356)
  at Isotope\Module\ProductList->findProducts()
     (vendor/isotope/isotope-core/system/modules/isotope/library/Isotope/Module/ProductList.php:217)
  at Isotope\Module\ProductList->compile()
     (vendor/contao/core-bundle/src/Resources/contao/modules/Module.php:214)
  at Contao\Module->generate()
     (vendor/codefog/contao-haste/library/Haste/Frontend/AbstractFrontendModule.php:52)
  at Haste\Frontend\AbstractFrontendModule->generate()
     (vendor/isotope/isotope-core/system/modules/isotope/library/Isotope/Module/Module.php:116)
  at Isotope\Module\Module->generate()
     (vendor/isotope/isotope-core/system/modules/isotope/library/Isotope/Module/ProductList.php:105)
  at Isotope\Module\ProductList->generate()
     (vendor/contao/core-bundle/src/Resources/contao/elements/ContentModule.php:98)
  at Contao\ContentModule->generate()
     (vendor/contao/core-bundle/src/Resources/contao/library/Contao/Controller.php:623)
  at Contao\Controller::getContentElement(object(ContentModel), 'main')
     (vendor/contao/core-bundle/src/Resources/contao/modules/ModuleArticle.php:197)
  at Contao\ModuleArticle->compile()
     (vendor/contao/core-bundle/src/Resources/contao/modules/Module.php:214)
  at Contao\Module->generate()
     (vendor/contao/core-bundle/src/Resources/contao/modules/ModuleArticle.php:70)
  at Contao\ModuleArticle->generate(true)
     (vendor/contao/core-bundle/src/Resources/contao/library/Contao/Controller.php:551)
  at Contao\Controller::getArticle(2, false, true, 'main')
     (vendor/contao/core-bundle/src/Resources/contao/elements/ContentArticle.php:30)
  at Contao\ContentArticle->generate()
     (vendor/contao/core-bundle/src/Resources/contao/library/Contao/Controller.php:623)
  at Contao\Controller::getContentElement(object(ContentModel), 'main')
     (vendor/contao/core-bundle/src/Resources/contao/modules/ModuleArticle.php:197)
  at Contao\ModuleArticle->compile()
     (vendor/contao/core-bundle/src/Resources/contao/modules/Module.php:214)
  at Contao\Module->generate()
     (vendor/contao/core-bundle/src/Resources/contao/modules/ModuleArticle.php:70)
  at Contao\ModuleArticle->generate(false)
     (vendor/contao/core-bundle/src/Resources/contao/library/Contao/Controller.php:551)
  at Contao\Controller::getArticle(object(ArticleModel), true, false, 'main')
     (vendor/contao/core-bundle/src/Resources/contao/library/Contao/Controller.php:393)
  at Contao\Controller::getFrontendModule('0', 'main')
     (vendor/contao/core-bundle/src/Resources/contao/pages/PageRegular.php:194)
  at Contao\PageRegular->prepare(object(PageModel))
     (vendor/contao/core-bundle/src/Resources/contao/pages/PageRegular.php:61)
  at Contao\PageRegular->getResponse(object(PageModel), true)
     (vendor/contao/core-bundle/src/Resources/contao/controllers/FrontendIndex.php:320)
  at Contao\FrontendIndex->renderPage(object(PageModel))
     (vendor/symfony/http-kernel/HttpKernel.php:163)
  at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1)
     (vendor/symfony/http-kernel/HttpKernel.php:75)
  at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true)
     (vendor/symfony/http-kernel/Kernel.php:202)
  at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
     (public/index.php:44)           

I could not figure out why it happens in the first place but $arrProducts contains way more entries than $arrParam[0]

https://github.com/isotope/core/blob/2.9/system/modules/isotope/library/Isotope/Model/Product.php#L562-L563

To fix the problem momentarily I've added a quick hotfix which makes sure that $arrProducts only contains the products listed in $arrParam[0]

// [...]
// -- HOTFIX: Make sure products matches the params
$arrProductsUnique = [];
foreach( $arrProducts as $i => $p ) {

    if( !array_key_exists($p->id, $arrParam[0]) ) {
        continue;
    }

    $arrProductsUnique[$p->id] = $p;
}
$arrProducts = $arrProductsUnique;
// -- HOTFIX

// Add product array as the last item.
// This will sort the products array based on the sorting of the passed in arguments.
$arrParam[] = &$arrProducts;
array_multisort(...$arrParam);

Judging from your stack trace you are still on Isotope 2.8.x. Does the issue occur in Isotope 2.9.0 as well?

I'm actually on 2.9.x-dev 6aff607

Your error message says

at vendor/isotope/isotope-core/system/modules/isotope/library/Isotope/Model/Product.php:578

The error message cannot originate from 2.9.x-dev 6aff607 as there is nothing in that line:

The error message likely originates from Isotope 2.8.17:

$arrParam[] = &$arrData[$strField];

Sorry for the confusion. I am on 2.9.x-dev 6aff607 but the stack trace was shifted due to some debugging lines 😁
So it is really about array_multisort(...$arrParam);

What do the translations look like? I could imagine that products are translated two two languages but not to all of them? Or one is the fallback?

What do the translations look like?

I'm not quite sure what you mean. Some of the product data is translated in all 3 languages, some are not and using the fallback translation.

Can you maybe screenshot the backend product configuration for all three languages?

What configuration do you mean? There are only some core fields that are enabled for translation (name, teaser, description).

or maybe provide a dump of these products so I can reproduce this locally?