Hi everyone,
I need your help !
If i summarize : I have a module (MyModule) with inside a controller :
class MyModuleCreationDevisModuleFrontController extends ModuleFrontController
who displays mytemplate.tpl and a button with Ajax (my-button). -> I don't only display a button that's why i use ajax but i simplify for the post
I would like to know how i am suppose to process if i want to display the product with mytemplate.tpl without reloading the page when i click on my-button.
Should i process like this :
Add the id of the product in the data of my-button
Get the data when my-button is click with Jquery.
Thanks to AJAX send the data to the function DisplayAjax() of the override controller ProductController.php
Display the template product.tpl with the product's data
<?php
class ProductController extends ProductControllerCore
{
public function __construct()
{
parent::__construct();
}
public function initContent()
{
$this->ajax = true;
parent::initContent();
}
public function displayAjax()
{
$id_product = Tools::getValue('id');
$product = new Product($id_product);
ob_end_clean();
header('Content-Type: application/json');
$this->ajaxDie(Tools::jsonEncode(array(
'template' =>'catalog/product',
'product' => $product,
'entity' => 'product',
'id' => $id_product,
)));
}
}
Or is there a cleaner way to do that ? The operation of the ProductController is hard to understand...
Your help is precious to me and I would be very grateful if you could help me to find a solution.
Rémi