I' trying to build this kind of pages:

  • one page for each taxonomy term with taxonomy info and all commerce products related to term


  • one 'products' page where users can click on a taxonomy image to view all the products in a box (loaded via ajax).

I have built taxonomy/term/* pages and the products page and they work fine but when I tried to add a product to cart (from taxonomy/term AND products pages.. ) drupal add the product to cart but always redirect me in the taxonomy/term page.

So I tried to setup a different form #redirect in hook_form_alter() but it work in a strange way: when I call taxonomy/term page via ajax to include it in products page now drupal serve me the product page itself like there is a all times redirect from taxonomy/term page to products page.

$form['#redirect'] = drupal_goto('products');

If I write

$form['#redirect'] = 'products';

just do not redirect.

How can I achieve a right redirect?

I'm working in D7 with drupal commerce to manage e-commerce


1 Answer 1


I solved this problem with this code:

function mymodule_form_alter(&$form, &$form_state, $form_id) {
  if( startsWith($form_id, 'commerce_cart_add_to_cart_form_') ){
    array_push($form['#submit'], '_mymodule_redirect_to_products_page');

function  _mymodule_redirect_to_products_page(&$form, &$form_state){
  global $language ;
  $lang_name = $language->language ;

  $form_state['redirect'] = url('prodotti', array('language' => $language));

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.