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