Posts

SAP Spartacus : CMS content page with dynamic parameter

CMS content page with dynamic parameter: refer below example: here we are passing savedCart id as a dynamic parameter. e.g. 'my-account/saved-cart/000101010'  Angular/Saprtacus Configuration   @ NgModule ({   imports : [     CommonModule ,     SpinnerModule ,     I18nModule ,     PaginationModule ,     ReactiveFormsModule ,     FormsModule ,     RouterModule ,     IconModule ,     FormErrorsModule ,     MyAccountTopMenuModule ,     RouterModule . forChild ([       {   //path with dynamic parameter         path : 'my-account/saved-cart/:cartid' ,                 data : { //label of cms page without parameter.             pageLabel : '/my-account/saved-cart' ,         }, // for displaying CMS slots,compone...

Spartacus : Clear/Reset State on Logout

This can be done using meta reducers. Below example is for clearing multicartstate after user logs out. 1. MultiCartStoreModule configuration to define metareducres (multiCartMetaReducers) @ NgModule ({   imports : [     CommonModule ,     StateModule ,     StoreModule . forFeature ( MULTI_CART_FEATURE , multiCartReducerToken , {       metaReducers : multiCartMetaReducers ,     }),     EffectsModule . forFeature ( effects ),   ],   providers : [ multiCartReducerProvider ], }) export class MultiCartStoreModule {}     2. clearMultiCartState  function to Define multiCartMetaReducers export function clearMultiCartState (   reducer : ActionReducer < any > ): ActionReducer < any > {   return function ( state , action ) {     if ( action . type === AuthActions . LOGOUT ) {       state = undefined ;     }     return reduc...

Typescript: array length check

 var codesArray ={ '123455','787998'};  var lengthofArray =  Object.keys(codesArray).length                                      OR var lengthofArray =  codesArray.length

Angular slice pipe with length check

  {{(string.length > 200) ? (string | slice : 0:200) + '...' : string}}

How to use Document/Window objetcts in SAP Spartacus?

  Here are the steps:   //import from spartacus   import  {    WindowRef , }  from   '@spartacus/core' ;   //constructor in your component/service   constructor (        protected   winRef :  WindowRef ,      ) {}     const   window  =  this . winRef . nativeWindow ; const document = this . winRef . document;   //use it like below  console.log( window . location . href);   //use it like below  const   form :  HTMLFormElement  =  this . winRef . document . querySelector ( 'form#loginForm' );