OXID eShop CE  4.8.10
 All Classes Files Functions Variables Pages
oxwarticledetails.php
Go to the documentation of this file.
1 <?php
2 
9 {
15  protected $_aVariantList = null;
21  protected $_aComponentNames = array( 'oxcmp_cur' => 1, 'oxcmp_shop' => 1, 'oxcmp_basket' => 1, 'oxcmp_user' => 1 );
22 
27  protected $_sThisTemplate = 'widget/product/details.tpl';
28 
34  protected $_oParentProd = null;
35 
41  protected $_blCanRate = null;
42 
47  protected $_blCanEditTags = null;
48 
53  protected $_oCaptcha = null;
54 
59  protected $_aMediaFiles = null;
60 
65  protected $_aLastProducts = null;
66 
71  protected $_oVendor = null;
72 
77  protected $_oManufacturer = null;
78 
83  protected $_oCategory = null;
84 
89  protected $_aAttributes = null;
90 
95  protected $_aPicGallery = null;
96 
101  protected $_aReviews = null;
102 
107  protected $_oCrossSelling = null;
108 
113  protected $_oSimilarProducts = null;
114 
119  protected $_oAccessoires = null;
120 
125  protected $_aAlsoBoughtArts = null;
126 
131  protected $_sSearchTitle = null;
132 
138  protected $_blIsInitialized = false;
139 
145  protected $_iLinkType = null;
146 
152  protected $_blMdView = null;
153 
158  protected $_dRatingValue = null;
159 
164  protected $_iRatingCnt = null;
165 
170  protected $_sBidPrice = null;
171 
176  protected $_blShowSorting = true;
177 
183  protected $_aSimilarRecommListIds = null;
184 
185 
191  public function getActZoomPic()
192  {
193  return 1;
194  }
195 
203  protected function _getParentProduct( $sParentId )
204  {
205  if ( $sParentId && $this->_oParentProd === null ) {
206  $this->_oParentProd = false;
207  $oProduct = oxNew( 'oxArticle' );
208  if ( ( $oProduct->load( $sParentId ) ) ) {
209  $this->_processProduct( $oProduct );
210  $this->_oParentProd = $oProduct;
211  }
212  }
213  return $this->_oParentProd;
214  }
215 
221  protected function _getAddUrlParams()
222  {
223  if ( $this->getListType() == "search" ) {
224  return $this->getDynUrlParams();
225  }
226  }
227 
235  protected function _processProduct( $oProduct )
236  {
237  $oProduct->setLinkType( $this->getLinkType() );
238  if ( $sAddParams = $this->_getAddUrlParams() ) {
239  $oProduct->appendLink( $sAddParams );
240  }
241  }
242 
248  public function ratingIsActive()
249  {
250  return $this->getConfig()->getConfigParam( 'bl_perfLoadReviews' );
251  }
252 
258  public function canRate()
259  {
260  if ( $this->_blCanRate === null ) {
261 
262  $this->_blCanRate = false;
263 
264  if ( $this->ratingIsActive() && $oUser = $this->getUser() ) {
265 
266  $oRating = oxNew( 'oxrating' );
267  $this->_blCanRate = $oRating->allowRating( $oUser->getId(), 'oxarticle', $this->getProduct()->getId() );
268  }
269  }
270 
271  return $this->_blCanRate;
272  }
273 
279  public function canChangeTags()
280  {
281  if ( $oUser = $this->getUser() ) {
282 
283  return true;
284  }
285  return false;
286  }
287 
293  public function getAttributes()
294  {
295  if ( $this->_aAttributes === null ) {
296  // all attributes this article has
297  $aArtAttributes = $this->getProduct()->getAttributes();
298 
299  //making a new array for backward compatibility
300  $this->_aAttributes = false;
301 
302  if ( count( $aArtAttributes ) ) {
303  foreach ( $aArtAttributes as $sKey => $oAttribute ) {
304  $this->_aAttributes[$sKey] = new stdClass();
305  $this->_aAttributes[$sKey]->title = $oAttribute->oxattribute__oxtitle->value;
306  $this->_aAttributes[$sKey]->value = $oAttribute->oxattribute__oxvalue->value;
307  }
308  }
309  }
310  return $this->_aAttributes;
311  }
312 
318  public function getTagCloudManager()
319  {
320  $oManager = oxNew( "oxTagCloud" );
321  $oManager->setExtendedMode( true );
322  $oManager->setProductId( $this->getProduct()->getId() );
323  return $oManager;
324  }
325 
332  public function isEditableTags()
333  {
334  if ( $this->_blCanEditTags === null ) {
335  $this->_blCanEditTags = false;
336  if ( $this->getProduct() && $this->getUser()) {
337  $this->_blCanEditTags = true;
338  }
339  }
340  return $this->_blCanEditTags;
341  }
342 
348  public function getLinkType()
349  {
350  if ( $this->_iLinkType === null ) {
351  $sListType = oxConfig::getParameter( 'listtype' );
352  if ( 'vendor' == $sListType ) {
353  $this->_iLinkType = OXARTICLE_LINKTYPE_VENDOR;
354  } elseif ( 'manufacturer' == $sListType ) {
355  $this->_iLinkType = OXARTICLE_LINKTYPE_MANUFACTURER;
356  } elseif ( 'tag' == $sListType ) {
357  $this->_iLinkType = OXARTICLE_LINKTYPE_TAG;
358  } elseif ( 'recommlist' == $sListType ) {
359  $this->_iLinkType = OXARTICLE_LINKTYPE_RECOMM;
360  } else {
361  $this->_iLinkType = OXARTICLE_LINKTYPE_CATEGORY;
362 
363  // price category has own type..
364  if ( ( $oCat = $this->getActiveCategory() ) && $oCat->isPriceCategory() ) {
365  $this->_iLinkType = OXARTICLE_LINKTYPE_PRICECATEGORY;
366  }
367  }
368  }
369 
370  return $this->_iLinkType;
371  }
372 
379  public function getVariantListExceptCurrent()
380  {
381  $oList = $this->getVariantList();
382  if (is_object($oList)) {
383  $oList = clone $oList;
384  }
385 
386  $sOxId = $this->getProduct()->getId();
387  if (isset($oList[$sOxId])) {
388  unset($oList[$sOxId]);
389  }
390  return $oList;
391  }
392 
399  public function loadVariantInformation()
400  {
401  if ( $this->_aVariantList === null ) {
402  $oProduct = $this->getProduct();
403 
404  //if we are child and do not have any variants then let's load all parent variants as ours
405  if ( $oParent = $oProduct->getParentArticle() ) {
406  $myConfig = $this->getConfig();
407 
408  $oParent->setNoVariantLoading(false);
409  $this->_aVariantList = $oParent->getFullVariants( false );
410 
411  //lets additionally add parent article if it is sellable
412  if ( count( $this->_aVariantList ) && $myConfig->getConfigParam( 'blVariantParentBuyable' ) ) {
413  //#1104S if parent is buyable load select lists too
414  $oParent->enablePriceLoad();
415  $oParent->aSelectlist = $oParent->getSelectLists();
416  $this->_aVariantList = array_merge( array( $oParent ), $this->_aVariantList->getArray() );
417  }
418  } else {
419  //loading full list of variants
420  $this->_aVariantList = $oProduct->getFullVariants( false );
421  }
422 
423  // setting link type for variants ..
424  foreach ( $this->_aVariantList as $oVariant ) {
425  $this->_processProduct( $oVariant );
426  }
427 
428  }
429 
430  return $this->_aVariantList;
431  }
432 
433 
439  public function getVariantList()
440  {
441  return $this->loadVariantInformation();
442  }
443 
449  public function getCaptcha()
450  {
451  if ( $this->_oCaptcha === null ) {
452  $this->_oCaptcha = oxNew('oxCaptcha');
453  }
454  return $this->_oCaptcha;
455  }
456 
462  public function getMediaFiles()
463  {
464  if ( $this->_aMediaFiles === null ) {
465  $aMediaFiles = $this->getProduct()->getMediaUrls();
466  $this->_aMediaFiles = count($aMediaFiles) ? $aMediaFiles : false;
467  }
468  return $this->_aMediaFiles;
469  }
470 
478  public function getLastProducts( $iCnt = 4 )
479  {
480  if ( $this->_aLastProducts === null ) {
481  //last seen products for #768CA
482  $oProduct = $this->getProduct();
483  $sArtId = $oProduct->oxarticles__oxparentid->value?$oProduct->oxarticles__oxparentid->value:$oProduct->getId();
484 
485  $oHistoryArtList = oxNew( 'oxArticleList' );
486  $oHistoryArtList->loadHistoryArticles( $sArtId, $iCnt );
487  $this->_aLastProducts = $oHistoryArtList;
488  }
489  return $this->_aLastProducts;
490  }
491 
497  public function getManufacturer()
498  {
499  if ( $this->_oManufacturer === null ) {
500  $this->_oManufacturer = $this->getProduct()->getManufacturer( false );
501  }
502  return $this->_oManufacturer;
503  }
504 
510  public function getVendor()
511  {
512  if ( $this->_oVendor === null ) {
513  $this->_oVendor = $this->getProduct()->getVendor( false );
514  }
515  return $this->_oVendor;
516  }
517 
523  public function getCategory()
524  {
525  if ( $this->_oCategory === null ) {
526  $this->_oCategory = $this->getProduct()->getCategory();
527  }
528  return $this->_oCategory;
529  }
530 
536  public function getPictureGallery()
537  {
538  if ( $this->_aPicGallery === null ) {
539  //get picture gallery
540  $this->_aPicGallery = $this->getPicturesProduct()->getPictureGallery();
541  }
542  return $this->_aPicGallery;
543  }
544 
550  public function getActPicture()
551  {
552  $aPicGallery = $this->getPictureGallery();
553  return $aPicGallery['ActPic'];
554  }
555 
561  public function morePics()
562  {
563  $aPicGallery = $this->getPictureGallery();
564  return $aPicGallery['MorePics'];
565  }
566 
572  public function getIcons()
573  {
574  $aPicGallery = $this->getPictureGallery();
575  return $aPicGallery['Icons'];
576  }
577 
583  public function showZoomPics()
584  {
585  $aPicGallery = $this->getPictureGallery();
586  return $aPicGallery['ZoomPic'];
587  }
588 
594  public function getZoomPics()
595  {
596  $aPicGallery = $this->getPictureGallery();
597  return $aPicGallery['ZoomPics'];
598  }
599 
605  public function getReviews()
606  {
607  if ( $this->_aReviews === null ) {
608  $this->_aReviews = false;
609  if ( $this->getConfig()->getConfigParam( 'bl_perfLoadReviews' ) ) {
610  $this->_aReviews = $this->getProduct()->getReviews();
611  }
612  }
613  return $this->_aReviews;
614  }
615 
621  public function getCrossSelling()
622  {
623  if ( $this->_oCrossSelling === null ) {
624  $this->_oCrossSelling = false;
625  if ( $oProduct = $this->getProduct() ) {
626  $this->_oCrossSelling = $oProduct->getCrossSelling();
627  }
628  }
629  return $this->_oCrossSelling;
630  }
631 
637  public function getSimilarProducts()
638  {
639  if ( $this->_oSimilarProducts === null ) {
640  $this->_oSimilarProducts = false;
641  if ( $oProduct = $this->getProduct() ) {
642  $this->_oSimilarProducts = $oProduct->getSimilarProducts();
643  }
644  }
646  }
647 
653  public function getSimilarRecommListIds()
654  {
655  if ( $this->_aSimilarRecommListIds === null ) {
656  $this->_aSimilarRecommListIds = false;
657 
658  if ( $oProduct = $this->getProduct() ) {
659  $this->_aSimilarRecommListIds = array( $oProduct->getId() );
660  }
661  }
663  }
664 
670  public function getAccessoires()
671  {
672  if ( $this->_oAccessoires === null ) {
673  $this->_oAccessoires = false;
674  if ( $oProduct = $this->getProduct() ) {
675  $this->_oAccessoires = $oProduct->getAccessoires();
676  }
677  }
678  return $this->_oAccessoires;
679  }
680 
686  public function getAlsoBoughtTheseProducts()
687  {
688  if ( $this->_aAlsoBoughtArts === null ) {
689  $this->_aAlsoBoughtArts = false;
690  if ( $oProduct = $this->getProduct() ) {
691  $this->_aAlsoBoughtArts = $oProduct->getCustomerAlsoBoughtThisProducts();
692  }
693  }
695  }
696 
702  public function isPriceAlarm()
703  {
704  // #419 disabling price alarm if article has fixed price
705  $oProduct = $this->getProduct();
706  if ( isset( $oProduct->oxarticles__oxblfixedprice->value ) && $oProduct->oxarticles__oxblfixedprice->value ) {
707  return 0;
708  }
709  return 1;
710  }
711 
720  protected function _getSubject( $iLang )
721  {
722  return $this->getProduct();
723  }
724 
730  public function getSearchTitle()
731  {
732  return $this->_sSearchTitle;
733  }
734 
742  public function setSearchTitle( $sTitle )
743  {
744  $this->_sSearchTitle = $sTitle;
745  }
746 
754  public function setCatTreePath( $sActCatPath )
755  {
756  $this->_sCatTreePath = $sActCatPath;
757  }
758 
764  public function isPersParam()
765  {
766  $oProduct = $this->getProduct();
767  return $oProduct->oxarticles__oxisconfigurable->value;
768  }
769 
775  public function getRatingValue()
776  {
777 
778  if ( $this->_dRatingValue === null ) {
779  $this->_dRatingValue = (double) 0;
780  if ( $this->isReviewActive() && ( $oDetailsProduct = $this->getProduct() ) ) {
781  $this->_dRatingValue = round( $oDetailsProduct->getArticleRatingAverage( $this->getConfig()->getConfigParam( 'blShowVariantReviews' ) ), 1);
782  }
783  }
784 
785  return (double) $this->_dRatingValue;
786  }
787 
793  public function isReviewActive()
794  {
795  return $this->getConfig()->getConfigParam( 'bl_perfLoadReviews' );
796  }
797 
803  public function getRatingCount()
804  {
805  if ( $this->_iRatingCnt === null ) {
806  $this->_iRatingCnt = false;
807  if ( $this->isReviewActive() && ( $oDetailsProduct = $this->getProduct() ) ) {
808  $this->_iRatingCnt = $oDetailsProduct->getArticleRatingCount( $this->getConfig()->getConfigParam( 'blShowVariantReviews' ) );
809  }
810  }
811  return $this->_iRatingCnt;
812  }
813 
819  public function getPriceAlarmStatus()
820  {
821  return $this->getViewParameter('iPriceAlarmStatus');
822  }
823 
829  public function getBidPrice()
830  {
831  if ( $this->_sBidPrice === null ) {
832  $this->_sBidPrice = false;
833 
834  $aParams = oxConfig::getParameter( 'pa' );
835  $oCur = $this->getConfig()->getActShopCurrencyObject();
836  $iPrice = oxRegistry::getUtils()->currency2Float( $aParams['price'] );
837  $this->_sBidPrice = oxRegistry::getLang()->formatCurrency( $iPrice, $oCur );
838  }
839  return $this->_sBidPrice;
840  }
841 
847  public function getVariantSelections()
848  {
849  // finding parent
850  $oProduct = $this->getProduct();
851  if ( ( $oParent = $this->_getParentProduct( $oProduct->oxarticles__oxparentid->value ) ) ) {
852  return $oParent->getVariantSelections( oxConfig::getParameter( "varselid" ), $oProduct->getId() );
853  }
854 
855  return $oProduct->getVariantSelections( oxConfig::getParameter( "varselid" ) );
856  }
857 
863  public function getPicturesProduct()
864  {
865  $aVariantSelections = $this->getVariantSelections();
866  if ($aVariantSelections && $aVariantSelections['oActiveVariant'] && !$aVariantSelections['blPerfectFit']) {
867  return $aVariantSelections['oActiveVariant'];
868  }
869  return $this->getProduct();
870  }
871 
877  public function getProduct()
878  {
879  $myConfig = $this->getConfig();
880  $myUtils = oxRegistry::getUtils();
881 
882  if ( $this->_oProduct === null ) {
883 
884  if ( $this->getViewParameter( '_object' ) ) {
885  $this->_oProduct = $this->getViewParameter( '_object' );
886  } else {
887  //this option is only for lists and we must reset value
888  //as blLoadVariants = false affect "ab price" functionality
889  $myConfig->setConfigParam( 'blLoadVariants', true );
890 
891  $sOxid = oxConfig::getParameter( 'anid' );
892 
893  // object is not yet loaded
894  $this->_oProduct = oxNew( 'oxarticle' );
895 
896  if ( !$this->_oProduct->load( $sOxid ) ) {
897  $myUtils->redirect( $myConfig->getShopHomeURL() );
898  $myUtils->showMessageAndExit( '' );
899  }
900 
901  $aVariantSelections = $this->_oProduct->getVariantSelections( oxConfig::getParameter( "varselid" ) );
902  if ($aVariantSelections && $aVariantSelections['oActiveVariant'] && $aVariantSelections['blPerfectFit']) {
903  $this->_oProduct = $aVariantSelections['oActiveVariant'];
904  }
905  }
906  }
907  if ( !$this->_blIsInitialized ) {
908  $this->_additionalChecksForArticle( $myUtils, $myConfig );
909  }
910 
911  return $this->_oProduct;
912  }
913 
919  protected function _setSortingParameters()
920  {
921  $sSortingParameters = $this->getViewParameter( 'sorting' );
922  if ( $sSortingParameters ) {
923  list( $sSortBy, $sSortDir ) = explode( '|', $sSortingParameters );
924  $this->setItemSorting( 'alist', $sSortBy, $sSortDir );
925  }
926  }
927 
934  public function render()
935  {
936  $oProduct = $this->getProduct();
937 
938  parent::render();
939 
940  $oCategory = oxNew( 'oxCategory' );
941 
942  // if category parameter is not found, use category from product
943  $sCatId = $this->getViewParameter( "cnid" );
944 
945  if ( !$sCatId && $oProduct->getCategory() ) {
946  $oCategory = $oProduct->getCategory();
947  } else {
948  $oCategory->load( $sCatId );
949  }
950  $this->_setSortingParameters();
951 
952  $this->setActiveCategory( $oCategory );
953 
957  $oLocator = oxNew( 'oxLocator', $this->getListType() );
958  $oLocator->setLocatorData( $oProduct, $this );
959  return $this->_sThisTemplate;
960 
961  }
962 
968  public function isMdVariantView()
969  {
970  if ( $this->_blMdView === null ) {
971  $this->_blMdView = false;
972  if ( $this->getConfig()->getConfigParam( 'blUseMultidimensionVariants' ) ) {
973  $iMaxMdDepth = $this->getProduct()->getMdVariants()->getMaxDepth();
974  $this->_blMdView = ($iMaxMdDepth > 1);
975  }
976  }
977 
978  return $this->_blMdView;
979  }
980 
986  public function getTagSeparator()
987  {
988  $sSeparator = $this->getConfig()->getConfigParam("sTagSeparator");
989  return $sSeparator;
990  }
991 
1000  protected function _additionalChecksForArticle( $myUtils, $myConfig )
1001  {
1002  $blContinue = true;
1003  if ( !$this->_oProduct->isVisible() ) {
1004  $blContinue = false;
1005  } elseif ( $this->_oProduct->oxarticles__oxparentid->value ) {
1006  $oParent = $this->_getParentProduct( $this->_oProduct->oxarticles__oxparentid->value );
1007  if ( !$oParent || !$oParent->isVisible() ) {
1008  $blContinue = false;
1009  }
1010  }
1011 
1012  if ( !$blContinue ) {
1013  $myUtils->redirect( $myConfig->getShopHomeURL() );
1014  $myUtils->showMessageAndExit( '' );
1015  }
1016 
1017  $this->_processProduct( $this->_oProduct );
1018  $this->_blIsInitialized = true;
1019  }
1020 
1026  public function getDefaultSorting()
1027  {
1028  $aSorting = parent::getDefaultSorting();
1029  $oCategory = $this->getActiveCategory();
1030 
1031  if ( $this->getListType() != 'search' && $oCategory && $oCategory instanceof oxCategory ) {
1032  if ( $sSortBy = $oCategory->getDefaultSorting() ) {
1033  $sSortDir = ( $oCategory->getDefaultSortingMode() ) ? "desc" : "asc";
1034  $aSorting = array ( 'sortby' => $sSortBy, 'sortdir' => $sSortDir );
1035  }
1036  }
1037 
1038  return $aSorting;
1039  }
1040 
1041 }