Chill_user Posted April 30, 2020 Share Posted April 30, 2020 (edited) Hello, I like to ask you how to create page programmatically from custom module? I know how to create controller and assign .tpl to this controller My idea: customer clicks "create" button from BO module page and it creates the page with url and page details he choosed. Thanks a lot! Edited May 4, 2020 by Amantha Bill (see edit history) Link to comment Share on other sites More sharing options...
Guest Posted May 2, 2020 Share Posted May 2, 2020 I already gave you the instructions. Creating a module is not a problem. Link to comment Share on other sites More sharing options...
Chill_user Posted May 4, 2020 Author Share Posted May 4, 2020 (edited) On 5/2/2020 at 7:21 AM, Guest said: I already gave you the instructions. Creating a module is not a problem. Thanks, but it is not the same problem. I need to create "CMS page" with no controller Something like: $cms = new CMS //to create page automatically $cms->link_rewrite; //add url link, etc $cms->add(); Do you know something about it? I saw there is a CMS class, but I didn't find the instructions about it Edited May 4, 2020 by Amantha Bill (see edit history) Link to comment Share on other sites More sharing options...
Guest Posted May 4, 2020 Share Posted May 4, 2020 Topic name = Create page programmatically change to Create CMS page programmatically 😉 Link to comment Share on other sites More sharing options...
Chill_user Posted May 4, 2020 Author Share Posted May 4, 2020 35 minutes ago, Guest said: Topic name = Create page programmatically change to Create CMS page programmatically 😉 Thanks, did it. As I understood, I need to create controller than class to create cms pages. I need to create something like "blog" with news of web-site. Can you help me? Link to comment Share on other sites More sharing options...
Guest Posted May 4, 2020 Share Posted May 4, 2020 (edited) It's not so easy. SQL queries must be used. It is impossible to write the whole code here. Just look at the tables in the database and then everything will be clear. Např.: // table ps_cms // // cms position $cms_position = Db::getInstance()->getValue('SELECT position FROM '._DB_PREFIX_.'cms ORDER BY position DESC') + 1; // cms category $cms_category = 1; // cms active $cms_active = 1; // cms indexation $cms_indexation = 1; // create cms id $cms = Db::getInstance()->Execute('INSERT INTO '._DB_PREFIX_.'cms (id_cms_category, position, active, indexation) VALUES ($cms_category, $cms_position, $cms_active, $cms_indexation)'); // inserted cms id $cms_id = Db::getInstance()->Insert_ID(); // table ps_cmas_lang // // cms for multistore $cms_shops = array(1,2); // cms for actual store $cms_shop = (int)Context::getContext()->shop->id; // cms languages for multistore $cms_langs_stores = Language::getLanguages(true); // cms languages for current store $cms_langs = Language::getLanguages(true, $this->context->shop->id); // cms current language $cms_lang = (int)Context::getContext()->language->id; $cms_meta_title = 'your metatitle'; $cms_seo_head_titile = 'your head seo titile'; $cms_meta_description = 'your meta description'; $cms_meta_keywords = 'your,meta,keywords'; $cms_content = 'your html content'; $cms_link_rewrite = 'your-link-rewrite'; // create cms page content Db::getInstance()->Execute("INSERT INTO "._DB_PREFIX_."cms_lang (id_cms, id_lang, id_shop, meta_title, head_so_title, meta_description, meta_keywords, content, link_rewrite) VALUES ($cms_id, $cms_lang, $cms_shop, '".$cms_meta_title."', '".$cms_seo_head_titile."', '".$cms_meta_description."', '".$cms_meta_keywords."', '".$cms_content."', '".$cms_link_rewrite."')"); // associate created cms page to shop Db::getInstance()->Execute('INSERT INTO '._DB_PREFIX_.'cms_shop (id_cms, id_shop) VALUES ($cms_id,$cms_shop); If you want to add more languages and more shops, you have to use foreach. Edited May 4, 2020 by Guest (see edit history) Link to comment Share on other sites More sharing options...
Chill_user Posted May 4, 2020 Author Share Posted May 4, 2020 (edited) 15 minutes ago, Guest said: It's not so easy. SQL queries must be used. It is impossible to write the whole code here. Just look at the tables in the database and then everything will be clear. Např.: // table ps_cms // // cms position $cms_position = Db::getInstance()->getValue('SELECT position FROM '._DB_PREFIX_.'cms ORDER BY position DESC') + 1; // cms category $cms_category = 1; // cms active $cms_active = 1; // cms indexation $cms_indexation = 1; // create cms id $cms = Db::getInstance()->Execute('INSERT INTO '._DB_PREFIX_.'cms (id_cms_category, position, active, indexation) VALUES ($cms_category, $cms_position, $cms_active, $cms_indexation)'); // inserted cms id $cms_id = Db::getInstance()->Insert_ID(); // table ps_cmas_lang // // cms for multistore $cms_shops = array(1,2); // cms for actual store $cms_shop = (int)Context::getContext()->shop->id; // cms languages for multistore $cms_langs_stores = Language::getLanguages(true); // cms languages for current store $cms_langs = Language::getLanguages(true, $this->context->shop->id); // cms current language $cms_lang = (int)Context::getContext()->language->id; $cms_meta_title = 'your metatitle'; $cms_seo_head_titile = 'your head seo titile'; $cms_meta_description = 'your meta description'; $cms_meta_keywords = 'your,meta,keywords'; $cms_content = 'your html content'; $cms_link_rewrite = 'your-link-rewrite'; // create cms page content Db::getInstance()->Execute("INSERT INTO "._DB_PREFIX_."cms_lang (id_cms, id_lang, id_shop, meta_title, head_so_title, meta_description, meta_keywords, content, link_rewrite) VALUES ($cms_id, $cms_lang, $cms_shop, '".$cms_meta_title."', '".$cms_seo_head_titile."', '".$cms_meta_description."', '".$cms_meta_keywords."', '".$cms_content."', '".$cms_link_rewrite."')"); // associate created cms page to shop Db::getInstance()->Execute('INSERT INTO '._DB_PREFIX_.'cms_shop (id_cms, id_shop) VALUES ($cms_id,$cms_shop); If you want to add more languages and more shops, you have to use foreach. Thanks a lot! I modified your code already from your previous post for my needs. Thanks a lot for your help, I think soon I will create full tutorial how to create cms pages from module. Edited May 4, 2020 by Amantha Bill (see edit history) Link to comment Share on other sites More sharing options...
Guest Posted May 4, 2020 Share Posted May 4, 2020 I hope you will introduce me as a co-author 😎 Link to comment Share on other sites More sharing options...
Guest Posted May 4, 2020 Share Posted May 4, 2020 Will your demonstration look something like this? 😁 Link to comment Share on other sites More sharing options...
Chill_user Posted May 4, 2020 Author Share Posted May 4, 2020 11 minutes ago, Guest said: Will your demonstration look something like this? 😁 Yes, but how did you get "custom CSS" field like this? I have found only next lines: array( 'col' => 3, 'type' => 'text', 'prefix' => '<i class="icon icon-envelope"></i>', 'desc' => $this->l('SEO HEAD'), 'name' => 'BL_SEO_HEAD', 'label' => $this->l('Seo head'), ), Link to comment Share on other sites More sharing options...
Guest Posted May 4, 2020 Share Posted May 4, 2020 (edited) $fields_form = array( 'form' => array( 'tinymce' => true, 'legend' => array( 'title' => $this->l('Settings custom page'), 'icon' => 'icon-cogs' ), 'input' => array( ... ... // tinymce editor array( 'type' => 'textarea', 'label' => $this->l('Page content'), 'name' => '_content', 'lang' => false, 'autoload_rte' => true, 'cols' => 50, 'rows' => 20 ), ... ... // normal editor array( 'type' => 'textarea', 'label' => $this->l('Custom CSS'), 'name' => '_css', 'lang' => false, 'autoload_rte' => false, 'cols' => 50, 'rows' => 5 ), ... ... Edited May 4, 2020 by Guest (see edit history) Link to comment Share on other sites More sharing options...
Chill_user Posted May 4, 2020 Author Share Posted May 4, 2020 6 minutes ago, Guest said: $fields_form = array( 'form' => array( 'tinymce' => true, 'legend' => array( 'title' => $this->l('Settings custom page'), 'icon' => 'icon-cogs' ), 'input' => array( ... ... // tinymce editor array( 'type' => 'textarea', 'label' => $this->l('Page content'), 'name' => '_content', 'lang' => false, 'autoload_rte' => true, 'cols' => 50, 'rows' => 20 ), ... ... // normal editor array( 'type' => 'textarea', 'label' => $this->l('Custom CSS'), 'name' => '_css', 'lang' => false, 'autoload_rte' => false, 'cols' => 50, 'rows' => 5 ), ... ... thanks, perfect! Link to comment Share on other sites More sharing options...
Guest Posted May 4, 2020 Share Posted May 4, 2020 There is a gray heart to thank you 🙂 Link to comment Share on other sites More sharing options...
Chill_user Posted May 4, 2020 Author Share Posted May 4, 2020 13 minutes ago, Guest said: There is a gray heart to thank you 🙂 Do you have some ideas about this post? Link to comment Share on other sites More sharing options...
WebDesign-Entreprise Posted July 3, 2020 Share Posted July 3, 2020 Easy way: $cms=new CMS(); $cms->meta_title[1]="TITLE"; //1 is lang id $cms->link_rewrite[1] = "URL"; //1 is lang id $cms->head_seo_title = "META TITLE"; $cms->meta_description = "META DESC"; $cms->content = "CONTENT"; $cms->id_cms_category=1; $cms->indexation=1; $cms->active=1; $cms->add(); Link to comment Share on other sites More sharing options...
accessorybee01 Posted July 4, 2020 Share Posted July 4, 2020 Hey Sorry for posting this question here but I have a problem in my side. If you guys can help then please look at this thread and reply 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