Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Hi,
I'm giving a try to proposed submodule commerce_fee here and found that it was not possible to add a fee by payment gateway because a condition to filter by payment gateways was missing.
Proposed resolution
Added Drupal\commerce_payment\Plugin\Commerce\Condition OrderPaymentGateway
It works ok for me with Drupal 8.5.0 and Commerce 8.x-2.5
Remaining tasks
The only thing I think is not correct is that that condition is displayed on payment gateways condition settings too but did not found how to avoid it.
User interface changes
Find a new condition "Limit by payment gateway" under "Order" tab on conditions group.
Thanks!
Comment | File | Size | Author |
---|---|---|---|
#6 | commerce_payment-add-order-payment-gateway-condition-2953940-6.patch | 6.72 KB | jsacksick |
| |||
#3 | commerce-orderpaymentgateway-condition-2953940-3.patch | 2.38 KB | pslcbs |
|
Comments
Comment #2
pslcbs CreditAttribution: pslcbs commentedComment #3
pslcbs CreditAttribution: pslcbs commentedOoops, problem found and solved, sorry.
Comment #4
mglamanWe currently do not have a way for Commerce condition plugins to say "except this entity type." So I think we are fine by opening a follow up issue and it is just a slight UX bug for later.
We should also make a test for the condition.
Comment #5
bojanz CreditAttribution: bojanz at Centarro commentedWe actually do have that mechanism: https://github.com/drupalcommerce/commerce/blob/8.x-2.x/modules/promotio...
Setting "needs work" for that and tests.
Comment #6
jsacksick CreditAttribution: jsacksick at Centarro commentedI added a test, and the event subscriber for removing the condition on payment gateways, and slightly modified evaluate() on the condition.
Comment #7
mglamanYou have prophesize below, but mockbuilder here
Comment #8
bojanz CreditAttribution: bojanz at Centarro commentedWrapping this up.
We also need a schema entry such as the one order_store has:
Comment #10
bojanz CreditAttribution: bojanz at Centarro commentedAnd indeed, Prophecy can't mock magic methods. I switched to using ->get() in the condition itself, so that we don't need mockbuilder.
Comment #12
pslcbs CreditAttribution: pslcbs commentedHi,
Sorry but I think something is wrong on #6 because I was getting some errors related to some lines of code on that patch.
I was trying that features with the committed code on my use case (with commerce_fee) with D8.53 and Commerce 2.6 but I was getting a php error:
Drupal\Core\Entity\EntityStorageException: Unable to get a value with a non-numeric delta in a list. in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (line 829 of /public_html/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php)
As with patch on #3 it was working for me I was looking for code differences between patches and I found that on patch on #6 @jsacksick made some changes on #3 that were generating my trouble.
Changing it, my environment works again as it did.
On file /modules/payment/src/Plugin/Commerce/Condition/OrderPaymentGateway.php
The "wrong" code
The "good" code:
Moreover, I think the FilterConditionsEventSubscriber.php is not working correctly because I can see the filter "Limit by payment gateway" on commerce payment gateways settings in admin/commerce/config/payment-gateways page.
Comment #13
bojanz CreditAttribution: bojanz at Centarro commented@pslcbs
If you're reporting a bug, do it in a new issue.
This issue has been closed, and the described functionality has been released as a part of Commerce 2.6.
Neither of the mentioned patches are relevant anymore.
FWIW I don't see a "Limit by payment gateway" on admin/commerce/config/payment-gateways.