vendor_main.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',     'oxarticles', 0, 0, 1 )
00020                                         )
00021                     );
00022 
00026 class ajaxComponent extends ajaxListComponent
00027 {
00033     protected function _getQuery()
00034     {
00035         $myConfig = $this->getConfig();
00036 
00037         // looking for table/view
00038         $sArtTable = getViewName('oxarticles');
00039         $sO2CView  = getViewName('oxobject2category');
00040 
00041         $sVendorId      = oxConfig::getParameter( 'oxid' );
00042         $sSynchVendorId = oxConfig::getParameter( 'synchoxid' );
00043 
00044         // vendor selected or not ?
00045         if ( !$sVendorId ) {
00046             // dodger performance
00047             $sQAdd  = ' from '.$sArtTable.' where '.$sArtTable.'.oxshopid="'.$myConfig->getShopId().'" and 1 ';
00048             $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection' ) ?'':" and $sArtTable.oxparentid = '' and $sArtTable.oxvendorid != '$sSynchVendorId' ";
00049         } else {
00050             // selected category ?
00051             if ( $sSynchVendorId && $sSynchVendorId != $sVendorId ) {
00052                 $sQAdd  = " from $sO2CView left join $sArtTable on ";
00053                 $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection' )?" ( $sArtTable.oxid = $sO2CView.oxobjectid or $sArtTable.oxparentid = oxobject2category.oxobjectid )":" $sArtTable.oxid = $sO2CView.oxobjectid ";
00054                 $sQAdd .= 'where '.$sArtTable.'.oxshopid="'.$myConfig->getShopId().'" and '.$sO2CView.'.oxcatnid = "'.$sVendorId.'" and '.$sArtTable.'.oxvendorid != "'. $sSynchVendorId .'" ';
00055                 $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection' )?'':" and $sArtTable.oxparentid = '' ";
00056             } else {
00057                 $sQAdd  = " from $sArtTable where $sArtTable.oxvendorid = '$sVendorId' ";
00058                 $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection' )?'':" and $sArtTable.oxparentid = '' ";
00059             }
00060         }
00061 
00062         return $sQAdd;
00063     }
00064 
00072     protected function _addFilter( $sQ )
00073     {
00074         $sArtTable = getViewName('oxarticles');
00075         $sQ = parent::_addFilter( $sQ );
00076 
00077         // display variants or not ?
00078         $sQ .= $this->getConfig()->getConfigParam( 'blVariantsSelection' ) ? ' group by '.$sArtTable.'.oxid ' : '';
00079         return $sQ;
00080     }
00081 
00087     public function removevendor()
00088     {
00089         $myConfig   = $this->getConfig();
00090         $aRemoveArt = $this->_getActionIds( 'oxarticles.oxid' );
00091 
00092         if ( oxConfig::getParameter( 'all' ) ) {
00093             $sArtTable = getViewName( 'oxarticles' );
00094             $aRemoveArt = $this->_getAll( $this->_addFilter( "select $sArtTable.oxid ".$this->_getQuery() ) );
00095         }
00096 
00097         if ( is_array(  $aRemoveArt ) ) {
00098             $sSelect = "update oxarticles set oxvendorid = null where oxid in ( ".implode(", ", oxDb::getInstance()->quoteArray( $aRemoveArt ) ) . ") ";
00099             oxDb::getDb()->Execute( $sSelect);
00100             $this->resetCounter( "vendorArticle", oxConfig::getParameter( 'oxid' ) );
00101         }
00102     }
00103 
00109     public function addvendor()
00110     {
00111         $myConfig = $this->getConfig();
00112 
00113         $aAddArticle = $this->_getActionIds( 'oxarticles.oxid' );
00114         $soxId       = oxConfig::getParameter( 'synchoxid' );
00115 
00116         if ( oxConfig::getParameter( 'all' ) ) {
00117             $sArtTable = getViewName( 'oxarticles' );
00118             $aAddArticle = $this->_getAll( $this->_addFilter( "select $sArtTable.oxid ".$this->_getQuery() ) );
00119         }
00120 
00121         if ( $soxId && $soxId != "-1" && is_array( $aAddArticle ) ) {
00122             $sSelect = "update oxarticles set oxvendorid = '$soxId' where oxid in ( ".implode(", ", oxDb::getInstance()->quoteArray( $aAddArticle ) )." )";
00123 
00124             oxDb::getDb()->Execute( $sSelect);
00125             $this->resetCounter( "vendorArticle", $soxId );
00126         }
00127     }
00128 
00135     protected function _getQueryCols()
00136     {
00137         $myConfig = $this->getConfig();
00138         $sLangTag = oxLang::getInstance()->getLanguageTag();
00139 
00140         $sQ = '';
00141         $blSep = false;
00142         $aVisiblecols = $this->_getVisibleColNames();
00143         foreach ( $aVisiblecols as $iCnt => $aCol ) {
00144             if ( $blSep )
00145                 $sQ .= ', ';
00146             $sViewTable = getViewName( $aCol[1] );
00147             // multilanguage
00148             $sCol = $aCol[3]?$aCol[0].$sLangTag:$aCol[0];
00149             if ( $myConfig->getConfigParam( 'blVariantsSelection' ) && $aCol[0] == 'oxtitle' ) {
00150                 $sVarSelect = "$sViewTable.oxvarselect".$sLangTag;
00151                 $sQ .= " IF( $sViewTable.$sCol != '', $sViewTable.$sCol, CONCAT((select oxart.$sCol from $sViewTable as oxart where oxart.oxid = $sViewTable.oxparentid),', ',$sVarSelect)) as _" . $iCnt;
00152             } else {
00153                 $sQ  .= $sViewTable . '.' . $sCol . ' as _' . $iCnt;
00154             }
00155             $blSep = true;
00156         }
00157 
00158         $aIdentCols = $this->_getIdentColNames();
00159         foreach ( $aIdentCols as $iCnt => $aCol ) {
00160             if ( $blSep )
00161                 $sQ .= ', ';
00162 
00163             // multilanguage
00164             $sCol = $aCol[3]?$aCol[0].$sLangTag:$aCol[0];
00165             $sQ  .= getViewName( $aCol[1] ) . '.' . $sCol . ' as _' . $iCnt;
00166         }
00167 
00168         return " $sQ ";
00169     }
00170 
00171 }