Back to PhocacartCartCalculation class

Method recalculateCartDiscounts

public
recalculateCartDiscounts
(mixed &$fullItems, mixed &$fullItemsGroup, mixed &$total)

Method recalculateCartDiscounts - Source code

/*
 * Used only for fixed amount of discount
 */
public function recalculateCartDiscounts(&$fullItems, &$fullItemsGroup, &$total)
{
    foreach ($fullItems as $k => $v) {
        // Fixed amount - we need to recalculate
        $dF = $v['discountcartfixedid'];
        if (isset($total['discountcartfixedamount'][$dF]['discount']) && isset($total['discountcartfixedamount'][$dF]['netto'])) {
            $dPRel = 0;
            if ($total['discountcartfixedamount'][$dF]['netto'] > 0) {
                $dPRel = $total['discountcartfixedamount'][$dF]['discount'] / $total['discountcartfixedamount'][$dF]['netto'];
            }
            // CART DISCOUNT - DIVIDE IT INTO QUANTITY
            $dPFix = $dPRel * $v['netto'] * $v['quantity'];
            if ($v['netto'] > 0) {
                $r = $dPFix * 100 / $v['netto'] / $v['quantity'];
                // Ratio to use it for brutto and tax but you need to divide it into qunatity
            } else {
                $r = 0;
            }
            PhocacartCalculation::calculateDiscountFixedAmount($r, $v['quantity'], $fullItems[$k], $total, $v['taxkey']);
            PhocacartCalculation::correctItemsIfNull($fullItems[$k]);
            PhocacartCalculation::correctTotalIfNull($total, $v['taxkey']);
        }
        $fullItems[$k]['final'] = $fullItems[$k]['netto'] && !$this->posbruttocalculation ? $fullItems[$k]['netto'] * $v['quantity'] : $fullItems[$k]['brutto'] * $v['quantity'];
        if (isset($fullItems[$k]['nettodiscount']) && !$this->posbruttocalculation) {
            $fullItems[$k]['finaldiscount'] = $fullItems[$k]['nettodiscount'] * $v['quantity'];
        } else {
            if (isset($fullItems[$k]['bruttodiscount'])) {
                $fullItems[$k]['finaldiscount'] = $fullItems[$k]['bruttodiscount'] * $v['quantity'];
            }
        }
        if ($this->correctsubtotal) {
            $this->correctSubTotal($fullItems[$k], $total);
        }
    }
}