@shopware/helpers 1.4.0 → 1.5.0
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.
- package/README.md +2 -4
- package/dist/index.d.mts +19 -1
- package/dist/index.d.ts +19 -1
- package/dist/index.mjs +20 -17
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -36,10 +36,8 @@ export default defineConfig({
|
|
|
36
36
|
|
|
37
37
|
Full changelog for stable version is available [here](https://github.com/shopware/frontends/blob/main/packages/helpers/CHANGELOG.md)
|
|
38
38
|
|
|
39
|
-
### Latest changes: 1.
|
|
39
|
+
### Latest changes: 1.5.0
|
|
40
40
|
|
|
41
41
|
### Minor Changes
|
|
42
42
|
|
|
43
|
-
- [#
|
|
44
|
-
|
|
45
|
-
- [#1602](https://github.com/shopware/frontends/pull/1602) [`bb7d1cb`](https://github.com/shopware/frontends/commit/bb7d1cbc4204ff1d48f77416f94f550bc235e5ed) Thanks [@patzick](https://github.com/patzick)! - Switch from `@shopware-pwa/cms-base` to `@shopware/cms-base-layer` package.
|
|
43
|
+
- [#1910](https://github.com/shopware/frontends/pull/1910) [`c8fa438`](https://github.com/shopware/frontends/commit/c8fa438b38de6dbc43a2895f2d1906907447c384) Thanks [@mdanilowicz](https://github.com/mdanilowicz)! - Add helper for getting payment and shipping method icon
|
package/dist/index.d.mts
CHANGED
|
@@ -584,6 +584,24 @@ declare function getShippingMethodDeliveryTime<T extends {
|
|
|
584
584
|
};
|
|
585
585
|
}>(shippingMethod: T): string | undefined;
|
|
586
586
|
|
|
587
|
+
/**
|
|
588
|
+
* Get shipping method icon
|
|
589
|
+
*/
|
|
590
|
+
declare function getShippingMethodIcon<T extends {
|
|
591
|
+
media?: {
|
|
592
|
+
url: string;
|
|
593
|
+
};
|
|
594
|
+
}>(shippingMethod: T): string;
|
|
595
|
+
|
|
596
|
+
/**
|
|
597
|
+
* Get payment method icon
|
|
598
|
+
*/
|
|
599
|
+
declare function getPaymentMethodIcon<T extends {
|
|
600
|
+
media?: {
|
|
601
|
+
url: string;
|
|
602
|
+
};
|
|
603
|
+
}>(paymentMethod: T): string;
|
|
604
|
+
|
|
587
605
|
/**
|
|
588
606
|
* Get translated language name
|
|
589
607
|
*
|
|
@@ -614,4 +632,4 @@ declare function canUseQuoteActions<T extends {
|
|
|
614
632
|
};
|
|
615
633
|
}>(quote: T): boolean;
|
|
616
634
|
|
|
617
|
-
export { type HelpersCssClasses, type LayoutConfiguration, type TierPrice, type UiMediaGalleryItem, type UiMediaGalleryItemUrl, type UiProductOption, type UiProductProperty, type UiProductReview, buildUrlPrefix, canUseQuoteActions, downloadFile, getBackgroundImageUrl, getBiggestThumbnailUrl, getCategoryBreadcrumbs, getCategoryImageUrl, getCategoryRoute, getCategoryUrl, getCmsBreadcrumbs, getCmsEntityObject, getCmsLayoutConfiguration, getCmsTranslate, getFormattedPrice, getLanguageName, getListingFilters, getMainImageUrl, getMedia, getProductCalculatedListingPrice, getProductFreeShipping, getProductFromPrice, getProductName, getProductRatingAverage, getProductReviews, getProductRoute, getProductTierPrices, getProductUrl, getShippingMethodDeliveryTime, getSmallestThumbnailUrl, getSrcSetForMedia, getTranslatedProperty, helpersCssClasses, isCategory, isLandingPage, isMaintenanceMode, isProduct, relativeUrlSlash, urlIsAbsolute };
|
|
635
|
+
export { type HelpersCssClasses, type LayoutConfiguration, type TierPrice, type UiMediaGalleryItem, type UiMediaGalleryItemUrl, type UiProductOption, type UiProductProperty, type UiProductReview, buildUrlPrefix, canUseQuoteActions, downloadFile, getBackgroundImageUrl, getBiggestThumbnailUrl, getCategoryBreadcrumbs, getCategoryImageUrl, getCategoryRoute, getCategoryUrl, getCmsBreadcrumbs, getCmsEntityObject, getCmsLayoutConfiguration, getCmsTranslate, getFormattedPrice, getLanguageName, getListingFilters, getMainImageUrl, getMedia, getPaymentMethodIcon, getProductCalculatedListingPrice, getProductFreeShipping, getProductFromPrice, getProductName, getProductRatingAverage, getProductReviews, getProductRoute, getProductTierPrices, getProductUrl, getShippingMethodDeliveryTime, getShippingMethodIcon, getSmallestThumbnailUrl, getSrcSetForMedia, getTranslatedProperty, helpersCssClasses, isCategory, isLandingPage, isMaintenanceMode, isProduct, relativeUrlSlash, urlIsAbsolute };
|
package/dist/index.d.ts
CHANGED
|
@@ -584,6 +584,24 @@ declare function getShippingMethodDeliveryTime<T extends {
|
|
|
584
584
|
};
|
|
585
585
|
}>(shippingMethod: T): string | undefined;
|
|
586
586
|
|
|
587
|
+
/**
|
|
588
|
+
* Get shipping method icon
|
|
589
|
+
*/
|
|
590
|
+
declare function getShippingMethodIcon<T extends {
|
|
591
|
+
media?: {
|
|
592
|
+
url: string;
|
|
593
|
+
};
|
|
594
|
+
}>(shippingMethod: T): string;
|
|
595
|
+
|
|
596
|
+
/**
|
|
597
|
+
* Get payment method icon
|
|
598
|
+
*/
|
|
599
|
+
declare function getPaymentMethodIcon<T extends {
|
|
600
|
+
media?: {
|
|
601
|
+
url: string;
|
|
602
|
+
};
|
|
603
|
+
}>(paymentMethod: T): string;
|
|
604
|
+
|
|
587
605
|
/**
|
|
588
606
|
* Get translated language name
|
|
589
607
|
*
|
|
@@ -614,4 +632,4 @@ declare function canUseQuoteActions<T extends {
|
|
|
614
632
|
};
|
|
615
633
|
}>(quote: T): boolean;
|
|
616
634
|
|
|
617
|
-
export { type HelpersCssClasses, type LayoutConfiguration, type TierPrice, type UiMediaGalleryItem, type UiMediaGalleryItemUrl, type UiProductOption, type UiProductProperty, type UiProductReview, buildUrlPrefix, canUseQuoteActions, downloadFile, getBackgroundImageUrl, getBiggestThumbnailUrl, getCategoryBreadcrumbs, getCategoryImageUrl, getCategoryRoute, getCategoryUrl, getCmsBreadcrumbs, getCmsEntityObject, getCmsLayoutConfiguration, getCmsTranslate, getFormattedPrice, getLanguageName, getListingFilters, getMainImageUrl, getMedia, getProductCalculatedListingPrice, getProductFreeShipping, getProductFromPrice, getProductName, getProductRatingAverage, getProductReviews, getProductRoute, getProductTierPrices, getProductUrl, getShippingMethodDeliveryTime, getSmallestThumbnailUrl, getSrcSetForMedia, getTranslatedProperty, helpersCssClasses, isCategory, isLandingPage, isMaintenanceMode, isProduct, relativeUrlSlash, urlIsAbsolute };
|
|
635
|
+
export { type HelpersCssClasses, type LayoutConfiguration, type TierPrice, type UiMediaGalleryItem, type UiMediaGalleryItemUrl, type UiProductOption, type UiProductProperty, type UiProductReview, buildUrlPrefix, canUseQuoteActions, downloadFile, getBackgroundImageUrl, getBiggestThumbnailUrl, getCategoryBreadcrumbs, getCategoryImageUrl, getCategoryRoute, getCategoryUrl, getCmsBreadcrumbs, getCmsEntityObject, getCmsLayoutConfiguration, getCmsTranslate, getFormattedPrice, getLanguageName, getListingFilters, getMainImageUrl, getMedia, getPaymentMethodIcon, getProductCalculatedListingPrice, getProductFreeShipping, getProductFromPrice, getProductName, getProductRatingAverage, getProductReviews, getProductRoute, getProductTierPrices, getProductUrl, getShippingMethodDeliveryTime, getShippingMethodIcon, getSmallestThumbnailUrl, getSrcSetForMedia, getTranslatedProperty, helpersCssClasses, isCategory, isLandingPage, isMaintenanceMode, isProduct, relativeUrlSlash, urlIsAbsolute };
|
package/dist/index.mjs
CHANGED
|
@@ -3,8 +3,7 @@ function getProductFreeShipping(product) {
|
|
|
3
3
|
}
|
|
4
4
|
|
|
5
5
|
function getMainImageUrl(object) {
|
|
6
|
-
if (!object)
|
|
7
|
-
return "";
|
|
6
|
+
if (!object) return "";
|
|
8
7
|
if ("cover" in object && object.cover) {
|
|
9
8
|
if ("media" in object.cover) {
|
|
10
9
|
return object?.cover?.media?.url || "";
|
|
@@ -58,8 +57,7 @@ function getProductTierPrices(product) {
|
|
|
58
57
|
}
|
|
59
58
|
|
|
60
59
|
function getProductUrl(product) {
|
|
61
|
-
if (!product)
|
|
62
|
-
return "/";
|
|
60
|
+
if (!product) return "/";
|
|
63
61
|
const seoUrl = product.seoUrls?.[0]?.seoPathInfo;
|
|
64
62
|
return seoUrl ? `/${seoUrl}` : `/detail/${product.id}`;
|
|
65
63
|
}
|
|
@@ -89,8 +87,8 @@ function getProductFromPrice(product) {
|
|
|
89
87
|
}
|
|
90
88
|
const realPrice = getProductRealPrice(product);
|
|
91
89
|
const displayFromPriceLabel = (product.calculatedPrices?.length ?? 0) > 0;
|
|
92
|
-
if (displayFromPriceLabel)
|
|
93
|
-
|
|
90
|
+
if (displayFromPriceLabel) return realPrice?.unitPrice;
|
|
91
|
+
return void 0;
|
|
94
92
|
}
|
|
95
93
|
|
|
96
94
|
function getProductRoute(product) {
|
|
@@ -111,11 +109,12 @@ function getEntityPrefix(category) {
|
|
|
111
109
|
return "detail";
|
|
112
110
|
case "landing_page":
|
|
113
111
|
return "landingPage";
|
|
112
|
+
default:
|
|
113
|
+
return "navigation";
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
function getCategoryUrl(category) {
|
|
117
|
-
if (!category)
|
|
118
|
-
return "/";
|
|
117
|
+
if (!category) return "/";
|
|
119
118
|
switch (category.type) {
|
|
120
119
|
case void 0:
|
|
121
120
|
return "/";
|
|
@@ -136,8 +135,7 @@ function getCategoryImageUrl(category) {
|
|
|
136
135
|
function getCategoryBreadcrumbs(category, options) {
|
|
137
136
|
const breadcrumbs = category?.translated?.breadcrumb || category?.breadcrumb || [];
|
|
138
137
|
const startIndex = options?.startIndex || 0;
|
|
139
|
-
if (breadcrumbs.length <= startIndex)
|
|
140
|
-
return [];
|
|
138
|
+
if (breadcrumbs.length <= startIndex) return [];
|
|
141
139
|
return breadcrumbs.slice(startIndex).map((element) => {
|
|
142
140
|
return {
|
|
143
141
|
name: element
|
|
@@ -146,8 +144,7 @@ function getCategoryBreadcrumbs(category, options) {
|
|
|
146
144
|
}
|
|
147
145
|
|
|
148
146
|
function getCategoryRoute(category) {
|
|
149
|
-
if (!category)
|
|
150
|
-
return "/";
|
|
147
|
+
if (!category) return "/";
|
|
151
148
|
if (category.type === "page" || category.type === "link" && category.linkType === "category") {
|
|
152
149
|
return {
|
|
153
150
|
path: getCategoryUrl(category),
|
|
@@ -266,8 +263,7 @@ function urlIsAbsolute(url) {
|
|
|
266
263
|
|
|
267
264
|
function buildUrlPrefix(url, prefix) {
|
|
268
265
|
if (typeof url === "string") {
|
|
269
|
-
if (urlIsAbsolute(url))
|
|
270
|
-
return { path: url };
|
|
266
|
+
if (urlIsAbsolute(url)) return { path: url };
|
|
271
267
|
const resultUrl = url[0] !== "/" ? `/${url}` : url;
|
|
272
268
|
return { path: prefix ? `/${prefix}${resultUrl}` : resultUrl };
|
|
273
269
|
}
|
|
@@ -290,8 +286,7 @@ function isMaintenanceMode(errors) {
|
|
|
290
286
|
}
|
|
291
287
|
|
|
292
288
|
function getCmsTranslate(key, params) {
|
|
293
|
-
if (!params)
|
|
294
|
-
return key;
|
|
289
|
+
if (!params) return key;
|
|
295
290
|
let translatedText = key;
|
|
296
291
|
for (const param in params) {
|
|
297
292
|
const placeholder = `{${param}}`;
|
|
@@ -436,6 +431,14 @@ function getShippingMethodDeliveryTime(shippingMethod) {
|
|
|
436
431
|
return shippingMethod.deliveryTime?.translated.name;
|
|
437
432
|
}
|
|
438
433
|
|
|
434
|
+
function getShippingMethodIcon(shippingMethod) {
|
|
435
|
+
return shippingMethod.media?.url ?? "";
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
function getPaymentMethodIcon(paymentMethod) {
|
|
439
|
+
return paymentMethod.media?.url ?? "";
|
|
440
|
+
}
|
|
441
|
+
|
|
439
442
|
function getLanguageName(language) {
|
|
440
443
|
return language.translationCode?.translated.name || "";
|
|
441
444
|
}
|
|
@@ -452,4 +455,4 @@ function canUseQuoteActions(quote) {
|
|
|
452
455
|
return ["replied"].includes(quote.stateMachineState?.technicalName ?? "");
|
|
453
456
|
}
|
|
454
457
|
|
|
455
|
-
export { buildUrlPrefix, canUseQuoteActions, downloadFile, getBackgroundImageUrl, getBiggestThumbnailUrl, getCategoryBreadcrumbs, getCategoryImageUrl, getCategoryRoute, getCategoryUrl, getCmsBreadcrumbs, getCmsEntityObject, getCmsLayoutConfiguration, getCmsTranslate, getFormattedPrice, getLanguageName, getListingFilters, getMainImageUrl, getMedia, getProductCalculatedListingPrice, getProductFreeShipping, getProductFromPrice, getProductName, getProductRatingAverage, getProductReviews, getProductRoute, getProductTierPrices, getProductUrl, getShippingMethodDeliveryTime, getSmallestThumbnailUrl, getSrcSetForMedia, getTranslatedProperty, helpersCssClasses, isCategory, isLandingPage, isMaintenanceMode, isProduct, relativeUrlSlash, urlIsAbsolute };
|
|
458
|
+
export { buildUrlPrefix, canUseQuoteActions, downloadFile, getBackgroundImageUrl, getBiggestThumbnailUrl, getCategoryBreadcrumbs, getCategoryImageUrl, getCategoryRoute, getCategoryUrl, getCmsBreadcrumbs, getCmsEntityObject, getCmsLayoutConfiguration, getCmsTranslate, getFormattedPrice, getLanguageName, getListingFilters, getMainImageUrl, getMedia, getPaymentMethodIcon, getProductCalculatedListingPrice, getProductFreeShipping, getProductFromPrice, getProductName, getProductRatingAverage, getProductReviews, getProductRoute, getProductTierPrices, getProductUrl, getShippingMethodDeliveryTime, getShippingMethodIcon, getSmallestThumbnailUrl, getSrcSetForMedia, getTranslatedProperty, helpersCssClasses, isCategory, isLandingPage, isMaintenanceMode, isProduct, relativeUrlSlash, urlIsAbsolute };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shopware/helpers",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "Shopware helpers for accessing API data",
|
|
5
5
|
"author": "Shopware",
|
|
6
6
|
"type": "module",
|
|
@@ -33,10 +33,10 @@
|
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@biomejs/biome": "1.8.3",
|
|
36
|
-
"@vitest/coverage-v8": "2.
|
|
37
|
-
"happy-dom": "
|
|
36
|
+
"@vitest/coverage-v8": "3.2.3",
|
|
37
|
+
"happy-dom": "18.0.1",
|
|
38
38
|
"unbuild": "2.0.0",
|
|
39
|
-
"vitest": "2.
|
|
39
|
+
"vitest": "3.2.3",
|
|
40
40
|
"tsconfig": "0.0.0"
|
|
41
41
|
},
|
|
42
42
|
"scripts": {
|