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
02563 public function getStdTagLink( $sTag )
02564 {
02565 $sStdTagLink = $this->getConfig()->getShopHomeURL( $this->getLanguage(), false );
02566 return $sStdTagLink . "cl=details&anid=".$this->getId()."&listtype=tag&searchtag=".rawurlencode( $sTag );
02567 }
02568
02574 public function getTags()
02575 {
02576 $oDb = oxDb::getDb();
02577 $sViewName = getViewName( "oxartextends", $this->getLanguage() );
02578 $sQ = "select oxtags from {$sViewName} where oxid = ".$oDb->quote( $this->getId() );
02579 $oTagCloud = oxNew('oxtagcloud');
02580 return $oTagCloud->trimTags( $oDb->getOne( $sQ ) );
02581 }
02582
02590 public function saveTags($sTags)
02591 {
02592
02593 if ( !$this->allowDerivedUpdate() ) {
02594 return false;
02595 }
02596
02597
02598 $oTagCloud = oxNew( 'oxtagcloud' );
02599 $oTagCloud->resetTagCache();
02600 $sTags = oxDb::getInstance()->escapeString( $oTagCloud->prepareTags( $sTags ) );
02601 $oDb = oxDb::getDb();
02602
02603 $sTable = getLangTableName( 'oxartextends', $this->getLanguage() );
02604 $sLangSuffix = oxRegistry::getLang()->getLanguageTag($this->getLanguage());
02605 $sQ = "insert into {$sTable} (oxid, oxtags$sLangSuffix) value (".$oDb->quote( $this->getId() ).", '{$sTags}')
02606 on duplicate key update oxtags$sLangSuffix = '{$sTags}'";
02607 return $oDb->execute( $sQ );
02608 }
02609
02617 public function addTag($sTag)
02618 {
02619
02620 $oDb = oxDb::getDb();
02621
02622 $oTagCloud = oxNew('oxtagcloud');
02623 $oTagCloud->resetTagCache();
02624 $sTag = $oTagCloud->prepareTags($sTag);
02625 $sTagSeparator = $this->getConfig()->getConfigParam('sTagSeparator');
02626
02627 $sTable = getLangTableName( 'oxartextends', $this->getLanguage() );
02628 $sLangSuffix = oxRegistry::getLang()->getLanguageTag($this->getLanguage());
02629 if ( $oDb->getOne( "select {$sTable}.OXTAGS$sLangSuffix from {$sTable} where {$sTable}.OXID = ".$oDb->quote( $this->getId() ) ) ) {
02630 $sTailTag = $sTagSeparator . $sTag;
02631 } else {
02632 $sTailTag = $sTag;
02633 }
02634
02635 $sTag = oxDb::getInstance()->escapeString($sTag);
02636 $sTailTag = oxDb::getInstance()->escapeString($sTailTag);
02637
02638 $sTag = oxDb::getInstance()->escapeString($sTag);
02639 $sTailTag = oxDb::getInstance()->escapeString($sTailTag);
02640
02641 $sQ = "insert into {$sTable} ( {$sTable}.OXID, {$sTable}.OXTAGS$sLangSuffix) values (".$oDb->quote( $this->getId() ).", '{$sTag}')
02642 ON DUPLICATE KEY update {$sTable}.OXTAGS$sLangSuffix = CONCAT(TRIM({$sTable}.OXTAGS$sLangSuffix), '$sTailTag') ";
02643
02644 return $oDb->execute( $sQ );
02645 }
02646
02652 public function getMediaUrls()
02653 {
02654 if ( $this->_aMediaUrls === null ) {
02655 $this->_aMediaUrls = oxNew("oxlist");
02656 $this->_aMediaUrls->init("oxmediaurl");
02657 $this->_aMediaUrls->getBaseObject()->setLanguage( $this->getLanguage() );
02658
02659 $sViewName = getViewName( "oxmediaurls", $this->getLanguage() );
02660 $sQ = "select * from {$sViewName} where oxobjectid = '".$this->getId()."'";
02661 $this->_aMediaUrls->selectString($sQ);
02662 }
02663 return $this->_aMediaUrls;
02664 }
02665
02671 public function getDynImageDir()
02672 {
02673 return $this->_sDynImageDir;
02674 }
02675
02681 public function getDispSelList()
02682 {
02683 if ($this->_aDispSelList === null) {
02684 if ( $this->getConfig()->getConfigParam( 'bl_perfLoadSelectLists' ) && $this->getConfig()->getConfigParam( 'bl_perfLoadSelectListsInAList' ) ) {
02685 $this->_aDispSelList = $this->getSelectLists();
02686 }
02687 }
02688 return $this->_aDispSelList;
02689 }
02690
02696 public function getMoreDetailLink()
02697 {
02698 if ( $this->_sMoreDetailLink == null ) {
02699
02700
02701 $this->_sMoreDetailLink = $this->getConfig()->getShopHomeURL() . 'cl=moredetails';
02702
02703
02704 if ( $sActCat = oxConfig::getParameter( 'cnid' ) ) {
02705 $this->_sMoreDetailLink .= '&cnid='.$sActCat;
02706 }
02707 $this->_sMoreDetailLink .= '&anid='.$this->getId();
02708 $this->_sMoreDetailLink = $this->_sMoreDetailLink;
02709 }
02710
02711 return $this->_sMoreDetailLink;
02712 }
02713
02719 public function getToBasketLink()
02720 {
02721 if ( $this->_sToBasketLink == null ) {
02722 $myConfig = $this->getConfig();
02723
02724 if ( oxRegistry::getUtils()->isSearchEngine() ) {
02725 $this->_sToBasketLink = $this->getLink();
02726 } else {
02727
02728 $this->_sToBasketLink = $myConfig->getShopHomeURL();
02729
02730
02731 $sActClass = oxConfig::getParameter( 'cl' );
02732 if ( $sActClass == 'thankyou') {
02733 $sActClass = 'basket';
02734 }
02735 $this->_sToBasketLink .= 'cl='.$sActClass;
02736
02737
02738 if ( $sActCat = oxConfig::getParameter( 'cnid' ) ) {
02739 $this->_sToBasketLink .= '&cnid='.$sActCat;
02740 }
02741
02742 $this->_sToBasketLink .= '&fnc=tobasket&aid='.$this->getId().'&anid='.$this->getId();
02743
02744 if ( $sTpl = basename( oxConfig::getParameter( 'tpl' ) ) ) {
02745 $this->_sToBasketLink .= '&tpl='.$sTpl;
02746 }
02747 }
02748 }
02749
02750 return $this->_sToBasketLink;
02751 }
02752
02758 public function getStockStatus()
02759 {
02760 return $this->_iStockStatus;
02761 }
02762
02768 public function getDeliveryDate()
02769 {
02770 if ( $this->oxarticles__oxdelivery->value != '0000-00-00') {
02771 return oxRegistry::get("oxUtilsDate")->formatDBDate( $this->oxarticles__oxdelivery->value);
02772 }
02773 return false;
02774 }
02775
02781 public function getFTPrice()
02782 {
02783
02784 if ( $oPrice = $this->getTPrice() ) {
02785 if ( $dPrice = $this->_getPriceForView( $oPrice ) ) {
02786 return oxRegistry::getLang()->formatCurrency( $dPrice );
02787 }
02788 }
02789 }
02790
02796 public function getFPrice()
02797 {
02798 if ( $oPrice = $this->getPrice() ) {
02799 $dPrice = $this->_getPriceForView( $oPrice );
02800 return oxRegistry::getLang()->formatCurrency( $dPrice );
02801 }
02802 }
02803
02809 public function getFNetPrice()
02810 {
02811 if ( $oPrice = $this->getPrice() ) {
02812 return oxRegistry::getLang()->formatCurrency( $oPrice->getNettoPrice() );
02813 }
02814 }
02815
02823 public function getPricePerUnit()
02824 {
02825 return $this->getFUnitPrice();
02826 }
02827
02833 public function isParentNotBuyable()
02834 {
02835 return $this->_blNotBuyableParent;
02836 }
02837
02843 public function isNotBuyable()
02844 {
02845 return $this->_blNotBuyable;
02846 }
02847
02855 public function setBuyableState( $blBuyable = false )
02856 {
02857 $this->_blNotBuyable = !$blBuyable;
02858 }
02859
02867 public function setSelectlist( $aSelList )
02868 {
02869 $this->_aDispSelList = $aSelList;
02870 }
02871
02879 public function getPictureUrl( $iIndex = 1 )
02880 {
02881 if ( $iIndex ) {
02882 $sImgName = false;
02883 if ( !$this->_isFieldEmpty( "oxarticles__oxpic".$iIndex ) ) {
02884 $sImgName = basename( $this->{"oxarticles__oxpic$iIndex"}->value );
02885 }
02886
02887 $sSize = $this->getConfig()->getConfigParam( 'aDetailImageSizes' );
02888 return oxRegistry::get("oxPictureHandler")->getProductPicUrl( "product/{$iIndex}/", $sImgName, $sSize, 'oxpic'.$iIndex );
02889 }
02890 }
02891
02900 public function getIconUrl( $iIndex = 0 )
02901 {
02902 $sImgName = false;
02903 $sDirname = "product/1/";
02904 if ( $iIndex && !$this->_isFieldEmpty( "oxarticles__oxpic{$iIndex}" ) ) {
02905 $sImgName = basename( $this->{"oxarticles__oxpic$iIndex"}->value );
02906 $sDirname = "product/{$iIndex}/";
02907 } elseif ( !$this->_isFieldEmpty( "oxarticles__oxicon" ) ) {
02908 $sImgName = basename( $this->oxarticles__oxicon->value );
02909 $sDirname = "product/icon/";
02910 } elseif ( !$this->_isFieldEmpty( "oxarticles__oxpic1" ) ) {
02911 $sImgName = basename( $this->oxarticles__oxpic1->value );
02912 }
02913
02914 $sSize = $this->getConfig()->getConfigParam( 'sIconsize' );
02915 return oxRegistry::get("oxPictureHandler")->getProductPicUrl( $sDirname, $sImgName, $sSize, $iIndex );
02916 }
02917
02925 public function getThumbnailUrl( $bSsl = null )
02926 {
02927 $sImgName = false;
02928 $sDirname = "product/1/";
02929 if ( !$this->_isFieldEmpty( "oxarticles__oxthumb" ) ) {
02930 $sImgName = basename( $this->oxarticles__oxthumb->value );
02931 $sDirname = "product/thumb/";
02932 } elseif ( !$this->_isFieldEmpty( "oxarticles__oxpic1" ) ) {
02933 $sImgName = basename( $this->oxarticles__oxpic1->value );
02934 }
02935
02936 $sSize = $this->getConfig()->getConfigParam( 'sThumbnailsize' );
02937 return oxRegistry::get("oxPictureHandler")->getProductPicUrl( $sDirname, $sImgName, $sSize, 0, $bSsl );
02938 }
02939
02947 public function getZoomPictureUrl( $iIndex = '' )
02948 {
02949 $iIndex = (int) $iIndex;
02950 if ( $iIndex > 0 && !$this->_isFieldEmpty( "oxarticles__oxpic".$iIndex ) ) {
02951 $sImgName = basename( $this->{"oxarticles__oxpic".$iIndex}->value );
02952 $sSize = $this->getConfig()->getConfigParam( "sZoomImageSize" );
02953 return oxRegistry::get("oxPictureHandler")->getProductPicUrl( "product/{$iIndex}/", $sImgName, $sSize, 'oxpic'.$iIndex );
02954 }
02955 }
02956
02962 public function getFileUrl()
02963 {
02964 return $this->getConfig()->getPictureUrl( 'media/' );
02965 }
02966
02974 public function getPriceFromPrefix()
02975 {
02976 $sPricePrefix = '';
02977 if ( $this->_blIsRangePrice) {
02978 $sPricePrefix = oxLang::getInstance()->translateString('PRICE_FROM').' ';
02979 }
02980
02981 return $sPricePrefix;
02982 }
02983
02989 protected function _saveArtLongDesc()
02990 {
02991 $myConfig = $this->getConfig();
02992 $sShopId = $myConfig->getShopID();
02993 if (in_array("oxlongdesc", $this->_aSkipSaveFields)) {
02994 return;
02995 }
02996
02997 if ($this->_blEmployMultilanguage) {
02998 $sValue = $this->getLongDescription()->getRawValue();
02999 if ( $sValue !== null ) {
03000 $oArtExt = oxNew('oxI18n');
03001 $oArtExt->init('oxartextends');
03002 $oArtExt->setLanguage((int) $this->getLanguage());
03003 if (!$oArtExt->load($this->getId())) {
03004 $oArtExt->setId($this->getId());
03005 }
03006 $oArtExt->oxartextends__oxlongdesc = new oxField($sValue, oxField::T_RAW);
03007 $oArtExt->save();
03008 }
03009 } else {
03010 $oArtExt = oxNew('oxI18n');
03011 $oArtExt->setEnableMultilang(false);
03012 $oArtExt->init('oxartextends');
03013 $aObjFields = $oArtExt->_getAllFields(true);
03014 if (!$oArtExt->load($this->getId())) {
03015 $oArtExt->setId($this->getId());
03016 }
03017
03018 foreach ($aObjFields as $sKey => $sValue ) {
03019 if ( preg_match('/^oxlongdesc(_(\d{1,2}))?$/', $sKey) ) {
03020 $sField = $this->_getFieldLongName($sKey);
03021
03022 if (isset($this->$sField)) {
03023 $sLongDesc = null;
03024 if ($this->$sField instanceof oxField) {
03025 $sLongDesc = $this->$sField->getRawValue();
03026 } elseif (is_object($this->$sField)) {
03027 $sLongDesc = $this->$sField->value;
03028 }
03029 if (isset($sLongDesc)) {
03030 $sAEField = $oArtExt->_getFieldLongName($sKey);
03031 $oArtExt->$sAEField = new oxField($sLongDesc, oxField::T_RAW);
03032 }
03033 }
03034 }
03035 }
03036 $oArtExt->save();
03037 }
03038 }
03039
03045 protected function _skipSaveFields()
03046 {
03047 $myConfig = $this->getConfig();
03048
03049 $this->_aSkipSaveFields = array();
03050
03051 $this->_aSkipSaveFields[] = 'oxtimestamp';
03052
03053 $this->_aSkipSaveFields[] = 'oxinsert';
03054
03055 if ( !$this->_blAllowEmptyParentId && (!isset( $this->oxarticles__oxparentid->value) || $this->oxarticles__oxparentid->value == '') ) {
03056 $this->_aSkipSaveFields[] = 'oxparentid';
03057 }
03058
03059 }
03060
03070 protected function _mergeDiscounts( $aDiscounts, $aItemDiscounts)
03071 {
03072 foreach ( $aItemDiscounts as $sKey => $oDiscount ) {
03073
03074 if ( array_key_exists ($sKey, $aDiscounts) ) {
03075 $aDiscounts[$sKey]->dDiscount += $oDiscount->dDiscount;
03076 } else {
03077 $aDiscounts[$sKey] = $oDiscount;
03078 }
03079 }
03080 return $aDiscounts;
03081 }
03082
03088 protected function _getGroupPrice()
03089 {
03090 $sPriceSufix = $this->_getUserPriceSufix();
03091 $sVarName = oxarticles__oxprice.$sPriceSufix;
03092 $dPrice = $this->$sVarName->value;
03093
03094
03095 if ( $this->getConfig()->getConfigParam( 'blOverrideZeroABCPrices' ) && (double) $dPrice == 0 ) {
03096 $dPrice = $this->oxarticles__oxprice->value;
03097 }
03098
03099 return $dPrice;
03100 }
03101
03110 protected function _getAmountPrice($dAmount = 1)
03111 {
03112 $myConfig = $this->getConfig();
03113
03114 startProfile( "_getAmountPrice" );
03115
03116 $dPrice = $this->_getGroupPrice();
03117 $oAmtPrices = $this->_getAmountPriceList();
03118 foreach ($oAmtPrices as $oAmPrice) {
03119 if ($oAmPrice->oxprice2article__oxamount->value <= $dAmount
03120 && $dAmount <= $oAmPrice->oxprice2article__oxamountto->value
03121 && $dPrice > $oAmPrice->oxprice2article__oxaddabs->value ) {
03122 $dPrice = $oAmPrice->oxprice2article__oxaddabs->value;
03123 }
03124 }
03125
03126 stopProfile( "_getAmountPrice" );
03127 return $dPrice;
03128 }
03129
03138 protected function _modifySelectListPrice( $dPrice, $aChosenList = null )
03139 {
03140 $myConfig = $this->getConfig();
03141
03142 if ( $myConfig->getConfigParam( 'bl_perfLoadSelectLists' ) && $myConfig->getConfigParam( 'bl_perfUseSelectlistPrice' ) ) {
03143
03144 $aSelLists = $this->getSelectLists();
03145
03146 foreach ( $aSelLists as $key => $aSel) {
03147 if ( isset( $aChosenList[$key]) && isset($aSel[$aChosenList[$key]] ) ) {
03148 $oSel = $aSel[$aChosenList[$key]];
03149 if ( $oSel->priceUnit =='abs' ) {
03150 $dPrice += $oSel->price;
03151 } elseif ( $oSel->priceUnit =='%' ) {
03152 $dPrice += oxPrice::percent( $dPrice, $oSel->price );
03153 }
03154 }
03155 }
03156 }
03157 return $dPrice;
03158 }
03159
03160
03168 protected function _fillAmountPriceList($oAmPriceList)
03169 {
03170 $myConfig = $this->getConfig();
03171 $oLang = oxRegistry::getLang();
03172
03173
03174 foreach ($oAmPriceList as $sId => $oItem) {
03175
03176 $oItemPrice = $this->_getPriceObject();
03177 if ( $oItem->oxprice2article__oxaddabs->value ) {
03178
03179 $dBasePrice = $oItem->oxprice2article__oxaddabs->value;
03180 $dBasePrice = $this->_preparePrice( $dBasePrice, $this->getArticleVat() );
03181
03182 $oItemPrice->setPrice( $dBasePrice );
03183 $this->_calculatePrice( $oItemPrice );
03184
03185 } else {
03186 $dBasePrice = $this->_getGroupPrice();
03187 $dBasePrice = $this->_preparePrice( $dBasePrice, $this->getArticleVat() );
03188 $oItemPrice->setPrice( $dBasePrice );
03189 $oItemPrice->subtractPercent( $oItem->oxprice2article__oxaddperc->value );
03190 }
03191
03192
03193 $oAmPriceList[$sId]->fbrutprice = $oLang->formatCurrency( $this->_getPriceForView( $oItemPrice ) );
03194 }
03195
03196 return $oAmPriceList;
03197 }
03198
03199
03205 protected function _getVariantsIds()
03206 {
03207 $aSelect = array();
03208 if ( ( $sId = $this->getId() ) ) {
03209 $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
03210 $sQ = "select oxid from " . $this->getViewName( true ) . " where oxparentid = ".$oDb->quote( $sId )." and " .
03211 $this->getSqlActiveSnippet( true ) . " order by oxsort";
03212 $oRs = $oDb->select( $sQ );
03213 if ( $oRs != false && $oRs->recordCount() > 0 ) {
03214 while (!$oRs->EOF) {
03215 $aSelect[] = reset( $oRs->fields );
03216 $oRs->moveNext();
03217 }
03218 }
03219 }
03220 return $aSelect;
03221 }
03222
03228 public function getArticleVat()
03229 {
03230 if (!isset($this->_dArticleVat)) {
03231 $this->_dArticleVat = oxRegistry::get("oxVatSelector")->getArticleVat( $this );
03232 }
03233 return $this->_dArticleVat;
03234 }
03235
03244 protected function _applyVAT( oxPrice $oPrice, $dVat )
03245 {
03246 startProfile(__FUNCTION__);
03247 $oPrice->setVAT( $dVat );
03248 if ( ($dVat = oxRegistry::get("oxVatSelector")->getArticleUserVat($this)) !== false ) {
03249 $oPrice->setUserVat( $dVat );
03250 }
03251 stopProfile(__FUNCTION__);
03252 }
03253
03261 public function applyVats( oxPrice $oPrice )
03262 {
03263 $this->_applyVAT($oPrice, $this->getArticleVat() );
03264 }
03265
03273 public function applyDiscountsForVariant( $oPrice )
03274 {
03275
03276 if ( !$this->skipDiscounts() ) {
03277 $oDiscountList = oxRegistry::get("oxDiscountList");
03278 $aDiscounts = $oDiscountList->getArticleDiscounts( $this, $this->getArticleUser() );
03279
03280 reset( $aDiscounts );
03281 foreach ( $aDiscounts as $oDiscount ) {
03282 $oPrice->setDiscount($oDiscount->getAddSum(), $oDiscount->getAddSumType());
03283 }
03284 $oPrice->calculateDiscount();
03285 }
03286 }
03287
03296 protected function _applyCurrency(oxPrice $oPrice, $oCur = null )
03297 {
03298 if ( !$oCur ) {
03299 $oCur = $this->getConfig()->getActShopCurrencyObject();
03300 }
03301
03302 $oPrice->multiply($oCur->rate);
03303 }
03304
03305
03314 protected function _getAttribsString(&$sAttribs, &$iCnt)
03315 {
03316
03317 $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
03318 $sSelect = 'select oxattrid from oxobject2attribute where oxobject2attribute.oxobjectid='.$oDb->quote( $this->getId() );
03319 $sAttribs = '';
03320 $blSep = false;
03321 $rs = $oDb->select( $sSelect);
03322 $iCnt = 0;
03323 if ($rs != false && $rs->recordCount() > 0) {
03324 while (!$rs->EOF) {
03325 if ( $blSep) {
03326 $sAttribs .= ' or ';
03327 }
03328 $sAttribs .= 't1.oxattrid = '.$oDb->quote($rs->fields['oxattrid']).' ';
03329 $blSep = true;
03330 $iCnt++;
03331 $rs->moveNext();
03332 }
03333 }
03334 }
03335
03344 protected function _getSimList($sAttribs, $iCnt)
03345 {
03346 $myConfig = $this->getConfig();
03347 $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
03348
03349
03350 $iAttrPercent = $myConfig->getConfigParam( 'iAttributesPercent' )/100;
03351
03352 if ( !$iAttrPercent || $iAttrPercent < 0 || $iAttrPercent > 1) {
03353 $iAttrPercent = 0.70;
03354 }
03355
03356 $iHitMin = ceil( $iCnt * $iAttrPercent );
03357
03358
03359 $aList= array();
03360 $sSelect = "select oxobjectid, count(*) as cnt from oxobject2attribute as t1 where
03361 ( $sAttribs )
03362 and t1.oxobjectid != ".$oDb->quote( $this->oxarticles__oxid->value )."
03363 group by t1.oxobjectid having count(*) >= $iHitMin ";
03364
03365 $rs = $oDb->selectLimit( $sSelect, 20, 0 );
03366 if ($rs != false && $rs->recordCount() > 0) {
03367 while (!$rs->EOF) {
03368 $oTemp = new stdClass();
03369 $oTemp->cnt = $rs->fields['cnt'];
03370 $oTemp->id = $rs->fields['oxobjectid'];
03371 $aList[] = $oTemp;
03372 $rs->moveNext();
03373 }
03374 }
03375 return $aList;
03376 }
03377
03386 protected function _generateSimListSearchStr($sArticleTable, $aList)
03387 {
03388 $myConfig = $this->getConfig();
03389 $sFieldList = $this->getSelectFields();
03390 $sSearch = "select $sFieldList from $sArticleTable where ".$this->getSqlActiveSnippet()." and $sArticleTable.oxissearch = 1 and $sArticleTable.oxid in ( ";
03391 $blSep = false;
03392 $iCnt = 0;
03393 $oDb = oxDb::getDb();
03394 foreach ( $aList as $oTemp) {
03395 if ( $blSep) {
03396 $sSearch .= ',';
03397 }
03398 $sSearch .= $oDb->quote($oTemp->id);
03399 $blSep = true;
03400 if ( $iCnt >= $myConfig->getConfigParam( 'iNrofSimilarArticles' ) ) {
03401 break;
03402 }
03403 $iCnt++;
03404 }
03405
03406
03407
03408 $sSearch .= ') ';
03409
03410
03411 $sSearch .= ' order by rand() ';
03412
03413 return $sSearch;
03414 }
03415
03424 protected function _generateSearchStr($sOXID, $blSearchPriceCat = false )
03425 {
03426
03427 $sCatView = getViewName( 'oxcategories', $this->getLanguage() );
03428 $sO2CView = getViewName( 'oxobject2category' );
03429
03430
03431 if ( !$blSearchPriceCat ) {
03432 $sSelect = "select {$sCatView}.* from {$sO2CView} as oxobject2category left join {$sCatView} on
03433 {$sCatView}.oxid = oxobject2category.oxcatnid
03434 where oxobject2category.oxobjectid=".oxDb::getDb()->quote($sOXID)." and {$sCatView}.oxid is not null ";
03435 } else {
03436 $sSelect = "select {$sCatView}.* from {$sCatView} where
03437 '{$this->oxarticles__oxprice->value}' >= {$sCatView}.oxpricefrom and
03438 '{$this->oxarticles__oxprice->value}' <= {$sCatView}.oxpriceto ";
03439 }
03440 return $sSelect;
03441 }
03442
03448 protected function _generateSearchStrForCustomerBought()
03449 {
03450 $sArtTable = $this->getViewName();
03451 $sOrderArtTable = getViewName( 'oxorderarticles' );
03452
03453
03454 $sIn = " '{$this->oxarticles__oxid->value}' ";
03455 if ( $this->oxarticles__oxparentid->value ) {
03456
03457
03458 $sIn .= ", '{$this->oxarticles__oxparentid->value}' ";
03459 $sParentIdForVariants = $this->oxarticles__oxparentid->value;
03460
03461 } else {
03462 $sParentIdForVariants = $this->getId();
03463 }
03464
03465
03466 $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
03467 $oRs = $oDb->select( "select oxid from {$sArtTable} where oxparentid = ".$oDb->quote($sParentIdForVariants)." and oxid != ".$oDb->quote($this->oxarticles__oxid->value) );
03468 if ( $oRs != false && $oRs->recordCount() > 0) {
03469 while ( !$oRs->EOF ) {
03470 $sIn .= ", ".$oDb->quote(current( $oRs->fields ))." ";
03471 $oRs->moveNext();
03472 }
03473 }
03474
03475 $iLimit = (int) $this->getConfig()->getConfigParam( 'iNrofCustomerWhoArticles' );
03476 $iLimit = $iLimit?( $iLimit * 10 ): 50;
03477
03478
03479 $sQ = "select distinct {$sArtTable}.* from (
03480 select d.oxorderid as suborderid from {$sOrderArtTable} as d use index ( oxartid ) where d.oxartid in ( {$sIn} ) limit {$iLimit}
03481 ) as suborder
03482 left join {$sOrderArtTable} force index ( oxorderid ) on suborder.suborderid = {$sOrderArtTable}.oxorderid
03483 left join {$sArtTable} on {$sArtTable}.oxid = {$sOrderArtTable}.oxartid
03484 where {$sArtTable}.oxid not in ( {$sIn} )
03485 and ( {$sArtTable}.oxissearch = 1 or {$sArtTable}.oxparentid <> '' ) and ".$this->getSqlActiveSnippet();
03486
03487
03488
03489
03490
03491
03492
03493
03494
03495
03496 return $sQ;
03497 }
03498
03508 protected function _generateSelectCatStr($sOXID, $sCatId, $dPriceFromTo = false)
03509 {
03510 $sCategoryView = getViewName('oxcategories');
03511 $sO2CView = getViewName('oxobject2category');
03512
03513 $oDb = oxDb::getDb();
03514 $sOXID = $oDb->quote($sOXID);
03515 $sCatId = $oDb->quote($sCatId);
03516
03517 if (!$dPriceFromTo) {
03518 $sSelect = "select oxobject2category.oxcatnid from $sO2CView as oxobject2category ";
03519 $sSelect .= "left join $sCategoryView as oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
03520 $sSelect .= "where oxobject2category.oxcatnid=$sCatId and oxobject2category.oxobjectid=$sOXID ";
03521 $sSelect .= "and oxcategories.oxactive = 1 order by oxobject2category.oxtime ";
03522 } else {
03523 $dPriceFromTo = $oDb->quote($dPriceFromTo);
03524 $sSelect = "select oxcategories.oxid from $sCategoryView as oxcategories where ";
03525 $sSelect .= "oxcategories.oxid=$sCatId and $dPriceFromTo >= oxcategories.oxpricefrom and ";
03526 $sSelect .= "$dPriceFromTo <= oxcategories.oxpriceto ";
03527 }
03528 return $sSelect;
03529 }
03530
03536 protected function _getAmountPriceList()
03537 {
03538 if ( $this->_oAmountPriceList === null ) {
03539 $this->_oAmountPriceList = array();
03540 if ( !$this->skipDiscounts() ) {
03541
03542
03543 $oAmPriceList = oxNew( 'oxAmountPricelist' );
03544 $oAmPriceList->load( $this );
03545
03546
03547 $oBasePrice = $this->_getGroupPrice();
03548 foreach ( $oAmPriceList as $oAmPrice ) {
03549 if ( $oAmPrice->oxprice2article__oxaddperc->value ) {
03550 $oAmPrice->oxprice2article__oxaddabs = new oxField(oxPrice::percent( $oBasePrice, 100 - $oAmPrice->oxprice2article__oxaddperc->value ), oxField::T_RAW );
03551 }
03552 }
03553
03554 $this->_oAmountPriceList = $oAmPriceList;
03555 }
03556 }
03557
03558 return $this->_oAmountPriceList;
03559 }
03560
03568 protected function _isFieldEmpty( $sFieldName )
03569 {
03570 $mValue = $this->$sFieldName->value;
03571
03572 if ( is_null( $mValue ) ) {
03573 return true;
03574 }
03575
03576 if ( $mValue === '' ) {
03577 return true;
03578 }
03579
03580
03581 $aZeroValueFields = array('oxarticles__oxprice', 'oxarticles__oxvat', 'oxarticles__oxunitquantity');
03582
03583 if (!$mValue && in_array( $sFieldName, $aZeroValueFields ) ) {
03584 return true;
03585 }
03586
03587
03588 if (!strcmp($mValue, '0000-00-00 00:00:00') || !strcmp($mValue, '0000-00-00')) {
03589 return true;
03590 }
03591
03592 $sFieldName = strtolower($sFieldName);
03593
03594 if ( $sFieldName == 'oxarticles__oxicon' && ( strpos($mValue, "nopic_ico.jpg") !== false || strpos($mValue, "nopic.jpg") !== false ) ) {
03595 return true;
03596 }
03597
03598 if ( strpos($mValue, "nopic.jpg") !== false && ($sFieldName == 'oxarticles__oxthumb' || substr($sFieldName, 0, 17) == 'oxarticles__oxpic' || substr($sFieldName, 0, 18) == 'oxarticles__oxzoom') ) {
03599 return true;
03600 }
03601
03602 return false;
03603 }
03604
03612 protected function _assignParentFieldValue($sFieldName)
03613 {
03614 if (!($oParentArticle = $this->getParentArticle())) {
03615 return;
03616 }
03617
03618 $sCopyFieldName = $this->_getFieldLongName($sFieldName);
03619
03620
03621 if ( $oParentArticle->$sCopyFieldName != null ) {
03622
03623
03624 if ( substr( $sCopyFieldName, 0, 12) != 'oxarticles__') {
03625 return;
03626 }
03627
03628
03629 if (in_array($sCopyFieldName, $this->_aNonCopyParentFields)) {
03630 return;
03631 }
03632
03633
03634
03635 if ( stristr($sCopyFieldName, '_oxthumb') || stristr($sCopyFieldName, '_oxicon') ) {
03636 if ( $this->_isFieldEmpty( $sCopyFieldName ) && !$this->_hasMasterImage( 1 ) ) {
03637 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03638 }
03639 } elseif ( stristr($sCopyFieldName, '_oxzoom') ) {
03640
03641
03642 $iIndex = (int) str_ireplace( "oxarticles__oxzoom", "", $sFieldName );
03643 if ( $this->_isFieldEmpty( $sCopyFieldName ) && !$this->_hasMasterImage( $iIndex ) && !$this->_hasMasterImage( 1 ) ) {
03644 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03645 }
03646 } elseif ( stristr($sCopyFieldName, '_oxpicsgenerated') && $this->{$sCopyFieldName}->value == 0 ) {
03647
03648 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03649 } elseif ($this->_isFieldEmpty($sCopyFieldName) || in_array( $sCopyFieldName, $this->_aCopyParentField ) ) {
03650 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03651 }
03652 }
03653 }
03654
03660 public function getParentArticle()
03661 {
03662 if ( ( $sParentId = $this->oxarticles__oxparentid->value ) ) {
03663 $sIndex = $sParentId . "_" . $this->getLanguage();
03664 if ( !isset( self::$_aLoadedParents[$sIndex] ) ) {
03665 self::$_aLoadedParents[$sIndex] = oxNew( 'oxarticle' );
03666
03667 self::$_aLoadedParents[$sIndex]->_blLoadPrice = false;
03668 self::$_aLoadedParents[$sIndex]->_blLoadVariants = false;
03669 self::$_aLoadedParents[$sIndex]->loadInLang( $this->getLanguage(), $sParentId );
03670 }
03671 return self::$_aLoadedParents[$sIndex];
03672 }
03673 }
03674
03680 protected function _assignParentFieldValues()
03681 {
03682 startProfile('articleAssignParentInternal');
03683 if ( $this->oxarticles__oxparentid->value ) {
03684
03685 if ( !$this->isAdmin() || ( $this->_blLoadParentData && $this->isAdmin() ) ) {
03686 foreach ( $this->_aFieldNames as $sFieldName => $sVal ) {
03687 $this->_assignParentFieldValue( $sFieldName );
03688 }
03689 }
03690 }
03691 stopProfile('articleAssignParentInternal');
03692 }
03693
03699 protected function _assignNotBuyableParent()
03700 {
03701 if ( !$this->getConfig()->getConfigParam( 'blVariantParentBuyable' ) &&
03702 ($this->_blHasVariants || $this->oxarticles__oxvarstock->value || $this->oxarticles__oxvarcount->value )) {
03703 $this->_blNotBuyableParent = true;
03704
03705 }
03706 }
03707
03713 protected function _assignStock()
03714 {
03715 $myConfig = $this->getConfig();
03716
03717
03718
03719
03720
03721 if (!$myConfig->getConfigParam( 'blAllowUnevenAmounts' ) && !$this->isAdmin() ) {
03722 $this->oxarticles__oxstock = new oxField((int) floor($this->oxarticles__oxstock->value));
03723 }
03724
03725 $this->_iStockStatus = 0;
03726
03727
03728 if ( $myConfig->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstockflag->value != 4) {
03729
03730 $iStock = $this->oxarticles__oxstock->value;
03731
03732 if ($this->_blNotBuyableParent) {
03733 $iStock = $this->oxarticles__oxvarstock->value;
03734 }
03735
03736
03737 if ( $iStock <= $myConfig->getConfigParam( 'sStockWarningLimit' ) && $iStock > 0) {
03738 $this->_iStockStatus = 1;
03739 }
03740
03741
03742 if ($iStock <= 0) {
03743 $this->_iStockStatus = -1;
03744 }
03745 }
03746
03747
03748
03749 if ( $myConfig->getConfigParam( 'blUseStock' ) && ($this->oxarticles__oxstockflag->value == 3 || $this->oxarticles__oxstockflag->value == 2)) {
03750 $iOnStock = $this->oxarticles__oxstock->value;
03751 if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
03752 $iOnStock += $this->getSession()->getBasketReservations()->getReservedAmount($this->getId());
03753 }
03754 if ($iOnStock <= 0) {
03755 $this->setBuyableState( false );
03756 }
03757 }
03758
03759
03760 if ($this->_blNotBuyable && $this->oxarticles__oxvarstock->value ) {
03761 $this->setBuyableState( true );
03762
03763 $this->_blNotBuyableParent = true;
03764 }
03765
03766
03767
03768
03769 if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && !$myConfig->getConfigParam( 'blLoadVariants' ) && $this->oxarticles__oxvarstock->value) {
03770 $this->setBuyableState( false );
03771 }
03772
03773
03774 if (!$this->_blNotBuyable && $this->_blNotBuyableParent && $this->oxarticles__oxvarcount->value == 0) {
03775 $this->setBuyableState( false );
03776 }
03777 }
03778
03786 protected function _assignPrices()
03787 {
03788 $myConfig = $this->getConfig();
03789
03790
03791 if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
03792 return;
03793 }
03794
03795
03796 if ( $this->_hasAnyVariant() ) {
03797 $this->_applyRangePrice();
03798 }
03799 }
03800
03806 protected function _assignPersistentParam()
03807 {
03808
03809 $aPersParam = oxSession::getVar( 'persparam');
03810 if ( isset( $aPersParam) && isset( $aPersParam[$this->getId()])) {
03811 $this->_aPersistParam = $aPersParam[$this->getId()];
03812 }
03813 }
03814
03820 protected function _assignDynImageDir()
03821 {
03822 $myConfig = $this->getConfig();
03823
03824 $sThisShop = $this->oxarticles__oxshopid->value;
03825
03826 $this->_sDynImageDir = $myConfig->getPictureUrl( null, false );
03827 $this->dabsimagedir = $myConfig->getPictureDir( false );
03828 $this->nossl_dimagedir = $myConfig->getPictureUrl( null, false, false, null, $sThisShop );
03829 $this->ssl_dimagedir = $myConfig->getPictureUrl( null, false, true, null, $sThisShop );
03830 }
03831
03837 protected function _assignComparisonListFlag()
03838 {
03839
03840
03841 $aItems = oxSession::getVar('aFiltcompproducts');
03842 if ( isset( $aItems[$this->getId()])) {
03843 $this->_blIsOnComparisonList = true;
03844 }
03845 }
03846
03847
03855 protected function _insert()
03856 {
03857
03858 $sNow = date('Y-m-d H:i:s', oxRegistry::get("oxUtilsDate")->getTime());
03859 $this->oxarticles__oxinsert = new oxField( $sNow );
03860 if ( !is_object($this->oxarticles__oxsubclass) || $this->oxarticles__oxsubclass->value == '') {
03861 $this->oxarticles__oxsubclass = new oxField('oxarticle');
03862 }
03863
03864 return parent::_insert();
03865 }
03866
03872 protected function _update()
03873 {
03874
03875 $this->_skipSaveFields();
03876
03877 $myConfig = $this->getConfig();
03878
03879
03880 $blRes = parent::_update();
03881
03882
03883 return $blRes;
03884 }
03885
03891 public function updateVariantsRemind()
03892 {
03893
03894 if ( !$this->isVariant() && $this->_hasAnyVariant()) {
03895 $oDb = oxDb::getDb();
03896 $sOxId = $oDb->quote($this->getId());
03897 $sOxShopId = $oDb->quote($this->getShopId());
03898 $iRemindActive = $oDb->quote($this->oxarticles__oxremindactive->value);
03899 $sUpdate = "
03900 update oxarticles
03901 set oxremindactive = $iRemindActive
03902 where oxparentid = $sOxId and
03903 oxshopid = $sOxShopId
03904 ";
03905 $oDb->execute( $sUpdate );
03906 }
03907 }
03908
03916 protected function _deleteRecords($sOXID)
03917 {
03918 $oDb = oxDb::getDb();
03919
03920 $sOXID = $oDb->quote($sOXID);
03921
03922
03923 $sDelete = 'delete from oxobject2article where oxarticlenid = '.$sOXID.' or oxobjectid = '.$sOXID.' ';
03924 $oDb->execute( $sDelete);
03925
03926 $sDelete = 'delete from oxobject2attribute where oxobjectid = '.$sOXID.' ';
03927 $oDb->execute( $sDelete);
03928
03929 $sDelete = 'delete from oxobject2category where oxobjectid = '.$sOXID.' ';
03930 $oDb->execute( $sDelete);
03931
03932 $sDelete = 'delete from oxobject2selectlist where oxobjectid = '.$sOXID.' ';
03933 $oDb->execute( $sDelete);
03934
03935 $sDelete = 'delete from oxprice2article where oxartid = '.$sOXID.' ';
03936 $oDb->execute( $sDelete);
03937
03938 $sDelete = 'delete from oxreviews where oxtype="oxarticle" and oxobjectid = '.$sOXID.' ';
03939 $oDb->execute( $sDelete);
03940
03941 $sDelete = 'delete from oxratings where oxobjectid = '.$sOXID.' ';
03942 $rs = $oDb->execute( $sDelete );
03943
03944 $sDelete = 'delete from oxaccessoire2article where oxobjectid = '.$sOXID.' or oxarticlenid = '.$sOXID.' ';
03945 $oDb->execute( $sDelete);
03946
03947
03948 $sDelete = 'delete from oxobject2delivery where oxobjectid = '.$sOXID.' and oxtype=\'oxarticles\' ';
03949 $oDb->execute( $sDelete);
03950
03951 $sDelete = 'delete from oxartextends where oxid = '.$sOXID.' ';
03952 $oDb->execute( $sDelete);
03953
03954
03955 foreach ( $this->_getLanguageSetTables( "oxartextends" ) as $sSetTbl ) {
03956 $oDb->execute( "delete from $sSetTbl where oxid = {$sOXID}" );
03957 }
03958
03959 $sDelete = 'delete from oxactions2article where oxartid = '.$sOXID.' ';
03960 $rs = $oDb->execute( $sDelete );
03961
03962 $sDelete = 'delete from oxobject2list where oxobjectid = '.$sOXID.' ';
03963 $rs = $oDb->execute( $sDelete );
03964
03965
03966 return $rs;
03967 }
03968
03976 protected function _deleteVariantRecords( $sOXID )
03977 {
03978 if ( $sOXID ) {
03979 $oDb = oxDb::getDb();
03980
03981 $sQ = 'select oxid from '.$this->getViewName().' where oxparentid = '.$oDb->quote( $sOXID );
03982 $rs = $oDb->select( $sQ, false, false );
03983 $oArticle = oxNew("oxArticle");
03984 if ($rs != false && $rs->recordCount() > 0) {
03985 while (!$rs->EOF) {
03986 $oArticle->setId($rs->fields[0]);
03987 $oArticle->delete();
03988 $rs->moveNext();
03989 }
03990 }
03991 }
03992 }
03993
03999 protected function _deletePics()
04000 {
04001 $myUtilsPic = oxRegistry::get("oxUtilsPic");
04002 $myConfig = $this->getConfig();
04003 $oPictureHandler = oxRegistry::get("oxPictureHandler");
04004
04005
04006 $oPictureHandler->deleteMainIcon( $this );
04007
04008
04009 $oPictureHandler->deleteThumbnail( $this );
04010
04011 $sAbsDynImageDir = $myConfig->getPictureDir(false);
04012
04013
04014 $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
04015 for ( $i = 1; $i <= $iPicCount; $i++ ) {
04016 $oPictureHandler->deleteArticleMasterPicture( $this, $i );
04017 }
04018 }
04019
04029 protected function _onChangeResetCounts( $sOxid, $sVendorId = null, $sManufacturerId = null )
04030 {
04031
04032 $myUtilsCount = oxRegistry::get("oxUtilsCount");
04033
04034 if ( $sVendorId ) {
04035 $myUtilsCount->resetVendorArticleCount( $sVendorId );
04036 }
04037
04038 if ( $sManufacturerId ) {
04039 $myUtilsCount->resetManufacturerArticleCount( $sManufacturerId );
04040 }
04041
04042
04043 $oDb = oxDb::getDb();
04044 $sQ = "select oxcatnid from oxobject2category where oxobjectid = ".$oDb->quote($sOxid);
04045 $oRs = $oDb->select( $sQ, false, false );
04046 if ( $oRs !== false && $oRs->recordCount() > 0) {
04047 while ( !$oRs->EOF ) {
04048 $myUtilsCount->resetCatArticleCount( $oRs->fields[0] );
04049 $oRs->moveNext();
04050 }
04051 }
04052 }
04053
04061 protected function _onChangeUpdateStock( $sParentID )
04062 {
04063 if ( $sParentID ) {
04064 $oDb = oxDb::getDb();
04065 $sParentIdQuoted = $oDb->quote($sParentID);
04066 $sQ = 'select oxstock, oxvendorid, oxmanufacturerid from oxarticles where oxid = '.$sParentIdQuoted;
04067 $rs = $oDb->select( $sQ, false, false );
04068 $iOldStock = $rs->fields[0];
04069 $iVendorID = $rs->fields[1];
04070 $iManufacturerID = $rs->fields[2];
04071
04072 $sQ = 'select sum(oxstock) from '.$this->getViewName(true).' where oxparentid = '.$sParentIdQuoted.' and '. $this->getSqlActiveSnippet( true ).' and oxstock > 0 ';
04073 $iStock = (float) $oDb->getOne( $sQ, false, false );
04074
04075 $sQ = 'update oxarticles set oxvarstock = '.$iStock.' where oxid = '.$sParentIdQuoted;
04076 $oDb->execute( $sQ );
04077
04078
04079
04080 if ( $iStock < 0 ) {
04081 $iStock = 0;
04082 }
04083 if ( $iOldStock < 0 ) {
04084 $iOldStock = 0;
04085 }
04086 if ( $this->oxarticles__oxstockflag->value == 2 && $iOldStock xor $iStock ) {
04087
04088
04089 $this->_onChangeResetCounts( $sParentID, $iVendorID, $iManufacturerID );
04090 }
04091 }
04092 }
04093
04101 protected function _onChangeStockResetCount( $sOxid )
04102 {
04103 $myConfig = $this->getConfig();
04104
04105 if ( $myConfig->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstockflag->value == 2 &&
04106 ( $this->oxarticles__oxstock->value + $this->oxarticles__oxvarstock->value ) <= 0 ) {
04107
04108 $this->_onChangeResetCounts( $sOxid, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
04109 }
04110 }
04111
04119 protected function _onChangeUpdateVarCount( $sParentID )
04120 {
04121 if ( $sParentID ) {
04122 $oDb = oxDb::getDb();
04123 $sParentIdQuoted = $oDb->quote( $sParentID );
04124 $sQ = "select count(*) as varcount from oxarticles where oxparentid = {$sParentIdQuoted}";
04125 $iVarCount = (int) $oDb->getOne( $sQ, false, false );
04126
04127 $sQ = "update oxarticles set oxvarcount = {$iVarCount} where oxid = {$sParentIdQuoted}";
04128 $oDb->execute( $sQ );
04129 }
04130 }
04131
04139 protected function _setVarMinMaxPrice( $sParentId )
04140 {
04141 if ( $sParentId ) {
04142 $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
04143 $sQ = '
04144 SELECT
04145 MIN( IF( `oxarticles`.`oxprice` > 0, `oxarticles`.`oxprice`, `p`.`oxprice` ) ) AS `varminprice`,
04146 MAX( IF( `oxarticles`.`oxprice` > 0, `oxarticles`.`oxprice`, `p`.`oxprice` ) ) AS `varmaxprice`
04147 FROM '. $this->getViewName(true) . ' AS `oxarticles`
04148 LEFT JOIN '. $this->getViewName(true) . ' AS `p` ON ( `p`.`oxid` = `oxarticles`.`oxparentid` AND `p`.`oxprice` > 0 )
04149 WHERE '. $this->getSqlActiveSnippet(true) .'
04150 AND ( `oxarticles`.`oxparentid` = '. $oDb->quote( $sParentId ) .' )';
04151 $oDb->setFetchMode( oxDb::FETCH_MODE_ASSOC );
04152 $aPrices = $oDb->getRow( $sQ, false, false );
04153 if ( !is_null( $aPrices['varminprice'] ) || !is_null( $aPrices['varmaxprice'] ) ) {
04154 $sQ = '
04155 UPDATE `oxarticles`
04156 SET
04157 `oxvarminprice` = '. $oDb->quote( $aPrices['varminprice'] ) .',
04158 `oxvarmaxprice` = '. $oDb->quote( $aPrices['varmaxprice'] ) .'
04159 WHERE
04160 `oxid` = ' . $oDb->quote( $sParentId );
04161 } else {
04162 $sQ = '
04163 UPDATE `oxarticles`
04164 SET
04165 `oxvarminprice` = `oxprice`,
04166 `oxvarmaxprice` = `oxprice`
04167 WHERE
04168 `oxid` = ' . $oDb->quote( $sParentId );
04169 }
04170 $oDb->execute( $sQ );
04171 }
04172 }
04173
04174
04184 protected function _onChangeUpdateMinVarPrice( $sParentID )
04185 {
04186 if ( $sParentID ) {
04187 $oDb = oxDb::getDb();
04188 $sParentIdQuoted = $oDb->quote($sParentID);
04189
04190 $sQ = 'select min(oxprice) as varminprice from '.$this->getViewName(true).' where '.$this->getSqlActiveSnippet(true).' and (oxparentid = '.$sParentIdQuoted.')';
04191 $dVarMinPrice = $oDb->getOne( $sQ, false, false );
04192
04193 $dParentPrice = $oDb->getOne( "select oxprice from oxarticles where oxid = $sParentIdQuoted ", false, false );
04194
04195 $blParentBuyable = $this->getConfig()->getConfigParam( 'blVariantParentBuyable' );
04196
04197 if ($dVarMinPrice) {
04198 if ($blParentBuyable) {
04199 $dVarMinPrice = min($dVarMinPrice, $dParentPrice);
04200 }
04201 } else {
04202 $dVarMinPrice = $dParentPrice;
04203 }
04204
04205 if ( $dVarMinPrice ) {
04206 $sQ = 'update oxarticles set oxvarminprice = '.$dVarMinPrice.' where oxid = '.$sParentIdQuoted;
04207 $oDb->execute($sQ);
04208 }
04209 }
04210 }
04211
04212
04220 protected function _applyRangePrice()
04221 {
04222
04223 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
04224 return;
04225 }
04226
04227 $this->_blIsRangePrice = false;
04228
04229
04230 if ($this->_blSkipFromPrice || !$this->_blNotBuyableParent) {
04231 return;
04232 }
04233
04234 if ( $this->isParentNotBuyable() && !$this->getConfig()->getConfigParam( 'blLoadVariants' )) {
04235
04236 $dPrice = $this->_preparePrice( $this->oxarticles__oxvarminprice->value, $this->getArticleVat() );
04237 $this->getPrice()->setPrice($dPrice);
04238 $this->_blIsRangePrice = true;
04239 $this->_calculatePrice( $this->getPrice() );
04240 return;
04241
04242 }
04243
04244 $aPrices = array();
04245
04246 if (!$this->_blNotBuyableParent) {
04247 $aPrices[] = $this->getPrice()->getPrice();
04248 }
04249
04250 $aVariants = $this->getVariants(false);
04251
04252 if (count($aVariants)) {
04253 foreach ($aVariants as $sKey => $oVariant) {
04254 $aPrices[] = $oVariant->getPrice()->getPrice();
04255 }
04256 }
04257
04258 if ( count( $aPrices ) ) {
04259 $dMinPrice = min( $aPrices );
04260 $dMaxPrice = max( $aPrices );
04261 }
04262
04263 if ($this->_blNotBuyableParent && isset($dMinPrice) && $dMinPrice == $dMaxPrice) {
04264 $this->getPrice()->setPrice($dMinPrice);
04265 }
04266
04267 if (isset($dMinPrice) && $dMinPrice != $dMaxPrice) {
04268 $this->getPrice()->setPrice($dMinPrice);
04269 $this->_blIsRangePrice = true;
04270 }
04271 }
04272
04279 public function getProductId()
04280 {
04281 return $this->getId();
04282 }
04283
04291 public function getProductParentId()
04292 {
04293 return $this->getParentId();
04294 }
04295
04301 public function getParentId()
04302 {
04303 return $this->oxarticles__oxparentid->value;
04304 }
04305
04311 public function isOrderArticle()
04312 {
04313 return false;
04314 }
04315
04321 public function isVariant()
04322 {
04323 return (bool) ( isset( $this->oxarticles__oxparentid ) ? $this->oxarticles__oxparentid->value : false );
04324 }
04325
04331 public function isMdVariant()
04332 {
04333 $oMdVariant = oxNew( "oxVariantHandler" );
04334
04335 return $oMdVariant->isMdVariant($this);
04336 }
04337
04345 public function getSqlForPriceCategories($sFields = '')
04346 {
04347 if (!$sFields) {
04348 $sFields = 'oxid';
04349 }
04350 $sSelectWhere = "select $sFields from ".$this->_getObjectViewName('oxcategories')." where";
04351 $sQuotedPrice = oxDb::getDb()->quote( $this->oxarticles__oxprice->value );
04352 return "$sSelectWhere oxpricefrom != 0 and oxpriceto != 0 and oxpricefrom <= $sQuotedPrice and oxpriceto >= $sQuotedPrice"
04353 ." union $sSelectWhere oxpricefrom != 0 and oxpriceto = 0 and oxpricefrom <= $sQuotedPrice"
04354 ." union $sSelectWhere oxpricefrom = 0 and oxpriceto != 0 and oxpriceto >= $sQuotedPrice";
04355 }
04356
04364 public function inPriceCategory( $sCatNid )
04365 {
04366 $oDb = oxDb::getDb();
04367
04368 $sQuotedPrice = $oDb->quote( $this->oxarticles__oxprice->value );
04369 $sQuotedCnid = $oDb->quote( $sCatNid );
04370 return (bool) $oDb->getOne(
04371 "select 1 from ".$this->_getObjectViewName('oxcategories')." where oxid=$sQuotedCnid and"
04372 ."( (oxpricefrom != 0 and oxpriceto != 0 and oxpricefrom <= $sQuotedPrice and oxpriceto >= $sQuotedPrice)"
04373 ." or (oxpricefrom != 0 and oxpriceto = 0 and oxpricefrom <= $sQuotedPrice)"
04374 ." or (oxpricefrom = 0 and oxpriceto != 0 and oxpriceto >= $sQuotedPrice)"
04375 .")"
04376 );
04377 }
04378
04384 public function getMdVariants()
04385 {
04386 if ( $this->_oMdVariants ) {
04387 return $this->_oMdVariants;
04388 }
04389
04390 $oParentArticle = $this->getParentArticle();
04391 if ( $oParentArticle ) {
04392 $oVariants = $oParentArticle->getVariants();
04393 } else {
04394 $oVariants = $this->getVariants();
04395 }
04396
04397 $oVariantHandler = oxNew( "oxVariantHandler" );
04398 $this->_oMdVariants = $oVariantHandler->buildMdVariants( $oVariants, $this->getId() );
04399
04400 return $this->_oMdVariants;
04401 }
04402
04408 public function getMdSubvariants()
04409 {
04410 return $this->getMdVariants()->getMdSubvariants();
04411 }
04412
04420 protected function _hasMasterImage( $iIndex )
04421 {
04422 $sPicName = basename($this->{"oxarticles__oxpic" . $iIndex}->value);
04423
04424 if ( $sPicName == "nopic.jpg" || $sPicName == "" ) {
04425 return false;
04426 }
04427 if ( $this->isVariant() && $this->getParentArticle()->{"oxarticles__oxpic".$iIndex}->value == $this->{"oxarticles__oxpic".$iIndex}->value ) {
04428 return false;
04429 }
04430
04431 $sMasterPic = 'product/'.$iIndex . "/" . $sPicName;
04432
04433 if ( $this->getConfig()->getMasterPicturePath( $sMasterPic ) ) {
04434 return true;
04435 }
04436
04437 return false;
04438 }
04439
04448 public function getPictureFieldValue( $sFieldName, $iIndex = null )
04449 {
04450 if ( $sFieldName ) {
04451 $sFieldName = "oxarticles__" . $sFieldName . $iIndex;
04452 return $this->$sFieldName->value;
04453 }
04454 }
04455
04463 public function getMasterZoomPictureUrl( $iIndex )
04464 {
04465 $sPicUrl = false;
04466 $sPicName = basename( $this->{"oxarticles__oxpic" . $iIndex}->value );
04467
04468 if ( $sPicName && $sPicName != "nopic.jpg" ) {
04469 $sPicUrl = $this->getConfig()->getPictureUrl( "master/product/" . $iIndex . "/" . $sPicName );
04470 if ( !$sPicUrl || basename( $sPicUrl ) == "nopic.jpg" ) {
04471 $sPicUrl = false;
04472 }
04473 }
04474
04475 return $sPicUrl;
04476 }
04477
04483 public function getUnitName()
04484 {
04485 if ( $this->oxarticles__oxunitname->value ) {
04486 return oxRegistry::getLang()->translateString( $this->oxarticles__oxunitname->value );
04487 }
04488 }
04489
04497 public function getArticleFiles( $blAddFromParent=false )
04498 {
04499 if ( $this->_aArticleFiles === null) {
04500
04501 $this->_aArticleFiles = false;
04502
04503 $sQ = "SELECT * FROM `oxfiles` WHERE `oxartid` = '".$this->getId()."'";
04504
04505 if ( !$this->getConfig()->getConfigParam( 'blVariantParentBuyable' ) && $blAddFromParent ) {
04506 $sQ .= " OR `oxartId` = '". $this->oxarticles__oxparentid->value . "'";
04507 }
04508
04509 $oArticleFiles = oxNew("oxlist");
04510 $oArticleFiles->init("oxfile");
04511 $oArticleFiles->selectString( $sQ );
04512 $this->_aArticleFiles = $oArticleFiles;
04513
04514 }
04515
04516 return $this->_aArticleFiles;
04517 }
04518
04524 public function isDownloadable()
04525 {
04526 return $this->oxarticles__oxisdownloadable->value;
04527 }
04528
04534 public function hasAmountPrice()
04535 {
04536 if ( self::$_blHasAmountPrice === null ) {
04537
04538 self::$_blHasAmountPrice = false;
04539
04540 $oDb = oxDb::getDb();
04541 $sQ = "SELECT 1 FROM `oxprice2article` LIMIT 1";
04542
04543 if ( $oDb->getOne( $sQ ) ) {
04544 self::$_blHasAmountPrice = true;
04545 }
04546 }
04547
04548 return self::$_blHasAmountPrice;
04549 }
04550
04551
04557 protected function _isPriceViewModeNetto()
04558 {
04559 $blResult = (bool) $this->getConfig()->getConfigParam('blShowNetPrice');
04560 $oUser = $this->getArticleUser();
04561 if ( $oUser ) {
04562 $blResult = $oUser->isPriceViewModeNetto();
04563 }
04564
04565 return $blResult;
04566 }
04567
04568
04576 protected function _getPriceObject( $blCalculationModeNetto = null )
04577 {
04578 $oPrice = oxNew( 'oxPrice' );
04579
04580 if ( $blCalculationModeNetto === null ) {
04581 $blCalculationModeNetto = $this->_isPriceViewModeNetto();
04582 }
04583
04584 if ( $blCalculationModeNetto ) {
04585 $oPrice->setNettoPriceMode();
04586 } else {
04587 $oPrice->setBruttoPriceMode();
04588 }
04589
04590 return $oPrice;
04591 }
04592
04593
04601 protected function _getPriceForView( $oPrice )
04602 {
04603 if ( $this->_isPriceViewModeNetto() ) {
04604 $dPrice = $oPrice->getNettoPrice();
04605 } else {
04606 $dPrice = $oPrice->getBruttoPrice();
04607 }
04608
04609 return $dPrice;
04610 }
04611
04612
04622 protected function _preparePrice( $dPrice, $dVat, $blCalculationModeNetto = null )
04623 {
04624 if ( $blCalculationModeNetto === null ) {
04625 $blCalculationModeNetto = $this->_isPriceViewModeNetto();
04626 }
04627
04628 $blEnterNetPrice = $this->getConfig()->getConfigParam('blEnterNetPrice');
04629 if ( $blCalculationModeNetto && !$blEnterNetPrice ) {
04630 $dPrice = round( oxPrice::brutto2Netto( $dPrice, $dVat ), 2 );
04631 } elseif ( !$blCalculationModeNetto && $blEnterNetPrice ) {
04632 $dPrice = round( oxPrice::netto2Brutto( $dPrice, $dVat ), 2 );
04633 }
04634
04635 return $dPrice;
04636 }
04637
04638
04644 public function getFUnitPrice()
04645 {
04646 if ($this->_fPricePerUnit == null) {
04647 if ( $oPrice = $this->getUnitPrice() ) {
04648 if ( $dPrice = $this->_getPriceForView( $oPrice ) ) {
04649 $this->_fPricePerUnit = oxRegistry::getLang()->formatCurrency( $dPrice );
04650 }
04651 }
04652 }
04653
04654 return $this->_fPricePerUnit;
04655 }
04656
04657
04663 public function getUnitPrice()
04664 {
04665
04666 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
04667 return;
04668 }
04669
04670 $oPrice = null;
04671 if ( (double) $this->oxarticles__oxunitquantity->value && $this->oxarticles__oxunitname->value ) {
04672 $oPrice = clone $this->getPrice();
04673 $oPrice->divide( (double) $this->oxarticles__oxunitquantity->value );
04674 }
04675
04676 return $oPrice;
04677 }
04678
04679
04685 public function getFMinPrice()
04686 {
04687 $sPrice = '';
04688 if ( $oPrice = $this->getMinPrice() ) {
04689 $dPrice = $this->_getPriceForView( $oPrice );
04690 $sPrice = oxRegistry::getLang()->formatCurrency( $dPrice );
04691 }
04692
04693 return $sPrice;
04694 }
04695
04701 public function getFVarMinPrice()
04702 {
04703 $sPrice = '';
04704 if ( $oPrice = $this->getVarMinPrice() ) {
04705 $dPrice = $this->_getPriceForView( $oPrice );
04706 $sPrice = oxRegistry::getLang()->formatCurrency( $dPrice );
04707 }
04708
04709 return $sPrice;
04710 }
04711
04717 public function getVarMinPrice()
04718 {
04719 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
04720 return;
04721 }
04722
04723 $oPrice = null;
04724 $dPrice = $this->_getVarMinPrice();
04725
04726 $dPrice = $this->_preparePrice( $dPrice, $this->getArticleVat() );
04727
04728
04729 $oPrice = $this->_getPriceObject();
04730 $oPrice->setPrice( $dPrice );
04731 $this->_calculatePrice( $oPrice );
04732
04733
04734 return $oPrice;
04735 }
04736
04737
04743 public function getMinPrice()
04744 {
04745 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
04746 return;
04747 }
04748
04749 $oPrice = null;
04750 $dPrice = $this->_getPrice();
04751 if ( $this->_getVarMinPrice() !== null && $dPrice > $this->_getVarMinPrice() ) {
04752 $dPrice = $this->_getVarMinPrice();
04753 }
04754
04755 $dPrice = $this->_preparePrice( $dPrice, $this->getArticleVat() );
04756
04757
04758 $oPrice = $this->_getPriceObject();
04759 $oPrice->setPrice( $dPrice );
04760 $this->_calculatePrice( $oPrice );
04761
04762
04763 return $oPrice;
04764 }
04765
04766
04772 public function isRangePrice()
04773 {
04774 if ( $this->_blIsRangePrice === null ) {
04775
04776 $this->setRangePrice( false );
04777
04778 if ( $this->_hasAnyVariant() ) {
04779 $dPrice = $this->_getPrice();
04780 $dMinPrice = $this->_getVarMinPrice();
04781 $dMaxPrice = $this->_getVarMaxPrice();
04782
04783 if ( $dMinPrice != $dMaxPrice ) {
04784 $this->setRangePrice();
04785 } elseif ( !$this->isParentNotBuyable() && $dMinPrice != $dPrice ) {
04786 $this->setRangePrice();
04787 }
04788 }
04789 }
04790
04791 return $this->_blIsRangePrice;
04792 }
04793
04794
04802 public function setRangePrice( $blIsRangePrice = true )
04803 {
04804 return $this->_blIsRangePrice = $blIsRangePrice;
04805 }
04806
04812 protected function _getUserPriceSufix()
04813 {
04814 $sPriceSufix = '';
04815 $oUser = $this->getArticleUser();
04816
04817 if ( $oUser ) {
04818 if ( $oUser->inGroup( 'oxidpricea' ) ) {
04819 $sPriceSufix = 'a';
04820 } elseif ( $oUser->inGroup( 'oxidpriceb' ) ) {
04821 $sPriceSufix = 'b';
04822 } elseif ( $oUser->inGroup( 'oxidpricec' ) ) {
04823 $sPriceSufix = 'c';
04824 }
04825 }
04826
04827 return $sPriceSufix;
04828 }
04829
04830
04836 protected function _getPrice()
04837 {
04838 $sPriceSufix = $this->_getUserPriceSufix();
04839 if ( $sPriceSufix === '') {
04840 $dPrice = $this->oxarticles__oxprice->value;
04841 } else {
04842 if ( $this->getConfig()->getConfigParam( 'blOverrideZeroABCPrices' ) ) {
04843 $dPrice = ($this->{oxarticles__oxprice.$sPriceSufix}->value !=0 )? $this->{oxarticles__oxprice.$sPriceSufix}->value : $this->oxarticles__oxprice->value;
04844 } else {
04845 $dPrice = $this->{oxarticles__oxprice.$sPriceSufix}->value;
04846 }
04847 }
04848 return $dPrice;
04849 }
04850
04851
04857 protected function _getVarMinPrice()
04858 {
04859 if ( $this->_dVarMinPrice === null) {
04860
04861 $sPriceSufix = $this->_getUserPriceSufix();
04862 if ( $dPrice === null ) {
04863 if ( $sPriceSufix === '' ) {
04864 $dPrice = $this->oxarticles__oxvarminprice->value;
04865 } else {
04866 $sSql = 'SELECT ';
04867 if ( $this->getConfig()->getConfigParam( 'blOverrideZeroABCPrices' ) ) {
04868 $sSql .= 'MIN( IF(`oxprice'.$sPriceSufix.'` = 0, `oxprice`, `oxprice'.$sPriceSufix.'`) ) AS `varminprice` ';
04869 } else {
04870 $sSql .= 'MIN(`oxprice'.$sPriceSufix.'`) AS `varminprice` ';
04871 }
04872
04873 $sSql .= ' FROM ' . $this->getViewName(true) . '
04874 WHERE ' .$this->getSqlActiveSnippet(true) . '
04875 AND ( `oxparentid` = ' . oxDb::getDb()->quote( $this->getId() ) . ' )';
04876
04877 $dPrice = oxDb::getDb()->getOne( $sSql );
04878 }
04879 }
04880 $this->_dVarMinPrice = $dPrice;
04881 }
04882
04883 return $this->_dVarMinPrice;
04884 }
04885
04891 protected function _getSubShopVarMinPrice()
04892 {
04893 $myConfig = $this->getConfig();
04894 $sShopId = $myConfig->getShopId();
04895 if ($this->getConfig()->getConfigParam( 'blMallCustomPrice' ) && $sShopId != $this->oxarticles__oxshopid->value ) {
04896 $sPriceSufix = $this->_getUserPriceSufix();
04897 $sSql = 'SELECT ';
04898 if ( $sPriceSufix != '' && $this->getConfig()->getConfigParam( 'blOverrideZeroABCPrices' ) ) {
04899 $sSql .= 'MIN(IF(`oxfield2shop`.`oxprice'.$sPriceSufix.'` = 0, `oxfield2shop`.`oxprice`, `oxfield2shop`.`oxprice'.$sPriceSufix.'`)) AS `varminprice` ';
04900 } else {
04901 $sSql .= 'MIN(`oxfield2shop`.`oxprice'.$sPriceSufix.'`) AS `varminprice` ';
04902 }
04903 $sSql .= ' FROM ' . getViewName('oxfield2shop') . ' AS oxfield2shop
04904 INNER JOIN ' . $this->getViewName(true) . ' AS oxarticles ON `oxfield2shop`.`oxartid` = `oxarticles`.`oxid`
04905 WHERE ' .$this->getSqlActiveSnippet(true) . '
04906 AND ( `oxarticles`.`oxparentid` = ' . oxDb::getDb()->quote( $this->getId() ) . ' )
04907 AND ( `oxfield2shop`.`oxshopid` = ' . oxDb::getDb()->quote( $sShopId ) . ' )';
04908 $dPrice = oxDb::getDb()->getOne( $sSql );
04909 }
04910 return $dPrice;
04911 }
04912
04918 protected function _getVarMaxPrice()
04919 {
04920 if ( $this->_dVarMaxPrice === null ) {
04921
04922 $sPriceSufix = $this->_getUserPriceSufix();
04923 if ( $dPrice === null ) {
04924 if ( $sPriceSufix === '') {
04925 $dPrice = $this->oxarticles__oxvarmaxprice->value;
04926 } else {
04927 $sSql = 'SELECT ';
04928 if ( $this->getConfig()->getConfigParam( 'blOverrideZeroABCPrices' ) ) {
04929 $sSql .= 'MAX( IF(`oxprice'.$sPriceSufix.'` = 0, `oxprice`, `oxprice'.$sPriceSufix.'`) ) AS `varmaxprice` ';
04930 } else {
04931 $sSql .= 'MAX(`oxprice'.$sPriceSufix.'`) AS `varmaxprice` ';
04932 }
04933
04934 $sSql .= ' FROM ' . $this->getViewName(true) . '
04935 WHERE ' .$this->getSqlActiveSnippet(true) . '
04936 AND ( `oxparentid` = ' . oxDb::getDb()->quote( $this->getId() ) . ' )';
04937
04938 $dPrice = oxDb::getDb()->getOne( $sSql );
04939 }
04940 }
04941 $this->_dVarMaxPrice = $dPrice;
04942 }
04943
04944 return $this->_dVarMaxPrice;
04945 }
04946
04952 protected function _getSubShopVarMaxPrice()
04953 {
04954 $myConfig = $this->getConfig();
04955 $sShopId = $myConfig->getShopId();
04956 if ($this->getConfig()->getConfigParam( 'blMallCustomPrice' ) && $sShopId != $this->oxarticles__oxshopid->value ) {
04957 $sPriceSufix = $this->_getUserPriceSufix();
04958 $sSql = 'SELECT ';
04959 if ( $sPriceSufix != '' && $this->getConfig()->getConfigParam( 'blOverrideZeroABCPrices' ) ) {
04960 $sSql .= 'MAX(IF(`oxfield2shop`.`oxprice'.$sPriceSufix.'` = 0, `oxfield2shop`.`oxprice`, `oxfield2shop`.`oxprice'.$sPriceSufix.'`)) AS `varmaxprice` ';
04961 } else {
04962 $sSql .= 'MAX(`oxfield2shop`.`oxprice'.$sPriceSufix.'`) AS `varmaxprice` ';
04963 }
04964 $sSql .= ' FROM ' . getViewName('oxfield2shop') . ' AS oxfield2shop
04965 INNER JOIN ' . $this->getViewName(true) . ' AS oxarticles ON `oxfield2shop`.`oxartid` = `oxarticles`.`oxid`
04966 WHERE ' .$this->getSqlActiveSnippet(true) . '
04967 AND ( `oxarticles`.`oxparentid` = ' . oxDb::getDb()->quote( $this->getId() ) . ' )
04968 AND ( `oxfield2shop`.`oxshopid` = ' . oxDb::getDb()->quote( $sShopId ) . ' )';
04969 $dPrice = oxDb::getDb()->getOne( $sSql );
04970 }
04971 return $dPrice;
04972 }
04973
04974 }