OXID eShop CE  4.9.5
 All Classes Files Functions Variables Pages
order_article.php
Go to the documentation of this file.
1 <?php
2 
9 {
10 
16  protected $_oSearchProduct = null;
17 
25  protected $_oSearchProductList = null;
26 
32  protected $_oMainSearchProduct = null;
33 
39  protected $_oEditObject = null;
40 
48  public function render()
49  {
51 
52  if ($oOrder = $this->getEditObject()) {
53  $this->_aViewData["edit"] = $oOrder;
54  $this->_aViewData["aProductVats"] = $oOrder->getProductVats(true);
55  }
56 
57  return "order_article.tpl";
58  }
59 
65  public function getEditObject()
66  {
67  $soxId = $this->getEditObjectId();
68  if ($this->_oEditObject === null && isset($soxId) && $soxId != "-1") {
69  $this->_oEditObject = oxNew("oxorder");
70  $this->_oEditObject->load($soxId);
71  }
72 
73  return $this->_oEditObject;
74  }
75 
81  public function getSearchProductArtNr()
82  {
83  return oxRegistry::getConfig()->getRequestParameter('sSearchArtNum');
84  }
85 
91  public function getSearchProduct()
92  {
93  if ($this->_oSearchProduct === null) {
94  $this->_oSearchProduct = false;
95  $sSearchArtNum = $this->getSearchProductArtNr();
96 
97  foreach ($this->getProductList() as $oProduct) {
98  if ($oProduct->oxarticles__oxartnum->value == $sSearchArtNum) {
99  $this->_oSearchProduct = $oProduct;
100  break;
101  }
102  }
103  }
104 
105  return $this->_oSearchProduct;
106  }
107 
113  public function getMainProduct()
114  {
115  if ($this->_oMainSearchProduct === null && ($sArtNum = $this->getSearchProductArtNr())) {
116  $this->_oMainSearchProduct = false;
117  $sArtId = null;
118 
119  //get article id
120  $oDb = oxDb::getDb(oxDB::FETCH_MODE_ASSOC);
121  $sTable = getViewName("oxarticles");
122  $sQ = "select oxid, oxparentid from $sTable where oxartnum = " . $oDb->quote($sArtNum) . " limit 1";
123 
124  $rs = $oDb->execute($sQ);
125  if ($rs != false && $rs->recordCount() > 0) {
126  $sArtId = $rs->fields['OXPARENTID'] ? $rs->fields['OXPARENTID'] : $rs->fields['OXID'];
127 
128  $oProduct = oxNew("oxarticle");
129  if ($oProduct->load($sArtId)) {
130  $this->_oMainSearchProduct = $oProduct;
131  }
132  }
133  }
134 
136  }
137 
143  public function getProductList()
144  {
145  if ($this->_oSearchProductList === null) {
146  $this->_oSearchProductList = oxNew("oxlist");
147 
148  // main search product is found?
149  if ($oMainSearchProduct = $this->getMainProduct()) {
150  // storing self to first list position
151  $this->_oSearchProductList->offsetSet($oMainSearchProduct->getId(), $oMainSearchProduct);
152 
153  // adding variants..
154  foreach ($oMainSearchProduct->getVariants() as $oVariant) {
155  $this->_oSearchProductList->offsetSet($oVariant->getId(), $oVariant);
156  }
157  }
158  }
159 
161  }
162 
166  public function addThisArticle()
167  {
168  $sOxid = oxRegistry::getConfig()->getRequestParameter('aid');
169  $dAmount = oxRegistry::getConfig()->getRequestParameter('am');
170  $oProduct = oxNew("oxarticle");
171 
172  if ($sOxid && $dAmount && $oProduct->load($sOxid)) {
173 
174  $sOrderId = $this->getEditObjectId();
175  $oOrder = oxNew('oxorder');
176  if ($sOrderId && $oOrder->load($sOrderId)) {
177  $oOrderArticle = oxNew('oxorderArticle');
178  $oOrderArticle->oxorderarticles__oxartid = new oxField($oProduct->getId());
179  $oOrderArticle->oxorderarticles__oxartnum = new oxField($oProduct->oxarticles__oxartnum->value);
180  $oOrderArticle->oxorderarticles__oxamount = new oxField($dAmount);
181  $oOrderArticle->oxorderarticles__oxselvariant = new oxField(oxRegistry::getConfig()->getRequestParameter('sel'));
182  $oOrder->recalculateOrder(array($oOrderArticle));
183  }
184  }
185  }
186 
190  public function deleteThisArticle()
191  {
192  // get article id
193  $sOrderArtId = oxRegistry::getConfig()->getRequestParameter('sArtID');
194  $sOrderId = $this->getEditObjectId();
195 
196  $oOrderArticle = oxNew('oxorderarticle');
197  $oOrder = oxNew('oxorder');
198 
199  // order and order article exits?
200  if ($oOrderArticle->load($sOrderArtId) && $oOrder->load($sOrderId)) {
201  $myConfig = $this->getConfig();
202 
203  // deleting record
204  $oOrderArticle->delete();
205 
206  // recalculating order
207  $oOrder->recalculateOrder();
208  }
209  }
210 
214  public function storno()
215  {
216  $myConfig = $this->getConfig();
217 
218  $sOrderArtId = oxRegistry::getConfig()->getRequestParameter('sArtID');
219  $oArticle = oxNew('oxorderarticle');
220  $oArticle->load($sOrderArtId);
221 
222  if ($oArticle->oxorderarticles__oxstorno->value == 1) {
223  $oArticle->oxorderarticles__oxstorno->setValue(0);
224  $sStockSign = -1;
225  } else {
226  $oArticle->oxorderarticles__oxstorno->setValue(1);
227  $sStockSign = 1;
228  }
229 
230  // stock information
231  if ($myConfig->getConfigParam('blUseStock')) {
232  $oArticle->updateArticleStock($oArticle->oxorderarticles__oxamount->value * $sStockSign, $myConfig->getConfigParam('blAllowNegativeStock'));
233  }
234 
235  $oDb = oxDb::getDb();
236  $sQ = "update oxorderarticles set oxstorno = " . $oDb->quote($oArticle->oxorderarticles__oxstorno->value) . " where oxid = " . $oDb->quote($sOrderArtId);
237  $oDb->execute($sQ);
238 
239  //get article id
240  $sQ = "select oxartid from oxorderarticles where oxid = " . $oDb->quote($sOrderArtId);
241  if (($sArtId = oxDb::getDb()->getOne($sQ, false, false))) {
242  $oOrder = oxNew('oxorder');
243  if ($oOrder->load($this->getEditObjectId())) {
244  $oOrder->recalculateOrder();
245  }
246  }
247  }
248 
252  public function updateOrder()
253  {
254  $aOrderArticles = oxRegistry::getConfig()->getRequestParameter('aOrderArticles');
255 
256  $oOrder = oxNew('oxorder');
257  if (is_array($aOrderArticles) && $oOrder->load($this->getEditObjectId())) {
258 
259  $myConfig = $this->getConfig();
260  $oOrderArticles = $oOrder->getOrderArticles(true);
261 
262  $blUseStock = $myConfig->getConfigParam('blUseStock');
263  foreach ($oOrderArticles as $oOrderArticle) {
264  $sItemId = $oOrderArticle->getId();
265  if (isset($aOrderArticles[$sItemId])) {
266 
267  // update stock
268  if ($blUseStock) {
269  $oOrderArticle->setNewAmount($aOrderArticles[$sItemId]['oxamount']);
270  } else {
271  $oOrderArticle->assign($aOrderArticles[$sItemId]);
272  $oOrderArticle->save();
273  }
274  }
275  }
276 
277  // recalculating order
278  $oOrder->recalculateOrder();
279  }
280  }
281 }