complex if else logic in message template

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
3 Jahre weitere
Anyone ever get more than %if (your conditions) ... endif% logic to work?  It's probably better handled in a Factory extension/override method that sets a bool similar to how %Order.Shippable% is handled, but now I'm curious as to what's possible in the template itself.

For example, I want to offer customers the option to pay extra to have their order items shipped as they become available, rather than in 1 complete shipment.  (I offer this during checkout but many customers overlook it, so I want to make it easy after checkout too).  

So in the OrderPaid.CustomerNotification template I have something like:

%if (%Order.ShippingCountry% == "United States" && %Order.Shippable% && !(%Order.ShippingMethod%).Contains("multiple")) To have items shipped as they become available click the link above to view your order. Eligible orders will offer a Splitship option. endif%


But in testing, the && operators have been html encoded to && by the tinyMCE editor, so I end up with this conditionalStatement in the Tokenizer:
 ("United States" == "United States" && True && !("ground shipping").Contains("multiple"))


I think the linq Contains should work in the AsQueryable(), but I would have to find/replace the && beforehand, which means overriding that method so I'm probably better off just moving the logic out of the template in the first place.
3 Jahre weitere
Stumbled across this when trying to check if a simple if an else can be added or is a case statement is possible. I think this needs to be editable at template level so that the site administrator can edit it if conditions change.
3 Jahre weitere
I did some digging and it's not very straightforward to get the CKeditor to stop encoding &&:
https://ckeditor.com/old/forums/CKEditor-3.x/Conversion-special-characters

It should be possible to override ReplaceConditionalStatements to detect an %else% token in between %if% and %endif%, and then some experimentation to find the limits of AsQueryable() and Linq, but rather than go down that route I moved my logic into a factory method.
3 Jahre weitere
The conditional capability is provided by "Dynamic Linq".  Thus, you can use 'and' rather than '&&' - e.g.

%if (%Order.ShippingCountry% == "United States" and %Order.Shippable% and !(%Order.ShippingMethod%).Contains("multiple")) To have items shipped as they become available click the link above to view your order. Eligible orders will offer a Splitship option. endif%
3 Jahre weitere
Nice!  I'll have to give that a try.
2 Jahre weitere
motoTed wrote:
Nice!  I'll have to give that a try.

I tried using 'and' instead of '&&' it didn't work. did you find any solution to this?
2 Jahre weitere
What version of nopCommerce?
Describe "didn't work";  what output are you seeing?

Try putting spaces around your operators
%if (%Order.PaymentMethod% == "paypal" and %Order.ShippingMethod% == "Standard") text... endif%

The "==" is an exact match (case matters too).  And, the method names will be the Friendly Names (and localized too if you have multiple languages).  E.g.
   %Order.PaymentMethod% == "PayPal Standard"
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.