예제 #1
0
    /**
     * Gets all orders that where payed with Klarna and delivers a JSON String.
     * Checks all orders that have the "pending" state and changes the state if neccesary.
     *
     * @see templates/backend/plugins/PigmbhKlarnaPayment/index.php
     * @return void
     */
    public function getOrdersAction()
    {
        piKlarnaCheckPendingOrders();
        $piKlarnaInvoiceId = piKlarnaGetInvoicePaymentId();
        $piKlarnaRateId    = piKlarnaGetRatePaymentId();
        $this->View()->setTemplate();

        $piKlarnaStart            = isset($this->Request()->start) ? $this->Request()->start : 0;
        $piKlarnaLimit            = isset($this->Request()->limit) ? $this->Request()->limit : 10;
        $piKlarnaAcceptedStatusId = piKlarnaGetAcceptedStatusId();

        if ($this->Request()->nurbezahlt == 'true') {
            $piKlarnaZahlString = "AND a.cleared = " . (int)$piKlarnaAcceptedStatusId . "";
        } else {
            $piKlarnaZahlString = "";
        }
        if (isset($this->Request()->search)) {
            $piKlarnaSearch = mysql_escape_string($this->Request()->search);
        } else {
            $piKlarnaSearch = '';
        }
        if (isset($this->Request()->suchenach)) {
            $piKlarnaSearchFor = $this->Request()->suchenach;
        } else {
            $piKlarnaSearchFor = 1;
        }
        if ($piKlarnaSearch == '') {
            $piKlarnaSearchString = "a.transactionID LIKE '%%'";
        } else {
            switch($piKlarnaSearchFor) {
                case 1:
                    $piKlarnaSearchString = "a.ordernumber LIKE '%" . $piKlarnaSearch . "%'" . "OR a.transactionID LIKE '%" . $piKlarnaSearch . "%'" . "OR d.description LIKE '%" . $piKlarnaSearch . "%'" . "OR b.lastname LIKE '%" . $piKlarnaSearch . "%' ";
                    break;
                case 2:
                    $piKlarnaSearchString = "a.ordernumber LIKE '%" . $piKlarnaSearch . "%'";
                    break;
                case 3:
                    $piKlarnaSearchString = "a.transactionID LIKE '%" . $piKlarnaSearch . "%'";
                    break;
                case 4:
                    $piKlarnaSearchString = "d.description LIKE '%" . $piKlarnaSearch . "%'";
                    break;
                case 5:
                    $piKlarnaSearchString = "b.lastname LIKE '%" . $piKlarnaSearch . "%'";
                    break;
                default:
                    $piKlarnaSearchString = "a.ordernumber LIKE '%" . $piKlarnaSearch . "%'" . " OR a.transactionID LIKE '%" . $piKlarnaSearch . "%'" . " OR d.description LIKE '%" . $piKlarnaSearch . "%'" . " OR b.lastname LIKE '%" . $piKlarnaSearch . "%' ";
            }
        }
        $sql = "SELECT DISTINCT
                a.id AS id,
                a.ordertime AS bestellzeit,
                a.ordernumber AS bestellnr,
                a.transactionID AS transaktion,
                a.invoice_amount AS betrag,
                b.lastname AS kunde,
                c.description AS zahlstatus,
                d.description AS bestellstatus,
                e.description AS zahlart,
                f.name AS sprache
            FROM
                s_order AS a
            LEFT JOIN
                s_order_billingaddress b ON a.userID = b.UserID
            LEFT JOIN
                s_core_states c ON a.cleared = c.id
            LEFT JOIN
                s_core_states d ON a.status = d.id
            LEFT JOIN
                s_core_paymentmeans e ON a.paymentID = e.id
            LEFT JOIN
                s_core_multilanguage f ON a.language = f.isocode
            WHERE ".$piKlarnaSearchString."
            ".$piKlarnaZahlString."
            AND
            (
                    a.paymentID = ?
                OR  a.paymentID = ?
            )
            AND a.cleared !='Abgebrochen'
            AND b.orderID = a.id 
            ORDER BY
                a.ordertime desc
            LIMIT ".(int)$piKlarnaStart.",".(int)$piKlarnaLimit."
        ";
        $piKlarnaOrders = Shopware()->Db()->fetchAll($sql, array((int)$piKlarnaInvoiceId, (int)$piKlarnaRateId));
        $piKlarnaStringPosition = strpos($sql, 'LIMIT');
        $piKlarnaText = substr($sql, 0, $piKlarnaStringPosition);       
        $piKlarnaTotal = Shopware()->Db()->fetchAll($piKlarnaText, array((int)$piKlarnaInvoiceId, (int)$piKlarnaRateId));
        for ($i = 0; $i < sizeof($piKlarnaOrders); $i++) {
            $piKlarnaDispatchId = piKlarnaGetDispatchId($piKlarnaOrders[$i]['bestellnr']);
            if ($piKlarnaDispatchId == 0) {
                $piKlarnaOrders[$i]['versand'] = 'Keine Versandkosten';
            }
            else {
                $sql="SELECT name FROM s_premium_dispatch WHERE id  = ?";
                $piKlarnaOrders[$i]['versand'] = Shopware()->Db()->fetchOne($sql,array($piKlarnaDispatchId));
            }
            $sql = "SELECT DISTINCT b.userID
                    FROM s_user_billingaddress a
                    INNER JOIN s_order b on a.userID = b.userID
                    WHERE a.userID = b.userID
                    AND ordernumber = ?";
            $piKlarnaOrders[$i]['userid'] = Shopware()->Db()->fetchOne($sql,array($piKlarnaOrders[$i]['bestellnr']));
            $piKlarnaOrders[$i]['klarnaid'] = $i + 1;
            $piKlarnaOrders[$i]['betrag'] = number_format($piKlarnaOrders[$i]['betrag'], 2, ',', '.');
            $piKlarnaOrders[$i]['options_work'] = '&nbsp;';
            $piKlarnaOrders[$i]['kunde'] = htmlentities($piKlarnaOrders[$i]['kunde'], ENT_COMPAT | ENT_HTML401,'UTF-8');
            $piKlarnaOrders[$i]['bestellstatus_kurz'] = $piKlarnaOrders[$i]['bestellstatus'];
            if($piKlarnaOrders[$i]['bestellstatus']=='Komplett ausgeliefert'){
                $piKlarnaOrders[$i]['bestellstatus']='<span style="color:green">Komplett ausgeliefert</span>';
            }
            elseif($piKlarnaOrders[$i]['bestellstatus']=='Teilweise ausgeliefert'){
                $piKlarnaOrders[$i]['bestellstatus']='<span style="color:orange">Teilweise ausgeliefert</span>';
            }
            $piKlarnaOrders[$i]['options_delete'] = '&nbsp;';
            $klarnaimg="";
            if ($piKlarnaOrders[$i]['zahlart'] == 'Klarna Rechnung') {
                $klarnaimg = $this->View()->fetch('string:{link file=' . var_export( '/engine/Shopware/Plugins/Default/Frontend/PigmbhKlarnaPayment/img/de/KlarnaInvoiceLogoSmall.png', true) . ' fullPath}'); 
            }
            else {
                $klarnaimg = $this->View()->fetch('string:{link file=' . var_export( '/engine/Shopware/Plugins/Default/Frontend/PigmbhKlarnaPayment/img/de/KlarnaRatepayLogoSmall.png', true) . ' fullPath}');
            }
            $piKlarnaOrders[$i]['options_klarna'] = '
                <a class ="pencil myonclick" onclick="orderwindow(' . $piKlarnaOrders[$i]['id'] . ','
                                                                    . $piKlarnaOrders[$i]['bestellnr'] . ',\''
                                                                    . $piKlarnaOrders[$i]['kunde'] . '\')">
                    <img class="Klarna_order_img" src="' . $klarnaimg . '" width="70px";/>
                </a>
            ';
        }
        echo json_encode(array(
            "total" => count($piKlarnaTotal),
            "items" => $piKlarnaOrders
        ));
    }
