oxwarticledetails.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class oxwArticleDetails extends oxWidget
00007 {
00008 
00014     protected $_aVariantList = null;
00021     protected $_aComponentNames = array('oxcmp_cur' => 1, 'oxcmp_shop' => 1, 'oxcmp_basket' => 1, 'oxcmp_user' => 1);
00022 
00028     protected $_sThisTemplate = 'widget/product/details.tpl';
00029 
00035     protected $_oParentProd = null;
00036 
00042     protected $_blCanRate = null;
00043 
00049     protected $_blCanEditTags = null;
00050 
00056     protected $_oCaptcha = null;
00057 
00063     protected $_aMediaFiles = null;
00064 
00070     protected $_aLastProducts = null;
00071 
00077     protected $_oVendor = null;
00078 
00084     protected $_oManufacturer = null;
00085 
00091     protected $_oCategory = null;
00092 
00098     protected $_aAttributes = null;
00099 
00105     protected $_aPicGallery = null;
00106 
00112     protected $_aReviews = null;
00113 
00119     protected $_oCrossSelling = null;
00120 
00126     protected $_oSimilarProducts = null;
00127 
00133     protected $_oAccessoires = null;
00134 
00140     protected $_aAlsoBoughtArts = null;
00141 
00147     protected $_sSearchTitle = null;
00148 
00155     protected $_blIsInitialized = false;
00156 
00162     protected $_iLinkType = null;
00163 
00169     protected $_blMdView = null;
00170 
00176     protected $_dRatingValue = null;
00177 
00183     protected $_iRatingCnt = null;
00184 
00190     protected $_sBidPrice = null;
00191 
00197     protected $_blShowSorting = true;
00198 
00204     protected $_aSimilarRecommListIds = null;
00205 
00206 
00212     public function getActZoomPic()
00213     {
00214         return 1;
00215     }
00216 
00224     protected function _getParentProduct($sParentId)
00225     {
00226         if ($sParentId && $this->_oParentProd === null) {
00227             $this->_oParentProd = false;
00228             $oProduct = oxNew('oxArticle');
00229             if (($oProduct->load($sParentId))) {
00230                 $this->_processProduct($oProduct);
00231                 $this->_oParentProd = $oProduct;
00232             }
00233         }
00234 
00235         return $this->_oParentProd;
00236     }
00237 
00243     protected function _getAddUrlParams()
00244     {
00245         if ($this->getListType() == "search") {
00246             return $this->getDynUrlParams();
00247         }
00248     }
00249 
00255     protected function _processProduct($oProduct)
00256     {
00257         $oProduct->setLinkType($this->getLinkType());
00258         if ($sAddParams = $this->_getAddUrlParams()) {
00259             $oProduct->appendLink($sAddParams);
00260         }
00261     }
00262 
00268     public function ratingIsActive()
00269     {
00270         return $this->getConfig()->getConfigParam('bl_perfLoadReviews');
00271     }
00272 
00278     public function canRate()
00279     {
00280         if ($this->_blCanRate === null) {
00281 
00282             $this->_blCanRate = false;
00283 
00284             if ($this->ratingIsActive() && $oUser = $this->getUser()) {
00285 
00286                 $oRating = oxNew('oxrating');
00287                 $this->_blCanRate = $oRating->allowRating($oUser->getId(), 'oxarticle', $this->getProduct()->getId());
00288             }
00289         }
00290 
00291         return $this->_blCanRate;
00292     }
00293 
00299     public function canChangeTags()
00300     {
00301         if ($oUser = $this->getUser()) {
00302 
00303             return true;
00304         }
00305 
00306         return false;
00307     }
00308 
00314     public function getAttributes()
00315     {
00316         if ($this->_aAttributes === null) {
00317             // all attributes this article has
00318             $aArtAttributes = $this->getProduct()->getAttributes();
00319 
00320             //making a new array for backward compatibility
00321             $this->_aAttributes = false;
00322 
00323             if (count($aArtAttributes)) {
00324                 foreach ($aArtAttributes as $sKey => $oAttribute) {
00325                     $this->_aAttributes[$sKey] = new stdClass();
00326                     $this->_aAttributes[$sKey]->title = $oAttribute->oxattribute__oxtitle->value;
00327                     $this->_aAttributes[$sKey]->value = $oAttribute->oxattribute__oxvalue->value;
00328                 }
00329             }
00330         }
00331 
00332         return $this->_aAttributes;
00333     }
00334 
00340     public function getTagCloudManager()
00341     {
00343         $oTagList = oxNew("oxArticleTagList");
00344         //$oTagList->load($this->getProduct()->getId());
00345         $oTagList->setArticleId($this->getProduct()->getId());
00346         $oTagCloud = oxNew("oxTagCloud");
00347         $oTagCloud->setTagList($oTagList);
00348         $oTagCloud->setExtendedMode(true);
00349 
00350         return $oTagCloud;
00351     }
00352 
00359     public function isEditableTags()
00360     {
00361         if ($this->_blCanEditTags === null) {
00362             $this->_blCanEditTags = false;
00363             if ($this->getProduct() && $this->getUser()) {
00364                 $this->_blCanEditTags = true;
00365             }
00366         }
00367 
00368         return $this->_blCanEditTags;
00369     }
00370 
00376     public function getLinkType()
00377     {
00378         if ($this->_iLinkType === null) {
00379             $sListType = oxRegistry::getConfig()->getRequestParameter('listtype');
00380             if ('vendor' == $sListType) {
00381                 $this->_iLinkType = OXARTICLE_LINKTYPE_VENDOR;
00382             } elseif ('manufacturer' == $sListType) {
00383                 $this->_iLinkType = OXARTICLE_LINKTYPE_MANUFACTURER;
00384             } elseif ('tag' == $sListType) {
00385                 $this->_iLinkType = OXARTICLE_LINKTYPE_TAG;
00386             } elseif ('recommlist' == $sListType) {
00387                 $this->_iLinkType = OXARTICLE_LINKTYPE_RECOMM;
00388             } else {
00389                 $this->_iLinkType = OXARTICLE_LINKTYPE_CATEGORY;
00390 
00391                 // price category has own type..
00392                 if (($oCat = $this->getActiveCategory()) && $oCat->isPriceCategory()) {
00393                     $this->_iLinkType = OXARTICLE_LINKTYPE_PRICECATEGORY;
00394                 }
00395             }
00396         }
00397 
00398         return $this->_iLinkType;
00399     }
00400 
00407     public function getVariantListExceptCurrent()
00408     {
00409         $oList = $this->getVariantList();
00410         if (is_object($oList)) {
00411             $oList = clone $oList;
00412         }
00413 
00414         $sOxId = $this->getProduct()->getId();
00415         if (isset($oList[$sOxId])) {
00416             unset($oList[$sOxId]);
00417         }
00418 
00419         return $oList;
00420     }
00421 
00428     public function loadVariantInformation()
00429     {
00430         if ($this->_aVariantList === null) {
00431             $oProduct = $this->getProduct();
00432 
00433             //if we are child and do not have any variants then let's load all parent variants as ours
00434             if ($oParent = $oProduct->getParentArticle()) {
00435                 $myConfig = $this->getConfig();
00436 
00437                 $oParent->setNoVariantLoading(false);
00438                 $this->_aVariantList = $oParent->getFullVariants(false);
00439 
00440                 //lets additionally add parent article if it is sellable
00441                 if (count($this->_aVariantList) && $myConfig->getConfigParam('blVariantParentBuyable')) {
00442                     //#1104S if parent is buyable load select lists too
00443                     $oParent->enablePriceLoad();
00444                     $oParent->aSelectlist = $oParent->getSelectLists();
00445                     $this->_aVariantList = array_merge(array($oParent), $this->_aVariantList->getArray());
00446                 }
00447             } else {
00448                 //loading full list of variants
00449                 $this->_aVariantList = $oProduct->getFullVariants(false);
00450             }
00451 
00452             // setting link type for variants ..
00453             foreach ($this->_aVariantList as $oVariant) {
00454                 $this->_processProduct($oVariant);
00455             }
00456 
00457         }
00458 
00459         return $this->_aVariantList;
00460     }
00461 
00462 
00468     public function getVariantList()
00469     {
00470         return $this->loadVariantInformation();
00471     }
00472 
00478     public function getCaptcha()
00479     {
00480         if ($this->_oCaptcha === null) {
00481             $this->_oCaptcha = oxNew('oxCaptcha');
00482         }
00483 
00484         return $this->_oCaptcha;
00485     }
00486 
00492     public function getMediaFiles()
00493     {
00494         if ($this->_aMediaFiles === null) {
00495             $aMediaFiles = $this->getProduct()->getMediaUrls();
00496             $this->_aMediaFiles = count($aMediaFiles) ? $aMediaFiles : false;
00497         }
00498 
00499         return $this->_aMediaFiles;
00500     }
00501 
00509     public function getLastProducts($iCnt = 4)
00510     {
00511         if ($this->_aLastProducts === null) {
00512             //last seen products for #768CA
00513             $oProduct = $this->getProduct();
00514             $sParentIdField = 'oxarticles__oxparentid';
00515             $sArtId = $oProduct->$sParentIdField->value ? $oProduct->$sParentIdField->value : $oProduct->getId();
00516 
00517             $oHistoryArtList = oxNew('oxArticleList');
00518             $oHistoryArtList->loadHistoryArticles($sArtId, $iCnt);
00519             $this->_aLastProducts = $oHistoryArtList;
00520         }
00521 
00522         return $this->_aLastProducts;
00523     }
00524 
00530     public function getManufacturer()
00531     {
00532         if ($this->_oManufacturer === null) {
00533             $this->_oManufacturer = $this->getProduct()->getManufacturer(false);
00534         }
00535 
00536         return $this->_oManufacturer;
00537     }
00538 
00544     public function getVendor()
00545     {
00546         if ($this->_oVendor === null) {
00547             $this->_oVendor = $this->getProduct()->getVendor(false);
00548         }
00549 
00550         return $this->_oVendor;
00551     }
00552 
00558     public function getCategory()
00559     {
00560         if ($this->_oCategory === null) {
00561             $this->_oCategory = $this->getProduct()->getCategory();
00562         }
00563 
00564         return $this->_oCategory;
00565     }
00566 
00572     public function getPictureGallery()
00573     {
00574         if ($this->_aPicGallery === null) {
00575             //get picture gallery
00576             $this->_aPicGallery = $this->getPicturesProduct()->getPictureGallery();
00577         }
00578 
00579         return $this->_aPicGallery;
00580     }
00581 
00587     public function getActPicture()
00588     {
00589         $aPicGallery = $this->getPictureGallery();
00590 
00591         return $aPicGallery['ActPic'];
00592     }
00593 
00599     public function morePics()
00600     {
00601         $aPicGallery = $this->getPictureGallery();
00602 
00603         return $aPicGallery['MorePics'];
00604     }
00605 
00611     public function getIcons()
00612     {
00613         $aPicGallery = $this->getPictureGallery();
00614 
00615         return $aPicGallery['Icons'];
00616     }
00617 
00623     public function showZoomPics()
00624     {
00625         $aPicGallery = $this->getPictureGallery();
00626 
00627         return $aPicGallery['ZoomPic'];
00628     }
00629 
00635     public function getZoomPics()
00636     {
00637         $aPicGallery = $this->getPictureGallery();
00638 
00639         return $aPicGallery['ZoomPics'];
00640     }
00641 
00647     public function getReviews()
00648     {
00649         if ($this->_aReviews === null) {
00650             $this->_aReviews = false;
00651             if ($this->getConfig()->getConfigParam('bl_perfLoadReviews')) {
00652                 $this->_aReviews = $this->getProduct()->getReviews();
00653             }
00654         }
00655 
00656         return $this->_aReviews;
00657     }
00658 
00664     public function getCrossSelling()
00665     {
00666         if ($this->_oCrossSelling === null) {
00667             $this->_oCrossSelling = false;
00668             if ($oProduct = $this->getProduct()) {
00669                 $this->_oCrossSelling = $oProduct->getCrossSelling();
00670             }
00671         }
00672 
00673         return $this->_oCrossSelling;
00674     }
00675 
00681     public function getSimilarProducts()
00682     {
00683         if ($this->_oSimilarProducts === null) {
00684             $this->_oSimilarProducts = false;
00685             if ($oProduct = $this->getProduct()) {
00686                 $this->_oSimilarProducts = $oProduct->getSimilarProducts();
00687             }
00688         }
00689 
00690         return $this->_oSimilarProducts;
00691     }
00692 
00698     public function getSimilarRecommListIds()
00699     {
00700         if ($this->_aSimilarRecommListIds === null) {
00701             $this->_aSimilarRecommListIds = false;
00702 
00703             if ($oProduct = $this->getProduct()) {
00704                 $this->_aSimilarRecommListIds = array($oProduct->getId());
00705             }
00706         }
00707 
00708         return $this->_aSimilarRecommListIds;
00709     }
00710 
00716     public function getAccessoires()
00717     {
00718         if ($this->_oAccessoires === null) {
00719             $this->_oAccessoires = false;
00720             if ($oProduct = $this->getProduct()) {
00721                 $this->_oAccessoires = $oProduct->getAccessoires();
00722             }
00723         }
00724 
00725         return $this->_oAccessoires;
00726     }
00727 
00733     public function getAlsoBoughtTheseProducts()
00734     {
00735         if ($this->_aAlsoBoughtArts === null) {
00736             $this->_aAlsoBoughtArts = false;
00737             if ($oProduct = $this->getProduct()) {
00738                 $this->_aAlsoBoughtArts = $oProduct->getCustomerAlsoBoughtThisProducts();
00739             }
00740         }
00741 
00742         return $this->_aAlsoBoughtArts;
00743     }
00744 
00750     public function isPriceAlarm()
00751     {
00752         // #419 disabling price alarm if article has fixed price
00753         $oProduct = $this->getProduct();
00754         $sFixedPriceField = 'oxarticles__oxblfixedprice';
00755         if (isset($oProduct->$sFixedPriceField->value) && $oProduct->$sFixedPriceField->value) {
00756             return 0;
00757         }
00758 
00759         return 1;
00760     }
00761 
00770     protected function _getSubject($iLang)
00771     {
00772         return $this->getProduct();
00773     }
00774 
00780     public function getSearchTitle()
00781     {
00782         return $this->_sSearchTitle;
00783     }
00784 
00790     public function setSearchTitle($sTitle)
00791     {
00792         $this->_sSearchTitle = $sTitle;
00793     }
00794 
00800     public function setCatTreePath($sActCatPath)
00801     {
00802         $this->_sCatTreePath = $sActCatPath;
00803     }
00804 
00810     public function isPersParam()
00811     {
00812         $oProduct = $this->getProduct();
00813 
00814         return $oProduct->oxarticles__oxisconfigurable->value;
00815     }
00816 
00822     public function getRatingValue()
00823     {
00824 
00825         if ($this->_dRatingValue === null) {
00826             $this->_dRatingValue = (double) 0;
00827             if ($this->isReviewActive() && ($oDetailsProduct = $this->getProduct())) {
00828                 $blShowVariantsReviews = $this->getConfig()->getConfigParam('blShowVariantReviews');
00829                 $this->_dRatingValue = round($oDetailsProduct->getArticleRatingAverage($blShowVariantsReviews), 1);
00830             }
00831         }
00832 
00833         return (double) $this->_dRatingValue;
00834     }
00835 
00841     public function isReviewActive()
00842     {
00843         return $this->getConfig()->getConfigParam('bl_perfLoadReviews');
00844     }
00845 
00851     public function getRatingCount()
00852     {
00853         if ($this->_iRatingCnt === null) {
00854             $this->_iRatingCnt = false;
00855             if ($this->isReviewActive() && ($oDetailsProduct = $this->getProduct())) {
00856                 $blShowVariantsReviews = $this->getConfig()->getConfigParam('blShowVariantReviews');
00857                 $this->_iRatingCnt = $oDetailsProduct->getArticleRatingCount($blShowVariantsReviews);
00858             }
00859         }
00860 
00861         return $this->_iRatingCnt;
00862     }
00863 
00869     public function getPriceAlarmStatus()
00870     {
00871         return $this->getViewParameter('iPriceAlarmStatus');
00872     }
00873 
00879     public function getBidPrice()
00880     {
00881         if ($this->_sBidPrice === null) {
00882             $this->_sBidPrice = false;
00883 
00884             $aParams = oxRegistry::getConfig()->getRequestParameter('pa');
00885             $oCur = $this->getConfig()->getActShopCurrencyObject();
00886             $iPrice = oxRegistry::getUtils()->currency2Float($aParams['price']);
00887             $this->_sBidPrice = oxRegistry::getLang()->formatCurrency($iPrice, $oCur);
00888         }
00889 
00890         return $this->_sBidPrice;
00891     }
00892 
00898     public function getVariantSelections()
00899     {
00900         // finding parent
00901         $oProduct = $this->getProduct();
00902         $sParentIdField = 'oxarticles__oxparentid';
00903         if (($oParent = $this->_getParentProduct($oProduct->$sParentIdField->value))) {
00904             $sVarSelId = oxRegistry::getConfig()->getRequestParameter("varselid");
00905             return $oParent->getVariantSelections($sVarSelId, $oProduct->getId());
00906         }
00907 
00908         return $oProduct->getVariantSelections(oxRegistry::getConfig()->getRequestParameter("varselid"));
00909     }
00910 
00916     public function getPicturesProduct()
00917     {
00918         $aVariantSelections = $this->getVariantSelections();
00919         if ($aVariantSelections && $aVariantSelections['oActiveVariant'] && !$aVariantSelections['blPerfectFit']) {
00920             return $aVariantSelections['oActiveVariant'];
00921         }
00922 
00923         return $this->getProduct();
00924     }
00925 
00931     public function getProduct()
00932     {
00933         $myConfig = $this->getConfig();
00934         $myUtils = oxRegistry::getUtils();
00935 
00936         if ($this->_oProduct === null) {
00937 
00938             if ($this->getViewParameter('_object')) {
00939                 $this->_oProduct = $this->getViewParameter('_object');
00940             } else {
00941                 //this option is only for lists and we must reset value
00942                 //as blLoadVariants = false affect "ab price" functionality
00943                 $myConfig->setConfigParam('blLoadVariants', true);
00944 
00945                 $sOxid = oxRegistry::getConfig()->getRequestParameter('anid');
00946 
00947                 // object is not yet loaded
00948                 $this->_oProduct = oxNew('oxarticle');
00949 
00950                 if (!$this->_oProduct->load($sOxid)) {
00951                     $myUtils->redirect($myConfig->getShopHomeURL());
00952                     $myUtils->showMessageAndExit('');
00953                 }
00954 
00955                 $sVarSelId = oxRegistry::getConfig()->getRequestParameter("varselid");
00956                 $aVarSelections = $this->_oProduct->getVariantSelections($sVarSelId);
00957                 if ($aVarSelections && $aVarSelections['oActiveVariant'] && $aVarSelections['blPerfectFit']) {
00958                     $this->_oProduct = $aVarSelections['oActiveVariant'];
00959                 }
00960             }
00961         }
00962         if (!$this->_blIsInitialized) {
00963             $this->_additionalChecksForArticle($myUtils, $myConfig);
00964         }
00965 
00966         return $this->_oProduct;
00967     }
00968 
00972     protected function _setSortingParameters()
00973     {
00974         $sSortingParameters = $this->getViewParameter('sorting');
00975         if ($sSortingParameters) {
00976             list($sSortBy, $sSortDir) = explode('|', $sSortingParameters);
00977             $this->setItemSorting($this->getSortIdent(), $sSortBy, $sSortDir);
00978         }
00979     }
00980 
00987     public function render()
00988     {
00989         $oProduct = $this->getProduct();
00990 
00991         parent::render();
00992 
00993         $oCategory = oxNew('oxCategory');
00994 
00995         // if category parameter is not found, use category from product
00996         $sCatId = $this->getViewParameter("cnid");
00997 
00998         if (!$sCatId && $oProduct->getCategory()) {
00999             $oCategory = $oProduct->getCategory();
01000         } else {
01001             $oCategory->load($sCatId);
01002         }
01003         $this->_setSortingParameters();
01004 
01005         $this->setActiveCategory($oCategory);
01006 
01010         $oLocator = oxNew('oxLocator', $this->getListType());
01011         $oLocator->setLocatorData($oProduct, $this);
01012 
01013         return $this->_sThisTemplate;
01014 
01015     }
01016 
01022     public function isMdVariantView()
01023     {
01024         if ($this->_blMdView === null) {
01025             $this->_blMdView = false;
01026             if ($this->getConfig()->getConfigParam('blUseMultidimensionVariants')) {
01027                 $iMaxMdDepth = $this->getProduct()->getMdVariants()->getMaxDepth();
01028                 $this->_blMdView = ($iMaxMdDepth > 1);
01029             }
01030         }
01031 
01032         return $this->_blMdView;
01033     }
01034 
01040     public function getTagSeparator()
01041     {
01042         $sSeparator = $this->getConfig()->getConfigParam("sTagSeparator");
01043 
01044         return $sSeparator;
01045     }
01046 
01053     protected function _additionalChecksForArticle($myUtils, $myConfig)
01054     {
01055         $blContinue = true;
01056         if (!$this->_oProduct->isVisible()) {
01057             $blContinue = false;
01058         } elseif ($this->_oProduct->oxarticles__oxparentid->value) {
01059             $oParent = $this->_getParentProduct($this->_oProduct->oxarticles__oxparentid->value);
01060             if (!$oParent || !$oParent->isVisible()) {
01061                 $blContinue = false;
01062             }
01063         }
01064 
01065         if (!$blContinue) {
01066             $myUtils->redirect($myConfig->getShopHomeURL());
01067             $myUtils->showMessageAndExit('');
01068         }
01069 
01070         $this->_processProduct($this->_oProduct);
01071         $this->_blIsInitialized = true;
01072     }
01073 
01079     public function getDefaultSorting()
01080     {
01081         $aSorting = parent::getDefaultSorting();
01082 
01083         $oCategory = $this->getActiveCategory();
01084 
01085         if ($this->getListType() != 'search' && $oCategory && $oCategory instanceof oxCategory) {
01086             if ($sSortBy = $oCategory->getDefaultSorting()) {
01087                 $sSortDir = ($oCategory->getDefaultSortingMode()) ? "desc" : "asc";
01088                 $aSorting = array('sortby' => $sSortBy, 'sortdir' => $sSortDir);
01089             }
01090         }
01091 
01092         return $aSorting;
01093     }
01094 }