0

We have this weird issue on one of our websites.

When customers try to buy something they get an error 500 when they complete the order, the order is registered but they get an error 500 and no email is sent to the customer.

This also happens when a new customer is registering, so when they hit submit they get an error 500 and the registration is stored in Magento.

We also get error 500 in Magento when we try to click on the "reset password" button.

The reason why I think it has something to do with emails is that all of these actions should trigger an email to the customer. However, We have tested the email and it works.

This is what i get in the error logs:

==> var/log/exception.log <==
[2021-10-11 14:47:59] main.CRITICAL: Notice: Undefined index: directiveName in /chroot/home/a96f0e0b/stores.etailhandel.no/html/vendor/magento/framework/Filter/DirectiveProcessor/SimpleDirective.php on line 68 {"exception":"[object] (Exception(code: 0): Notice: Undefined index: directiveName in /chroot/home/a96f0e0b/stores.etailhandel.no/html/vendor/magento/framework/Filter/DirectiveProcessor/SimpleDirective.php on line 68 at /chroot/home/a96f0e0b/stores.etailhandel.no/html/vendor/magento/framework/App/ErrorHandler.php:61)"} []

==> ../../logs/php-error.log <==

[11-Oct-2021 14:47:59 UTC] PHP Fatal error:  Uncaught TypeError: Return value of Magento\Framework\Filter\DirectiveProcessor\DependDirective::process() must be of the type string, object returned in /chroot/home/a96f0e0b/stores.etailhandel.no/html/vendor/magento/framework/Filter/DirectiveProcessor/DependDirective.php:47

Stack trace:

#0 /chroot/home/a96f0e0b/stores.etailhandel.no/html/vendor/magento/framework/Filter/Template.php(184): Magento\Framework\Filter\DirectiveProcessor\DependDirective->process(Array, Object(Magento\Email\Model\Template\Filter), Array)

#1 /chroot/home/a96f0e0b/stores.etailhandel.no/html/vendor/magento/module-email/Model/Template/Filter.php(1080): Magento\Framework\Filter\Template->filter('<!-- End Conten...')

#2 /chroot/home/a96f0e0b/stores.etailhandel.no/html/vendor/magento/module-email/Model/AbstractTemplate.php(369): Magento\Email\Model\Template\Filter->filter('<!-- End Conten...')

