oxcmp_utils.php

Go to the documentation of this file.
00001 <?php
00002 
00009 class oxcmp_utils extends oxView
00010 {
00015     protected $_blIsComponent = true;
00016 
00025     public function getArticle()
00026     {
00027         $myConfig = $this->getConfig();
00028         $myUtils  = oxUtils::getInstance();
00029 
00030         if (!$myConfig->getConfigParam("blAllowRemoteArticleInfo"))
00031             return false;
00032 
00033 
00034         $sOutput  = 'OXID__Problem : no valid oxid !';
00035         $oProduct = null;
00036 
00037         if ( ( $sId = oxConfig::getParameter( 'oxid' ) ) ) {
00038             $oProduct = oxNewArticle( $sId );
00039         } elseif ( $myConfig->getConfigParam( 'bl_perfLoadAktion' ) ) {
00040             $oArtList = oxNew( 'oxarticlelist');
00041             $oArtList->loadAktionArticles( 'OXAFFILIATE' );
00042             $oProduct = $oArtList->current();
00043         }
00044 
00045         if ( $oProduct ) {
00046 
00047             $aExport = array();
00048 
00049             $aClassVars = get_object_vars( $oProduct );
00050             $oStr = getStr();
00051 
00052             // add all database fields
00053             while ( list( $sFieldName, ) = each( $aClassVars ) ) {
00054                 if ( $oStr->strstr( $sFieldName, 'oxarticles' ) ) {
00055                     $sName = str_replace( 'oxarticles__', '', $sFieldName );
00056                     $aExport[$sName] = $oProduct->$sFieldName->value;
00057                 }
00058             }
00059 
00060             $oPrice  = $oProduct->getPrice();
00061 
00062             $aExport['vatPercent'] = $oPrice->getVat();
00063             $aExport['netPrice']   = $myUtils->fRound( $oPrice->getNettoPrice() );
00064             $aExport['brutPrice']  = $myUtils->fRound( $oPrice->getBruttoPrice() );
00065             $aExport['vat']        = $oPrice->getVatValue();
00066             $aExport['fprice']     = $oProduct->getFPrice();
00067             $aExport['ftprice']    = $oProduct->getFTPrice();
00068 
00069             $aExport['oxdetaillink']     = $oProduct->getLink();
00070             $aExport['oxmoredetaillink'] = $oProduct->getMoreDetailLink();
00071             $aExport['tobasketlink']     = $oProduct->getToBasketLink();
00072             $aExport['thumbnaillink']    = $myConfig->getPictureUrl(null, false, $myConfig->isSsl()) ."/". $aExport['oxthumb'];
00073             $sOutput = serialize( $aExport );
00074         }
00075 
00076         // stop shop here
00077         $myUtils->showMessageAndExit( $sOutput );
00078     }
00079 
00091     public function toCompareList( $sProductId = null, $dAmount = null, $aSel = null, $blOverride = false, $blBundle = false )
00092     {
00093         // only if enabled and not search engine..
00094         if ( $this->getViewConfig()->getShowCompareList() && !oxUtils::getInstance()->isSearchEngine() ) {
00095 
00096             
00097 
00098             // #657 special treatment if we want to put on comparelist
00099             $blAddCompare  = oxConfig::getParameter( 'addcompare' );
00100             $blRemoveCompare = oxConfig::getParameter( 'removecompare' );
00101             $sProductId = $sProductId ? $sProductId:oxConfig::getParameter( 'aid' );
00102             if ( ( $blAddCompare || $blRemoveCompare ) && $sProductId ) {
00103 
00104                 // toggle state in session array
00105                 $aItems = oxSession::getVar( 'aFiltcompproducts' );
00106                 if ( $blAddCompare && !isset( $aItems[$sProductId] ) ) {
00107                     $aItems[$sProductId] = true;
00108                 }
00109 
00110                 if ( $blRemoveCompare ) {
00111                     unset( $aItems[$sProductId] );
00112                 }
00113 
00114                 oxSession::setVar( 'aFiltcompproducts', $aItems );
00115                 $oParentView = $this->getParent();
00116 
00117                 // #843C there was problem then field "blIsOnComparisonList" was not set to article object
00118                 if ( ( $oProduct = $oParentView->getViewProduct() ) ) {
00119                     if ( isset( $aItems[$oProduct->getId()] ) ) {
00120                         $oProduct->setOnComparisonList( true );
00121                     } else {
00122                         $oProduct->setOnComparisonList( false );
00123                     }
00124                 }
00125 
00126                 $aViewProds = $oParentView->getViewProductList();
00127                 if ( is_array( $aViewProds ) && count( $aViewProds ) ) {
00128                     foreach ( $aViewProds as $oProduct ) {
00129                         if ( isset( $aItems[$oProduct->getId()] ) ) {
00130                             $oProduct->setOnComparisonList( true );
00131                         } else {
00132                             $oProduct->setOnComparisonList( false );
00133                         }
00134                     }
00135                 }
00136             }
00137         }
00138     }
00139 
00150     public function toNoticeList( $sProductId = null, $dAmount = null, $aSel = null)
00151     {
00152         $this->_toList( 'noticelist', $sProductId, $dAmount, $aSel );
00153     }
00154 
00165     public function toWishList( $sProductId = null, $dAmount = null, $aSel = null )
00166     {
00167         // only if enabled
00168         if ( $this->getViewConfig()->getShowWishlist() ) {
00169             $this->_toList( 'wishlist', $sProductId, $dAmount, $aSel );
00170         }
00171     }
00172 
00183     protected function _toList( $sListType, $sProductId, $dAmount, $aSel )
00184     {
00185         // only if user is logged in
00186         if ( $oUser = $this->getUser() ) {
00187 
00188             $sProductId = ($sProductId) ? $sProductId : oxConfig::getParameter( 'aid' );
00189             $sProductId = ($sProductId) ? $sProductId : oxConfig::getParameter( 'itmid' );
00190             $dAmount = isset( $dAmount ) ? $dAmount : oxConfig::getParameter( 'am' );
00191             $aSel    = $aSel ? $aSel : oxConfig::getParameter( 'sel' );
00192 
00193             // processing amounts
00194             $dAmount = str_replace( ',', '.', $dAmount );
00195             if ( !$this->getConfig()->getConfigParam( 'blAllowUnevenAmounts' ) ) {
00196                 $dAmount = round( ( string ) $dAmount );
00197             }
00198 
00199             $oBasket = $oUser->getBasket( $sListType );
00200             $oBasket->addItemToBasket( $sProductId, abs( $dAmount ), $aSel, ($dAmount == 0) );
00201 
00202             // recalculate basket count
00203             $oBasket->getItemCount( true );
00204         }
00205     }
00206 
00212     public function render()
00213     {
00214         parent::render();
00215 
00216         $myConfig = $this->getConfig();
00217         $oParentView = $this->getParent();
00218 
00219         if ( ( $oUser = $this->getUser() ) ) {
00220             // calculating user friends wishlist item count
00221             $sUserId = oxConfig::getParameter( 'wishid') ? oxConfig::getParameter( 'wishid' ): oxSession::getVar( 'wishid');
00222             if ( $sUserId ) {
00223                 $oWishUser = oxNew( 'oxuser' );
00224                 if ( $oWishUser->load( $sUserId ) ) {
00225                     $oParentView->setWishlistName( $oWishUser->oxuser__oxfname->value );
00226                 }
00227             }
00228         }
00229 
00230         // add content for mainmenu
00231         $oContentList = oxNew( 'oxcontentlist' );
00232         $oContentList->loadMainMenulist();
00233         $oParentView->setMenueList( $oContentList );
00234 
00235         // Performance
00236         if ( ( $myConfig->getConfigParam( 'blDisableNavBars' ) && $myConfig->getActiveView()->getIsOrderStep() ) ) {
00237             return;
00238         }
00239 
00240         // load nr. of items which are currently shown in comparison
00241         $aItems = oxSession::getVar( 'aFiltcompproducts' );
00242         if ( is_array( $aItems ) && count( $aItems ) ) {
00243 
00244             $oArticle = oxNew( 'oxarticle' );
00245 
00246             // counts how many pages
00247             $sViewName = $oArticle->getViewName();
00248             $sInSql   = implode( ",", oxDb::getInstance()->quoteArray( array_keys( $aItems ) ) );
00249             $sSelect  = "select count(oxid) from {$sViewName} where {$sViewName}.oxid in (".$sInSql.") ";
00250             $sSelect .= 'and '.$oArticle->getSqlActiveSnippet();
00251 
00252             $iCnt = (int) oxDb::getDb()->getOne( $sSelect );
00253 
00254             //add amount of compared items to view data
00255             $oParentView->setCompareItemsCnt( $iCnt );
00256 
00257             // return amount of items
00258             return $iCnt;
00259         }
00260     }
00261 }