Post by Majnoon » Fri Jun 10, 2022 4:49 pm

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' %}
              &nbsp;<small> - {{ option.name }}: {{ option.value }}</small> {% else %}
              &nbsp;<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

Code: Select all

{{ product.name }}
into the link it doesn't show output compare to

Code: Select all

{{ firstname }}
Link example:

Code: Select all

<td><a href="https://wa.me/9{{ telephone }}?text=Hi {{ firstname }} {{ lastname }}," target="_blank">{{ telephone }}</a></td>
Last edited by Majnoon on Mon Jun 13, 2022 8:54 pm, edited 1 time in total.

Active Member

Posts

Joined
Fri Feb 05, 2021 8:29 pm

Post by JNeuhoff » Fri Jun 10, 2022 5:02 pm

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,
		.....
	);

Override Engine * Integrated VQMod * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Rich Snippets * Google Tag Manager * Export/Import Tool * SpamBot Buster * Survey Plus


User avatar
Guru Member

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by Majnoon » 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? ???

Active Member

Posts

Joined
Fri Feb 05, 2021 8:29 pm

Post by JNeuhoff » Fri Jun 10, 2022 5:22 pm

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>

Override Engine * Integrated VQMod * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Rich Snippets * Google Tag Manager * Export/Import Tool * SpamBot Buster * Survey Plus


User avatar
Guru Member

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by Majnoon » Fri Jun 10, 2022 7:01 pm

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

Active Member

Posts

Joined
Fri Feb 05, 2021 8:29 pm

Post by JNeuhoff » Fri Jun 10, 2022 8:15 pm

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

Override Engine * Integrated VQMod * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Rich Snippets * Google Tag Manager * Export/Import Tool * SpamBot Buster * Survey Plus


User avatar
Guru Member

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by Majnoon » Fri Jun 10, 2022 9:15 pm

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.

Attachments

url-encoded.png

url-encoded.png (127.06 KiB) Viewed 108 times


Active Member

Posts

Joined
Fri Feb 05, 2021 8:29 pm

Post by JNeuhoff » 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.

Override Engine * Integrated VQMod * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Rich Snippets * Google Tag Manager * Export/Import Tool * SpamBot Buster * Survey Plus


User avatar
Guru Member

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by Majnoon » Fri Jun 10, 2022 11:09 pm

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 .

Active Member

Posts

Joined
Fri Feb 05, 2021 8:29 pm

Post by Majnoon » Mon Jun 13, 2022 11:07 am

@JNeuhoff any thoughts ?

Active Member

Posts

Joined
Fri Feb 05, 2021 8:29 pm

Post by DigitCart » Mon Jun 13, 2022 3:59 pm

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 %}

My Extensions


User avatar
Active Member

Posts

Joined
Thu Jun 22, 2017 5:32 pm


Post by Majnoon » Mon Jun 13, 2022 4:16 pm

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. :-* :)

Active Member

Posts

Joined
Fri Feb 05, 2021 8:29 pm
Who is online

Users browsing this forum: No registered users and 1 guest