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

Generated by  doxygen 1.6.2