CRM-21764: Recurring Events without Price Set fail to save.
authorAlok Patel <alok@agileware.com.au>
Tue, 20 Mar 2018 03:41:11 +0000 (13:41 +1000)
committerAlok Patel <alok@agileware.com.au>
Thu, 22 Mar 2018 00:40:51 +0000 (10:40 +1000)
CRM/Core/BAO/RecurringEntity.php
CRM/Core/Page/AJAX/RecurringEntity.php

index 5915c74e438623967e606b27deee54f922975c1d..729d3f8ca59799181bde7ea7ef0c12496eed2ce1 100644 (file)
@@ -1214,21 +1214,37 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
       $dao->mode = $mode;
       $dao->save();
 
-      //CRM-20787 Fix
-      //I am not sure about other fields, if mode = 3 apply for an event then other fields
-      //should be save for all other series events or not so applying for price set only for now here.
-      if (CRM_Core_BAO_RecurringEntity::MODE_ALL_ENTITY_IN_SERIES === $mode) {
-
-        //Step-1: Get all events of series
-        $seriesEventRecords = CRM_Core_BAO_RecurringEntity::getEntitiesFor($entityId, $entityTable);
-        foreach ($seriesEventRecords as $event) {
-          //Step-3: Save price set in other series events
-          if (CRM_Price_BAO_PriceSet::removeFrom($event['table'], $event['id'])) {//Remove existing priceset
-            CRM_Core_BAO_Discount::del($event['id'], $event['table']);
+      if ($priceSet) {
+        //CRM-20787 Fix
+        //I am not sure about other fields, if mode = 3 apply for an event then other fields
+        //should be save for all other series events or not so applying for price set only for now here.
+        if (CRM_Core_BAO_RecurringEntity::MODE_ALL_ENTITY_IN_SERIES === $mode) {
+          //Step-1: Get all events of series
+          $seriesEventRecords = CRM_Core_BAO_RecurringEntity::getEntitiesFor($entityId, $entityTable);
+          foreach ($seriesEventRecords as $event) {
+            //Step-2: Save price set in other series events
+            if (CRM_Price_BAO_PriceSet::removeFrom($event['table'], $event['id'])) {//Remove existing priceset
+              CRM_Core_BAO_Discount::del($event['id'], $event['table']);
+            }
             CRM_Price_BAO_PriceSet::addTo($event['table'], $event['id'], $priceSet); //Add new price set
           }
         }
+
+        if (CRM_Core_BAO_RecurringEntity::MODE_NEXT_ALL_ENTITY === $mode) {
+          //Step-1: Get all events of series
+          $seriesEventRecords = CRM_Core_BAO_RecurringEntity::getEntitiesFor($entityId, $entityTable);
+          foreach ($seriesEventRecords as $event) {
+            //Step-2: Save price set in other series events
+            if ($entityId < $event["id"]) {
+              if (CRM_Price_BAO_PriceSet::removeFrom($event['table'], $event['id'])) {//Remove existing priceset
+                CRM_Core_BAO_Discount::del($event['id'], $event['table']);
+              }
+              CRM_Price_BAO_PriceSet::addTo($event['table'], $event['id'], $priceSet); //Add new price set
+            }
+          }
+        }
       }
+
       //CRM-20787 - Fix end
       $finalResult['status'] = 'Done';
     }
index 9fe6b84f713b93e7a4271ef14b45bee5812659c5..f091bf4795087f3ef5e33feadd7d0e85a7defbf8 100644 (file)
@@ -14,12 +14,21 @@ class CRM_Core_Page_AJAX_RecurringEntity {
 
   public static function updateMode() {
     $finalResult = array();
-    if (CRM_Utils_Array::value('mode', $_REQUEST) && CRM_Utils_Array::value('entityId', $_REQUEST) && CRM_Utils_Array::value('entityTable', $_REQUEST) && CRM_Utils_Array::value('priceSet', $_REQUEST)) {
-
+    if (CRM_Utils_Array::value('mode', $_REQUEST) && CRM_Utils_Array::value('entityId', $_REQUEST) && CRM_Utils_Array::value('entityTable', $_REQUEST)) {
       $mode = CRM_Utils_Type::escape($_REQUEST['mode'], 'Integer');
       $entityId = CRM_Utils_Type::escape($_REQUEST['entityId'], 'Integer');
       $entityTable = CRM_Utils_Type::escape($_REQUEST['entityTable'], 'String');
       $priceSet = CRM_Utils_Type::escape($_REQUEST['priceSet'], 'String');
+
+      // CRM-21764 fix
+      // Retrieving existing priceset if price set id is not passed
+      if ($priceSet == "") {
+        $priceSetEntity = new CRM_Price_DAO_PriceSetEntity();
+        $priceSetEntity->entity_id = $entityId;
+        $priceSetEntity->entity_table = $entityTable;
+        $priceSetEntity->find(TRUE);
+        $priceSet = $priceSetEntity->price_set_id;
+      }
       $linkedEntityTable = $_REQUEST['linkedEntityTable'];
       $finalResult = CRM_Core_BAO_RecurringEntity::updateModeAndPriceSet($entityId, $entityTable, $mode, $linkedEntityTable, $priceSet);
     }