Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By nellngun on
Hi,
I want to sent email to the customer with a price excluding tax 'base-price' (there is no token value for my case)
I made this custom module but I when i use tokens for commerce message i see price 0. What do I do wrong please?
Module.tokens.inc file:
/**
* Implements hook_token_info().
*/
function Commerce_Order_Breakup_tokens_info() {
$type = array(
'name' => t('Line items'),
'description' => t('Tokens related to individual line items.'),
'needs-data' => 'commerce-line-item',
);
// Tokens for line items.
$line_item = array();
$line_item['base-price'] = array(
'name' => t('Order total:Base price'),
'description' => t('The sub-total excluding shipping tax end other fees and charges.'),
);
$line_item['shipping'] = array(
'name' => t('Order total:Shipping'),
'description' => t('The total cost of shipping.'),
);
$line_item['tax_rate'] = array(
'name' => t('Order total:Tax'),
'description' => t('The Tax of the order including shipping.'),
);
return array(
'tokens' => array('commerce-order' => $order),
);
}
/**
* Implements hook_tokens().
*/
function Commerce_Order_Breakup_tokens($type, $tokens, array $data = array(), array $options = array()) {
$url_options = array('absolute' => TRUE);
$replacements = array();
if ($type == 'commerce-line-item' && !empty($data['commerce-line-item'])) {
$line_item = $data['commerce-line-item'];
foreach ($tokens as $name => $original) {
switch ($name) {
// Simple key values on the line item.
case 'base-price':
$price_components = commerce_price_component_load($line_item->commerce_order_total['und']['0'], 'base_price');
// kpr($price_components);
$replacements[$original] = commerce_currency_format($price_components['0']['price']['amount'], $price_components['0']['price']['currency_code']);
break;
case 'shipping':
$price_components = array();
if (empty($price_components['0'])) { $price_components = commerce_price_component_load($line_item->commerce_order_total['und']['0'], 'flat_rate_binnen_nederland'); }
if (empty($price_components['0'])) { $price_components = commerce_price_component_load($line_item->commerce_order_total['und']['0'], 'flat_rate_verzenden_buiten_nederland'); }
// Following is a dummy line to slot in another shipping rate above
// this comment. We never use the following line as at least one
// shipping rate always gets set above. Just copy and change.
// if(empty($price_components['0'])) { $price_components = commerce_price_component_load($line_item->commerce_order_total['und']['0'], 'flat_rate_dummy'); }
$replacements[$original] = commerce_currency_format($price_components['0']['price']['amount'], $price_components['0']['price']['currency_code']);
break;
case 'tax_rate':
$price_components = commerce_price_component_load($order->commerce_order_total['und']['0'], 'btw_hoog');
$replacements[$original] = commerce_currency_format($price_components['0']['price']['amount'], $price_components['0']['price']['currency_code']);
break;
}
}
}
return $replacements;
}
MODULE FILE:
<?php
<?php
/**
* @file Commerce_Order_Breakup_tokens.module
* TODO: Enter file description here.
*/
Comments
anybody?
anybody?