I have duplicated Drupal Commerce module "Cash on delivery", from which I am trying to make custom module, where if customer choose as payment method my new payment, it will simply print out text with tokens inside. (This is because client needs to be able to pair orders with payments sent by credit card directly to his account, he will pair them with commerce order number)
I have successfully made a textarea in rules UI even with token field under this area, now I have to print them.
Working code for making textarea:
function bankovy_prevod_settings_form($settings = NULL) {
$settings = (array) $settings + array(
'information' => '',
'var_symbol' => ''
);
$form = array();
$form['information'] = array(
'#type' => 'textarea',
'#title' => t('Information'),
'#description' => t('Informácie, ktoré chcete zobraziť zákazníkom, keď si navolia túto možnosť platby.'),
'#default_value' => $settings['information']
);
$form['var_symbol'] = array(
'#type' => 'textarea',
'#title' => t('Variabilný symbol'),
'#description' => t('Sem vložte token, na základe ktorého sa bude generovať variabilný symbol.'),
'#default_value' => $settings['var_symbol']
);
if (module_exists('token')) {
$form['token_help'] = array(
'#theme' => 'token_tree',
'#token_types' => array('commerce-order'),
);
}
return $form;
}
Code for displaying the output on commerce order:
function bankovy_prevod_submit_form($payment_method, $pane_values, $checkout_pane, $order) {
$form = array();
$var_symbol = "";
if (!empty($payment_method['settings']['var_symbol'])) {
$var_symbol = token_replace($payment_method['settings']['var_symbol'], array('node' => $form['commerce_checkout_form']));
}
if (!empty($payment_method['settings']['information'])) {
$form['grafeon_bankovy_prevod_description'] = array(
'#markup' => $payment_method['settings']['information'] . "<br/>" . $var_symbol
);
}
// Need to create a dummy value to solve http://drupal.org/node/1230666
// Probably an issue in the main commerce module
$form['dummy'] = array(
'#type' => 'hidden',
'#value' => 'dummy'
);
return $form;
}
Now I have to somehow replace tokens, trying to use function token_replace, but it does not seem to work with "node" as checkout is not node, so I tried various different "commerce_checkout_form" strings but neither of them worked. Can anyone please help me out to solve this?
Thats the part I have problem with:
$var_symbol = token_replace($payment_method['settings']['var_symbol'], array('node' => $form['commerce_checkout_form']));
Any advice would be greatly appreciated.