private function calculateCouponModifier(CouponInterface $coupon, OrderInterface $order) : float { $modifierType = $coupon->getModifierType(); $modifierValue = $coupon->getModifierValue(); $baseCurrency = $coupon->getCurrency(); $targetCurrency = $order->getCurrency(); $totalGrossPrice = $order->getProductTotal()->getGrossPrice(); if ('%' === $modifierType) { return $modifierValue / 100; } if ('-' === $modifierType) { $modifierValue = $this->currencyHelper->convert($modifierValue, $baseCurrency, $targetCurrency); return $modifierValue >= $totalGrossPrice ? 1 : $modifierValue / $totalGrossPrice; } return 1; }
/** * Calculates the modifier's value according to current currency and coupon's modifier * * @param CouponInterface $coupon * @param float|int $amount * @param string $targetCurrency * * @return float|int */ protected function calculateModifierValue(CouponInterface $coupon, $amount, $targetCurrency) { $modifierType = $coupon->getModifierType(); $modifierValue = $coupon->getModifierValue(); $baseCurrency = $coupon->getCurrency(); switch ($modifierType) { case '-': $modifierValue = $this->currencyHelper->convert($modifierValue, $baseCurrency, $targetCurrency); $modifier = $modifierValue >= $amount ? 1 : $modifierValue / $amount; break; case '%': $modifier = $modifierValue / 100; break; default: $modifier = 0; } return $modifier; }