Back to PhocacartCalculation class

Method calculateDiscountPercentage

public static
calculateDiscountPercentage
(mixed $discount, mixed $quantity, mixed &$priceItems, mixed &$total, mixed $taxKey = '')

Method calculateDiscountPercentage - Source code

public static function calculateDiscountPercentage($discount, $quantity, &$priceItems, &$total, $taxKey = '')
{
    $price = new PhocacartPrice();
    // $taxCalcType 1 ... percentage, 2 ... fixed amount (be aware it is not the tax calculation set in options: brutto, netto, none)
    $taxCalcType = $priceItems['taxcalctype'];
    $dB = $price->roundPrice($priceItems['brutto'] * $discount / 100);
    $dN = $price->roundPrice($priceItems['netto'] * $discount / 100);
    $dT = $price->roundPrice($priceItems['tax'] * $discount / 100);
    $priceItems['bruttodiscount'] = $taxCalcType == 2 ? $dN : $dB;
    $priceItems['nettodiscount'] = $dN;
    $priceItems['taxdiscount'] = $taxCalcType == 2 ? 0 : $dT;
    $priceItems['brutto'] -= $priceItems['bruttodiscount'];
    $priceItems['netto'] -= $priceItems['nettodiscount'];
    $priceItems['tax'] -= $priceItems['taxdiscount'];
    if (!empty($total)) {
        $total['brutto'] -= $taxCalcType == 2 ? $dN * $quantity : $dB * $quantity;
        $total['netto'] -= $dN * $quantity;
        $total['tax'][$taxKey]['tax'] -= $taxCalcType == 2 ? 0 : $dT * $quantity;
        $total['tax'][$taxKey]['netto'] -= $taxCalcType == 2 ? 0 : $dN * $quantity;
        $total['tax'][$taxKey]['brutto'] -= $taxCalcType == 2 ? 0 : $dB * $quantity;
    }
    return true;
}