OXID eShop CE  4.9.8
 All Classes Files Functions Variables Pages
order_main.php
Go to the documentation of this file.
1 <?php
2 
9 {
15  protected $fieldsTriggerNoOrderRecalculation = array('oxorder__oxordernr',
16  'oxorder__oxbillnr',
17  'oxorder__oxtrackcode',
18  'oxorder__oxpaid');
19 
27  public function render()
28  {
30 
31  $soxId = $this->_aViewData["oxid"] = $this->getEditObjectId();
32  if ($soxId != "-1" && isset($soxId)) {
33  // load object
34  $oOrder = oxNew("oxorder");
35  $oOrder->load($soxId);
36 
37 
38  // paid ?
39  $sOxPaidField = 'oxorder__oxpaid';
40  $sDelTypeField = 'oxorder__oxdeltype';
41 
42  if ($oOrder->$sOxPaidField->value != "0000-00-00 00:00:00") {
43  $oOrder->blIsPaid = true;
45  $oUtilsDate = oxRegistry::get("oxUtilsDate");
46  $oOrder->$sOxPaidField = new oxField($oUtilsDate->formatDBDate($oOrder->$sOxPaidField->value));
47  }
48 
49 
50  $this->_aViewData["edit"] = $oOrder;
51  $this->_aViewData["paymentType"] = $oOrder->getPaymentType();
52  $this->_aViewData["oShipSet"] = $oOrder->getShippingSetList();
53 
54 
55  if ($oOrder->$sDelTypeField->value) {
56 
57  // order user
58  $oUser = oxNew('oxuser');
59  $oUser->load($oOrder->oxorder__oxuserid->value);
60 
61  // order sum in default currency
62  $dPrice = $oOrder->oxorder__oxtotalbrutsum->value / $oOrder->oxorder__oxcurrate->value;
63 
65  $oPaymentList = oxRegistry::get("oxPaymentList");
66  $this->_aViewData["oPayments"] =
67  $oPaymentList->getPaymentList($oOrder->$sDelTypeField->value, $dPrice, $oUser);
68  }
69 
70  // any voucher used ?
71  $this->_aViewData["aVouchers"] = $oOrder->getVoucherNrList();
72  }
73 
74  $this->_aViewData["sNowValue"] = date("Y-m-d H:i:s", oxRegistry::get("oxUtilsDate")->getTime());
75 
76  return "order_main.tpl";
77  }
78 
82  public function save()
83  {
84  parent::save();
85 
86  $soxId = $this->getEditObjectId();
87  $aParams = oxRegistry::getConfig()->getRequestParameter("editval");
88 
89  // shopid
90  $sShopID = oxRegistry::getSession()->getVariable("actshop");
91  $aParams['oxorder__oxshopid'] = $sShopID;
92 
93  $oOrder = oxNew("oxorder");
94  if ($soxId != "-1") {
95  $oOrder->load($soxId);
96  } else {
97  $aParams['oxorder__oxid'] = null;
98  }
99 
100  $needOrderRecalculate = false;
101  if (is_array($aParams)) {
102  foreach ($aParams as $parameter => $value) {
103  //parameter changes for not whitelisted parameters trigger order recalculation
104  $orderField = $oOrder->$parameter;
105  if ( ($value != $orderField->value) && !in_array($parameter, $this->fieldsTriggerNoOrderRecalculation) ) {
106  $needOrderRecalculate = true;
107  continue;
108  }
109  }
110  }
111 
112  //change payment
113  $sPayId = oxRegistry::getConfig()->getRequestParameter("setPayment");
114  if (!empty($sPayId) && ($sPayId != $oOrder->oxorder__oxpaymenttype->value)) {
115  $aParams['oxorder__oxpaymenttype'] = $sPayId;
116  $needOrderRecalculate = true;
117  }
118 
119  $oOrder->assign($aParams);
120 
121  $aDynvalues = oxRegistry::getConfig()->getRequestParameter("dynvalue");
122  if (isset($aDynvalues)) {
123  $oPayment = oxNew("oxuserpayment");
124  $oPayment->load($oOrder->oxorder__oxpaymentid->value);
125  $oPayment->oxuserpayments__oxvalue->setValue(oxRegistry::getUtils()->assignValuesToText($aDynvalues));
126  $oPayment->save();
127  $needOrderRecalculate = true;
128  }
129  //change delivery set
130  $sDelSetId = oxRegistry::getConfig()->getRequestParameter("setDelSet");
131  if (!empty($sDelSetId) && ($sDelSetId != $oOrder->oxorder__oxdeltype->value)) {
132  $oOrder->oxorder__oxpaymenttype->setValue("oxempty");
133  $oOrder->setDelivery($sDelSetId);
134  $needOrderRecalculate = true;
135  } else {
136  // keeps old delivery cost
137  $oOrder->reloadDelivery(false);
138  }
139 
140  if ($needOrderRecalculate) {
141  // keeps old discount
142  $oOrder->reloadDiscount(false);
143  $oOrder->recalculateOrder();
144  } else {
145  //nothing changed in order that requires a full recalculation
146  $oOrder->save();
147  }
148 
149  // set oxid if inserted
150  $this->setEditObjectId($oOrder->getId());
151  }
152 
156  public function sendorder()
157  {
158  $soxId = $this->getEditObjectId();
159  $oOrder = oxNew("oxorder");
160  if ($oOrder->load($soxId)) {
161 
162  // #632A
163  $oOrder->oxorder__oxsenddate = new oxField(date("Y-m-d H:i:s", oxRegistry::get("oxUtilsDate")->getTime()));
164  $oOrder->save();
165 
166  // #1071C
167  $oOrderArticles = $oOrder->getOrderArticles(true);
168  if (oxRegistry::getConfig()->getRequestParameter("sendmail")) {
169  // send eMail
170  $oEmail = oxNew("oxemail");
171  $oEmail->sendSendedNowMail($oOrder);
172  }
173 
174  }
175  }
176 
180  public function senddownloadlinks()
181  {
182  $soxId = $this->getEditObjectId();
183  $oOrder = oxNew("oxorder");
184  if ($oOrder->load($soxId)) {
185  $oEmail = oxNew("oxemail");
186  $oEmail->sendDownloadLinksMail($oOrder);
187  }
188  }
189 
193  public function resetorder()
194  {
195  $oOrder = oxNew("oxorder");
196  if ($oOrder->load($this->getEditObjectId())) {
197 
198  $oOrder->oxorder__oxsenddate = new oxField("0000-00-00 00:00:00");
199  $oOrder->save();
200 
201  }
202  }
203 }