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( 'oxprice',  'oxarticles', 0, 0, 0 ),
00008                                         array( 'oxstock',  'oxarticles', 0, 0, 0 ),
00009                                         array( 'oxid',     'oxarticles', 0, 0, 1 )
00010                                         ),
00011                      'container2' => array(
00012                                         array( 'oxartnum', 'oxarticles', 1, 0, 0 ),
00013                                         array( 'oxtitle',  'oxarticles', 1, 1, 0 ),
00014                                         array( 'oxean',    'oxarticles', 1, 0, 0 ),
00015                                         array( 'oxprice',  'oxarticles', 0, 0, 0 ),
00016                                         array( 'oxstock',  'oxarticles', 0, 0, 0 ),
00017                                         array( 'oxid',     'oxobject2discount', 0, 0, 1 )
00018                                         )
00019                     );
00020 
00024 class ajaxComponent extends ajaxListComponent
00025 {
00031     protected function _getQuery()
00032     {
00033         $myConfig = $this->getConfig();
00034 
00035         $sArticleTable = getViewName('oxarticles');
00036         $sCatTable     = getViewName('oxcategories');
00037         $sO2CView      = getViewName('oxobject2category');
00038 
00039         $sOxid      = oxConfig::getParameter( 'oxid' );
00040         $sSynchOxid = oxConfig::getParameter( 'synchoxid' );
00041 
00042         // category selected or not ?
00043         if ( !$sOxid && $sSynchOxid ) {
00044             $sQAdd  = " from $sArticleTable where 1 ";
00045             $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection' )?'':"and $sArticleTable.oxparentid = '' ";
00046         } else {
00047             // selected category ?
00048             if ( $sSynchOxid && $sOxid != $sSynchOxid ) {
00049                 $sQAdd  = " from $sO2CView left join $sArticleTable on ";
00050                 $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection' )?"($sArticleTable.oxid=$sO2CView.oxobjectid or $sArticleTable.oxparentid=$sO2CView.oxobjectid)":" $sArticleTable.oxid=$sO2CView.oxobjectid ";
00051                 $sQAdd .= " where $sO2CView.oxcatnid = '$sOxid' and $sArticleTable.oxid is not null ";
00052 
00053                 // resetting
00054                 $sId = null;
00055             } else {
00056                 $sQAdd  = " from oxobject2discount, $sArticleTable where $sArticleTable.oxid=oxobject2discount.oxobjectid ";
00057                 $sQAdd .= " and oxobject2discount.oxdiscountid = '$sOxid' and oxobject2discount.oxtype = 'oxarticles' ";
00058             }
00059         }
00060 
00061         if ( $sSynchOxid && $sSynchOxid != $sOxid) {
00062             // dodger performance
00063             $sSubSelect .= " select $sArticleTable.oxid from oxobject2discount, $sArticleTable where $sArticleTable.oxid=oxobject2discount.oxobjectid ";
00064             $sSubSelect .= " and oxobject2discount.oxdiscountid = '$sSynchOxid' and oxobject2discount.oxtype = 'oxarticles' ";
00065 
00066             if ( stristr( $sQAdd, 'where' ) === false )
00067                 $sQAdd .= ' where ';
00068             else
00069                 $sQAdd .= ' and ';
00070             $sQAdd .= " $sArticleTable.oxid not in ( $sSubSelect ) ";
00071         }
00072 
00073         return $sQAdd;
00074     }
00075 
00081     public function removediscart()
00082     {
00083         $aChosenArt = $this->_getActionIds( 'oxobject2discount.oxid' );
00084         if ( oxConfig::getParameter( 'all' ) ) {
00085 
00086             $sQ = $this->_addFilter( "delete oxobject2discount.* ".$this->_getQuery() );
00087             oxDb::getDb()->Execute( $sQ );
00088 
00089         } elseif ( is_array( $aChosenArt ) ) {
00090             $sQ = "delete from oxobject2discount where oxobject2discount.oxid in ('" . implode( "', '", $aChosenArt ) . "') ";
00091             oxDb::getDb()->Execute( $sQ );
00092         }
00093     }
00094 
00100     public function adddiscart()
00101     {
00102         $aChosenArt = $this->_getActionIds( 'oxarticles.oxid' );
00103         $soxId      = oxConfig::getParameter( 'synchoxid');
00104 
00105         // adding
00106         if ( oxConfig::getParameter( 'all' ) ) {
00107             $sArticleTable = getViewName('oxarticles');
00108             $aChosenArt = $this->_getAll( $this->_addFilter( "select $sArticleTable.oxid ".$this->_getQuery() ) );
00109         }
00110         if ( $soxId && $soxId != "-1" && is_array( $aChosenArt ) ) {
00111             foreach ( $aChosenArt as $sChosenArt) {
00112                 $oObject2Discount = oxNew( "oxbase" );
00113                 $oObject2Discount->init( 'oxobject2discount' );
00114                 $oObject2Discount->oxobject2discount__oxdiscountid = new oxField($soxId);
00115                 $oObject2Discount->oxobject2discount__oxobjectid   = new oxField($sChosenArt);
00116                 $oObject2Discount->oxobject2discount__oxtype       = new oxField("oxarticles");
00117                 $oObject2Discount->save();
00118             }
00119         }
00120     }
00121 
00128     protected function _getQueryCols()
00129     {
00130         $myConfig = $this->getConfig();
00131         $sLangTag = oxLang::getInstance()->getLanguageTag();
00132 
00133         $sQ = '';
00134         $blSep = false;
00135         $aVisiblecols = $this->_getVisibleColNames();
00136         foreach ( $aVisiblecols as $iCnt => $aCol ) {
00137             if ( $blSep )
00138                 $sQ .= ', ';
00139             $sViewTable = getViewName( $aCol[1] );
00140             // multilanguage
00141             $sCol = $aCol[3]?$aCol[0].$sLangTag:$aCol[0];
00142             if ( $myConfig->getConfigParam( 'blVariantsSelection' ) && $aCol[0] == 'oxtitle' ) {
00143                 $sVarSelect = "$sViewTable.oxvarselect".$sLangTag;
00144                 $sQ .= " IF( $sViewTable.$sCol != '', $sViewTable.$sCol, CONCAT((select oxart.$sCol from $sViewTable as oxart where oxart.oxid = $sViewTable.oxparentid),', ',$sVarSelect)) as _" . $iCnt;
00145             } else {
00146                 $sQ  .= $sViewTable . '.' . $sCol . ' as _' . $iCnt;
00147             }
00148             $blSep = true;
00149         }
00150 
00151         $aIdentCols = $this->_getIdentColNames();
00152         foreach ( $aIdentCols as $iCnt => $aCol ) {
00153             if ( $blSep )
00154                 $sQ .= ', ';
00155 
00156             // multilanguage
00157             $sCol = $aCol[3]?$aCol[0].$sLangTag:$aCol[0];
00158             $sQ  .= getViewName( $aCol[1] ) . '.' . $sCol . ' as _' . $iCnt;
00159         }
00160 
00161         return " $sQ ";
00162     }
00163 
00164 }

Generated on Wed Apr 22 12:26:29 2009 for OXID eShop CE by  doxygen 1.5.5