@snabcentr/client-core 3.21.0 → 3.21.1

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.
@@ -1748,6 +1748,7 @@ class ScProduct extends ScCatalogItem {
1748
1748
  else {
1749
1749
  this.image = data.images?.find((img) => img.isDefault)?.image ?? data.properties?.image;
1750
1750
  this.supplierSku = data.supplierSku;
1751
+ this.brand = data.brand;
1751
1752
  this.cost = data.cost;
1752
1753
  this.costRub = data.costRub;
1753
1754
  this.costDate = data.costDate;
@@ -7991,7 +7992,6 @@ class SchemaOrgFactory {
7991
7992
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
7992
7993
  const image = this.mediaImageTransformerPipe.transform(product?.getImagePreview?.() ?? product.image, true);
7993
7994
  const description = product.properties?.description;
7994
- const priceValidUntil = this.normalizePriceValidUntil(product.discount?.expiredAt);
7995
7995
  return {
7996
7996
  '@context': 'https://schema.org',
7997
7997
  '@type': 'Product',
@@ -7999,21 +7999,16 @@ class SchemaOrgFactory {
7999
7999
  name: product.name,
8000
8000
  ...(image && { image }),
8001
8001
  ...(description && { description: this.stripHtml(description) }),
8002
- mpn: product.code,
8003
- url: productUrl,
8004
- offers: {
8005
- '@type': 'Offer',
8006
- priceCurrency: 'RUB',
8007
- ...(priceValidUntil && { priceValidUntil }),
8008
- price: product.costRub,
8009
- availability: this.getAvailability(product),
8010
- itemCondition: 'https://schema.org/NewCondition',
8011
- seller: {
8012
- '@type': 'Organization',
8013
- name: this.companyInfo.name,
8002
+ sku: product.code,
8003
+ ...(product.supplierSku && { mpn: product.supplierSku }),
8004
+ ...(product.brand && {
8005
+ brand: {
8006
+ '@type': 'Brand',
8007
+ name: product.brand,
8014
8008
  },
8015
- url: productUrl,
8016
- },
8009
+ }),
8010
+ url: productUrl,
8011
+ offers: this.createOffer(product, productUrl),
8017
8012
  };
8018
8013
  }
8019
8014
  /**
@@ -8097,6 +8092,7 @@ class SchemaOrgFactory {
8097
8092
  // eslint-disable-next-line sonarjs/function-return-type
8098
8093
  generateForOrganization() {
8099
8094
  const postalAddress = this.createPostalAddress(this.companyInfo.address);
8095
+ const merchantReturnPolicy = this.createMerchantReturnPolicy();
8100
8096
  return {
8101
8097
  '@context': 'https://schema.org',
8102
8098
  '@type': 'OnlineStore',
@@ -8126,6 +8122,13 @@ class SchemaOrgFactory {
8126
8122
  address: warehouseAddress,
8127
8123
  })),
8128
8124
  }),
8125
+ ...(merchantReturnPolicy && {
8126
+ // Тип возмещения Google принимает только в политике организации, в предложениях его нет.
8127
+ hasMerchantReturnPolicy: {
8128
+ ...merchantReturnPolicy,
8129
+ refundType: 'https://schema.org/FullRefund',
8130
+ },
8131
+ }),
8129
8132
  };
8130
8133
  }
8131
8134
  /**
@@ -8261,6 +8264,22 @@ class SchemaOrgFactory {
8261
8264
  }
8262
8265
  return contactPoints;
8263
8266
  }
8267
+ /**
8268
+ * Формирует MerchantReturnPolicy по условиям возврата из данных о компании.
8269
+ */
8270
+ createMerchantReturnPolicy() {
8271
+ if (!this.companyInfo.returnPolicy) {
8272
+ return undefined;
8273
+ }
8274
+ return {
8275
+ '@type': 'MerchantReturnPolicy',
8276
+ applicableCountry: 'RU',
8277
+ returnPolicyCategory: 'https://schema.org/MerchantReturnFiniteReturnWindow',
8278
+ merchantReturnDays: this.companyInfo.returnPolicy.returnDays,
8279
+ returnMethod: 'https://schema.org/ReturnInStore',
8280
+ returnFees: 'https://schema.org/FreeReturn',
8281
+ };
8282
+ }
8264
8283
  /**
8265
8284
  * Удаляет HTML-разметку из текста.
8266
8285
  *
@@ -8354,6 +8373,30 @@ class SchemaOrgFactory {
8354
8373
  const path = categoryPath.replace(':id', id);
8355
8374
  return `${this.urls.siteUrl}${path}`;
8356
8375
  }
8376
+ /**
8377
+ * Создаёт Offer о продаже товара.
8378
+ *
8379
+ * @param product Данные о продукте.
8380
+ * @param productUrl Полный URL страницы товара.
8381
+ */
8382
+ createOffer(product, productUrl) {
8383
+ const priceValidUntil = this.normalizePriceValidUntil(product.discount?.expiredAt);
8384
+ const merchantReturnPolicy = this.createMerchantReturnPolicy();
8385
+ return {
8386
+ '@type': 'Offer',
8387
+ priceCurrency: 'RUB',
8388
+ ...(priceValidUntil && { priceValidUntil }),
8389
+ price: product.costRub,
8390
+ availability: this.getAvailability(product),
8391
+ itemCondition: 'https://schema.org/NewCondition',
8392
+ seller: {
8393
+ '@type': 'Organization',
8394
+ name: this.companyInfo.name,
8395
+ },
8396
+ url: productUrl,
8397
+ ...(merchantReturnPolicy && { hasMerchantReturnPolicy: merchantReturnPolicy }),
8398
+ };
8399
+ }
8357
8400
  /**
8358
8401
  * Создаёт элемент списка ItemList с кратким Product для страницы категории.
8359
8402
  *
@@ -8366,7 +8409,6 @@ class SchemaOrgFactory {
8366
8409
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
8367
8410
  const image = this.mediaImageTransformerPipe.transform(product?.getImagePreview?.() ?? product.image, true);
8368
8411
  const description = product.seo?.description ?? product.properties?.description;
8369
- const priceValidUntil = this.normalizePriceValidUntil(product.discount?.expiredAt);
8370
8412
  return {
8371
8413
  '@type': 'ListItem',
8372
8414
  position,
@@ -8376,19 +8418,7 @@ class SchemaOrgFactory {
8376
8418
  url: productUrl,
8377
8419
  ...(image && { image }),
8378
8420
  ...(description && { description: this.stripHtml(description) }),
8379
- offers: {
8380
- '@type': 'Offer',
8381
- priceCurrency: 'RUB',
8382
- ...(priceValidUntil && { priceValidUntil }),
8383
- price: product.costRub,
8384
- availability: this.getAvailability(product),
8385
- itemCondition: 'https://schema.org/NewCondition',
8386
- seller: {
8387
- '@type': 'Organization',
8388
- name: this.companyInfo.name,
8389
- },
8390
- url: productUrl,
8391
- },
8421
+ offers: this.createOffer(product, productUrl),
8392
8422
  },
8393
8423
  };
8394
8424
  }