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         $sQ = '';
00161         $blSep = false;
00162         $aVisiblecols = $this->_getVisibleColNames();
00163         foreach ( $aVisiblecols as $iCnt => $aCol ) {
00164             if ( $blSep )
00165                 $sQ .= ', ';
00166             $sViewTable = getViewName( $aCol[1] );
00167             // multilanguage
00168             $sCol = $aCol[3]?$aCol[0].oxLang::getInstance()->getLanguageTag():$aCol[0];
00169             if ( $myConfig->getConfigParam( 'blVariantsSelection' ) && $aCol[0] == 'oxtitle' ) {
00170                 $sVarSelect = "$sViewTable.oxvarselect".oxLang::getInstance()->getLanguageTag();
00171                 $sQ .= " IF( $sViewTable.$sCol != '', $sViewTable.$sCol, CONCAT((select oxart.$sCol from $sViewTable as oxart where oxart.oxid = $sViewTable.oxparentid),', ',$sVarSelect)) as _" . $iCnt;
00172             } else {
00173                 $sQ  .= $sViewTable . '.' . $sCol . ' as _' . $iCnt;
00174             }
00175             $blSep = true;
00176         }
00177 
00178         $aIdentCols = $this->_getIdentColNames();
00179         foreach ( $aIdentCols as $iCnt => $aCol ) {
00180             if ( $blSep )
00181                 $sQ .= ', ';
00182 
00183             // multilanguage
00184             $sCol = $aCol[3]?$aCol[0].oxLang::getInstance()->getLanguageTag():$aCol[0];
00185             $sQ  .= getViewName( $aCol[1] ) . '.' . $sCol . ' as _' . $iCnt;
00186         }
00187 
00188         return " $sQ ";
00189     }
00190 
00191 }

Generated on Thu Dec 4 12:04:55 2008 for OXID eShop CE by  doxygen 1.5.5