2013-11-05 25 views
0

所以這看起來真的很愚蠢的問題,也許基本上是一本教科書的實現。但是當使用由renderList()創建的Add/Edit按鈕時,提交的字段是空的。我已經進入核心ObjectModel類並輸出結果,實際上沒有數據傳回。從我可以告訴這應該全部連接起來,因爲所有這些都是由後端生成/處理,但顯然缺少一些東西。Extend ModuleAdminController Add/Edit not working

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

示範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

什麼是數據庫結構和StoreMatrix ObjectModel? PrestaShop編碼風格需要PRIMARY KEY爲id_store_matrix,而不是store_matrix_id。可能你沒有在StoreMatrix中正確定義它? – PrestaShopDeveloper

+0

所以模塊是'storematrices'表'store_matrices',模型是'storematrix'。我之前確實解決了這個問題......我已經粘貼了上面的模型並更新了控制器 – Amb3rL4nn

回答

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