@gt6/sdk 1.0.33 → 1.0.35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -743,6 +743,65 @@ class ProductsAPI {
743
743
  }
744
744
  return product;
745
745
  }
746
+ /**
747
+ * 1.2. 根据产品ID全部产品详情(包括自定义和平台)
748
+ */
749
+ async getProduct_all(productId) {
750
+ const product = await this.client.request(`/products_all/${productId}.json`);
751
+ // 检查产品是否有销售区域和税费模板
752
+ if (product.regions_Parent && product.regions_Parent.length > 0 &&
753
+ product.taxTemplates && product.taxTemplates.length > 0) {
754
+ try {
755
+ // 获取税费信息
756
+ const taxInfo = await this.getTaxInfo01(product.platformId);
757
+ // 为每个税费模板添加规则
758
+ product.taxTemplates = product.taxTemplates.map(template => {
759
+ const matchingTemplate = taxInfo.templates.find(t => t.templateId === template.templateId);
760
+ if (matchingTemplate) {
761
+ // 过滤出产品可销售区域的规则
762
+ const productRegionIds = product.regions_Parent.map(r => r.regionId);
763
+ const applicableRules = matchingTemplate.rules.filter(rule => productRegionIds.includes(rule.regionId));
764
+ return {
765
+ ...template,
766
+ rules: applicableRules
767
+ };
768
+ }
769
+ return template;
770
+ });
771
+ }
772
+ catch (error) {
773
+ // 如果获取税费信息失败,不影响产品详情返回
774
+ console.warn('Failed to fetch tax info:', error);
775
+ }
776
+ }
777
+ // 检查产品是否有销售区域和运费模板
778
+ if (product.regions_Parent && product.regions_Parent.length > 0 &&
779
+ product.shippingTemplates && product.shippingTemplates.length > 0) {
780
+ try {
781
+ // 获取运费信息
782
+ const shippingInfo = await this.getShippingInfo01(product.platformId);
783
+ // 为每个运费模板添加规则
784
+ product.shippingTemplates = product.shippingTemplates.map(template => {
785
+ const matchingTemplate = shippingInfo.templates.find(t => t.templateId === template.templateId);
786
+ if (matchingTemplate) {
787
+ // 过滤出产品可销售区域的规则
788
+ const productRegionIds = product.regions.map(r => r.regionId);
789
+ const applicableRules = matchingTemplate.rules.filter(rule => productRegionIds.includes(rule.regionId));
790
+ return {
791
+ ...template,
792
+ rules: applicableRules
793
+ };
794
+ }
795
+ return template;
796
+ });
797
+ }
798
+ catch (error) {
799
+ // 如果获取运费信息失败,不影响产品详情返回
800
+ console.warn('Failed to fetch shipping info:', error);
801
+ }
802
+ }
803
+ return product;
804
+ }
746
805
  /**
747
806
  * 2. 获取产品分类列表
748
807
  */
@@ -1355,6 +1414,9 @@ class ProductsAPI {
1355
1414
  const config = this.client.getConfig();
1356
1415
  return this.client.request(`/tax/platform-${config.platformId}.json`);
1357
1416
  }
1417
+ async getTaxInfo01(platformId) {
1418
+ return this.client.request(`/tax/platform-${platformId}.json`);
1419
+ }
1358
1420
  /**
1359
1421
  * 9. 获取运费信息
1360
1422
  * 获取平台的所有运费模板和规则
@@ -1363,6 +1425,9 @@ class ProductsAPI {
1363
1425
  const config = this.client.getConfig();
1364
1426
  return this.client.request(`/shipping/platform-${config.platformId}.json`);
1365
1427
  }
1428
+ async getShippingInfo01(platformId) {
1429
+ return this.client.request(`/shipping/platform-${platformId}.json`);
1430
+ }
1366
1431
  /**
1367
1432
  * 10. 获取区域信息
1368
1433
  * 获取平台的所有区域信息,包括层级结构
@@ -2881,6 +2946,12 @@ class GT6SDK {
2881
2946
  async getProduct_p(productId) {
2882
2947
  return this.products.getProduct_p(productId);
2883
2948
  }
2949
+ /**
2950
+ * 8.1.1. 便捷方法:根据产品ID获取全部产品详情(包括自定义和平台)
2951
+ */
2952
+ async getProduct_all(productId) {
2953
+ return this.products.getProduct_all(productId);
2954
+ }
2884
2955
  /**
2885
2956
  * 8.2. 便捷方法:获取父平台产品分类列表
2886
2957
  */