The order revision system is in place, but there's currently no way to view changes. At this point, I don't believe we need to consider reverting revisions, but some sort of Views integration should be developed so we can list revisions on a tab for Orders. Furthermore, there should be a way to see what's changed or at the very least to get a link to view the order at the time of the specific revision.

Comments

m.stenta’s picture

StatusFileSize
new6.06 KB

Here is an initial patch that provides Views support for the {commerce_order_revision} table.

redhoodie’s picture

This would be useful

redhoodie’s picture

I don't seem to be able to get the Order via the relationship on commerce_order_revision revision_id

j0rd’s picture

I need this as well. This is important for accounting reasons.

I also think we need something very similar for manually entered payments. Currently commerce depends on each particular processor to implement fields which are used for inputting data. In my opinion we should add one generic textarea, which could be used when payments are entered manually then appended to `commerce_payment_transaction.message`. Something like this is useful for vendors who need to log a little additional information (especially when manually entering payments in the admin)

rszrama’s picture

j0rd, you mean like comments on a payment transaction itself?

adamgerthel’s picture

@j0rd I think a more generic approach like adding log messages to orders is better.

Anyway, I'm looking for order revisions as well. Also for accounting reasons. I see that they are available in the DB, but there's no revisions tab. Using the "comment" also feels a bit useless without this functionality.

I can probably create a view to display revisions where a user can filter on order ID, but a tab on orders labeled "Order history" or so would be much more useful and intuitive.

rszrama’s picture

@Adam, yep, what you see in #840786-1: View order UI is the end goal. Orders already support log messages in revisions; you can add a general comment field to the order entity if you'd prefer. I think bojanz made a module for that.

adamgerthel’s picture

We tried the patch in #1 and it works. For now we'll add an "order history" tab on orders through views ourselves. Looking forward to seeing it implemented in DC later on

urlaub’s picture

@AdamGerthel I tried the patch as well, but I can't find the "order history" tab "out-of the-box?
Where and how did you add the tab?

adamgerthel’s picture

@urlaub It's not there out of the box. You can add it using views (add it as a "tab" from the menu settings). Understanding how tabs work is a little tricky but you should be able to work it out

pjnes’s picture

I've applied this patch and tried to create a view, however the Commerce Order Revision stuff doesn't seem to be showing up anywhere? Where should it be showing? I've checked the relationships and fields within an order view and found nothing.

Presumably I'm missing something obvious!

yannisc’s picture

Ryan, do you consider adding this in the next commerce version? It is really usefull.

rszrama’s picture

If it gets ready in time. : )

farald’s picture

A big +1 to this, very useful for a multi-storekeeper environment to keep track of what actually happened to that order.

benjy’s picture

any news on this?

davidwhthomas’s picture

Status: Active » Needs review
StatusFileSize
new6.13 KB

@m.stenta thanks for the patch!

Here's an amended patch that fixes the relationship handler for revision_uid to users.uid.

This way you can show revision_uid user details, such as user name and email address.

Views assume the two field names in a relationship are the same, unless you specify a 'field' and perhaps also 'field_name' ( both added ) in the handler.

Patch attached.

Seems harmless to commit as works fine and adds integration for commerce_order_revision

cheers,

DT

davidwhthomas’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new16.97 KB

And here's an export of the view I created that lists the revisions for an order on the "Revisions" tab on the admin order ui pages.

After applying the order revisions views integration patch, you should be able to import this view to test.

May need to clear views cache first.

Requires permission "Administer orders"

cheers,

DT

davidwhthomas’s picture

StatusFileSize
new40.51 KB

Lastly a screenshot of the order "Revisions" view :-)

DT

farald’s picture

Status: Needs review » Reviewed & tested by the community

Great! Tested the patch in #16, no issues found. Works great!

helior’s picture

Made a few updates:
- Removed a bit of extra whitespace.
- Fixed commerce_order_revision.revision_id relationship definition. It had a relationship that pointed to the wrong field(commerce_order.order_id) which would have accidentally referenced completely different orders o_O. Should be commerce_order.revision_id. (Only the currently used revision will be able to relate to the order, which makes sense)
- Added a relationship via commerce_order_revision.order_id, that way any revision row will be able to reference back to the order entity. (unlike revision_id)

helior’s picture

Changed relationship from order_number to order_id since order numbers can actually change throughout the different states of the order.

davidwhthomas’s picture

Status: Needs review » Reviewed & tested by the community

@helior #21

Thanks for the adjusted patch, looks good!

Tested and working fine from here.

rszrama’s picture

