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 $dVat = 0;
01141 if ( $this->getPrice() != null ) {
01142 $dVat = $this->getPrice()->getVat();
01143 }
01144
01145 $iCnt = 0;
01146 self::$_aSelList[$sKey] = array();
01147 foreach ( $oLists as $oSelectlist ) {
01148 self::$_aSelList[$sKey][$iCnt] = $oSelectlist->getFieldList( $dVat );
01149 self::$_aSelList[$sKey][$iCnt]['name'] = $oSelectlist->oxselectlist__oxtitle->value;
01150 $iCnt++;
01151 }
01152 }
01153 return self::$_aSelList[$sKey];
01154 }
01155
01163 protected function _hasAnyVariant( $blForceCoreTable = null )
01164 {
01165 $blHas = false;
01166 if ( ( $sId = $this->getId() ) ) {
01167 if ( $this->oxarticles__oxshopid->value == $this->getConfig()->getShopId() ) {
01168 $blHas = (bool) $this->oxarticles__oxvarcount->value;
01169 } else {
01170 $sArticleTable = $this->getViewName( $blForceCoreTable );
01171 $blHas = (bool) oxDb::getDb()->getOne( "select 1 from $sArticleTable where oxparentid='{$sId}'" );
01172 }
01173 }
01174 return $blHas;
01175 }
01176
01182 public function hasMdVariants()
01183 {
01184 return $this->_blHasMdVariants;
01185 }
01186
01196 public function getVariantSelections( $aFilterIds = null, $sActVariantId = null, $iLimit = 0 )
01197 {
01198 $iLimit = (int) $iLimit;
01199 if ( !isset( $this->_aVariantSelections[$iLimit] ) ) {
01200 $aVariantSelections = false;
01201 if ( $this->oxarticles__oxvarcount->value ) {
01202 $oVariants = $this->getVariants( false );
01203 $aVariantSelections = oxNew( "oxVariantHandler" )->buildVariantSelections( $this->oxarticles__oxvarname->getRawValue(), $oVariants, $aFilterIds, $sActVariantId, $iLimit );
01204
01205 if ( !empty($oVariants) && empty( $aVariantSelections['rawselections'] ) ) {
01206 $aVariantSelections = false;
01207 }
01208 }
01209 $this->_aVariantSelections[$iLimit] = $aVariantSelections;
01210 }
01211
01212 return $this->_aVariantSelections[$iLimit];
01213 }
01214
01223 public function getSelections( $iLimit = null, $aFilter = null )
01224 {
01225 $sId = $this->getId() . ( (int) $iLimit );
01226 if ( !array_key_exists( $sId, self::$_aSelections ) ) {
01227
01228 $oDb = oxDb::getDb();
01229 $sSLViewName = getViewName( 'oxselectlist' );
01230
01231 $sQ = "select {$sSLViewName}.* from oxobject2selectlist join {$sSLViewName} on $sSLViewName.oxid=oxobject2selectlist.oxselnid
01232 where oxobject2selectlist.oxobjectid=%s order by oxobject2selectlist.oxsort";
01233
01234 if ( ( $iLimit = (int) $iLimit ) ) {
01235 $sQ .= " limit $iLimit ";
01236 }
01237
01238
01239 $dVat = 0;
01240 if ( ( $oPrice = $this->getPrice() ) != null ) {
01241 $dVat = $oPrice->getVat();
01242 }
01243
01244
01245 $oList = oxNew( 'oxlist' );
01246 $oList->init( 'oxselectlist' );
01247 $oList->getBaseObject()->setVat( $dVat );
01248 $oList->selectString( sprintf( $sQ, $oDb->quote( $this->getId() ) ) );
01249
01250
01251 if ( $oList->count() == 0 && $this->oxarticles__oxparentid->value ) {
01252 $oList->selectString( sprintf( $sQ, $oDb->quote( $this->oxarticles__oxparentid->value ) ) );
01253 }
01254
01255 self::$_aSelections[$sId] = $oList->count() ? $oList : false;
01256 }
01257
01258 if ( self::$_aSelections[$sId] ) {
01259
01260 $aFilter = ( $aFilter === null ) ? oxConfig::getParameter( "sel" ) : $aFilter;
01261 if ( $aFilter ) {
01262 $iSelIdx = 0;
01263 foreach ( self::$_aSelections[$sId] as $oSelection ) {
01264 if ( isset( $aFilter[$iSelIdx] ) ) {
01265 $oSelection->setActiveSelectionByIndex( $aFilter[$iSelIdx] );
01266 }
01267 $iSelIdx++;
01268 }
01269 }
01270 }
01271
01272 return self::$_aSelections[$sId];
01273 }
01274
01284 protected function _loadVariantList( $blSimple, $blRemoveNotOrderables = true, $blForceCoreTable = null )
01285 {
01286 $oVariants = array();
01287 if ( ( $sId = $this->getId() ) ) {
01288
01289 self::$_aLoadedParents[$sId] = $this;
01290
01291 $myConfig = $this->getConfig();
01292
01293 if ( !$this->_blLoadVariants ||
01294 ( !$this->isAdmin() && !$myConfig->getConfigParam( 'blLoadVariants') ) ||
01295 ( !$this->isAdmin() && !$this->oxarticles__oxvarcount->value ) ) {
01296 return $oVariants;
01297 }
01298
01299
01300 $sCacheKey = $blSimple ? "simple" : "full";
01301 if ( $blRemoveNotOrderables ) {
01302 if ( isset( $this->_aVariants[$sCacheKey] ) ) {
01303 return $this->_aVariants[$sCacheKey];
01304 } else {
01305 $this->_aVariants[$sCacheKey] = & $oVariants;
01306 }
01307 } elseif ( !$blRemoveNotOrderables ) {
01308 if ( isset( $this->_aVariantsWithNotOrderables[$sCacheKey] ) ) {
01309 return $this->_aVariantsWithNotOrderables[$sCacheKey];
01310 } else {
01311 $this->_aVariantsWithNotOrderables[$sCacheKey] = & $oVariants;
01312 }
01313 }
01314
01315 if ( ( $this->_blHasVariants = $this->_hasAnyVariant( $blForceCoreTable ) ) ) {
01316
01317
01318 if ( $blSimple ) {
01319 $oVariants = oxNew( 'oxsimplevariantlist' );
01320 $oVariants->setParent( $this );
01321 } else {
01322
01323 $oVariants = oxNew( 'oxarticlelist' );
01324 $oVariants->getBaseObject()->modifyCacheKey( '_variants' );
01325 }
01326
01327 startProfile("selectVariants");
01328 $blUseCoreTable = (bool) $blForceCoreTable;
01329 $oBaseObject = $oVariants->getBaseObject();
01330 $oBaseObject->setLanguage( $this->getLanguage() );
01331
01332
01333 $sArticleTable = $this->getViewName( $blUseCoreTable );
01334
01335 $sSelect = "select ".$oBaseObject->getSelectFields( $blUseCoreTable )." from $sArticleTable where " .
01336 $this->getActiveCheckQuery( $blUseCoreTable ) .
01337 $this->getVariantsQuery( $blRemoveNotOrderables, $blUseCoreTable ) .
01338 " order by $sArticleTable.oxsort";
01339
01340
01341 $oVariants->selectString( $sSelect );
01342
01343
01344 if ( $myConfig->getConfigParam( 'blUseMultidimensionVariants' ) ) {
01345 $oMdVariants = oxNew( "oxVariantHandler" );
01346 $this->_blHasMdVariants = $oMdVariants->isMdVariant( $oVariants->current() );
01347 }
01348 stopProfile("selectVariants");
01349 }
01350
01351
01352 if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && $this->_blHasVariants ) {
01353 $this->_blNotBuyableParent = true;
01354 }
01355
01356
01357 if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && count( $oVariants ) == 0 && $this->_blHasVariants ) {
01358 $this->_blNotBuyable = true;
01359 }
01360 }
01361
01362 return $oVariants;
01363 }
01364
01373 public function getFullVariants( $blRemoveNotOrderables = true, $blForceCoreTable = null )
01374 {
01375 return $this->_loadVariantList( false, $blRemoveNotOrderables, $blForceCoreTable );
01376 }
01377
01386 public function getVariants( $blRemoveNotOrderables = true, $blForceCoreTable = null )
01387 {
01388 return $this->_loadVariantList( $this->_isInList(), $blRemoveNotOrderables, $blForceCoreTable );
01389 }
01390
01396 public function getSimpleVariants()
01397 {
01398 if ( $this->oxarticles__oxvarcount->value) {
01399 return $this->getVariants();
01400 }
01401 }
01402
01411 public function getAdminVariants( $sLanguage = null )
01412 {
01413 $oVariants = oxNew( 'oxarticlelist');
01414 if ( ( $sId = $this->getId() ) ) {
01415
01416 $oBaseObj = $oVariants->getBaseObject();
01417
01418 if ( is_null( $sLanguage ) ) {
01419 $oBaseObj->setLanguage( oxRegistry::getLang()->getBaseLanguage() );
01420 } else {
01421 $oBaseObj->setLanguage( $sLanguage );
01422 }
01423
01424 $sSql = "select * from ".$oBaseObj->getViewName()." where oxparentid = '{$sId}' order by oxsort ";
01425 $oVariants->selectString( $sSql );
01426
01427
01428 if ( !$this->getConfig()->getConfigParam( 'blVariantParentBuyable' ) && ( $oVariants->count() > 0 ) ) {
01429
01430 $this->_blNotBuyableParent = true;
01431 }
01432 }
01433
01434 return $oVariants;
01435 }
01436
01444 public function getCategory()
01445 {
01446 $oCategory = oxNew( 'oxcategory' );
01447 $oCategory->setLanguage( $this->getLanguage() );
01448
01449
01450 $sOXID = $this->getId();
01451 if ( isset( $this->oxarticles__oxparentid->value ) && $this->oxarticles__oxparentid->value ) {
01452 $sOXID = $this->oxarticles__oxparentid->value;
01453 }
01454
01455 if ( $sOXID ) {
01456
01457 if ( !isset( $this->_aCategoryCache[ $sOXID ] ) ) {
01458 startPRofile( 'getCategory' );
01459 $oStr = getStr();
01460 $sWhere = $oCategory->getSqlActiveSnippet();
01461 $sSelect = $this->_generateSearchStr( $sOXID );
01462 $sSelect .= ( $oStr->strstr( $sSelect, 'where' )?' and ':' where ') . $sWhere . " order by oxobject2category.oxtime limit 1";
01463
01464
01465 if ( !$oCategory->assignRecord( $sSelect ) ) {
01466
01467 $sSelect = $this->_generateSearchStr( $sOXID, true );
01468 $sSelect .= ( $oStr->strstr( $sSelect, 'where' )?' and ':' where ') . $sWhere . " limit 1";
01469
01470
01471 if ( !$oCategory->assignRecord( $sSelect ) ) {
01472 $oCategory = null;
01473 }
01474 }
01475
01476 $this->_aCategoryCache[ $sOXID ] = $oCategory;
01477 stopPRofile( 'getCategory' );
01478 } else {
01479
01480 $oCategory = $this->_aCategoryCache[ $sOXID ];
01481 }
01482 }
01483
01484 return $oCategory;
01485 }
01486
01495 public function getCategoryIds( $blActCats = false, $blSkipCache = false )
01496 {
01497 $myConfig = $this->getConfig();
01498 if ( isset( self::$_aArticleCats[$this->getId()] ) && !$blSkipCache ) {
01499 return self::$_aArticleCats[$this->getId()];
01500 }
01501
01502
01503 $sOXID = $this->getId();
01504 if (isset( $this->oxarticles__oxparentid->value) && $this->oxarticles__oxparentid->value) {
01505 $sOXID = $this->oxarticles__oxparentid->value;
01506 }
01507
01508
01509 $sSql = $this->_getSelectCatIds( $sOXID, $blActCats );
01510 $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
01511 $rs = $oDb->select( $sSql );
01512
01513
01514 $aRet = array();
01515
01516 if ($rs != false && $rs->recordCount() > 0) {
01517 while (!$rs->EOF) {
01518 $aRet[] = $rs->fields['oxcatnid'];
01519 $rs->moveNext();
01520 }
01521 }
01522
01523
01524 $sSql = $this->getSqlForPriceCategories();
01525 $oDb->setFetchMode( oxDb::FETCH_MODE_ASSOC );
01526 $rs = $oDb->select( $sSql );
01527
01528 if ($rs != false && $rs->recordCount() > 0) {
01529 while (!$rs->EOF) {
01530
01531 if ( is_array( $rs->fields ) ) {
01532 $rs->fields = array_change_key_case( $rs->fields, CASE_LOWER );
01533 }
01534
01535
01536 if ( !$aRet[$rs->fields['oxid']] ) {
01537 $aRet[] = $rs->fields['oxid'];
01538 }
01539 $rs->moveNext();
01540 }
01541 }
01542
01543 return self::$_aArticleCats[$this->getId()] = $aRet;
01544 }
01545
01554 protected function _getSelectCatIds( $sOXID, $blActCats = false )
01555 {
01556 $sO2CView = $this->_getObjectViewName('oxobject2category');
01557 $sCatView = $this->_getObjectViewName('oxcategories');
01558 $sSelect = "select oxobject2category.oxcatnid as oxcatnid from $sO2CView as oxobject2category left join $sCatView as oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
01559 $sSelect .= 'where oxobject2category.oxobjectid='.oxDb::getDb()->quote($sOXID).' and oxcategories.oxid is not null and oxcategories.oxactive = 1 ';
01560 if ( $blActCats ) {
01561 $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 ";
01562 }
01563 $sSelect .= 'order by oxobject2category.oxtime ';
01564 return $sSelect;
01565 }
01566
01576 public function getVendor( $blShopCheck = true )
01577 {
01578 if ( ( $sVendorId = $this->getVendorId() ) ) {
01579 $oVendor = oxNew( 'oxvendor' );
01580 } elseif ( !$blShopCheck && $this->oxarticles__oxvendorid->value ) {
01581 $oVendor = oxNew( 'oxi18n' );
01582 $oVendor->init('oxvendor');
01583 $oVendor->setReadOnly( true );
01584 $sVendorId = $this->oxarticles__oxvendorid->value;
01585 }
01586 if ( $sVendorId && $oVendor->load( $sVendorId ) && $oVendor->oxvendor__oxactive->value ) {
01587
01588 return $oVendor;
01589 }
01590 return null;
01591 }
01592
01600 public function getVendorId( $blForceReload = false )
01601 {
01602 $sVendorId = false;
01603 if ( $this->oxarticles__oxvendorid->value ) {
01604 $sVendorId = $this->oxarticles__oxvendorid->value;
01605
01606 }
01607 return $sVendorId;
01608 }
01609
01617 public function getManufacturerId( $blForceReload = false )
01618 {
01619 $sManufacturerId = false;
01620 if ( $this->oxarticles__oxmanufacturerid->value ) {
01621
01622 $sManufacturerId = $this->oxarticles__oxmanufacturerid->value;
01623
01624 }
01625 return $sManufacturerId;
01626 }
01627
01637 public function getManufacturer( $blShopCheck = true )
01638 {
01639 $oManufacturer = oxNew( 'oxmanufacturer' );;
01640 if ( !( $sManufacturerId = $this->getManufacturerId() ) &&
01641 !$blShopCheck && $this->oxarticles__oxmanufacturerid->value ) {
01642 $oManufacturer->setReadOnly( true );
01643 $sManufacturerId = $this->oxarticles__oxmanufacturerid->value;
01644 }
01645
01646 if ( $sManufacturerId && $oManufacturer->load( $sManufacturerId ) ) {
01647 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadManufacturerTree' ) ) {
01648 $oManufacturer->setReadOnly( true );
01649 }
01650 $oManufacturer = $oManufacturer->oxmanufacturers__oxactive->value ? $oManufacturer : null;
01651 } else {
01652 $oManufacturer = null;
01653 }
01654
01655 return $oManufacturer;
01656 }
01657
01665 public function inCategory( $sCatNid)
01666 {
01667 return in_array( $sCatNid, $this->getCategoryIds());
01668 }
01669
01678 public function isAssignedToCategory( $sCatId )
01679 {
01680
01681 $sOXID = $this->getId();
01682 if ( isset( $this->oxarticles__oxparentid->value) && $this->oxarticles__oxparentid->value) {
01683 $sOXID = $this->oxarticles__oxparentid->value;
01684 }
01685
01686 $oDb = oxDb::getDb();
01687 $sSelect = $this->_generateSelectCatStr( $sOXID, $sCatId);
01688 $sOXID = $oDb->getOne( $sSelect );
01689
01690 if ( isset( $sOXID) && $sOXID) {
01691 return true;
01692 }
01693
01694
01695 if ( $this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) && $this->_blLoadPrice ) {
01696 $dPriceFromTo = $this->getPrice()->getBruttoPrice();
01697 if ( $dPriceFromTo > 0) {
01698 $sSelect = $this->_generateSelectCatStr( $sOXID, $sCatId, $dPriceFromTo);
01699 $sOXID = $oDb->getOne( $sSelect );
01700
01701 if ( isset( $sOXID) && $sOXID) {
01702 return true;
01703 }
01704 }
01705 }
01706 return false;
01707 }
01708
01714 public function getTPrice()
01715 {
01716 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
01717 return;
01718 }
01719
01720
01721 if ( $this->_oTPrice !== null ) {
01722 return $this->_oTPrice;
01723 }
01724
01725 $oPrice = $this->_getPriceObject();
01726
01727 $dBasePrice = $this->oxarticles__oxtprice->value;
01728 $dBasePrice = $this->_preparePrice( $dBasePrice, $this->getArticleVat() );
01729
01730 $oPrice->setPrice( $dBasePrice );
01731
01732 $this->_applyVat( $oPrice, $this->getArticleVat() );
01733 $this->_applyCurrency( $oPrice );
01734
01735 if ( $this->isParentNotBuyable() ) {
01736
01737 $oPrice2 = $this->getVarMinPrice();
01738 } else {
01739
01740 $oPrice2 = $this->getPrice();
01741 }
01742
01743 if ( $oPrice->getPrice() <= $oPrice2->getPrice() ) {
01744
01745 return;
01746 }
01747
01748 $this->_oTPrice = $oPrice;
01749
01750 return $this->_oTPrice;
01751 }
01752
01758 public function skipDiscounts()
01759 {
01760
01761 if ( $this->_blSkipDiscounts !== null ) {
01762 return $this->_blSkipDiscounts;
01763 }
01764
01765 if ( $this->oxarticles__oxskipdiscounts->value ) {
01766 return true;
01767 }
01768
01769
01770 $this->_blSkipDiscounts = false;
01771 if ( oxRegistry::get("oxDiscountList")->hasSkipDiscountCategories() ) {
01772
01773 $oDb = oxDb::getDb();
01774 $sO2CView = getViewName( 'oxobject2category', $this->getLanguage() );
01775 $sViewName = getViewName( 'oxcategories', $this->getLanguage() );
01776 $sSelect = "select 1 from $sO2CView as $sO2CView left join {$sViewName} on {$sViewName}.oxid = $sO2CView.oxcatnid
01777 where $sO2CView.oxobjectid=".$oDb->quote( $this->getId() )." and {$sViewName}.oxactive = 1 and {$sViewName}.oxskipdiscounts = '1' ";
01778 $this->_blSkipDiscounts = ( $oDb->getOne( $sSelect ) == 1 );
01779 }
01780
01781 return $this->_blSkipDiscounts;
01782 }
01783
01791 public function setPrice(oxPrice $oPrice)
01792 {
01793 $this->_oPrice = $oPrice;
01794 }
01795
01804 public function getBasePrice( $dAmount = 1 )
01805 {
01806
01807
01808
01809
01810 $myConfig = $this->getConfig();
01811 if( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice )
01812 return;
01813
01814
01815 $dPrice = $this->_getAmountPrice( $dAmount );
01816
01817
01818 return $dPrice;
01819 }
01820
01828 public function getPrice( $dAmount = 1 )
01829 {
01830 $myConfig = $this->getConfig();
01831
01832 if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
01833 return;
01834 }
01835
01836
01837 if ( $dAmount != 1 || $this->_oPrice === null ) {
01838
01839
01840 $dBasePrice = $this->getBasePrice( $dAmount );
01841 $dBasePrice = $this->_preparePrice( $dBasePrice, $this->getArticleVat() );
01842
01843 $oPrice = $this->_getPriceObject();
01844
01845 $oPrice->setPrice( $dBasePrice );
01846
01847
01848 if ( !$this->_blCalcPrice && $dAmount == 1 ) {
01849 return $this->_oPrice = $oPrice;
01850 }
01851
01852 $this->_calculatePrice( $oPrice );
01853 if ( $dAmount != 1 ) {
01854 return $oPrice;
01855 }
01856
01857 $this->_oPrice = $oPrice;
01858 }
01859 return $this->_oPrice;
01860 }
01861
01870 protected function _calculatePrice( $oPrice, $dVat = null )
01871 {
01872
01873 if ( isset( $dVat ) || !$this->getConfig()->getConfigParam( 'bl_perfCalcVatOnlyForBasketOrder' ) ) {
01874 $this->_applyVAT( $oPrice, isset( $dVat ) ? $dVat : $this->getArticleVat() );
01875 }
01876
01877
01878 $this->_applyCurrency( $oPrice );
01879
01880 if ( !$this->skipDiscounts() ) {
01881 $oDiscountList = oxRegistry::get("oxDiscountList");
01882 $aDiscounts = $oDiscountList->getArticleDiscounts( $this, $this->getArticleUser() );
01883
01884 reset( $aDiscounts );
01885 foreach ( $aDiscounts as $oDiscount ) {
01886 $oPrice->setDiscount($oDiscount->getAddSum(), $oDiscount->getAddSumType());
01887 }
01888 $oPrice->calculateDiscount();
01889 }
01890
01891 return $oPrice;
01892 }
01893
01901 public function setArticleUser($oUser)
01902 {
01903 $this->_oUser = $oUser;
01904 }
01905
01911 public function getArticleUser()
01912 {
01913 if ($this->_oUser) {
01914 return $this->_oUser;
01915 }
01916 return $this->getUser();
01917 }
01918
01928 public function getBasketPrice( $dAmount, $aSelList, $oBasket )
01929 {
01930 $oUser = $oBasket->getBasketUser();
01931 $this->setArticleUser( $oUser );
01932
01933 $oBasketPrice = $this->_getPriceObject( $oBasket->isCalculationModeNetto() );
01934
01935
01936 $dBasePrice = $this->getBasePrice( $dAmount );
01937 $dBasePrice = $this->_preparePrice( $dBasePrice, $this->getArticleVat(), $oBasket->isCalculationModeNetto() );
01938
01939
01940 $dBasePrice = $this->_modifySelectListPrice( $dBasePrice, $aSelList );
01941
01942
01943 $oBasketPrice->setPrice( $dBasePrice );
01944
01945 $dVat = oxRegistry::get("oxVatSelector")->getBasketItemVat( $this, $oBasket );
01946 $this->_calculatePrice( $oBasketPrice, $dVat );
01947
01948
01949 return $oBasketPrice;
01950 }
01951
01960 public function delete( $sOXID = null )
01961 {
01962 if ( !$sOXID ) {
01963 $sOXID = $this->getId();
01964 }
01965 if ( !$sOXID ) {
01966 return false;
01967 }
01968
01969
01970
01971
01972 $this->_deleteVariantRecords( $sOXID );
01973 $this->load( $sOXID );
01974 $this->_deletePics();
01975 $this->_onChangeResetCounts( $sOXID, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
01976
01977
01978 parent::delete( $sOXID );
01979
01980 $rs = $this->_deleteRecords( $sOXID );
01981
01982 oxRegistry::get("oxSeoEncoderArticle")->onDeleteArticle($this);
01983
01984 $this->onChange( ACTION_DELETE, $sOXID, $this->oxarticles__oxparentid->value );
01985
01986 return $rs->EOF;
01987 }
01988
01997 public function reduceStock($dAmount, $blAllowNegativeStock = false)
01998 {
01999 $this->beforeUpdate();
02000
02001 $iStockCount = $this->oxarticles__oxstock->value - $dAmount;
02002 if (!$blAllowNegativeStock && ($iStockCount < 0)) {
02003 $dAmount += $iStockCount;
02004 $iStockCount = 0;
02005 }
02006 $this->oxarticles__oxstock = new oxField($iStockCount);
02007
02008 $oDb = oxDb::getDb();
02009 $oDb->execute( 'update oxarticles set oxarticles.oxstock = '.$oDb->quote( $iStockCount ).' where oxarticles.oxid = '.$oDb->quote( $this->getId() ) );
02010 $this->onChange( ACTION_UPDATE_STOCK );
02011 return $dAmount;
02012 }
02013
02022 public function updateSoldAmount( $dAmount = 0 )
02023 {
02024 if ( !$dAmount ) {
02025 return;
02026 }
02027
02028 $this->beforeUpdate();
02029
02030
02031 if ( !$this->oxarticles__oxparentid->value ) {
02032
02033 $dAmount = (double) $dAmount;
02034 $oDb = oxDb::getDb();
02035 $rs = $oDb->execute( "update oxarticles set oxarticles.oxsoldamount = oxarticles.oxsoldamount + $dAmount where oxarticles.oxid = ".$oDb->quote($this->oxarticles__oxid->value));
02036 } elseif ( $this->oxarticles__oxparentid->value) {
02037
02038 $oUpdateArticle = oxNewArticle( $this->oxarticles__oxparentid->value );
02039 $oUpdateArticle->updateSoldAmount( $dAmount );
02040 }
02041
02042 $this->onChange( ACTION_UPDATE );
02043
02044 return $rs;
02045 }
02046
02052 public function disableReminder()
02053 {
02054 $oDb = oxDb::getDb();
02055 return $oDb->execute( "update oxarticles set oxarticles.oxremindactive = 2 where oxarticles.oxid = ".$oDb->quote($this->oxarticles__oxid->value));
02056 }
02057
02063 public function save()
02064 {
02065 if ( ( $blRet = parent::save() ) ) {
02066
02067 $this->_saveArtLongDesc();
02068 }
02069
02070 return $blRet;
02071 }
02072
02078 public function resetParent()
02079 {
02080 $sParentId = $this->oxarticles__oxparentid;
02081 $this->oxarticles__oxparentid = new oxField( '', oxField::T_RAW );
02082 $this->_blAllowEmptyParentId = true;
02083 $this->save();
02084 $this->_blAllowEmptyParentId = false;
02085
02086 if ( $sParentId !== '' ) {
02087 $this->onChange( ACTION_UPDATE, null, $sParentId );
02088 }
02089 }
02090
02091
02098 public function getPictureGallery()
02099 {
02100 $myConfig = $this->getConfig();
02101
02102
02103 $blMorePic = false;
02104 $aArtPics = array();
02105 $aArtIcons = array();
02106 $iActPicId = 1;
02107 $sActPic = $this->getPictureUrl( $iActPicId );
02108
02109 if ( oxConfig::getParameter( 'actpicid' ) ) {
02110 $iActPicId = oxConfig::getParameter('actpicid');
02111 }
02112
02113 $oStr = getStr();
02114 $iCntr = 0;
02115 $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
02116 $blCheckActivePicId = true;
02117
02118 for ( $i = 1; $i <= $iPicCount; $i++) {
02119 $sPicVal = $this->getPictureUrl( $i );
02120 $sIcoVal = $this->getIconUrl( $i );
02121 if ( !$oStr->strstr($sIcoVal, 'nopic_ico.jpg') && !$oStr->strstr($sIcoVal, 'nopic.jpg') &&
02122 !$oStr->strstr($sPicVal, 'nopic_ico.jpg') && !$oStr->strstr($sPicVal, 'nopic.jpg') ) {
02123 if ($iCntr) {
02124 $blMorePic = true;
02125 }
02126 $aArtIcons[$i]= $sIcoVal;
02127 $aArtPics[$i]= $sPicVal;
02128 $iCntr++;
02129
02130 if ($iActPicId == $i) {
02131 $sActPic = $sPicVal;
02132 $blCheckActivePicId = false;
02133 }
02134
02135 } else if ( $blCheckActivePicId && $iActPicId <= $i) {
02136
02137
02138 $iActPicId++;
02139 }
02140 }
02141
02142 $blZoomPic = false;
02143 $aZoomPics = array();
02144 $iZoomPicCount = $myConfig->getConfigParam( 'iPicCount' );
02145
02146 for ( $j = 1,$c = 1; $j <= $iZoomPicCount; $j++) {
02147 $sVal = $this->getZoomPictureUrl($j);
02148
02149 if ( $sVal && !$oStr->strstr($sVal, 'nopic.jpg')) {
02150 $blZoomPic = true;
02151 $aZoomPics[$c]['id'] = $c;
02152 $aZoomPics[$c]['file'] = $sVal;
02153
02154 if (!$sVal) {
02155 $aZoomPics[$c]['file'] = "nopic.jpg";
02156 }
02157 $c++;
02158 }
02159 }
02160
02161 $aPicGallery = array('ActPicID' => $iActPicId,
02162 'ActPic' => $sActPic,
02163 'MorePics' => $blMorePic,
02164 'Pics' => $aArtPics,
02165 'Icons' => $aArtIcons,
02166 'ZoomPic' => $blZoomPic,
02167 'ZoomPics' => $aZoomPics);
02168
02169 return $aPicGallery;
02170 }
02171
02185 public function onChange($sAction = null, $sOXID = null, $sParentID = null)
02186 {
02187 $myConfig = $this->getConfig();
02188
02189 if (!isset($sOXID)) {
02190 if ( $this->getId()) {
02191 $sOXID = $this->getId();
02192 }
02193 if (!isset ($sOXID)) {
02194 $sOXID = $this->oxarticles__oxid->value;
02195 }
02196 if ($this->oxarticles__oxparentid->value) {
02197 $sParentID = $this->oxarticles__oxparentid->value;
02198 }
02199 }
02200 if (!isset($sOXID)) {
02201 return;
02202 }
02203
02204
02205 if ( $myConfig->getConfigParam( 'blUseStock' ) ) {
02206
02207
02208 if (!isset($sParentID)) {
02209 $oDb = oxDb::getDb();
02210 $sQ = 'select oxparentid from oxarticles where oxid = '.$oDb->quote($sOXID);
02211 $sParentID = $oDb->getOne( $sQ );
02212 }
02213
02214 if ($sParentID) {
02215 $this->_onChangeUpdateStock($sParentID);
02216 }
02217 }
02218
02219
02220 if ($sParentID) {
02221 $this->_onChangeUpdateVarCount($sParentID);
02222 }
02223
02224 $sId = ( $sParentID ) ? $sParentID : $sOXID;
02225 $this->_setVarMinMaxPrice( $sId );
02226
02227
02228
02229 if ( $sAction === ACTION_UPDATE_STOCK ) {
02230 $this->_onChangeStockResetCount( $sOXID );
02231 }
02232
02233 }
02234
02241 public function getCustomVAT()
02242 {
02243 if ( isset($this->oxarticles__oxvat->value) ) {
02244 return $this->oxarticles__oxvat->value;
02245 }
02246 }
02247
02256 public function checkForStock( $dAmount, $dArtStockAmount = 0 )
02257 {
02258 $myConfig = $this->getConfig();
02259 if ( !$myConfig->getConfigParam( 'blUseStock' ) ) {
02260 return true;
02261 }
02262
02263 $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
02264
02265 $sQ = 'select oxstock, oxstockflag from oxarticles where oxid = '.$oDb->quote( $this->getId() );
02266 $rs = $oDb->select( $sQ );
02267
02268 $iOnStock = 0;
02269 $iStockFlag = 0;
02270 if ( $rs !== false && $rs->recordCount() > 0 ) {
02271 $iOnStock = $rs->fields['oxstock'] - $dArtStockAmount;
02272 $iStockFlag = $rs->fields['oxstockflag'];
02273
02274
02275 if ( $iStockFlag == 1 || $iStockFlag == 4) {
02276 return true;
02277 }
02278 if ( !$myConfig->getConfigParam( 'blAllowUnevenAmounts' ) ) {
02279 $iOnStock = floor( $iOnStock );
02280 }
02281 }
02282 if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
02283 $iOnStock += $this->getSession()->getBasketReservations()->getReservedAmount($this->getId());
02284 }
02285 if ( $iOnStock >= $dAmount ) {
02286 return true;
02287 } else {
02288 if ( $iOnStock > 0 ) {
02289 return $iOnStock;
02290 } else {
02291 $oEx = oxNew( 'oxArticleInputException' );
02292 $oEx->setMessage( 'EXCEPTION_ARTICLE_ARTICELNOTBUYABLE' );
02293 oxRegistry::get("oxUtilsView")->addErrorToDisplay( $oEx );
02294 return false;
02295 }
02296 }
02297 }
02298
02299
02305 public function getLongDescription()
02306 {
02307 if ( $this->_oLongDesc === null ) {
02308
02309 $this->_oLongDesc = new oxField();
02310
02311
02312
02313 $sOxid = $this->getId();
02314 $sViewName = getViewName( 'oxartextends', $this->getLanguage() );
02315
02316 $oDb = oxDb::getDb();
02317 $sDbValue = $oDb->getOne( "select oxlongdesc from {$sViewName} where oxid = " . $oDb->quote( $sOxid ) );
02318
02319 if ( $sDbValue != false ) {
02320 $this->_oLongDesc->setValue( $sDbValue, oxField::T_RAW );
02321 } elseif ( $this->oxarticles__oxparentid->value ) {
02322 if ( !$this->isAdmin() || $this->_blLoadParentData ) {
02323 $this->_oLongDesc->setValue( $this->getParentArticle()->getLongDescription()->getRawValue(), oxField::T_RAW );
02324 }
02325 }
02326 }
02327 return $this->_oLongDesc;
02328 }
02329
02336 public function getLongDesc()
02337 {
02338 return oxRegistry::get("oxUtilsView")->parseThroughSmarty( $this->getLongDescription()->getRawValue(), $this->getId().$this->getLanguage(), null, true );
02339 }
02340
02348 public function setArticleLongDesc( $sDesc )
02349 {
02350
02351
02352 $this->_oLongDesc = new oxField( $sDesc, oxField::T_RAW );
02353 $this->oxarticles__oxlongdesc = new oxField( $sDesc, oxField::T_RAW );
02354 }
02355
02361 public function getAttributes()
02362 {
02363 if ( $this->_oAttributeList === null ) {
02364 $this->_oAttributeList = oxNew( 'oxattributelist' );
02365 $this->_oAttributeList->loadAttributes( $this->getId(), $this->getParentId() );
02366 }
02367
02368 return $this->_oAttributeList;
02369 }
02370
02376 public function getAttributesDisplayableInBasket()
02377 {
02378 if ( $this->_oAttributeList === null ) {
02379 $this->_oAttributeList = oxNew( 'oxattributelist' );
02380 $this->_oAttributeList->loadAttributesDisplayableInBasket( $this->getId() );
02381 }
02382
02383 return $this->_oAttributeList;
02384 }
02385
02386
02395 public function appendLink( $sAddParams, $iLang = null )
02396 {
02397 if ( $sAddParams ) {
02398 if ( $iLang === null ) {
02399 $iLang = $this->getLanguage();
02400 }
02401
02402 $this->_aSeoAddParams[$iLang] = isset( $this->_aSeoAddParams[$iLang] ) ? $this->_aSeoAddParams[$iLang] . "&" : "";
02403 $this->_aSeoAddParams[$iLang] .= $sAddParams;
02404 }
02405 }
02406
02415 public function getBaseSeoLink( $iLang, $blMain = false )
02416 {
02417 $oEncoder = oxRegistry::get("oxSeoEncoderArticle");
02418 if ( !$blMain ) {
02419 return $oEncoder->getArticleUrl( $this, $iLang, $this->getLinkType() );
02420 }
02421 return $oEncoder->getArticleMainUrl( $this, $iLang );
02422 }
02423
02432 public function getLink( $iLang = null, $blMain = false )
02433 {
02434 if ( !oxRegistry::getUtils()->seoIsActive() ) {
02435 return $this->getStdLink( $iLang );
02436 }
02437
02438 if ( $iLang === null ) {
02439 $iLang = $this->getLanguage();
02440 }
02441
02442 $iLinkType = $this->getLinkType();
02443 if ( !isset( $this->_aSeoUrls[$iLang][$iLinkType] ) ) {
02444 $this->_aSeoUrls[$iLang][$iLinkType] = $this->getBaseSeoLink( $iLang, $blMain );
02445 }
02446
02447 $sUrl = $this->_aSeoUrls[$iLang][$iLinkType];
02448 if ( isset($this->_aSeoAddParams[$iLang])) {
02449 $sUrl .= ( ( strpos( $sUrl.$this->_aSeoAddParams[$iLang], '?' ) === false ) ? '?' : '&' ).$this->_aSeoAddParams[$iLang];
02450 }
02451
02452 return $sUrl;
02453 }
02454
02463 public function getMainLink( $iLang = null )
02464 {
02465 return $this->getLink( $iLang, true );
02466 }
02467
02475 public function setLinkType( $iType )
02476 {
02477
02478 $this->_sDetailLink = null;
02479
02480
02481 $this->_iLinkType = (int) $iType;
02482 }
02483
02489 public function getLinkType()
02490 {
02491 return $this->_iLinkType;
02492 }
02493
02502 public function appendStdLink( $sAddParams, $iLang = null )
02503 {
02504 if ( $sAddParams ) {
02505 if ( $iLang === null ) {
02506 $iLang = $this->getLanguage();
02507 }
02508
02509 $this->_aStdAddParams[$iLang] = isset( $this->_aStdAddParams[$iLang] ) ? $this->_aStdAddParams[$iLang] . "&" : "";
02510 $this->_aStdAddParams[$iLang] .= $sAddParams;
02511 }
02512 }
02513
02523 public function getBaseStdLink( $iLang, $blAddId = true, $blFull = true )
02524 {
02525 $sUrl = '';
02526 if ( $blFull ) {
02527
02528 $sUrl = $this->getConfig()->getShopUrl( $iLang, false );
02529 }
02530
02531 $sUrl .= "index.php?cl=details" . ( $blAddId ? "&anid=".$this->getId() : "" );
02532 return $sUrl . ( isset( $this->_aStdAddParams[$iLang] ) ? "&". $this->_aStdAddParams[$iLang] : "" );
02533 }
02534
02543 public function getStdLink( $iLang = null, $aParams = array() )
02544 {
02545 if ( $iLang === null ) {
02546 $iLang = $this->getLanguage();
02547 }
02548
02549 if ( !isset( $this->_aStdUrls[$iLang] ) ) {
02550 $this->_aStdUrls[$iLang] = $this->getBaseStdLink( $iLang );
02551 }
02552
02553 return oxRegistry::get("oxUtilsUrl")->processUrl( $this->_aStdUrls[$iLang], true, $aParams, $iLang );
02554 }
02555
02565 public function getStdTagLink( $sTag )
02566 {
02567 $oArticleTags = oxNew('oxarticletaglist');
02568 $oArticleTags->setArticleId( $this->getId() );
02569 return $oArticleTags->getStdTagLink($sTag);
02570 }
02571
02579 public function getTags()
02580 {
02581 $oArticleTags = oxNew('oxarticletaglist');
02582 $oArticleTags->load( $this->getId() );
02583 return $oArticleTags->get()->__toString();
02584 }
02585
02595 public function saveTags($sTags)
02596 {
02597
02598 if ( !$this->allowDerivedUpdate() ) {
02599 return false;
02600 }
02601 $oArticleTags = oxNew('oxarticletaglist');
02602 $oArticleTags->setArticleId( $this->getId() );
02603 $oArticleTags->set( $sTags );
02604 $oArticleTags->save();
02605 }
02606
02616 public function addTag($sTag)
02617 {
02618 $oArticleTags = oxNew('oxarticletaglist');
02619 $oArticleTags->load( $this->getId() );
02620 $oArticleTags->addTag( $sTag );
02621 if ( $oArticleTags->save() ) {
02622 return true;
02623 }
02624 return false;
02625 }
02626
02632 public function getMediaUrls()
02633 {
02634 if ( $this->_aMediaUrls === null ) {
02635 $this->_aMediaUrls = oxNew("oxlist");
02636 $this->_aMediaUrls->init("oxmediaurl");
02637 $this->_aMediaUrls->getBaseObject()->setLanguage( $this->getLanguage() );
02638
02639 $sViewName = getViewName( "oxmediaurls", $this->getLanguage() );
02640 $sQ = "select * from {$sViewName} where oxobjectid = '".$this->getId()."'";
02641 $this->_aMediaUrls->selectString($sQ);
02642 }
02643 return $this->_aMediaUrls;
02644 }
02645
02651 public function getDynImageDir()
02652 {
02653 return $this->_sDynImageDir;
02654 }
02655
02661 public function getDispSelList()
02662 {
02663 if ($this->_aDispSelList === null) {
02664 if ( $this->getConfig()->getConfigParam( 'bl_perfLoadSelectLists' ) && $this->getConfig()->getConfigParam( 'bl_perfLoadSelectListsInAList' ) ) {
02665 $this->_aDispSelList = $this->getSelectLists();
02666 }
02667 }
02668 return $this->_aDispSelList;
02669 }
02670
02676 public function getMoreDetailLink()
02677 {
02678 if ( $this->_sMoreDetailLink == null ) {
02679
02680
02681 $this->_sMoreDetailLink = $this->getConfig()->getShopHomeURL() . 'cl=moredetails';
02682
02683
02684 if ( $sActCat = oxConfig::getParameter( 'cnid' ) ) {
02685 $this->_sMoreDetailLink .= '&cnid='.$sActCat;
02686 }
02687 $this->_sMoreDetailLink .= '&anid='.$this->getId();
02688 $this->_sMoreDetailLink = $this->_sMoreDetailLink;
02689 }
02690
02691 return $this->_sMoreDetailLink;
02692 }
02693
02699 public function getToBasketLink()
02700 {
02701 if ( $this->_sToBasketLink == null ) {
02702 $myConfig = $this->getConfig();
02703
02704 if ( oxRegistry::getUtils()->isSearchEngine() ) {
02705 $this->_sToBasketLink = $this->getLink();
02706 } else {
02707
02708 $this->_sToBasketLink = $myConfig->getShopHomeURL();
02709
02710
02711 $sActClass = oxConfig::getParameter( 'cl' );
02712 if ( $sActClass == 'thankyou') {
02713 $sActClass = 'basket';
02714 }
02715 $this->_sToBasketLink .= 'cl='.$sActClass;
02716
02717
02718 if ( $sActCat = oxConfig::getParameter( 'cnid' ) ) {
02719 $this->_sToBasketLink .= '&cnid='.$sActCat;
02720 }
02721
02722 $this->_sToBasketLink .= '&fnc=tobasket&aid='.$this->getId().'&anid='.$this->getId();
02723
02724 if ( $sTpl = basename( oxConfig::getParameter( 'tpl' ) ) ) {
02725 $this->_sToBasketLink .= '&tpl='.$sTpl;
02726 }
02727 }
02728 }
02729
02730 return $this->_sToBasketLink;
02731 }
02732
02738 public function getStockStatus()
02739 {
02740 return $this->_iStockStatus;
02741 }
02742
02748 public function getDeliveryDate()
02749 {
02750 if ( $this->oxarticles__oxdelivery->value != '0000-00-00') {
02751 return oxRegistry::get("oxUtilsDate")->formatDBDate( $this->oxarticles__oxdelivery->value);
02752 }
02753 return false;
02754 }
02755
02761 public function getFTPrice()
02762 {
02763
02764 if ( $oPrice = $this->getTPrice() ) {
02765 if ( $dPrice = $this->_getPriceForView( $oPrice ) ) {
02766 return oxRegistry::getLang()->formatCurrency( $dPrice );
02767 }
02768 }
02769 }
02770
02776 public function getFPrice()
02777 {
02778 if ( $oPrice = $this->getPrice() ) {
02779 $dPrice = $this->_getPriceForView( $oPrice );
02780 return oxRegistry::getLang()->formatCurrency( $dPrice );
02781 }
02782 }
02783
02790 public function resetRemindStatus()
02791 {
02792 if ( $this->oxarticles__oxremindactive->value == 2 &&
02793 $this->oxarticles__oxremindamount->value <= $this->oxarticles__oxstock->value ) {
02794 $this->oxarticles__oxremindactive->value = 1;
02795 }
02796 }
02797
02803 public function getFNetPrice()
02804 {
02805 if ( $oPrice = $this->getPrice() ) {
02806 return oxRegistry::getLang()->formatCurrency( $oPrice->getNettoPrice() );
02807 }
02808 }
02809
02817 public function getPricePerUnit()
02818 {
02819 return $this->getFUnitPrice();
02820 }
02821
02827 public function isParentNotBuyable()
02828 {
02829 return $this->_blNotBuyableParent;
02830 }
02831
02837 public function isNotBuyable()
02838 {
02839 return $this->_blNotBuyable;
02840 }
02841
02849 public function setBuyableState( $blBuyable = false )
02850 {
02851 $this->_blNotBuyable = !$blBuyable;
02852 }
02853
02861 public function setSelectlist( $aSelList )
02862 {
02863 $this->_aDispSelList = $aSelList;
02864 }
02865
02873 public function getPictureUrl( $iIndex = 1 )
02874 {
02875 if ( $iIndex ) {
02876 $sImgName = false;
02877 if ( !$this->_isFieldEmpty( "oxarticles__oxpic".$iIndex ) ) {
02878 $sImgName = basename( $this->{"oxarticles__oxpic$iIndex"}->value );
02879 }
02880
02881 $sSize = $this->getConfig()->getConfigParam( 'aDetailImageSizes' );
02882 return oxRegistry::get("oxPictureHandler")->getProductPicUrl( "product/{$iIndex}/", $sImgName, $sSize, 'oxpic'.$iIndex );
02883 }
02884 }
02885
02894 public function getIconUrl( $iIndex = 0 )
02895 {
02896 $sImgName = false;
02897 $sDirname = "product/1/";
02898 if ( $iIndex && !$this->_isFieldEmpty( "oxarticles__oxpic{$iIndex}" ) ) {
02899 $sImgName = basename( $this->{"oxarticles__oxpic$iIndex"}->value );
02900 $sDirname = "product/{$iIndex}/";
02901 } elseif ( !$this->_isFieldEmpty( "oxarticles__oxicon" ) ) {
02902 $sImgName = basename( $this->oxarticles__oxicon->value );
02903 $sDirname = "product/icon/";
02904 } elseif ( !$this->_isFieldEmpty( "oxarticles__oxpic1" ) ) {
02905 $sImgName = basename( $this->oxarticles__oxpic1->value );
02906 }
02907
02908 $sSize = $this->getConfig()->getConfigParam( 'sIconsize' );
02909 return oxRegistry::get("oxPictureHandler")->getProductPicUrl( $sDirname, $sImgName, $sSize, $iIndex );
02910 }
02911
02919 public function getThumbnailUrl( $bSsl = null )
02920 {
02921 $sImgName = false;
02922 $sDirname = "product/1/";
02923 if ( !$this->_isFieldEmpty( "oxarticles__oxthumb" ) ) {
02924 $sImgName = basename( $this->oxarticles__oxthumb->value );
02925 $sDirname = "product/thumb/";
02926 } elseif ( !$this->_isFieldEmpty( "oxarticles__oxpic1" ) ) {
02927 $sImgName = basename( $this->oxarticles__oxpic1->value );
02928 }
02929
02930 $sSize = $this->getConfig()->getConfigParam( 'sThumbnailsize' );
02931 return oxRegistry::get("oxPictureHandler")->getProductPicUrl( $sDirname, $sImgName, $sSize, 0, $bSsl );
02932 }
02933
02941 public function getZoomPictureUrl( $iIndex = '' )
02942 {
02943 $iIndex = (int) $iIndex;
02944 if ( $iIndex > 0 && !$this->_isFieldEmpty( "oxarticles__oxpic".$iIndex ) ) {
02945 $sImgName = basename( $this->{"oxarticles__oxpic".$iIndex}->value );
02946 $sSize = $this->getConfig()->getConfigParam( "sZoomImageSize" );
02947 return oxRegistry::get("oxPictureHandler")->getProductPicUrl( "product/{$iIndex}/", $sImgName, $sSize, 'oxpic'.$iIndex );
02948 }
02949 }
02950
02956 public function getFileUrl()
02957 {
02958 return $this->getConfig()->getPictureUrl( 'media/' );
02959 }
02960
02968 public function getPriceFromPrefix()
02969 {
02970 $sPricePrefix = '';
02971 if ( $this->_blIsRangePrice) {
02972 $sPricePrefix = oxLang::getInstance()->translateString('PRICE_FROM').' ';
02973 }
02974
02975 return $sPricePrefix;
02976 }
02977
02983 protected function _saveArtLongDesc()
02984 {
02985 $myConfig = $this->getConfig();
02986 $sShopId = $myConfig->getShopID();
02987 if (in_array("oxlongdesc", $this->_aSkipSaveFields)) {
02988 return;
02989 }
02990
02991 if ($this->_blEmployMultilanguage) {
02992 $sValue = $this->getLongDescription()->getRawValue();
02993 if ( $sValue !== null ) {
02994 $oArtExt = oxNew('oxI18n');
02995 $oArtExt->init('oxartextends');
02996 $oArtExt->setLanguage((int) $this->getLanguage());
02997 if (!$oArtExt->load($this->getId())) {
02998 $oArtExt->setId($this->getId());
02999 }
03000 $oArtExt->oxartextends__oxlongdesc = new oxField($sValue, oxField::T_RAW);
03001 $oArtExt->save();
03002 }
03003 } else {
03004 $oArtExt = oxNew('oxI18n');
03005 $oArtExt->setEnableMultilang(false);
03006 $oArtExt->init('oxartextends');
03007 $aObjFields = $oArtExt->_getAllFields(true);
03008 if (!$oArtExt->load($this->getId())) {
03009 $oArtExt->setId($this->getId());
03010 }
03011
03012 foreach ($aObjFields as $sKey => $sValue ) {
03013 if ( preg_match('/^oxlongdesc(_(\d{1,2}))?$/', $sKey) ) {
03014 $sField = $this->_getFieldLongName($sKey);
03015
03016 if (isset($this->$sField)) {
03017 $sLongDesc = null;
03018 if ($this->$sField instanceof oxField) {
03019 $sLongDesc = $this->$sField->getRawValue();
03020 } elseif (is_object($this->$sField)) {
03021 $sLongDesc = $this->$sField->value;
03022 }
03023 if (isset($sLongDesc)) {
03024 $sAEField = $oArtExt->_getFieldLongName($sKey);
03025 $oArtExt->$sAEField = new oxField($sLongDesc, oxField::T_RAW);
03026 }
03027 }
03028 }
03029 }
03030 $oArtExt->save();
03031 }
03032 }
03033
03039 protected function _skipSaveFields()
03040 {
03041 $myConfig = $this->getConfig();
03042
03043 $this->_aSkipSaveFields = array();
03044
03045 $this->_aSkipSaveFields[] = 'oxtimestamp';
03046
03047 $this->_aSkipSaveFields[] = 'oxinsert';
03048
03049 if ( !$this->_blAllowEmptyParentId && (!isset( $this->oxarticles__oxparentid->value) || $this->oxarticles__oxparentid->value == '') ) {
03050 $this->_aSkipSaveFields[] = 'oxparentid';
03051 }
03052
03053 }
03054
03064 protected function _mergeDiscounts( $aDiscounts, $aItemDiscounts)
03065 {
03066 foreach ( $aItemDiscounts as $sKey => $oDiscount ) {
03067
03068 if ( array_key_exists ($sKey, $aDiscounts) ) {
03069 $aDiscounts[$sKey]->dDiscount += $oDiscount->dDiscount;
03070 } else {
03071 $aDiscounts[$sKey] = $oDiscount;
03072 }
03073 }
03074 return $aDiscounts;
03075 }
03076
03082 protected function _getGroupPrice()
03083 {
03084 $sPriceSufix = $this->_getUserPriceSufix();
03085 $sVarName = oxarticles__oxprice.$sPriceSufix;
03086 $dPrice = $this->$sVarName->value;
03087
03088
03089 if ( $this->getConfig()->getConfigParam( 'blOverrideZeroABCPrices' ) && (double) $dPrice == 0 ) {
03090 $dPrice = $this->oxarticles__oxprice->value;
03091 }
03092
03093 return $dPrice;
03094 }
03095
03104 protected function _getAmountPrice($dAmount = 1)
03105 {
03106 $myConfig = $this->getConfig();
03107
03108 startProfile( "_getAmountPrice" );
03109
03110 $dPrice = $this->_getGroupPrice();
03111 $oAmtPrices = $this->_getAmountPriceList();
03112 foreach ($oAmtPrices as $oAmPrice) {
03113 if ($oAmPrice->oxprice2article__oxamount->value <= $dAmount
03114 && $dAmount <= $oAmPrice->oxprice2article__oxamountto->value
03115 && $dPrice > $oAmPrice->oxprice2article__oxaddabs->value ) {
03116 $dPrice = $oAmPrice->oxprice2article__oxaddabs->value;
03117 }
03118 }
03119
03120 stopProfile( "_getAmountPrice" );
03121 return $dPrice;
03122 }
03123
03132 protected function _modifySelectListPrice( $dPrice, $aChosenList = null )
03133 {
03134 $myConfig = $this->getConfig();
03135
03136 if ( $myConfig->getConfigParam( 'bl_perfLoadSelectLists' ) && $myConfig->getConfigParam( 'bl_perfUseSelectlistPrice' ) ) {
03137
03138 $aSelLists = $this->getSelectLists();
03139
03140 foreach ( $aSelLists as $key => $aSel) {
03141 if ( isset( $aChosenList[$key]) && isset($aSel[$aChosenList[$key]] ) ) {
03142 $oSel = $aSel[$aChosenList[$key]];
03143 if ( $oSel->priceUnit =='abs' ) {
03144 $dPrice += $oSel->price;
03145 } elseif ( $oSel->priceUnit =='%' ) {
03146 $dPrice += oxPrice::percent( $dPrice, $oSel->price );
03147 }
03148 }
03149 }
03150 }
03151 return $dPrice;
03152 }
03153
03154
03162 protected function _fillAmountPriceList($oAmPriceList)
03163 {
03164 $myConfig = $this->getConfig();
03165 $oLang = oxRegistry::getLang();
03166
03167
03168 foreach ($oAmPriceList as $sId => $oItem) {
03169
03170 $oItemPrice = $this->_getPriceObject();
03171 if ( $oItem->oxprice2article__oxaddabs->value ) {
03172
03173 $dBasePrice = $oItem->oxprice2article__oxaddabs->value;
03174 $dBasePrice = $this->_preparePrice( $dBasePrice, $this->getArticleVat() );
03175
03176 $oItemPrice->setPrice( $dBasePrice );
03177 $this->_calculatePrice( $oItemPrice );
03178
03179 } else {
03180 $dBasePrice = $this->_getGroupPrice();
03181 $dBasePrice = $this->_preparePrice( $dBasePrice, $this->getArticleVat() );
03182 $oItemPrice->setPrice( $dBasePrice );
03183 $oItemPrice->subtractPercent( $oItem->oxprice2article__oxaddperc->value );
03184 }
03185
03186
03187 $oAmPriceList[$sId]->fbrutprice = $oLang->formatCurrency( $this->_getPriceForView( $oItemPrice ) );
03188 }
03189
03190 return $oAmPriceList;
03191 }
03192
03193
03199 protected function _getVariantsIds()
03200 {
03201 $aSelect = array();
03202 if ( ( $sId = $this->getId() ) ) {
03203 $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
03204 $sQ = "select oxid from " . $this->getViewName( true ) . " where oxparentid = ".$oDb->quote( $sId )." and " .
03205 $this->getSqlActiveSnippet( true ) . " order by oxsort";
03206 $oRs = $oDb->select( $sQ );
03207 if ( $oRs != false && $oRs->recordCount() > 0 ) {
03208 while (!$oRs->EOF) {
03209 $aSelect[] = reset( $oRs->fields );
03210 $oRs->moveNext();
03211 }
03212 }
03213 }
03214 return $aSelect;
03215 }
03216
03222 public function getArticleVat()
03223 {
03224 if (!isset($this->_dArticleVat)) {
03225 $this->_dArticleVat = oxRegistry::get("oxVatSelector")->getArticleVat( $this );
03226 }
03227 return $this->_dArticleVat;
03228 }
03229
03238 protected function _applyVAT( oxPrice $oPrice, $dVat )
03239 {
03240 startProfile(__FUNCTION__);
03241 $oPrice->setVAT( $dVat );
03242 if ( ($dVat = oxRegistry::get("oxVatSelector")->getArticleUserVat($this)) !== false ) {
03243 $oPrice->setUserVat( $dVat );
03244 }
03245 stopProfile(__FUNCTION__);
03246 }
03247
03255 public function applyVats( oxPrice $oPrice )
03256 {
03257 $this->_applyVAT($oPrice, $this->getArticleVat() );
03258 }
03259
03267 public function applyDiscountsForVariant( $oPrice )
03268 {
03269
03270 if ( !$this->skipDiscounts() ) {
03271 $oDiscountList = oxRegistry::get("oxDiscountList");
03272 $aDiscounts = $oDiscountList->getArticleDiscounts( $this, $this->getArticleUser() );
03273
03274 reset( $aDiscounts );
03275 foreach ( $aDiscounts as $oDiscount ) {
03276 $oPrice->setDiscount($oDiscount->getAddSum(), $oDiscount->getAddSumType());
03277 }
03278 $oPrice->calculateDiscount();
03279 }
03280 }
03281
03290 protected function _applyCurrency(oxPrice $oPrice, $oCur = null )
03291 {
03292 if ( !$oCur ) {
03293 $oCur = $this->getConfig()->getActShopCurrencyObject();
03294 }
03295
03296 $oPrice->multiply($oCur->rate);
03297 }
03298
03299
03308 protected function _getAttribsString(&$sAttribs, &$iCnt)
03309 {
03310
03311 $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
03312 $sSelect = 'select oxattrid from oxobject2attribute where oxobject2attribute.oxobjectid='.$oDb->quote( $this->getId() );
03313 $sAttribs = '';
03314 $blSep = false;
03315 $rs = $oDb->select( $sSelect);
03316 $iCnt = 0;
03317 if ($rs != false && $rs->recordCount() > 0) {
03318 while (!$rs->EOF) {
03319 if ( $blSep) {
03320 $sAttribs .= ' or ';
03321 }
03322 $sAttribs .= 't1.oxattrid = '.$oDb->quote($rs->fields['oxattrid']).' ';
03323 $blSep = true;
03324 $iCnt++;
03325 $rs->moveNext();
03326 }
03327 }
03328 }
03329
03338 protected function _getSimList($sAttribs, $iCnt)
03339 {
03340 $myConfig = $this->getConfig();
03341 $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
03342
03343
03344 $iAttrPercent = $myConfig->getConfigParam( 'iAttributesPercent' )/100;
03345
03346 if ( !$iAttrPercent || $iAttrPercent < 0 || $iAttrPercent > 1) {
03347 $iAttrPercent = 0.70;
03348 }
03349
03350 $iHitMin = ceil( $iCnt * $iAttrPercent );
03351
03352
03353 $aList= array();
03354 $sSelect = "select oxobjectid, count(*) as cnt from oxobject2attribute as t1 where
03355 ( $sAttribs )
03356 and t1.oxobjectid != ".$oDb->quote( $this->oxarticles__oxid->value )."
03357 group by t1.oxobjectid having count(*) >= $iHitMin ";
03358
03359 $rs = $oDb->selectLimit( $sSelect, 20, 0 );
03360 if ($rs != false && $rs->recordCount() > 0) {
03361 while (!$rs->EOF) {
03362 $oTemp = new stdClass();
03363 $oTemp->cnt = $rs->fields['cnt'];
03364 $oTemp->id = $rs->fields['oxobjectid'];
03365 $aList[] = $oTemp;
03366 $rs->moveNext();
03367 }
03368 }
03369 return $aList;
03370 }
03371
03380 protected function _generateSimListSearchStr($sArticleTable, $aList)
03381 {
03382 $myConfig = $this->getConfig();
03383 $sFieldList = $this->getSelectFields();
03384 $sSearch = "select $sFieldList from $sArticleTable where ".$this->getSqlActiveSnippet()." and $sArticleTable.oxissearch = 1 and $sArticleTable.oxid in ( ";
03385 $blSep = false;
03386 $iCnt = 0;
03387 $oDb = oxDb::getDb();
03388 foreach ( $aList as $oTemp) {
03389 if ( $blSep) {
03390 $sSearch .= ',';
03391 }
03392 $sSearch .= $oDb->quote($oTemp->id);
03393 $blSep = true;
03394 if ( $iCnt >= $myConfig->getConfigParam( 'iNrofSimilarArticles' ) ) {
03395 break;
03396 }
03397 $iCnt++;
03398 }
03399
03400
03401
03402 $sSearch .= ') ';
03403
03404
03405 $sSearch .= ' order by rand() ';
03406
03407 return $sSearch;
03408 }
03409
03418 protected function _generateSearchStr($sOXID, $blSearchPriceCat = false )
03419 {
03420
03421 $sCatView = getViewName( 'oxcategories', $this->getLanguage() );
03422 $sO2CView = getViewName( 'oxobject2category' );
03423
03424
03425 if ( !$blSearchPriceCat ) {
03426 $sSelect = "select {$sCatView}.* from {$sO2CView} as oxobject2category left join {$sCatView} on
03427 {$sCatView}.oxid = oxobject2category.oxcatnid
03428 where oxobject2category.oxobjectid=".oxDb::getDb()->quote($sOXID)." and {$sCatView}.oxid is not null ";
03429 } else {
03430 $sSelect = "select {$sCatView}.* from {$sCatView} where
03431 '{$this->oxarticles__oxprice->value}' >= {$sCatView}.oxpricefrom and
03432 '{$this->oxarticles__oxprice->value}' <= {$sCatView}.oxpriceto ";
03433 }
03434 return $sSelect;
03435 }
03436
03442 protected function _generateSearchStrForCustomerBought()
03443 {
03444 $sArtTable = $this->getViewName();
03445 $sOrderArtTable = getViewName( 'oxorderarticles' );
03446
03447
03448 $sIn = " '{$this->oxarticles__oxid->value}' ";
03449 if ( $this->oxarticles__oxparentid->value ) {
03450
03451
03452 $sIn .= ", '{$this->oxarticles__oxparentid->value}' ";
03453 $sParentIdForVariants = $this->oxarticles__oxparentid->value;
03454
03455 } else {
03456 $sParentIdForVariants = $this->getId();
03457 }
03458
03459
03460 $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
03461 $oRs = $oDb->select( "select oxid from {$sArtTable} where oxparentid = ".$oDb->quote($sParentIdForVariants)." and oxid != ".$oDb->quote($this->oxarticles__oxid->value) );
03462 if ( $oRs != false && $oRs->recordCount() > 0) {
03463 while ( !$oRs->EOF ) {
03464 $sIn .= ", ".$oDb->quote(current( $oRs->fields ))." ";
03465 $oRs->moveNext();
03466 }
03467 }
03468
03469 $iLimit = (int) $this->getConfig()->getConfigParam( 'iNrofCustomerWhoArticles' );
03470 $iLimit = $iLimit?( $iLimit * 10 ): 50;
03471
03472
03473 $sQ = "select distinct {$sArtTable}.* from (
03474 select d.oxorderid as suborderid from {$sOrderArtTable} as d use index ( oxartid ) where d.oxartid in ( {$sIn} ) limit {$iLimit}
03475 ) as suborder
03476 left join {$sOrderArtTable} force index ( oxorderid ) on suborder.suborderid = {$sOrderArtTable}.oxorderid
03477 left join {$sArtTable} on {$sArtTable}.oxid = {$sOrderArtTable}.oxartid
03478 where {$sArtTable}.oxid not in ( {$sIn} )
03479 and ( {$sArtTable}.oxissearch = 1 or {$sArtTable}.oxparentid <> '' ) and ".$this->getSqlActiveSnippet();
03480
03481
03482
03483
03484
03485
03486
03487
03488
03489
03490 return $sQ;
03491 }
03492
03502 protected function _generateSelectCatStr($sOXID, $sCatId, $dPriceFromTo = false)
03503 {
03504 $sCategoryView = getViewName('oxcategories');
03505 $sO2CView = getViewName('oxobject2category');
03506
03507 $oDb = oxDb::getDb();
03508 $sOXID = $oDb->quote($sOXID);
03509 $sCatId = $oDb->quote($sCatId);
03510
03511 if (!$dPriceFromTo) {
03512 $sSelect = "select oxobject2category.oxcatnid from $sO2CView as oxobject2category ";
03513 $sSelect .= "left join $sCategoryView as oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
03514 $sSelect .= "where oxobject2category.oxcatnid=$sCatId and oxobject2category.oxobjectid=$sOXID ";
03515 $sSelect .= "and oxcategories.oxactive = 1 order by oxobject2category.oxtime ";
03516 } else {
03517 $dPriceFromTo = $oDb->quote($dPriceFromTo);
03518 $sSelect = "select oxcategories.oxid from $sCategoryView as oxcategories where ";
03519 $sSelect .= "oxcategories.oxid=$sCatId and $dPriceFromTo >= oxcategories.oxpricefrom and ";
03520 $sSelect .= "$dPriceFromTo <= oxcategories.oxpriceto ";
03521 }
03522 return $sSelect;
03523 }
03524
03530 protected function _getAmountPriceList()
03531 {
03532 if ( $this->_oAmountPriceList === null ) {
03533 $this->_oAmountPriceList = array();
03534 if ( !$this->skipDiscounts() ) {
03535
03536
03537 $oAmPriceList = oxNew( 'oxAmountPricelist' );
03538 $oAmPriceList->load( $this );
03539
03540
03541 $oBasePrice = $this->_getGroupPrice();
03542 foreach ( $oAmPriceList as $oAmPrice ) {
03543 if ( $oAmPrice->oxprice2article__oxaddperc->value ) {
03544 $oAmPrice->oxprice2article__oxaddabs = new oxField(oxPrice::percent( $oBasePrice, 100 - $oAmPrice->oxprice2article__oxaddperc->value ), oxField::T_RAW );
03545 }
03546 }
03547
03548 $this->_oAmountPriceList = $oAmPriceList;
03549 }
03550 }
03551
03552 return $this->_oAmountPriceList;
03553 }
03554
03562 protected function _isFieldEmpty( $sFieldName )
03563 {
03564 $mValue = $this->$sFieldName->value;
03565
03566 if ( is_null( $mValue ) ) {
03567 return true;
03568 }
03569
03570 if ( $mValue === '' ) {
03571 return true;
03572 }
03573
03574
03575 $aZeroValueFields = array('oxarticles__oxprice', 'oxarticles__oxvat', 'oxarticles__oxunitquantity');
03576
03577 if (!$mValue && in_array( $sFieldName, $aZeroValueFields ) ) {
03578 return true;
03579 }
03580
03581
03582 if (!strcmp($mValue, '0000-00-00 00:00:00') || !strcmp($mValue, '0000-00-00')) {
03583 return true;
03584 }
03585
03586 $sFieldName = strtolower($sFieldName);
03587
03588 if ( $sFieldName == 'oxarticles__oxicon' && ( strpos($mValue, "nopic_ico.jpg") !== false || strpos($mValue, "nopic.jpg") !== false ) ) {
03589 return true;
03590 }
03591
03592 if ( strpos($mValue, "nopic.jpg") !== false && ($sFieldName == 'oxarticles__oxthumb' || substr($sFieldName, 0, 17) == 'oxarticles__oxpic' || substr($sFieldName, 0, 18) == 'oxarticles__oxzoom') ) {
03593 return true;
03594 }
03595
03596 return false;
03597 }
03598
03606 protected function _assignParentFieldValue($sFieldName)
03607 {
03608 if (!($oParentArticle = $this->getParentArticle())) {
03609 return;
03610 }
03611
03612 $sCopyFieldName = $this->_getFieldLongName($sFieldName);
03613
03614
03615 if ( $oParentArticle->$sCopyFieldName != null ) {
03616
03617
03618 if ( substr( $sCopyFieldName, 0, 12) != 'oxarticles__') {
03619 return;
03620 }
03621
03622
03623 if (in_array($sCopyFieldName, $this->_aNonCopyParentFields)) {
03624 return;
03625 }
03626
03627
03628
03629 if ( stristr($sCopyFieldName, '_oxthumb') || stristr($sCopyFieldName, '_oxicon') ) {
03630 if ( $this->_isFieldEmpty( $sCopyFieldName ) && !$this->_hasMasterImage( 1 ) ) {
03631 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03632 }
03633 } elseif ( stristr($sCopyFieldName, '_oxzoom') ) {
03634
03635
03636 $iIndex = (int) str_ireplace( "oxarticles__oxzoom", "", $sFieldName );
03637 if ( $this->_isFieldEmpty( $sCopyFieldName ) && !$this->_hasMasterImage( $iIndex ) && !$this->_hasMasterImage( 1 ) ) {
03638 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03639 }
03640 } elseif ( stristr($sCopyFieldName, '_oxpicsgenerated') && $this->{$sCopyFieldName}->value == 0 ) {
03641
03642 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03643 } elseif ($this->_isFieldEmpty($sCopyFieldName) || in_array( $sCopyFieldName, $this->_aCopyParentField ) ) {
03644 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03645 }
03646 }
03647 }
03648
03654 public function getParentArticle()
03655 {
03656 if ( ( $sParentId = $this->oxarticles__oxparentid->value ) ) {
03657 $sIndex = $sParentId . "_" . $this->getLanguage();
03658 if ( !isset( self::$_aLoadedParents[$sIndex] ) ) {
03659 self::$_aLoadedParents[$sIndex] = oxNew( 'oxarticle' );
03660
03661 self::$_aLoadedParents[$sIndex]->_blLoadPrice = false;
03662 self::$_aLoadedParents[$sIndex]->_blLoadVariants = false;
03663 self::$_aLoadedParents[$sIndex]->loadInLang( $this->getLanguage(), $sParentId );
03664 }
03665 return self::$_aLoadedParents[$sIndex];
03666 }
03667 }
03668
03674 protected function _assignParentFieldValues()
03675 {
03676 startProfile('articleAssignParentInternal');
03677 if ( $this->oxarticles__oxparentid->value ) {
03678
03679 if ( !$this->isAdmin() || ( $this->_blLoadParentData && $this->isAdmin() ) ) {
03680 foreach ( $this->_aFieldNames as $sFieldName => $sVal ) {
03681 $this->_assignParentFieldValue( $sFieldName );
03682 }
03683 }
03684 }
03685 stopProfile('articleAssignParentInternal');
03686 }
03687
03693 protected function _assignNotBuyableParent()
03694 {
03695 if ( !$this->getConfig()->getConfigParam( 'blVariantParentBuyable' ) &&
03696 ($this->_blHasVariants || $this->oxarticles__oxvarstock->value || $this->oxarticles__oxvarcount->value )) {
03697 $this->_blNotBuyableParent = true;
03698
03699 }
03700 }
03701
03707 protected function _assignStock()
03708 {
03709 $myConfig = $this->getConfig();
03710
03711
03712
03713
03714
03715 if (!$myConfig->getConfigParam( 'blAllowUnevenAmounts' ) && !$this->isAdmin() ) {
03716 $this->oxarticles__oxstock = new oxField((int) floor($this->oxarticles__oxstock->value));
03717 }
03718
03719 $this->_iStockStatus = 0;
03720
03721
03722 if ( $myConfig->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstockflag->value != 4) {
03723
03724 $iStock = $this->oxarticles__oxstock->value;
03725
03726 if ($this->_blNotBuyableParent) {
03727 $iStock = $this->oxarticles__oxvarstock->value;
03728 }
03729
03730
03731 if ( $iStock <= $myConfig->getConfigParam( 'sStockWarningLimit' ) && $iStock > 0) {
03732 $this->_iStockStatus = 1;
03733 }
03734
03735
03736 if ($iStock <= 0) {
03737 $this->_iStockStatus = -1;
03738 }
03739 }
03740
03741
03742
03743 if ( $myConfig->getConfigParam( 'blUseStock' ) && ($this->oxarticles__oxstockflag->value == 3 || $this->oxarticles__oxstockflag->value == 2)) {
03744 $iOnStock = $this->oxarticles__oxstock->value;
03745 if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
03746 $iOnStock += $this->getSession()->getBasketReservations()->getReservedAmount($this->getId());
03747 }
03748 if ($iOnStock <= 0) {
03749 $this->setBuyableState( false );
03750 }
03751 }
03752
03753
03754 if ($this->_blNotBuyable && $this->oxarticles__oxvarstock->value ) {
03755 $this->setBuyableState( true );
03756
03757 $this->_blNotBuyableParent = true;
03758 }
03759
03760
03761
03762
03763 if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && !$myConfig->getConfigParam( 'blLoadVariants' ) && $this->oxarticles__oxvarstock->value) {
03764 $this->setBuyableState( false );
03765 }
03766
03767
03768 if (!$this->_blNotBuyable && $this->_blNotBuyableParent && $this->oxarticles__oxvarcount->value == 0) {
03769 $this->setBuyableState( false );
03770 }
03771 }
03772
03780 protected function _assignPrices()
03781 {
03782 $myConfig = $this->getConfig();
03783
03784
03785 if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
03786 return;
03787 }
03788
03789
03790 if ( $this->_hasAnyVariant() ) {
03791 $this->_applyRangePrice();
03792 }
03793 }
03794
03800 protected function _assignPersistentParam()
03801 {
03802
03803 $aPersParam = oxSession::getVar( 'persparam');
03804 if ( isset( $aPersParam) && isset( $aPersParam[$this->getId()])) {
03805 $this->_aPersistParam = $aPersParam[$this->getId()];
03806 }
03807 }
03808
03814 protected function _assignDynImageDir()
03815 {
03816 $myConfig = $this->getConfig();
03817
03818 $sThisShop = $this->oxarticles__oxshopid->value;
03819
03820 $this->_sDynImageDir = $myConfig->getPictureUrl( null, false );
03821 $this->dabsimagedir = $myConfig->getPictureDir( false );
03822 $this->nossl_dimagedir = $myConfig->getPictureUrl( null, false, false, null, $sThisShop );
03823 $this->ssl_dimagedir = $myConfig->getPictureUrl( null, false, true, null, $sThisShop );
03824 }
03825
03831 protected function _assignComparisonListFlag()
03832 {
03833
03834
03835 $aItems = oxSession::getVar('aFiltcompproducts');
03836 if ( isset( $aItems[$this->getId()])) {
03837 $this->_blIsOnComparisonList = true;
03838 }
03839 }
03840
03841
03849 protected function _insert()
03850 {
03851
03852 $sNow = date('Y-m-d H:i:s', oxRegistry::get("oxUtilsDate")->getTime());
03853 $this->oxarticles__oxinsert = new oxField( $sNow );
03854 if ( !is_object($this->oxarticles__oxsubclass) || $this->oxarticles__oxsubclass->value == '') {
03855 $this->oxarticles__oxsubclass = new oxField('oxarticle');
03856 }
03857
03858 return parent::_insert();
03859 }
03860
03866 protected function _update()
03867 {
03868
03869 $this->_skipSaveFields();
03870
03871 $myConfig = $this->getConfig();
03872
03873
03874 $blRes = parent::_update();
03875
03876
03877 return $blRes;
03878 }
03879
03885 public function updateVariantsRemind()
03886 {
03887
03888 if ( !$this->isVariant() && $this->_hasAnyVariant()) {
03889 $oDb = oxDb::getDb();
03890 $sOxId = $oDb->quote($this->getId());
03891 $sOxShopId = $oDb->quote($this->getShopId());
03892 $iRemindActive = $oDb->quote($this->oxarticles__oxremindactive->value);
03893 $sUpdate = "
03894 update oxarticles
03895 set oxremindactive = $iRemindActive
03896 where oxparentid = $sOxId and
03897 oxshopid = $sOxShopId
03898 ";
03899 $oDb->execute( $sUpdate );
03900 }
03901 }
03902
03910 protected function _deleteRecords($sOXID)
03911 {
03912 $oDb = oxDb::getDb();
03913
03914 $sOXID = $oDb->quote($sOXID);
03915
03916
03917 $sDelete = 'delete from oxobject2article where oxarticlenid = '.$sOXID.' or oxobjectid = '.$sOXID.' ';
03918 $oDb->execute( $sDelete);
03919
03920 $sDelete = 'delete from oxobject2attribute where oxobjectid = '.$sOXID.' ';
03921 $oDb->execute( $sDelete);
03922
03923 $sDelete = 'delete from oxobject2category where oxobjectid = '.$sOXID.' ';
03924 $oDb->execute( $sDelete);
03925
03926 $sDelete = 'delete from oxobject2selectlist where oxobjectid = '.$sOXID.' ';
03927 $oDb->execute( $sDelete);
03928
03929 $sDelete = 'delete from oxprice2article where oxartid = '.$sOXID.' ';
03930 $oDb->execute( $sDelete);
03931
03932 $sDelete = 'delete from oxreviews where oxtype="oxarticle" and oxobjectid = '.$sOXID.' ';
03933 $oDb->execute( $sDelete);
03934
03935 $sDelete = 'delete from oxratings where oxobjectid = '.$sOXID.' ';
03936 $rs = $oDb->execute( $sDelete );
03937
03938 $sDelete = 'delete from oxaccessoire2article where oxobjectid = '.$sOXID.' or oxarticlenid = '.$sOXID.' ';
03939 $oDb->execute( $sDelete);
03940
03941
03942 $sDelete = 'delete from oxobject2delivery where oxobjectid = '.$sOXID.' and oxtype=\'oxarticles\' ';
03943 $oDb->execute( $sDelete);
03944
03945 $sDelete = 'delete from oxartextends where oxid = '.$sOXID.' ';
03946 $oDb->execute( $sDelete);
03947
03948
03949 foreach ( $this->_getLanguageSetTables( "oxartextends" ) as $sSetTbl ) {
03950 $oDb->execute( "delete from $sSetTbl where oxid = {$sOXID}" );
03951 }
03952
03953 $sDelete = 'delete from oxactions2article where oxartid = '.$sOXID.' ';
03954 $rs = $oDb->execute( $sDelete );
03955
03956 $sDelete = 'delete from oxobject2list where oxobjectid = '.$sOXID.' ';
03957 $rs = $oDb->execute( $sDelete );
03958
03959
03960 return $rs;
03961 }
03962
03970 protected function _deleteVariantRecords( $sOXID )
03971 {
03972 if ( $sOXID ) {
03973 $oDb = oxDb::getDb();
03974
03975 $sQ = 'select oxid from '.$this->getViewName().' where oxparentid = '.$oDb->quote( $sOXID );
03976 $rs = $oDb->select( $sQ, false, false );
03977 $oArticle = oxNew("oxArticle");
03978 if ($rs != false && $rs->recordCount() > 0) {
03979 while (!$rs->EOF) {
03980 $oArticle->setId($rs->fields[0]);
03981 $oArticle->delete();
03982 $rs->moveNext();
03983 }
03984 }
03985 }
03986 }
03987
03993 protected function _deletePics()
03994 {
03995 $myUtilsPic = oxRegistry::get("oxUtilsPic");
03996 $myConfig = $this->getConfig();
03997 $oPictureHandler = oxRegistry::get("oxPictureHandler");
03998
03999
04000 $oPictureHandler->deleteMainIcon( $this );
04001
04002
04003 $oPictureHandler->deleteThumbnail( $this );
04004
04005 $sAbsDynImageDir = $myConfig->getPictureDir(false);
04006
04007
04008 $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
04009 for ( $i = 1; $i <= $iPicCount; $i++ ) {
04010 $oPictureHandler->deleteArticleMasterPicture( $this, $i );
04011 }
04012 }
04013
04023 protected function _onChangeResetCounts( $sOxid, $sVendorId = null, $sManufacturerId = null )
04024 {
04025
04026 $myUtilsCount = oxRegistry::get("oxUtilsCount");
04027
04028 if ( $sVendorId ) {
04029 $myUtilsCount->resetVendorArticleCount( $sVendorId );
04030 }
04031
04032 if ( $sManufacturerId ) {
04033 $myUtilsCount->resetManufacturerArticleCount( $sManufacturerId );
04034 }
04035
04036
04037 $oDb = oxDb::getDb();
04038 $sQ = "select oxcatnid from oxobject2category where oxobjectid = ".$oDb->quote($sOxid);
04039 $oRs = $oDb->select( $sQ, false, false );
04040 if ( $oRs !== false && $oRs->recordCount() > 0) {
04041 while ( !$oRs->EOF ) {
04042 $myUtilsCount->resetCatArticleCount( $oRs->fields[0] );
04043 $oRs->moveNext();
04044 }
04045 }
04046 }
04047
04055 protected function _onChangeUpdateStock( $sParentID )
04056 {
04057 if ( $sParentID ) {
04058 $oDb = oxDb::getDb();
04059 $sParentIdQuoted = $oDb->quote($sParentID);
04060 $sQ = 'select oxstock, oxvendorid, oxmanufacturerid from oxarticles where oxid = '.$sParentIdQuoted;
04061 $rs = $oDb->select( $sQ, false, false );
04062 $iOldStock = $rs->fields[0];
04063 $iVendorID = $rs->fields[1];
04064 $iManufacturerID = $rs->fields[2];
04065
04066 $sQ = 'select sum(oxstock) from '.$this->getViewName(true).' where oxparentid = '.$sParentIdQuoted.' and '. $this->getSqlActiveSnippet( true ).' and oxstock > 0 ';
04067 $iStock = (float) $oDb->getOne( $sQ, false, false );
04068
04069 $sQ = 'update oxarticles set oxvarstock = '.$iStock.' where oxid = '.$sParentIdQuoted;
04070 $oDb->execute( $sQ );
04071
04072
04073
04074 if ( $iStock < 0 ) {
04075 $iStock = 0;
04076 }
04077 if ( $iOldStock < 0 ) {
04078 $iOldStock = 0;
04079 }
04080 if ( $this->oxarticles__oxstockflag->value == 2 && $iOldStock xor $iStock ) {
04081
04082
04083 $this->_onChangeResetCounts( $sParentID, $iVendorID, $iManufacturerID );
04084 }
04085 }
04086 }
04087
04095 protected function _onChangeStockResetCount( $sOxid )
04096 {
04097 $myConfig = $this->getConfig();
04098
04099 if ( $myConfig->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstockflag->value == 2 &&
04100 ( $this->oxarticles__oxstock->value + $this->oxarticles__oxvarstock->value ) <= 0 ) {
04101
04102 $this->_onChangeResetCounts( $sOxid, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
04103 }
04104 }
04105
04113 protected function _onChangeUpdateVarCount( $sParentID )
04114 {
04115 if ( $sParentID ) {
04116 $oDb = oxDb::getDb();
04117 $sParentIdQuoted = $oDb->quote( $sParentID );
04118 $sQ = "select count(*) as varcount from oxarticles where oxparentid = {$sParentIdQuoted}";
04119 $iVarCount = (int) $oDb->getOne( $sQ, false, false );
04120
04121 $sQ = "update oxarticles set oxvarcount = {$iVarCount} where oxid = {$sParentIdQuoted}";
04122 $oDb->execute( $sQ );
04123 }
04124 }
04125
04133 protected function _setVarMinMaxPrice( $sParentId )
04134 {
04135 if ( $sParentId ) {
04136 $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
04137 $sQ = '
04138 SELECT
04139 MIN( IF( `oxarticles`.`oxprice` > 0, `oxarticles`.`oxprice`, `p`.`oxprice` ) ) AS `varminprice`,
04140 MAX( IF( `oxarticles`.`oxprice` > 0, `oxarticles`.`oxprice`, `p`.`oxprice` ) ) AS `varmaxprice`
04141 FROM '. $this->getViewName(true) . ' AS `oxarticles`
04142 LEFT JOIN '. $this->getViewName(true) . ' AS `p` ON ( `p`.`oxid` = `oxarticles`.`oxparentid` AND `p`.`oxprice` > 0 )
04143 WHERE '. $this->getSqlActiveSnippet(true) .'
04144 AND ( `oxarticles`.`oxparentid` = '. $oDb->quote( $sParentId ) .' )';
04145 $oDb->setFetchMode( oxDb::FETCH_MODE_ASSOC );
04146 $aPrices = $oDb->getRow( $sQ, false, false );
04147 if ( !is_null( $aPrices['varminprice'] ) || !is_null( $aPrices['varmaxprice'] ) ) {
04148 $sQ = '
04149 UPDATE `oxarticles`
04150 SET
04151 `oxvarminprice` = '. $oDb->quote( $aPrices['varminprice'] ) .',
04152 `oxvarmaxprice` = '. $oDb->quote( $aPrices['varmaxprice'] ) .'
04153 WHERE
04154 `oxid` = ' . $oDb->quote( $sParentId );
04155 } else {
04156 $sQ = '
04157 UPDATE `oxarticles`
04158 SET
04159 `oxvarminprice` = `oxprice`,
04160 `oxvarmaxprice` = `oxprice`
04161 WHERE
04162 `oxid` = ' . $oDb->quote( $sParentId );
04163 }
04164 $oDb->execute( $sQ );
04165 }
04166 }
04167
04168
04178 protected function _onChangeUpdateMinVarPrice( $sParentID )
04179 {
04180 if ( $sParentID ) {
04181 $oDb = oxDb::getDb();
04182 $sParentIdQuoted = $oDb->quote($sParentID);
04183
04184 $sQ = 'select min(oxprice) as varminprice from '.$this->getViewName(true).' where '.$this->getSqlActiveSnippet(true).' and (oxparentid = '.$sParentIdQuoted.')';
04185 $dVarMinPrice = $oDb->getOne( $sQ, false, false );
04186
04187 $dParentPrice = $oDb->getOne( "select oxprice from oxarticles where oxid = $sParentIdQuoted ", false, false );
04188
04189 $blParentBuyable = $this->getConfig()->getConfigParam( 'blVariantParentBuyable' );
04190
04191 if ($dVarMinPrice) {
04192 if ($blParentBuyable) {
04193 $dVarMinPrice = min($dVarMinPrice, $dParentPrice);
04194 }
04195 } else {
04196 $dVarMinPrice = $dParentPrice;
04197 }
04198
04199 if ( $dVarMinPrice ) {
04200 $sQ = 'update oxarticles set oxvarminprice = '.$dVarMinPrice.' where oxid = '.$sParentIdQuoted;
04201 $oDb->execute($sQ);
04202 }
04203 }
04204 }
04205
04206
04214 protected function _applyRangePrice()
04215 {
04216
04217 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
04218 return;
04219 }
04220
04221 $this->_blIsRangePrice = false;
04222
04223
04224 if ($this->_blSkipFromPrice || !$this->_blNotBuyableParent) {
04225 return;
04226 }
04227
04228 if ( $this->isParentNotBuyable() && !$this->getConfig()->getConfigParam( 'blLoadVariants' )) {
04229
04230 $dPrice = $this->_preparePrice( $this->oxarticles__oxvarminprice->value, $this->getArticleVat() );
04231 $this->getPrice()->setPrice($dPrice);
04232 $this->_blIsRangePrice = true;
04233 $this->_calculatePrice( $this->getPrice() );
04234 return;
04235
04236 }
04237
04238 $aPrices = array();
04239
04240 if (!$this->_blNotBuyableParent) {
04241 $aPrices[] = $this->getPrice()->getPrice();
04242 }
04243
04244 $aVariants = $this->getVariants(false);
04245
04246 if (count($aVariants)) {
04247 foreach ($aVariants as $sKey => $oVariant) {
04248 $aPrices[] = $oVariant->getPrice()->getPrice();
04249 }
04250 }
04251
04252 if ( count( $aPrices ) ) {
04253 $dMinPrice = min( $aPrices );
04254 $dMaxPrice = max( $aPrices );
04255 }
04256
04257 if ($this->_blNotBuyableParent && isset($dMinPrice) && $dMinPrice == $dMaxPrice) {
04258 $this->getPrice()->setPrice($dMinPrice);
04259 }
04260
04261 if (isset($dMinPrice) && $dMinPrice != $dMaxPrice) {
04262 $this->getPrice()->setPrice($dMinPrice);
04263 $this->_blIsRangePrice = true;
04264 }
04265 }
04266
04273 public function getProductId()
04274 {
04275 return $this->getId();
04276 }
04277
04285 public function getProductParentId()
04286 {
04287 return $this->getParentId();
04288 }
04289
04295 public function getParentId()
04296 {
04297 return $this->oxarticles__oxparentid->value;
04298 }
04299
04305 public function isOrderArticle()
04306 {
04307 return false;
04308 }
04309
04315 public function isVariant()
04316 {
04317 return (bool) ( isset( $this->oxarticles__oxparentid ) ? $this->oxarticles__oxparentid->value : false );
04318 }
04319
04325 public function isMdVariant()
04326 {
04327 $oMdVariant = oxNew( "oxVariantHandler" );
04328
04329 return $oMdVariant->isMdVariant($this);
04330 }
04331
04339 public function getSqlForPriceCategories($sFields = '')
04340 {
04341 if (!$sFields) {
04342 $sFields = 'oxid';
04343 }
04344 $sSelectWhere = "select $sFields from ".$this->_getObjectViewName('oxcategories')." where";
04345 $sQuotedPrice = oxDb::getDb()->quote( $this->oxarticles__oxprice->value );
04346 return "$sSelectWhere oxpricefrom != 0 and oxpriceto != 0 and oxpricefrom <= $sQuotedPrice and oxpriceto >= $sQuotedPrice"
04347 ." union $sSelectWhere oxpricefrom != 0 and oxpriceto = 0 and oxpricefrom <= $sQuotedPrice"
04348 ." union $sSelectWhere oxpricefrom = 0 and oxpriceto != 0 and oxpriceto >= $sQuotedPrice";
04349 }
04350
04358 public function inPriceCategory( $sCatNid )
04359 {
04360 $oDb = oxDb::getDb();
04361
04362 $sQuotedPrice = $oDb->quote( $this->oxarticles__oxprice->value );
04363 $sQuotedCnid = $oDb->quote( $sCatNid );
04364 return (bool) $oDb->getOne(
04365 "select 1 from ".$this->_getObjectViewName('oxcategories')." where oxid=$sQuotedCnid and"
04366 ."( (oxpricefrom != 0 and oxpriceto != 0 and oxpricefrom <= $sQuotedPrice and oxpriceto >= $sQuotedPrice)"
04367 ." or (oxpricefrom != 0 and oxpriceto = 0 and oxpricefrom <= $sQuotedPrice)"
04368 ." or (oxpricefrom = 0 and oxpriceto != 0 and oxpriceto >= $sQuotedPrice)"
04369 .")"
04370 );
04371 }
04372
04378 public function getMdVariants()
04379 {
04380 if ( $this->_oMdVariants ) {
04381 return $this->_oMdVariants;
04382 }
04383
04384 $oParentArticle = $this->getParentArticle();
04385 if ( $oParentArticle ) {
04386 $oVariants = $oParentArticle->getVariants();
04387 } else {
04388 $oVariants = $this->getVariants();
04389 }
04390
04391 $oVariantHandler = oxNew( "oxVariantHandler" );
04392 $this->_oMdVariants = $oVariantHandler->buildMdVariants( $oVariants, $this->getId() );
04393
04394 return $this->_oMdVariants;
04395 }
04396
04402 public function getMdSubvariants()
04403 {
04404 return $this->getMdVariants()->getMdSubvariants();
04405 }
04406
04414 protected function _hasMasterImage( $iIndex )
04415 {
04416 $sPicName = basename($this->{"oxarticles__oxpic" . $iIndex}->value);
04417
04418 if ( $sPicName == "nopic.jpg" || $sPicName == "" ) {
04419 return false;
04420 }
04421 if ( $this->isVariant() && $this->getParentArticle()->{"oxarticles__oxpic".$iIndex}->value == $this->{"oxarticles__oxpic".$iIndex}->value ) {
04422 return false;
04423 }
04424
04425 $sMasterPic = 'product/'.$iIndex . "/" . $sPicName;
04426
04427 if ( $this->getConfig()->getMasterPicturePath( $sMasterPic ) ) {
04428 return true;
04429 }
04430
04431 return false;
04432 }
04433
04442 public function getPictureFieldValue( $sFieldName, $iIndex = null )
04443 {
04444 if ( $sFieldName ) {
04445 $sFieldName = "oxarticles__" . $sFieldName . $iIndex;
04446 return $this->$sFieldName->value;
04447 }
04448 }
04449
04457 public function getMasterZoomPictureUrl( $iIndex )
04458 {
04459 $sPicUrl = false;
04460 $sPicName = basename( $this->{"oxarticles__oxpic" . $iIndex}->value );
04461
04462 if ( $sPicName && $sPicName != "nopic.jpg" ) {
04463 $sPicUrl = $this->getConfig()->getPictureUrl( "master/product/" . $iIndex . "/" . $sPicName );
04464 if ( !$sPicUrl || basename( $sPicUrl ) == "nopic.jpg" ) {
04465 $sPicUrl = false;
04466 }
04467 }
04468
04469 return $sPicUrl;
04470 }
04471
04477 public function getUnitName()
04478 {
04479 if ( $this->oxarticles__oxunitname->value ) {
04480 return oxRegistry::getLang()->translateString( $this->oxarticles__oxunitname->value );
04481 }
04482 }
04483
04491 public function getArticleFiles( $blAddFromParent=false )
04492 {
04493 if ( $this->_aArticleFiles === null) {
04494
04495 $this->_aArticleFiles = false;
04496
04497 $sQ = "SELECT * FROM `oxfiles` WHERE `oxartid` = '".$this->getId()."'";
04498
04499 if ( !$this->getConfig()->getConfigParam( 'blVariantParentBuyable' ) && $blAddFromParent ) {
04500 $sQ .= " OR `oxartId` = '". $this->oxarticles__oxparentid->value . "'";
04501 }
04502
04503 $oArticleFiles = oxNew("oxlist");
04504 $oArticleFiles->init("oxfile");
04505 $oArticleFiles->selectString( $sQ );
04506 $this->_aArticleFiles = $oArticleFiles;
04507
04508 }
04509
04510 return $this->_aArticleFiles;
04511 }
04512
04518 public function isDownloadable()
04519 {
04520 return $this->oxarticles__oxisdownloadable->value;
04521 }
04522
04528 public function hasAmountPrice()
04529 {
04530 if ( self::$_blHasAmountPrice === null ) {
04531
04532 self::$_blHasAmountPrice = false;
04533
04534 $oDb = oxDb::getDb();
04535 $sQ = "SELECT 1 FROM `oxprice2article` LIMIT 1";
04536
04537 if ( $oDb->getOne( $sQ ) ) {
04538 self::$_blHasAmountPrice = true;
04539 }
04540 }
04541
04542 return self::$_blHasAmountPrice;
04543 }
04544
04545
04551 protected function _isPriceViewModeNetto()
04552 {
04553 $blResult = (bool) $this->getConfig()->getConfigParam('blShowNetPrice');
04554 $oUser = $this->getArticleUser();
04555 if ( $oUser ) {
04556 $blResult = $oUser->isPriceViewModeNetto();
04557 }
04558
04559 return $blResult;
04560 }
04561
04562
04570 protected function _getPriceObject( $blCalculationModeNetto = null )
04571 {
04572 $oPrice = oxNew( 'oxPrice' );
04573
04574 if ( $blCalculationModeNetto === null ) {
04575 $blCalculationModeNetto = $this->_isPriceViewModeNetto();
04576 }
04577
04578 if ( $blCalculationModeNetto ) {
04579 $oPrice->setNettoPriceMode();
04580 } else {
04581 $oPrice->setBruttoPriceMode();
04582 }
04583
04584 return $oPrice;
04585 }
04586
04587
04595 protected function _getPriceForView( $oPrice )
04596 {
04597 if ( $this->_isPriceViewModeNetto() ) {
04598 $dPrice = $oPrice->getNettoPrice();
04599 } else {
04600 $dPrice = $oPrice->getBruttoPrice();
04601 }
04602
04603 return $dPrice;
04604 }
04605
04606
04616 protected function _preparePrice( $dPrice, $dVat, $blCalculationModeNetto = null )
04617 {
04618 if ( $blCalculationModeNetto === null ) {
04619 $blCalculationModeNetto = $this->_isPriceViewModeNetto();
04620 }
04621
04622 $blEnterNetPrice = $this->getConfig()->getConfigParam('blEnterNetPrice');
04623 if ( $blCalculationModeNetto && !$blEnterNetPrice ) {
04624 $dPrice = round( oxPrice::brutto2Netto( $dPrice, $dVat ), 2 );
04625 } elseif ( !$blCalculationModeNetto && $blEnterNetPrice ) {
04626 $dPrice = round( oxPrice::netto2Brutto( $dPrice, $dVat ), 2 );
04627 }
04628
04629 return $dPrice;
04630 }
04631
04632
04638 public function getFUnitPrice()
04639 {
04640 if ($this->_fPricePerUnit == null) {
04641 if ( $oPrice = $this->getUnitPrice() ) {
04642 if ( $dPrice = $this->_getPriceForView( $oPrice ) ) {
04643 $this->_fPricePerUnit = oxRegistry::getLang()->formatCurrency( $dPrice );
04644 }
04645 }
04646 }
04647
04648 return $this->_fPricePerUnit;
04649 }
04650
04651
04657 public function getUnitPrice()
04658 {
04659
04660 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
04661 return;
04662 }
04663
04664 $oPrice = null;
04665 if ( (double) $this->oxarticles__oxunitquantity->value && $this->oxarticles__oxunitname->value ) {
04666 $oPrice = clone $this->getPrice();
04667 $oPrice->divide( (double) $this->oxarticles__oxunitquantity->value );
04668 }
04669
04670 return $oPrice;
04671 }
04672
04673
04679 public function getFMinPrice()
04680 {
04681 $sPrice = '';
04682 if ( $oPrice = $this->getMinPrice() ) {
04683 $dPrice = $this->_getPriceForView( $oPrice );
04684 $sPrice = oxRegistry::getLang()->formatCurrency( $dPrice );
04685 }
04686
04687 return $sPrice;
04688 }
04689
04695 public function getFVarMinPrice()
04696 {
04697 $sPrice = '';
04698 if ( $oPrice = $this->getVarMinPrice() ) {
04699 $dPrice = $this->_getPriceForView( $oPrice );
04700 $sPrice = oxRegistry::getLang()->formatCurrency( $dPrice );
04701 }
04702
04703 return $sPrice;
04704 }
04705
04711 public function getVarMinPrice()
04712 {
04713 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
04714 return;
04715 }
04716
04717 $oPrice = null;
04718 $dPrice = $this->_getVarMinPrice();
04719
04720 $dPrice = $this->_preparePrice( $dPrice, $this->getArticleVat() );
04721
04722
04723 $oPrice = $this->_getPriceObject();
04724 $oPrice->setPrice( $dPrice );
04725 $this->_calculatePrice( $oPrice );
04726
04727
04728 return $oPrice;
04729 }
04730
04731
04737 public function getMinPrice()
04738 {
04739 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
04740 return;
04741 }
04742
04743 $oPrice = null;
04744 $dPrice = $this->_getPrice();
04745 if ( $this->_getVarMinPrice() !== null && $dPrice > $this->_getVarMinPrice() ) {
04746 $dPrice = $this->_getVarMinPrice();
04747 }
04748
04749 $dPrice = $this->_preparePrice( $dPrice, $this->getArticleVat() );
04750
04751
04752 $oPrice = $this->_getPriceObject();
04753 $oPrice->setPrice( $dPrice );
04754 $this->_calculatePrice( $oPrice );
04755
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 }