Skip to content
Code-Schnipsel Gruppen Projekte
Commit a8f1df91 erstellt von Henning Leutz's avatar Henning Leutz :martial_arts_uniform:
Dateien durchsuchen

refactor: merge product list method -> Takes a product array and brings...

refactor: merge product list method -> Takes a product array and brings together all products that can be brought together
Übergeordneter 53689959
Keine zugehörigen Branchen gefunden
Keine zugehörigen Tags gefunden
Keine zugehörigen Merge Requests gefunden
......@@ -263,32 +263,7 @@ public function import($products = [])
$merge = \boolval($Config->getValue('orderProcess', 'mergeSameProducts'));
if ($merge) {
$newProductList = [];
$getProductIndex = function ($product) use (&$newProductList) {
foreach ($newProductList as $index => $p) {
$p1 = \serialize(OrderProductUtils::getCompareProductArray($product));
$p2 = \serialize(OrderProductUtils::getCompareProductArray($p));
if ($p1 == $p2) {
return $index;
}
}
return false;
};
foreach ($products as $product) {
$index = $getProductIndex($product);
if ($index !== false) {
$newProductList[$index]['quantity'] = $newProductList[$index]['quantity'] + $product['quantity'];
continue;
}
$newProductList[] = $product;
}
$products = $newProductList;
$products = OrderProductUtils::getMergedProductList($products);
}
$this->List = QUI\ERP\Order\Utils\Utils::importProductsToBasketList(
......
......@@ -354,4 +354,40 @@ public static function getCompareProductArray($product)
return $compare;
}
/**
* Takes a product array and brings together all products that can be brought together
*
* @param $products
* @return array
*/
public static function getMergedProductList($products)
{
$newProductList = [];
$getProductIndex = function ($product) use (&$newProductList) {
foreach ($newProductList as $index => $p) {
$p1 = \serialize(self::getCompareProductArray($product));
$p2 = \serialize(self::getCompareProductArray($p));
if ($p1 == $p2) {
return $index;
}
}
return false;
};
foreach ($products as $product) {
$index = $getProductIndex($product);
if ($index !== false) {
$newProductList[$index]['quantity'] = $newProductList[$index]['quantity'] + $product['quantity'];
continue;
}
$newProductList[] = $product;
}
return $newProductList;
}
}
0% Lade oder .
You are about to add 0 people to the discussion. Proceed with caution.
Bearbeitung dieser Nachricht zuerst beenden!
Bitte registrieren oder zum Kommentieren