From 254f0bcda23ea9cc9ea3d91996ab37ef7515af1b Mon Sep 17 00:00:00 2001 From: zorgalina Date: Fri, 8 May 2015 20:51:54 -0700 Subject: [PATCH] CRM-16481 Add priceset defaults, check field visibility Comment-out textbox for 'add discount code', it will appear if the event(s) and pricesets have discounts -an update to CiviDiscount with this formname will prompt for discount code - check for price field visibility admin only or public - set for price field defaults if any --- .../Form/Checkout/ParticipantsAndPrices.php | 45 ++++++++++++++++--- 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/CRM/Event/Cart/Form/Checkout/ParticipantsAndPrices.php b/CRM/Event/Cart/Form/Checkout/ParticipantsAndPrices.php index adde82c038..52aabc8e6e 100644 --- a/CRM/Event/Cart/Form/Checkout/ParticipantsAndPrices.php +++ b/CRM/Event/Cart/Form/Checkout/ParticipantsAndPrices.php @@ -26,8 +26,9 @@ class CRM_Event_Cart_Form_Checkout_ParticipantsAndPrices extends CRM_Event_Cart_ foreach ($this->cart->get_main_events_in_carts() as $event_in_cart) { $this->price_fields_for_event[$event_in_cart->event_id] = $this->build_price_options($event_in_cart->event); } - // XXX - $this->addElement('text', 'discountcode', ts('If you have a discount code, enter it here')); + //If events in cart have discounts the textbox for discount code will be displayed at the top, as long as this + //form name is added to cividiscount + //$this->addElement('text', 'discountcode', ts('If you have a discount code, enter it here')); $this->assign('events_in_carts', $this->cart->get_main_events_in_carts()); $this->assign('price_fields_for_event', $this->price_fields_for_event); $this->addButtons( @@ -74,15 +75,23 @@ class CRM_Event_Cart_Form_Checkout_ParticipantsAndPrices extends CRM_Event_Cart_ $price_fields_for_event = array(); $base_field_name = "event_{$event->id}_amount"; $price_set_id = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $event->id); + //CRM-14492 display admin fields only if user is admin + $admin_field_visible = false; + if (CRM_Core_Permission::check('administer CiviCRM')){ + $admin_field_visible = true; + } if ($price_set_id) { $price_sets = CRM_Price_BAO_PriceSet::getSetDetail($price_set_id, TRUE, TRUE); $price_set = $price_sets[$price_set_id]; $index = -1; foreach ($price_set['fields'] as $field) { $index++; - $field_name = "event_{$event->id}_price_{$field['id']}"; - CRM_Price_BAO_PriceField::addQuickFormElement($this, $field_name, $field['id'], FALSE); - $price_fields_for_event[] = $field_name; + if (CRM_Utils_Array::value('visibility', $field) == 'public' || + (CRM_Utils_Array::value('visibility', $field) == 'admin' && $adminFieldVisible == true) ){ + $field_name = "event_{$event->id}_price_{$field['id']}"; + CRM_Price_BAO_PriceField::addQuickFormElement($this, $field_name, $field['id'], FALSE); + $price_fields_for_event[] = $field_name; + } } } return $price_fields_for_event; @@ -184,7 +193,31 @@ class CRM_Event_Cart_Form_Checkout_ParticipantsAndPrices extends CRM_Event_Cart_ $participant->contact_id = self::find_or_create_contact($this->getContactID()); } $defaults += $form->setDefaultValues(); - } + //Set price defaults if any + foreach ($this->cart->get_main_events_in_carts() as $event_in_cart) { + $price_set_id = CRM_Event_BAO_Event::usesPriceSet($event_in_cart->event_id); + if ($price_set_id) { + $price_sets = CRM_Price_BAO_PriceSet::getSetDetail($price_set_id, TRUE, TRUE); + $price_set = $price_sets[$price_set_id]; + foreach ($price_set['fields'] as $field){ + $options = CRM_Utils_Array::value('options', $field); + if (!is_array($options)) { + continue; + } + $field_name = "event_{$event_id}_price_{$field['id']}"; + foreach ($options as $value){ + if ( $value['is_default'] ){ + if ($field['html_type'] == 'Checkbox'){ + $defaults[$field_name] = 1; + } else { + $defaults[$field_name] = $value['id']; + } + } + } + } + } + } + } return $defaults; } -- 2.25.1