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.

CommentFileSizeAuthor
#3 interdiff-3091090-2-3.txt662 bytesl0ke
#3 3091090-3.patch2.58 KBl0ke
#2 3091090-2.patch2.61 KBl0ke

Issue fork basic_cart-3091090

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

l0ke created an issue. See original summary.

l0ke’s picture

Assigned: l0ke » Unassigned
Status: Active » Needs review
Issue tags: +DrupalCon Amsterdam 2019
StatusFileSize
new2.61 KB
l0ke’s picture

StatusFileSize
new2.58 KB
new662 bytes
br0ken’s picture

+++ b/src/Utility.php
@@ -473,4 +474,19 @@ class Utility extends Settings {
+    return empty($node->get('basic_cart_content')->getValue()) &&

Can we rely on isEmpty() method?

br0ken’s picture

Status: Needs review » Reviewed & tested by the community

Sorry, I was viewing the wrong patch.

rachel_norfolk’s picture

Issue tags: -DrupalCon Amsterdam 2019 +Amsterdam2019

retagging

karthikeyan-manivasagam’s picture

Status: Reviewed & tested by the community » Fixed

Thanks All for the contribution

Status: Fixed » Closed (fixed)

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

norman.lol’s picture

Version: 8.x-6.x-dev » 8.x-8.x-dev
Status: Closed (fixed) » Active

This issue resulted in all of the logic inside basic_cart_entity_presave being 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 in basic_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.

  • norman.lol committed adf34ee7 on 8.x-8.x
    #3091090 Skip presave hook if cart is empty to allow basic_cart_order...

norman.lol’s picture

Status: Active » Fixed

Okay, !empty(Utility::getCartData()) always is true no matter what.. but $cart_data['empty']['status'] === FALSE only is true when there's really stuff in the cart, so let's check on this instead.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • norman.lol committed 7166e718 on 8.x-8.x
    #3091090 Explicitly check if the empty status is FALSE

Status: Fixed » Closed (fixed)

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