Jump to content

[ps_emailsubscription] ajax calls from the front-end

Recommended Posts

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


* 2007-2015 PrestaShop
* 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:
* 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 license@prestashop.com so we can send you a copy immediately.
* 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 <contact@prestashop.com>
* @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;
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);
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 


var ps_emailsubscription_url= "{url entity='module' name='ps_emailsubscription' controller='ajax'}"

And now you can make ajax calls to ps_emailsubscription_url


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

Important Information

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