Hi,
I want to implement a checkbox to subscribe to the newsletter at the last step of the checkout process. Does anyone know a simple way to do that?
public bool SubscribeToNewsLetter { get; set; }
@Html.CheckBoxFor(model => model.SubscribeToNewsLetter)
<div class="subscribe-to-newsletter">
@Html.CheckBoxFor(model => model.SubscribeToNewsLetter)
</div>
<div class="terms-of-service">
<input id="termsofservice" type="checkbox" name="termsofservice" />
@T("Checkout.TermsOfService.IAccept")
<span class="read" onclick="javascript:OpenWindow('@Url.RouteUrl("TopicPopup", new { SystemName = "conditionsofuse" })', 450, 500, true)">@T("Checkout.TermsOfService.Read")</span>
</div>
<div class="subscribe-to-newsletter">
<input type="checkbox" id="checknewsletter" checked="checked"/><span> subscribe to newsletter</span>
</div>
if (termOfServiceOk) {
Checkout.setLoadWaiting('confirm-order');
$.ajax({
cache: false,
url: this.saveUrl,
type: 'post',
success: this.nextStep,
complete: this.resetLoadWaiting,
error: Checkout.ajaxFailure,
data: { confirmNewsletter:checknewsletter.checked }
});
} else {
return false;
}
if (confirmNewsletter)
{
var workContext = EngineContext.Current.Resolve<IWorkContext>();
var newsLetterSubscriptionService = EngineContext.Current.Resolve<INewsLetterSubscriptionService>();
newsLetterSubscriptionService.InsertNewsLetterSubscription(new NewsLetterSubscription()
{
NewsLetterSubscriptionGuid = Guid.NewGuid(),
Email = workContext.CurrentCustomer.Email,
Active = true,
StoreId = _storeContext.CurrentStore.Id,
CreatedOnUtc = DateTime.UtcNow
});
}