Example #1
0
 /**
  * end action method handles payment confirm and saves order
  */
 public function endAction()
 {
     $config = Shopware()->Plugins()->Frontend()->PigmbhRatePAYPayment()->Config();
     $secret = $this->getPaymentShortName() == 'RatePAYInvoice'?  $config->security_code: $config->security_code_rate;
     $transactionId = Shopware()->Session()->pi_ratepay_transactionID;
     $hash = $secret . $transactionId;
     $this->saveOrder($transactionId, $hash);
     $sql = "SELECT `ordernumber` FROM `s_order` WHERE `transactionID` = ?";
     $this->ordernumber = Shopware()->Db()->fetchOne($sql, array($transactionId));
     $sql = "SELECT `id` FROM `s_order` WHERE `transactionID` = ?";
     $this->orderId = Shopware()->Db()->fetchOne($sql, array($transactionId));
     Shopware()->Session()->pi_ratepay_ordernumber = $this->ordernumber;
     if ($this->getPaymentShortName() == 'RatePAYRate') $this->saveRateDetails();
     historyEntry($this->ordernumber, '<b class=\"green\">Bestellung ist eingegangen</b>', '', '', '');
     $this->saveRatepayDetails();
     $this->saveStats(true);
     $this->saveOrderDetails();
     $this->saveShippingCosts();
     $sql = "UPDATE `s_order` SET `cleared` = ? WHERE `ordernumber` = ?";
     Shopware()->Db()->query($sql, array((int)getAcceptedStatusId(), $this->ordernumber));
     $this->redirect(array('controller' => 'checkout', 'action' => 'finish', 'sUniqueID' => $hash, 'forceSecure' => true));
 }
