OXID eShop CE  4.8.11
 All Classes Files Functions Variables Pages
category_main_ajax.php
Go to the documentation of this file.
1 <?php
2 
7 {
13  protected $_blAllowExtColumns = true;
14 
20  protected $_aColumns = array( 'container1' => array( // field , table, visible, multilanguage, ident
21  array( 'oxartnum', 'oxarticles', 1, 0, 0 ),
22  array( 'oxtitle', 'oxarticles', 1, 1, 0 ),
23  array( 'oxean', 'oxarticles', 1, 0, 0 ),
24  array( 'oxmpn', 'oxarticles', 0, 0, 0 ),
25  array( 'oxprice', 'oxarticles', 0, 0, 0 ),
26  array( 'oxstock', 'oxarticles', 0, 0, 0 ),
27  array( 'oxid', 'oxarticles', 0, 0, 1 )
28  ),
29  'container2' => array(
30  array( 'oxartnum', 'oxarticles', 1, 0, 0 ),
31  array( 'oxtitle', 'oxarticles', 1, 1, 0 ),
32  array( 'oxean', 'oxarticles', 1, 0, 0 ),
33  array( 'oxmpn', 'oxarticles', 0, 0, 0 ),
34  array( 'oxprice', 'oxarticles', 0, 0, 0 ),
35  array( 'oxstock', 'oxarticles', 0, 0, 0 ),
36  array( 'oxid', 'oxarticles', 0, 0, 1 )
37  )
38  );
39 
45  protected function _getQuery()
46  {
47  $myConfig = $this->getConfig();
48 
49  $sArticleTable = $this->_getViewName('oxarticles');
50  $sO2CView = $this->_getViewName('oxobject2category');
51 
52  $sOxid = oxConfig::getParameter( 'oxid' );
53  $sSynchOxid = oxConfig::getParameter( 'synchoxid' );
54  $oDb = oxDb::getDb();
55 
56  $sShopID = $myConfig->getShopId();
57 
58  // category selected or not ?
59  if ( !$sOxid && $sSynchOxid ) {
60 
61  // dodger performance
62  $sQAdd = ' from '.$sArticleTable.' where 1 ';
63  } else {
64 
65  // copied from oxadminview
66  $sJoin = " {$sArticleTable}.oxid={$sO2CView}.oxobjectid ";
67 
68  $sSubSelect = '';
69  if ( $sSynchOxid && $sOxid != $sSynchOxid ) {
70 
71  $sSubSelect = ' and '.$sArticleTable.'.oxid not in ( ';
72  $sSubSelect .= "select $sArticleTable.oxid from $sO2CView left join $sArticleTable ";
73  $sSubSelect .= "on $sJoin where $sO2CView.oxcatnid = " . $oDb->quote( $sSynchOxid ) . " ";
74  $sSubSelect .= 'and '.$sArticleTable.'.oxid is not null ) ';
75  }
76 
77  $sQAdd = " from $sO2CView join $sArticleTable ";
78  $sQAdd .= " on $sJoin where $sO2CView.oxcatnid = " . $oDb->quote( $sOxid );
79  $sQAdd .= " and $sArticleTable.oxid is not null $sSubSelect ";
80  }
81 
82  return $sQAdd;
83  }
84 
92  protected function _addFilter( $sQ )
93  {
94  $sArtTable = $this->_getViewName('oxarticles');
95  $sQ = parent::_addFilter( $sQ );
96 
97  // display variants or not ?
98  if ( !$this->getConfig()->getConfigParam( 'blVariantsSelection' ) ) {
99  $sQ .= " and {$sArtTable}.oxparentid = '' ";
100  }
101 
102  return $sQ;
103  }
104 
111  public function addArticle()
112  {
113  $myConfig = $this->getConfig();
114 
115  $aArticles = $this->_getActionIds( 'oxarticles.oxid' );
116  $sCategoryID = oxConfig::getParameter( 'synchoxid');
117  $sShopID = $myConfig->getShopId();
118  $oDb = oxDb::getDb();
119  $sArticleTable = $this->_getViewName( 'oxarticles' );
120 
121  // adding
122  if ( oxConfig::getParameter( 'all' ) ) {
123  $aArticles = $this->_getAll( $this->_addFilter( "select $sArticleTable.oxid ".$this->_getQuery() ) );
124  }
125 
126  if ( is_array($aArticles)) {
127 
128 
129  $sO2CView = $this->_getViewName('oxobject2category');
130 
131  $oNew = oxNew( 'oxbase' );
132  $oNew->init( 'oxobject2category' );
133  $myUtilsObject = oxUtilsObject::getInstance();
134  $oActShop = $myConfig->getActiveShop();
135 
136  $sProdIds = "";
137  foreach ( $aArticles as $sAdd) {
138 
139  // check, if it's already in, then don't add it again
140  $sSelect = "select 1 from $sO2CView as oxobject2category where oxobject2category.oxcatnid= " . $oDb->quote( $sCategoryID ) . " and oxobject2category.oxobjectid = " . $oDb->quote( $sAdd ) . "";
141  if ( $oDb->getOne( $sSelect, false, false ) )
142  continue;
143 
144  $oNew->oxobject2category__oxid = new oxField( $oNew->setId( $myUtilsObject->generateUID() ) );
145  $oNew->oxobject2category__oxobjectid = new oxField( $sAdd );
146  $oNew->oxobject2category__oxcatnid = new oxField( $sCategoryID );
147  $oNew->oxobject2category__oxtime = new oxField( time() );
148 
149  $oNew->save();
150 
151  if ( $sProdIds ) {
152  $sProdIds .= ",";
153  }
154  $sProdIds .= $oDb->quote( $sAdd ) ;
155  }
156 
157  // updating oxtime values
158  $this->_updateOxTime( $sProdIds );
159 
160  $this->resetArtSeoUrl( $aArticles );
161  $this->resetCounter( "catArticle", $sCategoryID );
162 
163 
164  }
165  }
166 
174  protected function _updateOxTime( $sProdIds )
175  {
176  if ( $sProdIds ) {
177  $sO2CView = $this->_getViewName('oxobject2category');
178  $sQ = "update oxobject2category set oxtime = 0 where oxid in (
179  select _tmp.oxid from (
180  select oxobject2category.oxid from (
181  select min(oxtime) as oxtime, oxobjectid from {$sO2CView} where oxobjectid in ( {$sProdIds} ) group by oxobjectid
182  ) as _subtmp
183  left join oxobject2category on oxobject2category.oxtime = _subtmp.oxtime and oxobject2category.oxobjectid = _subtmp.oxobjectid
184  ) as _tmp
185  )";
186 
187  oxDb::getDb()->execute( $sQ );
188  }
189  }
190 
196  public function removeArticle()
197  {
198  $aArticles = $this->_getActionIds( 'oxarticles.oxid' );
199  $sCategoryID = oxConfig::getParameter( 'oxid');
200  $sShopID = $this->getConfig()->getShopId();
201  $oDb = oxDb::getDb();
202 
203  // adding
204  if ( oxConfig::getParameter( 'all' ) ) {
205  $sArticleTable = $this->_getViewName( 'oxarticles' );
206  $aArticles = $this->_getAll( $this->_addFilter( "select $sArticleTable.oxid ".$this->_getQuery() ) );
207  }
208 
209  // adding
210  if ( is_array( $aArticles ) && count( $aArticles ) ) {
211  $sProdIds = implode( ", ", oxDb::getInstance()->quoteArray( $aArticles ) );
212 
213  $sDelete = "delete from oxobject2category where";
214  $sWhere = " oxcatnid=".$oDb->quote( $sCategoryID );
215  if ( !$this->getConfig()->getConfigParam( 'blVariantsSelection' ) ) {
216  $sQ = $sDelete.$sWhere." and oxobjectid in ( select oxid from oxarticles where oxparentid in ( {$sProdIds} ) )";
217  $oDb->execute( $sQ );
218  }
219  $sQ = $sDelete.$sWhere." and oxobjectid in ( {$sProdIds} )";
220  $oDb->execute( $sQ );
221 
222 
223  // updating oxtime values
224  $this->_updateOxTime( $sProdIds );
225  }
226 
227  $this->resetArtSeoUrl( $aArticles, $sCategoryID );
228  $this->resetCounter( "catArticle", $sCategoryID );
229 
230  }
231 }