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;
}
}
}
- $dao->save();
+ // only add/update contribution product when a product is selected
+ if (!empty($selectedProductID)) {
+ $dao->save();
+ }
+
//CRM-11106
if ($premiumID == NULL || $isDeleted) {
$premiumParams = [
[$sendReceipt] = CRM_Core_BAO_MessageTemplate::sendTemplate(
[
- 'groupName' => 'msg_tpl_workflow_contribution',
- 'valueName' => 'contribution_offline_receipt',
+ 'workflow' => 'contribution_offline_receipt',
'contactId' => $params['contact_id'],
'contributionId' => $params['contribution_id'],
+ 'tokenContext' => ['contributionId' => (int) $params['contribution_id'], 'contactId' => $params['contact_id']],
'from' => $params['from_email_address'],
'toName' => $contributorDisplayName,
'toEmail' => $contributorEmail,
- 'isTest' => $form->_mode == 'test',
+ 'isTest' => $form->_mode === 'test',
'PDFFilename' => ts('receipt') . '.pdf',
'isEmailPdf' => Civi::settings()->get('invoice_is_email_pdf'),
]