Post by santanu2019 » Fri Aug 07, 2020 2:42 pm

I am using version 3.x of Opencart.

I have downloaded the Canned Message extension and set it up for V3 But when I'm storing messages in the database with variable, the twig file is displaying as a variable.

I am using this in the order info page in the admin panel

This is my twig file code

Code: Select all

<div class="form-group">
            <label class="col-sm-2" for="cannedmessage"><a href="{{ new_cm }}" class="btn btn-default"><i class="fa fa-plus" aria-hidden="true"></i> Canned message</a></label>
             <div class="col-sm-10">
                  <select name="cannedmessage" id="cannedmessage" class="form-control">
                        <option>Select</option>
                        {% for cannedmessage in cannedmessages %}
                        {% if cannedmessage.status == 1 %}
                        {{ cannedmessage.description | raw }}
                        <option value="{{ cannedmessage.description }}">{{ cannedmessage.title }}</option>
                        {% endif %}
                        {% endfor %}                        
                  </select>
         </div>
 </div>
And Output: See the attach screenshot.

Please help me how to solve this

Attachments

display on twig.PNG

display on twig.PNG (9.93 KiB) Viewed 329 times


New member

Posts

Joined
Wed Jul 03, 2019 7:42 pm

Post by letxobnav » Fri Aug 07, 2020 4:46 pm

check with the Canned Message extension developer.

Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces

“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by santanu2019 » Fri Aug 07, 2020 5:09 pm

letxobnav wrote:
Fri Aug 07, 2020 4:46 pm
check with the Canned Message extension developer.
This is a normal Twig/PHP issue. This is not an extension issue so why I will contact the developer.
anyone please help me

New member

Posts

Joined
Wed Jul 03, 2019 7:42 pm

Post by letxobnav » Fri Aug 07, 2020 6:05 pm

I think your problem has nothing to do with twig but with either you not being able to use that extension or the developer not being able to code it.

Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces

“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by santanu2019 » Fri Aug 07, 2020 6:32 pm

letxobnav wrote:
Fri Aug 07, 2020 6:05 pm
I think your problem has nothing to do with twig but with either you not being able to use that extension or the developer not being able to code it.
Even the ones I'm modifying don't have any effect in the admin panel

New member

Posts

Joined
Wed Jul 03, 2019 7:42 pm

Post by xxvirusxx » Sat Aug 08, 2020 2:11 pm

santanu2019 wrote:
Fri Aug 07, 2020 2:42 pm
I am using version 3.x of Opencart.
There are many 3.x....versions...
And the extension is this?
https://www.opencart.com/index.php?rout ... n_id=30997

OC 2.3.0.2 | OC 3.0.3.6 | Extensions converted by me | Buy me a beer


User avatar
Expert Member

Posts

Joined
Tue Jul 17, 2012 10:35 pm
Location - România

Post by letxobnav » Sat Aug 08, 2020 3:02 pm

normally how this works:
you have a field with placeholders in a file or database:

Code: Select all

Hi { firstname } { lastname }, how are you?
the controller retrieves that field from the database or file, determines which variables you want of the available ones, replaces those placeholders with their values obtained from the database and then sends that to twig.

it is almost identical as using sprintf() where you have a standard string with %s placeholders:

Code: Select all

$template = 'Hi %s %s, how are you?';
$final_text = sprintf($template,$firstname,$lastname);
The difference being that sprintf is rather static, requires the number of placeholders to be the same as the supplied variables and the need to know php whereas with canned messages (read templates) you can freely choose from a predefined set of variables and scatter them in your text and only need to know the syntax and available variables.

Still, the effort lies with the controller and/or models to do the replacements and not with the twig files.

Hence my point that the issue is not with that twig code but with the logic that feeds it, hence, the extension and not a normal twig/php issue.
Or in the way that you use the syntax with that extension, if you use the wrong syntax, the logic will not identify the placeholders, as such cannot replace them and simply outputs the placeholder code which is the scenario I would check first.

Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces

“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by santanu2019 » Mon Aug 10, 2020 1:03 pm

letxobnav wrote:
Sat Aug 08, 2020 3:02 pm
normally how this works:
you have a field with placeholders in a file or database:

Code: Select all

Hi { firstname } { lastname }, how are you?
the controller retrieves that field from the database or file, determines which variables you want of the available ones, replaces those placeholders with their values obtained from the database and then sends that to twig.

it is almost identical as using sprintf() where you have a standard string with %s placeholders:

Code: Select all

$template = 'Hi %s %s, how are you?';
$final_text = sprintf($template,$firstname,$lastname);
The difference being that sprintf is rather static, requires the number of placeholders to be the same as the supplied variables and the need to know php whereas with canned messages (read templates) you can freely choose from a predefined set of variables and scatter them in your text and only need to know the syntax and available variables.

Still, the effort lies with the controller and/or models to do the replacements and not with the twig files.

Hence my point that the issue is not with that twig code but with the logic that feeds it, hence, the extension and not a normal twig/php issue.
Or in the way that you use the syntax with that extension, if you use the wrong syntax, the logic will not identify the placeholders, as such cannot replace them and simply outputs the placeholder code which is the scenario I would check first.
thank you for your replay i have already solved this issue using ajax

Code: Select all

$("#cannedmessage").change(function() {
            var myString = $(this).val();
            var	replaceArray = ['store_name','firstname', 'lastname', 'date_added', 'payment_method','text_order','Total'];
            var	replaceWith = ['{{ store_name }}','{{ firstname }}', '{{ lastname }}', '{{ date_added }}','{{ payment_method }}','{{ text_order }}','{{ total.text }}'];
                for(var i = 0; i < replaceArray.length; i++) {
                    console.log(myString.replace(new RegExp('{' + replaceArray[i] + '}', 'gi'), replaceWith[i]));
                    myString = myString.replace(new RegExp('{ ' + replaceArray[i] + ' }', 'gi'), replaceWith[i]);
                }
            $("#input-comment").val(myString);
            //$("#input-comment").summernote('code', myString);
            
        });

New member

Posts

Joined
Wed Jul 03, 2019 7:42 pm

Post by letxobnav » Mon Aug 10, 2020 1:46 pm

Well, that is not ajax nor is it solving the issue, at best it is correcting the wrong outcome caused by the issue.

Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces

“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan
Who is online

Users browsing this forum: Baidu [Spider] and 20 guests