OXID eShop CE  4.8.11
 All Classes Files Functions Variables Pages
manufacturer_main_ajax.php
Go to the documentation of this file.
1 <?php
2 
7 {
13  protected $_blAllowExtColumns = true;
14 
20  protected $_aColumns = array( 'container1' => array( // field , table, visible, multilanguage, ident
21  array( 'oxartnum', 'oxarticles', 1, 0, 0 ),
22  array( 'oxtitle', 'oxarticles', 1, 1, 0 ),
23  array( 'oxean', 'oxarticles', 1, 0, 0 ),
24  array( 'oxmpn', 'oxarticles', 0, 0, 0 ),
25  array( 'oxprice', 'oxarticles', 0, 0, 0 ),
26  array( 'oxstock', 'oxarticles', 0, 0, 0 ),
27  array( 'oxid', 'oxarticles', 0, 0, 1 )
28  ),
29  'container2' => array(
30  array( 'oxartnum', 'oxarticles', 1, 0, 0 ),
31  array( 'oxtitle', 'oxarticles', 1, 1, 0 ),
32  array( 'oxean', 'oxarticles', 1, 0, 0 ),
33  array( 'oxmpn', 'oxarticles', 0, 0, 0 ),
34  array( 'oxprice', 'oxarticles', 0, 0, 0 ),
35  array( 'oxstock', 'oxarticles', 0, 0, 0 ),
36  array( 'oxid', 'oxarticles', 0, 0, 1 )
37  )
38  );
39 
45  protected function _getQuery()
46  {
47  $myConfig = $this->getConfig();
48 
49  // looking for table/view
50  $sArtTable = $this->_getViewName('oxarticles');
51  $sO2CView = $this->_getViewName('oxobject2category');
52  $oDb = oxDb::getDb();
53 
54  $sManufacturerId = $myConfig->getRequestParameter( 'oxid' );
55  $sSynchManufacturerId = $myConfig->getRequestParameter( 'synchoxid' );
56 
57  // Manufacturer selected or not ?
58  if ( !$sManufacturerId ) {
59  // dodger performance
60  $sQAdd = ' from '.$sArtTable.' where '.$sArtTable.'.oxshopid="'.$myConfig->getShopId().'" and 1 ';
61  $sQAdd .= $myConfig->getRequestParameter( 'blVariantsSelection' ) ?'':" and $sArtTable.oxparentid = '' and $sArtTable.oxmanufacturerid != ".$oDb->quote( $sSynchManufacturerId );
62  } elseif ( $sSynchManufacturerId && $sSynchManufacturerId != $sManufacturerId ) {
63  // selected category ?
64  $sQAdd = " from $sO2CView left join $sArtTable on ";
65  $sQAdd .= $myConfig->getRequestParameter( 'blVariantsSelection' )?" ( $sArtTable.oxid = $sO2CView.oxobjectid or $sArtTable.oxparentid = $sO2CView.oxobjectid )":" $sArtTable.oxid = $sO2CView.oxobjectid ";
66  $sQAdd .= 'where '.$sArtTable.'.oxshopid="'.$myConfig->getShopId().'" and '.$sO2CView.'.oxcatnid = '.$oDb->quote( $sManufacturerId ).' and '.$sArtTable.'.oxmanufacturerid != '.$oDb->quote( $sSynchManufacturerId );
67  $sQAdd .= $myConfig->getRequestParameter( 'blVariantsSelection' )?'':" and $sArtTable.oxparentid = '' ";
68  } else {
69  $sQAdd = " from $sArtTable where $sArtTable.oxmanufacturerid = ".$oDb->quote( $sManufacturerId );
70  $sQAdd .= $myConfig->getRequestParameter( 'blVariantsSelection' )?'':" and $sArtTable.oxparentid = '' ";
71  }
72  return $sQAdd;
73  }
74 
82  protected function _addFilter( $sQ )
83  {
84  $sArtTable = $this->_getViewName('oxarticles');
85  $sQ = parent::_addFilter( $sQ );
86 
87  // display variants or not ?
88  $sQ .= $this->getConfig()->getRequestParameter( 'blVariantsSelection' ) ? ' group by '.$sArtTable.'.oxid ' : '';
89  return $sQ;
90  }
91 
97  public function removeManufacturer()
98  {
99  $myConfig = $this->getConfig();
100  $aRemoveArt = $this->_getActionIds( 'oxarticles.oxid' );
101  $sOxid = $myConfig->getRequestParameter( 'oxid' );
102 
103  if ( $this->getConfig()->getRequestParameter( "all" ) ) {
104  $sArtTable = $this->_getViewName( 'oxarticles' );
105  $aRemoveArt = $this->_getAll( $this->_addFilter( "select $sArtTable.oxid ".$this->_getQuery() ) );
106  }
107 
108  if ( is_array( $aRemoveArt ) && !empty( $aRemoveArt ) ) {
109  $sSelect = "update oxarticles set oxmanufacturerid = null where oxid in ( ".implode(", ", oxDb::getInstance()->quoteArray( $aRemoveArt ) ).") ";
110  oxDb::getDb()->Execute( $sSelect);
111 
112  $this->resetCounter( "manufacturerArticle", $sOxid );
113  }
114  }
115 
121  public function addManufacturer()
122  {
123  $myConfig = $this->getConfig();
124 
125  $aAddArticle = $this->_getActionIds( 'oxarticles.oxid' );
126  $sSynchOxid = $myConfig->getRequestParameter( 'synchoxid' );
127 
128  if ( $myConfig->getRequestParameter( 'all' ) ) {
129  $sArtTable = $this->_getViewName( 'oxarticles' );
130  $aAddArticle = $this->_getAll( $this->_addFilter( "select $sArtTable.oxid ".$this->_getQuery() ) );
131  }
132 
133  if ( $sSynchOxid && $sSynchOxid != "-1" && is_array( $aAddArticle ) ) {
134  $oDb = oxDb::getDb();
135  $sSelect = "update oxarticles set oxmanufacturerid = ".$oDb->quote( $sSynchOxid )." where oxid in ( ".implode(", ", oxDb::getInstance()->quoteArray( $aAddArticle ) )." )";
136 
137  $oDb->Execute( $sSelect);
138  $this->resetCounter( "manufacturerArticle", $sSynchOxid );
139  }
140  }
141 }