扩展模块管理控制器添加/编辑不起作用


Extend ModuleAdminController Add/Edit not working

所以这似乎是一个非常愚蠢的问题,基本上是一个教科书式的实现。 但是当使用由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();
}

模型存储矩阵.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),
    ),
);
}

因此,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),
        ),
    );
}