Jump to content

[ Solved ] How to import CMS in Product Description


amar.prestashop
 Share

Recommended Posts

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 by amar.prestashop (see edit history)

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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,

Share this post


Link to post
Share on other sites

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)

  • Like 2

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

  • 3 weeks later...

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}

Share this post


Link to post
Share on other sites

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,

Share this post


Link to post
Share on other sites

  • 4 weeks later...

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 :)

Share this post


Link to post
Share on other sites

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()

Share this post


Link to post
Share on other sites

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}

Share this post


Link to post
Share on other sites

  • 5 weeks later...

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.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More