Skip to content

Notice: Undefined index: default in vendor/magento/module-catalog/……BatchSizeCalculator.php

I got this error when try to reindex catalog_product_price

php bin/magento indexer:reindex catalog_product_price

Notice: Undefined index: default in
/public_html/vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/Price/BatchSizeCalculator.php
on line 55

and from system.log

2019-11-27 20:03:04] main.ERROR: Cron Job indexer_reindex_all_invalid
has an error: Notice: Undefined property:
MagentoCatalogModelResourceModelProductIndexerPriceBatchSizeCalculator::$_batchRowsCount
in
/public_html/vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/Price/BatchSizeCalculator.php
on line 55. Statistics:
{“sum”:0,”count”:1,”realmem”:0,”emalloc”:0,”realmem_start”:138412032,”emalloc_start”:134564184}
[] []

BatchSizeCalculator.php as below ( unmodified)

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

namespace MagentoCatalogModelResourceModelProductIndexerPrice;

/**
 * Ensure that size of index MEMORY table is enough for configured rows count in batch.
 */
class BatchSizeCalculator
{
    /**
     * @var array
     */
    private $batchRowsCount;

    /**
     * @var MagentoFrameworkIndexerBatchSizeManagementInterface[]
     */
    private $estimators;

    /**
     * @var MagentoCatalogModelResourceModelProductIndexerPriceCompositeProductBatchSizeAdjusterInterface[]
     */
    private $batchSizeAdjusters;

    /**
     * BatchSizeCalculator constructor.
     * @param array $batchRowsCount
     * @param array $estimators
     * @param array $batchSizeAdjusters
     */
    public function __construct(array $batchRowsCount, array $estimators, array $batchSizeAdjusters)
    {
        $this->batchRowsCount = $batchRowsCount;
        $this->estimators = $estimators;
        $this->batchSizeAdjusters = $batchSizeAdjusters;
    }

    /**
     * Retrieve batch size for the given indexer.
     *
     * Ensure that the database will be able to handle provided batch size correctly.
     *
     * @param MagentoFrameworkDBAdapterAdapterInterface $connection
     * @param string $indexerTypeId
     * @return int
     */
    public function estimateBatchSize(MagentoFrameworkDBAdapterAdapterInterface $connection, $indexerTypeId)
    {
        $batchRowsCount = isset($this->batchRowsCount[$indexerTypeId])
            ? $this->batchRowsCount[$indexerTypeId]
            : $this->batchRowsCount['default'];

        /** @var MagentoFrameworkIndexerBatchSizeManagementInterface $calculator */
        $calculator = isset($this->estimators[$indexerTypeId])
            ? $this->estimators[$indexerTypeId]
            : $this->estimators['default'];

        $batchRowsCount = isset($this->batchSizeAdjusters[$indexerTypeId])
            ? $this->batchSizeAdjusters[$indexerTypeId]->adjust($batchRowsCount)
            : $batchRowsCount;

        $calculator->ensureBatchSize($connection, $batchRowsCount);

        return $batchRowsCount;
    }
}

tried running following doesn’t work

bin/magento setup:upgrade

bin/magento setup:di:compile

bin/magento setup:static-content:deploy -f 

bin/magento indexer:reindex

bin/magento cache:clean

bin/magento cache:flush

I also tried add the following to

app/etc/di.xml

but doesn’t work

<type name="MagentoCatalogModelResourceModelProductIndexerPriceBatchSizeCalculator">
    <arguments>
        <argument name="batchRowsCount" xsi:type="array">
            <item name="default" xsi:type="number">1000</item>
        </argument>
    </arguments>
</type>