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         $sOutput  = 'OXID__Problem : no valid oxid !';
00031         $oProduct = null;
00032 
00033         if ( ( $sId = oxConfig::getParameter( 'oxid' ) ) ) {
00034             $oProduct = oxNewArticle( $sId );
00035         } elseif ( $myConfig->getConfigParam( 'bl_perfLoadAktion' ) ) {
00036             $oArtList = oxNew( 'oxarticlelist');
00037             $oArtList->loadAktionArticles( 'OXAFFILIATE' );
00038             $oProduct = $oArtList->current();
00039         }
00040 
00041         if ( $oProduct ) {
00042 
00043             $aExport = array();
00044 
00045             $aClassVars = get_object_vars( $oProduct );
00046             $oStr = getStr();
00047 
00048             // add all database fields
00049             while ( list( $sFieldName, ) = each( $aClassVars ) ) {
00050                 if ( $oStr->strstr( $sFieldName, 'oxarticles' ) ) {
00051                     $sName = str_replace( 'oxarticles__', '', $sFieldName );
00052                     $aExport[$sName] = $oProduct->$sFieldName->value;
00053                 }
00054             }
00055 
00056             $oPrice  = $oProduct->getPrice();
00057             $oTPrice = $oProduct->getTPrice();
00058 
00059             $aExport['vatPercent'] = $oPrice->getVat();
00060             $aExport['netPrice']   = $myUtils->fRound( $oPrice->getNettoPrice() );
00061             $aExport['brutPrice']  = $myUtils->fRound( $oPrice->getBruttoPrice() );
00062             $aExport['vat']        = $oPrice->getVatValue();
00063             $aExport['fprice']     = $oProduct->getFPrice();
00064             $aExport['ftprice']    = oxLang::getInstance()->formatCurrency( $myUtils->fRound( $oTPrice->getBruttoPrice() ) );
00065 
00066             $aExport['oxdetaillink']     = $oProduct->getLink();
00067             $aExport['oxmoredetaillink'] = $oProduct->getMoreDetailLink();
00068             $aExport['tobasketlink']     = $oProduct->getToBasketLink();
00069             $aExport['thumbnaillink']    = $myConfig->getDynImageDir() ."/". $aExport['oxthumb'];
00070             $sOutput = serialize( $aExport );
00071         }
00072 
00073         // stop shop here
00074         $myUtils->showMessageAndExit( $sOutput );
00075     }
00076 
00088     public function toCompareList( $sProductId = null, $dAmount = null, $aSel = null, $blOverride = false, $blBundle = false )
00089     {
00090         // only if enabled and not search engine..
00091         if ( $this->getViewConfig()->getShowCompareList() && !oxUtils::getInstance()->isSearchEngine() ) {
00092 
00093             // #657 special treatment if we want to put on comparelist
00094             $blAddCompare  = oxConfig::getParameter( 'addcompare' );
00095             $blRemoveCompare = oxConfig::getParameter( 'removecompare' );
00096             $sProductId = $sProductId ? $sProductId:oxConfig::getParameter( 'aid' );
00097             if ( ( $blAddCompare || $blRemoveCompare ) && $sProductId ) {
00098 
00099                 // toggle state in session array
00100                 $aItems = oxConfig::getParameter( 'aFiltcompproducts' );
00101                 if ( $blAddCompare && !isset( $aItems[$sProductId] ) ) {
00102                     $aItems[$sProductId] = true;
00103                 }
00104 
00105                 if ( $blRemoveCompare ) {
00106                     unset( $aItems[$sProductId] );
00107                 }
00108 
00109                 oxSession::setVar( 'aFiltcompproducts', $aItems );
00110                 $oParentView = $this->getParent();
00111 
00112                 // #843C there was problem then field "blIsOnComparisonList" was not set to article object
00113                 if ( ( $oProduct = $oParentView->getViewProduct() ) ) {
00114                     if ( isset( $aItems[$oProduct->getId()] ) ) {
00115                         $oProduct->setOnComparisonList( true );
00116                     } else {
00117                         $oProduct->setOnComparisonList( false );
00118                     }
00119                 }
00120 
00121                 $aViewProds = $oParentView->getViewProductList();
00122                 if ( is_array( $aViewProds ) && count( $aViewProds ) ) {
00123                     foreach ( $aViewProds as $oProduct ) {
00124                         if ( isset( $aItems[$oProduct->getId()] ) ) {
00125                             $oProduct->setOnComparisonList( true );
00126                         } else {
00127                             $oProduct->setOnComparisonList( false );
00128                         }
00129                     }
00130                 }
00131             }
00132         }
00133     }
00134 
00145     public function toNoticeList( $sProductId = null, $dAmount = null, $aSel = null)
00146     {
00147         $this->_toList( 'noticelist', $sProductId, $dAmount, $aSel );
00148     }
00149 
00160     public function toWishList( $sProductId = null, $dAmount = null, $aSel = null )
00161     {
00162         // only if enabled
00163         if ( $this->getViewConfig()->getShowWishlist() ) {
00164             $this->_toList( 'wishlist', $sProductId, $dAmount, $aSel );
00165         }
00166     }
00167 
00178     protected function _toList( $sListType, $sProductId, $dAmount, $aSel )
00179     {
00180         // only if user is logged in
00181         if ( $oUser = $this->getUser() ) {
00182 
00183             $sProductId = ($sProductId) ? $sProductId : oxConfig::getParameter( 'aid' );
00184             $sProductId = ($sProductId) ? $sProductId : oxConfig::getParameter( 'itmid' );
00185             $dAmount = isset( $dAmount ) ? $dAmount : oxConfig::getParameter( 'am' );
00186             $aSel    = $aSel ? $aSel : oxConfig::getParameter( 'sel' );
00187 
00188             // processing amounts
00189             $dAmount = str_replace( ',', '.', $dAmount );
00190             if ( !$this->getConfig()->getConfigParam( 'blAllowUnevenAmounts' ) ) {
00191                 $dAmount = round( ( string ) $dAmount );
00192             }
00193 
00194             $oBasket = $oUser->getBasket( $sListType );
00195             $oBasket->addItemToBasket( $sProductId, abs( $dAmount ), $aSel );
00196 
00197             // recalculate basket count
00198             $oBasket->getItemCount( true );
00199         }
00200     }
00201 
00207     public function render()
00208     {
00209         parent::render();
00210 
00211         $myConfig = $this->getConfig();
00212         $oParentView = $this->getParent();
00213 
00214         if ( ( $oUser = $this->getUser() ) ) {
00215 
00216             // calculating user friends wishlist item count
00217             if ( ( $sUserId = oxConfig::getParameter( 'wishid' ) ) ) {
00218                 $oWishUser = oxNew( 'oxuser' );
00219                 if ( $oWishUser->load( $sUserId ) ) {
00220                     $oParentView->setWishlistName( $oWishUser->oxuser__oxfname->value );
00221                     // Passing to view. Left for compatibility reasons for a while. Will be removed in future
00222                     $oParentView->addTplParam( 'ShowWishlistName', $oParentView->getWishlistName() );
00223                 }
00224             }
00225         }
00226 
00227         // add content for mainmenu
00228         $oContentList = oxNew( 'oxcontentlist' );
00229         $oContentList->loadMainMenulist();
00230         $oParentView->setMenueList( $oContentList );
00231 
00232         // Passing to view. Left for compatibility reasons for a while. Will be removed in future
00233         $oParentView->addTplParam( 'aMenueList', $oParentView->getMenueList() );
00234 
00235         // Performance
00236         if ( !$myConfig->getConfigParam( 'bl_perfLoadCompare' ) ||
00237             ( $myConfig->getConfigParam( 'blDisableNavBars' ) && $myConfig->getActiveView()->getIsOrderStep() ) ) {
00238             $oParentView->addTplParam('isfiltering', false );
00239             return;
00240         }
00241 
00242         // load nr. of items which are currently shown in comparison
00243         $aItems = oxConfig::getParameter( 'aFiltcompproducts' );
00244         if ( is_array( $aItems ) && count( $aItems ) ) {
00245 
00246             $oArticle = oxNew( 'oxarticle' );
00247 
00248             // counts how many pages
00249             $sInSql   = implode( ",", oxDb::getInstance()->quoteArray( array_keys( $aItems ) ) );
00250             $sSelect  = "select count(oxid) from oxarticles where oxarticles.oxid in (".$sInSql.") ";
00251             $sSelect .= 'and '.$oArticle->getSqlActiveSnippet();
00252 
00253             $iCnt = (int) oxDb::getDb()->getOne( $sSelect );
00254 
00255             //add amount of compared items to view data
00256             $oParentView->setCompareItemsCnt( $iCnt );
00257             // Passing to view. Left for compatibility reasons for a while. Will be removed in future
00258             $oParentView->addTplParam( 'oxcmp_compare', $oParentView->getCompareItemsCnt() );
00259 
00260             // return amount of items
00261             return $iCnt;
00262         }
00263     }
00264 }

Generated by  doxygen 1.6.2