Redirect to a cart after a cart item is added to the cart

Created on 8 September 2017, about 7 years ago
Updated 17 November 2023, about 1 year ago

Problem/Motivation

Some shops has low average order item count. E.g. selling a few goods/services in larger scale. Now, when user add an item to a cart, he is redirected back to the same item page and he needs to find a cart link a click it.

Proposed resolution

I suggest, that there should be a configuration option (at a store level?) to "stay on cart item or redirect to cart" (after adding an item to a cart).

Feature request
Status

Active

Version

2.0

Component

Cart

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇺🇸United States mikemccaffrey

    In case anyone else stumbles here looking to do this, I believe this code will work perfectly well until the feature is added to core.

    /**
     * Implements hook_form_BASE_FORM_ID_alter().
     */
    function MODULENAME_form_commerce_order_item_add_to_cart_form_alter(&$form, FormStateInterface $form_state, $form_id) {
    
      // Redirect the user to the shopping cart on submit.
      $form_state->setRedirect('commerce_cart.page');
    }
    
  • 🇮🇱Israel jsacksick

    So... There's this issue Allow order types to have no carts Needs work which is about redirecting to checkout directly... It'd be great if from within the same patch we could support both usecases, but I'm afraid the other patch is focused on the checkout usecase...

    Perhaps the order type setting could be the page to redirect to? But it isn't as easy as exposing the path to redirect to because some routes (like the checkout route) require extra parameters (i.e. the order).

  • 🇮🇱Israel jsacksick

    But maybe as part of this issue, the cart module itself could do this...

Production build 0.71.5 2024