manufacturer_main_ajax.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class manufacturer_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         $myConfig = $this->getConfig();
00048 
00049         // looking for table/view
00050         $sArtTable = $this->_getViewName('oxarticles');
00051         $sO2CView  = $this->_getViewName('oxobject2category');
00052         $oDb = oxDb::getDb();
00053 
00054         $sManufacturerId      = oxConfig::getParameter( 'oxid' );
00055         $sSynchManufacturerId = oxConfig::getParameter( 'synchoxid' );
00056 
00057         // Manufacturer selected or not ?
00058         if ( !$sManufacturerId ) {
00059             // dodger performance
00060             $sQAdd  = ' from '.$sArtTable.' where '.$sArtTable.'.oxshopid="'.$myConfig->getShopId().'" and 1 ';
00061             $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection' ) ?'':" and $sArtTable.oxparentid = '' and $sArtTable.oxmanufacturerid != ".$oDb->quote( $sSynchManufacturerId );
00062         } else {
00063             // selected category ?
00064             if ( $sSynchManufacturerId && $sSynchManufacturerId != $sManufacturerId ) {
00065                 $sQAdd  = " from $sO2CView left join $sArtTable on ";
00066                 $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection' )?" ( $sArtTable.oxid = $sO2CView.oxobjectid or $sArtTable.oxparentid = oxobject2category.oxobjectid )":" $sArtTable.oxid = $sO2CView.oxobjectid ";
00067                 $sQAdd .= 'where '.$sArtTable.'.oxshopid="'.$myConfig->getShopId().'" and '.$sO2CView.'.oxcatnid = '.$oDb->quote( $sManufacturerId ).' and '.$sArtTable.'.oxmanufacturerid != '.$oDb->quote( $sSynchManufacturerId );
00068                 $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection' )?'':" and $sArtTable.oxparentid = '' ";
00069             } else {
00070                 $sQAdd  = " from $sArtTable where $sArtTable.oxmanufacturerid = ".$oDb->quote( $sManufacturerId );
00071                 $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection' )?'':" and $sArtTable.oxparentid = '' ";
00072             }
00073         }
00074 
00075         return $sQAdd;
00076     }
00077 
00085     protected function _addFilter( $sQ )
00086     {
00087         $sArtTable = $this->_getViewName('oxarticles');
00088         $sQ = parent::_addFilter( $sQ );
00089 
00090         // display variants or not ?
00091         $sQ .= $this->getConfig()->getConfigParam( 'blVariantsSelection' ) ? ' group by '.$sArtTable.'.oxid ' : '';
00092         return $sQ;
00093     }
00094 
00100     public function removeManufacturer()
00101     {
00102         $myConfig   = $this->getConfig();
00103         $aRemoveArt = $this->_getActionIds( 'oxarticles.oxid' );
00104 
00105         if ( oxConfig::getParameter( 'all' ) ) {
00106             $sArtTable = $this->_getViewName( 'oxarticles' );
00107             $aRemoveArt = $this->_getAll( $this->_addFilter( "select $sArtTable.oxid ".$this->_getQuery() ) );
00108         }
00109 
00110         if ( is_array(  $aRemoveArt ) ) {
00111             $sSelect = "update oxarticles set oxmanufacturerid = null where oxid in ( ".implode(", ", oxDb::getInstance()->quoteArray( $aRemoveArt ) ).") ";
00112             oxDb::getDb()->Execute( $sSelect);
00113 
00114             $this->resetCounter( "manufacturerArticle", oxConfig::getParameter( 'oxid' ) );
00115         }
00116     }
00117 
00123     public function addManufacturer()
00124     {
00125         $myConfig = $this->getConfig();
00126 
00127         $aAddArticle = $this->_getActionIds( 'oxarticles.oxid' );
00128         $soxId       = oxConfig::getParameter( 'synchoxid' );
00129 
00130         if ( oxConfig::getParameter( 'all' ) ) {
00131             $sArtTable = $this->_getViewName( 'oxarticles' );
00132             $aAddArticle = $this->_getAll( $this->_addFilter( "select $sArtTable.oxid ".$this->_getQuery() ) );
00133         }
00134 
00135         if ( $soxId && $soxId != "-1" && is_array( $aAddArticle ) ) {
00136             $oDb = oxDb::getDb();
00137             $sSelect = "update oxarticles set oxmanufacturerid = ".$oDb->quote( $soxId )." where oxid in ( ".implode(", ", oxDb::getInstance()->quoteArray( $aAddArticle ) )." )";
00138 
00139             $oDb->Execute( $sSelect);
00140             $this->resetCounter( "manufacturerArticle", $soxId );
00141         }
00142     }
00143 }