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

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