Details
Description
An event has been setup with a discount set of fees. Everything appears fine on the website and the correct amount is shown in the payment gateway etc. However, on return to the confirm page a white screen and error occurs:
"Sorry but we are not able to provide this at the moment
is not of type String
Return to home page"
Looking at the error reports in depth I found the error starts at the confirm page (/CRM/Event/Form/Registration/Confirm.php) on this line:
CRM_Event_BAO_Participant::createDiscountTrxn($form->_eventId, $contribParams, CRM_Utils_Array::value('amount_priceset_level_radio', $params, NULL));
Printing out my $params shows me that 'amount_priceset_level_radio' is nowhere to be found, so I had a dig to see what would happen if NULL is used there.
The function createDiscountTrxn in '/CRM/Event/BAO/Participant.php' looks like this:
createDiscountTrxn($eventID, $contributionParams, $feeLevel)
So assuming $feeLevel is NULL it tries to do this:
$feeLevel = current($feeLevel);
$priceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $eventID, NULL);
$query = "SELECT cpfv.amount FROM `civicrm_price_field_value` cpfv
LEFT JOIN civicrm_price_field cpf ON cpfv.price_field_id = cpf.id
WHERE cpf.price_set_id = %1
AND cpfv.label LIKE %2";
$params = array(1 => array($priceSetId, 'Integer'), 2 => array($feeLevel, 'String'));
$mainAmount = CRM_Core_DAO::singleValueQuery($query, $params);
Looking at the SQL $feeLevel is actually the label for this particular price set option. If it's NULL it can't identify it exactly, but mainly it isn't of type String, hence the original error message.
Looking back at when we send $feeLevel over I have found the 'label' I would ideally use (and confirmed looking in the SQL tables) is in the variable $params['amount_level'] not 'amount_priceset_level_radio' as it tries to look.
I would like to suggest that the call to createDiscountTrxn is done in this manner instead:
CRM_Event_BAO_Participant::createDiscountTrxn($form->_eventId, $contribParams, CRM_Utils_Array::value('amount_level', $params, NULL));
I can't be sure of all the possible options here and if 'amount_level' is always going to work, but within the Confirm file the variable is used quite a few times so appears to be safe.