Back to PhocacartCart class

Method addPaymentCosts

public
addPaymentCosts
(mixed $paymentId = 0)

Method addPaymentCosts - Source code

public function addPaymentCosts($paymentId = 0)
{
    if ($paymentId == 0) {
        $paymentId = $this->payment['id'];
    }
    $paymentObject = new PhocacartPayment();
    $paymentObject->setType($this->type);
    $pI = $paymentObject->getPaymentMethod((int) $paymentId);
    $shippingId = 0;
    if (isset($this->shipping['id']) && (int) $this->shipping['id'] > 0) {
        $shippingId = $this->shipping['id'];
    } else {
        if (isset($this->shipping['costs']['id']) && (int) $this->shipping['costs']['id'] > 0) {
            $shippingId = $this->shipping['costs']['id'];
        }
    }
    if (!isset($this->total[0])) {
        $this->total[0] = array();
    }
    $paymentValid = $paymentObject->checkAndGetPaymentMethod((int) $paymentId, $this->total[0], $shippingId);
    if (!$paymentValid) {
        PhocacartPayment::removePayment();
        // In case user has in cart payment method which does not exists
        // Remove Shipping and Payment when updated
        unset($pI);
    }
    if (!empty($pI)) {
        $pI->freepayment = 0;
        if (isset($this->total[0]['free_payment']) && $this->total[0]['free_payment'] == 1) {
            $pI->freepayment = 1;
        }
        $price = new PhocacartPrice();
        $priceI = $price->getPriceItemsPayment($pI->cost, $pI->cost_additional, $pI->calculation_type, $this->total[0], $pI->taxid, $pI->taxrate, $pI->taxcalculationtype, $pI->taxtitle, $pI->freepayment, 1);
        // CALCULATION
        $calc = new PhocacartCartCalculation();
        $calc->setType($this->type);
        $this->payment['costs'] = $priceI;
        if (!isset($this->total[0]['free_payment']) || isset($this->total[0]['free_payment']) && $this->total[0]['free_payment'] != 1) {
            $this->payment['costs']['id'] = $pI->id;
            $this->payment['costs']['title'] = $pI->title;
            $this->payment['costs']['title_lang'] = $pI->title;
            $this->payment['costs']['title_lang_suffix'] = '';
            $this->payment['costs']['title_lang_suffix2'] = '';
            $this->payment['costs']['description'] = $pI->description;
            $this->payment['costs']['image'] = $pI->image;
            $this->payment['costs']['method'] = $pI->method;
            $this->payment['costs']['params_payment'] = !empty($this->payment['params_payment']) ? $this->payment['params_payment'] : array();
            // Update even the payment info
            $this->payment['id'] = $pI->id;
            $this->payment['title'] = $pI->title;
            $this->payment['method'] = $pI->method;
            $this->payment['image'] = $pI->image;
        }
        $calc->calculatePayment($priceI, $this->total[0]);
        //$calc->round($this->total[0], 0);
    }
}