Witam
Chcę stworzyć własny moduł do presty. Na początek skopiowałem pliki classes/Zone.php i zmieniłem mu nazwę na Test.php, admin/tabs/AdminZones.php na AdminTest.php no i oczywiście skopiowałem tabelę 'zone' i stworzyłem 'test'.
Wyskakuje mi jednak błąd: "Złe zapytanie SQL"
Wszystkie pliki wyglądają tak:
AdminTest.php
<?php
/**
* Test tab for admin panel, AdminTest.php
* @category admin
*
* @author PrestaShop <support@prestashop.com>
* @copyright PrestaShop
* @license http://www.opensource.org/licenses/osl-3.0.php Open-source licence 3.0
* @version 1.2
*
*/
include_once(dirname(__FILE__).'/../../classes/AdminTab.php');
class AdminTest extends AdminTab
{
public function __construct()
{
$this->table = 'test';
$this->className = 'Test';
$this->lang = false;
$this->edit = true;
$this->delete = true;
$this->fieldsDisplay = array(
'id_test' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25),
'name' => array('title' => $this->l('Zone'), 'width' => 150),
'active' => array('title' => $this->l('Enabled'), 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false)
);
parent::__construct();
}
public function displayForm()
{
}
}
?>
Test.php
<?php
/**
* Test class, Test.php
* Test management
* @category classes
*
* @author PrestaShop <support@prestashop.com>
* @copyright PrestaShop
* @license http://www.opensource.org/licenses/osl-3.0.php Open-source licence 3.0
* @version 1.2
*
*/
class Test extends ObjectModel
{
/** @var string Name */
public $name;
/** @var boolean Test statuts */
public $active = true;
public $eu_test = false; /* Obsolete; to remove */
protected $fieldsRequired = array('name');
protected $fieldsSize = array('name' => 64);
protected $fieldsValidate = array('name' => 'isGenericName', 'active' => 'isBool');
protected $table = 'test';
protected $identifier = 'id_test';
public function getFields()
{
parent::validateFields();
$fields['name'] = pSQL($this->name);
$fields['active'] = intval($this->active);
return $fields;
}
/**
* Get all available geographical test
*
* @return array Test
*/
static public function getTest($active = false)
{
return Db::getInstance()->ExecuteS('
SELECT *
FROM `'._DB_PREFIX_.'test`
'.($active ? 'WHERE active = 1' : '').'
ORDER BY `name` ASC');
}
}
?>
Oraz tabela:
CREATE TABLE IF NOT EXISTS `ps_test` (
`id_test` int(10) unsigned NOT NULL auto_increment,
`name` varchar(64) NOT NULL,
`active` tinyint(1) unsigned NOT NULL default '0',
`enabled` tinyint(1) unsigned NOT NULL default '0',
PRIMARY KEY (`id_test`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=6 ;
--
-- Zrzut danych tabeli `ps_test`
--
INSERT INTO `ps_test` (`id_test`, `name`, `active`, `enabled`) VALUES
(1, 'Europe', 1, 1),
(2, 'US', 1, 1),
(3, 'Asia', 1, 1),
(4, 'Africa', 1, 1),
(5, 'Oceania', 1, 1);