Jump to content

Edit History

spc

spc


first problem solved

I manage to fix the first problem i got, but this is another problem.
I have problems to join table and show the result.

This i manage to fix so i can se the variable,
 

private function paginationYearDataControl($pageId, $limit) {
		$year_list = array();
		$start_from = ($pageId-1) * $limit;
		$sql = 'SELECT ma.makename,mo.modelname,fy.typename,y.year,y.yearid FROM ' 
		._DB_PREFIX_.'caryear y inner join ' 
		._DB_PREFIX_.'carmake ma on y.makeid = ma.makeid inner join ' 
		._DB_PREFIX_.'carmodel mo on mo.modelid = y.modelid inner join '
		._DB_PREFIX_.'cartype fy on fy.typeid = y.typeid ORDER BY ma.makename,mo.modelname,fy.typename,y.year ASC LIMIT '.$start_from.','.$limit;
		if ($results = Db::getInstance()->ExecuteS($sql)){
			foreach($results as $row){
				$year_list[] = array(
					'yearId'			=> $row['yearid'],
					'MakeName'			=> $row['makename'],
					'ModelName'			=> $row['modelname'],
					'Typename'			=> $row['typename'],
					'year'				=> $row['year']
				);
			}
		}
		return $year_list;

But the other in the dropdown i can see, it doesent get the variable´s.
I think this is the problem.
from the tpl file:

<div class="form-group">
      <label for="carType">Type</label>
      <select required="required" id="carType" name="cartype" required>
        <option value="">--Select Type--</option>
    {foreach from=$type_list item=foo}
    <option {if $typeid==$foo.typeid}selected{/if} value="{$foo.typeid}">{$foo.typename}</option>
    {/foreach}
      </select>
    </div>

this is the controller file:

parent::initContent();
		$year_list = array();
		$make_list = array();
		$type_list = array();
		$total_row = 0;
		$total_page = 1;
		$per_page_count = 25;
		$pageId = 1;
		if($row = Db::getInstance()->getRow('SELECT count(yearid) as total FROM '
		._DB_PREFIX_.'caryear y inner join '
		._DB_PREFIX_.'carmake ma on y.makeid = ma.makeid inner join '
		._DB_PREFIX_.'carmodel mo on y.modelid = mo.modelid inner join '
		._DB_PREFIX_.'cartype fy on y.typeid = fy.typeid ORDER BY ma.makename ASC')){
			$total_row = $row['total'];
		}
		if(Tools::getValue('page') && Tools::getValue('page') != ''){
			$pageId = Tools::getValue('page');
		}

Or my be this is the problem.
 

//view operation
	  	if(Tools::getValue('edit')){
			if($row = Db::getInstance()->getRow('SELECT * FROM '._DB_PREFIX_.'caryear where yearid='.Tools::getValue('edit'))){
				$this->makeid = $row['makeid'];
				$this->modelid = $row['modelid'];
				$this->typeid = $row['typeid'];
				$this->yearid = Tools::getValue('edit');
				$this->year = $row['year'];
				if ($results = Db::getInstance()->ExecuteS('SELECT * FROM '._DB_PREFIX_.'carmodel where makeid='.(int)$row['makeid'])){
					foreach($results as $row){
						$this->model_list[] = array(
							'modelid'			=> $row['modelid'],
							'modelname'			=> $row['modelname']
						);

I hope someone can help me, im stuck now.

Untitled.png

Uppdate: I have now figure out that im missing the type_list that show the typename and type id.

I have for make_list:

$sqlx = 'SELECT * FROM '._DB_PREFIX_.'carmake ORDER BY makename ASC';
        if ($resultsx = Db::getInstance()->ExecuteS($sqlx)){
            foreach($resultsx as $rowx){
                $make_list[] = array(
                    'mid'           => $rowx['makeid'],
                    'name'          => $rowx['makename']
                );
            }
        }

Wondering how i can get type_list in to this.

spc

spc


first problem solved

I manage to fix the first problem i got, but this is another problem.
I have problems to join table and show the result.

This i manage to fix so i can se the variable,
 

private function paginationYearDataControl($pageId, $limit) {
		$year_list = array();
		$start_from = ($pageId-1) * $limit;
		$sql = 'SELECT ma.makename,mo.modelname,fy.typename,y.year,y.yearid FROM ' 
		._DB_PREFIX_.'caryear y inner join ' 
		._DB_PREFIX_.'carmake ma on y.makeid = ma.makeid inner join ' 
		._DB_PREFIX_.'carmodel mo on mo.modelid = y.modelid inner join '
		._DB_PREFIX_.'cartype fy on fy.typeid = y.typeid ORDER BY ma.makename,mo.modelname,fy.typename,y.year ASC LIMIT '.$start_from.','.$limit;
		if ($results = Db::getInstance()->ExecuteS($sql)){
			foreach($results as $row){
				$year_list[] = array(
					'yearId'			=> $row['yearid'],
					'MakeName'			=> $row['makename'],
					'ModelName'			=> $row['modelname'],
					'Typename'			=> $row['typename'],
					'year'				=> $row['year']
				);
			}
		}
		return $year_list;

But the other in the dropdown i can see, it doesent get the variable´s.
I think this is the problem.
from the tpl file:

<div class="form-group">
      <label for="carType">Type</label>
      <select required="required" id="carType" name="cartype" required>
        <option value="">--Select Type--</option>
    {foreach from=$type_list item=foo}
    <option {if $typeid==$foo.typeid}selected{/if} value="{$foo.typeid}">{$foo.typename}</option>
    {/foreach}
      </select>
    </div>

this is the controller file:

parent::initContent();
		$year_list = array();
		$make_list = array();
		$type_list = array();
		$total_row = 0;
		$total_page = 1;
		$per_page_count = 25;
		$pageId = 1;
		if($row = Db::getInstance()->getRow('SELECT count(yearid) as total FROM '
		._DB_PREFIX_.'caryear y inner join '
		._DB_PREFIX_.'carmake ma on y.makeid = ma.makeid inner join '
		._DB_PREFIX_.'carmodel mo on y.modelid = mo.modelid inner join '
		._DB_PREFIX_.'cartype fy on y.typeid = fy.typeid ORDER BY ma.makename ASC')){
			$total_row = $row['total'];
		}
		if(Tools::getValue('page') && Tools::getValue('page') != ''){
			$pageId = Tools::getValue('page');
		}

Or my be this is the problem.
 

//view operation
	  	if(Tools::getValue('edit')){
			if($row = Db::getInstance()->getRow('SELECT * FROM '._DB_PREFIX_.'caryear where yearid='.Tools::getValue('edit'))){
				$this->makeid = $row['makeid'];
				$this->modelid = $row['modelid'];
				$this->typeid = $row['typeid'];
				$this->yearid = Tools::getValue('edit');
				$this->year = $row['year'];
				if ($results = Db::getInstance()->ExecuteS('SELECT * FROM '._DB_PREFIX_.'carmodel where makeid='.(int)$row['makeid'])){
					foreach($results as $row){
						$this->model_list[] = array(
							'modelid'			=> $row['modelid'],
							'modelname'			=> $row['modelname']
						);

I hope someone can help me, im stuck now.

 

Untitled.png

spc

spc

I have tried now for a few day´s to create a module. Its going to be a easy one, that add some variable to different table, and show them in a list when you select from a dropdown. I'm only still in admin, the front do i create later,

I follow a tutorials that was easy to follow.
https://blog.floriancourgey.com/2018/05/create-an-admin-for-a-customized-sql-table/

CREATE TABLE pasta (
  `id` INT NOT NULL AUTO_INCREMENT,
  `sku` VARCHAR(255) NOT NULL,
  `name` VARCHAR(255) NOT NULL,
  `description` TEXT,
  `id_pasta_category` INT NOT NULL,
  `created` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
) ENGINE = InnoDB;

Then i copy the ObjectModel class /override/classes/fc_pasta/Pasta.php

<?php
class Pasta extends ObjectModel {
  public $id; // fields are mandatory for create/update
  public $sku;
  public $name;
  public $created;
  public $category;
  public $id_pasta_category;
  public static $definition = [
    'table' => 'pasta',
    'primary' => 'id',
    'fields' => [
      'sku' =>  ['type' => self::TYPE_STRING, 'validate' => 'isAnything', 'required'=>true],
      'name' =>  ['type' => self::TYPE_STRING, 'validate' => 'isAnything', 'required'=>true],
      'description' =>  ['type' => self::TYPE_HTML, 'validate' => 'isAnything',],
      'created' =>  ['type' => self::TYPE_DATE, 'validate' => 'isDateFormat'],
      'id_pasta_category' => ['type'=>self::TYPE_INT, 'validate'=>'isUnsignedInt','required'=>true,],
    ],
  ];
}

And after that i copy the module /modules/fc_pasta/fc_pasta.php

<?php
if (!defined('_PS_VERSION_')) {exit;}
class Fc_Pasta extends Module {
  public function __construct() {
      $this->name = 'fc_pasta'; // must match folder & file name
      $this->tab = 'administration';
      $this->version = '1.0.0';
      $this->author = 'Florian Courgey';
      $this->bootstrap = true; // use Bootstrap CSS
      parent::__construct();
      $this->displayName = $this->l('PrestaShop Module by FC');
      $this->description = $this->l('Improve your store by [...]');
      $this->ps_versions_compliancy = ['min' => '1.7', 'max' => _PS_VERSION_];
      // install Tab to register AdminController in the database
      $tab = new Tab();
      $tab->class_name = 'AdminPasta';
      $tab->module = $this->name;
      $tab->id_parent = (int)Tab::getIdFromClassName('DEFAULT');
      $tab->icon = 'settings_applications';
      $languages = Language::getLanguages();
      foreach ($languages as $lang) {
          $tab->name[$lang['id_lang']] = $this->l('FC Pasta Admin controller');
      }
      $tab->save();
  }
}

And after that i create the AdminPastaController

<?php
require_once _PS_ROOT_DIR_.'/override/classes/fc_pasta/Pasta.php';

class AdminPastaController extends ModuleAdminController {
  public function __construct(){
      parent::__construct();
        
        // Base
        $this->bootstrap = true; // use Bootstrap CSS
        $this->table = 'pasta'; // SQL table name, will be prefixed with _DB_PREFIX_
        $this->identifier = 'id'; // SQL column to be used as primary key
        $this->className = 'Pasta'; // PHP class name
        $this->allow_export = true; // allow export in CSV, XLS..

        // List records
        $this->_defaultOrderBy = 'a.sku'; // the table alias is always `a`
        $this->_defaultOrderWay = 'ASC';
        $this->_select = 'a.name as `pastaName`, cl.name as `categoryName`';
        $this->_join = '
            LEFT JOIN `'._DB_PREFIX_.'category` cat ON (cat.id_category=a.id_pasta_category)
            LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (cat.id_category=cl.id_category and cat.id_shop_default=cl.id_shop)';
        $this->fields_list = [
            'id' => ['title' => 'ID','class' => 'fixed-width-xs'],
            'sku' => ['title' => 'SKU'],
            'pastaName' => ['title' => 'Name', 'filter_key'=>'a!name'], // filter_key mandatory because "name" is ambiguous for SQL
            'categoryName' => ['title' => 'Category', 'filter_key'=>'cl!name'], // filter_key mandatory because JOIN
            'created' => ['title' => 'Created','type'=>'datetime'],
        ];

        // Read & update record
        $this->addRowAction('details');
        $this->addRowAction('edit');
        $categories = Category::getCategories($this->context->language->id, $active=true, $order=false); // [0=>[id_category=>X,name=>Y]..]
        $categories = [['id'=>1, 'display'=> 'abc'], ['id'=>2, 'display'=>'def']];
        $this->fields_form = [
            'legend' => [
            'title' => 'Pasta',
            'icon' => 'icon-list-ul'
        ],
      'input' => [
        ['type'=>'html','html_content'=>'<div class="alert alert-info">Put here any info content</div>'],
    ['name'=>'id_xxx','label'=>'XXX','type'=>'select',
      'options'=>[ 'query'=>$categories,
        'id'=>'id', // use the key id as the <option> value
        'name'=> 'display', // use the key display as the <option> title
      ]
    ],
        ['name'=>'name','type'=>'text','label'=>'Name','required'=>true],
        ['name'=>'description','type'=>'textarea','label'=>'Description',],
        ['name'=>'created','type'=>'datetime','label'=>'Created',],
        ['name'=>'id_pasta_category','label'=>'Category','type'=>'select','required'=>true,'class'=>'select2',
          'options'=>[ 'query'=>$categories,
            'id'=>'id_category', // use the key "id_category" as the <option> value
            'name'=> 'name', // use the key "name" as the <option> title
        ]],
      ],
      'submit' => [
        'title' => $this->trans('Save', [], 'Admin.Actions'),
      ]
    ];
  }
   protected function getFromClause() {
     return str_replace(_DB_PREFIX_, '', parent::getFromClause());
 }
}

Everything almost ok, but every time I update the page it create a new menu all the time: FC Pasta Admin controller, instead of 1 I have 25 now.

And one more thing, everything i do in the module i get INVALID SECURITY TOKEN

I'm really new to create modules to PS 1.7, but i really want to try.

spc

spc

I have tried now for a few day´s to create a module. Its going to be a easy one, that add some variable to different table, and show them in a list when you select from a dropdown. I'm only still in admin, the front do i create later,

I follow a tutorials that was easy to follow.
https://blog.floriancourgey.com/2018/05/create-an-admin-for-a-customized-sql-table/

CREATE TABLE pasta (
  `id` INT NOT NULL AUTO_INCREMENT,
  `sku` VARCHAR(255) NOT NULL,
  `name` VARCHAR(255) NOT NULL,
  `description` TEXT,
  `id_pasta_category` INT NOT NULL,
  `created` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
) ENGINE = InnoDB;

Then i copy the ObjectModel class /override/classes/fc_pasta/Pasta.php

<?php
class Pasta extends ObjectModel {
  public $id; // fields are mandatory for create/update
  public $sku;
  public $name;
  public $created;
  public $category;
  public $id_pasta_category;
  public static $definition = [
    'table' => 'pasta',
    'primary' => 'id',
    'fields' => [
      'sku' =>  ['type' => self::TYPE_STRING, 'validate' => 'isAnything', 'required'=>true],
      'name' =>  ['type' => self::TYPE_STRING, 'validate' => 'isAnything', 'required'=>true],
      'description' =>  ['type' => self::TYPE_HTML, 'validate' => 'isAnything',],
      'created' =>  ['type' => self::TYPE_DATE, 'validate' => 'isDateFormat'],
      'id_pasta_category' => ['type'=>self::TYPE_INT, 'validate'=>'isUnsignedInt','required'=>true,],
    ],
  ];
}

Everything almost ok, but every time I update the page it create a new menu all the time: FC Pasta Admin controller, instead of 1 I have 25 now.

That I can´t find why.

And one more thing, everything i do in the module i get INVALID SECURITY TOKEN

I'm really new to create modules to PS 1.7, but i really want to try.

I tried to add the code but i only get error security error on the page, why i don´t now.

spc

spc

I have tried now for a few day´s to create a module. Its going to be a easy one, that add some variable to different table, and show them in a list when you select from a dropdown. I'm only still in admin, the front do i create later,

I follow a tutorials that was easy to follow.
https://blog.floriancourgey.com/2018/05/create-an-admin-for-a-customized-sql-table/

CREATE TABLE pasta (
  `id` INT NOT NULL AUTO_INCREMENT,
  `sku` VARCHAR(255) NOT NULL,
  `name` VARCHAR(255) NOT NULL,
  `description` TEXT,
  `id_pasta_category` INT NOT NULL,
  `created` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
) ENGINE = InnoDB;

 

Everything almost ok, but every time I update the page it create a new menu all the time: FC Pasta Admin controller, instead of 1 I have 25 now.

That I can´t find why.

And one more thing, everything i do in the module i get INVALID SECURITY TOKEN

I'm really new to create modules to PS 1.7, but i really want to try.

I tried to add the code but i only get error security error on the page, why i don´t now.

spc

spc

I have tried now for a few day´s to create a module. Its going to be a easy one, that add some variable to different table, and show them in a list when you select from a dropdown. I'm only still in admin, the front do i create later,

I follow a tutorials that was easy to follow.
https://blog.floriancourgey.com/2018/05/create-an-admin-for-a-customized-sql-table/

Everything almost ok, but every time I update the page it create a new menu all the time: FC Pasta Admin controller, instead of 1 I have 25 now.

That I can´t find why.

And one more thing, everything i do in the module i get INVALID SECURITY TOKEN

I'm really new to create modules to PS 1.7, but i really want to try.

I tried to add the code but i only get error security error on the page, why i don´t now.

×
×
  • Create New...