OXID eShop CE  4.10.7
 All Classes Namespaces Files Functions Variables Pages
oxwarticledetails.php
Go to the documentation of this file.
1 <?php
2 
7 {
8 
14  protected $_aVariantList = null;
21  protected $_aComponentNames = array('oxcmp_cur' => 1, 'oxcmp_shop' => 1, 'oxcmp_basket' => 1, 'oxcmp_user' => 1);
22 
28  protected $_sThisTemplate = 'widget/product/details.tpl';
29 
35  protected $_oParentProd = null;
36 
42  protected $_blCanRate = null;
43 
51  protected $_blCanEditTags = null;
52 
58  protected $_oCaptcha = null;
59 
65  protected $_aMediaFiles = null;
66 
72  protected $_aLastProducts = null;
73 
79  protected $_oVendor = null;
80 
86  protected $_oManufacturer = null;
87 
93  protected $_oCategory = null;
94 
100  protected $_aAttributes = null;
101 
107  protected $_aPicGallery = null;
108 
114  protected $_aReviews = null;
115 
121  protected $_oCrossSelling = null;
122 
128  protected $_oSimilarProducts = null;
129 
135  protected $_oAccessoires = null;
136 
142  protected $_aAlsoBoughtArts = null;
143 
149  protected $_sSearchTitle = null;
150 
157  protected $_blIsInitialized = false;
158 
164  protected $_iLinkType = null;
165 
171  protected $_blMdView = null;
172 
178  protected $_dRatingValue = null;
179 
185  protected $_iRatingCnt = null;
186 
192  protected $_sBidPrice = null;
193 
199  protected $_blShowSorting = true;
200 
208  protected $_aSimilarRecommListIds = null;
209 
210 
216  public function getActZoomPic()
217  {
218  return 1;
219  }
220 
228  protected function _getParentProduct($sParentId)
229  {
230  if ($sParentId && $this->_oParentProd === null) {
231  $this->_oParentProd = false;
232  $oProduct = oxNew('oxArticle');
233  if (($oProduct->load($sParentId))) {
234  $this->_processProduct($oProduct);
235  $this->_oParentProd = $oProduct;
236  }
237  }
238 
239  return $this->_oParentProd;
240  }
241 
247  protected function _getAddUrlParams()
248  {
249  if ($this->getListType() == "search") {
250  return $this->getDynUrlParams();
251  }
252  }
253 
259  protected function _processProduct($oProduct)
260  {
261  $oProduct->setLinkType($this->getLinkType());
262  if ($sAddParams = $this->_getAddUrlParams()) {
263  $oProduct->appendLink($sAddParams);
264  }
265  }
266 
272  public function ratingIsActive()
273  {
274  return $this->getConfig()->getConfigParam('bl_perfLoadReviews');
275  }
276 
282  public function canRate()
283  {
284  if ($this->_blCanRate === null) {
285 
286  $this->_blCanRate = false;
287 
288  if ($this->ratingIsActive() && $oUser = $this->getUser()) {
289 
290  $oRating = oxNew('oxrating');
291  $this->_blCanRate = $oRating->allowRating($oUser->getId(), 'oxarticle', $this->getProduct()->getId());
292  }
293  }
294 
295  return $this->_blCanRate;
296  }
297 
305  public function canChangeTags()
306  {
307  if ($oUser = $this->getUser()) {
308 
309  return true;
310  }
311 
312  return false;
313  }
314 
320  public function getAttributes()
321  {
322  if ($this->_aAttributes === null) {
323  // all attributes this article has
324  $aArtAttributes = $this->getProduct()->getAttributes();
325 
326  //making a new array for backward compatibility
327  $this->_aAttributes = false;
328 
329  if (count($aArtAttributes)) {
330  foreach ($aArtAttributes as $sKey => $oAttribute) {
331  $this->_aAttributes[$sKey] = new stdClass();
332  $this->_aAttributes[$sKey]->title = $oAttribute->oxattribute__oxtitle->value;
333  $this->_aAttributes[$sKey]->value = $oAttribute->oxattribute__oxvalue->value;
334  }
335  }
336  }
337 
338  return $this->_aAttributes;
339  }
340 
348  public function getTagCloudManager()
349  {
351  $oTagList = oxNew("oxArticleTagList");
352  //$oTagList->load($this->getProduct()->getId());
353  $oTagList->setArticleId($this->getProduct()->getId());
354  $oTagCloud = oxNew("oxTagCloud");
355  $oTagCloud->setTagList($oTagList);
356  $oTagCloud->setExtendedMode(true);
357 
358  return $oTagCloud;
359  }
360 
369  public function isEditableTags()
370  {
371  if ($this->_blCanEditTags === null) {
372  $this->_blCanEditTags = false;
373  if ($this->getProduct() && $this->getUser()) {
374  $this->_blCanEditTags = true;
375  }
376  }
377 
378  return $this->_blCanEditTags;
379  }
380 
386  public function getLinkType()
387  {
388  if ($this->_iLinkType === null) {
389  $sListType = oxRegistry::getConfig()->getRequestParameter('listtype');
390  if ('vendor' == $sListType) {
391  $this->_iLinkType = OXARTICLE_LINKTYPE_VENDOR;
392  } elseif ('manufacturer' == $sListType) {
393  $this->_iLinkType = OXARTICLE_LINKTYPE_MANUFACTURER;
394  // @deprecated v5.3 (2016-05-04); Tags will be moved to own module.
395  } elseif ('tag' == $sListType) {
396  $this->_iLinkType = OXARTICLE_LINKTYPE_TAG;
397  // END deprecated
398  // @deprecated since v5.3 (2016-06-17); Listmania will be moved to an own module.
399  } elseif ('recommlist' == $sListType) {
400  $this->_iLinkType = OXARTICLE_LINKTYPE_RECOMM;
401  // END deprecated
402  } else {
403  $this->_iLinkType = OXARTICLE_LINKTYPE_CATEGORY;
404 
405  // price category has own type..
406  if (($oCat = $this->getActiveCategory()) && $oCat->isPriceCategory()) {
407  $this->_iLinkType = OXARTICLE_LINKTYPE_PRICECATEGORY;
408  }
409  }
410  }
411 
412  return $this->_iLinkType;
413  }
414 
421  public function getVariantListExceptCurrent()
422  {
423  $oList = $this->getVariantList();
424  if (is_object($oList)) {
425  $oList = clone $oList;
426  }
427 
428  $sOxId = $this->getProduct()->getId();
429  if (isset($oList[$sOxId])) {
430  unset($oList[$sOxId]);
431  }
432 
433  return $oList;
434  }
435 
442  public function loadVariantInformation()
443  {
444  if ($this->_aVariantList === null) {
445  $oProduct = $this->getProduct();
446 
447  //if we are child and do not have any variants then let's load all parent variants as ours
448  if ($oParent = $oProduct->getParentArticle()) {
449  $myConfig = $this->getConfig();
450 
451  $oParent->setNoVariantLoading(false);
452  $this->_aVariantList = $oParent->getFullVariants(false);
453 
454  //lets additionally add parent article if it is sellable
455  if (count($this->_aVariantList) && $myConfig->getConfigParam('blVariantParentBuyable')) {
456  //#1104S if parent is buyable load select lists too
457  $oParent->enablePriceLoad();
458  $oParent->aSelectlist = $oParent->getSelectLists();
459  $this->_aVariantList = array_merge(array($oParent), $this->_aVariantList->getArray());
460  }
461  } else {
462  //loading full list of variants
463  $this->_aVariantList = $oProduct->getFullVariants(false);
464  }
465 
466  // setting link type for variants ..
467  foreach ($this->_aVariantList as $oVariant) {
468  $this->_processProduct($oVariant);
469  }
470 
471  }
472 
473  return $this->_aVariantList;
474  }
475 
476 
482  public function getVariantList()
483  {
484  return $this->loadVariantInformation();
485  }
486 
494  public function getCaptcha()
495  {
496  if ($this->_oCaptcha === null) {
497  $this->_oCaptcha = oxNew('oxCaptcha');
498  }
499 
500  return $this->_oCaptcha;
501  }
502 
508  public function getMediaFiles()
509  {
510  if ($this->_aMediaFiles === null) {
511  $aMediaFiles = $this->getProduct()->getMediaUrls();
512  $this->_aMediaFiles = count($aMediaFiles) ? $aMediaFiles : false;
513  }
514 
515  return $this->_aMediaFiles;
516  }
517 
525  public function getLastProducts($iCnt = 4)
526  {
527  if ($this->_aLastProducts === null) {
528  //last seen products for #768CA
529  $oProduct = $this->getProduct();
530  $sParentIdField = 'oxarticles__oxparentid';
531  $sArtId = $oProduct->$sParentIdField->value ? $oProduct->$sParentIdField->value : $oProduct->getId();
532 
533  $oHistoryArtList = oxNew('oxArticleList');
534  $oHistoryArtList->loadHistoryArticles($sArtId, $iCnt);
535  $this->_aLastProducts = $oHistoryArtList;
536  }
537 
538  return $this->_aLastProducts;
539  }
540 
546  public function getManufacturer()
547  {
548  if ($this->_oManufacturer === null) {
549  $this->_oManufacturer = $this->getProduct()->getManufacturer(false);
550  }
551 
552  return $this->_oManufacturer;
553  }
554 
560  public function getVendor()
561  {
562  if ($this->_oVendor === null) {
563  $this->_oVendor = $this->getProduct()->getVendor(false);
564  }
565 
566  return $this->_oVendor;
567  }
568 
574  public function getCategory()
575  {
576  if ($this->_oCategory === null) {
577  $this->_oCategory = $this->getProduct()->getCategory();
578  }
579 
580  return $this->_oCategory;
581  }
582 
588  public function getPictureGallery()
589  {
590  if ($this->_aPicGallery === null) {
591  //get picture gallery
592  $this->_aPicGallery = $this->getPicturesProduct()->getPictureGallery();
593  }
594 
595  return $this->_aPicGallery;
596  }
597 
603  public function getActPicture()
604  {
605  $aPicGallery = $this->getPictureGallery();
606 
607  return $aPicGallery['ActPic'];
608  }
609 
615  public function morePics()
616  {
617  $aPicGallery = $this->getPictureGallery();
618 
619  return $aPicGallery['MorePics'];
620  }
621 
627  public function getIcons()
628  {
629  $aPicGallery = $this->getPictureGallery();
630 
631  return $aPicGallery['Icons'];
632  }
633 
639  public function showZoomPics()
640  {
641  $aPicGallery = $this->getPictureGallery();
642 
643  return $aPicGallery['ZoomPic'];
644  }
645 
651  public function getZoomPics()
652  {
653  $aPicGallery = $this->getPictureGallery();
654 
655  return $aPicGallery['ZoomPics'];
656  }
657 
663  public function getReviews()
664  {
665  if ($this->_aReviews === null) {
666  $this->_aReviews = false;
667  if ($this->getConfig()->getConfigParam('bl_perfLoadReviews')) {
668  $this->_aReviews = $this->getProduct()->getReviews();
669  }
670  }
671 
672  return $this->_aReviews;
673  }
674 
680  public function getCrossSelling()
681  {
682  if ($this->_oCrossSelling === null) {
683  $this->_oCrossSelling = false;
684  if ($oProduct = $this->getProduct()) {
685  $this->_oCrossSelling = $oProduct->getCrossSelling();
686  }
687  }
688 
689  return $this->_oCrossSelling;
690  }
691 
697  public function getSimilarProducts()
698  {
699  if ($this->_oSimilarProducts === null) {
700  $this->_oSimilarProducts = false;
701  if ($oProduct = $this->getProduct()) {
702  $this->_oSimilarProducts = $oProduct->getSimilarProducts();
703  }
704  }
705 
707  }
708 
716  public function getSimilarRecommListIds()
717  {
718  if ($this->_aSimilarRecommListIds === null) {
719  $this->_aSimilarRecommListIds = false;
720 
721  if ($oProduct = $this->getProduct()) {
722  $this->_aSimilarRecommListIds = array($oProduct->getId());
723  }
724  }
725 
727  }
728 
734  public function getAccessoires()
735  {
736  if ($this->_oAccessoires === null) {
737  $this->_oAccessoires = false;
738  if ($oProduct = $this->getProduct()) {
739  $this->_oAccessoires = $oProduct->getAccessoires();
740  }
741  }
742 
743  return $this->_oAccessoires;
744  }
745 
751  public function getAlsoBoughtTheseProducts()
752  {
753  if ($this->_aAlsoBoughtArts === null) {
754  $this->_aAlsoBoughtArts = false;
755  if ($oProduct = $this->getProduct()) {
756  $this->_aAlsoBoughtArts = $oProduct->getCustomerAlsoBoughtThisProducts();
757  }
758  }
759 
761  }
762 
768  public function isPriceAlarm()
769  {
770  // #419 disabling price alarm if article has fixed price
771  $oProduct = $this->getProduct();
772  $sFixedPriceField = 'oxarticles__oxblfixedprice';
773  if (isset($oProduct->$sFixedPriceField->value) && $oProduct->$sFixedPriceField->value) {
774  return 0;
775  }
776 
777  return 1;
778  }
779 
788  protected function _getSubject($iLang)
789  {
790  return $this->getProduct();
791  }
792 
798  public function getSearchTitle()
799  {
800  return $this->_sSearchTitle;
801  }
802 
808  public function setSearchTitle($sTitle)
809  {
810  $this->_sSearchTitle = $sTitle;
811  }
812 
818  public function setCatTreePath($sActCatPath)
819  {
820  $this->_sCatTreePath = $sActCatPath;
821  }
822 
828  public function isPersParam()
829  {
830  $oProduct = $this->getProduct();
831 
832  return $oProduct->oxarticles__oxisconfigurable->value;
833  }
834 
840  public function getRatingValue()
841  {
842 
843  if ($this->_dRatingValue === null) {
844  $this->_dRatingValue = (double) 0;
845  if ($this->isReviewActive() && ($oDetailsProduct = $this->getProduct())) {
846  $blShowVariantsReviews = $this->getConfig()->getConfigParam('blShowVariantReviews');
847  $this->_dRatingValue = round($oDetailsProduct->getArticleRatingAverage($blShowVariantsReviews), 1);
848  }
849  }
850 
851  return (double) $this->_dRatingValue;
852  }
853 
859  public function isReviewActive()
860  {
861  return $this->getConfig()->getConfigParam('bl_perfLoadReviews');
862  }
863 
869  public function getRatingCount()
870  {
871  if ($this->_iRatingCnt === null) {
872  $this->_iRatingCnt = false;
873  if ($this->isReviewActive() && ($oDetailsProduct = $this->getProduct())) {
874  $blShowVariantsReviews = $this->getConfig()->getConfigParam('blShowVariantReviews');
875  $this->_iRatingCnt = $oDetailsProduct->getArticleRatingCount($blShowVariantsReviews);
876  }
877  }
878 
879  return $this->_iRatingCnt;
880  }
881 
887  public function getPriceAlarmStatus()
888  {
889  return $this->getViewParameter('iPriceAlarmStatus');
890  }
891 
897  public function getBidPrice()
898  {
899  if ($this->_sBidPrice === null) {
900  $this->_sBidPrice = false;
901 
902  $aParams = oxRegistry::getConfig()->getRequestParameter('pa');
903  $oCur = $this->getConfig()->getActShopCurrencyObject();
904  $iPrice = oxRegistry::getUtils()->currency2Float($aParams['price']);
905  $this->_sBidPrice = oxRegistry::getLang()->formatCurrency($iPrice, $oCur);
906  }
907 
908  return $this->_sBidPrice;
909  }
910 
916  public function getVariantSelections()
917  {
918  // finding parent
919  $oProduct = $this->getProduct();
920  $sParentIdField = 'oxarticles__oxparentid';
921  if (($oParent = $this->_getParentProduct($oProduct->$sParentIdField->value))) {
922  $sVarSelId = oxRegistry::getConfig()->getRequestParameter("varselid");
923  return $oParent->getVariantSelections($sVarSelId, $oProduct->getId());
924  }
925 
926  return $oProduct->getVariantSelections(oxRegistry::getConfig()->getRequestParameter("varselid"));
927  }
928 
934  public function getPicturesProduct()
935  {
936  $aVariantSelections = $this->getVariantSelections();
937  if ($aVariantSelections && $aVariantSelections['oActiveVariant'] && !$aVariantSelections['blPerfectFit']) {
938  return $aVariantSelections['oActiveVariant'];
939  }
940 
941  return $this->getProduct();
942  }
943 
949  public function getProduct()
950  {
951  $myConfig = $this->getConfig();
952  $myUtils = oxRegistry::getUtils();
953 
954  if ($this->_oProduct === null) {
955 
956  if ($this->getViewParameter('_object')) {
957  $this->_oProduct = $this->getViewParameter('_object');
958  } else {
959  //this option is only for lists and we must reset value
960  //as blLoadVariants = false affect "ab price" functionality
961  $myConfig->setConfigParam('blLoadVariants', true);
962 
963  $sOxid = oxRegistry::getConfig()->getRequestParameter('anid');
964 
965  // object is not yet loaded
966  $this->_oProduct = oxNew('oxarticle');
967 
968  if (!$this->_oProduct->load($sOxid)) {
969  $myUtils->redirect($myConfig->getShopHomeURL());
970  $myUtils->showMessageAndExit('');
971  }
972 
973  $sVarSelId = oxRegistry::getConfig()->getRequestParameter("varselid");
974  $aVarSelections = $this->_oProduct->getVariantSelections($sVarSelId);
975  if ($aVarSelections && $aVarSelections['oActiveVariant'] && $aVarSelections['blPerfectFit']) {
976  $this->_oProduct = $aVarSelections['oActiveVariant'];
977  }
978  }
979  }
980  if (!$this->_blIsInitialized) {
981  $this->_additionalChecksForArticle($myUtils, $myConfig);
982  }
983 
984  return $this->_oProduct;
985  }
986 
990  protected function _setSortingParameters()
991  {
992  $sSortingParameters = $this->getViewParameter('sorting');
993  if ($sSortingParameters) {
994  list($sSortBy, $sSortDir) = explode('|', $sSortingParameters);
995  $this->setItemSorting($this->getSortIdent(), $sSortBy, $sSortDir);
996  }
997  }
998 
1005  public function render()
1006  {
1007  $oProduct = $this->getProduct();
1008 
1009  parent::render();
1010 
1011  $oCategory = oxNew('oxCategory');
1012 
1013  // if category parameter is not found, use category from product
1014  $sCatId = $this->getViewParameter("cnid");
1015 
1016  if (!$sCatId && $oProduct->getCategory()) {
1017  $oCategory = $oProduct->getCategory();
1018  } else {
1019  $oCategory->load($sCatId);
1020  }
1021  $this->_setSortingParameters();
1022 
1023  $this->setActiveCategory($oCategory);
1024 
1028  $oLocator = oxNew('oxLocator', $this->getListType());
1029  $oLocator->setLocatorData($oProduct, $this);
1030 
1031  return $this->_sThisTemplate;
1032 
1033  }
1034 
1040  public function isMdVariantView()
1041  {
1042  if ($this->_blMdView === null) {
1043  $this->_blMdView = false;
1044  if ($this->getConfig()->getConfigParam('blUseMultidimensionVariants')) {
1045  $iMaxMdDepth = $this->getProduct()->getMdVariants()->getMaxDepth();
1046  $this->_blMdView = ($iMaxMdDepth > 1);
1047  }
1048  }
1049 
1050  return $this->_blMdView;
1051  }
1052 
1060  public function getTagSeparator()
1061  {
1062  $sSeparator = $this->getConfig()->getConfigParam("sTagSeparator");
1063 
1064  return $sSeparator;
1065  }
1066 
1073  protected function _additionalChecksForArticle($myUtils, $myConfig)
1074  {
1075  $blContinue = true;
1076  if (!$this->_oProduct->isVisible()) {
1077  $blContinue = false;
1078  } elseif ($this->_oProduct->oxarticles__oxparentid->value) {
1079  $oParent = $this->_getParentProduct($this->_oProduct->oxarticles__oxparentid->value);
1080  if (!$oParent || !$oParent->isVisible()) {
1081  $blContinue = false;
1082  }
1083  }
1084 
1085  if (!$blContinue) {
1086  $myUtils->redirect($myConfig->getShopHomeURL());
1087  $myUtils->showMessageAndExit('');
1088  }
1089 
1090  $this->_processProduct($this->_oProduct);
1091  $this->_blIsInitialized = true;
1092  }
1093 
1099  public function getDefaultSorting()
1100  {
1101  $aSorting = parent::getDefaultSorting();
1102 
1103  $oCategory = $this->getActiveCategory();
1104 
1105  if ($this->getListType() != 'search' && $oCategory && $oCategory instanceof oxCategory) {
1106  if ($sSortBy = $oCategory->getDefaultSorting()) {
1107  $sSortDir = ($oCategory->getDefaultSortingMode()) ? "desc" : "asc";
1108  $aSorting = array('sortby' => $sSortBy, 'sortdir' => $sSortDir);
1109  }
1110  }
1111 
1112  return $aSorting;
1113  }
1114 }