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         $sId = oxConfig::getParameter( 'oxid' );
00029         $oProduct = null;
00030         if ( $sId ) {
00031             $oProduct = oxNewArticle( $sId );
00032         } else {
00033             if ( $myConfig->getConfigParam( 'bl_perfLoadAktion' ) ) {
00034                 $oArtList = oxNew( 'oxarticlelist');
00035                 $oArtList->loadAktionArticles( 'OXAFFILIATE' );
00036                 $oProduct = $oArtList->current();
00037             }
00038         }
00039 
00040         if ( !$oProduct ) {
00041             die( 'OXID__Problem : no valid oxid !' );
00042         }
00043 
00044         $aExport = array();
00045 
00046         $aClassVars = get_object_vars( $oProduct );
00047         $oStr = getStr();
00048 
00049         // add all database fields
00050         while ( list( $sFieldName, ) = each( $aClassVars ) ) {
00051             if ( $oStr->strstr( $sFieldName, 'oxarticles' ) ) {
00052                 $sName = str_replace( 'oxarticles__', '', $sFieldName );
00053                 $aExport[$sName] = $oProduct->$sFieldName->value;
00054             }
00055         }
00056 
00057         $aExport['vatPercent'] = $oProduct->vatPercent;
00058         $aExport['netPrice']   = $oProduct->netPrice;
00059         $aExport['brutPrice']  = $oProduct->brutPrice;
00060         $aExport['vat']        = $oProduct->vat;
00061         $aExport['fprice']     = $oProduct->fprice;
00062         $aExport['ftprice']    = $oProduct->ftprice;
00063 
00064         $aExport['oxdetaillink']     = $oProduct->oxdetaillink;
00065         $aExport['oxmoredetaillink'] = $oProduct->getMoreDetailLink();
00066         $aExport['tobasketlink']     = $oProduct->tobasketlink;
00067         $aExport['thumbnaillink']    = $myConfig->getDynImageDir() ."/". $aExport['oxthumb'];
00068 
00069         // stop shop here
00070         die( serialize( $aExport ) );
00071     }
00072 
00073 
00085     public function toCompareList( $sProductId = null, $dAmount = null, $aSel = null, $blOverride = false, $blBundle = false )
00086     {
00087         //disables adding of articles if current client is Search Engine
00088         if ( oxUtils::getInstance()->isSearchEngine() ) {
00089             return;
00090         }
00091 
00092         // #657 special treatment if we want to put on comparelist
00093         $myConfig = $this->getConfig();
00094 
00095         $blAddCompare  = oxConfig::getParameter( 'addcompare' );
00096         $blRemoveCompare = oxConfig::getParameter( 'removecompare' );
00097         $sProductId = $sProductId?$sProductId:oxConfig::getParameter( 'aid' );
00098         if ( ($blAddCompare || $blRemoveCompare) && $sProductId ) {
00099 
00100             // toggle state in session array
00101             $aItems = oxConfig::getParameter( 'aFiltcompproducts' );
00102             if ($blAddCompare && !isset( $aItems[$sProductId] ) ) {
00103                 $aItems[$sProductId] = true;
00104             }
00105 
00106             if ($blRemoveCompare) {
00107                 unset( $aItems[$sProductId] );
00108             }
00109 
00110             oxSession::setVar( 'aFiltcompproducts', $aItems );
00111 
00112             // #843C there was problem then field "blIsOnComparisonList" was not set to article object
00113             if ( ( $oProduct = $this->_oParent->getViewProduct() ) ) {
00114                 if ( isset( $aItems[$oProduct->getId()] ) ) {
00115                     $oProduct->setOnComparisonList( true );
00116                 } else {
00117                     $oProduct->setOnComparisonList( false );
00118                 }
00119             }
00120 
00121             $aViewProds = $this->_oParent->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             return;
00133         }
00134     }
00135 
00146     public function toNoticeList( $sProductId = null, $dAmount = null, $aSel = null)
00147     {
00148         $oUser = $this->getUser();
00149         if ( !$oUser ) {
00150             return; // we shouldnt call this if not logged in
00151         }
00152 
00153         $sProductId = $sProductId ? $sProductId : oxConfig::getParameter( 'itmid' );
00154         $sProductId = $sProductId ? $sProductId : oxConfig::getParameter( 'aid' );
00155         $dAmount    = isset( $dAmount ) ? $dAmount : oxConfig::getParameter( 'am' );
00156         $aSel       = $aSel ? $aSel : oxConfig::getParameter( 'sel' );
00157 
00158         // processing amounts
00159         $dAmount = str_replace( ',', '.', $dAmount );
00160         if ( !$this->getConfig()->getConfigParam( 'blAllowUnevenAmounts' ) ) {
00161             $dAmount = round( ( string ) $dAmount );
00162         }
00163 
00164         $oBasket = $oUser->getBasket( 'noticelist' );
00165         $oBasket->addItemToBasket( $sProductId, abs( $dAmount ), $aSel );
00166 
00167         // recalculate basket count
00168         $oBasket->getItemCount(true);
00169     }
00170 
00181     public function toWishList( $sProductId = null, $dAmount = null, $aSel = null )
00182     {
00183         $oUser = $this->getUser();
00184         if ( !$oUser ) {
00185             return; // we shouldnt call this if not logged in
00186         }
00187 
00188         $sProductId = $sProductId ? $sProductId : oxConfig::getParameter( 'itmid' );
00189         $sProductId = $sProductId ? $sProductId : oxConfig::getParameter( 'aid' );
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( 'wishlist' );
00200         $oBasket->addItemToBasket( $sProductId, abs( $dAmount ), $aSel );
00201 
00202         // recalculate basket count
00203         $oBasket->getItemCount(true);
00204     }
00205 
00211     public function render()
00212     {
00213         $myConfig  = $this->getConfig();
00214         parent::render();
00215 
00216         if ( ( $oUser = $this->getUser() ) ) {
00217 
00218             // calculating user friends wishlist item count
00219             if ( ( $sUserId = oxConfig::getParameter( 'wishid' ) ) ) {
00220                 $oWishUser = oxNew( 'oxuser' );
00221                 if ( $oWishUser->load( $sUserId ) ) {
00222                     $this->_oParent->setWishlistName( $oWishUser->oxuser__oxfname->value );
00223                     // Passing to view. Left for compatibility reasons for a while. Will be removed in future
00224                     $this->_oParent->addTplParam( 'ShowWishlistName', $this->_oParent->getWishlistName() );
00225                 }
00226             }
00227         }
00228 
00229         // add content for mainmenu
00230         $oContentList = oxNew( 'oxcontentlist' );
00231         $oContentList->loadMainMenulist();
00232         $this->_oParent->setMenueList( $oContentList );
00233         // Passing to view. Left for compatibility reasons for a while. Will be removed in future
00234         $this->_oParent->addTplParam( 'aMenueList', $this->_oParent->getMenueList() );
00235 
00236         // Performance
00237         if ( !$myConfig->getConfigParam( 'bl_perfLoadCompare' ) ||
00238             ( $myConfig->getConfigParam( 'blDisableNavBars' ) && $myConfig->getActiveView()->getIsOrderStep() ) ) {
00239             $this->_oParent->addTplParam('isfiltering', false );
00240             return;
00241         }
00242 
00243         // load nr. of items which are currently shown in comparison
00244         $aItems = oxConfig::getParameter( 'aFiltcompproducts' );
00245         if ( is_array( $aItems ) && count( $aItems ) ) {
00246 
00247             $oArticle = oxNew( 'oxarticle' );
00248             // counts how many pages
00249             $sAddSql  = implode( "','", array_keys( $aItems ) );
00250             $sSelect  = "select count(oxid) from oxarticles where oxarticles.oxid in ( '".$sAddSql."' ) ";
00251             $sSelect .= 'and '.$oArticle->getSqlActiveSnippet();
00252 
00253             $iCnt = (int) oxDb::getDb()->getOne( $sSelect );
00254 
00255             //add amount of compared items to view data
00256             $this->_oParent->setCompareItemsCnt( $iCnt );
00257             // Passing to view. Left for compatibility reasons for a while. Will be removed in future
00258             $this->_oParent->addTplParam( 'oxcmp_compare', $this->_oParent->getCompareItemsCnt() );
00259 
00260             // return amount of items
00261             return $iCnt;
00262         }
00263     }
00264 }

Generated on Tue Aug 18 09:21:08 2009 for OXID eShop CE by  doxygen 1.5.5