Email template - add data from the random table

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.

Email template - add data from the random table

Postby confused » Tue Mar 05, 2019 4:38 am

VERSION: 7.0.89.7670
Release Label: GoldR9

Hi,
I have delivery date for order shipments saved in the "xyz" table in the ac database. How can I include that delivery date in OrderPlaced email template, so when customer places the order, delivery date is shown in the email?

Thank you!
confused
Ensign (ENS)
Ensign (ENS)
 
Posts: 6
Joined: Tue Apr 06, 2010 7:27 am

Re: Email template - add data from the random table

Postby jguengerich » Tue Mar 05, 2019 7:57 am

Technical details:
The DefaultEventsHandler.cs file (in the source code) has an OrderPlaced method that sets up some parameters (order, customer, and payments) so the corresponding objects are available to the template processor. The store parameter is added by the ProcessEmails method in the EmailProcessor.cs file (also in source code). In the template, you will see things like $order.OrderDate.ToString("G"), which uses the order parameter to access the OrderDate property of the Order and format it.

There are 3 possibilities I can think of:
1. Store the delivery date in a way that is already accessible through an Order object property or method. If you had Gold R12, you could use the ExtendedProperties feature; In Gold R9 perhaps store it as an OrderNote? You would not need the source code to make this change. Your email template code would have to find the right OrderNote by looping through the items in $order.OrderNotes. It would be similar to how the template loops through the $order.Shipments.
2. Add a property (or method) to the Order (or Shipment) object that returns the delivery date so you can access $order.YourDeliveryDate (or $shipment.YourDeliveryDate) in the template. This is a source code change - the property or method would look up and return the value from the "xyz" table.
3. Change the DefaultEventsHandler.OrderPlaced method to add the delivery date as a parameter to the template. This is a source code change - OrderPlaced would look up the value from the "xyz" table and add it to the collection of parameters. Your email template code would access it as $DeliveryDate (or whatever parameter name you use).

BTW this is about Gold, so it should probably be in the AbleCommerce GOLD forum. Not sure if you can move it yourself or if an admin would have to do it.
Jay
jguengerich
Commodore (COMO)
Commodore (COMO)
 
Posts: 414
Joined: Tue May 07, 2013 1:59 pm

Re: Email template - add data from the random table

Postby confused » Wed Mar 06, 2019 12:06 am

Hi Jay.

Thanks a lot for taking a time to give an elaborate answer. Numbers 2. and 3. wouldn't work because I do not have a source code :(
I might use idea from number 1. and store shipment delivery date in the shipment.Address.Nickname field which we don't use.

I was actually hoping (since I don't have a source code) for possibility of using IOC (Inversion of Control) to override default DefaultEventsHandler.OrderPlaced method or something in that nature, but I might end up using your idea that I had mentioned above if nobody else chimes in and help with IOC.

Thanks again!
confused
Ensign (ENS)
Ensign (ENS)
 
Posts: 6
Joined: Tue Apr 06, 2010 7:27 am

Re: Email template - add data from the random table

Postby jguengerich » Wed Mar 06, 2019 12:54 am

I'm not very well versed in IOC or other more advanced object-oriented concepts, so hopefully someone else can provide more insight on if there is a clever OOP way to handle this. DefaultEventsHandler.OrderPlaced does more than just create the parameters and call the email processor, so if you don't have the source code, not sure how you'd make sure the same things are done. I'm pretty sure I can't just post that part of the source code here, but if there is a "better" way but it requires knowing what else needs to be done, maybe AbleCommerce would give you the source for OrderPlaced so you could make it work.
Jay
jguengerich
Commodore (COMO)
Commodore (COMO)
 
Posts: 414
Joined: Tue May 07, 2013 1:59 pm

Re: Email template - add data from the random table

Postby confused » Wed Mar 06, 2019 2:47 am

Thanks Jay.

Will seat for day or two and wait for possibility of using IOC. Otherwise, will be using unused field : address.nickname.

Cheers.
confused
Ensign (ENS)
Ensign (ENS)
 
Posts: 6
Joined: Tue Apr 06, 2010 7:27 am

Re: Email template - add data from the random table

Postby jmestep » Wed Mar 06, 2019 10:03 pm

I don't know about R9, but in R12, you can override the default events handler similar to the following snippet:
Code: Select all
public class PowerWebStoreEventsHandler : DefaultEventsHandler
    {
public override void OrderPlaced(object o, OrderPlacedEventArgs e)
        {
            base.OrderPlaced(o, e);

            var order = e.Order;

...

Edit:
You need to add an entry to the Windsor.config file also, similar to the following if you put your events handler class in the App_Code folder
<component id="W2M_StoreEventsHandler" service="CommerceBuilder.Eventing.IStoreEventsHandler, CommerceBuilder" type="W2M.Services.PowerWebStoreEventsHandler, __Code"/>
Judy Estep
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx
User avatar
jmestep
AbleCommerce Angel
 
Posts: 8159
Joined: Sun Feb 29, 2004 8:04 pm
Location: Dayton, OH

Re: Email template - add data from the random table

Postby confused » Wed Mar 06, 2019 11:59 pm

@Judy

Bingo!

I was struggling with Windsor part yesterday all day long and your "__Code" part made it work.
And yes, it is very simple to override default service using this method.

Thanks!!!
confused
Ensign (ENS)
Ensign (ENS)
 
Posts: 6
Joined: Tue Apr 06, 2010 7:27 am


Return to AbleCommerce 7.0 Asp.Net Shopping Cart

Who is online

Users browsing this forum: No registered users and 5 guests

cron