OXID eShop CE  4.8.12
 All Classes Files Functions Variables Pages
article_extend.php
Go to the documentation of this file.
1 <?php
2 
11 {
16  protected $_aUnitsArray = null;
17 
24  public function render()
25  {
27 
28  $this->_aViewData['edit'] = $oArticle = oxNew( 'oxArticle' );
29 
30  $soxId = $this->getEditObjectId();
31 
32  $this->_createCategoryTree( "artcattree");
33 
34  // all categories
35  if ( $soxId != "-1" && isset( $soxId ) ) {
36  // load object
37  $oArticle->loadInLang( $this->_iEditLang, $soxId );
38 
39 
40  // load object in other languages
41  $oOtherLang = $oArticle->getAvailableInLangs();
42  if (!isset($oOtherLang[$this->_iEditLang])) {
43  // echo "language entry doesn't exist! using: ".key($oOtherLang);
44  $oArticle->loadInLang( key($oOtherLang), $soxId );
45  }
46 
47  foreach ( $oOtherLang as $id => $language) {
48  $oLang= new stdClass();
49  $oLang->sLangDesc = $language;
50  $oLang->selected = ($id == $this->_iEditLang);
51  $this->_aViewData["otherlang"][$id] = clone $oLang;
52  }
53 
54  // variant handling
55  if ( $oArticle->oxarticles__oxparentid->value) {
56  $oParentArticle = oxNew( 'oxArticle' );
57  $oParentArticle->load( $oArticle->oxarticles__oxparentid->value);
58  $this->_aViewData["parentarticle"] = $oParentArticle;
59  $this->_aViewData["oxparentid"] = $oArticle->oxarticles__oxparentid->value;
60  }
61  }
62 
63 
64  $oDB = oxDb::getDB();
65  $myConfig = $this->getConfig();
66 
67  $sArticleTable = getViewName( 'oxarticles', $this->_iEditLang );
68  $sSelect = "select $sArticleTable.oxtitle, $sArticleTable.oxartnum, $sArticleTable.oxvarselect from $sArticleTable where 1 ";
69  // #546
70  $sSelect .= $myConfig->getConfigParam( 'blVariantsSelection' )?'':" and $sArticleTable.oxparentid = '' ";
71  $sSelect .= " and $sArticleTable.oxid = ".$oDB->quote( $oArticle->oxarticles__oxbundleid->value );
72 
73  $rs = $oDB->Execute( $sSelect);
74  if ($rs != false && $rs->RecordCount() > 0) {
75  while (!$rs->EOF) {
76  $sArtNum = new oxField($rs->fields[1]);
77  $sArtTitle = new oxField($rs->fields[0]." ".$rs->fields[2]);
78  $rs->MoveNext();
79  }
80  }
81  $this->_aViewData['bundle_artnum'] = $sArtNum;
82  $this->_aViewData['bundle_title'] = $sArtTitle;
83 
84 
85  $iAoc = $this->getConfig()->getRequestParameter("aoc");
86  if ( $iAoc == 1 ) {
87  $oArticleExtendAjax = oxNew( 'article_extend_ajax' );
88  $this->_aViewData['oxajax'] = $oArticleExtendAjax->getColumns();
89 
90  return "popups/article_extend.tpl";
91  } elseif ( $iAoc == 2 ) {
92  $oArticleBundleAjax = oxNew( 'article_bundle_ajax' );
93  $this->_aViewData['oxajax'] = $oArticleBundleAjax->getColumns();
94 
95  return "popups/article_bundle.tpl";
96  }
97 
98  //load media files
99  $this->_aViewData['aMediaUrls'] = $oArticle->getMediaUrls();
100 
101  return "article_extend.tpl";
102  }
103 
109  public function save()
110  {
111  parent::save();
112 
113  $aMyFile = $this->getConfig()->getUploadedFile( "myfile" );
114  $aMediaFile = $this->getConfig()->getUploadedFile( "mediaFile" );
115  if ( is_array( $aMyFile['name'] ) && reset( $aMyFile['name'] ) || $aMediaFile['name'] ) {
116  $myConfig = $this->getConfig();
117  if ( $myConfig->isDemoShop() ) {
118  $oEx = oxNew( "oxExceptionToDisplay" );
119  $oEx->setMessage( 'ARTICLE_EXTEND_UPLOADISDISABLED' );
120  oxRegistry::get("oxUtilsView")->addErrorToDisplay( $oEx, false );
121 
122  return;
123  }
124  }
125 
126  $soxId = $this->getEditObjectId();
127  $aParams = oxRegistry::getConfig()->getRequestParameter( "editval");
128  // checkbox handling
129  if ( !isset( $aParams['oxarticles__oxissearch'])) {
130  $aParams['oxarticles__oxissearch'] = 0;
131  }
132  if ( !isset( $aParams['oxarticles__oxblfixedprice'])) {
133  $aParams['oxarticles__oxblfixedprice'] = 0;
134  }
135 
136  // new way of handling bundled articles
137  //#1517C - remove possibility to add Bundled Product
138  //$this->setBundleId($aParams, $soxId);
139 
140  // default values
141  $aParams = $this->addDefaultValues( $aParams);
142 
143  $oArticle = oxNew( "oxarticle" );
144  $oArticle->loadInLang( $this->_iEditLang, $soxId);
145 
146  if ( $aParams['oxarticles__oxtprice'] != $oArticle->oxarticles__oxtprice->value && $aParams['oxarticles__oxtprice'] && $aParams['oxarticles__oxtprice'] <= $oArticle->oxarticles__oxprice->value) {
147  $this->_aViewData["errorsavingtprice"] = 1;
148  }
149 
150  $oArticle->setLanguage(0);
151  $oArticle->assign( $aParams);
152  $oArticle->setLanguage($this->_iEditLang);
153  $oArticle = oxRegistry::get("oxUtilsFile")->processFiles( $oArticle );
154  $oArticle->save();
155 
156  //saving media file
157  $sMediaUrl = $this->getConfig()->getRequestParameter( "mediaUrl" );
158  $sMediaDesc = $this->getConfig()->getRequestParameter( "mediaDesc");
159 
160  if ( ( $sMediaUrl && $sMediaUrl != 'http://' ) || $aMediaFile['name'] || $sMediaDesc ) {
161 
162  if ( !$sMediaDesc ) {
163  return oxRegistry::get("oxUtilsView")->addErrorToDisplay( 'EXCEPTION_NODESCRIPTIONADDED' );
164  }
165 
166  if ( ( !$sMediaUrl || $sMediaUrl == 'http://' ) && !$aMediaFile['name'] ) {
167  return oxRegistry::get("oxUtilsView")->addErrorToDisplay( 'EXCEPTION_NOMEDIAADDED' );
168  }
169 
170  $oMediaUrl = oxNew( "oxMediaUrl" );
171  $oMediaUrl->setLanguage( $this->_iEditLang );
172  $oMediaUrl->oxmediaurls__oxisuploaded = new oxField( 0, oxField::T_RAW );
173 
174  //handle uploaded file
175  if ($aMediaFile['name']) {
176  try {
177  $sMediaUrl = oxRegistry::get("oxUtilsFile")->processFile( 'mediaFile', 'out/media/' );
178  $oMediaUrl->oxmediaurls__oxisuploaded = new oxField(1, oxField::T_RAW);
179  } catch (Exception $e) {
180  return oxRegistry::get("oxUtilsView")->addErrorToDisplay( $e->getMessage() );
181  }
182  }
183 
184  //save media url
185  $oMediaUrl->oxmediaurls__oxobjectid = new oxField($soxId, oxField::T_RAW);
186  $oMediaUrl->oxmediaurls__oxurl = new oxField($sMediaUrl, oxField::T_RAW);
187  $oMediaUrl->oxmediaurls__oxdesc = new oxField($sMediaDesc, oxField::T_RAW);
188  $oMediaUrl->save();
189  }
190 
191  // renew price update time
192  oxNew( "oxArticleList" )->renewPriceUpdateTime();
193  }
194 
200  public function deletemedia()
201  {
202  $soxId = $this->getEditObjectId();
203  $sMediaId = $this->getConfig()->getRequestParameter( "mediaid" );
204  if ($sMediaId && $soxId) {
205  $oMediaUrl = oxNew("oxMediaUrl");
206  $oMediaUrl->load($sMediaId);
207  $oMediaUrl->delete();
208  }
209  }
210 
219  public function addDefaultValues( $aParams)
220  {
221  $aParams['oxarticles__oxexturl'] = str_replace( "http://", "", $aParams['oxarticles__oxexturl']);
222 
223  return $aParams;
224  }
225 
231  public function updateMedia()
232  {
233  $aMediaUrls = $this->getConfig()->getRequestParameter( 'aMediaUrls' );
234  if ( is_array( $aMediaUrls ) ) {
235  foreach ( $aMediaUrls as $sMediaId => $aMediaParams ) {
236  $oMedia = oxNew("oxMediaUrl");
237  if ( $oMedia->load( $sMediaId ) ) {
238  $oMedia->setLanguage(0);
239  $oMedia->assign( $aMediaParams );
240  $oMedia->setLanguage( $this->_iEditLang );
241  $oMedia->save();
242  }
243  }
244  }
245  }
246 
252  public function getUnitsArray()
253  {
254  if ( $this->_aUnitsArray === null ) {
255  $this->_aUnitsArray = oxRegistry::getLang()->getSimilarByKey( "_UNIT_", $this->_iEditLang, false );
256  }
257  return $this->_aUnitsArray;
258  }
259 }