Skip to content

Commit

Permalink
Merge pull request #21512 from JMAConsulting/core_2816_42
Browse files Browse the repository at this point in the history
dev/core#2816: New contribution can't be saved when validation fails …
  • Loading branch information
demeritcowboy authored Sep 17, 2021
2 parents aca729f + 3c7b2a1 commit b940460
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions CRM/Contribute/Form/AdditionalInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,16 @@ public static function processPremium($params, $contributionID, $premiumID = NUL
if (!empty($options[$selectedProductID])) {
$dao->product_option = $options[$selectedProductID][$selectedProductOptionID];
}
if ($premiumID) {

// This IF condition codeblock does the following:
// 1. If premium is present then get previous contribution-product mapping record (if any) based on contribtuion ID.
// If found and the product chosen doesn't matches with old done, then delete or else set the ID for update
// 2. If no product is chosen theb delete the previous contribution-product mapping record based on contribtuion ID.
if ($premiumID || empty($selectedProductID)) {
$ContributionProduct = new CRM_Contribute_DAO_ContributionProduct();
$ContributionProduct->id = $premiumID;
$ContributionProduct->contribution_id = $contributionID;
$ContributionProduct->find(TRUE);
// here $selectedProductID can be 0 in case one unselect the premium product on backoffice update form
if ($ContributionProduct->product_id == $selectedProductID) {
$dao->id = $premiumID;
}
Expand All @@ -203,7 +209,11 @@ public static function processPremium($params, $contributionID, $premiumID = NUL
}
}

$dao->save();
// only add/update contribution product when a product is selected
if (!empty($selectedProductID)) {
$dao->save();
}

//CRM-11106
if ($premiumID == NULL || $isDeleted) {
$premiumParams = [
Expand Down

0 comments on commit b940460

Please sign in to comment.