00001 <?php
00002
00006 class manufacturer_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
00054 $sManufacturerId = $myConfig->getRequestParameter( 'oxid' );
00055 $sSynchManufacturerId = $myConfig->getRequestParameter( 'synchoxid' );
00056
00057
00058 if ( !$sManufacturerId ) {
00059
00060 $sQAdd = ' from '.$sArtTable.' where '.$sArtTable.'.oxshopid="'.$myConfig->getShopId().'" and 1 ';
00061 $sQAdd .= $myConfig->getRequestParameter( 'blVariantsSelection' ) ?'':" and $sArtTable.oxparentid = '' and $sArtTable.oxmanufacturerid != ".$oDb->quote( $sSynchManufacturerId );
00062 } elseif ( $sSynchManufacturerId && $sSynchManufacturerId != $sManufacturerId ) {
00063
00064 $sQAdd = " from $sO2CView left join $sArtTable on ";
00065 $sQAdd .= $myConfig->getRequestParameter( 'blVariantsSelection' )?" ( $sArtTable.oxid = $sO2CView.oxobjectid or $sArtTable.oxparentid = $sO2CView.oxobjectid )":" $sArtTable.oxid = $sO2CView.oxobjectid ";
00066 $sQAdd .= 'where '.$sArtTable.'.oxshopid="'.$myConfig->getShopId().'" and '.$sO2CView.'.oxcatnid = '.$oDb->quote( $sManufacturerId ).' and '.$sArtTable.'.oxmanufacturerid != '.$oDb->quote( $sSynchManufacturerId );
00067 $sQAdd .= $myConfig->getRequestParameter( 'blVariantsSelection' )?'':" and $sArtTable.oxparentid = '' ";
00068 } else {
00069 $sQAdd = " from $sArtTable where $sArtTable.oxmanufacturerid = ".$oDb->quote( $sManufacturerId );
00070 $sQAdd .= $myConfig->getRequestParameter( 'blVariantsSelection' )?'':" and $sArtTable.oxparentid = '' ";
00071 }
00072 return $sQAdd;
00073 }
00074
00082 protected function _addFilter( $sQ )
00083 {
00084 $sArtTable = $this->_getViewName('oxarticles');
00085 $sQ = parent::_addFilter( $sQ );
00086
00087
00088 $sQ .= $this->getConfig()->getRequestParameter( 'blVariantsSelection' ) ? ' group by '.$sArtTable.'.oxid ' : '';
00089 return $sQ;
00090 }
00091
00097 public function removeManufacturer()
00098 {
00099 $myConfig = $this->getConfig();
00100 $aRemoveArt = $this->_getActionIds( 'oxarticles.oxid' );
00101 $sOxid = $myConfig->getRequestParameter( 'oxid' );
00102
00103 if ( $this->getConfig()->getRequestParameter( "all" ) ) {
00104 $sArtTable = $this->_getViewName( 'oxarticles' );
00105 $aRemoveArt = $this->_getAll( $this->_addFilter( "select $sArtTable.oxid ".$this->_getQuery() ) );
00106 }
00107
00108 if ( is_array( $aRemoveArt ) && !empty( $aRemoveArt ) ) {
00109 $sSelect = "update oxarticles set oxmanufacturerid = null where oxid in ( ".implode(", ", oxDb::getInstance()->quoteArray( $aRemoveArt ) ).") ";
00110 oxDb::getDb()->Execute( $sSelect);
00111
00112 $this->resetCounter( "manufacturerArticle", $sOxid );
00113 }
00114 }
00115
00121 public function addManufacturer()
00122 {
00123 $myConfig = $this->getConfig();
00124
00125 $aAddArticle = $this->_getActionIds( 'oxarticles.oxid' );
00126 $sSynchOxid = $myConfig->getRequestParameter( 'synchoxid' );
00127
00128 if ( $myConfig->getRequestParameter( 'all' ) ) {
00129 $sArtTable = $this->_getViewName( 'oxarticles' );
00130 $aAddArticle = $this->_getAll( $this->_addFilter( "select $sArtTable.oxid ".$this->_getQuery() ) );
00131 }
00132
00133 if ( $sSynchOxid && $sSynchOxid != "-1" && is_array( $aAddArticle ) ) {
00134 $oDb = oxDb::getDb();
00135 $sSelect = "update oxarticles set oxmanufacturerid = ".$oDb->quote( $sSynchOxid )." where oxid in ( ".implode(", ", oxDb::getInstance()->quoteArray( $aAddArticle ) )." )";
00136
00137 $oDb->Execute( $sSelect);
00138 $this->resetCounter( "manufacturerArticle", $sSynchOxid );
00139 }
00140 }
00141 }