00001 <?php
00002
00006 class manufacturer_main_ajax extends ajaxListComponent
00007 {
00008
00014 protected $_blAllowExtColumns = true;
00015
00021 protected $_aColumns = array('container1' => array(
00022 array('oxartnum', 'oxarticles', 1, 0, 0),
00023 array('oxtitle', 'oxarticles', 1, 1, 0),
00024 array('oxean', 'oxarticles', 1, 0, 0),
00025 array('oxmpn', 'oxarticles', 0, 0, 0),
00026 array('oxprice', 'oxarticles', 0, 0, 0),
00027 array('oxstock', 'oxarticles', 0, 0, 0),
00028 array('oxid', 'oxarticles', 0, 0, 1)
00029 ),
00030 'container2' => array(
00031 array('oxartnum', 'oxarticles', 1, 0, 0),
00032 array('oxtitle', 'oxarticles', 1, 1, 0),
00033 array('oxean', 'oxarticles', 1, 0, 0),
00034 array('oxmpn', 'oxarticles', 0, 0, 0),
00035 array('oxprice', 'oxarticles', 0, 0, 0),
00036 array('oxstock', 'oxarticles', 0, 0, 0),
00037 array('oxid', 'oxarticles', 0, 0, 1)
00038 )
00039 );
00040
00046 protected function _getQuery()
00047 {
00048 $myConfig = $this->getConfig();
00049
00050
00051 $sArtTable = $this->_getViewName('oxarticles');
00052 $sO2CView = $this->_getViewName('oxobject2category');
00053 $oDb = oxDb::getDb();
00054
00055 $sManufacturerId = $myConfig->getRequestParameter('oxid');
00056 $sSynchManufacturerId = $myConfig->getRequestParameter('synchoxid');
00057
00058
00059 if (!$sManufacturerId) {
00060
00061 $sQAdd = ' from ' . $sArtTable . ' where ' . $sArtTable . '.oxshopid="' . $myConfig->getShopId() . '" and 1 ';
00062 $sQAdd .= $myConfig->getRequestParameter('blVariantsSelection') ? '' : " and $sArtTable.oxparentid = '' and $sArtTable.oxmanufacturerid != " . $oDb->quote($sSynchManufacturerId);
00063 } elseif ($sSynchManufacturerId && $sSynchManufacturerId != $sManufacturerId) {
00064
00065 $sQAdd = " from $sO2CView left join $sArtTable on ";
00066 $sQAdd .= $myConfig->getRequestParameter('blVariantsSelection') ? " ( $sArtTable.oxid = $sO2CView.oxobjectid or $sArtTable.oxparentid = $sO2CView.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->getRequestParameter('blVariantsSelection') ? '' : " and $sArtTable.oxparentid = '' ";
00069 } else {
00070 $sQAdd = " from $sArtTable where $sArtTable.oxmanufacturerid = " . $oDb->quote($sManufacturerId);
00071 $sQAdd .= $myConfig->getRequestParameter('blVariantsSelection') ? '' : " and $sArtTable.oxparentid = '' ";
00072 }
00073
00074 return $sQAdd;
00075 }
00076
00084 protected function _addFilter($sQ)
00085 {
00086 $sArtTable = $this->_getViewName('oxarticles');
00087 $sQ = parent::_addFilter($sQ);
00088
00089
00090 $sQ .= $this->getConfig()->getRequestParameter('blVariantsSelection') ? ' group by ' . $sArtTable . '.oxid ' : '';
00091
00092 return $sQ;
00093 }
00094
00098 public function removeManufacturer()
00099 {
00100 $myConfig = $this->getConfig();
00101 $aRemoveArt = $this->_getActionIds('oxarticles.oxid');
00102 $sOxid = $myConfig->getRequestParameter('oxid');
00103
00104 if ($this->getConfig()->getRequestParameter("all")) {
00105 $sArtTable = $this->_getViewName('oxarticles');
00106 $aRemoveArt = $this->_getAll($this->_addFilter("select $sArtTable.oxid " . $this->_getQuery()));
00107 }
00108
00109 if (is_array($aRemoveArt) && !empty($aRemoveArt)) {
00110 $sSelect = "update oxarticles set oxmanufacturerid = null where oxid in ( " . implode(", ", oxDb::getInstance()->quoteArray($aRemoveArt)) . ") ";
00111 oxDb::getDb()->Execute($sSelect);
00112
00113 $this->resetCounter("manufacturerArticle", $sOxid);
00114 }
00115 }
00116
00120 public function addManufacturer()
00121 {
00122 $myConfig = $this->getConfig();
00123
00124 $aAddArticle = $this->_getActionIds('oxarticles.oxid');
00125 $sSynchOxid = $myConfig->getRequestParameter('synchoxid');
00126
00127 if ($myConfig->getRequestParameter('all')) {
00128 $sArtTable = $this->_getViewName('oxarticles');
00129 $aAddArticle = $this->_getAll($this->_addFilter("select $sArtTable.oxid " . $this->_getQuery()));
00130 }
00131
00132 if ($sSynchOxid && $sSynchOxid != "-1" && is_array($aAddArticle)) {
00133 $oDb = oxDb::getDb();
00134 $sSelect = "update oxarticles set oxmanufacturerid = " . $oDb->quote($sSynchOxid) . " where oxid in ( " . implode(", ", oxDb::getInstance()->quoteArray($aAddArticle)) . " )";
00135
00136 $oDb->Execute($sSelect);
00137 $this->resetCounter("manufacturerArticle", $sSynchOxid);
00138 }
00139 }
00140 }