OXID eShop CE  4.10.1
 All Classes Namespaces Files Functions Variables Pages
discount_articles_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', 'oxobject2discount', 0, 0, 1)
38  )
39  );
40 
46  protected function _getQuery()
47  {
48  $oConfig = $this->getConfig();
49 
50  $sArticleTable = $this->_getViewName('oxarticles');
51  $sO2CView = $this->_getViewName('oxobject2category');
52 
53  $oDb = oxDb::getDb();
54  $sOxid = $oConfig->getRequestParameter('oxid');
55  $sSynchOxid = $oConfig->getRequestParameter('synchoxid');
56 
57  // category selected or not ?
58  if (!$sOxid && $sSynchOxid) {
59  $sQAdd = " from $sArticleTable where 1 ";
60  $sQAdd .= $oConfig->getConfigParam('blVariantsSelection') ? '' : "and $sArticleTable.oxparentid = '' ";
61 
62  //#6027
63  //if we have variants then depending on config option the parent may be non buyable
64  //when the checkbox is checked, blVariantParentBuyable is true.
65  $sQAdd .= $oConfig->getConfigParam('blVariantParentBuyable') ? '' : "and $sArticleTable.oxvarcount = 0";
66  } else {
67  // selected category ?
68  if ($sSynchOxid && $sOxid != $sSynchOxid) {
69  $sQAdd = " from $sO2CView left join $sArticleTable on ";
70  $sQAdd .= $oConfig->getConfigParam('blVariantsSelection') ? "($sArticleTable.oxid=$sO2CView.oxobjectid or $sArticleTable.oxparentid=$sO2CView.oxobjectid)" : " $sArticleTable.oxid=$sO2CView.oxobjectid ";
71  $sQAdd .= " where $sO2CView.oxcatnid = " . $oDb->quote($sOxid) . " and $sArticleTable.oxid is not null ";
72  //#6027
73  $sQAdd .= $oConfig->getConfigParam('blVariantParentBuyable') ? '' : " and $sArticleTable.oxvarcount = 0";
74 
75  // resetting
76  $sId = null;
77  } else {
78  $sQAdd = " from oxobject2discount, $sArticleTable where $sArticleTable.oxid=oxobject2discount.oxobjectid ";
79  $sQAdd .= " and oxobject2discount.oxdiscountid = " . $oDb->quote($sOxid) . " and oxobject2discount.oxtype = 'oxarticles' ";
80  }
81  }
82 
83  if ($sSynchOxid && $sSynchOxid != $sOxid) {
84  // performance
85  $sSubSelect .= " select $sArticleTable.oxid from oxobject2discount, $sArticleTable where $sArticleTable.oxid=oxobject2discount.oxobjectid ";
86  $sSubSelect .= " and oxobject2discount.oxdiscountid = " . $oDb->quote($sSynchOxid) . " and oxobject2discount.oxtype = 'oxarticles' ";
87 
88  if (stristr($sQAdd, 'where') === false) {
89  $sQAdd .= ' where ';
90  } else {
91  $sQAdd .= ' and ';
92  }
93  $sQAdd .= " $sArticleTable.oxid not in ( $sSubSelect ) ";
94  }
95 
96  return $sQAdd;
97  }
98 
102  public function removeDiscArt()
103  {
104  $aChosenArt = $this->_getActionIds('oxobject2discount.oxid');
105 
106 
107  if ($this->getConfig()->getRequestParameter('all')) {
108 
109  $sQ = parent::_addFilter("delete oxobject2discount.* " . $this->_getQuery());
110  oxDb::getDb()->Execute($sQ);
111 
112  } elseif (is_array($aChosenArt)) {
113  $sQ = "delete from oxobject2discount where oxobject2discount.oxid in (" . implode(", ", oxDb::getInstance()->quoteArray($aChosenArt)) . ") ";
114  oxDb::getDb()->Execute($sQ);
115  }
116  }
117 
121  public function addDiscArt()
122  {
123  $oConfig = $this->getConfig();
124  $aChosenArt = $this->_getActionIds('oxarticles.oxid');
125  $soxId = $oConfig->getRequestParameter('synchoxid');
126 
127 
128  // adding
129  if ($oConfig->getRequestParameter('all')) {
130  $sArticleTable = $this->_getViewName('oxarticles');
131  $aChosenArt = $this->_getAll(parent::_addFilter("select $sArticleTable.oxid " . $this->_getQuery()));
132  }
133  if ($soxId && $soxId != "-1" && is_array($aChosenArt)) {
134  foreach ($aChosenArt as $sChosenArt) {
135  $oObject2Discount = oxNew("oxbase");
136  $oObject2Discount->init('oxobject2discount');
137  $oObject2Discount->oxobject2discount__oxdiscountid = new oxField($soxId);
138  $oObject2Discount->oxobject2discount__oxobjectid = new oxField($sChosenArt);
139  $oObject2Discount->oxobject2discount__oxtype = new oxField("oxarticles");
140  $oObject2Discount->save();
141 
142  }
143  }
144  }
145 }