所以这似乎是一个非常愚蠢的问题,基本上是教科书的实施。但是当使用renderList()创建的“添加/编辑”按钮时,提交的字段为空。我已进入核心ObjectModel类并输出结果,实际上没有数据传回。从我所知道的,所有这些都应该链接起来,因为所有这些都是由后端生成/处理的,但显然遗漏了一些东西。
class AdminStoreMatrixController extends ModuleAdminController {
protected $actions_available = array('edit', 'delete');//, 'details');
protected $actions = array('edit', 'delete');//, 'details');
protected $position_identifier = 'id_store_matrices';
public function __construct() {
$this->context = Context::getContext();
$this->table = 'store_matrices';
$this->identifier = 'id_store_matrices';
$this->className = 'StoreMatrix';
$this->lang = false;
$this->fields_list = array(
'id_store_matrices' => array('title' => $this->l('#')),
'price_low' => array('title' => $this->l('Price Low')),
'price_high' => array('title' => $this->l('Price High')),
'apr' => array('title' => $this->l('APR')),
'apr_term' => array('title' => $this->l('APR Term')),
'down_payment' => array('title' => $this->l('Down Payment')),
'shipping' => array('title' => $this->l('Shipping')),
);
// This adds a multiple deletion button
$this->bulk_actions = array(
'delete' => array(
'text' => $this->l('Delete selected'),
'confirm' => $this->l('Delete selected items?')
)
);
parent::__construct();
}
// This method generates the list of results
//public function renderList() {
// $this->addRowAction('edit');
// $this->addRowAction('delete');
//$this->addRowAction('details');
// return parent::renderList();
//}
// This method generates the Add/Edit form
public function renderForm() {
// Building the Add/Edit form
$this->fields_form = array(
'legend' => array(
'title' => $this->l('Store Matrices')
),
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Price Low:'),
'name' => 'price_low',
'size' => 10,
'required' => true,
'desc' => $this->l('Lowest price this will apply too'),
),
array(
'type' => 'text',
'label' => $this->l('Price High:'),
'name' => 'price_high',
'size' => 10,
'required' => true,
'desc' => $this->l('Highest price this will apply too'),
),
array(
'type' => 'text',
'label' => $this->l('APR:'),
'name' => 'apr',
'size' => 5,
'required' => true,
'desc' => $this->l('Annual Percentage Rate'),
),
array(
'type' => 'text',
'label' => $this->l('APR Term:'),
'name' => 'apr_term',
'size' => 33,
'required' => true,
'desc' => $this->l('Months the APR will apply'),
),
array(
'type' => 'text',
'label' => $this->l('Down Payment:'),
'name' => 'down_payment',
'size' => 5,
'required' => true,
'desc' => $this->l('Percentage of Down payment'),
),
array(
'type' => 'text',
'label' => $this->l('Shipping:'),
'name' => 'shipping',
'size' => 5,
'required' => true,
'desc' => $this->l('Percentage of Shipping cost'),
),
),
'submit' => array(
'title' => $this->l(' Save '),
'class' => 'button'
)
);
return parent::renderForm();
}
Model storematrix.php
class StoreMatrix extends ObjectModel {
/*
*//**
* @see ObjectModel::$definition
*/
public static $definition = array(
'table' => 'store_matrices',
'primary' => 'id_store_matrices',
'fields' => array(
'price_low' => array('type' => self::TYPE_FLOAT, 'validate' => 'isFloat', 'required' => true, 'size' => 10),
'price_high' => array('type' => self::TYPE_FLOAT, 'validate' => 'isFloat', 'required' => true, 'size' => 10),
'apr' => array('type' => self::TYPE_FLOAT, 'validate' => 'isFloat', 'required' => true, 'size' => 10),
'apr_term' => array('type' => self::TYPE_INT, 'validate' => 'isInt', 'required' => true, 'size' => 10),
'down_payment' => array('type' => self::TYPE_FLOAT, 'validate' => 'isFloat', 'required' => true, 'size' => 10),
'shipping' => array('type' => self::TYPE_FLOAT, 'validate' => 'isFloat', 'required' => true, 'size' => 10),
),
);
}
答案 0 :(得分:0)
因此,prestashop中模型的问题在于,您不仅需要拥有字段的定义,而且还必须将字段声明为上面的公共字段。见下文,现在一切都很完美。
class StoreMatrix extends ObjectModel {
//fields to store into the database
public $price_low;
public $price_high;
public $apr;
public $apr_term;
public $down_payment;
public $shipping;
/*
*//**
* @see ObjectModel::$definition
*/
public static $definition = array(
'table' => 'store_matrices',
'primary' => 'id_store_matrices',
'fields' => array(
'price_low' => array('type' => self::TYPE_FLOAT, 'validate' => 'isFloat', 'required' => true, 'size' => 10),
'price_high' => array('type' => self::TYPE_FLOAT, 'validate' => 'isFloat', 'required' => true, 'size' => 10),
'apr' => array('type' => self::TYPE_FLOAT, 'validate' => 'isFloat', 'required' => true, 'size' => 10),
'apr_term' => array('type' => self::TYPE_INT, 'validate' => 'isInt', 'required' => true, 'size' => 10),
'down_payment' => array('type' => self::TYPE_FLOAT, 'validate' => 'isFloat', 'required' => true, 'size' => 10),
'shipping' => array('type' => self::TYPE_FLOAT, 'validate' => 'isFloat', 'required' => true, 'size' => 10),
),
);
}