Problem/Motivation

A error occurs when removing a donation from the card then visiting /donate again.

UnexpectedValueException: Order Items not properly initialized in Drupal\commerce_donation_flow\Plugin\Commerce\CheckoutPane\DonationItemPaneBase::create() (line 54 of modules/contrib/commerce_donation_flow/src/Plugin/Commerce/CheckoutPane/DonationItemPaneBase.php).

Steps to reproduce

  1. Log in (may happen as anonymous)
  2. Go to /donate and make a donation
  3. Go to /cart and remove the donation
  4. Go to /donate

The above error is returned.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

imclean created an issue. See original summary.

imclean’s picture

Trying to solve this problem results in an "access denied" message on the /donate page. I suspect this is because Commerce Donation Flow is using the same order ID for subsequent donations but there has already been a donation made, even if it has been removed from the cart.

imclean’s picture

Issue summary: View changes

imclean’s picture

Status: Active » Needs review

Creating a new order seems to get around the problem, but there's an error getting the form state values in DonationLevelWidget->massageFormValues().

fathershawn’s picture

This is a good use case to sort out. The client work that I'm abstracting this from for general contribution only had one active route /donate.

The `/donate` route is checkout flow focused only on donations. An order is created and the purchasable entity for the order is an OrderItem. The order id persists with this item until the donation is completed or until the cart session expires. We had some debate about this, but it allows a user to exit the donation flow and return to where they left off.

In your use case do you also have regular commerce sales going on in /cart?

imclean’s picture

Yes, we have other workflows and order items. This would happen even with just the donation workflow but is more obvious with other products.

imclean’s picture

Status: Needs review » Needs work

OK creating a new order is definitely not the right way to do it. What happens after I make a donation but don't complete the workflow, then create another donation, is that I end up with 2 carts. The original order should be updated or handled another way.

So there are 2 related issues which could be fixed here:

  1. Handle removing donations from the cart
  2. Handle visiting /donate when there is already a donation in the cart

For 2, I suggest simply disabling the form at /donate with a message stating the previous donation needs to be removed from the order first.

imclean’s picture

Status: Needs work » Needs review

This addresses point 1 only. If you remove the donation from the card the visit /donate again, then a new donation item will be added.

  • This takes into account the new method in dev: #3178281: Create helper method to addDonationItem
  • It removes checking if there are any items from the access check method
  • It recalculates totals a couple of extra times as Commerce's step checking process requires a total price

With point 2, visiting /donate when there is already a donation in the cart creates adds another donation to the cart. This may not be desirable.

imclean’s picture

With point 2, visiting /donate when there is already a donation in the cart creates adds another donation to the cart. This may not be desirable.

Actually that's not quite accurate. It only adds another donation if the current donation is the placeholder $0 donation. Once a donation has been selected it replaces the existing one which has a price.

In short, visiting /donate multiple times generates multiple $0 donations in the cart.

imclean’s picture

Fixes point 2 above and a resulting error regarding the currency code not being available.

Note: this is separate to this issue: #3211899: Use an enabled currency as the default currency

imclean’s picture

imclean’s picture

imclean’s picture

Merge requests can get a little confusing when there are multiple changes. All the changes are here: https://git.drupalcode.org/project/commerce_donation_flow/-/merge_reques...

fathershawn’s picture

There are numerous problems that stem from combining this module's flow and the traditional checkout flow in the same site. I've finally had time to return to work on this module and I've built a second checkout flow that extends the standard multistep flow. See the latest dev branch.

fathershawn’s picture

Version: 1.0.x-dev » 1.1.x-dev

Added guided configuration via a settings form at admin/commerce/config/donation-settings. Automated tests still needed.

  • FatherShawn committed 063f207a on 1.1.x
    Issue #3212238 by imclean, FatherShawn: Emptying cart causing an error...
fathershawn’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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