예제 #2
0
    /**
     *  Displays the Klarna banner
     *
     *  @param Enlight_Event_EventArgs $piKlarnaArgs
     */
    static function piKlarnaOnPostDispatch(Enlight_Event_EventArgs $piKlarnaArgs) {
        $piKlarnaRequest = $piKlarnaArgs->getSubject()->Request();
        $piKlarnaConfig = Shopware()->Plugins()->Frontend()->PigmbhKlarnaPayment()->Config();
        $piKlarnaView = $piKlarnaArgs->getSubject()->View();
        $piKlarnaAction = $piKlarnaRequest->getActionName();
        // break if no template is set.
        if(!$piKlarnaView->hasTemplate()) {
            return;
        }
        $templates = Shopware()->Template()->getTemplateDir();
        $firstTemplate = array_shift($templates);
        $piKlarnaView->_isEmotion = true;
        
        $piKlarnaView->addTemplateDir(dirname(__FILE__) . '/Views/Frontend/');
        if ($piKlarnaRequest->getModuleName() == 'frontend' && $piKlarnaConfig->pi_klarna_active == true) {
            $klarnaShopLang = checkKlarnaCountryCurrencys();
            if ($klarnaShopLang == 'de') $klarnaShopLang = Shopware()->Locale()->getLanguage();
            if ($piKlarnaView->sUserData) $piKlarnaImgPathLocale = strtolower($piKlarnaView->sUserData['additional']['country']['countryiso']);
            else $piKlarnaImgPathLocale = Shopware()->Locale()->getLanguage();
            if ($piKlarnaImgPathLocale == "sv") $piKlarnaImgPathLocale = "se";
            if (!checkKlarnaCountrys($piKlarnaImgPathLocale)) $piKlarnaImgPathLocale = 'de';
            
            $piKlarnaView->piKlarnaImgDir = 'http://' . Shopware()->Config()->Basepath
                    . '/engine/Shopware/Plugins/Default/Frontend/PigmbhKlarnaPayment/img/'
                    . $piKlarnaImgPathLocale
                    . '/';
            $piKlarnaView->piKlarnaShopLang = Shopware()->Locale()->getLanguage();
            $piKlarnaView->piKlarnaShopCurrency = Shopware()->Currency()->getShortName();
            $piKlarnaView->sPaymentErrorMethod = Shopware()->Session()->sPaymentErrorMethod;
            $piKlarnaView->pi_Klarna_lang = piKlarnaGetLanguage(Shopware()->Locale()->getLanguage());
            $piKlarnaView->pi_klarna_shopid = $piKlarnaConfig->pi_klarna_Merchant_ID;
            $sql = "SELECT active FROM s_core_paymentmeans  WHERE name = ?";
            $piKlarnaView->pi_klarna_active = Shopware()->Db()->fetchOne($sql,array('KlarnaInvoice'));
            $piKlarnaView->pi_klarna_rate_active = Shopware()->Db()->fetchOne($sql,array('KlarnaPartPayment'));
            $paymentMeans = Shopware()->Modules()->Admin()->sGetPaymentMeans();
            $allowKlarnaPartPayment = false;
            foreach($paymentMeans as $payment) {
                if('KlarnaPartPayment' == $payment['name']) { 
                    $allowKlarnaPartPayment = true;
                    break;
                }
            }
            if(!$allowKlarnaPartPayment) {
                $piKlarnaView->pi_klarna_rate_active = null;
            }

            
            $piKlarnaView->extendsTemplate('index/header.tpl');
            $piKlarnaUserdata = $piKlarnaView->sUserData;

            if($piKlarnaAction == 'payment' && $piKlarnaRequest->getControllerName() == 'checkout'
                 && ($piKlarnaUserdata["additional"]["payment"]["id"] == piKlarnaGetInvoicePaymentId()
                     || $piKlarnaUserdata["additional"]["payment"]["id"] == piKlarnaGetRatePaymentId())
            ){
            }
            if (($piKlarnaRequest->getControllerName() == 'account' 
                    && ($piKlarnaAction == 'payment' || $piKlarnaAction == 'savePayment' 
                        || $piKlarnaAction == 'saveBilling' || $piKlarnaAction == 'orders' || $piKlarnaAction == 'stornoOrder'))
                    || ($piKlarnaRequest->getControllerName() == 'checkout' 
                            && ($piKlarnaAction == 'confirm' || $piKlarnaAction == 'savePayment' || $piKlarnaAction == 'saveBilling'))
                    || ($piKlarnaRequest->getControllerName() == 'register' 
                            && ($piKlarnaAction == 'confirm' || $piKlarnaAction == 'savePayment' || $piKlarnaAction == 'saveBilling'))
                    || $piKlarnaAction == 'cart'
            ) {
                $piKlarnaCountryIso = getBillingCountry($piKlarnaView->sUserData);
                if ($piKlarnaCountryIso) {
                    $piKlarnaView->piKlarnaCountryIso = $piKlarnaCountryIso;
                    if (!checkKlarnaCurrency(strtolower($piKlarnaCountryIso))) $piKlarnaView->klarnaWrongCurrency = 1;
                }
                $piKlarnaView->KlarnaJS = true;
                $piKlarnaView->extendsTemplate('register/payment_fieldset.tpl');
                if (($piKlarnaAction == 'cart' || $piKlarnaAction == 'confirm' || $piKlarnaAction == 'payment') && $piKlarnaUserdata && checkKlarnaCountrys($klarnaShopLang)) {
                    $k = piKlarnaCreateKlarnaInstance();
                    $k->setCountry($klarnaShopLang);
                    $piKlarnaAmount = Shopware()->Modules()->Basket()->sgetAmount();
                    $piKlarnaSurcharge = piKlarnaGetSurcharge();
                    $piKlarnaBasketAmount = $piKlarnaAmount["totalAmount"];
                    $piKlarnaBasketAmount-= $piKlarnaSurcharge;
                    if ($piKlarnaBasketAmount == null) $piKlarnaBasketAmount = 0;
                    if($piKlarnaBasketAmount){
                        $pClass = $k->getCheapestPClass($piKlarnaBasketAmount, KlarnaFlags::CHECKOUT_PAGE);
                        if ($pClass) {
                            $piKlarnaView->pi_klarna_rateAmount = number_format(KlarnaCalc::calc_monthly_cost(
                                            $piKlarnaBasketAmount, 
                                            $pClass, 
                                            KlarnaFlags::CHECKOUT_PAGE), 2, ',', '.');
                            $piKlarnaView->pi_klarna_sum = $piKlarnaBasketAmount;
                            if ($piKlarnaCountryIso == "NO") {
                                $piKlarnaView->NorwayTotalCost = number_format(KlarnaCalc::total_credit_purchase_cost($piKlarnaBasketAmount, $pClass, 1), 2, ',', '.');
                                $piKlarnaView->NorwayAprCost = number_format(KlarnaCalc::apr_annuity(intval($piKlarnaBasketAmount), intval($pClass->getMonths()), $pClass->getInvoiceFee(), $pClass->getInterestRate(), $pClass->getStartFee(), 1), 2, ',', '.');
                            }
                            if ($piKlarnaConfig->pi_klarna_rate_checkout == true && $piKlarnaAction == 'confirm') $piKlarnaView->extendsTemplate('checkout/confirm_footer.tpl');
                            elseif (($piKlarnaAction == 'cart' || $piKlarnaRequest->sTargetAction == 'cart') && $piKlarnaConfig->pi_klarna_rate_cart == true) $piKlarnaView->extendsTemplate('checkout/cart_footer.tpl');
                            $piKlarnaView->RateIsTrue = true;
                        }
                    }
                }

                if ($piKlarnaAction == 'confirm' || $piKlarnaAction == 'payment') {
                    
                    $piKlarnaSurcharge = piKlarnaGetInvoiceSurcharge($piKlarnaUserdata);
                    if ($piKlarnaUserdata["additional"]["payment"]["id"] == piKlarnaGetInvoicePaymentId()
                            || $piKlarnaUserdata["additional"]["payment"]["id"] == piKlarnaGetRatePaymentId()
                    ) {
                        $piKlarnaUserdata["additional"]["payment"]["embediframe"] = true;
                        $piKlarnaView->sUserData = $piKlarnaUserdata;
                    }
                    if ($piKlarnaAction == 'confirm') {
                         if(Shopware()->Session()->klarnaAgb == true){
                             if(Shopware()->Session()->klarnaAgbChecked){
                                 $piKlarnaView->agbChecked = true;
                             }else{
                                 $piKlarnaView->agbChecked = false;
                             }
                             $piKlarnaView->piKlarnaError = true;
                             Shopware()->Session()->klarnaAgb =false;
                         }    
                         if (Shopware()->Session()->klarnaStandardAgb == true) {
                             if(Shopware()->Session()->klarnaStandardAgbChecked){
                                 $piKlarnaView->standardAgbChecked = true;
                             }else{
                                 $piKlarnaView->standardAgbChecked = false;
                             }
                             $piKlarnaView->sError = true;
                             Shopware()->Session()->klarnaStandardAgb =false;
                         } 
                         Shopware()->Session()->klarnaAgbChecked = false;
                         Shopware()->Session()->klarnaStandardAgbChecked = false;
                    }
                    $piKlarnaView->pi_klarna_surcharge = $piKlarnaSurcharge;
                    $piKlarnaResult = piKlarnaCheckBillingEqalShipping($piKlarnaUserdata);
                    if (Shopware()->Session()->sPaymentError) {
                        $piKlarnaView->piKlarnaSesssionWarning = true;
                        $piKlarnaView->PigmbhKlarnaPaymentInvoiceWarningText = Shopware()->Session()->sPaymentError;
                        $piKlarnaView->PigmbhKlarnaPaymentRateWarningText = Shopware()->Session()->sPaymentError;
                    }
                    if (Shopware()->Session()->klarnaDenied) $piKlarnaView->klarnaDenied = true;
                    if (($piKlarnaUserdata["billingaddress"]["company"] || $piKlarnaUserdata["shippingaddress"]["company"]) && ($piKlarnaCountryIso == "DE" || $piKlarnaCountryIso == "NL")) {
                        $piKlarnaView->sCompanyError = true;
                        $piKlarnaView->PigmbhKlarnaPaymentInvoiceWarningText = $piKlarnaView->pi_Klarna_lang['invoice']['companyerror'];
                        $piKlarnaView->PigmbhKlarnaPaymentRateWarningText = $piKlarnaView->pi_Klarna_lang['rate']['companyerror'];
                        $piKlarnaView->sPaymentRegisterError = true;
                    }
                    if ($piKlarnaUserdata["billingaddress"]["birthday"] == "0000-00-00" && ($piKlarnaCountryIso != "DK" && $piKlarnaCountryIso != "NO" && $piKlarnaCountryIso != "FI" && $piKlarnaCountryIso != "SE")) {
                        $piKlarnaView->PigmbhKlarnaPaymentInvoiceWarningText = $piKlarnaView->pi_Klarna_lang['invoice']['birthdayerror'];
                        $piKlarnaView->PigmbhKlarnaPaymentRateWarningText = $piKlarnaView->pi_Klarna_lang['rate']['birthdayerror'];
                        $piKlarnaView->sPaymentRegisterError = true;
                    }
                    if (count($piKlarnaResult) && !$piKlarnaArgs->getSubject()->View()->sCompanyError) {
                        $piKlarnaView->sAddressError = true;
                        $piKlarnaInvoiceError = str_replace("{_COUNTRYNAME_}", $piKlarnaView->pi_Klarna_lang['countryName'][$piKlarnaCountryIso], $piKlarnaView->pi_Klarna_lang['invoice']['addresserror']);
                        $piKlarnaRatepayError = str_replace("{_COUNTRYNAME_}", $piKlarnaView->pi_Klarna_lang['countryName'][$piKlarnaCountryIso], $piKlarnaView->pi_Klarna_lang['rate']['addresserror']);
                        $piKlarnaView->PigmbhKlarnaPaymentInvoiceWarningText = $piKlarnaInvoiceError;
                        $piKlarnaView->PigmbhKlarnaPaymentRateWarningText = $piKlarnaRatepayError;
                        $piKlarnaView->sPaymentRegisterError = true;
                    }
                    elseif (!$piKlarnaUserdata["billingaddress"]["text4"] && !Shopware()->Session()->sPaymentError 
                            && ($piKlarnaCountryIso == "DK" || $piKlarnaCountryIso == "NO" || $piKlarnaCountryIso == "FI" || $piKlarnaCountryIso == "SE")) {
                        $piKlarnaInvoiceError = str_replace("{_COUNTRYNAME_}", $piKlarnaView->pi_Klarna_lang['countryName'][$piKlarnaCountryIso], $piKlarnaView->pi_Klarna_lang['invoice']['skanderror']);
                        $piKlarnaRatepayError = str_replace("{_COUNTRYNAME_}", $piKlarnaView->pi_Klarna_lang['countryName'][$piKlarnaCountryIso], $piKlarnaView->pi_Klarna_lang['rate']['skanderror']);
                        if ($piKlarnaView->PigmbhKlarnaPaymentInvoiceWarningText != '') $piKlarnaView->PigmbhKlarnaPaymentInvoiceWarningText.='<br />';
                        if ($piKlarnaView->PigmbhKlarnaPaymentRateWarningText != '') $piKlarnaView->PigmbhKlarnaPaymentRateWarningText.='<br />';
                        $piKlarnaView->PigmbhKlarnaPaymentInvoiceWarningText.=$piKlarnaInvoiceError;
                        $piKlarnaView->PigmbhKlarnaPaymentRateWarningText.=$piKlarnaRatepayError;
                        $piKlarnaView->sPaymentRegisterError = true;
                    }
                    if (!$piKlarnaView->RateIsTrue) {
                        $piKlarnaView->PigmbhKlarnaPaymentRateWarningText = $piKlarnaView->pi_Klarna_lang['rate']['noPclass'];
                    }
                    $piKlarnaView->pi_klarna_viewport = $piKlarnaArgs->getSubject()->Request()->sViewport;
                    $piKlarnaView->pi_klarna_actions = $piKlarnaArgs->getSubject()->Request()->getActionName();
                    if ($piKlarnaUserdata["additional"]["payment"]["name"] == "KlarnaInvoice"
                            || $piKlarnaUserdata["additional"]["payment"]["name"] == "KlarnaPartPayment"
                    ) {
                        $piKlarnaView->extendsTemplate('checkout/confirm.tpl');
                    }
                }
            }
           
            if (($piKlarnaAction == 'billing') && $piKlarnaConfig->pi_klarna_active && $piKlarnaRequest->sViewport == 'account') {
                $piKlarnaCountryIso = getBillingCountry($piKlarnaView->sUserData);
                $piKlarnaView->piKlarnaCountryIso = $piKlarnaCountryIso;
                $piKlarnaView->extendsTemplate('register/personal_fieldset.tpl');
            }
            if (($piKlarnaAction == 'orders' || $piKlarnaAction == 'stornoOrder') && $piKlarnaConfig->pi_klarna_active) {
                $piKlarnaView->klarnaStatusIds = piKlarnaGetAllStatusIds();
                piKlarnaCheckPendingOrders();
                $piKlarnaView->extendsTemplate(dirname(__FILE__) . '/Views/Frontend/account/order_item.tpl');
                $PigmbhKlarnaPaymentIds = piKlarnaGetPaymentIds();
                $piKlarnaArgs->getSubject()->View()->pi_klarna_invoice_ids = $PigmbhKlarnaPaymentIds;
            }
            $piKlarnaGetPost = $piKlarnaArgs->getSubject()->Request()->getPost();
            if (isset($piKlarnaGetPost['KlarnaSubmit']) || $piKlarnaAction == 'saveBilling') {
                $piKlarnaConfig = Shopware()->Plugins()->Frontend()->PigmbhKlarnaPayment()->Config();
                $piKlarnaInvoiceId = piKlarnaGetInvoicePaymentId();
                $piKlarnaRateId = piKlarnaGetRatePaymentId();
                if ($piKlarnaConfig->pi_klarna_active == true && ($piKlarnaGetPost['KlarnaSubmit'] || $piKlarnaAction == 'saveBilling')) {
                    $piKlarnaResponse = array();
                    $textVar = false;
                    $piKlarnaUserdata = $piKlarnaArgs->getSubject()->View()->sUserData;
                    $piKlarnaResponse = $piKlarnaArgs->getSubject()->Response();
                    $piKlarnaRequest = $piKlarnaArgs->getSubject()->Request();
                    $piKlarnaResult = piKlarnaCheckBillingEqalShipping($piKlarnaUserdata);
                    if ($piKlarnaGetPost['klarnaRegister']['personal']['additional']) {
                        $textVar = "";
                        $invoiceFlag = boolean;
                        $textVar = $piKlarnaGetPost['klarnaRegister']['personal']['additional'];
                        $invoiceFlag = true;
                    }
                    elseif ($piKlarnaGetPost['klarnaRegister']['personal']['additionalRate']){
                        $textVar = $piKlarnaGetPost['klarnaRegister']['personal']['additionalRate'];
                    }
                    if ($textVar) {
                        $sql = "INSERT INTO s_user_billingaddress_attributes (billingID, text4) VALUES (?, ?) ON DUPLICATE KEY UPDATE text4=VALUES(text4)";
//                        $sql = "UPDATE s_user_billingaddress SET text4 = ? WHERE ID= ?";
                        Shopware()->Db()->query($sql, array($textVar, (int)$piKlarnaUserdata['billingaddress']['id']));
                    }
                    $piKlarnaArgs->getSubject()->View()->pi_klarna_selectedPayment = $piKlarnaUserdata['additional']['payment']['name'];
                    $piKlarnaBirthday = $piKlarnaGetPost['klarnaRegister']['personal']['birthyear'] . "-"
                            . $piKlarnaGetPost['klarnaRegister']['personal']['birthmonth'] . "-"
                            . $piKlarnaGetPost['klarnaRegister']['personal']['birthday'];
                    if ($piKlarnaBirthday == '--') {
                        $piKlarnaBirthday = $piKlarnaGetPost['klarnaRegister']['personal']['birthyearRate'] . "-"
                                . $piKlarnaGetPost['klarnaRegister']['personal']['birthmonthRate'] . "-"
                                . $piKlarnaGetPost['klarnaRegister']['personal']['birthdayRate'];
                    }
                    else $invoiceFlag = true;
                    if ($piKlarnaBirthday != '--') {
                        $sql = " UPDATE s_user_billingaddress SET birthday = ? WHERE ID = ?";
                        Shopware()->Db()->query($sql, array($piKlarnaBirthday, (int)$piKlarnaUserdata['billingaddress']['id']));
                    }
                    if ($invoiceFlag) $piKlarnaId = $piKlarnaInvoiceId;
                    else $piKlarnaId = $piKlarnaRateId;
                    if (($piKlarnaUserdata['additional']['country']['countryiso'] == 'NL' && $piKlarnaBirthday != '--' 
                        && !$piKlarnaUserdata["billingaddress"]["company"] && !$piKlarnaUserdata["shippingaddress"]["company"])
                        || ($piKlarnaUserdata['additional']['country']['countryiso'] == 'DE' && $piKlarnaBirthday != '--' 
                                && !$piKlarnaUserdata["billingaddress"]["company"] && !$piKlarnaUserdata["shippingaddress"]["company"])
                        && (count($piKlarnaResult)
                        && $piKlarnaAction != 'saveBilling')
                    ) {
                        $sql = "UPDATE s_user SET paymentID = ? WHERE id= ?";
                        Shopware()->Db()->query($sql, array((int)$piKlarnaId, (int)$piKlarnaUserdata['billingaddress']['id']));
                    }
                    elseif ($textVar && count($piKlarnaResult)) {
                        $sql = "UPDATE s_user SET paymentID = ? WHERE id= ?";
                        Shopware()->Db()->query($sql, array((int)$piKlarnaId, (int)$piKlarnaUserdata['billingaddress']['id']));
                    }
                }
            }
            $piKlarnaResponse = $piKlarnaArgs->getSubject()->Response();
            if ($piKlarnaConfig->piKlarnaShowBannerOnStartpage
                    && (!$piKlarnaRequest->isDispatched()
                    || $piKlarnaResponse->isException()
                    || $piKlarnaRequest->getModuleName() != 'frontend'
                    || $piKlarnaRequest->getControllerName() != 'index'
                    )) return;
            elseif (!$piKlarnaConfig->piKlarnaShowBannerOnStartpage
                    && (!$piKlarnaRequest->isDispatched()
                    || $piKlarnaResponse->isException()
                    || $piKlarnaRequest->getModuleName() != 'frontend'
                    )) return;
            $piKlarnaView->piKlarnaConfig = $piKlarnaConfig;
            $piKlarnaView->extendsTemplate('index/left.tpl');
            $piKlarnaView->extendsTemplate('home/right.tpl');
            $piKlarnaView->extendsTemplate('index/index.tpl');
        }
    }