I created a node display for a regular Product type, referencing a generic tshirt product.

Add to cart works fine, and going to checkout is fine too. However, if you click 'Go Back' at this point, you get access denied or go back to the cart, it is empty. There is an order in the backend with no order status attributed to no one, and its orphaned.

I have a hunch it is because 'Go Back' eventually hits the Registration Information checkout page/pane and there is no registration in the cart. I don't really have any custom code that would trigger this, I will look at any existing Rules too.

Comments

kevinquillen’s picture

If I place an order and put a registration in cart, and a regular product, the checkout process works fine. Once I remove that registration and try to move forward, I get the same error(s) noted in the original post.

kevinquillen’s picture

Title: When placing a regular order that is not a registration, order is destroyed. » When placing a regular order that is not a registration, order gets mangled.

Here is what I came up with to get around this temporarily:


function satb_registrations_cart_order_has_registration() {
  global $user;
  $order = commerce_cart_order_load($user->uid);

  if (!$order) {
    $order = commerce_order_load(arg(1));
  }

  if ($order) {
    $order_wrapper = entity_metadata_wrapper('commerce_order', $order);

    foreach ($order_wrapper->commerce_line_items as $line_item_wrapper) {
      $line_item = $line_item_wrapper->value();
      $line_item_product = commerce_product_load($line_item->commerce_product[LANGUAGE_NONE][0]['product_id']);
      if ($line_item_product->type == 'registration') {
        return TRUE;
      }
    }
  }

  return FALSE;
}

function satb_registrations_commerce_checkout_pane_info_alter(&$checkout_panes) {
  if (preg_match('/(cart|checkout)/', request_uri())) {
    if (!satb_registrations_cart_order_has_registration()) {
      $checkout_panes['registration_information']['enabled'] = FALSE;
    }
  }
}

function satb_registrations_commerce_checkout_page_info_alter(&$checkout_pages) {
  if (preg_match('/(cart|checkout)/', request_uri())) {
    if (!satb_registrations_cart_order_has_registration()) {
      unset($checkout_pages['registration']);
    }
  }
}

On the cart or checkout pages, it will load the order in the cart, or if the status has changed, grab it from the URL. If the order contains a registration, the page is disabled and pane is removed.

It seems to do the trick, with one exception. Any order now throws this error on every page up to completing checkout:

There are errors on the page. Please correct them and resubmit the form.

However there was no form to complete. I am not sure why this is occurring.

jpontani’s picture

The problem lies in the fact that you're unsetting the page, but the registration pane still exists inside a page that no longer exists. The other issue is skipping it properly. The pane form builders don't actually get told which button was clicked (next page or go back), so I have to cheese a way to figure out which direction the user wants to go, which is not 100% reliable and can cause issues.

The problem that you're having with mangled orders is that I was always skipping forward without regard for when the user clicked "go back". I am going to remove the code that tries to skip the pane for now, and unfortunately just have to show a message saying no information required, skip the page.

This is related to #1302096: Automatically skip empty checkout pages which unfortunately was marked as will not fix.

kevinquillen’s picture

What I wound up doing was taking the core commerce 'back' function in the submit and implementing my own, nearly the same code, but I am changing the form redirects, as well as setting the order status to 'cart' or 'checkout_registration' depending on where they are about to go.

jpontani’s picture

Status: Active » Closed (won't fix)

Closing. I am starting the 3.x branch anew and it will no longer include a checkout page, only a checkout pane.