From 9d0984ef84b2cb49fd4846b3354e09907017feea Mon Sep 17 00:00:00 2001 From: Monish Deb Date: Wed, 3 Feb 2021 04:59:34 +0530 Subject: [PATCH] Prevent loss of line-item when multiple price field has same name --- CRM/Lineitemedit/Util.php | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/CRM/Lineitemedit/Util.php b/CRM/Lineitemedit/Util.php index 7ecb894..73d490f 100644 --- a/CRM/Lineitemedit/Util.php +++ b/CRM/Lineitemedit/Util.php @@ -909,13 +909,20 @@ public static function buildLineItemRows(&$form, $contributionID = NULL) { } } else { - if ($rowNumber == 0) { - $priceFieldValue = civicrm_api3('PriceFieldValue', 'get', ['name' => 'contribution_amount']); - } - else { - $priceFieldValue = civicrm_api3('PriceFieldValue', 'get', ['name' => 'additional_item_' . $rowNumber]); - } - $form->setDefaults(["item_price_field_value_id[$rowNumber]" => $priceFieldValue['id']]); + $priceSetDetails = civicrm_api3('PriceSet', 'get', [ + 'sequential' => 1, + 'name' => "default_contribution_amount", + 'is_quick_config' => 1, + 'api.PriceField.get' => [ + 'sequential' => 1, + 'price_set_id' => "\$value.id", + 'api.PriceFieldValue.get' => [ + 'sequential' => 1, + 'price_field_id' => "\$value.id" + ], + ], + ]); + $form->setDefaults(["item_price_field_value_id[$rowNumber]" => $priceSetDetails['values'][0]['api.PriceField.get']['values'][$rowNumber]['api.PriceFieldValue.get']['id']]); } } }