diff --git a/src/automats/articleIndexAutomat.js b/src/automats/articleIndexAutomat.js index 0bf6869..f0470f3 100644 --- a/src/automats/articleIndexAutomat.js +++ b/src/automats/articleIndexAutomat.js @@ -97,14 +97,19 @@ function scheduleRebuild() { */ function toIndexRecord(article, categoryId) { const eans = article.eans ?? article.eanCodes ?? article.ean ?? null; + const childCount = Number(article.childCount) || 0; + const price = article.price ?? article.net ?? article.vknetto ?? null; return { ...article, id: article.id, sku: article.sku, name: article.name, + price, + net: article.net ?? price, eans: Array.isArray(eans) ? eans.filter(Boolean) : eans ? [eans] : [], categories: categoryId != null ? String(categoryId) : null, - isParent: Boolean(article.isParent ?? article.is_parent), + isParent: Boolean(article.isParent ?? article.is_parent ?? (childCount > 0)), + childCount, }; } @@ -135,7 +140,20 @@ export function buildArticleIndex(views) { ids.add(String(categoryId)); existing.categories = Array.from(ids).join(','); } - existing.isParent = Boolean(existing.isParent || (article.isParent ?? article.is_parent)); + const childCount = Number(article.childCount) || 0; + if (childCount > (Number(existing.childCount) || 0)) { + existing.childCount = childCount; + } + existing.isParent = Boolean( + existing.isParent || + (article.isParent ?? article.is_parent) || + (childCount > 0) + ); + if (existing.price == null && (article.price != null || article.net != null)) { + const p = article.price ?? article.net ?? article.vknetto; + existing.price = p; + existing.net = article.net ?? p; + } } } diff --git a/src/components/article/ArticleSearch.jsx b/src/components/article/ArticleSearch.jsx index 0cb6e33..5e8a329 100644 --- a/src/components/article/ArticleSearch.jsx +++ b/src/components/article/ArticleSearch.jsx @@ -28,7 +28,7 @@ import { BrandLabel } from '../brand'; import { formatPrice } from '../../utils/price'; import { formatStock } from './searchFormat'; import ResultsPagination from './ResultsPagination'; -import { BORDER } from '../../colors'; +import { BORDER, SCRIM_LABEL } from '../../colors'; const searchResultRowSx = { alignItems: 'center', @@ -45,6 +45,8 @@ const searchResultRowSx = { whiteSpace: 'nowrap', lineHeight: '22px', height: '22px', + display: 'flex', + alignItems: 'center', }, '& .MuiListItemText-secondary': { overflow: 'hidden', @@ -512,7 +514,52 @@ export default class ArticleSearch extends PureComponent { + + {article.name || '–'} + + {Boolean(article.isParent || article.is_parent || (Number(article.childCount) > 0)) && ( + + {Number(article.childCount) || 0} + + )} + + } secondary={ {article.name || '–'} + {Boolean(article.isParent || article.is_parent || (Number(article.childCount) > 0)) && ( + + {Number(article.childCount) || 0} + + )} {(article.brand?.name || article.brandName) && ( diff --git a/src/routes/artikel.jsx b/src/routes/artikel.jsx index cc6da4f..b0b820b 100644 --- a/src/routes/artikel.jsx +++ b/src/routes/artikel.jsx @@ -48,6 +48,7 @@ import { categoryAutomat, } from '../automats'; import { BrandLabel } from '../components/brand'; +import { SCRIM_LABEL } from '../colors'; // #endregion // #region Styles & Measure Sample @@ -66,6 +67,8 @@ const resultRowSx = { whiteSpace: 'nowrap', lineHeight: '22px', height: '22px', + display: 'flex', + alignItems: 'center', }, '& .MuiListItemText-secondary': { overflow: 'hidden', @@ -579,22 +582,72 @@ class ArtikelSearchPage extends Component { {rows.length > 0 && ( - {rows.map((row, index) => ( - e.preventDefault()} - onClick={() => { - this.persistQuery(); - this.props.navigate(artikelDetailPath(row)); - }} - sx={resultRowSx} - > - { + const isParent = Boolean(row.isParent || row.is_parent); + const childCount = Number(row.childCount) || 0; + const showChildBadge = isParent || childCount > 0; + const price = row.price ?? row.net ?? row.vknetto; + return ( + e.preventDefault()} + onClick={() => { + this.persistQuery(); + this.props.navigate(artikelDetailPath(row)); + }} + sx={resultRowSx} + > + + + {row.name} + + {showChildBadge && ( + + {childCount} + + )} + + } + secondary={ - {row.price != null ? formatPrice(row.price) : '—'} + {price != null ? formatPrice(price) : '—'} - ))} + ); + })} )}