2

We have upgraded magento to 2.4.3-p1 and added new bundle product. On frontend when we access bundle product it show error Call to undefined method Magento\Catalog\Model\ResourceModel\Product\Flat::getLinkField()

<script type="text/x-magento-init">
    {
        "*": {
                "Magento_Catalog/js/product/view/provider": {
                    "data": Error: Call to undefined method Magento\Catalog\Model\ResourceModel\Product\Flat::getLinkField() in /chroot/home/3343sfdsadf/domain.com/html/vendor/magento/module-eav/Model/Entity/Collection/AbstractCollection.php:1066

it seems like magento added some new files and plugin for bundle product in magento 2.4.3-p1. Any help is appreciated!

3 Answers 3

5

Vendor\Module\etc\di.xml

<preference for="Magento\Bundle\Model\Product\SingleChoiceProvider" type="Vendor\Module\Model\Product\SingleChoiceProvider" />

Vendor\Module\Model\Product\SingleChoiceProvider.php

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
declare(strict_types=1);

namespace Vendor\Module\Model\Product;
use Magento\Catalog\Model\Product;
use Magento\Catalog\Model\Product\Type as BundleType;

class SingleChoiceProvider extends \Magento\Bundle\Model\Product\SingleChoiceProvider
{

    public function isSingleChoiceAvailable(Product $product) : bool
    {
        $result = false;
        if ($product->getTypeId() === BundleType::TYPE_BUNDLE) {
            $typeInstance = $product->getTypeInstance();
            $typeInstance->setStoreFilter($product->getStoreId(), $product);

            if ($typeInstance->hasRequiredOptions($product)) {
                $options = $typeInstance->getOptions($product);
                $isNoCustomizations = true;
                foreach ($options as $option) {
                    $optionId = $option->getId();
                    $required = $option->getRequired();
                    if ($isNoCustomizations && (int) $required === 1) {
                        $selectionsCollection = $typeInstance->getSelectionsCollection(
                            [$optionId],
                            $product
                        );
                        $selections = []; //$selectionsCollection->exportToArray();
                        if (count($selections) > 1) {
                            foreach ($selections as $selection) {
                                if ($isNoCustomizations) {
                                    $isNoCustomizations = (int)$selection['is_default'] === 1
                                        && (int)$selection['selection_can_change_qty'] === 0;
                                } else {
                                    break;
                                }
                            }
                        }
                    } else {
                        $isNoCustomizations = false;
                        break;
                    }
                }

                $result = $isNoCustomizations;
            }
        }
        return $result;
    }
}
2
  • Akashmalik did that fix it? We're experiencing similar issues after all bundle products since migrating from 1.9.3 to 2.4.3 Commented Nov 15, 2021 at 16:50
  • yes rewrite file Vendor\Module\Model\Product\SingleChoiceProvider.php and modify below line $selections = []; //$selectionsCollection->exportToArray();
    – akashmalik
    Commented Dec 2, 2021 at 16:59
3

Since 2.3 Magento recommends to disable Flat catalog, this would fix that problem

https://docs.magento.com/user-guide/catalog/catalog-flat.html

Use of a flat catalog is no longer recommended as a best practice. Continued use of this feature is known to cause performance degradation and other indexing issues. A detailed description and solution is available in the Help Center.

Affected versions include:

  • Adobe Commerce on cloud infrastructure, 2.3.x and above
  • Adobe Commerce (On-Premise), 2.3.x and above
  • Magento Open Source, 2.3.x and above

On any release version, some extensions only work with flat tables, thus creating a risk if you disable flat tables. If you know that you have some extensions that use Flat Catalog indexers, you need to be aware of this risk when setting those values to No.

1
1

Disable the Use Flat Catalog Product from admin.

Path to disable is Admin->Stores->Configuration->Catalog->Catalog->Storefront->Use Flat Catalog Product

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.