Post by Jeens » Fri Jul 24, 2020 5:04 am

Hello,
I have a problem..I have a newsletter popup module of which i cannot reach the developer and there is a thing that needs to be done, can someone maybe help me?

It's like this:
It's a popup that shows up on my page and offers the visitor to subscribe to our mailing list.
The only problem ism the popup keeps showing, even after the visitor has entered their adress and I want it to stop showing up after that.

As far as I know, the module consists of two files, the controller file and the template, here are both:

Controller:

Code: Select all

<?php  
class ControllerExtensionModuleNewsletter extends Controller {
	public function index($setting) {
		
		static $module = 0;
		$this->language->load('extension/module/newsletter');
		
    	$data['heading_title'] = $this->language->get('heading_title');
		$data['text_email'] = $this->language->get('text_email');
		$data['entry_email'] = $this->language->get('entry_email');
		$data['button_join'] = $this->language->get('button_join');
		$data['style'] = $setting['style'];
		$data['show_once'] = $setting['show_once'];
		$data['popup_delay_time'] = $setting['delay'];
		
		$this->load->model('localisation/language');
		
		if(empty($setting['block'][$this->config->get('config_language_id')])) {
			$data['block'] = false;
		} else if (isset($setting['block'][$this->config->get('config_language_id')])) {
			$data['block'] = html_entity_decode($setting['block'][$this->config->get('config_language_id')], ENT_QUOTES, 'UTF-8');
		}
		
		$data['module'] = $module++;

		return $this->load->view('extension/module/newsletter', $data);
		
	}
	
	public function unsubscribe() {
		if (isset($this->request->get['id'])) {
			$this->language->load('extension/module/newsletter');

			$this->document->setTitle($this->language->get('heading_title'));

			$data['breadcrumbs'] = array();

			$data['breadcrumbs'][] = array(
				'text'      => $this->language->get('text_home'),
				'href'      => $this->url->link('common/home')
			);

			$data['breadcrumbs'][] = array(
				'text'      => $this->language->get('heading_title'),
				'href'      => $this->url->link('extension/module/newsletter/unsubscribe')
			);
			
			$data['heading_title'] = $this->language->get('heading_title');
			
			$data['button_continue'] = $this->language->get('button_continue');
			
			$data['continue'] = $this->url->link('common/home');
			
			$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "newsletter WHERE md5(CONCAT('newsletter', email)) = '" . $this->db->escape($this->request->get['id']) . "'");
			
			$query1 = $this->db->query("SELECT * FROM " . DB_PREFIX . "customer WHERE md5(CONCAT('newsletter', email)) = '" . $this->db->escape($this->request->get['id']) . "'");

			if ($query->num_rows) {
				$this->db->query("DELETE FROM " . DB_PREFIX . "newsletter WHERE email = '" . $this->db->escape($query->row['email']) . "'");
				
				$data['text_message'] = sprintf($this->language->get('text_message'), $query->row['email']);
			} elseif  ($query1->num_rows) {
				$this->db->query("UPDATE " . DB_PREFIX . "customer SET newsletter = '0' WHERE email = '" . $this->db->escape($query1->row['email']) . "'");
				
				$data['text_message'] = sprintf($this->language->get('text_message'), $query1->row['email']);
			} else {
				$data['text_message'] = $this->language->get('error_unsubscribe');
			}		
		
			$data['column_left'] = $this->load->controller('common/column_left');
			$data['column_right'] = $this->load->controller('common/column_right');
			$data['content_top'] = $this->load->controller('common/content_top');
			$data['content_bottom'] = $this->load->controller('common/content_bottom');
			$data['footer'] = $this->load->controller('common/footer');
			$data['header'] = $this->load->controller('common/header');

			$this->response->setOutput($this->load->view('common/success', $data));
			
		} else {
			$this->response->redirect($this->url->link('common/home'));
		}
	}
	
	public function validate() {
		$this->language->load('extension/module/newsletter');
		
		$json = array();
		
		if ((strlen($this->request->post['email']) > 96) || !preg_match('/^[^\@]+@.*\.[a-z]{2,6}$/i', $this->request->post['email'])) {
			$json['error']['warning'] = $this->language->get('error_email');
		} elseif (strlen($this->request->post['email']) < 3) {
			$json['error']['warning'] = $this->language->get('error_message');
		}
		
		if(!$json) {
			$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "customer WHERE email = '" . $this->db->escape($this->request->post['email']) . "'");
			
			if ($query->num_rows) {
				$query = $this->db->query("SELECT newsletter FROM " . DB_PREFIX . "customer WHERE email = '" . $this->db->escape($this->request->post['email']) . "'");
				
				if ($query->row['newsletter']) {
					$this->db->query("UPDATE " . DB_PREFIX . "customer SET newsletter = '0' WHERE email = '" . $this->db->escape($this->request->post['email']) . "'");
					
					$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "newsletter WHERE email = '" . $this->db->escape($this->request->post['email']) . "'");
					
					if ($query->num_rows) {
						$this->db->query("DELETE FROM " . DB_PREFIX . "newsletter WHERE email = '" . $this->db->escape($this->request->post['email']) . "'");
					}
					
					$json['success'] = $this->language->get('text_unsubscribe');
				} else {
					$this->db->query("UPDATE " . DB_PREFIX . "customer SET newsletter = '1' WHERE email = '" . $this->db->escape($this->request->post['email']) . "'");
					
					$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "newsletter WHERE email = '" . $this->db->escape($this->request->post['email']) . "'");
					
					if ($query->num_rows) {
						$this->db->query("DELETE FROM " . DB_PREFIX . "newsletter WHERE email = '" . $this->db->escape($this->request->post['email']) . "'");
					}
					
					$json['success'] = $this->language->get('text_subscribe');
				}
			} else {
				$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "newsletter WHERE email = '" . $this->db->escape($this->request->post['email']) . "'");
				
				if ($query->num_rows) {
					$this->db->query("DELETE FROM " . DB_PREFIX . "newsletter WHERE email = '" . $this->db->escape($this->request->post['email']) . "'");
					
					$json['success'] = $this->language->get('text_unsubscribe');
				} else {
					$this->db->query("INSERT INTO " . DB_PREFIX . "newsletter SET email = '" . $this->db->escape($this->request->post['email']) . "'");
					
					$json['success'] = $this->language->get('text_subscribe');
				}
			}
		}
		
		$this->response->setOutput(json_encode($json));	
	}
}

