HomeHome Product Discus... Product Discus...RazorCartRazorCartSetting the default country/state in the viewsetSetting the default country/state in the viewset
Previous
 
Next
New Post
5/25/2018 4:30 PM
 
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>

At your service,
Dave Smith
DotNetNuke Consulting, DotNetNuke Store and DNN Ecommerce
 
New Post
9/5/2018 3:07 PM
 
Dave,

Thanks for posting how update the set the default country/state in the viewset. While we were following your instructions we noticed the select statement for billCountry is not correct. Please update item 2 with the following:

<select name="billCountry" class="form-control" ng-model="checkout.billing.CountryID" ng-disabled="true" ng-init="checkout.billing.CountryID = checkout.billing.CountryID || (checkout.countries | filter : {'Value': 'US'})[0].EntryID; checkout.billCountryChange()">
<option>-- @Dnn.LocalizeString("Country") --</option>
<option ng-repeat="country in checkout.countries" value="{{country.EntryID}}">{{country.Text}}</option>
</select>

Thanks
 
Previous
 
Next
HomeHome Product Discus... Product Discus...RazorCartRazorCartSetting the default country/state in the viewsetSetting the default country/state in the viewset