00001 <?php
00002
00006 class vendor_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
00049 $sArtTable = $this->_getViewName('oxarticles');
00050 $sO2CView = $this->_getViewName('oxobject2category');
00051 $oDb = oxDb::getDb();
00052 $oConfig = oxRegistry::getConfig();
00053 $sVendorId = $oConfig->getRequestParameter('oxid');
00054 $sSynchVendorId = $oConfig->getRequestParameter('synchoxid');
00055
00056
00057 if (!$sVendorId) {
00058 $sQAdd = ' from ' . $sArtTable . ' where ' . $sArtTable . '.oxshopid="' . $oConfig->getShopId() . '" and 1 ';
00059 $sQAdd .= $oConfig->getConfigParam('blVariantsSelection') ? '' : " and $sArtTable.oxparentid = '' and $sArtTable.oxvendorid != " . $oDb->quote($sSynchVendorId);
00060 } else {
00061
00062 if ($sSynchVendorId && $sSynchVendorId != $sVendorId) {
00063 $sQAdd = " from $sO2CView left join $sArtTable on ";
00064 $sQAdd .= $oConfig->getConfigParam('blVariantsSelection') ? " ( $sArtTable.oxid = $sO2CView.oxobjectid or $sArtTable.oxparentid = oxobject2category.oxobjectid )" : " $sArtTable.oxid = $sO2CView.oxobjectid ";
00065 $sQAdd .= 'where ' . $sArtTable . '.oxshopid="' . $oConfig->getShopId() . '" and ' . $sO2CView . '.oxcatnid = ' . $oDb->quote($sVendorId) . ' and ' . $sArtTable . '.oxvendorid != ' . $oDb->quote($sSynchVendorId);
00066 } else {
00067 $sQAdd = " from $sArtTable where $sArtTable.oxvendorid = " . $oDb->quote($sVendorId);
00068 }
00069
00070 $sQAdd .= $oConfig->getConfigParam('blVariantsSelection') ? '' : " and $sArtTable.oxparentid = '' ";
00071 }
00072
00073 return $sQAdd;
00074 }
00075
00083 protected function _addFilter($sQ)
00084 {
00085 $sArtTable = $this->_getViewName('oxarticles');
00086 $sQ = parent::_addFilter($sQ);
00087
00088
00089 $sQ .= $this->getConfig()->getConfigParam('blVariantsSelection') ? ' group by ' . $sArtTable . '.oxid ' : '';
00090
00091 return $sQ;
00092 }
00093
00097 public function removeVendor()
00098 {
00099 $oConfig = $this->getConfig();
00100 $aRemoveArt = $this->_getActionIds('oxarticles.oxid');
00101
00102 if ($oConfig->getRequestParameter('all')) {
00103 $sArtTable = $this->_getViewName('oxarticles');
00104 $aRemoveArt = $this->_getAll($this->_addFilter("select $sArtTable.oxid " . $this->_getQuery()));
00105 }
00106
00107 if (is_array($aRemoveArt)) {
00108 $sSelect = "update oxarticles set oxvendorid = null where oxid in ( " . implode(", ", oxDb::getInstance()->quoteArray($aRemoveArt)) . ") ";
00109 oxDb::getDb()->Execute($sSelect);
00110 $this->resetCounter("vendorArticle", $oConfig->getRequestParameter('oxid'));
00111 }
00112 }
00113
00117 public function addVendor()
00118 {
00119 $oConfig = $this->getConfig();
00120
00121 $aAddArticle = $this->_getActionIds('oxarticles.oxid');
00122 $soxId = $oConfig->getRequestParameter('synchoxid');
00123
00124 if ($oConfig->getRequestParameter('all')) {
00125 $sArtTable = $this->_getViewName('oxarticles');
00126 $aAddArticle = $this->_getAll($this->_addFilter("select $sArtTable.oxid " . $this->_getQuery()));
00127 }
00128
00129 if ($soxId && $soxId != "-1" && is_array($aAddArticle)) {
00130 $oDb = oxDb::getDb();
00131 $sSelect = "update oxarticles set oxvendorid = " . $oDb->quote($soxId) . " where oxid in ( " . implode(", ", oxDb::getInstance()->quoteArray($aAddArticle)) . " )";
00132
00133 $oDb->Execute($sSelect);
00134 $this->resetCounter("vendorArticle", $soxId);
00135 }
00136 }
00137 }