You are here

function commerce_order_get_properties in Commerce Core 7

Callback for getting order properties.

See also

commerce_order_entity_property_info()

1 call to commerce_order_get_properties()
commerce_checkout_update_7103 in modules/checkout/commerce_checkout.install
If the variable commerce_checkout_run_update_7103 is set, change all user names that contain @ and look like an e-mail address to prevent the disclosure of e-mail addresses to non-trusted users. Refer to the release notes for Commerce 1.10 for…
2 string references to 'commerce_order_get_properties'
commerce_order_entity_property_info in modules/order/commerce_order.info.inc
Implements hook_entity_property_info().
commerce_order_ui_entity_property_info_alter in modules/order/commerce_order_ui.info.inc
Implements hook_entity_property_info_alter().

File

modules/order/commerce_order.module, line 1385
Defines the core Commerce order entity and API functions to manage orders and interact with them.

Code

function commerce_order_get_properties($order, array $options, $name) {
  switch ($name) {
    case 'owner':
      return $order->uid;
    case 'view_url':
      return url('user/' . $order->uid . '/orders/' . $order->order_id, $options);
    case 'admin_url':
      return url('admin/commerce/orders/' . $order->order_id, $options);
    case 'edit_url':
      return url('admin/commerce/orders/' . $order->order_id . '/edit', $options);
    case 'state':
      $order_status = commerce_order_status_load($order->status);
      return $order_status['state'];
    case 'mail_username':

      // To prepare an e-mail address to be a username, we trim any potential
      // leading and trailing spaces and replace simple illegal characters with
      // hyphens. More could be done with additional illegal characters if
      // necessary, but those typically won't pass e-mail validation anyways.
      // We also limit the username to the maximum length for usernames.
      // @see user_validate_name()
      $username = preg_replace('/[^\\x{80}-\\x{F7} a-z0-9@_.\'-]/i', '-', trim($order->mail));

      // Remove the e-mail host name so usernames are not valid email adresses.
      // Since usernames are considered public information in Drupal, we must
      // not leak e-mail adresses through usernames.
      $username = preg_replace('/@.*$/', '', $username);
      $username = substr($username, 0, USERNAME_MAX_LENGTH);
      return commerce_order_unique_username($username);
  }
}