Search code examples
phpjoomlaoptgroup

joomla: adding a select.optgroup to select.genericlist


I need to add a select.optgroup to my select.genericlist, this is my code:

foreach ($this->methods as $method) {
      if ($this->checkConditions($cart, $method, $cart->pricesUnformatted)) {
          $methodSalesPrice = $this->calculateSalesPrice($cart, $method, $cart->pricesUnformatted);
          $method->$method_name = $this->renderPluginName($method);

              $session = JFactory::getSession();
              $htmlI[] = $this->getPluginHtml($method, $selected, $methodSalesPrice);
              // this is my attempt
              $htmlI[] = JHTML::_('Select.optgroup', 'My optgroup');
              // my attempt ends here
              $htmlI[] = JHTML::_('Select.genericlist', $this->banks, 'service_issuer', 'size=1', 'key', 'value', $session->get('service_issuer', 0, 'vm'));
              $html[] = $htmlI;


      }
  }

this returns the following:

array

Has anyone done this before? Advice is much appreciated


Solution

  • I've managed to fix it myself, below is the working code

    if($method->payment_method == "mymethod") {
                  $session = JFactory::getSession();
                  $htmlI = $this->getPluginHtml($method, $selected, $methodSalesPrice);
                  $banksEra[] = JHTML::_('select.option', '', JText::_('VMPAYMENT_BANKS'));
                  $banksEra[] = JHTML::_('select.optgroup', 'Countries');
                  foreach ($this->banksEra as $key => $value) {
                    $banksEra[] = JHTML::_( 'select.option', $key, $value );
                  }
                  $htmlI .= JHTML::_('select.genericlist', $banksEra, 'issuer', 'class="inputbox"', 'value', 'text', $session->get('issuer', 0, 'vm'));
                  $html[] = $htmlI;
              }