I would like to create simple orders list with chosen payment method.

Problem: If customer goes through checkout process at once (without returning from checkout review and changing payment method) there would be only one payment method for an order, which is ok.

However, if customer returns from checkout page and changes payment method and then completes checkout - the order has 2 payment methods attached to it.

Now, inside view I can add relationship to Commerce Order: Payment Transaction, which causes duplicates. So I choose Commerce Order: Representative payment transaction, which gives me only one payment method (Now I can use payment method field). Inside relationship I can select representative sort criteria - in my case it would be transaction id (descending). However, sorting does not seem to work. The view always outputs the first payment method chosen when creating the order.

Is anything wrong with the view or is it better option to delete the unused payment transactions?

Question: what is the recommended way of keeping only one (last) payment method.

  • @Pierre.Vriens Hi, I have tried the module. In case of multiple payments connected to one order (which causes duplicate rows) I need to filter out the payments that have lower id. Only one should remain - with highest id (tha alst selected payment method). I do not think this module can accomplish this. Correct me if I am wrong.
    – loparr
    Commented Nov 29, 2016 at 20:20
  • @pierre I'm afraid distinct query would not necessarily show the right transaction... It sounds more like a kind of turn around when the solution should be found in Commerce implementation. Don't you think so? Good night
    – Kojo
    Commented Nov 29, 2016 at 20:26
  • 1
    @Kojo : it may be perceived as a workaround, but also like "sometimes the solutionn to a problem, is to prevent the problem from happening" ... Moreover, one could say "make it right (= get rid of the duplicates) before you make it better (= fix whatever causes the duplicates)". Commented Nov 29, 2016 at 20:34
  • @loparr : about that "highest id" that should remain, it's tough without to "guess" which option you'd hae to refine (with hardy any details about how your view looks like, eg no exported view in ,your question). However, here is another kind of guess: don't you have anything you can use to perform a "group by" in your view, so that only the one with the highest id (= max) remains? Commented Nov 29, 2016 at 20:37
  • @Pierre.Vriens I believe the view is described in my question. Simple order view with payment relationship. Once you try to display payment id along with its payment method - you get duplicates. (orders with more payment methods). Now I need to remove duplicates, showing only orders with its latest payment methods.
    – loparr
    Commented Nov 29, 2016 at 20:42

2 Answers 2


As per the "... which causes duplicates ..." in your question: you may be able to prevent those by using the Views Distinct module. From its project page:

Relationships or other joins in Views often create "duplicate" results. For example, a node with a field that has multiple values may show up in the View once per value in the multi-value field. It's frustrating, and the "DISTINCT" SQL query option in the Views UI does not actually solve the problem because the result row is technically distinct. This module aims to give a simple GUI method to remove or aggregate these "duplicate" rows.

Consider an example like so (with the duplicates included):

order id1 with payment id1
order id2 with payment id2
order id2 with payment id3
order id3 with payment id4

For this example, to only show the last payment method, sort by payment id (but descending!), and on the order_id filter repeats. So that only the last row for every order_id will be shown.

The new Views results with these changes applied for the above example should now look like so (with no more the duplicates related to payment id2):

order id1 with payment id1
order id2 with payment id3
order id3 with payment id4
  • Hi, this actually works. The views distinct module did the trick along with sorting based on payment id (this was the important part). I just added sorting based on order id on top, so orders appear naturally from oldest to newest.
    – loparr
    Commented Dec 1, 2016 at 16:48
  • Merci for the "accept" @loparr ... in the end, but better late then never, right? Commented Dec 1, 2016 at 18:59
  • @Kojo I truly appreciate your help - after all you were rewarded 25pts. However, I asked for a general solution and your solution did not help because you came with assumption that I use same/similar modules as you are. I think the question was clear and there is no need to filter out which payment has which status.
    – loparr
    Commented Dec 1, 2016 at 19:26

You need to use Relationship: Commerce Order: Payment Transaction in relationships section, and require that relationship.

Then add the filter (Transaction) Commerce Payment Transaction: Status (<> Failure) or its reverse logic is one of "SUCCESS". Don't forget to add relationship to transaction for the filter

Commerce Payment Transaction filter

Last, no need to add "distinct" in the query if you don't have other stuff causing duplicates. I have such views working great in production sites.

Update: I searched my setup a bit but there's no "custom rule". I believe it depends on payment methods. Which means that if yours don't implement "failure" status, you need to create a custom rule. Anyway the strange in your config is that a transaction that was not followed until checkout complete is attached to the order! This is not logical and doesn't work so on my config.

  • 1
    Hi,Thank you. The problem here is that all payments have status "pending" after user completes checkout. (in case that available payment methods are: bank transfer and cod)
    – loparr
    Commented Nov 29, 2016 at 18:46
  • MIght be, but if sbody abandons a payment and choose another, the first one will have Failure status
    – Kojo
    Commented Nov 29, 2016 at 18:48
  • 1
    Hi, this does not happen on my dev site. I can select a payment method (bank transfer), continue to review order page. Next hit "go back" button and select another payment (cod) and finish the order. I can see that now 2 payments are referenced to the order and both are active (pending).
    – loparr
    Commented Nov 29, 2016 at 19:04
  • Well I've checked both on dev & prod sites, and it doesn't happen on mine. check payment and order rules. Sounds like a bug or misconfiguration somewhere. Tomorrow I'm not there, can't help you. Let us know was was succeeding.
    – Kojo
    Commented Nov 29, 2016 at 19:37
  • Hi, I upvoted. However on fresh commerce install I can not find any rule that would change current payment status to failure, if a new payment is created for that order. The intention of commerce creators was to have the ability for multiple active payment methods for one order. So I think this must be some custom rule you have going on. If you can look it up that would be great.
    – loparr
    Commented Nov 29, 2016 at 20:11

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.