From b0f2e06f68c595e19e7128a78a9d0ea6f2331e5b Mon Sep 17 00:00:00 2001 From: Rupal Javiya Date: Mon, 3 Jul 2017 01:35:58 +0530 Subject: [PATCH] CRM-20787: CIVICRM-152 For a repeating Event series. If change the Price Set for a paid Event then this Price Set selection is not applied to all Events in the series even when apply to Every Event is selected - Added Code for apply same priceset for paid series events --- CRM/Core/BAO/RecurringEntity.php | 5 +++++ CRM/Core/Page/AJAX/RecurringEntity.php | 19 +++++++++++++++++++ CRM/Price/BAO/PriceSet.php | 19 +++++++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/CRM/Core/BAO/RecurringEntity.php b/CRM/Core/BAO/RecurringEntity.php index ebd496c808..2e4dd2471c 100644 --- a/CRM/Core/BAO/RecurringEntity.php +++ b/CRM/Core/BAO/RecurringEntity.php @@ -126,6 +126,11 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity { ), ); + //Define global CLASS CONSTANTS for recurring entity mode types + const MODE_THIS_ENTITY_ONLY = 1; + const MODE_NEXT_ALL_ENTITY = 2; + const MODE_ALL_ENTITY_IN_SERIES = 3; + /** * Getter for status. * diff --git a/CRM/Core/Page/AJAX/RecurringEntity.php b/CRM/Core/Page/AJAX/RecurringEntity.php index 7265eeda26..fb54792897 100644 --- a/CRM/Core/Page/AJAX/RecurringEntity.php +++ b/CRM/Core/Page/AJAX/RecurringEntity.php @@ -37,6 +37,25 @@ class CRM_Core_Page_AJAX_RecurringEntity { if ($dao->find(TRUE)) { $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 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 + } + } + } + //CRM-20787 - Fix end $finalResult['status'] = 'Done'; } else { diff --git a/CRM/Price/BAO/PriceSet.php b/CRM/Price/BAO/PriceSet.php index e1dabf5202..2bb62c9334 100644 --- a/CRM/Price/BAO/PriceSet.php +++ b/CRM/Price/BAO/PriceSet.php @@ -273,6 +273,25 @@ 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. * -- 2.25.1