<?php
/**
 * @package    VP Email Manager
 * @copyright  Copyright (C) 2012-2021 VirtuePlanet Services LLP. All rights reserved.
 * @license    GNU General Public License version 2 or later; see LICENSE.txt
 * @author     Abhishek Das <info@virtueplanet.com>
 * @link       https://www.virtueplanet.com
 */

defined('_JEXEC') or die;

use Joomla\Registry\Registry;

jimport('joomla.form.formfield');

JFormHelper::loadFieldClass('list');

JLoader::register('VmConfig', JPATH_ROOT .'/administrator/components/com_virtuemart/helpers/config.php');

class JFormFieldVpemvendor extends JFormFieldList
{
	public $type = 'vpemvendor';
	
	protected static $vendors = null;
	
	protected function getOptions()
	{
		VmConfig::loadConfig();
		vmLanguage::loadJLang('com_virtuemart');
		
		if (self::$vendors === null)
		{
			$model         = VmModel::getModel('vendor');
			self::$vendors = $model->getVendors(true, true, false);
		}
		
		$options = [];
		
		foreach (self::$vendors as $vendor)
		{
			$options[] = JHtml::_('select.option', (int) $vendor->virtuemart_vendor_id, $vendor->vendor_name);
		}
		
		return array_merge(parent::getOptions(), $options);
	}
}