Search code examples
phptwigopencart-3

Highlight Error message similar to Warning Style In Opencart 3.0.3.8 and Journal theme 3.1.12


I am using Opencart 3.0.3.8 and JournalTheme 3.1.12. I have some custom validation in catalog/controller/journal3/checkout.php The custom validation will display error and it works good. Modified question to make it clear: At present I use the built in error code variable $error['email'] like below:

$error['email'] = "Oops ! Something went wrong. Contact the administrator"; 

This works and error is displayed below the email field.

I wanted this error to appear like the one in Warning message in register.php with pink background in a box or similar to warning message in cart page when add to card more quantity than available. I tried,

$error['warning'] = "Oops ! Something went wrong. Contact the administrator"; 

But it breaks and no other error messages are even displayed. I wanted to display Warning type of error, placed above the confirm order button in Checkout page. As it Journal theme 3 related one, people having enough knowledge of Journal theme 3 files, may easily solve it. I could see the {% if error_warning %} and div class lines in both catalog/view/theme/default/template/checkout/checkout.twig

also in: catalog/view/theme/journal3/template/checkout/checkout.twig

 {% if error_warning %}
      <div class="alert alert-danger alert-dismissible"><i class="fa fa-exclamation-circle"></i> {{ error_warning }}
{% endif %}

The same class "alert alert-danger alert-dismissible" is present in register.twig file where it works in register.php. But warning type not displaying in Checkout page. Where to add the required class and get it to work as intended? Please help me. Thank you


Solution

  • I have solved and done it. I added the following code in catalog/view/theme/journal3/template/journal3/checkout/confirm.twig file without {% if error_warning %} condition:

    <div class="error_email" v-bind:class="{ 'has-error': error && error.email }">      
            <span class="alert alert-danger alert-dismissible" v-if="error && error.warning" v-html="error.warning"></span>
      </div>
    

    Added validation error in checkout.php as:

     $error['warning'] = "Oops ! Something went wrong. Contact the Administrator";
    

    The above worked me.

    One can change the variable from email to whatever for which validation and error display is needed accordingly, based on the above code. Also one can add the error message in language files and call it in Checkout.php. But the div part and error class code in confirm.twig is necessary to get it work.