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
- Log in (may happen as anonymous)
- Go to
/donateand make a donation - Go to
/cartand remove the donation - Go to
/donate
The above error is returned.
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
Issue fork commerce_donation_flow-3212238
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
Comment #2
imclean commentedTrying 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.
Comment #3
imclean commentedComment #5
imclean commentedCreating a new order seems to get around the problem, but there's an error getting the form state values in
DonationLevelWidget->massageFormValues().Comment #6
fathershawnThis 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?Comment #7
imclean commentedYes, we have other workflows and order items. This would happen even with just the donation workflow but is more obvious with other products.
Comment #8
imclean commentedOK 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:
/donatewhen there is already a donation in the cartFor 2, I suggest simply disabling the form at
/donatewith a message stating the previous donation needs to be removed from the order first.Comment #9
imclean commentedThis addresses point 1 only. If you remove the donation from the card the visit
/donateagain, then a new donation item will be added.With point 2, visiting
/donatewhen there is already a donation in the cart creates adds another donation to the cart. This may not be desirable.Comment #10
imclean commentedActually 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
/donatemultiple times generates multiple $0 donations in the cart.Comment #11
imclean commentedFixes 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
Comment #12
imclean commentedComment #13
imclean commentedComment #14
imclean commentedMerge 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...
Comment #15
fathershawnThere 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.
Comment #16
fathershawnAdded guided configuration via a settings form at
admin/commerce/config/donation-settings. Automated tests still needed.Comment #18
fathershawn