Problem / motivation

If we follow recommended pane order (shipping before billing) as it has been written by Bojan here and here, we need to provide a shipping condition for orders. It will allow admins to set restrictions for payment method based on the selected shipping method. It is useful when some shipping methods require payment in cash and some others expect payment by bank transfer etc.

Background

Drupal commerce introduced payment condition as a result of the feature request Add an OrderPaymentGateway condition in version 8.x-2.6. It allows admins to set restriction for shipping method based on the selected payment method. In that case the problem is, that the billing method must be selected (and saved) before selecting shipping method, which is not in recommended order.

Solution

Provide a shipping condition for Order entity.
Set shipping pane before billing pane in the order checkout flow, set restriction on the page /admin/commerce/config/payment-gateways/manage/{method_id}, check the "Limit by shipping method" checkbox in the Order tab and select a required shipping methods.

Limit by shipping method

In the following patch I used the code from OrderPaymentGateway condition and adapted it for the shipping purposes.

Comments

martin_klima created an issue. See original summary.

martin_klima’s picture

Status: Active » Needs review
StatusFileSize
new4.25 KB
mirom’s picture

Status: Needs review » Reviewed & tested by the community

Works great

martin_klima’s picture

Issue summary: View changes
StatusFileSize
new13.21 KB
parisek’s picture

Working great

mglaman’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

There are no tests for this.

mellowtothemax’s picture

This works great thanks. In my case I needed a payment method of cash on delivery but only for one shipping method so I had to create a new custom checkout flow for payment method and moved the billing there.

mellowtothemax’s picture

The patches are not applying on latest commerce shipping rc2

mhawwari’s picture

Rerolled patch to work with the latest version.

mellowtothemax’s picture

#10 worked for me on rc2. Thank you.

oneICT’s picture

Hello,

Thank you, I was looking for this but I'm not sure how to define this.

In my case I have the option to "come and get the order" like a take-away or deliver the order.
In case of take-away we accept cash or online payment
In case of delivery we accept online payment only

What I have done so far:

  1. I made the sure the shipping is before the billing pane in the checkout flow
  2. in the payment gateway cash, I defined this option is only available in case of shipping method delivery
  3. in the payment gateway online, I defined this option is available in both take-away and delivery

After defining this I get the error:
There are no payment gateways available for this order. Please try again later.

When I remove the conditions on the payment gateways both payment options appear.
But online payment remains available although I selected to deliver the order...

Thing is that when switching between the delivery options nothing really happens.
I would expect a refresh or loading of options.
Like when choosing the payment options cash or online.

Any idea what I'm missing?

Kind regards,
Johnny

mellowtothemax’s picture

Unfortunately latest patch no longer works for current version.

primsi’s picture

Re-roll for the patch.

primsi’s picture

Status: Needs work » Needs review
StatusFileSize
new5.46 KB
new9.82 KB

Added tests and schema fixes.

Status: Needs review » Needs work

The last submitted patch, 15: provide_shipping_condition-2976252-15.patch, failed testing. View results

primsi’s picture

Status: Needs work » Needs review
StatusFileSize
new9.77 KB

Removing leftover debug screenshot.

berdir’s picture

Status: Needs review » Needs work
Issue tags: -Needs tests
+++ b/src/EventSubscriber/FilterConditionsEventSubscriber.php
@@ -0,0 +1,34 @@
+use Symfony\Component\EventDispatcher\EventSubscriberInterface;
+
+class FilterConditionsEventSubscriber implements EventSubscriberInterface {
+
+  /**

Missing class docblock.

Tests and so on look good to me, so removing that tag.

ekes’s picture

Status: Needs work » Needs review
StatusFileSize
new9.83 KB

Rerolled to apply to current dev.
Also added the class docblock.

jsacksick’s picture

Title: Provide billing by shipping condition » Provide a shipping method condition for orders

Retitling for clarity.

order_shipping is too generic as Commerce core provides an "order_shipping_address" condition.

We need to rename it to order_shipping_method.
Additionally, we should change the category to "Shipment" (instead of Shipping, to be consistent with what Commerce shipping is currently doing.

Also, to be consistent with what Commerce is doing in general, the condition needs to store the shipping method UUIDS (similar to the Store & customer conditions for example).

Will upload a patch that addresses these soon.

jsacksick’s picture

jsacksick’s picture

StatusFileSize
new10.64 KB

Better with the condition itself :).

Status: Needs review » Needs work

The last submitted patch, 22: 2976252-22.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

jsacksick’s picture

Status: Needs work » Needs review
StatusFileSize
new10.93 KB
jsacksick’s picture

We're probably also missing a unit test for the new condition, similar to what we have for other conditions provided by commerce_shipping.

  • jsacksick committed 4f69111 on 8.x-2.x
    Issue #2976252 by Primsi, jsacksick, martin_klima, mhawwari, dwkitchen,...
jsacksick’s picture

Status: Needs review » Fixed

Went ahead and committed the patch from #24.

Status: Fixed » Closed (fixed)

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