OXID eShop CE  4.8.10
 All Classes Files Functions Variables Pages
vendor_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  // looking for table/view
48  $sArtTable = $this->_getViewName('oxarticles');
49  $sO2CView = $this->_getViewName('oxobject2category');
50  $oDb = oxDb::getDb();
51  $oConfig = oxRegistry::getConfig();
52  $sVendorId = $oConfig->getRequestParameter( 'oxid' );
53  $sSynchVendorId = $oConfig->getRequestParameter( 'synchoxid' );
54 
55  // vendor selected or not ?
56  if ( !$sVendorId ) {
57  $sQAdd = ' from '.$sArtTable.' where '.$sArtTable.'.oxshopid="'.$oConfig->getShopId().'" and 1 ';
58  $sQAdd .= $oConfig->getConfigParam( 'blVariantsSelection' ) ?'':" and $sArtTable.oxparentid = '' and $sArtTable.oxvendorid != ".$oDb->quote( $sSynchVendorId );
59  } else {
60  // selected category ?
61  if ( $sSynchVendorId && $sSynchVendorId != $sVendorId ) {
62  $sQAdd = " from $sO2CView left join $sArtTable on ";
63  $sQAdd .= $oConfig->getConfigParam( 'blVariantsSelection' )?" ( $sArtTable.oxid = $sO2CView.oxobjectid or $sArtTable.oxparentid = oxobject2category.oxobjectid )":" $sArtTable.oxid = $sO2CView.oxobjectid ";
64  $sQAdd .= 'where '.$sArtTable.'.oxshopid="'.$oConfig->getShopId().'" and '.$sO2CView.'.oxcatnid = '.$oDb->quote( $sVendorId ).' and '.$sArtTable.'.oxvendorid != '. $oDb->quote( $sSynchVendorId );
65  } else {
66  $sQAdd = " from $sArtTable where $sArtTable.oxvendorid = ".$oDb->quote( $sVendorId );
67  }
68 
69  $sQAdd .= $oConfig->getConfigParam( 'blVariantsSelection' )?'':" and $sArtTable.oxparentid = '' ";
70  }
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()->getConfigParam( 'blVariantsSelection' ) ? ' group by '.$sArtTable.'.oxid ' : '';
89  return $sQ;
90  }
91 
97  public function removeVendor()
98  {
99  $oConfig = $this->getConfig();
100  $aRemoveArt = $this->_getActionIds( 'oxarticles.oxid' );
101 
102  if ( $oConfig->getRequestParameter( 'all' ) ) {
103  $sArtTable = $this->_getViewName( 'oxarticles' );
104  $aRemoveArt = $this->_getAll( $this->_addFilter( "select $sArtTable.oxid ".$this->_getQuery() ) );
105  }
106 
107  if ( is_array( $aRemoveArt ) ) {
108  $sSelect = "update oxarticles set oxvendorid = null where oxid in ( ".implode(", ", oxDb::getInstance()->quoteArray( $aRemoveArt ) ) . ") ";
109  oxDb::getDb()->Execute( $sSelect);
110  $this->resetCounter( "vendorArticle", $oConfig->getRequestParameter( 'oxid' ) );
111  }
112  }
113 
119  public function addVendor()
120  {
121  $oConfig = $this->getConfig();
122 
123  $aAddArticle = $this->_getActionIds( 'oxarticles.oxid' );
124  $soxId = $oConfig->getRequestParameter( 'synchoxid' );
125 
126  if ( $oConfig->getRequestParameter( 'all' ) ) {
127  $sArtTable = $this->_getViewName( 'oxarticles' );
128  $aAddArticle = $this->_getAll( $this->_addFilter( "select $sArtTable.oxid ".$this->_getQuery() ) );
129  }
130 
131  if ( $soxId && $soxId != "-1" && is_array( $aAddArticle ) ) {
132  $oDb = oxDb::getDb();
133  $sSelect = "update oxarticles set oxvendorid = ".$oDb->quote( $soxId )." where oxid in ( ".implode(", ", oxDb::getInstance()->quoteArray( $aAddArticle ) )." )";
134 
135  $oDb->Execute( $sSelect);
136  $this->resetCounter( "vendorArticle", $soxId );
137  }
138  }
139 }