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