$params['membership_id'] = $membership->id;
if (isset($ids['membership'])) {
$ids['contribution'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipPayment',
- $ids['membership'],
+ $membership->id,
'contribution_id',
'membership_id'
);
* @param CRM_Core_Form $qf
* @param array $membershipType
* Array with membership type and organization.
- * @param int $priceSetId
*
+ * @return int $priceSetId
*/
- public static function createLineItems(&$qf, $membershipType, &$priceSetId) {
+ public static function createLineItems(&$qf, $membershipType) {
$qf->_priceSetId = $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', 'default_membership_type_amount', 'id', 'name');
- if ($priceSetId) {
- $qf->_priceSet = $priceSets = current(CRM_Price_BAO_PriceSet::getSetDetail($priceSetId));
- }
+ $qf->_priceSet = $priceSets = current(CRM_Price_BAO_PriceSet::getSetDetail($priceSetId));
+
+ // The name of the price field corresponds to the membership_type organization contact.
$editedFieldParams = array(
'price_set_id' => $priceSetId,
'name' => $membershipType[0],
$fieldID = key($qf->_priceSet['fields']);
$qf->_params['price_' . $fieldID] = CRM_Utils_Array::value('id', $editedResults);
+ return $priceSetId;
}
/**
$lineItems = $this->_lineItem;
}
+ if ($this->_id) {
+ $ids['membership'] = $params['id'] = $this->_id;
+ }
+ $ids['userId'] = CRM_Core_Session::singleton()->get('userID');
+
// Set variables that we normally get from context.
// In form mode these are set in preProcess.
//TODO: set memberships, fixme
}
// process price set and get total amount and line items.
- $lineItem = array();
- $isQuickConfig = 0;
+ if (!$priceSetID) {
+ $priceSetID = CRM_Member_BAO_Membership::createLineItems(
+ $this,
+ $formValues['membership_type_id'],
+ NULL
+ );
+ }
+ $isQuickConfig = FALSE;
+ if (CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $priceSetID, 'is_quick_config')) {
+ $isQuickConfig = 1;
+ }
$termsByType = array();
- if ($priceSetID) {
- CRM_Member_BAO_Membership::createLineItems($this, $formValues['membership_type_id'], $priceSetID);
-
- if (CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $priceSetID, 'is_quick_config')) {
- $isQuickConfig = 1;
- }
- CRM_Price_BAO_PriceSet::processAmount($this->_priceSet['fields'],
- $this->_params, $lineItem[$priceSetID]);
- if (CRM_Utils_Array::value('tax_amount', $this->_params)) {
- $params['tax_amount'] = $this->_params['tax_amount'];
- }
- $params['total_amount'] = CRM_Utils_Array::value('amount', $this->_params);
- $submittedFinancialType = CRM_Utils_Array::value('financial_type_id', $formValues);
- if (!empty($lineItem[$priceSetID])) {
- foreach ($lineItem[$priceSetID] as &$li) {
- if (!empty($li['membership_type_id'])) {
- if (!empty($li['membership_num_terms'])) {
- $termsByType[$li['membership_type_id']] = $li['membership_num_terms'];
- }
+ $lineItem = array();
+ CRM_Price_BAO_PriceSet::processAmount($this->_priceSet['fields'],
+ $this->_params, $lineItem[$priceSetID]);
+ if (CRM_Utils_Array::value('tax_amount', $this->_params)) {
+ $params['tax_amount'] = $this->_params['tax_amount'];
+ }
+ $params['total_amount'] = CRM_Utils_Array::value('amount', $this->_params);
+ $submittedFinancialType = CRM_Utils_Array::value('financial_type_id', $formValues);
+ if (!empty($lineItem[$priceSetID])) {
+ foreach ($lineItem[$priceSetID] as &$li) {
+ if (!empty($li['membership_type_id'])) {
+ if (!empty($li['membership_num_terms'])) {
+ $termsByType[$li['membership_type_id']] = $li['membership_num_terms'];
}
+ }
- ///CRM-11529 for quick config backoffice transactions
- //when financial_type_id is passed in form, update the
- //lineitems with the financial type selected in form
- if ($isQuickConfig && $submittedFinancialType) {
- $li['financial_type_id'] = $submittedFinancialType;
- }
+ ///CRM-11529 for quick config backoffice transactions
+ //when financial_type_id is passed in form, update the
+ //lineitems with the financial type selected in form
+ if ($isQuickConfig && $submittedFinancialType) {
+ $li['financial_type_id'] = $submittedFinancialType;
}
}
}
if (array_key_exists('max_related', $formValues)) {
$membershipTypeValues[$memType]['max_related'] = CRM_Utils_Array::value('max_related', $formValues);
}
- }
-
- if ($this->_id) {
- $ids['membership'] = $params['id'] = $this->_id;
- }
-
- $ids['userId'] = CRM_Core_Session::singleton()->get('userID');
-
- // membership type custom data
- foreach ($this->_memTypeSelected as $memType) {
$membershipTypeValues[$memType]['custom'] = CRM_Core_BAO_CustomField::postProcess($formValues,
$this->_id,
'Membership'
);
- }
-
- foreach ($this->_memTypeSelected as $memType) {
$membershipTypes[$memType] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType',
$memType
);
//create line items
$lineItem = array();
- $priceSetId = NULL;
- CRM_Member_BAO_Membership::createLineItems($this, $formValues['membership_type_id'], $priceSetId);
+
+ $priceSetId = CRM_Member_BAO_Membership::createLineItems($this, $formValues['membership_type_id']);
CRM_Price_BAO_PriceSet::processAmount($this->_priceSet['fields'],
$this->_params, $lineItem[$priceSetId]
);
* @return array
* array reference of all membership types if any
*/
- public static function &membershipType($id = NULL, $force = FALSE) {
+ public static function membershipType($id = NULL, $force = TRUE) {
if (!self::$membershipType || $force) {
CRM_Core_PseudoConstant::populate(self::$membershipType,
'CRM_Member_DAO_MembershipType',
$params['name']['api.required'] = 1;
$params['duration_unit']['api.required'] = 1;
$params['duration_interval']['api.required'] = 1;
+ $params['is_active']['api.default'] = 1;
}
/**
protected $_ids = array();
protected $_paymentProcessorID;
+ /**
+ * Membership type ID for annual fixed membership.
+ *
+ * @var int
+ */
+ protected $membershipTypeAnnualFixedID;
+
/**
* Parameters to create payment processor.
*
dirname(__FILE__) . '/dataset/data.xml'
)
);
+ $membershipTypeAnnualFixed = $this->callAPISuccess('membership_type', 'create', array(
+ 'domain_id' => 1,
+ 'name' => "AnnualFixed",
+ 'member_of_contact_id' => 23,
+ 'duration_unit' => "year",
+ 'duration_interval' => 1,
+ 'period_type' => "fixed",
+ 'fixed_period_start_day' => "101",
+ 'fixed_period_rollover_day' => "1231",
+ 'relationship_type_id' => 20,
+ 'financial_type_id' => 2,
+ ));
+ $this->membershipTypeAnnualFixedID = $membershipTypeAnnualFixed['id'];
$instruments = $this->callAPISuccess('contribution', 'getoptions', array('field' => 'payment_instrument_id'));
$this->paymentInstruments = $instruments['values'];
$files = array();
$obj = new CRM_Member_Form_Membership();
$rc = $obj->formRule($params, $files, $obj);
- $this->assertType('array', $rc,
- 'In line ' . __LINE__
- );
- $this->assertTrue(array_key_exists('end_date', $rc),
- 'In line ' . __LINE__
- );
+ $this->assertType('array', $rc);
+ $this->assertTrue(array_key_exists('end_date', $rc));
}
/**
$files = array();
$obj = new CRM_Member_Form_Membership();
$rc = $obj->formRule($params, $files, $obj);
- $this->assertType('array', $rc,
- 'In line ' . __LINE__
- );
- $this->assertTrue(array_key_exists('start_date', $rc),
- 'In line ' . __LINE__
- );
+ $this->assertType('array', $rc);
+ $this->assertTrue(array_key_exists('start_date', $rc));
}
/**
* Test the submit function of the membership form.
*/
public function testSubmit() {
- $form = new CRM_Member_Form_Membership();
+ $form = $this->getForm();
+ $form->_mode = 'test';
$this->createLoggedInUser();
$params = array(
'cid' => $this->_individualId,
'join_date' => date('m/d/Y', time()),
'start_date' => '',
'end_date' => '',
- // This format reflects the 1 being the organisation & the 25 being the type.
- 'membership_type_id' => array(1, 25),
+ // This format reflects the 23 being the organisation & the 25 being the type.
+ 'membership_type_id' => array(23, $this->membershipTypeAnnualFixedID),
'auto_renew' => '0',
'max_related' => '',
'num_terms' => '1',
'cvv2' => '123',
'credit_card_exp_date' => array(
'M' => '9',
- 'Y' => '2019', // TODO: Future proof
+ 'Y' => '2024', // TODO: Future proof
),
'credit_card_type' => 'Visa',
'billing_first_name' => 'Test',
'billing_country_id-5' => '1228',
);
$form->submit($params);
- $this->callAPISuccessGetCount('Membership', array('contact_id' => $this->_individualId), 1);
+ $membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId));
+ $this->callAPISuccessGetCount('ContributionRecur', array('contact_id' => $this->_individualId), 0);
+ $contribution = $this->callAPISuccess('Contribution', 'get', array(
+ 'contact_id' => $this->_individualId,
+ 'is_test' => TRUE,
+ ));
+
+ $this->callAPISuccessGetCount('LineItem', array(
+ 'entity_id' => $membership['id'],
+ 'entity_table' => 'civicrm_membership',
+ 'contribution_id' => $contribution['id'],
+ ), 1);
}
/**
$form = $this->getForm();
$this->callAPISuccess('MembershipType', 'create', array(
- 'id' => 25,
+ 'id' => $this->membershipTypeAnnualFixedID,
'duration_unit' => 'month',
'duration_interval' => 1,
'auto_renew' => TRUE,
'start_date' => '',
'end_date' => '',
'campaign_id' => '',
- // This format reflects the 1 being the organisation & the 25 being the type.
- 'membership_type_id' => array(1, 25),
+ // This format reflects the 23 being the organisation & the 25 being the type.
+ 'membership_type_id' => array(23, $this->membershipTypeAnnualFixedID),
'auto_renew' => '1',
'is_recur' => 1,
'max_related' => 0,
relationship_type_id="20"
financial_type_id="2"
/>
- <civicrm_membership_type
- id="20"
- domain_id="1"
- name="AnnualFixed"
- member_of_contact_id="23"
- duration_unit="year"
- duration_interval="1"
- period_type="fixed"
- fixed_period_start_day="101"
- fixed_period_rollover_day="1231"
- relationship_type_id="20"
- financial_type_id="2"
- />
<civicrm_membership_type
id="25"
domain_id="1"