【问题标题】:Implementing Custom Modules in Drupal在 Drupal 中实现自定义模块
【发布时间】:2012-07-27 00:35:15
【问题描述】:

我是 Drupal 的新手,我必须为 ubercart 编写一个新的自定义付款方式。我简要了解了 Drupal 的 hooks 系统。

在 ubercart api 文档中,http://www.ubercart.org/docs/api/hook_payment_method

<?php
function uc_payment_payment_method() {
  $methods[] = array(
    'id' => 'check',
    'name' => t('Check'),
    'title' => t('Check or Money Order'),
    'desc' => t('Pay by mailing a check or money order.'),
    'callback' => 'uc_payment_method_check',
    'weight' => 1,
    'checkout' => TRUE,
  );
  return $methods;
}
?>

但是,当我查看 paypal 模块的实现方式时:

$methods[] = array(
    'id' => 'paypal_wps',
    'name' => t('PayPal Website Payments Standard'),
    'title' => $title1 . $title2,
    'review' => t('PayPal'),
    'desc' => t('Redirect users to submit payments through PayPal.'),
    'callback' => 'uc_payment_method_paypal_wps',
    'redirect' => 'uc_paypal_wps_form',
    'weight' => 1,
    'checkout' => FALSE,
    'no_gateway' => TRUE,
  );

有一些特殊的字段,例如redirect 和no_gateway。我在哪里可以找到这些字段的文档以了解这些字段的实际作用?

非常感谢您的帮助。

【问题讨论】:

  • 别忘了你唯一能做的定制是支付方式。可能是 Paypal 模块为这个数组引入了一个新的键?这不是一个罕见的情况。抱歉,我找不到链接。

标签: php drupal ubercart


【解决方案1】:

您还可以在 http://api.ubercart.me/ 上查看 Ubercart API 文档。

但我看到对于hook_uc_payment_method(),这里没有比您提到的文档更多的信息了。

以 PayPal 支付模块为例,我发现重定向回调指定了重定向到场外支付网关的最终结帐按钮背后的代码。

所以uc_paypal_wps_form 是在最终结帐按钮后面生成的表单。如果您使用 Firebug 检查呈现的结帐按钮元素,您将看到此函数生成的表单。

我还在我的博客http://nmc-codes.blogspot.ca/2012/07/how-to-create-custom-ubercart-payment.html 上发布了一个示例

至于no_gateway 选项,这是我能在 ubercart 模块中找到的唯一一段引用它的代码:

if (empty($method['no_gateway'])) {
  $gateways = _uc_payment_gateway_list($id, TRUE);
  $options = array();
  foreach ($gateways as $gateway_id => $gateway) {
    $options[$gateway_id] = $gateway['title'];
  }
  if ($options) {
    $form['pmtable'][$id]['uc_payment_method_' . $id . '_checkout']['#title'] .= ' (' . t('includes %gateways', array('%gateways' => implode(', ', $options))) . ')';
  }
}

当您在admin/store/settings/payment的付款方式管理列表中查看付款方式时,它似乎没有做太多,但添加到付款方式的标签/标题

【讨论】:

  • 我在nmc-codes.blogspot.ca/2012/07/… 关注您的博客但是,我无法使用付款方式模块。可以帮我吗?
  • @peifa 我建议你提出一个关于你在哪里或如何被困的具体问题,并在这个论坛上提问。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-08-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多