Status: Reviewed & tested by the community » Needs work

If I'm reading the patch right, this still needs work. The order_number appears to be used in various places in this patch where I'd expect the order_id to be used, such as $data['commerce_order_revision']['table']['base']['field'] and $data['commerce_order_revision']['order_id']['argument']['name field']. Perhaps I'm misreading these, but the order_number should only be used in presentation, the order_id should be used in any sort of join or URL. The order_id is constant, but the order_number can change from revision to revision. It's like the SKU to a product; a merchant defined number for the order that may or may not correspond to the actual ID of the order entity. But for query building / data modeling, the order_id should be the standard.

Please let me know if I just misread the patch, as I don't have the whole Views API memorized. ; )

helior’s picture

Status: Needs work » Needs review
StatusFileSize
new6.93 KB

D'oh. Remnants from the original patch.. I remember we had a conversation about this, too!

deggertsen’s picture

Tested. Works great. The only thing I was wondering is if you can show past log messages as well as the most recent one?

joeysantiago’s picture

Sorry, i tried to apply the patch order-revision-views-integration-804850-24.patch, but get this error when trying to import the view:

git apply ~/Desktop/patches/order-revision-views-integration-804850-24.patch
Field handler commerce_order_revision.revision_id is not available.
    Field handler commerce_order_revision.revision_timestamp is not available.
    Field handler commerce_order_revision.order_number is not available.
    Field handler commerce_order_revision.status is not available.
    Field handler commerce_order_revision.log is not available.
    Contextual filter handler commerce_order_revision.order_id is not available.
    Relationship handler commerce_order_revision.revision_uid is not available.
    Field handler commerce_order_revision.revision_id is not available.
    Field handler commerce_order_revision.revision_timestamp is not available.
    Field handler commerce_order_revision.order_number is not available.
    Field handler commerce_order_revision.status is not available.
    Field handler commerce_order_revision.log is not available.
    Contextual filter handler commerce_order_revision.order_id is not available.
    Relationship handler commerce_order_revision.revision_uid is not available.
    Unable to import view.

could you help me out please?

aidanlis’s picture

@joeysantiago clear your cache

Patch and provided view seem to be working perfectly here.

vasike’s picture

Status: Needs review » Reviewed & tested by the community

