logo
Welcome to our new AbleCommerce forums. As a guest, you may view the information here. To post to this forum, you must have a registered account with us, either as a new user evaluating AbleCommerce or an existing user of the application. For all questions related to the older version of Gold and earlier, please go to AbleCommerce Gold forum. Please use your AbleCommerce username and password to Login. New Registrations are disabled.

Notification

Icon
Error

Options
Go to last post Go to first unread
judy at Web2Market  
#1 Posted : Monday, May 16, 2022 11:19:22 AM(UTC)
judy at Web2Market

Rank: Advanced Member

Groups: Developers
Joined: 11/7/2018(UTC)
Posts: 286

Thanks: 21 times
Was thanked: 5 time(s) in 5 post(s)
I am upgrade a site from Gold and they had code to add a coupon code to an abandoned basket email, after selecting the coupon in a dropdown.
I have the code working to pick up the coupon code from a dropdown on SendAbandonedBasketsAlert view, but the coupon doesn't get picked up in the email.How can I get it to display in the email?
The code in the template from the old site is:
#if($coupon && $coupon!="")
<p>Please return and enter the Coupon Code $coupon during checkout to receive a 10% discount** on your entire order.</p>
#end

I have added this code in the ReportController, SendAbandondedBasketsAlert and when I step through the code, the coupon gets picked up. It just doesn't display in the email.


int couponId = model.SelectedCouponId;
Coupon coup = AbleContext.Resolve<ICouponRepository>().Load(couponId);

if (coup != null)
{

emailTemplate.Parameters.Add("coupon", coup.CouponCode);

}

mailMessage.Subject = model.Subject;
mailMessage.IsBodyHtml = emailTemplate.IsHTML;

Thanks


Wanna join the discussion?! Login to your AbleCommerce Forums forum account. New Registrations are disabled.

nadeem  
#2 Posted : Tuesday, May 17, 2022 7:52:59 AM(UTC)
nadeem

Rank: Advanced Member

Groups: Administrators, Developers, Registered, HelpDesk, Authorized User, Admin, System
Joined: 10/11/2018(UTC)
Posts: 109

Thanks: 17 times
Was thanked: 18 time(s) in 18 post(s)
Hi Judy,

I think you are setting the coupon parameter in the SendAbandonedBasketsAlert POST action method. It should be inside the GET method just after the following line of code:

Code:

parameters.Add("basket", basket);


Let me know if it doesn't work. Thank you!
judy at Web2Market  
#3 Posted : Tuesday, May 17, 2022 8:55:05 AM(UTC)
judy at Web2Market

Rank: Advanced Member

Groups: Developers
Joined: 11/7/2018(UTC)
Posts: 286

Thanks: 21 times
Was thanked: 5 time(s) in 5 post(s)
I was afraid you were going to say that. I populate a dropdown list of coupons to select from in the public ActionResult SendAbandonedBasketsAlert(int basketId) GET method. So the admin person possibly selects one then sends the email.
The old site had a select coupon box in the grid on the Daily Abandoned Baskets report - see image below. Then it passed the coupon id to the Send Abandoned Baskets Alert page in the query string and the coupon variable is populated in the email.
2022-05-17_9-39-48.png (38kb) downloaded 0 time(s).
I tried that, but couldn't figure out a way to pass the couponid to the next page.
I tried picking up the couponId from the dropdown in the grid and adding it below, but it just passed 0. So that is why I decided to put it on the next page, not knowing that it had to be populated by the GET method.
@if (item.HasEmail)
{
<a href="@Url.Action("SendAbandonedBasketsAlert", new { basketId = item.BasketId })" class="btn btn-white btn-sm">Send Alert</a>
}
How can I pick up the couponId from a dropdownlist of coupons? The list of coupons in the grid in the view is :
<td class="text-right">
@Html.DropDownListFor(model => @item.SelectedCouponId, (IEnumerable<SelectListItem>)@item.CouponList, "Select a Coupon", new { @class = "form-control" })
</td>

I have added the following to the AbandonedBasketsModel and the controller populates the dropdown
public List<SelectListItem> CouponList { get; set; }
public int SelectedCouponId { get; set; }

