1

Somehow, the Drupal Commerce page at admin/commerce/products/add is failing to recognise that I have product types and is giving this misleading error:

You have not created any product types yet. Go to the product type creation page to add a new product type.

From reading this discussion and a look at the code here it looks like the Commerce module on this page bizarrely gets the list of product types from looking at the menus. There's a heap of "what worked for me was moving X to Y in the menus" but they all seem to be slightly different and match older menu naming conventions. This issue appears related but isn't. I have editted the Commerce menu and would like to keep my editted menu how it is.

How can I make sure that Commerce recognised my product types on this page? What has to be where for this page to recognise product types (or even better, is there a way to make it happen the normal way via entities instead of via menus?)

I've also tried bypassing my broken admin/commerce/products/add page completely with a redirect, but the redirect is ignored.

I've also tried moving my Products > Create Item auto-generated menu links back under Store in the Management menu, and creating new menu links to those pages under Store in the Management menu, but neither works.

1 Answer 1

1

Those admin pages are generally based on the menu, so I think it makes sense that the commerce module is using the menu to build it.

It doesn't have to be like that, though, you can change it up pretty easily:

function MYMODULE_menu_alter(&$items) {
  $items['admin/commerce/products/add']['page callback'] = 'MYMODULE_commerce_product_ui_add_page';
}

function MYMODULE_commerce_product_ui_add_page() {
  $types = commerce_product_types();  

  if (count($types) == 1) { 
    drupal_goto(_MYMODULE_commerce_product_admin_add_path(key($types)));
  } 

  return theme('MYMODULE_product_add_list', array('types' => $types));
}

function _MYMODULE_commerce_product_admin_add_path($type) {
  // Method taken from commerce_product_ui_menu()
  return 'admin/commerce/products/add/' . strtr($type, array('_' => '-'));
}

function MYMODULE_theme() {
  return array(
    'MYMODULE_product_add_list' => array(
      'variables' => array('types' => array()),
    ),
  );
}

function theme_MYMODULE_product_add_list($variables) {
  // Build up an HTML list of links based on $variables['types'], similar to theme_product_add_list()
}
2
  • I've tried using the menu callback to redirect to a page using drupal_goto() but, like the Global Redirect module redirect, it doesn't do anything - it seems like Commerce is somehow overriding all other instructions about what to do with this page? Commented Jun 12, 2016 at 12:47
  • Hmm, if I'm not mistaken we're just using the core menu functions, but I have personally seen the problem with nodes on a D7 site ... didn't realize it was related! Gives me a good lead to track that down. Commented Jan 25, 2019 at 16:50

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.