Drupal Commerce 2 - 修改评论结帐面板

问题描述 投票:0回答:0

我正在使用 https://docs.drupalcommerce.org/commerce2/developer-guide/checkout/replacing-existing-checkout-pane 的指导来尝试修改 Review checkout 窗格。

我需要检查自定义结帐窗格中的一些数据,并根据该逻辑禁用“完成付款”提交按钮并将其替换为警告。

在我的 custom_module.module 中,我正在使用:

<?php

/**
 * Implements hook_commerce_checkout_pane_info_alter().
 */
function custom_module_check_commerce_checkout_pane_info_alter(&$definitions) {

  if (isset($definitions['review'])) {
    $definitions['review']['class'] = \Drupal\custom_module\Plugin\Commerce\CheckoutPane\Review::class;
    $definitions['review']['provider'] = 'custom_module';
  }
}

在 Review.php 中:

<?php

namespace Drupal\custom_module\Plugin\Commerce\CheckoutPane;

use Drupal\checkout\Plugin\Commerce\CheckoutPane\Review as BaseReview;
use Drupal\Core\Form\FormStateInterface;

/**
 * Provides a custom payment information pane.
 */
class Review extends BaseReview {

  /**
   * {@inheritdoc}
   */
  public function buildPaneForm(array $pane_form, FormStateInterface $form_state, array &$complete_form) {
    $pane_form = parent::buildPaneForm($pane_form, $form_state, $complete_form);
    // Do something custom with the pane form here.
    $pane_form['test'] = [
        '#markup' => $this->t('Error.'),
      ];
    return $pane_form;
  }
}

我收到这个错误: 错误:类“德鲁巴

drupal drupal-9 commerce
© www.soinside.com 2019 - 2024. All rights reserved.