Spartacus Storefront 产品明细页面里的 Add to Wish 动态隐藏问题

举报
Jerry Wang 发表于 2023/04/01 15:31:52 2023/04/01
【摘要】 这个 configurable 产品(搜索 home theater)明细页面里,没有看到 add to wish list 的超链接:http://localhost:4000/electronics-spa/en/USD/product/CONF_CAMERA_SL-PROF-BLACK/digital-camera-professional-black有时我们会发现 Add to wi...

这个 configurable 产品(搜索 home theater)明细页面里,没有看到 add to wish list 的超链接:

http://localhost:4000/electronics-spa/en/USD/product/CONF_CAMERA_SL-PROF-BLACK/digital-camera-professional-black

有时我们会发现 Add to wish list 按钮为空的情况:

选择器 cx-add-to-wishlist 下是空的,没有任何元素,如上图所示。

ng-container 里的 ngIf 指令不难发现,add to wish list 的工作前提,是当前产品已经成功被获取,并且用户处于登录状态。

在 Component AddToWishListComponent 里打印出当前 product 的详细信息:

在函数 isUserLoggedIn 里添加 console.log:

  isUserLoggedIn(): Observable<boolean> {
    return this.authStorageService.getToken().pipe(
      tap((token) => { console.log('Jerry token: ', token)}),
      map((userToken) => Boolean(userToken?.access_token)),
      distinctUntilChanged()
    );
  }

运行时根本没有执行到 console.log 里来:

为什么运行时调用的是 asm service:

从代码层面看,应该注入这个 AuthService 才对:

在 ASM auth service 的构造函数里打印 log:

加上打印语句:

在 add to wish list Component 页面添加调试信息:

<div> {{ product$ | async | json }}</div>

最后的效果:

同理:

难道是这个 wishlist entries 为空吗?

果然:

变量 wishListEntries$ 为空,导致 add to wish list 的超链接出不来。

wish list 是通过 cart 来实现的:

getWishList(): Observable<Cart> {
    return combineLatest([
      this.getWishListId(),
      this.userService.get(),
      this.userIdService.getUserId(),
    ]).pipe(
      distinctUntilChanged(),
      tap(([wishListId, user, userId]) => {
        if (
          !Boolean(wishListId) &&
          userId !== OCC_USER_ID_ANONYMOUS &&
          Boolean(user) &&
          Boolean(user.customerId)
        ) {
          this.loadWishList(userId, user.customerId);
        }
      }),
      filter(([wishListId]) => Boolean(wishListId)),
      switchMap(([wishListId]) => this.multiCartService.getCart(wishListId))
    );
  }

Spartacus 登录后,用户直接回到店面,第一次调用是这样的:
https://localhost:9002/occ/v2/jerry/users/current/carts/0-1bff26781e2c?fields=DEFAULT,potent

因此,登录后,Spartacus 仍在尝试从 guid 而不是代码加载购物车。
因此,我们会收到 未找到购物车 错误

默认情况下,在 DEMO Spartacus 网站上,登录是直接在同一网站上完成的,

购物车行为是:

  • 登录前使用购物车 guid,登录后使用购物车代码。
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。