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

WIP ensure line items without price field id set doesn't cause problems #23087

Closed
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
16 changes: 11 additions & 5 deletions CRM/Financial/BAO/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -809,11 +809,17 @@ protected function calculateLineItems(): array {
// a template contribution.
$this->setLineItemCount(count($lineItems));

foreach ($lineItems as &$lineItem) {
// Set the price set id if not set above. Note that the above
// requires it for line retrieval but we want to fix that as it
// should not be required at that point.
$this->setPriceSetIDFromSelectedField($lineItem['price_field_id']);
foreach ($lineItems as $k => &$lineItem) {
if (empty($lineItem['price_field_id'])) {
$component = !empty($lineItem['membership_type_id']) ? 'membership' : 'contribution';
$this->setPriceSetToDefault($component);
}
else {
// Set the price set id if not set above. Note that the above
// requires it for line retrieval but we want to fix that as it
// should not be required at that point.
$this->setPriceSetIDFromSelectedField($lineItem['price_field_id']);
}
// Set any pre-calculation to zero as we will calculate.
$lineItem['tax_amount'] = 0;
if ($this->isOverrideLineItemFinancialType($lineItem['financial_type_id']) !== FALSE) {
Expand Down
31 changes: 31 additions & 0 deletions tests/phpunit/CRM/Contribute/BAO/ContributionRecurTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -732,4 +732,35 @@ public function testContributionEmailReceipt(): void {
$this->assertEquals('0', $recurring3Get['is_email_receipt']);
}

/**
* Test that a recurring contribution created without a price set id can be accessed.
*
* @throws \CRM_Core_Exception
*/
public function testRetrieveContributionWithoutPriceSetField(): void {
// Create a recurring contribution.
$contributionRecur = $this->callAPISuccess('contribution_recur', 'create', $this->_params);
// Add a contribution record to it.
$contribution = $this->callAPISuccess('Contribution', 'create', [
'contribution_recur_id' => $contributionRecur['id'],
'total_amount' => '3.00',
'financial_type_id' => 1,
'payment_instrument_id' => 1,
'currency' => 'USD',
'contact_id' => $this->individualCreate(),
'contribution_status_id' => 1,
'receive_date' => 'yesterday',
]);

// Delete the default price_field_id that is set for it.
$lineItems = \Civi\Api4\LineItem::update()
->setCheckPermissions(FALSE)
->addWhere('contribution_id', '=', $contribution['id'])
->addValue('price_field_id', NULL)
->execute();

// Ensure this missing price_field_id doesn't cause problems.
CRM_Contribute_BAO_ContributionRecur::getTemplateContribution($contributionRecur['id']);
}

}