From 7dc99ab66e58cee85b41e2efba6501b9bc171709 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Sun, 19 Feb 2023 12:17:49 +1300 Subject: [PATCH] Php8.2 test fix, remove one instance on undeclared parameter --- .../CRM/Event/Form/ParticipantTest.php | 91 +++++++++---------- .../CRM/Financial/Form/PaymentFormsTest.php | 12 ++- tests/phpunit/CiviTest/CiviUnitTestCase.php | 44 ++++----- 3 files changed, 70 insertions(+), 77 deletions(-) diff --git a/tests/phpunit/CRM/Event/Form/ParticipantTest.php b/tests/phpunit/CRM/Event/Form/ParticipantTest.php index 498c8bf3d9..c75195df22 100644 --- a/tests/phpunit/CRM/Event/Form/ParticipantTest.php +++ b/tests/phpunit/CRM/Event/Form/ParticipantTest.php @@ -11,6 +11,8 @@ use Civi\Api4\Participant; class CRM_Event_Form_ParticipantTest extends CiviUnitTestCase { use CRMTraits_Financial_OrderTrait; + use CRMTraits_Financial_PriceSetTrait; + /** * Options on the from Email address array. * @@ -19,7 +21,7 @@ class CRM_Event_Form_ParticipantTest extends CiviUnitTestCase { protected $fromEmailAddressOptions = []; public function setUp(): void { - $this->useTransaction(TRUE); + $this->useTransaction(); parent::setUp(); } @@ -44,7 +46,7 @@ class CRM_Event_Form_ParticipantTest extends CiviUnitTestCase { * * @throws \Exception */ - public function testSubmitUnpaidPriceChangeWhileStillPending() { + public function testSubmitUnpaidPriceChangeWhileStillPending(): void { $form = $this->getForm(['is_monetary' => 1, 'financial_type_id' => 1]); $form->_quickConfig = TRUE; @@ -72,13 +74,13 @@ class CRM_Event_Form_ParticipantTest extends CiviUnitTestCase { ], ]; $form->setAction(CRM_Core_Action::ADD); - $form->_priceSetId = $this->getPriceSetID(); + $form->_priceSetId = $this->getPriceSetID('event'); $form->submit([ 'register_date' => date('Ymd'), 'status_id' => 5, 'role_id' => 1, 'event_id' => $form->_eventId, - 'priceSetId' => $this->getPriceSetID(), + 'priceSetId' => $this->getPriceSetID('event'), $this->getPriceFieldKey() => $this->_ids['price_field_value'][0], 'is_pay_later' => 1, 'amount_level' => 'Too much', @@ -106,12 +108,14 @@ class CRM_Event_Form_ParticipantTest extends CiviUnitTestCase { } $this->assertEquals(55, $sum); - CRM_Price_BAO_LineItem::changeFeeSelections($priceSetParams, $participant['id'], 'participant', $contribution['id'], $this->eventFeeBlock, $lineItem); + $priceSetID = $this->ids['PriceSet']['event']; + $eventFeeBlock = CRM_Price_BAO_PriceSet::getSetDetail($priceSetID)[$priceSetID]['fields']; + CRM_Price_BAO_LineItem::changeFeeSelections($priceSetParams, $participant['id'], 'participant', $contribution['id'], $eventFeeBlock, $lineItem); // Check that no payment records have been created. - // In https://lab.civicrm.org/dev/financial/issues/94 we had an issue where payments were created when none happend. + // In https://lab.civicrm.org/dev/financial/issues/94 we had an issue where payments were created when none happened. $payments = $this->callAPISuccess('Payment', 'get', [])['values']; $this->assertCount(0, $payments); - $lineItem = CRM_Price_BAO_LineItem::getLineItems($participant['id'], 'participant'); + $lineItem = CRM_Price_BAO_LineItem::getLineItems($participant['id']); // Participants is updated to 0 but line remains. $this->assertEquals(0, $lineItem[1]['subTotal']); $this->assertEquals(1550.55, $lineItem[2]['subTotal']); @@ -138,13 +142,13 @@ class CRM_Event_Form_ParticipantTest extends CiviUnitTestCase { // 5. Record the additional amount which $40 ($50-$10) // Expected : Check the amount of new Financial Item created is $40 $this->createParticipantRecordsFromTwoFieldPriceSet(); - $priceSetBlock = CRM_Price_BAO_PriceSet::getSetDetail($this->getPriceSetID(), TRUE, FALSE)[$this->getPriceSetID()]['fields']; + $priceSetBlock = CRM_Price_BAO_PriceSet::getSetDetail($this->getPriceSetID('event'), TRUE, FALSE)[$this->getPriceSetID('event')]['fields']; $priceSetParams = [ - 'priceSetId' => $this->getPriceSetID(), + 'priceSetId' => $this->getPriceSetID('event'), // The 1 & 5 refer to qty as they are text fields. - 'price_' . $this->_ids['price_field']['first_text_field'] => 5, - 'price_' . $this->_ids['price_field']['second_text_field'] => 1, + 'price_' . $this->ids['PriceField']['first_text_field'] => 5, + 'price_' . $this->ids['PriceField']['second_text_field'] => 1, ]; $participant = $this->callAPISuccess('Participant', 'get', []); $lineItem = CRM_Price_BAO_LineItem::getLineItems($participant['id'], 'participant'); @@ -185,7 +189,7 @@ class CRM_Event_Form_ParticipantTest extends CiviUnitTestCase { * * @throws \Exception */ - public function testSubmitWithPayment($thousandSeparator) { + public function testSubmitWithPayment(string $thousandSeparator): void { $this->setCurrencySeparators($thousandSeparator); $form = $this->getForm(['is_monetary' => 1, 'financial_type_id' => 1]); $form->_mode = 'Live'; @@ -207,7 +211,7 @@ class CRM_Event_Form_ParticipantTest extends CiviUnitTestCase { 'unit_price' => 1550.55, 'line_total' => 1550.55, 'participant_count' => 0, - 'price_field_id' => $this->_ids['price_field'][0], + 'price_field_id' => $this->getPriceFieldID(), 'price_field_value_id' => $this->_ids['price_field_value'][1], 'tax_amount' => 0, // Interestingly the financial_type_id set in this test is ignored but currently locking in what is happening with this test so setting to 'actual' @@ -228,7 +232,7 @@ class CRM_Event_Form_ParticipantTest extends CiviUnitTestCase { * * @throws \Exception */ - public function testSubmitWithFailedPayment($thousandSeparator, $fromEmails = []) { + public function testSubmitWithFailedPayment(string $thousandSeparator, $fromEmails = []) { $this->setCurrencySeparators($thousandSeparator); $form = $this->getForm(['is_monetary' => 1, 'financial_type_id' => 1]); $form->_mode = 'Live'; @@ -380,7 +384,7 @@ class CRM_Event_Form_ParticipantTest extends CiviUnitTestCase { * * @throws \CRM_Core_Exception */ - protected function createParticipantRecordsFromTwoFieldPriceSet() { + protected function createParticipantRecordsFromTwoFieldPriceSet(): void { // Create financial type - Event Fee 2 $form = $this->getForm(['is_monetary' => 1, 'financial_type_id' => 1]); @@ -393,7 +397,7 @@ class CRM_Event_Form_ParticipantTest extends CiviUnitTestCase { 'option_amount' => ['1' => $fieldToCreate['amount']], 'option_weight' => ['1' => $fieldToCreate['amount']], 'is_display_amounts' => 1, - 'price_set_id' => $this->_ids['price_set'], + 'price_set_id' => $this->getPriceSetID('event'), 'is_enter_qty' => 1, 'html_type' => 'Text', 'financial_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'financial_type_id', 'Campaign Contribution'), @@ -401,15 +405,15 @@ class CRM_Event_Form_ParticipantTest extends CiviUnitTestCase { $fieldParams['label'] = $fieldToCreate['label']; $fieldParams['name'] = CRM_Utils_String::titleToVar($fieldToCreate['label']); $fieldParams['price'] = $fieldToCreate['amount']; - $this->_ids['price_field'][strtolower(CRM_Utils_String::titleToVar($fieldToCreate['label']))] = $textPriceFieldID = $this->callAPISuccess('PriceField', 'create', $fieldParams)['id']; - $this->_ids['price_field_value'][strtolower(CRM_Utils_String::titleToVar($fieldToCreate['label']))] = (int) $this->callAPISuccess('PriceFieldValue', 'getsingle', ['price_field_id' => $textPriceFieldID])['id']; + $this->ids['PriceField'][strtolower($fieldParams['name'])] = $textPriceFieldID = $this->callAPISuccess('PriceField', 'create', $fieldParams)['id']; + $this->ids['PriceFieldValue'][strtolower($fieldParams['name'])] = (int) $this->callAPISuccess('PriceFieldValue', 'getsingle', ['price_field_id' => $textPriceFieldID])['id']; } $form->_lineItem = [ 0 => [ 13 => [ - 'price_field_id' => $this->_ids['price_field']['second_text_field'], - 'price_field_value_id' => $this->_ids['price_field_value']['second_text_field'], + 'price_field_id' => $this->ids['PriceField']['second_text_field'], + 'price_field_value_id' => $this->ids['PriceFieldValue']['second_text_field'], 'label' => 'Event Fee 1', 'field_title' => 'Event Fee 1', 'description' => NULL, @@ -427,8 +431,8 @@ class CRM_Event_Form_ParticipantTest extends CiviUnitTestCase { 'non_deductible_amount' => '0.00', ], 14 => [ - 'price_field_id' => $this->_ids['price_field']['first_text_field'], - 'price_field_value_id' => $this->_ids['price_field_value']['first_text_field'], + 'price_field_id' => $this->ids['PriceField']['first_text_field'], + 'price_field_value_id' => $this->ids['PriceFieldValue']['first_text_field'], 'label' => 'Event Fee 2', 'field_title' => 'Event Fee 2', 'description' => NULL, @@ -448,7 +452,7 @@ class CRM_Event_Form_ParticipantTest extends CiviUnitTestCase { ], ]; $form->setAction(CRM_Core_Action::ADD); - $form->_priceSetId = $this->_ids['price_set']; + $form->_priceSetId = $this->getPriceSetID('event'); $form->submit([ 'register_date' => date('Ymd'), @@ -456,9 +460,9 @@ class CRM_Event_Form_ParticipantTest extends CiviUnitTestCase { 'status_id' => 5, 'role_id' => 1, 'event_id' => $this->getEventID(), - 'priceSetId' => $this->_ids['price_set'], - 'price_' . $this->_ids['price_field']['first_text_field'] => [$this->_ids['price_field_value']['first_text_field'] => 1], - 'price_' . $this->_ids['price_field']['second_text_field'] => [$this->_ids['price_field_value']['second_text_field'] => 1], + 'priceSetId' => $this->getPriceSetID('event'), + 'price_' . $this->ids['PriceField']['first_text_field'] => [$this->ids['PriceFieldValue']['first_text_field'] => 1], + 'price_' . $this->ids['PriceField']['second_text_field'] => [$this->ids['PriceFieldValue']['second_text_field'] => 1], 'amount_level' => 'Too much', 'fee_amount' => 65, 'total_amount' => 65, @@ -499,7 +503,7 @@ class CRM_Event_Form_ParticipantTest extends CiviUnitTestCase { 'billing_postal_code-5' => 10545, 'billing_country_id-5' => 1228, 'payment_processor_id' => $paymentProcessorID, - 'priceSetId' => $this->getPriceSetID(), + 'priceSetId' => $this->getPriceSetID('event'), $this->getPriceFieldKey() => $this->getPriceFieldValueID(), 'amount_level' => 'Too much', 'fee_amount' => $this->formatMoneyInput(1550.55), @@ -526,7 +530,7 @@ class CRM_Event_Form_ParticipantTest extends CiviUnitTestCase { 'status_id' => 1, 'role_id' => 1, $this->getPriceFieldKey() => $this->getPriceFieldValueID(), - 'priceSetId' => $this->getPriceSetID(), + 'priceSetId' => $this->getPriceSetID('event'), 'event_id' => $this->getEventID(), 'record_contribution' => TRUE, 'amount_level' => 'blah', @@ -553,12 +557,12 @@ class CRM_Event_Form_ParticipantTest extends CiviUnitTestCase { public function testSubmitPartialPayment($isQuickConfig) { $mut = new CiviMailUtils($this, TRUE); $form = $this->getForm(['is_monetary' => 1]); - $this->callAPISuccess('PriceSet', 'create', ['is_quick_config' => $isQuickConfig, 'id' => $this->getPriceSetID()]); + $this->callAPISuccess('PriceSet', 'create', ['is_quick_config' => $isQuickConfig, 'id' => $this->getPriceSetID('event')]); $paymentInstrumentID = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'payment_instrument_id', 'Check'); $submitParams = [ 'hidden_feeblock' => '1', 'hidden_eventFullMsg' => '', - 'priceSetId' => $this->getPriceSetID(), + 'priceSetId' => $this->getPriceSetID('event'), $this->getPriceFieldKey() => $this->getPriceFieldValueID(), 'check_number' => '879', 'record_contribution' => '1', @@ -599,10 +603,10 @@ class CRM_Event_Form_ParticipantTest extends CiviUnitTestCase { * * @throws \CRM_Core_Exception */ - public function testSubmitPendingPartiallyPaidAddPayment($isQuickConfig) { + public function testSubmitPendingPartiallyPaidAddPayment(bool $isQuickConfig): void { $mut = new CiviMailUtils($this, TRUE); $form = $this->getForm(['is_monetary' => 1]); - $this->callAPISuccess('PriceSet', 'create', ['is_quick_config' => $isQuickConfig, 'id' => $this->getPriceSetID()]); + $this->callAPISuccess('PriceSet', 'create', ['is_quick_config' => $isQuickConfig, 'id' => $this->getPriceSetID('event')]); $paymentInstrumentID = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'payment_instrument_id', 'Check'); $submitParams = $this->getRecordContributionParams('Partially paid', $form); $form->submit($submitParams); @@ -626,10 +630,10 @@ class CRM_Event_Form_ParticipantTest extends CiviUnitTestCase { * * @throws \CRM_Core_Exception */ - public function testSubmitPendingAddPayment($isQuickConfig) { + public function testSubmitPendingAddPayment($isQuickConfig): void { $mut = new CiviMailUtils($this, TRUE); $form = $this->getForm(['is_monetary' => 1]); - $this->callAPISuccess('PriceSet', 'create', ['is_quick_config' => $isQuickConfig, 'id' => $this->getPriceSetID()]); + $this->callAPISuccess('PriceSet', 'create', ['is_quick_config' => $isQuickConfig, 'id' => $this->getPriceSetID('event')]); $paymentInstrumentID = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'payment_instrument_id', 'Check'); $submitParams = $this->getRecordContributionParams('Pending from pay later', 'Pending'); // Create the pending contribution for the full amount to be paid. @@ -650,7 +654,7 @@ class CRM_Event_Form_ParticipantTest extends CiviUnitTestCase { * @param bool $isAmountPaidOnForm * Was the amount paid entered on the form (if so this should be on the receipt) */ - protected function assertPartialPaymentResult($isQuickConfig, CiviMailUtils $mut, $isAmountPaidOnForm = TRUE) { + protected function assertPartialPaymentResult(bool $isQuickConfig, CiviMailUtils $mut, $isAmountPaidOnForm = TRUE): void { $paymentInstrumentID = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'payment_instrument_id', 'Check'); $contribution = $this->callAPISuccessGetSingle('Contribution', []); $expected = [ @@ -740,22 +744,13 @@ class CRM_Event_Form_ParticipantTest extends CiviUnitTestCase { ]); } - /** - * Get the id of the configured price set. - * - * @return int - */ - protected function getPriceSetID() { - return (int) $this->_ids['price_set']; - } - /** * Get the price field id that has been created for the test. * * @return int */ - protected function getPriceFieldID() { - return (int) $this->_ids['price_field'][0]; + protected function getPriceFieldID(): int { + return (int) reset($this->ids['PriceField']); } /** @@ -784,11 +779,11 @@ class CRM_Event_Form_ParticipantTest extends CiviUnitTestCase { * * @return array */ - protected function getRecordContributionParams($participantStatus, $contributionStatus): array { + protected function getRecordContributionParams(string $participantStatus, $contributionStatus): array { $submitParams = [ 'hidden_feeblock' => '1', 'hidden_eventFullMsg' => '', - 'priceSetId' => $this->getPriceSetID(), + 'priceSetId' => $this->getPriceSetID('event'), $this->getPriceFieldKey() => $this->getPriceFieldValueID(), 'check_number' => '879', 'record_contribution' => '1', diff --git a/tests/phpunit/CRM/Financial/Form/PaymentFormsTest.php b/tests/phpunit/CRM/Financial/Form/PaymentFormsTest.php index fde69818b4..61ea1420e5 100644 --- a/tests/phpunit/CRM/Financial/Form/PaymentFormsTest.php +++ b/tests/phpunit/CRM/Financial/Form/PaymentFormsTest.php @@ -9,13 +9,15 @@ +--------------------------------------------------------------------+ */ +use Civi\Api4\Participant; + /** * Test various payment forms. * * This class is intended to be a place to build out testing of various forms - with the * hope being to ensure all payment forms are consistently tested and to refine * helper functions into a trait that could be available to - * extensions for testing - notably the eventcart which ideally should interact with core + * extensions for testing - notably the event cart which ideally should interact with core * through approved interfaces - ideally even in tests. * * An approved interface would sit in the Civi directory and would at minimum support some functions @@ -24,7 +26,7 @@ * - allowing us to easily check payment forms work with the core processors which cover a reasonable amount of the * expectations held by non-core processors . * - * Note that this tests eventcart but is not in eventcart because I want to be sure about whether the + * Note that this tests event cart but is not in event cart because I want to be sure about whether the * traits supporting it make sense before making them available to extensions. */ class CRM_Financial_Form_PaymentFormsTest extends CiviUnitTestCase { @@ -36,7 +38,7 @@ class CRM_Financial_Form_PaymentFormsTest extends CiviUnitTestCase { * * @throws \CRM_Core_Exception */ - public function testEventPaymentForms() { + public function testEventPaymentForms(): void { $this->createAuthorizeNetProcessor(); $processors = [$this->ids['PaymentProcessor']['anet']]; $eventID = $this->eventCreatePaid([ @@ -52,7 +54,7 @@ class CRM_Financial_Form_PaymentFormsTest extends CiviUnitTestCase { 'controller' => [], 'submitValues' => [ 'event' => [$eventID => ['participant' => [1 => ['email' => 'bob@example.com']]]], - 'event_' . $eventID . '_price_' . $this->_ids['price_field'][0] => $this->_ids['price_field_value'][0], + 'event_' . $eventID . '_price_' . $this->ids['PriceField']['event_radio'] => $this->ids['PriceFieldValue']['price_field'], ], 'REQUEST' => [], ], @@ -92,7 +94,7 @@ class CRM_Financial_Form_PaymentFormsTest extends CiviUnitTestCase { $qfKey = $form->controller->_key; } } - $participant = \Civi\Api4\Participant::get(FALSE) + $participant = Participant::get(FALSE) ->addWhere('status_id:name', '=', 'Registered') ->execute() ->first(); diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index f4cf1bdb35..8a80dc2e1e 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -37,6 +37,7 @@ use Civi\Api4\LineItem; use Civi\Api4\MembershipType; use Civi\Api4\OptionGroup; use Civi\Api4\Phone; +use Civi\Api4\PriceSet; use Civi\Api4\RelationshipType; use Civi\Payment\System; use Civi\Api4\OptionValue; @@ -805,7 +806,7 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase { * @return int * Id Payment Processor */ - public function processorCreate($params = []) { + public function processorCreate($params = []): int { $processorParams = [ 'domain_id' => 1, 'name' => 'Dummy', @@ -834,9 +835,9 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase { * @return \CRM_Core_Payment_Dummy * Instance of Dummy Payment Processor * - * @throws \CRM_Core_Exception + * @noinspection PhpIncompatibleReturnTypeInspection */ - public function dummyProcessorCreate($processorParams = []) { + public function dummyProcessorCreate(array $processorParams = []): CRM_Core_Payment_Dummy { $paymentProcessorID = $this->processorCreate($processorParams); $this->ids['PaymentProcessor']['dummy_test'] = $paymentProcessorID; // For the tests we don't need a live processor, but as core ALWAYS creates a processor in live mode and one in test mode we do need to create both @@ -1072,10 +1073,8 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase { * Index for storing event ID in ids array. * * @return array - * - * @throws \CRM_Core_Exception */ - protected function eventCreatePaid(array $params, array $options = [['name' => 'hundy', 'amount' => 100]], $key = 'event'): array { + protected function eventCreatePaid(array $params = [], array $options = [['name' => 'hundred', 'amount' => 100]], $key = 'event'): array { // @todo - uncomment these - but need to fix an e-notice first. // $this->dummyProcessorCreate(); // $params['payment_processor'] = [$this->ids['PaymentProcessor']['dummy_live']]; @@ -1089,9 +1088,6 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase { $this->ids['Event'][$key] = (int) $event['id']; $this->ids['PriceSet'][$key] = $this->eventPriceSetCreate(55, 0, 'Radio', $options); CRM_Price_BAO_PriceSet::addTo('civicrm_event', $event['id'], $this->ids['PriceSet'][$key]); - $priceSet = CRM_Price_BAO_PriceSet::getSetDetail($this->ids['PriceSet'][$key], TRUE, FALSE); - $priceSet = $priceSet[$this->ids['PriceSet'][$key]] ?? NULL; - $this->eventFeeBlock = $priceSet['fields'] ?? NULL; return $event; } @@ -2520,22 +2516,20 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase { * * @return int * Price Set ID. - * @throws \CRM_Core_Exception + * @noinspection PhpUnhandledExceptionInspection */ - protected function eventPriceSetCreate($feeTotal, $minAmt = 0, $type = 'Text', $options = [['name' => 'hundy', 'amount' => 100]]) { - // creating price set, price field + protected function eventPriceSetCreate($feeTotal, $minAmt = 0, string $type = 'Text', array $options = [['name' => 'hundred', 'amount' => 100]]): int { $paramsSet['title'] = 'Price Set'; - $paramsSet['name'] = CRM_Utils_String::titleToVar('Price Set'); + $paramsSet['name'] = 'price_set'; $paramsSet['is_active'] = FALSE; $paramsSet['extends'] = 1; $paramsSet['min_amount'] = $minAmt; - $priceSet = CRM_Price_BAO_PriceSet::create($paramsSet); - $this->_ids['price_set'] = $priceSet->id; + $priceSetID = PriceSet::create()->setValues($paramsSet)->execute()->first()['id']; $paramsField = [ 'label' => 'Price Field', - 'name' => CRM_Utils_String::titleToVar('Price Field'), + 'name' => 'price_field', 'html_type' => $type, 'price' => $feeTotal, 'option_label' => ['1' => 'Price Field'], @@ -2547,7 +2541,7 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase { 'weight' => 1, 'options_per_line' => 1, 'is_active' => ['1' => 1], - 'price_set_id' => $this->_ids['price_set'], + 'price_set_id' => $priceSetID, 'is_enter_qty' => 1, 'financial_type_id' => $this->getFinancialTypeId('Event Fee'), ]; @@ -2560,13 +2554,15 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase { } } - $this->callAPISuccess('PriceField', 'create', $paramsField); - $fields = $this->callAPISuccess('PriceField', 'get', ['price_set_id' => $this->_ids['price_set']]); - $this->_ids['price_field'] = array_keys($fields['values']); - $fieldValues = $this->callAPISuccess('PriceFieldValue', 'get', ['price_field_id' => $this->_ids['price_field'][0]]); - $this->_ids['price_field_value'] = array_keys($fieldValues['values']); - - return $this->_ids['price_set']; + $priceFieldID = $this->callAPISuccess('PriceField', 'create', $paramsField)['id']; + $this->ids['PriceField']['event_' . strtolower($type)] = $priceFieldID; + $this->_ids['price_field'] = [$priceFieldID]; + $fieldValues = $this->callAPISuccess('PriceFieldValue', 'get', ['price_field_id' => $priceFieldID])['values']; + foreach ($fieldValues as $priceFieldValue) { + $this->ids['PriceFieldValue'][strtolower($priceFieldValue['name'])] = $priceFieldValue['id']; + } + $this->_ids['price_field_value'] = array_keys($fieldValues); + return $priceSetID; } /** -- 2.25.1