Monday, March 28, 2016

Content personalization in sitecore8 based on country with Maxmind GeoIP free Service

Content personalization in sitecore8 based on country with Maxmind GeoIP free Service

One of my client requirement was to personalize the sitecore content based on the country(Geo-Ip). And they were using free geo-ip country database provided by maxmind.
Site core Personalization (country rules) is tightly coupled with analytic database so we need to customize the  sitecore condition to call geolite country database file to resolve the country ip address.
So below is the step by step process to implement this solution:
Configure the layout with rule and condition
Step1. Go to the sitecore > Item > presentation>Details>Edit>Controls>Personalization>



Step2. Add new condition and edit rule



Step3. In rule editor, select geo-ip condition and provide value of compareto and specific country attribute as below



Step4. Select the presentation content> select the datasource



Step5. You can add n number of condition with default condition



Not working...ohh missed one step, now one sitecore presentation task has been done but still personalization condition is point to analytic dll, we need to override that condition with custom dll, as below:
Kindly refer my blog to find the new path of condition item in sitecore 8


Need to change the type as below:

          Class name, Namespace
Below is the sample code for custom class logic:
public class LiteCountryCondition<T> : CountryCondition<T> where T : RuleContext
    {
        
        protected override string GetColumnValue(VisitorDataSet.VisitsRow visit)
        {
            try
            {
                string countryCode = string.Empty;

                if (Sitecore.Context.Item != null)
                {
                    LookupService lookupService =
                           new LookupService(
                               HttpContext.Current.Server.MapPath(
                                   Sitecore.Configuration.Settings.GetSetting("Sitecore.SharedSource.GeoLiteResolver.DataFile")),
                               LookupService.GEOIP_MEMORY_CACHE);
                    Country country = lookupService.getCountry(HttpContext.Current.Request.UserHostAddress);
                    return country.getCode();
                }
                return countryCode;

            }
            catch (Exception ex)
            {
                Sitecore.Diagnostics.Log.Error(string.Format("LiteCountryCondition: Exception: {0}, Inner Exception: {1},  LiteCountryCondition : GetColumnValue",
                    ex.Message, ex.InnerException != null ? ex.InnerException.Message : string.Empty), this);
                return "";
            }




        }
    }


I Hope you enjoyed this article..

Appreciate to your suggestion and comments


Happy sitecore :)

Saturday, March 26, 2016

Country Condition (Geo IP) item path location changed in sitecore 8

Country Condition (Geo IP) item path changed in sitecore 8 for personalization

Recently I have implemented the personalization(country based layout rendering) on site core 8.1 and wanted to overrides the existing country condition of sitecore with my custom logic.
So I noticed that the path of the country condition has been changed as below




/sitecore/system/Settings/Rules/Definitions/Obsolete/Marketing Workflows/Conditions/Geo IP/Country Condition
Previously in sitecore 7 versions the country folder path as below:

/sitecore/system/Settings/Rules/Conditional Renderings/Conditions/Geo IP/Country Condition





Happy Sitecore :)

Wednesday, March 2, 2016

Copy all content from one language to another in sitecore


Copy all content of the sitecore tree from one language to another

If you want to migrate all the content of the siteore from existing language to new language then below solution is fit for you.

Problem statement: my client wanted to migrate the complete site from /fr-fr to /fr  so I had to migrate all language version of “fr-fr” into new language version called “fr”. We migrated more than 1 million items from FR-FR to fr with below solution:

Solution:
There are three major tasks to migrate this language

  1. Export the language
  2. Change the language in file
  3. Import the language


Export language

Step1: Create new language in the system called FR only.

Step2.  Go to control panel > globalization>



Step3. Click on export language to a file



Step4. Select the language that needs to be migrated ex. Fr-fr



Step5. Select the content tree that needs to be migrated. In my case I selected the content folder as I need to migrate the complete tree, but we can select any folder or item.




Step6. Enter the file name.





Step7 . Download the file



Step8: Open the file in notepad ++ or any editor and replace fr-fr with fr



Step 9 : Same as replace </fr-fr> with </fr> and save the file





Step 10: Import the saved file:



Step11: Browse the file









Step12: select the new language(import)











Step13 : Finished the import dialog



Step14Now new language version has been created with all field value of fr-fr > go to item > language version>






If you have any comments or suggestions, please use the comments below, thanks.

Happy Sitecore