Back to PhocacartCartCalculation class

Method calculateRewardDiscounts

public
calculateRewardDiscounts
(mixed &$fullItems, mixed &$fullItemsGroup, mixed &$total, mixed $rewardCart)

Method calculateRewardDiscounts - Source code

// ================
// REWARD POINTS
// ================
public function calculateRewardDiscounts(&$fullItems, &$fullItemsGroup, &$total, $rewardCart)
{
    $reward = new PhocacartReward();
    $rewards = array();
    $rewards['used'] = $reward->checkReward((int) $rewardCart['used']);
    $rewards['usedtotal'] = 0;
    foreach ($fullItems as $k => $v) {
        if (isset($v['points_needed']) && (int) $v['points_needed'] > 0) {
            $rewards['needed'] = $v['quantity'] * $v['points_needed'];
            $reward->calculatedRewardDiscountProduct($rewards);
            if (isset($rewards['percentage']) && $rewards['percentage'] > 0) {
                $fullItems[$k]['rewardproduct'] = 1;
                $fullItems[$k]['rewardproductpoints'] = $rewards['usedproduct'];
                $fullItems[$k]['rewardproducttitle'] = Text::_('COM_PHOCACART_REWARD_POINTS');
                PhocacartCalculation::calculateDiscountPercentage($rewards['percentage'], $v['quantity'], $fullItems[$k], $total, $v['taxkey']);
                $fullItems[$k]['rewardproducttxtsuffix'] = ' (' . $rewards['usedproduct'] . ')';
                $total['rewardproducttxtsuffix'] = ' (' . $rewards['usedtotal'] . ')';
                $total['rewardproductusedtotal'] = $rewards['usedtotal'];
                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);
            }
        }
    }
}