Basic cart order product fix

Small patch to fix product list in basic cart order:

diff --git a/basic_cart.module b/basic_cart.module
index d51edbe..1eb1f12 100755
--- a/basic_cart.module
+++ b/basic_cart.module
@@ -101,27 +101,20 @@ function basic_cart_form_alter(&$form, FormStateInterface $form_state, $form_id)
 function basic_cart_entity_presave(EntityInterface $node) {
   // Get the cart contents for a new orders unless order already has filled data
   // to allow programmatical creation of an order.
-  if (
-    $node->isNew() &&
-    Utility::isBasicCartOrder($node->bundle()) &&
-    Utility::isOrderEmpty($node)
-  ) {
+  if (Utility::isBasicCartOrder($node->bundle())) {
     $get_price = Utility::getTotalPrice();
     $cart = Utility::getCart();
-
-    $target_ids = [];
-    if (!empty($cart['cart_quantity'])) {
+    $content = $cart['cart'] ? $cart['cart'] : [];
+    if (empty($node->id())) {
+      $node->set('basic_cart_vat', $get_price->vat);
+      $node->set('basic_cart_total_price', $get_price->total);
+      $keys = array_keys($content);
+      $target_ids = [];
       foreach ($cart['cart_quantity'] as $key => $value) {
         $target_ids[] = ['target_id' => $key, 'quantity' => $value];
       }
+      $node->set('basic_cart_content', !empty($target_ids) ? $target_ids : $keys);
     }
-    elseif (!empty($cart['cart'])) {
-      $target_ids = array_keys($cart['cart']);
-    }
-
-    $node->set('basic_cart_vat', $get_price->vat);
-    $node->set('basic_cart_total_price', $get_price->total);
-    $node->set('basic_cart_content', $target_ids);
   }
 }

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.
The comment language code.