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