Tuesday, April 27, 2021

Wishlist in Sitecore Commerce

In e-commerce, wishlist or saved products for later purchase is one of the important functionality. I have created simple plugin in sitecore commerce which will save wishlist information of products such as product id, product title, product price in commerce on customer as component.

Wishlist Plugin is built on Sitecore Commerce 9.3 and is shared on github - https://github.com/savalagiakash/Sitecore-Commerce-Wishlist

This wishlist plugin has implementation of 3 apis

  1. Add Wishlist: To add wishlist to Wishlist Component
  2. Get Wishlist: Gets wishlist from Wishlist Component
  3. Remove Wishlist: Remove wishlist from Wishlist Component
Note: This plugin is not extension of OOTB sxa wishlist.
 
Below is the sample code of sitecore commerce proxy request to add, get and remove wishlist.

       
 var addWish = Proxy.DoCommand(ShopsContainer.AddWishlist(new SCPlugin.Commerce.Wishlist.Models.WishlistModel()
      {
        CustomerId = customerId,
        ProductId = productId,
        ProductPrice = productPrice,
        ProductTitle = productTitle
      }
      ));
 
 var getWished = Proxy.GetValue(ShopsContainer.GetWishlist(customerId, 10, 0));
 
 var removeWishList = Proxy.DoCommand(ShopsContainer.RemoveWishlist(customerId, productId));
       
 

Saturday, April 3, 2021

Customize Sitecore Commerce Index Such as CustomersScope, OrdersScope

Sitecore Commerce search are mainly built for the purpose of searching in Business tool(Bizfx) with lesser fields but it can be easily extended to use this search index in storefront search.

I will explain using order search by adding OrderTotal field in sitecore commerce order scope index as it is not present so that we sort order based on order total amount.

All index fields are defined in "PlugIn.Search.PolicySet-1.0.0.json" file in folder path "..\wwwroot\data\Environments". We have to add new field inside order scope node inside this file and bootstraps through postman.

Below is the screen shot "PlugIn.Search.PolicySet-1.0.0.json" with order total field. 




 



All fields mention in policy set files are populated inside "InitializeOrdersIndexingViewBlock" block with in "IFullIndexMinionPipeline" pipeline. 

To populate new field we have to replace InitializeOrdersIndexingViewBlock with custom block inside "configuresitecore.cs" and then populate new fields along with old one in custom block "InitializeOrdersCustomIndexingViewBlock".




Then defined order total field in "managed-schema" file of order scope inside solr. Restart the solr and trigger "Run FullIndex Minion - Orders" api from postman or wait till incremental index kicks off(order scope incremental index runs in every 5 min interval).


Then use Search api from shop container to test new index field.

       
 Proxy.DoCommand(container.Search(ConfigSettings.EnbdOrderScopeName, term, status,
 	sortBy, take, skip));
       
 


Friday, February 5, 2021

Simplest Way To Debugging Sitecore Commerce Engine

Different ways to debug sitecore commerce engine:


1. Processor:(This is the easiest way to debug Commerce)
Debug Sitecore Commerce Engine solution by attaching process in a same way as we do for Sitecore. 
Not w3wp.exe but by attaching Sitecore.Commerce.Engine.exe process.

processor



2. Hosting through Visual Studio
 Stop Commerce Authoring in IIS and Run Sitecore Commerce Solution from Visual Studio after making below changes in Sitecore Commerce Engine project:
    a. Set Profile to Engine
    b. Set App Url to Commerce Authoring url

Sitecore Commerce VS

























Then if everything is good, commerce engine will start running from Visual Studio.
authoring logs in cmd


Tuesday, February 2, 2021

Creating Custom Domain in Headless Sitecore Commerce

Domain For Commerce User and Customer

Usually we configure domain name for Sitecore Commerce SxA sites in Powershell tool's SxA Site Manager or in Site Grouping item of storefront site for commerce user. But if we are going we headless sitecore commerce setup and having SxA will not make sense. So Powershell tool's SxA Site Manager or in Site Grouping item will not be part of Sitecore Commerce setup.









To have our domain for commerce user and customer, we need to remove Sitecore Commerce Domain provider, adding custom domain class. Below is the example:

Domain config
Deleting out of box domain




Headless Custom Domain
Adding custom domain






Code for Domain
Code for overriding domain class with new domain name


In above code snippet we are setting domain name to "Headless" from default "Commerce User". 









Tuesday, November 10, 2020

Sitecore Commerce Service Proxy Error in Sitecore Commerce 9.3

I recently tried to generate Sitecore Commerce Service Proxy dll(Sitecore.Commerce.ServiceProxy.dll) in Visual Studio 2019 with OData Connected Service 0.4.0. After generating proxy using Odata Connected Service there are hundreds of error.

Cannot convert from 'System.Collections.Generic.IDictionary<string, object>' to 'System.Collections.Generic.Dictionary<string, object>'











Solution:
For Sitecore Commerce 9 to 9.3, we have to uses Visual Studio 2017 and OData Connected Service 0.3.0 instead of latest version. 

We can find OData Connected Service 0.3.0 sitecore commerce sdk.

Thursday, October 29, 2020

The login is from an untrusted domain and cannot be used with Windows authentication while installing Sitecore Commerce 9

 While installing Sitecore Commerce 9.2 had error on Bootstrap at "CommerceEngine-Initialize_BootStrapCommerceServices : BootStrapCommerceServices"

Sitecore Commerce Error in power shell

In Shops log file i could see the below error:

ERROR Message=SQL.GetDBVersion.Fail: Environment='GlobalEnvironment'|Message='Login failed for user 'abc\CSFndRuntimeUser'.'

at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)


Solution:
1. Get the IP address using cmd. Add IP address and system name to host file. Below is an example
    [11.022.11.4] [MachineName]

2. Add the account/username to “Access this computer from the network” local security policy             (secpol.msc) Then it got resolved.



Wishlist in Sitecore Commerce

In e-commerce, wishlist or saved products for later purchase is one of the important functionality. I have created simple plugin in sitecore...