- Spartacus Storefront 产品明细页面里的 Ad
- SAP Spartacus的基于outlet的页面扩展
- Spartacus Storefront 里的 currency
- SAP Commerce Accelerator和SAP Spa
- 关于 SAP Spartacus 的 Theme 颜色主题
- SAP Spartacus Storefront页面的page
- 关于 SAP 电商云首页加载时触发的 OCC API 请求
- StorefrontModule和B2CStorefrontMo
- 自定义SAP Spartacus Cart界面
- SAP Spartacus产品明细页面用Observable显示
这个 configurable 产品(搜索 home theater)明细页面里,没有看到 add to wish list 的超链接:
![](https://img.haomeiwen.com/i2085791/d45eb5d966d0e989.png)
有时我们会发现 Add to wish list 按钮为空的情况:
![](https://img.haomeiwen.com/i2085791/6adcba8162e4e1f0.png)
选择器 cx-add-to-wishlist
下是空的,没有任何元素,如上图所示。
从 ng-container
里的 ngIf
指令不难发现,add to wish list 的工作前提,是当前产品已经成功被获取,并且用户处于登录状态。
![](https://img.haomeiwen.com/i2085791/5a9ea0f4396d82f6.png)
在 Component AddToWishListComponent
里打印出当前 product 的详细信息:
![](https://img.haomeiwen.com/i2085791/e5e20cff0bc1580e.png)
![](https://img.haomeiwen.com/i2085791/ead9f0f237cf63f7.png)
在函数 isUserLoggedIn
里添加 console.log:
![](https://img.haomeiwen.com/i2085791/89c3745e2d96379c.png)
isUserLoggedIn(): Observable<boolean> {
return this.authStorageService.getToken().pipe(
tap((token) => { console.log('Jerry token: ', token)}),
map((userToken) => Boolean(userToken?.access_token)),
distinctUntilChanged()
);
}
运行时根本没有执行到 console.log 里来:
![](https://img.haomeiwen.com/i2085791/76f85f0f90fe01ec.png)
为什么运行时调用的是 asm service:
![](https://img.haomeiwen.com/i2085791/ffbb1c25080556ec.png)
![](https://img.haomeiwen.com/i2085791/9ab6ff12b9bfa32d.png)
从代码层面看,应该注入这个 AuthService 才对:
![](https://img.haomeiwen.com/i2085791/7d3593bfe0c4774a.png)
在 ASM auth service 的构造函数里打印 log:
![](https://img.haomeiwen.com/i2085791/dcfce92b86b28b38.png)
加上打印语句:
![](https://img.haomeiwen.com/i2085791/809e65a36c92b9e7.png)
![](https://img.haomeiwen.com/i2085791/067e28cd1f2c16f7.png)
在 add to wish list Component 页面添加调试信息:
<div> {{ product$ | async | json }}</div>
![](https://img.haomeiwen.com/i2085791/620f9ba7589f6ef0.png)
最后的效果:
![](https://img.haomeiwen.com/i2085791/0407baba229e465a.png)
同理:
![](https://img.haomeiwen.com/i2085791/916f290e52ecc3c4.png)
![](https://img.haomeiwen.com/i2085791/051f18391bf89858.png)
难道是这个 wishlist entries 为空吗?
![](https://img.haomeiwen.com/i2085791/b306a697c67e5c05.png)
果然:
![](https://img.haomeiwen.com/i2085791/6df1ed215110e26b.png)
变量 wishListEntries$
为空,导致 add to wish list 的超链接出不来。
wish list 是通过 cart 来实现的:
![](https://img.haomeiwen.com/i2085791/fb5999fa1280af0f.png)
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,登录后使用购物车代码。
网友评论