Do this modification on your own responsibility!
Make a backup of database & (Field.php , Item.php) files in "\oc-includes\osclass\model\" before doing any changes!
NOTE: After this modification you need to edit manually the order/position for each custom field on the database! You can't do it on oc-admin!
If you add a new custom field make sure to edit the position number or it will be displayed at the top of custom fields!
Requirements:1.Basic knowledge of PHP and SQL (MySQL).
2.Access to database, (phpmyadmin) or mysql command line.
Tasks:1.Add a column to
oc_t_meta_fields table.
2.Edit files (
Field.php ,
Item.php) in "
\oc-includes\osclass\model\"
===========================================
First you need to create a column to
oc_t_meta_fields table. To do that, login to
PhpMyAdmin, Select the database that you have installed Osclass, click on
SQL tab and
run this query:
ALTER TABLE `oc_t_meta_fields` ADD `c_position` INT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER `b_searchable`;
Warning: If you have changed the default
Database Table Prefix don't forget to change the
oc prefix from code above! (For example:
customprefix_t_meta_fields)
===========================================
Go to
\oc-includes\osclass\model\ and edit:
Field.php:Find: (Line 62)$this->setFields( array('pk_i_id', 's_name', 'e_type', 'b_required', 'b_searchable', 's_slug', 's_options') );
Replace with:$this->setFields( array('pk_i_id', 's_name', 'e_type', 'b_required', 'b_searchable', 's_slug', 's_options', 'c_position') );
Find: (Line 96) public function findByCategory($id)
{
$this->dao->select('mf.*');
$this->dao->from(sprintf('%st_meta_fields mf, %st_meta_categories mc', DB_TABLE_PREFIX, DB_TABLE_PREFIX));
$this->dao->where('mc.fk_i_category_id', $id);
$this->dao->where('mf.pk_i_id = mc.fk_i_field_id');
$result = $this->dao->get();
if( $result == false ) {
return array();
}
return $result->result();
}
Replace with: public function findByCategory($id)
{
$this->dao->select('mf.*');
$this->dao->from(sprintf('%st_meta_fields mf, %st_meta_categories mc', DB_TABLE_PREFIX, DB_TABLE_PREFIX));
$this->dao->where('mc.fk_i_category_id', $id);
$this->dao->where('mf.pk_i_id = mc.fk_i_field_id');
$this->dao->orderBy('c_position', 'ASC');
$result = $this->dao->get();
if( $result == false ) {
return array();
}
return $result->result();
}
Find: (Line 164) public function findByCategoryItem($catId, $itemId)
{
if( !is_numeric($catId) || (!is_numeric($itemId) && $itemId != null) ) {
return array();
}
$result = $this->dao->query(sprintf("SELECT query.*, im.s_value as s_value, im.fk_i_item_id FROM (SELECT mf.* FROM %st_meta_fields mf, %st_meta_categories mc WHERE mc.fk_i_category_id = %d AND mf.pk_i_id = mc.fk_i_field_id) as query LEFT JOIN %st_item_meta im ON im.fk_i_field_id = query.pk_i_id AND im.fk_i_item_id = %d group by pk_i_id", DB_TABLE_PREFIX, DB_TABLE_PREFIX, $catId, DB_TABLE_PREFIX, $itemId));
if( $result == false ) {
return array();
}
return $result->result();
}
Replace with: public function findByCategoryItem($catId, $itemId)
{
if( !is_numeric($catId) || (!is_numeric($itemId) && $itemId != null) ) {
return array();
}
$result = $this->dao->query(sprintf("SELECT query.*, im.s_value as s_value, im.fk_i_item_id FROM (SELECT mf.* FROM %st_meta_fields mf, %st_meta_categories mc WHERE mc.fk_i_category_id = %d AND mf.pk_i_id = mc.fk_i_field_id) as query LEFT JOIN %st_item_meta im ON im.fk_i_field_id = query.pk_i_id AND im.fk_i_item_id = %d group by pk_i_id order by c_position", DB_TABLE_PREFIX, DB_TABLE_PREFIX, $catId, DB_TABLE_PREFIX, $itemId));
if( $result == false ) {
return array();
}
return $result->result();
}
===========================================
Go to
\oc-includes\osclass\model\ and edit:
Item.php:Find: (Line 904) public function metaFields($id)
{
$this->dao->select('im.s_value as s_value,mf.pk_i_id as pk_i_id, mf.s_name as s_name, mf.e_type as e_type, im.s_multi as s_multi, mf.s_slug as s_slug ');
$this->dao->from($this->getTableName().' i, '.DB_TABLE_PREFIX.'t_item_meta im, '.DB_TABLE_PREFIX.'t_meta_categories mc, '.DB_TABLE_PREFIX.'t_meta_fields mf');
$this->dao->where('mf.pk_i_id = im.fk_i_field_id');
$this->dao->where('mf.pk_i_id = mc.fk_i_field_id');
$this->dao->where('mc.fk_i_category_id = i.fk_i_category_id');
$array_where = array(
'im.fk_i_item_id' => $id,
'i.pk_i_id' => $id
);
$this->dao->where($array_where);
$result = $this->dao->get();
if($result == false) {
return array();
}
$aTemp = $result->result();
Replace with:public function metaFields($id)
{
$this->dao->select('im.s_value as s_value,mf.pk_i_id as pk_i_id, mf.s_name as s_name, mf.e_type as e_type, im.s_multi as s_multi, mf.s_slug as s_slug ');
$this->dao->from($this->getTableName().' i, '.DB_TABLE_PREFIX.'t_item_meta im, '.DB_TABLE_PREFIX.'t_meta_categories mc, '.DB_TABLE_PREFIX.'t_meta_fields mf');
$this->dao->where('mf.pk_i_id = im.fk_i_field_id');
$this->dao->where('mf.pk_i_id = mc.fk_i_field_id');
$this->dao->where('mc.fk_i_category_id = i.fk_i_category_id');
$array_where = array(
'im.fk_i_item_id' => $id,
'i.pk_i_id' => $id
);
$this->dao->where($array_where);
$this->dao->orderBy('c_position', 'ASC');
$result = $this->dao->get();
if($result == false) {
return array();
}
$aTemp = $result->result();
Done!To edit order/position of the custom field go to
phpmyadmin, -->
osclass database, select
oc_t_meta_fields table and modify the value of
c_position.
Hope this helps!