Sitecore tips and tricks and community news !

Post Top Ad

Post Top Ad

Showing posts with label custom. Show all posts
Showing posts with label custom. Show all posts
5:18 PM

Indexing xCommerce products with site languages versions



 

The default approach for Sitecore and xCommerce for indexing commerce items is to get items languages in as many version as you have defined in xCommerce. 

 

But not always this behavior is acceptable. In our scenario particular site languages versions were kept in Home item of every page. Basing on that, we are able to make it as a point of truth and during indexing match only proper languages versions to each site.

 

The result will be reduction of unnecessary entries in the index. What will have an influence on time and performance.

 

To achieve this we need to  implement new Crawler which will do new logic. It should inherit form default xCommerce crawler. Take a look below:





Afterwards we need to register this in the index configuration



Thank you :)
8:26 PM

Sitecore xCommerce custom Product Index (9.0.3)

 
 Hi,

Indexing is wide and complex process.  Usually we get default solution to use default indexes, to save our time and effort. Probably in most common scenarios it is sufficient solution. But what when we have a lot of data and we would like to separate our data from default content data or we would like to separate invoking particular object indexing, scale this process etc.

 

 

The best option is to create our own custom index.

This approach is also doable to obtain in xCommerce. What we have to do is to write our own custom patches to switch indexing configuration to ours.


1. Custom Product Index declaration with commerce templates indexing


2. Product Index strategies and crawlers definition for xCommerce

 

3. We have to get rid of the products inside default master_index. It's done to don't keep duplicated data what also will have an influence on index rebuilding process. Especially in time consuming.


4. We have to indicate for xCommerce new index. To make it we need to prepare new Index Resolver with custom values.



Thank you!

1:55 PM

Sitecore + SXA + xCommerce - Azure ASE custom ARMs deployment

Hello fellows,

Today I would like to talk about custom deployment of Sitecore 9.0.2 + SXA  + xCommerce  on Azure PaaS - but here we have to add something more ASE support. I got a case from client to make it in isolated way and this approach was the most acceptable by them.

Because they have used Sitecore 9.0.2 we have to work with this version, which needs our custom work to achieve Azure ASE on Sitecore ARMs files.



But somebody will ask, bro, what is this Azure ASE?

From MS site (more Microsoft Docs - Azure ASE):

The Azure App Service Environment is an Azure App Service feature that provides a fully isolated and dedicated environment for securely running App Service apps at high scale. This capability can host your:
  • Windows web apps
  • Linux web apps
  • Docker containers
  • Mobile apps
  • Functions
App Service environments (ASEs) are appropriate for application workloads that require:
  • Very high scale.
  • Isolation and secure network access.
  • High memory utilization.
Customers can create multiple ASEs within a single Azure region or across multiple Azure regions. This flexibility makes ASEs ideal for horizontally scaling stateless application tiers in support of high RPS workloads.
ASEs are isolated to running only a single customer's applications and are always deployed into a virtual network. Customers have fine-grained control over inbound and outbound application network traffic. Applications can establish high-speed secure connections over VPNs to on-premises corporate resources.
First of all I have to remind where we can find Sitecore ARM templates:



I was digging this topic and I what I got to know more is which ARMs attribute we have to use. The main one are:
  • server farm
  • hosting environment profile
Where we can find them? -> In infrastructure files of Sitecore

I will make here some out off topic, but I recommend to use ARM templates extension for VSCode, check this out:


Take a look on Sitecore ARM infrastructure.json file


But you have to be aware that there is more than 1 place to switch :)

What you can do more is for instance change default Azure App Service Plan usage. Of course not on a production stage, but if you are building only kind of PoC, you don't need all PaaS App Service Plans (which on ASE costs much). You can e.g. create only one for PoC purpose like I said.

What I would like to highlight is that this parameters values we can also pass from the top, what means parameters.json file. In that way we will keep all values in one place.


The same situation is with xCommerce ARMs template, which have similar structure to Sitecore ARMs templates


Because we knowe already, from where we can get default ARMs for Sitecore I will put here only infrastructure files for Sitecore 9.0.2 and xCommerce 9.0.3 to help understand how to use this paramas.
I would like to notice that my custom templatea are only for PoC purposes and I have changed number of App Service Plans. In the other hand, it will be also a good example for you.


Cheers!
8:27 PM

xCommerce - extend by composition 3/3

So here we are with the next and the last one part of our journey through xCommerce customization path. Now we will take a look on the most proper way to make xCommerce fit to us - composition.



In this way we have to understand how xCommerce solution is build. It has (like Sitecore) own hierarchy flow to process the request. To handle it it uses a few steps:

  • Plugins
  • Controllers and Commands
  • Pipelines
  • Blocks
Let's take a look a bit on them.

 Plugins
  • Independent features
  • Only accepted way to extend Commerce Engine
  • Don’t remove default ones just like that ;)
Controllers & Commands


  • Controllers works in the same way as usuall
  • Commands are invoking inside the controllers
  • Commands invokes Pipelines
 Pipelines


  • You can create your own pipelines and hook into pipelines defined in other plugin
  • Similar to standard Sitecore pipeline mechanism
  • In SXC9 they are in the code not XML
  • Aggregate SXC Blocks
  • Comparing to XML approach No „ShowConfig.ASPX” but JSON preview
  • In Commerce, there is no config patching facilities. Instead we can create our custom plugin and can patch our Blocks through the code.
     
 Blocks



  • Equivalent for Sitecore processors
  • Chaining calls
  • Remember about returning element
Take a look on this examples of adding blocks in a few several ways:



Example

Let's assumme that we have sort of new functionality like subaccounts. To make it work properly we have to add a new controller, command, pipeline and some blocks. To achieve that we have below actions:

  • Controller
  • Command
  • Pipeline
  • Blocks
We also should remember about mentioned earlier registration piplines and blocks in the configuration classes. You will have it also below in the examples of code.
Enjoy!
12:54 PM

WFFM Custom Error Message


Well known picture, isn't it ? :) Creating our custom message is really helpful in the future: during using our application by end-users or even for other developers who will maintain project.

What in case when we use WFFM, is it possible ? Of course it is, each WFFM action has possibility to display custom error message by dedicated field which looks like:


It works perfectly. We can use many custom actions with own error messages for each other. Generally it solves problem with custom error messages.

But what when someone has a lot of custom error messages or many combination of them? We assume that this person would like to avoid creating many action just to see correct error message. Is there any solution?

Well.. sure it is :) !

Firstly we have to create our custom Form Verification action. It's important to make Form Verification action, not the Save Action.


Secondly we create our custom class which inherits from WffmCheckAction and do the magic inside.
The most important part of this magic for us is to catch exception that can occur. We can for instance put there message we would like to see and re-throw it again. Even in bubble way from previous layers.

At the end this exception message will be displayed above our form.
You don't have to fill error message fields in the action. The code you have written is everything you need.

Cheers !