OXID eShop CE  4.9.6
 All Classes 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 
49  protected $_blCanEditTags = null;
50 
56  protected $_oCaptcha = null;
57 
63  protected $_aMediaFiles = null;
64 
70  protected $_aLastProducts = null;
71 
77  protected $_oVendor = null;
78 
84  protected $_oManufacturer = null;
85 
91  protected $_oCategory = null;
92 
98  protected $_aAttributes = null;
99 
105  protected $_aPicGallery = null;
106 
112  protected $_aReviews = null;
113 
119  protected $_oCrossSelling = null;
120 
126  protected $_oSimilarProducts = null;
127 
133  protected $_oAccessoires = null;
134 
140  protected $_aAlsoBoughtArts = null;
141 
147  protected $_sSearchTitle = null;
148 
155  protected $_blIsInitialized = false;
156 
162  protected $_iLinkType = null;
163 
169  protected $_blMdView = null;
170 
176  protected $_dRatingValue = null;
177 
183  protected $_iRatingCnt = null;
184 
190  protected $_sBidPrice = null;
191 
197  protected $_blShowSorting = true;
198 
204  protected $_aSimilarRecommListIds = null;
205 
206 
212  public function getActZoomPic()
213  {
214  return 1;
215  }
216 
224  protected function _getParentProduct($sParentId)
225  {
226  if ($sParentId && $this->_oParentProd === null) {
227  $this->_oParentProd = false;
228  $oProduct = oxNew('oxArticle');
229  if (($oProduct->load($sParentId))) {
230  $this->_processProduct($oProduct);
231  $this->_oParentProd = $oProduct;
232  }
233  }
234 
235  return $this->_oParentProd;
236  }
237 
243  protected function _getAddUrlParams()
244  {
245  if ($this->getListType() == "search") {
246  return $this->getDynUrlParams();
247  }
248  }
249 
255  protected function _processProduct($oProduct)
256  {
257  $oProduct->setLinkType($this->getLinkType());
258  if ($sAddParams = $this->_getAddUrlParams()) {
259  $oProduct->appendLink($sAddParams);
260  }
261  }
262 
268  public function ratingIsActive()
269  {
270  return $this->getConfig()->getConfigParam('bl_perfLoadReviews');
271  }
272 
278  public function canRate()
279  {
280  if ($this->_blCanRate === null) {
281 
282  $this->_blCanRate = false;
283 
284  if ($this->ratingIsActive() && $oUser = $this->getUser()) {
285 
286  $oRating = oxNew('oxrating');
287  $this->_blCanRate = $oRating->allowRating($oUser->getId(), 'oxarticle', $this->getProduct()->getId());
288  }
289  }
290 
291  return $this->_blCanRate;
292  }
293 
299  public function canChangeTags()
300  {
301  if ($oUser = $this->getUser()) {
302 
303  return true;
304  }
305 
306  return false;
307  }
308 
314  public function getAttributes()
315  {
316  if ($this->_aAttributes === null) {
317  // all attributes this article has
318  $aArtAttributes = $this->getProduct()->getAttributes();
319 
320  //making a new array for backward compatibility
321  $this->_aAttributes = false;
322 
323  if (count($aArtAttributes)) {
324  foreach ($aArtAttributes as $sKey => $oAttribute) {
325  $this->_aAttributes[$sKey] = new stdClass();
326  $this->_aAttributes[$sKey]->title = $oAttribute->oxattribute__oxtitle->value;
327  $this->_aAttributes[$sKey]->value = $oAttribute->oxattribute__oxvalue->value;
328  }
329  }
330  }
331 
332  return $this->_aAttributes;
333  }
334 
340  public function getTagCloudManager()
341  {
343  $oTagList = oxNew("oxArticleTagList");
344  //$oTagList->load($this->getProduct()->getId());
345  $oTagList->setArticleId($this->getProduct()->getId());
346  $oTagCloud = oxNew("oxTagCloud");
347  $oTagCloud->setTagList($oTagList);
348  $oTagCloud->setExtendedMode(true);
349 
350  return $oTagCloud;
351  }
352 
359  public function isEditableTags()
360  {
361  if ($this->_blCanEditTags === null) {
362  $this->_blCanEditTags = false;
363  if ($this->getProduct() && $this->getUser()) {
364  $this->_blCanEditTags = true;
365  }
366  }
367 
368  return $this->_blCanEditTags;
369  }
370 
376  public function getLinkType()
377  {
378  if ($this->_iLinkType === null) {
379  $sListType = oxRegistry::getConfig()->getRequestParameter('listtype');
380  if ('vendor' == $sListType) {
381  $this->_iLinkType = OXARTICLE_LINKTYPE_VENDOR;
382  } elseif ('manufacturer' == $sListType) {
383  $this->_iLinkType = OXARTICLE_LINKTYPE_MANUFACTURER;
384  } elseif ('tag' == $sListType) {
385  $this->_iLinkType = OXARTICLE_LINKTYPE_TAG;
386  } elseif ('recommlist' == $sListType) {
387  $this->_iLinkType = OXARTICLE_LINKTYPE_RECOMM;
388  } else {
389  $this->_iLinkType = OXARTICLE_LINKTYPE_CATEGORY;
390 
391  // price category has own type..
392  if (($oCat = $this->getActiveCategory()) && $oCat->isPriceCategory()) {
393  $this->_iLinkType = OXARTICLE_LINKTYPE_PRICECATEGORY;
394  }
395  }
396  }
397 
398  return $this->_iLinkType;
399  }
400 
407  public function getVariantListExceptCurrent()
408  {
409  $oList = $this->getVariantList();
410  if (is_object($oList)) {
411  $oList = clone $oList;
412  }
413 
414  $sOxId = $this->getProduct()->getId();
415  if (isset($oList[$sOxId])) {
416  unset($oList[$sOxId]);
417  }
418 
419  return $oList;
420  }
421 
428  public function loadVariantInformation()
429  {
430  if ($this->_aVariantList === null) {
431  $oProduct = $this->getProduct();
432 
433  //if we are child and do not have any variants then let's load all parent variants as ours
434  if ($oParent = $oProduct->getParentArticle()) {
435  $myConfig = $this->getConfig();
436 
437  $oParent->setNoVariantLoading(false);
438  $this->_aVariantList = $oParent->getFullVariants(false);
439 
440  //lets additionally add parent article if it is sellable
441  if (count($this->_aVariantList) && $myConfig->getConfigParam('blVariantParentBuyable')) {
442  //#1104S if parent is buyable load select lists too
443  $oParent->enablePriceLoad();
444  $oParent->aSelectlist = $oParent->getSelectLists();
445  $this->_aVariantList = array_merge(array($oParent), $this->_aVariantList->getArray());
446  }
447  } else {
448  //loading full list of variants
449  $this->_aVariantList = $oProduct->getFullVariants(false);
450  }
451 
452  // setting link type for variants ..
453  foreach ($this->_aVariantList as $oVariant) {
454  $this->_processProduct($oVariant);
455  }
456 
457  }
458 
459  return $this->_aVariantList;
460  }
461 
462 
468  public function getVariantList()
469  {
470  return $this->loadVariantInformation();
471  }
472 
478  public function getCaptcha()
479  {
480  if ($this->_oCaptcha === null) {
481  $this->_oCaptcha = oxNew('oxCaptcha');
482  }
483 
484  return $this->_oCaptcha;
485  }
486 
492  public function getMediaFiles()
493  {
494  if ($this->_aMediaFiles === null) {
495  $aMediaFiles = $this->getProduct()->getMediaUrls();
496  $this->_aMediaFiles = count($aMediaFiles) ? $aMediaFiles : false;
497  }
498 
499  return $this->_aMediaFiles;
500  }
501 
509  public function getLastProducts($iCnt = 4)
510  {
511  if ($this->_aLastProducts === null) {
512  //last seen products for #768CA
513  $oProduct = $this->getProduct();
514  $sParentIdField = 'oxarticles__oxparentid';
515  $sArtId = $oProduct->$sParentIdField->value ? $oProduct->$sParentIdField->value : $oProduct->getId();
516 
517  $oHistoryArtList = oxNew('oxArticleList');
518  $oHistoryArtList->loadHistoryArticles($sArtId, $iCnt);
519  $this->_aLastProducts = $oHistoryArtList;
520  }
521 
522  return $this->_aLastProducts;
523  }
524 
530  public function getManufacturer()
531  {
532  if ($this->_oManufacturer === null) {
533  $this->_oManufacturer = $this->getProduct()->getManufacturer(false);
534  }
535 
536  return $this->_oManufacturer;
537  }
538 
544  public function getVendor()
545  {
546  if ($this->_oVendor === null) {
547  $this->_oVendor = $this->getProduct()->getVendor(false);
548  }
549 
550  return $this->_oVendor;
551  }
552 
558  public function getCategory()
559  {
560  if ($this->_oCategory === null) {
561  $this->_oCategory = $this->getProduct()->getCategory();
562  }
563 
564  return $this->_oCategory;
565  }
566 
572  public function getPictureGallery()
573  {
574  if ($this->_aPicGallery === null) {
575  //get picture gallery
576  $this->_aPicGallery = $this->getPicturesProduct()->getPictureGallery();
577  }
578 
579  return $this->_aPicGallery;
580  }
581 
587  public function getActPicture()
588  {
589  $aPicGallery = $this->getPictureGallery();
590 
591  return $aPicGallery['ActPic'];
592  }
593 
599  public function morePics()
600  {
601  $aPicGallery = $this->getPictureGallery();
602 
603  return $aPicGallery['MorePics'];
604  }
605 
611  public function getIcons()
612  {
613  $aPicGallery = $this->getPictureGallery();
614 
615  return $aPicGallery['Icons'];
616  }
617 
623  public function showZoomPics()
624  {
625  $aPicGallery = $this->getPictureGallery();
626 
627  return $aPicGallery['ZoomPic'];
628  }
629 
635  public function getZoomPics()
636  {
637  $aPicGallery = $this->getPictureGallery();
638 
639  return $aPicGallery['ZoomPics'];
640  }
641 
647  public function getReviews()
648  {
649  if ($this->_aReviews === null) {
650  $this->_aReviews = false;
651  if ($this->getConfig()->getConfigParam('bl_perfLoadReviews')) {
652  $this->_aReviews = $this->getProduct()->getReviews();
653  }
654  }
655 
656  return $this->_aReviews;
657  }
658 
664  public function getCrossSelling()
665  {
666  if ($this->_oCrossSelling === null) {
667  $this->_oCrossSelling = false;
668  if ($oProduct = $this->getProduct()) {
669  $this->_oCrossSelling = $oProduct->getCrossSelling();
670  }
671  }
672 
673  return $this->_oCrossSelling;
674  }
675 
681  public function getSimilarProducts()
682  {
683  if ($this->_oSimilarProducts === null) {
684  $this->_oSimilarProducts = false;
685  if ($oProduct = $this->getProduct()) {
686  $this->_oSimilarProducts = $oProduct->getSimilarProducts();
687  }
688  }
689 
691  }
692 
698  public function getSimilarRecommListIds()
699  {
700  if ($this->_aSimilarRecommListIds === null) {
701  $this->_aSimilarRecommListIds = false;
702 
703  if ($oProduct = $this->getProduct()) {
704  $this->_aSimilarRecommListIds = array($oProduct->getId());
705  }
706  }
707 
709  }
710 
716  public function getAccessoires()
717  {
718  if ($this->_oAccessoires === null) {
719  $this->_oAccessoires = false;
720  if ($oProduct = $this->getProduct()) {
721  $this->_oAccessoires = $oProduct->getAccessoires();
722  }
723  }
724 
725  return $this->_oAccessoires;
726  }
727 
733  public function getAlsoBoughtTheseProducts()
734  {
735  if ($this->_aAlsoBoughtArts === null) {
736  $this->_aAlsoBoughtArts = false;
737  if ($oProduct = $this->getProduct()) {
738  $this->_aAlsoBoughtArts = $oProduct->getCustomerAlsoBoughtThisProducts();
739  }
740  }
741 
743  }
744 
750  public function isPriceAlarm()
751  {
752  // #419 disabling price alarm if article has fixed price
753  $oProduct = $this->getProduct();
754  $sFixedPriceField = 'oxarticles__oxblfixedprice';
755  if (isset($oProduct->$sFixedPriceField->value) && $oProduct->$sFixedPriceField->value) {
756  return 0;
757  }
758 
759  return 1;
760  }
761 
770  protected function _getSubject($iLang)
771  {
772  return $this->getProduct();
773  }
774 
780  public function getSearchTitle()
781  {
782  return $this->_sSearchTitle;
783  }
784 
790  public function setSearchTitle($sTitle)
791  {
792  $this->_sSearchTitle = $sTitle;
793  }
794 
800  public function setCatTreePath($sActCatPath)
801  {
802  $this->_sCatTreePath = $sActCatPath;
803  }
804 
810  public function isPersParam()
811  {
812  $oProduct = $this->getProduct();
813 
814  return $oProduct->oxarticles__oxisconfigurable->value;
815  }
816 
822  public function getRatingValue()
823  {
824 
825  if ($this->_dRatingValue === null) {
826  $this->_dRatingValue = (double) 0;
827  if ($this->isReviewActive() && ($oDetailsProduct = $this->getProduct())) {
828  $blShowVariantsReviews = $this->getConfig()->getConfigParam('blShowVariantReviews');
829  $this->_dRatingValue = round($oDetailsProduct->getArticleRatingAverage($blShowVariantsReviews), 1);
830  }
831  }
832 
833  return (double) $this->_dRatingValue;
834  }
835 
841  public function isReviewActive()
842  {
843  return $this->getConfig()->getConfigParam('bl_perfLoadReviews');
844  }
845 
851  public function getRatingCount()
852  {
853  if ($this->_iRatingCnt === null) {
854  $this->_iRatingCnt = false;
855  if ($this->isReviewActive() && ($oDetailsProduct = $this->getProduct())) {
856  $blShowVariantsReviews = $this->getConfig()->getConfigParam('blShowVariantReviews');
857  $this->_iRatingCnt = $oDetailsProduct->getArticleRatingCount($blShowVariantsReviews);
858  }
859  }
860 
861  return $this->_iRatingCnt;
862  }
863 
869  public function getPriceAlarmStatus()
870  {
871  return $this->getViewParameter('iPriceAlarmStatus');
872  }
873 
879  public function getBidPrice()
880  {
881  if ($this->_sBidPrice === null) {
882  $this->_sBidPrice = false;
883 
884  $aParams = oxRegistry::getConfig()->getRequestParameter('pa');
885  $oCur = $this->getConfig()->getActShopCurrencyObject();
886  $iPrice = oxRegistry::getUtils()->currency2Float($aParams['price']);
887  $this->_sBidPrice = oxRegistry::getLang()->formatCurrency($iPrice, $oCur);
888  }
889 
890  return $this->_sBidPrice;
891  }
892 
898  public function getVariantSelections()
899  {
900  // finding parent
901  $oProduct = $this->getProduct();
902  $sParentIdField = 'oxarticles__oxparentid';
903  if (($oParent = $this->_getParentProduct($oProduct->$sParentIdField->value))) {
904  $sVarSelId = oxRegistry::getConfig()->getRequestParameter("varselid");
905  return $oParent->getVariantSelections($sVarSelId, $oProduct->getId());
906  }
907 
908  return $oProduct->getVariantSelections(oxRegistry::getConfig()->getRequestParameter("varselid"));
909  }
910 
916  public function getPicturesProduct()
917  {
918  $aVariantSelections = $this->getVariantSelections();
919  if ($aVariantSelections && $aVariantSelections['oActiveVariant'] && !$aVariantSelections['blPerfectFit']) {
920  return $aVariantSelections['oActiveVariant'];
921  }
922 
923  return $this->getProduct();
924  }
925 
931  public function getProduct()
932  {
933  $myConfig = $this->getConfig();
934  $myUtils = oxRegistry::getUtils();
935 
936  if ($this->_oProduct === null) {
937 
938  if ($this->getViewParameter('_object')) {
939  $this->_oProduct = $this->getViewParameter('_object');
940  } else {
941  //this option is only for lists and we must reset value
942  //as blLoadVariants = false affect "ab price" functionality
943  $myConfig->setConfigParam('blLoadVariants', true);
944 
945  $sOxid = oxRegistry::getConfig()->getRequestParameter('anid');
946 
947  // object is not yet loaded
948  $this->_oProduct = oxNew('oxarticle');
949 
950  if (!$this->_oProduct->load($sOxid)) {
951  $myUtils->redirect($myConfig->getShopHomeURL());
952  $myUtils->showMessageAndExit('');
953  }
954 
955  $sVarSelId = oxRegistry::getConfig()->getRequestParameter("varselid");
956  $aVarSelections = $this->_oProduct->getVariantSelections($sVarSelId);
957  if ($aVarSelections && $aVarSelections['oActiveVariant'] && $aVarSelections['blPerfectFit']) {
958  $this->_oProduct = $aVarSelections['oActiveVariant'];
959  }
960  }
961  }
962  if (!$this->_blIsInitialized) {
963  $this->_additionalChecksForArticle($myUtils, $myConfig);
964  }
965 
966  return $this->_oProduct;
967  }
968 
972  protected function _setSortingParameters()
973  {
974  $sSortingParameters = $this->getViewParameter('sorting');
975  if ($sSortingParameters) {
976  list($sSortBy, $sSortDir) = explode('|', $sSortingParameters);
977  $this->setItemSorting($this->getSortIdent(), $sSortBy, $sSortDir);
978  }
979  }
980 
987  public function render()
988  {
989  $oProduct = $this->getProduct();
990 
991  parent::render();
992 
993  $oCategory = oxNew('oxCategory');
994 
995  // if category parameter is not found, use category from product
996  $sCatId = $this->getViewParameter("cnid");
997 
998  if (!$sCatId && $oProduct->getCategory()) {
999  $oCategory = $oProduct->getCategory();
1000  } else {
1001  $oCategory->load($sCatId);
1002  }
1003  $this->_setSortingParameters();
1004 
1005  $this->setActiveCategory($oCategory);
1006 
1010  $oLocator = oxNew('oxLocator', $this->getListType());
1011  $oLocator->setLocatorData($oProduct, $this);
1012 
1013  return $this->_sThisTemplate;
1014 
1015  }
1016 
1022  public function isMdVariantView()
1023  {
1024  if ($this->_blMdView === null) {
1025  $this->_blMdView = false;
1026  if ($this->getConfig()->getConfigParam('blUseMultidimensionVariants')) {
1027  $iMaxMdDepth = $this->getProduct()->getMdVariants()->getMaxDepth();
1028  $this->_blMdView = ($iMaxMdDepth > 1);
1029  }
1030  }
1031 
1032  return $this->_blMdView;
1033  }
1034 
1040  public function getTagSeparator()
1041  {
1042  $sSeparator = $this->getConfig()->getConfigParam("sTagSeparator");
1043 
1044  return $sSeparator;
1045  }
1046 
1053  protected function _additionalChecksForArticle($myUtils, $myConfig)
1054  {
1055  $blContinue = true;
1056  if (!$this->_oProduct->isVisible()) {
1057  $blContinue = false;
1058  } elseif ($this->_oProduct->oxarticles__oxparentid->value) {
1059  $oParent = $this->_getParentProduct($this->_oProduct->oxarticles__oxparentid->value);
1060  if (!$oParent || !$oParent->isVisible()) {
1061  $blContinue = false;
1062  }
1063  }
1064 
1065  if (!$blContinue) {
1066  $myUtils->redirect($myConfig->getShopHomeURL());
1067  $myUtils->showMessageAndExit('');
1068  }
1069 
1070  $this->_processProduct($this->_oProduct);
1071  $this->_blIsInitialized = true;
1072  }
1073 
1079  public function getDefaultSorting()
1080  {
1081  $aSorting = parent::getDefaultSorting();
1082 
1083  $oCategory = $this->getActiveCategory();
1084 
1085  if ($this->getListType() != 'search' && $oCategory && $oCategory instanceof oxCategory) {
1086  if ($sSortBy = $oCategory->getDefaultSorting()) {
1087  $sSortDir = ($oCategory->getDefaultSortingMode()) ? "desc" : "asc";
1088  $aSorting = array('sortby' => $sSortBy, 'sortdir' => $sSortDir);
1089  }
1090  }
1091 
1092  return $aSorting;
1093  }
1094 }