OXID eShop CE  4.8.11
 All Classes Files Functions Variables Pages
discount_main_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( 'oxtitle', 'oxcountry', 1, 1, 0 ),
15  array( 'oxisoalpha2', 'oxcountry', 1, 0, 0 ),
16  array( 'oxisoalpha3', 'oxcountry', 0, 0, 0 ),
17  array( 'oxunnum3', 'oxcountry', 0, 0, 0 ),
18  array( 'oxid', 'oxcountry', 0, 0, 1 )
19  ),
20  'container2' => array(
21  array( 'oxtitle', 'oxcountry', 1, 1, 0 ),
22  array( 'oxisoalpha2', 'oxcountry', 1, 0, 0 ),
23  array( 'oxisoalpha3', 'oxcountry', 0, 0, 0 ),
24  array( 'oxunnum3', 'oxcountry', 0, 0, 0 ),
25  array( 'oxid', 'oxobject2discount', 0, 0, 1 )
26  )
27  );
28 
34  protected function _getQuery()
35  {
36  $oConfig = $this->getConfig();
37  $sCountryTable = $this->_getViewName('oxcountry');
38  $oDb = oxDb::getDb();
39  $sId = $oConfig->getRequestParameter( 'oxid' );
40  $sSynchId = $oConfig->getRequestParameter( 'synchoxid' );
41 
42  // category selected or not ?
43  if ( !$sId) {
44  $sQAdd = " from $sCountryTable where $sCountryTable.oxactive = '1' ";
45  } else {
46  $sQAdd = " from oxobject2discount, $sCountryTable where $sCountryTable.oxid=oxobject2discount.oxobjectid ";
47  $sQAdd .= "and oxobject2discount.oxdiscountid = ".$oDb->quote( $sId )." and oxobject2discount.oxtype = 'oxcountry' ";
48  }
49 
50  if ( $sSynchId && $sSynchId != $sId) {
51  $sQAdd .= "and $sCountryTable.oxid not in ( select $sCountryTable.oxid from oxobject2discount, $sCountryTable where $sCountryTable.oxid=oxobject2discount.oxobjectid ";
52  $sQAdd .= "and oxobject2discount.oxdiscountid = ".$oDb->quote( $sSynchId )." and oxobject2discount.oxtype = 'oxcountry' ) ";
53  }
54 
55  return $sQAdd;
56  }
57 
63  public function removeDiscCountry()
64  {
65  $oConfig = $this->getConfig();
66 
67  $aChosenCntr = $this->_getActionIds( 'oxobject2discount.oxid' );
68  if ( $oConfig->getRequestParameter( 'all' ) ) {
69 
70  $sQ = $this->_addFilter( "delete oxobject2discount.* ".$this->_getQuery() );
71  oxDb::getDb()->Execute( $sQ );
72 
73  } elseif ( is_array( $aChosenCntr ) ) {
74  $sQ = "delete from oxobject2discount where oxobject2discount.oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aChosenCntr ) ) . ") ";
75  oxDb::getDb()->Execute( $sQ );
76  }
77  }
78 
84  public function addDiscCountry()
85  {
86  $oConfig = $this->getConfig();
87  $aChosenCntr = $this->_getActionIds( 'oxcountry.oxid' );
88  $soxId = $oConfig->getRequestParameter( 'synchoxid');
89 
90 
91  if ( $oConfig->getRequestParameter( 'all' ) ) {
92  $sCountryTable = $this->_getViewName('oxcountry');
93  $aChosenCntr = $this->_getAll( $this->_addFilter( "select $sCountryTable.oxid ".$this->_getQuery() ) );
94  }
95  if ( $soxId && $soxId != "-1" && is_array( $aChosenCntr ) ) {
96  foreach ( $aChosenCntr as $sChosenCntr) {
97  $oObject2Discount = oxNew( "oxbase" );
98  $oObject2Discount->init( 'oxobject2discount' );
99  $oObject2Discount->oxobject2discount__oxdiscountid = new oxField($soxId);
100  $oObject2Discount->oxobject2discount__oxobjectid = new oxField($sChosenCntr);
101  $oObject2Discount->oxobject2discount__oxtype = new oxField("oxcountry");
102  $oObject2Discount->save();
103  }
104  }
105  }
106 }