OXID eShop CE  4.8.12
 All Classes Files Functions Variables Pages
discount_articles_ajax.php
Go to the documentation of this file.
1 <?php
2 
7 {
13  protected $_blAllowExtColumns = true;
14 
20  protected $_aColumns = array( 'container1' => array( // field , table, visible, multilanguage, ident
21  array( 'oxartnum', 'oxarticles', 1, 0, 0 ),
22  array( 'oxtitle', 'oxarticles', 1, 1, 0 ),
23  array( 'oxean', 'oxarticles', 1, 0, 0 ),
24  array( 'oxmpn', 'oxarticles', 0, 0, 0 ),
25  array( 'oxprice', 'oxarticles', 0, 0, 0 ),
26  array( 'oxstock', 'oxarticles', 0, 0, 0 ),
27  array( 'oxid', 'oxarticles', 0, 0, 1 )
28  ),
29  'container2' => array(
30  array( 'oxartnum', 'oxarticles', 1, 0, 0 ),
31  array( 'oxtitle', 'oxarticles', 1, 1, 0 ),
32  array( 'oxean', 'oxarticles', 1, 0, 0 ),
33  array( 'oxmpn', 'oxarticles', 0, 0, 0 ),
34  array( 'oxprice', 'oxarticles', 0, 0, 0 ),
35  array( 'oxstock', 'oxarticles', 0, 0, 0 ),
36  array( 'oxid', 'oxobject2discount', 0, 0, 1 )
37  )
38  );
39 
45  protected function _getQuery()
46  {
47  $oConfig = $this->getConfig();
48 
49  $sArticleTable = $this->_getViewName('oxarticles');
50  $sO2CView = $this->_getViewName('oxobject2category');
51 
52  $oDb = oxDb::getDb();
53  $sOxid = $oConfig->getRequestParameter( 'oxid' );
54  $sSynchOxid = $oConfig->getRequestParameter( 'synchoxid' );
55 
56  // category selected or not ?
57  if ( !$sOxid && $sSynchOxid ) {
58  $sQAdd = " from $sArticleTable where 1 ";
59  $sQAdd .= $oConfig->getConfigParam( 'blVariantsSelection' )?'':"and $sArticleTable.oxparentid = '' ";
60  } else {
61  // selected category ?
62  if ( $sSynchOxid && $sOxid != $sSynchOxid ) {
63  $sQAdd = " from $sO2CView left join $sArticleTable on ";
64  $sQAdd .= $oConfig->getConfigParam( 'blVariantsSelection' )?"($sArticleTable.oxid=$sO2CView.oxobjectid or $sArticleTable.oxparentid=$sO2CView.oxobjectid)":" $sArticleTable.oxid=$sO2CView.oxobjectid ";
65  $sQAdd .= " where $sO2CView.oxcatnid = ".$oDb->quote( $sOxid )." and $sArticleTable.oxid is not null ";
66 
67  // resetting
68  $sId = null;
69  } else {
70  $sQAdd = " from oxobject2discount, $sArticleTable where $sArticleTable.oxid=oxobject2discount.oxobjectid ";
71  $sQAdd .= " and oxobject2discount.oxdiscountid = ".$oDb->quote( $sOxid )." and oxobject2discount.oxtype = 'oxarticles' ";
72  }
73  }
74 
75  if ( $sSynchOxid && $sSynchOxid != $sOxid) {
76  // dodger performance
77  $sSubSelect .= " select $sArticleTable.oxid from oxobject2discount, $sArticleTable where $sArticleTable.oxid=oxobject2discount.oxobjectid ";
78  $sSubSelect .= " and oxobject2discount.oxdiscountid = ".$oDb->quote( $sSynchOxid )." and oxobject2discount.oxtype = 'oxarticles' ";
79 
80  if ( stristr( $sQAdd, 'where' ) === false )
81  $sQAdd .= ' where ';
82  else
83  $sQAdd .= ' and ';
84  $sQAdd .= " $sArticleTable.oxid not in ( $sSubSelect ) ";
85  }
86 
87  return $sQAdd;
88  }
89 
95  public function removeDiscArt()
96  {
97  $aChosenArt = $this->_getActionIds( 'oxobject2discount.oxid' );
98 
99 
100  if ( $this->getConfig()->getRequestParameter( 'all' ) ) {
101 
102  $sQ = parent::_addFilter( "delete oxobject2discount.* ".$this->_getQuery() );
103  oxDb::getDb()->Execute( $sQ );
104 
105  } elseif ( is_array( $aChosenArt ) ) {
106  $sQ = "delete from oxobject2discount where oxobject2discount.oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aChosenArt ) ) . ") ";
107  oxDb::getDb()->Execute( $sQ );
108  }
109  }
110 
116  public function addDiscArt()
117  {
118  $oConfig = $this->getConfig();
119  $aChosenArt = $this->_getActionIds( 'oxarticles.oxid' );
120  $soxId = $oConfig->getRequestParameter('synchoxid');
121 
122 
123  // adding
124  if ( $oConfig->getRequestParameter( 'all' ) ) {
125  $sArticleTable = $this->_getViewName('oxarticles');
126  $aChosenArt = $this->_getAll( parent::_addFilter( "select $sArticleTable.oxid ".$this->_getQuery() ) );
127  }
128  if ( $soxId && $soxId != "-1" && is_array( $aChosenArt ) ) {
129  foreach ( $aChosenArt as $sChosenArt) {
130  $oObject2Discount = oxNew( "oxbase" );
131  $oObject2Discount->init( 'oxobject2discount' );
132  $oObject2Discount->oxobject2discount__oxdiscountid = new oxField($soxId);
133  $oObject2Discount->oxobject2discount__oxobjectid = new oxField($sChosenArt);
134  $oObject2Discount->oxobject2discount__oxtype = new oxField("oxarticles");
135  $oObject2Discount->save();
136 
137  }
138  }
139  }
140 
141 
142 }