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
00421
00430 public function __construct($aParams = null)
00431 {
00432 if ( $aParams && is_array($aParams)) {
00433 foreach ( $aParams as $sParam => $mValue) {
00434 $this->$sParam = $mValue;
00435 }
00436 }
00437 parent::__construct();
00438 $this->init( 'oxarticles' );
00439 }
00440
00449 public function __get($sName)
00450 {
00451 $this->$sName = parent::__get($sName);
00452 if ( $this->$sName ) {
00453
00454 $this->_assignParentFieldValue($sName);
00455 }
00456
00457 return $this->$sName;
00458 }
00459
00468 public function __set( $sName, $sValue )
00469 {
00470 parent::__set( $sName, $sValue );
00471 }
00472
00480 public function setId( $sId = null )
00481 {
00482 $sId = parent::setId( $sId );
00483
00484
00485 $this->oxarticles__oxnid = $this->oxarticles__oxid;
00486
00487 return $sId;
00488 }
00489
00499 public function getActiveCheckQuery( $blForceCoreTable = null )
00500 {
00501 $sTable = $this->getViewName( $blForceCoreTable );
00502
00503
00504 $sQ = " $sTable.oxactive = 1 ";
00505
00506
00507 if ( $this->getConfig()->getConfigParam( 'blUseTimeCheck' ) ) {
00508 $sDate = date( 'Y-m-d H:i:s', oxRegistry::get("oxUtilsDate")->getTime() );
00509 $sQ = "( $sQ or ( $sTable.oxactivefrom < '$sDate' and $sTable.oxactiveto > '$sDate' ) ) ";
00510 }
00511
00512 return $sQ;
00513 }
00514
00528 public function getStockCheckQuery( $blForceCoreTable = null )
00529 {
00530 $myConfig = $this->getConfig();
00531 $sTable = $this->getViewName( $blForceCoreTable );
00532
00533 $sQ = "";
00534
00535
00536 if ( $myConfig->getConfigParam( 'blUseStock' ) ) {
00537 $sQ = " and ( $sTable.oxstockflag != 2 or ( $sTable.oxstock + $sTable.oxvarstock ) > 0 ) ";
00538
00539 if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) ) {
00540 $sTimeCheckQ = '';
00541 if ( $myConfig->getConfigParam( 'blUseTimeCheck' ) ) {
00542 $sDate = date( 'Y-m-d H:i:s', oxRegistry::get("oxUtilsDate")->getTime() );
00543 $sTimeCheckQ = " or ( art.oxactivefrom < '$sDate' and art.oxactiveto > '$sDate' )";
00544 }
00545 $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 ) ) ";
00546 }
00547 }
00548
00549 return $sQ;
00550 }
00551
00563 public function getVariantsQuery( $blRemoveNotOrderables, $blForceCoreTable = null )
00564 {
00565 $sTable = $this->getViewName( $blForceCoreTable );
00566 $sQ = " and $sTable.oxparentid = '".$this->getId()."' ";
00567
00568
00569 if ( $this->getConfig()->getConfigParam( 'blUseStock' ) ) {
00570 $sQ .= " and ( $sTable.oxstock > 0 or ( $sTable.oxstock <= 0 and $sTable.oxstockflag != 2 ";
00571 if ( $blRemoveNotOrderables ) {
00572 $sQ .= " and $sTable.oxstockflag != 3 ";
00573 }
00574 $sQ .= " ) ) ";
00575 }
00576
00577 return $sQ;
00578 }
00579
00587 public function getSqlActiveSnippet( $blForceCoreTable = null )
00588 {
00589 $myConfig = $this->getConfig();
00590
00591
00592 $sQ = $this->getActiveCheckQuery( $blForceCoreTable );
00593
00594
00595 $sQ .= $this->getStockCheckQuery( $blForceCoreTable );
00596
00597
00598 return "( $sQ ) ";
00599 }
00600
00608 public function setSkipAssign($blSkipAssign)
00609 {
00610 $this->_blSkipAssign = $blSkipAssign;
00611 }
00612
00618 public function disablePriceLoad()
00619 {
00620 $this->_blLoadPrice = false;
00621 }
00622
00628 public function enablePriceLoad()
00629 {
00630 $this->_blLoadPrice = true;
00631 }
00632
00638 public function getItemKey()
00639 {
00640 return $this->_sItemKey;
00641 }
00642
00650 public function setItemKey($sItemKey)
00651 {
00652 $this->_sItemKey = $sItemKey;
00653 }
00654
00662 public function setNoVariantLoading( $blLoadVariants )
00663 {
00664 $this->_blLoadVariants = !$blLoadVariants;
00665 }
00666
00672 public function isBuyable()
00673 {
00674 if ($this->_blNotBuyableParent) {
00675 return false;
00676 }
00677
00678 return !$this->_blNotBuyable;
00679 }
00680
00686 public function getPersParams()
00687 {
00688 return $this->_aPersistParam;
00689 }
00690
00696 public function isOnComparisonList()
00697 {
00698 return $this->_blIsOnComparisonList;
00699 }
00700
00708 public function setOnComparisonList( $blOnList )
00709 {
00710 $this->_blIsOnComparisonList = $blOnList;
00711 }
00712
00720 public function setLoadParentData($blLoadParentData)
00721 {
00722 $this->_blLoadParentData = $blLoadParentData;
00723 }
00724
00734 public function setSkipAbPrice( $blSkipAbPrice = null )
00735 {
00736 $this->_blSkipAbPrice = $blSkipAbPrice;
00737 }
00738
00739
00747 public function isMultilingualField($sFieldName)
00748 {
00749 switch ($sFieldName) {
00750 case "oxlongdesc":
00751 case "oxtags":
00752 return true;
00753 }
00754
00755 return parent::isMultilingualField($sFieldName);
00756 }
00757
00763 public function isVisible()
00764 {
00765
00766
00767 if ( ( $blCanPreview = oxRegistry::getUtils()->canPreview() ) !== null ) {
00768 return $blCanPreview;
00769 }
00770
00771
00772 $sNow = date('Y-m-d H:i:s');
00773 if ( !$this->oxarticles__oxactive->value &&
00774 ( $this->oxarticles__oxactivefrom->value > $sNow ||
00775 $this->oxarticles__oxactiveto->value < $sNow
00776 )) {
00777 return false;
00778 }
00779
00780
00781 if ( $this->getConfig()->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstockflag->value == 2) {
00782 $iOnStock = $this->oxarticles__oxstock->value + $this->oxarticles__oxvarstock->value;
00783 if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
00784 $iOnStock += $this->getSession()->getBasketReservations()->getReservedAmount($this->getId());
00785 }
00786 if ( $iOnStock <= 0 ) {
00787 return false;
00788 }
00789 }
00790
00791 return true;
00792 }
00793
00802 public function assign( $aRecord )
00803 {
00804
00805 startProfile('articleAssign');
00806
00807
00808 parent::assign( $aRecord );
00809
00810 $this->oxarticles__oxnid = $this->oxarticles__oxid;
00811
00812
00813 if ($this->_blSkipAssign) {
00814 return;
00815 }
00816
00817 $this->_assignParentFieldValues();
00818 $this->_assignNotBuyableParent();
00819
00820
00821 $this->_assignStock();
00822 $this->_assignPersistentParam();
00823 $this->_assignDynImageDir();
00824 $this->_assignComparisonListFlag();
00825
00826
00827 stopProfile('articleAssign');
00828 }
00829
00830
00838 protected function _loadFromDb( $sOXID )
00839 {
00840 $sSelect = $this->buildSelectString( array( $this->getViewName().".oxid" => $sOXID ));
00841 $aData = oxDb::getDb( oxDb::FETCH_MODE_ASSOC )->getRow( $sSelect );
00842 return $aData;
00843 }
00844
00855 public function load( $sOXID )
00856 {
00857
00858 $this->_blNotBuyableParent = false;
00859
00860
00861 $aData = $this->_loadFromDb( $sOXID );
00862
00863 if ( $aData ) {
00864 $this->assign( $aData );
00865
00866 $this->_isLoaded = true;
00867 return true;
00868 }
00869
00870 return false;
00871 }
00872
00873
00881 public function addToRatingAverage( $iRating )
00882 {
00883 $dOldRating = $this->oxarticles__oxrating->value;
00884 $dOldCnt = $this->oxarticles__oxratingcnt->value;
00885 $this->oxarticles__oxrating->setValue(( $dOldRating * $dOldCnt + $iRating ) / ($dOldCnt + 1));
00886 $this->oxarticles__oxratingcnt->setValue($dOldCnt + 1);
00887 $dRating = ( $dOldRating * $dOldCnt + $iRating ) / ($dOldCnt + 1);
00888 $dRatingCnt = (int) ($dOldCnt + 1);
00889
00890 $oDb = oxDb::getDb();
00891 $oDb->execute( 'update oxarticles set oxarticles.oxrating = '.$dRating.',oxarticles.oxratingcnt = '.$dRatingCnt.', oxarticles.oxtimestamp = oxarticles.oxtimestamp where oxarticles.oxid = '.$oDb->quote( $this->getId() ) );
00892
00893 }
00894
00902 public function setRatingAverage( $iRating )
00903 {
00904 $this->oxarticles__oxrating = new oxField( $iRating );
00905 }
00906
00914 public function setRatingCount( $iRatingCnt )
00915 {
00916 $this->oxarticles__oxratingcnt = new oxField( $iRatingCnt );
00917 }
00918
00926 public function getArticleRatingAverage( $blIncludeVariants = false )
00927 {
00928 if ( !$blIncludeVariants ) {
00929 return round( $this->oxarticles__oxrating->value, 1);
00930 } else {
00931 $oRating = oxNew( 'oxRating' );
00932 return $oRating->getRatingAverage( $this->getId(), 'oxarticle', $this->_getVariantsIds() );
00933 }
00934 }
00935
00943 public function getArticleRatingCount( $blIncludeVariants = false )
00944 {
00945 if ( !$blIncludeVariants ) {
00946 return $this->oxarticles__oxratingcnt->value;
00947 } else {
00948 $oRating = oxNew( 'oxRating' );
00949 return $oRating->getRatingCount( $this->getId(), 'oxarticle', $this->_getVariantsIds() );
00950 }
00951 }
00952
00953
00959 public function getReviews()
00960 {
00961 $aIds = array($this->getId());
00962
00963 if ( $this->oxarticles__oxparentid->value ) {
00964 $aIds[] = $this->oxarticles__oxparentid->value;
00965 }
00966
00967
00968 if ( $this->getConfig()->getConfigParam( 'blShowVariantReviews' ) ) {
00969 $aAdd = $this->_getVariantsIds();
00970 if (is_array($aAdd)) {
00971 $aIds = array_merge($aIds, $aAdd);
00972 }
00973 }
00974
00975 $oReview = oxNew('oxreview');
00976 $oRevs = $oReview->loadList('oxarticle', $aIds);
00977
00978
00979 if ( $oRevs->count() < 1 ) {
00980 return null;
00981 }
00982
00983 return $oRevs;
00984 }
00985
00991 public function getCrossSelling()
00992 {
00993 $oCrosslist = oxNew( "oxarticlelist");
00994 $oCrosslist->loadArticleCrossSell($this->oxarticles__oxid->value);
00995 if ( $oCrosslist->count() ) {
00996 return $oCrosslist;
00997 }
00998 }
00999
01005 public function getAccessoires()
01006 {
01007 $myConfig = $this->getConfig();
01008
01009
01010 if ( !$myConfig->getConfigParam( 'bl_perfLoadAccessoires' ) ) {
01011 return;
01012 }
01013
01014 $oAcclist = oxNew( "oxarticlelist");
01015 $oAcclist->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofCrossellArticles' ));
01016 $oAcclist->loadArticleAccessoires($this->oxarticles__oxid->value);
01017
01018 if ( $oAcclist->count()) {
01019 return $oAcclist;
01020 }
01021 }
01022
01028 public function getSimilarProducts()
01029 {
01030
01031 $myConfig = $this->getConfig();
01032 if ( !$myConfig->getConfigParam( 'bl_perfLoadSimilar' ) ) {
01033 return;
01034 }
01035
01036 $sArticleTable = $this->getViewName();
01037
01038 $sAttribs = '';
01039 $iCnt = 0;
01040 $this->_getAttribsString($sAttribs, $iCnt);
01041
01042 if ( !$sAttribs) {
01043 return null;
01044 }
01045
01046 $aList = $this->_getSimList($sAttribs, $iCnt);
01047
01048 if ( count( $aList ) ) {
01049 uasort( $aList, 'cmpart');
01050
01051 $sSearch = $this->_generateSimListSearchStr($sArticleTable, $aList);
01052
01053 $oSimilarlist = oxNew( 'oxarticlelist' );
01054 $oSimilarlist->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofSimilarArticles' ));
01055 $oSimilarlist->selectString( $sSearch);
01056
01057 return $oSimilarlist;
01058 }
01059 }
01060
01066 public function getCustomerAlsoBoughtThisProducts()
01067 {
01068
01069 $myConfig = $this->getConfig();
01070 if ( !$myConfig->getConfigParam( 'bl_perfLoadCustomerWhoBoughtThis' ) ) {
01071 return;
01072 }
01073
01074
01075 $sQ = $this->_generateSearchStrForCustomerBought();
01076
01077 $oArticles = oxNew( 'oxarticlelist' );
01078 $oArticles->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofCustomerWhoArticles' ));
01079 $oArticles->selectString( $sQ );
01080 if ( $oArticles->count() ) {
01081 return $oArticles;
01082 }
01083 }
01084
01091 public function loadAmountPriceInfo()
01092 {
01093 $myConfig = $this->getConfig();
01094 if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice || !$this->_blCalcPrice || !$this->hasAmountPrice() ) {
01095 return array();
01096 }
01097
01098 if ( $this->_oAmountPriceInfo === null ) {
01099 $this->_oAmountPriceInfo = array();
01100 if ( count( ( $oAmPriceList = $this->_getAmountPriceList() ) ) ) {
01101 $this->_oAmountPriceInfo = $this->_fillAmountPriceList( $oAmPriceList );
01102 }
01103 }
01104 return $this->_oAmountPriceInfo;
01105 }
01106
01114 public function getSelectLists($sKeyPrefix = null)
01115 {
01116
01117
01118 $sKey = $this->getId();
01119 if ( isset( $sKeyPrefix ) ) {
01120 $sKey = $sKeyPrefix.'__'.$sKey;
01121 }
01122
01123 if ( !isset( self::$_aSelList[$sKey] ) ) {
01124 $oDb = oxDb::getDb();
01125 $sSLViewName = getViewName( 'oxselectlist' );
01126
01127 $sQ = "select {$sSLViewName}.* from oxobject2selectlist join {$sSLViewName} on $sSLViewName.oxid=oxobject2selectlist.oxselnid
01128 where oxobject2selectlist.oxobjectid=%s order by oxobject2selectlist.oxsort";
01129
01130
01131 $oLists = oxNew( 'oxlist' );
01132 $oLists->init( 'oxselectlist' );
01133 $oLists->selectString( sprintf( $sQ, $oDb->quote( $this->getId() ) ) );
01134
01135
01136 if ( $oLists->count() == 0 && $this->oxarticles__oxparentid->value ) {
01137 $oLists->selectString( sprintf( $sQ, $oDb->quote( $this->oxarticles__oxparentid->value ) ) );
01138 }
01139
01140
01141
01142
01143
01144 $dVat = $this->getArticleVat();
01145
01146 $iCnt = 0;
01147 self::$_aSelList[$sKey] = array();
01148 foreach ( $oLists as $oSelectlist ) {
01149 self::$_aSelList[$sKey][$iCnt] = $oSelectlist->getFieldList( $dVat );
01150 self::$_aSelList[$sKey][$iCnt]['name'] = $oSelectlist->oxselectlist__oxtitle->value;
01151 $iCnt++;
01152 }
01153 }
01154 return self::$_aSelList[$sKey];
01155 }
01156
01164 protected function _hasAnyVariant( $blForceCoreTable = null )
01165 {
01166 $blHas = false;
01167 if ( ( $sId = $this->getId() ) ) {
01168 if ( $this->oxarticles__oxshopid->value == $this->getConfig()->getShopId() ) {
01169 $blHas = (bool) $this->oxarticles__oxvarcount->value;
01170 } else {
01171 $sArticleTable = $this->getViewName( $blForceCoreTable );
01172 $blHas = (bool) oxDb::getDb()->getOne( "select 1 from $sArticleTable where oxparentid='{$sId}'" );
01173 }
01174 }
01175 return $blHas;
01176 }
01177
01183 public function hasMdVariants()
01184 {
01185 return $this->_blHasMdVariants;
01186 }
01187
01197 public function getVariantSelections( $aFilterIds = null, $sActVariantId = null, $iLimit = 0 )
01198 {
01199 $iLimit = (int) $iLimit;
01200 if ( !isset( $this->_aVariantSelections[$iLimit] ) ) {
01201 $aVariantSelections = false;
01202 if ( $this->oxarticles__oxvarcount->value ) {
01203 $oVariants = $this->getVariants( false );
01204 $aVariantSelections = oxNew( "oxVariantHandler" )->buildVariantSelections( $this->oxarticles__oxvarname->getRawValue(), $oVariants, $aFilterIds, $sActVariantId, $iLimit );
01205
01206 if ( !empty($oVariants) && empty( $aVariantSelections['rawselections'] ) ) {
01207 $aVariantSelections = false;
01208 }
01209 }
01210 $this->_aVariantSelections[$iLimit] = $aVariantSelections;
01211 }
01212
01213 return $this->_aVariantSelections[$iLimit];
01214 }
01215
01224 public function getSelections( $iLimit = null, $aFilter = null )
01225 {
01226 $sId = $this->getId() . ( (int) $iLimit );
01227 if ( !array_key_exists( $sId, self::$_aSelections ) ) {
01228
01229 $oDb = oxDb::getDb();
01230 $sSLViewName = getViewName( 'oxselectlist' );
01231
01232 $sQ = "select {$sSLViewName}.* from oxobject2selectlist join {$sSLViewName} on $sSLViewName.oxid=oxobject2selectlist.oxselnid
01233 where oxobject2selectlist.oxobjectid=%s order by oxobject2selectlist.oxsort";
01234
01235 if ( ( $iLimit = (int) $iLimit ) ) {
01236 $sQ .= " limit $iLimit ";
01237 }
01238
01239
01240 $dVat = 0;
01241 if ( ( $oPrice = $this->getPrice() ) != null ) {
01242 $dVat = $oPrice->getVat();
01243 }
01244
01245
01246 $oList = oxNew( 'oxlist' );
01247 $oList->init( 'oxselectlist' );
01248 $oList->getBaseObject()->setVat( $dVat );
01249 $oList->selectString( sprintf( $sQ, $oDb->quote( $this->getId() ) ) );
01250
01251
01252 if ( $oList->count() == 0 && $this->oxarticles__oxparentid->value ) {
01253 $oList->selectString( sprintf( $sQ, $oDb->quote( $this->oxarticles__oxparentid->value ) ) );
01254 }
01255
01256 self::$_aSelections[$sId] = $oList->count() ? $oList : false;
01257 }
01258
01259 if ( self::$_aSelections[$sId] ) {
01260
01261 $aFilter = ( $aFilter === null ) ? oxConfig::getParameter( "sel" ) : $aFilter;
01262 if ( $aFilter ) {
01263 $iSelIdx = 0;
01264 foreach ( self::$_aSelections[$sId] as $oSelection ) {
01265 if ( isset( $aFilter[$iSelIdx] ) ) {
01266 $oSelection->setActiveSelectionByIndex( $aFilter[$iSelIdx] );
01267 }
01268 $iSelIdx++;
01269 }
01270 }
01271 }
01272
01273 return self::$_aSelections[$sId];
01274 }
01275
01285 protected function _loadVariantList( $blSimple, $blRemoveNotOrderables = true, $blForceCoreTable = null )
01286 {
01287 $oVariants = array();
01288 if ( ( $sId = $this->getId() ) ) {
01289
01290 self::$_aLoadedParents[$sId] = $this;
01291
01292 $myConfig = $this->getConfig();
01293
01294 if ( !$this->_blLoadVariants ||
01295 ( !$this->isAdmin() && !$myConfig->getConfigParam( 'blLoadVariants') ) ||
01296 ( !$this->isAdmin() && !$this->oxarticles__oxvarcount->value ) ) {
01297 return $oVariants;
01298 }
01299
01300
01301 $sCacheKey = $blSimple ? "simple" : "full";
01302 if ( $blRemoveNotOrderables ) {
01303 if ( isset( $this->_aVariants[$sCacheKey] ) ) {
01304 return $this->_aVariants[$sCacheKey];
01305 } else {
01306 $this->_aVariants[$sCacheKey] = & $oVariants;
01307 }
01308 } elseif ( !$blRemoveNotOrderables ) {
01309 if ( isset( $this->_aVariantsWithNotOrderables[$sCacheKey] ) ) {
01310 return $this->_aVariantsWithNotOrderables[$sCacheKey];
01311 } else {
01312 $this->_aVariantsWithNotOrderables[$sCacheKey] = & $oVariants;
01313 }
01314 }
01315
01316 if ( ( $this->_blHasVariants = $this->_hasAnyVariant( $blForceCoreTable ) ) ) {
01317
01318
01319 if ( $blSimple ) {
01320 $oVariants = oxNew( 'oxsimplevariantlist' );
01321 $oVariants->setParent( $this );
01322 } else {
01323
01324 $oVariants = oxNew( 'oxarticlelist' );
01325 $oVariants->getBaseObject()->modifyCacheKey( '_variants' );
01326 }
01327
01328 startProfile("selectVariants");
01329 $blUseCoreTable = (bool) $blForceCoreTable;
01330 $oBaseObject = $oVariants->getBaseObject();
01331 $oBaseObject->setLanguage( $this->getLanguage() );
01332
01333
01334 $sArticleTable = $this->getViewName( $blUseCoreTable );
01335
01336 $sSelect = "select ".$oBaseObject->getSelectFields( $blUseCoreTable )." from $sArticleTable where " .
01337 $this->getActiveCheckQuery( $blUseCoreTable ) .
01338 $this->getVariantsQuery( $blRemoveNotOrderables, $blUseCoreTable ) .
01339 " order by $sArticleTable.oxsort";
01340
01341
01342 $oVariants->selectString( $sSelect );
01343
01344
01345 if ( $myConfig->getConfigParam( 'blUseMultidimensionVariants' ) ) {
01346 $oMdVariants = oxNew( "oxVariantHandler" );
01347 $this->_blHasMdVariants = $oMdVariants->isMdVariant( $oVariants->current() );
01348 }
01349 stopProfile("selectVariants");
01350 }
01351
01352
01353 if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && $this->_blHasVariants ) {
01354 $this->_blNotBuyableParent = true;
01355 }
01356
01357
01358 if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && count( $oVariants ) == 0 && $this->_blHasVariants ) {
01359 $this->_blNotBuyable = true;
01360 }
01361 }
01362
01363 return $oVariants;
01364 }
01365
01374 public function getFullVariants( $blRemoveNotOrderables = true, $blForceCoreTable = null )
01375 {
01376 return $this->_loadVariantList( false, $blRemoveNotOrderables, $blForceCoreTable );
01377 }
01378
01387 public function getVariants( $blRemoveNotOrderables = true, $blForceCoreTable = null )
01388 {
01389 return $this->_loadVariantList( $this->_isInList(), $blRemoveNotOrderables, $blForceCoreTable );
01390 }
01391
01397 public function getSimpleVariants()
01398 {
01399 if ( $this->oxarticles__oxvarcount->value) {
01400 return $this->getVariants();
01401 }
01402 }
01403
01412 public function getAdminVariants( $sLanguage = null )
01413 {
01414 $oVariants = oxNew( 'oxarticlelist');
01415 if ( ( $sId = $this->getId() ) ) {
01416
01417 $oBaseObj = $oVariants->getBaseObject();
01418
01419 if ( is_null( $sLanguage ) ) {
01420 $oBaseObj->setLanguage( oxRegistry::getLang()->getBaseLanguage() );
01421 } else {
01422 $oBaseObj->setLanguage( $sLanguage );
01423 }
01424
01425 $sSql = "select * from ".$oBaseObj->getViewName()." where oxparentid = '{$sId}' order by oxsort ";
01426 $oVariants->selectString( $sSql );
01427
01428
01429 if ( !$this->getConfig()->getConfigParam( 'blVariantParentBuyable' ) && ( $oVariants->count() > 0 ) ) {
01430
01431 $this->_blNotBuyableParent = true;
01432 }
01433 }
01434
01435 return $oVariants;
01436 }
01437
01445 public function getCategory()
01446 {
01447 $oCategory = oxNew( 'oxcategory' );
01448 $oCategory->setLanguage( $this->getLanguage() );
01449
01450
01451 $sOXID = $this->getId();
01452 if ( isset( $this->oxarticles__oxparentid->value ) && $this->oxarticles__oxparentid->value ) {
01453 $sOXID = $this->oxarticles__oxparentid->value;
01454 }
01455
01456 if ( $sOXID ) {
01457
01458 if ( !isset( $this->_aCategoryCache[ $sOXID ] ) ) {
01459 startPRofile( 'getCategory' );
01460 $oStr = getStr();
01461 $sWhere = $oCategory->getSqlActiveSnippet();
01462 $sSelect = $this->_generateSearchStr( $sOXID );
01463 $sSelect .= ( $oStr->strstr( $sSelect, 'where' )?' and ':' where ') . $sWhere . " order by oxobject2category.oxtime limit 1";
01464
01465
01466 if ( !$oCategory->assignRecord( $sSelect ) ) {
01467
01468 $sSelect = $this->_generateSearchStr( $sOXID, true );
01469 $sSelect .= ( $oStr->strstr( $sSelect, 'where' )?' and ':' where ') . $sWhere . " limit 1";
01470
01471
01472 if ( !$oCategory->assignRecord( $sSelect ) ) {
01473 $oCategory = null;
01474 }
01475 }
01476
01477 $this->_aCategoryCache[ $sOXID ] = $oCategory;
01478 stopPRofile( 'getCategory' );
01479 } else {
01480
01481 $oCategory = $this->_aCategoryCache[ $sOXID ];
01482 }
01483 }
01484
01485 return $oCategory;
01486 }
01487
01496 public function getCategoryIds( $blActCats = false, $blSkipCache = false )
01497 {
01498 $myConfig = $this->getConfig();
01499 if ( isset( self::$_aArticleCats[$this->getId()] ) && !$blSkipCache ) {
01500 return self::$_aArticleCats[$this->getId()];
01501 }
01502
01503
01504 $sOXID = $this->getId();
01505 if (isset( $this->oxarticles__oxparentid->value) && $this->oxarticles__oxparentid->value) {
01506 $sOXID = $this->oxarticles__oxparentid->value;
01507 }
01508
01509
01510 $sSql = $this->_getSelectCatIds( $sOXID, $blActCats );
01511 $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
01512 $rs = $oDb->select( $sSql );
01513
01514
01515 $aRet = array();
01516
01517 if ($rs != false && $rs->recordCount() > 0) {
01518 while (!$rs->EOF) {
01519 $aRet[] = $rs->fields['oxcatnid'];
01520 $rs->moveNext();
01521 }
01522 }
01523
01524
01525 $sSql = $this->getSqlForPriceCategories();
01526 $oDb->setFetchMode( oxDb::FETCH_MODE_ASSOC );
01527 $rs = $oDb->select( $sSql );
01528
01529 if ($rs != false && $rs->recordCount() > 0) {
01530 while (!$rs->EOF) {
01531
01532 if ( is_array( $rs->fields ) ) {
01533 $rs->fields = array_change_key_case( $rs->fields, CASE_LOWER );
01534 }
01535
01536
01537 if ( !$aRet[$rs->fields['oxid']] ) {
01538 $aRet[] = $rs->fields['oxid'];
01539 }
01540 $rs->moveNext();
01541 }
01542 }
01543
01544 return self::$_aArticleCats[$this->getId()] = $aRet;
01545 }
01546
01555 protected function _getSelectCatIds( $sOXID, $blActCats = false )
01556 {
01557 $sO2CView = $this->_getObjectViewName('oxobject2category');
01558 $sCatView = $this->_getObjectViewName('oxcategories');
01559 $sSelect = "select oxobject2category.oxcatnid as oxcatnid from $sO2CView as oxobject2category left join $sCatView as oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
01560 $sSelect .= 'where oxobject2category.oxobjectid='.oxDb::getDb()->quote($sOXID).' and oxcategories.oxid is not null and oxcategories.oxactive = 1 ';
01561 if ( $blActCats ) {
01562 $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 ";
01563 }
01564 $sSelect .= 'order by oxobject2category.oxtime ';
01565 return $sSelect;
01566 }
01567
01577 public function getVendor( $blShopCheck = true )
01578 {
01579 if ( ( $sVendorId = $this->getVendorId() ) ) {
01580 $oVendor = oxNew( 'oxvendor' );
01581 } elseif ( !$blShopCheck && $this->oxarticles__oxvendorid->value ) {
01582 $oVendor = oxNew( 'oxi18n' );
01583 $oVendor->init('oxvendor');
01584 $oVendor->setReadOnly( true );
01585 $sVendorId = $this->oxarticles__oxvendorid->value;
01586 }
01587 if ( $sVendorId && $oVendor->load( $sVendorId ) && $oVendor->oxvendor__oxactive->value ) {
01588
01589 return $oVendor;
01590 }
01591 return null;
01592 }
01593
01601 public function getVendorId( $blForceReload = false )
01602 {
01603 $sVendorId = false;
01604 if ( $this->oxarticles__oxvendorid->value ) {
01605 $sVendorId = $this->oxarticles__oxvendorid->value;
01606
01607 }
01608 return $sVendorId;
01609 }
01610
01618 public function getManufacturerId( $blForceReload = false )
01619 {
01620 $sManufacturerId = false;
01621 if ( $this->oxarticles__oxmanufacturerid->value ) {
01622
01623 $sManufacturerId = $this->oxarticles__oxmanufacturerid->value;
01624
01625 }
01626 return $sManufacturerId;
01627 }
01628
01638 public function getManufacturer( $blShopCheck = true )
01639 {
01640 $oManufacturer = oxNew( 'oxmanufacturer' );;
01641 if ( !( $sManufacturerId = $this->getManufacturerId() ) &&
01642 !$blShopCheck && $this->oxarticles__oxmanufacturerid->value ) {
01643 $oManufacturer->setReadOnly( true );
01644 $sManufacturerId = $this->oxarticles__oxmanufacturerid->value;
01645 }
01646
01647 if ( $sManufacturerId && $oManufacturer->load( $sManufacturerId ) ) {
01648 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadManufacturerTree' ) ) {
01649 $oManufacturer->setReadOnly( true );
01650 }
01651 $oManufacturer = $oManufacturer->oxmanufacturers__oxactive->value ? $oManufacturer : null;
01652 } else {
01653 $oManufacturer = null;
01654 }
01655
01656 return $oManufacturer;
01657 }
01658
01666 public function inCategory( $sCatNid)
01667 {
01668 return in_array( $sCatNid, $this->getCategoryIds());
01669 }
01670
01679 public function isAssignedToCategory( $sCatId )
01680 {
01681
01682 $sOXID = $this->getId();
01683 if ( isset( $this->oxarticles__oxparentid->value) && $this->oxarticles__oxparentid->value) {
01684 $sOXID = $this->oxarticles__oxparentid->value;
01685 }
01686
01687 $oDb = oxDb::getDb();
01688 $sSelect = $this->_generateSelectCatStr( $sOXID, $sCatId);
01689 $sOXID = $oDb->getOne( $sSelect );
01690
01691 if ( isset( $sOXID) && $sOXID) {
01692 return true;
01693 }
01694
01695
01696 if ( $this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) && $this->_blLoadPrice ) {
01697 $dPriceFromTo = $this->getPrice()->getBruttoPrice();
01698 if ( $dPriceFromTo > 0) {
01699 $sSelect = $this->_generateSelectCatStr( $sOXID, $sCatId, $dPriceFromTo);
01700 $sOXID = $oDb->getOne( $sSelect );
01701
01702 if ( isset( $sOXID) && $sOXID) {
01703 return true;
01704 }
01705 }
01706 }
01707 return false;
01708 }
01709
01715 public function getTPrice()
01716 {
01717 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
01718 return;
01719 }
01720
01721
01722 if ( $this->_oTPrice !== null ) {
01723 return $this->_oTPrice;
01724 }
01725
01726 $oPrice = $this->_getPriceObject();
01727
01728 $dBasePrice = $this->oxarticles__oxtprice->value;
01729 $dBasePrice = $this->_preparePrice( $dBasePrice, $this->getArticleVat() );
01730
01731 $oPrice->setPrice( $dBasePrice );
01732
01733 $this->_applyVat( $oPrice, $this->getArticleVat() );
01734 $this->_applyCurrency( $oPrice );
01735
01736 if ( $this->isParentNotBuyable() ) {
01737
01738 $oPrice2 = $this->getVarMinPrice();
01739 } else {
01740
01741 $oPrice2 = $this->getPrice();
01742 }
01743
01744 if ( $oPrice->getPrice() <= $oPrice2->getPrice() ) {
01745
01746 return;
01747 }
01748
01749 $this->_oTPrice = $oPrice;
01750
01751 return $this->_oTPrice;
01752 }
01753
01759 public function skipDiscounts()
01760 {
01761
01762 if ( $this->_blSkipDiscounts !== null ) {
01763 return $this->_blSkipDiscounts;
01764 }
01765
01766 if ( $this->oxarticles__oxskipdiscounts->value ) {
01767 return true;
01768 }
01769
01770
01771 $this->_blSkipDiscounts = false;
01772 if ( oxRegistry::get("oxDiscountList")->hasSkipDiscountCategories() ) {
01773
01774 $oDb = oxDb::getDb();
01775 $sO2CView = getViewName( 'oxobject2category', $this->getLanguage() );
01776 $sViewName = getViewName( 'oxcategories', $this->getLanguage() );
01777 $sSelect = "select 1 from $sO2CView as $sO2CView left join {$sViewName} on {$sViewName}.oxid = $sO2CView.oxcatnid
01778 where $sO2CView.oxobjectid=".$oDb->quote( $this->getId() )." and {$sViewName}.oxactive = 1 and {$sViewName}.oxskipdiscounts = '1' ";
01779 $this->_blSkipDiscounts = ( $oDb->getOne( $sSelect ) == 1 );
01780 }
01781
01782 return $this->_blSkipDiscounts;
01783 }
01784
01792 public function setPrice(oxPrice $oPrice)
01793 {
01794 $this->_oPrice = $oPrice;
01795 }
01796
01805 public function getBasePrice( $dAmount = 1 )
01806 {
01807
01808
01809
01810
01811 $myConfig = $this->getConfig();
01812 if( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice )
01813 return;
01814
01815
01816 $dPrice = $this->_getAmountPrice( $dAmount );
01817
01818
01819 return $dPrice;
01820 }
01821
01829 public function getPrice( $dAmount = 1 )
01830 {
01831 $myConfig = $this->getConfig();
01832
01833 if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
01834 return;
01835 }
01836
01837
01838 if ( $dAmount != 1 || $this->_oPrice === null ) {
01839
01840
01841 $dBasePrice = $this->getBasePrice( $dAmount );
01842 $dBasePrice = $this->_preparePrice( $dBasePrice, $this->getArticleVat() );
01843
01844 $oPrice = $this->_getPriceObject();
01845
01846 $oPrice->setPrice( $dBasePrice );
01847
01848
01849 if ( !$this->_blCalcPrice && $dAmount == 1 ) {
01850 return $this->_oPrice = $oPrice;
01851 }
01852
01853 $this->_calculatePrice( $oPrice );
01854 if ( $dAmount != 1 ) {
01855 return $oPrice;
01856 }
01857
01858 $this->_oPrice = $oPrice;
01859 }
01860 return $this->_oPrice;
01861 }
01862
01871 protected function _calculatePrice( $oPrice, $dVat = null )
01872 {
01873
01874 if ( isset( $dVat ) || !$this->getConfig()->getConfigParam( 'bl_perfCalcVatOnlyForBasketOrder' ) ) {
01875 $this->_applyVAT( $oPrice, isset( $dVat ) ? $dVat : $this->getArticleVat() );
01876 }
01877
01878
01879 $this->_applyCurrency( $oPrice );
01880
01881 if ( !$this->skipDiscounts() ) {
01882 $oDiscountList = oxRegistry::get("oxDiscountList");
01883 $aDiscounts = $oDiscountList->getArticleDiscounts( $this, $this->getArticleUser() );
01884
01885 reset( $aDiscounts );
01886 foreach ( $aDiscounts as $oDiscount ) {
01887 $oPrice->setDiscount($oDiscount->getAddSum(), $oDiscount->getAddSumType());
01888 }
01889 $oPrice->calculateDiscount();
01890 }
01891
01892 return $oPrice;
01893 }
01894
01902 public function setArticleUser($oUser)
01903 {
01904 $this->_oUser = $oUser;
01905 }
01906
01912 public function getArticleUser()
01913 {
01914 if ($this->_oUser) {
01915 return $this->_oUser;
01916 }
01917 return $this->getUser();
01918 }
01919
01929 public function getBasketPrice( $dAmount, $aSelList, $oBasket )
01930 {
01931 $oUser = $oBasket->getBasketUser();
01932 $this->setArticleUser( $oUser );
01933
01934 $oBasketPrice = $this->_getPriceObject( $oBasket->isCalculationModeNetto() );
01935
01936
01937 $dBasePrice = $this->getBasePrice( $dAmount );
01938
01939 $dBasePrice = $this->_modifySelectListPrice( $dBasePrice, $aSelList );
01940 $dBasePrice = $this->_preparePrice( $dBasePrice, $this->getArticleVat(), $oBasket->isCalculationModeNetto() );
01941
01942
01943
01944
01945 $oBasketPrice->setPrice( $dBasePrice );
01946
01947 $dVat = oxRegistry::get("oxVatSelector")->getBasketItemVat( $this, $oBasket );
01948 $this->_calculatePrice( $oBasketPrice, $dVat );
01949
01950
01951 return $oBasketPrice;
01952 }
01953
01962 public function delete( $sOXID = null )
01963 {
01964 if ( !$sOXID ) {
01965 $sOXID = $this->getId();
01966 }
01967 if ( !$sOXID ) {
01968 return false;
01969 }
01970
01971
01972
01973
01974 $this->_deleteVariantRecords( $sOXID );
01975 $this->load( $sOXID );
01976 $this->_deletePics();
01977 $this->_onChangeResetCounts( $sOXID, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
01978
01979
01980 parent::delete( $sOXID );
01981
01982 $rs = $this->_deleteRecords( $sOXID );
01983
01984 oxRegistry::get("oxSeoEncoderArticle")->onDeleteArticle($this);
01985
01986 $this->onChange( ACTION_DELETE, $sOXID, $this->oxarticles__oxparentid->value );
01987
01988 return $rs->EOF;
01989 }
01990
01999 public function reduceStock($dAmount, $blAllowNegativeStock = false)
02000 {
02001 $this->beforeUpdate();
02002
02003 $iStockCount = $this->oxarticles__oxstock->value - $dAmount;
02004 if (!$blAllowNegativeStock && ($iStockCount < 0)) {
02005 $dAmount += $iStockCount;
02006 $iStockCount = 0;
02007 }
02008 $this->oxarticles__oxstock = new oxField($iStockCount);
02009
02010 $oDb = oxDb::getDb();
02011 $oDb->execute( 'update oxarticles set oxarticles.oxstock = '.$oDb->quote( $iStockCount ).' where oxarticles.oxid = '.$oDb->quote( $this->getId() ) );
02012 $this->onChange( ACTION_UPDATE_STOCK );
02013 return $dAmount;
02014 }
02015
02024 public function updateSoldAmount( $dAmount = 0 )
02025 {
02026 if ( !$dAmount ) {
02027 return;
02028 }
02029
02030 $this->beforeUpdate();
02031
02032
02033 if ( !$this->oxarticles__oxparentid->value ) {
02034
02035 $dAmount = (double) $dAmount;
02036 $oDb = oxDb::getDb();
02037 $rs = $oDb->execute( "update oxarticles set oxarticles.oxsoldamount = oxarticles.oxsoldamount + $dAmount where oxarticles.oxid = ".$oDb->quote($this->oxarticles__oxid->value));
02038 } elseif ( $this->oxarticles__oxparentid->value) {
02039
02040 $oUpdateArticle = $this->getParentArticle();
02041 $oUpdateArticle->updateSoldAmount( $dAmount );
02042 }
02043
02044 $this->onChange( ACTION_UPDATE );
02045
02046 return $rs;
02047 }
02048
02054 public function disableReminder()
02055 {
02056 $oDb = oxDb::getDb();
02057 return $oDb->execute( "update oxarticles set oxarticles.oxremindactive = 2 where oxarticles.oxid = ".$oDb->quote($this->oxarticles__oxid->value));
02058 }
02059
02065 public function save()
02066 {
02067 if ( ( $blRet = parent::save() ) ) {
02068
02069 $this->_saveArtLongDesc();
02070 }
02071
02072 return $blRet;
02073 }
02074
02080 public function resetParent()
02081 {
02082 $sParentId = $this->oxarticles__oxparentid;
02083 $this->oxarticles__oxparentid = new oxField( '', oxField::T_RAW );
02084 $this->_blAllowEmptyParentId = true;
02085 $this->save();
02086 $this->_blAllowEmptyParentId = false;
02087
02088 if ( $sParentId !== '' ) {
02089 $this->onChange( ACTION_UPDATE, null, $sParentId );
02090 }
02091 }
02092
02093
02100 public function getPictureGallery()
02101 {
02102 $myConfig = $this->getConfig();
02103
02104
02105 $blMorePic = false;
02106 $aArtPics = array();
02107 $aArtIcons = array();
02108 $iActPicId = 1;
02109 $sActPic = $this->getPictureUrl( $iActPicId );
02110
02111 if ( oxConfig::getParameter( 'actpicid' ) ) {
02112 $iActPicId = oxConfig::getParameter('actpicid');
02113 }
02114
02115 $oStr = getStr();
02116 $iCntr = 0;
02117 $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
02118 $blCheckActivePicId = true;
02119
02120 for ( $i = 1; $i <= $iPicCount; $i++) {
02121 $sPicVal = $this->getPictureUrl( $i );
02122 $sIcoVal = $this->getIconUrl( $i );
02123 if ( !$oStr->strstr($sIcoVal, 'nopic_ico.jpg') && !$oStr->strstr($sIcoVal, 'nopic.jpg') &&
02124 !$oStr->strstr($sPicVal, 'nopic_ico.jpg') && !$oStr->strstr($sPicVal, 'nopic.jpg') ) {
02125 if ($iCntr) {
02126 $blMorePic = true;
02127 }
02128 $aArtIcons[$i]= $sIcoVal;
02129 $aArtPics[$i]= $sPicVal;
02130 $iCntr++;
02131
02132 if ($iActPicId == $i) {
02133 $sActPic = $sPicVal;
02134 $blCheckActivePicId = false;
02135 }
02136
02137 } else if ( $blCheckActivePicId && $iActPicId <= $i) {
02138
02139
02140 $iActPicId++;
02141 }
02142 }
02143
02144 $blZoomPic = false;
02145 $aZoomPics = array();
02146 $iZoomPicCount = $myConfig->getConfigParam( 'iPicCount' );
02147
02148 for ( $j = 1,$c = 1; $j <= $iZoomPicCount; $j++) {
02149 $sVal = $this->getZoomPictureUrl($j);
02150
02151 if ( $sVal && !$oStr->strstr($sVal, 'nopic.jpg')) {
02152 $blZoomPic = true;
02153 $aZoomPics[$c]['id'] = $c;
02154 $aZoomPics[$c]['file'] = $sVal;
02155
02156 if (!$sVal) {
02157 $aZoomPics[$c]['file'] = "nopic.jpg";
02158 }
02159 $c++;
02160 }
02161 }
02162
02163 $aPicGallery = array('ActPicID' => $iActPicId,
02164 'ActPic' => $sActPic,
02165 'MorePics' => $blMorePic,
02166 'Pics' => $aArtPics,
02167 'Icons' => $aArtIcons,
02168 'ZoomPic' => $blZoomPic,
02169 'ZoomPics' => $aZoomPics);
02170
02171 return $aPicGallery;
02172 }
02173
02187 public function onChange($sAction = null, $sOXID = null, $sParentID = null)
02188 {
02189 $myConfig = $this->getConfig();
02190
02191 if (!isset($sOXID)) {
02192 if ( $this->getId()) {
02193 $sOXID = $this->getId();
02194 }
02195 if (!isset ($sOXID)) {
02196 $sOXID = $this->oxarticles__oxid->value;
02197 }
02198 if ($this->oxarticles__oxparentid->value) {
02199 $sParentID = $this->oxarticles__oxparentid->value;
02200 }
02201 }
02202 if (!isset($sOXID)) {
02203 return;
02204 }
02205
02206
02207 if ( $myConfig->getConfigParam( 'blUseStock' ) ) {
02208
02209
02210 if (!isset($sParentID)) {
02211 $oDb = oxDb::getDb();
02212 $sQ = 'select oxparentid from oxarticles where oxid = '.$oDb->quote($sOXID);
02213 $sParentID = $oDb->getOne( $sQ );
02214 }
02215
02216 if ($sParentID) {
02217 $this->_onChangeUpdateStock($sParentID);
02218 }
02219 }
02220
02221
02222 if ($sParentID) {
02223 $this->_onChangeUpdateVarCount($sParentID);
02224 }
02225
02226 $sId = ( $sParentID ) ? $sParentID : $sOXID;
02227 $this->_setVarMinMaxPrice( $sId );
02228
02229
02230
02231 if ( $sAction === ACTION_UPDATE_STOCK ) {
02232 $this->_onChangeStockResetCount( $sOXID );
02233 }
02234
02235 }
02236
02243 public function getCustomVAT()
02244 {
02245 if ( isset($this->oxarticles__oxvat->value) ) {
02246 return $this->oxarticles__oxvat->value;
02247 }
02248 }
02249
02258 public function checkForStock( $dAmount, $dArtStockAmount = 0 )
02259 {
02260 $myConfig = $this->getConfig();
02261 if ( !$myConfig->getConfigParam( 'blUseStock' ) ) {
02262 return true;
02263 }
02264
02265 $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
02266
02267 $sQ = 'select oxstock, oxstockflag from oxarticles where oxid = '.$oDb->quote( $this->getId() );
02268 $rs = $oDb->select( $sQ );
02269
02270 $iOnStock = 0;
02271 $iStockFlag = 0;
02272 if ( $rs !== false && $rs->recordCount() > 0 ) {
02273 $iOnStock = $rs->fields['oxstock'] - $dArtStockAmount;
02274 $iStockFlag = $rs->fields['oxstockflag'];
02275
02276
02277 if ( $iStockFlag == 1 || $iStockFlag == 4) {
02278 return true;
02279 }
02280 if ( !$myConfig->getConfigParam( 'blAllowUnevenAmounts' ) ) {
02281 $iOnStock = floor( $iOnStock );
02282 }
02283 }
02284 if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
02285 $iOnStock += $this->getSession()->getBasketReservations()->getReservedAmount($this->getId());
02286 }
02287 if ( $iOnStock >= $dAmount ) {
02288 return true;
02289 } else {
02290 if ( $iOnStock > 0 ) {
02291 return $iOnStock;
02292 } else {
02293 $oEx = oxNew( 'oxArticleInputException' );
02294 $oEx->setMessage( 'EXCEPTION_ARTICLE_ARTICELNOTBUYABLE' );
02295 oxRegistry::get("oxUtilsView")->addErrorToDisplay( $oEx );
02296 return false;
02297 }
02298 }
02299 }
02300
02301
02307 public function getLongDescription()
02308 {
02309 if ( $this->_oLongDesc === null ) {
02310
02311 $this->_oLongDesc = new oxField();
02312
02313
02314
02315 $sOxid = $this->getId();
02316 $sViewName = getViewName( 'oxartextends', $this->getLanguage() );
02317
02318 $oDb = oxDb::getDb();
02319 $sDbValue = $oDb->getOne( "select oxlongdesc from {$sViewName} where oxid = " . $oDb->quote( $sOxid ) );
02320
02321 if ( $sDbValue != false ) {
02322 $this->_oLongDesc->setValue( $sDbValue, oxField::T_RAW );
02323 } elseif ( $this->oxarticles__oxparentid->value ) {
02324 if ( !$this->isAdmin() || $this->_blLoadParentData ) {
02325 $this->_oLongDesc->setValue( $this->getParentArticle()->getLongDescription()->getRawValue(), oxField::T_RAW );
02326 }
02327 }
02328 }
02329 return $this->_oLongDesc;
02330 }
02331
02338 public function getLongDesc()
02339 {
02340 return oxRegistry::get("oxUtilsView")->parseThroughSmarty( $this->getLongDescription()->getRawValue(), $this->getId().$this->getLanguage(), null, true );
02341 }
02342
02350 public function setArticleLongDesc( $sDesc )
02351 {
02352
02353
02354 $this->_oLongDesc = new oxField( $sDesc, oxField::T_RAW );
02355 $this->oxarticles__oxlongdesc = new oxField( $sDesc, oxField::T_RAW );
02356 }
02357
02363 public function getAttributes()
02364 {
02365 if ( $this->_oAttributeList === null ) {
02366 $this->_oAttributeList = oxNew( 'oxattributelist' );
02367 $this->_oAttributeList->loadAttributes( $this->getId(), $this->getParentId() );
02368 }
02369
02370 return $this->_oAttributeList;
02371 }
02372
02378 public function getAttributesDisplayableInBasket()
02379 {
02380 if ( $this->_oAttributeList === null ) {
02381 $this->_oAttributeList = oxNew( 'oxattributelist' );
02382 $this->_oAttributeList->loadAttributesDisplayableInBasket( $this->getId() );
02383 }
02384
02385 return $this->_oAttributeList;
02386 }
02387
02388
02397 public function appendLink( $sAddParams, $iLang = null )
02398 {
02399 if ( $sAddParams ) {
02400 if ( $iLang === null ) {
02401 $iLang = $this->getLanguage();
02402 }
02403
02404 $this->_aSeoAddParams[$iLang] = isset( $this->_aSeoAddParams[$iLang] ) ? $this->_aSeoAddParams[$iLang] . "&" : "";
02405 $this->_aSeoAddParams[$iLang] .= $sAddParams;
02406 }
02407 }
02408
02417 public function getBaseSeoLink( $iLang, $blMain = false )
02418 {
02419 $oEncoder = oxRegistry::get("oxSeoEncoderArticle");
02420 if ( !$blMain ) {
02421 return $oEncoder->getArticleUrl( $this, $iLang, $this->getLinkType() );
02422 }
02423 return $oEncoder->getArticleMainUrl( $this, $iLang );
02424 }
02425
02434 public function getLink( $iLang = null, $blMain = false )
02435 {
02436 if ( !oxRegistry::getUtils()->seoIsActive() ) {
02437 return $this->getStdLink( $iLang );
02438 }
02439
02440 if ( $iLang === null ) {
02441 $iLang = $this->getLanguage();
02442 }
02443
02444 $iLinkType = $this->getLinkType();
02445 if ( !isset( $this->_aSeoUrls[$iLang][$iLinkType] ) ) {
02446 $this->_aSeoUrls[$iLang][$iLinkType] = $this->getBaseSeoLink( $iLang, $blMain );
02447 }
02448
02449 $sUrl = $this->_aSeoUrls[$iLang][$iLinkType];
02450 if ( isset($this->_aSeoAddParams[$iLang])) {
02451 $sUrl .= ( ( strpos( $sUrl.$this->_aSeoAddParams[$iLang], '?' ) === false ) ? '?' : '&' ).$this->_aSeoAddParams[$iLang];
02452 }
02453
02454 return $sUrl;
02455 }
02456
02465 public function getMainLink( $iLang = null )
02466 {
02467 return $this->getLink( $iLang, true );
02468 }
02469
02477 public function setLinkType( $iType )
02478 {
02479
02480 $this->_sDetailLink = null;
02481
02482
02483 $this->_iLinkType = (int) $iType;
02484 }
02485
02491 public function getLinkType()
02492 {
02493 return $this->_iLinkType;
02494 }
02495
02504 public function appendStdLink( $sAddParams, $iLang = null )
02505 {
02506 if ( $sAddParams ) {
02507 if ( $iLang === null ) {
02508 $iLang = $this->getLanguage();
02509 }
02510
02511 $this->_aStdAddParams[$iLang] = isset( $this->_aStdAddParams[$iLang] ) ? $this->_aStdAddParams[$iLang] . "&" : "";
02512 $this->_aStdAddParams[$iLang] .= $sAddParams;
02513 }
02514 }
02515
02525 public function getBaseStdLink( $iLang, $blAddId = true, $blFull = true )
02526 {
02527 $sUrl = '';
02528 if ( $blFull ) {
02529
02530 $sUrl = $this->getConfig()->getShopUrl( $iLang, false );
02531 }
02532
02533 $sUrl .= "index.php?cl=details" . ( $blAddId ? "&anid=".$this->getId() : "" );
02534 return $sUrl . ( isset( $this->_aStdAddParams[$iLang] ) ? "&". $this->_aStdAddParams[$iLang] : "" );
02535 }
02536
02545 public function getStdLink( $iLang = null, $aParams = array() )
02546 {
02547 if ( $iLang === null ) {
02548 $iLang = $this->getLanguage();
02549 }
02550
02551 if ( !isset( $this->_aStdUrls[$iLang] ) ) {
02552 $this->_aStdUrls[$iLang] = $this->getBaseStdLink( $iLang );
02553 }
02554
02555 return oxRegistry::get("oxUtilsUrl")->processUrl( $this->_aStdUrls[$iLang], true, $aParams, $iLang );
02556 }
02557
02567 public function getStdTagLink( $sTag )
02568 {
02569 $oArticleTags = oxNew('oxarticletaglist');
02570 $oArticleTags->setArticleId( $this->getId() );
02571 return $oArticleTags->getStdTagLink($sTag);
02572 }
02573
02581 public function getTags()
02582 {
02583 $oArticleTags = oxNew('oxarticletaglist');
02584 $oArticleTags->load( $this->getId() );
02585 return $oArticleTags->get()->__toString();
02586 }
02587
02597 public function saveTags($sTags)
02598 {
02599
02600 if ( !$this->allowDerivedUpdate() ) {
02601 return false;
02602 }
02603 $oArticleTags = oxNew('oxarticletaglist');
02604 $oArticleTags->setArticleId( $this->getId() );
02605 $oArticleTags->set( $sTags );
02606 $oArticleTags->save();
02607 }
02608
02618 public function addTag($sTag)
02619 {
02620 $oArticleTags = oxNew('oxarticletaglist');
02621 $oArticleTags->load( $this->getId() );
02622 $oArticleTags->addTag( $sTag );
02623 if ( $oArticleTags->save() ) {
02624 return true;
02625 }
02626 return false;
02627 }
02628
02634 public function getMediaUrls()
02635 {
02636 if ( $this->_aMediaUrls === null ) {
02637 $this->_aMediaUrls = oxNew("oxlist");
02638 $this->_aMediaUrls->init("oxmediaurl");
02639 $this->_aMediaUrls->getBaseObject()->setLanguage( $this->getLanguage() );
02640
02641 $sViewName = getViewName( "oxmediaurls", $this->getLanguage() );
02642 $sQ = "select * from {$sViewName} where oxobjectid = '".$this->getId()."'";
02643 $this->_aMediaUrls->selectString($sQ);
02644 }
02645 return $this->_aMediaUrls;
02646 }
02647
02653 public function getDynImageDir()
02654 {
02655 return $this->_sDynImageDir;
02656 }
02657
02663 public function getDispSelList()
02664 {
02665 if ($this->_aDispSelList === null) {
02666 if ( $this->getConfig()->getConfigParam( 'bl_perfLoadSelectLists' ) && $this->getConfig()->getConfigParam( 'bl_perfLoadSelectListsInAList' ) ) {
02667 $this->_aDispSelList = $this->getSelectLists();
02668 }
02669 }
02670 return $this->_aDispSelList;
02671 }
02672
02678 public function getMoreDetailLink()
02679 {
02680 if ( $this->_sMoreDetailLink == null ) {
02681
02682
02683 $this->_sMoreDetailLink = $this->getConfig()->getShopHomeURL() . 'cl=moredetails';
02684
02685
02686 if ( $sActCat = oxConfig::getParameter( 'cnid' ) ) {
02687 $this->_sMoreDetailLink .= '&cnid='.$sActCat;
02688 }
02689 $this->_sMoreDetailLink .= '&anid='.$this->getId();
02690 $this->_sMoreDetailLink = $this->_sMoreDetailLink;
02691 }
02692
02693 return $this->_sMoreDetailLink;
02694 }
02695
02701 public function getToBasketLink()
02702 {
02703 if ( $this->_sToBasketLink == null ) {
02704 $myConfig = $this->getConfig();
02705
02706 if ( oxRegistry::getUtils()->isSearchEngine() ) {
02707 $this->_sToBasketLink = $this->getLink();
02708 } else {
02709
02710 $this->_sToBasketLink = $myConfig->getShopHomeURL();
02711
02712
02713 $sActClass = oxConfig::getParameter( 'cl' );
02714 if ( $sActClass == 'thankyou') {
02715 $sActClass = 'basket';
02716 }
02717 $this->_sToBasketLink .= 'cl='.$sActClass;
02718
02719
02720 if ( $sActCat = oxConfig::getParameter( 'cnid' ) ) {
02721 $this->_sToBasketLink .= '&cnid='.$sActCat;
02722 }
02723
02724 $this->_sToBasketLink .= '&fnc=tobasket&aid='.$this->getId().'&anid='.$this->getId();
02725
02726 if ( $sTpl = basename( oxConfig::getParameter( 'tpl' ) ) ) {
02727 $this->_sToBasketLink .= '&tpl='.$sTpl;
02728 }
02729 }
02730 }
02731
02732 return $this->_sToBasketLink;
02733 }
02734
02740 public function getStockStatus()
02741 {
02742 return $this->_iStockStatus;
02743 }
02744
02750 public function getDeliveryDate()
02751 {
02752 if ( $this->oxarticles__oxdelivery->value != '0000-00-00') {
02753 return oxRegistry::get("oxUtilsDate")->formatDBDate( $this->oxarticles__oxdelivery->value);
02754 }
02755 return false;
02756 }
02757
02763 public function getFTPrice()
02764 {
02765
02766 if ( $oPrice = $this->getTPrice() ) {
02767 if ( $dPrice = $this->_getPriceForView( $oPrice ) ) {
02768 return oxRegistry::getLang()->formatCurrency( $dPrice );
02769 }
02770 }
02771 }
02772
02778 public function getFPrice()
02779 {
02780 if ( $oPrice = $this->getPrice() ) {
02781 $dPrice = $this->_getPriceForView( $oPrice );
02782 return oxRegistry::getLang()->formatCurrency( $dPrice );
02783 }
02784 }
02785
02792 public function resetRemindStatus()
02793 {
02794 if ( $this->oxarticles__oxremindactive->value == 2 &&
02795 $this->oxarticles__oxremindamount->value <= $this->oxarticles__oxstock->value ) {
02796 $this->oxarticles__oxremindactive->value = 1;
02797 }
02798 }
02799
02805 public function getFNetPrice()
02806 {
02807 if ( $oPrice = $this->getPrice() ) {
02808 return oxRegistry::getLang()->formatCurrency( $oPrice->getNettoPrice() );
02809 }
02810 }
02811
02819 public function getPricePerUnit()
02820 {
02821 return $this->getFUnitPrice();
02822 }
02823
02829 public function isParentNotBuyable()
02830 {
02831 return $this->_blNotBuyableParent;
02832 }
02833
02839 public function isNotBuyable()
02840 {
02841 return $this->_blNotBuyable;
02842 }
02843
02851 public function setBuyableState( $blBuyable = false )
02852 {
02853 $this->_blNotBuyable = !$blBuyable;
02854 }
02855
02863 public function setSelectlist( $aSelList )
02864 {
02865 $this->_aDispSelList = $aSelList;
02866 }
02867
02875 public function getPictureUrl( $iIndex = 1 )
02876 {
02877 if ( $iIndex ) {
02878 $sImgName = false;
02879 if ( !$this->_isFieldEmpty( "oxarticles__oxpic".$iIndex ) ) {
02880 $sImgName = basename( $this->{"oxarticles__oxpic$iIndex"}->value );
02881 }
02882
02883 $sSize = $this->getConfig()->getConfigParam( 'aDetailImageSizes' );
02884 return oxRegistry::get("oxPictureHandler")->getProductPicUrl( "product/{$iIndex}/", $sImgName, $sSize, 'oxpic'.$iIndex );
02885 }
02886 }
02887
02896 public function getIconUrl( $iIndex = 0 )
02897 {
02898 $sImgName = false;
02899 $sDirname = "product/1/";
02900 if ( $iIndex && !$this->_isFieldEmpty( "oxarticles__oxpic{$iIndex}" ) ) {
02901 $sImgName = basename( $this->{"oxarticles__oxpic$iIndex"}->value );
02902 $sDirname = "product/{$iIndex}/";
02903 } elseif ( !$this->_isFieldEmpty( "oxarticles__oxicon" ) ) {
02904 $sImgName = basename( $this->oxarticles__oxicon->value );
02905 $sDirname = "product/icon/";
02906 } elseif ( !$this->_isFieldEmpty( "oxarticles__oxpic1" ) ) {
02907 $sImgName = basename( $this->oxarticles__oxpic1->value );
02908 }
02909
02910 $sSize = $this->getConfig()->getConfigParam( 'sIconsize' );
02911 return oxRegistry::get("oxPictureHandler")->getProductPicUrl( $sDirname, $sImgName, $sSize, $iIndex );
02912 }
02913
02921 public function getThumbnailUrl( $bSsl = null )
02922 {
02923 $sImgName = false;
02924 $sDirname = "product/1/";
02925 if ( !$this->_isFieldEmpty( "oxarticles__oxthumb" ) ) {
02926 $sImgName = basename( $this->oxarticles__oxthumb->value );
02927 $sDirname = "product/thumb/";
02928 } elseif ( !$this->_isFieldEmpty( "oxarticles__oxpic1" ) ) {
02929 $sImgName = basename( $this->oxarticles__oxpic1->value );
02930 }
02931
02932 $sSize = $this->getConfig()->getConfigParam( 'sThumbnailsize' );
02933 return oxRegistry::get("oxPictureHandler")->getProductPicUrl( $sDirname, $sImgName, $sSize, 0, $bSsl );
02934 }
02935
02943 public function getZoomPictureUrl( $iIndex = '' )
02944 {
02945 $iIndex = (int) $iIndex;
02946 if ( $iIndex > 0 && !$this->_isFieldEmpty( "oxarticles__oxpic".$iIndex ) ) {
02947 $sImgName = basename( $this->{"oxarticles__oxpic".$iIndex}->value );
02948 $sSize = $this->getConfig()->getConfigParam( "sZoomImageSize" );
02949 return oxRegistry::get("oxPictureHandler")->getProductPicUrl( "product/{$iIndex}/", $sImgName, $sSize, 'oxpic'.$iIndex );
02950 }
02951 }
02952
02958 public function getFileUrl()
02959 {
02960 return $this->getConfig()->getPictureUrl( 'media/' );
02961 }
02962
02970 public function getPriceFromPrefix()
02971 {
02972 $sPricePrefix = '';
02973 if ( $this->_blIsRangePrice) {
02974 $sPricePrefix = oxLang::getInstance()->translateString('PRICE_FROM').' ';
02975 }
02976
02977 return $sPricePrefix;
02978 }
02979
02985 protected function _saveArtLongDesc()
02986 {
02987 $myConfig = $this->getConfig();
02988 $sShopId = $myConfig->getShopID();
02989 if (in_array("oxlongdesc", $this->_aSkipSaveFields)) {
02990 return;
02991 }
02992
02993 if ($this->_blEmployMultilanguage) {
02994 $sValue = $this->getLongDescription()->getRawValue();
02995 if ( $sValue !== null ) {
02996 $oArtExt = oxNew('oxI18n');
02997 $oArtExt->init('oxartextends');
02998 $oArtExt->setLanguage((int) $this->getLanguage());
02999 if (!$oArtExt->load($this->getId())) {
03000 $oArtExt->setId($this->getId());
03001 }
03002 $oArtExt->oxartextends__oxlongdesc = new oxField($sValue, oxField::T_RAW);
03003 $oArtExt->save();
03004 }
03005 } else {
03006 $oArtExt = oxNew('oxI18n');
03007 $oArtExt->setEnableMultilang(false);
03008 $oArtExt->init('oxartextends');
03009 $aObjFields = $oArtExt->_getAllFields(true);
03010 if (!$oArtExt->load($this->getId())) {
03011 $oArtExt->setId($this->getId());
03012 }
03013
03014 foreach ($aObjFields as $sKey => $sValue ) {
03015 if ( preg_match('/^oxlongdesc(_(\d{1,2}))?$/', $sKey) ) {
03016 $sField = $this->_getFieldLongName($sKey);
03017
03018 if (isset($this->$sField)) {
03019 $sLongDesc = null;
03020 if ($this->$sField instanceof oxField) {
03021 $sLongDesc = $this->$sField->getRawValue();
03022 } elseif (is_object($this->$sField)) {
03023 $sLongDesc = $this->$sField->value;
03024 }
03025 if (isset($sLongDesc)) {
03026 $sAEField = $oArtExt->_getFieldLongName($sKey);
03027 $oArtExt->$sAEField = new oxField($sLongDesc, oxField::T_RAW);
03028 }
03029 }
03030 }
03031 }
03032 $oArtExt->save();
03033 }
03034 }
03035
03041 protected function _skipSaveFields()
03042 {
03043 $myConfig = $this->getConfig();
03044
03045 $this->_aSkipSaveFields = array();
03046
03047 $this->_aSkipSaveFields[] = 'oxtimestamp';
03048
03049 $this->_aSkipSaveFields[] = 'oxinsert';
03050
03051 if ( !$this->_blAllowEmptyParentId && (!isset( $this->oxarticles__oxparentid->value) || $this->oxarticles__oxparentid->value == '') ) {
03052 $this->_aSkipSaveFields[] = 'oxparentid';
03053 }
03054
03055 }
03056
03066 protected function _mergeDiscounts( $aDiscounts, $aItemDiscounts)
03067 {
03068 foreach ( $aItemDiscounts as $sKey => $oDiscount ) {
03069
03070 if ( array_key_exists ($sKey, $aDiscounts) ) {
03071 $aDiscounts[$sKey]->dDiscount += $oDiscount->dDiscount;
03072 } else {
03073 $aDiscounts[$sKey] = $oDiscount;
03074 }
03075 }
03076 return $aDiscounts;
03077 }
03078
03084 protected function _getGroupPrice()
03085 {
03086 $sPriceSufix = $this->_getUserPriceSufix();
03087 $sVarName = oxarticles__oxprice.$sPriceSufix;
03088 $dPrice = $this->$sVarName->value;
03089
03090
03091 if ( $this->getConfig()->getConfigParam( 'blOverrideZeroABCPrices' ) && (double) $dPrice == 0 ) {
03092 $dPrice = $this->oxarticles__oxprice->value;
03093 }
03094
03095 return $dPrice;
03096 }
03097
03106 protected function _getAmountPrice($dAmount = 1)
03107 {
03108 $myConfig = $this->getConfig();
03109
03110 startProfile( "_getAmountPrice" );
03111
03112 $dPrice = $this->_getGroupPrice();
03113 $oAmtPrices = $this->_getAmountPriceList();
03114 foreach ($oAmtPrices as $oAmPrice) {
03115 if ($oAmPrice->oxprice2article__oxamount->value <= $dAmount
03116 && $dAmount <= $oAmPrice->oxprice2article__oxamountto->value
03117 && $dPrice > $oAmPrice->oxprice2article__oxaddabs->value ) {
03118 $dPrice = $oAmPrice->oxprice2article__oxaddabs->value;
03119 }
03120 }
03121
03122 stopProfile( "_getAmountPrice" );
03123 return $dPrice;
03124 }
03125
03134 protected function _modifySelectListPrice( $dPrice, $aChosenList = null )
03135 {
03136 $myConfig = $this->getConfig();
03137
03138 if ( $myConfig->getConfigParam( 'bl_perfLoadSelectLists' ) && $myConfig->getConfigParam( 'bl_perfUseSelectlistPrice' ) ) {
03139
03140 $aSelLists = $this->getSelectLists();
03141
03142 foreach ( $aSelLists as $key => $aSel) {
03143 if ( isset( $aChosenList[$key]) && isset($aSel[$aChosenList[$key]] ) ) {
03144 $oSel = $aSel[$aChosenList[$key]];
03145 if ( $oSel->priceUnit =='abs' ) {
03146 $dPrice += $oSel->price;
03147 } elseif ( $oSel->priceUnit =='%' ) {
03148 $dPrice += oxPrice::percent( $dPrice, $oSel->price );
03149 }
03150 }
03151 }
03152 }
03153 return $dPrice;
03154 }
03155
03156
03164 protected function _fillAmountPriceList($oAmPriceList)
03165 {
03166 $myConfig = $this->getConfig();
03167 $oLang = oxRegistry::getLang();
03168
03169
03170 foreach ($oAmPriceList as $sId => $oItem) {
03171
03172 $oItemPrice = $this->_getPriceObject();
03173 if ( $oItem->oxprice2article__oxaddabs->value ) {
03174
03175 $dBasePrice = $oItem->oxprice2article__oxaddabs->value;
03176 $dBasePrice = $this->_preparePrice( $dBasePrice, $this->getArticleVat() );
03177
03178 $oItemPrice->setPrice( $dBasePrice );
03179 $this->_calculatePrice( $oItemPrice );
03180
03181 } else {
03182 $dBasePrice = $this->_getGroupPrice();
03183 $dBasePrice = $this->_preparePrice( $dBasePrice, $this->getArticleVat() );
03184 $oItemPrice->setPrice( $dBasePrice );
03185 $oItemPrice->subtractPercent( $oItem->oxprice2article__oxaddperc->value );
03186 }
03187
03188
03189 $oAmPriceList[$sId]->fbrutprice = $oLang->formatCurrency( $this->_getPriceForView( $oItemPrice ) );
03190 }
03191
03192 return $oAmPriceList;
03193 }
03194
03195
03201 protected function _getVariantsIds()
03202 {
03203 $aSelect = array();
03204 if ( ( $sId = $this->getId() ) ) {
03205 $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
03206 $sQ = "select oxid from " . $this->getViewName( true ) . " where oxparentid = ".$oDb->quote( $sId )." and " .
03207 $this->getSqlActiveSnippet( true ) . " order by oxsort";
03208 $oRs = $oDb->select( $sQ );
03209 if ( $oRs != false && $oRs->recordCount() > 0 ) {
03210 while (!$oRs->EOF) {
03211 $aSelect[] = reset( $oRs->fields );
03212 $oRs->moveNext();
03213 }
03214 }
03215 }
03216 return $aSelect;
03217 }
03218
03224 public function getArticleVat()
03225 {
03226 if (!isset($this->_dArticleVat)) {
03227 $this->_dArticleVat = oxRegistry::get("oxVatSelector")->getArticleVat( $this );
03228 }
03229 return $this->_dArticleVat;
03230 }
03231
03240 protected function _applyVAT( oxPrice $oPrice, $dVat )
03241 {
03242 startProfile(__FUNCTION__);
03243 $oPrice->setVAT( $dVat );
03244 if ( ($dVat = oxRegistry::get("oxVatSelector")->getArticleUserVat($this)) !== false ) {
03245 $oPrice->setUserVat( $dVat );
03246 }
03247 stopProfile(__FUNCTION__);
03248 }
03249
03257 public function applyVats( oxPrice $oPrice )
03258 {
03259 $this->_applyVAT($oPrice, $this->getArticleVat() );
03260 }
03261
03269 public function applyDiscountsForVariant( $oPrice )
03270 {
03271
03272 if ( !$this->skipDiscounts() ) {
03273 $oDiscountList = oxRegistry::get("oxDiscountList");
03274 $aDiscounts = $oDiscountList->getArticleDiscounts( $this, $this->getArticleUser() );
03275
03276 reset( $aDiscounts );
03277 foreach ( $aDiscounts as $oDiscount ) {
03278 $oPrice->setDiscount($oDiscount->getAddSum(), $oDiscount->getAddSumType());
03279 }
03280 $oPrice->calculateDiscount();
03281 }
03282 }
03283
03292 protected function _applyCurrency(oxPrice $oPrice, $oCur = null )
03293 {
03294 if ( !$oCur ) {
03295 $oCur = $this->getConfig()->getActShopCurrencyObject();
03296 }
03297
03298 $oPrice->multiply($oCur->rate);
03299 }
03300
03301
03310 protected function _getAttribsString(&$sAttribs, &$iCnt)
03311 {
03312
03313 $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
03314 $sSelect = 'select oxattrid from oxobject2attribute where oxobject2attribute.oxobjectid='.$oDb->quote( $this->getId() );
03315 $sAttribs = '';
03316 $blSep = false;
03317 $rs = $oDb->select( $sSelect);
03318 $iCnt = 0;
03319 if ($rs != false && $rs->recordCount() > 0) {
03320 while (!$rs->EOF) {
03321 if ( $blSep) {
03322 $sAttribs .= ' or ';
03323 }
03324 $sAttribs .= 't1.oxattrid = '.$oDb->quote($rs->fields['oxattrid']).' ';
03325 $blSep = true;
03326 $iCnt++;
03327 $rs->moveNext();
03328 }
03329 }
03330 }
03331
03340 protected function _getSimList($sAttribs, $iCnt)
03341 {
03342 $myConfig = $this->getConfig();
03343 $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
03344
03345
03346 $iAttrPercent = $myConfig->getConfigParam( 'iAttributesPercent' )/100;
03347
03348 if ( !$iAttrPercent || $iAttrPercent < 0 || $iAttrPercent > 1) {
03349 $iAttrPercent = 0.70;
03350 }
03351
03352 $iHitMin = ceil( $iCnt * $iAttrPercent );
03353
03354
03355 $aList= array();
03356 $sSelect = "select oxobjectid, count(*) as cnt from oxobject2attribute as t1 where
03357 ( $sAttribs )
03358 and t1.oxobjectid != ".$oDb->quote( $this->oxarticles__oxid->value )."
03359 group by t1.oxobjectid having count(*) >= $iHitMin ";
03360
03361 $rs = $oDb->selectLimit( $sSelect, 20, 0 );
03362 if ($rs != false && $rs->recordCount() > 0) {
03363 while (!$rs->EOF) {
03364 $oTemp = new stdClass();
03365 $oTemp->cnt = $rs->fields['cnt'];
03366 $oTemp->id = $rs->fields['oxobjectid'];
03367 $aList[] = $oTemp;
03368 $rs->moveNext();
03369 }
03370 }
03371 return $aList;
03372 }
03373
03382 protected function _generateSimListSearchStr($sArticleTable, $aList)
03383 {
03384 $myConfig = $this->getConfig();
03385 $sFieldList = $this->getSelectFields();
03386 $sSearch = "select $sFieldList from $sArticleTable where ".$this->getSqlActiveSnippet()." and $sArticleTable.oxissearch = 1 and $sArticleTable.oxid in ( ";
03387 $blSep = false;
03388 $iCnt = 0;
03389 $oDb = oxDb::getDb();
03390 foreach ( $aList as $oTemp) {
03391 if ( $blSep) {
03392 $sSearch .= ',';
03393 }
03394 $sSearch .= $oDb->quote($oTemp->id);
03395 $blSep = true;
03396 if ( $iCnt >= $myConfig->getConfigParam( 'iNrofSimilarArticles' ) ) {
03397 break;
03398 }
03399 $iCnt++;
03400 }
03401
03402
03403
03404 $sSearch .= ') ';
03405
03406
03407 $sSearch .= ' order by rand() ';
03408
03409 return $sSearch;
03410 }
03411
03420 protected function _generateSearchStr($sOXID, $blSearchPriceCat = false )
03421 {
03422
03423 $sCatView = getViewName( 'oxcategories', $this->getLanguage() );
03424 $sO2CView = getViewName( 'oxobject2category' );
03425
03426
03427 if ( !$blSearchPriceCat ) {
03428 $sSelect = "select {$sCatView}.* from {$sO2CView} as oxobject2category left join {$sCatView} on
03429 {$sCatView}.oxid = oxobject2category.oxcatnid
03430 where oxobject2category.oxobjectid=".oxDb::getDb()->quote($sOXID)." and {$sCatView}.oxid is not null ";
03431 } else {
03432 $sSelect = "select {$sCatView}.* from {$sCatView} where
03433 '{$this->oxarticles__oxprice->value}' >= {$sCatView}.oxpricefrom and
03434 '{$this->oxarticles__oxprice->value}' <= {$sCatView}.oxpriceto ";
03435 }
03436 return $sSelect;
03437 }
03438
03444 protected function _generateSearchStrForCustomerBought()
03445 {
03446 $sArtTable = $this->getViewName();
03447 $sOrderArtTable = getViewName( 'oxorderarticles' );
03448
03449
03450 $sIn = " '{$this->oxarticles__oxid->value}' ";
03451 if ( $this->oxarticles__oxparentid->value ) {
03452
03453
03454 $sIn .= ", '{$this->oxarticles__oxparentid->value}' ";
03455 $sParentIdForVariants = $this->oxarticles__oxparentid->value;
03456
03457 } else {
03458 $sParentIdForVariants = $this->getId();
03459 }
03460
03461
03462 $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
03463 $oRs = $oDb->select( "select oxid from {$sArtTable} where oxparentid = ".$oDb->quote($sParentIdForVariants)." and oxid != ".$oDb->quote($this->oxarticles__oxid->value) );
03464 if ( $oRs != false && $oRs->recordCount() > 0) {
03465 while ( !$oRs->EOF ) {
03466 $sIn .= ", ".$oDb->quote(current( $oRs->fields ))." ";
03467 $oRs->moveNext();
03468 }
03469 }
03470
03471 $iLimit = (int) $this->getConfig()->getConfigParam( 'iNrofCustomerWhoArticles' );
03472 $iLimit = $iLimit?( $iLimit * 10 ): 50;
03473
03474
03475 $sQ = "select distinct {$sArtTable}.* from (
03476 select d.oxorderid as suborderid from {$sOrderArtTable} as d use index ( oxartid ) where d.oxartid in ( {$sIn} ) limit {$iLimit}
03477 ) as suborder
03478 left join {$sOrderArtTable} force index ( oxorderid ) on suborder.suborderid = {$sOrderArtTable}.oxorderid
03479 left join {$sArtTable} on {$sArtTable}.oxid = {$sOrderArtTable}.oxartid
03480 where {$sArtTable}.oxid not in ( {$sIn} )
03481 and ( {$sArtTable}.oxissearch = 1 or {$sArtTable}.oxparentid <> '' ) and ".$this->getSqlActiveSnippet();
03482
03483
03484
03485
03486
03487
03488
03489
03490
03491
03492 return $sQ;
03493 }
03494
03504 protected function _generateSelectCatStr($sOXID, $sCatId, $dPriceFromTo = false)
03505 {
03506 $sCategoryView = getViewName('oxcategories');
03507 $sO2CView = getViewName('oxobject2category');
03508
03509 $oDb = oxDb::getDb();
03510 $sOXID = $oDb->quote($sOXID);
03511 $sCatId = $oDb->quote($sCatId);
03512
03513 if (!$dPriceFromTo) {
03514 $sSelect = "select oxobject2category.oxcatnid from $sO2CView as oxobject2category ";
03515 $sSelect .= "left join $sCategoryView as oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
03516 $sSelect .= "where oxobject2category.oxcatnid=$sCatId and oxobject2category.oxobjectid=$sOXID ";
03517 $sSelect .= "and oxcategories.oxactive = 1 order by oxobject2category.oxtime ";
03518 } else {
03519 $dPriceFromTo = $oDb->quote($dPriceFromTo);
03520 $sSelect = "select oxcategories.oxid from $sCategoryView as oxcategories where ";
03521 $sSelect .= "oxcategories.oxid=$sCatId and $dPriceFromTo >= oxcategories.oxpricefrom and ";
03522 $sSelect .= "$dPriceFromTo <= oxcategories.oxpriceto ";
03523 }
03524 return $sSelect;
03525 }
03526
03532 protected function _getAmountPriceList()
03533 {
03534 if ( $this->_oAmountPriceList === null ) {
03535 $this->_oAmountPriceList = array();
03536 if ( !$this->skipDiscounts() ) {
03537
03538
03539 $oAmPriceList = oxNew( 'oxAmountPricelist' );
03540 $oAmPriceList->load( $this );
03541
03542
03543 $oBasePrice = $this->_getGroupPrice();
03544 foreach ( $oAmPriceList as $oAmPrice ) {
03545 if ( $oAmPrice->oxprice2article__oxaddperc->value ) {
03546 $oAmPrice->oxprice2article__oxaddabs = new oxField(oxPrice::percent( $oBasePrice, 100 - $oAmPrice->oxprice2article__oxaddperc->value ), oxField::T_RAW );
03547 }
03548 }
03549
03550 $this->_oAmountPriceList = $oAmPriceList;
03551 }
03552 }
03553
03554 return $this->_oAmountPriceList;
03555 }
03556
03564 protected function _isFieldEmpty( $sFieldName )
03565 {
03566 $mValue = $this->$sFieldName->value;
03567
03568 if ( is_null( $mValue ) ) {
03569 return true;
03570 }
03571
03572 if ( $mValue === '' ) {
03573 return true;
03574 }
03575
03576
03577 $aZeroValueFields = array('oxarticles__oxprice', 'oxarticles__oxvat', 'oxarticles__oxunitquantity');
03578
03579 if (!$mValue && in_array( $sFieldName, $aZeroValueFields ) ) {
03580 return true;
03581 }
03582
03583
03584 if (!strcmp($mValue, '0000-00-00 00:00:00') || !strcmp($mValue, '0000-00-00')) {
03585 return true;
03586 }
03587
03588 $sFieldName = strtolower($sFieldName);
03589
03590 if ( $sFieldName == 'oxarticles__oxicon' && ( strpos($mValue, "nopic_ico.jpg") !== false || strpos($mValue, "nopic.jpg") !== false ) ) {
03591 return true;
03592 }
03593
03594 if ( strpos($mValue, "nopic.jpg") !== false && ($sFieldName == 'oxarticles__oxthumb' || substr($sFieldName, 0, 17) == 'oxarticles__oxpic' || substr($sFieldName, 0, 18) == 'oxarticles__oxzoom') ) {
03595 return true;
03596 }
03597
03598 return false;
03599 }
03600
03608 protected function _assignParentFieldValue($sFieldName)
03609 {
03610 if (!($oParentArticle = $this->getParentArticle())) {
03611 return;
03612 }
03613
03614 $sCopyFieldName = $this->_getFieldLongName($sFieldName);
03615
03616
03617 if ( $oParentArticle->$sCopyFieldName != null ) {
03618
03619
03620 if ( substr( $sCopyFieldName, 0, 12) != 'oxarticles__') {
03621 return;
03622 }
03623
03624
03625 if (in_array($sCopyFieldName, $this->_aNonCopyParentFields)) {
03626 return;
03627 }
03628
03629
03630
03631 if ( stristr($sCopyFieldName, '_oxthumb') || stristr($sCopyFieldName, '_oxicon') ) {
03632 if ( $this->_isFieldEmpty( $sCopyFieldName ) && !$this->_hasMasterImage( 1 ) ) {
03633 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03634 }
03635 } elseif ( stristr($sCopyFieldName, '_oxzoom') ) {
03636
03637
03638 $iIndex = (int) str_ireplace( "oxarticles__oxzoom", "", $sFieldName );
03639 if ( $this->_isFieldEmpty( $sCopyFieldName ) && !$this->_hasMasterImage( $iIndex ) && !$this->_hasMasterImage( 1 ) ) {
03640 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03641 }
03642 } elseif ( stristr($sCopyFieldName, '_oxpicsgenerated') && $this->{$sCopyFieldName}->value == 0 ) {
03643
03644 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03645 } elseif ($this->_isFieldEmpty($sCopyFieldName) || in_array( $sCopyFieldName, $this->_aCopyParentField ) ) {
03646 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03647 }
03648 }
03649 }
03650
03656 public function getParentArticle()
03657 {
03658 if ( ( $sParentId = $this->oxarticles__oxparentid->value ) ) {
03659 $sIndex = $sParentId . "_" . $this->getLanguage();
03660 if ( !isset( self::$_aLoadedParents[$sIndex] ) ) {
03661 self::$_aLoadedParents[$sIndex] = oxNew( 'oxarticle' );
03662 self::$_aLoadedParents[$sIndex]->_blLoadPrice = false;
03663 self::$_aLoadedParents[$sIndex]->_blLoadVariants = false;
03664 self::$_aLoadedParents[$sIndex]->loadInLang( $this->getLanguage(), $sParentId );
03665 }
03666 return self::$_aLoadedParents[$sIndex];
03667 }
03668 }
03669
03675 protected function _assignParentFieldValues()
03676 {
03677 startProfile('articleAssignParentInternal');
03678 if ( $this->oxarticles__oxparentid->value ) {
03679
03680 if ( !$this->isAdmin() || ( $this->_blLoadParentData && $this->isAdmin() ) ) {
03681 foreach ( $this->_aFieldNames as $sFieldName => $sVal ) {
03682 $this->_assignParentFieldValue( $sFieldName );
03683 }
03684 }
03685 }
03686 stopProfile('articleAssignParentInternal');
03687 }
03688
03694 protected function _assignNotBuyableParent()
03695 {
03696 if ( !$this->getConfig()->getConfigParam( 'blVariantParentBuyable' ) &&
03697 ($this->_blHasVariants || $this->oxarticles__oxvarstock->value || $this->oxarticles__oxvarcount->value )) {
03698 $this->_blNotBuyableParent = true;
03699
03700 }
03701 }
03702
03708 protected function _assignStock()
03709 {
03710 $myConfig = $this->getConfig();
03711
03712
03713
03714
03715
03716 if (!$myConfig->getConfigParam( 'blAllowUnevenAmounts' ) && !$this->isAdmin() ) {
03717 $this->oxarticles__oxstock = new oxField((int) floor($this->oxarticles__oxstock->value));
03718 }
03719
03720 $this->_iStockStatus = 0;
03721
03722
03723 if ( $myConfig->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstockflag->value != 4) {
03724
03725 $iStock = $this->oxarticles__oxstock->value;
03726
03727 if ($this->_blNotBuyableParent) {
03728 $iStock = $this->oxarticles__oxvarstock->value;
03729 }
03730
03731
03732 if ( $iStock <= $myConfig->getConfigParam( 'sStockWarningLimit' ) && $iStock > 0) {
03733 $this->_iStockStatus = 1;
03734 }
03735
03736
03737 if ($iStock <= 0) {
03738 $this->_iStockStatus = -1;
03739 }
03740 }
03741
03742
03743
03744 if ( $myConfig->getConfigParam( 'blUseStock' ) && ($this->oxarticles__oxstockflag->value == 3 || $this->oxarticles__oxstockflag->value == 2)) {
03745 $iOnStock = $this->oxarticles__oxstock->value;
03746 if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
03747 $iOnStock += $this->getSession()->getBasketReservations()->getReservedAmount($this->getId());
03748 }
03749 if ($iOnStock <= 0) {
03750 $this->setBuyableState( false );
03751 }
03752 }
03753
03754
03755 if ($this->_blNotBuyable && $this->oxarticles__oxvarstock->value ) {
03756 $this->setBuyableState( true );
03757
03758 $this->_blNotBuyableParent = true;
03759 }
03760
03761
03762
03763
03764 if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && !$myConfig->getConfigParam( 'blLoadVariants' ) && $this->oxarticles__oxvarstock->value) {
03765 $this->setBuyableState( false );
03766 }
03767
03768
03769 if (!$this->_blNotBuyable && $this->_blNotBuyableParent && $this->oxarticles__oxvarcount->value == 0) {
03770 $this->setBuyableState( false );
03771 }
03772 }
03773
03781 protected function _assignPrices()
03782 {
03783 $myConfig = $this->getConfig();
03784
03785
03786 if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
03787 return;
03788 }
03789
03790
03791 if ( $this->_hasAnyVariant() ) {
03792 $this->_applyRangePrice();
03793 }
03794 }
03795
03801 protected function _assignPersistentParam()
03802 {
03803
03804 $aPersParam = oxSession::getVar( 'persparam');
03805 if ( isset( $aPersParam) && isset( $aPersParam[$this->getId()])) {
03806 $this->_aPersistParam = $aPersParam[$this->getId()];
03807 }
03808 }
03809
03815 protected function _assignDynImageDir()
03816 {
03817 $myConfig = $this->getConfig();
03818
03819 $sThisShop = $this->oxarticles__oxshopid->value;
03820
03821 $this->_sDynImageDir = $myConfig->getPictureUrl( null, false );
03822 $this->dabsimagedir = $myConfig->getPictureDir( false );
03823 $this->nossl_dimagedir = $myConfig->getPictureUrl( null, false, false, null, $sThisShop );
03824 $this->ssl_dimagedir = $myConfig->getPictureUrl( null, false, true, null, $sThisShop );
03825 }
03826
03832 protected function _assignComparisonListFlag()
03833 {
03834
03835
03836 $aItems = oxSession::getVar('aFiltcompproducts');
03837 if ( isset( $aItems[$this->getId()])) {
03838 $this->_blIsOnComparisonList = true;
03839 }
03840 }
03841
03842
03850 protected function _insert()
03851 {
03852
03853 $sNow = date('Y-m-d H:i:s', oxRegistry::get("oxUtilsDate")->getTime());
03854 $this->oxarticles__oxinsert = new oxField( $sNow );
03855 if ( !is_object($this->oxarticles__oxsubclass) || $this->oxarticles__oxsubclass->value == '') {
03856 $this->oxarticles__oxsubclass = new oxField('oxarticle');
03857 }
03858
03859 return parent::_insert();
03860 }
03861
03867 protected function _update()
03868 {
03869
03870 $this->_skipSaveFields();
03871
03872 $myConfig = $this->getConfig();
03873
03874
03875 $blRes = parent::_update();
03876
03877
03878 return $blRes;
03879 }
03880
03886 public function updateVariantsRemind()
03887 {
03888
03889 if ( !$this->isVariant() && $this->_hasAnyVariant()) {
03890 $oDb = oxDb::getDb();
03891 $sOxId = $oDb->quote($this->getId());
03892 $sOxShopId = $oDb->quote($this->getShopId());
03893 $iRemindActive = $oDb->quote($this->oxarticles__oxremindactive->value);
03894 $sUpdate = "
03895 update oxarticles
03896 set oxremindactive = $iRemindActive
03897 where oxparentid = $sOxId and
03898 oxshopid = $sOxShopId
03899 ";
03900 $oDb->execute( $sUpdate );
03901 }
03902 }
03903
03911 protected function _deleteRecords($sOXID)
03912 {
03913 $oDb = oxDb::getDb();
03914
03915 $sOXID = $oDb->quote($sOXID);
03916
03917
03918 $sDelete = 'delete from oxobject2article where oxarticlenid = '.$sOXID.' or oxobjectid = '.$sOXID.' ';
03919 $oDb->execute( $sDelete);
03920
03921 $sDelete = 'delete from oxobject2attribute where oxobjectid = '.$sOXID.' ';
03922 $oDb->execute( $sDelete);
03923
03924 $sDelete = 'delete from oxobject2category where oxobjectid = '.$sOXID.' ';
03925 $oDb->execute( $sDelete);
03926
03927 $sDelete = 'delete from oxobject2selectlist where oxobjectid = '.$sOXID.' ';
03928 $oDb->execute( $sDelete);
03929
03930 $sDelete = 'delete from oxprice2article where oxartid = '.$sOXID.' ';
03931 $oDb->execute( $sDelete);
03932
03933 $sDelete = 'delete from oxreviews where oxtype="oxarticle" and oxobjectid = '.$sOXID.' ';
03934 $oDb->execute( $sDelete);
03935
03936 $sDelete = 'delete from oxratings where oxobjectid = '.$sOXID.' ';
03937 $rs = $oDb->execute( $sDelete );
03938
03939 $sDelete = 'delete from oxaccessoire2article where oxobjectid = '.$sOXID.' or oxarticlenid = '.$sOXID.' ';
03940 $oDb->execute( $sDelete);
03941
03942
03943 $sDelete = 'delete from oxobject2delivery where oxobjectid = '.$sOXID.' and oxtype=\'oxarticles\' ';
03944 $oDb->execute( $sDelete);
03945
03946 $sDelete = 'delete from oxartextends where oxid = '.$sOXID.' ';
03947 $oDb->execute( $sDelete);
03948
03949
03950 foreach ( $this->_getLanguageSetTables( "oxartextends" ) as $sSetTbl ) {
03951 $oDb->execute( "delete from $sSetTbl where oxid = {$sOXID}" );
03952 }
03953
03954 $sDelete = 'delete from oxactions2article where oxartid = '.$sOXID.' ';
03955 $rs = $oDb->execute( $sDelete );
03956
03957 $sDelete = 'delete from oxobject2list where oxobjectid = '.$sOXID.' ';
03958 $rs = $oDb->execute( $sDelete );
03959
03960
03961 return $rs;
03962 }
03963
03971 protected function _deleteVariantRecords( $sOXID )
03972 {
03973 if ( $sOXID ) {
03974 $oDb = oxDb::getDb();
03975
03976 $sQ = 'select oxid from '.$this->getViewName().' where oxparentid = '.$oDb->quote( $sOXID );
03977 $rs = $oDb->select( $sQ, false, false );
03978 $oArticle = oxNew("oxArticle");
03979 if ($rs != false && $rs->recordCount() > 0) {
03980 while (!$rs->EOF) {
03981 $oArticle->setId($rs->fields[0]);
03982 $oArticle->delete();
03983 $rs->moveNext();
03984 }
03985 }
03986 }
03987 }
03988
03994 protected function _deletePics()
03995 {
03996 $myUtilsPic = oxRegistry::get("oxUtilsPic");
03997 $myConfig = $this->getConfig();
03998 $oPictureHandler = oxRegistry::get("oxPictureHandler");
03999
04000
04001 $oPictureHandler->deleteMainIcon( $this );
04002
04003
04004 $oPictureHandler->deleteThumbnail( $this );
04005
04006 $sAbsDynImageDir = $myConfig->getPictureDir(false);
04007
04008
04009 $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
04010 for ( $i = 1; $i <= $iPicCount; $i++ ) {
04011 $oPictureHandler->deleteArticleMasterPicture( $this, $i );
04012 }
04013 }
04014
04024 protected function _onChangeResetCounts( $sOxid, $sVendorId = null, $sManufacturerId = null )
04025 {
04026
04027 $myUtilsCount = oxRegistry::get("oxUtilsCount");
04028
04029 if ( $sVendorId ) {
04030 $myUtilsCount->resetVendorArticleCount( $sVendorId );
04031 }
04032
04033 if ( $sManufacturerId ) {
04034 $myUtilsCount->resetManufacturerArticleCount( $sManufacturerId );
04035 }
04036
04037
04038 $oDb = oxDb::getDb();
04039 $sQ = "select oxcatnid from oxobject2category where oxobjectid = ".$oDb->quote($sOxid);
04040 $oRs = $oDb->select( $sQ, false, false );
04041 if ( $oRs !== false && $oRs->recordCount() > 0) {
04042 while ( !$oRs->EOF ) {
04043 $myUtilsCount->resetCatArticleCount( $oRs->fields[0] );
04044 $oRs->moveNext();
04045 }
04046 }
04047 }
04048
04056 protected function _onChangeUpdateStock( $sParentID )
04057 {
04058 if ( $sParentID ) {
04059 $oDb = oxDb::getDb();
04060 $sParentIdQuoted = $oDb->quote($sParentID);
04061 $sQ = 'select oxstock, oxvendorid, oxmanufacturerid from oxarticles where oxid = '.$sParentIdQuoted;
04062 $rs = $oDb->select( $sQ, false, false );
04063 $iOldStock = $rs->fields[0];
04064 $iVendorID = $rs->fields[1];
04065 $iManufacturerID = $rs->fields[2];
04066
04067 $sQ = 'select sum(oxstock) from '.$this->getViewName(true).' where oxparentid = '.$sParentIdQuoted.' and '. $this->getSqlActiveSnippet( true ).' and oxstock > 0 ';
04068 $iStock = (float) $oDb->getOne( $sQ, false, false );
04069
04070 $sQ = 'update oxarticles set oxvarstock = '.$iStock.' where oxid = '.$sParentIdQuoted;
04071 $oDb->execute( $sQ );
04072
04073
04074
04075 if ( $iStock < 0 ) {
04076 $iStock = 0;
04077 }
04078 if ( $iOldStock < 0 ) {
04079 $iOldStock = 0;
04080 }
04081 if ( $this->oxarticles__oxstockflag->value == 2 && $iOldStock xor $iStock ) {
04082
04083
04084 $this->_onChangeResetCounts( $sParentID, $iVendorID, $iManufacturerID );
04085 }
04086 }
04087 }
04088
04096 protected function _onChangeStockResetCount( $sOxid )
04097 {
04098 $myConfig = $this->getConfig();
04099
04100 if ( $myConfig->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstockflag->value == 2 &&
04101 ( $this->oxarticles__oxstock->value + $this->oxarticles__oxvarstock->value ) <= 0 ) {
04102
04103 $this->_onChangeResetCounts( $sOxid, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
04104 }
04105 }
04106
04114 protected function _onChangeUpdateVarCount( $sParentID )
04115 {
04116 if ( $sParentID ) {
04117 $oDb = oxDb::getDb();
04118 $sParentIdQuoted = $oDb->quote( $sParentID );
04119 $sQ = "select count(*) as varcount from oxarticles where oxparentid = {$sParentIdQuoted}";
04120 $iVarCount = (int) $oDb->getOne( $sQ, false, false );
04121
04122 $sQ = "update oxarticles set oxvarcount = {$iVarCount} where oxid = {$sParentIdQuoted}";
04123 $oDb->execute( $sQ );
04124 }
04125 }
04126
04134 protected function _setVarMinMaxPrice( $sParentId )
04135 {
04136 if ( $sParentId ) {
04137 $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
04138 $sQ = '
04139 SELECT
04140 MIN( IF( `oxarticles`.`oxprice` > 0, `oxarticles`.`oxprice`, `p`.`oxprice` ) ) AS `varminprice`,
04141 MAX( IF( `oxarticles`.`oxprice` > 0, `oxarticles`.`oxprice`, `p`.`oxprice` ) ) AS `varmaxprice`
04142 FROM '. $this->getViewName(true) . ' AS `oxarticles`
04143 LEFT JOIN '. $this->getViewName(true) . ' AS `p` ON ( `p`.`oxid` = `oxarticles`.`oxparentid` AND `p`.`oxprice` > 0 )
04144 WHERE '. $this->getSqlActiveSnippet(true) .'
04145 AND ( `oxarticles`.`oxparentid` = '. $oDb->quote( $sParentId ) .' )';
04146 $oDb->setFetchMode( oxDb::FETCH_MODE_ASSOC );
04147 $aPrices = $oDb->getRow( $sQ, false, false );
04148 if ( !is_null( $aPrices['varminprice'] ) || !is_null( $aPrices['varmaxprice'] ) ) {
04149 $sQ = '
04150 UPDATE `oxarticles`
04151 SET
04152 `oxvarminprice` = '. $oDb->quote( $aPrices['varminprice'] ) .',
04153 `oxvarmaxprice` = '. $oDb->quote( $aPrices['varmaxprice'] ) .'
04154 WHERE
04155 `oxid` = ' . $oDb->quote( $sParentId );
04156 } else {
04157 $sQ = '
04158 UPDATE `oxarticles`
04159 SET
04160 `oxvarminprice` = `oxprice`,
04161 `oxvarmaxprice` = `oxprice`
04162 WHERE
04163 `oxid` = ' . $oDb->quote( $sParentId );
04164 }
04165 $oDb->execute( $sQ );
04166 }
04167 }
04168
04169
04179 protected function _onChangeUpdateMinVarPrice( $sParentID )
04180 {
04181 if ( $sParentID ) {
04182 $oDb = oxDb::getDb();
04183 $sParentIdQuoted = $oDb->quote($sParentID);
04184
04185 $sQ = 'select min(oxprice) as varminprice from '.$this->getViewName(true).' where '.$this->getSqlActiveSnippet(true).' and (oxparentid = '.$sParentIdQuoted.')';
04186 $dVarMinPrice = $oDb->getOne( $sQ, false, false );
04187
04188 $dParentPrice = $oDb->getOne( "select oxprice from oxarticles where oxid = $sParentIdQuoted ", false, false );
04189
04190 $blParentBuyable = $this->getConfig()->getConfigParam( 'blVariantParentBuyable' );
04191
04192 if ($dVarMinPrice) {
04193 if ($blParentBuyable) {
04194 $dVarMinPrice = min($dVarMinPrice, $dParentPrice);
04195 }
04196 } else {
04197 $dVarMinPrice = $dParentPrice;
04198 }
04199
04200 if ( $dVarMinPrice ) {
04201 $sQ = 'update oxarticles set oxvarminprice = '.$dVarMinPrice.' where oxid = '.$sParentIdQuoted;
04202 $oDb->execute($sQ);
04203 }
04204 }
04205 }
04206
04207
04215 protected function _applyRangePrice()
04216 {
04217
04218 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
04219 return;
04220 }
04221
04222 $this->_blIsRangePrice = false;
04223
04224
04225 if ($this->_blSkipFromPrice || !$this->_blNotBuyableParent) {
04226 return;
04227 }
04228
04229 if ( $this->isParentNotBuyable() && !$this->getConfig()->getConfigParam( 'blLoadVariants' )) {
04230
04231 $dPrice = $this->_preparePrice( $this->oxarticles__oxvarminprice->value, $this->getArticleVat() );
04232 $this->getPrice()->setPrice($dPrice);
04233 $this->_blIsRangePrice = true;
04234 $this->_calculatePrice( $this->getPrice() );
04235 return;
04236
04237 }
04238
04239 $aPrices = array();
04240
04241 if (!$this->_blNotBuyableParent) {
04242 $aPrices[] = $this->getPrice()->getPrice();
04243 }
04244
04245 $aVariants = $this->getVariants(false);
04246
04247 if (count($aVariants)) {
04248 foreach ($aVariants as $sKey => $oVariant) {
04249 $aPrices[] = $oVariant->getPrice()->getPrice();
04250 }
04251 }
04252
04253 if ( count( $aPrices ) ) {
04254 $dMinPrice = min( $aPrices );
04255 $dMaxPrice = max( $aPrices );
04256 }
04257
04258 if ($this->_blNotBuyableParent && isset($dMinPrice) && $dMinPrice == $dMaxPrice) {
04259 $this->getPrice()->setPrice($dMinPrice);
04260 }
04261
04262 if (isset($dMinPrice) && $dMinPrice != $dMaxPrice) {
04263 $this->getPrice()->setPrice($dMinPrice);
04264 $this->_blIsRangePrice = true;
04265 }
04266 }
04267
04274 public function getProductId()
04275 {
04276 return $this->getId();
04277 }
04278
04286 public function getProductParentId()
04287 {
04288 return $this->getParentId();
04289 }
04290
04296 public function getParentId()
04297 {
04298 return $this->oxarticles__oxparentid->value;
04299 }
04300
04306 public function isOrderArticle()
04307 {
04308 return false;
04309 }
04310
04316 public function isVariant()
04317 {
04318 return (bool) ( isset( $this->oxarticles__oxparentid ) ? $this->oxarticles__oxparentid->value : false );
04319 }
04320
04326 public function isMdVariant()
04327 {
04328 $oMdVariant = oxNew( "oxVariantHandler" );
04329
04330 return $oMdVariant->isMdVariant($this);
04331 }
04332
04340 public function getSqlForPriceCategories($sFields = '')
04341 {
04342 if (!$sFields) {
04343 $sFields = 'oxid';
04344 }
04345 $sSelectWhere = "select $sFields from ".$this->_getObjectViewName('oxcategories')." where";
04346 $sQuotedPrice = oxDb::getDb()->quote( $this->oxarticles__oxprice->value );
04347 return "$sSelectWhere oxpricefrom != 0 and oxpriceto != 0 and oxpricefrom <= $sQuotedPrice and oxpriceto >= $sQuotedPrice"
04348 ." union $sSelectWhere oxpricefrom != 0 and oxpriceto = 0 and oxpricefrom <= $sQuotedPrice"
04349 ." union $sSelectWhere oxpricefrom = 0 and oxpriceto != 0 and oxpriceto >= $sQuotedPrice";
04350 }
04351
04359 public function inPriceCategory( $sCatNid )
04360 {
04361 $oDb = oxDb::getDb();
04362
04363 $sQuotedPrice = $oDb->quote( $this->oxarticles__oxprice->value );
04364 $sQuotedCnid = $oDb->quote( $sCatNid );
04365 return (bool) $oDb->getOne(
04366 "select 1 from ".$this->_getObjectViewName('oxcategories')." where oxid=$sQuotedCnid and"
04367 ."( (oxpricefrom != 0 and oxpriceto != 0 and oxpricefrom <= $sQuotedPrice and oxpriceto >= $sQuotedPrice)"
04368 ." or (oxpricefrom != 0 and oxpriceto = 0 and oxpricefrom <= $sQuotedPrice)"
04369 ." or (oxpricefrom = 0 and oxpriceto != 0 and oxpriceto >= $sQuotedPrice)"
04370 .")"
04371 );
04372 }
04373
04379 public function getMdVariants()
04380 {
04381 if ( $this->_oMdVariants ) {
04382 return $this->_oMdVariants;
04383 }
04384
04385 $oParentArticle = $this->getParentArticle();
04386 if ( $oParentArticle ) {
04387 $oVariants = $oParentArticle->getVariants();
04388 } else {
04389 $oVariants = $this->getVariants();
04390 }
04391
04392 $oVariantHandler = oxNew( "oxVariantHandler" );
04393 $this->_oMdVariants = $oVariantHandler->buildMdVariants( $oVariants, $this->getId() );
04394
04395 return $this->_oMdVariants;
04396 }
04397
04403 public function getMdSubvariants()
04404 {
04405 return $this->getMdVariants()->getMdSubvariants();
04406 }
04407
04415 protected function _hasMasterImage( $iIndex )
04416 {
04417 $sPicName = basename($this->{"oxarticles__oxpic" . $iIndex}->value);
04418
04419 if ( $sPicName == "nopic.jpg" || $sPicName == "" ) {
04420 return false;
04421 }
04422 if ( $this->isVariant() && $this->getParentArticle()->{"oxarticles__oxpic".$iIndex}->value == $this->{"oxarticles__oxpic".$iIndex}->value ) {
04423 return false;
04424 }
04425
04426 $sMasterPic = 'product/'.$iIndex . "/" . $sPicName;
04427
04428 if ( $this->getConfig()->getMasterPicturePath( $sMasterPic ) ) {
04429 return true;
04430 }
04431
04432 return false;
04433 }
04434
04443 public function getPictureFieldValue( $sFieldName, $iIndex = null )
04444 {
04445 if ( $sFieldName ) {
04446 $sFieldName = "oxarticles__" . $sFieldName . $iIndex;
04447 return $this->$sFieldName->value;
04448 }
04449 }
04450
04458 public function getMasterZoomPictureUrl( $iIndex )
04459 {
04460 $sPicUrl = false;
04461 $sPicName = basename( $this->{"oxarticles__oxpic" . $iIndex}->value );
04462
04463 if ( $sPicName && $sPicName != "nopic.jpg" ) {
04464 $sPicUrl = $this->getConfig()->getPictureUrl( "master/product/" . $iIndex . "/" . $sPicName );
04465 if ( !$sPicUrl || basename( $sPicUrl ) == "nopic.jpg" ) {
04466 $sPicUrl = false;
04467 }
04468 }
04469
04470 return $sPicUrl;
04471 }
04472
04478 public function getUnitName()
04479 {
04480 if ( $this->oxarticles__oxunitname->value ) {
04481 return oxRegistry::getLang()->translateString( $this->oxarticles__oxunitname->value );
04482 }
04483 }
04484
04492 public function getArticleFiles( $blAddFromParent=false )
04493 {
04494 if ( $this->_aArticleFiles === null) {
04495
04496 $this->_aArticleFiles = false;
04497
04498 $sQ = "SELECT * FROM `oxfiles` WHERE `oxartid` = '".$this->getId()."'";
04499
04500 if ( !$this->getConfig()->getConfigParam( 'blVariantParentBuyable' ) && $blAddFromParent ) {
04501 $sQ .= " OR `oxartId` = '". $this->oxarticles__oxparentid->value . "'";
04502 }
04503
04504 $oArticleFiles = oxNew("oxlist");
04505 $oArticleFiles->init("oxfile");
04506 $oArticleFiles->selectString( $sQ );
04507 $this->_aArticleFiles = $oArticleFiles;
04508
04509 }
04510
04511 return $this->_aArticleFiles;
04512 }
04513
04519 public function isDownloadable()
04520 {
04521 return $this->oxarticles__oxisdownloadable->value;
04522 }
04523
04529 public function hasAmountPrice()
04530 {
04531 if ( self::$_blHasAmountPrice === null ) {
04532
04533 self::$_blHasAmountPrice = false;
04534
04535 $oDb = oxDb::getDb();
04536 $sQ = "SELECT 1 FROM `oxprice2article` LIMIT 1";
04537
04538 if ( $oDb->getOne( $sQ ) ) {
04539 self::$_blHasAmountPrice = true;
04540 }
04541 }
04542
04543 return self::$_blHasAmountPrice;
04544 }
04545
04546
04552 protected function _isPriceViewModeNetto()
04553 {
04554 $blResult = (bool) $this->getConfig()->getConfigParam('blShowNetPrice');
04555 $oUser = $this->getArticleUser();
04556 if ( $oUser ) {
04557 $blResult = $oUser->isPriceViewModeNetto();
04558 }
04559
04560 return $blResult;
04561 }
04562
04563
04571 protected function _getPriceObject( $blCalculationModeNetto = null )
04572 {
04573 $oPrice = oxNew( 'oxPrice' );
04574
04575 if ( $blCalculationModeNetto === null ) {
04576 $blCalculationModeNetto = $this->_isPriceViewModeNetto();
04577 }
04578
04579 if ( $blCalculationModeNetto ) {
04580 $oPrice->setNettoPriceMode();
04581 } else {
04582 $oPrice->setBruttoPriceMode();
04583 }
04584
04585 return $oPrice;
04586 }
04587
04588
04596 protected function _getPriceForView( $oPrice )
04597 {
04598 if ( $this->_isPriceViewModeNetto() ) {
04599 $dPrice = $oPrice->getNettoPrice();
04600 } else {
04601 $dPrice = $oPrice->getBruttoPrice();
04602 }
04603
04604 return $dPrice;
04605 }
04606
04607
04617 protected function _preparePrice( $dPrice, $dVat, $blCalculationModeNetto = null )
04618 {
04619 if ( $blCalculationModeNetto === null ) {
04620 $blCalculationModeNetto = $this->_isPriceViewModeNetto();
04621 }
04622
04623 $blEnterNetPrice = $this->getConfig()->getConfigParam('blEnterNetPrice');
04624 if ( $blCalculationModeNetto && !$blEnterNetPrice ) {
04625 $dPrice = round( oxPrice::brutto2Netto( $dPrice, $dVat ), 2 );
04626 } elseif ( !$blCalculationModeNetto && $blEnterNetPrice ) {
04627 $dPrice = round( oxPrice::netto2Brutto( $dPrice, $dVat ), 2 );
04628 }
04629
04630 return $dPrice;
04631 }
04632
04633
04639 public function getFUnitPrice()
04640 {
04641 if ($this->_fPricePerUnit == null) {
04642 if ( $oPrice = $this->getUnitPrice() ) {
04643 if ( $dPrice = $this->_getPriceForView( $oPrice ) ) {
04644 $this->_fPricePerUnit = oxRegistry::getLang()->formatCurrency( $dPrice );
04645 }
04646 }
04647 }
04648
04649 return $this->_fPricePerUnit;
04650 }
04651
04652
04658 public function getUnitPrice()
04659 {
04660
04661 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
04662 return;
04663 }
04664
04665 $oPrice = null;
04666 if ( (double) $this->oxarticles__oxunitquantity->value && $this->oxarticles__oxunitname->value ) {
04667 $oPrice = clone $this->getPrice();
04668 $oPrice->divide( (double) $this->oxarticles__oxunitquantity->value );
04669 }
04670
04671 return $oPrice;
04672 }
04673
04674
04680 public function getFMinPrice()
04681 {
04682 $sPrice = '';
04683 if ( $oPrice = $this->getMinPrice() ) {
04684 $dPrice = $this->_getPriceForView( $oPrice );
04685 $sPrice = oxRegistry::getLang()->formatCurrency( $dPrice );
04686 }
04687
04688 return $sPrice;
04689 }
04690
04696 public function getFVarMinPrice()
04697 {
04698 $sPrice = '';
04699 if ( $oPrice = $this->getVarMinPrice() ) {
04700 $dPrice = $this->_getPriceForView( $oPrice );
04701 $sPrice = oxRegistry::getLang()->formatCurrency( $dPrice );
04702 }
04703
04704 return $sPrice;
04705 }
04706
04712 public function getVarMinPrice()
04713 {
04714 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
04715 return;
04716 }
04717
04718 $oPrice = null;
04719 $dPrice = $this->_getVarMinPrice();
04720
04721 $dPrice = $this->_preparePrice( $dPrice, $this->getArticleVat() );
04722
04723
04724 $oPrice = $this->_getPriceObject();
04725 $oPrice->setPrice( $dPrice );
04726 $this->_calculatePrice( $oPrice );
04727
04728
04729 return $oPrice;
04730 }
04731
04732
04738 public function getMinPrice()
04739 {
04740 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
04741 return;
04742 }
04743
04744 $oPrice = null;
04745 $dPrice = $this->_getPrice();
04746 if ( $this->_getVarMinPrice() !== null && $dPrice > $this->_getVarMinPrice() ) {
04747 $dPrice = $this->_getVarMinPrice();
04748 }
04749
04750 $dPrice = $this->_preparePrice( $dPrice, $this->getArticleVat() );
04751
04752
04753 $oPrice = $this->_getPriceObject();
04754 $oPrice->setPrice( $dPrice );
04755 $this->_calculatePrice( $oPrice );
04756
04757 return $oPrice;
04758 }
04759
04760
04766 public function isRangePrice()
04767 {
04768 if ( $this->_blIsRangePrice === null ) {
04769
04770 $this->setRangePrice( false );
04771
04772 if ( $this->_hasAnyVariant() ) {
04773 $dPrice = $this->_getPrice();
04774 $dMinPrice = $this->_getVarMinPrice();
04775 $dMaxPrice = $this->_getVarMaxPrice();
04776
04777 if ( $dMinPrice != $dMaxPrice ) {
04778 $this->setRangePrice();
04779 } elseif ( !$this->isParentNotBuyable() && $dMinPrice != $dPrice ) {
04780 $this->setRangePrice();
04781 }
04782 }
04783 }
04784
04785 return $this->_blIsRangePrice;
04786 }
04787
04788
04796 public function setRangePrice( $blIsRangePrice = true )
04797 {
04798 return $this->_blIsRangePrice = $blIsRangePrice;
04799 }
04800
04806 protected function _getUserPriceSufix()
04807 {
04808 $sPriceSufix = '';
04809 $oUser = $this->getArticleUser();
04810
04811 if ( $oUser ) {
04812 if ( $oUser->inGroup( 'oxidpricea' ) ) {
04813 $sPriceSufix = 'a';
04814 } elseif ( $oUser->inGroup( 'oxidpriceb' ) ) {
04815 $sPriceSufix = 'b';
04816 } elseif ( $oUser->inGroup( 'oxidpricec' ) ) {
04817 $sPriceSufix = 'c';
04818 }
04819 }
04820
04821 return $sPriceSufix;
04822 }
04823
04824
04830 protected function _getPrice()
04831 {
04832 $sPriceSufix = $this->_getUserPriceSufix();
04833 if ( $sPriceSufix === '') {
04834 $dPrice = $this->oxarticles__oxprice->value;
04835 } else {
04836 if ( $this->getConfig()->getConfigParam( 'blOverrideZeroABCPrices' ) ) {
04837 $dPrice = ($this->{oxarticles__oxprice.$sPriceSufix}->value !=0 )? $this->{oxarticles__oxprice.$sPriceSufix}->value : $this->oxarticles__oxprice->value;
04838 } else {
04839 $dPrice = $this->{oxarticles__oxprice.$sPriceSufix}->value;
04840 }
04841 }
04842 return $dPrice;
04843 }
04844
04845
04851 protected function _getVarMinPrice()
04852 {
04853 if ( $this->_dVarMinPrice === null) {
04854
04855 $sPriceSufix = $this->_getUserPriceSufix();
04856 if ( $dPrice === null ) {
04857 if ( $sPriceSufix === '' ) {
04858 $dPrice = $this->oxarticles__oxvarminprice->value;
04859 } else {
04860 $sSql = 'SELECT ';
04861 if ( $this->getConfig()->getConfigParam( 'blOverrideZeroABCPrices' ) ) {
04862 $sSql .= 'MIN( IF(`oxprice'.$sPriceSufix.'` = 0, `oxprice`, `oxprice'.$sPriceSufix.'`) ) AS `varminprice` ';
04863 } else {
04864 $sSql .= 'MIN(`oxprice'.$sPriceSufix.'`) AS `varminprice` ';
04865 }
04866
04867 $sSql .= ' FROM ' . $this->getViewName(true) . '
04868 WHERE ' .$this->getSqlActiveSnippet(true) . '
04869 AND ( `oxparentid` = ' . oxDb::getDb()->quote( $this->getId() ) . ' )';
04870
04871 $dPrice = oxDb::getDb()->getOne( $sSql );
04872 }
04873 }
04874 $this->_dVarMinPrice = $dPrice;
04875 }
04876
04877 return $this->_dVarMinPrice;
04878 }
04879
04885 protected function _getSubShopVarMinPrice()
04886 {
04887 $myConfig = $this->getConfig();
04888 $sShopId = $myConfig->getShopId();
04889 if ($this->getConfig()->getConfigParam( 'blMallCustomPrice' ) && $sShopId != $this->oxarticles__oxshopid->value ) {
04890 $sPriceSufix = $this->_getUserPriceSufix();
04891 $sSql = 'SELECT ';
04892 if ( $sPriceSufix != '' && $this->getConfig()->getConfigParam( 'blOverrideZeroABCPrices' ) ) {
04893 $sSql .= 'MIN(IF(`oxfield2shop`.`oxprice'.$sPriceSufix.'` = 0, `oxfield2shop`.`oxprice`, `oxfield2shop`.`oxprice'.$sPriceSufix.'`)) AS `varminprice` ';
04894 } else {
04895 $sSql .= 'MIN(`oxfield2shop`.`oxprice'.$sPriceSufix.'`) AS `varminprice` ';
04896 }
04897 $sSql .= ' FROM ' . getViewName('oxfield2shop') . ' AS oxfield2shop
04898 INNER JOIN ' . $this->getViewName(true) . ' AS oxarticles ON `oxfield2shop`.`oxartid` = `oxarticles`.`oxid`
04899 WHERE ' .$this->getSqlActiveSnippet(true) . '
04900 AND ( `oxarticles`.`oxparentid` = ' . oxDb::getDb()->quote( $this->getId() ) . ' )
04901 AND ( `oxfield2shop`.`oxshopid` = ' . oxDb::getDb()->quote( $sShopId ) . ' )';
04902 $dPrice = oxDb::getDb()->getOne( $sSql );
04903 }
04904 return $dPrice;
04905 }
04906
04912 protected function _getVarMaxPrice()
04913 {
04914 if ( $this->_dVarMaxPrice === null ) {
04915
04916 $sPriceSufix = $this->_getUserPriceSufix();
04917 if ( $dPrice === null ) {
04918 if ( $sPriceSufix === '') {
04919 $dPrice = $this->oxarticles__oxvarmaxprice->value;
04920 } else {
04921 $sSql = 'SELECT ';
04922 if ( $this->getConfig()->getConfigParam( 'blOverrideZeroABCPrices' ) ) {
04923 $sSql .= 'MAX( IF(`oxprice'.$sPriceSufix.'` = 0, `oxprice`, `oxprice'.$sPriceSufix.'`) ) AS `varmaxprice` ';
04924 } else {
04925 $sSql .= 'MAX(`oxprice'.$sPriceSufix.'`) AS `varmaxprice` ';
04926 }
04927
04928 $sSql .= ' FROM ' . $this->getViewName(true) . '
04929 WHERE ' .$this->getSqlActiveSnippet(true) . '
04930 AND ( `oxparentid` = ' . oxDb::getDb()->quote( $this->getId() ) . ' )';
04931
04932 $dPrice = oxDb::getDb()->getOne( $sSql );
04933 }
04934 }
04935 $this->_dVarMaxPrice = $dPrice;
04936 }
04937
04938 return $this->_dVarMaxPrice;
04939 }
04940
04946 protected function _getSubShopVarMaxPrice()
04947 {
04948 $myConfig = $this->getConfig();
04949 $sShopId = $myConfig->getShopId();
04950 if ($this->getConfig()->getConfigParam( 'blMallCustomPrice' ) && $sShopId != $this->oxarticles__oxshopid->value ) {
04951 $sPriceSufix = $this->_getUserPriceSufix();
04952 $sSql = 'SELECT ';
04953 if ( $sPriceSufix != '' && $this->getConfig()->getConfigParam( 'blOverrideZeroABCPrices' ) ) {
04954 $sSql .= 'MAX(IF(`oxfield2shop`.`oxprice'.$sPriceSufix.'` = 0, `oxfield2shop`.`oxprice`, `oxfield2shop`.`oxprice'.$sPriceSufix.'`)) AS `varmaxprice` ';
04955 } else {
04956 $sSql .= 'MAX(`oxfield2shop`.`oxprice'.$sPriceSufix.'`) AS `varmaxprice` ';
04957 }
04958 $sSql .= ' FROM ' . getViewName('oxfield2shop') . ' AS oxfield2shop
04959 INNER JOIN ' . $this->getViewName(true) . ' AS oxarticles ON `oxfield2shop`.`oxartid` = `oxarticles`.`oxid`
04960 WHERE ' .$this->getSqlActiveSnippet(true) . '
04961 AND ( `oxarticles`.`oxparentid` = ' . oxDb::getDb()->quote( $this->getId() ) . ' )
04962 AND ( `oxfield2shop`.`oxshopid` = ' . oxDb::getDb()->quote( $sShopId ) . ' )';
04963 $dPrice = oxDb::getDb()->getOne( $sSql );
04964 }
04965 return $dPrice;
04966 }
04967
04968 }