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 
00084     public function removediscart()
00085     {
00086         $soxId      = oxConfig::getParameter( 'oxid');
00087         $aChosenArt = $this->_getActionIds( 'oxdiscount.oxitmartid' );
00088         if ( is_array( $aChosenArt ) ) {
00089             $sQ = "update oxdiscount set oxitmartid = '' where oxid = ? and oxitmartid = ?";
00090             oxDb::getDb()->execute( $sQ, array( $soxId, reset( $aChosenArt ) ) );
00091         }
00092     }
00093 
00099     public function adddiscart()
00100     {
00101         $aChosenArt = $this->_getActionIds( 'oxarticles.oxid' );
00102         $soxId      = oxConfig::getParameter( 'synchoxid');
00103         if ( $soxId && $soxId != "-1" && is_array( $aChosenArt ) ) {
00104             $sQ = "update oxdiscount set oxitmartid = ? where oxid = ?";
00105             oxDb::getDb()->execute( $sQ, array( reset( $aChosenArt ), $soxId ) );
00106         }
00107     }
00108 
00115     protected function _getQueryCols()
00116     {
00117         $myConfig = $this->getConfig();
00118         $sLangTag = oxLang::getInstance()->getLanguageTag();
00119 
00120         $sQ = '';
00121         $blSep = false;
00122         $aVisiblecols = $this->_getVisibleColNames();
00123         foreach ( $aVisiblecols as $iCnt => $aCol ) {
00124             if ( $blSep )
00125                 $sQ .= ', ';
00126             $sViewTable = $this->_getViewName( $aCol[1] );
00127             // multilanguage
00128 
00129             $sCol = $aCol[3] ? $aCol[0] : $aCol[0];
00130 
00131             if ( $myConfig->getConfigParam( 'blVariantsSelection' ) && $aCol[0] == 'oxtitle' ) {
00132                 $sVarSelect = "$sViewTable.oxvarselect".$sLangTag;
00133                 $sQ .= " IF( $sViewTable.$sCol != '', $sViewTable.$sCol, CONCAT((select oxart.$sCol from $sViewTable as oxart where oxart.oxid = $sViewTable.oxparentid),', ',$sVarSelect)) as _" . $iCnt;
00134             } else {
00135                 $sQ  .= $sViewTable . '.' . $sCol . ' as _' . $iCnt;
00136             }
00137 
00138             $blSep = true;
00139         }
00140 
00141         $aIdentCols = $this->_getIdentColNames();
00142         foreach ( $aIdentCols as $iCnt => $aCol ) {
00143             if ( $blSep )
00144                 $sQ .= ', ';
00145 
00146             // multilanguage
00147             $sCol = $aCol[3] ? $aCol[0] : $aCol[0];
00148             $sQ  .= $this->_getViewName( $aCol[1] ) . '.' . $sCol . ' as _' . $iCnt;
00149         }
00150 
00151         return " $sQ ";
00152     }
00153 
00154 }