discount_item_ajax.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class discount_item_ajax extends ajaxListComponent
00007 {
00008 
00014     protected $_aColumns = array('container1' => array( // field , table,         visible, multilanguage, ident
00015         array('oxartnum', 'oxarticles', 1, 0, 0),
00016         array('oxtitle', 'oxarticles', 1, 1, 0),
00017         array('oxean', 'oxarticles', 1, 0, 0),
00018         array('oxmpn', 'oxarticles', 0, 0, 0),
00019         array('oxprice', 'oxarticles', 0, 0, 0),
00020         array('oxstock', 'oxarticles', 0, 0, 0),
00021         array('oxid', 'oxarticles', 0, 0, 1)
00022     ),
00023                                  'container2' => array(
00024                                      array('oxartnum', 'oxarticles', 1, 0, 0),
00025                                      array('oxtitle', 'oxarticles', 1, 1, 0),
00026                                      array('oxean', 'oxarticles', 1, 0, 0),
00027                                      array('oxmpn', 'oxarticles', 0, 0, 0),
00028                                      array('oxprice', 'oxarticles', 0, 0, 0),
00029                                      array('oxstock', 'oxarticles', 0, 0, 0),
00030                                      array('oxitmartid', 'oxdiscount', 0, 0, 1)
00031                                  )
00032     );
00033 
00039     protected function _getQuery()
00040     {
00041         $oConfig = $this->getConfig();
00042 
00043         $sArticleTable = $this->_getViewName('oxarticles');
00044         $sCatTable = $this->_getViewName('oxcategories');
00045         $sO2CView = $this->_getViewName('oxobject2category');
00046         $sDiscTable = $this->_getViewName('oxdiscount');
00047         $oDb = oxDb::getDb();
00048         $sOxid = $oConfig->getRequestParameter('oxid');
00049         $sSynchOxid = $oConfig->getRequestParameter('synchoxid');
00050 
00051         // category selected or not ?
00052         if (!$sOxid && $sSynchOxid) {
00053             $sQAdd = " from $sArticleTable where 1 ";
00054             $sQAdd .= $oConfig->getConfigParam('blVariantsSelection') ? '' : "and $sArticleTable.oxparentid = '' ";
00055         } else {
00056             // selected category ?
00057             if ($sSynchOxid && $sOxid != $sSynchOxid) {
00058                 $sQAdd = " from $sO2CView left join $sArticleTable on ";
00059                 $sQAdd .= $oConfig->getConfigParam('blVariantsSelection') ? "($sArticleTable.oxid=$sO2CView.oxobjectid or $sArticleTable.oxparentid=$sO2CView.oxobjectid)" : " $sArticleTable.oxid=$sO2CView.oxobjectid ";
00060                 $sQAdd .= " where $sO2CView.oxcatnid = " . $oDb->quote($sOxid) . " and $sArticleTable.oxid is not null ";
00061 
00062                 // resetting
00063                 $sId = null;
00064             } else {
00065                 $sQAdd = " from $sDiscTable left join $sArticleTable on $sArticleTable.oxid=$sDiscTable.oxitmartid ";
00066                 $sQAdd .= " where $sDiscTable.oxid = " . $oDb->quote($sOxid) . " and $sDiscTable.oxitmartid != '' ";
00067             }
00068         }
00069 
00070         if ($sSynchOxid && $sSynchOxid != $sOxid) {
00071             // performance
00072             $sSubSelect .= " select $sArticleTable.oxid from $sDiscTable, $sArticleTable where $sArticleTable.oxid=$sDiscTable.oxitmartid ";
00073             $sSubSelect .= " and $sDiscTable.oxid = " . $oDb->quote($sSynchOxid);
00074 
00075             if (stristr($sQAdd, 'where') === false) {
00076                 $sQAdd .= ' where ';
00077             } else {
00078                 $sQAdd .= ' and ';
00079             }
00080             $sQAdd .= " $sArticleTable.oxid not in ( $sSubSelect ) ";
00081         }
00082 
00083         return $sQAdd;
00084     }
00085 
00089     public function removeDiscArt()
00090     {
00091         $soxId = $this->getConfig()->getRequestParameter('oxid');
00092         $aChosenArt = $this->_getActionIds('oxdiscount.oxitmartid');
00093         if (is_array($aChosenArt)) {
00094             $sQ = "update oxdiscount set oxitmartid = '' where oxid = ? and oxitmartid = ?";
00095             oxDb::getDb()->execute($sQ, array($soxId, reset($aChosenArt)));
00096         }
00097     }
00098 
00102     public function addDiscArt()
00103     {
00104         $aChosenArt = $this->_getActionIds('oxarticles.oxid');
00105         $soxId = $this->getConfig()->getRequestParameter('synchoxid');
00106         if ($soxId && $soxId != "-1" && is_array($aChosenArt)) {
00107             $sQ = "update oxdiscount set oxitmartid = ? where oxid = ?";
00108             oxDb::getDb()->execute($sQ, array(reset($aChosenArt), $soxId));
00109         }
00110     }
00111 
00118     protected function _getQueryCols()
00119     {
00120         $oConfig = $this->getConfig();
00121         $sLangTag = oxRegistry::getLang()->getLanguageTag();
00122 
00123         $sQ = '';
00124         $blSep = false;
00125         $aVisiblecols = $this->_getVisibleColNames();
00126         foreach ($aVisiblecols as $iCnt => $aCol) {
00127             if ($blSep) {
00128                 $sQ .= ', ';
00129             }
00130             $sViewTable = $this->_getViewName($aCol[1]);
00131             // multilanguage
00132 
00133             $sCol = $aCol[3] ? $aCol[0] : $aCol[0];
00134 
00135             if ($oConfig->getConfigParam('blVariantsSelection') && $aCol[0] == 'oxtitle') {
00136                 $sVarSelect = "$sViewTable.oxvarselect" . $sLangTag;
00137                 $sQ .= " IF( $sViewTable.$sCol != '', $sViewTable.$sCol, CONCAT((select oxart.$sCol from $sViewTable as oxart where oxart.oxid = $sViewTable.oxparentid),', ',$sVarSelect)) as _" . $iCnt;
00138             } else {
00139                 $sQ .= $sViewTable . '.' . $sCol . ' as _' . $iCnt;
00140             }
00141 
00142             $blSep = true;
00143         }
00144 
00145         $aIdentCols = $this->_getIdentColNames();
00146         foreach ($aIdentCols as $iCnt => $aCol) {
00147             if ($blSep) {
00148                 $sQ .= ', ';
00149             }
00150 
00151             // multilanguage
00152             $sCol = $aCol[3] ? $aCol[0] : $aCol[0];
00153             $sQ .= $this->_getViewName($aCol[1]) . '.' . $sCol . ' as _' . $iCnt;
00154         }
00155 
00156         return " $sQ ";
00157     }
00158 }