Reload submitted line items on re-submit of Main form
authoreileen <emcnaughton@wikimedia.org>
Mon, 1 Jan 2024 03:06:45 +0000 (16:06 +1300)
committereileen <emcnaughton@wikimedia.org>
Wed, 3 Jan 2024 23:41:40 +0000 (12:41 +1300)
CRM/Contribute/Form/Contribution/Main.php
CRM/Financial/BAO/Order.php

index b3120cf9132140782bb385e69bafe7fd2d772186..5f7851a2cf810a2ba89e2b7e2b528f7aaf2720fa 100644 (file)
@@ -1170,10 +1170,17 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu
 
   /**
    * Process the form submission.
+   *
+   * @throws \CRM_Core_Exception
    */
   public function postProcess() {
     // we first reset the confirm page so it accepts new values
     $this->controller->resetPage('Confirm');
+    // Update order to the submitted values (in case the back button has been used
+    // and the submitted values have changed.
+    $this->set('lineItem', NULL);
+    $this->order->setPriceSelectionFromUnfilteredInput($this->getSubmittedValues());
+    $this->order->recalculateLineItems();
 
     // get the submitted form values.
     $params = $this->controller->exportValues($this->_name);
index ec85b13fec0c9470fe371a95ecfd8d3ae296eccc..0230d46735153575a3a77da4e7c9bcc35e076bd1 100644 (file)
@@ -822,6 +822,17 @@ class CRM_Financial_BAO_Order {
     return $this->lineItems;
   }
 
+  /**
+   * Recalculate the line items.
+   *
+   * @return void
+   *
+   * @throws \CRM_Core_Exception
+   */
+  public function recalculateLineItems(): void {
+    $this->lineItems = $this->calculateLineItems();
+  }
+
   /**
    * Get line items in a 'traditional' indexing format.
    *