如果其他不在opencart 3 trick文件中工作



我试图在opencart 3中集成以下代码,但我不知道为什么我的代码id没有执行?我是新手。请帮我解决这个问题。

{% for product in products %}
{{ product.total}}  
{% set my_total = product.total|replace({'AED': '', ',': ''}) %}
{{ my_total }}
{% endfor %}
{% if my_total >= 500.00 %}
{% set randomPassword = [] %}
{% set alpha = 'abcdefghijklmnopqrstuvwxyz' %}
{% set numbers = '0123456789' %}
{% for i in 1..10 %}
{% set randomCharacter = random(alpha ~ alpha|upper ~ numbers ~ '-_') %}
{% set randomPassword = randomPassword|merge([randomCharacter]) %}
{% endfor %}
{% set randomPassword = randomPassword|join %}
{{ order_id }}{{ randomPassword }}
{% else %}
(text)
{% endif %}

for-循环中定义的变量只有在这样的循环中才是已知的。当你试图在循环外访问my_total时,你需要在循环外定义它,例如

{% set my_total = 0 %} {# <--- outside the loop #}
{% for product in products %}
{% set my_total = my_total + product.total|replace({'AED': '', ',': ''}) %}
{% endfor %}
{% if my_total >= 500.00 %} {# <--- still accessible #}
{% set randomPassword = [] %}
{% set alpha = 'abcdefghijklmnopqrstuvwxyz' %}
{% set numbers = '0123456789' %}
{% for i in 1..10 %}
{% set randomCharacter = random(alpha ~ alpha|upper ~ numbers ~ '-_') %}
{% set randomPassword = randomPassword|merge([randomCharacter]) %}
{% endfor %}
{% set randomPassword = randomPassword|join %}
{{ order_id }}{{ randomPassword }}
{% else %}
(text)
{% endif %}

演示


注意:您应该启用调试模式以查看分支错误,当运行您的代码时,您会清楚地得到以下错误

变量"my_total";不存在。

最新更新