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