OXID eShop CE  4.10.0
 All Classes Namespaces Files Functions Variables Pages
manufacturer_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  $myConfig = $this->getConfig();
49 
50  // looking for table/view
51  $sArtTable = $this->_getViewName('oxarticles');
52  $sO2CView = $this->_getViewName('oxobject2category');
53  $oDb = oxDb::getDb();
54 
55  $sManufacturerId = $myConfig->getRequestParameter('oxid');
56  $sSynchManufacturerId = $myConfig->getRequestParameter('synchoxid');
57 
58  // Manufacturer selected or not ?
59  if (!$sManufacturerId) {
60  // performance
61  $sQAdd = ' from ' . $sArtTable . ' where ' . $sArtTable . '.oxshopid="' . $myConfig->getShopId() . '" and 1 ';
62  $sQAdd .= $myConfig->getRequestParameter('blVariantsSelection') ? '' : " and $sArtTable.oxparentid = '' and $sArtTable.oxmanufacturerid != " . $oDb->quote($sSynchManufacturerId);
63  } elseif ($sSynchManufacturerId && $sSynchManufacturerId != $sManufacturerId) {
64  // selected category ?
65  $sQAdd = " from $sO2CView left join $sArtTable on ";
66  $sQAdd .= $myConfig->getRequestParameter('blVariantsSelection') ? " ( $sArtTable.oxid = $sO2CView.oxobjectid or $sArtTable.oxparentid = $sO2CView.oxobjectid )" : " $sArtTable.oxid = $sO2CView.oxobjectid ";
67  $sQAdd .= 'where ' . $sArtTable . '.oxshopid="' . $myConfig->getShopId() . '" and ' . $sO2CView . '.oxcatnid = ' . $oDb->quote($sManufacturerId) . ' and ' . $sArtTable . '.oxmanufacturerid != ' . $oDb->quote($sSynchManufacturerId);
68  $sQAdd .= $myConfig->getRequestParameter('blVariantsSelection') ? '' : " and $sArtTable.oxparentid = '' ";
69  } else {
70  $sQAdd = " from $sArtTable where $sArtTable.oxmanufacturerid = " . $oDb->quote($sManufacturerId);
71  $sQAdd .= $myConfig->getRequestParameter('blVariantsSelection') ? '' : " and $sArtTable.oxparentid = '' ";
72  }
73 
74  return $sQAdd;
75  }
76 
84  protected function _addFilter($sQ)
85  {
86  $sArtTable = $this->_getViewName('oxarticles');
87  $sQ = parent::_addFilter($sQ);
88 
89  // display variants or not ?
90  $sQ .= $this->getConfig()->getRequestParameter('blVariantsSelection') ? ' group by ' . $sArtTable . '.oxid ' : '';
91 
92  return $sQ;
93  }
94 
98  public function removeManufacturer()
99  {
100  $myConfig = $this->getConfig();
101  $aRemoveArt = $this->_getActionIds('oxarticles.oxid');
102  $sOxid = $myConfig->getRequestParameter('oxid');
103 
104  if ($this->getConfig()->getRequestParameter("all")) {
105  $sArtTable = $this->_getViewName('oxarticles');
106  $aRemoveArt = $this->_getAll($this->_addFilter("select $sArtTable.oxid " . $this->_getQuery()));
107  }
108 
109  if (is_array($aRemoveArt) && !empty($aRemoveArt)) {
110  $sSelect = "update oxarticles set oxmanufacturerid = null where oxid in ( " . implode(", ", oxDb::getInstance()->quoteArray($aRemoveArt)) . ") ";
111  oxDb::getDb()->Execute($sSelect);
112 
113  $this->resetCounter("manufacturerArticle", $sOxid);
114  }
115  }
116 
120  public function addManufacturer()
121  {
122  $myConfig = $this->getConfig();
123 
124  $aAddArticle = $this->_getActionIds('oxarticles.oxid');
125  $sSynchOxid = $myConfig->getRequestParameter('synchoxid');
126 
127  if ($myConfig->getRequestParameter('all')) {
128  $sArtTable = $this->_getViewName('oxarticles');
129  $aAddArticle = $this->_getAll($this->_addFilter("select $sArtTable.oxid " . $this->_getQuery()));
130  }
131 
132  if ($sSynchOxid && $sSynchOxid != "-1" && is_array($aAddArticle)) {
133  $oDb = oxDb::getDb();
134  $sSelect = "update oxarticles set oxmanufacturerid = " . $oDb->quote($sSynchOxid) . " where oxid in ( " . implode(", ", oxDb::getInstance()->quoteArray($aAddArticle)) . " )";
135 
136  $oDb->Execute($sSelect);
137  $this->resetCounter("manufacturerArticle", $sSynchOxid);
138  }
139  }
140 }