Skip to content

Instantly share code, notes, and snippets.

@RyanABailey
RyanABailey / c#
Last active March 8, 2016 01:01
Sitecore searcher
public static class Searcher
{
public static List<SearchResult> DoSearch(string searchTerm)
{
var searchIndex = ContentSearchManager.GetIndex("MySearchIndex"); // Get the search index
var searchPredicate = GetSearchPredicate(searchTerm); // Build the search predicate
using (var searchContext = searchIndex.CreateSearchContext()) // Get a context of the search index
{
var searchResults = searchContext.GetQueryable<SearchModel>().Where(searchPredicate); // Search the index for items which match the predicate
@RyanABailey
RyanABailey / XML
Created February 17, 2016 20:04
Patch
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<settings>
<setting name="Analytics.PerformLookup">
<patch:attribute name="value">false</patch:attribute>
</setting>
</settings>
</sitecore>
</configuration>
@RyanABailey
RyanABailey / gist:cc5eea0e7a2626274a95
Created February 16, 2016 19:45
Sitecore reporting section
<reporting>
<dataProvider>
<datasources>
<add key="item">
<FiltersFactory>
<param desc="definitionDatabaseName">web</param>
</FiltersFactory>
</add>
<add key="collection">
<FiltersFactory>
@RyanABailey
RyanABailey / C#
Created November 25, 2015 07:16
Entity First Composite Key
public class Raffle
{
public int RaffleId { get; set; }
public virtual List<Ticket> Tickets { get; set; }
}
public class Ticket
{
[Key, Column(Order = 0)]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
@RyanABailey
RyanABailey / Product Creation
Created November 23, 2015 02:27
uCommerce API
private static readonly Guid ProductDefinitionGuid = new Guid("{9B19A3A0-287B-4DA4-B45E-018BD94F2718}"); // Product (template in SC content tree)
private static readonly Guid ProductVariantDefinitionGuid = new Guid("{70D1C14E-15FA-F05C-28D9-2E6DEAAD2A27}"); // Product Variant (template in SC content tree)
private static readonly PriceGroup AuPriceGroup = PriceGroup.SingleOrDefault(x => x.Name == "AU 10 pct");
// Model to create a product
public class CreateProductModel
{
public string Sku { get; set; }
public string Name { get; set; }
public bool AllowOrdering { get; set; }
@RyanABailey
RyanABailey / Products
Created November 23, 2015 02:20
uCommerce API
/// <summary>
/// Set a custom property on a product
/// </summary>
/// <param name="product">Product</param>
/// <param name="propertyName">Property name</param>
/// <param name="propertyValue">Property value</param>
public static void SetCustomProperty(Product product, string propertyName, string propertyValue)
{
var property = product[propertyName];
property.Value = propertyValue;
@RyanABailey
RyanABailey / Categories
Created November 23, 2015 02:12
uCommerce API
/// <summary>
/// Gets all categories
/// </summary>
/// <returns>All categories</returns>
public static List<Category> GetCategories()
{
return Catalog.Categories.ToList();
}
/// <summary>
@RyanABailey
RyanABailey / Catalogue
Created November 23, 2015 02:04
uCommerce API
/// <summary>
/// Get a catalogue
/// </summary>
/// <param name="catalogueName">name of the catalogue</param>
/// <returns>Product catalogue</returns>
public static ProductCatalog GetCatalogue(string catalogueName)
{
List<ProductCatalog> catalogs = UCommerce.Api.CatalogLibrary.GetAllCatalogs();
return catalogs.FirstOrDefault(productCatalog => productCatalog.Name == catalogueName);
}
@RyanABailey
RyanABailey / Class
Created November 17, 2015 05:39
Sitecore Agent with Param
namespace MyProject.Jobs
{
public string param {get; set;}
public class DataSync
{
public void DoSync()
{
// code goes here
}
@RyanABailey
RyanABailey / Class
Created November 17, 2015 05:34
Sitecore Agent
namespace MyProject.Jobs
{
public class DataSync
{
public void DoSync()
{
// code goes here
}
}
}