Question: Is there a way to set the country and regions to display by default value on the checkout page? Our client doesn't do business internationally and wishes that there weren't so many steps to select the region/state. Ideally they would like country to be disabled and automatically set to United States and the regions drop down to automatically be populated with the states. Right now it looks like there's an onchange event that needs to be triggered in order to render the region list. Is there an easy way around this?
Answer: You can do this by modifying the view sets (Please clear dnn cache and restart app pool after doing this):
1. \DesktopModules\MVC\RazorCart\Checkout\Views\Shared\_Shipping.cshtml
Find the select element with name attribute shipCountry and add these two attributes
a) ng-disabled="true"
this attribute will disable the select element
b) ng-init="checkout.shipping.CountryID = checkout.shipping.CountryID || (checkout.countries | filter : {'Value': 'US'})[0].EntryID; checkout.shipCountryChange()"
this attribute will check if there's no country (no customer/user records) it will set it to US, then it will call api and fill regions.
c) (optional) since the select element is disabled you can remove ng-change="checkout.shipCountryChange()" attribute
<select name=
"shipCountry"
class=
"form-control"
ng-model=
"checkout.shipping.CountryID"
ng-disabled=
"true"
ng-init=
"checkout.shipping.CountryID = checkout.shipping.CountryID || (checkout.countries | filter : {'Value': 'US'})[0].EntryID; checkout.shipCountryChange()"
required><br> <option value=
""
disabled selected>-- @Dnn.LocalizeString(
"Country"
) --</option><br> <option ng-repeat=
"country in checkout.countries"
value=
"{{country.EntryID}}"
>{{country.Text}}</option><br></select>
2. \DesktopModules\MVC\RazorCart\Checkout\Views\Shared\_Billing.cshtml
<select name=
"billCountry"
class=
"form-control"
ng-model=
"checkout.billing.CountryID"
ng-disabled=
"true"
ng-init=
"checkout.shipping.CountryID = checkout.shipping.CountryID || (checkout.countries | filter : {'Value': 'US'})[0].EntryID; checkout.shipCountryChange()"
required><br> <option value=
""
disabled selected>-- @Dnn.LocalizeString(
"Country"
) --</option><br> <option ng-repeat=
"country in checkout.countries"
value=
"{{country.EntryID}}"
>{{country.Text}}</option><br></select>