Thanks
nadeem  
#4 Posted : Tuesday, May 17, 2022 1:34:11 PM(UTC)
nadeem

Rank: Advanced Member

Groups: Administrators, Developers, Registered, HelpDesk, Authorized User, Admin, System
Joined: 10/11/2018(UTC)
Posts: 109

Thanks: 17 times
Was thanked: 18 time(s) in 18 post(s)
Quote:
I have added this code in the ReportController, SendAbandondedBasketsAlert and when I step through the code, the coupon gets picked up. It just doesn't display in the email.


If you are getting the correct coupon code on post request based on the send alert button click, then you can achieve your goal with following steps:

Add a below model property

Code:

public System.Collections.Hashtable Parameters { get; set; }


On the get action method, locate the following line:

Code:

parameters.Add("basket", basket);


and update with


Code:

parameters.Add("basket", basket);
model.Parameters = parameters;


In the view file update the button like this by adding another parameter i.e. parameters:

Code:

@if (item.HasEmail)
{
   <a href="@Url.Action("SendAbandonedBasketsAlert", new { basketId = item.BasketId, parameters = item.Parameters })" class="btn btn-white btn-sm">Send Alert</a>
}


and update the SendAbandonedBasketsAlert post action like this:

Code:

public ActionResult SendAbandonedBasketsAlert(AbondonedBasketsModel model, Hashtable parameters = null)


Now add your code just above mailMessage.Subject = model.Subject; line like this:

Code:

Coupon coup = AbleContext.Resolve<ICouponRepository>().Load(model.SelectedCouponId);
if (coup != null)
{
   parameters.Add("coupon", coup.CouponCode);
}


Finally, update the following line

Code:

mailMessage.Body = emailTemplate.IsHTML ? model.HtmlMessageContents : model.TextMessageContents;


with

Code:

mailMessage.Body = emailTemplate.IsHTML ? NVelocityEngine.Instance.Process(parameters, model.HtmlMessageContents) : NVelocityEngine.Instance.Process(parameters, model.TextMessageContents);
nadeem  
#5 Posted : Wednesday, May 18, 2022 5:57:46 AM(UTC)
nadeem

Rank: Advanced Member

Groups: Administrators, Developers, Registered, HelpDesk, Authorized User, Admin, System
Joined: 10/11/2018(UTC)
Posts: 109

Thanks: 17 times
Was thanked: 18 time(s) in 18 post(s)
Judy,

I just realized it can be done with minimum changes as well. You can just process the newly added coupon parameter with the email contents. So you just need the following updates in the POST action method:

Code:

Coupon coup = AbleContext.Resolve<ICouponRepository>().Load(model.SelectedCouponId);
if (coup != null)
{
   emailTemplate.Parameters.Add("coupon", coup.CouponCode);
}


and then replace the below line of code

Code:

mailMessage.Body = emailTemplate.IsHTML ? model.HtmlMessageContents : model.TextMessageContents;


with

Code:

mailMessage.Body = emailTemplate.IsHTML ? NVelocityEngine.Instance.Process(emailTemplate.Parameters, model.HtmlMessageContents) : NVelocityEngine.Instance.Process(emailTemplate.Parameters, model.TextMessageContents);


That's all! You can ignore the updates from the last post since it requires a lot more work than this.
judy at Web2Market  
#6 Posted : Wednesday, May 18, 2022 11:58:20 AM(UTC)
judy at Web2Market

Rank: Advanced Member

Groups: Developers
Joined: 11/7/2018(UTC)
Posts: 286

Thanks: 21 times
Was thanked: 5 time(s) in 5 post(s)
Thanks for your help. The easy way didn't work.
If I hardcode a couponId in the GET method public ActionResult SendAbandonedBasketsAlert(int basketId)
{

The preview of the email on SendAbandondedBasketsAlert page picks up the coupon value and the email sends the coupon value. That is the only thing that has worked so far.Adding the code to the post method didn't work.
I just can't figure out how to pick up the selected coupon from the dropdown in the grid so I can pass it to the next page so it will be picked up in the email preview, hence it will be sent with the email.Maybe I need to use some kind of js.
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.