OXID eShop CE  4.9.8
 All Classes Files Functions Variables Pages
category_main.php
Go to the documentation of this file.
1 <?php
2 
10 {
11 
18  public function render()
19  {
20  $myConfig = $this->getConfig();
21 
23 
25  $oCategory = oxNew("oxcategory");
26 
27  $soxId = $this->getEditObjectId();
28 
29  $this->_aViewData["edit"] = $oCategory;
30  $this->_aViewData["oxid"] = $soxId;
31 
32  if ($soxId != "-1" && isset($soxId)) {
33 
34  // generating category tree for select list
35  $this->_createCategoryTree("artcattree", $soxId);
36 
37  // load object
38  $oCategory->loadInLang($this->_iEditLang, $soxId);
39 
40 
41  $oOtherLang = $oCategory->getAvailableInLangs();
42  if (!isset($oOtherLang[$this->_iEditLang])) {
43  // echo "language entry doesn't exist! using: ".key($oOtherLang);
44  $oCategory->loadInLang(key($oOtherLang), $soxId);
45  }
46 
47  // remove already created languages
48  $aLang = array_diff(oxRegistry::getLang()->getLanguageNames(), $oOtherLang);
49  if (count($aLang)) {
50  $this->_aViewData["posslang"] = $aLang;
51  }
52 
53  foreach ($oOtherLang as $id => $language) {
54  $oLang = new stdClass();
55  $oLang->sLangDesc = $language;
56  $oLang->selected = ($id == $this->_iEditLang);
57  $this->_aViewData["otherlang"][$id] = clone $oLang;
58  }
59 
60  if ($oCategory->oxcategories__oxparentid->value == 'oxrootid') {
61  $oCategory->oxcategories__oxparentid->setValue('');
62  }
63 
64  $this->_getCategoryTree("cattree", $oCategory->oxcategories__oxparentid->value, $oCategory->oxcategories__oxid->value, true, $oCategory->oxcategories__oxshopid->value);
65 
66  $this->_aViewData["defsort"] = $oCategory->oxcategories__oxdefsort->value;
67  } else {
68  $this->_createCategoryTree("cattree", "", true, $myConfig->getShopId());
69  }
70 
71  $this->_aViewData["sortableFields"] = $this->getSortableFields();
72 
73  if (oxRegistry::getConfig()->getRequestParameter("aoc")) {
75  $oCategoryMainAjax = oxNew('category_main_ajax');
76  $this->_aViewData['oxajax'] = $oCategoryMainAjax->getColumns();
77 
78  return "popups/category_main.tpl";
79  }
80 
81  return "category_main.tpl";
82  }
83 
89  public function getSortableFields()
90  {
91  $aSkipFields = array("OXID", "OXSHOPID", "OXMAPID", "OXPARENTID", "OXACTIVE", "OXACTIVEFROM"
92  , "OXACTIVETO", "OXSHORTDESC"
93  , "OXUNITNAME", "OXUNITQUANTITY", "OXEXTURL", "OXURLDESC", "OXURLIMG", "OXVAT"
94  , "OXTHUMB", "OXPIC1", "OXPIC2", "OXPIC3", "OXPIC4", "OXPIC5"
95  , "OXPIC6", "OXPIC7", "OXPIC8", "OXPIC9", "OXPIC10", "OXPIC11", "OXPIC12", "OXSTOCKFLAG"
96  , "OXSTOCKTEXT", "OXNOSTOCKTEXT", "OXDELIVERY", "OXFILE", "OXSEARCHKEYS", "OXTEMPLATE"
97  , "OXQUESTIONEMAIL", "OXISSEARCH", "OXISCONFIGURABLE", "OXBUNDLEID", "OXFOLDER", "OXSUBCLASS"
98  , "OXREMINDACTIVE", "OXREMINDAMOUNT", "OXVENDORID", "OXMANUFACTURERID", "OXSKIPDISCOUNTS"
99  , "OXBLFIXEDPRICE", "OXICON", "OXVARSELECT", "OXAMITEMID", "OXAMTASKID", "OXPIXIEXPORT", "OXPIXIEXPORTED", "OXSORT"
100  , "OXUPDATEPRICE", "OXUPDATEPRICEA", "OXUPDATEPRICEB", "OXUPDATEPRICEC", "OXUPDATEPRICETIME", "OXISDOWNLOADABLE"
101  , "OXVARMAXPRICE", "OXSHOWCUSTOMAGREEMENT"
102  );
104  $oDbHandler = oxNew("oxDbMetaDataHandler");
105  $aFields = array_merge($oDbHandler->getMultilangFields('oxarticles'), array_keys($oDbHandler->getSinglelangFields('oxarticles', 0)));
106  $aFields = array_diff($aFields, $aSkipFields);
107  $aFields = array_unique($aFields);
108 
109  return $aFields;
110  }
111 
117  public function save()
118  {
119  parent::save();
120 
121  $myConfig = $this->getConfig();
122 
123  $soxId = $this->getEditObjectId();
124 
125  $aParams = $this->_parseRequestParametersForSave(
126  $myConfig->getRequestParameter("editval")
127  );
128 
130  $oCategory = oxNew("oxcategory");
131 
132  if ($soxId != "-1") {
133  $this->resetCounter("catArticle", $soxId);
134  $oCategory->load($soxId);
135  $oCategory->loadInLang($this->_iEditLang, $soxId);
136 
138  $myUtilsPic = oxRegistry::get("oxUtilsPic");
139 
140  // #1173M - not all pic are deleted, after article is removed
141  $myUtilsPic->overwritePic($oCategory, 'oxcategories', 'oxthumb', 'TC', '0', $aParams, $myConfig->getPictureDir(false));
142  $myUtilsPic->overwritePic($oCategory, 'oxcategories', 'oxicon', 'CICO', 'icon', $aParams, $myConfig->getPictureDir(false));
143  $myUtilsPic->overwritePic($oCategory, 'oxcategories', 'oxpromoicon', 'PICO', 'icon', $aParams, $myConfig->getPictureDir(false));
144  }
145 
146 
147  $oCategory->setLanguage(0);
148 
149 
150  $oCategory->assign($aParams);
151  $oCategory->setLanguage($this->_iEditLang);
152 
154  $oUtilsFile = oxRegistry::get("oxUtilsFile");
155 
156  $oCategory = $oUtilsFile->processFiles($oCategory);
157  $oCategory->save();
158 
159  $this->setEditObjectId($oCategory->getId());
160  }
161 
169  protected function _processLongDesc($sValue)
170  {
171  // workaround for firefox showing &lang= as &9001;= entity, mantis#0001272
172  return str_replace('&lang=', '&amp;lang=', $sValue);
173  }
174 
178  public function saveinnlang()
179  {
180  $this->save();
181  }
182 
188  public function deletePicture()
189  {
190  $myConfig = $this->getConfig();
191 
192  if ($myConfig->isDemoShop()) {
193  // disabling uploading pictures if this is demo shop
194  $oEx = new oxExceptionToDisplay();
195  $oEx->setMessage('CATEGORY_PICTURES_UPLOADISDISABLED');
196 
198  $oUtilsView = oxRegistry::get("oxUtilsView");
199 
200  $oUtilsView->addErrorToDisplay($oEx, false);
201 
202  return;
203  }
204 
205  $sOxId = $this->getEditObjectId();
206  $sField = oxRegistry::getConfig()->getRequestParameter('masterPicField');
207  if (empty($sField)) {
208  return;
209  }
210 
212  $oItem = oxNew('oxCategory');
213  $oItem->load($sOxId);
214  $this->_deleteCatPicture($oItem, $sField);
215  }
216 
225  protected function _deleteCatPicture(oxCategory $oItem, $sField)
226  {
227  $myConfig = $this->getConfig();
228  $sItemKey = 'oxcategories__' . $sField;
229 
230 
231  switch ($sField) {
232  case 'oxthumb':
233  $sImgType = 'TC';
234  break;
235 
236  case 'oxicon':
237  $sImgType = 'CICO';
238  break;
239 
240  case 'oxpromoicon':
241  $sImgType = 'PICO';
242  break;
243 
244  default:
245  $sImgType = false;
246  }
247 
248  if ($sImgType !== false) {
250  $myUtilsPic = oxRegistry::get("oxUtilsPic");
252  $oUtilsFile = oxRegistry::get("oxUtilsFile");
253 
254  $sDir = $myConfig->getPictureDir(false);
255  $myUtilsPic->safePictureDelete($oItem->$sItemKey->value, $sDir . $oUtilsFile->getImageDirByType($sImgType), 'oxcategories', $sField);
256 
257  $oItem->$sItemKey = new oxField();
258  $oItem->save();
259  }
260  }
261 
269  protected function _parseRequestParametersForSave($aReqParams)
270  {
271  // checkbox handling
272  if (!isset($aReqParams['oxcategories__oxactive'])) {
273  $aReqParams['oxcategories__oxactive'] = 0;
274  }
275  if (!isset($aReqParams['oxcategories__oxhidden'])) {
276  $aReqParams['oxcategories__oxhidden'] = 0;
277  }
278  if (!isset($aReqParams['oxcategories__oxdefsortmode'])) {
279  $aReqParams['oxcategories__oxdefsortmode'] = 0;
280  }
281 
282  // null values
283  if ($aReqParams['oxcategories__oxvat'] === '') {
284  $aReqParams['oxcategories__oxvat'] = null;
285  }
286 
287  // shopId
288  $aReqParams['oxcategories__oxshopid'] = oxRegistry::getSession()->getVariable("actshop");
289 
290  if ($this->getEditObjectId() == "-1") {
291  //#550A - if new category is made then is must be default activ
292  //#4051: Impossible to create inactive category
293  //$aReqParams['oxcategories__oxactive'] = 1;
294  $aReqParams['oxcategories__oxid'] = null;
295  }
296 
297  if (isset($aReqParams["oxcategories__oxlongdesc"])) {
298  $aReqParams["oxcategories__oxlongdesc"] = $this->_processLongDesc($aReqParams["oxcategories__oxlongdesc"]);
299  }
300 
301  if (empty($aReqParams['oxcategories__oxpricefrom'])) {
302  $aReqParams['oxcategories__oxpricefrom'] = 0;
303  }
304  if (empty($aReqParams['oxcategories__oxpriceto'])) {
305  $aReqParams['oxcategories__oxpriceto'] = 0;
306  }
307 
308  return $aReqParams;
309  }
310 }