#3 /chroot/home/a96f0e0b/stores.etailhandel.no/html/vendor/magento/module-email/Model/AbstractTemplate.php(247): Magento\Email\Model\AbstractTempla in /chroot/home/a96f0e0b/stores.etailhandel.no/html/vendor/magento/framework/Filter/DirectiveProcessor/DependDirective.php on line 47
    <!-- End Content -->
                    </td>
                </tr>
                <tr>
                    <td class="footer">
                        <table>
                            <tr>
                                <td>
                                    <p><a href="https://cobi.no/om-cobi-norge">Om Cobi Norge</a></p>
                                    <p><a href="https://cobi.no/nyheter.html">Forhandlernytt</a></p>
                                </td>
                                <td>
                                    {{depend store_phone}}
                                        <p class="phone">
                                            {{trans '<a href="tel:%store_phone">%store_phone</a>' store_phone=$store_phone |raw}}
                                        </p>
                                    {{/depend}}
                                    {{depend store_hours}}
                                        <p class="hours">
                                            Åpningstider: <br />{{<span class="no-link">%store_hours</span>.' store_hours=$store_hours |raw}}
                                        </p>
                                    {{/depend}}
                                </td>
                                <td>
                                    <p class="address">
                                        Kabelgata 8<br/>
                                        0580 Oslo<br/>
                                    </p>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
</table>
<!-- End wrapper table -->
</body>
2
  • Your email template that’s managed in Magento’s Admin is having variables or ‘directives’ {{depends xyz}} inserted that are no longer valid in Magento’s new version. This happened to me when I upgraded my version of Magento from 2.2 to 2.3 . Magento remembered to upgrade everything but the old email templates and I had to edit them manually to be compatible. I found the solution by googling the error about “Depend Directive email error after Magento upgrade”. Sorry my answer could be better but it’s ~2am and my phone’s about to die 😲. Oct 12, 2021 at 8:48
  • Hi, Thank you for the quick response. I did look into what you wrote, but the thing is that we have 5 websites and it is only 1 that has this issue. As I can see all of the templates were made before we upgraded from 2.3.3 to 2.3.6, so we should have seen this issue on other web pages. Oct 12, 2021 at 12:54

1 Answer 1

1

I had this same problem.

Although I don't have access to your store to evaluate your specific case, here are some hypotheses that I encountered when working through this on my own store(s).


Keep in mind: Template issues don't have to exist directly in your top-level email template.
The issue can manifest when a child template contains the issue that is being called-in from your top-level template.
Nonetheless: Be confident that all template issues can be resolved within Magento's Admin and do not require changes to the codebase.


Hypothesis #0 (Very likely)

In the footer_template shown in your Question. There is an inconsistency.

In the first usage of {{trans ''}} regarding store_phone, it looks desired:

{{trans '<a href="tel:%store_phone">%store_phone</a>' store_phone=$store_phone |raw}}

However, in the second usage of {{trans ''}} regarding store_hours, the syntax looks malformed. It seems the opening trans ' after the opening brackets {{ is missing:

{{<span class="no-link">%store_hours</span>.' store_hours=$store_hours |raw}}

Hypothesis #1 (Very likely)

You need to close your template tags!

{{depend some_var}}Some Content{{/depend}}

In my codebase, this was noticed on email templates containing {{template config_path="design/email/footer_template"}} because the footer template we created in Magento's Admin didn't close a depend tag {{depend store_phone}} with a corresponding {{/depend}}.


Hypothesis #2 (Less likely)

A non-existent variable or a variable containing no data.

Although I wasn't able to test this other hypothesis at the time, I became suspicious that using a variable for which there is no data for could also cause this error even if your template tags are properly terminated. However this would be such a silly oversight by Magento that I became doubtful it could be related to the issue.

For example, I thought this could throw an error when I didn't have my phone number saved into Magento Admin's store configuration (at path general/store_information/phone):

{{depend store_phone}}
    Call us: {{store_phone}}
{{/depend}}

Edit answer - added #3:

The original answer was quite good, so I decided to just add my information found as part of it. I am adding an additional possible reason when this error might appear.

Hypothesis #3 (Very likely)

- Nested {{depends}} or {{if}} not supported.

Regarding Hypothesis #2, this should not really going to be a problem if you have a missing value, or missing directive, it will simply output:

<p>Call us: {{store_phone}}</p>

In my testing it just outputs the variable as part of the text.

What this Hypothesis #2 helped me with was to think of {{depend}} and {{if}} together.

To put it simply, it does not appear to be possible to nest multiple same type conditions into each other:

This will also give the same error as original poster:

{{depend order_data.is_not_virtual}}
   <td class="method-info">
      <h3>{{trans "Shipping Method"}}</h3>
      {{depend shipping_msg}}
         <p>{{var shipping_msg}}</p>
      {{/depend}}
    </td>
{{/depend}}

However this should work:

{{depend order_data.is_not_virtual}}
   <td class="method-info">
      <h3>{{trans "Shipping Method"}}</h3>
      {{if shipping_msg}}
         <p>{{var shipping_msg}}</p>
      {{/if}}
    </td>
{{/depend}}

I had an extra {{depend}} inside this {{depend}} for a new custom directive (not shown here, using existing variable directive as example) and it failed since I thought depend and if are used differently (functionally); but as described above it does not appear to be the case really. I do not know what the difference of {{depend}} and {{if}} is functionally, but they appear to be interchangeable.

Summary of all of these errors.

Based on my issue, I assume the regex matching used ensures that there are opening and matching closing entity, so a nested 'condition' entity will partially cut-off the string.

Hypothesis #1 and #2 also seems to reinforce the idea that all of these issues are related to regex matching failure because of unexpected end / missing / malformed 'tags'

3
  • Hi, Thank you for your detailed answer. As i can see from the error message it seams to be a depend tag that is not closed as you say. But I can't seem to find it. I have edited the question with the footer code Oct 12, 2021 at 19:21
  • After looking at your footer_template content, I've updated my answer with another hypothesis. Oct 12, 2021 at 19:35
  • 1
    Thank you so much for your help!!!!! You are a savior, I did not see that at all.... And it was like you said after I added trans before <span it worked again, how could I have missed that Oct 12, 2021 at 19:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.