Problem/Motivation
There is no possibility to set the contents of an order programmatically on creation it's getting overriden from a current cart storage.
The real-life example when you need it is a migration of historical data.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | interdiff-3091090-2-3.txt | 662 bytes | l0ke |
| #3 | 3091090-3.patch | 2.58 KB | l0ke |
| #2 | 3091090-2.patch | 2.61 KB | l0ke |
Issue fork basic_cart-3091090
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
l0keComment #3
l0keComment #4
br0kenCan we rely on
isEmpty()method?Comment #5
br0kenSorry, I was viewing the wrong patch.
Comment #6
rachel_norfolkretagging
Comment #8
karthikeyan-manivasagam commentedThanks All for the contribution
Comment #10
norman.lolThis issue resulted in all of the logic inside
basic_cart_entity_presavebeing skipped for everybody, see #3180430: Neither cart content, price or vat are stored in the newly 'order' node and #3214499: Empty Basic cart content.In the long run this needs to get refactored and all that logic removed from the presave hook.
But for now we could at least add a condition in the presave hook to check if
!empty(Utility::getCartData())$cart_data['empty']['status'] === FALSE, because when placing the order, the cart gets only emptied a few milliseconds later inbasic_cart_entity_insert. That way, the only thing you need to make sure when creating nodes programmatically is, that the user pressing the button to start the batch has their cart empty via an initial call to the$utility::emptyCart();method in the beginning.Comment #14
norman.lolOkay,
!empty(Utility::getCartData())always is true no matter what.. but$cart_data['empty']['status'] === FALSEonly is true when there's really stuff in the cart, so let's check on this instead.