From a1bfea17587a462072f3dcfb37888afce7f93fc8 Mon Sep 17 00:00:00 2001 From: Alok Patel Date: Wed, 18 Oct 2017 14:48:49 +0530 Subject: [PATCH] CRM-20787: Passing price set value in AJAX call to modify the price set of repeating events. --- CRM/Core/Page/AJAX/RecurringEntity.php | 21 +++++++++---------- CRM/Price/BAO/PriceSet.php | 19 ----------------- .../Form/ManageEvent/ConfirmRepeatMode.tpl | 5 +++-- 3 files changed, 13 insertions(+), 32 deletions(-) diff --git a/CRM/Core/Page/AJAX/RecurringEntity.php b/CRM/Core/Page/AJAX/RecurringEntity.php index fb54792897..9c1f3e9f89 100644 --- a/CRM/Core/Page/AJAX/RecurringEntity.php +++ b/CRM/Core/Page/AJAX/RecurringEntity.php @@ -14,11 +14,12 @@ 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)) { + 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)) { $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'); if (!empty($_REQUEST['linkedEntityTable'])) { $result = CRM_Core_BAO_RecurringEntity::updateModeLinkedEntity($entityId, $_REQUEST['linkedEntityTable'], $entityTable); @@ -42,18 +43,16 @@ class CRM_Core_Page_AJAX_RecurringEntity { //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 Price set for parent event - $currentEventPriceSet = CRM_Price_BAO_PriceSet::getPriceSetOfEntity($entityTable, $entityId); - //Step-2: 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']); - CRM_Price_BAO_PriceSet::addTo($event['table'], $event['id'], $currentEventPriceSet['price_set_id']); //Add new price set - } + //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']); + CRM_Price_BAO_PriceSet::addTo($event['table'], $event['id'], $priceSet); //Add new price set } + } } //CRM-20787 - Fix end $finalResult['status'] = 'Done'; diff --git a/CRM/Price/BAO/PriceSet.php b/CRM/Price/BAO/PriceSet.php index 2bb62c9334..e1dabf5202 100644 --- a/CRM/Price/BAO/PriceSet.php +++ b/CRM/Price/BAO/PriceSet.php @@ -273,25 +273,6 @@ WHERE cpf.price_set_id = %1"; return $dao->save(); } - /** - * Get price set for the given entity and id. - * - * @param string $entityTable - * @param int $entityId - * - * @return mixed - */ - public static function getPriceSetOfEntity($entityTable, $entityId) { - $dao = new CRM_Price_DAO_PriceSetEntity(); - $dao->entity_id = $entityId; - $dao->entity_table = $entityTable; - if ($dao->find(TRUE)) { - $entities['table'] = $dao->entity_table; - $entities['id'] = $dao->entity_id; - $entities['price_set_id'] = $dao->price_set_id; - } - return $entities; - } /** * Delete price set for the given entity and id. * diff --git a/templates/CRM/Event/Form/ManageEvent/ConfirmRepeatMode.tpl b/templates/CRM/Event/Form/ManageEvent/ConfirmRepeatMode.tpl index 4b4e1a0c28..7eea07481b 100644 --- a/templates/CRM/Event/Form/ManageEvent/ConfirmRepeatMode.tpl +++ b/templates/CRM/Event/Form/ManageEvent/ConfirmRepeatMode.tpl @@ -89,10 +89,11 @@ function updateMode() { var mode = $('input[name=recur_mode]:checked', this).val(), entityID = parseInt('{/literal}{$entityID}{literal}'), - entityTable = '{/literal}{$entityTable}{literal}'; + entityTable = '{/literal}{$entityTable}{literal}', + priceSet = $('#price_set_id').val(); if (entityID != "" && mode && mapper.hasOwnProperty(formClass) && entityTable !="") { $.getJSON(CRM.url("civicrm/ajax/recurringentity/update-mode", - {mode: mode, entityId: entityID, entityTable: entityTable, linkedEntityTable: mapper[formClass]}) + {mode: mode, entityId: entityID, entityTable: entityTable, linkedEntityTable: mapper[formClass], priceSet: priceSet}) ).done(function (result) { if (result.status != "" && result.status == 'Done') { $form.submit(); -- 2.25.1