OXID eShop CE  4.10.2
 All Classes Namespaces Files Functions Variables Pages
discount_item_ajax.php
Go to the documentation of this file.
1 <?php
2 
7 {
8 
14  protected $_aColumns = array('container1' => array( // field , table, visible, multilanguage, ident
15  array('oxartnum', 'oxarticles', 1, 0, 0),
16  array('oxtitle', 'oxarticles', 1, 1, 0),
17  array('oxean', 'oxarticles', 1, 0, 0),
18  array('oxmpn', 'oxarticles', 0, 0, 0),
19  array('oxprice', 'oxarticles', 0, 0, 0),
20  array('oxstock', 'oxarticles', 0, 0, 0),
21  array('oxid', 'oxarticles', 0, 0, 1)
22  ),
23  'container2' => array(
24  array('oxartnum', 'oxarticles', 1, 0, 0),
25  array('oxtitle', 'oxarticles', 1, 1, 0),
26  array('oxean', 'oxarticles', 1, 0, 0),
27  array('oxmpn', 'oxarticles', 0, 0, 0),
28  array('oxprice', 'oxarticles', 0, 0, 0),
29  array('oxstock', 'oxarticles', 0, 0, 0),
30  array('oxitmartid', 'oxdiscount', 0, 0, 1)
31  )
32  );
33 
39  protected function _getQuery()
40  {
41  $oConfig = $this->getConfig();
42 
43  $sArticleTable = $this->_getViewName('oxarticles');
44  $sCatTable = $this->_getViewName('oxcategories');
45  $sO2CView = $this->_getViewName('oxobject2category');
46  $sDiscTable = $this->_getViewName('oxdiscount');
47  $oDb = oxDb::getDb();
48  $sOxid = $oConfig->getRequestParameter('oxid');
49  $sSynchOxid = $oConfig->getRequestParameter('synchoxid');
50 
51  // category selected or not ?
52  if (!$sOxid && $sSynchOxid) {
53  $sQAdd = " from $sArticleTable where 1 ";
54  $sQAdd .= $oConfig->getConfigParam('blVariantsSelection') ? '' : "and $sArticleTable.oxparentid = '' ";
55 
56  //#6027
57  //if we have variants then depending on config option the parent may be non buyable
58  //when the checkbox is checked, blVariantParentBuyable is true.
59  $sQAdd .= $oConfig->getConfigParam('blVariantParentBuyable') ? '' : "and $sArticleTable.oxvarcount = 0";
60  } else {
61  // selected category ?
62  if ($sSynchOxid && $sOxid != $sSynchOxid) {
63  $sQAdd = " from $sO2CView left join $sArticleTable on ";
64  $sQAdd .= $oConfig->getConfigParam('blVariantsSelection') ? "($sArticleTable.oxid=$sO2CView.oxobjectid or $sArticleTable.oxparentid=$sO2CView.oxobjectid)" : " $sArticleTable.oxid=$sO2CView.oxobjectid ";
65  $sQAdd .= " where $sO2CView.oxcatnid = " . $oDb->quote($sOxid) . " and $sArticleTable.oxid is not null ";
66  //#6027
67  $sQAdd .= $oConfig->getConfigParam('blVariantParentBuyable') ? '' : " and $sArticleTable.oxvarcount = 0";
68 
69  // resetting
70  $sId = null;
71  } else {
72  $sQAdd = " from $sDiscTable left join $sArticleTable on $sArticleTable.oxid=$sDiscTable.oxitmartid ";
73  $sQAdd .= " where $sDiscTable.oxid = " . $oDb->quote($sOxid) . " and $sDiscTable.oxitmartid != '' ";
74  }
75  }
76 
77  if ($sSynchOxid && $sSynchOxid != $sOxid) {
78  // performance
79  $sSubSelect .= " select $sArticleTable.oxid from $sDiscTable, $sArticleTable where $sArticleTable.oxid=$sDiscTable.oxitmartid ";
80  $sSubSelect .= " and $sDiscTable.oxid = " . $oDb->quote($sSynchOxid);
81 
82  if (stristr($sQAdd, 'where') === false) {
83  $sQAdd .= ' where ';
84  } else {
85  $sQAdd .= ' and ';
86  }
87  $sQAdd .= " $sArticleTable.oxid not in ( $sSubSelect ) ";
88  }
89 
90  return $sQAdd;
91  }
92 
96  public function removeDiscArt()
97  {
98  $soxId = $this->getConfig()->getRequestParameter('oxid');
99  $aChosenArt = $this->_getActionIds('oxdiscount.oxitmartid');
100  if (is_array($aChosenArt)) {
101  $sQ = "update oxdiscount set oxitmartid = '' where oxid = ? and oxitmartid = ?";
102  oxDb::getDb()->execute($sQ, array($soxId, reset($aChosenArt)));
103  }
104  }
105 
109  public function addDiscArt()
110  {
111  $aChosenArt = $this->_getActionIds('oxarticles.oxid');
112  $soxId = $this->getConfig()->getRequestParameter('synchoxid');
113  if ($soxId && $soxId != "-1" && is_array($aChosenArt)) {
114  $sQ = "update oxdiscount set oxitmartid = ? where oxid = ?";
115  oxDb::getDb()->execute($sQ, array(reset($aChosenArt), $soxId));
116  }
117  }
118 
125  protected function _getQueryCols()
126  {
127  $oConfig = $this->getConfig();
128  $sLangTag = oxRegistry::getLang()->getLanguageTag();
129 
130  $sQ = '';
131  $blSep = false;
132  $aVisiblecols = $this->_getVisibleColNames();
133  foreach ($aVisiblecols as $iCnt => $aCol) {
134  if ($blSep) {
135  $sQ .= ', ';
136  }
137  $sViewTable = $this->_getViewName($aCol[1]);
138  // multilanguage
139 
140  $sCol = $aCol[3] ? $aCol[0] : $aCol[0];
141 
142  if ($oConfig->getConfigParam('blVariantsSelection') && $aCol[0] == 'oxtitle') {
143  $sVarSelect = "$sViewTable.oxvarselect" . $sLangTag;
144  $sQ .= " IF( $sViewTable.$sCol != '', $sViewTable.$sCol, CONCAT((select oxart.$sCol from $sViewTable as oxart where oxart.oxid = $sViewTable.oxparentid),', ',$sVarSelect)) as _" . $iCnt;
145  } else {
146  $sQ .= $sViewTable . '.' . $sCol . ' as _' . $iCnt;
147  }
148 
149  $blSep = true;
150  }
151 
152  $aIdentCols = $this->_getIdentColNames();
153  foreach ($aIdentCols as $iCnt => $aCol) {
154  if ($blSep) {
155  $sQ .= ', ';
156  }
157 
158  // multilanguage
159  $sCol = $aCol[3] ? $aCol[0] : $aCol[0];
160  $sQ .= $this->_getViewName($aCol[1]) . '.' . $sCol . ' as _' . $iCnt;
161  }
162 
163  return " $sQ ";
164  }
165 }