00001 <?php
00002
00006 class vendor_main_ajax extends ajaxListComponent
00007 {
00013 protected $_blAllowExtColumns = true;
00014
00020 protected $_aColumns = array( 'container1' => array(
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 $myConfig = $this->getConfig();
00048
00049
00050 $sArtTable = $this->_getViewName('oxarticles');
00051 $sO2CView = $this->_getViewName('oxobject2category');
00052 $oDb = oxDb::getDb();
00053 $sVendorId = oxConfig::getParameter( 'oxid' );
00054 $sSynchVendorId = oxConfig::getParameter( 'synchoxid' );
00055
00056
00057 if ( !$sVendorId ) {
00058
00059 $sQAdd = ' from '.$sArtTable.' where '.$sArtTable.'.oxshopid="'.$myConfig->getShopId().'" and 1 ';
00060 $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection' ) ?'':" and $sArtTable.oxparentid = '' and $sArtTable.oxvendorid != ".$oDb->quote( $sSynchVendorId );
00061 } else {
00062
00063 if ( $sSynchVendorId && $sSynchVendorId != $sVendorId ) {
00064 $sQAdd = " from $sO2CView left join $sArtTable on ";
00065 $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection' )?" ( $sArtTable.oxid = $sO2CView.oxobjectid or $sArtTable.oxparentid = oxobject2category.oxobjectid )":" $sArtTable.oxid = $sO2CView.oxobjectid ";
00066 $sQAdd .= 'where '.$sArtTable.'.oxshopid="'.$myConfig->getShopId().'" and '.$sO2CView.'.oxcatnid = '.$oDb->quote( $sVendorId ).' and '.$sArtTable.'.oxvendorid != '. $oDb->quote( $sSynchVendorId );
00067 $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection' )?'':" and $sArtTable.oxparentid = '' ";
00068 } else {
00069 $sQAdd = " from $sArtTable where $sArtTable.oxvendorid = ".$oDb->quote( $sVendorId );
00070 $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection' )?'':" and $sArtTable.oxparentid = '' ";
00071 }
00072 }
00073
00074 return $sQAdd;
00075 }
00076
00084 protected function _addFilter( $sQ )
00085 {
00086 $sArtTable = $this->_getViewName('oxarticles');
00087 $sQ = parent::_addFilter( $sQ );
00088
00089
00090 $sQ .= $this->getConfig()->getConfigParam( 'blVariantsSelection' ) ? ' group by '.$sArtTable.'.oxid ' : '';
00091 return $sQ;
00092 }
00093
00099 public function removeVendor()
00100 {
00101 $myConfig = $this->getConfig();
00102 $aRemoveArt = $this->_getActionIds( 'oxarticles.oxid' );
00103
00104 if ( oxConfig::getParameter( 'all' ) ) {
00105 $sArtTable = $this->_getViewName( 'oxarticles' );
00106 $aRemoveArt = $this->_getAll( $this->_addFilter( "select $sArtTable.oxid ".$this->_getQuery() ) );
00107 }
00108
00109 if ( is_array( $aRemoveArt ) ) {
00110 $sSelect = "update oxarticles set oxvendorid = null where oxid in ( ".implode(", ", oxDb::getInstance()->quoteArray( $aRemoveArt ) ) . ") ";
00111 oxDb::getDb()->Execute( $sSelect);
00112 $this->resetCounter( "vendorArticle", oxConfig::getParameter( 'oxid' ) );
00113 }
00114 }
00115
00121 public function addVendor()
00122 {
00123 $myConfig = $this->getConfig();
00124
00125 $aAddArticle = $this->_getActionIds( 'oxarticles.oxid' );
00126 $soxId = oxConfig::getParameter( 'synchoxid' );
00127
00128 if ( oxConfig::getParameter( 'all' ) ) {
00129 $sArtTable = $this->_getViewName( 'oxarticles' );
00130 $aAddArticle = $this->_getAll( $this->_addFilter( "select $sArtTable.oxid ".$this->_getQuery() ) );
00131 }
00132
00133 if ( $soxId && $soxId != "-1" && is_array( $aAddArticle ) ) {
00134 $oDb = oxDb::getDb();
00135 $sSelect = "update oxarticles set oxvendorid = ".$oDb->quote( $soxId )." where oxid in ( ".implode(", ", oxDb::getInstance()->quoteArray( $aAddArticle ) )." )";
00136
00137 $oDb->Execute( $sSelect);
00138 $this->resetCounter( "vendorArticle", $soxId );
00139 }
00140 }
00141 }