Exemplo n.º 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
        ));
    }
Exemplo n.º 2
0
 /**
  * Plugin unistall method
  *
  * @return	bool
  */
 public function uninstall() {
     try {
         $piKlarnaInvoiceId = piKlarnaGetInvoicePaymentId();
         $piKlarnaRateId = piKlarnaGetRatePaymentId();
         $piKlarnaPluginId = piKlarnaGetPluginId();
         $sql = "DELETE FROM s_core_rulesets WHERE paymentID = ? OR paymentID = ?";
         Shopware()->Db()->query($sql, array((int)$piKlarnaInvoiceId, (int)$piKlarnaRateId));
         $sql = "DELETE FROM s_core_paymentmeans WHERE name IN ('KlarnaInvoice','KlarnaPartPayment')";
         Shopware()->Db()->query($sql);
         $sql = "DELETE FROM s_core_states
                 WHERE description IN
                 (
                     '<span style=\"color:orange\">Zahlung wird von Klarna gepr&uuml;ft</span>',
                     '<span style=\"color:green\">Zahlung von Klarna akzeptiert</span>',
                     '<span style=\"color:red\">Zahlung von Klarna nicht akzeptiert</span>',
                     '<span style=\"color:red\">Reservierung abgebrochen</span>',
                     '<span style=\"color:orange\">Reservierung teilweise aktiviert</span>',
                     '<span style=\"color:green\">Reservierung komplett aktiviert</span>',
                     '<span style=\"color:orange\">Teilweise retourniert</span>',
                     '<span style=\"color:red\">Komplett retourniert</span>',
                     '<span style=\"color:orange\">Teilweise storniert</span>',
                     '<span style=\"color:red\">Komplett storniert</span>'
                 )";    
         Shopware()->Db()->query($sql);
         return parent::uninstall();
     }
     catch (Exception $e) {
         throw new Exception('Fehler beim deinstallieren(uninstall)');
     }
     return true;
 }