OXID eShop CE  4.9.6
 All Classes Files Functions Variables Pages
vendor_main_ajax.php
Go to the documentation of this file.
1 <?php
2 
7 {
8 
14  protected $_blAllowExtColumns = true;
15 
21  protected $_aColumns = array('container1' => array( // field , table, visible, multilanguage, ident
22  array('oxartnum', 'oxarticles', 1, 0, 0),
23  array('oxtitle', 'oxarticles', 1, 1, 0),
24  array('oxean', 'oxarticles', 1, 0, 0),
25  array('oxmpn', 'oxarticles', 0, 0, 0),
26  array('oxprice', 'oxarticles', 0, 0, 0),
27  array('oxstock', 'oxarticles', 0, 0, 0),
28  array('oxid', 'oxarticles', 0, 0, 1)
29  ),
30  'container2' => array(
31  array('oxartnum', 'oxarticles', 1, 0, 0),
32  array('oxtitle', 'oxarticles', 1, 1, 0),
33  array('oxean', 'oxarticles', 1, 0, 0),
34  array('oxmpn', 'oxarticles', 0, 0, 0),
35  array('oxprice', 'oxarticles', 0, 0, 0),
36  array('oxstock', 'oxarticles', 0, 0, 0),
37  array('oxid', 'oxarticles', 0, 0, 1)
38  )
39  );
40 
46  protected function _getQuery()
47  {
48  // looking for table/view
49  $sArtTable = $this->_getViewName('oxarticles');
50  $sO2CView = $this->_getViewName('oxobject2category');
51  $oDb = oxDb::getDb();
52  $oConfig = oxRegistry::getConfig();
53  $sVendorId = $oConfig->getRequestParameter('oxid');
54  $sSynchVendorId = $oConfig->getRequestParameter('synchoxid');
55 
56  // vendor selected or not ?
57  if (!$sVendorId) {
58  $sQAdd = ' from ' . $sArtTable . ' where ' . $sArtTable . '.oxshopid="' . $oConfig->getShopId() . '" and 1 ';
59  $sQAdd .= $oConfig->getConfigParam('blVariantsSelection') ? '' : " and $sArtTable.oxparentid = '' and $sArtTable.oxvendorid != " . $oDb->quote($sSynchVendorId);
60  } else {
61  // selected category ?
62  if ($sSynchVendorId && $sSynchVendorId != $sVendorId) {
63  $sQAdd = " from $sO2CView left join $sArtTable on ";
64  $sQAdd .= $oConfig->getConfigParam('blVariantsSelection') ? " ( $sArtTable.oxid = $sO2CView.oxobjectid or $sArtTable.oxparentid = oxobject2category.oxobjectid )" : " $sArtTable.oxid = $sO2CView.oxobjectid ";
65  $sQAdd .= 'where ' . $sArtTable . '.oxshopid="' . $oConfig->getShopId() . '" and ' . $sO2CView . '.oxcatnid = ' . $oDb->quote($sVendorId) . ' and ' . $sArtTable . '.oxvendorid != ' . $oDb->quote($sSynchVendorId);
66  } else {
67  $sQAdd = " from $sArtTable where $sArtTable.oxvendorid = " . $oDb->quote($sVendorId);
68  }
69 
70  $sQAdd .= $oConfig->getConfigParam('blVariantsSelection') ? '' : " and $sArtTable.oxparentid = '' ";
71  }
72 
73  return $sQAdd;
74  }
75 
83  protected function _addFilter($sQ)
84  {
85  $sArtTable = $this->_getViewName('oxarticles');
86  $sQ = parent::_addFilter($sQ);
87 
88  // display variants or not ?
89  $sQ .= $this->getConfig()->getConfigParam('blVariantsSelection') ? ' group by ' . $sArtTable . '.oxid ' : '';
90 
91  return $sQ;
92  }
93 
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 
117  public function addVendor()
118  {
119  $oConfig = $this->getConfig();
120 
121  $aAddArticle = $this->_getActionIds('oxarticles.oxid');
122  $soxId = $oConfig->getRequestParameter('synchoxid');
123 
124  if ($oConfig->getRequestParameter('all')) {
125  $sArtTable = $this->_getViewName('oxarticles');
126  $aAddArticle = $this->_getAll($this->_addFilter("select $sArtTable.oxid " . $this->_getQuery()));
127  }
128 
129  if ($soxId && $soxId != "-1" && is_array($aAddArticle)) {
130  $oDb = oxDb::getDb();
131  $sSelect = "update oxarticles set oxvendorid = " . $oDb->quote($soxId) . " where oxid in ( " . implode(", ", oxDb::getInstance()->quoteArray($aAddArticle)) . " )";
132 
133  $oDb->Execute($sSelect);
134  $this->resetCounter("vendorArticle", $soxId);
135  }
136  }
137 }