oxwarticledetails.php

Go to the documentation of this file.
00001 <?php
00002 
00003 class oxwArticleDetails extends oxWidget
00004 {
00010     protected $_aVariantList = null;
00016     protected $_aComponentNames = array( 'oxcmp_cur' => 1, 'oxcmp_shop' => 1, 'oxcmp_basket' => 1, 'oxcmp_user' => 1 );
00017 
00022     protected $_sThisTemplate = 'widget/product/details.tpl';
00023 
00029     protected $_oParentProd = null;
00030 
00036     protected $_blCanRate = null;
00037 
00042     protected $_blCanEditTags = null;
00043 
00048     protected $_oCaptcha = null;
00049 
00054     protected $_aMediaFiles = null;
00055 
00060     protected $_aLastProducts = null;
00061 
00066     protected $_oVendor = null;
00067 
00072     protected $_oManufacturer = null;
00073 
00078     protected $_oCategory = null;
00079 
00084     protected $_aAttributes = null;
00085 
00090     protected $_aPicGallery = null;
00091 
00096     protected $_aReviews = null;
00097 
00102     protected $_oCrossSelling = null;
00103 
00108     protected $_oSimilarProducts = null;
00109 
00114     protected $_oAccessoires = null;
00115 
00120     protected $_aAlsoBoughtArts = null;
00121 
00126     protected $_sSearchTitle = null;
00127 
00133     protected $_blIsInitialized = false;
00134 
00140     protected $_iLinkType = null;
00141 
00147     protected $_blMdView = null;
00148 
00153     protected $_dRatingValue = null;
00154 
00159     protected $_iRatingCnt = null;
00160 
00165     protected $_sBidPrice = null;
00166 
00171     protected $_blShowSorting = true;
00172 
00178     protected $_aSimilarRecommListIds = null;
00179 
00180 
00186     public function getActZoomPic()
00187     {
00188         return 1;
00189     }
00190 
00198     protected function _getParentProduct( $sParentId )
00199     {
00200         if ( $sParentId && $this->_oParentProd === null ) {
00201             $this->_oParentProd = false;
00202             $oProduct = oxNew( 'oxArticle' );
00203             if ( ( $oProduct->load( $sParentId ) ) ) {
00204                 $this->_processProduct( $oProduct );
00205                 $this->_oParentProd = $oProduct;
00206             }
00207         }
00208         return $this->_oParentProd;
00209     }
00210 
00216     protected function _getAddUrlParams()
00217     {
00218         if ( $this->getListType() == "search" ) {
00219             return $this->getDynUrlParams();
00220         }
00221     }
00222 
00230     protected function _processProduct( $oProduct )
00231     {
00232         $oProduct->setLinkType( $this->getLinkType() );
00233         if ( $sAddParams = $this->_getAddUrlParams() ) {
00234             $oProduct->appendLink( $sAddParams );
00235         }
00236     }
00237 
00243     public function ratingIsActive()
00244     {
00245         return $this->getConfig()->getConfigParam( 'bl_perfLoadReviews' );
00246     }
00247 
00253     public function canRate()
00254     {
00255         if ( $this->_blCanRate === null ) {
00256 
00257             $this->_blCanRate = false;
00258 
00259             if ( $this->ratingIsActive() && $oUser = $this->getUser() ) {
00260 
00261                 $oRating = oxNew( 'oxrating' );
00262                 $this->_blCanRate = $oRating->allowRating( $oUser->getId(), 'oxarticle', $this->getProduct()->getId() );
00263             }
00264         }
00265 
00266         return $this->_blCanRate;
00267     }
00268 
00274     public function canChangeTags()
00275     {
00276         if ( $oUser = $this->getUser() ) {
00277 
00278             return true;
00279         }
00280         return false;
00281     }
00282 
00288     public function getAttributes()
00289     {
00290         if ( $this->_aAttributes === null ) {
00291             // all attributes this article has
00292             $aArtAttributes = $this->getProduct()->getAttributes();
00293 
00294             //making a new array for backward compatibility
00295             $this->_aAttributes = false;
00296 
00297             if ( count( $aArtAttributes ) ) {
00298                 foreach ( $aArtAttributes as $sKey => $oAttribute ) {
00299                     $this->_aAttributes[$sKey] = new stdClass();
00300                     $this->_aAttributes[$sKey]->title = $oAttribute->oxattribute__oxtitle->value;
00301                     $this->_aAttributes[$sKey]->value = $oAttribute->oxattribute__oxvalue->value;
00302                 }
00303             }
00304         }
00305         return $this->_aAttributes;
00306     }
00307 
00313     public function getTagCloudManager()
00314     {
00315         $oManager = oxNew( "oxTagCloud" );
00316         $oManager->setExtendedMode( true );
00317         $oManager->setProductId( $this->getProduct()->getId() );
00318         return $oManager;
00319     }
00320 
00327     public function isEditableTags()
00328     {
00329         if ( $this->_blCanEditTags === null ) {
00330             $this->_blCanEditTags = false;
00331             if ( $this->getProduct() && $this->getUser()) {
00332                 $this->_blCanEditTags = true;
00333             }
00334         }
00335         return $this->_blCanEditTags;
00336     }
00337 
00343     public function getLinkType()
00344     {
00345         if ( $this->_iLinkType === null ) {
00346             $sListType = oxConfig::getParameter( 'listtype' );
00347             if ( 'vendor' == $sListType ) {
00348                 $this->_iLinkType = OXARTICLE_LINKTYPE_VENDOR;
00349             } elseif ( 'manufacturer' == $sListType ) {
00350                 $this->_iLinkType = OXARTICLE_LINKTYPE_MANUFACTURER;
00351             } elseif ( 'tag' == $sListType ) {
00352                 $this->_iLinkType = OXARTICLE_LINKTYPE_TAG;
00353             } elseif ( 'recommlist' == $sListType ) {
00354                 $this->_iLinkType = OXARTICLE_LINKTYPE_RECOMM;
00355             } else {
00356                 $this->_iLinkType = OXARTICLE_LINKTYPE_CATEGORY;
00357 
00358                 // price category has own type..
00359                 if ( ( $oCat = $this->getActiveCategory() ) && $oCat->isPriceCategory() ) {
00360                     $this->_iLinkType = OXARTICLE_LINKTYPE_PRICECATEGORY;
00361                 }
00362             }
00363         }
00364 
00365         return $this->_iLinkType;
00366     }
00367 
00374     public function getVariantListExceptCurrent()
00375     {
00376         $oList = $this->getVariantList();
00377         if (is_object($oList)) {
00378             $oList = clone $oList;
00379         }
00380 
00381         $sOxId = $this->getProduct()->getId();
00382         if (isset($oList[$sOxId])) {
00383             unset($oList[$sOxId]);
00384         }
00385         return $oList;
00386     }
00387 
00394     public function loadVariantInformation()
00395     {
00396         if ( $this->_aVariantList === null ) {
00397             $oProduct = $this->getProduct();
00398 
00399             //if we are child and do not have any variants then let's load all parent variants as ours
00400             if ( $oParent = $oProduct->getParentArticle() ) {
00401                 $myConfig = $this->getConfig();
00402 
00403                 $oParent->setNoVariantLoading(false);
00404                 $this->_aVariantList = $oParent->getFullVariants( false );
00405 
00406                 //lets additionally add parent article if it is sellable
00407                 if ( count( $this->_aVariantList ) && $myConfig->getConfigParam( 'blVariantParentBuyable' ) ) {
00408                     //#1104S if parent is buyable load select lists too
00409                     $oParent->enablePriceLoad();
00410                     $oParent->aSelectlist = $oParent->getSelectLists();
00411                     $this->_aVariantList = array_merge( array( $oParent ), $this->_aVariantList->getArray() );
00412                 }
00413             } else {
00414                 //loading full list of variants
00415                 $this->_aVariantList = $oProduct->getFullVariants( false );
00416             }
00417 
00418             // setting link type for variants ..
00419             foreach ( $this->_aVariantList as $oVariant ) {
00420                 $this->_processProduct( $oVariant );
00421             }
00422 
00423         }
00424 
00425         return $this->_aVariantList;
00426     }
00427 
00428 
00434     public function getVariantList()
00435     {
00436         return $this->loadVariantInformation();
00437     }
00438 
00444     public function getCaptcha()
00445     {
00446         if ( $this->_oCaptcha === null ) {
00447             $this->_oCaptcha = oxNew('oxCaptcha');
00448         }
00449         return $this->_oCaptcha;
00450     }
00451 
00457     public function getMediaFiles()
00458     {
00459         if ( $this->_aMediaFiles === null ) {
00460             $aMediaFiles = $this->getProduct()->getMediaUrls();
00461             $this->_aMediaFiles = count($aMediaFiles) ? $aMediaFiles : false;
00462         }
00463         return $this->_aMediaFiles;
00464     }
00465 
00473     public function getLastProducts( $iCnt = 4 )
00474     {
00475         if ( $this->_aLastProducts === null ) {
00476             //last seen products for #768CA
00477             $oProduct = $this->getProduct();
00478             $sArtId = $oProduct->oxarticles__oxparentid->value?$oProduct->oxarticles__oxparentid->value:$oProduct->getId();
00479 
00480             $oHistoryArtList = oxNew( 'oxArticleList' );
00481             $oHistoryArtList->loadHistoryArticles( $sArtId, $iCnt );
00482             $this->_aLastProducts = $oHistoryArtList;
00483         }
00484         return $this->_aLastProducts;
00485     }
00486 
00492     public function getManufacturer()
00493     {
00494         if ( $this->_oManufacturer === null ) {
00495             $this->_oManufacturer = $this->getProduct()->getManufacturer( false );
00496         }
00497         return $this->_oManufacturer;
00498     }
00499 
00505     public function getVendor()
00506     {
00507         if ( $this->_oVendor === null ) {
00508             $this->_oVendor = $this->getProduct()->getVendor( false );
00509         }
00510         return $this->_oVendor;
00511     }
00512 
00518     public function getCategory()
00519     {
00520         if ( $this->_oCategory === null ) {
00521             $this->_oCategory = $this->getProduct()->getCategory();
00522         }
00523         return $this->_oCategory;
00524     }
00525 
00531     public function getPictureGallery()
00532     {
00533         if ( $this->_aPicGallery === null ) {
00534             //get picture gallery
00535             $this->_aPicGallery = $this->getPicturesProduct()->getPictureGallery();
00536         }
00537         return $this->_aPicGallery;
00538     }
00539 
00545     public function getActPicture()
00546     {
00547         $aPicGallery = $this->getPictureGallery();
00548         return $aPicGallery['ActPic'];
00549     }
00550 
00556     public function morePics()
00557     {
00558         $aPicGallery = $this->getPictureGallery();
00559         return $aPicGallery['MorePics'];
00560     }
00561 
00567     public function getIcons()
00568     {
00569         $aPicGallery = $this->getPictureGallery();
00570         return $aPicGallery['Icons'];
00571     }
00572 
00578     public function showZoomPics()
00579     {
00580         $aPicGallery = $this->getPictureGallery();
00581         return $aPicGallery['ZoomPic'];
00582     }
00583 
00589     public function getZoomPics()
00590     {
00591         $aPicGallery = $this->getPictureGallery();
00592         return $aPicGallery['ZoomPics'];
00593     }
00594 
00600     public function getReviews()
00601     {
00602         if ( $this->_aReviews === null ) {
00603             $this->_aReviews = false;
00604             if ( $this->getConfig()->getConfigParam( 'bl_perfLoadReviews' ) ) {
00605                 $this->_aReviews = $this->getProduct()->getReviews();
00606             }
00607         }
00608         return $this->_aReviews;
00609     }
00610 
00616     public function getCrossSelling()
00617     {
00618         if ( $this->_oCrossSelling === null ) {
00619             $this->_oCrossSelling = false;
00620             if ( $oProduct = $this->getProduct() ) {
00621                 $this->_oCrossSelling = $oProduct->getCrossSelling();
00622             }
00623         }
00624         return $this->_oCrossSelling;
00625     }
00626 
00632     public function getSimilarProducts()
00633     {
00634         if ( $this->_oSimilarProducts === null ) {
00635             $this->_oSimilarProducts = false;
00636             if ( $oProduct = $this->getProduct() ) {
00637                 $this->_oSimilarProducts = $oProduct->getSimilarProducts();
00638             }
00639         }
00640         return $this->_oSimilarProducts;
00641     }
00642 
00648     public function getSimilarRecommListIds()
00649     {
00650         if ( $this->_aSimilarRecommListIds === null ) {
00651             $this->_aSimilarRecommListIds = false;
00652 
00653             if ( $oProduct = $this->getProduct() ) {
00654                 $this->_aSimilarRecommListIds = array( $oProduct->getId() );
00655             }
00656         }
00657         return $this->_aSimilarRecommListIds;
00658     }
00659 
00665     public function getAccessoires()
00666     {
00667         if ( $this->_oAccessoires === null ) {
00668             $this->_oAccessoires = false;
00669             if ( $oProduct = $this->getProduct() ) {
00670                 $this->_oAccessoires = $oProduct->getAccessoires();
00671             }
00672         }
00673         return $this->_oAccessoires;
00674     }
00675 
00681     public function getAlsoBoughtTheseProducts()
00682     {
00683         if ( $this->_aAlsoBoughtArts === null ) {
00684             $this->_aAlsoBoughtArts = false;
00685             if ( $oProduct = $this->getProduct() ) {
00686                 $this->_aAlsoBoughtArts = $oProduct->getCustomerAlsoBoughtThisProducts();
00687             }
00688         }
00689         return $this->_aAlsoBoughtArts;
00690     }
00691 
00697     public function isPriceAlarm()
00698     {
00699         // #419 disabling price alarm if article has fixed price
00700         $oProduct = $this->getProduct();
00701         if ( isset( $oProduct->oxarticles__oxblfixedprice->value ) && $oProduct->oxarticles__oxblfixedprice->value ) {
00702             return 0;
00703         }
00704         return 1;
00705     }
00706 
00715     protected function _getSubject( $iLang )
00716     {
00717         return $this->getProduct();
00718     }
00719 
00725     public function getSearchTitle()
00726     {
00727         return $this->_sSearchTitle;
00728     }
00729 
00737     public function setSearchTitle( $sTitle )
00738     {
00739         $this->_sSearchTitle = $sTitle;
00740     }
00741 
00749     public function setCatTreePath( $sActCatPath )
00750     {
00751         $this->_sCatTreePath = $sActCatPath;
00752     }
00753 
00759     public function isPersParam()
00760     {
00761         $oProduct = $this->getProduct();
00762         return $oProduct->oxarticles__oxisconfigurable->value;
00763     }
00764 
00770     public function getRatingValue()
00771     {
00772 
00773         if ( $this->_dRatingValue === null ) {
00774             $this->_dRatingValue = (double) 0;
00775             if ( $this->isReviewActive() && ( $oDetailsProduct = $this->getProduct() ) ) {
00776                 $this->_dRatingValue = round( $oDetailsProduct->getArticleRatingAverage( $this->getConfig()->getConfigParam( 'blShowVariantReviews' ) ), 1);
00777             }
00778         }
00779 
00780         return (double) $this->_dRatingValue;
00781     }
00782 
00788     public function isReviewActive()
00789     {
00790         return $this->getConfig()->getConfigParam( 'bl_perfLoadReviews' );
00791     }
00792 
00798     public function getRatingCount()
00799     {
00800         if ( $this->_iRatingCnt === null ) {
00801             $this->_iRatingCnt = false;
00802             if ( $this->isReviewActive() && ( $oDetailsProduct = $this->getProduct() ) ) {
00803                 $this->_iRatingCnt = $oDetailsProduct->getArticleRatingCount( $this->getConfig()->getConfigParam( 'blShowVariantReviews' ) );
00804             }
00805         }
00806         return $this->_iRatingCnt;
00807     }
00808 
00814     public function getPriceAlarmStatus()
00815     {
00816         return $this->getViewParameter('iPriceAlarmStatus');
00817     }
00818 
00824     public function getBidPrice()
00825     {
00826         if ( $this->_sBidPrice === null ) {
00827             $this->_sBidPrice = false;
00828 
00829             $aParams = oxConfig::getParameter( 'pa' );
00830             $oCur = $this->getConfig()->getActShopCurrencyObject();
00831             $iPrice = oxRegistry::getUtils()->currency2Float( $aParams['price'] );
00832             $this->_sBidPrice = oxRegistry::getLang()->formatCurrency( $iPrice, $oCur );
00833         }
00834         return $this->_sBidPrice;
00835     }
00836 
00842     public function getVariantSelections()
00843     {
00844         // finding parent
00845         $oProduct = $this->getProduct();
00846         if ( ( $oParent = $this->_getParentProduct( $oProduct->oxarticles__oxparentid->value ) ) ) {
00847             return $oParent->getVariantSelections( oxConfig::getParameter( "varselid" ), $oProduct->getId() );
00848         }
00849 
00850         return $oProduct->getVariantSelections( oxConfig::getParameter( "varselid" ) );
00851     }
00852 
00858     public function getPicturesProduct()
00859     {
00860         $aVariantSelections = $this->getVariantSelections();
00861         if ($aVariantSelections && $aVariantSelections['oActiveVariant'] && !$aVariantSelections['blPerfectFit']) {
00862             return $aVariantSelections['oActiveVariant'];
00863         }
00864         return $this->getProduct();
00865     }
00866 
00872     public function getProduct()
00873     {
00874         $myConfig = $this->getConfig();
00875         $myUtils = oxRegistry::getUtils();
00876 
00877         if ( $this->_oProduct === null ) {
00878 
00879             if ( $this->getViewParameter( '_object' ) ) {
00880                 $this->_oProduct = $this->getViewParameter( '_object' );
00881             } else {
00882                 //this option is only for lists and we must reset value
00883                 //as blLoadVariants = false affect "ab price" functionality
00884                 $myConfig->setConfigParam( 'blLoadVariants', true );
00885 
00886                 $sOxid = oxConfig::getParameter( 'anid' );
00887 
00888                 // object is not yet loaded
00889                 $this->_oProduct = oxNew( 'oxarticle' );
00890 
00891                 if ( !$this->_oProduct->load( $sOxid ) ) {
00892                     $myUtils->redirect( $myConfig->getShopHomeURL() );
00893                     $myUtils->showMessageAndExit( '' );
00894                 }
00895 
00896                 $aVariantSelections = $this->_oProduct->getVariantSelections( oxConfig::getParameter( "varselid" ) );
00897                 if ($aVariantSelections && $aVariantSelections['oActiveVariant'] && $aVariantSelections['blPerfectFit']) {
00898                     $this->_oProduct = $aVariantSelections['oActiveVariant'];
00899                 }
00900             }
00901         }
00902         if ( !$this->_blIsInitialized ) {
00903             $this->_additionalChecksForArticle( $myUtils, $myConfig );
00904         }
00905 
00906         return $this->_oProduct;
00907     }
00908 
00912     protected function _setSortingParameters()
00913     {
00914         $sSortingParameters = $this->getViewParameter( 'sorting' );
00915         if ( $sSortingParameters ) {
00916             list( $sSortBy, $sSortDir ) = explode( '|', $sSortingParameters );
00917             $this->setItemSorting( 'alist', $sSortBy, $sSortDir );
00918         }
00919     }
00920 
00927     public function render()
00928     {
00929         $oProduct = $this->getProduct();
00930 
00931         parent::render();
00932 
00933         $oCategory = oxNew( 'oxCategory' );
00934 
00935         // if category parameter is not found, use category from product
00936         $sCatId = $this->getViewParameter( "cnid" );
00937 
00938         if ( !$sCatId && $oProduct->getCategory() ) {
00939             $oCategory = $oProduct->getCategory();
00940         }else {
00941             $oCategory->load( $sCatId );
00942         }
00943         $this->_setSortingParameters();
00944 
00945         $this->setActiveCategory( $oCategory );
00946 
00950         $oLocator = oxNew( 'oxLocator', $this->getListType() );
00951         $oLocator->setLocatorData( $oProduct, $this );
00952         return $this->_sThisTemplate;
00953 
00954     }
00955 
00961     public function isMdVariantView()
00962     {
00963         if ( $this->_blMdView === null ) {
00964             $this->_blMdView = false;
00965             if ( $this->getConfig()->getConfigParam( 'blUseMultidimensionVariants' ) ) {
00966                 $iMaxMdDepth = $this->getProduct()->getMdVariants()->getMaxDepth();
00967                 $this->_blMdView = ($iMaxMdDepth > 1);
00968             }
00969         }
00970 
00971         return $this->_blMdView;
00972     }
00973 
00979     public function getTagSeparator()
00980     {
00981         $sSeparator = $this->getConfig()->getConfigParam("sTagSeparator");
00982         return $sSeparator;
00983     }
00984 
00993     protected function _additionalChecksForArticle( $myUtils, $myConfig )
00994     {
00995         $blContinue = true;
00996         if ( !$this->_oProduct->isVisible() ) {
00997             $blContinue = false;
00998         } elseif ( $this->_oProduct->oxarticles__oxparentid->value ) {
00999             $oParent = $this->_getParentProduct( $this->_oProduct->oxarticles__oxparentid->value );
01000             if ( !$oParent || !$oParent->isVisible() ) {
01001                 $blContinue = false;
01002             }
01003         }
01004 
01005         if ( !$blContinue ) {
01006             $myUtils->redirect( $myConfig->getShopHomeURL() );
01007             $myUtils->showMessageAndExit( '' );
01008         }
01009 
01010         $this->_processProduct( $this->_oProduct );
01011         $this->_blIsInitialized = true;
01012     }
01013 
01019     public function getDefaultSorting()
01020     {
01021         $aSorting = parent::getDefaultSorting();
01022 
01023         $oCategory = $this->getActiveCategory();
01024 
01025         if ( $this->getListType() != 'search' && $oCategory && $oCategory instanceof oxCategory ) {
01026 
01027             if ( $sDefaultSorting = $oCategory->getDefaultSorting() ) {
01028                 $sArticleTable = getViewName( 'oxarticles' );
01029                 $sSortBy  = $sArticleTable.'.'.$sDefaultSorting;
01030                 $sSortDir = ( $oCategory->getDefaultSortingMode() ) ? "desc" : "asc";
01031                 $aSorting = array ( 'sortby' => $sSortBy, 'sortdir' => $sSortDir );
01032             }
01033         }
01034 
01035         return $aSorting;
01036     }
01037 
01038 }