Bonjour Nabouill,
Let's make it simple. If you will look at your product controller, you will find that the name of the product is being declared as follows:
Code: Select all
$data['heading_title'] = $product_info['name'];
So we will use this instead of declaring again uselessly.
Coming to your template (view) product.tpl, you can simply put a data attribute in your html code like this:
Code: Select all
<a href="<?php echo $SendOffline; ?>" data-toggle="tooltip" title="<?php echo "Signaler une vidéo hors ligne"; ?>" data-name="<?php echo $heading_title; ?>" class="btn attention-panneau"><?php echo 'Signaler une vidéo hors ligne '?></a>
You can then simply make a JQuery Code to post the value onclick like this:
Code: Select all
$('.attention-panneau').on('click', function() {
$.ajax({
url: 'index.php?route=product/product/sendoffline',
type: 'post',
data: 'product_name=' + encodeURIComponent($(this).data("name")),
dataType: 'json',
beforeSend: function() {
$(this).text('Envoi en cours');
},
complete: function() {
$(this).text('Envoyé');
},
success: function(json) {
if (json['error']) {
$('.breadcrumb').after('<div class="alert alert-danger warning"><i class="fa fa-exclamation-circle"></i> ' + json['error'] + '<button type="button" class="close" data-dismiss="alert">×</button></div>');
$('html, body').animate({ scrollTop: 0 }, 'slow');
}
if (json['redirect']) {
location = json['redirect'];
}
}
});
});
In the controller product/product.php, change your function as such:
Code: Select all
public function sendoffline() {
$this->load->language('product/product');
$json = array();
if (isset($this->request->post['product_name'])) {
$product_name = $this->request->post['product_name'];
} else {
$product_name = '';
}
if (empty($this->request->post['product_name'])) {
$json['error'] = $this->language->get('error_sendoffline');
} else {
$mail = new Mail($this->config->get('config_mail'));
$mail->setTo($this->config->get('config_email'));
$mail->setFrom($this->config->get('config_email'));
$mail->setSender($this->config->get('config_name'));
$mail->setSubject('Lien MORT');
$mail->setText('Lien MORT - ' . $product_name);
$mail->send();
$json['redirect'] = $this->url->link('product/product/success');
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
Go to your language file 'product/product.php' and add this line:
Code: Select all
$_['error_sendoffline'] = 'Une erreur s\'est produite, veuillez réessayer ultérieurement.';
Hope it helps.