contao/newsletter-bundle

tl_member.newsletter not updated

Closed this issue · 5 comments

Subscribing to a newsletter channel by the newsletter module or canceling a subscription does not update the field tl_member.newsletter.
This is why adapting the newsletter template to show only the possible channels by use of {{user::newsletter}} is not possible.

I changed the template to show only channels for subscription that are not already subscribed to. Vice versa to show only channels for canceling that are subscribed to. If no channels remain a text will be shown "you already subscribed to all possible newsletters" vv. "There are no newsletters subscriptions to be canceled" .

Maybe a good idea to fix the inconsistency and also change the standard template as I did.

This will also need to ask if the user is a FE user. I skipped that as I show the module only to FE users. If positive, the email should be set by the template.

My template (also has some special logic):

<!--- ernstjendritzki: Nur abonnierte Newsletter zum Kündigen anbieten. Nur nicht abonnierte Newsletter zum Abonnieren anbieten.
      ernstjendritzki: Nur bestätigten Vereinsmitgliedern den Newsletter Verein anbieten
      ernstjendritzki: Nur Nicht-Interessenten (Mitgliedergruppe Interessent nicht belegt) Newsletter für Mitglieder anbieten-->

<?php $this->extend('block_unsearchable'); ?>

<?php $this->block('content'); ?>

