其他分享
首页 > 其他分享> > SAP Spartacus 3.0的一些变化

SAP Spartacus 3.0的一些变化

作者:互联网

Technical Changes in Spartacus 3.0

Breaking Changes

Translations (i18n) changed

Default Router options changed

The Angular router can be initialized with so-called ExtraOptions in the forRoot method fo the RouterModule. See https://angular.io/api/router/ExtraOptions for more information on those options.

The default ExtraOptions have changed with 3.0. Before 3.0, Spartacus set the anchorScrolling and scrollPositionRestoration options. In Spartacus 3.0, the scrollPositionRestoration has dropped, and the relativeLinkResolution and initialNavigation has been added. See the below table for the actual values and reasoning

Option< 3.0> 3.0
anchorScrolling'enabled''enabled'
scrollPositionRestoration'enabled'(removed)
relativeLinkResolutionn/a'corrected'
initialNavigationn/a'enabled'

The enabled scrollPositionRestoration was causing a bad experience in most cases, as it would scroll the page to the top on each route change. This is unexpected in a single page experience.

The corrected relativeLinkResolution is used to opt-in to a fix that has been added in angular. This will become default from angular 11 onwards.

The enabled initialNavigation provides better experience with server side rendering, starting initial navigation before the root component is created and blocking bootstrap until the initial navigation is complete. More details available in Angular documentation.

The RouterModule.forRoot() method can actually only be called once in an angular application. This makes the default options rather opinionated, which is why the default configurations are carefully selected in Spartacus. The options that have been added/removed can be provided in your custom application with the Angular ROUTER_CONFIGURATION injection token. For example:

providers: [
  {
    provide: ROUTER_CONFIGURATION,
    useValue: {
      scrollPositionRestoration: 'enabled',
    },
  },
];

There’s no automation (schematics) planned for this change.

Page Layout

With version 2.1 we’ve started to add the page layout based style class to the root element of the application (cx-storefront). This is done in addition to the style class added by the PageLayoutComponent. The style class on the PageLayoutComponent was considered to be too limited, as it would not affect selectors outside the page template component.

The implementation of the page layout based style class has moved from the PageLayoutComponent to the PageTemplateDirective. This results in a cleaner PageLayoutComponent with a constructor that no longer requires the lower level renderer2 service and ElementRef. The constructor reduces to the following signature:

constructor(protected pageLayoutService: PageLayoutService) {}

We’ve also made the PageLayoutService a protected argument, so that it is extensible.

There’s no automation (schematics) planned to migrate constructors automatically.

Static CMS structure config changes

Occ prefix

Default value for backend.occ.prefix configuration option was changed from /rest/v2/ to /occ/v2/.

Storefront config

ContentPageMetaResolver

ContentPageMetaResolver has a new required constructor dependency RoutingPageMetaResolver.

LoginFormComponent

It’s no longer the responsibility of the LoginFormComponent to redirect to the anticipated page (it no longer calls the method AuthRedirectService.redirect).
Now the redirecting logic is placed inside the core AuthService to support more OAuth flows.

LoginFormComponent no longer has properties loginAsGuest, sub and the method ngOnDestroy.

HttpClientModule is not imported in feature libraries

In most cases HttpClientModule should only be imported in the root app module, as importing it in lazy-loaded modules can
cause unexpected side effects regarding the visibility of HTTP_INTERCEPTORS, etc. To fix this, we removed all HttpClientModule imports from all our
feature libraries and moved them to recipes.

There’s no automation (schematics) planned for this change.

SSR Engine Optimizations

NgExpressEngineDecorator now adds SSR Optimization logic on top of the universal engine by default.

NgExpressEngineDecorator was moved from @spartacus/core to @spartacus/setup/ssr. Also NgExpressEngineDecorator.get() method now accepts an additional second parameter to fine-tune SSR optimizations. Passing null there will turn off optimizations by removing optimization layer completely (bring back default 2.x behavior).

Store finder functionality has been moved to a new library

Store finder logic from @spartacus/core and store finder components from @spartacus/storefront were moved to respective entrypoints in @spartacus/misc/storefinder.
Store finder translations (storeFinderTranslations) and translation chunks (storeFinderTranslationChunksConfig) were moved to @spartacus/misc/storefinder/assets.
Store finder functionality is now also lazy-loadable out of the box.

StockNotificationComponent

StockNotificationComponent has a new required dependency UserIdService, but no more depends on AuthService.

CmsComponentsService

Method CmsComponentsService.getChildRoutes changed return type from Route[] to CmsComponentChildRoutesConfig

Config cmsComponents

The property childRoutes of config cmsComponents changed type from Route[] to Route[] | CmsComponentChildRoutesConfig.

PageMetaService lazy-loading related changes

ConverterService lazy-loading related changes

Payload for constructor of PlaceOrder class from Checkout actions requires an additional property

PlaceOrderComponent

Property renamed in SearchConfig interface

Old NameNew Name
sortCodesort

Changes in CheckoutStepsState interface

Changes in CheckoutState interface

OutletRefDirective unregisters template on destroy

