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

fix: consider null getActiveUserDiscounts

Übergeordneter 8cd7974a
No related branches found
No related tags found
Keine zugehörigen Merge Requests gefunden
......@@ -503,6 +503,7 @@ public function toPriceFactor($Locale = null, $Customer = null)
if ($this->getAttribute('scope') === Handler::DISCOUNT_SCOPE_TOTAL) {
return new PriceFactor([
'identifier' => 'discount-'.$this->getId(),
'title' => $this->getTitle($Locale),
'description' => '',
'priority' => (int)$this->getAttribute('priority'),
......@@ -515,6 +516,7 @@ public function toPriceFactor($Locale = null, $Customer = null)
}
return new QUI\ERP\Products\Utils\PriceFactor([
'identifier' => 'discount-'.$this->getId(),
'title' => $this->getTitle($Locale),
'description' => '',
'priority' => (int)$this->getAttribute('priority'),
......
......@@ -153,7 +153,7 @@ public static function onQuiqqerProductsCalcListProduct(
return false;
}
return $Discount->getAttribute('scope') == Handler::DISCOUNT_SCOPE_EVERY_PRODUCT;
return (int)$Discount->getAttribute('scope') === Handler::DISCOUNT_SCOPE_EVERY_PRODUCT;
});
if (!\is_array($userDiscounts) || empty($userDiscounts)) {
......@@ -168,6 +168,7 @@ public static function onQuiqqerProductsCalcListProduct(
return;
}
$PriceFactors = $Product->getPriceFactors();
$productQuantity = $Product->getQuantity();
$productNettoSum = $attributes['calculated_nettoSum'];
......@@ -181,13 +182,21 @@ public static function onQuiqqerProductsCalcListProduct(
continue;
}
$Product->getPriceFactors()->addToEnd(
$Discount->toPriceFactor(
$Calc->getUser()->getLocale(),
$Calc->getUser()
)
// check if Pricefactor is already in
$factors = $PriceFactors->toArray();
$Factor = $Discount->toPriceFactor(
$Calc->getUser()->getLocale(),
$Calc->getUser()
);
foreach ($factors['end'] as $factor) {
if ($factor['identifier'] === $Factor->getIdentifier()) {
continue 2;
}
}
$PriceFactors->addToEnd($Factor);
if ($Discount->getAttribute('lastProductDiscount')) {
return;
}
......@@ -220,7 +229,7 @@ public static function onQuiqqerProductsCalcList(
return false;
}
return $Discount->getAttribute('scope') == Handler::DISCOUNT_SCOPE_TOTAL;
return (int)$Discount->getAttribute('scope') == Handler::DISCOUNT_SCOPE_TOTAL;
});
if (!\is_array($userDiscounts)) {
......@@ -229,6 +238,7 @@ public static function onQuiqqerProductsCalcList(
$listQuantity = $List->getQuantity();
$products = $List->getProducts();
$PriceFactors = $List->getPriceFactors();
/* @var $Discount Discount */
foreach ($userDiscounts as $Discount) {
......@@ -295,14 +305,21 @@ public static function onQuiqqerProductsCalcList(
}
}
$List->getPriceFactors()->addToEnd(
$Discount->toPriceFactor(
$Calc->getUser()->getLocale(),
$Calc->getUser()
)
// check if Pricefactor is already in
$factors = $PriceFactors->toArray();
$Factor = $Discount->toPriceFactor(
$Calc->getUser()->getLocale(),
$Calc->getUser()
);
foreach ($factors['end'] as $factor) {
if ($factor['identifier'] === $Factor->getIdentifier()) {
continue 2;
}
}
$PriceFactors->addToEnd($Factor);
if ($Discount->getAttribute('lastSumDiscount')) {
return;
}
......
......@@ -127,6 +127,14 @@ public static function getActiveUserDiscounts(UserInterface $User)
]
]);
$discountsNULL = $Discounts->getChildren([
'where' => [
'active' => 1,
'user_groups' => null
]
]);
$discounts = \array_merge($discounts, $discountsNULL);
if (!empty($personalDiscounts)) {
$result = \array_merge($personalDiscounts, $result);
......@@ -136,6 +144,22 @@ public static function getActiveUserDiscounts(UserInterface $User)
$result = \array_merge($discounts, $result);
}
$alreadyAttached = [];
$result = \array_filter($result, function ($Discount) use (&$alreadyAttached) {
/* @var $Discount Discount */
$id = $Discount->getId();
if (isset($alreadyAttached[$id])) {
return false;
}
$alreadyAttached[$id] = true;
return true;
});
return $result;
}
......
0% oder .
You are about to add 0 people to the discussion. Proceed with caution.
Bearbeitung dieser Nachricht zuerst beenden!
Bitte registrieren oder zum Kommentieren