00001 <?php
00002
00003
00004 define( 'OXARTICLE_LINKTYPE_CATEGORY', 0 );
00005 define( 'OXARTICLE_LINKTYPE_VENDOR', 1 );
00006 define( 'OXARTICLE_LINKTYPE_MANUFACTURER', 2 );
00007 define( 'OXARTICLE_LINKTYPE_PRICECATEGORY', 3 );
00008 define( 'OXARTICLE_LINKTYPE_TAG', 4 );
00009 define( 'OXARTICLE_LINKTYPE_RECOMM', 5 );
00010
00017 class oxArticle extends oxI18n implements oxIArticle, oxIUrl
00018 {
00024 protected $_sClassName = 'oxarticle';
00025
00031 protected $_blUseLazyLoading = true;
00032
00038 protected $_sItemKey;
00039
00045 protected $_blCalcPrice = true;
00046
00051 protected $_oPrice = null;
00052
00053
00059 protected $_dVarMinPrice = null;
00060
00066 protected $_dVarMaxPrice = null;
00067
00073 protected $_dArticleVat = null;
00074
00080 protected $_aPersistParam = null;
00081
00087 protected $_blNotBuyable = false;
00088
00095 protected $_blLoadVariants = true;
00096
00102 protected $_aVariants = null;
00103
00109 protected $_aVariantsWithNotOrderables = null;
00110
00119 protected $_blNotBuyableParent = false;
00120
00121
00125 protected $_blHasVariants = false;
00126
00130 protected $_blHasMdVariants = false;
00131
00136 protected $_blIsOnComparisonList = false;
00137
00142 protected $_oUser = null;
00143
00149 protected $_blLoadPrice = true;
00150
00157 protected $_blSkipAbPrice = false;
00158
00165 protected $_fPricePerUnit = null;
00166
00170 protected $_blLoadParentData = false;
00171
00175 protected $_blSkipAssign = false;
00176
00182 protected $_blSkipDiscounts = null;
00183
00188 protected $_oAttributeList = null;
00189
00190
00196 protected $_blIsRangePrice = null;
00197
00203 protected $_aMediaUrls = null;
00204
00210 static protected $_aLoadedParents;
00211
00217 static protected $_aSelList;
00218
00224 protected $_aDispSelList;
00225
00231 protected $_blIsSeoObject = true;
00232
00238 protected $_oAmountPriceList = null;
00239
00248 protected $_iLinkType = 0;
00249
00255 protected $_aStdUrls = array();
00256
00262 protected $_aSeoUrls = array();
00263
00269 protected $_aSeoAddParams = array();
00270
00276 protected $_aStdAddParams = array();
00277
00283 protected $_sDynImageDir = null;
00284
00290 protected $_sMoreDetailLink = null;
00291
00297 protected $_sToBasketLink = null;
00298
00304 protected $_iStockStatus = null;
00305
00311 protected $_oTPrice = null;
00312
00318 protected $_oAmountPriceInfo = null;
00319
00325 protected $_dAmountPrice = null;
00326
00332 protected static $_aArticleManufacturers = array();
00333
00339 protected static $_aArticleVendors = array();
00340
00346 protected static $_aArticleCats = array();
00347
00353 protected $_aNonCopyParentFields = array('oxarticles__oxinsert',
00354 'oxarticles__oxtimestamp',
00355 'oxarticles__oxnid',
00356 'oxarticles__oxid',
00357 'oxarticles__oxparentid');
00358
00364 protected $_aCopyParentField = array('oxarticles__oxnonmaterial',
00365 'oxarticles__oxfreeshipping',
00366 'oxarticles__oxremindactive',
00367 'oxarticles__oxisdownloadable');
00368
00374 protected $_oMdVariants = null;
00375
00381 protected $_oLongDesc = null;
00382
00390 protected $_aVariantSelections = array();
00391
00396 protected static $_aSelections = array();
00397
00402 protected static $_aCategoryCache = null;
00403
00408 protected static $_blHasAmountPrice = null;
00409
00414 protected $_aArticleFiles = null;
00415
00416
00425 public function __construct($aParams = null)
00426 {
00427 if ( $aParams && is_array($aParams)) {
00428 foreach ( $aParams as $sParam => $mValue) {
00429 $this->$sParam = $mValue;
00430 }
00431 }
00432 parent::__construct();
00433 $this->init( 'oxarticles' );
00434 }
00435
00444 public function __get($sName)
00445 {
00446 $this->$sName = parent::__get($sName);
00447 if ( $this->$sName ) {
00448
00449 $this->_assignParentFieldValue($sName);
00450 }
00451
00452 return $this->$sName;
00453 }
00454
00463 public function __set( $sName, $sValue )
00464 {
00465 parent::__set( $sName, $sValue );
00466 }
00467
00475 public function setId( $sId = null )
00476 {
00477 $sId = parent::setId( $sId );
00478
00479
00480 $this->oxarticles__oxnid = $this->oxarticles__oxid;
00481
00482 return $sId;
00483 }
00484
00494 public function getActiveCheckQuery( $blForceCoreTable = null )
00495 {
00496 $sTable = $this->getViewName( $blForceCoreTable );
00497
00498
00499 $sQ = " $sTable.oxactive = 1 ";
00500
00501
00502 if ( $this->getConfig()->getConfigParam( 'blUseTimeCheck' ) ) {
00503 $sDate = date( 'Y-m-d H:i:s', oxRegistry::get("oxUtilsDate")->getTime() );
00504 $sQ = "( $sQ or ( $sTable.oxactivefrom < '$sDate' and $sTable.oxactiveto > '$sDate' ) ) ";
00505 }
00506
00507 return $sQ;
00508 }
00509
00523 public function getStockCheckQuery( $blForceCoreTable = null )
00524 {
00525 $myConfig = $this->getConfig();
00526 $sTable = $this->getViewName( $blForceCoreTable );
00527
00528 $sQ = "";
00529
00530
00531 if ( $myConfig->getConfigParam( 'blUseStock' ) ) {
00532 $sQ = " and ( $sTable.oxstockflag != 2 or ( $sTable.oxstock + $sTable.oxvarstock ) > 0 ) ";
00533
00534 if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) ) {
00535 $sTimeCheckQ = '';
00536 if ( $myConfig->getConfigParam( 'blUseTimeCheck' ) ) {
00537 $sDate = date( 'Y-m-d H:i:s', oxRegistry::get("oxUtilsDate")->getTime() );
00538 $sTimeCheckQ = " or ( art.oxactivefrom < '$sDate' and art.oxactiveto > '$sDate' )";
00539 }
00540 $sQ = " $sQ and IF( $sTable.oxvarcount = 0, 1, ( select 1 from $sTable as art where art.oxparentid=$sTable.oxid and ( art.oxactive = 1 $sTimeCheckQ ) and ( art.oxstockflag != 2 or art.oxstock > 0 ) limit 1 ) ) ";
00541 }
00542 }
00543
00544 return $sQ;
00545 }
00546
00558 public function getVariantsQuery( $blRemoveNotOrderables, $blForceCoreTable = null )
00559 {
00560 $sTable = $this->getViewName( $blForceCoreTable );
00561 $sQ = " and $sTable.oxparentid = '".$this->getId()."' ";
00562
00563
00564 if ( $this->getConfig()->getConfigParam( 'blUseStock' ) ) {
00565 $sQ .= " and ( $sTable.oxstock > 0 or ( $sTable.oxstock <= 0 and $sTable.oxstockflag != 2 ";
00566 if ( $blRemoveNotOrderables ) {
00567 $sQ .= " and $sTable.oxstockflag != 3 ";
00568 }
00569 $sQ .= " ) ) ";
00570 }
00571
00572 return $sQ;
00573 }
00574
00582 public function getSqlActiveSnippet( $blForceCoreTable = null )
00583 {
00584 $myConfig = $this->getConfig();
00585
00586
00587 $sQ = $this->getActiveCheckQuery( $blForceCoreTable );
00588
00589
00590 $sQ .= $this->getStockCheckQuery( $blForceCoreTable );
00591
00592
00593 return "( $sQ ) ";
00594 }
00595
00603 public function setSkipAssign($blSkipAssign)
00604 {
00605 $this->_blSkipAssign = $blSkipAssign;
00606 }
00607
00613 public function disablePriceLoad()
00614 {
00615 $this->_blLoadPrice = false;
00616 }
00617
00623 public function getItemKey()
00624 {
00625 return $this->_sItemKey;
00626 }
00627
00635 public function setItemKey($sItemKey)
00636 {
00637 $this->_sItemKey = $sItemKey;
00638 }
00639
00647 public function setNoVariantLoading( $blLoadVariants )
00648 {
00649 $this->_blLoadVariants = !$blLoadVariants;
00650 }
00651
00657 public function isBuyable()
00658 {
00659 if ($this->_blNotBuyableParent) {
00660 return false;
00661 }
00662
00663 return !$this->_blNotBuyable;
00664 }
00665
00671 public function getPersParams()
00672 {
00673 return $this->_aPersistParam;
00674 }
00675
00681 public function isOnComparisonList()
00682 {
00683 return $this->_blIsOnComparisonList;
00684 }
00685
00693 public function setOnComparisonList( $blOnList )
00694 {
00695 $this->_blIsOnComparisonList = $blOnList;
00696 }
00697
00705 public function setLoadParentData($blLoadParentData)
00706 {
00707 $this->_blLoadParentData = $blLoadParentData;
00708 }
00709
00719 public function setSkipAbPrice( $blSkipAbPrice = null )
00720 {
00721 $this->_blSkipAbPrice = $blSkipAbPrice;
00722 }
00723
00724
00732 public function isMultilingualField($sFieldName)
00733 {
00734 switch ($sFieldName) {
00735 case "oxlongdesc":
00736 case "oxtags":
00737 return true;
00738 }
00739
00740 return parent::isMultilingualField($sFieldName);
00741 }
00742
00748 public function isVisible()
00749 {
00750
00751
00752 if ( ( $blCanPreview = oxRegistry::getUtils()->canPreview() ) !== null ) {
00753 return $blCanPreview;
00754 }
00755
00756
00757 $sNow = date('Y-m-d H:i:s');
00758 if ( !$this->oxarticles__oxactive->value &&
00759 ( $this->oxarticles__oxactivefrom->value > $sNow ||
00760 $this->oxarticles__oxactiveto->value < $sNow
00761 )) {
00762 return false;
00763 }
00764
00765
00766 if ( $this->getConfig()->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstockflag->value == 2) {
00767 $iOnStock = $this->oxarticles__oxstock->value + $this->oxarticles__oxvarstock->value;
00768 if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
00769 $iOnStock += $this->getSession()->getBasketReservations()->getReservedAmount($this->getId());
00770 }
00771 if ( $iOnStock <= 0 ) {
00772 return false;
00773 }
00774 }
00775
00776 return true;
00777 }
00778
00787 public function assign( $aRecord )
00788 {
00789
00790 startProfile('articleAssign');
00791
00792
00793 parent::assign( $aRecord );
00794
00795 $this->oxarticles__oxnid = $this->oxarticles__oxid;
00796
00797
00798 if ($this->_blSkipAssign) {
00799 return;
00800 }
00801
00802 $this->_assignParentFieldValues();
00803 $this->_assignNotBuyableParent();
00804
00805
00806 $this->_assignStock();
00807 $this->_assignPersistentParam();
00808 $this->_assignDynImageDir();
00809 $this->_assignComparisonListFlag();
00810
00811
00812 stopProfile('articleAssign');
00813 }
00814
00815
00823 protected function _loadFromDb( $sOXID )
00824 {
00825 $sSelect = $this->buildSelectString( array( $this->getViewName().".oxid" => $sOXID ));
00826 $aData = oxDb::getDb( oxDb::FETCH_MODE_ASSOC )->getRow( $sSelect );
00827 return $aData;
00828 }
00829
00840 public function load( $sOXID )
00841 {
00842
00843 $this->_blNotBuyableParent = false;
00844
00845
00846 $aData = $this->_loadFromDb( $sOXID );
00847
00848 if ( $aData ) {
00849 $this->assign( $aData );
00850
00851 $this->oxarticles__oxinsert = new oxField(oxRegistry::get("oxUtilsDate")->formatDBDate( $this->oxarticles__oxinsert->value));
00852 $this->oxarticles__oxtimestamp = new oxField(oxRegistry::get("oxUtilsDate")->formatDBDate( $this->oxarticles__oxtimestamp->value));
00853 $this->_isLoaded = true;
00854 return true;
00855 }
00856
00857 return false;
00858 }
00859
00860
00868 public function addToRatingAverage( $iRating )
00869 {
00870 $dOldRating = $this->oxarticles__oxrating->value;
00871 $dOldCnt = $this->oxarticles__oxratingcnt->value;
00872 $this->oxarticles__oxrating->setValue(( $dOldRating * $dOldCnt + $iRating ) / ($dOldCnt + 1));
00873 $this->oxarticles__oxratingcnt->setValue($dOldCnt + 1);
00874 $dRating = ( $dOldRating * $dOldCnt + $iRating ) / ($dOldCnt + 1);
00875 $dRatingCnt = (int) ($dOldCnt + 1);
00876
00877 $oDb = oxDb::getDb();
00878 $oDb->execute( 'update oxarticles set oxarticles.oxrating = '.$dRating.',oxarticles.oxratingcnt = '.$dRatingCnt.', oxarticles.oxtimestamp = oxarticles.oxtimestamp where oxarticles.oxid = '.$oDb->quote( $this->getId() ) );
00879
00880 }
00881
00889 public function setRatingAverage( $iRating )
00890 {
00891 $this->oxarticles__oxrating = new oxField( $iRating );
00892 }
00893
00901 public function setRatingCount( $iRatingCnt )
00902 {
00903 $this->oxarticles__oxratingcnt = new oxField( $iRatingCnt );
00904 }
00905
00913 public function getArticleRatingAverage( $blIncludeVariants = false )
00914 {
00915 if ( !$blIncludeVariants ) {
00916 return round( $this->oxarticles__oxrating->value, 1);
00917 } else {
00918 $oRating = oxNew( 'oxRating' );
00919 return $oRating->getRatingAverage( $this->getId(), 'oxarticle', $this->_getVariantsIds() );
00920 }
00921 }
00922
00930 public function getArticleRatingCount( $blIncludeVariants = false )
00931 {
00932 if ( !$blIncludeVariants ) {
00933 return $this->oxarticles__oxratingcnt->value;
00934 } else {
00935 $oRating = oxNew( 'oxRating' );
00936 return $oRating->getRatingCount( $this->getId(), 'oxarticle', $this->_getVariantsIds() );
00937 }
00938 }
00939
00940
00946 public function getReviews()
00947 {
00948 $aIds = array($this->getId());
00949
00950 if ( $this->oxarticles__oxparentid->value ) {
00951 $aIds[] = $this->oxarticles__oxparentid->value;
00952 }
00953
00954
00955 if ( $this->getConfig()->getConfigParam( 'blShowVariantReviews' ) ) {
00956 $aAdd = $this->_getVariantsIds();
00957 if (is_array($aAdd)) {
00958 $aIds = array_merge($aIds, $aAdd);
00959 }
00960 }
00961
00962 $oReview = oxNew('oxreview');
00963 $oRevs = $oReview->loadList('oxarticle', $aIds);
00964
00965
00966 if ( $oRevs->count() < 1 ) {
00967 return null;
00968 }
00969
00970 return $oRevs;
00971 }
00972
00978 public function getCrossSelling()
00979 {
00980 $oCrosslist = oxNew( "oxarticlelist");
00981 $oCrosslist->loadArticleCrossSell($this->oxarticles__oxid->value);
00982 if ( $oCrosslist->count() ) {
00983 return $oCrosslist;
00984 }
00985 }
00986
00992 public function getAccessoires()
00993 {
00994 $myConfig = $this->getConfig();
00995
00996
00997 if ( !$myConfig->getConfigParam( 'bl_perfLoadAccessoires' ) ) {
00998 return;
00999 }
01000
01001 $oAcclist = oxNew( "oxarticlelist");
01002 $oAcclist->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofCrossellArticles' ));
01003 $oAcclist->loadArticleAccessoires($this->oxarticles__oxid->value);
01004
01005 if ( $oAcclist->count()) {
01006 return $oAcclist;
01007 }
01008 }
01009
01015 public function getSimilarProducts()
01016 {
01017
01018 $myConfig = $this->getConfig();
01019 if ( !$myConfig->getConfigParam( 'bl_perfLoadSimilar' ) ) {
01020 return;
01021 }
01022
01023 $sArticleTable = $this->getViewName();
01024
01025 $sAttribs = '';
01026 $iCnt = 0;
01027 $this->_getAttribsString($sAttribs, $iCnt);
01028
01029 if ( !$sAttribs) {
01030 return null;
01031 }
01032
01033 $aList = $this->_getSimList($sAttribs, $iCnt);
01034
01035 if ( count( $aList ) ) {
01036 uasort( $aList, 'cmpart');
01037
01038 $sSearch = $this->_generateSimListSearchStr($sArticleTable, $aList);
01039
01040 $oSimilarlist = oxNew( 'oxarticlelist' );
01041 $oSimilarlist->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofSimilarArticles' ));
01042 $oSimilarlist->selectString( $sSearch);
01043
01044 return $oSimilarlist;
01045 }
01046 }
01047
01053 public function getCustomerAlsoBoughtThisProducts()
01054 {
01055
01056 $myConfig = $this->getConfig();
01057 if ( !$myConfig->getConfigParam( 'bl_perfLoadCustomerWhoBoughtThis' ) ) {
01058 return;
01059 }
01060
01061
01062 $sQ = $this->_generateSearchStrForCustomerBought();
01063
01064 $oArticles = oxNew( 'oxarticlelist' );
01065 $oArticles->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofCustomerWhoArticles' ));
01066 $oArticles->selectString( $sQ );
01067 if ( $oArticles->count() ) {
01068 return $oArticles;
01069 }
01070 }
01071
01078 public function loadAmountPriceInfo()
01079 {
01080 $myConfig = $this->getConfig();
01081 if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice || !$this->_blCalcPrice || !$this->hasAmountPrice() ) {
01082 return array();
01083 }
01084
01085 if ( $this->_oAmountPriceInfo === null ) {
01086 $this->_oAmountPriceInfo = array();
01087 if ( count( ( $oAmPriceList = $this->_getAmountPriceList() ) ) ) {
01088 $this->_oAmountPriceInfo = $this->_fillAmountPriceList( $oAmPriceList );
01089 }
01090 }
01091 return $this->_oAmountPriceInfo;
01092 }
01093
01101 public function getSelectLists($sKeyPrefix = null)
01102 {
01103
01104
01105 $sKey = $this->getId();
01106 if ( isset( $sKeyPrefix ) ) {
01107 $sKey = $sKeyPrefix.'__'.$this->getId();
01108 }
01109
01110 if ( !isset( self::$_aSelList[$sKey] ) ) {
01111 $oDb = oxDb::getDb();
01112 $sSLViewName = getViewName( 'oxselectlist' );
01113
01114 $sQ = "select {$sSLViewName}.* from oxobject2selectlist join {$sSLViewName} on $sSLViewName.oxid=oxobject2selectlist.oxselnid
01115 where oxobject2selectlist.oxobjectid=%s order by oxobject2selectlist.oxsort";
01116
01117
01118 $oLists = oxNew( 'oxlist' );
01119 $oLists->init( 'oxselectlist' );
01120 $oLists->selectString( sprintf( $sQ, $oDb->quote( $this->getId() ) ) );
01121
01122
01123 if ( $oLists->count() == 0 && $this->oxarticles__oxparentid->value ) {
01124 $oLists->selectString( sprintf( $sQ, $oDb->quote( $this->oxarticles__oxparentid->value ) ) );
01125 }
01126
01127 $dVat = 0;
01128 if ( $this->getPrice() != null ) {
01129 $dVat = $this->getPrice()->getVat();
01130 }
01131
01132 $iCnt = 0;
01133 self::$_aSelList[$sKey] = array();
01134 foreach ( $oLists as $oSelectlist ) {
01135 self::$_aSelList[$sKey][$iCnt] = $oSelectlist->getFieldList( $dVat );
01136 self::$_aSelList[$sKey][$iCnt]['name'] = $oSelectlist->oxselectlist__oxtitle->value;
01137 $iCnt++;
01138 }
01139 }
01140 return self::$_aSelList[$sKey];
01141 }
01142
01150 protected function _hasAnyVariant( $blForceCoreTable = null )
01151 {
01152 $blHas = false;
01153 if ( ( $sId = $this->getId() ) ) {
01154 if ( $this->oxarticles__oxshopid->value == $this->getConfig()->getShopId() ) {
01155 $blHas = (bool) $this->oxarticles__oxvarcount->value;
01156 } else {
01157 $sArticleTable = $this->getViewName( $blForceCoreTable );
01158 $blHas = (bool) oxDb::getDb()->getOne( "select 1 from $sArticleTable where oxparentid='{$sId}'" );
01159 }
01160 }
01161 return $blHas;
01162 }
01163
01169 public function hasMdVariants()
01170 {
01171 return $this->_blHasMdVariants;
01172 }
01173
01183 public function getVariantSelections( $aFilterIds = null, $sActVariantId = null, $iLimit = 0 )
01184 {
01185
01186 $iLimit = (int) $iLimit;
01187 if ( !isset( $this->_aVariantSelections[$iLimit] ) ) {
01188 $this->_aVariantSelections[$iLimit] = false;
01189
01190 if ( $this->oxarticles__oxvarcount->value ) {
01191 $this->_aVariantSelections[$iLimit] = oxNew( "oxVariantHandler" )->buildVariantSelections( $this->oxarticles__oxvarname->getRawValue(), $this->getVariants(false), $aFilterIds, $sActVariantId, $iLimit );
01192 }
01193 }
01194
01195 return $this->_aVariantSelections[$iLimit];
01196 }
01197
01206 public function getSelections( $iLimit = null, $aFilter = null )
01207 {
01208 $sId = $this->getId() . ( (int) $iLimit );
01209 if ( !array_key_exists( $sId, self::$_aSelections ) ) {
01210
01211 $oDb = oxDb::getDb();
01212 $sSLViewName = getViewName( 'oxselectlist' );
01213
01214 $sQ = "select {$sSLViewName}.* from oxobject2selectlist join {$sSLViewName} on $sSLViewName.oxid=oxobject2selectlist.oxselnid
01215 where oxobject2selectlist.oxobjectid=%s order by oxobject2selectlist.oxsort";
01216
01217 if ( ( $iLimit = (int) $iLimit ) ) {
01218 $sQ .= " limit $iLimit ";
01219 }
01220
01221
01222 $dVat = 0;
01223 if ( ( $oPrice = $this->getPrice() ) != null ) {
01224 $dVat = $oPrice->getVat();
01225 }
01226
01227
01228 $oList = oxNew( 'oxlist' );
01229 $oList->init( 'oxselectlist' );
01230 $oList->getBaseObject()->setVat( $dVat );
01231 $oList->selectString( sprintf( $sQ, $oDb->quote( $this->getId() ) ) );
01232
01233
01234 if ( $oList->count() == 0 && $this->oxarticles__oxparentid->value ) {
01235 $oList->selectString( sprintf( $sQ, $oDb->quote( $this->oxarticles__oxparentid->value ) ) );
01236 }
01237
01238 self::$_aSelections[$sId] = $oList->count() ? $oList : false;
01239 }
01240
01241 if ( self::$_aSelections[$sId] ) {
01242
01243 $aFilter = ( $aFilter === null ) ? oxConfig::getParameter( "sel" ) : $aFilter;
01244 if ( $aFilter ) {
01245 $iSelIdx = 0;
01246 foreach ( self::$_aSelections[$sId] as $oSelection ) {
01247 if ( isset( $aFilter[$iSelIdx] ) ) {
01248 $oSelection->setActiveSelectionByIndex( $aFilter[$iSelIdx] );
01249 }
01250 $iSelIdx++;
01251 }
01252 }
01253 }
01254
01255 return self::$_aSelections[$sId];
01256 }
01257
01267 protected function _loadVariantList( $blSimple, $blRemoveNotOrderables = true, $blForceCoreTable = null )
01268 {
01269 $oVariants = array();
01270 if ( ( $sId = $this->getId() ) ) {
01271
01272 self::$_aLoadedParents[$sId] = $this;
01273
01274 $myConfig = $this->getConfig();
01275
01276 if ( !$this->_blLoadVariants ||
01277 ( !$this->isAdmin() && !$myConfig->getConfigParam( 'blLoadVariants') ) ||
01278 ( !$this->isAdmin() && !$this->oxarticles__oxvarcount->value ) ) {
01279 return $oVariants;
01280 }
01281
01282
01283 $sCacheKey = $blSimple ? "simple" : "full";
01284 if ( $blRemoveNotOrderables ) {
01285 if ( isset( $this->_aVariants[$sCacheKey] ) ) {
01286 return $this->_aVariants[$sCacheKey];
01287 } else {
01288 $this->_aVariants[$sCacheKey] = & $oVariants;
01289 }
01290 } elseif ( !$blRemoveNotOrderables ) {
01291 if ( isset( $this->_aVariantsWithNotOrderables[$sCacheKey] ) ) {
01292 return $this->_aVariantsWithNotOrderables[$sCacheKey];
01293 } else {
01294 $this->_aVariantsWithNotOrderables[$sCacheKey] = & $oVariants;
01295 }
01296 }
01297
01298 if ( ( $this->_blHasVariants = $this->_hasAnyVariant( $blForceCoreTable ) ) ) {
01299
01300
01301 if ( $blSimple ) {
01302 $oVariants = oxNew( 'oxsimplevariantlist' );
01303 $oVariants->setParent( $this );
01304 } else {
01305
01306 $oVariants = oxNew( 'oxarticlelist' );
01307 $oVariants->getBaseObject()->modifyCacheKey( '_variants' );
01308 }
01309
01310 startProfile("selectVariants");
01311 $blUseCoreTable = (bool) $blForceCoreTable;
01312 $oBaseObject = $oVariants->getBaseObject();
01313 $oBaseObject->setLanguage( $this->getLanguage() );
01314
01315
01316 $sArticleTable = $this->getViewName( $blUseCoreTable );
01317
01318 $sSelect = "select ".$oBaseObject->getSelectFields( $blUseCoreTable )." from $sArticleTable where " .
01319 $this->getActiveCheckQuery( $blUseCoreTable ) .
01320 $this->getVariantsQuery( $blRemoveNotOrderables, $blUseCoreTable ) .
01321 " order by $sArticleTable.oxsort";
01322
01323
01324 $oVariants->selectString( $sSelect );
01325
01326
01327 if ( $myConfig->getConfigParam( 'blUseMultidimensionVariants' ) ) {
01328 $oMdVariants = oxNew( "oxVariantHandler" );
01329 $this->_blHasMdVariants = $oMdVariants->isMdVariant( $oVariants->current() );
01330 }
01331 stopProfile("selectVariants");
01332 }
01333
01334
01335 if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && $this->_blHasVariants ) {
01336 $this->_blNotBuyableParent = true;
01337 }
01338
01339
01340 if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && count( $oVariants ) == 0 && $this->_blHasVariants ) {
01341 $this->_blNotBuyable = true;
01342 }
01343 }
01344
01345 return $oVariants;
01346 }
01347
01356 public function getFullVariants( $blRemoveNotOrderables = true, $blForceCoreTable = null )
01357 {
01358 return $this->_loadVariantList( false, $blRemoveNotOrderables, $blForceCoreTable );
01359 }
01360
01369 public function getVariants( $blRemoveNotOrderables = true, $blForceCoreTable = null )
01370 {
01371 return $this->_loadVariantList( $this->_isInList(), $blRemoveNotOrderables, $blForceCoreTable );
01372 }
01373
01379 public function getSimpleVariants()
01380 {
01381 if ( $this->oxarticles__oxvarcount->value) {
01382 return $this->getVariants();
01383 }
01384 }
01385
01394 public function getAdminVariants( $sLanguage = null )
01395 {
01396 $oVariants = oxNew( 'oxarticlelist');
01397 if ( ( $sId = $this->getId() ) ) {
01398
01399 $oBaseObj = $oVariants->getBaseObject();
01400
01401 if ( is_null( $sLanguage ) ) {
01402 $oBaseObj->setLanguage( oxRegistry::getLang()->getBaseLanguage() );
01403 } else {
01404 $oBaseObj->setLanguage( $sLanguage );
01405 }
01406
01407 $sSql = "select * from ".$oBaseObj->getViewName()." where oxparentid = '{$sId}' order by oxsort ";
01408 $oVariants->selectString( $sSql );
01409
01410
01411 if ( !$this->getConfig()->getConfigParam( 'blVariantParentBuyable' ) && ( $oVariants->count() > 0 ) ) {
01412
01413 $this->_blNotBuyableParent = true;
01414 }
01415 }
01416
01417 return $oVariants;
01418 }
01419
01427 public function getCategory()
01428 {
01429 $oCategory = oxNew( 'oxcategory' );
01430 $oCategory->setLanguage( $this->getLanguage() );
01431
01432
01433 $sOXID = $this->getId();
01434 if ( isset( $this->oxarticles__oxparentid->value ) && $this->oxarticles__oxparentid->value ) {
01435 $sOXID = $this->oxarticles__oxparentid->value;
01436 }
01437
01438 if ( $sOXID ) {
01439
01440 if ( !isset( $this->_aCategoryCache[ $sOXID ] ) ) {
01441 startPRofile( 'getCategory' );
01442 $oStr = getStr();
01443 $sWhere = $oCategory->getSqlActiveSnippet();
01444 $sSelect = $this->_generateSearchStr( $sOXID );
01445 $sSelect .= ( $oStr->strstr( $sSelect, 'where' )?' and ':' where ') . $sWhere . " order by oxobject2category.oxtime limit 1";
01446
01447
01448 if ( !$oCategory->assignRecord( $sSelect ) ) {
01449
01450 $sSelect = $this->_generateSearchStr( $sOXID, true );
01451 $sSelect .= ( $oStr->strstr( $sSelect, 'where' )?' and ':' where ') . $sWhere . " limit 1";
01452
01453
01454 if ( !$oCategory->assignRecord( $sSelect ) ) {
01455 $oCategory = null;
01456 }
01457 }
01458
01459 $this->_aCategoryCache[ $sOXID ] = $oCategory;
01460 stopPRofile( 'getCategory' );
01461 } else {
01462
01463 $oCategory = $this->_aCategoryCache[ $sOXID ];
01464 }
01465 }
01466
01467 return $oCategory;
01468 }
01469
01478 public function getCategoryIds( $blActCats = false, $blSkipCache = false )
01479 {
01480 $myConfig = $this->getConfig();
01481 if ( isset( self::$_aArticleCats[$this->getId()] ) && !$blSkipCache ) {
01482 return self::$_aArticleCats[$this->getId()];
01483 }
01484
01485
01486 $sOXID = $this->getId();
01487 if (isset( $this->oxarticles__oxparentid->value) && $this->oxarticles__oxparentid->value) {
01488 $sOXID = $this->oxarticles__oxparentid->value;
01489 }
01490
01491
01492 $sSql = $this->_getSelectCatIds( $sOXID, $blActCats );
01493 $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
01494 $rs = $oDb->select( $sSql );
01495
01496
01497 $aRet = array();
01498
01499 if ($rs != false && $rs->recordCount() > 0) {
01500 while (!$rs->EOF) {
01501 $aRet[] = $rs->fields['oxcatnid'];
01502 $rs->moveNext();
01503 }
01504 }
01505
01506
01507 $sSql = $this->getSqlForPriceCategories();
01508 $oDb->setFetchMode( oxDb::FETCH_MODE_ASSOC );
01509 $rs = $oDb->select( $sSql );
01510
01511 if ($rs != false && $rs->recordCount() > 0) {
01512 while (!$rs->EOF) {
01513
01514 if ( is_array( $rs->fields ) ) {
01515 $rs->fields = array_change_key_case( $rs->fields, CASE_LOWER );
01516 }
01517
01518
01519 if ( !$aRet[$rs->fields['oxid']] ) {
01520 $aRet[] = $rs->fields['oxid'];
01521 }
01522 $rs->moveNext();
01523 }
01524 }
01525
01526 return self::$_aArticleCats[$this->getId()] = $aRet;
01527 }
01528
01537 protected function _getSelectCatIds( $sOXID, $blActCats = false )
01538 {
01539 $sO2CView = $this->_getObjectViewName('oxobject2category');
01540 $sCatView = $this->_getObjectViewName('oxcategories');
01541 $sSelect = "select oxobject2category.oxcatnid as oxcatnid from $sO2CView as oxobject2category left join $sCatView as oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
01542 $sSelect .= 'where oxobject2category.oxobjectid='.oxDb::getDb()->quote($sOXID).' and oxcategories.oxid is not null and oxcategories.oxactive = 1 ';
01543 if ( $blActCats ) {
01544 $sSelect .= "and oxcategories.oxhidden = 0 and (select count(cats.oxid) from $sCatView as cats where cats.oxrootid = oxcategories.oxrootid and cats.oxleft < oxcategories.oxleft and cats.oxright > oxcategories.oxright and ( cats.oxhidden = 1 or cats.oxactive = 0 ) ) = 0 ";
01545 }
01546 $sSelect .= 'order by oxobject2category.oxtime ';
01547 return $sSelect;
01548 }
01549
01559 public function getVendor( $blShopCheck = true )
01560 {
01561 if ( ( $sVendorId = $this->getVendorId() ) ) {
01562 $oVendor = oxNew( 'oxvendor' );
01563 } elseif ( !$blShopCheck && $this->oxarticles__oxvendorid->value ) {
01564 $oVendor = oxNew( 'oxi18n' );
01565 $oVendor->init('oxvendor');
01566 $oVendor->setReadOnly( true );
01567 $sVendorId = $this->oxarticles__oxvendorid->value;
01568 }
01569 if ( $sVendorId && $oVendor->load( $sVendorId ) && $oVendor->oxvendor__oxactive->value ) {
01570
01571 return $oVendor;
01572 }
01573 return null;
01574 }
01575
01583 public function getVendorId( $blForceReload = false )
01584 {
01585 $sVendorId = false;
01586 if ( $this->oxarticles__oxvendorid->value ) {
01587 $sVendorId = $this->oxarticles__oxvendorid->value;
01588
01589 }
01590 return $sVendorId;
01591 }
01592
01600 public function getManufacturerId( $blForceReload = false )
01601 {
01602 $sManufacturerId = false;
01603 if ( $this->oxarticles__oxmanufacturerid->value ) {
01604
01605 $sManufacturerId = $this->oxarticles__oxmanufacturerid->value;
01606
01607 }
01608 return $sManufacturerId;
01609 }
01610
01620 public function getManufacturer( $blShopCheck = true )
01621 {
01622 $oManufacturer = oxNew( 'oxmanufacturer' );;
01623 if ( !( $sManufacturerId = $this->getManufacturerId() ) &&
01624 !$blShopCheck && $this->oxarticles__oxmanufacturerid->value ) {
01625 $oManufacturer->setReadOnly( true );
01626 $sManufacturerId = $this->oxarticles__oxmanufacturerid->value;
01627 }
01628
01629 if ( $sManufacturerId && $oManufacturer->load( $sManufacturerId ) ) {
01630 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadManufacturerTree' ) ) {
01631 $oManufacturer->setReadOnly( true );
01632 }
01633 $oManufacturer = $oManufacturer->oxmanufacturers__oxactive->value ? $oManufacturer : null;
01634 } else {
01635 $oManufacturer = null;
01636 }
01637
01638 return $oManufacturer;
01639 }
01640
01648 public function inCategory( $sCatNid)
01649 {
01650 return in_array( $sCatNid, $this->getCategoryIds());
01651 }
01652
01661 public function isAssignedToCategory( $sCatId )
01662 {
01663
01664 $sOXID = $this->getId();
01665 if ( isset( $this->oxarticles__oxparentid->value) && $this->oxarticles__oxparentid->value) {
01666 $sOXID = $this->oxarticles__oxparentid->value;
01667 }
01668
01669 $oDb = oxDb::getDb();
01670 $sSelect = $this->_generateSelectCatStr( $sOXID, $sCatId);
01671 $sOXID = $oDb->getOne( $sSelect );
01672
01673 if ( isset( $sOXID) && $sOXID) {
01674 return true;
01675 }
01676
01677
01678 if ( $this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) && $this->_blLoadPrice ) {
01679 $dPriceFromTo = $this->getPrice()->getBruttoPrice();
01680 if ( $dPriceFromTo > 0) {
01681 $sSelect = $this->_generateSelectCatStr( $sOXID, $sCatId, $dPriceFromTo);
01682 $sOXID = $oDb->getOne( $sSelect );
01683
01684 if ( isset( $sOXID) && $sOXID) {
01685 return true;
01686 }
01687 }
01688 }
01689 return false;
01690 }
01691
01697 public function getTPrice()
01698 {
01699 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
01700 return;
01701 }
01702
01703
01704 if ( $this->_oTPrice !== null ) {
01705 return $this->_oTPrice;
01706 }
01707
01708 $oPrice = $this->_getPriceObject();
01709
01710 $dBasePrice = $this->oxarticles__oxtprice->value;
01711 $dBasePrice = $this->_preparePrice( $dBasePrice, $this->getArticleVat() );
01712
01713 $oPrice->setPrice( $dBasePrice );
01714
01715 $this->_applyVat( $oPrice, $this->getArticleVat() );
01716 $this->_applyCurrency( $oPrice );
01717
01718 $this->_oTPrice = $oPrice;
01719
01720 return $this->_oTPrice;
01721 }
01722
01728 public function skipDiscounts()
01729 {
01730
01731 if ( $this->_blSkipDiscounts !== null ) {
01732 return $this->_blSkipDiscounts;
01733 }
01734
01735 if ( $this->oxarticles__oxskipdiscounts->value ) {
01736 return true;
01737 }
01738
01739
01740 $this->_blSkipDiscounts = false;
01741 if ( oxRegistry::get("oxDiscountList")->hasSkipDiscountCategories() ) {
01742
01743 $oDb = oxDb::getDb();
01744 $sO2CView = getViewName( 'oxobject2category', $this->getLanguage() );
01745 $sViewName = getViewName( 'oxcategories', $this->getLanguage() );
01746 $sSelect = "select 1 from $sO2CView as $sO2CView left join {$sViewName} on {$sViewName}.oxid = $sO2CView.oxcatnid
01747 where $sO2CView.oxobjectid=".$oDb->quote( $this->getId() )." and {$sViewName}.oxactive = 1 and {$sViewName}.oxskipdiscounts = '1' ";
01748 $this->_blSkipDiscounts = ( $oDb->getOne( $sSelect ) == 1 );
01749 }
01750
01751 return $this->_blSkipDiscounts;
01752 }
01753
01761 public function setPrice(oxPrice $oPrice)
01762 {
01763 $this->_oPrice = $oPrice;
01764 }
01765
01774 public function getBasePrice( $dAmount = 1 )
01775 {
01776
01777
01778
01779
01780 $myConfig = $this->getConfig();
01781 if( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice )
01782 return;
01783
01784
01785 $dPrice = $this->_getAmountPrice( $dAmount );
01786
01787
01788 return $dPrice;
01789 }
01790
01798 public function getPrice( $dAmount = 1 )
01799 {
01800 $myConfig = $this->getConfig();
01801
01802 if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
01803 return;
01804 }
01805
01806
01807 if ( $dAmount != 1 || $this->_oPrice === null ) {
01808
01809
01810 $dBasePrice = $this->getBasePrice( $dAmount );
01811 $dBasePrice = $this->_preparePrice( $dBasePrice, $this->getArticleVat() );
01812
01813 $oPrice = $this->_getPriceObject();
01814
01815 $oPrice->setPrice( $dBasePrice );
01816
01817
01818 if ( !$this->_blCalcPrice && $dAmount == 1 ) {
01819 return $this->_oPrice = $oPrice;
01820 }
01821
01822 $this->_calculatePrice( $oPrice );
01823 if ( $dAmount != 1 ) {
01824 return $oPrice;
01825 }
01826
01827 $this->_oPrice = $oPrice;
01828 }
01829 return $this->_oPrice;
01830 }
01831
01840 protected function _calculatePrice( $oPrice, $dVat = null )
01841 {
01842
01843 if ( isset( $dVat ) || !$this->getConfig()->getConfigParam( 'bl_perfCalcVatOnlyForBasketOrder' ) ) {
01844 $this->_applyVAT( $oPrice, isset( $dVat ) ? $dVat : $this->getArticleVat() );
01845 }
01846
01847
01848 $this->_applyCurrency( $oPrice );
01849
01850 if ( !$this->skipDiscounts() ) {
01851 $oDiscountList = oxRegistry::get("oxDiscountList");
01852 $aDiscounts = $oDiscountList->getArticleDiscounts( $this, $this->getArticleUser() );
01853
01854 reset( $aDiscounts );
01855 foreach ( $aDiscounts as $oDiscount ) {
01856 $oPrice->setDiscount($oDiscount->getAddSum(), $oDiscount->getAddSumType());
01857 }
01858 $oPrice->calculateDiscount();
01859 }
01860
01861 return $oPrice;
01862 }
01863
01871 public function setArticleUser($oUser)
01872 {
01873 $this->_oUser = $oUser;
01874 }
01875
01881 public function getArticleUser()
01882 {
01883 if ($this->_oUser) {
01884 return $this->_oUser;
01885 }
01886 return $this->getUser();
01887 }
01888
01898 public function getBasketPrice( $dAmount, $aSelList, $oBasket )
01899 {
01900 $oUser = $oBasket->getBasketUser();
01901 $this->setArticleUser( $oUser );
01902
01903 $oBasketPrice = $this->_getPriceObject( $oBasket->isCalculationModeNetto() );
01904
01905
01906 $dBasePrice = $this->getBasePrice( $dAmount );
01907 $dBasePrice = $this->_preparePrice( $dBasePrice, $this->getArticleVat(), $oBasket->isCalculationModeNetto() );
01908
01909
01910 $dBasePrice = $this->_modifySelectListPrice( $dBasePrice, $aSelList );
01911
01912
01913 $oBasketPrice->setPrice( $dBasePrice );
01914
01915 $dVat = oxRegistry::get("oxVatSelector")->getBasketItemVat( $this, $oBasket );
01916 $this->_calculatePrice( $oBasketPrice, $dVat );
01917
01918
01919 return $oBasketPrice;
01920 }
01921
01930 public function delete( $sOXID = null )
01931 {
01932 if ( !$sOXID ) {
01933 $sOXID = $this->getId();
01934 }
01935 if ( !$sOXID ) {
01936 return false;
01937 }
01938
01939
01940
01941
01942 $this->_deleteVariantRecords( $sOXID );
01943 $this->load( $sOXID );
01944 $this->_deletePics();
01945 $this->_onChangeResetCounts( $sOXID, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
01946
01947
01948 parent::delete( $sOXID );
01949
01950 $rs = $this->_deleteRecords( $sOXID );
01951
01952 oxRegistry::get("oxSeoEncoderArticle")->onDeleteArticle($this);
01953
01954 $this->onChange( ACTION_DELETE, $sOXID, $this->oxarticles__oxparentid->value );
01955
01956 return $rs->EOF;
01957 }
01958
01967 public function reduceStock($dAmount, $blAllowNegativeStock = false)
01968 {
01969 $this->beforeUpdate();
01970
01971 $iStockCount = $this->oxarticles__oxstock->value - $dAmount;
01972 if (!$blAllowNegativeStock && ($iStockCount < 0)) {
01973 $dAmount += $iStockCount;
01974 $iStockCount = 0;
01975 }
01976 $this->oxarticles__oxstock = new oxField($iStockCount);
01977
01978 $oDb = oxDb::getDb();
01979 $oDb->execute( 'update oxarticles set oxarticles.oxstock = '.$oDb->quote( $iStockCount ).' where oxarticles.oxid = '.$oDb->quote( $this->getId() ) );
01980 $this->onChange( ACTION_UPDATE_STOCK );
01981 return $dAmount;
01982 }
01983
01992 public function updateSoldAmount( $dAmount = 0 )
01993 {
01994 if ( !$dAmount ) {
01995 return;
01996 }
01997
01998 $this->beforeUpdate();
01999
02000
02001 if ( !$this->oxarticles__oxparentid->value ) {
02002
02003 $dAmount = (double) $dAmount;
02004 $oDb = oxDb::getDb();
02005 $rs = $oDb->execute( "update oxarticles set oxarticles.oxsoldamount = oxarticles.oxsoldamount + $dAmount where oxarticles.oxid = ".$oDb->quote($this->oxarticles__oxid->value));
02006 } elseif ( $this->oxarticles__oxparentid->value) {
02007
02008 $oUpdateArticle = oxNewArticle( $this->oxarticles__oxparentid->value );
02009 $oUpdateArticle->updateSoldAmount( $dAmount );
02010 }
02011
02012 $this->onChange( ACTION_UPDATE );
02013
02014 return $rs;
02015 }
02016
02022 public function disableReminder()
02023 {
02024 $oDb = oxDb::getDb();
02025 return $oDb->execute( "update oxarticles set oxarticles.oxremindactive = 2 where oxarticles.oxid = ".$oDb->quote($this->oxarticles__oxid->value));
02026 }
02027
02033 public function save()
02034 {
02035 if ( ( $blRet = parent::save() ) ) {
02036
02037 $this->_saveArtLongDesc();
02038 }
02039
02040 return $blRet;
02041 }
02042
02043
02050 public function getPictureGallery()
02051 {
02052 $myConfig = $this->getConfig();
02053
02054
02055 $blMorePic = false;
02056 $aArtPics = array();
02057 $aArtIcons = array();
02058 $iActPicId = 1;
02059 $sActPic = $this->getPictureUrl( $iActPicId );
02060
02061 if ( oxConfig::getParameter( 'actpicid' ) ) {
02062 $iActPicId = oxConfig::getParameter('actpicid');
02063 }
02064
02065 $oStr = getStr();
02066 $iCntr = 0;
02067 $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
02068 $blCheckActivePicId = true;
02069
02070 for ( $i = 1; $i <= $iPicCount; $i++) {
02071 $sPicVal = $this->getPictureUrl( $i );
02072 $sIcoVal = $this->getIconUrl( $i );
02073 if ( !$oStr->strstr($sIcoVal, 'nopic_ico.jpg') && !$oStr->strstr($sIcoVal, 'nopic.jpg') &&
02074 !$oStr->strstr($sPicVal, 'nopic_ico.jpg') && !$oStr->strstr($sPicVal, 'nopic.jpg') ) {
02075 if ($iCntr) {
02076 $blMorePic = true;
02077 }
02078 $aArtIcons[$i]= $sIcoVal;
02079 $aArtPics[$i]= $sPicVal;
02080 $iCntr++;
02081
02082 if ($iActPicId == $i) {
02083 $sActPic = $sPicVal;
02084 $blCheckActivePicId = false;
02085 }
02086
02087 } else if ( $blCheckActivePicId && $iActPicId <= $i) {
02088
02089
02090 $iActPicId++;
02091 }
02092 }
02093
02094 $blZoomPic = false;
02095 $aZoomPics = array();
02096 $iZoomPicCount = $myConfig->getConfigParam( 'iPicCount' );
02097
02098 for ( $j = 1,$c = 1; $j <= $iZoomPicCount; $j++) {
02099 $sVal = $this->getZoomPictureUrl($j);
02100
02101 if ( $sVal && !$oStr->strstr($sVal, 'nopic.jpg')) {
02102 $blZoomPic = true;
02103 $aZoomPics[$c]['id'] = $c;
02104 $aZoomPics[$c]['file'] = $sVal;
02105
02106 if (!$sVal) {
02107 $aZoomPics[$c]['file'] = "nopic.jpg";
02108 }
02109 $c++;
02110 }
02111 }
02112
02113 $aPicGallery = array('ActPicID' => $iActPicId,
02114 'ActPic' => $sActPic,
02115 'MorePics' => $blMorePic,
02116 'Pics' => $aArtPics,
02117 'Icons' => $aArtIcons,
02118 'ZoomPic' => $blZoomPic,
02119 'ZoomPics' => $aZoomPics);
02120
02121 return $aPicGallery;
02122 }
02123
02137 public function onChange($sAction = null, $sOXID = null, $sParentID = null)
02138 {
02139 $myConfig = $this->getConfig();
02140
02141 if (!isset($sOXID)) {
02142 if ( $this->getId()) {
02143 $sOXID = $this->getId();
02144 }
02145 if (!isset ($sOXID)) {
02146 $sOXID = $this->oxarticles__oxid->value;
02147 }
02148 if ($this->oxarticles__oxparentid->value) {
02149 $sParentID = $this->oxarticles__oxparentid->value;
02150 }
02151 }
02152 if (!isset($sOXID)) {
02153 return;
02154 }
02155
02156
02157 if ( $myConfig->getConfigParam( 'blUseStock' ) ) {
02158
02159
02160 if (!isset($sParentID)) {
02161 $oDb = oxDb::getDb();
02162 $sQ = 'select oxparentid from oxarticles where oxid = '.$oDb->quote($sOXID);
02163 $sParentID = $oDb->getOne( $sQ );
02164 }
02165
02166 if ($sParentID) {
02167 $this->_onChangeUpdateStock($sParentID);
02168 }
02169 }
02170
02171
02172 if ($sParentID) {
02173 $this->_onChangeUpdateVarCount($sParentID);
02174 }
02175
02176 $sId = ( $sParentID ) ? $sParentID : $sOXID;
02177 $this->_setVarMinMaxPrice( $sId );
02178
02179
02180
02181 if ( $sAction === ACTION_UPDATE_STOCK ) {
02182 $this->_onChangeStockResetCount( $sOXID );
02183 }
02184
02185 }
02186
02193 public function getCustomVAT()
02194 {
02195 if ( isset($this->oxarticles__oxvat->value) ) {
02196 return $this->oxarticles__oxvat->value;
02197 }
02198 }
02199
02208 public function checkForStock( $dAmount, $dArtStockAmount = 0 )
02209 {
02210 $myConfig = $this->getConfig();
02211 if ( !$myConfig->getConfigParam( 'blUseStock' ) ) {
02212 return true;
02213 }
02214
02215 $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
02216
02217 $sQ = 'select oxstock, oxstockflag from oxarticles where oxid = '.$oDb->quote( $this->getId() );
02218 $rs = $oDb->select( $sQ );
02219
02220 $iOnStock = 0;
02221 $iStockFlag = 0;
02222 if ( $rs !== false && $rs->recordCount() > 0 ) {
02223 $iOnStock = $rs->fields['oxstock'] - $dArtStockAmount;
02224 $iStockFlag = $rs->fields['oxstockflag'];
02225
02226
02227 if ( $iStockFlag == 1 || $iStockFlag == 4) {
02228 return true;
02229 }
02230 if ( !$myConfig->getConfigParam( 'blAllowUnevenAmounts' ) ) {
02231 $iOnStock = floor( $iOnStock );
02232 }
02233 }
02234 if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
02235 $iOnStock += $this->getSession()->getBasketReservations()->getReservedAmount($this->getId());
02236 }
02237 if ( $iOnStock >= $dAmount ) {
02238 return true;
02239 } else {
02240 if ( $iOnStock > 0 ) {
02241 return $iOnStock;
02242 } else {
02243 $oEx = oxNew( 'oxArticleInputException' );
02244 $oEx->setMessage( 'EXCEPTION_ARTICLE_ARTICELNOTBUYABLE' );
02245 oxRegistry::get("oxUtilsView")->addErrorToDisplay( $oEx );
02246 return false;
02247 }
02248 }
02249 }
02250
02251
02257 public function getLongDescription()
02258 {
02259 if ( $this->_oLongDesc === null ) {
02260
02261 $this->_oLongDesc = new oxField();
02262
02263
02264
02265 $sOxid = $this->getId();
02266 $sViewName = getViewName( 'oxartextends', $this->getLanguage() );
02267
02268 $oDb = oxDb::getDb();
02269 $sDbValue = $oDb->getOne( "select oxlongdesc from {$sViewName} where oxid = " . $oDb->quote( $sOxid ) );
02270
02271 if ( $sDbValue != false ) {
02272 $this->_oLongDesc->setValue( $sDbValue, oxField::T_RAW );
02273 } elseif ( $this->oxarticles__oxparentid->value ) {
02274 if ( !$this->isAdmin() || $this->_blLoadParentData ) {
02275 $this->_oLongDesc->setValue( $this->getParentArticle()->getLongDescription()->getRawValue(), oxField::T_RAW );
02276 }
02277 }
02278 }
02279 return $this->_oLongDesc;
02280 }
02281
02288 public function getLongDesc()
02289 {
02290 return oxRegistry::get("oxUtilsView")->parseThroughSmarty( $this->getLongDescription()->getRawValue(), $this->getId().$this->getLanguage(), null, true );
02291 }
02292
02300 public function setArticleLongDesc( $sDesc )
02301 {
02302
02303
02304 $this->_oLongDesc = new oxField( $sDesc, oxField::T_RAW );
02305 $this->oxarticles__oxlongdesc = new oxField( $sDesc, oxField::T_RAW );
02306 }
02307
02313 public function getAttributes()
02314 {
02315 if ( $this->_oAttributeList === null ) {
02316 $this->_oAttributeList = oxNew( 'oxattributelist' );
02317 $this->_oAttributeList->loadAttributes( $this->getId() );
02318 }
02319
02320 return $this->_oAttributeList;
02321 }
02322
02328 public function getAttributesDisplayableInBasket()
02329 {
02330 if ( $this->_oAttributeList === null ) {
02331 $this->_oAttributeList = oxNew( 'oxattributelist' );
02332 $this->_oAttributeList->loadAttributesDisplayableInBasket( $this->getId() );
02333 }
02334
02335 return $this->_oAttributeList;
02336 }
02337
02338
02347 public function appendLink( $sAddParams, $iLang = null )
02348 {
02349 if ( $sAddParams ) {
02350 if ( $iLang === null ) {
02351 $iLang = $this->getLanguage();
02352 }
02353
02354 $this->_aSeoAddParams[$iLang] = isset( $this->_aSeoAddParams[$iLang] ) ? $this->_aSeoAddParams[$iLang] . "&" : "";
02355 $this->_aSeoAddParams[$iLang] .= $sAddParams;
02356 }
02357 }
02358
02367 public function getBaseSeoLink( $iLang, $blMain = false )
02368 {
02369 $oEncoder = oxRegistry::get("oxSeoEncoderArticle");
02370 if ( !$blMain ) {
02371 return $oEncoder->getArticleUrl( $this, $iLang, $this->getLinkType() );
02372 }
02373 return $oEncoder->getArticleMainUrl( $this, $iLang );
02374 }
02375
02384 public function getLink( $iLang = null, $blMain = false )
02385 {
02386 if ( !oxRegistry::getUtils()->seoIsActive() ) {
02387 return $this->getStdLink( $iLang );
02388 }
02389
02390 if ( $iLang === null ) {
02391 $iLang = $this->getLanguage();
02392 }
02393
02394 $iLinkType = $this->getLinkType();
02395 if ( !isset( $this->_aSeoUrls[$iLang][$iLinkType] ) ) {
02396 $this->_aSeoUrls[$iLang][$iLinkType] = $this->getBaseSeoLink( $iLang, $blMain );
02397 }
02398
02399 $sUrl = $this->_aSeoUrls[$iLang][$iLinkType];
02400 if ( isset($this->_aSeoAddParams[$iLang])) {
02401 $sUrl .= ( ( strpos( $sUrl.$this->_aSeoAddParams[$iLang], '?' ) === false ) ? '?' : '&' ).$this->_aSeoAddParams[$iLang];
02402 }
02403
02404 return $sUrl;
02405 }
02406
02415 public function getMainLink( $iLang = null )
02416 {
02417 return $this->getLink( $iLang, true );
02418 }
02419
02427 public function setLinkType( $iType )
02428 {
02429
02430 $this->_sDetailLink = null;
02431
02432
02433 $this->_iLinkType = (int) $iType;
02434 }
02435
02441 public function getLinkType()
02442 {
02443 return $this->_iLinkType;
02444 }
02445
02454 public function appendStdLink( $sAddParams, $iLang = null )
02455 {
02456 if ( $sAddParams ) {
02457 if ( $iLang === null ) {
02458 $iLang = $this->getLanguage();
02459 }
02460
02461 $this->_aStdAddParams[$iLang] = isset( $this->_aStdAddParams[$iLang] ) ? $this->_aStdAddParams[$iLang] . "&" : "";
02462 $this->_aStdAddParams[$iLang] .= $sAddParams;
02463 }
02464 }
02465
02475 public function getBaseStdLink( $iLang, $blAddId = true, $blFull = true )
02476 {
02477 $sUrl = '';
02478 if ( $blFull ) {
02479
02480 $sUrl = $this->getConfig()->getShopUrl( $iLang, false );
02481 }
02482
02483 $sUrl .= "index.php?cl=details" . ( $blAddId ? "&anid=".$this->getId() : "" );
02484 return $sUrl . ( isset( $this->_aStdAddParams[$iLang] ) ? "&". $this->_aStdAddParams[$iLang] : "" );
02485 }
02486
02495 public function getStdLink( $iLang = null, $aParams = array() )
02496 {
02497 if ( $iLang === null ) {
02498 $iLang = $this->getLanguage();
02499 }
02500
02501 if ( !isset( $this->_aStdUrls[$iLang] ) ) {
02502 $this->_aStdUrls[$iLang] = $this->getBaseStdLink( $iLang );
02503 }
02504
02505 return oxRegistry::get("oxUtilsUrl")->processUrl( $this->_aStdUrls[$iLang], true, $aParams, $iLang );
02506 }
02507
02515 public function getStdTagLink( $sTag )
02516 {
02517 $sStdTagLink = $this->getConfig()->getShopHomeURL( $this->getLanguage(), false );
02518 return $sStdTagLink . "cl=details&anid=".$this->getId()."&listtype=tag&searchtag=".rawurlencode( $sTag );
02519 }
02520
02526 public function getTags()
02527 {
02528 $oDb = oxDb::getDb();
02529 $sViewName = getViewName( "oxartextends", $this->getLanguage() );
02530 $sQ = "select oxtags from {$sViewName} where oxid = ".$oDb->quote( $this->getId() );
02531 $oTagCloud = oxNew('oxtagcloud');
02532 return $oTagCloud->trimTags( $oDb->getOne( $sQ ) );
02533 }
02534
02542 public function saveTags($sTags)
02543 {
02544
02545 if ( !$this->allowDerivedUpdate() ) {
02546 return false;
02547 }
02548
02549
02550 $oTagCloud = oxNew( 'oxtagcloud' );
02551 $oTagCloud->resetTagCache();
02552 $sTags = oxDb::getInstance()->escapeString( $oTagCloud->prepareTags( $sTags ) );
02553 $oDb = oxDb::getDb();
02554
02555 $sTable = getLangTableName( 'oxartextends', $this->getLanguage() );
02556 $sLangSuffix = oxRegistry::getLang()->getLanguageTag($this->getLanguage());
02557 $sQ = "insert into {$sTable} (oxid, oxtags$sLangSuffix) value (".$oDb->quote( $this->getId() ).", '{$sTags}')
02558 on duplicate key update oxtags$sLangSuffix = '{$sTags}'";
02559 return $oDb->execute( $sQ );
02560 }
02561
02569 public function addTag($sTag)
02570 {
02571
02572 $oDb = oxDb::getDb();
02573
02574 $oTagCloud = oxNew('oxtagcloud');
02575 $oTagCloud->resetTagCache();
02576 $sTag = $oTagCloud->prepareTags($sTag);
02577 $sTagSeparator = $this->getConfig()->getConfigParam('sTagSeparator');
02578
02579 $sTable = getLangTableName( 'oxartextends', $this->getLanguage() );
02580 $sLangSuffix = oxRegistry::getLang()->getLanguageTag($this->getLanguage());
02581 if ( $oDb->getOne( "select {$sTable}.OXTAGS$sLangSuffix from {$sTable} where {$sTable}.OXID = ".$oDb->quote( $this->getId() ) ) ) {
02582 $sTailTag = $sTagSeparator . $sTag;
02583 } else {
02584 $sTailTag = $sTag;
02585 }
02586
02587 $sTag = oxDb::getInstance()->escapeString($sTag);
02588 $sTailTag = oxDb::getInstance()->escapeString($sTailTag);
02589
02590 $sTag = oxDb::getInstance()->escapeString($sTag);
02591 $sTailTag = oxDb::getInstance()->escapeString($sTailTag);
02592
02593 $sQ = "insert into {$sTable} ( {$sTable}.OXID, {$sTable}.OXTAGS$sLangSuffix) values (".$oDb->quote( $this->getId() ).", '{$sTag}')
02594 ON DUPLICATE KEY update {$sTable}.OXTAGS$sLangSuffix = CONCAT(TRIM({$sTable}.OXTAGS$sLangSuffix), '$sTailTag') ";
02595
02596 return $oDb->execute( $sQ );
02597 }
02598
02604 public function getMediaUrls()
02605 {
02606 if ( $this->_aMediaUrls === null ) {
02607 $this->_aMediaUrls = oxNew("oxlist");
02608 $this->_aMediaUrls->init("oxmediaurl");
02609 $this->_aMediaUrls->getBaseObject()->setLanguage( $this->getLanguage() );
02610
02611 $sViewName = getViewName( "oxmediaurls", $this->getLanguage() );
02612 $sQ = "select * from {$sViewName} where oxobjectid = '".$this->getId()."'";
02613 $this->_aMediaUrls->selectString($sQ);
02614 }
02615 return $this->_aMediaUrls;
02616 }
02617
02623 public function getDynImageDir()
02624 {
02625 return $this->_sDynImageDir;
02626 }
02627
02633 public function getDispSelList()
02634 {
02635 if ($this->_aDispSelList === null) {
02636 if ( $this->getConfig()->getConfigParam( 'bl_perfLoadSelectLists' ) && $this->getConfig()->getConfigParam( 'bl_perfLoadSelectListsInAList' ) ) {
02637 $this->_aDispSelList = $this->getSelectLists();
02638 }
02639 }
02640 return $this->_aDispSelList;
02641 }
02642
02648 public function getMoreDetailLink()
02649 {
02650 if ( $this->_sMoreDetailLink == null ) {
02651
02652
02653 $this->_sMoreDetailLink = $this->getConfig()->getShopHomeURL() . 'cl=moredetails';
02654
02655
02656 if ( $sActCat = oxConfig::getParameter( 'cnid' ) ) {
02657 $this->_sMoreDetailLink .= '&cnid='.$sActCat;
02658 }
02659 $this->_sMoreDetailLink .= '&anid='.$this->getId();
02660 $this->_sMoreDetailLink = $this->_sMoreDetailLink;
02661 }
02662
02663 return $this->_sMoreDetailLink;
02664 }
02665
02671 public function getToBasketLink()
02672 {
02673 if ( $this->_sToBasketLink == null ) {
02674 $myConfig = $this->getConfig();
02675
02676 if ( oxRegistry::getUtils()->isSearchEngine() ) {
02677 $this->_sToBasketLink = $this->getLink();
02678 } else {
02679
02680 $this->_sToBasketLink = $myConfig->getShopHomeURL();
02681
02682
02683 $sActClass = oxConfig::getParameter( 'cl' );
02684 if ( $sActClass == 'thankyou') {
02685 $sActClass = 'basket';
02686 }
02687 $this->_sToBasketLink .= 'cl='.$sActClass;
02688
02689
02690 if ( $sActCat = oxConfig::getParameter( 'cnid' ) ) {
02691 $this->_sToBasketLink .= '&cnid='.$sActCat;
02692 }
02693
02694 $this->_sToBasketLink .= '&fnc=tobasket&aid='.$this->getId().'&anid='.$this->getId();
02695
02696 if ( $sTpl = basename( oxConfig::getParameter( 'tpl' ) ) ) {
02697 $this->_sToBasketLink .= '&tpl='.$sTpl;
02698 }
02699 }
02700 }
02701
02702 return $this->_sToBasketLink;
02703 }
02704
02710 public function getStockStatus()
02711 {
02712 return $this->_iStockStatus;
02713 }
02714
02720 public function getDeliveryDate()
02721 {
02722 if ( $this->oxarticles__oxdelivery->value != '0000-00-00') {
02723 return oxRegistry::get("oxUtilsDate")->formatDBDate( $this->oxarticles__oxdelivery->value);
02724 }
02725 return false;
02726 }
02727
02733 public function getFTPrice()
02734 {
02735
02736 if ( $oPrice = $this->getTPrice() ) {
02737 if ( $dPrice = $this->_getPriceForView( $oPrice ) ) {
02738 return oxRegistry::getLang()->formatCurrency( $dPrice );
02739 }
02740 }
02741 }
02742
02748 public function getFPrice()
02749 {
02750 if ( $oPrice = $this->getPrice() ) {
02751 $dPrice = $this->_getPriceForView( $oPrice );
02752 return oxRegistry::getLang()->formatCurrency( $dPrice );
02753 }
02754 }
02755
02761 public function getFNetPrice()
02762 {
02763 if ( $oPrice = $this->getPrice() ) {
02764 return oxRegistry::getLang()->formatCurrency( $oPrice->getNettoPrice() );
02765 }
02766 }
02767
02775 public function getPricePerUnit()
02776 {
02777 return $this->getFUnitPrice();
02778 }
02779
02785 public function isParentNotBuyable()
02786 {
02787 return $this->_blNotBuyableParent;
02788 }
02789
02795 public function isNotBuyable()
02796 {
02797 return $this->_blNotBuyable;
02798 }
02799
02807 public function setBuyableState( $blBuyable = false )
02808 {
02809 $this->_blNotBuyable = !$blBuyable;
02810 }
02811
02819 public function setSelectlist( $aSelList )
02820 {
02821 $this->_aDispSelList = $aSelList;
02822 }
02823
02831 public function getPictureUrl( $iIndex = 1 )
02832 {
02833 if ( $iIndex ) {
02834 $sImgName = false;
02835 if ( !$this->_isFieldEmpty( "oxarticles__oxpic".$iIndex ) ) {
02836 $sImgName = basename( $this->{"oxarticles__oxpic$iIndex"}->value );
02837 }
02838
02839 $sSize = $this->getConfig()->getConfigParam( 'aDetailImageSizes' );
02840 return oxRegistry::get("oxPictureHandler")->getProductPicUrl( "product/{$iIndex}/", $sImgName, $sSize, 'oxpic'.$iIndex );
02841 }
02842 }
02843
02852 public function getIconUrl( $iIndex = 0 )
02853 {
02854 $sImgName = false;
02855 $sDirname = "product/1/";
02856 if ( $iIndex && !$this->_isFieldEmpty( "oxarticles__oxpic{$iIndex}" ) ) {
02857 $sImgName = basename( $this->{"oxarticles__oxpic$iIndex"}->value );
02858 $sDirname = "product/{$iIndex}/";
02859 } elseif ( !$this->_isFieldEmpty( "oxarticles__oxicon" ) ) {
02860 $sImgName = basename( $this->oxarticles__oxicon->value );
02861 $sDirname = "product/icon/";
02862 } elseif ( !$this->_isFieldEmpty( "oxarticles__oxpic1" ) ) {
02863 $sImgName = basename( $this->oxarticles__oxpic1->value );
02864 }
02865
02866 $sSize = $this->getConfig()->getConfigParam( 'sIconsize' );
02867 return oxRegistry::get("oxPictureHandler")->getProductPicUrl( $sDirname, $sImgName, $sSize, $iIndex );
02868 }
02869
02877 public function getThumbnailUrl( $bSsl = null )
02878 {
02879 $sImgName = false;
02880 $sDirname = "product/1/";
02881 if ( !$this->_isFieldEmpty( "oxarticles__oxthumb" ) ) {
02882 $sImgName = basename( $this->oxarticles__oxthumb->value );
02883 $sDirname = "product/thumb/";
02884 } elseif ( !$this->_isFieldEmpty( "oxarticles__oxpic1" ) ) {
02885 $sImgName = basename( $this->oxarticles__oxpic1->value );
02886 }
02887
02888 $sSize = $this->getConfig()->getConfigParam( 'sThumbnailsize' );
02889 return oxRegistry::get("oxPictureHandler")->getProductPicUrl( $sDirname, $sImgName, $sSize, 0, $bSsl );
02890 }
02891
02899 public function getZoomPictureUrl( $iIndex = '' )
02900 {
02901 $iIndex = (int) $iIndex;
02902 if ( $iIndex > 0 && !$this->_isFieldEmpty( "oxarticles__oxpic".$iIndex ) ) {
02903 $sImgName = basename( $this->{"oxarticles__oxpic".$iIndex}->value );
02904 $sSize = $this->getConfig()->getConfigParam( "sZoomImageSize" );
02905 return oxRegistry::get("oxPictureHandler")->getProductPicUrl( "product/{$iIndex}/", $sImgName, $sSize, 'oxpic'.$iIndex );
02906 }
02907 }
02908
02914 public function getFileUrl()
02915 {
02916 return $this->getConfig()->getPictureUrl( 'media/' );
02917 }
02918
02926 public function getPriceFromPrefix()
02927 {
02928 $sPricePrefix = '';
02929 if ( $this->_blIsRangePrice) {
02930 $sPricePrefix = oxLang::getInstance()->translateString('PRICE_FROM').' ';
02931 }
02932
02933 return $sPricePrefix;
02934 }
02935
02941 protected function _saveArtLongDesc()
02942 {
02943 $myConfig = $this->getConfig();
02944 $sShopId = $myConfig->getShopID();
02945 if (in_array("oxlongdesc", $this->_aSkipSaveFields)) {
02946 return;
02947 }
02948
02949 if ($this->_blEmployMultilanguage) {
02950 $sValue = $this->getLongDescription()->getRawValue();
02951 if ( $sValue !== null ) {
02952 $oArtExt = oxNew('oxI18n');
02953 $oArtExt->init('oxartextends');
02954 $oArtExt->setLanguage((int) $this->getLanguage());
02955 if (!$oArtExt->load($this->getId())) {
02956 $oArtExt->setId($this->getId());
02957 }
02958 $oArtExt->oxartextends__oxlongdesc = new oxField($sValue, oxField::T_RAW);
02959 $oArtExt->save();
02960 }
02961 } else {
02962 $oArtExt = oxNew('oxI18n');
02963 $oArtExt->setEnableMultilang(false);
02964 $oArtExt->init('oxartextends');
02965 $aObjFields = $oArtExt->_getAllFields(true);
02966 if (!$oArtExt->load($this->getId())) {
02967 $oArtExt->setId($this->getId());
02968 }
02969
02970 foreach ($aObjFields as $sKey => $sValue ) {
02971 if ( preg_match('/^oxlongdesc(_(\d{1,2}))?$/', $sKey) ) {
02972 $sField = $this->_getFieldLongName($sKey);
02973
02974 if (isset($this->$sField)) {
02975 $sLongDesc = null;
02976 if ($this->$sField instanceof oxField) {
02977 $sLongDesc = $this->$sField->getRawValue();
02978 } elseif (is_object($this->$sField)) {
02979 $sLongDesc = $this->$sField->value;
02980 }
02981 if (isset($sLongDesc)) {
02982 $sAEField = $oArtExt->_getFieldLongName($sKey);
02983 $oArtExt->$sAEField = new oxField($sLongDesc, oxField::T_RAW);
02984 }
02985 }
02986 }
02987 }
02988 $oArtExt->save();
02989 }
02990 }
02991
02997 protected function _skipSaveFields()
02998 {
02999 $myConfig = $this->getConfig();
03000
03001 $this->_aSkipSaveFields = array();
03002
03003 $this->_aSkipSaveFields[] = 'oxtimestamp';
03004
03005 $this->_aSkipSaveFields[] = 'oxinsert';
03006
03007 if ( !isset( $this->oxarticles__oxparentid->value) || $this->oxarticles__oxparentid->value == '') {
03008 $this->_aSkipSaveFields[] = 'oxparentid';
03009 }
03010
03011 }
03012
03022 protected function _mergeDiscounts( $aDiscounts, $aItemDiscounts)
03023 {
03024 foreach ( $aItemDiscounts as $sKey => $oDiscount ) {
03025
03026 if ( array_key_exists ($sKey, $aDiscounts) ) {
03027 $aDiscounts[$sKey]->dDiscount += $oDiscount->dDiscount;
03028 } else {
03029 $aDiscounts[$sKey] = $oDiscount;
03030 }
03031 }
03032 return $aDiscounts;
03033 }
03034
03040 protected function _getGroupPrice()
03041 {
03042 $sPriceSufix = $this->_getUserPriceSufix();
03043 $sVarName = oxarticles__oxprice.$sPriceSufix;
03044 $dPrice = $this->$sVarName->value;
03045
03046
03047 if ( $this->getConfig()->getConfigParam( 'blOverrideZeroABCPrices' ) && (double) $dPrice == 0 ) {
03048 $dPrice = $this->oxarticles__oxprice->value;
03049 }
03050
03051 return $dPrice;
03052 }
03053
03062 protected function _getAmountPrice($dAmount = 1)
03063 {
03064 $myConfig = $this->getConfig();
03065
03066 startProfile( "_getAmountPrice" );
03067
03068 $dPrice = $this->_getGroupPrice();
03069 $oAmtPrices = $this->_getAmountPriceList();
03070 foreach ($oAmtPrices as $oAmPrice) {
03071 if ($oAmPrice->oxprice2article__oxamount->value <= $dAmount
03072 && $dAmount <= $oAmPrice->oxprice2article__oxamountto->value
03073 && $dPrice > $oAmPrice->oxprice2article__oxaddabs->value ) {
03074 $dPrice = $oAmPrice->oxprice2article__oxaddabs->value;
03075 }
03076 }
03077
03078 stopProfile( "_getAmountPrice" );
03079 return $dPrice;
03080 }
03081
03090 protected function _modifySelectListPrice( $dPrice, $aChosenList = null )
03091 {
03092 $myConfig = $this->getConfig();
03093
03094 if ( $myConfig->getConfigParam( 'bl_perfLoadSelectLists' ) && $myConfig->getConfigParam( 'bl_perfUseSelectlistPrice' ) ) {
03095
03096 $aSelLists = $this->getSelectLists();
03097
03098 foreach ( $aSelLists as $key => $aSel) {
03099 if ( isset( $aChosenList[$key]) && isset($aSel[$aChosenList[$key]] ) ) {
03100 $oSel = $aSel[$aChosenList[$key]];
03101 if ( $oSel->priceUnit =='abs' ) {
03102 $dPrice += $oSel->price;
03103 } elseif ( $oSel->priceUnit =='%' ) {
03104 $dPrice += oxPrice::percent( $dPrice, $oSel->price );
03105 }
03106 }
03107 }
03108 }
03109 return $dPrice;
03110 }
03111
03112
03120 protected function _fillAmountPriceList($oAmPriceList)
03121 {
03122 $myConfig = $this->getConfig();
03123 $oLang = oxRegistry::getLang();
03124
03125
03126 foreach ($oAmPriceList as $sId => $oItem) {
03127
03128 $oItemPrice = $this->_getPriceObject();
03129 if ( $oItem->oxprice2article__oxaddabs->value ) {
03130
03131 $dBasePrice = $oItem->oxprice2article__oxaddabs->value;
03132 $dBasePrice = $this->_preparePrice( $dBasePrice, $this->getArticleVat() );
03133
03134 $oItemPrice->setPrice( $dBasePrice );
03135 $this->_calculatePrice( $oItemPrice );
03136
03137 } else {
03138 $dBasePrice = $this->_getGroupPrice();
03139 $dBasePrice = $this->_preparePrice( $dBasePrice, $this->getArticleVat() );
03140 $oItemPrice->setPrice( $dBasePrice );
03141 $oItemPrice->subtractPercent( $oItem->oxprice2article__oxaddperc->value );
03142 }
03143
03144
03145 $oAmPriceList[$sId]->fbrutprice = $oLang->formatCurrency( $this->_getPriceForView( $oItemPrice ) );
03146 }
03147
03148 return $oAmPriceList;
03149 }
03150
03151
03157 protected function _getVariantsIds()
03158 {
03159 $aSelect = array();
03160 if ( ( $sId = $this->getId() ) ) {
03161 $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
03162 $sQ = "select oxid from " . $this->getViewName( true ) . " where oxparentid = ".$oDb->quote( $sId )." and " .
03163 $this->getSqlActiveSnippet( true ) . " order by oxsort";
03164 $oRs = $oDb->select( $sQ );
03165 if ( $oRs != false && $oRs->recordCount() > 0 ) {
03166 while (!$oRs->EOF) {
03167 $aSelect[] = reset( $oRs->fields );
03168 $oRs->moveNext();
03169 }
03170 }
03171 }
03172 return $aSelect;
03173 }
03174
03180 public function getArticleVat()
03181 {
03182 if (!isset($this->_dArticleVat)) {
03183 $this->_dArticleVat = oxRegistry::get("oxVatSelector")->getArticleVat( $this );
03184 }
03185 return $this->_dArticleVat;
03186 }
03187
03196 protected function _applyVAT( oxPrice $oPrice, $dVat )
03197 {
03198 startProfile(__FUNCTION__);
03199 $oPrice->setVAT( $dVat );
03200 if ( ($dVat = oxRegistry::get("oxVatSelector")->getArticleUserVat($this)) !== false ) {
03201 $oPrice->setUserVat( $dVat );
03202 }
03203 stopProfile(__FUNCTION__);
03204 }
03205
03213 public function applyVats( oxPrice $oPrice )
03214 {
03215 $this->_applyVAT($oPrice, $this->getArticleVat() );
03216 }
03217
03225 public function applyDiscountsForVariant( $oPrice )
03226 {
03227
03228 if ( !$this->skipDiscounts() ) {
03229 $oDiscountList = oxRegistry::get("oxDiscountList");
03230 $aDiscounts = $oDiscountList->getArticleDiscounts( $this, $this->getArticleUser() );
03231
03232 reset( $aDiscounts );
03233 foreach ( $aDiscounts as $oDiscount ) {
03234 $oPrice->setDiscount($oDiscount->getAddSum(), $oDiscount->getAddSumType());
03235 }
03236 $oPrice->calculateDiscount();
03237 }
03238 }
03239
03248 protected function _applyCurrency(oxPrice $oPrice, $oCur = null )
03249 {
03250 if ( !$oCur ) {
03251 $oCur = $this->getConfig()->getActShopCurrencyObject();
03252 }
03253
03254 $oPrice->multiply($oCur->rate);
03255 }
03256
03257
03266 protected function _getAttribsString(&$sAttribs, &$iCnt)
03267 {
03268
03269 $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
03270 $sSelect = 'select oxattrid from oxobject2attribute where oxobject2attribute.oxobjectid='.$oDb->quote( $this->getId() );
03271 $sAttribs = '';
03272 $blSep = false;
03273 $rs = $oDb->select( $sSelect);
03274 $iCnt = 0;
03275 if ($rs != false && $rs->recordCount() > 0) {
03276 while (!$rs->EOF) {
03277 if ( $blSep) {
03278 $sAttribs .= ' or ';
03279 }
03280 $sAttribs .= 't1.oxattrid = '.$oDb->quote($rs->fields['oxattrid']).' ';
03281 $blSep = true;
03282 $iCnt++;
03283 $rs->moveNext();
03284 }
03285 }
03286 }
03287
03296 protected function _getSimList($sAttribs, $iCnt)
03297 {
03298 $myConfig = $this->getConfig();
03299 $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
03300
03301
03302 $iAttrPercent = $myConfig->getConfigParam( 'iAttributesPercent' )/100;
03303
03304 if ( !$iAttrPercent || $iAttrPercent < 0 || $iAttrPercent > 1) {
03305 $iAttrPercent = 0.70;
03306 }
03307
03308 $iHitMin = ceil( $iCnt * $iAttrPercent );
03309
03310
03311 $aList= array();
03312 $sSelect = "select oxobjectid, count(*) as cnt from oxobject2attribute as t1 where
03313 ( $sAttribs )
03314 and t1.oxobjectid != ".$oDb->quote( $this->oxarticles__oxid->value )."
03315 group by t1.oxobjectid having count(*) >= $iHitMin ";
03316
03317 $rs = $oDb->selectLimit( $sSelect, 20, 0 );
03318 if ($rs != false && $rs->recordCount() > 0) {
03319 while (!$rs->EOF) {
03320 $oTemp = new stdClass();
03321 $oTemp->cnt = $rs->fields['cnt'];
03322 $oTemp->id = $rs->fields['oxobjectid'];
03323 $aList[] = $oTemp;
03324 $rs->moveNext();
03325 }
03326 }
03327 return $aList;
03328 }
03329
03338 protected function _generateSimListSearchStr($sArticleTable, $aList)
03339 {
03340 $myConfig = $this->getConfig();
03341 $sFieldList = $this->getSelectFields();
03342 $sSearch = "select $sFieldList from $sArticleTable where ".$this->getSqlActiveSnippet()." and $sArticleTable.oxissearch = 1 and $sArticleTable.oxid in ( ";
03343 $blSep = false;
03344 $iCnt = 0;
03345 $oDb = oxDb::getDb();
03346 foreach ( $aList as $oTemp) {
03347 if ( $blSep) {
03348 $sSearch .= ',';
03349 }
03350 $sSearch .= $oDb->quote($oTemp->id);
03351 $blSep = true;
03352 if ( $iCnt >= $myConfig->getConfigParam( 'iNrofSimilarArticles' ) ) {
03353 break;
03354 }
03355 $iCnt++;
03356 }
03357
03358
03359
03360 $sSearch .= ') ';
03361
03362
03363 $sSearch .= ' order by rand() ';
03364
03365 return $sSearch;
03366 }
03367
03376 protected function _generateSearchStr($sOXID, $blSearchPriceCat = false )
03377 {
03378
03379 $sCatView = getViewName( 'oxcategories', $this->getLanguage() );
03380 $sO2CView = getViewName( 'oxobject2category' );
03381
03382
03383 if ( !$blSearchPriceCat ) {
03384 $sSelect = "select {$sCatView}.* from {$sO2CView} as oxobject2category left join {$sCatView} on
03385 {$sCatView}.oxid = oxobject2category.oxcatnid
03386 where oxobject2category.oxobjectid=".oxDb::getDb()->quote($sOXID)." and {$sCatView}.oxid is not null ";
03387 } else {
03388 $sSelect = "select {$sCatView}.* from {$sCatView} where
03389 '{$this->oxarticles__oxprice->value}' >= {$sCatView}.oxpricefrom and
03390 '{$this->oxarticles__oxprice->value}' <= {$sCatView}.oxpriceto ";
03391 }
03392 return $sSelect;
03393 }
03394
03400 protected function _generateSearchStrForCustomerBought()
03401 {
03402 $sArtTable = $this->getViewName();
03403 $sOrderArtTable = getViewName( 'oxorderarticles' );
03404
03405
03406 $sIn = " '{$this->oxarticles__oxid->value}' ";
03407 if ( $this->oxarticles__oxparentid->value ) {
03408
03409
03410 $sIn .= ", '{$this->oxarticles__oxparentid->value}' ";
03411 $sParentIdForVariants = $this->oxarticles__oxparentid->value;
03412
03413 } else {
03414 $sParentIdForVariants = $this->getId();
03415 }
03416
03417
03418 $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
03419 $oRs = $oDb->select( "select oxid from {$sArtTable} where oxparentid = ".$oDb->quote($sParentIdForVariants)." and oxid != ".$oDb->quote($this->oxarticles__oxid->value) );
03420 if ( $oRs != false && $oRs->recordCount() > 0) {
03421 while ( !$oRs->EOF ) {
03422 $sIn .= ", ".$oDb->quote(current( $oRs->fields ))." ";
03423 $oRs->moveNext();
03424 }
03425 }
03426
03427 $iLimit = (int) $this->getConfig()->getConfigParam( 'iNrofCustomerWhoArticles' );
03428 $iLimit = $iLimit?( $iLimit * 10 ): 50;
03429
03430
03431 $sQ = "select distinct {$sArtTable}.* from (
03432 select d.oxorderid as suborderid from {$sOrderArtTable} as d use index ( oxartid ) where d.oxartid in ( {$sIn} ) limit {$iLimit}
03433 ) as suborder
03434 left join {$sOrderArtTable} force index ( oxorderid ) on suborder.suborderid = {$sOrderArtTable}.oxorderid
03435 left join {$sArtTable} on {$sArtTable}.oxid = {$sOrderArtTable}.oxartid
03436 where {$sArtTable}.oxid not in ( {$sIn} )
03437 and ( {$sArtTable}.oxissearch = 1 or {$sArtTable}.oxparentid <> '' ) and ".$this->getSqlActiveSnippet();
03438
03439
03440
03441
03442
03443
03444
03445
03446
03447
03448 return $sQ;
03449 }
03450
03460 protected function _generateSelectCatStr($sOXID, $sCatId, $dPriceFromTo = false)
03461 {
03462 $sCategoryView = getViewName('oxcategories');
03463 $sO2CView = getViewName('oxobject2category');
03464
03465 $oDb = oxDb::getDb();
03466 $sOXID = $oDb->quote($sOXID);
03467 $sCatId = $oDb->quote($sCatId);
03468
03469 if (!$dPriceFromTo) {
03470 $sSelect = "select oxobject2category.oxcatnid from $sO2CView as oxobject2category ";
03471 $sSelect .= "left join $sCategoryView as oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
03472 $sSelect .= "where oxobject2category.oxcatnid=$sCatId and oxobject2category.oxobjectid=$sOXID ";
03473 $sSelect .= "and oxcategories.oxactive = 1 order by oxobject2category.oxtime ";
03474 } else {
03475 $dPriceFromTo = $oDb->quote($dPriceFromTo);
03476 $sSelect = "select oxcategories.oxid from $sCategoryView as oxcategories where ";
03477 $sSelect .= "oxcategories.oxid=$sCatId and $dPriceFromTo >= oxcategories.oxpricefrom and ";
03478 $sSelect .= "$dPriceFromTo <= oxcategories.oxpriceto ";
03479 }
03480 return $sSelect;
03481 }
03482
03488 protected function _getAmountPriceList()
03489 {
03490 if ( $this->_oAmountPriceList === null ) {
03491 $this->_oAmountPriceList = array();
03492 if ( !$this->skipDiscounts() ) {
03493
03494
03495 $oAmPriceList = oxNew( 'oxAmountPricelist' );
03496 $oAmPriceList->load( $this );
03497
03498
03499 $oBasePrice = $this->_getGroupPrice();
03500 foreach ( $oAmPriceList as $oAmPrice ) {
03501 if ( $oAmPrice->oxprice2article__oxaddperc->value ) {
03502 $oAmPrice->oxprice2article__oxaddabs = new oxField(oxPrice::percent( $oBasePrice, 100 - $oAmPrice->oxprice2article__oxaddperc->value ), oxField::T_RAW );
03503 }
03504 }
03505
03506 $this->_oAmountPriceList = $oAmPriceList;
03507 }
03508 }
03509
03510 return $this->_oAmountPriceList;
03511 }
03512
03520 protected function _isFieldEmpty( $sFieldName )
03521 {
03522 $mValue = $this->$sFieldName->value;
03523
03524 if ( is_null( $mValue ) ) {
03525 return true;
03526 }
03527
03528 if ( $mValue === '' ) {
03529 return true;
03530 }
03531
03532 $aDoubleCopyFields = array('oxarticles__oxprice', 'oxarticles__oxvat');
03533
03534 if (!$mValue && in_array( $sFieldName, $aDoubleCopyFields ) ) {
03535 return true;
03536 }
03537
03538
03539 if (!strcmp($mValue, '0000-00-00 00:00:00') || !strcmp($mValue, '0000-00-00')) {
03540 return true;
03541 }
03542
03543 $sFieldName = strtolower($sFieldName);
03544
03545 if ( $sFieldName == 'oxarticles__oxicon' && ( strpos($mValue, "nopic_ico.jpg") !== false || strpos($mValue, "nopic.jpg") !== false ) ) {
03546 return true;
03547 }
03548
03549 if ( strpos($mValue, "nopic.jpg") !== false && ($sFieldName == 'oxarticles__oxthumb' || substr($sFieldName, 0, 17) == 'oxarticles__oxpic' || substr($sFieldName, 0, 18) == 'oxarticles__oxzoom') ) {
03550 return true;
03551 }
03552
03553 return false;
03554 }
03555
03563 protected function _assignParentFieldValue($sFieldName)
03564 {
03565 if (!($oParentArticle = $this->getParentArticle())) {
03566 return;
03567 }
03568
03569 $sCopyFieldName = $this->_getFieldLongName($sFieldName);
03570
03571
03572 if ( $oParentArticle->$sCopyFieldName != null ) {
03573
03574
03575 if ( substr( $sCopyFieldName, 0, 12) != 'oxarticles__') {
03576 return;
03577 }
03578
03579
03580 if (in_array($sCopyFieldName, $this->_aNonCopyParentFields)) {
03581 return;
03582 }
03583
03584
03585
03586 if ( stristr($sCopyFieldName, '_oxthumb') || stristr($sCopyFieldName, '_oxicon') ) {
03587 if ( $this->_isFieldEmpty( $sCopyFieldName ) && !$this->_hasMasterImage( 1 ) ) {
03588 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03589 }
03590 } elseif ( stristr($sCopyFieldName, '_oxzoom') ) {
03591
03592
03593 $iIndex = (int) str_ireplace( "oxarticles__oxzoom", "", $sFieldName );
03594 if ( $this->_isFieldEmpty( $sCopyFieldName ) && !$this->_hasMasterImage( $iIndex ) && !$this->_hasMasterImage( 1 ) ) {
03595 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03596 }
03597 } elseif ( stristr($sCopyFieldName, '_oxpicsgenerated') && $this->{$sCopyFieldName}->value == 0 ) {
03598
03599 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03600 } elseif ($this->_isFieldEmpty($sCopyFieldName) || in_array( $sCopyFieldName, $this->_aCopyParentField ) ) {
03601 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03602 }
03603 }
03604 }
03605
03611 public function getParentArticle()
03612 {
03613 if ( ( $sParentId = $this->oxarticles__oxparentid->value ) ) {
03614 $sIndex = $sParentId . "_" . $this->getLanguage();
03615 if ( !isset( self::$_aLoadedParents[$sIndex] ) ) {
03616 self::$_aLoadedParents[$sIndex] = oxNew( 'oxarticle' );
03617
03618 self::$_aLoadedParents[$sIndex]->_blLoadPrice = false;
03619 self::$_aLoadedParents[$sIndex]->_blLoadVariants = false;
03620 self::$_aLoadedParents[$sIndex]->loadInLang( $this->getLanguage(), $sParentId );
03621 }
03622 return self::$_aLoadedParents[$sIndex];
03623 }
03624 }
03625
03631 protected function _assignParentFieldValues()
03632 {
03633 startProfile('articleAssignParentInternal');
03634 if ( $this->oxarticles__oxparentid->value ) {
03635
03636 if ( !$this->isAdmin() || ( $this->_blLoadParentData && $this->isAdmin() ) ) {
03637 foreach ( $this->_aFieldNames as $sFieldName => $sVal ) {
03638 $this->_assignParentFieldValue( $sFieldName );
03639 }
03640 }
03641 }
03642 stopProfile('articleAssignParentInternal');
03643 }
03644
03650 protected function _assignNotBuyableParent()
03651 {
03652 if ( !$this->getConfig()->getConfigParam( 'blVariantParentBuyable' ) &&
03653 ($this->_blHasVariants || $this->oxarticles__oxvarstock->value || $this->oxarticles__oxvarcount->value )) {
03654 $this->_blNotBuyableParent = true;
03655
03656 }
03657 }
03658
03664 protected function _assignStock()
03665 {
03666 $myConfig = $this->getConfig();
03667
03668
03669
03670
03671
03672 if (!$myConfig->getConfigParam( 'blAllowUnevenAmounts' ) && !$this->isAdmin() ) {
03673 $this->oxarticles__oxstock = new oxField((int) floor($this->oxarticles__oxstock->value));
03674 }
03675
03676 $this->_iStockStatus = 0;
03677
03678
03679 if ( $myConfig->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstockflag->value != 4) {
03680
03681 $iStock = $this->oxarticles__oxstock->value;
03682
03683 if ($this->_blNotBuyableParent) {
03684 $iStock = $this->oxarticles__oxvarstock->value;
03685 }
03686
03687
03688 if ( $iStock <= $myConfig->getConfigParam( 'sStockWarningLimit' ) && $iStock > 0) {
03689 $this->_iStockStatus = 1;
03690 }
03691
03692
03693 if ($iStock <= 0) {
03694 $this->_iStockStatus = -1;
03695 }
03696 }
03697
03698
03699
03700 if ( $myConfig->getConfigParam( 'blUseStock' ) && ($this->oxarticles__oxstockflag->value == 3 || $this->oxarticles__oxstockflag->value == 2)) {
03701 $iOnStock = $this->oxarticles__oxstock->value;
03702 if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
03703 $iOnStock += $this->getSession()->getBasketReservations()->getReservedAmount($this->getId());
03704 }
03705 if ($iOnStock <= 0) {
03706 $this->setBuyableState( false );
03707 }
03708 }
03709
03710
03711 if ($this->_blNotBuyable && $this->oxarticles__oxvarstock->value ) {
03712 $this->setBuyableState( true );
03713
03714 $this->_blNotBuyableParent = true;
03715 }
03716
03717
03718
03719
03720 if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && !$myConfig->getConfigParam( 'blLoadVariants' ) && $this->oxarticles__oxvarstock->value) {
03721 $this->setBuyableState( false );
03722 }
03723
03724
03725 if (!$this->_blNotBuyable && $this->_blNotBuyableParent && $this->oxarticles__oxvarcount->value == 0) {
03726 $this->setBuyableState( false );
03727 }
03728 }
03729
03737 protected function _assignPrices()
03738 {
03739 $myConfig = $this->getConfig();
03740
03741
03742 if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
03743 return;
03744 }
03745
03746
03747 if ( $this->_hasAnyVariant() ) {
03748 $this->_applyRangePrice();
03749 }
03750 }
03751
03757 protected function _assignPersistentParam()
03758 {
03759
03760 $aPersParam = oxSession::getVar( 'persparam');
03761 if ( isset( $aPersParam) && isset( $aPersParam[$this->getId()])) {
03762 $this->_aPersistParam = $aPersParam[$this->getId()];
03763 }
03764 }
03765
03771 protected function _assignDynImageDir()
03772 {
03773 $myConfig = $this->getConfig();
03774
03775 $sThisShop = $this->oxarticles__oxshopid->value;
03776
03777 $this->_sDynImageDir = $myConfig->getPictureUrl( null, false );
03778 $this->dabsimagedir = $myConfig->getPictureDir( false );
03779 $this->nossl_dimagedir = $myConfig->getPictureUrl( null, false, false, null, $sThisShop );
03780 $this->ssl_dimagedir = $myConfig->getPictureUrl( null, false, true, null, $sThisShop );
03781 }
03782
03788 protected function _assignComparisonListFlag()
03789 {
03790
03791
03792 $aItems = oxSession::getVar('aFiltcompproducts');
03793 if ( isset( $aItems[$this->getId()])) {
03794 $this->_blIsOnComparisonList = true;
03795 }
03796 }
03797
03798
03806 protected function _insert()
03807 {
03808
03809 $sNow = date('Y-m-d H:i:s', oxRegistry::get("oxUtilsDate")->getTime());
03810 $this->oxarticles__oxinsert = new oxField( $sNow );
03811 $this->oxarticles__oxtimestamp = new oxField( $sNow );
03812 if ( !is_object($this->oxarticles__oxsubclass) || $this->oxarticles__oxsubclass->value == '') {
03813 $this->oxarticles__oxsubclass = new oxField('oxarticle');
03814 }
03815
03816 return parent::_insert();
03817 }
03818
03824 protected function _update()
03825 {
03826
03827 $this->_skipSaveFields();
03828
03829 $myConfig = $this->getConfig();
03830
03831
03832 $blRes = parent::_update();
03833
03834
03835 return $blRes;
03836 }
03837
03845 protected function _deleteRecords($sOXID)
03846 {
03847 $oDb = oxDb::getDb();
03848
03849 $sOXID = $oDb->quote($sOXID);
03850
03851
03852 $sDelete = 'delete from oxobject2article where oxarticlenid = '.$sOXID.' or oxobjectid = '.$sOXID.' ';
03853 $oDb->execute( $sDelete);
03854
03855 $sDelete = 'delete from oxobject2attribute where oxobjectid = '.$sOXID.' ';
03856 $oDb->execute( $sDelete);
03857
03858 $sDelete = 'delete from oxobject2category where oxobjectid = '.$sOXID.' ';
03859 $oDb->execute( $sDelete);
03860
03861 $sDelete = 'delete from oxobject2selectlist where oxobjectid = '.$sOXID.' ';
03862 $oDb->execute( $sDelete);
03863
03864 $sDelete = 'delete from oxprice2article where oxartid = '.$sOXID.' ';
03865 $oDb->execute( $sDelete);
03866
03867 $sDelete = 'delete from oxreviews where oxtype="oxarticle" and oxobjectid = '.$sOXID.' ';
03868 $oDb->execute( $sDelete);
03869
03870
03871
03872
03873 $sDelete = 'delete from oxaccessoire2article where oxobjectid = '.$sOXID.' or oxarticlenid = '.$sOXID.' ';
03874 $oDb->execute( $sDelete);
03875
03876
03877 $sDelete = 'delete from oxobject2delivery where oxobjectid = '.$sOXID.' and oxtype=\'oxarticles\' ';
03878 $oDb->execute( $sDelete);
03879
03880 $sDelete = 'delete from oxartextends where oxid = '.$sOXID.' ';
03881 $oDb->execute( $sDelete);
03882
03883
03884 foreach ( $this->_getLanguageSetTables( "oxartextends" ) as $sSetTbl ) {
03885 $oDb->execute( "delete from $sSetTbl where oxid = {$sOXID}" );
03886 }
03887
03888 $sDelete = 'delete from oxactions2article where oxartid = '.$sOXID.' ';
03889 $rs = $oDb->execute( $sDelete );
03890
03891 $sDelete = 'delete from oxobject2list where oxobjectid = '.$sOXID.' ';
03892 $rs = $oDb->execute( $sDelete );
03893
03894
03895 return $rs;
03896 }
03897
03905 protected function _deleteVariantRecords( $sOXID )
03906 {
03907 if ( $sOXID ) {
03908 $oDb = oxDb::getDb();
03909
03910 $sQ = 'select oxid from '.$this->getViewName().' where oxparentid = '.$oDb->quote( $sOXID );
03911 $rs = $oDb->select( $sQ, false, false );
03912 $oArticle = oxNew("oxArticle");
03913 if ($rs != false && $rs->recordCount() > 0) {
03914 while (!$rs->EOF) {
03915 $oArticle->setId($rs->fields[0]);
03916 $oArticle->delete();
03917 $rs->moveNext();
03918 }
03919 }
03920 }
03921 }
03922
03928 protected function _deletePics()
03929 {
03930 $myUtilsPic = oxRegistry::get("oxUtilsPic");
03931 $myConfig = $this->getConfig();
03932 $oPictureHandler = oxRegistry::get("oxPictureHandler");
03933
03934
03935 $oPictureHandler->deleteMainIcon( $this );
03936
03937
03938 $oPictureHandler->deleteThumbnail( $this );
03939
03940 $sAbsDynImageDir = $myConfig->getPictureDir(false);
03941
03942
03943 $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
03944 for ( $i = 1; $i <= $iPicCount; $i++ ) {
03945 $oPictureHandler->deleteArticleMasterPicture( $this, $i );
03946 }
03947 }
03948
03958 protected function _onChangeResetCounts( $sOxid, $sVendorId = null, $sManufacturerId = null )
03959 {
03960
03961 $myUtilsCount = oxRegistry::get("oxUtilsCount");
03962
03963 if ( $sVendorId ) {
03964 $myUtilsCount->resetVendorArticleCount( $sVendorId );
03965 }
03966
03967 if ( $sManufacturerId ) {
03968 $myUtilsCount->resetManufacturerArticleCount( $sManufacturerId );
03969 }
03970
03971
03972 $oDb = oxDb::getDb();
03973 $sQ = "select oxcatnid from oxobject2category where oxobjectid = ".$oDb->quote($sOxid);
03974 $oRs = $oDb->select( $sQ, false, false );
03975 if ( $oRs !== false && $oRs->recordCount() > 0) {
03976 while ( !$oRs->EOF ) {
03977 $myUtilsCount->resetCatArticleCount( $oRs->fields[0] );
03978 $oRs->moveNext();
03979 }
03980 }
03981 }
03982
03990 protected function _onChangeUpdateStock( $sParentID )
03991 {
03992 if ( $sParentID ) {
03993 $oDb = oxDb::getDb();
03994 $sParentIdQuoted = $oDb->quote($sParentID);
03995 $sQ = 'select oxstock, oxvendorid, oxmanufacturerid from oxarticles where oxid = '.$sParentIdQuoted;
03996 $rs = $oDb->select( $sQ, false, false );
03997 $iOldStock = $rs->fields[0];
03998 $iVendorID = $rs->fields[1];
03999 $iManufacturerID = $rs->fields[2];
04000
04001 $sQ = 'select sum(oxstock) from '.$this->getViewName(true).' where oxparentid = '.$sParentIdQuoted.' and '. $this->getSqlActiveSnippet( true ).' and oxstock > 0 ';
04002 $iStock = (float) $oDb->getOne( $sQ, false, false );
04003
04004 $sQ = 'update oxarticles set oxvarstock = '.$iStock.' where oxid = '.$sParentIdQuoted;
04005 $oDb->execute( $sQ );
04006
04007
04008
04009 if ( $iStock < 0 ) {
04010 $iStock = 0;
04011 }
04012 if ( $iOldStock < 0 ) {
04013 $iOldStock = 0;
04014 }
04015 if ( $this->oxarticles__oxstockflag->value == 2 && $iOldStock xor $iStock ) {
04016
04017
04018 $this->_onChangeResetCounts( $sParentID, $iVendorID, $iManufacturerID );
04019 }
04020 }
04021 }
04022
04030 protected function _onChangeStockResetCount( $sOxid )
04031 {
04032 $myConfig = $this->getConfig();
04033
04034 if ( $myConfig->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstockflag->value == 2 &&
04035 ( $this->oxarticles__oxstock->value + $this->oxarticles__oxvarstock->value ) <= 0 ) {
04036
04037 $this->_onChangeResetCounts( $sOxid, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
04038 }
04039 }
04040
04048 protected function _onChangeUpdateVarCount( $sParentID )
04049 {
04050 if ( $sParentID ) {
04051 $oDb = oxDb::getDb();
04052 $sParentIdQuoted = $oDb->quote( $sParentID );
04053 $sQ = "select count(*) as varcount from oxarticles where oxparentid = {$sParentIdQuoted}";
04054 $iVarCount = (int) $oDb->getOne( $sQ, false, false );
04055
04056 $sQ = "update oxarticles set oxvarcount = {$iVarCount} where oxid = {$sParentIdQuoted}";
04057 $oDb->execute( $sQ );
04058 }
04059 }
04060
04068 protected function _setVarMinMaxPrice( $sParentId )
04069 {
04070 if ( $sParentId ) {
04071 $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
04072 $sQ = '
04073 SELECT
04074 MIN(`oxprice`) AS `varminprice`,
04075 MAX(`oxprice`) AS `varmaxprice`
04076 FROM ' . $this->getViewName(true) . '
04077 WHERE ' .$this->getSqlActiveSnippet(true) . '
04078 AND ( `oxparentid` = ' . $oDb->quote( $sParentId ) . ')';
04079
04080 $aPrices = $oDb->getRow( $sQ, false, false );
04081
04082 if ( !is_null( $aPrices['varminprice'] ) || !is_null( $aPrices['varmaxprice'] ) ) {
04083 $sQ = '
04084 UPDATE `oxarticles`
04085 SET
04086 `oxvarminprice` = ' . $oDb->quote( $aPrices['varminprice'] ) .',
04087 `oxvarmaxprice` = ' . $oDb->quote( $aPrices['varmaxprice'] ) .'
04088 WHERE
04089 `oxid` = ' . $oDb->quote( $sParentId );
04090 } else {
04091 $sQ = '
04092 UPDATE `oxarticles`
04093 SET
04094 `oxvarminprice` = `oxprice`,
04095 `oxvarmaxprice` = `oxprice`
04096 WHERE
04097 `oxid` = ' . $oDb->quote( $sParentId );
04098 }
04099 $oDb->execute( $sQ );
04100 }
04101 }
04102
04103
04113 protected function _onChangeUpdateMinVarPrice( $sParentID )
04114 {
04115 if ( $sParentID ) {
04116 $oDb = oxDb::getDb();
04117 $sParentIdQuoted = $oDb->quote($sParentID);
04118
04119 $sQ = 'select min(oxprice) as varminprice from '.$this->getViewName(true).' where '.$this->getSqlActiveSnippet(true).' and (oxparentid = '.$sParentIdQuoted.')';
04120 $dVarMinPrice = $oDb->getOne( $sQ, false, false );
04121
04122 $dParentPrice = $oDb->getOne( "select oxprice from oxarticles where oxid = $sParentIdQuoted ", false, false );
04123
04124 $blParentBuyable = $this->getConfig()->getConfigParam( 'blVariantParentBuyable' );
04125
04126 if ($dVarMinPrice) {
04127 if ($blParentBuyable) {
04128 $dVarMinPrice = min($dVarMinPrice, $dParentPrice);
04129 }
04130 } else {
04131 $dVarMinPrice = $dParentPrice;
04132 }
04133
04134 if ( $dVarMinPrice ) {
04135 $sQ = 'update oxarticles set oxvarminprice = '.$dVarMinPrice.' where oxid = '.$sParentIdQuoted;
04136 $oDb->execute($sQ);
04137 }
04138 }
04139 }
04140
04141
04149 protected function _applyRangePrice()
04150 {
04151
04152 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
04153 return;
04154 }
04155
04156 $this->_blIsRangePrice = false;
04157
04158
04159 if ($this->_blSkipFromPrice || !$this->_blNotBuyableParent) {
04160 return;
04161 }
04162
04163 if ( $this->isParentNotBuyable() && !$this->getConfig()->getConfigParam( 'blLoadVariants' )) {
04164
04165 $dPrice = $this->_preparePrice( $this->oxarticles__oxvarminprice->value, $this->getArticleVat() );
04166 $this->getPrice()->setPrice($dPrice);
04167 $this->_blIsRangePrice = true;
04168 $this->_calculatePrice( $this->getPrice() );
04169 return;
04170
04171 }
04172
04173 $aPrices = array();
04174
04175 if (!$this->_blNotBuyableParent) {
04176 $aPrices[] = $this->getPrice()->getPrice();
04177 }
04178
04179 $aVariants = $this->getVariants(false);
04180
04181 if (count($aVariants)) {
04182 foreach ($aVariants as $sKey => $oVariant) {
04183 $aPrices[] = $oVariant->getPrice()->getPrice();
04184 }
04185 }
04186
04187 if ( count( $aPrices ) ) {
04188 $dMinPrice = min( $aPrices );
04189 $dMaxPrice = max( $aPrices );
04190 }
04191
04192 if ($this->_blNotBuyableParent && isset($dMinPrice) && $dMinPrice == $dMaxPrice) {
04193 $this->getPrice()->setPrice($dMinPrice);
04194 }
04195
04196 if (isset($dMinPrice) && $dMinPrice != $dMaxPrice) {
04197 $this->getPrice()->setPrice($dMinPrice);
04198 $this->_blIsRangePrice = true;
04199 }
04200 }
04201
04208 public function getProductId()
04209 {
04210 return $this->getId();
04211 }
04212
04220 public function getProductParentId()
04221 {
04222 return $this->getParentId();
04223 }
04224
04230 public function getParentId()
04231 {
04232 return $this->oxarticles__oxparentid->value;
04233 }
04234
04240 public function isOrderArticle()
04241 {
04242 return false;
04243 }
04244
04250 public function isVariant()
04251 {
04252 return (bool) ( isset( $this->oxarticles__oxparentid ) ? $this->oxarticles__oxparentid->value : false );
04253 }
04254
04260 public function isMdVariant()
04261 {
04262 $oMdVariant = oxNew( "oxVariantHandler" );
04263
04264 return $oMdVariant->isMdVariant($this);
04265 }
04266
04274 public function getSqlForPriceCategories($sFields = '')
04275 {
04276 if (!$sFields) {
04277 $sFields = 'oxid';
04278 }
04279 $sSelectWhere = "select $sFields from ".$this->_getObjectViewName('oxcategories')." where";
04280 $sQuotedPrice = oxDb::getDb()->quote( $this->oxarticles__oxprice->value );
04281 return "$sSelectWhere oxpricefrom != 0 and oxpriceto != 0 and oxpricefrom <= $sQuotedPrice and oxpriceto >= $sQuotedPrice"
04282 ." union $sSelectWhere oxpricefrom != 0 and oxpriceto = 0 and oxpricefrom <= $sQuotedPrice"
04283 ." union $sSelectWhere oxpricefrom = 0 and oxpriceto != 0 and oxpriceto >= $sQuotedPrice";
04284 }
04285
04293 public function inPriceCategory( $sCatNid )
04294 {
04295 $oDb = oxDb::getDb();
04296
04297 $sQuotedPrice = $oDb->quote( $this->oxarticles__oxprice->value );
04298 $sQuotedCnid = $oDb->quote( $sCatNid );
04299 return (bool) $oDb->getOne(
04300 "select 1 from ".$this->_getObjectViewName('oxcategories')." where oxid=$sQuotedCnid and"
04301 ."( (oxpricefrom != 0 and oxpriceto != 0 and oxpricefrom <= $sQuotedPrice and oxpriceto >= $sQuotedPrice)"
04302 ." or (oxpricefrom != 0 and oxpriceto = 0 and oxpricefrom <= $sQuotedPrice)"
04303 ." or (oxpricefrom = 0 and oxpriceto != 0 and oxpriceto >= $sQuotedPrice)"
04304 .")"
04305 );
04306 }
04307
04313 public function getMdVariants()
04314 {
04315 if ( $this->_oMdVariants ) {
04316 return $this->_oMdVariants;
04317 }
04318
04319 $oParentArticle = $this->getParentArticle();
04320 if ( $oParentArticle ) {
04321 $oVariants = $oParentArticle->getVariants();
04322 } else {
04323 $oVariants = $this->getVariants();
04324 }
04325
04326 $oVariantHandler = oxNew( "oxVariantHandler" );
04327 $this->_oMdVariants = $oVariantHandler->buildMdVariants( $oVariants, $this->getId() );
04328
04329 return $this->_oMdVariants;
04330 }
04331
04337 public function getMdSubvariants()
04338 {
04339 return $this->getMdVariants()->getMdSubvariants();
04340 }
04341
04349 protected function _hasMasterImage( $iIndex )
04350 {
04351 $sPicName = basename($this->{"oxarticles__oxpic" . $iIndex}->value);
04352
04353 if ( $sPicName == "nopic.jpg" || $sPicName == "" ) {
04354 return false;
04355 }
04356 if ( $this->isVariant() && $this->getParentArticle()->{"oxarticles__oxpic".$iIndex}->value == $this->{"oxarticles__oxpic".$iIndex}->value ) {
04357 return false;
04358 }
04359
04360 $sMasterPic = 'product/'.$iIndex . "/" . $sPicName;
04361
04362 if ( $this->getConfig()->getMasterPicturePath( $sMasterPic ) ) {
04363 return true;
04364 }
04365
04366 return false;
04367 }
04368
04377 public function getPictureFieldValue( $sFieldName, $iIndex = null )
04378 {
04379 if ( $sFieldName ) {
04380 $sFieldName = "oxarticles__" . $sFieldName . $iIndex;
04381 return $this->$sFieldName->value;
04382 }
04383 }
04384
04392 public function getMasterZoomPictureUrl( $iIndex )
04393 {
04394 $sPicUrl = false;
04395 $sPicName = basename( $this->{"oxarticles__oxpic" . $iIndex}->value );
04396
04397 if ( $sPicName && $sPicName != "nopic.jpg" ) {
04398 $sPicUrl = $this->getConfig()->getPictureUrl( "master/product/" . $iIndex . "/" . $sPicName );
04399 if ( !$sPicUrl || basename( $sPicUrl ) == "nopic.jpg" ) {
04400 $sPicUrl = false;
04401 }
04402 }
04403
04404 return $sPicUrl;
04405 }
04406
04412 public function getUnitName()
04413 {
04414 if ( $this->oxarticles__oxunitname->value ) {
04415 return oxRegistry::getLang()->translateString( $this->oxarticles__oxunitname->value );
04416 }
04417 }
04418
04426 public function getArticleFiles( $blAddFromParent=false )
04427 {
04428 if ( $this->_aArticleFiles === null) {
04429
04430 $this->_aArticleFiles = false;
04431
04432 $sQ = "SELECT * FROM `oxfiles` WHERE `oxartid` = '".$this->getId()."'";
04433
04434 if ( !$this->getConfig()->getConfigParam( 'blVariantParentBuyable' ) && $blAddFromParent ) {
04435 $sQ .= " OR `oxartId` = '". $this->oxarticles__oxparentid->value . "'";
04436 }
04437
04438 $oArticleFiles = oxNew("oxlist");
04439 $oArticleFiles->init("oxfile");
04440 $oArticleFiles->selectString( $sQ );
04441 $this->_aArticleFiles = $oArticleFiles;
04442
04443 }
04444
04445 return $this->_aArticleFiles;
04446 }
04447
04453 public function isDownloadable()
04454 {
04455 return $this->oxarticles__oxisdownloadable->value;
04456 }
04457
04463 public function hasAmountPrice()
04464 {
04465 if ( self::$_blHasAmountPrice === null ) {
04466
04467 self::$_blHasAmountPrice = false;
04468
04469 $oDb = oxDb::getDb();
04470 $sQ = "SELECT 1 FROM `oxprice2article` LIMIT 1";
04471
04472 if ( $oDb->getOne( $sQ ) ) {
04473 self::$_blHasAmountPrice = true;
04474 }
04475 }
04476
04477 return self::$_blHasAmountPrice;
04478 }
04479
04480
04486 protected function _isPriceViewModeNetto()
04487 {
04488 $blResult = (bool) $this->getConfig()->getConfigParam('blShowNetPrice');
04489 $oUser = $this->getArticleUser();
04490 if ( $oUser ) {
04491 $blResult = $oUser->isPriceViewModeNetto();
04492 }
04493
04494 return $blResult;
04495 }
04496
04497
04505 protected function _getPriceObject( $blCalculationModeNetto = null )
04506 {
04507 $oPrice = oxNew( 'oxPrice' );
04508
04509 if ( $blCalculationModeNetto === null ) {
04510 $blCalculationModeNetto = $this->_isPriceViewModeNetto();
04511 }
04512
04513 if ( $blCalculationModeNetto ) {
04514 $oPrice->setNettoPriceMode();
04515 } else {
04516 $oPrice->setBruttoPriceMode();
04517 }
04518
04519 return $oPrice;
04520 }
04521
04522
04530 protected function _getPriceForView( $oPrice )
04531 {
04532 if ( $this->_isPriceViewModeNetto() ) {
04533 $dPrice = $oPrice->getNettoPrice();
04534 } else {
04535 $dPrice = $oPrice->getBruttoPrice();
04536 }
04537
04538 return $dPrice;
04539 }
04540
04541
04551 protected function _preparePrice( $dPrice, $dVat, $blCalculationModeNetto = null )
04552 {
04553 if ( $blCalculationModeNetto === null ) {
04554 $blCalculationModeNetto = $this->_isPriceViewModeNetto();
04555 }
04556
04557 $blEnterNetPrice = $this->getConfig()->getConfigParam('blEnterNetPrice');
04558 if ( $blCalculationModeNetto && !$blEnterNetPrice ) {
04559 $dPrice = round( oxPrice::brutto2Netto( $dPrice, $dVat ), 2 );
04560 } elseif ( !$blCalculationModeNetto && $blEnterNetPrice ) {
04561 $dPrice = round( oxPrice::netto2Brutto( $dPrice, $dVat ), 2 );
04562 }
04563
04564 return $dPrice;
04565 }
04566
04567
04573 public function getFUnitPrice()
04574 {
04575 if ($this->_fPricePerUnit == null) {
04576 if ( $oPrice = $this->getUnitPrice() ) {
04577 if ( $dPrice = $this->_getPriceForView( $oPrice ) ) {
04578 $this->_fPricePerUnit = oxRegistry::getLang()->formatCurrency( $dPrice );
04579 }
04580 }
04581 }
04582
04583 return $this->_fPricePerUnit;
04584 }
04585
04586
04592 public function getUnitPrice()
04593 {
04594
04595 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
04596 return;
04597 }
04598
04599 $oPrice = null;
04600 if ( (double) $this->oxarticles__oxunitquantity->value && $this->oxarticles__oxunitname->value ) {
04601 $oPrice = clone $this->getPrice();
04602 $oPrice->divide( (double) $this->oxarticles__oxunitquantity->value );
04603 }
04604
04605 return $oPrice;
04606 }
04607
04608
04614 public function getFMinPrice()
04615 {
04616 $sPrice = '';
04617 if ( $oPrice = $this->getMinPrice() ) {
04618 $dPrice = $this->_getPriceForView( $oPrice );
04619 $sPrice = oxRegistry::getLang()->formatCurrency( $dPrice );
04620 }
04621
04622 return $sPrice;
04623 }
04624
04630 public function getFVarMinPrice()
04631 {
04632 $sPrice = '';
04633 if ( $oPrice = $this->getVarMinPrice() ) {
04634 $dPrice = $this->_getPriceForView( $oPrice );
04635 $sPrice = oxRegistry::getLang()->formatCurrency( $dPrice );
04636 }
04637
04638 return $sPrice;
04639 }
04640
04646 public function getVarMinPrice()
04647 {
04648 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
04649 return;
04650 }
04651
04652 $oPrice = null;
04653 $dPrice = $this->_getVarMinPrice();
04654
04655 $dPrice = $this->_preparePrice( $dPrice, $this->getArticleVat() );
04656
04657
04658 $oPrice = $this->_getPriceObject();
04659 $oPrice->setPrice( $dPrice );
04660 $this->_calculatePrice( $oPrice );
04661
04662
04663 return $oPrice;
04664 }
04665
04666
04672 public function getMinPrice()
04673 {
04674 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
04675 return;
04676 }
04677
04678 $oPrice = null;
04679 $dPrice = $this->_getPrice();
04680 if ( $this->_getVarMinPrice() !== null && $dPrice > $this->_getVarMinPrice() ) {
04681 $dPrice = $this->_getVarMinPrice();
04682 }
04683
04684 $dPrice = $this->_preparePrice( $dPrice, $this->getArticleVat() );
04685
04686
04687 $oPrice = $this->_getPriceObject();
04688 $oPrice->setPrice( $dPrice );
04689 $this->_calculatePrice( $oPrice );
04690
04691
04692 return $oPrice;
04693 }
04694
04695
04701 public function isRangePrice()
04702 {
04703 if ( $this->_blIsRangePrice === null ) {
04704
04705 $this->setRangePrice( false );
04706
04707 if ( $this->_hasAnyVariant() ) {
04708 $dPrice = $this->_getPrice();
04709 $dMinPrice = $this->_getVarMinPrice();
04710 $dMaxPrice = $this->_getVarMaxPrice();
04711
04712 if ( $dMinPrice != $dMaxPrice ) {
04713 $this->setRangePrice();
04714 } elseif ( !$this->isParentNotBuyable() && $dMinPrice != $dPrice ) {
04715 $this->setRangePrice();
04716 }
04717 }
04718 }
04719
04720 return $this->_blIsRangePrice;
04721 }
04722
04723
04731 public function setRangePrice( $blIsRangePrice = true )
04732 {
04733 return $this->_blIsRangePrice = $blIsRangePrice;
04734 }
04735
04741 protected function _getUserPriceSufix()
04742 {
04743 $sPriceSufix = '';
04744 $oUser = $this->getArticleUser();
04745
04746 if ( $oUser ) {
04747 if ( $oUser->inGroup( 'oxidpricea' ) ) {
04748 $sPriceSufix = 'a';
04749 } elseif ( $oUser->inGroup( 'oxidpriceb' ) ) {
04750 $sPriceSufix = 'b';
04751 } elseif ( $oUser->inGroup( 'oxidpricec' ) ) {
04752 $sPriceSufix = 'c';
04753 }
04754 }
04755
04756 return $sPriceSufix;
04757 }
04758
04759
04765 protected function _getPrice()
04766 {
04767 $sPriceSufix = $this->_getUserPriceSufix();
04768 if ( $sPriceSufix === '') {
04769 $dPrice = $this->oxarticles__oxprice->value;
04770 } else {
04771 if ( $this->getConfig()->getConfigParam( 'blOverrideZeroABCPrices' ) ) {
04772 $dPrice = ($this->{oxarticles__oxprice.$sPriceSufix}->value !=0 )? $this->{oxarticles__oxprice.$sPriceSufix}->value : $this->oxarticles__oxprice->value;
04773 } else {
04774 $dPrice = $this->{oxarticles__oxprice.$sPriceSufix}->value;
04775 }
04776 }
04777 return $dPrice;
04778 }
04779
04780
04786 protected function _getVarMinPrice()
04787 {
04788 if ( $this->_dVarMinPrice === null) {
04789
04790 $sPriceSufix = $this->_getUserPriceSufix();
04791 if ( $dPrice === null ) {
04792 if ( $sPriceSufix === '' ) {
04793 $dPrice = $this->oxarticles__oxvarminprice->value;
04794 } else {
04795 $sSql = 'SELECT ';
04796 if ( $this->getConfig()->getConfigParam( 'blOverrideZeroABCPrices' ) ) {
04797 $sSql .= 'MIN( IF(`oxprice'.$sPriceSufix.'` = 0, `oxprice`, `oxprice'.$sPriceSufix.'`) ) AS `varminprice` ';
04798 } else {
04799 $sSql .= 'MIN(`oxprice'.$sPriceSufix.'`) AS `varminprice` ';
04800 }
04801
04802 $sSql .= ' FROM ' . $this->getViewName(true) . '
04803 WHERE ' .$this->getSqlActiveSnippet(true) . '
04804 AND ( `oxparentid` = ' . oxDb::getDb()->quote( $this->getId() ) . ' )';
04805
04806 $dPrice = oxDb::getDb()->getOne( $sSql );
04807 }
04808 }
04809 $this->_dVarMinPrice = $dPrice;
04810 }
04811
04812 return $this->_dVarMinPrice;
04813 }
04814
04820 protected function _getSubShopVarMinPrice()
04821 {
04822 $myConfig = $this->getConfig();
04823 $sShopId = $myConfig->getShopId();
04824 if ($this->getConfig()->getConfigParam( 'blMallCustomPrice' ) && $sShopId != $this->oxarticles__oxshopid->value ) {
04825 $sPriceSufix = $this->_getUserPriceSufix();
04826 $sSql = 'SELECT ';
04827 if ( $sPriceSufix != '' && $this->getConfig()->getConfigParam( 'blOverrideZeroABCPrices' ) ) {
04828 $sSql .= 'MIN(IF(`oxfield2shop`.`oxprice'.$sPriceSufix.'` = 0, `oxfield2shop`.`oxprice`, `oxfield2shop`.`oxprice'.$sPriceSufix.'`)) AS `varminprice` ';
04829 } else {
04830 $sSql .= 'MIN(`oxfield2shop`.`oxprice'.$sPriceSufix.'`) AS `varminprice` ';
04831 }
04832 $sSql .= ' FROM ' . getViewName('oxfield2shop') . ' AS oxfield2shop
04833 INNER JOIN ' . $this->getViewName(true) . ' AS oxarticles ON `oxfield2shop`.`oxartid` = `oxarticles`.`oxid`
04834 WHERE ' .$this->getSqlActiveSnippet(true) . '
04835 AND ( `oxarticles`.`oxparentid` = ' . oxDb::getDb()->quote( $this->getId() ) . ' )
04836 AND ( `oxfield2shop`.`oxshopid` = ' . oxDb::getDb()->quote( $sShopId ) . ' )';
04837 $dPrice = oxDb::getDb()->getOne( $sSql );
04838 }
04839 return $dPrice;
04840 }
04841
04847 protected function _getVarMaxPrice()
04848 {
04849 if ( $this->_dVarMaxPrice === null ) {
04850
04851 $sPriceSufix = $this->_getUserPriceSufix();
04852 if ( $dPrice === null ) {
04853 if ( $sPriceSufix === '') {
04854 $dPrice = $this->oxarticles__oxvarmaxprice->value;
04855 } else {
04856 $sSql = 'SELECT ';
04857 if ( $this->getConfig()->getConfigParam( 'blOverrideZeroABCPrices' ) ) {
04858 $sSql .= 'MAX( IF(`oxprice'.$sPriceSufix.'` = 0, `oxprice`, `oxprice'.$sPriceSufix.'`) ) AS `varmaxprice` ';
04859 } else {
04860 $sSql .= 'MAX(`oxprice'.$sPriceSufix.'`) AS `varmaxprice` ';
04861 }
04862
04863 $sSql .= ' FROM ' . $this->getViewName(true) . '
04864 WHERE ' .$this->getSqlActiveSnippet(true) . '
04865 AND ( `oxparentid` = ' . oxDb::getDb()->quote( $this->getId() ) . ' )';
04866
04867 $dPrice = oxDb::getDb()->getOne( $sSql );
04868 }
04869 }
04870 $this->_dVarMaxPrice = $dPrice;
04871 }
04872
04873 return $this->_dVarMaxPrice;
04874 }
04875
04881 protected function _getSubShopVarMaxPrice()
04882 {
04883 $myConfig = $this->getConfig();
04884 $sShopId = $myConfig->getShopId();
04885 if ($this->getConfig()->getConfigParam( 'blMallCustomPrice' ) && $sShopId != $this->oxarticles__oxshopid->value ) {
04886 $sPriceSufix = $this->_getUserPriceSufix();
04887 $sSql = 'SELECT ';
04888 if ( $sPriceSufix != '' && $this->getConfig()->getConfigParam( 'blOverrideZeroABCPrices' ) ) {
04889 $sSql .= 'MAX(IF(`oxfield2shop`.`oxprice'.$sPriceSufix.'` = 0, `oxfield2shop`.`oxprice`, `oxfield2shop`.`oxprice'.$sPriceSufix.'`)) AS `varmaxprice` ';
04890 } else {
04891 $sSql .= 'MAX(`oxfield2shop`.`oxprice'.$sPriceSufix.'`) AS `varmaxprice` ';
04892 }
04893 $sSql .= ' FROM ' . getViewName('oxfield2shop') . ' AS oxfield2shop
04894 INNER JOIN ' . $this->getViewName(true) . ' AS oxarticles ON `oxfield2shop`.`oxartid` = `oxarticles`.`oxid`
04895 WHERE ' .$this->getSqlActiveSnippet(true) . '
04896 AND ( `oxarticles`.`oxparentid` = ' . oxDb::getDb()->quote( $this->getId() ) . ' )
04897 AND ( `oxfield2shop`.`oxshopid` = ' . oxDb::getDb()->quote( $sShopId ) . ' )';
04898 $dPrice = oxDb::getDb()->getOne( $sSql );
04899 }
04900 return $dPrice;
04901 }
04902
04903 }