discount_articles.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( 'oxid',     'oxobject2discount', 0, 0, 1 )
00020                                         )
00021                     );
00022 
00026 class ajaxComponent extends ajaxListComponent
00027 {
00033     protected function _getQuery()
00034     {
00035         $myConfig = $this->getConfig();
00036 
00037         $sArticleTable = getViewName('oxarticles');
00038         $sCatTable     = getViewName('oxcategories');
00039         $sO2CView      = getViewName('oxobject2category');
00040 
00041         $sOxid      = oxConfig::getParameter( 'oxid' );
00042         $sSynchOxid = oxConfig::getParameter( 'synchoxid' );
00043 
00044         // category selected or not ?
00045         if ( !$sOxid && $sSynchOxid ) {
00046             $sQAdd  = " from $sArticleTable where 1 ";
00047             $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection' )?'':"and $sArticleTable.oxparentid = '' ";
00048         } else {
00049             // selected category ?
00050             if ( $sSynchOxid && $sOxid != $sSynchOxid ) {
00051                 $sQAdd  = " from $sO2CView left join $sArticleTable on ";
00052                 $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection' )?"($sArticleTable.oxid=$sO2CView.oxobjectid or $sArticleTable.oxparentid=$sO2CView.oxobjectid)":" $sArticleTable.oxid=$sO2CView.oxobjectid ";
00053                 $sQAdd .= " where $sO2CView.oxcatnid = '$sOxid' and $sArticleTable.oxid is not null ";
00054 
00055                 // resetting
00056                 $sId = null;
00057             } else {
00058                 $sQAdd  = " from oxobject2discount, $sArticleTable where $sArticleTable.oxid=oxobject2discount.oxobjectid ";
00059                 $sQAdd .= " and oxobject2discount.oxdiscountid = '$sOxid' and oxobject2discount.oxtype = 'oxarticles' ";
00060             }
00061         }
00062 
00063         if ( $sSynchOxid && $sSynchOxid != $sOxid) {
00064             // dodger performance
00065             $sSubSelect .= " select $sArticleTable.oxid from oxobject2discount, $sArticleTable where $sArticleTable.oxid=oxobject2discount.oxobjectid ";
00066             $sSubSelect .= " and oxobject2discount.oxdiscountid = '$sSynchOxid' and oxobject2discount.oxtype = 'oxarticles' ";
00067 
00068             if ( stristr( $sQAdd, 'where' ) === false )
00069                 $sQAdd .= ' where ';
00070             else
00071                 $sQAdd .= ' and ';
00072             $sQAdd .= " $sArticleTable.oxid not in ( $sSubSelect ) ";
00073         }
00074 
00075         return $sQAdd;
00076     }
00077 
00085     protected function _addFilter( $sQ )
00086     {
00087         $sArtTable = getViewName('oxarticles');
00088         $sQ = parent::_addFilter( $sQ );
00089 
00090         // display variants or not ?
00091         $sQ .= $this->getConfig()->getConfigParam( 'blVariantsSelection' ) ? ' group by '.$sArtTable.'.oxid ' : '';
00092         return $sQ;
00093     }
00094 
00100     public function removediscart()
00101     {
00102         $aChosenArt = $this->_getActionIds( 'oxobject2discount.oxid' );
00103         if ( oxConfig::getParameter( 'all' ) ) {
00104 
00105             $sQ = $this->_addFilter( "delete oxobject2discount.* ".$this->_getQuery() );
00106             oxDb::getDb()->Execute( $sQ );
00107 
00108         } elseif ( is_array( $aChosenArt ) ) {
00109             $sQ = "delete from oxobject2discount where oxobject2discount.oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aChosenArt ) ) . ") ";
00110             oxDb::getDb()->Execute( $sQ );
00111         }
00112     }
00113 
00119     public function adddiscart()
00120     {
00121         $aChosenArt = $this->_getActionIds( 'oxarticles.oxid' );
00122         $soxId      = oxConfig::getParameter( 'synchoxid');
00123 
00124         // adding
00125         if ( oxConfig::getParameter( 'all' ) ) {
00126             $sArticleTable = getViewName('oxarticles');
00127             $aChosenArt = $this->_getAll( $this->_addFilter( "select $sArticleTable.oxid ".$this->_getQuery() ) );
00128         }
00129         if ( $soxId && $soxId != "-1" && is_array( $aChosenArt ) ) {
00130             foreach ( $aChosenArt as $sChosenArt) {
00131                 $oObject2Discount = oxNew( "oxbase" );
00132                 $oObject2Discount->init( 'oxobject2discount' );
00133                 $oObject2Discount->oxobject2discount__oxdiscountid = new oxField($soxId);
00134                 $oObject2Discount->oxobject2discount__oxobjectid   = new oxField($sChosenArt);
00135                 $oObject2Discount->oxobject2discount__oxtype       = new oxField("oxarticles");
00136                 $oObject2Discount->save();
00137             }
00138         }
00139     }
00140 
00147     protected function _getQueryCols()
00148     {
00149         $myConfig = $this->getConfig();
00150         $sLangTag = oxLang::getInstance()->getLanguageTag();
00151 
00152         $sQ = '';
00153         $blSep = false;
00154         $aVisiblecols = $this->_getVisibleColNames();
00155         foreach ( $aVisiblecols as $iCnt => $aCol ) {
00156             if ( $blSep )
00157                 $sQ .= ', ';
00158             $sViewTable = getViewName( $aCol[1] );
00159             // multilanguage
00160             $sCol = $aCol[3]?$aCol[0].$sLangTag:$aCol[0];
00161             if ( $myConfig->getConfigParam( 'blVariantsSelection' ) && $aCol[0] == 'oxtitle' ) {
00162                 $sVarSelect = "$sViewTable.oxvarselect".$sLangTag;
00163                 $sQ .= " IF( $sViewTable.$sCol != '', $sViewTable.$sCol, CONCAT((select oxart.$sCol from $sViewTable as oxart where oxart.oxid = $sViewTable.oxparentid),', ',$sVarSelect)) as _" . $iCnt;
00164             } else {
00165                 $sQ  .= $sViewTable . '.' . $sCol . ' as _' . $iCnt;
00166             }
00167             $blSep = true;
00168         }
00169 
00170         $aIdentCols = $this->_getIdentColNames();
00171         foreach ( $aIdentCols as $iCnt => $aCol ) {
00172             if ( $blSep )
00173                 $sQ .= ', ';
00174 
00175             // multilanguage
00176             $sCol = $aCol[3]?$aCol[0].$sLangTag:$aCol[0];
00177             $sQ  .= getViewName( $aCol[1] ) . '.' . $sCol . ' as _' . $iCnt;
00178         }
00179 
00180         return " $sQ ";
00181     }
00182 
00183 }

Generated by  doxygen 1.6.2