OXID eShop CE  4.8.12
 All Classes Files Functions Variables Pages
article_variant.php
Go to the documentation of this file.
1 <?php
2 
9 {
15  protected $_oProductParent = null;
16 
23  public function render()
24  {
26 
27  $soxId = $this->getEditObjectId();
28  $sSLViewName = getViewName('oxselectlist');
29 
30  // all selectlists
31  $oAllSel = oxNew( "oxlist");
32  $oAllSel->init( "oxselectlist");
33  $sQ = "select * from $sSLViewName";
34  $oAllSel->selectString( $sQ);
35  $this->_aViewData["allsel"] = $oAllSel;
36 
37  $oArticle = oxNew( "oxarticle");
38  $this->_aViewData["edit"] = $oArticle;
39 
40  if ( $soxId != "-1" && isset( $soxId)) {
41  // load object
42  $oArticle->loadInLang( $this->_iEditLang, $soxId );
43 
44 
45  $_POST["language"] = $_GET["language"] = $this->_iEditLang;
46  $oVariants = $oArticle->getAdminVariants( $this->_iEditLang);
47 
48  $this->_aViewData["mylist"] = $oVariants;
49 
50  // load object in other languages
51  $oOtherLang = $oArticle->getAvailableInLangs();
52  if (!isset($oOtherLang[ $this->_iEditLang])) {
53  // echo "language entry doesn't exist! using: ".key($oOtherLang);
54  $oArticle->loadInLang( key($oOtherLang), $soxId );
55  }
56 
57  foreach ( $oOtherLang as $id => $language) {
58  $oLang= new stdClass();
59  $oLang->sLangDesc = $language;
60  $oLang->selected = ($id == $this->_iEditLang);
61  $this->_aViewData["otherlang"][$id] = clone $oLang;
62  }
63 
64  if ( $oArticle->oxarticles__oxparentid->value) {
65  $this->_aViewData["parentarticle"] = $this->_getProductParent( $oArticle->oxarticles__oxparentid->value );
66  $this->_aViewData["oxparentid"] = $oArticle->oxarticles__oxparentid->value;
67  $this->_aViewData["issubvariant"] = 1;
68  // A. disable variant information editing for variant
69  $this->_aViewData["readonly"] = 1;
70  }
71  $this->_aViewData["editlanguage"] = $this->_iEditLang;
72 
73  $aLang = array_diff (oxRegistry::getLang()->getLanguageNames(), $oOtherLang);
74  if ( count( $aLang))
75  $this->_aViewData["posslang"] = $aLang;
76 
77  foreach ( $oOtherLang as $id => $language) {
78  $oLang= new stdClass();
79  $oLang->sLangDesc = $language;
80  $oLang->selected = ($id == $this->_iEditLang);
81  $this->_aViewData["otherlang"][$id] = $oLang;
82  }
83  }
84 
85  return "article_variant.tpl";
86  }
87 
96  public function savevariant($sOXID = null, $aParams = null)
97  {
98  if ( !isset( $sOXID ) && !isset( $aParams ) ) {
99  $sOXID = oxConfig::getParameter( "voxid" );
100  $aParams = oxConfig::getParameter( "editval" );
101  }
102 
103  // checkbox handling
104  if ( !isset( $aParams['oxarticles__oxactive'] ) ) {
105  $aParams['oxarticles__oxactive'] = 0;
106  }
107 
108  // shopid
109  $aParams['oxarticles__oxshopid'] = oxSession::getVar( "actshop" );
110 
111  // varianthandling
112  $soxparentId = $this->getEditObjectId();
113  if ( isset( $soxparentId) && $soxparentId && $soxparentId != "-1" ) {
114  $aParams['oxarticles__oxparentid'] = $soxparentId;
115  } else {
116  unset( $aParams['oxarticles__oxparentid'] );
117  }
118 
119  $oArticle = oxNew( "oxarticle");
120 
121  /*
122  //TODO: solve this from lazy loading point of view
123  //acessing main fields for lazy loading mechnism to iniatialise them
124  $oArticle->oxarticles__oxvarselect->value;
125  $oArticle->oxarticles__oxartnum->value;
126  $oArticle->oxarticles__oxprice->value;
127  $oArticle->oxarticles__oxstock->value;
128  $oArticle->oxarticles__oxshopid->value;
129  $oArticle->oxarticles__oxshopincl->value;
130  $oArticle->oxarticles__oxshopexcl->value;*/
131 
132  if ( $sOXID != "-1" ) {
133  $oArticle->loadInLang( $this->_iEditLang, $sOXID );
134  }
135 
136  $oArticle->setLanguage( 0 );
137  $oArticle->assign( $aParams );
138  $oArticle->setLanguage( $this->_iEditLang );
139 
140  // #0004473
141  $oArticle->resetRemindStatus();
142 
143  if ( $sOXID == "-1" ) {
144  if ( $oParent = $this->_getProductParent( $oArticle->oxarticles__oxparentid->value ) ) {
145 
146  // assign field from parent for new variant
147  // #4406
148  $oArticle->oxarticles__oxisconfigurable = new oxField( $oParent->oxarticles__oxisconfigurable->value );
149  $oArticle->oxarticles__oxremindactive = new oxField( $oParent->oxarticles__oxremindactive->value );
150 
151  }
152  }
153 
154  $oArticle->save();
155  }
156 
164  protected function _getProductParent( $sParentId )
165  {
166  if ( $this->_oProductParent === null ||
167  ( $this->_oProductParent !== false && $this->_oProductParent->getId() != $sParentId ) ) {
168  $this->_oProductParent = false;
169  $oProduct = oxNew( "oxarticle" );
170  if ( $oProduct->load( $sParentId ) ) {
171  $this->_oProductParent = $oProduct;
172  }
173  }
174  return $this->_oProductParent;
175  }
176 
182  public function savevariants()
183  {
184 
185  $aParams = oxConfig::getParameter( "editval" );
186  if ( is_array( $aParams ) ) {
187  foreach ( $aParams as $soxId => $aVarParams ) {
188  $this->savevariant( $soxId, $aVarParams );
189  }
190  }
191 
192  }
193 
199  public function deleteVariant()
200  {
201 
202 
203  $soxId = oxConfig::getParameter( "voxid" );
204  $oDelete = oxNew( "oxarticle" );
205  $oDelete->delete( $soxId );
206  }
207 
213  public function changename()
214  {
215  $soxId = $this->getEditObjectId();
216  $aParams = oxConfig::getParameter( "editval");
217 
218 
219  // shopid
220  $aParams['oxarticles__oxshopid'] = oxSession::getVar( "actshop" );
221 
222  $oArticle = oxNew( "oxarticle" );
223  if ( $soxId != "-1") {
224  $oArticle->loadInLang( $this->_iEditLang, $soxId );
225  }
226 
227  $oArticle->setLanguage( 0 );
228  $oArticle->assign( $aParams);
229  $oArticle->setLanguage( $this->_iEditLang );
230  $oArticle->save();
231  }
232 
233 
239  public function addsel()
240  {
241  $oArticle = oxNew("oxarticle");
242  //#3644
243  //$oArticle->setEnableMultilang( false );
244  if ( $oArticle->load( $this->getEditObjectId() ) ) {
245 
246 
247 
248  if ( $aSels = oxConfig::getParameter( "allsel" ) ) {
249  $oVariantHandler = oxNew( "oxVariantHandler" );
250  $oVariantHandler->genVariantFromSell( $aSels, $oArticle );
251  }
252  }
253  }
254 }