CRM-15787 - Not possible to add contribution field in profile for on behalf membership
authoratif-shaikh <shaikh388@gmail.com>
Fri, 9 Jan 2015 08:04:45 +0000 (13:34 +0530)
committeratif-shaikh <shaikh388@gmail.com>
Fri, 9 Jan 2015 08:04:45 +0000 (13:34 +0530)
https://issues.civicrm.org/jira/browse/CRM-15787

CRM/Contribute/Form/Contribution/Main.php
CRM/Contribute/Form/ContributionPage/Settings.php

index 365009a07863eb5b1c6bef2e82da8cf32abdfd4f..2dada275a7fdbc5f9c333c7ba032f80b08f1f5e2 100644 (file)
@@ -138,7 +138,9 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu
     }
 
     //CRM-5001
-    if (!empty($this->_values['is_for_organization'])) {
+    //CRM-15787
+    $member = CRM_Member_BAO_Membership::getMembershipBlock($this->_id);
+    if (!empty($this->_values['is_for_organization']) && empty($member['is_active'])) {
       $msg = ts('Mixed profile not allowed for on behalf of registration/sign up.');
       $ufJoinParams = array(
         'module' => 'onBehalf',
index 0298e8bce3c4190064e0bd73972c099761105deb..8a8fa5f8f0dc5be53ff8d8246ff2a49f39e90a25 100644 (file)
@@ -144,15 +144,25 @@ class CRM_Contribute_Form_ContributionPage_Settings extends CRM_Contribute_Form_
     // is on behalf of an organization ?
     $this->addElement('checkbox', 'is_organization', ts('Allow individuals to contribute and / or signup for membership on behalf of an organization?'), NULL, array('onclick' => "showHideByValue('is_organization',true,'for_org_text','table-row','radio',false);showHideByValue('is_organization',true,'for_org_option','table-row','radio',false);"));
 
-    $allowCoreTypes = array_merge(array('Contact', 'Organization'), CRM_Contact_BAO_ContactType::subTypes('Organization'));
-    $allowSubTypes = array();
-    $entities = array(
-      array(
-        'entity_name' => 'contact_1',
-        'entity_type' => 'OrganizationModel',
-      ),
+    //CRM-15787 - If applicable, register 'membership_1'
+    $member = CRM_Member_BAO_Membership::getMembershipBlock($this->_id);
+    $allowMemberCoreTypes = '';
+
+    $entities[] = array(
+      'entity_name' => array ('contact_1'),
+      'entity_type' => 'OrganizationModel',
     );
 
+    if ($member && $member['is_active']) {
+      $allowMemberCoreTypes = 'Membership';
+      $entities[] = array(
+        'entity_name' => array ('membership_1'),
+        'entity_type' => 'MembershipModel',
+      );
+    }
+    $allowCoreTypes = array_merge(array('Contact', 'Organization', $allowMemberCoreTypes), CRM_Contact_BAO_ContactType::subTypes('Organization'));
+    $allowSubTypes = array();
+
     $this->addProfileSelector('onbehalf_profile_id', ts('Organization Profile'), $allowCoreTypes, $allowSubTypes, $entities);
 
     $options   = array();