OXID eShop CE  4.8.11
 All Classes Files Functions Variables Pages
oxcmp_utils.php
Go to the documentation of this file.
1 <?php
2 
9 class oxcmp_utils extends oxView
10 {
15  protected $_blIsComponent = true;
16 
27  public function getArticle()
28  {
29  $myConfig = $this->getConfig();
30  $myUtils = oxRegistry::getUtils();
31 
32  if (!$myConfig->getConfigParam("blAllowRemoteArticleInfo"))
33  return false;
34 
35 
36  $sOutput = 'OXID__Problem : no valid oxid !';
37  $oProduct = null;
38 
39  if ( ( $sId = oxConfig::getParameter( 'oxid' ) ) ) {
40  $oProduct = oxNew( 'oxArticle' );
41  $oProduct->load( $sId );
42  } elseif ( $myConfig->getConfigParam( 'bl_perfLoadAktion' ) ) {
43  $oArtList = oxNew( 'oxarticlelist');
44  $oArtList->loadActionArticles( 'OXAFFILIATE' );
45  $oProduct = $oArtList->current();
46  }
47 
48  if ( $oProduct ) {
49 
50  $aExport = array();
51 
52  $aClassVars = get_object_vars( $oProduct );
53  $oStr = getStr();
54 
55  // add all database fields
56  while ( list( $sFieldName, ) = each( $aClassVars ) ) {
57  if ( $oStr->strstr( $sFieldName, 'oxarticles' ) ) {
58  $sName = str_replace( 'oxarticles__', '', $sFieldName );
59  $aExport[$sName] = $oProduct->$sFieldName->value;
60  }
61  }
62 
63  $oPrice = $oProduct->getPrice();
64 
65  $aExport['vatPercent'] = $oPrice->getVat();
66  $aExport['netPrice'] = $myUtils->fRound( $oPrice->getNettoPrice() );
67  $aExport['brutPrice'] = $myUtils->fRound( $oPrice->getBruttoPrice() );
68  $aExport['vat'] = $oPrice->getVatValue();
69  $aExport['fprice'] = $oProduct->getFPrice();
70  $aExport['ftprice'] = $oProduct->getFTPrice();
71 
72  $aExport['oxdetaillink'] = $oProduct->getLink();
73  $aExport['oxmoredetaillink'] = $oProduct->getMoreDetailLink();
74  $aExport['tobasketlink'] = $oProduct->getToBasketLink();
75  $aExport['thumbnaillink'] = $myConfig->getPictureUrl(null, false, $myConfig->isSsl()) ."/". $aExport['oxthumb'];
76  $sOutput = serialize( $aExport );
77  }
78 
79  // stop shop here
80  $myUtils->showMessageAndExit( $sOutput );
81  }
82 
94  public function toCompareList( $sProductId = null, $dAmount = null, $aSel = null, $blOverride = false, $blBundle = false )
95  {
96  // only if enabled and not search engine..
97  if ( $this->getViewConfig()->getShowCompareList() && !oxRegistry::getUtils()->isSearchEngine() ) {
98 
99 
100 
101  // #657 special treatment if we want to put on comparelist
102  $blAddCompare = oxConfig::getParameter( 'addcompare' );
103  $blRemoveCompare = oxConfig::getParameter( 'removecompare' );
104  $sProductId = $sProductId ? $sProductId:oxConfig::getParameter( 'aid' );
105  if ( ( $blAddCompare || $blRemoveCompare ) && $sProductId ) {
106 
107  // toggle state in session array
108  $aItems = oxSession::getVar( 'aFiltcompproducts' );
109  if ( $blAddCompare && !isset( $aItems[$sProductId] ) ) {
110  $aItems[$sProductId] = true;
111  }
112 
113  if ( $blRemoveCompare ) {
114  unset( $aItems[$sProductId] );
115  }
116 
117  oxSession::setVar( 'aFiltcompproducts', $aItems );
118  $oParentView = $this->getParent();
119 
120  // #843C there was problem then field "blIsOnComparisonList" was not set to article object
121  if ( ( $oProduct = $oParentView->getViewProduct() ) ) {
122  if ( isset( $aItems[$oProduct->getId()] ) ) {
123  $oProduct->setOnComparisonList( true );
124  } else {
125  $oProduct->setOnComparisonList( false );
126  }
127  }
128 
129  $aViewProds = $oParentView->getViewProductList();
130  if ( is_array( $aViewProds ) && count( $aViewProds ) ) {
131  foreach ( $aViewProds as $oProduct ) {
132  if ( isset( $aItems[$oProduct->getId()] ) ) {
133  $oProduct->setOnComparisonList( true );
134  } else {
135  $oProduct->setOnComparisonList( false );
136  }
137  }
138  }
139  }
140  }
141  }
142 
153  public function toNoticeList( $sProductId = null, $dAmount = null, $aSel = null)
154  {
155  if (!oxRegistry::getSession()->checkSessionChallenge()) {
156  return;
157  }
158 
159  $this->_toList( 'noticelist', $sProductId, $dAmount, $aSel );
160  }
161 
172  public function toWishList( $sProductId = null, $dAmount = null, $aSel = null )
173  {
174  if (!oxRegistry::getSession()->checkSessionChallenge()) {
175  return;
176  }
177 
178  // only if enabled
179  if ( $this->getViewConfig()->getShowWishlist() ) {
180  $this->_toList( 'wishlist', $sProductId, $dAmount, $aSel );
181  }
182  }
183 
194  protected function _toList( $sListType, $sProductId, $dAmount, $aSel )
195  {
196  // only if user is logged in
197  if ( $oUser = $this->getUser() ) {
198 
199  $sProductId = ($sProductId) ? $sProductId : oxConfig::getParameter( 'itmid' );
200  $sProductId = ($sProductId) ? $sProductId : oxConfig::getParameter( 'aid' );
201  $dAmount = isset( $dAmount ) ? $dAmount : oxConfig::getParameter( 'am' );
202  $aSel = $aSel ? $aSel : oxConfig::getParameter( 'sel' );
203 
204  // processing amounts
205  $dAmount = str_replace( ',', '.', $dAmount );
206  if ( !$this->getConfig()->getConfigParam( 'blAllowUnevenAmounts' ) ) {
207  $dAmount = round( ( string ) $dAmount );
208  }
209 
210  $oBasket = $oUser->getBasket( $sListType );
211  $oBasket->addItemToBasket( $sProductId, abs( $dAmount ), $aSel, ($dAmount == 0) );
212 
213  // recalculate basket count
214  $oBasket->getItemCount( true );
215  }
216  }
217 
223  public function render()
224  {
225  parent::render();
226 
227  $myConfig = $this->getConfig();
228  $oParentView = $this->getParent();
229 
230  // add content for main menu
231  $oContentList = oxNew( 'oxcontentlist' );
232  $oContentList->loadMainMenulist();
233  $oParentView->setMenueList( $oContentList );
234 
235  return;
236  }
237 }