In this post, we will look at how to remove the sample projects from the Sitecore Experience Commerce 9.0.2 (Sitecore.Commerce.Engine.SDK.2.2.72).
Unlike previous versions, the SDK for 9 update 2 has been cleaned up a little bit. I want to remove Plugin.Sample.AdventureWorks, Plugin.Sample.Customers.CsMigration, Plugin.Sample.Customers.Upgrade, Plugin.Sample.Habitat and Plugin.Sample.Upgrade. For now, I want to keep Plugin.Sample.Payments.Braintree.
I posted some useful links at the bottom of this blog post. First extract Sitecore.Commerce.Engine.SDK.2.2.72.zip and make a copy of the extracted source.
Rename your solution and build to make sure the solution builds. Add the following NuGet packages to the Commerce Engine project: Sitecore.Commerce.Plugin.Coupons Sitecore.Commerce.Plugin.Journaling Sitecore.Commerce.Plugin.SQL Sitecore.Commerce.Plugin.Tax
Next, go through all your configs and find where the sample projects were used and remove the config elements.
Your authoring configuration changes (PlugIn.Habitat.CommerceAuthoring-1.0.0.json):
//{
// "$type": "Plugin.Sample.Customers.CsMigration.ProfilesSqlPolicy, Plugin.Sample.Customers.CsMigration",
// "Server": ".",
// "Database": "SXAStorefrontSite_profiles",
// "TrustedConnection": true,
// "UserName": "",
// "Password": ""
//},
//{
// "$type": "Plugin.Sample.Customers.CsMigration.ProfilePropertiesMappingPolicy, Plugin.Sample.Customers.CsMigration",
// "UserProperties": {
// "GeneralInfo.language": "Language",
// "GeneralInfo.tel_number": "PhoneNumber"
// },
// "AddressProperties": {
// "ProfileSystem.user_id_changed_by": "ChangedBy"
// }
//},
Global.json file changes:
//{
// "$type": "Plugin.Sample.Customers.CsMigration.ProfilesSqlPolicy, Plugin.Sample.Customers.CsMigration",
// "Server": ".",
// "Database": "SXAStorefrontSite_profiles",
// "TrustedConnection": true,
// "UserName": "",
// "Password": ""
//},
//{
// "$type": "Plugin.Sample.Customers.CsMigration.ProfilePropertiesMappingPolicy, Plugin.Sample.Customers.CsMigration",
// "UserProperties": {
// "GeneralInfo.language": "Language",
// "GeneralInfo.tel_number": "PhoneNumber"
// },
// "AddressProperties": {
// "ProfileSystem.user_id_changed_by": "ChangedBy"
// }
//},
//{
// "$type": "Plugin.Sample.Upgrade.MigrationPolicy, Plugin.Sample.Upgrade",
// "DefaultEnvironmentName": "AdventureWorksAuthoring",
// "SqlPolicySetName": "SqlPolicySet",
// "ReviewOnly": false,
// "ListsToMigrate": {
// "*orders*": null,
// "carts": null,
// "giftcards": null,
// "order-*-salesactivity": null,
// "completedrmas": null,
// "journalentries*": null,
// "coupons": null,
// "entitlements": null,
// "managedlists": null,
// "pricebooks*": null,
// "pricecards": null,
// "privatecoupongroups": null,
// "promotionbooks*": null,
// "promotions": null,
// "promotions-*-coupons": null,
// "promotion-*-publiccoupons": null,
// "promotion-*-privatecoupongroups": null,
// "promotion-*-unallocatedcoupons": null,
// "salesactivities": null,
// "settledsalesactivities": null,
// "sellableitems": 0
// }
//},
//{
// "$type": "Plugin.Sample.Upgrade.MigrationSqlPolicy, Plugin.Sample.Upgrade",
// "ArtifactStoreId": "6BE385F1-93DC-4299-9DD4-934F6BA42EAA",
// "SourceStoreSqlPolicy": {
// "$type": "Sitecore.Commerce.Plugin.SQL.EntityStoreSqlPolicy, Sitecore.Commerce.Plugin.SQL",
// "PolicyId": "Global",
// "AllowAdmin": true,
// "Database": "SitecoreCommerce_Global",
// "EffectiveDate": "0001-01-01T00:00:00",
// "IsVisible": false,
// "Password": "",
// "Server": "",
// "TrustedConnection": true,
// "UserName": "",
// "View": "EntityStoreSqlPolicy"
// }
//},
Remove projects from the solution and remove the project references from the Commerce Engine solution.
Rebuild and deploy your commerce engine. Once that is done, Bootstrap and Initialize.
Here is a modified version of the deployment script based on the Habitat Home Commerce PowerShell script:
Param(
[string]$siteName = "sxa.storefront.com",
[string]$engineHostName = "localhost",
[string]$identityServerHost = "localhost:5050",
[switch]$Initialize,
[switch]$Bootstrap,
[switch]$SkipPublish,
[string]$webRoot = "C:inetpubwwwroot",
[string]$engineSuffix = "Sc9",
[string[]] $engines = @("Authoring", "Minions", "Ops", "Shops"),
[string]$BizFxPathName = "SitecoreBizFx",
[string]$IdentityServerPathName = "SitecoreIdentityServer",
[string]$CommerceOpsPort = "5000",
[string]$adminUser = "admin",
[string]$adminPassword = "b",
[string]$certificateName = "sxa.storefront.com",
[string]$solutionFolder = (get-item $PWD).parent.fullname,
[string]$publishFolder = (Join-Path $solutionFolder "publishTemp"),
[string]$engineSolutionPath = (Join-Path $solutionFolder "YOUR SOLUTION NAME INCLUSE .sln")
)
Function Start-CommerceEngineCompile ( [string] $basePublishPath = $(Join-Path $publishFolder "engine") ) {
if (Test-Path $publishFolder) {
Remove-Item $publishFolder -Recurse -Force
}
Write-Host ("Compiling and Publishing Engine to {0}" -f $basePublishPath) -ForegroundColor Green
dotnet publish $engineSolutionPath -o $basePublishPath
}
Function Start-CommerceEnginePepare ( [string] $basePublishPath = $(Join-Path $publishFolder "engine") ) {
$certPrefix = "CN="
$fullCertificateName = $certPrefix + $certificateName
$thumbprint = Get-ChildItem -path cert:LocalMachinemy | Where-Object {$_.Subject -like $fullCertificateName} | Select-Object Thumbprint
Write-Host $thumbprint
$pathToGlobalJson = $(Join-Path -Path $basePublishPath -ChildPath "wwwrootbootstrapGlobal.json")
$global = Get-Content $pathToGlobalJson -Raw | ConvertFrom-Json
#Write-Host $global $siteName $adminUser $adminPassword
$global.Policies.'$values'[5].Host = $siteName
$global.Policies.'$values'[5].UserName = $adminUser
$global.Policies.'$values'[5].Password = $adminPassword
$global | ConvertTo-Json -Depth 10 -Compress | set-Content $pathToGlobalJson
$pathToJson = $(Join-Path -Path $basePublishPath -ChildPath "wwwrootconfig.json")
$config = Get-Content $pathToJson -Raw | ConvertFrom-Json
$certificateNode = $config.Certificates.Certificates[0]
$certificateNode.Thumbprint = $thumbprint.Thumbprint
$config | ConvertTo-Json -Depth 10 -Compress | set-content $pathToJson
# Modify PlugIn.Content.PolicySet
$pathToContentPolicySet = $(Join-Path -Path $basePublishPath -ChildPath "wwwrootdataenvironmentsPlugIn.Content.PolicySet-1.0.0.json")
$contentPolicySet = Get-Content $pathToContentPolicySet -Raw | ConvertFrom-Json
$contentPolicySet.Policies.'$values'[0].Host = $siteName
$contentPolicySet.Policies.'$values'[0].username = $adminUser
$contentPolicySet.Policies.'$values'[0].password = $adminPassword
$contentPolicySet | ConvertTo-Json -Depth 10 -Compress | Set-Content $pathToContentPolicySet
foreach ($engine in $engines) {
Write-Host ("Customizing configuration values for {0}" -f $engine) -ForegroundColor Green
$engineFullName = ("Commerce{0}" -f $engine)
$environmentName = ("Habitat{0}" -f $engine)
$enginePath = Join-Path $publishFolder $engineFullName
Copy-Item $basePublishPath $enginePath -Recurse -Force
$pathToJson = $(Join-Path -Path $enginePath -ChildPath "wwwrootconfig.json")
$config = Get-Content $pathToJson -Raw | ConvertFrom-Json
$appSettings = $config.AppSettings
$appSettings.EnvironmentName = $environmentName
$config | ConvertTo-Json -Depth 10 -Compress | set-content $pathToJson
}
Write-Host "Modifying Identity Server configuration" -ForegroundColor Green
# Modify IdentityServer AppSettings based on new engine hostname
$idServerJson = $([System.IO.Path]::Combine($webRoot, $IdentityServerPathName, "wwwrootappSettings.json"))
$idServerSettings = Get-Content $idServerJson -Raw | ConvertFrom-Json
$client = $idServerSettings.AppSettings.Clients | Where-Object {$_.ClientId -eq "CommerceBusinessTools"}
$client.RedirectUris = @(("https://{0}:4200" -f $engineHostName), ("https://{0}:4200/?" -f $engineHostName))
$client.PostLogoutRedirectUris = @(("https://{0}:4200" -f $engineHostName), ("https://{0}:4200/?" -f $engineHostName))
$client.AllowedCorsOrigins = @(("https://{0}:4200/" -f $engineHostName), ("https://{0}:4200" -f $engineHostName))
$idServerSettings | ConvertTo-Json -Depth 10 -Compress | set-content $idServerJson
Write-Host "Modifying BizFx (Business Tools) configuration" -ForegroundColor Green
#Modify BizFx to match new hostname
$bizFxJson = $([System.IO.Path]::Combine($webRoot, $BizFxPathName, "assetsconfig.json"))
$bizFxSettings = Get-Content $bizFxJson -Raw | ConvertFrom-Json
$bizFxSettings.BizFxUri = ("https://{0}:4200" -f $engineHostName)
$bizFxSettings.IdentityServerUri = ("https://{0}" -f $identityServerHost)
$bizFxSettings.EngineUri = ("https://{0}:5000" -f $engineHostName)
$bizFxSettings | ConvertTo-Json -Depth 10 -Compress | set-content $bizFxJson
}
Function Publish-CommerceEngine {
Write-Host ("Deploying Commerce Engine") -ForegroundColor Green
IISRESET /STOP
foreach ($engine in $engines) {
$engineFullName = ("Commerce{0}" -f $engine)
$enginePath = Join-Path $publishFolder $engineFullName
if ($engineSuffix.length -gt 0) {
$engineWebRoot = Join-Path $webRoot $($engineFullName + "_" + $engineSuffix)
}
else {
$engineWebRoot = [System.IO.Path]::Combine($webRoot, $engineFullName)
}
Write-Host ("Copying to {0}" -f $engineWebRoot) -ForegroundColor Green
$engineWebRootBackup = ("{0}_backup" -f $engineWebRoot)
if (Test-Path $engineWebRootBackup -PathType Container) {
Remove-Item $engineWebRootBackup -Recurse -Force
}
Rename-Item $engineWebRoot -NewName $engineWebRootBackup
Get-ChildItem $engineWebRoot -Recurse | ForEach-Object {Remove-Item $_.FullName -Recurse}
Copy-Item -Path "$enginePath" -Destination $engineWebRoot -Container -Recurse -Force
}
IISRESET /START
Start-Sleep 10
}
Function Get-IdServerToken {
$UrlIdentityServerGetToken = ("https://{0}/connect/token" -f $identityServerHost)
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Content-Type", 'application/x-www-form-urlencoded')
$headers.Add("Accept", 'application/json')
$body = @{
password = "$adminPassword"
grant_type = 'password'
username = ("sitecore{0}" -f $adminUser)
client_id = 'postman-api'
scope = 'openid EngineAPI postman_api'
}
Write-Host "Getting Identity Token From Sitecore.IdentityServer" -ForegroundColor Green
$response = Invoke-RestMethod $UrlIdentityServerGetToken -Method Post -Body $body -Headers $headers
$sitecoreIdToken = "Bearer {0}" -f $response.access_token
$global:sitecoreIdToken = $sitecoreIdToken
Write-Host $global:sitecoreIdToken
}
Function BootStrapCommerceServices {
$UrlCommerceShopsServicesBootstrap = ("https://{0}:{1}/commerceops/Bootstrap()" -f $engineHostName, $CommerceOpsPort)
Write-Host "BootStrapping Commerce Services: $($urlCommerceShopsServicesBootstrap)" -ForegroundColor Green
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", $global:sitecoreIdToken)
Invoke-RestMethod $UrlCommerceShopsServicesBootstrap -TimeoutSec 1200 -Method PUT -Headers $headers
Write-Host "Commerce Services BootStrapping completed" -ForegroundColor Green
}
if ($DeployOnly) {
}
if (!($SkipPublish)) {
Start-CommerceEngineCompile
Start-CommerceEnginePepare
Publish-CommerceEngine
}
if ($Bootstrap -or $Initialize) {
Get-IdServerToken
}
if ($Bootstrap) {
BootStrapCommerceServices
}
If you have any questions or concerns, please get in touch with me. (@akshaysura13 on Twitter or on Slack).
References:
Decoupling the Sample Plugins from the Sitecore Commerce 9 SDK Setting up a new Sitecore Experience Commerce Environment
Share on social media