对 SAP Commerce 的后端调用不会从我的新 Spartacus 设置中触发
Backend Call to SAP Commerce is not triggering From My New Spartacus Setup
我是 Spartacus 的新手,我正在尝试通过在 myAccount Navigation 中创建一项功能来进行端到端集成。我能够呈现页面并将 CMS 组件映射到 Angular 组件并且它正确显示。
现在我想从该组件向 Commerce 调用一个新的 occ API。我已经编写了一个调用 API 的服务。但我没有看到 Web 浏览器控制台中触发了请求。是否需要为此做任何额外的设置
我正在使用 Spartacus 4.3 和 Hybris 2011
下面是组件
import { Component, OnInit } from '@angular/core';
import { Observable } from 'rxjs';
import { BuyAgain } from 'src/app/model/buyAgain-model';
import { BuyAgainService } from 'src/app/service/buyAgain.service';
@Component({
selector: 'app-buyAgain',
templateUrl: './buyAgain.component.html',
styleUrls: ['./buyAgain.component.scss']
})
export class BuyAgainComponent implements OnInit {
productList$: any;
constructor(protected buyAgainService: BuyAgainService) { }
ngOnInit(): void {
this.productList$ = this.getAllProductsForCustomer();
}
getAllProductsForCustomer(): Observable<BuyAgain> {
return this.buyAgainService.getCustomerOrderedProducts();
}
}
下面是BuyAgain服务
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { OccEndpointsService } from '@spartacus/core';
import { Observable } from 'rxjs';
import { BuyAgain } from '../model/buyAgain-model';
@Injectable({
providedIn: 'root'
})
export class BuyAgainService {
constructor(protected http: HttpClient,
protected occEndpoints: OccEndpointsService) { }
getCustomerOrderedProducts(): Observable<BuyAgain> {
console.log("In Service")
return this.http.get<BuyAgain>(
this.getBuyAgainEndpoint()
);
}
protected getBuyAgainEndpoint(): string {
return this.occEndpoints.buildUrl('buyAgainProducts');
}
}
import { HttpClientModule } from '@angular/common/http';
import { NgModule } from '@angular/core';
import { translationChunksConfig, translations } from "@spartacus/assets";
import { FeaturesConfig, I18nConfig, OccConfig, provideConfig, SiteContextConfig } from "@spartacus/core";
import { defaultCmsContentProviders,layoutConfig, mediaConfig } from "@spartacus/storefront";
import { BuyAgainModule } from '../component/buyAgain/buyAgain.module';
import { LayoutConfigurationModule } from '../confiuration/layout/layout.module';
import { ExtendServices } from '../service/extend-services.service';
@NgModule({
declarations: [],
imports: [
LayoutConfigurationModule,
ExtendServices,
BuyAgainModule,
HttpClientModule
],
providers: [provideConfig(mediaConfig), ...defaultCmsContentProviders, provideConfig(<OccConfig>{
backend: {
occ: {
baseUrl: 'https://localhost:9002/',
}
},
}), provideConfig(<SiteContextConfig>{
context: {
currency: ['GBP', 'USD'],
language: ['en','de'],
baseSite: ['apparel-uk-spa', 'electronics-spa'],
urlParameters: ['baseSite', 'language', 'currency']
},
}),
provideConfig(<I18nConfig>{
i18n: {
resources: translations,
chunks: translationChunksConfig,
fallbackLang: 'en'
},
}),
//***** How to Override i18n*****/
// provideConfig({
// i18n: {
// backend: {
// loadPath: 'assets/i18n-assets/{{lng}}/{{ns}}.json',
// },
// chunks: translationChunksConfig,
// },
// }),
provideConfig(<FeaturesConfig>{
features: {
level: '4.3'
}
})]
})
export class SpartacusConfigurationModule { }
你对 this.occEndpoints.buildUrl 的调用实际上调用了 return 什么东西吗?您需要在配置中为端点提供相应的字段。
另一个问题可能是您的 productList 的 observable 订阅可能没有启动?您是否在组件的 html 中使用异步管道之类的东西来订阅 productList$ 属性?
我是 Spartacus 的新手,我正在尝试通过在 myAccount Navigation 中创建一项功能来进行端到端集成。我能够呈现页面并将 CMS 组件映射到 Angular 组件并且它正确显示。
现在我想从该组件向 Commerce 调用一个新的 occ API。我已经编写了一个调用 API 的服务。但我没有看到 Web 浏览器控制台中触发了请求。是否需要为此做任何额外的设置
我正在使用 Spartacus 4.3 和 Hybris 2011
下面是组件
import { Component, OnInit } from '@angular/core';
import { Observable } from 'rxjs';
import { BuyAgain } from 'src/app/model/buyAgain-model';
import { BuyAgainService } from 'src/app/service/buyAgain.service';
@Component({
selector: 'app-buyAgain',
templateUrl: './buyAgain.component.html',
styleUrls: ['./buyAgain.component.scss']
})
export class BuyAgainComponent implements OnInit {
productList$: any;
constructor(protected buyAgainService: BuyAgainService) { }
ngOnInit(): void {
this.productList$ = this.getAllProductsForCustomer();
}
getAllProductsForCustomer(): Observable<BuyAgain> {
return this.buyAgainService.getCustomerOrderedProducts();
}
}
下面是BuyAgain服务
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { OccEndpointsService } from '@spartacus/core';
import { Observable } from 'rxjs';
import { BuyAgain } from '../model/buyAgain-model';
@Injectable({
providedIn: 'root'
})
export class BuyAgainService {
constructor(protected http: HttpClient,
protected occEndpoints: OccEndpointsService) { }
getCustomerOrderedProducts(): Observable<BuyAgain> {
console.log("In Service")
return this.http.get<BuyAgain>(
this.getBuyAgainEndpoint()
);
}
protected getBuyAgainEndpoint(): string {
return this.occEndpoints.buildUrl('buyAgainProducts');
}
}
import { HttpClientModule } from '@angular/common/http';
import { NgModule } from '@angular/core';
import { translationChunksConfig, translations } from "@spartacus/assets";
import { FeaturesConfig, I18nConfig, OccConfig, provideConfig, SiteContextConfig } from "@spartacus/core";
import { defaultCmsContentProviders,layoutConfig, mediaConfig } from "@spartacus/storefront";
import { BuyAgainModule } from '../component/buyAgain/buyAgain.module';
import { LayoutConfigurationModule } from '../confiuration/layout/layout.module';
import { ExtendServices } from '../service/extend-services.service';
@NgModule({
declarations: [],
imports: [
LayoutConfigurationModule,
ExtendServices,
BuyAgainModule,
HttpClientModule
],
providers: [provideConfig(mediaConfig), ...defaultCmsContentProviders, provideConfig(<OccConfig>{
backend: {
occ: {
baseUrl: 'https://localhost:9002/',
}
},
}), provideConfig(<SiteContextConfig>{
context: {
currency: ['GBP', 'USD'],
language: ['en','de'],
baseSite: ['apparel-uk-spa', 'electronics-spa'],
urlParameters: ['baseSite', 'language', 'currency']
},
}),
provideConfig(<I18nConfig>{
i18n: {
resources: translations,
chunks: translationChunksConfig,
fallbackLang: 'en'
},
}),
//***** How to Override i18n*****/
// provideConfig({
// i18n: {
// backend: {
// loadPath: 'assets/i18n-assets/{{lng}}/{{ns}}.json',
// },
// chunks: translationChunksConfig,
// },
// }),
provideConfig(<FeaturesConfig>{
features: {
level: '4.3'
}
})]
})
export class SpartacusConfigurationModule { }
你对 this.occEndpoints.buildUrl 的调用实际上调用了 return 什么东西吗?您需要在配置中为端点提供相应的字段。
另一个问题可能是您的 productList 的 observable 订阅可能没有启动?您是否在组件的 html 中使用异步管道之类的东西来订阅 productList$ 属性?