检索 Spartacus 中客户的当前 B2B 单位

发布于 2025-01-12 04:19:24 字数 781 浏览 0 评论 0原文

我想在标题中显示当前的 B2B 单位名称。 为当前客户检索 B2B 单位的正确方法是什么?

到目前为止我发现,/current 有一个有效负载?在初始页面加载时加载的端点,它包含 orgUnit:

Payload for /current?

当我尝试通过 CurrentUnitService 检索单位时,我得到了 null 值。

单元.组件.ts:

orgUnit$: Observable<B2BUnit> = this.currentUnitService.item$;

  constructor(
    protected currentUnitService: CurrentUnitService,
  ) {}

单元.组件.html:

  <ng-container *ngIf="orgUnit$ | async as unit">
    <p class="d-inline-block">{{unit.name}}&nbsp;</p>
    <a href="#" class="d-inline-block">
      ({{unit.uid}})
    </a>
  </ng-container>

I want to show current B2B Unit name in the header.
What would be the correct way to retrieve B2B Unit for current customer?

What I found so far, there is a payload for /current? endpoint which is loaded on initial page load and it contains the orgUnit:

Payload for /current?

When I was trying to retrieve the Unit via CurrentUnitService, I got null value.

unit.component.ts:

orgUnit$: Observable<B2BUnit> = this.currentUnitService.item$;

  constructor(
    protected currentUnitService: CurrentUnitService,
  ) {}

unit.component.html:

  <ng-container *ngIf="orgUnit$ | async as unit">
    <p class="d-inline-block">{{unit.name}} </p>
    <a href="#" class="d-inline-block">
      ({{unit.uid}})
    </a>
  </ng-container>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

多情癖 2025-01-19 04:19:24

我能够使用 UserAccountFacade 并通过使用 orgUnit 扩展用户模型来检索当前客户的 B2BUnit,如下所示:

unit.component.ts

export class UnitComponent implements OnInit {
  user$: Observable<CustomUser | undefined>;

  constructor(
    protected auth: AuthService,
    protected userAccount: UserAccountFacade
  ) {}

  ngOnInit(): void {
    this.user$ = this.auth.isUserLoggedIn().pipe(
      switchMap(isUserLoggedIn => {
        if (isUserLoggedIn) {
          return this.userAccount.get();
        } else {
          return of(undefined);
        }
      })
    );
  }
}

interface CustomUser extends User {
  orgUnit?: B2BUnit
}

unit.component.html

<ng-container *ngIf="user$ | async as user">
    <p class="d-inline-block">{{user.orgUnit?.name}} </p>
    <a href="#" class="d-inline-block">
      ({{user.orgUnit?.uid}})
    </a>
    <p>{{ user.name }}</p>
  </ng-container>

结果:

在此处输入图像描述

I was able to retrieve the B2BUnit for current customer using UserAccountFacade and by extending User model with orgUnit as follows:

unit.component.ts

export class UnitComponent implements OnInit {
  user$: Observable<CustomUser | undefined>;

  constructor(
    protected auth: AuthService,
    protected userAccount: UserAccountFacade
  ) {}

  ngOnInit(): void {
    this.user$ = this.auth.isUserLoggedIn().pipe(
      switchMap(isUserLoggedIn => {
        if (isUserLoggedIn) {
          return this.userAccount.get();
        } else {
          return of(undefined);
        }
      })
    );
  }
}

interface CustomUser extends User {
  orgUnit?: B2BUnit
}

unit.component.html

<ng-container *ngIf="user$ | async as user">
    <p class="d-inline-block">{{user.orgUnit?.name}} </p>
    <a href="#" class="d-inline-block">
      ({{user.orgUnit?.uid}})
    </a>
    <p>{{ user.name }}</p>
  </ng-container>

Result:

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文