You are here

function commerce_coupon_menu in Commerce Coupon 7.2

Implements hook_menu().

File

./commerce_coupon.module, line 125
Provides coupon functionality for Drupal Commerce.

Code

function commerce_coupon_menu() {

  // Find coupon auto-complete
  $items['commerce/coupons/find'] = array(
    'title' => 'Find coupon',
    'page callback' => 'commerce_coupon_find_coupon_autocomplete',
    'type' => MENU_CALLBACK,
    'access arguments' => array(
      'View any commerce_coupon of any type',
    ),
  );

  // Remove coupon from order.
  $items['commerce/coupons/order/remove/%commerce_coupon/%commerce_order'] = array(
    'title' => 'Delete coupon from order',
    'page callback' => 'commerce_coupon_remove_coupon_from_order_callback',
    'page arguments' => array(
      4,
      5,
    ),
    'access arguments' => array(
      'access checkout',
    ),
    'type' => MENU_CALLBACK,
  );

  // Edit & Delete coupon forms.
  $items['admin/commerce/coupons/%commerce_coupon'] = array(
    'title' => 'Edit',
    'page callback' => 'commerce_coupon_coupon_form_wrapper',
    'page arguments' => array(
      3,
      'edit',
    ),
    'access callback' => 'commerce_coupon_access',
    'access arguments' => array(
      'update',
      3,
    ),
    'weight' => 0,
    'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
  );
  $items['admin/commerce/coupons/%commerce_coupon/edit'] = array(
    'title' => 'Edit',
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'weight' => -10,
    'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
    'access callback' => 'commerce_coupon_access',
    'access arguments' => array(
      'update',
      3,
    ),
  );
  $items['admin/commerce/coupons/%commerce_coupon/delete'] = array(
    'title' => 'Delete',
    'page callback' => 'commerce_coupon_coupon_delete_form_wrapper',
    'page arguments' => array(
      3,
    ),
    'access callback' => 'commerce_coupon_access',
    'access arguments' => array(
      'delete',
      3,
    ),
    'type' => MENU_LOCAL_TASK,
    'weight' => 20,
    'context' => MENU_CONTEXT_INLINE,
  );

  // Coupon types.
  $items['admin/commerce/coupons/types'] = array(
    'title' => 'Coupon types',
    'description' => 'Manage coupon types for your store.',
    'file' => 'includes/commerce_coupon.admin.inc',
    'page callback' => 'commerce_coupon_types_overview_page',
    'access arguments' => array(
      'administer coupon types',
    ),
    'type' => MENU_LOCAL_TASK,
    'weight' => 0,
  );

  // Add coupon.
  $items['admin/commerce/coupons/add'] = array(
    'title' => 'Create Coupon',
    'description' => 'Create a new coupon',
    'page callback' => 'commerce_coupon_add_page',
    'page arguments' => array(
      commerce_coupon_create('discount_coupon'),
    ),
    'weight' => 10,
    'access callback' => 'commerce_coupon_access',
    'access arguments' => array(
      'create',
      commerce_coupon_create('discount_coupon'),
    ),
    'file' => 'includes/commerce_coupon.admin.inc',
  );
  foreach (commerce_coupon_get_types(TRUE) as $type => $coupon_type) {
    $coupon_type['type'] = $type;

    // Convert underscores to hyphens for the menu item argument.
    $type_arg = strtr($type, '_', '-');

    // Edit page.
    $items['admin/commerce/coupons/types/' . $type_arg] = array(
      'title' => $coupon_type['label'],
      'page callback' => 'drupal_get_form',
      'page arguments' => array(
        'commerce_coupon_type_settings_form',
        $coupon_type,
      ),
      'access arguments' => array(
        'administer commerce_coupon entities',
      ),
      'file' => 'includes/commerce_coupon.admin.inc',
    );
    $items['admin/commerce/coupons/types/' . $type_arg . '/edit'] = array(
      'title' => 'Edit',
      'access arguments' => array(
        'administer commerce_coupon entities',
      ),
      'type' => MENU_DEFAULT_LOCAL_TASK,
      'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
    );

    // Add pages.
    $items['admin/commerce/coupons/add/' . $type_arg] = array(
      'title' => 'Create !label',
      'title arguments' => array(
        '!label' => $coupon_type['label'],
      ),
      'description' => isset($coupon_type['description']) ? $coupon_type['description'] : '',
      'page callback' => 'commerce_coupon_coupon_form_wrapper',
      'page arguments' => array(
        commerce_coupon_create($type),
      ),
      'access callback' => 'commerce_coupon_access',
      'access arguments' => array(
        'create',
        commerce_coupon_create($type),
      ),
      'file' => 'includes/commerce_coupon.admin.inc',
    );

    // Edit conditions component - redirects to the normal component url.
    $items['admin/commerce/coupons/types/' . $type_arg . '/conditions'] = array(
      'title' => 'Edit conditions component',
      'description' => 'Add or remove conditions from the component that is evaluated to determine coupon eligibility',
      'access arguments' => array(
        'administer commerce_coupon entities',
      ),
      'page callback' => 'drupal_goto',
      'page arguments' => array(
        'admin/config/workflow/rules/components/manage/' . commerce_coupon_conditions_component_name($type),
      ),
      'type' => MENU_LOCAL_TASK,
      'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
      'weight' => 100,
    );
  }
  return $items;
}