tried the last one (#24) and all it looks just fine.

@rszrama, is there an issue about $data['commerce_order_revision']['order_id']['argument']['name field'] = 'order_number'?
as $data['commerce_order']['order_id']['argument']['name field'] has the same value 'order_number'?

@deggertsen for the question from #25: it should the number of items to display for the view/display. so please review the view pager settings, as the patch has no limitation.
actually it also could be some revisions without any log messages, as this data it's not editable at this moment and it's optional.
so maybe this could another feature for the module: Order Revision Log messages text input.

rszrama’s picture

Status: Reviewed & tested by the community » Needs work

That's not the only issue I see now that I've tried this out, actually. I'm not sure we should be making the join on the revision_id column here; it seems like we might actually need to make the join on the order_id column and have a separate "current revision" handler to join just to the current revision for its log message. This would make this relationship function similarly to the payment transaction relationship, where the normal relationship will provide a result in an Order View for each payment transaction joined with a separate relationship to pull a reference transaction from the table.

Additionally, in practice it looks like we need to update various titles and labels. I can do this for consistency's sake, but I'm open to other patchers to resolve the issue with the relationship itself if I can't get to it first.

emawk7’s picture

I'm hoping that someone can do this soon as I was working on a project for a client with UC and needed to do some complex pricing calculations and switched to DC when I read rszrama's recommendation. Audit trails are key for my client and I had shown him in the UC site and just assumed that DC would have it too. Now having invested so much time in the DC site, I can't turn back now :( I'll keep following this thread. rszrama, based on your last comment, are you suggesting that using this patch could cause problems in a site or just that the Audit Trail might not function as accurately/stably as you'd like?

emawk7’s picture

Just in case anyone else reads this post, I work alone and I don't use GIT, can someone tell me how I can apply this patch manually in an editor? Do I just remove all the "+" symbols and paste the code at the end of the inc file? This seems like additional code and not an overwrite. Thanks in advance.

muschpusch’s picture

@emawk: you don't need to "use" git. Just install it and: http://drupal.org/patch/apply

emawk7’s picture

Thanks muschpusch.

aidanlis’s picture

I've just upgraded to the latest -dev and I see this patch no longer applies. I'll take a closer look in the morning, but maybe someone knows what's going on already?

5n00py’s picture

I'm successfully applied last patch to the latest stable release.
It works fine for me, and i hope that in next stable reslease this patch (or better) will be included.

I'm building administrative interface and order revisions is vary useful for me.
But also we need to provide ctools context for order revisions.
I have the following structure:
admin/commerce/orders - default orders page
admin/commerce/orders/%order/revisions - view that using this patch ^_^
admin/commerce/orders/%order/revisions/%revision - This is missing for me now, i try to create page with page manager! But there is no context for revision_id.

I will make some review i create new issue about integrating order revisions in ctools...

5n00py’s picture

As i say in #35, i create an issue #1772172: Entity revision as argument and post patch for fixing issue.
Now it wait for review.

geek-merlin’s picture

@rszrama #29: totally agree.

re-rolled this with some fixups, see interdiff:
* added relation to hop from order to current revision and all revision
* removed relation to hop from revision to order by revision_id - this does not make sense. we still can hop by order_id
* removed implicit join in favor of explicit join

Minor:
* re-worded group name to be consistent with core revision fields
* re-worded title and labels to be consistent

I already have the order => all-revisions relation in use to get the checkout date,
effectively solving #1166540: add ability to get order checkout date and #1231360: Add "first completed" or "last completed" order date to commerce_order

joachim’s picture

Patch looks good, but AFAICT it doesn't cover what we'd need for #1166540: add ability to get order checkout date.

For that, you need to be able to hop from the order to a single revision *based on that revision's status*.

In other words, you need a custom relationship handler that implements a custom join like:

JOIN order_revision ON (id = id) AND order_revision.status = 'checkout_complete'.

Given how long this patch has been in the works, I'd be inclined to say we get this one in and then add to the views support in the other issue.

geek-merlin’s picture

@joachim #38:
i did get order checkout date with said relation order->revision and a filter on order revision state.
(this gets more complicated if our order receives a status several times but for "checkout completed" that's a rather pathological case.)

you want to test this patch and help make it rtbc?

miljance’s picture

Is it planned to integrate Product revisions with Views?

brunorios1’s picture

Hey @miljance,

i created a feature request to this: Integrate Product Revisions with Views

cvangysel’s picture

I changed some stuff that wasn't quite right in the previous patch and also added a default display that shows the revisions of an order.

You can also

  • show the latest log message by adding the Commerce Order: Latest Revision relationship and then adding the Commerce Order Revision: Log message field using that relationship
  • show the log message from a certain order state change by adding the Commerce Order Revision: Log message field (without using any relationship) and then filtering on the Commerce Order Revision: Order revision status field
wesleydv’s picture

@cvangysel your updates seem to work fine, I only changed the default sort order of the default views display to Revision ID.
This is because sorting by date can be very confusing when different updates happen in the same minute (e.g. review, checkout, complete ...).

Status: Needs review » Needs work

The last submitted patch, commerce-order_revision_views_integration-804850-43.patch, failed testing.

rcross’s picture

Status: Needs work » Needs review
jonathan_hunt’s picture

Status: Needs review » Needs work

This patch works for me, thanks. IMO, it needs one further tweak. In the default view provided, the label associated with the commerce_order_revision.mail field is "Revision user e-mail"

$handler->display->display_options['fields']['mail']['label'] = 'Revision user e-mail';

This implies the email is that of the user who made the revision. However, the column comment for commerce_order_revision.mail is "The e-mail address associated with the order at this revision." Perhaps a better label for the view field would be "Order e-mail".

rcross’s picture

I would agree. Here is a revised patch.

rcross’s picture

Status: Needs work » Needs review
brunorios1’s picture

Status: Needs review » Reviewed & tested by the community

looks ok to me

rszrama’s picture

Status: Reviewed & tested by the community » Fixed
StatusFileSize
new133.74 KB

Alrighty, folks. This patch was quite the dog pile - just named 8 people in the commit message, and that doesn't include all the reviewers. Thanks for the attention and feedback as it's developed!

I repackaged the relationship code joining the order table with its revision table to match what I just put in place for the product table to its revision table. The relationship is designed to join on the revision ID, so you don't end up with a result for each revision in a View joining from the order table to the revision table. I also changed the columns and labels in the default Revisions tab a bit. See the attached for the default look.

In keeping with the default product revision View, I changed the permission for this to administer orders. I also noticed the patch was trying to fix the issue of sorting on the default Orders admin View, but that's out of scope for this patch; removed it, will fix it in the related issue we have open to resolve that.

Commit: http://drupalcode.org/project/commerce.git/commitdiff/8570e45

Status: Fixed » Closed (fixed)

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