How about a hook for adding some description text at the bottom of the box?

I am creating a plugin module for Coffee called Commerce Coffee, that enables sellers to:

- Quickly navigate trough commerce
- Find latest order by entering email
- Setting commonly used search criterias for views by using Coffee

Having a hook like that would enable it to add a command quicklist to the box.

Comments

lsolesen’s picture

That would be a great idea, so the user would instantly know which commands to use.

@farald How is the development going - any public code, and do you plan on releasing on d.o.?

farald’s picture

Assigned: michaelmol » Unassigned

Hey, thought is to get a sandbox up & running with it, and eventually a module.
The code is pretty basic, it hooks in using hook_coffee_command, code below.

To look for users & user's orders:
:u buyer@email.com or :u username

Look for sku:
:sku BOOK_1

Look for orders:
:o 19

..and links magically shows up.

<?php

/**
 * Implements hook_coffee_command().
 * 
 * Allows hooking into coffee and feed it with cool commands.
 */
function commerce_coffee_coffee_command($op) {
  if (user_access('use commercify coffee')) {
    switch ($op) {
    // Users & orders owned
    if (strpos($op, 'u ') === 0) {
      $return = array();
      //xdebug_break();
      // Remove the first letter
      $email = substr($op, 2);
      if (!empty($email)) {
        if ($s_user = user_load_by_mail($email) or $s_user = user_load_by_name($email)) {
          $return[] = array(
            'path' => 'user/' . $s_user->uid,
            'title' => $s_user->name . " -> Settings",
          );

          // Let's see if we can get the latest order...
          $query = new EntityFieldQuery();
          $query
              ->entityCondition('entity_type', 'commerce_order', '=')
              ->entityOrderBy('entity_id', 'DESC')
              ->range(0, 1)
              ->propertyCondition('uid', $s_user->uid, '=');
          $result = $query->execute();
          foreach ($result['commerce_order'] as $order_id => $order) {
            $order = commerce_order_load($order_id);
            $return[] = array(
              'path' => 'admin/commerce/orders/' . $order_id,
              'title' => "Show orders " . $order_id . " datert " . format_date($order->created, 'custom', 'd-m-Y'),
            );
          }
        }
      }
    }

    if (strpos($op, 'sku ') === 0) {
      $return = array();
      //xdebug_break();
      // Remove the first letter
      $sku = substr($op, 4);
      if (!empty($sku)) {
        if ($product = commerce_product_load_by_sku($sku)) {
          $return[] = array(
            'path' => 'admin/commerce/products/' . $product->product_id,
            'title' => "Product: " . $product->title,
          );
        }
      };
    }

    // Order IDs
    if (strpos($op, 'o ') === 0) {
      $return = array();
      $order_id = substr($op, 2);
      if (is_numeric($order_id)) {

        // Let's see if we can get the latest order...
        $query = new EntityFieldQuery();
        $query
            ->entityCondition('entity_type', 'commerce_order', '=')
            ->entityOrderBy('entity_id', 'DESC')
            ->range(0, 1)
            ->propertyCondition('order_id', $order_id, '=');
        $result = $query->execute();

        foreach ($result['commerce_order'] as $order_id => $order) {
          $order = commerce_order_load($order_id);
          $return[] = array(
            'path' => 'admin/commerce/orders/' . $order_id,
            'title' => "Show order " . $order_id . " datert " . format_date($order->created, 'custom', 'd-m-Y'),
          );
          $return[] = array(
            'path' => 'admin/commerce/orders/' . $order_id . "/edit",
            'title' => "Change order " . $order_id . " datert " . format_date($order->created, 'custom', 'd-m-Y'),
          );
        }
      }
    }
    if (isset($return)) {
      return $return;
    }
  }
};?>

My utopia is a hook, in which I can write:

<?php

function commerce_coffee_coffee_command_info() {
  $info = array();
  $info['commerce_coffee_order'] = array(
    'command' => ':o {An order ID}',
    'info' => 'Look for & goto an order ID.'
  );
  $info['commerce_coffee_user'] = array(
    'command' => ':u {An email, username or user ID}',
    'info' => 'Goto user page or latest orders.'
  );
  return $info;
}

?>

Personally I think this would be best implemented as showing only when the input field is empty (or maybe only containing the ':'), and hiding itself once user starts entering.

When administering Commerce a lot, this feels more or less like having a Drush inside Drupal. And that's awesome :)

EDIT: Temp sandbox for Commerce Coffee is now here: http://drupal.org/sandbox/farald/1457938

michaelmol’s picture

I like the idea and I think a list of possible command should show when ':' is typed.

michaelmol’s picture

Assigned: Unassigned » michaelmol
maartenverbaarschot’s picture

Assigned: Unassigned » michaelmol

Sounds like we could bring :help back from the dead. (Similar to typing drush help)

lsolesen’s picture

@micahelmol a good idea with some hints when : is typed. Maybe starting with a short message explaining that the user can type : to get the possible commands.

@maartenverbaarschot :help would also be a good idea :)

michaelmol’s picture

:help sounds like an ideal candidate

maartenverbaarschot’s picture

Version: 7.x-1.0 » 7.x-2.x-dev
farald’s picture

Re @Isolesen #1: Commerce Coffee is now a full project.