oxwarticledetails.php

Go to the documentation of this file.
00001 <?php
00002 
00008 class oxwArticleDetails extends oxWidget
00009 {
00015     protected $_aVariantList = null;
00021     protected $_aComponentNames = array( 'oxcmp_cur' => 1, 'oxcmp_shop' => 1, 'oxcmp_basket' => 1, 'oxcmp_user' => 1 );
00022 
00027     protected $_sThisTemplate = 'widget/product/details.tpl';
00028 
00034     protected $_oParentProd = null;
00035 
00041     protected $_blCanRate = null;
00042 
00047     protected $_blCanEditTags = null;
00048 
00053     protected $_oCaptcha = null;
00054 
00059     protected $_aMediaFiles = null;
00060 
00065     protected $_aLastProducts = null;
00066 
00071     protected $_oVendor = null;
00072 
00077     protected $_oManufacturer = null;
00078 
00083     protected $_oCategory = null;
00084 
00089     protected $_aAttributes = null;
00090 
00095     protected $_aPicGallery = null;
00096 
00101     protected $_aReviews = null;
00102 
00107     protected $_oCrossSelling = null;
00108 
00113     protected $_oSimilarProducts = null;
00114 
00119     protected $_oAccessoires = null;
00120 
00125     protected $_aAlsoBoughtArts = null;
00126 
00131     protected $_sSearchTitle = null;
00132 
00138     protected $_blIsInitialized = false;
00139 
00145     protected $_iLinkType = null;
00146 
00152     protected $_blMdView = null;
00153 
00158     protected $_dRatingValue = null;
00159 
00164     protected $_iRatingCnt = null;
00165 
00170     protected $_sBidPrice = null;
00171 
00176     protected $_blShowSorting = true;
00177 
00183     protected $_aSimilarRecommListIds = null;
00184 
00185 
00191     public function getActZoomPic()
00192     {
00193         return 1;
00194     }
00195 
00203     protected function _getParentProduct( $sParentId )
00204     {
00205         if ( $sParentId && $this->_oParentProd === null ) {
00206             $this->_oParentProd = false;
00207             $oProduct = oxNew( 'oxArticle' );
00208             if ( ( $oProduct->load( $sParentId ) ) ) {
00209                 $this->_processProduct( $oProduct );
00210                 $this->_oParentProd = $oProduct;
00211             }
00212         }
00213         return $this->_oParentProd;
00214     }
00215 
00221     protected function _getAddUrlParams()
00222     {
00223         if ( $this->getListType() == "search" ) {
00224             return $this->getDynUrlParams();
00225         }
00226     }
00227 
00235     protected function _processProduct( $oProduct )
00236     {
00237         $oProduct->setLinkType( $this->getLinkType() );
00238         if ( $sAddParams = $this->_getAddUrlParams() ) {
00239             $oProduct->appendLink( $sAddParams );
00240         }
00241     }
00242 
00248     public function ratingIsActive()
00249     {
00250         return $this->getConfig()->getConfigParam( 'bl_perfLoadReviews' );
00251     }
00252 
00258     public function canRate()
00259     {
00260         if ( $this->_blCanRate === null ) {
00261 
00262             $this->_blCanRate = false;
00263 
00264             if ( $this->ratingIsActive() && $oUser = $this->getUser() ) {
00265 
00266                 $oRating = oxNew( 'oxrating' );
00267                 $this->_blCanRate = $oRating->allowRating( $oUser->getId(), 'oxarticle', $this->getProduct()->getId() );
00268             }
00269         }
00270 
00271         return $this->_blCanRate;
00272     }
00273 
00279     public function canChangeTags()
00280     {
00281         if ( $oUser = $this->getUser() ) {
00282 
00283             return true;
00284         }
00285         return false;
00286     }
00287 
00293     public function getAttributes()
00294     {
00295         if ( $this->_aAttributes === null ) {
00296             // all attributes this article has
00297             $aArtAttributes = $this->getProduct()->getAttributes();
00298 
00299             //making a new array for backward compatibility
00300             $this->_aAttributes = false;
00301 
00302             if ( count( $aArtAttributes ) ) {
00303                 foreach ( $aArtAttributes as $sKey => $oAttribute ) {
00304                     $this->_aAttributes[$sKey] = new stdClass();
00305                     $this->_aAttributes[$sKey]->title = $oAttribute->oxattribute__oxtitle->value;
00306                     $this->_aAttributes[$sKey]->value = $oAttribute->oxattribute__oxvalue->value;
00307                 }
00308             }
00309         }
00310         return $this->_aAttributes;
00311     }
00312 
00318     public function getTagCloudManager()
00319     {
00320         $oManager = oxNew( "oxTagCloud" );
00321         $oManager->setExtendedMode( true );
00322         $oManager->setProductId( $this->getProduct()->getId() );
00323         return $oManager;
00324     }
00325 
00332     public function isEditableTags()
00333     {
00334         if ( $this->_blCanEditTags === null ) {
00335             $this->_blCanEditTags = false;
00336             if ( $this->getProduct() && $this->getUser()) {
00337                 $this->_blCanEditTags = true;
00338             }
00339         }
00340         return $this->_blCanEditTags;
00341     }
00342 
00348     public function getLinkType()
00349     {
00350         if ( $this->_iLinkType === null ) {
00351             $sListType = oxConfig::getParameter( 'listtype' );
00352             if ( 'vendor' == $sListType ) {
00353                 $this->_iLinkType = OXARTICLE_LINKTYPE_VENDOR;
00354             } elseif ( 'manufacturer' == $sListType ) {
00355                 $this->_iLinkType = OXARTICLE_LINKTYPE_MANUFACTURER;
00356             } elseif ( 'tag' == $sListType ) {
00357                 $this->_iLinkType = OXARTICLE_LINKTYPE_TAG;
00358             } elseif ( 'recommlist' == $sListType ) {
00359                 $this->_iLinkType = OXARTICLE_LINKTYPE_RECOMM;
00360             } else {
00361                 $this->_iLinkType = OXARTICLE_LINKTYPE_CATEGORY;
00362 
00363                 // price category has own type..
00364                 if ( ( $oCat = $this->getActiveCategory() ) && $oCat->isPriceCategory() ) {
00365                     $this->_iLinkType = OXARTICLE_LINKTYPE_PRICECATEGORY;
00366                 }
00367             }
00368         }
00369 
00370         return $this->_iLinkType;
00371     }
00372 
00379     public function getVariantListExceptCurrent()
00380     {
00381         $oList = $this->getVariantList();
00382         if (is_object($oList)) {
00383             $oList = clone $oList;
00384         }
00385 
00386         $sOxId = $this->getProduct()->getId();
00387         if (isset($oList[$sOxId])) {
00388             unset($oList[$sOxId]);
00389         }
00390         return $oList;
00391     }
00392 
00399     public function loadVariantInformation()
00400     {
00401         if ( $this->_aVariantList === null ) {
00402             $oProduct = $this->getProduct();
00403 
00404             //if we are child and do not have any variants then let's load all parent variants as ours
00405             if ( $oParent = $oProduct->getParentArticle() ) {
00406                 $myConfig = $this->getConfig();
00407 
00408                 $oParent->setNoVariantLoading(false);
00409                 $this->_aVariantList = $oParent->getFullVariants( false );
00410 
00411                 //lets additionally add parent article if it is sellable
00412                 if ( count( $this->_aVariantList ) && $myConfig->getConfigParam( 'blVariantParentBuyable' ) ) {
00413                     //#1104S if parent is buyable load select lists too
00414                     $oParent->enablePriceLoad();
00415                     $oParent->aSelectlist = $oParent->getSelectLists();
00416                     $this->_aVariantList = array_merge( array( $oParent ), $this->_aVariantList->getArray() );
00417                 }
00418             } else {
00419                 //loading full list of variants
00420                 $this->_aVariantList = $oProduct->getFullVariants( false );
00421             }
00422 
00423             // setting link type for variants ..
00424             foreach ( $this->_aVariantList as $oVariant ) {
00425                 $this->_processProduct( $oVariant );
00426             }
00427 
00428         }
00429 
00430         return $this->_aVariantList;
00431     }
00432 
00433 
00439     public function getVariantList()
00440     {
00441         return $this->loadVariantInformation();
00442     }
00443 
00449     public function getCaptcha()
00450     {
00451         if ( $this->_oCaptcha === null ) {
00452             $this->_oCaptcha = oxNew('oxCaptcha');
00453         }
00454         return $this->_oCaptcha;
00455     }
00456 
00462     public function getMediaFiles()
00463     {
00464         if ( $this->_aMediaFiles === null ) {
00465             $aMediaFiles = $this->getProduct()->getMediaUrls();
00466             $this->_aMediaFiles = count($aMediaFiles) ? $aMediaFiles : false;
00467         }
00468         return $this->_aMediaFiles;
00469     }
00470 
00478     public function getLastProducts( $iCnt = 4 )
00479     {
00480         if ( $this->_aLastProducts === null ) {
00481             //last seen products for #768CA
00482             $oProduct = $this->getProduct();
00483             $sArtId = $oProduct->oxarticles__oxparentid->value?$oProduct->oxarticles__oxparentid->value:$oProduct->getId();
00484 
00485             $oHistoryArtList = oxNew( 'oxArticleList' );
00486             $oHistoryArtList->loadHistoryArticles( $sArtId, $iCnt );
00487             $this->_aLastProducts = $oHistoryArtList;
00488         }
00489         return $this->_aLastProducts;
00490     }
00491 
00497     public function getManufacturer()
00498     {
00499         if ( $this->_oManufacturer === null ) {
00500             $this->_oManufacturer = $this->getProduct()->getManufacturer( false );
00501         }
00502         return $this->_oManufacturer;
00503     }
00504 
00510     public function getVendor()
00511     {
00512         if ( $this->_oVendor === null ) {
00513             $this->_oVendor = $this->getProduct()->getVendor( false );
00514         }
00515         return $this->_oVendor;
00516     }
00517 
00523     public function getCategory()
00524     {
00525         if ( $this->_oCategory === null ) {
00526             $this->_oCategory = $this->getProduct()->getCategory();
00527         }
00528         return $this->_oCategory;
00529     }
00530 
00536     public function getPictureGallery()
00537     {
00538         if ( $this->_aPicGallery === null ) {
00539             //get picture gallery
00540             $this->_aPicGallery = $this->getPicturesProduct()->getPictureGallery();
00541         }
00542         return $this->_aPicGallery;
00543     }
00544 
00550     public function getActPicture()
00551     {
00552         $aPicGallery = $this->getPictureGallery();
00553         return $aPicGallery['ActPic'];
00554     }
00555 
00561     public function morePics()
00562     {
00563         $aPicGallery = $this->getPictureGallery();
00564         return $aPicGallery['MorePics'];
00565     }
00566 
00572     public function getIcons()
00573     {
00574         $aPicGallery = $this->getPictureGallery();
00575         return $aPicGallery['Icons'];
00576     }
00577 
00583     public function showZoomPics()
00584     {
00585         $aPicGallery = $this->getPictureGallery();
00586         return $aPicGallery['ZoomPic'];
00587     }
00588 
00594     public function getZoomPics()
00595     {
00596         $aPicGallery = $this->getPictureGallery();
00597         return $aPicGallery['ZoomPics'];
00598     }
00599 
00605     public function getReviews()
00606     {
00607         if ( $this->_aReviews === null ) {
00608             $this->_aReviews = false;
00609             if ( $this->getConfig()->getConfigParam( 'bl_perfLoadReviews' ) ) {
00610                 $this->_aReviews = $this->getProduct()->getReviews();
00611             }
00612         }
00613         return $this->_aReviews;
00614     }
00615 
00621     public function getCrossSelling()
00622     {
00623         if ( $this->_oCrossSelling === null ) {
00624             $this->_oCrossSelling = false;
00625             if ( $oProduct = $this->getProduct() ) {
00626                 $this->_oCrossSelling = $oProduct->getCrossSelling();
00627             }
00628         }
00629         return $this->_oCrossSelling;
00630     }
00631 
00637     public function getSimilarProducts()
00638     {
00639         if ( $this->_oSimilarProducts === null ) {
00640             $this->_oSimilarProducts = false;
00641             if ( $oProduct = $this->getProduct() ) {
00642                 $this->_oSimilarProducts = $oProduct->getSimilarProducts();
00643             }
00644         }
00645         return $this->_oSimilarProducts;
00646     }
00647 
00653     public function getSimilarRecommListIds()
00654     {
00655         if ( $this->_aSimilarRecommListIds === null ) {
00656             $this->_aSimilarRecommListIds = false;
00657 
00658             if ( $oProduct = $this->getProduct() ) {
00659                 $this->_aSimilarRecommListIds = array( $oProduct->getId() );
00660             }
00661         }
00662         return $this->_aSimilarRecommListIds;
00663     }
00664 
00670     public function getAccessoires()
00671     {
00672         if ( $this->_oAccessoires === null ) {
00673             $this->_oAccessoires = false;
00674             if ( $oProduct = $this->getProduct() ) {
00675                 $this->_oAccessoires = $oProduct->getAccessoires();
00676             }
00677         }
00678         return $this->_oAccessoires;
00679     }
00680 
00686     public function getAlsoBoughtTheseProducts()
00687     {
00688         if ( $this->_aAlsoBoughtArts === null ) {
00689             $this->_aAlsoBoughtArts = false;
00690             if ( $oProduct = $this->getProduct() ) {
00691                 $this->_aAlsoBoughtArts = $oProduct->getCustomerAlsoBoughtThisProducts();
00692             }
00693         }
00694         return $this->_aAlsoBoughtArts;
00695     }
00696 
00702     public function isPriceAlarm()
00703     {
00704         // #419 disabling price alarm if article has fixed price
00705         $oProduct = $this->getProduct();
00706         if ( isset( $oProduct->oxarticles__oxblfixedprice->value ) && $oProduct->oxarticles__oxblfixedprice->value ) {
00707             return 0;
00708         }
00709         return 1;
00710     }
00711 
00720     protected function _getSubject( $iLang )
00721     {
00722         return $this->getProduct();
00723     }
00724 
00730     public function getSearchTitle()
00731     {
00732         return $this->_sSearchTitle;
00733     }
00734 
00742     public function setSearchTitle( $sTitle )
00743     {
00744         $this->_sSearchTitle = $sTitle;
00745     }
00746 
00754     public function setCatTreePath( $sActCatPath )
00755     {
00756         $this->_sCatTreePath = $sActCatPath;
00757     }
00758 
00764     public function isPersParam()
00765     {
00766         $oProduct = $this->getProduct();
00767         return $oProduct->oxarticles__oxisconfigurable->value;
00768     }
00769 
00775     public function getRatingValue()
00776     {
00777 
00778         if ( $this->_dRatingValue === null ) {
00779             $this->_dRatingValue = (double) 0;
00780             if ( $this->isReviewActive() && ( $oDetailsProduct = $this->getProduct() ) ) {
00781                 $this->_dRatingValue = round( $oDetailsProduct->getArticleRatingAverage( $this->getConfig()->getConfigParam( 'blShowVariantReviews' ) ), 1);
00782             }
00783         }
00784 
00785         return (double) $this->_dRatingValue;
00786     }
00787 
00793     public function isReviewActive()
00794     {
00795         return $this->getConfig()->getConfigParam( 'bl_perfLoadReviews' );
00796     }
00797 
00803     public function getRatingCount()
00804     {
00805         if ( $this->_iRatingCnt === null ) {
00806             $this->_iRatingCnt = false;
00807             if ( $this->isReviewActive() && ( $oDetailsProduct = $this->getProduct() ) ) {
00808                 $this->_iRatingCnt = $oDetailsProduct->getArticleRatingCount( $this->getConfig()->getConfigParam( 'blShowVariantReviews' ) );
00809             }
00810         }
00811         return $this->_iRatingCnt;
00812     }
00813 
00819     public function getPriceAlarmStatus()
00820     {
00821         return $this->getViewParameter('iPriceAlarmStatus');
00822     }
00823 
00829     public function getBidPrice()
00830     {
00831         if ( $this->_sBidPrice === null ) {
00832             $this->_sBidPrice = false;
00833 
00834             $aParams = oxConfig::getParameter( 'pa' );
00835             $oCur = $this->getConfig()->getActShopCurrencyObject();
00836             $iPrice = oxRegistry::getUtils()->currency2Float( $aParams['price'] );
00837             $this->_sBidPrice = oxRegistry::getLang()->formatCurrency( $iPrice, $oCur );
00838         }
00839         return $this->_sBidPrice;
00840     }
00841 
00847     public function getVariantSelections()
00848     {
00849         // finding parent
00850         $oProduct = $this->getProduct();
00851         if ( ( $oParent = $this->_getParentProduct( $oProduct->oxarticles__oxparentid->value ) ) ) {
00852             return $oParent->getVariantSelections( oxConfig::getParameter( "varselid" ), $oProduct->getId() );
00853         }
00854 
00855         return $oProduct->getVariantSelections( oxConfig::getParameter( "varselid" ) );
00856     }
00857 
00863     public function getPicturesProduct()
00864     {
00865         $aVariantSelections = $this->getVariantSelections();
00866         if ($aVariantSelections && $aVariantSelections['oActiveVariant'] && !$aVariantSelections['blPerfectFit']) {
00867             return $aVariantSelections['oActiveVariant'];
00868         }
00869         return $this->getProduct();
00870     }
00871 
00877     public function getProduct()
00878     {
00879         $myConfig = $this->getConfig();
00880         $myUtils = oxRegistry::getUtils();
00881 
00882         if ( $this->_oProduct === null ) {
00883 
00884             if ( $this->getViewParameter( '_object' ) ) {
00885                 $this->_oProduct = $this->getViewParameter( '_object' );
00886             } else {
00887                 //this option is only for lists and we must reset value
00888                 //as blLoadVariants = false affect "ab price" functionality
00889                 $myConfig->setConfigParam( 'blLoadVariants', true );
00890 
00891                 $sOxid = oxConfig::getParameter( 'anid' );
00892 
00893                 // object is not yet loaded
00894                 $this->_oProduct = oxNew( 'oxarticle' );
00895 
00896                 if ( !$this->_oProduct->load( $sOxid ) ) {
00897                     $myUtils->redirect( $myConfig->getShopHomeURL() );
00898                     $myUtils->showMessageAndExit( '' );
00899                 }
00900 
00901                 $aVariantSelections = $this->_oProduct->getVariantSelections( oxConfig::getParameter( "varselid" ) );
00902                 if ($aVariantSelections && $aVariantSelections['oActiveVariant'] && $aVariantSelections['blPerfectFit']) {
00903                     $this->_oProduct = $aVariantSelections['oActiveVariant'];
00904                 }
00905             }
00906         }
00907         if ( !$this->_blIsInitialized ) {
00908             $this->_additionalChecksForArticle( $myUtils, $myConfig );
00909         }
00910 
00911         return $this->_oProduct;
00912     }
00913 
00919     protected function _setSortingParameters()
00920     {
00921         $sSortingParameters = $this->getViewParameter( 'sorting' );
00922         if ( $sSortingParameters ) {
00923             list( $sSortBy, $sSortDir ) = explode( '|', $sSortingParameters );
00924             $this->setItemSorting( 'alist', $sSortBy, $sSortDir );
00925         }
00926     }
00927 
00934     public function render()
00935     {
00936         $oProduct = $this->getProduct();
00937 
00938         parent::render();
00939 
00940         $oCategory = oxNew( 'oxCategory' );
00941 
00942         // if category parameter is not found, use category from product
00943         $sCatId = $this->getViewParameter( "cnid" );
00944 
00945         if ( !$sCatId && $oProduct->getCategory() ) {
00946             $oCategory = $oProduct->getCategory();
00947         } else {
00948             $oCategory->load( $sCatId );
00949         }
00950         $this->_setSortingParameters();
00951 
00952         $this->setActiveCategory( $oCategory );
00953 
00957         $oLocator = oxNew( 'oxLocator', $this->getListType() );
00958         $oLocator->setLocatorData( $oProduct, $this );
00959         return $this->_sThisTemplate;
00960 
00961     }
00962 
00968     public function isMdVariantView()
00969     {
00970         if ( $this->_blMdView === null ) {
00971             $this->_blMdView = false;
00972             if ( $this->getConfig()->getConfigParam( 'blUseMultidimensionVariants' ) ) {
00973                 $iMaxMdDepth = $this->getProduct()->getMdVariants()->getMaxDepth();
00974                 $this->_blMdView = ($iMaxMdDepth > 1);
00975             }
00976         }
00977 
00978         return $this->_blMdView;
00979     }
00980 
00986     public function getTagSeparator()
00987     {
00988         $sSeparator = $this->getConfig()->getConfigParam("sTagSeparator");
00989         return $sSeparator;
00990     }
00991 
01000     protected function _additionalChecksForArticle( $myUtils, $myConfig )
01001     {
01002         $blContinue = true;
01003         if ( !$this->_oProduct->isVisible() ) {
01004             $blContinue = false;
01005         } elseif ( $this->_oProduct->oxarticles__oxparentid->value ) {
01006             $oParent = $this->_getParentProduct( $this->_oProduct->oxarticles__oxparentid->value );
01007             if ( !$oParent || !$oParent->isVisible() ) {
01008                 $blContinue = false;
01009             }
01010         }
01011 
01012         if ( !$blContinue ) {
01013             $myUtils->redirect( $myConfig->getShopHomeURL() );
01014             $myUtils->showMessageAndExit( '' );
01015         }
01016 
01017         $this->_processProduct( $this->_oProduct );
01018         $this->_blIsInitialized = true;
01019     }
01020 
01026     public function getDefaultSorting()
01027     {
01028         $aSorting = parent::getDefaultSorting();
01029         $oCategory = $this->getActiveCategory();
01030 
01031         if ( $this->getListType() != 'search' &&  $oCategory && $oCategory instanceof oxCategory ) {
01032             if ( $sSortBy = $oCategory->getDefaultSorting() ) {
01033                 $sSortDir = ( $oCategory->getDefaultSortingMode() ) ? "desc" : "asc";
01034                 $aSorting = array ( 'sortby' => $sSortBy, 'sortdir' => $sSortDir );
01035             }
01036         }
01037 
01038         return $aSorting;
01039     }
01040 
01041 }