Example #2
0
 /**
  * Returns articles from the order. Delivers a JSON String with article details
  *
  * @see templates/backend/plugins/PigmbhRatePAYPayment/index.php
  * @throws RatePAYException
  */
 public function returnArticlesAction()
 {
     $this->View()->setTemplate();
     $articlenr = explode(";", $this->Request()->articlenr);
     $quantity = explode(";", $this->Request()->anzahl);
     $orderNumber = $this->Request()->myordernumber;
     $completeQuantity = 0;
     $articles = array();
     $myerror = array('error' => false, 'errormessage' => 'Fehler beim retournieren der Artikel');
     $sql = "SELECT SUM(anzahl-storniert-retourniert) FROM pi_ratepay_order_detail WHERE ordernumber = ?";
     $articlesquantity = Shopware()->Db()->fetchOne($sql, array($orderNumber));
     $allarticles = $this->_getArticlesByOrderNumber($orderNumber);
     for ($counter = 0; $counter < sizeof($articlenr); $counter++) {
         for ($j = 0; $j < sizeof($allarticles); $j++) {
             if ($articlenr[$counter] == $allarticles[$j]['bestell_nr']) {
                 $allarticles[$j]['retourniert'] = $allarticles[$j]['retourniert'] + $quantity[$counter];
                 $allarticles[$j]['geliefert'] = $allarticles[$j]['geliefert'] - $quantity[$counter];
                 $allarticles[$j]['anzahl'] = $quantity[$counter];
             }
         }
         $completeQuantity+=$quantity[$counter];
     }
     $totalreturn = 0;
     $totalordered = 0;
     for ($counter = 0; $counter < sizeof($allarticles); $counter++) {
         $articles[$counter]['name'] = $allarticles[$counter]['name'];
         $articles[$counter]['geliefert'] = $allarticles[$counter]['geliefert'];
         $articles[$counter]['bestellt'] = $allarticles[$counter]['bestellt'];
         $articles[$counter]['storniert'] = $allarticles[$counter]['storniert'];
         $articles[$counter]['anzahl'] = $allarticles[$counter]['anzahl'];
         $articles[$counter]['quantity'] = $allarticles[$counter]['bestellt'];
         $articles[$counter]['offen'] = $allarticles[$counter]['offen'];
         $articles[$counter]['retourniert'] = $allarticles[$counter]['retourniert'];
         $articles[$counter]['bestellt'] = $allarticles[$counter]['bestellt'];
         $articles[$counter]['einzelpreis'] = $allarticles[$counter]['einzelpreis'];
         $articles[$counter]['bestellnr'] = $allarticles[$counter]['bestell_nr'];
         $articles[$counter]['ordernumber'] = $allarticles[$counter]['bestell_nr'];
         $articles[$counter]['einzelpreis_net'] = $allarticles[$counter]['einzelpreis_net'];
         $totalreturn+=$articles[$counter]['retourniert'];
         $totalordered+=$articles[$counter]['bestellt'];
     }
     if (sizeof($articlenr) > 0) {
         $articlesquantity == $completeQuantity? $subtype='full-return': $subtype='partial-return';
         try {
             $myerror['error'] = paymentChange($orderNumber, $articles, $subtype);
         } catch (Exception $e) {
             $myerror['error'] = false;
             $myerror['errormessage'] = $e->getMessage() . " (#" . $e->getCode() . ")";
             echo json_encode(array("items" => $myerror));
         }
         if ($myerror['error'] == true) {
             $sql = "UPDATE `pi_ratepay_orders` SET `invoice_number` ='<span class=\'red\'>Rechnung ist nicht aktuell.</span>'
                     WHERE order_number = ?";
             Shopware()->Db()->query($sql, array($orderNumber));
             for ($counter = 0; $counter < sizeof($articlenr); $counter++) {
                 if ($quantity[$counter] > 0) {
                     $sql = "SELECT retourniert FROM pi_ratepay_order_detail WHERE ordernumber = ? AND bestell_nr = ?";
                     $returned = Shopware()->Db()->fetchOne($sql, array($orderNumber, $articlenr[$counter]));
                     $sql = "SELECT geliefert FROM pi_ratepay_order_detail WHERE ordernumber = ? AND bestell_nr = ?";
                     $delivered = Shopware()->Db()->fetchOne($sql, array($orderNumber, $articlenr[$counter]));
                     $sql = "UPDATE pi_ratepay_order_detail SET retourniert = ?, geliefert= ? WHERE ordernumber = ? AND bestell_nr = ?";
                     Shopware()->Db()->query($sql, array(
                         $returned + (int)$quantity[$counter],
                         $delivered - (int)$quantity[$counter],
                         $orderNumber,
                         $articlenr[$counter]
                     ));
                     $sql = "UPDATE pi_ratepay_order_detail SET gesamtpreis = geliefert * einzelpreis
                             WHERE ordernumber = ? AND bestell_nr = ?";
                     Shopware()->Db()->query($sql, array(
                         $orderNumber,
                         $articlenr[$counter]
                     ));
                     $sql = "SELECT * FROM s_order_details WHERE ordernumber = ? AND articleordernumber = ?";
                     $ratepayOrder= Shopware()->Db()->fetchRow($sql, array($orderNumber, $articlenr[$counter]));
                     if (($ratepayOrder['quantity'] - $quantity[$counter]) > 0) {
                         $sql = "SELECT quantity FROM s_order_details WHERE ordernumber = ? AND articleordernumber = ?";
                         $quant = Shopware()->Db()->fetchOne($sql, array($orderNumber, $articlenr[$counter]));
                         $sql = "UPDATE s_order_details SET quantity = ? WHERE ordernumber = ? AND articleordernumber = ?";
                         $newQuant = $quant - (int)$quantity[$counter];
                         Shopware()->Db()->query($sql, array($newQuant, $orderNumber, $articlenr[$counter]));
                     } else {
                         $sql = "DELETE FROM s_order_details WHERE ordernumber = ? AND articleordernumber = ?";
                         Shopware()->Db()->query($sql, array($orderNumber, $articlenr[$counter]));
                     }
                     $sql = "SELECT * FROM pi_ratepay_order_detail WHERE ordernumber = ? AND bestell_nr = ?";
                     $ratepayOwnOrder= Shopware()->Db()->fetchRow($sql, array($orderNumber, $articlenr[$counter]));
                     if ($ratepayOwnOrder['bestellt'] == $ratepayOwnOrder['retourniert']) {
                         $sql = "UPDATE pi_ratepay_order_detail SET versandstatus= ? WHERE ordernumber = ? AND bestell_nr= ?";
                         Shopware()->Db()->query($sql, array((int)getCompleteReturnStatusId(), $orderNumber, $articlenr[$counter]));
                     }
                     if ($ratepayOwnOrder['name'] == 'Versandkosten') {
                         $sql = "UPDATE s_order SET invoice_shipping = ?, invoice_shipping_net = ?, dispatchID = ? WHERE ordernumber = ?";
                         Shopware()->Db()->query($sql, array((double)0, (double)0, (int)0, $orderNumber));
                     }
                     $sql = " SELECT name FROM pi_ratepay_order_detail WHERE ordernumber = ? AND bestell_nr = ?";
                     $myarticlename = Shopware()->Db()->fetchOne($sql, array($orderNumber, $articlenr[$counter]));
                     $myarticlename = str_replace("'", "\'", $myarticlename);
                     historyEntry($orderNumber, "<span class=\"red\">Artikel retourniert</span>", $myarticlename, $articlenr[$counter] , $quantity[$counter]);
                 }
             }
         }
     }
     berechneGesamtpreis($orderNumber);
     $sql = "SELECT invoice_amount FROM s_order WHERE ordernumber = ?";
     $orderamount = Shopware()->Db()->fetchOne($sql, array($orderNumber));
     if ($orderamount == 0) {
         setOrderState($orderNumber, getCompleteReturnStatusId());
         historyEntry($orderNumber, "<b class=\"red\">Bestellung vollst&auml;ndig retourniert</b>", "" , "" , "");
     }
     echo json_encode(array("items" => $myerror, "articlesquantity" => $articlesquantity));
 }