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 'oxarticles__oxisdownloadable',
00372 'oxarticles__oxshowcustomagreement');
00373
00379 protected $_oMdVariants = null;
00380
00386 protected $_oLongDesc = null;
00387
00395 protected $_aVariantSelections = array();
00396
00401 protected static $_aSelections = array();
00402
00407 protected static $_aCategoryCache = null;
00408
00413 protected static $_blHasAmountPrice = null;
00414
00419 protected $_aArticleFiles = null;
00420
00425 protected $_blCanUpdateAnyField = null;
00426
00435 public function __construct($aParams = null)
00436 {
00437 if ( $aParams && is_array($aParams)) {
00438 foreach ( $aParams as $sParam => $mValue) {
00439 $this->$sParam = $mValue;
00440 }
00441 }
00442 parent::__construct();
00443 $this->init( 'oxarticles' );
00444 }
00445
00454 public function __get($sName)
00455 {
00456 $this->$sName = parent::__get($sName);
00457 if ( $this->$sName ) {
00458
00459 $this->_assignParentFieldValue($sName);
00460 }
00461
00462 return $this->$sName;
00463 }
00464
00473 public function __set( $sName, $sValue )
00474 {
00475 parent::__set( $sName, $sValue );
00476 }
00477
00485 public function setId( $sId = null )
00486 {
00487 $sId = parent::setId( $sId );
00488
00489
00490 $this->oxarticles__oxnid = $this->oxarticles__oxid;
00491
00492 return $sId;
00493 }
00494
00504 public function getActiveCheckQuery( $blForceCoreTable = null )
00505 {
00506 $sTable = $this->getViewName( $blForceCoreTable );
00507
00508
00509 $sQ = " $sTable.oxactive = 1 ";
00510
00511
00512 if ( $this->getConfig()->getConfigParam( 'blUseTimeCheck' ) ) {
00513 $sDate = date( 'Y-m-d H:i:s', oxRegistry::get("oxUtilsDate")->getTime() );
00514 $sQ = "( $sQ or ( $sTable.oxactivefrom < '$sDate' and $sTable.oxactiveto > '$sDate' ) ) ";
00515 }
00516
00517 return $sQ;
00518 }
00519
00533 public function getStockCheckQuery( $blForceCoreTable = null )
00534 {
00535 $myConfig = $this->getConfig();
00536 $sTable = $this->getViewName( $blForceCoreTable );
00537
00538 $sQ = "";
00539
00540
00541 if ( $myConfig->getConfigParam( 'blUseStock' ) ) {
00542 $sQ = " and ( $sTable.oxstockflag != 2 or ( $sTable.oxstock + $sTable.oxvarstock ) > 0 ) ";
00543
00544 if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) ) {
00545 $sTimeCheckQ = '';
00546 if ( $myConfig->getConfigParam( 'blUseTimeCheck' ) ) {
00547 $sDate = date( 'Y-m-d H:i:s', oxRegistry::get("oxUtilsDate")->getTime() );
00548 $sTimeCheckQ = " or ( art.oxactivefrom < '$sDate' and art.oxactiveto > '$sDate' )";
00549 }
00550 $sQ = " $sQ and IF( $sTable.oxvarcount = 0, 1, ( select 1 from $sTable as art where art.oxparentid=$sTable.oxid and ( art.oxactive = 1 $sTimeCheckQ ) and ( art.oxstockflag != 2 or art.oxstock > 0 ) limit 1 ) ) ";
00551 }
00552 }
00553
00554 return $sQ;
00555 }
00556
00568 public function getVariantsQuery( $blRemoveNotOrderables, $blForceCoreTable = null )
00569 {
00570 $sTable = $this->getViewName( $blForceCoreTable );
00571 $sQ = " and $sTable.oxparentid = '".$this->getId()."' ";
00572
00573
00574 if ( $this->getConfig()->getConfigParam( 'blUseStock' ) ) {
00575 $sQ .= " and ( $sTable.oxstock > 0 or ( $sTable.oxstock <= 0 and $sTable.oxstockflag != 2 ";
00576 if ( $blRemoveNotOrderables ) {
00577 $sQ .= " and $sTable.oxstockflag != 3 ";
00578 }
00579 $sQ .= " ) ) ";
00580 }
00581
00582 return $sQ;
00583 }
00584
00592 public function getSqlActiveSnippet( $blForceCoreTable = null )
00593 {
00594 $myConfig = $this->getConfig();
00595
00596
00597 $sQ = $this->getActiveCheckQuery( $blForceCoreTable );
00598
00599
00600 $sQ .= $this->getStockCheckQuery( $blForceCoreTable );
00601
00602
00603 return "( $sQ ) ";
00604 }
00605
00613 public function setSkipAssign($blSkipAssign)
00614 {
00615 $this->_blSkipAssign = $blSkipAssign;
00616 }
00617
00623 public function disablePriceLoad()
00624 {
00625 $this->_blLoadPrice = false;
00626 }
00627
00633 public function enablePriceLoad()
00634 {
00635 $this->_blLoadPrice = true;
00636 }
00637
00643 public function getItemKey()
00644 {
00645 return $this->_sItemKey;
00646 }
00647
00655 public function setItemKey($sItemKey)
00656 {
00657 $this->_sItemKey = $sItemKey;
00658 }
00659
00667 public function setNoVariantLoading( $blLoadVariants )
00668 {
00669 $this->_blLoadVariants = !$blLoadVariants;
00670 }
00671
00677 public function isBuyable()
00678 {
00679 if ($this->_blNotBuyableParent) {
00680 return false;
00681 }
00682
00683 return !$this->_blNotBuyable;
00684 }
00685
00691 public function getPersParams()
00692 {
00693 return $this->_aPersistParam;
00694 }
00695
00701 public function isOnComparisonList()
00702 {
00703 return $this->_blIsOnComparisonList;
00704 }
00705
00713 public function setOnComparisonList( $blOnList )
00714 {
00715 $this->_blIsOnComparisonList = $blOnList;
00716 }
00717
00725 public function setLoadParentData($blLoadParentData)
00726 {
00727 $this->_blLoadParentData = $blLoadParentData;
00728 }
00729
00735 public function getLoadParentData()
00736 {
00737 return $this->_blLoadParentData;
00738 }
00739
00749 public function setSkipAbPrice( $blSkipAbPrice = null )
00750 {
00751 $this->_blSkipAbPrice = $blSkipAbPrice;
00752 }
00753
00754
00762 public function isMultilingualField($sFieldName)
00763 {
00764 switch ($sFieldName) {
00765 case "oxlongdesc":
00766 case "oxtags":
00767 return true;
00768 }
00769
00770 return parent::isMultilingualField($sFieldName);
00771 }
00772
00778 public function isVisible()
00779 {
00780
00781
00782 if ( ( $blCanPreview = oxRegistry::getUtils()->canPreview() ) !== null ) {
00783 return $blCanPreview;
00784 }
00785
00786
00787 $sNow = date('Y-m-d H:i:s');
00788 if ( !$this->oxarticles__oxactive->value &&
00789 ( $this->oxarticles__oxactivefrom->value > $sNow ||
00790 $this->oxarticles__oxactiveto->value < $sNow
00791 )) {
00792 return false;
00793 }
00794
00795
00796 if ( $this->getConfig()->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstockflag->value == 2) {
00797 $iOnStock = $this->oxarticles__oxstock->value + $this->oxarticles__oxvarstock->value;
00798 if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
00799 $iOnStock += $this->getSession()->getBasketReservations()->getReservedAmount($this->getId());
00800 }
00801 if ( $iOnStock <= 0 ) {
00802 return false;
00803 }
00804 }
00805
00806 return true;
00807 }
00808
00817 public function assign( $aRecord )
00818 {
00819
00820 startProfile('articleAssign');
00821
00822
00823 parent::assign( $aRecord );
00824
00825 $this->oxarticles__oxnid = $this->oxarticles__oxid;
00826
00827
00828 if ($this->_blSkipAssign) {
00829 return;
00830 }
00831
00832 $this->_assignParentFieldValues();
00833 $this->_assignNotBuyableParent();
00834
00835
00836 $this->_assignStock();
00837 $this->_assignPersistentParam();
00838 $this->_assignDynImageDir();
00839 $this->_assignComparisonListFlag();
00840
00841
00842 stopProfile('articleAssign');
00843 }
00844
00845
00853 protected function _loadFromDb( $sOXID )
00854 {
00855 $sSelect = $this->buildSelectString( array( $this->getViewName().".oxid" => $sOXID ));
00856
00857 $aData = oxDb::getDb( oxDb::FETCH_MODE_ASSOC )->getRow( $sSelect );
00858
00859 return $aData;
00860 }
00861
00872 public function load( $sOXID )
00873 {
00874
00875 $this->_blNotBuyableParent = false;
00876
00877
00878 $aData = $this->_loadFromDb( $sOXID );
00879
00880 if ( $aData ) {
00881 $this->assign( $aData );
00882
00883 $this->_isLoaded = true;
00884 return true;
00885 }
00886
00887 return false;
00888 }
00889
00890
00898 public function addToRatingAverage( $iRating )
00899 {
00900 $dOldRating = $this->oxarticles__oxrating->value;
00901 $dOldCnt = $this->oxarticles__oxratingcnt->value;
00902 $this->oxarticles__oxrating->setValue(( $dOldRating * $dOldCnt + $iRating ) / ($dOldCnt + 1));
00903 $this->oxarticles__oxratingcnt->setValue($dOldCnt + 1);
00904 $dRating = ( $dOldRating * $dOldCnt + $iRating ) / ($dOldCnt + 1);
00905 $dRatingCnt = (int) ($dOldCnt + 1);
00906
00907 $oDb = oxDb::getDb();
00908 $oDb->execute( 'update oxarticles set oxarticles.oxrating = '.$dRating.',oxarticles.oxratingcnt = '.$dRatingCnt.', oxarticles.oxtimestamp = oxarticles.oxtimestamp where oxarticles.oxid = '.$oDb->quote( $this->getId() ) );
00909
00910 }
00911
00919 public function setRatingAverage( $iRating )
00920 {
00921 $this->oxarticles__oxrating = new oxField( $iRating );
00922 }
00923
00931 public function setRatingCount( $iRatingCnt )
00932 {
00933 $this->oxarticles__oxratingcnt = new oxField( $iRatingCnt );
00934 }
00935
00943 public function getArticleRatingAverage( $blIncludeVariants = false )
00944 {
00945 if ( !$blIncludeVariants ) {
00946 return round( $this->oxarticles__oxrating->value, 1);
00947 } else {
00948 $oRating = oxNew( 'oxRating' );
00949 return $oRating->getRatingAverage( $this->getId(), 'oxarticle', $this->_getVariantsIds() );
00950 }
00951 }
00952
00960 public function getArticleRatingCount( $blIncludeVariants = false )
00961 {
00962 if ( !$blIncludeVariants ) {
00963 return $this->oxarticles__oxratingcnt->value;
00964 } else {
00965 $oRating = oxNew( 'oxRating' );
00966 return $oRating->getRatingCount( $this->getId(), 'oxarticle', $this->_getVariantsIds() );
00967 }
00968 }
00969
00970
00976 public function getReviews()
00977 {
00978 $aIds = array($this->getId());
00979
00980 if ( $this->oxarticles__oxparentid->value ) {
00981 $aIds[] = $this->oxarticles__oxparentid->value;
00982 }
00983
00984
00985 if ( $this->getConfig()->getConfigParam( 'blShowVariantReviews' ) ) {
00986 $aAdd = $this->_getVariantsIds();
00987 if (is_array($aAdd)) {
00988 $aIds = array_merge($aIds, $aAdd);
00989 }
00990 }
00991
00992 $oReview = oxNew('oxreview');
00993 $oRevs = $oReview->loadList('oxarticle', $aIds);
00994
00995
00996 if ( $oRevs->count() < 1 ) {
00997 return null;
00998 }
00999
01000 return $oRevs;
01001 }
01002
01008 public function getCrossSelling()
01009 {
01010 $oCrosslist = oxNew( "oxarticlelist");
01011 $oCrosslist->loadArticleCrossSell($this->oxarticles__oxid->value);
01012 if ( $oCrosslist->count() ) {
01013 return $oCrosslist;
01014 }
01015 }
01016
01022 public function getAccessoires()
01023 {
01024 $myConfig = $this->getConfig();
01025
01026
01027 if ( !$myConfig->getConfigParam( 'bl_perfLoadAccessoires' ) ) {
01028 return;
01029 }
01030
01031 $oAcclist = oxNew( "oxarticlelist");
01032 $oAcclist->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofCrossellArticles' ));
01033 $oAcclist->loadArticleAccessoires($this->oxarticles__oxid->value);
01034
01035 if ( $oAcclist->count()) {
01036 return $oAcclist;
01037 }
01038 }
01039
01045 public function getSimilarProducts()
01046 {
01047
01048 $myConfig = $this->getConfig();
01049 if ( !$myConfig->getConfigParam( 'bl_perfLoadSimilar' ) ) {
01050 return;
01051 }
01052
01053 $sArticleTable = $this->getViewName();
01054
01055 $sAttribs = '';
01056 $iCnt = 0;
01057 $this->_getAttribsString($sAttribs, $iCnt);
01058
01059 if ( !$sAttribs) {
01060 return null;
01061 }
01062
01063 $aList = $this->_getSimList($sAttribs, $iCnt);
01064
01065 if ( count( $aList ) ) {
01066 uasort( $aList, 'cmpart');
01067
01068 $sSearch = $this->_generateSimListSearchStr($sArticleTable, $aList);
01069
01070 $oSimilarlist = oxNew( 'oxarticlelist' );
01071 $oSimilarlist->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofSimilarArticles' ));
01072 $oSimilarlist->selectString( $sSearch);
01073
01074 return $oSimilarlist;
01075 }
01076 }
01077
01083 public function getCustomerAlsoBoughtThisProducts()
01084 {
01085
01086 $myConfig = $this->getConfig();
01087 if ( !$myConfig->getConfigParam( 'bl_perfLoadCustomerWhoBoughtThis' ) ) {
01088 return;
01089 }
01090
01091
01092 $sQ = $this->_generateSearchStrForCustomerBought();
01093
01094 $oArticles = oxNew( 'oxarticlelist' );
01095 $oArticles->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofCustomerWhoArticles' ));
01096 $oArticles->selectString( $sQ );
01097 if ( $oArticles->count() ) {
01098 return $oArticles;
01099 }
01100 }
01101
01108 public function loadAmountPriceInfo()
01109 {
01110 $myConfig = $this->getConfig();
01111 if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice || !$this->_blCalcPrice || !$this->hasAmountPrice() ) {
01112 return array();
01113 }
01114
01115 if ( $this->_oAmountPriceInfo === null ) {
01116 $this->_oAmountPriceInfo = array();
01117 if ( count( ( $aAmPriceList = $this->_getAmountPriceList()->getArray() ) ) ) {
01118 $this->_oAmountPriceInfo = $this->_fillAmountPriceList( $aAmPriceList );
01119 }
01120 }
01121 return $this->_oAmountPriceInfo;
01122 }
01123
01131 public function getSelectLists($sKeyPrefix = null)
01132 {
01133
01134
01135 $sKey = $this->getId();
01136 if ( isset( $sKeyPrefix ) ) {
01137 $sKey = $sKeyPrefix.'__'.$sKey;
01138 }
01139
01140 if ( !isset( self::$_aSelList[$sKey] ) ) {
01141 $oDb = oxDb::getDb();
01142 $sSLViewName = getViewName( 'oxselectlist' );
01143
01144 $sQ = "select {$sSLViewName}.* from oxobject2selectlist join {$sSLViewName} on $sSLViewName.oxid=oxobject2selectlist.oxselnid
01145 where oxobject2selectlist.oxobjectid=%s order by oxobject2selectlist.oxsort";
01146
01147
01148 $oLists = oxNew( 'oxlist' );
01149 $oLists->init( 'oxselectlist' );
01150 $oLists->selectString( sprintf( $sQ, $oDb->quote( $this->getId() ) ) );
01151
01152
01153 if ( $oLists->count() == 0 && $this->oxarticles__oxparentid->value ) {
01154 $oLists->selectString( sprintf( $sQ, $oDb->quote( $this->oxarticles__oxparentid->value ) ) );
01155 }
01156
01157
01158
01159
01160
01161 $dVat = $this->getArticleVat();
01162
01163 $iCnt = 0;
01164 self::$_aSelList[$sKey] = array();
01165 foreach ( $oLists as $oSelectlist ) {
01166 self::$_aSelList[$sKey][$iCnt] = $oSelectlist->getFieldList( $dVat );
01167 self::$_aSelList[$sKey][$iCnt]['name'] = $oSelectlist->oxselectlist__oxtitle->value;
01168 $iCnt++;
01169 }
01170 }
01171 return self::$_aSelList[$sKey];
01172 }
01173
01181 protected function _hasAnyVariant( $blForceCoreTable = null )
01182 {
01183 $blHas = false;
01184 if ( ( $sId = $this->getId() ) ) {
01185 if ( $this->oxarticles__oxshopid->value == $this->getConfig()->getShopId() ) {
01186 $blHas = (bool) $this->oxarticles__oxvarcount->value;
01187 } else {
01188 $sArticleTable = $this->getViewName( $blForceCoreTable );
01189 $blHas = (bool) oxDb::getDb()->getOne( "select 1 from $sArticleTable where oxparentid='{$sId}'" );
01190 }
01191 }
01192 return $blHas;
01193 }
01194
01200 public function hasMdVariants()
01201 {
01202 return $this->_blHasMdVariants;
01203 }
01204
01210 public function hasIntangibleAgreement()
01211 {
01212 return $this->oxarticles__oxshowcustomagreement->value && $this->oxarticles__oxnonmaterial->value && !$this->hasDownloadableAgreement();
01213 }
01214
01220 public function hasDownloadableAgreement()
01221 {
01222 return $this->oxarticles__oxshowcustomagreement->value && $this->oxarticles__oxisdownloadable->value;
01223 }
01224
01234 public function getVariantSelections( $aFilterIds = null, $sActVariantId = null, $iLimit = 0 )
01235 {
01236 $iLimit = (int) $iLimit;
01237 if ( !isset( $this->_aVariantSelections[$iLimit] ) ) {
01238 $aVariantSelections = false;
01239 if ( $this->oxarticles__oxvarcount->value ) {
01240 $oVariants = $this->getVariants( false );
01241 $aVariantSelections = oxNew( "oxVariantHandler" )->buildVariantSelections( $this->oxarticles__oxvarname->getRawValue(), $oVariants, $aFilterIds, $sActVariantId, $iLimit );
01242
01243 if ( !empty($oVariants) && empty( $aVariantSelections['rawselections'] ) ) {
01244 $aVariantSelections = false;
01245 }
01246 }
01247 $this->_aVariantSelections[$iLimit] = $aVariantSelections;
01248 }
01249
01250 return $this->_aVariantSelections[$iLimit];
01251 }
01252
01261 public function getSelections( $iLimit = null, $aFilter = null )
01262 {
01263 $sId = $this->getId() . ( (int) $iLimit );
01264 if ( !array_key_exists( $sId, self::$_aSelections ) ) {
01265
01266 $oDb = oxDb::getDb();
01267 $sSLViewName = getViewName( 'oxselectlist' );
01268
01269 $sQ = "select {$sSLViewName}.* from oxobject2selectlist join {$sSLViewName} on $sSLViewName.oxid=oxobject2selectlist.oxselnid
01270 where oxobject2selectlist.oxobjectid=%s order by oxobject2selectlist.oxsort";
01271
01272 if ( ( $iLimit = (int) $iLimit ) ) {
01273 $sQ .= " limit $iLimit ";
01274 }
01275
01276
01277 $dVat = 0;
01278 if ( ( $oPrice = $this->getPrice() ) != null ) {
01279 $dVat = $oPrice->getVat();
01280 }
01281
01282
01283 $oList = oxNew( 'oxlist' );
01284 $oList->init( 'oxselectlist' );
01285 $oList->getBaseObject()->setVat( $dVat );
01286 $oList->selectString( sprintf( $sQ, $oDb->quote( $this->getId() ) ) );
01287
01288
01289 if ( $oList->count() == 0 && $this->oxarticles__oxparentid->value ) {
01290 $oList->selectString( sprintf( $sQ, $oDb->quote( $this->oxarticles__oxparentid->value ) ) );
01291 }
01292
01293 self::$_aSelections[$sId] = $oList->count() ? $oList : false;
01294 }
01295
01296 if ( self::$_aSelections[$sId] ) {
01297
01298 $aFilter = ( $aFilter === null ) ? oxConfig::getParameter( "sel" ) : $aFilter;
01299 if ( $aFilter ) {
01300 $iSelIdx = 0;
01301 foreach ( self::$_aSelections[$sId] as $oSelection ) {
01302 if ( isset( $aFilter[$iSelIdx] ) ) {
01303 $oSelection->setActiveSelectionByIndex( $aFilter[$iSelIdx] );
01304 }
01305 $iSelIdx++;
01306 }
01307 }
01308 }
01309
01310 return self::$_aSelections[$sId];
01311 }
01312
01322 protected function _loadVariantList( $blSimple, $blRemoveNotOrderables = true, $blForceCoreTable = null )
01323 {
01324 $oVariants = array();
01325 if ( ( $sId = $this->getId() ) ) {
01326
01327 self::$_aLoadedParents[$sId] = $this;
01328
01329 $myConfig = $this->getConfig();
01330
01331 if ( !$this->_blLoadVariants ||
01332 ( !$this->isAdmin() && !$myConfig->getConfigParam( 'blLoadVariants') ) ||
01333 ( !$this->isAdmin() && !$this->oxarticles__oxvarcount->value ) ) {
01334 return $oVariants;
01335 }
01336
01337
01338 $sCacheKey = $blSimple ? "simple" : "full";
01339 if ( $blRemoveNotOrderables ) {
01340 if ( isset( $this->_aVariants[$sCacheKey] ) ) {
01341 return $this->_aVariants[$sCacheKey];
01342 } else {
01343 $this->_aVariants[$sCacheKey] = & $oVariants;
01344 }
01345 } elseif ( !$blRemoveNotOrderables ) {
01346 if ( isset( $this->_aVariantsWithNotOrderables[$sCacheKey] ) ) {
01347 return $this->_aVariantsWithNotOrderables[$sCacheKey];
01348 } else {
01349 $this->_aVariantsWithNotOrderables[$sCacheKey] = & $oVariants;
01350 }
01351 }
01352
01353 if ( ( $this->_blHasVariants = $this->_hasAnyVariant( $blForceCoreTable ) ) ) {
01354
01355
01356 if ( $blSimple ) {
01357 $oVariants = oxNew( 'oxsimplevariantlist' );
01358 $oVariants->setParent( $this );
01359 } else {
01360
01361 $oVariants = oxNew( 'oxarticlelist' );
01362 $oVariants->getBaseObject()->modifyCacheKey( '_variants' );
01363 }
01364
01365 startProfile("selectVariants");
01366 $blUseCoreTable = (bool) $blForceCoreTable;
01367 $oBaseObject = $oVariants->getBaseObject();
01368 $oBaseObject->setLanguage( $this->getLanguage() );
01369
01370
01371 $sArticleTable = $this->getViewName( $blUseCoreTable );
01372
01373 $sSelect = "select ".$oBaseObject->getSelectFields( $blUseCoreTable )." from $sArticleTable where " .
01374 $this->getActiveCheckQuery( $blUseCoreTable ) .
01375 $this->getVariantsQuery( $blRemoveNotOrderables, $blUseCoreTable ) .
01376 " order by $sArticleTable.oxsort";
01377
01378
01379 $oVariants->selectString( $sSelect );
01380
01381
01382 if ( $myConfig->getConfigParam( 'blUseMultidimensionVariants' ) ) {
01383 $oMdVariants = oxNew( "oxVariantHandler" );
01384 $this->_blHasMdVariants = $oMdVariants->isMdVariant( $oVariants->current() );
01385 }
01386 stopProfile("selectVariants");
01387 }
01388
01389
01390 if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && $this->_blHasVariants ) {
01391 $this->_blNotBuyableParent = true;
01392 }
01393
01394
01395 if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && count( $oVariants ) == 0 && $this->_blHasVariants ) {
01396 $this->_blNotBuyable = true;
01397 }
01398 }
01399
01400 return $oVariants;
01401 }
01402
01411 public function getFullVariants( $blRemoveNotOrderables = true, $blForceCoreTable = null )
01412 {
01413 return $this->_loadVariantList( false, $blRemoveNotOrderables, $blForceCoreTable );
01414 }
01415
01424 public function getVariants( $blRemoveNotOrderables = true, $blForceCoreTable = null )
01425 {
01426 return $this->_loadVariantList( $this->_isInList(), $blRemoveNotOrderables, $blForceCoreTable );
01427 }
01428
01434 public function getSimpleVariants()
01435 {
01436 if ( $this->oxarticles__oxvarcount->value) {
01437 return $this->getVariants();
01438 }
01439 }
01440
01449 public function getAdminVariants( $sLanguage = null )
01450 {
01451 $oVariants = oxNew( 'oxarticlelist');
01452 if ( ( $sId = $this->getId() ) ) {
01453
01454 $oBaseObj = $oVariants->getBaseObject();
01455
01456 if ( is_null( $sLanguage ) ) {
01457 $oBaseObj->setLanguage( oxRegistry::getLang()->getBaseLanguage() );
01458 } else {
01459 $oBaseObj->setLanguage( $sLanguage );
01460 }
01461
01462 $sSql = "select * from ".$oBaseObj->getViewName()." where oxparentid = '{$sId}' order by oxsort ";
01463 $oVariants->selectString( $sSql );
01464
01465
01466 if ( !$this->getConfig()->getConfigParam( 'blVariantParentBuyable' ) && ( $oVariants->count() > 0 ) ) {
01467
01468 $this->_blNotBuyableParent = true;
01469 }
01470 }
01471
01472 return $oVariants;
01473 }
01474
01482 public function getCategory()
01483 {
01484 $oCategory = oxNew( 'oxcategory' );
01485 $oCategory->setLanguage( $this->getLanguage() );
01486
01487
01488 $sOXID = $this->getId();
01489 if ( isset( $this->oxarticles__oxparentid->value ) && $this->oxarticles__oxparentid->value ) {
01490 $sOXID = $this->oxarticles__oxparentid->value;
01491 }
01492
01493 if ( $sOXID ) {
01494
01495 if ( !isset( $this->_aCategoryCache[ $sOXID ] ) ) {
01496 startPRofile( 'getCategory' );
01497 $oStr = getStr();
01498 $sWhere = $oCategory->getSqlActiveSnippet();
01499 $sSelect = $this->_generateSearchStr( $sOXID );
01500 $sSelect .= ( $oStr->strstr( $sSelect, 'where' )?' and ':' where ') . $sWhere . " order by oxobject2category.oxtime limit 1";
01501
01502
01503 if ( !$oCategory->assignRecord( $sSelect ) ) {
01504
01505 $sSelect = $this->_generateSearchStr( $sOXID, true );
01506 $sSelect .= ( $oStr->strstr( $sSelect, 'where' )?' and ':' where ') . $sWhere . " limit 1";
01507
01508
01509 if ( !$oCategory->assignRecord( $sSelect ) ) {
01510 $oCategory = null;
01511 }
01512 }
01513
01514 $this->_aCategoryCache[ $sOXID ] = $oCategory;
01515 stopPRofile( 'getCategory' );
01516 } else {
01517
01518 $oCategory = $this->_aCategoryCache[ $sOXID ];
01519 }
01520 }
01521
01522 return $oCategory;
01523 }
01524
01533 public function getCategoryIds( $blActCats = false, $blSkipCache = false )
01534 {
01535 if ( isset( self::$_aArticleCats[$this->getId()] ) && !$blSkipCache ) {
01536 return self::$_aArticleCats[$this->getId()];
01537 }
01538
01539
01540 $sOXID = $this->getId();
01541
01542 $aRet = $this->_getArticleCategories( $sOXID, $blActCats );
01543
01544 if (isset( $this->oxarticles__oxparentid->value) && $this->oxarticles__oxparentid->value) {
01545 $aRet = array_merge( $aRet, $this->_getArticleCategories( $this->oxarticles__oxparentid->value, $blActCats ) );
01546 }
01547
01548
01549 $sSql = $this->getSqlForPriceCategories();
01550
01551 $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
01552 $rs = $oDb->select( $sSql );
01553
01554
01555 if ($rs != false && $rs->recordCount() > 0) {
01556 while (!$rs->EOF) {
01557
01558 if ( is_array( $rs->fields ) ) {
01559 $rs->fields = array_change_key_case( $rs->fields, CASE_LOWER );
01560 }
01561
01562
01563 if ( !$aRet[$rs->fields['oxid']] ) {
01564 $aRet[] = $rs->fields['oxid'];
01565 }
01566 $rs->moveNext();
01567 }
01568 }
01569
01570 return self::$_aArticleCats[$this->getId()] = $aRet;
01571 }
01572
01581 protected function _getArticleCategories( $sOXID, $blActCats = false )
01582 {
01583
01584 $sSql = $this->_getSelectCatIds( $sOXID, $blActCats );
01585 $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
01586 $rs = $oDb->select( $sSql );
01587
01588
01589 $aRet = array();
01590
01591 if ($rs != false && $rs->recordCount() > 0) {
01592 while (!$rs->EOF) {
01593 $aRet[] = $rs->fields['oxcatnid'];
01594 $rs->moveNext();
01595 }
01596 }
01597
01598 return $aRet;
01599 }
01600
01609 protected function _getSelectCatIds( $sOXID, $blActCats = false )
01610 {
01611 $sO2CView = $this->_getObjectViewName('oxobject2category');
01612 $sCatView = $this->_getObjectViewName('oxcategories');
01613 $sSelect = "select oxobject2category.oxcatnid as oxcatnid from $sO2CView as oxobject2category left join $sCatView as oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
01614 $sSelect .= 'where oxobject2category.oxobjectid='.oxDb::getDb()->quote($sOXID).' and oxcategories.oxid is not null and oxcategories.oxactive = 1 ';
01615 if ( $blActCats ) {
01616 $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 ";
01617 }
01618 $sSelect .= 'order by oxobject2category.oxtime ';
01619 return $sSelect;
01620 }
01621
01631 public function getVendor( $blShopCheck = true )
01632 {
01633 if ( ( $sVendorId = $this->getVendorId() ) ) {
01634 $oVendor = oxNew( 'oxvendor' );
01635 } elseif ( !$blShopCheck && $this->oxarticles__oxvendorid->value ) {
01636 $oVendor = oxNew( 'oxi18n' );
01637 $oVendor->init('oxvendor');
01638 $oVendor->setReadOnly( true );
01639 $sVendorId = $this->oxarticles__oxvendorid->value;
01640 }
01641 if ( $sVendorId && $oVendor->load( $sVendorId ) && $oVendor->oxvendor__oxactive->value ) {
01642
01643 return $oVendor;
01644 }
01645 return null;
01646 }
01647
01655 public function getVendorId( $blForceReload = false )
01656 {
01657 $sVendorId = false;
01658 if ( $this->oxarticles__oxvendorid->value ) {
01659 $sVendorId = $this->oxarticles__oxvendorid->value;
01660
01661 }
01662 return $sVendorId;
01663 }
01664
01672 public function getManufacturerId( $blForceReload = false )
01673 {
01674 $sManufacturerId = false;
01675 if ( $this->oxarticles__oxmanufacturerid->value ) {
01676
01677 $sManufacturerId = $this->oxarticles__oxmanufacturerid->value;
01678
01679 }
01680 return $sManufacturerId;
01681 }
01682
01692 public function getManufacturer( $blShopCheck = true )
01693 {
01694 $oManufacturer = oxNew( 'oxmanufacturer' );;
01695 if ( !( $sManufacturerId = $this->getManufacturerId() ) &&
01696 !$blShopCheck && $this->oxarticles__oxmanufacturerid->value ) {
01697 $oManufacturer->setReadOnly( true );
01698 $sManufacturerId = $this->oxarticles__oxmanufacturerid->value;
01699 }
01700
01701 if ( $sManufacturerId && $oManufacturer->load( $sManufacturerId ) ) {
01702 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadManufacturerTree' ) ) {
01703 $oManufacturer->setReadOnly( true );
01704 }
01705 $oManufacturer = $oManufacturer->oxmanufacturers__oxactive->value ? $oManufacturer : null;
01706 } else {
01707 $oManufacturer = null;
01708 }
01709
01710 return $oManufacturer;
01711 }
01712
01720 public function inCategory( $sCatNid)
01721 {
01722 return in_array( $sCatNid, $this->getCategoryIds());
01723 }
01724
01733 public function isAssignedToCategory( $sCatId )
01734 {
01735
01736 $sOXID = $this->getId();
01737 if ( isset( $this->oxarticles__oxparentid->value) && $this->oxarticles__oxparentid->value) {
01738 $sOXID = $this->oxarticles__oxparentid->value;
01739 }
01740
01741 $oDb = oxDb::getDb();
01742 $sSelect = $this->_generateSelectCatStr( $sOXID, $sCatId);
01743 $sOXID = $oDb->getOne( $sSelect );
01744
01745 if ( isset( $sOXID) && $sOXID) {
01746 return true;
01747 }
01748
01749
01750 if ( $this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) && $this->_blLoadPrice ) {
01751 $dPriceFromTo = $this->getPrice()->getBruttoPrice();
01752 if ( $dPriceFromTo > 0) {
01753 $sSelect = $this->_generateSelectCatStr( $sOXID, $sCatId, $dPriceFromTo);
01754 $sOXID = $oDb->getOne( $sSelect );
01755
01756 if ( isset( $sOXID) && $sOXID) {
01757 return true;
01758 }
01759 }
01760 }
01761 return false;
01762 }
01763
01769 public function getTPrice()
01770 {
01771 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
01772 return;
01773 }
01774
01775
01776 if ( $this->_oTPrice !== null ) {
01777 return $this->_oTPrice;
01778 }
01779
01780 $oPrice = $this->_getPriceObject();
01781
01782 $dBasePrice = $this->oxarticles__oxtprice->value;
01783 $dBasePrice = $this->_preparePrice( $dBasePrice, $this->getArticleVat() );
01784
01785 $oPrice->setPrice( $dBasePrice );
01786
01787 $this->_applyVat( $oPrice, $this->getArticleVat() );
01788 $this->_applyCurrency( $oPrice );
01789
01790 if ( $this->isParentNotBuyable() ) {
01791
01792 $oPrice2 = $this->getVarMinPrice();
01793 } else {
01794
01795 $oPrice2 = $this->getPrice();
01796 }
01797
01798 if ( $oPrice->getPrice() <= $oPrice2->getPrice() ) {
01799
01800 return;
01801 }
01802
01803 $this->_oTPrice = $oPrice;
01804
01805 return $this->_oTPrice;
01806 }
01807
01813 public function skipDiscounts()
01814 {
01815
01816 if ( $this->_blSkipDiscounts !== null ) {
01817 return $this->_blSkipDiscounts;
01818 }
01819
01820 if ( $this->oxarticles__oxskipdiscounts->value ) {
01821 return true;
01822 }
01823
01824
01825 $this->_blSkipDiscounts = false;
01826 if ( oxRegistry::get("oxDiscountList")->hasSkipDiscountCategories() ) {
01827
01828 $oDb = oxDb::getDb();
01829 $sO2CView = getViewName( 'oxobject2category', $this->getLanguage() );
01830 $sViewName = getViewName( 'oxcategories', $this->getLanguage() );
01831 $sSelect = "select 1 from $sO2CView as $sO2CView left join {$sViewName} on {$sViewName}.oxid = $sO2CView.oxcatnid
01832 where $sO2CView.oxobjectid=".$oDb->quote( $this->getId() )." and {$sViewName}.oxactive = 1 and {$sViewName}.oxskipdiscounts = '1' ";
01833 $this->_blSkipDiscounts = ( $oDb->getOne( $sSelect ) == 1 );
01834 }
01835
01836 return $this->_blSkipDiscounts;
01837 }
01838
01846 public function setPrice(oxPrice $oPrice)
01847 {
01848 $this->_oPrice = $oPrice;
01849 }
01850
01859 public function getBasePrice( $dAmount = 1 )
01860 {
01861
01862
01863
01864
01865 $myConfig = $this->getConfig();
01866 if( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice )
01867 return;
01868
01869
01870 $dPrice = $this->_getAmountPrice( $dAmount );
01871
01872
01873 return $dPrice;
01874 }
01875
01883 public function getPrice( $dAmount = 1 )
01884 {
01885 $myConfig = $this->getConfig();
01886
01887 if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
01888 return;
01889 }
01890
01891
01892 if ( $dAmount != 1 || $this->_oPrice === null ) {
01893
01894
01895 $dBasePrice = $this->getBasePrice( $dAmount );
01896 $dBasePrice = $this->_preparePrice( $dBasePrice, $this->getArticleVat() );
01897
01898 $oPrice = $this->_getPriceObject();
01899
01900 $oPrice->setPrice( $dBasePrice );
01901
01902
01903 if ( !$this->_blCalcPrice && $dAmount == 1 ) {
01904 return $this->_oPrice = $oPrice;
01905 }
01906
01907 $this->_calculatePrice( $oPrice );
01908 if ( $dAmount != 1 ) {
01909 return $oPrice;
01910 }
01911
01912 $this->_oPrice = $oPrice;
01913 }
01914 return $this->_oPrice;
01915 }
01916
01925 protected function _calculatePrice( $oPrice, $dVat = null )
01926 {
01927
01928 if ( isset( $dVat ) || !$this->getConfig()->getConfigParam( 'bl_perfCalcVatOnlyForBasketOrder' ) ) {
01929 $this->_applyVAT( $oPrice, isset( $dVat ) ? $dVat : $this->getArticleVat() );
01930 }
01931
01932
01933 $this->_applyCurrency( $oPrice );
01934
01935 if ( !$this->skipDiscounts() ) {
01936 $oDiscountList = oxRegistry::get("oxDiscountList");
01937 $aDiscounts = $oDiscountList->getArticleDiscounts( $this, $this->getArticleUser() );
01938
01939 reset( $aDiscounts );
01940 foreach ( $aDiscounts as $oDiscount ) {
01941 $oPrice->setDiscount($oDiscount->getAddSum(), $oDiscount->getAddSumType());
01942 }
01943 $oPrice->calculateDiscount();
01944 }
01945
01946 return $oPrice;
01947 }
01948
01956 public function setArticleUser($oUser)
01957 {
01958 $this->_oUser = $oUser;
01959 }
01960
01966 public function getArticleUser()
01967 {
01968 if ($this->_oUser) {
01969 return $this->_oUser;
01970 }
01971 return $this->getUser();
01972 }
01973
01983 public function getBasketPrice( $dAmount, $aSelList, $oBasket )
01984 {
01985 $oUser = $oBasket->getBasketUser();
01986 $this->setArticleUser( $oUser );
01987
01988 $oBasketPrice = $this->_getPriceObject( $oBasket->isCalculationModeNetto() );
01989
01990
01991 $dBasePrice = $this->getBasePrice( $dAmount );
01992
01993 $dBasePrice = $this->_modifySelectListPrice( $dBasePrice, $aSelList );
01994 $dBasePrice = $this->_preparePrice( $dBasePrice, $this->getArticleVat(), $oBasket->isCalculationModeNetto() );
01995
01996
01997
01998
01999 $oBasketPrice->setPrice( $dBasePrice );
02000
02001 $dVat = oxRegistry::get("oxVatSelector")->getBasketItemVat( $this, $oBasket );
02002 $this->_calculatePrice( $oBasketPrice, $dVat );
02003
02004
02005 return $oBasketPrice;
02006 }
02007
02016 public function delete( $sOXID = null )
02017 {
02018 if ( !$sOXID ) {
02019 $sOXID = $this->getId();
02020 }
02021 if ( !$sOXID ) {
02022 return false;
02023 }
02024
02025
02026
02027
02028 $this->_deleteVariantRecords( $sOXID );
02029 $this->load( $sOXID );
02030 $this->_deletePics();
02031 $this->_onChangeResetCounts( $sOXID, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
02032
02033
02034 parent::delete( $sOXID );
02035
02036 $rs = $this->_deleteRecords( $sOXID );
02037
02038 oxRegistry::get("oxSeoEncoderArticle")->onDeleteArticle($this);
02039
02040 $this->onChange( ACTION_DELETE, $sOXID, $this->oxarticles__oxparentid->value );
02041
02042 return $rs->EOF;
02043 }
02044
02053 public function reduceStock($dAmount, $blAllowNegativeStock = false)
02054 {
02055 $this->beforeUpdate();
02056
02057 $iStockCount = $this->oxarticles__oxstock->value - $dAmount;
02058 if (!$blAllowNegativeStock && ($iStockCount < 0)) {
02059 $dAmount += $iStockCount;
02060 $iStockCount = 0;
02061 }
02062 $this->oxarticles__oxstock = new oxField($iStockCount);
02063
02064 $oDb = oxDb::getDb();
02065 $oDb->execute( 'update oxarticles set oxarticles.oxstock = '.$oDb->quote( $iStockCount ).' where oxarticles.oxid = '.$oDb->quote( $this->getId() ) );
02066 $this->onChange( ACTION_UPDATE_STOCK );
02067 return $dAmount;
02068 }
02069
02078 public function updateSoldAmount( $dAmount = 0 )
02079 {
02080 if ( !$dAmount ) {
02081 return;
02082 }
02083
02084 $this->beforeUpdate();
02085
02086
02087 if ( !$this->oxarticles__oxparentid->value ) {
02088
02089 $dAmount = (double) $dAmount;
02090 $oDb = oxDb::getDb();
02091 $rs = $oDb->execute( "update oxarticles set oxarticles.oxsoldamount = oxarticles.oxsoldamount + $dAmount where oxarticles.oxid = ".$oDb->quote($this->oxarticles__oxid->value));
02092 } elseif ( $this->oxarticles__oxparentid->value) {
02093
02094 $oUpdateArticle = $this->getParentArticle();
02095 $oUpdateArticle->updateSoldAmount( $dAmount );
02096 }
02097
02098 $this->onChange( ACTION_UPDATE );
02099
02100 return $rs;
02101 }
02102
02108 public function disableReminder()
02109 {
02110 $oDb = oxDb::getDb();
02111 return $oDb->execute( "update oxarticles set oxarticles.oxremindactive = 2 where oxarticles.oxid = ".$oDb->quote($this->oxarticles__oxid->value));
02112 }
02113
02119 public function save()
02120 {
02121 if ( ( $blRet = parent::save() ) ) {
02122
02123 $this->_saveArtLongDesc();
02124 }
02125
02126 return $blRet;
02127 }
02128
02134 public function resetParent()
02135 {
02136 $sParentId = $this->oxarticles__oxparentid;
02137 $this->oxarticles__oxparentid = new oxField( '', oxField::T_RAW );
02138 $this->_blAllowEmptyParentId = true;
02139 $this->save();
02140 $this->_blAllowEmptyParentId = false;
02141
02142 if ( $sParentId !== '' ) {
02143 $this->onChange( ACTION_UPDATE, null, $sParentId );
02144 }
02145 }
02146
02147
02154 public function getPictureGallery()
02155 {
02156 $myConfig = $this->getConfig();
02157
02158
02159 $blMorePic = false;
02160 $aArtPics = array();
02161 $aArtIcons = array();
02162 $iActPicId = 1;
02163 $sActPic = $this->getPictureUrl( $iActPicId );
02164
02165 if ( oxConfig::getParameter( 'actpicid' ) ) {
02166 $iActPicId = oxConfig::getParameter('actpicid');
02167 }
02168
02169 $oStr = getStr();
02170 $iCntr = 0;
02171 $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
02172 $blCheckActivePicId = true;
02173
02174 for ( $i = 1; $i <= $iPicCount; $i++) {
02175 $sPicVal = $this->getPictureUrl( $i );
02176 $sIcoVal = $this->getIconUrl( $i );
02177 if ( !$oStr->strstr($sIcoVal, 'nopic_ico.jpg') && !$oStr->strstr($sIcoVal, 'nopic.jpg') &&
02178 !$oStr->strstr($sPicVal, 'nopic_ico.jpg') && !$oStr->strstr($sPicVal, 'nopic.jpg') ) {
02179 if ($iCntr) {
02180 $blMorePic = true;
02181 }
02182 $aArtIcons[$i]= $sIcoVal;
02183 $aArtPics[$i]= $sPicVal;
02184 $iCntr++;
02185
02186 if ($iActPicId == $i) {
02187 $sActPic = $sPicVal;
02188 $blCheckActivePicId = false;
02189 }
02190
02191 } else if ( $blCheckActivePicId && $iActPicId <= $i) {
02192
02193
02194 $iActPicId++;
02195 }
02196 }
02197
02198 $blZoomPic = false;
02199 $aZoomPics = array();
02200 $iZoomPicCount = $myConfig->getConfigParam( 'iPicCount' );
02201
02202 for ( $j = 1,$c = 1; $j <= $iZoomPicCount; $j++) {
02203 $sVal = $this->getZoomPictureUrl($j);
02204
02205 if ( $sVal && !$oStr->strstr($sVal, 'nopic.jpg')) {
02206 $blZoomPic = true;
02207 $aZoomPics[$c]['id'] = $c;
02208 $aZoomPics[$c]['file'] = $sVal;
02209
02210 if (!$sVal) {
02211 $aZoomPics[$c]['file'] = "nopic.jpg";
02212 }
02213 $c++;
02214 }
02215 }
02216
02217 $aPicGallery = array('ActPicID' => $iActPicId,
02218 'ActPic' => $sActPic,
02219 'MorePics' => $blMorePic,
02220 'Pics' => $aArtPics,
02221 'Icons' => $aArtIcons,
02222 'ZoomPic' => $blZoomPic,
02223 'ZoomPics' => $aZoomPics);
02224
02225 return $aPicGallery;
02226 }
02227
02241 public function onChange($sAction = null, $sOXID = null, $sParentID = null)
02242 {
02243 $myConfig = $this->getConfig();
02244
02245 if (!isset($sOXID)) {
02246 if ( $this->getId()) {
02247 $sOXID = $this->getId();
02248 }
02249 if (!isset ($sOXID)) {
02250 $sOXID = $this->oxarticles__oxid->value;
02251 }
02252 if ($this->oxarticles__oxparentid->value) {
02253 $sParentID = $this->oxarticles__oxparentid->value;
02254 }
02255 }
02256 if (!isset($sOXID)) {
02257 return;
02258 }
02259
02260
02261 if ( $myConfig->getConfigParam( 'blUseStock' ) ) {
02262
02263
02264 if (!isset($sParentID)) {
02265 $oDb = oxDb::getDb();
02266 $sQ = 'select oxparentid from oxarticles where oxid = '.$oDb->quote($sOXID);
02267 $sParentID = $oDb->getOne( $sQ );
02268 }
02269
02270 if ($sParentID) {
02271 $this->_onChangeUpdateStock($sParentID);
02272 }
02273 }
02274
02275
02276 if ($sParentID) {
02277 $this->_onChangeUpdateVarCount($sParentID);
02278 }
02279
02280 $sId = ( $sParentID ) ? $sParentID : $sOXID;
02281 $this->_setVarMinMaxPrice( $sId );
02282
02283
02284
02285 if ( $sAction === ACTION_UPDATE_STOCK ) {
02286 $this->_onChangeStockResetCount( $sOXID );
02287 }
02288
02289 }
02290
02297 public function getCustomVAT()
02298 {
02299 if ( isset($this->oxarticles__oxvat->value) ) {
02300 return $this->oxarticles__oxvat->value;
02301 }
02302 }
02303
02312 public function checkForStock( $dAmount, $dArtStockAmount = 0 )
02313 {
02314 $myConfig = $this->getConfig();
02315 if ( !$myConfig->getConfigParam( 'blUseStock' ) ) {
02316 return true;
02317 }
02318
02319 $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
02320
02321 $sQ = 'select oxstock, oxstockflag from oxarticles where oxid = '.$oDb->quote( $this->getId() );
02322 $rs = $oDb->select( $sQ );
02323
02324 $iOnStock = 0;
02325 $iStockFlag = 0;
02326 if ( $rs !== false && $rs->recordCount() > 0 ) {
02327 $iOnStock = $rs->fields['oxstock'] - $dArtStockAmount;
02328 $iStockFlag = $rs->fields['oxstockflag'];
02329
02330
02331 if ( $iStockFlag == 1 || $iStockFlag == 4) {
02332 return true;
02333 }
02334 if ( !$myConfig->getConfigParam( 'blAllowUnevenAmounts' ) ) {
02335 $iOnStock = floor( $iOnStock );
02336 }
02337 }
02338 if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
02339 $iOnStock += $this->getSession()->getBasketReservations()->getReservedAmount($this->getId());
02340 }
02341 if ( $iOnStock >= $dAmount ) {
02342 return true;
02343 } else {
02344 if ( $iOnStock > 0 ) {
02345 return $iOnStock;
02346 } else {
02347 $oEx = oxNew( 'oxArticleInputException' );
02348 $oEx->setMessage( 'EXCEPTION_ARTICLE_ARTICELNOTBUYABLE' );
02349 oxRegistry::get("oxUtilsView")->addErrorToDisplay( $oEx );
02350 return false;
02351 }
02352 }
02353 }
02354
02355
02361 public function getLongDescription()
02362 {
02363 if ( $this->_oLongDesc === null ) {
02364
02365 $this->_oLongDesc = new oxField();
02366
02367
02368
02369 $sOxid = $this->getId();
02370 $sViewName = getViewName( 'oxartextends', $this->getLanguage() );
02371
02372 $oDb = oxDb::getDb();
02373 $sDbValue = $oDb->getOne( "select oxlongdesc from {$sViewName} where oxid = " . $oDb->quote( $sOxid ) );
02374
02375 if ( $sDbValue != false ) {
02376 $this->_oLongDesc->setValue( $sDbValue, oxField::T_RAW );
02377 } elseif ( $this->oxarticles__oxparentid->value ) {
02378 if ( !$this->isAdmin() || $this->_blLoadParentData ) {
02379 $this->_oLongDesc->setValue( $this->getParentArticle()->getLongDescription()->getRawValue(), oxField::T_RAW );
02380 }
02381 }
02382 }
02383 return $this->_oLongDesc;
02384 }
02385
02392 public function getLongDesc()
02393 {
02394 return oxRegistry::get("oxUtilsView")->parseThroughSmarty( $this->getLongDescription()->getRawValue(), $this->getId().$this->getLanguage(), null, true );
02395 }
02396
02404 public function setArticleLongDesc( $sDesc )
02405 {
02406
02407
02408 $this->_oLongDesc = new oxField( $sDesc, oxField::T_RAW );
02409 $this->oxarticles__oxlongdesc = new oxField( $sDesc, oxField::T_RAW );
02410 }
02411
02417 public function getAttributes()
02418 {
02419 if ( $this->_oAttributeList === null ) {
02420 $this->_oAttributeList = oxNew( 'oxattributelist' );
02421 $this->_oAttributeList->loadAttributes( $this->getId(), $this->getParentId() );
02422 }
02423
02424 return $this->_oAttributeList;
02425 }
02426
02432 public function getAttributesDisplayableInBasket()
02433 {
02434 if ( $this->_oAttributeList === null ) {
02435 $this->_oAttributeList = oxNew( 'oxattributelist' );
02436 $this->_oAttributeList->loadAttributesDisplayableInBasket( $this->getId(), $this->getParentId() );
02437 }
02438
02439 return $this->_oAttributeList;
02440 }
02441
02442
02451 public function appendLink( $sAddParams, $iLang = null )
02452 {
02453 if ( $sAddParams ) {
02454 if ( $iLang === null ) {
02455 $iLang = $this->getLanguage();
02456 }
02457
02458 $this->_aSeoAddParams[$iLang] = isset( $this->_aSeoAddParams[$iLang] ) ? $this->_aSeoAddParams[$iLang] . "&" : "";
02459 $this->_aSeoAddParams[$iLang] .= $sAddParams;
02460 }
02461 }
02462
02471 public function getBaseSeoLink( $iLang, $blMain = false )
02472 {
02473 $oEncoder = oxRegistry::get("oxSeoEncoderArticle");
02474 if ( !$blMain ) {
02475 return $oEncoder->getArticleUrl( $this, $iLang, $this->getLinkType() );
02476 }
02477 return $oEncoder->getArticleMainUrl( $this, $iLang );
02478 }
02479
02488 public function getLink( $iLang = null, $blMain = false )
02489 {
02490 if ( !oxRegistry::getUtils()->seoIsActive() ) {
02491 return $this->getStdLink( $iLang );
02492 }
02493
02494 if ( $iLang === null ) {
02495 $iLang = $this->getLanguage();
02496 }
02497
02498 $iLinkType = $this->getLinkType();
02499 if ( !isset( $this->_aSeoUrls[$iLang][$iLinkType] ) ) {
02500 $this->_aSeoUrls[$iLang][$iLinkType] = $this->getBaseSeoLink( $iLang, $blMain );
02501 }
02502
02503 $sUrl = $this->_aSeoUrls[$iLang][$iLinkType];
02504 if ( isset($this->_aSeoAddParams[$iLang])) {
02505 $sUrl .= ( ( strpos( $sUrl.$this->_aSeoAddParams[$iLang], '?' ) === false ) ? '?' : '&' ).$this->_aSeoAddParams[$iLang];
02506 }
02507
02508 return $sUrl;
02509 }
02510
02519 public function getMainLink( $iLang = null )
02520 {
02521 return $this->getLink( $iLang, true );
02522 }
02523
02531 public function setLinkType( $iType )
02532 {
02533
02534 $this->_sDetailLink = null;
02535
02536
02537 $this->_iLinkType = (int) $iType;
02538 }
02539
02545 public function getLinkType()
02546 {
02547 return $this->_iLinkType;
02548 }
02549
02558 public function appendStdLink( $sAddParams, $iLang = null )
02559 {
02560 if ( $sAddParams ) {
02561 if ( $iLang === null ) {
02562 $iLang = $this->getLanguage();
02563 }
02564
02565 $this->_aStdAddParams[$iLang] = isset( $this->_aStdAddParams[$iLang] ) ? $this->_aStdAddParams[$iLang] . "&" : "";
02566 $this->_aStdAddParams[$iLang] .= $sAddParams;
02567 }
02568 }
02569
02579 public function getBaseStdLink( $iLang, $blAddId = true, $blFull = true )
02580 {
02581 $sUrl = '';
02582 if ( $blFull ) {
02583
02584 $sUrl = $this->getConfig()->getShopUrl( $iLang, false );
02585 }
02586
02587 $sUrl .= "index.php?cl=details" . ( $blAddId ? "&anid=".$this->getId() : "" );
02588 return $sUrl . ( isset( $this->_aStdAddParams[$iLang] ) ? "&". $this->_aStdAddParams[$iLang] : "" );
02589 }
02590
02599 public function getStdLink( $iLang = null, $aParams = array() )
02600 {
02601 if ( $iLang === null ) {
02602 $iLang = $this->getLanguage();
02603 }
02604
02605 if ( !isset( $this->_aStdUrls[$iLang] ) ) {
02606 $this->_aStdUrls[$iLang] = $this->getBaseStdLink( $iLang );
02607 }
02608
02609 return oxRegistry::get("oxUtilsUrl")->processUrl( $this->_aStdUrls[$iLang], true, $aParams, $iLang );
02610 }
02611
02621 public function getStdTagLink( $sTag )
02622 {
02623 $oArticleTags = oxNew('oxarticletaglist');
02624 $oArticleTags->setArticleId( $this->getId() );
02625 return $oArticleTags->getStdTagLink($sTag);
02626 }
02627
02635 public function getTags()
02636 {
02637 $oArticleTags = oxNew('oxarticletaglist');
02638 $oArticleTags->load( $this->getId() );
02639 return $oArticleTags->get()->__toString();
02640 }
02641
02651 public function saveTags($sTags)
02652 {
02653
02654 if ( !$this->allowDerivedUpdate() ) {
02655 return false;
02656 }
02657 $oArticleTags = oxNew('oxarticletaglist');
02658 $oArticleTags->setArticleId( $this->getId() );
02659 $oArticleTags->set( $sTags );
02660 $oArticleTags->save();
02661 }
02662
02672 public function addTag($sTag)
02673 {
02674 $oArticleTags = oxNew('oxarticletaglist');
02675 $oArticleTags->load( $this->getId() );
02676 $oArticleTags->addTag( $sTag );
02677 if ( $oArticleTags->save() ) {
02678 return true;
02679 }
02680 return false;
02681 }
02682
02688 public function getMediaUrls()
02689 {
02690 if ( $this->_aMediaUrls === null ) {
02691 $this->_aMediaUrls = oxNew("oxlist");
02692 $this->_aMediaUrls->init("oxmediaurl");
02693 $this->_aMediaUrls->getBaseObject()->setLanguage( $this->getLanguage() );
02694
02695 $sViewName = getViewName( "oxmediaurls", $this->getLanguage() );
02696 $sQ = "select * from {$sViewName} where oxobjectid = '".$this->getId()."'";
02697 $this->_aMediaUrls->selectString($sQ);
02698 }
02699 return $this->_aMediaUrls;
02700 }
02701
02707 public function getDynImageDir()
02708 {
02709 return $this->_sDynImageDir;
02710 }
02711
02717 public function getDispSelList()
02718 {
02719 if ($this->_aDispSelList === null) {
02720 if ( $this->getConfig()->getConfigParam( 'bl_perfLoadSelectLists' ) && $this->getConfig()->getConfigParam( 'bl_perfLoadSelectListsInAList' ) ) {
02721 $this->_aDispSelList = $this->getSelectLists();
02722 }
02723 }
02724 return $this->_aDispSelList;
02725 }
02726
02732 public function getMoreDetailLink()
02733 {
02734 if ( $this->_sMoreDetailLink == null ) {
02735
02736
02737 $this->_sMoreDetailLink = $this->getConfig()->getShopHomeURL() . 'cl=moredetails';
02738
02739
02740 if ( $sActCat = oxConfig::getParameter( 'cnid' ) ) {
02741 $this->_sMoreDetailLink .= '&cnid='.$sActCat;
02742 }
02743 $this->_sMoreDetailLink .= '&anid='.$this->getId();
02744 $this->_sMoreDetailLink = $this->_sMoreDetailLink;
02745 }
02746
02747 return $this->_sMoreDetailLink;
02748 }
02749
02755 public function getToBasketLink()
02756 {
02757 if ( $this->_sToBasketLink == null ) {
02758 $myConfig = $this->getConfig();
02759
02760 if ( oxRegistry::getUtils()->isSearchEngine() ) {
02761 $this->_sToBasketLink = $this->getLink();
02762 } else {
02763
02764 $this->_sToBasketLink = $myConfig->getShopHomeURL();
02765
02766
02767 $sActClass = oxConfig::getParameter( 'cl' );
02768 if ( $sActClass == 'thankyou') {
02769 $sActClass = 'basket';
02770 }
02771 $this->_sToBasketLink .= 'cl='.$sActClass;
02772
02773
02774 if ( $sActCat = oxConfig::getParameter( 'cnid' ) ) {
02775 $this->_sToBasketLink .= '&cnid='.$sActCat;
02776 }
02777
02778 $this->_sToBasketLink .= '&fnc=tobasket&aid='.$this->getId().'&anid='.$this->getId();
02779
02780 if ( $sTpl = basename( oxConfig::getParameter( 'tpl' ) ) ) {
02781 $this->_sToBasketLink .= '&tpl='.$sTpl;
02782 }
02783 }
02784 }
02785
02786 return $this->_sToBasketLink;
02787 }
02788
02794 public function getStockStatus()
02795 {
02796 return $this->_iStockStatus;
02797 }
02798
02804 public function getDeliveryDate()
02805 {
02806 if ( $this->oxarticles__oxdelivery->value != '0000-00-00') {
02807 return oxRegistry::get("oxUtilsDate")->formatDBDate( $this->oxarticles__oxdelivery->value);
02808 }
02809 return false;
02810 }
02811
02817 public function getFTPrice()
02818 {
02819
02820 if ( $oPrice = $this->getTPrice() ) {
02821 if ( $dPrice = $this->_getPriceForView( $oPrice ) ) {
02822 return oxRegistry::getLang()->formatCurrency( $dPrice );
02823 }
02824 }
02825 }
02826
02832 public function getFPrice()
02833 {
02834 if ( $oPrice = $this->getPrice() ) {
02835 $dPrice = $this->_getPriceForView( $oPrice );
02836 return oxRegistry::getLang()->formatCurrency( $dPrice );
02837 }
02838 }
02839
02846 public function resetRemindStatus()
02847 {
02848 if ( $this->oxarticles__oxremindactive->value == 2 &&
02849 $this->oxarticles__oxremindamount->value <= $this->oxarticles__oxstock->value ) {
02850 $this->oxarticles__oxremindactive->value = 1;
02851 }
02852 }
02853
02859 public function getFNetPrice()
02860 {
02861 if ( $oPrice = $this->getPrice() ) {
02862 return oxRegistry::getLang()->formatCurrency( $oPrice->getNettoPrice() );
02863 }
02864 }
02865
02873 public function getPricePerUnit()
02874 {
02875 return $this->getFUnitPrice();
02876 }
02877
02883 public function isParentNotBuyable()
02884 {
02885 return $this->_blNotBuyableParent;
02886 }
02887
02893 public function isNotBuyable()
02894 {
02895 return $this->_blNotBuyable;
02896 }
02897
02905 public function setBuyableState( $blBuyable = false )
02906 {
02907 $this->_blNotBuyable = !$blBuyable;
02908 }
02909
02917 public function setSelectlist( $aSelList )
02918 {
02919 $this->_aDispSelList = $aSelList;
02920 }
02921
02929 public function getPictureUrl( $iIndex = 1 )
02930 {
02931 if ( $iIndex ) {
02932 $sImgName = false;
02933 if ( !$this->_isFieldEmpty( "oxarticles__oxpic".$iIndex ) ) {
02934 $sImgName = basename( $this->{"oxarticles__oxpic$iIndex"}->value );
02935 }
02936
02937 $sSize = $this->getConfig()->getConfigParam( 'aDetailImageSizes' );
02938 return oxRegistry::get("oxPictureHandler")->getProductPicUrl( "product/{$iIndex}/", $sImgName, $sSize, 'oxpic'.$iIndex );
02939 }
02940 }
02941
02950 public function getIconUrl( $iIndex = 0 )
02951 {
02952 $sImgName = false;
02953 $sDirname = "product/1/";
02954 if ( $iIndex && !$this->_isFieldEmpty( "oxarticles__oxpic{$iIndex}" ) ) {
02955 $sImgName = basename( $this->{"oxarticles__oxpic$iIndex"}->value );
02956 $sDirname = "product/{$iIndex}/";
02957 } elseif ( !$this->_isFieldEmpty( "oxarticles__oxicon" ) ) {
02958 $sImgName = basename( $this->oxarticles__oxicon->value );
02959 $sDirname = "product/icon/";
02960 } elseif ( !$this->_isFieldEmpty( "oxarticles__oxpic1" ) ) {
02961 $sImgName = basename( $this->oxarticles__oxpic1->value );
02962 }
02963
02964 $sSize = $this->getConfig()->getConfigParam( 'sIconsize' );
02965 return oxRegistry::get("oxPictureHandler")->getProductPicUrl( $sDirname, $sImgName, $sSize, $iIndex );
02966 }
02967
02975 public function getThumbnailUrl( $bSsl = null )
02976 {
02977 $sImgName = false;
02978 $sDirname = "product/1/";
02979 if ( !$this->_isFieldEmpty( "oxarticles__oxthumb" ) ) {
02980 $sImgName = basename( $this->oxarticles__oxthumb->value );
02981 $sDirname = "product/thumb/";
02982 } elseif ( !$this->_isFieldEmpty( "oxarticles__oxpic1" ) ) {
02983 $sImgName = basename( $this->oxarticles__oxpic1->value );
02984 }
02985
02986 $sSize = $this->getConfig()->getConfigParam( 'sThumbnailsize' );
02987 return oxRegistry::get("oxPictureHandler")->getProductPicUrl( $sDirname, $sImgName, $sSize, 0, $bSsl );
02988 }
02989
02997 public function getZoomPictureUrl( $iIndex = '' )
02998 {
02999 $iIndex = (int) $iIndex;
03000 if ( $iIndex > 0 && !$this->_isFieldEmpty( "oxarticles__oxpic".$iIndex ) ) {
03001 $sImgName = basename( $this->{"oxarticles__oxpic".$iIndex}->value );
03002 $sSize = $this->getConfig()->getConfigParam( "sZoomImageSize" );
03003 return oxRegistry::get("oxPictureHandler")->getProductPicUrl( "product/{$iIndex}/", $sImgName, $sSize, 'oxpic'.$iIndex );
03004 }
03005 }
03006
03012 public function getFileUrl()
03013 {
03014 return $this->getConfig()->getPictureUrl( 'media/' );
03015 }
03016
03024 public function getPriceFromPrefix()
03025 {
03026 $sPricePrefix = '';
03027 if ( $this->_blIsRangePrice) {
03028 $sPricePrefix = oxLang::getInstance()->translateString('PRICE_FROM').' ';
03029 }
03030
03031 return $sPricePrefix;
03032 }
03033
03039 protected function _saveArtLongDesc()
03040 {
03041 $myConfig = $this->getConfig();
03042 $sShopId = $myConfig->getShopID();
03043 if (in_array("oxlongdesc", $this->_aSkipSaveFields)) {
03044 return;
03045 }
03046
03047 if ($this->_blEmployMultilanguage) {
03048 $sValue = $this->getLongDescription()->getRawValue();
03049 if ( $sValue !== null ) {
03050 $oArtExt = oxNew('oxI18n');
03051 $oArtExt->init('oxartextends');
03052 $oArtExt->setLanguage((int) $this->getLanguage());
03053 if (!$oArtExt->load($this->getId())) {
03054 $oArtExt->setId($this->getId());
03055 }
03056 $oArtExt->oxartextends__oxlongdesc = new oxField($sValue, oxField::T_RAW);
03057 $oArtExt->save();
03058 }
03059 } else {
03060 $oArtExt = oxNew('oxI18n');
03061 $oArtExt->setEnableMultilang(false);
03062 $oArtExt->init('oxartextends');
03063 $aObjFields = $oArtExt->_getAllFields(true);
03064 if (!$oArtExt->load($this->getId())) {
03065 $oArtExt->setId($this->getId());
03066 }
03067
03068 foreach ($aObjFields as $sKey => $sValue ) {
03069 if ( preg_match('/^oxlongdesc(_(\d{1,2}))?$/', $sKey) ) {
03070 $sField = $this->_getFieldLongName($sKey);
03071
03072 if (isset($this->$sField)) {
03073 $sLongDesc = null;
03074 if ($this->$sField instanceof oxField) {
03075 $sLongDesc = $this->$sField->getRawValue();
03076 } elseif (is_object($this->$sField)) {
03077 $sLongDesc = $this->$sField->value;
03078 }
03079 if (isset($sLongDesc)) {
03080 $sAEField = $oArtExt->_getFieldLongName($sKey);
03081 $oArtExt->$sAEField = new oxField($sLongDesc, oxField::T_RAW);
03082 }
03083 }
03084 }
03085 }
03086 $oArtExt->save();
03087 }
03088 }
03089
03095 protected function _skipSaveFields()
03096 {
03097 $myConfig = $this->getConfig();
03098
03099 $this->_aSkipSaveFields = array();
03100
03101 $this->_aSkipSaveFields[] = 'oxtimestamp';
03102
03103 $this->_aSkipSaveFields[] = 'oxinsert';
03104
03105 if ( !$this->_blAllowEmptyParentId && (!isset( $this->oxarticles__oxparentid->value) || $this->oxarticles__oxparentid->value == '') ) {
03106 $this->_aSkipSaveFields[] = 'oxparentid';
03107 }
03108
03109 }
03110
03120 protected function _mergeDiscounts( $aDiscounts, $aItemDiscounts)
03121 {
03122 foreach ( $aItemDiscounts as $sKey => $oDiscount ) {
03123
03124 if ( array_key_exists ($sKey, $aDiscounts) ) {
03125 $aDiscounts[$sKey]->dDiscount += $oDiscount->dDiscount;
03126 } else {
03127 $aDiscounts[$sKey] = $oDiscount;
03128 }
03129 }
03130 return $aDiscounts;
03131 }
03132
03138 protected function _getGroupPrice()
03139 {
03140 $sPriceSufix = $this->_getUserPriceSufix();
03141 $sVarName = oxarticles__oxprice.$sPriceSufix;
03142 $dPrice = $this->$sVarName->value;
03143
03144
03145 if ( $this->getConfig()->getConfigParam( 'blOverrideZeroABCPrices' ) && (double) $dPrice == 0 ) {
03146 $dPrice = $this->oxarticles__oxprice->value;
03147 }
03148
03149 return $dPrice;
03150 }
03151
03160 protected function _getAmountPrice($dAmount = 1)
03161 {
03162 $myConfig = $this->getConfig();
03163
03164 startProfile( "_getAmountPrice" );
03165
03166 $dPrice = $this->_getGroupPrice();
03167 $oAmtPrices = $this->_getAmountPriceList();
03168 foreach ($oAmtPrices as $oAmPrice) {
03169 if ($oAmPrice->oxprice2article__oxamount->value <= $dAmount
03170 && $dAmount <= $oAmPrice->oxprice2article__oxamountto->value
03171 && $dPrice > $oAmPrice->oxprice2article__oxaddabs->value ) {
03172 $dPrice = $oAmPrice->oxprice2article__oxaddabs->value;
03173 }
03174 }
03175
03176 stopProfile( "_getAmountPrice" );
03177 return $dPrice;
03178 }
03179
03188 protected function _modifySelectListPrice( $dPrice, $aChosenList = null )
03189 {
03190 $myConfig = $this->getConfig();
03191
03192 if ( $myConfig->getConfigParam( 'bl_perfLoadSelectLists' ) && $myConfig->getConfigParam( 'bl_perfUseSelectlistPrice' ) ) {
03193
03194 $aSelLists = $this->getSelectLists();
03195
03196 foreach ( $aSelLists as $key => $aSel) {
03197 if ( isset( $aChosenList[$key]) && isset($aSel[$aChosenList[$key]] ) ) {
03198 $oSel = $aSel[$aChosenList[$key]];
03199 if ( $oSel->priceUnit =='abs' ) {
03200 $dPrice += $oSel->price;
03201 } elseif ( $oSel->priceUnit =='%' ) {
03202 $dPrice += oxPrice::percent( $dPrice, $oSel->price );
03203 }
03204 }
03205 }
03206 }
03207 return $dPrice;
03208 }
03209
03210
03218 protected function _fillAmountPriceList($aAmPriceList)
03219 {
03220 $myConfig = $this->getConfig();
03221 $oLang = oxRegistry::getLang();
03222
03223
03224 foreach ($aAmPriceList as $sId => $oItem) {
03225
03226 $oItemPrice = $this->_getPriceObject();
03227 if ( $oItem->oxprice2article__oxaddabs->value ) {
03228
03229 $dBasePrice = $oItem->oxprice2article__oxaddabs->value;
03230 $dBasePrice = $this->_preparePrice( $dBasePrice, $this->getArticleVat() );
03231
03232 $oItemPrice->setPrice( $dBasePrice );
03233 $this->_calculatePrice( $oItemPrice );
03234
03235 } else {
03236 $dBasePrice = $this->_getGroupPrice();
03237 $dBasePrice = $this->_preparePrice( $dBasePrice, $this->getArticleVat() );
03238 $oItemPrice->setPrice( $dBasePrice );
03239 $oItemPrice->subtractPercent( $oItem->oxprice2article__oxaddperc->value );
03240 }
03241
03242
03243 $aAmPriceList[$sId]->fbrutprice = $oLang->formatCurrency( $this->_getPriceForView( $oItemPrice ) );
03244 }
03245
03246 return $aAmPriceList;
03247 }
03248
03249
03255 protected function _getVariantsIds()
03256 {
03257 $aSelect = array();
03258 if ( ( $sId = $this->getId() ) ) {
03259 $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
03260 $sQ = "select oxid from " . $this->getViewName( true ) . " where oxparentid = ".$oDb->quote( $sId )." and " .
03261 $this->getSqlActiveSnippet( true ) . " order by oxsort";
03262 $oRs = $oDb->select( $sQ );
03263 if ( $oRs != false && $oRs->recordCount() > 0 ) {
03264 while (!$oRs->EOF) {
03265 $aSelect[] = reset( $oRs->fields );
03266 $oRs->moveNext();
03267 }
03268 }
03269 }
03270 return $aSelect;
03271 }
03272
03278 public function getArticleVat()
03279 {
03280 if (!isset($this->_dArticleVat)) {
03281 $this->_dArticleVat = oxRegistry::get("oxVatSelector")->getArticleVat( $this );
03282 }
03283 return $this->_dArticleVat;
03284 }
03285
03294 protected function _applyVAT( oxPrice $oPrice, $dVat )
03295 {
03296 startProfile(__FUNCTION__);
03297 $oPrice->setVAT( $dVat );
03298 if ( ($dVat = oxRegistry::get("oxVatSelector")->getArticleUserVat($this)) !== false ) {
03299 $oPrice->setUserVat( $dVat );
03300 }
03301 stopProfile(__FUNCTION__);
03302 }
03303
03311 public function applyVats( oxPrice $oPrice )
03312 {
03313 $this->_applyVAT($oPrice, $this->getArticleVat() );
03314 }
03315
03323 public function applyDiscountsForVariant( $oPrice )
03324 {
03325
03326 if ( !$this->skipDiscounts() ) {
03327 $oDiscountList = oxRegistry::get("oxDiscountList");
03328 $aDiscounts = $oDiscountList->getArticleDiscounts( $this, $this->getArticleUser() );
03329
03330 reset( $aDiscounts );
03331 foreach ( $aDiscounts as $oDiscount ) {
03332 $oPrice->setDiscount($oDiscount->getAddSum(), $oDiscount->getAddSumType());
03333 }
03334 $oPrice->calculateDiscount();
03335 }
03336 }
03337
03346 protected function _applyCurrency(oxPrice $oPrice, $oCur = null )
03347 {
03348 if ( !$oCur ) {
03349 $oCur = $this->getConfig()->getActShopCurrencyObject();
03350 }
03351
03352 $oPrice->multiply($oCur->rate);
03353 }
03354
03355
03364 protected function _getAttribsString(&$sAttribs, &$iCnt)
03365 {
03366
03367 $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
03368 $sSelect = 'select oxattrid from oxobject2attribute where oxobject2attribute.oxobjectid='.$oDb->quote( $this->getId() );
03369 $sAttribs = '';
03370 $blSep = false;
03371 $rs = $oDb->select( $sSelect);
03372 $iCnt = 0;
03373 if ($rs != false && $rs->recordCount() > 0) {
03374 while (!$rs->EOF) {
03375 if ( $blSep) {
03376 $sAttribs .= ' or ';
03377 }
03378 $sAttribs .= 't1.oxattrid = '.$oDb->quote($rs->fields['oxattrid']).' ';
03379 $blSep = true;
03380 $iCnt++;
03381 $rs->moveNext();
03382 }
03383 }
03384 }
03385
03394 protected function _getSimList($sAttribs, $iCnt)
03395 {
03396 $myConfig = $this->getConfig();
03397 $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
03398
03399
03400 $iAttrPercent = $myConfig->getConfigParam( 'iAttributesPercent' )/100;
03401
03402 if ( !$iAttrPercent || $iAttrPercent < 0 || $iAttrPercent > 1) {
03403 $iAttrPercent = 0.70;
03404 }
03405
03406 $iHitMin = ceil( $iCnt * $iAttrPercent );
03407
03408
03409 $aList= array();
03410 $sSelect = "select oxobjectid, count(*) as cnt from oxobject2attribute as t1 where
03411 ( $sAttribs )
03412 and t1.oxobjectid != ".$oDb->quote( $this->oxarticles__oxid->value )."
03413 group by t1.oxobjectid having count(*) >= $iHitMin ";
03414
03415 $rs = $oDb->selectLimit( $sSelect, 20, 0 );
03416 if ($rs != false && $rs->recordCount() > 0) {
03417 while (!$rs->EOF) {
03418 $oTemp = new stdClass();
03419 $oTemp->cnt = $rs->fields['cnt'];
03420 $oTemp->id = $rs->fields['oxobjectid'];
03421 $aList[] = $oTemp;
03422 $rs->moveNext();
03423 }
03424 }
03425 return $aList;
03426 }
03427
03436 protected function _generateSimListSearchStr($sArticleTable, $aList)
03437 {
03438 $myConfig = $this->getConfig();
03439 $sFieldList = $this->getSelectFields();
03440 $sSearch = "select $sFieldList from $sArticleTable where ".$this->getSqlActiveSnippet()." and $sArticleTable.oxissearch = 1 and $sArticleTable.oxid in ( ";
03441 $blSep = false;
03442 $iCnt = 0;
03443 $oDb = oxDb::getDb();
03444 foreach ( $aList as $oTemp) {
03445 if ( $blSep) {
03446 $sSearch .= ',';
03447 }
03448 $sSearch .= $oDb->quote($oTemp->id);
03449 $blSep = true;
03450 if ( $iCnt >= $myConfig->getConfigParam( 'iNrofSimilarArticles' ) ) {
03451 break;
03452 }
03453 $iCnt++;
03454 }
03455
03456
03457
03458 $sSearch .= ') ';
03459
03460
03461 $sSearch .= ' order by rand() ';
03462
03463 return $sSearch;
03464 }
03465
03474 protected function _generateSearchStr($sOXID, $blSearchPriceCat = false )
03475 {
03476
03477 $sCatView = getViewName( 'oxcategories', $this->getLanguage() );
03478 $sO2CView = getViewName( 'oxobject2category' );
03479
03480
03481 if ( !$blSearchPriceCat ) {
03482 $sSelect = "select {$sCatView}.* from {$sO2CView} as oxobject2category left join {$sCatView} on
03483 {$sCatView}.oxid = oxobject2category.oxcatnid
03484 where oxobject2category.oxobjectid=".oxDb::getDb()->quote($sOXID)." and {$sCatView}.oxid is not null ";
03485 } else {
03486 $sSelect = "select {$sCatView}.* from {$sCatView} where
03487 '{$this->oxarticles__oxprice->value}' >= {$sCatView}.oxpricefrom and
03488 '{$this->oxarticles__oxprice->value}' <= {$sCatView}.oxpriceto ";
03489 }
03490 return $sSelect;
03491 }
03492
03498 protected function _generateSearchStrForCustomerBought()
03499 {
03500 $sArtTable = $this->getViewName();
03501 $sOrderArtTable = getViewName( 'oxorderarticles' );
03502
03503
03504 $sIn = " '{$this->oxarticles__oxid->value}' ";
03505 if ( $this->oxarticles__oxparentid->value ) {
03506
03507
03508 $sIn .= ", '{$this->oxarticles__oxparentid->value}' ";
03509 $sParentIdForVariants = $this->oxarticles__oxparentid->value;
03510
03511 } else {
03512 $sParentIdForVariants = $this->getId();
03513 }
03514
03515
03516 $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
03517 $oRs = $oDb->select( "select oxid from {$sArtTable} where oxparentid = ".$oDb->quote($sParentIdForVariants)." and oxid != ".$oDb->quote($this->oxarticles__oxid->value) );
03518 if ( $oRs != false && $oRs->recordCount() > 0) {
03519 while ( !$oRs->EOF ) {
03520 $sIn .= ", ".$oDb->quote(current( $oRs->fields ))." ";
03521 $oRs->moveNext();
03522 }
03523 }
03524
03525 $iLimit = (int) $this->getConfig()->getConfigParam( 'iNrofCustomerWhoArticles' );
03526 $iLimit = $iLimit?( $iLimit * 10 ): 50;
03527
03528
03529 $sQ = "select distinct {$sArtTable}.* from (
03530 select d.oxorderid as suborderid from {$sOrderArtTable} as d use index ( oxartid ) where d.oxartid in ( {$sIn} ) limit {$iLimit}
03531 ) as suborder
03532 left join {$sOrderArtTable} force index ( oxorderid ) on suborder.suborderid = {$sOrderArtTable}.oxorderid
03533 left join {$sArtTable} on {$sArtTable}.oxid = {$sOrderArtTable}.oxartid
03534 where {$sArtTable}.oxid not in ( {$sIn} )
03535 and ( {$sArtTable}.oxissearch = 1 or {$sArtTable}.oxparentid <> '' ) and ".$this->getSqlActiveSnippet();
03536
03537
03538
03539
03540
03541
03542
03543
03544
03545
03546 return $sQ;
03547 }
03548
03558 protected function _generateSelectCatStr($sOXID, $sCatId, $dPriceFromTo = false)
03559 {
03560 $sCategoryView = getViewName('oxcategories');
03561 $sO2CView = getViewName('oxobject2category');
03562
03563 $oDb = oxDb::getDb();
03564 $sOXID = $oDb->quote($sOXID);
03565 $sCatId = $oDb->quote($sCatId);
03566
03567 if (!$dPriceFromTo) {
03568 $sSelect = "select oxobject2category.oxcatnid from $sO2CView as oxobject2category ";
03569 $sSelect .= "left join $sCategoryView as oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
03570 $sSelect .= "where oxobject2category.oxcatnid=$sCatId and oxobject2category.oxobjectid=$sOXID ";
03571 $sSelect .= "and oxcategories.oxactive = 1 order by oxobject2category.oxtime ";
03572 } else {
03573 $dPriceFromTo = $oDb->quote($dPriceFromTo);
03574 $sSelect = "select oxcategories.oxid from $sCategoryView as oxcategories where ";
03575 $sSelect .= "oxcategories.oxid=$sCatId and $dPriceFromTo >= oxcategories.oxpricefrom and ";
03576 $sSelect .= "$dPriceFromTo <= oxcategories.oxpriceto ";
03577 }
03578 return $sSelect;
03579 }
03580
03586 protected function _getAmountPriceList()
03587 {
03588 if ( $this->_oAmountPriceList === null ) {
03589 $oAmPriceList = oxNew( 'oxAmountPricelist' );
03590
03591 if ( !$this->skipDiscounts() ) {
03592
03593 $oAmPriceList->load( $this );
03594
03595
03596 $oBasePrice = $this->_getGroupPrice();
03597 foreach ( $oAmPriceList as $oAmPrice ) {
03598 if ( $oAmPrice->oxprice2article__oxaddperc->value ) {
03599 $oAmPrice->oxprice2article__oxaddabs = new oxField(oxPrice::percent( $oBasePrice, 100 - $oAmPrice->oxprice2article__oxaddperc->value ), oxField::T_RAW );
03600 }
03601 }
03602
03603 }
03604
03605 $this->_oAmountPriceList = $oAmPriceList;
03606 }
03607
03608 return $this->_oAmountPriceList;
03609 }
03610
03618 protected function _isFieldEmpty( $sFieldName )
03619 {
03620 $mValue = $this->$sFieldName->value;
03621
03622 if ( is_null( $mValue ) ) {
03623 return true;
03624 }
03625
03626 if ( $mValue === '' ) {
03627 return true;
03628 }
03629
03630
03631 $aZeroValueFields = array('oxarticles__oxprice', 'oxarticles__oxvat', 'oxarticles__oxunitquantity');
03632
03633 if (!$mValue && in_array( $sFieldName, $aZeroValueFields ) ) {
03634 return true;
03635 }
03636
03637
03638 if (!strcmp($mValue, '0000-00-00 00:00:00') || !strcmp($mValue, '0000-00-00')) {
03639 return true;
03640 }
03641
03642 $sFieldName = strtolower($sFieldName);
03643
03644 if ( $sFieldName == 'oxarticles__oxicon' && ( strpos($mValue, "nopic_ico.jpg") !== false || strpos($mValue, "nopic.jpg") !== false ) ) {
03645 return true;
03646 }
03647
03648 if ( strpos($mValue, "nopic.jpg") !== false && ($sFieldName == 'oxarticles__oxthumb' || substr($sFieldName, 0, 17) == 'oxarticles__oxpic' || substr($sFieldName, 0, 18) == 'oxarticles__oxzoom') ) {
03649 return true;
03650 }
03651
03652 return false;
03653 }
03654
03662 protected function _isImageField($sFieldName)
03663 {
03664 $blIsImageField = ( stristr($sFieldName, '_oxthumb') || stristr($sFieldName, '_oxicon') || stristr($sFieldName, '_oxzoom') || stristr($sFieldName, '_oxpic') );
03665 return $blIsImageField;
03666 }
03667
03675 protected function _assignParentFieldValue($sFieldName)
03676 {
03677 if (!($oParentArticle = $this->getParentArticle())) {
03678 return;
03679 }
03680
03681 $sCopyFieldName = $this->_getFieldLongName($sFieldName);
03682
03683
03684 if ( $oParentArticle->$sCopyFieldName != null ) {
03685
03686
03687 if ( substr( $sCopyFieldName, 0, 12) != 'oxarticles__') {
03688 return;
03689 }
03690
03691
03692 if (in_array($sCopyFieldName, $this->_aNonCopyParentFields)) {
03693 return;
03694 }
03695
03696
03697 if ($this->_isFieldEmpty($sCopyFieldName) && $this->_isImageField($sCopyFieldName) && $this->_hasMasterImage( 1 )) {
03698 return;
03699 }
03700
03701
03702 if ($this->_isFieldEmpty($sCopyFieldName) || in_array( $sCopyFieldName, $this->_aCopyParentField ) ) {
03703 $this->$sCopyFieldName = clone $oParentArticle->$sCopyFieldName;
03704 }
03705
03706
03707
03708
03709
03710
03711
03712
03713
03714
03715
03716
03717
03718
03719
03720
03721
03722
03723 }
03724 }
03725
03731 public function getParentArticle()
03732 {
03733 if ( ( $sParentId = $this->oxarticles__oxparentid->value ) ) {
03734 $sIndex = $sParentId . "_" . $this->getLanguage();
03735 if ( !isset( self::$_aLoadedParents[$sIndex] ) ) {
03736 self::$_aLoadedParents[$sIndex] = oxNew( 'oxarticle' );
03737 self::$_aLoadedParents[$sIndex]->_blLoadPrice = false;
03738 self::$_aLoadedParents[$sIndex]->_blLoadVariants = false;
03739 self::$_aLoadedParents[$sIndex]->loadInLang( $this->getLanguage(), $sParentId );
03740 }
03741 return self::$_aLoadedParents[$sIndex];
03742 }
03743 }
03744
03750 protected function _assignParentFieldValues()
03751 {
03752 startProfile('articleAssignParentInternal');
03753 if ( $this->oxarticles__oxparentid->value ) {
03754
03755 if ( !$this->isAdmin() || ( $this->_blLoadParentData && $this->isAdmin() ) ) {
03756 foreach ( $this->_aFieldNames as $sFieldName => $sVal ) {
03757 $this->_assignParentFieldValue( $sFieldName );
03758 }
03759 }
03760 }
03761 stopProfile('articleAssignParentInternal');
03762 }
03763
03769 protected function _assignNotBuyableParent()
03770 {
03771 if ( !$this->getConfig()->getConfigParam( 'blVariantParentBuyable' ) &&
03772 ($this->_blHasVariants || $this->oxarticles__oxvarstock->value || $this->oxarticles__oxvarcount->value )) {
03773 $this->_blNotBuyableParent = true;
03774
03775 }
03776 }
03777
03783 protected function _assignStock()
03784 {
03785 $myConfig = $this->getConfig();
03786
03787
03788
03789
03790
03791 if (!$myConfig->getConfigParam( 'blAllowUnevenAmounts' ) && !$this->isAdmin() ) {
03792 $this->oxarticles__oxstock = new oxField((int) floor($this->oxarticles__oxstock->value));
03793 }
03794
03795 $this->_iStockStatus = 0;
03796
03797
03798 if ( $myConfig->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstockflag->value != 4) {
03799
03800 $iStock = $this->oxarticles__oxstock->value;
03801
03802 if ($this->_blNotBuyableParent) {
03803 $iStock = $this->oxarticles__oxvarstock->value;
03804 }
03805
03806
03807 if ( $iStock <= $myConfig->getConfigParam( 'sStockWarningLimit' ) && $iStock > 0) {
03808 $this->_iStockStatus = 1;
03809 }
03810
03811
03812 if ($iStock <= 0) {
03813 $this->_iStockStatus = -1;
03814 }
03815 }
03816
03817
03818
03819 if ( $myConfig->getConfigParam( 'blUseStock' ) && ($this->oxarticles__oxstockflag->value == 3 || $this->oxarticles__oxstockflag->value == 2)) {
03820 $iOnStock = $this->oxarticles__oxstock->value;
03821 if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
03822 $iOnStock += $this->getSession()->getBasketReservations()->getReservedAmount($this->getId());
03823 }
03824 if ($iOnStock <= 0) {
03825 $this->setBuyableState( false );
03826 }
03827 }
03828
03829
03830 if ($this->_blNotBuyable && $this->oxarticles__oxvarstock->value ) {
03831 $this->setBuyableState( true );
03832
03833 $this->_blNotBuyableParent = true;
03834 }
03835
03836
03837
03838
03839 if ( !$myConfig->getConfigParam( 'blVariantParentBuyable' ) && !$myConfig->getConfigParam( 'blLoadVariants' ) && $this->oxarticles__oxvarstock->value) {
03840 $this->setBuyableState( false );
03841 }
03842
03843
03844 if (!$this->_blNotBuyable && $this->_blNotBuyableParent && $this->oxarticles__oxvarcount->value == 0) {
03845 $this->setBuyableState( false );
03846 }
03847 }
03848
03856 protected function _assignPrices()
03857 {
03858 $myConfig = $this->getConfig();
03859
03860
03861 if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
03862 return;
03863 }
03864
03865
03866 if ( $this->_hasAnyVariant() ) {
03867 $this->_applyRangePrice();
03868 }
03869 }
03870
03876 protected function _assignPersistentParam()
03877 {
03878
03879 $aPersParam = oxSession::getVar( 'persparam');
03880 if ( isset( $aPersParam) && isset( $aPersParam[$this->getId()])) {
03881 $this->_aPersistParam = $aPersParam[$this->getId()];
03882 }
03883 }
03884
03890 protected function _assignDynImageDir()
03891 {
03892 $myConfig = $this->getConfig();
03893
03894 $sThisShop = $this->oxarticles__oxshopid->value;
03895
03896 $this->_sDynImageDir = $myConfig->getPictureUrl( null, false );
03897 $this->dabsimagedir = $myConfig->getPictureDir( false );
03898 $this->nossl_dimagedir = $myConfig->getPictureUrl( null, false, false, null, $sThisShop );
03899 $this->ssl_dimagedir = $myConfig->getPictureUrl( null, false, true, null, $sThisShop );
03900 }
03901
03907 protected function _assignComparisonListFlag()
03908 {
03909
03910
03911 $aItems = oxSession::getVar('aFiltcompproducts');
03912 if ( isset( $aItems[$this->getId()])) {
03913 $this->_blIsOnComparisonList = true;
03914 }
03915 }
03916
03917
03925 protected function _insert()
03926 {
03927
03928 $sNow = date('Y-m-d H:i:s', oxRegistry::get("oxUtilsDate")->getTime());
03929 $this->oxarticles__oxinsert = new oxField( $sNow );
03930 if ( !is_object($this->oxarticles__oxsubclass) || $this->oxarticles__oxsubclass->value == '') {
03931 $this->oxarticles__oxsubclass = new oxField('oxarticle');
03932 }
03933
03934 return parent::_insert();
03935 }
03936
03942 protected function _update()
03943 {
03944
03945 $this->setUpdateSeo(true);
03946 $this->_setUpdateSeoOnFieldChange('oxtitle');
03947
03948 $this->_skipSaveFields();
03949
03950 $myConfig = $this->getConfig();
03951
03952
03953 $blRes = parent::_update();
03954
03955
03956 return $blRes;
03957 }
03958
03964 public function updateVariantsRemind()
03965 {
03966
03967 if ( !$this->isVariant() && $this->_hasAnyVariant()) {
03968 $oDb = oxDb::getDb();
03969 $sOxId = $oDb->quote($this->getId());
03970 $sOxShopId = $oDb->quote($this->getShopId());
03971 $iRemindActive = $oDb->quote($this->oxarticles__oxremindactive->value);
03972 $sUpdate = "
03973 update oxarticles
03974 set oxremindactive = $iRemindActive
03975 where oxparentid = $sOxId and
03976 oxshopid = $sOxShopId
03977 ";
03978 $oDb->execute( $sUpdate );
03979 }
03980 }
03981
03989 protected function _deleteRecords($sOXID)
03990 {
03991 $oDb = oxDb::getDb();
03992
03993 $sOXID = $oDb->quote($sOXID);
03994
03995
03996 $sDelete = 'delete from oxobject2article where oxarticlenid = '.$sOXID.' or oxobjectid = '.$sOXID.' ';
03997 $oDb->execute( $sDelete);
03998
03999 $sDelete = 'delete from oxobject2attribute where oxobjectid = '.$sOXID.' ';
04000 $oDb->execute( $sDelete);
04001
04002 $sDelete = 'delete from oxobject2category where oxobjectid = '.$sOXID.' ';
04003 $oDb->execute( $sDelete);
04004
04005 $sDelete = 'delete from oxobject2selectlist where oxobjectid = '.$sOXID.' ';
04006 $oDb->execute( $sDelete);
04007
04008 $sDelete = 'delete from oxprice2article where oxartid = '.$sOXID.' ';
04009 $oDb->execute( $sDelete);
04010
04011 $sDelete = 'delete from oxreviews where oxtype="oxarticle" and oxobjectid = '.$sOXID.' ';
04012 $oDb->execute( $sDelete);
04013
04014 $sDelete = 'delete from oxratings where oxobjectid = '.$sOXID.' ';
04015 $rs = $oDb->execute( $sDelete );
04016
04017 $sDelete = 'delete from oxaccessoire2article where oxobjectid = '.$sOXID.' or oxarticlenid = '.$sOXID.' ';
04018 $oDb->execute( $sDelete);
04019
04020
04021 $sDelete = 'delete from oxobject2delivery where oxobjectid = '.$sOXID.' and oxtype=\'oxarticles\' ';
04022 $oDb->execute( $sDelete);
04023
04024 $sDelete = 'delete from oxartextends where oxid = '.$sOXID.' ';
04025 $oDb->execute( $sDelete);
04026
04027
04028 foreach ( $this->_getLanguageSetTables( "oxartextends" ) as $sSetTbl ) {
04029 $oDb->execute( "delete from $sSetTbl where oxid = {$sOXID}" );
04030 }
04031
04032 $sDelete = 'delete from oxactions2article where oxartid = '.$sOXID.' ';
04033 $rs = $oDb->execute( $sDelete );
04034
04035 $sDelete = 'delete from oxobject2list where oxobjectid = '.$sOXID.' ';
04036 $rs = $oDb->execute( $sDelete );
04037
04038
04039 return $rs;
04040 }
04041
04049 protected function _deleteVariantRecords( $sOXID )
04050 {
04051 if ( $sOXID ) {
04052 $oDb = oxDb::getDb();
04053
04054 $sQ = 'select oxid from '.$this->getViewName().' where oxparentid = '.$oDb->quote( $sOXID );
04055 $rs = $oDb->select( $sQ, false, false );
04056 $oArticle = oxNew("oxArticle");
04057 if ($rs != false && $rs->recordCount() > 0) {
04058 while (!$rs->EOF) {
04059 $oArticle->setId($rs->fields[0]);
04060 $oArticle->delete();
04061 $rs->moveNext();
04062 }
04063 }
04064 }
04065 }
04066
04072 protected function _deletePics()
04073 {
04074 $myUtilsPic = oxRegistry::get("oxUtilsPic");
04075 $myConfig = $this->getConfig();
04076 $oPictureHandler = oxRegistry::get("oxPictureHandler");
04077
04078
04079 $oPictureHandler->deleteMainIcon( $this );
04080
04081
04082 $oPictureHandler->deleteThumbnail( $this );
04083
04084 $sAbsDynImageDir = $myConfig->getPictureDir(false);
04085
04086
04087 $iPicCount = $myConfig->getConfigParam( 'iPicCount' );
04088 for ( $i = 1; $i <= $iPicCount; $i++ ) {
04089 $oPictureHandler->deleteArticleMasterPicture( $this, $i );
04090 }
04091 }
04092
04102 protected function _onChangeResetCounts( $sOxid, $sVendorId = null, $sManufacturerId = null )
04103 {
04104
04105 $myUtilsCount = oxRegistry::get("oxUtilsCount");
04106
04107 if ( $sVendorId ) {
04108 $myUtilsCount->resetVendorArticleCount( $sVendorId );
04109 }
04110
04111 if ( $sManufacturerId ) {
04112 $myUtilsCount->resetManufacturerArticleCount( $sManufacturerId );
04113 }
04114
04115
04116 $oDb = oxDb::getDb();
04117 $sQ = "select oxcatnid from oxobject2category where oxobjectid = ".$oDb->quote($sOxid);
04118 $oRs = $oDb->select( $sQ, false, false );
04119 if ( $oRs !== false && $oRs->recordCount() > 0) {
04120 while ( !$oRs->EOF ) {
04121 $myUtilsCount->resetCatArticleCount( $oRs->fields[0] );
04122 $oRs->moveNext();
04123 }
04124 }
04125 }
04126
04134 protected function _onChangeUpdateStock( $sParentID )
04135 {
04136 if ( $sParentID ) {
04137 $oDb = oxDb::getDb();
04138 $sParentIdQuoted = $oDb->quote($sParentID);
04139 $sQ = 'select oxstock, oxvendorid, oxmanufacturerid from oxarticles where oxid = '.$sParentIdQuoted;
04140 $rs = $oDb->select( $sQ, false, false );
04141 $iOldStock = $rs->fields[0];
04142 $iVendorID = $rs->fields[1];
04143 $iManufacturerID = $rs->fields[2];
04144
04145 $sQ = 'select sum(oxstock) from '.$this->getViewName(true).' where oxparentid = '.$sParentIdQuoted.' and '. $this->getSqlActiveSnippet( true ).' and oxstock > 0 ';
04146 $iStock = (float) $oDb->getOne( $sQ, false, false );
04147
04148 $sQ = 'update oxarticles set oxvarstock = '.$iStock.' where oxid = '.$sParentIdQuoted;
04149 $oDb->execute( $sQ );
04150
04151
04152
04153 if ( $iStock < 0 ) {
04154 $iStock = 0;
04155 }
04156 if ( $iOldStock < 0 ) {
04157 $iOldStock = 0;
04158 }
04159 if ( $this->oxarticles__oxstockflag->value == 2 && $iOldStock xor $iStock ) {
04160
04161
04162 $this->_onChangeResetCounts( $sParentID, $iVendorID, $iManufacturerID );
04163 }
04164 }
04165 }
04166
04174 protected function _onChangeStockResetCount( $sOxid )
04175 {
04176 $myConfig = $this->getConfig();
04177
04178 if ( $myConfig->getConfigParam( 'blUseStock' ) && $this->oxarticles__oxstockflag->value == 2 &&
04179 ( $this->oxarticles__oxstock->value + $this->oxarticles__oxvarstock->value ) <= 0 ) {
04180
04181 $this->_onChangeResetCounts( $sOxid, $this->oxarticles__oxvendorid->value, $this->oxarticles__oxmanufacturerid->value );
04182 }
04183 }
04184
04192 protected function _onChangeUpdateVarCount( $sParentID )
04193 {
04194 if ( $sParentID ) {
04195 $oDb = oxDb::getDb();
04196 $sParentIdQuoted = $oDb->quote( $sParentID );
04197 $sQ = "select count(*) as varcount from oxarticles where oxparentid = {$sParentIdQuoted}";
04198 $iVarCount = (int) $oDb->getOne( $sQ, false, false );
04199
04200 $sQ = "update oxarticles set oxvarcount = {$iVarCount} where oxid = {$sParentIdQuoted}";
04201 $oDb->execute( $sQ );
04202 }
04203 }
04204
04212 protected function _setVarMinMaxPrice( $sParentId )
04213 {
04214 if ( $sParentId ) {
04215 $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
04216 $sQ = '
04217 SELECT
04218 MIN( IF( `oxarticles`.`oxprice` > 0, `oxarticles`.`oxprice`, `p`.`oxprice` ) ) AS `varminprice`,
04219 MAX( IF( `oxarticles`.`oxprice` > 0, `oxarticles`.`oxprice`, `p`.`oxprice` ) ) AS `varmaxprice`
04220 FROM '. $this->getViewName(true) . ' AS `oxarticles`
04221 LEFT JOIN '. $this->getViewName(true) . ' AS `p` ON ( `p`.`oxid` = `oxarticles`.`oxparentid` AND `p`.`oxprice` > 0 )
04222 WHERE '. $this->getSqlActiveSnippet(true) .'
04223 AND ( `oxarticles`.`oxparentid` = '. $oDb->quote( $sParentId ) .' )';
04224 $oDb->setFetchMode( oxDb::FETCH_MODE_ASSOC );
04225 $aPrices = $oDb->getRow( $sQ, false, false );
04226 if ( !is_null( $aPrices['varminprice'] ) || !is_null( $aPrices['varmaxprice'] ) ) {
04227 $sQ = '
04228 UPDATE `oxarticles`
04229 SET
04230 `oxvarminprice` = '. $oDb->quote( $aPrices['varminprice'] ) .',
04231 `oxvarmaxprice` = '. $oDb->quote( $aPrices['varmaxprice'] ) .'
04232 WHERE
04233 `oxid` = ' . $oDb->quote( $sParentId );
04234 } else {
04235 $sQ = '
04236 UPDATE `oxarticles`
04237 SET
04238 `oxvarminprice` = `oxprice`,
04239 `oxvarmaxprice` = `oxprice`
04240 WHERE
04241 `oxid` = ' . $oDb->quote( $sParentId );
04242 }
04243 $oDb->execute( $sQ );
04244 }
04245 }
04246
04247
04257 protected function _onChangeUpdateMinVarPrice( $sParentID )
04258 {
04259 if ( $sParentID ) {
04260 $oDb = oxDb::getDb();
04261 $sParentIdQuoted = $oDb->quote($sParentID);
04262
04263 $sQ = 'select min(oxprice) as varminprice from '.$this->getViewName(true).' where '.$this->getSqlActiveSnippet(true).' and (oxparentid = '.$sParentIdQuoted.')';
04264 $dVarMinPrice = $oDb->getOne( $sQ, false, false );
04265
04266 $dParentPrice = $oDb->getOne( "select oxprice from oxarticles where oxid = $sParentIdQuoted ", false, false );
04267
04268 $blParentBuyable = $this->getConfig()->getConfigParam( 'blVariantParentBuyable' );
04269
04270 if ($dVarMinPrice) {
04271 if ($blParentBuyable) {
04272 $dVarMinPrice = min($dVarMinPrice, $dParentPrice);
04273 }
04274 } else {
04275 $dVarMinPrice = $dParentPrice;
04276 }
04277
04278 if ( $dVarMinPrice ) {
04279 $sQ = 'update oxarticles set oxvarminprice = '.$dVarMinPrice.' where oxid = '.$sParentIdQuoted;
04280 $oDb->execute($sQ);
04281 }
04282 }
04283 }
04284
04285
04293 protected function _applyRangePrice()
04294 {
04295
04296 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
04297 return;
04298 }
04299
04300 $this->_blIsRangePrice = false;
04301
04302
04303 if ($this->_blSkipFromPrice || !$this->_blNotBuyableParent) {
04304 return;
04305 }
04306
04307 if ( $this->isParentNotBuyable() && !$this->getConfig()->getConfigParam( 'blLoadVariants' )) {
04308
04309 $dPrice = $this->_preparePrice( $this->oxarticles__oxvarminprice->value, $this->getArticleVat() );
04310 $this->getPrice()->setPrice($dPrice);
04311 $this->_blIsRangePrice = true;
04312 $this->_calculatePrice( $this->getPrice() );
04313 return;
04314
04315 }
04316
04317 $aPrices = array();
04318
04319 if (!$this->_blNotBuyableParent) {
04320 $aPrices[] = $this->getPrice()->getPrice();
04321 }
04322
04323 $aVariants = $this->getVariants(false);
04324
04325 if (count($aVariants)) {
04326 foreach ($aVariants as $sKey => $oVariant) {
04327 $aPrices[] = $oVariant->getPrice()->getPrice();
04328 }
04329 }
04330
04331 if ( count( $aPrices ) ) {
04332 $dMinPrice = min( $aPrices );
04333 $dMaxPrice = max( $aPrices );
04334 }
04335
04336 if ($this->_blNotBuyableParent && isset($dMinPrice) && $dMinPrice == $dMaxPrice) {
04337 $this->getPrice()->setPrice($dMinPrice);
04338 }
04339
04340 if (isset($dMinPrice) && $dMinPrice != $dMaxPrice) {
04341 $this->getPrice()->setPrice($dMinPrice);
04342 $this->_blIsRangePrice = true;
04343 }
04344 }
04345
04352 public function getProductId()
04353 {
04354 return $this->getId();
04355 }
04356
04364 public function getProductParentId()
04365 {
04366 return $this->getParentId();
04367 }
04368
04374 public function getParentId()
04375 {
04376 return $this->oxarticles__oxparentid->value;
04377 }
04378
04384 public function isOrderArticle()
04385 {
04386 return false;
04387 }
04388
04394 public function isVariant()
04395 {
04396 return (bool) ( isset( $this->oxarticles__oxparentid ) ? $this->oxarticles__oxparentid->value : false );
04397 }
04398
04404 public function isMdVariant()
04405 {
04406 $oMdVariant = oxNew( "oxVariantHandler" );
04407
04408 return $oMdVariant->isMdVariant($this);
04409 }
04410
04418 public function getSqlForPriceCategories($sFields = '')
04419 {
04420 if (!$sFields) {
04421 $sFields = 'oxid';
04422 }
04423 $sSelectWhere = "select $sFields from ".$this->_getObjectViewName('oxcategories')." where";
04424 $sQuotedPrice = oxDb::getDb()->quote( $this->oxarticles__oxprice->value );
04425 return "$sSelectWhere oxpricefrom != 0 and oxpriceto != 0 and oxpricefrom <= $sQuotedPrice and oxpriceto >= $sQuotedPrice"
04426 ." union $sSelectWhere oxpricefrom != 0 and oxpriceto = 0 and oxpricefrom <= $sQuotedPrice"
04427 ." union $sSelectWhere oxpricefrom = 0 and oxpriceto != 0 and oxpriceto >= $sQuotedPrice";
04428 }
04429
04437 public function inPriceCategory( $sCatNid )
04438 {
04439 $oDb = oxDb::getDb();
04440
04441 $sQuotedPrice = $oDb->quote( $this->oxarticles__oxprice->value );
04442 $sQuotedCnid = $oDb->quote( $sCatNid );
04443 return (bool) $oDb->getOne(
04444 "select 1 from ".$this->_getObjectViewName('oxcategories')." where oxid=$sQuotedCnid and"
04445 ."( (oxpricefrom != 0 and oxpriceto != 0 and oxpricefrom <= $sQuotedPrice and oxpriceto >= $sQuotedPrice)"
04446 ." or (oxpricefrom != 0 and oxpriceto = 0 and oxpricefrom <= $sQuotedPrice)"
04447 ." or (oxpricefrom = 0 and oxpriceto != 0 and oxpriceto >= $sQuotedPrice)"
04448 .")"
04449 );
04450 }
04451
04457 public function getMdVariants()
04458 {
04459 if ( $this->_oMdVariants ) {
04460 return $this->_oMdVariants;
04461 }
04462
04463 $oParentArticle = $this->getParentArticle();
04464 if ( $oParentArticle ) {
04465 $oVariants = $oParentArticle->getVariants();
04466 } else {
04467 $oVariants = $this->getVariants();
04468 }
04469
04470 $oVariantHandler = oxNew( "oxVariantHandler" );
04471 $this->_oMdVariants = $oVariantHandler->buildMdVariants( $oVariants, $this->getId() );
04472
04473 return $this->_oMdVariants;
04474 }
04475
04481 public function getMdSubvariants()
04482 {
04483 return $this->getMdVariants()->getMdSubvariants();
04484 }
04485
04493 protected function _hasMasterImage( $iIndex )
04494 {
04495 $sPicName = basename($this->{"oxarticles__oxpic" . $iIndex}->value);
04496
04497 if ( $sPicName == "nopic.jpg" || $sPicName == "" ) {
04498 return false;
04499 }
04500 if ( $this->isVariant() && $this->getParentArticle()->{"oxarticles__oxpic".$iIndex}->value == $this->{"oxarticles__oxpic".$iIndex}->value ) {
04501 return false;
04502 }
04503
04504 $sMasterPic = 'product/'.$iIndex . "/" . $sPicName;
04505
04506 if ( $this->getConfig()->getMasterPicturePath( $sMasterPic ) ) {
04507 return true;
04508 }
04509
04510 return false;
04511 }
04512
04521 public function getPictureFieldValue( $sFieldName, $iIndex = null )
04522 {
04523 if ( $sFieldName ) {
04524 $sFieldName = "oxarticles__" . $sFieldName . $iIndex;
04525 return $this->$sFieldName->value;
04526 }
04527 }
04528
04536 public function getMasterZoomPictureUrl( $iIndex )
04537 {
04538 $sPicUrl = false;
04539 $sPicName = basename( $this->{"oxarticles__oxpic" . $iIndex}->value );
04540
04541 if ( $sPicName && $sPicName != "nopic.jpg" ) {
04542 $sPicUrl = $this->getConfig()->getPictureUrl( "master/product/" . $iIndex . "/" . $sPicName );
04543 if ( !$sPicUrl || basename( $sPicUrl ) == "nopic.jpg" ) {
04544 $sPicUrl = false;
04545 }
04546 }
04547
04548 return $sPicUrl;
04549 }
04550
04556 public function getUnitName()
04557 {
04558 if ( $this->oxarticles__oxunitname->value ) {
04559 return oxRegistry::getLang()->translateString( $this->oxarticles__oxunitname->value );
04560 }
04561 }
04562
04570 public function getArticleFiles( $blAddFromParent=false )
04571 {
04572 if ( $this->_aArticleFiles === null) {
04573
04574 $this->_aArticleFiles = false;
04575
04576 $sQ = "SELECT * FROM `oxfiles` WHERE `oxartid` = '".$this->getId()."'";
04577
04578 if ( !$this->getConfig()->getConfigParam( 'blVariantParentBuyable' ) && $blAddFromParent ) {
04579 $sQ .= " OR `oxartId` = '". $this->oxarticles__oxparentid->value . "'";
04580 }
04581
04582 $oArticleFiles = oxNew("oxlist");
04583 $oArticleFiles->init("oxfile");
04584 $oArticleFiles->selectString( $sQ );
04585 $this->_aArticleFiles = $oArticleFiles;
04586
04587 }
04588
04589 return $this->_aArticleFiles;
04590 }
04591
04597 public function isDownloadable()
04598 {
04599 return $this->oxarticles__oxisdownloadable->value;
04600 }
04601
04607 public function hasAmountPrice()
04608 {
04609 if ( self::$_blHasAmountPrice === null ) {
04610
04611 self::$_blHasAmountPrice = false;
04612
04613 $oDb = oxDb::getDb();
04614 $sQ = "SELECT 1 FROM `oxprice2article` LIMIT 1";
04615
04616 if ( $oDb->getOne( $sQ ) ) {
04617 self::$_blHasAmountPrice = true;
04618 }
04619 }
04620
04621 return self::$_blHasAmountPrice;
04622 }
04623
04624
04630 protected function _isPriceViewModeNetto()
04631 {
04632 $blResult = (bool) $this->getConfig()->getConfigParam('blShowNetPrice');
04633 $oUser = $this->getArticleUser();
04634 if ( $oUser ) {
04635 $blResult = $oUser->isPriceViewModeNetto();
04636 }
04637
04638 return $blResult;
04639 }
04640
04641
04649 protected function _getPriceObject( $blCalculationModeNetto = null )
04650 {
04651 $oPrice = oxNew( 'oxPrice' );
04652
04653 if ( $blCalculationModeNetto === null ) {
04654 $blCalculationModeNetto = $this->_isPriceViewModeNetto();
04655 }
04656
04657 if ( $blCalculationModeNetto ) {
04658 $oPrice->setNettoPriceMode();
04659 } else {
04660 $oPrice->setBruttoPriceMode();
04661 }
04662
04663 return $oPrice;
04664 }
04665
04666
04674 protected function _getPriceForView( $oPrice )
04675 {
04676 if ( $this->_isPriceViewModeNetto() ) {
04677 $dPrice = $oPrice->getNettoPrice();
04678 } else {
04679 $dPrice = $oPrice->getBruttoPrice();
04680 }
04681
04682 return $dPrice;
04683 }
04684
04685
04695 protected function _preparePrice( $dPrice, $dVat, $blCalculationModeNetto = null )
04696 {
04697 if ( $blCalculationModeNetto === null ) {
04698 $blCalculationModeNetto = $this->_isPriceViewModeNetto();
04699 }
04700
04701 $oCurrency = $this->getConfig()->getActShopCurrencyObject();
04702
04703 $blEnterNetPrice = $this->getConfig()->getConfigParam('blEnterNetPrice');
04704 if ( $blCalculationModeNetto && !$blEnterNetPrice ) {
04705 $dPrice = round( oxPrice::brutto2Netto( $dPrice, $dVat ), $oCurrency->decimal );
04706 } elseif ( !$blCalculationModeNetto && $blEnterNetPrice ) {
04707 $dPrice = round( oxPrice::netto2Brutto( $dPrice, $dVat ), $oCurrency->decimal );
04708 }
04709
04710 return $dPrice;
04711 }
04712
04713
04719 public function getFUnitPrice()
04720 {
04721 if ($this->_fPricePerUnit == null) {
04722 if ( $oPrice = $this->getUnitPrice() ) {
04723 if ( $dPrice = $this->_getPriceForView( $oPrice ) ) {
04724 $this->_fPricePerUnit = oxRegistry::getLang()->formatCurrency( $dPrice );
04725 }
04726 }
04727 }
04728
04729 return $this->_fPricePerUnit;
04730 }
04731
04732
04738 public function getUnitPrice()
04739 {
04740
04741 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
04742 return;
04743 }
04744
04745 $oPrice = null;
04746 if ( (double) $this->oxarticles__oxunitquantity->value && $this->oxarticles__oxunitname->value ) {
04747 $oPrice = clone $this->getPrice();
04748 $oPrice->divide( (double) $this->oxarticles__oxunitquantity->value );
04749 }
04750
04751 return $oPrice;
04752 }
04753
04754
04760 public function getFMinPrice()
04761 {
04762 $sPrice = '';
04763 if ( $oPrice = $this->getMinPrice() ) {
04764 $dPrice = $this->_getPriceForView( $oPrice );
04765 $sPrice = oxRegistry::getLang()->formatCurrency( $dPrice );
04766 }
04767
04768 return $sPrice;
04769 }
04770
04776 public function getFVarMinPrice()
04777 {
04778 $sPrice = '';
04779 if ( $oPrice = $this->getVarMinPrice() ) {
04780 $dPrice = $this->_getPriceForView( $oPrice );
04781 $sPrice = oxRegistry::getLang()->formatCurrency( $dPrice );
04782 }
04783
04784 return $sPrice;
04785 }
04786
04792 public function getVarMinPrice()
04793 {
04794 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
04795 return;
04796 }
04797
04798 $oPrice = null;
04799 $dPrice = $this->_getVarMinPrice();
04800
04801 $dPrice = $this->_preparePrice( $dPrice, $this->getArticleVat() );
04802
04803
04804 $oPrice = $this->_getPriceObject();
04805 $oPrice->setPrice( $dPrice );
04806 $this->_calculatePrice( $oPrice );
04807
04808
04809 return $oPrice;
04810 }
04811
04812
04818 public function getMinPrice()
04819 {
04820 if ( !$this->getConfig()->getConfigParam( 'bl_perfLoadPrice' ) || !$this->_blLoadPrice ) {
04821 return;
04822 }
04823
04824 $oPrice = null;
04825 $dPrice = $this->_getPrice();
04826 if ( $this->_getVarMinPrice() !== null && $dPrice > $this->_getVarMinPrice() ) {
04827 $dPrice = $this->_getVarMinPrice();
04828 }
04829
04830 $dPrice = $this->_preparePrice( $dPrice, $this->getArticleVat() );
04831
04832
04833 $oPrice = $this->_getPriceObject();
04834 $oPrice->setPrice( $dPrice );
04835 $this->_calculatePrice( $oPrice );
04836
04837 return $oPrice;
04838 }
04839
04840
04846 public function isRangePrice()
04847 {
04848 if ( $this->_blIsRangePrice === null ) {
04849
04850 $this->setRangePrice( false );
04851
04852 if ( $this->_hasAnyVariant() ) {
04853 $dPrice = $this->_getPrice();
04854 $dMinPrice = $this->_getVarMinPrice();
04855 $dMaxPrice = $this->_getVarMaxPrice();
04856
04857 if ( $dMinPrice != $dMaxPrice ) {
04858 $this->setRangePrice();
04859 } elseif ( !$this->isParentNotBuyable() && $dMinPrice != $dPrice ) {
04860 $this->setRangePrice();
04861 }
04862 }
04863 }
04864
04865 return $this->_blIsRangePrice;
04866 }
04867
04868
04876 public function setRangePrice( $blIsRangePrice = true )
04877 {
04878 return $this->_blIsRangePrice = $blIsRangePrice;
04879 }
04880
04886 protected function _getUserPriceSufix()
04887 {
04888 $sPriceSufix = '';
04889 $oUser = $this->getArticleUser();
04890
04891 if ( $oUser ) {
04892 if ( $oUser->inGroup( 'oxidpricea' ) ) {
04893 $sPriceSufix = 'a';
04894 } elseif ( $oUser->inGroup( 'oxidpriceb' ) ) {
04895 $sPriceSufix = 'b';
04896 } elseif ( $oUser->inGroup( 'oxidpricec' ) ) {
04897 $sPriceSufix = 'c';
04898 }
04899 }
04900
04901 return $sPriceSufix;
04902 }
04903
04904
04910 protected function _getPrice()
04911 {
04912 $sPriceSufix = $this->_getUserPriceSufix();
04913 if ( $sPriceSufix === '') {
04914 $dPrice = $this->oxarticles__oxprice->value;
04915 } else {
04916 if ( $this->getConfig()->getConfigParam( 'blOverrideZeroABCPrices' ) ) {
04917 $dPrice = ($this->{oxarticles__oxprice.$sPriceSufix}->value !=0 )? $this->{oxarticles__oxprice.$sPriceSufix}->value : $this->oxarticles__oxprice->value;
04918 } else {
04919 $dPrice = $this->{oxarticles__oxprice.$sPriceSufix}->value;
04920 }
04921 }
04922 return $dPrice;
04923 }
04924
04925
04931 protected function _getVarMinPrice()
04932 {
04933 if ( $this->_dVarMinPrice === null) {
04934
04935 $sPriceSufix = $this->_getUserPriceSufix();
04936 if ( $dPrice === null ) {
04937 if ( $sPriceSufix === '' ) {
04938 $dPrice = $this->oxarticles__oxvarminprice->value;
04939 } else {
04940 $sSql = 'SELECT ';
04941 if ( $this->getConfig()->getConfigParam( 'blOverrideZeroABCPrices' ) ) {
04942 $sSql .= 'MIN( IF(`oxprice'.$sPriceSufix.'` = 0, `oxprice`, `oxprice'.$sPriceSufix.'`) ) AS `varminprice` ';
04943 } else {
04944 $sSql .= 'MIN(`oxprice'.$sPriceSufix.'`) AS `varminprice` ';
04945 }
04946
04947 $sSql .= ' FROM ' . $this->getViewName(true) . '
04948 WHERE ' .$this->getSqlActiveSnippet(true) . '
04949 AND ( `oxparentid` = ' . oxDb::getDb()->quote( $this->getId() ) . ' )';
04950
04951 $dPrice = oxDb::getDb()->getOne( $sSql );
04952 }
04953 }
04954 $this->_dVarMinPrice = $dPrice;
04955 }
04956
04957 return $this->_dVarMinPrice;
04958 }
04959
04965 protected function _getSubShopVarMinPrice()
04966 {
04967 $myConfig = $this->getConfig();
04968 $sShopId = $myConfig->getShopId();
04969 if ($this->getConfig()->getConfigParam( 'blMallCustomPrice' ) && $sShopId != $this->oxarticles__oxshopid->value ) {
04970 $sPriceSufix = $this->_getUserPriceSufix();
04971 $sSql = 'SELECT ';
04972 if ( $sPriceSufix != '' && $this->getConfig()->getConfigParam( 'blOverrideZeroABCPrices' ) ) {
04973 $sSql .= 'MIN(IF(`oxfield2shop`.`oxprice'.$sPriceSufix.'` = 0, `oxfield2shop`.`oxprice`, `oxfield2shop`.`oxprice'.$sPriceSufix.'`)) AS `varminprice` ';
04974 } else {
04975 $sSql .= 'MIN(`oxfield2shop`.`oxprice'.$sPriceSufix.'`) AS `varminprice` ';
04976 }
04977 $sSql .= ' FROM ' . getViewName('oxfield2shop') . ' AS oxfield2shop
04978 INNER JOIN ' . $this->getViewName(true) . ' AS oxarticles ON `oxfield2shop`.`oxartid` = `oxarticles`.`oxid`
04979 WHERE ' .$this->getSqlActiveSnippet(true) . '
04980 AND ( `oxarticles`.`oxparentid` = ' . oxDb::getDb()->quote( $this->getId() ) . ' )
04981 AND ( `oxfield2shop`.`oxshopid` = ' . oxDb::getDb()->quote( $sShopId ) . ' )';
04982 $dPrice = oxDb::getDb()->getOne( $sSql );
04983 }
04984 return $dPrice;
04985 }
04986
04992 protected function _getVarMaxPrice()
04993 {
04994 if ( $this->_dVarMaxPrice === null ) {
04995
04996 $sPriceSufix = $this->_getUserPriceSufix();
04997 if ( $dPrice === null ) {
04998 if ( $sPriceSufix === '') {
04999 $dPrice = $this->oxarticles__oxvarmaxprice->value;
05000 } else {
05001 $sSql = 'SELECT ';
05002 if ( $this->getConfig()->getConfigParam( 'blOverrideZeroABCPrices' ) ) {
05003 $sSql .= 'MAX( IF(`oxprice'.$sPriceSufix.'` = 0, `oxprice`, `oxprice'.$sPriceSufix.'`) ) AS `varmaxprice` ';
05004 } else {
05005 $sSql .= 'MAX(`oxprice'.$sPriceSufix.'`) AS `varmaxprice` ';
05006 }
05007
05008 $sSql .= ' FROM ' . $this->getViewName(true) . '
05009 WHERE ' .$this->getSqlActiveSnippet(true) . '
05010 AND ( `oxparentid` = ' . oxDb::getDb()->quote( $this->getId() ) . ' )';
05011
05012 $dPrice = oxDb::getDb()->getOne( $sSql );
05013 }
05014 }
05015 $this->_dVarMaxPrice = $dPrice;
05016 }
05017
05018 return $this->_dVarMaxPrice;
05019 }
05020
05026 protected function _getSubShopVarMaxPrice()
05027 {
05028 $myConfig = $this->getConfig();
05029 $sShopId = $myConfig->getShopId();
05030 if ($this->getConfig()->getConfigParam( 'blMallCustomPrice' ) && $sShopId != $this->oxarticles__oxshopid->value ) {
05031 $sPriceSufix = $this->_getUserPriceSufix();
05032 $sSql = 'SELECT ';
05033 if ( $sPriceSufix != '' && $this->getConfig()->getConfigParam( 'blOverrideZeroABCPrices' ) ) {
05034 $sSql .= 'MAX(IF(`oxfield2shop`.`oxprice'.$sPriceSufix.'` = 0, `oxfield2shop`.`oxprice`, `oxfield2shop`.`oxprice'.$sPriceSufix.'`)) AS `varmaxprice` ';
05035 } else {
05036 $sSql .= 'MAX(`oxfield2shop`.`oxprice'.$sPriceSufix.'`) AS `varmaxprice` ';
05037 }
05038 $sSql .= ' FROM ' . getViewName('oxfield2shop') . ' AS oxfield2shop
05039 INNER JOIN ' . $this->getViewName(true) . ' AS oxarticles ON `oxfield2shop`.`oxartid` = `oxarticles`.`oxid`
05040 WHERE ' .$this->getSqlActiveSnippet(true) . '
05041 AND ( `oxarticles`.`oxparentid` = ' . oxDb::getDb()->quote( $this->getId() ) . ' )
05042 AND ( `oxfield2shop`.`oxshopid` = ' . oxDb::getDb()->quote( $sShopId ) . ' )';
05043 $dPrice = oxDb::getDb()->getOne( $sSql );
05044 }
05045 return $dPrice;
05046 }
05047
05048 }