You are here

Ubercart的支付方法,率先采用插件机制

g089h515r806 的头像
Submitted by g089h515r806 on 星期六, 2014-01-18 10:18

Ubercart的Drupal8版本,已经开发了1年多的时间了,这无疑是一个鼓舞人心的消息。而与之形成对比的是Commerce模块,毫无动静。
在Ubercart4.x,支付方法,结算窗格,运费计算方法,都将采用插件的形式,我们现在先读为快:

/**
* @file
* Contains \Drupal\uc_payment\Plugin\Ubercart\PaymentMethod\FreeOrder.
*/

namespace Drupal\uc_payment\Plugin\Ubercart\PaymentMethod;

use Drupal\uc_order\UcOrderInterface;
use Drupal\uc_payment\PaymentMethodPluginBase;

/**
* Defines a free order payment method.
*
* @Plugin(
* id = "free_order",
* name = @Translation("Free order"),
* title = @Translation("No payment required"),
* description = @Translation("Allow customers with free orders to check out without paying."),
* checkout = TRUE,
* no_gateway = TRUE,
* configurable = FALSE,
* weight = 0,
* )
*/
class FreeOrder extends PaymentMethodPluginBase {

/**
* {@inheritdoc}
*/
public function cartDetails(UcOrderInterface $order, array $form, array &$form_state) {
return array(
'#markup' => t('Continue with checkout to complete your order.'),
);
}

/**
* {@inheritdoc}
*/
public function orderSubmit(UcOrderInterface $order) {
if ($order->getTotal() >= 0.01) {
return array(array(
'pass' => FALSE,
'message' => t('We cannot process your order without payment.'),
));
}

uc_payment_enter($order->id(), 'free_order', 0, 0, NULL, t('Checkout completed for a free order.'));
}

}

论坛:

Drupal版本:

g089h515r806 的头像

采用插件机制,实现支付方法,最早就是在Ubercart社区内提出来的,无论是Drupal7下,还是Drupal8下,Ubercart都是率先实现的。
而Commerce模块,仅仅提出了这个目标,将来也会实现,但是现在还没有动静。