Page 1 of 1
[SOLVED] Why order_info.twig use {{ product.name }} rather then {{ productname }}
Posted: Fri Jun 10, 2022 4:49 pm
by Majnoon
Hi,
This is just a question regarding opencart 3 version
Was looking into admin/view/template/sale/order_info.twig
Code: Select all
{% for product in products %}
<tr>
<td class="text-left"><a href="{{ product.href }}">{{ product.name }}</a> {% for option in product.option %} <br />
{% if option.type != 'file' %}
<small> - {{ option.name }}: {{ option.value }}</small> {% else %}
<small> - {{ option.name }}: <a href="{{ option.href }}">{{ option.value }}</a></small> {% endif %}
{% endfor %}</td>
<td class="text-left">{{ product.model }}</td>
<td class="text-right">{{ product.quantity }}</td>
<td class="text-right">{{ product.price }}</td>
<td class="text-right">{{ product.total }}</td>
</tr>
{% endfor %}
because when trying to use
into the link it doesn't show output compare to
Link example:
Code: Select all
<td><a href="https://wa.me/9{{ telephone }}?text=Hi {{ firstname }} {{ lastname }}," target="_blank">{{ telephone }}</a></td>
Re: Why order_info.twig use {{ product.name }} rather then {{ productname }}
Posted: Fri Jun 10, 2022 5:02 pm
by JNeuhoff
This is correct, because in the controller the 'products' variable is generated like this:
Code: Select all
$data['products'][] = array(
'order_product_id' => $product['order_product_id'],
'product_id' => $product['product_id'],
'name' => $product['name'],
'model' => $product['model'],
'option' => $option_data,
.....
);
Re: Why order_info.twig use {{ product.name }} rather then {{ productname }}
Posted: Fri Jun 10, 2022 5:08 pm
by Majnoon
So if want to output product name the url in this way it doesnt work
Code: Select all
<td><a href="https://wa.me/9{{ telephone }}?text=Hi {{ product.name}}" target="_blank">{{ telephone }}</a></td>
in this case what would be the proper solution to it?

Re: Why order_info.twig use {{ product.name }} rather then {{ productname }}
Posted: Fri Jun 10, 2022 5:22 pm
by JNeuhoff
Majnoon wrote: ↑Fri Jun 10, 2022 5:08 pm
So if want to output product name the url in this way it doesnt work
Code: Select all
<td><a href="https://wa.me/9{{ telephone }}?text=Hi {{ product.name}}" target="_blank">{{ telephone }}</a></td>
in this case what would be the proper solution to it?
Well, if you want to use variables in a URL, you should escape them:
Code: Select all
<td><a href="https://wa.me/9{{ telephone|url_escape }}?text=Hi%20{{ product.name|url_escape }}" target="_blank">{{ telephone }}</a></td>
Re: Why order_info.twig use {{ product.name }} rather then {{ productname }}
Posted: Fri Jun 10, 2022 7:01 pm
by Majnoon
JNeuhoff wrote: ↑Fri Jun 10, 2022 5:22 pm
Well, if you want to use variables in a URL, you should escape them:
Code: Select all
<td><a href="https://wa.me/9{{ telephone|url_escape }}?text=Hi%20{{ product.name|url_escape }}" target="_blank">{{ telephone }}</a></td>
This throws the error:
PHP Fatal error: Uncaught Twig\Error\SyntaxError: Unknown "url_escape" filter. Did you mean "url_encode" in "sale/order_info.twig" at line 74? in /home/eashome/public_html/easyboy/storage/vendor/twig/twig/src/ExpressionParser.php:772
Stack trace:
#0 /home/eashome/public_html/easyboy/storage/vendor/twig/twig/src/ExpressionParser.php(554): Twig\ExpressionParser->getFilterNodeClass('url_escape', 74)
#1 /home/eashome/public_html/easyboy/storage/vendor/twig/twig/src/ExpressionParser.php(539): Twig\ExpressionParser->parseFilterExpressionRaw(Object(Twig\Node\Expression\GetAttrExpression))
#2 /home/eashome/public_html/easyboy/storage/vendor/twig/twig/src/ExpressionParser.php(397): Twig\ExpressionParser->parseFilterExpression(Object(Twig\Node\Expression\GetAttrExpression))
#3 /home/eashome/public_html/easyboy/storage/vendor/twig/twig/src/ExpressionParser.php(289): Twig\ExpressionParser->parsePostfixExpression(Object(Twig\Node\Expression\GetAttrExpression))
#4 /home/eashome/public_html/easyboy/storage/vendor/twig/twig/src/ExpressionPar in /home/eashome/public_html/easyboy/storage/vendor/twig/twig/src/ExpressionParser.php on line 772
Re: Why order_info.twig use {{ product.name }} rather then {{ productname }}
Posted: Fri Jun 10, 2022 8:15 pm
by JNeuhoff
Yes, the error message is right. It should be this:
Code: Select all
<td><a href="https://wa.me/9{{ telephone|url_encode }}?text=Hi%20{{ product.name|url_encode }}" target="_blank">{{ telephone }}</a></td>
See
https://twig.symfony.com/doc/3.x/filter ... ncode.html
Re: Why order_info.twig use {{ product.name }} rather then {{ productname }}
Posted: Fri Jun 10, 2022 9:15 pm
by Majnoon
JNeuhoff wrote: ↑Fri Jun 10, 2022 8:15 pm
Code: Select all
<td><a href="https://wa.me/9{{ telephone|url_encode }}?text=Hi%20{{ product.name|url_encode }}" target="_blank">{{ telephone }}</a></td>
Tried but still nothing prints except the Hi

I did attach the output for your reference.
Re: Why order_info.twig use {{ product.name }} rather then {{ productname }}
Posted: Fri Jun 10, 2022 10:03 pm
by JNeuhoff
In that case you need to provide more details, or re-post it on the commercial support section to find a professional developer to take a look at it.
Re: Why order_info.twig use {{ product.name }} rather then {{ productname }}
Posted: Fri Jun 10, 2022 11:09 pm
by Majnoon
JNeuhoff wrote: ↑Fri Jun 10, 2022 10:03 pm
In that case you need to provide more details, or re-post it on the commercial support section to find a professional developer to take a look at it.
It is very simple modification in my opencart 3.0.3.5 admin where in the order_info.twig made a small change when i click on the phone number it should open as What'sApp link with predefine message.
Where is the message is define as this:
Code: Select all
<td><a href="https://wa.me/9{{ telephone }}?text=Hi%20{{ product.name|url_encode }}" target="_blank">{{ telephone }}</a></td>
It is only {{ product.name|url_encode }} which is not translating .
Re: Why order_info.twig use {{ product.name }} rather then {{ productname }}
Posted: Mon Jun 13, 2022 11:07 am
by Majnoon
@JNeuhoff any thoughts ?
Re: Why order_info.twig use {{ product.name }} rather then {{ productname }}
Posted: Mon Jun 13, 2022 3:59 pm
by DigitCart
Hi
Please note {{ product.name }} works inside the for loop.
Example, This will work:
Code: Select all
{% for product in products %
...
{{ product.name }}
...
{% endfor %}
Example, This will not work:
Code: Select all
{{ product.name }}
{% for product in products %
...
{% endfor %}
Re: Why order_info.twig use {{ product.name }} rather then {{ productname }}
Posted: Mon Jun 13, 2022 4:16 pm
by Majnoon
DigitCart wrote: ↑Mon Jun 13, 2022 3:59 pm
Hi
Please note {{ product.name }} works inside the for loop.
Thanks for explaining.
I was able to print as i wanted.