The directive’s template in unregistered from outlet on directive destroy.

Before v3.0, when an instance of OutletRefDirective was destroyed (removed from DOM), its template remained registered for the Outlet, which could cause the same template being rendered multiple times in case of re-creation of the same [cxOutletRef] later on. Now it’s fixed.

CartItemComponent lost members

CartItemComponent lost members:

CartItemListComponent

There can be more than one cart entry with the same product code. So now they are referenced by the property entryNumber instead of the product code in CartItemListComponent.

AddToCartComponent

AddToCartComponent lost members:

Auth module refactor

Store

Models

Guards

Services

Config

KymaModule

KymaModule were removed with all it’s code. We expose the same functionality through configuration of auth.

To fetch OpenId token along with access token in Resource Owner Password Flow you have to use following configuration.

authentication: {
  client_id: 'client4kyma',
  client_secret: 'secret',
  OAuthLibConfig: {
    responseType: 'id_token',
    scope: 'openid',
    customTokenParameters: ['token_type', 'id_token'],
  }
}

Then you can access OpenId token with OAuthLibWrapperService.getIdToken method. For more options related to OpenId token look into angular-oauth2-oidc library documentation.

ASM module refactor

AsmAuthService

Service was renamed to CsAgentAuthService. AsmAuthService is now responsible for making AuthService aware of ASM and adjusts it for CS agent support.

CDC library

OrderDetailHeadlineComponent

Order detail headline component has been removed.

OrderDetailShippingComponent

The following functions have been removed from the component:

OrderConfirmationOverviewComponent

The following functions have been removed from the component:

The type of BaseSiteService is changed

Before it was:

Now it is:

The return type of the function getAll() is changed from:

to:

The return type of the function setActive(baseSite: string) is changed from:

to:

ConfigInitializerService’s constructor has an additional parameter added

Before it was:

  constructor(
    @Inject(Config) protected config: any,
    @Optional()
    @Inject(CONFIG_INITIALIZER_FORROOT_GUARD)
    protected initializerGuard
  ) {}

Now it is:

  constructor(
    @Inject(Config) protected config: any,
    @Optional()
    @Inject(CONFIG_INITIALIZER_FORROOT_GUARD)
    protected initializerGuard,
    @Inject(RootConfig) protected rootConfig: any

CmsComponentsService constructor has an additional parameter added

Before it was:

  constructor(
    protected config: CmsConfig,
    @Inject(PLATFORM_ID) protected platformId: Object
  ) {}

Now it is:

  constructor(
    protected config: CmsConfig,
    @Inject(PLATFORM_ID) protected platformId: Object,
    protected featureModules?: FeatureModulesService
  ) {}

configurationFactory was removed

Configuration merging logic now uses separate tokens for default configuration and user configuration.

CheckoutProgressMobileBottomComponent

CheckoutProgressMobileTopComponent

CheckoutProgressComponent

DeliveryModeComponent

OrderDetailShippingComponent

PaymentMethodComponent

ShippingAddressComponent

CheckoutAuthGuard

CheckoutConfigService

Method placeOrder in CheckoutAdapter, OccCheckoutAdapter and CheckoutConnector

The method placeOrder of CheckoutAdapter, OccCheckoutAdapter and CheckoutConnector now has 3rd, a new required argument termsChecked: boolean.

BreakpointService

ProtectedRoutesGuard

The return type of the method ProtectedRoutesGuard.canActivate changed from Observable<boolean> to Observable<boolean | UrlTree>

ItemCounterComponent

ViewComponent

UpdateEmailComponent

StorefrontComponent

StarRatingComponent

CartNotEmptyGuard

NotCheckoutAuthGuard

ProductVariantGuard

LogoutGuard

CurrentProductService

MultiCartStatePersistenceService

ProductReferenceService

LanguageService

CurrencyService

OccCmsComponentAdapter

The OCC CMS component API in SAP Commerce Cloud before version 1905 was using a POST method. This has changed in 1905 (using GET going forward). Spartacus has supported both version from version 1.0 by using a legacy flag to distinguish this backend API behavior. With release 3.0 we maintain the support for the pre 1905 CMS component API, but the implementation has moved to a separate adapter (LegacyOccCmsComponentAdapter). With that change, we’re also dropping the legacy flag in the OCC configuration.

UserState

The interface for the ngrx state UserState now has new required properties: replenishmentOrders, replenishmentOrder and costCenters.

CloseAccountModalComponent

The property userToken$ of CloseAccountModalComponent has been replaced with isLoggedIn$ of type Observable<boolean>.

BaseSiteState

The interface BaseSiteState has now a new required property entities: BaseSiteEntities.

UserService

UserOrderService

Checkout selectors

ProductListComponentService

ProductCarouselService

The following functions have been removed from the component:

CheckoutService

AnonymousConsentTemplatesAdapter

AnonymousConsentTemplatesConnector

SplitViewComponent

Automated Migrations for Version 3

标签:now,SAP,Spartacus,no,uses,3.0,removed,was,longer
来源: https://blog.csdn.net/i042416/article/details/110817308