Template, it has 3 different layouts, only the bottom one is used, but I think the javascript will be more interesting in this case (style popup):

Code: Select all

<?php if (($style) == ('box')) { ?>
<div class="box newsletter boxed primary_background">
<div class="inner">
  <div class="box-content">
  <!--<span class="heading"><?php echo $heading_title; ?></span>-->
  <p><!--<?php echo $entry_email; ?>--></p>
          <div class="subscribe_form">
          <input type="text" value="" placeholder="<?php echo $text_email; ?>" name="email" id="newsletter_email<?php echo $module; ?>" class="form-control" />
          <a class="subscribe_icon" id="button-newsletter<?php echo $module; ?>"><i class="fa fa-envelope"></i></a>
          </div>
          </div>
	</div>
    </div>

<?php } else if (($style) == ('default')) { ?>
<div class="box newsletter">
  <div class="box-heading"><?php echo $heading_title; ?></div>
  <div class="box-content">
  <label>
  <p class="contrast_font intro"><?php echo $entry_email; ?></p>
             <input type="text" value="" placeholder="<?php echo $text_email; ?>" name="email" id="newsletter_email<?php echo $module; ?>" class="form-control" />
             <a class="button" id="button-newsletter<?php echo $module; ?>"><span><?php echo $button_join; ?></span></a>
			 </label>
	</div>
</div>

<?php } else if (($style) == ('popup')) { ?>
<div class="init_popup">
<div style="display: none;" class="window_holder">
<div class="window_content primary_border">
<div class="box newsletter boxed popup">
<div class="inner primary_background">
<a class="popup_close">X</a>
  <div class="box-content">
	<div>
	<br>
	</div>
  	<div class="popup_block">
  	<?php echo $block; ?>
  	</div>

      <div class="subscribe_form field">
      <input type="text" value="" placeholder="<?php echo $text_email; ?>" name="email" id="newsletter_email<?php echo $module; ?>" />
      </div>
      <a class="button" id="button-newsletter<?php echo $module; ?>"><span><?php echo $button_join; ?></span></a>
 	</div>
</div>
</div>
</div>
</div>
</div>
<div class="popup_mask popup_close" style="display: none;"></div>

<?php if(!isset($_COOKIE['newsletter_already_popup'])) { ?>
<script type="text/javascript">
$(document).ready(function() {	
if ($(window).width() > 160) {
	setTimeout(function() {	
		/*$('.popup_mask').fadeTo(750,0.5);*/
		$('.window_holder').show();
		setTimeout(function() { $('.window_holder').addClass('active'); }, 750);
	}, <?php echo $popup_delay_time; ?>);
		
	$('.popup_close').click(function () {
		/*$('.popup_mask').hide();*/
		$('.window_holder').hide();
	});	
};
<?php if ($show_once) { ?>
$.cookie( 'newsletter_already_popup' , 1 , { expires: 1 , path: '/' });
<?php } ?>
});
</script>
<?php } ?>

<?php } ?>
<script type="text/javascript"><!--
$('#button-newsletter<?php echo $module; ?>').on('click', function() {
	$.ajax({
		url: 'index.php?route=extension/module/newsletter/validate',
		type: 'post',
		data: $('#newsletter_email<?php echo $module; ?>'),
		dataType: 'json',
		/*beforeSend: function() {
			$('#button-newsletter').prop('disabled', true);
			$('#button-newsletter').after('<i class="fa fa-spinner"></i>');
		},	
		complete: function() {
			$('#button-newsletter').prop('disabled', false);
			$('.fa-spinner').remove();
		},*/		
		success: function(json) {
			if (json['error']) {
				alert(json['error']['warning']);
			} else {
				alert(json['success']);
				
				$('#newsletter_email').val('');
			}
		}
	});	
});	
/*$('#newsletter_email').on('keydown', function(e) {
	if (e.keyCode == 13) {
		$('#button-newsletter').trigger('click');
	}
});*/
//--></script> 
As you can see it sets a cookie for it to be shown only once to every person.
I plan to turn this off, and have it on the site all the time, till the visitor enters his/her address or closes it.
The problem is, it shows up even after they have signed up already.

Sorry for the long post, my coding is not good at all, so maybe someone can help me? I use opencart 2.3.0.2.

Thanks a lot!

Newbie

Posts

Joined
Sat Jul 11, 2020 5:16 pm

Post by JNeuhoff » Mon Aug 10, 2020 5:33 pm

Since it is a 3rd party extension I think your best option would be to post it on the commercial section of this forum to find a developer who can look into it.

Override Engine * Integrated VQMod * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Rich Snippets * Google Tag Manager * Export/Import Tool * SpamBot Buster * Survey Plus


User avatar
Expert Member

Posts

Joined
Wed Dec 05, 2007 3:38 am

Who is online

Users browsing this forum: No registered users and 6 guests