Как вывести способы оплаты в виде таблицы в Drupal Commerce

Для того, чтобы вывести доступные способы оплаты заказа в виде таблицы в Drupal Commerce, необходимо добавить следующий код в свой модуль:

/**
 * Implements hook_form_FORM_ID_alter().
 */
function example_form_commerce_checkout_form_review_alter(&$form, &$form_state) {
  $header = array(
    'payment' => t('Payment'),
    'description' => t('Description'),
  );
  
  $checkout_pane = commerce_checkout_pane_load('commerce_payment');
  foreach ($form['commerce_payment']['payment_method']['#options'] as $key => $option) {  
    $method_info = $form['commerce_payment']['payment_methods']['#value'][$key];
    $payment_method = commerce_payment_method_load($method_info['method_id']);
    $payment_method['settings'] = $method_info['settings'];
    
    $description = '';
    if ($callback = commerce_payment_method_callback($payment_method, 'submit_form')) {
      $description = $callback($payment_method, array(), $checkout_pane, $form_state['order']);
    }
    
    $options[$key] = array();
    $options[$key]['payment'] = $option;
    $options[$key]['description'] = render($description);
  }
  
  // Change a standart widget to a table select widget to specify the payment method.
  $form['commerce_payment']['payment_method']['#type'] = 'tableselect';
  $form['commerce_payment']['payment_method']['#header'] = $header;
  $form['commerce_payment']['payment_method']['#options'] = $options;
  $form['commerce_payment']['payment_method']['#empty'] = t('No payment methods available.');
  $form['commerce_payment']['payment_method']['#multiple'] = FALSE;
  
  $form['commerce_payment']['payment_details']['#access'] = FALSE;
}

Результат

Cпособы оплаты в виде таблицы в Drupal Commerce
Cпособы оплаты в виде таблицы в Drupal Commerce
Benya