u
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
||||
netFromGross,
|
||||
parsePriceInput,
|
||||
} from './price';
|
||||
import brandAutomat from '../automats/brandAutomat';
|
||||
|
||||
export function sortedPhotos(article) {
|
||||
if (!Array.isArray(article?.photos)) return [];
|
||||
@@ -150,6 +151,51 @@ export function articleEans(article) {
|
||||
return article.eans.filter(Boolean);
|
||||
}
|
||||
|
||||
export function getArticleEan(article) {
|
||||
if (!article) return '';
|
||||
const eans = articleEans(article);
|
||||
if (eans.length > 0) {
|
||||
const first = eans[0];
|
||||
return String(typeof first === 'object' && first ? (first.ean ?? '') : first ?? '').trim();
|
||||
}
|
||||
if (article.ean) {
|
||||
return String(typeof article.ean === 'object' && article.ean ? (article.ean.ean ?? '') : article.ean).trim();
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
export function getArticleBrand(article) {
|
||||
if (!article) return '';
|
||||
if (typeof article.brand === 'object' && article.brand?.name) {
|
||||
return String(article.brand.name).trim();
|
||||
}
|
||||
if (typeof article.brand === 'string' && article.brand.trim()) {
|
||||
return article.brand.trim();
|
||||
}
|
||||
if (article.brandName) {
|
||||
return String(article.brandName).trim();
|
||||
}
|
||||
if (article.brandId != null) {
|
||||
const brands = brandAutomat?.state?.brands || [];
|
||||
const b = brands.find((x) => x.id === article.brandId);
|
||||
if (b?.name) return String(b.name).trim();
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
export function getArticleName(article) {
|
||||
if (!article) return '';
|
||||
return String(article.name ?? article.sku ?? '').trim();
|
||||
}
|
||||
|
||||
export function buildGoogleSearchQuery(article) {
|
||||
if (!article) return '';
|
||||
const ean = getArticleEan(article);
|
||||
const brand = getArticleBrand(article);
|
||||
const name = getArticleName(article);
|
||||
return [ean, brand, name].filter(Boolean).join(' ');
|
||||
}
|
||||
|
||||
export function formatPhotoSizeKb(fullSize) {
|
||||
return `${Math.round(fullSize / 1024)} KB`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user