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

defined('_JEXEC') or die;

use Joomla\Registry\Registry;

jimport('joomla.form.formfield');

JFormHelper::loadFieldClass('list');

JLoader::register('VmConfig',        JPATH_ADMINISTRATOR . '/components/com_virtuemart/helpers/config.php');
JLoader::register('ShopFunctions',   JPATH_ADMINISTRATOR . '/components/com_virtuemart/helpers/shopfunctions.php');
JLoader::register('TableCategories', JPATH_ADMINISTRATOR . '/components/com_virtuemart/tables/categories.php');
JLoader::register('VmModel',         JPATH_ADMINISTRATOR . '/components/com_virtuemart/helpers/vmmodel.php');

class JFormFieldVMManufacturers extends JFormFieldList
{
	public $type = 'VMManufacturers';
	
	protected function getOptions()
	{
		$options = array();
		
		VmConfig::loadConfig();
		
		$model = VmModel::getModel('Manufacturer');
		
		$manufacturers = $model->getManufacturers(true, true, false);
		
		if (!empty($manufacturers) && is_array($manufacturers))
		{
			foreach ($manufacturers as $manufacturer)
			{
				$options[] = JHTML::_('select.option', (int) $manufacturer->virtuemart_manufacturer_id, htmlspecialchars($manufacturer->mf_name, ENT_COMPAT, 'UTF-8', false));
			}
		}
		
		return array_merge(parent::getOptions(), $options);
	}
}