0

错误错误:未捕获(承诺):TypeError:无法读取未定义的属性“过滤器”

尝试访问 Spartacus 3.0 Telco(TUA) 中具有变体的产品基本页面时,我从以下findVariant方法中收到脚本错误ProductVariantGuard

ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'filter' of undefined

错误发生在Spartacus StorefrontfindVariant的文件路径“ storefrontlib\src\cms-components\product\product-variants\guards\product-variant.guard.ts ”处的方法上

findVariant(variants: VariantOption[]): VariantOption {
  const results: VariantOption[] = variants.filter((variant) => {
    return variant.stock && variant.stock.stockLevel ? variant : false;
  });
  return !results.length && variants.length ? variants[0] : results[0];
}

Spartacus 期待 'variantOptions' 属性,但从Product API没有收到类似的东西。

return this.productService.get(productCode, "variants" /* VARIANTS */).pipe(filter(Boolean), switchMap((product) => {
            if (!product.purchasable) {
                const variant = this.findVariant(product.variantOptions);

我收到了它的回复

GET /occ/v2/telcospa/products/iPhone_x?fields=purchasable,baseOptions(DEFAULT),baseProduct,variantOptions(DEFAULT),variantType&lang=en&curr=USD
{
  "baseOptions" : [ ],
  "isComponentEditable" : false,
  "isMaxLimitReachedForBundle" : false,
  "isRemovableEntry" : false,
  "preselected" : false,
  "purchasable" : false,
  "variantType" : "TmaPoVariant"
}
重现异常的屏幕截图

1 - 点击产品

2 - 异常行和方法

3 - 导致异常的调试方法

3.1 - 导致异常的调试方法

4 - 请求

5 - 响应

包.json
{
  "name": "tua-spartacus",
  "version": "0.0.1-51",
  "scripts": {
    "ng": "ng",
    "start": "ng serve --disable-host-check",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular-devkit/core": "^10.1.0",
    "@angular-devkit/schematics": "^10.1.0",
    "@angular/animations": "~10.1.0",
    "@angular/common": "~10.1.0",
    "@angular/compiler": "~10.1.0",
    "@angular/core": "~10.1.0",
    "@angular/forms": "~10.1.0",
    "@angular/localize": "^10.1.6",
    "@angular/platform-browser": "~10.1.0",
    "@angular/platform-browser-dynamic": "~10.1.0",
    "@angular/platform-server": "~10.1.0",
    "@angular/router": "~10.1.0",
    "@angular/service-worker": "~10.1.0",
    "@ng-bootstrap/ng-bootstrap": "^7.0.0",
    "@ng-select/ng-select": "^5.0.9",
    "@ngrx/effects": "~10.0.0",
    "@ngrx/router-store": "~10.0.0",
    "@ngrx/store": "~10.0.0",
    "@schematics/angular": "^10.1.0",
    "@spartacus/assets": "~3.0.0",
    "@spartacus/core": "~3.0.0",
    "@spartacus/storefront": "~3.0.0",
    "@spartacus/styles": "~3.0.0",
    "@spartacus/tua-spa": "~3.0.0",
    "angular-oauth2-oidc": "^10.0.1",
    "bootstrap": "^4.2.1",
    "chart.js": "^2.9.3",
    "express": "^4.15.2",
    "i18next": "^19.3.4",
    "i18next-xhr-backend": "^3.2.2",
    "jquery": "^3.5.1",
    "material-design-icons": "^3.0.1",
    "ng2-charts": "^2.3.2",
    "ngx-infinite-scroll": "^8.0.0",
    "ngx-mask": "^11.1.5",
    "ngx-spinner": "^10.0.1",
    "parse5": "^6.0.1",
    "popper.js": "^1.16.1",
    "rxjs": "^6.6.0",
    "tslib": "^2.0.0",
    "zone.js": "~0.10.2"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.1002.3",
    "@angular/cli": "~10.2.3",
    "@angular/compiler-cli": "~10.1.0",
    "@angular/language-service": "~10.1.0",
    "@spartacus/schematics": "~3.0.0",
    "@types/jasmine": "~3.5.0",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "^12.11.1",
    "codelyzer": "^6.0.2",
    "jasmine-core": "^3.7.1",
    "jasmine-spec-reporter": "~5.0.0",
    "karma": "~5.0.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage-istanbul-reporter": "~3.0.2",
    "karma-jasmine": "~4.0.0",
    "karma-jasmine-html-reporter": "^1.5.0",
    "protractor": "~7.0.0",
    "ts-node": "~8.3.0",
    "tslint": "~6.1.0",
    "typescript": "~4.0.7"
  }
}

谢谢!

4

0 回答 0