OXID eShop CE  4.9.5
 All Classes Files Functions Variables Pages
article_variant.php
Go to the documentation of this file.
1 <?php
2 
9 {
10 
16  protected $_oProductParent = null;
17 
24  public function render()
25  {
27 
28  $soxId = $this->getEditObjectId();
29  $sSLViewName = getViewName('oxselectlist');
30 
31  // all selectlists
32  $oAllSel = oxNew("oxlist");
33  $oAllSel->init("oxselectlist");
34  $sQ = "select * from $sSLViewName";
35  $oAllSel->selectString($sQ);
36  $this->_aViewData["allsel"] = $oAllSel;
37 
38  $oArticle = oxNew("oxarticle");
39  $this->_aViewData["edit"] = $oArticle;
40 
41  if ($soxId != "-1" && isset($soxId)) {
42  // load object
43  $oArticle->loadInLang($this->_iEditLang, $soxId);
44 
45 
46  $_POST["language"] = $_GET["language"] = $this->_iEditLang;
47  $oVariants = $oArticle->getAdminVariants($this->_iEditLang);
48 
49  $this->_aViewData["mylist"] = $oVariants;
50 
51  // load object in other languages
52  $oOtherLang = $oArticle->getAvailableInLangs();
53  if (!isset($oOtherLang[$this->_iEditLang])) {
54  // echo "language entry doesn't exist! using: ".key($oOtherLang);
55  $oArticle->loadInLang(key($oOtherLang), $soxId);
56  }
57 
58  foreach ($oOtherLang as $id => $language) {
59  $oLang = new stdClass();
60  $oLang->sLangDesc = $language;
61  $oLang->selected = ($id == $this->_iEditLang);
62  $this->_aViewData["otherlang"][$id] = clone $oLang;
63  }
64 
65  if ($oArticle->oxarticles__oxparentid->value) {
66  $this->_aViewData["parentarticle"] = $this->_getProductParent($oArticle->oxarticles__oxparentid->value);
67  $this->_aViewData["oxparentid"] = $oArticle->oxarticles__oxparentid->value;
68  $this->_aViewData["issubvariant"] = 1;
69  // A. disable variant information editing for variant
70  $this->_aViewData["readonly"] = 1;
71  }
72  $this->_aViewData["editlanguage"] = $this->_iEditLang;
73 
74  $aLang = array_diff(oxRegistry::getLang()->getLanguageNames(), $oOtherLang);
75  if (count($aLang)) {
76  $this->_aViewData["posslang"] = $aLang;
77  }
78 
79  foreach ($oOtherLang as $id => $language) {
80  $oLang = new stdClass();
81  $oLang->sLangDesc = $language;
82  $oLang->selected = ($id == $this->_iEditLang);
83  $this->_aViewData["otherlang"][$id] = $oLang;
84  }
85  }
86 
87  return "article_variant.tpl";
88  }
89 
98  public function savevariant($sOXID = null, $aParams = null)
99  {
100  if (!isset($sOXID) && !isset($aParams)) {
101  $sOXID = oxRegistry::getConfig()->getRequestParameter("voxid");
102  $aParams = oxRegistry::getConfig()->getRequestParameter("editval");
103  }
104 
105  // shopid
106  $aParams['oxarticles__oxshopid'] = oxRegistry::getSession()->getVariable("actshop");
107 
108  // varianthandling
109  $soxparentId = $this->getEditObjectId();
110  if (isset($soxparentId) && $soxparentId && $soxparentId != "-1") {
111  $aParams['oxarticles__oxparentid'] = $soxparentId;
112  } else {
113  unset($aParams['oxarticles__oxparentid']);
114  }
116  $oArticle = oxNew("oxarticle");
117 
118  if ($sOXID != "-1") {
119  $oArticle->loadInLang($this->_iEditLang, $sOXID);
120  }
121 
122  // checkbox handling
123  if (is_array($aParams) && !isset($aParams['oxarticles__oxactive'])) {
124  $aParams['oxarticles__oxactive'] = 0;
125  }
126 
127  if (!$this->_isAnythingChanged($oArticle, $aParams)) {
128  return;
129  }
130 
131  $oArticle->setLanguage(0);
132  $oArticle->assign($aParams);
133  $oArticle->setLanguage($this->_iEditLang);
134 
135  // #0004473
136  $oArticle->resetRemindStatus();
137 
138  if ($sOXID == "-1") {
139  if ($oParent = $this->_getProductParent($oArticle->oxarticles__oxparentid->value)) {
140 
141  // assign field from parent for new variant
142  // #4406
143  $oArticle->oxarticles__oxisconfigurable = new oxField($oParent->oxarticles__oxisconfigurable->value);
144  $oArticle->oxarticles__oxremindactive = new oxField($oParent->oxarticles__oxremindactive->value);
145  }
146  }
147 
148  $oArticle->save();
149  }
150 
159  protected function _isAnythingChanged($oProduct, $aData)
160  {
161  if (!is_array($aData)) {
162  return true;
163  }
164  foreach ($aData as $sKey => $sValue) {
165  if (isset($oProduct->$sKey) && $oProduct->$sKey->value != $aData[$sKey]) {
166  return true;
167  }
168  }
169 
170  return false;
171  }
172 
180  protected function _getProductParent($sParentId)
181  {
182  if ($this->_oProductParent === null ||
183  ($this->_oProductParent !== false && $this->_oProductParent->getId() != $sParentId)
184  ) {
185  $this->_oProductParent = false;
186  $oProduct = oxNew("oxarticle");
187  if ($oProduct->load($sParentId)) {
188  $this->_oProductParent = $oProduct;
189  }
190  }
191 
192  return $this->_oProductParent;
193  }
194 
198  public function savevariants()
199  {
200 
201  $aParams = oxRegistry::getConfig()->getRequestParameter("editval");
202  if (is_array($aParams)) {
203  foreach ($aParams as $soxId => $aVarParams) {
204  $this->savevariant($soxId, $aVarParams);
205  }
206  }
207 
208  $this->resetContentCache();
209  }
210 
216  public function deleteVariant()
217  {
218 
219  $this->resetContentCache();
220 
221  $soxId = oxRegistry::getConfig()->getRequestParameter("voxid");
222  $oDelete = oxNew("oxarticle");
223  $oDelete->delete($soxId);
224  }
225 
229  public function changename()
230  {
231  $soxId = $this->getEditObjectId();
232  $aParams = oxRegistry::getConfig()->getRequestParameter("editval");
233 
234  $this->resetContentCache();
235 
236  // shopid
237  $aParams['oxarticles__oxshopid'] = oxRegistry::getSession()->getVariable("actshop");
238 
239  $oArticle = oxNew("oxarticle");
240  if ($soxId != "-1") {
241  $oArticle->loadInLang($this->_iEditLang, $soxId);
242  }
243 
244  $oArticle->setLanguage(0);
245  $oArticle->assign($aParams);
246  $oArticle->setLanguage($this->_iEditLang);
247  $oArticle->save();
248  }
249 
250 
256  public function addsel()
257  {
258  $oArticle = oxNew("oxarticle");
259  //#3644
260  //$oArticle->setEnableMultilang( false );
261  if ($oArticle->load($this->getEditObjectId())) {
262 
263 
264  $this->resetContentCache();
265 
266  if ($aSels = oxRegistry::getConfig()->getRequestParameter("allsel")) {
267  $oVariantHandler = oxNew("oxVariantHandler");
268  $oVariantHandler->genVariantFromSell($aSels, $oArticle);
269  }
270  }
271  }
272 }