AmineDevx Posted March 24, 2019 Share Posted March 24, 2019 Hello everyone, If you want to make ajax calls to ps_emailsubscription module from the front-end here is how to do it: In the ps_emailsubscription.php file declare a new controller named ajax public function __construct(EntityManager $entity_manager) { $this->controllers = array('verification', 'subscription', 'ajax'); Then create new file in modules/ps_emailsubscription/controllers/front named ajax.php <?php /* * 2007-2015 PrestaShop * * NOTICE OF LICENSE * * This source file is subject to the Academic Free License (AFL 3.0) * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/afl-3.0.php * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to [email protected] so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade PrestaShop to newer * versions in the future. If you wish to customize PrestaShop for your * needs please refer to http://www.prestashop.com for more information. * * @author PrestaShop SA <[email protected]> * @copyright 2007-2015 PrestaShop SA * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA */ /** * @since 1.5.0 */ class Ps_EmailsubscriptionAjaxModuleFrontController extends ModuleFrontController { private $variables = []; /** * @see FrontController::initContent() */ public function initContent() { $this->ajax = true; parent::initContent(); } public function displayAjax() { } public function postProcess() { $this->variables['value'] = Tools::getValue('email', ''); $this->variables['msg'] = ''; $this->variables['conditions'] = Configuration::get('NW_CONDITIONS', $this->context->language->id); $this->module->newsletterRegistration(); if ($this->module->error) { $this->variables['msg'] = $this->module->error; $this->variables['nw_error'] = true; } elseif ($this->module->valid) { $this->variables['msg'] = $this->module->valid; $this->variables['nw_error'] = false; } header('Content-Type: application/json'); return die(Tools::jsonEncode($this->variables)); } } In your theme's head.tpl add the following code <script> var ps_emailsubscription_url= "{url entity='module' name='ps_emailsubscription' controller='ajax'}" </script> And now you can make ajax calls to ps_emailsubscription_url 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