OXID eShop CE  4.8.11
 All Classes Files Functions Variables Pages
category_main.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"] = $oCategory = oxNew( "oxcategory" );;
24  $soxId = $this->_aViewData["oxid"] = $this->getEditObjectId();
25  if ( $soxId != "-1" && isset( $soxId)) {
26 
27  // generating category tree for select list
28  $this->_createCategoryTree( "artcattree", $soxId );
29 
30  // load object
31  $oCategory->loadInLang( $this->_iEditLang, $soxId );
32 
33 
34  $oOtherLang = $oCategory->getAvailableInLangs();
35  if (!isset($oOtherLang[$this->_iEditLang])) {
36  // echo "language entry doesn't exist! using: ".key($oOtherLang);
37  $oCategory->loadInLang( key($oOtherLang), $soxId );
38  }
39 
40  // remove already created languages
41  $aLang = array_diff ( oxRegistry::getLang()->getLanguageNames(), $oOtherLang );
42  if ( count( $aLang))
43  $this->_aViewData["posslang"] = $aLang;
44 
45  foreach ( $oOtherLang as $id => $language) {
46  $oLang = new stdClass();
47  $oLang->sLangDesc = $language;
48  $oLang->selected = ($id == $this->_iEditLang);
49  $this->_aViewData["otherlang"][$id] = clone $oLang;
50  }
51 
52  if ( $oCategory->oxcategories__oxparentid->value == 'oxrootid')
53  $oCategory->oxcategories__oxparentid->setValue('');
54 
55  $this->_getCategoryTree( "cattree", $oCategory->oxcategories__oxparentid->value, $oCategory->oxcategories__oxid->value, true, $oCategory->oxcategories__oxshopid->value);
56 
57  $this->_aViewData["defsort"] = $oCategory->oxcategories__oxdefsort->value;
58  } else
59  $this->_createCategoryTree( "cattree", "", true, $myConfig->getShopId());
60 
61  $this->_aViewData["sortableFields"] = $this->getSortableFields();
62 
63  if ( oxConfig::getParameter("aoc") ) {
64  $oCategoryMainAjax = oxNew( 'category_main_ajax' );
65  $this->_aViewData['oxajax'] = $oCategoryMainAjax->getColumns();
66 
67  return "popups/category_main.tpl";
68  }
69 
70  return "category_main.tpl";
71  }
72 
78  public function getSortableFields()
79  {
80  $aSkipFields = array( "OXID", "OXSHOPID", "OXSHOPINCL", "OXSHOPEXCL", "OXPARENTID", "OXACTIVE", "OXACTIVEFROM"
81  , "OXACTIVETO", "OXSHORTDESC"
82  , "OXUNITNAME", "OXUNITQUANTITY", "OXEXTURL", "OXURLDESC", "OXURLIMG", "OXVAT"
83  , "OXTHUMB", "OXPIC1", "OXPIC2", "OXPIC3", "OXPIC4", "OXPIC5"
84  , "OXPIC6", "OXPIC7", "OXPIC8", "OXPIC9", "OXPIC10", "OXPIC11", "OXPIC12", "OXSTOCKFLAG"
85  , "OXSTOCKTEXT", "OXNOSTOCKTEXT", "OXDELIVERY", "OXFILE", "OXSEARCHKEYS", "OXTEMPLATE"
86  , "OXQUESTIONEMAIL", "OXISSEARCH", "OXISCONFIGURABLE", "OXBUNDLEID", "OXFOLDER", "OXSUBCLASS"
87  , "OXREMINDACTIVE", "OXREMINDAMOUNT", "OXVENDORID", "OXMANUFACTURERID", "OXSKIPDISCOUNTS"
88  , "OXBLFIXEDPRICE", "OXICON", "OXVARSELECT", "OXAMITEMID", "OXAMTASKID", "OXPIXIEXPORT", "OXPIXIEXPORTED", "OXSORT"
89  , "OXUPDATEPRICE", "OXUPDATEPRICEA", "OXUPDATEPRICEB", "OXUPDATEPRICEC", "OXUPDATEPRICETIME", "OXISDOWNLOADABLE"
90  , "OXVARMAXPRICE", "OXSHOWCUSTOMAGREEMENT"
91  );
92  $aSkipFields = array_merge($aSkipFields, oxRegistry::get("oxShopMetaData")->getShopFields());
93 
94  $oDbHandler = oxNew( "oxDbMetaDataHandler" );
95  $aFields = array_merge( $oDbHandler->getMultilangFields( 'oxarticles' ), $oDbHandler->getSinglelangFields( 'oxarticles', 0 ) );
96  $aFields = array_diff( $aFields, $aSkipFields );
97  $aFields = array_unique( $aFields );
98 
99  return $aFields;
100  }
101 
107  public function save()
108  {
109  parent::save();
110 
111  $myConfig = $this->getConfig();
112 
113  $soxId = $this->getEditObjectId();
114  $aParams = oxConfig::getParameter( "editval");
115 
116  // checkbox handling
117  if ( !isset( $aParams['oxcategories__oxactive']))
118  $aParams['oxcategories__oxactive'] = 0;
119  if ( !isset( $aParams['oxcategories__oxhidden']))
120  $aParams['oxcategories__oxhidden'] = 0;
121  if ( !isset( $aParams['oxcategories__oxdefsortmode']))
122  $aParams['oxcategories__oxdefsortmode'] = 0;
123 
124  // null values
125  if ($aParams['oxcategories__oxvat'] === '')
126  $aParams['oxcategories__oxvat'] = null;
127 
128  // shopId
129  $aParams['oxcategories__oxshopid'] = oxSession::getVar( "actshop" );
130 
131  $oCategory = oxNew( "oxcategory" );
132 
133  if ( $soxId != "-1") {
134  $this->resetCounter( "catArticle", $soxId );
135  $oCategory->load( $soxId);
136  $oCategory->loadInLang( $this->_iEditLang, $soxId );
137 
138  $myUtilsPic = oxRegistry::get("oxUtilsPic");
139  // #1173M - not all pic are deleted, after article is removed
140  $myUtilsPic->overwritePic( $oCategory, 'oxcategories', 'oxthumb', 'TC', '0', $aParams, $myConfig->getPictureDir(false) );
141  $myUtilsPic->overwritePic( $oCategory, 'oxcategories', 'oxicon', 'CICO', 'icon', $aParams, $myConfig->getPictureDir(false) );
142  $myUtilsPic->overwritePic( $oCategory, 'oxcategories', 'oxpromoicon', 'PICO', 'icon', $aParams, $myConfig->getPictureDir(false) );
143 
144  } else {
145  //#550A - if new category is made then is must be default activ
146  //#4051: Impossible to create inactive category
147  //$aParams['oxcategories__oxactive'] = 1;
148  $aParams['oxcategories__oxid'] = null;
149  }
150 
151 
152  $oCategory->setLanguage(0);
153  if ( isset( $aParams["oxcategories__oxlongdesc"] ) ) {
154  $aParams["oxcategories__oxlongdesc"] = $this->_processLongDesc( $aParams["oxcategories__oxlongdesc"] );
155  }
156 
157 
158  if ( empty($aParams['oxcategories__oxpricefrom']) ) {
159  $aParams['oxcategories__oxpricefrom'] = 0;
160  }
161  if ( empty($aParams['oxcategories__oxpriceto']) ) {
162  $aParams['oxcategories__oxpriceto'] = 0;
163  }
164 
165  $oCategory->assign( $aParams );
166  $oCategory->setLanguage($this->_iEditLang);
167 
168  $oCategory = oxRegistry::get("oxUtilsFile")->processFiles( $oCategory );
169  $oCategory->save();
170 
171  $this->setEditObjectId( $oCategory->getId() );
172  }
173 
181  protected function _processLongDesc( $sValue )
182  {
183  // workaround for firefox showing &lang= as &9001;= entity, mantis#0001272
184  return str_replace( '&lang=', '&amp;lang=', $sValue );
185  }
186 
192  public function saveinnlang()
193  {
194  $this->save();
195  }
196 
202  public function deletePicture()
203  {
204  $myConfig = $this->getConfig();
205 
206  if ( $myConfig->isDemoShop() ) {
207  // disabling uploading pictures if this is demo shop
208  $oEx = new oxExceptionToDisplay();
209  $oEx->setMessage( 'CATEGORY_PICTURES_UPLOADISDISABLED' );
210  oxRegistry::get("oxUtilsView")->addErrorToDisplay( $oEx, false );
211 
212  return;
213  }
214 
215  $sOxId = $this->getEditObjectId();
216  $sField = oxConfig::getParameter('masterPicField');
217  if (empty($sField)) {
218  return;
219  }
220 
221  $oItem = oxNew('oxCategory');
222  $oItem->load($sOxId);
223  $this->_deleteCatPicture($oItem, $sField);
224  }
225 
234  protected function _deleteCatPicture(oxCategory $oItem, $sField)
235  {
236  $myConfig = $this->getConfig();
237  $sItemKey = 'oxcategories__'.$sField;
238 
239 
240  switch ($sField) {
241  case 'oxthumb':
242  $sImgType = 'TC';
243  break;
244 
245  case 'oxicon':
246  $sImgType = 'CICO';
247  break;
248 
249  case 'oxpromoicon':
250  $sImgType = 'PICO';
251  break;
252 
253  default:
254  $sImgType = false;
255  }
256 
257  if ($sImgType !== false) {
258  $myUtilsPic = oxRegistry::get("oxUtilsPic");
259  $sDir = $myConfig->getPictureDir(false);
260  $myUtilsPic->safePictureDelete($oItem->$sItemKey->value, $sDir . oxRegistry::get("oxUtilsFile")->getImageDirByType($sImgType), 'oxcategories', $sField);
261 
262  $oItem->$sItemKey = new oxField();
263  $oItem->save();
264  }
265  }
266 }