00001 <?php
00002
00006 class discount_articles_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', 'oxobject2discount', 0, 0, 1)
00038 )
00039 );
00040
00046 protected function _getQuery()
00047 {
00048 $oConfig = $this->getConfig();
00049
00050 $sArticleTable = $this->_getViewName('oxarticles');
00051 $sO2CView = $this->_getViewName('oxobject2category');
00052
00053 $oDb = oxDb::getDb();
00054 $sOxid = $oConfig->getRequestParameter('oxid');
00055 $sSynchOxid = $oConfig->getRequestParameter('synchoxid');
00056
00057
00058 if (!$sOxid && $sSynchOxid) {
00059 $sQAdd = " from $sArticleTable where 1 ";
00060 $sQAdd .= $oConfig->getConfigParam('blVariantsSelection') ? '' : "and $sArticleTable.oxparentid = '' ";
00061 } else {
00062
00063 if ($sSynchOxid && $sOxid != $sSynchOxid) {
00064 $sQAdd = " from $sO2CView left join $sArticleTable on ";
00065 $sQAdd .= $oConfig->getConfigParam('blVariantsSelection') ? "($sArticleTable.oxid=$sO2CView.oxobjectid or $sArticleTable.oxparentid=$sO2CView.oxobjectid)" : " $sArticleTable.oxid=$sO2CView.oxobjectid ";
00066 $sQAdd .= " where $sO2CView.oxcatnid = " . $oDb->quote($sOxid) . " and $sArticleTable.oxid is not null ";
00067
00068
00069 $sId = null;
00070 } else {
00071 $sQAdd = " from oxobject2discount, $sArticleTable where $sArticleTable.oxid=oxobject2discount.oxobjectid ";
00072 $sQAdd .= " and oxobject2discount.oxdiscountid = " . $oDb->quote($sOxid) . " and oxobject2discount.oxtype = 'oxarticles' ";
00073 }
00074 }
00075
00076 if ($sSynchOxid && $sSynchOxid != $sOxid) {
00077
00078 $sSubSelect .= " select $sArticleTable.oxid from oxobject2discount, $sArticleTable where $sArticleTable.oxid=oxobject2discount.oxobjectid ";
00079 $sSubSelect .= " and oxobject2discount.oxdiscountid = " . $oDb->quote($sSynchOxid) . " and oxobject2discount.oxtype = 'oxarticles' ";
00080
00081 if (stristr($sQAdd, 'where') === false) {
00082 $sQAdd .= ' where ';
00083 } else {
00084 $sQAdd .= ' and ';
00085 }
00086 $sQAdd .= " $sArticleTable.oxid not in ( $sSubSelect ) ";
00087 }
00088
00089 return $sQAdd;
00090 }
00091
00095 public function removeDiscArt()
00096 {
00097 $aChosenArt = $this->_getActionIds('oxobject2discount.oxid');
00098
00099
00100 if ($this->getConfig()->getRequestParameter('all')) {
00101
00102 $sQ = parent::_addFilter("delete oxobject2discount.* " . $this->_getQuery());
00103 oxDb::getDb()->Execute($sQ);
00104
00105 } elseif (is_array($aChosenArt)) {
00106 $sQ = "delete from oxobject2discount where oxobject2discount.oxid in (" . implode(", ", oxDb::getInstance()->quoteArray($aChosenArt)) . ") ";
00107 oxDb::getDb()->Execute($sQ);
00108 }
00109 }
00110
00114 public function addDiscArt()
00115 {
00116 $oConfig = $this->getConfig();
00117 $aChosenArt = $this->_getActionIds('oxarticles.oxid');
00118 $soxId = $oConfig->getRequestParameter('synchoxid');
00119
00120
00121
00122 if ($oConfig->getRequestParameter('all')) {
00123 $sArticleTable = $this->_getViewName('oxarticles');
00124 $aChosenArt = $this->_getAll(parent::_addFilter("select $sArticleTable.oxid " . $this->_getQuery()));
00125 }
00126 if ($soxId && $soxId != "-1" && is_array($aChosenArt)) {
00127 foreach ($aChosenArt as $sChosenArt) {
00128 $oObject2Discount = oxNew("oxbase");
00129 $oObject2Discount->init('oxobject2discount');
00130 $oObject2Discount->oxobject2discount__oxdiscountid = new oxField($soxId);
00131 $oObject2Discount->oxobject2discount__oxobjectid = new oxField($sChosenArt);
00132 $oObject2Discount->oxobject2discount__oxtype = new oxField("oxarticles");
00133 $oObject2Discount->save();
00134
00135 }
00136 }
00137 }
00138 }