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