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

feat: quiqqer/stock-management#13

Übergeordneter 10023c73
Keine zugehörigen Branchen gefunden
Keine zugehörigen Tags gefunden
Keine zugehörigen Merge Requests gefunden
......@@ -8,6 +8,7 @@
use QUI;
use QUI\ERP\Products\Product\ProductList;
use QUI\ERP\Order\Utils\Utils as OrderProductUtils;
/**
* Class BasketOrder
......@@ -175,30 +176,48 @@ public function getProducts()
* Add a product to the basket
*
* @param Product $Product
* @throws QUI\Exception
*/
public function addProduct(Product $Product)
{
/** @noinspection \QUI\Exception */
$Package = QUI::getPackage('quiqqer/order');
$Config = $Package->getConfig();
$merge = \boolval($Config->getValue('orderProcess', 'mergeSameProducts'));
if (!$merge) {
$this->List->addProduct($Product);
} else {
$Products = $this->List->getProducts();
foreach ($Products as $Product) {
if ($this->hasOrder()) {
$this->updateOrder();
}
return;
}
if ($this->hasOrder()) {
if (!$merge) {
$this->getOrder()->addArticle($Product->toArticle());
$Products = $this->List->getProducts();
$foundProduct = false;
foreach ($Products as $key => $P) {
$p1 = OrderProductUtils::getCompareProductArray($Product->toArray());
$p2 = OrderProductUtils::getCompareProductArray($P->toArray());
if ($p1 == $p2) {
$foundProduct = true;
$quantity = $P->getQuantity();
$quantity = $quantity + $Product->getQuantity();
$P->setQuantity($quantity);
break;
}
}
$this->save();
if ($foundProduct === false) {
$this->List->addProduct($Product);
}
if ($this->hasOrder()) {
$this->updateOrder();
}
}
......@@ -207,7 +226,6 @@ public function addProduct(Product $Product)
*
* @param integer $pos
*
* @throws Exception
* @throws QUI\ERP\Exception
* @throws QUI\ERP\Order\Exception
* @throws QUI\Exception
......@@ -245,36 +263,11 @@ public function import($products = [])
$merge = \boolval($Config->getValue('orderProcess', 'mergeSameProducts'));
if ($merge) {
$newProductList = [];
$getCompareProductArray = function ($product) {
$compare = [];
$needles = [
'id',
'title',
'articleNo',
'description',
'unitPrice',
'displayPrice',
'class',
'customFields',
'customData',
'display_unitPrice'
];
foreach ($needles as $f) {
if (isset($product[$f])) {
$compare[$f] = $product[$f];
}
}
return $compare;
};
$getProductIndex = function ($product) use (&$newProductList, $getCompareProductArray) {
$newProductList = [];
$getProductIndex = function ($product) use (&$newProductList) {
foreach ($newProductList as $index => $p) {
$p1 = \serialize($getCompareProductArray($product));
$p2 = \serialize($getCompareProductArray($p));
$p1 = \serialize(OrderProductUtils::getCompareProductArray($product));
$p2 = \serialize(OrderProductUtils::getCompareProductArray($p));
if ($p1 == $p2) {
return $index;
......
......@@ -323,4 +323,35 @@ public static function importProductsToBasketList(
return $List;
}
/**
* Return a product array with all important fields, to compare a product with another
*
* @param $product
* @return array
*/
public static function getCompareProductArray($product)
{
$compare = [];
$needles = [
'id',
'title',
'articleNo',
'description',
'unitPrice',
'displayPrice',
'class',
'customFields',
'customData',
'display_unitPrice'
];
foreach ($needles as $f) {
if (isset($product[$f])) {
$compare[$f] = $product[$f];
}
}
return $compare;
}
}
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