You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently the credit card form uses hard coded values for the expiration year select element, which means the options start in 2014 and would need to be manually updated every year to remove old values. You can update this values with hypr variables as seen below:
Came up with an alternative solution that leverages the automation that @chris-decker provided above, but that allows the merchant to define the number of years for the expiration date via theme setting (themeSetting.ccYears).
EDIT: I updated/improved my snippet to use a numeric theme setting for number of CC years, and leveraged set_var so we don't have to deal with with scopes, and it simplifies the markup a bit.
{% set_varcurrentYearpageContext.now|date('Y') %}
{% set_varyearsList"a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z"|split(',') %} {# this gives us a list of 26 years #}
{% set_varccYearsthemeSettings.ccYears|default(10) %}
{# sanity check that theme setting is less than the length of yearsList (26) #}
{% ifyearsList.length<ccYears %}
{% set_varccYearsyearsList.length %}
{% endif %}
{# sanity check that the valid length of years is not less than 4 #}
{% ifccYears<4 %}
{% set_varccYears4 %}
{% endif %}
<code>ccYears: </code>{{ ccYears }}
<br><br>
{% partial_cachecurrentYear, ccYears %}
<labelfor="cc-year-dynamic">CC Year: </label>
<selectname="cc-year-dynamic"id="cc-year-dynamic"required>
<option>{{ themeSetting.blankOptionText|default('') }}</option>
{% foryearinyearsList %}
{% ifforloop.counter0<ccYears %}
{% set_varthisYearcurrentYear|add(forloop.counter0) %}
<optionvalue="{{ thisYear }}"{% ifmodel.expireYear==thisYear %} selected="selected"{% endif %}>{{ thisYear }}</option>
{% endif %}
{% endfor %}
</select>
{% endpartial_cache %}
Currently the credit card form uses hard coded values for the expiration year select element, which means the options start in 2014 and would need to be manually updated every year to remove old values. You can update this values with hypr variables as seen below:
These values are currently in use on this sandbox (an active dev environment): http://t15181-s21551.sandbox.mozu.com/
The text was updated successfully, but these errors were encountered: