discount_item_ajax.php

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