OXID eShop CE  4.9.5
 All Classes Files Functions Variables Pages
delivery_articles_ajax.php
Go to the documentation of this file.
1 <?php
2 
7 {
8 
14  protected $_aColumns = array('container1' => array( // field , table, visible, multilanguage, ident
15  array('oxartnum', 'oxarticles', 1, 0, 0),
16  array('oxtitle', 'oxarticles', 1, 1, 0),
17  array('oxean', 'oxarticles', 1, 0, 0),
18  array('oxmpn', 'oxarticles', 0, 0, 0),
19  array('oxprice', 'oxarticles', 0, 0, 0),
20  array('oxstock', 'oxarticles', 0, 0, 0),
21  array('oxid', 'oxarticles', 0, 0, 1)
22  ),
23  'container2' => array(
24  array('oxartnum', 'oxarticles', 1, 0, 0),
25  array('oxtitle', 'oxarticles', 1, 1, 0),
26  array('oxean', 'oxarticles', 1, 0, 0),
27  array('oxmpn', 'oxarticles', 0, 0, 0),
28  array('oxprice', 'oxarticles', 0, 0, 0),
29  array('oxstock', 'oxarticles', 0, 0, 0),
30  array('oxid', 'oxobject2delivery', 0, 0, 1)
31  )
32  );
33 
39  protected $_blAllowExtColumns = true;
40 
46  protected function _getQuery()
47  {
48  $myConfig = $this->getConfig();
49  $oDb = oxDb::getDb();
50 
51  // looking for table/view
52  $sArtTable = $this->_getViewName('oxarticles');
53  $sCatTable = $this->_getViewName('oxcategories');
54  $sO2CView = $this->_getViewName('oxobject2category');
55 
56  $sDelId = $this->getConfig()->getRequestParameter('oxid');
57  $sSynchDelId = $this->getConfig()->getRequestParameter('synchoxid');
58 
59  // category selected or not ?
60  if (!$sDelId) {
61  // performance
62  $sQAdd = " from $sArtTable where 1 ";
63  $sQAdd .= $myConfig->getConfigParam('blVariantsSelection') ? '' : "and $sArtTable.oxparentid = '' ";
64  } else {
65  // selected category ?
66  if ($sSynchDelId && $sDelId != $sSynchDelId) {
67  $sQAdd = " from $sO2CView left join $sArtTable on ";
68  $sQAdd .= $myConfig->getConfigParam('blVariantsSelection') ? " ( $sArtTable.oxid=$sO2CView.oxobjectid or $sArtTable.oxparentid=$sO2CView.oxobjectid)" : " $sArtTable.oxid=$sO2CView.oxobjectid ";
69  $sQAdd .= "where $sO2CView.oxcatnid = " . $oDb->quote($sDelId);
70  } else {
71  $sQAdd = ' from oxobject2delivery left join ' . $sArtTable . ' on ' . $sArtTable . '.oxid=oxobject2delivery.oxobjectid ';
72  $sQAdd .= 'where oxobject2delivery.oxdeliveryid = ' . $oDb->quote($sDelId) . ' and oxobject2delivery.oxtype = "oxarticles" ';
73  }
74  }
75 
76  if ($sSynchDelId && $sSynchDelId != $sDelId) {
77  $sQAdd .= 'and ' . $sArtTable . '.oxid not in ( ';
78  $sQAdd .= 'select oxobject2delivery.oxobjectid from oxobject2delivery ';
79  $sQAdd .= 'where oxobject2delivery.oxdeliveryid = ' . $oDb->quote($sSynchDelId) . ' and oxobject2delivery.oxtype = "oxarticles" ) ';
80  }
81 
82  return $sQAdd;
83  }
84 
92  /*protected function _addFilter( $sQ )
93  {
94  $sArtTable = $this->_getViewName('oxarticles');
95  $sQ = parent::_addFilter( $sQ );
96 
97  // display variants or not ?
98  $sQ .= $this->getConfig()->getConfigParam( 'blVariantsSelection' ) ? ' group by '.$sArtTable.'.oxid ' : '';
99  return $sQ;
100  }*/
101 
105  public function removeArtFromDel()
106  {
107  $aChosenArt = $this->_getActionIds('oxobject2delivery.oxid');
108  // removing all
109  if ($this->getConfig()->getRequestParameter('all')) {
110 
111  $sQ = parent::_addFilter("delete oxobject2delivery.* " . $this->_getQuery());
112  oxDb::getDb()->Execute($sQ);
113 
114  } elseif (is_array($aChosenArt)) {
115  $sQ = "delete from oxobject2delivery where oxobject2delivery.oxid in (" . implode(", ", oxDb::getInstance()->quoteArray($aChosenArt)) . ") ";
116  oxDb::getDb()->Execute($sQ);
117  }
118  }
119 
123  public function addArtToDel()
124  {
125  $aChosenArt = $this->_getActionIds('oxarticles.oxid');
126  $soxId = $this->getConfig()->getRequestParameter('synchoxid');
127 
128  // adding
129  if ($this->getConfig()->getRequestParameter('all')) {
130  $sArtTable = $this->_getViewName('oxarticles');
131  $aChosenArt = $this->_getAll($this->_addFilter("select $sArtTable.oxid " . $this->_getQuery()));
132  }
133 
134  if ($soxId && $soxId != "-1" && is_array($aChosenArt)) {
135  foreach ($aChosenArt as $sChosenArt) {
136  $oObject2Delivery = oxNew('oxbase');
137  $oObject2Delivery->init('oxobject2delivery');
138  $oObject2Delivery->oxobject2delivery__oxdeliveryid = new oxField($soxId);
139  $oObject2Delivery->oxobject2delivery__oxobjectid = new oxField($sChosenArt);
140  $oObject2Delivery->oxobject2delivery__oxtype = new oxField("oxarticles");
141  $oObject2Delivery->save();
142  }
143  }
144  }
145 }