E-com notification

Dominic Boyer asked on July 31, 2020 20:08

Him working on the e-com notification and i have a custom table (customtablename) and I can't figure out how to pass the Order.ID in the where condition:

{% GlobalObjects.CustomTables["customtablename"].Items.Where("OrderID = '" + Order.ID + "'")[0]["FirstName"]

Order.ID in the where condition doesnt work, but if i only put {% Order.ID #%} in my html notification it return the good value...

someone have a solution for that ? thank you

Correct Answer

Dominic Boyer answered on August 10, 2020 22:01

the automatic email notification work great, but i think i need to desactivate the notification on createorder and add one at change order status, like that i can get the orderID at the creation of the table put it in the custom table and then call a order status change later...

0 votesVote for this answer Unmark Correct answer

Recent Answers


Brenden Kehren answered on August 1, 2020 18:50

Where are you using this macro? Need some context to be able to provide an answer

0 votesVote for this answer Mark as a Correct answer

Dominic Boyer answered on August 2, 2020 17:29

Hi Brenden, i use this macro in the e-commerce notification for a new E-commerce Order send to the Administrator. I have a custom table with some information(fields) and a orderID field. So in my notification, i need to get those value of that custom table "link" to the orderID. i can get the count of that custom table, but i cant figute out how to "put" the order.id in the where condition??? hope you understand, i speak french :) Thank you

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on August 2, 2020 22:10

Ok makes sense. The COM_Order table doesn't have an ID field so so that may be your issue. Try OrderID instead.

0 votesVote for this answer Mark as a Correct answer

Dominic Boyer answered on August 3, 2020 16:49

The Order.ID (insert macro) is the associated context specific object "OrderID of the Com_Order table" of that customer for that order. If i insert simply {% Order.ID %} its ok, but i can't in the where conditions:(

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on August 4, 2020 15:26

Have you ran the macro statement under System > Macros > Console and inserted a value where the macro for Order ID is? Does it work? Have you tried casting that INT to a String in the macro?

{% GlobalObjects.CustomTables["customtablename"].Items.Where("OrderID = '" + Order.ID.ToString() + "'")[0]["FirstName"]

0 votesVote for this answer Mark as a Correct answer

Dominic Boyer answered on August 4, 2020 17:26

if i inserted in the macro statement (where 199 is a valid OrderID) it work GlobalObjects.CustomTables["MAGN.Beneficiary"].Items.Where("OrderID = '" + 199 + "'")[0]["FirstName"]

even if i try it work: GlobalObjects.CustomTables["MAGN.Beneficiary"].Items.Where("OrderID = '" + 199 + "'").Transform("{#FirstName#}")

{% Order.ID #%} give me the orderID

but if i put any object or var in the where condition, nothing works, even if i try to cast to string

0 votesVote for this answer Mark as a Correct answer

Dominic Boyer answered on August 4, 2020 19:42

{% orderid = 199; GlobalObjects.CustomTables["customtable"].Items.Where("OrderID = " + orderid + "").Transform("{#FirstName#}").ToUpper() #%} >> works great

{% Order.ID #%} >> works great

{% orderid = Order.ID; GlobalObjects.CustomTables["customtable"].Items.Where("OrderID = " + orderid + "").Transform("{#FirstName#}").ToUpper() #%} >> doesnt work

{% orderid = Order.ID.ToString(); GlobalObjects.CustomTables["customtable"].Items.Where("OrderID = " + orderid + "").Transform("{#FirstName#}").ToUpper() #%} >> doesnt work

{% GlobalObjects.CustomTables["customtable"].Items.Where("OrderID = " + Order.ID + "").Transform("{#FirstName#}").ToUpper() #%} >> doesnt work

{% GlobalObjects.CustomTables["customtable"].Items.Where("OrderID = " + Order.ID.ToString()+ "").Transform("{#FirstName#}").ToUpper() #%} >> doesnt work

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on August 4, 2020 19:59

I'm kind of at a loss here so I'll start shooting out some troubleshooting ideas.

  1. Check the event log and see what the error is being logged. Most likely if it is failing, there is some event log record being created.
  2. It could be an issue with the string is being escaped for SQL Injection security. So try putting this flag at the end of the macro {% orderid = Order.ID; GlobalObjects.CustomTables["customtable"].Items.Where("OrderID = " + orderid + "").Transform("{#FirstName#}").ToUpper()|(handlesqlinjection)false%}
  3. Try using .WhereEquals("OrderID", Order.ID) vs. manually creating the statement. Seems rudimentary but sometimes it helps escape SQL injection issues in the backend and resolve the issue.
0 votesVote for this answer Mark as a Correct answer

Dominic Boyer answered on August 4, 2020 21:23

Hi Brenden, nothing in the event log and no luck with all the solution

I try: GlobalObjects.CustomTables["customtable"].Items.Where("OrderID = '" + 199 + "'").ItemsAsFields.Firstname and it work

if i execute: GlobalObjects.CustomTables["customtable"].Items.ItemsAsFields.OrderID it show me all the row with the good orderid value

if i execute: GlobalObjects.CustomTables["MAGN.Beneficiary"].Items.Columns("OrderID") it show me all the row with the orderid value at 0

but if i execute: GlobalObjects.CustomTables["MAGN.Beneficiary"].Items.Columns("ItemID") it show me all the row with the good itemid value (default field when creating a new custom table)

and now just to add up i put the Order.OrderCulture in the notification and it always show the default culture (fr-ca) but in the database is "en-us"... im really lost with all the e-commerce notification.

0 votesVote for this answer Mark as a Correct answer

Dominic Boyer answered on August 10, 2020 21:53

Hi Brenden i think i found out why is not getting value from the customtable. When the order is create from the shoppingcart i think it trigger the notification.

OrderInfo order = shoppingService.CreateOrder();

but i need to create that order to get that orderid to insert it in my customtable. So when i try to get the row where the orderID in the notification, that row doesnt exist. I just need to found a way to trigger the notification for a new order after all those action...

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on August 10, 2020 21:56

Out of the box, Kentico will send email notifications during different statuses of an order. Will the automatic email notifications not work?

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.