dousi1097 2017-07-26 12:33
浏览 30
已采纳

在创建配置文件时覆盖配置文件 - Prestashop

I wanted to add a dropdown list with the profile on creation of profile. I had used override, the dropdown is coming correctly and saved in database also but when editing or viewing it is not making the "dropdown selected ".

Also so many warnings are coming with undefined name, undefined type. I will share my code :-

AdminProfilesController.php

    class AdminProfilesController extends AdminProfilesControllerCore
{
    public function __construct()
    {
        $this->bootstrap = true;
        $this->context = Context::getContext();
        $this->table = 'profile';
        $this->className = 'Profile';
        $this->multishop_context = Shop::CONTEXT_ALL;
        $this->lang = true;
        $this->addRowAction('edit');
        $this->addRowAction('delete');
        $this->addRowActionSkipList('delete', array(1));

        // For add a fields via an override of $fields_form, use $fields_form_override
        if (is_array($this->fields_form_override) && !empty($this->fields_form_override)) {
         $this->fields_form[0]['form']['input'] = array_merge($this->fields_form[0]['form']['input'], $this->fields_form_override);
     }

     $this->bulk_actions = array(
        'delete' => array(
            'text' => $this->l('Delete selected'),
            'confirm' => $this->l('Delete selected items?'),
            'icon' => 'icon-trash'
            )
        );

     $this->fields_list = array(
        'id_profile' => array(
            'title' => $this->l('ID'),
            'align' => 'center',
            'class' => 'fixed-width-xs'
            ),
        'name' => array('title' => $this->l('Name'))
        );

     $this->identifier = 'id_profile';

     /* Fetch All Profiles*/
     $admin_levels = Profile::adminLevels();
     foreach ($admin_levels as $row) {         
      $values_access[] = array(
        'id' => $row['id_admin'],
        'name' => $this->l($row['admin_level_name']),
        'label' => $this->l($row['admin_level_name']),
        'val' => $row['id_admin']                                
        );
  }

  $this->fields_form = array(
    'legend' => array(
        'title' => $this->l('Profile'),
        'icon' => 'icon-group'
        ),
    'input' => array(
        array(
            'type' => 'text',
            'label' => $this->l('Name'),
            'name' => 'name',
            'required' => true,
            'lang' => true,
            ),
        ),

    $this->fields_form_override = array(
        array(
            'type' => 'select',
            'label' => $this->l('Access Levels'),
            'name' => 'id_admin',   
                // 'lang' => true,                 
            'col' => '4',                   
            'options' => array(
                'query' => $values_access,
                'id' => 'id',
                'name' => 'name',
                'val' => 'val'
                ),
            ),
        ),


    'submit' => array(
        'title' => $this->l('Save'),
        )
    );

  $list_profile = array();
  foreach (Profile::getProfiles($this->context->language->id) as $profil) { 
    $list_profile[] = array('value' => $profil['id_profile'], 'name' => $profil['name']);
}

parent::__construct();
}



}

In Classes folder

Profile.php

class Profile extends ProfileCore
{
    /** @var string Name */
    public $name;
    public $id_admin;

    /**
     * @see ObjectModel::$definition
     */
    public static $definition = array(
        'table' => 'profile',
        'primary' => 'id_profile',
        'multilang' => true,
        'fields' => array(
            /* Lang fields */
            'name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 32),
            'id_admin' => array('type' => self::TYPE_INT, 'lang' => true)           
            ),
        );

    /** Fetching Admin Access Levels */
    public static function adminLevels()
    {
        $access_level = Db::getInstance()->ExecuteS('SELECT *  FROM '._DB_PREFIX_.'admin_levels');
        return $access_level;
    }
}

Can anyone help me to sort out this. I am using prestashop 1.6

profile structure is same as default. profile_lang structure changes Column Type id_lang int(10) unsigned
id_profile int(10) unsigned
name varchar(128)
id_admin int(11)

  • 写回答

1条回答 默认 最新

  • douping5226 2017-07-26 13:33
    关注

    Try using just:

    $this->fields_form_override = array(
                array(
                    'type' => 'select',
                    'label' => $this->l('Access Levels'),
                    'name' => 'id_admin_level',   
                    'lang' => true,                 
                    'col' => '4',                   
                    'options' => array(
                        'query' => $values_access,
                        'id' => 'id',
                        'name' => 'name',
                        'val' => 'val'
                        ),
                    ),
            );
    

    If you check where it's used:

    // For add a fields via an override of $fields_form, use $fields_form_override
    if (is_array($this->fields_form_override) && !empty($this->fields_form_override)) {
         $this->fields_form[0]['form']['input'] = array_merge($this->fields_form[0]['form']['input'], $this->fields_form_override);
    }
    

    It will merge the override fields with the $this->fields_form[0]['form']['input'] so the $this->fields_form_override need to be in the same format.

    Another solution is to change the name to $this->fields_form_override to $this->fields_form and instead of parent::__construct(); use AdminController::__construct() to bypass (ignore) the AdminProfile contructor.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 在不同的执行界面调用同一个页面
  • ¥20 基于51单片机的数字频率计
  • ¥50 M3T长焦相机如何标定以及正射影像拼接问题
  • ¥15 keepalived的虚拟VIP地址 ping -s 发包测试,只能通过1472字节以下的数据包(相关搜索:静态路由)
  • ¥20 关于#stm32#的问题:STM32串口发送问题,偶校验(even),发送5A 41 FB 20.烧录程序后发现串口助手读到的是5A 41 7B A0
  • ¥15 C++map释放不掉
  • ¥15 Mabatis查询数据
  • ¥15 想知道lingo目标函数中求和公式上标是变量情况如何求解
  • ¥15 关于E22-400T22S的LORA模块的通信问题
  • ¥15 求用二阶有源低通滤波将3khz方波转为正弦波的电路