Ensure apiv3 params are converted at the line item level
authorEileen McNaughton <emcnaughton@wikimedia.org>
Tue, 28 Jun 2022 05:45:59 +0000 (17:45 +1200)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Tue, 28 Jun 2022 05:46:22 +0000 (17:46 +1200)
We switched to using apiv4 but at least one test seems to be passing in a string
at the line item level which is a bit weird but we should handle it

api/v3/Order.php

index 400bef6f1274c6d0cca95acf039026117b6d7f85..3b495b93a2376318e256a9bb2f4e5ccfe3b8e3b2 100644 (file)
@@ -94,6 +94,10 @@ function civicrm_api3_order_create(array $params): array {
         $order->setEntityParameters($lineItems['params'], $index);
       }
       foreach ($lineItems['line_item'] as $innerIndex => $lineItem) {
+        // For historical reasons it might be name.
+        if (!empty($lineItem['membership_type_id']) && !is_numeric($lineItem['membership_type_id'])) {
+          $lineItem['membership_type_id'] = CRM_Core_PseudoConstant::getKey('CRM_Member_BAO_Membership', 'membership_type_id', $lineItems['params']['membership_type_id']);
+        }
         $lineIndex = $index . '+' . $innerIndex;
         $order->setLineItem($lineItem, $lineIndex);
         $order->addLineItemToEntityParameters($lineIndex, $index);