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 $_blAllowEmptyParentId = false;
00176
00180 protected $_blSkipAssign = false;
00181
00187 protected $_blSkipDiscounts = null;
00188
00193 protected $_oAttributeList = null;
00194
00195
00201 protected $_blIsRangePrice = null;
00202
00208 protected $_aMediaUrls = null;
00209
00215 static protected $_aLoadedParents;
00216
00222 static protected $_aSelList;
00223
00229 protected $_aDispSelList;
00230
00236 protected $_blIsSeoObject = true;
00237
00243 protected $_oAmountPriceList = null;
00244
00253 protected $_iLinkType = 0;
00254
00260 protected $_aStdUrls = array();
00261
00267 protected $_aSeoUrls = array();
00268
00274 protected $_aSeoAddParams = array();
00275
00281 protected $_aStdAddParams = array();
00282
00288 protected $_sDynImageDir = null;
00289
00295 protected $_sMoreDetailLink = null;
00296
00302 protected $_sToBasketLink = null;
00303
00309 protected $_iStockStatus = null;
00310
00316 protected $_oTPrice = null;
00317
00323 protected $_oAmountPriceInfo = null;
00324
00330 protected $_dAmountPrice = null;
00331
00337 protected static $_aArticleManufacturers = array();
00338
00344 protected static $_aArticleVendors = array();
00345
00351 protected static $_aArticleCats = array();
00352
00358 protected $_aNonCopyParentFields = array('oxarticles__oxinsert',
00359 'oxarticles__oxtimestamp',
00360 'oxarticles__oxnid',
00361 'oxarticles__oxid',
00362 'oxarticles__oxparentid');
00363
00369 protected $_aCopyParentField = array('oxarticles__oxnonmaterial',
00370 'oxarticles__oxfreeshipping',
00371
00372 'oxarticles__oxisdownloadable');
00373
00379 protected $_oMdVariants = null;
00380
00386 protected $_oLongDesc = null;
00387
00395 protected $_aVariantSelections = array();
00396
00401 protected static $_aSelections = array();
00402
00407 protected static $_aCategoryCache = null;
00408
00413 protected static $_blHasAmountPrice = null;
00414
00419 protected $_aArticleFiles = null;
00420
00425 protected $_blCanUpdateAnyField = null;
00426
00435 public function __construct($aParams = null)
00436 {
00437 if ( $aParams && is_array($aParams)) {
00438 foreach ( $aParams as $sParam => $mValue) {
00439 $this->$sParam = $mValue;
00440 }
00441 }
00442 parent::__construct();
00443 $this->init( 'oxarticles' );
00444 }
00445
00454 public function __get($sName)
00455 {
00456 $this->$sName = parent::__get($sName);
00457 if ( $this->$sName ) {
00458
00459 $this->_assignParentFieldValue($sName);
00460 }
00461
00462 return $this->$sName;
00463 }
00464
00473 public function __set( $sName, $sValue )
00474 {
00475 parent::__set( $sName, $sValue );
00476 }
00477
00485 public function setId( $sId = null )
00486 {
00487 $sId = parent::setId( $sId );
00488
00489
00490 $this->oxarticles__oxnid = $this->oxarticles__oxid;
00491
00492 return $sId;
00493 }
00494
00504 public function getActiveCheckQuery( $blForceCoreTable = null )
00505 {
00506 $sTable = $this->getViewName( $blForceCoreTable );
00507
00508
00509 $sQ = " $sTable.oxactive = 1 ";
00510
00511
00512 if ( $this->getConfig()->getConfigParam( 'blUseTimeCheck' ) ) {
00513 $sDate = date( 'Y-m-d H:i:s', oxRegistry::get("oxUtilsDate")->getTime() );
00514 $sQ = "( $sQ or ( $sTable.oxactivefrom < '$sDate' and $sTable.oxactiveto > '$sDate' ) ) ";
00515 }
00516
00517 return $sQ;
00518 }
00519
00533 public function getStockCheckQuery( $blForceCoreTable = null )
00534 {
00535 $myConfig = $this->getConfig();
00536 $sTable = $this->getViewName( $blForceCoreTable );
00537
00538 $sQ = "";
00539
00540
00541 if ( $myConfig->getConfigParam( 'blUseStock' ) ) {
00542 $sQ = " and ( $sTable.oxstockflag != 2 or ( $sTable.oxstock + $sTable.oxvarstock ) > 0 ) ";
00543
00544 if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) ) {
00545 $sTimeCheckQ = '';
00546 if ( $myConfig->getConfigParam( 'blUseTimeCheck' ) ) {
00547 $sDate = date( 'Y-m-d H:i:s', oxRegistry::get("oxUtilsDate")->getTime() );
00548 $sTimeCheckQ = " or ( art.oxactivefrom < '$sDate' and art.oxactiveto > '$sDate' )";
00549 }
00550 $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 ) ) ";
00551 }
00552 }
00553
00554 return $sQ;
00555 }
00556
00568 public function getVariantsQuery( $blRemoveNotOrderables, $blForceCoreTable = null )
00569 {
00570 $sTable = $this->getViewName( $blForceCoreTable );
00571 $sQ = " and $sTable.oxparentid = '".$this->getId()."' ";
00572
00573
00574 if ( $this->getConfig()->getConfigParam( 'blUseStock' ) ) {
00575 $sQ .= " and ( $sTable.oxstock > 0 or ( $sTable.oxstock <= 0 and $sTable.oxstockflag != 2 ";
00576 if ( $blRemoveNotOrderables ) {
00577 $sQ .= " and $sTable.oxstockflag != 3 ";
00578 }
00579 $sQ .= " ) ) ";
00580 }
00581
00582 return $sQ;
00583 }
00584
00592 public function getSqlActiveSnippet( $blForceCoreTable = null )
00593 {
00594 $myConfig = $this->getConfig();
00595
00596
00597 $sQ = $this->getActiveCheckQuery( $blForceCoreTable );
00598
00599
00600 $sQ .= $this->getStockCheckQuery( $blForceCoreTable );
00601
00602
00603 return "( $sQ ) ";
00604 }
00605
00613 public function setSkipAssign($blSkipAssign)
00614 {
00615 $this->_blSkipAssign = $blSkipAssign;
00616 }
00617
00623 public function disablePriceLoad()
00624 {
00625 $this->_blLoadPrice = false;
00626 }
00627
00633 public function enablePriceLoad()
00634 {
00635 $this->_blLoadPrice = true;
00636 }
00637
00643 public function getItemKey()
00644 {
00645 return $this->_sItemKey;
00646 }
00647
00655 public function setItemKey($sItemKey)
00656 {
00657 $this->_sItemKey = $sItemKey;
00658 }
00659
00667 public function setNoVariantLoading( $blLoadVariants )
00668 {
00669 $this->_blLoadVariants = !$blLoadVariants;
00670 }
00671
00677 public function isBuyable()
00678 {
00679 if ($this->_blNotBuyableParent) {
00680 return false;
00681 }
00682
00683 return !$this->_blNotBuyable;
00684 }
00685
00691 public function getPersParams()
00692 {
00693 return $this->_aPersistParam;
00694 }
00695
00701 public function isOnComparisonList()
00702 {
00703 return $this->_blIsOnComparisonList;
00704 }
00705
00713 public function setOnComparisonList( $blOnList )
00714 {
00715 $this->_blIsOnComparisonList = $blOnList;
00716 }
00717
00725 public function setLoadParentData($blLoadParentData)
00726 {
00727 $this->_blLoadParentData = $blLoadParentData;
00728 }
00729
00739 public function setSkipAbPrice( $blSkipAbPrice = null )
00740 {
00741 $this->_blSkipAbPrice = $blSkipAbPrice;
00742 }
00743
00744
00752 public function isMultilingualField($sFieldName)
00753 {
00754 switch ($sFieldName) {
00755 case "oxlongdesc":
00756 case "oxtags":
00757 return true;
00758 }
00759
00760 return parent::isMultilingualField($sFieldName);
00761 }
00762
00768 public function isVisible()
00769 {
00770
00771
00772 if ( ( $blCanPreview = oxRegistry::getUtils()->canPreview() ) !== null ) {
00773 return $blCanPreview;
00774 }
00775
00776
00777 $sNow = date('Y-m-d H:i:s');
00778 if ( !$this->oxarticles__oxactive->value &&
00779 ( $this->oxarticles__oxactivefrom->value > $sNow ||
00780 $this->oxarticles__oxactiveto->value < $sNow
00781 )) {
00782 return false;
00783 }
00784
00785
00786 if ( $this->getConfig()->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstockflag->value == 2) {
00787 $iOnStock = $this->oxarticles__oxstock->value + $this->oxarticles__oxvarstock->value;
00788 if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
00789 $iOnStock += $this->getSession()->getBasketReservations()->getReservedAmount($this->getId());
00790 }
00791 if ( $iOnStock <= 0 ) {
00792 return false;
00793 }
00794 }
00795
00796 return true;
00797 }
00798
00807 public function assign( $aRecord )
00808 {
00809
00810 startProfile('articleAssign');
00811
00812
00813 parent::assign( $aRecord );
00814
00815 $this->oxarticles__oxnid = $this->oxarticles__oxid;
00816
00817
00818 if ($this->_blSkipAssign) {
00819 return;
00820 }
00821
00822 $this->_assignParentFieldValues();
00823 $this->_assignNotBuyableParent();
00824
00825
00826 $this->_assignStock();
00827 $this->_assignPersistentParam();
00828 $this->_assignDynImageDir();
00829 $this->_assignComparisonListFlag();
00830
00831
00832 stopProfile('articleAssign');
00833 }
00834
00835
00843 protected function _loadFromDb( $sOXID )
00844 {
00845 $sSelect = $this->buildSelectString( array( $this->getViewName().".oxid" => $sOXID ));
00846
00847 $aData = oxDb::getDb( oxDb::FETCH_MODE_ASSOC )->getRow( $sSelect );
00848
00849 return $aData;
00850 }
00851
00862 public function load( $sOXID )
00863 {
00864
00865 $this->_blNotBuyableParent = false;
00866
00867
00868 $aData = $this->_loadFromDb( $sOXID );
00869
00870 if ( $aData ) {
00871 $this->assign( $aData );
00872
00873 $this->_isLoaded = true;
00874 return true;
00875 }
00876
00877 return false;
00878 }
00879
00880
00888 public function addToRatingAverage( $iRating )
00889 {
00890 $dOldRating = $this->oxarticles__oxrating->value;
00891 $dOldCnt = $this->oxarticles__oxratingcnt->value;
00892 $this->oxarticles__oxrating->setValue(( $dOldRating * $dOldCnt + $iRating ) / ($dOldCnt + 1));
00893 $this->oxarticles__oxratingcnt->setValue($dOldCnt + 1);
00894 $dRating = ( $dOldRating * $dOldCnt + $iRating ) / ($dOldCnt + 1);
00895 $dRatingCnt = (int) ($dOldCnt + 1);
00896
00897 $oDb = oxDb::getDb();
00898 $oDb->execute( 'update oxarticles set oxarticles.oxrating = '.$dRating.',oxarticles.oxratingcnt = '.$dRatingCnt.', oxarticles.oxtimestamp = oxarticles.oxtimestamp where oxarticles.oxid = '.$oDb->quote( $this->getId() ) );
00899
00900 }
00901
00909 public function setRatingAverage( $iRating )
00910 {
00911 $this->oxarticles__oxrating = new oxField( $iRating );
00912 }
00913
00921 public function setRatingCount( $iRatingCnt )
00922 {
00923 $this->oxarticles__oxratingcnt = new oxField( $iRatingCnt );
00924 }
00925
00933 public function getArticleRatingAverage( $blIncludeVariants = false )
00934 {
00935 if ( !$blIncludeVariants ) {
00936 return round( $this->oxarticles__oxrating->value, 1);
00937 } else {
00938 $oRating = oxNew( 'oxRating' );
00939 return $oRating->getRatingAverage( $this->getId(), 'oxarticle', $this->_getVariantsIds() );
00940 }
00941 }
00942
00950 public function getArticleRatingCount( $blIncludeVariants = false )
00951 {
00952 if ( !$blIncludeVariants ) {
00953 return $this->oxarticles__oxratingcnt->value;
00954 } else {
00955 $oRating = oxNew( 'oxRating' );
00956 return $oRating->getRatingCount( $this->getId(), 'oxarticle', $this->_getVariantsIds() );
00957 }
00958 }
00959
00960
00966 public function getReviews()
00967 {
00968 $aIds = array($this->getId());
00969
00970 if ( $this->oxarticles__oxparentid->value ) {
00971 $aIds[] = $this->oxarticles__oxparentid->value;
00972 }
00973
00974
00975 if ( $this->getConfig()->getConfigParam( 'blShowVariantReviews' ) ) {
00976 $aAdd = $this->_getVariantsIds();
00977 if (is_array($aAdd)) {
00978 $aIds = array_merge($aIds, $aAdd);
00979 }
00980 }
00981
00982 $oReview = oxNew('oxreview');
00983 $oRevs = $oReview->loadList('oxarticle', $aIds);
00984
00985
00986 if ( $oRevs->count() < 1 ) {
00987 return null;
00988 }
00989
00990 return $oRevs;
00991 }
00992
00998 public function getCrossSelling()
00999 {
01000 $oCrosslist = oxNew( "oxarticlelist");
01001 $oCrosslist->loadArticleCrossSell($this->oxarticles__oxid->value);
01002 if ( $oCrosslist->count() ) {
01003 return $oCrosslist;
01004 }
01005 }
01006
01012 public function getAccessoires()
01013 {
01014 $myConfig = $this->getConfig();
01015
01016
01017 if ( !$myConfig->getConfigParam( 'bl_perfLoadAccessoires' ) ) {
01018 return;
01019 }
01020
01021 $oAcclist = oxNew( "oxarticlelist");
01022 $oAcclist->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofCrossellArticles' ));
01023 $oAcclist->loadArticleAccessoires($this->oxarticles__oxid->value);
01024
01025 if ( $oAcclist->count()) {
01026 return $oAcclist;
01027 }
01028 }
01029
01035 public function getSimilarProducts()
01036 {
01037
01038 $myConfig = $this->getConfig();
01039 if ( !$myConfig->getConfigParam( 'bl_perfLoadSimilar' ) ) {
01040 return;
01041 }
01042
01043 $sArticleTable = $this->getViewName();
01044
01045 $sAttribs = '';
01046 $iCnt = 0;
01047 $this->_getAttribsString($sAttribs, $iCnt);
01048
01049 if ( !$sAttribs) {
01050 return null;
01051 }
01052
01053 $aList = $this->_getSimList($sAttribs, $iCnt);
01054
01055 if ( count( $aList ) ) {
01056 uasort( $aList, 'cmpart');
01057
01058 $sSearch = $this->_generateSimListSearchStr($sArticleTable, $aList);
01059
01060 $oSimilarlist = oxNew( 'oxarticlelist' );
01061 $oSimilarlist->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofSimilarArticles' ));
01062 $oSimilarlist->selectString( $sSearch);
01063
01064 return $oSimilarlist;
01065 }
01066 }
01067
01073 public function getCustomerAlsoBoughtThisProducts()
01074 {
01075
01076 $myConfig = $this->getConfig();
01077 if ( !$myConfig->getConfigParam( 'bl_perfLoadCustomerWhoBoughtThis' ) ) {
01078 return;
01079 }
01080
01081
01082 $sQ = $this->_generateSearchStrForCustomerBought();
01083
01084 $oArticles = oxNew( 'oxarticlelist' );
01085 $oArticles->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofCustomerWhoArticles' ));
01086 $oArticles->selectString( $sQ );
01087 if ( $oArticles->count() ) {
01088 return $oArticles;
01089 }
01090 }
01091
01098 public function loadAmountPriceInfo()
01099 {
01100 $myConfig = $this->getConfig();
01101 if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice || !$this->_blCalcPrice || !$this->hasAmountPrice() ) {
01102 return array();
01103 }
01104
01105 if ( $this->_oAmountPriceInfo === null ) {
01106 $this->_oAmountPriceInfo = array();
01107 if ( count( ( $aAmPriceList = $this->_getAmountPriceList()->getArray() ) ) ) {
01108 $this->_oAmountPriceInfo = $this->_fillAmountPriceList( $aAmPriceList );
01109 }
01110 }
01111 return $this->_oAmountPriceInfo;
01112 }
01113
01121 public function getSelectLists($sKeyPrefix = null)
01122 {
01123
01124
01125 $sKey = $this->getId();
01126 if ( isset( $sKeyPrefix ) ) {
01127 $sKey = $sKeyPrefix.'__'.$sKey;
01128 }
01129
01130 if ( !isset( self::$_aSelList[$sKey] ) ) {
01131 $oDb = oxDb::getDb();
01132 $sSLViewName = getViewName( 'oxselectlist' );
01133
01134 $sQ = "select {$sSLViewName}.* from oxobject2selectlist join {$sSLViewName} on $sSLViewName.oxid=oxobject2selectlist.oxselnid
01135 where oxobject2selectlist.oxobjectid=%s order by oxobject2selectlist.oxsort";
01136
01137
01138 $oLists = oxNew( 'oxlist' );
01139 $oLists->init( 'oxselectlist' );
01140 $oLists->selectString( sprintf( $sQ, $oDb->quote( $this->getId() ) ) );
01141
01142
01143 if ( $oLists->count() == 0 && $this->oxarticles__oxparentid->value ) {
01144 $oLists->selectString( sprintf( $sQ, $oDb->quote( $this->oxarticles__oxparentid->value ) ) );
01145 }
01146
01147
01148
01149
01150
01151 $dVat = $this->getArticleVat();
01152
01153 $iCnt = 0;
01154 self::$_aSelList[$sKey] = array();
01155 foreach ( $oLists as $oSelectlist ) {
01156 self::$_aSelList[$sKey][$iCnt] = $oSelectlist->getFieldList( $dVat );
01157 self::$_aSelList[$sKey][$iCnt]['name'] = $oSelectlist->oxselectlist__oxtitle->value;
01158 $iCnt++;
01159 }
01160 }
01161 return self::$_aSelList[$sKey];
01162 }
01163
01171 protected function _hasAnyVariant( $blForceCoreTable = null )
01172 {
01173 $blHas = false;
01174 if ( ( $sId = $this->getId() ) ) {
01175 if ( $this->oxarticles__oxshopid->value == $this->getConfig()->getShopId() ) {
01176 $blHas = (bool) $this->oxarticles__oxvarcount->value;
01177 } else {
01178 $sArticleTable = $this->getViewName( $blForceCoreTable );
01179 $blHas = (bool) oxDb::getDb()->getOne( "select 1 from $sArticleTable where oxparentid='{$sId}'" );
01180 }
01181 }
01182 return $blHas;
01183 }
01184
01190 public function hasMdVariants()
01191 {
01192 return $this->_blHasMdVariants;
01193 }
01194
01204 public function getVariantSelections( $aFilterIds = null, $sActVariantId = null, $iLimit = 0 )
01205 {
01206 $iLimit = (int) $iLimit;
01207 if ( !isset( $this->_aVariantSelections[$iLimit] ) ) {
01208 $aVariantSelections = false;
01209 if ( $this->oxarticles__oxvarcount->value ) {
01210 $oVariants = $this->getVariants( false );
01211 $aVariantSelections = oxNew( "oxVariantHandler" )->buildVariantSelections( $this->oxarticles__oxvarname->getRawValue(), $oVariants, $aFilterIds, $sActVariantId, $iLimit );
01212
01213 if ( !empty($oVariants) && empty( $aVariantSelections['rawselections'] ) ) {
01214 $aVariantSelections = false;
01215 }
01216 }
01217 $this->_aVariantSelections[$iLimit] = $aVariantSelections;
01218 }
01219
01220 return $this->_aVariantSelections[$iLimit];
01221 }
01222
01231 public function getSelections( $iLimit = null, $aFilter = null )
01232 {
01233 $sId = $this->getId() . ( (int) $iLimit );
01234 if ( !array_key_exists( $sId, self::$_aSelections ) ) {
01235
01236 $oDb = oxDb::getDb();
01237 $sSLViewName = getViewName( 'oxselectlist' );
01238
01239 $sQ = "select {$sSLViewName}.* from oxobject2selectlist join {$sSLViewName} on $sSLViewName.oxid=oxobject2selectlist.oxselnid
01240 where oxobject2selectlist.oxobjectid=%s order by oxobject2selectlist.oxsort";
01241
01242 if ( ( $iLimit = (int) $iLimit ) ) {
01243 $sQ .= " limit $iLimit ";
01244 }
01245
01246
01247 $dVat = 0;
01248 if ( ( $oPrice = $this->getPrice() ) != null ) {
01249 $dVat = $oPrice->getVat();
01250 }
01251
01252
01253 $oList = oxNew( 'oxlist' );
01254 $oList->init( 'oxselectlist' );
01255 $oList->getBaseObject()->setVat( $dVat );
01256 $oList->selectString( sprintf( $sQ, $oDb->quote( $this->getId() ) ) );
01257
01258
01259 if ( $oList->count() == 0 && $this->oxarticles__oxparentid->value ) {
01260 $oList->selectString( sprintf( $sQ, $oDb->quote( $this->oxarticles__oxparentid->value ) ) );
01261 }
01262
01263 self::$_aSelections[$sId] = $oList->count() ? $oList : false;
01264 }
01265
01266 if ( self::$_aSelections[$sId] ) {
01267
01268 $aFilter = ( $aFilter === null ) ? oxConfig::getParameter( "sel" ) : $aFilter;
01269 if ( $aFilter ) {
01270 $iSelIdx = 0;
01271 foreach ( self::$_aSelections[$sId] as $oSelection ) {
01272 if ( isset( $aFilter[$iSelIdx] ) ) {
01273 $oSelection->setActiveSelectionByIndex( $aFilter[$iSelIdx] );
01274 }
01275 $iSelIdx++;
01276 }
01277 }
01278 }
01279
01280 return self::$_aSelections[$sId];
01281 }
01282
01292 protected function _loadVariantList( $blSimple, $blRemoveNotOrderables = true, $blForceCoreTable = null )
01293 {
01294 $oVariants = array();
01295 if ( ( $sId = $this->getId() ) ) {
01296
01297 self::$_aLoadedParents[$sId] = $this;
01298
01299 $myConfig = $this->getConfig();
01300
01301 if ( !$this->_blLoadVariants ||
01302 ( !$this->isAdmin() && !$myConfig->getConfigParam( 'blLoadVariants') ) ||
01303 ( !$this->isAdmin() && !$this->oxarticles__oxvarcount->value ) ) {
01304 return $oVariants;
01305 }
01306
01307
01308 $sCacheKey = $blSimple ? "simple" : "full";
01309 if ( $blRemoveNotOrderables ) {
01310 if ( isset( $this->_aVariants[$sCacheKey] ) ) {
01311 return $this->_aVariants[$sCacheKey];
01312 } else {
01313 $this->_aVariants[$sCacheKey] = & $oVariants;
01314 }
01315 } elseif ( !$blRemoveNotOrderables ) {
01316 if ( isset( $this->_aVariantsWithNotOrderables[$sCacheKey] ) ) {
01317 return $this->_aVariantsWithNotOrderables[$sCacheKey];
01318 } else {
01319 $this->_aVariantsWithNotOrderables[$sCacheKey] = & $oVariants;
01320 }
01321 }
01322
01323 if ( ( $this->_blHasVariants = $this->_hasAnyVariant( $blForceCoreTable ) ) ) {
01324
01325
01326 if ( $blSimple ) {
01327 $oVariants = oxNew( 'oxsimplevariantlist' );
01328 $oVariants->setParent( $this );
01329 } else {
01330
01331 $oVariants = oxNew( 'oxarticlelist' );
01332 $oVariants->getBaseObject()->modifyCacheKey( '_variants' );
01333 }
01334
01335 startProfile("selectVariants");
01336 $blUseCoreTable = (bool) $blForceCoreTable;
01337 $oBaseObject = $oVariants->getBaseObject();
01338 $oBaseObject->setLanguage( $this->getLanguage() );
01339
01340
01341 $sArticleTable = $this->getViewName( $blUseCoreTable );
01342
01343 $sSelect = "select ".$oBaseObject->getSelectFields( $blUseCoreTable )." from $sArticleTable where " .
01344 $this->getActiveCheckQuery( $blUseCoreTable ) .
01345 $this->getVariantsQuery( $blRemoveNotOrderables, $blUseCoreTable ) .
01346 " order by $sArticleTable.oxsort";
01347
01348
01349 $oVariants->selectString( $sSelect );
01350
01351
01352 if ( $myConfig->getConfigParam( 'blUseMultidimensionVariants' ) ) {
01353 $oMdVariants = oxNew( "oxVariantHandler" );
01354 $this->_blHasMdVariants = $oMdVariants->isMdVariant( $oVariants->current() );
01355 }
01356 stopProfile("selectVariants");
01357 }
01358
01359
01360 if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && $this->_blHasVariants ) {
01361 $this->_blNotBuyableParent = true;
01362 }
01363
01364
01365 if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && count( $oVariants ) == 0 && $this->_blHasVariants ) {
01366 $this->_blNotBuyable = true;
01367 }
01368 }
01369
01370 return $oVariants;
01371 }
01372
01381 public function getFullVariants( $blRemoveNotOrderables = true, $blForceCoreTable = null )
01382 {
01383 return $this->_loadVariantList( false, $blRemoveNotOrderables, $blForceCoreTable );
01384 }
01385
01394 public function getVariants( $blRemoveNotOrderables = true, $blForceCoreTable = null )
01395 {
01396 return $this->_loadVariantList( $this->_isInList(), $blRemoveNotOrderables, $blForceCoreTable );
01397 }
01398
01404 public function getSimpleVariants()
01405 {
01406 if ( $this->oxarticles__oxvarcount->value) {
01407 return $this->getVariants();
01408 }
01409 }
01410
01419 public function getAdminVariants( $sLanguage = null )
01420 {
01421 $oVariants = oxNew( 'oxarticlelist');
01422 if ( ( $sId = $this->getId() ) ) {
01423
01424 $oBaseObj = $oVariants->getBaseObject();
01425
01426 if ( is_null( $sLanguage ) ) {
01427 $oBaseObj->setLanguage( oxRegistry::getLang()->getBaseLanguage() );
01428 } else {
01429 $oBaseObj->setLanguage( $sLanguage );
01430 }
01431
01432 $sSql = "select * from ".$oBaseObj->getViewName()." where oxparentid = '{$sId}' order by oxsort ";
01433 $oVariants->selectString( $sSql );
01434
01435
01436 if ( !$this->getConfig()->getConfigParam( 'blVariantParentBuyable' ) && ( $oVariants->count() > 0 ) ) {
01437
01438 $this->_blNotBuyableParent = true;
01439 }
01440 }
01441
01442 return $oVariants;
01443 }
01444
01452 public function getCategory()
01453 {
01454 $oCategory = oxNew( 'oxcategory' );
01455 $oCategory->setLanguage( $this->getLanguage() );
01456
01457
01458 $sOXID = $this->getId();
01459 if ( isset( $this->oxarticles__oxparentid->value ) && $this->oxarticles__oxparentid->value ) {
01460 $sOXID = $this->oxarticles__oxparentid->value;
01461 }
01462
01463 if ( $sOXID ) {
01464
01465 if ( !isset( $this->_aCategoryCache[ $sOXID ] ) ) {
01466 startPRofile( 'getCategory' );
01467 $oStr = getStr();
01468 $sWhere = $oCategory->getSqlActiveSnippet();
01469 $sSelect = $this->_generateSearchStr( $sOXID );
01470 $sSelect .= ( $oStr->strstr( $sSelect, 'where' )?' and ':' where ') . $sWhere . " order by oxobject2category.oxtime limit 1";
01471
01472
01473 if ( !$oCategory->assignRecord( $sSelect ) ) {
01474
01475 $sSelect = $this->_generateSearchStr( $sOXID, true );
01476 $sSelect .= ( $oStr->strstr( $sSelect, 'where' )?' and ':' where ') . $sWhere . " limit 1";
01477
01478
01479 if ( !$oCategory->assignRecord( $sSelect ) ) {
01480 $oCategory = null;
01481 }
01482 }
01483
01484 $this->_aCategoryCache[ $sOXID ] = $oCategory;
01485 stopPRofile( 'getCategory' );
01486 } else {
01487
01488 $oCategory = $this->_aCategoryCache[ $sOXID ];
01489 }
01490 }
01491
01492 return $oCategory;
01493 }
01494
01503 public function getCategoryIds( $blActCats = false, $blSkipCache = false )
01504 {
01505 if ( isset( self::$_aArticleCats[$this->getId()] ) && !$blSkipCache ) {
01506 return self::$_aArticleCats[$this->getId()];
01507 }
01508
01509
01510 $sOXID = $this->getId();
01511
01512 $aRet = $this->_getArticleCategories( $sOXID, $blActCats );
01513
01514 if (isset( $this->oxarticles__oxparentid->value) && $this->oxarticles__oxparentid->value) {
01515 $aRet = array_merge( $aRet, $this->_getArticleCategories( $this->oxarticles__oxparentid->value, $blActCats ) );
01516 }
01517
01518
01519 $sSql = $this->getSqlForPriceCategories();
01520
01521 $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
01522 $rs = $oDb->select( $sSql );
01523
01524
01525 if ($rs != false && $rs->recordCount() > 0) {
01526 while (!$rs->EOF) {
01527
01528 if ( is_array( $rs->fields ) ) {
01529 $rs->fields = array_change_key_case( $rs->fields, CASE_LOWER );
01530 }
01531
01532
01533 if ( !$aRet[$rs->fields['oxid']] ) {
01534 $aRet[] = $rs->fields['oxid'];
01535 }
01536 $rs->moveNext();
01537 }
01538 }
01539
01540 return self::$_aArticleCats[$this->getId()] = $aRet;
01541 }
01542
01551 protected function _getArticleCategories( $sOXID, $blActCats = false )
01552 {
01553
01554 $sSql = $this->_getSelectCatIds( $sOXID, $blActCats );
01555 $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
01556 $rs = $oDb->select( $sSql );
01557
01558
01559 $aRet = array();
01560
01561 if ($rs != false && $rs->recordCount() > 0) {
01562 while (!$rs->EOF) {
01563 $aRet[] = $rs->fields['oxcatnid'];
01564 $rs->moveNext();
01565 }
01566 }
01567
01568 return $aRet;
01569 }
01570
01579 protected function _getSelectCatIds( $sOXID, $blActCats = false )
01580 {
01581 $sO2CView = $this->_getObjectViewName('oxobject2category');
01582 $sCatView = $this->_getObjectViewName('oxcategories');
01583 $sSelect = "select oxobject2category.oxcatnid as oxcatnid from $sO2CView as oxobject2category left join $sCatView as oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
01584 $sSelect .= 'where oxobject2category.oxobjectid='.oxDb::getDb()->quote($sOXID).' and oxcategories.oxid is not null and oxcategories.oxactive = 1 ';
01585 if ( $blActCats ) {
01586 $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 ";
01587 }
01588 $sSelect .= 'order by oxobject2category.oxtime ';
01589 return $sSelect;
01590 }
01591
01601 public function getVendor( $blShopCheck = true )
01602 {
01603 if ( ( $sVendorId = $this->getVendorId() ) ) {
01604 $oVendor = oxNew( 'oxvendor' );
01605 } elseif ( !$blShopCheck && $this->oxarticles__oxvendorid->value ) {
01606 $oVendor = oxNew( 'oxi18n' );
01607 $oVendor->init('oxvendor');
01608 $oVendor->setReadOnly( true );
01609 $sVendorId = $this->oxarticles__oxvendorid->value;
01610 }
01611 if ( $sVendorId && $oVendor->load( $sVendorId ) && $oVendor->oxvendor__oxactive->value ) {
01612
01613 return $oVendor;
01614 }
01615 return null;
01616 }
01617
01625 public function getVendorId( $blForceReload = false )
01626 {
01627 $sVendorId = false;
01628 if ( $this->oxarticles__oxvendorid->value ) {
01629 $sVendorId = $this->oxarticles__oxvendorid->value;
01630
01631 }
01632 return $sVendorId;
01633 }
01634
01642 public function getManufacturerId( $blForceReload = false )
01643 {
01644 $sManufacturerId = false;
01645 if ( $this->oxarticles__oxmanufacturerid->value ) {
01646
01647 $sManufacturerId = $this->oxarticles__oxmanufacturerid->value;
01648
01649 }
01650 return $sManufacturerId;
01651 }
01652
01662 public function getManufacturer( $blShopCheck = true )
01663 {
01664 $oManufacturer = oxNew( 'oxmanufacturer' );;
01665 if ( !( $sManufacturerId = $this->getManufacturerId() ) &&
01666 !$blShopCheck && $this->oxarticles__oxmanufacturerid->value ) {
01667 $oManufacturer->setReadOnly( true );
01668 $sManufacturerId = $this->oxarticles__oxmanufacturerid->value;
01669 }
01670
01671 if ( $sManufacturerId && $oManufacturer->load( $sManufacturerId ) ) {
01672 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadManufacturerTree' ) ) {
01673 $oManufacturer->setReadOnly( true );
01674 }
01675 $oManufacturer = $oManufacturer->oxmanufacturers__oxactive->value ? $oManufacturer : null;
01676 } else {
01677 $oManufacturer = null;
01678 }
01679
01680 return $oManufacturer;
01681 }
01682
01690 public function inCategory( $sCatNid)
01691 {
01692 return in_array( $sCatNid, $this->getCategoryIds());
01693 }
01694
01703 public function isAssignedToCategory( $sCatId )
01704 {
01705
01706 $sOXID = $this->getId();
01707 if ( isset( $this->oxarticles__oxparentid->value) && $this->oxarticles__oxparentid->value) {
01708 $sOXID = $this->oxarticles__oxparentid->value;
01709 }
01710
01711 $oDb = oxDb::getDb();
01712 $sSelect = $this->_generateSelectCatStr( $sOXID, $sCatId);
01713 $sOXID = $oDb->getOne( $sSelect );
01714
01715 if ( isset( $sOXID) && $sOXID) {
01716 return true;
01717 }
01718
01719
01720 if ( $this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) && $this->_blLoadPrice ) {
01721 $dPriceFromTo = $this->getPrice()->getBruttoPrice();
01722 if ( $dPriceFromTo > 0) {
01723 $sSelect = $this->_generateSelectCatStr( $sOXID, $sCatId, $dPriceFromTo);
01724 $sOXID = $oDb->getOne( $sSelect );
01725
01726 if ( isset( $sOXID) && $sOXID) {
01727 return true;
01728 }
01729 }
01730 }
01731 return false;
01732 }
01733
01739 public function getTPrice()
01740 {
01741 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
01742 return;
01743 }
01744
01745
01746 if ( $this->_oTPrice !== null ) {
01747 return $this->_oTPrice;
01748 }
01749
01750 $oPrice = $this->_getPriceObject();
01751
01752 $dBasePrice = $this->oxarticles__oxtprice->value;
01753 $dBasePrice = $this->_preparePrice( $dBasePrice, $this->getArticleVat() );
01754
01755 $oPrice->setPrice( $dBasePrice );
01756
01757 $this->_applyVat( $oPrice, $this->getArticleVat() );
01758 $this->_applyCurrency( $oPrice );
01759
01760 if ( $this->isParentNotBuyable() ) {
01761
01762 $oPrice2 = $this->getVarMinPrice();
01763 } else {
01764
01765 $oPrice2 = $this->getPrice();
01766 }
01767
01768 if ( $oPrice->getPrice() <= $oPrice2->getPrice() ) {
01769
01770 return;
01771 }
01772
01773 $this->_oTPrice = $oPrice;
01774
01775 return $this->_oTPrice;
01776 }
01777
01783 public function skipDiscounts()
01784 {
01785
01786 if ( $this->_blSkipDiscounts !== null ) {
01787 return $this->_blSkipDiscounts;
01788 }
01789
01790 if ( $this->oxarticles__oxskipdiscounts->value ) {
01791 return true;
01792 }
01793
01794
01795 $this->_blSkipDiscounts = false;
01796 if ( oxRegistry::get("oxDiscountList")->hasSkipDiscountCategories() ) {
01797
01798 $oDb = oxDb::getDb();
01799 $sO2CView = getViewName( 'oxobject2category', $this->getLanguage() );
01800 $sViewName = getViewName( 'oxcategories', $this->getLanguage() );
01801 $sSelect = "select 1 from $sO2CView as $sO2CView left join {$sViewName} on {$sViewName}.oxid = $sO2CView.oxcatnid
01802 where $sO2CView.oxobjectid=".$oDb->quote( $this->getId() )." and {$sViewName}.oxactive = 1 and {$sViewName}.oxskipdiscounts = '1' ";
01803 $this->_blSkipDiscounts = ( $oDb->getOne( $sSelect ) == 1 );
01804 }
01805
01806 return $this->_blSkipDiscounts;
01807 }
01808
01816 public function setPrice(oxPrice $oPrice)
01817 {
01818 $this->_oPrice = $oPrice;
01819 }
01820
01829 public function getBasePrice( $dAmount = 1 )
01830 {
01831
01832
01833
01834
01835 $myConfig = $this->getConfig();
01836 if( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice )
01837 return;
01838
01839
01840 $dPrice = $this->_getAmountPrice( $dAmount );
01841
01842
01843 return $dPrice;
01844 }
01845
01853 public function getPrice( $dAmount = 1 )
01854 {
01855 $myConfig = $this->getConfig();
01856
01857 if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
01858 return;
01859 }
01860
01861
01862 if ( $dAmount != 1 || $this->_oPrice === null ) {
01863
01864
01865 $dBasePrice = $this->getBasePrice( $dAmount );
01866 $dBasePrice = $this->_preparePrice( $dBasePrice, $this->getArticleVat() );
01867
01868 $oPrice = $this->_getPriceObject();
01869
01870 $oPrice->setPrice( $dBasePrice );
01871
01872
01873 if ( !$this->_blCalcPrice && $dAmount == 1 ) {
01874 return $this->_oPrice = $oPrice;
01875 }
01876
01877 $this->_calculatePrice( $oPrice );
01878 if ( $dAmount != 1 ) {
01879 return $oPrice;
01880 }
01881
01882 $this->_oPrice = $oPrice;
01883 }
01884 return $this->_oPrice;
01885 }
01886
01895 protected function _calculatePrice( $oPrice, $dVat = null )
01896 {
01897
01898 if ( isset( $dVat ) || !$this->getConfig()->getConfigParam( 'bl_perfCalcVatOnlyForBasketOrder' ) ) {
01899 $this->_applyVAT( $oPrice, isset( $dVat ) ? $dVat : $this->getArticleVat() );
01900 }
01901
01902
01903 $this->_applyCurrency( $oPrice );
01904
01905 if ( !$this->skipDiscounts() ) {
01906 $oDiscountList = oxRegistry::get("oxDiscountList");
01907 $aDiscounts = $oDiscountList->getArticleDiscounts( $this, $this->getArticleUser() );
01908
01909 reset( $aDiscounts );
01910 foreach ( $aDiscounts as $oDiscount ) {
01911 $oPrice->setDiscount($oDiscount->getAddSum(), $oDiscount->getAddSumType());
01912 }
01913 $oPrice->calculateDiscount();
01914 }
01915
01916 return $oPrice;
01917 }
01918
01926 public function setArticleUser($oUser)
01927 {
01928 $this->_oUser = $oUser;
01929 }
01930
01936 public function getArticleUser()
01937 {
01938 if ($this->_oUser) {
01939 return $this->_oUser;
01940 }
01941 return $this->getUser();
01942 }
01943
01953 public function getBasketPrice( $dAmount, $aSelList, $oBasket )
01954 {
01955 $oUser = $oBasket->getBasketUser();
01956 $this->setArticleUser( $oUser );
01957
01958 $oBasketPrice = $this->_getPriceObject( $oBasket->isCalculationModeNetto() );
01959
01960
01961 $dBasePrice = $this->getBasePrice( $dAmount );
01962
01963 $dBasePrice = $this->_modifySelectListPrice( $dBasePrice, $aSelList );
01964 $dBasePrice = $this->_preparePrice( $dBasePrice, $this->getArticleVat(), $oBasket->isCalculationModeNetto() );
01965
01966
01967
01968
01969 $oBasketPrice->setPrice( $dBasePrice );
01970
01971 $dVat = oxRegistry::get("oxVatSelector")->getBasketItemVat( $this, $oBasket );
01972 $this->_calculatePrice( $oBasketPrice, $dVat );
01973
01974
01975 return $oBasketPrice;
01976 }
01977
01986 public function delete( $sOXID = null )
01987 {
01988 if ( !$sOXID ) {
01989 $sOXID = $this->getId();
01990 }
01991 if ( !$sOXID ) {
01992 return false;
01993 }
01994
01995
01996
01997
01998 $this->_deleteVariantRecords( $sOXID );
01999 $this->load( $sOXID );
02000 $this->_deletePics();
02001 $this->_onChangeResetCounts( $sOXID, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
02002
02003
02004 parent::delete( $sOXID );
02005
02006 $rs = $this->_deleteRecords( $sOXID );
02007
02008 oxRegistry::get("oxSeoEncoderArticle")->onDeleteArticle($this);
02009
02010 $this->onChange( ACTION_DELETE, $sOXID, $this->oxarticles__oxparentid->value );
02011
02012 return $rs->EOF;
02013 }
02014
02023 public function reduceStock($dAmount, $blAllowNegativeStock = false)
02024 {
02025 $this->beforeUpdate();
02026
02027 $iStockCount = $this->oxarticles__oxstock->value - $dAmount;
02028 if (!$blAllowNegativeStock && ($iStockCount < 0)) {
02029 $dAmount += $iStockCount;
02030 $iStockCount = 0;
02031 }
02032 $this->oxarticles__oxstock = new oxField($iStockCount);
02033
02034 $oDb = oxDb::getDb();
02035 $oDb->execute( 'update oxarticles set oxarticles.oxstock = '.$oDb->quote( $iStockCount ).' where oxarticles.oxid = '.$oDb->quote( $this->getId() ) );
02036 $this->onChange( ACTION_UPDATE_STOCK );
02037 return $dAmount;
02038 }
02039
02048 public function updateSoldAmount( $dAmount = 0 )
02049 {
02050 if ( !$dAmount ) {
02051 return;
02052 }
02053
02054 $this->beforeUpdate();
02055
02056
02057 if ( !$this->oxarticles__oxparentid->value ) {
02058
02059 $dAmount = (double) $dAmount;
02060 $oDb = oxDb::getDb();
02061 $rs = $oDb->execute( "update oxarticles set oxarticles.oxsoldamount = oxarticles.oxsoldamount + $dAmount where oxarticles.oxid = ".$oDb->quote($this->oxarticles__oxid->value));
02062 } elseif ( $this->oxarticles__oxparentid->value) {
02063
02064 $oUpdateArticle = $this->getParentArticle();
02065 $oUpdateArticle->updateSoldAmount( $dAmount );
02066 }
02067
02068 $this->onChange( ACTION_UPDATE );
02069
02070 return $rs;
02071 }
02072
02078 public function disableReminder()
02079 {
02080 $oDb = oxDb::getDb();
02081 return $oDb->execute( "update oxarticles set oxarticles.oxremindactive = 2 where oxarticles.oxid = ".$oDb->quote($this->oxarticles__oxid->value));
02082 }
02083
02089 public function save()
02090 {
02091 if ( ( $blRet = parent::save() ) ) {
02092
02093 $this->_saveArtLongDesc();
02094 }
02095
02096 return $blRet;
02097 }
02098
02104 public function resetParent()
02105 {
02106 $sParentId = $this->oxarticles__oxparentid;
02107 $this->oxarticles__oxparentid = new oxField( '', oxField::T_RAW );
02108 $this->_blAllowEmptyParentId = true;
02109 $this->save();
02110 $this->_blAllowEmptyParentId = false;
02111
02112 if ( $sParentId !== '' ) {
02113 $this->onChange( ACTION_UPDATE, null, $sParentId );
02114 }
02115 }
02116
02117
02124 public function getPictureGallery()
02125 {
02126 $myConfig = $this->getConfig();
02127
02128
02129 $blMorePic = false;
02130 $aArtPics = array();
02131 $aArtIcons = array();
02132 $iActPicId = 1;
02133 $sActPic = $this->getPictureUrl( $iActPicId );
02134
02135 if ( oxConfig::getParameter( 'actpicid' ) ) {
02136 $iActPicId = oxConfig::getParameter('actpicid');
02137 }
02138
02139 $oStr = getStr();
02140 $iCntr = 0;
02141 $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
02142 $blCheckActivePicId = true;
02143
02144 for ( $i = 1; $i <= $iPicCount; $i++) {
02145 $sPicVal = $this->getPictureUrl( $i );
02146 $sIcoVal = $this->getIconUrl( $i );
02147 if ( !$oStr->strstr($sIcoVal, 'nopic_ico.jpg') && !$oStr->strstr($sIcoVal, 'nopic.jpg') &&
02148 !$oStr->strstr($sPicVal, 'nopic_ico.jpg') && !$oStr->strstr($sPicVal, 'nopic.jpg') ) {
02149 if ($iCntr) {
02150 $blMorePic = true;
02151 }
02152 $aArtIcons[$i]= $sIcoVal;
02153 $aArtPics[$i]= $sPicVal;
02154 $iCntr++;
02155
02156 if ($iActPicId == $i) {
02157 $sActPic = $sPicVal;
02158 $blCheckActivePicId = false;
02159 }
02160
02161 } else if ( $blCheckActivePicId && $iActPicId <= $i) {
02162
02163
02164 $iActPicId++;
02165 }
02166 }
02167
02168 $blZoomPic = false;
02169 $aZoomPics = array();
02170 $iZoomPicCount = $myConfig->getConfigParam( 'iPicCount' );
02171
02172 for ( $j = 1,$c = 1; $j <= $iZoomPicCount; $j++) {
02173 $sVal = $this->getZoomPictureUrl($j);
02174
02175 if ( $sVal && !$oStr->strstr($sVal, 'nopic.jpg')) {
02176 $blZoomPic = true;
02177 $aZoomPics[$c]['id'] = $c;
02178 $aZoomPics[$c]['file'] = $sVal;
02179
02180 if (!$sVal) {
02181 $aZoomPics[$c]['file'] = "nopic.jpg";
02182 }
02183 $c++;
02184 }
02185 }
02186
02187 $aPicGallery = array('ActPicID' => $iActPicId,
02188 'ActPic' => $sActPic,
02189 'MorePics' => $blMorePic,
02190 'Pics' => $aArtPics,
02191 'Icons' => $aArtIcons,
02192 'ZoomPic' => $blZoomPic,
02193 'ZoomPics' => $aZoomPics);
02194
02195 return $aPicGallery;
02196 }
02197
02211 public function onChange($sAction = null, $sOXID = null, $sParentID = null)
02212 {
02213 $myConfig = $this->getConfig();
02214
02215 if (!isset($sOXID)) {
02216 if ( $this->getId()) {
02217 $sOXID = $this->getId();
02218 }
02219 if (!isset ($sOXID)) {
02220 $sOXID = $this->oxarticles__oxid->value;
02221 }
02222 if ($this->oxarticles__oxparentid->value) {
02223 $sParentID = $this->oxarticles__oxparentid->value;
02224 }
02225 }
02226 if (!isset($sOXID)) {
02227 return;
02228 }
02229
02230
02231 if ( $myConfig->getConfigParam( 'blUseStock' ) ) {
02232
02233
02234 if (!isset($sParentID)) {
02235 $oDb = oxDb::getDb();
02236 $sQ = 'select oxparentid from oxarticles where oxid = '.$oDb->quote($sOXID);
02237 $sParentID = $oDb->getOne( $sQ );
02238 }
02239
02240 if ($sParentID) {
02241 $this->_onChangeUpdateStock($sParentID);
02242 }
02243 }
02244
02245
02246 if ($sParentID) {
02247 $this->_onChangeUpdateVarCount($sParentID);
02248 }
02249
02250 $sId = ( $sParentID ) ? $sParentID : $sOXID;
02251 $this->_setVarMinMaxPrice( $sId );
02252
02253
02254
02255 if ( $sAction === ACTION_UPDATE_STOCK ) {
02256 $this->_onChangeStockResetCount( $sOXID );
02257 }
02258
02259 }
02260
02267 public function getCustomVAT()
02268 {
02269 if ( isset($this->oxarticles__oxvat->value) ) {
02270 return $this->oxarticles__oxvat->value;
02271 }
02272 }
02273
02282 public function checkForStock( $dAmount, $dArtStockAmount = 0 )
02283 {
02284 $myConfig = $this->getConfig();
02285 if ( !$myConfig->getConfigParam( 'blUseStock' ) ) {
02286 return true;
02287 }
02288
02289 $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
02290
02291 $sQ = 'select oxstock, oxstockflag from oxarticles where oxid = '.$oDb->quote( $this->getId() );
02292 $rs = $oDb->select( $sQ );
02293
02294 $iOnStock = 0;
02295 $iStockFlag = 0;
02296 if ( $rs !== false && $rs->recordCount() > 0 ) {
02297 $iOnStock = $rs->fields['oxstock'] - $dArtStockAmount;
02298 $iStockFlag = $rs->fields['oxstockflag'];
02299
02300
02301 if ( $iStockFlag == 1 || $iStockFlag == 4) {
02302 return true;
02303 }
02304 if ( !$myConfig->getConfigParam( 'blAllowUnevenAmounts' ) ) {
02305 $iOnStock = floor( $iOnStock );
02306 }
02307 }
02308 if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
02309 $iOnStock += $this->getSession()->getBasketReservations()->getReservedAmount($this->getId());
02310 }
02311 if ( $iOnStock >= $dAmount ) {
02312 return true;
02313 } else {
02314 if ( $iOnStock > 0 ) {
02315 return $iOnStock;
02316 } else {
02317 $oEx = oxNew( 'oxArticleInputException' );
02318 $oEx->setMessage( 'EXCEPTION_ARTICLE_ARTICELNOTBUYABLE' );
02319 oxRegistry::get("oxUtilsView")->addErrorToDisplay( $oEx );
02320 return false;
02321 }
02322 }
02323 }
02324
02325
02331 public function getLongDescription()
02332 {
02333 if ( $this->_oLongDesc === null ) {
02334
02335 $this->_oLongDesc = new oxField();
02336
02337
02338
02339 $sOxid = $this->getId();
02340 $sViewName = getViewName( 'oxartextends', $this->getLanguage() );
02341
02342 $oDb = oxDb::getDb();
02343 $sDbValue = $oDb->getOne( "select oxlongdesc from {$sViewName} where oxid = " . $oDb->quote( $sOxid ) );
02344
02345 if ( $sDbValue != false ) {
02346 $this->_oLongDesc->setValue( $sDbValue, oxField::T_RAW );
02347 } elseif ( $this->oxarticles__oxparentid->value ) {
02348 if ( !$this->isAdmin() || $this->_blLoadParentData ) {
02349 $this->_oLongDesc->setValue( $this->getParentArticle()->getLongDescription()->getRawValue(), oxField::T_RAW );
02350 }
02351 }
02352 }
02353 return $this->_oLongDesc;
02354 }
02355
02362 public function getLongDesc()
02363 {
02364 return oxRegistry::get("oxUtilsView")->parseThroughSmarty( $this->getLongDescription()->getRawValue(), $this->getId().$this->getLanguage(), null, true );
02365 }
02366
02374 public function setArticleLongDesc( $sDesc )
02375 {
02376
02377
02378 $this->_oLongDesc = new oxField( $sDesc, oxField::T_RAW );
02379 $this->oxarticles__oxlongdesc = new oxField( $sDesc, oxField::T_RAW );
02380 }
02381
02387 public function getAttributes()
02388 {
02389 if ( $this->_oAttributeList === null ) {
02390 $this->_oAttributeList = oxNew( 'oxattributelist' );
02391 $this->_oAttributeList->loadAttributes( $this->getId(), $this->getParentId() );
02392 }
02393
02394 return $this->_oAttributeList;
02395 }
02396
02402 public function getAttributesDisplayableInBasket()
02403 {
02404 if ( $this->_oAttributeList === null ) {
02405 $this->_oAttributeList = oxNew( 'oxattributelist' );
02406 $this->_oAttributeList->loadAttributesDisplayableInBasket( $this->getId(), $this->getParentId() );
02407 }
02408
02409 return $this->_oAttributeList;
02410 }
02411
02412
02421 public function appendLink( $sAddParams, $iLang = null )
02422 {
02423 if ( $sAddParams ) {
02424 if ( $iLang === null ) {
02425 $iLang = $this->getLanguage();
02426 }
02427
02428 $this->_aSeoAddParams[$iLang] = isset( $this->_aSeoAddParams[$iLang] ) ? $this->_aSeoAddParams[$iLang] . "&" : "";
02429 $this->_aSeoAddParams[$iLang] .= $sAddParams;
02430 }
02431 }
02432
02441 public function getBaseSeoLink( $iLang, $blMain = false )
02442 {
02443 $oEncoder = oxRegistry::get("oxSeoEncoderArticle");
02444 if ( !$blMain ) {
02445 return $oEncoder->getArticleUrl( $this, $iLang, $this->getLinkType() );
02446 }
02447 return $oEncoder->getArticleMainUrl( $this, $iLang );
02448 }
02449
02458 public function getLink( $iLang = null, $blMain = false )
02459 {
02460 if ( !oxRegistry::getUtils()->seoIsActive() ) {
02461 return $this->getStdLink( $iLang );
02462 }
02463
02464 if ( $iLang === null ) {
02465 $iLang = $this->getLanguage();
02466 }
02467
02468 $iLinkType = $this->getLinkType();
02469 if ( !isset( $this->_aSeoUrls[$iLang][$iLinkType] ) ) {
02470 $this->_aSeoUrls[$iLang][$iLinkType] = $this->getBaseSeoLink( $iLang, $blMain );
02471 }
02472
02473 $sUrl = $this->_aSeoUrls[$iLang][$iLinkType];
02474 if ( isset($this->_aSeoAddParams[$iLang])) {
02475 $sUrl .= ( ( strpos( $sUrl.$this->_aSeoAddParams[$iLang], '?' ) === false ) ? '?' : '&' ).$this->_aSeoAddParams[$iLang];
02476 }
02477
02478 return $sUrl;
02479 }
02480
02489 public function getMainLink( $iLang = null )
02490 {
02491 return $this->getLink( $iLang, true );
02492 }
02493
02501 public function setLinkType( $iType )
02502 {
02503
02504 $this->_sDetailLink = null;
02505
02506
02507 $this->_iLinkType = (int) $iType;
02508 }
02509
02515 public function getLinkType()
02516 {
02517 return $this->_iLinkType;
02518 }
02519
02528 public function appendStdLink( $sAddParams, $iLang = null )
02529 {
02530 if ( $sAddParams ) {
02531 if ( $iLang === null ) {
02532 $iLang = $this->getLanguage();
02533 }
02534
02535 $this->_aStdAddParams[$iLang] = isset( $this->_aStdAddParams[$iLang] ) ? $this->_aStdAddParams[$iLang] . "&" : "";
02536 $this->_aStdAddParams[$iLang] .= $sAddParams;
02537 }
02538 }
02539
02549 public function getBaseStdLink( $iLang, $blAddId = true, $blFull = true )
02550 {
02551 $sUrl = '';
02552 if ( $blFull ) {
02553
02554 $sUrl = $this->getConfig()->getShopUrl( $iLang, false );
02555 }
02556
02557 $sUrl .= "index.php?cl=details" . ( $blAddId ? "&anid=".$this->getId() : "" );
02558 return $sUrl . ( isset( $this->_aStdAddParams[$iLang] ) ? "&". $this->_aStdAddParams[$iLang] : "" );
02559 }
02560
02569 public function getStdLink( $iLang = null, $aParams = array() )
02570 {
02571 if ( $iLang === null ) {
02572 $iLang = $this->getLanguage();
02573 }
02574
02575 if ( !isset( $this->_aStdUrls[$iLang] ) ) {
02576 $this->_aStdUrls[$iLang] = $this->getBaseStdLink( $iLang );
02577 }
02578
02579 return oxRegistry::get("oxUtilsUrl")->processUrl( $this->_aStdUrls[$iLang], true, $aParams, $iLang );
02580 }
02581
02591 public function getStdTagLink( $sTag )
02592 {
02593 $oArticleTags = oxNew('oxarticletaglist');
02594 $oArticleTags->setArticleId( $this->getId() );
02595 return $oArticleTags->getStdTagLink($sTag);
02596 }
02597
02605 public function getTags()
02606 {
02607 $oArticleTags = oxNew('oxarticletaglist');
02608 $oArticleTags->load( $this->getId() );
02609 return $oArticleTags->get()->__toString();
02610 }
02611
02621 public function saveTags($sTags)
02622 {
02623
02624 if ( !$this->allowDerivedUpdate() ) {
02625 return false;
02626 }
02627 $oArticleTags = oxNew('oxarticletaglist');
02628 $oArticleTags->setArticleId( $this->getId() );
02629 $oArticleTags->set( $sTags );
02630 $oArticleTags->save();
02631 }
02632
02642 public function addTag($sTag)
02643 {
02644 $oArticleTags = oxNew('oxarticletaglist');
02645 $oArticleTags->load( $this->getId() );
02646 $oArticleTags->addTag( $sTag );
02647 if ( $oArticleTags->save() ) {
02648 return true;
02649 }
02650 return false;
02651 }
02652
02658 public function getMediaUrls()
02659 {
02660 if ( $this->_aMediaUrls === null ) {
02661 $this->_aMediaUrls = oxNew("oxlist");
02662 $this->_aMediaUrls->init("oxmediaurl");
02663 $this->_aMediaUrls->getBaseObject()->setLanguage( $this->getLanguage() );
02664
02665 $sViewName = getViewName( "oxmediaurls", $this->getLanguage() );
02666 $sQ = "select * from {$sViewName} where oxobjectid = '".$this->getId()."'";
02667 $this->_aMediaUrls->selectString($sQ);
02668 }
02669 return $this->_aMediaUrls;
02670 }
02671
02677 public function getDynImageDir()
02678 {
02679 return $this->_sDynImageDir;
02680 }
02681
02687 public function getDispSelList()
02688 {
02689 if ($this->_aDispSelList === null) {
02690 if ( $this->getConfig()->getConfigParam( 'bl_perfLoadSelectLists' ) && $this->getConfig()->getConfigParam( 'bl_perfLoadSelectListsInAList' ) ) {
02691 $this->_aDispSelList = $this->getSelectLists();
02692 }
02693 }
02694 return $this->_aDispSelList;
02695 }
02696
02702 public function getMoreDetailLink()
02703 {
02704 if ( $this->_sMoreDetailLink == null ) {
02705
02706
02707 $this->_sMoreDetailLink = $this->getConfig()->getShopHomeURL() . 'cl=moredetails';
02708
02709
02710 if ( $sActCat = oxConfig::getParameter( 'cnid' ) ) {
02711 $this->_sMoreDetailLink .= '&cnid='.$sActCat;
02712 }
02713 $this->_sMoreDetailLink .= '&anid='.$this->getId();
02714 $this->_sMoreDetailLink = $this->_sMoreDetailLink;
02715 }
02716
02717 return $this->_sMoreDetailLink;
02718 }
02719
02725 public function getToBasketLink()
02726 {
02727 if ( $this->_sToBasketLink == null ) {
02728 $myConfig = $this->getConfig();
02729
02730 if ( oxRegistry::getUtils()->isSearchEngine() ) {
02731 $this->_sToBasketLink = $this->getLink();
02732 } else {
02733
02734 $this->_sToBasketLink = $myConfig->getShopHomeURL();
02735
02736
02737 $sActClass = oxConfig::getParameter( 'cl' );
02738 if ( $sActClass == 'thankyou') {
02739 $sActClass = 'basket';
02740 }
02741 $this->_sToBasketLink .= 'cl='.$sActClass;
02742
02743
02744 if ( $sActCat = oxConfig::getParameter( 'cnid' ) ) {
02745 $this->_sToBasketLink .= '&cnid='.$sActCat;
02746 }
02747
02748 $this->_sToBasketLink .= '&fnc=tobasket&aid='.$this->getId().'&anid='.$this->getId();
02749
02750 if ( $sTpl = basename( oxConfig::getParameter( 'tpl' ) ) ) {
02751 $this->_sToBasketLink .= '&tpl='.$sTpl;
02752 }
02753 }
02754 }
02755
02756 return $this->_sToBasketLink;
02757 }
02758
02764 public function getStockStatus()
02765 {
02766 return $this->_iStockStatus;
02767 }
02768
02774 public function getDeliveryDate()
02775 {
02776 if ( $this->oxarticles__oxdelivery->value != '0000-00-00') {
02777 return oxRegistry::get("oxUtilsDate")->formatDBDate( $this->oxarticles__oxdelivery->value);
02778 }
02779 return false;
02780 }
02781
02787 public function getFTPrice()
02788 {
02789
02790 if ( $oPrice = $this->getTPrice() ) {
02791 if ( $dPrice = $this->_getPriceForView( $oPrice ) ) {
02792 return oxRegistry::getLang()->formatCurrency( $dPrice );
02793 }
02794 }
02795 }
02796
02802 public function getFPrice()
02803 {
02804 if ( $oPrice = $this->getPrice() ) {
02805 $dPrice = $this->_getPriceForView( $oPrice );
02806 return oxRegistry::getLang()->formatCurrency( $dPrice );
02807 }
02808 }
02809
02816 public function resetRemindStatus()
02817 {
02818 if ( $this->oxarticles__oxremindactive->value == 2 &&
02819 $this->oxarticles__oxremindamount->value <= $this->oxarticles__oxstock->value ) {
02820 $this->oxarticles__oxremindactive->value = 1;
02821 }
02822 }
02823
02829 public function getFNetPrice()
02830 {
02831 if ( $oPrice = $this->getPrice() ) {
02832 return oxRegistry::getLang()->formatCurrency( $oPrice->getNettoPrice() );
02833 }
02834 }
02835
02843 public function getPricePerUnit()
02844 {
02845 return $this->getFUnitPrice();
02846 }
02847
02853 public function isParentNotBuyable()
02854 {
02855 return $this->_blNotBuyableParent;
02856 }
02857
02863 public function isNotBuyable()
02864 {
02865 return $this->_blNotBuyable;
02866 }
02867
02875 public function setBuyableState( $blBuyable = false )
02876 {
02877 $this->_blNotBuyable = !$blBuyable;
02878 }
02879
02887 public function setSelectlist( $aSelList )
02888 {
02889 $this->_aDispSelList = $aSelList;
02890 }
02891
02899 public function getPictureUrl( $iIndex = 1 )
02900 {
02901 if ( $iIndex ) {
02902 $sImgName = false;
02903 if ( !$this->_isFieldEmpty( "oxarticles__oxpic".$iIndex ) ) {
02904 $sImgName = basename( $this->{"oxarticles__oxpic$iIndex"}->value );
02905 }
02906
02907 $sSize = $this->getConfig()->getConfigParam( 'aDetailImageSizes' );
02908 return oxRegistry::get("oxPictureHandler")->getProductPicUrl( "product/{$iIndex}/", $sImgName, $sSize, 'oxpic'.$iIndex );
02909 }
02910 }
02911
02920 public function getIconUrl( $iIndex = 0 )
02921 {
02922 $sImgName = false;
02923 $sDirname = "product/1/";
02924 if ( $iIndex && !$this->_isFieldEmpty( "oxarticles__oxpic{$iIndex}" ) ) {
02925 $sImgName = basename( $this->{"oxarticles__oxpic$iIndex"}->value );
02926 $sDirname = "product/{$iIndex}/";
02927 } elseif ( !$this->_isFieldEmpty( "oxarticles__oxicon" ) ) {
02928 $sImgName = basename( $this->oxarticles__oxicon->value );
02929 $sDirname = "product/icon/";
02930 } elseif ( !$this->_isFieldEmpty( "oxarticles__oxpic1" ) ) {
02931 $sImgName = basename( $this->oxarticles__oxpic1->value );
02932 }
02933
02934 $sSize = $this->getConfig()->getConfigParam( 'sIconsize' );
02935 return oxRegistry::get("oxPictureHandler")->getProductPicUrl( $sDirname, $sImgName, $sSize, $iIndex );
02936 }
02937
02945 public function getThumbnailUrl( $bSsl = null )
02946 {
02947 $sImgName = false;
02948 $sDirname = "product/1/";
02949 if ( !$this->_isFieldEmpty( "oxarticles__oxthumb" ) ) {
02950 $sImgName = basename( $this->oxarticles__oxthumb->value );
02951 $sDirname = "product/thumb/";
02952 } elseif ( !$this->_isFieldEmpty( "oxarticles__oxpic1" ) ) {
02953 $sImgName = basename( $this->oxarticles__oxpic1->value );
02954 }
02955
02956 $sSize = $this->getConfig()->getConfigParam( 'sThumbnailsize' );
02957 return oxRegistry::get("oxPictureHandler")->getProductPicUrl( $sDirname, $sImgName, $sSize, 0, $bSsl );
02958 }
02959
02967 public function getZoomPictureUrl( $iIndex = '' )
02968 {
02969 $iIndex = (int) $iIndex;
02970 if ( $iIndex > 0 && !$this->_isFieldEmpty( "oxarticles__oxpic".$iIndex ) ) {
02971 $sImgName = basename( $this->{"oxarticles__oxpic".$iIndex}->value );
02972 $sSize = $this->getConfig()->getConfigParam( "sZoomImageSize" );
02973 return oxRegistry::get("oxPictureHandler")->getProductPicUrl( "product/{$iIndex}/", $sImgName, $sSize, 'oxpic'.$iIndex );
02974 }
02975 }
02976
02982 public function getFileUrl()
02983 {
02984 return $this->getConfig()->getPictureUrl( 'media/' );
02985 }
02986
02994 public function getPriceFromPrefix()
02995 {
02996 $sPricePrefix = '';
02997 if ( $this->_blIsRangePrice) {
02998 $sPricePrefix = oxLang::getInstance()->translateString('PRICE_FROM').' ';
02999 }
03000
03001 return $sPricePrefix;
03002 }
03003
03009 protected function _saveArtLongDesc()
03010 {
03011 $myConfig = $this->getConfig();
03012 $sShopId = $myConfig->getShopID();
03013 if (in_array("oxlongdesc", $this->_aSkipSaveFields)) {
03014 return;
03015 }
03016
03017 if ($this->_blEmployMultilanguage) {
03018 $sValue = $this->getLongDescription()->getRawValue();
03019 if ( $sValue !== null ) {
03020 $oArtExt = oxNew('oxI18n');
03021 $oArtExt->init('oxartextends');
03022 $oArtExt->setLanguage((int) $this->getLanguage());
03023 if (!$oArtExt->load($this->getId())) {
03024 $oArtExt->setId($this->getId());
03025 }
03026 $oArtExt->oxartextends__oxlongdesc = new oxField($sValue, oxField::T_RAW);
03027 $oArtExt->save();
03028 }
03029 } else {
03030 $oArtExt = oxNew('oxI18n');
03031 $oArtExt->setEnableMultilang(false);
03032 $oArtExt->init('oxartextends');
03033 $aObjFields = $oArtExt->_getAllFields(true);
03034 if (!$oArtExt->load($this->getId())) {
03035 $oArtExt->setId($this->getId());
03036 }
03037
03038 foreach ($aObjFields as $sKey => $sValue ) {
03039 if ( preg_match('/^oxlongdesc(_(\d{1,2}))?$/', $sKey) ) {
03040 $sField = $this->_getFieldLongName($sKey);
03041
03042 if (isset($this->$sField)) {
03043 $sLongDesc = null;
03044 if ($this->$sField instanceof oxField) {
03045 $sLongDesc = $this->$sField->getRawValue();
03046 } elseif (is_object($this->$sField)) {
03047 $sLongDesc = $this->$sField->value;
03048 }
03049 if (isset($sLongDesc)) {
03050 $sAEField = $oArtExt->_getFieldLongName($sKey);
03051 $oArtExt->$sAEField = new oxField($sLongDesc, oxField::T_RAW);
03052 }
03053 }
03054 }
03055 }
03056 $oArtExt->save();
03057 }
03058 }
03059
03065 protected function _skipSaveFields()
03066 {
03067 $myConfig = $this->getConfig();
03068
03069 $this->_aSkipSaveFields = array();
03070
03071 $this->_aSkipSaveFields[] = 'oxtimestamp';
03072
03073 $this->_aSkipSaveFields[] = 'oxinsert';
03074
03075 if ( !$this->_blAllowEmptyParentId && (!isset( $this->oxarticles__oxparentid->value) || $this->oxarticles__oxparentid->value == '') ) {
03076 $this->_aSkipSaveFields[] = 'oxparentid';
03077 }
03078
03079 }
03080
03090 protected function _mergeDiscounts( $aDiscounts, $aItemDiscounts)
03091 {
03092 foreach ( $aItemDiscounts as $sKey => $oDiscount ) {
03093
03094 if ( array_key_exists ($sKey, $aDiscounts) ) {
03095 $aDiscounts[$sKey]->dDiscount += $oDiscount->dDiscount;
03096 } else {
03097 $aDiscounts[$sKey] = $oDiscount;
03098 }
03099 }
03100 return $aDiscounts;
03101 }
03102
03108 protected function _getGroupPrice()
03109 {
03110 $sPriceSufix = $this->_getUserPriceSufix();
03111 $sVarName = oxarticles__oxprice.$sPriceSufix;
03112 $dPrice = $this->$sVarName->value;
03113
03114
03115 if ( $this->getConfig()->getConfigParam( 'blOverrideZeroABCPrices' ) && (double) $dPrice == 0 ) {
03116 $dPrice = $this->oxarticles__oxprice->value;
03117 }
03118
03119 return $dPrice;
03120 }
03121
03130 protected function _getAmountPrice($dAmount = 1)
03131 {
03132 $myConfig = $this->getConfig();
03133
03134 startProfile( "_getAmountPrice" );
03135
03136 $dPrice = $this->_getGroupPrice();
03137 $oAmtPrices = $this->_getAmountPriceList();
03138 foreach ($oAmtPrices as $oAmPrice) {
03139 if ($oAmPrice->oxprice2article__oxamount->value <= $dAmount
03140 && $dAmount <= $oAmPrice->oxprice2article__oxamountto->value
03141 && $dPrice > $oAmPrice->oxprice2article__oxaddabs->value ) {
03142 $dPrice = $oAmPrice->oxprice2article__oxaddabs->value;
03143 }
03144 }
03145
03146 stopProfile( "_getAmountPrice" );
03147 return $dPrice;
03148 }
03149
03158 protected function _modifySelectListPrice( $dPrice, $aChosenList = null )
03159 {
03160 $myConfig = $this->getConfig();
03161
03162 if ( $myConfig->getConfigParam( 'bl_perfLoadSelectLists' ) && $myConfig->getConfigParam( 'bl_perfUseSelectlistPrice' ) ) {
03163
03164 $aSelLists = $this->getSelectLists();
03165
03166 foreach ( $aSelLists as $key => $aSel) {
03167 if ( isset( $aChosenList[$key]) && isset($aSel[$aChosenList[$key]] ) ) {
03168 $oSel = $aSel[$aChosenList[$key]];
03169 if ( $oSel->priceUnit =='abs' ) {
03170 $dPrice += $oSel->price;
03171 } elseif ( $oSel->priceUnit =='%' ) {
03172 $dPrice += oxPrice::percent( $dPrice, $oSel->price );
03173 }
03174 }
03175 }
03176 }
03177 return $dPrice;
03178 }
03179
03180
03188 protected function _fillAmountPriceList($aAmPriceList)
03189 {
03190 $myConfig = $this->getConfig();
03191 $oLang = oxRegistry::getLang();
03192
03193
03194 foreach ($aAmPriceList as $sId => $oItem) {
03195
03196 $oItemPrice = $this->_getPriceObject();
03197 if ( $oItem->oxprice2article__oxaddabs->value ) {
03198
03199 $dBasePrice = $oItem->oxprice2article__oxaddabs->value;
03200 $dBasePrice = $this->_preparePrice( $dBasePrice, $this->getArticleVat() );
03201
03202 $oItemPrice->setPrice( $dBasePrice );
03203 $this->_calculatePrice( $oItemPrice );
03204
03205 } else {
03206 $dBasePrice = $this->_getGroupPrice();
03207 $dBasePrice = $this->_preparePrice( $dBasePrice, $this->getArticleVat() );
03208 $oItemPrice->setPrice( $dBasePrice );
03209 $oItemPrice->subtractPercent( $oItem->oxprice2article__oxaddperc->value );
03210 }
03211
03212
03213 $aAmPriceList[$sId]->fbrutprice = $oLang->formatCurrency( $this->_getPriceForView( $oItemPrice ) );
03214 }
03215
03216 return $aAmPriceList;
03217 }
03218
03219
03225 protected function _getVariantsIds()
03226 {
03227 $aSelect = array();
03228 if ( ( $sId = $this->getId() ) ) {
03229 $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
03230 $sQ = "select oxid from " . $this->getViewName( true ) . " where oxparentid = ".$oDb->quote( $sId )." and " .
03231 $this->getSqlActiveSnippet( true ) . " order by oxsort";
03232 $oRs = $oDb->select( $sQ );
03233 if ( $oRs != false && $oRs->recordCount() > 0 ) {
03234 while (!$oRs->EOF) {
03235 $aSelect[] = reset( $oRs->fields );
03236 $oRs->moveNext();
03237 }
03238 }
03239 }
03240 return $aSelect;
03241 }
03242
03248 public function getArticleVat()
03249 {
03250 if (!isset($this->_dArticleVat)) {
03251 $this->_dArticleVat = oxRegistry::get("oxVatSelector")->getArticleVat( $this );
03252 }
03253 return $this->_dArticleVat;
03254 }
03255
03264 protected function _applyVAT( oxPrice $oPrice, $dVat )
03265 {
03266 startProfile(__FUNCTION__);
03267 $oPrice->setVAT( $dVat );
03268 if ( ($dVat = oxRegistry::get("oxVatSelector")->getArticleUserVat($this)) !== false ) {
03269 $oPrice->setUserVat( $dVat );
03270 }
03271 stopProfile(__FUNCTION__);
03272 }
03273
03281 public function applyVats( oxPrice $oPrice )
03282 {
03283 $this->_applyVAT($oPrice, $this->getArticleVat() );
03284 }
03285
03293 public function applyDiscountsForVariant( $oPrice )
03294 {
03295
03296 if ( !$this->skipDiscounts() ) {
03297 $oDiscountList = oxRegistry::get("oxDiscountList");
03298 $aDiscounts = $oDiscountList->getArticleDiscounts( $this, $this->getArticleUser() );
03299
03300 reset( $aDiscounts );
03301 foreach ( $aDiscounts as $oDiscount ) {
03302 $oPrice->setDiscount($oDiscount->getAddSum(), $oDiscount->getAddSumType());
03303 }
03304 $oPrice->calculateDiscount();
03305 }
03306 }
03307
03316 protected function _applyCurrency(oxPrice $oPrice, $oCur = null )
03317 {
03318 if ( !$oCur ) {
03319 $oCur = $this->getConfig()->getActShopCurrencyObject();
03320 }
03321
03322 $oPrice->multiply($oCur->rate);
03323 }
03324
03325
03334 protected function _getAttribsString(&$sAttribs, &$iCnt)
03335 {
03336
03337 $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
03338 $sSelect = 'select oxattrid from oxobject2attribute where oxobject2attribute.oxobjectid='.$oDb->quote( $this->getId() );
03339 $sAttribs = '';
03340 $blSep = false;
03341 $rs = $oDb->select( $sSelect);
03342 $iCnt = 0;
03343 if ($rs != false && $rs->recordCount() > 0) {
03344 while (!$rs->EOF) {
03345 if ( $blSep) {
03346 $sAttribs .= ' or ';
03347 }
03348 $sAttribs .= 't1.oxattrid = '.$oDb->quote($rs->fields['oxattrid']).' ';
03349 $blSep = true;
03350 $iCnt++;
03351 $rs->moveNext();
03352 }
03353 }
03354 }
03355
03364 protected function _getSimList($sAttribs, $iCnt)
03365 {
03366 $myConfig = $this->getConfig();
03367 $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
03368
03369
03370 $iAttrPercent = $myConfig->getConfigParam( 'iAttributesPercent' )/100;
03371
03372 if ( !$iAttrPercent || $iAttrPercent < 0 || $iAttrPercent > 1) {
03373 $iAttrPercent = 0.70;
03374 }
03375
03376 $iHitMin = ceil( $iCnt * $iAttrPercent );
03377
03378
03379 $aList= array();
03380 $sSelect = "select oxobjectid, count(*) as cnt from oxobject2attribute as t1 where
03381 ( $sAttribs )
03382 and t1.oxobjectid != ".$oDb->quote( $this->oxarticles__oxid->value )."
03383 group by t1.oxobjectid having count(*) >= $iHitMin ";
03384
03385 $rs = $oDb->selectLimit( $sSelect, 20, 0 );
03386 if ($rs != false && $rs->recordCount() > 0) {
03387 while (!$rs->EOF) {
03388 $oTemp = new stdClass();
03389 $oTemp->cnt = $rs->fields['cnt'];
03390 $oTemp->id = $rs->fields['oxobjectid'];
03391 $aList[] = $oTemp;
03392 $rs->moveNext();
03393 }
03394 }
03395 return $aList;
03396 }
03397
03406 protected function _generateSimListSearchStr($sArticleTable, $aList)
03407 {
03408 $myConfig = $this->getConfig();
03409 $sFieldList = $this->getSelectFields();
03410 $sSearch = "select $sFieldList from $sArticleTable where ".$this->getSqlActiveSnippet()." and $sArticleTable.oxissearch = 1 and $sArticleTable.oxid in ( ";
03411 $blSep = false;
03412 $iCnt = 0;
03413 $oDb = oxDb::getDb();
03414 foreach ( $aList as $oTemp) {
03415 if ( $blSep) {
03416 $sSearch .= ',';
03417 }
03418 $sSearch .= $oDb->quote($oTemp->id);
03419 $blSep = true;
03420 if ( $iCnt >= $myConfig->getConfigParam( 'iNrofSimilarArticles' ) ) {
03421 break;
03422 }
03423 $iCnt++;
03424 }
03425
03426
03427
03428 $sSearch .= ') ';
03429
03430
03431 $sSearch .= ' order by rand() ';
03432
03433 return $sSearch;
03434 }
03435
03444 protected function _generateSearchStr($sOXID, $blSearchPriceCat = false )
03445 {
03446
03447 $sCatView = getViewName( 'oxcategories', $this->getLanguage() );
03448 $sO2CView = getViewName( 'oxobject2category' );
03449
03450
03451 if ( !$blSearchPriceCat ) {
03452 $sSelect = "select {$sCatView}.* from {$sO2CView} as oxobject2category left join {$sCatView} on
03453 {$sCatView}.oxid = oxobject2category.oxcatnid
03454 where oxobject2category.oxobjectid=".oxDb::getDb()->quote($sOXID)." and {$sCatView}.oxid is not null ";
03455 } else {
03456 $sSelect = "select {$sCatView}.* from {$sCatView} where
03457 '{$this->oxarticles__oxprice->value}' >= {$sCatView}.oxpricefrom and
03458 '{$this->oxarticles__oxprice->value}' <= {$sCatView}.oxpriceto ";
03459 }
03460 return $sSelect;
03461 }
03462
03468 protected function _generateSearchStrForCustomerBought()
03469 {
03470 $sArtTable = $this->getViewName();
03471 $sOrderArtTable = getViewName( 'oxorderarticles' );
03472
03473
03474 $sIn = " '{$this->oxarticles__oxid->value}' ";
03475 if ( $this->oxarticles__oxparentid->value ) {
03476
03477
03478 $sIn .= ", '{$this->oxarticles__oxparentid->value}' ";
03479 $sParentIdForVariants = $this->oxarticles__oxparentid->value;
03480
03481 } else {
03482 $sParentIdForVariants = $this->getId();
03483 }
03484
03485
03486 $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
03487 $oRs = $oDb->select( "select oxid from {$sArtTable} where oxparentid = ".$oDb->quote($sParentIdForVariants)." and oxid != ".$oDb->quote($this->oxarticles__oxid->value) );
03488 if ( $oRs != false && $oRs->recordCount() > 0) {
03489 while ( !$oRs->EOF ) {
03490 $sIn .= ", ".$oDb->quote(current( $oRs->fields ))." ";
03491 $oRs->moveNext();
03492 }
03493 }
03494
03495 $iLimit = (int) $this->getConfig()->getConfigParam( 'iNrofCustomerWhoArticles' );
03496 $iLimit = $iLimit?( $iLimit * 10 ): 50;
03497
03498
03499 $sQ = "select distinct {$sArtTable}.* from (
03500 select d.oxorderid as suborderid from {$sOrderArtTable} as d use index ( oxartid ) where d.oxartid in ( {$sIn} ) limit {$iLimit}
03501 ) as suborder
03502 left join {$sOrderArtTable} force index ( oxorderid ) on suborder.suborderid = {$sOrderArtTable}.oxorderid
03503 left join {$sArtTable} on {$sArtTable}.oxid = {$sOrderArtTable}.oxartid
03504 where {$sArtTable}.oxid not in ( {$sIn} )
03505 and ( {$sArtTable}.oxissearch = 1 or {$sArtTable}.oxparentid <> '' ) and ".$this->getSqlActiveSnippet();
03506
03507
03508
03509
03510
03511
03512
03513
03514
03515
03516 return $sQ;
03517 }
03518
03528 protected function _generateSelectCatStr($sOXID, $sCatId, $dPriceFromTo = false)
03529 {
03530 $sCategoryView = getViewName('oxcategories');
03531 $sO2CView = getViewName('oxobject2category');
03532
03533 $oDb = oxDb::getDb();
03534 $sOXID = $oDb->quote($sOXID);
03535 $sCatId = $oDb->quote($sCatId);
03536
03537 if (!$dPriceFromTo) {
03538 $sSelect = "select oxobject2category.oxcatnid from $sO2CView as oxobject2category ";
03539 $sSelect .= "left join $sCategoryView as oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
03540 $sSelect .= "where oxobject2category.oxcatnid=$sCatId and oxobject2category.oxobjectid=$sOXID ";
03541 $sSelect .= "and oxcategories.oxactive = 1 order by oxobject2category.oxtime ";
03542 } else {
03543 $dPriceFromTo = $oDb->quote($dPriceFromTo);
03544 $sSelect = "select oxcategories.oxid from $sCategoryView as oxcategories where ";
03545 $sSelect .= "oxcategories.oxid=$sCatId and $dPriceFromTo >= oxcategories.oxpricefrom and ";
03546 $sSelect .= "$dPriceFromTo <= oxcategories.oxpriceto ";
03547 }
03548 return $sSelect;
03549 }
03550
03556 protected function _getAmountPriceList()
03557 {
03558 if ( $this->_oAmountPriceList === null ) {
03559 $oAmPriceList = oxNew( 'oxAmountPricelist' );
03560
03561 if ( !$this->skipDiscounts() ) {
03562
03563 $oAmPriceList->load( $this );
03564
03565
03566 $oBasePrice = $this->_getGroupPrice();
03567 foreach ( $oAmPriceList as $oAmPrice ) {
03568 if ( $oAmPrice->oxprice2article__oxaddperc->value ) {
03569 $oAmPrice->oxprice2article__oxaddabs = new oxField(oxPrice::percent( $oBasePrice, 100 - $oAmPrice->oxprice2article__oxaddperc->value ), oxField::T_RAW );
03570 }
03571 }
03572
03573 }
03574
03575 $this->_oAmountPriceList = $oAmPriceList;
03576 }
03577
03578 return $this->_oAmountPriceList;
03579 }
03580
03588 protected function _isFieldEmpty( $sFieldName )
03589 {
03590 $mValue = $this->$sFieldName->value;
03591
03592 if ( is_null( $mValue ) ) {
03593 return true;
03594 }
03595
03596 if ( $mValue === '' ) {
03597 return true;
03598 }
03599
03600
03601 $aZeroValueFields = array('oxarticles__oxprice', 'oxarticles__oxvat', 'oxarticles__oxunitquantity');
03602
03603 if (!$mValue && in_array( $sFieldName, $aZeroValueFields ) ) {
03604 return true;
03605 }
03606
03607
03608 if (!strcmp($mValue, '0000-00-00 00:00:00') || !strcmp($mValue, '0000-00-00')) {
03609 return true;
03610 }
03611
03612 $sFieldName = strtolower($sFieldName);
03613
03614 if ( $sFieldName == 'oxarticles__oxicon' && ( strpos($mValue, "nopic_ico.jpg") !== false || strpos($mValue, "nopic.jpg") !== false ) ) {
03615 return true;
03616 }
03617
03618 if ( strpos($mValue, "nopic.jpg") !== false && ($sFieldName == 'oxarticles__oxthumb' || substr($sFieldName, 0, 17) == 'oxarticles__oxpic' || substr($sFieldName, 0, 18) == 'oxarticles__oxzoom') ) {
03619 return true;
03620 }
03621
03622 return false;
03623 }
03624
03632 protected function _isImageField($sFieldName)
03633 {
03634 $blIsImageField = ( stristr($sFieldName, '_oxthumb') || stristr($sFieldName, '_oxicon') || stristr($sFieldName, '_oxzoom') || stristr($sFieldName, '_oxpic') );
03635 return $blIsImageField;
03636 }
03637
03645 protected function _assignParentFieldValue($sFieldName)
03646 {
03647 if (!($oParentArticle = $this->getParentArticle())) {
03648 return;
03649 }
03650
03651 $sCopyFieldName = $this->_getFieldLongName($sFieldName);
03652
03653
03654 if ( $oParentArticle->$sCopyFieldName != null ) {
03655
03656
03657 if ( substr( $sCopyFieldName, 0, 12) != 'oxarticles__') {
03658 return;
03659 }
03660
03661
03662 if (in_array($sCopyFieldName, $this->_aNonCopyParentFields)) {
03663 return;
03664 }
03665
03666
03667 if ($this->_isFieldEmpty($sCopyFieldName) && $this->_isImageField($sCopyFieldName) && $this->_hasMasterImage( 1 )) {
03668 return;
03669 }
03670
03671
03672 if ($this->_isFieldEmpty($sCopyFieldName) || in_array( $sCopyFieldName, $this->_aCopyParentField ) ) {
03673 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03674 }
03675
03676
03677
03678
03679
03680
03681
03682
03683
03684
03685
03686
03687
03688
03689
03690
03691
03692
03693 }
03694 }
03695
03701 public function getParentArticle()
03702 {
03703 if ( ( $sParentId = $this->oxarticles__oxparentid->value ) ) {
03704 $sIndex = $sParentId . "_" . $this->getLanguage();
03705 if ( !isset( self::$_aLoadedParents[$sIndex] ) ) {
03706 self::$_aLoadedParents[$sIndex] = oxNew( 'oxarticle' );
03707 self::$_aLoadedParents[$sIndex]->_blLoadPrice = false;
03708 self::$_aLoadedParents[$sIndex]->_blLoadVariants = false;
03709 self::$_aLoadedParents[$sIndex]->loadInLang( $this->getLanguage(), $sParentId );
03710 }
03711 return self::$_aLoadedParents[$sIndex];
03712 }
03713 }
03714
03720 protected function _assignParentFieldValues()
03721 {
03722 startProfile('articleAssignParentInternal');
03723 if ( $this->oxarticles__oxparentid->value ) {
03724
03725 if ( !$this->isAdmin() || ( $this->_blLoadParentData && $this->isAdmin() ) ) {
03726 foreach ( $this->_aFieldNames as $sFieldName => $sVal ) {
03727 $this->_assignParentFieldValue( $sFieldName );
03728 }
03729 }
03730 }
03731 stopProfile('articleAssignParentInternal');
03732 }
03733
03739 protected function _assignNotBuyableParent()
03740 {
03741 if ( !$this->getConfig()->getConfigParam( 'blVariantParentBuyable' ) &&
03742 ($this->_blHasVariants || $this->oxarticles__oxvarstock->value || $this->oxarticles__oxvarcount->value )) {
03743 $this->_blNotBuyableParent = true;
03744
03745 }
03746 }
03747
03753 protected function _assignStock()
03754 {
03755 $myConfig = $this->getConfig();
03756
03757
03758
03759
03760
03761 if (!$myConfig->getConfigParam( 'blAllowUnevenAmounts' ) && !$this->isAdmin() ) {
03762 $this->oxarticles__oxstock = new oxField((int) floor($this->oxarticles__oxstock->value));
03763 }
03764
03765 $this->_iStockStatus = 0;
03766
03767
03768 if ( $myConfig->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstockflag->value != 4) {
03769
03770 $iStock = $this->oxarticles__oxstock->value;
03771
03772 if ($this->_blNotBuyableParent) {
03773 $iStock = $this->oxarticles__oxvarstock->value;
03774 }
03775
03776
03777 if ( $iStock <= $myConfig->getConfigParam( 'sStockWarningLimit' ) && $iStock > 0) {
03778 $this->_iStockStatus = 1;
03779 }
03780
03781
03782 if ($iStock <= 0) {
03783 $this->_iStockStatus = -1;
03784 }
03785 }
03786
03787
03788
03789 if ( $myConfig->getConfigParam( 'blUseStock' ) && ($this->oxarticles__oxstockflag->value == 3 || $this->oxarticles__oxstockflag->value == 2)) {
03790 $iOnStock = $this->oxarticles__oxstock->value;
03791 if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
03792 $iOnStock += $this->getSession()->getBasketReservations()->getReservedAmount($this->getId());
03793 }
03794 if ($iOnStock <= 0) {
03795 $this->setBuyableState( false );
03796 }
03797 }
03798
03799
03800 if ($this->_blNotBuyable && $this->oxarticles__oxvarstock->value ) {
03801 $this->setBuyableState( true );
03802
03803 $this->_blNotBuyableParent = true;
03804 }
03805
03806
03807
03808
03809 if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && !$myConfig->getConfigParam( 'blLoadVariants' ) && $this->oxarticles__oxvarstock->value) {
03810 $this->setBuyableState( false );
03811 }
03812
03813
03814 if (!$this->_blNotBuyable && $this->_blNotBuyableParent && $this->oxarticles__oxvarcount->value == 0) {
03815 $this->setBuyableState( false );
03816 }
03817 }
03818
03826 protected function _assignPrices()
03827 {
03828 $myConfig = $this->getConfig();
03829
03830
03831 if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
03832 return;
03833 }
03834
03835
03836 if ( $this->_hasAnyVariant() ) {
03837 $this->_applyRangePrice();
03838 }
03839 }
03840
03846 protected function _assignPersistentParam()
03847 {
03848
03849 $aPersParam = oxSession::getVar( 'persparam');
03850 if ( isset( $aPersParam) && isset( $aPersParam[$this->getId()])) {
03851 $this->_aPersistParam = $aPersParam[$this->getId()];
03852 }
03853 }
03854
03860 protected function _assignDynImageDir()
03861 {
03862 $myConfig = $this->getConfig();
03863
03864 $sThisShop = $this->oxarticles__oxshopid->value;
03865
03866 $this->_sDynImageDir = $myConfig->getPictureUrl( null, false );
03867 $this->dabsimagedir = $myConfig->getPictureDir( false );
03868 $this->nossl_dimagedir = $myConfig->getPictureUrl( null, false, false, null, $sThisShop );
03869 $this->ssl_dimagedir = $myConfig->getPictureUrl( null, false, true, null, $sThisShop );
03870 }
03871
03877 protected function _assignComparisonListFlag()
03878 {
03879
03880
03881 $aItems = oxSession::getVar('aFiltcompproducts');
03882 if ( isset( $aItems[$this->getId()])) {
03883 $this->_blIsOnComparisonList = true;
03884 }
03885 }
03886
03887
03895 protected function _insert()
03896 {
03897
03898 $sNow = date('Y-m-d H:i:s', oxRegistry::get("oxUtilsDate")->getTime());
03899 $this->oxarticles__oxinsert = new oxField( $sNow );
03900 if ( !is_object($this->oxarticles__oxsubclass) || $this->oxarticles__oxsubclass->value == '') {
03901 $this->oxarticles__oxsubclass = new oxField('oxarticle');
03902 }
03903
03904 return parent::_insert();
03905 }
03906
03912 protected function _update()
03913 {
03914
03915 $this->_skipSaveFields();
03916
03917 $myConfig = $this->getConfig();
03918
03919
03920 $blRes = parent::_update();
03921
03922
03923 return $blRes;
03924 }
03925
03931 public function updateVariantsRemind()
03932 {
03933
03934 if ( !$this->isVariant() && $this->_hasAnyVariant()) {
03935 $oDb = oxDb::getDb();
03936 $sOxId = $oDb->quote($this->getId());
03937 $sOxShopId = $oDb->quote($this->getShopId());
03938 $iRemindActive = $oDb->quote($this->oxarticles__oxremindactive->value);
03939 $sUpdate = "
03940 update oxarticles
03941 set oxremindactive = $iRemindActive
03942 where oxparentid = $sOxId and
03943 oxshopid = $sOxShopId
03944 ";
03945 $oDb->execute( $sUpdate );
03946 }
03947 }
03948
03956 protected function _deleteRecords($sOXID)
03957 {
03958 $oDb = oxDb::getDb();
03959
03960 $sOXID = $oDb->quote($sOXID);
03961
03962
03963 $sDelete = 'delete from oxobject2article where oxarticlenid = '.$sOXID.' or oxobjectid = '.$sOXID.' ';
03964 $oDb->execute( $sDelete);
03965
03966 $sDelete = 'delete from oxobject2attribute where oxobjectid = '.$sOXID.' ';
03967 $oDb->execute( $sDelete);
03968
03969 $sDelete = 'delete from oxobject2category where oxobjectid = '.$sOXID.' ';
03970 $oDb->execute( $sDelete);
03971
03972 $sDelete = 'delete from oxobject2selectlist where oxobjectid = '.$sOXID.' ';
03973 $oDb->execute( $sDelete);
03974
03975 $sDelete = 'delete from oxprice2article where oxartid = '.$sOXID.' ';
03976 $oDb->execute( $sDelete);
03977
03978 $sDelete = 'delete from oxreviews where oxtype="oxarticle" and oxobjectid = '.$sOXID.' ';
03979 $oDb->execute( $sDelete);
03980
03981 $sDelete = 'delete from oxratings where oxobjectid = '.$sOXID.' ';
03982 $rs = $oDb->execute( $sDelete );
03983
03984 $sDelete = 'delete from oxaccessoire2article where oxobjectid = '.$sOXID.' or oxarticlenid = '.$sOXID.' ';
03985 $oDb->execute( $sDelete);
03986
03987
03988 $sDelete = 'delete from oxobject2delivery where oxobjectid = '.$sOXID.' and oxtype=\'oxarticles\' ';
03989 $oDb->execute( $sDelete);
03990
03991 $sDelete = 'delete from oxartextends where oxid = '.$sOXID.' ';
03992 $oDb->execute( $sDelete);
03993
03994
03995 foreach ( $this->_getLanguageSetTables( "oxartextends" ) as $sSetTbl ) {
03996 $oDb->execute( "delete from $sSetTbl where oxid = {$sOXID}" );
03997 }
03998
03999 $sDelete = 'delete from oxactions2article where oxartid = '.$sOXID.' ';
04000 $rs = $oDb->execute( $sDelete );
04001
04002 $sDelete = 'delete from oxobject2list where oxobjectid = '.$sOXID.' ';
04003 $rs = $oDb->execute( $sDelete );
04004
04005
04006 return $rs;
04007 }
04008
04016 protected function _deleteVariantRecords( $sOXID )
04017 {
04018 if ( $sOXID ) {
04019 $oDb = oxDb::getDb();
04020
04021 $sQ = 'select oxid from '.$this->getViewName().' where oxparentid = '.$oDb->quote( $sOXID );
04022 $rs = $oDb->select( $sQ, false, false );
04023 $oArticle = oxNew("oxArticle");
04024 if ($rs != false && $rs->recordCount() > 0) {
04025 while (!$rs->EOF) {
04026 $oArticle->setId($rs->fields[0]);
04027 $oArticle->delete();
04028 $rs->moveNext();
04029 }
04030 }
04031 }
04032 }
04033
04039 protected function _deletePics()
04040 {
04041 $myUtilsPic = oxRegistry::get("oxUtilsPic");
04042 $myConfig = $this->getConfig();
04043 $oPictureHandler = oxRegistry::get("oxPictureHandler");
04044
04045
04046 $oPictureHandler->deleteMainIcon( $this );
04047
04048
04049 $oPictureHandler->deleteThumbnail( $this );
04050
04051 $sAbsDynImageDir = $myConfig->getPictureDir(false);
04052
04053
04054 $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
04055 for ( $i = 1; $i <= $iPicCount; $i++ ) {
04056 $oPictureHandler->deleteArticleMasterPicture( $this, $i );
04057 }
04058 }
04059
04069 protected function _onChangeResetCounts( $sOxid, $sVendorId = null, $sManufacturerId = null )
04070 {
04071
04072 $myUtilsCount = oxRegistry::get("oxUtilsCount");
04073
04074 if ( $sVendorId ) {
04075 $myUtilsCount->resetVendorArticleCount( $sVendorId );
04076 }
04077
04078 if ( $sManufacturerId ) {
04079 $myUtilsCount->resetManufacturerArticleCount( $sManufacturerId );
04080 }
04081
04082
04083 $oDb = oxDb::getDb();
04084 $sQ = "select oxcatnid from oxobject2category where oxobjectid = ".$oDb->quote($sOxid);
04085 $oRs = $oDb->select( $sQ, false, false );
04086 if ( $oRs !== false && $oRs->recordCount() > 0) {
04087 while ( !$oRs->EOF ) {
04088 $myUtilsCount->resetCatArticleCount( $oRs->fields[0] );
04089 $oRs->moveNext();
04090 }
04091 }
04092 }
04093
04101 protected function _onChangeUpdateStock( $sParentID )
04102 {
04103 if ( $sParentID ) {
04104 $oDb = oxDb::getDb();
04105 $sParentIdQuoted = $oDb->quote($sParentID);
04106 $sQ = 'select oxstock, oxvendorid, oxmanufacturerid from oxarticles where oxid = '.$sParentIdQuoted;
04107 $rs = $oDb->select( $sQ, false, false );
04108 $iOldStock = $rs->fields[0];
04109 $iVendorID = $rs->fields[1];
04110 $iManufacturerID = $rs->fields[2];
04111
04112 $sQ = 'select sum(oxstock) from '.$this->getViewName(true).' where oxparentid = '.$sParentIdQuoted.' and '. $this->getSqlActiveSnippet( true ).' and oxstock > 0 ';
04113 $iStock = (float) $oDb->getOne( $sQ, false, false );
04114
04115 $sQ = 'update oxarticles set oxvarstock = '.$iStock.' where oxid = '.$sParentIdQuoted;
04116 $oDb->execute( $sQ );
04117
04118
04119
04120 if ( $iStock < 0 ) {
04121 $iStock = 0;
04122 }
04123 if ( $iOldStock < 0 ) {
04124 $iOldStock = 0;
04125 }
04126 if ( $this->oxarticles__oxstockflag->value == 2 && $iOldStock xor $iStock ) {
04127
04128
04129 $this->_onChangeResetCounts( $sParentID, $iVendorID, $iManufacturerID );
04130 }
04131 }
04132 }
04133
04141 protected function _onChangeStockResetCount( $sOxid )
04142 {
04143 $myConfig = $this->getConfig();
04144
04145 if ( $myConfig->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstockflag->value == 2 &&
04146 ( $this->oxarticles__oxstock->value + $this->oxarticles__oxvarstock->value ) <= 0 ) {
04147
04148 $this->_onChangeResetCounts( $sOxid, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
04149 }
04150 }
04151
04159 protected function _onChangeUpdateVarCount( $sParentID )
04160 {
04161 if ( $sParentID ) {
04162 $oDb = oxDb::getDb();
04163 $sParentIdQuoted = $oDb->quote( $sParentID );
04164 $sQ = "select count(*) as varcount from oxarticles where oxparentid = {$sParentIdQuoted}";
04165 $iVarCount = (int) $oDb->getOne( $sQ, false, false );
04166
04167 $sQ = "update oxarticles set oxvarcount = {$iVarCount} where oxid = {$sParentIdQuoted}";
04168 $oDb->execute( $sQ );
04169 }
04170 }
04171
04179 protected function _setVarMinMaxPrice( $sParentId )
04180 {
04181 if ( $sParentId ) {
04182 $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
04183 $sQ = '
04184 SELECT
04185 MIN( IF( `oxarticles`.`oxprice` > 0, `oxarticles`.`oxprice`, `p`.`oxprice` ) ) AS `varminprice`,
04186 MAX( IF( `oxarticles`.`oxprice` > 0, `oxarticles`.`oxprice`, `p`.`oxprice` ) ) AS `varmaxprice`
04187 FROM '. $this->getViewName(true) . ' AS `oxarticles`
04188 LEFT JOIN '. $this->getViewName(true) . ' AS `p` ON ( `p`.`oxid` = `oxarticles`.`oxparentid` AND `p`.`oxprice` > 0 )
04189 WHERE '. $this->getSqlActiveSnippet(true) .'
04190 AND ( `oxarticles`.`oxparentid` = '. $oDb->quote( $sParentId ) .' )';
04191 $oDb->setFetchMode( oxDb::FETCH_MODE_ASSOC );
04192 $aPrices = $oDb->getRow( $sQ, false, false );
04193 if ( !is_null( $aPrices['varminprice'] ) || !is_null( $aPrices['varmaxprice'] ) ) {
04194 $sQ = '
04195 UPDATE `oxarticles`
04196 SET
04197 `oxvarminprice` = '. $oDb->quote( $aPrices['varminprice'] ) .',
04198 `oxvarmaxprice` = '. $oDb->quote( $aPrices['varmaxprice'] ) .'
04199 WHERE
04200 `oxid` = ' . $oDb->quote( $sParentId );
04201 } else {
04202 $sQ = '
04203 UPDATE `oxarticles`
04204 SET
04205 `oxvarminprice` = `oxprice`,
04206 `oxvarmaxprice` = `oxprice`
04207 WHERE
04208 `oxid` = ' . $oDb->quote( $sParentId );
04209 }
04210 $oDb->execute( $sQ );
04211 }
04212 }
04213
04214
04224 protected function _onChangeUpdateMinVarPrice( $sParentID )
04225 {
04226 if ( $sParentID ) {
04227 $oDb = oxDb::getDb();
04228 $sParentIdQuoted = $oDb->quote($sParentID);
04229
04230 $sQ = 'select min(oxprice) as varminprice from '.$this->getViewName(true).' where '.$this->getSqlActiveSnippet(true).' and (oxparentid = '.$sParentIdQuoted.')';
04231 $dVarMinPrice = $oDb->getOne( $sQ, false, false );
04232
04233 $dParentPrice = $oDb->getOne( "select oxprice from oxarticles where oxid = $sParentIdQuoted ", false, false );
04234
04235 $blParentBuyable = $this->getConfig()->getConfigParam( 'blVariantParentBuyable' );
04236
04237 if ($dVarMinPrice) {
04238 if ($blParentBuyable) {
04239 $dVarMinPrice = min($dVarMinPrice, $dParentPrice);
04240 }
04241 } else {
04242 $dVarMinPrice = $dParentPrice;
04243 }
04244
04245 if ( $dVarMinPrice ) {
04246 $sQ = 'update oxarticles set oxvarminprice = '.$dVarMinPrice.' where oxid = '.$sParentIdQuoted;
04247 $oDb->execute($sQ);
04248 }
04249 }
04250 }
04251
04252
04260 protected function _applyRangePrice()
04261 {
04262
04263 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
04264 return;
04265 }
04266
04267 $this->_blIsRangePrice = false;
04268
04269
04270 if ($this->_blSkipFromPrice || !$this->_blNotBuyableParent) {
04271 return;
04272 }
04273
04274 if ( $this->isParentNotBuyable() && !$this->getConfig()->getConfigParam( 'blLoadVariants' )) {
04275
04276 $dPrice = $this->_preparePrice( $this->oxarticles__oxvarminprice->value, $this->getArticleVat() );
04277 $this->getPrice()->setPrice($dPrice);
04278 $this->_blIsRangePrice = true;
04279 $this->_calculatePrice( $this->getPrice() );
04280 return;
04281
04282 }
04283
04284 $aPrices = array();
04285
04286 if (!$this->_blNotBuyableParent) {
04287 $aPrices[] = $this->getPrice()->getPrice();
04288 }
04289
04290 $aVariants = $this->getVariants(false);
04291
04292 if (count($aVariants)) {
04293 foreach ($aVariants as $sKey => $oVariant) {
04294 $aPrices[] = $oVariant->getPrice()->getPrice();
04295 }
04296 }
04297
04298 if ( count( $aPrices ) ) {
04299 $dMinPrice = min( $aPrices );
04300 $dMaxPrice = max( $aPrices );
04301 }
04302
04303 if ($this->_blNotBuyableParent && isset($dMinPrice) && $dMinPrice == $dMaxPrice) {
04304 $this->getPrice()->setPrice($dMinPrice);
04305 }
04306
04307 if (isset($dMinPrice) && $dMinPrice != $dMaxPrice) {
04308 $this->getPrice()->setPrice($dMinPrice);
04309 $this->_blIsRangePrice = true;
04310 }
04311 }
04312
04319 public function getProductId()
04320 {
04321 return $this->getId();
04322 }
04323
04331 public function getProductParentId()
04332 {
04333 return $this->getParentId();
04334 }
04335
04341 public function getParentId()
04342 {
04343 return $this->oxarticles__oxparentid->value;
04344 }
04345
04351 public function isOrderArticle()
04352 {
04353 return false;
04354 }
04355
04361 public function isVariant()
04362 {
04363 return (bool) ( isset( $this->oxarticles__oxparentid ) ? $this->oxarticles__oxparentid->value : false );
04364 }
04365
04371 public function isMdVariant()
04372 {
04373 $oMdVariant = oxNew( "oxVariantHandler" );
04374
04375 return $oMdVariant->isMdVariant($this);
04376 }
04377
04385 public function getSqlForPriceCategories($sFields = '')
04386 {
04387 if (!$sFields) {
04388 $sFields = 'oxid';
04389 }
04390 $sSelectWhere = "select $sFields from ".$this->_getObjectViewName('oxcategories')." where";
04391 $sQuotedPrice = oxDb::getDb()->quote( $this->oxarticles__oxprice->value );
04392 return "$sSelectWhere oxpricefrom != 0 and oxpriceto != 0 and oxpricefrom <= $sQuotedPrice and oxpriceto >= $sQuotedPrice"
04393 ." union $sSelectWhere oxpricefrom != 0 and oxpriceto = 0 and oxpricefrom <= $sQuotedPrice"
04394 ." union $sSelectWhere oxpricefrom = 0 and oxpriceto != 0 and oxpriceto >= $sQuotedPrice";
04395 }
04396
04404 public function inPriceCategory( $sCatNid )
04405 {
04406 $oDb = oxDb::getDb();
04407
04408 $sQuotedPrice = $oDb->quote( $this->oxarticles__oxprice->value );
04409 $sQuotedCnid = $oDb->quote( $sCatNid );
04410 return (bool) $oDb->getOne(
04411 "select 1 from ".$this->_getObjectViewName('oxcategories')." where oxid=$sQuotedCnid and"
04412 ."( (oxpricefrom != 0 and oxpriceto != 0 and oxpricefrom <= $sQuotedPrice and oxpriceto >= $sQuotedPrice)"
04413 ." or (oxpricefrom != 0 and oxpriceto = 0 and oxpricefrom <= $sQuotedPrice)"
04414 ." or (oxpricefrom = 0 and oxpriceto != 0 and oxpriceto >= $sQuotedPrice)"
04415 .")"
04416 );
04417 }
04418
04424 public function getMdVariants()
04425 {
04426 if ( $this->_oMdVariants ) {
04427 return $this->_oMdVariants;
04428 }
04429
04430 $oParentArticle = $this->getParentArticle();
04431 if ( $oParentArticle ) {
04432 $oVariants = $oParentArticle->getVariants();
04433 } else {
04434 $oVariants = $this->getVariants();
04435 }
04436
04437 $oVariantHandler = oxNew( "oxVariantHandler" );
04438 $this->_oMdVariants = $oVariantHandler->buildMdVariants( $oVariants, $this->getId() );
04439
04440 return $this->_oMdVariants;
04441 }
04442
04448 public function getMdSubvariants()
04449 {
04450 return $this->getMdVariants()->getMdSubvariants();
04451 }
04452
04460 protected function _hasMasterImage( $iIndex )
04461 {
04462 $sPicName = basename($this->{"oxarticles__oxpic" . $iIndex}->value);
04463
04464 if ( $sPicName == "nopic.jpg" || $sPicName == "" ) {
04465 return false;
04466 }
04467 if ( $this->isVariant() && $this->getParentArticle()->{"oxarticles__oxpic".$iIndex}->value == $this->{"oxarticles__oxpic".$iIndex}->value ) {
04468 return false;
04469 }
04470
04471 $sMasterPic = 'product/'.$iIndex . "/" . $sPicName;
04472
04473 if ( $this->getConfig()->getMasterPicturePath( $sMasterPic ) ) {
04474 return true;
04475 }
04476
04477 return false;
04478 }
04479
04488 public function getPictureFieldValue( $sFieldName, $iIndex = null )
04489 {
04490 if ( $sFieldName ) {
04491 $sFieldName = "oxarticles__" . $sFieldName . $iIndex;
04492 return $this->$sFieldName->value;
04493 }
04494 }
04495
04503 public function getMasterZoomPictureUrl( $iIndex )
04504 {
04505 $sPicUrl = false;
04506 $sPicName = basename( $this->{"oxarticles__oxpic" . $iIndex}->value );
04507
04508 if ( $sPicName && $sPicName != "nopic.jpg" ) {
04509 $sPicUrl = $this->getConfig()->getPictureUrl( "master/product/" . $iIndex . "/" . $sPicName );
04510 if ( !$sPicUrl || basename( $sPicUrl ) == "nopic.jpg" ) {
04511 $sPicUrl = false;
04512 }
04513 }
04514
04515 return $sPicUrl;
04516 }
04517
04523 public function getUnitName()
04524 {
04525 if ( $this->oxarticles__oxunitname->value ) {
04526 return oxRegistry::getLang()->translateString( $this->oxarticles__oxunitname->value );
04527 }
04528 }
04529
04537 public function getArticleFiles( $blAddFromParent=false )
04538 {
04539 if ( $this->_aArticleFiles === null) {
04540
04541 $this->_aArticleFiles = false;
04542
04543 $sQ = "SELECT * FROM `oxfiles` WHERE `oxartid` = '".$this->getId()."'";
04544
04545 if ( !$this->getConfig()->getConfigParam( 'blVariantParentBuyable' ) && $blAddFromParent ) {
04546 $sQ .= " OR `oxartId` = '". $this->oxarticles__oxparentid->value . "'";
04547 }
04548
04549 $oArticleFiles = oxNew("oxlist");
04550 $oArticleFiles->init("oxfile");
04551 $oArticleFiles->selectString( $sQ );
04552 $this->_aArticleFiles = $oArticleFiles;
04553
04554 }
04555
04556 return $this->_aArticleFiles;
04557 }
04558
04564 public function isDownloadable()
04565 {
04566 return $this->oxarticles__oxisdownloadable->value;
04567 }
04568
04574 public function hasAmountPrice()
04575 {
04576 if ( self::$_blHasAmountPrice === null ) {
04577
04578 self::$_blHasAmountPrice = false;
04579
04580 $oDb = oxDb::getDb();
04581 $sQ = "SELECT 1 FROM `oxprice2article` LIMIT 1";
04582
04583 if ( $oDb->getOne( $sQ ) ) {
04584 self::$_blHasAmountPrice = true;
04585 }
04586 }
04587
04588 return self::$_blHasAmountPrice;
04589 }
04590
04591
04597 protected function _isPriceViewModeNetto()
04598 {
04599 $blResult = (bool) $this->getConfig()->getConfigParam('blShowNetPrice');
04600 $oUser = $this->getArticleUser();
04601 if ( $oUser ) {
04602 $blResult = $oUser->isPriceViewModeNetto();
04603 }
04604
04605 return $blResult;
04606 }
04607
04608
04616 protected function _getPriceObject( $blCalculationModeNetto = null )
04617 {
04618 $oPrice = oxNew( 'oxPrice' );
04619
04620 if ( $blCalculationModeNetto === null ) {
04621 $blCalculationModeNetto = $this->_isPriceViewModeNetto();
04622 }
04623
04624 if ( $blCalculationModeNetto ) {
04625 $oPrice->setNettoPriceMode();
04626 } else {
04627 $oPrice->setBruttoPriceMode();
04628 }
04629
04630 return $oPrice;
04631 }
04632
04633
04641 protected function _getPriceForView( $oPrice )
04642 {
04643 if ( $this->_isPriceViewModeNetto() ) {
04644 $dPrice = $oPrice->getNettoPrice();
04645 } else {
04646 $dPrice = $oPrice->getBruttoPrice();
04647 }
04648
04649 return $dPrice;
04650 }
04651
04652
04662 protected function _preparePrice( $dPrice, $dVat, $blCalculationModeNetto = null )
04663 {
04664 if ( $blCalculationModeNetto === null ) {
04665 $blCalculationModeNetto = $this->_isPriceViewModeNetto();
04666 }
04667
04668 $oCurrency = $this->getConfig()->getActShopCurrencyObject();
04669
04670 $blEnterNetPrice = $this->getConfig()->getConfigParam('blEnterNetPrice');
04671 if ( $blCalculationModeNetto && !$blEnterNetPrice ) {
04672 $dPrice = round( oxPrice::brutto2Netto( $dPrice, $dVat ), $oCurrency->decimal );
04673 } elseif ( !$blCalculationModeNetto && $blEnterNetPrice ) {
04674 $dPrice = round( oxPrice::netto2Brutto( $dPrice, $dVat ), $oCurrency->decimal );
04675 }
04676
04677 return $dPrice;
04678 }
04679
04680
04686 public function getFUnitPrice()
04687 {
04688 if ($this->_fPricePerUnit == null) {
04689 if ( $oPrice = $this->getUnitPrice() ) {
04690 if ( $dPrice = $this->_getPriceForView( $oPrice ) ) {
04691 $this->_fPricePerUnit = oxRegistry::getLang()->formatCurrency( $dPrice );
04692 }
04693 }
04694 }
04695
04696 return $this->_fPricePerUnit;
04697 }
04698
04699
04705 public function getUnitPrice()
04706 {
04707
04708 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
04709 return;
04710 }
04711
04712 $oPrice = null;
04713 if ( (double) $this->oxarticles__oxunitquantity->value && $this->oxarticles__oxunitname->value ) {
04714 $oPrice = clone $this->getPrice();
04715 $oPrice->divide( (double) $this->oxarticles__oxunitquantity->value );
04716 }
04717
04718 return $oPrice;
04719 }
04720
04721
04727 public function getFMinPrice()
04728 {
04729 $sPrice = '';
04730 if ( $oPrice = $this->getMinPrice() ) {
04731 $dPrice = $this->_getPriceForView( $oPrice );
04732 $sPrice = oxRegistry::getLang()->formatCurrency( $dPrice );
04733 }
04734
04735 return $sPrice;
04736 }
04737
04743 public function getFVarMinPrice()
04744 {
04745 $sPrice = '';
04746 if ( $oPrice = $this->getVarMinPrice() ) {
04747 $dPrice = $this->_getPriceForView( $oPrice );
04748 $sPrice = oxRegistry::getLang()->formatCurrency( $dPrice );
04749 }
04750
04751 return $sPrice;
04752 }
04753
04759 public function getVarMinPrice()
04760 {
04761 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
04762 return;
04763 }
04764
04765 $oPrice = null;
04766 $dPrice = $this->_getVarMinPrice();
04767
04768 $dPrice = $this->_preparePrice( $dPrice, $this->getArticleVat() );
04769
04770
04771 $oPrice = $this->_getPriceObject();
04772 $oPrice->setPrice( $dPrice );
04773 $this->_calculatePrice( $oPrice );
04774
04775
04776 return $oPrice;
04777 }
04778
04779
04785 public function getMinPrice()
04786 {
04787 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
04788 return;
04789 }
04790
04791 $oPrice = null;
04792 $dPrice = $this->_getPrice();
04793 if ( $this->_getVarMinPrice() !== null && $dPrice > $this->_getVarMinPrice() ) {
04794 $dPrice = $this->_getVarMinPrice();
04795 }
04796
04797 $dPrice = $this->_preparePrice( $dPrice, $this->getArticleVat() );
04798
04799
04800 $oPrice = $this->_getPriceObject();
04801 $oPrice->setPrice( $dPrice );
04802 $this->_calculatePrice( $oPrice );
04803
04804 return $oPrice;
04805 }
04806
04807
04813 public function isRangePrice()
04814 {
04815 if ( $this->_blIsRangePrice === null ) {
04816
04817 $this->setRangePrice( false );
04818
04819 if ( $this->_hasAnyVariant() ) {
04820 $dPrice = $this->_getPrice();
04821 $dMinPrice = $this->_getVarMinPrice();
04822 $dMaxPrice = $this->_getVarMaxPrice();
04823
04824 if ( $dMinPrice != $dMaxPrice ) {
04825 $this->setRangePrice();
04826 } elseif ( !$this->isParentNotBuyable() && $dMinPrice != $dPrice ) {
04827 $this->setRangePrice();
04828 }
04829 }
04830 }
04831
04832 return $this->_blIsRangePrice;
04833 }
04834
04835
04843 public function setRangePrice( $blIsRangePrice = true )
04844 {
04845 return $this->_blIsRangePrice = $blIsRangePrice;
04846 }
04847
04853 protected function _getUserPriceSufix()
04854 {
04855 $sPriceSufix = '';
04856 $oUser = $this->getArticleUser();
04857
04858 if ( $oUser ) {
04859 if ( $oUser->inGroup( 'oxidpricea' ) ) {
04860 $sPriceSufix = 'a';
04861 } elseif ( $oUser->inGroup( 'oxidpriceb' ) ) {
04862 $sPriceSufix = 'b';
04863 } elseif ( $oUser->inGroup( 'oxidpricec' ) ) {
04864 $sPriceSufix = 'c';
04865 }
04866 }
04867
04868 return $sPriceSufix;
04869 }
04870
04871
04877 protected function _getPrice()
04878 {
04879 $sPriceSufix = $this->_getUserPriceSufix();
04880 if ( $sPriceSufix === '') {
04881 $dPrice = $this->oxarticles__oxprice->value;
04882 } else {
04883 if ( $this->getConfig()->getConfigParam( 'blOverrideZeroABCPrices' ) ) {
04884 $dPrice = ($this->{oxarticles__oxprice.$sPriceSufix}->value !=0 )? $this->{oxarticles__oxprice.$sPriceSufix}->value : $this->oxarticles__oxprice->value;
04885 } else {
04886 $dPrice = $this->{oxarticles__oxprice.$sPriceSufix}->value;
04887 }
04888 }
04889 return $dPrice;
04890 }
04891
04892
04898 protected function _getVarMinPrice()
04899 {
04900 if ( $this->_dVarMinPrice === null) {
04901
04902 $sPriceSufix = $this->_getUserPriceSufix();
04903 if ( $dPrice === null ) {
04904 if ( $sPriceSufix === '' ) {
04905 $dPrice = $this->oxarticles__oxvarminprice->value;
04906 } else {
04907 $sSql = 'SELECT ';
04908 if ( $this->getConfig()->getConfigParam( 'blOverrideZeroABCPrices' ) ) {
04909 $sSql .= 'MIN( IF(`oxprice'.$sPriceSufix.'` = 0, `oxprice`, `oxprice'.$sPriceSufix.'`) ) AS `varminprice` ';
04910 } else {
04911 $sSql .= 'MIN(`oxprice'.$sPriceSufix.'`) AS `varminprice` ';
04912 }
04913
04914 $sSql .= ' FROM ' . $this->getViewName(true) . '
04915 WHERE ' .$this->getSqlActiveSnippet(true) . '
04916 AND ( `oxparentid` = ' . oxDb::getDb()->quote( $this->getId() ) . ' )';
04917
04918 $dPrice = oxDb::getDb()->getOne( $sSql );
04919 }
04920 }
04921 $this->_dVarMinPrice = $dPrice;
04922 }
04923
04924 return $this->_dVarMinPrice;
04925 }
04926
04932 protected function _getSubShopVarMinPrice()
04933 {
04934 $myConfig = $this->getConfig();
04935 $sShopId = $myConfig->getShopId();
04936 if ($this->getConfig()->getConfigParam( 'blMallCustomPrice' ) && $sShopId != $this->oxarticles__oxshopid->value ) {
04937 $sPriceSufix = $this->_getUserPriceSufix();
04938 $sSql = 'SELECT ';
04939 if ( $sPriceSufix != '' && $this->getConfig()->getConfigParam( 'blOverrideZeroABCPrices' ) ) {
04940 $sSql .= 'MIN(IF(`oxfield2shop`.`oxprice'.$sPriceSufix.'` = 0, `oxfield2shop`.`oxprice`, `oxfield2shop`.`oxprice'.$sPriceSufix.'`)) AS `varminprice` ';
04941 } else {
04942 $sSql .= 'MIN(`oxfield2shop`.`oxprice'.$sPriceSufix.'`) AS `varminprice` ';
04943 }
04944 $sSql .= ' FROM ' . getViewName('oxfield2shop') . ' AS oxfield2shop
04945 INNER JOIN ' . $this->getViewName(true) . ' AS oxarticles ON `oxfield2shop`.`oxartid` = `oxarticles`.`oxid`
04946 WHERE ' .$this->getSqlActiveSnippet(true) . '
04947 AND ( `oxarticles`.`oxparentid` = ' . oxDb::getDb()->quote( $this->getId() ) . ' )
04948 AND ( `oxfield2shop`.`oxshopid` = ' . oxDb::getDb()->quote( $sShopId ) . ' )';
04949 $dPrice = oxDb::getDb()->getOne( $sSql );
04950 }
04951 return $dPrice;
04952 }
04953
04959 protected function _getVarMaxPrice()
04960 {
04961 if ( $this->_dVarMaxPrice === null ) {
04962
04963 $sPriceSufix = $this->_getUserPriceSufix();
04964 if ( $dPrice === null ) {
04965 if ( $sPriceSufix === '') {
04966 $dPrice = $this->oxarticles__oxvarmaxprice->value;
04967 } else {
04968 $sSql = 'SELECT ';
04969 if ( $this->getConfig()->getConfigParam( 'blOverrideZeroABCPrices' ) ) {
04970 $sSql .= 'MAX( IF(`oxprice'.$sPriceSufix.'` = 0, `oxprice`, `oxprice'.$sPriceSufix.'`) ) AS `varmaxprice` ';
04971 } else {
04972 $sSql .= 'MAX(`oxprice'.$sPriceSufix.'`) AS `varmaxprice` ';
04973 }
04974
04975 $sSql .= ' FROM ' . $this->getViewName(true) . '
04976 WHERE ' .$this->getSqlActiveSnippet(true) . '
04977 AND ( `oxparentid` = ' . oxDb::getDb()->quote( $this->getId() ) . ' )';
04978
04979 $dPrice = oxDb::getDb()->getOne( $sSql );
04980 }
04981 }
04982 $this->_dVarMaxPrice = $dPrice;
04983 }
04984
04985 return $this->_dVarMaxPrice;
04986 }
04987
04993 protected function _getSubShopVarMaxPrice()
04994 {
04995 $myConfig = $this->getConfig();
04996 $sShopId = $myConfig->getShopId();
04997 if ($this->getConfig()->getConfigParam( 'blMallCustomPrice' ) && $sShopId != $this->oxarticles__oxshopid->value ) {
04998 $sPriceSufix = $this->_getUserPriceSufix();
04999 $sSql = 'SELECT ';
05000 if ( $sPriceSufix != '' && $this->getConfig()->getConfigParam( 'blOverrideZeroABCPrices' ) ) {
05001 $sSql .= 'MAX(IF(`oxfield2shop`.`oxprice'.$sPriceSufix.'` = 0, `oxfield2shop`.`oxprice`, `oxfield2shop`.`oxprice'.$sPriceSufix.'`)) AS `varmaxprice` ';
05002 } else {
05003 $sSql .= 'MAX(`oxfield2shop`.`oxprice'.$sPriceSufix.'`) AS `varmaxprice` ';
05004 }
05005 $sSql .= ' FROM ' . getViewName('oxfield2shop') . ' AS oxfield2shop
05006 INNER JOIN ' . $this->getViewName(true) . ' AS oxarticles ON `oxfield2shop`.`oxartid` = `oxarticles`.`oxid`
05007 WHERE ' .$this->getSqlActiveSnippet(true) . '
05008 AND ( `oxarticles`.`oxparentid` = ' . oxDb::getDb()->quote( $this->getId() ) . ' )
05009 AND ( `oxfield2shop`.`oxshopid` = ' . oxDb::getDb()->quote( $sShopId ) . ' )';
05010 $dPrice = oxDb::getDb()->getOne( $sSql );
05011 }
05012 return $dPrice;
05013 }
05014
05015 }