vendor_main_ajax.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class vendor_main_ajax extends ajaxListComponent
00007 {
00013     protected $_blAllowExtColumns = true;
00014 
00020     protected $_aColumns = array( 'container1' => array(    // field , table,       visible, multilanguage, ident
00021                                         array( 'oxartnum', 'oxarticles', 1, 0, 0 ),
00022                                         array( 'oxtitle',  'oxarticles', 1, 1, 0 ),
00023                                         array( 'oxean',    'oxarticles', 1, 0, 0 ),
00024                                         array( 'oxmpn',    'oxarticles', 0, 0, 0 ),
00025                                         array( 'oxprice',  'oxarticles', 0, 0, 0 ),
00026                                         array( 'oxstock',  'oxarticles', 0, 0, 0 ),
00027                                         array( 'oxid',     'oxarticles', 0, 0, 1 )
00028                                         ),
00029                                     'container2' => array(
00030                                         array( 'oxartnum', 'oxarticles', 1, 0, 0 ),
00031                                         array( 'oxtitle',  'oxarticles', 1, 1, 0 ),
00032                                         array( 'oxean',    'oxarticles', 1, 0, 0 ),
00033                                         array( 'oxmpn',    'oxarticles', 0, 0, 0 ),
00034                                         array( 'oxprice',  'oxarticles', 0, 0, 0 ),
00035                                         array( 'oxstock',  'oxarticles', 0, 0, 0 ),
00036                                         array( 'oxid',     'oxarticles', 0, 0, 1 )
00037                                         )
00038                                 );
00039 
00045     protected function _getQuery()
00046     {
00047         // looking for table/view
00048         $sArtTable = $this->_getViewName('oxarticles');
00049         $sO2CView  = $this->_getViewName('oxobject2category');
00050         $oDb = oxDb::getDb();
00051         $oConfig = oxRegistry::getConfig();
00052         $sVendorId      = $oConfig->getRequestParameter( 'oxid' );
00053         $sSynchVendorId = $oConfig->getRequestParameter( 'synchoxid' );
00054 
00055         // vendor selected or not ?
00056         if ( !$sVendorId ) {
00057             $sQAdd  = ' from '.$sArtTable.' where '.$sArtTable.'.oxshopid="'.$oConfig->getShopId().'" and 1 ';
00058             $sQAdd .= $oConfig->getConfigParam( 'blVariantsSelection' ) ?'':" and $sArtTable.oxparentid = '' and $sArtTable.oxvendorid != ".$oDb->quote( $sSynchVendorId );
00059         } else {
00060             // selected category ?
00061             if ( $sSynchVendorId && $sSynchVendorId != $sVendorId ) {
00062                 $sQAdd  = " from $sO2CView left join $sArtTable on ";
00063                 $sQAdd .= $oConfig->getConfigParam( 'blVariantsSelection' )?" ( $sArtTable.oxid = $sO2CView.oxobjectid or $sArtTable.oxparentid = oxobject2category.oxobjectid )":" $sArtTable.oxid = $sO2CView.oxobjectid ";
00064                 $sQAdd .= 'where '.$sArtTable.'.oxshopid="'.$oConfig->getShopId().'" and '.$sO2CView.'.oxcatnid = '.$oDb->quote( $sVendorId ).' and '.$sArtTable.'.oxvendorid != '. $oDb->quote( $sSynchVendorId );
00065             } else {
00066                 $sQAdd  = " from $sArtTable where $sArtTable.oxvendorid = ".$oDb->quote( $sVendorId );
00067             }
00068 
00069             $sQAdd .= $oConfig->getConfigParam( 'blVariantsSelection' )?'':" and $sArtTable.oxparentid = '' ";
00070         }
00071 
00072         return $sQAdd;
00073     }
00074 
00082     protected function _addFilter( $sQ )
00083     {
00084         $sArtTable = $this->_getViewName('oxarticles');
00085         $sQ = parent::_addFilter( $sQ );
00086 
00087         // display variants or not ?
00088         $sQ .= $this->getConfig()->getConfigParam( 'blVariantsSelection' ) ? ' group by '.$sArtTable.'.oxid ' : '';
00089         return $sQ;
00090     }
00091 
00097     public function removeVendor()
00098     {
00099         $oConfig    = $this->getConfig();
00100         $aRemoveArt = $this->_getActionIds( 'oxarticles.oxid' );
00101 
00102         if ( $oConfig->getRequestParameter( 'all' ) ) {
00103             $sArtTable = $this->_getViewName( 'oxarticles' );
00104             $aRemoveArt = $this->_getAll( $this->_addFilter( "select $sArtTable.oxid ".$this->_getQuery() ) );
00105         }
00106 
00107         if ( is_array(  $aRemoveArt ) ) {
00108             $sSelect = "update oxarticles set oxvendorid = null where oxid in ( ".implode(", ", oxDb::getInstance()->quoteArray( $aRemoveArt ) ) . ") ";
00109             oxDb::getDb()->Execute( $sSelect);
00110             $this->resetCounter( "vendorArticle", $oConfig->getRequestParameter( 'oxid' ) );
00111         }
00112     }
00113 
00119     public function addVendor()
00120     {
00121         $oConfig = $this->getConfig();
00122 
00123         $aAddArticle = $this->_getActionIds( 'oxarticles.oxid' );
00124         $soxId       = $oConfig->getRequestParameter( 'synchoxid' );
00125 
00126         if ( $oConfig->getRequestParameter( 'all' ) ) {
00127             $sArtTable = $this->_getViewName( 'oxarticles' );
00128             $aAddArticle = $this->_getAll( $this->_addFilter( "select $sArtTable.oxid ".$this->_getQuery() ) );
00129         }
00130 
00131         if ( $soxId && $soxId != "-1" && is_array( $aAddArticle ) ) {
00132             $oDb = oxDb::getDb();
00133             $sSelect = "update oxarticles set oxvendorid = ".$oDb->quote( $soxId )." where oxid in ( ".implode(", ", oxDb::getInstance()->quoteArray( $aAddArticle ) )." )";
00134 
00135             $oDb->Execute( $sSelect);
00136             $this->resetCounter( "vendorArticle", $soxId );
00137         }
00138     }
00139 }