예제 #1
0
 function pdf()
 {
     exit("deactivated for now...");
     if ($ID = Director::urlParam("ID")) {
         if ($invoice = DataObject::get_one("ShopInvoice", "PublicURL = '" . Convert::Raw2SQL($ID) . "'")) {
             $this->Invoice = $invoice;
             if (!isset($_REQUEST['view'])) {
                 //generate pdf
                 require dirname(__FILE__) . '/Thirdparty/html2fpdf/html2fpdf.php';
                 //to get work HTML2PDF
                 error_reporting(E_ALL ^ (E_NOTICE | E_DEPRECATED));
                 $pdf = new HTML2FPDF();
                 $pdf->AddPage();
                 $pdfPath = $invoice->generatePDF();
                 $outputPath = TEMP_FOLDER . "/shopsystem/";
                 $outputFile = $outputPath . $invoice->PublicURL . ".pdf";
                 $fp = fopen($pdfPath, "r");
                 $strContent = fread($fp, filesize($pdfPath));
                 fclose($fp);
                 $pdf->WriteHTML($strContent);
                 $pdf->Output($outputFile);
                 header('Content-type: application/pdf');
                 header('Content-Disposition: attachment; filename="invoice.pdf"');
                 echo file_get_contents($outputFile);
                 //PDF file is generated successfully!
                 exit;
             }
             if (isset($_REQUEST['remove'])) {
                 //remove invoice from public by generating a new public url
                 $invoice->PublicURL = ShopInvoice::generatePublicURL();
                 $invoice->write();
             }
         }
     }
     return array();
 }
예제 #2
0
 function complete()
 {
     $this->setCheckoutStep(0);
     $session = ShopOrder::orderSession();
     $this->OrderIsPlaced = false;
     if ($session->isComplete()) {
         if ($session->Status == "Ordered") {
             //order already placed
             Director::redirect($this->dataRecord->Link() . "already_placed");
             return array();
         }
         $session->Status = "Ordered";
         $session->OrderKey = $session->generateOrderKey();
         $session->PlacedOrderOn = time();
         //remove all items from order, where quantity not > 0
         if ($items = $session->Items()) {
             foreach ($items as $item) {
                 if (!($item->Quantity > 0)) {
                     $item->delete();
                 }
             }
         }
         $session->Payment()->Price = $session->Total;
         $session->Payment()->write();
         if ($session->Items()) {
             foreach ($session->Items() as $item) {
                 if ($orgItem = $item->OriginalItem()) {
                     //if quantity in stock is 0 -> leave 0 and don't decrement
                     $orgItem->StockQuantity = $orgItem->StockQuantity - $item->Quantity;
                     $orgItem->OrderCount++;
                     $orgItem->writeToStage('Stage');
                     $orgItem->publish('Stage', 'Live');
                 }
             }
         }
         $session->calculateAndWrite();
         $session->write();
         //create invoice
         $invoice = new ShopInvoice();
         $invoice->PublicURL = ShopInvoice::generatePublicURL();
         $invoice->OrderID = $session->ID;
         $invoice->DateOfDelivery = null;
         $invoice->DateOfInvoice = time();
         //increment invoicekey if exists, otherwise use the id
         if ($lastInvoice = DataObject::get_one("ShopInvoice", null, null, "ID DESC")) {
             $invoice->InvoiceKey = (int) preg_replace('/\\D+/', '', $lastInvoice->InvoiceKey) + 1;
         } else {
             $invoice->InvoiceKey = $invoice->ID;
         }
         $invoice->write();
         $session->InvoiceID = $invoice->ID;
         $session->write();
         $this->OrderIsPlaced = true;
         $this->Order = $session;
         $session->sendOrderConfirmation();
         //to customer
         $session->sendOrderConfirmation(ShopOrder::getEmailFor("OrderConfirmation"));
         //to shop admin
         //send email with invoice link?!
         return array();
     } else {
         Director::redirect($this->dataRecord->Link() . "incomplete");
         return array();
     }
 }