// build price set form.
$this->set('priceSetId', $this->_priceSetId);
if (empty($this->_ccid)) {
- CRM_Price_BAO_PriceSet::buildPriceSet($this);
+ CRM_Price_BAO_PriceSet::buildPriceSet($this, $this->getMainEntityType());
}
if ($this->_values['is_monetary'] &&
$this->_values['is_recur'] && empty($this->_values['pledge_id'])
*/
protected function isMembershipPriceSet(): bool {
if ($this->_useForMember === NULL) {
- if (CRM_Core_Component::isEnabled('CiviMember') &&
- (!$this->isQuickConfig() || !empty($this->_ccid)) &&
- (int) CRM_Core_Component::getComponentID('CiviMember') === (int) $this->order->getPriceSetMetadata()['extends']) {
+ if ($this->getMainEntityType() === 'membership' &&
+ !$this->isQuickConfig()) {
$this->_useForMember = 1;
}
else {
return (bool) $this->_useForMember;
}
+ public function getMainEntityType() {
+ if (CRM_Core_Component::isEnabled('CiviMember') && (int) CRM_Core_Component::getComponentID('CiviMember') === (int) $this->order->getPriceSetMetadata()['extends']) {
+ return 'membership';
+ }
+ return 'contribution';
+ }
+
/**
* Should the membership block be displayed.
*
* Build the price set form.
*
* @param CRM_Core_Form $form
+ * @param string|null $component
*
* @return void
*/
- public static function buildPriceSet(&$form) {
+ public static function buildPriceSet(&$form, $component = NULL) {
$priceSetId = $form->get('priceSetId');
if (!$priceSetId) {
return;
$form->_priceSet['id'] = $form->_priceSet['id'] ?? $priceSetId;
$form->assign('priceSet', $form->_priceSet);
- $component = 'contribution';
if ($className == 'CRM_Member_Form_Membership') {
$component = 'membership';
}
if ($className == 'CRM_Contribute_Form_Contribution_Main') {
$feeBlock = &$form->_values['fee'];
- if (!empty($form->_useForMember)) {
- $component = 'membership';
- }
}
else {
$feeBlock = &$form->_priceSet['fields'];
}
// Call the buildAmount hook.
- CRM_Utils_Hook::buildAmount($component, $form, $feeBlock);
+ CRM_Utils_Hook::buildAmount($component ?? 'contribution', $form, $feeBlock);
self::addPriceFieldsToForm($form, $feeBlock, $validFieldsOnly, $className, $validPriceFieldIds);
}