/** * Determine if recurring parameters need to be added to the form parameters. * * - is_recur * - frequency_interval * - frequency_unit * * For membership this is based on the membership type. * * This needs to be done before processing the pre-approval redirect where relevant on the main page or before any payment processing. * * Arguably the form should start to build $this->_params in the pre-process main page & use that array consistently throughout. */ protected function setRecurringMembershipParams() { $selectedMembershipTypeID = CRM_Utils_Array::value('selectMembership', $this->_params); if ($selectedMembershipTypeID) { // @todo the price_x fields will ALWAYS allow us to determine the membership - so we should ignore // 'selectMembership' and calculate from the price_x fields so we have one method that always works // this is lazy & only catches when selectMembership is set, but the worst of all worlds would be to fix // this with an else (calculate for price set). $membershipTypes = CRM_Price_BAO_PriceSet::getMembershipTypesFromPriceSet($this->_priceSetId); if (in_array($selectedMembershipTypeID, $membershipTypes['autorenew_required']) || in_array($selectedMembershipTypeID, $membershipTypes['autorenew_optional']) && !empty($this->_params['is_recur'])) { $this->_params['auto_renew'] = TRUE; } } if ((!empty($this->_params['selectMembership']) || !empty($this->_params['priceSetId'])) && !empty($this->_paymentProcessor['is_recur']) && CRM_Utils_Array::value('auto_renew', $this->_params) && empty($this->_params['is_recur']) && empty($this->_params['frequency_interval'])) { $this->_params['is_recur'] = $this->_values['is_recur'] = 1; // check if price set is not quick config if (!empty($this->_params['priceSetId']) && !CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_params['priceSetId'], 'is_quick_config')) { list($this->_params['frequency_interval'], $this->_params['frequency_unit']) = CRM_Price_BAO_PriceSet::getRecurDetails($this->_params['priceSetId']); } else { // FIXME: set interval and unit based on selected membership type $this->_params['frequency_interval'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_params['selectMembership'], 'duration_interval'); $this->_params['frequency_unit'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_params['selectMembership'], 'duration_unit'); } } }