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

dev/core#2816: New contribution can't be saved when validation fails … #21512

Merged
merged 1 commit into from
Sep 17, 2021
Merged
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
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is ok because the UI only supports one premium per contribution.

$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