dbermudez Posted June 28, 2013 Share Posted June 28, 2013 (edited) Hi, I´m trying to enable a date field for the CMS in the Administration panel, I´ve added a new field myDate in the table ps_cms_lang with Type=Date. In file /classes/CMS.php I have done the following: class CMSCore extends ObjectModel { /** @var string Name */ public $meta_title; public $meta_description; public $meta_keywords; public $content; public $myDate; /** My variable Name**/ public $link_rewrite; public $id_cms_category; public $position; public $active; /** * @see ObjectModel::$definition */ public static $definition = array( 'table' => 'cms', 'primary' => 'id_cms', 'multilang' => true, 'fields' => array( 'id_cms_category' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'), 'position' => array('type' => self::TYPE_INT), 'active' => array('type' => self::TYPE_BOOL), /*Added myDate field*/ 'myDate' => array('type' => self::TYPE_DATE, 'validate' => 'isDate' ), //'myDate' => array('type' => self::TYPE_DATE, 'validate' => 'isDate', 'lang' => true ), // Lang fields 'meta_description' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 255), 'meta_keywords' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 255), 'meta_title' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 128), 'link_rewrite' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isLinkRewrite', 'required' => true, 'size' => 128), 'content' => array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString', 'size' => 3999999999999), ), ); And in file /controllers/AdminCmsController.php: class AdminCmsControllerCore extends AdminController { protected $category; public $id_cms_category; protected $position_identifier = 'id_cms'; public function __construct() { $this->table = 'cms'; $this->className = 'CMS'; $this->lang = true; $this->addRowAction('edit'); $this->addRowAction('delete'); $this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?'))); $this->fields_list = array( 'id_cms' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25), 'link_rewrite' => array('title' => $this->l('URL'), 'width' => 'auto'), 'meta_title' => array('title' => $this->l('Title'), 'width' => '300', 'filter_key' => 'b!meta_title'), 'position' => array('title' => $this->l('Position'), 'width' => 40,'filter_key' => 'position', 'align' => 'center', 'position' => 'position'), 'active' => array('title' => $this->l('Displayed'), 'width' => 25, 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false) ); // The controller can't be call directly // In this case, AdminCmsContentController::getCurrentCMSCategory() is null if (!AdminCmsContentController::getCurrentCMSCategory()) { $this->redirect_after = '?controller=AdminCmsContent&token='.Tools::getAdminTokenLite('AdminCmsContent'); $this->redirect(); } $this->_category = AdminCmsContentController::getCurrentCMSCategory(); $this->_join = ' LEFT JOIN `'._DB_PREFIX_.'cms_category` c ON (c.`id_cms_category` = a.`id_cms_category`)'; $this->_select = 'a.position '; $this->_filter = 'AND c.id_cms_category = '.(int)$this->_category->id; parent::__construct(); } public function renderForm() { if (!$this->loadObject(true)) return; if (Validate::isLoadedObject($this->object)) $this->display = 'edit'; else $this->display = 'add'; $this->toolbar_btn['save-and-preview'] = array( 'href' => '#', 'desc' => $this->l('Save and preview') ); $this->toolbar_btn['save-and-stay'] = array( 'short' => 'SaveAndStay', 'href' => '#', 'desc' => $this->l('Save and stay'), ); $this->initToolbar(); $categories = CMSCategory::getCategories($this->context->language->id, false); $html_categories = CMSCategory::recurseCMSCategory($categories, $categories[0][1], 1, $this->getFieldValue($this->object, 'id_cms_category'), 1); $this->fields_form = array( 'tinymce' => true, 'legend' => array( 'title' => $this->l('CMS Page'), 'image' => '../img/admin/tab-categories.gif' ), 'input' => array( // custom template array( 'type' => 'select_category', 'label' => $this->l('CMS Category'), 'name' => 'id_cms_category', 'options' => array( 'html' => $html_categories, ), ), array( 'type' => 'text', 'label' => $this->l('Meta title:'), 'name' => 'meta_title', 'id' => 'name', // for copy2friendlyUrl compatibility 'lang' => true, 'required' => true, 'class' => 'copy2friendlyUrl', 'hint' => $this->l('Invalid characters:').' <>;=#{}', 'size' => 50 ), array( 'type' => 'text', 'label' => $this->l('Meta description'), 'name' => 'meta_description', 'lang' => true, 'hint' => $this->l('Invalid characters:').' <>;=#{}', 'size' => 70 ), array( 'type' => 'tags', 'label' => $this->l('Meta keywords'), 'name' => 'meta_keywords', 'lang' => true, 'hint' => $this->l('Invalid characters:').' <>;=#{}', 'size' => 70, 'desc' => $this->l('To add "tags" click in the field, write something, and then press "Enter."') ), array( 'type' => 'text', 'label' => $this->l('Friendly URL'), 'name' => 'link_rewrite', 'required' => true, 'lang' => true, 'hint' => $this->l('Only letters and the minus (-) character are allowed') ), array( 'type' => 'textarea', 'label' => $this->l('Page content'), 'name' => 'content', 'autoload_rte' => true, 'lang' => true, 'rows' => 5, 'cols' => 40, 'hint' => $this->l('Invalid characters:').' <>;=#{}' ), //<------------------------------------------------------ myDate field array( 'type' => 'date', 'label' => $this->l('Fecha Evento'), 'name' => 'myDate', 'required' => false, ), //<------------------------------------------------END myDate field array( 'type' => 'radio', 'label' => $this->l('Displayed:'), 'name' => 'active', 'required' => false, 'class' => 't', 'is_bool' => true, 'values' => array( array( 'id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled') ), array( 'id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled') ) ), ), ), 'submit' => array( 'title' => $this->l('Save'), 'class' => 'button' ) ); I get the date saved in the DB when in CMS.php y use 'lang'=>true for the field (That doesn't make much sense for me). But the date I save is not displayed in the field, intead I get the followinf error inside the field: Untitled.tiff Warning: htmlspecialchars() expects parameter 1 to be string, array given in /MAMP/htdocs/store/tools/smarty/plugins/modifier.escape.php on line 63 Any ideas? Edited July 1, 2013 by dbermudez (see edit history) Link to comment Share on other sites More sharing options...
SmartDataSoft Posted June 28, 2013 Share Posted June 28, 2013 (edited) Hello, dbermudez It is not better way to modified the core file as in that case you will lose your class and controller file if you update in future. Your problem is interesting so i take my time to solve the issue. Here is what you need to do. 1. copy CMS.php to override->classes->CMS.php and add your code. bellow is my code . <?php /* * 2007-2013 PrestaShop * * NOTICE OF LICENSE * * This source file is subject to the Open Software License (OSL 3.0) * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/osl-3.0.php * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to [email protected] so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade PrestaShop to newer * versions in the future. If you wish to customize PrestaShop for your * needs please refer to http://www.prestashop.com for more information. * * @author PrestaShop SA <[email protected]> * @copyright 2007-2013 PrestaShop SA * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ class CMSCore extends ObjectModel { /** @var string Name */ public $meta_title; public $meta_description; public $meta_keywords; public $content; public $link_rewrite; public $id_cms_category; public $position; public $active; public $myDate; /** My variable Name**/ /** * @see ObjectModel::$definition */ public static $definition = array( 'table' => 'cms', 'primary' => 'id_cms', 'multilang' => true, 'fields' => array( 'id_cms_category' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'), 'position' => array('type' => self::TYPE_INT), 'active' => array('type' => self::TYPE_BOOL), /*Added myDate field*/ 'myDate' => array('type' => self::TYPE_DATE, 'validate' => 'isDate' ), //'myDate' => array('type' => self::TYPE_DATE, 'validate' => 'isDate', 'lang' => true ), // // Lang fields 'meta_description' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 255), 'meta_keywords' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 255), 'meta_title' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 128), 'link_rewrite' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isLinkRewrite', 'required' => true, 'size' => 128), 'content' => array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString', 'size' => 3999999999999), ), ); protected $webserviceParameters = array( 'objectNodeName' => 'content', 'objectsNodeName' => 'content_management_system', ); public function add($autodate = true, $null_values = false) { $this->position = CMS::getLastPosition((int)$this->id_cms_category); return parent::add($autodate, true); } public function update($null_values = false) { if (parent::update($null_values)) return $this->cleanPositions($this->id_cms_category); return false; } public function delete() { if (parent::delete()) return $this->cleanPositions($this->id_cms_category); return false; } public static function getLinks($id_lang, $selection = null, $active = true, Link $link = null) { if (!$link) $link = Context::getContext()->link; $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT c.id_cms, cl.link_rewrite, cl.meta_title FROM '._DB_PREFIX_.'cms c LEFT JOIN '._DB_PREFIX_.'cms_lang cl ON (c.id_cms = cl.id_cms AND cl.id_lang = '.(int)$id_lang.') '.Shop::addSqlAssociation('cms', 'c').' WHERE 1 '.(($selection !== null) ? ' AND c.id_cms IN ('.implode(',', array_map('intval', $selection)).')' : ''). ($active ? ' AND c.`active` = 1 ' : ''). 'GROUP BY c.id_cms ORDER BY c.`position`'); $links = array(); if ($result) foreach ($result as $row) { $row['link'] = $link->getCMSLink((int)$row['id_cms'], $row['link_rewrite']); $links[] = $row; } return $links; } public static function listCms($id_lang = null, $id_block = false, $active = true) { if (empty($id_lang)) $id_lang = (int)Configuration::get('PS_LANG_DEFAULT'); return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT c.id_cms, l.meta_title FROM '._DB_PREFIX_.'cms c JOIN '._DB_PREFIX_.'cms_lang l ON (c.id_cms = l.id_cms) '.Shop::addSqlAssociation('cms', 'c').' '.(($id_block) ? 'JOIN '._DB_PREFIX_.'block_cms b ON (c.id_cms = b.id_cms)' : '').' WHERE l.id_lang = '.(int)$id_lang.(($id_block) ? ' AND b.id_block = '.(int)$id_block : '').($active ? ' AND c.`active` = 1 ' : '').' GROUP BY c.id_cms ORDER BY c.`position`'); } public function updatePosition($way, $position) { if (!$res = Db::getInstance()->executeS(' SELECT cp.`id_cms`, cp.`position`, cp.`id_cms_category` FROM `'._DB_PREFIX_.'cms` cp WHERE cp.`id_cms_category` = '.(int)$this->id_cms_category.' ORDER BY cp.`position` ASC' )) return false; foreach ($res as $cms) if ((int)$cms['id_cms'] == (int)$this->id) $moved_cms = $cms; if (!isset($moved_cms) || !isset($position)) return false; // < and > statements rather than BETWEEN operator // since BETWEEN is treated differently according to databases return (Db::getInstance()->execute(' UPDATE `'._DB_PREFIX_.'cms` SET `position`= `position` '.($way ? '- 1' : '+ 1').' WHERE `position` '.($way ? '> '.(int)$moved_cms['position'].' AND `position` <= '.(int)$position : '< '.(int)$moved_cms['position'].' AND `position` >= '.(int)$position).' AND `id_cms_category`='.(int)$moved_cms['id_cms_category']) && Db::getInstance()->execute(' UPDATE `'._DB_PREFIX_.'cms` SET `position` = '.(int)$position.' WHERE `id_cms` = '.(int)$moved_cms['id_cms'].' AND `id_cms_category`='.(int)$moved_cms['id_cms_category'])); } public static function cleanPositions($id_category) { $sql = ' SELECT `id_cms` FROM `'._DB_PREFIX_.'cms` WHERE `id_cms_category` = '.(int)$id_category.' ORDER BY `position`'; $result = Db::getInstance()->executeS($sql); for ($i = 0, $total = count($result); $i < $total; ++$i) { $sql = 'UPDATE `'._DB_PREFIX_.'cms` SET `position` = '.(int)$i.' WHERE `id_cms_category` = '.(int)$id_category.' AND `id_cms` = '.(int)$result[$i]['id_cms']; Db::getInstance()->execute($sql); } return true; } public static function getLastPosition($id_category) { $sql = ' SELECT MAX(position) + 1 FROM `'._DB_PREFIX_.'cms` WHERE `id_cms_category` = '.(int)$id_category; return (Db::getInstance()->getValue($sql)); } public static function getCMSPages($id_lang = null, $id_cms_category = null, $active = true) { $sql = new DbQuery(); $sql->select('*'); $sql->from('cms', 'c'); if ($id_lang) $sql->innerJoin('cms_lang', 'l', 'c.id_cms = l.id_cms AND l.id_lang = '.(int)$id_lang); if ($active) $sql->where('c.active = 1'); if ($id_cms_category) $sql->where('c.id_cms_category = '.(int)$id_cms_category); $sql->orderBy('position'); return Db::getInstance()->executeS($sql); } public static function getUrlRewriteInformations($id_cms) { $sql = 'SELECT l.`id_lang`, c.`link_rewrite` FROM `'._DB_PREFIX_.'cms_lang` AS c LEFT JOIN `'._DB_PREFIX_.'lang` AS l ON c.`id_lang` = l.`id_lang` WHERE c.`id_cms` = '.(int)$id_cms.' AND l.`active` = 1'; return Db::getInstance()->executeS($sql); } } after that copy AdminCmsController to override->controllers->admin->AdminCmsController.php and write my code like bellow. <?php /* * 2007-2013 PrestaShop * * NOTICE OF LICENSE * * This source file is subject to the Open Software License (OSL 3.0) * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/osl-3.0.php * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to [email protected] so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade PrestaShop to newer * versions in the future. If you wish to customize PrestaShop for your * needs please refer to http://www.prestashop.com for more information. * * @author PrestaShop SA <[email protected]> * @copyright 2007-2013 PrestaShop SA * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ class AdminCmsControllerCore extends AdminController { protected $category; public $id_cms_category; protected $position_identifier = 'id_cms'; public function __construct() { $this->table = 'cms'; $this->className = 'CMS'; $this->lang = true; $this->addRowAction('edit'); $this->addRowAction('delete'); $this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?'))); $this->fields_list = array( 'id_cms' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25), 'link_rewrite' => array('title' => $this->l('URL'), 'width' => 'auto'), 'myDate' => array('myDate' => $this->l('Date'), 'width' => 'auto'), 'meta_title' => array('title' => $this->l('Title'), 'width' => '300', 'filter_key' => 'b!meta_title'), 'position' => array('title' => $this->l('Position'), 'width' => 40,'filter_key' => 'position', 'align' => 'center', 'position' => 'position'), 'active' => array('title' => $this->l('Displayed'), 'width' => 25, 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false) ); // The controller can't be call directly // In this case, AdminCmsContentController::getCurrentCMSCategory() is null if (!AdminCmsContentController::getCurrentCMSCategory()) { $this->redirect_after = '?controller=AdminCmsContent&token='.Tools::getAdminTokenLite('AdminCmsContent'); $this->redirect(); } $this->_category = AdminCmsContentController::getCurrentCMSCategory(); $this->_join = ' LEFT JOIN `'._DB_PREFIX_.'cms_category` c ON (c.`id_cms_category` = a.`id_cms_category`)'; $this->_select = 'a.position '; $this->_filter = 'AND c.id_cms_category = '.(int)$this->_category->id; parent::__construct(); } public function renderForm() { if (!$this->loadObject(true)) return; if (Validate::isLoadedObject($this->object)) $this->display = 'edit'; else $this->display = 'add'; $this->toolbar_btn['save-and-preview'] = array( 'href' => '#', 'desc' => $this->l('Save and preview') ); $this->toolbar_btn['save-and-stay'] = array( 'short' => 'SaveAndStay', 'href' => '#', 'desc' => $this->l('Save and stay'), ); $this->initToolbar(); $categories = CMSCategory::getCategories($this->context->language->id, false); $html_categories = CMSCategory::recurseCMSCategory($categories, $categories[0][1], 1, $this->getFieldValue($this->object, 'id_cms_category'), 1); $this->fields_form = array( 'tinymce' => true, 'legend' => array( 'title' => $this->l('CMS Page'), 'image' => '../img/admin/tab-categories.gif' ), 'input' => array( // custom template array( 'type' => 'select_category', 'label' => $this->l('CMS Category'), 'name' => 'id_cms_category', 'options' => array( 'html' => $html_categories, ), ), array( 'type' => 'text', 'label' => $this->l('Meta title:'), 'name' => 'meta_title', 'id' => 'name', // for copy2friendlyUrl compatibility 'lang' => true, 'required' => true, 'class' => 'copy2friendlyUrl', 'hint' => $this->l('Invalid characters:').' <>;=#{}', 'size' => 50 ), array( 'type' => 'text', 'label' => $this->l('Meta description'), 'name' => 'meta_description', 'lang' => true, 'hint' => $this->l('Invalid characters:').' <>;=#{}', 'size' => 70 ), array( 'type' => 'tags', 'label' => $this->l('Meta keywords'), 'name' => 'meta_keywords', 'lang' => true, 'hint' => $this->l('Invalid characters:').' <>;=#{}', 'size' => 70, 'desc' => $this->l('To add "tags" click in the field, write something, and then press "Enter."') ), array( 'type' => 'text', 'label' => $this->l('Friendly URL'), 'name' => 'link_rewrite', 'required' => true, 'lang' => true, 'hint' => $this->l('Only letters and the minus (-) character are allowed') ), array( 'type' => 'textarea', 'label' => $this->l('Page content'), 'name' => 'content', 'autoload_rte' => true, 'lang' => true, 'rows' => 5, 'cols' => 40, 'hint' => $this->l('Invalid characters:').' <>;=#{}' ), //<------------------------------------------------------ myDate field array( 'type' => 'date', 'label' => $this->l('Fecha Evento'), 'name' => 'myDate', 'required' => false, ), //<------------------------------------------------END myDate field array( 'type' => 'radio', 'label' => $this->l('Displayed:'), 'name' => 'active', 'required' => false, 'class' => 't', 'is_bool' => true, 'values' => array( array( 'id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled') ), array( 'id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled') ) ), ), ), 'submit' => array( 'title' => $this->l('Save'), 'class' => 'button' ) ); if (Shop::isFeatureActive()) { $this->fields_form['input'][] = array( 'type' => 'shop', 'label' => $this->l('Shop association:'), 'name' => 'checkBoxShopAsso', ); } $this->tpl_form_vars = array( 'active' => $this->object->active, 'PS_ALLOW_ACCENTED_CHARS_URL', (int)Configuration::get('PS_ALLOW_ACCENTED_CHARS_URL') ); return parent::renderForm(); } public function renderList() { $this->toolbar_title = $this->l('Pages in this category'); $this->toolbar_btn['new'] = array( 'href' => self::$currentIndex.'&add'.$this->table.'&id_cms_category='.(int)$this->id_cms_category.'&token='.$this->token, 'desc' => $this->l('Add new') ); return parent::renderList(); } public function displayList($token = null) { /* Display list header (filtering, pagination and column names) */ $this->displayListHeader($token); if (!count($this->_list)) echo '<tr><td class="center" colspan="'.(count($this->fields_list) + 2).'">'.$this->l('No items found').'</td></tr>'; /* Show the content of the table */ $this->displayListContent($token); /* Close list table and submit button */ $this->displayListFooter($token); } public function postProcess() { if (Tools::isSubmit($this->table.'Orderby') || Tools::isSubmit($this->table.'Orderway')) $this->filter = true; if (Tools::isSubmit('viewcms') && ($id_cms = (int)Tools::getValue('id_cms')) && ($cms = new CMS($id_cms, $this->context->language->id)) && Validate::isLoadedObject($cms)) { $redir = $this->context->link->getCMSLink($cms); if (!$cms->active) { $admin_dir = dirname($_SERVER['PHP_SELF']); $admin_dir = substr($admin_dir, strrpos($admin_dir, '/') + 1); $redir .= '?adtoken='.Tools::getAdminTokenLite('AdminCmsContent').'&ad='.$admin_dir.'&id_employee='.(int)$this->context->employee->id; } Tools::redirectAdmin($redir); } elseif (Tools::isSubmit('deletecms')) { if (Tools::getValue('id_cms') == Configuration::get('PS_CONDITIONS_CMS_ID')) { Configuration::updateValue('PS_CONDITIONS', 0); Configuration::updateValue('PS_CONDITIONS_CMS_ID', 0); } $cms = new CMS((int)Tools::getValue('id_cms')); $cms->cleanPositions($cms->id_cms_category); if (!$cms->delete()) $this->errors[] = Tools::displayError('An error occurred while deleting the object.') .' <b>'.$this->table.' ('.Db::getInstance()->getMsgError().')</b>'; else Tools::redirectAdmin(self::$currentIndex.'&id_cms_category='.$cms->id_cms_category.'&conf=1&token='.Tools::getAdminTokenLite('AdminCmsContent')); }/* Delete multiple objects */ elseif (Tools::getValue('submitDel'.$this->table)) { if ($this->tabAccess['delete'] === '1') { if (Tools::isSubmit($this->table.'Box')) { $cms = new CMS(); $result = true; $result = $cms->deleteSelection(Tools::getValue($this->table.'Box')); if ($result) { $cms->cleanPositions((int)Tools::getValue('id_cms_category')); $token = Tools::getAdminTokenLite('AdminCmsContent'); Tools::redirectAdmin(self::$currentIndex.'&conf=2&token='.$token.'&id_cms_category='.(int)Tools::getValue('id_cms_category')); } $this->errors[] = Tools::displayError('An error occurred while deleting this selection.'); } else $this->errors[] = Tools::displayError('You must select at least one element to delete.'); } else $this->errors[] = Tools::displayError('You do not have permission to delete this.'); } elseif (Tools::isSubmit('submitAddcms') || Tools::isSubmit('submitAddcmsAndPreview')) { parent::validateRules(); if (count($this->errors)) return false; if (!$id_cms = (int)Tools::getValue('id_cms')) { $cms = new CMS(); $this->copyFromPost($cms, 'cms'); if (!$cms->add()) $this->errors[] = Tools::displayError('An error occurred while creating an object.') .' <b>'.$this->table.' ('.Db::getInstance()->getMsgError().')</b>'; else $this->updateAssoShop($cms->id); } else { $cms = new CMS($id_cms); $this->copyFromPost($cms, 'cms'); if (!$cms->update()) $this->errors[] = Tools::displayError('An error occurred while updating an object.') .' <b>'.$this->table.' ('.Db::getInstance()->getMsgError().')</b>'; else $this->updateAssoShop($cms->id); } if (Tools::isSubmit('submitAddcmsAndPreview')) { $alias = $this->getFieldValue($cms, 'link_rewrite', $this->context->language->id); $preview_url = $this->context->link->getCMSLink($cms, $alias, $this->context->language->id); if (!$cms->active) { $admin_dir = dirname($_SERVER['PHP_SELF']); $admin_dir = substr($admin_dir, strrpos($admin_dir, '/') + 1); $params = http_build_query(array( 'adtoken' => Tools::getAdminTokenLite('AdminCmsContent'), 'ad' => $admin_dir, 'id_employee' => (int)$this->context->employee->id) ); if (Configuration::get('PS_REWRITING_SETTINGS')) $params = '?'.$params; else $params = '&'.$params; $preview_url .= $cms->active ? '' : $params; } Tools::redirectAdmin($preview_url); } elseif (Tools::isSubmit('submitAdd'.$this->table.'AndStay')) Tools::redirectAdmin(self::$currentIndex.'&'.$this->identifier.'='.$cms->id.'&conf=4&update'.$this->table.'&token='.Tools::getAdminTokenLite('AdminCmsContent')); else Tools::redirectAdmin(self::$currentIndex.'&id_cms_category='.$cms->id_cms_category.'&conf=4&token='.Tools::getAdminTokenLite('AdminCmsContent')); } elseif (Tools::isSubmit('way') && Tools::isSubmit('id_cms') && (Tools::isSubmit('position'))) { if ($this->tabAccess['edit'] !== '1') $this->errors[] = Tools::displayError('You do not have permission to edit this.'); elseif (!Validate::isLoadedObject($object = $this->loadObject())) $this->errors[] = Tools::displayError('An error occurred while updating the status for an object.') .' <b>'.$this->table.'</b> '.Tools::displayError('(cannot load object)'); elseif (!$object->updatePosition((int)Tools::getValue('way'), (int)Tools::getValue('position'))) $this->errors[] = Tools::displayError('Failed to update the position.'); else Tools::redirectAdmin(self::$currentIndex.'&'.$this->table.'Orderby=position&'.$this->table.'Orderway=asc&conf=4&id_cms_category='.(int)$object->id_cms_category.'&token='.Tools::getAdminTokenLite('AdminCmsContent')); } /* Change object statuts (active, inactive) */ elseif (Tools::isSubmit('statuscms') && Tools::isSubmit($this->identifier)) { if ($this->tabAccess['edit'] === '1') { if (Validate::isLoadedObject($object = $this->loadObject())) { if ($object->toggleStatus()) Tools::redirectAdmin(self::$currentIndex.'&conf=5&id_cms_category='.(int)$object->id_cms_category.'&token='.Tools::getValue('token')); else $this->errors[] = Tools::displayError('An error occurred while updating the status.'); } else $this->errors[] = Tools::displayError('An error occurred while updating the status for an object.') .' <b>'.$this->table.'</b> '.Tools::displayError('(cannot load object)'); } else $this->errors[] = Tools::displayError('You do not have permission to edit this.'); } /* Delete multiple CMS content */ elseif (Tools::isSubmit('submitBulkdeletecms')) { if ($this->tabAccess['delete'] === '1') { $this->action = 'bulkdelete'; $this->boxes = Tools::getValue($this->table.'Box'); if (is_array($this->boxes) && array_key_exists(0, $this->boxes)) { $firstCms = new CMS((int)$this->boxes[0]); $id_cms_category = (int)$firstCms->id_cms_category; if (!$res = parent::postProcess(true)) return $res; Tools::redirectAdmin(self::$currentIndex.'&conf=2&token='.Tools::getAdminTokenLite('AdminCmsContent').'&id_cms_category='.$id_cms_category); } } else $this->errors[] = Tools::displayError('You do not have permission to delete this.'); } else parent::postProcess(true); } } Note that i do not add the mydate in language table i add that in ps_cms table As logically date filed do not need to multi language. And it work like a charme and see my page and out put is ok. I have test by changing my date. and it worked 100% without any error. Inform me if need any help. Edited June 28, 2013 by smartdatasoft (see edit history) 3 Link to comment Share on other sites More sharing options...
dbermudez Posted July 1, 2013 Author Share Posted July 1, 2013 Thanks man, works like a charm. Cheers! Link to comment Share on other sites More sharing options...
SmartDataSoft Posted July 1, 2013 Share Posted July 1, 2013 Thanks man, works like a charm. Cheers! Thanks, Please change the title ase [solved] Link to comment Share on other sites More sharing options...
fierymech Posted December 17, 2013 Share Posted December 17, 2013 Hi, I also have somewhat the same requirement but instead of adding a date field, I want to add a file field. I want to upload an image for a CMS page and / or CMS page under a created CMS Category page in the admin panel. The image as added will be unique to that page content itself. I could have added that image through fck editor but that will be a part of {$cms->content}. I need to create a field in ps_cms_lang as banner_image so that I can display that image on front end at a specific location at the top position. Can anybody pls help me in this regard. Thanks in advance 1 Link to comment Share on other sites More sharing options...
itklif Posted January 8, 2014 Share Posted January 8, 2014 UP Same problem for me, I think there is not a lot of change from the example here ... please help :-) i'm sur this is would be a great contribution !!! Arnaud Link to comment Share on other sites More sharing options...
PrestaShark Posted April 7, 2017 Share Posted April 7, 2017 Off topic but It not working with PS 1.6.1.x Date picker is available but cant save picked date ps_cms table with added mydate field show the current date after save cms page, but the cms admin page dont show even this date. how to show this date on front office cms page? variable {$myDate} doesnt work Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now