<form<?php if ($this->action): ?> action="<?= $this->action ?>"<?php endif; ?> id="<?= $this->formId ?>" method="post">
<div class="formbody">
    <input type="hidden" name="FORM_SUBMIT" value="<?= $this->formId ?>">
    <input type="hidden" name="REQUEST_TOKEN" value="{{request_token}}">

    <?php if ($this->message): ?>
	    <p class="<?= $this->mclass ?>"><?= $this->message ?></p>
    <?php endif; ?>

	<!--- Anzahl erlaubter Newsletter-Abonnements -->
	<?php $countAllowedChannels = 0; ?>

	<!--- Verteilermenü ausgeblendet -->
    <?php if (!$this->showChannels): ?>
    <?php foreach ($this->channels as $id=>$title): ?>
	    <input type="hidden" name="channels[]" value="<?= $id ?>">
    <?php endforeach; ?>
    <?php endif; ?>

	<!--- Email-Adresse mit der des Users belegen -->
    <div class="widget widget-text invisible">
        <label for="ctrl_email_<?= $this->id ?>" class="invisible"><?= $this->emailLabel ?></label>
        <input type="text" name="email" id="ctrl_email_<?= $this->id ?>" class="text " value={{user::email}} placeholder="<?= $this->emailLabel ?>" >
    </div>

	<!--- Mitglied ist Interessent? -->
	<?php $interessent = FALSE; ?>
	<?php if(substr_count($this->replaceInsertTags('{{user::groups}}'), '13') != 0): ?>
		<?php $interessent = TRUE; ?>
    <?php endif; ?>

	<!--- Verteilermenü aufbereiten -->
    <?php if ($this->showChannels): ?>
    <div class="widget widget-checkbox">
        <fieldset id="ctrl_channels_<?= $this->id ?>" class="checkbox_container">
        <legend class="invisible"><?= $this->channelsLabel ?></legend>
        <?php foreach ($this->channels as $id=>$title): 
			// Mitteilungen oder Einladungen -->
			if($id == 7 || $id == 13):
				//Newsletter abonnieren  
				 if ($this->submit == 'Abonnieren'):
					//Newsletter noch nicht abonniert -->
				 	if (substr_count($this->replaceInsertTags('{{user::newsletter}}'), $id) == 0): 
						//Newsletter anbieten sofern kein Interessent	 -->	
						if (!$interessent):
							echo '<label for="opt_' , $this->id , '_' , $id , '">';
						    echo '<input type="checkbox" name="channels[]" id="opt_', $this->id ,'_', $id , '"', ' value="', $id ,'"', ' class="checkbox">';
						    if (is_array($this->selectedChannels) && in_array($id, $this->selectedChannels)):
						    	echo ' checked';
						    endif;
						    echo '<span>', $title, '</span>';
						    echo '</label>';
			            	$countAllowedChannels++;
						endif;
					endif;
				//Newsletter kündigen  -->
				 else:
					//Newsletter abonniert -->
					if (substr_count($this->replaceInsertTags('{{user::newsletter}}'), $id) != 0): 
						echo '<label for="opt_' , $this->id , '_' , $id , '">';
					    echo '<input type="checkbox" name="channels[]" id="opt_', $this->id ,'_', $id , '"', ' value="', $id ,'"', ' class="checkbox">';
					    if (is_array($this->selectedChannels) && in_array($id, $this->selectedChannels)):
					    	echo ' checked';
					    endif;
					    echo '<span>', $title, '</span>';
					    echo '</label>';
		            	$countAllowedChannels++;
					endif;
				endif;
			// Vereinsmitteilungen  -->
			elseif($id == '12'):
				//Newsletter abonnieren  -->
				 if ($this->submit == 'Abonnieren'):
					//Newsletter noch nicht abonniert -->
				 	if (substr_count($this->replaceInsertTags('{{user::newsletter}}'), $id) == 0): 
				 	//Newsletter nur bestätigten Vereinsmitgliedern anbieten	 -->	
						if ($this->replaceInsertTags('{{user::clubMemberState}}') == 'Bestätigt'):
							echo '<label for="opt_' , $this->id , '_' , $id , '">';
						    echo '<input type="checkbox" name="channels[]" id="opt_', $this->id ,'_', $id , '"', ' value="', $id ,'"', ' class="checkbox">';
						    if (is_array($this->selectedChannels) && in_array($id, $this->selectedChannels)):
						    	echo ' checked';
						    endif;
						    echo '<span>', $title, '</span>';
						    echo '</label>';
			            	$countAllowedChannels++;
						endif;
					endif;
				//Newsletter kündigen  -->
				else:
					//Newsletter abonniert -->
					if (substr_count($this->replaceInsertTags('{{user::newsletter}}'), $id) != 0): 
						echo '<label for="opt_' , $this->id , '_' , $id , '">';
					    echo '<input type="checkbox" name="channels[]" id="opt_', $this->id ,'_', $id , '"', ' value="', $id ,'"', ' class="checkbox">';
					    if (is_array($this->selectedChannels) && in_array($id, $this->selectedChannels)):
					    	echo ' checked';
					    endif;
					    echo '<span>', $title, '</span>';
					    echo '</label>';
		            	$countAllowedChannels++;
					endif;
				endif;
			?>
			<?php endif ?>
         <?php endforeach; ?>
        </fieldset>
    </div>
    <?php endif; ?>

    <?= $this->captcha ?>

	<!--- Entweder submit-Button zeigen oder Hinweistext -->
    <div class="widget widget-submit">
		<!--- Button anzeigen, wenn erlaubte Abonnements vorhanden sind -->
	    <?php if ($countAllowedChannels > 0): ?>
    	   <button type="submit" class="submit"><?= $this->submit ?></button>
    	<?php else: ?>
			<!--- Sonst Hinweistext anzeigen -->	
    	   <?php if ($this->submit == 'Abonnieren'): ?>
    			<span>Sie haben aktuell bereits alle verfügbaren Mitteilungen abonniert</span>
    	   <?php else: ?>
    			<span>Sie haben aktuell keine Mitteilungen abonniert</span>
    	   <?php endif; ?>
	    <?php endif; ?>
    </div>
</div>
</form>

<?php if ($this->hasError): ?>
<script>
    try {
        window.scrollTo(null, parseInt($('<?php echo $this->formId; ?>').getElement('p.error').getPosition().y - 40));
    } catch(e) {}
</script>
<?php endif; ?>

<?php $this->endblock(); ?>

Actually, newsletter subscriptions should be synchronized between members and recipients. How can I reproduce the original issue in the online demo?

At the moment it seems not possible to login to the demo FE. So i just decribe what I would do there:

Login to the FE
Add channel Newsletter-Demo to user. Go through double-opt-in process.

Open phpadmin and examine tl_member.newsletter.

Won't find channel-id there.

Now that online Demo FE can be accessed again, I learn, that newsletter subscription can only be made by memberlist in the BE. So I did. If I were able to have a look at the Database, I would find that tl_member.newsletter won't contain the just subscribben channel.

I can not see any update of member model in the coding...I suppose, it might have been forgotten.

I made a proposal for this issue: #25