You are here

function basic_cart_order_tokens in Basic cart 7.3

Implements hook_tokens().

File

basic_cart_order/basic_cart_order.module, line 448

Code

function basic_cart_order_tokens($type, $tokens, array $data = array(), array $options = array()) {
  $replacements = array();

  // The first thing that we're going to check for is the type of token - node,
  // user etc...
  if ($type == 'basic_cart_order') {

    // Loop through each of the available tokens.
    foreach ($tokens as $name => $original) {

      // Find the desired token by name
      switch ($name) {
        case 'products':
          $new = '';
          $cart = basic_cart_get_cart();

          // Building the order details.
          $i = 0;
          $products = '';
          foreach ($cart as $nid => $node) {
            $unit_price = basic_cart_price_format($node->basic_cart_unit_price);
            $new .= ++$i . '. ' . $node->title . "\t" . $node->basic_cart_quantity . ' x ' . $unit_price . "\n";
          }

          // Add the new value into the replacements array.
          $replacements[$original] = $new;
          break;
      }
    }
  }

  // Return the replacements.
  return $replacements;
}