Post by nabouill » Sun Jun 21, 2015 7:54 pm

i try to setup a button for visitors for when there is a problem with a product(offline product for example), they click on the button and i receive automatically a mail.
it's work well, but i cannot get the product in my mail.

this is m code:
in catalog/view/theme/default/template/product/product.tpl i have simply adding:

Code: Select all

<?php echo 'Signaler une vid&eacute;o hors ligne '?><a href="<?php echo $SendOffline; ?>" data-toggle="tooltip" title="<?php echo "Signaler une vid&eacute;o hors ligne"; ?>" class="btn attention-panneau"></a>
and in catalog/controller/product/product.php, i have adding this fonction:

Code: Select all

	public function SendOffline() {			
					
		    $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');
			$mail->send();
			
			$this->response->redirect($this->url->link('product/product/success'));	
	}
How can i get the product name or product id (or the link of page) in a variable my mail text, i d'like doing a thing like this:

Code: Select all

$variable = productName // but i don't know how
$mail->setText($variable);
Anybody know how do, please.

Thank's in advance.
Last edited by nabouill on Wed Jun 24, 2015 3:11 pm, edited 1 time in total.

opencart 2.0.1.1 fr
-vqmod


New member

Posts

Joined
Thu May 16, 2013 6:41 am

Post by IP_CAM » Mon Jun 22, 2015 4:09 am

You have two variables, containing some ID-Values, in here:

Code: Select all

<?php echo $heading_title; ?>
<?php echo $product_id; ?>
I made a test on those, they look like on the image below.
If you send one, or both, of those VALUES, as part of a Button 'FORM COMMAND', instead of using a simple href-Button, you could then use the, usually 'hidden' CONTENT of those Variables, sent, to include it in your Mail.
Just an idea... ;)
Good Luck!
Ernie
PS. In Perl, I would know, how to do it... :-\

Code: Select all

hitline.info\shop\catalog\view\theme\adefault2\template\product\product.tpl
added this, just to show your the Values, displayed:

Code: Select all

 <div class="description">
  Product Title: <?php echo $heading_title; ?><br />
  Product ID: <?php echo $product_id; ?><br />
  <?php if ($manufacturer) { ?>
http://www.hitline.info/shop/index.php? ... uct_id=275
Last edited by IP_CAM on Tue Jun 23, 2015 12:24 am, edited 1 time in total.

My Github OC Site: https://github.com/IP-CAM
5'600 + FREE OC Extensions, on the World's largest private Github OC Repository Archive Site.


User avatar
Legendary Member

Posts

Joined
Tue Mar 04, 2014 1:37 am
Location - Switzerland

Post by OpenTeam » Mon Jun 22, 2015 3:33 pm

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&eacute;o hors ligne"; ?>" data-name="<?php echo $heading_title; ?>" class="btn attention-panneau"><?php echo 'Signaler une vid&eacute;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&eacute;');
		},
		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">&times;</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&eacute;essayer ult&eacute;rieurement.';
Hope it helps.

User avatar
Active Member

Posts

Joined
Tue May 19, 2015 2:31 am

Post by nabouill » Tue Jun 23, 2015 4:20 am

Thank you a lot, i think i'm on the good way.
But i have a problem,

When i click on the link, my navigator (opera) open a new page with only this message:
"{"error":"Une erreur s'est produite, veuillez r&eacute;essayer ult&eacute;rieurement."}"

With IE11, it ask to download a file "index.json" and in this file i have the same message.

I think than the fonction sendoffline() cannot get the product name.

Have you an idea ?
Thank's again.

opencart 2.0.1.1 fr
-vqmod


New member

Posts

Joined
Thu May 16, 2013 6:41 am

Post by OpenTeam » Tue Jun 23, 2015 4:30 am

Hello,

Do you have an URL where we can visualize the page containing the link being sent?

Regards.

User avatar
Active Member

Posts

Joined
Tue May 19, 2015 2:31 am

Post by nabouill » Tue Jun 23, 2015 5:43 am

hello.

i have put online the code

http://www.manga-vf.fr/manga-streaming- ... -streaming

Thanks.

opencart 2.0.1.1 fr
-vqmod


New member

Posts

Joined
Thu May 16, 2013 6:41 am

Post by nabouill » Wed Jun 24, 2015 6:44 am

Hmmm ! very strange
I received 2 mail today,so I did another test with my pc, it does not work (with IE, opera and Firefox)
I test with another pc, same thing.
I test with my phone (android), it work perfectly :choke:
(with your code)

opencart 2.0.1.1 fr
-vqmod


New member

Posts

Joined
Thu May 16, 2013 6:41 am

Post by nabouill » Wed Jun 24, 2015 3:10 pm

Hoho,
I have found why. The only difference between a PC and a phone is a slide that I had put in.
(slide-in already asked me problem for reviews http://forum.opencart.com/viewtopic.php?f=190&t=146330)
I removed the F******K slide-in and your code works perfectly on pc.

Thank you again for your help.

opencart 2.0.1.1 fr
-vqmod


New member

Posts

Joined
Thu May 16, 2013 6:41 am
Who is online

Users browsing this forum: paulfeakins and 12 guests