u
This commit is contained in:
@@ -359,12 +359,24 @@ export async function executeCompanyImport({
|
|||||||
const brandEntries = Array.from(brandMap.entries());
|
const brandEntries = Array.from(brandMap.entries());
|
||||||
log.info(`Processing ${brandEntries.length} brands (Hersteller)...`);
|
log.info(`Processing ${brandEntries.length} brands (Hersteller)...`);
|
||||||
|
|
||||||
|
// Fetch existing brands to accurately track new vs existing
|
||||||
|
const existingBrands = await store.brand.list(googleAuthId);
|
||||||
|
const existingBrandNames = new Set(
|
||||||
|
existingBrands.map((b) => (b.name || '').trim().toLowerCase()).filter(Boolean)
|
||||||
|
);
|
||||||
|
|
||||||
for (let i = 0; i < brandEntries.length; i++) {
|
for (let i = 0; i < brandEntries.length; i++) {
|
||||||
const [brandName, picSet] = brandEntries[i];
|
const [brandName, picSet] = brandEntries[i];
|
||||||
|
const lowerName = brandName.trim().toLowerCase();
|
||||||
|
const isNew = !existingBrandNames.has(lowerName);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const brand = await store.brand.upsert(googleAuthId, { name: brandName });
|
const brand = await store.brand.upsert(googleAuthId, { name: brandName });
|
||||||
brandNameToId.set(brandName.toLowerCase(), brand.id);
|
brandNameToId.set(lowerName, brand.id);
|
||||||
createdBrandCount++;
|
if (isNew) {
|
||||||
|
createdBrandCount++;
|
||||||
|
existingBrandNames.add(lowerName);
|
||||||
|
}
|
||||||
|
|
||||||
// If brand doesn't have an image yet, import from manufacturerPictureFiles
|
// If brand doesn't have an image yet, import from manufacturerPictureFiles
|
||||||
if ((!brand.pics || brand.pics.length === 0) && picSet.size > 0) {
|
if ((!brand.pics || brand.pics.length === 0) && picSet.size > 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user