amar.prestashop Posted July 3, 2013 Share Posted July 3, 2013 (edited) Hi, I need to import a specific CMS page in some of my product description page. Specifically i need to import a guide that i've wrote in CMS onto same product that use the guide. I know that is not possible to use smarty inside product description, someone know how to solve this ? Thanks, Edited July 18, 2013 by amar.prestashop (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted July 3, 2013 Share Posted July 3, 2013 you want to use the same cms content for each product or maybe you want to use different cms pages for certain products? im asking because second solution will need a bit more work/modification. what ps version you use? Link to comment Share on other sites More sharing options...
amar.prestashop Posted July 3, 2013 Author Share Posted July 3, 2013 Hi Vekia, PS 1.5.4.1 I need to use different cms pages for certain products because i've made different guides for different products. P.S. I know Prestique, i've bought one module i need to another module but i need to ask one question, i make a mail in your site or directly in this forum ? Thanks, Link to comment Share on other sites More sharing options...
vekia Posted July 3, 2013 Share Posted July 3, 2013 you can send me PM here. where you want to display CMS content? (as a additional tab?) or maybe somewhere else? just let me know 1 Link to comment Share on other sites More sharing options...
amar.prestashop Posted July 3, 2013 Author Share Posted July 3, 2013 Hi, I send you a PM I like display CMS content in description area ( no additional tab ). Link to comment Share on other sites More sharing options...
vekia Posted July 3, 2013 Share Posted July 3, 2013 open the file: controllers/front/ProductController.php you've got there: $this->context->smarty->assign('errors', $this->errors); $this->setTemplate(_PS_THEME_DIR_.'product.tpl'); right before this code use: if (Tools::getValue('id_product')==3){ $cms=New CMS(2,$this->context->language->id); $this->context->smarty->assign(array('cms'=> $cms)); } duplicate this code for each product (id_product==3, id_product==4, id_product==5 etc.) with this: New CMS(2,$this->context->language->id); you're defining the id of the cms you want to display. Change the '2' value to other that you want to display. to display cms content, open the product.tpl file and put this code: {if $cms->content} {$cms->content} {/if} exactly there where you want to show CMS page content. this is the simplest method to achieve what you want. It's not very good solution, but only one available for now for free (i don't know any module for that) 2 Link to comment Share on other sites More sharing options...
amar.prestashop Posted July 4, 2013 Author Share Posted July 4, 2013 Hi vekia, I Think i will use your solution. I'm also testing a import html using ajax ( without use of CMS because i'm not able to import only a specific DIV section with Ajax ) on an external html files that contain the guide. Thanks Link to comment Share on other sites More sharing options...
vekia Posted July 4, 2013 Share Posted July 4, 2013 but note that when you will have, for example, 1000 products, then you will have to create 1000 if conditions - it isn't great solution at all. The best thing in this case will be separate module, with customp product field to define cms page. Link to comment Share on other sites More sharing options...
prestatent Posted July 4, 2013 Share Posted July 4, 2013 (edited) Hi What about creating a basic html page for each guide needed. You could then place an iframe in the product description for each product with the basic html page in the iframe code. Just a thought. Edited July 4, 2013 by prestatent (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted July 4, 2013 Share Posted July 4, 2013 nice idea but sometimes plugins like addblock blocks iframes Link to comment Share on other sites More sharing options...
prestatent Posted July 4, 2013 Share Posted July 4, 2013 I'm fairly new to Prestashop development and thought this may be worth a try. Thanks for letting me know. Link to comment Share on other sites More sharing options...
vekia Posted July 4, 2013 Share Posted July 4, 2013 well - your method will work! definitely! but as i said, many internet users use AddBlock feature to block adverts, in this case iframe will disappear Link to comment Share on other sites More sharing options...
prestatent Posted July 4, 2013 Share Posted July 4, 2013 Thanks Vekia. Good to know this for the future. Link to comment Share on other sites More sharing options...
amar.prestashop Posted July 4, 2013 Author Share Posted July 4, 2013 Hi, I've testing this solution : simple html page and used Ajax to import it ( no iframe) : <script type="text/javascript">// <![CDATA[ ajaxinclude("http://www.genuineluxuryoutlet.com/my_guides/how_to_measure_your_belt_size_short_guide.html") // ]]></script> I Call the function in the header.tpl :var rootdomain="http://"+window.location.hostname function ajaxinclude(url) { var page_request = false if (window.XMLHttpRequest) // if Mozilla, Safari etc page_request = new XMLHttpRequest() else if (window.ActiveXObject){ // if IE try { page_request = new ActiveXObject("Msxml2.XMLHTTP") } catch (e){ try{ page_request = new ActiveXObject("Microsoft.XMLHTTP") } catch (e){} } } else return false page_request.open('GET', url, false) //get page synchronously page_request.send(null) writecontent(page_request) } function writecontent(page_request){ if (window.location.href.indexOf("http")==-1 || page_request.status==200) document.write(page_request.responseText) } I hope addblok don't block the import but now i don't use it Link to comment Share on other sites More sharing options...
BenLivingston Posted July 19, 2013 Share Posted July 19, 2013 Here's how I did this. If you haven't already, copy classes/Products.php to override/classes/Products.php and change "class ProductCore" to "class Product". Then, in the function __construct(), around line 453, after: $this->supplier_name = Supplier::getNameById((int)$this->id_supplier); Add: $id_cms = 14; // set your cms id # here $cms_content = new CMS($id_cms, $this->context->language->id); $this->cms_content = $cms_content->content[1]; Then, in the theme product.tpl, use: {$product->cms_content} Link to comment Share on other sites More sharing options...
amar.prestashop Posted July 22, 2013 Author Share Posted July 22, 2013 Hi BenLivingston, It's a real good solution ( i've tested it on local ) but i need different guides based on different products. So i simply import an html file with the content i need through ajax, it is not the best solution but functions. In a second step, when the shop will produce money I will make a custom module Thanks, Amar, Link to comment Share on other sites More sharing options...
SonoguN Posted August 19, 2013 Share Posted August 19, 2013 Hi this is very similar to something I need to do.. I need to dynamically pull content of a CMS page into product.tpl based on the product category.. Vekia, how would I adapt your code for ProductController.php? Thanks Link to comment Share on other sites More sharing options...
vekia Posted August 19, 2013 Share Posted August 19, 2013 use the same code as above + create smart variable in array: $this->context->smarty->assign(array( 'stock_management' => Configuration::get('PS_STOCK_MANAGEMENT'), ... } like this: 'cms_content' => $cms don't forget to create new $cms object somewhere before the smarty variables definition: $cms=New CMS(2,$this->context->language->id); of course everything you can find in the public function initContent() Link to comment Share on other sites More sharing options...
SonoguN Posted August 19, 2013 Share Posted August 19, 2013 Hi Landed up doing the category filtering on the product.tpl page Thanks Assigning variables in ProductController.php for different CMS pages: $cms_jams =New CMS(10,$this->context->language->id); $cms_marmelades =New CMS(9,$this->context->language->id); $this->context->smarty->assign(array( 'cms_jams'=> $cms_jams, 'cms_marmelades'=> $cms_marmelades )); Filtering depending on which product category: {if $id_category_current == 6} {if $cms_jams->content} {$cms_jams->content} {/if} {else if $id_category_current == 5} {if $cms_marmelades->content} {$cms_marmelades->content} {/if} {/if} Link to comment Share on other sites More sharing options...
ghomi Posted September 17, 2013 Share Posted September 17, 2013 open the file: you've got there: $this->context->smarty->assign('errors', $this->errors); $this->setTemplate(_PS_THEME_DIR_.'product.tpl'); right before this code use: if (Tools::getValue('id_product')==3){ $cms=New CMS(2,$this->context->language->id); $this->context->smarty->assign(array('cms'=> $cms)); } duplicate this code for each product (id_product==3, id_product==4, id_product==5 etc.)with this: New CMS(2,$this->context->language->id); you're defining the id of the cms you want to display. Change the '2' value to other that you want to display. to display cms content, open the product.tpl file and put this code: {if $cms->content} {$cms->content} {/if} exactly there where you want to show CMS page content. this is the simplest method to achieve what you want. It's not very good solution, but only one available for now for free (i don't know any module for that) Thanks for the description! I used for all products, reduced the code: if (Tools::getValue('id_product')==3){ $cms=New CMS(2,$this->context->language->id); $this->context->smarty->assign(array('cms'=> $cms)); } Used only the following lines in ProductController.php $cms=New CMS(2,$this->context->language->id); $this->context->smarty->assign(array('cms'=> $cms)); Works on 1.5.4.1. Link to comment Share on other sites More sharing options...
vekia Posted September 17, 2013 Share Posted September 17, 2013 but in this case you will have cms variable in all available products, right? 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