self::$_exportableFields = array();
}
- $impFields = CRM_Contribute_DAO_Contribution::export();
- $expFieldProduct = CRM_Contribute_DAO_Product::export();
- $expFieldsContrib = CRM_Contribute_DAO_ContributionProduct::export();
+ $fields = CRM_Contribute_DAO_Contribution::export();
+ if (CRM_Contribute_BAO_Query::isSiteHasProducts()) {
+ $fields = array_merge(
+ $fields,
+ CRM_Contribute_DAO_Product::export(),
+ CRM_Contribute_DAO_ContributionProduct::export(),
+ // CRM-16713 - contribution search by Premiums on 'Find Contribution' form.
+ [
+ 'contribution_product_id' => [
+ 'title' => ts('Premium'),
+ 'name' => 'contribution_product_id',
+ 'where' => 'civicrm_product.id',
+ 'data_type' => CRM_Utils_Type::T_INT,
+ ],
+ ]
+ );
+ }
$typeField = CRM_Financial_DAO_FinancialType::export();
$financialAccount = CRM_Financial_DAO_FinancialAccount::export();
),
);
- // CRM-16713 - contribution search by Premiums on 'Find Contribution' form.
- $premiums = array(
- 'contribution_product_id' => array(
- 'title' => ts('Premium'),
- 'name' => 'contribution_product_id',
- 'where' => 'civicrm_product.id',
- 'data_type' => CRM_Utils_Type::T_INT,
- ),
- );
-
- $fields = array_merge($impFields, $typeField, $contributionPage, $expFieldProduct,
- $expFieldsContrib, $contributionNote, $extraFields, $softCreditFields, $financialAccount, $premiums, $campaignTitle,
+ $fields = array_merge($fields, $typeField, $contributionPage,
+ $contributionNote, $extraFields, $softCreditFields, $financialAccount, $campaignTitle,
CRM_Core_BAO_CustomField::getFieldsForImport('Contribution', FALSE, FALSE, FALSE, $checkPermission)
);
'contribution_status_id' => 1,
// @todo return this & fix query to do pseudoconstant thing.
'contribution_status' => 1,
- // @todo the product field got added because it suited someone's use case.
- // ideally we would have some configurability here because I think 90% of sites would
- // disagree this is the right field to show - but they wouldn't agree with each other
- // on what field to show instead.
- 'contribution_product_id' => 1,
- 'product_name' => 1,
'currency' => 1,
'cancel_date' => 1,
'contribution_recur_id' => 1,
);
+ if (self::isSiteHasProducts()) {
+ $properties['product_name'] = 1;
+ $properties['contribution_product_id'] = 1;
+ }
if (self::isSoftCreditOptionEnabled($queryParams)) {
$properties = array_merge($properties, self::softCreditReturnProperties());
}
return $properties;
}
+ /**
+ * Do any products exist in this site's database.
+ *
+ * @return bool
+ */
+ public static function isSiteHasProducts() {
+ if (!isset(\Civi::$statics[__CLASS__]['has_products'])) {
+ \Civi::$statics[__CLASS__]['has_products'] = (bool) CRM_Core_DAO::singleValueQuery('SELECT id FROM civicrm_contribution_product LIMIT 1');
+ }
+ return \Civi::$statics[__CLASS__]['has_products'];
+ }
+
/**
* Function you should avoid.
*
//every
'receipt_date' => 1,
// query
- 'product_name' => 1,
//whether
- 'sku' => 1,
// or
- 'product_option' => 1,
// not
- 'fulfilled_date' => 1,
// the
- 'contribution_start_date' => 1,
// field
- 'contribution_end_date' => 1,
// is
'is_test' => 1,
// actually
// on
'contribution_campaign_id' => 1,
// calling
- 'contribution_product_id' => 1,
//function
);
+ if (self::isSiteHasProducts()) {
+ $properties['fulfilled_date'] = 1;
+ $properties['product_name'] = 1;
+ $properties['contribution_product_id'] = 1;
+ $properties['product_option'] = 1;
+ $properties['sku'] = 1;
+ $properties['contribution_start_date'] = 1;
+ $properties['contribution_end_date'] = 1;
+ }
if (self::isSoftCreditOptionEnabled()) {
$properties = array_merge($properties, self::softCreditReturnProperties());
}
'autocomplete' => 'off',
));
- // CRM-16713 - contribution search by premiums on 'Find Contribution' form.
- $form->add('select', 'contribution_product_id',
- ts('Premium'),
- CRM_Contribute_PseudoConstant::products(),
- FALSE, array('class' => 'crm-select2', 'multiple' => 'multiple', 'placeholder' => ts('- any -'))
- );
+ if (CRM_Contribute_BAO_Query::isSiteHasProducts()) {
+ // CRM-16713 - contribution search by premiums on 'Find Contribution' form.
+ $form->add('select', 'contribution_product_id',
+ ts('Premium'),
+ CRM_Contribute_PseudoConstant::products(),
+ FALSE, [
+ 'class' => 'crm-select2',
+ 'multiple' => 'multiple',
+ 'placeholder' => ts('- any -')
+ ]
+ );
+ }
self::addCustomFormFields($form, array('Contribution'));
'field_name' => 'contribution_status',
'direction' => CRM_Utils_Sort::DONTCARE,
),
- array(
- 'name' => ts('Premium'),
- 'sort' => 'product_name',
- 'field_name' => 'product_name',
- 'direction' => CRM_Utils_Sort::DONTCARE,
- ),
)
);
+ if (CRM_Contribute_BAO_Query::isSiteHasProducts()) {
+ self::$_columnHeaders[] = [
+ 'name' => ts('Premium'),
+ 'sort' => 'product_name',
+ 'field_name' => 'product_name',
+ 'direction' => CRM_Utils_Sort::DONTCARE,
+ ];
+ }
if (!$this->_single) {
$pre = array(
array(
'currency' => 1,
'cancel_reason' => 1,
'receipt_date' => 1,
- 'product_name' => 1,
- 'sku' => 1,
- 'product_option' => 1,
- 'fulfilled_date' => 1,
- 'contribution_start_date' => 1,
- 'contribution_end_date' => 1,
'is_test' => 1,
'is_pay_later' => 1,
'contribution_status' => 1,
'contribution_batch' => 1,
'contribution_campaign_title' => 1,
'contribution_campaign_id' => 1,
- 'contribution_product_id' => 1,
'contribution_soft_credit_name' => 1,
'contribution_soft_credit_amount' => 1,
'contribution_soft_credit_type' => 1,
97 => 'Currency',
98 => 'Cancellation / Refund Reason',
99 => 'Receipt Date',
- 100 => 'Product Name',
- 101 => 'SKU',
- 102 => 'Product Option',
- 103 => 'Fulfilled Date',
- 104 => 'Start date for premium',
- 105 => 'End date for premium',
106 => 'Test',
107 => 'Is Pay Later',
108 => 'contribution_status',
112 => 'Batch Name',
113 => 'Campaign Title',
114 => 'Campaign ID',
- 115 => 'Premium',
116 => 'Soft Credit For',
117 => 'Soft Credit Amount',
118 => 'Soft Credit Type',
'currency' => 'currency varchar(3)',
'cancel_reason' => 'cancel_reason longtext',
'receipt_date' => 'receipt_date varchar(32)',
- 'product_name' => 'product_name varchar(255)',
- 'sku' => 'sku varchar(50)',
- 'product_option' => 'product_option varchar(255)',
- 'fulfilled_date' => 'fulfilled_date varchar(32)',
- 'contribution_start_date' => 'contribution_start_date varchar(32)',
- 'contribution_end_date' => 'contribution_end_date varchar(32)',
'is_test' => 'is_test varchar(16)',
'is_pay_later' => 'is_pay_later varchar(16)',
'contribution_status' => 'contribution_status text',
'contribution_batch' => 'contribution_batch text',
'contribution_campaign_title' => 'contribution_campaign_title varchar(255)',
'contribution_campaign_id' => 'contribution_campaign_id varchar(128)',
- 'contribution_product_id' => 'contribution_product_id varchar(255)',
'contribution_soft_credit_name' => 'contribution_soft_credit_name varchar(255)',
'contribution_soft_credit_amount' => 'contribution_soft_credit_amount varchar(255)',
'contribution_soft_credit_type' => 'contribution_soft_credit_type varchar(255)',