Tumgik
#episervercommerce
vu3lo · 6 years
Text
Episerver Asset Panel Search with Find Custom Fields
Had been struggling to figure out how to include our custom field extension methods on our product content types in the asset panel (right hand panel) search for editors.
We just had a simple extension method on the product content type that we used a custom CatalogContentClientConventions to include it in the Find index. 
But to ensure these fields are used in the Asset Panel for editors searching, the solution is to extend the EnterpriseCatalogSearchProvider class. The outcome looks something like this:
[SearchProvider] public class CustomEnterpriseCatalogSearchProvider : EnterpriseCatalogSearchProvider, ISortable {    public CustomEnterpriseCatalogSearchProvider(LocalizationService localizationService, IEnterpriseSettings enterpriseSettings, IContentTypeRepository<ContentType> contentTypeRepository)        : base(localizationService, enterpriseSettings, contentTypeRepository)    {    }    public CustomEnterpriseCatalogSearchProvider(LocalizationService localizationService, IEnterpriseSettings enterpriseSettings, IContentTypeRepository<ContentType> contentTypeRepository, UIDescriptorRegistry uiDescriptorRegistry)        : base(localizationService, enterpriseSettings, contentTypeRepository, uiDescriptorRegistry)    {    }    public CustomEnterpriseCatalogSearchProvider(LocalizationService localizationService, ISiteDefinitionResolver siteDefinitionResolver, IContentTypeRepository contentTypeRepository, UIDescriptorRegistry uiDescriptorRegistry)        : base(localizationService, siteDefinitionResolver, contentTypeRepository, uiDescriptorRegistry)    {    }    protected override IQueriedSearch<IContentData, QueryStringQuery> AddContentSpecificFields(IQueriedSearch<IContentData, QueryStringQuery> query)    {        return base.AddContentSpecificFields(query)            .InField(x => ((CustomProduct)x).GetSpecialValue());    }    /// <summary>    /// Change to be first search provider (otherwise other instances might be selected first)    /// </summary>    public new int SortOrder => 1; }
In the above example the overridden AddContentSpecificFields method will add the “GetSpecialValue()” to the asset panel catalog search query.
This should also work for CMS content search too. But instead you would extend EnterprisePageSearchProvider for pages, EnterpriseBlockSearchProvider for blocks, or EnterpriseMediaSearchProvider for media.
0 notes
vu3lo · 6 years
Text
Disable Episerver Commerce Find indexing on price or inventory updates
Episerver Commerce with Find integration will, by default, reindex content when a price or inventory update occurs.
This is coordinated by the CatalogContentEventListener class. Inside this class implementation there is are methods “IsReindexingContentOnPriceUpdates” and “IsReindexingContentOnInventoryUpdates” which return their respective boolean as to whether it should reindex.
The problem I had was to figure out how to change these settings. Because I am yet to find a simple appSetting or other property to set, here is how I have overridden their settings:
[ServiceConfiguration(ServiceType = typeof(CatalogContentEventListener))] public class CustomCatalogContentEventListener : CatalogContentEventListener {    public CustomCatalogContentEventListener(ReferenceConverter referenceConverter, IContentRepository contentRepository, IClient client, CatalogEventIndexer indexer, CatalogContentClientConventions catalogContentClientConventions)        : base(referenceConverter, contentRepository, client, indexer, catalogContentClientConventions)    { }    public CustomCatalogContentEventListener(ReferenceConverter referenceConverter, IContentRepository contentRepository, IClient client, CatalogEventIndexer indexer, CatalogContentClientConventions catalogContentClientConventions, PriceIndexing priceIndexing)        : base(referenceConverter, contentRepository, client, indexer, catalogContentClientConventions, priceIndexing)    { }    public override bool IsReindexingContentOnPriceUpdates()    {        return false;    }    public override bool IsReindexingContentOnInventoryUpdates()    {        return false;    } }
Hope this helps someone (or myself when I re google this in the future).
0 notes
vu3lo · 9 years
Text
EPiServer Commerce CartCheckout workflow with IsIgnoreProcessPayment parameter
EPiServer Commerce has substantial processes which rely on workflows. In many scenarios, like on a simple consumer website, you may get away without modifying or configuring these workflows beyond their defaults.
But on my current project I needed to simply disable payment processing in the CartCheckout workflow. And there is an API method in Mediachase.Commerce.Orders.OrderGroup that facilitates this:
// Summary: //     Runs the specified workflow. // // Parameters: //   name: //     The name. // //   throwException: //     if set to true the exception will be thrown and should be handled by the //     caller. // //   param: //     The additional input parameters. public virtual WorkflowResults RunWorkflow(string name, bool throwException, Dictionary<string, object> param);
For my situation setting IsIgnoreProcessPayment to true when running the CartCheckout workflow, this is my simplified code that was required:
var workflowParams = new Dictionary<string, object> { { "IsIgnoreProcessPayment", true } } var results = cartHelper.Cart.RunWorkflow(OrderGroupWorkflowManager.CartCheckOutWorkflowName, true, workflowParams);
I hunted for examples of how to set IsIgnoreProcessPayment so thought it deserved a blog post.
0 notes
vu3lo · 9 years
Text
Implementing IPriceService with default IPriceService as its dependency
In EPiServer Commerce prices are loaded via the IPriceService and IPriceDetailService. I needed to customise the IPriceService logic but just to tweak the price filtering and still intend to call the default IPriceService internally to reuse the base functionality.
This is where confusion ensues, how does one configure the dependency resolver (StructureMap) to return my custom price service implementation which itself has a dependency on the same IPriceService interface? Turns out StructureMap has a method called EnrichWith to achieve this.
So I have my implementation called “CustomPriceService” and the default EPiServer implmentation is “PriceServiceDatabase“. My CustomPriceService constructor looks like this:
public CustomPriceService(IPriceService defaultPriceService) { this._defaultPriceService = defaultPriceService; }
Now I have the local field _defaultPriceService that I can call for default functionality throughout my custom implementation and it still retains the injected abstraction for unit testing purposes.
To configure StructureMap all that is needed is:
container.For<IPriceService>().Use<PriceServiceDatabase>().EnrichWith((context, systemPriceService) => new CustomPriceService(systemPriceService));
When an IPriceService dependency is resolved StructureMap will get the default EPiServer Commerce “PriceServiceDatabase” and then create my “CustomPriceService” passing the PriceServiceDatabase into the constructor.
If your constructor needs other dependencies you can use the “IContext” that EnrichWith provides, for example:
container.For<IPriceService>().Use<PriceServiceDatabase>().EnrichWith((context, systemPriceService) => new CustomPriceService(systemPriceService, context.GetInstance<ICurrentMarket>()));
Hopefully this will help anyone trying to figure out how to get StructureMap to configure a dependency for a given type to itself have a dependency on the same type.
0 notes