OXID eShop CE  4.8.12
 All Classes Files Functions Variables Pages
payment_country_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', 'oxobject2payment', 0, 0, 1 )
26  )
27  );
28 
34  protected function _getQuery()
35  {
36  // looking for table/view
37  $sCountryTable = $this->_getViewName('oxcountry');
38  $oDb = oxDb::getDb();
39  $sCountryId = $this->getConfig()->getRequestParameter( 'oxid' );
40  $sSynchCountryId = $this->getConfig()->getRequestParameter( 'synchoxid' );
41 
42  // category selected or not ?
43  if ( !$sCountryId) {
44  // which fields to load ?
45  $sQAdd = " from $sCountryTable where $sCountryTable.oxactive = '1' ";
46  } else {
47 
48  $sQAdd = " from oxobject2payment left join $sCountryTable on $sCountryTable.oxid=oxobject2payment.oxobjectid ";
49  $sQAdd .= "where $sCountryTable.oxactive = '1' and oxobject2payment.oxpaymentid = ".$oDb->quote( $sCountryId )." and oxobject2payment.oxtype = 'oxcountry' ";
50  }
51 
52  if ( $sSynchCountryId && $sSynchCountryId != $sCountryId ) {
53  $sQAdd .= "and $sCountryTable.oxid not in ( ";
54  $sQAdd .= "select $sCountryTable.oxid from oxobject2payment left join $sCountryTable on $sCountryTable.oxid=oxobject2payment.oxobjectid ";
55  $sQAdd .= "where oxobject2payment.oxpaymentid = ".$oDb->quote( $sSynchCountryId )." and oxobject2payment.oxtype = 'oxcountry' ) ";
56  }
57 
58  return $sQAdd;
59  }
60 
66  public function addPayCountry()
67  {
68  $aChosenCntr = $this->_getActionIds( 'oxcountry.oxid' );
69  $soxId = $this->getConfig()->getRequestParameter( 'synchoxid');
70 
71  if ( $this->getConfig()->getRequestParameter( 'all' ) ) {
72  $sCountryTable = $this->_getViewName('oxcountry');
73  $aChosenCntr = $this->_getAll( $this->_addFilter( "select $sCountryTable.oxid ".$this->_getQuery() ) );
74  }
75  if ( $soxId && $soxId != "-1" && is_array( $aChosenCntr ) ) {
76  foreach ( $aChosenCntr as $sChosenCntr) {
77  $oObject2Payment = oxNew( 'oxbase' );
78  $oObject2Payment->init( 'oxobject2payment' );
79  $oObject2Payment->oxobject2payment__oxpaymentid = new oxField($soxId);
80  $oObject2Payment->oxobject2payment__oxobjectid = new oxField($sChosenCntr);
81  $oObject2Payment->oxobject2payment__oxtype = new oxField("oxcountry");
82  $oObject2Payment->save();
83  }
84  }
85  }
86 
92  public function removePayCountry()
93  {
94  $aChosenCntr = $this->_getActionIds( 'oxobject2payment.oxid' );
95  if ( $this->getConfig()->getRequestParameter( 'all' ) ) {
96 
97  $sQ = $this->_addFilter( "delete oxobject2payment.* ".$this->_getQuery() );
98  oxDb::getDb()->Execute( $sQ );
99 
100  } elseif ( is_array( $aChosenCntr ) ) {
101  $sQ = "delete from oxobject2payment where oxobject2payment.oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aChosenCntr ) ) . ") ";
102  oxDb::getDb()->Execute( $sQ );
103  }
104  }
105 }