<?php
/**
 * @version     1.3.3
 * @package     sellacious
 *
 * @copyright   Copyright (C) 2012-2017 Bhartiy Web Technologies. All rights reserved.
 * @license     SPL Sellacious Private License; see http://www.sellacious.com/spl.html
 * @author      Izhar Aazmi <info@bhartiy.com> - http://www.bhartiy.com
 */
// no direct access.
defined('_JEXEC') or die;

JFormHelper::loadFieldClass('list');

class JFormFieldShippingMethod extends JFormFieldList
{
	/**
	 * The field type.
	 *
	 * @var  string
	 */
	protected $type = 'ShippingMethod';

	/**
	 * Method to get a list of options for a list input.
	 *
	 * @return  array  An array of JHtml options.
	 */
	protected function getOptions()
	{
		$options  = array();
		$helper   = SellaciousHelper::getInstance();
		$handlers = $helper->shippingRule->getHandlers();

		asort($handlers);

		if (!$helper->access->check('shippingrule.edit'))
		{
			$choices = array_filter(explode('|', (string) $this->element['choices']), 'strlen');
		}

		foreach ($handlers as $handler => $handler_name)
		{
			if (empty($choices) || in_array($handler, $choices))
			{
				$options[] = JHtml::_('select.option', $handler, $handler_name);
			}
		}

		return array_merge(parent::getOptions(), $options);
	}
}
