discount_item.inc.php

Go to the documentation of this file.
00001 <?php
00002 
00003 $aColumns = array( 'container1' => array(    // field , table,         visible, multilanguage, ident
00004                                         array( 'oxartnum', 'oxarticles', 1, 0, 0 ),
00005                                         array( 'oxtitle',  'oxarticles', 1, 1, 0 ),
00006                                         array( 'oxean',    'oxarticles', 1, 0, 0 ),
00007                                         array( 'oxmpn',    'oxarticles', 0, 0, 0 ),
00008                                         array( 'oxprice',  'oxarticles', 0, 0, 0 ),
00009                                         array( 'oxstock',  'oxarticles', 0, 0, 0 ),
00010                                         array( 'oxid',     'oxarticles', 0, 0, 1 )
00011                                         ),
00012                      'container2' => array(
00013                                         array( 'oxartnum',   'oxarticles', 1, 0, 0 ),
00014                                         array( 'oxtitle',    'oxarticles', 1, 1, 0 ),
00015                                         array( 'oxean',      'oxarticles', 1, 0, 0 ),
00016                                         array( 'oxmpn',      'oxarticles', 0, 0, 0 ),
00017                                         array( 'oxprice',    'oxarticles', 0, 0, 0 ),
00018                                         array( 'oxstock',    'oxarticles', 0, 0, 0 ),
00019                                         array( 'oxitmartid', 'oxdiscount', 0, 0, 1 )
00020                                         )
00021                     );
00022 
00026 class ajaxComponent extends ajaxListComponent
00027 {
00033     protected function _getQuery()
00034     {
00035         $myConfig = $this->getConfig();
00036 
00037         $sArticleTable = $this->_getViewName('oxarticles');
00038         $sCatTable     = $this->_getViewName('oxcategories');
00039         $sO2CView      = $this->_getViewName('oxobject2category');
00040         $sDiscTable    = $this->_getViewName('oxdiscount');
00041         $oDb = oxDb::getDb();
00042         $sOxid = oxConfig::getParameter( 'oxid' );
00043         $sSynchOxid = oxConfig::getParameter( 'synchoxid' );
00044 
00045         // category selected or not ?
00046         if ( !$sOxid && $sSynchOxid ) {
00047             $sQAdd  = " from $sArticleTable where 1 ";
00048             $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection' )?'':"and $sArticleTable.oxparentid = '' ";
00049         } else {
00050             // selected category ?
00051             if ( $sSynchOxid && $sOxid != $sSynchOxid ) {
00052                 $sQAdd  = " from $sO2CView left join $sArticleTable on ";
00053                 $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection' )?"($sArticleTable.oxid=$sO2CView.oxobjectid or $sArticleTable.oxparentid=$sO2CView.oxobjectid)":" $sArticleTable.oxid=$sO2CView.oxobjectid ";
00054                 $sQAdd .= " where $sO2CView.oxcatnid = ".$oDb->quote( $sOxid )." and $sArticleTable.oxid is not null ";
00055 
00056                 // resetting
00057                 $sId = null;
00058             } else {
00059                 $sQAdd  = " from $sDiscTable left join $sArticleTable on $sArticleTable.oxid=$sDiscTable.oxitmartid ";
00060                 $sQAdd .= " where $sDiscTable.oxid = ".$oDb->quote( $sOxid )." and $sDiscTable.oxitmartid != '' ";
00061             }
00062         }
00063 
00064         if ( $sSynchOxid && $sSynchOxid != $sOxid) {
00065             // dodger performance
00066             $sSubSelect .= " select $sArticleTable.oxid from $sDiscTable, $sArticleTable where $sArticleTable.oxid=$sDiscTable.oxitmartid ";
00067             $sSubSelect .= " and $sDiscTable.oxid = ".$oDb->quote( $sSynchOxid );
00068 
00069             if ( stristr( $sQAdd, 'where' ) === false )
00070                 $sQAdd .= ' where ';
00071             else
00072                 $sQAdd .= ' and ';
00073             $sQAdd .= " $sArticleTable.oxid not in ( $sSubSelect ) ";
00074         }
00075 
00076         return $sQAdd;
00077     }
00078 
00086     protected function _addFilter( $sQ )
00087     {
00088         $sArtTable = $this->_getViewName('oxarticles');
00089         $sQ = parent::_addFilter( $sQ );
00090 
00091         // display variants or not ?
00092         $sQ .= $this->getConfig()->getConfigParam( 'blVariantsSelection' ) ? ' group by '.$sArtTable.'.oxid ' : '';
00093         return $sQ;
00094     }
00095 
00101     public function removediscart()
00102     {
00103         $soxId      = oxConfig::getParameter( 'oxid');
00104         $aChosenArt = $this->_getActionIds( 'oxdiscount.oxitmartid' );
00105         if ( is_array( $aChosenArt ) ) {
00106             $sQ = "update oxdiscount set oxitmartid = '' where oxid = ? and oxitmartid = ?";
00107             oxDb::getDb()->execute( $sQ, array( $soxId, reset( $aChosenArt ) ) );
00108         }
00109     }
00110 
00116     public function adddiscart()
00117     {
00118         $aChosenArt = $this->_getActionIds( 'oxarticles.oxid' );
00119         $soxId      = oxConfig::getParameter( 'synchoxid');
00120         if ( $soxId && $soxId != "-1" && is_array( $aChosenArt ) ) {
00121             $sQ = "update oxdiscount set oxitmartid = ? where oxid = ?";
00122             oxDb::getDb()->execute( $sQ, array( reset( $aChosenArt ), $soxId ) );
00123         }
00124     }
00125 
00132     protected function _getQueryCols()
00133     {
00134         $myConfig = $this->getConfig();
00135         $sLangTag = oxLang::getInstance()->getLanguageTag();
00136 
00137         $sQ = '';
00138         $blSep = false;
00139         $aVisiblecols = $this->_getVisibleColNames();
00140         foreach ( $aVisiblecols as $iCnt => $aCol ) {
00141             if ( $blSep )
00142                 $sQ .= ', ';
00143             $sViewTable = $this->_getViewName( $aCol[1] );
00144             // multilanguage
00145 
00146             $sCol = $aCol[3] ? $aCol[0] : $aCol[0];
00147 
00148             if ( $myConfig->getConfigParam( 'blVariantsSelection' ) && $aCol[0] == 'oxtitle' ) {
00149                 $sVarSelect = "$sViewTable.oxvarselect".$sLangTag;
00150                 $sQ .= " IF( $sViewTable.$sCol != '', $sViewTable.$sCol, CONCAT((select oxart.$sCol from $sViewTable as oxart where oxart.oxid = $sViewTable.oxparentid),', ',$sVarSelect)) as _" . $iCnt;
00151             } else {
00152                 $sQ  .= $sViewTable . '.' . $sCol . ' as _' . $iCnt;
00153             }
00154 
00155             $blSep = true;
00156         }
00157 
00158         $aIdentCols = $this->_getIdentColNames();
00159         foreach ( $aIdentCols as $iCnt => $aCol ) {
00160             if ( $blSep )
00161                 $sQ .= ', ';
00162 
00163             // multilanguage
00164             $sCol = $aCol[3] ? $aCol[0] : $aCol[0];
00165             $sQ  .= $this->_getViewName( $aCol[1] ) . '.' . $sCol . ' as _' . $iCnt;
00166         }
00167 
00168         return " $sQ ";
00169     }
00170 
00171 }