duanre1891 2013-11-05 05:25
浏览 30
已采纳

扩展ModuleAdminController添加/编辑不起作用

So this seems really dumb question maybe and basically a text book implementation. But when using the Add/Edit buttons created by the renderList() the submitted fields are empty. I have gone into the core ObjectModel class and output the results and indeed no data is passing back. From what I can tell this should all link up since all of this is generated/handled by the backend but obviously missing something.

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();
}

The 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),
    ),
);
}
  • 写回答

1条回答 默认 最新

  • douran6443 2013-11-05 21:25
    关注

    So the issue with the model in prestashop is that you not only need to have the definitions for the fields but also you must actually declare the fields as public above. See the below and now everything work perfect.

    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),
            ),
        );
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用