Jump to content

[ Solved ] How to import CMS in Product Description


amar.prestashop

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)
Link to comment
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?

Link to comment
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,

Link to comment
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
Link to comment
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.

Link to comment
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

Link to comment
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}

Link to comment
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,

Link to comment
Share on other sites

  • 4 weeks later...

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

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

  • 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.

Link to comment
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
×
×
  • Create New...