此可配置产品(搜索家庭影院)详情页看不到addtowishlist的超链接:http://localhost:4000/electronics-spa/en/USD/product/CONF_CAM...有时候我们发现Addtowishlist按钮是空的:选择器cx-add-to-wishlist是空的,没有任何元素,如上图。从ng-container中的ngIf指令不难发现addtowishlist的工作前提是当前商品已经成功获取,用户处于登录状态。在组件AddToWishListComponent中打印出当前商品的详细信息:在函数isUserLoggedIn中添加console.log:isUserLoggedIn():Observable{returnthis.authStorageService.getToken().pipe(tap((token)=>{console.log('Jerrytoken:',token)}),map((userToken)=>Boolean(userToken?.access_token)),distinctUntilChanged());}运行时,console.log中根本没有执行:whyrun时调用了asm服务:从代码层面来看,应该是注入了这个AuthService:在ASMauth服务的构造函数中打印日志:添加打印语句:在添加到愿望清单组件页面上添加调试信息:{{product$|异步|json}}
最终效果:同样的原因:这个愿望清单条目是否为空?果然:变量wishListEntries$为空,导致addtowishlist超链接失败。愿望清单是通过购物车实现的:getWishList():Observable{),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-1bf...,potent。...所以,在登录后,Spartacus仍在尝试从guid而不是代码加载购物车。结果我们得到一个购物车未找到的错误默认情况下,在DEMOSpartacus网站上,登录是直接在同一网站上完成的,购物车行为是:登录前使用购物车guid,登录后使用购物车代码。