From cb063506a83147a2de40f2e6da69248e28ee4114 Mon Sep 17 00:00:00 2001 From: Kurund Jalmi Date: Fri, 17 Jul 2015 16:20:22 +0530 Subject: [PATCH] allow setting of price set value via url for online membership pages --- CRM/Price/BAO/PriceSet.php | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/CRM/Price/BAO/PriceSet.php b/CRM/Price/BAO/PriceSet.php index e79e9bdad5..c7acad678b 100644 --- a/CRM/Price/BAO/PriceSet.php +++ b/CRM/Price/BAO/PriceSet.php @@ -1041,12 +1041,28 @@ WHERE id = %1"; foreach ($form->_priceSet['fields'] as $key => $val) { foreach ($val['options'] as $keys => $values) { - if ($values['is_default']) { + // build price field index which is passed via URL + // url format will be appended by "&price_5=11" + $priceFieldName = 'price_' . $values['price_field_id']; + $priceFieldValue = self::getPriceFieldValueFromURL($form, $priceFieldName); + if (!empty($priceFieldValue)) { if ($val['html_type'] == 'CheckBox') { - $defaults["price_{$key}"][$keys] = 1; + $defaults[$priceFieldName][$priceFieldValue] = 1; } else { - $defaults["price_{$key}"] = $keys; + $defaults[$priceFieldName] = $priceFieldValue; + } + + // break here to prevent overwriting of default due to 'is_default' + // option configuration. The value sent via URL get's higher priority. + break; + } + elseif ($values['is_default']) { + if ($val['html_type'] == 'CheckBox') { + $defaults[$priceFieldName][$keys] = 1; + } + else { + $defaults[$priceFieldName] = $keys; } } } @@ -1054,6 +1070,21 @@ WHERE id = %1"; return $defaults; } + /** + * Get the value of price field if passed via url + * + * @param CRM_Core_Form $form + * @param string $priceFieldName + * + * @return mixed $priceFieldValue + */ + public static function getPriceFieldValueFromURL(&$form, $priceFieldName) { + $priceFieldValue = CRM_Utils_Request::retrieve($priceFieldName, 'String', $form, FALSE, NULL, 'GET'); + if (!empty($priceFieldValue)) { + return $priceFieldValue; + } + } + /** * Supports event create function by setting up required price sets, not tested but expect * it will work for contribution page -- 2.25.1