OXID eShop CE  4.8.11
 All Classes Files Functions Variables Pages
discount_main.php
Go to the documentation of this file.
1 <?php
2 
9 {
16  public function render()
17  {
18  $myConfig = $this->getConfig();
20 
21  $sOxId = $this->_aViewData["oxid"] = $this->getEditObjectId();
22  if ( $sOxId != "-1" && isset( $sOxId)) {
23  // load object
24  $oDiscount = oxNew( "oxdiscount" );
25  $oDiscount->loadInLang( $this->_iEditLang, $sOxId );
26 
27  $oOtherLang = $oDiscount->getAvailableInLangs();
28  if (!isset($oOtherLang[$this->_iEditLang])) {
29  // echo "language entry doesn't exist! using: ".key($oOtherLang);
30  $oDiscount->loadInLang( key( $oOtherLang ), $sOxId );
31  }
32 
33  $this->_aViewData["edit"] = $oDiscount;
34 
35 
36  // remove already created languages
37  $aLang = array_diff ( oxRegistry::getLang()->getLanguageNames(), $oOtherLang );
38 
39  if ( count( $aLang ) ) {
40  $this->_aViewData["posslang"] = $aLang;
41  }
42 
43  foreach ( $oOtherLang as $id => $language) {
44  $oLang= new stdClass();
45  $oLang->sLangDesc = $language;
46  $oLang->selected = ($id == $this->_iEditLang);
47  $this->_aViewData["otherlang"][$id] = clone $oLang;
48  }
49  }
50 
51  if ( ( $iAoc = oxConfig::getParameter("aoc") ) ) {
52  if ( $iAoc == "1" ) {
53  $oDiscountMainAjax = oxNew( 'discount_main_ajax' );
54  $this->_aViewData['oxajax'] = $oDiscountMainAjax->getColumns();
55 
56  return "popups/discount_main.tpl";
57  } elseif ( $iAoc == "2" ) {
58  // generating category tree for artikel choose select list
59  $this->_createCategoryTree( "artcattree" );
60 
61  $oDiscountItemAjax = oxNew( 'discount_item_ajax' );
62  $this->_aViewData['oxajax'] = $oDiscountItemAjax->getColumns();
63 
64  return "popups/discount_item.tpl";
65  }
66  }
67  return "discount_main.tpl";
68  }
69 
75  public function getItemDiscountProductTitle()
76  {
77  $sTitle = false;
78  $sOxId = $this->getEditObjectId();
79  if ( $sOxId != "-1" && isset( $sOxId)) {
80  $sViewName = getViewName( "oxarticles", $this->_iEditLang );
81  $oDb = oxDb::getDb();
82  $sQ = "select concat( $sViewName.oxartnum, ' ', $sViewName.oxtitle ) from oxdiscount
83  left join $sViewName on $sViewName.oxid=oxdiscount.oxitmartid
84  where oxdiscount.oxitmartid != '' and oxdiscount.oxid=" . $oDb->quote( $sOxId );
85  $sTitle = $oDb->getOne( $sQ, false, false );
86  }
87 
88  return $sTitle ? $sTitle : " -- ";
89  }
90 
96  public function save()
97  {
98  parent::save();
99 
100  $sOxId = $this->getEditObjectId();
101  $aParams = oxConfig::getParameter( "editval");
102 
103  // shopid
104  $sShopID = oxSession::getVar( "actshop");
105  $aParams['oxdiscount__oxshopid'] = $sShopID;
106 
107  $oAttr = oxNew( "oxdiscount" );
108  if ( $sOxId != "-1") {
109  $oAttr->load( $sOxId );
110  } else {
111  $aParams['oxdiscount__oxid'] = null;
112  }
113 
114  // checkbox handling
115  if ( !isset( $aParams['oxdiscount__oxactive'])) {
116  $aParams['oxdiscount__oxactive'] = 0;
117  }
118 
119 
120  //$aParams = $oAttr->ConvertNameArray2Idx( $aParams);
121  $oAttr->setLanguage(0);
122  $oAttr->assign( $aParams );
123  $oAttr->setLanguage($this->_iEditLang);
124  $oAttr = oxRegistry::get("oxUtilsFile")->processFiles( $oAttr );
125  $oAttr->save();
126 
127  // set oxid if inserted
128  $this->setEditObjectId( $oAttr->getId() );
129  }
130 
136  public function saveinnlang()
137  {
138  parent::save();
139 
140  $sOxId = $this->getEditObjectId();
141  $aParams = oxConfig::getParameter( "editval");
142 
143  // shopid
144  $sShopID = oxSession::getVar( "actshop");
145  $aParams['oxdiscount__oxshopid'] = $sShopID;
146  $oAttr = oxNew( "oxdiscount" );
147  if ( $sOxId != "-1")
148  $oAttr->load( $sOxId);
149  else
150  $aParams['oxdiscount__oxid'] = null;
151  // checkbox handling
152  if ( !isset( $aParams['oxdiscount__oxactive']))
153  $aParams['oxdiscount__oxactive'] = 0;
154 
155 
156  //$aParams = $oAttr->ConvertNameArray2Idx( $aParams);
157  $oAttr->setLanguage(0);
158  $oAttr->assign( $aParams);
159  $oAttr->setLanguage($this->_iEditLang);
160  $oAttr = oxRegistry::get("oxUtilsFile")->processFiles( $oAttr );
161  $oAttr->save();
162 
163  // set oxid if inserted
164  $this->setEditObjectId( $oAttr->getId() );
165  }
166 }