Fatal error: Class Drupal\commerce_product_bundle_stock\ProductBundleStockProxy contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Drupal\commerce_stock\StockCheckInterface::getTotalAvailableStockLevel) in /app/modules/contrib/commerce_product_bundle/modules/commerce_product_bundle_stock/src/ProductBundleStockProxy.php on line 14

I have installed commerce_product_bundle $ lando composer require 'drupal/commerce_product_bundle:^1.0@alpha' in drupal 9 latest and enabled the module. Error started showing.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

FlutterStack created an issue. See original summary.

flutterstack’s picture

getTotalAvailableStockLevel is an abstract method declared in StockCheckInterface. getTotalAvailableStockLevel is not defined in ProductBundleStockProxy. Hence error is throwing.

  /**
   * {@inheritdoc}
   */
  public function getTotalAvailableStockLevel(
    PurchasableEntityInterface $bundle,
    array $locations
  ) {
    $this->assertBundleInterface($bundle);
    /** @var \Drupal\commerce_product_bundle\Entity\BundleItemInterface $bundleItem */
    $levels = array_map(function ($bundleItem) use ($bundle, $locations) {
      $quantity = $bundleItem->getQuantity() ?: 1;
      /** @var \Drupal\commerce\PurchasableEntityInterface $entity */
      $entity = $bundleItem->getCurrentVariation();
      $service = $this->stockServiceManager->getService($entity);
      $level = $service->getStockChecker()
        ->getTotalAvailableStockLevel($entity, $locations);
      return floor($level / $quantity);
    }, $bundle->getBundleItems());

    return min($levels);
  }

this code resolves the error but I am not sure method body is implemented correctly. kindly review method body and confirm. thank you.

socialnicheguru’s picture

Status: Active » Closed (duplicate)

I think that because there are no changes to code and the function will be inherited, it just has to be mentioned.