GTM snippet

Monday, August 30, 2021

Setup Installation Guide for SAP CX 2011 with Spartacus

 Step 1: Download the latest SAP Commerce Cloud suite (in our case its 2011 version).

SAP CX suite

Step 2: Extract it in a folder.

Extracted

Step 3: Download spartacussampledata zip file.

Step 4: Move the file custom.properties from spartacussampledata/resources/installer/customconfig to hybris-commerce-suite-2011/installer/customconfig, set build.parallel= false.



Step 5: Create a custom folder inside bin (hybris/bin), copy spartacussampledata inside custom.

Spartacus Sample Data

Step 6: Go to installer/recipes, duplicate cx folder, rename duplicate folder as cx-for-spa.


Receipe

Step 7: Inside cx-for-spa open build.gradle uncomment extName 'spartacussampledata' save and close.



Step 8: Open cmd inside installer

Step 9: Install the recipe run cmd “install.bat –r cx-for-spa”

Step 10: Initialize the system run cmd  “install.bat -r cx-for-spa initialize” (this will take a while)


Init

Step 11: Strat the server run cmd “install.bat -r cx-for-spa start”


Sap Server Start

 

Step 12: Verify if things are working as expected or not hit the following urls

·       Display the Admin Console: https://localhost:9002


HAC

·       Display Backoffice: https://localhost:9002/backoffice


Backoffice

·       Display the Accelerator Electronics storefront: https://apparel-uk.local:9002/yacceleratorstorefront/


Storefront

 

Step 13: Import the below impex  for Auth client to accept OCC

INSERT_UPDATE OAuthClientDetails;clientId[unique=true]    ;resourceIds       ;scope        ;authorizedGrantTypes                                            ;authorities             ;clientSecret    ;registeredRedirectUri

                                ;client-side              ;hybris            ;basic        ;implicit,client_credentials                                  ;ROLE_CLIENT             ;secret          ;http://localhost:9001/authorizationserver/oauth2_implicit_callback;

                                ;mobile_android           ;hybris            ;basic        ;authorization_code,refresh_token,password,client_credentials    ;ROLE_CLIENT             ;secret          ;http://localhost:9001/authorizationserver/oauth2_callback;

 

######################### NOW WE NEED TO START SPARTACUS ###################

Front End Development Requirement:

·       Angular CLI: V 12.0.5 or later

·       Node js: V 12.x

·       Yarn: 1.15 or later

Assuming you have all requirements installed to check angular version run command “ng  - -version”

Angular CLI

Step 1: Create a new angular project, go to the location where you want to create open cmd and run this cmd “ng new <storename> --style=scss” (in our case storename is “electronicsspa”).



Step 2: Check whether you are able to see the sample store or not, go to the folder created above (in our case its electronicsspa) to do that run cmd “cd <foldername>”



Step 3: Start the server, run cmd “yarn start”






Step 4: After server is started hit “localhost:4200”, you see a sample angular site running

Step 5: To set Spartacus you must be in same folder i.e electronicsspa, run cmd “ng add @spartacus/schematics - -baseSite electronics-spa”, after running this command it will ask for several moduels just press enter or you can select your desired modules and press enter.

 

After above steps start you’re both servers

·       SAP Commerce suite (run command inside platform hybrisserver.bat)



·       Angular (ng serve inside your folder in our case it is electronicsspa)



Hit localhost:4200 and you will see something like this


Spartacus Storefront

 

 

 

 

 

 

 

 







Sunday, June 13, 2021

Search Restriction in Hybris

Search Restriction is a crucial concept in SAP Commerce Cloud(Hybris). It is used in most of the projects.

What is Search Restriction? Search Restriction is a set of rules which is applied on Flexible Search Query in order to limit the search results or to filter search results based on specific condition.

SearchRestriction in Hybris

It is a transparent process and in most of the cases business logic layer remains unchanged. It is applied on  the item type level and by default restrictions do not apply on admin users. We can create restrictions for users who use HAC to fetch the data or for the Storefront users.

We create restrictions via impex. All the search restrictions are store in SearchRestriction item type and extension is core.

How Search Restriction work? When ever a flexible search query fires it appends where clause at the end of the query with the specified condition mentioned.

Where can we use Search Restriction? There are couple of scenarios where it can be useful for ex:

  • To show only those orders which were placed in last 6 months on order history page.
  • To show some special category only for the registered users.
  • To show some special discounted products to the logged in users.
  • To allow customers to provide review if they are not blocked.
  • Integration Objects to be visible only to admin group

There could be n number of scenarios where we can use Search Restriction.

How To create Search Restriction? There are two ways to create a search restriction

  • From Backoffice
  • Via Impex

To create from Backoffice Go to Backoffice > Types > SearchRestriction click on + icon

No alt text provided for this image
  • Restricted type: Item type to which restriction has to be applied (for ex Customer : select * from {Customer})
  • Identifier: Code of Search Restriction
  • Time created: Created time
  • Owner can be left blank
  • Filter: Restriction to be applied ({uid}!='testacocunt@gmail.com') now whenever any one will fire query to Customer table this restriction will be applied and will not show this user in results.
  • Apply on: Upon which group this restrction should be applicable( for ex: user is of employeegroup) now when ever an user from employeegroup will fire any flexible query on Customer table he/she will not be able to see this 'testacocunt@gmail.com' customer in results.
  • Active: true to enable restriction | false to disable restriction

To create via impex

INSERT_UPDATE SearchRestriction;code[unique=true];principal(uid)[unique=true];query;restrictedType(code)[unique=true];active;generate

;backendOrderVisibility;customersupportagentgroup;{versionID} IS NULL;Order;true;true

  • (Identifier)Code: backendOrderVisibility
  • (Apply on) principal(uid)[unique=true]: customersupportagentgroup
  • (Filter) query: {versionID} IS NULL
  • (Restricted type) restrictedType: Order
  • active: true
  • generate: true

Not so tough but a crucial role in SAP Commerce Cloud. Mostly you will see search restriction in every project.