CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Set Price Field Options that are full not to show in the select list at all?
Pages: [1]

Author Topic: Set Price Field Options that are full not to show in the select list at all?  (Read 1044 times)

lolas

  • I post frequently
  • ***
  • Posts: 134
  • Karma: 9
    • Freeform Solutions
  • CiviCRM version: Several
  • CMS version: Drupal
  • MySQL version: 5.1+
  • PHP version: Several
Set Price Field Options that are full not to show in the select list at all?
March 18, 2013, 10:42:46 am
If we have price field options that have a maximum participant count it seems that they show up in a select list even if they are full? Looks like for every html type except select the full options are frozen. Instead for the select type a form rule is added to return an error if the user chooses that option.

So far I see that there is a function that checks if they are full: CRM_Event_BAO_Participant::priceSetOptionsCount() which is used by formatFieldsForOptionFull to add more info to the options array for each field including $optionFullIds. Then $optionFullIds is passed to CRM_Price_BAO_Field::addQuickFormElement as $feezeOptions unless the form is called CRM_Event_Form_Participant in order to ignore full options for offline registration. Except that for the select type they are added anyway and a form rule prevents submission if they are chosen.

Code: [Select]
      case 'Select':
        $selectOption = $allowedOptions = $priceVal = array();

        foreach ($customOption as $opt) {
          $count = CRM_Utils_Array::value('count', $opt, '');
          $max_value = CRM_Utils_Array::value('max_value', $opt, '');
          $priceVal[$opt['id']] = implode($seperator, array($opt[$valueFieldName], $count, $max_value));

          if ($field->is_display_amounts) {
            $opt['label'] .= ' - ';
            $opt['label'] .= CRM_Utils_Money::format($opt[$valueFieldName]);
          }
-          $selectOption[$opt['id']] = $opt['label'];

          if (!in_array($opt['id'], $feezeOptions)) {
            $allowedOptions[] = $opt['id'];
+          $selectOption[$opt['id']] = $opt['label'];
          }
        }
        $element = &$qf->add('select', $elementName, $label,
          array(
            '' => ts('- select -')) + $selectOption,
          $useRequired && $field->is_required,
          array('price' => json_encode($priceVal))
        );

        // CRM-6902
        $button = substr($qf->controller->getButtonName(), -4);
        if (!empty($feezeOptions) && $button != 'skip') {
          $qf->addRule($elementName, ts('Sorry, this option is currently sold out.'), 'regex', "/" . implode('|', $allowedOptions) . "/");
        }
        break;

Code: [Select]
-      //ignore option full for offline registration.
-      if ($className == 'CRM_Event_Form_Participant') {
-        $optionFullIds = array();
-      }
I have an event manager end user who would like the event registrants not to see the full options at all in the select list so that they don't get frustrated by choosing sold out options and I think they would like to at least retain the sold out warning in the offline registration. Any comments on the feasibility of just not showing the options at all by using an overridden version of CRM_Price_BAO_Field::addQuickFormElement and CRM_Event_Form_Registration_Register::formatFieldsForOptionFull()? Can anyone see any potential problems where this code is used elsewhere?
Freeform Solutions provides technology and management consulting, website and database development, and managed internet hosting solutions for not-for-profit organizations (NFPs).

lolas

  • I post frequently
  • ***
  • Posts: 134
  • Karma: 9
    • Freeform Solutions
  • CiviCRM version: Several
  • CMS version: Drupal
  • MySQL version: 5.1+
  • PHP version: Several
Re: Set Price Field Options that are full not to show in the select list at all?
March 18, 2013, 01:24:13 pm
I have tested the changes and it seems to work nicely. It seems that CRM_Price_BAO_Field::addQuickFormElement() is only called from 4 places in the core code. I tested 3 of them in this 4.1.5 install. The fourth place is in event carts which I didn't get a chance to test.

I wonder if there is any interest in making this more flexible somehow like adding a checkbox to the backend event registration such as "Ignore full price set options" that must be checked to let the backend user ignore the full status?
Freeform Solutions provides technology and management consulting, website and database development, and managed internet hosting solutions for not-for-profit organizations (NFPs).

RachelWright

  • I post occasionally
  • **
  • Posts: 78
  • Karma: 3
  • CiviCRM version: 4.2.7
  • CMS version: Joomla 2.5.17
  • MySQL version: 5.5.37
  • PHP version: 5.4.26
Re: Set Price Field Options that are full not to show in the select list at all?
April 11, 2013, 10:57:19 am
Is this solution still working for you? I agree with the frustration of choosing an option and typing in all your info, only to find out it is sold out when you submit. I was also considering, perhaps adding the words "sold out" to the option in the drop down. Is there a way in the  CRM_Price_BAO_Field file to add a if the option is 'frozen' add the text 'sold out' in the drop down?

lolas

  • I post frequently
  • ***
  • Posts: 134
  • Karma: 9
    • Freeform Solutions
  • CiviCRM version: Several
  • CMS version: Drupal
  • MySQL version: 5.1+
  • PHP version: Several
Re: Set Price Field Options that are full not to show in the select list at all?
April 23, 2013, 07:27:04 am
Hi Rachel,
Yes this option is still working for the customer that is using it. It would be possible to add a text like (Sold out) instead of removing the option. In the code below it would change to something like this:

Code: [Select]
          if (!in_array($opt['id'], $feezeOptions)) {
            $allowedOptions[] = $opt['id'];
            $selectOption[$opt['id']] = $opt['label'];
          }
          else {
            $selectOption[$opt['id']] = $opt['label'] . ' ' .  ts('(Sold out)'); // Note translate this if necessary
          }
Freeform Solutions provides technology and management consulting, website and database development, and managed internet hosting solutions for not-for-profit organizations (NFPs).

RachelWright

  • I post occasionally
  • **
  • Posts: 78
  • Karma: 3
  • CiviCRM version: 4.2.7
  • CMS version: Joomla 2.5.17
  • MySQL version: 5.5.37
  • PHP version: 5.4.26
Re: Set Price Field Options that are full not to show in the select list at all?
April 24, 2013, 09:57:27 am
Worked perfectly!!! Exactly what I needed, thank you!

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Set Price Field Options that are full not to show in the select list at all?

This forum was archived on 2017-11-26.