Skip to content

Instantly share code, notes, and snippets.

@keyan1603
keyan1603 / GetSiteSettings.cs
Created September 20, 2023 18:43
Sitecore SXA – To get Site Settings for a Site
View GetSiteSettings.cs
public static T GetValueFromSiteSettings<T>(IMvcContext mvcSiteContext, string TenantSiteSettingsTemplateId)
{
var query = "/sitecore/content//*[@@ID='" + mvcSiteContext.GetRootItem<Item>().ID + "']/*[@@templateId='" + TenantSiteSettingsTemplateId + "']";
var settings = mvcSiteContext.SitecoreService.Database.SelectSingleItem(query);
if (settings == null)
{
return null;
}
return mvcSiteContext.SitecoreService.GetItem<T>(settings);
}
@keyan1603
keyan1603 / Coveo.SearchProvider.Custom.config
Created September 20, 2023 18:38
To add a new Coveo index in Sitecore (tested on Sitecore 9.2)
View Coveo.SearchProvider.Custom.config
<index id="Coveo_pub_index" type="Coveo.SearchProvider.ProviderIndex, Coveo.SearchProvider" patch:before = "*[3]">
<param desc="p_Name">$(id)</param>
<configuration ref="coveo/defaultIndexConfiguration" />
<locations hint="list:AddCrawler">
<crawler name="ContentCrawler" type="Sitecore.ContentSearch.SitecoreItemCrawler, Sitecore.ContentSearch">
<database>pub</database>
<root>/sitecore/content</root>
<stopOnError>true</stopOnError>
</crawler>
<crawler name="MediaLibraryCrawler" type="Sitecore.ContentSearch.SitecoreItemCrawler, Sitecore.ContentSearch">
@keyan1603
keyan1603 / SitecoreHelixLoggingFramework.config
Created September 20, 2023 18:37
Sitecore Helix – Feature based logging framework - Config update
View SitecoreHelixLoggingFramework.config
<?xml version="1.0"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/" xmlns:env="http://www.sitecore.net/xmlconfig/env/">
<sitecore>
<log4net>
<appender name="MySite.Feature.Products" type="log4net.Appender.RollingFileAppender, Sitecore.Logging">
<file value="$(dataFolder)/logs/MySite.Feature.Products.log.{date}.txt" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maximumFileSize value="10MB" />
<maxSizeRollBackups value="-1" />
@keyan1603
keyan1603 / SitecoreHelixLogging.cs
Created September 20, 2023 18:37
Sitecore Helix – Feature based logging framework
View SitecoreHelixLogging.cs
using System;
namespace MySite.Foundation.Common
{
public interface ILoggerService
{
#region Debug
void Debug(string message);
void Debug(string message, Exception ex);
#endregion
@keyan1603
keyan1603 / ResetSitecoreAdminPassword.sql
Created September 20, 2023 18:35
Reset Sitecore Admin account password without logging into Sitecore
View ResetSitecoreAdminPassword.sql
UPDATE
[aspnet_Membership]
SET
[Password]='qOvF8m8F2IcWMvfOBjJYHmfLABc=',
[PasswordSalt]='OM5gu45RQuJ76itRvkSPFw==',
[IsApproved] = '1',
[IsLockedOut] = '0'
WHERE
UserId IN (
SELECT UserId FROM dbo.aspnet_Users WHERE UserName = 'sitecore\Admin'
@keyan1603
keyan1603 / SitecoreAllowDuplicateName.config
Created September 20, 2023 18:34
Allow duplicate Item Names in Sitecore content tree at the same folder level
View SitecoreAllowDuplicateName.config
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:role="http://www.sitecore.net/xmlconfig/role/">
<sitecore>
<settings>
<setting name="AllowDuplicateItemNamesOnSameLevel" value="true" />
</settings>
</sitecore>
</configuration>
@keyan1603
keyan1603 / UpdateFields.ps1
Created September 20, 2023 18:33
Update fields in Sitecore for all items based on a specific Template in all languages using Powershell script – with Progress bar
View UpdateFields.ps1
#Get all Product from the Master index for all languages.
#You can change this to get data from specific language codes
#like 'en', 'fr', etc.
$searchCriteria = @(
@{ Filter = "Equals"; Field = "_language"; Value = "*"; }
@{ Filter = "Equals"; Field = "_templatename"; Value = "Product"; }
)
#This script executes against Sitecore master index
$searchProps = @{
@keyan1603
keyan1603 / blockiframecookiesexample.html
Created September 20, 2023 18:31
Block iFrame cookies
View blockiframecookiesexample.html
<iframe sandbox="allow-scripts" src="..."></iframe>
@keyan1603
keyan1603 / createssl.ps1
Created September 20, 2023 18:27
Create SSL – Self signed certificate for your localhost website
View createssl.ps1
$dnsname = "mysite.com"
$pwd = ConvertTo-SecureString -String "123456" -Force -AsPlainText
$print = (New-SelfSignedCertificate -certstorelocation cert:\localmachine\my -dnsname $dnsname).Thumbprint
$path = "c:\Windows\temp\cert.pfx"
Export-PfxCertificate -cert cert:\localMachine\my\$print -FilePath $path -Password $pwd
@keyan1603
keyan1603 / coveodistancesort.js
Created September 20, 2023 18:26
Coveo distance sort using Javascript framework on static devices with no geolocation data
View coveodistancesort.js
Coveo.$$(search).on("buildingQuery",
function (e, args) {
var currentLatitude = getCookie("currentlatitude");
var currentLongitude = getCookie("currentlongitude");
var latitudeField = '@@' + CoveoForSitecore.Context.fields.toCoveo('latitude');
var longitudeField = '@@' + CoveoForSitecore.Context.fields.toCoveo('longitude');
var distanceField = CoveoForSitecore.Context.fields.toCoveo('distance');
if (currentLatitude != '' && currentLongitude != '') {
var geoQuery = "$qf(function:'dist(" + latitudeField + "," + longitudeField + "," + currentLatitude + "," + currentLongitude + ")', fieldName: 'distance') ";
if (args && args.queryBuilder) {