article_crossselling.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',     'oxobject2article', 0, 0, 1 )
00018                                         )
00019                     );
00020 
00024 class ajaxComponent extends ajaxListComponent
00025 {
00031     protected function _getQuery()
00032     {
00033         $myConfig      = $this->getConfig();
00034         $sArticleTable = getViewName( 'oxarticles' );
00035         $sO2CView      = getViewName( 'oxobject2category' );
00036 
00037         $sSelId      = oxConfig::getParameter( 'oxid' );
00038         $sSynchSelId = oxConfig::getParameter( 'synchoxid' );
00039         $oDb         = oxDb::getDb();
00040 
00041         // category selected or not ?
00042         if ( !$sSelId ) {
00043             $sQAdd  = " from $sArticleTable where 1 ";
00044             $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection' )?'':" and $sArticleTable.oxparentid = '' ";
00045         } else {
00046             // selected category ?
00047             if ( $sSynchSelId && $sSelId != $sSynchSelId ) {
00048                 $sQAdd  = " from $sO2CView as oxobject2category left join $sArticleTable on ";
00049                 $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection' )?" ($sArticleTable.oxid=oxobject2category.oxobjectid or $sArticleTable.oxparentid=oxobject2category.oxobjectid)":" $sArticleTable.oxid=oxobject2category.oxobjectid ";
00050                 $sQAdd .= " where oxobject2category.oxcatnid = " . $oDb->quote( $sSelId ) . " ";
00051             } else {
00052 
00053                 if ( $myConfig->getConfigParam( 'blBidirectCross' ) ) {
00054                     $sQAdd  = " from oxobject2article ";
00055                     $sQAdd .= " inner join $sArticleTable on ( oxobject2article.oxobjectid = $sArticleTable.oxid ";
00056                     $sQAdd .= " or oxobject2article.oxarticlenid = $sArticleTable.oxid ) ";
00057                     $sQAdd .= " where ( oxobject2article.oxarticlenid = " . $oDb->quote( $sSelId ) . " or oxobject2article.oxobjectid = " . $oDb->quote( $sSelId ) . " ) ";
00058                     $sQAdd .= " and $sArticleTable.oxid != " . $oDb->quote( $sSelId ) . " ";
00059                 } else {
00060                     $sQAdd  = " from oxobject2article left join $sArticleTable on oxobject2article.oxobjectid=$sArticleTable.oxid ";
00061                     $sQAdd .= " where oxobject2article.oxarticlenid = " . $oDb->quote( $sSelId ) . " ";
00062                 }
00063             }
00064         }
00065         if ( $sSynchSelId && $sSynchSelId != $sSelId) {
00066             if ( $myConfig->getConfigParam( 'blBidirectCross' ) ) {
00067                 $sSubSelect  = "select $sArticleTable.oxid from oxobject2article left join $sArticleTable on (oxobject2article.oxobjectid=$sArticleTable.oxid or oxobject2article.oxarticlenid=$sArticleTable.oxid) ";
00068                 $sSubSelect .= "where (oxobject2article.oxarticlenid = " . $oDb->quote( $sSynchSelId ) . " or oxobject2article.oxobjectid = " . $oDb->quote( $sSynchSelId ) . " )";
00069             } else {
00070                 $sSubSelect  = "select $sArticleTable.oxid from oxobject2article left join $sArticleTable on oxobject2article.oxobjectid=$sArticleTable.oxid ";
00071                 $sSubSelect .= "where oxobject2article.oxarticlenid = " . $oDb->quote( $sSynchSelId ) . " ";
00072             }
00073 
00074             $sSubSelect .= " and $sArticleTable.oxid IS NOT NULL ";
00075             $sQAdd .= " and $sArticleTable.oxid not in ( $sSubSelect ) ";
00076         }
00077 
00078         // #1513C/#1826C - skip references, to not existing articles
00079         $sQAdd .= " and $sArticleTable.oxid IS NOT NULL ";
00080 
00081         // skipping self from list
00082         $sId = ( $sSelId ) ? $sSelId : $sSynchSelId ;
00083         $sQAdd .= " and $sArticleTable.oxid != " . $oDb->quote( $sId ) . " ";
00084 
00085         return $sQAdd;
00086     }
00087 
00095     protected function _getDataQuery( $sQ )
00096     {
00097         $sArtTable = getViewName('oxarticles');
00098         $sQ = parent::_getDataQuery( $sQ );
00099 
00100         // display variants or not ?
00101         $sQ .= $this->getConfig()->getConfigParam( 'blVariantsSelection' ) ? ' group by '.$sArtTable.'.oxid ' : '';
00102         return $sQ;
00103     }
00104 
00110     public function removearticlecross()
00111     {
00112         $aChosenArt = $this->_getActionIds( 'oxobject2article.oxid' );
00113         // removing all
00114         if ( oxConfig::getParameter( 'all' ) ) {
00115 
00116             $sQ = $this->_addFilter( "delete oxobject2article.* ".$this->_getQuery() );
00117             oxDb::getDb()->Execute( $sQ );
00118 
00119         } elseif ( is_array( $aChosenArt ) ) {
00120             $sQ = "delete from oxobject2article where oxobject2article.oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aChosenArt ) ) . ") ";
00121             oxDb::getDb()->Execute( $sQ );
00122         }
00123     }
00124 
00130     public function addarticlecross()
00131     {
00132         $aChosenArt = $this->_getActionIds( 'oxarticles.oxid' );
00133         $soxId      = oxConfig::getParameter( 'synchoxid');
00134 
00135         // adding
00136         if ( oxConfig::getParameter( 'all' ) ) {
00137             $sArtTable = getViewName('oxarticles');
00138             $aChosenArt = $this->_getAll( $this->_addFilter( "select $sArtTable.oxid ".$this->_getQuery() ) );
00139         }
00140 
00141         $oArticle = oxNew( "oxarticle" );
00142         if ( $oArticle->load( $soxId) && $soxId && $soxId != "-1" && is_array( $aChosenArt ) ) {
00143             foreach ( $aChosenArt as $sAdd ) {
00144                 $oNewGroup = oxNew( 'oxbase' );
00145                 $oNewGroup->init( 'oxobject2article' );
00146                 $oNewGroup->oxobject2article__oxobjectid   = new oxField($sAdd);
00147                 $oNewGroup->oxobject2article__oxarticlenid = new oxField($oArticle->oxarticles__oxid->value);
00148                 $oNewGroup->oxobject2article__oxsort       = new oxField(0);
00149                 $oNewGroup->save();
00150             }
00151         }
00152     }
00153 
00160     protected function _getQueryCols()
00161     {
00162         $myConfig = $this->getConfig();
00163         $sLangTag = oxLang::getInstance()->getLanguageTag();
00164 
00165         $sQ = '';
00166         $blSep = false;
00167         $aVisiblecols = $this->_getVisibleColNames();
00168         foreach ( $aVisiblecols as $iCnt => $aCol ) {
00169             if ( $blSep )
00170                 $sQ .= ', ';
00171             $sViewTable = getViewName( $aCol[1] );
00172             // multilanguage
00173             $sCol = $aCol[3]?$aCol[0].$sLangTag:$aCol[0];
00174             if ( $myConfig->getConfigParam( 'blVariantsSelection' ) && $aCol[0] == 'oxtitle' ) {
00175                 $sVarSelect = "$sViewTable.oxvarselect".$sLangTag;
00176                 $sQ .= " IF( $sViewTable.$sCol != '', $sViewTable.$sCol, CONCAT((select oxart.$sCol from $sViewTable as oxart where oxart.oxid = $sViewTable.oxparentid),', ',$sVarSelect)) as _" . $iCnt;
00177             } else {
00178                 $sQ  .= $sViewTable . '.' . $sCol . ' as _' . $iCnt;
00179             }
00180             $blSep = true;
00181         }
00182 
00183         $aIdentCols = $this->_getIdentColNames();
00184         foreach ( $aIdentCols as $iCnt => $aCol ) {
00185             if ( $blSep )
00186                 $sQ .= ', ';
00187 
00188             // multilanguage
00189             $sCol = $aCol[3]?$aCol[0].$sLangTag:$aCol[0];
00190             $sQ  .= getViewName( $aCol[1] ) . '.' . $sCol . ' as _' . $iCnt;
00191         }
00192 
00193         return " $sQ ";
00194     }
00195 
00196 }

Generated on Tue Sep 29 16:45:12 2009 for OXID eShop CE by  doxygen 1.5.5