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