The link to the order on the detail page of a return entity is wrong. It leads to "user/%user/order/%commerce_order" instead of "user/%user/orders/%commerce_order".

I've attached a patch that...

1. removes the implementation of hook_preprocess_field(), that manipulated the link to the order
2. adds an implementation of hook_commerce_order_uri(), that serves a correct link to the order, no matter if you're on an admin page or on frontend.

I've wrapped that in an if statement, that looks for existence of commerce_order_ui module because all the order related menu hooks are coming from the UI module. I've not tested, what happens to the output of the reference field, if the commerce_order_ui module is disabled. In my current setup, it's also not possible to disable the Order UI module because lots of other modules have direct or indirect dependencies on that module. So it would be nice, if someone could test this scenario. Then one must decide, whether further manipulation in a preprocess function should happen, or maybe the module should add a dependency on the order UI module as well, etc.

A smaller detail question to clarify, how we should find out, when to direct to an admin page. Currently, I've chosen to check for
if (path_is_admin(current_path()) || user_access('view any commerce_order entity')) { because same check is done within commerce_return_uri(). But maybe only checking for the user_access would be enough or even better?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

agoradesign’s picture

Issue summary: View changes
Status: Active » Needs review
FileSize
2.07 KB
jkuma’s picture

Status: Needs review » Reviewed & tested by the community

@agoradesign: Your approach is better and much cleaner than using the preprocess_field hook. It also solves the issue raised on both admin and customer UI. Updating the issue to RTBC.

  • goldorak committed 3a9c1b9 on 7.x-2.x authored by agoradesign
    Issue #2407069 by agoradesign: Link to order on detail page is wrong
    
jkuma’s picture

Status: Reviewed & tested by the community » Fixed

committed to dev branch.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.