OXID eShop CE  4.10.8
 All Classes Namespaces Files Functions Variables Pages
article_stock.php
Go to the documentation of this file.
1 <?php
2 
10 {
11 
18  public function render()
19  {
20  $myConfig = $this->getConfig();
21 
23 
24  $this->_aViewData["edit"] = $oArticle = oxNew("oxarticle");
25 
26  $soxId = $this->getEditObjectId();
27  if ($soxId != "-1" && isset($soxId)) {
28 
29  // load object
30  $oArticle->loadInLang($this->_iEditLang, $soxId);
31 
32  // load object in other languages
33  $oOtherLang = $oArticle->getAvailableInLangs();
34  if (!isset($oOtherLang[$this->_iEditLang])) {
35  // echo "language entry doesn't exist! using: ".key($oOtherLang);
36  $oArticle->loadInLang(key($oOtherLang), $soxId);
37  }
38 
39  foreach ($oOtherLang as $id => $language) {
40  $oLang = new stdClass();
41  $oLang->sLangDesc = $language;
42  $oLang->selected = ($id == $this->_iEditLang);
43  $this->_aViewData["otherlang"][$id] = clone $oLang;
44  }
45 
46 
47  // variant handling
48  if ($oArticle->oxarticles__oxparentid->value) {
49  $oParentArticle = oxNew("oxarticle");
50  $oParentArticle->load($oArticle->oxarticles__oxparentid->value);
51  $this->_aViewData["parentarticle"] = $oParentArticle;
52  $this->_aViewData["oxparentid"] = $oArticle->oxarticles__oxparentid->value;
53  }
54 
55  if ($myConfig->getConfigParam('blMallInterchangeArticles')) {
56  $sShopSelect = '1';
57  } else {
58  $sShopID = $myConfig->getShopID();
59  $sShopSelect = " oxshopid = '$sShopID' ";
60  }
61 
62  $oPriceList = oxNew("oxlist");
63  $oPriceList->init('oxbase', "oxprice2article");
64  $sQ = "select * from oxprice2article where oxartid = '{$soxId}' " .
65  "and {$sShopSelect} and (oxamount > 0 or oxamountto > 0) order by oxamount ";
66  $oPriceList->selectstring($sQ);
67 
68  $this->_aViewData["amountprices"] = $oPriceList;
69 
70  }
71 
72  return "article_stock.tpl";
73  }
74 
78  public function save()
79  {
80  parent::save();
81 
82  $soxId = $this->getEditObjectId();
83  $aParams = oxRegistry::getConfig()->getRequestParameter("editval");
84 
85  // shopid
86  $sShopID = oxRegistry::getSession()->getVariable("actshop");
87  $aParams['oxarticles__oxshopid'] = $sShopID;
88 
89  $oArticle = oxNew("oxarticle");
90  $oArticle->loadInLang($this->_iEditLang, $soxId);
91 
92  $oArticle->setLanguage(0);
93 
94  // checkbox handling
95  if (!$oArticle->oxarticles__oxparentid->value && !isset($aParams['oxarticles__oxremindactive'])) {
96  $aParams['oxarticles__oxremindactive'] = 0;
97  }
98 
99  $oArticle->assign($aParams);
100 
101  //tells to article to save in different language
102  $oArticle->setLanguage($this->_iEditLang);
103  $oArticle = oxRegistry::get("oxUtilsFile")->processFiles($oArticle);
104 
105  $oArticle->resetRemindStatus();
106 
107  $oArticle->updateVariantsRemind();
108 
109  $oArticle->save();
110  }
111 
120  public function addprice($sOXID = null, $aUpdateParams = null)
121  {
122  $myConfig = $this->getConfig();
123 
124  $this->resetContentCache();
125 
126  $sOxArtId = $this->getEditObjectId();
127 
128 
129 
130  $aParams = oxRegistry::getConfig()->getRequestParameter("editval");
131 
132  if (!is_array($aParams)) {
133  return;
134  }
135 
136  if (isset($aUpdateParams) && is_array($aUpdateParams)) {
137  $aParams = array_merge($aParams, $aUpdateParams);
138  }
139 
140  //replacing commas
141  foreach ($aParams as $key => $sParam) {
142  $aParams[$key] = str_replace(",", ".", $sParam);
143  }
144 
145  $aParams['oxprice2article__oxshopid'] = $myConfig->getShopID();
146 
147  if (isset($sOXID)) {
148  $aParams['oxprice2article__oxid'] = $sOXID;
149  }
150 
151  $aParams['oxprice2article__oxartid'] = $sOxArtId;
152  if (!isset($aParams['oxprice2article__oxamount']) || !$aParams['oxprice2article__oxamount']) {
153  $aParams['oxprice2article__oxamount'] = "1";
154  }
155 
156  if (!$myConfig->getConfigParam('blAllowUnevenAmounts')) {
157  $aParams['oxprice2article__oxamount'] = round(( string ) $aParams['oxprice2article__oxamount']);
158  $aParams['oxprice2article__oxamountto'] = round(( string ) $aParams['oxprice2article__oxamountto']);
159  }
160 
161  $dPrice = $aParams['price'];
162  $sType = $aParams['pricetype'];
163 
164  $oArticlePrice = oxNew("oxbase");
165  $oArticlePrice->init("oxprice2article");
166  $oArticlePrice->assign($aParams);
167 
168  $oArticlePrice->$sType = new oxField($dPrice);
169 
170  //validating
171  if ($oArticlePrice->$sType->value &&
172  $oArticlePrice->oxprice2article__oxamount->value &&
173  $oArticlePrice->oxprice2article__oxamountto->value &&
174  is_numeric($oArticlePrice->$sType->value) &&
175  is_numeric($oArticlePrice->oxprice2article__oxamount->value) &&
176  is_numeric($oArticlePrice->oxprice2article__oxamountto->value) &&
177  $oArticlePrice->oxprice2article__oxamount->value <= $oArticlePrice->oxprice2article__oxamountto->value
178  ) {
179  $oArticlePrice->save();
180  }
181 
182  // check if abs price is lower than base price
183  $oArticle = oxNew("oxArticle");
184  $oArticle->loadInLang($this->_iEditLang, $sOxArtId);
185  $sPriceField = 'oxarticles__oxprice';
186  if (($aParams['price'] >= $oArticle->$sPriceField->value) &&
187  ($aParams['pricetype'] == 'oxprice2article__oxaddabs')) {
188  if (is_null($sOXID)) {
189  $sOXID = $oArticlePrice->getId();
190  }
191  $this->_aViewData["errorscaleprice"][] = $sOXID;
192  }
193 
194  }
195 
199  public function updateprices()
200  {
201 
202  $aParams = oxRegistry::getConfig()->getRequestParameter("updateval");
203  if (is_array($aParams)) {
204  foreach ($aParams as $soxId => $aStockParams) {
205  $this->addprice($soxId, $aStockParams);
206  }
207  }
208  }
209 
210 
214  public function deleteprice()
215  {
216  $this->resetContentCache();
217 
218  $oDb = oxDb::getDb();
219  $sPriceId = $oDb->quote(oxRegistry::getConfig()->getRequestParameter("priceid"));
220  $sId = $oDb->quote($this->getEditObjectId());
221  $oDb->execute("delete from oxprice2article where oxid = {$sPriceId} and oxartid = {$sId}");
222  }
223 }