Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CIVICRM-152 For a repeating Event series. If change the Price Set for… #10592

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CRM/Core/BAO/RecurringEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
19 changes: 19 additions & 0 deletions CRM/Core/Page/AJAX/RecurringEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,25 @@ public static function updateMode() {
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 {
Expand Down
19 changes: 19 additions & 0 deletions CRM/Price/BAO/PriceSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,25 @@ public static function addTo($entityTable, $entityId, $priceSetId) {
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.
*
Expand Down