OXID eShop CE  4.9.6
 All Classes Files Functions Variables Pages
order_overview.php
Go to the documentation of this file.
1 <?php
2 
9 {
10 
18  public function render()
19  {
20  $myConfig = $this->getConfig();
22 
23  $oOrder = oxNew("oxOrder");
24  $oCur = $myConfig->getActShopCurrencyObject();
25  $oLang = oxRegistry::getLang();
26 
27  $soxId = $this->getEditObjectId();
28  if ($soxId != "-1" && isset($soxId)) {
29  // load object
30  $oOrder->load($soxId);
31 
32  $this->_aViewData["edit"] = $oOrder;
33  $this->_aViewData["aProductVats"] = $oOrder->getProductVats();
34  $this->_aViewData["orderArticles"] = $oOrder->getOrderArticles();
35  $this->_aViewData["giftCard"] = $oOrder->getGiftCard();
36  $this->_aViewData["paymentType"] = $this->_getPaymentType($oOrder);
37  $this->_aViewData["deliveryType"] = $oOrder->getDelSet();
38  $sTsProtectsField = 'oxorder__oxtsprotectcosts';
39  if ($oOrder->$sTsProtectsField->value) {
40  $this->_aViewData["tsprotectcosts"] = $oLang->formatCurrency($oOrder->$sTsProtectsField->value, $oCur);
41  }
42  }
43 
44  // orders today
45  $dSum = $oOrder->getOrderSum(true);
46  $this->_aViewData["ordersum"] = $oLang->formatCurrency($dSum, $oCur);
47  $this->_aViewData["ordercnt"] = $oOrder->getOrderCnt(true);
48 
49  // ALL orders
50  $dSum = $oOrder->getOrderSum();
51  $this->_aViewData["ordertotalsum"] = $oLang->formatCurrency($dSum, $oCur);
52  $this->_aViewData["ordertotalcnt"] = $oOrder->getOrderCnt();
53  $this->_aViewData["afolder"] = $myConfig->getConfigParam('aOrderfolder');
54  $this->_aViewData["alangs"] = $oLang->getLanguageNames();
55 
56  $this->_aViewData["currency"] = $oCur;
57 
58  return "order_overview.tpl";
59  }
60 
70  protected function _getPaymentType($oOrder)
71  {
72  if (!($oUserPayment = $oOrder->getPaymentType()) && $oOrder->oxorder__oxpaymenttype->value) {
73  $oPayment = oxNew("oxPayment");
74  if ($oPayment->load($oOrder->oxorder__oxpaymenttype->value)) {
75  // in case due to security reasons payment info was not kept in db
76  $oUserPayment = oxNew("oxUserPayment");
77  $oUserPayment->oxpayments__oxdesc = new oxField($oPayment->oxpayments__oxdesc->value);
78  }
79  }
80 
81  return $oUserPayment;
82  }
83 
87  public function exportlex()
88  {
89  $sOrderNr = oxRegistry::getConfig()->getRequestParameter("ordernr");
90  $sToOrderNr = oxRegistry::getConfig()->getRequestParameter("toordernr");
91  $oImex = oxNew("oximex");
92  if (($sLexware = $oImex->exportLexwareOrders($sOrderNr, $sToOrderNr))) {
93  $oUtils = oxRegistry::getUtils();
94  $oUtils->setHeader("Pragma: public");
95  $oUtils->setHeader("Cache-Control: must-revalidate, post-check=0, pre-check=0");
96  $oUtils->setHeader("Expires: 0");
97  $oUtils->setHeader("Content-type: application/x-download");
98  $oUtils->setHeader("Content-Length: " . strlen($sLexware));
99  $oUtils->setHeader("Content-Disposition: attachment; filename=intern.xml");
100  $oUtils->showMessageAndExit($sLexware);
101  }
102  }
103 
111  public function makeValidFileName($sFilename)
112  {
113  $sFilename = preg_replace('/[\s]+/', '_', $sFilename);
114  $sFilename = preg_replace('/[^a-zA-Z0-9_\.-]/', '', $sFilename);
115 
116  return str_replace(' ', '_', $sFilename);
117  }
118 
124  public function createPDF()
125  {
126  $soxId = $this->getEditObjectId();
127  if ($soxId != "-1" && isset($soxId)) {
128  // load object
129  $oOrder = oxNew("oxorder");
130  if ($oOrder->load($soxId)) {
131  $oUtils = oxRegistry::getUtils();
132  $sTrimmedBillName = trim($oOrder->oxorder__oxbilllname->getRawValue());
133  $sFilename = $oOrder->oxorder__oxordernr->value . "_" . $sTrimmedBillName . ".pdf";
134  $sFilename = $this->makeValidFileName($sFilename);
135  ob_start();
136  $oOrder->genPDF($sFilename, oxRegistry::getConfig()->getRequestParameter("pdflanguage"));
137  $sPDF = ob_get_contents();
138  ob_end_clean();
139  $oUtils->setHeader("Pragma: public");
140  $oUtils->setHeader("Cache-Control: must-revalidate, post-check=0, pre-check=0");
141  $oUtils->setHeader("Expires: 0");
142  $oUtils->setHeader("Content-type: application/pdf");
143  $oUtils->setHeader("Content-Disposition: attachment; filename=" . $sFilename);
144  oxRegistry::getUtils()->showMessageAndExit($sPDF);
145  }
146  }
147  }
148 
149 
153  public function sendorder()
154  {
155  $oOrder = oxNew("oxorder");
156  if ($oOrder->load($this->getEditObjectId())) {
157  $oOrder->oxorder__oxsenddate = new oxField(date("Y-m-d H:i:s", oxRegistry::get("oxUtilsDate")->getTime()));
158  $oOrder->save();
159 
160  // #1071C
161  $oOrderArticles = $oOrder->getOrderArticles();
162  foreach ($oOrderArticles as $sOxid => $oArticle) {
163  // remove canceled articles from list
164  if ($oArticle->oxorderarticles__oxstorno->value == 1) {
165  $oOrderArticles->offsetUnset($sOxid);
166  }
167  }
168 
169  if (($blMail = oxRegistry::getConfig()->getRequestParameter("sendmail"))) {
170  // send eMail
171  $oEmail = oxNew("oxemail");
172  $oEmail->sendSendedNowMail($oOrder);
173  }
174  }
175  }
176 
180  public function resetorder()
181  {
182  $oOrder = oxNew("oxorder");
183  if ($oOrder->load($this->getEditObjectId())) {
184  $oOrder->oxorder__oxsenddate = new oxField("0000-00-00 00:00:00");
185  $oOrder->save();
186  }
187  }
188 
194  public function canExport()
195  {
196  $blCan = false;
197  //V #529: check if PDF invoice module is active
198  $oModule = oxNew('oxmodule');
199  $oModule->load('invoicepdf');
200  if ($oModule->isActive()) {
201  $oDb = oxDb::getDb();
202  $sOrderId = $this->getEditObjectId();
203  $sTable = getViewName("oxorderarticles");
204  $sQ = "select count(oxid) from {$sTable} where oxorderid = " . $oDb->quote($sOrderId) . " and oxstorno = 0";
205  $blCan = (bool) $oDb->getOne($sQ, false, false);
206  }
207 
208  return $blCan;
209  }
210 
216  public function canResetShippingDate()
217  {
218  $oOrder = oxNew("oxorder");
219  $blCan = false;
220  if ($oOrder->load($this->getEditObjectId())) {
221  $blCan = $oOrder->oxorder__oxstorno->value == "0" &&
222  !($oOrder->oxorder__oxsenddate->value == "0000-00-00 00:00:00" || $oOrder->oxorder__oxsenddate->value == "-");
223  }
224 
225  return $blCan;
226  }
227 }