CMXX - Categories and catalog enhancements

This commit is contained in:
“VeLiTi”
2025-01-31 17:03:31 +01:00
parent a669b2fadf
commit 754359f6b6
10 changed files with 234 additions and 37 deletions

View File

@@ -2983,4 +2983,55 @@ function removeKeysRecursive(array &$array, array $keysToRemove): void {
}
}
}
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Catalogprocessor ++++++++++++++
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
function processProductCollection($products) {
$processedProducts = [];
foreach ($products as $key => $product) {
// Check if product has versions
if (isset($product['versions']) && !empty($product['versions'])) {
// Check if there's only one version
$singleVersion = count($product['versions']) === 1;
// For each version, create a new product entry
foreach ($product['versions'] as $version) {
// Create a copy of the base product
$versionProduct = $product;
// Remove the versions array
unset($versionProduct['versions']);
// Add version specific data
$versionProduct['version_id'] = $version['version_id'];
$versionProduct['config_setting'] = $version['config_setting'];
$versionProduct['configurations'] = $version['configurations'];
// Only modify identifiers if there's more than one version
if (!$singleVersion) {
// Create a unique rowID for the new product
$versionProduct['rowID'] = $versionProduct['rowID'] . '_v' . $version['version_id'];
// Add version suffix to productcode and url_slug
$versionProduct['productcode'] = $versionProduct['productcode'] . '_v' . $version['version_id'];
if (!empty($versionProduct['url_slug'])) {
$versionProduct['url_slug'] = $versionProduct['url_slug'] . '_v' . $version['version_id'];
}
// Add version to product name if needed
$versionProduct['productname'] = $versionProduct['productname'] . ' (v' . $version['version_id'] . ')';
}
// Add to processed products
$processedProducts[] = $versionProduct;
}
} else {
// If no versions, add product as is
$processedProducts[] = $product;
}
}
return $processedProducts;
}