1

As question states, i'm trying to make a custom menu ( hook_menu() ) to call the same pages as how commerce does it originally (will link everything below)

The idea is to let Authenticated users add products (of all product types)
I have changed the permissions for creating product entities
and can acces, as Authenticated users, the add form via the the admin url

But i'd like to change that so they have a custom link and don't see the whole admin/commerce/products/add/bag

but only
/products/add/bag

i have tried to do this by adding a custom menu with the hook_menu() but always get an 'You are not authorized to access this page.' message, even when i am connected as admin

Anyone any idea what i should change to be able to acces it outside de admin zone?

my hook_menu():

function TTK_product_form_menu() {

  //non admin form
  if (function_exists('commerce_product_types')) {
    $commerce_product_bp = drupal_get_path('module', 'commerce_product').'/';


    foreach (commerce_product_types() as $type => $product_type) {

      $items['products/add/' . strtr($type, array('_' => '-'))] = array(
        'title' => 'Create !name',
        'title arguments' => array('!name' => $product_type['name']),
        'description' => $product_type['description'],
        'page callback' => $commerce_product_bp.'commerce_product_ui_product_form_wrapper',
        'page arguments' => array(commerce_product_new($type)),
        'access callback' => $commerce_product_bp.'commerce_product_access',
        'access arguments' => array('create', $type),
        'file' => $commerce_product_bp.'includes/commerce_product_ui.products.inc',
      );
    }
  }

  return $items;
}

1 Answer 1

0

problem was that i didn't knew very well how menu hook worked
solution is:

foreach (commerce_product_types() as $type => $product_type) {
  $items['sell/' . strtr($type, array('_' => '-'))] = array(
    'title' => 'Sell !name',
    'title arguments' => array('!name' => $product_type['name']),
    'page callback' => 'commerce_product_ui_product_form_wrapper',
    'page arguments' => array(commerce_product_new($type)),
    'access callback' => 'commerce_product_access',
    'access arguments' => array('create', commerce_product_new($type)),
    'file' => 'includes/commerce_product_ui.products.inc',
    'file path' => $commerce_product_bp,
  );
}

didn't have to apend the path to function names, thought those where called by path for some reason..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.