$priceFieldIds = $this->get('memberPriceFieldIDS');
if (!empty($priceFieldIds)) {
- $contributionTypeID = CRM_Core_DAO::getFieldValue( 'CRM_Price_DAO_Set', $priceFieldIds['id'], 'financial_type_id' );
+ $contributionTypeID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Set', $priceFieldIds['id'], 'financial_type_id');
unset($priceFieldIds['id']);
$membershipTypeIds = array();
$membershipTypeTerms = array();
}
}
$membershipParams['selectMembership'] = $membershipTypeIds;
- $membershipParams['financial_type_id'] = $contributionTypeID;
+ $membershipParams['financial_type_id'] = $contributionTypeID;
$membershipParams['types_terms'] = $membershipTypeTerms;
}
if (CRM_Utils_Array::value('selectMembership', $membershipParams)) {
+ // CRM-12233
+ if ($this->_separateMembershipPayment && $this->_values['amount_block_is_active']) {
+ foreach ($this->_values['fee'] as $key => $feeValues) {
+ if ($feeValues['name'] == 'membership_amount') {
+ $fieldId = $this->_params['price_' . $key];
+ $this->_memLineItem[$this->_priceSetId][$fieldId] = $this->_lineItem[$this->_priceSetId][$fieldId];
+ unset($this->_lineItem[$this->_priceSetId][$fieldId]);
+ break;
+ }
+ }
+ }
+
CRM_Member_BAO_Membership::postProcessMembership($membershipParams, $contactID,
$this, $premiumParams, $customFieldsFormatted,
$fieldTypes
);
- }
+ }
}
else {
// at this point we've created a contact and stored its address etc
}
$this->addFormRule(array('CRM_Contribute_Form_Contribution_Main', 'formRule'), $this);
-
}
/**
}
}
+ // CRM-12233
+ if ($membershipIsActive && !$self->_membershipBlock['is_required']
+ && $self->_values['amount_block_is_active']) {
+ $membershipFieldId = $contributionFieldId = $errorKey = $otherFieldId = NULL;
+ foreach ($self->_values['fee'] as $fieldKey => $fieldValue) {
+ if ($fieldValue['name'] == 'membership_amount' && CRM_Utils_Array::value('price_' . $fieldKey, $fields) == 0) {
+ $membershipFieldId = $fieldKey;
+ }
+ elseif ($membershipFieldId) {
+ if ($fieldValue['name'] == 'other_amount') {
+ $otherFieldId = $fieldKey;
+ }
+ elseif ($fieldValue['name'] == 'contribution_amount') {
+ $contributionFieldId = $fieldKey;
+ }
+
+ if (!$errorKey || CRM_Utils_Array::value('price_' . $contributionFieldId, $fields) == '0') {
+ $errorKey = $fieldKey;
+ }
+ }
+ }
+
+ if ($membershipFieldId && (!CRM_Utils_Array::value('price_' . $contributionFieldId, $fields)
+ && !CRM_Utils_Array::value('price_' . $otherFieldId, $fields))) {
+ $errors["price_{$errorKey}"] = ts('Additional Amount is required.');
+ }
+ }
if (empty($check)) {
if ($self->_useForMember == 1 && $membershipIsActive) {
$errors['_qf_default'] = ts('Select at least one option from Membership Type(s).');
}
}
- $fieldId = $memPresent = $membershipLabel = $fieldOption = $proceFieldAmount = NULL;
- if ($self->_separateMembershipPayment == 0 && $self->_quickConfig) {
- foreach ($self->_priceSet['fields'] as $fieldKey => $fieldVal) {
- if ($fieldVal['name'] == 'membership_amount' && CRM_Utils_Array::value('price_' . $fieldId, $fields)) {
- $fieldId = $fieldVal['id'];
- $fieldOption = $fields['price_' . $fieldId];
- $memPresent = TRUE;
- }
- else {
- if (CRM_Utils_Array::value('price_' . $fieldKey, $fields) && $memPresent && ($fieldVal['name'] == 'other_amount' || $fieldVal['name'] == 'contribution_amount')) {
- $fieldId = $fieldVal['id'];
- if ($fieldVal['name'] == 'other_amount') {
- $proceFieldAmount = $self->_submitValues['price_' . $fieldId];
- }
- else $proceFieldAmount = $fieldVal['options'][$self->_submitValues['price_' . $fieldId]]['amount'];
- unset($fields['price_' . $fieldId]);
- break;
- }
- }
- }
- }
-
CRM_Price_BAO_Set::processAmount($self->_values['fee'],
$fields, $lineItem
);
- if ($proceFieldAmount) {
- if ($proceFieldAmount < $lineItem[$fieldOption]['line_total']) {
- $errors["price_$fieldId"] = ts('The Membership you have selected requires a minimum contribution of %1',
- array(1 => CRM_Utils_Money::format($lineItem[$fieldOption]['line_total']))
- );
- }
- $fields['amount'] = $proceFieldAmount;
- }
+
if ($fields['amount'] < 0) {
$errors['_qf_default'] = ts('Contribution can not be less than zero. Please select the options accordingly');
}
}
//If the membership & contribution is used in contribution page & not seperate payment
- $fieldId = $memPresent = $membershipLabel = $fieldOption = $proceFieldAmount = $is_quick_config = NULL;
+ $fieldId = $memPresent = $membershipLabel = $fieldOption = $is_quick_config = NULL;
+ $proceFieldAmount = 0;
if ($this->_separateMembershipPayment == 0) {
$is_quick_config = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Set', $this->_priceSetId, 'is_quick_config');
if ($is_quick_config) {
foreach ($this->_priceSet['fields'] as $fieldKey => $fieldVal) {
- if ($fieldVal['name'] == 'membership_amount' && CRM_Utils_Array::value('price_' . $fieldId, $params)) {
+ if ($fieldVal['name'] == 'membership_amount' && CRM_Utils_Array::value('price_' . $fieldKey , $params)) {
$fieldId = $fieldVal['id'];
$fieldOption = $params['price_' . $fieldId];
+ $proceFieldAmount += $fieldVal['options'][$this->_submitValues['price_' . $fieldId]]['amount'];
$memPresent = TRUE;
}
else {
if (CRM_Utils_Array::value('price_' . $fieldKey, $params) && $memPresent && ($fieldVal['name'] == 'other_amount' || $fieldVal['name'] == 'contribution_amount')) {
$fieldId = $fieldVal['id'];
if ($fieldVal['name'] == 'other_amount') {
- $proceFieldAmount = $this->_submitValues['price_' . $fieldId];
+ $proceFieldAmount += $this->_submitValues['price_' . $fieldId];
}
else {
- $proceFieldAmount = $fieldVal['options'][$this->_submitValues['price_' . $fieldId]]['amount'];
+ $proceFieldAmount += $fieldVal['options'][$this->_submitValues['price_' . $fieldId]]['amount'];
}
unset($params['price_' . $fieldId]);
break;
}
}
$hasMembershipBlk = TRUE;
- if ($membershipBlock->is_separate_payment && !$fields['amount_block_is_active']) {
+ if ($membershipBlock->is_separate_payment && !CRM_Utils_Array::value('amount_block_is_active', $fields)) {
$errors['amount_block_is_active'] = ts('To disable Contribution Amounts section you need to first disable Separate Membership Payment option from Membership Settings.');
}
}
$memBlockDetails = CRM_Member_BAO_Membership::getMembershipBlock($form->_id);
if (CRM_Utils_Array::value('is_separate_payment', $memBlockDetails) && !$paymentDone) {
+ $form->_lineItem = $form->_memLineItem;
$contributionType = new CRM_Financial_DAO_FinancialType( );
$contributionType->id = CRM_Utils_Array::value('financial_type_id', $membershipDetails);
if (!$contributionType->find(TRUE)) {
CRM_Price_BAO_Field::retrieve($editedFieldParams, $editedResults);
if (!CRM_Utils_Array::value('id', $editedResults)) {
$fieldParams['name'] = strtolower(CRM_Utils_String::munge('Membership Amount', '_', 245));
- $fieldParams['label'] = CRM_Utils_Array::value('new_title', $params) ? $params['new_title'] : 'Membership Amount';
+ $fieldParams['label'] = CRM_Utils_Array::value('new_title', $params) ? $params['new_title'] : 'Membership';
if (!CRM_Utils_Array::value('mem_price_field_id', $params)) {
CRM_Utils_Weight::updateOtherWeights('CRM_Price_DAO_Field', 0, 1, array('price_set_id' => $priceSetID));
}
$currencyName = $config->defaultCurrency;
if (!isset($label)) {
- $label = (property_exists($qf,'_membershipBlock') && CRM_Utils_Array::value('is_separate_payment', $qf->_membershipBlock) && $field->name == 'contribution_amount' && !CRM_Utils_Array::value('is_allow_other_amount', $otherAmount)) ? ts('Additional Contribution') : $field->label;
+ $label = (property_exists($qf,'_membershipBlock') && $field->name == 'contribution_amount') ? ts('Additional Contribution') : $field->label;
}
if ($field->name == 'contribution_amount') {
}
// if seperate membership payment is used with quick config priceset then change the other amount label
- if (property_exists($qf,'_membershipBlock') && CRM_Utils_Array::value('is_separate_payment', $qf->_membershipBlock) && $qf->_quickConfig && $field->name == 'other_amount' && !property_exists($qf,'_contributionAmount')) {
+ if (property_exists($qf,'_membershipBlock') && $qf->_quickConfig && $field->name == 'other_amount' && !property_exists($qf,'_contributionAmount')) {
$label = ts('Additional Contribution');
$useRequired = 0;
}
$element = &$qf->addGroup($choice, $elementName, $label);
// make contribution field required for quick config when membership block is enabled
- if (($field->name == 'contribution_amount' || $field->name == 'membership_amount') && property_exists($qf, '_membershipBlock') && !empty($qf->_membershipBlock) && !$field->is_required) {
+ if (($field->name == 'membership_amount' || ($field->name == 'contribution_amount' && CRM_Utils_Array::value('is_separate_payment', $qf->_membershipBlock)))
+ && property_exists($qf, '_membershipBlock') && !empty($qf->_membershipBlock) && !$field->is_required) {
$useRequired = $field->is_required = TRUE;
}